@tsed/platform-koa 7.0.0-beta.1 → 7.0.0-beta.4

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 (71) hide show
  1. package/lib/cjs/components/PlatformKoa.js +76 -20
  2. package/lib/cjs/components/PlatformKoa.js.map +1 -1
  3. package/lib/cjs/exports.js +7 -0
  4. package/lib/cjs/exports.js.map +1 -0
  5. package/lib/cjs/index.js +18 -12
  6. package/lib/cjs/index.js.map +1 -1
  7. package/lib/cjs/interfaces/PlatformKoaSettings.js.map +1 -1
  8. package/lib/cjs/interfaces/{index.js → interfaces.js} +2 -2
  9. package/lib/cjs/interfaces/interfaces.js.map +1 -0
  10. package/lib/cjs/middlewares/resourceNotFoundMiddleware.js +2 -2
  11. package/lib/cjs/middlewares/resourceNotFoundMiddleware.js.map +1 -1
  12. package/lib/cjs/middlewares/staticsMiddleware.js +1 -1
  13. package/lib/cjs/middlewares/staticsMiddleware.js.map +1 -1
  14. package/lib/cjs/package.json +3 -0
  15. package/lib/cjs/services/PlatformKoaRequest.js +7 -7
  16. package/lib/cjs/services/PlatformKoaRequest.js.map +1 -1
  17. package/lib/cjs/services/PlatformKoaResponse.js +4 -4
  18. package/lib/cjs/services/PlatformKoaResponse.js.map +1 -1
  19. package/lib/cjs/utils/multer.js +26 -1
  20. package/lib/cjs/utils/multer.js.map +1 -1
  21. package/lib/esm/components/PlatformKoa.js +73 -18
  22. package/lib/esm/components/PlatformKoa.js.map +1 -1
  23. package/lib/esm/decorators/caseSensitive.js +1 -1
  24. package/lib/esm/decorators/strict.js +1 -1
  25. package/lib/esm/exports.js +5 -0
  26. package/lib/esm/exports.js.map +1 -0
  27. package/lib/esm/index.js +18 -12
  28. package/lib/esm/index.js.map +1 -1
  29. package/lib/esm/interfaces/PlatformKoaSettings.js.map +1 -1
  30. package/lib/esm/interfaces/interfaces.js +2 -0
  31. package/lib/esm/interfaces/interfaces.js.map +1 -0
  32. package/lib/esm/middlewares/resourceNotFoundMiddleware.js +1 -1
  33. package/lib/esm/middlewares/resourceNotFoundMiddleware.js.map +1 -1
  34. package/lib/esm/package.json +3 -0
  35. package/lib/esm/services/PlatformKoaHandler.js +1 -1
  36. package/lib/esm/services/PlatformKoaResponse.js +1 -1
  37. package/lib/esm/services/PlatformKoaResponse.js.map +1 -1
  38. package/lib/esm/utils/multer.js +3 -1
  39. package/lib/esm/utils/multer.js.map +1 -1
  40. package/lib/types/components/PlatformKoa.d.ts +35 -13
  41. package/lib/types/exports.d.ts +1 -0
  42. package/lib/types/index.d.ts +17 -3
  43. package/lib/types/interfaces/PlatformKoaSettings.d.ts +10 -3
  44. package/lib/types/interfaces/{index.d.ts → interfaces.d.ts} +0 -0
  45. package/lib/types/services/PlatformKoaResponse.d.ts +1 -1
  46. package/package.json +51 -26
  47. package/readme.md +0 -2
  48. package/tsconfig.compile.esm.json +1 -12
  49. package/lib/cjs/decorators/index.js +0 -9
  50. package/lib/cjs/decorators/index.js.map +0 -1
  51. package/lib/cjs/interfaces/index.js.map +0 -1
  52. package/lib/cjs/services/PlatformKoaApplication.js +0 -32
  53. package/lib/cjs/services/PlatformKoaApplication.js.map +0 -1
  54. package/lib/cjs/services/PlatformKoaRouter.js +0 -45
  55. package/lib/cjs/services/PlatformKoaRouter.js.map +0 -1
  56. package/lib/cjs/services/index.js +0 -9
  57. package/lib/cjs/services/index.js.map +0 -1
  58. package/lib/esm/decorators/index.js +0 -6
  59. package/lib/esm/decorators/index.js.map +0 -1
  60. package/lib/esm/interfaces/index.js +0 -2
  61. package/lib/esm/interfaces/index.js.map +0 -1
  62. package/lib/esm/services/PlatformKoaApplication.js +0 -29
  63. package/lib/esm/services/PlatformKoaApplication.js.map +0 -1
  64. package/lib/esm/services/PlatformKoaRouter.js +0 -42
  65. package/lib/esm/services/PlatformKoaRouter.js.map +0 -1
  66. package/lib/esm/services/index.js +0 -6
  67. package/lib/esm/services/index.js.map +0 -1
  68. package/lib/types/decorators/index.d.ts +0 -5
  69. package/lib/types/services/PlatformKoaApplication.d.ts +0 -22
  70. package/lib/types/services/PlatformKoaRouter.d.ts +0 -22
  71. package/lib/types/services/index.d.ts +0 -5
@@ -1,36 +1,51 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlatformKoa = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const router_1 = tslib_1.__importDefault(require("@koa/router"));
4
6
  const common_1 = require("@tsed/common");
7
+ const platform_exceptions_1 = require("@tsed/platform-exceptions");
8
+ const core_1 = require("@tsed/core");
9
+ const koa_1 = tslib_1.__importDefault(require("koa"));
5
10
  const resourceNotFoundMiddleware_1 = require("../middlewares/resourceNotFoundMiddleware");
6
- const services_1 = require("../services");
11
+ const PlatformKoaResponse_1 = require("../services/PlatformKoaResponse");
12
+ const PlatformKoaRequest_1 = require("../services/PlatformKoaRequest");
13
+ const PlatformKoaHandler_1 = require("../services/PlatformKoaHandler");
14
+ const multer_1 = require("../utils/multer");
15
+ const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
16
+ // @ts-ignore
17
+ const koa_qs_1 = tslib_1.__importDefault(require("koa-qs"));
18
+ const koa_bodyparser_1 = tslib_1.__importDefault(require("koa-bodyparser"));
19
+ // @ts-ignore
20
+ router_1.default.prototype.$$match = router_1.default.prototype.match;
21
+ router_1.default.prototype.match = function match(...args) {
22
+ const matched = this.$$match(...args);
23
+ if (matched) {
24
+ if (matched.path.length) {
25
+ matched.route = true;
26
+ }
27
+ }
28
+ return matched;
29
+ };
7
30
  /**
8
31
  * @platform
9
32
  * @koa
10
33
  */
11
34
  class PlatformKoa {
12
- constructor(platform) {
13
- this.platform = platform;
35
+ constructor(injector) {
36
+ this.injector = injector;
14
37
  this.providers = [
15
38
  {
16
39
  provide: common_1.PlatformResponse,
17
- useClass: services_1.PlatformKoaResponse
40
+ useClass: PlatformKoaResponse_1.PlatformKoaResponse
18
41
  },
19
42
  {
20
43
  provide: common_1.PlatformRequest,
21
- useClass: services_1.PlatformKoaRequest
44
+ useClass: PlatformKoaRequest_1.PlatformKoaRequest
22
45
  },
23
46
  {
24
47
  provide: common_1.PlatformHandler,
25
- useClass: services_1.PlatformKoaHandler
26
- },
27
- {
28
- provide: common_1.PlatformRouter,
29
- useClass: services_1.PlatformKoaRouter
30
- },
31
- {
32
- provide: common_1.PlatformApplication,
33
- useClass: services_1.PlatformKoaApplication
48
+ useClass: PlatformKoaHandler_1.PlatformKoaHandler
34
49
  }
35
50
  ];
36
51
  }
@@ -57,23 +72,26 @@ class PlatformKoa {
57
72
  });
58
73
  }
