@fastify/compress 6.1.0 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,4 +14,5 @@ jobs:
14
14
  test:
15
15
  uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
16
16
  with:
17
+ license-check: true
17
18
  lint: true
package/README.md CHANGED
@@ -85,7 +85,7 @@ app.get('/', (req, reply) => {
85
85
  .compress(fs.createReadStream('./package.json'))
86
86
  })
87
87
 
88
- await app.listen(3000)
88
+ await app.listen({ port: 3000 })
89
89
  ```
90
90
 
91
91
  ## Compress Options
@@ -163,7 +163,7 @@ You can tune compression by setting the `brotliOptions` and `zlibOptions` proper
163
163
  },
164
164
  },
165
165
  zlibOptions: {
166
- level: 9, // default is 9, max is 9, min is 0
166
+ level: 6, // default is typically 6, max is 9, min is 0
167
167
  }
168
168
  });
169
169
  ```
package/index.js CHANGED
@@ -8,7 +8,7 @@ const intoStream = require('into-stream')
8
8
  const peek = require('peek-stream')
9
9
  const Minipass = require('minipass')
10
10
  const pumpify = require('pumpify')
11
- const encodingNegotiator = require('encoding-negotiator')
11
+ const encodingNegotiator = require('@fastify/accept-negotiator')
12
12
  const { inherits, format } = require('util')
13
13
 
14
14
  const { isStream, isGzip, isDeflate } = require('./lib/utils')
@@ -16,7 +16,7 @@ const { isStream, isGzip, isDeflate } = require('./lib/utils')
16
16
  const InvalidRequestEncodingError = createError('FST_CP_ERR_INVALID_CONTENT_ENCODING', 'Unsupported Content-Encoding: %s', 415)
17
17
  const InvalidRequestCompressedPayloadError = createError('FST_CP_ERR_INVALID_CONTENT', 'Could not decompress the request payload using the provided encoding', 400)
18
18
 
