fastify 5.11.2 → 6.0.0-alpha.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 (64) hide show
  1. package/README.md +9 -9
  2. package/SPONSORS.md +1 -0
  3. package/build/build-validation.js +20 -34
  4. package/docs/Guides/Getting-Started.md +2 -2
  5. package/docs/Guides/Serverless.md +34 -2
  6. package/docs/Reference/Encapsulation.md +31 -2
  7. package/docs/Reference/Errors.md +81 -6
  8. package/docs/Reference/Hooks.md +0 -4
  9. package/docs/Reference/LTS.md +6 -5
  10. package/docs/Reference/Request.md +18 -6
  11. package/docs/Reference/Routes.md +13 -0
  12. package/docs/Reference/Server.md +8 -88
  13. package/docs/Reference/TypeScript.md +3 -49
  14. package/docs/Reference/Warnings.md +4 -11
  15. package/fastify.d.ts +10 -24
  16. package/fastify.js +17 -34
  17. package/lib/config-validator.js +368 -475
  18. package/lib/content-type-parser.js +4 -0
  19. package/lib/decorate.js +1 -1
  20. package/lib/errors.js +9 -3
  21. package/lib/log-controller.js +3 -5
  22. package/lib/logger-factory.js +1 -1
  23. package/lib/reply.js +7 -3
  24. package/lib/route.js +4 -9
  25. package/lib/server.js +2 -3
  26. package/lib/warnings.js +2 -46
  27. package/package.json +2 -3
  28. package/test/404s.test.js +0 -49
  29. package/test/allow-unsafe-regex.test.js +12 -4
  30. package/test/case-insensitive.test.js +12 -4
  31. package/test/content-parser.test.js +32 -0
  32. package/test/custom-querystring-parser.test.js +0 -16
  33. package/test/decorator-instance-properties.test.js +49 -0
  34. package/test/hooks.test.js +6 -1
  35. package/test/http-methods/custom-http-methods.test.js +12 -17
  36. package/test/http-methods/trace.test.js +1 -1
  37. package/test/https/custom-https-server.test.js +1 -1
  38. package/test/internals/errors.test.js +15 -5
  39. package/test/internals/initial-config.test.js +56 -38
  40. package/test/internals/logger.test.js +17 -4
  41. package/test/internals/reply.test.js +1 -1
  42. package/test/internals/request.test.js +8 -24
  43. package/test/logger/logging.test.js +2 -121
  44. package/test/logger/request.test.js +1 -36
  45. package/test/plugin.4.test.js +5 -4
  46. package/test/reply-trailers.test.js +92 -4
  47. package/test/route-prefix.test.js +46 -18
  48. package/test/route.1.test.js +2 -2
  49. package/test/router-options.test.js +25 -523
  50. package/test/set-error-handler.test.js +7 -9
  51. package/test/types/errors.tst.ts +2 -1
  52. package/test/types/fastify.tst.ts +44 -48
  53. package/test/types/instance.tst.ts +4 -5
  54. package/test/types/logger.tst.ts +3 -7
  55. package/test/use-semicolon-delimiter.test.js +0 -60
  56. package/types/context.d.ts +0 -20
  57. package/types/errors.d.ts +2 -1
  58. package/types/instance.d.ts +0 -4
  59. package/types/logger.d.ts +2 -17
  60. package/types/plugin.d.ts +0 -9
  61. package/types/request.d.ts +0 -4
  62. package/.pi/bash-confirm-whitelist.json +0 -180
  63. package/lib/promise.js +0 -23
  64. package/test/internals/promise.test.js +0 -63
