@tsed/common 7.0.0-alpha.1 → 7.0.0-beta.10

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 (386) hide show
  1. package/lib/cjs/builder/PlatformBuilder.js +286 -0
  2. package/lib/cjs/builder/PlatformBuilder.js.map +1 -0
  3. package/lib/cjs/builder/PlatformControllerBuilder.js +82 -0
  4. package/lib/cjs/builder/PlatformControllerBuilder.js.map +1 -0
  5. package/lib/cjs/config/interfaces/ConverterSettings.js +3 -0
  6. package/lib/cjs/config/interfaces/ConverterSettings.js.map +1 -0
  7. package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js +3 -0
  8. package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js.map +1 -0
  9. package/lib/cjs/config/interfaces/PlatformLoggerSettings.js +3 -0
  10. package/lib/cjs/config/interfaces/PlatformLoggerSettings.js.map +1 -0
  11. package/lib/cjs/config/interfaces/PlatformMulterSettings.js +3 -0
  12. package/lib/cjs/config/interfaces/PlatformMulterSettings.js.map +1 -0
  13. package/lib/cjs/config/interfaces/PlatformStaticsSettings.js +3 -0
  14. package/lib/cjs/config/interfaces/PlatformStaticsSettings.js.map +1 -0
  15. package/lib/cjs/config/services/PlatformConfiguration.js +181 -0
  16. package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -0
  17. package/lib/cjs/constants/routerOptions.js +5 -0
  18. package/lib/cjs/constants/routerOptions.js.map +1 -0
  19. package/lib/cjs/decorators/multer/multerFileSize.js +35 -0
  20. package/lib/cjs/decorators/multer/multerFileSize.js.map +1 -0
  21. package/lib/cjs/decorators/multer/multerOptions.js +52 -0
  22. package/lib/cjs/decorators/multer/multerOptions.js.map +1 -0
  23. package/lib/cjs/decorators/multer/multipartFile.js +78 -0
  24. package/lib/cjs/decorators/multer/multipartFile.js.map +1 -0
  25. package/lib/cjs/decorators/params/error.js +20 -0
  26. package/lib/cjs/decorators/params/error.js.map +1 -0
  27. package/lib/cjs/decorators/params/next.js +21 -0
  28. package/lib/cjs/decorators/params/next.js.map +1 -0
  29. package/lib/cjs/decorators/params/request.js +39 -0
  30. package/lib/cjs/decorators/params/request.js.map +1 -0
  31. package/lib/cjs/decorators/params/response.js +33 -0
  32. package/lib/cjs/decorators/params/response.js.map +1 -0
  33. package/lib/cjs/domain/AnyToPromiseWithCtx.js +27 -0
  34. package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -0
  35. package/lib/cjs/domain/ControllerProvider.js +51 -0
  36. package/lib/cjs/domain/ControllerProvider.js.map +1 -0
  37. package/lib/cjs/domain/EndpointMetadata.js +6 -0
  38. package/lib/cjs/domain/EndpointMetadata.js.map +1 -0
  39. package/lib/cjs/domain/HandlerMetadata.js +57 -0
  40. package/lib/cjs/domain/HandlerMetadata.js.map +1 -0
  41. package/lib/cjs/domain/PlatformContext.js +92 -0
  42. package/lib/cjs/domain/PlatformContext.js.map +1 -0
  43. package/lib/cjs/domain/PlatformRouteDetails.js +24 -0
  44. package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -0
  45. package/lib/cjs/exports.js +31 -0
  46. package/lib/cjs/exports.js.map +1 -0
  47. package/lib/cjs/index.js +70 -0
  48. package/lib/cjs/index.js.map +1 -0
  49. package/lib/cjs/interfaces/AfterInit.js +3 -0
  50. package/lib/cjs/interfaces/AfterInit.js.map +1 -0
  51. package/lib/cjs/interfaces/AfterListen.js +3 -0
  52. package/lib/cjs/interfaces/AfterListen.js.map +1 -0
  53. package/lib/cjs/interfaces/AfterRoutesInit.js +3 -0
  54. package/lib/cjs/interfaces/AfterRoutesInit.js.map +1 -0
  55. package/lib/cjs/interfaces/BeforeInit.js +3 -0
  56. package/lib/cjs/interfaces/BeforeInit.js.map +1 -0
  57. package/lib/cjs/interfaces/BeforeListen.js +3 -0
  58. package/lib/cjs/interfaces/BeforeListen.js.map +1 -0
  59. package/lib/cjs/interfaces/BeforeRoutesInit.js +3 -0
  60. package/lib/cjs/interfaces/BeforeRoutesInit.js.map +1 -0
  61. package/lib/cjs/interfaces/HandlerType.js +17 -0
  62. package/lib/cjs/interfaces/HandlerType.js.map +1 -0
  63. package/lib/cjs/interfaces/IncomingEvent.js +3 -0
  64. package/lib/cjs/interfaces/IncomingEvent.js.map +1 -0
  65. package/lib/cjs/interfaces/OnReady.js +3 -0
  66. package/lib/cjs/interfaces/OnReady.js.map +1 -0
  67. package/lib/cjs/interfaces/OnRequest.js +3 -0
  68. package/lib/cjs/interfaces/OnRequest.js.map +1 -0
  69. package/lib/cjs/interfaces/OnResponse.js +3 -0
  70. package/lib/cjs/interfaces/OnResponse.js.map +1 -0
  71. package/lib/cjs/interfaces/OnRoutesInit.js +3 -0
  72. package/lib/cjs/interfaces/OnRoutesInit.js.map +1 -0
  73. package/lib/cjs/interfaces/PlatformRouteOptions.js +3 -0
  74. package/lib/cjs/interfaces/PlatformRouteOptions.js.map +1 -0
  75. package/lib/cjs/interfaces/ResponseErrorObject.js +3 -0
  76. package/lib/cjs/interfaces/ResponseErrorObject.js.map +1 -0
  77. package/lib/cjs/interfaces/Route.js +3 -0
  78. package/lib/cjs/interfaces/Route.js.map +1 -0
  79. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js +37 -0
  80. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
  81. package/lib/cjs/middlewares/PlatformMulterMiddleware.js +67 -0
  82. package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -0
  83. package/lib/cjs/middlewares/__mock__/FakeCtrl.js +12 -0
  84. package/lib/cjs/middlewares/__mock__/FakeCtrl.js.map +1 -0
  85. package/lib/cjs/middlewares/bindEndpointMiddleware.js +13 -0
  86. package/lib/cjs/middlewares/bindEndpointMiddleware.js.map +1 -0
  87. package/lib/cjs/package.json +3 -0
  88. package/lib/cjs/services/FakeAdapter.js +55 -0
  89. package/lib/cjs/services/FakeAdapter.js.map +1 -0
  90. package/lib/cjs/services/Platform.js +128 -0
  91. package/lib/cjs/services/Platform.js.map +1 -0
  92. package/lib/cjs/services/PlatformAdapter.js +14 -0
  93. package/lib/cjs/services/PlatformAdapter.js.map +1 -0
  94. package/lib/cjs/services/PlatformApplication.js +32 -0
  95. package/lib/cjs/services/PlatformApplication.js.map +1 -0
  96. package/lib/cjs/services/PlatformHandler.js +235 -0
  97. package/lib/cjs/services/PlatformHandler.js.map +1 -0
  98. package/lib/cjs/services/PlatformMiddlewaresChain.js +75 -0
  99. package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -0
  100. package/lib/cjs/services/PlatformRequest.js +138 -0
  101. package/lib/cjs/services/PlatformRequest.js.map +1 -0
  102. package/lib/cjs/services/PlatformResponse.js +271 -0
  103. package/lib/cjs/services/PlatformResponse.js.map +1 -0
  104. package/lib/cjs/services/PlatformRouter.js +108 -0
  105. package/lib/cjs/services/PlatformRouter.js.map +1 -0
  106. package/lib/cjs/services/PlatformTest.js +167 -0
  107. package/lib/cjs/services/PlatformTest.js.map +1 -0
  108. package/lib/cjs/utils/__mock__/Test1.js +8 -0
  109. package/lib/cjs/utils/__mock__/Test1.js.map +1 -0
  110. package/lib/cjs/utils/__mock__/Test2.js +8 -0
  111. package/lib/cjs/utils/__mock__/Test2.js.map +1 -0
  112. package/lib/cjs/utils/createContext.js +38 -0
  113. package/lib/cjs/utils/createContext.js.map +1 -0
  114. package/lib/cjs/utils/createHandlerMetadata.js +49 -0
  115. package/lib/cjs/utils/createHandlerMetadata.js.map +1 -0
  116. package/lib/cjs/utils/createHttpServer.js +29 -0
  117. package/lib/cjs/utils/createHttpServer.js.map +1 -0
  118. package/lib/cjs/utils/createHttpsServer.js +29 -0
  119. package/lib/cjs/utils/createHttpsServer.js.map +1 -0
  120. package/lib/cjs/utils/createInjector.js +46 -0
  121. package/lib/cjs/utils/createInjector.js.map +1 -0
  122. package/lib/cjs/utils/getConfiguration.js +42 -0
  123. package/lib/cjs/utils/getConfiguration.js.map +1 -0
  124. package/lib/cjs/utils/getStaticsOptions.js +21 -0
  125. package/lib/cjs/utils/getStaticsOptions.js.map +1 -0
  126. package/lib/cjs/utils/importProviders.js +29 -0
  127. package/lib/cjs/utils/importProviders.js.map +1 -0
  128. package/lib/cjs/utils/listenServer.js +21 -0
  129. package/lib/cjs/utils/listenServer.js.map +1 -0
  130. package/lib/cjs/utils/mapReturnedResponse.js +15 -0
  131. package/lib/cjs/utils/mapReturnedResponse.js.map +1 -0
  132. package/lib/cjs/utils/printRoutes.js +36 -0
  133. package/lib/cjs/utils/printRoutes.js.map +1 -0
  134. package/lib/cjs/utils/setResponseHeaders.js +35 -0
  135. package/lib/cjs/utils/setResponseHeaders.js.map +1 -0
  136. package/lib/cjs/utils/useCtxHandler.js +15 -0
  137. package/lib/cjs/utils/useCtxHandler.js.map +1 -0
  138. package/lib/esm/builder/PlatformBuilder.js +282 -0
  139. package/lib/esm/builder/PlatformBuilder.js.map +1 -0
  140. package/lib/esm/builder/PlatformControllerBuilder.js +76 -0
  141. package/lib/esm/builder/PlatformControllerBuilder.js.map +1 -0
  142. package/lib/esm/config/interfaces/ConverterSettings.js +2 -0
  143. package/lib/esm/config/interfaces/ConverterSettings.js.map +1 -0
  144. package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js +2 -0
  145. package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js.map +1 -0
  146. package/lib/esm/config/interfaces/PlatformLoggerSettings.js +2 -0
  147. package/lib/esm/config/interfaces/PlatformLoggerSettings.js.map +1 -0
  148. package/lib/esm/config/interfaces/PlatformMulterSettings.js +2 -0
  149. package/lib/esm/config/interfaces/PlatformMulterSettings.js.map +1 -0
  150. package/lib/esm/config/interfaces/PlatformStaticsSettings.js +2 -0
  151. package/lib/esm/config/interfaces/PlatformStaticsSettings.js.map +1 -0
  152. package/lib/esm/config/services/PlatformConfiguration.js +178 -0
  153. package/lib/esm/config/services/PlatformConfiguration.js.map +1 -0
  154. package/lib/esm/constants/routerOptions.js +2 -0
  155. package/lib/esm/constants/routerOptions.js.map +1 -0
  156. package/lib/esm/decorators/multer/multerFileSize.js +31 -0
  157. package/lib/esm/decorators/multer/multerFileSize.js.map +1 -0
  158. package/lib/esm/decorators/multer/multerOptions.js +48 -0
  159. package/lib/esm/decorators/multer/multerOptions.js.map +1 -0
  160. package/lib/esm/decorators/multer/multipartFile.js +74 -0
  161. package/lib/esm/decorators/multer/multipartFile.js.map +1 -0
  162. package/lib/esm/decorators/params/error.js +16 -0
  163. package/lib/esm/decorators/params/error.js.map +1 -0
  164. package/lib/esm/decorators/params/next.js +17 -0
  165. package/lib/esm/decorators/params/next.js.map +1 -0
  166. package/lib/esm/decorators/params/request.js +34 -0
  167. package/lib/esm/decorators/params/request.js.map +1 -0
  168. package/lib/esm/decorators/params/response.js +28 -0
  169. package/lib/esm/decorators/params/response.js.map +1 -0
  170. package/lib/esm/domain/AnyToPromiseWithCtx.js +23 -0
  171. package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -0
  172. package/lib/esm/domain/ControllerProvider.js +47 -0
  173. package/lib/esm/domain/ControllerProvider.js.map +1 -0
  174. package/lib/esm/domain/EndpointMetadata.js +2 -0
  175. package/lib/esm/domain/EndpointMetadata.js.map +1 -0
  176. package/lib/esm/domain/HandlerMetadata.js +53 -0
  177. package/lib/esm/domain/HandlerMetadata.js.map +1 -0
  178. package/lib/esm/domain/PlatformContext.js +88 -0
  179. package/lib/esm/domain/PlatformContext.js.map +1 -0
  180. package/lib/esm/domain/PlatformRouteDetails.js +20 -0
  181. package/lib/esm/domain/PlatformRouteDetails.js.map +1 -0
  182. package/lib/esm/exports.js +13 -0
  183. package/lib/esm/exports.js.map +1 -0
  184. package/lib/esm/index.js +67 -0
  185. package/lib/esm/index.js.map +1 -0
  186. package/lib/esm/interfaces/AfterInit.js +2 -0
  187. package/lib/esm/interfaces/AfterInit.js.map +1 -0
  188. package/lib/esm/interfaces/AfterListen.js +2 -0
  189. package/lib/esm/interfaces/AfterListen.js.map +1 -0
  190. package/lib/esm/interfaces/AfterRoutesInit.js +2 -0
  191. package/lib/esm/interfaces/AfterRoutesInit.js.map +1 -0
  192. package/lib/esm/interfaces/BeforeInit.js +2 -0
  193. package/lib/esm/interfaces/BeforeInit.js.map +1 -0
  194. package/lib/esm/interfaces/BeforeListen.js +2 -0
  195. package/lib/esm/interfaces/BeforeListen.js.map +1 -0
  196. package/lib/esm/interfaces/BeforeRoutesInit.js +2 -0
  197. package/lib/esm/interfaces/BeforeRoutesInit.js.map +1 -0
  198. package/lib/esm/interfaces/HandlerType.js +14 -0
  199. package/lib/esm/interfaces/HandlerType.js.map +1 -0
  200. package/lib/esm/interfaces/IncomingEvent.js +2 -0
  201. package/lib/esm/interfaces/IncomingEvent.js.map +1 -0
  202. package/lib/esm/interfaces/OnReady.js +2 -0
  203. package/lib/esm/interfaces/OnReady.js.map +1 -0
  204. package/lib/esm/interfaces/OnRequest.js +2 -0
  205. package/lib/esm/interfaces/OnRequest.js.map +1 -0
  206. package/lib/esm/interfaces/OnResponse.js +2 -0
  207. package/lib/esm/interfaces/OnResponse.js.map +1 -0
  208. package/lib/esm/interfaces/OnRoutesInit.js +2 -0
  209. package/lib/esm/interfaces/OnRoutesInit.js.map +1 -0
  210. package/lib/esm/interfaces/PlatformRouteOptions.js +2 -0
  211. package/lib/esm/interfaces/PlatformRouteOptions.js.map +1 -0
  212. package/lib/esm/interfaces/ResponseErrorObject.js +2 -0
  213. package/lib/esm/interfaces/ResponseErrorObject.js.map +1 -0
  214. package/lib/esm/interfaces/Route.js +2 -0
  215. package/lib/esm/interfaces/Route.js.map +1 -0
  216. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js +34 -0
  217. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
  218. package/lib/esm/middlewares/PlatformMulterMiddleware.js +63 -0
  219. package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -0
  220. package/lib/esm/middlewares/__mock__/FakeCtrl.js +9 -0
  221. package/lib/esm/middlewares/__mock__/FakeCtrl.js.map +1 -0
  222. package/lib/esm/middlewares/bindEndpointMiddleware.js +9 -0
  223. package/lib/esm/middlewares/bindEndpointMiddleware.js.map +1 -0
  224. package/lib/esm/package.json +3 -0
  225. package/lib/esm/services/FakeAdapter.js +51 -0
  226. package/lib/esm/services/FakeAdapter.js.map +1 -0
  227. package/lib/esm/services/Platform.js +125 -0
  228. package/lib/esm/services/Platform.js.map +1 -0
  229. package/lib/esm/services/PlatformAdapter.js +10 -0
  230. package/lib/esm/services/PlatformAdapter.js.map +1 -0
  231. package/lib/esm/services/PlatformApplication.js +29 -0
  232. package/lib/esm/services/PlatformApplication.js.map +1 -0
  233. package/lib/esm/services/PlatformHandler.js +232 -0
  234. package/lib/esm/services/PlatformHandler.js.map +1 -0
  235. package/lib/esm/services/PlatformMiddlewaresChain.js +72 -0
  236. package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -0
  237. package/lib/esm/services/PlatformRequest.js +135 -0
  238. package/lib/esm/services/PlatformRequest.js.map +1 -0
  239. package/lib/esm/services/PlatformResponse.js +268 -0
  240. package/lib/esm/services/PlatformResponse.js.map +1 -0
  241. package/lib/esm/services/PlatformRouter.js +105 -0
  242. package/lib/esm/services/PlatformRouter.js.map +1 -0
  243. package/lib/esm/services/PlatformTest.js +162 -0
  244. package/lib/esm/services/PlatformTest.js.map +1 -0
  245. package/lib/esm/utils/__mock__/Test1.js +4 -0
  246. package/lib/esm/utils/__mock__/Test1.js.map +1 -0
  247. package/lib/esm/utils/__mock__/Test2.js +4 -0
  248. package/lib/esm/utils/__mock__/Test2.js.map +1 -0
  249. package/lib/esm/utils/createContext.js +34 -0
  250. package/lib/esm/utils/createContext.js.map +1 -0
  251. package/lib/esm/utils/createHandlerMetadata.js +45 -0
  252. package/lib/esm/utils/createHandlerMetadata.js.map +1 -0
  253. package/lib/esm/utils/createHttpServer.js +24 -0
  254. package/lib/esm/utils/createHttpServer.js.map +1 -0
  255. package/lib/esm/utils/createHttpsServer.js +24 -0
  256. package/lib/esm/utils/createHttpsServer.js.map +1 -0
  257. package/lib/esm/utils/createInjector.js +42 -0
  258. package/lib/esm/utils/createInjector.js.map +1 -0
  259. package/lib/esm/utils/getConfiguration.js +38 -0
  260. package/lib/esm/utils/getConfiguration.js.map +1 -0
  261. package/lib/esm/utils/getStaticsOptions.js +17 -0
  262. package/lib/esm/utils/getStaticsOptions.js.map +1 -0
  263. package/lib/esm/utils/importProviders.js +25 -0
  264. package/lib/esm/utils/importProviders.js.map +1 -0
  265. package/lib/esm/utils/listenServer.js +17 -0
  266. package/lib/esm/utils/listenServer.js.map +1 -0
  267. package/lib/esm/utils/mapReturnedResponse.js +11 -0
  268. package/lib/esm/utils/mapReturnedResponse.js.map +1 -0
  269. package/lib/esm/utils/printRoutes.js +32 -0
  270. package/lib/esm/utils/printRoutes.js.map +1 -0
  271. package/lib/esm/utils/setResponseHeaders.js +31 -0
  272. package/lib/esm/utils/setResponseHeaders.js.map +1 -0
  273. package/lib/esm/utils/useCtxHandler.js +11 -0
  274. package/lib/esm/utils/useCtxHandler.js.map +1 -0
  275. package/lib/{builder → types/builder}/PlatformBuilder.d.ts +28 -32
  276. package/lib/types/builder/PlatformControllerBuilder.d.ts +18 -0
  277. package/lib/{config → types/config}/interfaces/ConverterSettings.d.ts +0 -0
  278. package/lib/{config → types/config}/interfaces/EndpointDirectoriesSettings.d.ts +0 -0
  279. package/lib/{config → types/config}/interfaces/PlatformLoggerSettings.d.ts +0 -16
  280. package/lib/types/config/interfaces/PlatformMulterSettings.d.ts +14 -0
  281. package/lib/{config → types/config}/interfaces/PlatformStaticsSettings.d.ts +1 -0
  282. package/lib/{config → types/config}/services/PlatformConfiguration.d.ts +15 -12
  283. package/lib/{constants → types/constants}/routerOptions.d.ts +0 -0
  284. package/lib/{decorators → types/decorators}/multer/multerFileSize.d.ts +0 -0
  285. package/lib/{decorators → types/decorators}/multer/multerOptions.d.ts +0 -0
  286. package/lib/{decorators → types/decorators}/multer/multipartFile.d.ts +0 -0
  287. package/lib/{decorators → types/decorators}/params/error.d.ts +0 -0
  288. package/lib/{decorators → types/decorators}/params/next.d.ts +0 -0
  289. package/lib/{decorators → types/decorators}/params/request.d.ts +0 -0
  290. package/lib/{decorators → types/decorators}/params/response.d.ts +0 -0
  291. package/lib/{domain → types/domain}/AnyToPromiseWithCtx.d.ts +0 -0
  292. package/lib/types/domain/ControllerProvider.d.ts +24 -0
  293. package/lib/types/domain/EndpointMetadata.d.ts +1 -0
  294. package/lib/{domain → types/domain}/HandlerMetadata.d.ts +2 -2
  295. package/lib/{domain → types/domain}/PlatformContext.d.ts +2 -2
  296. package/lib/types/domain/PlatformRouteDetails.d.ts +22 -0
  297. package/lib/types/exports.d.ts +12 -0
  298. package/lib/types/index.d.ts +66 -0
  299. package/lib/{interfaces → types/interfaces}/AfterInit.d.ts +0 -0
  300. package/lib/{interfaces → types/interfaces}/AfterListen.d.ts +0 -0
  301. package/lib/{interfaces → types/interfaces}/AfterRoutesInit.d.ts +0 -0
  302. package/lib/{interfaces → types/interfaces}/BeforeInit.d.ts +0 -0
  303. package/lib/{interfaces → types/interfaces}/BeforeListen.d.ts +0 -0
  304. package/lib/{interfaces → types/interfaces}/BeforeRoutesInit.d.ts +0 -0
  305. package/lib/{interfaces → types/interfaces}/HandlerType.d.ts +0 -0
  306. package/lib/{interfaces → types/interfaces}/IncomingEvent.d.ts +0 -0
  307. package/lib/{interfaces → types/interfaces}/OnReady.d.ts +0 -0
  308. package/lib/{interfaces → types/interfaces}/OnRequest.d.ts +0 -0
  309. package/lib/{interfaces → types/interfaces}/OnResponse.d.ts +0 -0
  310. package/lib/{interfaces → types/interfaces}/OnRoutesInit.d.ts +0 -0
  311. package/lib/{interfaces → types/interfaces}/PlatformRouteOptions.d.ts +6 -4
  312. package/lib/{interfaces → types/interfaces}/ResponseErrorObject.d.ts +0 -0
  313. package/lib/{interfaces → types/interfaces}/Route.d.ts +0 -0
  314. package/lib/{middlewares → types/middlewares}/PlatformAcceptMimesMiddleware.d.ts +0 -0
  315. package/lib/{middlewares → types/middlewares}/PlatformMulterMiddleware.d.ts +8 -3
  316. package/lib/{middlewares/data → types/middlewares/__mock__}/FakeCtrl.d.ts +0 -0
  317. package/lib/types/middlewares/bindEndpointMiddleware.d.ts +6 -0
  318. package/lib/types/services/FakeAdapter.d.ts +30 -0
  319. package/lib/{services → types/services}/Platform.d.ts +22 -7
  320. package/lib/types/services/PlatformAdapter.d.ts +47 -0
  321. package/lib/{services → types/services}/PlatformApplication.d.ts +3 -3
  322. package/lib/{services → types/services}/PlatformHandler.d.ts +4 -9
  323. package/lib/types/services/PlatformMiddlewaresChain.d.ts +10 -0
  324. package/lib/{services → types/services}/PlatformRequest.d.ts +2 -1
  325. package/lib/{services → types/services}/PlatformResponse.d.ts +10 -10
  326. package/lib/{services → types/services}/PlatformRouter.d.ts +13 -9
  327. package/lib/{services → types/services}/PlatformTest.d.ts +6 -5
  328. package/lib/types/utils/__mock__/Test1.d.ts +3 -0
  329. package/lib/types/utils/__mock__/Test2.d.ts +3 -0
  330. package/lib/{utils → types/utils}/createContext.d.ts +0 -0
  331. package/lib/{utils → types/utils}/createHandlerMetadata.d.ts +1 -1
  332. package/lib/types/utils/createHttpServer.d.ts +4 -0
  333. package/lib/types/utils/createHttpsServer.d.ts +5 -0
  334. package/lib/types/utils/createInjector.d.ts +9 -0
  335. package/lib/types/utils/getConfiguration.d.ts +2 -0
  336. package/lib/types/utils/getStaticsOptions.d.ts +5 -0
  337. package/lib/types/utils/importProviders.d.ts +10 -0
  338. package/lib/types/utils/listenServer.d.ts +7 -0
  339. package/lib/{utils → types/utils}/mapReturnedResponse.d.ts +0 -0
  340. package/lib/{utils → types/utils}/printRoutes.d.ts +0 -0
  341. package/lib/{utils → types/utils}/setResponseHeaders.d.ts +0 -0
  342. package/lib/{utils → types/utils}/useCtxHandler.d.ts +0 -0
  343. package/package.json +47 -30
  344. package/readme.md +50 -57
  345. package/tsconfig.compile.esm.json +13 -0
  346. package/lib/PlatformModule.d.ts +0 -15
  347. package/lib/builder/PlatformControllerBuilder.d.ts +0 -19
  348. package/lib/config/index.d.ts +0 -3
  349. package/lib/config/interfaces/PlatformMulterSettings.d.ts +0 -138
  350. package/lib/config/interfaces/index.d.ts +0 -82
  351. package/lib/decorators/class/controller.d.ts +0 -43
  352. package/lib/decorators/httpServer.d.ts +0 -27
  353. package/lib/decorators/httpsServer.d.ts +0 -27
  354. package/lib/decorators/index.d.ts +0 -14
  355. package/lib/decorators/method/acceptMime.d.ts +0 -19
  356. package/lib/decorators/method/endpointFn.d.ts +0 -8
  357. package/lib/decorators/method/location.d.ts +0 -1
  358. package/lib/decorators/method/redirect.d.ts +0 -1
  359. package/lib/decorators/method/route.d.ts +0 -128
  360. package/lib/decorators/multer/index.d.ts +0 -3
  361. package/lib/domain/ControllerProvider.d.ts +0 -54
  362. package/lib/domain/EndpointMetadata.d.ts +0 -89
  363. package/lib/domain/PlatformRouteDetails.d.ts +0 -29
  364. package/lib/domain/index.d.ts +0 -6
  365. package/lib/index.d.ts +0 -21
  366. package/lib/index.js +0 -3990
  367. package/lib/index.js.map +0 -1
  368. package/lib/index.modern.js +0 -3870
  369. package/lib/index.modern.js.map +0 -1
  370. package/lib/interfaces/PathType.d.ts +0 -1
  371. package/lib/interfaces/PlatformRouterMethods.d.ts +0 -10
  372. package/lib/interfaces/index.d.ts +0 -18
  373. package/lib/middlewares/PlatformLogMiddleware.d.ts +0 -44
  374. package/lib/middlewares/bindEndpointMiddleware.d.ts +0 -5
  375. package/lib/middlewares/index.d.ts +0 -4
  376. package/lib/registries/ControllerRegistry.d.ts +0 -1
  377. package/lib/services/ConverterService.d.ts +0 -27
  378. package/lib/services/FakeRawDriver.d.ts +0 -15
  379. package/lib/services/index.d.ts +0 -8
  380. package/lib/utils/createHttpServer.d.ts +0 -3
  381. package/lib/utils/createHttpsServer.d.ts +0 -3
  382. package/lib/utils/createInjector.d.ts +0 -2
  383. package/lib/utils/createPlatformApplication.d.ts +0 -2
  384. package/lib/utils/getControllerPath.d.ts +0 -2
  385. package/lib/utils/index.d.ts +0 -8
  386. package/lib/utils/listenServer.d.ts +0 -10
