fastify 3.27.2 → 3.28.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/docs/Reference/Reply.md +49 -0
- package/fastify.js +1 -1
- package/lib/errors.js +8 -0
- package/lib/fourOhFour.js +20 -1
- package/lib/reply.js +96 -9
- package/lib/symbols.js +1 -0
- package/package.json +1 -1
- package/test/404s.test.js +52 -0
- package/test/internals/reply.test.js +16 -14
- package/test/logger.test.js +20 -0
- package/test/reply-trailers.test.js +277 -0
- package/test/types/hooks.test-d.ts +52 -2
- package/test/types/request.test-d.ts +41 -1
- package/types/.eslintrc.json +3 -1
- package/types/hooks.d.ts +85 -61
- package/types/instance.d.ts +54 -38
- package/types/request.d.ts +2 -1
- package/types/route.d.ts +35 -30
package/types/route.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { FastifyRequest, RequestGenericInterface } from './request'
|
|
|
3
3
|
import { FastifyReply, ReplyGenericInterface } from './reply'
|
|
4
4
|
import { FastifySchema, FastifySchemaCompiler, FastifySchemaValidationError, FastifySerializerCompiler } from './schema'
|
|
5
5
|
import { HTTPMethods, RawServerBase, RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, ContextConfigDefault } from './utils'
|
|
6
|
-
import { LogLevel } from './logger'
|
|
6
|
+
import { FastifyLoggerInstance, LogLevel } from './logger'
|
|
7
7
|
import { preValidationHookHandler, preHandlerHookHandler, preSerializationHookHandler, onRequestHookHandler, preParsingHookHandler, onResponseHookHandler, onSendHookHandler, onErrorHookHandler, onTimeoutHookHandler } from './hooks'
|
|
8
8
|
import { FastifyError } from 'fastify-error'
|
|
9
9
|
import { FastifyContext } from './context'
|
|
@@ -20,6 +20,7 @@ export interface RouteShorthandOptions<
|
|
|
20
20
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
21
21
|
ContextConfig = ContextConfigDefault,
|
|
22
22
|
SchemaCompiler = FastifySchema,
|
|
23
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
23
24
|
> {
|
|
24
25
|
schema?: FastifySchema;
|
|
25
26
|
attachValidation?: boolean;
|
|
@@ -37,15 +38,15 @@ export interface RouteShorthandOptions<
|
|
|
37
38
|
schemaErrorFormatter?: (errors: FastifySchemaValidationError[], dataVar: string) => Error;
|
|
38
39
|
|
|
39
40
|
// hooks
|
|
40
|
-
onRequest?: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> | onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>[];
|
|
41
|
-
preParsing?: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> | preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>[];
|
|
42
|
-
preValidation?: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> | preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>[];
|
|
43
|
-
preHandler?: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> | preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>[];
|
|
44
|
-
preSerialization?: preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> | preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>[];
|
|
45
|
-
onSend?: onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> | onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>[];
|
|
46
|
-
onResponse?: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> | onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>[];
|
|
47
|
-
onTimeout?: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> | onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>[];
|
|
48
|
-
onError?: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> | onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>[];
|
|
41
|
+
onRequest?: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger> | onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger>[];
|
|
42
|
+
preParsing?: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger> | preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger>[];
|
|
43
|
+
preValidation?: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger> | preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger>[];
|
|
44
|
+
preHandler?: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger> | preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger>[];
|
|
45
|
+
preSerialization?: preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger> | preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger>[];
|
|
46
|
+
onSend?: onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger> | onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger>[];
|
|
47
|
+
onResponse?: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger> | onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger>[];
|
|
48
|
+
onTimeout?: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger> | onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger>[];
|
|
49
|
+
onError?: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, Logger> | onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, Logger>[];
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/**
|
|
@@ -56,10 +57,11 @@ export type RouteHandlerMethod<
|
|
|
56
57
|
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
57
58
|
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
58
59
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
59
|
-
ContextConfig = ContextConfigDefault
|
|
60
|
+
ContextConfig = ContextConfigDefault,
|
|
61
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
60
62
|
> = (
|
|
61
|
-
this: FastifyInstance<RawServer, RawRequest, RawReply>,
|
|
62
|
-
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, ContextConfig>,
|
|
63
|
+
this: FastifyInstance<RawServer, RawRequest, RawReply, Logger>,
|
|
64
|
+
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, ContextConfig, Logger>,
|
|
63
65
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
64
66
|
) => void | Promise<RouteGeneric['Reply'] | void>
|
|
65
67
|
|
|
@@ -73,8 +75,9 @@ export interface RouteShorthandOptionsWithHandler<
|
|
|
73
75
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
74
76
|
ContextConfig = ContextConfigDefault,
|
|
75
77
|
SchemaCompiler = FastifySchema,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
79
|
+
> extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, Logger> {
|
|
80
|
+
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger>;
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
/**
|
|
@@ -85,19 +88,19 @@ export interface RouteShorthandMethod<
|
|
|
85
88
|
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
86
89
|
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
87
90
|
> {
|
|
88
|
-
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema>(
|
|
91
|
+
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, Logger extends FastifyLoggerInstance = FastifyLoggerInstance>(
|
|
89
92
|
path: string,
|
|
90
|
-
opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler>,
|
|
91
|
-
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
92
|
-
): FastifyInstance<RawServer, RawRequest, RawReply>;
|
|
93
|
-
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault>(
|
|
93
|
+
opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, Logger>,
|
|
94
|
+
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger>
|
|
95
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
96
|
+
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, Logger extends FastifyLoggerInstance = FastifyLoggerInstance>(
|
|
94
97
|
path: string,
|
|
95
|
-
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
96
|
-
): FastifyInstance<RawServer, RawRequest, RawReply>;
|
|
97
|
-
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema>(
|
|
98
|
+
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger>
|
|
99
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
100
|
+
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, Logger extends FastifyLoggerInstance = FastifyLoggerInstance>(
|
|
98
101
|
path: string,
|
|
99
|
-
opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler>
|
|
100
|
-
): FastifyInstance<RawServer, RawRequest, RawReply>;
|
|
102
|
+
opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, Logger>
|
|
103
|
+
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
/**
|
|
@@ -110,10 +113,11 @@ export interface RouteOptions<
|
|
|
110
113
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
111
114
|
ContextConfig = ContextConfigDefault,
|
|
112
115
|
SchemaCompiler = FastifySchema,
|
|
113
|
-
|
|
116
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
117
|
+
> extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, Logger> {
|
|
114
118
|
method: HTTPMethods | HTTPMethods[];
|
|
115
119
|
url: string;
|
|
116
|
-
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>;
|
|
120
|
+
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, Logger>;
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
export type RouteHandler<
|
|
@@ -121,10 +125,11 @@ export type RouteHandler<
|
|
|
121
125
|
RawServer extends RawServerBase = RawServerDefault,
|
|
122
126
|
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
123
127
|
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
124
|
-
ContextConfig = ContextConfigDefault
|
|
128
|
+
ContextConfig = ContextConfigDefault,
|
|
129
|
+
Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
|
125
130
|
> = (
|
|
126
|
-
this: FastifyInstance<RawServer, RawRequest, RawReply>,
|
|
127
|
-
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
131
|
+
this: FastifyInstance<RawServer, RawRequest, RawReply, Logger>,
|
|
132
|
+
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, ContextConfig, Logger>,
|
|
128
133
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
129
134
|
) => void | Promise<RouteGeneric['Reply'] | void>
|
|
130
135
|
|