@fastcar/koa 0.1.12 → 0.1.14

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.
Files changed (41) hide show
  1. package/index.d.ts +3 -0
  2. package/package.json +9 -9
  3. package/src/annotation.ts +0 -2
  4. package/src/index.ts +2 -2
  5. package/src/middleware/ExceptionGlobalHandler.ts +1 -1
  6. package/src/middleware/KoaBody.ts +3 -2
  7. package/src/middleware/KoaBodyParser.ts +2 -1
  8. package/src/middleware/KoaCors.ts +3 -2
  9. package/src/middleware/KoaMulter.ts +2 -1
  10. package/src/middleware/KoaStatic.ts +5 -3
  11. package/src/type/KoaConfig.ts +2 -5
  12. package/target/KoaApplication.js +147 -143
  13. package/target/annotation/EnableKoa.js +11 -11
  14. package/target/annotation/KoaMiddleware.js +19 -19
  15. package/target/annotation/router/AddMapping.js +29 -29
  16. package/target/annotation/router/AllMapping.js +14 -14
  17. package/target/annotation/router/DeleteMapping.js +14 -14
  18. package/target/annotation/router/GetMapping.js +14 -14
  19. package/target/annotation/router/PatchMapping.js +14 -14
  20. package/target/annotation/router/PostMapping.js +14 -14
  21. package/target/annotation/router/PutMapping.js +14 -14
  22. package/target/annotation/router/RequestMapping.js +22 -22
  23. package/target/annotation.js +38 -40
  24. package/target/index.js +19 -19
  25. package/target/middleware/ExceptionGlobalHandler.js +32 -32
  26. package/target/middleware/KoaBody.js +10 -10
  27. package/target/middleware/KoaBodyParser.js +10 -10
  28. package/target/middleware/KoaCors.js +33 -33
  29. package/target/middleware/KoaMulter.js +8 -8
  30. package/target/middleware/KoaStatic.js +38 -38
  31. package/target/type/DesignMeta.js +7 -7
  32. package/target/type/KoaConfig.js +2 -2
  33. package/target/type/MethodType.js +2 -2
  34. package/target/type/RouteMethods.js +12 -12
  35. package/test/logs/sys.log +78 -118
  36. package/test/simple/app.ts +4 -5
  37. package/src/middleware/Swagger.ts +0 -63
  38. package/target/middleware/Swagger.js +0 -53
  39. package/target/npmlist.json +0 -1
  40. package/test/logs/koa.log +0 -0
  41. package/test/logs/serverlogger.log +0 -3
package/index.d.ts CHANGED
@@ -60,4 +60,7 @@ export function KoaStatic(app: FastCarApplication): MiddleWareType;
60
60
  //支持api说明
61
61
  export function Swagger(app: FastCarApplication): MiddleWareType;
62
62
 
63
+ //增强multi文件解析
64
+ export function KoaMulter(app: FastCarApplication): MiddleWareType;
65
+
63
66
  export * from "./src/type/DesignMeta";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastcar/koa",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "homepage": "https://github.com/williamDazhangyu/fast-car",
5
5
  "description": "fastcar框架下对koa的包装",
6
6
  "main": "target/index.js",
@@ -30,17 +30,18 @@
30
30
  "node": ">=16"
31
31
  },
32
32
  "devDependencies": {
33
- "@fastcar/core": "^0.2.38",
33
+ "@fastcar/core": "0.3.1",
34
34
  "@fastcar/server": "^0.0.3",
35
35
  "@types/koa": "^2.13.5",
36
- "reflect-metadata": "^0.1.13",
37
36
  "@types/koa-bodyparser": "^4.3.11",
38
- "@types/koa-router": "^7.4.6"
37
+ "@types/koa-router": "^7.4.6",
38
+ "@types/koa__multer": "*",
39
+ "reflect-metadata": "*"
39
40
  },
