-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
64 lines (54 loc) · 1.61 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
import * as Koa from 'koa';
declare namespace Router {
export type RouteHandle = Middleware | RouteFragment | Router;
export type RouteLookup = Middleware | undefined;
export type RouteParams = Record<string, string | undefined>;
export type Context = Koa.ParameterizedContext<
Koa.DefaultState,
RouterContext & Koa.DefaultContext
>;
export type Middleware = Koa.Middleware<
Koa.DefaultState,
RouterContext & Koa.DefaultContext
>;
export type RoutingOptions = {
prefix?: string;
caseSensitive?: boolean;
strict?: boolean;
};
export type RouterContext = {
params: RouteParams;
};
export interface RegisterHandle {
(...middleware: RouteHandle[]): Router;
(path: string, ...middlewares: RouteHandle[]): Router;
}
export { RouteFragment as Fragment };
}
declare class RouteFragment {
readonly type: number;
readonly chain: unknown[];
readonly prefix: string;
readonly caseSensitive: boolean;
readonly strict: boolean;
constructor(options?: Router.RoutingOptions);
add(method: string, ...args: Parameters<Router.RegisterHandle>): this;
use: Router.RegisterHandle;
all: Router.RegisterHandle;
get: Router.RegisterHandle;
post: Router.RegisterHandle;
patch: Router.RegisterHandle;
put: Router.RegisterHandle;
delete: Router.RegisterHandle;
del: Router.RegisterHandle;
}
declare class Router extends RouteFragment {
lookup(
method: string,
path: string,
params?: Router.RouteParams,
): Router.RouteLookup;
handle(ctx: Koa.ParameterizedContext, next: Koa.Next): ReturnType<Koa.Next>;
routes(): Router.Middleware;
}
export = Router;