fastify 4.15.0 → 4.16.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 +3 -3
- package/docs/Guides/Database.md +7 -8
- package/docs/Guides/Ecosystem.md +16 -7
- package/docs/Guides/Getting-Started.md +1 -1
- package/docs/Guides/Migration-Guide-V4.md +21 -0
- package/docs/Guides/Plugins-Guide.md +1 -1
- package/docs/Guides/Prototype-Poisoning.md +31 -39
- package/docs/Guides/Recommendations.md +1 -1
- package/docs/Guides/Write-Type-Provider.md +3 -3
- package/docs/Reference/Hooks.md +42 -9
- package/docs/Reference/Reply.md +2 -2
- package/docs/Reference/Routes.md +13 -2
- package/docs/Reference/Server.md +19 -3
- package/docs/Reference/Type-Providers.md +1 -1
- package/docs/Reference/TypeScript.md +3 -3
- package/docs/index.md +2 -2
- package/examples/benchmark/parser.js +47 -0
- package/fastify.js +26 -23
- package/lib/error-serializer.js +9 -162
- package/lib/hooks.js +3 -0
- package/lib/server.js +9 -4
- package/lib/validation.js +10 -8
- package/lib/warnings.js +2 -0
- package/package.json +8 -7
- package/test/close.test.js +91 -0
- package/test/route-hooks.test.js +29 -0
- package/test/route.test.js +1 -1
- package/test/schema-feature.test.js +128 -35
- package/test/serial/logger.0.test.js +861 -0
- package/test/serial/logger.1.test.js +862 -0
- package/test/serial/tap-parallel-not-ok +0 -0
- package/test/server.test.js +10 -0
- package/test/types/hooks.test-d.ts +66 -11
- package/test/types/import.js +1 -1
- package/test/types/instance.test-d.ts +2 -0
- package/test/types/route.test-d.ts +106 -5
- package/test/types/type-provider.test-d.ts +77 -10
- package/types/hooks.d.ts +28 -0
- package/types/instance.d.ts +20 -1
- package/types/logger.d.ts +1 -1
- package/types/route.d.ts +41 -11
- package/test/logger.test.js +0 -1721
|
@@ -6,6 +6,7 @@ const fp = require('fastify-plugin')
|
|
|
6
6
|
const deepClone = require('rfdc')({ circles: true, proto: false })
|
|
7
7
|
const Ajv = require('ajv')
|
|
8
8
|
const { kSchemaController } = require('../lib/symbols.js')
|
|
9
|
+
const warning = require('../lib/warnings')
|
|
9
10
|
|
|
10
11
|
const echoParams = (req, reply) => { reply.send(req.params) }
|
|
11
12
|
const echoBody = (req, reply) => { reply.send(req.body) }
|
|
@@ -253,88 +254,180 @@ test('Should not change the input schemas', t => {
|
|
|
253
254
|
})
|
|
254
255
|
})
|
|
255
256
|
|
|
256
|
-
test('Should
|
|
257
|
-
t.plan(
|
|
257
|
+
test('Should emit warning if the schema headers is undefined', t => {
|
|
258
|
+
t.plan(4)
|
|
258
259
|
const fastify = Fastify()
|
|
259
260
|
|
|
260
|
-
|
|
261
|
+
process.on('warning', onWarning)
|
|
262
|
+
function onWarning (warning) {
|
|
263
|
+
t.equal(warning.name, 'FastifyWarning')
|
|
264
|
+
t.equal(warning.code, 'FSTWRN001')
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
t.teardown(() => {
|
|
268
|
+
process.removeListener('warning', onWarning)
|
|
269
|
+
warning.emitted.set('FSTWRN001', false)
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
fastify.post('/:id', {
|
|
261
273
|
handler: echoParams,
|
|
262
274
|
schema: {
|
|
263
|
-
|
|
275
|
+
headers: undefined
|
|
264
276
|
}
|
|
265
277
|
})
|
|
266
278
|
|
|
267
|
-
fastify.
|
|
268
|
-
|
|
269
|
-
|
|
279
|
+
fastify.inject({
|
|
280
|
+
method: 'POST',
|
|
281
|
+
url: '/123'
|
|
282
|
+
}, (error, res) => {
|
|
283
|
+
t.error(error)
|
|
284
|
+
t.equal(res.statusCode, 200)
|
|
270
285
|
})
|
|
271
286
|
})
|
|
272
287
|
|
|
273
|
-
test('Should
|
|
274
|
-
t.plan(
|
|
288
|
+
test('Should emit warning if the schema body is undefined', t => {
|
|
289
|
+
t.plan(4)
|
|
275
290
|
const fastify = Fastify()
|
|
276
291
|
|
|
277
|
-
|
|
292
|
+
process.on('warning', onWarning)
|
|
293
|
+
function onWarning (warning) {
|
|
294
|
+
t.equal(warning.name, 'FastifyWarning')
|
|
295
|
+
t.equal(warning.code, 'FSTWRN001')
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
t.teardown(() => {
|
|
299
|
+
process.removeListener('warning', onWarning)
|
|
300
|
+
warning.emitted.set('FSTWRN001', false)
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
fastify.post('/:id', {
|
|
278
304
|
handler: echoParams,
|
|
279
305
|
schema: {
|
|
280
|
-
|
|
306
|
+
body: undefined
|
|
281
307
|
}
|
|
282
308
|
})
|
|
283
309
|
|
|
284
|
-
fastify.
|
|
285
|
-
|
|
286
|
-
|
|
310
|
+
fastify.inject({
|
|
311
|
+
method: 'POST',
|
|
312
|
+
url: '/123'
|
|
313
|
+
}, (error, res) => {
|
|
314
|
+
t.error(error)
|
|
315
|
+
t.equal(res.statusCode, 200)
|
|
287
316
|
})
|
|
288
317
|
})
|
|
289
318
|
|
|
290
|
-
test('Should
|
|
291
|
-
t.plan(
|
|
319
|
+
test('Should emit warning if the schema query is undefined', t => {
|
|
320
|
+
t.plan(4)
|
|
292
321
|
const fastify = Fastify()
|
|
293
322
|
|
|
294
|
-
|
|
323
|
+
process.on('warning', onWarning)
|
|
324
|
+
function onWarning (warning) {
|
|
325
|
+
t.equal(warning.name, 'FastifyWarning')
|
|
326
|
+
t.equal(warning.code, 'FSTWRN001')
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
t.teardown(() => {
|
|
330
|
+
process.removeListener('warning', onWarning)
|
|
331
|
+
warning.emitted.set('FSTWRN001', false)
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
fastify.post('/:id', {
|
|
295
335
|
handler: echoParams,
|
|
296
336
|
schema: {
|
|
297
|
-
|
|
337
|
+
querystring: undefined
|
|
298
338
|
}
|
|
299
339
|
})
|
|
300
340
|
|
|
301
|
-
fastify.
|
|
302
|
-
|
|
303
|
-
|
|
341
|
+
fastify.inject({
|
|
342
|
+
method: 'POST',
|
|
343
|
+
url: '/123'
|
|
344
|
+
}, (error, res) => {
|
|
345
|
+
t.error(error)
|
|
346
|
+
t.equal(res.statusCode, 200)
|
|
304
347
|
})
|
|
305
348
|
})
|
|
306
349
|
|
|
307
|
-
test('Should
|
|
308
|
-
t.plan(
|
|
350
|
+
test('Should emit warning if the schema params is undefined', t => {
|
|
351
|
+
t.plan(4)
|
|
309
352
|
const fastify = Fastify()
|
|
310
353
|
|
|
311
|
-
|
|
354
|
+
process.on('warning', onWarning)
|
|
355
|
+
function onWarning (warning) {
|
|
356
|
+
t.equal(warning.name, 'FastifyWarning')
|
|
357
|
+
t.equal(warning.code, 'FSTWRN001')
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
t.teardown(() => {
|
|
361
|
+
process.removeListener('warning', onWarning)
|
|
362
|
+
warning.emitted.set('FSTWRN001', false)
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
fastify.post('/:id', {
|
|
312
366
|
handler: echoParams,
|
|
313
367
|
schema: {
|
|
314
|
-
|
|
368
|
+
params: undefined
|
|
315
369
|
}
|
|
316
370
|
})
|
|
317
371
|
|
|
318
|
-
fastify.
|
|
319
|
-
|
|
320
|
-
|
|
372
|
+
fastify.inject({
|
|
373
|
+
method: 'POST',
|
|
374
|
+
url: '/123'
|
|
375
|
+
}, (error, res) => {
|
|
376
|
+
t.error(error)
|
|
377
|
+
t.equal(res.statusCode, 200)
|
|
321
378
|
})
|
|
322
379
|
})
|
|
323
380
|
|
|
324
|
-
test('Should
|
|
325
|
-
t.plan(
|
|
381
|
+
test('Should emit a warning for every route with undefined schema', t => {
|
|
382
|
+
t.plan(16)
|
|
326
383
|
const fastify = Fastify()
|
|
327
384
|
|
|
328
|
-
|
|
385
|
+
let runs = 0
|
|
386
|
+
const expectedWarningEmitted = [0, 1, 2, 3]
|
|
387
|
+
// It emits 4 warnings:
|
|
388
|
+
// - 2 - GET and HEAD for /undefinedParams/:id
|
|
389
|
+
// - 2 - GET and HEAD for /undefinedBody/:id
|
|
390
|
+
// => 3 x 4 assertions = 12 assertions
|
|
391
|
+
function onWarning (warning) {
|
|
392
|
+
t.equal(warning.name, 'FastifyWarning')
|
|
393
|
+
t.equal(warning.code, 'FSTWRN001')
|
|
394
|
+
t.equal(runs++, expectedWarningEmitted.shift())
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
process.on('warning', onWarning)
|
|
398
|
+
t.teardown(() => {
|
|
399
|
+
process.removeListener('warning', onWarning)
|
|
400
|
+
warning.emitted.set('FSTWRN001', false)
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
fastify.get('/undefinedParams/:id', {
|
|
329
404
|
handler: echoParams,
|
|
330
405
|
schema: {
|
|
331
|
-
|
|
406
|
+
params: undefined
|
|
332
407
|
}
|
|
333
408
|
})
|
|
334
409
|
|
|
335
|
-
fastify.
|
|
336
|
-
|
|
337
|
-
|
|
410
|
+
fastify.get('/undefinedBody/:id', {
|
|
411
|
+
handler: echoParams,
|
|
412
|
+
schema: {
|
|
413
|
+
body: undefined
|
|
414
|
+
}
|
|
415
|
+
})
|
|
416
|
+
|
|
417
|
+
fastify.inject({
|
|
418
|
+
method: 'GET',
|
|
419
|
+
url: '/undefinedParams/123'
|
|
420
|
+
}, (error, res) => {
|
|
421
|
+
t.error(error)
|
|
422
|
+
t.equal(res.statusCode, 200)
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
fastify.inject({
|
|
426
|
+
method: 'GET',
|
|
427
|
+
url: '/undefinedBody/123'
|
|
428
|
+
}, (error, res) => {
|
|
429
|
+
t.error(error)
|
|
430
|
+
t.equal(res.statusCode, 200)
|
|
338
431
|
})
|
|
339
432
|
})
|
|
340
433
|
|