koa-ts-core 0.0.23 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -1
- package/dist/global.d.ts +9 -0
- package/dist/index.cjs.js +8 -8
- package/dist/index.esm.js +8 -8
- package/dist/init/index.d.ts +3 -1
- package/dist/middleware/exception_middleware.d.ts +1 -3
- package/dist/middleware/logger_middleware.d.ts +6 -0
- package/dist/middleware/request_params_middleware.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,8 @@ const [app] = await initializeKoaApp({
|
|
|
29
29
|
) => void;
|
|
30
30
|
// 是否挂载log4到context
|
|
31
31
|
log4: TLog4;
|
|
32
|
+
// 是否挂载运行时日志
|
|
33
|
+
runtimeLog: boolean;
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
app.listen();
|
|
@@ -52,8 +54,16 @@ app.listen();
|
|
|
52
54
|
|
|
53
55
|
- log4 (TLog4) : 是否挂载 log4 到 context
|
|
54
56
|
|
|
57
|
+
- runtimeLog (boolean) : 是否挂载运行时日志
|
|
58
|
+
|
|
55
59
|
## 能力
|
|
56
60
|
|
|
61
|
+
### 内置部分中间件
|
|
62
|
+
|
|
63
|
+
#### 按优先级排序
|
|
64
|
+
|
|
65
|
+
全局错误处理 => AsyncLocalStorage 上下文中间件 => 请求日志 / 响应时间统计 => CORS / 安全相关 => 解析 body => 鉴权 => 路由
|
|
66
|
+
|
|
57
67
|
### 约定式路由
|
|
58
68
|
|
|
59
69
|
控制器注册路由,约定在`src/controller`目录下.ts 文件,使用`@Router`和`@AuthRouter`装饰器注册路由
|
|
@@ -156,7 +166,7 @@ export default Test;
|
|
|
156
166
|
|
|
157
167
|
#### 装饰器实现
|
|
158
168
|
|
|
159
|
-
`@Router`和`@AuthRouter
|
|
169
|
+
`@Router`和`@AuthRouter`装饰器实现是基于[@koa/router](https://www.npmjs.com/package/@koa/router)进行封装
|
|
160
170
|
|
|
161
171
|
ps:路由参数参考[path-to-regexp](https://github.com/pillarjs/path-to-regexp)
|
|
162
172
|
|
package/dist/global.d.ts
CHANGED
|
@@ -4,12 +4,21 @@ declare module "koa" {
|
|
|
4
4
|
interface DefaultContext {
|
|
5
5
|
// log4js
|
|
6
6
|
log4?: import("log4js").Log4js;
|
|
7
|
+
// hook
|
|
8
|
+
hook?: (ctx: Koa.Context, type: "request" | "response" | "error") => void;
|
|
9
|
+
// runtimeLog
|
|
10
|
+
runtimeLog: boolean;
|
|
7
11
|
// 验证过的参数
|
|
8
12
|
validated: {
|
|
9
13
|
params: Record<string, any>;
|
|
10
14
|
get: Record<string, any>;
|
|
11
15
|
post: Record<string, any>;
|
|
12
16
|
};
|
|
17
|
+
// 拓展字段
|
|
18
|
+
extra: {
|
|
19
|
+
get: Record<string, any>;
|
|
20
|
+
post: Record<string, any>;
|
|
21
|
+
};
|
|
13
22
|
}
|
|
14
23
|
}
|
|
15
24
|
|