fastify 5.8.4 → 5.9.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 (105) hide show
  1. package/SECURITY.md +1 -1
  2. package/SPONSORS.md +6 -4
  3. package/docs/Guides/Database.md +0 -28
  4. package/docs/Guides/Ecosystem.md +17 -2
  5. package/docs/Guides/Serverless.md +2 -2
  6. package/docs/Guides/Write-Plugin.md +1 -1
  7. package/docs/Reference/Encapsulation.md +27 -26
  8. package/docs/Reference/Errors.md +10 -4
  9. package/docs/Reference/HTTP2.md +10 -10
  10. package/docs/Reference/Hooks.md +4 -4
  11. package/docs/Reference/Index.md +14 -16
  12. package/docs/Reference/LTS.md +12 -13
  13. package/docs/Reference/Lifecycle.md +9 -8
  14. package/docs/Reference/Logging.md +44 -39
  15. package/docs/Reference/Middleware.md +21 -25
  16. package/docs/Reference/Principles.md +2 -2
  17. package/docs/Reference/Reply.md +6 -1
  18. package/docs/Reference/Request.md +27 -16
  19. package/docs/Reference/Routes.md +5 -2
  20. package/docs/Reference/Server.md +31 -3
  21. package/docs/Reference/Type-Providers.md +29 -5
  22. package/docs/Reference/Validation-and-Serialization.md +15 -2
  23. package/docs/Reference/Warnings.md +7 -6
  24. package/eslint.config.js +7 -2
  25. package/fastify.d.ts +8 -3
  26. package/fastify.js +43 -14
  27. package/lib/content-type-parser.js +13 -1
  28. package/lib/decorate.js +11 -3
  29. package/lib/error-handler.js +4 -3
  30. package/lib/error-serializer.js +59 -59
  31. package/lib/errors.js +16 -1
  32. package/lib/four-oh-four.js +14 -9
  33. package/lib/handle-request.js +11 -5
  34. package/lib/plugin-override.js +2 -1
  35. package/lib/plugin-utils.js +5 -5
  36. package/lib/reply.js +63 -8
  37. package/lib/request.js +23 -19
  38. package/lib/route.js +20 -6
  39. package/lib/schema-controller.js +1 -1
  40. package/lib/schemas.js +37 -30
  41. package/lib/symbols.js +3 -1
  42. package/lib/validation.js +1 -13
  43. package/lib/warnings.js +3 -3
  44. package/package.json +16 -18
  45. package/scripts/validate-ecosystem-links.js +1 -0
  46. package/test/bundler/esbuild/package.json +1 -1
  47. package/test/close-pipelining.test.js +1 -2
  48. package/test/custom-http-server.test.js +38 -0
  49. package/test/decorator-instance-properties.test.js +63 -0
  50. package/test/diagnostics-channel/async-error-handler.test.js +74 -0
  51. package/test/hooks.test.js +23 -0
  52. package/test/http-methods/get.test.js +1 -1
  53. package/test/http2/plain.test.js +135 -0
  54. package/test/http2/secure-with-fallback.test.js +1 -1
  55. package/test/https/https.test.js +1 -2
  56. package/test/internals/errors.test.js +31 -1
  57. package/test/internals/plugin.test.js +3 -1
  58. package/test/internals/request.test.js +27 -3
  59. package/test/internals/schema-controller-perf.test.js +33 -0
  60. package/test/logger/logging.test.js +18 -1
  61. package/test/logger/options.test.js +38 -1
  62. package/test/reply-error.test.js +1 -1
  63. package/test/reply-trailers.test.js +70 -0
  64. package/test/request-media-type.test.js +105 -0
  65. package/test/request-port.test.js +72 -0
  66. package/test/route-prefix.test.js +34 -0
  67. package/test/router-options.test.js +222 -11
  68. package/test/schema-serialization.test.js +108 -0
  69. package/test/schema-validation.test.js +45 -0
  70. package/test/scripts/validate-ecosystem-links.test.js +40 -57
  71. package/test/throw.test.js +14 -0
  72. package/test/trust-proxy.test.js +74 -0
  73. package/test/types/content-type-parser.tst.ts +70 -0
  74. package/test/types/{decorate-request-reply.test-d.ts → decorate-request-reply.tst.ts} +4 -4
  75. package/test/types/{dummy-plugin.ts → dummy-plugin.mts} +1 -1
  76. package/test/types/errors.tst.ts +91 -0
  77. package/test/types/fastify.tst.ts +351 -0
  78. package/test/types/hooks.tst.ts +578 -0
  79. package/test/types/instance.tst.ts +597 -0
  80. package/test/types/{logger.test-d.ts → logger.tst.ts} +61 -62
  81. package/test/types/plugin.tst.ts +96 -0
  82. package/test/types/register.tst.ts +245 -0
  83. package/test/types/reply.tst.ts +297 -0
  84. package/test/types/request.tst.ts +199 -0
  85. package/test/types/route.tst.ts +576 -0
  86. package/test/types/{schema.test-d.ts → schema.tst.ts} +22 -22
  87. package/test/types/{serverFactory.test-d.ts → serverFactory.tst.ts} +4 -4
  88. package/test/types/tsconfig.json +9 -0
  89. package/test/types/{type-provider.test-d.ts → type-provider.tst.ts} +256 -250
  90. package/test/types/using.tst.ts +14 -0
  91. package/types/errors.d.ts +3 -0
  92. package/types/request.d.ts +23 -2
  93. package/AGENTS.md +0 -290
  94. package/test/types/content-type-parser.test-d.ts +0 -72
  95. package/test/types/errors.test-d.ts +0 -90
  96. package/test/types/fastify.test-d.ts +0 -352
  97. package/test/types/hooks.test-d.ts +0 -550
  98. package/test/types/import.ts +0 -2
  99. package/test/types/instance.test-d.ts +0 -588
  100. package/test/types/plugin.test-d.ts +0 -97
  101. package/test/types/register.test-d.ts +0 -237
  102. package/test/types/reply.test-d.ts +0 -254
  103. package/test/types/request.test-d.ts +0 -188
  104. package/test/types/route.test-d.ts +0 -553
  105. package/test/types/using.test-d.ts +0 -17
