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.
- package/PROJECT_CHARTER.md +1 -1
- package/README.md +7 -10
- package/SPONSORS.md +1 -0
- package/build/build-validation.js +2 -2
- package/docs/Guides/Delay-Accepting-Requests.md +1 -1
- package/docs/Guides/Ecosystem.md +12 -9
- package/docs/Guides/Getting-Started.md +10 -10
- package/docs/Guides/Migration-Guide-V4.md +2 -2
- package/docs/Guides/Migration-Guide-V5.md +1 -1
- package/docs/Guides/Plugins-Guide.md +1 -1
- package/docs/Guides/Prototype-Poisoning.md +3 -3
- package/docs/Guides/Serverless.md +6 -13
- package/docs/Guides/Style-Guide.md +1 -1
- package/docs/Reference/Errors.md +6 -0
- package/docs/Reference/Hooks.md +1 -1
- package/docs/Reference/Logging.md +3 -0
- package/docs/Reference/Reply.md +2 -2
- package/docs/Reference/Request.md +13 -13
- package/docs/Reference/Server.md +117 -17
- package/docs/Reference/Type-Providers.md +24 -4
- package/docs/Reference/TypeScript.md +8 -10
- package/docs/Reference/Warnings.md +5 -0
- package/eslint.config.js +1 -1
- package/fastify.d.ts +60 -13
- package/fastify.js +28 -23
- package/lib/content-type-parser.js +1 -11
- package/lib/content-type.js +70 -19
- package/lib/context.js +0 -3
- package/lib/error-handler.js +7 -26
- package/lib/errors.js +17 -0
- package/lib/four-oh-four.js +8 -10
- package/lib/handle-request.js +37 -8
- package/lib/hooks.js +5 -1
- package/lib/log-controller.js +169 -0
- package/lib/logger-factory.js +25 -4
- package/lib/reply.js +35 -44
- package/lib/req-id-gen-factory.js +4 -1
- package/lib/request.js +3 -3
- package/lib/route.js +28 -36
- package/lib/schemas.js +3 -3
- package/lib/symbols.js +1 -1
- package/lib/validation.js +10 -1
- package/lib/warnings.js +19 -1
- package/package.json +4 -4
- package/test/content-type.test.js +51 -4
- package/test/find-route.test.js +35 -0
- package/test/fix-6411.test.js +65 -0
- package/test/genReqId.test.js +24 -0
- package/test/hooks.test.js +71 -0
- package/test/internals/all.test.js +2 -1
- package/test/internals/errors.test.js +21 -1
- package/test/internals/logger.test.js +322 -0
- package/test/internals/reply.test.js +57 -4
- package/test/internals/request.test.js +10 -7
- package/test/logger/logging.test.js +40 -1
- package/test/reply-error.test.js +35 -0
- package/test/rfc-10008.test.js +147 -0
- package/test/route-shorthand.test.js +14 -4
- package/test/schema-serialization.test.js +33 -0
- package/test/stream.4.test.js +2 -2
- package/test/trust-proxy.test.js +49 -30
- package/test/types/errors.tst.ts +2 -0
- package/test/types/route.tst.ts +3 -3
- package/types/content-type-parser.d.ts +26 -6
- package/types/errors.d.ts +3 -0
- package/types/hooks.d.ts +137 -76
- package/types/instance.d.ts +152 -47
- package/types/logger.d.ts +57 -2
- package/types/plugin.d.ts +7 -3
- package/types/register.d.ts +53 -10
- package/types/reply.d.ts +62 -14
- package/types/route.d.ts +68 -34
- package/types/type-provider.d.ts +29 -8
- 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 &
|
|
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,
|
|
54
|
-
|
|
55
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
65
|
-
|
|
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(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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:
|
|
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,
|
|
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,
|
|
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,
|
|
76
|
-
|
|
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,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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,
|
|
135
|
-
|
|
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,
|
|
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,
|
|
151
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
211
|
+
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler,
|
|
212
|
+
TypeProvider, Logger>;
|
|
179
213
|
}
|
|
180
214
|
|
|
181
215
|
export type RouteHandler<
|
package/types/type-provider.d.ts
CHANGED
|
@@ -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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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> =
|
|
85
|
-
|
|
86
|
-
|
|
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
|
|