fastify 5.9.0 → 5.11.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 (74) hide show
  1. package/PROJECT_CHARTER.md +1 -1
  2. package/README.md +7 -10
  3. package/SPONSORS.md +1 -0
  4. package/build/build-validation.js +2 -2
  5. package/docs/Guides/Delay-Accepting-Requests.md +1 -1
  6. package/docs/Guides/Ecosystem.md +12 -9
  7. package/docs/Guides/Getting-Started.md +10 -10
  8. package/docs/Guides/Migration-Guide-V4.md +2 -2
  9. package/docs/Guides/Migration-Guide-V5.md +1 -1
  10. package/docs/Guides/Plugins-Guide.md +1 -1
  11. package/docs/Guides/Prototype-Poisoning.md +3 -3
  12. package/docs/Guides/Serverless.md +6 -13
  13. package/docs/Guides/Style-Guide.md +1 -1
  14. package/docs/Reference/Errors.md +6 -0
  15. package/docs/Reference/Hooks.md +1 -1
  16. package/docs/Reference/Logging.md +3 -0
  17. package/docs/Reference/Reply.md +2 -2
  18. package/docs/Reference/Request.md +13 -13
  19. package/docs/Reference/Server.md +117 -17
  20. package/docs/Reference/Type-Providers.md +24 -4
  21. package/docs/Reference/TypeScript.md +8 -10
  22. package/docs/Reference/Warnings.md +5 -0
  23. package/eslint.config.js +1 -1
  24. package/fastify.d.ts +60 -13
  25. package/fastify.js +28 -23
  26. package/lib/content-type-parser.js +1 -11
  27. package/lib/content-type.js +70 -19
  28. package/lib/context.js +0 -3
  29. package/lib/error-handler.js +7 -26
  30. package/lib/errors.js +17 -0
  31. package/lib/four-oh-four.js +8 -10
  32. package/lib/handle-request.js +37 -8
  33. package/lib/hooks.js +5 -1
  34. package/lib/log-controller.js +169 -0
  35. package/lib/logger-factory.js +25 -4
  36. package/lib/reply.js +35 -44
  37. package/lib/req-id-gen-factory.js +4 -1
  38. package/lib/request.js +3 -3
  39. package/lib/route.js +28 -36
  40. package/lib/schemas.js +3 -3
  41. package/lib/symbols.js +1 -1
  42. package/lib/validation.js +10 -1
  43. package/lib/warnings.js +19 -1
  44. package/package.json +4 -4
  45. package/test/content-type.test.js +51 -4
  46. package/test/find-route.test.js +35 -0
  47. package/test/fix-6411.test.js +65 -0
  48. package/test/genReqId.test.js +24 -0
  49. package/test/hooks.test.js +71 -0
  50. package/test/internals/all.test.js +2 -1
  51. package/test/internals/errors.test.js +21 -1
  52. package/test/internals/logger.test.js +322 -0
  53. package/test/internals/reply.test.js +57 -4
  54. package/test/internals/request.test.js +10 -7
  55. package/test/logger/logging.test.js +40 -1
  56. package/test/reply-error.test.js +35 -0
  57. package/test/rfc-10008.test.js +147 -0
  58. package/test/route-shorthand.test.js +14 -4
  59. package/test/schema-serialization.test.js +33 -0
  60. package/test/stream.4.test.js +2 -2
  61. package/test/trust-proxy.test.js +49 -30
  62. package/test/types/errors.tst.ts +2 -0
  63. package/test/types/route.tst.ts +3 -3
  64. package/types/content-type-parser.d.ts +26 -6
  65. package/types/errors.d.ts +3 -0
  66. package/types/hooks.d.ts +137 -76
  67. package/types/instance.d.ts +152 -47
  68. package/types/logger.d.ts +57 -2
  69. package/types/plugin.d.ts +7 -3
  70. package/types/register.d.ts +53 -10
  71. package/types/reply.d.ts +62 -14
  72. package/types/route.d.ts +68 -34
  73. package/types/type-provider.d.ts +29 -8
  74. package/types/utils.d.ts +2 -2
