@tsed/platform-koa 6.89.0 → 6.90.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.
- package/lib/cjs/components/PlatformKoa.d.ts +15 -8
- package/lib/cjs/components/PlatformKoa.js +51 -40
- package/lib/cjs/components/PlatformKoa.js.map +1 -1
- package/lib/cjs/index.js +2 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/components/PlatformKoa.js +51 -40
- package/lib/esm/components/PlatformKoa.js.map +1 -1
- package/lib/esm/index.js +2 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/types/components/PlatformKoa.d.ts +15 -8
- package/package.json +11 -11
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="koa__router" />
|
|
2
2
|
import KoaRouter from "@koa/router";
|
|
3
|
-
import { PlatformApplication, PlatformBuilder,
|
|
3
|
+
import { PlatformAdapter, PlatformApplication, PlatformBuilder, PlatformHandler, PlatformRequest, PlatformResponse, PlatformRouter } from "@tsed/common";
|
|
4
4
|
import { Type } from "@tsed/core";
|
|
5
5
|
import Koa from "koa";
|
|
6
6
|
import { PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, PlatformKoaResponse, PlatformKoaRouter } from "../services";
|
|
@@ -8,8 +8,9 @@ import { PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, Platfor
|
|
|
8
8
|
* @platform
|
|
9
9
|
* @koa
|
|
10
10
|
*/
|
|
11
|
-
export declare class PlatformKoa
|
|
12
|
-
|
|
11
|
+
export declare class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {
|
|
12
|
+
private platform;
|
|
13
|
+
readonly providers: ({
|
|
13
14
|
provide: typeof PlatformResponse;
|
|
14
15
|
useClass: typeof PlatformKoaResponse;
|
|
15
16
|
} | {
|
|
@@ -25,14 +26,20 @@ export declare class PlatformKoa extends PlatformBuilder<Koa, KoaRouter> {
|
|
|
25
26
|
provide: typeof PlatformApplication;
|
|
26
27
|
useClass: typeof PlatformKoaApplication;
|
|
27
28
|
})[];
|
|
28
|
-
constructor(
|
|
29
|
+
constructor(platform: PlatformBuilder<Koa, KoaRouter>);
|
|
29
30
|
/**
|
|
30
31
|
* Create new serverless application. In this mode, the component scan are disabled.
|
|
31
32
|
* @param module
|
|
32
33
|
* @param settings
|
|
33
34
|
*/
|
|
34
|
-
static create(module: Type<any>, settings?: Partial<TsED.Configuration>):
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
static create(module: Type<any>, settings?: Partial<TsED.Configuration>): PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext>, KoaRouter<any, {}>>;
|
|
36
|
+
/**
|
|
37
|
+
* Bootstrap a server application
|
|
38
|
+
* @param module
|
|
39
|
+
* @param settings
|
|
40
|
+
*/
|
|
41
|
+
static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext>, KoaRouter<any, {}>>>;
|
|
42
|
+
onInit(): void;
|
|
43
|
+
useRouter(): this;
|
|
44
|
+
useContext(): this;
|
|
38
45
|
}
|
|
@@ -8,15 +8,31 @@ const services_1 = require("../services");
|
|
|
8
8
|
* @platform
|
|
9
9
|
* @koa
|
|
10
10
|
*/
|
|
11
|
-
class PlatformKoa
|
|
12
|
-
constructor(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
class PlatformKoa {
|
|
12
|
+
constructor(platform) {
|
|
13
|
+
this.platform = platform;
|
|
14
|
+
this.providers = [
|
|
15
|
+
{
|
|
16
|
+
provide: common_1.PlatformResponse,
|
|
17
|
+
useClass: services_1.PlatformKoaResponse
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
provide: common_1.PlatformRequest,
|
|
21
|
+
useClass: services_1.PlatformKoaRequest
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
provide: common_1.PlatformHandler,
|
|
25
|
+
useClass: services_1.PlatformKoaHandler
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
provide: common_1.PlatformRouter,
|
|
29
|
+
useClass: services_1.PlatformKoaRouter
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
provide: common_1.PlatformApplication,
|
|
33
|
+
useClass: services_1.PlatformKoaApplication
|
|
34
|
+
}
|
|
35
|
+
];
|
|
20
36
|
}
|
|
21
37
|
/**
|
|
22
38
|
* Create new serverless application. In this mode, the component scan are disabled.
|
|
@@ -24,24 +40,41 @@ class PlatformKoa extends common_1.PlatformBuilder {
|
|
|
24
40
|
* @param settings
|
|
25
41
|
*/
|
|
26
42
|
static create(module, settings = {}) {
|
|
27
|
-
return
|
|
28
|
-
httpsPort: false,
|
|
29
|
-
httpPort: false,
|
|
43
|
+
return common_1.PlatformBuilder.create(module, {
|
|
30
44
|
...settings,
|
|
31
|
-
|
|
45
|
+
adapter: PlatformKoa
|
|
32
46
|
});
|
|
33
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Bootstrap a server application
|
|
50
|
+
* @param module
|
|
51
|
+
* @param settings
|
|
52
|
+
*/
|
|
34
53
|
static async bootstrap(module, settings = {}) {
|
|
35
|
-
return
|
|
54
|
+
return common_1.PlatformBuilder.bootstrap(module, {
|
|
55
|
+
...settings,
|
|
56
|
+
adapter: PlatformKoa
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
onInit() {
|
|
60
|
+
const { injector, app } = this.platform;
|
|
61
|
+
const listener = (error, ctx) => {
|
|
62
|
+
var _a;
|
|
63
|
+
(_a = injector.get(common_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(error, ctx.request.$ctx);
|
|
64
|
+
};
|
|
65
|
+
app.getApp().silent = true;
|
|
66
|
+
app.getApp().on("error", listener);
|
|
36
67
|
}
|
|
37
68
|
useRouter() {
|
|
38
|
-
|
|
69
|
+
const { app } = this.platform;
|
|
70
|
+
app.getApp().use(resourceNotFoundMiddleware_1.resourceNotFoundMiddleware).use(app.getRouter().routes()).use(app.getRouter().allowedMethods());
|
|
39
71
|
return this;
|
|
40
72
|
}
|
|
41
73
|
useContext() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
74
|
+
const { injector, app, logger } = this.platform;
|
|
75
|
+
logger.info("Mount app context");
|
|
76
|
+
const invoke = (0, common_1.createContext)(injector);
|
|
77
|
+
app.getApp().use(async (ctx, next) => {
|
|
45
78
|
await invoke({
|
|
46
79
|
request: ctx.request,
|
|
47
80
|
response: ctx.response,
|
|
@@ -53,26 +86,4 @@ class PlatformKoa extends common_1.PlatformBuilder {
|
|
|
53
86
|
}
|
|
54
87
|
}
|
|
55
88
|
exports.PlatformKoa = PlatformKoa;
|
|
56
|
-
PlatformKoa.providers = [
|
|
57
|
-
{
|
|
58
|
-
provide: common_1.PlatformResponse,
|
|
59
|
-
useClass: services_1.PlatformKoaResponse
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
provide: common_1.PlatformRequest,
|
|
63
|
-
useClass: services_1.PlatformKoaRequest
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
provide: common_1.PlatformHandler,
|
|
67
|
-
useClass: services_1.PlatformKoaHandler
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
provide: common_1.PlatformRouter,
|
|
71
|
-
useClass: services_1.PlatformKoaRouter
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
provide: common_1.PlatformApplication,
|
|
75
|
-
useClass: services_1.PlatformKoaApplication
|
|
76
|
-
}
|
|
77
|
-
];
|
|
78
89
|
//# sourceMappingURL=PlatformKoa.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;AACA,yCAUsB;AAGtB,0FAAqF;AACrF,0CAAmI;AAEnI;;;GAGG;AACH,MAAa,
|
|
1
|
+
{"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,OAAO,CAAC,IAAI,CAAC,CAAC;QACvF,CAAC,CAAC;QAEF,GAAG,CAAC,MAAM,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC;QAC3B,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IAED,SAAS;QACP,MAAM,EAAC,GAAG,EAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC5B,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,uDAA0B,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;QAEjH,OAAO,IAAI,CAAC;IACd,CAAC;IAED,UAAU;QACR,MAAM,EAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9C,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAEjC,MAAM,MAAM,GAAG,IAAA,sBAAa,EAAC,QAAQ,CAAC,CAAC;QAEvC,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,GAAY,EAAE,IAAU,EAAE,EAAE;YAClD,MAAM,MAAM,CAAC;gBACX,OAAO,EAAE,GAAG,CAAC,OAAc;gBAC3B,QAAQ,EAAE,GAAG,CAAC,QAAe;gBAC7B,GAAG;aACJ,CAAC,CAAC;YAEH,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAtFD,kCAsFC","sourcesContent":["import KoaRouter from \"@koa/router\";\nimport {\n createContext,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformExceptions,\n PlatformHandler,\n PlatformRequest,\n PlatformResponse,\n PlatformRouter\n} from \"@tsed/common\";\nimport {Type} from \"@tsed/core\";\nimport Koa, {Context, Next} from \"koa\";\nimport {resourceNotFoundMiddleware} from \"../middlewares/resourceNotFoundMiddleware\";\nimport {PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, PlatformKoaResponse, PlatformKoaRouter} from \"../services\";\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {\n readonly providers = [\n {\n provide: PlatformResponse,\n useClass: PlatformKoaResponse\n },\n {\n provide: PlatformRequest,\n useClass: PlatformKoaRequest\n },\n {\n provide: PlatformHandler,\n useClass: PlatformKoaHandler\n },\n {\n provide: PlatformRouter,\n useClass: PlatformKoaRouter\n },\n {\n provide: PlatformApplication,\n useClass: PlatformKoaApplication\n }\n ];\n\n constructor(private platform: PlatformBuilder<Koa, KoaRouter>) {}\n\n /**\n * Create new serverless application. In this mode, the component scan are disabled.\n * @param module\n * @param settings\n */\n static create(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.create<Koa, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.bootstrap<Koa, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n onInit() {\n const {injector, app} = this.platform;\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, ctx.request.$ctx);\n };\n\n app.getApp().silent = true;\n app.getApp().on(\"error\", listener);\n }\n\n useRouter(): this {\n const {app} = this.platform;\n app.getApp().use(resourceNotFoundMiddleware).use(app.getRouter().routes()).use(app.getRouter().allowedMethods());\n\n return this;\n }\n\n useContext(): this {\n const {injector, app, logger} = this.platform;\n logger.info(\"Mount app context\");\n\n const invoke = createContext(injector);\n\n app.getApp().use(async (ctx: Context, next: Next) => {\n await invoke({\n request: ctx.request as any,\n response: ctx.response as any,\n ctx\n });\n\n return next();\n });\n\n return this;\n }\n}\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const common_1 = require("@tsed/common");
|
|
5
5
|
const PlatformKoa_1 = require("./components/PlatformKoa");
|
|
6
|
-
common_1.PlatformTest.
|
|
7
|
-
common_1.PlatformBuilder.
|
|
6
|
+
common_1.PlatformTest.adapter = PlatformKoa_1.PlatformKoa;
|
|
7
|
+
common_1.PlatformBuilder.adapter = PlatformKoa_1.PlatformKoa;
|
|
8
8
|
// interfaces
|
|
9
9
|
(0, tslib_1.__exportStar)(require("./interfaces"), exports);
|
|
10
10
|
// decorators
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA2D;AAC3D,0DAAqD;AAErD,qBAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA2D;AAC3D,0DAAqD;AAErD,qBAAY,CAAC,OAAO,GAAG,yBAAW,CAAC;AACnC,wBAAe,CAAC,OAAO,GAAG,yBAAW,CAAC;AAEtC,aAAa;AACb,4DAA6B;AAE7B,aAAa;AACb,4DAA6B;AAE7B,WAAW;AACX,0DAA2B;AAE3B,aAAa;AACb,wEAAyC","sourcesContent":["import {PlatformBuilder, PlatformTest} from \"@tsed/common\";\nimport {PlatformKoa} from \"./components/PlatformKoa\";\n\nPlatformTest.adapter = PlatformKoa;\nPlatformBuilder.adapter = PlatformKoa;\n\n// interfaces\nexport * from \"./interfaces\";\n\n// decorators\nexport * from \"./decorators\";\n\n// services\nexport * from \"./services\";\n\n// components\nexport * from \"./components/PlatformKoa\";\n"]}
|
|
@@ -5,15 +5,31 @@ import { PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, Platfor
|
|
|
5
5
|
* @platform
|
|
6
6
|
* @koa
|
|
7
7
|
*/
|
|
8
|
-
export class PlatformKoa
|
|
9
|
-
constructor(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
export class PlatformKoa {
|
|
9
|
+
constructor(platform) {
|
|
10
|
+
this.platform = platform;
|
|
11
|
+
this.providers = [
|
|
12
|
+
{
|
|
13
|
+
provide: PlatformResponse,
|
|
14
|
+
useClass: PlatformKoaResponse
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
provide: PlatformRequest,
|
|
18
|
+
useClass: PlatformKoaRequest
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
provide: PlatformHandler,
|
|
22
|
+
useClass: PlatformKoaHandler
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
provide: PlatformRouter,
|
|
26
|
+
useClass: PlatformKoaRouter
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
provide: PlatformApplication,
|
|
30
|
+
useClass: PlatformKoaApplication
|
|
31
|
+
}
|
|
32
|
+
];
|
|
17
33
|
}
|
|
18
34
|
/**
|
|
19
35
|
* Create new serverless application. In this mode, the component scan are disabled.
|
|
@@ -21,24 +37,41 @@ export class PlatformKoa extends PlatformBuilder {
|
|
|
21
37
|
* @param settings
|
|
22
38
|
*/
|
|
23
39
|
static create(module, settings = {}) {
|
|
24
|
-
return
|
|
25
|
-
httpsPort: false,
|
|
26
|
-
httpPort: false,
|
|
40
|
+
return PlatformBuilder.create(module, {
|
|
27
41
|
...settings,
|
|
28
|
-
|
|
42
|
+
adapter: PlatformKoa
|
|
29
43
|
});
|
|
30
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Bootstrap a server application
|
|
47
|
+
* @param module
|
|
48
|
+
* @param settings
|
|
49
|
+
*/
|
|
31
50
|
static async bootstrap(module, settings = {}) {
|
|
32
|
-
return
|
|
51
|
+
return PlatformBuilder.bootstrap(module, {
|
|
52
|
+
...settings,
|
|
53
|
+
adapter: PlatformKoa
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
onInit() {
|
|
57
|
+
const { injector, app } = this.platform;
|
|
58
|
+
const listener = (error, ctx) => {
|
|
59
|
+
var _a;
|
|
60
|
+
(_a = injector.get(PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(error, ctx.request.$ctx);
|
|
61
|
+
};
|
|
62
|
+
app.getApp().silent = true;
|
|
63
|
+
app.getApp().on("error", listener);
|
|
33
64
|
}
|
|
34
65
|
useRouter() {
|
|
35
|
-
|
|
66
|
+
const { app } = this.platform;
|
|
67
|
+
app.getApp().use(resourceNotFoundMiddleware).use(app.getRouter().routes()).use(app.getRouter().allowedMethods());
|
|
36
68
|
return this;
|
|
37
69
|
}
|
|
38
70
|
useContext() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
71
|
+
const { injector, app, logger } = this.platform;
|
|
72
|
+
logger.info("Mount app context");
|
|
73
|
+
const invoke = createContext(injector);
|
|
74
|
+
app.getApp().use(async (ctx, next) => {
|
|
42
75
|
await invoke({
|
|
43
76
|
request: ctx.request,
|
|
44
77
|
response: ctx.response,
|
|
@@ -49,26 +82,4 @@ export class PlatformKoa extends PlatformBuilder {
|
|
|
49
82
|
return this;
|
|
50
83
|
}
|
|
51
84
|
}
|
|
52
|
-
PlatformKoa.providers = [
|
|
53
|
-
{
|
|
54
|
-
provide: PlatformResponse,
|
|
55
|
-
useClass: PlatformKoaResponse
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
provide: PlatformRequest,
|
|
59
|
-
useClass: PlatformKoaRequest
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
provide: PlatformHandler,
|
|
63
|
-
useClass: PlatformKoaHandler
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
provide: PlatformRouter,
|
|
67
|
-
useClass: PlatformKoaRouter
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
provide: PlatformApplication,
|
|
71
|
-
useClass: PlatformKoaApplication
|
|
72
|
-
}
|
|
73
|
-
];
|
|
74
85
|
//# sourceMappingURL=PlatformKoa.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,
|
|
1
|
+
{"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EAEb,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,cAAc,EACf,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAC,0BAA0B,EAAC,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAC,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAEnI;;;GAGG;AACH,MAAM,OAAO,WAAW;IAwBtB,YAAoB,QAAyC;QAAzC,aAAQ,GAAR,QAAQ,CAAiC;QAvBpD,cAAS,GAAG;YACnB;gBACE,OAAO,EAAE,gBAAgB;gBACzB,QAAQ,EAAE,mBAAmB;aAC9B;YACD;gBACE,OAAO,EAAE,eAAe;gBACxB,QAAQ,EAAE,kBAAkB;aAC7B;YACD;gBACE,OAAO,EAAE,eAAe;gBACxB,QAAQ,EAAE,kBAAkB;aAC7B;YACD;gBACE,OAAO,EAAE,cAAc;gBACvB,QAAQ,EAAE,iBAAiB;aAC5B;YACD;gBACE,OAAO,EAAE,mBAAmB;gBAC5B,QAAQ,EAAE,sBAAsB;aACjC;SACF,CAAC;IAE8D,CAAC;IAEjE;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,MAAiB,EAAE,WAAwC,EAAE;QACzE,O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M,MAAM,GAAG,aAAa,CAAC,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","sourcesContent":["import KoaRouter from \"@koa/router\";\nimport {\n createContext,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformExceptions,\n PlatformHandler,\n PlatformRequest,\n PlatformResponse,\n PlatformRouter\n} from \"@tsed/common\";\nimport {Type} from \"@tsed/core\";\nimport Koa, {Context, Next} from \"koa\";\nimport {resourceNotFoundMiddleware} from \"../middlewares/resourceNotFoundMiddleware\";\nimport {PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, PlatformKoaResponse, PlatformKoaRouter} from \"../services\";\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {\n readonly providers = [\n {\n provide: PlatformResponse,\n useClass: PlatformKoaResponse\n },\n {\n provide: PlatformRequest,\n useClass: PlatformKoaRequest\n },\n {\n provide: PlatformHandler,\n useClass: PlatformKoaHandler\n },\n {\n provide: PlatformRouter,\n useClass: PlatformKoaRouter\n },\n {\n provide: PlatformApplication,\n useClass: PlatformKoaApplication\n }\n ];\n\n constructor(private platform: PlatformBuilder<Koa, KoaRouter>) {}\n\n /**\n * Create new serverless application. In this mode, the component scan are disabled.\n * @param module\n * @param settings\n */\n static create(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.create<Koa, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.bootstrap<Koa, KoaRouter>(module, {\n ...settings,\n adapter: PlatformKoa\n });\n }\n\n onInit() {\n const {injector, app} = this.platform;\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, ctx.request.$ctx);\n };\n\n app.getApp().silent = true;\n app.getApp().on(\"error\", listener);\n }\n\n useRouter(): this {\n const {app} = this.platform;\n app.getApp().use(resourceNotFoundMiddleware).use(app.getRouter().routes()).use(app.getRouter().allowedMethods());\n\n return this;\n }\n\n useContext(): this {\n const {injector, app, logger} = this.platform;\n logger.info(\"Mount app context\");\n\n const invoke = createContext(injector);\n\n app.getApp().use(async (ctx: Context, next: Next) => {\n await invoke({\n request: ctx.request as any,\n response: ctx.response as any,\n ctx\n });\n\n return next();\n });\n\n return this;\n }\n}\n"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PlatformBuilder, PlatformTest } from "@tsed/common";
|
|
2
2
|
import { PlatformKoa } from "./components/PlatformKoa";
|
|
3
|
-
PlatformTest.
|
|
4
|
-
PlatformBuilder.
|
|
3
|
+
PlatformTest.adapter = PlatformKoa;
|
|
4
|
+
PlatformBuilder.adapter = PlatformKoa;
|
|
5
5
|
// interfaces
|
|
6
6
|
export * from "./interfaces";
|
|
7
7
|
// decorators
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,YAAY,EAAC,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAC,WAAW,EAAC,MAAM,0BAA0B,CAAC;AAErD,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,YAAY,EAAC,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAC,WAAW,EAAC,MAAM,0BAA0B,CAAC;AAErD,YAAY,CAAC,OAAO,GAAG,WAAW,CAAC;AACnC,eAAe,CAAC,OAAO,GAAG,WAAW,CAAC;AAEtC,aAAa;AACb,cAAc,cAAc,CAAC;AAE7B,aAAa;AACb,cAAc,cAAc,CAAC;AAE7B,WAAW;AACX,cAAc,YAAY,CAAC;AAE3B,aAAa;AACb,cAAc,0BAA0B,CAAC","sourcesContent":["import {PlatformBuilder, PlatformTest} from \"@tsed/common\";\nimport {PlatformKoa} from \"./components/PlatformKoa\";\n\nPlatformTest.adapter = PlatformKoa;\nPlatformBuilder.adapter = PlatformKoa;\n\n// interfaces\nexport * from \"./interfaces\";\n\n// decorators\nexport * from \"./decorators\";\n\n// services\nexport * from \"./services\";\n\n// components\nexport * from \"./components/PlatformKoa\";\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="koa__router" />
|
|
2
2
|
import KoaRouter from "@koa/router";
|
|
3
|
-
import { PlatformApplication, PlatformBuilder,
|
|
3
|
+
import { PlatformAdapter, PlatformApplication, PlatformBuilder, PlatformHandler, PlatformRequest, PlatformResponse, PlatformRouter } from "@tsed/common";
|
|
4
4
|
import { Type } from "@tsed/core";
|
|
5
5
|
import Koa from "koa";
|
|
6
6
|
import { PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, PlatformKoaResponse, PlatformKoaRouter } from "../services";
|
|
@@ -8,8 +8,9 @@ import { PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, Platfor
|
|
|
8
8
|
* @platform
|
|
9
9
|
* @koa
|
|
10
10
|
*/
|
|
11
|
-
export declare class PlatformKoa
|
|
12
|
-
|
|
11
|
+
export declare class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {
|
|
12
|
+
private platform;
|
|
13
|
+
readonly providers: ({
|
|
13
14
|
provide: typeof PlatformResponse;
|
|
14
15
|
useClass: typeof PlatformKoaResponse;
|
|
15
16
|
} | {
|
|
@@ -25,14 +26,20 @@ export declare class PlatformKoa extends PlatformBuilder<Koa, KoaRouter> {
|
|
|
25
26
|
provide: typeof PlatformApplication;
|
|
26
27
|
useClass: typeof PlatformKoaApplication;
|
|
27
28
|
})[];
|
|
28
|
-
constructor(
|
|
29
|
+
constructor(platform: PlatformBuilder<Koa, KoaRouter>);
|
|
29
30
|
/**
|
|
30
31
|
* Create new serverless application. In this mode, the component scan are disabled.
|
|
31
32
|
* @param module
|
|
32
33
|
* @param settings
|
|
33
34
|
*/
|
|
34
|
-
static create(module: Type<any>, settings?: Partial<TsED.Configuration>):
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
static create(module: Type<any>, settings?: Partial<TsED.Configuration>): PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext>, KoaRouter<any, {}>>;
|
|
36
|
+
/**
|
|
37
|
+
* Bootstrap a server application
|
|
38
|
+
* @param module
|
|
39
|
+
* @param settings
|
|
40
|
+
*/
|
|
41
|
+
static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformBuilder<Koa<Koa.DefaultState, Koa.DefaultContext>, KoaRouter<any, {}>>>;
|
|
42
|
+
onInit(): void;
|
|
43
|
+
useRouter(): this;
|
|
44
|
+
useContext(): this;
|
|
38
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-koa",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.90.0",
|
|
4
4
|
"description": "Koa package for Ts.ED framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"repository": "https://github.com/tsedio/tsed",
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@koa/cors": "3.1.0",
|
|
52
|
-
"@tsed/common": "6.
|
|
53
|
-
"@tsed/core": "6.
|
|
54
|
-
"@tsed/di": "6.
|
|
55
|
-
"@tsed/platform-test-utils": "6.
|
|
52
|
+
"@tsed/common": "6.90.0",
|
|
53
|
+
"@tsed/core": "6.90.0",
|
|
54
|
+
"@tsed/di": "6.90.0",
|
|
55
|
+
"@tsed/platform-test-utils": "6.90.0",
|
|
56
56
|
"@types/koa": "2.11.3",
|
|
57
57
|
"@types/koa-bodyparser": "4.3.0",
|
|
58
58
|
"@types/koa-compose": "3.2.5",
|
|
@@ -77,13 +77,13 @@
|
|
|
77
77
|
"tslib": "2.2.0"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"@tsed/common": "^6.
|
|
81
|
-
"@tsed/core": "^6.
|
|
82
|
-
"@tsed/di": "^6.
|
|
83
|
-
"@tsed/json-mapper": "^6.
|
|
80
|
+
"@tsed/common": "^6.90.0",
|
|
81
|
+
"@tsed/core": "^6.90.0",
|
|
82
|
+
"@tsed/di": "^6.90.0",
|
|
83
|
+
"@tsed/json-mapper": "^6.90.0",
|
|
84
84
|
"@tsed/logger": ">=6.0.0",
|
|
85
|
-
"@tsed/openspec": "^6.
|
|
86
|
-
"@tsed/schema": "^6.
|
|
85
|
+
"@tsed/openspec": "^6.90.0",
|
|
86
|
+
"@tsed/schema": "^6.90.0",
|
|
87
87
|
"koa": ">=2.13.0",
|
|
88
88
|
"koa-bodyparser": ">=4.3.0",
|
|
89
89
|
"koa-compress": ">=5.0.1",
|