@tsed/platform-koa 6.110.1 → 6.112.0

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.
@@ -1,20 +1,38 @@
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 core_1 = require("@tsed/core");
8
+ const koa_1 = tslib_1.__importDefault(require("koa"));
5
9
  const resourceNotFoundMiddleware_1 = require("../middlewares/resourceNotFoundMiddleware");
6
10
  const PlatformKoaResponse_1 = require("../services/PlatformKoaResponse");
7
11
  const PlatformKoaRequest_1 = require("../services/PlatformKoaRequest");
8
12
  const PlatformKoaHandler_1 = require("../services/PlatformKoaHandler");
9
- const PlatformKoaRouter_1 = require("../services/PlatformKoaRouter");
10
- const PlatformKoaApplication_1 = require("../services/PlatformKoaApplication");
13
+ const multer_1 = require("../utils/multer");
14
+ const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
15
+ // @ts-ignore
16
+ const koa_qs_1 = tslib_1.__importDefault(require("koa-qs"));
17
+ const koa_bodyparser_1 = tslib_1.__importDefault(require("koa-bodyparser"));
18
+ // @ts-ignore
19
+ router_1.default.prototype.$$match = router_1.default.prototype.match;
20
+ router_1.default.prototype.match = function match(...args) {
21
+ const matched = this.$$match(...args);
22
+ if (matched) {
23
+ if (matched.path.length) {
24
+ matched.route = true;
25
+ }
26
+ }
27
+ return matched;
28
+ };
11
29
  /**
12
30
  * @platform
13
31
  * @koa
14
32
  */
