@tsed/platform-koa 6.67.0 → 6.68.3
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/decorators/ctx.js
CHANGED
|
@@ -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,iBAAQ,CAAC,SAAS,EAAE;QACzB,YAAY,EAAE,KAAK;QACnB,aAAa,EAAE,KAAK;KACrB,CAAC,CAAC;AACL,CAAC;
|
|
1
|
+
{"version":3,"file":"ctx.js","sourceRoot":"","sources":["../../src/decorators/ctx.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAGtC;;;;;;GAMG;AACH,SAAgB,MAAM;IACpB,OAAO,iBAAQ,CAAC,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,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HandlerMetadata, OnRequestOptions, PlatformContext, PlatformHandler } from "@tsed/common";
|
|
2
2
|
import "./PlatformKoaRequest";
|
|
3
3
|
export declare class PlatformKoaHandler extends PlatformHandler {
|
|
4
|
-
protected getArg(type: ParamTypes | string, h: HandlerContext): any;
|
|
5
|
-
protected createRawHandler(metadata: HandlerMetadata): any;
|
|
6
4
|
flush(data: any, ctx: PlatformContext): Promise<void>;
|
|
5
|
+
protected createRawHandler(metadata: HandlerMetadata): any;
|
|
7
6
|
protected onRequest(requestOptions: OnRequestOptions): Promise<any>;
|
|
8
7
|
protected onError(error: unknown, requestOptions: OnRequestOptions): any;
|
|
9
8
|
protected onCtxRequest(requestOptions: OnRequestOptions): Promise<any>;
|
|
@@ -4,16 +4,11 @@ exports.PlatformKoaHandler = void 0;
|
|
|
4
4
|
const common_1 = require("@tsed/common");
|
|
5
5
|
require("./PlatformKoaRequest");
|
|
6
6
|
class PlatformKoaHandler extends common_1.PlatformHandler {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
case "KOA_CTX":
|
|
11
|
-
return koaCtx;
|
|
12
|
-
case common_1.ParamTypes.LOCALS:
|
|
13
|
-
return koaCtx.state;
|
|
14
|
-
default:
|
|
15
|
-
return super.getArg(type, h);
|
|
7
|
+
async flush(data, ctx) {
|
|
8
|
+
if (data === undefined && ctx.getResponse().body) {
|
|
9
|
+
data = ctx.getResponse().body;
|
|
16
10
|
}
|
|
11
|
+
return super.flush(data, ctx);
|
|
17
12
|
}
|
|
18
13
|
createRawHandler(metadata) {
|
|
19
14
|
switch (metadata.type) {
|
|
@@ -38,12 +33,6 @@ class PlatformKoaHandler extends common_1.PlatformHandler {
|
|
|
38
33
|
});
|
|
39
34
|
}
|
|
40
35
|
}
|
|
41
|
-
async flush(data, ctx) {
|
|
42
|
-
if (data === undefined && ctx.getResponse().body) {
|
|
43
|
-
data = ctx.getResponse().body;
|
|
44
|
-
}
|
|
45
|
-
return super.flush(data, ctx);
|
|
46
|
-
}
|
|
47
36
|
async onRequest(requestOptions) {
|
|
48
37
|
const { metadata, $ctx } = requestOptions;
|
|
49
38
|
if ($ctx.data instanceof Error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaHandler.js","sourceRoot":"","sources":["../../src/services/PlatformKoaHandler.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"PlatformKoaHandler.js","sourceRoot":"","sources":["../../src/services/PlatformKoaHandler.ts"],"names":[],"mappings":";;;AAAA,yCAA8G;AAE9G,gCAA8B;AAE9B,MAAa,kBAAmB,SAAQ,wBAAe;IAC9C,KAAK,CAAC,KAAK,CAAC,IAAS,EAAE,GAAoB;QAChD,IAAI,IAAI,KAAK,SAAS,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE;YAChD,IAAI,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC;SAC/B;QAED,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC;IAES,gBAAgB,CAAC,QAAyB;QAClD,QAAQ,QAAQ,CAAC,IAAI,EAAE;YACrB;gBACE,OAAO,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;YAE1C,KAAK,oBAAW,CAAC,MAAM;gBACrB,OAAO,KAAK,EAAE,GAAgB,EAAE,IAAS,EAAE,EAAE,CAC3C,IAAI,CAAC,YAAY,CAAC;oBAChB,QAAQ;oBACR,IAAI;oBACJ,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI;iBACvB,CAAC,CAAC;YAEP,KAAK,oBAAW,CAAC,UAAU,CAAC;YAC5B,KAAK,oBAAW,CAAC,MAAM;gBACrB,OAAO,QAAQ,CAAC,OAAO,CAAC;YAE1B,KAAK,oBAAW,CAAC,QAAQ,CAAC;YAC1B,KAAK,oBAAW,CAAC,UAAU,CAAC;YAC5B,KAAK,oBAAW,CAAC,cAAc;gBAC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AI,CAAC,CAAC;SAC9B;IACH,CAAC;IAES,UAAU,CAAC,KAAU,EAAE,IAAqB;QACpD,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;IAC5D,CAAC;CACF;AApFD,gDAoFC","sourcesContent":["import {HandlerMetadata, HandlerType, OnRequestOptions, PlatformContext, PlatformHandler} from \"@tsed/common\";\nimport Koa from \"koa\";\nimport \"./PlatformKoaRequest\";\n\nexport class PlatformKoaHandler extends PlatformHandler {\n public async flush(data: any, ctx: PlatformContext): Promise<void> {\n if (data === undefined && ctx.getResponse().body) {\n data = ctx.getResponse().body;\n }\n\n return super.flush(data, ctx);\n }\n\n protected createRawHandler(metadata: HandlerMetadata) {\n switch (metadata.type) {\n default:\n return super.createRawHandler(metadata);\n\n case HandlerType.CTX_FN:\n return async (ctx: Koa.Context, next: any) =>\n this.onCtxRequest({\n metadata,\n next,\n $ctx: ctx.request.$ctx\n });\n\n case HandlerType.RAW_ERR_FN:\n case HandlerType.RAW_FN:\n return metadata.handler;\n\n case HandlerType.ENDPOINT:\n case HandlerType.MIDDLEWARE:\n case HandlerType.ERR_MIDDLEWARE:\n return (ctx: Koa.Context, next: Koa.Next) =>\n this.onRequest({\n $ctx: ctx.request.$ctx,\n metadata,\n next\n });\n }\n }\n\n protected async onRequest(requestOptions: OnRequestOptions): Promise<any> {\n const {metadata, $ctx} = requestOptions;\n\n if ($ctx.data instanceof Error) {\n if (metadata.hasErrorParam) {\n requestOptions.err = $ctx.data;\n } else {\n return this.onError($ctx.data, requestOptions);\n }\n }\n\n return super.onRequest(requestOptions);\n }\n\n protected onError(error: unknown, requestOptions: OnRequestOptions) {\n const {next, $ctx, metadata} = requestOptions;\n\n // istanbul ignore next\n if ($ctx.isDone()) {\n return;\n }\n\n $ctx.data = error;\n\n if (!next || metadata.isFinal()) {\n this.throwError(error, $ctx);\n\n return;\n }\n\n return next();\n }\n\n protected async onCtxRequest(requestOptions: OnRequestOptions): Promise<any> {\n const {$ctx} = requestOptions;\n\n try {\n return await super.onCtxRequest(requestOptions);\n } catch (error) {\n this.throwError(error, $ctx);\n }\n }\n\n protected throwError(error: any, $ctx: PlatformContext) {\n $ctx.getApp().emit(\"error\", error, $ctx.getRequest().ctx);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-koa",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.68.3",
|
|
4
4
|
"description": "Koa package for Ts.ED framework",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"bugs": {
|
|
34
34
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
35
35
|
},
|
|
36
|
-
"homepage": "https://github.com/tsedio/tsed/tree/production//packages/platform-koa",
|
|
36
|
+
"homepage": "https://github.com/tsedio/tsed/tree/production//packages/platform/platform-koa",
|
|
37
37
|
"repository": "https://github.com/tsedio/tsed",
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsc --build tsconfig.compile.json",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@koa/cors": "3.1.0",
|
|
44
|
-
"@tsed/common": "6.
|
|
45
|
-
"@tsed/core": "6.
|
|
46
|
-
"@tsed/di": "6.
|
|
47
|
-
"@tsed/platform-test-utils": "6.
|
|
44
|
+
"@tsed/common": "6.68.3",
|
|
45
|
+
"@tsed/core": "6.68.3",
|
|
46
|
+
"@tsed/di": "6.68.3",
|
|
47
|
+
"@tsed/platform-test-utils": "6.68.3",
|
|
48
48
|
"@types/koa": "2.11.3",
|
|
49
49
|
"@types/koa-bodyparser": "4.3.0",
|
|
50
50
|
"@types/koa-compose": "3.2.5",
|
|
@@ -69,13 +69,13 @@
|
|
|
69
69
|
"tslib": "2.2.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"@tsed/common": "^6.
|
|
73
|
-
"@tsed/core": "^6.
|
|
74
|
-
"@tsed/di": "^6.
|
|
75
|
-
"@tsed/json-mapper": "^6.
|
|
72
|
+
"@tsed/common": "^6.68.2",
|
|
73
|
+
"@tsed/core": "^6.68.2",
|
|
74
|
+
"@tsed/di": "^6.68.2",
|
|
75
|
+
"@tsed/json-mapper": "^6.68.2",
|
|
76
76
|
"@tsed/logger": "^5.16.0",
|
|
77
|
-
"@tsed/openspec": "^6.
|
|
78
|
-
"@tsed/schema": "^6.
|
|
77
|
+
"@tsed/openspec": "^6.68.2",
|
|
78
|
+
"@tsed/schema": "^6.68.2",
|
|
79
79
|
"koa": "2.13.0",
|
|
80
80
|
"koa-bodyparser": "4.3.0",
|
|
81
81
|
"koa-compress": "5.0.1",
|