fastify 5.11.2 → 6.0.0-alpha.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/README.md +9 -9
- package/SPONSORS.md +1 -0
- package/build/build-validation.js +20 -34
- package/docs/Guides/Getting-Started.md +2 -2
- package/docs/Guides/Serverless.md +34 -2
- package/docs/Reference/Encapsulation.md +31 -2
- package/docs/Reference/Errors.md +81 -6
- package/docs/Reference/Hooks.md +0 -4
- package/docs/Reference/LTS.md +6 -5
- package/docs/Reference/Request.md +18 -6
- package/docs/Reference/Routes.md +13 -0
- package/docs/Reference/Server.md +8 -88
- package/docs/Reference/TypeScript.md +3 -49
- package/docs/Reference/Warnings.md +4 -11
- package/fastify.d.ts +10 -24
- package/fastify.js +17 -34
- package/lib/config-validator.js +368 -475
- package/lib/content-type-parser.js +4 -0
- package/lib/decorate.js +1 -1
- package/lib/errors.js +9 -3
- package/lib/log-controller.js +3 -5
- package/lib/logger-factory.js +1 -1
- package/lib/reply.js +7 -3
- package/lib/route.js +4 -9
- package/lib/server.js +2 -3
- package/lib/warnings.js +2 -46
- package/package.json +2 -3
- package/test/404s.test.js +0 -49
- package/test/allow-unsafe-regex.test.js +12 -4
- package/test/case-insensitive.test.js +12 -4
- package/test/content-parser.test.js +32 -0
- package/test/custom-querystring-parser.test.js +0 -16
- package/test/decorator-instance-properties.test.js +49 -0
- package/test/hooks.test.js +6 -1
- package/test/http-methods/custom-http-methods.test.js +12 -17
- package/test/http-methods/trace.test.js +1 -1
- package/test/https/custom-https-server.test.js +1 -1
- package/test/internals/errors.test.js +15 -5
- package/test/internals/initial-config.test.js +56 -38
- package/test/internals/logger.test.js +17 -4
- package/test/internals/reply.test.js +1 -1
- package/test/internals/request.test.js +8 -24
- package/test/logger/logging.test.js +2 -121
- package/test/logger/request.test.js +1 -36
- package/test/plugin.4.test.js +5 -4
- package/test/reply-trailers.test.js +92 -4
- package/test/route-prefix.test.js +46 -18
- package/test/route.1.test.js +2 -2
- package/test/router-options.test.js +25 -523
- package/test/set-error-handler.test.js +7 -9
- package/test/types/errors.tst.ts +2 -1
- package/test/types/fastify.tst.ts +44 -48
- package/test/types/instance.tst.ts +4 -5
- package/test/types/logger.tst.ts +3 -7
- package/test/use-semicolon-delimiter.test.js +0 -60
- package/types/context.d.ts +0 -20
- package/types/errors.d.ts +2 -1
- package/types/instance.d.ts +0 -4
- package/types/logger.d.ts +2 -17
- package/types/plugin.d.ts +0 -9
- package/types/request.d.ts +0 -4
- package/.pi/bash-confirm-whitelist.json +0 -180
- package/lib/promise.js +0 -23
- package/test/internals/promise.test.js +0 -63
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import Ajv, { ErrorObject as AjvErrorObject } from 'ajv'
|
|
1
2
|
import * as http from 'node:http'
|
|
2
3
|
import * as http2 from 'node:http2'
|
|
3
4
|
import * as https from 'node:https'
|
|
4
5
|
import { Socket } from 'node:net'
|
|
5
|
-
import Ajv, { ErrorObject as AjvErrorObject } from 'ajv'
|
|
6
6
|
import { expect } from 'tstyche'
|
|
7
7
|
import fastify, {
|
|
8
8
|
ConnectionError,
|
|
@@ -10,7 +10,6 @@ import fastify, {
|
|
|
10
10
|
FastifyError,
|
|
11
11
|
FastifyErrorCodes,
|
|
12
12
|
FastifyInstance,
|
|
13
|
-
FastifyPlugin,
|
|
14
13
|
FastifyPluginAsync,
|
|
15
14
|
FastifyPluginCallback,
|
|
16
15
|
InjectOptions,
|
|
@@ -127,9 +126,6 @@ expect(fastify({ pluginTimeout: 1000 })).type.toBeAssignableTo<FastifyInstance>(
|
|
|
127
126
|
expect(fastify({ bodyLimit: 100 })).type.toBeAssignableTo<FastifyInstance>()
|
|
128
127
|
expect(fastify({ handlerTimeout: 5000 })).type.toBeAssignableTo<FastifyInstance>()
|
|
129
128
|
expect(fastify({ maxParamLength: 100 })).type.toBeAssignableTo<FastifyInstance>()
|
|
130
|
-
expect(fastify({ disableRequestLogging: true })).type.toBeAssignableTo<FastifyInstance>()
|
|
131
|
-
expect(fastify({ disableRequestLogging: (req) => req.url?.includes('/health') ?? false })).type.toBeAssignableTo<FastifyInstance>()
|
|
132
|
-
expect(fastify({ requestIdLogLabel: 'request-id' })).type.toBeAssignableTo<FastifyInstance>()
|
|
133
129
|
expect(fastify({ onProtoPoisoning: 'error' })).type.toBeAssignableTo<FastifyInstance>()
|
|
134
130
|
expect(fastify({ onConstructorPoisoning: 'error' })).type.toBeAssignableTo<FastifyInstance>()
|
|
135
131
|
expect(fastify({ serializerOpts: { rounding: 'ceil' } })).type.toBeAssignableTo<FastifyInstance>()
|
|
@@ -188,7 +184,7 @@ expect(fastify({ logger: customLogger })).type.toBeAssignableTo<
|
|
|
188
184
|
FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse, FastifyBaseLogger>
|
|
189
185
|
>()
|
|
190
186
|
expect(fastify({ serverFactory: () => http.createServer() })).type.toBeAssignableTo<FastifyInstance>()
|
|
191
|
-
expect(fastify({ caseSensitive: true })).type.toBeAssignableTo<FastifyInstance>()
|
|
187
|
+
expect(fastify({ routerOptions: { caseSensitive: true } })).type.toBeAssignableTo<FastifyInstance>()
|
|
192
188
|
expect(fastify({ requestIdHeader: 'request-id' })).type.toBeAssignableTo<FastifyInstance>()
|
|
193
189
|
expect(fastify({ requestIdHeader: false })).type.toBeAssignableTo<FastifyInstance>()
|
|
194
190
|
expect(fastify({
|
|
@@ -198,45 +194,46 @@ expect(fastify({
|
|
|
198
194
|
}
|
|
199
195
|
})).type.toBeAssignableTo<FastifyInstance>()
|
|
200
196
|
expect(fastify({ trustProxy: true })).type.toBeAssignableTo<FastifyInstance>()
|
|
201
|
-
expect(fastify({ querystringParser: () => ({ foo: 'bar' }) })).type.toBeAssignableTo<FastifyInstance>()
|
|
202
|
-
expect(fastify({ querystringParser: () => ({ foo: { bar: 'fuzz' } }) })).type.toBeAssignableTo<FastifyInstance>()
|
|
203
|
-
expect(fastify({ querystringParser: () => ({ foo: ['bar', 'fuzz'] }) })).type.toBeAssignableTo<FastifyInstance>()
|
|
204
|
-
expect(fastify({ constraints: {} })).type.toBeAssignableTo<FastifyInstance>()
|
|
197
|
+
expect(fastify({ routerOptions: { querystringParser: () => ({ foo: 'bar' }) } })).type.toBeAssignableTo<FastifyInstance>()
|
|
198
|
+
expect(fastify({ routerOptions: { querystringParser: () => ({ foo: { bar: 'fuzz' } }) } })).type.toBeAssignableTo<FastifyInstance>()
|
|
199
|
+
expect(fastify({ routerOptions: { querystringParser: () => ({ foo: ['bar', 'fuzz'] }) } })).type.toBeAssignableTo<FastifyInstance>()
|
|
200
|
+
expect(fastify({ routerOptions: { constraints: {} } })).type.toBeAssignableTo<FastifyInstance>()
|
|
205
201
|
expect(fastify({
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
202
|
+
routerOptions: {
|
|
203
|
+
constraints: {
|
|
204
|
+
version: {
|
|
205
|
+
name: 'version',
|
|
206
|
+
storage: () => ({
|
|
207
|
+
get: () => () => { },
|
|
208
|
+
set: () => { },
|
|
209
|
+
del: () => { },
|
|
210
|
+
empty: () => { }
|
|
211
|
+
}),
|
|
212
|
+
validate () { },
|
|
213
|
+
deriveConstraint: () => 'foo'
|
|
214
|
+
},
|
|
215
|
+
host: {
|
|
216
|
+
name: 'host',
|
|
217
|
+
storage: () => ({
|
|
218
|
+
get: () => () => { },
|
|
219
|
+
set: () => { },
|
|
220
|
+
del: () => { },
|
|
221
|
+
empty: () => { }
|
|
222
|
+
}),
|
|
223
|
+
validate () { },
|
|
224
|
+
deriveConstraint: () => 'foo'
|
|
225
|
+
},
|
|
226
|
+
withObjectValue: {
|
|
227
|
+
name: 'withObjectValue',
|
|
228
|
+
storage: () => ({
|
|
229
|
+
get: () => () => { },
|
|
230
|
+
set: () => { },
|
|
231
|
+
del: () => { },
|
|
232
|
+
empty: () => { }
|
|
233
|
+
}),
|
|
234
|
+
validate () { },
|
|
235
|
+
deriveConstraint: () => { }
|
|
236
|
+
}
|
|
240
237
|
}
|
|
241
238
|
}
|
|
242
239
|
})).type.toBeAssignableTo<FastifyInstance>()
|
|
@@ -322,7 +319,6 @@ fastify().then(fastifyInstance => expect(fastifyInstance).type.toBeAssignableTo<
|
|
|
322
319
|
|
|
323
320
|
expect<FastifyPluginAsync>().type.toBeAssignableFrom(async () => { })
|
|
324
321
|
expect<FastifyPluginCallback>().type.toBeAssignableFrom(() => { })
|
|
325
|
-
expect<FastifyPlugin>().type.toBeAssignableFrom(() => { })
|
|
326
322
|
|
|
327
323
|
const ajvErrorObject: AjvErrorObject = {
|
|
328
324
|
keyword: '',
|
|
@@ -354,9 +350,9 @@ expect<RouteGenericInterface['Reply']>().type.toBe<unknown>()
|
|
|
354
350
|
// ErrorCodes
|
|
355
351
|
expect(fastify.errorCodes).type.toBe<FastifyErrorCodes>()
|
|
356
352
|
|
|
357
|
-
fastify({ allowUnsafeRegex: true })
|
|
358
|
-
fastify({ allowUnsafeRegex: false })
|
|
359
|
-
expect(fastify).type.not.toBeCallableWith({ allowUnsafeRegex: 'invalid' })
|
|
353
|
+
fastify({ routerOptions: { allowUnsafeRegex: true } })
|
|
354
|
+
fastify({ routerOptions: { allowUnsafeRegex: false } })
|
|
355
|
+
expect(fastify).type.not.toBeCallableWith({ routerOptions: { allowUnsafeRegex: 'invalid' } })
|
|
360
356
|
|
|
361
357
|
expect(fastify({ allowErrorHandlerOverride: true })).type.toBeAssignableTo<FastifyInstance>()
|
|
362
358
|
expect(fastify({ allowErrorHandlerOverride: false })).type.toBeAssignableTo<FastifyInstance>()
|
|
@@ -314,13 +314,11 @@ type InitialConfig = Readonly<{
|
|
|
314
314
|
https?: boolean | Readonly<{ allowHTTP1: boolean }>,
|
|
315
315
|
ignoreTrailingSlash?: boolean,
|
|
316
316
|
ignoreDuplicateSlashes?: boolean,
|
|
317
|
-
disableRequestLogging?: boolean | ((req: FastifyRequest) => boolean),
|
|
318
317
|
maxParamLength?: number,
|
|
319
318
|
onProtoPoisoning?: 'error' | 'remove' | 'ignore',
|
|
320
319
|
onConstructorPoisoning?: 'error' | 'remove' | 'ignore',
|
|
321
320
|
pluginTimeout?: number,
|
|
322
321
|
requestIdHeader?: string | false,
|
|
323
|
-
requestIdLogLabel?: string,
|
|
324
322
|
http2SessionTimeout?: number,
|
|
325
323
|
useSemicolonDelimiter?: boolean,
|
|
326
324
|
routerOptions?: FastifyRouterOptions<RawServerDefault>
|
|
@@ -328,9 +326,10 @@ type InitialConfig = Readonly<{
|
|
|
328
326
|
|
|
329
327
|
expect(fastify().initialConfig).type.toBe<InitialConfig>()
|
|
330
328
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
329
|
+
// TODO: we accept wider types than find-my-way and it cannot be assign to a restricted types
|
|
330
|
+
// expect<FastifyRouterOptions<RawServerDefault>>().type.toBeAssignableTo<
|
|
331
|
+
// FindMyWayConfig<FindMyWayVersion<RawServerDefault>>
|
|
332
|
+
// >()
|
|
334
333
|
|
|
335
334
|
fastify({
|
|
336
335
|
routerOptions: {
|
package/test/types/logger.tst.ts
CHANGED
|
@@ -10,7 +10,6 @@ import fastify, {
|
|
|
10
10
|
FastifyRequest,
|
|
11
11
|
LogLevel
|
|
12
12
|
} from '../../fastify.js'
|
|
13
|
-
import { ResSerializerReply } from '../../types/logger.js'
|
|
14
13
|
|
|
15
14
|
expect(fastify().log).type.toBe<FastifyBaseLogger>()
|
|
16
15
|
|
|
@@ -158,8 +157,7 @@ const serverWithPinoConfig = fastify({
|
|
|
158
157
|
}
|
|
159
158
|
},
|
|
160
159
|
res (reply) {
|
|
161
|
-
expect(reply).type.toBe<
|
|
162
|
-
expect(reply).type.toBeAssignableTo<Partial<FastifyReply> & Pick<FastifyReply, 'statusCode'>>()
|
|
160
|
+
expect(reply).type.toBe<Partial<FastifyReply>>()
|
|
163
161
|
expect(reply).type.not.toBeAssignableTo<FastifyReply>()
|
|
164
162
|
return {
|
|
165
163
|
statusCode: 'statusCode'
|
|
@@ -194,8 +192,7 @@ const serverAutoInferredSerializerResponseObjectOption = fastify({
|
|
|
194
192
|
logger: {
|
|
195
193
|
serializers: {
|
|
196
194
|
res (reply) {
|
|
197
|
-
expect(reply).type.toBe<
|
|
198
|
-
expect(reply).type.toBeAssignableTo<Partial<FastifyReply> & Pick<FastifyReply, 'statusCode'>>()
|
|
195
|
+
expect(reply).type.toBe<Partial<FastifyReply>>()
|
|
199
196
|
expect(reply).type.not.toBeAssignableTo<FastifyReply>()
|
|
200
197
|
return {
|
|
201
198
|
status: '200'
|
|
@@ -223,8 +220,7 @@ const serverAutoInferredSerializerObjectOption = fastify({
|
|
|
223
220
|
}
|
|
224
221
|
},
|
|
225
222
|
res (reply) {
|
|
226
|
-
expect(reply).type.toBe<
|
|
227
|
-
expect(reply).type.toBeAssignableTo<Partial<FastifyReply> & Pick<FastifyReply, 'statusCode'>>()
|
|
223
|
+
expect(reply).type.toBe<Partial<FastifyReply>>()
|
|
228
224
|
expect(reply).type.not.toBeAssignableTo<FastifyReply>()
|
|
229
225
|
return {
|
|
230
226
|
statusCode: 'statusCode'
|
|
@@ -23,66 +23,6 @@ test('use semicolon delimiter default false', async (t) => {
|
|
|
23
23
|
t.assert.deepStrictEqual(body, {})
|
|
24
24
|
})
|
|
25
25
|
|
|
26
|
-
test('use semicolon delimiter set to true', async (t) => {
|
|
27
|
-
t.plan(3)
|
|
28
|
-
const fastify = Fastify({
|
|
29
|
-
useSemicolonDelimiter: true
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
fastify.get('/1234', (req, reply) => {
|
|
33
|
-
reply.send(req.query)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
const fastifyServer = await fastify.listen({ port: 0 })
|
|
37
|
-
t.after(() => { fastify.close() })
|
|
38
|
-
|
|
39
|
-
const result = await fetch(fastifyServer + '/1234;foo=bar')
|
|
40
|
-
t.assert.ok(result.ok)
|
|
41
|
-
t.assert.strictEqual(result.status, 200)
|
|
42
|
-
t.assert.deepStrictEqual(await result.json(), {
|
|
43
|
-
foo: 'bar'
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('use semicolon delimiter set to false', async (t) => {
|
|
48
|
-
t.plan(3)
|
|
49
|
-
|
|
50
|
-
const fastify = Fastify({
|
|
51
|
-
useSemicolonDelimiter: false
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
fastify.get('/1234;foo=bar', (req, reply) => {
|
|
55
|
-
reply.send(req.query)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
const fastifyServer = await fastify.listen({ port: 0 })
|
|
59
|
-
t.after(() => { fastify.close() })
|
|
60
|
-
|
|
61
|
-
const result = await fetch(fastifyServer + '/1234;foo=bar')
|
|
62
|
-
t.assert.ok(result.ok)
|
|
63
|
-
t.assert.strictEqual(result.status, 200)
|
|
64
|
-
t.assert.deepStrictEqual(await result.json(), {})
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test('use semicolon delimiter set to false return 404', async (t) => {
|
|
68
|
-
t.plan(2)
|
|
69
|
-
|
|
70
|
-
const fastify = Fastify({
|
|
71
|
-
useSemicolonDelimiter: false
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
fastify.get('/1234', (req, reply) => {
|
|
75
|
-
reply.send(req.query)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
const fastifyServer = await fastify.listen({ port: 0 })
|
|
79
|
-
t.after(() => { fastify.close() })
|
|
80
|
-
|
|
81
|
-
const result = await fetch(fastifyServer + '/1234;foo=bar')
|
|
82
|
-
t.assert.ok(!result.ok)
|
|
83
|
-
t.assert.strictEqual(result.status, 404)
|
|
84
|
-
})
|
|
85
|
-
|
|
86
26
|
test('use routerOptions semicolon delimiter default false', async t => {
|
|
87
27
|
t.plan(3)
|
|
88
28
|
|
package/types/context.d.ts
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
import { FastifyRouteConfig } from './route'
|
|
2
|
-
import { ContextConfigDefault } from './utils'
|
|
3
|
-
|
|
4
1
|
export interface FastifyContextConfig {
|
|
5
2
|
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Route context object. Properties defined here will be available in the route's handler
|
|
9
|
-
*/
|
|
10
|
-
export interface FastifyRequestContext<ContextConfig = ContextConfigDefault> {
|
|
11
|
-
/**
|
|
12
|
-
* @deprecated Use Request#routeOptions#config or Request#routeOptions#schema instead
|
|
13
|
-
*/
|
|
14
|
-
config: FastifyContextConfig & FastifyRouteConfig & ContextConfig;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface FastifyReplyContext<ContextConfig = ContextConfigDefault> {
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated Use Reply#routeOptions#config or Reply#routeOptions#schema instead
|
|
20
|
-
*/
|
|
21
|
-
config: FastifyContextConfig & FastifyRouteConfig & ContextConfig;
|
|
22
|
-
}
|
package/types/errors.d.ts
CHANGED
|
@@ -74,6 +74,7 @@ export type FastifyErrorCodes = Record<
|
|
|
74
74
|
'FST_ERR_ROUTE_HANDLER_NOT_FN' |
|
|
75
75
|
'FST_ERR_ROUTE_MISSING_HANDLER' |
|
|
76
76
|
'FST_ERR_ROUTE_METHOD_INVALID' |
|
|
77
|
+
'FST_ERR_ROUTE_METHOD_ALREADY_SUPPORTED' |
|
|
77
78
|
'FST_ERR_ROUTE_METHOD_NOT_SUPPORTED' |
|
|
78
79
|
'FST_ERR_ROUTE_LOG_LEVEL_INVALID' |
|
|
79
80
|
'FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED' |
|
|
@@ -85,7 +86,7 @@ export type FastifyErrorCodes = Record<
|
|
|
85
86
|
'FST_ERR_ROUTE_MISSING_CONTENT' |
|
|
86
87
|
'FST_ERR_REOPENED_CLOSE_SERVER' |
|
|
87
88
|
'FST_ERR_REOPENED_SERVER' |
|
|
88
|
-
'
|
|
89
|
+
'FST_ERR_INSTANCE_ALREADY_STARTED' |
|
|
89
90
|
'FST_ERR_PLUGIN_VERSION_MISMATCH' |
|
|
90
91
|
'FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE' |
|
|
91
92
|
'FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER' |
|
package/types/instance.d.ts
CHANGED
|
@@ -701,15 +701,11 @@ export interface FastifyInstance<
|
|
|
701
701
|
https?: boolean | Readonly<{ allowHTTP1: boolean }>,
|
|
702
702
|
ignoreTrailingSlash?: boolean,
|
|
703
703
|
ignoreDuplicateSlashes?: boolean,
|
|
704
|
-
/** @deprecated Use the `logController` option with `disableRequestLogging` or `isLogDisabled` override instead. Will be removed in `fastify@6`. */
|
|
705
|
-
disableRequestLogging?: boolean | ((req: FastifyRequest) => boolean),
|
|
706
704
|
maxParamLength?: number,
|
|
707
705
|
onProtoPoisoning?: ProtoAction,
|
|
708
706
|
onConstructorPoisoning?: ConstructorAction,
|
|
709
707
|
pluginTimeout?: number,
|
|
710
708
|
requestIdHeader?: string | false,
|
|
711
|
-
/** @deprecated Use the `logController` option with `requestIdLogLabel` instead. Will be removed in `fastify@6`. */
|
|
712
|
-
requestIdLogLabel?: string,
|
|
713
709
|
http2SessionTimeout?: number,
|
|
714
710
|
useSemicolonDelimiter?: boolean,
|
|
715
711
|
routerOptions?: FastifyRouterOptions<RawServer>
|
package/types/logger.d.ts
CHANGED
|
@@ -28,25 +28,10 @@ export interface FastifyBaseLogger extends Pick<BaseLogger, 'level' | 'info' | '
|
|
|
28
28
|
child(bindings: Bindings, options?: ChildLoggerOptions): FastifyBaseLogger
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
// TODO delete FastifyLoggerInstance in the next major release. It seems that it is enough to have only FastifyBaseLogger.
|
|
32
|
-
/**
|
|
33
|
-
* @deprecated Use FastifyBaseLogger instead
|
|
34
|
-
*/
|
|
35
|
-
export type FastifyLoggerInstance = FastifyBaseLogger
|
|
36
|
-
|
|
37
31
|
export interface FastifyLoggerStreamDestination {
|
|
38
32
|
write(msg: string): void;
|
|
39
33
|
}
|
|
40
34
|
|
|
41
|
-
// TODO: once node 18 is EOL, this type can be replaced with plain FastifyReply.
|
|
42
|
-
/**
|
|
43
|
-
* Specialized reply type used for the `res` log serializer, since only `statusCode` is passed in certain cases.
|
|
44
|
-
*/
|
|
45
|
-
export type ResSerializerReply<
|
|
46
|
-
RawServer extends RawServerBase,
|
|
47
|
-
RawReply extends FastifyReply<RouteGenericInterface, RawServer>
|
|
48
|
-
> = Partial<RawReply> & Pick<RawReply, 'statusCode'>
|
|
49
|
-
|
|
50
35
|
/**
|
|
51
36
|
* Fastify Custom Logger options.
|
|
52
37
|
*/
|
|
@@ -99,7 +84,7 @@ export interface FastifyLoggerOptions<
|
|
|
99
84
|
stack: string;
|
|
100
85
|
[key: string]: unknown;
|
|
101
86
|
};
|
|
102
|
-
res?: (res:
|
|
87
|
+
res?: (res: Partial<RawReply>) => {
|
|
103
88
|
statusCode?: string | number;
|
|
104
89
|
[key: string]: unknown;
|
|
105
90
|
};
|
|
@@ -124,7 +109,7 @@ export declare class LogController {
|
|
|
124
109
|
isLogDisabled (request: FastifyRequest): boolean
|
|
125
110
|
incomingRequest (request: FastifyRequest, reply: FastifyReply, metadata?: Record<string, unknown>): void
|
|
126
111
|
requestCompleted (
|
|
127
|
-
error: Error | null,
|
|
112
|
+
error: Error | null | undefined,
|
|
128
113
|
request: FastifyRequest,
|
|
129
114
|
reply: FastifyReply,
|
|
130
115
|
metadata?: Record<string, unknown>
|
package/types/plugin.d.ts
CHANGED
|
@@ -37,12 +37,3 @@ export type FastifyPluginAsync<
|
|
|
37
37
|
TypeProvider>,
|
|
38
38
|
opts: Options
|
|
39
39
|
) => Promise<void>
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Generic plugin type.
|
|
43
|
-
* @deprecated union type doesn't work well with type inference in TS and is therefore deprecated in favor of explicit types. Use `FastifyPluginCallback` or `FastifyPluginAsync` instead. To activate
|
|
44
|
-
* plugins use `FastifyRegister`. https://fastify.dev/docs/latest/Reference/TypeScript/#register
|
|
45
|
-
*/
|
|
46
|
-
export type FastifyPlugin<
|
|
47
|
-
Options extends FastifyPluginOptions = Record<never, never>
|
|
48
|
-
> = FastifyPluginCallback<Options> | FastifyPluginAsync<Options>
|
package/types/request.d.ts
CHANGED
|
@@ -67,10 +67,6 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
|
|
|
67
67
|
/** in order for this to be used the user should ensure they have set the attachValidation option. */
|
|
68
68
|
validationError?: Error & { validation: any; validationContext: string };
|
|
69
69
|
|
|
70
|
-
/**
|
|
71
|
-
* @deprecated Use `raw` property
|
|
72
|
-
*/
|
|
73
|
-
readonly req: RawRequest & RouteGeneric['Headers']; // this enables the developer to extend the existing http(s|2) headers list
|
|
74
70
|
/**
|
|
75
71
|
* Derived from request socket metadata or forwarding headers.
|
|
76
72
|
* Treat as untrusted input and validate before security-sensitive use.
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"entries": [
|
|
3
|
-
{
|
|
4
|
-
"type": "exact",
|
|
5
|
-
"value": "git fetch --all --prune --quiet && echo FETCH_OK || echo FETCH_FAILED",
|
|
6
|
-
"addedAt": "2026-02-07T10:03:03.909Z",
|
|
7
|
-
"note": "Always accept",
|
|
8
|
-
"source": "user"
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"type": "exact",
|
|
12
|
-
"value": "npm install --ignore-scripts",
|
|
13
|
-
"addedAt": "2026-02-07T10:21:13.104Z",
|
|
14
|
-
"note": "Always accept",
|
|
15
|
-
"source": "user"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"type": "exact",
|
|
19
|
-
"value": "npm run coverage:ci-check-coverage",
|
|
20
|
-
"addedAt": "2026-02-07T15:10:08.412Z",
|
|
21
|
-
"note": "Always accept",
|
|
22
|
-
"source": "user"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"type": "exact",
|
|
26
|
-
"value": "node --test test/web-api.test.js",
|
|
27
|
-
"addedAt": "2026-02-07T15:24:46.872Z",
|
|
28
|
-
"note": "Always accept",
|
|
29
|
-
"source": "user"
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"type": "exact",
|
|
33
|
-
"value": "gpg --list-secret-keys --keyid-format=long || true && git config --get user.signingkey && git config --get commit.gpgsign",
|
|
34
|
-
"addedAt": "2026-02-11T04:42:44.716Z",
|
|
35
|
-
"note": "Always accept",
|
|
36
|
-
"source": "user"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"type": "exact",
|
|
40
|
-
"value": "cd /home/matteo/repositories/fastify && npm run test:typescript",
|
|
41
|
-
"addedAt": "2026-02-19T20:22:59.298Z",
|
|
42
|
-
"note": "Always accept",
|
|
43
|
-
"source": "user"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"type": "exact",
|
|
47
|
-
"value": "cd /home/matteo/repositories/fastify && git checkout -- types/route.d.ts",
|
|
48
|
-
"addedAt": "2026-02-19T20:23:45.912Z",
|
|
49
|
-
"note": "Always accept",
|
|
50
|
-
"source": "user"
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
"type": "exact",
|
|
54
|
-
"value": "cd /home/matteo/repositories/fastify && git status --short && git diff -- types/route.d.ts test/types/route.test-d.ts | sed -n '1,220p'",
|
|
55
|
-
"addedAt": "2026-02-19T20:25:10.175Z",
|
|
56
|
-
"note": "Always accept",
|
|
57
|
-
"source": "user"
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
"type": "exact",
|
|
61
|
-
"value": "cd /home/matteo/repositories/fastify && git checkout -- types/route.d.ts test/types/route.test-d.ts && npm run test:typescript",
|
|
62
|
-
"addedAt": "2026-02-19T20:25:56.421Z",
|
|
63
|
-
"note": "Always accept",
|
|
64
|
-
"source": "user"
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
"type": "exact",
|
|
68
|
-
"value": "cd /home/matteo/repositories/fastify && npm run lint:eslint -- types/route.d.ts test/types/route.test-d.ts",
|
|
69
|
-
"addedAt": "2026-02-19T20:27:12.547Z",
|
|
70
|
-
"note": "Always accept",
|
|
71
|
-
"source": "user"
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
"type": "exact",
|
|
75
|
-
"value": "cd /home/matteo/repositories/fastify && git checkout -b fix/6513-route-hook-meta-return",
|
|
76
|
-
"addedAt": "2026-02-19T20:27:31.569Z",
|
|
77
|
-
"note": "Always accept",
|
|
78
|
-
"source": "user"
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
"type": "exact",
|
|
82
|
-
"value": "cd /home/matteo/repositories/fastify && git add types/route.d.ts test/types/route.test-d.ts && git commit -m \"fix(types): allow async route hooks in shorthand options\"",
|
|
83
|
-
"addedAt": "2026-02-19T20:27:35.261Z",
|
|
84
|
-
"note": "Always accept",
|
|
85
|
-
"source": "user"
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
"type": "exact",
|
|
89
|
-
"value": "cd /home/matteo/repositories/fastify && npx tsc /tmp/ctx-test2.ts --noEmit --strict",
|
|
90
|
-
"addedAt": "2026-02-19T20:44:45.451Z",
|
|
91
|
-
"note": "Always accept",
|
|
92
|
-
"source": "user"
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
"type": "exact",
|
|
96
|
-
"value": "cd /home/matteo/repositories/fastify && npx tsd --files test/types/hooks.test-d.ts",
|
|
97
|
-
"addedAt": "2026-02-19T20:47:16.815Z",
|
|
98
|
-
"note": "Always accept",
|
|
99
|
-
"source": "user"
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
"type": "exact",
|
|
103
|
-
"value": "cd /home/matteo/repositories/fastify && npx tsd --files test/types/route.test-d.ts",
|
|
104
|
-
"addedAt": "2026-02-19T20:47:37.607Z",
|
|
105
|
-
"note": "Always accept",
|
|
106
|
-
"source": "user"
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
"type": "exact",
|
|
110
|
-
"value": "cd /home/matteo/repositories/fastify && npx tsd",
|
|
111
|
-
"addedAt": "2026-02-19T20:48:17.812Z",
|
|
112
|
-
"note": "Always accept",
|
|
113
|
-
"source": "user"
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
"type": "exact",
|
|
117
|
-
"value": "cd /home/matteo/repositories/fastify && npm run lint:eslint -- types/route.d.ts && npx tsd --files test/types/hooks.test-d.ts && npx tsd --files test/types/route.test-d.ts",
|
|
118
|
-
"addedAt": "2026-02-19T20:51:05.173Z",
|
|
119
|
-
"note": "Always accept",
|
|
120
|
-
"source": "user"
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
"type": "exact",
|
|
124
|
-
"value": "which gh && gh --version && gh auth status",
|
|
125
|
-
"addedAt": "2026-02-20T07:03:43.023Z",
|
|
126
|
-
"note": "Always accept",
|
|
127
|
-
"source": "user"
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
"type": "exact",
|
|
131
|
-
"value": "gh api repos/fastify/fastify/rulesets",
|
|
132
|
-
"addedAt": "2026-02-22T22:29:22.020Z",
|
|
133
|
-
"note": "Always accept",
|
|
134
|
-
"source": "user"
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
"type": "exact",
|
|
138
|
-
"value": "node --test test/fastify-instance.test.js",
|
|
139
|
-
"addedAt": "2026-02-23T07:23:34.147Z",
|
|
140
|
-
"note": "Always accept",
|
|
141
|
-
"source": "user"
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
"type": "exact",
|
|
145
|
-
"value": "nl -ba scripts/validate-ecosystem-links.js | sed -n '1,220p'",
|
|
146
|
-
"addedAt": "2026-02-23T07:23:55.927Z",
|
|
147
|
-
"note": "Always accept",
|
|
148
|
-
"source": "user"
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
"type": "pattern",
|
|
152
|
-
"value": "^npx\\s+eslint\\s+[\\w./~-]+\\s+[\\w./~-]+\\s+[\\w./~-]+\\s+[\\w./~-]+$",
|
|
153
|
-
"addedAt": "2026-03-09T12:41:11.065Z",
|
|
154
|
-
"note": "Always accept generic",
|
|
155
|
-
"source": "ai"
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
"type": "pattern",
|
|
159
|
-
"value": "^node\\s+--test\\s+[\\w./~-]+\\s+[\\w./~-]+$",
|
|
160
|
-
"addedAt": "2026-03-09T12:41:58.425Z",
|
|
161
|
-
"note": "Always accept generic",
|
|
162
|
-
"source": "ai"
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
"type": "pattern",
|
|
166
|
-
"value": "^npm\\s+run\\s+test:typescript$",
|
|
167
|
-
"addedAt": "2026-03-09T12:42:48.283Z",
|
|
168
|
-
"note": "Always accept generic",
|
|
169
|
-
"source": "ai"
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
"type": "exact",
|
|
173
|
-
"value": "gh search code \"request.host org:fastify\" --limit 20 --json repository,path,url",
|
|
174
|
-
"addedAt": "2026-03-09T21:03:22.953Z",
|
|
175
|
-
"note": "Always accept exact",
|
|
176
|
-
"source": "user"
|
|
177
|
-
}
|
|
178
|
-
],
|
|
179
|
-
"version": 2
|
|
180
|
-
}
|
package/lib/promise.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { kTestInternals } = require('./symbols')
|
|
4
|
-
|
|
5
|
-
function withResolvers () {
|
|
6
|
-
let res, rej
|
|
7
|
-
const promise = new Promise((resolve, reject) => {
|
|
8
|
-
res = resolve
|
|
9
|
-
rej = reject
|
|
10
|
-
})
|
|
11
|
-
return { promise, resolve: res, reject: rej }
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = {
|
|
15
|
-
// TODO(20.x): remove when node@20 is not supported
|
|
16
|
-
withResolvers: typeof Promise.withResolvers === 'function'
|
|
17
|
-
? Promise.withResolvers.bind(Promise) // Promise.withResolvers must bind to itself
|
|
18
|
-
/* c8 ignore next */
|
|
19
|
-
: withResolvers, // Tested using the kTestInternals
|
|
20
|
-
[kTestInternals]: {
|
|
21
|
-
withResolvers
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { test } = require('node:test')
|
|
4
|
-
|
|
5
|
-
const { kTestInternals } = require('../../lib/symbols')
|
|
6
|
-
const PonyPromise = require('../../lib/promise')
|
|
7
|
-
|
|
8
|
-
test('withResolvers', async (t) => {
|
|
9
|
-
t.plan(3)
|
|
10
|
-
await t.test('resolve', async (t) => {
|
|
11
|
-
t.plan(1)
|
|
12
|
-
const { promise, resolve } = PonyPromise.withResolvers()
|
|
13
|
-
resolve(true)
|
|
14
|
-
t.assert.ok(await promise)
|
|
15
|
-
})
|
|
16
|
-
await t.test('reject', async (t) => {
|
|
17
|
-
t.plan(1)
|
|
18
|
-
const { promise, reject } = PonyPromise.withResolvers()
|
|
19
|
-
await t.assert.rejects(async () => {
|
|
20
|
-
reject(Error('reject'))
|
|
21
|
-
return promise
|
|
22
|
-
}, {
|
|
23
|
-
name: 'Error',
|
|
24
|
-
message: 'reject'
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
await t.test('thenable', async (t) => {
|
|
28
|
-
t.plan(1)
|
|
29
|
-
const { promise, resolve } = PonyPromise.withResolvers()
|
|
30
|
-
resolve(true)
|
|
31
|
-
promise.then((value) => {
|
|
32
|
-
t.assert.ok(value)
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
test('withResolvers - ponyfill', async (t) => {
|
|
38
|
-
await t.test('resolve', async (t) => {
|
|
39
|
-
t.plan(1)
|
|
40
|
-
const { promise, resolve } = PonyPromise[kTestInternals].withResolvers()
|
|
41
|
-
resolve(true)
|
|
42
|
-
t.assert.ok(await promise)
|
|
43
|
-
})
|
|
44
|
-
await t.test('reject', async (t) => {
|
|
45
|
-
t.plan(1)
|
|
46
|
-
const { promise, reject } = PonyPromise[kTestInternals].withResolvers()
|
|
47
|
-
await t.assert.rejects(async () => {
|
|
48
|
-
reject(Error('reject'))
|
|
49
|
-
return promise
|
|
50
|
-
}, {
|
|
51
|
-
name: 'Error',
|
|
52
|
-
message: 'reject'
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
await t.test('thenable', async (t) => {
|
|
56
|
-
t.plan(1)
|
|
57
|
-
const { promise, resolve } = PonyPromise.withResolvers()
|
|
58
|
-
resolve(true)
|
|
59
|
-
promise.then((value) => {
|
|
60
|
-
t.assert.ok(value)
|
|
61
|
-
})
|
|
62
|
-
})
|
|
63
|
-
})
|