generated from Eomm/fastify-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.d.ts
124 lines (108 loc) · 3.87 KB
/
index.d.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import type { FastifyPluginCallback, RouteOptions, HTTPMethods } from 'fastify'
interface OverviewStructureSource {
stackIndex: number,
fileName: string,
relativeFileName: string,
lineNumber: number,
columnNumber: number,
functionName: string,
typeName?: string,
methodName?: string,
}
interface OverviewStructureDecorator {
name: string;
type: 'undefined' | 'object' | 'boolean' | 'number' | 'bigint' | 'string' | 'symbol' | 'function' | 'array'
source?: OverviewStructureSource,
}
interface OverviewStructureHook {
name: string;
hash: string;
source?: OverviewStructureSource;
}
interface OverviewStructureHooks {
onRequest?: OverviewStructureHook[],
preParsing?: OverviewStructureHook[],
preValidation?: OverviewStructureHook[],
preHandler?: OverviewStructureHook[],
preSerialization?: OverviewStructureHook[],
onError?: OverviewStructureHook[],
onSend?: OverviewStructureHook[],
onResponse?: OverviewStructureHook[],
onTimeout?: OverviewStructureHook[],
onListen?: OverviewStructureHook[],
onReady?: OverviewStructureHook[],
preClose?: OverviewStructureHook[],
onClose?: OverviewStructureHook[],
onRoute?: OverviewStructureHook[],
onRegister?: OverviewStructureHook[],
onRequestAbort?: OverviewStructureHook[],
}
interface RouteItem {
method: HTTPMethods | HTTPMethods[],
url: string,
prefix: string,
hooks: OverviewStructureHooks,
source?: OverviewStructureSource,
}
export interface Decorators {
instance?: Record<string, unknown>
request?: Record<string, unknown>
reply?: Record<string, unknown>
}
type ExtractDecoratorType<T extends Record<PropertyKey, unknown>, K extends keyof Decorators> = T extends Decorators ? T[K] : T
export interface OverviewStructure<T = {}, D extends Record<PropertyKey, unknown> = {}> {
id: Number,
name: string,
source?: OverviewStructureSource,
children?: OverviewStructure<T>[],
decorators?: {
decorate: (Omit<OverviewStructureDecorator, keyof ExtractDecoratorType<D, 'instance'>> & ExtractDecoratorType<D, 'instance'>)[],
decorateRequest: (Omit<OverviewStructureDecorator, keyof ExtractDecoratorType<D, 'request'>> & ExtractDecoratorType<D, 'request'>)[],
decorateReply: (Omit<OverviewStructureDecorator, keyof ExtractDecoratorType<D, 'reply'>> & ExtractDecoratorType<D, 'reply'>)[]
},
hooks?: OverviewStructureHooks,
routes?: (Omit<RouteItem, keyof T> & T)[]
}
export interface FastifyOverviewOptions {
/**
* Add a `source` property to each node of the tree.
* @default false
*/
addSource?: boolean,
/**
* Expose a route that will return the JSON structure.
* By default the route is exposed at `GET /json-overview`.
* @default false
*/
exposeRoute?: boolean,
/**
* Customize the route's options when `exposeRoute` is set to `true`
*/
exposeRouteOptions?: Partial<RouteOptions>,
/**
* Customise which properties of the route options will be included in the overview
*/
onRouteDefinition?: (routeOptions: RouteOptions & { routePath: string; path: string; prefix: string }) => Record<string, unknown>
/**
* Customise which information from decorators should be added to the overview
*/
onDecorateDefinition?: (type: 'decorate' | 'decorateRequest' | 'decorateReply', name: string, value: unknown) => Record<string, unknown>
}
export interface FastifyOverviewDecoratorOptions {
/**
* Filters routes based on the provided predicate
*/
routesFilter?: (routeItem: RouteItem) => boolean,
/**
* To keep the structure light and clean, you can hide empty properties
* @default false
*/
hideEmpty?: boolean,
}
declare module 'fastify' {
export interface FastifyInstance {
overview: <T = {}, D extends Record<PropertyKey, unknown> = {}>(opts?: FastifyOverviewDecoratorOptions) => OverviewStructure<T, D>;
}
}
export const FastifyOverview: FastifyPluginCallback<FastifyOverviewOptions>
export default FastifyOverview