Comparing version 4.3.0 to 4.4.0
@@ -115,2 +115,10 @@ <h1 align="center">Fastify</h1> | ||
generation. | ||
- [`@fastify/type-provider-json-schema-to-ts`](https://github.com/fastify/fastify-type-provider-json-schema-to-ts) | ||
Fastify | ||
[type provider](https://www.fastify.io/docs/latest/Reference/Type-Providers/) | ||
for [json-schema-to-ts](https://github.com/ThomasAribart/json-schema-to-ts). | ||
- [`@fastify/type-provider-typebox`](https://github.com/fastify/fastify-type-provider-typebox) | ||
Fastify | ||
[type provider](https://www.fastify.io/docs/latest/Reference/Type-Providers/) | ||
for [Typebox](https://github.com/sinclairzx81/typebox). | ||
- [`@fastify/under-pressure`](https://github.com/fastify/under-pressure) Measure | ||
@@ -151,2 +159,5 @@ process load with automatic handling of _"Service Unavailable"_ plugin for | ||
to go! | ||
- [`@mateonunez/fastify-lyra`](https://github.com/mateonunez/fastify-lyra) | ||
A plugin to implement [Lyra](https://github.com/nearform/lyra) search engine | ||
on Fastify | ||
- [`@mgcrea/fastify-graceful-exit`](https://github.com/mgcrea/fastify-graceful-exit) | ||
@@ -220,2 +231,4 @@ A plugin to close the server gracefully | ||
to add [bree](https://github.com/breejs/bree) support. | ||
- [`fastify-bugsnag`](https://github.com/ZigaStrgar/fastify-bugsnag) Fastify plugin | ||
to add support for [Bugsnag](https://www.bugsnag.com/) error reporting. | ||
- [`fastify-casbin`](https://github.com/nearform/fastify-casbin) Casbin support | ||
@@ -334,2 +347,4 @@ for Fastify. | ||
that adds support for KafkaJS - a modern Apache Kafka client library. | ||
- [`fastify-keycloak-adapter`](https://github.com/yubinTW/fastify-keycloak-adapter) | ||
A keycloak adapter for a Fastify app. | ||
- [`fastify-knexjs`](https://github.com/chapuletta/fastify-knexjs) Fastify | ||
@@ -515,2 +530,6 @@ plugin for support KnexJS Query Builder. | ||
Useful functions for Twitch Extension Backend Services (EBS). | ||
- [`fastify-type-provider-zod`](https://github.com/turkerdev/fastify-type-provider-zod) | ||
Fastify | ||
[type provider](https://www.fastify.io/docs/latest/Reference/Type-Providers/) | ||
for [zod](https://github.com/colinhacks/zod). | ||
- [`fastify-typeorm-plugin`](https://github.com/inthepocket/fastify-typeorm-plugin) | ||
@@ -517,0 +536,0 @@ Fastify plugin to work with TypeORM. |
@@ -247,2 +247,5 @@ <h1 align="center">Fastify</h1> | ||
**Note:** setting `disableRequestLogging` to `true` will disable any error log | ||
inside the `onResponse` hook. In this case use `try - catch` to log errors. | ||
### onTimeout | ||
@@ -291,3 +294,3 @@ | ||
```js | ||
fastify.addHook('onResponse', async (request, reply) => { | ||
fastify.addHook('onRequest', async (request, reply) => { | ||
throw new Error('Some error') | ||
@@ -294,0 +297,0 @@ }) |
@@ -173,3 +173,3 @@ <h1 align="center">Fastify</h1> | ||
interface; that is, it must have the following methods: `info`, `error`, | ||
`debug`, `fatal`, `warn`, `trace`, `child`. | ||
`debug`, `fatal`, `warn`, `trace`, `silent`, `child` and a string property `level`. | ||
@@ -176,0 +176,0 @@ Example: |
@@ -770,2 +770,3 @@ <h1 align="center">Fastify</h1> | ||
```js | ||
const { promisify } = require('util') | ||
const delay = promisify(setTimeout) | ||
@@ -772,0 +773,0 @@ |
@@ -35,4 +35,6 @@ <h1 align="center">Fastify</h1> | ||
*`method`: currently it supports `'DELETE'`, `'GET'`, `'HEAD'`, `'PATCH'`, | ||
`'POST'`, `'PUT'` and `'OPTIONS'`. It could also be an array of methods. | ||
* `method`: currently it supports `'DELETE'`, `'GET'`, `'HEAD'`, `'PATCH'`, | ||
`'POST'`, `'PUT'`, `'OPTIONS'`, `'SEARCH'`, `'TRACE'`, `'PROPFIND'`, | ||
`'PROPPATCH'`, `'MKCOL'`, `'COPY'`, `'MOVE'`, `'LOCK'` and `'UNLOCK'`. | ||
It could also be an array of methods. | ||
* `url`: the path of the URL to match this route (alias: `path`). | ||
@@ -39,0 +41,0 @@ * `schema`: an object containing the schemas for the request and response. They |
@@ -893,3 +893,3 @@ <h1 align="center">Fastify</h1> | ||
`callback` parameters follow the [Node.js | ||
core][https://nodejs.org/api/net.html#serverlistenoptions-callback] parameter | ||
core](https://nodejs.org/api/net.html#serverlistenoptions-callback) parameter | ||
definitions. | ||
@@ -1406,2 +1406,5 @@ | ||
*Also note* that `setErrorHandler` will ***not*** catch any error inside | ||
an `onResponse` hook because the response has already been sent to the client. | ||
```js | ||
@@ -1408,0 +1411,0 @@ fastify.setErrorHandler(function (error, request, reply) { |
'use strict' | ||
const VERSION = '4.3.0' | ||
const VERSION = '4.4.0' | ||
@@ -37,3 +37,3 @@ const Avvio = require('avvio') | ||
const Request = require('./lib/request') | ||
const supportedMethods = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS'] | ||
const { supportedMethods } = require('./lib/httpMethods') | ||
const decorator = require('./lib/decorate') | ||
@@ -40,0 +40,0 @@ const ContentTypeParser = require('./lib/contentTypeParser') |
@@ -21,3 +21,3 @@ 'use strict' | ||
if (method === 'GET' || method === 'HEAD') { | ||
if (method === 'GET' || method === 'HEAD' || method === 'SEARCH') { | ||
handler(request, reply) | ||
@@ -29,3 +29,3 @@ return | ||
if (method === 'POST' || method === 'PUT' || method === 'PATCH') { | ||
if (method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'TRACE') { | ||
if (contentType === undefined) { | ||
@@ -32,0 +32,0 @@ if ( |
@@ -7,3 +7,3 @@ 'use strict' | ||
const { hookRunner, hookIterator, lifecycleHooks } = require('./hooks') | ||
const supportedMethods = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS'] | ||
const { supportedMethods } = require('./httpMethods') | ||
const { normalizeSchema } = require('./schemas') | ||
@@ -10,0 +10,0 @@ const { parseHeadOnSendHandlers } = require('./headRoute') |
{ | ||
"name": "fastify", | ||
"version": "4.3.0", | ||
"version": "4.4.0", | ||
"description": "Fast and low overhead web framework, for Node.js", | ||
@@ -162,3 +162,3 @@ "main": "fastify.js", | ||
"license-checker": "^25.0.1", | ||
"markdownlint-cli2": "^0.4.0", | ||
"markdownlint-cli2": "^0.5.0", | ||
"proxyquire": "^2.1.3", | ||
@@ -165,0 +165,0 @@ "pump": "^3.0.0", |
@@ -6,5 +6,11 @@ 'use strict' | ||
const Fastify = require('../..') | ||
const supportedMethods = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS'] | ||
const { supportedMethods } = require('../../lib/httpMethods') | ||
test('fastify.all should add all the methods to the same url', t => { | ||
const requirePayload = [ | ||
'POST', | ||
'PUT', | ||
'PATCH' | ||
] | ||
t.plan(supportedMethods.length * 2) | ||
@@ -26,3 +32,3 @@ | ||
if (method === 'POST' || method === 'PUT' || method === 'PATCH') { | ||
if (requirePayload.includes(method)) { | ||
options.payload = { hello: 'world' } | ||
@@ -29,0 +35,0 @@ } |
@@ -1047,3 +1047,3 @@ 'use strict' | ||
test('reply.getHeader returns correct values', t => { | ||
t.plan(4) | ||
t.plan(5) | ||
@@ -1059,2 +1059,5 @@ const fastify = require('../../')() | ||
reply.header('x-foo', 42) | ||
t.strictSame(reply.getHeader('x-foo'), 42) | ||
reply.header('set-cookie', 'one') | ||
@@ -1061,0 +1064,0 @@ reply.header('set-cookie', 'two') |
@@ -1,2 +0,2 @@ | ||
import { expectError, expectType } from 'tsd' | ||
import { expectDeprecated, expectError, expectType } from 'tsd' | ||
import fastify, { | ||
@@ -27,4 +27,2 @@ FastifyLogFn, | ||
/* | ||
// TODO make pino export BaseLogger again | ||
interface CustomLogger extends FastifyBaseLogger { | ||
@@ -34,3 +32,2 @@ customMethod(msg: string, ...args: unknown[]): void; | ||
// // ToDo https://github.com/pinojs/pino/issues/1100 | ||
class CustomLoggerImpl implements CustomLogger { | ||
@@ -65,3 +62,2 @@ level = 'info' | ||
expectType<CustomLoggerImpl>(serverWithCustomLogger.log) | ||
*/ | ||
@@ -219,2 +215,5 @@ const serverWithPino = fastify< | ||
// FastifyLoggerInstance is deprecated | ||
expectDeprecated({} as FastifyLoggerInstance) | ||
const childParent = fastify().log | ||
@@ -221,0 +220,0 @@ // we test different option variant here |
@@ -1,2 +0,2 @@ | ||
import { expectType, expectError } from 'tsd' | ||
import { expectType, expectError, expectAssignable } from 'tsd' | ||
import fastify, { RouteHandlerMethod, RouteHandler, RawRequestDefaultExpression, FastifyContext, FastifyContextConfig, FastifyRequest, FastifyReply } from '../../fastify' | ||
@@ -9,2 +9,4 @@ import { RawServerDefault, RawReplyDefaultExpression, ContextConfigDefault } from '../../types/utils' | ||
type DefaultSerializationFunction = (payload: {[key: string]: unknown}) => string | ||
const getHandler: RouteHandlerMethod = function (_request, reply) { | ||
@@ -23,3 +25,3 @@ expectType<RawReplyDefaultExpression>(reply.raw) | ||
expectType<(values: {[key: string]: any}) => FastifyReply>(reply.headers) | ||
expectType<(key: string) => string | undefined>(reply.getHeader) | ||
expectType<(key: string) => number | string | string[] | undefined>(reply.getHeader) | ||
expectType<() => { [key: string]: number | string | string[] | undefined }>(reply.getHeaders) | ||
@@ -37,2 +39,7 @@ expectType<(key: string) => void>(reply.removeHeader) | ||
expectType<FastifyInstance>(reply.server) | ||
expectAssignable<((httpStatus: string) => DefaultSerializationFunction)>(reply.getSerializationFunction) | ||
expectAssignable<((schema: {[key: string]: unknown}) => DefaultSerializationFunction)>(reply.getSerializationFunction) | ||
expectAssignable<((schema: {[key: string]: unknown}, httpStatus?: string) => DefaultSerializationFunction)>(reply.compileSerializationSchema) | ||
expectAssignable<((input: {[key: string]: unknown}, schema: {[key: string]: unknown}, httpStatus?: string) => unknown)>(reply.serializeInput) | ||
expectAssignable<((input: {[key: string]: unknown}, httpStatus: string) => unknown)>(reply.serializeInput) | ||
} | ||
@@ -46,2 +53,10 @@ | ||
interface ReplyUnion { | ||
Reply: { | ||
success: boolean; | ||
} | { | ||
error: string; | ||
} | ||
} | ||
const typedHandler: RouteHandler<ReplyPayload> = async (request, reply) => { | ||
@@ -60,3 +75,3 @@ expectType<((payload?: ReplyPayload['Reply']) => FastifyReply<RawServerDefault, RawRequestDefaultExpression<RawServerDefault>, RawReplyDefaultExpression<RawServerDefault>, ReplyPayload>)>(reply.send) | ||
}) | ||
expectError(server.get<ReplyPayload>('/get-generic-return-error', async function handler (request, reply) { | ||
expectError(server.get<ReplyPayload>('/get-generic-send-error', async function handler (request, reply) { | ||
reply.send({ foo: 'bar' }) | ||
@@ -67,1 +82,27 @@ })) | ||
})) | ||
server.get<ReplyUnion>('/get-generic-union-send', async function handler (request, reply) { | ||
if (0 as number === 0) { | ||
reply.send({ success: true }) | ||
} else { | ||
reply.send({ error: 'error' }) | ||
} | ||
}) | ||
server.get<ReplyUnion>('/get-generic-union-return', async function handler (request, reply) { | ||
if (0 as number === 0) { | ||
return { success: true } | ||
} else { | ||
return { error: 'error' } | ||
} | ||
}) | ||
expectError(server.get<ReplyUnion>('/get-generic-union-send-error-1', async function handler (request, reply) { | ||
reply.send({ successes: true }) | ||
})) | ||
expectError(server.get<ReplyUnion>('/get-generic-union-send-error-2', async function handler (request, reply) { | ||
reply.send({ error: 500 }) | ||
})) | ||
expectError(server.get<ReplyUnion>('/get-generic-union-return-error-1', async function handler (request, reply) { | ||
return { successes: true } | ||
})) | ||
expectError(server.get<ReplyUnion>('/get-generic-union-return-error-2', async function handler (request, reply) { | ||
return { error: 500 } | ||
})) |
@@ -1,2 +0,2 @@ | ||
import { expectType } from 'tsd' | ||
import { expectAssignable, expectType } from 'tsd' | ||
import pino from 'pino' | ||
@@ -24,3 +24,2 @@ import fastify, { | ||
import { RouteGenericInterface } from '../../types/route' | ||
import { ResolveFastifyReplyReturnType, ResolveFastifyRequestType } from '../../types/type-provider' | ||
@@ -59,2 +58,5 @@ interface RequestBody { | ||
type HTTPRequestPart = 'body' | 'query' | 'querystring' | 'params' | 'headers' | ||
type ExpectedGetValidationFunction = (input: {[key: string]: unknown}) => boolean | ||
interface CustomLoggerInterface extends FastifyLoggerInstance { | ||
@@ -88,2 +90,6 @@ foo: FastifyLogFn; // custom severity logger method | ||
expectType<FastifyInstance>(request.server) | ||
expectAssignable<(httpPart: HTTPRequestPart) => ExpectedGetValidationFunction>(request.getValidationFunction) | ||
expectAssignable<(schema: {[key: string]: unknown}) => ExpectedGetValidationFunction>(request.getValidationFunction) | ||
expectAssignable<(input: {[key: string]: unknown}, schema: {[key: string]: unknown}, httpPart?: HTTPRequestPart) => boolean>(request.validateInput) | ||
expectAssignable<(input: {[key: string]: unknown}, httpPart?: HTTPRequestPart) => boolean>(request.validateInput) | ||
} | ||
@@ -134,13 +140,2 @@ | ||
level: 'info', | ||
version: '5.0', | ||
useOnlyCustomLevels: false, | ||
useLevelLabels: false, | ||
levels: { labels: [], values: {} }, | ||
eventNames: () => [], | ||
listenerCount: (eventName: string | symbol) => 0, | ||
bindings: () => ({}), | ||
flush: () => () => {}, | ||
customLevels: { foo: 1 }, | ||
isLevelEnabled: () => false, | ||
levelVal: 0, | ||
silent: () => { }, | ||
@@ -154,17 +149,3 @@ info: () => { }, | ||
foo: () => { }, // custom severity logger method | ||
on: (event, listener) => customLogger, | ||
emit: (event, listener) => false, | ||
off: (event, listener) => customLogger, | ||
addListener: (event, listener) => customLogger, | ||
prependListener: (event, listener) => customLogger, | ||
prependOnceListener: (event, listener) => customLogger, | ||
removeListener: (event, listener) => customLogger, | ||
removeAllListeners: (event) => customLogger, | ||
setMaxListeners: (n) => customLogger, | ||
getMaxListeners: () => 0, | ||
listeners: () => [], | ||
rawListeners: () => [], | ||
once: (event, listener) => customLogger, | ||
child: () => customLogger as pino.Logger<never>, | ||
setBindings: (bindings) => { } | ||
child: () => customLogger as pino.Logger<never> | ||
} | ||
@@ -171,0 +152,0 @@ |
@@ -394,3 +394,5 @@ import fastify, { | ||
schema: { | ||
response: { type: 'string' } | ||
response: { | ||
200: { type: 'string' } | ||
} | ||
} as const | ||
@@ -397,0 +399,0 @@ }, (_, res) => { |
@@ -22,9 +22,12 @@ import { FastifyError } from '@fastify/error' | ||
export type FastifyLoggerInstance = pino.Logger | ||
// TODO make pino export BaseLogger again | ||
// export type FastifyBaseLogger = pino.BaseLogger & { | ||
export type FastifyBaseLogger = pino.Logger & { | ||
export type FastifyBaseLogger = pino.BaseLogger & { | ||
child(bindings: Bindings, options?: ChildLoggerOptions): FastifyBaseLogger | ||
} | ||
// TODO delete FastifyLoggerInstance in the next major release. It seems that it is enough to have only FastifyBaseLogger. | ||
/** | ||
* @deprecated Use FastifyBaseLogger instead | ||
*/ | ||
export type FastifyLoggerInstance = FastifyBaseLogger | ||
export interface FastifyLoggerStreamDestination { | ||
@@ -31,0 +34,0 @@ write(msg: string): void; |
@@ -41,3 +41,3 @@ import { RawReplyDefaultExpression, RawServerBase, RawServerDefault, ContextConfigDefault, RawRequestDefaultExpression, ReplyDefault } from './utils' | ||
headers(values: {[key: string]: any}): FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>; | ||
getHeader(key: string): string | undefined; | ||
getHeader(key: string): number | string | string[] | undefined; | ||
getHeaders(): { | ||
@@ -58,8 +58,9 @@ // Node's `getHeaders()` can return numbers and arrays, so they're included here as possible types. | ||
serialize(payload: any): string | ArrayBuffer | Buffer; | ||
getSerializationFunction(httpStatus: string): (payload: any) => string; | ||
getSerializationFunction(schema: {[key: string]: any}): (payload: any) => string; | ||
compileSerializationSchema(schema: {[key: string]: any}, httpStatus?: string): (payload: any) => string; | ||
serializeInput(input: any, schema: {[key: string]: any}, httpStatus?: string): string | ||
serializeInput(input: any, httpStatus: string): string | ||
// Serialization Methods | ||
getSerializationFunction(httpStatus: string): (payload: {[key: string]: unknown}) => string; | ||
getSerializationFunction(schema: {[key: string]: unknown}): (payload: {[key: string]: unknown}) => string; | ||
compileSerializationSchema(schema: {[key: string]: unknown}, httpStatus?: string): (payload: {[key: string]: unknown}) => string; | ||
serializeInput(input: {[key: string]: unknown}, schema: {[key: string]: unknown}, httpStatus?: string): string; | ||
serializeInput(input: {[key: string]: unknown}, httpStatus: string): unknown; | ||
then(fulfilled: () => void, rejected: (err: Error) => void): void; | ||
} |
@@ -67,4 +67,4 @@ import { FastifyLoggerInstance } from './logger' | ||
compileValidationSchema(schema: {[key: string]: any}, httpPart?: HTTPRequestPart): (input: any) => boolean | ||
validate(input: any, schema: {[key: string]: any}, httpPart?: HTTPRequestPart): boolean | ||
validate(input: any, httpPart?: HTTPRequestPart): boolean | ||
validateInput(input: any, schema: {[key: string]: any}, httpPart?: HTTPRequestPart): boolean | ||
validateInput(input: any, httpPart?: HTTPRequestPart): boolean | ||
@@ -71,0 +71,0 @@ // Prefer `socket` over deprecated `connection` property in node 13.0.0 or higher |
@@ -63,11 +63,2 @@ | ||
// Tests if the user has specified a generic argument for Reply | ||
type UseReplyFromRouteGeneric<RouteGeneric extends RouteGenericInterface> = keyof RouteGeneric['Reply'] extends never ? false : true | ||
// Tests if the user has specified a response schema. | ||
type UseReplyFromSchemaCompiler<SchemaCompiler extends FastifySchema> = keyof SchemaCompiler['response'] extends never ? false : true | ||
// Resolves the Reply type from the generic argument | ||
type ResolveReplyFromRouteGeneric<RouteGeneric extends RouteGenericInterface> = RouteGeneric['Reply'] | ||
// Resolves the Reply type by taking a union of response status codes | ||
@@ -84,7 +75,3 @@ type ResolveReplyFromSchemaCompiler<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema> = { | ||
// by the user. The Reply can be explicitly overriden by users providing a generic Reply type on the route. | ||
export type ResolveFastifyReplyType<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema, RouteGeneric extends RouteGenericInterface> = FastifyReplyType< | ||
UseReplyFromRouteGeneric<RouteGeneric> extends true ? ResolveReplyFromRouteGeneric<RouteGeneric> : | ||
UseReplyFromSchemaCompiler<SchemaCompiler> extends true ? ResolveReplyFromSchemaCompiler<TypeProvider, SchemaCompiler> : | ||
unknown | ||
> | ||
export type ResolveFastifyReplyType<TypeProvider extends FastifyTypeProvider, SchemaCompiler extends FastifySchema, RouteGeneric extends RouteGenericInterface> = UndefinedToUnknown<KeysOf<RouteGeneric['Reply']> extends never ? ResolveReplyFromSchemaCompiler<TypeProvider, SchemaCompiler> : RouteGeneric['Reply']> | ||
@@ -91,0 +78,0 @@ // ----------------------------------------------------------------------------------------------- |
@@ -8,3 +8,4 @@ import * as http from 'http' | ||
*/ | ||
export type HTTPMethods = 'DELETE' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'OPTIONS' | ||
export type HTTPMethods = 'DELETE' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'OPTIONS' | | ||
'PROPFIND' | 'PROPPATCH' | 'MKCOL' | 'COPY' | 'MOVE' | 'LOCK' | 'UNLOCK' | 'TRACE' | 'SEARCH' | ||
@@ -11,0 +12,0 @@ /** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1897685
268
45456