fastify 5.6.2 → 5.7.1
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 +34 -33
- package/SECURITY.md +45 -7
- package/SPONSORS.md +1 -1
- package/build/build-validation.js +1 -2
- package/build/sync-version.js +0 -1
- package/docs/Guides/Detecting-When-Clients-Abort.md +1 -1
- package/docs/Guides/Ecosystem.md +12 -15
- package/docs/Guides/Migration-Guide-V4.md +2 -1
- package/docs/Guides/Migration-Guide-V5.md +9 -0
- package/docs/Guides/Serverless.md +25 -7
- package/docs/Guides/Testing.md +2 -2
- package/docs/Reference/Decorators.md +4 -3
- package/docs/Reference/Encapsulation.md +2 -2
- package/docs/Reference/Logging.md +4 -0
- package/docs/Reference/Plugins.md +2 -2
- package/docs/Reference/Principles.md +2 -2
- package/docs/Reference/Reply.md +3 -2
- package/docs/Reference/Server.md +35 -4
- package/docs/Reference/TypeScript.md +2 -1
- package/docs/Reference/Validation-and-Serialization.md +7 -1
- package/examples/benchmark/webstream.js +27 -0
- package/fastify.d.ts +16 -21
- package/fastify.js +14 -9
- package/lib/config-validator.js +189 -223
- package/lib/error-handler.js +2 -5
- package/lib/error-status.js +14 -0
- package/lib/four-oh-four.js +2 -1
- package/lib/handle-request.js +6 -1
- package/lib/reply.js +53 -3
- package/lib/route.js +26 -12
- package/lib/schema-controller.js +2 -2
- package/lib/wrap-thenable.js +3 -0
- package/package.json +4 -4
- package/test/404s.test.js +69 -0
- package/test/diagnostics-channel/error-status.test.js +84 -0
- package/test/internals/schema-controller-perf.test.js +40 -0
- package/test/issue-4959.test.js +34 -9
- package/test/listen.1.test.js +9 -1
- package/test/logger/logging.test.js +38 -1
- package/test/router-options.test.js +169 -0
- package/test/server.test.js +4 -1
- package/test/types/fastify.test-d.ts +28 -7
- package/test/types/instance.test-d.ts +29 -21
- package/test/types/reply.test-d.ts +55 -4
- package/test/types/type-provider.test-d.ts +6 -6
- package/test/web-api.test.js +136 -0
- package/types/instance.d.ts +1 -1
- package/types/reply.d.ts +2 -2
- package/types/type-provider.d.ts +16 -0
- package/.vscode/settings.json +0 -22
- package/test/decorator-namespace.test._js_ +0 -30
package/types/instance.d.ts
CHANGED
|
@@ -595,7 +595,7 @@ export interface FastifyInstance<
|
|
|
595
595
|
https?: boolean | Readonly<{ allowHTTP1: boolean }>,
|
|
596
596
|
ignoreTrailingSlash?: boolean,
|
|
597
597
|
ignoreDuplicateSlashes?: boolean,
|
|
598
|
-
disableRequestLogging?: boolean,
|
|
598
|
+
disableRequestLogging?: boolean | ((req: FastifyRequest) => boolean),
|
|
599
599
|
maxParamLength?: number,
|
|
600
600
|
onProtoPoisoning?: ProtoAction,
|
|
601
601
|
onConstructorPoisoning?: ConstructorAction,
|
package/types/reply.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { FastifyBaseLogger } from './logger'
|
|
|
4
4
|
import { FastifyRequest, RequestRouteOptions } from './request'
|
|
5
5
|
import { RouteGenericInterface } from './route'
|
|
6
6
|
import { FastifySchema } from './schema'
|
|
7
|
-
import { CallSerializerTypeProvider, FastifyReplyType, FastifyTypeProvider, FastifyTypeProviderDefault, ResolveFastifyReplyType } from './type-provider'
|
|
7
|
+
import { CallSerializerTypeProvider, FastifyReplyType, FastifyTypeProvider, FastifyTypeProviderDefault, ResolveFastifyReplyType, SendArgs } from './type-provider'
|
|
8
8
|
import { CodeToReplyKey, ContextConfigDefault, HttpHeader, HttpKeys, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault, ReplyDefault, ReplyKeysToCodes } from './utils'
|
|
9
9
|
|
|
10
10
|
export interface ReplyGenericInterface {
|
|
@@ -50,7 +50,7 @@ export interface FastifyReply<
|
|
|
50
50
|
status<Code extends keyof SchemaCompiler['response'] extends never ? ReplyKeysToCodes<keyof RouteGeneric['Reply']> : keyof SchemaCompiler['response'] extends ReplyKeysToCodes<keyof RouteGeneric['Reply']> ? keyof SchemaCompiler['response'] : ReplyKeysToCodes<keyof RouteGeneric['Reply']>>(statusCode: Code): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider, ResolveReplyTypeWithRouteGeneric<RouteGeneric['Reply'], Code, SchemaCompiler, TypeProvider>>;
|
|
51
51
|
statusCode: number;
|
|
52
52
|
sent: boolean;
|
|
53
|
-
send(
|
|
53
|
+
send(...args: SendArgs<ReplyType>): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
|
|
54
54
|
header(key: HttpHeader, value: any): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
|
|
55
55
|
headers(values: Partial<Record<HttpHeader, number | string | string[] | undefined>>): FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>;
|
|
56
56
|
getHeader(key: HttpHeader): number | string | string[] | undefined;
|
package/types/type-provider.d.ts
CHANGED
|
@@ -112,3 +112,19 @@ RouteGeneric
|
|
|
112
112
|
* https://github.com/fastify/fastify/issues/5498
|
|
113
113
|
*/
|
|
114
114
|
export type SafePromiseLike<T> = PromiseLike<T> & { __linterBrands: 'SafePromiseLike' }
|
|
115
|
+
|
|
116
|
+
// -----------------------------------------------------------------------------------------------
|
|
117
|
+
// SendArgs
|
|
118
|
+
// -----------------------------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Determines whether the send() payload parameter should be required or optional.
|
|
122
|
+
* - When ReplyType is unknown (default/unspecified), payload is optional
|
|
123
|
+
* - When ReplyType is undefined or void, payload is optional (returning undefined is valid)
|
|
124
|
+
* - Otherwise, payload is required
|
|
125
|
+
*/
|
|
126
|
+
export type SendArgs<ReplyType> = unknown extends ReplyType
|
|
127
|
+
? [payload?: ReplyType]
|
|
128
|
+
: [ReplyType] extends [undefined | void]
|
|
129
|
+
? [payload?: ReplyType]
|
|
130
|
+
: [payload: ReplyType]
|
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
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
/* eslint no-prototype-builtins: 0 */
|
|
4
|
-
|
|
5
|
-
const { test } = require('node:test')
|
|
6
|
-
const Fastify = require('..')
|
|
7
|
-
const fp = require('fastify-plugin')
|
|
8
|
-
|
|
9
|
-
test('plugin namespace', async t => {
|
|
10
|
-
t.plan(2)
|
|
11
|
-
const app = Fastify()
|
|
12
|
-
|
|
13
|
-
await app.register(async function plugin (app, opts) {
|
|
14
|
-
app.decorate('utility', function () {
|
|
15
|
-
return 'utility'
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
app.get('/', function (req, reply) {
|
|
19
|
-
// ! here the plugin would use app.utility()
|
|
20
|
-
// ! the plugin does not know about the namespace
|
|
21
|
-
reply.send({ utility: app.utility() })
|
|
22
|
-
})
|
|
23
|
-
}, { namespace: 'foo' })
|
|
24
|
-
|
|
25
|
-
// ! but outside the plugin the decorator would be app.foo.utility()
|
|
26
|
-
t.assert.ok(app.foo.utility)
|
|
27
|
-
|
|
28
|
-
const res = await app.inject('/')
|
|
29
|
-
t.assert.deepStrictEqual(res.json(), { utility: 'utility' })
|
|
30
|
-
})
|