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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (414) hide show
  1. package/lib/cjs/builder/PlatformBuilder.js +281 -0
  2. package/lib/cjs/builder/PlatformBuilder.js.map +1 -0
  3. package/lib/cjs/builder/PlatformControllerBuilder.js +82 -0
  4. package/lib/cjs/builder/PlatformControllerBuilder.js.map +1 -0
  5. package/lib/cjs/config/interfaces/ConverterSettings.js +3 -0
  6. package/lib/cjs/config/interfaces/ConverterSettings.js.map +1 -0
  7. package/lib/cjs/config/interfaces/PlatformLoggerSettings.js +3 -0
  8. package/lib/cjs/config/interfaces/PlatformLoggerSettings.js.map +1 -0
  9. package/lib/cjs/config/interfaces/PlatformMulterSettings.js +3 -0
  10. package/lib/cjs/config/interfaces/PlatformMulterSettings.js.map +1 -0
  11. package/lib/cjs/config/interfaces/PlatformStaticsSettings.js +3 -0
  12. package/lib/cjs/config/interfaces/PlatformStaticsSettings.js.map +1 -0
  13. package/lib/cjs/config/services/PlatformConfiguration.js +187 -0
  14. package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -0
  15. package/lib/cjs/constants/routerOptions.js +5 -0
  16. package/lib/cjs/constants/routerOptions.js.map +1 -0
  17. package/lib/cjs/decorators/multer/multerFileSize.js +35 -0
  18. package/lib/cjs/decorators/multer/multerFileSize.js.map +1 -0
  19. package/lib/cjs/decorators/multer/multerOptions.js +52 -0
  20. package/lib/cjs/decorators/multer/multerOptions.js.map +1 -0
  21. package/lib/cjs/decorators/multer/multipartFile.js +78 -0
  22. package/lib/cjs/decorators/multer/multipartFile.js.map +1 -0
  23. package/lib/cjs/decorators/params/error.js +20 -0
  24. package/lib/cjs/decorators/params/error.js.map +1 -0
  25. package/lib/cjs/decorators/params/next.js +21 -0
  26. package/lib/cjs/decorators/params/next.js.map +1 -0
  27. package/lib/cjs/decorators/params/request.js +39 -0
  28. package/lib/cjs/decorators/params/request.js.map +1 -0
  29. package/lib/cjs/decorators/params/response.js +33 -0
  30. package/lib/cjs/decorators/params/response.js.map +1 -0
  31. package/lib/cjs/domain/AnyToPromiseWithCtx.js +27 -0
  32. package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -0
  33. package/lib/cjs/domain/ControllerProvider.js +51 -0
  34. package/lib/cjs/domain/ControllerProvider.js.map +1 -0
  35. package/lib/cjs/domain/EndpointMetadata.js +6 -0
  36. package/lib/cjs/domain/EndpointMetadata.js.map +1 -0
  37. package/lib/cjs/domain/HandlerMetadata.js +57 -0
  38. package/lib/cjs/domain/HandlerMetadata.js.map +1 -0
  39. package/lib/cjs/domain/PlatformContext.js +92 -0
  40. package/lib/cjs/domain/PlatformContext.js.map +1 -0
  41. package/lib/cjs/domain/PlatformRouteDetails.js +24 -0
  42. package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -0
  43. package/lib/cjs/exports.js +31 -0
  44. package/lib/cjs/exports.js.map +1 -0
  45. package/lib/cjs/index.js +68 -0
  46. package/lib/cjs/index.js.map +1 -0
  47. package/lib/cjs/interfaces/AfterInit.js +3 -0
  48. package/lib/cjs/interfaces/AfterInit.js.map +1 -0
  49. package/lib/cjs/interfaces/AfterListen.js +3 -0
  50. package/lib/cjs/interfaces/AfterListen.js.map +1 -0
  51. package/lib/cjs/interfaces/AfterRoutesInit.js +3 -0
  52. package/lib/cjs/interfaces/AfterRoutesInit.js.map +1 -0
  53. package/lib/cjs/interfaces/BeforeInit.js +3 -0
  54. package/lib/cjs/interfaces/BeforeInit.js.map +1 -0
  55. package/lib/cjs/interfaces/BeforeListen.js +3 -0
  56. package/lib/cjs/interfaces/BeforeListen.js.map +1 -0
  57. package/lib/cjs/interfaces/BeforeRoutesInit.js +3 -0
  58. package/lib/cjs/interfaces/BeforeRoutesInit.js.map +1 -0
  59. package/lib/cjs/interfaces/HandlerType.js +17 -0
  60. package/lib/cjs/interfaces/HandlerType.js.map +1 -0
  61. package/lib/cjs/interfaces/IncomingEvent.js +3 -0
  62. package/lib/cjs/interfaces/IncomingEvent.js.map +1 -0
  63. package/lib/cjs/interfaces/OnReady.js +3 -0
  64. package/lib/cjs/interfaces/OnReady.js.map +1 -0
  65. package/lib/cjs/interfaces/OnRequest.js +3 -0
  66. package/lib/cjs/interfaces/OnRequest.js.map +1 -0
  67. package/lib/cjs/interfaces/OnResponse.js +3 -0
  68. package/lib/cjs/interfaces/OnResponse.js.map +1 -0
  69. package/lib/cjs/interfaces/OnRoutesInit.js +3 -0
  70. package/lib/cjs/interfaces/OnRoutesInit.js.map +1 -0
  71. package/lib/cjs/interfaces/PlatformRouteOptions.js +3 -0
  72. package/lib/cjs/interfaces/PlatformRouteOptions.js.map +1 -0
  73. package/lib/cjs/interfaces/ResponseErrorObject.js +3 -0
  74. package/lib/cjs/interfaces/ResponseErrorObject.js.map +1 -0
  75. package/lib/cjs/interfaces/Route.js +3 -0
  76. package/lib/cjs/interfaces/Route.js.map +1 -0
  77. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js +37 -0
  78. package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
  79. package/lib/cjs/middlewares/PlatformMulterMiddleware.js +67 -0
  80. package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -0
  81. package/lib/cjs/middlewares/__mock__/FakeCtrl.js +12 -0
  82. package/lib/cjs/middlewares/__mock__/FakeCtrl.js.map +1 -0
  83. package/lib/cjs/middlewares/bindEndpointMiddleware.js +13 -0
  84. package/lib/cjs/middlewares/bindEndpointMiddleware.js.map +1 -0
  85. package/lib/cjs/package.json +3 -0
  86. package/lib/cjs/services/FakeAdapter.js +55 -0
  87. package/lib/cjs/services/FakeAdapter.js.map +1 -0
  88. package/lib/cjs/services/Platform.js +128 -0
  89. package/lib/cjs/services/Platform.js.map +1 -0
  90. package/lib/cjs/services/PlatformAdapter.js +14 -0
  91. package/lib/cjs/services/PlatformAdapter.js.map +1 -0
  92. package/lib/cjs/services/PlatformApplication.js +32 -0
  93. package/lib/cjs/services/PlatformApplication.js.map +1 -0
  94. package/lib/cjs/services/PlatformHandler.js +235 -0
  95. package/lib/cjs/services/PlatformHandler.js.map +1 -0
  96. package/lib/cjs/services/PlatformMiddlewaresChain.js +75 -0
  97. package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -0
  98. package/lib/cjs/services/PlatformRequest.js +138 -0
  99. package/lib/cjs/services/PlatformRequest.js.map +1 -0
  100. package/lib/cjs/services/PlatformResponse.js +271 -0
  101. package/lib/cjs/services/PlatformResponse.js.map +1 -0
  102. package/lib/cjs/services/PlatformRouter.js +108 -0
  103. package/lib/cjs/services/PlatformRouter.js.map +1 -0
  104. package/lib/cjs/services/PlatformTest.js +173 -0
  105. package/lib/cjs/services/PlatformTest.js.map +1 -0
  106. package/lib/cjs/utils/__mock__/Test1.js +8 -0
  107. package/lib/cjs/utils/__mock__/Test1.js.map +1 -0
  108. package/lib/cjs/utils/__mock__/Test2.js +8 -0
  109. package/lib/cjs/utils/__mock__/Test2.js.map +1 -0
  110. package/lib/cjs/utils/__mock__/controllers/rest/TestCtrl.js +12 -0
  111. package/lib/cjs/utils/__mock__/controllers/rest/TestCtrl.js.map +1 -0
  112. package/lib/cjs/utils/__mock__/module1/Module1.js +19 -0
  113. package/lib/cjs/utils/__mock__/module1/Module1.js.map +1 -0
  114. package/lib/cjs/utils/__mock__/module1/controllers/M1Ctrl1.js +17 -0
  115. package/lib/cjs/utils/__mock__/module1/controllers/M1Ctrl1.js.map +1 -0
  116. package/lib/cjs/utils/__mock__/module1/services/M1Service.js +17 -0
  117. package/lib/cjs/utils/__mock__/module1/services/M1Service.js.map +1 -0
  118. package/lib/cjs/utils/__mock__/module1/submodule/SubModule.js +15 -0
  119. package/lib/cjs/utils/__mock__/module1/submodule/SubModule.js.map +1 -0
  120. package/lib/cjs/utils/__mock__/module1/submodule/SubService.js +12 -0
  121. package/lib/cjs/utils/__mock__/module1/submodule/SubService.js.map +1 -0
  122. package/lib/cjs/utils/__mock__/module2/Module2.js +18 -0
  123. package/lib/cjs/utils/__mock__/module2/Module2.js.map +1 -0
  124. package/lib/cjs/utils/__mock__/module2/controllers/M2Ctrl.js +12 -0
  125. package/lib/cjs/utils/__mock__/module2/controllers/M2Ctrl.js.map +1 -0
  126. package/lib/cjs/utils/createContext.js +38 -0
  127. package/lib/cjs/utils/createContext.js.map +1 -0
  128. package/lib/cjs/utils/createHandlerMetadata.js +49 -0
  129. package/lib/cjs/utils/createHandlerMetadata.js.map +1 -0
  130. package/lib/cjs/utils/createHttpServer.js +29 -0
  131. package/lib/cjs/utils/createHttpServer.js.map +1 -0
  132. package/lib/cjs/utils/createHttpsServer.js +29 -0
  133. package/lib/cjs/utils/createHttpsServer.js.map +1 -0
  134. package/lib/cjs/utils/createInjector.js +46 -0
  135. package/lib/cjs/utils/createInjector.js.map +1 -0
  136. package/lib/cjs/utils/getConfiguration.js +46 -0
  137. package/lib/cjs/utils/getConfiguration.js.map +1 -0
  138. package/lib/cjs/utils/getStaticsOptions.js +21 -0
  139. package/lib/cjs/utils/getStaticsOptions.js.map +1 -0
  140. package/lib/cjs/utils/listenServer.js +21 -0
  141. package/lib/cjs/utils/listenServer.js.map +1 -0
  142. package/lib/cjs/utils/mapReturnedResponse.js +15 -0
  143. package/lib/cjs/utils/mapReturnedResponse.js.map +1 -0
  144. package/lib/cjs/utils/printRoutes.js +36 -0
  145. package/lib/cjs/utils/printRoutes.js.map +1 -0
  146. package/lib/cjs/utils/setResponseHeaders.js +35 -0
  147. package/lib/cjs/utils/setResponseHeaders.js.map +1 -0
  148. package/lib/cjs/utils/useCtxHandler.js +15 -0
  149. package/lib/cjs/utils/useCtxHandler.js.map +1 -0
  150. package/lib/esm/builder/PlatformBuilder.js +277 -0
  151. package/lib/esm/builder/PlatformBuilder.js.map +1 -0
  152. package/lib/esm/builder/PlatformControllerBuilder.js +76 -0
  153. package/lib/esm/builder/PlatformControllerBuilder.js.map +1 -0
  154. package/lib/esm/config/interfaces/ConverterSettings.js +2 -0
  155. package/lib/esm/config/interfaces/ConverterSettings.js.map +1 -0
  156. package/lib/esm/config/interfaces/PlatformLoggerSettings.js +2 -0
  157. package/lib/esm/config/interfaces/PlatformLoggerSettings.js.map +1 -0
  158. package/lib/esm/config/interfaces/PlatformMulterSettings.js +2 -0
  159. package/lib/esm/config/interfaces/PlatformMulterSettings.js.map +1 -0
  160. package/lib/esm/config/interfaces/PlatformStaticsSettings.js +2 -0
  161. package/lib/esm/config/interfaces/PlatformStaticsSettings.js.map +1 -0
  162. package/lib/esm/config/services/PlatformConfiguration.js +184 -0
  163. package/lib/esm/config/services/PlatformConfiguration.js.map +1 -0
  164. package/lib/esm/constants/routerOptions.js +2 -0
  165. package/lib/esm/constants/routerOptions.js.map +1 -0
  166. package/lib/esm/decorators/multer/multerFileSize.js +31 -0
  167. package/lib/esm/decorators/multer/multerFileSize.js.map +1 -0
  168. package/lib/esm/decorators/multer/multerOptions.js +48 -0
  169. package/lib/esm/decorators/multer/multerOptions.js.map +1 -0
  170. package/lib/esm/decorators/multer/multipartFile.js +74 -0
  171. package/lib/esm/decorators/multer/multipartFile.js.map +1 -0
  172. package/lib/esm/decorators/params/error.js +16 -0
  173. package/lib/esm/decorators/params/error.js.map +1 -0
  174. package/lib/esm/decorators/params/next.js +17 -0
  175. package/lib/esm/decorators/params/next.js.map +1 -0
  176. package/lib/esm/decorators/params/request.js +34 -0
  177. package/lib/esm/decorators/params/request.js.map +1 -0
  178. package/lib/esm/decorators/params/response.js +28 -0
  179. package/lib/esm/decorators/params/response.js.map +1 -0
  180. package/lib/esm/domain/AnyToPromiseWithCtx.js +23 -0
  181. package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -0
  182. package/lib/esm/domain/ControllerProvider.js +47 -0
  183. package/lib/esm/domain/ControllerProvider.js.map +1 -0
  184. package/lib/esm/domain/EndpointMetadata.js +2 -0
  185. package/lib/esm/domain/EndpointMetadata.js.map +1 -0
  186. package/lib/esm/domain/HandlerMetadata.js +53 -0
  187. package/lib/esm/domain/HandlerMetadata.js.map +1 -0
  188. package/lib/esm/domain/PlatformContext.js +88 -0
  189. package/lib/esm/domain/PlatformContext.js.map +1 -0
  190. package/lib/esm/domain/PlatformRouteDetails.js +20 -0
  191. package/lib/esm/domain/PlatformRouteDetails.js.map +1 -0
  192. package/lib/esm/exports.js +13 -0
  193. package/lib/esm/exports.js.map +1 -0
  194. package/lib/esm/index.js +65 -0
  195. package/lib/esm/index.js.map +1 -0
  196. package/lib/esm/interfaces/AfterInit.js +2 -0
  197. package/lib/esm/interfaces/AfterInit.js.map +1 -0
  198. package/lib/esm/interfaces/AfterListen.js +2 -0
  199. package/lib/esm/interfaces/AfterListen.js.map +1 -0
  200. package/lib/esm/interfaces/AfterRoutesInit.js +2 -0
  201. package/lib/esm/interfaces/AfterRoutesInit.js.map +1 -0
  202. package/lib/esm/interfaces/BeforeInit.js +2 -0
  203. package/lib/esm/interfaces/BeforeInit.js.map +1 -0
  204. package/lib/esm/interfaces/BeforeListen.js +2 -0
  205. package/lib/esm/interfaces/BeforeListen.js.map +1 -0
  206. package/lib/esm/interfaces/BeforeRoutesInit.js +2 -0
  207. package/lib/esm/interfaces/BeforeRoutesInit.js.map +1 -0
  208. package/lib/esm/interfaces/HandlerType.js +14 -0
  209. package/lib/esm/interfaces/HandlerType.js.map +1 -0
  210. package/lib/esm/interfaces/IncomingEvent.js +2 -0
  211. package/lib/esm/interfaces/IncomingEvent.js.map +1 -0
  212. package/lib/esm/interfaces/OnReady.js +2 -0
  213. package/lib/esm/interfaces/OnReady.js.map +1 -0
  214. package/lib/esm/interfaces/OnRequest.js +2 -0
  215. package/lib/esm/interfaces/OnRequest.js.map +1 -0
  216. package/lib/esm/interfaces/OnResponse.js +2 -0
  217. package/lib/esm/interfaces/OnResponse.js.map +1 -0
  218. package/lib/esm/interfaces/OnRoutesInit.js +2 -0
  219. package/lib/esm/interfaces/OnRoutesInit.js.map +1 -0
  220. package/lib/esm/interfaces/PlatformRouteOptions.js +2 -0
  221. package/lib/esm/interfaces/PlatformRouteOptions.js.map +1 -0
  222. package/lib/esm/interfaces/ResponseErrorObject.js +2 -0
  223. package/lib/esm/interfaces/ResponseErrorObject.js.map +1 -0
  224. package/lib/esm/interfaces/Route.js +2 -0
  225. package/lib/esm/interfaces/Route.js.map +1 -0
  226. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js +34 -0
  227. package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
  228. package/lib/esm/middlewares/PlatformMulterMiddleware.js +63 -0
  229. package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -0
  230. package/lib/esm/middlewares/__mock__/FakeCtrl.js +9 -0
  231. package/lib/esm/middlewares/__mock__/FakeCtrl.js.map +1 -0
  232. package/lib/esm/middlewares/bindEndpointMiddleware.js +9 -0
  233. package/lib/esm/middlewares/bindEndpointMiddleware.js.map +1 -0
  234. package/lib/esm/package.json +3 -0
  235. package/lib/esm/services/FakeAdapter.js +51 -0
  236. package/lib/esm/services/FakeAdapter.js.map +1 -0
  237. package/lib/esm/services/Platform.js +125 -0
  238. package/lib/esm/services/Platform.js.map +1 -0
  239. package/lib/esm/services/PlatformAdapter.js +10 -0
  240. package/lib/esm/services/PlatformAdapter.js.map +1 -0
  241. package/lib/esm/services/PlatformApplication.js +29 -0
  242. package/lib/esm/services/PlatformApplication.js.map +1 -0
  243. package/lib/esm/services/PlatformHandler.js +232 -0
  244. package/lib/esm/services/PlatformHandler.js.map +1 -0
  245. package/lib/esm/services/PlatformMiddlewaresChain.js +72 -0
  246. package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -0
  247. package/lib/esm/services/PlatformRequest.js +135 -0
  248. package/lib/esm/services/PlatformRequest.js.map +1 -0
  249. package/lib/esm/services/PlatformResponse.js +268 -0
  250. package/lib/esm/services/PlatformResponse.js.map +1 -0
  251. package/lib/esm/services/PlatformRouter.js +105 -0
  252. package/lib/esm/services/PlatformRouter.js.map +1 -0
  253. package/lib/esm/services/PlatformTest.js +168 -0
  254. package/lib/esm/services/PlatformTest.js.map +1 -0
  255. package/lib/esm/utils/__mock__/Test1.js +4 -0
  256. package/lib/esm/utils/__mock__/Test1.js.map +1 -0
  257. package/lib/esm/utils/__mock__/Test2.js +4 -0
  258. package/lib/esm/utils/__mock__/Test2.js.map +1 -0
  259. package/lib/esm/utils/__mock__/controllers/rest/TestCtrl.js +9 -0
  260. package/lib/esm/utils/__mock__/controllers/rest/TestCtrl.js.map +1 -0
  261. package/lib/esm/utils/__mock__/module1/Module1.js +16 -0
  262. package/lib/esm/utils/__mock__/module1/Module1.js.map +1 -0
  263. package/lib/esm/utils/__mock__/module1/controllers/M1Ctrl1.js +14 -0
  264. package/lib/esm/utils/__mock__/module1/controllers/M1Ctrl1.js.map +1 -0
  265. package/lib/esm/utils/__mock__/module1/services/M1Service.js +14 -0
  266. package/lib/esm/utils/__mock__/module1/services/M1Service.js.map +1 -0
  267. package/lib/esm/utils/__mock__/module1/submodule/SubModule.js +12 -0
  268. package/lib/esm/utils/__mock__/module1/submodule/SubModule.js.map +1 -0
  269. package/lib/esm/utils/__mock__/module1/submodule/SubService.js +9 -0
  270. package/lib/esm/utils/__mock__/module1/submodule/SubService.js.map +1 -0
  271. package/lib/esm/utils/__mock__/module2/Module2.js +15 -0
  272. package/lib/esm/utils/__mock__/module2/Module2.js.map +1 -0
  273. package/lib/esm/utils/__mock__/module2/controllers/M2Ctrl.js +9 -0
  274. package/lib/esm/utils/__mock__/module2/controllers/M2Ctrl.js.map +1 -0
  275. package/lib/esm/utils/createContext.js +34 -0
  276. package/lib/esm/utils/createContext.js.map +1 -0
  277. package/lib/esm/utils/createHandlerMetadata.js +45 -0
  278. package/lib/esm/utils/createHandlerMetadata.js.map +1 -0
  279. package/lib/esm/utils/createHttpServer.js +24 -0
  280. package/lib/esm/utils/createHttpServer.js.map +1 -0
  281. package/lib/esm/utils/createHttpsServer.js +24 -0
  282. package/lib/esm/utils/createHttpsServer.js.map +1 -0
  283. package/lib/esm/utils/createInjector.js +42 -0
  284. package/lib/esm/utils/createInjector.js.map +1 -0
  285. package/lib/esm/utils/getConfiguration.js +42 -0
  286. package/lib/esm/utils/getConfiguration.js.map +1 -0
  287. package/lib/esm/utils/getStaticsOptions.js +17 -0
  288. package/lib/esm/utils/getStaticsOptions.js.map +1 -0
  289. package/lib/esm/utils/listenServer.js +17 -0
  290. package/lib/esm/utils/listenServer.js.map +1 -0
  291. package/lib/esm/utils/mapReturnedResponse.js +11 -0
  292. package/lib/esm/utils/mapReturnedResponse.js.map +1 -0
  293. package/lib/esm/utils/printRoutes.js +32 -0
  294. package/lib/esm/utils/printRoutes.js.map +1 -0
  295. package/lib/esm/utils/setResponseHeaders.js +31 -0
  296. package/lib/esm/utils/setResponseHeaders.js.map +1 -0
  297. package/lib/esm/utils/useCtxHandler.js +11 -0
  298. package/lib/esm/utils/useCtxHandler.js.map +1 -0
  299. package/lib/{builder → types/builder}/PlatformBuilder.d.ts +30 -34
  300. package/lib/types/builder/PlatformControllerBuilder.d.ts +18 -0
  301. package/lib/{config → types/config}/interfaces/ConverterSettings.d.ts +0 -0
  302. package/lib/{config → types/config}/interfaces/PlatformLoggerSettings.d.ts +0 -0
  303. package/lib/types/config/interfaces/PlatformMulterSettings.d.ts +14 -0
  304. package/lib/{config → types/config}/interfaces/PlatformStaticsSettings.d.ts +1 -0
  305. package/lib/{config → types/config}/services/PlatformConfiguration.d.ts +24 -17
  306. package/lib/{constants → types/constants}/routerOptions.d.ts +0 -0
  307. package/lib/{decorators → types/decorators}/multer/multerFileSize.d.ts +0 -0
  308. package/lib/{decorators → types/decorators}/multer/multerOptions.d.ts +0 -0
  309. package/lib/{decorators → types/decorators}/multer/multipartFile.d.ts +0 -0
  310. package/lib/{decorators → types/decorators}/params/error.d.ts +0 -0
  311. package/lib/{decorators → types/decorators}/params/next.d.ts +0 -0
  312. package/lib/{decorators → types/decorators}/params/request.d.ts +0 -0
  313. package/lib/{decorators → types/decorators}/params/response.d.ts +0 -0
  314. package/lib/{domain → types/domain}/AnyToPromiseWithCtx.d.ts +0 -0
  315. package/lib/types/domain/ControllerProvider.d.ts +24 -0
  316. package/lib/types/domain/EndpointMetadata.d.ts +1 -0
  317. package/lib/{domain → types/domain}/HandlerMetadata.d.ts +2 -2
  318. package/lib/{domain → types/domain}/PlatformContext.d.ts +1 -1
  319. package/lib/types/domain/PlatformRouteDetails.d.ts +22 -0
  320. package/lib/types/exports.d.ts +12 -0
  321. package/lib/types/index.d.ts +64 -0
  322. package/lib/{interfaces → types/interfaces}/AfterInit.d.ts +0 -0
  323. package/lib/{interfaces → types/interfaces}/AfterListen.d.ts +0 -0
  324. package/lib/{interfaces → types/interfaces}/AfterRoutesInit.d.ts +0 -0
  325. package/lib/{interfaces → types/interfaces}/BeforeInit.d.ts +0 -0
  326. package/lib/{interfaces → types/interfaces}/BeforeListen.d.ts +0 -0
  327. package/lib/{interfaces → types/interfaces}/BeforeRoutesInit.d.ts +0 -0
  328. package/lib/{interfaces → types/interfaces}/HandlerType.d.ts +0 -0
  329. package/lib/{interfaces → types/interfaces}/IncomingEvent.d.ts +0 -0
  330. package/lib/{interfaces → types/interfaces}/OnReady.d.ts +0 -0
  331. package/lib/{interfaces → types/interfaces}/OnRequest.d.ts +0 -0
  332. package/lib/{interfaces → types/interfaces}/OnResponse.d.ts +0 -0
  333. package/lib/{interfaces → types/interfaces}/OnRoutesInit.d.ts +0 -0
  334. package/lib/{interfaces → types/interfaces}/PlatformRouteOptions.d.ts +5 -3
  335. package/lib/{interfaces → types/interfaces}/ResponseErrorObject.d.ts +0 -0
  336. package/lib/{interfaces → types/interfaces}/Route.d.ts +0 -0
  337. package/lib/{middlewares → types/middlewares}/PlatformAcceptMimesMiddleware.d.ts +0 -0
  338. package/lib/{middlewares → types/middlewares}/PlatformMulterMiddleware.d.ts +8 -3
  339. package/lib/{middlewares/data → types/middlewares/__mock__}/FakeCtrl.d.ts +0 -0
  340. package/lib/types/middlewares/bindEndpointMiddleware.d.ts +6 -0
  341. package/lib/types/services/FakeAdapter.d.ts +30 -0
  342. package/lib/{services → types/services}/Platform.d.ts +22 -7
  343. package/lib/types/services/PlatformAdapter.d.ts +47 -0
  344. package/lib/{services → types/services}/PlatformApplication.d.ts +3 -3
  345. package/lib/{services → types/services}/PlatformHandler.d.ts +1 -1
  346. package/lib/types/services/PlatformMiddlewaresChain.d.ts +10 -0
  347. package/lib/{services → types/services}/PlatformRequest.d.ts +2 -1
  348. package/lib/{services → types/services}/PlatformResponse.d.ts +10 -10
  349. package/lib/{services → types/services}/PlatformRouter.d.ts +12 -8
  350. package/lib/{services → types/services}/PlatformTest.d.ts +6 -5
  351. package/lib/types/utils/__mock__/Test1.d.ts +3 -0
  352. package/lib/types/utils/__mock__/Test2.d.ts +3 -0
  353. package/lib/types/utils/__mock__/controllers/rest/TestCtrl.d.ts +2 -0
  354. package/lib/types/utils/__mock__/module1/Module1.d.ts +2 -0
  355. package/lib/types/utils/__mock__/module1/controllers/M1Ctrl1.d.ts +5 -0
  356. package/lib/types/utils/__mock__/module1/services/M1Service.d.ts +5 -0
  357. package/lib/types/utils/__mock__/module1/submodule/SubModule.d.ts +2 -0
  358. package/lib/types/utils/__mock__/module1/submodule/SubService.d.ts +2 -0
  359. package/lib/types/utils/__mock__/module2/Module2.d.ts +2 -0
  360. package/lib/types/utils/__mock__/module2/controllers/M2Ctrl.d.ts +2 -0
  361. package/lib/{utils → types/utils}/createContext.d.ts +0 -0
  362. package/lib/{utils → types/utils}/createHandlerMetadata.d.ts +1 -1
  363. package/lib/types/utils/createHttpServer.d.ts +4 -0
  364. package/lib/types/utils/createHttpsServer.d.ts +5 -0
  365. package/lib/types/utils/createInjector.d.ts +9 -0
  366. package/lib/types/utils/getConfiguration.d.ts +2 -0
  367. package/lib/types/utils/getStaticsOptions.d.ts +5 -0
  368. package/lib/types/utils/listenServer.d.ts +7 -0
  369. package/lib/{utils → types/utils}/mapReturnedResponse.d.ts +0 -0
  370. package/lib/{utils → types/utils}/printRoutes.d.ts +0 -0
  371. package/lib/{utils → types/utils}/setResponseHeaders.d.ts +0 -0
  372. package/lib/{utils → types/utils}/useCtxHandler.d.ts +0 -0
  373. package/package.json +47 -34
  374. package/readme.md +50 -57
  375. package/tsconfig.compile.esm.json +13 -0
  376. package/lib/PlatformModule.d.ts +0 -15
  377. package/lib/builder/PlatformControllerBuilder.d.ts +0 -19
  378. package/lib/config/index.d.ts +0 -3
  379. package/lib/config/interfaces/EndpointDirectoriesSettings.d.ts +0 -3
  380. package/lib/config/interfaces/PlatformMulterSettings.d.ts +0 -138
  381. package/lib/config/interfaces/index.d.ts +0 -84
  382. package/lib/decorators/httpServer.d.ts +0 -27
  383. package/lib/decorators/httpsServer.d.ts +0 -27
  384. package/lib/decorators/index.d.ts +0 -13
  385. package/lib/decorators/method/acceptMime.d.ts +0 -19
  386. package/lib/decorators/method/endpointFn.d.ts +0 -8
  387. package/lib/decorators/method/location.d.ts +0 -1
  388. package/lib/decorators/method/redirect.d.ts +0 -1
  389. package/lib/decorators/method/route.d.ts +0 -1
  390. package/lib/decorators/multer/index.d.ts +0 -3
  391. package/lib/domain/ControllerProvider.d.ts +0 -53
  392. package/lib/domain/EndpointMetadata.d.ts +0 -88
  393. package/lib/domain/PlatformRouteDetails.d.ts +0 -29
  394. package/lib/domain/index.d.ts +0 -6
  395. package/lib/index.d.ts +0 -22
  396. package/lib/index.js +0 -3651
  397. package/lib/index.js.map +0 -1
  398. package/lib/index.modern.js +0 -3464
  399. package/lib/index.modern.js.map +0 -1
  400. package/lib/interfaces/PathType.d.ts +0 -1
  401. package/lib/interfaces/PlatformRouterMethods.d.ts +0 -10
  402. package/lib/interfaces/index.d.ts +0 -17
  403. package/lib/middlewares/bindEndpointMiddleware.d.ts +0 -5
  404. package/lib/middlewares/index.d.ts +0 -3
  405. package/lib/registries/ControllerRegistry.d.ts +0 -1
  406. package/lib/services/FakeRawDriver.d.ts +0 -15
  407. package/lib/services/index.d.ts +0 -7
  408. package/lib/utils/createHttpServer.d.ts +0 -3
  409. package/lib/utils/createHttpsServer.d.ts +0 -3
  410. package/lib/utils/createInjector.d.ts +0 -2
  411. package/lib/utils/createPlatformApplication.d.ts +0 -2
  412. package/lib/utils/getControllerPath.d.ts +0 -2
  413. package/lib/utils/index.d.ts +0 -8
  414. package/lib/utils/listenServer.d.ts +0 -10
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlatformRequest = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const di_1 = require("@tsed/di");
6
+ /**
7
+ * Platform Request abstraction layer.
8
+ * @platform
9
+ */
10
+ let PlatformRequest = class PlatformRequest {
11
+ constructor({ request }, $ctx) {
12
+ this.$ctx = $ctx;
13
+ this.raw = request;
14
+ }
15
+ get secure() {
16
+ return this.raw.secure;
17
+ }
18
+ get host() {
19
+ return this.get("host");
20
+ }
21
+ get protocol() {
22
+ return this.raw.protocol;
23
+ }
24
+ /**
25
+ * Get the url of the request.
26
+ *
27
+ * Is equivalent of `express.response.originalUrl || express.response.url`.
28
+ */
29
+ get url() {
30
+ return this.raw.originalUrl || this.raw.url;
31
+ }
32
+ get headers() {
33
+ return this.raw.headers;
34
+ }
35
+ get method() {
36
+ return this.raw.method;
37
+ }
38
+ /**
39
+ * Contains key-value pairs of data submitted in the request body. By default, it is `undefined`, and is populated when you use
40
+ * `body-parsing` middleware such as `express.json()` or `express.urlencoded()`.
41
+ */
42
+ get body() {
43
+ return this.raw.body;
44
+ }
45
+ get rawBody() {
46
+ return this.raw.rawBody || this.raw.body;
47
+ }
48
+ /**
49
+ * When using `cookie-parser` middleware, this property is an object that contains cookies sent by the request.
50
+ * If the request contains no cookies, it defaults to `{}`.
51
+ */
52
+ get cookies() {
53
+ return this.raw.cookies;
54
+ }
55
+ /**
56
+ * This property is an object containing properties mapped to the named route `parameters`.
57
+ * For example, if you have the route `/user/:name`, then the `name` property is available as `req.params.name`.
58
+ * This object defaults to `{}`.
59
+ */
60
+ get params() {
61
+ return this.raw.params;
62
+ }
63
+ /**
64
+ * This property is an object containing a property for each query string parameter in the route.
65
+ * When query parser is set to disabled, it is an empty object `{}`, otherwise it is the result of the configured query parser.
66
+ */
67
+ get query() {
68
+ return this.raw.query;
69
+ }
70
+ /**
71
+ * This property is an object containing a property for each session attributes set by any code.
72
+ * It require to install a middleware like express-session to work.
73
+ */
74
+ get session() {
75
+ return this.raw.session;
76
+ }
77
+ get files() {
78
+ return this.raw.files;
79
+ }
80
+ /**
81
+ * Return the original request framework instance
82
+ */
83
+ get request() {
84
+ return this.getRequest();
85
+ }
86
+ /**
87
+ * Return the original request node.js instance
88
+ */
89
+ get req() {
90
+ return this.getReq();
91
+ }
92
+ /**
93
+ * Returns the HTTP request header specified by field. The match is case-insensitive.
94
+ *
95
+ * ```typescript
96
+ * request.get('Content-Type') // => "text/plain"
97
+ * ```
98
+ *
99
+ * @param name
100
+ */
101
+ get(name) {
102
+ return this.raw.get(name);
103
+ }
104
+ accepts(mime) {
105
+ // @ts-ignore
106
+ return this.raw.accepts(mime);
107
+ }
108
+ isAborted() {
109
+ return this.raw.aborted;
110
+ }
111
+ destroy() {
112
+ // @ts-ignore
113
+ delete this.raw;
114
+ // @ts-ignore
115
+ delete this.response;
116
+ // @ts-ignore
117
+ delete this.$ctx;
118
+ }
119
+ /**
120
+ * Return the Framework response object (express, koa, etc...)
121
+ */
122
+ getRequest() {
123
+ return this.raw;
124
+ }
125
+ /**
126
+ * Return the Node.js response object
127
+ */
128
+ getReq() {
129
+ return this.raw;
130
+ }
131
+ };
132
+ PlatformRequest = tslib_1.__decorate([
133
+ (0, di_1.Injectable)(),
134
+ (0, di_1.Scope)(di_1.ProviderScope.INSTANCE),
135
+ tslib_1.__metadata("design:paramtypes", [Object, Function])
136
+ ], PlatformRequest);
137
+ exports.PlatformRequest = PlatformRequest;
138
+ //# sourceMappingURL=PlatformRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformRequest.js","sourceR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IACxB,CAAC;IAED;;;OAGG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,CAAC,OAAc,CAAC;IACjC,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAaD,OAAO,CAAC,IAAwB;QAC9B,aAAa;QACb,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED,OAAO;QACL,aAAa;QACb,OAAO,IAAI,CAAC,GAAG,CAAC;QAChB,aAAa;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC;QACrB,aAAa;QACb,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,GAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,GAAU,CAAC;IACzB,CAAC;CACF,CAAA;AA/JY,eAAe;IAF3B,IAAA,eAAU,GAAE;IACZ,IAAA,UAAK,EAAC,kBAAa,CAAC,QAAQ,CAAC;;GACjB,eAAe,CA+J3B;AA/JY,0CAAe","sourcesContent":["import {Injectable, ProviderScope, Scope} from \"@tsed/di\";\nimport {IncomingHttpHeaders, IncomingMessage} from \"http\";\nimport type {PlatformContext} from \"../domain/PlatformContext\";\nimport {IncomingEvent} from \"../interfaces/IncomingEvent\";\nimport type {PlatformResponse} from \"./PlatformResponse\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Request {\n id: string;\n $ctx: PlatformContext;\n }\n }\n}\n\n/**\n * Platform Request abstraction layer.\n * @platform\n */\n@Injectable()\n@Scope(ProviderScope.INSTANCE)\nexport class PlatformRequest<T extends {[key: string]: any} = any> {\n public raw: T;\n\n /**\n * The current @@PlatformResponse@@.\n */\n public response: PlatformResponse;\n\n constructor({request}: IncomingEvent, protected $ctx: PlatformContext) {\n this.raw = request as any;\n }\n\n get secure(): boolean {\n return this.raw.secure;\n }\n\n get host(): string {\n return this.get(\"host\");\n }\n\n get protocol(): string {\n return this.raw.protocol;\n }\n\n /**\n * Get the url of the request.\n *\n * Is equivalent of `express.response.originalUrl || express.response.url`.\n */\n get url(): string {\n return this.raw.originalUrl || this.raw.url;\n }\n\n get headers(): IncomingHttpHeaders {\n return this.raw.headers;\n }\n\n get method(): string {\n return this.raw.method;\n }\n\n /**\n * Contains key-value pairs of data submitted in the request body. By default, it is `undefined`, and is populated when you use\n * `body-parsing` middleware such as `express.json()` or `express.urlencoded()`.\n */\n get body(): any {\n return this.raw.body;\n }\n\n get rawBody(): any {\n return this.raw.rawBody || this.raw.body;\n }\n\n /**\n * When using `cookie-parser` middleware, this property is an object that contains cookies sent by the request.\n * If the request contains no cookies, it defaults to `{}`.\n */\n get cookies(): {[key: string]: any} {\n return this.raw.cookies;\n }\n\n /**\n * This property is an object containing properties mapped to the named route `parameters`.\n * For example, if you have the route `/user/:name`, then the `name` property is available as `req.params.name`.\n * This object defaults to `{}`.\n */\n get params(): {[key: string]: any} {\n return this.raw.params;\n }\n\n /**\n * This property is an object containing a property for each query string parameter in the route.\n * When query parser is set to disabled, it is an empty object `{}`, otherwise it is the result of the configured query parser.\n */\n get query(): {[key: string]: any} {\n return this.raw.query;\n }\n\n /**\n * This property is an object containing a property for each session attributes set by any code.\n * It require to install a middleware like express-session to work.\n */\n get session(): {[key: string]: any} {\n return this.raw.session as any;\n }\n\n get files() {\n return this.raw.files;\n }\n\n /**\n * Return the original request framework instance\n */\n get request() {\n return this.getRequest();\n }\n\n /**\n * Return the original request node.js instance\n */\n get req() {\n return this.getReq();\n }\n\n /**\n * Returns the HTTP request header specified by field. The match is case-insensitive.\n *\n * ```typescript\n * request.get('Content-Type') // => \"text/plain\"\n * ```\n *\n * @param name\n */\n get(name: string) {\n return this.raw.get(name);\n }\n\n /**\n * Checks if the specified content types are acceptable, based on the request’s Accept HTTP header field. The method returns the best match, or if none of the specified content types is acceptable, returns false (in which case, the application should respond with 406 \"Not Acceptable\").\n *\n * The type value may be a single MIME type string (such as “application/json”), an extension name such as “json”, a comma-delimited list, or an array. For a list or array, the method returns the best match (if any).\n *\n * @param mime\n */\n accepts(mime: string): string | false;\n\n accepts(mime: string[]): string[] | false;\n\n accepts(mime?: string | string[]): string | string[] | false {\n // @ts-ignore\n return this.raw.accepts(mime);\n }\n\n isAborted() {\n return this.raw.aborted;\n }\n\n destroy() {\n // @ts-ignore\n delete this.raw;\n // @ts-ignore\n delete this.response;\n // @ts-ignore\n delete this.$ctx;\n }\n\n /**\n * Return the Framework response object (express, koa, etc...)\n */\n getRequest<Req = T>(): Req {\n return this.raw as any;\n }\n\n /**\n * Return the Node.js response object\n */\n getReq(): IncomingMessage {\n return this.raw as any;\n }\n}\n"]}
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ var PlatformResponse_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PlatformResponse = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const core_1 = require("@tsed/core");
7
+ const di_1 = require("@tsed/di");
8
+ const on_finished_1 = tslib_1.__importDefault(require("on-finished"));
9
+ /**
10
+ * Platform Response abstraction layer.
11
+ * @platform
12
+ */
13
+ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
14
+ constructor({ response }, $ctx) {
15
+ this.$ctx = $ctx;
16
+ this.raw = response;
17
+ }
18
+ /**
19
+ * Get the current statusCode
20
+ */
21
+ get statusCode() {
22
+ return this.raw.statusCode;
23
+ }
24
+ /**
25
+ * 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.
26
+ *
27
+ * This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.
28
+ */
29
+ get locals() {
30
+ return this.raw.locals;
31
+ }
32
+ /**
33
+ * Return the original response framework instance
34
+ */
35
+ get response() {
36
+ return this.getResponse();
37
+ }
38
+ /**
39
+ * Return the original response node.js instance
40
+ */
41
+ get res() {
42
+ return this.getRes();
43
+ }
44
+ static onFinished(res, cb) {
45
+ (0, on_finished_1.default)(res, cb);
46
+ }
47
+ /**
48
+ * Returns the HTTP response header specified by field. The match is case-insensitive.
49
+ *
50
+ * ```typescript
51
+ * response.get('Content-Type') // => "text/plain"
52
+ * ```
53
+ *
54
+ * @param name
55
+ */
56
+ get(name) {
57
+ return this.raw.get(name);
58
+ }
59
+ getHeaders() {
60
+ return this.raw.getHeaders();
61
+ }
62
+ /**
63
+ * Return the Framework response object (express, koa, etc...)
64
+ */
65
+ getResponse() {
66
+ return this.raw;
67
+ }
68
+ /**
69
+ * Return the Node.js response object
70
+ */
71
+ getRes() {
72
+ return this.raw;
73
+ }
74
+ hasStatus() {
75
+ return this.statusCode !== 200;
76
+ }
77
+ /**
78
+ * Sets the HTTP status for the response.
79
+ *
80
+ * @param status
81
+ */
82
+ status(status) {
83
+ this.raw.status(status);
84
+ return this;
85
+ }
86
+ /**
87
+ * Set header `field` to `val`, or pass
88
+ * an object of header fields.
89
+ *
90
+ * Examples:
91
+ * ```typescript
92
+ * response.setHeaders({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
93
+ * ```
94
+ *
95
+ * Aliased as `res.header()`.
96
+ */
97
+ setHeaders(headers) {
98
+ // apply headers
99
+ Object.entries(headers).forEach(([key, item]) => {
100
+ this.setHeader(key, item);
101
+ });
102
+ return this;
103
+ }
104
+ setHeader(key, item) {
105
+ if (key.toLowerCase() === "location") {
106
+ return this.location(String(item));
107
+ }
108
+ this.raw.set(key, item);
109
+ return this;
110
+ }
111
+ /**
112
+ * Set `Content-Type` response header with `type` through `mime.lookup()`
113
+ * when it does not contain "/", or set the Content-Type to `type` otherwise.
114
+ *
115
+ * Examples:
116
+ *
117
+ * res.type('.html');
118
+ * res.type('html');
119
+ * res.type('json');
120
+ * res.type('application/json');
121
+ * res.type('png');
122
+ */
123
+ contentType(contentType) {
124
+ this.raw.contentType(contentType);
125
+ return this;
126
+ }
127
+ contentLength(length) {
128
+ this.setHeader("Content-Length", length);
129
+ return this;
130
+ }
131
+ getContentLength() {
132
+ if (this.get("Content-Length")) {
133
+ return parseInt(this.get("Content-Length"), 10) || 0;
134
+ }
135
+ }
136
+ getContentType() {
137
+ return (this.get("Content-Type") || "").split(";")[0];
138
+ }
139
+ /**
140
+ * Sets the HTTP response Content-Disposition header field to “attachment”.
141
+ * 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.
142
+ *
143
+ * ```typescript
144
+ * res.attachment()
145
+ * // Content-Disposition: attachment
146
+ *
147
+ * res.attachment('path/to/logo.png')
148
+ * // Content-Disposition: attachment; filename="logo.png"
149
+ * // Content-Type: image/png
150
+ * ```
151
+ *
152
+ * @param filename
153
+ */
154
+ attachment(filename) {
155
+ this.raw.attachment(filename);
156
+ return this;
157
+ }
158
+ /**
159
+ * 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).
160
+ * If not specified, status defaults to `302 Found`.
161
+ *
162
+ * @param status
163
+ * @param url
164
+ */
165
+ redirect(status, url) {
166
+ this.raw.redirect(status, url);
167
+ return this;
168
+ }
169
+ /**
170
+ * Sets the response Location HTTP header to the specified path parameter.
171
+ *
172
+ * @param location
173
+ */
174
+ location(location) {
175
+ this.raw.location(location);
176
+ return this;
177
+ }
178
+ /**
179
+ * Stream the given data.
180
+ *
181
+ * @param data
182
+ */
183
+ stream(data) {
184
+ data.pipe(this.raw);
185
+ return this;
186
+ }
187
+ /**
188
+ * Renders a view and sends the rendered HTML string to the client.
189
+ *
190
+ * @param path
191
+ * @param options
192
+ */
193
+ async render(path, options = {}) {
194
+ const { PlatformViews } = await Promise.resolve().then(() => tslib_1.__importStar(require("@tsed/platform-views")));
195
+ const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);
196
+ return platformViews.render(path, {
197
+ ...this.locals,
198
+ ...options
199
+ });
200
+ }
201
+ /**
202
+ * Send any data to your consumer.
203
+ *
204
+ * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.
205
+ * It choose the better way to send the data.
206
+ *
207
+ * @param data
208
+ */
209
+ body(data) {
210
+ this.data = data;
211
+ if (data === undefined) {
212
+ this.raw.send();
213
+ return this;
214
+ }
215
+ if ((0, core_1.isStream)(data)) {
216
+ this.stream(data);
217
+ return this;
218
+ }
219
+ if (Buffer.isBuffer(data)) {
220
+ if (!this.getContentType()) {
221
+ this.contentType("application/octet-stream");
222
+ }
223
+ this.contentLength(data.length);
224
+ this.raw.send(data);
225
+ return this;
226
+ }
227
+ if ((0, core_1.isBoolean)(data) || (0, core_1.isNumber)(data) || (0, core_1.isString)(data) || data === null) {
228
+ this.raw.send(data);
229
+ return this;
230
+ }
231
+ this.raw.json(data);
232
+ return this;
233
+ }
234
+ getBody() {
235
+ return this.data;
236
+ }
237
+ /**
238
+ * Add a listener to handler the end of the request/response.
239
+ * @param cb
240
+ */
241
+ onEnd(cb) {
242
+ PlatformResponse_1.onFinished(this.getRes(), cb);
243
+ return this;
244
+ }
245
+ isDone() {
246
+ if (!this.raw) {
247
+ return true;
248
+ }
249
+ const res = this.getRes();
250
+ return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);
251
+ }
252
+ destroy() {
253
+ // @ts-ignore
254
+ delete this.raw;
255
+ delete this.data;
256
+ // @ts-ignore
257
+ delete this.request;
258
+ // @ts-ignore
259
+ delete this.$ctx;
260
+ }
261
+ isHeadersSent() {
262
+ return this.getRes().headersSent;
263
+ }
264
+ };
265
+ PlatformResponse = PlatformResponse_1 = tslib_1.__decorate([
266
+ (0, di_1.Injectable)(),
267
+ (0, di_1.Scope)(di_1.ProviderScope.INSTANCE),
268
+ tslib_1.__metadata("design:paramtypes", [Object, Function])
269
+ ], PlatformResponse);
270
+ exports.PlatformResponse = PlatformResponse;
271
+ //# sourceMappingURL=PlatformResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformResponse.ts"],"names":[],"mappings":";;;;;AAAA,qCAAmE;AACnE,iCAA0D;AAE1D,sEAAqC;AAgBrC;;;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,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,GAAQ,EAAE,EAA+C;QACzE,IAAA,qBAAU,EAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACtB,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,UAAU;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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;AAtTY,gBAAgB;IAF5B,IAAA,eAAU,GAAE;IACZ,IAAA,UAAK,EAAC,kBAAa,CAAC,QAAQ,CAAC;;GACjB,gBAAgB,CAsT5B;AAtTY,4CAAgB","sourcesContent":["import {isBoolean, isNumber, isStream, isString} from \"@tsed/core\";\nimport {Injectable, ProviderScope, Scope} from \"@tsed/di\";\nimport {OutgoingHttpHeaders, ServerResponse} from \"http\";\nimport onFinished from \"on-finished\";\nimport {IncomingEvent} from \"../interfaces/IncomingEvent\";\nimport type {PlatformRequest} from \"./PlatformRequest\";\nimport type {PlatformContext} from \"../domain/PlatformContext\";\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: (er: Error | null, message: string) => void) {\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(): OutgoingHttpHeaders {\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: OutgoingHttpHeaders) {\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: 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\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: (er: Error | null, message: string) => void): 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,108 @@
1
+ "use strict";
2
+ var PlatformRouter_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PlatformRouter = exports.PLATFORM_ROUTER_OPTIONS = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const di_1 = require("@tsed/di");
7
+ const PlatformHandler_1 = require("./PlatformHandler");
8
+ const PlatformAdapter_1 = require("./PlatformAdapter");
9
+ /**
10
+ * @ignore
11
+ */
12
+ exports.PLATFORM_ROUTER_OPTIONS = Symbol.for("PlatformRouterOptions");
13
+ /**
14
+ * Platform Router abstraction layer.
15
+ * @platform
16
+ */
17
+ let PlatformRouter = PlatformRouter_1 = class PlatformRouter {
18
+ constructor(platformHandler, adapter, routerOptions = {}) {
19
+ this.platformHandler = platformHandler;
20
+ this.adapter = adapter;
21
+ this.isBuilt = false;
22
+ const { router, callback } = adapter.router(routerOptions);
23
+ this.rawRouter = this.raw = router;
24
+ this.callback = callback;
25
+ }
26
+ /**
27
+ * Create a new instance of PlatformRouter
28
+ * @param injector
29
+ * @param routerOptions
30
+ */
31
+ static create(injector, routerOptions = {}) {
32
+ const locals = new Map();
33
+ locals.set(exports.PLATFORM_ROUTER_OPTIONS, routerOptions);
34
+ return injector.invoke(PlatformRouter_1, locals);
35
+ }
36
+ getRouter() {
37
+ return this.rawRouter;
38
+ }
39
+ use(...handlers) {
40
+ // @ts-ignore
41
+ this.getRouter().use(...this.mapHandlers(handlers));
42
+ return this;
43
+ }
44
+ addRoute(options) {
45
+ const { method, path, handlers, ...opts } = options;
46
+ // @ts-ignore
47
+ this.getRouter()[method](path, ...this.mapHandlers(handlers, { method, path, ...opts }));
48
+ return this;
49
+ }
50
+ all(path, ...handlers) {
51
+ return this.addRoute({ method: "all", path, handlers, isFinal: true });
52
+ }
53
+ get(path, ...handlers) {
54
+ return this.addRoute({ method: "get", path, handlers, isFinal: true });
55
+ }
56
+ post(path, ...handlers) {
57
+ return this.addRoute({ method: "post", path, handlers, isFinal: true });
58
+ }
59
+ put(path, ...handlers) {
60
+ return this.addRoute({ method: "put", path, handlers, isFinal: true });
61
+ }
62
+ delete(path, ...handlers) {
63
+ return this.addRoute({ method: "delete", path, handlers, isFinal: true });
64
+ }
65
+ patch(path, ...handlers) {
66
+ return this.addRoute({ method: "patch", path, handlers, isFinal: true });
67
+ }
68
+ head(path, ...handlers) {
69
+ return this.addRoute({ method: "head", path, handlers, isFinal: true });
70
+ }
71
+ options(path, ...handlers) {
72
+ return this.addRoute({ method: "options", path, handlers, isFinal: true });
73
+ }
74
+ statics(path, options) {
75
+ return this.use(path, this.adapter.statics(path, options));
76
+ }
77
+ multer(options) {
78
+ return this.adapter.multipart(options);
79
+ }
80
+ mapHandlers(handlers, options = {}) {
81
+ return handlers.reduce((list, handler, index) => {
82
+ if (typeof handler === "string") {
83
+ return list.concat(handler);
84
+ }
85
+ if (handler instanceof PlatformRouter_1) {
86
+ return list.concat(handler.callback());
87
+ }
88
+ return list.concat(this.platformHandler.createHandler(handler, {
89
+ ...options,
90
+ isFinal: options.isFinal ? index === handlers.length - 1 : false
91
+ }));
92
+ }, []);
93
+ }
94
+ };
95
+ tslib_1.__decorate([
96
+ (0, di_1.Inject)(),
97
+ tslib_1.__metadata("design:type", di_1.InjectorService)
98
+ ], PlatformRouter.prototype, "injector", void 0);
99
+ PlatformRouter = PlatformRouter_1 = tslib_1.__decorate([
100
+ (0, di_1.Injectable)({
101
+ scope: di_1.ProviderScope.INSTANCE
102
+ }),
103
+ tslib_1.__param(2, (0, di_1.Inject)(exports.PLATFORM_ROUTER_OPTIONS)),
104
+ tslib_1.__metadata("design:paramtypes", [PlatformHandler_1.PlatformHandler,
105
+ PlatformAdapter_1.PlatformAdapter, Object])
106
+ ], PlatformRouter);
107
+ exports.PlatformRouter = PlatformRouter;
108
+ //# sourceMappingURL=PlatformRouter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformRouter.js","sourceRoot":"","sources":["../../../src/services/PlatformRouter.ts"],"names":[],"mappings":";;;;;AAAA,iCAAsF;AACtF,uDAAkD;AAIlD,uDAAkD;AAGlD;;GAEG;AACU,QAAA,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAS3E;;;GAGG;AAIH,IAAa,cAAc,sBAA3B,MAAa,cAAc;IAUzB,YACY,eAAgC,EACjC,OAAqC,EACb,gBAAwC,EAAE;QAFjE,oBAAe,GAAf,eAAe,CAAiB;QACjC,YAAO,GAAP,OAAO,CAA8B;QAThD,YAAO,GAAY,KAAK,CAAC;QAYvB,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,GAAG,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QAEzD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;OAIG;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M,CAAC,OAA+B;QACpC,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACzC,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;AAzGC;IADC,IAAA,WAAM,GAAE;sCACC,oBAAe;gDAAC;AANf,cAAc;IAH1B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,QAAQ;KAC9B,CAAC;IAcG,mBAAA,IAAA,WAAM,EAAC,+BAAuB,CAAC,CAAA;6CAFL,iCAAe;QACxB,iCAAe;GAZxB,cAAc,CA+G1B;AA/GY,wCAAc","sourcesContent":["import {Inject, Injectable, InjectorService, PathType, ProviderScope} from \"@tsed/di\";\nimport {PlatformHandler} from \"./PlatformHandler\";\nimport {PlatformRouteOptions, PlatformRouteWithoutHandlers} from \"../interfaces/PlatformRouteOptions\";\nimport {PlatformStaticsOptions} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {PlatformMulter, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformAdapter} from \"./PlatformAdapter\";\nimport {RouterOptions} from \"express\";\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<App = TsED.Application, Router = TsED.Router> {\n rawRouter: Router;\n raw: any;\n isBuilt: boolean = false;\n\n @Inject()\n injector: InjectorService;\n\n callback: () => any;\n\n constructor(\n protected platformHandler: PlatformHandler,\n readonly adapter: PlatformAdapter<App, Router>,\n @Inject(PLATFORM_ROUTER_OPTIONS) routerOptions: Partial<RouterOptions> = {}\n ) {\n const {router, callback} = adapter.router(routerOptions);\n\n this.rawRouter = this.raw = router;\n this.callback = callback;\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 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) {\n return this.use(path, this.adapter.statics(path, options));\n }\n\n multer(options: PlatformMulterSettings): PlatformMulter {\n return this.adapter.multipart(options);\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"]}