fastify 5.3.3 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/.vscode/settings.json +15 -15
  2. package/LICENSE +1 -1
  3. package/README.md +2 -0
  4. package/SECURITY.md +158 -2
  5. package/build/build-validation.js +20 -1
  6. package/docs/Guides/Delay-Accepting-Requests.md +8 -5
  7. package/docs/Guides/Ecosystem.md +20 -5
  8. package/docs/Guides/Migration-Guide-V5.md +6 -10
  9. package/docs/Guides/Recommendations.md +1 -1
  10. package/docs/Reference/ContentTypeParser.md +1 -1
  11. package/docs/Reference/Errors.md +5 -3
  12. package/docs/Reference/Hooks.md +16 -20
  13. package/docs/Reference/Lifecycle.md +2 -2
  14. package/docs/Reference/Logging.md +3 -3
  15. package/docs/Reference/Middleware.md +1 -1
  16. package/docs/Reference/Reply.md +8 -8
  17. package/docs/Reference/Request.md +2 -2
  18. package/docs/Reference/Routes.md +7 -6
  19. package/docs/Reference/Server.md +341 -200
  20. package/docs/Reference/TypeScript.md +1 -3
  21. package/docs/Reference/Validation-and-Serialization.md +56 -4
  22. package/docs/Reference/Warnings.md +2 -1
  23. package/fastify.d.ts +4 -3
  24. package/fastify.js +47 -34
  25. package/lib/configValidator.js +196 -28
  26. package/lib/contentTypeParser.js +41 -48
  27. package/lib/error-handler.js +3 -3
  28. package/lib/errors.js +11 -0
  29. package/lib/handleRequest.js +13 -17
  30. package/lib/pluginOverride.js +3 -1
  31. package/lib/promise.js +23 -0
  32. package/lib/reply.js +24 -30
  33. package/lib/request.js +3 -10
  34. package/lib/route.js +37 -3
  35. package/lib/server.js +36 -35
  36. package/lib/symbols.js +1 -0
  37. package/lib/warnings.js +19 -1
  38. package/package.json +14 -10
  39. package/test/404s.test.js +226 -325
  40. package/test/allow-unsafe-regex.test.js +19 -48
  41. package/test/als.test.js +28 -40
  42. package/test/async-await.test.js +84 -128
  43. package/test/async_hooks.test.js +18 -37
  44. package/test/body-limit.test.js +90 -63
  45. package/test/buffer.test.js +22 -0
  46. package/test/build-certificate.js +1 -1
  47. package/test/case-insensitive.test.js +44 -65
  48. package/test/check.test.js +17 -21
  49. package/test/close-pipelining.test.js +24 -15
  50. package/test/constrained-routes.test.js +231 -0
  51. package/test/custom-http-server.test.js +7 -15
  52. package/test/custom-parser-async.test.js +17 -22
  53. package/test/custom-parser.0.test.js +267 -348
  54. package/test/custom-parser.1.test.js +141 -191
  55. package/test/custom-parser.2.test.js +34 -44
  56. package/test/custom-parser.3.test.js +56 -104
  57. package/test/custom-parser.4.test.js +106 -144
  58. package/test/custom-parser.5.test.js +56 -75
  59. package/test/custom-querystring-parser.test.js +51 -77
  60. package/test/decorator-namespace.test._js_ +3 -4
  61. package/test/decorator.test.js +76 -259
  62. package/test/delete.test.js +101 -110
  63. package/test/diagnostics-channel/404.test.js +7 -15
  64. package/test/diagnostics-channel/async-delay-request.test.js +7 -16
  65. package/test/diagnostics-channel/async-request.test.js +8 -16
  66. package/test/diagnostics-channel/error-request.test.js +7 -15
  67. package/test/diagnostics-channel/sync-delay-request.test.js +7 -16
  68. package/test/diagnostics-channel/sync-request-reply.test.js +9 -16
  69. package/test/diagnostics-channel/sync-request.test.js +9 -16
  70. package/test/fastify-instance.test.js +1 -1
  71. package/test/header-overflow.test.js +18 -29
  72. package/test/helper.js +139 -135
  73. package/test/hooks-async.test.js +259 -235
  74. package/test/hooks.test.js +951 -996
  75. package/test/http-methods/copy.test.js +14 -19
  76. package/test/http-methods/get.test.js +131 -143
  77. package/test/http-methods/head.test.js +53 -84
  78. package/test/http-methods/lock.test.js +31 -31
  79. package/test/http-methods/mkcalendar.test.js +45 -72
  80. package/test/http-methods/mkcol.test.js +5 -9
  81. package/test/http-methods/move.test.js +6 -10
  82. package/test/http-methods/propfind.test.js +34 -44
  83. package/test/http-methods/proppatch.test.js +23 -29
  84. package/test/http-methods/report.test.js +44 -69
  85. package/test/http-methods/search.test.js +67 -82
  86. package/test/http-methods/unlock.test.js +5 -9
  87. package/test/http2/closing.test.js +38 -20
  88. package/test/http2/secure-with-fallback.test.js +31 -28
  89. package/test/https/custom-https-server.test.js +9 -13
  90. package/test/https/https.test.js +56 -53
  91. package/test/input-validation.js +139 -150
  92. package/test/internals/errors.test.js +50 -1
  93. package/test/internals/handle-request.test.js +72 -65
  94. package/test/internals/promise.test.js +63 -0
  95. package/test/internals/reply.test.js +277 -496
  96. package/test/issue-4959.test.js +12 -3
  97. package/test/listen.4.test.js +31 -43
  98. package/test/nullable-validation.test.js +33 -46
  99. package/test/output-validation.test.js +24 -26
  100. package/test/plugin.1.test.js +40 -68
  101. package/test/plugin.2.test.js +108 -120
  102. package/test/plugin.3.test.js +50 -72
  103. package/test/plugin.4.test.js +124 -119
  104. package/test/promises.test.js +42 -63
  105. package/test/proto-poisoning.test.js +78 -97
  106. package/test/register.test.js +8 -18
  107. package/test/request-error.test.js +57 -146
  108. package/test/request-id.test.js +30 -49
  109. package/test/route-hooks.test.js +117 -101
  110. package/test/route-prefix.test.js +194 -133
  111. package/test/route-shorthand.test.js +9 -27
  112. package/test/route.1.test.js +74 -131
  113. package/test/route.8.test.js +9 -17
  114. package/test/router-options.test.js +450 -0
  115. package/test/schema-serialization.test.js +177 -154
  116. package/test/schema-special-usage.test.js +165 -132
  117. package/test/schema-validation.test.js +254 -218
  118. package/test/server.test.js +143 -5
  119. package/test/set-error-handler.test.js +58 -1
  120. package/test/skip-reply-send.test.js +64 -69
  121. package/test/stream.1.test.js +33 -50
  122. package/test/stream.4.test.js +18 -28
  123. package/test/stream.5.test.js +11 -19
  124. package/test/trust-proxy.test.js +32 -58
  125. package/test/types/errors.test-d.ts +13 -1
  126. package/test/types/fastify.test-d.ts +3 -0
  127. package/test/types/request.test-d.ts +1 -0
  128. package/test/types/type-provider.test-d.ts +55 -0
  129. package/test/url-rewriting.test.js +45 -62
  130. package/test/use-semicolon-delimiter.test.js +117 -59
  131. package/test/versioned-routes.test.js +39 -56
  132. package/types/errors.d.ts +11 -1
  133. package/types/hooks.d.ts +1 -1
  134. package/types/instance.d.ts +1 -1
  135. package/types/reply.d.ts +2 -2
  136. package/types/request.d.ts +1 -0
  137. package/.taprc +0 -7
