UNPKG

2.2 kBTypeScriptView Raw
1import { FastifyInstance } from './instance'
2import { RawServerBase, RawRequestDefaultExpression, RawReplyDefaultExpression, RawServerDefault } from './utils'
3import { FastifyTypeProvider, FastifyTypeProviderDefault } from './type-provider'
4import { FastifyBaseLogger } from './logger'
5
6export type FastifyPluginOptions = Record<string, any>
7
8/**
9 * FastifyPluginCallback
10 *
11 * Fastify allows the user to extend its functionalities with plugins. A plugin can be a set of routes, a server decorator or whatever. To activate plugins, use the `fastify.register()` method.
12 */
13export type FastifyPluginCallback<
14 Options extends FastifyPluginOptions = Record<never, never>,
15 Server extends RawServerBase = RawServerDefault,
16 TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
17 Logger extends FastifyBaseLogger = FastifyBaseLogger,
18> = (
19 instance: FastifyInstance<Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>, Logger, TypeProvider>,
20 opts: Options,
21 done: (err?: Error) => void
22) => void
23
24/**
25 * FastifyPluginAsync
26 *
27 * Fastify allows the user to extend its functionalities with plugins. A plugin can be a set of routes, a server decorator or whatever. To activate plugins, use the `fastify.register()` method.
28 */
29export type FastifyPluginAsync<
30 Options extends FastifyPluginOptions = Record<never, never>,
31 Server extends RawServerBase = RawServerDefault,
32 TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
33 Logger extends FastifyBaseLogger = FastifyBaseLogger,
34> = (
35 instance: FastifyInstance<Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>, Logger, TypeProvider>,
36 opts: Options
37) => Promise<void>;
38
39/**
40 * Generic plugin type.
41 * @deprecated union type doesn't work well with type inference in TS and is therefore deprecated in favor of explicit types. Use `FastifyPluginCallback` or `FastifyPluginAsync` instead. To activate
42 * plugins use `FastifyRegister`. https://fastify.dev/docs/latest/Reference/TypeScript/#register
43 */
44export type FastifyPlugin<Options extends FastifyPluginOptions = Record<never, never>> = FastifyPluginCallback<Options> | FastifyPluginAsync<Options>