forked from fastify/fastify-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
44 lines (39 loc) · 1.61 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { FastifyBaseLogger, FastifyPluginCallback, FastifyPluginAsync, FastifyTypeProvider, RawServerBase, FastifyPluginOptions } from 'fastify'
export interface PluginMetadata {
/** Bare-minimum version of Fastify for your plugin, just add the semver range that you need. */
fastify?: string
name?: string
/** Decorator dependencies for this plugin */
decorators?: {
fastify?: Array<string | symbol>
reply?: Array<string | symbol>
request?: Array<string | symbol>
}
/** The plugin dependencies */
dependencies?: string[]
encapsulate?: boolean
}
/**
* @deprecated Use PluginMetadata instead
*/
export interface PluginOptions extends PluginMetadata {}
export type PromiseFunction = (...args: any) => Promise<any>
export type PluginAsyncOrCallback<
Options extends FastifyPluginOptions,
RawServer extends RawServerBase,
TypeProvider extends FastifyTypeProvider,
Logger extends FastifyBaseLogger,
Fn extends PluginAsyncOrCallback<Options, RawServer, TypeProvider, Logger, Fn> | unknown
> = FastifyPluginCallback<Options, RawServer, TypeProvider, Logger> |
FastifyPluginAsync<Options, RawServer, TypeProvider, Logger>
export type GetPluginAsyncOrCallback<
Options extends FastifyPluginOptions,
RawServer extends RawServerBase,
TypeProvider extends FastifyTypeProvider,
Logger extends FastifyBaseLogger,
Fn extends PluginAsyncOrCallback<Options, RawServer, TypeProvider, Logger, Fn> | unknown,
> = Fn extends unknown
? Fn extends PromiseFunction
? FastifyPluginAsync<Options, RawServer, TypeProvider, Logger>
: FastifyPluginCallback<Options, RawServer, TypeProvider, Logger>
: Fn