@tsed/common 7.0.0-beta.3 → 7.0.0-beta.6

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 (218) hide show
  1. package/lib/cjs/builder/PlatformBuilder.js +38 -27
  2. package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
  3. package/lib/cjs/builder/PlatformControllerBuilder.js +5 -8
  4. package/lib/cjs/builder/PlatformControllerBuilder.js.map +1 -1
  5. package/lib/cjs/config/interfaces/PlatformMulterSettings.js.map +1 -1
  6. package/lib/cjs/config/services/PlatformConfiguration.js +2 -2
  7. package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -1
  8. package/lib/cjs/decorators/multer/multipartFile.js.map +1 -1
  9. package/lib/cjs/domain/EndpointMetadata.js +2 -66
  10. package/lib/cjs/domain/EndpointMetadata.js.map +1 -1
  11. package/lib/cjs/domain/PlatformContext.js.map +1 -1
  12. package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -1
  13. package/lib/cjs/exports.js +31 -0
  14. package/lib/cjs/exports.js.map +1 -0
  15. package/lib/cjs/index.js +68 -30
  16. package/lib/cjs/index.js.map +1 -1
  17. package/lib/cjs/interfaces/PlatformRouteOptions.js.map +1 -1
  18. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js +8 -8
  19. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -1
  20. package/lib/cjs/middlewares/PlatformMulterMiddleware.js +25 -13
  21. package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -1
  22. package/lib/cjs/middlewares/__mock__/FakeCtrl.js +1 -1
  23. package/lib/cjs/middlewares/bindEndpointMiddleware.js.map +1 -1
  24. package/lib/cjs/package.json +3 -0
  25. package/lib/cjs/services/FakeAdapter.js +55 -0
  26. package/lib/cjs/services/FakeAdapter.js.map +1 -0
  27. package/lib/cjs/services/Platform.js +30 -9
  28. package/lib/cjs/services/Platform.js.map +1 -1
  29. package/lib/cjs/services/PlatformAdapter.js +14 -0
  30. package/lib/cjs/services/PlatformAdapter.js.map +1 -0
  31. package/lib/cjs/services/PlatformApplication.js +9 -11
  32. package/lib/cjs/services/PlatformApplication.js.map +1 -1
  33. package/lib/cjs/services/PlatformHandler.js +10 -8
  34. package/lib/cjs/services/PlatformHandler.js.map +1 -1
  35. package/lib/cjs/services/PlatformMiddlewaresChain.js +56 -15
  36. package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -1
  37. package/lib/cjs/services/PlatformRequest.js +2 -2
  38. package/lib/cjs/services/PlatformResponse.js +5 -5
  39. package/lib/cjs/services/PlatformResponse.js.map +1 -1
  40. package/lib/cjs/services/PlatformRouter.js +14 -32
  41. package/lib/cjs/services/PlatformRouter.js.map +1 -1
  42. package/lib/cjs/services/PlatformTest.js +3 -2
  43. package/lib/cjs/services/PlatformTest.js.map +1 -1
  44. package/lib/cjs/utils/__mock__/Test1.js +8 -0
  45. package/lib/cjs/utils/__mock__/Test1.js.map +1 -0
  46. package/lib/cjs/utils/__mock__/Test2.js +8 -0
  47. package/lib/cjs/utils/__mock__/Test2.js.map +1 -0
  48. package/lib/cjs/utils/createContext.js +2 -2
  49. package/lib/cjs/utils/createContext.js.map +1 -1
  50. package/lib/cjs/utils/createHandlerMetadata.js +2 -2
  51. package/lib/cjs/utils/createHandlerMetadata.js.map +1 -1
  52. package/lib/cjs/utils/createHttpServer.js +3 -2
  53. package/lib/cjs/utils/createHttpServer.js.map +1 -1
  54. package/lib/cjs/utils/createHttpsServer.js +3 -2
  55. package/lib/cjs/utils/createHttpsServer.js.map +1 -1
  56. package/lib/cjs/utils/createInjector.js +11 -3
  57. package/lib/cjs/utils/createInjector.js.map +1 -1
  58. package/lib/cjs/utils/importProviders.js +29 -0
  59. package/lib/cjs/utils/importProviders.js.map +1 -0
  60. package/lib/cjs/utils/setResponseHeaders.js.map +1 -1
  61. package/lib/esm/builder/PlatformBuilder.js +25 -14
  62. package/lib/esm/builder/PlatformBuilder.js.map +1 -1
  63. package/lib/esm/builder/PlatformControllerBuilder.js +8 -11
  64. package/lib/esm/builder/PlatformControllerBuilder.js.map +1 -1
  65. package/lib/esm/config/interfaces/PlatformMulterSettings.js.map +1 -1
  66. package/lib/esm/config/services/PlatformConfiguration.js.map +1 -1
  67. package/lib/esm/decorators/multer/multerFileSize.js +1 -1
  68. package/lib/esm/decorators/multer/multerOptions.js +1 -1
  69. package/lib/esm/decorators/multer/multipartFile.js +1 -1
  70. package/lib/esm/decorators/multer/multipartFile.js.map +1 -1
  71. package/lib/esm/domain/ControllerProvider.js +1 -1
  72. package/lib/esm/domain/EndpointMetadata.js +1 -66
  73. package/lib/esm/domain/EndpointMetadata.js.map +1 -1
  74. package/lib/esm/domain/HandlerMetadata.js +1 -1
  75. package/lib/esm/domain/PlatformContext.js +3 -3
  76. package/lib/esm/domain/PlatformContext.js.map +1 -1
  77. package/lib/esm/domain/PlatformRouteDetails.js.map +1 -1
  78. package/lib/esm/exports.js +13 -0
  79. package/lib/esm/exports.js.map +1 -0
  80. package/lib/esm/index.js +68 -27
  81. package/lib/esm/index.js.map +1 -1
  82. package/lib/esm/interfaces/PlatformRouteOptions.js.map +1 -1
  83. package/lib/esm/middlewares/PlatformMulterMiddleware.js +16 -5
  84. package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -1
  85. package/lib/esm/middlewares/bindEndpointMiddleware.js.map +1 -1
  86. package/lib/esm/package.json +3 -0
  87. package/lib/esm/services/FakeAdapter.js +51 -0
  88. package/lib/esm/services/FakeAdapter.js.map +1 -0
  89. package/lib/esm/services/Platform.js +31 -10
  90. package/lib/esm/services/Platform.js.map +1 -1
  91. package/lib/esm/services/PlatformAdapter.js +10 -0
  92. package/lib/esm/services/PlatformAdapter.js.map +1 -0
  93. package/lib/esm/services/PlatformApplication.js +11 -13
  94. package/lib/esm/services/PlatformApplication.js.map +1 -1
  95. package/lib/esm/services/PlatformHandler.js +11 -9
  96. package/lib/esm/services/PlatformHandler.js.map +1 -1
  97. package/lib/esm/services/PlatformMiddlewaresChain.js +61 -20
  98. package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -1
  99. package/lib/esm/services/PlatformResponse.js +1 -1
  100. package/lib/esm/services/PlatformResponse.js.map +1 -1
  101. package/lib/esm/services/PlatformRouter.js +13 -31
  102. package/lib/esm/services/PlatformRouter.js.map +1 -1
  103. package/lib/esm/services/PlatformTest.js +7 -7
  104. package/lib/esm/services/PlatformTest.js.map +1 -1
  105. package/lib/esm/utils/__mock__/Test1.js +4 -0
  106. package/lib/esm/utils/__mock__/Test1.js.map +1 -0
  107. package/lib/esm/utils/__mock__/Test2.js +4 -0
  108. package/lib/esm/utils/__mock__/Test2.js.map +1 -0
  109. package/lib/esm/utils/createContext.js +5 -5
  110. package/lib/esm/utils/createContext.js.map +1 -1
  111. package/lib/esm/utils/createHandlerMetadata.js +3 -3
  112. package/lib/esm/utils/createHandlerMetadata.js.map +1 -1
  113. package/lib/esm/utils/createHttpServer.js +4 -3
  114. package/lib/esm/utils/createHttpServer.js.map +1 -1
  115. package/lib/esm/utils/createHttpsServer.js +4 -3
  116. package/lib/esm/utils/createHttpsServer.js.map +1 -1
  117. package/lib/esm/utils/createInjector.js +18 -10
  118. package/lib/esm/utils/createInjector.js.map +1 -1
  119. package/lib/esm/utils/importProviders.js +25 -0
  120. package/lib/esm/utils/importProviders.js.map +1 -0
  121. package/lib/esm/utils/setResponseHeaders.js.map +1 -1
  122. package/lib/esm/utils/useCtxHandler.js +1 -1
  123. package/lib/types/builder/PlatformBuilder.d.ts +7 -6
  124. package/lib/types/builder/PlatformControllerBuilder.d.ts +2 -1
  125. package/lib/types/config/interfaces/PlatformMulterSettings.d.ts +6 -130
  126. package/lib/types/config/services/PlatformConfiguration.d.ts +2 -1
  127. package/lib/types/domain/EndpointMetadata.d.ts +1 -50
  128. package/lib/types/domain/PlatformContext.d.ts +1 -1
  129. package/lib/types/domain/PlatformRouteDetails.d.ts +2 -3
  130. package/lib/types/exports.d.ts +12 -0
  131. package/lib/types/index.d.ts +65 -17
  132. package/lib/types/interfaces/PlatformRouteOptions.d.ts +1 -1
  133. package/lib/types/middlewares/PlatformMulterMiddleware.d.ts +8 -3
  134. package/lib/types/middlewares/bindEndpointMiddleware.d.ts +2 -1
  135. package/lib/types/services/FakeAdapter.d.ts +30 -0
  136. package/lib/types/services/Platform.d.ts +10 -1
  137. package/lib/types/services/PlatformAdapter.d.ts +47 -0
  138. package/lib/types/services/PlatformApplication.d.ts +3 -3
  139. package/lib/types/services/PlatformHandler.d.ts +1 -1
  140. package/lib/types/services/PlatformMiddlewaresChain.d.ts +6 -2
  141. package/lib/types/services/PlatformResponse.d.ts +6 -6
  142. package/lib/types/services/PlatformRouter.d.ts +10 -7
  143. package/lib/types/services/PlatformTest.d.ts +2 -2
  144. package/lib/types/utils/__mock__/Test1.d.ts +3 -0
  145. package/lib/types/utils/__mock__/Test2.d.ts +3 -0
  146. package/lib/types/utils/createHandlerMetadata.d.ts +1 -1
  147. package/lib/types/utils/createHttpServer.d.ts +1 -1
  148. package/lib/types/utils/createHttpsServer.d.ts +2 -1
  149. package/lib/types/utils/createInjector.d.ts +5 -3
  150. package/lib/types/utils/importProviders.d.ts +10 -0
  151. package/package.json +38 -26
  152. package/readme.md +50 -57
  153. package/tsconfig.compile.esm.json +2 -12
  154. package/lib/cjs/config/index.js +0 -7
  155. package/lib/cjs/config/index.js.map +0 -1
  156. package/lib/cjs/config/interfaces/index.js +0 -8
  157. package/lib/cjs/config/interfaces/index.js.map +0 -1
  158. package/lib/cjs/decorators/index.js +0 -26
  159. package/lib/cjs/decorators/index.js.map +0 -1
  160. package/lib/cjs/decorators/method/acceptMime.js +0 -28
  161. package/lib/cjs/decorators/method/acceptMime.js.map +0 -1
  162. package/lib/cjs/decorators/multer/index.js +0 -7
  163. package/lib/cjs/decorators/multer/index.js.map +0 -1
  164. package/lib/cjs/domain/index.js +0 -10
  165. package/lib/cjs/domain/index.js.map +0 -1
  166. package/lib/cjs/interfaces/PathType.js +0 -3
  167. package/lib/cjs/interfaces/PathType.js.map +0 -1
  168. package/lib/cjs/interfaces/PlatformAdapter.js +0 -3
  169. package/lib/cjs/interfaces/PlatformAdapter.js.map +0 -1
  170. package/lib/cjs/interfaces/index.js +0 -21
  171. package/lib/cjs/interfaces/index.js.map +0 -1
  172. package/lib/cjs/middlewares/index.js +0 -7
  173. package/lib/cjs/middlewares/index.js.map +0 -1
  174. package/lib/cjs/services/FakeRawDriver.js +0 -26
  175. package/lib/cjs/services/FakeRawDriver.js.map +0 -1
  176. package/lib/cjs/services/index.js +0 -12
  177. package/lib/cjs/services/index.js.map +0 -1
  178. package/lib/cjs/utils/index.js +0 -11
  179. package/lib/cjs/utils/index.js.map +0 -1
  180. package/lib/esm/config/index.js +0 -4
  181. package/lib/esm/config/index.js.map +0 -1
  182. package/lib/esm/config/interfaces/index.js +0 -5
  183. package/lib/esm/config/interfaces/index.js.map +0 -1
  184. package/lib/esm/decorators/index.js +0 -14
  185. package/lib/esm/decorators/index.js.map +0 -1
  186. package/lib/esm/decorators/method/acceptMime.js +0 -24
  187. package/lib/esm/decorators/method/acceptMime.js.map +0 -1
  188. package/lib/esm/decorators/multer/index.js +0 -4
  189. package/lib/esm/decorators/multer/index.js.map +0 -1
  190. package/lib/esm/domain/index.js +0 -7
  191. package/lib/esm/domain/index.js.map +0 -1
  192. package/lib/esm/interfaces/PathType.js +0 -2
  193. package/lib/esm/interfaces/PathType.js.map +0 -1
  194. package/lib/esm/interfaces/PlatformAdapter.js +0 -2
  195. package/lib/esm/interfaces/PlatformAdapter.js.map +0 -1
  196. package/lib/esm/interfaces/index.js +0 -18
  197. package/lib/esm/interfaces/index.js.map +0 -1
  198. package/lib/esm/middlewares/index.js +0 -4
  199. package/lib/esm/middlewares/index.js.map +0 -1
  200. package/lib/esm/services/FakeRawDriver.js +0 -22
  201. package/lib/esm/services/FakeRawDriver.js.map +0 -1
  202. package/lib/esm/services/index.js +0 -9
  203. package/lib/esm/services/index.js.map +0 -1
  204. package/lib/esm/utils/index.js +0 -8
  205. package/lib/esm/utils/index.js.map +0 -1
  206. package/lib/types/config/index.d.ts +0 -3
  207. package/lib/types/config/interfaces/index.d.ts +0 -97
  208. package/lib/types/decorators/index.d.ts +0 -10
  209. package/lib/types/decorators/method/acceptMime.d.ts +0 -19
  210. package/lib/types/decorators/multer/index.d.ts +0 -3
  211. package/lib/types/domain/index.d.ts +0 -6
  212. package/lib/types/interfaces/PathType.d.ts +0 -1
  213. package/lib/types/interfaces/PlatformAdapter.d.ts +0 -19
  214. package/lib/types/interfaces/index.d.ts +0 -17
  215. package/lib/types/middlewares/index.d.ts +0 -3
  216. package/lib/types/services/FakeRawDriver.d.ts +0 -15
  217. package/lib/types/services/index.d.ts +0 -8
  218. package/lib/types/utils/index.d.ts +0 -7