@@ -0,0 +1,14 @@
1
+ import { expect, test } from 'tstyche'
2
+ import fastify, { FastifyInstance } from '../../fastify.js'
3
+
4
+ test("has 'Symbol.dispose' when declared with 'using'", async () => {
5
+ await using app = fastify()
6
+ expect(app).type.toBeAssignableTo<FastifyInstance>()
7
+ expect(app[Symbol.asyncDispose]).type.toBe<() => Promise<undefined>>()
8
+ })
9
+
10
+ test("has 'Symbol.dispose'", async () => {
11
+ await using app = fastify()
12
+ expect(app).type.toBeAssignableTo<FastifyInstance>()
13
+ expect(app[Symbol.asyncDispose]).type.toBe<() => Promise<undefined>>()
14
+ })
package/types/errors.d.ts CHANGED
@@ -65,6 +65,7 @@ export type FastifyErrorCodes = Record<
65
65
  'FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE' |
66
66
  'FST_ERR_DUPLICATED_ROUTE' |
67
67
  'FST_ERR_BAD_URL' |
68
+ 'FST_ERR_MAX_PARAM_LENGTH' |
68
69
  'FST_ERR_ASYNC_CONSTRAINT' |
69
70
  'FST_ERR_INVALID_URL' |
70
71
  'FST_ERR_ROUTE_OPTIONS_NOT_OBJ' |
@@ -73,6 +74,7 @@ export type FastifyErrorCodes = Record<
73
74
  'FST_ERR_ROUTE_MISSING_HANDLER' |
