fastify 5.1.0 → 5.2.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 +54 -50
- package/build/build-validation.js +1 -1
- package/docs/Guides/Database.md +15 -15
- package/docs/Guides/Detecting-When-Clients-Abort.md +28 -28
- package/docs/Guides/Ecosystem.md +13 -7
- package/docs/Guides/Index.md +1 -1
- package/docs/Guides/Migration-Guide-V4.md +11 -11
- package/docs/Guides/Migration-Guide-V5.md +5 -5
- package/docs/Guides/Plugins-Guide.md +1 -1
- package/docs/Guides/Prototype-Poisoning.md +3 -3
- package/docs/Guides/Recommendations.md +9 -9
- package/docs/Guides/Serverless.md +5 -5
- package/docs/Guides/Testing.md +8 -8
- package/docs/Guides/Write-Plugin.md +1 -1
- package/docs/Guides/Write-Type-Provider.md +3 -3
- package/docs/Reference/Decorators.md +2 -2
- package/docs/Reference/Errors.md +4 -2
- package/docs/Reference/Hooks.md +7 -7
- package/docs/Reference/LTS.md +8 -0
- package/docs/Reference/Logging.md +5 -4
- package/docs/Reference/Reply.md +54 -53
- package/docs/Reference/Request.md +49 -44
- package/docs/Reference/Routes.md +7 -7
- package/docs/Reference/Server.md +32 -28
- package/docs/Reference/TypeScript.md +9 -9
- package/docs/Reference/Validation-and-Serialization.md +5 -5
- package/examples/typescript-server.ts +1 -1
- package/fastify.d.ts +4 -4
- package/fastify.js +1 -1
- package/lib/error-handler.js +9 -9
- package/lib/errors.js +5 -1
- package/lib/hooks.js +4 -1
- package/lib/reply.js +4 -0
- package/lib/request.js +16 -11
- package/package.json +21 -11
- package/test/{allowUnsafeRegex.test.js → allow-unsafe-regex.test.js} +4 -4
- package/test/async-dispose.test.js +0 -1
- package/test/async_hooks.test.js +4 -4
- package/test/buffer.test.js +4 -4
- package/test/build-certificate.js +1 -1
- package/test/bundler/README.md +5 -5
- package/test/case-insensitive.test.js +10 -10
- package/test/check.test.js +2 -3
- package/test/{childLoggerFactory.test.js → child-logger-factory.test.js} +1 -1
- package/test/client-timeout.test.js +1 -1
- package/test/close-pipelining.test.js +0 -1
- package/test/conditional-pino.test.js +3 -3
- package/test/content-length.test.js +53 -68
- package/test/content-parser.test.js +178 -167
- package/test/content-type.test.js +8 -9
- package/test/context-config.test.js +44 -54
- package/test/custom-parser.2.test.js +19 -20
- package/test/custom-parser.3.test.js +56 -45
- package/test/custom-parser.5.test.js +32 -32
- package/test/delete.test.js +79 -67
- package/test/encapsulated-child-logger-factory.test.js +8 -8
- package/test/encapsulated-error-handler.test.js +20 -20
- package/test/fastify-instance.test.js +33 -34
- package/test/{findRoute.test.js → find-route.test.js} +11 -10
- package/test/fluent-schema.test.js +33 -36
- package/test/handler-context.test.js +11 -11
- package/test/has-route.test.js +12 -15
- package/test/header-overflow.test.js +13 -12
- package/test/hooks.on-ready.test.js +2 -2
- package/test/hooks.test.js +19 -19
- package/test/http-methods/head.test.js +0 -3
- package/test/imports.test.js +2 -2
- package/test/internals/errors.test.js +20 -8
- package/test/listen.5.test.js +9 -9
- package/test/{maxRequestsPerSocket.test.js → max-requests-per-socket.test.js} +30 -30
- package/test/middleware.test.js +4 -5
- package/test/noop-set.test.js +1 -1
- package/test/nullable-validation.test.js +30 -27
- package/test/post-empty-body.test.js +18 -11
- package/test/pretty-print.test.js +59 -49
- package/test/proto-poisoning.test.js +42 -37
- package/test/reply-code.test.js +34 -32
- package/test/{reply-earlyHints.test.js → reply-early-hints.test.js} +21 -19
- package/test/request-header-host.test.js +154 -12
- package/test/request-id.test.js +31 -25
- package/test/{requestTimeout.test.js → request-timeout.test.js} +11 -11
- package/test/route.3.test.js +3 -2
- package/test/route.8.test.js +20 -20
- package/test/router-options.test.js +80 -77
- package/test/schema-examples.test.js +72 -38
- package/test/server.test.js +12 -12
- package/test/set-error-handler.test.js +2 -3
- package/test/stream-serializers.test.js +10 -7
- package/test/sync-routes.test.js +18 -18
- package/test/trust-proxy.test.js +51 -45
- package/test/type-provider.test.js +8 -6
- package/test/types/content-type-parser.test-d.ts +1 -1
- package/test/types/fastify.test-d.ts +4 -4
- package/test/types/instance.test-d.ts +3 -1
- package/test/types/logger.test-d.ts +2 -2
- package/test/types/plugin.test-d.ts +2 -2
- package/test/types/register.test-d.ts +2 -2
- package/test/types/reply.test-d.ts +1 -1
- package/test/types/route.test-d.ts +1 -1
- package/test/types/serverFactory.test-d.ts +1 -1
- package/test/types/type-provider.test-d.ts +1 -1
- package/test/url-rewriting.test.js +35 -38
- package/test/{useSemicolonDelimiter.test.js → use-semicolon-delimiter.test.js} +30 -30
- package/test/validation-error-handling.test.js +259 -285
- package/test/web-api.test.js +44 -0
- package/types/hooks.d.ts +1 -1
- package/types/instance.d.ts +9 -2
- package/types/reply.d.ts +1 -1
- package/types/request.d.ts +0 -4
- package/types/serverFactory.d.ts +3 -3
- package/types/utils.d.ts +3 -3
- package/.vscode/settings.json +0 -22
- package/test/test-reporter.mjs +0 -68
- /package/test/{connectionTimeout.test.js → connection-timeout.test.js} +0 -0
- /package/test/internals/{contentTypeParser.test.js → content-type-parser.test.js} +0 -0
- /package/test/internals/{handleRequest.test.js → handle-request.test.js} +0 -0
- /package/test/internals/{hookRunner.test.js → hook-runner.test.js} +0 -0
- /package/test/internals/{initialConfig.test.js → initial-config.test.js} +0 -0
- /package/test/internals/{reqIdGenFactory.test.js → req-id-gen-factory.test.js} +0 -0
- /package/test/{wrapThenable.test.js → wrap-thenable.test.js} +0 -0
package/test/web-api.test.js
CHANGED
|
@@ -227,6 +227,50 @@ test('Error when Response.bodyUsed', async (t) => {
|
|
|
227
227
|
t.assert.strictEqual(body.code, 'FST_ERR_REP_RESPONSE_BODY_CONSUMED')
|
|
228
228
|
})
|
|
229
229
|
|
|
230
|
+
test('Error when Response.body.locked', async (t) => {
|
|
231
|
+
t.plan(3)
|
|
232
|
+
|
|
233
|
+
const fastify = Fastify()
|
|
234
|
+
|
|
235
|
+
fastify.get('/', async function (request, reply) {
|
|
236
|
+
const stream = Readable.toWeb(fs.createReadStream(__filename))
|
|
237
|
+
const response = new Response(stream, {
|
|
238
|
+
status: 200,
|
|
239
|
+
headers: {
|
|
240
|
+
hello: 'world'
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
stream.getReader()
|
|
244
|
+
t.assert.strictEqual(stream.locked, true)
|
|
245
|
+
return reply.send(response)
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
const response = await fastify.inject({ method: 'GET', path: '/' })
|
|
249
|
+
|
|
250
|
+
t.assert.strictEqual(response.statusCode, 500)
|
|
251
|
+
const body = response.json()
|
|
252
|
+
t.assert.strictEqual(body.code, 'FST_ERR_REP_READABLE_STREAM_LOCKED')
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
test('Error when ReadableStream.locked', async (t) => {
|
|
256
|
+
t.plan(3)
|
|
257
|
+
|
|
258
|
+
const fastify = Fastify()
|
|
259
|
+
|
|
260
|
+
fastify.get('/', async function (request, reply) {
|
|
261
|
+
const stream = Readable.toWeb(fs.createReadStream(__filename))
|
|
262
|
+
stream.getReader()
|
|
263
|
+
t.assert.strictEqual(stream.locked, true)
|
|
264
|
+
return reply.send(stream)
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
const response = await fastify.inject({ method: 'GET', path: '/' })
|
|
268
|
+
|
|
269
|
+
t.assert.strictEqual(response.statusCode, 500)
|
|
270
|
+
const body = response.json()
|
|
271
|
+
t.assert.strictEqual(body.code, 'FST_ERR_REP_READABLE_STREAM_LOCKED')
|
|
272
|
+
})
|
|
273
|
+
|
|
230
274
|
test('allow to pipe with fetch', async (t) => {
|
|
231
275
|
t.plan(2)
|
|
232
276
|
const abortController = new AbortController()
|
package/types/hooks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Readable } from 'stream'
|
|
1
|
+
import { Readable } from 'node:stream'
|
|
2
2
|
import { FastifyInstance } from './instance'
|
|
3
3
|
import { RouteOptions, RouteGenericInterface } from './route'
|
|
4
4
|
import { RawServerBase, RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, ContextConfigDefault } from './utils'
|
package/types/instance.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { FastifyError } from '@fastify/error'
|
|
2
2
|
import { ConstraintStrategy, FindResult, HTTPVersion } from 'find-my-way'
|
|
3
|
-
import * as http from 'http'
|
|
3
|
+
import * as http from 'node:http'
|
|
4
4
|
import { InjectOptions, CallbackFunc as LightMyRequestCallback, Chain as LightMyRequestChain, Response as LightMyRequestResponse } from 'light-my-request'
|
|
5
|
-
import { AddressInfo } from 'net'
|
|
5
|
+
import { AddressInfo } from 'node:net'
|
|
6
6
|
import { AddContentTypeParser, ConstructorAction, FastifyBodyParser, ProtoAction, getDefaultJsonParser, hasContentTypeParser, removeAllContentTypeParsers, removeContentTypeParser } from './content-type-parser'
|
|
7
7
|
import { ApplicationHook, HookAsyncLookup, HookLookup, LifecycleHook, onCloseAsyncHookHandler, onCloseHookHandler, onErrorAsyncHookHandler, onErrorHookHandler, onListenAsyncHookHandler, onListenHookHandler, onReadyAsyncHookHandler, onReadyHookHandler, onRegisterHookHandler, onRequestAbortAsyncHookHandler, onRequestAbortHookHandler, onRequestAsyncHookHandler, onRequestHookHandler, onResponseAsyncHookHandler, onResponseHookHandler, onRouteHookHandler, onSendAsyncHookHandler, onSendHookHandler, onTimeoutAsyncHookHandler, onTimeoutHookHandler, preCloseAsyncHookHandler, preCloseHookHandler, preHandlerAsyncHookHandler, preHandlerHookHandler, preParsingAsyncHookHandler, preParsingHookHandler, preSerializationAsyncHookHandler, preSerializationHookHandler, preValidationAsyncHookHandler, preValidationHookHandler } from './hooks'
|
|
8
8
|
import { FastifyBaseLogger, FastifyChildLoggerFactory } from './logger'
|
|
@@ -548,6 +548,13 @@ export interface FastifyInstance<
|
|
|
548
548
|
* Remove all content type parsers, including the default ones
|
|
549
549
|
*/
|
|
550
550
|
removeAllContentTypeParsers: removeAllContentTypeParsers
|
|
551
|
+
/**
|
|
552
|
+
* Add a non-standard HTTP method
|
|
553
|
+
*
|
|
554
|
+
* Methods defined by default include `GET`, `HEAD`, `TRACE`, `DELETE`,
|
|
555
|
+
* `OPTIONS`, `PATCH`, `PUT` and `POST`
|
|
556
|
+
*/
|
|
557
|
+
addHttpMethod(method: string, methodOptions?: { hasBody: boolean }): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
|
|
551
558
|
/**
|
|
552
559
|
* Fastify default JSON parser
|
|
553
560
|
*/
|
package/types/reply.d.ts
CHANGED
package/types/request.d.ts
CHANGED
|
@@ -87,8 +87,4 @@ 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
|
-
|
|
91
|
-
// Prefer `socket` over deprecated `connection` property in node 13.0.0 or higher
|
|
92
|
-
// @deprecated
|
|
93
|
-
readonly connection: RawRequest['socket'];
|
|
94
90
|
}
|
package/types/serverFactory.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RawServerBase, RawServerDefault, RawReplyDefaultExpression, RawRequestDefaultExpression } from './utils'
|
|
2
|
-
import * as http from 'http'
|
|
3
|
-
import * as https from 'https'
|
|
4
|
-
import * as http2 from 'http2'
|
|
2
|
+
import * as http from 'node:http'
|
|
3
|
+
import * as https from 'node:https'
|
|
4
|
+
import * as http2 from 'node:http2'
|
|
5
5
|
|
|
6
6
|
export type FastifyServerFactoryHandler<
|
|
7
7
|
RawServer extends RawServerBase = RawServerDefault,
|
package/types/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as http from 'http'
|
|
2
|
-
import * as http2 from 'http2'
|
|
3
|
-
import * as https from 'https'
|
|
1
|
+
import * as http from 'node:http'
|
|
2
|
+
import * as http2 from 'node:http2'
|
|
3
|
+
import * as https from 'node:https'
|
|
4
4
|
|
|
5
5
|
type AutocompletePrimitiveBaseType<T> =
|
|
6
6
|
T extends string ? string :
|
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
|
-
}
|
package/test/test-reporter.mjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
function colorize (type, text) {
|
|
2
|
-
if (type === 'pass') {
|
|
3
|
-
const blackText = `\x1b[30m${text}`
|
|
4
|
-
const boldblackText = `\x1b[1m${blackText}`
|
|
5
|
-
// Green background with black text
|
|
6
|
-
return `\x1b[42m${boldblackText}\x1b[0m`
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if (type === 'fail') {
|
|
10
|
-
const whiteText = `\x1b[37m${text}`
|
|
11
|
-
const boldWhiteText = `\x1b[1m${whiteText}`
|
|
12
|
-
// Red background with white text
|
|
13
|
-
return `\x1b[41m${boldWhiteText}\x1b[0m`
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return text
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function formatDiagnosticStr (str) {
|
|
20
|
-
return str.replace(/^(\w+)(\s*\d*)/i, (_, firstWord, rest) => {
|
|
21
|
-
return firstWord.charAt(0).toUpperCase() + firstWord.slice(1).toLowerCase() + ':' + rest
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function * reporter (source) {
|
|
26
|
-
const failed = new Set()
|
|
27
|
-
const diagnostics = new Set()
|
|
28
|
-
|
|
29
|
-
for await (const event of source) {
|
|
30
|
-
switch (event.type) {
|
|
31
|
-
case 'test:pass': {
|
|
32
|
-
yield `${colorize('pass', 'PASSED')}: ${event.data.file || event.data.name}\n`
|
|
33
|
-
break
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
case 'test:fail': {
|
|
37
|
-
failed.add(event.data.name || event.data.file)
|
|
38
|
-
yield `${colorize('fail', 'FAILED')}: ${event.data.file || event.data.name}\n`
|
|
39
|
-
break
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
case 'test:diagnostic': {
|
|
43
|
-
diagnostics.add(`${formatDiagnosticStr(event.data.message)}\n`)
|
|
44
|
-
break
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
default: {
|
|
48
|
-
yield ''
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (failed.size > 0) {
|
|
54
|
-
yield `\n\n${colorize('fail', 'Failed tests:')}\n`
|
|
55
|
-
for (const file of failed) {
|
|
56
|
-
yield `${file}\n`
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
yield '\n'
|
|
61
|
-
|
|
62
|
-
for (const diagnostic of diagnostics) {
|
|
63
|
-
yield `${diagnostic}`
|
|
64
|
-
}
|
|
65
|
-
yield '\n'
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export default reporter
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|