fastify 5.8.5 → 5.10.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/PROJECT_CHARTER.md +1 -1
- package/README.md +7 -10
- package/SECURITY.md +1 -1
- package/SPONSORS.md +6 -4
- package/build/build-validation.js +2 -2
- package/docs/Guides/Database.md +0 -28
- package/docs/Guides/Delay-Accepting-Requests.md +1 -1
- package/docs/Guides/Ecosystem.md +23 -9
- package/docs/Guides/Getting-Started.md +2 -2
- package/docs/Guides/Migration-Guide-V4.md +2 -2
- package/docs/Guides/Migration-Guide-V5.md +1 -1
- package/docs/Guides/Plugins-Guide.md +1 -1
- package/docs/Guides/Prototype-Poisoning.md +3 -3
- package/docs/Guides/Serverless.md +8 -15
- package/docs/Guides/Style-Guide.md +1 -1
- package/docs/Guides/Write-Plugin.md +1 -1
- package/docs/Reference/Encapsulation.md +27 -26
- package/docs/Reference/Errors.md +12 -4
- package/docs/Reference/HTTP2.md +10 -10
- package/docs/Reference/Hooks.md +5 -5
- package/docs/Reference/Index.md +14 -16
- package/docs/Reference/LTS.md +12 -13
- package/docs/Reference/Lifecycle.md +9 -8
- package/docs/Reference/Logging.md +47 -39
- package/docs/Reference/Middleware.md +21 -25
- package/docs/Reference/Principles.md +2 -2
- package/docs/Reference/Reply.md +6 -1
- package/docs/Reference/Request.md +29 -18
- package/docs/Reference/Routes.md +5 -2
- package/docs/Reference/Server.md +138 -11
- package/docs/Reference/Type-Providers.md +53 -9
- package/docs/Reference/TypeScript.md +3 -3
- package/docs/Reference/Validation-and-Serialization.md +15 -2
- package/docs/Reference/Warnings.md +11 -6
- package/eslint.config.js +7 -2
- package/fastify.d.ts +13 -3
- package/fastify.js +60 -31
- package/lib/content-type-parser.js +2 -0
- package/lib/content-type.js +34 -1
- package/lib/context.js +0 -3
- package/lib/decorate.js +11 -3
- package/lib/error-handler.js +10 -28
- package/lib/error-serializer.js +59 -59
- package/lib/errors.js +23 -1
- package/lib/four-oh-four.js +22 -19
- package/lib/handle-request.js +12 -5
- package/lib/log-controller.js +169 -0
- package/lib/logger-factory.js +25 -4
- package/lib/plugin-override.js +2 -1
- package/lib/plugin-utils.js +5 -5
- package/lib/reply.js +96 -50
- package/lib/req-id-gen-factory.js +4 -1
- package/lib/request.js +16 -6
- package/lib/route.js +47 -41
- package/lib/schema-controller.js +1 -1
- package/lib/schemas.js +37 -30
- package/lib/symbols.js +4 -2
- package/lib/validation.js +10 -13
- package/lib/warnings.js +22 -4
- package/package.json +15 -17
- package/scripts/validate-ecosystem-links.js +1 -0
- package/test/bundler/esbuild/package.json +1 -1
- package/test/close-pipelining.test.js +1 -2
- package/test/content-type.test.js +20 -0
- package/test/custom-http-server.test.js +38 -0
- package/test/decorator-instance-properties.test.js +63 -0
- package/test/diagnostics-channel/async-error-handler.test.js +74 -0
- package/test/genReqId.test.js +24 -0
- package/test/hooks.test.js +94 -0
- package/test/http-methods/get.test.js +1 -1
- package/test/http2/plain.test.js +135 -0
- package/test/http2/secure-with-fallback.test.js +1 -1
- package/test/https/https.test.js +1 -2
- package/test/internals/errors.test.js +31 -1
- package/test/internals/logger.test.js +322 -0
- package/test/internals/plugin.test.js +3 -1
- package/test/internals/reply.test.js +35 -4
- package/test/internals/request.test.js +37 -10
- package/test/internals/schema-controller-perf.test.js +33 -0
- package/test/logger/logging.test.js +57 -1
- package/test/logger/options.test.js +38 -1
- package/test/reply-error.test.js +1 -1
- package/test/reply-trailers.test.js +70 -0
- package/test/request-media-type.test.js +105 -0
- package/test/route-prefix.test.js +34 -0
- package/test/router-options.test.js +222 -11
- package/test/schema-serialization.test.js +108 -0
- package/test/schema-validation.test.js +24 -0
- package/test/scripts/validate-ecosystem-links.test.js +40 -57
- package/test/stream.4.test.js +2 -2
- package/test/throw.test.js +14 -0
- package/test/trust-proxy.test.js +70 -30
- package/test/types/content-type-parser.tst.ts +70 -0
- package/test/types/{decorate-request-reply.test-d.ts → decorate-request-reply.tst.ts} +4 -4
- package/test/types/{dummy-plugin.ts → dummy-plugin.mts} +1 -1
- package/test/types/errors.tst.ts +91 -0
- package/test/types/fastify.tst.ts +351 -0
- package/test/types/hooks.tst.ts +578 -0
- package/test/types/instance.tst.ts +597 -0
- package/test/types/{logger.test-d.ts → logger.tst.ts} +61 -62
- package/test/types/plugin.tst.ts +96 -0
- package/test/types/register.tst.ts +245 -0
- package/test/types/reply.tst.ts +297 -0
- package/test/types/request.tst.ts +199 -0
- package/test/types/route.tst.ts +576 -0
- package/test/types/{schema.test-d.ts → schema.tst.ts} +22 -22
- package/test/types/{serverFactory.test-d.ts → serverFactory.tst.ts} +4 -4
- package/test/types/tsconfig.json +9 -0
- package/test/types/{type-provider.test-d.ts → type-provider.tst.ts} +256 -250
- package/test/types/using.tst.ts +14 -0
- package/types/errors.d.ts +4 -0
- package/types/instance.d.ts +2 -0
- package/types/logger.d.ts +22 -0
- package/types/request.d.ts +23 -2
- package/test/types/content-type-parser.test-d.ts +0 -72
- package/test/types/errors.test-d.ts +0 -90
- package/test/types/fastify.test-d.ts +0 -352
- package/test/types/hooks.test-d.ts +0 -550
- package/test/types/import.ts +0 -2
- package/test/types/instance.test-d.ts +0 -588
- package/test/types/plugin.test-d.ts +0 -97
- package/test/types/register.test-d.ts +0 -237
- package/test/types/reply.test-d.ts +0 -254
- package/test/types/request.test-d.ts +0 -188
- package/test/types/route.test-d.ts +0 -553
- package/test/types/using.test-d.ts +0 -17
package/test/trust-proxy.test.js
CHANGED
|
@@ -6,10 +6,10 @@ const helper = require('./helper')
|
|
|
6
6
|
const Request = require('../lib/request')
|
|
7
7
|
const buildRequest = Request.buildRequest
|
|
8
8
|
|
|
9
|
-
const fetchForwardedRequest = async (fastifyServer, forHeader, path, protoHeader) => {
|
|
9
|
+
const fetchForwardedRequest = async (fastifyServer, forHeader, path, protoHeader, hostHeader = 'fastify.test') => {
|
|
10
10
|
const headers = {
|
|
11
11
|
'X-Forwarded-For': forHeader,
|
|
12
|
-
'X-Forwarded-Host':
|
|
12
|
+
'X-Forwarded-Host': hostHeader
|
|
13
13
|
}
|
|
14
14
|
if (protoHeader) {
|
|
15
15
|
headers['X-Forwarded-Proto'] = protoHeader
|
|
@@ -28,8 +28,10 @@ const testRequestValues = (t, req, options) => {
|
|
|
28
28
|
if (options.host) {
|
|
29
29
|
t.assert.ok(req.host, 'host is defined')
|
|
30
30
|
t.assert.strictEqual(req.host, options.host, 'gets host from x-forwarded-host')
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
}
|
|
32
|
+
if (options.hostname) {
|
|
33
|
+
t.assert.ok(req.hostname, 'hostname is defined')
|
|
34
|
+
t.assert.strictEqual(req.hostname, options.hostname, 'gets hostname from x-forwarded-host')
|
|
33
35
|
}
|
|
34
36
|
if (options.ips) {
|
|
35
37
|
t.assert.deepStrictEqual(req.ips, options.ips, 'gets ips from x-forwarded-for')
|
|
@@ -38,9 +40,8 @@ const testRequestValues = (t, req, options) => {
|
|
|
38
40
|
t.assert.ok(req.protocol, 'protocol is defined')
|
|
39
41
|
t.assert.strictEqual(req.protocol, options.protocol, 'gets protocol from x-forwarded-proto')
|
|
40
42
|
}
|
|
41
|
-
if (options
|
|
42
|
-
t.assert.
|
|
43
|
-
t.assert.strictEqual(req.port, options.port, 'port is taken from x-forwarded-for or host')
|
|
43
|
+
if ('port' in options) {
|
|
44
|
+
t.assert.strictEqual(req.port, options.port, 'port is parsed from x-forwarded-host')
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
|
|
@@ -50,117 +51,135 @@ before(async function () {
|
|
|
50
51
|
})
|
|
51
52
|
|
|
52
53
|
test('trust proxy, not add properties to node req', async t => {
|
|
53
|
-
t.plan(
|
|
54
|
+
t.plan(11)
|
|
54
55
|
const app = fastify({
|
|
55
56
|
trustProxy: true
|
|
56
57
|
})
|
|
57
58
|
t.after(() => app.close())
|
|
58
59
|
|
|
59
60
|
app.get('/trustproxy', function (req, reply) {
|
|
60
|
-
testRequestValues(t, req, { ip: '1.1.1.1', host: 'fastify.test',
|
|
61
|
+
testRequestValues(t, req, { ip: '1.1.1.1', host: 'fastify.test:1234', hostname: 'fastify.test', port: 1234 })
|
|
61
62
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
62
63
|
})
|
|
63
64
|
|
|
64
65
|
app.get('/trustproxychain', function (req, reply) {
|
|
65
|
-
|
|
66
|
+
// x-forwarded-host carries no port, so req.port is null
|
|
67
|
+
testRequestValues(t, req, { ip: '2.2.2.2', ips: [localhost, '1.1.1.1', '2.2.2.2'], port: null })
|
|
66
68
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
67
69
|
})
|
|
68
70
|
|
|
69
71
|
const fastifyServer = await app.listen({ port: 0 })
|
|
70
72
|
|
|
71
|
-
await fetchForwardedRequest(fastifyServer, '1.1.1.1', '/trustproxy', undefined)
|
|
73
|
+
await fetchForwardedRequest(fastifyServer, '1.1.1.1', '/trustproxy', undefined, 'fastify.test:1234')
|
|
72
74
|
await fetchForwardedRequest(fastifyServer, '2.2.2.2, 1.1.1.1', '/trustproxychain', undefined)
|
|
73
75
|
})
|
|
74
76
|
|
|
75
77
|
test('trust proxy chain', async t => {
|
|
76
|
-
t.plan(
|
|
78
|
+
t.plan(7)
|
|
77
79
|
const app = fastify({
|
|
78
80
|
trustProxy: [localhost, '192.168.1.1']
|
|
79
81
|
})
|
|
80
82
|
t.after(() => app.close())
|
|
81
83
|
|
|
82
84
|
app.get('/trustproxychain', function (req, reply) {
|
|
83
|
-
testRequestValues(t, req, { ip: '1.1.1.1', host: 'fastify.test',
|
|
85
|
+
testRequestValues(t, req, { ip: '1.1.1.1', host: 'fastify.test:1234', hostname: 'fastify.test', port: 1234 })
|
|
84
86
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
85
87
|
})
|
|
86
88
|
|
|
87
89
|
const fastifyServer = await app.listen({ port: 0 })
|
|
88
|
-
await fetchForwardedRequest(fastifyServer, '192.168.1.1, 1.1.1.1', '/trustproxychain', undefined)
|
|
90
|
+
await fetchForwardedRequest(fastifyServer, '192.168.1.1, 1.1.1.1', '/trustproxychain', undefined, 'fastify.test:1234')
|
|
89
91
|
})
|
|
90
92
|
|
|
91
93
|
test('trust proxy function', async t => {
|
|
92
|
-
t.plan(
|
|
94
|
+
t.plan(7)
|
|
93
95
|
const app = fastify({
|
|
94
96
|
trustProxy: (address) => address === localhost
|
|
95
97
|
})
|
|
96
98
|
t.after(() => app.close())
|
|
97
99
|
|
|
98
100
|
app.get('/trustproxyfunc', function (req, reply) {
|
|
99
|
-
testRequestValues(t, req, { ip: '1.1.1.1', host: 'fastify.test',
|
|
101
|
+
testRequestValues(t, req, { ip: '1.1.1.1', host: 'fastify.test:1234', hostname: 'fastify.test', port: 1234 })
|
|
100
102
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
101
103
|
})
|
|
102
104
|
|
|
103
105
|
const fastifyServer = await app.listen({ port: 0 })
|
|
104
|
-
await fetchForwardedRequest(fastifyServer, '1.1.1.1', '/trustproxyfunc', undefined)
|
|
106
|
+
await fetchForwardedRequest(fastifyServer, '1.1.1.1', '/trustproxyfunc', undefined, 'fastify.test:1234')
|
|
105
107
|
})
|
|
106
108
|
|
|
107
109
|
test('trust proxy number', async t => {
|
|
108
|
-
t.plan(
|
|
110
|
+
t.plan(8)
|
|
109
111
|
const app = fastify({
|
|
110
112
|
trustProxy: 1
|
|
111
113
|
})
|
|
112
114
|
t.after(() => app.close())
|
|
113
115
|
|
|
114
116
|
app.get('/trustproxynumber', function (req, reply) {
|
|
115
|
-
testRequestValues(t, req, { ip: '1.1.1.1', ips: [localhost, '1.1.1.1'], host: 'fastify.test',
|
|
117
|
+
testRequestValues(t, req, { ip: '1.1.1.1', ips: [localhost, '1.1.1.1'], host: 'fastify.test:1234', hostname: 'fastify.test', port: 1234 })
|
|
116
118
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
117
119
|
})
|
|
118
120
|
|
|
119
121
|
const fastifyServer = await app.listen({ port: 0 })
|
|
120
|
-
await fetchForwardedRequest(fastifyServer, '2.2.2.2, 1.1.1.1', '/trustproxynumber', undefined)
|
|
122
|
+
await fetchForwardedRequest(fastifyServer, '2.2.2.2, 1.1.1.1', '/trustproxynumber', undefined, 'fastify.test:1234')
|
|
121
123
|
})
|
|
122
124
|
|
|
123
125
|
test('trust proxy IP addresses', async t => {
|
|
124
|
-
t.plan(
|
|
126
|
+
t.plan(8)
|
|
125
127
|
const app = fastify({
|
|
126
128
|
trustProxy: `${localhost}, 2.2.2.2`
|
|
127
129
|
})
|
|
128
130
|
t.after(() => app.close())
|
|
129
131
|
|
|
130
132
|
app.get('/trustproxyipaddrs', function (req, reply) {
|
|
131
|
-
testRequestValues(t, req, { ip: '1.1.1.1', ips: [localhost, '1.1.1.1'], host: 'fastify.test',
|
|
133
|
+
testRequestValues(t, req, { ip: '1.1.1.1', ips: [localhost, '1.1.1.1'], host: 'fastify.test:1234', hostname: 'fastify.test', port: 1234 })
|
|
132
134
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
133
135
|
})
|
|
134
136
|
|
|
135
137
|
const fastifyServer = await app.listen({ port: 0 })
|
|
136
|
-
await fetchForwardedRequest(fastifyServer, '3.3.3.3, 2.2.2.2, 1.1.1.1', '/trustproxyipaddrs', undefined)
|
|
138
|
+
await fetchForwardedRequest(fastifyServer, '3.3.3.3, 2.2.2.2, 1.1.1.1', '/trustproxyipaddrs', undefined, 'fastify.test:1234')
|
|
137
139
|
})
|
|
138
140
|
|
|
139
141
|
test('trust proxy protocol', async t => {
|
|
140
|
-
t.plan(
|
|
142
|
+
t.plan(27)
|
|
141
143
|
const app = fastify({
|
|
142
144
|
trustProxy: true
|
|
143
145
|
})
|
|
144
146
|
t.after(() => app.close())
|
|
145
147
|
|
|
146
148
|
app.get('/trustproxyprotocol', function (req, reply) {
|
|
147
|
-
testRequestValues(t, req, { ip: '1.1.1.1', protocol: 'lorem', host: 'fastify.test',
|
|
149
|
+
testRequestValues(t, req, { ip: '1.1.1.1', protocol: 'lorem', host: 'fastify.test:1234', hostname: 'fastify.test', port: 1234 })
|
|
148
150
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
149
151
|
})
|
|
150
152
|
app.get('/trustproxynoprotocol', function (req, reply) {
|
|
151
|
-
testRequestValues(t, req, { ip: '1.1.1.1', protocol: 'http', host: 'fastify.test',
|
|
153
|
+
testRequestValues(t, req, { ip: '1.1.1.1', protocol: 'http', host: 'fastify.test:1234', hostname: 'fastify.test', port: 1234 })
|
|
152
154
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
153
155
|
})
|
|
154
156
|
app.get('/trustproxyprotocols', function (req, reply) {
|
|
155
|
-
testRequestValues(t, req, { ip: '1.1.1.1', protocol: 'dolor', host: 'fastify.test',
|
|
157
|
+
testRequestValues(t, req, { ip: '1.1.1.1', protocol: 'dolor', host: 'fastify.test:1234', hostname: 'fastify.test', port: 1234 })
|
|
156
158
|
reply.code(200).send({ ip: req.ip, host: req.host })
|
|
157
159
|
})
|
|
158
160
|
|
|
159
161
|
const fastifyServer = await app.listen({ port: 0 })
|
|
160
162
|
|
|
161
|
-
await fetchForwardedRequest(fastifyServer, '1.1.1.1', '/trustproxyprotocol', 'lorem')
|
|
162
|
-
await fetchForwardedRequest(fastifyServer, '1.1.1.1', '/trustproxynoprotocol', undefined)
|
|
163
|
-
await fetchForwardedRequest(fastifyServer, '1.1.1.1', '/trustproxyprotocols', 'ipsum, dolor')
|
|
163
|
+
await fetchForwardedRequest(fastifyServer, '1.1.1.1', '/trustproxyprotocol', 'lorem', 'fastify.test:1234')
|
|
164
|
+
await fetchForwardedRequest(fastifyServer, '1.1.1.1', '/trustproxynoprotocol', undefined, 'fastify.test:1234')
|
|
165
|
+
await fetchForwardedRequest(fastifyServer, '1.1.1.1', '/trustproxyprotocols', 'ipsum, dolor', 'fastify.test:1234')
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
test('trust proxy port is null when x-forwarded-host has no port', async t => {
|
|
169
|
+
t.plan(5)
|
|
170
|
+
const app = fastify({
|
|
171
|
+
trustProxy: true
|
|
172
|
+
})
|
|
173
|
+
t.after(() => app.close())
|
|
174
|
+
|
|
175
|
+
app.get('/trustproxynoport', function (req, reply) {
|
|
176
|
+
// req.port is derived from req.host; a forwarded host without a port yields null
|
|
177
|
+
testRequestValues(t, req, { host: 'fastify.test', hostname: 'fastify.test', port: null })
|
|
178
|
+
reply.code(200).send({ host: req.host, port: req.port })
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
const fastifyServer = await app.listen({ port: 0 })
|
|
182
|
+
await fetchForwardedRequest(fastifyServer, '1.1.1.1', '/trustproxynoport', undefined)
|
|
164
183
|
})
|
|
165
184
|
|
|
166
185
|
test('trust proxy ignores forwarded headers from untrusted connections', async t => {
|
|
@@ -272,3 +291,24 @@ test('trust proxy with number and null socket remoteAddress', t => {
|
|
|
272
291
|
t.assert.ok(request.ip, 'ip is defined')
|
|
273
292
|
t.assert.strictEqual(request.ip, '1.1.1.1', 'gets ip from x-forwarded-for')
|
|
274
293
|
})
|
|
294
|
+
|
|
295
|
+
test('trust proxy does not trust x-forwarded-host/proto when socket is null', t => {
|
|
296
|
+
t.plan(2)
|
|
297
|
+
|
|
298
|
+
const headers = {
|
|
299
|
+
host: 'real.test',
|
|
300
|
+
'x-forwarded-host': 'spoofed.test',
|
|
301
|
+
'x-forwarded-proto': 'https'
|
|
302
|
+
}
|
|
303
|
+
const req = {
|
|
304
|
+
method: 'GET',
|
|
305
|
+
url: '/',
|
|
306
|
+
socket: null,
|
|
307
|
+
headers
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const TpRequest = buildRequest(Request, true)
|
|
311
|
+
const request = new TpRequest('id', 'params', req, 'query', 'log')
|
|
312
|
+
t.assert.strictEqual(request.host, 'real.test', 'falls back to host header')
|
|
313
|
+
t.assert.strictEqual(request.protocol, undefined, 'does not trust x-forwarded-proto')
|
|
314
|
+
})
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { IncomingMessage } from 'node:http'
|
|
2
|
+
import { expect } from 'tstyche'
|
|
3
|
+
import fastify, { FastifyBodyParser } from '../../fastify.js'
|
|
4
|
+
import { FastifyRequest } from '../../types/request.js'
|
|
5
|
+
|
|
6
|
+
expect(fastify().addContentTypeParser('contentType', function (request, payload, done) {
|
|
7
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
8
|
+
expect(payload).type.toBe<IncomingMessage>()
|
|
9
|
+
done(null)
|
|
10
|
+
})).type.toBe<void>()
|
|
11
|
+
|
|
12
|
+
// Body limit options
|
|
13
|
+
|
|
14
|
+
expect(fastify().addContentTypeParser('contentType', { bodyLimit: 99 }, function (request, payload, done) {
|
|
15
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
16
|
+
expect(payload).type.toBe<IncomingMessage>()
|
|
17
|
+
done(null)
|
|
18
|
+
})).type.toBe<void>()
|
|
19
|
+
|
|
20
|
+
// Array for contentType
|
|
21
|
+
|
|
22
|
+
expect(fastify().addContentTypeParser(['contentType'], function (request, payload, done) {
|
|
23
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
24
|
+
expect(payload).type.toBe<IncomingMessage>()
|
|
25
|
+
done(null)
|
|
26
|
+
})).type.toBe<void>()
|
|
27
|
+
|
|
28
|
+
// Body Parser - the generic after addContentTypeParser enforces the type of the `body` parameter as well as the value of the `parseAs` property
|
|
29
|
+
|
|
30
|
+
expect(fastify().addContentTypeParser<string>('bodyContentType', { parseAs: 'string' }, function (request, body, done) {
|
|
31
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
32
|
+
expect(body).type.toBe<string>()
|
|
33
|
+
done(null)
|
|
34
|
+
})).type.toBe<void>()
|
|
35
|
+
|
|
36
|
+
expect(fastify().addContentTypeParser<Buffer>('bodyContentType', { parseAs: 'buffer' }, function (request, body, done) {
|
|
37
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
38
|
+
expect(body).type.toBe<Buffer>()
|
|
39
|
+
done(null)
|
|
40
|
+
})).type.toBe<void>()
|
|
41
|
+
|
|
42
|
+
expect(fastify().addContentTypeParser('contentType', async function (request: FastifyRequest, payload: IncomingMessage) {
|
|
43
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
44
|
+
expect(payload).type.toBe<IncomingMessage>()
|
|
45
|
+
return null
|
|
46
|
+
})).type.toBe<void>()
|
|
47
|
+
|
|
48
|
+
expect(fastify().addContentTypeParser<string>('bodyContentType', { parseAs: 'string' }, async function (request: FastifyRequest, body: string) {
|
|
49
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
50
|
+
expect(body).type.toBe<string>()
|
|
51
|
+
return null
|
|
52
|
+
})).type.toBe<void>()
|
|
53
|
+
|
|
54
|
+
expect(fastify().addContentTypeParser<Buffer>('bodyContentType', { parseAs: 'buffer' }, async function (request: FastifyRequest, body: Buffer) {
|
|
55
|
+
expect(request).type.toBe<FastifyRequest>()
|
|
56
|
+
expect(body).type.toBe<Buffer>()
|
|
57
|
+
return null
|
|
58
|
+
})).type.toBe<void>()
|
|
59
|
+
|
|
60
|
+
expect(fastify().getDefaultJsonParser('error', 'ignore')).type.toBe<FastifyBodyParser<string>>()
|
|
61
|
+
expect(fastify().getDefaultJsonParser).type.not.toBeCallableWith('error', 'skip')
|
|
62
|
+
expect(fastify().getDefaultJsonParser).type.not.toBeCallableWith('nothing', 'ignore')
|
|
63
|
+
|
|
64
|
+
expect(fastify().removeAllContentTypeParsers()).type.toBe<void>()
|
|
65
|
+
expect(fastify().removeAllContentTypeParsers).type.not.toBeCallableWith('contentType')
|
|
66
|
+
|
|
67
|
+
expect(fastify().removeContentTypeParser('contentType')).type.toBe<void>()
|
|
68
|
+
expect(fastify().removeContentTypeParser(/contentType+.*/)).type.toBe<void>()
|
|
69
|
+
expect(fastify().removeContentTypeParser(['contentType', /contentType+.*/])).type.toBe<void>()
|
|
70
|
+
expect(fastify().removeContentTypeParser).type.not.toBeCallableWith({})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { expect } from 'tstyche'
|
|
2
|
+
import fastify from '../../fastify.js'
|
|
3
3
|
|
|
4
4
|
type TestType = void
|
|
5
5
|
|
|
@@ -13,6 +13,6 @@ declare module '../../fastify' {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
fastify().get('/', (req, res) => {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
expect(req.testProp).type.toBe<TestType>()
|
|
17
|
+
expect(res.testProp).type.toBe<TestType>()
|
|
18
18
|
})
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { FastifyErrorConstructor } from '@fastify/error'
|
|
2
|
+
import { expect } from 'tstyche'
|
|
3
|
+
import { errorCodes } from '../../fastify.js'
|
|
4
|
+
|
|
5
|
+
expect(errorCodes.FST_ERR_NOT_FOUND).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
6
|
+
expect(errorCodes.FST_ERR_OPTIONS_NOT_OBJ).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
7
|
+
expect(errorCodes.FST_ERR_QSP_NOT_FN).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
8
|
+
expect(errorCodes.FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
9
|
+
expect(errorCodes.FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
10
|
+
expect(errorCodes.FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
11
|
+
expect(errorCodes.FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
12
|
+
expect(errorCodes.FST_ERR_VALIDATION).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
13
|
+
expect(errorCodes.FST_ERR_LISTEN_OPTIONS_INVALID).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
14
|
+
expect(errorCodes.FST_ERR_ERROR_HANDLER_NOT_FN).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
15
|
+
expect(errorCodes.FST_ERR_ERROR_HANDLER_ALREADY_SET).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
16
|
+
expect(errorCodes.FST_ERR_CTP_ALREADY_PRESENT).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
17
|
+
expect(errorCodes.FST_ERR_CTP_INVALID_TYPE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
18
|
+
expect(errorCodes.FST_ERR_CTP_EMPTY_TYPE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
19
|
+
expect(errorCodes.FST_ERR_CTP_INVALID_HANDLER).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
20
|
+
expect(errorCodes.FST_ERR_CTP_INVALID_PARSE_TYPE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
21
|
+
expect(errorCodes.FST_ERR_CTP_BODY_TOO_LARGE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
22
|
+
expect(errorCodes.FST_ERR_CTP_INVALID_MEDIA_TYPE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
23
|
+
expect(errorCodes.FST_ERR_CTP_INVALID_CONTENT_LENGTH).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
24
|
+
expect(errorCodes.FST_ERR_CTP_EMPTY_JSON_BODY).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
25
|
+
expect(errorCodes.FST_ERR_CTP_INVALID_JSON_BODY).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
26
|
+
expect(errorCodes.FST_ERR_CTP_INSTANCE_ALREADY_STARTED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
27
|
+
expect(errorCodes.FST_ERR_DEC_ALREADY_PRESENT).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
28
|
+
expect(errorCodes.FST_ERR_DEC_DEPENDENCY_INVALID_TYPE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
29
|
+
expect(errorCodes.FST_ERR_DEC_MISSING_DEPENDENCY).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
30
|
+
expect(errorCodes.FST_ERR_DEC_AFTER_START).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
31
|
+
expect(errorCodes.FST_ERR_DEC_REFERENCE_TYPE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
32
|
+
expect(errorCodes.FST_ERR_DEC_UNDECLARED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
33
|
+
expect(errorCodes.FST_ERR_HOOK_INVALID_TYPE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
34
|
+
expect(errorCodes.FST_ERR_HOOK_INVALID_HANDLER).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
35
|
+
expect(errorCodes.FST_ERR_HOOK_INVALID_ASYNC_HANDLER).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
36
|
+
expect(errorCodes.FST_ERR_HOOK_NOT_SUPPORTED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
37
|
+
expect(errorCodes.FST_ERR_MISSING_MIDDLEWARE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
38
|
+
expect(errorCodes.FST_ERR_HOOK_TIMEOUT).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
39
|
+
expect(errorCodes.FST_ERR_LOG_INVALID_DESTINATION).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
40
|
+
expect(errorCodes.FST_ERR_LOG_INVALID_LOGGER).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
41
|
+
expect(errorCodes.FST_ERR_LOG_INVALID_LOGGER_INSTANCE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
42
|
+
expect(errorCodes.FST_ERR_LOG_INVALID_LOGGER_CONFIG).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
43
|
+
expect(errorCodes.FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
44
|
+
expect(errorCodes.FST_ERR_REP_INVALID_PAYLOAD_TYPE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
45
|
+
expect(errorCodes.FST_ERR_REP_RESPONSE_BODY_CONSUMED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
46
|
+
expect(errorCodes.FST_ERR_REP_READABLE_STREAM_LOCKED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
47
|
+
expect(errorCodes.FST_ERR_REP_ALREADY_SENT).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
48
|
+
expect(errorCodes.FST_ERR_REP_SENT_VALUE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
49
|
+
expect(errorCodes.FST_ERR_SEND_INSIDE_ONERR).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
50
|
+
expect(errorCodes.FST_ERR_SEND_UNDEFINED_ERR).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
51
|
+
expect(errorCodes.FST_ERR_BAD_STATUS_CODE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
52
|
+
expect(errorCodes.FST_ERR_BAD_TRAILER_NAME).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
53
|
+
expect(errorCodes.FST_ERR_BAD_TRAILER_VALUE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
54
|
+
expect(errorCodes.FST_ERR_FAILED_ERROR_SERIALIZATION).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
55
|
+
expect(errorCodes.FST_ERR_MISSING_SERIALIZATION_FN).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
56
|
+
expect(errorCodes.FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
57
|
+
expect(errorCodes.FST_ERR_REQ_INVALID_VALIDATION_INVOCATION).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
58
|
+
expect(errorCodes.FST_ERR_SCH_MISSING_ID).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
59
|
+
expect(errorCodes.FST_ERR_SCH_ALREADY_PRESENT).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
60
|
+
expect(errorCodes.FST_ERR_SCH_CONTENT_MISSING_SCHEMA).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
61
|
+
expect(errorCodes.FST_ERR_SCH_DUPLICATE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
62
|
+
expect(errorCodes.FST_ERR_SCH_VALIDATION_BUILD).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
63
|
+
expect(errorCodes.FST_ERR_SCH_SERIALIZATION_BUILD).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
64
|
+
expect(errorCodes.FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
65
|
+
expect(errorCodes.FST_ERR_INIT_OPTS_INVALID).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
66
|
+
expect(errorCodes.FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
67
|
+
expect(errorCodes.FST_ERR_DUPLICATED_ROUTE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
68
|
+
expect(errorCodes.FST_ERR_BAD_URL).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
69
|
+
expect(errorCodes.FST_ERR_ASYNC_CONSTRAINT).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
70
|
+
expect(errorCodes.FST_ERR_INVALID_URL).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
71
|
+
expect(errorCodes.FST_ERR_ROUTE_OPTIONS_NOT_OBJ).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
72
|
+
expect(errorCodes.FST_ERR_ROUTE_DUPLICATED_HANDLER).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
73
|
+
expect(errorCodes.FST_ERR_ROUTE_HANDLER_NOT_FN).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
74
|
+
expect(errorCodes.FST_ERR_ROUTE_MISSING_HANDLER).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
75
|
+
expect(errorCodes.FST_ERR_ROUTE_METHOD_INVALID).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
76
|
+
expect(errorCodes.FST_ERR_ROUTE_METHOD_NOT_SUPPORTED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
77
|
+
expect(errorCodes.FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
78
|
+
expect(errorCodes.FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
79
|
+
expect(errorCodes.FST_ERR_ROUTE_REWRITE_NOT_STR).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
80
|
+
expect(errorCodes.FST_ERR_REOPENED_CLOSE_SERVER).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
81
|
+
expect(errorCodes.FST_ERR_REOPENED_SERVER).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
82
|
+
expect(errorCodes.FST_ERR_INSTANCE_ALREADY_LISTENING).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
83
|
+
expect(errorCodes.FST_ERR_PLUGIN_VERSION_MISMATCH).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
84
|
+
expect(errorCodes.FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
85
|
+
expect(errorCodes.FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
86
|
+
expect(errorCodes.FST_ERR_PLUGIN_DEPENDENCY_NOT_REGISTERED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
87
|
+
expect(errorCodes.FST_ERR_PLUGIN_CALLBACK_NOT_FN).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
88
|
+
expect(errorCodes.FST_ERR_PLUGIN_NOT_VALID).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
89
|
+
expect(errorCodes.FST_ERR_ROOT_PLG_BOOTED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
90
|
+
expect(errorCodes.FST_ERR_PARENT_PLUGIN_BOOTED).type.toBeAssignableTo<FastifyErrorConstructor>()
|
|
91
|
+
expect(errorCodes.FST_ERR_PLUGIN_TIMEOUT).type.toBeAssignableTo<FastifyErrorConstructor>()
|