@tsed/common 6.87.1 → 6.89.0

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 (536) hide show
  1. package/lib/{PlatformModule.d.ts → cjs/PlatformModule.d.ts} +0 -0
  2. package/lib/cjs/PlatformModule.js +11 -0
  3. package/lib/cjs/PlatformModule.js.map +1 -0
  4. package/lib/{builder → cjs/builder}/PlatformBuilder.d.ts +0 -1
  5. package/lib/cjs/builder/PlatformBuilder.js +248 -0
  6. package/lib/cjs/builder/PlatformBuilder.js.map +1 -0
  7. package/lib/{builder → cjs/builder}/PlatformControllerBuilder.d.ts +0 -0
  8. package/lib/cjs/builder/PlatformControllerBuilder.js +85 -0
  9. package/lib/cjs/builder/PlatformControllerBuilder.js.map +1 -0
  10. package/lib/{config → cjs/config}/index.d.ts +0 -0
  11. package/lib/cjs/config/index.js +7 -0
  12. package/lib/cjs/config/index.js.map +1 -0
  13. package/lib/{config → cjs/config}/interfaces/ConverterSettings.d.ts +0 -0
  14. package/lib/cjs/config/interfaces/ConverterSettings.js +3 -0
  15. package/lib/cjs/config/interfaces/ConverterSettings.js.map +1 -0
  16. package/lib/{config → cjs/config}/interfaces/EndpointDirectoriesSettings.d.ts +0 -0
  17. package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js +3 -0
  18. package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js.map +1 -0
  19. package/lib/{config → cjs/config}/interfaces/PlatformLoggerSettings.d.ts +0 -0
  20. package/lib/cjs/config/interfaces/PlatformLoggerSettings.js +3 -0
  21. package/lib/cjs/config/interfaces/PlatformLoggerSettings.js.map +1 -0
  22. package/lib/{config → cjs/config}/interfaces/PlatformMulterSettings.d.ts +0 -0
  23. package/lib/cjs/config/interfaces/PlatformMulterSettings.js +3 -0
  24. package/lib/cjs/config/interfaces/PlatformMulterSettings.js.map +1 -0
  25. package/lib/{config → cjs/config}/interfaces/PlatformStaticsSettings.d.ts +0 -0
  26. package/lib/cjs/config/interfaces/PlatformStaticsSettings.js +3 -0
  27. package/lib/cjs/config/interfaces/PlatformStaticsSettings.js.map +1 -0
  28. package/lib/{config → cjs/config}/interfaces/index.d.ts +0 -0
  29. package/lib/cjs/config/interfaces/index.js +8 -0
  30. package/lib/cjs/config/interfaces/index.js.map +1 -0
  31. package/lib/{config → cjs/config}/services/PlatformConfiguration.d.ts +0 -0
  32. package/lib/cjs/config/services/PlatformConfiguration.js +195 -0
  33. package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -0
  34. package/lib/{constants → cjs/constants}/routerOptions.d.ts +0 -0
  35. package/lib/cjs/constants/routerOptions.js +5 -0
  36. package/lib/cjs/constants/routerOptions.js.map +1 -0
  37. package/lib/{decorators → cjs/decorators}/httpServer.d.ts +0 -0
  38. package/lib/cjs/decorators/httpServer.js +31 -0
  39. package/lib/cjs/decorators/httpServer.js.map +1 -0
  40. package/lib/{decorators → cjs/decorators}/httpsServer.d.ts +0 -0
  41. package/lib/cjs/decorators/httpsServer.js +31 -0
  42. package/lib/cjs/decorators/httpsServer.js.map +1 -0
  43. package/lib/{decorators → cjs/decorators}/index.d.ts +1 -0
  44. package/lib/cjs/decorators/index.js +23 -0
  45. package/lib/cjs/decorators/index.js.map +1 -0
  46. package/lib/{decorators → cjs/decorators}/method/acceptMime.d.ts +0 -0
  47. package/lib/cjs/decorators/method/acceptMime.js +28 -0
  48. package/lib/cjs/decorators/method/acceptMime.js.map +1 -0
  49. package/lib/{decorators → cjs/decorators}/method/endpointFn.d.ts +0 -0
  50. package/lib/cjs/decorators/method/endpointFn.js +15 -0
  51. package/lib/cjs/decorators/method/endpointFn.js.map +1 -0
  52. package/lib/{decorators → cjs/decorators}/method/location.d.ts +0 -0
  53. package/lib/cjs/decorators/method/location.js +6 -0
  54. package/lib/cjs/decorators/method/location.js.map +1 -0
  55. package/lib/{decorators → cjs/decorators}/method/redirect.d.ts +0 -0
  56. package/lib/cjs/decorators/method/redirect.js +6 -0
  57. package/lib/cjs/decorators/method/redirect.js.map +1 -0
  58. package/lib/{decorators → cjs/decorators}/method/route.d.ts +0 -0
  59. package/lib/cjs/decorators/method/route.js +13 -0
  60. package/lib/cjs/decorators/method/route.js.map +1 -0
  61. package/lib/cjs/decorators/method/view.d.ts +25 -0
  62. package/lib/cjs/decorators/method/view.js +34 -0
  63. package/lib/cjs/decorators/method/view.js.map +1 -0
  64. package/lib/{decorators → cjs/decorators}/multer/index.d.ts +0 -0
  65. package/lib/cjs/decorators/multer/index.js +7 -0
  66. package/lib/cjs/decorators/multer/index.js.map +1 -0
  67. package/lib/{decorators → cjs/decorators}/multer/multerFileSize.d.ts +0 -0
  68. package/lib/cjs/decorators/multer/multerFileSize.js +35 -0
  69. package/lib/cjs/decorators/multer/multerFileSize.js.map +1 -0
  70. package/lib/{decorators → cjs/decorators}/multer/multerOptions.d.ts +0 -0
  71. package/lib/cjs/decorators/multer/multerOptions.js +52 -0
  72. package/lib/cjs/decorators/multer/multerOptions.js.map +1 -0
  73. package/lib/{decorators → cjs/decorators}/multer/multipartFile.d.ts +0 -0
  74. package/lib/cjs/decorators/multer/multipartFile.js +78 -0
  75. package/lib/cjs/decorators/multer/multipartFile.js.map +1 -0
  76. package/lib/{decorators → cjs/decorators}/params/endpointInfo.d.ts +0 -0
  77. package/lib/cjs/decorators/params/endpointInfo.js +21 -0
  78. package/lib/cjs/decorators/params/endpointInfo.js.map +1 -0
  79. package/lib/{decorators → cjs/decorators}/params/error.d.ts +0 -0
  80. package/lib/cjs/decorators/params/error.js +20 -0
  81. package/lib/cjs/decorators/params/error.js.map +1 -0
  82. package/lib/{decorators → cjs/decorators}/params/next.d.ts +0 -0
  83. package/lib/cjs/decorators/params/next.js +21 -0
  84. package/lib/cjs/decorators/params/next.js.map +1 -0
  85. package/lib/{decorators → cjs/decorators}/params/request.d.ts +0 -0
  86. package/lib/cjs/decorators/params/request.js +39 -0
  87. package/lib/cjs/decorators/params/request.js.map +1 -0
  88. package/lib/{decorators → cjs/decorators}/params/response.d.ts +0 -0
  89. package/lib/cjs/decorators/params/response.js +33 -0
  90. package/lib/cjs/decorators/params/response.js.map +1 -0
  91. package/lib/{decorators → cjs/decorators}/params/responseData.d.ts +0 -0
  92. package/lib/cjs/decorators/params/responseData.js +21 -0
  93. package/lib/cjs/decorators/params/responseData.js.map +1 -0
  94. package/lib/{domain → cjs/domain}/AnyToPromiseWithCtx.d.ts +0 -0
  95. package/lib/cjs/domain/AnyToPromiseWithCtx.js +35 -0
  96. package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -0
  97. package/lib/{domain → cjs/domain}/ControllerProvider.d.ts +0 -0
  98. package/lib/cjs/domain/ControllerProvider.js +51 -0
  99. package/lib/cjs/domain/ControllerProvider.js.map +1 -0
  100. package/lib/{domain → cjs/domain}/EndpointMetadata.d.ts +0 -0
  101. package/lib/cjs/domain/EndpointMetadata.js +111 -0
  102. package/lib/cjs/domain/EndpointMetadata.js.map +1 -0
  103. package/lib/{domain → cjs/domain}/HandlerMetadata.d.ts +0 -0
  104. package/lib/cjs/domain/HandlerMetadata.js +57 -0
  105. package/lib/cjs/domain/HandlerMetadata.js.map +1 -0
  106. package/lib/{domain → cjs/domain}/PlatformContext.d.ts +0 -0
  107. package/lib/cjs/domain/PlatformContext.js +85 -0
  108. package/lib/cjs/domain/PlatformContext.js.map +1 -0
  109. package/lib/{domain → cjs/domain}/PlatformRouteDetails.d.ts +0 -0
  110. package/lib/cjs/domain/PlatformRouteDetails.js +24 -0
  111. package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -0
  112. package/lib/{domain → cjs/domain}/PropertyMetadata.d.ts +0 -0
  113. package/lib/cjs/domain/PropertyMetadata.js +28 -0
  114. package/lib/cjs/domain/PropertyMetadata.js.map +1 -0
  115. package/lib/{domain → cjs/domain}/index.d.ts +0 -0
  116. package/lib/cjs/domain/index.js +11 -0
  117. package/lib/cjs/domain/index.js.map +1 -0
  118. package/lib/{index.d.ts → cjs/index.d.ts} +0 -1
  119. package/lib/cjs/index.js +37 -0
  120. package/lib/cjs/index.js.map +1 -0
  121. package/lib/{interfaces → cjs/interfaces}/AfterInit.d.ts +0 -0
  122. package/lib/cjs/interfaces/AfterInit.js +3 -0
  123. package/lib/cjs/interfaces/AfterInit.js.map +1 -0
  124. package/lib/{interfaces → cjs/interfaces}/AfterListen.d.ts +0 -0
  125. package/lib/cjs/interfaces/AfterListen.js +3 -0
  126. package/lib/cjs/interfaces/AfterListen.js.map +1 -0
  127. package/lib/{interfaces → cjs/interfaces}/AfterRoutesInit.d.ts +0 -0
  128. package/lib/cjs/interfaces/AfterRoutesInit.js +3 -0
  129. package/lib/cjs/interfaces/AfterRoutesInit.js.map +1 -0
  130. package/lib/{interfaces → cjs/interfaces}/BeforeInit.d.ts +0 -0
  131. package/lib/cjs/interfaces/BeforeInit.js +3 -0
  132. package/lib/cjs/interfaces/BeforeInit.js.map +1 -0
  133. package/lib/{interfaces → cjs/interfaces}/BeforeListen.d.ts +0 -0
  134. package/lib/cjs/interfaces/BeforeListen.js +3 -0
  135. package/lib/cjs/interfaces/BeforeListen.js.map +1 -0
  136. package/lib/{interfaces → cjs/interfaces}/BeforeRoutesInit.d.ts +0 -0
  137. package/lib/cjs/interfaces/BeforeRoutesInit.js +3 -0
  138. package/lib/cjs/interfaces/BeforeRoutesInit.js.map +1 -0
  139. package/lib/{interfaces → cjs/interfaces}/HandlerType.d.ts +0 -0
  140. package/lib/cjs/interfaces/HandlerType.js +17 -0
  141. package/lib/cjs/interfaces/HandlerType.js.map +1 -0
  142. package/lib/{interfaces → cjs/interfaces}/IncomingEvent.d.ts +0 -0
  143. package/lib/cjs/interfaces/IncomingEvent.js +3 -0
  144. package/lib/cjs/interfaces/IncomingEvent.js.map +1 -0
  145. package/lib/{interfaces → cjs/interfaces}/OnReady.d.ts +0 -0
  146. package/lib/cjs/interfaces/OnReady.js +3 -0
  147. package/lib/cjs/interfaces/OnReady.js.map +1 -0
  148. package/lib/{interfaces → cjs/interfaces}/OnRequest.d.ts +0 -0
  149. package/lib/cjs/interfaces/OnRequest.js +3 -0
  150. package/lib/cjs/interfaces/OnRequest.js.map +1 -0
  151. package/lib/{interfaces → cjs/interfaces}/OnResponse.d.ts +0 -0
  152. package/lib/cjs/interfaces/OnResponse.js +3 -0
  153. package/lib/cjs/interfaces/OnResponse.js.map +1 -0
  154. package/lib/{interfaces → cjs/interfaces}/OnRoutesInit.d.ts +0 -0
  155. package/lib/cjs/interfaces/OnRoutesInit.js +3 -0
  156. package/lib/cjs/interfaces/OnRoutesInit.js.map +1 -0
  157. package/lib/{interfaces → cjs/interfaces}/PathType.d.ts +0 -0
  158. package/lib/cjs/interfaces/PathType.js +3 -0
  159. package/lib/cjs/interfaces/PathType.js.map +1 -0
  160. package/lib/{interfaces → cjs/interfaces}/PlatformRouteOptions.d.ts +0 -0
  161. package/lib/cjs/interfaces/PlatformRouteOptions.js +3 -0
  162. package/lib/cjs/interfaces/PlatformRouteOptions.js.map +1 -0
  163. package/lib/{interfaces → cjs/interfaces}/ResponseErrorObject.d.ts +0 -0
  164. package/lib/cjs/interfaces/ResponseErrorObject.js +3 -0
  165. package/lib/cjs/interfaces/ResponseErrorObject.js.map +1 -0
  166. package/lib/{interfaces → cjs/interfaces}/Route.d.ts +0 -0
  167. package/lib/cjs/interfaces/Route.js +3 -0
  168. package/lib/cjs/interfaces/Route.js.map +1 -0
  169. package/lib/{interfaces → cjs/interfaces}/index.d.ts +0 -0
  170. package/lib/cjs/interfaces/index.js +20 -0
  171. package/lib/cjs/interfaces/index.js.map +1 -0
  172. package/lib/{middlewares → cjs/middlewares}/AcceptMimesMiddleware.d.ts +0 -0
  173. package/lib/cjs/middlewares/AcceptMimesMiddleware.js +27 -0
  174. package/lib/cjs/middlewares/AcceptMimesMiddleware.js.map +1 -0
  175. package/lib/{middlewares → cjs/middlewares}/GlobalAcceptMimesMiddleware.d.ts +0 -0
  176. package/lib/cjs/middlewares/GlobalAcceptMimesMiddleware.js +26 -0
  177. package/lib/cjs/middlewares/GlobalAcceptMimesMiddleware.js.map +1 -0
  178. package/lib/{middlewares → cjs/middlewares}/PlatformAcceptMimesMiddleware.d.ts +0 -0
  179. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js +37 -0
  180. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
  181. package/lib/{middlewares → cjs/middlewares}/PlatformMulterMiddleware.d.ts +0 -0
  182. package/lib/cjs/middlewares/PlatformMulterMiddleware.js +55 -0
  183. package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -0
  184. package/lib/{middlewares/data → cjs/middlewares/__mock__}/FakeCtrl.d.ts +0 -0
  185. package/lib/cjs/middlewares/__mock__/FakeCtrl.js +12 -0
  186. package/lib/cjs/middlewares/__mock__/FakeCtrl.js.map +1 -0
  187. package/lib/{middlewares → cjs/middlewares}/bindEndpointMiddleware.d.ts +0 -0
  188. package/lib/cjs/middlewares/bindEndpointMiddleware.js +13 -0
  189. package/lib/cjs/middlewares/bindEndpointMiddleware.js.map +1 -0
  190. package/lib/{middlewares → cjs/middlewares}/index.d.ts +0 -0
  191. package/lib/cjs/middlewares/index.js +9 -0
  192. package/lib/cjs/middlewares/index.js.map +1 -0
  193. package/lib/{services → cjs/services}/FakeRawDriver.d.ts +0 -0
  194. package/lib/cjs/services/FakeRawDriver.js +26 -0
  195. package/lib/cjs/services/FakeRawDriver.js.map +1 -0
  196. package/lib/{services → cjs/services}/Platform.d.ts +0 -0
  197. package/lib/cjs/services/Platform.js +107 -0
  198. package/lib/cjs/services/Platform.js.map +1 -0
  199. package/lib/{services → cjs/services}/PlatformApplication.d.ts +0 -0
  200. package/lib/cjs/services/PlatformApplication.js +34 -0
  201. package/lib/cjs/services/PlatformApplication.js.map +1 -0
  202. package/lib/{services → cjs/services}/PlatformHandler.d.ts +0 -0
  203. package/lib/cjs/services/PlatformHandler.js +235 -0
  204. package/lib/cjs/services/PlatformHandler.js.map +1 -0
  205. package/lib/{services → cjs/services}/PlatformMiddlewaresChain.d.ts +0 -0
  206. package/lib/cjs/services/PlatformMiddlewaresChain.js +34 -0
  207. package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -0
  208. package/lib/{services → cjs/services}/PlatformRequest.d.ts +2 -1
  209. package/lib/cjs/services/PlatformRequest.js +138 -0
  210. package/lib/cjs/services/PlatformRequest.js.map +1 -0
  211. package/lib/{services → cjs/services}/PlatformResponse.d.ts +4 -4
  212. package/lib/cjs/services/PlatformResponse.js +271 -0
  213. package/lib/cjs/services/PlatformResponse.js.map +1 -0
  214. package/lib/{services → cjs/services}/PlatformRouter.d.ts +0 -0
  215. package/lib/cjs/services/PlatformRouter.js +126 -0
  216. package/lib/cjs/services/PlatformRouter.js.map +1 -0
  217. package/lib/{services → cjs/services}/PlatformTest.d.ts +1 -1
  218. package/lib/cjs/services/PlatformTest.js +172 -0
  219. package/lib/cjs/services/PlatformTest.js.map +1 -0
  220. package/lib/{services → cjs/services}/index.d.ts +0 -0
  221. package/lib/cjs/services/index.js +12 -0
  222. package/lib/cjs/services/index.js.map +1 -0
  223. package/lib/{utils → cjs/utils}/createContext.d.ts +0 -0
  224. package/lib/cjs/utils/createContext.js +38 -0
  225. package/lib/cjs/utils/createContext.js.map +1 -0
  226. package/lib/{utils → cjs/utils}/createHandlerMetadata.d.ts +0 -0
  227. package/lib/cjs/utils/createHandlerMetadata.js +49 -0
  228. package/lib/cjs/utils/createHandlerMetadata.js.map +1 -0
  229. package/lib/{utils → cjs/utils}/createHttpServer.d.ts +0 -0
  230. package/lib/cjs/utils/createHttpServer.js +35 -0
  231. package/lib/cjs/utils/createHttpServer.js.map +1 -0
  232. package/lib/{utils → cjs/utils}/createHttpsServer.d.ts +0 -0
  233. package/lib/cjs/utils/createHttpsServer.js +36 -0
  234. package/lib/cjs/utils/createHttpsServer.js.map +1 -0
  235. package/lib/cjs/utils/createInjector.d.ts +7 -0
  236. package/lib/cjs/utils/createInjector.js +42 -0
  237. package/lib/cjs/utils/createInjector.js.map +1 -0
  238. package/lib/{utils → cjs/utils}/getConfiguration.d.ts +0 -0
  239. package/lib/cjs/utils/getConfiguration.js +42 -0
  240. package/lib/cjs/utils/getConfiguration.js.map +1 -0
  241. package/lib/{utils → cjs/utils}/getStaticsOptions.d.ts +0 -0
  242. package/lib/cjs/utils/getStaticsOptions.js +21 -0
  243. package/lib/cjs/utils/getStaticsOptions.js.map +1 -0
  244. package/lib/{utils → cjs/utils}/index.d.ts +0 -1
  245. package/lib/cjs/utils/index.js +12 -0
  246. package/lib/cjs/utils/index.js.map +1 -0
  247. package/lib/{utils → cjs/utils}/listenServer.d.ts +0 -0
  248. package/lib/cjs/utils/listenServer.js +17 -0
  249. package/lib/cjs/utils/listenServer.js.map +1 -0
  250. package/lib/{utils → cjs/utils}/loadInjector.d.ts +0 -0
  251. package/lib/cjs/utils/loadInjector.js +14 -0
  252. package/lib/cjs/utils/loadInjector.js.map +1 -0
  253. package/lib/{utils → cjs/utils}/mapReturnedResponse.d.ts +0 -0
  254. package/lib/cjs/utils/mapReturnedResponse.js +15 -0
  255. package/lib/cjs/utils/mapReturnedResponse.js.map +1 -0
  256. package/lib/{utils → cjs/utils}/printRoutes.d.ts +0 -0
  257. package/lib/cjs/utils/printRoutes.js +36 -0
  258. package/lib/cjs/utils/printRoutes.js.map +1 -0
  259. package/lib/{utils → cjs/utils}/setResponseHeaders.d.ts +0 -0
  260. package/lib/cjs/utils/setResponseHeaders.js +35 -0
  261. package/lib/cjs/utils/setResponseHeaders.js.map +1 -0
  262. package/lib/{utils → cjs/utils}/useCtxHandler.d.ts +0 -0
  263. package/lib/cjs/utils/useCtxHandler.js +15 -0
  264. package/lib/cjs/utils/useCtxHandler.js.map +1 -0
  265. package/lib/esm/PlatformModule.js +7 -0
  266. package/lib/esm/PlatformModule.js.map +1 -0
  267. package/lib/esm/builder/PlatformBuilder.js +244 -0
  268. package/lib/esm/builder/PlatformBuilder.js.map +1 -0
  269. package/lib/esm/builder/PlatformControllerBuilder.js +79 -0
  270. package/lib/esm/builder/PlatformControllerBuilder.js.map +1 -0
  271. package/lib/esm/config/index.js +4 -0
  272. package/lib/esm/config/index.js.map +1 -0
  273. package/lib/esm/config/interfaces/ConverterSettings.js +2 -0
  274. package/lib/esm/config/interfaces/ConverterSettings.js.map +1 -0
  275. package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js +2 -0
  276. package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js.map +1 -0
  277. package/lib/esm/config/interfaces/PlatformLoggerSettings.js +2 -0
  278. package/lib/esm/config/interfaces/PlatformLoggerSettings.js.map +1 -0
  279. package/lib/esm/config/interfaces/PlatformMulterSettings.js +2 -0
  280. package/lib/esm/config/interfaces/PlatformMulterSettings.js.map +1 -0
  281. package/lib/esm/config/interfaces/PlatformStaticsSettings.js +2 -0
  282. package/lib/esm/config/interfaces/PlatformStaticsSettings.js.map +1 -0
  283. package/lib/esm/config/interfaces/index.js +5 -0
  284. package/lib/esm/config/interfaces/index.js.map +1 -0
  285. package/lib/esm/config/services/PlatformConfiguration.js +192 -0
  286. package/lib/esm/config/services/PlatformConfiguration.js.map +1 -0
  287. package/lib/esm/constants/routerOptions.js +2 -0
  288. package/lib/esm/constants/routerOptions.js.map +1 -0
  289. package/lib/esm/decorators/httpServer.js +27 -0
  290. package/lib/esm/decorators/httpServer.js.map +1 -0
  291. package/lib/esm/decorators/httpsServer.js +27 -0
  292. package/lib/esm/decorators/httpsServer.js.map +1 -0
  293. package/lib/esm/decorators/index.js +20 -0
  294. package/lib/esm/decorators/index.js.map +1 -0
  295. package/lib/esm/decorators/method/acceptMime.js +24 -0
  296. package/lib/esm/decorators/method/acceptMime.js.map +1 -0
  297. package/lib/esm/decorators/method/endpointFn.js +11 -0
  298. package/lib/esm/decorators/method/endpointFn.js.map +1 -0
  299. package/lib/esm/decorators/method/location.js +2 -0
  300. package/lib/esm/decorators/method/location.js.map +1 -0
  301. package/lib/esm/decorators/method/redirect.js +2 -0
  302. package/lib/esm/decorators/method/redirect.js.map +1 -0
  303. package/lib/esm/decorators/method/route.js +2 -0
  304. package/lib/esm/decorators/method/route.js.map +1 -0
  305. package/lib/esm/decorators/method/view.js +30 -0
  306. package/lib/esm/decorators/method/view.js.map +1 -0
  307. package/lib/esm/decorators/multer/index.js +4 -0
  308. package/lib/esm/decorators/multer/index.js.map +1 -0
  309. package/lib/esm/decorators/multer/multerFileSize.js +31 -0
  310. package/lib/esm/decorators/multer/multerFileSize.js.map +1 -0
  311. package/lib/esm/decorators/multer/multerOptions.js +48 -0
  312. package/lib/esm/decorators/multer/multerOptions.js.map +1 -0
  313. package/lib/esm/decorators/multer/multipartFile.js +74 -0
  314. package/lib/esm/decorators/multer/multipartFile.js.map +1 -0
  315. package/lib/esm/decorators/params/endpointInfo.js +17 -0
  316. package/lib/esm/decorators/params/endpointInfo.js.map +1 -0
  317. package/lib/esm/decorators/params/error.js +16 -0
  318. package/lib/esm/decorators/params/error.js.map +1 -0
  319. package/lib/esm/decorators/params/next.js +17 -0
  320. package/lib/esm/decorators/params/next.js.map +1 -0
  321. package/lib/esm/decorators/params/request.js +34 -0
  322. package/lib/esm/decorators/params/request.js.map +1 -0
  323. package/lib/esm/decorators/params/response.js +28 -0
  324. package/lib/esm/decorators/params/response.js.map +1 -0
  325. package/lib/esm/decorators/params/responseData.js +17 -0
  326. package/lib/esm/decorators/params/responseData.js.map +1 -0
  327. package/lib/esm/domain/AnyToPromiseWithCtx.js +31 -0
  328. package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -0
  329. package/lib/esm/domain/ControllerProvider.js +47 -0
  330. package/lib/esm/domain/ControllerProvider.js.map +1 -0
  331. package/lib/esm/domain/EndpointMetadata.js +108 -0
  332. package/lib/esm/domain/EndpointMetadata.js.map +1 -0
  333. package/lib/esm/domain/HandlerMetadata.js +53 -0
  334. package/lib/esm/domain/HandlerMetadata.js.map +1 -0
  335. package/lib/esm/domain/PlatformContext.js +81 -0
  336. package/lib/esm/domain/PlatformContext.js.map +1 -0
  337. package/lib/esm/domain/PlatformRouteDetails.js +20 -0
  338. package/lib/esm/domain/PlatformRouteDetails.js.map +1 -0
  339. package/lib/esm/domain/PropertyMetadata.js +25 -0
  340. package/lib/esm/domain/PropertyMetadata.js.map +1 -0
  341. package/lib/esm/domain/index.js +8 -0
  342. package/lib/esm/domain/index.js.map +1 -0
  343. package/lib/esm/index.js +31 -0
  344. package/lib/esm/index.js.map +1 -0
  345. package/lib/esm/interfaces/AfterInit.js +2 -0
  346. package/lib/esm/interfaces/AfterInit.js.map +1 -0
  347. package/lib/esm/interfaces/AfterListen.js +2 -0
  348. package/lib/esm/interfaces/AfterListen.js.map +1 -0
  349. package/lib/esm/interfaces/AfterRoutesInit.js +2 -0
  350. package/lib/esm/interfaces/AfterRoutesInit.js.map +1 -0
  351. package/lib/esm/interfaces/BeforeInit.js +2 -0
  352. package/lib/esm/interfaces/BeforeInit.js.map +1 -0
  353. package/lib/esm/interfaces/BeforeListen.js +2 -0
  354. package/lib/esm/interfaces/BeforeListen.js.map +1 -0
  355. package/lib/esm/interfaces/BeforeRoutesInit.js +2 -0
  356. package/lib/esm/interfaces/BeforeRoutesInit.js.map +1 -0
  357. package/lib/esm/interfaces/HandlerType.js +14 -0
  358. package/lib/esm/interfaces/HandlerType.js.map +1 -0
  359. package/lib/esm/interfaces/IncomingEvent.js +2 -0
  360. package/lib/esm/interfaces/IncomingEvent.js.map +1 -0
  361. package/lib/esm/interfaces/OnReady.js +2 -0
  362. package/lib/esm/interfaces/OnReady.js.map +1 -0
  363. package/lib/esm/interfaces/OnRequest.js +2 -0
  364. package/lib/esm/interfaces/OnRequest.js.map +1 -0
  365. package/lib/esm/interfaces/OnResponse.js +2 -0
  366. package/lib/esm/interfaces/OnResponse.js.map +1 -0
  367. package/lib/esm/interfaces/OnRoutesInit.js +2 -0
  368. package/lib/esm/interfaces/OnRoutesInit.js.map +1 -0
  369. package/lib/esm/interfaces/PathType.js +2 -0
  370. package/lib/esm/interfaces/PathType.js.map +1 -0
  371. package/lib/esm/interfaces/PlatformRouteOptions.js +2 -0
  372. package/lib/esm/interfaces/PlatformRouteOptions.js.map +1 -0
  373. package/lib/esm/interfaces/ResponseErrorObject.js +2 -0
  374. package/lib/esm/interfaces/ResponseErrorObject.js.map +1 -0
  375. package/lib/esm/interfaces/Route.js +2 -0
  376. package/lib/esm/interfaces/Route.js.map +1 -0
  377. package/lib/esm/interfaces/index.js +17 -0
  378. package/lib/esm/interfaces/index.js.map +1 -0
  379. package/lib/esm/middlewares/AcceptMimesMiddleware.js +24 -0
  380. package/lib/esm/middlewares/AcceptMimesMiddleware.js.map +1 -0
  381. package/lib/esm/middlewares/GlobalAcceptMimesMiddleware.js +23 -0
  382. package/lib/esm/middlewares/GlobalAcceptMimesMiddleware.js.map +1 -0
  383. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js +34 -0
  384. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
  385. package/lib/esm/middlewares/PlatformMulterMiddleware.js +52 -0
  386. package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -0
  387. package/lib/esm/middlewares/__mock__/FakeCtrl.js +9 -0
  388. package/lib/esm/middlewares/__mock__/FakeCtrl.js.map +1 -0
  389. package/lib/esm/middlewares/bindEndpointMiddleware.js +9 -0
  390. package/lib/esm/middlewares/bindEndpointMiddleware.js.map +1 -0
  391. package/lib/esm/middlewares/index.js +6 -0
  392. package/lib/esm/middlewares/index.js.map +1 -0
  393. package/lib/esm/services/FakeRawDriver.js +22 -0
  394. package/lib/esm/services/FakeRawDriver.js.map +1 -0
  395. package/lib/esm/services/Platform.js +104 -0
  396. package/lib/esm/services/Platform.js.map +1 -0
  397. package/lib/esm/services/PlatformApplication.js +31 -0
  398. package/lib/esm/services/PlatformApplication.js.map +1 -0
  399. package/lib/esm/services/PlatformHandler.js +232 -0
  400. package/lib/esm/services/PlatformHandler.js.map +1 -0
  401. package/lib/esm/services/PlatformMiddlewaresChain.js +31 -0
  402. package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -0
  403. package/lib/esm/services/PlatformRequest.js +135 -0
  404. package/lib/esm/services/PlatformRequest.js.map +1 -0
  405. package/lib/esm/services/PlatformResponse.js +268 -0
  406. package/lib/esm/services/PlatformResponse.js.map +1 -0
  407. package/lib/esm/services/PlatformRouter.js +123 -0
  408. package/lib/esm/services/PlatformRouter.js.map +1 -0
  409. package/lib/esm/services/PlatformTest.js +168 -0
  410. package/lib/esm/services/PlatformTest.js.map +1 -0
  411. package/lib/esm/services/index.js +9 -0
  412. package/lib/esm/services/index.js.map +1 -0
  413. package/lib/esm/utils/createContext.js +34 -0
  414. package/lib/esm/utils/createContext.js.map +1 -0
  415. package/lib/esm/utils/createHandlerMetadata.js +45 -0
  416. package/lib/esm/utils/createHandlerMetadata.js.map +1 -0
  417. package/lib/esm/utils/createHttpServer.js +29 -0
  418. package/lib/esm/utils/createHttpServer.js.map +1 -0
  419. package/lib/esm/utils/createHttpsServer.js +30 -0
  420. package/lib/esm/utils/createHttpsServer.js.map +1 -0
  421. package/lib/esm/utils/createInjector.js +38 -0
  422. package/lib/esm/utils/createInjector.js.map +1 -0
  423. package/lib/esm/utils/getConfiguration.js +38 -0
  424. package/lib/esm/utils/getConfiguration.js.map +1 -0
  425. package/lib/esm/utils/getStaticsOptions.js +17 -0
  426. package/lib/esm/utils/getStaticsOptions.js.map +1 -0
  427. package/lib/esm/utils/index.js +9 -0
  428. package/lib/esm/utils/index.js.map +1 -0
  429. package/lib/esm/utils/listenServer.js +13 -0
  430. package/lib/esm/utils/listenServer.js.map +1 -0
  431. package/lib/esm/utils/loadInjector.js +10 -0
  432. package/lib/esm/utils/loadInjector.js.map +1 -0
  433. package/lib/esm/utils/mapReturnedResponse.js +11 -0
  434. package/lib/esm/utils/mapReturnedResponse.js.map +1 -0
  435. package/lib/esm/utils/printRoutes.js +32 -0
  436. package/lib/esm/utils/printRoutes.js.map +1 -0
  437. package/lib/esm/utils/setResponseHeaders.js +31 -0
  438. package/lib/esm/utils/setResponseHeaders.js.map +1 -0
  439. package/lib/esm/utils/useCtxHandler.js +11 -0
  440. package/lib/esm/utils/useCtxHandler.js.map +1 -0
  441. package/lib/types/PlatformModule.d.ts +6 -0
  442. package/lib/types/builder/PlatformBuilder.d.ts +116 -0
  443. package/lib/types/builder/PlatformControllerBuilder.d.ts +17 -0
  444. package/lib/types/config/index.d.ts +3 -0
  445. package/lib/types/config/interfaces/ConverterSettings.d.ts +6 -0
  446. package/lib/types/config/interfaces/EndpointDirectoriesSettings.d.ts +3 -0
  447. package/lib/types/config/interfaces/PlatformLoggerSettings.d.ts +44 -0
  448. package/lib/types/config/interfaces/PlatformMulterSettings.d.ts +138 -0
  449. package/lib/types/config/interfaces/PlatformStaticsSettings.d.ts +17 -0
  450. package/lib/types/config/interfaces/index.d.ts +88 -0
  451. package/lib/types/config/services/PlatformConfiguration.d.ts +85 -0
  452. package/lib/types/constants/routerOptions.d.ts +1 -0
  453. package/lib/types/decorators/httpServer.d.ts +27 -0
  454. package/lib/types/decorators/httpsServer.d.ts +27 -0
  455. package/lib/types/decorators/index.d.ts +16 -0
  456. package/lib/types/decorators/method/acceptMime.d.ts +19 -0
  457. package/lib/types/decorators/method/endpointFn.d.ts +9 -0
  458. package/lib/types/decorators/method/location.d.ts +1 -0
  459. package/lib/types/decorators/method/redirect.d.ts +1 -0
  460. package/lib/types/decorators/method/route.d.ts +1 -0
  461. package/lib/types/decorators/method/view.d.ts +25 -0
  462. package/lib/types/decorators/multer/index.d.ts +3 -0
  463. package/lib/types/decorators/multer/multerFileSize.d.ts +27 -0
  464. package/lib/types/decorators/multer/multerOptions.d.ts +41 -0
  465. package/lib/types/decorators/multer/multipartFile.d.ts +47 -0
  466. package/lib/types/decorators/params/endpointInfo.d.ts +13 -0
  467. package/lib/types/decorators/params/error.d.ts +7 -0
  468. package/lib/types/decorators/params/next.d.ts +22 -0
  469. package/lib/types/decorators/params/request.d.ts +46 -0
  470. package/lib/types/decorators/params/response.d.ts +40 -0
  471. package/lib/types/decorators/params/responseData.d.ts +9 -0
  472. package/lib/types/domain/AnyToPromiseWithCtx.d.ts +18 -0
  473. package/lib/types/domain/ControllerProvider.d.ts +24 -0
  474. package/lib/types/domain/EndpointMetadata.d.ts +76 -0
  475. package/lib/types/domain/HandlerMetadata.d.ts +32 -0
  476. package/lib/types/domain/PlatformContext.d.ts +65 -0
  477. package/lib/types/domain/PlatformRouteDetails.d.ts +23 -0
  478. package/lib/types/domain/PropertyMetadata.d.ts +17 -0
  479. package/lib/types/domain/index.d.ts +7 -0
  480. package/lib/types/index.d.ts +22 -0
  481. package/lib/types/interfaces/AfterInit.d.ts +3 -0
  482. package/lib/types/interfaces/AfterListen.d.ts +3 -0
  483. package/lib/types/interfaces/AfterRoutesInit.d.ts +3 -0
  484. package/lib/types/interfaces/BeforeInit.d.ts +3 -0
  485. package/lib/types/interfaces/BeforeListen.d.ts +3 -0
  486. package/lib/types/interfaces/BeforeRoutesInit.d.ts +3 -0
  487. package/lib/types/interfaces/HandlerType.d.ts +12 -0
  488. package/lib/types/interfaces/IncomingEvent.d.ts +6 -0
  489. package/lib/types/interfaces/OnReady.d.ts +3 -0
  490. package/lib/types/interfaces/OnRequest.d.ts +4 -0
  491. package/lib/types/interfaces/OnResponse.d.ts +4 -0
  492. package/lib/types/interfaces/OnRoutesInit.d.ts +3 -0
  493. package/lib/types/interfaces/PathType.d.ts +1 -0
  494. package/lib/types/interfaces/PlatformRouteOptions.d.ts +16 -0
  495. package/lib/types/interfaces/ResponseErrorObject.d.ts +8 -0
  496. package/lib/types/interfaces/Route.d.ts +10 -0
  497. package/lib/types/interfaces/index.d.ts +16 -0
  498. package/lib/types/middlewares/AcceptMimesMiddleware.d.ts +10 -0
  499. package/lib/types/middlewares/GlobalAcceptMimesMiddleware.d.ts +9 -0
  500. package/lib/types/middlewares/PlatformAcceptMimesMiddleware.d.ts +10 -0
  501. package/lib/types/middlewares/PlatformMulterMiddleware.d.ts +19 -0
  502. package/lib/types/middlewares/__mock__/FakeCtrl.d.ts +2 -0
  503. package/lib/types/middlewares/bindEndpointMiddleware.d.ts +5 -0
  504. package/lib/types/middlewares/index.d.ts +5 -0
  505. package/lib/types/services/FakeRawDriver.d.ts +15 -0
  506. package/lib/types/services/Platform.d.ts +37 -0
  507. package/lib/types/services/PlatformApplication.d.ts +21 -0
  508. package/lib/types/services/PlatformHandler.d.ts +80 -0
  509. package/lib/types/services/PlatformMiddlewaresChain.d.ts +6 -0
  510. package/lib/types/services/PlatformRequest.d.ts +112 -0
  511. package/lib/types/services/PlatformResponse.d.ts +161 -0
  512. package/lib/types/services/PlatformRouter.d.ts +48 -0
  513. package/lib/types/services/PlatformTest.d.ts +57 -0
  514. package/lib/types/services/index.d.ts +8 -0
  515. package/lib/types/utils/createContext.d.ts +9 -0
  516. package/lib/types/utils/createHandlerMetadata.d.ts +8 -0
  517. package/lib/types/utils/createHttpServer.d.ts +3 -0
  518. package/lib/types/utils/createHttpsServer.d.ts +3 -0
  519. package/lib/types/utils/createInjector.d.ts +7 -0
  520. package/lib/types/utils/getConfiguration.d.ts +2 -0
  521. package/lib/types/utils/getStaticsOptions.d.ts +5 -0
  522. package/lib/types/utils/index.d.ts +8 -0
  523. package/lib/types/utils/listenServer.d.ts +10 -0
  524. package/lib/types/utils/loadInjector.d.ts +6 -0
  525. package/lib/types/utils/mapReturnedResponse.d.ts +4 -0
  526. package/lib/types/utils/printRoutes.d.ts +2 -0
  527. package/lib/types/utils/setResponseHeaders.d.ts +5 -0
  528. package/lib/types/utils/useCtxHandler.d.ts +13 -0
  529. package/package.json +26 -22
  530. package/tsconfig.compile.esm.json +23 -0
  531. package/lib/index.js +0 -3603
  532. package/lib/index.js.map +0 -1
  533. package/lib/index.modern.js +0 -3410
  534. package/lib/index.modern.js.map +0 -1
  535. package/lib/utils/createInjector.d.ts +0 -2
  536. package/lib/utils/createPlatformApplication.d.ts +0 -2
