fastify 5.1.0 → 5.2.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 (111) hide show
  1. package/README.md +12 -7
  2. package/docs/Guides/Database.md +15 -15
  3. package/docs/Guides/Detecting-When-Clients-Abort.md +28 -28
  4. package/docs/Guides/Ecosystem.md +13 -7
  5. package/docs/Guides/Index.md +1 -1
  6. package/docs/Guides/Migration-Guide-V4.md +11 -11
  7. package/docs/Guides/Migration-Guide-V5.md +5 -5
  8. package/docs/Guides/Plugins-Guide.md +1 -1
  9. package/docs/Guides/Prototype-Poisoning.md +3 -3
  10. package/docs/Guides/Recommendations.md +9 -9
  11. package/docs/Guides/Serverless.md +5 -5
  12. package/docs/Guides/Testing.md +8 -8
  13. package/docs/Guides/Write-Plugin.md +1 -1
  14. package/docs/Guides/Write-Type-Provider.md +3 -3
  15. package/docs/Reference/Decorators.md +2 -2
  16. package/docs/Reference/Errors.md +2 -2
  17. package/docs/Reference/Hooks.md +7 -7
  18. package/docs/Reference/LTS.md +8 -0
  19. package/docs/Reference/Logging.md +5 -4
  20. package/docs/Reference/Reply.md +54 -53
  21. package/docs/Reference/Request.md +49 -43
  22. package/docs/Reference/Routes.md +7 -7
  23. package/docs/Reference/Server.md +31 -27
  24. package/docs/Reference/TypeScript.md +9 -9
  25. package/docs/Reference/Validation-and-Serialization.md +5 -5
  26. package/examples/typescript-server.ts +1 -1
  27. package/fastify.d.ts +4 -4
  28. package/fastify.js +1 -1
  29. package/lib/error-handler.js +9 -9
  30. package/lib/errors.js +1 -1
  31. package/lib/hooks.js +4 -1
  32. package/lib/request.js +11 -10
  33. package/package.json +3 -4
  34. package/test/{allowUnsafeRegex.test.js → allow-unsafe-regex.test.js} +4 -4
  35. package/test/async-dispose.test.js +0 -1
  36. package/test/async_hooks.test.js +4 -4
  37. package/test/buffer.test.js +4 -4
  38. package/test/build-certificate.js +1 -1
  39. package/test/bundler/README.md +5 -5
  40. package/test/case-insensitive.test.js +10 -10
  41. package/test/check.test.js +2 -3
  42. package/test/{childLoggerFactory.test.js → child-logger-factory.test.js} +1 -1
  43. package/test/client-timeout.test.js +1 -1
  44. package/test/close-pipelining.test.js +0 -1
  45. package/test/conditional-pino.test.js +3 -3
  46. package/test/content-length.test.js +53 -68
  47. package/test/content-parser.test.js +178 -167
  48. package/test/content-type.test.js +8 -9
  49. package/test/context-config.test.js +44 -54
  50. package/test/custom-parser.5.test.js +32 -32
  51. package/test/encapsulated-child-logger-factory.test.js +8 -8
  52. package/test/encapsulated-error-handler.test.js +20 -20
  53. package/test/fastify-instance.test.js +33 -34
  54. package/test/{findRoute.test.js → find-route.test.js} +11 -10
  55. package/test/fluent-schema.test.js +33 -36
  56. package/test/handler-context.test.js +11 -11
  57. package/test/has-route.test.js +12 -15
  58. package/test/header-overflow.test.js +13 -12
  59. package/test/hooks.on-ready.test.js +2 -2
  60. package/test/hooks.test.js +19 -19
  61. package/test/http-methods/head.test.js +0 -3
  62. package/test/imports.test.js +2 -2
  63. package/test/internals/errors.test.js +1 -1
  64. package/test/listen.5.test.js +9 -9
  65. package/test/{maxRequestsPerSocket.test.js → max-requests-per-socket.test.js} +30 -30
  66. package/test/middleware.test.js +4 -5
  67. package/test/noop-set.test.js +1 -1
  68. package/test/post-empty-body.test.js +18 -11
  69. package/test/pretty-print.test.js +59 -49
  70. package/test/proto-poisoning.test.js +42 -37
  71. package/test/reply-code.test.js +34 -32
  72. package/test/{reply-earlyHints.test.js → reply-early-hints.test.js} +21 -19
  73. package/test/request-header-host.test.js +154 -12
  74. package/test/request-id.test.js +31 -25
  75. package/test/{requestTimeout.test.js → request-timeout.test.js} +11 -11
  76. package/test/route.3.test.js +3 -2
  77. package/test/route.8.test.js +20 -20
  78. package/test/router-options.test.js +80 -77
  79. package/test/schema-examples.test.js +72 -38
  80. package/test/server.test.js +12 -12
  81. package/test/set-error-handler.test.js +2 -3
  82. package/test/stream-serializers.test.js +10 -7
  83. package/test/sync-routes.test.js +18 -18
  84. package/test/trust-proxy.test.js +51 -45
  85. package/test/type-provider.test.js +8 -6
  86. package/test/types/content-type-parser.test-d.ts +1 -1
  87. package/test/types/fastify.test-d.ts +4 -4
  88. package/test/types/instance.test-d.ts +3 -1
  89. package/test/types/logger.test-d.ts +2 -2
  90. package/test/types/plugin.test-d.ts +2 -2
  91. package/test/types/register.test-d.ts +2 -2
  92. package/test/types/reply.test-d.ts +1 -1
  93. package/test/types/route.test-d.ts +1 -1
  94. package/test/types/serverFactory.test-d.ts +1 -1
  95. package/test/types/type-provider.test-d.ts +1 -1
  96. package/test/url-rewriting.test.js +35 -38
  97. package/test/{useSemicolonDelimiter.test.js → use-semicolon-delimiter.test.js} +30 -30
  98. package/test/validation-error-handling.test.js +259 -285
  99. package/types/hooks.d.ts +1 -1
  100. package/types/instance.d.ts +9 -2
  101. package/types/reply.d.ts +1 -1
  102. package/types/request.d.ts +0 -4
  103. package/types/serverFactory.d.ts +3 -3
  104. package/types/utils.d.ts +3 -3
  105. /package/test/{connectionTimeout.test.js → connection-timeout.test.js} +0 -0
  106. /package/test/internals/{contentTypeParser.test.js → content-type-parser.test.js} +0 -0
  107. /package/test/internals/{handleRequest.test.js → handle-request.test.js} +0 -0
  108. /package/test/internals/{hookRunner.test.js → hook-runner.test.js} +0 -0
  109. /package/test/internals/{initialConfig.test.js → initial-config.test.js} +0 -0
  110. /package/test/internals/{reqIdGenFactory.test.js → req-id-gen-factory.test.js} +0 -0
  111. /package/test/{wrapThenable.test.js → wrap-thenable.test.js} +0 -0
