fastify 4.0.0-alpha.2 → 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.
@@ -1,10 +1,27 @@
1
1
  import { expectType } from 'tsd'
2
- import fastify, { RouteHandler, RawRequestDefaultExpression, RequestBodyDefault, RequestGenericInterface, FastifyContext, ContextConfigDefault, FastifyContextConfig } from '../../fastify'
2
+ import pino from 'pino'
3
+ import fastify, {
4
+ RouteHandler,
5
+ RawRequestDefaultExpression,
6
+ RequestBodyDefault,
7
+ RequestGenericInterface,
8
+ FastifyContext,
9
+ ContextConfigDefault,
10
+ FastifyContextConfig,
11
+ FastifyLogFn,
12
+ RouteHandlerMethod,
13
+ RawServerDefault,
14
+ RawReplyDefaultExpression,
15
+ FastifySchema,
16
+ FastifyTypeProviderDefault
17
+ } from '../../fastify'
3
18
  import { RequestParamsDefault, RequestHeadersDefault, RequestQuerystringDefault } from '../../types/utils'
4
19
  import { FastifyLoggerInstance } from '../../types/logger'
5
20
  import { FastifyRequest } from '../../types/request'
6
21
  import { FastifyReply } from '../../types/reply'
7
22
  import { FastifyInstance } from '../../types/instance'
23
+ import { RouteGenericInterface } from '../../types/route'
24
+ import { ResolveFastifyReplyReturnType, ResolveFastifyRequestType } from '../../types/type-provider'
8
25
 
9
26
  interface RequestBody {
10
27
  content: string;
@@ -38,6 +55,10 @@ type CustomRequest = FastifyRequest<{
38
55
  Headers: RequestHeaders;
39
56
  }>
40
57
 
58
+ interface CustomLoggerInterface extends FastifyLoggerInstance {
59
+ foo: FastifyLogFn; // custom severity logger method
60
+ }
61
+
41
62
  const getHandler: RouteHandler = function (request, _reply) {
42
63
  expectType<string>(request.url)
43
64
  expectType<string>(request.method)
@@ -64,6 +85,10 @@ const getHandler: RouteHandler = function (request, _reply) {
64
85
  expectType<FastifyInstance>(request.server)
65
86
  }
66
87
 
88
+ const getHandlerWithCustomLogger: RouteHandlerMethod<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, RouteGenericInterface, ContextConfigDefault, FastifySchema, FastifyTypeProviderDefault, ResolveFastifyReplyReturnType<FastifyTypeProviderDefault, FastifySchema, RouteGenericInterface>, ResolveFastifyRequestType<FastifyTypeProviderDefault, FastifySchema, RouteGenericInterface>, CustomLoggerInterface> = function (request, _reply) {
89
+ expectType<CustomLoggerInterface>(request.log)
90
+ }
91
+
67
92
  const postHandler: Handler = function (request) {
68
93
  expectType<RequestBody>(request.body)
69
94
  expectType<RequestParams>(request.params)
@@ -96,3 +121,48 @@ const server = fastify()
96
121
  server.get('/get', getHandler)
97
122
  server.post('/post', postHandler)
98
123
  server.put('/put', putHandler)
124
+
125
+ const customLogger: CustomLoggerInterface = {
126
+ level: 'info',
127
+ version: '5.0',
128
+ useOnlyCustomLevels: false,
129
+ useLevelLabels: false,
130
+ levels: { labels: [], values: {} },
131
+ eventNames: () => [],
132
+ listenerCount: (eventName: string | symbol) => 0,
133
+ bindings: () => ({}),
134
+ flush: () => () => {},
135
+ customLevels: { foo: 1 },
136
+ isLevelEnabled: () => false,
137
+ levelVal: 0,
138
+ silent: () => { },
139
+ info: () => { },
140
+ warn: () => { },
141
+ error: () => { },
142
+ fatal: () => { },
143
+ trace: () => { },
144
+ debug: () => { },
145
+ foo: () => { }, // custom severity logger method
146
+ on: (event, listener) => customLogger,
147
+ emit: (event, listener) => false,
148
+ off: (event, listener) => customLogger,
149
+ addListener: (event, listener) => customLogger,
150
+ prependListener: (event, listener) => customLogger,
151
+ prependOnceListener: (event, listener) => customLogger,
152
+ removeListener: (event, listener) => customLogger,
153
+ removeAllListeners: (event) => customLogger,
154
+ setMaxListeners: (n) => customLogger,
155
+ getMaxListeners: () => 0,
156
+ listeners: () => [],
157
+ rawListeners: () => [],
158
+ once: (event, listener) => customLogger,
159
+ child: () => customLogger as pino.Logger<never>
160
+ }
161
+
162
+ const serverWithCustomLogger = fastify({ logger: customLogger })
163
+ expectType<
164
+ FastifyInstance<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, CustomLoggerInterface>
165
+ & PromiseLike<FastifyInstance<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, CustomLoggerInterface>>
166
+ >(serverWithCustomLogger)
167
+
168
+ serverWithCustomLogger.get('/get', getHandlerWithCustomLogger)
@@ -1,8 +1,15 @@
1
- import fastify, { FastifyTypeProvider } from '../../fastify'
1
+ import fastify, {
2
+ ContextConfigDefault, FastifySchema,
3
+ FastifyTypeProvider, RawReplyDefaultExpression,
4
+ RawRequestDefaultExpression,
5
+ RawServerDefault,
6
+ RouteHandlerMethod
7
+ } from '../../fastify'
2
8
  import { expectAssignable, expectError, expectType } from 'tsd'
3
9
  import { IncomingHttpHeaders } from 'http'
4
10
  import { Type, TSchema, Static } from '@sinclair/typebox'
5
11
  import { FromSchema, JSONSchema } from 'json-schema-to-ts'
12
+ import { RouteGenericInterface } from '../../types/route'
6
13
 
7
14
  const server = fastify()
8
15
 
@@ -285,7 +292,7 @@ expectError(server.withTypeProvider<TypeBoxProvider>().get(
285
292
  }
286
293
  }
287
294
  },
288
- async (_, res) => {
295
+ async (_, res): Promise<RouteHandlerMethod<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, RouteGenericInterface, ContextConfigDefault, FastifySchema, TypeBoxProvider>> => {
289
296
  return false
290
297
  }
291
298
  ))
@@ -371,7 +378,7 @@ expectError(server.withTypeProvider<JsonSchemaToTsProvider>().get(
371
378
  } as const
372
379
  }
373
380
  },
