fastify 3.9.2 → 3.12.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.
Files changed (92) hide show
  1. package/GOVERNANCE.md +1 -1
  2. package/README.md +12 -8
  3. package/SECURITY.md +3 -3
  4. package/docs/ContentTypeParser.md +1 -1
  5. package/docs/Ecosystem.md +16 -6
  6. package/docs/Encapsulation.md +5 -2
  7. package/docs/Fluent-Schema.md +4 -4
  8. package/docs/Getting-Started.md +1 -1
  9. package/docs/Hooks.md +28 -1
  10. package/docs/Lifecycle.md +8 -1
  11. package/docs/Middleware.md +5 -4
  12. package/docs/Reply.md +13 -4
  13. package/docs/Routes.md +4 -3
  14. package/docs/Server.md +78 -4
  15. package/docs/Serverless.md +23 -51
  16. package/docs/TypeScript.md +35 -18
  17. package/docs/Validation-and-Serialization.md +4 -4
  18. package/docs/Write-Plugin.md +4 -4
  19. package/examples/hooks-benchmark.js +12 -12
  20. package/examples/hooks.js +16 -16
  21. package/examples/plugin.js +2 -2
  22. package/examples/route-prefix.js +4 -4
  23. package/fastify.d.ts +16 -1
  24. package/fastify.js +33 -16
  25. package/isolate-0x426d1e0-1227-v8.log +4019 -0
  26. package/isolate-0x4d4c7e0-1988-v8.log +4081 -0
  27. package/lib/errors.js +6 -0
  28. package/lib/headRoute.js +31 -0
  29. package/lib/pluginOverride.js +5 -5
  30. package/lib/pluginUtils.js +7 -6
  31. package/lib/reply.js +14 -2
  32. package/lib/reqIdGenFactory.js +5 -0
  33. package/lib/request.js +1 -1
  34. package/lib/route.js +66 -41
  35. package/lib/schema-compilers.js +5 -3
  36. package/lib/schema-controller.js +106 -0
  37. package/lib/schemas.js +14 -24
  38. package/lib/server.js +1 -0
  39. package/lib/symbols.js +1 -3
  40. package/lib/warnings.js +2 -0
  41. package/lib/wrapThenable.js +2 -1
  42. package/package.json +25 -21
  43. package/test/404s.test.js +120 -120
  44. package/test/500s.test.js +8 -8
  45. package/test/async-await.test.js +29 -1
  46. package/test/close.test.js +8 -8
  47. package/test/context-config.test.js +52 -0
  48. package/test/custom-parser.test.js +8 -8
  49. package/test/decorator.test.js +49 -49
  50. package/test/default-route.test.js +43 -0
  51. package/test/fastify-instance.test.js +2 -2
  52. package/test/fluent-schema.test.js +3 -3
  53. package/test/handler-context.test.js +2 -2
  54. package/test/hooks-async.test.js +3 -3
  55. package/test/hooks.on-ready.test.js +12 -12
  56. package/test/hooks.test.js +75 -32
  57. package/test/http2/closing.test.js +23 -1
  58. package/test/inject.test.js +6 -6
  59. package/test/input-validation.js +2 -2
  60. package/test/internals/hookRunner.test.js +50 -50
  61. package/test/internals/reply.test.js +47 -22
  62. package/test/internals/request.test.js +3 -9
  63. package/test/internals/version.test.js +2 -2
  64. package/test/logger.test.js +30 -30
  65. package/test/middleware.test.js +4 -4
  66. package/test/plugin.helper.js +2 -2
  67. package/test/plugin.test.js +154 -99
  68. package/test/register.test.js +11 -11
  69. package/test/request-error.test.js +2 -2
  70. package/test/route-hooks.test.js +24 -24
  71. package/test/route-prefix.test.js +81 -52
  72. package/test/route.test.js +568 -0
  73. package/test/schema-feature.test.js +168 -38
  74. package/test/schema-serialization.test.js +4 -4
  75. package/test/schema-special-usage.test.js +136 -0
  76. package/test/schema-validation.test.js +7 -7
  77. package/test/skip-reply-send.test.js +315 -0
  78. package/test/stream.test.js +6 -6
  79. package/test/throw.test.js +4 -4
  80. package/test/types/instance.test-d.ts +5 -3
  81. package/test/types/plugin.test-d.ts +7 -7
  82. package/test/types/reply.test-d.ts +1 -0
  83. package/test/types/schema.test-d.ts +15 -0
  84. package/test/validation-error-handling.test.js +5 -5
  85. package/test/versioned-routes.test.js +1 -1
  86. package/types/content-type-parser.d.ts +1 -1
  87. package/types/instance.d.ts +6 -3
  88. package/types/plugin.d.ts +1 -1
  89. package/types/reply.d.ts +1 -0
  90. package/types/route.d.ts +8 -2
  91. package/types/schema.d.ts +3 -0
  92. package/test/skip-reply-send.js +0 -98
