fastify 4.2.0 → 4.4.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.
Files changed (63) hide show
  1. package/README.md +13 -14
  2. package/docs/Guides/Database.md +2 -2
  3. package/docs/Guides/Ecosystem.md +42 -18
  4. package/docs/Guides/Migration-Guide-V4.md +29 -0
  5. package/docs/Guides/Plugins-Guide.md +5 -0
  6. package/docs/Reference/HTTP2.md +1 -3
  7. package/docs/Reference/Hooks.md +4 -1
  8. package/docs/Reference/Logging.md +1 -1
  9. package/docs/Reference/Reply.md +177 -0
  10. package/docs/Reference/Request.md +171 -0
  11. package/docs/Reference/Routes.md +4 -2
  12. package/docs/Reference/Server.md +4 -1
  13. package/docs/Reference/Type-Providers.md +1 -15
  14. package/docs/Reference/TypeScript.md +27 -3
  15. package/fastify.d.ts +1 -1
  16. package/fastify.js +3 -3
  17. package/lib/contentTypeParser.js +10 -2
  18. package/lib/context.js +10 -1
  19. package/lib/error-serializer.js +12 -12
  20. package/lib/errors.js +8 -0
  21. package/lib/handleRequest.js +2 -2
  22. package/lib/httpMethods.js +22 -0
  23. package/lib/reply.js +101 -24
  24. package/lib/request.js +97 -1
  25. package/lib/route.js +3 -1
  26. package/lib/symbols.js +15 -9
  27. package/package.json +7 -7
  28. package/test/build/error-serializer.test.js +3 -1
  29. package/test/content-parser.test.js +15 -0
  30. package/test/copy.test.js +41 -0
  31. package/test/internals/all.test.js +8 -2
  32. package/test/internals/reply-serialize.test.js +583 -0
  33. package/test/internals/reply.test.js +4 -1
  34. package/test/internals/request-validate.test.js +1269 -0
  35. package/test/internals/request.test.js +11 -2
  36. package/test/lock.test.js +73 -0
  37. package/test/mkcol.test.js +38 -0
  38. package/test/move.test.js +45 -0
  39. package/test/propfind.test.js +108 -0
  40. package/test/proppatch.test.js +78 -0
  41. package/test/request-error.test.js +44 -1
  42. package/test/schema-validation.test.js +71 -0
  43. package/test/search.test.js +100 -0
  44. package/test/trace.test.js +21 -0
  45. package/test/types/fastify.test-d.ts +12 -1
  46. package/test/types/hooks.test-d.ts +1 -2
  47. package/test/types/import.ts +1 -1
  48. package/test/types/instance.test-d.ts +4 -1
  49. package/test/types/logger.test-d.ts +4 -5
  50. package/test/types/reply.test-d.ts +44 -3
  51. package/test/types/request.test-d.ts +10 -29
  52. package/test/types/type-provider.test-d.ts +79 -7
  53. package/test/unlock.test.js +41 -0
  54. package/test/validation-error-handling.test.js +6 -1
  55. package/types/hooks.d.ts +19 -39
  56. package/types/instance.d.ts +78 -130
  57. package/types/logger.d.ts +7 -4
  58. package/types/reply.d.ts +7 -1
  59. package/types/request.d.ts +16 -3
  60. package/types/route.d.ts +23 -29
  61. package/types/schema.d.ts +4 -1
  62. package/types/type-provider.d.ts +8 -20
  63. package/types/utils.d.ts +2 -1
@@ -1,6 +1,6 @@
1
- import * as http from 'http'
2
1
  import { FastifyError } from '@fastify/error'
3
2
  import { ConstraintStrategy, HTTPVersion } from 'find-my-way'
3
+ import * as http from 'http'
4
4
  import { CallbackFunc as LightMyRequestCallback, Chain as LightMyRequestChain, InjectOptions, Response as LightMyRequestResponse } from 'light-my-request'
5
5
  import { AddContentTypeParser, ConstructorAction, FastifyBodyParser, getDefaultJsonParser, hasContentTypeParser, ProtoAction, removeAllContentTypeParsers, removeContentTypeParser } from './content-type-parser'
