@tsed/platform-koa 7.12.0 → 7.13.1
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/services/PlatformKoaResponse.js +9 -0
- package/lib/cjs/services/PlatformKoaResponse.js.map +1 -1
- package/lib/esm/services/PlatformKoaResponse.js +9 -0
- package/lib/esm/services/PlatformKoaResponse.js.map +1 -1
- package/lib/types/services/PlatformKoaResponse.d.ts +1 -0
- package/package.json +11 -11
|
@@ -96,6 +96,15 @@ class PlatformKoaResponse extends common_1.PlatformResponse {
|
|
|
96
96
|
this.raw.set("Location", (0, encodeurl_1.default)(location));
|
|
97
97
|
return this;
|
|
98
98
|
}
|
|
99
|
+
cookie(name, value, opts) {
|
|
100
|
+
if (value === null) {
|
|
101
|
+
this.ctx.cookies.set(name);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
this.ctx.cookies.set(name, value, opts);
|
|
105
|
+
}
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
99
108
|
}
|
|
100
109
|
exports.PlatformKoaResponse = PlatformKoaResponse;
|
|
101
110
|
//# sourceMappingURL=PlatformKoaResponse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":";;;;AAAA,yCAA8C;AAC9C,yCAA8C;AAC9C,kEAAkC;AAUlC;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,yBAA8B;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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AI,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;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;CACF;AAlHD,kDAkHC","sourcesContent":["import {PlatformResponse} from \"@tsed/common\";\nimport {getStatusMessage} from \"@tsed/schema\";\nimport encodeUrl from \"encodeurl\";\nimport {ServerResponse} from \"http\";\nimport Koa from \"koa\";\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 cookie(name: string, value: string | null, opts?: TsED.SetCookieOpts) {\n if (value === null) {\n this.ctx.cookies.set(name);\n } else {\n this.ctx.cookies.set(name, value, opts);\n }\n return this;\n }\n}\n"]}
|
|
@@ -92,5 +92,14 @@ export class PlatformKoaResponse extends PlatformResponse {
|
|
|
92
92
|
this.raw.set("Location", encodeUrl(location));
|
|
93
93
|
return this;
|
|
94
94
|
}
|
|
95
|
+
cookie(name, value, opts) {
|
|
96
|
+
if (value === null) {
|
|
97
|
+
this.ctx.cookies.set(name);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
this.ctx.cookies.set(name, value, opts);
|
|
101
|
+
}
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
95
104
|
}
|
|
96
105
|
//# sourceMappingURL=PlatformKoaResponse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,SAAS,MAAM,WAAW,CAAC;AAUlC;;;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,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G,CAAC,UAAU,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE9C,OAAO,IAAI,CAAC;IACd,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;CACF","sourcesContent":["import {PlatformResponse} from \"@tsed/common\";\nimport {getStatusMessage} from \"@tsed/schema\";\nimport encodeUrl from \"encodeurl\";\nimport {ServerResponse} from \"http\";\nimport Koa from \"koa\";\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 cookie(name: string, value: string | null, opts?: TsED.SetCookieOpts) {\n if (value === null) {\n this.ctx.cookies.set(name);\n } else {\n this.ctx.cookies.set(name, value, opts);\n }\n return this;\n }\n}\n"]}
|
|
@@ -53,4 +53,5 @@ export declare class PlatformKoaResponse extends PlatformResponse<Koa.Response>
|
|
|
53
53
|
getBody(): any;
|
|
54
54
|
redirect(status: number, url: string): this;
|
|
55
55
|
location(location: string): this;
|
|
56
|
+
cookie(name: string, value: string | null, opts?: TsED.SetCookieOpts): this;
|
|
56
57
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-koa",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.13.1",
|
|
4
4
|
"description": "Koa package for Ts.ED framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"repository": "https://github.com/tsedio/tsed",
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@koa/cors": "3.3.0",
|
|
55
|
-
"@tsed/common": "7.
|
|
56
|
-
"@tsed/core": "7.
|
|
57
|
-
"@tsed/di": "7.
|
|
58
|
-
"@tsed/platform-test-sdk": "7.
|
|
55
|
+
"@tsed/common": "7.13.1",
|
|
56
|
+
"@tsed/core": "7.13.1",
|
|
57
|
+
"@tsed/di": "7.13.1",
|
|
58
|
+
"@tsed/platform-test-sdk": "7.13.1",
|
|
59
59
|
"@types/koa": "2.13.4",
|
|
60
60
|
"@types/koa-bodyparser": "4.3.7",
|
|
61
61
|
"@types/koa-compose": "3.2.5",
|
|
@@ -80,13 +80,13 @@
|
|
|
80
80
|
"tslib": "2.4.0"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
|
-
"@tsed/common": "^7.
|
|
84
|
-
"@tsed/core": "^7.
|
|
85
|
-
"@tsed/di": "^7.
|
|
86
|
-
"@tsed/json-mapper": "^7.
|
|
83
|
+
"@tsed/common": "^7.13.1",
|
|
84
|
+
"@tsed/core": "^7.13.1",
|
|
85
|
+
"@tsed/di": "^7.13.1",
|
|
86
|
+
"@tsed/json-mapper": "^7.13.1",
|
|
87
87
|
"@tsed/logger": ">=6.2.2",
|
|
88
|
-
"@tsed/openspec": "^7.
|
|
89
|
-
"@tsed/schema": "^7.
|
|
88
|
+
"@tsed/openspec": "^7.13.1",
|
|
89
|
+
"@tsed/schema": "^7.13.1",
|
|
90
90
|
"koa": ">=2.13.0",
|
|
91
91
|
"koa-bodyparser": ">=4.3.0",
|
|
92
92
|
"koa-compress": ">=5.0.1",
|