fastify 4.2.0 → 4.4.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 +13 -14
- package/docs/Guides/Database.md +2 -2
- package/docs/Guides/Ecosystem.md +42 -18
- package/docs/Guides/Migration-Guide-V4.md +29 -0
- package/docs/Guides/Plugins-Guide.md +5 -0
- package/docs/Reference/HTTP2.md +1 -3
- package/docs/Reference/Hooks.md +4 -1
- package/docs/Reference/Logging.md +1 -1
- package/docs/Reference/Reply.md +177 -0
- package/docs/Reference/Request.md +171 -0
- package/docs/Reference/Routes.md +4 -2
- package/docs/Reference/Server.md +4 -1
- package/docs/Reference/Type-Providers.md +1 -15
- package/docs/Reference/TypeScript.md +27 -3
- package/fastify.d.ts +1 -1
- package/fastify.js +3 -3
- package/lib/contentTypeParser.js +10 -2
- package/lib/context.js +10 -1
- package/lib/error-serializer.js +12 -12
- package/lib/errors.js +8 -0
- package/lib/handleRequest.js +2 -2
- package/lib/httpMethods.js +22 -0
- package/lib/reply.js +101 -24
- package/lib/request.js +97 -1
- package/lib/route.js +3 -1
- package/lib/symbols.js +15 -9
- package/package.json +7 -7
- package/test/build/error-serializer.test.js +3 -1
- package/test/content-parser.test.js +15 -0
- package/test/copy.test.js +41 -0
- package/test/internals/all.test.js +8 -2
- package/test/internals/reply-serialize.test.js +583 -0
- package/test/internals/reply.test.js +4 -1
- package/test/internals/request-validate.test.js +1269 -0
- package/test/internals/request.test.js +11 -2
- package/test/lock.test.js +73 -0
- package/test/mkcol.test.js +38 -0
- package/test/move.test.js +45 -0
- package/test/propfind.test.js +108 -0
- package/test/proppatch.test.js +78 -0
- package/test/request-error.test.js +44 -1
- package/test/schema-validation.test.js +71 -0
- package/test/search.test.js +100 -0
- package/test/trace.test.js +21 -0
- package/test/types/fastify.test-d.ts +12 -1
- package/test/types/hooks.test-d.ts +1 -2
- package/test/types/import.ts +1 -1
- package/test/types/instance.test-d.ts +4 -1
- package/test/types/logger.test-d.ts +4 -5
- package/test/types/reply.test-d.ts +44 -3
- package/test/types/request.test-d.ts +10 -29
- package/test/types/type-provider.test-d.ts +79 -7
- package/test/unlock.test.js +41 -0
- package/test/validation-error-handling.test.js +6 -1
- package/types/hooks.d.ts +19 -39
- package/types/instance.d.ts +78 -130
- package/types/logger.d.ts +7 -4
- package/types/reply.d.ts +7 -1
- package/types/request.d.ts +16 -3
- package/types/route.d.ts +23 -29
- package/types/schema.d.ts +4 -1
- package/types/type-provider.d.ts +8 -20
- package/types/utils.d.ts +2 -1
package/types/type-provider.d.ts
CHANGED
|
@@ -48,26 +48,18 @@ export interface FastifyRequestType<Params = unknown, Querystring = unknown, Hea
|
|
|
48
48
|
body: Body
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
>
|
|
51
|
+
// Resolves the FastifyRequest generic parameters
|
|
52
|
+
export interface ResolveFastifyRequestType<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema, RouteGeneric extends RouteGenericInterface> extends FastifyRequestType {
|
|
53
|
+
params: ResolveRequestParams<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
54
|
+
query: ResolveRequestQuerystring<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
55
|
+
headers: ResolveRequestHeaders<TypeProvider, SchemaCompiler, RouteGeneric>,
|
|
56
|
+
body: ResolveRequestBody<TypeProvider, SchemaCompiler, RouteGeneric>
|
|
57
|
+
}
|
|
57
58
|
|
|
58
59
|
// -----------------------------------------------------------------------------------------------
|
|
59
60
|
// FastifyReplyType
|
|
60
61
|
// -----------------------------------------------------------------------------------------------
|
|
61
62
|
|
|
62
|
-
// Tests if the user has specified a generic argument for Reply
|
|
63
|
-
type UseReplyFromRouteGeneric<RouteGeneric extends RouteGenericInterface> = keyof RouteGeneric['Reply'] extends never ? false : true
|
|
64
|
-
|
|
65
|
-
// Tests if the user has specified a response schema.
|
|
66
|
-
type UseReplyFromSchemaCompiler<SchemaCompiler extends FastifySchema> = keyof SchemaCompiler['response'] extends never ? false : true
|
|
67
|
-
|
|
68
|
-
// Resolves the Reply type from the generic argument
|
|
69
|
-
type ResolveReplyFromRouteGeneric<RouteGeneric extends RouteGenericInterface> = RouteGeneric['Reply']
|
|
70
|
-
|
|
71
63
|
// Resolves the Reply type by taking a union of response status codes
|
|
72
64
|
type ResolveReplyFromSchemaCompiler<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema> = {
|
|
73
65
|
[K in keyof SchemaCompiler['response']]: CallTypeProvider<TypeProvider, SchemaCompiler['response'][K]>
|
|
@@ -79,11 +71,7 @@ export type FastifyReplyType<Reply = unknown> = Reply
|
|
|
79
71
|
// Resolves the Reply type either via generic argument or from response schema. This type uses a different
|
|
80
72
|
// resolution strategy to Requests where the Reply will infer a union of each status code type specified
|
|
81
73
|
// by the user. The Reply can be explicitly overriden by users providing a generic Reply type on the route.
|
|
82
|
-
export type ResolveFastifyReplyType<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema, RouteGeneric extends RouteGenericInterface> =
|
|
83
|
-
UseReplyFromRouteGeneric<RouteGeneric> extends true ? ResolveReplyFromRouteGeneric<RouteGeneric> :
|
|
84
|
-
UseReplyFromSchemaCompiler<SchemaCompiler> extends true ? ResolveReplyFromSchemaCompiler<TypeProvider, SchemaCompiler> :
|
|
85
|
-
unknown
|
|
86
|
-
>
|
|
74
|
+
export type ResolveFastifyReplyType<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema, RouteGeneric extends RouteGenericInterface> = UndefinedToUnknown<KeysOf<RouteGeneric['Reply']> extends never ? ResolveReplyFromSchemaCompiler<TypeProvider, SchemaCompiler> : RouteGeneric['Reply']>
|
|
87
75
|
|
|
88
76
|
// -----------------------------------------------------------------------------------------------
|
|
89
77
|
// FastifyReplyReturnType
|
package/types/utils.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ import * as https from 'https'
|
|
|
5
5
|
/**
|
|
6
6
|
* Standard HTTP method strings
|
|
7
7
|
*/
|
|
8
|
-
export type HTTPMethods = 'DELETE' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'OPTIONS'
|
|
8
|
+
export type HTTPMethods = 'DELETE' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'OPTIONS' |
|
|
9
|
+
'PROPFIND' | 'PROPPATCH' | 'MKCOL' | 'COPY' | 'MOVE' | 'LOCK' | 'UNLOCK' | 'TRACE' | 'SEARCH'
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* A union type of the Node.js server types from the http, https, and http2 modules.
|