@tsed/common 7.0.0-alpha.2 → 7.0.0-beta.11

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 (414) hide show
  1. package/lib/cjs/builder/PlatformBuilder.js +281 -0
  2. package/lib/cjs/builder/PlatformBuilder.js.map +1 -0
  3. package/lib/cjs/builder/PlatformControllerBuilder.js +82 -0
  4. package/lib/cjs/builder/PlatformControllerBuilder.js.map +1 -0
  5. package/lib/cjs/config/interfaces/ConverterSettings.js +3 -0
  6. package/lib/cjs/config/interfaces/ConverterSettings.js.map +1 -0
  7. package/lib/cjs/config/interfaces/PlatformLoggerSettings.js +3 -0
  8. package/lib/cjs/config/interfaces/PlatformLoggerSettings.js.map +1 -0
  9. package/lib/cjs/config/interfaces/PlatformMulterSettings.js +3 -0
  10. package/lib/cjs/config/interfaces/PlatformMulterSettings.js.map +1 -0
  11. package/lib/cjs/config/interfaces/PlatformStaticsSettings.js +3 -0
  12. package/lib/cjs/config/interfaces/PlatformStaticsSettings.js.map +1 -0
  13. package/lib/cjs/config/services/PlatformConfiguration.js +187 -0
  14. package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -0
  15. package/lib/cjs/constants/routerOptions.js +5 -0
  16. package/lib/cjs/constants/routerOptions.js.map +1 -0
  17. package/lib/cjs/decorators/multer/multerFileSize.js +35 -0
  18. package/lib/cjs/decorators/multer/multerFileSize.js.map +1 -0
  19. package/lib/cjs/decorators/multer/multerOptions.js +52 -0
  20. package/lib/cjs/decorators/multer/multerOptions.js.map +1 -0
  21. package/lib/cjs/decorators/multer/multipartFile.js +78 -0
  22. package/lib/cjs/decorators/multer/multipartFile.js.map +1 -0
  23. package/lib/cjs/decorators/params/error.js +20 -0
  24. package/lib/cjs/decorators/params/error.js.map +1 -0
  25. package/lib/cjs/decorators/params/next.js +21 -0
  26. package/lib/cjs/decorators/params/next.js.map +1 -0
  27. package/lib/cjs/decorators/params/request.js +39 -0
  28. package/lib/cjs/decorators/params/request.js.map +1 -0
  29. package/lib/cjs/decorators/params/response.js +33 -0
  30. package/lib/cjs/decorators/params/response.js.map +1 -0
  31. package/lib/cjs/domain/AnyToPromiseWithCtx.js +27 -0
  32. package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -0
  33. package/lib/cjs/domain/ControllerProvider.js +51 -0
  34. package/lib/cjs/domain/ControllerProvider.js.map +1 -0
  35. package/lib/cjs/domain/EndpointMetadata.js +6 -0
  36. package/lib/cjs/domain/EndpointMetadata.js.map +1 -0
  37. package/lib/cjs/domain/HandlerMetadata.js +57 -0
  38. package/lib/cjs/domain/HandlerMetadata.js.map +1 -0
  39. package/lib/cjs/domain/PlatformContext.js +92 -0
  40. package/lib/cjs/domain/PlatformContext.js.map +1 -0
  41. package/lib/cjs/domain/PlatformRouteDetails.js +24 -0
  42. package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -0
  43. package/lib/cjs/exports.js +31 -0
  44. package/lib/cjs/exports.js.map +1 -0
  45. package/lib/cjs/index.js +68 -0
  46. package/lib/cjs/index.js.map +1 -0
  47. package/lib/cjs/interfaces/AfterInit.js +3 -0
  48. package/lib/cjs/interfaces/AfterInit.js.map +1 -0
  49. package/lib/cjs/interfaces/AfterListen.js +3 -0
  50. package/lib/cjs/interfaces/AfterListen.js.map +1 -0
  51. package/lib/cjs/interfaces/AfterRoutesInit.js +3 -0
  52. package/lib/cjs/interfaces/AfterRoutesInit.js.map +1 -0
  53. package/lib/cjs/interfaces/BeforeInit.js +3 -0
  54. package/lib/cjs/interfaces/BeforeInit.js.map +1 -0
  55. package/lib/cjs/interfaces/BeforeListen.js +3 -0
  56. package/lib/cjs/interfaces/BeforeListen.js.map +1 -0
  57. package/lib/cjs/interfaces/BeforeRoutesInit.js +3 -0
  58. package/lib/cjs/interfaces/BeforeRoutesInit.js.map +1 -0
  59. package/lib/cjs/interfaces/HandlerType.js +17 -0
  60. package/lib/cjs/interfaces/HandlerType.js.map +1 -0
  61. package/lib/cjs/interfaces/IncomingEvent.js +3 -0
  62. package/lib/cjs/interfaces/IncomingEvent.js.map +1 -0
  63. package/lib/cjs/interfaces/OnReady.js +3 -0
  64. package/lib/cjs/interfaces/OnReady.js.map +1 -0
  65. package/lib/cjs/interfaces/OnRequest.js +3 -0
  66. package/lib/cjs/interfaces/OnRequest.js.map +1 -0
  67. package/lib/cjs/interfaces/OnResponse.js +3 -0
  68. package/lib/cjs/interfaces/OnResponse.js.map +1 -0
  69. package/lib/cjs/interfaces/OnRoutesInit.js +3 -0
  70. package/lib/cjs/interfaces/OnRoutesInit.js.map +1 -0
  71. package/lib/cjs/interfaces/PlatformRouteOptions.js +3 -0
  72. package/lib/cjs/interfaces/PlatformRouteOptions.js.map +1 -0
  73. package/lib/cjs/interfaces/ResponseErrorObject.js +3 -0
  74. package/lib/cjs/interfaces/ResponseErrorObject.js.map +1 -0
  75. package/lib/cjs/interfaces/Route.js +3 -0
  76. package/lib/cjs/interfaces/Route.js.map +1 -0
  77. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js +37 -0
  78. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
  79. package/lib/cjs/middlewares/PlatformMulterMiddleware.js +67 -0
  80. package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -0
  81. package/lib/cjs/middlewares/__mock__/FakeCtrl.js +12 -0
  82. package/lib/cjs/middlewares/__mock__/FakeCtrl.js.map +1 -0
  83. package/lib/cjs/middlewares/bindEndpointMiddleware.js +13 -0
  84. package/lib/cjs/middlewares/bindEndpointMiddleware.js.map +1 -0
  85. package/lib/cjs/package.json +3 -0
  86. package/lib/cjs/services/FakeAdapter.js +55 -0
  87. package/lib/cjs/services/FakeAdapter.js.map +1 -0
  88. package/lib/cjs/services/Platform.js +128 -0
  89. package/lib/cjs/services/Platform.js.map +1 -0
  90. package/lib/cjs/services/PlatformAdapter.js +14 -0
  91. package/lib/cjs/services/PlatformAdapter.js.map +1 -0
  92. package/lib/cjs/services/PlatformApplication.js +32 -0
  93. package/lib/cjs/services/PlatformApplication.js.map +1 -0
  94. package/lib/cjs/services/PlatformHandler.js +235 -0
  95. package/lib/cjs/services/PlatformHandler.js.map +1 -0
  96. package/lib/cjs/services/PlatformMiddlewaresChain.js +75 -0
  97. package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -0
  98. package/lib/cjs/services/PlatformRequest.js +138 -0
  99. package/lib/cjs/services/PlatformRequest.js.map +1 -0
  100. package/lib/cjs/services/PlatformResponse.js +271 -0
  101. package/lib/cjs/services/PlatformResponse.js.map +1 -0
  102. package/lib/cjs/services/PlatformRouter.js +108 -0
  103. package/lib/cjs/services/PlatformRouter.js.map +1 -0
  104. package/lib/cjs/services/PlatformTest.js +173 -0
  105. package/lib/cjs/services/PlatformTest.js.map +1 -0
  106. package/lib/cjs/utils/__mock__/Test1.js +8 -0
  107. package/lib/cjs/utils/__mock__/Test1.js.map +1 -0
  108. package/lib/cjs/utils/__mock__/Test2.js +8 -0
  109. package/lib/cjs/utils/__mock__/Test2.js.map +1 -0
  110. package/lib/cjs/utils/__mock__/controllers/rest/TestCtrl.js +12 -0
  111. package/lib/cjs/utils/__mock__/controllers/rest/TestCtrl.js.map +1 -0
  112. package/lib/cjs/utils/__mock__/module1/Module1.js +19 -0
  113. package/lib/cjs/utils/__mock__/module1/Module1.js.map +1 -0
  114. package/lib/cjs/utils/__mock__/module1/controllers/M1Ctrl1.js +17 -0
  115. package/lib/cjs/utils/__mock__/module1/controllers/M1Ctrl1.js.map +1 -0
  116. package/lib/cjs/utils/__mock__/module1/services/M1Service.js +17 -0
  117. package/lib/cjs/utils/__mock__/module1/services/M1Service.js.map +1 -0
  118. package/lib/cjs/utils/__mock__/module1/submodule/SubModule.js +15 -0
  119. package/lib/cjs/utils/__mock__/module1/submodule/SubModule.js.map +1 -0
  120. package/lib/cjs/utils/__mock__/module1/submodule/SubService.js +12 -0
  121. package/lib/cjs/utils/__mock__/module1/submodule/SubService.js.map +1 -0
  122. package/lib/cjs/utils/__mock__/module2/Module2.js +18 -0
  123. package/lib/cjs/utils/__mock__/module2/Module2.js.map +1 -0
  124. package/lib/cjs/utils/__mock__/module2/controllers/M2Ctrl.js +12 -0
  125. package/lib/cjs/utils/__mock__/module2/controllers/M2Ctrl.js.map +1 -0
  126. package/lib/cjs/utils/createContext.js +38 -0
  127. package/lib/cjs/utils/createContext.js.map +1 -0
  128. package/lib/cjs/utils/createHandlerMetadata.js +49 -0
  129. package/lib/cjs/utils/createHandlerMetadata.js.map +1 -0
  130. package/lib/cjs/utils/createHttpServer.js +29 -0
  131. package/lib/cjs/utils/createHttpServer.js.map +1 -0
  132. package/lib/cjs/utils/createHttpsServer.js +29 -0
  133. package/lib/cjs/utils/createHttpsServer.js.map +1 -0
  134. package/lib/cjs/utils/createInjector.js +46 -0
  135. package/lib/cjs/utils/createInjector.js.map +1 -0
  136. package/lib/cjs/utils/getConfiguration.js +46 -0
  137. package/lib/cjs/utils/getConfiguration.js.map +1 -0
  138. package/lib/cjs/utils/getStaticsOptions.js +21 -0
  139. package/lib/cjs/utils/getStaticsOptions.js.map +1 -0
  140. package/lib/cjs/utils/listenServer.js +21 -0
  141. package/lib/cjs/utils/listenServer.js.map +1 -0
  142. package/lib/cjs/utils/mapReturnedResponse.js +15 -0
  143. package/lib/cjs/utils/mapReturnedResponse.js.map +1 -0
  144. package/lib/cjs/utils/printRoutes.js +36 -0
  145. package/lib/cjs/utils/printRoutes.js.map +1 -0
  146. package/lib/cjs/utils/setResponseHeaders.js +35 -0
  147. package/lib/cjs/utils/setResponseHeaders.js.map +1 -0
  148. package/lib/cjs/utils/useCtxHandler.js +15 -0
  149. package/lib/cjs/utils/useCtxHandler.js.map +1 -0
  150. package/lib/esm/builder/PlatformBuilder.js +277 -0
  151. package/lib/esm/builder/PlatformBuilder.js.map +1 -0
  152. package/lib/esm/builder/PlatformControllerBuilder.js +76 -0
  153. package/lib/esm/builder/PlatformControllerBuilder.js.map +1 -0
  154. package/lib/esm/config/interfaces/ConverterSettings.js +2 -0
  155. package/lib/esm/config/interfaces/ConverterSettings.js.map +1 -0
  156. package/lib/esm/config/interfaces/PlatformLoggerSettings.js +2 -0
  157. package/lib/esm/config/interfaces/PlatformLoggerSettings.js.map +1 -0
  158. package/lib/esm/config/interfaces/PlatformMulterSettings.js +2 -0
  159. package/lib/esm/config/interfaces/PlatformMulterSettings.js.map +1 -0
  160. package/lib/esm/config/interfaces/PlatformStaticsSettings.js +2 -0
  161. package/lib/esm/config/interfaces/PlatformStaticsSettings.js.map +1 -0
  162. package/lib/esm/config/services/PlatformConfiguration.js +184 -0
  163. package/lib/esm/config/services/PlatformConfiguration.js.map +1 -0
  164. package/lib/esm/constants/routerOptions.js +2 -0
  165. package/lib/esm/constants/routerOptions.js.map +1 -0
  166. package/lib/esm/decorators/multer/multerFileSize.js +31 -0
  167. package/lib/esm/decorators/multer/multerFileSize.js.map +1 -0
  168. package/lib/esm/decorators/multer/multerOptions.js +48 -0
  169. package/lib/esm/decorators/multer/multerOptions.js.map +1 -0
  170. package/lib/esm/decorators/multer/multipartFile.js +74 -0
  171. package/lib/esm/decorators/multer/multipartFile.js.map +1 -0
  172. package/lib/esm/decorators/params/error.js +16 -0
  173. package/lib/esm/decorators/params/error.js.map +1 -0
  174. package/lib/esm/decorators/params/next.js +17 -0
  175. package/lib/esm/decorators/params/next.js.map +1 -0
  176. package/lib/esm/decorators/params/request.js +34 -0
  177. package/lib/esm/decorators/params/request.js.map +1 -0
  178. package/lib/esm/decorators/params/response.js +28 -0
  179. package/lib/esm/decorators/params/response.js.map +1 -0
  180. package/lib/esm/domain/AnyToPromiseWithCtx.js +23 -0
  181. package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -0
  182. package/lib/esm/domain/ControllerProvider.js +47 -0
  183. package/lib/esm/domain/ControllerProvider.js.map +1 -0
  184. package/lib/esm/domain/EndpointMetadata.js +2 -0
  185. package/lib/esm/domain/EndpointMetadata.js.map +1 -0
  186. package/lib/esm/domain/HandlerMetadata.js +53 -0
  187. package/lib/esm/domain/HandlerMetadata.js.map +1 -0
  188. package/lib/esm/domain/PlatformContext.js +88 -0
  189. package/lib/esm/domain/PlatformContext.js.map +1 -0
  190. package/lib/esm/domain/PlatformRouteDetails.js +20 -0
  191. package/lib/esm/domain/PlatformRouteDetails.js.map +1 -0
  192. package/lib/esm/exports.js +13 -0
  193. package/lib/esm/exports.js.map +1 -0
  194. package/lib/esm/index.js +65 -0
  195. package/lib/esm/index.js.map +1 -0
  196. package/lib/esm/interfaces/AfterInit.js +2 -0
  197. package/lib/esm/interfaces/AfterInit.js.map +1 -0
  198. package/lib/esm/interfaces/AfterListen.js +2 -0
  199. package/lib/esm/interfaces/AfterListen.js.map +1 -0
  200. package/lib/esm/interfaces/AfterRoutesInit.js +2 -0
  201. package/lib/esm/interfaces/AfterRoutesInit.js.map +1 -0
  202. package/lib/esm/interfaces/BeforeInit.js +2 -0
  203. package/lib/esm/interfaces/BeforeInit.js.map +1 -0
  204. package/lib/esm/interfaces/BeforeListen.js +2 -0
  205. package/lib/esm/interfaces/BeforeListen.js.map +1 -0
  206. package/lib/esm/interfaces/BeforeRoutesInit.js +2 -0
  207. package/lib/esm/interfaces/BeforeRoutesInit.js.map +1 -0
  208. package/lib/esm/interfaces/HandlerType.js +14 -0
  209. package/lib/esm/interfaces/HandlerType.js.map +1 -0
  210. package/lib/esm/interfaces/IncomingEvent.js +2 -0
  211. package/lib/esm/interfaces/IncomingEvent.js.map +1 -0
  212. package/lib/esm/interfaces/OnReady.js +2 -0
  213. package/lib/esm/interfaces/OnReady.js.map +1 -0
  214. package/lib/esm/interfaces/OnRequest.js +2 -0
  215. package/lib/esm/interfaces/OnRequest.js.map +1 -0
  216. package/lib/esm/interfaces/OnResponse.js +2 -0
  217. package/lib/esm/interfaces/OnResponse.js.map +1 -0
  218. package/lib/esm/interfaces/OnRoutesInit.js +2 -0
  219. package/lib/esm/interfaces/OnRoutesInit.js.map +1 -0
  220. package/lib/esm/interfaces/PlatformRouteOptions.js +2 -0
  221. package/lib/esm/interfaces/PlatformRouteOptions.js.map +1 -0
  222. package/lib/esm/interfaces/ResponseErrorObject.js +2 -0
  223. package/lib/esm/interfaces/ResponseErrorObject.js.map +1 -0
  224. package/lib/esm/interfaces/Route.js +2 -0
  225. package/lib/esm/interfaces/Route.js.map +1 -0
  226. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js +34 -0
  227. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
  228. package/lib/esm/middlewares/PlatformMulterMiddleware.js +63 -0
  229. package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -0
  230. package/lib/esm/middlewares/__mock__/FakeCtrl.js +9 -0
  231. package/lib/esm/middlewares/__mock__/FakeCtrl.js.map +1 -0
  232. package/lib/esm/middlewares/bindEndpointMiddleware.js +9 -0
  233. package/lib/esm/middlewares/bindEndpointMiddleware.js.map +1 -0
  234. package/lib/esm/package.json +3 -0
  235. package/lib/esm/services/FakeAdapter.js +51 -0
  236. package/lib/esm/services/FakeAdapter.js.map +1 -0
  237. package/lib/esm/services/Platform.js +125 -0
  238. package/lib/esm/services/Platform.js.map +1 -0
  239. package/lib/esm/services/PlatformAdapter.js +10 -0
  240. package/lib/esm/services/PlatformAdapter.js.map +1 -0
  241. package/lib/esm/services/PlatformApplication.js +29 -0
  242. package/lib/esm/services/PlatformApplication.js.map +1 -0
  243. package/lib/esm/services/PlatformHandler.js +232 -0
  244. package/lib/esm/services/PlatformHandler.js.map +1 -0
  245. package/lib/esm/services/PlatformMiddlewaresChain.js +72 -0
  246. package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -0
  247. package/lib/esm/services/PlatformRequest.js +135 -0
  248. package/lib/esm/services/PlatformRequest.js.map +1 -0
  249. package/lib/esm/services/PlatformResponse.js +268 -0
  250. package/lib/esm/services/PlatformResponse.js.map +1 -0
  251. package/lib/esm/services/PlatformRouter.js +105 -0
  252. package/lib/esm/services/PlatformRouter.js.map +1 -0
  253. package/lib/esm/services/PlatformTest.js +168 -0
  254. package/lib/esm/services/PlatformTest.js.map +1 -0
  255. package/lib/esm/utils/__mock__/Test1.js +4 -0
  256. package/lib/esm/utils/__mock__/Test1.js.map +1 -0
  257. package/lib/esm/utils/__mock__/Test2.js +4 -0
  258. package/lib/esm/utils/__mock__/Test2.js.map +1 -0
  259. package/lib/esm/utils/__mock__/controllers/rest/TestCtrl.js +9 -0
  260. package/lib/esm/utils/__mock__/controllers/rest/TestCtrl.js.map +1 -0
  261. package/lib/esm/utils/__mock__/module1/Module1.js +16 -0
  262. package/lib/esm/utils/__mock__/module1/Module1.js.map +1 -0
  263. package/lib/esm/utils/__mock__/module1/controllers/M1Ctrl1.js +14 -0
  264. package/lib/esm/utils/__mock__/module1/controllers/M1Ctrl1.js.map +1 -0
  265. package/lib/esm/utils/__mock__/module1/services/M1Service.js +14 -0
  266. package/lib/esm/utils/__mock__/module1/services/M1Service.js.map +1 -0
  267. package/lib/esm/utils/__mock__/module1/submodule/SubModule.js +12 -0
  268. package/lib/esm/utils/__mock__/module1/submodule/SubModule.js.map +1 -0
  269. package/lib/esm/utils/__mock__/module1/submodule/SubService.js +9 -0
  270. package/lib/esm/utils/__mock__/module1/submodule/SubService.js.map +1 -0
  271. package/lib/esm/utils/__mock__/module2/Module2.js +15 -0
  272. package/lib/esm/utils/__mock__/module2/Module2.js.map +1 -0
  273. package/lib/esm/utils/__mock__/module2/controllers/M2Ctrl.js +9 -0
  274. package/lib/esm/utils/__mock__/module2/controllers/M2Ctrl.js.map +1 -0
  275. package/lib/esm/utils/createContext.js +34 -0
  276. package/lib/esm/utils/createContext.js.map +1 -0
  277. package/lib/esm/utils/createHandlerMetadata.js +45 -0
  278. package/lib/esm/utils/createHandlerMetadata.js.map +1 -0
  279. package/lib/esm/utils/createHttpServer.js +24 -0
  280. package/lib/esm/utils/createHttpServer.js.map +1 -0
  281. package/lib/esm/utils/createHttpsServer.js +24 -0
  282. package/lib/esm/utils/createHttpsServer.js.map +1 -0
  283. package/lib/esm/utils/createInjector.js +42 -0
  284. package/lib/esm/utils/createInjector.js.map +1 -0
  285. package/lib/esm/utils/getConfiguration.js +42 -0
  286. package/lib/esm/utils/getConfiguration.js.map +1 -0
  287. package/lib/esm/utils/getStaticsOptions.js +17 -0
  288. package/lib/esm/utils/getStaticsOptions.js.map +1 -0
  289. package/lib/esm/utils/listenServer.js +17 -0
  290. package/lib/esm/utils/listenServer.js.map +1 -0
  291. package/lib/esm/utils/mapReturnedResponse.js +11 -0
  292. package/lib/esm/utils/mapReturnedResponse.js.map +1 -0
  293. package/lib/esm/utils/printRoutes.js +32 -0
  294. package/lib/esm/utils/printRoutes.js.map +1 -0
  295. package/lib/esm/utils/setResponseHeaders.js +31 -0
  296. package/lib/esm/utils/setResponseHeaders.js.map +1 -0
  297. package/lib/esm/utils/useCtxHandler.js +11 -0
  298. package/lib/esm/utils/useCtxHandler.js.map +1 -0
  299. package/lib/{builder → types/builder}/PlatformBuilder.d.ts +30 -34
  300. package/lib/types/builder/PlatformControllerBuilder.d.ts +18 -0
  301. package/lib/{config → types/config}/interfaces/ConverterSettings.d.ts +0 -0
  302. package/lib/{config → types/config}/interfaces/PlatformLoggerSettings.d.ts +0 -0
  303. package/lib/types/config/interfaces/PlatformMulterSettings.d.ts +14 -0
  304. package/lib/{config → types/config}/interfaces/PlatformStaticsSettings.d.ts +1 -0
  305. package/lib/{config → types/config}/services/PlatformConfiguration.d.ts +24 -17
  306. package/lib/{constants → types/constants}/routerOptions.d.ts +0 -0
  307. package/lib/{decorators → types/decorators}/multer/multerFileSize.d.ts +0 -0
  308. package/lib/{decorators → types/decorators}/multer/multerOptions.d.ts +0 -0
  309. package/lib/{decorators → types/decorators}/multer/multipartFile.d.ts +0 -0
  310. package/lib/{decorators → types/decorators}/params/error.d.ts +0 -0
  311. package/lib/{decorators → types/decorators}/params/next.d.ts +0 -0
  312. package/lib/{decorators → types/decorators}/params/request.d.ts +0 -0
  313. package/lib/{decorators → types/decorators}/params/response.d.ts +0 -0
  314. package/lib/{domain → types/domain}/AnyToPromiseWithCtx.d.ts +0 -0
  315. package/lib/types/domain/ControllerProvider.d.ts +24 -0
  316. package/lib/types/domain/EndpointMetadata.d.ts +1 -0
  317. package/lib/{domain → types/domain}/HandlerMetadata.d.ts +2 -2
  318. package/lib/{domain → types/domain}/PlatformContext.d.ts +1 -1
  319. package/lib/types/domain/PlatformRouteDetails.d.ts +22 -0
  320. package/lib/types/exports.d.ts +12 -0
  321. package/lib/types/index.d.ts +64 -0
  322. package/lib/{interfaces → types/interfaces}/AfterInit.d.ts +0 -0
  323. package/lib/{interfaces → types/interfaces}/AfterListen.d.ts +0 -0
  324. package/lib/{interfaces → types/interfaces}/AfterRoutesInit.d.ts +0 -0
  325. package/lib/{interfaces → types/interfaces}/BeforeInit.d.ts +0 -0
  326. package/lib/{interfaces → types/interfaces}/BeforeListen.d.ts +0 -0
  327. package/lib/{interfaces → types/interfaces}/BeforeRoutesInit.d.ts +0 -0
  328. package/lib/{interfaces → types/interfaces}/HandlerType.d.ts +0 -0
  329. package/lib/{interfaces → types/interfaces}/IncomingEvent.d.ts +0 -0
  330. package/lib/{interfaces → types/interfaces}/OnReady.d.ts +0 -0
  331. package/lib/{interfaces → types/interfaces}/OnRequest.d.ts +0 -0
  332. package/lib/{interfaces → types/interfaces}/OnResponse.d.ts +0 -0
  333. package/lib/{interfaces → types/interfaces}/OnRoutesInit.d.ts +0 -0
  334. package/lib/{interfaces → types/interfaces}/PlatformRouteOptions.d.ts +5 -3
  335. package/lib/{interfaces → types/interfaces}/ResponseErrorObject.d.ts +0 -0
  336. package/lib/{interfaces → types/interfaces}/Route.d.ts +0 -0
  337. package/lib/{middlewares → types/middlewares}/PlatformAcceptMimesMiddleware.d.ts +0 -0
  338. package/lib/{middlewares → types/middlewares}/PlatformMulterMiddleware.d.ts +8 -3
  339. package/lib/{middlewares/data → types/middlewares/__mock__}/FakeCtrl.d.ts +0 -0
  340. package/lib/types/middlewares/bindEndpointMiddleware.d.ts +6 -0
  341. package/lib/types/services/FakeAdapter.d.ts +30 -0
  342. package/lib/{services → types/services}/Platform.d.ts +22 -7
  343. package/lib/types/services/PlatformAdapter.d.ts +47 -0
  344. package/lib/{services → types/services}/PlatformApplication.d.ts +3 -3
  345. package/lib/{services → types/services}/PlatformHandler.d.ts +1 -1
  346. package/lib/types/services/PlatformMiddlewaresChain.d.ts +10 -0
  347. package/lib/{services → types/services}/PlatformRequest.d.ts +2 -1
  348. package/lib/{services → types/services}/PlatformResponse.d.ts +10 -10
  349. package/lib/{services → types/services}/PlatformRouter.d.ts +12 -8
  350. package/lib/{services → types/services}/PlatformTest.d.ts +6 -5
  351. package/lib/types/utils/__mock__/Test1.d.ts +3 -0
  352. package/lib/types/utils/__mock__/Test2.d.ts +3 -0
  353. package/lib/types/utils/__mock__/controllers/rest/TestCtrl.d.ts +2 -0
  354. package/lib/types/utils/__mock__/module1/Module1.d.ts +2 -0
  355. package/lib/types/utils/__mock__/module1/controllers/M1Ctrl1.d.ts +5 -0
  356. package/lib/types/utils/__mock__/module1/services/M1Service.d.ts +5 -0
  357. package/lib/types/utils/__mock__/module1/submodule/SubModule.d.ts +2 -0
  358. package/lib/types/utils/__mock__/module1/submodule/SubService.d.ts +2 -0
  359. package/lib/types/utils/__mock__/module2/Module2.d.ts +2 -0
  360. package/lib/types/utils/__mock__/module2/controllers/M2Ctrl.d.ts +2 -0
  361. package/lib/{utils → types/utils}/createContext.d.ts +0 -0
  362. package/lib/{utils → types/utils}/createHandlerMetadata.d.ts +1 -1
  363. package/lib/types/utils/createHttpServer.d.ts +4 -0
  364. package/lib/types/utils/createHttpsServer.d.ts +5 -0
  365. package/lib/types/utils/createInjector.d.ts +9 -0
  366. package/lib/types/utils/getConfiguration.d.ts +2 -0
  367. package/lib/types/utils/getStaticsOptions.d.ts +5 -0
  368. package/lib/types/utils/listenServer.d.ts +7 -0
  369. package/lib/{utils → types/utils}/mapReturnedResponse.d.ts +0 -0
  370. package/lib/{utils → types/utils}/printRoutes.d.ts +0 -0
  371. package/lib/{utils → types/utils}/setResponseHeaders.d.ts +0 -0
  372. package/lib/{utils → types/utils}/useCtxHandler.d.ts +0 -0
  373. package/package.json +47 -34
  374. package/readme.md +50 -57
  375. package/tsconfig.compile.esm.json +13 -0
  376. package/lib/PlatformModule.d.ts +0 -15
  377. package/lib/builder/PlatformControllerBuilder.d.ts +0 -19
  378. package/lib/config/index.d.ts +0 -3
  379. package/lib/config/interfaces/EndpointDirectoriesSettings.d.ts +0 -3
  380. package/lib/config/interfaces/PlatformMulterSettings.d.ts +0 -138
  381. package/lib/config/interfaces/index.d.ts +0 -84
  382. package/lib/decorators/httpServer.d.ts +0 -27
  383. package/lib/decorators/httpsServer.d.ts +0 -27
  384. package/lib/decorators/index.d.ts +0 -13
  385. package/lib/decorators/method/acceptMime.d.ts +0 -19
  386. package/lib/decorators/method/endpointFn.d.ts +0 -8
  387. package/lib/decorators/method/location.d.ts +0 -1
  388. package/lib/decorators/method/redirect.d.ts +0 -1
  389. package/lib/decorators/method/route.d.ts +0 -1
  390. package/lib/decorators/multer/index.d.ts +0 -3
  391. package/lib/domain/ControllerProvider.d.ts +0 -53
  392. package/lib/domain/EndpointMetadata.d.ts +0 -88
  393. package/lib/domain/PlatformRouteDetails.d.ts +0 -29
  394. package/lib/domain/index.d.ts +0 -6
  395. package/lib/index.d.ts +0 -22
  396. package/lib/index.js +0 -3651
  397. package/lib/index.js.map +0 -1
  398. package/lib/index.modern.js +0 -3464
  399. package/lib/index.modern.js.map +0 -1
  400. package/lib/interfaces/PathType.d.ts +0 -1
  401. package/lib/interfaces/PlatformRouterMethods.d.ts +0 -10
  402. package/lib/interfaces/index.d.ts +0 -17
  403. package/lib/middlewares/bindEndpointMiddleware.d.ts +0 -5
  404. package/lib/middlewares/index.d.ts +0 -3
  405. package/lib/registries/ControllerRegistry.d.ts +0 -1
  406. package/lib/services/FakeRawDriver.d.ts +0 -15
  407. package/lib/services/index.d.ts +0 -7
  408. package/lib/utils/createHttpServer.d.ts +0 -3
  409. package/lib/utils/createHttpsServer.d.ts +0 -3
  410. package/lib/utils/createInjector.d.ts +0 -2
  411. package/lib/utils/createPlatformApplication.d.ts +0 -2
  412. package/lib/utils/getControllerPath.d.ts +0 -2
  413. package/lib/utils/index.d.ts +0 -8
  414. package/lib/utils/listenServer.d.ts +0 -10
