fastify 3.27.2 → 4.0.0-alpha.1

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 (116) hide show
  1. package/README.md +5 -4
  2. package/build/build-error-serializer.js +27 -0
  3. package/build/build-validation.js +47 -35
  4. package/docs/Migration-Guide-V4.md +12 -0
  5. package/docs/Reference/ContentTypeParser.md +4 -0
  6. package/docs/Reference/Errors.md +51 -6
  7. package/docs/Reference/Hooks.md +4 -7
  8. package/docs/Reference/LTS.md +5 -4
  9. package/docs/Reference/Reply.md +23 -22
  10. package/docs/Reference/Request.md +1 -3
  11. package/docs/Reference/Routes.md +17 -10
  12. package/docs/Reference/Server.md +48 -63
  13. package/docs/Reference/TypeScript.md +11 -13
  14. package/docs/Reference/Validation-and-Serialization.md +28 -53
  15. package/docs/Type-Providers.md +257 -0
  16. package/examples/hooks.js +1 -1
  17. package/examples/simple-stream.js +18 -0
  18. package/fastify.d.ts +34 -22
  19. package/fastify.js +37 -35
  20. package/lib/configValidator.js +902 -1023
  21. package/lib/contentTypeParser.js +6 -16
  22. package/lib/context.js +36 -10
  23. package/lib/decorate.js +3 -1
  24. package/lib/error-handler.js +158 -0
  25. package/lib/error-serializer.js +257 -0
  26. package/lib/errors.js +43 -9
  27. package/lib/fourOhFour.js +31 -20
  28. package/lib/handleRequest.js +10 -13
  29. package/lib/hooks.js +14 -9
  30. package/lib/pluginOverride.js +0 -3
  31. package/lib/pluginUtils.js +3 -2
  32. package/lib/reply.js +28 -157
  33. package/lib/request.js +13 -10
  34. package/lib/route.js +131 -138
  35. package/lib/schema-controller.js +2 -2
  36. package/lib/schemas.js +27 -1
  37. package/lib/server.js +219 -116
  38. package/lib/symbols.js +4 -3
  39. package/lib/validation.js +2 -1
  40. package/lib/warnings.js +2 -12
  41. package/lib/wrapThenable.js +4 -11
  42. package/package.json +31 -35
  43. package/test/404s.test.js +243 -110
  44. package/test/500s.test.js +2 -2
  45. package/test/async-await.test.js +13 -69
  46. package/test/content-parser.test.js +32 -0
  47. package/test/context-config.test.js +52 -0
  48. package/test/custom-http-server.test.js +14 -7
  49. package/test/custom-parser-async.test.js +0 -65
  50. package/test/custom-parser.test.js +54 -121
  51. package/test/decorator.test.js +1 -3
  52. package/test/delete.test.js +5 -5
  53. package/test/encapsulated-error-handler.test.js +50 -0
  54. package/test/esm/index.test.js +0 -14
  55. package/test/fastify-instance.test.js +4 -4
  56. package/test/fluent-schema.test.js +4 -4
  57. package/test/get.test.js +3 -3
  58. package/test/helper.js +18 -3
  59. package/test/hooks-async.test.js +14 -47
  60. package/test/hooks.on-ready.test.js +9 -4
  61. package/test/hooks.test.js +58 -99
  62. package/test/http2/closing.test.js +5 -11
  63. package/test/http2/unknown-http-method.test.js +3 -9
  64. package/test/https/custom-https-server.test.js +12 -6
  65. package/test/input-validation.js +2 -2
  66. package/test/internals/handleRequest.test.js +3 -40
  67. package/test/internals/initialConfig.test.js +33 -12
  68. package/test/internals/reply.test.js +245 -3
  69. package/test/internals/request.test.js +13 -7
  70. package/test/internals/server.test.js +88 -0
  71. package/test/listen.test.js +84 -1
  72. package/test/logger.test.js +80 -40
  73. package/test/maxRequestsPerSocket.test.js +6 -4
  74. package/test/middleware.test.js +2 -25
  75. package/test/nullable-validation.test.js +51 -14
  76. package/test/plugin.test.js +31 -5
  77. package/test/pretty-print.test.js +22 -10
  78. package/test/reply-error.test.js +123 -12
  79. package/test/request-error.test.js +2 -5
  80. package/test/route-hooks.test.js +17 -17
  81. package/test/route-prefix.test.js +2 -1
  82. package/test/route.test.js +204 -20
  83. package/test/router-options.test.js +1 -1
  84. package/test/schema-examples.test.js +11 -5
  85. package/test/schema-feature.test.js +24 -19
  86. package/test/schema-serialization.test.js +9 -9
  87. package/test/schema-special-usage.test.js +14 -81
  88. package/test/schema-validation.test.js +9 -9
  89. package/test/skip-reply-send.test.js +1 -1
  90. package/test/stream.test.js +23 -12
  91. package/test/throw.test.js +8 -5
  92. package/test/type-provider.test.js +20 -0
  93. package/test/types/fastify.test-d.ts +10 -18
  94. package/test/types/import.js +2 -0
  95. package/test/types/import.ts +1 -0
  96. package/test/types/instance.test-d.ts +35 -14
  97. package/test/types/logger.test-d.ts +44 -15
  98. package/test/types/route.test-d.ts +8 -2
  99. package/test/types/schema.test-d.ts +2 -39
  100. package/test/types/type-provider.test-d.ts +417 -0
  101. package/test/validation-error-handling.test.js +8 -8
  102. package/test/versioned-routes.test.js +28 -16
  103. package/test/wrapThenable.test.js +7 -6
  104. package/types/content-type-parser.d.ts +17 -8
  105. package/types/hooks.d.ts +102 -59
  106. package/types/instance.d.ts +124 -104
  107. package/types/logger.d.ts +18 -104
  108. package/types/plugin.d.ts +10 -4
  109. package/types/reply.d.ts +16 -11
  110. package/types/request.d.ts +10 -5
  111. package/types/route.d.ts +42 -31
  112. package/types/schema.d.ts +1 -1
  113. package/types/type-provider.d.ts +99 -0
  114. package/types/utils.d.ts +1 -1
  115. package/lib/schema-compilers.js +0 -12
  116. package/test/emit-warning.test.js +0 -166
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const { test } = require('tap')
4
- const Joi = require('@hapi/joi')
4
+ const Joi = require('joi')
5
5
  const Fastify = require('..')
