fastify 3.25.3 → 3.27.2
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/LICENSE +1 -1
- package/build/build-validation.js +2 -0
- package/docs/Guides/Ecosystem.md +2 -1
- package/docs/Guides/Index.md +2 -0
- package/docs/Guides/Prototype-Poisoning.md +391 -0
- package/docs/Guides/Recommendations.md +1 -1
- package/docs/Reference/ContentTypeParser.md +4 -1
- package/docs/Reference/Plugins.md +4 -4
- package/docs/Reference/Request.md +3 -0
- package/docs/Reference/Server.md +52 -2
- package/docs/Reference/TypeScript.md +1 -1
- package/docs/Reference/Validation-and-Serialization.md +4 -1
- package/fastify.d.ts +3 -1
- package/fastify.js +41 -21
- package/lib/decorate.js +2 -2
- package/lib/errors.js +6 -1
- package/lib/noop-set.js +10 -0
- package/lib/pluginUtils.js +5 -0
- package/lib/reply.js +21 -11
- package/lib/route.js +34 -1
- package/lib/schema-controller.js +1 -1
- package/lib/server.js +1 -1
- package/lib/symbols.js +3 -1
- package/package.json +16 -17
- package/test/404s.test.js +25 -1
- package/test/async-await.test.js +3 -3
- package/test/bundler/esbuild/bundler-test.js +31 -0
- package/test/bundler/esbuild/package.json +10 -0
- package/test/bundler/esbuild/src/fail-plugin-version.js +12 -0
- package/test/bundler/esbuild/src/index.js +7 -0
- package/test/bundler/webpack/bundler-test.js +15 -4
- package/test/bundler/webpack/src/fail-plugin-version.js +1 -3
- package/test/bundler/webpack/src/index.js +1 -3
- package/test/close.test.js +39 -1
- package/test/context-config.test.js +4 -4
- package/test/custom-parser.test.js +30 -31
- package/test/inject.test.js +1 -1
- package/test/internals/all.test.js +2 -2
- package/test/internals/contentTypeParser.test.js +4 -4
- package/test/internals/handleRequest.test.js +8 -8
- package/test/internals/logger.test.js +1 -1
- package/test/logger.test.js +18 -18
- package/test/maxRequestsPerSocket.test.js +2 -2
- package/test/noop-set.test.js +19 -0
- package/test/plugin.name.display.js +10 -0
- package/test/plugin.test.js +18 -0
- package/test/route.test.js +12 -0
- package/test/schema-serialization.test.js +41 -0
- package/test/skip-reply-send.test.js +7 -7
- package/test/trust-proxy.test.js +1 -1
- package/test/types/fastify.test-d.ts +18 -0
- package/test/types/hooks.test-d.ts +34 -6
- package/test/types/instance.test-d.ts +26 -1
- package/test/validation-error-handling.test.js +1 -1
- package/test/versioned-routes.test.js +28 -4
- package/types/.eslintrc.json +1 -1
- package/types/hooks.d.ts +24 -20
- package/types/instance.d.ts +13 -1
- package/types/register.d.ts +1 -1
- package/types/schema.d.ts +14 -0
|
@@ -57,6 +57,7 @@ fastify({ http2: true, https: {} }).inject({}, lightMyRequestCallback)
|
|
|
57
57
|
expectAssignable<FastifyInstance<http2.Http2Server, http2.Http2ServerRequest, http2.Http2ServerResponse>>(fastify({ http2: true }))
|
|
58
58
|
expectAssignable<FastifyInstance>(fastify({ ignoreTrailingSlash: true }))
|
|
59
59
|
expectAssignable<FastifyInstance>(fastify({ connectionTimeout: 1000 }))
|
|
60
|
+
expectAssignable<FastifyInstance>(fastify({ forceCloseConnections: true }))
|
|
60
61
|
expectAssignable<FastifyInstance>(fastify({ keepAliveTimeout: 1000 }))
|
|
61
62
|
expectAssignable<FastifyInstance>(fastify({ pluginTimeout: 1000 }))
|
|
62
63
|
expectAssignable<FastifyInstance>(fastify({ bodyLimit: 100 }))
|
|
@@ -178,6 +179,22 @@ expectAssignable<FastifyInstance>(fastify({
|
|
|
178
179
|
plugins: [() => { }]
|
|
179
180
|
}
|
|
180
181
|
}))
|
|
182
|
+
expectAssignable<FastifyInstance>(fastify({
|
|
183
|
+
ajv: {
|
|
184
|
+
customOptions: {
|
|
185
|
+
nullable: false
|
|
186
|
+
},
|
|
187
|
+
plugins: [[() => { }, 'keyword']]
|
|
188
|
+
}
|
|
189
|
+
}))
|
|
190
|
+
expectAssignable<FastifyInstance>(fastify({
|
|
191
|
+
ajv: {
|
|
192
|
+
customOptions: {
|
|
193
|
+
nullable: false
|
|
194
|
+
},
|
|
195
|
+
plugins: [[() => { }, ['keyword1', 'keyword2']]]
|
|
196
|
+
}
|
|
197
|
+
}))
|
|
181
198
|
expectAssignable<FastifyInstance>(fastify({ frameworkErrors: () => { } }))
|
|
182
199
|
expectAssignable<FastifyInstance>(fastify({
|
|
183
200
|
rewriteUrl: (req) => req.url === '/hi' ? '/hello' : req.url!
|
|
@@ -189,6 +206,7 @@ expectAssignable<FastifyInstance>(fastify({
|
|
|
189
206
|
expectType<Socket>(socket)
|
|
190
207
|
}
|
|
191
208
|
}))
|
|
209
|
+
expectAssignable<FastifyInstance>(fastify({ jsonShorthand: true }))
|
|
192
210
|
|
|
193
211
|
// Thenable
|
|
194
212
|
expectAssignable<PromiseLike<FastifyInstance>>(fastify({ return503OnClosing: true }))
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import fastify, { RouteOptions, FastifyReply, FastifyRequest } from '../../fastify'
|
|
2
|
-
import { expectType, expectError, expectAssignable } from 'tsd'
|
|
3
|
-
import { FastifyInstance } from '../../types/instance'
|
|
4
1
|
import { FastifyError } from 'fastify-error'
|
|
5
|
-
import {
|
|
2
|
+
import { expectAssignable, expectError, expectType } from 'tsd'
|
|
3
|
+
import fastify, {
|
|
4
|
+
FastifyInstance,
|
|
5
|
+
FastifyReply,
|
|
6
|
+
FastifyRequest,
|
|
7
|
+
RawReplyDefaultExpression,
|
|
8
|
+
RawRequestDefaultExpression,
|
|
9
|
+
RawServerBase,
|
|
10
|
+
RouteOptions,
|
|
11
|
+
RegisterOptions,
|
|
12
|
+
FastifyPluginOptions
|
|
13
|
+
} from '../../fastify'
|
|
14
|
+
import { preHandlerAsyncHookHandler, RequestPayload } from '../../types/hooks'
|
|
6
15
|
|
|
7
16
|
const server = fastify()
|
|
8
17
|
|
|
@@ -106,8 +115,9 @@ server.addHook('onRoute', function (opts) {
|
|
|
106
115
|
expectType<RouteOptions & { routePath: string; path: string; prefix: string}>(opts)
|
|
107
116
|
})
|
|
108
117
|
|
|
109
|
-
server.addHook('onRegister', (instance, done) => {
|
|
118
|
+
server.addHook('onRegister', (instance, opts, done) => {
|
|
110
119
|
expectType<FastifyInstance>(instance)
|
|
120
|
+
expectType<RegisterOptions & FastifyPluginOptions>(opts)
|
|
111
121
|
expectAssignable<(err?: FastifyError) => void>(done)
|
|
112
122
|
expectAssignable<(err?: NodeJS.ErrnoException) => void>(done)
|
|
113
123
|
expectType<void>(done(new Error()))
|
|
@@ -187,8 +197,9 @@ server.addHook('onError', async function (request, reply, error) {
|
|
|
187
197
|
expectType<FastifyError>(error)
|
|
188
198
|
})
|
|
189
199
|
|
|
190
|
-
server.addHook('onRegister', async (instance) => {
|
|
200
|
+
server.addHook('onRegister', async (instance, opts) => {
|
|
191
201
|
expectType<FastifyInstance>(instance)
|
|
202
|
+
expectType<RegisterOptions & FastifyPluginOptions>(opts)
|
|
192
203
|
})
|
|
193
204
|
|
|
194
205
|
server.addHook('onReady', async function () {
|
|
@@ -198,3 +209,20 @@ server.addHook('onReady', async function () {
|
|
|
198
209
|
server.addHook('onClose', async (instance) => {
|
|
199
210
|
expectType<FastifyInstance>(instance)
|
|
200
211
|
})
|
|
212
|
+
|
|
213
|
+
// Use case to monitor any regression on issue #3620
|
|
214
|
+
// ref.: https://github.com/fastify/fastify/issues/3620
|
|
215
|
+
const customTypedHook: preHandlerAsyncHookHandler<
|
|
216
|
+
RawServerBase,
|
|
217
|
+
RawRequestDefaultExpression,
|
|
218
|
+
RawReplyDefaultExpression,
|
|
219
|
+
Record<string, unknown>
|
|
220
|
+
> = async function (request, reply) {
|
|
221
|
+
expectType<FastifyInstance>(this)
|
|
222
|
+
expectAssignable<FastifyRequest>(request)
|
|
223
|
+
expectAssignable<FastifyReply>(reply)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
server.register(async (instance) => {
|
|
227
|
+
instance.addHook('preHandler', customTypedHook)
|
|
228
|
+
})
|
|
@@ -10,6 +10,7 @@ import { expectAssignable, expectError, expectType } from 'tsd'
|
|
|
10
10
|
import { FastifyRequest } from '../../types/request'
|
|
11
11
|
import { FastifyReply } from '../../types/reply'
|
|
12
12
|
import { HookHandlerDoneFunction } from '../../types/hooks'
|
|
13
|
+
import { FastifySchemaControllerOptions } from '../../types/schema'
|
|
13
14
|
|
|
14
15
|
const server = fastify()
|
|
15
16
|
|
|
@@ -53,7 +54,7 @@ function asyncNodeJSErrorHandler (error: NodeJS.ErrnoException) {}
|
|
|
53
54
|
server.setErrorHandler(asyncNodeJSErrorHandler)
|
|
54
55
|
|
|
55
56
|
class CustomError extends Error {
|
|
56
|
-
private __brand: any
|
|
57
|
+
private __brand: any
|
|
57
58
|
}
|
|
58
59
|
interface ReplyPayload {
|
|
59
60
|
Reply: {
|
|
@@ -112,6 +113,29 @@ server.setNotFoundHandler({ preHandler: notFoundpreHandlerHandler, preValidation
|
|
|
112
113
|
function invalidErrorHandler (error: number) {}
|
|
113
114
|
expectError(server.setErrorHandler(invalidErrorHandler))
|
|
114
115
|
|
|
116
|
+
server.setSchemaController({
|
|
117
|
+
bucket: (parentSchemas: unknown) => {
|
|
118
|
+
return {
|
|
119
|
+
addSchema (schema: unknown) {
|
|
120
|
+
expectType<unknown>(schema)
|
|
121
|
+
expectType<FastifyInstance>(server.addSchema({ type: 'null' }))
|
|
122
|
+
return server.addSchema({ type: 'null' })
|
|
123
|
+
},
|
|
124
|
+
getSchema (schemaId: string) {
|
|
125
|
+
expectType<string>(schemaId)
|
|
126
|
+
return server.getSchema('SchemaId')
|
|
127
|
+
},
|
|
128
|
+
getSchemas () {
|
|
129
|
+
expectType<Record<string, unknown>>(server.getSchemas())
|
|
130
|
+
return server.getSchemas()
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
function invalidSchemaController (schemaControllerOptions: FastifySchemaControllerOptions) {}
|
|
137
|
+
expectError(server.setSchemaController(invalidSchemaController))
|
|
138
|
+
|
|
115
139
|
server.setReplySerializer(function (payload, statusCode) {
|
|
116
140
|
expectType<unknown>(payload)
|
|
117
141
|
expectType<number>(statusCode)
|
|
@@ -171,6 +195,7 @@ type InitialConfig = Readonly<{
|
|
|
171
195
|
keepAliveTimeout?: number,
|
|
172
196
|
bodyLimit?: number,
|
|
173
197
|
caseSensitive?: boolean,
|
|
198
|
+
forceCloseConnections?: boolean,
|
|
174
199
|
http2?: boolean,
|
|
175
200
|
https?: boolean | Readonly<{ allowHTTP1: boolean }>,
|
|
176
201
|
ignoreTrailingSlash?: boolean,
|
|
@@ -140,7 +140,7 @@ test('error inside custom error handler should have validationContext if specifi
|
|
|
140
140
|
return function (data) {
|
|
141
141
|
const error = new Error('this failed')
|
|
142
142
|
error.validationContext = 'customContext'
|
|
143
|
-
return { error
|
|
143
|
+
return { error }
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
}, function (req, reply) {
|
|
@@ -296,10 +296,25 @@ test('Shorthand route declaration', t => {
|
|
|
296
296
|
})
|
|
297
297
|
})
|
|
298
298
|
|
|
299
|
-
test('The not found handler should not
|
|
300
|
-
t.plan(
|
|
299
|
+
test('The not found handler should not erase the Accept-Version header', t => {
|
|
300
|
+
t.plan(13)
|
|
301
301
|
const fastify = Fastify()
|
|
302
302
|
|
|
303
|
+
fastify.addHook('onRequest', function (req, reply, done) {
|
|
304
|
+
t.same(req.headers['accept-version'], '2.x')
|
|
305
|
+
done()
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
fastify.addHook('preValidation', function (req, reply, done) {
|
|
309
|
+
t.same(req.headers['accept-version'], '2.x')
|
|
310
|
+
done()
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
fastify.addHook('preHandler', function (req, reply, done) {
|
|
314
|
+
t.same(req.headers['accept-version'], '2.x')
|
|
315
|
+
done()
|
|
316
|
+
})
|
|
317
|
+
|
|
303
318
|
fastify.route({
|
|
304
319
|
method: 'GET',
|
|
305
320
|
url: '/',
|
|
@@ -310,7 +325,16 @@ test('The not found handler should not use the Accept-Version header', t => {
|
|
|
310
325
|
})
|
|
311
326
|
|
|
312
327
|
fastify.setNotFoundHandler(function (req, reply) {
|
|
313
|
-
t.
|
|
328
|
+
t.same(req.headers['accept-version'], '2.x')
|
|
329
|
+
// we check if the symbol is exposed on key or not
|
|
330
|
+
for (const key in req.headers) {
|
|
331
|
+
t.same(typeof key, 'string')
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
for (const key of Object.keys(req.headers)) {
|
|
335
|
+
t.same(typeof key, 'string')
|
|
336
|
+
}
|
|
337
|
+
|
|
314
338
|
reply.code(404).send('not found handler')
|
|
315
339
|
})
|
|
316
340
|
|
|
@@ -409,7 +433,7 @@ test('test log stream', t => {
|
|
|
409
433
|
const stream = split(JSON.parse)
|
|
410
434
|
const fastify = Fastify({
|
|
411
435
|
logger: {
|
|
412
|
-
stream
|
|
436
|
+
stream,
|
|
413
437
|
level: 'info'
|
|
414
438
|
}
|
|
415
439
|
})
|
package/types/.eslintrc.json
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"files": ["*.test-d.ts"],
|
|
32
32
|
"rules": {
|
|
33
33
|
"no-unused-vars": "off",
|
|
34
|
-
"
|
|
34
|
+
"n/handle-callback-err": "off",
|
|
35
35
|
"@typescript-eslint/no-empty-function": "off",
|
|
36
36
|
"@typescript-eslint/explicit-function-return-type": "off",
|
|
37
37
|
"@typescript-eslint/no-unused-vars": "off",
|
package/types/hooks.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { FastifyRequest } from './request'
|
|
|
6
6
|
import { FastifyReply } from './reply'
|
|
7
7
|
import { FastifyError } from 'fastify-error'
|
|
8
8
|
import { FastifyLoggerInstance } from './logger'
|
|
9
|
+
import { RegisterOptions } from './register'
|
|
10
|
+
import { FastifyPluginOptions } from './plugin'
|
|
9
11
|
|
|
10
12
|
type HookHandlerDoneFunction = <TError extends Error = FastifyError>(err?: TError) => void
|
|
11
13
|
|
|
@@ -27,7 +29,7 @@ export interface onRequestHookHandler<
|
|
|
27
29
|
ContextConfig = ContextConfigDefault
|
|
28
30
|
> {
|
|
29
31
|
(
|
|
30
|
-
this: FastifyInstance
|
|
32
|
+
this: FastifyInstance,
|
|
31
33
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
32
34
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
33
35
|
done: HookHandlerDoneFunction
|
|
@@ -42,7 +44,7 @@ export interface onRequestAsyncHookHandler<
|
|
|
42
44
|
ContextConfig = ContextConfigDefault
|
|
43
45
|
> {
|
|
44
46
|
(
|
|
45
|
-
this: FastifyInstance
|
|
47
|
+
this: FastifyInstance,
|
|
46
48
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
47
49
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
48
50
|
): Promise<unknown>;
|
|
@@ -60,7 +62,7 @@ export interface preParsingHookHandler<
|
|
|
60
62
|
ContextConfig = ContextConfigDefault
|
|
61
63
|
> {
|
|
62
64
|
(
|
|
63
|
-
this: FastifyInstance
|
|
65
|
+
this: FastifyInstance,
|
|
64
66
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
65
67
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
66
68
|
payload: RequestPayload,
|
|
@@ -76,7 +78,7 @@ export interface preParsingAsyncHookHandler<
|
|
|
76
78
|
ContextConfig = ContextConfigDefault
|
|
77
79
|
> {
|
|
78
80
|
(
|
|
79
|
-
this: FastifyInstance
|
|
81
|
+
this: FastifyInstance,
|
|
80
82
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
81
83
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
82
84
|
payload: RequestPayload,
|
|
@@ -94,7 +96,7 @@ export interface preValidationHookHandler<
|
|
|
94
96
|
ContextConfig = ContextConfigDefault
|
|
95
97
|
> {
|
|
96
98
|
(
|
|
97
|
-
this: FastifyInstance
|
|
99
|
+
this: FastifyInstance,
|
|
98
100
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
99
101
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
100
102
|
done: HookHandlerDoneFunction
|
|
@@ -109,7 +111,7 @@ export interface preValidationAsyncHookHandler<
|
|
|
109
111
|
ContextConfig = ContextConfigDefault
|
|
110
112
|
> {
|
|
111
113
|
(
|
|
112
|
-
this: FastifyInstance
|
|
114
|
+
this: FastifyInstance,
|
|
113
115
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
114
116
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
115
117
|
): Promise<unknown>;
|
|
@@ -126,7 +128,7 @@ export interface preHandlerHookHandler<
|
|
|
126
128
|
ContextConfig = ContextConfigDefault
|
|
127
129
|
> {
|
|
128
130
|
(
|
|
129
|
-
this: FastifyInstance
|
|
131
|
+
this: FastifyInstance,
|
|
130
132
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
131
133
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
132
134
|
done: HookHandlerDoneFunction
|
|
@@ -141,7 +143,7 @@ export interface preHandlerAsyncHookHandler<
|
|
|
141
143
|
ContextConfig = ContextConfigDefault
|
|
142
144
|
> {
|
|
143
145
|
(
|
|
144
|
-
this: FastifyInstance
|
|
146
|
+
this: FastifyInstance,
|
|
145
147
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
146
148
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
147
149
|
): Promise<unknown>;
|
|
@@ -167,7 +169,7 @@ export interface preSerializationHookHandler<
|
|
|
167
169
|
ContextConfig = ContextConfigDefault
|
|
168
170
|
> {
|
|
169
171
|
(
|
|
170
|
-
this: FastifyInstance
|
|
172
|
+
this: FastifyInstance,
|
|
171
173
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
172
174
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
173
175
|
payload: PreSerializationPayload,
|
|
@@ -184,7 +186,7 @@ export interface preSerializationAsyncHookHandler<
|
|
|
184
186
|
ContextConfig = ContextConfigDefault
|
|
185
187
|
> {
|
|
186
188
|
(
|
|
187
|
-
this: FastifyInstance
|
|
189
|
+
this: FastifyInstance,
|
|
188
190
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
189
191
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
190
192
|
payload: PreSerializationPayload
|
|
@@ -204,7 +206,7 @@ export interface onSendHookHandler<
|
|
|
204
206
|
ContextConfig = ContextConfigDefault
|
|
205
207
|
> {
|
|
206
208
|
(
|
|
207
|
-
this: FastifyInstance
|
|
209
|
+
this: FastifyInstance,
|
|
208
210
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
209
211
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
210
212
|
payload: OnSendPayload,
|
|
@@ -221,7 +223,7 @@ export interface onSendAsyncHookHandler<
|
|
|
221
223
|
ContextConfig = ContextConfigDefault
|
|
222
224
|
> {
|
|
223
225
|
(
|
|
224
|
-
this: FastifyInstance
|
|
226
|
+
this: FastifyInstance,
|
|
225
227
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
226
228
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
227
229
|
payload: OnSendPayload,
|
|
@@ -240,7 +242,7 @@ export interface onResponseHookHandler<
|
|
|
240
242
|
ContextConfig = ContextConfigDefault
|
|
241
243
|
> {
|
|
242
244
|
(
|
|
243
|
-
this: FastifyInstance
|
|
245
|
+
this: FastifyInstance,
|
|
244
246
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
245
247
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
246
248
|
done: HookHandlerDoneFunction
|
|
@@ -255,7 +257,7 @@ export interface onResponseAsyncHookHandler<
|
|
|
255
257
|
ContextConfig = ContextConfigDefault
|
|
256
258
|
> {
|
|
257
259
|
(
|
|
258
|
-
this: FastifyInstance
|
|
260
|
+
this: FastifyInstance,
|
|
259
261
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
260
262
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
261
263
|
): Promise<unknown>;
|
|
@@ -273,7 +275,7 @@ export interface onTimeoutHookHandler<
|
|
|
273
275
|
ContextConfig = ContextConfigDefault
|
|
274
276
|
> {
|
|
275
277
|
(
|
|
276
|
-
this: FastifyInstance
|
|
278
|
+
this: FastifyInstance,
|
|
277
279
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
278
280
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
279
281
|
done: HookHandlerDoneFunction
|
|
@@ -288,7 +290,7 @@ export interface onTimeoutAsyncHookHandler<
|
|
|
288
290
|
ContextConfig = ContextConfigDefault
|
|
289
291
|
> {
|
|
290
292
|
(
|
|
291
|
-
this: FastifyInstance
|
|
293
|
+
this: FastifyInstance,
|
|
292
294
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
293
295
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
294
296
|
): Promise<unknown>;
|
|
@@ -309,7 +311,7 @@ export interface onErrorHookHandler<
|
|
|
309
311
|
TError extends Error = FastifyError
|
|
310
312
|
> {
|
|
311
313
|
(
|
|
312
|
-
this: FastifyInstance
|
|
314
|
+
this: FastifyInstance,
|
|
313
315
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
314
316
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
315
317
|
error: TError,
|
|
@@ -326,7 +328,7 @@ export interface onErrorAsyncHookHandler<
|
|
|
326
328
|
TError extends Error = FastifyError
|
|
327
329
|
> {
|
|
328
330
|
(
|
|
329
|
-
this: FastifyInstance
|
|
331
|
+
this: FastifyInstance,
|
|
330
332
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
331
333
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
332
334
|
error: TError
|
|
@@ -346,7 +348,7 @@ export interface onRouteHookHandler<
|
|
|
346
348
|
ContextConfig = ContextConfigDefault
|
|
347
349
|
> {
|
|
348
350
|
(
|
|
349
|
-
this: FastifyInstance
|
|
351
|
+
this: FastifyInstance,
|
|
350
352
|
opts: RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> & { routePath: string; path: string; prefix: string }
|
|
351
353
|
): Promise<unknown> | void;
|
|
352
354
|
}
|
|
@@ -360,10 +362,12 @@ export interface onRegisterHookHandler<
|
|
|
360
362
|
RawServer extends RawServerBase = RawServerDefault,
|
|
361
363
|
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
362
364
|
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
363
|
-
Logger = FastifyLoggerInstance
|
|
365
|
+
Logger = FastifyLoggerInstance,
|
|
366
|
+
Options extends FastifyPluginOptions = FastifyPluginOptions
|
|
364
367
|
> {
|
|
365
368
|
(
|
|
366
369
|
instance: FastifyInstance<RawServer, RawRequest, RawReply, Logger>,
|
|
370
|
+
opts: RegisterOptions & Options,
|
|
367
371
|
done: HookHandlerDoneFunction
|
|
368
372
|
): Promise<unknown> | void; // documentation is missing the `done` method
|
|
369
373
|
}
|
package/types/instance.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Chain as LightMyRequestChain, InjectOptions, Response as LightMyRequestResponse, CallbackFunc as LightMyRequestCallback } from 'light-my-request'
|
|
2
2
|
import { RouteOptions, RouteShorthandMethod, RouteGenericInterface, DefaultRoute } from './route'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
FastifySchema,
|
|
5
|
+
FastifySchemaCompiler,
|
|
6
|
+
FastifySchemaValidationError,
|
|
7
|
+
FastifySerializerCompiler,
|
|
8
|
+
FastifySchemaControllerOptions
|
|
9
|
+
} from './schema'
|
|
4
10
|
import { RawServerBase, RawRequestDefaultExpression, RawServerDefault, RawReplyDefaultExpression, ContextConfigDefault } from './utils'
|
|
5
11
|
import { FastifyLoggerInstance } from './logger'
|
|
6
12
|
import { FastifyRegister } from './register'
|
|
@@ -380,6 +386,11 @@ export interface FastifyInstance<
|
|
|
380
386
|
*/
|
|
381
387
|
setSerializerCompiler<T = FastifySchema>(schemaCompiler: FastifySerializerCompiler<T>): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
382
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Set the schema controller for all routes.
|
|
391
|
+
*/
|
|
392
|
+
setSchemaController(schemaControllerOpts: FastifySchemaControllerOptions): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
393
|
+
|
|
383
394
|
/**
|
|
384
395
|
* Set the reply serializer for all routes.
|
|
385
396
|
*/
|
|
@@ -427,6 +438,7 @@ export interface FastifyInstance<
|
|
|
427
438
|
initialConfig: Readonly<{
|
|
428
439
|
connectionTimeout?: number,
|
|
429
440
|
keepAliveTimeout?: number,
|
|
441
|
+
forceCloseConnections?: boolean,
|
|
430
442
|
bodyLimit?: number,
|
|
431
443
|
caseSensitive?: boolean,
|
|
432
444
|
http2?: boolean,
|
package/types/register.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { FastifyPluginOptions, FastifyPluginCallback, FastifyPluginAsync } from
|
|
|
2
2
|
import { LogLevel } from './logger'
|
|
3
3
|
import { FastifyInstance } from './instance'
|
|
4
4
|
|
|
5
|
-
interface RegisterOptions {
|
|
5
|
+
export interface RegisterOptions {
|
|
6
6
|
prefix?: string;
|
|
7
7
|
logLevel?: LogLevel;
|
|
8
8
|
logSerializers?: Record<string, (value: any) => string>;
|
package/types/schema.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ValidatorCompiler } from '@fastify/ajv-compiler'
|
|
2
|
+
import { FastifyInstance, FastifyServerOptions } from '../fastify'
|
|
1
3
|
/**
|
|
2
4
|
* Schemas in Fastify follow the JSON-Schema standard. For this reason
|
|
3
5
|
* we have opted to not ship strict schema based types. Instead we provide
|
|
@@ -36,3 +38,15 @@ export interface FastifyValidationResult {
|
|
|
36
38
|
export type FastifySchemaCompiler<T> = (routeSchema: FastifyRouteSchemaDef<T>) => FastifyValidationResult
|
|
37
39
|
|
|
38
40
|
export type FastifySerializerCompiler<T> = (routeSchema: FastifyRouteSchemaDef<T>) => (data: any) => string
|
|
41
|
+
|
|
42
|
+
export interface FastifySchemaControllerOptions{
|
|
43
|
+
bucket?: (parentSchemas?: unknown) => {
|
|
44
|
+
addSchema(schema: unknown): FastifyInstance;
|
|
45
|
+
getSchema(schemaId: string): unknown;
|
|
46
|
+
getSchemas(): Record<string, unknown>;
|
|
47
|
+
};
|
|
48
|
+
compilersFactory?: {
|
|
49
|
+
buildValidator?: ValidatorCompiler;
|
|
50
|
+
buildSerializer?: (externalSchemas: unknown, serializerOptsServerOption: FastifyServerOptions['serializerOpts']) => FastifySerializerCompiler<unknown>;
|
|
51
|
+
};
|
|
52
|
+
}
|