@tsed/platform-koa 7.0.0-alpha.2 → 7.0.0-beta.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 (122) hide show
  1. package/lib/cjs/components/PlatformKoa.js +89 -0
  2. package/lib/cjs/components/PlatformKoa.js.map +1 -0
  3. package/lib/{decorators → cjs/decorators}/caseSensitive.js +1 -1
  4. package/lib/cjs/decorators/caseSensitive.js.map +1 -0
  5. package/lib/{decorators → cjs/decorators}/ctx.js +1 -1
  6. package/lib/cjs/decorators/ctx.js.map +1 -0
  7. package/lib/cjs/decorators/index.js +9 -0
  8. package/lib/cjs/decorators/index.js.map +1 -0
  9. package/lib/{decorators → cjs/decorators}/routerSettings.js +1 -1
  10. package/lib/cjs/decorators/routerSettings.js.map +1 -0
  11. package/lib/{decorators → cjs/decorators}/state.js +0 -0
  12. package/lib/cjs/decorators/state.js.map +1 -0
  13. package/lib/{decorators → cjs/decorators}/strict.js +1 -1
  14. package/lib/cjs/decorators/strict.js.map +1 -0
  15. package/lib/cjs/index.js +16 -0
  16. package/lib/cjs/index.js.map +1 -0
  17. package/lib/{interfaces → cjs/interfaces}/PlatformKoaSettings.js +0 -0
  18. package/lib/cjs/interfaces/PlatformKoaSettings.js.map +1 -0
  19. package/lib/{interfaces → cjs/interfaces}/index.js +1 -1
  20. package/lib/cjs/interfaces/index.js.map +1 -0
  21. package/lib/{middlewares → cjs/middlewares}/resourceNotFoundMiddleware.js +0 -0
  22. package/lib/cjs/middlewares/resourceNotFoundMiddleware.js.map +1 -0
  23. package/lib/{middlewares → cjs/middlewares}/staticsMiddleware.js +2 -2
  24. package/lib/cjs/middlewares/staticsMiddleware.js.map +1 -0
  25. package/lib/{services → cjs/services}/PlatformKoaApplication.js +5 -4
  26. package/lib/cjs/services/PlatformKoaApplication.js.map +1 -0
  27. package/lib/{services → cjs/services}/PlatformKoaHandler.js +0 -0
  28. package/lib/cjs/services/PlatformKoaHandler.js.map +1 -0
  29. package/lib/cjs/services/PlatformKoaRequest.js +44 -0
  30. package/lib/cjs/services/PlatformKoaRequest.js.map +1 -0
  31. package/lib/{services → cjs/services}/PlatformKoaResponse.js +8 -8
  32. package/lib/cjs/services/PlatformKoaResponse.js.map +1 -0
  33. package/lib/{services → cjs/services}/PlatformKoaRouter.js +7 -7
  34. package/lib/cjs/services/PlatformKoaRouter.js.map +1 -0
  35. package/lib/cjs/services/index.js +9 -0
  36. package/lib/cjs/services/index.js.map +1 -0
  37. package/lib/{utils → cjs/utils}/multer.js +1 -1
  38. package/lib/cjs/utils/multer.js.map +1 -0
  39. package/lib/esm/components/PlatformKoa.js +85 -0
  40. package/lib/esm/components/PlatformKoa.js.map +1 -0
  41. package/lib/esm/decorators/caseSensitive.js +26 -0
  42. package/lib/esm/decorators/caseSensitive.js.map +1 -0
  43. package/lib/esm/decorators/ctx.js +27 -0
  44. package/lib/esm/decorators/ctx.js.map +1 -0
  45. package/lib/esm/decorators/index.js +6 -0
  46. package/lib/esm/decorators/index.js.map +1 -0
  47. package/lib/esm/decorators/routerSettings.js +27 -0
  48. package/lib/esm/decorators/routerSettings.js.map +1 -0
  49. package/lib/esm/decorators/state.js +5 -0
  50. package/lib/esm/decorators/state.js.map +1 -0
  51. package/lib/esm/decorators/strict.js +27 -0
  52. package/lib/esm/decorators/strict.js.map +1 -0
  53. package/lib/esm/index.js +13 -0
  54. package/lib/esm/index.js.map +1 -0
  55. package/lib/esm/interfaces/PlatformKoaSettings.js +2 -0
  56. package/lib/esm/interfaces/PlatformKoaSettings.js.map +1 -0
  57. package/lib/esm/interfaces/index.js +2 -0
  58. package/lib/esm/interfaces/index.js.map +1 -0
  59. package/lib/esm/middlewares/resourceNotFoundMiddleware.js +16 -0
  60. package/lib/esm/middlewares/resourceNotFoundMiddleware.js.map +1 -0
  61. package/lib/esm/middlewares/staticsMiddleware.js +30 -0
  62. package/lib/esm/middlewares/staticsMiddleware.js.map +1 -0
  63. package/lib/esm/services/PlatformKoaApplication.js +29 -0
  64. package/lib/esm/services/PlatformKoaApplication.js.map +1 -0
  65. package/lib/esm/services/PlatformKoaHandler.js +56 -0
  66. package/lib/esm/services/PlatformKoaHandler.js.map +1 -0
  67. package/lib/esm/services/PlatformKoaRequest.js +40 -0
  68. package/lib/esm/services/PlatformKoaRequest.js.map +1 -0
  69. package/lib/esm/services/PlatformKoaResponse.js +101 -0
  70. package/lib/esm/services/PlatformKoaResponse.js.map +1 -0
  71. package/lib/esm/services/PlatformKoaRouter.js +42 -0
  72. package/lib/esm/services/PlatformKoaRouter.js.map +1 -0
  73. package/lib/esm/services/index.js +6 -0
  74. package/lib/esm/services/index.js.map +1 -0
  75. package/lib/esm/utils/multer.js +51 -0
  76. package/lib/esm/utils/multer.js.map +1 -0
  77. package/lib/types/components/PlatformKoa.d.ts +45 -0
  78. package/lib/{decorators → types/decorators}/caseSensitive.d.ts +0 -0
  79. package/lib/{decorators → types/decorators}/ctx.d.ts +0 -0
  80. package/lib/{decorators → types/decorators}/index.d.ts +0 -0
  81. package/lib/{decorators → types/decorators}/routerSettings.d.ts +0 -0
  82. package/lib/{decorators → types/decorators}/state.d.ts +0 -0
  83. package/lib/{decorators → types/decorators}/strict.d.ts +0 -0
  84. package/lib/{index.d.ts → types/index.d.ts} +0 -0
  85. package/lib/{interfaces → types/interfaces}/PlatformKoaSettings.d.ts +0 -0
  86. package/lib/{interfaces → types/interfaces}/index.d.ts +0 -0
  87. package/lib/{middlewares → types/middlewares}/resourceNotFoundMiddleware.d.ts +0 -0
  88. package/lib/{middlewares → types/middlewares}/staticsMiddleware.d.ts +0 -0
  89. package/lib/{services → types/services}/PlatformKoaApplication.d.ts +0 -0
  90. package/lib/{services → types/services}/PlatformKoaHandler.d.ts +0 -0
  91. package/lib/{services → types/services}/PlatformKoaRequest.d.ts +1 -1
  92. package/lib/{services → types/services}/PlatformKoaResponse.d.ts +2 -2
  93. package/lib/{services → types/services}/PlatformKoaRouter.d.ts +0 -0
  94. package/lib/{services → types/services}/index.d.ts +0 -0
  95. package/lib/{utils → types/utils}/multer.d.ts +0 -0
  96. package/package.json +33 -27
  97. package/tsconfig.compile.esm.json +23 -0
  98. package/lib/components/PlatformKoa.d.ts +0 -32
  99. package/lib/components/PlatformKoa.js +0 -65
  100. package/lib/components/PlatformKoa.js.map +0 -1
  101. package/lib/decorators/caseSensitive.js.map +0 -1
  102. package/lib/decorators/ctx.js.map +0 -1
  103. package/lib/decorators/index.js +0 -9
  104. package/lib/decorators/index.js.map +0 -1
  105. package/lib/decorators/routerSettings.js.map +0 -1
  106. package/lib/decorators/state.js.map +0 -1
  107. package/lib/decorators/strict.js.map +0 -1
  108. package/lib/index.js +0 -16
  109. package/lib/index.js.map +0 -1
  110. package/lib/interfaces/PlatformKoaSettings.js.map +0 -1
  111. package/lib/interfaces/index.js.map +0 -1
  112. package/lib/middlewares/resourceNotFoundMiddleware.js.map +0 -1
  113. package/lib/middlewares/staticsMiddleware.js.map +0 -1
  114. package/lib/services/PlatformKoaApplication.js.map +0 -1
  115. package/lib/services/PlatformKoaHandler.js.map +0 -1
  116. package/lib/services/PlatformKoaRequest.js +0 -44
  117. package/lib/services/PlatformKoaRequest.js.map +0 -1
  118. package/lib/services/PlatformKoaResponse.js.map +0 -1
  119. package/lib/services/PlatformKoaRouter.js.map +0 -1
  120. package/lib/services/index.js +0 -9
  121. package/lib/services/index.js.map +0 -1
  122. package/lib/utils/multer.js.map +0 -1