374
- async (_, res) => {
381
+ async (_, res): Promise<RouteHandlerMethod<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, RouteGenericInterface, ContextConfigDefault, FastifySchema, TypeBoxProvider>> => {
375
382
  return false
376
383
  }
377
384
  ))
package/types/hooks.d.ts CHANGED
@@ -6,7 +6,12 @@ import { FastifyRequest } from './request'
6
6
  import { FastifyReply } from './reply'
7
7
  import { FastifyError } from 'fastify-error'
8
8
  import { FastifyLoggerInstance } from './logger'
9
- import { FastifyTypeProvider, FastifyTypeProviderDefault } from './type-provider'
9
+ import {
10
+ FastifyRequestType,
11
+ FastifyTypeProvider,
12
+ FastifyTypeProviderDefault,
13
+ ResolveFastifyRequestType
14
+ } from './type-provider'
10
15
  import { RegisterOptions } from './register'
11
16
  import { FastifySchema } from './schema'
12
17
  import { FastifyPluginOptions } from './plugin'
@@ -31,11 +36,12 @@ export interface onRequestHookHandler<
31
36
  ContextConfig = ContextConfigDefault,
32
37
  SchemaCompiler extends FastifySchema = FastifySchema,
33
38
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
34
-
39
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
40
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
35
41
  > {
36
42
  (
37
- this: FastifyInstance,
38
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
43
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
44
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
39
45
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
40
46
  done: HookHandlerDoneFunction
41
47
  ): void;
@@ -49,10 +55,12 @@ export interface onRequestAsyncHookHandler<
49
55
  ContextConfig = ContextConfigDefault,
50
56
  SchemaCompiler extends FastifySchema = FastifySchema,
51
57
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
58
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
59
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
52
60
  > {
53
61
  (
54
- this: FastifyInstance,
55
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
62
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
63
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
56
64
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
57
65
  ): Promise<unknown>;
58
66
  }
@@ -69,10 +77,12 @@ export interface preParsingHookHandler<
69
77
  ContextConfig = ContextConfigDefault,
70
78
  SchemaCompiler extends FastifySchema = FastifySchema,
71
79
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
80
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
81
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
72
82
  > {
73
83
  (
74
- this: FastifyInstance,
75
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
84
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
85
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
76
86
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
77
87
  payload: RequestPayload,
78
88
  done: <TError extends Error = FastifyError>(err?: TError | null, res?: RequestPayload) => void
@@ -87,10 +97,12 @@ export interface preParsingAsyncHookHandler<
87
97
  ContextConfig = ContextConfigDefault,
88
98
  SchemaCompiler extends FastifySchema = FastifySchema,
89
99
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
100
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
101
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
90
102
  > {
91
103
  (
92
- this: FastifyInstance,
93
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
104
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
105
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
94
106
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
95
107
  payload: RequestPayload,
96
108
  ): Promise<RequestPayload | unknown>;
@@ -107,10 +119,12 @@ export interface preValidationHookHandler<
107
119
  ContextConfig = ContextConfigDefault,
108
120
  SchemaCompiler extends FastifySchema = FastifySchema,
109
121
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
122
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
123
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
110
124
  > {
111
125
  (
112
- this: FastifyInstance,
113
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
126
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
127
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
114
128
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
115
129
  done: HookHandlerDoneFunction
116
130
  ): void;
@@ -124,10 +138,12 @@ export interface preValidationAsyncHookHandler<
124
138
  ContextConfig = ContextConfigDefault,
125
139
  SchemaCompiler extends FastifySchema = FastifySchema,
126
140
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
141
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
142
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
127
143
  > {
128
144
  (
129
- this: FastifyInstance,
130
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
145
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
146
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
131
147
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
132
148
  ): Promise<unknown>;
133
149
  }
@@ -143,10 +159,12 @@ export interface preHandlerHookHandler<
143
159
  ContextConfig = ContextConfigDefault,
144
160
  SchemaCompiler extends FastifySchema = FastifySchema,
145
161
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
162
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
163
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
146
164
  > {
147
165
  (
148
- this: FastifyInstance,
149
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
166
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
167
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
150
168
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
151
169
  done: HookHandlerDoneFunction
152
170
  ): void;
@@ -160,10 +178,12 @@ export interface preHandlerAsyncHookHandler<
160
178
  ContextConfig = ContextConfigDefault,
161
179
  SchemaCompiler extends FastifySchema = FastifySchema,
162
180
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
181
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
182
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
163
183
  > {
164
184
  (
165
- this: FastifyInstance,
166
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
185
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
186
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
167
187
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
168
188
  ): Promise<unknown>;
169
189
  }
@@ -188,10 +208,12 @@ export interface preSerializationHookHandler<
188
208
  ContextConfig = ContextConfigDefault,
189
209
  SchemaCompiler extends FastifySchema = FastifySchema,
190
210
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
211
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
212
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
191
213
  > {
192
214
  (
193
- this: FastifyInstance,
194
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
215
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
216
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
195
217
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
196
218
  payload: PreSerializationPayload,
197
219
  done: DoneFuncWithErrOrRes
@@ -207,10 +229,12 @@ export interface preSerializationAsyncHookHandler<
207
229
  ContextConfig = ContextConfigDefault,
208
230
  SchemaCompiler extends FastifySchema = FastifySchema,
209
231
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
232
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
233
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
210
234
  > {
211
235
  (
212
- this: FastifyInstance,
213
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
236
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
237
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
214
238
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
215
239
  payload: PreSerializationPayload
216
240
  ): Promise<unknown>;
@@ -229,10 +253,12 @@ export interface onSendHookHandler<
229
253
  ContextConfig = ContextConfigDefault,
230
254
  SchemaCompiler extends FastifySchema = FastifySchema,
231
255
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
256
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
257
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
232
258
  > {
233
259
  (
234
- this: FastifyInstance,
235
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
260
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
261
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
236
262
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
237
263
  payload: OnSendPayload,
238
264
  done: DoneFuncWithErrOrRes
@@ -248,10 +274,12 @@ export interface onSendAsyncHookHandler<
248
274
  ContextConfig = ContextConfigDefault,
249
275
  SchemaCompiler extends FastifySchema = FastifySchema,
250
276
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
277
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
278
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
251
279
  > {
252
280
  (
253
- this: FastifyInstance,
254
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
281
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
282
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
255
283
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
256
284
  payload: OnSendPayload,
257
285
  ): Promise<unknown>;
@@ -269,10 +297,12 @@ export interface onResponseHookHandler<
269
297
  ContextConfig = ContextConfigDefault,
270
298
  SchemaCompiler extends FastifySchema = FastifySchema,
271
299
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
300
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
301
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
272
302
  > {
273
303
  (
274
- this: FastifyInstance,
275
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
304
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
305
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
276
306
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
277
307
  done: HookHandlerDoneFunction
278
308
  ): void;
@@ -286,10 +316,12 @@ export interface onResponseAsyncHookHandler<
286
316
  ContextConfig = ContextConfigDefault,
287
317
  SchemaCompiler extends FastifySchema = FastifySchema,
288
318
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
319
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
320
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
289
321
  > {
290
322
  (
291
- this: FastifyInstance,
292
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
323
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
324
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
293
325
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
294
326
  ): Promise<unknown>;
295
327
  }
@@ -306,10 +338,12 @@ export interface onTimeoutHookHandler<
306
338
  ContextConfig = ContextConfigDefault,
307
339
  SchemaCompiler extends FastifySchema = FastifySchema,
308
340
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
341
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
342
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
309
343
  > {
310
344
  (
311
- this: FastifyInstance,
312
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
345
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
346
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
313
347
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
314
348
  done: HookHandlerDoneFunction
315
349
  ): void;
@@ -323,10 +357,12 @@ export interface onTimeoutAsyncHookHandler<
323
357
  ContextConfig = ContextConfigDefault,
324
358
  SchemaCompiler extends FastifySchema = FastifySchema,
325
359
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
360
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
361
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
326
362
  > {
327
363
  (
328
- this: FastifyInstance,
329
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
364
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
365
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
330
366
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
331
367
  ): Promise<unknown>;
332
368
  }
@@ -346,10 +382,12 @@ export interface onErrorHookHandler<
346
382
  TError extends Error = FastifyError,
347
383
  SchemaCompiler extends FastifySchema = FastifySchema,
348
384
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
385
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
386
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
349
387
  > {
350
388
  (
351
- this: FastifyInstance,
352
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
389
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
390
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
353
391
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
354
392
  error: TError,
355
393
  done: () => void
@@ -365,10 +403,12 @@ export interface onErrorAsyncHookHandler<
365
403
  TError extends Error = FastifyError,
366
404
  SchemaCompiler extends FastifySchema = FastifySchema,
367
405
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
406
+ RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>,
407
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
368
408
  > {
369
409
  (
370
- this: FastifyInstance,
371
- request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>,
410
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
411
+ request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
372
412
  reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>,
373
413
  error: TError
374
414
  ): Promise<unknown>;
@@ -387,9 +427,10 @@ export interface onRouteHookHandler<
387
427
  ContextConfig = ContextConfigDefault,
388
428
  SchemaCompiler extends FastifySchema = FastifySchema,
389
429
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
430
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance
390
431
  > {
391
432
  (
392
- this: FastifyInstance,
433
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
393
434
  opts: RouteOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider> & { routePath: string; path: string; prefix: string }
394
435
  ): Promise<unknown> | void;
395
436
  }
@@ -403,7 +444,7 @@ export interface onRegisterHookHandler<
403
444
  RawServer extends RawServerBase = RawServerDefault,
404
445
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
405
446
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
406
- Logger = FastifyLoggerInstance,
447
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance,
407
448
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
408
449
  Options extends FastifyPluginOptions = FastifyPluginOptions
409
450
  > {
@@ -417,16 +458,28 @@ export interface onRegisterHookHandler<
417
458
  /**
418
459
  * 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.
419
460
  */
420
- export interface onReadyHookHandler {
461
+ export interface onReadyHookHandler<
462
+ RawServer extends RawServerBase = RawServerDefault,
463
+ RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
464
+ RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
465
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance,
466
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
467
+ > {
421
468
  (
422
- this: FastifyInstance,
469
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
423
470
  done: HookHandlerDoneFunction
424
471
  ): void;
425
472
  }
426
473
 
427
- export interface onReadyAsyncHookHandler {
474
+ export interface onReadyAsyncHookHandler<
475
+ RawServer extends RawServerBase = RawServerDefault,
476
+ RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
477
+ RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
478
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance,
479
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
480
+ > {
428
481
  (
429
- this: FastifyInstance,
482
+ this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
430
483
  ): Promise<unknown>;
431
484
  }
432
485
  /**
@@ -436,7 +489,7 @@ export interface onCloseHookHandler<
436
489
  RawServer extends RawServerBase = RawServerDefault,
437
490
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
438
491
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
439
- Logger = FastifyLoggerInstance,
492
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance,
440
493
  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
441
494
  > {
442
495
  (
@@ -449,9 +502,10 @@ export interface onCloseAsyncHookHandler<
449
502
  RawServer extends RawServerBase = RawServerDefault,
450
503
  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
451
504
  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
452
- Logger = FastifyLoggerInstance
505
+ Logger extends FastifyLoggerInstance = FastifyLoggerInstance,
506
+ TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault
453
507
  > {
454
508
  (
455
- instance: FastifyInstance<RawServer, RawRequest, RawReply, Logger>
509
+ instance: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>
456
510
  ): Promise<unknown>;
457
511
  }