fastify 5.2.2 → 5.3.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/SPONSORS.md +0 -1
- package/docs/Guides/Ecosystem.md +2 -0
- package/docs/Reference/Decorators.md +199 -0
- package/docs/Reference/Errors.md +2 -0
- package/fastify.js +3 -2
- package/lib/decorate.js +18 -3
- package/lib/errors.js +4 -0
- package/lib/reply.js +17 -2
- package/lib/request.js +28 -2
- package/package.json +3 -3
- package/test/build/error-serializer.test.js +1 -2
- package/test/custom-parser.4.test.js +55 -38
- package/test/decorator.test.js +174 -4
- package/test/fastify-instance.test.js +12 -2
- package/test/hooks.on-listen.test.js +17 -14
- package/test/internals/errors.test.js +14 -1
- package/test/listen.2.test.js +4 -1
- package/test/server.test.js +175 -0
- package/test/types/instance.test-d.ts +3 -0
- package/test/types/reply.test-d.ts +1 -0
- package/test/types/request.test-d.ts +4 -0
- package/test/types/type-provider.test-d.ts +40 -0
- package/test/upgrade.test.js +3 -6
- package/types/instance.d.ts +2 -0
- package/types/reply.d.ts +1 -0
- package/types/request.d.ts +2 -0
- package/types/type-provider.d.ts +12 -3
- package/.vscode/settings.json +0 -22
package/test/upgrade.test.js
CHANGED
|
@@ -6,14 +6,11 @@ const { connect } = require('node:net')
|
|
|
6
6
|
const { once } = require('node:events')
|
|
7
7
|
const dns = require('node:dns').promises
|
|
8
8
|
|
|
9
|
-
describe('upgrade to both servers', async
|
|
9
|
+
describe('upgrade to both servers', async () => {
|
|
10
10
|
const localAddresses = await dns.lookup('localhost', { all: true })
|
|
11
|
-
|
|
12
|
-
t.skip('requires both IPv4 and IPv6')
|
|
13
|
-
return
|
|
14
|
-
}
|
|
11
|
+
const skip = localAddresses.length === 1 && 'requires both IPv4 and IPv6'
|
|
15
12
|
|
|
16
|
-
await test('upgrade IPv4 and IPv6', async t => {
|
|
13
|
+
await test('upgrade IPv4 and IPv6', { skip }, async t => {
|
|
17
14
|
t.plan(2)
|
|
18
15
|
|
|
19
16
|
const fastify = Fastify()
|
package/types/instance.d.ts
CHANGED
|
@@ -152,6 +152,8 @@ export interface FastifyInstance<
|
|
|
152
152
|
decorateRequest: DecorationMethod<FastifyRequest, FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>>;
|
|
153
153
|
decorateReply: DecorationMethod<FastifyReply, FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>>;
|
|
154
154
|
|
|
155
|
+
getDecorator<T>(name: string | symbol): T;
|
|
156
|
+
|
|
155
157
|
hasDecorator(decorator: string | symbol): boolean;
|
|
156
158
|
hasRequestDecorator(decorator: string | symbol): boolean;
|
|
157
159
|
hasReplyDecorator(decorator: string | symbol): boolean;
|
package/types/reply.d.ts
CHANGED
|
@@ -77,4 +77,5 @@ export interface FastifyReply<
|
|
|
77
77
|
) => FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
|
|
78
78
|
hasTrailer(key: string): boolean;
|
|
79
79
|
removeTrailer(key: string): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
|
|
80
|
+
getDecorator<T>(name: string | symbol): T;
|
|
80
81
|
}
|
package/types/request.d.ts
CHANGED
|
@@ -87,4 +87,6 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
|
|
|
87
87
|
compileValidationSchema(schema: { [key: string]: any }, httpPart?: HTTPRequestPart): ValidationFunction
|
|
88
88
|
validateInput(input: any, schema: { [key: string]: any }, httpPart?: HTTPRequestPart): boolean
|
|
89
89
|
validateInput(input: any, httpPart?: HTTPRequestPart): boolean
|
|
90
|
+
getDecorator<T>(name: string | symbol): T;
|
|
91
|
+
setDecorator<T = unknown>(name: string | symbol, value: T): void;
|
|
90
92
|
}
|
package/types/type-provider.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RouteGenericInterface } from './route'
|
|
2
2
|
import { FastifySchema } from './schema'
|
|
3
|
-
import { RecordKeysToLowercase } from './utils'
|
|
3
|
+
import { HttpKeys, RecordKeysToLowercase } from './utils'
|
|
4
4
|
|
|
5
5
|
// -----------------------------------------------------------------------------------------------
|
|
6
6
|
// TypeProvider
|
|
@@ -80,6 +80,11 @@ export type ResolveFastifyReplyType<TypeProvider extends FastifyTypeProvider, Sc
|
|
|
80
80
|
// FastifyReplyReturnType
|
|
81
81
|
// -----------------------------------------------------------------------------------------------
|
|
82
82
|
|
|
83
|
+
// Resolves the Reply return type by taking a union of response status codes in the generic argument
|
|
84
|
+
type ResolveReplyReturnTypeFromRouteGeneric<RouteGeneric extends RouteGenericInterface> = RouteGeneric extends { Reply: infer Return }
|
|
85
|
+
? keyof Return extends HttpKeys ? Return[keyof Return] | Return : Return
|
|
86
|
+
: unknown
|
|
87
|
+
|
|
83
88
|
// The target reply return type. This type is inferenced on fastify 'routes' via generic argument assignment
|
|
84
89
|
export type ResolveFastifyReplyReturnType<
|
|
85
90
|
TypeProvider extends FastifyTypeProvider,
|
|
@@ -89,8 +94,12 @@ export type ResolveFastifyReplyReturnType<
|
|
|
89
94
|
TypeProvider,
|
|
90
95
|
SchemaCompiler,
|
|
91
96
|
RouteGeneric
|
|
92
|
-
> extends infer
|
|
93
|
-
|
|
97
|
+
> extends infer ReplyType
|
|
98
|
+
? RouteGeneric['Reply'] extends ReplyType
|
|
99
|
+
? ResolveReplyReturnTypeFromRouteGeneric<RouteGeneric> extends infer Return
|
|
100
|
+
? Return | void | Promise<Return | void>
|
|
101
|
+
: unknown
|
|
102
|
+
: ReplyType | void | Promise<ReplyType | void>
|
|
94
103
|
// review: support both async and sync return types
|
|
95
104
|
// (Promise<Return> | Return | Promise<void> | void)
|
|
96
105
|
: unknown
|
package/.vscode/settings.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"workbench.colorCustomizations": {
|
|
3
|
-
"[GitHub Dark]": {
|
|
4
|
-
"tab.activeBackground": "#0d0d0d",
|
|
5
|
-
"tab.activeBorder": "#ffff00"
|
|
6
|
-
},
|
|
7
|
-
"activityBar.background": "#FBE7B2",
|
|
8
|
-
"activityBar.foreground": "#52358C",
|
|
9
|
-
"activityBar.inactiveForeground": "#616161",
|
|
10
|
-
"activityBar.activeBorder": "#04184d",
|
|
11
|
-
"activityBar.activeBackground": "#C3B48B",
|
|
12
|
-
"activityBar.border": "#C3B48B",
|
|
13
|
-
"titleBar.activeBackground": "#D2BE88",
|
|
14
|
-
"titleBar.activeForeground": "#52358C",
|
|
15
|
-
"titleBar.inactiveBackground": "#bdb59c",
|
|
16
|
-
"titleBar.inactiveForeground": "#616161",
|
|
17
|
-
"titleBar.border": "#C3B48B",
|
|
18
|
-
"statusBar.background": "#E9DBB7",
|
|
19
|
-
"statusBar.foreground": "#52358C",
|
|
20
|
-
"statusBar.border": "#C3B48B"
|
|
21
|
-
}
|
|
22
|
-
}
|