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.
@@ -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 t => {
9
+ describe('upgrade to both servers', async () => {
10
10
  const localAddresses = await dns.lookup('localhost', { all: true })
11
- if (localAddresses.length === 1) {
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()
@@ -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
  }
@@ -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
  }
@@ -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 Return ?
93
- (Return | void | Promise<Return | void>)
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
@@ -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
- }