package/types/reply.d.ts CHANGED
@@ -14,7 +14,8 @@ export interface ReplyGenericInterface {
14
14
  type HttpCodesReplyType = Partial<Record<HttpKeys, unknown>>
15
15
 
16
16
  type ReplyTypeConstrainer<RouteGenericReply, Code extends ReplyKeysToCodes<keyof RouteGenericReply>> =
17
- RouteGenericReply extends HttpCodesReplyType & Record<Exclude<keyof RouteGenericReply, keyof HttpCodesReplyType>, never> ?
17
+ RouteGenericReply extends HttpCodesReplyType &
18
+ Record<Exclude<keyof RouteGenericReply, keyof HttpCodesReplyType>, never> ?
18
19
  Code extends keyof RouteGenericReply ? RouteGenericReply[Code] :
19
20
  CodeToReplyKey<Code> extends keyof RouteGenericReply ? RouteGenericReply[CodeToReplyKey<Code>] : unknown :
20
21
  RouteGenericReply
@@ -50,32 +51,79 @@ export interface FastifyReply<
50
51
  status<Code extends keyof SchemaCompiler['response'] extends never ? ReplyKeysToCodes<keyof RouteGeneric['Reply']> : keyof SchemaCompiler['response'] extends ReplyKeysToCodes<keyof RouteGeneric['Reply']> ? keyof SchemaCompiler['response'] : ReplyKeysToCodes<keyof RouteGeneric['Reply']>>(statusCode: Code): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider, ResolveReplyTypeWithRouteGeneric<RouteGeneric['Reply'], Code, SchemaCompiler, TypeProvider>>;
51
52
  statusCode: number;
52
53
  sent: boolean;
53
- send(...args: SendArgs<ReplyType>): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
54
- header(key: HttpHeader, value: any): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
55
- headers(values: Partial<Record<HttpHeader, number | string | string[] | undefined>>): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
54
+ send(...args: SendArgs<ReplyType>): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig,
55
+ SchemaCompiler, TypeProvider>;
56
+ header(key: HttpHeader, value: any): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig,
57
+ SchemaCompiler, TypeProvider>;
58
+ headers(values: Partial<Record<HttpHeader, number | string | string[] | undefined>>): FastifyReply<RouteGeneric,
59
+ RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
56
60
  getHeader(key: HttpHeader): number | string | string[] | undefined;
57
61
  getHeaders(): Record<HttpHeader, number | string | string[] | undefined>;
58
- removeHeader(key: HttpHeader): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
62
+ removeHeader(key: HttpHeader): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig,
63
+ SchemaCompiler, TypeProvider>;
59
64
  hasHeader(key: HttpHeader): boolean;
60
- redirect(url: string, statusCode?: number): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
65
+ redirect(url: string, statusCode?: number): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig,
66
+ SchemaCompiler, TypeProvider>;
61
67
  writeEarlyHints(hints: Record<string, string | string[]>, callback?: () => void): void;
62
68
  hijack(): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
63
69
  callNotFound(): void;
64
- type(contentType: string): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
65
- serializer(fn: (payload: any) => string): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
70
+ type(contentType: string): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler,
71
+ TypeProvider>;
72
+ serializer(fn: (payload: any) => string): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig,
73
+ SchemaCompiler, TypeProvider>;
66
74
  serialize(payload: any): string | ArrayBuffer | Buffer;
67
75
  // Serialization Methods
68
- getSerializationFunction(httpStatus: string, contentType?: string): ((payload: { [key: string]: unknown }) => string) | undefined;
69
- getSerializationFunction(schema: { [key: string]: unknown }): ((payload: { [key: string]: unknown }) => string) | undefined;
70
- compileSerializationSchema(schema: { [key: string]: unknown }, httpStatus?: string, contentType?: string): (payload: { [key: string]: unknown }) => string;
71
- serializeInput(input: { [key: string]: unknown }, schema: { [key: string]: unknown }, httpStatus?: string, contentType?: string): string;
76
+ getSerializationFunction(
77
+ httpStatus: string,
78
+ contentType?: string
79
+ ): ((payload: { [key: string]: unknown }) => string) | undefined;
80
+ getSerializationFunction(
81
+ schema: { [key: string]: unknown }
82
+ ): ((payload: { [key: string]: unknown }) => string) | undefined;
83
+ compileSerializationSchema(
84
+ schema: { [key: string]: unknown },
85
+ httpStatus?: string,
86
+ contentType?: string
87
+ ): (payload: { [key: string]: unknown }) => string;
88
+ serializeInput(
89
+ input: { [key: string]: unknown },
90
+ schema: { [key: string]: unknown },
91
+ httpStatus?: string,
92
+ contentType?: string
93
+ ): string;
72
94
  serializeInput(input: { [key: string]: unknown }, httpStatus: string, contentType?: string): unknown;
73
95
  then(fulfilled: () => void, rejected: (err: Error) => void): void;
74
96
  trailer: (
75
97
  key: string,
76
- fn: ((reply: FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>, payload: string | Buffer | null) => Promise<string>) | ((reply: FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>, payload: string | Buffer | null, done: (err: Error | null, value?: string) => void) => void)
98
+ fn:
99
+ ((
100
+ reply: FastifyReply<
101
+ RouteGeneric,
102
+ RawServer,
103
+ RawRequest,
104
+ RawReply,
105
+ ContextConfig,
106
+ SchemaCompiler,
107
+ TypeProvider
108
+ >,
109
+ payload: string | Buffer | null
110
+ ) => Promise<string>)
111
+ | ((
112
+ reply: FastifyReply<
113
+ RouteGeneric,
114
+ RawServer,
115
+ RawRequest,
116
+ RawReply,
117
+ ContextConfig,
118
+ SchemaCompiler,
119
+ TypeProvider
120
+ >,
121
+ payload: string | Buffer | null,
122
+ done: (err: Error | null, value?: string) => void
123
+ ) => void)
77
124
  ) => FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
78
125
  hasTrailer(key: string): boolean;
79
- removeTrailer(key: string): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
126
+ removeTrailer(key: string): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler,
127
+ TypeProvider>;
80
128
  getDecorator<T>(name: string | symbol): T;
81
129
  }
