forked from fastify/fastify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.d.ts
124 lines (116 loc) · 6.99 KB
/
route.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 { FastifyInstance } from './instance'
import { FastifyRequest, RequestGenericInterface } from './request'
import { FastifyReply } from './reply'
import { FastifySchema, FastifySchemaCompiler } from './schema'
import { HTTPMethods, RawServerBase, RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, ContextConfigDefault } from './utils'
import { LogLevel } from './logger'
import { preValidationHookHandler, preHandlerHookHandler, preSerializationHookHandler, onRequestHookHandler, preParsingHookHandler, onResponseHookHandler, onSendHookHandler, onErrorHookHandler } from './hooks'
/**
* Fastify Router Shorthand method type that is similar to the Express/Restify approach
*/
export interface RouteShorthandMethod<
RawServer extends RawServerBase = RawServerDefault,
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
> {
<RequestGeneric extends RequestGenericInterface = RequestGenericInterface, ContextConfig = ContextConfigDefault>(
path: string,
opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>,
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>
): FastifyInstance<RawServer, RawRequest, RawReply>;
}
/**
* Fastify Router Shorthand method type that is similar to the Express/Restify approach
*/
export interface RouteShorthandMethod<
RawServer extends RawServerBase = RawServerDefault,
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
> {
<RequestGeneric extends RequestGenericInterface = RequestGenericInterface, ContextConfig = ContextConfigDefault>(
path: string,
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>
): FastifyInstance<RawServer, RawRequest, RawReply>;
}
/**
* Fastify Router Shorthand method type that is similar to the Express/Restify approach
*/
export interface RouteShorthandMethod<
RawServer extends RawServerBase = RawServerDefault,
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
> {
<RequestGeneric extends RequestGenericInterface = RequestGenericInterface, ContextConfig = ContextConfigDefault>(
path: string,
opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>
): FastifyInstance<RawServer, RawRequest, RawReply>;
}
/**
* Route shorthand options for the various shorthand methods
*/
export interface RouteShorthandOptions<
RawServer extends RawServerBase = RawServerDefault,
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
RequestGeneric extends RequestGenericInterface = RequestGenericInterface,
ContextConfig = ContextConfigDefault
> {
schema?: FastifySchema;
attachValidation?: boolean;
validatorCompiler?: FastifySchemaCompiler;
serializerCompiler?: FastifySchemaCompiler;
bodyLimit?: number;
logLevel?: LogLevel;
config?: ContextConfig;
version?: string;
prefixTrailingSlash?: boolean;
// hooks
onRequest?: onRequestHookHandler<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig> | onRequestHookHandler<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>[];
preParsing?: preParsingHookHandler<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig> | preParsingHookHandler<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>[];
preValidation?: preValidationHookHandler<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig> | preValidationHookHandler<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>[];
preHandler?: preHandlerHookHandler<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig> | preHandlerHookHandler<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>[];
preSerialization?: preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig> | preSerializationHookHandler<unknown, RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>[];
onSend?: onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig> | onSendHookHandler<unknown, RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>[];
onResponse?: onResponseHookHandler<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig> | onResponseHookHandler<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>[];
onError?: onErrorHookHandler<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig> | onErrorHookHandler<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>[];
}
/**
* Fastify route method options.
*/
export interface RouteOptions<
RawServer extends RawServerBase = RawServerDefault,
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
RequestGeneric extends RequestGenericInterface = RequestGenericInterface,
ContextConfig = ContextConfigDefault
> extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig> {
method: HTTPMethods | HTTPMethods[];
url: string;
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>;
}
/**
* Shorthand options including the handler function property
*/
export interface RouteShorthandOptionsWithHandler<
RawServer extends RawServerBase = RawServerDefault,
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
RequestGeneric extends RequestGenericInterface = RequestGenericInterface,
ContextConfig = ContextConfigDefault
> extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig> {
handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>;
}
/**
* Route handler method declaration.
*/
export type RouteHandlerMethod<
RawServer extends RawServerBase = RawServerDefault,
RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,
RequestGeneric extends RequestGenericInterface = RequestGenericInterface,
ContextConfig = ContextConfigDefault
> = (
this: FastifyInstance<RawServer, RawRequest, RawReply>,
request: FastifyRequest<RawServer, RawRequest, RequestGeneric>,
reply: FastifyReply<RawServer, RawRequest, RawReply, RequestGeneric, ContextConfig>
) => void | Promise<any>