@@ -0,0 +1,9 @@
1
+ import { __decorate } from "tslib";
2
+ import { Controller } from "@tsed/di";
3
+ let FakeCtrl = class FakeCtrl {
4
+ };
5
+ FakeCtrl = __decorate([
6
+ Controller("/")
7
+ ], FakeCtrl);
8
+ export { FakeCtrl };
9
+ //# sourceMappingURL=FakeCtrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FakeCtrl.js","sourceRoot":"","sources":["../../../../src/middlewares/__mock__/FakeCtrl.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC,IAAa,QAAQ,GAArB,MAAa,QAAQ;CAAG,CAAA;AAAX,QAAQ;IADpB,UAAU,CAAC,GAAG,CAAC;GACH,QAAQ,CAAG;SAAX,QAAQ","sourcesContent":["import {Controller} from \"@tsed/di\";\n\n@Controller(\"/\")\nexport class FakeCtrl {}\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @ignore
3
+ */
4
+ export function bindEndpointMiddleware(endpoint) {
5
+ return (ctx) => {
6
+ ctx.endpoint = endpoint;
7
+ };
8
+ }
9
+ //# sourceMappingURL=bindEndpointMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindEndpointMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/bindEndpointMiddleware.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAA0B;IAC/D,OAAO,CAAC,GAAoB,EAAE,EAAE;QAC9B,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type {EndpointMetadata} from \"../domain/EndpointMetadata\";\nimport type {PlatformContext} from \"../domain/PlatformContext\";\n\n/**\n * @ignore\n */\nexport function bindEndpointMiddleware(endpoint: EndpointMetadata) {\n return (ctx: PlatformContext) => {\n ctx.endpoint = endpoint;\n };\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,51 @@
1
+ export class FakeAdapter {
2
+ constructor() {
3
+ this.providers = [];
4
+ }
5
+ static createFakeRawDriver() {
6
+ // istanbul ignore next
7
+ function FakeRawDriver() { }
8
+ // istanbul ignore next
9
+ function use() {
10
+ return this;
11
+ }
12
+ FakeRawDriver.use = use;
13
+ FakeRawDriver.all = use;
14
+ FakeRawDriver.get = use;
15
+ FakeRawDriver.patch = use;
16
+ FakeRawDriver.post = use;
17
+ FakeRawDriver.put = use;
18
+ FakeRawDriver.head = use;
19
+ FakeRawDriver.delete = use;
20
+ FakeRawDriver.options = use;
21
+ return FakeRawDriver;
22
+ }
23
+ app() {
24
+ const app = FakeAdapter.createFakeRawDriver();
25
+ return {
26
+ app,
27
+ callback() {
28
+ return app;
29
+ }
30
+ };
31
+ }
32
+ multipart(options) {
33
+ return {};
34
+ }
35
+ router(routerOptions) {
36
+ const router = FakeAdapter.createFakeRawDriver();
37
+ return {
38
+ router,
39
+ callback() {
40
+ return router;
41
+ }
42
+ };
43
+ }
44
+ statics(endpoint, options) {
45
+ return {};
46
+ }
47
+ bodyParser(type) {
48
+ return () => { };
49
+ }
50
+ }
51
+ //# sourceMappingURL=FakeAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FakeAdapter.js","sourceRoot":"","sources":["../../../src/services/FakeAdapter.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,WAAW;IAAxB;QACE,cAAS,GAAmB,EAAE,CAAC;IAuDjC,CAAC;IArDC,MAAM,CAAC,mBAAmB;QACxB,uBAAuB;QACvB,SAAS,aAAa,KAAI,CAAC;QAE3B,uBAAuB;QACvB,SAAS,GAAG;YACV,OAAO,IAAI,CAAC;QACd,CAAC;QAED,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,KAAK,GAAG,GAAG,CAAC;QAC1B,aAAa,CAAC,IAAI,GAAG,GAAG,CAAC;QACzB,aAAa,CAAC,GAAG,GAAG,GAAG,CAAC;QACxB,aAAa,CAAC,IAAI,GAAG,GAAG,CAAC;QACzB,aAAa,CAAC,MAAM,GAAG,GAAG,CAAC;QAC3B,aAAa,CAAC,OAAO,GAAG,GAAG,CAAC;QAE5B,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,GAAG;QACD,MAAM,GAAG,GAAG,WAAW,CAAC,mBAAmB,EAAE,CAAC;QAC9C,OAAO;YACL,GAAG;YACH,QAAQ;gBACN,OAAO,GAAG,CAAC;YACb,CAAC;SACF,CAAC;IACJ,CAAC;IAED,SAAS,CAAC,OAA+B;QACvC,OAAO,EAAS,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,aAAkB;QACvB,MAAM,MAAM,GAAG,WAAW,CAAC,mBAAmB,EAAE,CAAC;QACjD,OAAO;YACL,MAAM;YACN,QAAQ;gBACN,OAAO,MAAM,CAAC;YAChB,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,QAAgB,EAAE,OAA+B;QACvD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,UAAU,CAAC,IAAY;QACrB,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IAClB,CAAC;CACF","sourcesContent":["import {ProviderOpts} from \"@tsed/di\";\nimport {PlatformAdapter} from \"./PlatformAdapter\";\nimport {PlatformMulter, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformStaticsOptions} from \"../config/interfaces/PlatformStaticsSettings\";\n\nexport class FakeAdapter implements PlatformAdapter<any, any> {\n providers: ProviderOpts[] = [];\n\n static createFakeRawDriver() {\n // istanbul ignore next\n function FakeRawDriver() {}\n\n // istanbul ignore next\n function use() {\n return this;\n }\n\n FakeRawDriver.use = use;\n FakeRawDriver.all = use;\n FakeRawDriver.get = use;\n FakeRawDriver.patch = use;\n FakeRawDriver.post = use;\n FakeRawDriver.put = use;\n FakeRawDriver.head = use;\n FakeRawDriver.delete = use;\n FakeRawDriver.options = use;\n\n return FakeRawDriver;\n }\n\n app(): {app: any; callback(): any} {\n const app = FakeAdapter.createFakeRawDriver();\n return {\n app,\n callback() {\n return app;\n }\n };\n }\n\n multipart(options: PlatformMulterSettings): PlatformMulter {\n return {} as any;\n }\n\n router(routerOptions: any): {router: any; callback(): any} {\n const router = FakeAdapter.createFakeRawDriver();\n return {\n router,\n callback() {\n return router;\n }\n };\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions): any {\n return {};\n }\n\n bodyParser(type: string): any {\n return () => {};\n }\n}\n"]}
@@ -0,0 +1,125 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Injectable, InjectorService, ProviderScope, ProviderType } from "@tsed/di";
3
+ import { concatPath, getJsonEntityStore, getOperationsRoutes, JsonEntityStore } from "@tsed/schema";
4
+ import { buildRouter, createRouter, getRouter } from "../builder/PlatformControllerBuilder.js";
5
+ import { PlatformRouteDetails } from "../domain/PlatformRouteDetails.js";
6
+ import { PlatformApplication } from "./PlatformApplication.js";
7
+ import { PlatformMiddlewaresChain } from "./PlatformMiddlewaresChain.js";
8
+ /**
9
+ * `Platform` is used to provide all routes collected by annotation `@Controller`.
10
+ *
11
+ * @platform
12
+ */
13
+ let Platform = class Platform {
14
+ constructor(injector, platformApplication) {
15
+ this.injector = injector;
16
+ this.platformApplication = platformApplication;
17
+ this._routes = [];
18
+ this._controllers = [];
19
+ this.createRouters();
20
+ }
21
+ get app() {
22
+ return this.platformApplication;
23
+ }
24
+ get routes() {
25
+ return this._routes;
26
+ }
27
+ addRoutes(routes) {
28
+ routes.forEach((routeSettings) => {
29
+ this.addRoute(routeSettings.route, routeSettings.token);
30
+ });
31
+ }
32
+ addRoute(basePath, token) {
33
+ const { injector } = this;
34
+ const provider = injector.getProvider(token);
35
+ if (!provider || provider.hasParent()) {
36
+ return;
37
+ }
38
+ this._controllers.push(...this.getAllControllers(basePath, token));
39
+ const ctrlPath = concatPath(basePath, JsonEntityStore.from(provider.token).path);
40
+ this.app.use(ctrlPath, ...[].concat(getRouter(injector, provider).callback()));
41
+ this._routes = getOperationsRoutes(provider.token, {
42
+ withChildren: true,
43
+ basePath
44
+ }).reduce((routes, operationRoute) => {
45
+ if (injector.hasProvider(token)) {
46
+ const provider = injector.getProvider(operationRoute.token);
47
+ const route = new PlatformRouteDetails({
48
+ ...operationRoute,
49
+ provider
50
+ });
51
+ routes = routes.concat(route);
52
+ }
53
+ return routes;
54
+ }, this._routes);
55
+ return this;
56
+ }
57
+ /**
58
+ * Get all routes built by TsExpressDecorators and mounted on Express application.
59
+ * @returns {PlatformRouteDetails[]}
60
+ */
61
+ getRoutes() {
62
+ return this._routes;
63
+ }
64
+ /**
65
+ * Get all controllers mounted on the application.
66
+ * @returns {RouteController[]}
67
+ */
68
+ getMountedControllers() {
69
+ return this._controllers;
70
+ }
71
+ $onInit() {
72
+ this.buildControllers();
73
+ }
74
+ /**
75
+ * Create routers from the collected controllers.
76
+ * @private
77
+ */
78
+ createRouters() {
79
+ const { injector } = this;
80
+ injector.getProviders(ProviderType.CONTROLLER).map((provider) => {
81
+ createRouter(injector, provider);
82
+ });
83
+ }
84
+ /**
85
+ * Get all router controllers from the controller token.
86
+ * @private
87
+ */
88
+ getAllControllers(basePath, token) {
89
+ const store = token.isStore ? token : getJsonEntityStore(token);
90
+ const ctrlPath = concatPath(basePath, JsonEntityStore.from(token).path);
91
+ const children = store.get("childrenControllers", []);
92
+ return children
93
+ .reduce((controllers, token) => {
94
+ const childBasePath = concatPath(basePath, store.path);
95
+ return controllers.concat(this.getAllControllers(childBasePath, token));
96
+ }, [])
97
+ .concat([
98
+ {
99
+ route: ctrlPath,
100
+ provider: this.injector.getProvider(token)
101
+ }
102
+ ]);
103
+ }
104
+ /**
105
+ * Create controllers from DI
106
+ * @private
107
+ */
108
+ buildControllers() {
109
+ const { injector } = this;
110
+ injector.getProviders(ProviderType.CONTROLLER).map((provider) => {
111
+ if (!provider.hasParent()) {
112
+ return buildRouter(injector, provider);
113
+ }
114
+ });
115
+ }
116
+ };
117
+ Platform = __decorate([
118
+ Injectable({
119
+ scope: ProviderScope.SINGLETON,
120
+ imports: [PlatformMiddlewaresChain]
121
+ }),
122
+ __metadata("design:paramtypes", [InjectorService, PlatformApplication])
123
+ ], Platform);
124
+ export { Platform };
125
+ //# sourceMappingURL=Platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../../src/services/Platform.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,UAAU,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAgB,MAAM,UAAU,CAAC;AACjG,OAAO,EAAC,UAAU,EAAoB,kBAAkB,EAAE,mBAAmB,EAAE,eAAe,EAAC,MAAM,cAAc,CAAC;AACpH,OAAO,EAAC,WAAW,EAAE,YAAY,EAAE,SAAS,EAAC,MAAM,sCAAsC,CAAC;AAE1F,OAAO,EAAC,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,wBAAwB,EAAC,MAAM,4BAA4B,CAAC;AAEpE;;;;GAIG;AAKH,IAAa,QAAQ,GAArB,MAAa,QAAQ;IAInB,YAAqB,QAAyB,EAAW,mBAAwC;QAA5E,aAAQ,GAAR,QAAQ,CAAiB;QAAW,wBAAmB,GAAnB,mBAAmB,CAAqB;QAHzF,YAAO,GAA2B,EAAE,CAAC;QACrC,iBAAY,GAAsB,EAAE,CAAC;QAG3C,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;I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ChD,MAAM,aAAa,GAAG,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YACvD,OAAO,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC;QAC1E,CAAC,EAAE,EAAE,CAAC;aACL,MAAM,CAAC;YACN;gBACE,KAAK,EAAE,QAAQ;gBACf,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAuB;aACjE;SACF,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACK,gBAAgB;QACtB,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QAExB,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,QAA4B,EAAE,EAAE;YAClF,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;gBACzB,OAAO,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;aACxC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA3HY,QAAQ;IAJpB,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,CAAC,wBAAwB,CAAC;KACpC,CAAC;qCAK+B,eAAe,EAAgC,mBAAmB;GAJtF,QAAQ,CA2HpB;SA3HY,QAAQ","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {Injectable, InjectorService, ProviderScope, ProviderType, TokenProvider} from \"@tsed/di\";\nimport {concatPath, EndpointMetadata, getJsonEntityStore, getOperationsRoutes, JsonEntityStore} from \"@tsed/schema\";\nimport {buildRouter, createRouter, getRouter} from \"../builder/PlatformControllerBuilder\";\nimport {ControllerProvider} from \"../domain/ControllerProvider\";\nimport {PlatformRouteDetails} from \"../domain/PlatformRouteDetails\";\nimport {Route, RouteController} from \"../interfaces/Route\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {PlatformMiddlewaresChain} from \"./PlatformMiddlewaresChain\";\n\n/**\n * `Platform` is used to provide all routes collected by annotation `@Controller`.\n *\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: [PlatformMiddlewaresChain]\n})\nexport class Platform {\n private _routes: PlatformRouteDetails[] = [];\n private _controllers: RouteController[] = [];\n\n constructor(readonly injector: InjectorService, readonly platformApplication: PlatformApplication) {\n this.createRouters();\n }\n\n get app() {\n return this.platformApplication;\n }\n\n get routes(): PlatformRouteDetails[] {\n return this._routes;\n }\n\n public addRoutes(routes: Route[]) {\n routes.forEach((routeSettings) => {\n this.addRoute(routeSettings.route, routeSettings.token);\n });\n }\n\n public addRoute(basePath: string, token: TokenProvider) {\n const {injector} = this;\n const provider = injector.getProvider(token) as ControllerProvider;\n\n if (!provider || provider.hasParent()) {\n return;\n }\n\n this._controllers.push(...this.getAllControllers(basePath, token));\n\n const ctrlPath = concatPath(basePath, JsonEntityStore.from(provider.token).path);\n\n this.app.use(ctrlPath, ...[].concat(getRouter(injector, provider).callback()));\n\n this._routes = getOperationsRoutes<EndpointMetadata>(provider.token, {\n withChildren: true,\n basePath\n }).reduce((routes, operationRoute) => {\n if (injector.hasProvider(token)) {\n const provider = injector.getProvider(operationRoute.token) as ControllerProvider;\n const route = new PlatformRouteDetails({\n ...operationRoute,\n provider\n });\n\n routes = routes.concat(route);\n }\n\n return routes;\n }, this._routes);\n\n return this;\n }\n\n /**\n * Get all routes built by TsExpressDecorators and mounted on Express application.\n * @returns {PlatformRouteDetails[]}\n */\n public getRoutes(): PlatformRouteDetails[] {\n return this._routes;\n }\n\n /**\n * Get all controllers mounted on the application.\n * @returns {RouteController[]}\n */\n public getMountedControllers(): RouteController[] {\n return this._controllers;\n }\n\n protected $onInit() {\n this.buildControllers();\n }\n\n /**\n * Create routers from the collected controllers.\n * @private\n */\n private createRouters() {\n const {injector} = this;\n\n injector.getProviders(ProviderType.CONTROLLER).map((provider: ControllerProvider) => {\n createRouter(injector, provider);\n });\n }\n\n /**\n * Get all router controllers from the controller token.\n * @private\n */\n private getAllControllers(basePath: string, token: Type<any> | any): RouteController[] {\n const store: JsonEntityStore = token.isStore ? token : getJsonEntityStore(token);\n const ctrlPath = concatPath(basePath, JsonEntityStore.from(token).path);\n const children = store.get<Type[]>(\"childrenControllers\", []);\n\n return children\n .reduce<RouteController[]>((controllers, token) => {\n const childBasePath = concatPath(basePath, store.path);\n return controllers.concat(this.getAllControllers(childBasePath, token));\n }, [])\n .concat([\n {\n route: ctrlPath,\n provider: this.injector.getProvider(token) as ControllerProvider\n }\n ]);\n }\n\n /**\n * Create controllers from DI\n * @private\n */\n private buildControllers() {\n const {injector} = this;\n\n injector.getProviders(ProviderType.CONTROLLER).map((provider: ControllerProvider) => {\n if (!provider.hasParent()) {\n return buildRouter(injector, provider);\n }\n });\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { InjectorService, registerProvider } from "@tsed/di";
2
+ import { FakeAdapter } from "./FakeAdapter.js";
3
+ export class PlatformAdapter {
4
+ }
5
+ registerProvider({
6
+ provide: PlatformAdapter,
7
+ deps: [InjectorService],
8
+ useClass: FakeAdapter
9
+ });
10
+ //# sourceMappingURL=PlatformAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformAdapter.js","sourceRoot":"","sources":["../../../src/services/PlatformAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAgB,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAIzE,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE1C,MAAM,OAAgB,eAAe;CAoCpC;AAMD,gBAAgB,CAAC;IACf,OAAO,EAAE,eAAe;IACxB,IAAI,EAAE,CAAC,eAAe,CAAC;IACvB,QAAQ,EAAE,WAAW;CACtB,CAAC,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {InjectorService, ProviderOpts, registerProvider} from \"@tsed/di\";\nimport {PlatformMulter, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformStaticsOptions} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {RouterOptions} from \"express\";\nimport {FakeAdapter} from \"./FakeAdapter\";\n\nexport abstract class PlatformAdapter<App = TsED.Application, Router = TsED.Router> {\n /**\n * Load providers in top priority\n */\n providers: ProviderOpts[];\n /**\n * Called after the injector instantiation\n */\n onInit?: () => any;\n beforeLoadRoutes?: () => Promise<any>;\n afterLoadRoutes?: () => Promise<any>;\n useRouter?: () => any;\n useContext?: () => any;\n\n abstract app(): {app: App; callback(): any};\n\n abstract router(routerOptions?: Partial<RouterOptions>): {router: Router; callback(): any};\n /**\n * Return the statics middlewares\n * @param endpoint\n * @param options\n */\n abstract statics(endpoint: string, options: PlatformStaticsOptions): any;\n\n /**\n * Return the multipart middleware\n * @param options\n */\n abstract multipart(options: PlatformMulterSettings): PlatformMulter;\n\n /**\n * Return the body parser for the given\n * @param type\n * @param opts\n */\n abstract bodyParser(type: string, opts?: Record<string, any>): any;\n}\n\nexport interface PlatformBuilderSettings<App = TsED.Application, Router = TsED.Router> extends Partial<TsED.Configuration> {\n adapter?: Type<PlatformAdapter<App, Router>>;\n}\n\nregisterProvider({\n provide: PlatformAdapter,\n deps: [InjectorService],\n useClass: FakeAdapter\n});\n"]}
@@ -0,0 +1,29 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Injectable, ProviderScope } from "@tsed/di";
3
+ import { PlatformHandler } from "./PlatformHandler.js";
4
+ import { PlatformRouter } from "./PlatformRouter.js";
5
+ import { PlatformAdapter } from "./PlatformAdapter.js";
6
+ /**
7
+ * `PlatformApplication` is used to provide all routes collected by annotation `@Controller`.
8
+ *
9
+ * @platform
10
+ */
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;
17
+ }
18
+ getApp() {
19
+ return this.raw;
20
+ }
21
+ };
22
+ PlatformApplication = __decorate([
23
+ Injectable({
24
+ scope: ProviderScope.SINGLETON
25
+ }),
26
+ __metadata("design:paramtypes", [PlatformHandler, PlatformAdapter])
27
+ ], PlatformApplication);
28
+ export { PlatformApplication };
29
+ //# sourceMappingURL=PlatformApplication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformApplication.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAE,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"]}
@@ -0,0 +1,232 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { AnyToPromiseStatus, isFunction, isStream } from "@tsed/core";
3
+ import { Inject, Injectable, InjectorService, ProviderScope, runInContext } from "@tsed/di";
4
+ import { $log } from "@tsed/logger";
5
+ import { PlatformParams } from "@tsed/platform-params";
6
+ import { PlatformResponseFilter } from "@tsed/platform-response-filter";
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
+ /**
13
+ * Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).
14
+ * @platform
15
+ */
16
+ let PlatformHandler = class PlatformHandler {
17
+ constructor(injector, params) {
18
+ this.injector = injector;
19
+ this.params = params;
20
+ }
21
+ /**
22
+ * Create a native middleware based on the given metadata and return an instance of AnyToPromiseWithCtx
23
+ * @param input
24
+ * @param options
25
+ */
26
+ createHandler(input, options = {}) {
27
+ return this.createRawHandler(createHandlerMetadata(this.injector, input, options));
28
+ }
29
+ /**
30
+ * Create injectable handler from the given provider
31
+ * @param provider
32
+ * @param propertyKey
33
+ */
34
+ createCustomHandler(provider, propertyKey) {
35
+ const handler = this.compileHandler(new HandlerMetadata({
36
+ token: provider.provide,
37
+ target: provider.useClass,
38
+ type: HandlerType.CUSTOM,
39
+ scope: provider.scope,
40
+ propertyKey
41
+ }));
42
+ return async ($ctx, next) => handler({
43
+ $ctx,
44
+ next
45
+ });
46
+ }
47
+ /**
48
+ * Send the response to the consumer.
49
+ * @param data
50
+ * @param ctx
51
+ * @protected
52
+ */
53
+ async flush(data, ctx) {
54
+ const { response } = ctx;
55
+ if (!response.isDone()) {
56
+ data = await this.responseFilter.serialize(data, ctx);
57
+ data = await this.responseFilter.transform(data, ctx);
58
+ response.body(data);
59
+ }
60
+ }
61
+ compileHandler(metadata) {
62
+ if (metadata.type === HandlerType.CTX_FN) {
63
+ return async (scope) => {
64
+ // @ts-ignore
65
+ return this.onCtxRequest({
66
+ ...scope,
67
+ handler: () => metadata.handler(scope.$ctx),
68
+ metadata
69
+ });
70
+ };
71
+ }
72
+ const promise = this.params.compileHandler({
73
+ token: metadata.token,
74
+ propertyKey: metadata.propertyKey,
75
+ getCustomArgs: metadata.injectable ? undefined : this.getDefaultArgs(metadata)
76
+ });
77
+ return async (scope) => {
78
+ const handler = await promise;
79
+ // @ts-ignore
80
+ return this.onRequest({
81
+ ...scope,
82
+ handler,
83
+ metadata
84
+ });
85
+ };
86
+ }
87
+ async onCtxRequest(requestOptions) {
88
+ await requestOptions.handler(requestOptions);
89
+ return this.next(requestOptions);
90
+ }
91
+ /**
92
+ * Call handler when a request his handle
93
+ * @param requestOptions
94
+ */
95
+ async onRequest(requestOptions) {
96
+ const { $ctx, metadata, err, handler } = requestOptions;
97
+ // istanbul ignore next
98
+ if (!$ctx || $ctx.isDone()) {
99
+ $log.error({
100
+ name: "HEADERS_SENT",
101
+ message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${metadata.toString()}`
102
+ });
103
+ return;
104
+ }
105
+ const resolver = new AnyToPromiseWithCtx({ $ctx, err });
106
+ return runInContext($ctx, async () => {
107
+ try {
108
+ const { state, data, status, headers } = await resolver.call(handler);
109
+ if (state === AnyToPromiseStatus.RESOLVED) {
110
+ if (status) {
111
+ $ctx.response.status(status);
112
+ }
113
+ if (headers) {
114
+ $ctx.response.setHeaders(headers);
115
+ }
116
+ if (data !== undefined) {
117
+ $ctx.data = data;
118
+ }
119
+ // Can be canceled by the handler itself
120
+ return await this.onSuccess($ctx.data, requestOptions);
121
+ }
122
+ }
123
+ catch (er) {
124
+ return this.onError(er, requestOptions);
125
+ }
126
+ });
127
+ }
128
+ async onError(er, requestOptions) {
129
+ const { next, $ctx, metadata } = requestOptions;
130
+ if ($ctx) {
131
+ $ctx.data = er;
132
+ }
133
+ if (!next) {
134
+ throw er;
135
+ }
136
+ // istanbul ignore next
137
+ if (!$ctx || $ctx.isDone()) {
138
+ $log.warn({
139
+ name: "HEADERS_SENT",
140
+ message: `An error was caught after the headers were sent to the client. The error comes from the handler: ${metadata.toString()}`,
141
+ stack: er.stack,
142
+ origin: er,
143
+ request_id: $ctx === null || $ctx === void 0 ? void 0 : $ctx.id
144
+ });
145
+ return;
146
+ }
147
+ return next(er);
148
+ }
149
+ /**
150
+ * Manage success scenario
151
+ * @param data
152
+ * @param requestOptions
153
+ * @protected
154
+ */
155
+ async onSuccess(data, requestOptions) {
156
+ const { metadata, $ctx, next } = requestOptions;
157
+ // istanbul ignore next
158
+ if ($ctx === null || $ctx === void 0 ? void 0 : $ctx.isDone()) {
159
+ return;
160
+ }
161
+ // set headers each times that an endpoint is called
162
+ if (metadata.type === HandlerType.ENDPOINT) {
163
+ this.setHeaders($ctx);
164
+ }
165
+ // call returned middleware
166
+ if (isFunction(data) && !isStream(data)) {
167
+ return this.callReturnedMiddleware(data, $ctx, next);
168
+ }
169
+ if (metadata.isFinal()) {
170
+ return this.flush(data, $ctx);
171
+ }
172
+ return this.next(requestOptions);
173
+ }
174
+ /**
175
+ * Call the returned middleware by the handler.
176
+ * @param middleware
177
+ * @param ctx
178
+ * @param next
179
+ * @protected
180
+ */
181
+ callReturnedMiddleware(middleware, ctx, next) {
182
+ return middleware(ctx.getRequest(), ctx.getResponse(), next);
183
+ }
184
+ /**
185
+ * create Raw handler
186
+ * @param metadata
187
+ */
188
+ createRawHandler(metadata) {
189
+ if ([HandlerType.RAW_ERR_FN, HandlerType.RAW_FN].includes(metadata.type)) {
190
+ return metadata.handler;
191
+ }
192
+ const handler = this.compileHandler(metadata);
193
+ return async (request, response, next) => {
194
+ return handler({
195
+ next,
196
+ $ctx: request.$ctx
197
+ });
198
+ };
199
+ }
200
+ /**
201
+ * Set response headers
202
+ * @param ctx
203
+ * @protected
204
+ */
205
+ setHeaders(ctx) {
206
+ return setResponseHeaders(ctx);
207
+ }
208
+ next(requestOptions) {
209
+ const { $ctx, next } = requestOptions;
210
+ return !$ctx.response.isDone() && next && next();
211
+ }
212
+ getDefaultArgs(metadata) {
213
+ return async (scope) => [
214
+ metadata.hasErrorParam && scope.err,
215
+ scope.$ctx.request.request,
216
+ scope.$ctx.response.response,
217
+ metadata.hasNextFunction && scope.next
218
+ ].filter(Boolean);
219
+ }
220
+ };
221
+ __decorate([
222
+ Inject(),
223
+ __metadata("design:type", PlatformResponseFilter)
224
+ ], PlatformHandler.prototype, "responseFilter", void 0);
225
+ PlatformHandler = __decorate([
226
+ Injectable({
227
+ scope: ProviderScope.SINGLETON
228
+ }),
229
+ __metadata("design:paramtypes", [InjectorService, PlatformParams])
230
+ ], PlatformHandler);
231
+ export { PlatformHandler };
232
+ //# sourceMappingURL=PlatformHandler.js.map
@@ -0,0 +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,EAAE,YAAY,EAAC,MAAM,UAAU,CAAC;AACpG,OAAO,EAAC,IAA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ChD;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, runInContext} 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 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"]}
@@ -0,0 +1,72 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Constant, Inject, Injectable } from "@tsed/di";
3
+ import { ParamTypes } from "@tsed/platform-params";
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";
11
+ let PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
12
+ get(provider, operationRoute, parentMiddlewares = []) {
13
+ const { endpoint } = operationRoute;
14
+ const { beforeMiddlewares, middlewares: mldwrs, afterMiddlewares } = endpoint;
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
+ });
58
+ }
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);
68
+ PlatformMiddlewaresChain = __decorate([
69
+ Injectable()
70
+ ], PlatformMiddlewaresChain);
71
+ export { PlatformMiddlewaresChain };
72
+ //# sourceMappingURL=PlatformMiddlewaresChain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformMiddlewaresChain.js","sourceRoot":"","sources":["../../../src/services/PlatformMiddlewaresChain.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AACtD,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAC,eAAe,EAAqB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAC,sBAAsB,EAAC,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAC,6BAA6B,EAAC,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EAAC,wBAAwB,EAAC,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAC,eAAe,EAAC,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AAGnC,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;IAOnC,GAAG,CAAC,QAA4B,EAAE,cAAkC,EAAE,oBAA2B,EAAE;QACjG,MAAM,EAAC,QAAQ,EAAC,GAAG,cAAc,CAAC;QAClC,MAAM,EAAC,iBAAiB,EAAE,WAAW,EAAE,MAAM,EAAE,gBAAgB,EAAC,GAAG,QAAQ,CAAC;QAE5E,MAAM,EACJ,WAAW,EAAE,EAAC,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAC,EACxC,GAAG,QAAQ,CAAC;QAEb,MAAM,cAAc,GAAG;YACrB,GAAG,iBAAiB;YACpB,GAAG,SAAS;YACZ,GAAG,iBAAiB;YACpB,GAAG,GAAG;YACN,GAAG,MAAM;YACT,QAAQ;YACR,GAAG,gBAAgB;YACn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AAI,IAAI,IAAI,CAAC;oBAC1C,UAAU,CAAC,QAAQ,GAAG,UAAU,CAAC,QAAQ,IAAI,QAAQ,CAAC;oBACtD,UAAU,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,IAAI,IAAI,CAAC;iBAC3C;aACF;YAED,OAAO,UAAU,CAAC;QACpB,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"]}