6
6
 
7
7
  const schema = {
@@ -58,7 +58,7 @@ test('should fail immediately with invalid payload', t => {
58
58
  t.same(res.json(), {
59
59
  statusCode: 400,
60
60
  error: 'Bad Request',
61
- message: "body should have required property 'name'"
61
+ message: "body must have required property 'name'"
62
62
  })
63
63
  t.equal(res.statusCode, 400)
64
64
  })
@@ -183,10 +183,10 @@ test('should be able to attach validation to request', t => {
183
183
 
184
184
  t.same(res.json(), [{
185
185
  keyword: 'required',
186
- dataPath: '',
186
+ instancePath: '',
187
187
  schemaPath: '#/required',
188
188
  params: { missingProperty: 'name' },
189
- message: 'should have required property \'name\''
189
+ message: 'must have required property \'name\''
190
190
  }])
191
191
  t.equal(res.statusCode, 400)
192
192
  })
@@ -213,7 +213,7 @@ test('should respect when attachValidation is explicitly set to false', t => {
213
213
  t.same(JSON.parse(res.payload), {
214
214
  statusCode: 400,
215
215
  error: 'Bad Request',
216
- message: "body should have required property 'name'"
216
+ message: "body must have required property 'name'"
217
217
  })
218
218
  t.equal(res.statusCode, 400)
219
219
  })
@@ -243,7 +243,7 @@ test('Attached validation error should take precedence over setErrorHandler', t
243
243
  url: '/'
244
244
  }, (err, res) => {
245
245
  t.error(err)
246
- t.same(res.payload, "Attached: Error: body should have required property 'name'")
246
+ t.same(res.payload, "Attached: Error: body must have required property 'name'")
247
247
  t.equal(res.statusCode, 400)
248
248
  })
249
249
  })
