1 | import { Chain as LightMyRequestChain, InjectOptions, Response as LightMyRequestResponse, CallbackFunc as LightMyRequestCallback } from 'light-my-request'
|
2 | import { RouteOptions, RouteShorthandMethod, RouteGenericInterface } from './route'
|
3 | import { FastifySchemaCompiler, FastifySchemaValidationError } from './schema'
|
4 | import { RawServerBase, RawRequestDefaultExpression, RawServerDefault, RawReplyDefaultExpression, ContextConfigDefault } from './utils'
|
5 | import { FastifyLoggerInstance } from './logger'
|
6 | import { FastifyRegister } from './register'
|
7 | import { onRequestHookHandler, preParsingHookHandler, onSendHookHandler, preValidationHookHandler, preHandlerHookHandler, preSerializationHookHandler, onResponseHookHandler, onErrorHookHandler, onRouteHookHandler, onRegisterHookHandler, onCloseHookHandler, onReadyHookHandler, onTimeoutHookHandler } from './hooks'
|
8 | import { FastifyRequest } from './request'
|
9 | import { FastifyReply } from './reply'
|
10 | import { FastifyError } from 'fastify-error'
|
11 | import { AddContentTypeParser, hasContentTypeParser } from './content-type-parser'
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export interface FastifyInstance<
|
17 | RawServer extends RawServerBase = RawServerDefault,
|
18 | RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
19 | RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
20 | Logger = FastifyLoggerInstance
|
21 | > {
|
22 | server: RawServer;
|
23 | prefix: string;
|
24 | version: string | undefined;
|
25 | log: Logger;
|
26 |
|
27 | addSchema(schema: unknown): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
28 | getSchema(schemaId: string): unknown;
|
29 | getSchemas(): Record<string, unknown>;
|
30 |
|
31 | after(): FastifyInstance<RawServer, RawRequest, RawReply, Logger> & PromiseLike<undefined>;
|
32 | after(afterListener: (err: Error) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
33 |
|
34 | close(): FastifyInstance<RawServer, RawRequest, RawReply, Logger> & PromiseLike<undefined>;
|
35 | close(closeListener: () => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
36 |
|
37 |
|
38 | decorate(property: string | symbol, value: any, dependencies?: string[]): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
39 | decorateRequest(property: string | symbol, value: any, dependencies?: string[]): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
40 | decorateReply(property: string | symbol, value: any, dependencies?: string[]): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
41 |
|
42 | hasDecorator(decorator: string | symbol): boolean;
|
43 | hasRequestDecorator(decorator: string | symbol): boolean;
|
44 | hasReplyDecorator(decorator: string | symbol): boolean;
|
45 |
|
46 | inject(opts: InjectOptions | string, cb: LightMyRequestCallback): void;
|
47 | inject(opts: InjectOptions | string): Promise<LightMyRequestResponse>;
|
48 | inject(): LightMyRequestChain;
|
49 |
|
50 | listen(port: number | string, address: string, backlog: number, callback: (err: Error, address: string) => void): void;
|
51 | listen(port: number | string, address: string, callback: (err: Error, address: string) => void): void;
|
52 | listen(port: number | string, callback: (err: Error, address: string) => void): void;
|
53 | listen(port: number | string, address?: string, backlog?: number): Promise<string>;
|
54 | listen(opts: { port: number; host?: string; backlog?: number }, callback: (err: Error, address: string) => void): void;
|
55 | listen(opts: { port: number; host?: string; backlog?: number }): Promise<string>;
|
56 |
|
57 | ready(): FastifyInstance<RawServer, RawRequest, RawReply> & PromiseLike<undefined>;
|
58 | ready(readyListener: (err: Error) => void): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
59 |
|
60 | register: FastifyRegister<FastifyInstance<RawServer, RawRequest, RawReply, Logger> & PromiseLike<undefined>>;
|
61 |
|
62 | |
63 |
|
64 |
|
65 |
|
66 |
|
67 | use(...args: unknown[]): unknown;
|
68 |
|
69 | route<
|
70 | RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
71 | ContextConfig = ContextConfigDefault
|
72 | >(opts: RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
73 |
|
74 | get: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
75 | head: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
76 | post: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
77 | put: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
78 | delete: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
79 | options: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
80 | patch: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
81 | all: RouteShorthandMethod<RawServer, RawRequest, RawReply>;
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | |
88 |
|
89 |
|
90 |
|
91 | addHook<
|
92 | RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
93 | ContextConfig = ContextConfigDefault
|
94 | >(
|
95 | name: 'onRequest',
|
96 | hook: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
97 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
98 |
|
99 | |
100 |
|
101 |
|
102 |
|
103 | addHook<
|
104 | RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
105 | ContextConfig = ContextConfigDefault
|
106 | >(
|
107 | name: 'preParsing',
|
108 | hook: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
109 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
110 |
|
111 | |
112 |
|
113 |
|
114 | addHook<
|
115 | RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
116 | ContextConfig = ContextConfigDefault
|
117 | >(
|
118 | name: 'preValidation',
|
119 | hook: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
120 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
121 |
|
122 | |
123 |
|
124 |
|
125 | addHook<
|
126 | RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
127 | ContextConfig = ContextConfigDefault
|
128 | >(
|
129 | name: 'preHandler',
|
130 | hook: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
131 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
132 |
|
133 | |
134 |
|
135 |
|
136 |
|
137 | addHook<
|
138 | PreSerializationPayload = unknown,
|
139 | RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
140 | ContextConfig = ContextConfigDefault
|
141 | >(
|
142 | name: 'preSerialization',
|
143 | hook: preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
144 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
145 |
|
146 | |
147 |
|
148 |
|
149 |
|
150 | addHook<
|
151 | OnSendPayload = unknown,
|
152 | RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
153 | ContextConfig = ContextConfigDefault
|
154 | >(
|
155 | name: 'onSend',
|
156 | hook: onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
157 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
158 |
|
159 | |
160 |
|
161 |
|
162 |
|
163 | addHook<
|
164 | RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
165 | ContextConfig = ContextConfigDefault
|
166 | >(
|
167 | name: 'onResponse',
|
168 | hook: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
169 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
170 |
|
171 | |
172 |
|
173 |
|
174 |
|
175 | addHook<
|
176 | RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
177 | ContextConfig = ContextConfigDefault
|
178 | >(
|
179 | name: 'onTimeout',
|
180 | hook: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
181 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
182 |
|
183 | |
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 | addHook<
|
190 | RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
191 | ContextConfig = ContextConfigDefault
|
192 | >(
|
193 | name: 'onError',
|
194 | hook: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
195 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
196 |
|
197 |
|
198 |
|
199 | |
200 |
|
201 |
|
202 | addHook<
|
203 | RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
204 | ContextConfig = ContextConfigDefault
|
205 | >(
|
206 | name: 'onRoute',
|
207 | hook: onRouteHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
208 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
209 |
|
210 | |
211 |
|
212 |
|
213 |
|
214 |
|
215 | addHook(
|
216 | name: 'onRegister',
|
217 | hook: onRegisterHookHandler<RawServer, RawRequest, RawReply, Logger>
|
218 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
219 |
|
220 | |
221 |
|
222 |
|
223 | addHook(
|
224 | name: 'onReady',
|
225 | hook: onReadyHookHandler<RawServer, Logger>
|
226 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
227 |
|
228 | |
229 |
|
230 |
|
231 | addHook(
|
232 | name: 'onClose',
|
233 | hook: onCloseHookHandler<RawServer, RawRequest, RawReply, Logger>
|
234 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
235 |
|
236 | |
237 |
|
238 |
|
239 | setNotFoundHandler<RouteGeneric extends RouteGenericInterface = RouteGenericInterface>(
|
240 | handler: (request: FastifyRequest<RouteGeneric, RawServer, RawRequest>, reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric>) => void
|
241 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
242 |
|
243 | |
244 |
|
245 |
|
246 | setErrorHandler<TError extends Error = FastifyError, RouteGeneric extends RouteGenericInterface = RouteGenericInterface>(
|
247 | handler: (this: FastifyInstance<RawServer, RawRequest, RawReply, Logger>, error: TError, request: FastifyRequest<RouteGeneric, RawServer, RawRequest>, reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric>) => void
|
248 | ): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
249 |
|
250 | |
251 |
|
252 |
|
253 | setValidatorCompiler(schemaCompiler: FastifySchemaCompiler): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
254 |
|
255 | |
256 |
|
257 |
|
258 | setSerializerCompiler(schemaCompiler: FastifySchemaCompiler): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
259 |
|
260 | |
261 |
|
262 |
|
263 | setReplySerializer(replySerializer: (payload: unknown, statusCode: number) => string): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
264 |
|
265 | |
266 |
|
267 |
|
268 | setSchemaErrorFormatter(errorFormatter: (errors: FastifySchemaValidationError[], dataVar: string) => Error): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
269 | |
270 |
|
271 |
|
272 | addContentTypeParser: AddContentTypeParser<RawServer, RawRequest>;
|
273 | hasContentTypeParser: hasContentTypeParser;
|
274 |
|
275 | |
276 |
|
277 |
|
278 | printRoutes(): string;
|
279 | }
|