@@ -0,0 +1,45 @@
1
+ /// <reference types="koa__router" />
2
+ import KoaRouter from "@koa/router";
3
+ import { PlatformAdapter, PlatformApplication, PlatformBuilder, PlatformHandler, PlatformRequest, PlatformResponse, PlatformRouter } from "@tsed/common";
4
+ import { Type } from "@tsed/core";
5
+ import Koa from "koa";
6
+ import { PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, PlatformKoaResponse, PlatformKoaRouter } from "../services";
7
+ /**
8
+ * @platform
9
+ * @koa
10
+ */
11
+ export declare class PlatformKoa implements PlatformAdapter<Koa, KoaRouter> {
12
+ private platform;
13
+ readonly providers: ({
14
+ provide: typeof PlatformResponse;
15
+ useClass: typeof PlatformKoaResponse;
16
+ } | {
17
+ provide: typeof PlatformRequest;
18
+ useClass: typeof PlatformKoaRequest;
19
+ } | {
20
+ provide: typeof PlatformHandler;
21
+ useClass: typeof PlatformKoaHandler;
22
+ } | {
23
+ provide: typeof PlatformRouter;
24
+ useClass: typeof PlatformKoaRouter;
25
+ } | {
26
+ provide: typeof PlatformApplication;
27
+ useClass: typeof PlatformKoaApplication;
28
+ })[];
29
+ constructor(platform: PlatformBuilder<Koa, KoaRouter>);
30
+ /**
31
+ * Create new serverless application. In this mode, the component scan are disabled.
32
+ * @param module
33
+ * @param settings
34
+ */
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;
45
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -21,7 +21,7 @@ declare global {
21
21
  */
22
22
  export declare class PlatformKoaRequest extends PlatformRequest<Koa.Request> {
23
23
  #private;
24
- constructor(event: IncomingEvent);
24
+ constructor(event: IncomingEvent, $ctx: PlatformContext);
25
25
  get protocol(): string;
26
26
  get host(): string;
27
27
  get secure(): boolean;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { IncomingEvent, PlatformResponse } from "@tsed/common";
2
+ import { IncomingEvent, PlatformContext, PlatformResponse } from "@tsed/common";
3
3
  import { ServerResponse } from "http";
4
4
  import Koa from "koa";
5
5
  declare global {
@@ -14,7 +14,7 @@ declare global {
14
14
  */
15
15
  export declare class PlatformKoaResponse extends PlatformResponse<Koa.Response> {
16
16
  #private;
17
- constructor(event: IncomingEvent);
17
+ constructor(event: IncomingEvent, $ctx: PlatformContext);
18
18
  get statusCode(): number;
19
19
  get locals(): Koa.DefaultState;
20
20
  /**
File without changes
File without changes
package/package.json CHANGED
@@ -1,11 +1,23 @@
1
1
  {
2
2
  "name": "@tsed/platform-koa",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.0.0-beta.1",
4
4
  "description": "Koa package for Ts.ED framework",
5
- "source": "./src/index.ts",
6
- "main": "./lib/index.js",
7
- "typings": "./lib/index.d.ts",
8
5
  "private": false,
6
+ "source": "./src/index.ts",
7
+ "main": "./lib/cjs/index.js",
8
+ "typings": "./lib/types/index.d.ts",
9
+ "exports": {
10
+ "types": "./lib/types/index.d.ts",
11
+ "import": "./lib/esm/index.js",
12
+ "require": "./lib/cjs/index.js",
13
+ "default": "./lib/esm/index.js"
14
+ },
15
+ "scripts": {
16
+ "build": "yarn run build:esm && yarn run build:cjs",
17
+ "build:cjs": "tsc --build tsconfig.compile.json",
18
+ "build:esm": "tsc --build tsconfig.compile.esm.json",
19
+ "start": "ts-node -r tsconfig-paths/register test/app/index.ts"
20
+ },
9
21
  "keywords": [
10
22
  "Koa",
11
23
  "TypeScript",
@@ -35,16 +47,12 @@
35
47
  },
36
48
  "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/platform/platform-koa",
37
49
  "repository": "https://github.com/tsedio/tsed",
38
- "scripts": {
39
- "build": "tsc --build tsconfig.compile.json",
40
- "start": "ts-node -r tsconfig-paths/register test/app/index.ts"
41
- },
42
50
  "devDependencies": {
43
51
  "@koa/cors": "3.1.0",
44
- "@tsed/common": "7.0.0-alpha.2",
45
- "@tsed/core": "7.0.0-alpha.2",
46
- "@tsed/di": "7.0.0-alpha.2",
47
- "@tsed/platform-test-utils": "7.0.0-alpha.2",
52
+ "@tsed/common": "7.0.0-beta.1",
53
+ "@tsed/core": "7.0.0-beta.1",
54
+ "@tsed/di": "7.0.0-beta.1",
55
+ "@tsed/platform-test-utils": "7.0.0-beta.1",
48
56
  "@types/koa": "2.11.3",
49
57
  "@types/koa-bodyparser": "4.3.0",
50
58
  "@types/koa-compose": "3.2.5",
@@ -69,20 +77,18 @@
69
77
  "tslib": "2.2.0"
70
78
  },
71
79
  "peerDependencies": {
72
- "@tsed/common": "^7.0.0-alpha.2",
73
- "@tsed/core": "^7.0.0-alpha.2",
74
- "@tsed/di": "^7.0.0-alpha.2",
75
- "@tsed/json-mapper": "^7.0.0-alpha.2",
76
- "@tsed/logger": "^5.16.0",
77
- "@tsed/openspec": "^7.0.0-alpha.2",
78
- "@tsed/schema": "^7.0.0-alpha.2",
79
- "koa": "2.13.0",
80
- "koa-bodyparser": "4.3.0",
81
- "koa-compress": "5.0.1",
82
- "koa-override": "3.0.0",
83
- "koa-session": "6.2.0"
84
- },
85
- "publishConfig": {
86
- "tag": "alpha"
80
+ "@tsed/common": "^7.0.0-beta.1",
81
+ "@tsed/core": "^7.0.0-beta.1",
82
+ "@tsed/di": "^7.0.0-beta.1",
83
+ "@tsed/json-mapper": "^7.0.0-beta.1",
84
+ "@tsed/logger": ">=6.0.0",
85
+ "@tsed/openspec": "^7.0.0-beta.1",
86
+ "@tsed/schema": "^7.0.0-beta.1",
87
+ "koa": ">=2.13.0",
88
+ "koa-bodyparser": ">=4.3.0",
89
+ "koa-compress": ">=5.0.1",
90
+ "koa-override": ">=3.0.0",
91
+ "koa-qs": ">=3.0.0",
92
+ "koa-session": ">=6.2.0"
87
93
  }
88
94
  }
@@ -0,0 +1,23 @@
1
+ {
2
+ "extends": "./tsconfig.compile.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "module": "ES2020",
6
+ "rootDir": "src",
7
+ "outDir": "./lib/esm",
8
+ "declaration": true,
9
+ "declarationDir": "./lib/types"
10
+ },
11
+ "exclude": [
12
+ "node_modules",
13
+ "test",
14
+ "lib",
15
+ "benchmark",
16
+ "coverage",
17
+ "spec",
18
+ "**/*.benchmark.ts",
19
+ "**/*.spec.ts",
20
+ "keys",
21
+ "jest.config.js"
22
+ ]
23
+ }
@@ -1,32 +0,0 @@
1
- /// <reference types="koa__router" />
2
- import KoaRouter from "@koa/router";
3
- import { PlatformApplication, PlatformBuilder, PlatformHandler, PlatformRequest, PlatformResponse, PlatformRouter } from "@tsed/common";
4
- import { Type } from "@tsed/core";
5
- import Koa from "koa";
6
- import { PlatformKoaApplication, PlatformKoaHandler, PlatformKoaRequest, PlatformKoaResponse, PlatformKoaRouter } from "../services";
7
- /**
8
- * @platform
9
- * @koa
10
- */
11
- export declare class PlatformKoa extends PlatformBuilder<Koa, KoaRouter> {
12
- static providers: ({
13
- provide: typeof PlatformResponse;
14
- useClass: typeof PlatformKoaResponse;
15
- } | {
16
- provide: typeof PlatformRequest;
17
- useClass: typeof PlatformKoaRequest;
18
- } | {
19
- provide: typeof PlatformHandler;
20
- useClass: typeof PlatformKoaHandler;
21
- } | {
22
- provide: typeof PlatformRouter;
23
- useClass: typeof PlatformKoaRouter;
24
- } | {
25
- provide: typeof PlatformApplication;
26
- useClass: typeof PlatformKoaApplication;
27
- })[];
28
- static bootstrap(module: Type<any>, settings?: Partial<TsED.Configuration>): Promise<PlatformKoa>;
29
- protected createInjector(module: Type<any>, settings: any): void;
30
- protected useRouter(): this;
31
- protected useContext(): this;
32
- }
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PlatformKoa = void 0;
4
- const common_1 = require("@tsed/common");
5
- const resourceNotFoundMiddleware_1 = require("../middlewares/resourceNotFoundMiddleware");
6
- const services_1 = require("../services");
7
- /**
8
- * @platform
9
- * @koa
10
- */
11
- class PlatformKoa extends common_1.PlatformBuilder {
12
- static async bootstrap(module, settings = {}) {
13
- return this.build(PlatformKoa).bootstrap(module, settings);
14
- }
15
- createInjector(module, settings) {
16
- super.createInjector(module, settings);
17
- const listener = (error, ctx) => {
18
- var _a;
19
- (_a = this.injector.get(common_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(error, ctx.request.$ctx);
20
- };
21
- this.app.getApp().silent = true;
22
- this.app.getApp().on("error", listener);
23
- }
24
- useRouter() {
25
- this.app.getApp().use(resourceNotFoundMiddleware_1.resourceNotFoundMiddleware).use(this.app.getRouter().routes()).use(this.app.getRouter().allowedMethods());
26
- return this;
27
- }
28
- useContext() {
29
- this.logger.info("Mount app context");
30
- const invoke = common_1.createContext(this.injector);
31
- this.app.getApp().use(async (ctx, next) => {
32
- await invoke({
33
- request: ctx.request,
34
- response: ctx.response,
35
- ctx
36
- });
37
- return next();
38
- });
39
- return this;
40
- }
41
- }
42
- exports.PlatformKoa = PlatformKoa;
43
- PlatformKoa.providers = [
44
- {
45
- provide: common_1.PlatformResponse,
46
- useClass: services_1.PlatformKoaResponse
47
- },
48
- {
49
- provide: common_1.PlatformRequest,
50
- useClass: services_1.PlatformKoaRequest
51
- },
52
- {
53
- provide: common_1.PlatformHandler,
54
- useClass: services_1.PlatformKoaHandler
55
- },
56
- {
57
- provide: common_1.PlatformRouter,
58
- useClass: services_1.PlatformKoaRouter
59
- },
60
- {
61
- provide: common_1.PlatformApplication,
62
- useClass: services_1.PlatformKoaApplication
63
- }
64
- ];
65
- //# sourceMappingURL=PlatformKoa.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformKoa.js","sourceRoot":"","sources":["../../src/components/PlatformKoa.ts"],"names":[],"mappings":";;;AACA,yCAUsB;AAGtB,0FAAqF;AACrF,0CAAmI;AAEnI;;;GAGG;AACH,MAAa,WAAY,SAAQ,wBAA+B;IAwB9D,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,MAAiB,EAAE,WAAwC,EAAE;QAClF,OAAO,IAAI,CAAC,KAAK,CAAc,WAAW,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC1E,CAAC;IAES,cAAc,CAAC,MAAiB,EAAE,QAAa;QACvD,KAAK,CAAC,cAAc,CAAC,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,OAAO,EAAE,yBAAgB;QACzB,QAAQ,EAAE,8BAAmB;KAC9B;IACD;QACE,OAAO,EAAE,wBAAe;QACxB,QAAQ,EAAE,6BAAkB;KAC7B;IACD;QACE,OAAO,EAAE,wBAAe;QACxB,QAAQ,EAAE,6BAAkB;KAC7B;IACD;QACE,OAAO,EAAE,uBAAc;QACvB,QAAQ,EAAE,4BAAiB;KAC5B;IACD;QACE,OAAO,EAAE,4BAAmB;QAC5B,QAAQ,EAAE,iCAAsB;KACjC;CACF,CAAC","sourcesContent":["import KoaRouter from \"@koa/router\";\nimport {\n createContext,\n PlatformApplication,\n PlatformBuilder,\n PlatformExceptions,\n PlatformHandler,\n PlatformRequest,\n PlatformResponse,\n PlatformRouter,\n PlatformViews\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 extends PlatformBuilder<Koa, KoaRouter> {\n static 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 static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}): Promise<PlatformKoa> {\n return this.build<PlatformKoa>(PlatformKoa).bootstrap(module, settings);\n }\n\n protected createInjector(module: Type<any>, settings: any) {\n super.createInjector(module, settings);\n\n const listener: any = (error: any, ctx: Koa.Context) => {\n this.injector.get<PlatformExceptions>(PlatformExceptions)?.catch(error, ctx.request.$ctx);\n };\n\n this.app.getApp().silent = true;\n this.app.getApp().on(\"error\", listener);\n }\n\n protected useRouter(): this {\n this.app.getApp().use(resourceNotFoundMiddleware).use(this.app.getRouter().routes()).use(this.app.getRouter().allowedMethods());\n\n return this;\n }\n\n protected useContext(): this {\n this.logger.info(\"Mount app context\");\n\n const invoke = createContext(this.injector);\n\n this.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"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"caseSensitive.js","sourceRoot":"","sources":["../../src/decorators/caseSensitive.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,aAAa,CAAC,SAAkB;IAC9C,OAAO,+BAAc,CAAC,EAAC,SAAS,EAAC,CAAC,CAAC;AACrC,CAAC;AAFD,sCAEC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @CaseSensitive(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @returns {Function}\n * @decorator\n * @koa\n * @param sensitive\n */\nexport function CaseSensitive(sensitive: boolean) {\n return RouterSettings({sensitive});\n}\n"]}
@@ -1 +0,0 @@
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;QACd,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({\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 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./routerSettings"), exports);
5
- tslib_1.__exportStar(require("./caseSensitive"), exports);
6
- tslib_1.__exportStar(require("./strict"), exports);
7
- tslib_1.__exportStar(require("./state"), exports);
8
- tslib_1.__exportStar(require("./ctx"), exports);
9
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,0DAAgC;AAChC,mDAAyB;AACzB,kDAAwB;AACxB,gDAAsB","sourcesContent":["export * from \"./routerSettings\";\nexport * from \"./caseSensitive\";\nexport * from \"./strict\";\nexport * from \"./state\";\nexport * from \"./ctx\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"routerSettings.js","sourceRoot":"","sources":["../../src/decorators/routerSettings.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,qCAAsC;AAGtC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,cAAc,CAAC,aAA4B;IACzD,OAAO,iBAAU,CAAC,uBAAc,EAAE,aAAa,CAAC,CAAC;AACnD,CAAC;AAFD,wCAEC","sourcesContent":["import {ROUTER_OPTIONS} from \"@tsed/common\";\nimport {StoreMerge} from \"@tsed/core\";\nimport {RouterOptions} from \"@koa/router\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @RouterSettings({sensitive: true})\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * sensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @returns {(target:any)=>void}\n * @decorator\n * @param routerOptions\n * @koa\n */\nexport function RouterSettings(routerOptions: RouterOptions): Function {\n return StoreMerge(ROUTER_OPTIONS, routerOptions);\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/decorators/state.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AAwCpC,SAAgB,KAAK,CAAC,GAAG,IAAW;IAClC,OAAQ,eAAc,CAAC,GAAG,IAAI,CAAC,CAAC;AAClC,CAAC;AAFD,sBAEC","sourcesContent":["import {Locals} from \"@tsed/common\";\n\n/**\n * State return the value from koa.ctx.state object.\n *\n * #### Example\n *\n * ```typescript\n * * @Middleware()\n * class StateMiddleware {\n * use(@State() state: any) {\n * // set some on locals\n * state.user = \"user\"\n * }\n * }\n *\n * @Controller('/')\n * @UseBefore(StateMiddleware)\n * class MyCtrl {\n * @Get('/')\n * @View('home.ejs') // will use locals and returned data to render the page\n * get(@State('user') user: any) {\n * console.log('user', user);\n *\n * return {\n * description: 'Hello world'\n * }\n * }\n * }\n * ```\n *\n * @param expression The path of the property to get.\n * @decorator\n * @operation\n * @input\n * @response\n * @koa\n */\nexport function State(expression: string): ParameterDecorator;\nexport function State(): ParameterDecorator;\nexport function State(...args: any[]): ParameterDecorator {\n return (Locals as any)(...args);\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"strict.js","sourceRoot":"","sources":["../../src/decorators/strict.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,MAAM,CAAC,MAAe;IACpC,OAAO,+BAAc,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC;AAClC,CAAC;AAFD,wBAEC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @Strict(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @param strict\n * @returns {Function}\n * @decorator\n * @koa\n */\nexport function Strict(strict: boolean) {\n return RouterSettings({strict});\n}\n"]}
package/lib/index.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const common_1 = require("@tsed/common");
5
- const PlatformKoa_1 = require("./components/PlatformKoa");
6
- common_1.PlatformTest.platformBuilder = PlatformKoa_1.PlatformKoa;
7
- common_1.PlatformBuilder.currentPlatform = PlatformKoa_1.PlatformKoa;
8
- // interfaces
9
- tslib_1.__exportStar(require("./interfaces"), exports);
10
- // decorators
11
- tslib_1.__exportStar(require("./decorators"), exports);
12
- // services
13
- tslib_1.__exportStar(require("./services"), exports);
14
- // components
15
- tslib_1.__exportStar(require("./components/PlatformKoa"), exports);
16
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA2D;AAC3D,0DAAqD;AAErD,qBAAY,CAAC,eAAe,GAAG,yBAAW,CAAC;AAC3C,wBAAe,CAAC,eAAe,GAAG,yBAAkB,CAAC;AAErD,aAAa;AACb,uDAA6B;AAE7B,aAAa;AACb,uDAA6B;AAE7B,WAAW;AACX,qDAA2B;AAE3B,aAAa;AACb,mEAAyC","sourcesContent":["import {PlatformBuilder, PlatformTest} from \"@tsed/common\";\nimport {PlatformKoa} from \"./components/PlatformKoa\";\n\nPlatformTest.platformBuilder = PlatformKoa;\nPlatformBuilder.currentPlatform = PlatformKoa as any;\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 +0,0 @@
1
- {"version":3,"file":"PlatformKoaSettings.js","sourceRoot":"","sources":["../../src/interfaces/PlatformKoaSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {RouterOptions} from \"@koa/router\";\n\nexport interface PlatformKoaSettings {\n /**\n * Global configuration for the Express.Router. See express [documentation](http://expressjs.com/en/api.html#express.router).\n */\n router: RouterOptions;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAGA,gEAAsC","sourcesContent":["import Koa from \"koa\";\nimport {PlatformKoaSettings} from \"./PlatformKoaSettings\";\n\nexport * from \"./PlatformKoaSettings\";\n\ndeclare global {\n namespace TsED {\n export interface Configuration {\n /**\n * Configuration related to Koa platform application.\n */\n koa: PlatformKoaSettings;\n }\n\n export interface NextFunction extends Koa.Next {}\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"resourceNotFoundMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/resourceNotFoundMiddleware.ts"],"names":[],"mappings":";;;AAAA,yCAAiE;AAEjE;;;;GAIG;AACI,KAAK,UAAU,0BAA0B,CAAC,GAAQ,EAAE,IAAS;;IAClE,MAAM,IAAI,GAAoB,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/C,MAAM,IAAI,EAAE,CAAC;IACb,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC;IAEjC,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE;QACpC,MAAA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAqB,2BAAkB,CAAC,0CAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;KACnF;AACH,CAAC;AARD,gEAQC","sourcesContent":["import {PlatformContext, PlatformExceptions} from \"@tsed/common\";\n\n/**\n * @ignore\n * @param ctx\n * @param next\n */\nexport async function resourceNotFoundMiddleware(ctx: any, next: any) {\n const $ctx: PlatformContext = ctx.request.$ctx;\n await next();\n const status = ctx.status || 404;\n\n if (status === 404 && !$ctx.isDone()) {\n $ctx.injector.get<PlatformExceptions>(PlatformExceptions)?.resourceNotFound($ctx);\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"staticsMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/staticsMiddleware.ts"],"names":[],"mappings":";;;;AAEA,gEAA4B;AAE5B;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,OAA+B;IAC/D,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK;QAAE,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,YAAY,CAAC;IAE3E,OAAO,KAAK,EAAE,GAAY,EAAE,IAAS,EAAE,EAAE;QACvC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;YACrD,IAAI,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;YAEpB,IAAI,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,aAAa,KAAK,GAAG,EAAE;gBAClD,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;aACzE;YACD,IAAI;gBACF,MAAM,IAAI,GAAG,MAAM,kBAAI,CAAC,GAAU,EAAE,IAAI,EAAE,OAA2B,CAAC,CAAC;gBAEvE,IAAI,IAAI,EAAE;oBACR,OAAO;iBACR;aACF;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;oBACtB,MAAM,GAAG,CAAC;iBACX;aACF;SACF;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AAzBD,8CAyBC","sourcesContent":["import {PlatformStaticsOptions} from \"@tsed/common\";\nimport type {Context} from \"koa\";\nimport send from \"koa-send\";\n\n/**\n * @ignore\n * @param options\n */\nexport function staticsMiddleware(options: PlatformStaticsOptions): any {\n if (options.index !== false) options.index = options.index || \"index.html\";\n\n return async (ctx: Context, next: any) => {\n if ([\"GET\", \"HEAD\"].includes(ctx.method) && !ctx.body) {\n let path = ctx.path;\n\n if (ctx._matchedRoute && ctx._matchedRoute !== \"/\") {\n path = path.replace(String(ctx._matchedRoute).replace(\"/(.*)\", \"\"), \"\");\n }\n try {\n const done = await send(ctx as any, path, options as send.SendOptions);\n\n if (done) {\n return;\n }\n } catch (err) {\n if (err.status !== 404) {\n throw err;\n }\n }\n }\n\n return next();\n };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformKoaApplication.js","sourceRoot":"","sources":["../../src/services/PlatformKoaApplication.ts"],"names":[],"mappings":";;;;AACA,yCAAyF;AACzF,sDAAsB;AACtB,2DAAsD;AAEtD,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAQhC;;;GAGG;AACH,IAAa,sBAAsB,GAAnC,MAAa,sBAAuB,SAAQ,qCAAiB;IAI3D,YAAsB,eAAgC,EAAmB,aAA4B;QACnG,KAAK,CAAC,eAAe,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC;QAE1C,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,aAAG,EAAE,CAAC;QACxD,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACjC,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;IAClC,CAAC;CACF,CAAA;AAlBY,sBAAsB;IAIpB,mBAAA,eAAM,EAAE,CAAA,EAAoC,mBAAA,sBAAa,EAAE,CAAA;6CAAjC,wBAAe;GAJ3C,sBAAsB,CAkBlC;AAlBY,wDAAsB","sourcesContent":["import KoaRouter from \"@koa/router\";\nimport {Configuration, Inject, PlatformApplication, PlatformHandler} from \"@tsed/common\";\nimport Koa from \"koa\";\nimport {PlatformKoaRouter} from \"./PlatformKoaRouter\";\n\nconst koaQs = require(\"koa-qs\");\n\ndeclare global {\n namespace TsED {\n export interface Application extends Koa {}\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformKoaApplication extends PlatformKoaRouter implements PlatformApplication<Koa, KoaRouter> {\n app: Koa;\n rawApp: Koa;\n\n constructor(@Inject() platformHandler: PlatformHandler, @Configuration() configuration: Configuration) {\n super(platformHandler, configuration, {});\n\n this.rawApp = configuration.get(\"koa.app\") || new Koa();\n koaQs(this.rawApp, \"extended\");\n }\n\n getApp(): Koa {\n return this.rawApp;\n }\n\n callback(): any {\n return this.getApp().callback();\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformKoaHandler.js","sourceRoot":"","sources":["../../src/services/PlatformKoaHandler.ts"],"names":[],"mappings":";;;AAAA,yCAA8G;AAE9G,gCAA8B;AAE9B,MAAM,cAAc,GAAG,CAAC,oBAAW,CAAC,QAAQ,EAAE,oBAAW,CAAC,UAAU,EA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AAE,IAAI,EAAE,QAAQ,EAAC,GAAG,cAAc,CAAC;QAE9C,uBAAuB;QACvB,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE;YACjB,OAAO;SACR;QAED,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAElB,IAAI,CAAC,IAAI,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE;YAC/B,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAE7B,OAAO;SACR;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,cAAgC;QAC3D,MAAM,EAAC,IAAI,EAAC,GAAG,cAAc,CAAC;QAE9B,IAAI;YACF,OAAO,MAAM,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;SACjD;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,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;AAhED,gDAgEC","sourcesContent":["import {HandlerMetadata, HandlerType, OnRequestOptions, PlatformContext, PlatformHandler} from \"@tsed/common\";\nimport Koa from \"koa\";\nimport \"./PlatformKoaRequest\";\n\nconst OVERRIDE_TYPES = [HandlerType.ENDPOINT, HandlerType.MIDDLEWARE, HandlerType.ERR_MIDDLEWARE, HandlerType.CTX_FN];\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 if (OVERRIDE_TYPES.includes(metadata.type)) {\n const handler = this.compileHandler(metadata);\n return async (ctx: Koa.Context, next: Koa.Next) => handler({next, $ctx: ctx.request.$ctx});\n }\n\n return super.createRawHandler(metadata);\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"]}
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var _ctx;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.PlatformKoaRequest = void 0;
5
- const tslib_1 = require("tslib");
6
- require("@koa/router");
7
- const common_1 = require("@tsed/common");
8
- /**
9
- * @platform
10
- * @koa
11
- */
12
- class PlatformKoaRequest extends common_1.PlatformRequest {
13
- constructor(event) {
14
- super(event);
15
- _ctx.set(this, void 0);
16
- tslib_1.__classPrivateFieldSet(this, _ctx, this.raw.ctx);
17
- }
18
- get protocol() {
19
- return tslib_1.__classPrivateFieldGet(this, _ctx).request.protocol;
20
- }
21
- get host() {
22
- return tslib_1.__classPrivateFieldGet(this, _ctx).request.host;
23
- }
24
- get secure() {
25
- return tslib_1.__classPrivateFieldGet(this, _ctx).request.secure;
26
- }
27
- get cookies() {
28
- return tslib_1.__classPrivateFieldGet(this, _ctx).cookie || tslib_1.__classPrivateFieldGet(this, _ctx).cookies;
29
- }
30
- get session() {
31
- return tslib_1.__classPrivateFieldGet(this, _ctx).session;
32
- }
33
- getReq() {
34
- return this.raw.req;
35
- }
36
- destroy() {
37
- // @ts-ignore
38
- tslib_1.__classPrivateFieldSet(this, _ctx, null);
39
- return super.destroy();
40
- }
41
- }
42
- exports.PlatformKoaRequest = PlatformKoaRequest;
43
- _ctx = new WeakMap();
44
- //# sourceMappingURL=PlatformKoaRequest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformKoaRequest.js","sourceRoot":"","sources":["../../src/services/PlatformKoaRequest.ts"],"names":[],"mappings":";;;;;AAAA,uBAAqB;AACrB,yCAA6E;AAiB7E;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,wBAA4B;IAGlE,YAAY,KAAoB;QAC9B,KAAK,CAAC,KAAK,CAAC,CAAC;QAHf,uBAAkB;QAIhB,+BAAA,IAAI,QAAQ,IAAI,CAAC,GAAG,CAAC,GAAG,EAAC;IAC3B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,2CAAU,OAAO,CAAC,QAAQ,CAAC;IACpC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,2CAAU,OAAO,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,2CAAU,OAAO,CAAC,MAAM,CAAC;IAClC,CAAC;IAED,IAAI,OAAO;QACT,OAAO,2CAAU,MAAM,IAAI,2CAAU,OAAO,CAAC;IAC/C,CAAC;IAED,IAAI,OAAO;QACT,OAAO,2CAAU,OAAO,CAAC;IAC3B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CAAC;IAED,OAAO;QACL,aAAa;QACb,+BAAA,IAAI,QAAQ,IAAI,EAAC;QACjB,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF;AArCD,gDAqCC","sourcesContent":["import \"@koa/router\";\nimport {IncomingEvent, PlatformContext, PlatformRequest} from \"@tsed/common\";\nimport {IncomingMessage} from \"http\";\nimport Koa from \"koa\";\n\ndeclare module \"koa\" {\n export interface Request {\n id: string;\n $ctx: PlatformContext;\n }\n}\n\ndeclare global {\n namespace TsED {\n export interface Request extends Koa.Request {}\n }\n}\n\n/**\n * @platform\n * @koa\n */\nexport class PlatformKoaRequest extends PlatformRequest<Koa.Request> {\n #ctx: Koa.Context;\n\n constructor(event: IncomingEvent) {\n super(event);\n this.#ctx = this.raw.ctx;\n }\n\n get protocol(): string {\n return this.#ctx.request.protocol;\n }\n\n get host(): string {\n return this.#ctx.request.host;\n }\n\n get secure(): boolean {\n return this.#ctx.request.secure;\n }\n\n get cookies(): {[p: string]: any} {\n return this.#ctx.cookie || this.#ctx.cookies;\n }\n\n get session(): any {\n return this.#ctx.session;\n }\n\n getReq(): IncomingMessage {\n return this.raw.req;\n }\n\n destroy() {\n // @ts-ignore\n this.#ctx = null;\n return super.destroy();\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformKoaResponse.js","sourceRoot":"","sources":["../../src/services/PlatformKoaResponse.ts"],"names":[],"mappings":";;;;;AAAA,yCAA6D;AAG7D,yCAA8C;AAE9C,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAQvC;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,yBAA8B;IAGrE,YAAY,KAAoB;QAC9B,KAAK,CAAC,KAAK,CAAC,CAAC;QAHf,uBAAkB;QAIhB,+BAAA,IAAI,QAAQ,IAAI,CAAC,GAAG,CAAC,GAAG,EAAC;IAC3B,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,2CAAU,KAAK,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACtB,CA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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,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE9C,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA5GD,kDA4GC","sourcesContent":["import {IncomingEvent, PlatformResponse} from \"@tsed/common\";\nimport {ServerResponse} from \"http\";\nimport Koa from \"koa\";\nimport {getStatusMessage} from \"@tsed/schema\";\n\nconst encodeUrl = require(\"encodeurl\");\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 #ctx: Koa.Context;\n\n constructor(event: IncomingEvent) {\n super(event);\n this.#ctx = 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() {\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));\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"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"PlatformKoaRouter.js","sourceRoot":"","sources":["../../src/services/PlatformKoaRouter.ts"],"names":[],"mappings":";;;;AAAA,iEAAoC;AAGpC,yCAOsB;AACtB,iCAA+C;AAE/C,wEAAmE;AACnE,4CAA0C;AAY1C,aAAa;AACb,gBAAS,CAAC,SAAS,CAAC,OAAO,GAAG,gBAAS,CAAC,SAAS,CAAC,KAAK,CAAC;AACxD,gBAAS,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,KAAK,CAAC,GAAG,IAAW;IACvD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IACtC,IAAI,OAAO,EAAE;QACX,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE;YACvB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;SACtB;KACF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,IAAa,iBAAiB,GAA9B,MAAa,iBAAkB,SAAQ,uBAAyB;IAC9D,YACE,QAAyB,EACR,aAA4B,EACZ,aAAkB;;QAEnD,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEhB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA,MAAA,aAAa,CAAC,GAAG,0CAAE,MAAM,KAAI,EAAE,EAAE,aAAa,CAAC,CAAC;QAClF,IAAI,CAAC,SAAS,GAAG,IAAI,gBAAS,CAAC,OAAO,CAAQ,CAAC;IACjD,CAAC;IAED,QAAQ;QACN,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,CAAC,OAA+B;QACpC,OAAO,kBAAS,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,CAAC,IAAY,EAAE,OAA+B;QACnD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,qCAAiB,CAAC,OAAO,CAAQ,CAAC,CAAC;QAE5D,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAzBY,iBAAiB;IAGzB,mBAAA,kBAAa,EAAE,CAAA;IACf,mBAAA,WAAM,CAAC,gCAAuB,CAAC,CAAA;6CAFtB,wBAAe;GAFhB,iBAAiB,CAyB7B;AAzBY,8CAAiB","sourcesContent":["import KoaRouter from \"@koa/router\";\nimport {RouterOptions as KoaRouterOptions} from \"@koa/router\";\n\nimport {\n PLATFORM_ROUTER_OPTIONS,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRouter,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {Configuration, Inject} from \"@tsed/di\";\nimport send from \"koa-send\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {getMulter} from \"../utils/multer\";\n\ndeclare global {\n namespace TsED {\n export interface Router extends KoaRouter {}\n\n export interface RouterOptions extends KoaRouterOptions {}\n\n export interface StaticsOptions extends send.SendOptions {}\n }\n}\n\n// @ts-ignore\nKoaRouter.prototype.$$match = KoaRouter.prototype.match;\nKoaRouter.prototype.match = function match(...args: any[]) {\n const matched = this.$$match(...args);\n if (matched) {\n if (matched.path.length) {\n matched.route = true;\n }\n }\n\n return matched;\n};\n\nexport class PlatformKoaRouter extends PlatformRouter<KoaRouter> {\n constructor(\n platform: PlatformHandler,\n @Configuration() configuration: Configuration,\n @Inject(PLATFORM_ROUTER_OPTIONS) routerOptions: any\n ) {\n super(platform);\n\n const options = Object.assign({}, configuration.koa?.router || {}, routerOptions);\n this.rawRouter = new KoaRouter(options) as any;\n }\n\n callback() {\n return [this.getRouter().routes(), this.getRouter().allowedMethods()];\n }\n\n multer(options: PlatformMulterSettings): PlatformMulter {\n return getMulter(options);\n }\n\n statics(path: string, options: PlatformStaticsOptions) {\n this.rawRouter.use(path, staticsMiddleware(options) as any);\n\n return this;\n }\n}\n"]}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./PlatformKoaApplication"), exports);
5
- tslib_1.__exportStar(require("./PlatformKoaHandler"), exports);
6
- tslib_1.__exportStar(require("./PlatformKoaRouter"), exports);
7
- tslib_1.__exportStar(require("./PlatformKoaRequest"), exports);
8
- tslib_1.__exportStar(require("./PlatformKoaResponse"), exports);
9
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,mEAAyC;AACzC,+DAAqC;AACrC,8DAAoC;AACpC,+DAAqC;AACrC,gEAAsC","sourcesContent":["export * from \"./PlatformKoaApplication\";\nexport * from \"./PlatformKoaHandler\";\nexport * from \"./PlatformKoaRouter\";\nexport * from \"./PlatformKoaRequest\";\nexport * from \"./PlatformKoaResponse\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"multer.js","sourceRoot":"","sources":["../../src/utils/multer.ts"],"names":[],"mappings":";;;AACA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AC,CAAC;QAEjD,OAAO,mBAAmB,CAAC,gBAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS,CAAC,OAAY;IACpC,MAAM,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC;IAErC,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACtB,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACxB,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IACzB,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACvB,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IAEzB,OAAO,CAAC,CAAC;AACX,CAAC;AAVD,8BAUC","sourcesContent":["import Koa from \"koa\";\nimport {promisify} from \"util\";\n\n/**\n * @ignore\n */\nfunction createRawMiddleware(middleware: any) {\n return async (request: Koa.Request) => {\n const ctx: any = request.ctx;\n\n await middleware(ctx.req, ctx.res);\n\n const forwardKey = (key: string) => {\n if (ctx.req[key]) {\n ctx.request[key] = ctx.req[key];\n ctx[key] = ctx.req[key];\n delete ctx.req[key];\n }\n };\n\n if (\"request\" in ctx) {\n if (ctx.req.body) {\n ctx.request.body = ctx.req.body;\n delete ctx.req.body;\n }\n\n forwardKey(\"file\");\n forwardKey(\"files\");\n }\n };\n}\n\n/**\n * @ignore\n */\nfunction makePromise(multer: any, name: string) {\n // istanbul ignore next\n if (!multer[name]) return;\n\n const fn = multer[name];\n\n multer[name] = function apply(...args: any[]) {\n const middleware = Reflect.apply(fn, this, args);\n\n return createRawMiddleware(promisify(middleware));\n };\n}\n\n/**\n * @ignore\n */\nexport function getMulter(options: any) {\n const m = require(\"multer\")(options);\n\n makePromise(m, \"any\");\n makePromise(m, \"array\");\n makePromise(m, \"fields\");\n makePromise(m, \"none\");\n makePromise(m, \"single\");\n\n return m;\n}\n"]}