@@ -22,11 +22,9 @@ describes the properties available in that options object.
22
22
  - [`onConstructorPoisoning`](#onconstructorpoisoning)
23
23
  - [`logger`](#logger)
24
24
  - [`loggerInstance`](#loggerinstance)
25
- - [`disableRequestLogging`](#disablerequestlogging)
26
25
  - [`logController`](#logcontroller)
27
26
  - [`serverFactory`](#serverfactory)
28
27
  - [`requestIdHeader`](#requestidheader)
29
- - [`requestIdLogLabel`](#requestidloglabel)
30
28
  - [`genReqId`](#genreqid)
31
29
  - [`trustProxy`](#trustproxy)
32
30
  - [`pluginTimeout`](#plugintimeout)
@@ -387,71 +385,6 @@ Pino interface by having the following methods: `info`, `error`, `debug`,
387
385
  const fastify = require('fastify')({ loggerInstance: customLogger });
388
386
  ```
389
387
 
390
- ### `disableRequestLogging`
391
- <a id="factory-disable-request-logging"></a>
392
-
393
- > **Deprecated:** Use the [`logController`](#factory-log-controller)
394
- > option with `disableRequestLogging` or `isLogDisabled` override instead.
395
- > This top-level option will be removed in `fastify@6`.
396
-
397
- + Default: `false`
398
-
399
- When logging is enabled, Fastify will issue an `info` level log
400
- message when a request is received and when the response for that request has
401
- been sent. By setting this option to `true`, these log messages will be
402
- disabled. This allows for more flexible request start and end logging by
403
- attaching custom `onRequest` and `onResponse` hooks.
404
-
405
- This option can also be a function that receives the Fastify request object
406
- and returns a boolean. This allows for conditional request logging based on the
407
- request properties (e.g., URL, headers, decorations).
408
-
409
- ```js
410
- const { LogController } = require('fastify')
411
-
412
- // Deprecated
413
- const fastify = require('fastify')({
414
- logger: true,
415
- disableRequestLogging: (request) => {
416
- return request.url === '/health' || request.url === '/ready'
417
- }
418
- })
419
-
420
- // Recommended: use logController instead
421
- const fastify = require('fastify')({
422
- logger: true,
423
- logController: new LogController({
424
- disableRequestLogging: (request) => {
425
- return request.url === '/health' || request.url === '/ready'
426
- }
427
- })
428
- })
429
- ```
430
-
431
- The other log entries that will be disabled are:
432
- - an error log written by the default `onResponse` hook on reply callback errors
433
- - the error and info logs written by the `defaultErrorHandler`
434
- on error management
435
- - the info log written by the `fourOhFour` handler when a
436
- non existent route is requested
437
-
438
- Other log messages emitted by Fastify will stay enabled,
439
- like deprecation warnings and messages
440
- emitted when requests are received while the server is closing.
441
-
442
- ```js
443
- // Examples of hooks to replicate the disabled functionality.
444
- fastify.addHook('onRequest', (req, reply, done) => {
445
- req.log.info({ url: req.raw.url, id: req.id }, 'received request')
446
- done()
447
- })
448
-
449
- fastify.addHook('onResponse', (req, reply, done) => {
450
- req.log.info({ url: req.raw.originalUrl, statusCode: reply.raw.statusCode }, 'request completed')
451
- done()
452
- })
453
- ```
454
-
455
388
  ### `logController`
456
389
  <a id="factory-log-controller"></a>
457
390
 
@@ -593,17 +526,6 @@ const fastify = require('fastify')({
593
526
  > value of their choosing.
594
527
  > No validation is performed on `requestIdHeader`.
595
528
 
596
- ### `requestIdLogLabel`
597
- <a id="factory-request-id-log-label"></a>
598
-
599
- > **Deprecated:** Use the [`logController`](#factory-log-controller)
600
- > option with `requestIdLogLabel` instead. This top-level option will be
601
- > removed in `fastify@6`.
602
-
603
- + Default: `'reqId'`
604
-
605
- Defines the label used for the request identifier when logging the request.
606
-
607
529
  ### `genReqId`
608
530
  <a id="factory-gen-request-id"></a>
609
531
 
@@ -1227,16 +1149,15 @@ fastify.get('/dev', async (request, reply) => {
1227
1149
  ### `allowErrorHandlerOverride`
1228
1150
  <a id="allow-error-handler-override"></a>
1229
1151
 
1230
- * **Default:** `true`
1231
-
1232
- > ⚠ Warning:
1233
- > This option will be set to `false` by default
1234
- > in the next major release.
1152
+ * **Default:** `false`
1235
1153
 
1236
1154
  When set to `false`, it prevents `setErrorHandler` from being called
1237
1155
  multiple times within the same scope, ensuring that the previous error
1238
1156
  handler is not unintentionally overridden.
1239
1157
 
1158
+ Set this option to `true` to allow an error handler to be overridden within
1159
+ the same scope.
1160
+
1240
1161
  #### Example of incorrect usage:
1241
1162
 
1242
1163
  ```js
@@ -1732,7 +1653,8 @@ fastify.mkcol('/', (req, reply) => {
1732
1653
  })
1733
1654
  ```
1734
1655
 
1735
- Calling `addHttpMethod` for an existing method overrides its body behavior.
1656
+ Calling `addHttpMethod` for an existing method requires `overrideExisting: true`
1657
+ and overrides its body behavior.
1736
1658
 
1737
1659
  ```js
1738
1660
  fastify.addHttpMethod('GET', {
@@ -1741,8 +1663,8 @@ fastify.addHttpMethod('GET', {
1741
1663
  })
1742
1664
  ```
1743
1665
 
1744
- In Fastify v5, omitting `overrideExisting: true` emits `FSTDEP025`; in Fastify
1745
- v6, it will throw an error.
1666
+ Omitting `overrideExisting: true` when the method already exists throws
1667
+ `FST_ERR_ROUTE_METHOD_ALREADY_SUPPORTED`.
1746
1668
 
1747
1669
  #### addSchema
1748
1670
  <a id="add-schema"></a>
@@ -2446,12 +2368,10 @@ The properties that can currently be exposed are:
2446
2368
  - http2
2447
2369
  - https (it will return `false`/`true` or `{ allowHTTP1: true/false }` if
2448
2370
  explicitly passed)
2449
- - disableRequestLogging
2450
2371
  - onProtoPoisoning
2451
2372
  - onConstructorPoisoning
2452
2373
  - pluginTimeout
2453
2374
  - requestIdHeader
2454
- - requestIdLogLabel
2455
2375
  - http2SessionTimeout
2456
2376
  - routerOptions
2457
2377
  - allowUnsafeRegex
@@ -1334,14 +1334,6 @@ Interface method definition used within the
1334
1334
  Interface method definition used within the
1335
1335
  [`fastify.register()`][FastifyRegister] method.
1336
1336
 
1337
- ##### fastify.FastifyPlugin< [Options][FastifyPluginOptions]>
1338
- [src](https://github.com/fastify/fastify/blob/main/types/plugin.d.ts#L29)
1339
-
1340
- Interface method definition used within the
1341
- [`fastify.register()`][FastifyRegister] method. Document deprecated in favor of
1342
- `FastifyPluginCallback` and `FastifyPluginAsync` since general `FastifyPlugin`
1343
- doesn't properly infer types for async functions.
1344
-
1345
1337
  ##### fastify.FastifyPluginOptions
1346
1338
  [src](https://github.com/fastify/fastify/blob/main/types/plugin.d.ts#L31)
1347
1339
 
@@ -1358,8 +1350,6 @@ extends FastifyPluginOptions`) so they can be passed to the register method.
1358
1350
  [src](https://github.com/fastify/fastify/blob/main/types/register.d.ts#L9)
1359
1351
  ##### fastify.FastifyRegister(plugin: [FastifyPluginAsync][FastifyPluginAsync], opts: [FastifyRegisterOptions][FastifyRegisterOptions])
1360
1352
  [src](https://github.com/fastify/fastify/blob/main/types/register.d.ts#L9)
1361
- ##### fastify.FastifyRegister(plugin: [FastifyPlugin][FastifyPlugin], opts: [FastifyRegisterOptions][FastifyRegisterOptions])
1362
- [src](https://github.com/fastify/fastify/blob/main/types/register.d.ts#L9)
1363
1353
 
1364
1354
  This type interface specifies the type for the
1365
1355
  [`fastify.register()`](./Server.md#register) method. The type interface returns
@@ -1368,8 +1358,7 @@ a function signature with an underlying generic `Options` which is defaulted to
1368
1358
  FastifyPlugin parameter when calling this function so there is no need to
1369
1359
  specify the underlying generic. The options parameter is the intersection of the
1370
1360
  plugin's options and two additional optional properties: `prefix: string` and
1371
- `logLevel`: [LogLevel][LogLevel]. `FastifyPlugin` is deprecated use
1372
- `FastifyPluginCallback` and `FastifyPluginAsync` instead.
1361
+ `logLevel`: [LogLevel][LogLevel].
1373
1362
 
1374
1363
  Below is an example of the options inference in action:
1375
1364
 
@@ -1427,39 +1416,6 @@ Union type of: `'info' | 'error' | 'debug' | 'fatal' | 'warn' | 'trace'`
1427
1416
 
1428
1417
  ---
1429
1418
 
1430
- #### Context
1431
-
1432
- The context type definition is similar to the other highly dynamic pieces of the
1433
- type system. Route context is available in the route handler method.
1434
-
1435
- ##### fastify.FastifyRequestContext
1436
-
1437
- [src](https://github.com/fastify/fastify/blob/main/types/context.d.ts#L11)
1438
-
1439
- An interface with a single required property `config` that is set by default to
1440
- `unknown`. Can be specified either using a generic or an overload.
1441
-
1442
- This type definition is potentially incomplete. If you are using it and can
1443
- provide more details on how to improve the definition, we strongly encourage you
1444
- to open an issue in the main
1445
- [fastify/fastify](https://github.com/fastify/fastify) repository. Thank you in
1446
- advanced!
1447
-
1448
- ##### fastify.FastifyReplyContext
1449
-
1450
- [src](https://github.com/fastify/fastify/blob/main/types/context.d.ts#L11)
1451
-
1452
- An interface with a single required property `config` that is set by default to
1453
- `unknown`. Can be specified either using a generic or an overload.
1454
-
1455
- This type definition is potentially incomplete. If you are using it and can
1456
- provide more details on how to improve the definition, we strongly encourage you
1457
- to open an issue in the main
1458
- [fastify/fastify](https://github.com/fastify/fastify) repository. Thank you in
1459
- advanced!
1460
-
1461
- ---
1462
-
1463
1419
  #### Routing
1464
1420
 
1465
1421
  One of the core principles in Fastify is its routing capabilities. Most of the
@@ -1559,9 +1515,9 @@ FastifyError is a custom error object that includes status code and validation
1559
1515
  results.
1560
1516
 
1561
1517
  It extends the Node.js `Error` type, and adds two additional, optional
1562
- properties: `statusCode: number` and `validation: ValidationResult[]`.
1518
+ properties: `statusCode: number` and `validation: FastifySchemaValidationError[]`.
1563
1519
 
1564
- ##### fastify.ValidationResult
1520
+ ##### fastify.FastifySchemaValidationError
1565
1521
 
1566
1522
  [src](https://github.com/fastify/fastify/blob/main/fastify.d.ts#L184)
1567
1523
 
@@ -1713,8 +1669,6 @@ database.
1713
1669
  [FastifyInstance]: #fastifyfastifyinstance
1714
1670
  [FastifyLoggerOptions]: #fastifyfastifyloggeroptions
1715
1671
  [ContextConfigGeneric]: #ContextConfigGeneric
1716
- [FastifyPlugin]:
1717
- #fastifyfastifypluginoptions-rawserver-rawrequest-requestgeneric
1718
1672
  [FastifyPluginCallback]: #fastifyfastifyplugincallbackoptions
1719
1673
  [FastifyPluginAsync]: #fastifyfastifypluginasyncoptions
1720
1674
  [FastifyPluginOptions]: #fastifyfastifypluginoptions
@@ -7,12 +7,7 @@
7
7
  - [Fastify Warning Codes](#fastify-warning-codes)
8
8
  - [FSTWRN001](#FSTWRN001)
9
9
  - [FSTWRN003](#FSTWRN003)
10
- - [FSTWRN004](#FSTWRN004)
11
10
  - [Fastify Deprecation Codes](#fastify-deprecation-codes)
12
- - [FSTDEP022](#FSTDEP022)
13
- - [FSTDEP023](#FSTDEP023)
14
- - [FSTDEP024](#FSTDEP024)
15
- - [FSTDEP025](#FSTDEP025)
16
11
 
17
12
  ## Warnings
18
13
 
@@ -34,7 +29,7 @@ one of the following methods:
34
29
  - Set the `NODE_NO_WARNINGS` environment variable to `1`
35
30
  - Pass the `--no-warnings` flag to the node process
36
31
  - Set `no-warnings` in the `NODE_OPTIONS` environment variable
37
- - Pass `--disable-warning=FSTWRN004` to disable a specific warning
32
+ - Pass `--disable-warning=FSTWRN003` to disable a specific warning
38
33
 
39
34
  For more information on disabling warnings, see [Node's documentation](https://nodejs.org/api/cli.html).
40
35
 
@@ -46,7 +41,7 @@ Disabling warnings is not recommended and may cause unexpected behavior.
46
41
  | ---- | ----------- | ------------ | ---------- |
47
42
  | <a id="FSTWRN001">FSTWRN001</a> | The specified schema for a route is missing. This may indicate the schema is not well specified. | Check the schema for the route. | [#4647](https://github.com/fastify/fastify/pull/4647) |
48
43
  | <a id="FSTWRN003">FSTWRN003</a> | The `%s` plugin mixes async and callback styles, which may lead to unhandled rejections. | Do not mix async and callback style. | [#6011](https://github.com/fastify/fastify/pull/6011) |
49
- | <a id="FSTWRN004">FSTWRN004</a> | An `errorHandler` is being overridden in the same scope, which can lead to subtle bugs. | Avoid calling `setErrorHandler` more than once in the same scope. For more information, see [Server documentation](https://fastify.dev/docs/latest/Reference/Server/#allowerrorhandleroverride). | [#6104](https://github.com/fastify/fastify/pull/6104) |
44
+
50
45
  ### Fastify Deprecation Codes
51
46
 
52
47
  Deprecation codes are supported by the Node.js CLI options:
@@ -55,10 +50,8 @@ Deprecation codes are supported by the Node.js CLI options:
55
50
  - [--throw-deprecation](https://nodejs.org/api/cli.html#throw-deprecation)
56
51
  - [--trace-deprecation](https://nodejs.org/api/cli.html#trace-deprecation)
57
52
 
53
+ There are currently no active deprecation codes because the APIs deprecated in
54
+ Fastify v5 have been removed in Fastify v6.
58
55
 
59
56
  | Code | Description | How to solve | Discussion |
60
57
  | ---- | ----------- | ------------ | ---------- |
61
- | <a id="FSTDEP022">FSTDEP022</a> | You are trying to access the deprecated router options on top option properties. | Use `options.routerOptions`. | [#5985](https://github.com/fastify/fastify/pull/5985)
62
- | <a id="FSTDEP023">FSTDEP023</a> | `disableRequestLogging` top-level option is deprecated. | Pass a `LogController` instance via the `logController` option with `disableRequestLogging` in its constructor instead. |
63
- | <a id="FSTDEP024">FSTDEP024</a> | `requestIdLogLabel` top-level option is deprecated. | Pass a `LogController` instance via the `logController` option with `requestIdLogLabel` in its constructor instead. |
64
- | <a id="FSTDEP025">FSTDEP025</a> | Calling `addHttpMethod` for an existing HTTP method without `{ overrideExisting: true }` is deprecated. | Pass `{ overrideExisting: true }` to make the override explicit. | [#6879](https://github.com/fastify/fastify/pull/6879) |
package/fastify.d.ts CHANGED
@@ -10,21 +10,20 @@ import { ConstraintStrategy, Config as FindMyWayConfig, HTTPVersion } from 'find
10
10
  import { InjectOptions, CallbackFunc as LightMyRequestCallback, Chain as LightMyRequestChain, Response as LightMyRequestResponse } from 'light-my-request'
11
11
 
12
12
  import { AddContentTypeParser, ConstructorAction, FastifyBodyParser, FastifyContentTypeParser, getDefaultJsonParser, hasContentTypeParser, ProtoAction } from './types/content-type-parser'
13
- import { FastifyContextConfig, FastifyReplyContext, FastifyRequestContext } from './types/context'
13
+ import { FastifyContextConfig } from './types/context'
14
14
  import { FastifyErrorCodes } from './types/errors'
15
15
  import { DoneFuncWithErrOrRes, HookHandlerDoneFunction, onCloseAsyncHookHandler, onCloseHookHandler, onErrorAsyncHookHandler, onErrorHookHandler, onListenAsyncHookHandler, onListenHookHandler, onReadyAsyncHookHandler, onReadyHookHandler, onRegisterHookHandler, onRequestAbortAsyncHookHandler, onRequestAbortHookHandler, onRequestAsyncHookHandler, onRequestHookHandler, onResponseAsyncHookHandler, onResponseHookHandler, onRouteHookHandler, onSendAsyncHookHandler, onSendHookHandler, onTimeoutAsyncHookHandler, onTimeoutHookHandler, preCloseAsyncHookHandler, preCloseHookHandler, preHandlerAsyncHookHandler, preHandlerHookHandler, preParsingAsyncHookHandler, preParsingHookHandler, preSerializationAsyncHookHandler, preSerializationHookHandler, preValidationAsyncHookHandler, preValidationHookHandler, RequestPayload } from './types/hooks'
16
16
  import { FastifyInstance, FastifyListenOptions, PrintRoutesOptions } from './types/instance'
17
17
  import {
18
18
  FastifyBaseLogger,
19
19
  FastifyChildLoggerFactory,
20
- LogController as LogControllerClass,
21
20
  FastifyLogFn,
22
- FastifyLoggerInstance,
23
21
  FastifyLoggerOptions,
22
+ LogController as LogControllerClass,
24
23
  LogLevel,
25
24
  PinoLoggerOptions
26
25
  } from './types/logger'
27
- import { FastifyPlugin, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions } from './types/plugin'
26
+ import { FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions } from './types/plugin'
28
27
  import { FastifyRegister, FastifyRegisterOptions, RegisterOptions } from './types/register'
29
28
  import { FastifyReply } from './types/reply'
30
29
  import { FastifyRequest, RequestGenericInterface } from './types/request'
@@ -96,7 +95,10 @@ declare namespace fastify {
96
95
 
97
96
  type TrustProxyFunction = (address: string, hop: number) => boolean
98
97
 
99
- export type FastifyRouterOptions<RawServer extends RawServerBase> = Omit<FindMyWayConfigForServer<RawServer>, 'defaultRoute' | 'onBadUrl' | 'onMaxParamLength' | 'querystringParser'> & {
98
+ export type FastifyRouterOptions<RawServer extends RawServerBase> = Omit<FindMyWayConfigForServer<RawServer>, 'defaultRoute' | 'onBadUrl' | 'onMaxParamLength' | 'querystringParser' | 'constraints'> & {
99
+ constraints?: {
100
+ [name: string]: ConstraintStrategy<FindMyWayVersion<RawServer>, unknown>,
101
+ },
100
102
  defaultRoute?: (
101
103
  req: RawRequestDefaultExpression<RawServer>,
102
104
  res: RawReplyDefaultExpression<RawServer>
@@ -132,8 +134,6 @@ declare namespace fastify {
132
134
  bodyLimit?: number,
133
135
  handlerTimeout?: number,
134
136
  maxParamLength?: number,
135
- /** @deprecated Use the `logController` option with `disableRequestLogging` or `isLogDisabled` override instead. Will be removed in `fastify@6`. */
136
- disableRequestLogging?: boolean | ((req: FastifyRequest) => boolean),
137
137
  logController?: LogControllerClass,
138
138
  exposeHeadRoutes?: boolean,
139
139
  onProtoPoisoning?: ProtoAction,
@@ -142,18 +142,9 @@ declare namespace fastify {
142
142
  loggerInstance?: Logger
143
143
  serializerOpts?: FJSOptions | Record<string, unknown>,
144
144
  serverFactory?: FastifyServerFactory<RawServer>,
145
- caseSensitive?: boolean,
146
- allowUnsafeRegex?: boolean,
147
145
  requestIdHeader?: string | false,
148
- /** @deprecated Use the `logController` option with `requestIdLogLabel` instead. Will be removed in `fastify@6`. */
149
- requestIdLogLabel?: string;
150
- useSemicolonDelimiter?: boolean,
151
146
  genReqId?: (req: RawRequestDefaultExpression<RawServer>) => string,
152
147
  trustProxy?: boolean | string | string[] | number | TrustProxyFunction,
153
- querystringParser?: (str: string) => { [key: string]: unknown },
154
- constraints?: {
155
- [name: string]: ConstraintStrategy<FindMyWayVersion<RawServer>, unknown>,
156
- },
157
148
  schemaController?: {
158
149
  bucket?: (parentSchemas?: unknown) => {
159
150
  add(schema: unknown): FastifyInstance;
@@ -212,20 +203,15 @@ declare namespace fastify {
212
203
  routerOptions?: FastifyRouterOptions<RawServer>,
213
204
  }
214
205
 
215
- /**
216
- * @deprecated use {@link FastifySchemaValidationError}
217
- */
218
- export type ValidationResult = FastifySchemaValidationError
219
-
220
206
  /* Export additional types */
221
207
  export type {
222
208
  LightMyRequestChain, InjectOptions, LightMyRequestResponse, LightMyRequestCallback, // 'light-my-request'
223
209
  FastifyRequest, RequestGenericInterface, // './types/request'
224
210
  FastifyReply, // './types/reply'
225
- FastifyPluginCallback, FastifyPluginAsync, FastifyPluginOptions, FastifyPlugin, // './types/plugin'
211
+ FastifyPluginCallback, FastifyPluginAsync, FastifyPluginOptions, // './types/plugin'
226
212
  FastifyListenOptions, FastifyInstance, PrintRoutesOptions, // './types/instance'
227
- FastifyLoggerOptions, FastifyBaseLogger, FastifyLoggerInstance, FastifyLogFn, LogLevel, // './types/logger'
228
- FastifyRequestContext, FastifyContextConfig, FastifyReplyContext, // './types/context'
213
+ FastifyLoggerOptions, FastifyBaseLogger, FastifyLogFn, LogLevel, // './types/logger'
214
+ FastifyContextConfig, // './types/context'
229
215
  RouteHandler, RouteHandlerMethod, RouteOptions, RouteShorthandMethod, RouteShorthandOptions,
230
216
  RouteShorthandOptionsWithHandler, RouteGenericInterface, // './types/route'
231
217
  FastifyRegister, FastifyRegisterOptions, RegisterOptions, // './types/register'
package/fastify.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const VERSION = '5.11.2'
3
+ const VERSION = '6.0.0-alpha.0'
4
4
 
5
5
  const Avvio = require('avvio')
6
6
  const http = require('node:http')
@@ -57,7 +57,6 @@ const {
57
57
  AVVIO_ERRORS_MAP,
58
58
  ...errorCodes
59
59
  } = require('./lib/errors')
60
- const PonyPromise = require('./lib/promise')
61
60
 
62
61
  const { defaultInitOptions } = getSecuredInitialConfig
63
62
 
@@ -70,17 +69,17 @@ const {
70
69
  FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN,
71
70
  FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ,
72
71
  FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR,
73
- FST_ERR_INSTANCE_ALREADY_LISTENING,
72
+ FST_ERR_INSTANCE_ALREADY_STARTED,
74
73
  FST_ERR_REOPENED_CLOSE_SERVER,
75
74
  FST_ERR_ROUTE_REWRITE_NOT_STR,
76
75
  FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN,
77
76
  FST_ERR_ERROR_HANDLER_NOT_FN,
78
77
  FST_ERR_ERROR_HANDLER_ALREADY_SET,
79
- FST_ERR_ROUTE_METHOD_INVALID
78
+ FST_ERR_ROUTE_METHOD_INVALID,
79
+ FST_ERR_ROUTE_METHOD_ALREADY_SUPPORTED
80
80
  } = errorCodes
81
81
 
82
82
  const { buildErrorHandler } = require('./lib/error-handler.js')
83
- const { FSTWRN004, FSTDEP023, FSTDEP024, FSTDEP025 } = require('./lib/warnings.js')
84
83
 
85
84
  const initChannel = diagnostics.channel('fastify.initialization')
86
85
 
@@ -466,7 +465,7 @@ function fastify (serverOptions) {
466
465
  return fastify
467
466
 
468
467
  function throwIfAlreadyStarted (msg) {
469
- if (fastify[kState].started) throw new FST_ERR_INSTANCE_ALREADY_LISTENING(msg)
468
+ if (fastify[kState].started) throw new FST_ERR_INSTANCE_ALREADY_STARTED(msg)
470
469
  }
471
470
 
472
471
  // HTTP injection handling
@@ -528,7 +527,7 @@ function fastify (serverOptions) {
528
527
  // It will work as a barrier for all the .ready() calls (ensuring single hook execution)
529
528
  // as well as a flow control mechanism to chain cbs and further
530
529
  // promises
531
- this[kState].readyResolver = PonyPromise.withResolvers()
530
+ this[kState].readyResolver = Promise.withResolvers()
532
531
 
533
532
  if (!cb) {
534
533
  return this[kState].readyResolver.promise
@@ -771,10 +770,8 @@ function fastify (serverOptions) {
771
770
  throw new FST_ERR_ERROR_HANDLER_NOT_FN()
772
771
  }
773
772
 
774
- if (!options.allowErrorHandlerOverride && this[kErrorHandlerAlreadySet]) {
773
+ if (this[kErrorHandlerAlreadySet] && !options.allowErrorHandlerOverride) {
775
774
  throw new FST_ERR_ERROR_HANDLER_ALREADY_SET()
776
- } else if (this[kErrorHandlerAlreadySet]) {
777
- FSTWRN004()
778
775
  }
779
776
 
780
777
  this[kErrorHandlerAlreadySet] = true
@@ -832,7 +829,7 @@ function fastify (serverOptions) {
832
829
  this[kSupportedHTTPMethods].bodywith.has(method)
833
830
 
834
831
  if (alreadyExists && !overrideExisting) {
835
- FSTDEP025(method)
832
+ throw new FST_ERR_ROUTE_METHOD_ALREADY_SUPPORTED(method)
836
833
  }
837
834
 
838
835
  if (hasBody === true) {
@@ -864,13 +861,10 @@ function processOptions (options, defaultRoute, onBadUrl, onMaxParamLength) {
864
861
  }
865
862
 
866
863
  if (
867
- (options.querystringParser && typeof options.querystringParser !== 'function') ||
868
- (
869
- options.routerOptions?.querystringParser &&
864
+ options.routerOptions?.querystringParser &&
870
865
  typeof options.routerOptions.querystringParser !== 'function'
871
- )
872
866
  ) {
873
- throw new FST_ERR_QSP_NOT_FN(typeof (options.querystringParser ?? options.routerOptions.querystringParser))
867
+ throw new FST_ERR_QSP_NOT_FN(typeof options.routerOptions.querystringParser)
874
868
  }
875
869
 
876
870
  if (options.schemaController && options.schemaController.bucket && typeof options.schemaController.bucket !== 'function') {
@@ -881,13 +875,7 @@ function processOptions (options, defaultRoute, onBadUrl, onMaxParamLength) {
881
875
 
882
876
  const requestIdHeader = typeof options.requestIdHeader === 'string' && options.requestIdHeader.length !== 0 ? options.requestIdHeader.toLowerCase() : (options.requestIdHeader === true && 'request-id')
883
877
  const genReqId = reqIdGenFactory(requestIdHeader, options.genReqId)
884
- if (options.requestIdLogLabel !== undefined) {
885
- FSTDEP024()
886
- }
887
878
  options.bodyLimit = options.bodyLimit || defaultInitOptions.bodyLimit
888
- if (options.disableRequestLogging !== undefined) {
889
- FSTDEP023()
890
- }
891
879
 
892
880
  const ajvOptions = Object.assign({
893
881
  customOptions: {},
@@ -918,6 +906,13 @@ function processOptions (options, defaultRoute, onBadUrl, onMaxParamLength) {
918
906
  options.clientErrorHandler = options.clientErrorHandler || defaultClientErrorHandler
919
907
  options.allowErrorHandlerOverride = options.allowErrorHandlerOverride ?? defaultInitOptions.allowErrorHandlerOverride
920
908
 
909
+ options.routerOptions = buildRouterOptions(options, {
910
+ buildPrettyMeta: defaultBuildPrettyMeta,
911
+ defaultRoute,
912
+ onBadUrl,
913
+ onMaxParamLength
914
+ })
915
+
921
916
  const initialConfig = getSecuredInitialConfig(options)
922
917
 
923
918
  // exposeHeadRoutes have its default set from the validator
@@ -926,18 +921,6 @@ function processOptions (options, defaultRoute, onBadUrl, onMaxParamLength) {
926
921
  // we need to set this before calling createServer
927
922
  options.http2SessionTimeout = initialConfig.http2SessionTimeout
928
923
 
929
- options.routerOptions = buildRouterOptions(options, {
930
- defaultRoute,
931
- onBadUrl,
932
- onMaxParamLength,
933
- ignoreTrailingSlash: defaultInitOptions.ignoreTrailingSlash,
934
- ignoreDuplicateSlashes: defaultInitOptions.ignoreDuplicateSlashes,
935
- maxParamLength: defaultInitOptions.maxParamLength,
936
- allowUnsafeRegex: defaultInitOptions.allowUnsafeRegex,
937
- buildPrettyMeta: defaultBuildPrettyMeta,
938
- useSemicolonDelimiter: defaultInitOptions.useSemicolonDelimiter
939
- })
940
-
941
924
  return {
942
925
  options,
943
926
  genReqId,