@tsed/common 6.87.2 → 6.90.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 (540) 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 +13 -26
  5. package/lib/cjs/builder/PlatformBuilder.js +268 -0
  6. package/lib/cjs/builder/PlatformBuilder.js.map +1 -0
  7. package/lib/{builder → cjs/builder}/PlatformControllerBuilder.d.ts +0 -0
  8. package/lib/cjs/builder/PlatformControllerBuilder.js +85 -0
  9. package/lib/cjs/builder/PlatformControllerBuilder.js.map +1 -0
  10. package/lib/{config → cjs/config}/index.d.ts +0 -0
  11. package/lib/cjs/config/index.js +7 -0
  12. package/lib/cjs/config/index.js.map +1 -0
  13. package/lib/{config → cjs/config}/interfaces/ConverterSettings.d.ts +0 -0
  14. package/lib/cjs/config/interfaces/ConverterSettings.js +3 -0
  15. package/lib/cjs/config/interfaces/ConverterSettings.js.map +1 -0
  16. package/lib/{config → cjs/config}/interfaces/EndpointDirectoriesSettings.d.ts +0 -0
  17. package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js +3 -0
  18. package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js.map +1 -0
  19. package/lib/{config → cjs/config}/interfaces/PlatformLoggerSettings.d.ts +0 -0
  20. package/lib/cjs/config/interfaces/PlatformLoggerSettings.js +3 -0
  21. package/lib/cjs/config/interfaces/PlatformLoggerSettings.js.map +1 -0
  22. package/lib/{config → cjs/config}/interfaces/PlatformMulterSettings.d.ts +0 -0
  23. package/lib/cjs/config/interfaces/PlatformMulterSettings.js +3 -0
  24. package/lib/cjs/config/interfaces/PlatformMulterSettings.js.map +1 -0
  25. package/lib/{config → cjs/config}/interfaces/PlatformStaticsSettings.d.ts +0 -0
  26. package/lib/cjs/config/interfaces/PlatformStaticsSettings.js +3 -0
  27. package/lib/cjs/config/interfaces/PlatformStaticsSettings.js.map +1 -0
  28. package/lib/{config → cjs/config}/interfaces/index.d.ts +0 -0
  29. package/lib/cjs/config/interfaces/index.js +8 -0
  30. package/lib/cjs/config/interfaces/index.js.map +1 -0
  31. package/lib/{config → cjs/config}/services/PlatformConfiguration.d.ts +0 -0
  32. package/lib/cjs/config/services/PlatformConfiguration.js +195 -0
  33. package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -0
  34. package/lib/{constants → cjs/constants}/routerOptions.d.ts +0 -0
  35. package/lib/cjs/constants/routerOptions.js +5 -0
  36. package/lib/cjs/constants/routerOptions.js.map +1 -0
  37. package/lib/{decorators → cjs/decorators}/httpServer.d.ts +0 -0
  38. package/lib/cjs/decorators/httpServer.js +31 -0
  39. package/lib/cjs/decorators/httpServer.js.map +1 -0
  40. package/lib/{decorators → cjs/decorators}/httpsServer.d.ts +0 -0
  41. package/lib/cjs/decorators/httpsServer.js +31 -0
  42. package/lib/cjs/decorators/httpsServer.js.map +1 -0
  43. package/lib/{decorators → cjs/decorators}/index.d.ts +1 -0
  44. package/lib/cjs/decorators/index.js +23 -0
  45. package/lib/cjs/decorators/index.js.map +1 -0
  46. package/lib/{decorators → cjs/decorators}/method/acceptMime.d.ts +0 -0
  47. package/lib/cjs/decorators/method/acceptMime.js +28 -0
  48. package/lib/cjs/decorators/method/acceptMime.js.map +1 -0
  49. package/lib/{decorators → cjs/decorators}/method/endpointFn.d.ts +0 -0
  50. package/lib/cjs/decorators/method/endpointFn.js +15 -0
  51. package/lib/cjs/decorators/method/endpointFn.js.map +1 -0
  52. package/lib/{decorators → cjs/decorators}/method/location.d.ts +0 -0
  53. package/lib/cjs/decorators/method/location.js +6 -0
  54. package/lib/cjs/decorators/method/location.js.map +1 -0
  55. package/lib/{decorators → cjs/decorators}/method/redirect.d.ts +0 -0
  56. package/lib/cjs/decorators/method/redirect.js +6 -0
  57. package/lib/cjs/decorators/method/redirect.js.map +1 -0
  58. package/lib/{decorators → cjs/decorators}/method/route.d.ts +0 -0
  59. package/lib/cjs/decorators/method/route.js +13 -0
  60. package/lib/cjs/decorators/method/route.js.map +1 -0
  61. package/lib/cjs/decorators/method/view.d.ts +25 -0
  62. package/lib/cjs/decorators/method/view.js +34 -0
  63. package/lib/cjs/decorators/method/view.js.map +1 -0
  64. package/lib/{decorators → cjs/decorators}/multer/index.d.ts +0 -0
  65. package/lib/cjs/decorators/multer/index.js +7 -0
  66. package/lib/cjs/decorators/multer/index.js.map +1 -0
  67. package/lib/{decorators → cjs/decorators}/multer/multerFileSize.d.ts +0 -0
  68. package/lib/cjs/decorators/multer/multerFileSize.js +35 -0
  69. package/lib/cjs/decorators/multer/multerFileSize.js.map +1 -0
  70. package/lib/{decorators → cjs/decorators}/multer/multerOptions.d.ts +0 -0
  71. package/lib/cjs/decorators/multer/multerOptions.js +52 -0
  72. package/lib/cjs/decorators/multer/multerOptions.js.map +1 -0
  73. package/lib/{decorators → cjs/decorators}/multer/multipartFile.d.ts +0 -0
  74. package/lib/cjs/decorators/multer/multipartFile.js +78 -0
  75. package/lib/cjs/decorators/multer/multipartFile.js.map +1 -0
  76. package/lib/{decorators → cjs/decorators}/params/endpointInfo.d.ts +0 -0
  77. package/lib/cjs/decorators/params/endpointInfo.js +21 -0
  78. package/lib/cjs/decorators/params/endpointInfo.js.map +1 -0
  79. package/lib/{decorators → cjs/decorators}/params/error.d.ts +0 -0
  80. package/lib/cjs/decorators/params/error.js +20 -0
  81. package/lib/cjs/decorators/params/error.js.map +1 -0
  82. package/lib/{decorators → cjs/decorators}/params/next.d.ts +0 -0
  83. package/lib/cjs/decorators/params/next.js +21 -0
  84. package/lib/cjs/decorators/params/next.js.map +1 -0
  85. package/lib/{decorators → cjs/decorators}/params/request.d.ts +0 -0
  86. package/lib/cjs/decorators/params/request.js +39 -0
  87. package/lib/cjs/decorators/params/request.js.map +1 -0
  88. package/lib/{decorators → cjs/decorators}/params/response.d.ts +0 -0
  89. package/lib/cjs/decorators/params/response.js +33 -0
  90. package/lib/cjs/decorators/params/response.js.map +1 -0
  91. package/lib/{decorators → cjs/decorators}/params/responseData.d.ts +0 -0
  92. package/lib/cjs/decorators/params/responseData.js +21 -0
  93. package/lib/cjs/decorators/params/responseData.js.map +1 -0
  94. package/lib/{domain → cjs/domain}/AnyToPromiseWithCtx.d.ts +0 -0
  95. package/lib/cjs/domain/AnyToPromiseWithCtx.js +35 -0
  96. package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -0
  97. package/lib/{domain → cjs/domain}/ControllerProvider.d.ts +0 -0
  98. package/lib/cjs/domain/ControllerProvider.js +51 -0
  99. package/lib/cjs/domain/ControllerProvider.js.map +1 -0
  100. package/lib/{domain → cjs/domain}/EndpointMetadata.d.ts +0 -0
  101. package/lib/cjs/domain/EndpointMetadata.js +111 -0
  102. package/lib/cjs/domain/EndpointMetadata.js.map +1 -0
  103. package/lib/{domain → cjs/domain}/HandlerMetadata.d.ts +0 -0
  104. package/lib/cjs/domain/HandlerMetadata.js +57 -0
  105. package/lib/cjs/domain/HandlerMetadata.js.map +1 -0
  106. package/lib/{domain → cjs/domain}/PlatformContext.d.ts +0 -0
  107. package/lib/cjs/domain/PlatformContext.js +85 -0
  108. package/lib/cjs/domain/PlatformContext.js.map +1 -0
  109. package/lib/{domain → cjs/domain}/PlatformRouteDetails.d.ts +0 -0
  110. package/lib/cjs/domain/PlatformRouteDetails.js +24 -0
  111. package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -0
  112. package/lib/{domain → cjs/domain}/PropertyMetadata.d.ts +0 -0
  113. package/lib/cjs/domain/PropertyMetadata.js +28 -0
  114. package/lib/cjs/domain/PropertyMetadata.js.map +1 -0
  115. package/lib/{domain → cjs/domain}/index.d.ts +0 -0
  116. package/lib/cjs/domain/index.js +11 -0
  117. package/lib/cjs/domain/index.js.map +1 -0
  118. package/lib/{index.d.ts → cjs/index.d.ts} +0 -1
  119. package/lib/cjs/index.js +37 -0
  120. package/lib/cjs/index.js.map +1 -0
  121. package/lib/{interfaces → cjs/interfaces}/AfterInit.d.ts +0 -0
  122. package/lib/cjs/interfaces/AfterInit.js +3 -0
  123. package/lib/cjs/interfaces/AfterInit.js.map +1 -0
  124. package/lib/{interfaces → cjs/interfaces}/AfterListen.d.ts +0 -0
  125. package/lib/cjs/interfaces/AfterListen.js +3 -0
  126. package/lib/cjs/interfaces/AfterListen.js.map +1 -0
  127. package/lib/{interfaces → cjs/interfaces}/AfterRoutesInit.d.ts +0 -0
  128. package/lib/cjs/interfaces/AfterRoutesInit.js +3 -0
  129. package/lib/cjs/interfaces/AfterRoutesInit.js.map +1 -0
  130. package/lib/{interfaces → cjs/interfaces}/BeforeInit.d.ts +0 -0
  131. package/lib/cjs/interfaces/BeforeInit.js +3 -0
  132. package/lib/cjs/interfaces/BeforeInit.js.map +1 -0
  133. package/lib/{interfaces → cjs/interfaces}/BeforeListen.d.ts +0 -0
  134. package/lib/cjs/interfaces/BeforeListen.js +3 -0
  135. package/lib/cjs/interfaces/BeforeListen.js.map +1 -0
  136. package/lib/{interfaces → cjs/interfaces}/BeforeRoutesInit.d.ts +0 -0
  137. package/lib/cjs/interfaces/BeforeRoutesInit.js +3 -0
  138. package/lib/cjs/interfaces/BeforeRoutesInit.js.map +1 -0
  139. package/lib/{interfaces → cjs/interfaces}/HandlerType.d.ts +0 -0
  140. package/lib/cjs/interfaces/HandlerType.js +17 -0
  141. package/lib/cjs/interfaces/HandlerType.js.map +1 -0
  142. package/lib/{interfaces → cjs/interfaces}/IncomingEvent.d.ts +0 -0
  143. package/lib/cjs/interfaces/IncomingEvent.js +3 -0
  144. package/lib/cjs/interfaces/IncomingEvent.js.map +1 -0
  145. package/lib/{interfaces → cjs/interfaces}/OnReady.d.ts +0 -0
  146. package/lib/cjs/interfaces/OnReady.js +3 -0
  147. package/lib/cjs/interfaces/OnReady.js.map +1 -0
  148. package/lib/{interfaces → cjs/interfaces}/OnRequest.d.ts +0 -0
  149. package/lib/cjs/interfaces/OnRequest.js +3 -0
  150. package/lib/cjs/interfaces/OnRequest.js.map +1 -0
  151. package/lib/{interfaces → cjs/interfaces}/OnResponse.d.ts +0 -0
  152. package/lib/cjs/interfaces/OnResponse.js +3 -0
  153. package/lib/cjs/interfaces/OnResponse.js.map +1 -0
  154. package/lib/{interfaces → cjs/interfaces}/OnRoutesInit.d.ts +0 -0
  155. package/lib/cjs/interfaces/OnRoutesInit.js +3 -0
  156. package/lib/cjs/interfaces/OnRoutesInit.js.map +1 -0
  157. package/lib/{interfaces → cjs/interfaces}/PathType.d.ts +0 -0
  158. package/lib/cjs/interfaces/PathType.js +3 -0
  159. package/lib/cjs/interfaces/PathType.js.map +1 -0
  160. package/lib/cjs/interfaces/PlatformAdapter.d.ts +19 -0
  161. package/lib/cjs/interfaces/PlatformAdapter.js +3 -0
  162. package/lib/cjs/interfaces/PlatformAdapter.js.map +1 -0
  163. package/lib/{interfaces → cjs/interfaces}/PlatformRouteOptions.d.ts +0 -0
  164. package/lib/cjs/interfaces/PlatformRouteOptions.js +3 -0
  165. package/lib/cjs/interfaces/PlatformRouteOptions.js.map +1 -0
  166. package/lib/{interfaces → cjs/interfaces}/ResponseErrorObject.d.ts +0 -0
  167. package/lib/cjs/interfaces/ResponseErrorObject.js +3 -0
  168. package/lib/cjs/interfaces/ResponseErrorObject.js.map +1 -0
  169. package/lib/{interfaces → cjs/interfaces}/Route.d.ts +0 -0
  170. package/lib/cjs/interfaces/Route.js +3 -0
  171. package/lib/cjs/interfaces/Route.js.map +1 -0
  172. package/lib/{interfaces → cjs/interfaces}/index.d.ts +1 -0
  173. package/lib/cjs/interfaces/index.js +21 -0
  174. package/lib/cjs/interfaces/index.js.map +1 -0
  175. package/lib/{middlewares → cjs/middlewares}/AcceptMimesMiddleware.d.ts +0 -0
  176. package/lib/cjs/middlewares/AcceptMimesMiddleware.js +27 -0
  177. package/lib/cjs/middlewares/AcceptMimesMiddleware.js.map +1 -0
  178. package/lib/{middlewares → cjs/middlewares}/GlobalAcceptMimesMiddleware.d.ts +0 -0
  179. package/lib/cjs/middlewares/GlobalAcceptMimesMiddleware.js +26 -0
  180. package/lib/cjs/middlewares/GlobalAcceptMimesMiddleware.js.map +1 -0
  181. package/lib/{middlewares → cjs/middlewares}/PlatformAcceptMimesMiddleware.d.ts +0 -0
  182. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js +37 -0
  183. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
  184. package/lib/{middlewares → cjs/middlewares}/PlatformMulterMiddleware.d.ts +0 -0
  185. package/lib/cjs/middlewares/PlatformMulterMiddleware.js +55 -0
  186. package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -0
  187. package/lib/{middlewares/data → cjs/middlewares/__mock__}/FakeCtrl.d.ts +0 -0
  188. package/lib/cjs/middlewares/__mock__/FakeCtrl.js +12 -0
  189. package/lib/cjs/middlewares/__mock__/FakeCtrl.js.map +1 -0
  190. package/lib/{middlewares → cjs/middlewares}/bindEndpointMiddleware.d.ts +0 -0
  191. package/lib/cjs/middlewares/bindEndpointMiddleware.js +13 -0
  192. package/lib/cjs/middlewares/bindEndpointMiddleware.js.map +1 -0
  193. package/lib/{middlewares → cjs/middlewares}/index.d.ts +0 -0
  194. package/lib/cjs/middlewares/index.js +9 -0
  195. package/lib/cjs/middlewares/index.js.map +1 -0
  196. package/lib/{services → cjs/services}/FakeRawDriver.d.ts +0 -0
  197. package/lib/cjs/services/FakeRawDriver.js +26 -0
  198. package/lib/cjs/services/FakeRawDriver.js.map +1 -0
  199. package/lib/{services → cjs/services}/Platform.d.ts +0 -0
  200. package/lib/cjs/services/Platform.js +107 -0
  201. package/lib/cjs/services/Platform.js.map +1 -0
  202. package/lib/{services → cjs/services}/PlatformApplication.d.ts +0 -0
  203. package/lib/cjs/services/PlatformApplication.js +34 -0
  204. package/lib/cjs/services/PlatformApplication.js.map +1 -0
  205. package/lib/{services → cjs/services}/PlatformHandler.d.ts +0 -0
  206. package/lib/cjs/services/PlatformHandler.js +235 -0
  207. package/lib/cjs/services/PlatformHandler.js.map +1 -0
  208. package/lib/{services → cjs/services}/PlatformMiddlewaresChain.d.ts +0 -0
  209. package/lib/cjs/services/PlatformMiddlewaresChain.js +34 -0
  210. package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -0
  211. package/lib/{services → cjs/services}/PlatformRequest.d.ts +2 -1
  212. package/lib/cjs/services/PlatformRequest.js +138 -0
  213. package/lib/cjs/services/PlatformRequest.js.map +1 -0
  214. package/lib/{services → cjs/services}/PlatformResponse.d.ts +4 -4
  215. package/lib/cjs/services/PlatformResponse.js +271 -0
  216. package/lib/cjs/services/PlatformResponse.js.map +1 -0
  217. package/lib/{services → cjs/services}/PlatformRouter.d.ts +0 -0
  218. package/lib/cjs/services/PlatformRouter.js +126 -0
  219. package/lib/cjs/services/PlatformRouter.js.map +1 -0
  220. package/lib/{services → cjs/services}/PlatformTest.d.ts +5 -4
  221. package/lib/cjs/services/PlatformTest.js +174 -0
  222. package/lib/cjs/services/PlatformTest.js.map +1 -0
  223. package/lib/{services → cjs/services}/index.d.ts +0 -0
  224. package/lib/cjs/services/index.js +12 -0
  225. package/lib/cjs/services/index.js.map +1 -0
  226. package/lib/{utils → cjs/utils}/createContext.d.ts +0 -0
  227. package/lib/cjs/utils/createContext.js +38 -0
  228. package/lib/cjs/utils/createContext.js.map +1 -0
  229. package/lib/{utils → cjs/utils}/createHandlerMetadata.d.ts +0 -0
  230. package/lib/cjs/utils/createHandlerMetadata.js +49 -0
  231. package/lib/cjs/utils/createHandlerMetadata.js.map +1 -0
  232. package/lib/{utils → cjs/utils}/createHttpServer.d.ts +0 -0
  233. package/lib/cjs/utils/createHttpServer.js +35 -0
  234. package/lib/cjs/utils/createHttpServer.js.map +1 -0
  235. package/lib/{utils → cjs/utils}/createHttpsServer.d.ts +0 -0
  236. package/lib/cjs/utils/createHttpsServer.js +36 -0
  237. package/lib/cjs/utils/createHttpsServer.js.map +1 -0
  238. package/lib/{utils → cjs/utils}/createInjector.d.ts +0 -0
  239. package/lib/cjs/utils/createInjector.js +42 -0
  240. package/lib/cjs/utils/createInjector.js.map +1 -0
  241. package/lib/{utils → cjs/utils}/getConfiguration.d.ts +0 -0
  242. package/lib/cjs/utils/getConfiguration.js +42 -0
  243. package/lib/cjs/utils/getConfiguration.js.map +1 -0
  244. package/lib/{utils → cjs/utils}/getStaticsOptions.d.ts +0 -0
  245. package/lib/cjs/utils/getStaticsOptions.js +21 -0
  246. package/lib/cjs/utils/getStaticsOptions.js.map +1 -0
  247. package/lib/{utils → cjs/utils}/index.d.ts +0 -0
  248. package/lib/cjs/utils/index.js +12 -0
  249. package/lib/cjs/utils/index.js.map +1 -0
  250. package/lib/{utils → cjs/utils}/listenServer.d.ts +0 -0
  251. package/lib/cjs/utils/listenServer.js +17 -0
  252. package/lib/cjs/utils/listenServer.js.map +1 -0
  253. package/lib/{utils → cjs/utils}/loadInjector.d.ts +0 -0
  254. package/lib/cjs/utils/loadInjector.js +14 -0
  255. package/lib/cjs/utils/loadInjector.js.map +1 -0
  256. package/lib/{utils → cjs/utils}/mapReturnedResponse.d.ts +0 -0
  257. package/lib/cjs/utils/mapReturnedResponse.js +15 -0
  258. package/lib/cjs/utils/mapReturnedResponse.js.map +1 -0
  259. package/lib/{utils → cjs/utils}/printRoutes.d.ts +0 -0
  260. package/lib/cjs/utils/printRoutes.js +36 -0
  261. package/lib/cjs/utils/printRoutes.js.map +1 -0
  262. package/lib/{utils → cjs/utils}/setResponseHeaders.d.ts +0 -0
  263. package/lib/cjs/utils/setResponseHeaders.js +35 -0
  264. package/lib/cjs/utils/setResponseHeaders.js.map +1 -0
  265. package/lib/{utils → cjs/utils}/useCtxHandler.d.ts +0 -0
  266. package/lib/cjs/utils/useCtxHandler.js +15 -0
  267. package/lib/cjs/utils/useCtxHandler.js.map +1 -0
  268. package/lib/esm/PlatformModule.js +7 -0
  269. package/lib/esm/PlatformModule.js.map +1 -0
  270. package/lib/esm/builder/PlatformBuilder.js +264 -0
  271. package/lib/esm/builder/PlatformBuilder.js.map +1 -0
  272. package/lib/esm/builder/PlatformControllerBuilder.js +79 -0
  273. package/lib/esm/builder/PlatformControllerBuilder.js.map +1 -0
  274. package/lib/esm/config/index.js +4 -0
  275. package/lib/esm/config/index.js.map +1 -0
  276. package/lib/esm/config/interfaces/ConverterSettings.js +2 -0
  277. package/lib/esm/config/interfaces/ConverterSettings.js.map +1 -0
  278. package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js +2 -0
  279. package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js.map +1 -0
  280. package/lib/esm/config/interfaces/PlatformLoggerSettings.js +2 -0
  281. package/lib/esm/config/interfaces/PlatformLoggerSettings.js.map +1 -0
  282. package/lib/esm/config/interfaces/PlatformMulterSettings.js +2 -0
  283. package/lib/esm/config/interfaces/PlatformMulterSettings.js.map +1 -0
  284. package/lib/esm/config/interfaces/PlatformStaticsSettings.js +2 -0
  285. package/lib/esm/config/interfaces/PlatformStaticsSettings.js.map +1 -0
  286. package/lib/esm/config/interfaces/index.js +5 -0
  287. package/lib/esm/config/interfaces/index.js.map +1 -0
  288. package/lib/esm/config/services/PlatformConfiguration.js +192 -0
  289. package/lib/esm/config/services/PlatformConfiguration.js.map +1 -0
  290. package/lib/esm/constants/routerOptions.js +2 -0
  291. package/lib/esm/constants/routerOptions.js.map +1 -0
  292. package/lib/esm/decorators/httpServer.js +27 -0
  293. package/lib/esm/decorators/httpServer.js.map +1 -0
  294. package/lib/esm/decorators/httpsServer.js +27 -0
  295. package/lib/esm/decorators/httpsServer.js.map +1 -0
  296. package/lib/esm/decorators/index.js +20 -0
  297. package/lib/esm/decorators/index.js.map +1 -0
  298. package/lib/esm/decorators/method/acceptMime.js +24 -0
  299. package/lib/esm/decorators/method/acceptMime.js.map +1 -0
  300. package/lib/esm/decorators/method/endpointFn.js +11 -0
  301. package/lib/esm/decorators/method/endpointFn.js.map +1 -0
  302. package/lib/esm/decorators/method/location.js +2 -0
  303. package/lib/esm/decorators/method/location.js.map +1 -0
  304. package/lib/esm/decorators/method/redirect.js +2 -0
  305. package/lib/esm/decorators/method/redirect.js.map +1 -0
  306. package/lib/esm/decorators/method/route.js +2 -0
  307. package/lib/esm/decorators/method/route.js.map +1 -0
  308. package/lib/esm/decorators/method/view.js +30 -0
  309. package/lib/esm/decorators/method/view.js.map +1 -0
  310. package/lib/esm/decorators/multer/index.js +4 -0
  311. package/lib/esm/decorators/multer/index.js.map +1 -0
  312. package/lib/esm/decorators/multer/multerFileSize.js +31 -0
  313. package/lib/esm/decorators/multer/multerFileSize.js.map +1 -0
  314. package/lib/esm/decorators/multer/multerOptions.js +48 -0
  315. package/lib/esm/decorators/multer/multerOptions.js.map +1 -0
  316. package/lib/esm/decorators/multer/multipartFile.js +74 -0
  317. package/lib/esm/decorators/multer/multipartFile.js.map +1 -0
  318. package/lib/esm/decorators/params/endpointInfo.js +17 -0
  319. package/lib/esm/decorators/params/endpointInfo.js.map +1 -0
  320. package/lib/esm/decorators/params/error.js +16 -0
  321. package/lib/esm/decorators/params/error.js.map +1 -0
  322. package/lib/esm/decorators/params/next.js +17 -0
  323. package/lib/esm/decorators/params/next.js.map +1 -0
  324. package/lib/esm/decorators/params/request.js +34 -0
  325. package/lib/esm/decorators/params/request.js.map +1 -0
  326. package/lib/esm/decorators/params/response.js +28 -0
  327. package/lib/esm/decorators/params/response.js.map +1 -0
  328. package/lib/esm/decorators/params/responseData.js +17 -0
  329. package/lib/esm/decorators/params/responseData.js.map +1 -0
  330. package/lib/esm/domain/AnyToPromiseWithCtx.js +31 -0
  331. package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -0
  332. package/lib/esm/domain/ControllerProvider.js +47 -0
  333. package/lib/esm/domain/ControllerProvider.js.map +1 -0
  334. package/lib/esm/domain/EndpointMetadata.js +108 -0
  335. package/lib/esm/domain/EndpointMetadata.js.map +1 -0
  336. package/lib/esm/domain/HandlerMetadata.js +53 -0
  337. package/lib/esm/domain/HandlerMetadata.js.map +1 -0
  338. package/lib/esm/domain/PlatformContext.js +81 -0
  339. package/lib/esm/domain/PlatformContext.js.map +1 -0
  340. package/lib/esm/domain/PlatformRouteDetails.js +20 -0
  341. package/lib/esm/domain/PlatformRouteDetails.js.map +1 -0
  342. package/lib/esm/domain/PropertyMetadata.js +25 -0
  343. package/lib/esm/domain/PropertyMetadata.js.map +1 -0
  344. package/lib/esm/domain/index.js +8 -0
  345. package/lib/esm/domain/index.js.map +1 -0
  346. package/lib/esm/index.js +31 -0
  347. package/lib/esm/index.js.map +1 -0
  348. package/lib/esm/interfaces/AfterInit.js +2 -0
  349. package/lib/esm/interfaces/AfterInit.js.map +1 -0
  350. package/lib/esm/interfaces/AfterListen.js +2 -0
  351. package/lib/esm/interfaces/AfterListen.js.map +1 -0
  352. package/lib/esm/interfaces/AfterRoutesInit.js +2 -0
  353. package/lib/esm/interfaces/AfterRoutesInit.js.map +1 -0
  354. package/lib/esm/interfaces/BeforeInit.js +2 -0
  355. package/lib/esm/interfaces/BeforeInit.js.map +1 -0
  356. package/lib/esm/interfaces/BeforeListen.js +2 -0
  357. package/lib/esm/interfaces/BeforeListen.js.map +1 -0
  358. package/lib/esm/interfaces/BeforeRoutesInit.js +2 -0
  359. package/lib/esm/interfaces/BeforeRoutesInit.js.map +1 -0
  360. package/lib/esm/interfaces/HandlerType.js +14 -0
  361. package/lib/esm/interfaces/HandlerType.js.map +1 -0
  362. package/lib/esm/interfaces/IncomingEvent.js +2 -0
  363. package/lib/esm/interfaces/IncomingEvent.js.map +1 -0
  364. package/lib/esm/interfaces/OnReady.js +2 -0
  365. package/lib/esm/interfaces/OnReady.js.map +1 -0
  366. package/lib/esm/interfaces/OnRequest.js +2 -0
  367. package/lib/esm/interfaces/OnRequest.js.map +1 -0
  368. package/lib/esm/interfaces/OnResponse.js +2 -0
  369. package/lib/esm/interfaces/OnResponse.js.map +1 -0
  370. package/lib/esm/interfaces/OnRoutesInit.js +2 -0
  371. package/lib/esm/interfaces/OnRoutesInit.js.map +1 -0
  372. package/lib/esm/interfaces/PathType.js +2 -0
  373. package/lib/esm/interfaces/PathType.js.map +1 -0
  374. package/lib/esm/interfaces/PlatformAdapter.js +2 -0
  375. package/lib/esm/interfaces/PlatformAdapter.js.map +1 -0
  376. package/lib/esm/interfaces/PlatformRouteOptions.js +2 -0
  377. package/lib/esm/interfaces/PlatformRouteOptions.js.map +1 -0
  378. package/lib/esm/interfaces/ResponseErrorObject.js +2 -0
  379. package/lib/esm/interfaces/ResponseErrorObject.js.map +1 -0
  380. package/lib/esm/interfaces/Route.js +2 -0
  381. package/lib/esm/interfaces/Route.js.map +1 -0
  382. package/lib/esm/interfaces/index.js +18 -0
  383. package/lib/esm/interfaces/index.js.map +1 -0
  384. package/lib/esm/middlewares/AcceptMimesMiddleware.js +24 -0
  385. package/lib/esm/middlewares/AcceptMimesMiddleware.js.map +1 -0
  386. package/lib/esm/middlewares/GlobalAcceptMimesMiddleware.js +23 -0
  387. package/lib/esm/middlewares/GlobalAcceptMimesMiddleware.js.map +1 -0
  388. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js +34 -0
  389. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
  390. package/lib/esm/middlewares/PlatformMulterMiddleware.js +52 -0
  391. package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -0
  392. package/lib/esm/middlewares/__mock__/FakeCtrl.js +9 -0
  393. package/lib/esm/middlewares/__mock__/FakeCtrl.js.map +1 -0
  394. package/lib/esm/middlewares/bindEndpointMiddleware.js +9 -0
  395. package/lib/esm/middlewares/bindEndpointMiddleware.js.map +1 -0
  396. package/lib/esm/middlewares/index.js +6 -0
  397. package/lib/esm/middlewares/index.js.map +1 -0
  398. package/lib/esm/services/FakeRawDriver.js +22 -0
  399. package/lib/esm/services/FakeRawDriver.js.map +1 -0
  400. package/lib/esm/services/Platform.js +104 -0
  401. package/lib/esm/services/Platform.js.map +1 -0
  402. package/lib/esm/services/PlatformApplication.js +31 -0
  403. package/lib/esm/services/PlatformApplication.js.map +1 -0
  404. package/lib/esm/services/PlatformHandler.js +232 -0
  405. package/lib/esm/services/PlatformHandler.js.map +1 -0
  406. package/lib/esm/services/PlatformMiddlewaresChain.js +31 -0
  407. package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -0
  408. package/lib/esm/services/PlatformRequest.js +135 -0
  409. package/lib/esm/services/PlatformRequest.js.map +1 -0
  410. package/lib/esm/services/PlatformResponse.js +268 -0
  411. package/lib/esm/services/PlatformResponse.js.map +1 -0
  412. package/lib/esm/services/PlatformRouter.js +123 -0
  413. package/lib/esm/services/PlatformRouter.js.map +1 -0
  414. package/lib/esm/services/PlatformTest.js +170 -0
  415. package/lib/esm/services/PlatformTest.js.map +1 -0
  416. package/lib/esm/services/index.js +9 -0
  417. package/lib/esm/services/index.js.map +1 -0
  418. package/lib/esm/utils/createContext.js +34 -0
  419. package/lib/esm/utils/createContext.js.map +1 -0
  420. package/lib/esm/utils/createHandlerMetadata.js +45 -0
  421. package/lib/esm/utils/createHandlerMetadata.js.map +1 -0
  422. package/lib/esm/utils/createHttpServer.js +29 -0
  423. package/lib/esm/utils/createHttpServer.js.map +1 -0
  424. package/lib/esm/utils/createHttpsServer.js +30 -0
  425. package/lib/esm/utils/createHttpsServer.js.map +1 -0
  426. package/lib/esm/utils/createInjector.js +38 -0
  427. package/lib/esm/utils/createInjector.js.map +1 -0
  428. package/lib/esm/utils/getConfiguration.js +38 -0
  429. package/lib/esm/utils/getConfiguration.js.map +1 -0
  430. package/lib/esm/utils/getStaticsOptions.js +17 -0
  431. package/lib/esm/utils/getStaticsOptions.js.map +1 -0
  432. package/lib/esm/utils/index.js +9 -0
  433. package/lib/esm/utils/index.js.map +1 -0
  434. package/lib/esm/utils/listenServer.js +13 -0
  435. package/lib/esm/utils/listenServer.js.map +1 -0
  436. package/lib/esm/utils/loadInjector.js +10 -0
  437. package/lib/esm/utils/loadInjector.js.map +1 -0
  438. package/lib/esm/utils/mapReturnedResponse.js +11 -0
  439. package/lib/esm/utils/mapReturnedResponse.js.map +1 -0
  440. package/lib/esm/utils/printRoutes.js +32 -0
  441. package/lib/esm/utils/printRoutes.js.map +1 -0
  442. package/lib/esm/utils/setResponseHeaders.js +31 -0
  443. package/lib/esm/utils/setResponseHeaders.js.map +1 -0
  444. package/lib/esm/utils/useCtxHandler.js +11 -0
  445. package/lib/esm/utils/useCtxHandler.js.map +1 -0
  446. package/lib/types/PlatformModule.d.ts +6 -0
  447. package/lib/types/builder/PlatformBuilder.d.ts +103 -0
  448. package/lib/types/builder/PlatformControllerBuilder.d.ts +17 -0
  449. package/lib/types/config/index.d.ts +3 -0
  450. package/lib/types/config/interfaces/ConverterSettings.d.ts +6 -0
  451. package/lib/types/config/interfaces/EndpointDirectoriesSettings.d.ts +3 -0
  452. package/lib/types/config/interfaces/PlatformLoggerSettings.d.ts +44 -0
  453. package/lib/types/config/interfaces/PlatformMulterSettings.d.ts +138 -0
  454. package/lib/types/config/interfaces/PlatformStaticsSettings.d.ts +17 -0
  455. package/lib/types/config/interfaces/index.d.ts +88 -0
  456. package/lib/types/config/services/PlatformConfiguration.d.ts +85 -0
  457. package/lib/types/constants/routerOptions.d.ts +1 -0
  458. package/lib/types/decorators/httpServer.d.ts +27 -0
  459. package/lib/types/decorators/httpsServer.d.ts +27 -0
  460. package/lib/types/decorators/index.d.ts +16 -0
  461. package/lib/types/decorators/method/acceptMime.d.ts +19 -0
  462. package/lib/types/decorators/method/endpointFn.d.ts +9 -0
  463. package/lib/types/decorators/method/location.d.ts +1 -0
  464. package/lib/types/decorators/method/redirect.d.ts +1 -0
  465. package/lib/types/decorators/method/route.d.ts +1 -0
  466. package/lib/types/decorators/method/view.d.ts +25 -0
  467. package/lib/types/decorators/multer/index.d.ts +3 -0
  468. package/lib/types/decorators/multer/multerFileSize.d.ts +27 -0
  469. package/lib/types/decorators/multer/multerOptions.d.ts +41 -0
  470. package/lib/types/decorators/multer/multipartFile.d.ts +47 -0
  471. package/lib/types/decorators/params/endpointInfo.d.ts +13 -0
  472. package/lib/types/decorators/params/error.d.ts +7 -0
  473. package/lib/types/decorators/params/next.d.ts +22 -0
  474. package/lib/types/decorators/params/request.d.ts +46 -0
  475. package/lib/types/decorators/params/response.d.ts +40 -0
  476. package/lib/types/decorators/params/responseData.d.ts +9 -0
  477. package/lib/types/domain/AnyToPromiseWithCtx.d.ts +18 -0
  478. package/lib/types/domain/ControllerProvider.d.ts +24 -0
  479. package/lib/types/domain/EndpointMetadata.d.ts +76 -0
  480. package/lib/types/domain/HandlerMetadata.d.ts +32 -0
  481. package/lib/types/domain/PlatformContext.d.ts +65 -0
  482. package/lib/types/domain/PlatformRouteDetails.d.ts +23 -0
  483. package/lib/types/domain/PropertyMetadata.d.ts +17 -0
  484. package/lib/types/domain/index.d.ts +7 -0
  485. package/lib/types/index.d.ts +22 -0
  486. package/lib/types/interfaces/AfterInit.d.ts +3 -0
  487. package/lib/types/interfaces/AfterListen.d.ts +3 -0
  488. package/lib/types/interfaces/AfterRoutesInit.d.ts +3 -0
  489. package/lib/types/interfaces/BeforeInit.d.ts +3 -0
  490. package/lib/types/interfaces/BeforeListen.d.ts +3 -0
  491. package/lib/types/interfaces/BeforeRoutesInit.d.ts +3 -0
  492. package/lib/types/interfaces/HandlerType.d.ts +12 -0
  493. package/lib/types/interfaces/IncomingEvent.d.ts +6 -0
  494. package/lib/types/interfaces/OnReady.d.ts +3 -0
  495. package/lib/types/interfaces/OnRequest.d.ts +4 -0
  496. package/lib/types/interfaces/OnResponse.d.ts +4 -0
  497. package/lib/types/interfaces/OnRoutesInit.d.ts +3 -0
  498. package/lib/types/interfaces/PathType.d.ts +1 -0
  499. package/lib/types/interfaces/PlatformAdapter.d.ts +19 -0
  500. package/lib/types/interfaces/PlatformRouteOptions.d.ts +16 -0
  501. package/lib/types/interfaces/ResponseErrorObject.d.ts +8 -0
  502. package/lib/types/interfaces/Route.d.ts +10 -0
  503. package/lib/types/interfaces/index.d.ts +17 -0
  504. package/lib/types/middlewares/AcceptMimesMiddleware.d.ts +10 -0
  505. package/lib/types/middlewares/GlobalAcceptMimesMiddleware.d.ts +9 -0
  506. package/lib/types/middlewares/PlatformAcceptMimesMiddleware.d.ts +10 -0
  507. package/lib/types/middlewares/PlatformMulterMiddleware.d.ts +19 -0
  508. package/lib/types/middlewares/__mock__/FakeCtrl.d.ts +2 -0
  509. package/lib/types/middlewares/bindEndpointMiddleware.d.ts +5 -0
  510. package/lib/types/middlewares/index.d.ts +5 -0
  511. package/lib/types/services/FakeRawDriver.d.ts +15 -0
  512. package/lib/types/services/Platform.d.ts +37 -0
  513. package/lib/types/services/PlatformApplication.d.ts +21 -0
  514. package/lib/types/services/PlatformHandler.d.ts +80 -0
  515. package/lib/types/services/PlatformMiddlewaresChain.d.ts +6 -0
  516. package/lib/types/services/PlatformRequest.d.ts +112 -0
  517. package/lib/types/services/PlatformResponse.d.ts +161 -0
  518. package/lib/types/services/PlatformRouter.d.ts +48 -0
  519. package/lib/types/services/PlatformTest.d.ts +58 -0
  520. package/lib/types/services/index.d.ts +8 -0
  521. package/lib/types/utils/createContext.d.ts +9 -0
  522. package/lib/types/utils/createHandlerMetadata.d.ts +8 -0
  523. package/lib/types/utils/createHttpServer.d.ts +3 -0
  524. package/lib/types/utils/createHttpsServer.d.ts +3 -0
  525. package/lib/types/utils/createInjector.d.ts +7 -0
  526. package/lib/types/utils/getConfiguration.d.ts +2 -0
  527. package/lib/types/utils/getStaticsOptions.d.ts +5 -0
  528. package/lib/types/utils/index.d.ts +8 -0
  529. package/lib/types/utils/listenServer.d.ts +10 -0
  530. package/lib/types/utils/loadInjector.d.ts +6 -0
  531. package/lib/types/utils/mapReturnedResponse.d.ts +4 -0
  532. package/lib/types/utils/printRoutes.d.ts +2 -0
  533. package/lib/types/utils/setResponseHeaders.d.ts +5 -0
  534. package/lib/types/utils/useCtxHandler.d.ts +13 -0
  535. package/package.json +26 -23
  536. package/tsconfig.compile.esm.json +23 -0
  537. package/lib/index.js +0 -3603
  538. package/lib/index.js.map +0 -1
  539. package/lib/index.modern.js +0 -3411
  540. package/lib/index.modern.js.map +0 -1