@@ -151,7 +151,7 @@ fastify.get('/', async function (req, rep) {
151
151
  Sets a response header. If the value is omitted or undefined, it is coerced to
152
152
  `''`.
153
153
 
154
- > 🛈 Note: The header's value must be properly encoded using
154
+ > â„šī¸ Note: The header's value must be properly encoded using
155
155
  > [`encodeURI`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
156
156
  > or similar modules such as
157
157
  > [`encodeurl`](https://www.npmjs.com/package/encodeurl). Invalid characters
@@ -260,10 +260,10 @@ requires heavy resources to be sent after the `data`, for example,
260
260
  `Server-Timing` and `Etag`. It can ensure the client receives the response data
261
261
  as soon as possible.
262
262
 
263
- > 🛈 Note: The header `Transfer-Encoding: chunked` will be added once you use
263
+ > â„šī¸ Note: The header `Transfer-Encoding: chunked` will be added once you use
264
264
  > the trailer. It is a hard requirement for using trailer in Node.js.
265
265
 
266
- > 🛈 Note: Any error passed to `done` callback will be ignored. If you interested
266
+ > â„šī¸ Note: Any error passed to `done` callback will be ignored. If you interested
267
267
  > in the error, you can turn on `debug` level logging.*
268
268
 
269
269
  ```js
@@ -279,14 +279,14 @@ const { createHash } = require('node:crypto')
279
279
  reply.trailer('content-md5', function(reply, payload, done) {
280
280
  const hash = createHash('md5')
281
281
  hash.update(payload)
282
- done(null, hash.disgest('hex'))
282
+ done(null, hash.digest('hex'))
283
283
  })
284
284
 
285
285
  // when you prefer async-await
286
286
  reply.trailer('content-md5', async function(reply, payload) {
287
287
  const hash = createHash('md5')
288
288
  hash.update(payload)
289
- return hash.disgest('hex')
289
+ return hash.digest('hex')
290
290
  })
291
291
  ```
292
292
 
@@ -314,7 +314,7 @@ reply.getTrailer('server-timing') // undefined
314
314
  Redirects a request to the specified URL, the status code is optional, default
315
315
  to `302` (if status code is not already set by calling `code`).
316
316
 
317
- > 🛈 Note: The input URL must be properly encoded using
317
+ > â„šī¸ Note: The input URL must be properly encoded using
318
318
  > [`encodeURI`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
319
319
  > or similar modules such as
320
320
  > [`encodeurl`](https://www.npmjs.com/package/encodeurl). Invalid URLs will
@@ -823,7 +823,7 @@ automatically create an error structured as the following:
823
823
  You can add custom properties to the Error object, such as `headers`, that will
824
824
  be used to enhance the HTTP response.
825
825
 
826
- > 🛈 Note: If you are passing an error to `send` and the statusCode is less than
826
+ > â„šī¸ Note: If you are passing an error to `send` and the statusCode is less than
827
827
  > 400, Fastify will automatically set it at 500.
828
828
 
829
829
  Tip: you can simplify errors by using the
@@ -871,7 +871,7 @@ fastify.get('/', {
871
871
  If you want to customize error handling, check out
872
872
  [`setErrorHandler`](./Server.md#seterrorhandler) API.
873
873
 
874
- > 🛈 Note: you are responsible for logging when customizing the error handler.
874
+ > â„šī¸ Note: you are responsible for logging when customizing the error handler.
875
875
 
876
876
  API:
877
877
 
@@ -84,7 +84,7 @@ This operation adds new values to the request headers, accessible via
84
84
  For performance reasons, `Symbol('fastify.RequestAcceptVersion')` may be added
85
85
  to headers on `not found` routes.
86
86
 
87
- > 🛈 Note: Schema validation may mutate the `request.headers` and
87
+ > â„šī¸ Note: Schema validation may mutate the `request.headers` and
88
88
  > `request.raw.headers` objects, causing the headers to become empty.
89
89
 
90
90
  ```js
@@ -237,7 +237,7 @@ const newValidate = request.compileValidationSchema(newSchema)
237
237
  console.log(newValidate === validate) // false
238
238
  ```
239
239
 
240
- ### .validateInput(data, [schema | httpStatus], [httpStatus])
240
+ ### .validateInput(data, [schema | httpPart], [httpPart])
241
241
  <a id="validate"></a>
242
242
 
243
243
  This function validates the input based on the provided schema or HTTP part. If
@@ -59,8 +59,9 @@ fastify.route(options)
59
59
  one.
60
60
  * `onRequest(request, reply, done)`: a [function](./Hooks.md#onrequest) called
61
61
  as soon as a request is received, it could also be an array of functions.
62
- * `preParsing(request, reply, done)`: a [function](./Hooks.md#preparsing) called
63
- before parsing the request, it could also be an array of functions.
62
+ * `preParsing(request, reply, payload, done)`: a
63
+ [function](./Hooks.md#preparsing) called before parsing the request, it could
64
+ also be an array of functions.
64
65
  * `preValidation(request, reply, done)`: a [function](./Hooks.md#prevalidation)
65
66
  called after the shared `preValidation` hooks, useful if you need to perform
66
67
  authentication at route level for example, it could also be an array of
@@ -137,7 +138,7 @@ fastify.route(options)
137
138
 
138
139
  * `reply` is defined in [Reply](./Reply.md).
139
140
 
140
- > 🛈 Note: The documentation for `onRequest`, `preParsing`, `preValidation`,
141
+ > â„šī¸ Note: The documentation for `onRequest`, `preParsing`, `preValidation`,
141
142
  > `preHandler`, `preSerialization`, `onSend`, and `onResponse` is detailed in
142
143
  > [Hooks](./Hooks.md). To send a response before the request is handled by the
143
144
  > `handler`, see [Respond to a request from
@@ -233,7 +234,7 @@ const opts = {
233
234
  fastify.get('/', opts)
234
235
  ```
235
236
 
236
- > 🛈 Note: Specifying the handler in both `options` and as the third parameter to
237
+ > â„šī¸ Note: Specifying the handler in both `options` and as the third parameter to
237
238
  > the shortcut method throws a duplicate `handler` error.
238
239
 
239
240
  ### Url building
@@ -402,7 +403,7 @@ This approach supports both `callback-style` and `async-await` with minimal
402
403
  trade-off. However, it is recommended to use only one style for consistent
403
404
  error handling within your application.
404
405
 
405
- > 🛈 Note: Every async function returns a promise by itself.
406
+ > â„šī¸ Note: Every async function returns a promise by itself.
406
407
 
407
408
  ### Route Prefixing
408
409
  <a id="route-prefixing"></a>
@@ -781,7 +782,7 @@ const secret = {
781
782
  > const Fastify = require('fastify')
782
783
  >
783
784
  > const fastify = Fastify({
784
- > frameworkErrors: function (err, res, res) {
785
+ > frameworkErrors: function (err, req, res) {
785
786
  > if (err instanceof Fastify.errorCodes.FST_ERR_ASYNC_CONSTRAINT) {
786
787
  > res.code(400)
787
788
  > return res.send("Invalid header provided")