fastify 5.5.0 → 5.6.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/Routes.md +1 -2
- package/docs/Reference/TypeScript.md +2 -2
- package/fastify.d.ts +17 -0
- package/fastify.js +1 -1
- package/package.json +1 -1
- package/test/types/instance.test-d.ts +18 -1
- package/types/instance.d.ts +2 -0
- package/types/logger.d.ts +16 -14
- package/.vscode/settings.json +0 -22
package/docs/Reference/Routes.md
CHANGED
|
@@ -636,8 +636,7 @@ has a version set, and will prefer a versioned route to a non-versioned route
|
|
|
636
636
|
for the same path. Advanced version ranges and pre-releases currently are not
|
|
637
637
|
supported.
|
|
638
638
|
|
|
639
|
-
|
|
640
|
-
performances of the router.*
|
|
639
|
+
> **Note:** using this feature can degrade the router’s performance.
|
|
641
640
|
|
|
642
641
|
```js
|
|
643
642
|
fastify.route({
|
|
@@ -147,7 +147,7 @@ route-level `request` object.
|
|
|
147
147
|
reply.code(200).send('uh-oh');
|
|
148
148
|
// it even works for wildcards
|
|
149
149
|
reply.code(404).send({ error: 'Not found' });
|
|
150
|
-
return
|
|
150
|
+
return { success: true }
|
|
151
151
|
})
|
|
152
152
|
```
|
|
153
153
|
|
|
@@ -173,7 +173,7 @@ route-level `request` object.
|
|
|
173
173
|
}, async (request, reply) => {
|
|
174
174
|
const customerHeader = request.headers['h-Custom']
|
|
175
175
|
// do something with request data
|
|
176
|
-
return
|
|
176
|
+
return { success: true }
|
|
177
177
|
})
|
|
178
178
|
```
|
|
179
179
|
7. Build and run and query with the `username` query string option set to
|
package/fastify.d.ts
CHANGED
|
@@ -89,6 +89,22 @@ declare namespace fastify {
|
|
|
89
89
|
|
|
90
90
|
type TrustProxyFunction = (address: string, hop: number) => boolean
|
|
91
91
|
|
|
92
|
+
export type FastifyRouterOptions<RawServer extends RawServerBase> = {
|
|
93
|
+
allowUnsafeRegex?: boolean,
|
|
94
|
+
buildPrettyMeta?: (route: { [k: string]: unknown, store: { [k: string]: unknown } }) => object,
|
|
95
|
+
caseSensitive?: boolean,
|
|
96
|
+
constraints?: {
|
|
97
|
+
[name: string]: ConstraintStrategy<FindMyWayVersion<RawServer>, unknown>,
|
|
98
|
+
},
|
|
99
|
+
defaultRoute?: (req: FastifyRequest, res: FastifyReply) => void,
|
|
100
|
+
ignoreDuplicateSlashes?: boolean,
|
|
101
|
+
ignoreTrailingSlash?: boolean,
|
|
102
|
+
maxParamLength?: number,
|
|
103
|
+
onBadUrl?: (path: string, req: FastifyRequest, res: FastifyReply) => void,
|
|
104
|
+
querystringParser?: (str: string) => { [key: string]: unknown },
|
|
105
|
+
useSemicolonDelimiter?: boolean,
|
|
106
|
+
}
|
|
107
|
+
|
|
92
108
|
/**
|
|
93
109
|
* Options for a fastify server instance. Utilizes conditional logic on the generic server parameter to enforce certain https and http2
|
|
94
110
|
*/
|
|
@@ -159,6 +175,7 @@ declare namespace fastify {
|
|
|
159
175
|
clientErrorHandler?: (error: ConnectionError, socket: Socket) => void,
|
|
160
176
|
childLoggerFactory?: FastifyChildLoggerFactory,
|
|
161
177
|
allowErrorHandlerOverride?: boolean
|
|
178
|
+
routerOptions?: FastifyRouterOptions<RawServer>,
|
|
162
179
|
}
|
|
163
180
|
|
|
164
181
|
/**
|
package/fastify.js
CHANGED
package/package.json
CHANGED
|
@@ -15,6 +15,8 @@ import { FastifyRequest } from '../../types/request'
|
|
|
15
15
|
import { FastifySchemaControllerOptions, FastifySchemaCompiler, FastifySerializerCompiler } from '../../types/schema'
|
|
16
16
|
import { AddressInfo } from 'node:net'
|
|
17
17
|
import { Bindings, ChildLoggerOptions } from '../../types/logger'
|
|
18
|
+
import { ConstraintStrategy } from 'find-my-way'
|
|
19
|
+
import { FindMyWayVersion } from '../../types/instance'
|
|
18
20
|
|
|
19
21
|
const server = fastify()
|
|
20
22
|
|
|
@@ -309,7 +311,22 @@ type InitialConfig = Readonly<{
|
|
|
309
311
|
requestIdHeader?: string | false,
|
|
310
312
|
requestIdLogLabel?: string,
|
|
311
313
|
http2SessionTimeout?: number,
|
|
312
|
-
useSemicolonDelimiter?: boolean
|
|
314
|
+
useSemicolonDelimiter?: boolean,
|
|
315
|
+
routerOptions?: {
|
|
316
|
+
allowUnsafeRegex?: boolean,
|
|
317
|
+
buildPrettyMeta?: (route: { [k: string]: unknown, store: { [k: string]: unknown } }) => object,
|
|
318
|
+
caseSensitive?: boolean,
|
|
319
|
+
constraints?: {
|
|
320
|
+
[name: string]: ConstraintStrategy<FindMyWayVersion<RawServerDefault>, unknown>
|
|
321
|
+
}
|
|
322
|
+
defaultRoute?: (req: FastifyRequest, res: FastifyReply) => void,
|
|
323
|
+
ignoreDuplicateSlashes?: boolean,
|
|
324
|
+
ignoreTrailingSlash?: boolean,
|
|
325
|
+
maxParamLength?: number,
|
|
326
|
+
onBadUrl?: (path: string, req: FastifyRequest, res: FastifyReply) => void,
|
|
327
|
+
querystringParser?: (str: string) => { [key: string]: unknown },
|
|
328
|
+
useSemicolonDelimiter?: boolean,
|
|
329
|
+
}
|
|
313
330
|
}>
|
|
314
331
|
|
|
315
332
|
expectType<InitialConfig>(fastify().initialConfig)
|
package/types/instance.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
SafePromiseLike
|
|
24
24
|
} from './type-provider'
|
|
25
25
|
import { ContextConfigDefault, HTTPMethods, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault } from './utils'
|
|
26
|
+
import { FastifyRouterOptions } from '../fastify'
|
|
26
27
|
|
|
27
28
|
export interface PrintRoutesOptions {
|
|
28
29
|
method?: HTTPMethods;
|
|
@@ -603,5 +604,6 @@ export interface FastifyInstance<
|
|
|
603
604
|
requestIdLogLabel?: string,
|
|
604
605
|
http2SessionTimeout?: number,
|
|
605
606
|
useSemicolonDelimiter?: boolean,
|
|
607
|
+
routerOptions?: FastifyRouterOptions<RawServer>
|
|
606
608
|
}>
|
|
607
609
|
}
|
package/types/logger.d.ts
CHANGED
|
@@ -7,20 +7,24 @@ import { FastifySchema } from './schema'
|
|
|
7
7
|
import { FastifyTypeProvider, FastifyTypeProviderDefault } from './type-provider'
|
|
8
8
|
import { ContextConfigDefault, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault } from './utils'
|
|
9
9
|
|
|
10
|
-
import
|
|
10
|
+
import type {
|
|
11
|
+
BaseLogger,
|
|
12
|
+
LogFn as FastifyLogFn,
|
|
13
|
+
LevelWithSilent as LogLevel,
|
|
14
|
+
Bindings,
|
|
15
|
+
ChildLoggerOptions,
|
|
16
|
+
LoggerOptions as PinoLoggerOptions
|
|
17
|
+
} from 'pino'
|
|
11
18
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export type Bindings = pino.Bindings
|
|
20
|
-
|
|
21
|
-
export type ChildLoggerOptions = pino.ChildLoggerOptions
|
|
19
|
+
export type {
|
|
20
|
+
FastifyLogFn,
|
|
21
|
+
LogLevel,
|
|
22
|
+
Bindings,
|
|
23
|
+
ChildLoggerOptions,
|
|
24
|
+
PinoLoggerOptions
|
|
25
|
+
}
|
|
22
26
|
|
|
23
|
-
export interface FastifyBaseLogger extends
|
|
27
|
+
export interface FastifyBaseLogger extends Pick<BaseLogger, 'level' | 'info' | 'error' | 'debug' | 'fatal' | 'warn' | 'trace' | 'silent'> {
|
|
24
28
|
child(bindings: Bindings, options?: ChildLoggerOptions): FastifyBaseLogger
|
|
25
29
|
}
|
|
26
30
|
|
|
@@ -34,8 +38,6 @@ export interface FastifyLoggerStreamDestination {
|
|
|
34
38
|
write(msg: string): void;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
export type PinoLoggerOptions = pino.LoggerOptions
|
|
38
|
-
|
|
39
41
|
// TODO: once node 18 is EOL, this type can be replaced with plain FastifyReply.
|
|
40
42
|
/**
|
|
41
43
|
* Specialized reply type used for the `res` log serializer, since only `statusCode` is passed in certain cases.
|
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
|
-
}
|