fastify 4.2.1 → 4.3.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.
@@ -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
 
@@ -200,22 +198,20 @@ export interface FastifyInstance<
200
198
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
201
199
  ContextConfig = ContextConfigDefault,
202
200
  SchemaCompiler extends FastifySchema = FastifySchema,
203
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
204
201
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
205
202
  >(
206
203
  name: 'onRequest',
207
- hook: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
204
+ hook: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
208
205
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
209
206
 
210
207
  addHook<
211
208
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
212
209
  ContextConfig = ContextConfigDefault,
213
210
  SchemaCompiler extends FastifySchema = FastifySchema,
214
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
215
211
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
216
212
  >(
217
213
  name: 'onRequest',
218
- hook: onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
214
+ hook: onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
219
215
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
220
216
 
221
217
  /**
@@ -226,22 +222,20 @@ export interface FastifyInstance<
226
222
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
227
223
  ContextConfig = ContextConfigDefault,
228
224
  SchemaCompiler extends FastifySchema = FastifySchema,
229
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
230
225
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
231
226
  >(
232
227
  name: 'preParsing',
233
- hook: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
228
+ hook: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
234
229
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
235
230
 
236
231
  addHook<
237
232
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
238
233
  ContextConfig = ContextConfigDefault,
239
234
  SchemaCompiler extends FastifySchema = FastifySchema,
240
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
241
235
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
242
236
  >(
243
237
  name: 'preParsing',
244
- hook: preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
238
+ hook: preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
245
239
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
246
240
 
247
241
  /**
@@ -251,22 +245,20 @@ export interface FastifyInstance<
251
245
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
252
246
  ContextConfig = ContextConfigDefault,
253
247
  SchemaCompiler extends FastifySchema = FastifySchema,
254
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
255
248
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
256
249
  >(
257
250
  name: 'preValidation',
258
- hook: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
251
+ hook: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
259
252
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
260
253
 
261
254
  addHook<
262
255
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
263
256
  ContextConfig = ContextConfigDefault,
264
257
  SchemaCompiler extends FastifySchema = FastifySchema,
265
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
266
258
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
267
259
  >(
268
260
  name: 'preValidation',
269
- hook: preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
261
+ hook: preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
270
262
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
271
263
 
272
264
  /**
@@ -276,22 +268,20 @@ export interface FastifyInstance<
276
268
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
277
269
  ContextConfig = ContextConfigDefault,
278
270
  SchemaCompiler extends FastifySchema = FastifySchema,
279
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
280
271
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
281
272
  >(
282
273
  name: 'preHandler',
283
- hook: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
274
+ hook: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
284
275
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
285
276
 
286
277
  addHook<
287
278
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
288
279
  ContextConfig = ContextConfigDefault,
289
280
  SchemaCompiler extends FastifySchema = FastifySchema,
290
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
291
281
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
292
282
  >(
293
283
  name: 'preHandler',
294
- hook: preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
284
+ hook: preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
295
285
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
296
286
 
297
287
  /**
@@ -303,11 +293,10 @@ export interface FastifyInstance<
303
293
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
304
294
  ContextConfig = ContextConfigDefault,
305
295
  SchemaCompiler extends FastifySchema = FastifySchema,
306
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
307
296
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
308
297
  >(
309
298
  name: 'preSerialization',
310
- hook: preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
299
+ hook: preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
311
300
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
312
301
 
313
302
  addHook<
@@ -315,11 +304,10 @@ export interface FastifyInstance<
315
304
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
316
305
  ContextConfig = ContextConfigDefault,
317
306
  SchemaCompiler extends FastifySchema = FastifySchema,
318
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
319
307
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
320
308
  >(
321
309
  name: 'preSerialization',
322
- hook: preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
310
+ hook: preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
323
311
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
324
312
 
325
313
  /**
@@ -331,11 +319,10 @@ export interface FastifyInstance<
331
319
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
332
320
  ContextConfig = ContextConfigDefault,
333
321
  SchemaCompiler extends FastifySchema = FastifySchema,
334
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
335
322
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
336
323
  >(
337
324
  name: 'onSend',
338
- hook: onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
325
+ hook: onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
339
326
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
340
327
 
341
328
  addHook<
@@ -343,11 +330,10 @@ export interface FastifyInstance<
343
330
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
344
331
  ContextConfig = ContextConfigDefault,
345
332
  SchemaCompiler extends FastifySchema = FastifySchema,
346
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
347
333
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
348
334
  >(
349
335
  name: 'onSend',
350
- hook: onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
336
+ hook: onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
351
337
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
352
338
 
353
339
  /**
@@ -358,22 +344,20 @@ export interface FastifyInstance<
358
344
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
359
345
  ContextConfig = ContextConfigDefault,
360
346
  SchemaCompiler extends FastifySchema = FastifySchema,
361
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
362
347
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
363
348
  >(
364
349
  name: 'onResponse',
365
- hook: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
350
+ hook: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
366
351
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
367
352
 
368
353
  addHook<
369
354
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
370
355
  ContextConfig = ContextConfigDefault,
371
356
  SchemaCompiler extends FastifySchema = FastifySchema,
372
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
373
357
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
374
358
  >(
375
359
  name: 'onResponse',
376
- hook: onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
360
+ hook: onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
377
361
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
378
362
 
379
363
  /**
@@ -384,22 +368,20 @@ export interface FastifyInstance<
384
368
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
385
369
  ContextConfig = ContextConfigDefault,
386
370
  SchemaCompiler extends FastifySchema = FastifySchema,
387
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
388
371
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
389
372
  >(
390
373
  name: 'onTimeout',
391
- hook: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
374
+ hook: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
392
375
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
393
376
 
394
377
  addHook<
395
378
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
396
379
  ContextConfig = ContextConfigDefault,
397
380
  SchemaCompiler extends FastifySchema = FastifySchema,
398
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
399
381
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
400
382
  >(
401
383
  name: 'onTimeout',
402
- hook: onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
384
+ hook: onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
403
385
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
404
386
 
405
387
  /**
@@ -412,22 +394,20 @@ export interface FastifyInstance<
412
394
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
413
395
  ContextConfig = ContextConfigDefault,
414
396
  SchemaCompiler extends FastifySchema = FastifySchema,
415
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
416
397
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
417
398
  >(
418
399
  name: 'onError',
419
- hook: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, RequestType, Logger>
400
+ hook: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>
420
401
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
421
402
 
422
403
  addHook<
423
404
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
424
405
  ContextConfig = ContextConfigDefault,
425
406
  SchemaCompiler extends FastifySchema = FastifySchema,
426
- RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
427
407
  Logger extends FastifyLoggerInstance = FastifyLoggerInstance
428
408
  >(
429
409
  name: 'onError',
430
- hook: onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, RequestType, Logger>
410
+ hook: onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>
431
411
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
432
412
 
433
413
  // Application addHooks
package/types/reply.d.ts CHANGED
@@ -54,5 +54,10 @@ 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
+ getSerializationFunction(httpStatus: string): (payload: any) => string;
58
+ getSerializationFunction(schema: {[key: string]: any}): (payload: any) => string;
59
+ compileSerializationSchema(schema: {[key: string]: any}, httpStatus?: string): (payload: any) => string;
60
+ serializeInput(input: any, schema: {[key: string]: any}, httpStatus?: string): string
61
+ serializeInput(input: any, httpStatus: string): string
57
62
  then(fulfilled: () => void, rejected: (err: Error) => void): void;
58
63
  }
@@ -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
+ validate(input: any, schema: {[key: string]: any}, httpPart?: HTTPRequestPart): boolean
68
+ validate(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
 
@@ -48,12 +48,13 @@ export interface FastifyRequestType<Params = unknown, Querystring = unknown, Hea
48
48
  body: Body
49
49
  }
50
50
 
51
- export type ResolveFastifyRequestType<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema, RouteGeneric extends RouteGenericInterface> = FastifyRequestType<
52
- ResolveRequestParams<TypeProvider, SchemaCompiler, RouteGeneric>,
53
- ResolveRequestQuerystring<TypeProvider, SchemaCompiler, RouteGeneric>,
54
- ResolveRequestHeaders<TypeProvider, SchemaCompiler, RouteGeneric>,
55
- ResolveRequestBody<TypeProvider, SchemaCompiler, RouteGeneric>
56
- >
51
+ // Resolves the FastifyRequest generic parameters
52
+ export interface ResolveFastifyRequestType<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema, RouteGeneric extends RouteGenericInterface> extends FastifyRequestType {
53
+ params: ResolveRequestParams<TypeProvider, SchemaCompiler, RouteGeneric>,
54
+ query: ResolveRequestQuerystring<TypeProvider, SchemaCompiler, RouteGeneric>,
55
+ headers: ResolveRequestHeaders<TypeProvider, SchemaCompiler, RouteGeneric>,
56
+ body: ResolveRequestBody<TypeProvider, SchemaCompiler, RouteGeneric>
57
+ }
57
58
 
58
59
  // -----------------------------------------------------------------------------------------------
59
60
  // FastifyReplyType