@@ -1,31 +1,29 @@
1
- var PlatformApplication_1;
2
1
  import { __decorate, __metadata } from "tslib";
3
2
  import { Injectable, ProviderScope } from "@tsed/di";
4
- import { createFakeRawDriver } from "./FakeRawDriver";
5
- import { PlatformHandler } from "./PlatformHandler";
6
- import { PlatformRouter } from "./PlatformRouter";
3
+ import { PlatformHandler } from "./PlatformHandler.js";
4
+ import { PlatformRouter } from "./PlatformRouter.js";
5
+ import { PlatformAdapter } from "./PlatformAdapter.js";
7
6
  /**
8
7
  * `PlatformApplication` is used to provide all routes collected by annotation `@Controller`.
9
8
  *
10
9
  * @platform
11
10
  */
12
- let PlatformApplication = PlatformApplication_1 = class PlatformApplication extends PlatformRouter {
13
- constructor(platformHandler) {
14
- super(platformHandler);
15
- this.rawApp = this.raw = PlatformApplication_1.createRawApp();
16
- }
17
- static createRawApp() {
18
- return createFakeRawDriver();
11
+ let PlatformApplication = class PlatformApplication extends PlatformRouter {
12
+ constructor(platformHandler, adapter) {
13
+ super(platformHandler, adapter);
14
+ const { app, callback } = adapter.app();
15
+ this.rawApp = this.raw = app;
16
+ this.callback = callback;
19
17
  }
20
18
  getApp() {
21
19
  return this.raw;
22
20
  }
23
21
  };
24
- PlatformApplication = PlatformApplication_1 = __decorate([
22
+ PlatformApplication = __decorate([
25
23
  Injectable({
26
24
  scope: ProviderScope.SINGLETON
27
25
  }),
28
- __metadata("design:paramtypes", [PlatformHandler])
26
+ __metadata("design:paramtypes", [PlatformHandler, PlatformAdapter])
29
27
  ], PlatformApplication);
30
28
  export { PlatformApplication };
31
29
  //# sourceMappingURL=PlatformApplication.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformApplication.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,UAAU,CAAC;AACnD,OAAO,EAAC,mBAAmB,EAAC,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAShD;;;;GAIG;AAIH,IAAa,mBAAmB,2BAAhC,MAAa,mBAAkE,SAAQ,cAAsB;IAK3G,YAAY,eAAgC;QAC1C,KAAK,CAAC,eAAe,CAAC,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,GAAG,qBAAmB,CAAC,YAAY,EAAS,CAAC;IACrE,CAAC;IAES,MAAM,CAAC,YAAY;QAC3B,OAAO,mBAAmB,EAAE,CAAC;IAC/B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF,CAAA;AAjBY,mBAAmB;IAH/B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;KAC/B,CAAC;qCAM6B,eAAe;GALjC,mBAAmB,CAiB/B;SAjBY,mBAAmB","sourcesContent":["import {Injectable, ProviderScope} from \"@tsed/di\";\nimport {createFakeRawDriver} from \"./FakeRawDriver\";\nimport {PlatformHandler} from \"./PlatformHandler\";\nimport {PlatformRouter} from \"./PlatformRouter\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Application {}\n }\n}\n\n/**\n * `PlatformApplication` is used to provide all routes collected by annotation `@Controller`.\n *\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON\n})\nexport class PlatformApplication<App = TsED.Application, Router = TsED.Router> extends PlatformRouter<Router> {\n raw: App;\n rawApp: App;\n declare rawRouter: Router;\n\n constructor(platformHandler: PlatformHandler) {\n super(platformHandler);\n this.rawApp = this.raw = PlatformApplication.createRawApp() as any;\n }\n\n protected static createRawApp(): any {\n return createFakeRawDriver();\n }\n\n getApp(): App {\n return this.raw;\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformApplication.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,UAAU,CAAC;AACnD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AASlD;;;;GAIG;AAIH,IAAa,mBAAmB,GAAhC,MAAa,mBAAkE,SAAQ,cAA2B;IAKhH,YAAY,eAAgC,EAAE,OAAqC;QACjF,KAAK,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAChC,MAAM,EAAC,GAAG,EAAE,QAAQ,EAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAEtC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF,CAAA;AAhBY,mBAAmB;IAH/B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;KAC/B,CAAC;qCAM6B,eAAe,EAAW,eAAe;GAL3D,mBAAmB,CAgB/B;SAhBY,mBAAmB","sourcesContent":["import {Injectable, ProviderScope} from \"@tsed/di\";\nimport {PlatformHandler} from \"./PlatformHandler\";\nimport {PlatformRouter} from \"./PlatformRouter\";\nimport {PlatformAdapter} from \"./PlatformAdapter\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Application {}\n }\n}\n\n/**\n * `PlatformApplication` is used to provide all routes collected by annotation `@Controller`.\n *\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON\n})\nexport class PlatformApplication<App = TsED.Application, Router = TsED.Router> extends PlatformRouter<App, Router> {\n raw: App;\n rawApp: App;\n declare rawRouter: Router;\n\n constructor(platformHandler: PlatformHandler, adapter: PlatformAdapter<App, Router>) {\n super(platformHandler, adapter);\n const {app, callback} = adapter.app();\n\n this.rawApp = this.raw = app;\n this.callback = callback;\n }\n\n getApp(): App {\n return this.raw;\n }\n}\n"]}
@@ -4,11 +4,11 @@ import { Inject, Injectable, InjectorService, ProviderScope } from "@tsed/di";
4
4
  import { $log } from "@tsed/logger";
5
5
  import { PlatformParams } from "@tsed/platform-params";
6
6
  import { PlatformResponseFilter } from "@tsed/platform-response-filter";
7
- import { AnyToPromiseWithCtx } from "../domain/AnyToPromiseWithCtx";
8
- import { HandlerMetadata } from "../domain/HandlerMetadata";
9
- import { HandlerType } from "../interfaces/HandlerType";
10
- import { createHandlerMetadata } from "../utils/createHandlerMetadata";
11
- import { setResponseHeaders } from "../utils/setResponseHeaders";
7
+ import { AnyToPromiseWithCtx } from "../domain/AnyToPromiseWithCtx.js";
8
+ import { HandlerMetadata } from "../domain/HandlerMetadata.js";
9
+ import { HandlerType } from "../interfaces/HandlerType.js";
10
+ import { createHandlerMetadata } from "../utils/createHandlerMetadata.js";
11
+ import { setResponseHeaders } from "../utils/setResponseHeaders.js";
12
12
  /**
13
13
  * Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).
14
14
  * @platform
@@ -127,22 +127,24 @@ let PlatformHandler = class PlatformHandler {
127
127
  }
128
128
  async onError(er, requestOptions) {
129
129
  const { next, $ctx, metadata } = requestOptions;
130
- $ctx.data = er;
130
+ if ($ctx) {
131
+ $ctx.data = er;
132
+ }
131
133
  if (!next) {
132
134
  throw er;
133
135
  }
134
136
  // istanbul ignore next
135
- if (!$ctx || ($ctx === null || $ctx === void 0 ? void 0 : $ctx.isDone())) {
137
+ if (!$ctx || $ctx.isDone()) {
136
138
  $log.warn({
137
139
  name: "HEADERS_SENT",
138
140
  message: `An error was caught after the headers were sent to the client. The error comes from the handler: ${metadata.toString()}`,
139
141
  stack: er.stack,
140
142
  origin: er,
141
- request_id: $ctx.id
143
+ request_id: $ctx === null || $ctx === void 0 ? void 0 : $ctx.id
142
144
  });
143
145
  return;
144
146
  }
145
- return next && next(er);
147
+ return next(er);
146
148
  }
147
149
  /**
148
150
  * Manage success scenario
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformHandler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,kBAAkB,EAAE,UAAU,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpE,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAY,aAAa,EAAC,MAAM,UAAU,CAAC;AACtF,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAA6B,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACjF,OAAO,EAAC,sBAAsB,EAAC,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAC,mBAAmB,EAAC,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAEtD,OAAO,EAAC,qBAAqB,EAAC,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAY/D;;;GAGG;AAIH,IAAa,eAAe,GAA5B,MAAa,eAA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,eAAe,CAiP3B;SAjPY,eAAe","sourcesContent":["import {AnyToPromiseStatus, isFunction, isStream} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService, Provider, ProviderScope} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {ArgScope, HandlerWithScope, PlatformParams} from \"@tsed/platform-params\";\nimport {PlatformResponseFilter} from \"@tsed/platform-response-filter\";\nimport {AnyToPromiseWithCtx} from \"../domain/AnyToPromiseWithCtx\";\nimport {EndpointMetadata} from \"../domain/EndpointMetadata\";\nimport {HandlerMetadata} from \"../domain/HandlerMetadata\";\nimport {PlatformContext} from \"../domain/PlatformContext\";\nimport {HandlerType} from \"../interfaces/HandlerType\";\nimport {PlatformRouteWithoutHandlers} from \"../interfaces/PlatformRouteOptions\";\nimport {createHandlerMetadata} from \"../utils/createHandlerMetadata\";\nimport {setResponseHeaders} from \"../utils/setResponseHeaders\";\n\nexport interface OnRequestOptions {\n $ctx: PlatformContext;\n metadata: HandlerMetadata;\n handler: HandlerWithScope;\n next?: any;\n err?: any;\n\n [key: string]: any;\n}\n\n/**\n * Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON\n})\nexport class PlatformHandler {\n @Inject()\n protected responseFilter: PlatformResponseFilter;\n\n constructor(protected injector: InjectorService, protected params: PlatformParams) {}\n\n /**\n * Create a native middleware based on the given metadata and return an instance of AnyToPromiseWithCtx\n * @param input\n * @param options\n */\n createHandler(input: EndpointMetadata | HandlerMetadata | any, options: PlatformRouteWithoutHandlers = {}) {\n return this.createRawHandler(createHandlerMetadata(this.injector, input, options));\n }\n\n /**\n * Create injectable handler from the given provider\n * @param provider\n * @param propertyKey\n */\n createCustomHandler(provider: Provider, propertyKey: string) {\n const handler = this.compileHandler(\n new HandlerMetadata({\n token: provider.provide,\n target: provider.useClass,\n type: HandlerType.CUSTOM,\n scope: provider.scope,\n propertyKey\n })\n );\n\n return async ($ctx: PlatformContext, next?: any) =>\n handler({\n $ctx,\n next\n });\n }\n\n /**\n * Send the response to the consumer.\n * @param data\n * @param ctx\n * @protected\n */\n async flush(data: any, ctx: PlatformContext) {\n const {response} = ctx;\n\n if (!response.isDone()) {\n data = await this.responseFilter.serialize(data, ctx);\n data = await this.responseFilter.transform(data, ctx);\n response.body(data);\n }\n }\n\n compileHandler(metadata: HandlerMetadata) {\n if (metadata.type === HandlerType.CTX_FN) {\n return async (scope: Record<string, any>) => {\n // @ts-ignore\n return this.onCtxRequest({\n ...scope,\n handler: () => metadata.handler(scope.$ctx),\n metadata\n });\n };\n }\n\n const promise = this.params.compileHandler<PlatformContext>({\n token: metadata.token,\n propertyKey: metadata.propertyKey,\n getCustomArgs: metadata.injectable ? undefined : this.getDefaultArgs(metadata)\n });\n\n return async (scope: Record<string, any>) => {\n const handler = await promise;\n // @ts-ignore\n return this.onRequest({\n ...scope,\n handler,\n metadata\n });\n };\n }\n\n protected async onCtxRequest(requestOptions: OnRequestOptions): Promise<any> {\n await requestOptions.handler(requestOptions);\n\n return this.next(requestOptions);\n }\n\n /**\n * Call handler when a request his handle\n * @param requestOptions\n */\n protected async onRequest(requestOptions: OnRequestOptions): Promise<any> {\n const {$ctx, metadata, err, handler} = requestOptions;\n // istanbul ignore next\n if (!$ctx || $ctx.isDone()) {\n $log.error({\n name: \"HEADERS_SENT\",\n message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${metadata.toString()}`\n });\n return;\n }\n\n const resolver = new AnyToPromiseWithCtx({$ctx, err});\n\n return this.injector.runInContext($ctx, async () => {\n try {\n const {state, data, status, headers} = await resolver.call(handler);\n\n if (state === AnyToPromiseStatus.RESOLVED) {\n if (status) {\n $ctx.response.status(status);\n }\n\n if (headers) {\n $ctx.response.setHeaders(headers);\n }\n\n if (data !== undefined) {\n $ctx.data = data;\n }\n\n // Can be canceled by the handler itself\n return await this.onSuccess($ctx.data, requestOptions);\n }\n } catch (er) {\n return this.onError(er, requestOptions);\n }\n });\n }\n\n protected async onError(er: Error, requestOptions: OnRequestOptions) {\n const {next, $ctx, metadata} = requestOptions;\n $ctx.data = er;\n\n if (!next) {\n throw er;\n }\n\n // istanbul ignore next\n if (!$ctx || $ctx?.isDone()) {\n $log.warn({\n name: \"HEADERS_SENT\",\n message: `An error was caught after the headers were sent to the client. The error comes from the handler: ${metadata.toString()}`,\n stack: er.stack,\n origin: er,\n request_id: $ctx.id\n });\n\n return;\n }\n\n return next && next(er);\n }\n\n /**\n * Manage success scenario\n * @param data\n * @param requestOptions\n * @protected\n */\n protected async onSuccess(data: any, requestOptions: OnRequestOptions) {\n const {metadata, $ctx, next} = requestOptions;\n\n // istanbul ignore next\n if ($ctx?.isDone()) {\n return;\n }\n\n // set headers each times that an endpoint is called\n if (metadata.type === HandlerType.ENDPOINT) {\n this.setHeaders($ctx);\n }\n\n // call returned middleware\n if (isFunction(data) && !isStream(data)) {\n return this.callReturnedMiddleware(data, $ctx, next);\n }\n\n if (metadata.isFinal()) {\n return this.flush(data, $ctx);\n }\n\n return this.next(requestOptions);\n }\n\n /**\n * Call the returned middleware by the handler.\n * @param middleware\n * @param ctx\n * @param next\n * @protected\n */\n protected callReturnedMiddleware(middleware: any, ctx: PlatformContext, next: any) {\n return middleware(ctx.getRequest(), ctx.getResponse(), next);\n }\n\n /**\n * create Raw handler\n * @param metadata\n */\n protected createRawHandler(metadata: HandlerMetadata) {\n if ([HandlerType.RAW_ERR_FN, HandlerType.RAW_FN].includes(metadata.type)) {\n return metadata.handler;\n }\n\n const handler = this.compileHandler(metadata);\n\n return async (request: any, response: any, next: any) => {\n return handler({\n next,\n $ctx: request.$ctx\n });\n };\n }\n\n /**\n * Set response headers\n * @param ctx\n * @protected\n */\n protected setHeaders(ctx: PlatformContext) {\n return setResponseHeaders(ctx);\n }\n\n protected next(requestOptions: OnRequestOptions) {\n const {$ctx, next} = requestOptions;\n\n return !$ctx.response.isDone() && next && next();\n }\n\n protected getDefaultArgs(metadata: HandlerMetadata) {\n return async (scope: ArgScope<PlatformContext>) =>\n [\n metadata.hasErrorParam && scope.err,\n scope.$ctx.request.request,\n scope.$ctx.response.response,\n metadata.hasNextFunction && scope.next\n ].filter(Boolean);\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformHandler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,kBAAkB,EAAE,UAAU,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpE,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAY,aAAa,EAAC,MAAM,UAAU,CAAC;AACtF,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAA6B,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACjF,OAAO,EAAC,sBAAsB,EAAC,MAAM,gCAAgC,CAAC;AAEtE,OAAO,EAAC,mBAAmB,EAAC,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAEtD,OAAO,EAAC,qBAAqB,EAAC,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAY/D;;;GAGG;AAIH,IAAa,eAAe,GAA5B,MAAa,eAAe;IAI1B,YAAsB,QAAyB,EAAY,MAAsB;QAA3D,aAAQ,GAAR,QAAQ,CAAiB;QAAY,WAAM,GAAN,MAAM,CAAgB;IAAG,CAAC;IAErF;;;;OAIG;IACH,aAAa,CAAC,KAA+C,EAAE,UAAwC,EAAE;QACvG,OAAO,IAAI,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;IACrF,CAAC;IAED;;;;OAIG;IACH,mBAAmB,CAAC,QAAkB,EAAE,WAAmB;QACzD,MAAM,OAAO,GAAG,IAAI,CAAC,c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OAAO,CAAC,IAAI;aACnB,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACO,UAAU,CAAC,GAAoB;QACvC,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAES,IAAI,CAAC,cAAgC;QAC7C,MAAM,EAAC,IAAI,EAAE,IAAI,EAAC,GAAG,cAAc,CAAC;QAEpC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;IACnD,CAAC;IAES,cAAc,CAAC,QAAyB;QAChD,OAAO,KAAK,EAAE,KAAgC,EAAE,EAAE,CAChD;YACE,QAAQ,CAAC,aAAa,IAAI,KAAK,CAAC,GAAG;YACnC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO;YAC1B,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ;YAC5B,QAAQ,CAAC,eAAe,IAAI,KAAK,CAAC,IAAI;SACvC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;CACF,CAAA;AAlPC;IADC,MAAM,EAAE;8BACiB,sBAAsB;uDAAC;AAFtC,eAAe;IAH3B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;KAC/B,CAAC;qCAKgC,eAAe,EAAoB,cAAc;GAJtE,eAAe,CAoP3B;SApPY,eAAe","sourcesContent":["import {AnyToPromiseStatus, isFunction, isStream} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService, Provider, ProviderScope} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {ArgScope, HandlerWithScope, PlatformParams} from \"@tsed/platform-params\";\nimport {PlatformResponseFilter} from \"@tsed/platform-response-filter\";\nimport {EndpointMetadata} from \"@tsed/schema\";\nimport {AnyToPromiseWithCtx} from \"../domain/AnyToPromiseWithCtx\";\nimport {HandlerMetadata} from \"../domain/HandlerMetadata\";\nimport {PlatformContext} from \"../domain/PlatformContext\";\nimport {HandlerType} from \"../interfaces/HandlerType\";\nimport {PlatformRouteWithoutHandlers} from \"../interfaces/PlatformRouteOptions\";\nimport {createHandlerMetadata} from \"../utils/createHandlerMetadata\";\nimport {setResponseHeaders} from \"../utils/setResponseHeaders\";\n\nexport interface OnRequestOptions {\n $ctx: PlatformContext;\n metadata: HandlerMetadata;\n handler: HandlerWithScope;\n next?: any;\n err?: any;\n\n [key: string]: any;\n}\n\n/**\n * Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON\n})\nexport class PlatformHandler {\n @Inject()\n protected responseFilter: PlatformResponseFilter;\n\n constructor(protected injector: InjectorService, protected params: PlatformParams) {}\n\n /**\n * Create a native middleware based on the given metadata and return an instance of AnyToPromiseWithCtx\n * @param input\n * @param options\n */\n createHandler(input: EndpointMetadata | HandlerMetadata | any, options: PlatformRouteWithoutHandlers = {}) {\n return this.createRawHandler(createHandlerMetadata(this.injector, input, options));\n }\n\n /**\n * Create injectable handler from the given provider\n * @param provider\n * @param propertyKey\n */\n createCustomHandler(provider: Provider, propertyKey: string) {\n const handler = this.compileHandler(\n new HandlerMetadata({\n token: provider.provide,\n target: provider.useClass,\n type: HandlerType.CUSTOM,\n scope: provider.scope,\n propertyKey\n })\n );\n\n return async ($ctx: PlatformContext, next?: any) =>\n handler({\n $ctx,\n next\n });\n }\n\n /**\n * Send the response to the consumer.\n * @param data\n * @param ctx\n * @protected\n */\n async flush(data: any, ctx: PlatformContext) {\n const {response} = ctx;\n\n if (!response.isDone()) {\n data = await this.responseFilter.serialize(data, ctx);\n data = await this.responseFilter.transform(data, ctx);\n response.body(data);\n }\n }\n\n compileHandler(metadata: HandlerMetadata) {\n if (metadata.type === HandlerType.CTX_FN) {\n return async (scope: Record<string, any>) => {\n // @ts-ignore\n return this.onCtxRequest({\n ...scope,\n handler: () => metadata.handler(scope.$ctx),\n metadata\n });\n };\n }\n\n const promise = this.params.compileHandler<PlatformContext>({\n token: metadata.token,\n propertyKey: metadata.propertyKey,\n getCustomArgs: metadata.injectable ? undefined : this.getDefaultArgs(metadata)\n });\n\n return async (scope: Record<string, any>) => {\n const handler = await promise;\n // @ts-ignore\n return this.onRequest({\n ...scope,\n handler,\n metadata\n });\n };\n }\n\n protected async onCtxRequest(requestOptions: OnRequestOptions): Promise<any> {\n await requestOptions.handler(requestOptions);\n\n return this.next(requestOptions);\n }\n\n /**\n * Call handler when a request his handle\n * @param requestOptions\n */\n protected async onRequest(requestOptions: OnRequestOptions): Promise<any> {\n const {$ctx, metadata, err, handler} = requestOptions;\n // istanbul ignore next\n if (!$ctx || $ctx.isDone()) {\n $log.error({\n name: \"HEADERS_SENT\",\n message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${metadata.toString()}`\n });\n return;\n }\n\n const resolver = new AnyToPromiseWithCtx({$ctx, err});\n\n return this.injector.runInContext($ctx, async () => {\n try {\n const {state, data, status, headers} = await resolver.call(handler);\n\n if (state === AnyToPromiseStatus.RESOLVED) {\n if (status) {\n $ctx.response.status(status);\n }\n\n if (headers) {\n $ctx.response.setHeaders(headers);\n }\n\n if (data !== undefined) {\n $ctx.data = data;\n }\n\n // Can be canceled by the handler itself\n return await this.onSuccess($ctx.data, requestOptions);\n }\n } catch (er) {\n return this.onError(er, requestOptions);\n }\n });\n }\n\n protected async onError(er: Error, requestOptions: OnRequestOptions) {\n const {next, $ctx, metadata} = requestOptions;\n\n if ($ctx) {\n $ctx.data = er;\n }\n\n if (!next) {\n throw er;\n }\n\n // istanbul ignore next\n if (!$ctx || $ctx.isDone()) {\n $log.warn({\n name: \"HEADERS_SENT\",\n message: `An error was caught after the headers were sent to the client. The error comes from the handler: ${metadata.toString()}`,\n stack: er.stack,\n origin: er,\n request_id: $ctx?.id\n });\n\n return;\n }\n\n return next(er);\n }\n\n /**\n * Manage success scenario\n * @param data\n * @param requestOptions\n * @protected\n */\n protected async onSuccess(data: any, requestOptions: OnRequestOptions) {\n const {metadata, $ctx, next} = requestOptions;\n\n // istanbul ignore next\n if ($ctx?.isDone()) {\n return;\n }\n\n // set headers each times that an endpoint is called\n if (metadata.type === HandlerType.ENDPOINT) {\n this.setHeaders($ctx);\n }\n\n // call returned middleware\n if (isFunction(data) && !isStream(data)) {\n return this.callReturnedMiddleware(data, $ctx, next);\n }\n\n if (metadata.isFinal()) {\n return this.flush(data, $ctx);\n }\n\n return this.next(requestOptions);\n }\n\n /**\n * Call the returned middleware by the handler.\n * @param middleware\n * @param ctx\n * @param next\n * @protected\n */\n protected callReturnedMiddleware(middleware: any, ctx: PlatformContext, next: any) {\n return middleware(ctx.getRequest(), ctx.getResponse(), next);\n }\n\n /**\n * create Raw handler\n * @param metadata\n */\n protected createRawHandler(metadata: HandlerMetadata) {\n if ([HandlerType.RAW_ERR_FN, HandlerType.RAW_FN].includes(metadata.type)) {\n return metadata.handler;\n }\n\n const handler = this.compileHandler(metadata);\n\n return async (request: any, response: any, next: any) => {\n return handler({\n next,\n $ctx: request.$ctx\n });\n };\n }\n\n /**\n * Set response headers\n * @param ctx\n * @protected\n */\n protected setHeaders(ctx: PlatformContext) {\n return setResponseHeaders(ctx);\n }\n\n protected next(requestOptions: OnRequestOptions) {\n const {$ctx, next} = requestOptions;\n\n return !$ctx.response.isDone() && next && next();\n }\n\n protected getDefaultArgs(metadata: HandlerMetadata) {\n return async (scope: ArgScope<PlatformContext>) =>\n [\n metadata.hasErrorParam && scope.err,\n scope.$ctx.request.request,\n scope.$ctx.response.response,\n metadata.hasNextFunction && scope.next\n ].filter(Boolean);\n }\n}\n"]}
@@ -1,29 +1,70 @@
1
- import { __decorate } from "tslib";
2
- import { Injectable } from "@tsed/di";
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Constant, Inject, Injectable } from "@tsed/di";
3
3
  import { ParamTypes } from "@tsed/platform-params";
4
- import { bindEndpointMiddleware } from "../middlewares/bindEndpointMiddleware";
5
- import { PlatformAcceptMimesMiddleware } from "../middlewares/PlatformAcceptMimesMiddleware";
6
- import { PlatformMulterMiddleware } from "../middlewares/PlatformMulterMiddleware";
7
- import { useCtxHandler } from "../utils/useCtxHandler";
4
+ import { JsonEntityStore } from "@tsed/schema";
5
+ import { bindEndpointMiddleware } from "../middlewares/bindEndpointMiddleware.js";
6
+ import { PlatformAcceptMimesMiddleware } from "../middlewares/PlatformAcceptMimesMiddleware.js";
7
+ import { PlatformMulterMiddleware } from "../middlewares/PlatformMulterMiddleware.js";
8
+ import { useCtxHandler } from "../utils/useCtxHandler.js";
9
+ import { PlatformAdapter } from "../services/PlatformAdapter.js";
10
+ import { isClass } from "@tsed/core";
8
11
  let PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
9
- get(provider, operationRoute) {
12
+ get(provider, operationRoute, parentMiddlewares = []) {
10
13
  const { endpoint } = operationRoute;
11
14
  const { beforeMiddlewares, middlewares: mldwrs, afterMiddlewares } = endpoint;
12
- const { middlewares: { use, useAfter } } = provider;
13
- const hasFiles = [...operationRoute.endpoint.children.values()].find((item) => item.paramType === ParamTypes.FILES);
14
- return []
15
- .concat(useCtxHandler(bindEndpointMiddleware(endpoint)))
16
- .concat(PlatformAcceptMimesMiddleware)
17
- .concat(hasFiles && PlatformMulterMiddleware)
18
- .concat(beforeMiddlewares) // Endpoint before-middlewares
19
- .concat(use) // Controller use-middlewares
20
- .concat(mldwrs) // Endpoint middlewares
21
- .concat(endpoint) // Endpoint metadata
22
- .concat(afterMiddlewares) // Endpoint after-middlewares
23
- .concat(useAfter) // Controller after middlewares (equivalent to afterEach)
24
- .filter((item) => !!item);
15
+ const { middlewares: { useBefore, use, useAfter } } = provider;
16
+ const allMiddlewares = [
17
+ ...parentMiddlewares,
18
+ ...useBefore,
19
+ ...beforeMiddlewares,
20
+ ...use,
21
+ ...mldwrs,
22
+ endpoint,
23
+ ...afterMiddlewares,
24
+ ...useAfter
25
+ ];
26
+ const { ACCEPT_MIMES, FILE, RAW_BODY, BODY } = this.getParamTypes(allMiddlewares, operationRoute);
27
+ return [
28
+ useCtxHandler(bindEndpointMiddleware(endpoint)),
29
+ ACCEPT_MIMES && PlatformAcceptMimesMiddleware,
30
+ FILE && PlatformMulterMiddleware,
31
+ !FILE && RAW_BODY && this.adapter.bodyParser("raw"),
32
+ !FILE && !RAW_BODY && BODY && this.adapter.bodyParser("json"),
33
+ !FILE && !RAW_BODY && BODY && this.adapter.bodyParser("urlencoded"),
34
+ ...allMiddlewares
35
+ ].filter(Boolean);
36
+ }
37
+ hasAcceptMimes(operationRoute) {
38
+ return operationRoute.endpoint.acceptMimes.length || this.acceptMimes.length;
39
+ }
40
+ getParamTypes(middlewares, operationRoute) {
41
+ return middlewares.filter(isClass).reduce((paramTypes, token) => {
42
+ if (token !== operationRoute.endpoint) {
43
+ const entity = JsonEntityStore.fromMethod(token, "use");
44
+ if (entity.decoratorType === "method") {
45
+ const { FILE, RAW_BODY, BODY } = entity.getParamTypes();
46
+ paramTypes.FILE = paramTypes.FILE || FILE;
47
+ paramTypes.RAW_BODY = paramTypes.RAW_BODY || RAW_BODY;
48
+ paramTypes.BODY = paramTypes.BODY || BODY;
49
+ }
50
+ }
51
+ return paramTypes;
52
+ }, {
53
+ ACCEPT_MIMES: this.hasAcceptMimes(operationRoute),
54
+ FILE: operationRoute.has(ParamTypes.FILES),
55
+ RAW_BODY: operationRoute.has(ParamTypes.RAW_BODY),
56
+ BODY: operationRoute.has(ParamTypes.BODY)
57
+ });
25
58
  }
26
59
  };
60
+ __decorate([
61
+ Constant("acceptMimes", []),
62
+ __metadata("design:type", Array)
63
+ ], PlatformMiddlewaresChain.prototype, "acceptMimes", void 0);
64
+ __decorate([
65
+ Inject(),
66
+ __metadata("design:type", PlatformAdapter)
67
+ ], PlatformMiddlewaresChain.prototype, "adapter", void 0);
27
68
  PlatformMiddlewaresChain = __decorate([
28
69
  Injectable()
29
70
  ], PlatformMiddlewaresChain);
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformMiddlewaresChain.js","sourceRoot":"","sources":["../../../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AgB,CAAC,CAAC,6BAA6B;aACtD,MAAM,CAAC,QAAQ,CAAC,CAAC,yDAAyD;aAC1E,MAAM,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;CACF,CAAA;AAvBY,wBAAwB;IADpC,UAAU,EAAE;GACA,wBAAwB,CAuBpC;SAvBY,wBAAwB","sourcesContent":["import {Injectable} from \"@tsed/di\";\nimport {ParamMetadata, ParamTypes} from \"@tsed/platform-params\";\nimport {JsonOperationRoute} from \"@tsed/schema\";\nimport {ControllerProvider} from \"../domain/ControllerProvider\";\nimport {EndpointMetadata} from \"../domain/EndpointMetadata\";\nimport {bindEndpointMiddleware} from \"../middlewares/bindEndpointMiddleware\";\nimport {PlatformAcceptMimesMiddleware} from \"../middlewares/PlatformAcceptMimesMiddleware\";\nimport {PlatformMulterMiddleware} from \"../middlewares/PlatformMulterMiddleware\";\nimport {useCtxHandler} from \"../utils/useCtxHandler\";\n\n@Injectable()\nexport class PlatformMiddlewaresChain {\n get(provider: ControllerProvider, operationRoute: JsonOperationRoute<EndpointMetadata>) {\n const {endpoint} = operationRoute;\n const {beforeMiddlewares, middlewares: mldwrs, afterMiddlewares} = endpoint;\n\n const {\n middlewares: {use, useAfter}\n } = provider;\n\n const hasFiles = [...operationRoute.endpoint.children.values()].find((item: ParamMetadata) => item.paramType === ParamTypes.FILES);\n\n return ([] as any[])\n .concat(useCtxHandler(bindEndpointMiddleware(endpoint)))\n .concat(PlatformAcceptMimesMiddleware)\n .concat(hasFiles && PlatformMulterMiddleware)\n .concat(beforeMiddlewares) // Endpoint before-middlewares\n .concat(use) // Controller use-middlewares\n .concat(mldwrs) // Endpoint middlewares\n .concat(endpoint) // Endpoint metadata\n .concat(afterMiddlewares) // Endpoint after-middlewares\n .concat(useAfter) // Controller after middlewares (equivalent to afterEach)\n .filter((item: any) => !!item);\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformMiddlewaresChain.js","sourceRoot":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pB,CAAC,EACD;YACE,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC;YACjD,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC;YAC1C,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC;YACjD,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;SAC1C,CACF,CAAC;IACJ,CAAC;CACF,CAAA;AAjEC;IADC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC;;6DACI;AAGhC;IADC,MAAM,EAAE;8BACU,eAAe;yDAAC;AALxB,wBAAwB;IADpC,UAAU,EAAE;GACA,wBAAwB,CAmEpC;SAnEY,wBAAwB","sourcesContent":["import {Constant, Inject, Injectable} from \"@tsed/di\";\nimport {ParamTypes} from \"@tsed/platform-params\";\nimport {JsonEntityStore, JsonOperationRoute} from \"@tsed/schema\";\nimport {ControllerProvider} from \"../domain/ControllerProvider\";\nimport {bindEndpointMiddleware} from \"../middlewares/bindEndpointMiddleware\";\nimport {PlatformAcceptMimesMiddleware} from \"../middlewares/PlatformAcceptMimesMiddleware\";\nimport {PlatformMulterMiddleware} from \"../middlewares/PlatformMulterMiddleware\";\nimport {useCtxHandler} from \"../utils/useCtxHandler\";\nimport {PlatformAdapter} from \"../services/PlatformAdapter\";\nimport {isClass} from \"@tsed/core\";\n\n@Injectable()\nexport class PlatformMiddlewaresChain {\n @Constant(\"acceptMimes\", [])\n protected acceptMimes: string[];\n\n @Inject()\n protected adapter: PlatformAdapter;\n\n get(provider: ControllerProvider, operationRoute: JsonOperationRoute, parentMiddlewares: any[] = []) {\n const {endpoint} = operationRoute;\n const {beforeMiddlewares, middlewares: mldwrs, afterMiddlewares} = endpoint;\n\n const {\n middlewares: {useBefore, use, useAfter}\n } = provider;\n\n const allMiddlewares = [\n ...parentMiddlewares,\n ...useBefore,\n ...beforeMiddlewares,\n ...use,\n ...mldwrs,\n endpoint,\n ...afterMiddlewares,\n ...useAfter\n ];\n\n const {ACCEPT_MIMES, FILE, RAW_BODY, BODY} = this.getParamTypes(allMiddlewares, operationRoute);\n\n return [\n useCtxHandler(bindEndpointMiddleware(endpoint)),\n ACCEPT_MIMES && PlatformAcceptMimesMiddleware,\n FILE && PlatformMulterMiddleware,\n !FILE && RAW_BODY && this.adapter.bodyParser(\"raw\"),\n !FILE && !RAW_BODY && BODY && this.adapter.bodyParser(\"json\"),\n !FILE && !RAW_BODY && BODY && this.adapter.bodyParser(\"urlencoded\"),\n ...allMiddlewares\n ].filter(Boolean);\n }\n\n protected hasAcceptMimes(operationRoute: JsonOperationRoute) {\n return operationRoute.endpoint.acceptMimes.length || this.acceptMimes.length;\n }\n\n protected getParamTypes(middlewares: any[], operationRoute: JsonOperationRoute) {\n return middlewares.filter(isClass).reduce(\n (paramTypes, token) => {\n if (token !== operationRoute.endpoint) {\n const entity = JsonEntityStore.fromMethod(token, \"use\");\n\n if (entity.decoratorType === \"method\") {\n const {FILE, RAW_BODY, BODY} = entity.getParamTypes();\n paramTypes.FILE = paramTypes.FILE || FILE;\n paramTypes.RAW_BODY = paramTypes.RAW_BODY || RAW_BODY;\n paramTypes.BODY = paramTypes.BODY || BODY;\n }\n }\n\n return paramTypes;\n },\n {\n ACCEPT_MIMES: this.hasAcceptMimes(operationRoute),\n FILE: operationRoute.has(ParamTypes.FILES),\n RAW_BODY: operationRoute.has(ParamTypes.RAW_BODY),\n BODY: operationRoute.has(ParamTypes.BODY)\n }\n );\n }\n}\n"]}
@@ -2,7 +2,7 @@ var PlatformResponse_1;
2
2
  import { __decorate, __metadata } from "tslib";
3
3
  import { isBoolean, isNumber, isStream, isString } from "@tsed/core";
4
4
  import { Injectable, ProviderScope, Scope } from "@tsed/di";
5
- const onFinished = require("on-finished");
5
+ import onFinished from "on-finished";
6
6
  /**
7
7
  * Platform Response abstraction layer.
8
8
  * @platform
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformResponse.js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C,aAAa,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACpF,CAAC;IAED,OAAO;QACL,aAAa;QACb,OAAO,IAAI,CAAC,GAAG,CAAC;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC;QACjB,aAAa;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;QACpB,aAAa;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC;IACnC,CAAC;CACF,CAAA;AAtTY,gBAAgB;IAF5B,UAAU,EAAE;IACZ,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC;;GACjB,gBAAgB,CAsT5B;SAtTY,gBAAgB","sourcesContent":["import {isBoolean, isNumber, isStream, isString} from \"@tsed/core\";\nimport {Injectable, ProviderScope, Scope} from \"@tsed/di\";\nimport {ServerResponse} from \"http\";\nimport {IncomingEvent} from \"../interfaces/IncomingEvent\";\nimport type {PlatformRequest} from \"./PlatformRequest\";\nimport type {PlatformContext} from \"../domain/PlatformContext\";\n\nconst onFinished = require(\"on-finished\");\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Response {\n // req: any;\n }\n }\n}\n\nexport type HeaderValue = Array<boolean | number | string> | boolean | number | string;\n\n/**\n * Platform Response abstraction layer.\n * @platform\n */\n@Injectable()\n@Scope(ProviderScope.INSTANCE)\nexport class PlatformResponse<T extends Record<string, any> = any> {\n /**\n * The current @@PlatformRequest@@.\n */\n public request: PlatformRequest;\n\n data: any;\n\n raw: T;\n\n constructor({response}: IncomingEvent, protected $ctx: PlatformContext) {\n this.raw = response as any;\n }\n\n /**\n * Get the current statusCode\n */\n get statusCode() {\n return this.raw.statusCode;\n }\n\n /**\n * An object that contains response local variables scoped to the request, and therefore available only to the view(s) rendered during that request / response cycle (if any). Otherwise, this property is identical to app.locals.\n *\n * This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.\n */\n get locals() {\n return this.raw.locals;\n }\n\n /**\n * Return the original response framework instance\n */\n get response() {\n return this.getResponse();\n }\n\n /**\n * Return the original response node.js instance\n */\n get res() {\n return this.getRes();\n }\n\n static onFinished(res: any, cb: Function) {\n onFinished(res, cb);\n }\n\n /**\n * Returns the HTTP response header specified by field. The match is case-insensitive.\n *\n * ```typescript\n * response.get('Content-Type') // => \"text/plain\"\n * ```\n *\n * @param name\n */\n get(name: string) {\n return this.raw.get(name);\n }\n\n getHeaders(): Record<string, HeaderValue> {\n return this.raw.getHeaders();\n }\n\n /**\n * Return the Framework response object (express, koa, etc...)\n */\n getResponse<Res = T>(): Res {\n return this.raw as any;\n }\n\n /**\n * Return the Node.js response object\n */\n getRes(): ServerResponse {\n return this.raw as any;\n }\n\n hasStatus() {\n return this.statusCode !== 200;\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 header `field` to `val`, or pass\n * an object of header fields.\n *\n * Examples:\n * ```typescript\n * response.setHeaders({ Accept: 'text/plain', 'X-API-Key': 'tobi' });\n * ```\n *\n * Aliased as `res.header()`.\n */\n setHeaders(headers: Record<string, HeaderValue>) {\n // apply headers\n Object.entries(headers).forEach(([key, item]) => {\n this.setHeader(key, item);\n });\n\n return this;\n }\n\n setHeader(key: string, item: any) {\n if (key.toLowerCase() === \"location\") {\n return this.location(String(item));\n }\n\n this.raw.set(key, item);\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.contentType(contentType);\n\n return this;\n }\n\n contentLength(length: number) {\n this.setHeader(\"Content-Length\", length);\n return this;\n }\n\n getContentLength() {\n if (this.get(\"Content-Length\")) {\n return parseInt(this.get(\"Content-Length\"), 10) || 0;\n }\n }\n\n getContentType() {\n return (this.get(\"Content-Type\") || \"\").split(\";\")[0];\n }\n\n /**\n * Sets the HTTP response Content-Disposition header field to “attachment”.\n * If a filename is given, then it sets the Content-Type based on the extension name via res.type(), and sets the Content-Disposition “filename=” parameter.\n *\n * ```typescript\n * res.attachment()\n * // Content-Disposition: attachment\n *\n * res.attachment('path/to/logo.png')\n * // Content-Disposition: attachment; filename=\"logo.png\"\n * // Content-Type: image/png\n * ```\n *\n * @param filename\n */\n attachment(filename: string) {\n this.raw.attachment(filename);\n return this;\n }\n\n /**\n * Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an [HTTP status code](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html).\n * If not specified, status defaults to `302 Found`.\n *\n * @param status\n * @param url\n */\n redirect(status: number, url: string) {\n this.raw.redirect(status, url);\n\n return this;\n }\n\n /**\n * Sets the response Location HTTP header to the specified path parameter.\n *\n * @param location\n */\n location(location: string) {\n this.raw.location(location);\n\n return this;\n }\n\n /**\n * Stream the given data.\n *\n * @param data\n */\n stream(data: ReadableStream | any) {\n data.pipe(this.raw);\n\n return this;\n }\n\n /**\n * Renders a view and sends the rendered HTML string to the client.\n *\n * @param path\n * @param options\n */\n async render(path: string, options: any = {}) {\n const {PlatformViews} = await import(\"@tsed/platform-views\");\n const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);\n\n return platformViews.render(path, {\n ...this.locals,\n ...options\n });\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) {\n this.data = data;\n\n if (data === undefined) {\n this.raw.send();\n\n return this;\n }\n\n if (isStream(data)) {\n this.stream(data);\n\n return this;\n }\n\n if (Buffer.isBuffer(data)) {\n if (!this.getContentType()) {\n this.contentType(\"application/octet-stream\");\n }\n\n this.contentLength(data.length);\n this.raw.send(data);\n\n return this;\n }\n\n if (isBoolean(data) || isNumber(data) || isString(data) || data === null) {\n this.raw.send(data);\n\n return this;\n }\n\n this.raw.json(data);\n\n return this;\n }\n\n getBody() {\n return this.data;\n }\n\n /**\n * Add a listener to handler the end of the request/response.\n * @param cb\n */\n onEnd(cb: Function): this {\n PlatformResponse.onFinished(this.getRes(), cb);\n\n return this;\n }\n\n isDone(): boolean {\n if (!this.raw) {\n return true;\n }\n\n const res = this.getRes();\n\n return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);\n }\n\n destroy() {\n // @ts-ignore\n delete this.raw;\n delete this.data;\n // @ts-ignore\n delete this.request;\n // @ts-ignore\n delete this.$ctx;\n }\n\n isHeadersSent() {\n return this.getRes().headersSent;\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformResponse.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACnE,OAAO,EAAC,UAAU,EAAE,aAAa,EAAE,KAAK,EAAC,MAAM,UAAU,CAAC;AAE1D,OAAO,UAAU,MAAM,aAAa,CAAC;AAgBrC;;;GAGG;AAGH,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;IAU3B,YAAY,EAAC,QAAQ,EAAgB,EAAY,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;QACpE,IAAI,CAAC,GAAG,GAAG,QAAe,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,MAAM,EAAE,C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AO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,EAA+C;QACnD,kBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;QAE/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;YACb,OAAO,IAAI,CAAC;SACb;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAE1B,OAAO,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACpF,CAAC;IAED,OAAO;QACL,aAAa;QACb,OAAO,IAAI,CAAC,GAAG,CAAC;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC;QACjB,aAAa;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;QACpB,aAAa;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC;IACnC,CAAC;CACF,CAAA;AAtTY,gBAAgB;IAF5B,UAAU,EAAE;IACZ,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC;;GACjB,gBAAgB,CAsT5B;SAtTY,gBAAgB","sourcesContent":["import {isBoolean, isNumber, isStream, isString} from \"@tsed/core\";\nimport {Injectable, ProviderScope, Scope} from \"@tsed/di\";\nimport {OutgoingHttpHeaders, ServerResponse} from \"http\";\nimport onFinished from \"on-finished\";\nimport {IncomingEvent} from \"../interfaces/IncomingEvent\";\nimport type {PlatformRequest} from \"./PlatformRequest\";\nimport type {PlatformContext} from \"../domain/PlatformContext\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Response {\n // req: any;\n }\n }\n}\n\nexport type HeaderValue = Array<boolean | number | string> | boolean | number | string;\n\n/**\n * Platform Response abstraction layer.\n * @platform\n */\n@Injectable()\n@Scope(ProviderScope.INSTANCE)\nexport class PlatformResponse<T extends Record<string, any> = any> {\n /**\n * The current @@PlatformRequest@@.\n */\n public request: PlatformRequest;\n\n data: any;\n\n raw: T;\n\n constructor({response}: IncomingEvent, protected $ctx: PlatformContext) {\n this.raw = response as any;\n }\n\n /**\n * Get the current statusCode\n */\n get statusCode() {\n return this.raw.statusCode;\n }\n\n /**\n * An object that contains response local variables scoped to the request, and therefore available only to the view(s) rendered during that request / response cycle (if any). Otherwise, this property is identical to app.locals.\n *\n * This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.\n */\n get locals() {\n return this.raw.locals;\n }\n\n /**\n * Return the original response framework instance\n */\n get response() {\n return this.getResponse();\n }\n\n /**\n * Return the original response node.js instance\n */\n get res() {\n return this.getRes();\n }\n\n static onFinished(res: any, cb: (er: Error | null, message: string) => void) {\n onFinished(res, cb);\n }\n\n /**\n * Returns the HTTP response header specified by field. The match is case-insensitive.\n *\n * ```typescript\n * response.get('Content-Type') // => \"text/plain\"\n * ```\n *\n * @param name\n */\n get(name: string) {\n return this.raw.get(name);\n }\n\n getHeaders(): OutgoingHttpHeaders {\n return this.raw.getHeaders();\n }\n\n /**\n * Return the Framework response object (express, koa, etc...)\n */\n getResponse<Res = T>(): Res {\n return this.raw as any;\n }\n\n /**\n * Return the Node.js response object\n */\n getRes(): ServerResponse {\n return this.raw as any;\n }\n\n hasStatus() {\n return this.statusCode !== 200;\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 header `field` to `val`, or pass\n * an object of header fields.\n *\n * Examples:\n * ```typescript\n * response.setHeaders({ Accept: 'text/plain', 'X-API-Key': 'tobi' });\n * ```\n *\n * Aliased as `res.header()`.\n */\n setHeaders(headers: OutgoingHttpHeaders) {\n // apply headers\n Object.entries(headers).forEach(([key, item]) => {\n this.setHeader(key, item);\n });\n\n return this;\n }\n\n setHeader(key: string, item: any) {\n if (key.toLowerCase() === \"location\") {\n return this.location(String(item));\n }\n\n this.raw.set(key, item);\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.contentType(contentType);\n\n return this;\n }\n\n contentLength(length: number) {\n this.setHeader(\"Content-Length\", length);\n return this;\n }\n\n getContentLength() {\n if (this.get(\"Content-Length\")) {\n return parseInt(this.get(\"Content-Length\"), 10) || 0;\n }\n }\n\n getContentType() {\n return (this.get(\"Content-Type\") || \"\").split(\";\")[0];\n }\n\n /**\n * Sets the HTTP response Content-Disposition header field to “attachment”.\n * If a filename is given, then it sets the Content-Type based on the extension name via res.type(), and sets the Content-Disposition “filename=” parameter.\n *\n * ```typescript\n * res.attachment()\n * // Content-Disposition: attachment\n *\n * res.attachment('path/to/logo.png')\n * // Content-Disposition: attachment; filename=\"logo.png\"\n * // Content-Type: image/png\n * ```\n *\n * @param filename\n */\n attachment(filename: string) {\n this.raw.attachment(filename);\n return this;\n }\n\n /**\n * Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an [HTTP status code](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html).\n * If not specified, status defaults to `302 Found`.\n *\n * @param status\n * @param url\n */\n redirect(status: number, url: string) {\n this.raw.redirect(status, url);\n\n return this;\n }\n\n /**\n * Sets the response Location HTTP header to the specified path parameter.\n *\n * @param location\n */\n location(location: string) {\n this.raw.location(location);\n\n return this;\n }\n\n /**\n * Stream the given data.\n *\n * @param data\n */\n stream(data: any) {\n data.pipe(this.raw);\n\n return this;\n }\n\n /**\n * Renders a view and sends the rendered HTML string to the client.\n *\n * @param path\n * @param options\n */\n async render(path: string, options: any = {}) {\n const {PlatformViews} = await import(\"@tsed/platform-views\");\n const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);\n\n return platformViews.render(path, {\n ...this.locals,\n ...options\n });\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) {\n this.data = data;\n\n if (data === undefined) {\n this.raw.send();\n\n return this;\n }\n\n if (isStream(data)) {\n this.stream(data);\n\n return this;\n }\n\n if (Buffer.isBuffer(data)) {\n if (!this.getContentType()) {\n this.contentType(\"application/octet-stream\");\n }\n\n this.contentLength(data.length);\n this.raw.send(data);\n\n return this;\n }\n\n if (isBoolean(data) || isNumber(data) || isString(data) || data === null) {\n this.raw.send(data);\n\n return this;\n }\n\n this.raw.json(data);\n\n return this;\n }\n\n getBody() {\n return this.data;\n }\n\n /**\n * Add a listener to handler the end of the request/response.\n * @param cb\n */\n onEnd(cb: (er: Error | null, message: string) => void): this {\n PlatformResponse.onFinished(this.getRes(), cb);\n\n return this;\n }\n\n isDone(): boolean {\n if (!this.raw) {\n return true;\n }\n\n const res = this.getRes();\n\n return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);\n }\n\n destroy() {\n // @ts-ignore\n delete this.raw;\n delete this.data;\n // @ts-ignore\n delete this.request;\n // @ts-ignore\n delete this.$ctx;\n }\n\n isHeadersSent() {\n return this.getRes().headersSent;\n }\n}\n"]}
@@ -1,9 +1,8 @@
1
1
  var PlatformRouter_1;
2
- import { __decorate, __metadata } from "tslib";
2
+ import { __decorate, __metadata, __param } from "tslib";
3
3
  import { Inject, Injectable, InjectorService, ProviderScope } from "@tsed/di";
4
- import { promisify } from "util";
5
- import { createFakeRawDriver } from "./FakeRawDriver";
6
- import { PlatformHandler } from "./PlatformHandler";
4
+ import { PlatformHandler } from "./PlatformHandler.js";
5
+ import { PlatformAdapter } from "./PlatformAdapter.js";
7
6
  /**
8
7
  * @ignore
9
8
  */
@@ -13,10 +12,13 @@ export const PLATFORM_ROUTER_OPTIONS = Symbol.for("PlatformRouterOptions");
13
12
  * @platform
14
13
  */
15
14
  let PlatformRouter = PlatformRouter_1 = class PlatformRouter {
16
- constructor(platformHandler) {
15
+ constructor(platformHandler, adapter, routerOptions = {}) {
17
16
  this.platformHandler = platformHandler;
17
+ this.adapter = adapter;
18
18
  this.isBuilt = false;
19
- this.rawRouter = this.raw = PlatformRouter_1.createRawRouter();
19
+ const { router, callback } = adapter.router(routerOptions);
20
+ this.rawRouter = this.raw = router;
21
+ this.callback = callback;
20
22
  }
21
23
  /**
22
24
  * Create a new instance of PlatformRouter
@@ -28,12 +30,6 @@ let PlatformRouter = PlatformRouter_1 = class PlatformRouter {
28
30
  locals.set(PLATFORM_ROUTER_OPTIONS, routerOptions);
29
31
  return injector.invoke(PlatformRouter_1, locals);
30
32
  }
31
- static createRawRouter() {
32
- return createFakeRawDriver();
33
- }
34
- callback() {
35
- return this.raw;
36
- }
37
33
  getRouter() {
38
34
  return this.rawRouter;
39
35
  }
@@ -73,26 +69,10 @@ let PlatformRouter = PlatformRouter_1 = class PlatformRouter {
73
69
  return this.addRoute({ method: "options", path, handlers, isFinal: true });
74
70
  }
75
71
  statics(path, options) {
76
- return this;
72
+ return this.use(path, this.adapter.statics(path, options));
77
73
  }
78
74
  multer(options) {
79
- const m = require("multer")(options);
80
- const makePromise = (multer, name) => {
81
- // istanbul ignore next
82
- if (!multer[name])
83
- return;
84
- const fn = multer[name];
85
- multer[name] = function apply(...args) {
86
- const middleware = Reflect.apply(fn, this, args);
87
- return (req, res) => promisify(middleware)(req, res);
88
- };
89
- };
90
- makePromise(m, "any");
91
- makePromise(m, "array");
92
- makePromise(m, "fields");
93
- makePromise(m, "none");
94
- makePromise(m, "single");
95
- return m;
75
+ return this.adapter.multipart(options);
96
76
  }
97
77
  mapHandlers(handlers, options = {}) {
98
78
  return handlers.reduce((list, handler, index) => {
@@ -117,7 +97,9 @@ PlatformRouter = PlatformRouter_1 = __decorate([
117
97
  Injectable({
118
98
  scope: ProviderScope.INSTANCE
119
99
  }),
120
- __metadata("design:paramtypes", [PlatformHandler])
100
+ __param(2, Inject(PLATFORM_ROUTER_OPTIONS)),
101
+ __metadata("design:paramtypes", [PlatformHandler,
102
+ PlatformAdapter, Object])
121
103
  ], PlatformRouter);
122
104
  export { PlatformRouter };
123
105
  //# sourceMappingURL=PlatformRouter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformRouter.js","sourceRoot":"","sources":["../../../src/services/PlatformRouter.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAY,aAAa,EAAC,MAAM,UAAU,CAAC;AACtF,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAG/B,OAAO,EAAC,mBAAmB,EAAC,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAS3E;;;GAGG;AAIH,IAAa,cAAc,sBAA3B,MAAa,cAAc;IAQzB,YAAsB,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;QALtD,YAAO,GAAY,KAAK,CAAC;QAMvB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,GAAG,gBAAc,CAAC,eAAe,EAAE,CAAC;IAC/D,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,QAAyB,EAAE,gBAAqB,EAAE;QAC9D,MAAM,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC;QAEnD,OAAO,QAAQ,CAAC,MAAM,CAAiB,gBAAc,EAAE,MAAM,CAAC,CAAC;IACjE,CAAC;IAES,MAAM,CAAC,eAAe;QAC9B,OAAO,mBAAmB,EAAE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C;IACT,CAAC;CACF,CAAA;AA7HC;IADC,MAAM,EAAE;8BACC,eAAe;gDAAC;AANf,cAAc;IAH1B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,QAAQ;KAC9B,CAAC;qCASuC,eAAe;GAR3C,cAAc,CAmI1B;SAnIY,cAAc","sourcesContent":["import {Inject, Injectable, InjectorService, PathType, ProviderScope} from \"@tsed/di\";\nimport {promisify} from \"util\";\nimport {PlatformMulter, PlatformMulterSettings, PlatformStaticsOptions} from \"../config\";\nimport {PlatformRouteOptions, PlatformRouteWithoutHandlers} from \"../interfaces\";\nimport {createFakeRawDriver} from \"./FakeRawDriver\";\nimport {PlatformHandler} from \"./PlatformHandler\";\n\n/**\n * @ignore\n */\nexport const PLATFORM_ROUTER_OPTIONS = Symbol.for(\"PlatformRouterOptions\");\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Router {}\n }\n}\n\n/**\n * Platform Router abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.INSTANCE\n})\nexport class PlatformRouter<Router = TsED.Router> {\n rawRouter: Router;\n raw: any;\n isBuilt: boolean = false;\n\n @Inject()\n injector: InjectorService;\n\n constructor(protected platformHandler: PlatformHandler) {\n this.rawRouter = this.raw = PlatformRouter.createRawRouter();\n }\n\n /**\n * Create a new instance of PlatformRouter\n * @param injector\n * @param routerOptions\n */\n static create(injector: InjectorService, routerOptions: any = {}) {\n const locals = new Map();\n locals.set(PLATFORM_ROUTER_OPTIONS, routerOptions);\n\n return injector.invoke<PlatformRouter>(PlatformRouter, locals);\n }\n\n protected static createRawRouter(): any {\n return createFakeRawDriver();\n }\n\n callback(): any {\n return this.raw;\n }\n\n getRouter(): Router {\n return this.rawRouter;\n }\n\n use(...handlers: any[]) {\n // @ts-ignore\n this.getRouter().use(...this.mapHandlers(handlers));\n\n return this;\n }\n\n addRoute(options: Partial<PlatformRouteOptions>) {\n const {method, path, handlers, ...opts} = options;\n\n // @ts-ignore\n this.getRouter()[method](path, ...this.mapHandlers(handlers, {method, path, ...opts}));\n\n return this;\n }\n\n all(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"all\", path, handlers, isFinal: true});\n }\n\n get(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"get\", path, handlers, isFinal: true});\n }\n\n post(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"post\", path, handlers, isFinal: true});\n }\n\n put(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"put\", path, handlers, isFinal: true});\n }\n\n delete(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"delete\", path, handlers, isFinal: true});\n }\n\n patch(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"patch\", path, handlers, isFinal: true});\n }\n\n head(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"head\", path, handlers, isFinal: true});\n }\n\n options(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"options\", path, handlers, isFinal: true});\n }\n\n statics(path: string, options: PlatformStaticsOptions): this {\n return this;\n }\n\n multer(options: PlatformMulterSettings): PlatformMulter {\n const m = require(\"multer\")(options);\n\n const 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 (req: any, res: any) => promisify(middleware)(req, res);\n };\n };\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\n protected mapHandlers(handlers: any[], options: PlatformRouteWithoutHandlers = {}): any[] {\n return handlers.reduce((list, handler, index) => {\n if (typeof handler === \"string\") {\n return list.concat(handler);\n }\n\n if (handler instanceof PlatformRouter) {\n return list.concat(handler.callback());\n }\n\n return list.concat(\n this.platformHandler.createHandler(handler, {\n ...options,\n isFinal: options.isFinal ? index === handlers.length - 1 : false\n })\n );\n }, []);\n }\n}\n"]}
1
+ {"version":3,"file":"P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OAAO,IAAI,CAAC,MAAM,CAChB,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,OAAO,EAAE;gBAC1C,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK;aACjE,CAAC,CACH,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AAzGC;IADC,MAAM,EAAE;8BACC,eAAe;gDAAC;AANf,cAAc;IAH1B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,QAAQ;KAC9B,CAAC;IAcG,WAAA,MAAM,CAAC,uBAAuB,CAAC,CAAA;qCAFL,eAAe;QACxB,eAAe;GAZxB,cAAc,CA+G1B;SA/GY,cAAc","sourcesContent":["import {Inject, Injectable, InjectorService, PathType, ProviderScope} from \"@tsed/di\";\nimport {PlatformHandler} from \"./PlatformHandler\";\nimport {PlatformRouteOptions, PlatformRouteWithoutHandlers} from \"../interfaces/PlatformRouteOptions\";\nimport {PlatformStaticsOptions} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {PlatformMulter, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformAdapter} from \"./PlatformAdapter\";\nimport {RouterOptions} from \"express\";\n\n/**\n * @ignore\n */\nexport const PLATFORM_ROUTER_OPTIONS = Symbol.for(\"PlatformRouterOptions\");\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Router {}\n }\n}\n\n/**\n * Platform Router abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.INSTANCE\n})\nexport class PlatformRouter<App = TsED.Application, Router = TsED.Router> {\n rawRouter: Router;\n raw: any;\n isBuilt: boolean = false;\n\n @Inject()\n injector: InjectorService;\n\n callback: () => any;\n\n constructor(\n protected platformHandler: PlatformHandler,\n readonly adapter: PlatformAdapter<App, Router>,\n @Inject(PLATFORM_ROUTER_OPTIONS) routerOptions: Partial<RouterOptions> = {}\n ) {\n const {router, callback} = adapter.router(routerOptions);\n\n this.rawRouter = this.raw = router;\n this.callback = callback;\n }\n\n /**\n * Create a new instance of PlatformRouter\n * @param injector\n * @param routerOptions\n */\n static create(injector: InjectorService, routerOptions: any = {}) {\n const locals = new Map();\n locals.set(PLATFORM_ROUTER_OPTIONS, routerOptions);\n\n return injector.invoke<PlatformRouter>(PlatformRouter, locals);\n }\n\n getRouter(): Router {\n return this.rawRouter;\n }\n\n use(...handlers: any[]) {\n // @ts-ignore\n this.getRouter().use(...this.mapHandlers(handlers));\n\n return this;\n }\n\n addRoute(options: Partial<PlatformRouteOptions>) {\n const {method, path, handlers, ...opts} = options;\n\n // @ts-ignore\n this.getRouter()[method](path, ...this.mapHandlers(handlers, {method, path, ...opts}));\n\n return this;\n }\n\n all(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"all\", path, handlers, isFinal: true});\n }\n\n get(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"get\", path, handlers, isFinal: true});\n }\n\n post(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"post\", path, handlers, isFinal: true});\n }\n\n put(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"put\", path, handlers, isFinal: true});\n }\n\n delete(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"delete\", path, handlers, isFinal: true});\n }\n\n patch(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"patch\", path, handlers, isFinal: true});\n }\n\n head(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"head\", path, handlers, isFinal: true});\n }\n\n options(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"options\", path, handlers, isFinal: true});\n }\n\n statics(path: string, options: PlatformStaticsOptions) {\n return this.use(path, this.adapter.statics(path, options));\n }\n\n multer(options: PlatformMulterSettings): PlatformMulter {\n return this.adapter.multipart(options);\n }\n\n protected mapHandlers(handlers: any[], options: PlatformRouteWithoutHandlers = {}): any[] {\n return handlers.reduce((list, handler, index) => {\n if (typeof handler === \"string\") {\n return list.concat(handler);\n }\n\n if (handler instanceof PlatformRouter) {\n return list.concat(handler.callback());\n }\n\n return list.concat(\n this.platformHandler.createHandler(handler, {\n ...options,\n isFinal: options.isFinal ? index === handlers.length - 1 : false\n })\n );\n }, []);\n }\n}\n"]}
@@ -1,9 +1,10 @@
1
1
  import { DITest } from "@tsed/di";
2
- import { PlatformBuilder } from "../builder/PlatformBuilder";
3
- import { PlatformContext } from "../domain/PlatformContext";
4
- import { createInjector } from "../utils/createInjector";
5
- import { PlatformApplication } from "./PlatformApplication";
6
- import { getConfiguration } from "../utils/getConfiguration";
2
+ import { PlatformBuilder } from "../builder/PlatformBuilder.js";
3
+ import { PlatformContext } from "../domain/PlatformContext.js";
4
+ import { createInjector } from "../utils/createInjector.js";
5
+ import { PlatformApplication } from "./PlatformApplication.js";
6
+ import { getConfiguration } from "../utils/getConfiguration.js";
7
+ import accepts from "accepts";
7
8
  /**
8
9
  * @platform
9
10
  */
@@ -17,7 +18,6 @@ export class PlatformTest extends DITest {
17
18
  */
18
19
  static createInjector(settings = {}) {
19
20
  return createInjector({
20
- providers: [],
21
21
  settings: DITest.configure({ httpPort: false, httpsPort: false, ...settings })
22
22
  });
23
23
  }
@@ -97,7 +97,7 @@ export class PlatformTest extends DITest {
97
97
  return this.headers[key.toLowerCase()];
98
98
  },
99
99
  accepts(mime) {
100
- return require("accepts")(this).types([].concat(mime));
100
+ return accepts(this).types([].concat(mime));
101
101
  },
102
102
  ...options
103
103
  };
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformTest.js","sourceRoot":"","sources":["../../../src/services/PlatformTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAiC,MAAM,UAAU,CAAC;AAChE,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAC,eAAe,EAAyB,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAC,cAAc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AAI,CAAC;YACnB,CAAC;YACD,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,oBAAoB,CAAC,UAAiD,EAAE;;QAC7E,MAAM,KAAK,GAAG;YACZ,OAAO,EAAE,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,OAAO,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,OAAO,CAAA,IAAI,YAAY,CAAC,aAAa,EAAE;YAC7F,QAAQ,EAAE,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,0CAAE,QAAQ,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,QAAQ,CAAA,IAAI,YAAY,CAAC,cAAc,EAAE;SACnG,CAAC;QAEF,OAAO,IAAI,eAAe,CAAC;YACzB,EAAE,EAAE,IAAI;YACR,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;YAC9B,GAAG,EAAE,GAAG;YACR,GAAG,OAAO;YACV,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import {DITest, DITestOptions, InjectorService} from \"@tsed/di\";\nimport {PlatformBuilder} from \"../builder/PlatformBuilder\";\nimport {PlatformContext, PlatformContextOptions} from \"../domain/PlatformContext\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../interfaces/PlatformAdapter\";\nimport {Type} from \"@tsed/core\";\n\n/**\n * @platform\n */\nexport class PlatformTest extends DITest {\n public static adapter: Type<PlatformAdapter>;\n\n static async create(settings: DITestOptions = {}) {\n DITest.injector = PlatformTest.createInjector(getConfiguration(settings));\n await DITest.createContainer(settings);\n }\n\n /**\n * Create a new injector with the right default services\n */\n static createInjector(settings: any = {}): InjectorService {\n return createInjector({\n providers: [],\n settings: DITest.configure({httpPort: false, httpsPort: false, ...settings})\n });\n }\n\n /**\n * Load the server silently without listening port and configure it on test profile.\n * @decorator\n * @param mod\n * @param listen\n * @param settings\n * @returns {Promise<void>}\n */\n static bootstrap(mod: any, {listen, ...settings}: Partial<PlatformBuilderSettings & {listen: boolean}> = {}): () => Promise<void> {\n return async function before(): Promise<void> {\n let instance: PlatformBuilder;\n const adapter: Type<PlatformAdapter> = settings.platform || settings.adapter || PlatformTest.adapter;\n\n /* istanbul ignore next */\n if (!adapter) {\n throw new Error(\n \"Platform adapter is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?\"\n );\n }\n\n // @ts-ignore\n settings = DITest.configure(settings);\n settings.adapter = adapter as any;\n\n instance = await PlatformBuilder.build(mod, settings).bootstrap();\n await instance.listen(!!listen);\n\n // used by inject method\n DITest.injector = instance.injector;\n };\n }\n\n /**\n * It injects services into the test function where you can alter, spy on, and manipulate them.\n *\n * The inject function has two parameters\n *\n * * an array of Service dependency injection tokens,\n * * a test function whose parameters correspond exactly to each item in the injection token array.\n *\n * @param targets\n * @param func\n */\n static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T> {\n return async (): Promise<T> => {\n if (!DITest.hasInjector()) {\n await PlatformTest.create();\n }\n\n const injector: InjectorService = DITest.injector;\n const deps = [];\n\n for (const target of targets) {\n deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));\n }\n\n return await func(...deps);\n };\n }\n\n /**\n * Return the raw application (express or koa).\n * Use this callback with SuperTest.\n *\n * ```typescript\n * let request: SuperTest.SuperTest<SuperTest.Test>;\n * beforeEach(PlatformTest.bootstrap(Server, {\n * mount: {\n * \"/rest\": [ProductsController]\n * }\n * }));\n * beforeEach(() => {\n * request = SuperTest(PlatformTest.callback());\n * });\n * ```\n */\n static callback() {\n return DITest.injector.get<PlatformApplication>(PlatformApplication)?.callback();\n }\n\n static createRequest(options: any = {}): any {\n return {\n headers: {},\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n accepts(mime?: string | string[]) {\n return require(\"accepts\")(this).types([].concat(mime as never));\n },\n ...options\n };\n }\n\n static createResponse(options: any = {}): any {\n return {\n headers: {},\n locals: {},\n statusCode: 200,\n status(code: number) {\n this.statusCode = code;\n return this;\n },\n contentType(content: string) {\n this.set(\"content-type\", content);\n },\n contentLength(content: number) {\n this.set(\"content-length\", content);\n },\n redirect(status: number, path: string) {\n this.statusCode = status;\n this.set(\"location\", path);\n },\n location(path: string) {\n this.set(\"location\", path);\n },\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n getHeaders() {\n return this.headers;\n },\n set(key: string, value: any) {\n this.headers[key.toLowerCase()] = value;\n return this;\n },\n send(data: any) {\n this.data = data;\n },\n json(data: any) {\n this.data = data;\n },\n ...options\n };\n }\n\n static createRequestContext(options: Partial<PlatformContextOptions & any> = {}) {\n const event = {\n request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),\n response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()\n };\n\n return new PlatformContext({\n id: \"id\",\n injector: DITest.injector,\n logger: DITest.injector.logger,\n url: \"/\",\n ...options,\n event\n });\n }\n}\n"]}
1
+ {"version":3,"file":"PlatformTest.js","sourceRoot":"","sources":["../../../src/services/PlatformTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAiC,MAAM,UAAU,CAAC;AAEhE,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAC,eAAe,EAAyB,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAE3D,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B;;GAEG;AACH,MAAM,O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AAO,0CAAE,OAAO,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,OAAO,CAAA,IAAI,YAAY,CAAC,aAAa,EAAE;YAC7F,QAAQ,EAAE,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,0CAAE,QAAQ,MAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,QAAQ,CAAA,IAAI,YAAY,CAAC,cAAc,EAAE;SACnG,CAAC;QAEF,OAAO,IAAI,eAAe,CAAC;YACzB,EAAE,EAAE,IAAI;YACR,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;YAC9B,GAAG,EAAE,GAAG;YACR,GAAG,OAAO;YACV,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import {DITest, DITestOptions, InjectorService} from \"@tsed/di\";\nimport {Type} from \"@tsed/core\";\nimport {PlatformBuilder} from \"../builder/PlatformBuilder\";\nimport {PlatformContext, PlatformContextOptions} from \"../domain/PlatformContext\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"./PlatformAdapter\";\nimport accepts from \"accepts\";\nimport {FakeAdapter} from \"./FakeAdapter\";\n\n/**\n * @platform\n */\nexport class PlatformTest extends DITest {\n public static adapter: Type<PlatformAdapter>;\n\n static async create(settings: DITestOptions = {}) {\n DITest.injector = PlatformTest.createInjector(getConfiguration(settings));\n await DITest.createContainer(settings);\n }\n\n /**\n * Create a new injector with the right default services\n */\n static createInjector(settings: any = {}): InjectorService {\n return createInjector({\n settings: DITest.configure({httpPort: false, httpsPort: false, ...settings})\n });\n }\n\n /**\n * Load the server silently without listening port and configure it on test profile.\n * @decorator\n * @param mod\n * @param listen\n * @param settings\n * @returns {Promise<void>}\n */\n static bootstrap(mod: any, {listen, ...settings}: Partial<PlatformBuilderSettings & {listen: boolean}> = {}): () => Promise<void> {\n return async function before(): Promise<void> {\n let instance: PlatformBuilder;\n const adapter: Type<PlatformAdapter> = settings.platform || settings.adapter || PlatformTest.adapter;\n\n /* istanbul ignore next */\n if (!adapter) {\n throw new Error(\n \"Platform adapter is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?\"\n );\n }\n\n // @ts-ignore\n settings = DITest.configure(settings);\n settings.adapter = adapter as any;\n\n instance = await PlatformBuilder.build(mod, settings).bootstrap();\n await instance.listen(!!listen);\n\n // used by inject method\n DITest.injector = instance.injector;\n };\n }\n\n /**\n * It injects services into the test function where you can alter, spy on, and manipulate them.\n *\n * The inject function has two parameters\n *\n * * an array of Service dependency injection tokens,\n * * a test function whose parameters correspond exactly to each item in the injection token array.\n *\n * @param targets\n * @param func\n */\n static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T> {\n return async (): Promise<T> => {\n if (!DITest.hasInjector()) {\n await PlatformTest.create();\n }\n\n const injector: InjectorService = DITest.injector;\n const deps = [];\n\n for (const target of targets) {\n deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));\n }\n\n return await func(...deps);\n };\n }\n\n /**\n * Return the raw application (express or koa).\n * Use this callback with SuperTest.\n *\n * ```typescript\n * let request: SuperTest.SuperTest<SuperTest.Test>;\n * beforeEach(PlatformTest.bootstrap(Server, {\n * mount: {\n * \"/rest\": [ProductsController]\n * }\n * }));\n * beforeEach(() => {\n * request = SuperTest(PlatformTest.callback());\n * });\n * ```\n */\n static callback() {\n return DITest.injector.get<PlatformApplication>(PlatformApplication)?.callback();\n }\n\n static createRequest(options: any = {}): any {\n return {\n headers: {},\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n accepts(mime?: string | string[]) {\n return accepts(this).types([].concat(mime as never));\n },\n ...options\n };\n }\n\n static createResponse(options: any = {}): any {\n return {\n headers: {},\n locals: {},\n statusCode: 200,\n status(code: number) {\n this.statusCode = code;\n return this;\n },\n contentType(content: string) {\n this.set(\"content-type\", content);\n },\n contentLength(content: number) {\n this.set(\"content-length\", content);\n },\n redirect(status: number, path: string) {\n this.statusCode = status;\n this.set(\"location\", path);\n },\n location(path: string) {\n this.set(\"location\", path);\n },\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n getHeaders() {\n return this.headers;\n },\n set(key: string, value: any) {\n this.headers[key.toLowerCase()] = value;\n return this;\n },\n send(data: any) {\n this.data = data;\n },\n json(data: any) {\n this.data = data;\n },\n ...options\n };\n }\n\n static createRequestContext(options: Partial<PlatformContextOptions & any> = {}) {\n const event = {\n request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),\n response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()\n };\n\n return new PlatformContext({\n id: \"id\",\n injector: DITest.injector,\n logger: DITest.injector.logger,\n url: \"/\",\n ...options,\n event\n });\n }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export const value1 = "value";
2
+ export class Test1 {
3
+ }
4
+ //# sourceMappingURL=Test1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Test1.js","sourceRoot":"","sources":["../../../../src/utils/__mock__/Test1.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC;AAE9B,MAAM,OAAO,KAAK;CAAG","sourcesContent":["export const value1 = \"value\";\n\nexport class Test1 {}\n"]}
@@ -0,0 +1,4 @@
1
+ export const value2 = "value";
2
+ export class Test2 {
3
+ }
4
+ //# sourceMappingURL=Test2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Test2.js","sourceRoot":"","sources":["../../../../src/utils/__mock__/Test2.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC;AAE9B,MAAM,OAAO,KAAK;CAAG","sourcesContent":["export const value2 = \"value\";\n\nexport class Test2 {}\n"]}