74
75
  'FST_ERR_ROUTE_METHOD_INVALID' |
75
76
  'FST_ERR_ROUTE_METHOD_NOT_SUPPORTED' |
77
+ 'FST_ERR_ROUTE_LOG_LEVEL_INVALID' |
76
78
  'FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED' |
77
79
  'FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT' |
78
80
  'FST_ERR_HANDLER_TIMEOUT' |
@@ -84,6 +86,7 @@ export type FastifyErrorCodes = Record<
84
86
  'FST_ERR_PLUGIN_VERSION_MISMATCH' |
85
87
  'FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE' |
86
88
  'FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER' |
89
+ 'FST_ERR_PLUGIN_DEPENDENCY_NOT_REGISTERED' |
87
90
  'FST_ERR_PLUGIN_CALLBACK_NOT_FN' |
88
91
  'FST_ERR_PLUGIN_NOT_VALID' |
89
92
  'FST_ERR_ROOT_PLG_BOOTED' |
@@ -71,22 +71,43 @@ export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = Rou
71
71
  * @deprecated Use `raw` property
72
72
  */
73
73
  readonly req: RawRequest & RouteGeneric['Headers']; // this enables the developer to extend the existing http(s|2) headers list
74
+ /**
75
+ * Derived from request socket metadata or forwarding headers.
76
+ * Treat as untrusted input and validate before security-sensitive use.
77
+ */
74
78
  readonly ip: string;
79
+ /**
80
+ * Derived from forwarding headers when trustProxy is enabled.
81
+ * Treat as untrusted input and validate before security-sensitive use.
82
+ */
75
83
  readonly ips?: string[];
84
+ /**
85
+ * Derived from Host/:authority/X-Forwarded-Host request metadata.
86
+ * Treat as untrusted input and validate before security-sensitive use.
87
+ */
76
88
  readonly host: string;
89
+ /**
90
+ * Parsed from request host metadata.
91
+ * Treat as untrusted input and validate before security-sensitive use.
92
+ */
77
93
  readonly port: number | null;
78
94
  readonly hostname: string;
79
95
  readonly url: string;
80
96
  readonly originalUrl: string;
97
+ /**
98
+ * Derived from socket state or forwarding headers.
99
+ * Treat as untrusted input and validate before security-sensitive use.
100
+ */
81
101
  readonly protocol: 'http' | 'https';
82
102
  readonly method: string;
83
103
  readonly routeOptions: Readonly<RequestRouteOptions<ContextConfig, SchemaCompiler>>
84
104
  readonly is404: boolean;
85
105
  readonly socket: RawRequest['socket'];
86
106
  readonly signal: AbortSignal;
107
+ readonly mediaType: string | undefined;
87
108
 
88
- getValidationFunction(httpPart: HTTPRequestPart): ValidationFunction
89
- getValidationFunction(schema: { [key: string]: any }): ValidationFunction
109
+ getValidationFunction(httpPart: HTTPRequestPart): ValidationFunction | undefined
110
+ getValidationFunction(schema: { [key: string]: any }): ValidationFunction | undefined
90
111
  compileValidationSchema(schema: { [key: string]: any }, httpPart?: HTTPRequestPart): ValidationFunction
91
112
  validateInput(input: any, schema: { [key: string]: any }, httpPart?: HTTPRequestPart): boolean
92
113
  validateInput(input: any, httpPart?: HTTPRequestPart): boolean
