@tsed/common 7.0.0-beta.2 → 7.0.0-beta.20

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 (305) hide show
  1. package/coverage.json +6 -0
  2. package/jest.config.js +9 -0
  3. package/lib/cjs/builder/PlatformBuilder.js +94 -65
  4. package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
  5. package/lib/cjs/config/interfaces/PlatformLoggerSettings.js.map +1 -1
  6. package/lib/cjs/config/interfaces/PlatformMulterSettings.js.map +1 -1
  7. package/lib/cjs/config/services/PlatformConfiguration.js +2 -66
  8. package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -1
  9. package/lib/cjs/decorators/multer/multipartFile.js.map +1 -1
  10. package/lib/cjs/decorators/params/error.js +1 -1
  11. package/lib/cjs/decorators/params/error.js.map +1 -1
  12. package/lib/cjs/domain/AnyToPromiseWithCtx.js +4 -5
  13. package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -1
  14. package/lib/cjs/domain/EndpointMetadata.js +2 -66
  15. package/lib/cjs/domain/EndpointMetadata.js.map +1 -1
  16. package/lib/cjs/domain/PlatformContext.js +46 -38
  17. package/lib/cjs/domain/PlatformContext.js.map +1 -1
  18. package/lib/cjs/domain/PlatformRouteDetails.js +0 -21
  19. package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -1
  20. package/lib/cjs/exports.js +32 -0
  21. package/lib/cjs/exports.js.map +1 -0
  22. package/lib/cjs/index.js +58 -30
  23. package/lib/cjs/index.js.map +1 -1
  24. package/lib/cjs/interfaces/PlatformRouteOptions.js.map +1 -1
  25. package/lib/cjs/interfaces/Route.js.map +1 -1
  26. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js +10 -9
  27. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -1
  28. package/lib/cjs/middlewares/PlatformMulterMiddleware.js +27 -13
  29. package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -1
  30. package/lib/cjs/package.json +3 -0
  31. package/lib/cjs/services/FakeAdapter.js +49 -0
  32. package/lib/cjs/services/FakeAdapter.js.map +1 -0
  33. package/lib/cjs/services/Platform.js +33 -68
  34. package/lib/cjs/services/Platform.js.map +1 -1
  35. package/lib/cjs/services/PlatformAdapter.js +24 -0
  36. package/lib/cjs/services/PlatformAdapter.js.map +1 -0
  37. package/lib/cjs/services/PlatformApplication.js +26 -14
  38. package/lib/cjs/services/PlatformApplication.js.map +1 -1
  39. package/lib/cjs/services/PlatformHandler.js +115 -172
  40. package/lib/cjs/services/PlatformHandler.js.map +1 -1
  41. package/lib/cjs/services/PlatformMiddlewaresChain.js +46 -19
  42. package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -1
  43. package/lib/cjs/services/PlatformRequest.js +17 -13
  44. package/lib/cjs/services/PlatformRequest.js.map +1 -1
  45. package/lib/cjs/services/PlatformResponse.js +20 -23
  46. package/lib/cjs/services/PlatformResponse.js.map +1 -1
  47. package/lib/cjs/services/PlatformTest.js +31 -10
  48. package/lib/cjs/services/PlatformTest.js.map +1 -1
  49. package/lib/cjs/utils/createContext.js +32 -21
  50. package/lib/cjs/utils/createContext.js.map +1 -1
  51. package/lib/cjs/utils/createHttpServer.js +6 -11
  52. package/lib/cjs/utils/createHttpServer.js.map +1 -1
  53. package/lib/cjs/utils/createHttpsServer.js +6 -11
  54. package/lib/cjs/utils/createHttpsServer.js.map +1 -1
  55. package/lib/cjs/utils/createInjector.js +16 -10
  56. package/lib/cjs/utils/createInjector.js.map +1 -1
  57. package/lib/cjs/utils/ensureContext.js +16 -0
  58. package/lib/cjs/utils/ensureContext.js.map +1 -0
  59. package/lib/cjs/utils/getConfiguration.js +6 -12
  60. package/lib/cjs/utils/getConfiguration.js.map +1 -1
  61. package/lib/cjs/utils/printRoutes.js +10 -8
  62. package/lib/cjs/utils/printRoutes.js.map +1 -1
  63. package/lib/cjs/utils/setResponseHeaders.js +8 -14
  64. package/lib/cjs/utils/setResponseHeaders.js.map +1 -1
  65. package/lib/esm/builder/PlatformBuilder.js +74 -68
  66. package/lib/esm/builder/PlatformBuilder.js.map +1 -1
  67. package/lib/esm/config/interfaces/PlatformLoggerSettings.js.map +1 -1
  68. package/lib/esm/config/interfaces/PlatformMulterSettings.js.map +1 -1
  69. package/lib/esm/config/services/PlatformConfiguration.js +0 -64
  70. package/lib/esm/config/services/PlatformConfiguration.js.map +1 -1
  71. package/lib/esm/decorators/multer/multerFileSize.js +1 -1
  72. package/lib/esm/decorators/multer/multerOptions.js +1 -1
  73. package/lib/esm/decorators/multer/multipartFile.js +1 -1
  74. package/lib/esm/decorators/multer/multipartFile.js.map +1 -1
  75. package/lib/esm/decorators/params/error.js +1 -1
  76. package/lib/esm/decorators/params/error.js.map +1 -1
  77. package/lib/esm/domain/AnyToPromiseWithCtx.js +4 -5
  78. package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -1
  79. package/lib/esm/domain/EndpointMetadata.js +1 -66
  80. package/lib/esm/domain/EndpointMetadata.js.map +1 -1
  81. package/lib/esm/domain/PlatformContext.js +49 -41
  82. package/lib/esm/domain/PlatformContext.js.map +1 -1
  83. package/lib/esm/domain/PlatformRouteDetails.js +1 -19
  84. package/lib/esm/domain/PlatformRouteDetails.js.map +1 -1
  85. package/lib/esm/exports.js +14 -0
  86. package/lib/esm/exports.js.map +1 -0
  87. package/lib/esm/index.js +58 -27
  88. package/lib/esm/index.js.map +1 -1
  89. package/lib/esm/interfaces/PlatformRouteOptions.js.map +1 -1
  90. package/lib/esm/interfaces/Route.js.map +1 -1
  91. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js +2 -1
  92. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -1
  93. package/lib/esm/middlewares/PlatformMulterMiddleware.js +18 -5
  94. package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -1
  95. package/lib/esm/package.json +3 -0
  96. package/lib/esm/services/FakeAdapter.js +45 -0
  97. package/lib/esm/services/FakeAdapter.js.map +1 -0
  98. package/lib/esm/services/Platform.js +34 -69
  99. package/lib/esm/services/Platform.js.map +1 -1
  100. package/lib/esm/services/PlatformAdapter.js +20 -0
  101. package/lib/esm/services/PlatformAdapter.js.map +1 -0
  102. package/lib/esm/services/PlatformApplication.js +27 -15
  103. package/lib/esm/services/PlatformApplication.js.map +1 -1
  104. package/lib/esm/services/PlatformHandler.js +116 -173
  105. package/lib/esm/services/PlatformHandler.js.map +1 -1
  106. package/lib/esm/services/PlatformMiddlewaresChain.js +49 -22
  107. package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -1
  108. package/lib/esm/services/PlatformRequest.js +16 -12
  109. package/lib/esm/services/PlatformRequest.js.map +1 -1
  110. package/lib/esm/services/PlatformResponse.js +19 -22
  111. package/lib/esm/services/PlatformResponse.js.map +1 -1
  112. package/lib/esm/services/PlatformTest.js +34 -14
  113. package/lib/esm/services/PlatformTest.js.map +1 -1
  114. package/lib/esm/utils/createContext.js +33 -23
  115. package/lib/esm/utils/createContext.js.map +1 -1
  116. package/lib/esm/utils/createHttpServer.js +6 -11
  117. package/lib/esm/utils/createHttpServer.js.map +1 -1
  118. package/lib/esm/utils/createHttpsServer.js +6 -11
  119. package/lib/esm/utils/createHttpsServer.js.map +1 -1
  120. package/lib/esm/utils/createInjector.js +20 -14
  121. package/lib/esm/utils/createInjector.js.map +1 -1
  122. package/lib/esm/utils/ensureContext.js +12 -0
  123. package/lib/esm/utils/ensureContext.js.map +1 -0
  124. package/lib/esm/utils/getConfiguration.js +8 -14
  125. package/lib/esm/utils/getConfiguration.js.map +1 -1
  126. package/lib/esm/utils/printRoutes.js +10 -8
  127. package/lib/esm/utils/printRoutes.js.map +1 -1
  128. package/lib/esm/utils/setResponseHeaders.js +8 -14
  129. package/lib/esm/utils/setResponseHeaders.js.map +1 -1
  130. package/lib/types/builder/PlatformBuilder.d.ts +19 -17
  131. package/lib/types/config/interfaces/PlatformLoggerSettings.d.ts +2 -43
  132. package/lib/types/config/interfaces/PlatformMulterSettings.d.ts +6 -130
  133. package/lib/types/config/services/PlatformConfiguration.d.ts +6 -21
  134. package/lib/types/domain/AnyToPromiseWithCtx.d.ts +1 -9
  135. package/lib/types/domain/EndpointMetadata.d.ts +1 -50
  136. package/lib/types/domain/PlatformContext.d.ts +32 -18
  137. package/lib/types/domain/PlatformRouteDetails.d.ts +4 -20
  138. package/lib/types/exports.d.ts +13 -0
  139. package/lib/types/index.d.ts +56 -18
  140. package/lib/types/interfaces/PlatformRouteOptions.d.ts +1 -2
  141. package/lib/types/interfaces/Route.d.ts +2 -3
  142. package/lib/types/middlewares/PlatformMulterMiddleware.d.ts +8 -3
  143. package/lib/types/services/FakeAdapter.d.ts +31 -0
  144. package/lib/types/services/Platform.d.ts +9 -21
  145. package/lib/types/services/PlatformAdapter.d.ts +58 -0
  146. package/lib/types/services/PlatformApplication.d.ts +15 -7
  147. package/lib/types/services/PlatformHandler.d.ts +21 -59
  148. package/lib/types/services/PlatformMiddlewaresChain.d.ts +6 -3
  149. package/lib/types/services/PlatformRequest.d.ts +8 -10
  150. package/lib/types/services/PlatformResponse.d.ts +15 -19
  151. package/lib/types/services/PlatformTest.d.ts +5 -4
  152. package/lib/types/utils/createContext.d.ts +4 -1
  153. package/lib/types/utils/createHttpServer.d.ts +1 -1
  154. package/lib/types/utils/createHttpsServer.d.ts +3 -1
  155. package/lib/types/utils/createInjector.d.ts +5 -3
  156. package/lib/types/utils/ensureContext.d.ts +2 -0
  157. package/lib/types/utils/listenServer.d.ts +2 -0
  158. package/package.json +43 -26
  159. package/readme.md +52 -58
  160. package/tsconfig.compile.esm.json +2 -12
  161. package/lib/cjs/builder/PlatformControllerBuilder.js +0 -85
  162. package/lib/cjs/builder/PlatformControllerBuilder.js.map +0 -1
  163. package/lib/cjs/config/index.js +0 -7
  164. package/lib/cjs/config/index.js.map +0 -1
  165. package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js +0 -3
  166. package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js.map +0 -1
  167. package/lib/cjs/config/interfaces/index.js +0 -8
  168. package/lib/cjs/config/interfaces/index.js.map +0 -1
  169. package/lib/cjs/decorators/httpServer.js +0 -32
  170. package/lib/cjs/decorators/httpServer.js.map +0 -1
  171. package/lib/cjs/decorators/httpsServer.js +0 -32
  172. package/lib/cjs/decorators/httpsServer.js.map +0 -1
  173. package/lib/cjs/decorators/index.js +0 -21
  174. package/lib/cjs/decorators/index.js.map +0 -1
  175. package/lib/cjs/decorators/method/acceptMime.js +0 -28
  176. package/lib/cjs/decorators/method/acceptMime.js.map +0 -1
  177. package/lib/cjs/decorators/method/endpointFn.js +0 -15
  178. package/lib/cjs/decorators/method/endpointFn.js.map +0 -1
  179. package/lib/cjs/decorators/method/location.js +0 -6
  180. package/lib/cjs/decorators/method/location.js.map +0 -1
  181. package/lib/cjs/decorators/method/redirect.js +0 -6
  182. package/lib/cjs/decorators/method/redirect.js.map +0 -1
  183. package/lib/cjs/decorators/method/route.js +0 -13
  184. package/lib/cjs/decorators/method/route.js.map +0 -1
  185. package/lib/cjs/decorators/method/view.js +0 -34
  186. package/lib/cjs/decorators/method/view.js.map +0 -1
  187. package/lib/cjs/decorators/multer/index.js +0 -7
  188. package/lib/cjs/decorators/multer/index.js.map +0 -1
  189. package/lib/cjs/domain/ControllerProvider.js +0 -51
  190. package/lib/cjs/domain/ControllerProvider.js.map +0 -1
  191. package/lib/cjs/domain/HandlerMetadata.js +0 -57
  192. package/lib/cjs/domain/HandlerMetadata.js.map +0 -1
  193. package/lib/cjs/domain/index.js +0 -10
  194. package/lib/cjs/domain/index.js.map +0 -1
  195. package/lib/cjs/interfaces/PathType.js +0 -3
  196. package/lib/cjs/interfaces/PathType.js.map +0 -1
  197. package/lib/cjs/interfaces/PlatformAdapter.js +0 -3
  198. package/lib/cjs/interfaces/PlatformAdapter.js.map +0 -1
  199. package/lib/cjs/interfaces/index.js +0 -21
  200. package/lib/cjs/interfaces/index.js.map +0 -1
  201. package/lib/cjs/middlewares/__mock__/FakeCtrl.js +0 -12
  202. package/lib/cjs/middlewares/__mock__/FakeCtrl.js.map +0 -1
  203. package/lib/cjs/middlewares/bindEndpointMiddleware.js +0 -13
  204. package/lib/cjs/middlewares/bindEndpointMiddleware.js.map +0 -1
  205. package/lib/cjs/middlewares/index.js +0 -7
  206. package/lib/cjs/middlewares/index.js.map +0 -1
  207. package/lib/cjs/services/FakeRawDriver.js +0 -26
  208. package/lib/cjs/services/FakeRawDriver.js.map +0 -1
  209. package/lib/cjs/services/PlatformRouter.js +0 -126
  210. package/lib/cjs/services/PlatformRouter.js.map +0 -1
  211. package/lib/cjs/services/index.js +0 -12
  212. package/lib/cjs/services/index.js.map +0 -1
  213. package/lib/cjs/utils/createHandlerMetadata.js +0 -49
  214. package/lib/cjs/utils/createHandlerMetadata.js.map +0 -1
  215. package/lib/cjs/utils/index.js +0 -11
  216. package/lib/cjs/utils/index.js.map +0 -1
  217. package/lib/cjs/utils/useCtxHandler.js +0 -15
  218. package/lib/cjs/utils/useCtxHandler.js.map +0 -1
  219. package/lib/esm/builder/PlatformControllerBuilder.js +0 -79
  220. package/lib/esm/builder/PlatformControllerBuilder.js.map +0 -1
  221. package/lib/esm/config/index.js +0 -4
  222. package/lib/esm/config/index.js.map +0 -1
  223. package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js +0 -2
  224. package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js.map +0 -1
  225. package/lib/esm/config/interfaces/index.js +0 -5
  226. package/lib/esm/config/interfaces/index.js.map +0 -1
  227. package/lib/esm/decorators/httpServer.js +0 -28
  228. package/lib/esm/decorators/httpServer.js.map +0 -1
  229. package/lib/esm/decorators/httpsServer.js +0 -28
  230. package/lib/esm/decorators/httpsServer.js.map +0 -1
  231. package/lib/esm/decorators/index.js +0 -18
  232. package/lib/esm/decorators/index.js.map +0 -1
  233. package/lib/esm/decorators/method/acceptMime.js +0 -24
  234. package/lib/esm/decorators/method/acceptMime.js.map +0 -1
  235. package/lib/esm/decorators/method/endpointFn.js +0 -11
  236. package/lib/esm/decorators/method/endpointFn.js.map +0 -1
  237. package/lib/esm/decorators/method/location.js +0 -2
  238. package/lib/esm/decorators/method/location.js.map +0 -1
  239. package/lib/esm/decorators/method/redirect.js +0 -2
  240. package/lib/esm/decorators/method/redirect.js.map +0 -1
  241. package/lib/esm/decorators/method/route.js +0 -2
  242. package/lib/esm/decorators/method/route.js.map +0 -1
  243. package/lib/esm/decorators/method/view.js +0 -30
  244. package/lib/esm/decorators/method/view.js.map +0 -1
  245. package/lib/esm/decorators/multer/index.js +0 -4
  246. package/lib/esm/decorators/multer/index.js.map +0 -1
  247. package/lib/esm/domain/ControllerProvider.js +0 -47
  248. package/lib/esm/domain/ControllerProvider.js.map +0 -1
  249. package/lib/esm/domain/HandlerMetadata.js +0 -53
  250. package/lib/esm/domain/HandlerMetadata.js.map +0 -1
  251. package/lib/esm/domain/index.js +0 -7
  252. package/lib/esm/domain/index.js.map +0 -1
  253. package/lib/esm/interfaces/PathType.js +0 -2
  254. package/lib/esm/interfaces/PathType.js.map +0 -1
  255. package/lib/esm/interfaces/PlatformAdapter.js +0 -2
  256. package/lib/esm/interfaces/PlatformAdapter.js.map +0 -1
  257. package/lib/esm/interfaces/index.js +0 -18
  258. package/lib/esm/interfaces/index.js.map +0 -1
  259. package/lib/esm/middlewares/__mock__/FakeCtrl.js +0 -9
  260. package/lib/esm/middlewares/__mock__/FakeCtrl.js.map +0 -1
  261. package/lib/esm/middlewares/bindEndpointMiddleware.js +0 -9
  262. package/lib/esm/middlewares/bindEndpointMiddleware.js.map +0 -1
  263. package/lib/esm/middlewares/index.js +0 -4
  264. package/lib/esm/middlewares/index.js.map +0 -1
  265. package/lib/esm/services/FakeRawDriver.js +0 -22
  266. package/lib/esm/services/FakeRawDriver.js.map +0 -1
  267. package/lib/esm/services/PlatformRouter.js +0 -123
  268. package/lib/esm/services/PlatformRouter.js.map +0 -1
  269. package/lib/esm/services/index.js +0 -9
  270. package/lib/esm/services/index.js.map +0 -1
  271. package/lib/esm/utils/createHandlerMetadata.js +0 -45
  272. package/lib/esm/utils/createHandlerMetadata.js.map +0 -1
  273. package/lib/esm/utils/index.js +0 -8
  274. package/lib/esm/utils/index.js.map +0 -1
  275. package/lib/esm/utils/useCtxHandler.js +0 -11
  276. package/lib/esm/utils/useCtxHandler.js.map +0 -1
  277. package/lib/types/builder/PlatformControllerBuilder.d.ts +0 -17
  278. package/lib/types/config/index.d.ts +0 -3
  279. package/lib/types/config/interfaces/EndpointDirectoriesSettings.d.ts +0 -3
  280. package/lib/types/config/interfaces/index.d.ts +0 -97
  281. package/lib/types/decorators/httpServer.d.ts +0 -28
  282. package/lib/types/decorators/httpsServer.d.ts +0 -28
  283. package/lib/types/decorators/index.d.ts +0 -14
  284. package/lib/types/decorators/method/acceptMime.d.ts +0 -19
  285. package/lib/types/decorators/method/endpointFn.d.ts +0 -9
  286. package/lib/types/decorators/method/location.d.ts +0 -1
  287. package/lib/types/decorators/method/redirect.d.ts +0 -1
  288. package/lib/types/decorators/method/route.d.ts +0 -1
  289. package/lib/types/decorators/method/view.d.ts +0 -25
  290. package/lib/types/decorators/multer/index.d.ts +0 -3
  291. package/lib/types/domain/ControllerProvider.d.ts +0 -24
  292. package/lib/types/domain/HandlerMetadata.d.ts +0 -32
  293. package/lib/types/domain/index.d.ts +0 -6
  294. package/lib/types/interfaces/PathType.d.ts +0 -1
  295. package/lib/types/interfaces/PlatformAdapter.d.ts +0 -19
  296. package/lib/types/interfaces/index.d.ts +0 -17
  297. package/lib/types/middlewares/__mock__/FakeCtrl.d.ts +0 -2
  298. package/lib/types/middlewares/bindEndpointMiddleware.d.ts +0 -5
  299. package/lib/types/middlewares/index.d.ts +0 -3
  300. package/lib/types/services/FakeRawDriver.d.ts +0 -15
  301. package/lib/types/services/PlatformRouter.d.ts +0 -48
  302. package/lib/types/services/index.d.ts +0 -8
  303. package/lib/types/utils/createHandlerMetadata.d.ts +0 -8
  304. package/lib/types/utils/index.d.ts +0 -7
  305. package/lib/types/utils/useCtxHandler.d.ts +0 -13
