-
Notifications
You must be signed in to change notification settings - Fork 3
/
types.d.ts
46 lines (40 loc) · 1.09 KB
/
types.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
import {
NextFunction,
IRouter as IExpressRouter,
RequestHandler,
} from 'express';
import RESOURCES from './src/resources';
export type EndpointNames = keyof typeof RESOURCES;
export type RequestMethods = 'get' | 'post' | 'put' | 'patch' | 'delete';
export type RegisterCb = (g: IRouter) => void;
export type GroupArgs = [...unknown[], RegisterCb];
export interface IResource {
index?: RequestHandler;
show?: RequestHandler;
store?: RequestHandler;
update?: RequestHandler;
patch?: RequestHandler;
destroy?: RequestHandler;
}
export type ResourceType = {
path?: string;
handlers: IResource;
middlewares?: {
index?: NextFunction[];
show?: NextFunction[];
store?: NextFunction[];
update?: NextFunction[];
patch?: NextFunction[];
destroy?: NextFunction[];
};
parameters?: {
[prop: string]: string;
};
};
export type IRouter = IExpressRouter & {
getPath(): string;
getRouter: () => IExpressRouter;
listRoutes: () => { method: string; path: string }[];
group: (...args: GroupArgs) => IRouter;
resource: (ins: IResource | ResourceType) => IRouter;
};