UNPKG

1.44 kBTypeScriptView Raw
1/// <reference types="fastify" />
2
3import {
4 FastifyPluginCallback,
5 FastifyPluginAsync,
6} from 'fastify'
7
8/**
9 * This function does three things for you:
10 * 1. Add the `skip-override` hidden property
11 * 2. Check bare-minimum version of Fastify
12 * 3. Pass some custom metadata of the plugin to Fastify
13 * @param fn Fastify plugin function
14 * @param options Optional plugin options
15 */
16export default function fp<Options>(fn: FastifyPluginAsync<Options>, options?: PluginMetadata): FastifyPluginAsync<Options>;
17export default function fp<Options>(fn: FastifyPluginAsync<Options>, options?: string): FastifyPluginAsync<Options>;
18export default function fp<Options>(fn: FastifyPluginCallback<Options>, options?: PluginMetadata): FastifyPluginCallback<Options>;
19export default function fp<Options>(fn: FastifyPluginCallback<Options>, options?: string): FastifyPluginCallback<Options>;
20
21export interface PluginMetadata {
22 /** Bare-minimum version of Fastify for your plugin, just add the semver range that you need. */
23 fastify?: string,
24 name?: string,
25 /** Decorator dependencies for this plugin */
26 decorators?: {
27 fastify?: (string | symbol)[],
28 reply?: (string | symbol)[],
29 request?: (string | symbol)[]
30 },
31 /** The plugin dependencies */
32 dependencies?: string[]
33}
34
35// Exporting PluginOptions for backward compatibility after renaming it to PluginMetadata
36export interface PluginOptions extends PluginMetadata {}