@@ -1,3410 +0,0 @@
1
- import { $log, colorize } from '@tsed/logger';
2
- export { $log, Logger } from '@tsed/logger';
3
- import '@tsed/logger-file';
4
- import { DIConfiguration, Injectable, ProviderScope, Inject, InjectorService, Constant, Provider, ProviderType, GlobalProviders, Scope, DIContext, setLoggerLevel, registerProvider, Configuration, createContainer, colors, DITest } from '@tsed/di';
5
- export * from '@tsed/di';
6
- import { ParamTypes, PlatformParams, Context, UseParam, mapParamsOptions } from '@tsed/platform-params';
7
- export * from '@tsed/platform-params';
8
- export * from '@tsed/platform-exceptions';
9
- import { PlatformResponseFilter } from '@tsed/platform-response-filter';
10
- export * from '@tsed/platform-response-filter';
11
- export * from '@tsed/platform-cache';
12
- import { Middleware, getMiddlewaresForHook } from '@tsed/platform-middlewares';
13
- export * from '@tsed/platform-middlewares';
14
- import { PlatformViews } from '@tsed/platform-views';
15
- export * from '@tsed/platform-views';
16
- import { importProviders } from '@tsed/components-scan';
17
- export * from '@tsed/components-scan';
18
- export * from '@tsed/platform-log-middleware';
19
- import { __decorate, __metadata, __param } from 'tslib';
20
- import { AnyToPromise, AnyToPromiseStatus, nameOf, Store, descriptorOf, prototypeOf, deepMerge, isFunction, DecoratorTypes, isStream, uniq, isBoolean, isNumber, isString, getValue, Env, toMap, StoreMerge, Metadata, useDecorators, useMethodDecorators, StoreSet, isClass } from '@tsed/core';
21
- import { Exception, NotAcceptable } from '@tsed/exceptions';
22
- import { JsonParameterStore, JsonMethodStore, JsonEntityStore, JsonEntityComponent, getOperationsRoutes, OperationMethods, JsonOperationRoute, JsonPropertyStore, getProperties, concatPath, Returns, Consumes, Produces, JsonEntityFn } from '@tsed/schema';
23
- export { All, Delete, Get, Head, Location, Options, Patch, Post, Put, Redirect } from '@tsed/schema';
24
- import { promisify } from 'util';
25
- import Http, { ServerResponse, IncomingMessage } from 'http';
26
- import Https from 'https';
27
-
28
- function _extends() {
29
- _extends = Object.assign || function (target) {
30
- for (var i = 1; i < arguments.length; i++) {
31
- var source = arguments[i];
32
-
33
- for (var key in source) {
34
- if (Object.prototype.hasOwnProperty.call(source, key)) {
35
- target[key] = source[key];
36
- }
37
- }
38
- }
39
-
40
- return target;
41
- };
42
-
43
- return _extends.apply(this, arguments);
44
- }
45
-
46
- function _objectWithoutPropertiesLoose(source, excluded) {
47
- if (source == null) return {};
48
- var target = {};
49
- var sourceKeys = Object.keys(source);
50
- var key, i;
51
-
52
- for (i = 0; i < sourceKeys.length; i++) {
53
- key = sourceKeys[i];
54
- if (excluded.indexOf(key) >= 0) continue;
55
- target[key] = source[key];
56
- }
57
-
58
- return target;
59
- }
60
-
61
- var id = 0;
62
-
63
- function _classPrivateFieldLooseKey(name) {
64
- return "__private_" + id++ + "_" + name;
65
- }
66
-
67
- function _classPrivateFieldLooseBase(receiver, privateKey) {
68
- if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
69
- throw new TypeError("attempted to use private field on non-instance");
70
- }
71
-
72
- return receiver;
73
- }
74
-
75
- var PlatformConfiguration_1;
76
- const rootDir = process.cwd();
77
- /**
78
- * `PlatformConfiguration` contains all information about your Server configuration.
79
- */
80
-
81
- let PlatformConfiguration = PlatformConfiguration_1 = class PlatformConfiguration extends DIConfiguration {
82
- constructor() {
83
- super({
84
- rootDir
85
- });
86
- }
87
-
88
- get version() {
89
- return this.getRaw("version");
90
- }
91
-
92
- set version(v) {
93
- this.setRaw("version", v);
94
- }
95
-
96
- get rootDir() {
97
- return this.getRaw("rootDir");
98
- }
99
-
100
- set rootDir(value) {
101
- this.setRaw("rootDir", value);
102
- }
103
-
104
- get port() {
105
- return this.httpPort;
106
- }
107
-
108
- set port(value) {
109
- this.httpPort = value;
110
- }
111
-
112
- get httpsOptions() {
113
- return this.getRaw("httpsOptions");
114
- }
115
-
116
- set httpsOptions(value) {
117
- this.setRaw("httpsOptions", value);
118
- }
119
-
120
- get httpPort() {
121
- return this.getRaw("httpPort");
122
- }
123
-
124
- set httpPort(value) {
125
- this.setRaw("httpPort", value);
126
- }
127
-
128
- get httpsPort() {
129
- return this.getRaw("httpsPort");
130
- }
131
-
132
- set httpsPort(value) {
133
- this.setRaw("httpsPort", value);
134
- }
135
-
136
- get env() {
137
- return this.getRaw("env");
138
- }
139
-
140
- set env(value) {
141
- this.setRaw("env", value);
142
- }
143
-
144
- get mount() {
145
- return this.get("mount");
146
- }
147
-
148
- set mount(value) {
149
- this.setRaw("mount", value);
150
- }
151
-
152
- get componentsScan() {
153
- return this.resolve(this.getRaw("componentsScan"));
154
- }
155
-
156
- set componentsScan(value) {
157
- this.setRaw("componentsScan", value);
158
- }
159
-
160
- get statics() {
161
- return this.getRaw("statics") || this.getRaw("serveStatic") || {};
162
- }
163
-
164
- set statics(value) {
165
- this.setRaw("statics", value);
166
- }
167
-
168
- get acceptMimes() {
169
- return this.getRaw("acceptMimes");
170
- }
171
-
172
- set acceptMimes(value) {
173
- this.setRaw("acceptMimes", value || []);
174
- }
175
-
176
- get debug() {
177
- return this.logger.level === "debug";
178
- }
179
-
180
- set debug(debug) {
181
- this.logger = _extends({}, this.logger, {
182
- level: debug ? "debug" : "info"
183
- });
184
- }
185
-
186
- get converter() {
187
- return this.get("converter") || {};
188
- }
189
-
190
- set converter(options) {
191
- this.setRaw("converter", options);
192
- }
193
-
194
- get logger() {
195
- return this.get("logger");
196
- }
197
-
198
- set logger(value) {
199
- const logger = _extends({}, this.logger, value);
200
-
201
- logger.debug = logger.level === "debug";
202
- this.setRaw("logger", logger);
203
- this.setRaw("debug", logger.debug);
204
-
205
- if (logger.format) {
206
- $log.appenders.set("stdout", {
207
- type: "stdout",
208
- levels: ["info", "debug"],
209
- layout: {
210
- type: "pattern",
211
- pattern: logger.format
212
- }
213
- });
214
- $log.appenders.set("stderr", {
215
- levels: ["trace", "fatal", "error", "warn"],
216
- type: "stderr",
217
- layout: {
218
- type: "pattern",
219
- pattern: logger.format
220
- }
221
- });
222
- }
223
- }
224
-
225
- get exclude() {
226
- return this.get("exclude");
227
- }
228
-
229
- set exclude(exclude) {
230
- this.setRaw("exclude", exclude);
231
- }
232
- /**
233
- *
234
- * @param addressPort
235
- * @returns {{address: string, port: number}}
236
- */
237
-
238
-
239
- static buildAddressAndPort(addressPort) {
240
- let address = "0.0.0.0";
241
- let port = addressPort;
242
-
243
- if (typeof addressPort === "string" && addressPort.indexOf(":") > -1) {
244
- [address, port] = addressPort.split(":");
245
- port = +port;
246
- }
247
-
248
- return {
249
- address,
250
- port: port
251
- };
252
- }
253
- /**
254
- *
255
- * @returns {string|number}
256
- */
257
-
258
-
259
- getHttpPort() {
260
- return PlatformConfiguration_1.buildAddressAndPort(this.getRaw("httpPort"));
261
- }
262
- /**
263
- *
264
- * @param settings
265
- */
266
-
267
-
268
- setHttpPort(settings) {
269
- this.setRaw("httpPort", `${settings.address}:${settings.port}`);
270
- }
271
- /**
272
- *
273
- * @returns {string|number}
274
- */
275
-
276
-
277
- getHttpsPort() {
278
- return PlatformConfiguration_1.buildAddressAndPort(this.getRaw("httpsPort"));
279
- }
280
- /**
281
- *
282
- * @param settings
283
- */
284
-
285
-
286
- setHttpsPort(settings) {
287
- this.setRaw("httpsPort", `${settings.address}:${settings.port}`);
288
- }
289
-
290
- getBestHost() {
291
- const {
292
- httpsPort,
293
- httpPort
294
- } = this;
295
-
296
- if (httpsPort) {
297
- const host = this.getHttpsPort();
298
- return _extends({
299
- protocol: "https"
300
- }, host);
301
- }
302
-
303
- if (httpPort) {
304
- const host = this.getHttpPort();
305
- return _extends({
306
- protocol: "http"
307
- }, host);
308
- }
309
- }
310
-
311
- };
312
- PlatformConfiguration = PlatformConfiguration_1 = __decorate([Injectable({
313
- scope: ProviderScope.SINGLETON,
314
- global: true
315
- }), __metadata("design:paramtypes", [])], PlatformConfiguration);
316
-
317
- /**
318
- * @ignore
319
- */
320
- function bindEndpointMiddleware(endpoint) {
321
- return ctx => {
322
- ctx.endpoint = endpoint;
323
- };
324
- }
325
-
326
- /**
327
- * @ignore
328
- */
329
- const createFakeRawDriver = () => {
330
- // istanbul ignore next
331
- function FakeRawDriver() {} // istanbul ignore next
332
-
333
-
334
- function use() {
335
- return this;
336
- }
337
-
338
- FakeRawDriver.use = use;
339
- FakeRawDriver.all = use;
340
- FakeRawDriver.get = use;
341
- FakeRawDriver.patch = use;
342
- FakeRawDriver.post = use;
343
- FakeRawDriver.put = use;
344
- FakeRawDriver.head = use;
345
- FakeRawDriver.delete = use;
346
- FakeRawDriver.options = use;
347
- return FakeRawDriver;
348
- };
349
-
350
- class AnyToPromiseWithCtx extends AnyToPromise {
351
- constructor({
352
- $ctx,
353
- err
354
- }) {
355
- super();
356
- this.$ctx = $ctx;
357
- this.err = err;
358
- }
359
-
360
- isDone() {
361
- const {
362
- $ctx
363
- } = this;
364
-
365
- if (!($ctx != null && $ctx.isDone())) {
366
- if ($ctx != null && $ctx.request.isAborted() || $ctx != null && $ctx.response.isDone()) {
367
- this.destroy();
368
-
369
- if (this.status === AnyToPromiseStatus.PENDING) {
370
- this.status = AnyToPromiseStatus.RESOLVED;
371
- }
372
- }
373
- }
374
-
375
- return super.isDone();
376
- }
377
-
378
- async call(cb) {
379
- return super.call(() => cb(this));
380
- }
381
-
382
- destroy() {
383
- // @ts-ignore
384
- delete this.$ctx;
385
- }
386
-
387
- isCanceledResponse(process) {
388
- return process === this.$ctx.getResponse();
389
- }
390
-
391
- }
392
-
393
- /**
394
- * @ignore
395
- */
396
- var HandlerType;
397
-
398
- (function (HandlerType) {
399
- HandlerType["CUSTOM"] = "custom";
400
- HandlerType["ENDPOINT"] = "endpoint";
401
- HandlerType["MIDDLEWARE"] = "middleware";
402
- HandlerType["ERR_MIDDLEWARE"] = "err:middleware";
403
- HandlerType["CTX_FN"] = "context";
404
- HandlerType["RAW_FN"] = "raw:middleware";
405
- HandlerType["RAW_ERR_FN"] = "raw:err:middleware";
406
- })(HandlerType || (HandlerType = {}));
407
-
408
- class HandlerMetadata {
409
- constructor(options) {
410
- this.injectable = false;
411
- this.type = HandlerType.RAW_FN;
412
- this.hasNextFunction = false;
413
- const {
414
- target,
415
- token,
416
- propertyKey,
417
- type,
418
- scope,
419
- routeOptions
420
- } = options;
421
- this.type = type || target.type || HandlerType.RAW_FN;
422
- this.scope = scope || ProviderScope.SINGLETON;
423
- this.routeOptions = routeOptions || {};
424
- const handler = propertyKey ? target.prototype[propertyKey] : target;
425
-
426
- if (propertyKey) {
427
- this.target = target;
428
- this.token = token;
429
- this.propertyKey = propertyKey;
430
- this.hasNextFunction = this.hasParamType(ParamTypes.NEXT_FN);
431
-
432
- if (this.hasParamType(ParamTypes.ERR)) {
433
- this.type = HandlerType.ERR_MIDDLEWARE;
434
- }
435
-
436
- this.injectable = JsonParameterStore.getParams(target, propertyKey).length > 0;
437
- } else {
438
- this.handler = handler;
439
- }
440
-
441
- if (!this.injectable) {
442
- if (handler.length === 4) {
443
- this.type = HandlerType.RAW_ERR_FN;
444
- }
445
-
446
- this.hasNextFunction = handler.length >= 3;
447
- }
448
- }
449
-
450
- get hasErrorParam() {
451
- return this.type === HandlerType.ERR_MIDDLEWARE || this.type === HandlerType.RAW_ERR_FN;
452
- }
453
-
454
- getParams() {
455
- return JsonParameterStore.getParams(this.target, this.propertyKey) || [];
456
- }
457
-
458
- hasParamType(paramType) {
459
- return this.getParams().findIndex(p => p.paramType === paramType) > -1;
460
- }
461
-
462
- isFinal() {
463
- var _this$routeOptions;
464
-
465
- return ((_this$routeOptions = this.routeOptions) == null ? void 0 : _this$routeOptions.isFinal) || false;
466
- }
467
-
468
- toString() {
469
- return [this.target && nameOf(this.target), this.propertyKey].filter(Boolean).join(".");
470
- }
471
-
472
- }
473
-
474
- /**
475
- * EndpointMetadata contains metadata about a controller and his method.
476
- * Each annotation (@Get, @Body...) attached to a method are stored in a endpoint.
477
- * EndpointMetadata convert this metadata to an array which contain arguments to call an Express method.
478
- *
479
- * Example :
480
- *
481
- * @Controller("/my-path")
482
- * provide MyClass {
483
- *
484
- * @Get("/")
485
- * @Authenticated()
486
- * public myMethod(){}
487
- * }
488
- *
489
- */
490
-
491
- let EndpointMetadata = class EndpointMetadata extends JsonMethodStore {
492
- constructor(options) {
493
- super(_extends({
494
- store: Store.fromMethod(options.target, options.propertyKey),
495
- descriptor: descriptorOf(options.target, options.propertyKey)
496
- }, options));
497
- this.beforeMiddlewares = [];
498
- this.middlewares = [];
499
- this.afterMiddlewares = [];
500
- const {
501
- beforeMiddlewares = [],
502
- middlewares = [],
503
- afterMiddlewares = []
504
- } = options;
505
- this.after(afterMiddlewares);
506
- this.before(beforeMiddlewares);
507
- this.use(middlewares);
508
- }
509
-
510
- get targetName() {
511
- return nameOf(this.token);
512
- }
513
-
514
- get params() {
515
- return this.parameters;
516
- }
517
-
518
- get view() {
519
- return this.store.get("view");
520
- }
521
-
522
- set view(view) {
523
- this.store.set("view", view);
524
- }
525
-
526
- get acceptMimes() {
527
- return this.store.get("acceptMimes", []);
528
- }
529
-
530
- set acceptMimes(mimes) {
531
- this.store.set("acceptMimes", mimes);
532
- }
533
- /**
534
- * Get an endpoint.
535
- * @param target
536
- * @param propertyKey
537
- * @param descriptor
538
- */
539
-
540
-
541
- static get(target, propertyKey, descriptor) {
542
- descriptor = descriptor || descriptorOf(prototypeOf(target), propertyKey);
543
- return JsonEntityStore.from(prototypeOf(target), propertyKey, descriptor);
544
- }
545
-
546
- addOperationPath(method, path, options = {}) {
547
- return this.operation.addOperationPath(method, path, options);
548
- }
549
- /**
550
- * Find the a value at the controller level. Let this value be extended or overridden by the endpoint itself.
551
- *
552
- * @param key
553
- * @returns {any}
554
- */
555
-
556
-
557
- get(key) {
558
- const ctrlValue = Store.from(this.target).get(key);
559
- return deepMerge(ctrlValue, this.store.get(key));
560
- }
561
- /**
562
- * Append middlewares to the beforeMiddlewares list.
563
- * @param args
564
- * @returns {EndpointMetadata}
565
- */
566
-
567
-
568
- before(args) {
569
- this.beforeMiddlewares = this.beforeMiddlewares.concat(args).filter(isFunction);
570
- return this;
571
- }
572
- /**
573
- * Append middlewares to the afterMiddlewares list.
574
- * @param args
575
- * @returns {EndpointMetadata}
576
- */
577
-
578
-
579
- after(args) {
580
- this.afterMiddlewares = this.afterMiddlewares.concat(args).filter(isFunction);
581
- return this;
582
- }
583
- /**
584
- * Store all arguments collected via Annotation.
585
- * @param args
586
- */
587
-
588
-
589
- use(args) {
590
- this.middlewares = this.middlewares.concat(args).filter(isFunction);
591
- return this;
592
- }
593
-
594
- };
595
- EndpointMetadata = __decorate([JsonEntityComponent(DecoratorTypes.METHOD), __metadata("design:paramtypes", [Object])], EndpointMetadata);
596
-
597
- function isMetadata(input) {
598
- return input instanceof HandlerMetadata;
599
- }
600
- /**
601
- * @ignore
602
- */
603
-
604
-
605
- function createHandlerMetadata(injector, obj, routeOptions = {}) {
606
- if (isMetadata(obj)) {
607
- return obj;
608
- }
609
-
610
- let options;
611
-
612
- if (obj instanceof EndpointMetadata) {
613
- const provider = injector.getProvider(routeOptions.token);
614
- options = {
615
- token: provider.token,
616
- target: provider.useClass,
617
- scope: provider.scope,
618
- type: HandlerType.ENDPOINT,
619
- propertyKey: obj.propertyKey
620
- };
621
- } else {
622
- const provider = injector.getProvider(obj);
623
-
624
- if (provider) {
625
- options = {
626
- token: provider.token,
627
- target: provider.useClass,
628
- scope: provider.scope,
629
- type: HandlerType.MIDDLEWARE,
630
- propertyKey: "use"
631
- };
632
- } else {
633
- options = {
634
- target: obj
635
- };
636
- }
637
- }
638
-
639
- options.routeOptions = routeOptions;
640
- return new HandlerMetadata(options);
641
- }
642
-
643
- function mergeHeaders(specHeaders, headers) {
644
- return Object.entries(specHeaders).reduce((headers, [key, item]) => {
645
- key = key.toLowerCase();
646
- return _extends({}, headers, {
647
- [key]: headers[key] === undefined ? String(item.example) : headers[key]
648
- });
649
- }, headers);
650
- }
651
- /**
652
- * @ignore
653
- */
654
-
655
-
656
- function setResponseHeaders(ctx) {
657
- const {
658
- response,
659
- endpoint
660
- } = ctx;
661
- const {
662
- operation
663
- } = endpoint;
664
-
665
- if (response.isDone()) {
666
- return;
667
- }
668
-
669
- if (!response.hasStatus()) {
670
- // apply status only if the isn't already modified
671
- response.status(operation.getStatus());
672
- }
673
-
674
- const statusCode = response.statusCode;
675
- const headers = operation.getHeadersOf(response.statusCode);
676
- const mergedHeaders = mergeHeaders(headers, response.getHeaders());
677
- response.setHeaders(mergedHeaders);
678
-
679
- if (operation.isRedirection(statusCode)) {
680
- response.redirect(statusCode, String(mergedHeaders["location"]));
681
- }
682
- }
683
-
684
- /**
685
- * Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).
686
- * @platform
687
- */
688
-
689
- let PlatformHandler = class PlatformHandler {
690
- constructor(injector, params) {
691
- this.injector = injector;
692
- this.params = params;
693
- }
694
- /**
695
- * Create a native middleware based on the given metadata and return an instance of AnyToPromiseWithCtx
696
- * @param input
697
- * @param options
698
- */
699
-
700
-
701
- createHandler(input, options = {}) {
702
- return this.createRawHandler(createHandlerMetadata(this.injector, input, options));
703
- }
704
- /**
705
- * Create injectable handler from the given provider
706
- * @param provider
707
- * @param propertyKey
708
- */
709
-
710
-
711
- createCustomHandler(provider, propertyKey) {
712
- const handler = this.compileHandler(new HandlerMetadata({
713
- token: provider.provide,
714
- target: provider.useClass,
715
- type: HandlerType.CUSTOM,
716
- scope: provider.scope,
717
- propertyKey
718
- }));
719
- return async function ($ctx, next) {
720
- return handler({
721
- $ctx,
722
- next
723
- });
724
- };
725
- }
726
- /**
727
- * Send the response to the consumer.
728
- * @param data
729
- * @param ctx
730
- * @protected
731
- */
732
-
733
-
734
- async flush(data, ctx) {
735
- const {
736
- response
737
- } = ctx;
738
-
739
- if (!response.isDone()) {
740
- data = await this.responseFilter.serialize(data, ctx);
741
- data = await this.responseFilter.transform(data, ctx);
742
- response.body(data);
743
- }
744
- }
745
-
746
- compileHandler(metadata) {
747
- var _this = this;
748
-
749
- if (metadata.type === HandlerType.CTX_FN) {
750
- return async function (scope) {
751
- // @ts-ignore
752
- return _this.onCtxRequest(_extends({}, scope, {
753
- handler: () => metadata.handler(scope.$ctx),
754
- metadata
755
- }));
756
- };
757
- }
758
-
759
- const promise = this.params.compileHandler({
760
- token: metadata.token,
761
- propertyKey: metadata.propertyKey,
762
- getCustomArgs: metadata.injectable ? undefined : this.getDefaultArgs(metadata)
763
- });
764
- return async function (scope) {
765
- const handler = await promise; // @ts-ignore
766
-
767
- return _this.onRequest(_extends({}, scope, {
768
- handler,
769
- metadata
770
- }));
771
- };
772
- }
773
-
774
- async onCtxRequest(requestOptions) {
775
- await requestOptions.handler(requestOptions);
776
- return this.next(requestOptions);
777
- }
778
- /**
779
- * Call handler when a request his handle
780
- * @param requestOptions
781
- */
782
-
783
-
784
- async onRequest(requestOptions) {
785
- var _this2 = this;
786
-
787
- const {
788
- $ctx,
789
- metadata,
790
- err,
791
- handler
792
- } = requestOptions; // istanbul ignore next
793
-
794
- if (!$ctx) {
795
- $log.error({
796
- name: "HEADERS_SENT",
797
- message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${metadata.toString()}`
798
- });
799
- return;
800
- }
801
-
802
- const resolver = new AnyToPromiseWithCtx({
803
- $ctx,
804
- err
805
- });
806
- return this.injector.runInContext($ctx, async function () {
807
- try {
808
- const {
809
- state,
810
- data,
811
- status,
812
- headers
813
- } = await resolver.call(handler);
814
-
815
- if (state === AnyToPromiseStatus.RESOLVED) {
816
- if (status) {
817
- $ctx.response.status(status);
818
- }
819
-
820
- if (headers) {
821
- $ctx.response.setHeaders(headers);
822
- }
823
-
824
- if (data !== undefined) {
825
- $ctx.data = data;
826
- } // Can be canceled by the handler itself
827
-
828
-
829
- return await _this2.onSuccess($ctx.data, requestOptions);
830
- }
831
- } catch (er) {
832
- return _this2.onError(er, requestOptions);
833
- }
834
- });
835
- }
836
-
837
- async onError(er, requestOptions) {
838
- var _$ctx$response;
839
-
840
- const {
841
- next,
842
- $ctx,
843
- metadata
844
- } = requestOptions;
845
- $ctx.data = er;
846
-
847
- if (!next) {
848
- throw er;
849
- } // istanbul ignore next
850
-
851
-
852
- if (!($ctx != null && (_$ctx$response = $ctx.response) != null && _$ctx$response.isHeadersSent) || $ctx.response.isHeadersSent()) {
853
- $log.warn({
854
- name: "HEADERS_SENT",
855
- message: `An error was caught after the headers were sent to the client. The error comes from the handler: ${metadata.toString()}`,
856
- stack: er.stack,
857
- origin: er,
858
- request_id: $ctx.id
859
- });
860
- return;
861
- }
862
-
863
- return next && next(er);
864
- }
865
- /**
866
- * Manage success scenario
867
- * @param data
868
- * @param requestOptions
869
- * @protected
870
- */
871
-
872
-
873
- async onSuccess(data, requestOptions) {
874
- const {
875
- metadata,
876
- $ctx,
877
- next
878
- } = requestOptions; // TODO see this control is necessary
879
- // istanbul ignore next
880
-
881
- if ($ctx.request.isAborted() || $ctx.response.isDone()) {
882
- return;
883
- } // set headers each times that an endpoint is called
884
-
885
-
886
- if (metadata.type === HandlerType.ENDPOINT) {
887
- this.setHeaders($ctx);
888
- } // call returned middleware
889
-
890
-
891
- if (isFunction(data) && !isStream(data)) {
892
- return this.callReturnedMiddleware(data, $ctx, next);
893
- }
894
-
895
- if (metadata.isFinal()) {
896
- return this.flush(data, $ctx);
897
- }
898
-
899
- return this.next(requestOptions);
900
- }
901
- /**
902
- * Call the returned middleware by the handler.
903
- * @param middleware
904
- * @param ctx
905
- * @param next
906
- * @protected
907
- */
908
-
909
-
910
- callReturnedMiddleware(middleware, ctx, next) {
911
- return middleware(ctx.getRequest(), ctx.getResponse(), next);
912
- }
913
- /**
914
- * create Raw handler
915
- * @param metadata
916
- */
917
-
918
-
919
- createRawHandler(metadata) {
920
- if ([HandlerType.RAW_ERR_FN, HandlerType.RAW_FN].includes(metadata.type)) {
921
- return metadata.handler;
922
- }
923
-
924
- const handler = this.compileHandler(metadata);
925
- return async function (request, response, next) {
926
- return handler({
927
- next,
928
- $ctx: request.$ctx
929
- });
930
- };
931
- }
932
- /**
933
- * Set response headers
934
- * @param ctx
935
- * @protected
936
- */
937
-
938
-
939
- setHeaders(ctx) {
940
- return setResponseHeaders(ctx);
941
- }
942
-
943
- next(requestOptions) {
944
- const {
945
- $ctx,
946
- next
947
- } = requestOptions;
948
- return !$ctx.response.isDone() && next && next();
949
- }
950
-
951
- getDefaultArgs(metadata) {
952
- return async function (scope) {
953
- return [metadata.hasErrorParam && scope.err, scope.$ctx.request.request, scope.$ctx.response.response, metadata.hasNextFunction && scope.next].filter(Boolean);
954
- };
955
- }
956
-
957
- };
958
-
959
- __decorate([Inject(), __metadata("design:type", PlatformResponseFilter)], PlatformHandler.prototype, "responseFilter", void 0);
960
-
961
- PlatformHandler = __decorate([Injectable({
962
- scope: ProviderScope.SINGLETON
963
- }), __metadata("design:paramtypes", [InjectorService, PlatformParams])], PlatformHandler);
964
-
965
- const _excluded$3 = ["method", "path", "handlers"];
966
- var PlatformRouter_1;
967
- /**
968
- * @ignore
969
- */
970
-
971
- const PLATFORM_ROUTER_OPTIONS = Symbol.for("PlatformRouterOptions");
972
- /**
973
- * Platform Router abstraction layer.
974
- * @platform
975
- */
976
-
977
- let PlatformRouter = PlatformRouter_1 = class PlatformRouter {
978
- constructor(platformHandler) {
979
- this.platformHandler = platformHandler;
980
- this.isBuilt = false;
981
- this.rawRouter = this.raw = PlatformRouter_1.createRawRouter();
982
- }
983
- /**
984
- * Create a new instance of PlatformRouter
985
- * @param injector
986
- * @param routerOptions
987
- */
988
-
989
-
990
- static create(injector, routerOptions = {}) {
991
- const locals = new Map();
992
- locals.set(PLATFORM_ROUTER_OPTIONS, routerOptions);
993
- return injector.invoke(PlatformRouter_1, locals);
994
- }
995
-
996
- static createRawRouter() {
997
- return createFakeRawDriver();
998
- }
999
-
1000
- callback() {
1001
- return this.raw;
1002
- }
1003
-
1004
- getRouter() {
1005
- return this.rawRouter;
1006
- }
1007
-
1008
- use(...handlers) {
1009
- // @ts-ignore
1010
- this.getRouter().use(...this.mapHandlers(handlers));
1011
- return this;
1012
- }
1013
-
1014
- addRoute(options) {
1015
- const {
1016
- method,
1017
- path,
1018
- handlers
1019
- } = options,
1020
- opts = _objectWithoutPropertiesLoose(options, _excluded$3); // @ts-ignore
1021
-
1022
-
1023
- this.getRouter()[method](path, ...this.mapHandlers(handlers, _extends({
1024
- method,
1025
- path
1026
- }, opts)));
1027
- return this;
1028
- }
1029
-
1030
- all(path, ...handlers) {
1031
- return this.addRoute({
1032
- method: "all",
1033
- path,
1034
- handlers,
1035
- isFinal: true
1036
- });
1037
- }
1038
-
1039
- get(path, ...handlers) {
1040
- return this.addRoute({
1041
- method: "get",
1042
- path,
1043
- handlers,
1044
- isFinal: true
1045
- });
1046
- }
1047
-
1048
- post(path, ...handlers) {
1049
- return this.addRoute({
1050
- method: "post",
1051
- path,
1052
- handlers,
1053
- isFinal: true
1054
- });
1055
- }
1056
-
1057
- put(path, ...handlers) {
1058
- return this.addRoute({
1059
- method: "put",
1060
- path,
1061
- handlers,
1062
- isFinal: true
1063
- });
1064
- }
1065
-
1066
- delete(path, ...handlers) {
1067
- return this.addRoute({
1068
- method: "delete",
1069
- path,
1070
- handlers,
1071
- isFinal: true
1072
- });
1073
- }
1074
-
1075
- patch(path, ...handlers) {
1076
- return this.addRoute({
1077
- method: "patch",
1078
- path,
1079
- handlers,
1080
- isFinal: true
1081
- });
1082
- }
1083
-
1084
- head(path, ...handlers) {
1085
- return this.addRoute({
1086
- method: "head",
1087
- path,
1088
- handlers,
1089
- isFinal: true
1090
- });
1091
- }
1092
-
1093
- options(path, ...handlers) {
1094
- return this.addRoute({
1095
- method: "options",
1096
- path,
1097
- handlers,
1098
- isFinal: true
1099
- });
1100
- }
1101
-
1102
- statics(path, options) {
1103
- return this;
1104
- }
1105
-
1106
- multer(options) {
1107
- const m = require("multer")(options);
1108
-
1109
- const makePromise = (multer, name) => {
1110
- // istanbul ignore next
1111
- if (!multer[name]) return;
1112
- const fn = multer[name];
1113
-
1114
- multer[name] = function apply(...args) {
1115
- const middleware = Reflect.apply(fn, this, args);
1116
- return (req, res) => promisify(middleware)(req, res);
1117
- };
1118
- };
1119
-
1120
- makePromise(m, "any");
1121
- makePromise(m, "array");
1122
- makePromise(m, "fields");
1123
- makePromise(m, "none");
1124
- makePromise(m, "single");
1125
- return m;
1126
- }
1127
-
1128
- mapHandlers(handlers, options = {}) {
1129
- return handlers.reduce((list, handler, index) => {
1130
- if (typeof handler === "string") {
1131
- return list.concat(handler);
1132
- }
1133
-
1134
- if (handler instanceof PlatformRouter_1) {
1135
- return list.concat(handler.callback());
1136
- }
1137
-
1138
- return list.concat(this.platformHandler.createHandler(handler, _extends({}, options, {
1139
- isFinal: options.isFinal ? index === handlers.length - 1 : false
1140
- })));
1141
- }, []);
1142
- }
1143
-
1144
- };
1145
-
1146
- __decorate([Inject(), __metadata("design:type", InjectorService)], PlatformRouter.prototype, "injector", void 0);
1147
-
1148
- PlatformRouter = PlatformRouter_1 = __decorate([Injectable({
1149
- scope: ProviderScope.INSTANCE
1150
- }), __metadata("design:paramtypes", [PlatformHandler])], PlatformRouter);
1151
-
1152
- var PlatformApplication_1;
1153
- /**
1154
- * `PlatformApplication` is used to provide all routes collected by annotation `@Controller`.
1155
- *
1156
- * @platform
1157
- */
1158
-
1159
- let PlatformApplication = PlatformApplication_1 = class PlatformApplication extends PlatformRouter {
1160
- constructor(platformHandler) {
1161
- super(platformHandler);
1162
- this.rawApp = this.raw = PlatformApplication_1.createRawApp();
1163
- }
1164
-
1165
- static createRawApp() {
1166
- return createFakeRawDriver();
1167
- }
1168
-
1169
- getApp() {
1170
- return this.raw;
1171
- }
1172
-
1173
- };
1174
- PlatformApplication = PlatformApplication_1 = __decorate([Injectable({
1175
- scope: ProviderScope.SINGLETON
1176
- }), __metadata("design:paramtypes", [PlatformHandler])], PlatformApplication);
1177
-
1178
- var PlatformMulterMiddleware_1;
1179
- /**
1180
- * @middleware
1181
- */
1182
-
1183
- let PlatformMulterMiddleware = PlatformMulterMiddleware_1 = class PlatformMulterMiddleware {
1184
- async use(ctx) {
1185
- try {
1186
- const {
1187
- fields,
1188
- options = {}
1189
- } = ctx.endpoint.get(PlatformMulterMiddleware_1);
1190
-
1191
- const settings = _extends({}, this.settings, options);
1192
- /* istanbul ignore next */
1193
-
1194
-
1195
- if (settings.storage) {
1196
- delete settings.dest;
1197
- }
1198
-
1199
- const middleware = this.app.multer(settings).fields(this.getFields({
1200
- fields
1201
- }));
1202
- return await middleware(ctx.getRequest(), ctx.getResponse());
1203
- } catch (er) {
1204
- throw er.code ? new Exception(er.code, `${er.message} ${er.field || ""}`.trim()) : er;
1205
- }
1206
- }
1207
-
1208
- getFields(conf) {
1209
- return conf.fields.map(({
1210
- name,
1211
- maxCount
1212
- }) => ({
1213
- name,
1214
- maxCount
1215
- }));
1216
- }
1217
-
1218
- };
1219
-
1220
- __decorate([Constant("multer", {}), __metadata("design:type", Object)], PlatformMulterMiddleware.prototype, "settings", void 0);
1221
-
1222
- __decorate([Inject(), __metadata("design:type", PlatformApplication)], PlatformMulterMiddleware.prototype, "app", void 0);
1223
-
1224
- __decorate([__param(0, Context()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise)], PlatformMulterMiddleware.prototype, "use", null);
1225
-
1226
- PlatformMulterMiddleware = PlatformMulterMiddleware_1 = __decorate([Middleware()], PlatformMulterMiddleware);
1227
-
1228
- /**
1229
- * @deprecated Since 2020-11-30. Use PlatformAcceptMimesMiddleware.
1230
- * @ignore
1231
- */
1232
-
1233
- let GlobalAcceptMimesMiddleware = class GlobalAcceptMimesMiddleware {
1234
- use(ctx) {
1235
- return;
1236
- }
1237
-
1238
- };
1239
-
1240
- __decorate([__param(0, Context()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0)], GlobalAcceptMimesMiddleware.prototype, "use", null);
1241
-
1242
- GlobalAcceptMimesMiddleware = __decorate([Middleware()], GlobalAcceptMimesMiddleware);
1243
-
1244
- /**
1245
- * @middleware
1246
- * @platform
1247
- */
1248
-
1249
- let PlatformAcceptMimesMiddleware = class PlatformAcceptMimesMiddleware {
1250
- use(ctx) {
1251
- const {
1252
- endpoint,
1253
- request
1254
- } = ctx;
1255
- const mimes = uniq(((endpoint == null ? void 0 : endpoint.get("acceptMimes")) || []).concat(this.acceptMimes));
1256
-
1257
- if (mimes.length && !request.accepts(mimes)) {
1258
- throw new NotAcceptable(mimes.join(", "));
1259
- }
1260
- }
1261
-
1262
- };
1263
-
1264
- __decorate([Constant("acceptMimes", []), __metadata("design:type", Array)], PlatformAcceptMimesMiddleware.prototype, "acceptMimes", void 0);
1265
-
1266
- __decorate([__param(0, Context()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0)], PlatformAcceptMimesMiddleware.prototype, "use", null);
1267
-
1268
- PlatformAcceptMimesMiddleware = __decorate([Middleware()], PlatformAcceptMimesMiddleware);
1269
-
1270
- /**
1271
- * @middleware
1272
- * @deprecated Since 2020-11-30. Use PlatformAcceptMimesMiddleware.
1273
- * @ignore
1274
- */
1275
-
1276
- let AcceptMimesMiddleware = class AcceptMimesMiddleware {
1277
- use(ctx) {
1278
- return;
1279
- }
1280
-
1281
- };
1282
-
1283
- __decorate([__param(0, Context()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0)], AcceptMimesMiddleware.prototype, "use", null);
1284
-
1285
- AcceptMimesMiddleware = __decorate([Middleware()], AcceptMimesMiddleware);
1286
-
1287
- const ROUTER_OPTIONS = Symbol.for("ROUTER_OPTIONS");
1288
-
1289
- let AUTO_INC = 0;
1290
- class ControllerProvider extends Provider {
1291
- constructor(provide, options = {}) {
1292
- super(provide, options);
1293
- this.type = ProviderType.CONTROLLER;
1294
- this.tokenRouter = `${this.name}_ROUTER_${AUTO_INC++}`;
1295
- }
1296
- /**
1297
- *
1298
- */
1299
-
1300
-
1301
- get routerOptions() {
1302
- return this.store.get(ROUTER_OPTIONS) || {};
1303
- }
1304
- /**
1305
- *
1306
- * @param value
1307
- */
1308
-
1309
-
1310
- set routerOptions(value) {
1311
- this.store.set(ROUTER_OPTIONS, value);
1312
- }
1313
- /**
1314
- *
1315
- * @returns {any[]}
1316
- */
1317
-
1318
-
1319
- get middlewares() {
1320
- return Object.assign({
1321
- use: [],
1322
- useAfter: [],
1323
- useBefore: []
1324
- }, this.store.get("middlewares", {}));
1325
- }
1326
- /**
1327
- *
1328
- * @param middlewares
1329
- */
1330
-
1331
-
1332
- set middlewares(middlewares) {
1333
- const mdlwrs = this.middlewares;
1334
-
1335
- const concat = (key, a, b) => a[key] = a[key].concat(b[key]);
1336
-
1337
- Object.keys(middlewares).forEach(key => {
1338
- concat(key, mdlwrs, middlewares);
1339
- });
1340
- this.store.set("middlewares", mdlwrs);
1341
- }
1342
-
1343
- }
1344
-
1345
- /**
1346
- * Create Ts.ED context handler
1347
- * @param fn
1348
- * @ignore
1349
- */
1350
-
1351
- function useCtxHandler(fn) {
1352
- fn.type = HandlerType.CTX_FN;
1353
- return fn;
1354
- }
1355
-
1356
- let PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
1357
- get(provider, operationRoute) {
1358
- const {
1359
- endpoint
1360
- } = operationRoute;
1361
- const {
1362
- beforeMiddlewares,
1363
- middlewares: mldwrs,
1364
- afterMiddlewares
1365
- } = endpoint;
1366
- const {
1367
- middlewares: {
1368
- use,
1369
- useAfter
1370
- }
1371
- } = provider;
1372
- const hasFiles = [...operationRoute.endpoint.children.values()].find(item => item.paramType === ParamTypes.FILES);
1373
- return [].concat(useCtxHandler(bindEndpointMiddleware(endpoint))).concat(PlatformAcceptMimesMiddleware).concat(hasFiles && PlatformMulterMiddleware).concat(beforeMiddlewares) // Endpoint before-middlewares
1374
- .concat(use) // Controller use-middlewares
1375
- .concat(mldwrs) // Endpoint middlewares
1376
- .concat(endpoint) // Endpoint metadata
1377
- .concat(afterMiddlewares) // Endpoint after-middlewares
1378
- .concat(useAfter) // Controller after middlewares (equivalent to afterEach)
1379
- .filter(item => !!item);
1380
- }
1381
-
1382
- };
1383
- PlatformMiddlewaresChain = __decorate([Injectable()], PlatformMiddlewaresChain);
1384
-
1385
- GlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {
1386
- onInvoke(provider, locals, {
1387
- injector
1388
- }) {
1389
- const router = createRouter(injector, provider);
1390
- locals.set(PlatformRouter, router);
1391
- }
1392
-
1393
- });
1394
- /**
1395
- * @ignore
1396
- */
1397
-
1398
- function formatMethod(method) {
1399
- return (method === OperationMethods.CUSTOM ? "use" : method || "use").toLowerCase();
1400
- }
1401
- /**
1402
- * @ignore
1403
- */
1404
-
1405
-
1406
- function getRouter(injector, provider) {
1407
- return injector.get(provider.tokenRouter);
1408
- }
1409
- /**
1410
- * @ignore
1411
- */
1412
-
1413
- function createRouter(injector, provider) {
1414
- const token = provider.tokenRouter;
1415
-
1416
- if (injector.has(token)) {
1417
- return getRouter(injector, provider);
1418
- }
1419
-
1420
- const router = PlatformRouter.create(injector, provider.routerOptions);
1421
- return injector.add(token, {
1422
- useValue: router
1423
- }).invoke(token);
1424
- }
1425
- /**
1426
- * @ignore
1427
- * @param injector
1428
- * @param provider
1429
- */
1430
-
1431
- function buildRouter(injector, provider) {
1432
- const {
1433
- middlewares: {
1434
- useBefore
1435
- },
1436
- children
1437
- } = provider; // Controller lifecycle
1438
-
1439
- const router = createRouter(injector, provider);
1440
-
1441
- if (!router.isBuilt) {
1442
- router.isBuilt = true;
1443
- const platformMiddlewaresChain = injector.get(PlatformMiddlewaresChain);
1444
- useBefore // Controller before-middleware
1445
- .filter(o => typeof o === "function").forEach(middleware => {
1446
- router.use(middleware);
1447
- }); // build all endpoints and his middlewares
1448
-
1449
- getOperationsRoutes(provider.token).forEach(operationRoute => {
1450
- const handlers = platformMiddlewaresChain == null ? void 0 : platformMiddlewaresChain.get(provider, operationRoute);
1451
- router.addRoute({
1452
- handlers,
1453
- token: operationRoute.token,
1454
- method: formatMethod(operationRoute.method),
1455
- path: operationRoute.path,
1456
- isFinal: operationRoute.isFinal
1457
- });
1458
- }); // build children controllers
1459
-
1460
- children.forEach(child => {
1461
- const childProvider = injector.getProvider(child);
1462
- /* istanbul ignore next */
1463
-
1464
- if (!childProvider) {
1465
- throw new Error("Controller component not found in the ControllerRegistry");
1466
- }
1467
-
1468
- router.use(childProvider.path, buildRouter(injector, childProvider));
1469
- });
1470
- }
1471
-
1472
- return router;
1473
- }
1474
-
1475
- /**
1476
- * Platform Request abstraction layer.
1477
- * @platform
1478
- */
1479
-
1480
- let PlatformRequest = class PlatformRequest {
1481
- constructor({
1482
- request
1483
- }) {
1484
- this.raw = request;
1485
- }
1486
-
1487
- get secure() {
1488
- return this.raw.secure;
1489
- }
1490
-
1491
- get host() {
1492
- return this.get("host");
1493
- }
1494
-
1495
- get protocol() {
1496
- return this.raw.protocol;
1497
- }
1498
- /**
1499
- * Get the url of the request.
1500
- *
1501
- * Is equivalent of `express.response.originalUrl || express.response.url`.
1502
- */
1503
-
1504
-
1505
- get url() {
1506
- return this.raw.originalUrl || this.raw.url;
1507
- }
1508
-
1509
- get headers() {
1510
- return this.raw.headers;
1511
- }
1512
-
1513
- get method() {
1514
- return this.raw.method;
1515
- }
1516
- /**
1517
- * Contains key-value pairs of data submitted in the request body. By default, it is `undefined`, and is populated when you use
1518
- * `body-parsing` middleware such as `express.json()` or `express.urlencoded()`.
1519
- */
1520
-
1521
-
1522
- get body() {
1523
- return this.raw.body;
1524
- }
1525
-
1526
- get rawBody() {
1527
- return this.raw.rawBody || this.raw.body;
1528
- }
1529
- /**
1530
- * When using `cookie-parser` middleware, this property is an object that contains cookies sent by the request.
1531
- * If the request contains no cookies, it defaults to `{}`.
1532
- */
1533
-
1534
-
1535
- get cookies() {
1536
- return this.raw.cookies;
1537
- }
1538
- /**
1539
- * This property is an object containing properties mapped to the named route `parameters`.
1540
- * For example, if you have the route `/user/:name`, then the `name` property is available as `req.params.name`.
1541
- * This object defaults to `{}`.
1542
- */
1543
-
1544
-
1545
- get params() {
1546
- return this.raw.params;
1547
- }
1548
- /**
1549
- * This property is an object containing a property for each query string parameter in the route.
1550
- * When query parser is set to disabled, it is an empty object `{}`, otherwise it is the result of the configured query parser.
1551
- */
1552
-
1553
-
1554
- get query() {
1555
- return this.raw.query;
1556
- }
1557
- /**
1558
- * This property is an object containing a property for each session attributes set by any code.
1559
- * It require to install a middleware like express-session to work.
1560
- */
1561
-
1562
-
1563
- get session() {
1564
- return this.raw.session;
1565
- }
1566
-
1567
- get files() {
1568
- return this.raw.files;
1569
- }
1570
- /**
1571
- * Return the original request framework instance
1572
- */
1573
-
1574
-
1575
- get request() {
1576
- return this.getRequest();
1577
- }
1578
- /**
1579
- * Return the original request node.js instance
1580
- */
1581
-
1582
-
1583
- get req() {
1584
- return this.getReq();
1585
- }
1586
- /**
1587
- * Returns the HTTP request header specified by field. The match is case-insensitive.
1588
- *
1589
- * ```typescript
1590
- * request.get('Content-Type') // => "text/plain"
1591
- * ```
1592
- *
1593
- * @param name
1594
- */
1595
-
1596
-
1597
- get(name) {
1598
- return this.raw.get(name);
1599
- }
1600
-
1601
- accepts(mime) {
1602
- // @ts-ignore
1603
- return this.raw.accepts(mime);
1604
- }
1605
-
1606
- isAborted() {
1607
- return this.raw.aborted;
1608
- }
1609
-
1610
- destroy() {
1611
- // @ts-ignore
1612
- delete this.raw; // @ts-ignore
1613
-
1614
- delete this.response;
1615
- }
1616
- /**
1617
- * Return the Framework response object (express, koa, etc...)
1618
- */
1619
-
1620
-
1621
- getRequest() {
1622
- return this.raw;
1623
- }
1624
- /**
1625
- * Return the Node.js response object
1626
- */
1627
-
1628
-
1629
- getReq() {
1630
- return this.raw;
1631
- }
1632
-
1633
- };
1634
- PlatformRequest = __decorate([Injectable(), Scope(ProviderScope.INSTANCE), __metadata("design:paramtypes", [Object])], PlatformRequest);
1635
-
1636
- var PlatformResponse_1;
1637
-
1638
- const onFinished = require("on-finished");
1639
- /**
1640
- * Platform Response abstraction layer.
1641
- * @platform
1642
- */
1643
-
1644
-
1645
- let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
1646
- constructor({
1647
- response
1648
- }) {
1649
- this.raw = response;
1650
- }
1651
- /**
1652
- * Get the current statusCode
1653
- */
1654
-
1655
-
1656
- get statusCode() {
1657
- return this.raw.statusCode;
1658
- }
1659
- /**
1660
- * 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.
1661
- *
1662
- * This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.
1663
- */
1664
-
1665
-
1666
- get locals() {
1667
- return this.raw.locals;
1668
- }
1669
- /**
1670
- * Return the original response framework instance
1671
- */
1672
-
1673
-
1674
- get response() {
1675
- return this.getResponse();
1676
- }
1677
- /**
1678
- * Return the original response node.js instance
1679
- */
1680
-
1681
-
1682
- get res() {
1683
- return this.getRes();
1684
- }
1685
-
1686
- static onFinished(res, cb) {
1687
- onFinished(res, cb);
1688
- }
1689
- /**
1690
- * Returns the HTTP response header specified by field. The match is case-insensitive.
1691
- *
1692
- * ```typescript
1693
- * response.get('Content-Type') // => "text/plain"
1694
- * ```
1695
- *
1696
- * @param name
1697
- */
1698
-
1699
-
1700
- get(name) {
1701
- return this.raw.get(name);
1702
- }
1703
-
1704
- getHeaders() {
1705
- return this.raw.getHeaders();
1706
- }
1707
- /**
1708
- * Return the Framework response object (express, koa, etc...)
1709
- */
1710
-
1711
-
1712
- getResponse() {
1713
- return this.raw;
1714
- }
1715
- /**
1716
- * Return the Node.js response object
1717
- */
1718
-
1719
-
1720
- getRes() {
1721
- return this.raw;
1722
- }
1723
-
1724
- hasStatus() {
1725
- return this.statusCode !== 200;
1726
- }
1727
- /**
1728
- * Sets the HTTP status for the response.
1729
- *
1730
- * @param status
1731
- */
1732
-
1733
-
1734
- status(status) {
1735
- this.raw.status(status);
1736
- return this;
1737
- }
1738
- /**
1739
- * Set header `field` to `val`, or pass
1740
- * an object of header fields.
1741
- *
1742
- * Examples:
1743
- * ```typescript
1744
- * response.setHeaders({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
1745
- * ```
1746
- *
1747
- * Aliased as `res.header()`.
1748
- */
1749
-
1750
-
1751
- setHeaders(headers) {
1752
- // apply headers
1753
- Object.entries(headers).forEach(([key, item]) => {
1754
- this.setHeader(key, item);
1755
- });
1756
- return this;
1757
- }
1758
-
1759
- setHeader(key, item) {
1760
- if (key.toLowerCase() === "location") {
1761
- return this.location(String(item));
1762
- }
1763
-
1764
- this.raw.set(key, item);
1765
- return this;
1766
- }
1767
- /**
1768
- * Set `Content-Type` response header with `type` through `mime.lookup()`
1769
- * when it does not contain "/", or set the Content-Type to `type` otherwise.
1770
- *
1771
- * Examples:
1772
- *
1773
- * res.type('.html');
1774
- * res.type('html');
1775
- * res.type('json');
1776
- * res.type('application/json');
1777
- * res.type('png');
1778
- */
1779
-
1780
-
1781
- contentType(contentType) {
1782
- this.raw.contentType(contentType);
1783
- return this;
1784
- }
1785
-
1786
- contentLength(length) {
1787
- this.setHeader("Content-Length", length);
1788
- return this;
1789
- }
1790
-
1791
- getContentLength() {
1792
- if (this.get("Content-Length")) {
1793
- return parseInt(this.get("Content-Length"), 10) || 0;
1794
- }
1795
- }
1796
-
1797
- getContentType() {
1798
- return (this.get("Content-Type") || "").split(";")[0];
1799
- }
1800
- /**
1801
- * Sets the HTTP response Content-Disposition header field to “attachment”.
1802
- * 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.
1803
- *
1804
- * ```typescript
1805
- * res.attachment()
1806
- * // Content-Disposition: attachment
1807
- *
1808
- * res.attachment('path/to/logo.png')
1809
- * // Content-Disposition: attachment; filename="logo.png"
1810
- * // Content-Type: image/png
1811
- * ```
1812
- *
1813
- * @param filename
1814
- */
1815
-
1816
-
1817
- attachment(filename) {
1818
- this.raw.attachment(filename);
1819
- return this;
1820
- }
1821
- /**
1822
- * 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).
1823
- * If not specified, status defaults to `302 Found`.
1824
- *
1825
- * @param status
1826
- * @param url
1827
- */
1828
-
1829
-
1830
- redirect(status, url) {
1831
- this.raw.redirect(status, url);
1832
- return this;
1833
- }
1834
- /**
1835
- * Sets the response Location HTTP header to the specified path parameter.
1836
- *
1837
- * @param location
1838
- */
1839
-
1840
-
1841
- location(location) {
1842
- this.raw.location(location);
1843
- return this;
1844
- }
1845
- /**
1846
- * Stream the given data.
1847
- *
1848
- * @param data
1849
- */
1850
-
1851
-
1852
- stream(data) {
1853
- data.pipe(this.raw);
1854
- return this;
1855
- }
1856
- /**
1857
- * Renders a view and sends the rendered HTML string to the client.
1858
- *
1859
- * @param path
1860
- * @param options
1861
- */
1862
-
1863
-
1864
- async render(path, options = {}) {
1865
- return this.platformViews.render(path, _extends({}, this.locals, options));
1866
- }
1867
- /**
1868
- * Send any data to your consumer.
1869
- *
1870
- * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.
1871
- * It choose the better way to send the data.
1872
- *
1873
- * @param data
1874
- */
1875
-
1876
-
1877
- body(data) {
1878
- this.data = data;
1879
-
1880
- if (data === undefined) {
1881
- this.raw.send();
1882
- return this;
1883
- }
1884
-
1885
- if (isStream(data)) {
1886
- this.stream(data);
1887
- return this;
1888
- }
1889
-
1890
- if (Buffer.isBuffer(data)) {
1891
- if (!this.getContentType()) {
1892
- this.contentType("application/octet-stream");
1893
- }
1894
-
1895
- this.contentLength(data.length);
1896
- this.raw.send(data);
1897
- return this;
1898
- }
1899
-
1900
- if (isBoolean(data) || isNumber(data) || isString(data) || data === null) {
1901
- this.raw.send(data);
1902
- return this;
1903
- }
1904
-
1905
- this.raw.json(data);
1906
- return this;
1907
- }
1908
-
1909
- getBody() {
1910
- return this.data;
1911
- }
1912
- /**
1913
- * Add a listener to handler the end of the request/response.
1914
- * @param cb
1915
- */
1916
-
1917
-
1918
- onEnd(cb) {
1919
- PlatformResponse_1.onFinished(this.getRes(), cb);
1920
- return this;
1921
- }
1922
-
1923
- isDone() {
1924
- if (!this.raw) {
1925
- return true;
1926
- }
1927
-
1928
- const res = this.getRes();
1929
- return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);
1930
- }
1931
-
1932
- destroy() {
1933
- // @ts-ignore
1934
- delete this.raw;
1935
- delete this.data; // @ts-ignore
1936
-
1937
- delete this.request;
1938
- }
1939
-
1940
- isHeadersSent() {
1941
- return this.getRes().headersSent;
1942
- }
1943
-
1944
- };
1945
- PlatformResponse = PlatformResponse_1 = __decorate([Injectable(), Scope(ProviderScope.INSTANCE), __metadata("design:paramtypes", [Object])], PlatformResponse);
1946
-
1947
- const _excluded$2 = ["event", "endpoint", "ignoreUrlPatterns", "ResponseKlass", "RequestKlass"];
1948
- class PlatformContext extends DIContext {
1949
- constructor(_ref) {
1950
- let {
1951
- event,
1952
- endpoint,
1953
- ignoreUrlPatterns = [],
1954
- ResponseKlass = PlatformResponse,
1955
- RequestKlass = PlatformRequest
1956
- } = _ref,
1957
- options = _objectWithoutPropertiesLoose(_ref, _excluded$2);
1958
-
1959
- super(_extends({}, options, {
1960
- ignoreLog: () => {
1961
- return this.ignoreUrlPatterns.find(reg => !!this.url.match(reg));
1962
- }
1963
- }));
1964
- this.ignoreUrlPatterns = [];
1965
- endpoint && (this.endpoint = endpoint);
1966
- this.ignoreUrlPatterns = ignoreUrlPatterns.map(pattern => typeof pattern === "string" ? new RegExp(pattern, "gi") : pattern);
1967
- this.response = new ResponseKlass(event);
1968
- this.request = new RequestKlass(event);
1969
- this.response.request = this.request;
1970
- this.request.response = this.response;
1971
- this.request.request.$ctx = this;
1972
- this.request.request.id = this.id;
1973
- this.logger.url = this.url;
1974
- this.container.set(PlatformResponse, this.response);
1975
- this.container.set(PlatformRequest, this.request);
1976
- this.container.set(PlatformContext, this);
1977
- this.response.setHeader("x-request-id", this.id);
1978
- }
1979
-
1980
- get url() {
1981
- return this.request.url;
1982
- }
1983
-
1984
- get app() {
1985
- return this.injector.get(PlatformApplication);
1986
- }
1987
-
1988
- async destroy() {
1989
- var _this$request, _this$request$request;
1990
-
1991
- await super.destroy();
1992
- (_this$request = this.request) == null ? true : (_this$request$request = _this$request.request) == null ? true : delete _this$request$request.$ctx;
1993
- this.response.destroy();
1994
- this.request.destroy(); // @ts-ignore
1995
-
1996
- delete this.endpoint; // @ts-ignore
1997
-
1998
- delete this.response; // @ts-ignore
1999
-
2000
- delete this.request;
2001
- }
2002
-
2003
- isDone() {
2004
- return !this.request || !this.response;
2005
- }
2006
- /**
2007
- * Return the framework request instance (Express, Koa, etc...)
2008
- */
2009
-
2010
-
2011
- getRequest() {
2012
- return this.request.getRequest();
2013
- }
2014
- /**
2015
- * Return the framework response instance (Express, Koa, etc...)
2016
- */
2017
-
2018
-
2019
- getResponse() {
2020
- return this.response.getResponse();
2021
- }
2022
- /**
2023
- * Get Node.js request
2024
- */
2025
-
2026
-
2027
- getReq() {
2028
- return this.request.getReq();
2029
- }
2030
- /**
2031
- * Get Node.js response
2032
- */
2033
-
2034
-
2035
- getRes() {
2036
- return this.response.getRes();
2037
- }
2038
- /**
2039
- * Return the original application instance.
2040
- */
2041
-
2042
-
2043
- getApp() {
2044
- return this.app.getApp();
2045
- }
2046
-
2047
- }
2048
-
2049
- class PlatformRouteDetails extends JsonOperationRoute {
2050
- constructor(options = {}) {
2051
- super(options);
2052
- this.rawBody = !!this.endpoint.parameters.find(param => param.paramType === ParamTypes.RAW_BODY);
2053
- }
2054
-
2055
- toJSON() {
2056
- return {
2057
- method: this.method,
2058
- name: this.name,
2059
- url: this.url,
2060
- className: this.className,
2061
- methodClassName: this.methodClassName,
2062
- parameters: this.parameters,
2063
- rawBody: this.rawBody
2064
- };
2065
- }
2066
-
2067
- }
2068
-
2069
- /**
2070
- * @deprecated Since 2020-11-11. Use getProperties from @tsed/schema
2071
- */
2072
-
2073
- let PropertyMetadata = class PropertyMetadata extends JsonPropertyStore {
2074
- /**
2075
- * @deprecated Since 2020-11-11. Use getProperties from @tsed/schema
2076
- */
2077
- static get(target, propertyKey) {
2078
- return JsonEntityStore.from(prototypeOf(target), propertyKey);
2079
- }
2080
- /**
2081
- * @deprecated Since 2020-11-11. Use getProperties from @tsed/schema
2082
- */
2083
-
2084
-
2085
- static getProperties(target, options = {}) {
2086
- return getProperties(target, options);
2087
- }
2088
-
2089
- };
2090
- PropertyMetadata = __decorate([JsonEntityComponent(DecoratorTypes.PROP)], PropertyMetadata);
2091
-
2092
- /**
2093
- * `Platform` is used to provide all routes collected by annotation `@Controller`.
2094
- *
2095
- * @platform
2096
- */
2097
-
2098
- let Platform = class Platform {
2099
- constructor(injector, platformApplication) {
2100
- this.injector = injector;
2101
- this.platformApplication = platformApplication;
2102
- this._routes = [];
2103
- this._controllers = [];
2104
- this.createRouters();
2105
- }
2106
-
2107
- get app() {
2108
- return this.platformApplication;
2109
- }
2110
-
2111
- get routes() {
2112
- return this._routes;
2113
- }
2114
-
2115
- addRoutes(routes) {
2116
- routes.forEach(routeSettings => {
2117
- this.addRoute(routeSettings.route, routeSettings.token);
2118
- });
2119
- }
2120
-
2121
- addRoute(basePath, token) {
2122
- const {
2123
- injector
2124
- } = this;
2125
- const provider = injector.getProvider(token);
2126
-
2127
- if (!provider || provider.hasParent()) {
2128
- return;
2129
- }
2130
-
2131
- const ctrlPath = concatPath(basePath, JsonEntityStore.from(provider.token).path);
2132
-
2133
- this._controllers.push({
2134
- route: ctrlPath,
2135
- provider
2136
- });
2137
-
2138
- this.app.use(ctrlPath, ...[].concat(getRouter(injector, provider).callback()));
2139
- this._routes = getOperationsRoutes(provider.token, {
2140
- withChildren: true,
2141
- basePath
2142
- }).reduce((routes, operationRoute) => {
2143
- if (injector.hasProvider(token)) {
2144
- const provider = injector.getProvider(operationRoute.token);
2145
- const route = new PlatformRouteDetails(_extends({}, operationRoute, {
2146
- provider
2147
- }));
2148
- return routes.concat(route);
2149
- }
2150
-
2151
- return routes;
2152
- }, this._routes);
2153
- return this;
2154
- }
2155
- /**
2156
- * Get all routes built by TsExpressDecorators and mounted on Express application.
2157
- * @returns {PlatformRouteDetails[]}
2158
- */
2159
-
2160
-
2161
- getRoutes() {
2162
- return this._routes;
2163
- }
2164
-
2165
- getMountedControllers() {
2166
- return this._controllers;
2167
- }
2168
-
2169
- $onInit() {
2170
- this.buildControllers();
2171
- }
2172
- /**
2173
- * Create routers from the collected controllers.
2174
- * @private
2175
- */
2176
-
2177
-
2178
- createRouters() {
2179
- const {
2180
- injector
2181
- } = this;
2182
- injector.getProviders(ProviderType.CONTROLLER).map(provider => {
2183
- createRouter(injector, provider);
2184
- });
2185
- }
2186
- /**
2187
- * Create controllers from DI
2188
- * @private
2189
- */
2190
-
2191
-
2192
- buildControllers() {
2193
- const {
2194
- injector
2195
- } = this;
2196
- injector.getProviders(ProviderType.CONTROLLER).map(provider => {
2197
- if (!provider.hasParent()) {
2198
- return buildRouter(injector, provider);
2199
- }
2200
- });
2201
- }
2202
-
2203
- };
2204
- Platform = __decorate([Injectable({
2205
- scope: ProviderScope.SINGLETON,
2206
- imports: [PlatformMiddlewaresChain]
2207
- }), __metadata("design:paramtypes", [InjectorService, PlatformApplication])], Platform);
2208
-
2209
- $log.name = "TSED";
2210
- function createInjector(settings = {}) {
2211
- const injector = new InjectorService();
2212
- injector.addProvider(PlatformConfiguration);
2213
- injector.settings = injector.invoke(PlatformConfiguration);
2214
- injector.logger = $log;
2215
- injector.settings.set(settings);
2216
- setLoggerLevel(injector);
2217
- return injector;
2218
- }
2219
-
2220
- function createPlatformApplication(injector) {
2221
- injector.forkProvider(PlatformApplication);
2222
- }
2223
-
2224
- /**
2225
- * Inject the Http.Server instance.
2226
- *
2227
- * ### Example
2228
- *
2229
- * ```typescript
2230
- * import {HttpServer, Service} from "@tsed/common";
2231
- *
2232
- * @Service()
2233
- * export default class OtherService {
2234
- * constructor(@HttpServer httpServer: HttpServer) {}
2235
- * }
2236
- * ```
2237
- *
2238
- * > Note: TypeScript transform and store `HttpServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2239
- *
2240
- * @param {Type<any>} target
2241
- * @param {string} targetKey
2242
- * @param {TypedPropertyDescriptor<Function> | number} descriptor
2243
- * @returns {any}
2244
- * @decorator
2245
- */
2246
-
2247
- function HttpServer(target, targetKey, descriptor) {
2248
- return Inject(HttpServer)(target, targetKey, descriptor);
2249
- }
2250
-
2251
- function listenServer(http, settings) {
2252
- const {
2253
- address,
2254
- port
2255
- } = settings;
2256
- const promise = new Promise((resolve, reject) => {
2257
- http.on("listening", resolve);
2258
- http.on("error", reject);
2259
- }).then(() => {
2260
- const port = http.address().port;
2261
- return {
2262
- address: settings.address,
2263
- port
2264
- };
2265
- });
2266
- http.listen(port, address);
2267
- return promise;
2268
- }
2269
-
2270
- function createHttpServer(injector) {
2271
- injector.forkProvider(HttpServer);
2272
- }
2273
- registerProvider({
2274
- provide: HttpServer,
2275
- deps: [PlatformApplication],
2276
- scope: ProviderScope.SINGLETON,
2277
- global: true,
2278
-
2279
- useFactory(platformApplication) {
2280
- return Http.createServer(platformApplication.callback());
2281
- }
2282
-
2283
- });
2284
- async function listenHttpServer(injector) {
2285
- const {
2286
- settings
2287
- } = injector;
2288
- const server = injector.get(HttpServer);
2289
-
2290
- if (settings.httpPort !== false && server) {
2291
- const {
2292
- address,
2293
- port
2294
- } = settings.getHttpPort();
2295
- injector.logger.debug(`Start server on http://${address}:${port}`);
2296
- const options = await listenServer(server, {
2297
- address,
2298
- port
2299
- });
2300
- settings.setHttpPort(options);
2301
- injector.logger.info(`Listen server on http://${options.address}:${options.port}`);
2302
- }
2303
- }
2304
-
2305
- /**
2306
- * Inject the Https.Server instance.
2307
- *
2308
- * ### Example
2309
- *
2310
- * ```typescript
2311
- * import {HttpsServer, Service} from "@tsed/common";
2312
- *
2313
- * @Service()
2314
- * export default class OtherService {
2315
- * constructor(@HttpsServer httpServer: HttpServer) {}
2316
- * }
2317
- * ```
2318
- *
2319
- * > Note: TypeScript transform and store `HttpsServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2320
- *
2321
- * @param {Type<any>} target
2322
- * @param {string} targetKey
2323
- * @param {TypedPropertyDescriptor<Function> | number} descriptor
2324
- * @returns {any}
2325
- * @decorator
2326
- */
2327
-
2328
- function HttpsServer(target, targetKey, descriptor) {
2329
- return Inject(HttpsServer)(target, targetKey, descriptor);
2330
- }
2331
-
2332
- function createHttpsServer(injector) {
2333
- injector.forkProvider(HttpsServer);
2334
- }
2335
- registerProvider({
2336
- provide: HttpsServer,
2337
- deps: [PlatformApplication, Configuration],
2338
- scope: ProviderScope.SINGLETON,
2339
- global: true,
2340
-
2341
- useFactory(platformApplication, settings) {
2342
- const options = settings.httpsOptions;
2343
- return Https.createServer(options, platformApplication.callback());
2344
- }
2345
-
2346
- });
2347
- async function listenHttpsServer(injector) {
2348
- const {
2349
- settings
2350
- } = injector;
2351
- const server = injector.get(HttpsServer);
2352
-
2353
- if (settings.httpsPort !== false && server) {
2354
- const {
2355
- address,
2356
- port
2357
- } = settings.getHttpsPort();
2358
- injector.logger.debug(`Start server on https://${address}:${port}`);
2359
- const options = await listenServer(server, {
2360
- address,
2361
- port
2362
- });
2363
- settings.setHttpsPort(options);
2364
- injector.logger.info(`Listen server on https://${options.address}:${options.port}`);
2365
- }
2366
- }
2367
-
2368
- /**
2369
- * @ignore
2370
- * @deprecated User injector.load(container, module) instead
2371
- */
2372
-
2373
- async function loadInjector(injector, container = createContainer()) {
2374
- injector.bootstrap(container);
2375
- return injector.load(container);
2376
- }
2377
-
2378
- function printRoutes(routes) {
2379
- const mapColor = {
2380
- GET: "green",
2381
- POST: "yellow",
2382
- PUT: "blue",
2383
- DELETE: "red",
2384
- PATCH: "magenta",
2385
- ALL: "cyan"
2386
- };
2387
- const list = routes.map(route => {
2388
- const obj = route.toJSON();
2389
- const method = obj.method.toUpperCase();
2390
- obj.method = {
2391
- length: method.length,
2392
- toString: () => {
2393
- return colorize(method, mapColor[method]);
2394
- }
2395
- };
2396
- return obj;
2397
- });
2398
- const str = $log.drawTable(list, {
2399
- padding: 1,
2400
- header: {
2401
- method: "Method",
2402
- url: "Endpoint",
2403
- name: "Class method"
2404
- }
2405
- });
2406
- return "\n" + str.trim();
2407
- }
2408
-
2409
- const _excluded$1 = ["reqIdBuilder"];
2410
-
2411
- const uuidv4 = require("uuid").v4;
2412
-
2413
- const defaultReqIdBuilder = req => req.get("x-request-id") || uuidv4().replace(/-/gi, "");
2414
- /**
2415
- * Create the TsED context to wrap request, response, injector, etc...
2416
- * @param injector
2417
- * @ignore
2418
- */
2419
-
2420
-
2421
- function createContext(injector) {
2422
- var _injector$getProvider, _injector$getProvider2;
2423
-
2424
- const ResponseKlass = (_injector$getProvider = injector.getProvider(PlatformResponse)) == null ? void 0 : _injector$getProvider.useClass;
2425
- const RequestKlass = (_injector$getProvider2 = injector.getProvider(PlatformRequest)) == null ? void 0 : _injector$getProvider2.useClass;
2426
- const platformViews = injector.get(PlatformViews);
2427
-
2428
- const _ref = injector.settings.logger || {},
2429
- {
2430
- reqIdBuilder = defaultReqIdBuilder
2431
- } = _ref,
2432
- loggerOptions = _objectWithoutPropertiesLoose(_ref, _excluded$1);
2433
-
2434
- return async event => {
2435
- const ctx = new PlatformContext(_extends({
2436
- event,
2437
- id: reqIdBuilder(event.request),
2438
- logger: injector.logger
2439
- }, loggerOptions, {
2440
- injector,
2441
- ResponseKlass,
2442
- RequestKlass
2443
- }));
2444
- ctx.response.platformViews = platformViews;
2445
- ctx.response.onEnd(async () => {
2446
- await ctx.emit("$onResponse", ctx);
2447
- await ctx.destroy();
2448
- });
2449
- await ctx.emit("$onRequest", ctx);
2450
- return ctx;
2451
- };
2452
- }
2453
-
2454
- function mapOptions$1(options) {
2455
- const opts = typeof options === "string" ? {
2456
- root: options
2457
- } : options;
2458
- return _extends({}, opts, {
2459
- hook: getValue(opts, "hook", "$afterRoutesInit")
2460
- });
2461
- }
2462
-
2463
- function getStaticsOptions(statics) {
2464
- return Object.entries(statics || {}).reduce((statics, [path, items]) => {
2465
- [].concat(items).forEach(options => {
2466
- statics.push({
2467
- path,
2468
- options: mapOptions$1(options)
2469
- });
2470
- });
2471
- return statics;
2472
- }, []);
2473
- }
2474
-
2475
- function getConfiguration(configuration = {}, module = null) {
2476
- const store = module ? Store.from(module).get("configuration") || {} : {};
2477
- const env = configuration.env || store.mount || process.env.NODE_ENV || Env.DEV;
2478
-
2479
- const config = _extends({
2480
- exclude: ["**/*.spec.ts", "**/*.spec.js"],
2481
- componentsScan: ["${rootDir}/mvc/**/*.ts", "${rootDir}/services/**/*.ts", "${rootDir}/middlewares/**/*.ts"],
2482
- env,
2483
- httpPort: 8080,
2484
- httpsPort: false
2485
- }, store, configuration, {
2486
- scopes: _extends({
2487
- [ProviderType.CONTROLLER]: ProviderScope.SINGLETON
2488
- }, store.scopes, configuration.scopes),
2489
- mount: store.mount || configuration.mount ? deepMerge(store.mount || {}, configuration.mount || {}) : {
2490
- "/rest": "${rootDir}/controllers/**/*.ts"
2491
- },
2492
- logger: _extends({
2493
- debug: false,
2494
- level: env === Env.TEST ? "off" : "info",
2495
- logRequest: true
2496
- }, store.logger, configuration.logger, {
2497
- jsonIndentation: process.env.NODE_ENV === Env.PROD ? 0 : 2
2498
- })
2499
- });
2500
-
2501
- if (!configuration.disableComponentsScan && store.componentsScan && configuration.componentsScan) {
2502
- config.componentsScan = [...store.componentsScan, ...configuration.componentsScan];
2503
- }
2504
-
2505
- return config;
2506
- }
2507
-
2508
- const DEFAULT_PROVIDERS = [{
2509
- provide: PlatformHandler
2510
- }, {
2511
- provide: PlatformResponse
2512
- }, {
2513
- provide: PlatformRequest
2514
- }, {
2515
- provide: PlatformRouter
2516
- }, {
2517
- provide: PlatformApplication
2518
- }, {
2519
- provide: Platform
2520
- }];
2521
- /**
2522
- * @platform
2523
- */
2524
-
2525
- var _injector = /*#__PURE__*/_classPrivateFieldLooseKey("injector");
2526
-
2527
- var _rootModule = /*#__PURE__*/_classPrivateFieldLooseKey("rootModule");
2528
-
2529
- class PlatformBuilder {
2530
- constructor({
2531
- name,
2532
- providers,
2533
- settings,
2534
- module
2535
- }) {
2536
- Object.defineProperty(this, _injector, {
2537
- writable: true,
2538
- value: void 0
2539
- });
2540
- Object.defineProperty(this, _rootModule, {
2541
- writable: true,
2542
- value: void 0
2543
- });
2544
- this.name = "";
2545
- this.startedAt = new Date();
2546
- this.current = new Date();
2547
- this.name = name;
2548
- _classPrivateFieldLooseBase(this, _rootModule)[_rootModule] = module;
2549
- this.createInjector(module, providers, settings);
2550
- }
2551
-
2552
- get injector() {
2553
- return _classPrivateFieldLooseBase(this, _injector)[_injector];
2554
- }
2555
-
2556
- get rootModule() {
2557
- return _classPrivateFieldLooseBase(this, _injector)[_injector].get(_classPrivateFieldLooseBase(this, _rootModule)[_rootModule]);
2558
- }
2559
-
2560
- get app() {
2561
- return this.injector.get(PlatformApplication);
2562
- }
2563
-
2564
- get platform() {
2565
- return this.injector.get(Platform);
2566
- }
2567
- /**
2568
- * Return the settings configured by the decorator @@Configuration@@.
2569
- *
2570
- * ```typescript
2571
- * @Configuration({
2572
- * rootDir: Path.resolve(__dirname),
2573
- * port: 8000,
2574
- * httpsPort: 8080,
2575
- * mount: {
2576
- * "/rest": "${rootDir}/controllers/**\/*.js"
2577
- * }
2578
- * })
2579
- * export class Server {
2580
- * $onInit(){
2581
- * console.log(this.settings); // {rootDir, port, httpsPort,...}
2582
- * }
2583
- * }
2584
- * ```
2585
- *
2586
- * @returns {PlatformConfiguration}
2587
- */
2588
-
2589
-
2590
- get settings() {
2591
- return this.injector.settings;
2592
- }
2593
-
2594
- get logger() {
2595
- return this.injector.logger;
2596
- }
2597
-
2598
- get disableBootstrapLog() {
2599
- var _this$settings$logger;
2600
-
2601
- return (_this$settings$logger = this.settings.logger) == null ? void 0 : _this$settings$logger.disableBootstrapLog;
2602
- }
2603
-
2604
- static build(platformBuildClass, module, settings = {}) {
2605
- return new platformBuildClass({
2606
- name: nameOf(platformBuildClass).replace("Platform", "").toLowerCase(),
2607
- module,
2608
- settings,
2609
- providers: platformBuildClass.providers
2610
- });
2611
- }
2612
-
2613
- callback(req, res) {
2614
- if (req && res) {
2615
- return this.app.callback()(req, res);
2616
- }
2617
-
2618
- return this.app.callback();
2619
- }
2620
-
2621
- log(...data) {
2622
- return !this.disableBootstrapLog && this.logger.info(...data, this.diff());
2623
- }
2624
- /**
2625
- * Add classes to the components list
2626
- * @param classes
2627
- */
2628
-
2629
-
2630
- addComponents(classes) {
2631
- this.settings.componentsScan = this.settings.componentsScan.concat(classes);
2632
- return this;
2633
- }
2634
- /**
2635
- * Add classes decorated by @@Controller@@ to components container.
2636
- *
2637
- * ### Example
2638
- *
2639
- * ```typescript
2640
- * @Controller('/ctrl')
2641
- * class MyController{
2642
- * }
2643
- *
2644
- * platform.addControllers('/rest', [MyController])
2645
- * ```
2646
- *
2647
- * ::: tip
2648
- * If the MyController class isn't decorated, the class will be ignored.
2649
- * :::
2650
- *
2651
- * @param {string} endpoint
2652
- * @param {any[]} controllers
2653
- */
2654
-
2655
-
2656
- addControllers(endpoint, controllers) {
2657
- this.settings.mount[endpoint] = (this.settings.mount[endpoint] || []).concat(controllers);
2658
- }
2659
-
2660
- async runLifecycle() {
2661
- setLoggerLevel(this.injector);
2662
- await this.importProviders();
2663
- await this.loadInjector();
2664
- this.useContext();
2665
- this.useRouter();
2666
- await this.loadRoutes();
2667
- await this.logRoutes();
2668
- return this;
2669
- }
2670
-
2671
- async loadInjector() {
2672
- const {
2673
- injector
2674
- } = this;
2675
- this.log("Build providers");
2676
- const container = createContainer();
2677
- container.addProvider(_classPrivateFieldLooseBase(this, _rootModule)[_rootModule], {
2678
- type: "server:module",
2679
- scope: ProviderScope.SINGLETON
2680
- });
2681
- await injector.load(container);
2682
- this.log("Settings and injector loaded...");
2683
- await this.callHook("$afterInit");
2684
- }
2685
-
2686
- async listen() {
2687
- await this.callHook("$beforeListen");
2688
- await this.listenServers();
2689
- await this.callHook("$afterListen");
2690
- await this.ready();
2691
- }
2692
-
2693
- async stop() {
2694
- await this.callHook("$onDestroy");
2695
- return this.injector.destroy();
2696
- }
2697
-
2698
- async ready() {
2699
- const {
2700
- startedAt
2701
- } = this;
2702
- await this.callHook("$onReady");
2703
- await this.injector.emit("$onServerReady");
2704
- this.log(`Started in ${new Date().getTime() - startedAt.getTime()} ms`);
2705
- }
2706
-
2707
- async callHook(hook, ...args) {
2708
- const {
2709
- injector
2710
- } = this;
2711
-
2712
- if (!this.disableBootstrapLog) {
2713
- injector.logger.debug(`\x1B[1mCall hook ${hook}\x1B[22m`);
2714
- } // Load middlewares for the given hook
2715
-
2716
-
2717
- this.loadMiddlewaresFor(hook); // call hooks added by providers
2718
-
2719
- await injector.emit(hook, ...args);
2720
- }
2721
-
2722
- async loadStatics(hook) {
2723
- const statics = this.settings.get("statics");
2724
- getStaticsOptions(statics).forEach(({
2725
- path,
2726
- options
2727
- }) => {
2728
- if (options.hook === hook) {
2729
- this.platform.app.statics(path, options);
2730
- }
2731
- });
2732
- }
2733
-
2734
- useProvider(token, settings) {
2735
- this.injector.addProvider(token, settings);
2736
- return this;
2737
- }
2738
-
2739
- async bootstrap() {
2740
- return this.runLifecycle();
2741
- }
2742
-
2743
- diff() {
2744
- const ms = colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);
2745
- this.current = new Date();
2746
- return ms;
2747
- }
2748
-
2749
- async importProviders() {
2750
- this.injector.logger.debug("Scan components");
2751
- const providers = await importProviders(this.injector.settings, ["imports", "mount", "componentsScan"]);
2752
- const routes = providers.filter(provider => !!provider.route).map(({
2753
- route,
2754
- token
2755
- }) => ({
2756
- route,
2757
- token
2758
- }));
2759
- this.settings.set("routes", routes);
2760
- this.log("Providers loaded...");
2761
- }
2762
- /**
2763
- * Load middlewares from configuration for the given hook
2764
- * @param hook
2765
- * @protected
2766
- */
2767
-
2768
-
2769
- loadMiddlewaresFor(hook) {
2770
- return getMiddlewaresForHook(hook, this.settings, "$beforeRoutesInit").forEach(({
2771
- use
2772
- }) => {
2773
- this.app.use(use);
2774
- });
2775
- }
2776
-
2777
- useRouter() {
2778
- return this;
2779
- }
2780
-
2781
- useContext() {
2782
- return this;
2783
- }
2784
-
2785
- async listenServers() {
2786
- await Promise.all([listenHttpServer(this.injector), listenHttpsServer(this.injector)]);
2787
- }
2788
-
2789
- async logRoutes() {
2790
- var _this$settings$logger2;
2791
-
2792
- const {
2793
- logger,
2794
- platform
2795
- } = this;
2796
- this.log("Routes mounted...");
2797
-
2798
- if (!((_this$settings$logger2 = this.settings.logger) != null && _this$settings$logger2.disableRoutesSummary) && !this.disableBootstrapLog) {
2799
- logger.info(printRoutes(await this.injector.alterAsync("$logRoutes", platform.getRoutes())));
2800
- }
2801
- }
2802
-
2803
- async loadRoutes() {
2804
- var _this$settings$logger3, _this$settings$accept;
2805
-
2806
- // istanbul ignore next
2807
- if (((_this$settings$logger3 = this.settings.logger) == null ? void 0 : _this$settings$logger3.level) !== "off") {
2808
- const {
2809
- PlatformLogMiddleware
2810
- } = await import('@tsed/platform-log-middleware');
2811
- this.app.use(PlatformLogMiddleware);
2812
- }
2813
-
2814
- if ((_this$settings$accept = this.settings.acceptMimes) != null && _this$settings$accept.length) {
2815
- this.app.use(GlobalAcceptMimesMiddleware);
2816
- }
2817
-
2818
- this.log("Load routes");
2819
- await this.loadStatics("$beforeRoutesInit");
2820
- await this.callHook("$beforeRoutesInit");
2821
- const routes = this.injector.settings.get("routes");
2822
- this.platform.addRoutes(routes);
2823
- await this.callHook("$onRoutesInit");
2824
- await this.loadStatics("$afterRoutesInit");
2825
- await this.callHook("$afterRoutesInit");
2826
- }
2827
-
2828
- createInjector(module, providers, settings) {
2829
- const configuration = getConfiguration(settings, module);
2830
- configuration.PLATFORM_NAME = this.name;
2831
- _classPrivateFieldLooseBase(this, _injector)[_injector] = createInjector(configuration);
2832
- providers = [...DEFAULT_PROVIDERS, ...providers];
2833
- toMap(providers, "provide").forEach((provider, token) => {
2834
- this.injector.addProvider(token, provider);
2835
- });
2836
- createPlatformApplication(this.injector);
2837
- createHttpsServer(this.injector);
2838
- createHttpServer(this.injector);
2839
- this.log("Injector created...");
2840
- }
2841
-
2842
- }
2843
-
2844
- /**
2845
- * Define multer option for all MultipartFile
2846
- *
2847
- * ```typescript
2848
- * import {Controller, Post, PlatformMulterFile, MultipartFile, MulterOptions} from "@tsed/common";
2849
- *
2850
- * @Controller('/')
2851
- * class MyCtrl {
2852
- * @Post('/file')
2853
- * private uploadFile(@MultipartFile("file1") file: PlatformMulterFile) {
2854
- *
2855
- * }
2856
- *
2857
- * @Post('/file')
2858
- * @MulterOptions({dest: "/other-dir"})
2859
- * private uploadFile(@MultipartFile("file1") file: PlatformMulterFile) {
2860
- *
2861
- * }
2862
- *
2863
- * @Post('/file2')
2864
- * @MulterOptions({dest: "/other-dir"})
2865
- * private uploadFile(@MultipartFile("file1") file: PlatformMulterFile, @MultipartFile("file2") file2: PlatformMulterFile) {
2866
- *
2867
- * }
2868
- *
2869
- * @Post('/files')
2870
- * private uploadFile(@MultipartFile("file1") files: PlatformMulterFile[]) {
2871
- *
2872
- * }
2873
- * }
2874
- * ```
2875
- *
2876
- * See the tutorial on the [multer configuration](/tutorials/multer.md).
2877
- *
2878
- * @param {multer.Options} options
2879
- * @returns {(target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor}
2880
- * @decorator
2881
- * @multer
2882
- */
2883
-
2884
- function MulterOptions(options) {
2885
- return (target, propertyKey, descriptor) => {
2886
- StoreMerge(PlatformMulterMiddleware, {
2887
- options
2888
- })(target, propertyKey, descriptor);
2889
- return descriptor;
2890
- };
2891
- }
2892
-
2893
- /**
2894
- * Define file size limit.
2895
- *
2896
- * ```typescript
2897
- * import {Controller, Post} from "@tsed/common";
2898
- * import {MulterOptions, MultipartFile} from "@tsed/common";
2899
- * import {Multer} from "@types/multer";
2900
- *
2901
- * type MulterFile = Express.Multer.File;
2902
- *
2903
- * @Controller('/')
2904
- * class MyCtrl {
2905
- * @Post('/file2')
2906
- * @MulterFileSize(1024) // (Ko). Applied for all fields
2907
- * private uploadFile(@MultipartFile("file1") file: MulterFile, @MultipartFile("file2") file2: MulterFile) {
2908
- *
2909
- * }
2910
- * }
2911
- * ```
2912
- *
2913
- * > See the tutorial on the [multer configuration](/tutorials/multer.md).
2914
- * @param fileSize
2915
- * @returns {(target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor}
2916
- * @decorator
2917
- * @multer
2918
- */
2919
-
2920
- function MulterFileSize(fileSize) {
2921
- return MulterOptions({
2922
- limits: {
2923
- fileSize
2924
- }
2925
- });
2926
- }
2927
-
2928
- function mapOptions(name, maxCount) {
2929
- return {
2930
- fields: [{
2931
- name,
2932
- maxCount
2933
- }]
2934
- };
2935
- }
2936
- /**
2937
- * Define a parameter as Multipart file.
2938
- *
2939
- * ```typescript
2940
- * import {Controller, Post} from "@tsed/common";
2941
- * import {MulterOptions, MultipartFile} from "@tsed/common";
2942
- * import {Multer} from "@types/multer";
2943
- *
2944
- * type MulterFile = Express.Multer.File;
2945
- *
2946
- * @Controller('/')
2947
- * class MyCtrl {
2948
- * @Post('/file')
2949
- * private uploadFile(@MultipartFile("file1") file: MulterFile) {
2950
- *
2951
- * }
2952
- *
2953
- * @Post('/file')
2954
- * @MulterOptions({dest: "/other-dir"})
2955
- * private uploadFile(@MultipartFile("file1") file: MulterFile) {
2956
- *
2957
- * }
2958
- *
2959
- * @Post('/file2')
2960
- * @MulterOptions({dest: "/other-dir"})
2961
- * private uploadFile(@MultipartFile("file1") file: MulterFile, @MultipartFile("file2") file2: MulterFile) {
2962
- *
2963
- * }
2964
- *
2965
- * @Post('/files')
2966
- * private uploadFile(@MultipartFile("file1") files: MulterFile[]) {
2967
- *
2968
- * }
2969
- * }
2970
- * ```
2971
- *
2972
- * > See the tutorial on the [multer configuration](/tutorials/multer.md).
2973
- *
2974
- * @param name
2975
- * @param maxCount
2976
- * @returns Function
2977
- * @decorator
2978
- * @input
2979
- */
2980
-
2981
-
2982
- function MultipartFile(name, maxCount) {
2983
- return (...args) => {
2984
- const [target, propertyKey, index] = args;
2985
- const multiple = Metadata.getParamTypes(target, propertyKey)[index] === Array;
2986
- name = typeof name === "object" ? undefined : name;
2987
- const expression = [name, !multiple && "0"].filter(Boolean).join(".");
2988
- const decorators = useDecorators(useMethodDecorators(Returns(400).Description(`<File too long | Too many parts | Too many files | Field name too long | Field value too long | Too many fields | Unexpected field> [fieldName] Example: File too long file1`), Consumes("multipart/form-data"), StoreMerge(PlatformMulterMiddleware, mapOptions(name, maxCount))), UseParam({
2989
- paramType: ParamTypes.FILES,
2990
- dataPath: "$ctx.request.files",
2991
- expression,
2992
- useValidation: true
2993
- }));
2994
- decorators(...args);
2995
- };
2996
- }
2997
-
2998
- /**
2999
- * Set a mime list which are acceptable and checks if the specified content types are acceptable, based on the request’s Accept HTTP header field.
3000
- *
3001
- * ```typescript
3002
- * @Controller('/mypath')
3003
- * export class MyCtrl {
3004
- *
3005
- * @Get('/')
3006
- * @AcceptMime('application/json')
3007
- * public getResource(){}
3008
- * }
3009
- * ```
3010
- *
3011
- * @param mimes
3012
- * @decorator
3013
- * @operation
3014
- * @response
3015
- */
3016
-
3017
- function AcceptMime(...mimes) {
3018
- return useDecorators(Produces(...mimes), StoreSet("acceptMimes", mimes));
3019
- }
3020
-
3021
- /**
3022
- *
3023
- * @param fn
3024
- * @decorator
3025
- * @deprecated Deprecated since 2021-10-05. Use JsonEntityFn instead.
3026
- */
3027
-
3028
- function EndpointFn(fn) {
3029
- return JsonEntityFn(fn);
3030
- }
3031
-
3032
- /**
3033
- * Return the current response data. Prefer the @@Context@@ decorator to get or set data.
3034
- *
3035
- * @decorator
3036
- * @operation
3037
- * @input
3038
- * @deprecated Use `@Context() $ctx: Context` then $ctx.data.
3039
- */
3040
-
3041
- function ResponseData() {
3042
- return UseParam({
3043
- paramType: ParamTypes.$CTX,
3044
- dataPath: "$ctx.data"
3045
- });
3046
- }
3047
-
3048
- function getParamType$1(target, propertyKey, parameterIndex) {
3049
- const type = Metadata.getOwnParamTypes(target, propertyKey)[parameterIndex];
3050
-
3051
- if (isClass(type)) {
3052
- if (nameOf(type) === "PlatformResponse") {
3053
- return {
3054
- paramType: ParamTypes.PLATFORM_RESPONSE,
3055
- dataPath: "$ctx.response"
3056
- };
3057
- }
3058
-
3059
- if (type === ServerResponse) {
3060
- return {
3061
- paramType: ParamTypes.NODE_RESPONSE,
3062
- dataPath: "$ctx.response.res"
3063
- };
3064
- }
3065
- }
3066
-
3067
- return {
3068
- paramType: ParamTypes.RESPONSE,
3069
- dataPath: "$ctx.response.response"
3070
- };
3071
- }
3072
-
3073
- function Response() {
3074
- return Res();
3075
- }
3076
- function Res() {
3077
- return (target, propertyKey, parameterIndex) => {
3078
- const {
3079
- paramType,
3080
- dataPath
3081
- } = getParamType$1(target, propertyKey, parameterIndex);
3082
- UseParam({
3083
- paramType,
3084
- dataPath
3085
- })(target, propertyKey, parameterIndex);
3086
- };
3087
- }
3088
-
3089
- function getParamType(target, propertyKey, parameterIndex) {
3090
- const type = Metadata.getOwnParamTypes(target, propertyKey)[parameterIndex];
3091
-
3092
- if (isClass(type)) {
3093
- if (nameOf(type) === "PlatformRequest") {
3094
- return {
3095
- paramType: ParamTypes.PLATFORM_REQUEST,
3096
- dataPath: "$ctx.request"
3097
- };
3098
- }
3099
-
3100
- if (type === IncomingMessage) {
3101
- return {
3102
- paramType: ParamTypes.NODE_REQUEST,
3103
- dataPath: "$ctx.request.req"
3104
- };
3105
- }
3106
- }
3107
-
3108
- return {
3109
- paramType: ParamTypes.REQUEST,
3110
- dataPath: "$ctx.request.request"
3111
- };
3112
- }
3113
-
3114
- function Request(...args) {
3115
- // @ts-ignore
3116
- return Req(...args);
3117
- }
3118
- function Req(...args) {
3119
- const {
3120
- expression,
3121
- useType,
3122
- useConverter = false,
3123
- useValidation = false
3124
- } = mapParamsOptions(args);
3125
- return (target, propertyKey, parameterIndex) => {
3126
- const {
3127
- paramType,
3128
- dataPath
3129
- } = getParamType(target, propertyKey, parameterIndex);
3130
- UseParam({
3131
- paramType,
3132
- dataPath,
3133
- expression,
3134
- useType,
3135
- useConverter,
3136
- useValidation
3137
- })(target, propertyKey, parameterIndex);
3138
- };
3139
- }
3140
-
3141
- /**
3142
- * Get the Next function (for express application and middleware).
3143
- *
3144
- * @decorator
3145
- * @operation
3146
- * @input
3147
- */
3148
-
3149
- function Next() {
3150
- return UseParam({
3151
- paramType: ParamTypes.NEXT_FN,
3152
- dataPath: "next",
3153
- useConverter: false,
3154
- useValidation: false
3155
- });
3156
- }
3157
-
3158
- /**
3159
- * @returns {Function}
3160
- * @decorator
3161
- * @operation
3162
- * @input
3163
- */
3164
-
3165
- function Err() {
3166
- return UseParam({
3167
- paramType: ParamTypes.ERR,
3168
- dataPath: "err",
3169
- useValidation: false,
3170
- useConverter: false
3171
- });
3172
- }
3173
-
3174
- /**
3175
- * Get the current endpoint metadata.
3176
- * @decorator
3177
- * @operation
3178
- * @input
3179
- * @deprecated Use `@Context() $ctx: Context` then `$ctx.endpoint` instead.
3180
- */
3181
-
3182
- function EndpointInfo() {
3183
- return UseParam({
3184
- paramType: ParamTypes.$CTX,
3185
- dataPath: "$ctx.endpoint",
3186
- useConverter: false,
3187
- useValidation: false
3188
- });
3189
- }
3190
-
3191
- const _excluded = ["use", "collection"];
3192
-
3193
- /**
3194
- * @ignore
3195
- */
3196
- function mapReturnedResponse(_ref) {
3197
- let {
3198
- use,
3199
- collection
3200
- } = _ref,
3201
- options = _objectWithoutPropertiesLoose(_ref, _excluded);
3202
-
3203
- return _extends({}, options, {
3204
- type: options.type || use,
3205
- collectionType: options.collectionType || collection
3206
- });
3207
- }
3208
-
3209
- /**
3210
- * @platform
3211
- */
3212
-
3213
- class PlatformTest extends DITest {
3214
- static async create(options = {}) {
3215
- DITest.injector = PlatformTest.createInjector(getConfiguration(options, null));
3216
- const container = createContainer();
3217
- await DITest.injector.load(container);
3218
- }
3219
- /**
3220
- * Create a new injector with the right default services
3221
- */
3222
-
3223
-
3224
- static createInjector(settings = {}) {
3225
- return createInjector(DITest.configure(settings));
3226
- }
3227
- /**
3228
- * Load the server silently without listening port and configure it on test profile.
3229
- * @decorator
3230
- * @param mod
3231
- * @param settings
3232
- * @returns {Promise<void>}
3233
- */
3234
-
3235
-
3236
- static bootstrap(mod, settings = {}) {
3237
- return async function before() {
3238
- let instance;
3239
- const platform = settings.platform || PlatformTest.platformBuilder;
3240
- /* istanbul ignore next */
3241
-
3242
- if (!platform) {
3243
- throw new Error("Platform type is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?");
3244
- } // @ts-ignore
3245
-
3246
-
3247
- settings = DITest.configure(settings);
3248
- instance = await PlatformBuilder.build(platform, mod, settings).bootstrap();
3249
-
3250
- if (!settings.listen) {
3251
- await instance.callHook("$beforeListen");
3252
- await instance.callHook("$afterListen");
3253
- await instance.ready();
3254
- } else {
3255
- await instance.listen();
3256
- } // used by inject method
3257
-
3258
-
3259
- DITest.injector = instance.injector;
3260
- };
3261
- }
3262
- /**
3263
- * It injects services into the test function where you can alter, spy on, and manipulate them.
3264
- *
3265
- * The inject function has two parameters
3266
- *
3267
- * * an array of Service dependency injection tokens,
3268
- * * a test function whose parameters correspond exactly to each item in the injection token array.
3269
- *
3270
- * @param targets
3271
- * @param func
3272
- */
3273
-
3274
-
3275
- static inject(targets, func) {
3276
- return async function () {
3277
- if (!DITest.hasInjector()) {
3278
- await PlatformTest.create();
3279
- }
3280
-
3281
- const injector = DITest.injector;
3282
- const deps = [];
3283
-
3284
- for (const target of targets) {
3285
- deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));
3286
- }
3287
-
3288
- return await func(...deps);
3289
- };
3290
- }
3291
- /**
3292
- * Return the raw application (express or koa).
3293
- * Use this callback with SuperTest.
3294
- *
3295
- * ```typescript
3296
- * let request: SuperTest.SuperTest<SuperTest.Test>;
3297
- * beforeEach(PlatformTest.bootstrap(Server, {
3298
- * mount: {
3299
- * "/rest": [ProductsController]
3300
- * }
3301
- * }));
3302
- * beforeEach(() => {
3303
- * request = SuperTest(PlatformTest.callback());
3304
- * });
3305
- * ```
3306
- */
3307
-
3308
-
3309
- static callback() {
3310
- var _DITest$injector$get;
3311
-
3312
- return (_DITest$injector$get = DITest.injector.get(PlatformApplication)) == null ? void 0 : _DITest$injector$get.callback();
3313
- }
3314
-
3315
- static createRequest(options = {}) {
3316
- return _extends({
3317
- headers: {},
3318
-
3319
- get(key) {
3320
- return this.headers[key.toLowerCase()];
3321
- },
3322
-
3323
- accepts(mime) {
3324
- return require("accepts")(this).types([].concat(mime));
3325
- }
3326
-
3327
- }, options);
3328
- }
3329
-
3330
- static createResponse(options = {}) {
3331
- return _extends({
3332
- headers: {},
3333
- locals: {},
3334
- statusCode: 200,
3335
-
3336
- status(code) {
3337
- this.statusCode = code;
3338
- return this;
3339
- },
3340
-
3341
- contentType(content) {
3342
- this.set("content-type", content);
3343
- },
3344
-
3345
- contentLength(content) {
3346
- this.set("content-length", content);
3347
- },
3348
-
3349
- redirect(status, path) {
3350
- this.statusCode = status;
3351
- this.set("location", path);
3352
- },
3353
-
3354
- location(path) {
3355
- this.set("location", path);
3356
- },
3357
-
3358
- get(key) {
3359
- return this.headers[key.toLowerCase()];
3360
- },
3361
-
3362
- getHeaders() {
3363
- return this.headers;
3364
- },
3365
-
3366
- set(key, value) {
3367
- this.headers[key.toLowerCase()] = value;
3368
- return this;
3369
- },
3370
-
3371
- send(data) {
3372
- this.data = data;
3373
- },
3374
-
3375
- json(data) {
3376
- this.data = data;
3377
- }
3378
-
3379
- }, options);
3380
- }
3381
-
3382
- static createRequestContext(options = {}) {
3383
- var _options$request, _options$event, _options$response, _options$event2;
3384
-
3385
- const event = {
3386
- request: (options == null ? void 0 : (_options$request = options.request) == null ? void 0 : _options$request.request) || (options == null ? void 0 : (_options$event = options.event) == null ? void 0 : _options$event.request) || PlatformTest.createRequest(),
3387
- response: (options == null ? void 0 : (_options$response = options.response) == null ? void 0 : _options$response.response) || (options == null ? void 0 : (_options$event2 = options.event) == null ? void 0 : _options$event2.response) || PlatformTest.createResponse()
3388
- };
3389
- const ctx = new PlatformContext(_extends({
3390
- id: "id",
3391
- injector: DITest.injector,
3392
- logger: DITest.injector.logger,
3393
- url: "/"
3394
- }, options, {
3395
- event
3396
- }));
3397
- ctx.response.platformViews = PlatformTest.get(PlatformViews);
3398
- return ctx;
3399
- }
3400
-
3401
- }
3402
-
3403
- /**
3404
- * @ignore
3405
- * @deprecated Will be removed in v7
3406
- */
3407
- class PlatformModule {}
3408
-
3409
- export { AcceptMime, AcceptMimesMiddleware, AnyToPromiseWithCtx, ControllerProvider, EndpointFn, EndpointInfo, EndpointMetadata, Err, GlobalAcceptMimesMiddleware, HandlerMetadata, HandlerType, HttpServer, HttpsServer, MulterFileSize, MulterOptions, MultipartFile, Next, PLATFORM_ROUTER_OPTIONS, Platform, PlatformAcceptMimesMiddleware, PlatformApplication, PlatformBuilder, PlatformConfiguration, PlatformContext, PlatformHandler, PlatformMiddlewaresChain, PlatformModule, PlatformMulterMiddleware, PlatformRequest, PlatformResponse, PlatformRouteDetails, PlatformRouter, PlatformTest, PropertyMetadata, ROUTER_OPTIONS, Req, Request, Res, Response, ResponseData, bindEndpointMiddleware, buildRouter, createContext, createHttpServer, createHttpsServer, createInjector, createPlatformApplication, createRouter, getRouter, listenHttpServer, listenHttpsServer, listenServer, loadInjector, mapReturnedResponse, printRoutes, useCtxHandler };
3410
- //# sourceMappingURL=index.modern.js.map