@@ -1,19 +1,27 @@
1
1
  "use strict";
2
- var PlatformResponse_1;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.PlatformResponse = void 0;
5
4
  const tslib_1 = require("tslib");
6
5
  const core_1 = require("@tsed/core");
7
6
  const di_1 = require("@tsed/di");
8
- const onFinished = require("on-finished");
9
7
  /**
10
8
  * Platform Response abstraction layer.
11
9
  * @platform
12
10
  */
13
- let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
14
- constructor({ response }, $ctx) {
11
+ let PlatformResponse = class PlatformResponse {
12
+ $ctx;
13
+ data;
14
+ constructor($ctx) {
15
15
  this.$ctx = $ctx;
16
- this.raw = response;
16
+ }
17
+ /**
18
+ * The current @@PlatformRequest@@.
19
+ */
20
+ get request() {
21
+ return this.$ctx.request;
22
+ }
23
+ get raw() {
24
+ return this.$ctx.event.response;
17
25
  }
18
26
  /**
19
27
  * Get the current statusCode
@@ -41,9 +49,6 @@ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
41
49
  get res() {
42
50
  return this.getRes();
43
51
  }
44
- static onFinished(res, cb) {
45
- onFinished(res, cb);
46
- }
47
52
  /**
48
53
  * Returns the HTTP response header specified by field. The match is case-insensitive.
49
54
  *
@@ -191,7 +196,7 @@ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
191
196
  * @param options
192
197
  */
193
198
  async render(path, options = {}) {
194
- const { PlatformViews } = await Promise.resolve().then(() => (0, tslib_1.__importStar)(require("@tsed/platform-views")));
199
+ const { PlatformViews } = await Promise.resolve().then(() => tslib_1.__importStar(require("@tsed/platform-views")));
195
200
  const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);
196
201
  return platformViews.render(path, {
197
202
  ...this.locals,
@@ -202,7 +207,7 @@ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
202
207
  * Send any data to your consumer.
203
208
  *
204
209
  * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.
205
- * It choose the better way to send the data.
210
+ * It chooses the better way to send the data.
206
211
  *
207
212
  * @param data
208
213
  */
@@ -239,33 +244,25 @@ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
239
244
  * @param cb
240
245
  */
241
246
  onEnd(cb) {
242
- PlatformResponse_1.onFinished(this.getRes(), cb);
247
+ const res = this.getRes();
248
+ res.on("finish", cb);
243
249
  return this;
244
250
  }
245
251
  isDone() {
246
- if (!this.raw) {
252
+ if (this.$ctx.isFinished()) {
247
253
  return true;
248
254
  }
249
255
  const res = this.getRes();
250
256
  return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);
251
257
  }
252
- destroy() {
253
- // @ts-ignore
254
- delete this.raw;
255
- delete this.data;
256
- // @ts-ignore
257
- delete this.request;
258
- // @ts-ignore
259
- delete this.$ctx;
260
- }
261
258
  isHeadersSent() {
262
259
  return this.getRes().headersSent;
263
260
  }
264
261
  };
265
- PlatformResponse = PlatformResponse_1 = (0, tslib_1.__decorate)([
262
+ PlatformResponse = tslib_1.__decorate([
266
263
  (0, di_1.Injectable)(),
267
264
  (0, di_1.Scope)(di_1.ProviderScope.INSTANCE),
268
- (0, tslib_1.__metadata)("design:paramtypes", [Object, Function])
265
+ tslib_1.__metadata("design:paramtypes", [Function])
269
266
  ], PlatformResponse);
270
267
  exports.PlatformResponse = PlatformResponse;
271
268
  //# sourceMappingURL=PlatformResponse.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformResponse.ts"],"names":[],"mappings":";;;;;AAAA,qCAAmE;AACnE,iCAA0D;AAM1D,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAa1C;;;GAGG;AAGH,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;IAU3B,YAAY,EAAC,QAAQ,EAAgB,EAAY,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;QACpE,IAAI,CAAC,GAAG,GAA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,QAAQ,CAAC;;GACjB,gBAAgB,CAsT5B;AAtTY,4CAAgB","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,qCAAmE;AACnE,iCAA0D;AAY1D;;;GAGG;AAGH,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAGN;IAFrB,IAAI,CAAM;IAEV,YAAqB,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;IAAG,CAAC;IAE9C;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IAC3B,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAe,CAAC;IACzC,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,CAAC;IACvB,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,GAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,GAAU,CAAC;IACzB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,UAAU,KAAK,GAAG,CAAC;IACjC,CAAC;IAED;;;;OAIG;IAC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pF,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC;IACnC,CAAC;CACF,CAAA;AA5SY,gBAAgB;IAF5B,IAAA,eAAU,GAAE;IACZ,IAAA,UAAK,EAAC,kBAAa,CAAC,QAAQ,CAAC;;GACjB,gBAAgB,CA4S5B;AA5SY,4CAAgB","sourcesContent":["import {isBoolean, isNumber, isStream, isString} from \"@tsed/core\";\nimport {Injectable, ProviderScope, Scope} from \"@tsed/di\";\nimport {OutgoingHttpHeaders, ServerResponse} from \"http\";\nimport type {PlatformContext} from \"../domain/PlatformContext\";\nimport type {PlatformRequest} from \"./PlatformRequest\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Response {}\n }\n}\n\n/**\n * Platform Response abstraction layer.\n * @platform\n */\n@Injectable()\n@Scope(ProviderScope.INSTANCE)\nexport class PlatformResponse<Res extends Record<string, any> = any> {\n data: any;\n\n constructor(readonly $ctx: PlatformContext) {}\n\n /**\n * The current @@PlatformRequest@@.\n */\n get request(): PlatformRequest {\n return this.$ctx.request;\n }\n\n get raw(): Res {\n return this.$ctx.event.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 /**\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<R = Res>(): R {\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 chooses 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: () => Promise<void> | void): this {\n const res: any = this.getRes();\n\n res.on(\"finish\", cb);\n\n return this;\n }\n\n isDone(): boolean {\n if (this.$ctx.isFinished()) {\n return true;\n }\n\n const res = this.getRes();\n\n return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);\n }\n\n isHeadersSent() {\n return this.getRes().headersSent;\n }\n}\n"]}
@@ -1,16 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlatformTest = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const di_1 = require("@tsed/di");
6
+ const accepts_1 = tslib_1.__importDefault(require("accepts"));
5
7
  const PlatformBuilder_1 = require("../builder/PlatformBuilder");
6
8
  const PlatformContext_1 = require("../domain/PlatformContext");
7
9
  const createInjector_1 = require("../utils/createInjector");
8
- const PlatformApplication_1 = require("./PlatformApplication");
9
10
  const getConfiguration_1 = require("../utils/getConfiguration");
11
+ const PlatformApplication_1 = require("./PlatformApplication");
10
12
  /**
11
13
  * @platform
12
14
  */
13
15
  class PlatformTest extends di_1.DITest {
16
+ static adapter;
14
17
  static async create(settings = {}) {
15
18
  di_1.DITest.injector = PlatformTest.createInjector((0, getConfiguration_1.getConfiguration)(settings));
16
19
  await di_1.DITest.createContainer(settings);
@@ -20,7 +23,6 @@ class PlatformTest extends di_1.DITest {
20
23
  */
21
24
  static createInjector(settings = {}) {
22
25
  return (0, createInjector_1.createInjector)({
23
- providers: [],
24
26
  settings: di_1.DITest.configure({ httpPort: false, httpsPort: false, ...settings })
25
27
  });
26
28
  }
@@ -43,7 +45,13 @@ class PlatformTest extends di_1.DITest {
43
45
  // @ts-ignore
44
46
  settings = di_1.DITest.configure(settings);
45
47
  settings.adapter = adapter;
46
- instance = await PlatformBuilder_1.PlatformBuilder.build(mod, settings).bootstrap();
48
+ const configuration = (0, getConfiguration_1.getConfiguration)(settings, mod);
49
+ const disableComponentsScan = configuration.disableComponentsScan || !!process.env.WEBPACK;
50
+ if (!disableComponentsScan) {
51
+ const { importProviders } = await Promise.resolve().then(() => tslib_1.__importStar(require("@tsed/components-scan")));
52
+ await importProviders(configuration);
53
+ }
54
+ instance = await PlatformBuilder_1.PlatformBuilder.build(mod, configuration).bootstrap();
47
55
  await instance.listen(!!listen);
48
56
  // used by inject method
49
57
  di_1.DITest.injector = instance.injector;
@@ -90,17 +98,19 @@ class PlatformTest extends di_1.DITest {
90
98
  * ```
91
99
  */
92
100
  static callback() {
93
- var _a;
94
- return (_a = di_1.DITest.injector.get(PlatformApplication_1.PlatformApplication)) === null || _a === void 0 ? void 0 : _a.callback();
101
+ return di_1.DITest.injector.get(PlatformApplication_1.PlatformApplication)?.callback();
95
102
  }
96
103
  static createRequest(options = {}) {
97
104
  return {
98
105
  headers: {},
106
+ method: "GET",
107
+ url: "/",
108
+ query: {},
99
109
  get(key) {
100
110
  return this.headers[key.toLowerCase()];
101
111
  },
102
112
  accepts(mime) {
103
- return require("accepts")(this).types([].concat(mime));
113
+ return (0, accepts_1.default)(this).types([].concat(mime));
104
114
  },
105
115
  ...options
106
116
  };
@@ -137,22 +147,29 @@ class PlatformTest extends di_1.DITest {
137
147
  this.headers[key.toLowerCase()] = value;
138
148
  return this;
139
149
  },
150
+ setHeader(key, value) {
151
+ this.headers[key.toLowerCase()] = value;
152
+ return this;
153
+ },
140
154
  send(data) {
141
155
  this.data = data;
142
156
  },
143
157
  json(data) {
144
158
  this.data = data;
145
159
  },
160
+ end(data) {
161
+ this.data = data;
162
+ },
146
163
  ...options
147
164
  };
148
165
  }
149
166
  static createRequestContext(options = {}) {
150
- var _a, _b, _c, _d;
151
167
  const event = {
152
- request: ((_a = options === null || options === void 0 ? void 0 : options.request) === null || _a === void 0 ? void 0 : _a.request) || ((_b = options === null || options === void 0 ? void 0 : options.event) === null || _b === void 0 ? void 0 : _b.request) || PlatformTest.createRequest(),
153
- response: ((_c = options === null || options === void 0 ? void 0 : options.response) === null || _c === void 0 ? void 0 : _c.response) || ((_d = options === null || options === void 0 ? void 0 : options.event) === null || _d === void 0 ? void 0 : _d.response) || PlatformTest.createResponse()
168
+ ...options.event,
169
+ request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),
170
+ response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()
154
171
  };
155
- return new PlatformContext_1.PlatformContext({
172
+ const $ctx = new PlatformContext_1.PlatformContext({
156
173
  id: "id",
157
174
  injector: di_1.DITest.injector,
158
175
  logger: di_1.DITest.injector.logger,
@@ -160,6 +177,10 @@ class PlatformTest extends di_1.DITest {
160
177
  ...options,
161
178
  event
162
179
  });
180
+ if (options.endpoint) {
181
+ $ctx.endpoint = options.endpoint;
182
+ }
183
+ return $ctx;
163
184
  }
164
185
  }
165
186
  exports.PlatformTest = PlatformTest;
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformTest.js","sourceRoot":"","sources":["../../../src/services/PlatformTest.ts"],"names":[],"mappings":";;;AAAA,iCAAgE;AAChE,gEAA2D;AAC3D,+DAAkF;AAClF,4DAAuD;AACvD,+DAA0D;AAC1D,gEAA2D;AAI3D;;GAEG;AACH,MAAa,YAAa,SAAQ,WAAM;IAGtC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAA0B,EAAE;QAC9C,WAAM,CAAC,QAAQ,GAAG,YAAY,CAAC,cAAc,CAAC,IAAA,mCAAgB,EAAC,QAAQ,CAAC,CAAC,CAAC;QAC1E,MAAM,WAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,WAAgB,EAAE;QACtC,OAAO,IAAA,+BAAc,EAAC;YACpB,SAAS,EAAE,EAAE;YACb,QAAQ,EAAE,WAAM,CAAC,SAAS,CAAC,EAAC,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAC,CAAC;SAC7E,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,SAAS,CAAC,GAAQ,EAAE,EAAC,MAAM,EAAE,GAAG,QAAQ,KAA0D,EAAE;QACzG,OAAO,KAAK,UAAU,MAAM;YAC1B,IAAI,QAAyB,CAAC;YAC9B,MAAM,OAAO,GAA0B,QAAQ,CAAC,QAAQ,IAAI,QAAQ,CAAC,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC;YAErG,0BAA0B;YAC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CAAC;YACD,GAAG,CAAC,GAAW,EAAE,KAAU;gBACzB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,KAAK,CAAC;gBACxC,OAAO,IAAI,CAAC;YACd,CAAC;YACD,IAAI,CAAC,IAAS;gBACZ,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,IAAI,CAAC,IAAS;gBACZ,IAAI,CAAC,IAAI,GAAG,IAAI,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,iCAAe,CAAC;YACzB,EAAE,EAAE,IAAI;YACR,QAAQ,EAAE,WAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,WAAM,CAAC,QAAQ,CAAC,MAAM;YAC9B,GAAG,EAAE,GAAG;YACR,GAAG,OAAO;YACV,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF;AAxKD,oCAwKC","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":";;;;AACA,iCAAgE;AAChE,8DAA8B;AAC9B,gEAA2D;AAC3D,+DAAkF;AAClF,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CAAC,QAAQ,CAAC;SAClC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAhMD,oCAgMC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {DITest, DITestOptions, InjectorService} from \"@tsed/di\";\nimport accepts from \"accepts\";\nimport {PlatformBuilder} from \"../builder/PlatformBuilder\";\nimport {PlatformContext, PlatformContextOptions} from \"../domain/PlatformContext\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"./PlatformAdapter\";\nimport {PlatformApplication} from \"./PlatformApplication\";\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 const configuration = getConfiguration(settings, mod);\n const disableComponentsScan = configuration.disableComponentsScan || !!process.env.WEBPACK;\n\n if (!disableComponentsScan) {\n const {importProviders} = await import(\"@tsed/components-scan\");\n await importProviders(configuration);\n }\n\n instance = await PlatformBuilder.build(mod, configuration).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 method: \"GET\",\n url: \"/\",\n query: {},\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 setHeader(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 end(data: any) {\n this.data = data;\n },\n ...options\n };\n }\n\n static createRequestContext(options: Partial<PlatformContextOptions & any> = {}) {\n const event = {\n ...options.event,\n request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),\n response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()\n };\n\n const $ctx = new PlatformContext({\n id: \"id\",\n injector: DITest.injector,\n logger: DITest.injector.logger,\n url: \"/\",\n ...options,\n event\n });\n\n if (options.endpoint) {\n $ctx.endpoint = options.endpoint;\n }\n\n return $ctx;\n }\n}\n"]}
@@ -1,37 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createContext = void 0;
3
+ exports.createContext = exports.buildIgnoreLog = void 0;
4
+ const uuid_1 = require("uuid");
4
5
  const PlatformContext_1 = require("../domain/PlatformContext");
5
6
  const PlatformRequest_1 = require("../services/PlatformRequest");
6
7
  const PlatformResponse_1 = require("../services/PlatformResponse");
7
- const uuidv4 = require("uuid").v4;
8
- const defaultReqIdBuilder = (req) => req.get("x-request-id") || uuidv4().replace(/-/gi, "");
8
+ function defaultReqIdBuilder(req) {
9
+ return req.get("x-request-id") || (0, uuid_1.v4)().split("-").join("");
10
+ }
11
+ function mapIgnoreUrlPatterns(ignoreUrlPatterns) {
12
+ return ignoreUrlPatterns.map((pattern) => (typeof pattern === "string" ? new RegExp(pattern, "gi") : pattern));
13
+ }
14
+ function buildIgnoreLog(ignoreUrlPatterns) {
15
+ if (ignoreUrlPatterns) {
16
+ ignoreUrlPatterns = mapIgnoreUrlPatterns(ignoreUrlPatterns);
17
+ return (ignore, data, url) => ignoreUrlPatterns?.find((reg) => !!url.match(reg));
18
+ }
19
+ }
20
+ exports.buildIgnoreLog = buildIgnoreLog;
9
21
  /**
10
22
  * Create the TsED context to wrap request, response, injector, etc...
11
23
  * @param injector
12
24
  * @ignore
13
25
  */
14
26
  function createContext(injector) {
15
- var _a, _b;
16
- const ResponseKlass = (_a = injector.getProvider(PlatformResponse_1.PlatformResponse)) === null || _a === void 0 ? void 0 : _a.useClass;
17
- const RequestKlass = (_b = injector.getProvider(PlatformRequest_1.PlatformRequest)) === null || _b === void 0 ? void 0 : _b.useClass;
18
- const { reqIdBuilder = defaultReqIdBuilder, ...loggerOptions } = injector.settings.logger || {};
19
- return async (event) => {
20
- const ctx = new PlatformContext_1.PlatformContext({
27
+ const ResponseKlass = injector.getProvider(PlatformResponse_1.PlatformResponse)?.useClass;
28
+ const RequestKlass = injector.getProvider(PlatformRequest_1.PlatformRequest)?.useClass;
29
+ const { reqIdBuilder = defaultReqIdBuilder, ...loggerOptions } = injector.settings.logger;
30
+ const opts = {
31
+ ...loggerOptions,
32
+ logger: injector.logger,
33
+ injector,
34
+ ResponseKlass,
35
+ RequestKlass
36
+ };
37
+ const ignoreLog = buildIgnoreLog(loggerOptions.ignoreUrlPatterns);
38
+ return async function invokeContext(event) {
39
+ const $ctx = new PlatformContext_1.PlatformContext({
40
+ ...opts,
21
41
  event,
22
- id: reqIdBuilder(event.request),
23
- logger: injector.logger,
24
- ...loggerOptions,
25
- injector,
26
- ResponseKlass,
27
- RequestKlass
28
- });
29
- ctx.response.onEnd(async () => {
30
- await ctx.emit("$onResponse", ctx);
31
- await ctx.destroy();
42
+ id: reqIdBuilder(event.request)
32
43
  });
33
- await ctx.emit("$onRequest", ctx);
34
- return ctx;
44
+ ignoreLog && $ctx.logger.alterIgnoreLog((ignore, data) => ignoreLog(ignore, data, $ctx.url));
45
+ return $ctx;
35
46
  };
36
47
  }
37
48
  exports.createContext = createContext;
@@ -1 +1 @@
1
- {"version":3,"file":"createContext.js","sourceRoot":"","sources":["../../../src/utils/createContext.ts"],"names":[],"mappings":";;;AACA,+DAA0D;AAC1D,iEAA4D;AAC5D,mEAA8D;AAG9D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;AAClC,MAAM,mBAAmB,GAAG,CAAC,GAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAEjG;;;;GAIG;AACH,SAAgB,aAAa,CAAC,QAAyB;;IACrD,MAAM,aAAa,GAAG,MAAA,QAAQ,CAAC,WAAW,CAAC,mCAAgB,CAAC,0CAAE,QAAQ,CAAC;IACvE,MAAM,YAAY,GAAG,MAAA,QAAQ,CAAC,WAAW,CAAC,iCAAe,CAAC,0CAAE,QAAQ,CAAC;IACrE,MAAM,EAAC,YAAY,GAAG,mBAAmB,EAAE,GAAG,aAAa,EAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAC;IAE9F,OAAO,KAAK,EAAE,KAAoB,EAA4B,EAAE;QAC9D,MAAM,GAAG,GAAG,IAAI,iCAAe,CAAC;YAC9B,KAAK;YACL,EAAE,EAAE,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC;YAC/B,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,GAAG,aAAa;YAChB,QAAQ;YACR,aAAa;YACb,YAAY;SACb,CAAC,CAAC;QAEH,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE;YAC5B,MAAM,GAAG,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;YACnC,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC;QACtB,CAAC,CAAC,CAAC;QAEH,MAAM,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;QAElC,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;AACJ,CAAC;AAzBD,sCAyBC","sourcesContent":["import {InjectorService} from \"@tsed/di\";\nimport {PlatformContext} from \"../domain/PlatformContext\";\nimport {PlatformRequest} from \"../services/PlatformRequest\";\nimport {PlatformResponse} from \"../services/PlatformResponse\";\nimport {IncomingEvent} from \"../interfaces/IncomingEvent\";\n\nconst uuidv4 = require(\"uuid\").v4;\nconst defaultReqIdBuilder = (req: any) => req.get(\"x-request-id\") || uuidv4().replace(/-/gi, \"\");\n\n/**\n * Create the TsED context to wrap request, response, injector, etc...\n * @param injector\n * @ignore\n */\nexport function createContext(injector: InjectorService) {\n const ResponseKlass = injector.getProvider(PlatformResponse)?.useClass;\n const RequestKlass = injector.getProvider(PlatformRequest)?.useClass;\n const {reqIdBuilder = defaultReqIdBuilder, ...loggerOptions} = injector.settings.logger || {};\n\n return async (event: IncomingEvent): Promise<PlatformContext> => {\n const ctx = new PlatformContext({\n event,\n id: reqIdBuilder(event.request),\n logger: injector.logger,\n ...loggerOptions,\n injector,\n ResponseKlass,\n RequestKlass\n });\n\n ctx.response.onEnd(async () => {\n await ctx.emit(\"$onResponse\", ctx);\n await ctx.destroy();\n });\n\n await ctx.emit(\"$onRequest\", ctx);\n\n return ctx;\n };\n}\n"]}
1
+ {"version":3,"file":"createContext.js","sourceRoot":"","sources":["../../../src/utils/createContext.ts"],"names":[],"mappings":";;;AACA,+BAAwB;AACxB,+DAA0D;AAE1D,iEAA4D;AAC5D,mEAA8D;AAE9D,SAAS,mBAAmB,CAAC,GAAQ;IACnC,OAAO,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,IAAA,SAAE,GAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,oBAAoB,CAAC,iBAAwB;IACpD,OAAO,iBAAiB,CAAC,GAAG,CAAC,CAAC,OAAwB,EAAE,EAAE,CAAC,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;AAClI,CAAC;AAED,SAAgB,cAAc,CAAC,iBAAoC;IACjE,IAAI,iBAAiB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\"@tsed/di\";\nimport {v4} from \"uuid\";\nimport {PlatformContext} from \"../domain/PlatformContext\";\nimport {IncomingEvent} from \"../interfaces/IncomingEvent\";\nimport {PlatformRequest} from \"../services/PlatformRequest\";\nimport {PlatformResponse} from \"../services/PlatformResponse\";\n\nfunction defaultReqIdBuilder(req: any) {\n return req.get(\"x-request-id\") || v4().split(\"-\").join(\"\");\n}\n\nfunction mapIgnoreUrlPatterns(ignoreUrlPatterns: any[]) {\n return ignoreUrlPatterns.map((pattern: string | RegExp) => (typeof pattern === \"string\" ? new RegExp(pattern, \"gi\") : pattern));\n}\n\nexport function buildIgnoreLog(ignoreUrlPatterns: any[] | undefined) {\n if (ignoreUrlPatterns) {\n ignoreUrlPatterns = mapIgnoreUrlPatterns(ignoreUrlPatterns);\n return (ignore: boolean, data: any, url: string) => ignoreUrlPatterns?.find((reg) => !!url.match(reg));\n }\n}\n\n/**\n * Create the TsED context to wrap request, response, injector, etc...\n * @param injector\n * @ignore\n */\nexport function createContext(injector: InjectorService) {\n const ResponseKlass = injector.getProvider(PlatformResponse)?.useClass;\n const RequestKlass = injector.getProvider(PlatformRequest)?.useClass;\n const {reqIdBuilder = defaultReqIdBuilder, ...loggerOptions} = injector.settings.logger;\n\n const opts = {\n ...loggerOptions,\n logger: injector.logger,\n injector,\n ResponseKlass,\n RequestKlass\n };\n\n const ignoreLog = buildIgnoreLog(loggerOptions.ignoreUrlPatterns);\n\n return async function invokeContext(event: IncomingEvent) {\n const $ctx = new PlatformContext({\n ...opts,\n event,\n id: reqIdBuilder(event.request)\n });\n\n ignoreLog && $ctx.logger.alterIgnoreLog((ignore, data) => ignoreLog(ignore, data, $ctx.url));\n\n return $ctx;\n };\n}\n"]}
@@ -4,29 +4,24 @@ exports.createHttpServer = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const di_1 = require("@tsed/di");
6
6
  const core_1 = require("@tsed/core");
7
- const http_1 = (0, tslib_1.__importDefault)(require("http"));
8
- const httpServer_1 = require("../decorators/httpServer");
7
+ const http_1 = tslib_1.__importDefault(require("http"));
9
8
  const listenServer_1 = require("./listenServer");
10
9
  function createHttpServer(injector, requestListener) {
11
10
  const { settings } = injector;
12
- const httpPort = settings.getRaw("httpPort");
13
- const httpOptions = settings.getRaw("httpOptions");
11
+ const httpPort = settings.get("httpPort");
12
+ const httpOptions = settings.get("httpOptions");
14
13
  const server = httpPort !== false ? http_1.default.createServer(httpOptions, requestListener) : null;
15
- injector.addProvider(httpServer_1.HttpServer, {
16
- scope: di_1.ProviderScope.SINGLETON,
17
- useValue: server
18
- });
19
14
  injector.addProvider(http_1.default.Server, {
20
15
  scope: di_1.ProviderScope.SINGLETON,
21
16
  useValue: server
22
17
  });
23
- injector.invoke(httpServer_1.HttpServer);
24
18
  injector.invoke(http_1.default.Server);
25
- if (httpPort !== false) {
19
+ if (server) {
26
20
  const hostInfo = (0, core_1.getHostInfoFromPort)("http", httpPort);
27
21
  return async () => {
28
22
  const resolvedHostInfo = await (0, listenServer_1.listenServer)(injector, server, hostInfo);
29
- settings.setRaw("httpPort", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);
23
+ settings.set("httpPort", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);
24
+ return server;
30
25
  };
31
26
  }
32
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createHttpServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpServer.ts"],"names":[],"mappings":";;;;AAAA,iCAAwD;AACxD,qCAA+C;AAC/C,6DAAwB;AACxB,yDAAoD;AACpD,iDAA4C;AAE5C,SAAgB,gBAAgB,CAAC,QAAyB,EAAE,eAAqC;IAC/F,MAAM,EAAC,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAC5B,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7C,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAEnD,MAAM,MAAM,GAAG,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,cAAI,CAAC,YAAY,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE3F,QAAQ,CAAC,WAAW,CAAC,uBAAU,EAAE;QAC/B,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,WAAW,CAAC,cAAI,CAAC,MAAM,EAAE;QAChC,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,uBAAU,CAAC,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,cAAI,CAAC,MAAM,CAAC,CAAC;IAE7B,IAAI,QAAQ,KAAK,KAAK,EAAE;QACtB,MAAM,QAAQ,GAAG,IAAA,0BAAmB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAEvD,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,gBAAgB,GAAG,MAAM,IAAA,2BAAY,EAAC,QAAQ,EAAE,MAAqB,EAAE,QAAQ,CAAC,CAAC;YACvF,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,gBAAgB,CAAC,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;QACtF,CAAC,CAAC;KACH;AACH,CAAC;AA5BD,4CA4BC","sourcesContent":["import {InjectorService, ProviderScope} from \"@tsed/di\";\nimport {getHostInfoFromPort} from \"@tsed/core\";\nimport Http from \"http\";\nimport {HttpServer} from \"../decorators/httpServer\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpServer(injector: InjectorService, requestListener: Http.RequestListener) {\n const {settings} = injector;\n const httpPort = settings.getRaw(\"httpPort\");\n const httpOptions = settings.getRaw(\"httpOptions\");\n\n const server = httpPort !== false ? Http.createServer(httpOptions, requestListener) : null;\n\n injector.addProvider(HttpServer, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.addProvider(Http.Server, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.invoke(HttpServer);\n injector.invoke(Http.Server);\n\n if (httpPort !== false) {\n const hostInfo = getHostInfoFromPort(\"http\", httpPort);\n\n return async () => {\n const resolvedHostInfo = await listenServer(injector, server as Http.Server, hostInfo);\n settings.setRaw(\"httpPort\", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);\n };\n }\n}\n"]}
1
+ {"version":3,"file":"createHttpServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpServer.ts"],"names":[],"mappings":";;;;AAAA,iCAAwD;AACxD,qCAA+C;AAC/C,wDAAwB;AACxB,iDAA4C;AAE5C,SAAgB,gBAAgB,CAAC,QAAyB,EAAE,eAAqC;IAC/F,MAAM,EAAC,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAC5B,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC1C,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAEhD,MAAM,MAAM,GAAG,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,cAAI,CAAC,YAAY,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE3F,QAAQ,CAAC,WAAW,CAAC,cAAI,CAAC,MAAM,EAAE;QAChC,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,cAAI,CAAC,MAAM,CAAC,CAAC;IAE7B,IAAI,MAAM,EAAE;QACV,MAAM,QAAQ,GAAG,IAAA,0BAAmB,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAEvD,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,gBAAgB,GAAG,MAAM,IAAA,2BAAY,EAAC,QAAQ,EAAE,MAAqB,EAAE,QAAQ,CAAC,CAAC;YACvF,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,gBAAgB,CAAC,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;YACjF,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;KACH;AACH,CAAC;AAvBD,4CAuBC","sourcesContent":["import {InjectorService, ProviderScope} from \"@tsed/di\";\nimport {getHostInfoFromPort} from \"@tsed/core\";\nimport Http from \"http\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpServer(injector: InjectorService, requestListener: Http.RequestListener) {\n const {settings} = injector;\n const httpPort = settings.get(\"httpPort\");\n const httpOptions = settings.get(\"httpOptions\");\n\n const server = httpPort !== false ? Http.createServer(httpOptions, requestListener) : null;\n\n injector.addProvider(Http.Server, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.invoke(Http.Server);\n\n if (server) {\n const hostInfo = getHostInfoFromPort(\"http\", httpPort);\n\n return async () => {\n const resolvedHostInfo = await listenServer(injector, server as Http.Server, hostInfo);\n settings.set(\"httpPort\", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);\n return server;\n };\n }\n}\n"]}
@@ -4,29 +4,24 @@ exports.createHttpsServer = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const di_1 = require("@tsed/di");
6
6
  const core_1 = require("@tsed/core");
7
- const https_1 = (0, tslib_1.__importDefault)(require("https"));
8
- const httpsServer_1 = require("../decorators/httpsServer");
7
+ const https_1 = tslib_1.__importDefault(require("https"));
9
8
  const listenServer_1 = require("./listenServer");
10
9
  function createHttpsServer(injector, requestListener) {
11
10
  const { settings } = injector;
12
- const httpsPort = settings.getRaw("httpsPort");
13
- const httpsOptions = settings.getRaw("httpsOptions");
11
+ const httpsPort = settings.get("httpsPort");
12
+ const httpsOptions = settings.get("httpsOptions");
14
13
  const server = httpsPort !== false ? https_1.default.createServer(httpsOptions, requestListener) : null;
15
- injector.addProvider(httpsServer_1.HttpsServer, {
16
- scope: di_1.ProviderScope.SINGLETON,
17
- useValue: server
18
- });
19
14
  injector.addProvider(https_1.default.Server, {
20
15
  scope: di_1.ProviderScope.SINGLETON,
21
16
  useValue: server
22
17
  });
23
- injector.invoke(httpsServer_1.HttpsServer);
24
18
  injector.invoke(https_1.default.Server);
25
- if (httpsPort !== false) {
19
+ if (server) {
26
20
  const hostInfo = (0, core_1.getHostInfoFromPort)("https", httpsPort);
27
21
  return async () => {
28
22
  const resolvedHostInfo = await (0, listenServer_1.listenServer)(injector, server, hostInfo);
29
- settings.setRaw("httpsPort", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);
23
+ settings.set("httpsPort", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);
24
+ return server;
30
25
  };
31
26
  }
32
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createHttpsServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpsServer.ts"],"names":[],"mappings":";;;;AAAA,iCAAwD;AACxD,qCAA+C;AAC/C,+DAA0B;AAE1B,2DAAsD;AACtD,iDAA4C;AAE5C,SAAgB,iBAAiB,CAAC,QAAyB,EAAE,eAAsC;IACjG,MAAM,EAAC,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAC5B,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAErD,MAAM,MAAM,GAAG,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,eAAK,CAAC,YAAY,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE9F,QAAQ,CAAC,WAAW,CAAC,yBAAW,EAAE;QAChC,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,WAAW,CAAC,eAAK,CAAC,MAAM,EAAE;QACjC,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,yBAAW,CAAC,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,eAAK,CAAC,MAAM,CAAC,CAAC;IAE9B,IAAI,SAAS,KAAK,KAAK,EAAE;QACvB,MAAM,QAAQ,GAAG,IAAA,0BAAmB,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAEzD,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,gBAAgB,GAAG,MAAM,IAAA,2BAAY,EAAC,QAAQ,EAAE,MAAsB,EAAE,QAAQ,CAAC,CAAC;YACxF,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,gBAAgB,CAAC,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;QACvF,CAAC,CAAC;KACH;AACH,CAAC;AA5BD,8CA4BC","sourcesContent":["import {InjectorService, ProviderScope} from \"@tsed/di\";\nimport {getHostInfoFromPort} from \"@tsed/core\";\nimport Https from \"https\";\nimport Http from \"http\";\nimport {HttpsServer} from \"../decorators/httpsServer\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpsServer(injector: InjectorService, requestListener?: Http.RequestListener) {\n const {settings} = injector;\n const httpsPort = settings.getRaw(\"httpsPort\");\n const httpsOptions = settings.getRaw(\"httpsOptions\");\n\n const server = httpsPort !== false ? Https.createServer(httpsOptions, requestListener) : null;\n\n injector.addProvider(HttpsServer, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.addProvider(Https.Server, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.invoke(HttpsServer);\n injector.invoke(Https.Server);\n\n if (httpsPort !== false) {\n const hostInfo = getHostInfoFromPort(\"https\", httpsPort);\n\n return async () => {\n const resolvedHostInfo = await listenServer(injector, server as Https.Server, hostInfo);\n settings.setRaw(\"httpsPort\", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);\n };\n }\n}\n"]}
1
+ {"version":3,"file":"createHttpsServer.js","sourceRoot":"","sources":["../../../src/utils/createHttpsServer.ts"],"names":[],"mappings":";;;;AAAA,iCAAwD;AACxD,qCAA+C;AAC/C,0DAA0B;AAE1B,iDAA4C;AAE5C,SAAgB,iBAAiB,CAAC,QAAyB,EAAE,eAAsC;IACjG,MAAM,EAAC,QAAQ,EAAC,GAAG,QAAQ,CAAC;IAC5B,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC5C,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAElD,MAAM,MAAM,GAAG,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,eAAK,CAAC,YAAY,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAE9F,QAAQ,CAAC,WAAW,CAAC,eAAK,CAAC,MAAM,EAAE;QACjC,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,eAAK,CAAC,MAAM,CAAC,CAAC;IAE9B,IAAI,MAAM,EAAE;QACV,MAAM,QAAQ,GAAG,IAAA,0BAAmB,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAEzD,OAAO,KAAK,IAAI,EAAE;YAChB,MAAM,gBAAgB,GAAG,MAAM,IAAA,2BAAY,EAAC,QAAQ,EAAE,MAAsB,EAAE,QAAQ,CAAC,CAAC;YACxF,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,gBAAgB,CAAC,OAAO,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;YAClF,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;KACH;AACH,CAAC;AAvBD,8CAuBC","sourcesContent":["import {InjectorService, ProviderScope} from \"@tsed/di\";\nimport {getHostInfoFromPort} from \"@tsed/core\";\nimport Https from \"https\";\nimport Http from \"http\";\nimport {listenServer} from \"./listenServer\";\n\nexport function createHttpsServer(injector: InjectorService, requestListener?: Http.RequestListener) {\n const {settings} = injector;\n const httpsPort = settings.get(\"httpsPort\");\n const httpsOptions = settings.get(\"httpsOptions\");\n\n const server = httpsPort !== false ? Https.createServer(httpsOptions, requestListener) : null;\n\n injector.addProvider(Https.Server, {\n scope: ProviderScope.SINGLETON,\n useValue: server\n });\n\n injector.invoke(Https.Server);\n\n if (server) {\n const hostInfo = getHostInfoFromPort(\"https\", httpsPort);\n\n return async () => {\n const resolvedHostInfo = await listenServer(injector, server as Https.Server, hostInfo);\n settings.set(\"httpsPort\", `${resolvedHostInfo.address}:${resolvedHostInfo.port}`);\n return server;\n };\n }\n}\n"]}
@@ -1,34 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createInjector = void 0;
4
+ const core_1 = require("@tsed/core");
4
5
  const di_1 = require("@tsed/di");
5
6
  const logger_1 = require("@tsed/logger");
6
- const core_1 = require("@tsed/core");
7
7
  const PlatformConfiguration_1 = require("../config/services/PlatformConfiguration");
8
- const PlatformHandler_1 = require("../services/PlatformHandler");
9
- const PlatformResponse_1 = require("../services/PlatformResponse");
10
- const PlatformRouter_1 = require("../services/PlatformRouter");
11
- const PlatformApplication_1 = require("../services/PlatformApplication");
12
8
  const Platform_1 = require("../services/Platform");
9
+ const PlatformAdapter_1 = require("../services/PlatformAdapter");
10
+ const PlatformApplication_1 = require("../services/PlatformApplication");
11
+ const PlatformHandler_1 = require("../services/PlatformHandler");
13
12
  const PlatformRequest_1 = require("../services/PlatformRequest");
13
+ const PlatformResponse_1 = require("../services/PlatformResponse");
14
14
  logger_1.$log.name = "TSED";
15
15
  const DEFAULT_PROVIDERS = [
16
16
  { provide: PlatformHandler_1.PlatformHandler },
17
17
  { provide: PlatformResponse_1.PlatformResponse },
18
18
  { provide: PlatformRequest_1.PlatformRequest },
19
- { provide: PlatformRouter_1.PlatformRouter },
20
19
  { provide: PlatformApplication_1.PlatformApplication },
21
20
  { provide: Platform_1.Platform }
22
21
  ];
23
- function createInjector({ providers = [], settings = {} }) {
22
+ function createInjector({ adapter, settings = {} }) {
24
23
  const injector = new di_1.InjectorService();
25
24
  injector.addProvider(PlatformConfiguration_1.PlatformConfiguration);
26
25
  injector.settings = injector.invoke(PlatformConfiguration_1.PlatformConfiguration);
27
26
  injector.logger = logger_1.$log;
28
27
  injector.settings.set(settings);
29
- (0, di_1.setLoggerLevel)(injector);
30
- providers = [...DEFAULT_PROVIDERS, ...providers];
31
- (0, core_1.toMap)(providers, "provide").forEach((provider, token) => {
28
+ if (adapter) {
29
+ injector.addProvider(PlatformAdapter_1.PlatformAdapter, {
30
+ useClass: adapter
31
+ });
32
+ }
33
+ injector.invoke(PlatformAdapter_1.PlatformAdapter);
34
+ (0, di_1.setLoggerConfiguration)(injector);
35
+ const instance = injector.get(PlatformAdapter_1.PlatformAdapter);
36
+ instance.providers = [...DEFAULT_PROVIDERS, ...instance.providers];
37
+ (0, core_1.toMap)(instance.providers, "provide").forEach((provider, token) => {
32
38
  injector.addProvider(token, provider);
33
39
  });
34
40
  injector.invoke(PlatformApplication_1.PlatformApplication);
@@ -1 +1 @@
1
- {"version":3,"file":"createInjector.js","sourceRoot":"","sources":["../../../src/utils/createInjector.ts"],"names":[],"mappings":";;;AAAA,iCAAoE;AACpE,yCAAkC;AAClC,qCAAiC;AACjC,oFAA+E;AAC/E,iEAA4D;AAC5D,mEAA8D;AAC9D,+DAA0D;AAC1D,yEAAoE;AACpE,mDAA8C;AAC9C,iEAA4D;AAE5D,aAAI,CAAC,IAAI,GAAG,MAAM,CAAC;AAEnB,MAAM,iBAAiB,GAAG;IACxB,EAAC,OAAO,EAAE,iCAAe,EAAC;IAC1B,EAAC,OAAO,EAAE,mCAAgB,EAAC;IAC3B,EAAC,OAAO,EAAE,iCAAe,EAAC;IAC1B,EAAC,OAAO,EAAE,+BAAc,EAAC;IACzB,EAAC,OAAO,EAAE,yCAAmB,EAAC;IAC9B,EAAC,OAAO,EAAE,mBAAQ,EAAC;CACpB,CAAC;AAOF,SAAgB,cAAc,CAAC,EAAC,SAAS,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAwB;IACnF,MAAM,QAAQ,GAAG,IAAI,oBAAe,EAAE,CAAC;IACvC,QAAQ,CAAC,WAAW,CAAC,6CAAqB,CAAC,CAAC;IAE5C,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,6CAAqB,CAAC,CAAC;IAC3D,QAAQ,CAAC,MAAM,GAAG,aAAI,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEhC,IAAA,mBAAc,EAAC,QAAQ,CAAC,CAAC;IAEzB,SAAS,GAAG,CAAC,GAAG,iBAAiB,EAAE,GAAG,SAAS,CAAC,CAAC;IAEjD,IAAA,YAAK,EAAiB,SAAS,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;QACtE,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,yCAAmB,CAAC,CAAC;IAErC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAnBD,wCAmBC","sourcesContent":["import {InjectorService, IProvider, setLoggerLevel} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {toMap} from \"@tsed/core\";\nimport {PlatformConfiguration} from \"../config/services/PlatformConfiguration\";\nimport {PlatformHandler} from \"../services/PlatformHandler\";\nimport {PlatformResponse} from \"../services/PlatformResponse\";\nimport {PlatformRouter} from \"../services/PlatformRouter\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformRequest} from \"../services/PlatformRequest\";\n\n$log.name = \"TSED\";\n\nconst DEFAULT_PROVIDERS = [\n {provide: PlatformHandler},\n {provide: PlatformResponse},\n {provide: PlatformRequest},\n {provide: PlatformRouter},\n {provide: PlatformApplication},\n {provide: Platform}\n];\n\ninterface CreateInjectorOptions {\n providers?: IProvider[];\n settings?: Partial<TsED.Configuration>;\n}\n\nexport function createInjector({providers = [], settings = {}}: CreateInjectorOptions) {\n const injector = new InjectorService();\n injector.addProvider(PlatformConfiguration);\n\n injector.settings = injector.invoke(PlatformConfiguration);\n injector.logger = $log;\n injector.settings.set(settings);\n\n setLoggerLevel(injector);\n\n providers = [...DEFAULT_PROVIDERS, ...providers];\n\n toMap<any, IProvider>(providers, \"provide\").forEach((provider, token) => {\n injector.addProvider(token, provider);\n });\n\n injector.invoke(PlatformApplication);\n\n return injector;\n}\n"]}
1
+ {"version":3,"file":"createInjector.js","sourceRoot":"","sources":["../../../src/utils/createInjector.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AACvC,iCAA+E;AAC/E,yCAAkC;AAClC,oFAA+E;AAC/E,mDAA8C;AAC9C,iEAA4D;AAC5D,yEAAoE;AACpE,iEAA4D;AAC5D,iEAA4D;AAC5D,mEAA8D;AAE9D,aAAI,CAAC,IAAI,GAAG,MAAM,CAAC;AAEnB,MAAM,iBAAiB,GAAG;IACxB,EAAC,OAAO,EAAE,iCAAe,EAAC;IAC1B,EAAC,OAAO,EAAE,mCAAgB,EAAC;IAC3B,EAAC,OAAO,EAAE,iCAAe,EAAC;IAC1B,EAAC,OAAO,EAAE,yCAAmB,EAAC;IAC9B,EAAC,OAAO,EAAE,mBAAQ,EAAC;CACpB,CAAC;AAOF,SAAgB,cAAc,CAAC,EAAC,OAAO,EAAE,QAAQ,GAAG,EAAE,EAAwB;IAC5E,MAAM,QAAQ,GAAG,IAAI,oBAAe,EAAE,CAAC;IACvC,QAAQ,CAAC,WAAW,CAAC,6CAAqB,CAAC,CAAC;IAE5C,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,6CAAqB,CAAC,CAAC;IAC3D,QAAQ,CAAC,MAAM,GAAG,aAAI,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEhC,IAAI,OAAO,EAAE;QACX,QAAQ,CAAC,WAAW,CAAC,iCAAe,EAAE;YACpC,QAAQ,EAAE,OAAO;SAClB,CAAC,CAAC;KACJ;IAED,QAAQ,CAAC,MAAM,CAAC,iCAAe,CAAC,CAAC;IAEjC,IAAA,2BAAsB,EAAC,QAAQ,CAAC,CAAC;IAEjC,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAkB,iCAAe,CAAE,CAAC;IAEjE,QAAQ,CAAC,SAAS,GAAG,CAAC,GAAG,iBAAiB,EAAE,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;IAEnE,IAAA,YAAK,EAAoB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE;QAClF,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,CAAC,yCAAmB,CAAC,CAAC;IAErC,OAAO,QAAQ,CAAC;AAClB,CAAC;AA7BD,wCA6BC","sourcesContent":["import {toMap, Type} from \"@tsed/core\";\nimport {InjectorService, ProviderOpts, setLoggerConfiguration} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {PlatformConfiguration} from \"../config/services/PlatformConfiguration\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformAdapter} from \"../services/PlatformAdapter\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {PlatformHandler} from \"../services/PlatformHandler\";\nimport {PlatformRequest} from \"../services/PlatformRequest\";\nimport {PlatformResponse} from \"../services/PlatformResponse\";\n\n$log.name = \"TSED\";\n\nconst DEFAULT_PROVIDERS = [\n {provide: PlatformHandler},\n {provide: PlatformResponse},\n {provide: PlatformRequest},\n {provide: PlatformApplication},\n {provide: Platform}\n];\n\ninterface CreateInjectorOptions {\n adapter?: Type<PlatformAdapter<any>>;\n settings?: Partial<TsED.Configuration>;\n}\n\nexport function createInjector({adapter, settings = {}}: CreateInjectorOptions) {\n const injector = new InjectorService();\n injector.addProvider(PlatformConfiguration);\n\n injector.settings = injector.invoke(PlatformConfiguration);\n injector.logger = $log;\n injector.settings.set(settings);\n\n if (adapter) {\n injector.addProvider(PlatformAdapter, {\n useClass: adapter\n });\n }\n\n injector.invoke(PlatformAdapter);\n\n setLoggerConfiguration(injector);\n\n const instance = injector.get<PlatformAdapter>(PlatformAdapter)!;\n\n instance.providers = [...DEFAULT_PROVIDERS, ...instance.providers];\n\n toMap<any, ProviderOpts>(instance.providers, \"provide\").forEach((provider, token) => {\n injector.addProvider(token, provider);\n });\n\n injector.invoke(PlatformApplication);\n\n return injector;\n}\n"]}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureContext = void 0;
4
+ const di_1 = require("@tsed/di");
5
+ function ensureContext(request, cb, fallback) {
6
+ const $ctx = (0, di_1.getContext)();
7
+ if ($ctx) {
8
+ return cb($ctx);
9
+ }
10
+ if (!request?.$ctx && fallback) {
11
+ return fallback();
12
+ }
13
+ return request.$ctx.runInContext(() => cb(request.$ctx));
14
+ }
15
+ exports.ensureContext = ensureContext;
16
+ //# sourceMappingURL=ensureContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensureContext.js","sourceRoot":"","sources":["../../../src/utils/ensureContext.ts"],"names":[],"mappings":";;;AAAA,iCAAoC;AAGpC,SAAgB,aAAa,CAAC,OAAY,EAAE,EAAkC,EAAE,QAAqB;IACnG,MAAM,IAAI,GAAG,IAAA,eAAU,GAAmB,CAAC;IAE3C,IAAI,IAAI,EAAE;QACR,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;KACjB;IAED,IAAI,CAAC,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE;QAC9B,OAAO,QAAQ,EAAE,CAAC;KACnB;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAC3D,CAAC;AAZD,sCAYC","sourcesContent":["import {getContext} from \"@tsed/di\";\nimport {PlatformContext} from \"../domain/PlatformContext\";\n\nexport function ensureContext(request: any, cb: ($ctx: PlatformContext) => any, fallback?: () => void) {\n const $ctx = getContext<PlatformContext>();\n\n if ($ctx) {\n return cb($ctx);\n }\n\n if (!request?.$ctx && fallback) {\n return fallback();\n }\n\n return request.$ctx.runInContext(() => cb(request.$ctx));\n}\n"]}