6
6
  import { onCloseAsyncHookHandler, onCloseHookHandler, onErrorAsyncHookHandler, onErrorHookHandler, onReadyAsyncHookHandler, onReadyHookHandler, onRegisterHookHandler, onRequestAsyncHookHandler, onRequestHookHandler, onResponseAsyncHookHandler, onResponseHookHandler, onRouteHookHandler, onSendAsyncHookHandler, onSendHookHandler, onTimeoutAsyncHookHandler, onTimeoutHookHandler, preHandlerAsyncHookHandler, preHandlerHookHandler, preParsingAsyncHookHandler, preParsingHookHandler, preSerializationAsyncHookHandler, preSerializationHookHandler, preValidationAsyncHookHandler, preValidationHookHandler } from './hooks'
@@ -17,10 +17,8 @@ import {
17
17
  FastifySerializerCompiler
18
18
  } from './schema'
19
19
  import {
20
- FastifyRequestType,
21
20
  FastifyTypeProvider,
22
- FastifyTypeProviderDefault,
23
- ResolveFastifyRequestType
21
+ FastifyTypeProviderDefault
24
22
  } from './type-provider'
25
23
  import { ContextConfigDefault, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault } from './utils'
26
24
 
@@ -30,6 +28,52 @@ export interface PrintRoutesOptions {
30
28
  includeHooks?: boolean
31
29
  }
32
30
 
31
+ export interface FastifyListenOptions {
32
+ /**
33
+ * Default to `0` (picks the first available open port).
34
+ */
35
+ port?: number;
36
+ /**
37
+ * Default to `localhost`.
38
+ */
39
+ host?: string;
40
+ /**
41
+ * Will be ignored if `port` is specified.
42
+ * @see [Identifying paths for IPC connections](https://nodejs.org/api/net.html#identifying-paths-for-ipc-connections).
43
+ */
44
+ path?: string;
45
+ /**
46
+ * Specify the maximum length of the queue of pending connections.
47
+ * The actual length will be determined by the OS through sysctl settings such as `tcp_max_syn_backlog` and `somaxconn` on Linux.
48
+ * Default to `511`.
49
+ */
50
+ backlog?: number;
51
+ /**
52
+ * Default to `false`.
53
+ */
54
+ exclusive?: boolean;
55
+ /**
56
+ * For IPC servers makes the pipe readable for all users.
57
+ * Default to `false`.
58
+ */
59
+ readableAll?: boolean;
60
+ /**
61
+ * For IPC servers makes the pipe writable for all users.
62
+ * Default to `false`.
63
+ */
64
+ writableAll?: boolean;
65
+ /**
66
+ * For TCP servers, setting `ipv6Only` to `true` will disable dual-stack support, i.e., binding to host `::` won't make `0.0.0.0` be bound.
67
+ * Default to `false`.
68
+ */
69
+ ipv6Only?: boolean;
70
+ /**
71
+ * An AbortSignal that may be used to close a listening server.
72
+ * @since This option is available only in Node.js v15.6.0 and greater
73
+ */
74
+ signal?: AbortSignal;
75
+ }
76
+
33
77
  type NotInInterface<Key, _Interface> = Key extends keyof _Interface ? never : Key
34
78
  type FindMyWayVersion<RawServer extends RawServerBase> = RawServer extends http.Server ? HTTPVersion.V1 : HTTPVersion.V2
35
79
 
@@ -93,96 +137,8 @@ export interface FastifyInstance<
93
137
  inject(opts: InjectOptions | string): Promise<LightMyRequestResponse>;
94
138
  inject(): LightMyRequestChain;
95
139
 
