Socket
Socket
Sign inDemoInstall

fastify

Package Overview
Dependencies
Maintainers
3
Versions
288
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify - npm Package Compare versions

Comparing version 4.21.0 to 4.22.0

8

docs/Guides/Ecosystem.md

@@ -47,2 +47,5 @@ <h1 align="center">Fastify</h1>

Plugin to deal with `diagnostics_channel` on Fastify
- [`@fastify/early-hints`](https://github.com/fastify/fastify-early-hints) Plugin
to add HTTP 103 feature based on [RFC
8297](https://httpwg.org/specs/rfc8297.html).
- [`@fastify/elasticsearch`](https://github.com/fastify/fastify-elasticsearch)

@@ -308,5 +311,2 @@ Plugin to share the same ES client.

register for Fastify.
- [`fastify-early-hints`](https://github.com/zekth/fastify-early-hints) Plugin
to add HTTP 103 feature based on [RFC
8297](https://httpwg.org/specs/rfc8297.html)
- [`fastify-envalid`](https://github.com/alemagio/fastify-envalid) Fastify

@@ -363,2 +363,4 @@ plugin to integrate [envalid](https://github.com/af/envalid) in your Fastify

that protects endpoints by checking authenticated user roles and/or scopes.
- [`fastify-hashids`](https://github.com/andersonjoseph/fastify-hashids) A Fastify
plugin to encode/decode IDs using [hashids](https://github.com/niieani/hashids.js).
- [`fastify-hasura`](https://github.com/ManUtopiK/fastify-hasura) A Fastify

@@ -365,0 +367,0 @@ plugin to have fun with [Hasura](https://github.com/hasura/graphql-engine).

@@ -280,3 +280,3 @@ <h1 align="center">Fastify</h1>

// and hooks, declared inside the plugin to the parent scope.
module.exports = fastifyPlugin(dbConnector)
export default fastifyPlugin(dbConnector)

@@ -283,0 +283,0 @@ ```

@@ -109,2 +109,5 @@ <h1 align="center">Fastify</h1>

**Notice:** The size of the returned stream is checked to not exceed the limit
set in [`bodyLimit`](./Server.md#bodylimit) option.
### preValidation

@@ -111,0 +114,0 @@

@@ -285,2 +285,6 @@ <h1 align="center">Fastify</h1>

Defines the maximum payload, in bytes, the server is allowed to accept.
The default body reader sends [`FST_ERR_CTP_BODY_TOO_LARGE`](./Errors.md#fst_err_ctp_body_too_large)
reply, if the size of the body exceeds this limit.
If [`preParsing` hook](./Hooks.md#preparsing) is provided, this limit is applied
to the size of the stream the hook returns (i.e. the size of "decoded" body).

@@ -287,0 +291,0 @@ ### `onProtoPoisoning`

@@ -400,3 +400,3 @@ <h1 align="center">Fastify</h1>

useDefaults: true, // replace missing properties and items with the values from corresponding default keyword
removeAdditional: true, // remove additional properties
removeAdditional: true, // remove additional properties if additionalProperties is set to false, see: https://ajv.js.org/guide/modifying-data.html#removing-additional-properties
uriResolver: require('fast-uri'),

@@ -403,0 +403,0 @@ addUsedSchema: false,

@@ -23,3 +23,3 @@ import * as http from 'http'

import { RouteHandler, RouteHandlerMethod, RouteOptions, RouteShorthandMethod, RouteShorthandOptions, RouteShorthandOptionsWithHandler, RouteGenericInterface } from './types/route'
import { FastifySchema, FastifySchemaCompiler, SchemaErrorDataVar, SchemaErrorFormatter } from './types/schema'
import { FastifySchema, FastifySchemaCompiler, FastifySchemaValidationError, SchemaErrorDataVar, SchemaErrorFormatter } from './types/schema'
import { FastifyServerFactory, FastifyServerFactoryHandler } from './types/serverFactory'

@@ -31,4 +31,4 @@ import { FastifyTypeProvider, FastifyTypeProviderDefault } from './types/type-provider'

interface FastifyError {
validation?: fastify.ValidationResult[];
validationContext?: SchemaErrorDataVar;
validation?: FastifySchemaValidationError[];
}

@@ -167,9 +167,6 @@ }

export interface ValidationResult {
keyword: string;
instancePath: string;
schemaPath: string;
params: Record<string, string | string[]>;
message?: string;
}
/**
* @deprecated use {@link FastifySchemaValidationError}
*/
export type ValidationResult = FastifySchemaValidationError;

@@ -247,2 +244,2 @@ /* Export additional types */

// const fastify = require('fastify')
export = fastify
export = fastify
'use strict'
const VERSION = '4.21.0'
const VERSION = '4.22.0'

@@ -244,3 +244,3 @@ const Avvio = require('avvio')

[kFourOhFour]: fourOhFour,
[pluginUtils.registeredPlugins]: [],
[pluginUtils.kRegisteredPlugins]: [],
[kPluginNameChain]: ['fastify'],

@@ -316,3 +316,3 @@ [kAvvioBoot]: null,

hasPlugin: function (name) {
return this[kPluginNameChain].includes(name)
return this[pluginUtils.kRegisteredPlugins].includes(name) || this[kPluginNameChain].includes(name)
},

@@ -319,0 +319,0 @@ // http server

@@ -229,4 +229,7 @@ 'use strict'

receivedLength += chunk.length
if ((payload.receivedEncodedLength || receivedLength) > limit) {
const { receivedEncodedLength = 0 } = payload
// The resulting body length must not exceed bodyLimit (see "zip bomb").
// The case when encoded length is larger than received length is rather theoretical,
// unless the stream returned by preParsing hook is broken and reports wrong value.
if (receivedLength > limit || receivedEncodedLength > limit) {
payload.removeListener('data', onData)

@@ -233,0 +236,0 @@ payload.removeListener('end', onEnd)

@@ -19,5 +19,5 @@ // This file is autogenerated by build/build-error-serializer.js, do not edit

// #
function anonymous0 (input) {
// #
const obj = (input && typeof input.toJSON === 'function')

@@ -27,30 +27,32 @@ ? input.toJSON()

let json = '{'
let addComma = false
let addComma = false
let json = '{'
if (obj["statusCode"] !== undefined) {
!addComma && (addComma = true) || (json += ',')
json += "\"statusCode\":"
json += serializer.asNumber(obj["statusCode"])
}
if (obj["code"] !== undefined) {
!addComma && (addComma = true) || (json += ',')
json += "\"code\":"
json += serializer.asString(obj["code"])
}
if (obj["error"] !== undefined) {
!addComma && (addComma = true) || (json += ',')
json += "\"error\":"
json += serializer.asString(obj["error"])
}
if (obj["message"] !== undefined) {
!addComma && (addComma = true) || (json += ',')
json += "\"message\":"
json += serializer.asString(obj["message"])
}
return json + '}'
if (obj["statusCode"] !== undefined) {
!addComma && (addComma = true) || (json += ',')
json += "\"statusCode\":"
json += serializer.asNumber(obj["statusCode"])
}
if (obj["code"] !== undefined) {
!addComma && (addComma = true) || (json += ',')
json += "\"code\":"
json += serializer.asString(obj["code"])
}
if (obj["error"] !== undefined) {
!addComma && (addComma = true) || (json += ',')
json += "\"error\":"
json += serializer.asString(obj["error"])
}
if (obj["message"] !== undefined) {
!addComma && (addComma = true) || (json += ',')
json += "\"message\":"
json += serializer.asString(obj["message"])
}
return json + '}'
}

@@ -57,0 +59,0 @@

@@ -30,5 +30,6 @@ 'use strict'

const fnName = pluginUtils.getPluginName(fn) || pluginUtils.getFuncPreview(fn)
if (shouldSkipOverride) {
// after every plugin registration we will enter a new name
old[kPluginNameChain].push(pluginUtils.getDisplayName(fn))
old[kPluginNameChain].push(fnName)
return old

@@ -52,5 +53,11 @@ }

instance.getSchemas = instance[kSchemaController].getSchemas.bind(instance[kSchemaController])
instance[pluginUtils.registeredPlugins] = Object.create(instance[pluginUtils.registeredPlugins])
instance[kPluginNameChain] = [pluginUtils.getPluginName(fn) || pluginUtils.getFuncPreview(fn)]
// Track the registered and loaded plugins since the root instance.
// It does not track the current encapsulated plugin.
instance[pluginUtils.kRegisteredPlugins] = Object.create(instance[pluginUtils.kRegisteredPlugins])
// Track the plugin chain since the root instance.
// When an non-encapsulated plugin is added, the chain will be updated.
instance[kPluginNameChain] = [fnName]
if (instance[kLogSerializers] || opts.logSerializers) {

@@ -57,0 +64,0 @@ instance[kLogSerializers] = Object.assign(Object.create(instance[kLogSerializers]), opts.logSerializers)

@@ -5,3 +5,3 @@ 'use strict'

const assert = require('assert')
const registeredPlugins = Symbol.for('registered-plugin')
const kRegisteredPlugins = Symbol.for('registered-plugin')
const {

@@ -29,8 +29,11 @@ kTestInternals

const cache = require.cache
const keys = Object.keys(cache)
// cache is undefined inside SEA
if (cache) {
const keys = Object.keys(cache)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
if (cache[key].exports === func) {
return key
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
if (cache[key].exports === func) {
return key
}
}

@@ -70,3 +73,3 @@ }

assert(
this[registeredPlugins].indexOf(dependency) > -1,
this[kRegisteredPlugins].indexOf(dependency) > -1,
`The dependency '${dependency}' of plugin '${meta.name}' is not registered`

@@ -134,3 +137,3 @@ )

if (!name) return
this[registeredPlugins].push(name)
this[kRegisteredPlugins].push(name)
}

@@ -149,3 +152,3 @@

getFuncPreview,
registeredPlugins,
kRegisteredPlugins,
getDisplayName,

@@ -152,0 +155,0 @@ registerPlugin

@@ -21,3 +21,6 @@ 'use strict'

// the request is killed by client.
if (payload !== undefined || (reply.sent === false && reply.raw.headersSent === false && reply.request.raw.aborted === false)) {
// Most of the times aborted will be true when destroyed is true,
// however there is a race condition where the request is not
// aborted but only destroyed.
if (payload !== undefined || (reply.sent === false && reply.raw.headersSent === false && reply.request.raw.aborted === false && reply.request.raw.destroyed === false)) {
// we use a try-catch internally to avoid adding a catch to another

@@ -24,0 +27,0 @@ // promise, increase promise perf by 10%

{
"name": "fastify",
"version": "4.21.0",
"version": "4.22.0",
"description": "Fast and low overhead web framework, for Node.js",

@@ -17,6 +17,7 @@ "main": "fastify.js",

"lint": "npm run lint:standard && npm run lint:typescript && npm run lint:markdown",
"lint:fix": "standard --fix",
"lint:fix": "standard --fix && npm run lint:typescript:fix",
"lint:markdown": "markdownlint-cli2",
"lint:standard": "standard | snazzy",
"lint:typescript": "eslint -c types/.eslintrc.json types/**/*.d.ts test/types/**/*.test-d.ts",
"lint:typescript:fix": "npm run lint:typescript -- --fix",
"prepublishOnly": "cross-env PREPUBLISH=true tap --no-check-coverage test/build/**.test.js && npm run test:validator:integrity",

@@ -137,7 +138,7 @@ "test": "npm run lint && npm run unit && npm run test:typescript",

"@fastify/pre-commit": "^2.0.2",
"@sinclair/typebox": "^0.29.1",
"@sinclair/typebox": "^0.31.1",
"@sinonjs/fake-timers": "^11.0.0",
"@types/node": "^20.1.0",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"@typescript-eslint/eslint-plugin": "^6.3.0",
"@typescript-eslint/parser": "^6.3.0",
"ajv": "^8.12.0",

@@ -144,0 +145,0 @@ "ajv-errors": "^3.0.0",

@@ -5,2 +5,3 @@ 'use strict'

const sget = require('simple-get').concat
const zlib = require('zlib')
const t = require('tap')

@@ -49,2 +50,70 @@ const test = t.test

test('bodyLimit is applied to decoded content', t => {
t.plan(9)
const body = { x: 'x'.repeat(30000) }
const json = JSON.stringify(body)
const encoded = zlib.gzipSync(json)
const fastify = Fastify()
fastify.addHook('preParsing', async (req, reply, payload) => {
t.equal(req.headers['content-length'], `${encoded.length}`)
const unzip = zlib.createGunzip()
Object.defineProperty(unzip, 'receivedEncodedLength', {
get () {
return unzip.bytesWritten
}
})
payload.pipe(unzip)
return unzip
})
fastify.post('/body-limit-40k', {
bodyLimit: 40000,
onError: async (req, res, err) => {
t.fail('should not be called')
}
}, (request, reply) => {
reply.send({ x: request.body.x })
})
fastify.post('/body-limit-20k', {
bodyLimit: 20000,
onError: async (req, res, err) => {
t.equal(err.code, 'FST_ERR_CTP_BODY_TOO_LARGE')
t.equal(err.statusCode, 413)
}
}, (request, reply) => {
reply.send({ x: 'handler should not be called' })
})
fastify.inject({
method: 'POST',
url: '/body-limit-40k',
headers: {
'content-encoding': 'gzip',
'content-type': 'application/json'
},
payload: encoded
}, (err, res) => {
t.error(err)
t.equal(res.statusCode, 200)
t.same(res.json(), body)
})
fastify.inject({
method: 'POST',
url: '/body-limit-20k',
headers: {
'content-encoding': 'gzip',
'content-type': 'application/json'
},
payload: encoded
}, (err, res) => {
t.error(err)
t.equal(res.statusCode, 413)
})
})
test('default request.routeOptions.bodyLimit should be 1048576', t => {

@@ -51,0 +120,0 @@ t.plan(4)

@@ -13,4 +13,5 @@ 'use strict'

const localAddresses = await dns.lookup('localhost', { all: true })
const minPlan = localAddresses.length - 1 || 1
t.plan((localAddresses.length - 1) + 3)
t.plan(minPlan + 3)

@@ -17,0 +18,0 @@ const serverFactory = (handler, opts) => {

@@ -15,4 +15,5 @@ 'use strict'

const localAddresses = await dns.lookup('localhost', { all: true })
const minPlan = localAddresses.length - 1 || 1
t.plan((localAddresses.length - 1) + 3)
t.plan(minPlan + 3)

@@ -19,0 +20,0 @@ const serverFactory = (handler, opts) => {

@@ -32,2 +32,17 @@ 'use strict'

test('getPluginName should not throw when require.cache is undefined', t => {
t.plan(1)
function example () {
console.log('is just an example')
}
const cache = require.cache
require.cache = undefined
t.teardown(() => {
require.cache = cache
})
const pluginName = pluginUtilsPublic.getPluginName(example)
t.equal(pluginName, 'example')
})
test("getMeta should return the object stored with the 'plugin-meta' symbol", t => {

@@ -126,3 +141,3 @@ t.plan(1)

function context () {}
context[pluginUtilsPublic.registeredPlugins] = ['plugin']
context[pluginUtilsPublic.kRegisteredPlugins] = ['plugin']

@@ -148,3 +163,3 @@ try {

function context () {}
context[pluginUtilsPublic.registeredPlugins] = []
context[pluginUtilsPublic.kRegisteredPlugins] = []

@@ -151,0 +166,0 @@ try {

@@ -1250,1 +1250,27 @@ 'use strict'

})
test('hasPlugin returns true when using encapsulation', async t => {
t.plan(2)
const fastify = Fastify()
const pluginCallback = function (server, options, done) {
done()
}
const pluginName = 'awesome-plugin'
const plugin = fp(pluginCallback, { name: pluginName })
fastify.register(plugin)
fastify.register(async (server) => {
t.ok(server.hasPlugin(pluginName))
})
fastify.register(async function foo (server) {
server.register(async function bar (server) {
t.ok(server.hasPlugin(pluginName))
})
})
await fastify.ready()
})

@@ -13,3 +13,2 @@ import fastify, {

RouteGenericInterface,
ValidationResult,
FastifyErrorCodes,

@@ -22,3 +21,3 @@ FastifyError

import * as http2 from 'http2'
import { expectType, expectError, expectAssignable } from 'tsd'
import { expectType, expectError, expectAssignable, expectNotAssignable } from 'tsd'
import { FastifyLoggerInstance } from '../../types/logger'

@@ -249,3 +248,9 @@ import { Socket } from 'net'

}
expectAssignable<ValidationResult>(ajvErrorObject)
expectNotAssignable<AjvErrorObject>({
keyword: '',
instancePath: '',
schemaPath: '',
params: '',
message: ''
})

@@ -252,0 +257,0 @@ expectAssignable<FastifyError['validation']>([ajvErrorObject])

@@ -395,1 +395,14 @@ import { FastifyError } from '@fastify/error'

})
expectError(server.addHook('onClose', async function (instance, done) {}))
expectError(server.addHook('onError', async function (request, reply, error, done) {}))
expectError(server.addHook('onReady', async function (done) {}))
expectError(server.addHook('onRequest', async function (request, reply, done) {}))
expectError(server.addHook('onRequestAbort', async function (request, done) {}))
expectError(server.addHook('onResponse', async function (request, reply, done) {}))
expectError(server.addHook('onSend', async function (request, reply, payload, done) {}))
expectError(server.addHook('onTimeout', async function (request, reply, done) {}))
expectError(server.addHook('preClose', async function (done) {}))
expectError(server.addHook('preHandler', async function (request, reply, done) {}))
expectError(server.addHook('preSerialization', async function (request, reply, payload, done) {}))
expectError(server.addHook('preValidation', async function (request, reply, done) {}))

@@ -9,3 +9,4 @@ import { expectAssignable, expectDeprecated, expectError, expectNotDeprecated, expectType } from 'tsd'

RawRequestDefaultExpression,
RawServerDefault
RawServerDefault,
RouteGenericInterface
} from '../../fastify'

@@ -261,5 +262,9 @@ import { HookHandlerDoneFunction } from '../../types/hooks'

expectType<FastifyInstance>(fastify().get('/', {
expectType<FastifyInstance>(fastify().get<RouteGenericInterface, { contextKey: string }>('/', {
handler: () => {},
errorHandler: (error, request, reply) => {
expectAssignable<FastifyError>(error)
expectAssignable<FastifyRequest>(request)
expectAssignable<{ contextKey: string }>(request.routeConfig)
expectAssignable<FastifyReply>(reply)
expectAssignable<void>(server.errorHandler(error, request, reply))

@@ -266,0 +271,0 @@ }

@@ -86,3 +86,3 @@ import pino from 'pino'

expectType<RequestQuerystringDefault>(request.query)
expectType<any>(request.id)
expectType<string>(request.id)
expectType<FastifyLoggerInstance>(request.log)

@@ -89,0 +89,0 @@ expectType<RawRequestDefaultExpression['socket']>(request.socket)

@@ -6,3 +6,4 @@ import fastify, {

FastifyReply,
FastifyInstance
FastifyInstance,
FastifyError
} from '../../fastify'

@@ -83,2 +84,10 @@ import { expectAssignable, expectError, expectType } from 'tsd'

})
},
errorHandler: (error, request, reply) => {
expectType<FastifyError>(error)
expectAssignable<FastifyRequest>(request)
expectType<number>(request.body.x)
expectType<number>(request.body.y)
expectType<number>(request.body.z)
expectAssignable<FastifyReply>(reply)
}

@@ -113,2 +122,10 @@ },

} as const
},
errorHandler: (error, request, reply) => {
expectType<FastifyError>(error)
expectAssignable<FastifyRequest>(request)
expectType<number | undefined>(request.body.x)
expectType<string | undefined>(request.body.y)
expectType<boolean | undefined>(request.body.z)
expectAssignable<FastifyReply>(reply)
}

@@ -141,2 +158,10 @@ },

} as const
},
errorHandler: (error, request, reply) => {
expectType<FastifyError>(error)
expectAssignable<FastifyRequest>(request)
expectType<number | undefined>(request.body.x)
expectType<string | undefined>(request.body.y)
expectType<boolean | undefined>(request.body.z)
expectAssignable<FastifyReply>(reply)
}

@@ -143,0 +168,0 @@ },

@@ -30,1 +30,23 @@ 'use strict'

})
test('should not send the payload if the raw socket was destroyed but not aborted', async t => {
const reply = {
sent: false,
raw: {
headersSent: false
},
request: {
raw: {
aborted: false,
destroyed: true
}
},
send () {
t.fail('should not send')
}
}
const thenable = Promise.resolve()
wrapThenable(thenable, reply)
await thenable
})

@@ -193,3 +193,3 @@ import { Readable } from 'stream'

export interface preSerializationHookHandler<
PreSerializationPayload,
PreSerializationPayload = unknown,
RawServer extends RawServerBase = RawServerDefault,

@@ -214,3 +214,3 @@ RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,

export interface preSerializationAsyncHookHandler<
PreSerializationPayload,
PreSerializationPayload = unknown,
RawServer extends RawServerBase = RawServerDefault,

@@ -238,3 +238,3 @@ RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,

export interface onSendHookHandler<
OnSendPayload,
OnSendPayload = unknown,
RawServer extends RawServerBase = RawServerDefault,

@@ -259,3 +259,3 @@ RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,

export interface onSendAsyncHookHandler<
OnSendPayload,
OnSendPayload = unknown,
RawServer extends RawServerBase = RawServerDefault,

@@ -439,2 +439,62 @@ RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,

export type LifecycleHook = 'onRequest'
| 'preParsing'
| 'preValidation'
| 'preHandler'
| 'preSerialization'
| 'onSend'
| 'onResponse'
| 'onRequest'
| 'onError'
| 'onTimeout'
| 'onRequestAbort'
export type LifecycleHookLookup<K extends LifecycleHook> = K extends 'onRequest'
? onRequestHookHandler
: K extends 'preParsing'
? preParsingHookHandler
: K extends 'preValidation'
? preValidationHookHandler
: K extends 'preHandler'
? preHandlerHookHandler
: K extends 'preSerialization'
? preSerializationHookHandler
: K extends 'onSend'
? onSendHookHandler
: K extends 'onResponse'
? onResponseHookHandler
: K extends 'onRequest'
? onRequestHookHandler
: K extends 'onError'
? onErrorHookHandler
: K extends 'onTimeout'
? onTimeoutHookHandler
: K extends 'onRequestAbort'
? onRequestAbortHookHandler
: never
export type LifecycleHookAsyncLookup<K extends LifecycleHook> = K extends 'onRequest'
? onRequestAsyncHookHandler
: K extends 'preParsing'
? preParsingAsyncHookHandler
: K extends 'preValidation'
? preValidationAsyncHookHandler
: K extends 'preHandler'
? preHandlerAsyncHookHandler
: K extends 'preSerialization'
? preSerializationAsyncHookHandler
: K extends 'onSend'
? onSendAsyncHookHandler
: K extends 'onResponse'
? onResponseAsyncHookHandler
: K extends 'onRequest'
? onRequestAsyncHookHandler
: K extends 'onError'
? onErrorAsyncHookHandler
: K extends 'onTimeout'
? onTimeoutAsyncHookHandler
: K extends 'onRequestAbort'
? onRequestAbortAsyncHookHandler
: never
// Application Hooks

@@ -563,1 +623,41 @@

}
export type ApplicationHook = 'onRoute'
| 'onRegister'
| 'onReady'
| 'onClose'
| 'preClose'
export type ApplicationHookLookup<K extends ApplicationHook> = K extends 'onRegister'
? onRegisterHookHandler
: K extends 'onReady'
? onReadyHookHandler
: K extends 'onClose'
? onCloseHookHandler
: K extends 'preClose'
? preCloseHookHandler
: K extends 'onRoute'
? onRouteHookHandler
: never
export type ApplicationHookAsyncLookup<K extends ApplicationHook> = K extends 'onRegister'
? onRegisterHookHandler
: K extends 'onReady'
? onReadyAsyncHookHandler
: K extends 'onClose'
? onCloseAsyncHookHandler
: K extends 'preClose'
? preCloseAsyncHookHandler
: never
export type HookLookup <K extends ApplicationHook | LifecycleHook> = K extends ApplicationHook
? ApplicationHookLookup<K>
: K extends LifecycleHook
? LifecycleHookLookup<K>
: never
export type HookAsyncLookup <K extends ApplicationHook | LifecycleHook> = K extends ApplicationHook
? ApplicationHookAsyncLookup<K>
: K extends LifecycleHook
? LifecycleHookAsyncLookup<K>
: never

@@ -6,3 +6,3 @@ import { FastifyError } from '@fastify/error'

import { AddContentTypeParser, ConstructorAction, FastifyBodyParser, getDefaultJsonParser, hasContentTypeParser, ProtoAction, removeAllContentTypeParsers, removeContentTypeParser } from './content-type-parser'
import { onCloseAsyncHookHandler, onCloseHookHandler, onErrorAsyncHookHandler, onErrorHookHandler, onReadyAsyncHookHandler, onReadyHookHandler, onRegisterHookHandler, onRequestAsyncHookHandler, onRequestHookHandler, onRequestAbortAsyncHookHandler, onRequestAbortHookHandler, onResponseAsyncHookHandler, onResponseHookHandler, onRouteHookHandler, onSendAsyncHookHandler, onSendHookHandler, onTimeoutAsyncHookHandler, onTimeoutHookHandler, preHandlerAsyncHookHandler, preHandlerHookHandler, preParsingAsyncHookHandler, preParsingHookHandler, preSerializationAsyncHookHandler, preSerializationHookHandler, preValidationAsyncHookHandler, preValidationHookHandler, preCloseHookHandler, preCloseAsyncHookHandler } from './hooks'
import { onCloseAsyncHookHandler, onCloseHookHandler, onErrorAsyncHookHandler, onErrorHookHandler, onReadyAsyncHookHandler, onReadyHookHandler, onRegisterHookHandler, onRequestAsyncHookHandler, onRequestHookHandler, onRequestAbortAsyncHookHandler, onRequestAbortHookHandler, onResponseAsyncHookHandler, onResponseHookHandler, onRouteHookHandler, onSendAsyncHookHandler, onSendHookHandler, onTimeoutAsyncHookHandler, onTimeoutHookHandler, preHandlerAsyncHookHandler, preHandlerHookHandler, preParsingAsyncHookHandler, preParsingHookHandler, preSerializationAsyncHookHandler, preSerializationHookHandler, preValidationAsyncHookHandler, preValidationHookHandler, preCloseHookHandler, preCloseAsyncHookHandler, LifecycleHook, ApplicationHook, HookAsyncLookup, HookLookup } from './hooks'
import { FastifyBaseLogger, FastifyChildLoggerFactory } from './logger'

@@ -34,2 +34,4 @@ import { FastifyRegister } from './register'

type AsyncFunction = (...args: any) => Promise<any>;
export interface FastifyListenOptions {

@@ -229,18 +231,9 @@ /**

SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
Logger extends FastifyBaseLogger = FastifyBaseLogger,
Fn extends onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> = onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
>(
name: 'onRequest',
hook: onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
hook: Fn extends unknown ? Fn extends AsyncFunction ? onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : onRequestHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : Fn,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
addHook<
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
ContextConfig = ContextConfigDefault,
SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
>(
name: 'onRequest',
hook: onRequestAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
/**

@@ -254,18 +247,9 @@ * `preParsing` is the second hook to be executed in the request lifecycle. The previous hook was `onRequest`, the next hook will be `preValidation`.

SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
Logger extends FastifyBaseLogger = FastifyBaseLogger,
Fn extends preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> = preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
>(
name: 'preParsing',
hook: preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
hook: Fn extends unknown ? Fn extends AsyncFunction ? preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : preParsingHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : Fn,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
addHook<
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
ContextConfig = ContextConfigDefault,
SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
>(
name: 'preParsing',
hook: preParsingAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
/**

@@ -278,18 +262,9 @@ * `preValidation` is the third hook to be executed in the request lifecycle. The previous hook was `preParsing`, the next hook will be `preHandler`.

SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
Logger extends FastifyBaseLogger = FastifyBaseLogger,
Fn extends preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> = preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
>(
name: 'preValidation',
hook: preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
hook: Fn extends unknown ? Fn extends AsyncFunction ? preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : preValidationHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : Fn,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
addHook<
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
ContextConfig = ContextConfigDefault,
SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
>(
name: 'preValidation',
hook: preValidationAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
/**

@@ -302,18 +277,9 @@ * `preHandler` is the fourth hook to be executed in the request lifecycle. The previous hook was `preValidation`, the next hook will be `preSerialization`.

SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
Logger extends FastifyBaseLogger = FastifyBaseLogger,
Fn extends preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> = preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
>(
name: 'preHandler',
hook: preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
hook: Fn extends unknown ? Fn extends AsyncFunction ? preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : preHandlerHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : Fn,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
addHook<
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
ContextConfig = ContextConfigDefault,
SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
>(
name: 'preHandler',
hook: preHandlerAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
/**

@@ -328,19 +294,9 @@ * `preSerialization` is the fifth hook to be executed in the request lifecycle. The previous hook was `preHandler`, the next hook will be `onSend`.

SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
Logger extends FastifyBaseLogger = FastifyBaseLogger,
Fn extends preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> = preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
>(
name: 'preSerialization',
hook: preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
hook: Fn extends unknown ? Fn extends AsyncFunction ? preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : preSerializationHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : Fn,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
addHook<
PreSerializationPayload = unknown,
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
ContextConfig = ContextConfigDefault,
SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
>(
name: 'preSerialization',
hook: preSerializationAsyncHookHandler<PreSerializationPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
/**

@@ -355,19 +311,9 @@ * You can change the payload with the `onSend` hook. It is the sixth hook to be executed in the request lifecycle. The previous hook was `preSerialization`, the next hook will be `onResponse`.

SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
Logger extends FastifyBaseLogger = FastifyBaseLogger,
Fn extends onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> = onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
>(
name: 'onSend',
hook: onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
hook: Fn extends unknown ? Fn extends AsyncFunction ? onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : onSendHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : Fn,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
addHook<
OnSendPayload = unknown,
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
ContextConfig = ContextConfigDefault,
SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
>(
name: 'onSend',
hook: onSendAsyncHookHandler<OnSendPayload, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
/**

@@ -381,18 +327,9 @@ * `onResponse` is the seventh and last hook in the request hook lifecycle. The previous hook was `onSend`, there is no next hook.

SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
Logger extends FastifyBaseLogger = FastifyBaseLogger,
Fn extends onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> = onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
>(
name: 'onResponse',
hook: onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
hook: Fn extends unknown ? Fn extends AsyncFunction ? onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : onResponseHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : Fn,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
addHook<
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
ContextConfig = ContextConfigDefault,
SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
>(
name: 'onResponse',
hook: onResponseAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
/**

@@ -406,18 +343,9 @@ * `onTimeout` is useful if you need to monitor the request timed out in your service. (if the `connectionTimeout` property is set on the fastify instance)

SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
Logger extends FastifyBaseLogger = FastifyBaseLogger,
Fn extends onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> = onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
>(
name: 'onTimeout',
hook: onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
hook: Fn extends unknown ? Fn extends AsyncFunction ? onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : onTimeoutHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : Fn,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
addHook<
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
ContextConfig = ContextConfigDefault,
SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
>(
name: 'onTimeout',
hook: onTimeoutAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
/**

@@ -432,18 +360,9 @@ * `onRequestAbort` is useful if you need to monitor the if the client aborts the request (if the `request.raw.aborted` property is set to `true`).

SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
Logger extends FastifyBaseLogger = FastifyBaseLogger,
Fn extends onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> | onRequestAbortAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> = onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
>(
name: 'onRequestAbort',
hook: onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
hook: Fn extends unknown ? Fn extends AsyncFunction ? onRequestAbortAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : onRequestAbortHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> : Fn,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
addHook<
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
ContextConfig = ContextConfigDefault,
SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
>(
name: 'onRequestAbort',
hook: onRequestAbortAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
/**

@@ -459,18 +378,9 @@ * This hook is useful if you need to do some custom error logging or add some specific header in case of error.

SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
Logger extends FastifyBaseLogger = FastifyBaseLogger,
Fn extends onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger> | onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger> = onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>
>(
name: 'onError',
hook: onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>
hook: Fn extends unknown ? Fn extends AsyncFunction ? onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger> : onErrorHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger> : Fn,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
addHook<
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
ContextConfig = ContextConfigDefault,
SchemaCompiler extends FastifySchema = FastifySchema,
Logger extends FastifyBaseLogger = FastifyBaseLogger
>(
name: 'onError',
hook: onErrorAsyncHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, SchemaCompiler, TypeProvider, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
// Application addHooks

@@ -504,37 +414,36 @@

*/
addHook(
addHook<
Fn extends onReadyHookHandler | onReadyAsyncHookHandler = onReadyHookHandler
>(
name: 'onReady',
hook: onReadyHookHandler
hook: Fn extends unknown ? Fn extends AsyncFunction ? onReadyAsyncHookHandler : onReadyHookHandler : Fn,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
addHook(
name: 'onReady',
hook: onReadyAsyncHookHandler,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
/**
* Triggered when fastify.close() is invoked to stop the server. It is useful when plugins need a "shutdown" event, for example to close an open connection to a database.
*/
addHook(
addHook<
Fn extends onCloseHookHandler | onCloseAsyncHookHandler = onCloseHookHandler
>(
name: 'onClose',
hook: onCloseHookHandler<RawServer, RawRequest, RawReply, Logger, TypeProvider>
hook: Fn extends unknown ? Fn extends AsyncFunction ? onCloseAsyncHookHandler : onCloseHookHandler : Fn,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
addHook(
name: 'onClose',
hook: onCloseAsyncHookHandler<RawServer, RawRequest, RawReply, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
/**
* Triggered when fastify.close() is invoked to stop the server. It is useful when plugins need to cancel some state to allow the server to close successfully.
*/
addHook(
addHook<
Fn extends preCloseHookHandler | preCloseAsyncHookHandler = preCloseHookHandler
>(
name: 'preClose',
hook: preCloseHookHandler<RawServer, RawRequest, RawReply, Logger, TypeProvider>
hook: Fn extends unknown ? Fn extends AsyncFunction ? preCloseAsyncHookHandler : preCloseHookHandler : Fn,
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;
addHook(
name: 'preClose',
hook: preCloseAsyncHookHandler<RawServer, RawRequest, RawReply, Logger>
): FastifyInstance<RawServer, RawRequest, RawReply, Logger>;
addHook<
K extends ApplicationHook | LifecycleHook,
Fn extends (...args: any) => Promise<any> | any
> (
name: K,
hook: Fn extends unknown ? Fn extends AsyncFunction ? HookAsyncLookup<K> : HookLookup<K> : Fn
): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;

@@ -541,0 +450,0 @@ /**

@@ -53,3 +53,3 @@ import { ErrorObject } from '@fastify/ajv-compiler'

> {
id: any;
id: string;
params: RequestType['params']; // deferred inference

@@ -56,0 +56,0 @@ raw: RawRequest;

@@ -48,3 +48,8 @@ import { FastifyError } from '@fastify/error'

prefixTrailingSlash?: 'slash'|'no-slash'|'both';
errorHandler?: (this: FastifyInstance, error: FastifyError, request: FastifyRequest, reply: FastifyReply) => void;
errorHandler?: (
this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,
error: FastifyError,
request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger>,
reply: FastifyReply<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider>
) => void;
childLoggerFactory?: FastifyChildLoggerFactory<RawServer, RawRequest, RawReply, Logger, TypeProvider>;

@@ -51,0 +56,0 @@ schemaErrorFormatter?: SchemaErrorFormatter;

@@ -31,3 +31,3 @@ import { ValidatorFactory } from '@fastify/ajv-compiler'

schemaPath: string;
params: Record<string, string | string[]>;
params: Record<string, unknown>;
message?: string;

@@ -34,0 +34,0 @@ }

@@ -10,5 +10,5 @@ {

"include": [
"/test/types/*.test-d.ts",
"/types/*.d.ts"
"../test/types/**/*.test-d.ts",
"./**/*.d.ts"
]
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc