Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make content encoder and options explicitly typed and extensible #4490

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

kanongil
Copy link
Contributor

This PR improves the typings of the route and payload compression options, by explicitly listing the available encoders (gzip & deflate) and types all the options.

Additionally, it allows users to register types for custom encoders/decoders with its own custom options. Eg.

import { createBrotliCompress } from 'zlib';

declare module '@hapi/hapi' {
    interface ContentEncoders {
        br: typeof createBrotliCompress;
    }
}

This will add and type a br encoder to servers.encoders(), and add it to the list of compression options with the expected typings.

Note that I deleted the nonsensical RouteCompressionEncoderSettings and PayloadCompressionDecoderSettings type exports (the settings have always been specific to each entry).

@kanongil kanongil added the types TypeScript type definitions label Mar 18, 2024
@Marsup Marsup added this to the 21.3.7 milestone Mar 19, 2024
@Marsup Marsup merged commit 4426c5a into hapijs:master Mar 19, 2024
12 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types TypeScript type definitions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants