@tsed/platform-http 8.0.0-beta.4

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 (190) hide show
  1. package/.barrelsby.json +5 -0
  2. package/lib/esm/builder/PlatformBuilder.js +308 -0
  3. package/lib/esm/builder/PlatformBuilder.js.map +1 -0
  4. package/lib/esm/config/interfaces/PlatformJsonMapperSettings.js +2 -0
  5. package/lib/esm/config/interfaces/PlatformJsonMapperSettings.js.map +1 -0
  6. package/lib/esm/config/interfaces/PlatformMulterSettings.js +2 -0
  7. package/lib/esm/config/interfaces/PlatformMulterSettings.js.map +1 -0
  8. package/lib/esm/config/interfaces/PlatformRouterSettings.js +2 -0
  9. package/lib/esm/config/interfaces/PlatformRouterSettings.js.map +1 -0
  10. package/lib/esm/config/interfaces/PlatformStaticsSettings.js +2 -0
  11. package/lib/esm/config/interfaces/PlatformStaticsSettings.js.map +1 -0
  12. package/lib/esm/config/services/PlatformConfiguration.js +119 -0
  13. package/lib/esm/config/services/PlatformConfiguration.js.map +1 -0
  14. package/lib/esm/constants/routerOptions.js +2 -0
  15. package/lib/esm/constants/routerOptions.js.map +1 -0
  16. package/lib/esm/decorators/PlatformProvider.js +7 -0
  17. package/lib/esm/decorators/PlatformProvider.js.map +1 -0
  18. package/lib/esm/decorators/multer/multerFileSize.js +32 -0
  19. package/lib/esm/decorators/multer/multerFileSize.js.map +1 -0
  20. package/lib/esm/decorators/multer/multerOptions.js +50 -0
  21. package/lib/esm/decorators/multer/multerOptions.js.map +1 -0
  22. package/lib/esm/decorators/multer/multipartFile.js +75 -0
  23. package/lib/esm/decorators/multer/multipartFile.js.map +1 -0
  24. package/lib/esm/decorators/params/error.js +16 -0
  25. package/lib/esm/decorators/params/error.js.map +1 -0
  26. package/lib/esm/decorators/params/next.js +17 -0
  27. package/lib/esm/decorators/params/next.js.map +1 -0
  28. package/lib/esm/decorators/params/request.js +34 -0
  29. package/lib/esm/decorators/params/request.js.map +1 -0
  30. package/lib/esm/decorators/params/response.js +28 -0
  31. package/lib/esm/decorators/params/response.js.map +1 -0
  32. package/lib/esm/domain/AnyToPromiseWithCtx.js +21 -0
  33. package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -0
  34. package/lib/esm/domain/EndpointMetadata.js +2 -0
  35. package/lib/esm/domain/EndpointMetadata.js.map +1 -0
  36. package/lib/esm/domain/PlatformContext.js +69 -0
  37. package/lib/esm/domain/PlatformContext.js.map +1 -0
  38. package/lib/esm/domain/PlatformRouteDetails.js +2 -0
  39. package/lib/esm/domain/PlatformRouteDetails.js.map +1 -0
  40. package/lib/esm/exports.js +5 -0
  41. package/lib/esm/exports.js.map +1 -0
  42. package/lib/esm/index.js +64 -0
  43. package/lib/esm/index.js.map +1 -0
  44. package/lib/esm/interfaces/AfterInit.js +2 -0
  45. package/lib/esm/interfaces/AfterInit.js.map +1 -0
  46. package/lib/esm/interfaces/AfterListen.js +2 -0
  47. package/lib/esm/interfaces/AfterListen.js.map +1 -0
  48. package/lib/esm/interfaces/AfterRoutesInit.js +2 -0
  49. package/lib/esm/interfaces/AfterRoutesInit.js.map +1 -0
  50. package/lib/esm/interfaces/BeforeInit.js +2 -0
  51. package/lib/esm/interfaces/BeforeInit.js.map +1 -0
  52. package/lib/esm/interfaces/BeforeListen.js +2 -0
  53. package/lib/esm/interfaces/BeforeListen.js.map +1 -0
  54. package/lib/esm/interfaces/BeforeRoutesInit.js +2 -0
  55. package/lib/esm/interfaces/BeforeRoutesInit.js.map +1 -0
  56. package/lib/esm/interfaces/HandlerType.js +14 -0
  57. package/lib/esm/interfaces/HandlerType.js.map +1 -0
  58. package/lib/esm/interfaces/IncomingEvent.js +2 -0
  59. package/lib/esm/interfaces/IncomingEvent.js.map +1 -0
  60. package/lib/esm/interfaces/OnReady.js +2 -0
  61. package/lib/esm/interfaces/OnReady.js.map +1 -0
  62. package/lib/esm/interfaces/OnRequest.js +2 -0
  63. package/lib/esm/interfaces/OnRequest.js.map +1 -0
  64. package/lib/esm/interfaces/OnResponse.js +2 -0
  65. package/lib/esm/interfaces/OnResponse.js.map +1 -0
  66. package/lib/esm/interfaces/OnRoutesInit.js +2 -0
  67. package/lib/esm/interfaces/OnRoutesInit.js.map +1 -0
  68. package/lib/esm/interfaces/PlatformRouteOptions.js +2 -0
  69. package/lib/esm/interfaces/PlatformRouteOptions.js.map +1 -0
  70. package/lib/esm/interfaces/ResponseErrorObject.js +2 -0
  71. package/lib/esm/interfaces/ResponseErrorObject.js.map +1 -0
  72. package/lib/esm/interfaces/Route.js +2 -0
  73. package/lib/esm/interfaces/Route.js.map +1 -0
  74. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js +36 -0
  75. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
  76. package/lib/esm/middlewares/PlatformMulterMiddleware.js +66 -0
  77. package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -0
  78. package/lib/esm/services/FakeAdapter.js +2 -0
  79. package/lib/esm/services/FakeAdapter.js.map +1 -0
  80. package/lib/esm/services/FakeResponse.js +55 -0
  81. package/lib/esm/services/FakeResponse.js.map +1 -0
  82. package/lib/esm/services/Platform.js +73 -0
  83. package/lib/esm/services/Platform.js.map +1 -0
  84. package/lib/esm/services/PlatformAdapter.js +77 -0
  85. package/lib/esm/services/PlatformAdapter.js.map +1 -0
  86. package/lib/esm/services/PlatformApplication.js +41 -0
  87. package/lib/esm/services/PlatformApplication.js.map +1 -0
  88. package/lib/esm/services/PlatformHandler.js +130 -0
  89. package/lib/esm/services/PlatformHandler.js.map +1 -0
  90. package/lib/esm/services/PlatformMiddlewaresChain.js +57 -0
  91. package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -0
  92. package/lib/esm/services/PlatformRequest.js +141 -0
  93. package/lib/esm/services/PlatformRequest.js.map +1 -0
  94. package/lib/esm/services/PlatformResponse.js +306 -0
  95. package/lib/esm/services/PlatformResponse.js.map +1 -0
  96. package/lib/esm/services/PlatformTest.js +131 -0
  97. package/lib/esm/services/PlatformTest.js.map +1 -0
  98. package/lib/esm/utils/closeServer.js +4 -0
  99. package/lib/esm/utils/closeServer.js.map +1 -0
  100. package/lib/esm/utils/createContext.js +44 -0
  101. package/lib/esm/utils/createContext.js.map +1 -0
  102. package/lib/esm/utils/createHttpServer.js +13 -0
  103. package/lib/esm/utils/createHttpServer.js.map +1 -0
  104. package/lib/esm/utils/createHttpsServer.js +13 -0
  105. package/lib/esm/utils/createHttpsServer.js.map +1 -0
  106. package/lib/esm/utils/createInjector.js +41 -0
  107. package/lib/esm/utils/createInjector.js.map +1 -0
  108. package/lib/esm/utils/createServer.js +29 -0
  109. package/lib/esm/utils/createServer.js.map +1 -0
  110. package/lib/esm/utils/ensureContext.js +12 -0
  111. package/lib/esm/utils/ensureContext.js.map +1 -0
  112. package/lib/esm/utils/getConfiguration.js +32 -0
  113. package/lib/esm/utils/getConfiguration.js.map +1 -0
  114. package/lib/esm/utils/getStaticsOptions.js +17 -0
  115. package/lib/esm/utils/getStaticsOptions.js.map +1 -0
  116. package/lib/esm/utils/listenServer.js +10 -0
  117. package/lib/esm/utils/listenServer.js.map +1 -0
  118. package/lib/esm/utils/mapReturnedResponse.js +11 -0
  119. package/lib/esm/utils/mapReturnedResponse.js.map +1 -0
  120. package/lib/esm/utils/printRoutes.js +34 -0
  121. package/lib/esm/utils/printRoutes.js.map +1 -0
  122. package/lib/esm/utils/registerPlatformAdapter.js +7 -0
  123. package/lib/esm/utils/registerPlatformAdapter.js.map +1 -0
  124. package/lib/esm/utils/setResponseHeaders.js +25 -0
  125. package/lib/esm/utils/setResponseHeaders.js.map +1 -0
  126. package/lib/types/builder/PlatformBuilder.d.ts +100 -0
  127. package/lib/types/config/interfaces/PlatformJsonMapperSettings.d.ts +10 -0
  128. package/lib/types/config/interfaces/PlatformMulterSettings.d.ts +14 -0
  129. package/lib/types/config/interfaces/PlatformRouterSettings.d.ts +10 -0
  130. package/lib/types/config/interfaces/PlatformStaticsSettings.d.ts +17 -0
  131. package/lib/types/config/services/PlatformConfiguration.d.ts +67 -0
  132. package/lib/types/constants/routerOptions.d.ts +1 -0
  133. package/lib/types/decorators/PlatformProvider.d.ts +3 -0
  134. package/lib/types/decorators/multer/multerFileSize.d.ts +28 -0
  135. package/lib/types/decorators/multer/multerOptions.d.ts +43 -0
  136. package/lib/types/decorators/multer/multipartFile.d.ts +48 -0
  137. package/lib/types/decorators/params/error.d.ts +7 -0
  138. package/lib/types/decorators/params/next.d.ts +22 -0
  139. package/lib/types/decorators/params/request.d.ts +46 -0
  140. package/lib/types/decorators/params/response.d.ts +40 -0
  141. package/lib/types/domain/AnyToPromiseWithCtx.d.ts +10 -0
  142. package/lib/types/domain/EndpointMetadata.d.ts +1 -0
  143. package/lib/types/domain/PlatformContext.d.ts +80 -0
  144. package/lib/types/domain/PlatformRouteDetails.d.ts +7 -0
  145. package/lib/types/exports.d.ts +4 -0
  146. package/lib/types/index.d.ts +63 -0
  147. package/lib/types/interfaces/AfterInit.d.ts +3 -0
  148. package/lib/types/interfaces/AfterListen.d.ts +3 -0
  149. package/lib/types/interfaces/AfterRoutesInit.d.ts +3 -0
  150. package/lib/types/interfaces/BeforeInit.d.ts +3 -0
  151. package/lib/types/interfaces/BeforeListen.d.ts +3 -0
  152. package/lib/types/interfaces/BeforeRoutesInit.d.ts +3 -0
  153. package/lib/types/interfaces/HandlerType.d.ts +12 -0
  154. package/lib/types/interfaces/IncomingEvent.d.ts +6 -0
  155. package/lib/types/interfaces/OnReady.d.ts +3 -0
  156. package/lib/types/interfaces/OnRequest.d.ts +4 -0
  157. package/lib/types/interfaces/OnResponse.d.ts +4 -0
  158. package/lib/types/interfaces/OnRoutesInit.d.ts +3 -0
  159. package/lib/types/interfaces/PlatformRouteOptions.d.ts +15 -0
  160. package/lib/types/interfaces/ResponseErrorObject.d.ts +8 -0
  161. package/lib/types/interfaces/Route.d.ts +10 -0
  162. package/lib/types/middlewares/PlatformAcceptMimesMiddleware.d.ts +10 -0
  163. package/lib/types/middlewares/PlatformMulterMiddleware.d.ts +24 -0
  164. package/lib/types/services/FakeAdapter.d.ts +1 -0
  165. package/lib/types/services/FakeResponse.d.ts +22 -0
  166. package/lib/types/services/Platform.d.ts +25 -0
  167. package/lib/types/services/PlatformAdapter.d.ts +89 -0
  168. package/lib/types/services/PlatformApplication.d.ts +29 -0
  169. package/lib/types/services/PlatformHandler.d.ts +39 -0
  170. package/lib/types/services/PlatformMiddlewaresChain.d.ts +17 -0
  171. package/lib/types/services/PlatformRequest.d.ts +111 -0
  172. package/lib/types/services/PlatformResponse.d.ts +175 -0
  173. package/lib/types/services/PlatformTest.d.ts +61 -0
  174. package/lib/types/utils/closeServer.d.ts +7 -0
  175. package/lib/types/utils/createContext.d.ts +10 -0
  176. package/lib/types/utils/createHttpServer.d.ts +4 -0
  177. package/lib/types/utils/createHttpsServer.d.ts +4 -0
  178. package/lib/types/utils/createInjector.d.ts +8 -0
  179. package/lib/types/utils/createServer.d.ts +17 -0
  180. package/lib/types/utils/ensureContext.d.ts +2 -0
  181. package/lib/types/utils/getConfiguration.d.ts +2 -0
  182. package/lib/types/utils/getStaticsOptions.d.ts +5 -0
  183. package/lib/types/utils/listenServer.d.ts +8 -0
  184. package/lib/types/utils/mapReturnedResponse.d.ts +4 -0
  185. package/lib/types/utils/printRoutes.d.ts +2 -0
  186. package/lib/types/utils/registerPlatformAdapter.d.ts +3 -0
  187. package/lib/types/utils/setResponseHeaders.d.ts +5 -0
  188. package/package.json +106 -0
  189. package/readme.md +226 -0
  190. package/vitest.config.mts +21 -0
@@ -0,0 +1,66 @@
1
+ var PlatformMulterMiddleware_1;
2
+ import { __decorate, __metadata, __param } from "tslib";
3
+ import { Inject, Value } from "@tsed/di";
4
+ import { BadRequest } from "@tsed/exceptions";
5
+ import { Middleware } from "@tsed/platform-middlewares";
6
+ import { Context } from "@tsed/platform-params";
7
+ import { PlatformContext } from "../domain/PlatformContext.js";
8
+ import { PlatformApplication } from "../services/PlatformApplication.js";
9
+ export class MulterException extends BadRequest {
10
+ constructor(er) {
11
+ super(er.message);
12
+ this.origin = er;
13
+ this.name = er.code;
14
+ }
15
+ }
16
+ /**
17
+ * @middleware
18
+ */
19
+ let PlatformMulterMiddleware = PlatformMulterMiddleware_1 = class PlatformMulterMiddleware {
20
+ async use(ctx) {
21
+ try {
22
+ const { fields, options = {} } = ctx.endpoint.get(PlatformMulterMiddleware_1);
23
+ const settings = {
24
+ ...this.settings,
25
+ ...options
26
+ };
27
+ /* istanbul ignore next */
28
+ if (settings.storage) {
29
+ delete settings.dest;
30
+ }
31
+ const middleware = this.app.multer(settings).fields(this.getFields({ fields }));
32
+ return await middleware(ctx.getRequest(), ctx.getResponse());
33
+ }
34
+ catch (er) {
35
+ if (er.code) {
36
+ throw new MulterException(er);
37
+ }
38
+ throw er;
39
+ }
40
+ }
41
+ getFields(conf) {
42
+ return conf.fields.map(({ name, maxCount }) => ({ name, maxCount }));
43
+ }
44
+ };
45
+ __decorate([
46
+ Value("multer", {}) // NOTE: don't use constant to getting multer configuration. See issue #1840
47
+ ,
48
+ __metadata("design:type", Object)
49
+ ], PlatformMulterMiddleware.prototype, "settings", void 0);
50
+ __decorate([
51
+ Inject(),
52
+ __metadata("design:type", PlatformApplication)
53
+ ], PlatformMulterMiddleware.prototype, "app", void 0);
54
+ __decorate([
55
+ __param(0, Context()),
56
+ __metadata("design:type", Function),
57
+ __metadata("design:paramtypes", [PlatformContext]),
58
+ __metadata("design:returntype", Promise)
59
+ ], PlatformMulterMiddleware.prototype, "use", null);
60
+ PlatformMulterMiddleware = PlatformMulterMiddleware_1 = __decorate([
61
+ Middleware({
62
+ priority: 10
63
+ })
64
+ ], PlatformMulterMiddleware);
65
+ export { PlatformMulterMiddleware };
66
+ //# sourceMappingURL=PlatformMulterMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformMulterMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/PlatformMulterMiddleware.ts"],"names":[],"mappings":";;AAAA,OAAO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AAO,EAAE,EAAE,CAAC;YACZ,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;gBACZ,MAAM,IAAI,eAAe,CAAC,EAAE,CAAC,CAAC;YAChC,CAAC;YAED,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC;IAES,SAAS,CAAC,IAAwB;QAC1C,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAC,EAAE,EAAE,CAAC,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAC,CAAC,CAAC,CAAC;IACnE,CAAC;CACF,CAAA;AAjCW;IADT,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,4EAA4E;;;0DACtD;AAGjC;IADT,MAAM,EAAE;8BACM,mBAAmB;qDAAC;AAE7B;IAAK,WAAA,OAAO,EAAE,CAAA;;qCAAM,eAAe;;mDAuBxC;AA9BU,wBAAwB;IAHpC,UAAU,CAAC;QACV,QAAQ,EAAE,EAAE;KACb,CAAC;GACW,wBAAwB,CAmCpC"}
@@ -0,0 +1,2 @@
1
+ export { FakeAdapter } from "./PlatformAdapter.js";
2
+ //# sourceMappingURL=FakeAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FakeAdapter.js","sourceRoot":"","sources":["../../../src/services/FakeAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { EventEmitter } from "node:events";
2
+ export class FakeResponse extends EventEmitter {
3
+ constructor(opts = {}) {
4
+ super();
5
+ this.headers = {};
6
+ this.locals = {};
7
+ this.statusCode = 200;
8
+ Object.assign(this, opts);
9
+ }
10
+ status(code) {
11
+ this.statusCode = code;
12
+ return this;
13
+ }
14
+ contentType(content) {
15
+ this.set("content-type", content);
16
+ }
17
+ contentLength(content) {
18
+ this.set("content-length", content);
19
+ }
20
+ redirect(status, path) {
21
+ this.statusCode = status;
22
+ this.set("location", path);
23
+ }
24
+ location(path) {
25
+ this.set("location", path);
26
+ }
27
+ get(key) {
28
+ return this.headers[key.toLowerCase()];
29
+ }
30
+ getHeaders() {
31
+ return this.headers;
32
+ }
33
+ set(key, value) {
34
+ this.headers[key.toLowerCase()] = value;
35
+ return this;
36
+ }
37
+ setHeader(key, value) {
38
+ this.headers[key.toLowerCase()] = value;
39
+ return this;
40
+ }
41
+ send(data) {
42
+ this.data = data;
43
+ }
44
+ json(data) {
45
+ this.data = data;
46
+ }
47
+ write(chunk) {
48
+ this.emit("data", chunk);
49
+ }
50
+ end(data) {
51
+ data !== undefined && (this.data = data);
52
+ this.emit("end");
53
+ }
54
+ }
55
+ //# sourceMappingURL=FakeResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FakeResponse.js","sourceRoot":"","sources":["../../../src/services/FakeResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAEzC,MAAM,OAAO,YAAa,SAAQ,YAAY;IAM5C,YAAY,IAAI,GAAG,EAAE;QACnB,KAAK,EAAE,CAAC;QANV,YAAO,GAA4B,EAAE,CAAC;QACtC,WAAM,GAA4B,EAAE,CAAC;QACrC,eAAU,GAAW,GAAG,CAAC;QAMvB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,IAAY;QACjB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,WAAW,CAAC,OAAe;QACzB,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,aAAa,CAAC,OAAe;QAC3B,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAED,QAAQ,CAAC,MAAc,EAAE,IAAY;QACnC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;QACzB,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,QAAQ,CAAC,IAAY;QACnB,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAU;QACzB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,CAAC,GAAW,EAAE,KAAU;QAC/B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,IAAS;QACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,IAAS;QACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,KAAU;QACd,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED,GAAG,CAAC,IAAS;QACX,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;QAEzC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,73 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Injectable, InjectorService, ProviderScope } from "@tsed/di";
3
+ import { PlatformRouters } from "@tsed/platform-router";
4
+ import { PlatformApplication } from "./PlatformApplication.js";
5
+ import { PlatformHandler } from "./PlatformHandler.js";
6
+ /**
7
+ * `Platform` is used to provide all routes collected by annotation `@Controller`.
8
+ *
9
+ * @platform
10
+ */
11
+ let Platform = class Platform {
12
+ #layers;
13
+ constructor(injector, platformApplication, platformRouters) {
14
+ this.injector = injector;
15
+ this.platformApplication = platformApplication;
16
+ this.platformRouters = platformRouters;
17
+ platformRouters.prebuild();
18
+ }
19
+ get app() {
20
+ return this.platformApplication;
21
+ }
22
+ addRoutes(routes) {
23
+ routes.forEach((routeSettings) => {
24
+ this.addRoute(routeSettings.route, routeSettings.token);
25
+ });
26
+ }
27
+ addRoute(route, token) {
28
+ const provider = this.injector.getProvider(token);
29
+ if (!provider || provider.hasParent()) {
30
+ return this;
31
+ }
32
+ const router = this.platformRouters.from(provider.token);
33
+ this.app.use(route, router);
34
+ return this;
35
+ }
36
+ getLayers() {
37
+ this.#layers = this.#layers || this.platformRouters.getLayers(this.app);
38
+ return this.#layers;
39
+ }
40
+ /**
41
+ * Get all controllers mounted on the application.
42
+ * @returns {RouteController[]}
43
+ */
44
+ getMountedControllers() {
45
+ const controllers = this.getLayers().reduce((controllers, layer) => {
46
+ if (layer.isProvider()) {
47
+ const route = String(layer.getBasePath());
48
+ const key = `${layer.provider.toString()}:${route}`;
49
+ if (!controllers.has(key)) {
50
+ controllers.set(key, {
51
+ route,
52
+ routes: new Set(),
53
+ provider: layer.provider
54
+ });
55
+ }
56
+ controllers.get(key).routes.add(String(layer.path));
57
+ }
58
+ return controllers;
59
+ }, new Map());
60
+ return [...controllers.values()];
61
+ }
62
+ };
63
+ Platform = __decorate([
64
+ Injectable({
65
+ scope: ProviderScope.SINGLETON,
66
+ imports: [PlatformHandler]
67
+ }),
68
+ __metadata("design:paramtypes", [InjectorService,
69
+ PlatformApplication,
70
+ PlatformRouters])
71
+ ], Platform);
72
+ export { Platform };
73
+ //# sourceMappingURL=Platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../../src/services/Platform.ts"],"names":[],"mappings":";AAAA,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vider } from "@tsed/di";
2
+ import { createHttpServer } from "../utils/createHttpServer.js";
3
+ import { createHttpsServer } from "../utils/createHttpsServer.js";
4
+ export class PlatformAdapter {
5
+ constructor(injector) {
6
+ this.injector = injector;
7
+ }
8
+ get app() {
9
+ return this.injector.get("PlatformApplication");
10
+ }
11
+ getServers() {
12
+ return [createHttpServer(this.injector, this.app.callback()), createHttpsServer(this.injector, this.app.callback())].filter(Boolean);
13
+ }
14
+ onInit() {
15
+ return Promise.resolve();
16
+ }
17
+ beforeLoadRoutes() {
18
+ return Promise.resolve();
19
+ }
20
+ afterLoadRoutes() {
21
+ return Promise.resolve();
22
+ }
23
+ }
24
+ export class FakeAdapter extends PlatformAdapter {
25
+ constructor() {
26
+ super(...arguments);
27
+ this.providers = [];
28
+ }
29
+ static { this.NAME = "FAKE_ADAPTER"; }
30
+ static createFakeRawDriver() {
31
+ // istanbul ignore next
32
+ function FakeRawDriver() { }
33
+ // istanbul ignore next
34
+ function use() {
35
+ return this;
36
+ }
37
+ FakeRawDriver.use = use;
38
+ FakeRawDriver.all = use;
39
+ FakeRawDriver.get = use;
40
+ FakeRawDriver.patch = use;
41
+ FakeRawDriver.post = use;
42
+ FakeRawDriver.put = use;
43
+ FakeRawDriver.head = use;
44
+ FakeRawDriver.delete = use;
45
+ FakeRawDriver.options = use;
46
+ return FakeRawDriver;
47
+ }
48
+ createApp() {
49
+ const app = FakeAdapter.createFakeRawDriver();
50
+ return {
51
+ app,
52
+ callback() {
53
+ return app;
54
+ }
55
+ };
56
+ }
57
+ multipart(options) {
58
+ return {};
59
+ }
60
+ statics(endpoint, options) {
61
+ return {};
62
+ }
63
+ bodyParser(type) {
64
+ return () => { };
65
+ }
66
+ mapLayers(layers) { }
67
+ mapHandler(handler) {
68
+ return handler;
69
+ }
70
+ useContext() { }
71
+ }
72
+ registerProvider({
73
+ provide: PlatformAdapter,
74
+ deps: [InjectorService],
75
+ useClass: FakeAdapter
76
+ });
77
+ //# sourceMappingURL=PlatformAdapter.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G,CAAC;QACxB,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,KAAK,GAAG,GAAG,CAAC;QAC1B,aAAa,CAAC,IAAI,GAAG,GAAG,CAAC;QACzB,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,IAAI,GAAG,GAAG,CAAC;QACzB,aAAa,CAAC,MAAM,GAAG,GAAG,CAAC;QAC3B,aAAa,CAAC,OAAO,GAAG,GAAG,CAAC;QAE5B,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,SAAS;QACP,MAAM,GAAG,GAAG,WAAW,CAAC,mBAAmB,EAAE,CAAC;QAC9C,OAAO;YACL,GAAG;YACH,QAAQ;gBACN,OAAO,GAAG,CAAC;YACb,CAAC;SACF,CAAC;IACJ,CAAC;IAED,SAAS,CAAC,OAA+B;QACvC,OAAO,EAAS,CAAC;IACnB,CAAC;IAED,OAAO,CAAC,QAAgB,EAAE,OAA+B;QACvD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,UAAU,CAAC,IAAY;QACrB,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IAClB,CAAC;IAED,SAAS,CAAC,MAAuB,IAAG,CAAC;IAErC,UAAU,CAAC,OAAgD;QACzD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,UAAU,KAAI,CAAC;;AAGjB,gBAAgB,CAAC;IACf,OAAO,EAAE,eAAe;IACxB,IAAI,EAAE,CAAC,eAAe,CAAC;IACvB,QAAQ,EAAE,WAAW;CACtB,CAAC,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Injectable, InjectorService, ProviderScope } from "@tsed/di";
3
+ import { PlatformRouter } from "@tsed/platform-router";
4
+ import { PlatformAdapter } from "./PlatformAdapter.js";
5
+ /**
6
+ * `PlatformApplication` is used to provide all routes collected by annotation `@Controller`.
7
+ *
8
+ * @platform
9
+ */
10
+ let PlatformApplication = class PlatformApplication extends PlatformRouter {
11
+ constructor(adapter, injector) {
12
+ super(injector);
13
+ this.adapter = adapter;
14
+ this.injector = injector;
15
+ const { app, callback } = adapter.createApp();
16
+ this.rawApp = app;
17
+ this.rawCallback = callback;
18
+ }
19
+ getApp() {
20
+ return this.rawApp;
21
+ }
22
+ multer(options) {
23
+ return this.adapter.multipart(options);
24
+ }
25
+ callback(req, res) {
26
+ if (req && res) {
27
+ return this.callback()(req, res);
28
+ }
29
+ return this.rawCallback();
30
+ }
31
+ };
32
+ PlatformApplication = __decorate([
33
+ Injectable({
34
+ scope: ProviderScope.SINGLETON,
35
+ alias: "PlatformApplication"
36
+ }),
37
+ __metadata("design:paramtypes", [PlatformAdapter,
38
+ InjectorService])
39
+ ], PlatformApplication);
40
+ export { PlatformApplication };
41
+ //# sourceMappingURL=PlatformApplication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformApplication.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAE,eAAe,EAAE,aAAa,EAAC,MAAM,UAAU,CAAC;AACpE,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAIrD,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC;AASrD;;;;GAIG;AAKI,IAAM,mBAAmB,GAAzB,MAAM,mBAA4C,SAAQ,cAAc;IAI7E,YACS,OAA6B,EAC7B,QAAyB;QAEhC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAHT,YAAO,GAAP,OAAO,CAAsB;QAC7B,aAAQ,GAAR,QAAQ,CAAiB;QAGhC,MAAM,EAAC,GAAG,EAAE,QAAQ,EAAC,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;QAE5C,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;QAClB,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,OAA+B;QACpC,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAID,QAAQ,CAAC,GAAqB,EAAE,GAAoB;QAClD,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;YACf,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnC,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;CACF,CAAA;AAhCY,mBAAmB;IAJ/B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,KAAK,EAAE,qBAAqB;KAC7B,CAAC;qCAMkB,eAAe;QACd,eAAe;GANvB,mBAAmB,CAgC/B"}
@@ -0,0 +1,130 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { AnyToPromiseStatus, catchAsyncError } from "@tsed/core";
3
+ import { Inject, Injectable, ProviderScope } from "@tsed/di";
4
+ import { PlatformExceptions } from "@tsed/platform-exceptions";
5
+ import { PlatformParams } from "@tsed/platform-params";
6
+ import { PlatformResponseFilter } from "@tsed/platform-response-filter";
7
+ import { PlatformHandlerMetadata, PlatformHandlerType, PlatformRouters, useResponseHandler } from "@tsed/platform-router";
8
+ import { AnyToPromiseWithCtx } from "../domain/AnyToPromiseWithCtx.js";
9
+ import { setResponseHeaders } from "../utils/setResponseHeaders.js";
10
+ import { PlatformApplication } from "./PlatformApplication.js";
11
+ import { PlatformMiddlewaresChain } from "./PlatformMiddlewaresChain.js";
12
+ /**
13
+ * Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).
14
+ * @platform
15
+ */
16
+ let PlatformHandler = class PlatformHandler {
17
+ constructor(platformRouters) {
18
+ this.platformRouters = platformRouters;
19
+ // configure the router module
20
+ platformRouters.hooks
21
+ .on("alterEndpointHandlers", (handlers, operationRoute) => {
22
+ handlers = this.platformMiddlewaresChain.get(handlers, operationRoute);
23
+ handlers.after.push(useResponseHandler(this.flush.bind(this)));
24
+ return handlers;
25
+ })
26
+ .on("alterHandler", (handlerMetadata) => {
27
+ const handler = handlerMetadata.isInjectable() ? this.createHandler(handlerMetadata) : handlerMetadata.handler;
28
+ return this.platformApplication.adapter.mapHandler(handler, handlerMetadata);
29
+ });
30
+ }
31
+ createHandler(handlerMetadata) {
32
+ const handler = this.platformParams.compileHandler(handlerMetadata);
33
+ return ($ctx) => {
34
+ $ctx.handlerMetadata = handlerMetadata;
35
+ return this.onRequest(handler, $ctx);
36
+ };
37
+ }
38
+ /**
39
+ * @param provider
40
+ * @param propertyKey
41
+ */
42
+ createCustomHandler(provider, propertyKey) {
43
+ const metadata = new PlatformHandlerMetadata({
44
+ provider,
45
+ type: PlatformHandlerType.CUSTOM,
46
+ propertyKey
47
+ });
48
+ return this.createHandler(metadata);
49
+ }
50
+ /**
51
+ * Call handler when a request his handle
52
+ */
53
+ async onRequest(handler, $ctx) {
54
+ const { handlerMetadata } = $ctx;
55
+ if (handlerMetadata.type === PlatformHandlerType.CTX_FN) {
56
+ return handler({ $ctx });
57
+ }
58
+ const resolver = new AnyToPromiseWithCtx($ctx);
59
+ const response = await resolver.call(handler);
60
+ // Note: restore previous handler metadata (for OIDC)
61
+ $ctx.handlerMetadata = handlerMetadata;
62
+ if (response.state === AnyToPromiseStatus.RESOLVED && !$ctx.isDone()) {
63
+ return this.onResponse(response, $ctx);
64
+ }
65
+ }
66
+ onResponse({ status, data, headers }, $ctx) {
67
+ if (status) {
68
+ $ctx.response.status(status);
69
+ }
70
+ if (headers) {
71
+ $ctx.response.setHeaders(headers);
72
+ }
73
+ if (data !== undefined) {
74
+ $ctx.data = data;
75
+ }
76
+ $ctx.error = null;
77
+ // set headers each times that an endpoint is called
78
+ if ($ctx.handlerMetadata.isEndpoint()) {
79
+ setResponseHeaders($ctx);
80
+ }
81
+ }
82
+ /**
83
+ * Send the response to the consumer.
84
+ * @protected
85
+ * @param $ctx
86
+ */
87
+ async flush($ctx) {
88
+ if (!$ctx.error) {
89
+ $ctx.error = await catchAsyncError(async () => {
90
+ const { response } = $ctx;
91
+ if (!$ctx.isDone()) {
92
+ let data = await this.responseFilter.serialize($ctx.data, $ctx);
93
+ data = await this.responseFilter.transform(data, $ctx);
94
+ response.body(data);
95
+ }
96
+ });
97
+ }
98
+ if ($ctx.error) {
99
+ this.platformExceptions.catch($ctx.error, $ctx);
100
+ }
101
+ }
102
+ };
103
+ __decorate([
104
+ Inject(),
105
+ __metadata("design:type", PlatformResponseFilter)
106
+ ], PlatformHandler.prototype, "responseFilter", void 0);
107
+ __decorate([
108
+ Inject(),
109
+ __metadata("design:type", PlatformParams)
110
+ ], PlatformHandler.prototype, "platformParams", void 0);
111
+ __decorate([
112
+ Inject(),
113
+ __metadata("design:type", PlatformExceptions)
114
+ ], PlatformHandler.prototype, "platformExceptions", void 0);
115
+ __decorate([
116
+ Inject(),
117
+ __metadata("design:type", PlatformApplication)
118
+ ], PlatformHandler.prototype, "platformApplication", void 0);
119
+ __decorate([
120
+ Inject(),
121
+ __metadata("design:type", PlatformMiddlewaresChain)
122
+ ], PlatformHandler.prototype, "platformMiddlewaresChain", void 0);
123
+ PlatformHandler = __decorate([
124
+ Injectable({
125
+ scope: ProviderScope.SINGLETON
126
+ }),
127
+ __metadata("design:paramtypes", [PlatformRouters])
128
+ ], PlatformHandler);
129
+ export { PlatformHandler };
130
+ //# sourceMappingURL=PlatformHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformHandler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAmB,kBAAkB,EAAE,eAAe,EAAC,MAAM,YAAY,CAAC;AACjF,OAAO,EAAC,MAAM,EAAE,UAAU,EAAY,aAAa,EAAC,MAAM,UAAU,CAAC;AACrE,OAAO,EAAC,kBAAkB,EAAC,MAAM,2BAA2B,CAAC;AAC7D,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B,sBAAsB;uDAAC;AAGvC;IADT,MAAM,EAAE;8BACiB,cAAc;uDAAC;AAG/B;IADT,MAAM,EAAE;8BACqB,kBAAkB;2DAAC;AAGvC;IADT,MAAM,EAAE;8BACsB,mBAAmB;4DAAC;AAGzC;IADT,MAAM,EAAE;8BAC2B,wBAAwB;iEAAC;AAdlD,eAAe;IAH3B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;KAC/B,CAAC;qCAiBuC,eAAe;GAhB3C,eAAe,CAyH3B"}
@@ -0,0 +1,57 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { isClass } from "@tsed/core";
3
+ import { Constant, Inject, Injectable, InjectorService } from "@tsed/di";
4
+ import { ParamTypes } from "@tsed/platform-params";
5
+ import { JsonEntityStore } from "@tsed/schema";
6
+ import { PlatformAcceptMimesMiddleware } from "../middlewares/PlatformAcceptMimesMiddleware.js";
7
+ import { PlatformMulterMiddleware } from "../middlewares/PlatformMulterMiddleware.js";
8
+ import { PlatformAdapter } from "./PlatformAdapter.js";
9
+ let PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
10
+ get(handlers, operationRoute) {
11
+ const { ACCEPT_MIMES, FILE } = this.getParamTypes(handlers, operationRoute);
12
+ return {
13
+ ...handlers,
14
+ before: [ACCEPT_MIMES && PlatformAcceptMimesMiddleware, ...handlers.before, FILE && PlatformMulterMiddleware].filter(Boolean)
15
+ };
16
+ }
17
+ hasAcceptMimes(operationRoute) {
18
+ return operationRoute.endpoint.acceptMimes.length || this.acceptMimes.length;
19
+ }
20
+ getParamTypes(middlewares, operationRoute) {
21
+ return middlewares.before
22
+ .concat(middlewares.after)
23
+ .filter(isClass)
24
+ .reduce((paramTypes, token) => {
25
+ const entity = JsonEntityStore.fromMethod(token, "use");
26
+ if (entity.decoratorType === "method") {
27
+ const { FILE, RAW_BODY, BODY } = entity.getParamTypes();
28
+ paramTypes.FILE = paramTypes.FILE || FILE;
29
+ paramTypes.RAW_BODY = paramTypes.RAW_BODY || RAW_BODY;
30
+ paramTypes.BODY = paramTypes.BODY || BODY;
31
+ }
32
+ return paramTypes;
33
+ }, {
34
+ ACCEPT_MIMES: this.hasAcceptMimes(operationRoute),
35
+ FILE: operationRoute.has(ParamTypes.FILES),
36
+ RAW_BODY: operationRoute.has(ParamTypes.RAW_BODY),
37
+ BODY: operationRoute.has(ParamTypes.BODY) || operationRoute.method === "ALL"
38
+ });
39
+ }
40
+ };
41
+ __decorate([
42
+ Constant("acceptMimes", []),
43
+ __metadata("design:type", Array)
44
+ ], PlatformMiddlewaresChain.prototype, "acceptMimes", void 0);
45
+ __decorate([
46
+ Inject(PlatformAdapter),
47
+ __metadata("design:type", PlatformAdapter)
48
+ ], PlatformMiddlewaresChain.prototype, "adapter", void 0);
49
+ __decorate([
50
+ Inject(InjectorService),
51
+ __metadata("design:type", InjectorService)
52
+ ], PlatformMiddlewaresChain.prototype, "injector", void 0);
53
+ PlatformMiddlewaresChain = __decorate([
54
+ Injectable()
55
+ ], PlatformMiddlewaresChain);
56
+ export { PlatformMiddlewaresChain };
57
+ //# sourceMappingURL=PlatformMiddlewaresChain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformMiddlewaresChain.js","sourceRoot":"","sources":["../../../src/services/PlatformMiddlewaresChain.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AACnC,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAgB,MAAM,UAAU,CAAC;AACtF,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAC,eAAe,EAAqB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAC,6BAA6B,EAAC,MAAM,iDAAiD,CAAC;AAC9F,OAAO,EAAC,wBAAwB,EAAC,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC;AAG9C,IAAM,wBAAwB,G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