fastify 4.0.0-alpha.2 → 4.0.0-alpha.3
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/docs/Guides/Ecosystem.md +9 -0
- package/docs/Reference/Reply.md +50 -0
- package/docs/Reference/Server.md +1 -1
- package/examples/parser.js +12 -2
- package/fastify.js +1 -1
- package/lib/errors.js +8 -0
- package/lib/reply.js +92 -17
- package/lib/server.js +1 -0
- package/lib/symbols.js +1 -0
- package/lib/validation.js +9 -8
- package/package.json +2 -2
- package/test/internals/reply.test.js +50 -23
- package/test/listen.test.js +27 -0
- package/test/reply-trailers.test.js +270 -0
- package/test/types/hooks.test-d.ts +61 -5
- package/test/types/request.test-d.ts +71 -1
- package/test/types/type-provider.test-d.ts +10 -3
- package/types/hooks.d.ts +101 -47
- package/types/instance.d.ts +83 -41
- package/types/request.d.ts +4 -4
- package/types/route.d.ts +46 -29
package/types/instance.d.ts
CHANGED
|
@@ -14,7 +14,12 @@ import {
|
|
|
14
14
|
FastifySchemaValidationError,
|
|
15
15
|
FastifySerializerCompiler
|
|
16
16
|
} from './schema'
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
FastifyRequestType,
|
|
19
|
+
FastifyTypeProvider,
|
|
20
|
+
FastifyTypeProviderDefault,
|
|
21
|
+
ResolveFastifyRequestType
|
|
22
|
+
} from './type-provider'
|
|
18
23
|
import { ContextConfigDefault, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault } from './utils'
|
|
19
24
|
|
|
20
25
|
export interface PrintRoutesOptions {
|
|
@@ -32,7 +37,7 @@ export interface FastifyInstance<
|
|
|
32
37
|
RawServer extends RawServerBase = RawServerDefault,
|
|
33
38
|
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
34
39
|
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
35
|
-
Logger = FastifyLoggerInstance,
|
|
40
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance,
|
|
36
41
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
37
42
|
> {
|
|
38
43
|
server: RawServer;
|
|
@@ -195,7 +200,7 @@ export interface FastifyInstance<
|
|
|
195
200
|
*/
|
|
196
201
|
listen(port: number | string, address?: string, backlog?: number): Promise<string>;
|
|
197
202
|
|
|
198
|
-
ready(): FastifyInstance<RawServer, RawRequest, RawReply,
|
|
203
|
+
ready(): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>;
|
|
199
204
|
ready(readyListener: (err: Error) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
200
205
|
|
|
201
206
|
register: FastifyRegister<FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>>;
|
|
@@ -230,19 +235,23 @@ export interface FastifyInstance<
|
|
|
230
235
|
addHook<
|
|
231
236
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
232
237
|
ContextConfig = ContextConfigDefault,
|
|
233
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
238
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
239
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
240
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
234
241
|
>(
|
|
235
242
|
name: 'onRequest',
|
|
236
|
-
hook: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
243
|
+
hook: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
237
244
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
238
245
|
|
|
239
246
|
addHook<
|
|
240
247
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
241
248
|
ContextConfig = ContextConfigDefault,
|
|
242
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
249
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
250
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
251
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
243
252
|
>(
|
|
244
253
|
name: 'onRequest',
|
|
245
|
-
hook: onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
254
|
+
hook: onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
246
255
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
247
256
|
|
|
248
257
|
/**
|
|
@@ -252,19 +261,23 @@ export interface FastifyInstance<
|
|
|
252
261
|
addHook<
|
|
253
262
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
254
263
|
ContextConfig = ContextConfigDefault,
|
|
255
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
264
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
265
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
266
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
256
267
|
>(
|
|
257
268
|
name: 'preParsing',
|
|
258
|
-
hook: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
269
|
+
hook: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
259
270
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
260
271
|
|
|
261
272
|
addHook<
|
|
262
273
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
263
274
|
ContextConfig = ContextConfigDefault,
|
|
264
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
275
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
276
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
277
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
265
278
|
>(
|
|
266
279
|
name: 'preParsing',
|
|
267
|
-
hook: preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
280
|
+
hook: preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
268
281
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
269
282
|
|
|
270
283
|
/**
|
|
@@ -273,19 +286,23 @@ export interface FastifyInstance<
|
|
|
273
286
|
addHook<
|
|
274
287
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
275
288
|
ContextConfig = ContextConfigDefault,
|
|
276
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
289
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
290
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
291
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
277
292
|
>(
|
|
278
293
|
name: 'preValidation',
|
|
279
|
-
hook: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
294
|
+
hook: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
280
295
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
281
296
|
|
|
282
297
|
addHook<
|
|
283
298
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
284
299
|
ContextConfig = ContextConfigDefault,
|
|
285
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
300
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
301
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
302
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
286
303
|
>(
|
|
287
304
|
name: 'preValidation',
|
|
288
|
-
hook: preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
305
|
+
hook: preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
289
306
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
290
307
|
|
|
291
308
|
/**
|
|
@@ -294,19 +311,23 @@ export interface FastifyInstance<
|
|
|
294
311
|
addHook<
|
|
295
312
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
296
313
|
ContextConfig = ContextConfigDefault,
|
|
297
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
314
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
315
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
316
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
298
317
|
>(
|
|
299
318
|
name: 'preHandler',
|
|
300
|
-
hook: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
319
|
+
hook: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
301
320
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
302
321
|
|
|
303
322
|
addHook<
|
|
304
323
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
305
324
|
ContextConfig = ContextConfigDefault,
|
|
306
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
325
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
326
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
327
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
307
328
|
>(
|
|
308
329
|
name: 'preHandler',
|
|
309
|
-
hook: preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
330
|
+
hook: preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
310
331
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
311
332
|
|
|
312
333
|
/**
|
|
@@ -317,20 +338,24 @@ export interface FastifyInstance<
|
|
|
317
338
|
PreSerializationPayload = unknown,
|
|
318
339
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
319
340
|
ContextConfig = ContextConfigDefault,
|
|
320
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
341
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
342
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
343
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
321
344
|
>(
|
|
322
345
|
name: 'preSerialization',
|
|
323
|
-
hook: preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
346
|
+
hook: preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
324
347
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
325
348
|
|
|
326
349
|
addHook<
|
|
327
350
|
PreSerializationPayload = unknown,
|
|
328
351
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
329
352
|
ContextConfig = ContextConfigDefault,
|
|
330
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
353
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
354
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
355
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
331
356
|
>(
|
|
332
357
|
name: 'preSerialization',
|
|
333
|
-
hook: preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
358
|
+
hook: preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
334
359
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
335
360
|
|
|
336
361
|
/**
|
|
@@ -341,20 +366,24 @@ export interface FastifyInstance<
|
|
|
341
366
|
OnSendPayload = unknown,
|
|
342
367
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
343
368
|
ContextConfig = ContextConfigDefault,
|
|
344
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
369
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
370
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
371
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
345
372
|
>(
|
|
346
373
|
name: 'onSend',
|
|
347
|
-
hook: onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
374
|
+
hook: onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
348
375
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
349
376
|
|
|
350
377
|
addHook<
|
|
351
378
|
OnSendPayload = unknown,
|
|
352
379
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
353
380
|
ContextConfig = ContextConfigDefault,
|
|
354
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
381
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
382
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
383
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
355
384
|
>(
|
|
356
385
|
name: 'onSend',
|
|
357
|
-
hook: onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
386
|
+
hook: onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
358
387
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
359
388
|
|
|
360
389
|
/**
|
|
@@ -364,19 +393,23 @@ export interface FastifyInstance<
|
|
|
364
393
|
addHook<
|
|
365
394
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
366
395
|
ContextConfig = ContextConfigDefault,
|
|
367
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
396
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
397
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
398
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
368
399
|
>(
|
|
369
400
|
name: 'onResponse',
|
|
370
|
-
hook: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
401
|
+
hook: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
371
402
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
372
403
|
|
|
373
404
|
addHook<
|
|
374
405
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
375
406
|
ContextConfig = ContextConfigDefault,
|
|
376
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
407
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
408
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
409
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
377
410
|
>(
|
|
378
411
|
name: 'onResponse',
|
|
379
|
-
hook: onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
412
|
+
hook: onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
380
413
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
381
414
|
|
|
382
415
|
/**
|
|
@@ -386,19 +419,23 @@ export interface FastifyInstance<
|
|
|
386
419
|
addHook<
|
|
387
420
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
388
421
|
ContextConfig = ContextConfigDefault,
|
|
389
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
422
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
423
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
424
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
390
425
|
>(
|
|
391
426
|
name: 'onTimeout',
|
|
392
|
-
hook: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
427
|
+
hook: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
393
428
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
394
429
|
|
|
395
430
|
addHook<
|
|
396
431
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
397
432
|
ContextConfig = ContextConfigDefault,
|
|
398
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
433
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
434
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
435
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
399
436
|
>(
|
|
400
437
|
name: 'onTimeout',
|
|
401
|
-
hook: onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
438
|
+
hook: onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
402
439
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
403
440
|
|
|
404
441
|
/**
|
|
@@ -410,19 +447,23 @@ export interface FastifyInstance<
|
|
|
410
447
|
addHook<
|
|
411
448
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
412
449
|
ContextConfig = ContextConfigDefault,
|
|
413
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
450
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
451
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
452
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
414
453
|
>(
|
|
415
454
|
name: 'onError',
|
|
416
|
-
hook: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider>
|
|
455
|
+
hook: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
417
456
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
418
457
|
|
|
419
458
|
addHook<
|
|
420
459
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
421
460
|
ContextConfig = ContextConfigDefault,
|
|
422
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
461
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
462
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
463
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
423
464
|
>(
|
|
424
465
|
name: 'onError',
|
|
425
|
-
hook: onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider>
|
|
466
|
+
hook: onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
426
467
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
427
468
|
|
|
428
469
|
// Application addHooks
|
|
@@ -433,10 +474,11 @@ export interface FastifyInstance<
|
|
|
433
474
|
addHook<
|
|
434
475
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
435
476
|
ContextConfig = ContextConfigDefault,
|
|
436
|
-
SchemaCompiler extends FastifySchema = FastifySchema
|
|
477
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
478
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
437
479
|
>(
|
|
438
480
|
name: 'onRoute',
|
|
439
|
-
hook: onRouteHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
481
|
+
hook: onRouteHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
440
482
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
441
483
|
|
|
442
484
|
/**
|
package/types/request.d.ts
CHANGED
|
@@ -17,21 +17,21 @@ export interface RequestGenericInterface {
|
|
|
17
17
|
* FastifyRequest is an instance of the standard http or http2 request objects.
|
|
18
18
|
* It defaults to http.IncomingMessage, and it also extends the relative request object.
|
|
19
19
|
*/
|
|
20
|
-
export interface FastifyRequest<
|
|
21
|
-
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
20
|
+
export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
22
21
|
RawServer extends RawServerBase = RawServerDefault,
|
|
23
22
|
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
24
23
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
25
24
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
26
25
|
ContextConfig = ContextConfigDefault,
|
|
27
|
-
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric
|
|
26
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
27
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
28
28
|
> {
|
|
29
29
|
id: any;
|
|
30
30
|
params: RequestType['params'];
|
|
31
31
|
raw: RawRequest;
|
|
32
32
|
query: RequestType['query'];
|
|
33
33
|
headers: RawRequest['headers'] & RequestType['headers']; // this enables the developer to extend the existing http(s|2) headers list
|
|
34
|
-
log:
|
|
34
|
+
log: Logger;
|
|
35
35
|
server: FastifyInstance;
|
|
36
36
|
body: RequestType['body'];
|
|
37
37
|
context: FastifyContext<ContextConfig>;
|
package/types/route.d.ts
CHANGED
|
@@ -6,7 +6,12 @@ import { HTTPMethods, RawServerBase, RawServerDefault, RawRequestDefaultExpressi
|
|
|
6
6
|
import { preValidationHookHandler, preHandlerHookHandler, preSerializationHookHandler, onRequestHookHandler, preParsingHookHandler, onResponseHookHandler, onSendHookHandler, onErrorHookHandler, onTimeoutHookHandler } from './hooks'
|
|
7
7
|
import { FastifyError } from 'fastify-error'
|
|
8
8
|
import { FastifyContext } from './context'
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
FastifyRequestType,
|
|
11
|
+
FastifyTypeProvider,
|
|
12
|
+
FastifyTypeProviderDefault,
|
|
13
|
+
ResolveFastifyReplyReturnType, ResolveFastifyRequestType
|
|
14
|
+
} from './type-provider'
|
|
10
15
|
import { FastifyLoggerInstance, LogLevel } from './logger'
|
|
11
16
|
|
|
12
17
|
export interface RouteGenericInterface extends RequestGenericInterface, ReplyGenericInterface {}
|
|
@@ -22,6 +27,8 @@ export interface RouteShorthandOptions<
|
|
|
22
27
|
ContextConfig = ContextConfigDefault,
|
|
23
28
|
SchemaCompiler = FastifySchema,
|
|
24
29
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
30
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
31
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
25
32
|
> {
|
|
26
33
|
schema?: SchemaCompiler, // originally FastifySchema
|
|
27
34
|
attachValidation?: boolean;
|
|
@@ -40,15 +47,15 @@ export interface RouteShorthandOptions<
|
|
|
40
47
|
schemaErrorFormatter?: (errors: FastifySchemaValidationError[], dataVar: string) => Error;
|
|
41
48
|
|
|
42
49
|
// hooks
|
|
43
|
-
onRequest?: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider> | onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>[];
|
|
44
|
-
preParsing?: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider> | preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>[];
|
|
45
|
-
preValidation?: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider> | preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>[];
|
|
46
|
-
preHandler?: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider> | preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>[];
|
|
47
|
-
preSerialization?: preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider> | preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>[];
|
|
48
|
-
onSend?: onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider> | onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>[];
|
|
49
|
-
onResponse?: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider> | onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>[];
|
|
50
|
-
onTimeout?: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider> | onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>[];
|
|
51
|
-
onError?: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider> | onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider>[];
|
|
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>[];
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
/**
|
|
@@ -62,10 +69,12 @@ export type RouteHandlerMethod<
|
|
|
62
69
|
ContextConfig = ContextConfigDefault,
|
|
63
70
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
64
71
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
65
|
-
ReturnType = ResolveFastifyReplyReturnType<TypeProvider, SchemaCompiler, RouteGeneric
|
|
72
|
+
ReturnType = ResolveFastifyReplyReturnType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
73
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
74
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
66
75
|
> = (
|
|
67
|
-
this: FastifyInstance<RawServer, RawRequest, RawReply,
|
|
68
|
-
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig>,
|
|
76
|
+
this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
|
|
77
|
+
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
|
|
69
78
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
70
79
|
) => ReturnType
|
|
71
80
|
|
|
@@ -80,8 +89,11 @@ export interface RouteShorthandOptionsWithHandler<
|
|
|
80
89
|
ContextConfig = ContextConfigDefault,
|
|
81
90
|
SchemaCompiler = FastifySchema,
|
|
82
91
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
83
|
-
|
|
84
|
-
|
|
92
|
+
ReturnType = ResolveFastifyReplyReturnType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
93
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
94
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
95
|
+
> extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger> {
|
|
96
|
+
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, ReturnType, RequestType, Logger>;
|
|
85
97
|
}
|
|
86
98
|
|
|
87
99
|
/**
|
|
@@ -93,19 +105,19 @@ export interface RouteShorthandMethod<
|
|
|
93
105
|
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
94
106
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
95
107
|
> {
|
|
96
|
-
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema>(
|
|
108
|
+
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, ReturnType = ResolveFastifyReplyReturnType<TypeProvider, SchemaCompiler, RouteGeneric>, RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>, Logger extends FastifyLoggerInstance = FastifyLoggerInstance>(
|
|
97
109
|
path: string,
|
|
98
|
-
opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
|
|
99
|
-
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
100
|
-
): FastifyInstance<RawServer, RawRequest, RawReply,
|
|
101
|
-
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault>(
|
|
110
|
+
opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>,
|
|
111
|
+
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, ReturnType, RequestType, Logger>
|
|
112
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
113
|
+
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, ReturnType = ResolveFastifyReplyReturnType<TypeProvider, SchemaCompiler, RouteGeneric>, RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>, Logger extends FastifyLoggerInstance = FastifyLoggerInstance>(
|
|
102
114
|
path: string,
|
|
103
|
-
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
|
|
104
|
-
): FastifyInstance<RawServer, RawRequest, RawReply,
|
|
105
|
-
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema>(
|
|
115
|
+
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, ReturnType, RequestType, Logger>
|
|
116
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
117
|
+
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, ReturnType = ResolveFastifyReplyReturnType<TypeProvider, SchemaCompiler, RouteGeneric>, RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>, Logger extends FastifyLoggerInstance = FastifyLoggerInstance>(
|
|
106
118
|
path: string,
|
|
107
|
-
opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
108
|
-
): FastifyInstance<RawServer, RawRequest, RawReply,
|
|
119
|
+
opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, ReturnType, RequestType, Logger>
|
|
120
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
109
121
|
}
|
|
110
122
|
|
|
111
123
|
/**
|
|
@@ -119,10 +131,13 @@ export interface RouteOptions<
|
|
|
119
131
|
ContextConfig = ContextConfigDefault,
|
|
120
132
|
SchemaCompiler = FastifySchema,
|
|
121
133
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
122
|
-
|
|
134
|
+
ReturnType = ResolveFastifyReplyReturnType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
135
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
136
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
137
|
+
> extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger> {
|
|
123
138
|
method: HTTPMethods | HTTPMethods[];
|
|
124
139
|
url: string;
|
|
125
|
-
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>;
|
|
140
|
+
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, ReturnType, RequestType, Logger>;
|
|
126
141
|
}
|
|
127
142
|
|
|
128
143
|
export type RouteHandler<
|
|
@@ -133,9 +148,11 @@ export type RouteHandler<
|
|
|
133
148
|
ContextConfig = ContextConfigDefault,
|
|
134
149
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
135
150
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
151
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
152
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
136
153
|
> = (
|
|
137
|
-
this: FastifyInstance<RawServer, RawRequest, RawReply,
|
|
138
|
-
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig>,
|
|
154
|
+
this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
|
|
155
|
+
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
|
|
139
156
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
140
157
|
) => void | Promise<RouteGeneric['Reply'] | void>
|
|
141
158
|
|