96
- listen(opts: {
97
- /**
98
- * Default to `0` (picks the first available open port).
99
- */
100
- port?: number;
101
- /**
102
- * Default to `localhost`.
103
- */
104
- host?: string;
105
- /**
106
- * Will be ignored if `port` is specified.
107
- * @see [Identifying paths for IPC connections](https://nodejs.org/api/net.html#identifying-paths-for-ipc-connections).
108
- */
109
- path?: string;
110
- /**
111
- * Specify the maximum length of the queue of pending connections.
112
- * The actual length will be determined by the OS through sysctl settings such as `tcp_max_syn_backlog` and `somaxconn` on Linux.
113
- * Default to `511`.
114
- */
115
- backlog?: number;
116
- /**
117
- * Default to `false`.
118
- */
119
- exclusive?: boolean;
120
- /**
121
- * For IPC servers makes the pipe readable for all users.
122
- * Default to `false`.
123
- */
124
- readableAll?: boolean;
125
- /**
126
- * For IPC servers makes the pipe writable for all users.
127
- * Default to `false`.
128
- */
129
- writableAll?: boolean;
130
- /**
131
- * For TCP servers, setting `ipv6Only` to `true` will disable dual-stack support, i.e., binding to host `::` won't make `0.0.0.0` be bound.
132
- * Default to `false`.
133
- */
134
- ipv6Only?: boolean;
135
- /**
136
- * An AbortSignal that may be used to close a listening server.
137
- * @since This option is available only in Node.js v15.6.0 and greater
138
- */
139
- signal?: AbortSignal;
140
- }, callback: (err: Error|null, address: string) => void): void;
141
- listen(opts?: {
142
- /**
143
- * Default to `0` (picks the first available open port).
144
- */
145
- port?: number;
146
- /**
147
- * Default to `localhost`.
148
- */
149
- host?: string;
150
- /**
151
- * Will be ignored if `port` is specified.
152
- * @see [Identifying paths for IPC connections](https://nodejs.org/api/net.html#identifying-paths-for-ipc-connections).
153
- */
154
- path?: string;
155
- /**
156
- * Specify the maximum length of the queue of pending connections.
157
- * The actual length will be determined by the OS through sysctl settings such as `tcp_max_syn_backlog` and `somaxconn` on Linux.
158
- * Default to `511`.
159
- */
160
- backlog?: number;
161
- /**
162
- * Default to `false`.
163
- */
164
- exclusive?: boolean;
165
- /**
166
- * For IPC servers makes the pipe readable for all users.
167
- * Default to `false`.
168
- */
169
- readableAll?: boolean;
170
- /**
171
- * For IPC servers makes the pipe writable for all users.
172
- * Default to `false`.
173
- */
174
- writableAll?: boolean;
175
- /**
176
- * For TCP servers, setting `ipv6Only` to `true` will disable dual-stack support, i.e., binding to host `::` won't make `0.0.0.0` be bound.
177
- * Default to `false`.
178
- */
179
- ipv6Only?: boolean;
180
- /**
181
- * An AbortSignal that may be used to close a listening server.
182
- * @since This option is available only in Node.js v15.6.0 and greater
183
- */
184
- signal?: AbortSignal;
185
- }): Promise<string>;
140
+ listen(opts: FastifyListenOptions, callback: (err: Error | null, address: string) => void): void;
141
+ listen(opts?: FastifyListenOptions): Promise<string>;
186
142
  listen(callback: (err: Error | null, address: string) => void): void;
187
143
 