59
74
  onInit() {
60
- const { injector, app } = this.platform;
75
+ const injector = this.injector;
76
+ const app = this.injector.get(common_1.PlatformApplication);
61
77
  const listener = (error, ctx) => {
62
78
  var _a;
63
- (_a = injector.get(common_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(error, ctx.request.$ctx);
79
+ (_a = injector.get(platform_exceptions_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(error, ctx.request.$ctx);
64
80
  };
65
81
  app.getApp().silent = true;
66
82
  app.getApp().on("error", listener);
67
83
  }
68
84
  useRouter() {
69
- const { app } = this.platform;
70
- app.getApp().use(resourceNotFoundMiddleware_1.resourceNotFoundMiddleware).use(app.getRouter().routes()).use(app.getRouter().allowedMethods());
85
+ const app = this.injector.get(common_1.PlatformApplication);
86
+ app.getApp().use(resourceNotFoundMiddleware_1.resourceNotFoundMiddleware);
87
+ app.getApp().use(app.getRouter().routes()).use(app.getRouter().allowedMethods());
71
88
  return this;
72
89
  }
73
90
  useContext() {
74
- const { injector, app, logger } = this.platform;
91
+ const app = this.injector.get(common_1.PlatformApplication);
92
+ const { logger } = this.injector;
75
93
  logger.info("Mount app context");
76
- const invoke = (0, common_1.createContext)(injector);
94
+ const invoke = (0, common_1.createContext)(this.injector);
77
95
  app.getApp().use(async (ctx, next) => {
78
96
  await invoke({
79
97
  request: ctx.request,
@@ -84,6 +102,44 @@ class PlatformKoa {
84
102
  });
85
103
  return this;
86
104
  }
105
+ app() {
106
+ const app = this.injector.settings.get("koa.app") || new koa_1.default();
107
+ (0, koa_qs_1.default)(app, "extended");
108
+ return {
109
+ app,
110
+ callback() {
111
+ return app.callback();
112
+ }
113
+ };
114
+ }
115
+ router(routerOptions = {}) {
116
+ var _a;
117
+ const { settings } = this.injector;
118
+ const options = Object.assign({}, ((_a = settings.koa) === null || _a === void 0 ? void 0 : _a.router) || {}, routerOptions);
119
+ const router = new router_1.default(options);
120
+ return {
121
+ router,
122
+ callback() {
123
+ return [router.routes(), router.allowedMethods()];
124
+ }
125
+ };
126
+ }
127
+ multipart(options) {
128
+ return (0, multer_1.getMulter)(options);
129
+ }
130
+ statics(endpoint, options) {
131
+ return (0, staticsMiddleware_1.staticsMiddleware)(options);
132
+ }
133
+ bodyParser(type, additionalOptions = {}) {
134
+ const opts = this.injector.settings.get(`koa.bodyParser`);
135
+ let parser = koa_bodyparser_1.default;
136
+ let options = {};
137
+ if ((0, core_1.isFunction)(opts)) {
138
+ parser = opts;
139
+ options = {};
140
+ }
141
+ return parser({ ...options, ...additionalOptions });
142
+ }
87
143
  }
88
144
  exports.PlatformKoa = PlatformKoa;
89
145
  //# sourceMappingURL=PlatformKoa.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;AACA,yCAUsB;AAGtB,0FAAqF;AACrF,0CAAmI;AAEnI;;;GAGG;AACH,MAAa,WAAW;IAwBtB,YAAoB,QAAyC;QAAzC,aAAQ,GAAR,QAAQ,CAAiC;QAvBpD,cAAS,GAAG;YACnB;gBACE,OAAO,EAAE,yBAAgB;gBACzB,QAAQ,EAAE,8BAAmB;aAC9B;YACD;gBACE,OAAO,EAAE,wBAAe;gBACxB,QAAQ,EAAE,6BAAkB;aAC7B;YACD;gBACE,OAAO,EAAE,wBAAe;gBACxB,QAAQ,EAAE,6BAAkB;aAC7B;YACD;gBACE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AAE,CAAC,cAAc,EAAE,CAAC,CAAC;QAEjH,OAAO,IAAI,CAAC;IACd,CAAC;IAED,UAAU;QACR,MAAM,EAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9C,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAEjC,MAAM,MAAM,GAAG,IAAA,sBAAa,EAAC,QAAQ,CAAC,CAAC;QAEvC,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,GAAY,EAAE,IAAU,EAAE,EAAE;YAClD,MAAM,MAAM,CAAC;gBACX,OAAO,EAAE,GAAG,CAAC,OAAc;gBAC3B,QAAQ,EAAE,GAAG,CAAC,QAAe;gBAC7B,GAAG;aACJ,CAAC,CAAC;YAEH,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAtFD,kCAsFC","sourcesContent":["import KoaRouter from \"@koa/router\";\nimport {\n createContext,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformExceptions,\n PlatformHandler,\n PlatformRequest,\n PlatformResponse,\n PlatformRouter\n} from \"@tsed/common\";\nimport {Type} from \"@tsed/core\";\nimport Koa, {Context, Next} from \"koa\";\nimport {resourceNotFoundMiddleware} from \"../middlewares/resourceNotFoundMiddleware\";\nimport {PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, PlatformKoaResponse, PlatformKoaRouter} from \"../services\";\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {\n readonly providers = [\n {\n provide: PlatformResponse,\n useClass: PlatformKoaResponse\n },\n {\n provide: PlatformRequest,\n useClass: PlatformKoaRequest\n },\n {\n provide: PlatformHandler,\n useClass: PlatformKoaHandler\n },\n {\n provide: PlatformRouter,\n useClass: PlatformKoaRouter\n },\n {\n provide: PlatformApplication,\n useClass: PlatformKoaApplication\n }\n ];\n\n constructor(private platform: PlatformBuilder<Koa, KoaRouter>) {}\n\n /**\n * Create new serverless application. In this mode, the component scan are disabled.\n * @param module\n * @param settings\n */\n static create(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.create<Koa, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.bootstrap<Koa, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n onInit() {\n const {injector, app} = this.platform;\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, ctx.request.$ctx);\n };\n\n app.getApp().silent = true;\n app.getApp().on(\"error\", listener);\n }\n\n useRouter(): this {\n const {app} = this.platform;\n app.getApp().use(resourceNotFoundMiddleware).use(app.getRouter().routes()).use(app.getRouter().allowedMethods());\n\n return this;\n }\n\n useContext(): this {\n const {injector, app, logger} = this.platform;\n logger.info(\"Mount app context\");\n\n const invoke = createContext(injector);\n\n app.getApp().use(async (ctx: Context, next: Next) => {\n await invoke({\n request: ctx.request as any,\n response: ctx.response as any,\n ctx\n });\n\n return next();\n });\n\n return this;\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;;AAAA,iEAAyE;AACzE,yCAYsB;AACtB,mEAA6D;AAC7D,qCAA4C;AAC5C,sDAAuC;AACvC,0FAAqF;AACrF,yEAAoE;AACpE,uEAAkE;AAClE,uEAAkE;AAClE,4CAA0C;AAC1C,wEAAmE;AAEnE,aAAa;AACb,4DAA2B;AAC3B,4EAAsD;AAgBtD,aAAa;AACb,gBAAS,CAAC,SAAS,CAAC,OAAO,GAAG,gBAAS,CAAC,SAAS,CAAC,KAAK,CAAC;AACxD,gBAA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I,CAAC,EAAE;YACpB,MAAM,GAAG,IAAI,CAAC;YACd,OAAO,GAAG,EAAE,CAAC;SACd;QAED,OAAO,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,GAAG,iBAAiB,EAAC,CAAC,CAAC;IACpD,CAAC;CACF;AAlID,kCAkIC","sourcesContent":["import KoaRouter, {RouterOptions as KoaRouterOptions} from \"@koa/router\";\nimport {\n createContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {PlatformExceptions} from \"@tsed/platform-exceptions\";\nimport {isFunction, Type} from \"@tsed/core\";\nimport Koa, {Context, Next} from \"koa\";\nimport {resourceNotFoundMiddleware} from \"../middlewares/resourceNotFoundMiddleware\";\nimport {PlatformKoaResponse} from \"../services/PlatformKoaResponse\";\nimport {PlatformKoaRequest} from \"../services/PlatformKoaRequest\";\nimport {PlatformKoaHandler} from \"../services/PlatformKoaHandler\";\nimport {getMulter} from \"../utils/multer\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport send from \"koa-send\";\n// @ts-ignore\nimport koaQs from \"koa-qs\";\nimport koaBodyParser, {Options} from \"koa-bodyparser\";\n\ndeclare global {\n namespace TsED {\n export interface Application extends Koa {}\n }\n\n namespace TsED {\n export interface Router extends KoaRouter {}\n\n export interface RouterOptions extends KoaRouterOptions {}\n\n export interface StaticsOptions extends send.SendOptions {}\n }\n}\n\n// @ts-ignore\nKoaRouter.prototype.$$match = KoaRouter.prototype.match;\nKoaRouter.prototype.match = function match(...args: any[]) {\n const matched = this.$$match(...args);\n if (matched) {\n if (matched.path.length) {\n matched.route = true;\n }\n }\n\n return matched;\n};\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {\n readonly providers = [\n {\n provide: PlatformResponse,\n useClass: PlatformKoaResponse\n },\n {\n provide: PlatformRequest,\n useClass: PlatformKoaRequest\n },\n {\n provide: PlatformHandler,\n useClass: PlatformKoaHandler\n }\n ];\n\n constructor(private injector: InjectorService) {}\n\n /**\n * Create new serverless application. In this mode, the component scan are disabled.\n * @param module\n * @param settings\n */\n static create(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.create<Koa, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.bootstrap<Koa, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n onInit() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication>(PlatformApplication)!;\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, ctx.request.$ctx);\n };\n\n app.getApp().silent = true;\n app.getApp().on(\"error\", listener);\n }\n\n useRouter(): this {\n const app = this.injector.get<PlatformApplication<Koa>>(PlatformApplication)!;\n\n app.getApp().use(resourceNotFoundMiddleware);\n app.getApp().use(app.getRouter().routes()).use(app.getRouter().allowedMethods());\n\n return this;\n }\n\n useContext(): this {\n const app = this.injector.get<PlatformApplication<Koa>>(PlatformApplication)!;\n const {logger} = this.injector;\n logger.info(\"Mount app context\");\n\n const invoke = createContext(this.injector);\n\n app.getApp().use(async (ctx: Context, next: Next) => {\n await invoke({\n request: ctx.request as any,\n response: ctx.response as any,\n ctx\n });\n\n return next();\n });\n\n return this;\n }\n\n app() {\n const app = this.injector.settings.get(\"koa.app\") || new Koa();\n koaQs(app, \"extended\");\n\n return {\n app,\n callback() {\n return app.callback();\n }\n };\n }\n\n router(routerOptions: any = {}) {\n const {settings} = this.injector;\n\n const options = Object.assign({}, settings.koa?.router || {}, routerOptions);\n const router = new KoaRouter(options) as any;\n\n return {\n router,\n callback() {\n return [router.routes(), router.allowedMethods()];\n }\n };\n }\n\n multipart(options: PlatformMulterSettings): PlatformMulter {\n return getMulter(options);\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n return staticsMiddleware(options);\n }\n\n bodyParser(type: \"json\" | \"urlencoded\" | \"raw\" | \"text\", additionalOptions: any = {}): any {\n const opts = this.injector.settings.get(`koa.bodyParser`);\n let parser: any = koaBodyParser;\n\n let options: Options = {};\n\n if (isFunction(opts)) {\n parser = opts;\n options = {};\n }\n\n return parser({...options, ...additionalOptions});\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const common_1 = require("@tsed/common");
4
+ const PlatformKoa_1 = require("./components/PlatformKoa");
5
+ common_1.PlatformTest.adapter = PlatformKoa_1.PlatformKoa;
6
+ common_1.PlatformBuilder.adapter = PlatformKoa_1.PlatformKoa;
7
+ //# sourceMappingURL=exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.js","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":";;AAAA,yCAA2D;AAC3D,0DAAqD;AAErD,qBAAY,CAAC,OAAO,GAAG,yBAAW,CAAC;AACnC,wBAAe,CAAC,OAAO,GAAG,yBAAW,CAAC","sourcesContent":["import {PlatformBuilder, PlatformTest} from \"@tsed/common\";\nimport {PlatformKoa} from \"./components/PlatformKoa\";\n\nPlatformTest.adapter = PlatformKoa;\nPlatformBuilder.adapter = PlatformKoa;\n"]}
package/lib/cjs/index.js CHANGED
@@ -1,16 +1,22 @@
1
1
  "use strict";
2
+ /**
3
+ * @file Automatically generated by barrelsby.
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const tslib_1 = require("tslib");
4
- const common_1 = require("@tsed/common");
5
- const PlatformKoa_1 = require("./components/PlatformKoa");
6
- common_1.PlatformTest.adapter = PlatformKoa_1.PlatformKoa;
7
- common_1.PlatformBuilder.adapter = PlatformKoa_1.PlatformKoa;
8
- // interfaces
9
- (0, tslib_1.__exportStar)(require("./interfaces"), exports);
10
- // decorators
11
- (0, tslib_1.__exportStar)(require("./decorators"), exports);
12
- // services
13
- (0, tslib_1.__exportStar)(require("./services"), exports);
14
- // components
15
- (0, tslib_1.__exportStar)(require("./components/PlatformKoa"), exports);
7
+ tslib_1.__exportStar(require("./exports"), exports);
8
+ tslib_1.__exportStar(require("./components/PlatformKoa"), exports);
9
+ tslib_1.__exportStar(require("./decorators/caseSensitive"), exports);
10
+ tslib_1.__exportStar(require("./decorators/ctx"), exports);
11
+ tslib_1.__exportStar(require("./decorators/routerSettings"), exports);
12
+ tslib_1.__exportStar(require("./decorators/state"), exports);
13
+ tslib_1.__exportStar(require("./decorators/strict"), exports);
14
+ tslib_1.__exportStar(require("./interfaces/PlatformKoaSettings"), exports);
15
+ tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
16
+ tslib_1.__exportStar(require("./middlewares/resourceNotFoundMiddleware"), exports);
17
+ tslib_1.__exportStar(require("./middlewares/staticsMiddleware"), exports);
18
+ tslib_1.__exportStar(require("./services/PlatformKoaHandler"), exports);
19
+ tslib_1.__exportStar(require("./services/PlatformKoaRequest"), exports);
20
+ tslib_1.__exportStar(require("./services/PlatformKoaResponse"), exports);
21
+ tslib_1.__exportStar(require("./utils/multer"), exports);
16
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA2D;AAC3D,0DAAqD;AAErD,qBAAY,CAAC,OAAO,GAAG,yBAAW,CAAC;AACnC,wBAAe,CAAC,OAAO,GAAG,yBAAW,CAAC;AAEtC,aAAa;AACb,4DAA6B;AAE7B,aAAa;AACb,4DAA6B;AAE7B,WAAW;AACX,0DAA2B;AAE3B,aAAa;AACb,wEAAyC","sourcesContent":["import {PlatformBuilder, PlatformTest} from \"@tsed/common\";\nimport {PlatformKoa} from \"./components/PlatformKoa\";\n\nPlatformTest.adapter = PlatformKoa;\nPlatformBuilder.adapter = PlatformKoa;\n\n// interfaces\nexport * from \"./interfaces\";\n\n// decorators\nexport * from \"./decorators\";\n\n// services\nexport * from \"./services\";\n\n// components\nexport * from \"./components/PlatformKoa\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,mEAAyC;AACzC,qEAA2C;AAC3C,2DAAiC;AACjC,sEAA4C;AAC5C,6DAAmC;AACnC,8DAAoC;AACpC,2EAAiD;AACjD,kEAAwC;AACxC,mFAAyD;AACzD,0EAAgD;AAChD,wEAA8C;AAC9C,wEAA8C;AAC9C,yEAA+C;AAC/C,yDAA+B","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./components/PlatformKoa\";\nexport * from \"./decorators/caseSensitive\";\nexport * from \"./decorators/ctx\";\nexport * from \"./decorators/routerSettings\";\nexport * from \"./decorators/state\";\nexport * from \"./decorators/strict\";\nexport * from \"./interfaces/PlatformKoaSettings\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/resourceNotFoundMiddleware\";\nexport * from \"./middlewares/staticsMiddleware\";\nexport * from \"./services/PlatformKoaHandler\";\nexport * from \"./services/PlatformKoaRequest\";\nexport * from \"./services/PlatformKoaResponse\";\nexport * from \"./utils/multer\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformKoaSettings.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformKoaSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {RouterOptions} from \"@koa/router\";\n\nexport interface PlatformKoaSettings {\n /**\n * Global configuration for the Express.Router. See express [documentation](http://expressjs.com/en/api.html#express.router).\n */\n router: RouterOptions;\n}\n"]}
1
+ {"version":3,"file":"PlatformKoaSettings.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformKoaSettings.ts"],"names":[],"mappings":"","sourcesContent":["import type {RouterOptions} from \"@koa/router\";\nimport type {Middleware} from \"koa\";\nimport type {Options} from \"koa-bodyparser\";\n\nexport interface PlatformKoaSettings {\n /**\n * Koa router options\n */\n router?: RouterOptions;\n /**\n * Body parser options\n * @param opts\n */\n bodyParser?: (opts?: Options) => Middleware | Options;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./PlatformKoaSettings"), exports);
5
- //# sourceMappingURL=index.js.map
4
+ tslib_1.__exportStar(require("./PlatformKoaSettings"), exports);
5
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":";;;AAGA,gEAAsC","sourcesContent":["import Koa from \"koa\";\nimport {PlatformKoaSettings} from \"./PlatformKoaSettings\";\n\nexport * from \"./PlatformKoaSettings\";\n\ndeclare global {\n namespace TsED {\n export interface Configuration {\n /**\n * Configuration related to Koa platform application.\n */\n koa: PlatformKoaSettings;\n }\n\n export interface NextFunction extends Koa.Next {}\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resourceNotFoundMiddleware = void 0;
4
- const common_1 = require("@tsed/common");
4
+ const platform_exceptions_1 = require("@tsed/platform-exceptions");
5
5
  /**
6
6
  * @ignore
7
7
  * @param ctx
@@ -13,7 +13,7 @@ async function resourceNotFoundMiddleware(ctx, next) {
13
13
  await next();
14
14
  const status = ctx.status || 404;
15
15
  if (status === 404 && !$ctx.isDone()) {
16
- (_a = $ctx.injector.get(common_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.resourceNotFound($ctx);
16
+ (_a = $ctx.injector.get(platform_exceptions_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.resourceNotFound($ctx);
17
17
  }
18
18
  }
19
19
  exports.resourceNotFoundMiddleware = resourceNotFoundMiddleware;
@@ -1 +1 @@
1
- {"version":3,"file":"resourceNotFoundMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/resourceNotFoundMiddleware.ts"],"names":[],"mappings":";;;AAAA,yCAAiE;AAEjE;;;;GAIG;AACI,KAAK,UAAU,0BAA0B,CAAC,GAAQ,EAAE,IAAS;;IAClE,MAAM,IAAI,GAAoB,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/C,MAAM,IAAI,EAAE,CAAC;IACb,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC;IAEjC,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE;QACpC,MAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAqB,2BAAkB,CAAC,0CAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;KACnF;AACH,CAAC;AARD,gEAQC","sourcesContent":["import {PlatformContext, PlatformExceptions} from \"@tsed/common\";\n\n/**\n * @ignore\n * @param ctx\n * @param next\n */\nexport async function resourceNotFoundMiddleware(ctx: any, next: any) {\n const $ctx: PlatformContext = ctx.request.$ctx;\n await next();\n const status = ctx.status || 404;\n\n if (status === 404 && !$ctx.isDone()) {\n $ctx.injector.get<PlatformExceptions>(PlatformExceptions)?.resourceNotFound($ctx);\n }\n}\n"]}
1
+ {"version":3,"file":"resourceNotFoundMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/resourceNotFoundMiddleware.ts"],"names":[],"mappings":";;;AACA,mEAA6D;AAE7D;;;;GAIG;AACI,KAAK,UAAU,0BAA0B,CAAC,GAAQ,EAAE,IAAS;;IAClE,MAAM,IAAI,GAAoB,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/C,MAAM,IAAI,EAAE,CAAC;IACb,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC;IAEjC,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE;QACpC,MAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAqB,wCAAkB,CAAC,0CAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;KACnF;AACH,CAAC;AARD,gEAQC","sourcesContent":["import {PlatformContext} from \"@tsed/common\";\nimport {PlatformExceptions} from \"@tsed/platform-exceptions\";\n\n/**\n * @ignore\n * @param ctx\n * @param next\n */\nexport async function resourceNotFoundMiddleware(ctx: any, next: any) {\n const $ctx: PlatformContext = ctx.request.$ctx;\n await next();\n const status = ctx.status || 404;\n\n if (status === 404 && !$ctx.isDone()) {\n $ctx.injector.get<PlatformExceptions>(PlatformExceptions)?.resourceNotFound($ctx);\n }\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.staticsMiddleware = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const koa_send_1 = (0, tslib_1.__importDefault)(require("koa-send"));
5
+ const koa_send_1 = tslib_1.__importDefault(require("koa-send"));
6
6
  /**
7
7
  * @ignore
8
8
  * @param options
@@ -1 +1 @@
1
- {"version":3,"file":"staticsMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/staticsMiddleware.ts"],"names":[],"mappings":";;;;AAEA,qEAA4B;AAE5B;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,OAA+B;IAC/D,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK;QAAE,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,YAAY,CAAC;IAE3E,OAAO,KAAK,EAAE,GAAY,EAAE,IAAS,EAAE,EAAE;QACvC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;YACrD,IAAI,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;YAEpB,IAAI,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,aAAa,KAAK,GAAG,EAAE;gBAClD,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;aACzE;YACD,IAAI;gBACF,MAAM,IAAI,GAAG,MAAM,IAAA,kBAAI,EAAC,GAAU,EAAE,IAAI,EAAE,OAA2B,CAAC,CAAC;gBAEvE,IAAI,IAAI,EAAE;oBACR,OAAO;iBACR;aACF;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;oBACtB,MAAM,GAAG,CAAC;iBACX;aACF;SACF;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAzBD,8CAyBC","sourcesContent":["import {PlatformStaticsOptions} from \"@tsed/common\";\nimport type {Context} from \"koa\";\nimport send from \"koa-send\";\n\n/**\n * @ignore\n * @param options\n */\nexport function staticsMiddleware(options: PlatformStaticsOptions): any {\n if (options.index !== false) options.index = options.index || \"index.html\";\n\n return async (ctx: Context, next: any) => {\n if ([\"GET\", \"HEAD\"].includes(ctx.method) && !ctx.body) {\n let path = ctx.path;\n\n if (ctx._matchedRoute && ctx._matchedRoute !== \"/\") {\n path = path.replace(String(ctx._matchedRoute).replace(\"/(.*)\", \"\"), \"\");\n }\n try {\n const done = await send(ctx as any, path, options as send.SendOptions);\n\n if (done) {\n return;\n }\n } catch (err) {\n if (err.status !== 404) {\n throw err;\n }\n }\n }\n\n return next();\n };\n}\n"]}
1
+ {"version":3,"file":"staticsMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/staticsMiddleware.ts"],"names":[],"mappings":";;;;AAEA,gEAA4B;AAE5B;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,OAA+B;IAC/D,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK;QAAE,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,YAAY,CAAC;IAE3E,OAAO,KAAK,EAAE,GAAY,EAAE,IAAS,EAAE,EAAE;QACvC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;YACrD,IAAI,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;YAEpB,IAAI,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,aAAa,KAAK,GAAG,EAAE;gBAClD,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;aACzE;YACD,IAAI;gBACF,MAAM,IAAI,GAAG,MAAM,IAAA,kBAAI,EAAC,GAAU,EAAE,IAAI,EAAE,OAA2B,CAAC,CAAC;gBAEvE,IAAI,IAAI,EAAE;oBACR,OAAO;iBACR;aACF;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;oBACtB,MAAM,GAAG,CAAC;iBACX;aACF;SACF;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAzBD,8CAyBC","sourcesContent":["import {PlatformStaticsOptions} from \"@tsed/common\";\nimport type {Context} from \"koa\";\nimport send from \"koa-send\";\n\n/**\n * @ignore\n * @param options\n */\nexport function staticsMiddleware(options: PlatformStaticsOptions): any {\n if (options.index !== false) options.index = options.index || \"index.html\";\n\n return async (ctx: Context, next: any) => {\n if ([\"GET\", \"HEAD\"].includes(ctx.method) && !ctx.body) {\n let path = ctx.path;\n\n if (ctx._matchedRoute && ctx._matchedRoute !== \"/\") {\n path = path.replace(String(ctx._matchedRoute).replace(\"/(.*)\", \"\"), \"\");\n }\n try {\n const done = await send(ctx as any, path, options as send.SendOptions);\n\n if (done) {\n return;\n }\n } catch (err) {\n if (err.status !== 404) {\n throw err;\n }\n }\n }\n\n return next();\n };\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -13,29 +13,29 @@ class PlatformKoaRequest extends common_1.PlatformRequest {
13
13
  constructor(event, $ctx) {
14
14
  super(event, $ctx);
15
15
  _PlatformKoaRequest_ctx.set(this, void 0);
16
- (0, tslib_1.__classPrivateFieldSet)(this, _PlatformKoaRequest_ctx, this.raw.ctx, "f");
16
+ tslib_1.__classPrivateFieldSet(this, _PlatformKoaRequest_ctx, this.raw.ctx, "f");
17
17
  }
18
18
  get protocol() {
19
- return (0, tslib_1.__classPrivateFieldGet)(this, _PlatformKoaRequest_ctx, "f").request.protocol;
19
+ return tslib_1.__classPrivateFieldGet(this, _PlatformKoaRequest_ctx, "f").request.protocol;
20
20
  }
21
21
  get host() {
22
- return (0, tslib_1.__classPrivateFieldGet)(this, _PlatformKoaRequest_ctx, "f").request.host;
22
+ return tslib_1.__classPrivateFieldGet(this, _PlatformKoaRequest_ctx, "f").request.host;
23
23
  }
24
24
  get secure() {
25
- return (0, tslib_1.__classPrivateFieldGet)(this, _PlatformKoaRequest_ctx, "f").request.secure;
25
+ return tslib_1.__classPrivateFieldGet(this, _PlatformKoaRequest_ctx, "f").request.secure;
26
26
  }
27
27
  get cookies() {
28
- return (0, tslib_1.__classPrivateFieldGet)(this, _PlatformKoaRequest_ctx, "f").cookie || (0, tslib_1.__classPrivateFieldGet)(this, _PlatformKoaRequest_ctx, "f").cookies;
28
+ return tslib_1.__classPrivateFieldGet(this, _PlatformKoaRequest_ctx, "f").cookie || tslib_1.__classPrivateFieldGet(this, _PlatformKoaRequest_ctx, "f").cookies;
29
29
  }
30
30
  get session() {
31
- return (0, tslib_1.__classPrivateFieldGet)(this, _PlatformKoaRequest_ctx, "f").session;
31
+ return tslib_1.__classPrivateFieldGet(this, _PlatformKoaRequest_ctx, "f").session;
32
32
  }
33
33
  getReq() {
34
34
  return this.raw.req;
35
35
  }
36
36
  destroy() {
37
37
  // @ts-ignore
38
- (0, tslib_1.__classPrivateFieldSet)(this, _PlatformKoaRequest_ctx, null, "f");
38
+ tslib_1.__classPrivateFieldSet(this, _PlatformKoaRequest_ctx, null, "f");
39
39
  return super.destroy();
40
40
  }
41
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":";;;;;AAAA,uBAAqB;AACrB,yCAA6E;AAiB7E;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,wBAA4B;IAGlE,YAAY,KAAoB,EAAE,IAAqB;QACrD,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAHrB,0CAAkB;QAIhB,oCAAA,IAAI,2BAAQ,IAAI,CAAC,GAAG,CAAC,GAAG,MAAA,CAAC;IAC3B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,oCAAA,IAAI,+BAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;IACpC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,oCAAA,IAAI,+BAAK,CAAC,OAAO,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,oCAAA,IAAI,+BAAK,CAAC,OAAO,CAAC,MAAM,CAAC;IAClC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,oCAAA,IAAI,+BAAK,CAAC,MAAM,IAAI,oCAAA,IAAI,+BAAK,CAAC,OAAO,CAAC;IAC/C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,oCAAA,IAAI,+BAAK,CAAC,OAAO,CAAC;IAC3B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,OAAO;QACL,aAAa;QACb,oCAAA,IAAI,2BAAQ,IAAI,MAAA,CAAC;QACjB,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF;AArCD,gDAqCC","sourcesContent":["import \"@koa/router\";\nimport {IncomingEvent, PlatformContext, PlatformRequest} from \"@tsed/common\";\nimport {IncomingMessage} from \"http\";\nimport Koa from \"koa\";\n\ndeclare module \"koa\" {\n export interface Request {\n id: string;\n $ctx: PlatformContext;\n }\n}\n\ndeclare global {\n namespace TsED {\n export interface Request extends Koa.Request {}\n }\n}\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoaRequest extends PlatformRequest<Koa.Request> {\n #ctx: Koa.Context;\n\n constructor(event: IncomingEvent, $ctx: PlatformContext) {\n super(event, $ctx);\n this.#ctx = this.raw.ctx;\n }\n\n get protocol(): string {\n return this.#ctx.request.protocol;\n }\n\n get host(): string {\n return this.#ctx.request.host;\n }\n\n get secure(): boolean {\n return this.#ctx.request.secure;\n }\n\n get cookies(): {[p: string]: any} {\n return this.#ctx.cookie || this.#ctx.cookies;\n }\n\n get session(): any {\n return this.#ctx.session;\n }\n\n getReq(): IncomingMessage {\n return this.raw.req;\n }\n\n destroy() {\n // @ts-ignore\n this.#ctx = null;\n return super.destroy();\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":";;;;;AAAA,uBAAqB;AACrB,yCAA6E;AAiB7E;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,wBAA4B;IAGlE,YAAY,KAAoB,EAAE,IAAqB;QACrD,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAHrB,0CAAkB;QAIhB,+BAAA,IAAI,2BAAQ,IAAI,CAAC,GAAG,CAAC,GAAG,MAAA,CAAC;IAC3B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,+BAAA,IAAI,+BAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;IACpC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,+BAAA,IAAI,+BAAK,CAAC,OAAO,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,+BAAA,IAAI,+BAAK,CAAC,OAAO,CAAC,MAAM,CAAC;IAClC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,+BAAA,IAAI,+BAAK,CAAC,MAAM,IAAI,+BAAA,IAAI,+BAAK,CAAC,OAAO,CAAC;IAC/C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,+BAAA,IAAI,+BAAK,CAAC,OAAO,CAAC;IAC3B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,OAAO;QACL,aAAa;QACb,+BAAA,IAAI,2BAAQ,IAAI,MAAA,CAAC;QACjB,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF;AArCD,gDAqCC","sourcesContent":["import \"@koa/router\";\nimport {IncomingEvent, PlatformContext, PlatformRequest} from \"@tsed/common\";\nimport {IncomingMessage} from \"http\";\nimport Koa from \"koa\";\n\ndeclare module \"koa\" {\n export interface Request {\n id: string;\n $ctx: PlatformContext;\n }\n}\n\ndeclare global {\n namespace TsED {\n export interface Request extends Koa.Request {}\n }\n}\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoaRequest extends PlatformRequest<Koa.Request> {\n #ctx: Koa.Context;\n\n constructor(event: IncomingEvent, $ctx: PlatformContext) {\n super(event, $ctx);\n this.#ctx = this.raw.ctx;\n }\n\n get protocol(): string {\n return this.#ctx.request.protocol;\n }\n\n get host(): string {\n return this.#ctx.request.host;\n }\n\n get secure(): boolean {\n return this.#ctx.request.secure;\n }\n\n get cookies(): {[p: string]: any} {\n return this.#ctx.cookie || this.#ctx.cookies;\n }\n\n get session(): any {\n return this.#ctx.session;\n }\n\n getReq(): IncomingMessage {\n return this.raw.req;\n }\n\n destroy() {\n // @ts-ignore\n this.#ctx = null;\n return super.destroy();\n }\n}\n"]}
@@ -5,7 +5,7 @@ exports.PlatformKoaResponse = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const common_1 = require("@tsed/common");
7
7
  const schema_1 = require("@tsed/schema");
8
- const encodeUrl = require("encodeurl");
8
+ const encodeurl_1 = tslib_1.__importDefault(require("encodeurl"));
9
9
  /**
10
10
  * @platform
11
11
  * @koa
@@ -14,13 +14,13 @@ class PlatformKoaResponse extends common_1.PlatformResponse {
14
14
  constructor(event, $ctx) {
15
15
  super(event, $ctx);
16
16
  _PlatformKoaResponse_ctx.set(this, void 0);
17
- (0, tslib_1.__classPrivateFieldSet)(this, _PlatformKoaResponse_ctx, this.raw.ctx, "f");
17
+ tslib_1.__classPrivateFieldSet(this, _PlatformKoaResponse_ctx, this.raw.ctx, "f");
18
18
  }
19
19
  get statusCode() {
20
20
  return this.raw.status;
21
21
  }
22
22
  get locals() {
23
- return (0, tslib_1.__classPrivateFieldGet)(this, _PlatformKoaResponse_ctx, "f").state;
23
+ return tslib_1.__classPrivateFieldGet(this, _PlatformKoaResponse_ctx, "f").state;
24
24
  }
25
25
  /**
26
26
  * Return the Node.js response object
@@ -96,7 +96,7 @@ class PlatformKoaResponse extends common_1.PlatformResponse {
96
96
  location = this.request.get("Referrer") || "/";
97
97
  }
98
98
  // set location
99
- this.raw.set("Location", encodeUrl(location));
99
+ this.raw.set("Location", (0, encodeurl_1.default)(location));
100
100
  return this;
101
101
  }
102
102
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":";;;;;AAAA,yCAA8E;AAG9E,yCAA8C;AAE9C,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAQvC;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,yBAA8B;IAGrE,YAAY,KAAoB,EAAE,IAAqB;QACrD,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAHrB,2CAAkB;QAIhB,oCAAA,IAAI,4BAAQ,IAAI,CAAC,GAAG,CAAC,GAAG,MAAA,CAAC;IAC3B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AAS,CAAC,gBAAgB,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QAEnE,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE;YAClC,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC;SACrB;aAAM;YACL,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;SACnC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ,CAAC,QAAgB;QACvB,sCAAsC;QACtC,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC;SAChD;QAED,eAAe;QACf,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE9C,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA5GD,kDA4GC","sourcesContent":["import {IncomingEvent, PlatformContext, PlatformResponse} from \"@tsed/common\";\nimport {ServerResponse} from \"http\";\nimport Koa from \"koa\";\nimport {getStatusMessage} from \"@tsed/schema\";\n\nconst encodeUrl = require(\"encodeurl\");\n\ndeclare global {\n namespace TsED {\n export interface Response extends Koa.Response {}\n }\n}\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoaResponse extends PlatformResponse<Koa.Response> {\n #ctx: Koa.Context;\n\n constructor(event: IncomingEvent, $ctx: PlatformContext) {\n super(event, $ctx);\n this.#ctx = this.raw.ctx;\n }\n\n get statusCode() {\n return this.raw.status;\n }\n\n get locals() {\n return this.#ctx.state;\n }\n\n /**\n * Return the Node.js response object\n */\n getRes(): ServerResponse {\n return this.raw.res;\n }\n\n hasStatus() {\n // KOA set 404 by default\n return this.statusCode !== 404;\n }\n\n /**\n * Sets the HTTP status for the response.\n *\n * @param status\n */\n status(status: number) {\n this.raw.status = status;\n\n return this;\n }\n\n /**\n * Set `Content-Type` response header with `type` through `mime.lookup()`\n * when it does not contain \"/\", or set the Content-Type to `type` otherwise.\n *\n * Examples:\n *\n * res.type('.html');\n * res.type('html');\n * res.type('json');\n * res.type('application/json');\n * res.type('png');\n */\n contentType(contentType: string) {\n this.raw.type = contentType;\n\n return this;\n }\n\n getHeaders() {\n return this.raw.headers;\n }\n\n /**\n * Send any data to your consumer.\n *\n * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.\n * It choose the better way to send the data.\n *\n * @param data\n */\n body(data: any): this {\n this.raw.body = data;\n\n return this;\n }\n\n getBody() {\n return this.raw.body;\n }\n\n redirect(status: number, url: string): this {\n status = status || 302;\n // Set location header\n url = this.location(url).raw.get(\"Location\");\n\n this.body(`${getStatusMessage(status)}. Redirecting to ${url}`);\n this.status(status);\n this.setHeader(\"Content-Length\", Buffer.byteLength(this.raw.body));\n\n if (this.request.method === \"HEAD\") {\n this.getRes().end();\n } else {\n this.getRes().end(this.getBody());\n }\n\n return this;\n }\n\n location(location: string): this {\n // \"back\" is an alias for the referrer\n if (location === \"back\") {\n location = this.request.get(\"Referrer\") || \"/\";\n }\n\n // set location\n this.raw.set(\"Location\", encodeUrl(location));\n\n return this;\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":";;;;;AAAA,yCAA8E;AAG9E,yCAA8C;AAC9C,kEAAkC;AAQlC;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,yBAA8B;IAGrE,YAAY,KAAoB,EAAE,IAAqB;QACrD,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAHrB,2CAAkB;QAIhB,+BAAA,IAAI,4BAAQ,IAAI,CAAC,GAAG,CAAC,GAAG,MAAA,CAAC;IAC3B,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,GAAG,CA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AAC,GAAG,CAAC,IAAW,CAAC,CAAC,CAAC;QAE1E,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE;YAClC,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC;SACrB;aAAM;YACL,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;SACnC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ,CAAC,QAAgB;QACvB,sCAAsC;QACtC,IAAI,QAAQ,KAAK,MAAM,EAAE;YACvB,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC;SAChD;QAED,eAAe;QACf,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,IAAA,mBAAS,EAAC,QAAQ,CAAC,CAAC,CAAC;QAE9C,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA5GD,kDA4GC","sourcesContent":["import {IncomingEvent, PlatformContext, PlatformResponse} from \"@tsed/common\";\nimport {ServerResponse} from \"http\";\nimport Koa from \"koa\";\nimport {getStatusMessage} from \"@tsed/schema\";\nimport encodeUrl from \"encodeurl\";\n\ndeclare global {\n namespace TsED {\n export interface Response extends Koa.Response {}\n }\n}\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoaResponse extends PlatformResponse<Koa.Response> {\n #ctx: Koa.Context;\n\n constructor(event: IncomingEvent, $ctx: PlatformContext) {\n super(event, $ctx);\n this.#ctx = this.raw.ctx;\n }\n\n get statusCode() {\n return this.raw.status;\n }\n\n get locals() {\n return this.#ctx.state;\n }\n\n /**\n * Return the Node.js response object\n */\n getRes(): ServerResponse {\n return this.raw.res;\n }\n\n hasStatus() {\n // KOA set 404 by default\n return this.statusCode !== 404;\n }\n\n /**\n * Sets the HTTP status for the response.\n *\n * @param status\n */\n status(status: number) {\n this.raw.status = status;\n\n return this;\n }\n\n /**\n * Set `Content-Type` response header with `type` through `mime.lookup()`\n * when it does not contain \"/\", or set the Content-Type to `type` otherwise.\n *\n * Examples:\n *\n * res.type('.html');\n * res.type('html');\n * res.type('json');\n * res.type('application/json');\n * res.type('png');\n */\n contentType(contentType: string) {\n this.raw.type = contentType;\n\n return this;\n }\n\n getHeaders() {\n return this.raw.headers;\n }\n\n /**\n * Send any data to your consumer.\n *\n * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.\n * It choose the better way to send the data.\n *\n * @param data\n */\n body(data: any): this {\n this.raw.body = data;\n\n return this;\n }\n\n getBody(): any {\n return this.raw.body;\n }\n\n redirect(status: number, url: string): this {\n status = status || 302;\n // Set location header\n url = this.location(url).raw.get(\"Location\");\n\n this.body(`${getStatusMessage(status)}. Redirecting to ${url}`);\n this.status(status);\n this.setHeader(\"Content-Length\", Buffer.byteLength(this.raw.body as any));\n\n if (this.request.method === \"HEAD\") {\n this.getRes().end();\n } else {\n this.getRes().end(this.getBody());\n }\n\n return this;\n }\n\n location(location: string): this {\n // \"back\" is an alias for the referrer\n if (location === \"back\") {\n location = this.request.get(\"Referrer\") || \"/\";\n }\n\n // set location\n this.raw.set(\"Location\", encodeUrl(location));\n\n return this;\n }\n}\n"]}
@@ -1,7 +1,32 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.getMulter = void 0;
4
27
  const util_1 = require("util");
28
+ let multer;
29
+ Promise.resolve().then(() => __importStar(require("multer"))).then(({ default: m }) => (multer = m));
5
30
  /**
6
31
  * @ignore
7
32
  */
@@ -43,7 +68,7 @@ function makePromise(multer, name) {
43
68
  * @ignore
44
69
  */
45
70
  function getMulter(options) {
46
- const m = require("multer")(options);
71
+ const m = multer(options);
47
72
  makePromise(m, "any");
48
73
  makePromise(m, "array");
49
74
  makePromise(m, "fields");
@@ -1 +1 @@
1
- {"version":3,"file":"multer.js","sourceRoot":"","sources":["../../../src/utils/multer.ts"],"names":[],"mappings":";;;AACA,+BAA+B;AAE/B;;GAEG;AACH,SAAS,mBAAmB,CAAC,UAAe;IAC1C,OAAO,KAAK,EAAE,OAAoB,EAAE,EAAE;QACpC,MAAM,GAAG,GAAQ,OAAO,CAAC,GAAG,CAAC;QAE7B,MAAM,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QAEnC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE;YACjC,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBAChB,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBAChC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACxB,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;aACrB;QACH,CAAC,CAAC;QAEF,IAAI,SAAS,IAAI,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n return async (request: Koa.Request) => {\n const ctx: any = request.ctx;\n\n await middleware(ctx.req, ctx.res);\n\n const forwardKey = (key: string) => {\n if (ctx.req[key]) {\n ctx.request[key] = ctx.req[key];\n ctx[key] = ctx.req[key];\n delete ctx.req[key];\n }\n };\n\n if (\"request\" in ctx) {\n if (ctx.req.body) {\n ctx.request.body = ctx.req.body;\n delete ctx.req.body;\n }\n\n forwardKey(\"file\");\n forwardKey(\"files\");\n }\n };\n}\n\n/**\n * @ignore\n */\nfunction makePromise(multer: any, name: string) {\n // istanbul ignore next\n if (!multer[name]) return;\n\n const fn = multer[name];\n\n multer[name] = function apply(...args: any[]) {\n const middleware = Reflect.apply(fn, this, args);\n\n return createRawMiddleware(promisify(middleware));\n };\n}\n\n/**\n * @ignore\n */\nexport function getMulter(options: any) {\n const m = require(\"multer\")(options);\n\n makePromise(m, \"any\");\n makePromise(m, \"array\");\n makePromise(m, \"fields\");\n makePromise(m, \"none\");\n makePromise(m, \"single\");\n\n return m;\n}\n"]}
1
+ {"version":3,"file":"multer.js","sourceRoot":"","sources":["../../../src/utils/multer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+BAA+B;AAE/B,IAAI,MAAW,CAAC;AAChB,kDAAO,QAAQ,IAAE,IAAI,CAAC,CAAC,EAAC,OAAO,EAAE,CAAC,EAAC,EAAE,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AAEtD;;GAEG;AACH,SAAS,mBAAmB,CAAC,UAAe;IAC1C,OAAO,KAAK,EAAE,OAAoB,EAAE,EAAE;QACpC,MAAM,GAAG,GAAQ,OAAO,CAAC,GAAG,CAAC;QAE7B,MAAM,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QAEnC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAE;YACjC,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBAChB,GAAG,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C,CAAC;IACzB,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACvB,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IAEzB,OAAO,CAAC,CAAC;AACX,CAAC;AAVD,8BAUC","sourcesContent":["import Koa from \"koa\";\nimport {promisify} from \"util\";\n\nlet multer: any;\nimport(\"multer\").then(({default: m}) => (multer = m));\n\n/**\n * @ignore\n */\nfunction createRawMiddleware(middleware: any) {\n return async (request: Koa.Request) => {\n const ctx: any = request.ctx;\n\n await middleware(ctx.req, ctx.res);\n\n const forwardKey = (key: string) => {\n if (ctx.req[key]) {\n ctx.request[key] = ctx.req[key];\n ctx[key] = ctx.req[key];\n delete ctx.req[key];\n }\n };\n\n if (\"request\" in ctx) {\n if (ctx.req.body) {\n ctx.request.body = ctx.req.body;\n delete ctx.req.body;\n }\n\n forwardKey(\"file\");\n forwardKey(\"files\");\n }\n };\n}\n\n/**\n * @ignore\n */\nfunction makePromise(multer: any, name: string) {\n // istanbul ignore next\n if (!multer[name]) return;\n\n const fn = multer[name];\n\n multer[name] = function apply(...args: any[]) {\n const middleware = Reflect.apply(fn, this, args);\n\n return createRawMiddleware(promisify(middleware));\n };\n}\n\n/**\n * @ignore\n */\nexport function getMulter(options: any) {\n const m = multer(options);\n\n makePromise(m, \"any\");\n makePromise(m, \"array\");\n makePromise(m, \"fields\");\n makePromise(m, \"none\");\n makePromise(m, \"single\");\n\n return m;\n}\n"]}
@@ -1,13 +1,35 @@
1
- import { createContext, PlatformApplication, PlatformBuilder, PlatformExceptions, PlatformHandler, PlatformRequest, PlatformResponse, PlatformRouter } from "@tsed/common";
2
- import { resourceNotFoundMiddleware } from "../middlewares/resourceNotFoundMiddleware";
3
- import { PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, PlatformKoaResponse, PlatformKoaRouter } from "../services";
1
+ import KoaRouter from "@koa/router";
2
+ import { createContext, PlatformApplication, PlatformBuilder, PlatformHandler, PlatformRequest, PlatformResponse } from "@tsed/common";
3
+ import { PlatformExceptions } from "@tsed/platform-exceptions";
4
+ import { isFunction } from "@tsed/core";
5
+ import Koa from "koa";
6
+ import { resourceNotFoundMiddleware } from "../middlewares/resourceNotFoundMiddleware.js";
7
+ import { PlatformKoaResponse } from "../services/PlatformKoaResponse.js";
8
+ import { PlatformKoaRequest } from "../services/PlatformKoaRequest.js";
9
+ import { PlatformKoaHandler } from "../services/PlatformKoaHandler.js";
10
+ import { getMulter } from "../utils/multer.js";
11
+ import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
12
+ // @ts-ignore
13
+ import koaQs from "koa-qs";
14
+ import koaBodyParser from "koa-bodyparser";
15
+ // @ts-ignore
16
+ KoaRouter.prototype.$$match = KoaRouter.prototype.match;
17
+ KoaRouter.prototype.match = function match(...args) {
18
+ const matched = this.$$match(...args);
19
+ if (matched) {
20
+ if (matched.path.length) {
21
+ matched.route = true;
22
+ }
23
+ }
24
+ return matched;
25
+ };
4
26
  /**
5
27
  * @platform
6
28
  * @koa
7
29
  */
8
30
  export class PlatformKoa {
9
- constructor(platform) {
10
- this.platform = platform;
31
+ constructor(injector) {
32
+ this.injector = injector;
11
33
  this.providers = [
12
34
  {
13
35
  provide: PlatformResponse,
@@ -20,14 +42,6 @@ export class PlatformKoa {
20
42
  {
21
43
  provide: PlatformHandler,
22
44
  useClass: PlatformKoaHandler
23
- },
24
- {
25
- provide: PlatformRouter,
26
- useClass: PlatformKoaRouter
27
- },
28
- {
29
- provide: PlatformApplication,
30
- useClass: PlatformKoaApplication
31
45
  }
32
46
  ];
33
47
  }
@@ -54,7 +68,8 @@ export class PlatformKoa {
54
68
  });
55
69
  }
56
70
  onInit() {
57
- const { injector, app } = this.platform;
71
+ const injector = this.injector;
72
+ const app = this.injector.get(PlatformApplication);
58
73
  const listener = (error, ctx) => {
59
74
  var _a;
60
75
  (_a = injector.get(PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(error, ctx.request.$ctx);
@@ -63,14 +78,16 @@ export class PlatformKoa {
63
78
  app.getApp().on("error", listener);
64
79
  }
65
80
  useRouter() {
66
- const { app } = this.platform;
67
- app.getApp().use(resourceNotFoundMiddleware).use(app.getRouter().routes()).use(app.getRouter().allowedMethods());
81
+ const app = this.injector.get(PlatformApplication);
82
+ app.getApp().use(resourceNotFoundMiddleware);
83
+ app.getApp().use(app.getRouter().routes()).use(app.getRouter().allowedMethods());
68
84
  return this;
69
85
  }
70
86
  useContext() {
71
- const { injector, app, logger } = this.platform;
87
+ const app = this.injector.get(PlatformApplication);
88
+ const { logger } = this.injector;
72
89
  logger.info("Mount app context");
73
- const invoke = createContext(injector);
90
+ const invoke = createContext(this.injector);
74
91
  app.getApp().use(async (ctx, next) => {
75
92
  await invoke({
76
93
  request: ctx.request,
@@ -81,5 +98,43 @@ export class PlatformKoa {
81
98
  });
82
99
  return this;
83
100
  }
101
+ app() {
102
+ const app = this.injector.settings.get("koa.app") || new Koa();
103
+ koaQs(app, "extended");
104
+ return {
105
+ app,
106
+ callback() {
107
+ return app.callback();
108
+ }
109
+ };
110
+ }
111
+ router(routerOptions = {}) {
112
+ var _a;
113
+ const { settings } = this.injector;
114
+ const options = Object.assign({}, ((_a = settings.koa) === null || _a === void 0 ? void 0 : _a.router) || {}, routerOptions);
115
+ const router = new KoaRouter(options);
116
+ return {
117
+ router,
118
+ callback() {
119
+ return [router.routes(), router.allowedMethods()];
120
+ }
121
+ };
122
+ }
123
+ multipart(options) {
124
+ return getMulter(options);
125
+ }
126
+ statics(endpoint, options) {
127
+ return staticsMiddleware(options);
128
+ }
129
+ bodyParser(type, additionalOptions = {}) {
130
+ const opts = this.injector.settings.get(`koa.bodyParser`);
131
+ let parser = koaBodyParser;
132
+ let options = {};
133
+ if (isFunction(opts)) {
134
+ parser = opts;
135
+ options = {};
136
+ }
137
+ return parser({ ...options, ...additionalOptions });
138
+ }
84
139
  }
85
140
  //# sourceMappingURL=PlatformKoa.js.map