@tsed/platform-koa 7.0.0-beta.10 → 7.0.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest.config.js +14 -0
- package/lib/cjs/components/PlatformKoa.js +24 -26
- package/lib/cjs/components/PlatformKoa.js.map +1 -1
- package/lib/cjs/interfaces/PlatformKoaSettings.js.map +1 -1
- package/lib/cjs/middlewares/resourceNotFoundMiddleware.js +1 -2
- package/lib/cjs/middlewares/resourceNotFoundMiddleware.js.map +1 -1
- package/lib/cjs/services/PlatformKoaRequest.js +8 -18
- package/lib/cjs/services/PlatformKoaRequest.js.map +1 -1
- package/lib/cjs/services/PlatformKoaResponse.js +3 -7
- package/lib/cjs/services/PlatformKoaResponse.js.map +1 -1
- package/lib/esm/components/PlatformKoa.js +24 -26
- package/lib/esm/components/PlatformKoa.js.map +1 -1
- package/lib/esm/interfaces/PlatformKoaSettings.js.map +1 -1
- package/lib/esm/middlewares/resourceNotFoundMiddleware.js +1 -2
- package/lib/esm/middlewares/resourceNotFoundMiddleware.js.map +1 -1
- package/lib/esm/services/PlatformKoaRequest.js +8 -18
- package/lib/esm/services/PlatformKoaRequest.js.map +1 -1
- package/lib/esm/services/PlatformKoaResponse.js +3 -8
- package/lib/esm/services/PlatformKoaResponse.js.map +1 -1
- package/lib/types/components/PlatformKoa.d.ts +3 -3
- package/lib/types/interfaces/PlatformKoaSettings.d.ts +1 -1
- package/lib/types/services/PlatformKoaRequest.d.ts +3 -6
- package/lib/types/services/PlatformKoaResponse.d.ts +2 -3
- package/package.json +24 -16
- package/readme.md +2 -1
package/jest.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// For a detailed explanation regarding each configuration property, visit:
|
|
2
|
+
// https://jestjs.io/docs/en/configuration.html
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
...require("@tsed/jest-config")(__dirname, "platform-koa"),
|
|
6
|
+
coverageThreshold: {
|
|
7
|
+
global: {
|
|
8
|
+
statements: 99.5,
|
|
9
|
+
branches: 85.45,
|
|
10
|
+
functions: 100,
|
|
11
|
+
lines: 99.49
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -7,15 +7,15 @@ const common_1 = require("@tsed/common");
|
|
|
7
7
|
const platform_exceptions_1 = require("@tsed/platform-exceptions");
|
|
8
8
|
const core_1 = require("@tsed/core");
|
|
9
9
|
const koa_1 = tslib_1.__importDefault(require("koa"));
|
|
10
|
+
const koa_bodyparser_1 = tslib_1.__importDefault(require("koa-bodyparser"));
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
const koa_qs_1 = tslib_1.__importDefault(require("koa-qs"));
|
|
10
13
|
const resourceNotFoundMiddleware_1 = require("../middlewares/resourceNotFoundMiddleware");
|
|
11
|
-
const
|
|
12
|
-
const PlatformKoaRequest_1 = require("../services/PlatformKoaRequest");
|
|
14
|
+
const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
|
|
13
15
|
const PlatformKoaHandler_1 = require("../services/PlatformKoaHandler");
|
|
16
|
+
const PlatformKoaRequest_1 = require("../services/PlatformKoaRequest");
|
|
17
|
+
const PlatformKoaResponse_1 = require("../services/PlatformKoaResponse");
|
|
14
18
|
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
19
|
// @ts-ignore
|
|
20
20
|
router_1.default.prototype.$$match = router_1.default.prototype.match;
|
|
21
21
|
router_1.default.prototype.match = function match(...args) {
|
|
@@ -32,22 +32,23 @@ router_1.default.prototype.match = function match(...args) {
|
|
|
32
32
|
* @koa
|
|
33
33
|
*/
|
|
34
34
|
class PlatformKoa {
|
|
35
|
+
injector;
|
|
36
|
+
providers = [
|
|
37
|
+
{
|
|
38
|
+
provide: common_1.PlatformResponse,
|
|
39
|
+
useClass: PlatformKoaResponse_1.PlatformKoaResponse
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
provide: common_1.PlatformRequest,
|
|
43
|
+
useClass: PlatformKoaRequest_1.PlatformKoaRequest
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
provide: common_1.PlatformHandler,
|
|
47
|
+
useClass: PlatformKoaHandler_1.PlatformKoaHandler
|
|
48
|
+
}
|
|
49
|
+
];
|
|
35
50
|
constructor(injector) {
|
|
36
51
|
this.injector = injector;
|
|
37
|
-
this.providers = [
|
|
38
|
-
{
|
|
39
|
-
provide: common_1.PlatformResponse,
|
|
40
|
-
useClass: PlatformKoaResponse_1.PlatformKoaResponse
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
provide: common_1.PlatformRequest,
|
|
44
|
-
useClass: PlatformKoaRequest_1.PlatformKoaRequest
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
provide: common_1.PlatformHandler,
|
|
48
|
-
useClass: PlatformKoaHandler_1.PlatformKoaHandler
|
|
49
|
-
}
|
|
50
|
-
];
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
53
54
|
* Create new serverless application. In this mode, the component scan are disabled.
|
|
@@ -75,8 +76,7 @@ class PlatformKoa {
|
|
|
75
76
|
const injector = this.injector;
|
|
76
77
|
const app = this.injector.get(common_1.PlatformApplication);
|
|
77
78
|
const listener = (error, ctx) => {
|
|
78
|
-
|
|
79
|
-
(_a = injector.get(platform_exceptions_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(error, ctx.request.$ctx);
|
|
79
|
+
injector.get(platform_exceptions_1.PlatformExceptions)?.catch(error, ctx.request.$ctx);
|
|
80
80
|
};
|
|
81
81
|
app.getApp().silent = true;
|
|
82
82
|
app.getApp().on("error", listener);
|
|
@@ -95,8 +95,7 @@ class PlatformKoa {
|
|
|
95
95
|
app.getApp().use(async (ctx, next) => {
|
|
96
96
|
await invoke({
|
|
97
97
|
request: ctx.request,
|
|
98
|
-
response: ctx.response
|
|
99
|
-
ctx
|
|
98
|
+
response: ctx.response
|
|
100
99
|
});
|
|
101
100
|
return next();
|
|
102
101
|
});
|
|
@@ -113,9 +112,8 @@ class PlatformKoa {
|
|
|
113
112
|
};
|
|
114
113
|
}
|
|
115
114
|
router(routerOptions = {}) {
|
|
116
|
-
var _a;
|
|
117
115
|
const { settings } = this.injector;
|
|
118
|
-
const options = Object.assign({},
|
|
116
|
+
const options = Object.assign({}, settings.get("koa.router", {}), routerOptions);
|
|
119
117
|
const router = new router_1.default(options);
|
|
120
118
|
return {
|
|
121
119
|
router,
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,4EAAsD;AACtD,aAAa;AACb,4DAA2B;AAE3B,0FAAqF;AACrF,wEAAmE;AACnE,uEAAkE;AAClE,uEAAkE;AAClE,yEAAoE;AACpE,4CAA0C;AAgB1C,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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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 koaBodyParser, {Options} from \"koa-bodyparser\";\n// @ts-ignore\nimport koaQs from \"koa-qs\";\nimport send from \"koa-send\";\nimport {resourceNotFoundMiddleware} from \"../middlewares/resourceNotFoundMiddleware\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {PlatformKoaHandler} from \"../services/PlatformKoaHandler\";\nimport {PlatformKoaRequest} from \"../services/PlatformKoaRequest\";\nimport {PlatformKoaResponse} from \"../services/PlatformKoaResponse\";\nimport {getMulter} from \"../utils/multer\";\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 });\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.get(\"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"]}
|
|
@@ -1 +1 @@
|
|
|
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
|
+
{"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"]}
|
|
@@ -8,12 +8,11 @@ const platform_exceptions_1 = require("@tsed/platform-exceptions");
|
|
|
8
8
|
* @param next
|
|
9
9
|
*/
|
|
10
10
|
async function resourceNotFoundMiddleware(ctx, next) {
|
|
11
|
-
var _a;
|
|
12
11
|
const $ctx = ctx.request.$ctx;
|
|
13
12
|
await next();
|
|
14
13
|
const status = ctx.status || 404;
|
|
15
14
|
if (status === 404 && !$ctx.isDone()) {
|
|
16
|
-
|
|
15
|
+
$ctx.injector.get(platform_exceptions_1.PlatformExceptions)?.resourceNotFound($ctx);
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
18
|
exports.resourceNotFoundMiddleware = resourceNotFoundMiddleware;
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAqB,wCAAkB,CAAC,EAAE,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"]}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _PlatformKoaRequest_ctx;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.PlatformKoaRequest = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
4
|
require("@koa/router");
|
|
7
5
|
const common_1 = require("@tsed/common");
|
|
8
6
|
/**
|
|
@@ -10,35 +8,27 @@ const common_1 = require("@tsed/common");
|
|
|
10
8
|
* @koa
|
|
11
9
|
*/
|
|
12
10
|
class PlatformKoaRequest extends common_1.PlatformRequest {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
_PlatformKoaRequest_ctx.set(this, void 0);
|
|
16
|
-
tslib_1.__classPrivateFieldSet(this, _PlatformKoaRequest_ctx, this.raw.ctx, "f");
|
|
11
|
+
get ctx() {
|
|
12
|
+
return this.raw.ctx;
|
|
17
13
|
}
|
|
18
14
|
get protocol() {
|
|
19
|
-
return
|
|
15
|
+
return this.ctx.request.protocol;
|
|
20
16
|
}
|
|
21
17
|
get host() {
|
|
22
|
-
return
|
|
18
|
+
return this.ctx.request.host;
|
|
23
19
|
}
|
|
24
20
|
get secure() {
|
|
25
|
-
return
|
|
21
|
+
return this.ctx.request.secure;
|
|
26
22
|
}
|
|
27
23
|
get cookies() {
|
|
28
|
-
return
|
|
24
|
+
return this.ctx.cookie || this.ctx.cookies;
|
|
29
25
|
}
|
|
30
26
|
get session() {
|
|
31
|
-
return
|
|
27
|
+
return this.ctx.session;
|
|
32
28
|
}
|
|
33
29
|
getReq() {
|
|
34
|
-
return this.
|
|
35
|
-
}
|
|
36
|
-
destroy() {
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
tslib_1.__classPrivateFieldSet(this, _PlatformKoaRequest_ctx, null, "f");
|
|
39
|
-
return super.destroy();
|
|
30
|
+
return this.ctx.request.req;
|
|
40
31
|
}
|
|
41
32
|
}
|
|
42
33
|
exports.PlatformKoaRequest = PlatformKoaRequest;
|
|
43
|
-
_PlatformKoaRequest_ctx = new WeakMap();
|
|
44
34
|
//# sourceMappingURL=PlatformKoaRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":";;;AAAA,uBAAqB;AACrB,yCAA8D;AAgB9D;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,wBAA4B;IAClE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;IACnC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC7C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;IAC9B,CAAC;CACF;AA5BD,gDA4BC","sourcesContent":["import \"@koa/router\";\nimport {PlatformContext, PlatformRequest} from \"@tsed/common\";\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 get ctx(): Koa.Context {\n return 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() {\n return this.ctx.request.req;\n }\n}\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _PlatformKoaResponse_ctx;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.PlatformKoaResponse = void 0;
|
|
5
4
|
const tslib_1 = require("tslib");
|
|
@@ -11,16 +10,14 @@ const encodeurl_1 = tslib_1.__importDefault(require("encodeurl"));
|
|
|
11
10
|
* @koa
|
|
12
11
|
*/
|
|
13
12
|
class PlatformKoaResponse extends common_1.PlatformResponse {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
_PlatformKoaResponse_ctx.set(this, void 0);
|
|
17
|
-
tslib_1.__classPrivateFieldSet(this, _PlatformKoaResponse_ctx, this.raw.ctx, "f");
|
|
13
|
+
get ctx() {
|
|
14
|
+
return this.raw.ctx;
|
|
18
15
|
}
|
|
19
16
|
get statusCode() {
|
|
20
17
|
return this.raw.status;
|
|
21
18
|
}
|
|
22
19
|
get locals() {
|
|
23
|
-
return
|
|
20
|
+
return this.ctx.state;
|
|
24
21
|
}
|
|
25
22
|
/**
|
|
26
23
|
* Return the Node.js response object
|
|
@@ -101,5 +98,4 @@ class PlatformKoaResponse extends common_1.PlatformResponse {
|
|
|
101
98
|
}
|
|
102
99
|
}
|
|
103
100
|
exports.PlatformKoaResponse = PlatformKoaResponse;
|
|
104
|
-
_PlatformKoaResponse_ctx = new WeakMap();
|
|
105
101
|
//# sourceMappingURL=PlatformKoaResponse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":";;;;AAAA,yCAA8E;AAG9E,yCAA8C;AAC9C,kEAAkC;AAQlC;;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AM,CAAC,oBAAoB,GAAG,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpB,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,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;AAzGD,kDAyGC","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 get ctx() {\n return 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"]}
|
|
@@ -3,15 +3,15 @@ import { createContext, PlatformApplication, PlatformBuilder, PlatformHandler, P
|
|
|
3
3
|
import { PlatformExceptions } from "@tsed/platform-exceptions";
|
|
4
4
|
import { isFunction } from "@tsed/core";
|
|
5
5
|
import Koa from "koa";
|
|
6
|
+
import koaBodyParser from "koa-bodyparser";
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import koaQs from "koa-qs";
|
|
6
9
|
import { resourceNotFoundMiddleware } from "../middlewares/resourceNotFoundMiddleware.js";
|
|
7
|
-
import {
|
|
8
|
-
import { PlatformKoaRequest } from "../services/PlatformKoaRequest.js";
|
|
10
|
+
import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
|
|
9
11
|
import { PlatformKoaHandler } from "../services/PlatformKoaHandler.js";
|
|
12
|
+
import { PlatformKoaRequest } from "../services/PlatformKoaRequest.js";
|
|
13
|
+
import { PlatformKoaResponse } from "../services/PlatformKoaResponse.js";
|
|
10
14
|
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
15
|
// @ts-ignore
|
|
16
16
|
KoaRouter.prototype.$$match = KoaRouter.prototype.match;
|
|
17
17
|
KoaRouter.prototype.match = function match(...args) {
|
|
@@ -28,22 +28,23 @@ KoaRouter.prototype.match = function match(...args) {
|
|
|
28
28
|
* @koa
|
|
29
29
|
*/
|
|
30
30
|
export class PlatformKoa {
|
|
31
|
+
injector;
|
|
32
|
+
providers = [
|
|
33
|
+
{
|
|
34
|
+
provide: PlatformResponse,
|
|
35
|
+
useClass: PlatformKoaResponse
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
provide: PlatformRequest,
|
|
39
|
+
useClass: PlatformKoaRequest
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
provide: PlatformHandler,
|
|
43
|
+
useClass: PlatformKoaHandler
|
|
44
|
+
}
|
|
45
|
+
];
|
|
31
46
|
constructor(injector) {
|
|
32
47
|
this.injector = injector;
|
|
33
|
-
this.providers = [
|
|
34
|
-
{
|
|
35
|
-
provide: PlatformResponse,
|
|
36
|
-
useClass: PlatformKoaResponse
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
provide: PlatformRequest,
|
|
40
|
-
useClass: PlatformKoaRequest
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
provide: PlatformHandler,
|
|
44
|
-
useClass: PlatformKoaHandler
|
|
45
|
-
}
|
|
46
|
-
];
|
|
47
48
|
}
|
|
48
49
|
/**
|
|
49
50
|
* Create new serverless application. In this mode, the component scan are disabled.
|
|
@@ -71,8 +72,7 @@ export class PlatformKoa {
|
|
|
71
72
|
const injector = this.injector;
|
|
72
73
|
const app = this.injector.get(PlatformApplication);
|
|
73
74
|
const listener = (error, ctx) => {
|
|
74
|
-
|
|
75
|
-
(_a = injector.get(PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(error, ctx.request.$ctx);
|
|
75
|
+
injector.get(PlatformExceptions)?.catch(error, ctx.request.$ctx);
|
|
76
76
|
};
|
|
77
77
|
app.getApp().silent = true;
|
|
78
78
|
app.getApp().on("error", listener);
|
|
@@ -91,8 +91,7 @@ export class PlatformKoa {
|
|
|
91
91
|
app.getApp().use(async (ctx, next) => {
|
|
92
92
|
await invoke({
|
|
93
93
|
request: ctx.request,
|
|
94
|
-
response: ctx.response
|
|
95
|
-
ctx
|
|
94
|
+
response: ctx.response
|
|
96
95
|
});
|
|
97
96
|
return next();
|
|
98
97
|
});
|
|
@@ -109,9 +108,8 @@ export class PlatformKoa {
|
|
|
109
108
|
};
|
|
110
109
|
}
|
|
111
110
|
router(routerOptions = {}) {
|
|
112
|
-
var _a;
|
|
113
111
|
const { settings } = this.injector;
|
|
114
|
-
const options = Object.assign({},
|
|
112
|
+
const options = Object.assign({}, settings.get("koa.router", {}), routerOptions);
|
|
115
113
|
const router = new KoaRouter(options);
|
|
116
114
|
return {
|
|
117
115
|
router,
|
|
@@ -1 +1 @@
|
|
|
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,eAAe,EAGf,eAAe,EACf,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAA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,EAAE,CAAC;YACxB,CAAC;SACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,gBAAqB,EAAE;QAC5B,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;QAEjC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC;QACjF,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,OAAO,CAAQ,CAAC;QAE7C,OAAO;YACL,MAAM;YACN,QAAQ;gBACN,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;YACpD,CAAC;SACF,CAAC;IACJ,CAAC;IAED,SAAS,CAAC,OAA+B;QACvC,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,CAAC,QAAgB,EAAE,OAA+B;QACvD,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,UAAU,CAAC,IAA4C,EAAE,oBAAyB,EAAE;QAClF,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC1D,IAAI,MAAM,GAAQ,aAAa,CAAC;QAEhC,IAAI,OAAO,GAAY,EAAE,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 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 koaBodyParser, {Options} from \"koa-bodyparser\";\n// @ts-ignore\nimport koaQs from \"koa-qs\";\nimport send from \"koa-send\";\nimport {resourceNotFoundMiddleware} from \"../middlewares/resourceNotFoundMiddleware\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {PlatformKoaHandler} from \"../services/PlatformKoaHandler\";\nimport {PlatformKoaRequest} from \"../services/PlatformKoaRequest\";\nimport {PlatformKoaResponse} from \"../services/PlatformKoaResponse\";\nimport {getMulter} from \"../utils/multer\";\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 });\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.get(\"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"]}
|
|
@@ -1 +1 @@
|
|
|
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
|
+
{"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"]}
|
|
@@ -5,12 +5,11 @@ import { PlatformExceptions } from "@tsed/platform-exceptions";
|
|
|
5
5
|
* @param next
|
|
6
6
|
*/
|
|
7
7
|
export async function resourceNotFoundMiddleware(ctx, next) {
|
|
8
|
-
var _a;
|
|
9
8
|
const $ctx = ctx.request.$ctx;
|
|
10
9
|
await next();
|
|
11
10
|
const status = ctx.status || 404;
|
|
12
11
|
if (status === 404 && !$ctx.isDone()) {
|
|
13
|
-
|
|
12
|
+
$ctx.injector.get(PlatformExceptions)?.resourceNotFound($ctx);
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
15
|
//# sourceMappingURL=resourceNotFoundMiddleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resourceNotFoundMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/resourceNotFoundMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,GAAQ,EAAE,IAAS
|
|
1
|
+
{"version":3,"file":"resourceNotFoundMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/resourceNotFoundMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,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,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAqB,kBAAkB,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;KACnF;AACH,CAAC","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"]}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _PlatformKoaRequest_ctx;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import "@koa/router";
|
|
4
2
|
import { PlatformRequest } from "@tsed/common";
|
|
5
3
|
/**
|
|
@@ -7,34 +5,26 @@ import { PlatformRequest } from "@tsed/common";
|
|
|
7
5
|
* @koa
|
|
8
6
|
*/
|
|
9
7
|
export class PlatformKoaRequest extends PlatformRequest {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
_PlatformKoaRequest_ctx.set(this, void 0);
|
|
13
|
-
__classPrivateFieldSet(this, _PlatformKoaRequest_ctx, this.raw.ctx, "f");
|
|
8
|
+
get ctx() {
|
|
9
|
+
return this.raw.ctx;
|
|
14
10
|
}
|
|
15
11
|
get protocol() {
|
|
16
|
-
return
|
|
12
|
+
return this.ctx.request.protocol;
|
|
17
13
|
}
|
|
18
14
|
get host() {
|
|
19
|
-
return
|
|
15
|
+
return this.ctx.request.host;
|
|
20
16
|
}
|
|
21
17
|
get secure() {
|
|
22
|
-
return
|
|
18
|
+
return this.ctx.request.secure;
|
|
23
19
|
}
|
|
24
20
|
get cookies() {
|
|
25
|
-
return
|
|
21
|
+
return this.ctx.cookie || this.ctx.cookies;
|
|
26
22
|
}
|
|
27
23
|
get session() {
|
|
28
|
-
return
|
|
24
|
+
return this.ctx.session;
|
|
29
25
|
}
|
|
30
26
|
getReq() {
|
|
31
|
-
return this.
|
|
32
|
-
}
|
|
33
|
-
destroy() {
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
__classPrivateFieldSet(this, _PlatformKoaRequest_ctx, null, "f");
|
|
36
|
-
return super.destroy();
|
|
27
|
+
return this.ctx.request.req;
|
|
37
28
|
}
|
|
38
29
|
}
|
|
39
|
-
_PlatformKoaRequest_ctx = new WeakMap();
|
|
40
30
|
//# sourceMappingURL=PlatformKoaRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AACrB,OAAO,EAAkB,eAAe,EAAC,MAAM,cAAc,CAAC;AAgB9D;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,eAA4B;IAClE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;IACnC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC7C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import \"@koa/router\";\nimport {PlatformContext, PlatformRequest} from \"@tsed/common\";\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 get ctx(): Koa.Context {\n return 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() {\n return this.ctx.request.req;\n }\n}\n"]}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _PlatformKoaResponse_ctx;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import { PlatformResponse } from "@tsed/common";
|
|
4
2
|
import { getStatusMessage } from "@tsed/schema";
|
|
5
3
|
import encodeUrl from "encodeurl";
|
|
@@ -8,16 +6,14 @@ import encodeUrl from "encodeurl";
|
|
|
8
6
|
* @koa
|
|
9
7
|
*/
|
|
10
8
|
export class PlatformKoaResponse extends PlatformResponse {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
_PlatformKoaResponse_ctx.set(this, void 0);
|
|
14
|
-
__classPrivateFieldSet(this, _PlatformKoaResponse_ctx, this.raw.ctx, "f");
|
|
9
|
+
get ctx() {
|
|
10
|
+
return this.raw.ctx;
|
|
15
11
|
}
|
|
16
12
|
get statusCode() {
|
|
17
13
|
return this.raw.status;
|
|
18
14
|
}
|
|
19
15
|
get locals() {
|
|
20
|
-
return
|
|
16
|
+
return this.ctx.state;
|
|
21
17
|
}
|
|
22
18
|
/**
|
|
23
19
|
* Return the Node.js response object
|
|
@@ -97,5 +93,4 @@ export class PlatformKoaResponse extends PlatformResponse {
|
|
|
97
93
|
return this;
|
|
98
94
|
}
|
|
99
95
|
}
|
|
100
|
-
_PlatformKoaResponse_ctx = new WeakMap();
|
|
101
96
|
//# sourceMappingURL=PlatformKoaResponse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAG9E,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,SAAS,MAAM,WAAW,CAAC;AAQlC;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,gBAA8B;IACrE,IAAI,G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AAM,CAAC,MAAM,CAAC,CAAC;QACpB,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,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,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE9C,OAAO,IAAI,CAAC;IACd,CAAC;CACF","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 get ctx() {\n return 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"]}
|
|
@@ -3,10 +3,10 @@ import KoaRouter, { RouterOptions as KoaRouterOptions } from "@koa/router";
|
|
|
3
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
|
-
import { PlatformKoaResponse } from "../services/PlatformKoaResponse";
|
|
7
|
-
import { PlatformKoaRequest } from "../services/PlatformKoaRequest";
|
|
8
|
-
import { PlatformKoaHandler } from "../services/PlatformKoaHandler";
|
|
9
6
|
import send from "koa-send";
|
|
7
|
+
import { PlatformKoaHandler } from "../services/PlatformKoaHandler";
|
|
8
|
+
import { PlatformKoaRequest } from "../services/PlatformKoaRequest";
|
|
9
|
+
import { PlatformKoaResponse } from "../services/PlatformKoaResponse";
|
|
10
10
|
declare global {
|
|
11
11
|
namespace TsED {
|
|
12
12
|
interface Application extends Koa {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import "@koa/router";
|
|
3
|
-
import {
|
|
4
|
-
import { IncomingMessage } from "http";
|
|
3
|
+
import { PlatformContext, PlatformRequest } from "@tsed/common";
|
|
5
4
|
import Koa from "koa";
|
|
6
5
|
declare module "koa" {
|
|
7
6
|
interface Request {
|
|
@@ -20,8 +19,7 @@ declare global {
|
|
|
20
19
|
* @koa
|
|
21
20
|
*/
|
|
22
21
|
export declare class PlatformKoaRequest extends PlatformRequest<Koa.Request> {
|
|
23
|
-
|
|
24
|
-
constructor(event: IncomingEvent, $ctx: PlatformContext);
|
|
22
|
+
get ctx(): Koa.Context;
|
|
25
23
|
get protocol(): string;
|
|
26
24
|
get host(): string;
|
|
27
25
|
get secure(): boolean;
|
|
@@ -29,6 +27,5 @@ export declare class PlatformKoaRequest extends PlatformRequest<Koa.Request> {
|
|
|
29
27
|
[p: string]: any;
|
|
30
28
|
};
|
|
31
29
|
get session(): any;
|
|
32
|
-
getReq(): IncomingMessage;
|
|
33
|
-
destroy(): void;
|
|
30
|
+
getReq(): import("http").IncomingMessage;
|
|
34
31
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { PlatformResponse } from "@tsed/common";
|
|
3
3
|
import { ServerResponse } from "http";
|
|
4
4
|
import Koa from "koa";
|
|
5
5
|
declare global {
|
|
@@ -13,8 +13,7 @@ declare global {
|
|
|
13
13
|
* @koa
|
|
14
14
|
*/
|
|
15
15
|
export declare class PlatformKoaResponse extends PlatformResponse<Koa.Response> {
|
|
16
|
-
|
|
17
|
-
constructor(event: IncomingEvent, $ctx: PlatformContext);
|
|
16
|
+
get ctx(): Koa.Context;
|
|
18
17
|
get statusCode(): number;
|
|
19
18
|
get locals(): Koa.DefaultState;
|
|
20
19
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-koa",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.13",
|
|
4
4
|
"description": "Koa package for Ts.ED framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
19
19
|
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
20
20
|
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
|
|
21
|
-
"start": "ts-node -r tsconfig-paths/register test/app/index.ts"
|
|
21
|
+
"start": "ts-node -r tsconfig-paths/register test/app/index.ts",
|
|
22
|
+
"test": "cross-env NODE_ENV=test yarn jest --max-workers=2 --testTimeout 10000"
|
|
22
23
|
},
|
|
23
24
|
"keywords": [
|
|
24
25
|
"Koa",
|
|
@@ -51,10 +52,10 @@
|
|
|
51
52
|
"repository": "https://github.com/tsedio/tsed",
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@koa/cors": "3.3.0",
|
|
54
|
-
"@tsed/common": "7.0.0-beta.
|
|
55
|
-
"@tsed/core": "7.0.0-beta.
|
|
56
|
-
"@tsed/di": "7.0.0-beta.
|
|
57
|
-
"@tsed/platform-test-utils": "7.0.0-beta.
|
|
55
|
+
"@tsed/common": "7.0.0-beta.13",
|
|
56
|
+
"@tsed/core": "7.0.0-beta.13",
|
|
57
|
+
"@tsed/di": "7.0.0-beta.13",
|
|
58
|
+
"@tsed/platform-test-utils": "7.0.0-beta.13",
|
|
58
59
|
"@types/koa": "2.13.4",
|
|
59
60
|
"@types/koa-bodyparser": "4.3.7",
|
|
60
61
|
"@types/koa-compose": "3.2.5",
|
|
@@ -75,23 +76,24 @@
|
|
|
75
76
|
"@koa/router": "^10.1.1",
|
|
76
77
|
"encodeurl": "^1.0.2",
|
|
77
78
|
"koa-send": "5.0.1",
|
|
78
|
-
"multer": "^1.4.
|
|
79
|
-
"tslib": "2.
|
|
79
|
+
"multer": "^1.4.5-lts.1",
|
|
80
|
+
"tslib": "2.4.0"
|
|
80
81
|
},
|
|
81
82
|
"peerDependencies": {
|
|
82
|
-
"@tsed/common": "^7.0.0-beta.
|
|
83
|
-
"@tsed/core": "^7.0.0-beta.
|
|
84
|
-
"@tsed/di": "^7.0.0-beta.
|
|
85
|
-
"@tsed/json-mapper": "^7.0.0-beta.
|
|
86
|
-
"@tsed/logger": ">=6.
|
|
87
|
-
"@tsed/openspec": "^7.0.0-beta.
|
|
88
|
-
"@tsed/schema": "^7.0.0-beta.
|
|
83
|
+
"@tsed/common": "^7.0.0-beta.13",
|
|
84
|
+
"@tsed/core": "^7.0.0-beta.13",
|
|
85
|
+
"@tsed/di": "^7.0.0-beta.13",
|
|
86
|
+
"@tsed/json-mapper": "^7.0.0-beta.13",
|
|
87
|
+
"@tsed/logger": ">=6.2.0",
|
|
88
|
+
"@tsed/openspec": "^7.0.0-beta.13",
|
|
89
|
+
"@tsed/schema": "^7.0.0-beta.13",
|
|
89
90
|
"koa": ">=2.13.0",
|
|
90
91
|
"koa-bodyparser": ">=4.3.0",
|
|
91
92
|
"koa-compress": ">=5.0.1",
|
|
92
93
|
"koa-override": ">=3.0.0",
|
|
93
94
|
"koa-qs": ">=3.0.0",
|
|
94
|
-
"koa-session": ">=6.2.0"
|
|
95
|
+
"koa-session": ">=6.2.0",
|
|
96
|
+
"multer": "^1.4.5-lts.1"
|
|
95
97
|
},
|
|
96
98
|
"peerDependenciesMeta": {
|
|
97
99
|
"@tsed/common": {
|
|
@@ -114,6 +116,12 @@
|
|
|
114
116
|
},
|
|
115
117
|
"@tsed/logger": {
|
|
116
118
|
"optional": false
|
|
119
|
+
},
|
|
120
|
+
"multer": {
|
|
121
|
+
"optional": false
|
|
117
122
|
}
|
|
123
|
+
},
|
|
124
|
+
"publishConfig": {
|
|
125
|
+
"tag": "beta"
|
|
118
126
|
}
|
|
119
127
|
}
|
package/readme.md
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
[](https://badge.fury.io/js/%40tsed%2Fcommon)
|
|
12
12
|
[](https://github.com/semantic-release/semantic-release)
|
|
13
13
|
[](https://github.com/prettier/prettier)
|
|
14
|
-
[](https://github.com/sponsors/romakita)
|
|
15
|
+
[](https://opencollective.com/tsed)
|
|
15
16
|
|
|
16
17
|
</div>
|
|
17
18
|
|