188
144
  /**
@@ -242,22 +198,20 @@ export interface FastifyInstance<
242
198
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
243
199
  ContextConfig = ContextConfigDefault,
244
200
  SchemaCompiler extends FastifySchema = FastifySchema,
245
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
246
201
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
247
202
  >(
248
203
  name: 'onRequest',
249
- hook: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
204
+ hook: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
250
205
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
251
206
 
252
207
  addHook<
253
208
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
254
209
  ContextConfig = ContextConfigDefault,
255
210
  SchemaCompiler extends FastifySchema = FastifySchema,
256
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
257
211
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
258
212
  >(
259
213
  name: 'onRequest',
260
- hook: onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
214
+ hook: onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
261
215
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
262
216
 
263
217
  /**
@@ -268,22 +222,20 @@ export interface FastifyInstance<
268
222
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
269
223
  ContextConfig = ContextConfigDefault,
270
224
  SchemaCompiler extends FastifySchema = FastifySchema,
271
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
272
225
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
273
226
  >(
274
227
  name: 'preParsing',
275
- hook: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
228
+ hook: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
276
229
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
277
230
 
278
231
  addHook<
279
232
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
280
233
  ContextConfig = ContextConfigDefault,
281
234
  SchemaCompiler extends FastifySchema = FastifySchema,
282
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
283
235
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
284
236
  >(
285
237
  name: 'preParsing',
286
- hook: preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
238
+ hook: preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
287
239
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
288
240
 
289
241
  /**
@@ -293,22 +245,20 @@ export interface FastifyInstance<
293
245
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
294
246
  ContextConfig = ContextConfigDefault,
295
247
  SchemaCompiler extends FastifySchema = FastifySchema,
296
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
297
248
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
298
249
  >(
299
250
  name: 'preValidation',
300
- hook: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
251
+ hook: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
301
252
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
302
253
 
303
254
  addHook<
304
255
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
305
256
  ContextConfig = ContextConfigDefault,
306
257
  SchemaCompiler extends FastifySchema = FastifySchema,
307
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
308
258
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
309
259
  >(
310
260
  name: 'preValidation',
311
- hook: preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
261
+ hook: preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
312
262
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
313
263
 
314
264
  /**
@@ -318,22 +268,20 @@ export interface FastifyInstance<
318
268
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
319
269
  ContextConfig = ContextConfigDefault,
320
270
  SchemaCompiler extends FastifySchema = FastifySchema,
321
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
322
271
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
323
272
  >(
324
273
  name: 'preHandler',
325
- hook: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
274
+ hook: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
326
275
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
327
276
 
328
277
  addHook<
329
278
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
330
279
  ContextConfig = ContextConfigDefault,
331
280
  SchemaCompiler extends FastifySchema = FastifySchema,
332
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
333
281
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
334
282
  >(
335
283
  name: 'preHandler',
336
- hook: preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
284
+ hook: preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
337
285
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
338
286
 
339
287
  /**
@@ -345,11 +293,10 @@ export interface FastifyInstance<
345
293
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
346
294
  ContextConfig = ContextConfigDefault,
347
295
  SchemaCompiler extends FastifySchema = FastifySchema,
348
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
349
296
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
350
297
  >(
351
298
  name: 'preSerialization',
352
- hook: preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
299
+ hook: preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
353
300
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
354
301
 
355
302
  addHook<
@@ -357,11 +304,10 @@ export interface FastifyInstance<
357
304
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
358
305
  ContextConfig = ContextConfigDefault,
359
306
  SchemaCompiler extends FastifySchema = FastifySchema,
360
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
361
307
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
362
308
  >(
363
309
  name: 'preSerialization',
364
- hook: preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
310
+ hook: preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
365
311
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
366
312
 
367
313
  /**
@@ -373,11 +319,10 @@ export interface FastifyInstance<
373
319
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
374
320
  ContextConfig = ContextConfigDefault,
375
321
  SchemaCompiler extends FastifySchema = FastifySchema,
376
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
377
322
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
378
323
  >(
379
324
  name: 'onSend',
380
- hook: onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
325
+ hook: onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
381
326
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
382
327
 
383
328
  addHook<
@@ -385,11 +330,10 @@ export interface FastifyInstance<
385
330
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
386
331
  ContextConfig = ContextConfigDefault,
387
332
  SchemaCompiler extends FastifySchema = FastifySchema,
388
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
389
333
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
390
334
  >(
391
335
  name: 'onSend',
392
- hook: onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
336
+ hook: onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
393
337
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
394
338
 
395
339
  /**
@@ -400,22 +344,20 @@ export interface FastifyInstance<
400
344
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
401
345
  ContextConfig = ContextConfigDefault,
402
346
  SchemaCompiler extends FastifySchema = FastifySchema,
403
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
404
347
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
405
348
  >(
406
349
  name: 'onResponse',
407
- hook: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
350
+ hook: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
408
351
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
409
352
 
410
353
  addHook<
411
354
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
412
355
  ContextConfig = ContextConfigDefault,
413
356
  SchemaCompiler extends FastifySchema = FastifySchema,
414
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
415
357
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
416
358
  >(
417
359
  name: 'onResponse',
418
- hook: onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
360
+ hook: onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
419
361
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
420
362
 
421
363
  /**
@@ -426,22 +368,20 @@ export interface FastifyInstance<
426
368
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
427
369
  ContextConfig = ContextConfigDefault,
428
370
  SchemaCompiler extends FastifySchema = FastifySchema,
429
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
430
371
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
431
372
  >(
432
373
  name: 'onTimeout',
433
- hook: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
374
+ hook: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
434
375
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
435
376
 
436
377
  addHook<
437
378
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
438
379
  ContextConfig = ContextConfigDefault,
439
380
  SchemaCompiler extends FastifySchema = FastifySchema,
440
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
441
381
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
442
382
  >(
443
383
  name: 'onTimeout',
444
- hook: onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
384
+ hook: onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
445
385
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
446
386
 
447
387
  /**
@@ -454,22 +394,20 @@ export interface FastifyInstance<
454
394
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
455
395
  ContextConfig = ContextConfigDefault,
456
396
  SchemaCompiler extends FastifySchema = FastifySchema,
457
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
458
397
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
459
398
  >(
460
399
  name: 'onError',
461
- hook: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, RequestType, Logger>
400
+ hook: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>
462
401
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
463
402
 
464
403
  addHook<
465
404
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
466
405
  ContextConfig = ContextConfigDefault,
467
406
  SchemaCompiler extends FastifySchema = FastifySchema,
468
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
469
407
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
470
408
  >(
471
409
  name: 'onError',
472
- hook: onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, RequestType, Logger>
410
+ hook: onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>
473
411
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
474
412
 
475
413
  // Application addHooks
@@ -550,11 +488,21 @@ export interface FastifyInstance<
550
488
  handler: (this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, error: TError, request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>, reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfigDefault, SchemaCompiler, TypeProvider>) => any | Promise<any>
551
489
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
552
490
 
491
+ /**
492
+ * Fastify schema validator for all routes.
493
+ */
494
+ validatorCompiler: FastifySchemaCompiler<any> | undefined;
495
+
553
496
  /**
554
497
  * Set the schema validator for all routes.
555
498
  */
