@tsed/platform-koa 7.61.0 → 7.61.2
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 +3 -3
- package/lib/cjs/services/PlatformKoaResponse.js +20 -34
- package/lib/cjs/services/PlatformKoaResponse.js.map +1 -1
- package/lib/esm/services/PlatformKoaResponse.js +20 -33
- package/lib/esm/services/PlatformKoaResponse.js.map +1 -1
- package/lib/types/services/PlatformKoaResponse.d.ts +5 -11
- package/package.json +20 -21
- package/.eslintignore +0 -13
- package/.eslintrc.js +0 -1
package/jest.config.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlatformKoaResponse = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const common_1 = require("@tsed/common");
|
|
6
|
-
const schema_1 = require("@tsed/schema");
|
|
7
|
-
const encodeurl_1 = tslib_1.__importDefault(require("encodeurl"));
|
|
8
5
|
/**
|
|
9
6
|
* @platform
|
|
10
7
|
* @koa
|
|
@@ -57,53 +54,42 @@ class PlatformKoaResponse extends common_1.PlatformResponse {
|
|
|
57
54
|
getHeaders() {
|
|
58
55
|
return this.raw.headers;
|
|
59
56
|
}
|
|
60
|
-
|
|
61
|
-
* Send any data to your consumer.
|
|
62
|
-
*
|
|
63
|
-
* This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.
|
|
64
|
-
* It choose the better way to send the data.
|
|
65
|
-
*
|
|
66
|
-
* @param data
|
|
67
|
-
*/
|
|
68
|
-
body(data) {
|
|
57
|
+
stream(data) {
|
|
69
58
|
this.raw.body = data;
|
|
70
59
|
return this;
|
|
71
60
|
}
|
|
72
61
|
getBody() {
|
|
73
62
|
return this.raw.body;
|
|
74
63
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
url = this.location(url).raw.get("Location");
|
|
79
|
-
this.body(`${(0, schema_1.getStatusMessage)(status)}. Redirecting to ${url}`);
|
|
80
|
-
this.status(status);
|
|
81
|
-
this.setHeader("Content-Length", Buffer.byteLength(this.raw.body));
|
|
82
|
-
if (this.request.method === "HEAD") {
|
|
83
|
-
this.getRes().end();
|
|
64
|
+
cookie(name, value, opts) {
|
|
65
|
+
if (value === null) {
|
|
66
|
+
this.ctx.cookies.set(name);
|
|
84
67
|
}
|
|
85
68
|
else {
|
|
86
|
-
this.
|
|
69
|
+
this.ctx.cookies.set(name, value, opts);
|
|
87
70
|
}
|
|
88
71
|
return this;
|
|
89
72
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (location === "back") {
|
|
93
|
-
location = this.request.get("Referrer") || "/";
|
|
94
|
-
}
|
|
95
|
-
// set location
|
|
96
|
-
this.raw.set("Location", (0, encodeurl_1.default)(location));
|
|
73
|
+
json(data) {
|
|
74
|
+
this.end(data);
|
|
97
75
|
return this;
|
|
98
76
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
77
|
+
buffer(data) {
|
|
78
|
+
this.end(data);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
end(data) {
|
|
82
|
+
if ([301, 302, 303, 307, 308].includes(this.statusCode)) {
|
|
83
|
+
if (this.request.method === "HEAD") {
|
|
84
|
+
this.getRes().end();
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.getRes().end(data);
|
|
88
|
+
}
|
|
102
89
|
}
|
|
103
90
|
else {
|
|
104
|
-
this.
|
|
91
|
+
this.raw.body = data;
|
|
105
92
|
}
|
|
106
|
-
return this;
|
|
107
93
|
}
|
|
108
94
|
}
|
|
109
95
|
exports.PlatformKoaResponse = PlatformKoaResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PlatformKo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,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;SACzC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAES,IAAI,CAAC,IAAS;QACtB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAES,MAAM,CAAC,IAAY;QAC3B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAES,GAAG,CAAC,IAAsB;QAClC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YACvD,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE;gBAClC,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC;aACrB;iBAAM;gBACL,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;aACzB;SACF;aAAM;YACL,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;SACtB;IACH,CAAC;CACF;AAjGD,kDAiGC"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { PlatformResponse } from "@tsed/common";
|
|
2
|
-
import { getStatusMessage } from "@tsed/schema";
|
|
3
|
-
import encodeUrl from "encodeurl";
|
|
4
2
|
/**
|
|
5
3
|
* @platform
|
|
6
4
|
* @koa
|
|
@@ -53,53 +51,42 @@ export class PlatformKoaResponse extends PlatformResponse {
|
|
|
53
51
|
getHeaders() {
|
|
54
52
|
return this.raw.headers;
|
|
55
53
|
}
|
|
56
|
-
|
|
57
|
-
* Send any data to your consumer.
|
|
58
|
-
*
|
|
59
|
-
* This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.
|
|
60
|
-
* It choose the better way to send the data.
|
|
61
|
-
*
|
|
62
|
-
* @param data
|
|
63
|
-
*/
|
|
64
|
-
body(data) {
|
|
54
|
+
stream(data) {
|
|
65
55
|
this.raw.body = data;
|
|
66
56
|
return this;
|
|
67
57
|
}
|
|
68
58
|
getBody() {
|
|
69
59
|
return this.raw.body;
|
|
70
60
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
url = this.location(url).raw.get("Location");
|
|
75
|
-
this.body(`${getStatusMessage(status)}. Redirecting to ${url}`);
|
|
76
|
-
this.status(status);
|
|
77
|
-
this.setHeader("Content-Length", Buffer.byteLength(this.raw.body));
|
|
78
|
-
if (this.request.method === "HEAD") {
|
|
79
|
-
this.getRes().end();
|
|
61
|
+
cookie(name, value, opts) {
|
|
62
|
+
if (value === null) {
|
|
63
|
+
this.ctx.cookies.set(name);
|
|
80
64
|
}
|
|
81
65
|
else {
|
|
82
|
-
this.
|
|
66
|
+
this.ctx.cookies.set(name, value, opts);
|
|
83
67
|
}
|
|
84
68
|
return this;
|
|
85
69
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (location === "back") {
|
|
89
|
-
location = this.request.get("Referrer") || "/";
|
|
90
|
-
}
|
|
91
|
-
// set location
|
|
92
|
-
this.raw.set("Location", encodeUrl(location));
|
|
70
|
+
json(data) {
|
|
71
|
+
this.end(data);
|
|
93
72
|
return this;
|
|
94
73
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
74
|
+
buffer(data) {
|
|
75
|
+
this.end(data);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
end(data) {
|
|
79
|
+
if ([301, 302, 303, 307, 308].includes(this.statusCode)) {
|
|
80
|
+
if (this.request.method === "HEAD") {
|
|
81
|
+
this.getRes().end();
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this.getRes().end(data);
|
|
85
|
+
}
|
|
98
86
|
}
|
|
99
87
|
else {
|
|
100
|
-
this.
|
|
88
|
+
this.raw.body = data;
|
|
101
89
|
}
|
|
102
|
-
return this;
|
|
103
90
|
}
|
|
104
91
|
}
|
|
105
92
|
//# sourceMappingURL=PlatformKoaResponse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAU9C;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,gBAA8B;IACrE,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,SAAS;QACP,yBAAyB;QACzB,OAAO,IAAI,CAAC,UAAU,KAAK,GAAG,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,MAAc;QACnB,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;OAWG;IACH,WAAW,CAAC,WAAmB;QAC7B,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,WAAW,CAAC;QAE5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,IAAS;QACd,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,IAAY,EAAE,KAAoB,EAAE,IAAyB;QAClE,IAAI,KAAK,KAAK,IAAI,EAAE;YAClB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;SAC5B;aAAM;YACL,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;SACzC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAES,IAAI,CAAC,IAAS;QACtB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAES,MAAM,CAAC,IAAY;QAC3B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAES,GAAG,CAAC,IAAsB;QAClC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YACvD,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE;gBAClC,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC;aACrB;iBAAM;gBACL,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;aACzB;SACF;aAAM;YACL,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;SACtB;IACH,CAAC;CACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { PlatformResponse } from "@tsed/common";
|
|
3
4
|
import { ServerResponse } from "http";
|
|
4
5
|
import Koa from "koa";
|
|
@@ -41,17 +42,10 @@ export declare class PlatformKoaResponse extends PlatformResponse<Koa.Response>
|
|
|
41
42
|
*/
|
|
42
43
|
contentType(contentType: string): this;
|
|
43
44
|
getHeaders(): import("http").OutgoingHttpHeaders;
|
|
44
|
-
|
|
45
|
-
* Send any data to your consumer.
|
|
46
|
-
*
|
|
47
|
-
* This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.
|
|
48
|
-
* It choose the better way to send the data.
|
|
49
|
-
*
|
|
50
|
-
* @param data
|
|
51
|
-
*/
|
|
52
|
-
body(data: any): this;
|
|
45
|
+
stream(data: any): this;
|
|
53
46
|
getBody(): any;
|
|
54
|
-
redirect(status: number, url: string): this;
|
|
55
|
-
location(location: string): this;
|
|
56
47
|
cookie(name: string, value: string | null, opts?: TsED.SetCookieOpts): this;
|
|
48
|
+
protected json(data: any): this;
|
|
49
|
+
protected buffer(data: Buffer): this;
|
|
50
|
+
protected end(data?: string | Buffer): void;
|
|
57
51
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-koa",
|
|
3
|
-
"version": "7.61.
|
|
3
|
+
"version": "7.61.2",
|
|
4
4
|
"description": "Koa package for Ts.ED framework",
|
|
5
|
-
"private": false,
|
|
6
5
|
"source": "./src/index.ts",
|
|
7
6
|
"main": "./lib/cjs/index.js",
|
|
8
7
|
"module": "./lib/esm/index.js",
|
|
@@ -16,11 +15,9 @@
|
|
|
16
15
|
"scripts": {
|
|
17
16
|
"build": "yarn barrels && yarn build:ts",
|
|
18
17
|
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
|
|
19
|
-
"start": "
|
|
18
|
+
"start": "ts-node test/app/index.ts",
|
|
20
19
|
"test": "cross-env NODE_ENV=test yarn jest --max-workers=2 --testTimeout 10000 && jest-coverage-thresholds-bumper",
|
|
21
|
-
"build:ts": "tsc --build tsconfig.json && tsc --build tsconfig.esm.json"
|
|
22
|
-
"lint": "eslint '**/*.{ts,js}'",
|
|
23
|
-
"lint:fix": "eslint '**/*.{ts,js}' --fix"
|
|
20
|
+
"build:ts": "tsc --build tsconfig.json && tsc --build tsconfig.esm.json"
|
|
24
21
|
},
|
|
25
22
|
"keywords": [
|
|
26
23
|
"Koa",
|
|
@@ -53,12 +50,11 @@
|
|
|
53
50
|
"repository": "https://github.com/tsedio/tsed",
|
|
54
51
|
"devDependencies": {
|
|
55
52
|
"@koa/cors": "5.0.0",
|
|
56
|
-
"@tsed/common": "7.61.
|
|
57
|
-
"@tsed/core": "7.61.
|
|
58
|
-
"@tsed/di": "7.61.
|
|
59
|
-
"@tsed/
|
|
60
|
-
"@tsed/
|
|
61
|
-
"@tsed/typescript": "7.44.1",
|
|
53
|
+
"@tsed/common": "7.61.2",
|
|
54
|
+
"@tsed/core": "7.61.2",
|
|
55
|
+
"@tsed/di": "7.61.2",
|
|
56
|
+
"@tsed/platform-test-sdk": "7.61.2",
|
|
57
|
+
"@tsed/typescript": "7.61.2",
|
|
62
58
|
"@types/koa": "2.13.4",
|
|
63
59
|
"@types/koa-bodyparser": "4.3.7",
|
|
64
60
|
"@types/koa-compose": "3.2.5",
|
|
@@ -68,7 +64,9 @@
|
|
|
68
64
|
"@types/koa-send": "4.1.3",
|
|
69
65
|
"@types/koa-session": "6.4.5",
|
|
70
66
|
"@types/koa__router": "12.0.0",
|
|
67
|
+
"barrelsby": "^2.8.1",
|
|
71
68
|
"eslint": "^8.12.0",
|
|
69
|
+
"jest": "^29.2.0",
|
|
72
70
|
"koa": "2.13.4",
|
|
73
71
|
"koa-bodyparser": "4.3.0",
|
|
74
72
|
"koa-compress": "5.1.0",
|
|
@@ -78,19 +76,20 @@
|
|
|
78
76
|
},
|
|
79
77
|
"dependencies": {
|
|
80
78
|
"@koa/router": "^12.0.0",
|
|
79
|
+
"cross-env": "7.0.3",
|
|
81
80
|
"encodeurl": "^1.0.2",
|
|
82
81
|
"koa-send": "5.0.1",
|
|
83
82
|
"multer": "^1.4.5-lts.1",
|
|
84
83
|
"tslib": "2.6.1"
|
|
85
84
|
},
|
|
86
85
|
"peerDependencies": {
|
|
87
|
-
"@tsed/common": "
|
|
88
|
-
"@tsed/core": "
|
|
89
|
-
"@tsed/di": "
|
|
90
|
-
"@tsed/json-mapper": "
|
|
86
|
+
"@tsed/common": "7.61.2",
|
|
87
|
+
"@tsed/core": "7.61.2",
|
|
88
|
+
"@tsed/di": "7.61.2",
|
|
89
|
+
"@tsed/json-mapper": "7.61.2",
|
|
91
90
|
"@tsed/logger": ">=6.2.2",
|
|
92
|
-
"@tsed/openspec": "
|
|
93
|
-
"@tsed/schema": "
|
|
91
|
+
"@tsed/openspec": "7.61.2",
|
|
92
|
+
"@tsed/schema": "7.61.2",
|
|
94
93
|
"koa": ">=2.13.0",
|
|
95
94
|
"koa-bodyparser": ">=4.3.0",
|
|
96
95
|
"koa-compress": ">=5.0.1",
|
|
@@ -112,13 +111,13 @@
|
|
|
112
111
|
"@tsed/json-mapper": {
|
|
113
112
|
"optional": false
|
|
114
113
|
},
|
|
115
|
-
"@tsed/
|
|
114
|
+
"@tsed/logger": {
|
|
116
115
|
"optional": false
|
|
117
116
|
},
|
|
118
|
-
"@tsed/
|
|
117
|
+
"@tsed/openspec": {
|
|
119
118
|
"optional": false
|
|
120
119
|
},
|
|
121
|
-
"@tsed/
|
|
120
|
+
"@tsed/schema": {
|
|
122
121
|
"optional": false
|
|
123
122
|
},
|
|
124
123
|
"multer": {
|
package/.eslintignore
DELETED
package/.eslintrc.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("@tsed/eslint/node.js");
|