15
33
  class PlatformKoa {
16
- constructor(platform) {
17
- this.platform = platform;
34
+ constructor(injector) {
35
+ this.injector = injector;
18
36
  this.providers = [
19
37
  {
20
38
  provide: common_1.PlatformResponse,
@@ -27,14 +45,6 @@ class PlatformKoa {
27
45
  {
28
46
  provide: common_1.PlatformHandler,
29
47
  useClass: PlatformKoaHandler_1.PlatformKoaHandler
30
- },
31
- {
32
- provide: common_1.PlatformRouter,
33
- useClass: PlatformKoaRouter_1.PlatformKoaRouter
34
- },
35
- {
36
- provide: common_1.PlatformApplication,
37
- useClass: PlatformKoaApplication_1.PlatformKoaApplication
38
48
  }
39
49
  ];
40
50
  }
@@ -61,7 +71,8 @@ class PlatformKoa {
61
71
  });
62
72
  }
63
73
  onInit() {
64
- const { injector, app } = this.platform;
74
+ const injector = this.injector;
75
+ const app = this.injector.get(common_1.PlatformApplication);
65
76
  const listener = (error, ctx) => {
66
77
  var _a;
67
78
  (_a = injector.get(common_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(error, ctx.request.$ctx);
@@ -70,14 +81,16 @@ class PlatformKoa {
70
81
  app.getApp().on("error", listener);
71
82
  }
72
83
  useRouter() {
73
- const { app } = this.platform;
74
- app.getApp().use(resourceNotFoundMiddleware_1.resourceNotFoundMiddleware).use(app.getRouter().routes()).use(app.getRouter().allowedMethods());
84
+ const app = this.injector.get(common_1.PlatformApplication);
85
+ app.getApp().use(resourceNotFoundMiddleware_1.resourceNotFoundMiddleware);
86
+ app.getApp().use(app.getRouter().routes()).use(app.getRouter().allowedMethods());
75
87
  return this;
76
88
  }
77
89
  useContext() {
78
- const { injector, app, logger } = this.platform;
90
+ const app = this.injector.get(common_1.PlatformApplication);
91
+ const { logger } = this.injector;
79
92
  logger.info("Mount app context");
80
- const invoke = (0, common_1.createContext)(injector);
93
+ const invoke = (0, common_1.createContext)(this.injector);
81
94
  app.getApp().use(async (ctx, next) => {
82
95
  await invoke({
83
96
  request: ctx.request,
@@ -88,6 +101,44 @@ class PlatformKoa {
88
101
  });
89
102
  return this;
90
103
  }
104
+ app() {
105
+ const app = this.injector.settings.get("koa.app") || new koa_1.default();
106
+ (0, koa_qs_1.default)(app, "extended");
107
+ return {
108
+ app,
109
+ callback() {
110
+ return app.callback();
111
+ }
112
+ };
113
+ }
114
+ router(routerOptions = {}) {
115
+ var _a;
116
+ const { settings } = this.injector;
117
+ const options = Object.assign({}, ((_a = settings.koa) === null || _a === void 0 ? void 0 : _a.router) || {}, routerOptions);
118
+ const router = new router_1.default(options);
119
+ return {
120
+ router,
121
+ callback() {
122
+ return [router.routes(), router.allowedMethods()];
123
+ }
124
+ };
125
+ }
126
+ multipart(options) {
127
+ return (0, multer_1.getMulter)(options);
128
+ }
129
+ statics(endpoint, options) {
130
+ return (0, staticsMiddleware_1.staticsMiddleware)(options);
131
+ }
132
+ bodyParser(type, additionalOptions = {}) {
133
+ const opts = this.injector.settings.get(`koa.bodyParser`);
134
+ let parser = koa_bodyparser_1.default;
135
+ let options = {};
136
+ if ((0, core_1.isFunction)(opts)) {
137
+ parser = opts;
138
+ options = {};
139
+ }
140
+ return parser({ ...options, ...additionalOptions });
141
+ }
91
142
  }
92
143
  exports.PlatformKoa = PlatformKoa;
93
144
  //# 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,yEAAoE;AACpE,uEAAkE;AAClE,uEAAkE;AAClE,qEAAgE;AAChE,+EAA0E;AAE1E;;;GAGG;AACH,MAAa,WAAW;IAwBtB,YAAoB,QAAyC;QAAzC,aAAQ,GAAR,QAAQ,CAAiC;QAvBpD,cAAS,GAAG;YACnB;gBACE,OAAO,EAAE,yBAAgB;gBACzB,QAAQ,EAAE,yCAAmB;aAC9B;YACD;gBACE,OAAO,EAAE,wBAAe;gBACxB,QAAQ,EAAE,uCAAkB;aAC7B;YACD;gBACE,OAAO,EAAE,wBAAe;gBACxB,QAAQ,EAAE,uCAAkB;aAC7B;YACD;gBACE,OAAO,EAAE,uBAAc;gBACvB,QAAQ,EAAE,qCAAiB;aAC5B;YACD;gBACE,OAAO,EAAE,4BAAmB;gBAC5B,QAAQ,EAAE,+CAAsB;aACjC;SACF,CAAC;IAE8D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,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 {PlatformKoaResponse} from \"../services/PlatformKoaResponse\";\nimport {PlatformKoaRequest} from \"../services/PlatformKoaRequest\";\nimport {PlatformKoaHandler} from \"../services/PlatformKoaHandler\";\nimport {PlatformKoaRouter} from \"../services/PlatformKoaRouter\";\nimport {PlatformKoaApplication} from \"../services/PlatformKoaApplication\";\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,yCAasB;AACtB,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,gBAAS,CAAC,SAAS,CAAC,KAAK,GAAG,S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AAI,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 PlatformExceptions,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\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"]}
@@ -10,7 +10,7 @@ const common_1 = require("@tsed/common");
10
10
  * @koa
11
11
  */
12
12
  function KoaCtx() {
13
- return (0, common_1.UseParam)("KOA_CTX", {
13
+ return (0, common_1.UseParam)({
14
14
  paramType: "KOA_CTX",
15
15
  dataPath: "$ctx.request.ctx",
16
16
  useConverter: false,
@@ -1 +1 @@
1
- {"version":3,"file":"ctx.js","sourceRoot":"","sources":["../../../src/decorators/ctx.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAGtC;;;;;;GAMG;AACH,SAAgB,MAAM;IACpB,OAAO,IAAA,iBAAQ,EAAC,SAAS,EAAE;QACzB,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,kBAAkB;QAC5B,YAAY,EAAE,KAAK;QACnB,aAAa,EAAE,KAAK;KACrB,CAAC,CAAC;AACL,CAAC;AAPD,wBAOC;AAED;;;;;;GAMG;AACH,SAAgB,GAAG;IACjB,OAAO,MAAM,EAAE,CAAC;AAClB,CAAC;AAFD,kBAEC","sourcesContent":["import {UseParam} from \"@tsed/common\";\nimport type {Context} from \"koa\";\n\n/**\n * Return the original Koa context.\n * @decorator\n * @operation\n * @input\n * @koa\n */\nexport function KoaCtx(): ParameterDecorator {\n return UseParam(\"KOA_CTX\", {\n paramType: \"KOA_CTX\",\n dataPath: \"$ctx.request.ctx\",\n useConverter: false,\n useValidation: false\n });\n}\n\n/**\n * Return the original Koa context.\n * @decorator\n * @operation\n * @input\n * @koa\n */\nexport function Ctx(): ParameterDecorator {\n return KoaCtx();\n}\n\nexport type Ctx = Context;\nexport type KoaCtx = Context;\n"]}
1
+ {"version":3,"file":"ctx.js","sourceRoot":"","sources":["../../../src/decorators/ctx.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAGtC;;;;;;GAMG;AACH,SAAgB,MAAM;IACpB,OAAO,IAAA,iBAAQ,EAAC;QACd,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,kBAAkB;QAC5B,YAAY,EAAE,KAAK;QACnB,aAAa,EAAE,KAAK;KACrB,CAAC,CAAC;AACL,CAAC;AAPD,wBAOC;AAED;;;;;;GAMG;AACH,SAAgB,GAAG;IACjB,OAAO,MAAM,EAAE,CAAC;AAClB,CAAC;AAFD,kBAEC","sourcesContent":["import {UseParam} from \"@tsed/common\";\nimport type {Context} from \"koa\";\n\n/**\n * Return the original Koa context.\n * @decorator\n * @operation\n * @input\n * @koa\n */\nexport function KoaCtx(): ParameterDecorator {\n return UseParam({\n paramType: \"KOA_CTX\",\n dataPath: \"$ctx.request.ctx\",\n useConverter: false,\n useValidation: false\n });\n}\n\n/**\n * Return the original Koa context.\n * @decorator\n * @operation\n * @input\n * @koa\n */\nexport function Ctx(): ParameterDecorator {\n return KoaCtx();\n}\n\nexport type Ctx = Context;\nexport type KoaCtx = Context;\n"]}
package/lib/cjs/index.js CHANGED
@@ -15,10 +15,8 @@ tslib_1.__exportStar(require("./interfaces/PlatformKoaSettings"), exports);
15
15
  tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
16
16
  tslib_1.__exportStar(require("./middlewares/resourceNotFoundMiddleware"), exports);
17
17
  tslib_1.__exportStar(require("./middlewares/staticsMiddleware"), exports);
18
- tslib_1.__exportStar(require("./services/PlatformKoaApplication"), exports);
19
18
  tslib_1.__exportStar(require("./services/PlatformKoaHandler"), exports);
20
19
  tslib_1.__exportStar(require("./services/PlatformKoaRequest"), exports);
21
20
  tslib_1.__exportStar(require("./services/PlatformKoaResponse"), exports);
22
- tslib_1.__exportStar(require("./services/PlatformKoaRouter"), exports);
23
21
  tslib_1.__exportStar(require("./utils/multer"), exports);
24
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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,4EAAkD;AAClD,wEAA8C;AAC9C,wEAA8C;AAC9C,yEAA+C;AAC/C,uEAA6C;AAC7C,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/PlatformKoaApplication\";\nexport * from \"./services/PlatformKoaHandler\";\nexport * from \"./services/PlatformKoaRequest\";\nexport * from \"./services/PlatformKoaResponse\";\nexport * from \"./services/PlatformKoaRouter\";\nexport * from \"./utils/multer\";\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,17 +1,34 @@
1
- import { createContext, PlatformApplication, PlatformBuilder, PlatformExceptions, PlatformHandler, PlatformRequest, PlatformResponse, PlatformRouter } from "@tsed/common";
1
+ import KoaRouter from "@koa/router";
2
+ import { createContext, PlatformApplication, PlatformBuilder, PlatformExceptions, PlatformHandler, PlatformRequest, PlatformResponse } from "@tsed/common";
3
+ import { isFunction } from "@tsed/core";
4
+ import Koa from "koa";
2
5
  import { resourceNotFoundMiddleware } from "../middlewares/resourceNotFoundMiddleware.js";
3
6
  import { PlatformKoaResponse } from "../services/PlatformKoaResponse.js";
4
7
  import { PlatformKoaRequest } from "../services/PlatformKoaRequest.js";
5
8
  import { PlatformKoaHandler } from "../services/PlatformKoaHandler.js";
6
- import { PlatformKoaRouter } from "../services/PlatformKoaRouter.js";
7
- import { PlatformKoaApplication } from "../services/PlatformKoaApplication.js";
9
+ import { getMulter } from "../utils/multer.js";
10
+ import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
11
+ // @ts-ignore
12
+ import koaQs from "koa-qs";
13
+ import koaBodyParser from "koa-bodyparser";
14
+ // @ts-ignore
15
+ KoaRouter.prototype.$$match = KoaRouter.prototype.match;
16
+ KoaRouter.prototype.match = function match(...args) {
17
+ const matched = this.$$match(...args);
18
+ if (matched) {
19
+ if (matched.path.length) {
20
+ matched.route = true;
21
+ }
22
+ }
23
+ return matched;
24
+ };
8
25
  /**
9
26
  * @platform
10
27
  * @koa
11
28
  */
12
29
  export class PlatformKoa {
13
- constructor(platform) {
14
- this.platform = platform;
30
+ constructor(injector) {
31
+ this.injector = injector;
15
32
  this.providers = [
16
33
  {
17
34
  provide: PlatformResponse,
@@ -24,14 +41,6 @@ export class PlatformKoa {
24
41
  {
25
42
  provide: PlatformHandler,
26
43
  useClass: PlatformKoaHandler
27
- },
28
- {
29
- provide: PlatformRouter,
30
- useClass: PlatformKoaRouter
31
- },
32
- {
33
- provide: PlatformApplication,
34
- useClass: PlatformKoaApplication
35
44
  }
36
45
  ];
37
46
  }
@@ -58,7 +67,8 @@ export class PlatformKoa {
58
67
  });
59
68
  }
60
69
  onInit() {
61
- const { injector, app } = this.platform;
70
+ const injector = this.injector;
71
+ const app = this.injector.get(PlatformApplication);
62
72
  const listener = (error, ctx) => {
63
73
  var _a;
64
74
  (_a = injector.get(PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(error, ctx.request.$ctx);
@@ -67,14 +77,16 @@ export class PlatformKoa {
67
77
  app.getApp().on("error", listener);
68
78
  }
69
79
  useRouter() {
70
- const { app } = this.platform;
71
- app.getApp().use(resourceNotFoundMiddleware).use(app.getRouter().routes()).use(app.getRouter().allowedMethods());
80
+ const app = this.injector.get(PlatformApplication);
81
+ app.getApp().use(resourceNotFoundMiddleware);
82
+ app.getApp().use(app.getRouter().routes()).use(app.getRouter().allowedMethods());
72
83
  return this;
73
84
  }
74
85
  useContext() {
75
- const { injector, app, logger } = this.platform;
86
+ const app = this.injector.get(PlatformApplication);
87
+ const { logger } = this.injector;
76
88
  logger.info("Mount app context");
77
- const invoke = createContext(injector);
89
+ const invoke = createContext(this.injector);
78
90
  app.getApp().use(async (ctx, next) => {
79
91
  await invoke({
80
92
  request: ctx.request,
@@ -85,5 +97,43 @@ export class PlatformKoa {
85
97
  });
86
98
  return this;
87
99
  }
100
+ app() {
101
+ const app = this.injector.settings.get("koa.app") || new Koa();
102
+ koaQs(app, "extended");
103
+ return {
104
+ app,
105
+ callback() {
106
+ return app.callback();
107
+ }
108
+ };
109
+ }
110
+ router(routerOptions = {}) {
111
+ var _a;
112
+ const { settings } = this.injector;
113
+ const options = Object.assign({}, ((_a = settings.koa) === null || _a === void 0 ? void 0 : _a.router) || {}, routerOptions);
114
+ const router = new KoaRouter(options);
115
+ return {
116
+ router,
117
+ callback() {
118
+ return [router.routes(), router.allowedMethods()];
119
+ }
120
+ };
121
+ }
122
+ multipart(options) {
123
+ return getMulter(options);
124
+ }
125
+ statics(endpoint, options) {
126
+ return staticsMiddleware(options);
127
+ }
128
+ bodyParser(type, additionalOptions = {}) {
129
+ const opts = this.injector.settings.get(`koa.bodyParser`);
130
+ let parser = koaBodyParser;
131
+ let options = {};
132
+ if (isFunction(opts)) {
133
+ parser = opts;
134
+ options = {};
135
+ }
136
+ return parser({ ...options, ...additionalOptions });
137
+ }
88
138
  }
89
139
  //# sourceMappingURL=PlatformKoa.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":"AACA,OAAO,E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7B,GAAG;aACJ,CAAC,CAAC;YAEH,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CACF","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 {PlatformKoaResponse} from \"../services/PlatformKoaResponse\";\nimport {PlatformKoaRequest} from \"../services/PlatformKoaRequest\";\nimport {PlatformKoaHandler} from \"../services/PlatformKoaHandler\";\nimport {PlatformKoaRouter} from \"../services/PlatformKoaRouter\";\nimport {PlatformKoaApplication} from \"../services/PlatformKoaApplication\";\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,OAAO,SAA8C,MAAM,aAAa,CAAC;AACzE,OAAO,EACL,aAAa,EAGb,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,eAAe,EAGf,eAAe,EACf,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,UAAU,EAAO,MAAM,YAAY,CAAC;AAC5C,OAAO,GAAoB,MAAM,KAAK,CAAC;AACvC,OAAO,EAAC,0BAA0B,EAAC,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAC,mBAAmB,EAAC,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AAEnE,aAAa;AACb,OAAO,KAAK,MAAM,QAAQ,CAAC;AAC3B,OAAO,aAAwB,MAAM,gBAAgB,CAAC;AAgBtD,aAAa;AACb,SAAS,CA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E,CAAC;QAE1B,IAAI,UAAU,CAAC,IAAI,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","sourcesContent":["import KoaRouter, {RouterOptions as KoaRouterOptions} from \"@koa/router\";\nimport {\n createContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformExceptions,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\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"]}
@@ -7,7 +7,7 @@ import { UseParam } from "@tsed/common";
7
7
  * @koa
8
8
  */
9
9
  export function KoaCtx() {
10
- return UseParam("KOA_CTX", {
10
+ return UseParam({
11
11
  paramType: "KOA_CTX",
12
12
  dataPath: "$ctx.request.ctx",
13
13
  useConverter: false,
@@ -1 +1 @@
1
- {"version":3,"file":"ctx.js","sourceRoot":"","sources":["../../../src/decorators/ctx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAGtC;;;;;;GAMG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,QAAQ,CAAC,SAAS,EAAE;QACzB,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,kBAAkB;QAC5B,YAAY,EAAE,KAAK;QACnB,aAAa,EAAE,KAAK;KACrB,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,GAAG;IACjB,OAAO,MAAM,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import {UseParam} from \"@tsed/common\";\nimport type {Context} from \"koa\";\n\n/**\n * Return the original Koa context.\n * @decorator\n * @operation\n * @input\n * @koa\n */\nexport function KoaCtx(): ParameterDecorator {\n return UseParam(\"KOA_CTX\", {\n paramType: \"KOA_CTX\",\n dataPath: \"$ctx.request.ctx\",\n useConverter: false,\n useValidation: false\n });\n}\n\n/**\n * Return the original Koa context.\n * @decorator\n * @operation\n * @input\n * @koa\n */\nexport function Ctx(): ParameterDecorator {\n return KoaCtx();\n}\n\nexport type Ctx = Context;\nexport type KoaCtx = Context;\n"]}
1
+ {"version":3,"file":"ctx.js","sourceRoot":"","sources":["../../../src/decorators/ctx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAGtC;;;;;;GAMG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,QAAQ,CAAC;QACd,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,kBAAkB;QAC5B,YAAY,EAAE,KAAK;QACnB,aAAa,EAAE,KAAK;KACrB,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,GAAG;IACjB,OAAO,MAAM,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import {UseParam} from \"@tsed/common\";\nimport type {Context} from \"koa\";\n\n/**\n * Return the original Koa context.\n * @decorator\n * @operation\n * @input\n * @koa\n */\nexport function KoaCtx(): ParameterDecorator {\n return UseParam({\n paramType: \"KOA_CTX\",\n dataPath: \"$ctx.request.ctx\",\n useConverter: false,\n useValidation: false\n });\n}\n\n/**\n * Return the original Koa context.\n * @decorator\n * @operation\n * @input\n * @koa\n */\nexport function Ctx(): ParameterDecorator {\n return KoaCtx();\n}\n\nexport type Ctx = Context;\nexport type KoaCtx = Context;\n"]}
package/lib/esm/index.js CHANGED
@@ -12,10 +12,8 @@ export * from "./interfaces/PlatformKoaSettings.js";
12
12
  export * from "./interfaces/interfaces.js";
13
13
  export * from "./middlewares/resourceNotFoundMiddleware.js";
14
14
  export * from "./middlewares/staticsMiddleware.js";
15
- export * from "./services/PlatformKoaApplication.js";
16
15
  export * from "./services/PlatformKoaHandler.js";
17
16
  export * from "./services/PlatformKoaRequest.js";
18
17
  export * from "./services/PlatformKoaResponse.js";
19
- export * from "./services/PlatformKoaRouter.js";
20
18
  export * from "./utils/multer.js";
21
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AACjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,0CAA0C,CAAC;AACzD,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gBAAgB,CAAC","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/PlatformKoaApplication\";\nexport * from \"./services/PlatformKoaHandler\";\nexport * from \"./services/PlatformKoaRequest\";\nexport * from \"./services/PlatformKoaResponse\";\nexport * from \"./services/PlatformKoaRouter\";\nexport * from \"./utils/multer\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AACjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,0CAA0C,CAAC;AACzD,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gBAAgB,CAAC","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,19 +1,32 @@
1
1
  /// <reference types="koa__router" />
2
- import KoaRouter from "@koa/router";
3
- import { PlatformAdapter, PlatformApplication, PlatformBuilder, PlatformHandler, PlatformRequest, PlatformResponse, PlatformRouter } from "@tsed/common";
2
+ import KoaRouter, { RouterOptions as KoaRouterOptions } from "@koa/router";
3
+ import { InjectorService, PlatformAdapter, PlatformBuilder, PlatformHandler, PlatformMulter, PlatformMulterSettings, PlatformRequest, PlatformResponse, PlatformStaticsOptions } from "@tsed/common";
4
4
  import { Type } from "@tsed/core";
5
5
  import Koa from "koa";
6
6
  import { PlatformKoaResponse } from "../services/PlatformKoaResponse";
7
7
  import { PlatformKoaRequest } from "../services/PlatformKoaRequest";
8
8
  import { PlatformKoaHandler } from "../services/PlatformKoaHandler";
9
- import { PlatformKoaRouter } from "../services/PlatformKoaRouter";
10
- import { PlatformKoaApplication } from "../services/PlatformKoaApplication";
9
+ import send from "koa-send";
10
+ declare global {
11
+ namespace TsED {
12
+ interface Application extends Koa {
13
+ }
14
+ }
15
+ namespace TsED {
16
+ interface Router extends KoaRouter {
17
+ }
18
+ interface RouterOptions extends KoaRouterOptions {
19
+ }
20
+ interface StaticsOptions extends send.SendOptions {
21
+ }
22
+ }
23
+ }
11
24
  /**
12
25
  * @platform
13
26
  * @koa
14
27
  */
15
28
  export declare class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {
16
- private platform;
29
+ private injector;
17
30
  readonly providers: ({
18
31
  provide: typeof PlatformResponse;
19
32
  useClass: typeof PlatformKoaResponse;
@@ -23,14 +36,8 @@ export declare class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {
23
36
  } | {
24
37
  provide: typeof PlatformHandler;
25
38
  useClass: typeof PlatformKoaHandler;
26
- } | {
27
- provide: typeof PlatformRouter;
28
- useClass: typeof PlatformKoaRouter;
29
- } | {
30
- provide: typeof PlatformApplication;
31
- useClass: typeof PlatformKoaApplication;
32
39
  })[];
33
- constructor(platform: PlatformBuilder<Koa, KoaRouter>);
40
+ constructor(injector: InjectorService);
34
41
  /**
35
42
  * Create new serverless application. In this mode, the component scan are disabled.
36
43
  * @param module
@@ -46,4 +53,15 @@ export declare class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {
46
53
  onInit(): void;
47
54
  useRouter(): this;
48
55
  useContext(): this;
56
+ app(): {
57
+ app: any;
58
+ callback(): any;
59
+ };
60
+ router(routerOptions?: any): {
61
+ router: any;
62
+ callback(): any[];
63
+ };
64
+ multipart(options: PlatformMulterSettings): PlatformMulter;
65
+ statics(endpoint: string, options: PlatformStaticsOptions): any;
66
+ bodyParser(type: "json" | "urlencoded" | "raw" | "text", additionalOptions?: any): any;
49
67
  }
@@ -12,9 +12,7 @@ export * from "./interfaces/PlatformKoaSettings";
12
12
  export * from "./interfaces/interfaces";
13
13
  export * from "./middlewares/resourceNotFoundMiddleware";
14
14
  export * from "./middlewares/staticsMiddleware";
15
- export * from "./services/PlatformKoaApplication";
16
15
  export * from "./services/PlatformKoaHandler";
17
16
  export * from "./services/PlatformKoaRequest";
18
17
  export * from "./services/PlatformKoaResponse";
19
- export * from "./services/PlatformKoaRouter";
20
18
  export * from "./utils/multer";
@@ -1,8 +1,15 @@
1
1
  /// <reference types="koa__router" />
2
- import { RouterOptions } from "@koa/router";
2
+ import type { RouterOptions } from "@koa/router";
3
+ import type { Middleware } from "koa";
4
+ import type { Options } from "koa-bodyparser";
3
5
  export interface PlatformKoaSettings {
4
6
  /**
5
- * Global configuration for the Express.Router. See express [documentation](http://expressjs.com/en/api.html#express.router).
7
+ * Koa router options
6
8
  */
7
- router: RouterOptions;
9
+ router?: RouterOptions;
10
+ /**
11
+ * Body parser options
12
+ * @param opts
13
+ */
14
+ bodyParser?: (opts?: Options) => Middleware | Options;
8
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/platform-koa",
3
- "version": "6.110.1",
3
+ "version": "6.112.0",
4
4
  "description": "Koa package for Ts.ED framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -51,10 +51,10 @@
51
51
  "repository": "https://github.com/tsedio/tsed",
52
52
  "devDependencies": {
53
53
  "@koa/cors": "3.3.0",
54
- "@tsed/common": "6.110.1",
55
- "@tsed/core": "6.110.1",
56
- "@tsed/di": "6.110.1",
57
- "@tsed/platform-test-utils": "6.110.1",
54
+ "@tsed/common": "6.112.0",
55
+ "@tsed/core": "6.112.0",
56
+ "@tsed/di": "6.112.0",
57
+ "@tsed/platform-test-utils": "6.112.0",
58
58
  "@types/koa": "2.13.4",
59
59
  "@types/koa-bodyparser": "4.3.7",
60
60
  "@types/koa-compose": "3.2.5",
@@ -79,13 +79,13 @@
79
79
  "tslib": "2.3.1"
80
80
  },
81
81
  "peerDependencies": {
82
- "@tsed/common": "^6.110.1",
83
- "@tsed/core": "^6.110.1",
84
- "@tsed/di": "^6.110.1",
85
- "@tsed/json-mapper": "^6.110.1",
82
+ "@tsed/common": "^6.112.0",
83
+ "@tsed/core": "^6.112.0",
84
+ "@tsed/di": "^6.112.0",
85
+ "@tsed/json-mapper": "^6.112.0",
86
86
  "@tsed/logger": ">=6.1.1",
87
- "@tsed/openspec": "^6.110.1",
88
- "@tsed/schema": "^6.110.1",
87
+ "@tsed/openspec": "^6.112.0",
88
+ "@tsed/schema": "^6.112.0",
89
89
  "koa": ">=2.13.0",
90
90
  "koa-bodyparser": ">=4.3.0",
91
91
  "koa-compress": ">=5.0.1",
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlatformKoaApplication = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@tsed/common");
6
- const koa_1 = tslib_1.__importDefault(require("koa"));
7
- const PlatformKoaRouter_1 = require("./PlatformKoaRouter");
8
- const koaQs = require("koa-qs");
9
- /**
10
- * @platform
11
- * @express
12
- */
13
- let PlatformKoaApplication = class PlatformKoaApplication extends PlatformKoaRouter_1.PlatformKoaRouter {
14
- constructor(platformHandler, configuration) {
15
- super(platformHandler, configuration, {});
16
- this.rawApp = configuration.get("koa.app") || new koa_1.default();
17
- koaQs(this.rawApp, "extended");
18
- }
19
- getApp() {
20
- return this.rawApp;
21
- }
22
- callback() {
23
- return this.getApp().callback();
24
- }
25
- };
26
- PlatformKoaApplication = tslib_1.__decorate([
27
- tslib_1.__param(0, (0, common_1.Inject)()),
28
- tslib_1.__param(1, (0, common_1.Configuration)()),
29
- tslib_1.__metadata("design:paramtypes", [common_1.PlatformHandler, Object])
30
- ], PlatformKoaApplication);
31
- exports.PlatformKoaApplication = PlatformKoaApplication;
32
- //# sourceMappingURL=PlatformKoaApplication.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformKoaApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaApplication.ts"],"names":[],"mappings":";;;;AACA,yCAAyF;AACzF,sDAAsB;AACtB,2DAAsD;AAEtD,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAQhC;;;GAGG;AACH,IAAa,sBAAsB,GAAnC,MAAa,sBAAuB,SAAQ,qCAAiB;IAI3D,YAAsB,eAAgC,EAAmB,aAA4B;QACnG,KAAK,CAAC,eAAe,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC;QAE1C,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,aAAG,EAAE,CAAC;QACxD,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACjC,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;IAClC,CAAC;CACF,CAAA;AAlBY,sBAAsB;IAIpB,mBAAA,IAAA,eAAM,GAAE,CAAA;IAAoC,mBAAA,IAAA,sBAAa,GAAE,CAAA;6CAAjC,wBAAe;GAJ3C,sBAAsB,CAkBlC;AAlBY,wDAAsB","sourcesContent":["import KoaRouter from \"@koa/router\";\nimport {Configuration, Inject, PlatformApplication, PlatformHandler} from \"@tsed/common\";\nimport Koa from \"koa\";\nimport {PlatformKoaRouter} from \"./PlatformKoaRouter\";\n\nconst koaQs = require(\"koa-qs\");\n\ndeclare global {\n namespace TsED {\n export interface Application extends Koa {}\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformKoaApplication extends PlatformKoaRouter implements PlatformApplication<Koa, KoaRouter> {\n app: Koa;\n rawApp: Koa;\n\n constructor(@Inject() platformHandler: PlatformHandler, @Configuration() configuration: Configuration) {\n super(platformHandler, configuration, {});\n\n this.rawApp = configuration.get(\"koa.app\") || new Koa();\n koaQs(this.rawApp, \"extended\");\n }\n\n getApp(): Koa {\n return this.rawApp;\n }\n\n callback(): any {\n return this.getApp().callback();\n }\n}\n"]}
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlatformKoaRouter = void 0;
4
- const tslib_1 = require("tslib");
5
- const router_1 = tslib_1.__importDefault(require("@koa/router"));
6
- const common_1 = require("@tsed/common");
7
- const di_1 = require("@tsed/di");
8
- const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
9
- const multer_1 = require("../utils/multer");
10
- // @ts-ignore
11
- router_1.default.prototype.$$match = router_1.default.prototype.match;
12
- router_1.default.prototype.match = function match(...args) {
13
- const matched = this.$$match(...args);
14
- if (matched) {
15
- if (matched.path.length) {
16
- matched.route = true;
17
- }
18
- }
19
- return matched;
20
- };
21
- let PlatformKoaRouter = class PlatformKoaRouter extends common_1.PlatformRouter {
22
- constructor(platform, configuration, routerOptions) {
23
- var _a;
24
- super(platform);
25
- const options = Object.assign({}, ((_a = configuration.koa) === null || _a === void 0 ? void 0 : _a.router) || {}, routerOptions);
26
- this.rawRouter = new router_1.default(options);
27
- }
28
- callback() {
29
- return [this.getRouter().routes(), this.getRouter().allowedMethods()];
30
- }
31
- multer(options) {
32
- return (0, multer_1.getMulter)(options);
33
- }
34
- statics(path, options) {
35
- this.rawRouter.use(path, (0, staticsMiddleware_1.staticsMiddleware)(options));
36
- return this;
37
- }
38
- };
39
- PlatformKoaRouter = tslib_1.__decorate([
40
- tslib_1.__param(1, (0, di_1.Configuration)()),
41
- tslib_1.__param(2, (0, di_1.Inject)(common_1.PLATFORM_ROUTER_OPTIONS)),
42
- tslib_1.__metadata("design:paramtypes", [common_1.PlatformHandler, Object, Object])
43
- ], PlatformKoaRouter);
44
- exports.PlatformKoaRouter = PlatformKoaRouter;
45
- //# sourceMappingURL=PlatformKoaRouter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformKoaRouter.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRouter.ts"],"names":[],"mappings":";;;;AAAA,iEAAoC;AAGpC,yCAOsB;AACtB,iCAA+C;AAE/C,wEAAmE;AACnE,4CAA0C;AAY1C,aAAa;AACb,gBAAS,CAAC,SAAS,CAAC,OAAO,GAAG,gBAAS,CAAC,SAAS,CAAC,KAAK,CAAC;AACxD,gBAAS,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,KAAK,CAAC,GAAG,IAAW;IACvD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IACtC,IAAI,OAAO,EAAE;QACX,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE;YACvB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;SACtB;KACF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,IAAa,iBAAiB,GAA9B,MAAa,iBAAkB,SAAQ,uBAAyB;IAC9D,YACE,QAAyB,EACR,aAA4B,EACZ,aAAkB;;QAEnD,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEhB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA,MAAA,aAAa,CAAC,GAAG,0CAAE,MAAM,KAAI,EAAE,EAAE,aAAa,CAAC,CAAC;QAClF,IAAI,CAAC,SAAS,GAAG,IAAI,gBAAS,CAAC,OAAO,CAAQ,CAAC;IACjD,CAAC;IAED,QAAQ;QACN,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,CAAC,OAA+B;QACpC,OAAO,IAAA,kBAAS,EAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,CAAC,IAAY,EAAE,OAA+B;QACnD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,IAAA,qCAAiB,EAAC,OAAO,CAAQ,CAAC,CAAC;QAE5D,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAzBY,iBAAiB;IAGzB,mBAAA,IAAA,kBAAa,GAAE,CAAA;IACf,mBAAA,IAAA,WAAM,EAAC,gCAAuB,CAAC,CAAA;6CAFtB,wBAAe;GAFhB,iBAAiB,CAyB7B;AAzBY,8CAAiB","sourcesContent":["import KoaRouter from \"@koa/router\";\nimport {RouterOptions as KoaRouterOptions} from \"@koa/router\";\n\nimport {\n PLATFORM_ROUTER_OPTIONS,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRouter,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {Configuration, Inject} from \"@tsed/di\";\nimport send from \"koa-send\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {getMulter} from \"../utils/multer\";\n\ndeclare global {\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\nexport class PlatformKoaRouter extends PlatformRouter<KoaRouter> {\n constructor(\n platform: PlatformHandler,\n @Configuration() configuration: Configuration,\n @Inject(PLATFORM_ROUTER_OPTIONS) routerOptions: any\n ) {\n super(platform);\n\n const options = Object.assign({}, configuration.koa?.router || {}, routerOptions);\n this.rawRouter = new KoaRouter(options) as any;\n }\n\n callback() {\n return [this.getRouter().routes(), this.getRouter().allowedMethods()];\n }\n\n multer(options: PlatformMulterSettings): PlatformMulter {\n return getMulter(options);\n }\n\n statics(path: string, options: PlatformStaticsOptions) {\n this.rawRouter.use(path, staticsMiddleware(options) as any);\n\n return this;\n }\n}\n"]}
@@ -1,29 +0,0 @@
1
- import { __decorate, __metadata, __param } from "tslib";
2
- import { Configuration, Inject, PlatformHandler } from "@tsed/common";
3
- import Koa from "koa";
4
- import { PlatformKoaRouter } from "./PlatformKoaRouter.js";
5
- const koaQs = require("koa-qs");
6
- /**
7
- * @platform
8
- * @express
9
- */
10
- let PlatformKoaApplication = class PlatformKoaApplication extends PlatformKoaRouter {
11
- constructor(platformHandler, configuration) {
12
- super(platformHandler, configuration, {});
13
- this.rawApp = configuration.get("koa.app") || new Koa();
14
- koaQs(this.rawApp, "extended");
15
- }
16
- getApp() {
17
- return this.rawApp;
18
- }
19
- callback() {
20
- return this.getApp().callback();
21
- }
22
- };
23
- PlatformKoaApplication = __decorate([
24
- __param(0, Inject()),
25
- __param(1, Configuration()),
26
- __metadata("design:paramtypes", [PlatformHandler, Object])
27
- ], PlatformKoaApplication);
28
- export { PlatformKoaApplication };
29
- //# sourceMappingURL=PlatformKoaApplication.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformKoaApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaApplication.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,aAAa,EAAE,MAAM,EAAuB,eAAe,EAAC,MAAM,cAAc,CAAC;AACzF,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAEtD,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAQhC;;;GAGG;AACH,IAAa,sBAAsB,GAAnC,MAAa,sBAAuB,SAAQ,iBAAiB;IAI3D,YAAsB,eAAgC,EAAmB,aAA4B;QACnG,KAAK,CAAC,eAAe,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC;QAE1C,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;QACxD,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACjC,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;IAClC,CAAC;CACF,CAAA;AAlBY,sBAAsB;IAIpB,WAAA,MAAM,EAAE,CAAA;IAAoC,WAAA,aAAa,EAAE,CAAA;qCAAjC,eAAe;GAJ3C,sBAAsB,CAkBlC;SAlBY,sBAAsB","sourcesContent":["import KoaRouter from \"@koa/router\";\nimport {Configuration, Inject, PlatformApplication, PlatformHandler} from \"@tsed/common\";\nimport Koa from \"koa\";\nimport {PlatformKoaRouter} from \"./PlatformKoaRouter\";\n\nconst koaQs = require(\"koa-qs\");\n\ndeclare global {\n namespace TsED {\n export interface Application extends Koa {}\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformKoaApplication extends PlatformKoaRouter implements PlatformApplication<Koa, KoaRouter> {\n app: Koa;\n rawApp: Koa;\n\n constructor(@Inject() platformHandler: PlatformHandler, @Configuration() configuration: Configuration) {\n super(platformHandler, configuration, {});\n\n this.rawApp = configuration.get(\"koa.app\") || new Koa();\n koaQs(this.rawApp, \"extended\");\n }\n\n getApp(): Koa {\n return this.rawApp;\n }\n\n callback(): any {\n return this.getApp().callback();\n }\n}\n"]}
@@ -1,42 +0,0 @@
1
- import { __decorate, __metadata, __param } from "tslib";
2
- import KoaRouter from "@koa/router";
3
- import { PLATFORM_ROUTER_OPTIONS, PlatformHandler, PlatformRouter } from "@tsed/common";
4
- import { Configuration, Inject } from "@tsed/di";
5
- import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
6
- import { getMulter } from "../utils/multer.js";
7
- // @ts-ignore
8
- KoaRouter.prototype.$$match = KoaRouter.prototype.match;
9
- KoaRouter.prototype.match = function match(...args) {
10
- const matched = this.$$match(...args);
11
- if (matched) {
12
- if (matched.path.length) {
13
- matched.route = true;
14
- }
15
- }
16
- return matched;
17
- };
18
- let PlatformKoaRouter = class PlatformKoaRouter extends PlatformRouter {
19
- constructor(platform, configuration, routerOptions) {
20
- var _a;
21
- super(platform);
22
- const options = Object.assign({}, ((_a = configuration.koa) === null || _a === void 0 ? void 0 : _a.router) || {}, routerOptions);
23
- this.rawRouter = new KoaRouter(options);
24
- }
25
- callback() {
26
- return [this.getRouter().routes(), this.getRouter().allowedMethods()];
27
- }
28
- multer(options) {
29
- return getMulter(options);
30
- }
31
- statics(path, options) {
32
- this.rawRouter.use(path, staticsMiddleware(options));
33
- return this;
34
- }
35
- };
36
- PlatformKoaRouter = __decorate([
37
- __param(1, Configuration()),
38
- __param(2, Inject(PLATFORM_ROUTER_OPTIONS)),
39
- __metadata("design:paramtypes", [PlatformHandler, Object, Object])
40
- ], PlatformKoaRouter);
41
- export { PlatformKoaRouter };
42
- //# sourceMappingURL=PlatformKoaRouter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformKoaRouter.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRouter.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,aAAa,CAAC;AAGpC,OAAO,EACL,uBAAuB,EACvB,eAAe,EAGf,cAAc,EAEf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,aAAa,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAE/C,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAA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iB;IAGzB,WAAA,aAAa,EAAE,CAAA;IACf,WAAA,MAAM,CAAC,uBAAuB,CAAC,CAAA;qCAFtB,eAAe;GAFhB,iBAAiB,CAyB7B;SAzBY,iBAAiB","sourcesContent":["import KoaRouter from \"@koa/router\";\nimport {RouterOptions as KoaRouterOptions} from \"@koa/router\";\n\nimport {\n PLATFORM_ROUTER_OPTIONS,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRouter,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {Configuration, Inject} from \"@tsed/di\";\nimport send from \"koa-send\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {getMulter} from \"../utils/multer\";\n\ndeclare global {\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\nexport class PlatformKoaRouter extends PlatformRouter<KoaRouter> {\n constructor(\n platform: PlatformHandler,\n @Configuration() configuration: Configuration,\n @Inject(PLATFORM_ROUTER_OPTIONS) routerOptions: any\n ) {\n super(platform);\n\n const options = Object.assign({}, configuration.koa?.router || {}, routerOptions);\n this.rawRouter = new KoaRouter(options) as any;\n }\n\n callback() {\n return [this.getRouter().routes(), this.getRouter().allowedMethods()];\n }\n\n multer(options: PlatformMulterSettings): PlatformMulter {\n return getMulter(options);\n }\n\n statics(path: string, options: PlatformStaticsOptions) {\n this.rawRouter.use(path, staticsMiddleware(options) as any);\n\n return this;\n }\n}\n"]}
@@ -1,22 +0,0 @@
1
- /// <reference types="koa__router" />
2
- import KoaRouter from "@koa/router";
3
- import { Configuration, PlatformApplication, PlatformHandler } from "@tsed/common";
4
- import Koa from "koa";
5
- import { PlatformKoaRouter } from "./PlatformKoaRouter";
6
- declare global {
7
- namespace TsED {
8
- interface Application extends Koa {
9
- }
10
- }
11
- }
12
- /**
13
- * @platform
14
- * @express
15
- */
16
- export declare class PlatformKoaApplication extends PlatformKoaRouter implements PlatformApplication<Koa, KoaRouter> {
17
- app: Koa;
18
- rawApp: Koa;
19
- constructor(platformHandler: PlatformHandler, configuration: Configuration);
20
- getApp(): Koa;
21
- callback(): any;
22
- }
@@ -1,23 +0,0 @@
1
- /// <reference types="koa__router" />
2
- /// <reference types="koa" />
3
- import KoaRouter from "@koa/router";
4
- import { RouterOptions as KoaRouterOptions } from "@koa/router";
5
- import { PlatformHandler, PlatformMulter, PlatformMulterSettings, PlatformRouter, PlatformStaticsOptions } from "@tsed/common";
6
- import { Configuration } from "@tsed/di";
7
- import send from "koa-send";
8
- declare global {
9
- namespace TsED {
10
- interface Router extends KoaRouter {
11
- }
12
- interface RouterOptions extends KoaRouterOptions {
13
- }
14
- interface StaticsOptions extends send.SendOptions {
15
- }
16
- }
17
- }
18
- export declare class PlatformKoaRouter extends PlatformRouter<KoaRouter> {
19
- constructor(platform: PlatformHandler, configuration: Configuration, routerOptions: any);
20
- callback(): KoaRouter.Middleware<import("koa").DefaultState, import("koa").DefaultContext>[];
21
- multer(options: PlatformMulterSettings): PlatformMulter;
22
- statics(path: string, options: PlatformStaticsOptions): this;
23
- }