@tsed/platform-koa 8.11.1 → 8.12.0-rc.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.
Files changed (37) hide show
  1. package/lib/esm/components/PlatformKoa.js +0 -1
  2. package/lib/esm/decorators/ctx.js +0 -1
  3. package/lib/esm/decorators/state.js +0 -1
  4. package/lib/esm/index.js +0 -1
  5. package/lib/esm/interfaces/PlatformKoaSettings.js +0 -1
  6. package/lib/esm/interfaces/interfaces.js +0 -1
  7. package/lib/esm/middlewares/staticsMiddleware.js +0 -1
  8. package/lib/esm/services/PlatformKoaHandler.js +0 -1
  9. package/lib/esm/services/PlatformKoaRequest.js +0 -1
  10. package/lib/esm/services/PlatformKoaResponse.js +0 -1
  11. package/package.json +10 -7
  12. package/lib/esm/components/PlatformKoa.js.map +0 -1
  13. package/lib/esm/decorators/ctx.js.map +0 -1
  14. package/lib/esm/decorators/state.js.map +0 -1
  15. package/lib/esm/index.js.map +0 -1
  16. package/lib/esm/interfaces/PlatformKoaSettings.js.map +0 -1
  17. package/lib/esm/interfaces/interfaces.js.map +0 -1
  18. package/lib/esm/middlewares/staticsMiddleware.js.map +0 -1
  19. package/lib/esm/services/PlatformKoaHandler.js.map +0 -1
  20. package/lib/esm/services/PlatformKoaRequest.js.map +0 -1
  21. package/lib/esm/services/PlatformKoaResponse.js.map +0 -1
  22. package/src/components/PlatformKoa.spec.ts +0 -64
  23. package/src/components/PlatformKoa.ts +0 -197
  24. package/src/decorators/ctx.spec.ts +0 -14
  25. package/src/decorators/ctx.ts +0 -32
  26. package/src/decorators/state.spec.ts +0 -16
  27. package/src/decorators/state.ts +0 -43
  28. package/src/index.ts +0 -12
  29. package/src/interfaces/PlatformKoaSettings.ts +0 -15
  30. package/src/interfaces/interfaces.ts +0 -18
  31. package/src/middlewares/staticsMiddleware.ts +0 -34
  32. package/src/services/PlatformKoaHandler.ts +0 -22
  33. package/src/services/PlatformKoaRequest.spec.ts +0 -112
  34. package/src/services/PlatformKoaRequest.ts +0 -51
  35. package/src/services/PlatformKoaResponse.spec.ts +0 -224
  36. package/src/services/PlatformKoaResponse.ts +0 -113
  37. package/vitest.config.mts +0 -21
@@ -150,4 +150,3 @@ adapter(PlatformKoa, [
150
150
  useClass: PlatformKoaHandler
151
151
  }
152
152
  ]);
153
- //# sourceMappingURL=PlatformKoa.js.map
@@ -24,4 +24,3 @@ export function KoaCtx() {
24
24
  export function Ctx() {
25
25
  return KoaCtx();
26
26
  }
27
- //# sourceMappingURL=ctx.js.map
@@ -2,4 +2,3 @@ import { Locals } from "@tsed/platform-params";
2
2
  export function State(...args) {
3
3
  return Locals(...args);
4
4
  }
5
- //# sourceMappingURL=state.js.map
package/lib/esm/index.js CHANGED
@@ -10,4 +10,3 @@ export * from "./middlewares/staticsMiddleware.js";
10
10
  export * from "./services/PlatformKoaHandler.js";
11
11
  export * from "./services/PlatformKoaRequest.js";
12
12
  export * from "./services/PlatformKoaResponse.js";
13
- //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=PlatformKoaSettings.js.map
@@ -1,2 +1 @@
1
1
  export * from "./PlatformKoaSettings.js";
2
- //# sourceMappingURL=interfaces.js.map
@@ -27,4 +27,3 @@ export function staticsMiddleware(options) {
27
27
  return next();
28
28
  };
29
29
  }
30
- //# sourceMappingURL=staticsMiddleware.js.map
@@ -14,4 +14,3 @@ export class PlatformKoaHandler extends PlatformHandler {
14
14
  return super.flush($ctx);
15
15
  }
16
16
  }
17
- //# sourceMappingURL=PlatformKoaHandler.js.map
@@ -27,4 +27,3 @@ export class PlatformKoaRequest extends PlatformRequest {
27
27
  return this.ctx.request.req;
28
28
  }
29
29
  }
30
- //# sourceMappingURL=PlatformKoaRequest.js.map
@@ -89,4 +89,3 @@ export class PlatformKoaResponse extends PlatformResponse {
89
89
  }
90
90
  }
91
91
  }