19
- function compressPlugin (fastify, opts, next) {
19
+ function fastifyCompress (fastify, opts, next) {
20
20
  const globalCompressParams = processCompressParams(opts)
21
21
  const globalDecompressParams = processDecompressParams(opts)
22
22
 
@@ -548,7 +548,9 @@ function createError (code, message, statusCode) {
548
548
  return FastifyCompressError
549
549
  }
550
550
 
551
- module.exports = fp(compressPlugin, {
551
+ module.exports = fp(fastifyCompress, {
552
552
  fastify: '4.x',
553
553
  name: '@fastify/compress'
554
554
  })
555
+ module.exports.default = fastifyCompress
556
+ module.exports.fastifyCompress = fastifyCompress
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@fastify/compress",
3
- "version": "6.1.0",
3
+ "version": "6.2.0",
4
4
  "description": "Fastify compression utils",
5
5
  "main": "index.js",
6
- "types": "index.d.ts",
6
+ "types": "types/index.d.ts",
7
7
  "dependencies": {
8
- "encoding-negotiator": "^2.0.1",
9
- "fastify-plugin": "^3.0.0",
8
+ "@fastify/accept-negotiator": "^1.0.0",
9
+ "fastify-plugin": "^4.0.0",
10
10
  "into-stream": "^6.0.0",
11
11
  "mime-db": "^1.51.0",
12
12
  "minipass": "^3.1.6",
@@ -15,16 +15,16 @@
15
15
  "pumpify": "^2.0.1"
16
16
  },
17
17
  "devDependencies": {
18
- "@types/node": "^17.0.8",
18
+ "@fastify/pre-commit": "^2.0.2",
19
+ "@types/node": "^18.0.0",
19
20
  "@typescript-eslint/eslint-plugin": "^5.9.0",
20
21
  "@typescript-eslint/parser": "^5.9.0",
21
22
  "adm-zip": "^0.5.9",
22
23
  "fastify": "^4.0.0-rc.2",
23
24
  "jsonstream": "^1.0.3",
24
- "pre-commit": "^1.2.2",
25
25
  "standard": "^17.0.0",
26
26
  "tap": "^16.0.0",
27
- "tsd": "^0.21.0",
27
+ "tsd": "^0.24.1",
28
28
  "typescript": "^4.5.4"
29
29
  },
30
30
  "scripts": {
@@ -0,0 +1,100 @@
1
+ import {
2
+ FastifyPluginCallback,
3
+ FastifyReply,
4
+ FastifyRequest,
5
+ RawServerBase,
6
+ RawServerDefault,
7
+ RouteOptions as FastifyRouteOptions
8
+ } from 'fastify'
9
+ import { Input, InputObject } from 'into-stream'
10
+ import { Stream } from 'stream'
11
+ import { BrotliOptions, ZlibOptions } from 'zlib'
12
+
13
+ declare module 'fastify' {
14
+ export interface FastifyContextConfig {
15
+ /** @deprecated `config.compress` is deprecated, use `compress` shorthand option instead */
16
+ compress?: RouteCompressOptions | false;
17
+ /** @deprecated `config.decompress` is deprecated, use `decompress` shorthand option instead */
18
+ decompress?: RouteDecompressOptions | false;
19
+ }
20
+
21
+ export interface RouteShorthandOptions<
22
+ RawServer extends RawServerBase = RawServerDefault
23
+ > {
24
+ compress?: RouteCompressOptions | false;
25
+ decompress?: RouteDecompressOptions | false;
26
+ }
27
+
28
+ interface FastifyReply {
29
+ compress(input: Stream | Input | InputObject): void;
30
+ }
31
+
32
+ export interface RouteOptions {
33
+ compress?: RouteCompressOptions | false;
34
+ decompress?: RouteDecompressOptions | false;
35
+ }
36
+ }
37
+
38
+ type FastifyCompress = FastifyPluginCallback<fastifyCompress.FastifyCompressOptions>
39
+
40
+ type RouteCompressOptions = Pick<fastifyCompress.FastifyCompressOptions,
41
+ | 'brotliOptions'
42
+ | 'customTypes'
43
+ | 'encodings'
44
+ | 'inflateIfDeflated'
45
+ | 'onUnsupportedEncoding'
46
+ | 'removeContentLengthHeader'
47
+ | 'threshold'
48
+ | 'zlib'
49
+ | 'zlibOptions'
50
+ >
51
+
52
+ type RouteDecompressOptions = Pick<fastifyCompress.FastifyCompressOptions,
53
+ | 'forceRequestEncoding'
54
+ | 'onInvalidRequestPayload'
55
+ | 'onUnsupportedRequestEncoding'
56
+ | 'requestEncodings'
57
+ | 'zlib'
58
+ >
59
+
60
+ type EncodingToken = 'br' | 'deflate' | 'gzip' | 'identity';
61
+
62
+ declare namespace fastifyCompress {
63
+
64
+ export interface FastifyCompressOptions {
65
+ brotliOptions?: BrotliOptions;
66
+ customTypes?: RegExp;
67
+ encodings?: EncodingToken[];
68
+ forceRequestEncoding?: EncodingToken;
69
+ global?: boolean;
70
+ inflateIfDeflated?: boolean;
71
+ onInvalidRequestPayload?: (encoding: string, request: FastifyRequest, error: Error) => Error | undefined | null;
72
+ onUnsupportedEncoding?: (encoding: string, request: FastifyRequest, reply: FastifyReply) => string | Buffer | Stream;
73
+ onUnsupportedRequestEncoding?: (encoding: string, request: FastifyRequest, reply: FastifyReply) => Error | undefined | null;
74
+ removeContentLengthHeader?: boolean;
75
+ requestEncodings?: EncodingToken[];
76
+ threshold?: number;
77
+ zlib?: unknown;
78
+ zlibOptions?: ZlibOptions;
79
+ }
80
+
81
+ export interface FastifyCompressRouteOptions {
82
+ compress?: RouteCompressOptions | false;
83
+ decompress?: RouteDecompressOptions | false;
84
+ }
85
+
86
+ export interface RouteOptions extends FastifyRouteOptions, FastifyCompressRouteOptions { }
87
+
88
+ export interface RoutesConfigCompressOptions {
89
+ /** @deprecated `config.compress` is deprecated, use `compress` shorthand option instead */
90
+ compress?: RouteCompressOptions | false;
91
+ /** @deprecated `config.decompress` is deprecated, use `decompress` shorthand option instead */
92
+ decompress?: RouteDecompressOptions | false;
93
+ }
94
+
95
+ export const fastifyCompress: FastifyCompress
96
+ export { fastifyCompress as default }
97
+ }
98
+
99
+ declare function fastifyCompress(...params: Parameters<FastifyCompress>): ReturnType<FastifyCompress>
100
+ export = fastifyCompress
@@ -2,7 +2,7 @@ import fastify, { FastifyInstance } from 'fastify'
2
2
  import { createReadStream } from 'fs'
3
3
  import { expectError, expectType } from 'tsd'
4
4
  import * as zlib from 'zlib'
5
- import fastifyCompress, { FastifyCompressOptions } from '../..'
5
+ import fastifyCompress, { FastifyCompressOptions } from '..'
6
6
 
7
7
  const stream = createReadStream('./package.json')
8
8
 
package/index.d.ts DELETED
@@ -1,81 +0,0 @@
1
- import {
2
- FastifyPluginCallback,
3
- FastifyReply,
4
- FastifyRequest,
5
- RawServerBase,
6
- RawServerDefault
7
- } from 'fastify'
8
- import * as fastify from 'fastify'
9
- import { Input, InputObject } from 'into-stream'
10
- import { Stream } from 'stream'
11
- import { BrotliOptions, ZlibOptions } from 'zlib'
12
-
13
- type EncodingToken = 'br' | 'deflate' | 'gzip' | 'identity';
14
-
15
- export interface FastifyCompressOptions {
16
- brotliOptions?: BrotliOptions;
17
- customTypes?: RegExp;
18
- encodings?: EncodingToken[];
19
- forceRequestEncoding?: EncodingToken;
20
- global?: boolean;
21
- inflateIfDeflated?: boolean;
22
- onInvalidRequestPayload?: (encoding: string, request: FastifyRequest, error: Error) => Error | undefined | null;
23
- onUnsupportedEncoding?: (encoding: string, request: FastifyRequest, reply: FastifyReply) => string | Buffer | Stream;
24
- onUnsupportedRequestEncoding?: (encoding: string, request: FastifyRequest, reply: FastifyReply) => Error | undefined | null;
25
- removeContentLengthHeader?: boolean;
26
- requestEncodings?: EncodingToken[];
27
- threshold?: number;
28
- zlib?: unknown;
29
- zlibOptions?: ZlibOptions;
30
- }
31
-
32
- interface RouteCompressOptions extends Pick<FastifyCompressOptions,
33
- | 'brotliOptions'
34
- | 'customTypes'
35
- | 'encodings'
36
- | 'inflateIfDeflated'
37
- | 'onUnsupportedEncoding'
38
- | 'removeContentLengthHeader'
39
- | 'threshold'
40
- | 'zlib'
41
- | 'zlibOptions'
42
- > {}
43
-
44
- interface RouteDecompressOptions extends Pick<FastifyCompressOptions,
45
- | 'forceRequestEncoding'
46
- | 'onInvalidRequestPayload'
47
- | 'onUnsupportedRequestEncoding'
48
- | 'requestEncodings'
49
- | 'zlib'
50
- > {}
51
-
52
- interface FastifyCompressRouteOptions {
53
- compress?: RouteCompressOptions | false;
54
- decompress?: RouteDecompressOptions | false;
55
- }
56
-
57
- export interface RouteOptions extends fastify.RouteOptions, FastifyCompressRouteOptions {}
58
-
59
- export interface RoutesConfigCompressOptions {
60
- /** @deprecated `config.compress` is deprecated, use `compress` shorthand option instead */
61
- compress?: RouteCompressOptions | false;
62
- /** @deprecated `config.decompress` is deprecated, use `decompress` shorthand option instead */
63
- decompress?: RouteDecompressOptions | false;
64
- }
65
-
66
- declare module 'fastify' {
67
- export interface FastifyContextConfig extends RoutesConfigCompressOptions {}
68
-
69
- export interface RouteShorthandOptions<
70
- RawServer extends RawServerBase = RawServerDefault
71
- > extends FastifyCompressRouteOptions {}
72
-
73
- interface FastifyReply {
74
- compress(input: Stream | Input | InputObject): void;
75
- }
76
-
77
- export interface RouteOptions extends FastifyCompressRouteOptions {}
78
- }
79
-
80
- declare const fastifyCompress: FastifyPluginCallback<FastifyCompressOptions>
81
- export default fastifyCompress