556
499
  setValidatorCompiler<T = FastifySchema>(schemaCompiler: FastifySchemaCompiler<T>): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
557
500
 
501
+ /**
502
+ * Fastify schema serializer for all routes.
503
+ */
504
+ serializerCompiler: FastifySerializerCompiler<any> | undefined;
505
+
558
506
  /**
559
507
  * Set the schema serializer for all routes.
560
508
  */
package/types/logger.d.ts CHANGED
@@ -19,13 +19,16 @@ export type Bindings = pino.Bindings
19
19
 
20
20
  export type ChildLoggerOptions = pino.ChildLoggerOptions
21
21
 
22
- export type FastifyLoggerInstance = pino.Logger
23
- // TODO make pino export BaseLogger again
24
- // export type FastifyBaseLogger = pino.BaseLogger & {
25
- export type FastifyBaseLogger = pino.Logger & {
22
+ export type FastifyBaseLogger = pino.BaseLogger & {
26
23
  child(bindings: Bindings, options?: ChildLoggerOptions): FastifyBaseLogger
27
24
  }
28
25
 
26
+ // TODO delete FastifyLoggerInstance in the next major release. It seems that it is enough to have only FastifyBaseLogger.
27
+ /**
28
+ * @deprecated Use FastifyBaseLogger instead
29
+ */
30
+ export type FastifyLoggerInstance = FastifyBaseLogger
31
+
29
32
  export interface FastifyLoggerStreamDestination {
30
33
  write(msg: string): void;
31
34
  }
package/types/reply.d.ts CHANGED
@@ -38,7 +38,7 @@ export interface FastifyReply<
38
38
  send(payload?: ReplyType): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>;
39
39
  header(key: string, value: any): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>;
40
40
  headers(values: {[key: string]: any}): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>;
41
- getHeader(key: string): string | undefined;
41
+ getHeader(key: string): number | string | string[] | undefined;
42
42
  getHeaders(): {
43
43
  // Node's `getHeaders()` can return numbers and arrays, so they're included here as possible types.
44
44
  [key: string]: number | string | string[] | undefined;
@@ -54,5 +54,11 @@ export interface FastifyReply<
54
54
  type(contentType: string): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>;
55
55
  serializer(fn: (payload: any) => string): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>;
56
56
  serialize(payload: any): string | ArrayBuffer | Buffer;
57
+ // Serialization Methods
58
+ getSerializationFunction(httpStatus: string): (payload: {[key: string]: unknown}) => string;
59
+ getSerializationFunction(schema: {[key: string]: unknown}): (payload: {[key: string]: unknown}) => string;
60
+ compileSerializationSchema(schema: {[key: string]: unknown}, httpStatus?: string): (payload: {[key: string]: unknown}) => string;
61
+ serializeInput(input: {[key: string]: unknown}, schema: {[key: string]: unknown}, httpStatus?: string): string;
62
+ serializeInput(input: {[key: string]: unknown}, httpStatus: string): unknown;
57
63
  then(fulfilled: () => void, rejected: (err: Error) => void): void;
58
64
  }
@@ -6,6 +6,7 @@ import { FastifyTypeProvider, FastifyTypeProviderDefault, FastifyRequestType, Re
6
6
  import { FastifySchema } from './schema'
7
7
  import { FastifyContext } from './context'
8
8
 
9
+ type HTTPRequestPart = 'body' | 'query' | 'querystring' | 'params' | 'headers'
9
10
  export interface RequestGenericInterface {
10
11
  Body?: RequestBodyDefault;
11
12
  Querystring?: RequestQuerystringDefault;
@@ -23,11 +24,17 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
23
24
  SchemaCompiler extends FastifySchema = FastifySchema,
24
25
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
25
26
  ContextConfig = ContextConfigDefault,
26
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
27
- Logger extends FastifyLoggerInstance = FastifyLoggerInstance
27
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance,
28
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>
29
+ // ^ Temporary Note: RequestType has been re-ordered to be the last argument in
30
+ // generic list. This generic argument is now considered optional as it can be
31
+ // automatically inferred from the SchemaCompiler, RouteGeneric and TypeProvider
32
+ // arguments. Implementations that already pass this argument can either omit
33
+ // the RequestType (preferred) or swap Logger and RequestType arguments when
34
+ // creating custom types of FastifyRequest. Related issue #4123
28
35
  > {
29
36
  id: any;
30
- params: RequestType['params'];
37
+ params: RequestType['params']; // deferred inference
31
38
  raw: RawRequest;
32
39
  query: RequestType['query'];
33
40
  headers: RawRequest['headers'] & RequestType['headers']; // this enables the developer to extend the existing http(s|2) headers list
@@ -54,6 +61,12 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
54
61
  readonly is404: boolean;
55
62
  readonly socket: RawRequest['socket'];
56
63
 
64
+ getValidationFunction(httpPart: HTTPRequestPart): (input: any) => boolean
65
+ getValidationFunction(schema: {[key: string]: any}): (input: any) => boolean
66
+ compileValidationSchema(schema: {[key: string]: any}, httpPart?: HTTPRequestPart): (input: any) => boolean
67
+ validateInput(input: any, schema: {[key: string]: any}, httpPart?: HTTPRequestPart): boolean
68
+ validateInput(input: any, httpPart?: HTTPRequestPart): boolean
69
+
57
70
  // Prefer `socket` over deprecated `connection` property in node 13.0.0 or higher
58
71
  // @deprecated
59
72
  readonly connection: RawRequest['socket'];
package/types/route.d.ts CHANGED
@@ -7,10 +7,9 @@ import { preValidationHookHandler, preHandlerHookHandler, preSerializationHookHa
7
7
  import { FastifyError } from '@fastify/error'
8
8
  import { FastifyContext } from './context'
9
9
  import {
10
- FastifyRequestType,
11
10
  FastifyTypeProvider,
12
11
  FastifyTypeProviderDefault,
13
- ResolveFastifyReplyReturnType, ResolveFastifyRequestType
12
+ ResolveFastifyReplyReturnType
14
13
  } from './type-provider'
15
14
  import { FastifyLoggerInstance, LogLevel } from './logger'
16
15
 
@@ -27,7 +26,6 @@ export interface RouteShorthandOptions<
27
26
  ContextConfig = ContextConfigDefault,
28
27
  SchemaCompiler = FastifySchema,
29
28
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
30
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
31
29
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
32
30
  > {
33
31
  schema?: SchemaCompiler, // originally FastifySchema
@@ -47,15 +45,15 @@ export interface RouteShorthandOptions<
47
45
  schemaErrorFormatter?: (errors: FastifySchemaValidationError[], dataVar: string) => Error;
48
46
 
49
47
  // hooks
50
- onRequest?: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger> | onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>[];
51
- preParsing?: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger> | preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>[];
52
- preValidation?: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger> | preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>[];
53
- preHandler?: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger> | preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>[];
54
- preSerialization?: preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger> | preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>[];
55
- onSend?: onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger> | onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>[];
56
- onResponse?: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger> | onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>[];
57
- onTimeout?: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger> | onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>[];
58
- onError?: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, RequestType, Logger> | onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, RequestType, Logger>[];
48
+ onRequest?: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
49
+ preParsing?: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
50
+ preValidation?: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
51
+ preHandler?: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
52
+ preSerialization?: preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
53
+ onSend?: onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
54
+ onResponse?: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
55
+ onTimeout?: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>[];
56
+ onError?: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger> | onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>[];
59
57
  }
60
58
 
61
59
  /**
@@ -69,11 +67,10 @@ export type RouteHandlerMethod<
69
67
  ContextConfig = ContextConfigDefault,
70
68
  SchemaCompiler extends FastifySchema = FastifySchema,
71
69
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
72
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
73
70
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
74
71
  > = (
75
72
  this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
76
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
73
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger>,
77
74
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
78
75
  // This return type used to be a generic type argument. Due to TypeScript's inference of return types, this rendered returns unchecked.
79
76
  ) => ResolveFastifyReplyReturnType<TypeProvider, SchemaCompiler, RouteGeneric>
@@ -89,10 +86,9 @@ export interface RouteShorthandOptionsWithHandler<
89
86
  ContextConfig = ContextConfigDefault,
90
87
  SchemaCompiler = FastifySchema,
91
88
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
92
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
93
89
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
94
- > extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger> {
95
- handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>;
90
+ > extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> {
91
+ handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>;
96
92
  }
97
93
 
98
94
  /**
@@ -104,18 +100,18 @@ export interface RouteShorthandMethod<
104
100
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
105
101
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
106
102
  > {
107
- <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>, Logger extends FastifyLoggerInstance = FastifyLoggerInstance>(
103
+ <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, Logger extends FastifyLoggerInstance = FastifyLoggerInstance>(
108
104
  path: string,
109
- opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>,
110
- handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
105
+ opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>,
106
+ handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
111
107
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
112
- <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>, Logger extends FastifyLoggerInstance = FastifyLoggerInstance>(
108
+ <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, Logger extends FastifyLoggerInstance = FastifyLoggerInstance>(
113
109
  path: string,
114
- handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
110
+ handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
115
111
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
116
- <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>, Logger extends FastifyLoggerInstance = FastifyLoggerInstance>(
112
+ <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, Logger extends FastifyLoggerInstance = FastifyLoggerInstance>(
117
113
  path: string,
118
- opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
114
+ opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
119
115
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
120
116
  }
121
117
 
@@ -130,12 +126,11 @@ export interface RouteOptions<
130
126
  ContextConfig = ContextConfigDefault,
131
127
  SchemaCompiler = FastifySchema,
132
128
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
133
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
134
129
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
135
- > extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger> {
130
+ > extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> {
136
131
  method: HTTPMethods | HTTPMethods[];
137
132
  url: string;
138
- handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>;
133
+ handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>;
139
134
  }
140
135
 
141
136
  export type RouteHandler<
@@ -146,11 +141,10 @@ export type RouteHandler<
146
141
  ContextConfig = ContextConfigDefault,
147
142
  SchemaCompiler extends FastifySchema = FastifySchema,
148
143
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
149
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
150
144
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
151
145
  > = (
152
146
  this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
153
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
147
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger>,
154
148
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
155
149
  ) => RouteGeneric['Reply'] | void | Promise<RouteGeneric['Reply'] | void>
156
150
 
package/types/schema.d.ts CHANGED
@@ -23,8 +23,11 @@ export interface FastifyRouteSchemaDef<T> {
23
23
  }
24
24
 
25
25
  export interface FastifySchemaValidationError {
26
- message?: string;
26
+ keyword: string;
27
27
  instancePath: string;
28
+ schemaPath: string;
29
+ params: Record<string, string | string[]>;
30
+ message?: string;
28
31
  }
29
32
 
30
33
  export interface FastifyValidationResult {