92
- //# sourceMappingURL=PlatformKoaResponse.js.map
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsed/platform-koa",
3
3
  "description": "Koa package for Ts.ED framework",
4
4
  "type": "module",
5
- "version": "8.11.1",
5
+ "version": "8.12.0-rc.1",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -54,12 +54,12 @@
54
54
  "repository": "https://github.com/tsedio/tsed",
55
55
  "devDependencies": {
56
56
  "@koa/cors": "5.0.0",
57
- "@tsed/barrels": "8.11.1",
58
- "@tsed/core": "8.11.1",
59
- "@tsed/di": "8.11.1",
60
- "@tsed/platform-http": "8.11.1",
61
- "@tsed/platform-test-sdk": "8.11.1",
62
- "@tsed/typescript": "8.11.1",
57
+ "@tsed/barrels": "8.12.0-rc.1",
58
+ "@tsed/core": "8.12.0-rc.1",
59
+ "@tsed/di": "8.12.0-rc.1",
60
+ "@tsed/platform-http": "8.12.0-rc.1",
61
+ "@tsed/platform-test-sdk": "8.12.0-rc.1",
62
+ "@tsed/typescript": "8.12.0-rc.1",
63
63
  "@types/koa": "2.15.0",
64
64
  "@types/koa-bodyparser": "4.3.12",
65
65
  "@types/koa-compose": "3.2.8",
@@ -128,5 +128,8 @@
128
128
  "multer": {
129
129
  "optional": false
130
130
  }
131
+ },
132
+ "publishConfig": {
133
+ "tag": "rc"
131
134
  }
