fastify 3.5.0 → 3.8.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/ContentTypeParser.md +3 -0
- package/docs/Ecosystem.md +7 -2
- package/docs/Hooks.md +0 -5
- package/docs/Lifecycle.md +2 -2
- package/docs/Logging.md +1 -1
- package/docs/Recommendations.md +17 -0
- package/docs/Reply.md +2 -2
- package/docs/Request.md +4 -2
- package/docs/Routes.md +21 -3
- package/docs/Server.md +51 -3
- package/docs/Style-Guide.md +180 -0
- package/docs/TypeScript.md +359 -359
- package/docs/Validation-and-Serialization.md +11 -5
- package/examples/parser.js +1 -1
- package/fastify.d.ts +2 -2
- package/fastify.js +39 -7
- package/lib/contentTypeParser.js +16 -11
- package/lib/context.js +5 -19
- package/lib/decorate.js +1 -1
- package/lib/errors.js +2 -2
- package/lib/fourOhFour.js +8 -7
- package/lib/handleRequest.js +5 -5
- package/lib/hooks.js +4 -4
- package/lib/logger.js +7 -7
- package/lib/pluginUtils.js +4 -2
- package/lib/reply.js +27 -24
- package/lib/reqIdGenFactory.js +2 -2
- package/lib/request.js +20 -8
- package/lib/route.js +12 -10
- package/lib/schemas.js +1 -1
- package/lib/server.js +5 -5
- package/lib/symbols.js +2 -1
- package/lib/validation.js +9 -8
- package/lib/warnings.js +3 -0
- package/lib/wrapThenable.js +2 -2
- package/package.json +10 -10
- package/test/404s.test.js +15 -15
- package/test/async-await.test.js +7 -7
- package/test/custom-parser-async.test.js +2 -2
- package/test/custom-parser.test.js +38 -8
- package/test/emit-warning.test.js +31 -0
- package/test/fastify-instance.test.js +33 -1
- package/test/helper.js +1 -1
- package/test/hooks.test.js +6 -6
- 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 +1 -1
- package/test/https/https.test.js +2 -1
- package/test/inject.test.js +2 -2
- package/test/internals/all.test.js +1 -1
- package/test/internals/hookRunner.test.js +1 -1
- package/test/internals/logger.test.js +1 -1
- package/test/internals/reply.test.js +62 -7
- package/test/internals/request.test.js +31 -5
- package/test/internals/version.test.js +43 -0
- package/test/listen.test.js +12 -0
- package/test/logger.test.js +11 -11
- package/test/nullable-validation.test.js +108 -0
- package/test/pretty-print.test.js +9 -14
- package/test/reply-error.test.js +2 -2
- package/test/request-error.test.js +81 -0
- package/test/route-hooks.test.js +10 -10
- package/test/stream.test.js +11 -11
- package/test/types/fastify.test-d.ts +1 -2
- package/test/types/instance.test-d.ts +17 -3
- package/test/types/logger.test-d.ts +35 -2
- package/test/types/register.test-d.ts +16 -0
- package/test/types/request.test-d.ts +1 -1
- package/test/types/route.test-d.ts +5 -0
- package/test/validation-error-handling.test.js +66 -0
- package/test/versioned-routes.test.js +55 -0
- package/types/.eslintrc.json +4 -1
- package/types/content-type-parser.d.ts +0 -15
- package/types/hooks.d.ts +138 -16
- package/types/instance.d.ts +86 -14
- package/types/logger.d.ts +13 -11
- package/types/plugin.d.ts +5 -7
- package/types/register.d.ts +8 -7
- package/types/request.d.ts +3 -1
- package/types/route.d.ts +38 -58
- package/types/schema.d.ts +4 -4
- package/types/serverFactory.d.ts +9 -9
package/types/route.d.ts
CHANGED
|
@@ -9,49 +9,6 @@ import { FastifyError } from 'fastify-error'
|
|
|
9
9
|
|
|
10
10
|
export interface RouteGenericInterface extends RequestGenericInterface, ReplyGenericInterface {}
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* Fastify Router Shorthand method type that is similar to the Express/Restify approach
|
|
14
|
-
*/
|
|
15
|
-
export interface RouteShorthandMethod<
|
|
16
|
-
RawServer extends RawServerBase = RawServerDefault,
|
|
17
|
-
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
18
|
-
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
19
|
-
> {
|
|
20
|
-
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault>(
|
|
21
|
-
path: string,
|
|
22
|
-
opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
23
|
-
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
24
|
-
): FastifyInstance<RawServer, RawRequest, RawReply>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Fastify Router Shorthand method type that is similar to the Express/Restify approach
|
|
29
|
-
*/
|
|
30
|
-
export interface RouteShorthandMethod<
|
|
31
|
-
RawServer extends RawServerBase = RawServerDefault,
|
|
32
|
-
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
33
|
-
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
34
|
-
> {
|
|
35
|
-
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault>(
|
|
36
|
-
path: string,
|
|
37
|
-
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
38
|
-
): FastifyInstance<RawServer, RawRequest, RawReply>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Fastify Router Shorthand method type that is similar to the Express/Restify approach
|
|
43
|
-
*/
|
|
44
|
-
export interface RouteShorthandMethod<
|
|
45
|
-
RawServer extends RawServerBase = RawServerDefault,
|
|
46
|
-
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
47
|
-
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
48
|
-
> {
|
|
49
|
-
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault>(
|
|
50
|
-
path: string,
|
|
51
|
-
opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
52
|
-
): FastifyInstance<RawServer, RawRequest, RawReply>;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
12
|
/**
|
|
56
13
|
* Route shorthand options for the various shorthand methods
|
|
57
14
|
*/
|
|
@@ -70,7 +27,7 @@ export interface RouteShorthandOptions<
|
|
|
70
27
|
logLevel?: LogLevel;
|
|
71
28
|
config?: ContextConfig;
|
|
72
29
|
version?: string;
|
|
73
|
-
prefixTrailingSlash?:
|
|
30
|
+
prefixTrailingSlash?: 'slash'|'no-slash'|'both';
|
|
74
31
|
errorHandler?: (this: FastifyInstance, error: FastifyError, request: FastifyRequest, reply: FastifyReply) => void;
|
|
75
32
|
// TODO: Change to actual type.
|
|
76
33
|
schemaErrorFormatter?: (errors: FastifySchemaValidationError[], dataVar: string) => Error;
|
|
@@ -88,19 +45,19 @@ export interface RouteShorthandOptions<
|
|
|
88
45
|
}
|
|
89
46
|
|
|
90
47
|
/**
|
|
91
|
-
*
|
|
48
|
+
* Route handler method declaration.
|
|
92
49
|
*/
|
|
93
|
-
export
|
|
50
|
+
export type RouteHandlerMethod<
|
|
94
51
|
RawServer extends RawServerBase = RawServerDefault,
|
|
95
52
|
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
96
53
|
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
97
54
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
98
55
|
ContextConfig = ContextConfigDefault
|
|
99
|
-
>
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
56
|
+
> = (
|
|
57
|
+
this: FastifyInstance<RawServer, RawRequest, RawReply>,
|
|
58
|
+
request: FastifyRequest<RouteGeneric, RawServer, RawRequest>,
|
|
59
|
+
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
60
|
+
) => void | Promise<RouteGeneric['Reply'] | void>
|
|
104
61
|
|
|
105
62
|
/**
|
|
106
63
|
* Shorthand options including the handler function property
|
|
@@ -116,19 +73,42 @@ export interface RouteShorthandOptionsWithHandler<
|
|
|
116
73
|
}
|
|
117
74
|
|
|
118
75
|
/**
|
|
119
|
-
*
|
|
76
|
+
* Fastify Router Shorthand method type that is similar to the Express/Restify approach
|
|
120
77
|
*/
|
|
121
|
-
export
|
|
78
|
+
export interface RouteShorthandMethod<
|
|
79
|
+
RawServer extends RawServerBase = RawServerDefault,
|
|
80
|
+
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
81
|
+
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
82
|
+
> {
|
|
83
|
+
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault>(
|
|
84
|
+
path: string,
|
|
85
|
+
opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>,
|
|
86
|
+
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
87
|
+
): FastifyInstance<RawServer, RawRequest, RawReply>;
|
|
88
|
+
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault>(
|
|
89
|
+
path: string,
|
|
90
|
+
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
91
|
+
): FastifyInstance<RawServer, RawRequest, RawReply>;
|
|
92
|
+
<RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault>(
|
|
93
|
+
path: string,
|
|
94
|
+
opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>
|
|
95
|
+
): FastifyInstance<RawServer, RawRequest, RawReply>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Fastify route method options.
|
|
100
|
+
*/
|
|
101
|
+
export interface RouteOptions<
|
|
122
102
|
RawServer extends RawServerBase = RawServerDefault,
|
|
123
103
|
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
124
104
|
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
|
|
125
105
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
|
126
106
|
ContextConfig = ContextConfigDefault
|
|
127
|
-
>
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
107
|
+
> extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig> {
|
|
108
|
+
method: HTTPMethods | HTTPMethods[];
|
|
109
|
+
url: string;
|
|
110
|
+
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig>;
|
|
111
|
+
}
|
|
132
112
|
|
|
133
113
|
export type RouteHandler<
|
|
134
114
|
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
package/types/schema.d.ts
CHANGED
|
@@ -20,15 +20,15 @@ export interface FastifyRouteSchemaDef {
|
|
|
20
20
|
httpStatus?: string;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export interface FastifyValidationResult {
|
|
24
|
-
errors?: FastifySchemaValidationError[] | null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
23
|
export interface FastifySchemaValidationError {
|
|
28
24
|
message?: string;
|
|
29
25
|
dataPath: string;
|
|
30
26
|
}
|
|
31
27
|
|
|
28
|
+
export interface FastifyValidationResult {
|
|
29
|
+
errors?: FastifySchemaValidationError[] | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
32
|
/**
|
|
33
33
|
* Compiler for FastifySchema Type
|
|
34
34
|
*/
|
package/types/serverFactory.d.ts
CHANGED
|
@@ -3,17 +3,17 @@ import * as http from 'http'
|
|
|
3
3
|
import * as https from 'https'
|
|
4
4
|
import * as http2 from 'http2'
|
|
5
5
|
|
|
6
|
-
export interface FastifyServerFactory<
|
|
7
|
-
RawServer extends RawServerBase = RawServerDefault
|
|
8
|
-
> {
|
|
9
|
-
(handler: FastifyServerFactoryHandler<RawServer>, opts: object): RawServer;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
6
|
export type FastifyServerFactoryHandler<
|
|
13
7
|
RawServer extends RawServerBase = RawServerDefault,
|
|
14
8
|
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
|
15
9
|
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>
|
|
16
10
|
> =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
RawServer extends http.Server | https.Server ?
|
|
12
|
+
(request: http.IncomingMessage & RawRequest, response: http.ServerResponse & RawReply) => void :
|
|
13
|
+
(request: http2.Http2ServerRequest & RawRequest, response: http2.Http2ServerResponse & RawReply) => void
|
|
14
|
+
|
|
15
|
+
export interface FastifyServerFactory<
|
|
16
|
+
RawServer extends RawServerBase = RawServerDefault
|
|
17
|
+
> {
|
|
18
|
+
(handler: FastifyServerFactoryHandler<RawServer>, opts: Record<string, unknown>): RawServer;
|
|
19
|
+
}
|