@@ -0,0 +1,286 @@
1
+ "use strict";
2
+ var _PlatformBuilder_injector, _PlatformBuilder_rootModule, _PlatformBuilder_adapter, _PlatformBuilder_promise, _PlatformBuilder_servers, _PlatformBuilder_listeners;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PlatformBuilder = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const core_1 = require("@tsed/core");
7
+ const di_1 = require("@tsed/di");
8
+ const platform_middlewares_1 = require("@tsed/platform-middlewares");
9
+ const Platform_1 = require("../services/Platform");
10
+ const PlatformApplication_1 = require("../services/PlatformApplication");
11
+ const getStaticsOptions_1 = require("../utils/getStaticsOptions");
12
+ const getConfiguration_1 = require("../utils/getConfiguration");
13
+ const PlatformAdapter_1 = require("../services/PlatformAdapter");
14
+ const importProviders_1 = require("../utils/importProviders");
15
+ const createInjector_1 = require("../utils/createInjector");
16
+ const printRoutes_1 = require("../utils/printRoutes");
17
+ const createHttpServer_1 = require("../utils/createHttpServer");
18
+ const createHttpsServer_1 = require("../utils/createHttpsServer");
19
+ /**
20
+ * @platform
21
+ */
22
+ class PlatformBuilder {
23
+ constructor(adapter, module, settings) {
24
+ this.name = "";
25
+ this.startedAt = new Date();
26
+ this.current = new Date();
27
+ _PlatformBuilder_injector.set(this, void 0);
28
+ _PlatformBuilder_rootModule.set(this, void 0);
29
+ _PlatformBuilder_adapter.set(this, void 0);
30
+ _PlatformBuilder_promise.set(this, void 0);
31
+ _PlatformBuilder_servers.set(this, void 0);
32
+ _PlatformBuilder_listeners.set(this, []);
33
+ tslib_1.__classPrivateFieldSet(this, _PlatformBuilder_rootModule, module, "f");
34
+ const adapterKlass = adapter || PlatformBuilder.adapter;
35
+ const name = (0, core_1.nameOf)(adapterKlass).replace("Platform", "").toLowerCase();
36
+ const configuration = (0, getConfiguration_1.getConfiguration)(settings, module);
37
+ configuration.PLATFORM_NAME = name;
38
+ this.name = name;
39
+ tslib_1.__classPrivateFieldSet(this, _PlatformBuilder_injector, (0, createInjector_1.createInjector)({
40
+ adapter: adapterKlass,
41
+ settings: configuration
42
+ }), "f");
43
+ tslib_1.__classPrivateFieldSet(this, _PlatformBuilder_adapter, tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_injector, "f").get(PlatformAdapter_1.PlatformAdapter), "f");
44
+ this.createHttpServers();
45
+ tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").onInit && tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").onInit();
46
+ this.log("Injector created...");
47
+ }
48
+ get injector() {
49
+ return tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_injector, "f");
50
+ }
51
+ get rootModule() {
52
+ return tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_injector, "f").get(tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_rootModule, "f"));
53
+ }
54
+ get app() {
55
+ return this.injector.get(PlatformApplication_1.PlatformApplication);
56
+ }
57
+ get platform() {
58
+ return this.injector.get(Platform_1.Platform);
59
+ }
60
+ get adapter() {
61
+ return tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f");
62
+ }
63
+ /**
64
+ * Return the settings configured by the decorator @@Configuration@@.
65
+ *
66
+ * ```typescript
67
+ * @Configuration({
68
+ * rootDir: Path.resolve(__dirname),
69
+ * port: 8000,
70
+ * httpsPort: 8080,
71
+ * mount: {
72
+ * "/rest": "${rootDir}/controllers/**\/*.js"
73
+ * }
74
+ * })
75
+ * export class Server {
76
+ * $onInit(){
77
+ * console.log(this.settings); // {rootDir, port, httpsPort,...}
78
+ * }
79
+ * }
80
+ * ```
81
+ *
82
+ * @returns {PlatformConfiguration}
83
+ */
84
+ get settings() {
85
+ return this.injector.settings;
86
+ }
87
+ get logger() {
88
+ return this.injector.logger;
89
+ }
90
+ get disableBootstrapLog() {
91
+ var _a;
92
+ return (_a = this.settings.logger) === null || _a === void 0 ? void 0 : _a.disableBootstrapLog;
93
+ }
94
+ static create(module, settings) {
95
+ return this.build(module, {
96
+ httpsPort: false,
97
+ httpPort: false,
98
+ ...settings,
99
+ disableComponentsScan: true
100
+ });
101
+ }
102
+ static build(module, { adapter, ...settings }) {
103
+ return new PlatformBuilder(adapter, module, settings);
104
+ }
105
+ /**
106
+ * Bootstrap a server application
107
+ * @param module
108
+ * @param settings
109
+ */
110
+ static async bootstrap(module, settings) {
111
+ return this.build(module, settings).bootstrap();
112
+ }
113
+ callback(req, res) {
114
+ if (req && res) {
115
+ return this.app.callback()(req, res);
116
+ }
117
+ return this.app.callback();
118
+ }
119
+ log(...data) {
120
+ return !this.disableBootstrapLog && this.logger.info(...data, this.diff());
121
+ }
122
+ /**
123
+ * Add classes to the components list
124
+ * @param classes
125
+ */
126
+ addComponents(classes) {
127
+ this.settings.componentsScan = this.settings.componentsScan.concat(classes);
128
+ return this;
129
+ }
130
+ /**
131
+ * Add classes decorated by @@Controller@@ to components container.
132
+ *
133
+ * ### Example
134
+ *
135
+ * ```typescript
136
+ * @Controller('/ctrl')
137
+ * class MyController{
138
+ * }
139
+ *
140
+ * platform.addControllers('/rest', [MyController])
141
+ * ```
142
+ *
143
+ * ::: tip
144
+ * If the MyController class isn't decorated, the class will be ignored.
145
+ * :::
146
+ *
147
+ * @param {string} endpoint
148
+ * @param {any[]} controllers
149
+ */
150
+ addControllers(endpoint, controllers) {
151
+ this.settings.mount[endpoint] = (this.settings.mount[endpoint] || []).concat(controllers);
152
+ }
153
+ async runLifecycle() {
154
+ (0, di_1.setLoggerLevel)(this.injector);
155
+ await this.importProviders();
156
+ await this.loadInjector();
157
+ tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").useContext && tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").useContext();
158
+ tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").useRouter && tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").useRouter();
159
+ await this.loadRoutes();
160
+ await this.logRoutes();
161
+ return this;
162
+ }
163
+ async loadInjector() {
164
+ const { injector } = this;
165
+ this.log("Build providers");
166
+ const container = (0, di_1.createContainer)();
167
+ container.addProvider(tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_rootModule, "f"), {
168
+ type: "server:module",
169
+ scope: di_1.ProviderScope.SINGLETON
170
+ });
171
+ await injector.load(container);
172
+ this.log("Settings and injector loaded...");
173
+ await this.callHook("$afterInit");
174
+ }
175
+ async listen(network = true) {
176
+ if (!tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_promise, "f")) {
177
+ await this.bootstrap();
178
+ }
179
+ await this.callHook("$beforeListen");
180
+ if (network) {
181
+ await this.listenServers();
182
+ }
183
+ await this.callHook("$afterListen");
184
+ await this.ready();
185
+ }
186
+ async stop() {
187
+ await this.callHook("$onDestroy");
188
+ await this.injector.destroy();
189
+ tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_listeners, "f").map((server) => {
190
+ return new Promise((resolve) => server.close(() => resolve(undefined)));
191
+ });
192
+ }
193
+ async ready() {
194
+ const { startedAt } = this;
195
+ await this.callHook("$onReady");
196
+ await this.injector.emit("$onServerReady");
197
+ this.log(`Started in ${new Date().getTime() - startedAt.getTime()} ms`);
198
+ }
199
+ async callHook(hook, ...args) {
200
+ const { injector } = this;
201
+ if (!this.disableBootstrapLog) {
202
+ injector.logger.debug(`\x1B[1mCall hook ${hook}\x1B[22m`);
203
+ }
204
+ // Load middlewares for the given hook
205
+ this.loadMiddlewaresFor(hook);
206
+ // call hooks added by providers
207
+ await injector.emit(hook, ...args);
208
+ }
209
+ async loadStatics(hook) {
210
+ const statics = this.settings.get("statics");
211
+ (0, getStaticsOptions_1.getStaticsOptions)(statics).forEach(({ path, options }) => {
212
+ if (options.hook === hook) {
213
+ this.platform.app.statics(path, options);
214
+ }
215
+ });
216
+ }
217
+ useProvider(token, settings) {
218
+ this.injector.addProvider(token, settings);
219
+ return this;
220
+ }
221
+ async bootstrap() {
222
+ tslib_1.__classPrivateFieldSet(this, _PlatformBuilder_promise, tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_promise, "f") || this.runLifecycle(), "f");
223
+ return tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_promise, "f");
224
+ }
225
+ async loadRoutes() {
226
+ var _a;
227
+ tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").beforeLoadRoutes && (await tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").beforeLoadRoutes());
228
+ // istanbul ignore next
229
+ if (((_a = this.settings.logger) === null || _a === void 0 ? void 0 : _a.level) !== "off") {
230
+ const { PlatformLogMiddleware } = await Promise.resolve().then(() => tslib_1.__importStar(require("@tsed/platform-log-middleware")));
231
+ this.app.use(PlatformLogMiddleware);
232
+ }
233
+ this.log("Load routes");
234
+ if (this.rootModule.$beforeRoutesInit) {
235
+ await this.rootModule.$beforeRoutesInit();
236
+ this.rootModule.$beforeRoutesInit = () => { };
237
+ }
238
+ await this.loadStatics("$beforeRoutesInit");
239
+ await this.callHook("$beforeRoutesInit");
240
+ const routes = this.injector.settings.get("routes");
241
+ this.platform.addRoutes(routes);
242
+ await this.callHook("$onRoutesInit");
243
+ await this.loadStatics("$afterRoutesInit");
244
+ await this.callHook("$afterRoutesInit");
245
+ tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").afterLoadRoutes && (await tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_adapter, "f").afterLoadRoutes());
246
+ }
247
+ diff() {
248
+ const ms = di_1.colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);
249
+ this.current = new Date();
250
+ return ms;
251
+ }
252
+ async importProviders() {
253
+ this.injector.logger.debug("Scan components");
254
+ const providers = await (0, importProviders_1.importProviders)(this.injector.settings, ["imports", "mount", "componentsScan"]);
255
+ const routes = providers.filter((provider) => !!provider.route).map(({ route, token }) => ({ route, token }));
256
+ this.settings.set("routes", routes);
257
+ this.log("Providers loaded...");
258
+ }
259
+ /**
260
+ * Load middlewares from configuration for the given hook
261
+ * @param hook
262
+ * @protected
263
+ */
264
+ loadMiddlewaresFor(hook) {
265
+ return (0, platform_middlewares_1.getMiddlewaresForHook)(hook, this.settings, "$beforeRoutesInit").forEach(({ use }) => {
266
+ this.app.use(use);
267
+ });
268
+ }
269
+ createHttpServers() {
270
+ tslib_1.__classPrivateFieldSet(this, _PlatformBuilder_servers, [(0, createHttpServer_1.createHttpServer)(tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_injector, "f"), this.callback()), (0, createHttpsServer_1.createHttpsServer)(tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_injector, "f"), this.callback())].filter(Boolean), "f");
271
+ }
272
+ async listenServers() {
273
+ tslib_1.__classPrivateFieldSet(this, _PlatformBuilder_listeners, await Promise.all(tslib_1.__classPrivateFieldGet(this, _PlatformBuilder_servers, "f").map((cb) => cb && cb())), "f");
274
+ }
275
+ async logRoutes() {
276
+ var _a;
277
+ const { logger, platform } = this;
278
+ this.log("Routes mounted...");
279
+ if (!((_a = this.settings.logger) === null || _a === void 0 ? void 0 : _a.disableRoutesSummary) && !this.disableBootstrapLog) {
280
+ logger.info((0, printRoutes_1.printRoutes)(await this.injector.alterAsync("$logRoutes", platform.getRoutes())));
281
+ }
282
+ }
283
+ }
284
+ exports.PlatformBuilder = PlatformBuilder;
285
+ _PlatformBuilder_injector = new WeakMap(), _PlatformBuilder_rootModule = new WeakMap(), _PlatformBuilder_adapter = new WeakMap(), _PlatformBuilder_promise = new WeakMap(), _PlatformBuilder_servers = new WeakMap(), _PlatformBuilder_listeners = new WeakMap();
286
+ //# sourceMappingURL=PlatformBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformBuilder.ts"],"names":[],"mappings":";;;;;AAAA,qCAAwC;AACxC,iCAA+G;AAC/G,qEAAiE;AACjE,mDAA8C;AAC9C,yEAAoE;AAEpE,kEAA6D;AAE7D,gEAA2D;AAE3D,iEAA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QAAQ,EAAE,mBAAmB,CAAC,CAAC,OAAO,CAAC,CAAC,EAAC,GAAG,EAAC,EAAE,EAAE;YACvF,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC;IAES,iBAAiB;QACzB,+BAAA,IAAI,4BAAY,CAAC,IAAA,mCAAgB,EAAC,+BAAA,IAAI,iCAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAA,qCAAiB,EAAC,+BAAA,IAAI,iCAAU,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAC5H,OAAO,CACC,MAAA,CAAC;IACb,CAAC;IAES,KAAK,CAAC,aAAa;QAC3B,+BAAA,IAAI,8BAAc,MAAM,OAAO,CAAC,GAAG,CAAC,+BAAA,IAAI,gCAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,MAAA,CAAC;IAC7E,CAAC;IAES,KAAK,CAAC,SAAS;;QACvB,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,GAAG,IAAI,CAAC;QAEhC,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAE9B,IAAI,CAAC,CAAA,MAAA,IAAI,CAAC,QAAQ,CAAC,MAAM,0CAAE,oBAAoB,CAAA,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE;YAC5E,MAAM,CAAC,IAAI,CAAC,IAAA,yBAAW,EAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,YAAY,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;SAC9F;IACH,CAAC;CACF;AAvVD,0CAuVC","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {colors, createContainer, InjectorService, ProviderOpts, ProviderScope, setLoggerLevel} from \"@tsed/di\";\nimport {getMiddlewaresForHook} from \"@tsed/platform-middlewares\";\nimport {Platform} from \"../services/Platform\";\nimport {PlatformApplication} from \"../services/PlatformApplication\";\nimport {PlatformStaticsSettings} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {getStaticsOptions} from \"../utils/getStaticsOptions\";\nimport {Route} from \"../interfaces/Route\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport type {IncomingMessage, Server, ServerResponse} from \"http\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../services/PlatformAdapter\";\nimport {importProviders} from \"../utils/importProviders\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {printRoutes} from \"../utils/printRoutes\";\nimport {createHttpServer} from \"../utils/createHttpServer\";\nimport {createHttpsServer} from \"../utils/createHttpsServer\";\nimport type Https from \"https\";\n\n/**\n * @platform\n */\nexport class PlatformBuilder<App = TsED.Application, Router = TsED.Router> {\n public static adapter: Type<PlatformAdapter<any, any>>;\n\n readonly name: string = \"\";\n protected startedAt = new Date();\n protected current = new Date();\n readonly #injector: InjectorService;\n readonly #rootModule: Type<any>;\n readonly #adapter: PlatformAdapter<App, Router>;\n #promise: Promise<this>;\n #servers: (() => Promise<Server | Https.Server>)[];\n #listeners: (Server | Https.Server)[] = [];\n\n protected constructor(adapter: Type<PlatformAdapter<App, Router>> | undefined, module: Type, settings: Partial<TsED.Configuration>) {\n this.#rootModule = module;\n const adapterKlass: Type<PlatformAdapter<App, Router>> = adapter || (PlatformBuilder.adapter as any);\n const name = nameOf(adapterKlass).replace(\"Platform\", \"\").toLowerCase();\n\n const configuration = getConfiguration(settings, module);\n configuration.PLATFORM_NAME = name;\n this.name = name;\n\n this.#injector = createInjector({\n adapter: adapterKlass,\n settings: configuration\n });\n\n this.#adapter = this.#injector.get<PlatformAdapter<App, Router>>(PlatformAdapter)!;\n\n this.createHttpServers();\n\n this.#adapter.onInit && this.#adapter.onInit();\n\n this.log(\"Injector created...\");\n }\n\n get injector(): InjectorService {\n return this.#injector;\n }\n\n get rootModule(): any {\n return this.#injector.get(this.#rootModule);\n }\n\n get app(): PlatformApplication<App, Router> {\n return this.injector.get<PlatformApplication<App, Router>>(PlatformApplication)!;\n }\n\n get platform() {\n return this.injector.get<Platform>(Platform)!;\n }\n\n get adapter() {\n return this.#adapter;\n }\n\n /**\n * Return the settings configured by the decorator @@Configuration@@.\n *\n * ```typescript\n * @Configuration({\n * rootDir: Path.resolve(__dirname),\n * port: 8000,\n * httpsPort: 8080,\n * mount: {\n * \"/rest\": \"${rootDir}/controllers/**\\/*.js\"\n * }\n * })\n * export class Server {\n * $onInit(){\n * console.log(this.settings); // {rootDir, port, httpsPort,...}\n * }\n * }\n * ```\n *\n * @returns {PlatformConfiguration}\n */\n get settings() {\n return this.injector.settings;\n }\n\n get logger() {\n return this.injector.logger;\n }\n\n get disableBootstrapLog() {\n return this.settings.logger?.disableBootstrapLog;\n }\n\n static create<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>) {\n return this.build(module, {\n httpsPort: false,\n httpPort: false,\n ...settings,\n disableComponentsScan: true\n });\n }\n\n static build<App = TsED.Application, Router = TsED.Router>(\n module: Type<any>,\n {adapter, ...settings}: PlatformBuilderSettings<App, Router>\n ) {\n return new PlatformBuilder(adapter, module, settings);\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>) {\n return this.build<App, Router>(module, settings).bootstrap();\n }\n\n callback(): (req: IncomingMessage, res: ServerResponse) => void;\n callback(req: IncomingMessage, res: ServerResponse): void;\n callback(req?: IncomingMessage, res?: ServerResponse) {\n if (req && res) {\n return this.app.callback()(req, res);\n }\n\n return this.app.callback();\n }\n\n log(...data: any[]) {\n return !this.disableBootstrapLog && this.logger.info(...data, this.diff());\n }\n\n /**\n * Add classes to the components list\n * @param classes\n */\n public addComponents(classes: any | any[]) {\n this.settings.componentsScan = this.settings.componentsScan.concat(classes);\n\n return this;\n }\n\n /**\n * Add classes decorated by @@Controller@@ to components container.\n *\n * ### Example\n *\n * ```typescript\n * @Controller('/ctrl')\n * class MyController{\n * }\n *\n * platform.addControllers('/rest', [MyController])\n * ```\n *\n * ::: tip\n * If the MyController class isn't decorated, the class will be ignored.\n * :::\n *\n * @param {string} endpoint\n * @param {any[]} controllers\n */\n public addControllers(endpoint: string, controllers: any | string | (any | string)[]) {\n this.settings.mount[endpoint] = (this.settings.mount[endpoint] || []).concat(controllers);\n }\n\n public async runLifecycle() {\n setLoggerLevel(this.injector);\n\n await this.importProviders();\n await this.loadInjector();\n\n this.#adapter.useContext && this.#adapter.useContext();\n this.#adapter.useRouter && this.#adapter.useRouter();\n\n await this.loadRoutes();\n await this.logRoutes();\n\n return this;\n }\n\n async loadInjector() {\n const {injector} = this;\n this.log(\"Build providers\");\n\n const container = createContainer();\n\n container.addProvider(this.#rootModule, {\n type: \"server:module\",\n scope: ProviderScope.SINGLETON\n });\n\n await injector.load(container);\n\n this.log(\"Settings and injector loaded...\");\n\n await this.callHook(\"$afterInit\");\n }\n\n async listen(network = true) {\n if (!this.#promise) {\n await this.bootstrap();\n }\n\n await this.callHook(\"$beforeListen\");\n\n if (network) {\n await this.listenServers();\n }\n\n await this.callHook(\"$afterListen\");\n\n await this.ready();\n }\n\n async stop() {\n await this.callHook(\"$onDestroy\");\n await this.injector.destroy();\n\n this.#listeners.map((server) => {\n return new Promise((resolve) => server.close(() => resolve(undefined)));\n });\n }\n\n public async ready() {\n const {startedAt} = this;\n\n await this.callHook(\"$onReady\");\n await this.injector.emit(\"$onServerReady\");\n\n this.log(`Started in ${new Date().getTime() - startedAt.getTime()} ms`);\n }\n\n async callHook(hook: string, ...args: any[]) {\n const {injector} = this;\n\n if (!this.disableBootstrapLog) {\n injector.logger.debug(`\\x1B[1mCall hook ${hook}\\x1B[22m`);\n }\n\n // Load middlewares for the given hook\n this.loadMiddlewaresFor(hook);\n\n // call hooks added by providers\n await injector.emit(hook, ...args);\n }\n\n async loadStatics(hook: string): Promise<void> {\n const statics = this.settings.get<PlatformStaticsSettings>(\"statics\");\n\n getStaticsOptions(statics).forEach(({path, options}) => {\n if (options.hook === hook) {\n this.platform.app.statics(path, options);\n }\n });\n }\n\n useProvider(token: Type<any>, settings?: Partial<ProviderOpts>) {\n this.injector.addProvider(token, settings);\n\n return this;\n }\n\n async bootstrap() {\n this.#promise = this.#promise || this.runLifecycle();\n\n return this.#promise;\n }\n\n protected async loadRoutes() {\n this.#adapter.beforeLoadRoutes && (await this.#adapter.beforeLoadRoutes());\n\n // istanbul ignore next\n if (this.settings.logger?.level !== \"off\") {\n const {PlatformLogMiddleware} = await import(\"@tsed/platform-log-middleware\");\n this.app.use(PlatformLogMiddleware);\n }\n\n this.log(\"Load routes\");\n\n if (this.rootModule.$beforeRoutesInit) {\n await this.rootModule.$beforeRoutesInit();\n this.rootModule.$beforeRoutesInit = () => {};\n }\n\n await this.loadStatics(\"$beforeRoutesInit\");\n await this.callHook(\"$beforeRoutesInit\");\n\n const routes = this.injector.settings.get<Route[]>(\"routes\");\n\n this.platform.addRoutes(routes);\n\n await this.callHook(\"$onRoutesInit\");\n\n await this.loadStatics(\"$afterRoutesInit\");\n\n await this.callHook(\"$afterRoutesInit\");\n\n this.#adapter.afterLoadRoutes && (await this.#adapter.afterLoadRoutes());\n }\n\n protected diff() {\n const ms = colors.yellow(`+${new Date().getTime() - this.current.getTime()}ms`);\n this.current = new Date();\n return ms;\n }\n\n protected async importProviders() {\n this.injector.logger.debug(\"Scan components\");\n\n const providers = await importProviders(this.injector.settings, [\"imports\", \"mount\", \"componentsScan\"]);\n const routes = providers.filter((provider) => !!provider.route).map(({route, token}) => ({route, token}));\n\n this.settings.set(\"routes\", routes);\n this.log(\"Providers loaded...\");\n }\n\n /**\n * Load middlewares from configuration for the given hook\n * @param hook\n * @protected\n */\n protected loadMiddlewaresFor(hook: string): void {\n return getMiddlewaresForHook(hook, this.settings, \"$beforeRoutesInit\").forEach(({use}) => {\n this.app.use(use);\n });\n }\n\n protected createHttpServers() {\n this.#servers = [createHttpServer(this.#injector, this.callback()), createHttpsServer(this.#injector, this.callback())].filter(\n Boolean\n ) as any[];\n }\n\n protected async listenServers(): Promise<void> {\n this.#listeners = await Promise.all(this.#servers.map((cb) => cb && cb()));\n }\n\n protected async logRoutes() {\n const {logger, platform} = this;\n\n this.log(\"Routes mounted...\");\n\n if (!this.settings.logger?.disableRoutesSummary && !this.disableBootstrapLog) {\n logger.info(printRoutes(await this.injector.alterAsync(\"$logRoutes\", platform.getRoutes())));\n }\n }\n}\n"]}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildRouter = exports.createRouter = exports.getRouter = void 0;
4
+ const di_1 = require("@tsed/di");
5
+ const schema_1 = require("@tsed/schema");
6
+ const ControllerProvider_1 = require("../domain/ControllerProvider");
7
+ const PlatformRouter_1 = require("../services/PlatformRouter");
8
+ const PlatformMiddlewaresChain_1 = require("../services/PlatformMiddlewaresChain");
9
+ di_1.GlobalProviders.createRegistry(di_1.ProviderType.CONTROLLER, ControllerProvider_1.ControllerProvider, {
10
+ onInvoke(provider, locals, { injector }) {
11
+ const router = createRouter(injector, provider);
12
+ locals.set(PlatformRouter_1.PlatformRouter, router);
13
+ }
14
+ });
15
+ /**
16
+ * @ignore
17
+ */
18
+ function formatMethod(method) {
19
+ return (method === schema_1.OperationMethods.CUSTOM ? "use" : method || "use").toLowerCase();
20
+ }
21
+ /**
22
+ * @ignore
23
+ */
24
+ function getRouter(injector, provider) {
25
+ return injector.get(provider.tokenRouter);
26
+ }
27
+ exports.getRouter = getRouter;
28
+ /**
29
+ * @ignore
30
+ */
31
+ function createRouter(injector, provider) {
32
+ const token = provider.tokenRouter;
33
+ if (injector.has(token)) {
34
+ return getRouter(injector, provider);
35
+ }
36
+ const router = PlatformRouter_1.PlatformRouter.create(injector, provider.routerOptions);
37
+ return injector
38
+ .add(token, {
39
+ useValue: router
40
+ })
41
+ .invoke(token);
42
+ }
43
+ exports.createRouter = createRouter;
44
+ /**
45
+ * @ignore
46
+ * @param injector
47
+ * @param provider
48
+ * @param parentUseBefore
49
+ */
50
+ function buildRouter(injector, provider, parentUseBefore = []) {
51
+ const { middlewares: { useBefore }, children } = provider;
52
+ // Controller lifecycle
53
+ const router = createRouter(injector, provider);
54
+ if (!router.isBuilt) {
55
+ router.isBuilt = true;
56
+ const platformMiddlewaresChain = injector.get(PlatformMiddlewaresChain_1.PlatformMiddlewaresChain);
57
+ // build all endpoints and his middlewares
58
+ (0, schema_1.getOperationsRoutes)(provider.token).forEach((operationRoute) => {
59
+ const handlers = platformMiddlewaresChain === null || platformMiddlewaresChain === void 0 ? void 0 : platformMiddlewaresChain.get(provider, operationRoute, parentUseBefore);
60
+ router.addRoute({
61
+ handlers,
62
+ token: operationRoute.token,
63
+ method: formatMethod(operationRoute.method),
64
+ path: operationRoute.path,
65
+ isFinal: operationRoute.isFinal
66
+ });
67
+ });
68
+ const middlewares = [...parentUseBefore, ...useBefore];
69
+ // build children controllers
70
+ children.forEach((child) => {
71
+ const childProvider = injector.getProvider(child);
72
+ /* istanbul ignore next */
73
+ if (!childProvider) {
74
+ throw new Error("Controller component not found in the ControllerRegistry");
75
+ }
76
+ router.use(childProvider.path, buildRouter(injector, childProvider, middlewares));
77
+ });
78
+ }
79
+ return router;
80
+ }
81
+ exports.buildRouter = buildRouter;
82
+ //# sourceMappingURL=PlatformControllerBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformControllerBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformControllerBuilder.ts"],"names":[],"mappings":";;;AACA,iCAAwE;AACxE,yCAAmE;AACnE,qEAAgE;AAChE,+DAA0D;AAC1D,mFAA8E;AAE9E,oBAAe,CAAC,cAAc,CAAC,iBAAY,CAAC,UAAU,EAAE,uCAAkB,EAAE;IAC1E,QAAQ,CAAC,QAA4B,EAAE,MAAW,EAAE,EAAC,QAAQ,EAAC;QAC5D,MA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perationsRoutes, OperationMethods} from \"@tsed/schema\";\nimport {ControllerProvider} from \"../domain/ControllerProvider\";\nimport {PlatformRouter} from \"../services/PlatformRouter\";\nimport {PlatformMiddlewaresChain} from \"../services/PlatformMiddlewaresChain\";\n\nGlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {\n onInvoke(provider: ControllerProvider, locals: any, {injector}) {\n const router = createRouter(injector, provider);\n locals.set(PlatformRouter, router);\n }\n});\n\n/**\n * @ignore\n */\nfunction formatMethod(method: string | undefined) {\n return (method === OperationMethods.CUSTOM ? \"use\" : method || \"use\").toLowerCase();\n}\n\n/**\n * @ignore\n */\nexport function getRouter(injector: InjectorService, provider: ControllerProvider) {\n return injector.get(provider.tokenRouter)!;\n}\n\n/**\n * @ignore\n */\nexport function createRouter(injector: InjectorService, provider: ControllerProvider): PlatformRouter {\n const token = provider.tokenRouter;\n\n if (injector.has(token)) {\n return getRouter(injector, provider);\n }\n\n const router = PlatformRouter.create(injector, provider.routerOptions);\n\n return injector\n .add(token, {\n useValue: router\n })\n .invoke<PlatformRouter>(token);\n}\n\n/**\n * @ignore\n * @param injector\n * @param provider\n * @param parentUseBefore\n */\nexport function buildRouter(injector: InjectorService, provider: ControllerProvider, parentUseBefore: any[] = []) {\n const {\n middlewares: {useBefore},\n children\n } = provider;\n\n // Controller lifecycle\n const router = createRouter(injector, provider);\n\n if (!router.isBuilt) {\n router.isBuilt = true;\n\n const platformMiddlewaresChain = injector.get<PlatformMiddlewaresChain>(PlatformMiddlewaresChain);\n\n // build all endpoints and his middlewares\n getOperationsRoutes(provider.token).forEach((operationRoute) => {\n const handlers = platformMiddlewaresChain?.get(provider, operationRoute, parentUseBefore);\n\n router.addRoute({\n handlers,\n token: operationRoute.token,\n method: formatMethod(operationRoute.method),\n path: operationRoute.path,\n isFinal: operationRoute.isFinal\n });\n });\n\n const middlewares: any[] = [...parentUseBefore, ...useBefore];\n // build children controllers\n children.forEach((child: Type<any>) => {\n const childProvider = injector.getProvider(child) as ControllerProvider;\n\n /* istanbul ignore next */\n if (!childProvider) {\n throw new Error(\"Controller component not found in the ControllerRegistry\");\n }\n\n router.use(childProvider.path, buildRouter(injector, childProvider, middlewares));\n });\n }\n\n return router;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ConverterSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConverterSettings.js","sourceRoot":"","sources":["../../../../src/config/interfaces/ConverterSettings.ts"],"names":[],"mappings":"","sourcesContent":["export interface ConverterSettings {\n /**\n * Converter additional property policy. (see [Converters](/docs/converters.md))\n */\n additionalProperties?: \"error\" | \"accept\" | \"ignore\";\n}\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=EndpointDirectoriesSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EndpointDirectoriesSettings.js","sourceRoot":"","sources":["../../../../src/config/interfaces/EndpointDirectoriesSettings.ts"],"names":[],"mappings":"","sourcesContent":["export interface EndpointDirectoriesSettings {\n [endpoint: string]: any | string | (any | string)[];\n}\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=PlatformLoggerSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformLoggerSettings.js","sourceRoot":"","sources":["../../../../src/config/interfaces/PlatformLoggerSettings.ts"],"names":[],"mappings":"","sourcesContent":["export interface PlatformLoggerSettings {\n /**\n * Enable debug mode. By default debug is false.\n */\n debug?: boolean;\n /**\n * Enable info mode. By default debug is false.\n */\n level?: \"debug\" | \"info\" | \"warn\" | \"error\" | \"off\";\n /**\n * Enable log performance tracker and disable log server.\n */\n perf?: boolean;\n /**\n * List of regexp to ignore log.\n */\n ignoreUrlPatterns?: string[];\n /**\n * The number of space characters to use as white space in JSON output. Default is 2 (0 in production).\n */\n jsonIndentation?: number;\n /**\n * A function called for each incoming request to create a request id.\n * @returns {number}\n */\n reqIdBuilder?: (req: TsED.Request) => string;\n /**\n * Disable routes table displayed in the logger. By default debug is `false`.\n */\n disableRoutesSummary?: boolean;\n /**\n * Disable bootstrap log displayed in the logger. By default debug is `false`.\n */\n disableBootstrapLog?: boolean;\n /**\n * Specify log format. Example: `%[%d{[yyyy-MM-dd hh:mm:ss,SSS}] %p%] %m`. See [@tsed/logger configuration](https://tsedio.github.io/logger/).\n */\n format?: string;\n /**\n * Specify the log stack size for the context.logger. When the stack.length is reach, the logger is flushed during the request.\n * Default size is set to 30.\n */\n maxStackSize?: number;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=PlatformMulterSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformMulterSettings.js","sourceRoot":"","sources":["../../../../src/config/interfaces/PlatformMulterSettings.ts"],"names":[],"mappings":"","sourcesContent":["import type {Express} from \"express\";\nimport type multer from \"multer\";\n\ndeclare global {\n namespace TsED {\n export type MulterFile = Express.Multer.File;\n export type MulterStorageEngine = multer.StorageEngine;\n export type MulterOptions = multer.Options;\n export type MulterField = multer.Field;\n export type Multer = multer.Multer;\n }\n}\n\nexport type PlatformMulter = TsED.Multer;\nexport type PlatformMulterSettings = TsED.MulterOptions;\nexport type PlatformMulterFile = TsED.MulterFile;\nexport type PlatformMulterField = TsED.MulterField;\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=PlatformStaticsSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformStaticsSettings.js","sourceRoot":"","sources":["../../../../src/config/interfaces/PlatformStaticsSettings.ts"],"names":[],"mappings":"","sourcesContent":["declare global {\n namespace TsED {\n // @ts-ignore\n export interface StaticsOptions {\n root: string;\n hook?: \"$beforeRoutesInit\" | \"$afterRoutesInit\";\n\n [key: string]: any;\n }\n }\n}\n\nexport interface PlatformStaticsOptions extends TsED.StaticsOptions {\n root: string;\n\n [key: string]: any;\n}\n\nexport type PathOrStaticsOptions = string | PlatformStaticsOptions;\n\nexport interface PlatformStaticsSettings {\n [endpoint: string]: PathOrStaticsOptions | PathOrStaticsOptions[];\n}\n"]}
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlatformConfiguration = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const core_1 = require("@tsed/core");
6
+ const di_1 = require("@tsed/di");
7
+ const logger_1 = require("@tsed/logger");
8
+ const rootDir = process.cwd();
9
+ /**
10
+ * `PlatformConfiguration` contains all information about your Server configuration.
11
+ */
12
+ let PlatformConfiguration = class PlatformConfiguration extends di_1.DIConfiguration {
13
+ constructor() {
14
+ super({ rootDir });
15
+ }
16
+ get version() {
17
+ return this.getRaw("version");
18
+ }
19
+ set version(v) {
20
+ this.setRaw("version", v);
21
+ }
22
+ get rootDir() {
23
+ return this.getRaw("rootDir");
24
+ }
25
+ set rootDir(value) {
26
+ this.setRaw("rootDir", value);
27
+ }
28
+ get port() {
29
+ return this.httpPort;
30
+ }
31
+ set port(value) {
32
+ this.httpPort = value;
33
+ }
34
+ get httpsOptions() {
35
+ return this.getRaw("httpsOptions");
36
+ }
37
+ set httpsOptions(value) {
38
+ this.setRaw("httpsOptions", value);
39
+ }
40
+ get httpPort() {
41
+ return this.getRaw("httpPort");
42
+ }
43
+ set httpPort(value) {
44
+ this.setRaw("httpPort", value);
45
+ }
46
+ get httpsPort() {
47
+ return this.getRaw("httpsPort");
48
+ }
49
+ set httpsPort(value) {
50
+ this.setRaw("httpsPort", value);
51
+ }
52
+ get env() {
53
+ return this.getRaw("env");
54
+ }
55
+ set env(value) {
56
+ this.setRaw("env", value);
57
+ }
58
+ get mount() {
59
+ return this.get("mount");
60
+ }
61
+ set mount(value) {
62
+ this.setRaw("mount", value);
63
+ }
64
+ get componentsScan() {
65
+ return this.resolve(this.getRaw("componentsScan"));
66
+ }
67
+ set componentsScan(value) {
68
+ this.setRaw("componentsScan", value);
69
+ }
70
+ get statics() {
71
+ return this.getRaw("statics") || this.getRaw("serveStatic") || {};
72
+ }
73
+ set statics(value) {
74
+ this.setRaw("statics", value);
75
+ }
76
+ get acceptMimes() {
77
+ return this.getRaw("acceptMimes");
78
+ }
79
+ set acceptMimes(value) {
80
+ this.setRaw("acceptMimes", value || []);
81
+ }
82
+ get debug() {
83
+ return this.logger.level === "debug";
84
+ }
85
+ set debug(debug) {
86
+ this.logger = { ...this.logger, level: debug ? "debug" : "info" };
87
+ }
88
+ get converter() {
89
+ return this.get("converter") || {};
90
+ }
91
+ set converter(options) {
92
+ this.setRaw("converter", options);
93
+ }
94
+ get logger() {
95
+ return this.get("logger");
96
+ }
97
+ set logger(value) {
98
+ const logger = { ...this.logger, ...value };
99
+ logger.debug = logger.level === "debug";
100
+ this.setRaw("logger", logger);
101
+ this.setRaw("debug", logger.debug);
102
+ if (logger.format) {
103
+ logger_1.$log.appenders.set("stdout", {
104
+ type: "stdout",
105
+ levels: ["info", "debug"],
106
+ layout: {
107
+ type: "pattern",
108
+ pattern: logger.format
109
+ }
110
+ });
111
+ logger_1.$log.appenders.set("stderr", {
112
+ levels: ["trace", "fatal", "error", "warn"],
113
+ type: "stderr",
114
+ layout: {
115
+ type: "pattern",
116
+ pattern: logger.format
117
+ }
118
+ });
119
+ }
120
+ }
121
+ get exclude() {
122
+ return this.get("exclude");
123
+ }
124
+ set exclude(exclude) {
125
+ this.setRaw("exclude", exclude);
126
+ }
127
+ get additionalProperties() {
128
+ return this.get("converter.additionalProperties") === "accept";
129
+ }
130
+ /**
131
+ *
132
+ * @returns {string|number}
133
+ */
134
+ getHttpPort() {
135
+ return (0, core_1.getHostInfoFromPort)("http", this.getRaw("httpPort"));
136
+ }
137
+ /**
138
+ *
139
+ * @param settings
140
+ */
141
+ setHttpPort(settings) {
142
+ this.setRaw("httpPort", `${settings.address}:${settings.port}`);
143
+ }
144
+ /**
145
+ *
146
+ * @returns {string|number}
147
+ */
148
+ getHttpsPort() {
149
+ return (0, core_1.getHostInfoFromPort)("https", this.getRaw("httpsPort"));
150
+ }
151
+ /**
152
+ *
153
+ * @param settings
154
+ */
155
+ setHttpsPort(settings) {
156
+ this.setRaw("httpsPort", `${settings.address}:${settings.port}`);
157
+ }
158
+ getBestHost() {
159
+ const { httpsPort, httpPort } = this;
160
+ if (httpsPort) {
161
+ return this.getHttpsPort();
162
+ }
163
+ if (httpPort) {
164
+ return this.getHttpPort();
165
+ }
166
+ return {
167
+ toString() {
168
+ return "/";
169
+ }
170
+ };
171
+ }
172
+ };
173
+ PlatformConfiguration = tslib_1.__decorate([
174
+ (0, di_1.Injectable)({
175
+ scope: di_1.ProviderScope.SINGLETON,
176
+ global: true
177
+ }),
178
+ tslib_1.__metadata("design:paramtypes", [])
179
+ ], PlatformConfiguration);
180
+ exports.PlatformConfiguration = PlatformConfiguration;
181
+ //# sourceMappingURL=PlatformConfiguration.js.map