fastify 4.9.1 → 4.10.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/README.md +7 -1
- package/docs/Guides/Ecosystem.md +2 -0
- package/docs/Guides/Plugins-Guide.md +0 -18
- package/docs/Guides/Recommendations.md +51 -0
- package/docs/Guides/Write-Type-Provider.md +32 -0
- package/docs/Reference/Decorators.md +7 -1
- package/docs/Reference/Reply.md +15 -7
- package/docs/Reference/Request.md +20 -1
- package/docs/Reference/Server.md +8 -1
- package/docs/Reference/TypeScript.md +1 -1
- package/fastify.d.ts +1 -0
- package/fastify.js +10 -5
- package/lib/contentTypeParser.js +6 -3
- package/lib/context.js +4 -0
- package/lib/errors.js +6 -0
- package/lib/hooks.js +1 -1
- package/lib/reply.js +50 -7
- package/lib/request.js +19 -0
- package/lib/route.js +9 -3
- package/lib/warnings.js +2 -0
- package/package.json +25 -26
- package/test/bodyLimit.test.js +79 -0
- package/test/close-pipelining.test.js +67 -42
- package/test/close.test.js +42 -1
- package/test/hooks-async.test.js +6 -2
- package/test/hooks.on-ready.test.js +2 -1
- package/test/hooks.test.js +20 -4
- package/test/input-validation.js +0 -1
- package/test/internals/hooks.test.js +1 -1
- package/test/logger.test.js +0 -14
- package/test/reply-trailers.test.js +207 -18
- package/test/request-error.test.js +96 -0
- package/test/types/fastify.test-d.ts +8 -1
- package/test/types/logger.test-d.ts +1 -35
- package/test/types/request.test-d.ts +5 -3
- package/test/types/type-provider.test-d.ts +317 -2
- package/types/context.d.ts +3 -0
- package/types/hooks.d.ts +25 -25
- package/types/instance.d.ts +21 -21
- package/types/logger.d.ts +3 -7
- package/types/plugin.d.ts +3 -3
- package/types/reply.d.ts +3 -4
- package/types/request.d.ts +17 -3
- package/types/route.d.ts +9 -9
- package/types/type-provider.d.ts +5 -3
package/types/instance.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as http from 'http'
|
|
|
4
4
|
import { CallbackFunc as LightMyRequestCallback, Chain as LightMyRequestChain, InjectOptions, Response as LightMyRequestResponse } from 'light-my-request'
|
|
5
5
|
import { AddContentTypeParser, ConstructorAction, FastifyBodyParser, getDefaultJsonParser, hasContentTypeParser, ProtoAction, removeAllContentTypeParsers, removeContentTypeParser } from './content-type-parser'
|
|
6
6
|
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'
|
|
7
|
-
import {
|
|
7
|
+
import { FastifyBaseLogger } from './logger'
|
|
8
8
|
import { FastifyRegister } from './register'
|
|
9
9
|
import { FastifyReply } from './reply'
|
|
10
10
|
import { FastifyRequest } from './request'
|
|
@@ -84,7 +84,7 @@ export interface FastifyInstance<
|
|
|
84
84
|
RawServer extends RawServerBase = RawServerDefault,
|
|
85
85
|
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
86
86
|
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
87
|
-
Logger extends FastifyBaseLogger =
|
|
87
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger,
|
|
88
88
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
89
89
|
> {
|
|
90
90
|
server: RawServer;
|
|
@@ -204,7 +204,7 @@ export interface FastifyInstance<
|
|
|
204
204
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
205
205
|
ContextConfig = ContextConfigDefault,
|
|
206
206
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
207
|
-
Logger extends FastifyBaseLogger =
|
|
207
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
208
208
|
>(
|
|
209
209
|
name: 'onRequest',
|
|
210
210
|
hook: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -214,7 +214,7 @@ export interface FastifyInstance<
|
|
|
214
214
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
215
215
|
ContextConfig = ContextConfigDefault,
|
|
216
216
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
217
|
-
Logger extends FastifyBaseLogger =
|
|
217
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
218
218
|
>(
|
|
219
219
|
name: 'onRequest',
|
|
220
220
|
hook: onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -228,7 +228,7 @@ export interface FastifyInstance<
|
|
|
228
228
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
229
229
|
ContextConfig = ContextConfigDefault,
|
|
230
230
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
231
|
-
Logger extends FastifyBaseLogger =
|
|
231
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
232
232
|
>(
|
|
233
233
|
name: 'preParsing',
|
|
234
234
|
hook: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -238,7 +238,7 @@ export interface FastifyInstance<
|
|
|
238
238
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
239
239
|
ContextConfig = ContextConfigDefault,
|
|
240
240
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
241
|
-
Logger extends FastifyBaseLogger =
|
|
241
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
242
242
|
>(
|
|
243
243
|
name: 'preParsing',
|
|
244
244
|
hook: preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -251,7 +251,7 @@ export interface FastifyInstance<
|
|
|
251
251
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
252
252
|
ContextConfig = ContextConfigDefault,
|
|
253
253
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
254
|
-
Logger extends FastifyBaseLogger =
|
|
254
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
255
255
|
>(
|
|
256
256
|
name: 'preValidation',
|
|
257
257
|
hook: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -261,7 +261,7 @@ export interface FastifyInstance<
|
|
|
261
261
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
262
262
|
ContextConfig = ContextConfigDefault,
|
|
263
263
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
264
|
-
Logger extends FastifyBaseLogger =
|
|
264
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
265
265
|
>(
|
|
266
266
|
name: 'preValidation',
|
|
267
267
|
hook: preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -274,7 +274,7 @@ export interface FastifyInstance<
|
|
|
274
274
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
275
275
|
ContextConfig = ContextConfigDefault,
|
|
276
276
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
277
|
-
Logger extends FastifyBaseLogger =
|
|
277
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
278
278
|
>(
|
|
279
279
|
name: 'preHandler',
|
|
280
280
|
hook: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -284,7 +284,7 @@ export interface FastifyInstance<
|
|
|
284
284
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
285
285
|
ContextConfig = ContextConfigDefault,
|
|
286
286
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
287
|
-
Logger extends FastifyBaseLogger =
|
|
287
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
288
288
|
>(
|
|
289
289
|
name: 'preHandler',
|
|
290
290
|
hook: preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -299,7 +299,7 @@ export interface FastifyInstance<
|
|
|
299
299
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
300
300
|
ContextConfig = ContextConfigDefault,
|
|
301
301
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
302
|
-
Logger extends FastifyBaseLogger =
|
|
302
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
303
303
|
>(
|
|
304
304
|
name: 'preSerialization',
|
|
305
305
|
hook: preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -310,7 +310,7 @@ export interface FastifyInstance<
|
|
|
310
310
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
311
311
|
ContextConfig = ContextConfigDefault,
|
|
312
312
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
313
|
-
Logger extends FastifyBaseLogger =
|
|
313
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
314
314
|
>(
|
|
315
315
|
name: 'preSerialization',
|
|
316
316
|
hook: preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -325,7 +325,7 @@ export interface FastifyInstance<
|
|
|
325
325
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
326
326
|
ContextConfig = ContextConfigDefault,
|
|
327
327
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
328
|
-
Logger extends FastifyBaseLogger =
|
|
328
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
329
329
|
>(
|
|
330
330
|
name: 'onSend',
|
|
331
331
|
hook: onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -336,7 +336,7 @@ export interface FastifyInstance<
|
|
|
336
336
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
337
337
|
ContextConfig = ContextConfigDefault,
|
|
338
338
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
339
|
-
Logger extends FastifyBaseLogger =
|
|
339
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
340
340
|
>(
|
|
341
341
|
name: 'onSend',
|
|
342
342
|
hook: onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -350,7 +350,7 @@ export interface FastifyInstance<
|
|
|
350
350
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
351
351
|
ContextConfig = ContextConfigDefault,
|
|
352
352
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
353
|
-
Logger extends FastifyBaseLogger =
|
|
353
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
354
354
|
>(
|
|
355
355
|
name: 'onResponse',
|
|
356
356
|
hook: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -360,7 +360,7 @@ export interface FastifyInstance<
|
|
|
360
360
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
361
361
|
ContextConfig = ContextConfigDefault,
|
|
362
362
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
363
|
-
Logger extends FastifyBaseLogger =
|
|
363
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
364
364
|
>(
|
|
365
365
|
name: 'onResponse',
|
|
366
366
|
hook: onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -374,7 +374,7 @@ export interface FastifyInstance<
|
|
|
374
374
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
375
375
|
ContextConfig = ContextConfigDefault,
|
|
376
376
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
377
|
-
Logger extends FastifyBaseLogger =
|
|
377
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
378
378
|
>(
|
|
379
379
|
name: 'onTimeout',
|
|
380
380
|
hook: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -384,7 +384,7 @@ export interface FastifyInstance<
|
|
|
384
384
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
385
385
|
ContextConfig = ContextConfigDefault,
|
|
386
386
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
387
|
-
Logger extends FastifyBaseLogger =
|
|
387
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
388
388
|
>(
|
|
389
389
|
name: 'onTimeout',
|
|
390
390
|
hook: onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -400,7 +400,7 @@ export interface FastifyInstance<
|
|
|
400
400
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
401
401
|
ContextConfig = ContextConfigDefault,
|
|
402
402
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
403
|
-
Logger extends FastifyBaseLogger =
|
|
403
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
404
404
|
>(
|
|
405
405
|
name: 'onError',
|
|
406
406
|
hook: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -410,7 +410,7 @@ export interface FastifyInstance<
|
|
|
410
410
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
411
411
|
ContextConfig = ContextConfigDefault,
|
|
412
412
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
413
|
-
Logger extends FastifyBaseLogger =
|
|
413
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
414
414
|
>(
|
|
415
415
|
name: 'onError',
|
|
416
416
|
hook: onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>
|
|
@@ -425,7 +425,7 @@ export interface FastifyInstance<
|
|
|
425
425
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
426
426
|
ContextConfig = ContextConfigDefault,
|
|
427
427
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
428
|
-
Logger extends FastifyBaseLogger =
|
|
428
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
429
429
|
>(
|
|
430
430
|
name: 'onRoute',
|
|
431
431
|
hook: onRouteHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
package/types/logger.d.ts
CHANGED
|
@@ -19,19 +19,15 @@ export type Bindings = pino.Bindings
|
|
|
19
19
|
|
|
20
20
|
export type ChildLoggerOptions = pino.ChildLoggerOptions
|
|
21
21
|
|
|
22
|
-
export
|
|
23
|
-
child(bindings: Bindings, options?: ChildLoggerOptions):
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface DefaultFastifyLogger extends FastifyBaseLogger<DefaultFastifyLogger>, Pick<pino.Logger, 'setBindings'> {
|
|
27
|
-
|
|
22
|
+
export type FastifyBaseLogger = pino.BaseLogger & {
|
|
23
|
+
child(bindings: Bindings, options?: ChildLoggerOptions): FastifyBaseLogger
|
|
28
24
|
}
|
|
29
25
|
|
|
30
26
|
// TODO delete FastifyBaseLogger in the next major release. It seems that it is enough to have only FastifyBaseLogger.
|
|
31
27
|
/**
|
|
32
28
|
* @deprecated Use FastifyBaseLogger instead
|
|
33
29
|
*/
|
|
34
|
-
export type FastifyLoggerInstance =
|
|
30
|
+
export type FastifyLoggerInstance = FastifyBaseLogger
|
|
35
31
|
|
|
36
32
|
export interface FastifyLoggerStreamDestination {
|
|
37
33
|
write(msg: string): void;
|
package/types/plugin.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FastifyInstance } from './instance'
|
|
2
2
|
import { RawServerBase, RawRequestDefaultExpression, RawReplyDefaultExpression, RawServerDefault } from './utils'
|
|
3
3
|
import { FastifyTypeProvider, FastifyTypeProviderDefault } from './type-provider'
|
|
4
|
-
import {
|
|
4
|
+
import { FastifyBaseLogger } from './logger'
|
|
5
5
|
|
|
6
6
|
export type FastifyPluginOptions = Record<string, any>
|
|
7
7
|
|
|
@@ -11,7 +11,7 @@ export type FastifyPluginOptions = Record<string, any>
|
|
|
11
11
|
* Fastify allows the user to extend its functionalities with plugins. A plugin can be a set of routes, a server decorator or whatever. To activate plugins, use the `fastify.register()` method.
|
|
12
12
|
*/
|
|
13
13
|
export type FastifyPluginCallback<Options extends FastifyPluginOptions = Record<never, never>, Server extends RawServerBase = RawServerDefault, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault> = (
|
|
14
|
-
instance: FastifyInstance<Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>,
|
|
14
|
+
instance: FastifyInstance<Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>, FastifyBaseLogger, TypeProvider>,
|
|
15
15
|
opts: Options,
|
|
16
16
|
done: (err?: Error) => void
|
|
17
17
|
) => void
|
|
@@ -26,7 +26,7 @@ export type FastifyPluginAsync<
|
|
|
26
26
|
Server extends RawServerBase = RawServerDefault,
|
|
27
27
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
28
28
|
> = (
|
|
29
|
-
instance: FastifyInstance<Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>,
|
|
29
|
+
instance: FastifyInstance<Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>, FastifyBaseLogger, TypeProvider>,
|
|
30
30
|
opts: Options
|
|
31
31
|
) => Promise<void>;
|
|
32
32
|
|
package/types/reply.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RawReplyDefaultExpression, RawServerBase, RawServerDefault, ContextConfigDefault, RawRequestDefaultExpression, ReplyDefault } from './utils'
|
|
2
2
|
import { FastifyReplyType, ResolveFastifyReplyType, FastifyTypeProvider, FastifyTypeProviderDefault } from './type-provider'
|
|
3
3
|
import { FastifyContext } from './context'
|
|
4
|
-
import {
|
|
4
|
+
import { FastifyBaseLogger } from './logger'
|
|
5
5
|
import { FastifyRequest } from './request'
|
|
6
6
|
import { RouteGenericInterface } from './route'
|
|
7
7
|
import { FastifyInstance } from './instance'
|
|
@@ -24,12 +24,11 @@ export interface FastifyReply<
|
|
|
24
24
|
ContextConfig = ContextConfigDefault,
|
|
25
25
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
26
26
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
27
|
-
ReplyType extends FastifyReplyType = ResolveFastifyReplyType<TypeProvider, SchemaCompiler, RouteGeneric
|
|
28
|
-
Logger extends FastifyBaseLogger = DefaultFastifyLogger,
|
|
27
|
+
ReplyType extends FastifyReplyType = ResolveFastifyReplyType<TypeProvider, SchemaCompiler, RouteGeneric>
|
|
29
28
|
> {
|
|
30
29
|
raw: RawReply;
|
|
31
30
|
context: FastifyContext<ContextConfig>;
|
|
32
|
-
log:
|
|
31
|
+
log: FastifyBaseLogger;
|
|
33
32
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider>;
|
|
34
33
|
server: FastifyInstance;
|
|
35
34
|
code(statusCode: number): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>;
|
package/types/request.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ErrorObject } from '@fastify/ajv-compiler'
|
|
2
|
-
import {
|
|
2
|
+
import { FastifyBaseLogger } from './logger'
|
|
3
3
|
import { ContextConfigDefault, RawServerBase, RawServerDefault, RawRequestDefaultExpression, RequestBodyDefault, RequestQuerystringDefault, RequestParamsDefault, RequestHeadersDefault } from './utils'
|
|
4
4
|
import { RouteGenericInterface } from './route'
|
|
5
5
|
import { FastifyInstance } from './instance'
|
|
6
6
|
import { FastifyTypeProvider, FastifyTypeProviderDefault, FastifyRequestType, ResolveFastifyRequestType } from './type-provider'
|
|
7
7
|
import { FastifySchema } from './schema'
|
|
8
|
-
import { FastifyContext } from './context'
|
|
8
|
+
import { FastifyContext, FastifyContextConfig } from './context'
|
|
9
9
|
|
|
10
10
|
type HTTPRequestPart = 'body' | 'query' | 'querystring' | 'params' | 'headers'
|
|
11
11
|
export interface RequestGenericInterface {
|
|
@@ -20,6 +20,17 @@ export interface ValidationFunction {
|
|
|
20
20
|
errors?: null | ErrorObject[];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
export interface RequestRouteOptions {
|
|
24
|
+
method: string,
|
|
25
|
+
url: string,
|
|
26
|
+
bodyLimit:number,
|
|
27
|
+
attachValidation:boolean,
|
|
28
|
+
logLevel:string,
|
|
29
|
+
version: string | undefined,
|
|
30
|
+
exposeHeadRoute: boolean,
|
|
31
|
+
prefixTrailingSlash: string
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
/**
|
|
24
35
|
* FastifyRequest is an instance of the standard http or http2 request objects.
|
|
25
36
|
* It defaults to http.IncomingMessage, and it also extends the relative request object.
|
|
@@ -30,7 +41,7 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
|
|
|
30
41
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
31
42
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
32
43
|
ContextConfig = ContextConfigDefault,
|
|
33
|
-
Logger extends FastifyBaseLogger =
|
|
44
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger,
|
|
34
45
|
RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>
|
|
35
46
|
// ^ Temporary Note: RequestType has been re-ordered to be the last argument in
|
|
36
47
|
// generic list. This generic argument is now considered optional as it can be
|
|
@@ -48,6 +59,8 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
|
|
|
48
59
|
server: FastifyInstance;
|
|
49
60
|
body: RequestType['body'];
|
|
50
61
|
context: FastifyContext<ContextConfig>;
|
|
62
|
+
routeConfig: FastifyContextConfig & ContextConfig;
|
|
63
|
+
routeSchema: FastifySchema
|
|
51
64
|
|
|
52
65
|
/** in order for this to be used the user should ensure they have set the attachValidation option. */
|
|
53
66
|
validationError?: Error & { validation: any; validationContext: string };
|
|
@@ -64,6 +77,7 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
|
|
|
64
77
|
readonly method: string;
|
|
65
78
|
readonly routerPath: string;
|
|
66
79
|
readonly routerMethod: string;
|
|
80
|
+
readonly routeOptions: Readonly<RequestRouteOptions>
|
|
67
81
|
readonly is404: boolean;
|
|
68
82
|
readonly socket: RawRequest['socket'];
|
|
69
83
|
|
package/types/route.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
FastifyTypeProviderDefault,
|
|
12
12
|
ResolveFastifyReplyReturnType
|
|
13
13
|
} from './type-provider'
|
|
14
|
-
import {
|
|
14
|
+
import { FastifyBaseLogger, LogLevel } from './logger'
|
|
15
15
|
|
|
16
16
|
export interface RouteGenericInterface extends RequestGenericInterface, ReplyGenericInterface {}
|
|
17
17
|
|
|
@@ -26,7 +26,7 @@ export interface RouteShorthandOptions<
|
|
|
26
26
|
ContextConfig = ContextConfigDefault,
|
|
27
27
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
28
28
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
29
|
-
Logger extends FastifyBaseLogger =
|
|
29
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
30
30
|
> {
|
|
31
31
|
schema?: SchemaCompiler, // originally FastifySchema
|
|
32
32
|
attachValidation?: boolean;
|
|
@@ -67,7 +67,7 @@ export type RouteHandlerMethod<
|
|
|
67
67
|
ContextConfig = ContextConfigDefault,
|
|
68
68
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
69
69
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
70
|
-
Logger extends FastifyBaseLogger =
|
|
70
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
71
71
|
> = (
|
|
72
72
|
this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
|
|
73
73
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger>,
|
|
@@ -86,7 +86,7 @@ export interface RouteShorthandOptionsWithHandler<
|
|
|
86
86
|
ContextConfig = ContextConfigDefault,
|
|
87
87
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
88
88
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
89
|
-
Logger extends FastifyBaseLogger =
|
|
89
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
90
90
|
> extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> {
|
|
91
91
|
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>;
|
|
92
92
|
}
|
|
@@ -100,16 +100,16 @@ export interface RouteShorthandMethod<
|
|
|
100
100
|
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
101
101
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
102
102
|
> {
|
|
103
|
-
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger =
|
|
103
|
+
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger = FastifyBaseLogger>(
|
|
104
104
|
path: string,
|
|
105
105
|
opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>,
|
|
106
106
|
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
107
107
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
108
|
-
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger =
|
|
108
|
+
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger = FastifyBaseLogger>(
|
|
109
109
|
path: string,
|
|
110
110
|
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
111
111
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
112
|
-
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger =
|
|
112
|
+
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler extends FastifySchema = FastifySchema, Logger extends FastifyBaseLogger = FastifyBaseLogger>(
|
|
113
113
|
path: string,
|
|
114
114
|
opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
|
|
115
115
|
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
@@ -126,7 +126,7 @@ export interface RouteOptions<
|
|
|
126
126
|
ContextConfig = ContextConfigDefault,
|
|
127
127
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
128
128
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
129
|
-
Logger extends FastifyBaseLogger =
|
|
129
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
130
130
|
> extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> {
|
|
131
131
|
method: HTTPMethods | HTTPMethods[];
|
|
132
132
|
url: string;
|
|
@@ -141,7 +141,7 @@ export type RouteHandler<
|
|
|
141
141
|
ContextConfig = ContextConfigDefault,
|
|
142
142
|
SchemaCompiler extends FastifySchema = FastifySchema,
|
|
143
143
|
TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
|
144
|
-
Logger extends FastifyBaseLogger =
|
|
144
|
+
Logger extends FastifyBaseLogger = FastifyBaseLogger
|
|
145
145
|
> = (
|
|
146
146
|
this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
|
|
147
147
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger>,
|
package/types/type-provider.d.ts
CHANGED
|
@@ -60,10 +60,12 @@ export interface ResolveFastifyRequestType<TypeProvider extends FastifyTypeProvi
|
|
|
60
60
|
// FastifyReplyType
|
|
61
61
|
// -----------------------------------------------------------------------------------------------
|
|
62
62
|
|
|
63
|
-
// Resolves the Reply type by taking a union of response status codes
|
|
63
|
+
// Resolves the Reply type by taking a union of response status codes and content-types
|
|
64
64
|
type ResolveReplyFromSchemaCompiler<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema> = {
|
|
65
|
-
[
|
|
66
|
-
|
|
65
|
+
[K1 in keyof SchemaCompiler['response']]: SchemaCompiler['response'][K1] extends { content: { [keyof: string]: { schema: unknown } } } ? ({
|
|
66
|
+
[K2 in keyof SchemaCompiler['response'][K1]['content']]: CallTypeProvider<TypeProvider, SchemaCompiler['response'][K1]['content'][K2]['schema']>
|
|
67
|
+
} extends infer Result ? Result[keyof Result] : unknown) : CallTypeProvider<TypeProvider, SchemaCompiler['response'][K1]>
|
|
68
|
+
} extends infer Result ? Result[keyof Result] : unknown;
|
|
67
69
|
|
|
68
70
|
// The target reply type. This type is inferenced on fastify 'replies' via generic argument assignment
|
|
69
71
|
export type FastifyReplyType<Reply = unknown> = Reply
|