40
41
  "dependencies": {
41
- "koa": "^2.13.1",
42
+ "koa": "^2.15.3",
42
43
  "koa-bodyparser": "^4.4.1",
43
- "koa-router": "^12.0.1"
44
+ "koa-router": "^13.0.1"
44
45
  },
45
46
  "peerDependencies": {
46
47
  "@fastcar/core": "*",
@@ -58,9 +59,8 @@
58
59
  "koa-range": "^0.3.0",
59
60
  "koa-static": "^5.0.0",
60
61
  "koa2-cors": "^2.0.6",
61
- "swagger-ui-dist": "4.5.0",
62
- "@types/koa__multer": "*",
63
- "multer": "*"
62
+ "multer": "*",
63
+ "swagger-ui-dist": "4.5.0"
64
64
  },
65
65
  "peerDependenciesMeta": {
66
66
  "@types/koa-bodyparser": {
package/src/annotation.ts CHANGED
@@ -8,7 +8,6 @@ import PatchMapping from "./annotation/router/PatchMapping";
8
8
  import PostMapping from "./annotation/router/PostMapping";
9
9
  import PutMapping from "./annotation/router/PutMapping";
10
10
  import RequestMapping from "./annotation/router/RequestMapping";
11
- import KoaMulter from "./middleware/KoaMulter";
12
11
 
13
12
  //声明简化的方式
14
13
  const GET = GetMapping;
@@ -41,5 +40,4 @@ export {
41
40
  PATCH,
42
41
  ALL,
43
42
  REQUEST,
44
- KoaMulter,
45
43
  };
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ import KoaBody from "./middleware/KoaBody";
5
5
  import KoaBodyParser from "./middleware/KoaBodyParser";
6
6
  import KoaCors from "./middleware/KoaCors";
7
7
  import KoaStatic from "./middleware/KoaStatic";
8
- import Swagger from "./middleware/Swagger";
9
8
  import { DesignMeta } from "./type/DesignMeta";
9
+ import KoaMulter from "./middleware/KoaMulter";
10
10
 
11
- export { KoaApplication, KoaConfig, ExceptionGlobalHandler, KoaBody, KoaBodyParser, KoaCors, KoaStatic, Swagger, DesignMeta };
11
+ export { KoaApplication, KoaConfig, ExceptionGlobalHandler, KoaBody, KoaBodyParser, KoaCors, KoaStatic, KoaMulter, DesignMeta };
@@ -2,7 +2,7 @@ import { FastCarApplication, ValidError } from "@fastcar/core";
2
2
 
3
3
  //默认错误捕捉
4
4
  export default function ExceptionGlobalHandler(app: FastCarApplication) {
5
- let logger = app.getSysLogger();
5
+ const logger = app.getSysLogger();
6
6
  return async (ctx: any, next: Function) => {
7
7
  try {
8
8
  await next();
@@ -1,11 +1,12 @@
1
- import * as koaBody from "koa-body";
2
1
  import { FastCarApplication } from "@fastcar/core";
3
2
  import { KoaConfig } from "../type/KoaConfig";
4
3
 
5
4
  //对于文件上传做限定
6
5
  export default function KoaBody(app: FastCarApplication) {
6
+ const koaBodyfn = require("koa-body").default;
7
+
7
8
  let koaConfig: KoaConfig = app.getSetting("koa");
8
9
  let bodyConfig = koaConfig?.koaBodyOptions;
9
10
 
10
- return koaBody(bodyConfig);
11
+ return koaBodyfn(bodyConfig);
11
12
  }
@@ -1,9 +1,10 @@
1
- import * as bodyParser from "koa-bodyparser";
2
1
  import { FastCarApplication } from "@fastcar/core";
3
2
  import { KoaConfig } from "../type/KoaConfig";
4
3
 
5
4
  //对文件内容做解析
6
5
  export default function KoaBodyParser(app: FastCarApplication) {
6
+ const bodyParser = require("koa-bodyparser");
7
+
7
8
  let koaConfig: KoaConfig = app.getSetting("koa");
8
9
  let bodyConfig = koaConfig?.koaBodyParser;
9
10
 
@@ -1,12 +1,13 @@
1
1
  import { FastCarApplication } from "@fastcar/core";
2
- import * as koa2Cors from "koa2-cors";
3
2
  import { KoaConfig } from "../type/KoaConfig";
4
3
  import { Context } from "koa";
5
4
 
6
5
  export default function KoaCors(app: FastCarApplication) {
6
+ const koa2Cors = require("koa2-cors");
7
+
7
8
  let koaConfig: KoaConfig = app.getSetting("koa");
8
9
  if (koaConfig?.extra) {
9
- let corsConfig: koa2Cors.Options = Reflect.get(koaConfig.extra, "cors");
10
+ let corsConfig = Reflect.get(koaConfig.extra, "cors");
10
11
  if (!!corsConfig) {
11
12
  //兼容支持多个跨域
12
13
  if (typeof corsConfig.origin == "string") {
@@ -1,7 +1,8 @@
1
- import * as multer from "@koa/multer";
2
1
  import { FastCarApplication } from "@fastcar/core";
3
2
 
4
3
  //对文件内容做解析
5
4
  export default function KoaMulter(app: FastCarApplication) {
5
+ const multer = require("@koa/multer");
6
+
6
7
  return multer().single();
7
8
  }
@@ -1,6 +1,3 @@
1
- import * as koaStatic from "koa-static";
2
- import * as KoaRange from "koa-range";
3
- import * as KoaMount from "koa-mount";
4
1
  import { FastCarApplication } from "@fastcar/core";
5
2
  import { KoaConfig } from "../type/KoaConfig";
6
3
  import * as fs from "fs";
@@ -9,6 +6,8 @@ import * as Koa from "koa";
9
6
 
10
7
  //支持静态文件访问
11
8
  export default function KoaStatic(app: FastCarApplication): Koa.Middleware[] {
9
+ const KoaRange = require("koa-range");
10
+
12
11
  let mlist: Koa.Middleware[] = [];
13
12
 
14
13
  //采用koa-range使文件可以流式传播
@@ -17,6 +16,9 @@ export default function KoaStatic(app: FastCarApplication): Koa.Middleware[] {
17
16
  let koaConfig: KoaConfig = app.getSetting("koa");
18
17
 
19
18
  if (!!koaConfig?.koaStatic) {
19
+ const KoaMount = require("koa-mount").default;
20
+ const koaStatic = require("koa-static").default;
21
+
20
22
  let keys = Object.keys(koaConfig?.koaStatic);
21
23
  if (keys.length > 0) {
22
24
  for (let key of keys) {
@@ -1,13 +1,10 @@
1
- import * as koaBody from "koa-body";
2
- import * as bodyParser from "koa-bodyparser";
3
1
  import { ServerConfig } from "@fastcar/server";
4
2
 
5
3
  //和koa的约定配置
6
4
  export type KoaConfig = {
7
5
  server: ServerConfig[] | ServerConfig; //监听的端口号
8
6
  koaStatic?: { [key: string]: string }; //相对路径为resource下的 或者绝对文件路径
9
- koaBodyOptions?: koaBody.IKoaBodyOptions; //文件上传的解析
10
- koaBodyParser?: bodyParser.Options; //解析请求
7
+ koaBodyOptions?: { [key: string]: any }; //文件上传的解析
8
+ koaBodyParser?: { [key: string]: any }; //bodyParser.Options; //解析请求
11
9
  extra?: { [key: string]: any }; //拓展设置
12
- swagger?: { enable: boolean; api: { [alias: string]: string } }; //别名:路径
13
10
  };
@@ -1,143 +1,147 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- require("reflect-metadata");
13
- const annotation_1 = require("@fastcar/core/annotation");
14
- const core_1 = require("@fastcar/core");
15
- const Koa = require("koa");
16
- const KoaRouter = require("koa-router");
17
- const DesignMeta_1 = require("./type/DesignMeta");
18
- const utils_1 = require("@fastcar/core/utils");
19
- const server_1 = require("@fastcar/server");
20
- /***
21
- * @version 1.0 koa基础组件启动
22
- *
23
- */
24
- let KoaApplication = class KoaApplication {
25
- constructor() {
26
- this.koaApp = new Koa();
27
- }
28
- /***
29
- * @version 1.0 加载中间件
30
- *
31
- */
32
- loadMiddleWare(list) {
33
- if (Array.isArray(list)) {
34
- list.forEach((item) => {
35
- if (utils_1.TypeUtil.isFunction(item)) {
36
- this.koaApp.use(item);
37
- }
38
- });
39
- }
40
- else {
41
- if (utils_1.TypeUtil.isFunction(list)) {
42
- this.koaApp.use(list);
43
- }
44
- }
45
- }
46
- /***
47
- * @version 1.0 加载路由
48
- *
49
- */
50
- loadRoute() {
51
- let router = new KoaRouter();
52
- let instanceList = this.app.getComponentByType(core_1.ComponentKind.Controller);
53
- //查找绑定的url
54
- instanceList.forEach((instance) => {
55
- let routerMap = Reflect.getMetadata(DesignMeta_1.DesignMeta.ROUTER_MAP, instance);
56
- //移除空的map结构
57
- if (!routerMap || routerMap.size == 0) {
58
- return;
59
- }
60
- routerMap.forEach((item) => {
61
- //去除ctx的影响
62
- let callBack = async (ctx, next) => {
63
- //进行参数的取值
64
- let body = {};
65
- //自动合并传参 如果有重合的部分 需要再次单独取就好了
66
- if (Object.keys(ctx.query).length > 0) {
67
- Object.assign(body, ctx.query);
68
- }
69
- if (!!ctx.request.body) {
70
- Object.assign(body, ctx.request.body);
71
- }
72
- if (!!ctx.params) {
73
- Object.assign(body, ctx.params);
74
- }
75
- let res = await instance[item.method](body, ctx);
76
- if (utils_1.ValidationUtil.isNotNull(res)) {
77
- ctx.body = res;
78
- }
79
- if (next) {
80
- await next();
81
- }
82
- };
83
- for (let r of item.request) {
84
- //进行绑定 加载router路由的执行方法
85
- Reflect.apply(router[`${r}`], router, [item.url, callBack]);
86
- }
87
- });
88
- });
89
- return router.routes();
90
- }
91
- start() {
92
- const koaApp = this.koaApp;
93
- //加载中间件
94
- let middlewareList = this.app.getSetting(DesignMeta_1.DesignMeta.KoaMIDDLEWARE);
95
- if (Array.isArray(middlewareList)) {
96
- for (let m of middlewareList) {
97
- if (utils_1.TypeUtil.isPromise(m)) {
98
- Reflect.apply(m, this, [this.app, koaApp]).then((tmpList) => {
99
- this.loadMiddleWare(tmpList);
100
- });
101
- }
102
- else {
103
- let tmpList = Reflect.apply(m, this, [this.app, koaApp]);
104
- this.loadMiddleWare(tmpList);
105
- }
106
- }
107
- }
108
- //加载路由
109
- koaApp.use(this.loadRoute());
110
- //读取配置文件 创建服务器
111
- let appCallback = koaApp.callback();
112
- let koaConfig = this.app.getSetting("koa");
113
- if (!!koaConfig.server) {
114
- if (Array.isArray(koaConfig.server)) {
115
- koaConfig.server.forEach((server) => {
116
- this.serverApplication.createServer(server, appCallback);
117
- });
118
- }
119
- else {
120
- this.serverApplication.createServer(koaConfig.server, appCallback);
121
- }
122
- }
123
- }
124
- async stop() { }
125
- };
126
- __decorate([
127
- annotation_1.Autowired,
128
- __metadata("design:type", core_1.FastCarApplication)
129
- ], KoaApplication.prototype, "app", void 0);
130
- __decorate([
131
- (0, annotation_1.Log)("koa"),
132
- __metadata("design:type", core_1.Logger)
133
- ], KoaApplication.prototype, "koaLogger", void 0);
134
- __decorate([
135
- annotation_1.Autowired,
136
- __metadata("design:type", server_1.ServerApplication)
137
- ], KoaApplication.prototype, "serverApplication", void 0);
138
- KoaApplication = __decorate([
139
- (0, annotation_1.ApplicationStart)(core_1.BootPriority.Lowest, "start"),
140
- (0, annotation_1.ApplicationStop)(core_1.BootPriority.Base, "stop"),
141
- __metadata("design:paramtypes", [])
142
- ], KoaApplication);
143
- exports.default = KoaApplication;
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ require("reflect-metadata");
13
+ const annotation_1 = require("@fastcar/core/annotation");
14
+ const core_1 = require("@fastcar/core");
15
+ const Koa = require("koa");
16
+ const KoaRouter = require("koa-router");
17
+ const DesignMeta_1 = require("./type/DesignMeta");
18
+ const utils_1 = require("@fastcar/core/utils");
19
+ const server_1 = require("@fastcar/server");
20
+ /***
21
+ * @version 1.0 koa基础组件启动
22
+ *
23
+ */
24
+ let KoaApplication = class KoaApplication {
25
+ app;
26
+ koaLogger;
27
+ koaApp;
28
+ serverApplication;
29
+ constructor() {
30
+ this.koaApp = new Koa();
31
+ }
32
+ /***
33
+ * @version 1.0 加载中间件
34
+ *
35
+ */
36
+ loadMiddleWare(list) {
37
+ if (Array.isArray(list)) {
38
+ list.forEach((item) => {
39
+ if (utils_1.TypeUtil.isFunction(item)) {
40
+ this.koaApp.use(item);
41
+ }
42
+ });
43
+ }
44
+ else {
45
+ if (utils_1.TypeUtil.isFunction(list)) {
46
+ this.koaApp.use(list);
47
+ }
48
+ }
49
+ }
50
+ /***
51
+ * @version 1.0 加载路由
52
+ *
53
+ */
54
+ loadRoute() {
55
+ let router = new KoaRouter();
56
+ let instanceList = this.app.getComponentByType(core_1.ComponentKind.Controller);
57
+ //查找绑定的url
58
+ instanceList.forEach((instance) => {
59
+ let routerMap = Reflect.getMetadata(DesignMeta_1.DesignMeta.ROUTER_MAP, instance);
60
+ //移除空的map结构
61
+ if (!routerMap || routerMap.size == 0) {
62
+ return;
63
+ }
64
+ routerMap.forEach((item) => {
65
+ //去除ctx的影响
66
+ let callBack = async (ctx, next) => {
67
+ //进行参数的取值
68
+ let body = {};
69
+ //自动合并传参 如果有重合的部分 需要再次单独取就好了
70
+ if (Object.keys(ctx.query).length > 0) {
71
+ Object.assign(body, ctx.query);
72
+ }
73
+ if (!!ctx.request.body) {
74
+ Object.assign(body, ctx.request.body);
75
+ }
76
+ if (!!ctx.params) {
77
+ Object.assign(body, ctx.params);
78
+ }
79
+ let res = await instance[item.method](body, ctx);
80
+ if (utils_1.ValidationUtil.isNotNull(res)) {
81
+ ctx.body = res;
82
+ }
83
+ if (next) {
84
+ await next();
85
+ }
86
+ };
87
+ for (let r of item.request) {
88
+ //进行绑定 加载router路由的执行方法
89
+ Reflect.apply(router[`${r}`], router, [item.url, callBack]);
90
+ }
91
+ });
92
+ });
93
+ return router.routes();
94
+ }
95
+ start() {
96
+ const koaApp = this.koaApp;
97
+ //加载中间件
98
+ let middlewareList = this.app.getSetting(DesignMeta_1.DesignMeta.KoaMIDDLEWARE);
99
+ if (Array.isArray(middlewareList)) {
100
+ for (let m of middlewareList) {
101
+ if (utils_1.TypeUtil.isPromise(m)) {
102
+ Reflect.apply(m, this, [this.app, koaApp]).then((tmpList) => {
103
+ this.loadMiddleWare(tmpList);
104
+ });
105
+ }
106
+ else {
107
+ let tmpList = Reflect.apply(m, this, [this.app, koaApp]);
108
+ this.loadMiddleWare(tmpList);
109
+ }
110
+ }
111
+ }
112
+ //加载路由
113
+ koaApp.use(this.loadRoute());
114
+ //读取配置文件 创建服务器
115
+ let appCallback = koaApp.callback();
116
+ let koaConfig = this.app.getSetting("koa");
117
+ if (!!koaConfig.server) {
118
+ if (Array.isArray(koaConfig.server)) {
119
+ koaConfig.server.forEach((server) => {
120
+ this.serverApplication.createServer(server, appCallback);
121
+ });
122
+ }
123
+ else {
124
+ this.serverApplication.createServer(koaConfig.server, appCallback);
125
+ }
126
+ }
127
+ }
128
+ async stop() { }
129
+ };
130
+ __decorate([
131
+ annotation_1.Autowired,
132
+ __metadata("design:type", core_1.FastCarApplication)
133
+ ], KoaApplication.prototype, "app", void 0);
134
+ __decorate([
135
+ (0, annotation_1.Log)("koa"),
136
+ __metadata("design:type", core_1.Logger)
137
+ ], KoaApplication.prototype, "koaLogger", void 0);
138
+ __decorate([
139
+ annotation_1.Autowired,
140
+ __metadata("design:type", server_1.ServerApplication)
141
+ ], KoaApplication.prototype, "serverApplication", void 0);
142
+ KoaApplication = __decorate([
143
+ (0, annotation_1.ApplicationStart)(core_1.BootPriority.Lowest, "start"),
144
+ (0, annotation_1.ApplicationStop)(core_1.BootPriority.Base, "stop"),
145
+ __metadata("design:paramtypes", [])
146
+ ], KoaApplication);
147
+ exports.default = KoaApplication;
@@ -1,11 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const annotation_1 = require("@fastcar/core/annotation");
4
- const server_1 = require("@fastcar/server");
5
- //开启koa应用
6
- function EnableKoa(target) {
7
- let fp = require.resolve("../KoaApplication");
8
- (0, annotation_1.ComponentInjection)(target, fp);
9
- (0, server_1.EnableServer)(target);
10
- }
11
- exports.default = EnableKoa;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = EnableKoa;
4
+ const annotation_1 = require("@fastcar/core/annotation");
5
+ const server_1 = require("@fastcar/server");
6
+ //开启koa应用
7
+ function EnableKoa(target) {
8
+ let fp = require.resolve("../KoaApplication");
9
+ (0, annotation_1.ComponentInjection)(target, fp);
10
+ (0, server_1.EnableServer)(target);
11
+ }
@@ -1,19 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- require("reflect-metadata");
4
- const DesignMeta_1 = require("../type/DesignMeta");
5
- //加载koa中间件
6
- function KoaMiddleware(...args) {
7
- return function (target) {
8
- let middlewareList = Reflect.get(target.prototype, DesignMeta_1.DesignMeta.KoaMIDDLEWARE);
9
- if (!middlewareList) {
10
- middlewareList = args;
11
- }
12
- else {
13
- //由于注解方式是从下至上运行 和我们理解的书写习惯不一样,所以这边做了一个反序
14
- middlewareList = [...args, ...middlewareList];
15
- }
16
- Reflect.set(target.prototype, DesignMeta_1.DesignMeta.KoaMIDDLEWARE, middlewareList);
17
- };
18
- }
19
- exports.default = KoaMiddleware;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = KoaMiddleware;
4
+ require("reflect-metadata");
5
+ const DesignMeta_1 = require("../type/DesignMeta");
6
+ //加载koa中间件
7
+ function KoaMiddleware(...args) {
8
+ return function (target) {
9
+ let middlewareList = Reflect.get(target.prototype, DesignMeta_1.DesignMeta.KoaMIDDLEWARE);
10
+ if (!middlewareList) {
11
+ middlewareList = args;
12
+ }
13
+ else {
14
+ //由于注解方式是从下至上运行 和我们理解的书写习惯不一样,所以这边做了一个反序
15
+ middlewareList = [...args, ...middlewareList];
16
+ }
17
+ Reflect.set(target.prototype, DesignMeta_1.DesignMeta.KoaMIDDLEWARE, middlewareList);
18
+ };
19
+ }
@@ -1,29 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- require("reflect-metadata");
4
- const DesignMeta_1 = require("../../type/DesignMeta");
5
- function AddMapping(target, info) {
6
- if (!info.url) {
7
- info.url = info.method;
8
- }
9
- //格式化url 以/开头
10
- if (!info.url.startsWith("/")) {
11
- info.url = "/" + info.url;
12
- }
13
- let routerMap = Reflect.getMetadata(DesignMeta_1.DesignMeta.ROUTER_MAP, target);
14
- if (!routerMap) {
15
- routerMap = new Map();
16
- Reflect.defineMetadata(DesignMeta_1.DesignMeta.ROUTER_MAP, routerMap, target);
17
- }
18
- let curr = routerMap.get(info.url);
19
- if (!curr) {
20
- routerMap.set(info.url, info);
21
- }
22
- else {
23
- if (info.url != curr.url) {
24
- console.warn(`The two URL names are inconsisten in (${info.url},${curr.url})`);
25
- }
26
- curr.request = [...info.request, ...curr.request];
27
- }
28
- }
29
- exports.default = AddMapping;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = AddMapping;
4
+ require("reflect-metadata");
5
+ const DesignMeta_1 = require("../../type/DesignMeta");
6
+ function AddMapping(target, info) {
7
+ if (!info.url) {
8
+ info.url = info.method;
9
+ }
10
+ //格式化url 以/开头
11
+ if (!info.url.startsWith("/")) {
12
+ info.url = "/" + info.url;
13
+ }
14
+ let routerMap = Reflect.getMetadata(DesignMeta_1.DesignMeta.ROUTER_MAP, target);
15
+ if (!routerMap) {
16
+ routerMap = new Map();
17
+ Reflect.defineMetadata(DesignMeta_1.DesignMeta.ROUTER_MAP, routerMap, target);
18
+ }
19
+ let curr = routerMap.get(info.url);
20
+ if (!curr) {
21
+ routerMap.set(info.url, info);
22
+ }
23
+ else {
24
+ if (info.url != curr.url) {
25
+ console.warn(`The two URL names are inconsisten in (${info.url},${curr.url})`);
26
+ }
27
+ curr.request = [...info.request, ...curr.request];
28
+ }
29
+ }
@@ -1,14 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const RouteMethods_1 = require("../../type/RouteMethods");
4
- const AddMapping_1 = require("./AddMapping");
5
- function AllMapping(url) {
6
- return function (target, name, descriptor) {
7
- (0, AddMapping_1.default)(target, {
8
- url,
9
- method: name,
10
- request: [RouteMethods_1.RouteMethods.AllMapping],
11
- });
12
- };
13
- }
14
- exports.default = AllMapping;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = AllMapping;
4
+ const RouteMethods_1 = require("../../type/RouteMethods");
5
+ const AddMapping_1 = require("./AddMapping");
6
+ function AllMapping(url) {
7
+ return function (target, name, descriptor) {
8
+ (0, AddMapping_1.default)(target, {
9
+ url,
10
+ method: name,
11
+ request: [RouteMethods_1.RouteMethods.AllMapping],
12
+ });
13
+ };
14
+ }