@@ -336,7 +336,7 @@ test('should return a defined output message parsing AJV errors', t => {
336
336
  url: '/'
337
337
  }, (err, res) => {
338
338
  t.error(err)
339
- t.equal(res.payload, '{"statusCode":400,"error":"Bad Request","message":"body should have required property \'name\'"}')
339
+ t.equal(res.payload, '{"statusCode":400,"error":"Bad Request","message":"body must have required property \'name\'"}')
340
340
  })
341
341
  })
342
342
 
@@ -467,7 +467,7 @@ test('should call custom error formatter', t => {
467
467
  const fastify = Fastify({
468
468
  schemaErrorFormatter: (errors, dataVar) => {
469
469
  t.equal(errors.length, 1)
470
- t.equal(errors[0].message, "should have required property 'name'")
470
+ t.equal(errors[0].message, "must have required property 'name'")
471
471
  t.equal(dataVar, 'body')
472
472
  return new Error('my error')
473
473
  }
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
4
- const test = t.test
3
+ const { test, before } = require('tap')
4
+ const helper = require('./helper')
5
5
  const Fastify = require('..')
6
6
  const sget = require('simple-get').concat
7
7
  const http = require('http')
@@ -9,6 +9,13 @@ const split = require('split2')
9
9
  const append = require('vary').append
10
10
  const proxyquire = require('proxyquire')
11
11
 
12
+ process.removeAllListeners('warning')
13
+
14
+ let localhost
15
+ before(async function () {
16
+ [localhost] = await helper.getLoopbackHost()
17
+ })
18
+
12
19
  test('Should register a versioned route', t => {
13
20
  t.plan(11)
14
21
  const fastify = Fastify()
@@ -442,12 +449,12 @@ test('test log stream', t => {
442
449
  reply.send(new Error('kaboom'))
443
450
  })
444
451
 
445
- fastify.listen(0, err => {
452
+ fastify.listen(0, localhost, err => {
446
453
  t.error(err)
447
454
  fastify.server.unref()
448
455
 
449
456
  http.get({
450
- hostname: 'localhost',
457
+ hostname: fastify.server.address().hostname,
451
458
  port: fastify.server.address().port,
452
459
  path: '/',
453
460
  method: 'GET',
@@ -549,7 +556,7 @@ test('Should register a versioned route with custom versioning strategy', t => {
549
556
  })
550
557
 
551
558
  test('Should get error using an invalid a versioned route, using default validation (deprecated versioning option)', t => {
552
- t.plan(1)
559
+ t.plan(3)
553
560
 
554
561
  const fastify = Fastify({
555
562
  versioning: {
@@ -577,15 +584,19 @@ test('Should get error using an invalid a versioned route, using default validat
577
584
  }
578
585
  })
579
586
 
580
- fastify.route({
581
- method: 'GET',
582
- url: '/',
583
- // not a string version
584
- constraints: { version: 2 },
585
- handler: (req, reply) => {
586
- reply.send({ hello: 'cant match route v2' })
587
- }
588
- })
587
+ try {
588
+ fastify.route({
589
+ method: 'GET',
590
+ url: '/',
591
+ // not a string version
592
+ constraints: { version: 2 },
593
+ handler: (req, reply) => {
594
+ reply.send({ hello: 'cant match route v2' })
595
+ }
596
+ })
597
+ } catch (err) {
598
+ t.equal(err.message, 'Version constraint should be a string.')
599
+ }
589
600
 
590
601
  fastify.inject({
591
602
  method: 'GET',
@@ -594,7 +605,8 @@ test('Should get error using an invalid a versioned route, using default validat
594
605
  Accept: 'application/vnd.example.api+json;version=2'
595
606
  }
596
607
  }, (err, res) => {
597
- t.equal(err.message, 'Version constraint should be a string.')
608
+ t.error(err)
609
+ t.equal(res.statusCode, 404)
598
610
  })
599
611
  })
600
612
 
@@ -663,7 +675,7 @@ test('Should trigger a warning when a versioned route is registered via version
663
675
  }
664
676
 
665
677
  const route = proxyquire('../lib/route', { './warnings': warning })
666
- const fastify = proxyquire('..', { './lib/route.js': route })()
678
+ const fastify = proxyquire('..', { './lib/route.js': route })({ exposeHeadRoutes: false })
667
679
 
668
680
  fastify.route({
669
681
  method: 'GET',
@@ -2,21 +2,22 @@
2
2
 
3
3
  const t = require('tap')
4
4
  const test = t.test
5
- const { kReplySentOverwritten } = require('../lib/symbols')
5
+ const { kReplyHijacked } = require('../lib/symbols')
6
6
  const wrapThenable = require('../lib/wrapThenable')
7
+ const Reply = require('../lib/reply')
7
8
 
8
- test('should resolve immediately when reply[kReplySentOverwritten] is true', t => {
9
+ test('should resolve immediately when reply[kReplyHijacked] is true', t => {
9
10
  const reply = {}
10
- reply[kReplySentOverwritten] = true
11
+ reply[kReplyHijacked] = true
11
12
  const thenable = Promise.resolve()
12
13
  wrapThenable(thenable, reply)
13
14
  t.end()
14
15
  })
15
16
 
16
- test('should reject immediately when reply[kReplySentOverwritten] is true', t => {
17
+ test('should reject immediately when reply[kReplyHijacked] is true', t => {
17
18
  t.plan(1)
18
- const reply = { res: {} }
19
- reply[kReplySentOverwritten] = true
19
+ const reply = new Reply({}, {}, {})
20
+ reply[kReplyHijacked] = true
20
21
  reply.log = {
21
22
  error: ({ err }) => {
22
23
  t.equal(err.message, 'Reply sent already')
@@ -1,6 +1,8 @@
1
1
  import { RawServerBase, RawServerDefault, RawRequestDefaultExpression } from './utils'
2
2
  import { FastifyRequest } from './request'
3
3
  import { RouteGenericInterface } from './route'
4
+ import { FastifyTypeProvider, FastifyTypeProviderDefault } from './type-provider'
5
+ import { FastifySchema } from './schema'
4
6
 
5
7
  type ContentTypeParserDoneFunction = (err: Error | null, body?: any) => void
6
8
 
@@ -12,8 +14,10 @@ export type FastifyBodyParser<
12
14
  RawServer extends RawServerBase = RawServerDefault,
13
15
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
14
16
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
15
- > = ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest>, rawBody: RawBody, done: ContentTypeParserDoneFunction) => void)
16
- | ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest>, rawBody: RawBody) => Promise<any>)
17
+ SchemaCompiler extends FastifySchema = FastifySchema,
18
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
19
+ > = ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>, rawBody: RawBody, done: ContentTypeParserDoneFunction) => void)
20
+ | ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>, rawBody: RawBody) => Promise<any>)
17
21
 
18
22
  /**
19
23
  * Content Type Parser method that operates on request content
@@ -22,31 +26,36 @@ export type FastifyContentTypeParser<
22
26
  RawServer extends RawServerBase = RawServerDefault,
23
27
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
24
28
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
25
- > = ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest>, payload: RawRequest) => Promise<any>)
26
- | ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest>, payload: RawRequest, done: ContentTypeParserDoneFunction) => void)
29
+ SchemaCompiler extends FastifySchema = FastifySchema,
30
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
31
+ > = ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>, payload: RawRequest) => Promise<any>)
32
+ | ((request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>, payload: RawRequest, done: ContentTypeParserDoneFunction) => void)
27
33
 
28
34
  /**
29
35
  * Natively, Fastify only supports 'application/json' and 'text/plain' content types. The default charset is utf-8. If you need to support different content types, you can use the addContentTypeParser API. The default JSON and/or plain text parser can be changed.
30
36
  */
31
37
  export interface AddContentTypeParser<
32
38
  RawServer extends RawServerBase = RawServerDefault,
33
- RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>
39
+ RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
40
+ RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
41
+ SchemaCompiler extends FastifySchema = FastifySchema,
42
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
34
43
  > {
35
44
  (
36
45
  contentType: string | string[] | RegExp,
37
46
  opts: {
38
47
  bodyLimit?: number;
39
48
  },
40
- parser: FastifyContentTypeParser<RawServer, RawRequest>
49
+ parser: FastifyContentTypeParser<RawServer, RawRequest, RouteGeneric, SchemaCompiler, TypeProvider>
41
50
  ): void;
42
- (contentType: string | string[] | RegExp, parser: FastifyContentTypeParser<RawServer, RawRequest>): void;
51
+ (contentType: string | string[] | RegExp, parser: FastifyContentTypeParser<RawServer, RawRequest, RouteGeneric, SchemaCompiler, TypeProvider>): void;
43
52
  <parseAs extends string | Buffer>(
44
53
  contentType: string | string[] | RegExp,
45
54
  opts: {
46
55
  parseAs: parseAs extends Buffer ? 'buffer' : 'string';
47
56
  bodyLimit?: number;
48
57
  },
49
- parser: FastifyBodyParser<parseAs, RawServer, RawRequest>
58
+ parser: FastifyBodyParser<parseAs, RawServer, RawRequest, RouteGeneric, SchemaCompiler, TypeProvider>
50
59
  ): void;
51
60
  }
52
61
 
package/types/hooks.d.ts CHANGED
@@ -6,7 +6,9 @@ import { FastifyRequest } from './request'
6
6
  import { FastifyReply } from './reply'
7
7
  import { FastifyError } from 'fastify-error'
8
8
  import { FastifyLoggerInstance } from './logger'
9
+ import { FastifyTypeProvider, FastifyTypeProviderDefault } from './type-provider'
9
10
  import { RegisterOptions } from './register'
11
+ import { FastifySchema } from './schema'
10
12
  import { FastifyPluginOptions } from './plugin'
11
13
 
12
14
  type HookHandlerDoneFunction = <TError extends Error = FastifyError>(err?: TError) => void
@@ -26,12 +28,15 @@ export interface onRequestHookHandler<
26
28
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
27
29
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
28
30
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
29
- ContextConfig = ContextConfigDefault
31
+ ContextConfig = ContextConfigDefault,
32
+ SchemaCompiler extends FastifySchema = FastifySchema,
33
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
34
+
30
35
  > {
31
36
  (
32
37
  this: FastifyInstance,
33
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
34
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
38
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
39
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
35
40
  done: HookHandlerDoneFunction
36
41
  ): void;
37
42
  }
@@ -41,12 +46,14 @@ export interface onRequestAsyncHookHandler<
41
46
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
42
47
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
43
48
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
44
- ContextConfig = ContextConfigDefault
49
+ ContextConfig = ContextConfigDefault,
50
+ SchemaCompiler extends FastifySchema = FastifySchema,
51
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
45
52
  > {
46
53
  (
47
54
  this: FastifyInstance,
48
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
49
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
55
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
56
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
50
57
  ): Promise<unknown>;
51
58
  }
52
59
 
@@ -59,12 +66,14 @@ export interface preParsingHookHandler<
59
66
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
60
67
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
61
68
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
62
- ContextConfig = ContextConfigDefault
69
+ ContextConfig = ContextConfigDefault,
70
+ SchemaCompiler extends FastifySchema = FastifySchema,
71
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
63
72
  > {
64
73
  (
65
74
  this: FastifyInstance,
66
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
67
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
75
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
76
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
68
77
  payload: RequestPayload,
69
78
  done: <TError extends Error = FastifyError>(err?: TError | null, res?: RequestPayload) => void
70
79
  ): void;
@@ -75,12 +84,14 @@ export interface preParsingAsyncHookHandler<
75
84
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
76
85
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
77
86
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
78
- ContextConfig = ContextConfigDefault
87
+ ContextConfig = ContextConfigDefault,
88
+ SchemaCompiler extends FastifySchema = FastifySchema,
89
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
79
90
  > {
80
91
  (
81
92
  this: FastifyInstance,
82
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
83
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
93
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
94
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
84
95
  payload: RequestPayload,
85
96
  ): Promise<RequestPayload | unknown>;
86
97
  }
@@ -93,12 +104,14 @@ export interface preValidationHookHandler<
93
104
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
94
105
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
95
106
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
96
- ContextConfig = ContextConfigDefault
107
+ ContextConfig = ContextConfigDefault,
108
+ SchemaCompiler extends FastifySchema = FastifySchema,
109
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
97
110
  > {
98
111
  (
99
112
  this: FastifyInstance,
100
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
101
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
113
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
114
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
102
115
  done: HookHandlerDoneFunction
103
116
  ): void;
104
117
  }
@@ -108,12 +121,14 @@ export interface preValidationAsyncHookHandler<
108
121
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
109
122
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
110
123
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
111
- ContextConfig = ContextConfigDefault
124
+ ContextConfig = ContextConfigDefault,
125
+ SchemaCompiler extends FastifySchema = FastifySchema,
126
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
112
127
  > {
113
128
  (
114
129
  this: FastifyInstance,
115
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
116
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
130
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
131
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
117
132
  ): Promise<unknown>;
118
133
  }
119
134
 
@@ -125,12 +140,14 @@ export interface preHandlerHookHandler<
125
140
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
126
141
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
127
142
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
128
- ContextConfig = ContextConfigDefault
143
+ ContextConfig = ContextConfigDefault,
144
+ SchemaCompiler extends FastifySchema = FastifySchema,
145
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
129
146
  > {
130
147
  (
131
148
  this: FastifyInstance,
132
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
133
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
149
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
150
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
134
151
  done: HookHandlerDoneFunction
135
152
  ): void;
136
153
  }
@@ -140,12 +157,14 @@ export interface preHandlerAsyncHookHandler<
140
157
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
141
158
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
142
159
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
143
- ContextConfig = ContextConfigDefault
160
+ ContextConfig = ContextConfigDefault,
161
+ SchemaCompiler extends FastifySchema = FastifySchema,
162
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
144
163
  > {
145
164
  (
146
165
  this: FastifyInstance,
147
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
148
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
166
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
167
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
149
168
  ): Promise<unknown>;
150
169
  }
151
170
 
@@ -166,12 +185,14 @@ export interface preSerializationHookHandler<
166
185
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
167
186
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
168
187
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
169
- ContextConfig = ContextConfigDefault
188
+ ContextConfig = ContextConfigDefault,
189
+ SchemaCompiler extends FastifySchema = FastifySchema,
190
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
170
191
  > {
171
192
  (
172
193
  this: FastifyInstance,
173
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
174
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
194
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
195
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
175
196
  payload: PreSerializationPayload,
176
197
  done: DoneFuncWithErrOrRes
177
198
  ): void;
@@ -183,12 +204,14 @@ export interface preSerializationAsyncHookHandler<
183
204
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
184
205
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
185
206
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
186
- ContextConfig = ContextConfigDefault
207
+ ContextConfig = ContextConfigDefault,
208
+ SchemaCompiler extends FastifySchema = FastifySchema,
209
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
187
210
  > {
188
211
  (
189
212
  this: FastifyInstance,
190
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
191
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
213
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
214
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
192
215
  payload: PreSerializationPayload
193
216
  ): Promise<unknown>;
194
217
  }
@@ -203,12 +226,14 @@ export interface onSendHookHandler<
203
226
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
204
227
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
205
228
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
206
- ContextConfig = ContextConfigDefault
229
+ ContextConfig = ContextConfigDefault,
230
+ SchemaCompiler extends FastifySchema = FastifySchema,
231
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
207
232
  > {
208
233
  (
209
234
  this: FastifyInstance,
210
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
211
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
235
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
236
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
212
237
  payload: OnSendPayload,
213
238
  done: DoneFuncWithErrOrRes
214
239
  ): void;
@@ -220,12 +245,14 @@ export interface onSendAsyncHookHandler<
220
245
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
221
246
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
222
247
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
223
- ContextConfig = ContextConfigDefault
248
+ ContextConfig = ContextConfigDefault,
249
+ SchemaCompiler extends FastifySchema = FastifySchema,
250
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
224
251
  > {
225
252
  (
226
253
  this: FastifyInstance,
227
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
228
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
254
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
255
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
229
256
  payload: OnSendPayload,
230
257
  ): Promise<unknown>;
231
258
  }
@@ -239,12 +266,14 @@ export interface onResponseHookHandler<
239
266
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
240
267
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
241
268
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
242
- ContextConfig = ContextConfigDefault
269
+ ContextConfig = ContextConfigDefault,
270
+ SchemaCompiler extends FastifySchema = FastifySchema,
271
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
243
272
  > {
244
273
  (
245
274
  this: FastifyInstance,
246
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
247
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
275
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
276
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
248
277
  done: HookHandlerDoneFunction
249
278
  ): void;
250
279
  }
@@ -254,12 +283,14 @@ export interface onResponseAsyncHookHandler<
254
283
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
255
284
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
256
285
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
257
- ContextConfig = ContextConfigDefault
286
+ ContextConfig = ContextConfigDefault,
287
+ SchemaCompiler extends FastifySchema = FastifySchema,
288
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
258
289
  > {
259
290
  (
260
291
  this: FastifyInstance,
261
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
262
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
292
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
293
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
263
294
  ): Promise<unknown>;
264
295
  }
265
296
 
@@ -272,12 +303,14 @@ export interface onTimeoutHookHandler<
272
303
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
273
304
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
274
305
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
275
- ContextConfig = ContextConfigDefault
306
+ ContextConfig = ContextConfigDefault,
307
+ SchemaCompiler extends FastifySchema = FastifySchema,
308
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
276
309
  > {
277
310
  (
278
311
  this: FastifyInstance,
279
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
280
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
312
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
313
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
281
314
  done: HookHandlerDoneFunction
282
315
  ): void;
283
316
  }
@@ -287,12 +320,14 @@ export interface onTimeoutAsyncHookHandler<
287
320
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
288
321
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
289
322
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
290
- ContextConfig = ContextConfigDefault
323
+ ContextConfig = ContextConfigDefault,
324
+ SchemaCompiler extends FastifySchema = FastifySchema,
325
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
291
326
  > {
292
327
  (
293
328
  this: FastifyInstance,
294
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
295
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
329
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
330
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
296
331
  ): Promise<unknown>;
297
332
  }
298
333
 
@@ -308,12 +343,14 @@ export interface onErrorHookHandler<
308
343
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
309
344
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
310
345
  ContextConfig = ContextConfigDefault,
311
- TError extends Error = FastifyError
346
+ TError extends Error = FastifyError,
347
+ SchemaCompiler extends FastifySchema = FastifySchema,
348
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
312
349
  > {
313
350
  (
314
351
  this: FastifyInstance,
315
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
316
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
352
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
353
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
317
354
  error: TError,
318
355
  done: () => void
319
356
  ): void;
@@ -325,12 +362,14 @@ export interface onErrorAsyncHookHandler<
325
362
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
326
363
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
327
364
  ContextConfig = ContextConfigDefault,
328
- TError extends Error = FastifyError
365
+ TError extends Error = FastifyError,
366
+ SchemaCompiler extends FastifySchema = FastifySchema,
367
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
329
368
  > {
330
369
  (
331
370
  this: FastifyInstance,
332
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
333
- reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
371
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
372
+ reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
334
373
  error: TError
335
374
  ): Promise<unknown>;
336
375
  }
@@ -345,11 +384,13 @@ export interface onRouteHookHandler<
345
384
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
346
385
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
347
386
  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
348
- ContextConfig = ContextConfigDefault
387
+ ContextConfig = ContextConfigDefault,
388
+ SchemaCompiler extends FastifySchema = FastifySchema,
389
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
349
390
  > {
350
391
  (
351
392
  this: FastifyInstance,
352
- opts: RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> & { routePath: string; path: string; prefix: string }
393
+ opts: RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider> & { routePath: string; path: string; prefix: string }
353
394
  ): Promise<unknown> | void;
354
395
  }
355
396
 
@@ -363,10 +404,11 @@ export interface onRegisterHookHandler<
363
404
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
364
405
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
365
406
  Logger = FastifyLoggerInstance,
407
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
366
408
  Options extends FastifyPluginOptions = FastifyPluginOptions
367
409
  > {
368
410
  (
369
- instance: FastifyInstance<RawServer, RawRequest, RawReply, Logger>,
411
+ instance: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
370
412
  opts: RegisterOptions & Options,
371
413
  done: HookHandlerDoneFunction
372
414
  ): Promise<unknown> | void; // documentation is missing the `done` method
@@ -394,10 +436,11 @@ export interface onCloseHookHandler<
394
436
  RawServer extends RawServerBase = RawServerDefault,
395
437
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
396
438
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
397
- Logger = FastifyLoggerInstance
439
+ Logger = FastifyLoggerInstance,
440
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
398
441
  > {
399
442
  (
400
- instance: FastifyInstance<RawServer, RawRequest, RawReply, Logger>,
443
+ instance: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
401
444
  done: HookHandlerDoneFunction
402
445
  ): void;
403
446
  }