@fastify/compress 6.1.1 → 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.
- package/index.js +4 -2
- package/package.json +3 -3
- package/types/index.d.ts +100 -0
- package/{test/types → types}/index.test-d.ts +1 -1
- package/index.d.ts +0 -81
package/index.js
CHANGED
|
@@ -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
|
|
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(
|
|
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,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/compress",
|
|
3
|
-
"version": "6.
|
|
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
8
|
"@fastify/accept-negotiator": "^1.0.0",
|
|
9
9
|
"fastify-plugin": "^4.0.0",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"jsonstream": "^1.0.3",
|
|
25
25
|
"standard": "^17.0.0",
|
|
26
26
|
"tap": "^16.0.0",
|
|
27
|
-
"tsd": "^0.
|
|
27
|
+
"tsd": "^0.24.1",
|
|
28
28
|
"typescript": "^4.5.4"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
package/types/index.d.ts
ADDED
|
@@ -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
|