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