UNPKG

1.49 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>(
17 fn: FastifyPluginCallback<Options>,
18 options?: PluginMetadata,
19): FastifyPluginCallback<Options>;
20export default function fp<Options>(
21 fn: FastifyPluginAsync<Options>,
22 options?: PluginMetadata,
23): FastifyPluginAsync<Options>;
24
25export default function fp<Options>(
26 fn: FastifyPluginCallback<Options>,
27 options?: string,
28): FastifyPluginCallback<Options>;
29export default function fp<Options>(
30 fn: FastifyPluginAsync<Options>,
31 options?: string,
32): FastifyPluginAsync<Options>;
33
34export interface PluginMetadata {
35 /** Bare-minimum version of Fastify for your plugin, just add the semver range that you need. */
36 fastify?: string,
37 name?: string,
38 /** Decorator dependencies for this plugin */
39 decorators?: {
40 fastify?: string[],
41 reply?: string[],
42 request?: string[]
43 },
44 /** The plugin dependencies */
45 dependencies?: string[]
46}
47
48// Exporting PluginOptions for backward compatibility after renaming it to PluginMetadata
49export interface PluginOptions extends PluginMetadata {}
50
51export type NextCallback = (err?: Error) => void;