@fastify/compress 8.3.1 → 9.1.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/.c8rc +2 -6
- package/.github/dependabot.yml +42 -2
- package/.github/workflows/ci.yml +1 -1
- package/.github/workflows/lock-threads.yml +19 -0
- package/LICENSE +1 -3
- package/README.md +2 -3
- package/index.js +42 -29
- package/lib/utils.js +90 -1
- package/package.json +9 -15
- package/test/global-compress.test.js +119 -0
- package/test/global-decompress.test.js +4 -2
- package/test/regression/issue-382.test.js +193 -0
- package/test/regression/issue-410.test.js +163 -0
- package/test/routes-compress.test.js +0 -89
- package/test/routes-decompress.test.js +4 -87
- package/test/utils.test.js +138 -1
- package/types/index.d.ts +0 -14
- package/types/{index.test-d.ts → index.tst.ts} +31 -31
- package/.github/stale.yml +0 -21
package/types/index.d.ts
CHANGED
|
@@ -10,13 +10,6 @@ import { Stream } from 'node:stream'
|
|
|
10
10
|
import { BrotliOptions, ZlibOptions } from 'node:zlib'
|
|
11
11
|
|
|
12
12
|
declare module 'fastify' {
|
|
13
|
-
export interface FastifyContextConfig {
|
|
14
|
-
/** @deprecated `config.compress` is deprecated, use `compress` shorthand option instead */
|
|
15
|
-
compress?: RouteCompressOptions | false;
|
|
16
|
-
/** @deprecated `config.decompress` is deprecated, use `decompress` shorthand option instead */
|
|
17
|
-
decompress?: RouteDecompressOptions | false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
13
|
export interface RouteShorthandOptions<
|
|
21
14
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
22
15
|
RawServer extends RawServerBase = RawServerDefault
|
|
@@ -97,13 +90,6 @@ declare namespace fastifyCompress {
|
|
|
97
90
|
|
|
98
91
|
export interface RouteOptions extends FastifyRouteOptions, FastifyCompressRouteOptions { }
|
|
99
92
|
|
|
100
|
-
export interface RoutesConfigCompressOptions {
|
|
101
|
-
/** @deprecated `config.compress` is deprecated, use `compress` shorthand option instead */
|
|
102
|
-
compress?: RouteCompressOptions | false;
|
|
103
|
-
/** @deprecated `config.decompress` is deprecated, use `decompress` shorthand option instead */
|
|
104
|
-
decompress?: RouteDecompressOptions | false;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
93
|
export const fastifyCompress: FastifyCompress
|
|
108
94
|
export { fastifyCompress as default }
|
|
109
95
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fastify, { FastifyInstance } from 'fastify'
|
|
2
2
|
import { createReadStream } from 'node:fs'
|
|
3
|
-
import {
|
|
3
|
+
import { expect } from 'tstyche'
|
|
4
4
|
import * as zlib from 'node:zlib'
|
|
5
5
|
import fastifyCompress, { FastifyCompressOptions } from '..'
|
|
6
6
|
|
|
@@ -39,11 +39,11 @@ app.register(fastifyCompress, {
|
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
app.get('/test-one', async (_request, reply) => {
|
|
42
|
-
|
|
42
|
+
expect(reply.compress(stream)).type.toBe<void>()
|
|
43
43
|
})
|
|
44
44
|
|
|
45
45
|
app.get('/test-two', async (_request, reply) => {
|
|
46
|
-
|
|
46
|
+
expect(reply.compress).type.not.toBeCallableWith()
|
|
47
47
|
})
|
|
48
48
|
|
|
49
49
|
// Instantiation of an app without global
|
|
@@ -64,7 +64,7 @@ appWithoutGlobal.get('/one', {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
}, (_request, reply) => {
|
|
67
|
-
|
|
67
|
+
expect(reply.type('text/plain').compress(stream)).type.toBe<void>()
|
|
68
68
|
})
|
|
69
69
|
|
|
70
70
|
appWithoutGlobal.get('/two', {
|
|
@@ -82,27 +82,27 @@ appWithoutGlobal.get('/two', {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
}, (_request, reply) => {
|
|
85
|
-
|
|
85
|
+
expect(reply.type('text/plain').compress(stream)).type.toBe<void>()
|
|
86
86
|
})
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
)
|
|
88
|
+
appWithoutGlobal.get('/throw-a-ts-arg-error-on-shorthand-route', {
|
|
89
|
+
// @ts-expect-error Type 'string' is not assignable
|
|
90
|
+
compress: 'bad compress route option value',
|
|
91
|
+
// @ts-expect-error Type 'string' is not assignable
|
|
92
|
+
decompress: 'bad decompress route option value'
|
|
93
|
+
}, (_request, reply) => {
|
|
94
|
+
reply.type('text/plain').compress(stream)
|
|
95
|
+
})
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
)
|
|
97
|
+
appWithoutGlobal.route({
|
|
98
|
+
method: 'GET',
|
|
99
|
+
path: '/throw-a-ts-arg-error',
|
|
100
|
+
// @ts-expect-error Type 'string' is not assignable
|
|
101
|
+
compress: 'bad compress route option value',
|
|
102
|
+
// @ts-expect-error Type 'string' is not assignable
|
|
103
|
+
decompress: 'bad decompress route option value',
|
|
104
|
+
handler: (_request, reply) => { reply.type('text/plain').compress(stream) }
|
|
105
|
+
})
|
|
106
106
|
|
|
107
107
|
appWithoutGlobal.inject(
|
|
108
108
|
{
|
|
@@ -113,29 +113,29 @@ appWithoutGlobal.inject(
|
|
|
113
113
|
}
|
|
114
114
|
},
|
|
115
115
|
(err) => {
|
|
116
|
-
|
|
116
|
+
expect(err).type.toBe<Error | undefined>()
|
|
117
117
|
}
|
|
118
118
|
)
|
|
119
119
|
|
|
120
120
|
// Test that invalid encoding values trigger TypeScript errors
|
|
121
|
-
|
|
121
|
+
expect(fastify().register).type.not.toBeCallableWith(fastifyCompress, {
|
|
122
122
|
encodings: ['invalid-encoding']
|
|
123
|
-
})
|
|
123
|
+
})
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
expect(fastify().register).type.not.toBeCallableWith(fastifyCompress, {
|
|
126
126
|
requestEncodings: ['another-invalid-encoding']
|
|
127
|
-
})
|
|
127
|
+
})
|
|
128
128
|
|
|
129
129
|
// Instantiation of an app that should trigger a typescript error
|
|
130
130
|
const appThatTriggerAnError = fastify()
|
|
131
|
-
|
|
131
|
+
expect(appThatTriggerAnError.register).type.not.toBeCallableWith(fastifyCompress, {
|
|
132
132
|
global: true,
|
|
133
133
|
thisOptionDoesNotExist: 'trigger a typescript error'
|
|
134
|
-
})
|
|
134
|
+
})
|
|
135
135
|
|
|
136
136
|
app.get('/ts-fetch-response', async (_request, reply) => {
|
|
137
137
|
const resp = new Response('ok', { headers: { 'content-type': 'text/plain' } })
|
|
138
|
-
|
|
138
|
+
expect(reply.compress(resp)).type.toBe<void>()
|
|
139
139
|
})
|
|
140
140
|
|
|
141
141
|
app.get('/ts-web-readable-stream', async (_request, reply) => {
|
|
@@ -145,5 +145,5 @@ app.get('/ts-web-readable-stream', async (_request, reply) => {
|
|
|
145
145
|
controller.close()
|
|
146
146
|
}
|
|
147
147
|
})
|
|
148
|
-
|
|
148
|
+
expect(reply.compress(stream)).type.toBe<void>()
|
|
149
149
|
})
|
package/.github/stale.yml
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# Number of days of inactivity before an issue becomes stale
|
|
2
|
-
daysUntilStale: 15
|
|
3
|
-
# Number of days of inactivity before a stale issue is closed
|
|
4
|
-
daysUntilClose: 7
|
|
5
|
-
# Issues with these labels will never be considered stale
|
|
6
|
-
exemptLabels:
|
|
7
|
-
- "discussion"
|
|
8
|
-
- "feature request"
|
|
9
|
-
- "bug"
|
|
10
|
-
- "help wanted"
|
|
11
|
-
- "plugin suggestion"
|
|
12
|
-
- "good first issue"
|
|
13
|
-
# Label to use when marking an issue as stale
|
|
14
|
-
staleLabel: stale
|
|
15
|
-
# Comment to post when marking an issue as stale. Set to `false` to disable
|
|
16
|
-
markComment: >
|
|
17
|
-
This issue has been automatically marked as stale because it has not had
|
|
18
|
-
recent activity. It will be closed if no further activity occurs. Thank you
|
|
19
|
-
for your contributions.
|
|
20
|
-
# Comment to post when closing a stale issue. Set to `false` to disable
|
|
21
|
-
closeComment: false
|