@@ -0,0 +1,268 @@
1
+ var PlatformResponse_1;
2
+ import { __decorate, __metadata } from "tslib";
3
+ import { isBoolean, isNumber, isStream, isString } from "@tsed/core";
4
+ import { Injectable, ProviderScope, Scope } from "@tsed/di";
5
+ const onFinished = require("on-finished");
6
+ /**
7
+ * Platform Response abstraction layer.
8
+ * @platform
9
+ */
10
+ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
11
+ constructor({ response }, $ctx) {
12
+ this.$ctx = $ctx;
13
+ this.raw = response;
14
+ }
15
+ /**
16
+ * Get the current statusCode
17
+ */
18
+ get statusCode() {
19
+ return this.raw.statusCode;
20
+ }
21
+ /**
22
+ * 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.
23
+ *
24
+ * This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.
25
+ */
26
+ get locals() {
27
+ return this.raw.locals;
28
+ }
29
+ /**
30
+ * Return the original response framework instance
31
+ */
32
+ get response() {
33
+ return this.getResponse();
34
+ }
35
+ /**
36
+ * Return the original response node.js instance
37
+ */
38
+ get res() {
39
+ return this.getRes();
40
+ }
41
+ static onFinished(res, cb) {
42
+ onFinished(res, cb);
43
+ }
44
+ /**
45
+ * Returns the HTTP response header specified by field. The match is case-insensitive.
46
+ *
47
+ * ```typescript
48
+ * response.get('Content-Type') // => "text/plain"
49
+ * ```
50
+ *
51
+ * @param name
52
+ */
53
+ get(name) {
54
+ return this.raw.get(name);
55
+ }
56
+ getHeaders() {
57
+ return this.raw.getHeaders();
58
+ }
59
+ /**
60
+ * Return the Framework response object (express, koa, etc...)
61
+ */
62
+ getResponse() {
63
+ return this.raw;
64
+ }
65
+ /**
66
+ * Return the Node.js response object
67
+ */
68
+ getRes() {
69
+ return this.raw;
70
+ }
71
+ hasStatus() {
72
+ return this.statusCode !== 200;
73
+ }
74
+ /**
75
+ * Sets the HTTP status for the response.
76
+ *
77
+ * @param status
78
+ */
79
+ status(status) {
80
+ this.raw.status(status);
81
+ return this;
82
+ }
83
+ /**
84
+ * Set header `field` to `val`, or pass
85
+ * an object of header fields.
86
+ *
87
+ * Examples:
88
+ * ```typescript
89
+ * response.setHeaders({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
90
+ * ```
91
+ *
92
+ * Aliased as `res.header()`.
93
+ */
94
+ setHeaders(headers) {
95
+ // apply headers
96
+ Object.entries(headers).forEach(([key, item]) => {
97
+ this.setHeader(key, item);
98
+ });
99
+ return this;
100
+ }
101
+ setHeader(key, item) {
102
+ if (key.toLowerCase() === "location") {
103
+ return this.location(String(item));
104
+ }
105
+ this.raw.set(key, item);
106
+ return this;
107
+ }
108
+ /**
109
+ * Set `Content-Type` response header with `type` through `mime.lookup()`
110
+ * when it does not contain "/", or set the Content-Type to `type` otherwise.
111
+ *
112
+ * Examples:
113
+ *
114
+ * res.type('.html');
115
+ * res.type('html');
116
+ * res.type('json');
117
+ * res.type('application/json');
118
+ * res.type('png');
119
+ */
120
+ contentType(contentType) {
121
+ this.raw.contentType(contentType);
122
+ return this;
123
+ }
124
+ contentLength(length) {
125
+ this.setHeader("Content-Length", length);
126
+ return this;
127
+ }
128
+ getContentLength() {
129
+ if (this.get("Content-Length")) {
130
+ return parseInt(this.get("Content-Length"), 10) || 0;
131
+ }
132
+ }
133
+ getContentType() {
134
+ return (this.get("Content-Type") || "").split(";")[0];
135
+ }
136
+ /**
137
+ * Sets the HTTP response Content-Disposition header field to “attachment”.
138
+ * 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.
139
+ *
140
+ * ```typescript
141
+ * res.attachment()
142
+ * // Content-Disposition: attachment
143
+ *
144
+ * res.attachment('path/to/logo.png')
145
+ * // Content-Disposition: attachment; filename="logo.png"
146
+ * // Content-Type: image/png
147
+ * ```
148
+ *
149
+ * @param filename
150
+ */
151
+ attachment(filename) {
152
+ this.raw.attachment(filename);
153
+ return this;
154
+ }
155
+ /**
156
+ * 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).
157
+ * If not specified, status defaults to `302 Found`.
158
+ *
159
+ * @param status
160
+ * @param url
161
+ */
162
+ redirect(status, url) {
163
+ this.raw.redirect(status, url);
164
+ return this;
165
+ }
166
+ /**
167
+ * Sets the response Location HTTP header to the specified path parameter.
168
+ *
169
+ * @param location
170
+ */
171
+ location(location) {
172
+ this.raw.location(location);
173
+ return this;
174
+ }
175
+ /**
176
+ * Stream the given data.
177
+ *
178
+ * @param data
179
+ */
180
+ stream(data) {
181
+ data.pipe(this.raw);
182
+ return this;
183
+ }
184
+ /**
185
+ * Renders a view and sends the rendered HTML string to the client.
186
+ *
187
+ * @param path
188
+ * @param options
189
+ */
190
+ async render(path, options = {}) {
191
+ const { PlatformViews } = await import("@tsed/platform-views");
192
+ const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);
193
+ return platformViews.render(path, {
194
+ ...this.locals,
195
+ ...options
196
+ });
197
+ }
198
+ /**
199
+ * Send any data to your consumer.
200
+ *
201
+ * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.
202
+ * It choose the better way to send the data.
203
+ *
204
+ * @param data
205
+ */
206
+ body(data) {
207
+ this.data = data;
208
+ if (data === undefined) {
209
+ this.raw.send();
210
+ return this;
211
+ }
212
+ if (isStream(data)) {
213
+ this.stream(data);
214
+ return this;
215
+ }
216
+ if (Buffer.isBuffer(data)) {
217
+ if (!this.getContentType()) {
218
+ this.contentType("application/octet-stream");
219
+ }
220
+ this.contentLength(data.length);
221
+ this.raw.send(data);
222
+ return this;
223
+ }
224
+ if (isBoolean(data) || isNumber(data) || isString(data) || data === null) {
225
+ this.raw.send(data);
226
+ return this;
227
+ }
228
+ this.raw.json(data);
229
+ return this;
230
+ }
231
+ getBody() {
232
+ return this.data;
233
+ }
234
+ /**
235
+ * Add a listener to handler the end of the request/response.
236
+ * @param cb
237
+ */
238
+ onEnd(cb) {
239
+ PlatformResponse_1.onFinished(this.getRes(), cb);
240
+ return this;
241
+ }
242
+ isDone() {
243
+ if (!this.raw) {
244
+ return true;
245
+ }
246
+ const res = this.getRes();
247
+ return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);
248
+ }
249
+ destroy() {
250
+ // @ts-ignore
251
+ delete this.raw;
252
+ delete this.data;
253
+ // @ts-ignore
254
+ delete this.request;
255
+ // @ts-ignore
256
+ delete this.$ctx;
257
+ }
258
+ isHeadersSent() {
259
+ return this.getRes().headersSent;
260
+ }
261
+ };
262
+ PlatformResponse = PlatformResponse_1 = __decorate([
263
+ Injectable(),
264
+ Scope(ProviderScope.INSTANCE),
265
+ __metadata("design:paramtypes", [Object, Function])
266
+ ], PlatformResponse);
267
+ export { PlatformResponse };
268
+ //# sourceMappingURL=PlatformResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformResponse.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACnE,OAAO,EAAC,UAAU,EAAE,aAAa,EAAE,KAAK,EAAC,MAAM,UAAU,CAAC;AAM1D,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAa1C;;;GAGG;AAGH,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;IAU3B,YAAY,EAAC,QAAQ,EAAgB,EAAY,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;QACpE,IAAI,CAAC,GAAG,GAAG,QAAe,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,IAA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AAI,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,IAAI,EAAE;YACxE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEpB,OAAO,IAAI,CAAC;SACb;QAED,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,EAAY;QAChB,kBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;QAE/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;YACb,OAAO,IAAI,CAAC;SACb;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAE1B,OAAO,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACpF,CAAC;IAED,OAAO;QACL,aAAa;QACb,OAAO,IAAI,CAAC,GAAG,CAAC;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC;QACjB,aAAa;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;QACpB,aAAa;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC;IACnC,CAAC;CACF,CAAA;AArTY,gBAAgB;IAF5B,UAAU,EAAE;IACZ,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC;;GACjB,gBAAgB,CAqT5B;SArTY,gBAAgB","sourcesContent":["import {isBoolean, isNumber, isStream, isString} from \"@tsed/core\";\nimport {Injectable, ProviderScope, Scope} from \"@tsed/di\";\nimport {ServerResponse} from \"http\";\nimport {IncomingEvent} from \"../interfaces/IncomingEvent\";\nimport type {PlatformRequest} from \"./PlatformRequest\";\nimport type {PlatformContext} from \"../domain/PlatformContext\";\n\nconst onFinished = require(\"on-finished\");\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Response {\n // req: any;\n }\n }\n}\n\nexport type HeaderValue = Array<boolean | number | string> | boolean | number | string;\n\n/**\n * Platform Response abstraction layer.\n * @platform\n */\n@Injectable()\n@Scope(ProviderScope.INSTANCE)\nexport class PlatformResponse<T extends Record<string, any> = any> {\n /**\n * The current @@PlatformRequest@@.\n */\n public request: PlatformRequest;\n\n data: any;\n\n raw: T;\n\n constructor({response}: IncomingEvent, protected $ctx: PlatformContext) {\n this.raw = response as any;\n }\n\n /**\n * Get the current statusCode\n */\n get statusCode() {\n return this.raw.statusCode;\n }\n\n /**\n * An object that contains response local variables scoped to the request, and therefore available only to the view(s) rendered during that request / response cycle (if any). Otherwise, this property is identical to app.locals.\n *\n * This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.\n */\n get locals() {\n return this.raw.locals;\n }\n\n /**\n * Return the original response framework instance\n */\n get response() {\n return this.getResponse();\n }\n\n /**\n * Return the original response node.js instance\n */\n get res() {\n return this.getRes();\n }\n\n static onFinished(res: any, cb: Function) {\n onFinished(res, cb);\n }\n\n /**\n * Returns the HTTP response header specified by field. The match is case-insensitive.\n *\n * ```typescript\n * response.get('Content-Type') // => \"text/plain\"\n * ```\n *\n * @param name\n */\n get(name: string) {\n return this.raw.get(name);\n }\n\n getHeaders(): Record<string, HeaderValue> {\n return this.raw.getHeaders();\n }\n\n /**\n * Return the Framework response object (express, koa, etc...)\n */\n getResponse<Res = T>(): Res {\n return this.raw as any;\n }\n\n /**\n * Return the Node.js response object\n */\n getRes(): ServerResponse {\n return this.raw as any;\n }\n\n hasStatus() {\n return this.statusCode !== 200;\n }\n\n /**\n * Sets the HTTP status for the response.\n *\n * @param status\n */\n status(status: number) {\n this.raw.status(status);\n\n return this;\n }\n\n /**\n * Set header `field` to `val`, or pass\n * an object of header fields.\n *\n * Examples:\n * ```typescript\n * response.setHeaders({ Accept: 'text/plain', 'X-API-Key': 'tobi' });\n * ```\n *\n * Aliased as `res.header()`.\n */\n setHeaders(headers: Record<string, HeaderValue>) {\n // apply headers\n Object.entries(headers).forEach(([key, item]) => {\n this.setHeader(key, item);\n });\n\n return this;\n }\n\n setHeader(key: string, item: any) {\n if (key.toLowerCase() === \"location\") {\n return this.location(String(item));\n }\n\n this.raw.set(key, item);\n\n return this;\n }\n\n /**\n * Set `Content-Type` response header with `type` through `mime.lookup()`\n * when it does not contain \"/\", or set the Content-Type to `type` otherwise.\n *\n * Examples:\n *\n * res.type('.html');\n * res.type('html');\n * res.type('json');\n * res.type('application/json');\n * res.type('png');\n */\n contentType(contentType: string) {\n this.raw.contentType(contentType);\n\n return this;\n }\n\n contentLength(length: number) {\n this.setHeader(\"Content-Length\", length);\n return this;\n }\n\n getContentLength() {\n if (this.get(\"Content-Length\")) {\n return parseInt(this.get(\"Content-Length\"), 10) || 0;\n }\n }\n\n getContentType() {\n return (this.get(\"Content-Type\") || \"\").split(\";\")[0];\n }\n\n /**\n * Sets the HTTP response Content-Disposition header field to “attachment”.\n * If a filename is given, then it sets the Content-Type based on the extension name via res.type(), and sets the Content-Disposition “filename=” parameter.\n *\n * ```typescript\n * res.attachment()\n * // Content-Disposition: attachment\n *\n * res.attachment('path/to/logo.png')\n * // Content-Disposition: attachment; filename=\"logo.png\"\n * // Content-Type: image/png\n * ```\n *\n * @param filename\n */\n attachment(filename: string) {\n this.raw.attachment(filename);\n return this;\n }\n\n /**\n * Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an [HTTP status code](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html).\n * If not specified, status defaults to `302 Found`.\n *\n * @param status\n * @param url\n */\n redirect(status: number, url: string) {\n this.raw.redirect(status, url);\n\n return this;\n }\n\n /**\n * Sets the response Location HTTP header to the specified path parameter.\n *\n * @param location\n */\n location(location: string) {\n this.raw.location(location);\n\n return this;\n }\n\n /**\n * Stream the given data.\n *\n * @param data\n */\n stream(data: ReadableStream | any) {\n data.pipe(this.raw);\n\n return this;\n }\n\n /**\n * Renders a view and sends the rendered HTML string to the client.\n *\n * @param path\n * @param options\n */\n async render(path: string, options: any = {}) {\n const {PlatformViews} = await import(\"@tsed/platform-views\");\n const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);\n\n return platformViews.render(path, {\n ...this.locals,\n ...options\n });\n }\n\n /**\n * Send any data to your consumer.\n *\n * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.\n * It choose the better way to send the data.\n *\n * @param data\n */\n body(data: any) {\n this.data = data;\n if (data === undefined) {\n this.raw.send();\n\n return this;\n }\n\n if (isStream(data)) {\n this.stream(data);\n\n return this;\n }\n\n if (Buffer.isBuffer(data)) {\n if (!this.getContentType()) {\n this.contentType(\"application/octet-stream\");\n }\n\n this.contentLength(data.length);\n this.raw.send(data);\n\n return this;\n }\n\n if (isBoolean(data) || isNumber(data) || isString(data) || data === null) {\n this.raw.send(data);\n\n return this;\n }\n\n this.raw.json(data);\n\n return this;\n }\n\n getBody() {\n return this.data;\n }\n\n /**\n * Add a listener to handler the end of the request/response.\n * @param cb\n */\n onEnd(cb: Function): this {\n PlatformResponse.onFinished(this.getRes(), cb);\n\n return this;\n }\n\n isDone(): boolean {\n if (!this.raw) {\n return true;\n }\n\n const res = this.getRes();\n\n return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);\n }\n\n destroy() {\n // @ts-ignore\n delete this.raw;\n delete this.data;\n // @ts-ignore\n delete this.request;\n // @ts-ignore\n delete this.$ctx;\n }\n\n isHeadersSent() {\n return this.getRes().headersSent;\n }\n}\n"]}
@@ -0,0 +1,123 @@
1
+ var PlatformRouter_1;
2
+ import { __decorate, __metadata } from "tslib";
3
+ import { Inject, Injectable, InjectorService, ProviderScope } from "@tsed/di";
4
+ import { promisify } from "util";
5
+ import { createFakeRawDriver } from "./FakeRawDriver";
6
+ import { PlatformHandler } from "./PlatformHandler";
7
+ /**
8
+ * @ignore
9
+ */
10
+ export const PLATFORM_ROUTER_OPTIONS = Symbol.for("PlatformRouterOptions");
11
+ /**
12
+ * Platform Router abstraction layer.
13
+ * @platform
14
+ */
15
+ let PlatformRouter = PlatformRouter_1 = class PlatformRouter {
16
+ constructor(platformHandler) {
17
+ this.platformHandler = platformHandler;
18
+ this.isBuilt = false;
19
+ this.rawRouter = this.raw = PlatformRouter_1.createRawRouter();
20
+ }
21
+ /**
22
+ * Create a new instance of PlatformRouter
23
+ * @param injector
24
+ * @param routerOptions
25
+ */
26
+ static create(injector, routerOptions = {}) {
27
+ const locals = new Map();
28
+ locals.set(PLATFORM_ROUTER_OPTIONS, routerOptions);
29
+ return injector.invoke(PlatformRouter_1, locals);
30
+ }
31
+ static createRawRouter() {
32
+ return createFakeRawDriver();
33
+ }
34
+ callback() {
35
+ return this.raw;
36
+ }
37
+ getRouter() {
38
+ return this.rawRouter;
39
+ }
40
+ use(...handlers) {
41
+ // @ts-ignore
42
+ this.getRouter().use(...this.mapHandlers(handlers));
43
+ return this;
44
+ }
45
+ addRoute(options) {
46
+ const { method, path, handlers, ...opts } = options;
47
+ // @ts-ignore
48
+ this.getRouter()[method](path, ...this.mapHandlers(handlers, { method, path, ...opts }));
49
+ return this;
50
+ }
51
+ all(path, ...handlers) {
52
+ return this.addRoute({ method: "all", path, handlers, isFinal: true });
53
+ }
54
+ get(path, ...handlers) {
55
+ return this.addRoute({ method: "get", path, handlers, isFinal: true });
56
+ }
57
+ post(path, ...handlers) {
58
+ return this.addRoute({ method: "post", path, handlers, isFinal: true });
59
+ }
60
+ put(path, ...handlers) {
61
+ return this.addRoute({ method: "put", path, handlers, isFinal: true });
62
+ }
63
+ delete(path, ...handlers) {
64
+ return this.addRoute({ method: "delete", path, handlers, isFinal: true });
65
+ }
66
+ patch(path, ...handlers) {
67
+ return this.addRoute({ method: "patch", path, handlers, isFinal: true });
68
+ }
69
+ head(path, ...handlers) {
70
+ return this.addRoute({ method: "head", path, handlers, isFinal: true });
71
+ }
72
+ options(path, ...handlers) {
73
+ return this.addRoute({ method: "options", path, handlers, isFinal: true });
74
+ }
75
+ statics(path, options) {
76
+ return this;
77
+ }
78
+ multer(options) {
79
+ const m = require("multer")(options);
80
+ const makePromise = (multer, name) => {
81
+ // istanbul ignore next
82
+ if (!multer[name])
83
+ return;
84
+ const fn = multer[name];
85
+ multer[name] = function apply(...args) {
86
+ const middleware = Reflect.apply(fn, this, args);
87
+ return (req, res) => promisify(middleware)(req, res);
88
+ };
89
+ };
90
+ makePromise(m, "any");
91
+ makePromise(m, "array");
92
+ makePromise(m, "fields");
93
+ makePromise(m, "none");
94
+ makePromise(m, "single");
95
+ return m;
96
+ }
97
+ mapHandlers(handlers, options = {}) {
98
+ return handlers.reduce((list, handler, index) => {
99
+ if (typeof handler === "string") {
100
+ return list.concat(handler);
101
+ }
102
+ if (handler instanceof PlatformRouter_1) {
103
+ return list.concat(handler.callback());
104
+ }
105
+ return list.concat(this.platformHandler.createHandler(handler, {
106
+ ...options,
107
+ isFinal: options.isFinal ? index === handlers.length - 1 : false
108
+ }));
109
+ }, []);
110
+ }
111
+ };
112
+ __decorate([
113
+ Inject(),
114
+ __metadata("design:type", InjectorService)
115
+ ], PlatformRouter.prototype, "injector", void 0);
116
+ PlatformRouter = PlatformRouter_1 = __decorate([
117
+ Injectable({
118
+ scope: ProviderScope.INSTANCE
119
+ }),
120
+ __metadata("design:paramtypes", [PlatformHandler])
121
+ ], PlatformRouter);
122
+ export { PlatformRouter };
123
+ //# sourceMappingURL=PlatformRouter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformRouter.js","sourceRoot":"","sources":["../../../src/services/PlatformRouter.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAY,aAAa,EAAC,MAAM,UAAU,CAAC;AACtF,OAAO,EAAC,SAAS,EAAC,MAAM,MA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,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACvB,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QAEzB,OAAO,CAAC,CAAC;IACX,CAAC;IAES,WAAW,CAAC,QAAe,EAAE,UAAwC,EAAE;QAC/E,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;YAC9C,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;gBAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;aAC7B;YAED,IAAI,OAAO,YAAY,gBAAc,EAAE;gBACrC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;aACxC;YAED,OAAO,IAAI,CAAC,MAAM,CAChB,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,OAAO,EAAE;gBAC1C,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK;aACjE,CAAC,CACH,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AA7HC;IADC,MAAM,EAAE;8BACC,eAAe;gDAAC;AANf,cAAc;IAH1B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,QAAQ;KAC9B,CAAC;qCASuC,eAAe;GAR3C,cAAc,CAmI1B;SAnIY,cAAc","sourcesContent":["import {Inject, Injectable, InjectorService, PathType, ProviderScope} from \"@tsed/di\";\nimport {promisify} from \"util\";\nimport {PlatformMulter, PlatformMulterSettings, PlatformStaticsOptions} from \"../config\";\nimport {PlatformRouteOptions, PlatformRouteWithoutHandlers} from \"../interfaces\";\nimport {createFakeRawDriver} from \"./FakeRawDriver\";\nimport {PlatformHandler} from \"./PlatformHandler\";\n\n/**\n * @ignore\n */\nexport const PLATFORM_ROUTER_OPTIONS = Symbol.for(\"PlatformRouterOptions\");\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Router {}\n }\n}\n\n/**\n * Platform Router abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.INSTANCE\n})\nexport class PlatformRouter<Router = TsED.Router> {\n rawRouter: Router;\n raw: any;\n isBuilt: boolean = false;\n\n @Inject()\n injector: InjectorService;\n\n constructor(protected platformHandler: PlatformHandler) {\n this.rawRouter = this.raw = PlatformRouter.createRawRouter();\n }\n\n /**\n * Create a new instance of PlatformRouter\n * @param injector\n * @param routerOptions\n */\n static create(injector: InjectorService, routerOptions: any = {}) {\n const locals = new Map();\n locals.set(PLATFORM_ROUTER_OPTIONS, routerOptions);\n\n return injector.invoke<PlatformRouter>(PlatformRouter, locals);\n }\n\n protected static createRawRouter(): any {\n return createFakeRawDriver();\n }\n\n callback(): any {\n return this.raw;\n }\n\n getRouter(): Router {\n return this.rawRouter;\n }\n\n use(...handlers: any[]) {\n // @ts-ignore\n this.getRouter().use(...this.mapHandlers(handlers));\n\n return this;\n }\n\n addRoute(options: Partial<PlatformRouteOptions>) {\n const {method, path, handlers, ...opts} = options;\n\n // @ts-ignore\n this.getRouter()[method](path, ...this.mapHandlers(handlers, {method, path, ...opts}));\n\n return this;\n }\n\n all(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"all\", path, handlers, isFinal: true});\n }\n\n get(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"get\", path, handlers, isFinal: true});\n }\n\n post(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"post\", path, handlers, isFinal: true});\n }\n\n put(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"put\", path, handlers, isFinal: true});\n }\n\n delete(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"delete\", path, handlers, isFinal: true});\n }\n\n patch(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"patch\", path, handlers, isFinal: true});\n }\n\n head(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"head\", path, handlers, isFinal: true});\n }\n\n options(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"options\", path, handlers, isFinal: true});\n }\n\n statics(path: string, options: PlatformStaticsOptions): this {\n return this;\n }\n\n multer(options: PlatformMulterSettings): PlatformMulter {\n const m = require(\"multer\")(options);\n\n const makePromise = (multer: any, name: string) => {\n // istanbul ignore next\n if (!multer[name]) return;\n\n const fn = multer[name];\n\n multer[name] = function apply(...args: any[]) {\n const middleware = Reflect.apply(fn, this, args);\n\n return (req: any, res: any) => promisify(middleware)(req, res);\n };\n };\n\n makePromise(m, \"any\");\n makePromise(m, \"array\");\n makePromise(m, \"fields\");\n makePromise(m, \"none\");\n makePromise(m, \"single\");\n\n return m;\n }\n\n protected mapHandlers(handlers: any[], options: PlatformRouteWithoutHandlers = {}): any[] {\n return handlers.reduce((list, handler, index) => {\n if (typeof handler === \"string\") {\n return list.concat(handler);\n }\n\n if (handler instanceof PlatformRouter) {\n return list.concat(handler.callback());\n }\n\n return list.concat(\n this.platformHandler.createHandler(handler, {\n ...options,\n isFinal: options.isFinal ? index === handlers.length - 1 : false\n })\n );\n }, []);\n }\n}\n"]}
@@ -0,0 +1,170 @@
1
+ import { createContainer, DITest } from "@tsed/di";
2
+ import { PlatformBuilder } from "../builder/PlatformBuilder";
3
+ import { PlatformContext } from "../domain/PlatformContext";
4
+ import { createInjector } from "../utils/createInjector";
5
+ import { PlatformApplication } from "./PlatformApplication";
6
+ import { getConfiguration } from "../utils/getConfiguration";
7
+ /**
8
+ * @platform
9
+ */
10
+ export class PlatformTest extends DITest {
11
+ static async create(settings = {}) {
12
+ DITest.injector = PlatformTest.createInjector(getConfiguration(settings));
13
+ const container = createContainer();
14
+ await DITest.injector.load(container);
15
+ }
16
+ /**
17
+ * Create a new injector with the right default services
18
+ */
19
+ static createInjector(settings = {}) {
20
+ return createInjector({
21
+ providers: [],
22
+ settings: DITest.configure(settings)
23
+ });
24
+ }
25
+ /**
26
+ * Load the server silently without listening port and configure it on test profile.
27
+ * @decorator
28
+ * @param mod
29
+ * @param listen
30
+ * @param settings
31
+ * @returns {Promise<void>}
32
+ */
33
+ static bootstrap(mod, { listen, ...settings } = {}) {
34
+ return async function before() {
35
+ let instance;
36
+ const adapter = settings.platform || settings.adapter || PlatformTest.adapter;
37
+ /* istanbul ignore next */
38
+ if (!adapter) {
39
+ throw new Error("Platform adapter is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?");
40
+ }
41
+ // @ts-ignore
42
+ settings = DITest.configure(settings);
43
+ settings.adapter = adapter;
44
+ instance = await PlatformBuilder.build(mod, settings).bootstrap();
45
+ if (!listen) {
46
+ await instance.callHook("$beforeListen");
47
+ await instance.callHook("$afterListen");
48
+ await instance.ready();
49
+ }
50
+ else {
51
+ await instance.listen();
52
+ }
53
+ // used by inject method
54
+ DITest.injector = instance.injector;
55
+ };
56
+ }
57
+ /**
58
+ * It injects services into the test function where you can alter, spy on, and manipulate them.
59
+ *
60
+ * The inject function has two parameters
61
+ *
62
+ * * an array of Service dependency injection tokens,
63
+ * * a test function whose parameters correspond exactly to each item in the injection token array.
64
+ *
65
+ * @param targets
66
+ * @param func
67
+ */
68
+ static inject(targets, func) {
69
+ return async () => {
70
+ if (!DITest.hasInjector()) {
71
+ await PlatformTest.create();
72
+ }
73
+ const injector = DITest.injector;
74
+ const deps = [];
75
+ for (const target of targets) {
76
+ deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));
77
+ }
78
+ return await func(...deps);
79
+ };
80
+ }
81
+ /**
82
+ * Return the raw application (express or koa).
83
+ * Use this callback with SuperTest.
84
+ *
85
+ * ```typescript
86
+ * let request: SuperTest.SuperTest<SuperTest.Test>;
87
+ * beforeEach(PlatformTest.bootstrap(Server, {
88
+ * mount: {
89
+ * "/rest": [ProductsController]
90
+ * }
91
+ * }));
92
+ * beforeEach(() => {
93
+ * request = SuperTest(PlatformTest.callback());
94
+ * });
95
+ * ```
96
+ */
97
+ static callback() {
98
+ var _a;
99
+ return (_a = DITest.injector.get(PlatformApplication)) === null || _a === void 0 ? void 0 : _a.callback();
100
+ }
101
+ static createRequest(options = {}) {
102
+ return {
103
+ headers: {},
104
+ get(key) {
105
+ return this.headers[key.toLowerCase()];
106
+ },
107
+ accepts(mime) {
108
+ return require("accepts")(this).types([].concat(mime));
109
+ },
110
+ ...options
111
+ };
112
+ }
113
+ static createResponse(options = {}) {
114
+ return {
115
+ headers: {},
116
+ locals: {},
117
+ statusCode: 200,
118
+ status(code) {
119
+ this.statusCode = code;
120
+ return this;
121
+ },
122
+ contentType(content) {
123
+ this.set("content-type", content);
124
+ },
125
+ contentLength(content) {
126
+ this.set("content-length", content);
127
+ },
128
+ redirect(status, path) {
129
+ this.statusCode = status;
130
+ this.set("location", path);
131
+ },
132
+ location(path) {
133
+ this.set("location", path);
134
+ },
135
+ get(key) {
136
+ return this.headers[key.toLowerCase()];
137
+ },
138
+ getHeaders() {
139
+ return this.headers;
140
+ },
141
+ set(key, value) {
142
+ this.headers[key.toLowerCase()] = value;
143
+ return this;
144
+ },
145
+ send(data) {
146
+ this.data = data;
147
+ },
148
+ json(data) {
149
+ this.data = data;
150
+ },
151
+ ...options
152
+ };
153
+ }
154
+ static createRequestContext(options = {}) {
155
+ var _a, _b, _c, _d;
156
+ const event = {
157
+ request: ((_a = options === null || options === void 0 ? void 0 : options.request) === null || _a === void 0 ? void 0 : _a.request) || ((_b = options === null || options === void 0 ? void 0 : options.event) === null || _b === void 0 ? void 0 : _b.request) || PlatformTest.createRequest(),
158
+ response: ((_c = options === null || options === void 0 ? void 0 : options.response) === null || _c === void 0 ? void 0 : _c.response) || ((_d = options === null || options === void 0 ? void 0 : options.event) === null || _d === void 0 ? void 0 : _d.response) || PlatformTest.createResponse()
159
+ };
160
+ return new PlatformContext({
161
+ id: "id",
162
+ injector: DITest.injector,
163
+ logger: DITest.injector.logger,
164
+ url: "/",
165
+ ...options,
166
+ event
167
+ });
168
+ }
169
+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,CAAC;CACF","sourcesContent":["import {createContainer, DITest, InjectorService} from \"@tsed/di\";\nimport {PlatformBuilder} from \"../builder/PlatformBuilder\";\nimport {PlatformContext, PlatformContextOptions} from \"../domain/PlatformContext\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../interfaces/PlatformAdapter\";\nimport {Type} from \"@tsed/core\";\n\n/**\n * @platform\n */\nexport class PlatformTest extends DITest {\n public static adapter: Type<PlatformAdapter>;\n\n static async create(settings: Partial<TsED.Configuration> = {}) {\n DITest.injector = PlatformTest.createInjector(getConfiguration(settings));\n const container = createContainer();\n\n await DITest.injector.load(container);\n }\n\n /**\n * Create a new injector with the right default services\n */\n static createInjector(settings: any = {}): InjectorService {\n return createInjector({\n providers: [],\n settings: DITest.configure(settings)\n });\n }\n\n /**\n * Load the server silently without listening port and configure it on test profile.\n * @decorator\n * @param mod\n * @param listen\n * @param settings\n * @returns {Promise<void>}\n */\n static bootstrap(mod: any, {listen, ...settings}: Partial<PlatformBuilderSettings & {listen: boolean}> = {}): () => Promise<void> {\n return async function before(): Promise<void> {\n let instance: any;\n const adapter: Type<PlatformAdapter> = settings.platform || settings.adapter || PlatformTest.adapter;\n\n /* istanbul ignore next */\n if (!adapter) {\n throw new Error(\n \"Platform adapter is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?\"\n );\n }\n\n // @ts-ignore\n settings = DITest.configure(settings);\n settings.adapter = adapter as any;\n\n instance = await PlatformBuilder.build(mod, settings).bootstrap();\n\n if (!listen) {\n await instance.callHook(\"$beforeListen\");\n await instance.callHook(\"$afterListen\");\n await instance.ready();\n } else {\n await instance.listen();\n }\n\n // used by inject method\n DITest.injector = instance.injector;\n };\n }\n\n /**\n * It injects services into the test function where you can alter, spy on, and manipulate them.\n *\n * The inject function has two parameters\n *\n * * an array of Service dependency injection tokens,\n * * a test function whose parameters correspond exactly to each item in the injection token array.\n *\n * @param targets\n * @param func\n */\n static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T> {\n return async (): Promise<T> => {\n if (!DITest.hasInjector()) {\n await PlatformTest.create();\n }\n\n const injector: InjectorService = DITest.injector;\n const deps = [];\n\n for (const target of targets) {\n deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));\n }\n\n return await func(...deps);\n };\n }\n\n /**\n * Return the raw application (express or koa).\n * Use this callback with SuperTest.\n *\n * ```typescript\n * let request: SuperTest.SuperTest<SuperTest.Test>;\n * beforeEach(PlatformTest.bootstrap(Server, {\n * mount: {\n * \"/rest\": [ProductsController]\n * }\n * }));\n * beforeEach(() => {\n * request = SuperTest(PlatformTest.callback());\n * });\n * ```\n */\n static callback() {\n return DITest.injector.get<PlatformApplication>(PlatformApplication)?.callback();\n }\n\n static createRequest(options: any = {}): any {\n return {\n headers: {},\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n accepts(mime?: string | string[]) {\n return require(\"accepts\")(this).types([].concat(mime as never));\n },\n ...options\n };\n }\n\n static createResponse(options: any = {}): any {\n return {\n headers: {},\n locals: {},\n statusCode: 200,\n status(code: number) {\n this.statusCode = code;\n return this;\n },\n contentType(content: string) {\n this.set(\"content-type\", content);\n },\n contentLength(content: number) {\n this.set(\"content-length\", content);\n },\n redirect(status: number, path: string) {\n this.statusCode = status;\n this.set(\"location\", path);\n },\n location(path: string) {\n this.set(\"location\", path);\n },\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n getHeaders() {\n return this.headers;\n },\n set(key: string, value: any) {\n this.headers[key.toLowerCase()] = value;\n return this;\n },\n send(data: any) {\n this.data = data;\n },\n json(data: any) {\n this.data = data;\n },\n ...options\n };\n }\n\n static createRequestContext(options: Partial<PlatformContextOptions & any> = {}) {\n const event = {\n request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),\n response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()\n };\n\n return new PlatformContext({\n id: \"id\",\n injector: DITest.injector,\n logger: DITest.injector.logger,\n url: \"/\",\n ...options,\n event\n });\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ export * from "./Platform";
2
+ export * from "./PlatformApplication";
3
+ export * from "./PlatformHandler";
4
+ export * from "./PlatformRequest";
5
+ export * from "./PlatformResponse";
6
+ export * from "./PlatformRouter";
7
+ export * from "./PlatformTest";
8
+ export * from "./PlatformMiddlewaresChain";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,4BAA4B,CAAC","sourcesContent":["export * from \"./Platform\";\nexport * from \"./PlatformApplication\";\nexport * from \"./PlatformHandler\";\nexport * from \"./PlatformRequest\";\nexport * from \"./PlatformResponse\";\nexport * from \"./PlatformRouter\";\nexport * from \"./PlatformTest\";\nexport * from \"./PlatformMiddlewaresChain\";\n"]}