fastify 3.27.4 → 4.0.0-alpha.3
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/.taprc +3 -0
- package/README.md +7 -7
- package/build/build-error-serializer.js +27 -0
- package/build/build-validation.js +47 -35
- package/docs/Guides/Database.md +320 -0
- package/docs/Guides/Ecosystem.md +9 -0
- package/docs/Guides/Getting-Started.md +7 -7
- package/docs/Guides/Plugins-Guide.md +1 -1
- package/docs/Guides/Serverless.md +3 -3
- package/docs/Guides/Testing.md +2 -2
- package/docs/Migration-Guide-V4.md +12 -0
- package/docs/Reference/ContentTypeParser.md +4 -0
- package/docs/Reference/Decorators.md +2 -2
- package/docs/Reference/Encapsulation.md +2 -2
- package/docs/Reference/Errors.md +51 -6
- package/docs/Reference/HTTP2.md +3 -3
- package/docs/Reference/Hooks.md +4 -7
- package/docs/Reference/LTS.md +5 -4
- package/docs/Reference/Plugins.md +3 -3
- package/docs/Reference/Reply.md +73 -22
- package/docs/Reference/Request.md +1 -3
- package/docs/Reference/Routes.md +22 -15
- package/docs/Reference/Server.md +69 -119
- package/docs/Reference/TypeScript.md +20 -22
- package/docs/Reference/Validation-and-Serialization.md +30 -55
- package/docs/Type-Providers.md +257 -0
- package/examples/asyncawait.js +1 -1
- package/examples/benchmark/hooks-benchmark-async-await.js +1 -1
- package/examples/benchmark/hooks-benchmark.js +1 -1
- package/examples/benchmark/simple.js +1 -1
- package/examples/hooks.js +2 -2
- package/examples/http2.js +1 -1
- package/examples/https.js +1 -1
- package/examples/parser.js +13 -3
- package/examples/route-prefix.js +1 -1
- package/examples/shared-schema.js +1 -1
- package/examples/simple-stream.js +18 -0
- package/examples/simple.js +1 -1
- package/examples/simple.mjs +1 -1
- package/examples/typescript-server.ts +1 -1
- package/examples/use-plugin.js +1 -1
- package/fastify.d.ts +34 -22
- package/fastify.js +40 -36
- package/lib/configValidator.js +902 -1023
- package/lib/contentTypeParser.js +6 -16
- package/lib/context.js +36 -10
- package/lib/decorate.js +3 -1
- package/lib/error-handler.js +158 -0
- package/lib/error-serializer.js +257 -0
- package/lib/errors.js +51 -9
- package/lib/fourOhFour.js +31 -20
- package/lib/handleRequest.js +10 -13
- package/lib/hooks.js +14 -9
- package/lib/pluginOverride.js +0 -3
- package/lib/pluginUtils.js +3 -2
- package/lib/reply.js +121 -175
- package/lib/request.js +13 -10
- package/lib/route.js +131 -138
- package/lib/schema-controller.js +2 -2
- package/lib/schemas.js +27 -1
- package/lib/server.js +242 -116
- package/lib/symbols.js +5 -3
- package/lib/validation.js +11 -9
- package/lib/warnings.js +4 -12
- package/lib/wrapThenable.js +4 -11
- package/package.json +37 -39
- package/test/404s.test.js +258 -125
- package/test/500s.test.js +3 -3
- package/test/als.test.js +1 -1
- package/test/async-await.test.js +20 -76
- package/test/bodyLimit.test.js +1 -1
- package/test/build-certificate.js +6 -7
- package/test/case-insensitive.test.js +4 -4
- package/test/close-pipelining.test.js +2 -2
- package/test/close.test.js +11 -11
- package/test/content-parser.test.js +32 -0
- package/test/context-config.test.js +52 -0
- package/test/custom-http-server.test.js +14 -7
- package/test/custom-parser-async.test.js +1 -66
- package/test/custom-parser.test.js +92 -159
- package/test/custom-querystring-parser.test.js +3 -3
- package/test/decorator.test.js +11 -13
- package/test/delete.test.js +6 -6
- package/test/encapsulated-error-handler.test.js +50 -0
- package/test/esm/index.test.js +0 -14
- package/test/fastify-instance.test.js +4 -4
- package/test/fluent-schema.test.js +4 -4
- package/test/genReqId.test.js +1 -1
- package/test/get.test.js +4 -4
- package/test/handler-context.test.js +2 -2
- package/test/head.test.js +1 -1
- package/test/helper.js +19 -4
- package/test/hooks-async.test.js +15 -48
- package/test/hooks.on-ready.test.js +10 -5
- package/test/hooks.test.js +78 -119
- package/test/http2/closing.test.js +10 -16
- package/test/http2/constraint.test.js +1 -1
- package/test/http2/head.test.js +1 -1
- package/test/http2/plain.test.js +1 -1
- package/test/http2/secure-with-fallback.test.js +1 -1
- package/test/http2/secure.test.js +1 -1
- package/test/http2/unknown-http-method.test.js +4 -10
- package/test/https/custom-https-server.test.js +12 -6
- package/test/https/https.test.js +1 -1
- package/test/input-validation.js +3 -3
- package/test/internals/handleRequest.test.js +6 -43
- package/test/internals/initialConfig.test.js +41 -12
- package/test/internals/logger.test.js +2 -2
- package/test/internals/reply.test.js +317 -48
- package/test/internals/request.test.js +13 -7
- package/test/internals/server.test.js +88 -0
- package/test/listen.deprecated.test.js +202 -0
- package/test/listen.test.js +140 -145
- package/test/logger.test.js +82 -42
- package/test/maxRequestsPerSocket.test.js +8 -6
- package/test/middleware.test.js +2 -25
- package/test/nullable-validation.test.js +53 -16
- package/test/output-validation.test.js +1 -1
- package/test/plugin.test.js +47 -21
- package/test/pretty-print.test.js +22 -10
- package/test/promises.test.js +1 -1
- package/test/proto-poisoning.test.js +6 -6
- package/test/register.test.js +3 -3
- package/test/reply-error.test.js +126 -15
- package/test/reply-trailers.test.js +270 -0
- package/test/request-error.test.js +3 -6
- package/test/route-hooks.test.js +18 -18
- package/test/route-prefix.test.js +2 -1
- package/test/route.test.js +206 -22
- package/test/router-options.test.js +2 -2
- package/test/schema-examples.test.js +11 -5
- package/test/schema-feature.test.js +25 -20
- package/test/schema-serialization.test.js +9 -9
- package/test/schema-special-usage.test.js +5 -153
- package/test/schema-validation.test.js +9 -9
- package/test/skip-reply-send.test.js +2 -2
- package/test/stream.test.js +82 -23
- package/test/throw.test.js +8 -5
- package/test/trust-proxy.test.js +6 -6
- package/test/type-provider.test.js +20 -0
- package/test/types/fastify.test-d.ts +10 -18
- package/test/types/hooks.test-d.ts +61 -5
- package/test/types/import.js +2 -0
- package/test/types/import.ts +1 -0
- package/test/types/instance.test-d.ts +68 -17
- package/test/types/logger.test-d.ts +44 -15
- package/test/types/reply.test-d.ts +2 -1
- package/test/types/request.test-d.ts +71 -1
- package/test/types/route.test-d.ts +8 -2
- package/test/types/schema.test-d.ts +2 -39
- package/test/types/type-provider.test-d.ts +424 -0
- package/test/url-rewriting.test.js +3 -3
- package/test/validation-error-handling.test.js +8 -8
- package/test/versioned-routes.test.js +30 -18
- package/test/wrapThenable.test.js +7 -6
- package/types/content-type-parser.d.ts +17 -8
- package/types/hooks.d.ts +182 -85
- package/types/instance.d.ts +286 -118
- package/types/logger.d.ts +18 -104
- package/types/plugin.d.ts +10 -4
- package/types/reply.d.ts +18 -12
- package/types/request.d.ts +13 -8
- package/types/route.d.ts +62 -34
- package/types/schema.d.ts +1 -1
- package/types/type-provider.d.ts +99 -0
- package/types/utils.d.ts +1 -1
- package/lib/schema-compilers.js +0 -12
- package/test/emit-warning.test.js +0 -166
package/types/instance.d.ts
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { FastifyError } from 'fastify-error'
|
|
2
|
+
import { CallbackFunc as LightMyRequestCallback, Chain as LightMyRequestChain, InjectOptions, Response as LightMyRequestResponse } from 'light-my-request'
|
|
3
|
+
import { AddContentTypeParser, ConstructorAction, FastifyBodyParser, getDefaultJsonParser, hasContentTypeParser, ProtoAction, removeAllContentTypeParsers, removeContentTypeParser } from './content-type-parser'
|
|
4
|
+
import { onCloseAsyncHookHandler, onCloseHookHandler, onErrorAsyncHookHandler, onErrorHookHandler, onReadyAsyncHookHandler, onReadyHookHandler, onRegisterHookHandler, onRequestAsyncHookHandler, onRequestHookHandler, onResponseAsyncHookHandler, onResponseHookHandler, onRouteHookHandler, onSendAsyncHookHandler, onSendHookHandler, onTimeoutAsyncHookHandler, onTimeoutHookHandler, preHandlerAsyncHookHandler, preHandlerHookHandler, preParsingAsyncHookHandler, preParsingHookHandler, preSerializationAsyncHookHandler, preSerializationHookHandler, preValidationAsyncHookHandler, preValidationHookHandler } from './hooks'
|
|
5
|
+
import { FastifyLoggerInstance } from './logger'
|
|
6
|
+
import { FastifyRegister } from './register'
|
|
7
|
+
import { FastifyReply } from './reply'
|
|
8
|
+
import { FastifyRequest } from './request'
|
|
9
|
+
import { DefaultRoute, RouteGenericInterface, RouteOptions, RouteShorthandMethod } from './route'
|
|
3
10
|
import {
|
|
4
11
|
FastifySchema,
|
|
5
12
|
FastifySchemaCompiler,
|
|
13
|
+
FastifySchemaControllerOptions,
|
|
6
14
|
FastifySchemaValidationError,
|
|
7
|
-
FastifySerializerCompiler
|
|
8
|
-
FastifySchemaControllerOptions
|
|
15
|
+
FastifySerializerCompiler
|
|
9
16
|
} from './schema'
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
import { AddContentTypeParser, hasContentTypeParser, getDefaultJsonParser, ProtoAction, ConstructorAction, FastifyBodyParser, removeContentTypeParser, removeAllContentTypeParsers } from './content-type-parser'
|
|
17
|
+
import {
|
|
18
|
+
FastifyRequestType,
|
|
19
|
+
FastifyTypeProvider,
|
|
20
|
+
FastifyTypeProviderDefault,
|
|
21
|
+
ResolveFastifyRequestType
|
|
22
|
+
} from './type-provider'
|
|
23
|
+
import { ContextConfigDefault, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault } from './utils'
|
|
18
24
|
|
|
19
25
|
export interface PrintRoutesOptions {
|
|
20
26
|
includeMeta?: boolean | (string | symbol)[]
|
|
@@ -22,6 +28,8 @@ export interface PrintRoutesOptions {
|
|
|
22
28
|
includeHooks?: boolean
|
|
23
29
|
}
|
|
24
30
|
|
|
31
|
+
type NotInInterface<Key, _Interface> = Key extends keyof _Interface ? never : Key
|
|
32
|
+
|
|
25
33
|
/**
|
|
26
34
|
* Fastify server instance. Returned by the core `fastify()` method.
|
|
27
35
|
*/
|
|
@@ -29,19 +37,22 @@ export interface FastifyInstance<
|
|
|
29
37
|
RawServer extends RawServerBase = RawServerDefault,
|
|
30
38
|
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
31
39
|
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
32
|
-
Logger = FastifyLoggerInstance
|
|
40
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance,
|
|
41
|
+
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
33
42
|
> {
|
|
34
43
|
server: RawServer;
|
|
35
44
|
prefix: string;
|
|
36
45
|
version: string;
|
|
37
46
|
log: Logger;
|
|
38
47
|
|
|
39
|
-
|
|
48
|
+
withTypeProvider<Provider extends FastifyTypeProvider>(): FastifyInstance<RawServer, RawRequest, RawReply, Logger, Provider>;
|
|
49
|
+
|
|
50
|
+
addSchema(schema: unknown): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
40
51
|
getSchema(schemaId: string): unknown;
|
|
41
52
|
getSchemas(): Record<string, unknown>;
|
|
42
53
|
|
|
43
|
-
after(): FastifyInstance<RawServer, RawRequest, RawReply, Logger> & PromiseLike<undefined>;
|
|
44
|
-
after(afterListener: (err: Error) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
54
|
+
after(): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>;
|
|
55
|
+
after(afterListener: (err: Error) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
45
56
|
|
|
46
57
|
close(): Promise<undefined>;
|
|
47
58
|
close(closeListener: () => void): undefined;
|
|
@@ -49,24 +60,24 @@ export interface FastifyInstance<
|
|
|
49
60
|
// should be able to define something useful with the decorator getter/setter pattern using Generics to enforce the users function returns what they expect it to
|
|
50
61
|
decorate<T>(property: string | symbol,
|
|
51
62
|
value: T extends (...args: any[]) => any
|
|
52
|
-
? (this: FastifyInstance<RawServer, RawRequest, RawReply, Logger>, ...args: Parameters<T>) => ReturnType<T>
|
|
63
|
+
? (this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, ...args: Parameters<T>) => ReturnType<T>
|
|
53
64
|
: T,
|
|
54
65
|
dependencies?: string[]
|
|
55
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
66
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
56
67
|
|
|
57
68
|
decorateRequest<T>(property: string | symbol,
|
|
58
69
|
value: T extends (...args: any[]) => any
|
|
59
70
|
? (this: FastifyRequest, ...args: Parameters<T>) => ReturnType<T>
|
|
60
71
|
: T,
|
|
61
72
|
dependencies?: string[]
|
|
62
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
73
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
63
74
|
|
|
64
75
|
decorateReply<T>(property: string | symbol,
|
|
65
76
|
value: T extends (...args: any[]) => any
|
|
66
77
|
? (this: FastifyReply, ...args: Parameters<T>) => ReturnType<T>
|
|
67
78
|
: T,
|
|
68
79
|
dependencies?: string[]
|
|
69
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
80
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
70
81
|
|
|
71
82
|
hasDecorator(decorator: string | symbol): boolean;
|
|
72
83
|
hasRequestDecorator(decorator: string | symbol): boolean;
|
|
@@ -76,17 +87,123 @@ export interface FastifyInstance<
|
|
|
76
87
|
inject(opts: InjectOptions | string): Promise<LightMyRequestResponse>;
|
|
77
88
|
inject(): LightMyRequestChain;
|
|
78
89
|
|
|
90
|
+
listen(opts: {
|
|
91
|
+
/**
|
|
92
|
+
* Default to `0` (picks the first available open port).
|
|
93
|
+
*/
|
|
94
|
+
port?: number;
|
|
95
|
+
/**
|
|
96
|
+
* Default to `localhost`.
|
|
97
|
+
*/
|
|
98
|
+
host?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Will be ignored if `port` is specified.
|
|
101
|
+
* @see [Identifying paths for IPC connections](https://nodejs.org/api/net.html#identifying-paths-for-ipc-connections).
|
|
102
|
+
*/
|
|
103
|
+
path?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Specify the maximum length of the queue of pending connections.
|
|
106
|
+
* The actual length will be determined by the OS through sysctl settings such as `tcp_max_syn_backlog` and `somaxconn` on Linux.
|
|
107
|
+
* Default to `511`.
|
|
108
|
+
*/
|
|
109
|
+
backlog?: number;
|
|
110
|
+
/**
|
|
111
|
+
* Default to `false`.
|
|
112
|
+
*/
|
|
113
|
+
exclusive?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* For IPC servers makes the pipe readable for all users.
|
|
116
|
+
* Default to `false`.
|
|
117
|
+
*/
|
|
118
|
+
readableAll?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* For IPC servers makes the pipe writable for all users.
|
|
121
|
+
* Default to `false`.
|
|
122
|
+
*/
|
|
123
|
+
writableAll?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* For TCP servers, setting `ipv6Only` to `true` will disable dual-stack support, i.e., binding to host `::` won't make `0.0.0.0` be bound.
|
|
126
|
+
* Default to `false`.
|
|
127
|
+
*/
|
|
128
|
+
ipv6Only?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* An AbortSignal that may be used to close a listening server.
|
|
131
|
+
* @since This option is available only in Node.js v15.6.0 and greater
|
|
132
|
+
*/
|
|
133
|
+
signal?: AbortSignal;
|
|
134
|
+
}, callback: (err: Error|null, address: string) => void): void;
|
|
135
|
+
listen(opts?: {
|
|
136
|
+
/**
|
|
137
|
+
* Default to `0` (picks the first available open port).
|
|
138
|
+
*/
|
|
139
|
+
port?: number;
|
|
140
|
+
/**
|
|
141
|
+
* Default to `localhost`.
|
|
142
|
+
*/
|
|
143
|
+
host?: string;
|
|
144
|
+
/**
|
|
145
|
+
* Will be ignored if `port` is specified.
|
|
146
|
+
* @see [Identifying paths for IPC connections](https://nodejs.org/api/net.html#identifying-paths-for-ipc-connections).
|
|
147
|
+
*/
|
|
148
|
+
path?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Specify the maximum length of the queue of pending connections.
|
|
151
|
+
* The actual length will be determined by the OS through sysctl settings such as `tcp_max_syn_backlog` and `somaxconn` on Linux.
|
|
152
|
+
* Default to `511`.
|
|
153
|
+
*/
|
|
154
|
+
backlog?: number;
|
|
155
|
+
/**
|
|
156
|
+
* Default to `false`.
|
|
157
|
+
*/
|
|
158
|
+
exclusive?: boolean;
|
|
159
|
+
/**
|
|
160
|
+
* For IPC servers makes the pipe readable for all users.
|
|
161
|
+
* Default to `false`.
|
|
162
|
+
*/
|
|
163
|
+
readableAll?: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* For IPC servers makes the pipe writable for all users.
|
|
166
|
+
* Default to `false`.
|
|
167
|
+
*/
|
|
168
|
+
writableAll?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* For TCP servers, setting `ipv6Only` to `true` will disable dual-stack support, i.e., binding to host `::` won't make `0.0.0.0` be bound.
|
|
171
|
+
* Default to `false`.
|
|
172
|
+
*/
|
|
173
|
+
ipv6Only?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* An AbortSignal that may be used to close a listening server.
|
|
176
|
+
* @since This option is available only in Node.js v15.6.0 and greater
|
|
177
|
+
*/
|
|
178
|
+
signal?: AbortSignal;
|
|
179
|
+
}): Promise<string>;
|
|
180
|
+
listen(callback: (err: Error | null, address: string) => void): void;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @deprecated Variadic listen method is deprecated. Please use `.listen(optionsObject, callback)` instead. The variadic signature will be removed in `fastify@5`
|
|
184
|
+
* @see https://github.com/fastify/fastify/pull/3712
|
|
185
|
+
*/
|
|
79
186
|
listen(port: number | string, address: string, backlog: number, callback: (err: Error|null, address: string) => void): void;
|
|
187
|
+
/**
|
|
188
|
+
* @deprecated Variadic listen method is deprecated. Please use `.listen(optionsObject, callback)` instead. The variadic signature will be removed in `fastify@5`
|
|
189
|
+
* @see https://github.com/fastify/fastify/pull/3712
|
|
190
|
+
*/
|
|
80
191
|
listen(port: number | string, address: string, callback: (err: Error|null, address: string) => void): void;
|
|
192
|
+
/**
|
|
193
|
+
* @deprecated Variadic listen method is deprecated. Please use `.listen(optionsObject, callback)` instead. The variadic signature will be removed in `fastify@5`
|
|
194
|
+
* @see https://github.com/fastify/fastify/pull/3712
|
|
195
|
+
*/
|
|
81
196
|
listen(port: number | string, callback: (err: Error|null, address: string) => void): void;
|
|
197
|
+
/**
|
|
198
|
+
* @deprecated Variadic listen method is deprecated. Please use `.listen(optionsObject)` instead. The variadic signature will be removed in `fastify@5`
|
|
199
|
+
* @see https://github.com/fastify/fastify/pull/3712
|
|
200
|
+
*/
|
|
82
201
|
listen(port: number | string, address?: string, backlog?: number): Promise<string>;
|
|
83
|
-
listen(opts: { port: number; host?: string; backlog?: number }, callback: (err: Error|null, address: string) => void): void;
|
|
84
|
-
listen(opts: { port: number; host?: string; backlog?: number }): Promise<string>;
|
|
85
202
|
|
|
86
|
-
ready(): FastifyInstance<RawServer, RawRequest, RawReply> & PromiseLike<undefined>;
|
|
87
|
-
ready(readyListener: (err: Error) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
203
|
+
ready(): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>;
|
|
204
|
+
ready(readyListener: (err: Error) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
88
205
|
|
|
89
|
-
register: FastifyRegister<FastifyInstance<RawServer, RawRequest, RawReply, Logger> & PromiseLike<undefined>>;
|
|
206
|
+
register: FastifyRegister<FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>>;
|
|
90
207
|
|
|
91
208
|
routing(req: RawRequest, res: RawReply): void;
|
|
92
209
|
getDefaultRoute: DefaultRoute<RawRequest, RawReply>;
|
|
@@ -96,16 +213,16 @@ export interface FastifyInstance<
|
|
|
96
213
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
97
214
|
ContextConfig = ContextConfigDefault,
|
|
98
215
|
SchemaCompiler = FastifySchema,
|
|
99
|
-
>(opts: RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler>): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
216
|
+
>(opts: RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
100
217
|
|
|
101
|
-
get: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
|
102
|
-
head: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
|
103
|
-
post: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
|
104
|
-
put: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
|
105
|
-
delete: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
|
106
|
-
options: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
|
107
|
-
patch: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
|
108
|
-
all: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
|
218
|
+
get: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
|
|
219
|
+
head: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
|
|
220
|
+
post: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
|
|
221
|
+
put: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
|
|
222
|
+
delete: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
|
|
223
|
+
options: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
|
|
224
|
+
patch: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
|
|
225
|
+
all: RouteShorthandMethod<RawServer, RawRequest, RawReply, TypeProvider>;
|
|
109
226
|
|
|
110
227
|
// addHook: overloads
|
|
111
228
|
|
|
@@ -117,19 +234,25 @@ export interface FastifyInstance<
|
|
|
117
234
|
*/
|
|
118
235
|
addHook<
|
|
119
236
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
120
|
-
ContextConfig = ContextConfigDefault
|
|
237
|
+
ContextConfig = ContextConfigDefault,
|
|
238
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
239
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
240
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
121
241
|
>(
|
|
122
242
|
name: 'onRequest',
|
|
123
|
-
hook: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
124
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
243
|
+
hook: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
244
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
125
245
|
|
|
126
246
|
addHook<
|
|
127
247
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
128
|
-
ContextConfig = ContextConfigDefault
|
|
248
|
+
ContextConfig = ContextConfigDefault,
|
|
249
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
250
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
251
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
129
252
|
>(
|
|
130
253
|
name: 'onRequest',
|
|
131
|
-
hook: onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
132
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
254
|
+
hook: onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
255
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
133
256
|
|
|
134
257
|
/**
|
|
135
258
|
* `preParsing` is the second hook to be executed in the request lifecycle. The previous hook was `onRequest`, the next hook will be `preValidation`.
|
|
@@ -137,57 +260,75 @@ export interface FastifyInstance<
|
|
|
137
260
|
*/
|
|
138
261
|
addHook<
|
|
139
262
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
140
|
-
ContextConfig = ContextConfigDefault
|
|
263
|
+
ContextConfig = ContextConfigDefault,
|
|
264
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
265
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
266
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
141
267
|
>(
|
|
142
268
|
name: 'preParsing',
|
|
143
|
-
hook: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
144
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
269
|
+
hook: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
270
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
145
271
|
|
|
146
272
|
addHook<
|
|
147
273
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
148
|
-
ContextConfig = ContextConfigDefault
|
|
274
|
+
ContextConfig = ContextConfigDefault,
|
|
275
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
276
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
277
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
149
278
|
>(
|
|
150
279
|
name: 'preParsing',
|
|
151
|
-
hook: preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
152
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
280
|
+
hook: preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
281
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
153
282
|
|
|
154
283
|
/**
|
|
155
284
|
* `preValidation` is the third hook to be executed in the request lifecycle. The previous hook was `preParsing`, the next hook will be `preHandler`.
|
|
156
285
|
*/
|
|
157
286
|
addHook<
|
|
158
287
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
159
|
-
ContextConfig = ContextConfigDefault
|
|
288
|
+
ContextConfig = ContextConfigDefault,
|
|
289
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
290
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
291
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
160
292
|
>(
|
|
161
293
|
name: 'preValidation',
|
|
162
|
-
hook: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
163
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
294
|
+
hook: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
295
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
164
296
|
|
|
165
297
|
addHook<
|
|
166
298
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
167
|
-
ContextConfig = ContextConfigDefault
|
|
299
|
+
ContextConfig = ContextConfigDefault,
|
|
300
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
301
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
302
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
168
303
|
>(
|
|
169
304
|
name: 'preValidation',
|
|
170
|
-
hook: preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
171
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
305
|
+
hook: preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
306
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
172
307
|
|
|
173
308
|
/**
|
|
174
309
|
* `preHandler` is the fourth hook to be executed in the request lifecycle. The previous hook was `preValidation`, the next hook will be `preSerialization`.
|
|
175
310
|
*/
|
|
176
311
|
addHook<
|
|
177
312
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
178
|
-
ContextConfig = ContextConfigDefault
|
|
313
|
+
ContextConfig = ContextConfigDefault,
|
|
314
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
315
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
316
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
179
317
|
>(
|
|
180
318
|
name: 'preHandler',
|
|
181
|
-
hook: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
182
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
319
|
+
hook: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
320
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
183
321
|
|
|
184
322
|
addHook<
|
|
185
323
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
186
|
-
ContextConfig = ContextConfigDefault
|
|
324
|
+
ContextConfig = ContextConfigDefault,
|
|
325
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
326
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
327
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
187
328
|
>(
|
|
188
329
|
name: 'preHandler',
|
|
189
|
-
hook: preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
190
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
330
|
+
hook: preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
331
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
191
332
|
|
|
192
333
|
/**
|
|
193
334
|
* `preSerialization` is the fifth hook to be executed in the request lifecycle. The previous hook was `preHandler`, the next hook will be `onSend`.
|
|
@@ -196,20 +337,26 @@ export interface FastifyInstance<
|
|
|
196
337
|
addHook<
|
|
197
338
|
PreSerializationPayload = unknown,
|
|
198
339
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
199
|
-
ContextConfig = ContextConfigDefault
|
|
340
|
+
ContextConfig = ContextConfigDefault,
|
|
341
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
342
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
343
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
200
344
|
>(
|
|
201
345
|
name: 'preSerialization',
|
|
202
|
-
hook: preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
203
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
346
|
+
hook: preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
347
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
204
348
|
|
|
205
349
|
addHook<
|
|
206
350
|
PreSerializationPayload = unknown,
|
|
207
351
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
208
|
-
ContextConfig = ContextConfigDefault
|
|
352
|
+
ContextConfig = ContextConfigDefault,
|
|
353
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
354
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
355
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
209
356
|
>(
|
|
210
357
|
name: 'preSerialization',
|
|
211
|
-
hook: preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
212
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
358
|
+
hook: preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
359
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
213
360
|
|
|
214
361
|
/**
|
|
215
362
|
* You can change the payload with the `onSend` hook. It is the sixth hook to be executed in the request lifecycle. The previous hook was `preSerialization`, the next hook will be `onResponse`.
|
|
@@ -218,20 +365,26 @@ export interface FastifyInstance<
|
|
|
218
365
|
addHook<
|
|
219
366
|
OnSendPayload = unknown,
|
|
220
367
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
221
|
-
ContextConfig = ContextConfigDefault
|
|
368
|
+
ContextConfig = ContextConfigDefault,
|
|
369
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
370
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
371
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
222
372
|
>(
|
|
223
373
|
name: 'onSend',
|
|
224
|
-
hook: onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
225
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
374
|
+
hook: onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
375
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
226
376
|
|
|
227
377
|
addHook<
|
|
228
378
|
OnSendPayload = unknown,
|
|
229
379
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
230
|
-
ContextConfig = ContextConfigDefault
|
|
380
|
+
ContextConfig = ContextConfigDefault,
|
|
381
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
382
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
383
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
231
384
|
>(
|
|
232
385
|
name: 'onSend',
|
|
233
|
-
hook: onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
234
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
386
|
+
hook: onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
387
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
235
388
|
|
|
236
389
|
/**
|
|
237
390
|
* `onResponse` is the seventh and last hook in the request hook lifecycle. The previous hook was `onSend`, there is no next hook.
|
|
@@ -239,19 +392,25 @@ export interface FastifyInstance<
|
|
|
239
392
|
*/
|
|
240
393
|
addHook<
|
|
241
394
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
242
|
-
ContextConfig = ContextConfigDefault
|
|
395
|
+
ContextConfig = ContextConfigDefault,
|
|
396
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
397
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
398
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
243
399
|
>(
|
|
244
400
|
name: 'onResponse',
|
|
245
|
-
hook: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
246
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
401
|
+
hook: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
402
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
247
403
|
|
|
248
404
|
addHook<
|
|
249
405
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
250
|
-
ContextConfig = ContextConfigDefault
|
|
406
|
+
ContextConfig = ContextConfigDefault,
|
|
407
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
408
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
409
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
251
410
|
>(
|
|
252
411
|
name: 'onResponse',
|
|
253
|
-
hook: onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
254
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
412
|
+
hook: onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
413
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
255
414
|
|
|
256
415
|
/**
|
|
257
416
|
* `onTimeout` is useful if you need to monitor the request timed out in your service. (if the `connectionTimeout` property is set on the fastify instance)
|
|
@@ -259,19 +418,25 @@ export interface FastifyInstance<
|
|
|
259
418
|
*/
|
|
260
419
|
addHook<
|
|
261
420
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
262
|
-
ContextConfig = ContextConfigDefault
|
|
421
|
+
ContextConfig = ContextConfigDefault,
|
|
422
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
423
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
424
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
263
425
|
>(
|
|
264
426
|
name: 'onTimeout',
|
|
265
|
-
hook: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
266
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
427
|
+
hook: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
428
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
267
429
|
|
|
268
430
|
addHook<
|
|
269
431
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
270
|
-
ContextConfig = ContextConfigDefault
|
|
432
|
+
ContextConfig = ContextConfigDefault,
|
|
433
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
434
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
435
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
271
436
|
>(
|
|
272
437
|
name: 'onTimeout',
|
|
273
|
-
hook: onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
274
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
438
|
+
hook: onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
439
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
275
440
|
|
|
276
441
|
/**
|
|
277
442
|
* This hook is useful if you need to do some custom error logging or add some specific header in case of error.
|
|
@@ -281,19 +446,25 @@ export interface FastifyInstance<
|
|
|
281
446
|
*/
|
|
282
447
|
addHook<
|
|
283
448
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
284
|
-
ContextConfig = ContextConfigDefault
|
|
449
|
+
ContextConfig = ContextConfigDefault,
|
|
450
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
451
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
452
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
285
453
|
>(
|
|
286
454
|
name: 'onError',
|
|
287
|
-
hook: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
288
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
455
|
+
hook: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
456
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
289
457
|
|
|
290
458
|
addHook<
|
|
291
459
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
292
|
-
ContextConfig = ContextConfigDefault
|
|
460
|
+
ContextConfig = ContextConfigDefault,
|
|
461
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
462
|
+
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
463
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
293
464
|
>(
|
|
294
465
|
name: 'onError',
|
|
295
|
-
hook: onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
296
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
466
|
+
hook: onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, RequestType, Logger>
|
|
467
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
297
468
|
|
|
298
469
|
// Application addHooks
|
|
299
470
|
|
|
@@ -302,11 +473,13 @@ export interface FastifyInstance<
|
|
|
302
473
|
*/
|
|
303
474
|
addHook<
|
|
304
475
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
305
|
-
ContextConfig = ContextConfigDefault
|
|
476
|
+
ContextConfig = ContextConfigDefault,
|
|
477
|
+
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
478
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
306
479
|
>(
|
|
307
480
|
name: 'onRoute',
|
|
308
|
-
hook: onRouteHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
309
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
481
|
+
hook: onRouteHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
482
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
310
483
|
|
|
311
484
|
/**
|
|
312
485
|
* Triggered when a new plugin is registered and a new encapsulation context is created. The hook will be executed before the registered code.
|
|
@@ -315,8 +488,8 @@ export interface FastifyInstance<
|
|
|
315
488
|
*/
|
|
316
489
|
addHook(
|
|
317
490
|
name: 'onRegister',
|
|
318
|
-
hook: onRegisterHookHandler<RawServer, RawRequest, RawReply, Logger>
|
|
319
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
491
|
+
hook: onRegisterHookHandler<RawServer, RawRequest, RawReply, Logger, TypeProvider>
|
|
492
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
320
493
|
|
|
321
494
|
/**
|
|
322
495
|
* Triggered when fastify.listen() or fastify.ready() is invoked to start the server. It is useful when plugins need a "ready" event, for example to load data before the server start listening for requests.
|
|
@@ -324,20 +497,20 @@ export interface FastifyInstance<
|
|
|
324
497
|
addHook(
|
|
325
498
|
name: 'onReady',
|
|
326
499
|
hook: onReadyHookHandler
|
|
327
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
500
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
328
501
|
|
|
329
502
|
addHook(
|
|
330
503
|
name: 'onReady',
|
|
331
504
|
hook: onReadyAsyncHookHandler,
|
|
332
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
505
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
333
506
|
|
|
334
507
|
/**
|
|
335
508
|
* Triggered when fastify.close() is invoked to stop the server. It is useful when plugins need a "shutdown" event, for example to close an open connection to a database.
|
|
336
509
|
*/
|
|
337
510
|
addHook(
|
|
338
511
|
name: 'onClose',
|
|
339
|
-
hook: onCloseHookHandler<RawServer, RawRequest, RawReply, Logger>
|
|
340
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
512
|
+
hook: onCloseHookHandler<RawServer, RawRequest, RawReply, Logger, TypeProvider>
|
|
513
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
341
514
|
|
|
342
515
|
addHook(
|
|
343
516
|
name: 'onClose',
|
|
@@ -347,17 +520,17 @@ export interface FastifyInstance<
|
|
|
347
520
|
/**
|
|
348
521
|
* Set the 404 handler
|
|
349
522
|
*/
|
|
350
|
-
setNotFoundHandler<RouteGeneric extends RouteGenericInterface = RouteGenericInterface> (
|
|
351
|
-
handler: (request: FastifyRequest<RouteGeneric, RawServer, RawRequest>, reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric>) => void
|
|
352
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
523
|
+
setNotFoundHandler<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, SchemaCompiler extends FastifySchema = FastifySchema> (
|
|
524
|
+
handler: (request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>, reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfigDefault, SchemaCompiler, TypeProvider>) => void
|
|
525
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
353
526
|
|
|
354
|
-
setNotFoundHandler<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig extends ContextConfigDefault = ContextConfigDefault> (
|
|
527
|
+
setNotFoundHandler<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig extends ContextConfigDefault = ContextConfigDefault, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, SchemaCompiler extends FastifySchema = FastifySchema> (
|
|
355
528
|
opts: {
|
|
356
|
-
preValidation?: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> | preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>[];
|
|
357
|
-
preHandler?: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> | preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>[];
|
|
529
|
+
preValidation?: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider> | preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>[];
|
|
530
|
+
preHandler?: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider> | preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>[];
|
|
358
531
|
},
|
|
359
|
-
handler: (request: FastifyRequest<RouteGeneric, RawServer, RawRequest>, reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric>) => void
|
|
360
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>
|
|
532
|
+
handler: (request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>, reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfigDefault, SchemaCompiler, TypeProvider>) => void
|
|
533
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>
|
|
361
534
|
|
|
362
535
|
/**
|
|
363
536
|
* Fastify default error handler
|
|
@@ -367,24 +540,19 @@ export interface FastifyInstance<
|
|
|
367
540
|
/**
|
|
368
541
|
* Set a function that will be called whenever an error happens
|
|
369
542
|
*/
|
|
370
|
-
setErrorHandler<TError extends Error = FastifyError, RouteGeneric extends RouteGenericInterface = RouteGenericInterface>(
|
|
371
|
-
handler: (
|
|
372
|
-
|
|
373
|
-
error: TError,
|
|
374
|
-
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
375
|
-
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric>
|
|
376
|
-
) => void | Promise<RouteGeneric['Reply'] | void>
|
|
377
|
-
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
543
|
+
setErrorHandler<TError extends Error = FastifyError, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, SchemaCompiler extends FastifySchema = FastifySchema, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault>(
|
|
544
|
+
handler: (this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>, error: TError, request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>, reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfigDefault, SchemaCompiler, TypeProvider>) => any | Promise<any>
|
|
545
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
378
546
|
|
|
379
547
|
/**
|
|
380
548
|
* Set the schema validator for all routes.
|
|
381
549
|
*/
|
|
382
|
-
setValidatorCompiler<T = FastifySchema>(schemaCompiler: FastifySchemaCompiler<T>): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
550
|
+
setValidatorCompiler<T = FastifySchema>(schemaCompiler: FastifySchemaCompiler<T>): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
383
551
|
|
|
384
552
|
/**
|
|
385
553
|
* Set the schema serializer for all routes.
|
|
386
554
|
*/
|
|
387
|
-
setSerializerCompiler<T = FastifySchema>(schemaCompiler: FastifySerializerCompiler<T>): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
555
|
+
setSerializerCompiler<T = FastifySchema>(schemaCompiler: FastifySerializerCompiler<T>): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
388
556
|
|
|
389
557
|
/**
|
|
390
558
|
* Set the schema controller for all routes.
|
|
@@ -394,16 +562,16 @@ export interface FastifyInstance<
|
|
|
394
562
|
/**
|
|
395
563
|
* Set the reply serializer for all routes.
|
|
396
564
|
*/
|
|
397
|
-
setReplySerializer(replySerializer: (payload: unknown, statusCode: number) => string): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
565
|
+
setReplySerializer(replySerializer: (payload: unknown, statusCode: number) => string): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
398
566
|
|
|
399
567
|
/*
|
|
400
568
|
* Set the schema error formatter for all routes.
|
|
401
569
|
*/
|
|
402
|
-
setSchemaErrorFormatter(errorFormatter: (errors: FastifySchemaValidationError[], dataVar: string) => Error): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
570
|
+
setSchemaErrorFormatter(errorFormatter: (errors: FastifySchemaValidationError[], dataVar: string) => Error): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
403
571
|
/**
|
|
404
572
|
* Add a content type parser
|
|
405
573
|
*/
|
|
406
|
-
addContentTypeParser: AddContentTypeParser<RawServer, RawRequest>;
|
|
574
|
+
addContentTypeParser: AddContentTypeParser<RawServer, RawRequest, RouteGenericInterface, FastifySchema, TypeProvider>;
|
|
407
575
|
hasContentTypeParser: hasContentTypeParser;
|
|
408
576
|
/**
|
|
409
577
|
* Remove an existing content type parser
|