UNPKG

1.56 kBTypeScriptView Raw
1import { FastifyInstance } from './instance'
2import { RawServerBase, RawRequestDefaultExpression, RawReplyDefaultExpression, RawServerDefault } from './utils'
3
4/**
5 * FastifyPluginCallback
6 *
7 * 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.
8 */
9export type FastifyPluginCallback<Options extends FastifyPluginOptions = {}, Server extends RawServerBase = RawServerDefault> = (
10 instance: FastifyInstance<Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>>,
11 opts: Options,
12 next: (err?: Error) => void
13) => void
14
15/**
16 * FastifyPluginAsync
17 *
18 * 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.
19 */
20export type FastifyPluginAsync<Options extends FastifyPluginOptions = {}, Server extends RawServerBase = RawServerDefault> = (
21 instance: FastifyInstance<Server, RawRequestDefaultExpression<Server>, RawReplyDefaultExpression<Server>>,
22 opts: Options
23) => Promise<void>;
24
25/**
26 * Generic plugin type.
27 * @deprecated union type doesn't work well with type inference in TS and is therefore deprecated in favor of explicit types. See FastifyRegister.
28 */
29export type FastifyPlugin<Options extends FastifyPluginOptions = {}> = FastifyPluginCallback<Options> | FastifyPluginAsync<Options>
30
31export interface FastifyPluginOptions {
32 [key: string]: any;
33}