fastify 5.0.0 → 5.2.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/.borp.yaml +3 -0
- package/.vscode/settings.json +22 -0
- package/README.md +12 -7
- package/docs/Guides/Database.md +15 -15
- package/docs/Guides/Detecting-When-Clients-Abort.md +28 -28
- package/docs/Guides/Ecosystem.md +14 -15
- package/docs/Guides/Index.md +1 -1
- package/docs/Guides/Migration-Guide-V4.md +11 -11
- package/docs/Guides/Migration-Guide-V5.md +133 -9
- 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 +58 -57
- package/docs/Guides/Write-Plugin.md +2 -2
- package/docs/Guides/Write-Type-Provider.md +3 -3
- package/docs/Reference/ContentTypeParser.md +4 -4
- package/docs/Reference/Decorators.md +2 -2
- package/docs/Reference/Errors.md +3 -3
- 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 +55 -58
- package/docs/Reference/Request.md +49 -42
- package/docs/Reference/Routes.md +16 -13
- 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 +14 -5
- package/fastify.js +8 -6
- package/lib/contentTypeParser.js +9 -7
- package/lib/context.js +1 -2
- package/lib/error-handler.js +9 -9
- package/lib/errors.js +1 -1
- package/lib/fourOhFour.js +1 -1
- package/lib/hooks.js +4 -1
- package/lib/{logger.js → logger-factory.js} +70 -122
- package/lib/logger-pino.js +68 -0
- package/lib/pluginOverride.js +1 -1
- package/lib/pluginUtils.js +2 -2
- package/lib/reply.js +4 -5
- package/lib/request.js +16 -9
- package/lib/route.js +23 -22
- package/lib/validation.js +2 -2
- package/package.json +13 -15
- package/test/404s.test.js +675 -629
- package/test/500s.test.js +72 -63
- package/test/{allowUnsafeRegex.test.js → allow-unsafe-regex.test.js} +30 -26
- package/test/als.test.js +48 -45
- package/test/async-await.test.js +148 -134
- package/test/async-dispose.test.js +4 -5
- package/test/async_hooks.test.js +30 -28
- package/test/{bodyLimit.test.js → body-limit.test.js} +61 -58
- package/test/buffer.test.js +9 -10
- package/test/build/error-serializer.test.js +3 -4
- package/test/build/version.test.js +2 -3
- package/test/build-certificate.js +1 -1
- package/test/bundler/README.md +5 -5
- package/test/bundler/esbuild/bundler-test.js +10 -9
- package/test/bundler/webpack/bundler-test.js +10 -9
- package/test/case-insensitive.test.js +31 -28
- package/test/chainable.test.js +4 -5
- package/test/check.test.js +8 -10
- package/test/{childLoggerFactory.test.js → child-logger-factory.test.js} +56 -19
- package/test/client-timeout.test.js +5 -5
- package/test/close-pipelining.test.js +6 -8
- package/test/conditional-pino.test.js +47 -0
- package/test/{connectionTimeout.test.js → connection-timeout.test.js} +10 -11
- package/test/constrained-routes.test.js +243 -236
- package/test/content-length.test.js +53 -68
- package/test/content-parser.test.js +186 -158
- package/test/content-type.test.js +8 -9
- package/test/context-config.test.js +44 -54
- package/test/custom-http-server.test.js +16 -20
- package/test/custom-parser.5.test.js +32 -32
- package/test/diagnostics-channel/404.test.js +15 -15
- package/test/diagnostics-channel/async-delay-request.test.js +25 -25
- package/test/diagnostics-channel/async-request.test.js +24 -24
- package/test/diagnostics-channel/error-before-handler.test.js +4 -5
- package/test/diagnostics-channel/error-request.test.js +19 -19
- package/test/diagnostics-channel/error-status.test.js +8 -8
- package/test/diagnostics-channel/init.test.js +6 -7
- package/test/diagnostics-channel/sync-delay-request.test.js +16 -16
- package/test/diagnostics-channel/sync-request-reply.test.js +16 -16
- package/test/diagnostics-channel/sync-request.test.js +19 -19
- package/test/encapsulated-child-logger-factory.test.js +8 -8
- package/test/encapsulated-error-handler.test.js +20 -20
- package/test/esm/errorCodes.test.mjs +5 -5
- package/test/esm/esm.test.mjs +3 -3
- package/test/esm/named-exports.mjs +3 -3
- package/test/esm/other.mjs +2 -2
- 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 +25 -25
- package/test/http-methods/copy.test.js +22 -24
- package/test/http-methods/custom-http-methods.test.js +24 -21
- package/test/http-methods/get.test.js +97 -84
- package/test/http-methods/head.test.js +63 -57
- package/test/http-methods/lock.test.js +21 -20
- package/test/http-methods/mkcalendar.test.js +31 -27
- package/test/http-methods/mkcol.test.js +10 -10
- package/test/http-methods/move.test.js +11 -11
- package/test/http-methods/propfind.test.js +32 -27
- package/test/http-methods/proppatch.test.js +21 -19
- package/test/http-methods/report.test.js +32 -27
- package/test/http-methods/search.test.js +52 -47
- package/test/http-methods/trace.test.js +3 -4
- package/test/http-methods/unlock.test.js +10 -10
- package/test/http2/closing.test.js +50 -58
- package/test/http2/constraint.test.js +47 -50
- package/test/http2/head.test.js +18 -19
- package/test/http2/missing-http2-module.test.js +4 -5
- package/test/http2/plain.test.js +31 -31
- package/test/http2/secure-with-fallback.test.js +61 -61
- package/test/http2/secure.test.js +28 -31
- package/test/http2/unknown-http-method.test.js +13 -14
- package/test/https/custom-https-server.test.js +6 -7
- package/test/https/https.test.js +78 -78
- package/test/imports.test.js +5 -6
- package/test/internals/all.test.js +8 -11
- package/test/internals/{contentTypeParser.test.js → content-type-parser.test.js} +5 -6
- package/test/internals/context.test.js +9 -11
- package/test/internals/decorator.test.js +20 -21
- package/test/internals/errors.test.js +427 -427
- package/test/internals/{handleRequest.test.js → handle-request.test.js} +53 -42
- package/test/internals/{hookRunner.test.js → hook-runner.test.js} +99 -100
- package/test/internals/hooks.test.js +31 -35
- package/test/internals/{initialConfig.test.js → initial-config.test.js} +92 -80
- package/test/internals/logger.test.js +28 -28
- package/test/internals/plugin.test.js +17 -18
- package/test/internals/reply-serialize.test.js +106 -106
- package/test/internals/reply.test.js +620 -585
- package/test/internals/{reqIdGenFactory.test.js → req-id-gen-factory.test.js} +31 -31
- package/test/internals/request-validate.test.js +218 -221
- package/test/internals/request.test.js +225 -107
- package/test/internals/server.test.js +15 -12
- package/test/internals/validation.test.js +35 -36
- package/test/{keepAliveTimeout.test.js → keep-alive-timeout.test.js} +9 -10
- 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 +5 -5
- 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-error.test.js +122 -0
- package/test/request-header-host.test.js +339 -0
- package/test/request-id.test.js +31 -25
- package/test/{requestTimeout.test.js → request-timeout.test.js} +11 -11
- package/test/route.1.test.js +79 -72
- package/test/route.2.test.js +17 -16
- package/test/route.3.test.js +32 -27
- package/test/route.4.test.js +21 -25
- package/test/route.5.test.js +45 -64
- package/test/route.6.test.js +70 -89
- package/test/route.7.test.js +61 -65
- package/test/route.8.test.js +80 -18
- package/test/router-options.test.js +80 -77
- package/test/same-shape.test.js +5 -5
- package/test/schema-examples.test.js +72 -38
- package/test/serialize-response.test.js +9 -10
- package/test/server.test.js +75 -78
- 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/test-reporter.mjs +68 -0
- 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 +16 -4
- package/test/types/hooks.test-d.ts +2 -1
- package/test/types/instance.test-d.ts +13 -13
- package/test/types/logger.test-d.ts +2 -2
- package/test/types/plugin.test-d.ts +17 -9
- package/test/types/register.test-d.ts +22 -6
- package/test/types/reply.test-d.ts +1 -1
- package/test/types/route.test-d.ts +34 -4
- 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/versioned-routes.test.js +126 -113
- package/test/web-api.test.js +48 -37
- package/test/{wrapThenable.test.js → wrap-thenable.test.js} +10 -9
- package/types/hooks.d.ts +2 -1
- package/types/instance.d.ts +9 -2
- package/types/register.d.ts +12 -3
- package/types/reply.d.ts +1 -1
- package/types/request.d.ts +2 -6
- package/types/serverFactory.d.ts +3 -3
- package/types/utils.d.ts +13 -5
- package/test/types/import.js +0 -2
package/test/web-api.test.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
const Fastify = require('../fastify')
|
|
6
5
|
const fs = require('node:fs')
|
|
7
6
|
const { Readable } = require('node:stream')
|
|
@@ -24,8 +23,8 @@ test('should response with a ReadableStream', async (t) => {
|
|
|
24
23
|
|
|
25
24
|
const expected = await fs.promises.readFile(__filename)
|
|
26
25
|
|
|
27
|
-
t.
|
|
28
|
-
t.
|
|
26
|
+
t.assert.strictEqual(statusCode, 200)
|
|
27
|
+
t.assert.strictEqual(expected.toString(), body.toString())
|
|
29
28
|
})
|
|
30
29
|
|
|
31
30
|
test('should response with a Response', async (t) => {
|
|
@@ -51,9 +50,9 @@ test('should response with a Response', async (t) => {
|
|
|
51
50
|
|
|
52
51
|
const expected = await fs.promises.readFile(__filename)
|
|
53
52
|
|
|
54
|
-
t.
|
|
55
|
-
t.
|
|
56
|
-
t.
|
|
53
|
+
t.assert.strictEqual(statusCode, 200)
|
|
54
|
+
t.assert.strictEqual(expected.toString(), body.toString())
|
|
55
|
+
t.assert.strictEqual(headers.hello, 'world')
|
|
57
56
|
})
|
|
58
57
|
|
|
59
58
|
test('should response with a Response 204', async (t) => {
|
|
@@ -76,9 +75,9 @@ test('should response with a Response 204', async (t) => {
|
|
|
76
75
|
body
|
|
77
76
|
} = await fastify.inject({ method: 'GET', path: '/' })
|
|
78
77
|
|
|
79
|
-
t.
|
|
80
|
-
t.
|
|
81
|
-
t.
|
|
78
|
+
t.assert.strictEqual(statusCode, 204)
|
|
79
|
+
t.assert.strictEqual(body, '')
|
|
80
|
+
t.assert.strictEqual(headers.hello, 'world')
|
|
82
81
|
})
|
|
83
82
|
|
|
84
83
|
test('should response with a Response 304', async (t) => {
|
|
@@ -101,9 +100,9 @@ test('should response with a Response 304', async (t) => {
|
|
|
101
100
|
body
|
|
102
101
|
} = await fastify.inject({ method: 'GET', path: '/' })
|
|
103
102
|
|
|
104
|
-
t.
|
|
105
|
-
t.
|
|
106
|
-
t.
|
|
103
|
+
t.assert.strictEqual(statusCode, 304)
|
|
104
|
+
t.assert.strictEqual(body, '')
|
|
105
|
+
t.assert.strictEqual(headers.hello, 'world')
|
|
107
106
|
})
|
|
108
107
|
|
|
109
108
|
test('should response with a Response without body', async (t) => {
|
|
@@ -126,9 +125,9 @@ test('should response with a Response without body', async (t) => {
|
|
|
126
125
|
body
|
|
127
126
|
} = await fastify.inject({ method: 'GET', path: '/' })
|
|
128
127
|
|
|
129
|
-
t.
|
|
130
|
-
t.
|
|
131
|
-
t.
|
|
128
|
+
t.assert.strictEqual(statusCode, 200)
|
|
129
|
+
t.assert.strictEqual(body, '')
|
|
130
|
+
t.assert.strictEqual(headers.hello, 'world')
|
|
132
131
|
})
|
|
133
132
|
|
|
134
133
|
test('able to use in onSend hook - ReadableStream', async (t) => {
|
|
@@ -142,7 +141,7 @@ test('able to use in onSend hook - ReadableStream', async (t) => {
|
|
|
142
141
|
})
|
|
143
142
|
|
|
144
143
|
fastify.addHook('onSend', (request, reply, payload, done) => {
|
|
145
|
-
t.
|
|
144
|
+
t.assert.strictEqual(Object.prototype.toString.call(payload), '[object ReadableStream]')
|
|
146
145
|
done(null, new Response(payload, {
|
|
147
146
|
status: 200,
|
|
148
147
|
headers: {
|
|
@@ -159,9 +158,9 @@ test('able to use in onSend hook - ReadableStream', async (t) => {
|
|
|
159
158
|
|
|
160
159
|
const expected = await fs.promises.readFile(__filename)
|
|
161
160
|
|
|
162
|
-
t.
|
|
163
|
-
t.
|
|
164
|
-
t.
|
|
161
|
+
t.assert.strictEqual(statusCode, 200)
|
|
162
|
+
t.assert.strictEqual(expected.toString(), body.toString())
|
|
163
|
+
t.assert.strictEqual(headers.hello, 'world')
|
|
165
164
|
})
|
|
166
165
|
|
|
167
166
|
test('able to use in onSend hook - Response', async (t) => {
|
|
@@ -180,7 +179,7 @@ test('able to use in onSend hook - Response', async (t) => {
|
|
|
180
179
|
})
|
|
181
180
|
|
|
182
181
|
fastify.addHook('onSend', (request, reply, payload, done) => {
|
|
183
|
-
t.
|
|
182
|
+
t.assert.strictEqual(Object.prototype.toString.call(payload), '[object Response]')
|
|
184
183
|
done(null, new Response(payload.body, {
|
|
185
184
|
status: 200,
|
|
186
185
|
headers: payload.headers
|
|
@@ -195,9 +194,9 @@ test('able to use in onSend hook - Response', async (t) => {
|
|
|
195
194
|
|
|
196
195
|
const expected = await fs.promises.readFile(__filename)
|
|
197
196
|
|
|
198
|
-
t.
|
|
199
|
-
t.
|
|
200
|
-
t.
|
|
197
|
+
t.assert.strictEqual(statusCode, 200)
|
|
198
|
+
t.assert.strictEqual(expected.toString(), body.toString())
|
|
199
|
+
t.assert.strictEqual(headers.hello, 'world')
|
|
201
200
|
})
|
|
202
201
|
|
|
203
202
|
test('Error when Response.bodyUsed', async (t) => {
|
|
@@ -216,31 +215,37 @@ test('Error when Response.bodyUsed', async (t) => {
|
|
|
216
215
|
}
|
|
217
216
|
})
|
|
218
217
|
const file = await response.text()
|
|
219
|
-
t.
|
|
220
|
-
t.
|
|
218
|
+
t.assert.strictEqual(expected.toString(), file)
|
|
219
|
+
t.assert.strictEqual(response.bodyUsed, true)
|
|
221
220
|
return reply.send(response)
|
|
222
221
|
})
|
|
223
222
|
|
|
224
223
|
const response = await fastify.inject({ method: 'GET', path: '/' })
|
|
225
224
|
|
|
226
|
-
t.
|
|
225
|
+
t.assert.strictEqual(response.statusCode, 500)
|
|
227
226
|
const body = response.json()
|
|
228
|
-
t.
|
|
227
|
+
t.assert.strictEqual(body.code, 'FST_ERR_REP_RESPONSE_BODY_CONSUMED')
|
|
229
228
|
})
|
|
230
229
|
|
|
231
230
|
test('allow to pipe with fetch', async (t) => {
|
|
232
231
|
t.plan(2)
|
|
232
|
+
const abortController = new AbortController()
|
|
233
|
+
const { signal } = abortController
|
|
233
234
|
|
|
234
235
|
const fastify = Fastify()
|
|
235
|
-
t.
|
|
236
|
+
t.after(() => {
|
|
237
|
+
fastify.close()
|
|
238
|
+
abortController.abort()
|
|
239
|
+
})
|
|
236
240
|
|
|
237
241
|
fastify.get('/', function (request, reply) {
|
|
238
242
|
return fetch(`${fastify.listeningOrigin}/fetch`, {
|
|
239
|
-
method: 'GET'
|
|
243
|
+
method: 'GET',
|
|
244
|
+
signal
|
|
240
245
|
})
|
|
241
246
|
})
|
|
242
247
|
|
|
243
|
-
fastify.get('/fetch', function (request, reply) {
|
|
248
|
+
fastify.get('/fetch', function async (request, reply) {
|
|
244
249
|
reply.code(200).send({ ok: true })
|
|
245
250
|
})
|
|
246
251
|
|
|
@@ -248,19 +253,25 @@ test('allow to pipe with fetch', async (t) => {
|
|
|
248
253
|
|
|
249
254
|
const response = await fastify.inject({ method: 'GET', path: '/' })
|
|
250
255
|
|
|
251
|
-
t.
|
|
252
|
-
t.
|
|
256
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
257
|
+
t.assert.deepStrictEqual(response.json(), { ok: true })
|
|
253
258
|
})
|
|
254
259
|
|
|
255
260
|
test('allow to pipe with undici.fetch', async (t) => {
|
|
256
261
|
t.plan(2)
|
|
262
|
+
const abortController = new AbortController()
|
|
263
|
+
const { signal } = abortController
|
|
257
264
|
|
|
258
265
|
const fastify = Fastify()
|
|
259
|
-
t.
|
|
266
|
+
t.after(() => {
|
|
267
|
+
fastify.close()
|
|
268
|
+
abortController.abort()
|
|
269
|
+
})
|
|
260
270
|
|
|
261
271
|
fastify.get('/', function (request, reply) {
|
|
262
272
|
return undiciFetch(`${fastify.listeningOrigin}/fetch`, {
|
|
263
|
-
method: 'GET'
|
|
273
|
+
method: 'GET',
|
|
274
|
+
signal
|
|
264
275
|
})
|
|
265
276
|
})
|
|
266
277
|
|
|
@@ -272,6 +283,6 @@ test('allow to pipe with undici.fetch', async (t) => {
|
|
|
272
283
|
|
|
273
284
|
const response = await fastify.inject({ method: 'GET', path: '/' })
|
|
274
285
|
|
|
275
|
-
t.
|
|
276
|
-
t.
|
|
286
|
+
t.assert.strictEqual(response.statusCode, 200)
|
|
287
|
+
t.assert.deepStrictEqual(response.json(), { ok: true })
|
|
277
288
|
})
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const test = t.test
|
|
3
|
+
const { test } = require('node:test')
|
|
5
4
|
const { kReplyHijacked } = require('../lib/symbols')
|
|
6
5
|
const wrapThenable = require('../lib/wrapThenable')
|
|
7
6
|
const Reply = require('../lib/reply')
|
|
8
7
|
|
|
9
|
-
test('should resolve immediately when reply[kReplyHijacked] is true', t => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
test('should resolve immediately when reply[kReplyHijacked] is true', async t => {
|
|
9
|
+
await new Promise(resolve => {
|
|
10
|
+
const reply = {}
|
|
11
|
+
reply[kReplyHijacked] = true
|
|
12
|
+
const thenable = Promise.resolve()
|
|
13
|
+
wrapThenable(thenable, reply)
|
|
14
|
+
resolve()
|
|
15
|
+
})
|
|
15
16
|
})
|
|
16
17
|
|
|
17
18
|
test('should reject immediately when reply[kReplyHijacked] is true', t => {
|
|
@@ -20,7 +21,7 @@ test('should reject immediately when reply[kReplyHijacked] is true', t => {
|
|
|
20
21
|
reply[kReplyHijacked] = true
|
|
21
22
|
reply.log = {
|
|
22
23
|
error: ({ err }) => {
|
|
23
|
-
t.
|
|
24
|
+
t.assert.strictEqual(err.message, 'Reply sent already')
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
|
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'
|
|
@@ -710,6 +710,7 @@ export interface onRegisterHookHandler<
|
|
|
710
710
|
Options extends FastifyPluginOptions = FastifyPluginOptions
|
|
711
711
|
> {
|
|
712
712
|
(
|
|
713
|
+
this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
|
|
713
714
|
instance: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
|
|
714
715
|
opts: RegisterOptions & Options
|
|
715
716
|
): Promise<unknown> | void;
|
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/register.d.ts
CHANGED
|
@@ -18,16 +18,25 @@ export type FastifyRegisterOptions<Options> = (RegisterOptions & Options) | ((in
|
|
|
18
18
|
* Function for adding a plugin to fastify. The options are inferred from the passed in FastifyPlugin parameter.
|
|
19
19
|
*/
|
|
20
20
|
export interface FastifyRegister<T = void, RawServer extends RawServerBase = RawServerDefault, TypeProviderDefault extends FastifyTypeProvider = FastifyTypeProvider, LoggerDefault extends FastifyBaseLogger = FastifyBaseLogger> {
|
|
21
|
+
<Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>(
|
|
22
|
+
plugin: FastifyPluginCallback<FastifyPluginOptions, Server, TypeProvider, Logger>
|
|
23
|
+
): T;
|
|
21
24
|
<Options extends FastifyPluginOptions, Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>(
|
|
22
25
|
plugin: FastifyPluginCallback<Options, Server, TypeProvider, Logger>,
|
|
23
|
-
opts
|
|
26
|
+
opts: FastifyRegisterOptions<Options>
|
|
27
|
+
): T;
|
|
28
|
+
<Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>(
|
|
29
|
+
plugin: FastifyPluginAsync<FastifyPluginOptions, Server, TypeProvider, Logger>
|
|
24
30
|
): T;
|
|
25
31
|
<Options extends FastifyPluginOptions, Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>(
|
|
26
32
|
plugin: FastifyPluginAsync<Options, Server, TypeProvider, Logger>,
|
|
27
|
-
opts
|
|
33
|
+
opts: FastifyRegisterOptions<Options>
|
|
34
|
+
): T;
|
|
35
|
+
<Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>(
|
|
36
|
+
plugin: FastifyPluginCallback<FastifyPluginOptions, Server, TypeProvider, Logger> | FastifyPluginAsync<FastifyPluginOptions, Server, TypeProvider, Logger> | Promise<{ default: FastifyPluginCallback<FastifyPluginOptions, Server, TypeProvider, Logger> }> | Promise<{ default: FastifyPluginAsync<FastifyPluginOptions, Server, TypeProvider, Logger> }>,
|
|
28
37
|
): T;
|
|
29
38
|
<Options extends FastifyPluginOptions, Server extends RawServerBase = RawServer, TypeProvider extends FastifyTypeProvider = TypeProviderDefault, Logger extends FastifyBaseLogger = LoggerDefault>(
|
|
30
39
|
plugin: FastifyPluginCallback<Options, Server, TypeProvider, Logger> | FastifyPluginAsync<Options, Server, TypeProvider, Logger> | Promise<{ default: FastifyPluginCallback<Options, Server, TypeProvider, Logger> }> | Promise<{ default: FastifyPluginAsync<Options, Server, TypeProvider, Logger> }>,
|
|
31
|
-
opts
|
|
40
|
+
opts: FastifyRegisterOptions<Options>
|
|
32
41
|
): T;
|
|
33
42
|
}
|
package/types/reply.d.ts
CHANGED
package/types/request.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { FastifyBaseLogger } from './logger'
|
|
|
5
5
|
import { FastifyRouteConfig, RouteGenericInterface, RouteHandlerMethod } from './route'
|
|
6
6
|
import { FastifySchema } from './schema'
|
|
7
7
|
import { FastifyRequestType, FastifyTypeProvider, FastifyTypeProviderDefault, ResolveFastifyRequestType } from './type-provider'
|
|
8
|
-
import { ContextConfigDefault, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestBodyDefault, RequestHeadersDefault, RequestParamsDefault, RequestQuerystringDefault } from './utils'
|
|
8
|
+
import { ContextConfigDefault, HTTPMethods, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestBodyDefault, RequestHeadersDefault, RequestParamsDefault, RequestQuerystringDefault } from './utils'
|
|
9
9
|
|
|
10
10
|
type HTTPRequestPart = 'body' | 'query' | 'querystring' | 'params' | 'headers'
|
|
11
11
|
export interface RequestGenericInterface {
|
|
@@ -21,7 +21,7 @@ export interface ValidationFunction {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface RequestRouteOptions<ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema> {
|
|
24
|
-
method:
|
|
24
|
+
method: HTTPMethods | HTTPMethods[];
|
|
25
25
|
// `url` can be `undefined` for instance when `request.is404` is true
|
|
26
26
|
url: string | undefined;
|
|
27
27
|
bodyLimit: number;
|
|
@@ -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,14 +1,23 @@
|
|
|
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
|
+
|
|
5
|
+
type AutocompletePrimitiveBaseType<T> =
|
|
6
|
+
T extends string ? string :
|
|
7
|
+
T extends number ? number :
|
|
8
|
+
T extends boolean ? boolean :
|
|
9
|
+
never
|
|
10
|
+
|
|
11
|
+
export type Autocomplete<T> = T | (AutocompletePrimitiveBaseType<T> & Record<never, never>)
|
|
4
12
|
|
|
5
13
|
/**
|
|
6
14
|
* Standard HTTP method strings
|
|
15
|
+
* for internal use
|
|
7
16
|
*/
|
|
8
17
|
type _HTTPMethods = 'DELETE' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'OPTIONS' |
|
|
9
18
|
'PROPFIND' | 'PROPPATCH' | 'MKCOL' | 'COPY' | 'MOVE' | 'LOCK' | 'UNLOCK' | 'TRACE' | 'SEARCH' | 'REPORT' | 'MKCALENDAR'
|
|
10
19
|
|
|
11
|
-
export type HTTPMethods =
|
|
20
|
+
export type HTTPMethods = Autocomplete<_HTTPMethods | Lowercase<_HTTPMethods>>
|
|
12
21
|
|
|
13
22
|
/**
|
|
14
23
|
* A union type of the Node.js server types from the http, https, and http2 modules.
|
|
@@ -56,7 +65,6 @@ type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
|
|
56
65
|
type HttpCodes = StringAsNumber<`${CodeClasses}${Digit}${Digit}`>
|
|
57
66
|
type HttpKeys = HttpCodes | `${Digit}xx`
|
|
58
67
|
export type StatusCodeReply = {
|
|
59
|
-
|
|
60
68
|
[Key in HttpKeys]?: unknown;
|
|
61
69
|
}
|
|
62
70
|
|
package/test/types/import.js
DELETED