fastify 4.0.0-rc.3 → 4.0.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/README.md +2 -1
- package/build/build-validation.js +14 -2
- package/docs/Guides/Ecosystem.md +23 -11
- package/docs/Guides/Index.md +1 -1
- package/docs/Guides/Migration-Guide-V3.md +1 -1
- package/docs/Guides/Plugins-Guide.md +3 -3
- package/docs/Guides/Prototype-Poisoning.md +1 -1
- package/docs/Guides/Recommendations.md +2 -2
- package/docs/Guides/Serverless.md +5 -5
- package/docs/Guides/Testing.md +3 -1
- package/docs/Guides/Write-Plugin.md +3 -3
- package/docs/Migration-Guide-V4.md +1 -1
- package/docs/Reference/Logging.md +10 -5
- package/docs/Reference/Middleware.md +3 -3
- package/docs/Reference/Routes.md +2 -2
- package/docs/Reference/Server.md +59 -10
- package/docs/Reference/TypeScript.md +2 -2
- package/docs/Reference/Validation-and-Serialization.md +11 -1
- package/fastify.d.ts +2 -1
- package/fastify.js +38 -14
- package/lib/configValidator.js +456 -332
- package/lib/errors.js +4 -0
- package/lib/request.js +2 -2
- package/lib/route.js +5 -2
- package/lib/schemas.js +3 -0
- package/lib/validation.js +8 -2
- package/package.json +34 -34
- package/test/close-pipelining.test.js +4 -2
- package/test/close.test.js +93 -3
- package/test/custom-http-server.test.js +22 -0
- package/test/decorator.test.js +146 -0
- package/test/internals/initialConfig.test.js +5 -3
- package/test/output-validation.test.js +6 -2
- package/test/plugin.test.js +177 -14
- package/test/route-prefix.test.js +250 -0
- package/test/router-options.test.js +61 -0
- package/test/schema-feature.test.js +24 -0
- package/test/schema-serialization.test.js +57 -0
- package/test/types/fastify.test-d.ts +1 -0
- package/test/types/instance.test-d.ts +1 -0
- package/test/types/logger.test-d.ts +13 -1
- package/test/types/route.test-d.ts +14 -0
- package/test/types/type-provider.test-d.ts +6 -0
- package/types/instance.d.ts +1 -0
- package/types/logger.d.ts +3 -1
- package/types/route.d.ts +1 -1
- package/types/schema.d.ts +1 -1
- package/types/type-provider.d.ts +3 -4
|
@@ -261,6 +261,7 @@ type InitialConfig = Readonly<{
|
|
|
261
261
|
http2?: boolean,
|
|
262
262
|
https?: boolean | Readonly<{ allowHTTP1: boolean }>,
|
|
263
263
|
ignoreTrailingSlash?: boolean,
|
|
264
|
+
ignoreDuplicateSlashes?: boolean,
|
|
264
265
|
disableRequestLogging?: boolean,
|
|
265
266
|
maxParamLength?: number,
|
|
266
267
|
onProtoPoisoning?: 'error' | 'remove' | 'ignore',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expectType } from 'tsd'
|
|
1
|
+
import { expectError, expectType } from 'tsd'
|
|
2
2
|
import fastify, {
|
|
3
3
|
FastifyLogFn,
|
|
4
4
|
LogLevel,
|
|
@@ -212,3 +212,15 @@ const passPinoOption = fastify({
|
|
|
212
212
|
})
|
|
213
213
|
|
|
214
214
|
expectType<FastifyBaseLogger>(passPinoOption.log)
|
|
215
|
+
|
|
216
|
+
const childParent = fastify().log
|
|
217
|
+
// we test different option variant here
|
|
218
|
+
expectType<FastifyLoggerInstance>(childParent.child({}, { level: 'info' }))
|
|
219
|
+
expectType<FastifyLoggerInstance>(childParent.child({}, { redact: ['pass', 'pin'] }))
|
|
220
|
+
expectType<FastifyLoggerInstance>(childParent.child({}, { serializers: { key: () => {} } }))
|
|
221
|
+
expectType<FastifyLoggerInstance>(childParent.child({}, { level: 'info', redact: ['pass', 'pin'], serializers: { key: () => {} } }))
|
|
222
|
+
|
|
223
|
+
// no option pass
|
|
224
|
+
expectError(childParent.child())
|
|
225
|
+
// wrong option
|
|
226
|
+
expectError(childParent.child({}, { nonExist: true }))
|
|
@@ -27,6 +27,14 @@ const routeHandler: RouteHandlerMethod = function (request, reply) {
|
|
|
27
27
|
expectType<FastifyReply>(reply)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
const routeHandlerWithReturnValue: RouteHandlerMethod = function (request, reply) {
|
|
31
|
+
expectType<FastifyInstance>(this)
|
|
32
|
+
expectType<FastifyRequest>(request)
|
|
33
|
+
expectType<FastifyReply>(reply)
|
|
34
|
+
|
|
35
|
+
return reply.send()
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
type LowerCaseHTTPMethods = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete' | 'options'
|
|
31
39
|
|
|
32
40
|
;['GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS'].forEach(method => {
|
|
@@ -216,3 +224,9 @@ expectType<FastifyInstance>(fastify().route({
|
|
|
216
224
|
expectError(fastify().route({
|
|
217
225
|
prefixTrailingSlash: true // Not a valid value
|
|
218
226
|
}))
|
|
227
|
+
|
|
228
|
+
expectType<FastifyInstance>(fastify().route({
|
|
229
|
+
url: '/',
|
|
230
|
+
method: 'GET',
|
|
231
|
+
handler: routeHandlerWithReturnValue
|
|
232
|
+
}))
|
|
@@ -13,6 +13,12 @@ import { RouteGenericInterface } from '../../types/route'
|
|
|
13
13
|
|
|
14
14
|
const server = fastify()
|
|
15
15
|
|
|
16
|
+
// -------------------------------------------------------------------
|
|
17
|
+
// Default (unknown)
|
|
18
|
+
// -------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
expectAssignable(server.get('/', (req) => expectType<unknown>(req.body)))
|
|
21
|
+
|
|
16
22
|
// -------------------------------------------------------------------
|
|
17
23
|
// Remapping
|
|
18
24
|
// -------------------------------------------------------------------
|
package/types/instance.d.ts
CHANGED
|
@@ -619,6 +619,7 @@ export interface FastifyInstance<
|
|
|
619
619
|
http2?: boolean,
|
|
620
620
|
https?: boolean | Readonly<{ allowHTTP1: boolean }>,
|
|
621
621
|
ignoreTrailingSlash?: boolean,
|
|
622
|
+
ignoreDuplicateSlashes?: boolean,
|
|
622
623
|
disableRequestLogging?: boolean,
|
|
623
624
|
maxParamLength?: number,
|
|
624
625
|
onProtoPoisoning?: ProtoAction,
|
package/types/logger.d.ts
CHANGED
|
@@ -17,11 +17,13 @@ export type LogLevel = pino.Level
|
|
|
17
17
|
|
|
18
18
|
export type Bindings = pino.Bindings
|
|
19
19
|
|
|
20
|
+
export type ChildLoggerOptions = pino.ChildLoggerOptions
|
|
21
|
+
|
|
20
22
|
export type FastifyLoggerInstance = pino.Logger
|
|
21
23
|
// TODO make pino export BaseLogger again
|
|
22
24
|
// export type FastifyBaseLogger = pino.BaseLogger & {
|
|
23
25
|
export type FastifyBaseLogger = pino.Logger & {
|
|
24
|
-
child(bindings: Bindings): FastifyBaseLogger
|
|
26
|
+
child(bindings: Bindings, options?: ChildLoggerOptions): FastifyBaseLogger
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export interface FastifyLoggerStreamDestination {
|
package/types/route.d.ts
CHANGED
|
@@ -154,7 +154,7 @@ export type RouteHandler<
|
|
|
154
154
|
this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
|
|
155
155
|
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, RequestType, Logger>,
|
|
156
156
|
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
|
|
157
|
-
) => void | Promise<RouteGeneric['Reply'] | void>
|
|
157
|
+
) => RouteGeneric['Reply'] | void | Promise<RouteGeneric['Reply'] | void>
|
|
158
158
|
|
|
159
159
|
export type DefaultRoute<Request, Reply> = (
|
|
160
160
|
req: Request,
|
package/types/schema.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { FastifyInstance, FastifyServerOptions } from '../fastify'
|
|
|
4
4
|
* Schemas in Fastify follow the JSON-Schema standard. For this reason
|
|
5
5
|
* we have opted to not ship strict schema based types. Instead we provide
|
|
6
6
|
* an example in our documentation on how to solve this problem. Check it
|
|
7
|
-
* out here: https://github.com/fastify/fastify/blob/main/docs/TypeScript.md#json-schema
|
|
7
|
+
* out here: https://github.com/fastify/fastify/blob/main/docs/Reference/TypeScript.md#json-schema
|
|
8
8
|
*/
|
|
9
9
|
export interface FastifySchema {
|
|
10
10
|
body?: unknown;
|
package/types/type-provider.d.ts
CHANGED
|
@@ -11,9 +11,8 @@ export interface FastifyTypeProvider {
|
|
|
11
11
|
readonly output: unknown,
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
15
|
+
export interface FastifyTypeProviderDefault extends FastifyTypeProvider {}
|
|
17
16
|
|
|
18
17
|
export type CallTypeProvider<F extends FastifyTypeProvider, I> = (F & { input: I })['output']
|
|
19
18
|
|
|
@@ -93,7 +92,7 @@ TypeProvider,
|
|
|
93
92
|
SchemaCompiler,
|
|
94
93
|
RouteGeneric
|
|
95
94
|
> extends infer Return ?
|
|
96
|
-
(void | Promise<Return | void>)
|
|
95
|
+
(Return | void | Promise<Return | void>)
|
|
97
96
|
// review: support both async and sync return types
|
|
98
97
|
// (Promise<Return> | Return | Promise<void> | void)
|
|
99
98
|
: unknown
|