132
135
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../../src/components/PlatformKoa.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AAEnC,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAC,eAAe,EAAE,UAAU,EAAO,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAC,MAAM,UAAU,CAAC;AACxD,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EACL,OAAO,EACP,WAAW,EACX,aAAa,EACb,eAAe,EAC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ACpB,OAAO,QAAQ,CAAC;QACd,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,kBAAkB;QAC5B,SAAS,EAAE,KAAK;QAChB,aAAa,EAAE,KAAK;KACrB,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,GAAG;IACjB,OAAO,MAAM,EAAE,CAAC;AAClB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/decorators/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,uBAAuB,CAAC;AAwC7C,MAAM,UAAU,KAAK,CAAC,GAAG,IAAW;IAClC,OAAQ,MAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AAClC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,oCAAoC,CAAC;AACnD,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformKoaSettings.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformKoaSettings.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"AAIA,cAAc,0BAA0B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"staticsMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/staticsMiddleware.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,UAAU,CAAC;AAE5B;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OA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ED,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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAC;AASrD;;;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,MA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atformKoa} from "./PlatformKoa.js";
2
-
3
- class Server {}
4
-
5
- describe("PlatformKoa", () => {
6
- describe("create()", () => {
7
- it("should create platform", () => {
8
- const platform = PlatformKoa.create(Server, {});
9
-
10
- expect(platform.adapter).toBeInstanceOf(PlatformKoa);
11
- });
12
- });
13
- describe("bootstrap()", () => {
14
- it("should create platform", async () => {
15
- const platform = await PlatformKoa.bootstrap(Server, {});
16
-
17
- expect(platform.adapter).toBeInstanceOf(PlatformKoa);
18
- });
19
- });
20
- describe("bodyParser()", () => {
21
- it("should return the body parser (json)", () => {
22
- const stub = vi.fn().mockReturnValue("body");
23
-
24
- const platform = PlatformKoa.create(Server, {
25
- koa: {
26
- bodyParser: stub
27
- }
28
- });
29
-
30
- const result = platform.adapter.bodyParser("json", {strict: true});
31
-
32
- expect(result).toEqual("body");
33
- expect(stub).toHaveBeenCalledWith({strict: true});
34
- });
35
- it("should return the body parser (raw)", () => {
36
- const stub = vi.fn().mockReturnValue("body");
37
-
38
- const platform = PlatformKoa.create(Server, {
39
- koa: {
40
- bodyParser: stub
41
- }
42
- });
43
-
44
- const result = platform.adapter.bodyParser("raw", {strict: true});
45
-
46
- expect(result).toEqual("body");
47
- expect(stub).toHaveBeenCalledWith({strict: true});
48
- });
49
- it("should return the body parser (urlencoded)", () => {
50
- const stub = vi.fn().mockReturnValue("body");
51
-
52
- const platform = PlatformKoa.create(Server, {
53
- koa: {
54
- bodyParser: stub
55
- }
56
- });
57
-
58
- const result = platform.adapter.bodyParser("urlencoded", {strict: true});
59
-
60
- expect(result).toEqual("body");
61
- expect(stub).toHaveBeenCalledWith({strict: true});
62
- });
63
- });
64
- });
@@ -1,197 +0,0 @@
1
- import "@tsed/platform-multer/koa";
2
-
3
- import KoaRouter from "@koa/router";
4
- import {catchAsyncError, isFunction, Type} from "@tsed/core";
5
- import {constant, inject, runInContext} from "@tsed/di";
6
- import {PlatformExceptions} from "@tsed/platform-exceptions";
7
- import {
8
- adapter,
9
- application,
10
- createContext,
11
- PlatformAdapter,
12
- PlatformBuilder,
13
- PlatformHandler,
14
- PlatformRequest,
15
- PlatformResponse,
16
- PlatformStaticsOptions
17
- } from "@tsed/platform-http";
18
- import {PlatformHandlerMetadata, PlatformHandlerType, PlatformLayer} from "@tsed/platform-router";
19
- import Koa, {Context, Next} from "koa";
20
- import koaBodyParser, {Options} from "koa-bodyparser";
21
- // @ts-ignore
22
- import koaQs from "koa-qs";
23
- import send from "koa-send";
24
-
25
- import {staticsMiddleware} from "../middlewares/staticsMiddleware.js";
26
- import {PlatformKoaHandler} from "../services/PlatformKoaHandler.js";
27
- import {PlatformKoaRequest} from "../services/PlatformKoaRequest.js";
28
- import {PlatformKoaResponse} from "../services/PlatformKoaResponse.js";
29
-
30
- declare global {
31
- namespace TsED {
32
- export interface Application extends Koa {}
33
- }
34
-
35
- namespace TsED {
36
- export interface StaticsOptions extends send.SendOptions {}
37
- }
38
- }
39
-
40
- // @ts-ignore
41
- KoaRouter.prototype.$$match = KoaRouter.prototype.match;
42
- KoaRouter.prototype.match = function match(...args: any[]) {
43
- const matched = this.$$match(...args);
44
- if (matched) {
45
- if (matched.path.length) {
46
- matched.route = true;
47
- }
48
- }
49
-
50
- return matched;
51
- };
52
-
53
- /**
54
- * @platform
55
- * @koa
56
- */
57
- export class PlatformKoa extends PlatformAdapter<Koa> {
58
- readonly NAME = "koa";
59
-
60
- /**
61
- * Create new serverless application. In this mode, the component scan are disabled.
62
- * @param module
63
- * @param settings
64
- */
65
- static create(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {
66
- return PlatformBuilder.create<Koa>(module, {
67
- ...settings,
68
- adapter: PlatformKoa
69
- });
70
- }
71
-
72
- /**
73
- * Bootstrap a server application
74
- * @param module
75
- * @param settings
76
- */
77
- static bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {
78
- return PlatformBuilder.bootstrap<Koa>(module, {
79
- ...settings,
80
- adapter: PlatformKoa
81
- });
82
- }
83
-
84
- onInit() {
85
- this.app.getApp().silent = true;
86
- }
87
-
88
- mapLayers(layers: PlatformLayer[]) {
89
- const options = constant("koa.router", {});
90
- const rawRouter = new KoaRouter(options) as any;
91
-
92
- layers.forEach((layer) => {
93
- switch (layer.method) {
94
- case "statics":
95
- rawRouter.use(layer.path, this.statics(layer.path as string, layer.opts as any));
96
- break;
97
-
98
- default:
99
- rawRouter[layer.method](...layer.getArgs());
100
- }
101
- });
102
-
103
- application().getApp().use(rawRouter.routes()).use(rawRouter.allowedMethods());
104
- }
105
-
106
- mapHandler(handler: Function, metadata: PlatformHandlerMetadata) {
107
- return async (koaContext: Koa.Context, next: Koa.Next) => {
108
- const {$ctx} = koaContext.request;
109
-
110
- $ctx.next = next;
111
-
112
- const error = await catchAsyncError(() => handler($ctx));
113
-
114
- if (error) {
115
- $ctx.error = error;
116
- }
117
-
118
- if (metadata.type !== PlatformHandlerType.RESPONSE_FN) {
119
- return $ctx.next && $ctx.error ? $ctx.next($ctx.error) : $ctx.next();
120
- }
121
- };
122
- }
123
-
124
- useContext(): void {
125
- const invoke = createContext();
126
- const platformExceptions = inject(PlatformExceptions);
127
-
128
- application().use((koaContext: Context, next: Next) => {
129
- const $ctx = invoke({
130
- request: koaContext.request as any,
131
- response: koaContext.response as any,
132
- koaContext
133
- });
134
-
135
- return runInContext($ctx, async () => {
136
- try {
137
- await $ctx.start();
138
- await next();
139
- const status = koaContext.status || 404;
140
-
141
- if (status === 404 && !$ctx.isDone()) {
142
- platformExceptions?.resourceNotFound($ctx);
143
- }
144
- } catch (error) {
145
- platformExceptions?.catch(error, $ctx);
146
- } finally {
147
- await $ctx.finish();
148
- }
149
- });
150
- });
151
- }
152
-
153
- createApp() {
154
- const app = constant<Koa | undefined>("koa.app") || new Koa();
155
- koaQs(app, "extended");
156
-
157
- return {
158
- app,
159
- callback() {
160
- return app.callback();
161
- }
162
- };
163
- }
164
-
165
- statics(endpoint: string, options: PlatformStaticsOptions) {
166
- return staticsMiddleware(options);
167
- }
168
-
169
- bodyParser(_: "json" | "urlencoded" | "raw" | "text", additionalOptions: any = {}): any {
170
- const opts = constant(`koa.bodyParser`);
171
- let parser: any = koaBodyParser;
172
-
173
- let options: Options = {};
174
-
175
- if (isFunction(opts)) {
176
- parser = opts;
177
- options = {};
178
- }
179
-
180
- return parser({...options, ...additionalOptions});
181
- }
182
- }
183
-
184
- adapter(PlatformKoa, [
185
- {
186
- token: PlatformResponse,
187
- useClass: PlatformKoaResponse
188
- },
189
- {
190
- token: PlatformRequest,
191
- useClass: PlatformKoaRequest
192
- },
193
- {
194
- token: PlatformHandler,
195
- useClass: PlatformKoaHandler
196
- }
197
- ]);
@@ -1,14 +0,0 @@
1
- import {JsonParameterStore} from "@tsed/schema";
2
-
3
- import {Ctx} from "./ctx.js";
4
-
5
- describe("@Ctx", () => {
6
- it("should call store the right configuration", () => {
7
- class Ctrl {
8
- test(@Ctx() ctx: Ctx) {}
9
- }
10
-
11
- const param = JsonParameterStore.get(Ctrl, "test", 0);
12
- expect(param.paramType).toEqual("KOA_CTX");
13
- });
14
- });
@@ -1,32 +0,0 @@
1
- import {UseParam} from "@tsed/platform-params";
2
- import type {Context} from "koa";
3
-
4
- /**
5
- * Return the original Koa context.
6
- * @decorator
7
- * @operation
8
- * @input
9
- * @koa
10
- */
11
- export function KoaCtx(): ParameterDecorator {
12
- return UseParam({
13
- paramType: "KOA_CTX",
14
- dataPath: "$ctx.request.ctx",
15
- useMapper: false,
16
- useValidation: false
17
- });
18
- }
19
-
20
- /**
21
- * Return the original Koa context.
22
- * @decorator
23
- * @operation
24
- * @input
25
- * @koa
26
- */
27
- export function Ctx(): ParameterDecorator {
28
- return KoaCtx();
29
- }
30
-
31
- export type Ctx = Context;
32
- export type KoaCtx = Context;
@@ -1,16 +0,0 @@
1
- import {ParamTypes} from "@tsed/platform-params";
2
- import {JsonParameterStore} from "@tsed/schema";
3
-
4
- import {State} from "./state.js";
5
-
6
- describe("@State", () => {
7
- it("should call ParamFilter.useParam method with the correct parameters", () => {
8
- class Ctrl {
9
- test(@State("expression") test: any) {}
10
- }
11
-
12
- const param = JsonParameterStore.get(Ctrl, "test", 0);
13
- expect(param.expression).toEqual("expression");
14
- expect(param.paramType).toEqual(ParamTypes.LOCALS);
15
- });
16
- });
@@ -1,43 +0,0 @@
1
- import {Locals} from "@tsed/platform-params";
2
-
3
- /**
4
- * State return the value from koa.ctx.state object.
5
- *
6
- * #### Example
7
- *
8
- * ```typescript
9
- * * @Middleware()
10
- * class StateMiddleware {
11
- * use(@State() state: any) {
12
- * // set some on locals
13
- * state.user = "user"
14
- * }
15
- * }
16
- *
17
- * @Controller('/')
18
- * @UseBefore(StateMiddleware)
19
- * class MyCtrl {
20
- * @Get('/')
21
- * @View('home.ejs') // will use locals and returned data to render the page
22
- * get(@State('user') user: any) {
23
- * console.log('user', user);
24
- *
25
- * return {
26
- * description: 'Hello world'
27
- * }
28
- * }
29
- * }
30
- * ```
31
- *
32
- * @param expression The path of the property to get.
33
- * @decorator
34
- * @operation
35
- * @input
36
- * @response
37
- * @koa
38
- */
39
- export function State(expression: string): ParameterDecorator;
40
- export function State(): ParameterDecorator;
41
- export function State(...args: any[]): ParameterDecorator {
42
- return (Locals as any)(...args);
43
- }
package/src/index.ts DELETED
@@ -1,12 +0,0 @@
1
- /**
2
- * @file Automatically generated by @tsed/barrels.
3
- */
4
- export * from "./components/PlatformKoa.js";
5
- export * from "./decorators/ctx.js";
6
- export * from "./decorators/state.js";
7
- export * from "./interfaces/interfaces.js";
8
- export * from "./interfaces/PlatformKoaSettings.js";
9
- export * from "./middlewares/staticsMiddleware.js";
10
- export * from "./services/PlatformKoaHandler.js";
11
- export * from "./services/PlatformKoaRequest.js";
12
- export * from "./services/PlatformKoaResponse.js";
@@ -1,15 +0,0 @@
1
- import type {RouterOptions} from "@koa/router";
2
- import type {Middleware} from "koa";
3
- import type {Options} from "koa-bodyparser";
4
-
5
- export interface PlatformKoaSettings {
6
- /**
7
- * Koa router options
8
- */
9
- router?: RouterOptions;
10
- /**
11
- * Body parser options
12
- * @param opts
13
- */
14
- bodyParser?: ((opts?: Options) => Middleware) | Options;
15
- }
@@ -1,18 +0,0 @@
1
- import Koa from "koa";
2
-
3
- import {PlatformKoaSettings} from "./PlatformKoaSettings.js";
4
-
5
- export * from "./PlatformKoaSettings.js";
6
-
7
- declare global {
8
- namespace TsED {
9
- export interface Configuration {
10
- /**
11
- * Configuration related to Koa platform application.
12
- */
13
- koa: PlatformKoaSettings;
14
- }
15
-
16
- export interface NextFunction extends Koa.Next {}
17
- }
18
- }
@@ -1,34 +0,0 @@
1
- import {PlatformStaticsOptions} from "@tsed/platform-http";
2
- import type {Context} from "koa";
3
- import send from "koa-send";
4
-
5
- /**
6
- * @ignore
7
- * @param options
8
- */
9
- export function staticsMiddleware(options: PlatformStaticsOptions): any {
10
- if (options.index !== false) options.index = options.index || "index.html";
11
-
12
- return async (ctx: Context, next: any) => {
13
- if (["GET", "HEAD"].includes(ctx.method) && !ctx.body) {
14
- let path = ctx.path;
15
-
16
- if (ctx._matchedRoute && ctx._matchedRoute !== "/") {
17
- path = path.replace(String(ctx._matchedRoute).replace("/(.*)", ""), "");
18
- }
19
- try {
20
- const done = await send(ctx as any, path, options as send.SendOptions);
21
-
22
- if (done) {
23
- return;
24
- }
25
- } catch (err) {
26
- if (err.status !== 404) {
27
- throw err;
28
- }
29
- }
30
- }
31
-
32
- return next();
33
- };
34
- }
@@ -1,22 +0,0 @@
1
- import "./PlatformKoaRequest.js";
2
-
3
- import {PlatformContext, PlatformHandler} from "@tsed/platform-http";
4
- import {PlatformParamsCallback} from "@tsed/platform-params";
5
-
6
- export class PlatformKoaHandler extends PlatformHandler {
7
- onRequest(handler: PlatformParamsCallback, $ctx: PlatformContext) {
8
- if (!(($ctx.error instanceof Error && !$ctx.handlerMetadata.hasErrorParam) || ($ctx.handlerMetadata.hasErrorParam && !$ctx.error))) {
9
- return super.onRequest(handler, $ctx);
10
- }
11
-
12
- return Promise.resolve();
13
- }
14
-
15
- public flush($ctx: PlatformContext) {
16
- if (!$ctx.error && $ctx.data === undefined && $ctx.getResponse().body) {
17
- $ctx.data = $ctx.getResponse().body;
18
- }
19
-
20
- return super.flush($ctx);
21
- }
22
- }
@@ -1,112 +0,0 @@
1
- import {PlatformTest} from "@tsed/platform-http/testing";
2
-
3
- import {PlatformKoaRequest} from "./PlatformKoaRequest.js";
4
-
5
- function createRequest() {
6
- const req = PlatformTest.createRequest();
7
- const koaRequest = {
8
- protocol: "http",
9
- req,
10
- get ctx() {
11
- return koaCtx;
12
- }
13
- };
14
-
15
- const koaCtx: any = {
16
- request: koaRequest,
17
- cookie: {
18
- test: "test"
19
- },
20
- cookies: {
21
- test: "test"
22
- },
23
- session: {
24
- test: "test"
25
- }
26
- };
27
-
28
- const ctx = PlatformTest.createRequestContext({
29
- event: {
30
- request: koaRequest,
31
- koaContext: koaCtx
32
- },
33
- RequestKlass: PlatformKoaRequest
34
- });
35
-
36
- return {req, request: ctx.request, koaCtx, koaRequest};
37
- }
38
-
39
- describe("PlatformKoaRequest", () => {
40
- beforeEach(() => PlatformTest.create());
41
- afterEach(() => PlatformTest.reset());
42
- it("should create a PlatformRequest instance", () => {
43
- const {koaRequest, request} = createRequest();
44
-
45
- expect(request.raw).toEqual(koaRequest);
46
- });
47
-
48
- describe("secure", () => {
49
- it("should get cookies from cookie", () => {
50
- const {koaCtx, request} = createRequest();
51
- koaCtx.request.secure = true;
52
-
53
- expect(request.secure).toEqual(true);
54
- });
55
- });
56
-
57
- describe("protocol()", () => {
58
- it("should return the protocol request state (http)", () => {
59
- const {koaCtx, request} = createRequest();
60
-
61
- koaCtx.request.req.protocol = "http";
62
-
63
- expect(request.protocol).toEqual("http");
64
- });
65
- it("should return the protocol request state (https)", () => {
66
- const {koaCtx, request} = createRequest();
67
-
68
- koaCtx.request.protocol = "https";
69
-
70
- expect(request.protocol).toEqual("https");
71
- });
72
- });
73
-
74
- describe("host()", () => {
75
- it("should return the host", () => {
76
- const {koaCtx, request} = createRequest();
77
-
78
- koaCtx.request.host = "host";
79
-
80
- expect(request.host).toEqual("host");
81
- });
82
- });
83
-
84
- describe("cookies", () => {
85
- it("should get cookies from cookies", () => {
86
- const {koaCtx, request} = createRequest();
87
-
88
- koaCtx.cookie = null;
89
-
90
- expect(request.cookies).toEqual({test: "test"});
91
- });
92
- it("should get cookies from cookie", () => {
93
- const {request} = createRequest();
94
-
95
- expect(request.cookies).toEqual({test: "test"});
96
- });
97
- });
98
- describe("session", () => {
99
- it("should get session", () => {
100
- const {request} = createRequest();
101
-
102
- expect(request.session).toEqual({test: "test"});
103
- });
104
- });
105
- describe("getReq()", () => {
106
- it("should return nodejs request", () => {
107
- const {req, request} = createRequest();
108
-
109
- expect(request.getReq()).toEqual(req);
110
- });
111
- });
112
- });
@@ -1,51 +0,0 @@
1
- import "@koa/router";
2
-
3
- import {PlatformContext, PlatformRequest} from "@tsed/platform-http";
4
- import Koa from "koa";
5
-
6
- declare module "koa" {
7
- export interface Request {
8
- id: string;
9
- $ctx: PlatformContext;
10
- }
11
- }
12
-
13
- declare global {
14
- namespace TsED {
15
- export interface Request extends Koa.Request {}
16
- }
17
- }
18
-
19
- /**
20
- * @platform
21
- * @koa
22
- */
23
- export class PlatformKoaRequest extends PlatformRequest<Koa.Request> {
24
- get ctx(): Koa.Context {
25
- return this.$ctx.event.koaContext as Koa.Context;
26
- }
27
-
28
- get protocol(): string {
29
- return this.ctx.request.protocol;
30
- }
31
-
32
- get host(): string {
33
- return this.ctx.request.host;
34
- }
35
-
36
- get secure(): boolean {
37
- return this.ctx.request.secure;
38
- }
39
-
40
- get cookies(): {[p: string]: any} {
41
- return this.ctx.cookie || this.ctx.cookies;
42
- }
43
-
44
- get session(): any {
45
- return this.ctx.session;
46
- }
47
-
48
- getReq() {
49
- return this.ctx.request.req;
50
- }
51
- }
@@ -1,224 +0,0 @@
1
- import {PlatformTest} from "@tsed/platform-http/testing";
2
-
3
- import {PlatformKoaRequest} from "./PlatformKoaRequest.js";
4
- import {PlatformKoaResponse} from "./PlatformKoaResponse.js";
5
-
6
- function createResponse() {
7
- const res = PlatformTest.createResponse();
8
- const req = PlatformTest.createRequest();
9
-
10
- const koaContext: any = {
11
- response: {}
12
- };
13
-
14
- const koaResponse: any = Object.assign(res, {
15
- res,
16
- get ctx() {
17
- return koaContext;
18
- }
19
- });
20
-
21
- const koaRequest: any = {
22
- ...req,
23
- req,
24
- get ctx() {
25
- return koaContext;
26
- }
27
- };
28
-
29
- koaContext.response = koaResponse;
30
-
31
- const ctx = PlatformTest.createRequestContext({
32
- event: {
33
- response: koaResponse,
34
- request: koaRequest
35
- },
36
- ResponseKlass: PlatformKoaResponse,
37
- RequestKlass: PlatformKoaRequest
38
- });
39
-
40
- return {res, response: ctx.response as PlatformKoaResponse, ctx, koaResponse, koaRequest, koaContext};
41
- }
42
-
43
- describe("PlatformKoaResponse", () => {
44
- beforeEach(() => PlatformTest.create());
45
- afterEach(() => PlatformTest.reset());
46
- it("should create a PlatformResponse instance", () => {
47
- const {koaResponse, response} = createResponse();
48
-
49
- expect(response.raw).toEqual(koaResponse);
50
- });
51
-
52
- describe("getRes()", () => {
53
- it("return res", async () => {
54
- const {res, response} = createResponse();
55
-
56
- const result = await response.getRes();
57
-
58
- expect(result).toEqual(res);
59
- });
60
- });
61
- describe("statusCode", () => {
62
- it("return statusCode", () => {
63
- const {response} = createResponse();
64
-
65
- response.status(302);
66
-
67
- expect(response.statusCode).toEqual(302);
68
- });
69
- });
70
- describe("hasStatus", () => {
71
- it("return hasStatus", () => {
72
- const {response} = createResponse();
73
-
74
- response.status(404);
75
- expect(response.statusCode).toEqual(404);
76
- expect(response.hasStatus()).toEqual(false);
77
-
78
- response.status(201);
79
- expect(response.hasStatus()).toEqual(true);
80
- });
81
- });
82
- describe("contentType()", () => {
83
- it("should set contentType", () => {
84
- const {ctx, koaResponse} = createResponse();
85
-
86
- ctx.response.contentType("text/html");
87
-
88
- expect(koaResponse.type).toEqual("text/html");
89
- });
90
- });
91
- describe("body()", () => {
92
- it("should set body", () => {
93
- const {response, koaResponse} = createResponse();
94
-
95
- response.body("body");
96
-
97
- expect(koaResponse.body).toEqual("body");
98
- expect(response.getBody()).toEqual("body");
99
- });
100
- });
101
- describe("location", () => {
102
- it("should set header location", () => {
103
- const {res, response} = createResponse();
104
-
105
- response.location("https://location");
106
-
107
- expect(res.headers).toEqual({
108
- location: "https://location",
109
- "x-request-id": "id"
110
- });
111
- });
112
-
113
- it("should go back based on Referrer", async () => {
114
- const {res, response} = createResponse();
115
-
116
- response.request.raw.headers["referrer"] = "https://location/back";
117
-
118
- await response.location("back");
119
-
120
- expect(res.headers).toEqual({
121
- location: "https://location/back",
122
- "x-request-id": "id"
123
- });
124
- });
125
-
126
- it("should go back based on default path", async () => {
127
- const {res, response} = createResponse();
128
-
129
- await response.location("back");
130
-
131
- expect(res.headers).toEqual({
132
- location: "/",
133
- "x-request-id": "id"
134
- });
135
- });
136
- });
137
- describe("redirect", () => {
138
- it("should set header location (HEAD)", async () => {
139
- const {res, response, koaRequest, koaResponse} = createResponse();
140
-
141
- res.headers["location"] = "https://location";
142
- koaRequest.method = "HEAD";
143
-
144
- await response.redirect(301, "https://location");
145
-
146
- // expect(koaResponse.body).toEqual("Moved Permanently. Redirecting to https://location");
147
- expect(response.statusCode).toEqual(301);
148
- expect(res.headers).toEqual({
149
- location: "https://location",
150
- "x-request-id": "id"
151
- });
152
- expect(res.data).toEqual(undefined);
153
- });
154
- it("should set header location (POST)", async () => {
155
- const {res, response, koaRequest, koaResponse, ctx} = createResponse();
156
-
157
- res.headers["location"] = "https://location";
158
- koaRequest.method = "POST";
159
-
160
- await response.redirect(301, "https://location");
161
-
162
- // expect(koaResponse.body).toEqual("Moved Permanently. Redirecting to https://location");
163
- expect(response.statusCode).toEqual(301);
164
- expect(res.headers).toEqual({
165
- "content-length": 50,
166
- location: "https://location",
167
- "x-request-id": "id"
168
- });
169
- });
170
- });
171
- describe("getHeaders()", () => {
172
- it("should get headers", () => {
173
- const {ctx} = createResponse();
174
-
175
- ctx.response.setHeader("contentType", "application/json");
176
-
177
- const result = ctx.response.getHeaders();
178
-
179
- expect(result).toEqual({
180
- contenttype: "application/json",
181
- "x-request-id": "id"
182
- });
183
- });
184
- });
185
- describe("cookie()", () => {
186
- it("should manipulate cookies", () => {
187
- const {res, response, koaContext} = createResponse();
188
- koaContext.cookies = {};
189
- koaContext.cookies.set = (...args: any[]) => {
190
- if (!args[1]) {
191
- res.headers["set-cookie"] = res.headers["set-cookie"].filter((cookie: string) => cookie.startsWith(args[0] + "="));
192
- return;
193
- }
194
-
195
- let value = `${args[0]}=${args[1]}`;
196
-
197
- if (!res.headers["set-cookie"]) {
198
- res.headers["set-cookie"] = [value];
199
- } else {
200
- res.headers["set-cookie"] = [].concat(res.headers["set-cookie"], value as any);
201
- }
202
- };
203
-
204
- response.cookie("locale", "fr-FR");
205
- expect(res.headers).toEqual({
206
- "set-cookie": ["locale=fr-FR"],
207
- "x-request-id": "id"
208
- });
209
-
210
- response.cookie("filename", "test");
211
- expect(res.headers).toEqual({
212
- "set-cookie": ["locale=fr-FR", "filename=test"],
213
- "x-request-id": "id"
214
- });
215
-
216
- response.cookie("filename", null);
217
-
218
- expect(res.headers).toEqual({
219
- "set-cookie": ["filename=test"],
220
- "x-request-id": "id"
221
- });
222
- });
223
- });
224
- });
@@ -1,113 +0,0 @@
1
- import {ServerResponse} from "node:http";
2
-
3
- import {PlatformResponse} from "@tsed/platform-http";
4
- import Koa from "koa";
5
-
6
- declare global {
7
- namespace TsED {
8
- export interface Response extends Koa.Response {}
9
- }
10
- }
11
-
12
- /**
13
- * @platform
14
- * @koa
15
- */
16
- export class PlatformKoaResponse extends PlatformResponse<Koa.Response> {
17
- get ctx() {
18
- return this.raw.ctx;
19
- }
20
-
21
- get statusCode() {
22
- return this.raw.status;
23
- }
24
-
25
- get locals() {
26
- return this.ctx.state;
27
- }
28
-
29
- /**
30
- * Return the Node.js response object
31
- */
32
- getRes(): ServerResponse {
33
- return this.raw.res;
34
- }
35
-
36
- hasStatus() {
37
- // KOA set 404 by default
38
- return this.statusCode !== 404;
39
- }
40
-
41
- /**
42
- * Sets the HTTP status for the response.
43
- *
44
- * @param status
45
- */
46
- status(status: number) {
47
- this.raw.status = status;
48
-
49
- return this;
50
- }
51
-
52
- /**
53
- * Set `Content-Type` response header with `type` through `mime.lookup()`
54
- * when it does not contain "/", or set the Content-Type to `type` otherwise.
55
- *
56
- * Examples:
57
- *
58
- * res.type('.html');
59
- * res.type('html');
60
- * res.type('json');
61
- * res.type('application/json');
62
- * res.type('png');
63
- */
64
- contentType(contentType: string) {
65
- this.raw.type = contentType;
66
-
67
- return this;
68
- }
69
-
70
- getHeaders() {
71
- return this.raw.headers;
72
- }
73
-
74
- stream(data: any) {
75
- this.raw.body = data;
76
- return this;
77
- }
78
-
79
- getBody(): any {
80
- return this.raw.body;
81
- }
82
-
83
- cookie(name: string, value: string | null, opts?: TsED.SetCookieOpts) {
84
- if (value === null) {
85
- this.ctx.cookies.set(name);
86
- } else {
87
- this.ctx.cookies.set(name, value, opts);
88
- }
89
- return this;
90
- }
91
-
92
- protected json(data: any) {
93
- this.end(data);
94
- return this;
95
- }
96
-
97
- protected buffer(data: Buffer) {
98
- this.end(data);
99
- return this;
100
- }
101
-
102
- protected end(data?: string | Buffer) {
103
- if ([301, 302, 303, 307, 308].includes(this.statusCode)) {
104
- if (this.request.method === "HEAD") {
105
- this.getRes().end();
106
- } else {
107
- this.getRes().end(data);
108
- }
109
- } else {
110
- this.raw.body = data;
111
- }
112
- }
113
- }
package/vitest.config.mts DELETED
@@ -1,21 +0,0 @@
1
- // @ts-ignore
2
- import {presets} from "@tsed/vitest/presets";
3
- import {defineConfig} from "vitest/config";
4
-
5
- export default defineConfig(
6
- {
7
- ...presets,
8
- test: {
9
- ...presets.test,
10
- coverage: {
11
- ...presets.test.coverage,
12
- thresholds: {
13
- statements: 0,
14
- branches: 0,
15
- functions: 0,
16
- lines: 0
17
- }
18
- }
19
- }
20
- }
21
- );