-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.d.ts
96 lines (84 loc) · 2.29 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
declare module 'node-susanin' {
import {
Router,
Request,
Response,
NextFunction,
} from 'express';
import {
Schema,
} from 'joi';
interface AnyProps {
[key: string]: any;
}
interface MiddlewaresSequenceArgs {
PARAMS_VALIDATION: symbol,
QUERY_VALIDATION: symbol,
BODY_VALIDATION: symbol,
ROUTER_MIDDLEWARES: symbol,
}
type ErrorFn = (error: any) => void;
type PassFn = () => void;
type SetToReqFn = (key: string, value: any) => void;
interface ModernMiddlewareProps {
req: Request;
res: Response;
next: NextFunction;
headers: AnyProps;
error: ErrorFn;
pass: PassFn;
setToReq: SetToReqFn;
props: AnyProps;
}
type ModernMiddlewareFn = (params: ModernMiddlewareProps) => any;
type ExpressMiddleware = (req: Request, res: Response, next: NextFunction) => any;
type Middleware = ModernMiddlewareFn | ExpressMiddleware;
type MiddlewaresSequence = (args: MiddlewaresSequenceArgs) => (symbol | Middleware)[];
interface ObjectWithJoiValidation {
[key: string]: Schema;
}
interface RouteValidation {
query?: Schema | ObjectWithJoiValidation;
params?: Schema | ObjectWithJoiValidation;
body?: Schema | ObjectWithJoiValidation;
}
interface Configuration {
routesPaths: string[];
pathsRelateTo: string;
routePrefix?: string | null;
extraControllerProps?: string[];
middlewaresSequence?: MiddlewaresSequence;
onValidationError?: (error: Error) => any;
onReply?: (data: any) => any;
defaultValidation?: RouteValidation;
}
interface ControllerParams {
req: Request;
res: Response;
next: NextFunction;
reply(data: any): void;
error: ErrorFn;
headers: AnyProps;
params: AnyProps;
body: AnyProps;
query: AnyProps;
[key: string]: any;
errorP(err: any): any;
errorP(err: any, promise: Promise<any>): Promise<any>;
}
interface RouteDescription {
name?: string;
description?: string;
version?: string;
group?: string;
}
export interface Route {
method: symbol;
path: string;
controller: (params: ControllerParams) => void | Promise<any>;
middlewares?: Middleware[];
validation: RouteValidation;
info?: RouteDescription;
}
export function createRouter (config: Configuration): Router;
}