package/types/hooks.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Readable } from 'stream'
1
+ import { Readable } from 'node:stream'
2
2
  import { FastifyInstance } from './instance'
3
3
  import { RouteOptions, RouteGenericInterface } from './route'
4
4
  import { RawServerBase, RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, ContextConfigDefault } from './utils'
@@ -1,8 +1,8 @@
1
1
  import { FastifyError } from '@fastify/error'
2
2
  import { ConstraintStrategy, FindResult, HTTPVersion } from 'find-my-way'
3
- import * as http from 'http'
3
+ import * as http from 'node:http'
4
4
  import { InjectOptions, CallbackFunc as LightMyRequestCallback, Chain as LightMyRequestChain, Response as LightMyRequestResponse } from 'light-my-request'
5
- import { AddressInfo } from 'net'
5
+ import { AddressInfo } from 'node:net'
6
6
  import { AddContentTypeParser, ConstructorAction, FastifyBodyParser, ProtoAction, getDefaultJsonParser, hasContentTypeParser, removeAllContentTypeParsers, removeContentTypeParser } from './content-type-parser'
7
7
  import { ApplicationHook, HookAsyncLookup, HookLookup, LifecycleHook, 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 } from './hooks'
8
8
  import { FastifyBaseLogger, FastifyChildLoggerFactory } from './logger'
@@ -548,6 +548,13 @@ export interface FastifyInstance<
548
548
  * Remove all content type parsers, including the default ones
549
549
  */
550
550
  removeAllContentTypeParsers: removeAllContentTypeParsers
551
+ /**
552
+ * Add a non-standard HTTP method
553
+ *
554
+ * Methods defined by default include `GET`, `HEAD`, `TRACE`, `DELETE`,
555
+ * `OPTIONS`, `PATCH`, `PUT` and `POST`
556
+ */
557
+ addHttpMethod(method: string, methodOptions?: { hasBody: boolean }): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
551
558
  /**
552
559
  * Fastify default JSON parser
553
560
  */
package/types/reply.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Buffer } from 'buffer'
1
+ import { Buffer } from 'node:buffer'
2
2
  import { FastifyInstance } from './instance'
3
3
  import { FastifyBaseLogger } from './logger'
4
4
  import { FastifyRequest, RequestRouteOptions } from './request'
@@ -87,8 +87,4 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
87
87
  compileValidationSchema(schema: { [key: string]: any }, httpPart?: HTTPRequestPart): ValidationFunction
88
88
  validateInput(input: any, schema: { [key: string]: any }, httpPart?: HTTPRequestPart): boolean
89
89
  validateInput(input: any, httpPart?: HTTPRequestPart): boolean
90
-
91
- // Prefer `socket` over deprecated `connection` property in node 13.0.0 or higher
92
- // @deprecated
93
- readonly connection: RawRequest['socket'];
94
90
  }
@@ -1,7 +1,7 @@
1
1
  import { RawServerBase, RawServerDefault, RawReplyDefaultExpression, RawRequestDefaultExpression } from './utils'
2
- import * as http from 'http'
3
- import * as https from 'https'
4
- import * as http2 from 'http2'
2
+ import * as http from 'node:http'
3
+ import * as https from 'node:https'
4
+ import * as http2 from 'node:http2'
5
5
 
6
6
  export type FastifyServerFactoryHandler<
7
7
  RawServer extends RawServerBase = RawServerDefault,
package/types/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import * as http from 'http'
2
- import * as http2 from 'http2'
3
- import * as https from 'https'
1
+ import * as http from 'node:http'
2
+ import * as http2 from 'node:http2'
3
+ import * as https from 'node:https'
4
4
 
5
5
  type AutocompletePrimitiveBaseType<T> =
6
6
  T extends string ? string :