package/types/route.d.ts CHANGED
@@ -33,7 +33,8 @@ export interface FastifyRouteConfig {
33
33
  export interface RouteGenericInterface extends RequestGenericInterface, ReplyGenericInterface { }
34
34
 
35
35
  export type RouteConstraintType = Omit<ConstraintStrategy<any>, 'deriveConstraint'> & {
36
- deriveConstraint<Context>(req: RawRequestDefaultExpression<RawServerDefault>, ctx?: Context, done?: (err: Error, ...args: any) => any): any,
36
+ deriveConstraint<Context>(req: RawRequestDefaultExpression<RawServerDefault>, ctx?: Context, done?: (err: Error,
37
+ ...args: any) => any): any,
37
38
  }
38
39
 
39
40
  export interface RouteConstraint {
@@ -72,33 +73,55 @@ export interface RouteShorthandOptions<
72
73
  errorHandler?: (
73
74
  this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
74
75
  error: FastifyError,
75
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, NoInfer<SchemaCompiler>, TypeProvider, ContextConfig, Logger>,
76
- reply: FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider>
76
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, NoInfer<SchemaCompiler>, TypeProvider, ContextConfig,
77
+ Logger>,
78
+ reply: FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, NoInfer<SchemaCompiler>,
79
+ TypeProvider>
77
80
  ) => void;
78
81
  childLoggerFactory?: FastifyChildLoggerFactory<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
79
82
  schemaErrorFormatter?: SchemaErrorFormatter;
80
83
 
81
84
  // hooks
82
- onRequest?: RouteShorthandHook<onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
83
- | RouteShorthandHook<onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
84
- preParsing?: RouteShorthandHook<preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
85
- | RouteShorthandHook<preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
86
- preValidation?: RouteShorthandHook<preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
87
- | RouteShorthandHook<preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
88
- preHandler?: RouteShorthandHook<preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
89
- | RouteShorthandHook<preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
90
- preSerialization?: RouteShorthandHook<preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
91
- | RouteShorthandHook<preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
92
- onSend?: RouteShorthandHook<onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
93
- | RouteShorthandHook<onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
94
- onResponse?: RouteShorthandHook<onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
95
- | RouteShorthandHook<onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
96
- onTimeout?: RouteShorthandHook<onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
97
- | RouteShorthandHook<onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
98
- onError?: RouteShorthandHook<onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
99
- | RouteShorthandHook<onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
100
- onRequestAbort?: RouteShorthandHook<onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
101
- | RouteShorthandHook<onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
85
+ onRequest?: RouteShorthandHook<onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
86
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>
87
+ | RouteShorthandHook<onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
88
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
89
+ preParsing?: RouteShorthandHook<preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
90
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>
91
+ | RouteShorthandHook<preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
92
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
93
+ preValidation?: RouteShorthandHook<preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric,
94
+ ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
95
+ | RouteShorthandHook<preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
96
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
97
+ preHandler?: RouteShorthandHook<preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
98
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>
99
+ | RouteShorthandHook<preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
100
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
101
+ preSerialization?: RouteShorthandHook<preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply,
102
+ RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
103
+ | RouteShorthandHook<preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric,
104
+ ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
105
+ onSend?: RouteShorthandHook<onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
106
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>
107
+ | RouteShorthandHook<onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
108
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
109
+ onResponse?: RouteShorthandHook<onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
110
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>
111
+ | RouteShorthandHook<onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
112
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
113
+ onTimeout?: RouteShorthandHook<onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
114
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>
115
+ | RouteShorthandHook<onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
116
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
117
+ onError?: RouteShorthandHook<onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
118
+ FastifyError, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
119
+ | RouteShorthandHook<onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError,
120
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
121
+ onRequestAbort?: RouteShorthandHook<onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric,
122
+ ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>>
123
+ | RouteShorthandHook<onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig,
124
+ NoInfer<SchemaCompiler>, TypeProvider, Logger>>[];
102
125
  }
103
126
  /**
104
127
  * Route handler method declaration.
@@ -131,8 +154,10 @@ export interface RouteShorthandOptionsWithHandler<
131
154
  SchemaCompiler extends FastifySchema = FastifySchema,
132
155
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
133
156
  Logger extends FastifyBaseLogger = FastifyBaseLogger
134
- > extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> {
135
- handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>;
157
+ > extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler,
158
+ TypeProvider, Logger> {
159
+ handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>,
160
+ TypeProvider, Logger>;
136
161
  }
137
162
 
138
163
  /**
@@ -145,18 +170,25 @@ export interface RouteShorthandMethod<
145
170
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
146
171
  Logger extends FastifyBaseLogger = FastifyBaseLogger
147
172
  > {
148
- <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema>(
173
+ <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault,
174
+ const SchemaCompiler extends FastifySchema = FastifySchema>(
149
175
  path: string,
150
- opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>,
151
- handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
176
+ opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler,
177
+ TypeProvider, Logger>,
178
+ handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler,
179
+ TypeProvider, Logger>
152
180
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
153
- <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema>(
181
+ <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault,
182
+ const SchemaCompiler extends FastifySchema = FastifySchema>(
154
183
  path: string,
155
- handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
184
+ handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler,
185
+ TypeProvider, Logger>
156
186
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
157
- <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema>(
187
+ <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault,
188
+ const SchemaCompiler extends FastifySchema = FastifySchema>(
158
189
  path: string,
159
- opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
190
+ opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler,
191
+ TypeProvider, Logger>
160
192
  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
161
193
  }
162
194
 
@@ -172,10 +204,12 @@ export interface RouteOptions<
172
204
  SchemaCompiler extends FastifySchema = FastifySchema,
173
205
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
174
206
  Logger extends FastifyBaseLogger = FastifyBaseLogger
175
- > extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> {
207
+ > extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler,
208
+ TypeProvider, Logger> {
176
209
  method: HTTPMethods | HTTPMethods[];
177
210
  url: string;
178
- handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>;
211
+ handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler,
212
+ TypeProvider, Logger>;
179
213
  }
180
214
 
181
215
  export type RouteHandler<
@@ -32,13 +32,29 @@ type UndefinedToUnknown<T> = [T] extends [undefined] ? unknown : T
32
32
  type KeysOf<T> = T extends any ? keyof T : never
33
33
 
34
34
  // Resolves Request types either from generic argument or Type Provider.
35
- type ResolveRequestParams<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema, RouteGeneric extends RouteGenericInterface> =
35
+ type ResolveRequestParams<
36
+ TypeProvider extends FastifyTypeProvider,
37
+ SchemaCompiler extends FastifySchema,
38
+ RouteGeneric extends RouteGenericInterface
39
+ > =
36
40
  UndefinedToUnknown<KeysOf<RouteGeneric['Params']> extends never ? CallValidatorTypeProvider<TypeProvider, SchemaCompiler['params']> : RouteGeneric['Params']>
37
- type ResolveRequestQuerystring<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema, RouteGeneric extends RouteGenericInterface> =
41
+ type ResolveRequestQuerystring<
42
+ TypeProvider extends FastifyTypeProvider,
43
+ SchemaCompiler extends FastifySchema,
44
+ RouteGeneric extends RouteGenericInterface
45
+ > =
38
46
  UndefinedToUnknown<KeysOf<RouteGeneric['Querystring']> extends never ? CallValidatorTypeProvider<TypeProvider, SchemaCompiler['querystring']> : RouteGeneric['Querystring']>
39
- type ResolveRequestHeaders<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema, RouteGeneric extends RouteGenericInterface> =
47
+ type ResolveRequestHeaders<
48
+ TypeProvider extends FastifyTypeProvider,
49
+ SchemaCompiler extends FastifySchema,
50
+ RouteGeneric extends RouteGenericInterface
51
+ > =
40
52
  UndefinedToUnknown<KeysOf<RouteGeneric['Headers']> extends never ? CallValidatorTypeProvider<TypeProvider, SchemaCompiler['headers']> : RouteGeneric['Headers']>
41
- type ResolveRequestBody<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema, RouteGeneric extends RouteGenericInterface> =
53
+ type ResolveRequestBody<
54
+ TypeProvider extends FastifyTypeProvider,
55
+ SchemaCompiler extends FastifySchema,
56
+ RouteGeneric extends RouteGenericInterface
57
+ > =
42
58
  UndefinedToUnknown<KeysOf<RouteGeneric['Body']> extends never ? CallValidatorTypeProvider<TypeProvider, SchemaCompiler['body']> : RouteGeneric['Body']>
43
59
 
44
60
  // The target request type. This type is inferenced on fastify 'requests' via generic argument assignment
@@ -50,7 +66,11 @@ export interface FastifyRequestType<Params = unknown, Querystring = unknown, Hea
50
66
  }
51
67
 
52
68
  // Resolves the FastifyRequest generic parameters
53
- export interface ResolveFastifyRequestType<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema, RouteGeneric extends RouteGenericInterface> extends FastifyRequestType {
69
+ export interface ResolveFastifyRequestType<
70
+ TypeProvider extends FastifyTypeProvider,
71
+ SchemaCompiler extends FastifySchema,
72
+ RouteGeneric extends RouteGenericInterface
73
+ > extends FastifyRequestType {
54
74
  params: ResolveRequestParams<TypeProvider, SchemaCompiler, RouteGeneric>,
55
75
  query: ResolveRequestQuerystring<TypeProvider, SchemaCompiler, RouteGeneric>,
56
76
  headers: RecordKeysToLowercase<ResolveRequestHeaders<TypeProvider, SchemaCompiler, RouteGeneric>>,
@@ -81,9 +101,10 @@ export type ResolveFastifyReplyType<TypeProvider extends FastifyTypeProvider, Sc
81
101
  // -----------------------------------------------------------------------------------------------
82
102
 
83
103
  // Resolves the Reply return type by taking a union of response status codes in the generic argument
84
- type ResolveReplyReturnTypeFromRouteGeneric<RouteGeneric extends RouteGenericInterface> = RouteGeneric extends { Reply: infer Return }
85
- ? keyof Return extends HttpKeys ? Return[keyof Return] | Return : Return
86
- : unknown
104
+ type ResolveReplyReturnTypeFromRouteGeneric<RouteGeneric extends RouteGenericInterface> =
105
+ RouteGeneric extends { Reply: infer Return }
106
+ ? keyof Return extends HttpKeys ? Return[keyof Return] | Return : Return
107
+ : unknown
87
108
 
88
109
  // The target reply return type. This type is inferenced on fastify 'routes' via generic argument assignment
89
110
  export type ResolveFastifyReplyReturnType<
package/types/utils.d.ts CHANGED
@@ -14,8 +14,8 @@ export type Autocomplete<T> = T | (AutocompletePrimitiveBaseType<T> & Record<nev
14
14
  * Standard HTTP method strings
15
15
  * for internal use
16
16
  */
17
- type _HTTPMethods = 'DELETE' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'OPTIONS' |
18
- 'PROPFIND' | 'PROPPATCH' | 'MKCOL' | 'COPY' | 'MOVE' | 'LOCK' | 'UNLOCK' | 'TRACE' | 'SEARCH' | 'REPORT' | 'MKCALENDAR'
17
+ type _HTTPMethods = 'DELETE' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'OPTIONS' | 'QUERY' |
18
+ 'PROPFIND' | 'PROPPATCH' | 'MKCOL' | 'COPY' | 'MOVE' | 'LOCK' | 'UNLOCK' | 'TRACE' | 'SEARCH' | 'REPORT' | 'MKCALENDAR'
19
19
 
20
20
  export type HTTPMethods = Autocomplete<_HTTPMethods | Lowercase<_HTTPMethods>>
21
21