@@ -1,98 +0,0 @@
1
- 'use strict'
2
-
3
- const { test } = require('tap')
4
- const split = require('split2')
5
- const Fastify = require('..')
6
-
7
- test('skip automatic reply.send() with reply.sent = true and a body', (t) => {
8
- const stream = split(JSON.parse)
9
- const app = Fastify({
10
- logger: {
11
- stream: stream
12
- }
13
- })
14
-
15
- stream.on('data', (line) => {
16
- t.notEqual(line.level, 40) // there are no errors
17
- t.notEqual(line.level, 50) // there are no errors
18
- })
19
-
20
- app.get('/', (req, reply) => {
21
- reply.sent = true
22
- reply.raw.end('hello world')
23
-
24
- return Promise.resolve('this will be skipped')
25
- })
26
-
27
- return app.inject({
28
- method: 'GET',
29
- url: '/'
30
- }).then((res) => {
31
- t.equal(res.statusCode, 200)
32
- t.equal(res.body, 'hello world')
33
- })
34
- })
35
-
36
- test('skip automatic reply.send() with reply.sent = true and no body', (t) => {
37
- const stream = split(JSON.parse)
38
- const app = Fastify({
39
- logger: {
40
- stream: stream
41
- }
42
- })
43
-
44
- stream.on('data', (line) => {
45
- t.notEqual(line.level, 40) // there are no error
46
- t.notEqual(line.level, 50) // there are no error
47
- })
48
-
49
- app.get('/', (req, reply) => {
50
- reply.sent = true
51
- reply.raw.end('hello world')
52
-
53
- return Promise.resolve()
54
- })
55
-
56
- return app.inject({
57
- method: 'GET',
58
- url: '/'
59
- }).then((res) => {
60
- t.equal(res.statusCode, 200)
61
- t.equal(res.body, 'hello world')
62
- })
63
- })
64
-
65
- test('skip automatic reply.send() with reply.sent = true and an error', (t) => {
66
- const stream = split(JSON.parse)
67
- const app = Fastify({
68
- logger: {
69
- stream: stream
70
- }
71
- })
72
-
73
- let errorSeen = false
74
-
75
- stream.on('data', (line) => {
76
- if (line.level === 50) {
77
- errorSeen = true
78
- t.equal(line.err.message, 'kaboom')
79
- t.equal(line.msg, 'Promise errored, but reply.sent = true was set')
80
- }
81
- })
82
-
83
- app.get('/', (req, reply) => {
84
- reply.sent = true
85
- reply.raw.end('hello world')
86
-
87
- return Promise.reject(new Error('kaboom'))
88
- })
89
-
90
- return app.inject({
91
- method: 'GET',
92
- url: '/'
93
- }).then((res) => {
94
- t.equal(errorSeen, true)
95
- t.equal(res.statusCode, 200)
96
- t.equal(res.body, 'hello world')
97
- })
98
- })