-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdefine.ts
More file actions
82 lines (70 loc) · 2.27 KB
/
define.ts
File metadata and controls
82 lines (70 loc) · 2.27 KB
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
import type KoaRouter from '@koa/router';
import type Koa from 'koa';
import type { ConfigFile, RouterSchema, TeeKoa, TeeOptions } from './types';
interface DefineMiddlewareOptions {
needWrap?: boolean;
}
interface DefineMiddlewareNeedWrapOptions extends DefineMiddlewareOptions {
needWrap: true;
}
/**
* 定义一个中间件
*/
export function defineMiddleware<C extends (options: TeeOptions<'middleware'>) => (...args: any[]) => TeeKoa.Middleware>(callback: C, options: DefineMiddlewareNeedWrapOptions): C;
export function defineMiddleware<C extends (options: TeeOptions<'middleware'>) => TeeKoa.Middleware>(callback: C): C;
export function defineMiddleware<C extends (options: TeeOptions<'middleware'>) => (...args: any[]) => any>(callback: C, _options?: DefineMiddlewareOptions): C {
return callback;
}
/**
* 定义一个 config
*/
export function defineConfig<C extends (options: TeeOptions<'config'>) => Record<string, any>>(callback: C): C {
return callback;
}
/**
* 定义一个 router
*/
export function defineRouter<C extends (options: Required<TeeOptions<'router'>>) => void>(callback: C): C {
return callback;
}
export interface TeeContext extends KoaRouter.RouterContext<Koa.DefaultState, TeeKoa.Context> {}
/**
* 定义一个控制器
*/
export function defineController<C extends (options: TeeOptions<'controller'>) => new (...args: any) => any>(callback: C): C {
return callback;
}
/**
* 定义一个 service
*/
export function defineService<C extends (options: TeeOptions<'service'>) => new (...args: any) => any>(callback: C): C {
return callback;
}
/**
* 定义一个扩展
*/
export function defineExtend<C extends (options: TeeOptions<'extend'>) => any>(callback: C): C {
return callback;
}
/**
* 定义一个 routerSchema
*
* 可用于自动生成前端接口请求文件
*
* TODO: 生成 OpenAPI 规范的请求文档
*/
export function defineRouterSchema<C extends (options: TeeOptions<'routerSchema'>) => Record<string, RouterSchema>>(callback: C): C {
return callback;
}
/**
* 定义一个 tee 配置
*/
export function defineTeeConfig(config: ConfigFile): ConfigFile {
return config;
}
/**
* 定义一个入口
*/
export function defineEntry<C extends (app: TeeKoa.Application, router: KoaRouter) => void>(callback: C): C {
return callback;
}