package/AGENTS.md DELETED
@@ -1,290 +0,0 @@
1
- # AGENTS.md - Guide for AI Agents Working with Fastify
2
-
3
- This document provides information and guidelines for AI agents (such as GitHub Copilot, Cursor, pi, or other AI coding assistants) working with the Fastify codebase.
4
-
5
- ## Project Overview
6
-
7
- Fastify is a high-performance web framework for Node.js focused on:
8
- - **Speed**: One of the fastest Node.js web frameworks
9
- - **Extensibility**: Powerful plugin architecture with hooks and decorators
10
- - **Schema-based**: JSON Schema validation and serialization
11
- - **Developer experience**: Expressive API with minimal overhead
12
- - **TypeScript support**: Full type definitions included
13
-
14
- **Current Version**: 5.7.1 (main branch)
15
- **Repository**: https://github.com/fastify/fastify
16
-
17
- ## Repository Structure
18
-
19
- ```
20
- fastify/
21
- ├── docs/ # Documentation (Guides and Reference)
22
- │ ├── Guides/ # Tutorials and how-to guides
23
- │ └── Reference/ # API documentation
24
- ├── examples/ # Example applications and benchmarks
25
- ├── lib/ # Core library code
26
- ├── test/ # Test files
27
- ├── types/ # TypeScript type definitions
28
- ├── build/ # Build scripts
29
- ├── integration/ # Integration tests
30
- ├── fastify.js # Main entry point
31
- ├── fastify.d.ts # Main TypeScript definitions
32
- └── package.json # Dependencies and scripts
33
- ```
34
-
35
- ## Key Files for Agents
36
-
37
- ### Core Files
38
- - **`fastify.js`** - Main Fastify class and entry point
39
- - **`fastify.d.ts`** - TypeScript type definitions (keep these in sync)
40
- - **`lib/`** - All core functionality:
41
- - `route.js` - Route handling
42
- - `req-res.js` - Request and Reply objects
43
- - `hooks.js` - Lifecycle hooks
44
- - `plugin.js` - Plugin system
45
- - `validation.js` - Schema validation
46
- - `content-type-parser.js` - Body parsing
47
- - `logger.js` - Pino logger integration
48
-
49
- ### Configuration Files
50
- - **`package.json`** - Scripts, dependencies, and contributors
51
- - **`eslint.config.js`** - Linting configuration (uses neostandard)
52
- - **`.markdownlint-cli2.yaml`** - Markdown linting rules
53
-
54
- ### Documentation Files
55
- - **`README.md`** - Project overview and quick start
56
- - **`CONTRIBUTING.md`** - Contribution guidelines
57
- - **`GOVERNANCE.md`** - Links to organization governance
58
- - **`SECURITY.md`** - Security policy
59
- - **`docs/Guides/Contributing.md`** - Detailed contributing guide
60
- - **`docs/Guides/Style-Guide.md`** - Coding style conventions
61
-
62
- ## Testing Conventions
63
-
64
- ### Test Framework
65
- Fastify uses **Borp** (a custom test runner) for testing.
66
-
67
- ### Test Structure
68
- - Tests are in the **`test/`** directory
69
- - Test files follow the pattern: `test/<module>.test.js`
70
- - Integration tests are in **`integration/`** directory
71
-
72
- ### Running Tests
73
-
74
- ```bash
75
- # Run all tests
76
- npm test
77
-
78
- # Run unit tests only
79
- npm run unit
80
-
81
- # Run tests with coverage
82
- npm run coverage
83
-
84
- # Run tests in watch mode
85
- npm run test:watch
86
-
87
- # Run TypeScript type tests
88
- npm run test:typescript
89
-
90
- # Run CI tests (minimal)
91
- npm run test:ci
92
- ```
93
-
94
- ### Test Requirements
95
- - **100% line coverage** is required for all changes (enforced by CI)
96
- - Tests must pass on all supported Node.js versions
97
- - TypeScript types must be tested (using `tsd`)
98
-
99
- ## Code Style and Conventions
100
-
101
- ### Linting
102
- - Uses **Neostandard** JavaScript style guide
103
- - ESLint is configured in `eslint.config.js`
104
- - Run `npm run lint` to check code style
105
- - Run `npm run lint:fix` to auto-fix issues
106
-
107
- ### Key Style Rules (from Style-Guide.md)
108
- - Use `const` and `let`, never `var`
109
- - Use arrow functions for callbacks
110
- - Use async/await instead of promises
111
- - Follow semicolon usage (neostandard enforces this)
112
- - Use template literals for string interpolation
113
- - Prefer functional methods (`map`, `filter`, `reduce`) over loops
114
- - Error-first callback pattern for async operations where needed
115
-
116
- ### Naming Conventions
117
- - **Files**: kebab-case (`content-type-parser.js`)
118
- - **Variables**: camelCase
119
- - **Constants**: UPPER_SNAKE_CASE
120
- - **Classes**: PascalCase
121
- - **Private methods**: prefixed with `_`
122
-
123
- ## Common Tasks
124
-
125
- ### Adding a New Feature
126
- 1. Implement the feature in `lib/`
127
- 2. Add tests in `test/`
128
- 3. Update TypeScript types in `fastify.d.ts` or `types/`
129
- 4. Update documentation in `docs/`
130
- 5. Run `npm test` to ensure all tests pass
131
- 6. Run `npm run lint` to check code style
132
- 7. Add changelog entry for release
133
-
134
- ### Fixing a Bug
135
- 1. Add a failing test case in `test/`
136
- 2. Fix the bug in `lib/`
137
- 3. Ensure all tests pass
138
- 4. Check if TypeScript types need updating
139
- 5. Update documentation if behavior changes
140
-
141
- ### Working with Plugins
142
- - See `docs/Guides/Write-Plugin.md` for plugin authoring
143
- - See `docs/Guides/Plugins-Guide.md` for plugin usage
144
- - Plugin example: `lib/plugin.js`
145
-
146
- ## Architecture Highlights
147
-
148
- ### Core Components
149
-
150
- 1. **Server (`fastify.js`)**
151
- - Main Fastify class
152
- - Server initialization and configuration
153
- - Plugin system integration (via `avvio`)
154
-
155
- 2. **Routing (`lib/route.js`)**
156
- - Uses `find-my-way` for fast route matching
157
- - Route registration and lookup
158
- - Shorthand methods (get, post, put, delete, etc.)
159
-
160
- 3. **Request/Response (`lib/req-res.js`)**
161
- - Request object extensions
162
- - Reply object with fluent API
163
- - Decorator support
164
-
165
- 4. **Hooks (`lib/hooks.js`)**
166
- - Lifecycle hooks (onRequest, preHandler, etc.)
167
- - Hook execution order and timing
168
-
169
- 5. **Validation (`lib/validation.js`)**
170
- - JSON Schema validation via AJV
171
- - Response serialization
172
- - Built-in error serializer
173
-
174
- 6. **Content Type Parser (`lib/content-type-parser.js`)**
175
- - Request body parsing
176
- - Custom parser support
177
- - JSON and other formats
178
-
179
- ### Plugin System
180
- - Plugins are loaded asynchronously via `avvio`
181
- - Supports encapsulation (scoped plugins)
182
- - Hooks and decorators can be scoped
183
- - See `lib/plugin.js` for implementation
184
-
185
- ## TypeScript Integration
186
-
187
- - TypeScript definitions are in `fastify.d.ts` and `types/`
188
- - Types must be tested with `tsd`
189
- - Run `npm run test:typescript` to verify types
190
- - Keep types in sync with JavaScript implementation
191
-
192
- ## Performance Considerations
193
-
194
- Fastify prioritizes performance:
195
- - **Routes**: Pre-compiled functions for fast matching
196
- - **Validation**: Compiled JSON Schema validators
197
- - **Serialization**: Compiled serializers (fast-json-stringify)
198
- - **Logging**: Low-overhead Pino logger
199
- - **Caching**: Route context caching with `toad-cache`
200
-
201
- When making changes:
202
- - Profile performance impact for hot paths
203
- - Use benchmarks in `examples/benchmark/`
204
- - Run `npm run benchmark` to measure
205
-
206
- ## Documentation Updates
207
-
208
- Documentation is critical for Fastify. When changing behavior:
209
-
210
- 1. Update relevant docs in `docs/Reference/` for API changes
211
- 2. Update `docs/Guides/` for usage pattern changes
212
- 3. Check for broken links (CI validates this)
213
- 4. Update examples in `examples/` if needed
214
- 5. Run `npm run lint:markdown` to check docs
215
-
216
- ## Pre-commit Checks
217
-
218
- Before submitting changes, ensure:
219
-
220
- 1. ✅ All tests pass: `npm test`
221
- 2. ✅ 100% coverage: `npm run coverage`
222
- 3. ✅ Linting passes: `npm run lint`
223
- 4. ✅ TypeScript types pass: `npm run test:typescript`
224
- 5. ✅ Markdown linting passes: `npm run lint:markdown`
225
- 6. ✅ Documentation is updated
226
- 7. ✅ Examples still work if affected
227
-
228
- ## Working with CI
229
-
230
- Fastify uses GitHub Actions for CI. Workflows are in `.github/workflows/`:
231
- - **`ci.yml`** - Main CI pipeline
232
- - **`package-manager-ci.yml`** - Tests multiple package managers
233
- - **`website.yml`** - Website deployment
234
-
235
- ## Agent-Specific Tips
236
-
237
- ### When Generating Code
238
- 1. Check existing patterns in `lib/` before creating new patterns
239
- 2. Follow the established error handling patterns
240
- 3. Use async/await consistently
241
- 4. Add appropriate hooks if extending lifecycle
242
- 5. Consider TypeScript types from the start
243
-
244
- ### When Refactoring
245
- 1. Ensure all tests still pass
246
- 2. Don't change public APIs without semver consideration
247
- 3. Update TypeScript definitions if signatures change
248
- 4. Check for deprecation needs
249
- 5. Update documentation for changed behavior
250
-
251
- ### When Analyzing Issues
252
- 1. Check `test/` for usage examples
253
- 2. Review relevant `docs/Reference/` files
254
- 3. Look at similar implementations in `lib/`
255
- 4. Consider the plugin system and encapsulation
256
- 5. Check hook timing and order
257
-
258
- ### Common Gotchas
259
- - **Encapsulation**: Plugins are isolated - decorators don't leak
260
- - **Hook order**: Hooks run in specific order (see docs/Reference/Hooks.md)
261
- - **Async boot**: Server starts asynchronously - use `ready()` or `after()`
262
- - **Error handling**: Use Fastify error classes from `@fastify/error`
263
- - **Validation**: Schemas are compiled - changes require recompilation
264
-
265
- ## Key Dependencies
266
-
267
- - **`avvio`** - Plugin loading and boot
268
- - **`find-my-way`** - Fast HTTP router
269
- - **`fast-json-stringify`** - Response serialization
270
- - **`pino`** - Logging
271
- - **`@fastify/ajv-compiler`** - JSON Schema validation
272
- - **`light-my-request`** - HTTP injection for testing
273
-
274
- ## Contact and Resources
275
-
276
- - **Documentation**: https://fastify.dev/
277
- - **Discord**: https://discord.gg/fastify
278
- - **GitHub Issues**: https://github.com/fastify/fastify/issues
279
- - **GitHub Discussions**: https://github.com/fastify/fastify/discussions
280
- - **Help**: https://github.com/fastify/help
281
-
282
- ## Version Information
283
-
284
- - **Main branch**: Fastify v5
285
- - **v4 branch**: https://github.com/fastify/fastify/tree/4.x
286
- - **LTS Policy**: See `docs/Reference/LTS.md`
287
-
288
- ---
289
-
290
- This document is maintained by the Fastify team. For questions or suggestions, please open an issue or discussion.
@@ -1,72 +0,0 @@
1
- import fastify, { FastifyBodyParser } from '../../fastify'
2
- import { expectError, expectType } from 'tsd'
3
- import { IncomingMessage } from 'node:http'
4
- import { FastifyRequest } from '../../types/request'
5
-
6
- expectType<void>(fastify().addContentTypeParser('contentType', function (request, payload, done) {
7
- expectType<FastifyRequest>(request)
8
- expectType<IncomingMessage>(payload)
9
- done(null)
10
- }))
11
-
12
- // Body limit options
13
-
14
- expectType<void>(fastify().addContentTypeParser('contentType', { bodyLimit: 99 }, function (request, payload, done) {
15
- expectType<FastifyRequest>(request)
16
- expectType<IncomingMessage>(payload)
17
- done(null)
18
- }))
19
-
20
- // Array for contentType
21
-
22
- expectType<void>(fastify().addContentTypeParser(['contentType'], function (request, payload, done) {
23
- expectType<FastifyRequest>(request)
24
- expectType<IncomingMessage>(payload)
25
- done(null)
26
- }))
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
- expectType<void>(fastify().addContentTypeParser<string>('bodyContentType', { parseAs: 'string' }, function (request, body, done) {
31
- expectType<FastifyRequest>(request)
32
- expectType<string>(body)
33
- done(null)
34
- }))
35
-
36
- expectType<void>(fastify().addContentTypeParser<Buffer>('bodyContentType', { parseAs: 'buffer' }, function (request, body, done) {
37
- expectType<FastifyRequest>(request)
38
- expectType<Buffer>(body)
39
- done(null)
40
- }))
41
-
42
- expectType<void>(fastify().addContentTypeParser('contentType', async function (request: FastifyRequest, payload: IncomingMessage) {
43
- expectType<FastifyRequest>(request)
44
- expectType<IncomingMessage>(payload)
45
- return null
46
- }))
47
-
48
- expectType<void>(fastify().addContentTypeParser<string>('bodyContentType', { parseAs: 'string' }, async function (request: FastifyRequest, body: string) {
49
- expectType<FastifyRequest>(request)
50
- expectType<string>(body)
51
- return null
52
- }))
53
-
54
- expectType<void>(fastify().addContentTypeParser<Buffer>('bodyContentType', { parseAs: 'buffer' }, async function (request: FastifyRequest, body: Buffer) {
55
- expectType<FastifyRequest>(request)
56
- expectType<Buffer>(body)
57
- return null
58
- }))
59
-
60
- expectType<FastifyBodyParser<string>>(fastify().getDefaultJsonParser('error', 'ignore'))
61
-
62
- expectError(fastify().getDefaultJsonParser('error', 'skip'))
63
-
64
- expectError(fastify().getDefaultJsonParser('nothing', 'ignore'))
65
-
66
- expectType<void>(fastify().removeAllContentTypeParsers())
67
- expectError(fastify().removeAllContentTypeParsers('contentType'))
68
-
69
- expectType<void>(fastify().removeContentTypeParser('contentType'))
70
- expectType<void>(fastify().removeContentTypeParser(/contentType+.*/))
71
- expectType<void>(fastify().removeContentTypeParser(['contentType', /contentType+.*/]))
72
- expectError(fastify().removeContentTypeParser({}))
@@ -1,90 +0,0 @@
1
- import { FastifyErrorConstructor } from '@fastify/error'
2
- import { expectAssignable } from 'tsd'
3
- import { errorCodes } from '../../fastify'
4
-
5
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_NOT_FOUND)
6
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_OPTIONS_NOT_OBJ)
7
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_QSP_NOT_FN)
8
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN)
9
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN)
10
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ)
11
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR)
12
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_VALIDATION)
13
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_LISTEN_OPTIONS_INVALID)
14
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_ERROR_HANDLER_NOT_FN)
15
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_ERROR_HANDLER_ALREADY_SET)
16
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_CTP_ALREADY_PRESENT)
17
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_CTP_INVALID_TYPE)
18
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_CTP_EMPTY_TYPE)
19
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_CTP_INVALID_HANDLER)
20
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_CTP_INVALID_PARSE_TYPE)
21
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_CTP_BODY_TOO_LARGE)
22
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_CTP_INVALID_MEDIA_TYPE)
23
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_CTP_INVALID_CONTENT_LENGTH)
24
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_CTP_EMPTY_JSON_BODY)
25
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_CTP_INVALID_JSON_BODY)
26
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_CTP_INSTANCE_ALREADY_STARTED)
27
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_DEC_ALREADY_PRESENT)
28
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_DEC_DEPENDENCY_INVALID_TYPE)
29
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_DEC_MISSING_DEPENDENCY)
30
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_DEC_AFTER_START)
31
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_DEC_REFERENCE_TYPE)
32
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_DEC_UNDECLARED)
33
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_HOOK_INVALID_TYPE)
34
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_HOOK_INVALID_HANDLER)
35
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_HOOK_INVALID_ASYNC_HANDLER)
36
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_HOOK_NOT_SUPPORTED)
37
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_MISSING_MIDDLEWARE)
38
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_HOOK_TIMEOUT)
39
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_LOG_INVALID_DESTINATION)
40
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_LOG_INVALID_LOGGER)
41
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_LOG_INVALID_LOGGER_INSTANCE)
42
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_LOG_INVALID_LOGGER_CONFIG)
43
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED)
44
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_REP_INVALID_PAYLOAD_TYPE)
45
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_REP_RESPONSE_BODY_CONSUMED)
46
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_REP_READABLE_STREAM_LOCKED)
47
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_REP_ALREADY_SENT)
48
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_REP_SENT_VALUE)
49
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_SEND_INSIDE_ONERR)
50
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_SEND_UNDEFINED_ERR)
51
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_BAD_STATUS_CODE)
52
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_BAD_TRAILER_NAME)
53
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_BAD_TRAILER_VALUE)
54
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_FAILED_ERROR_SERIALIZATION)
55
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_MISSING_SERIALIZATION_FN)
56
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN)
57
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_REQ_INVALID_VALIDATION_INVOCATION)
58
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_SCH_MISSING_ID)
59
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_SCH_ALREADY_PRESENT)
60
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_SCH_CONTENT_MISSING_SCHEMA)
61
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_SCH_DUPLICATE)
62
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_SCH_VALIDATION_BUILD)
63
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_SCH_SERIALIZATION_BUILD)
64
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX)
65
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_INIT_OPTS_INVALID)
66
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE)
67
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_DUPLICATED_ROUTE)
68
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_BAD_URL)
69
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_ASYNC_CONSTRAINT)
70
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_INVALID_URL)
71
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_ROUTE_OPTIONS_NOT_OBJ)
72
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_ROUTE_DUPLICATED_HANDLER)
73
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_ROUTE_HANDLER_NOT_FN)
74
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_ROUTE_MISSING_HANDLER)
75
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_ROUTE_METHOD_INVALID)
76
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_ROUTE_METHOD_NOT_SUPPORTED)
77
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED)
78
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT)
79
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_ROUTE_REWRITE_NOT_STR)
80
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_REOPENED_CLOSE_SERVER)
81
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_REOPENED_SERVER)
82
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_INSTANCE_ALREADY_LISTENING)
83
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_PLUGIN_VERSION_MISMATCH)
84
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE)
85
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER)
86
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_PLUGIN_CALLBACK_NOT_FN)
87
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_PLUGIN_NOT_VALID)
88
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_ROOT_PLG_BOOTED)
89
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_PARENT_PLUGIN_BOOTED)
90
- expectAssignable<FastifyErrorConstructor>(errorCodes.FST_ERR_PLUGIN_TIMEOUT)