@tsed/common 7.0.0-alpha.2 → 7.0.0-beta.1
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.
- package/lib/cjs/builder/PlatformBuilder.js +275 -0
- package/lib/cjs/builder/PlatformBuilder.js.map +1 -0
- package/lib/cjs/builder/PlatformControllerBuilder.js +85 -0
- package/lib/cjs/builder/PlatformControllerBuilder.js.map +1 -0
- package/lib/cjs/config/index.js +7 -0
- package/lib/cjs/config/index.js.map +1 -0
- package/lib/cjs/config/interfaces/ConverterSettings.js +3 -0
- package/lib/cjs/config/interfaces/ConverterSettings.js.map +1 -0
- package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js +3 -0
- package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js.map +1 -0
- package/lib/cjs/config/interfaces/PlatformLoggerSettings.js +3 -0
- package/lib/cjs/config/interfaces/PlatformLoggerSettings.js.map +1 -0
- package/lib/cjs/config/interfaces/PlatformMulterSettings.js +3 -0
- package/lib/cjs/config/interfaces/PlatformMulterSettings.js.map +1 -0
- package/lib/cjs/config/interfaces/PlatformStaticsSettings.js +3 -0
- package/lib/cjs/config/interfaces/PlatformStaticsSettings.js.map +1 -0
- package/lib/cjs/config/interfaces/index.js +8 -0
- package/lib/cjs/config/interfaces/index.js.map +1 -0
- package/lib/cjs/config/services/PlatformConfiguration.js +181 -0
- package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -0
- package/lib/cjs/constants/routerOptions.js +5 -0
- package/lib/cjs/constants/routerOptions.js.map +1 -0
- package/lib/cjs/decorators/httpServer.js +32 -0
- package/lib/cjs/decorators/httpServer.js.map +1 -0
- package/lib/cjs/decorators/httpsServer.js +32 -0
- package/lib/cjs/decorators/httpsServer.js.map +1 -0
- package/lib/cjs/decorators/index.js +21 -0
- package/lib/cjs/decorators/index.js.map +1 -0
- package/lib/cjs/decorators/method/acceptMime.js +28 -0
- package/lib/cjs/decorators/method/acceptMime.js.map +1 -0
- package/lib/cjs/decorators/method/endpointFn.js +15 -0
- package/lib/cjs/decorators/method/endpointFn.js.map +1 -0
- package/lib/cjs/decorators/method/location.js +6 -0
- package/lib/cjs/decorators/method/location.js.map +1 -0
- package/lib/cjs/decorators/method/redirect.js +6 -0
- package/lib/cjs/decorators/method/redirect.js.map +1 -0
- package/lib/cjs/decorators/method/route.js +13 -0
- package/lib/cjs/decorators/method/route.js.map +1 -0
- package/lib/cjs/decorators/method/view.js +34 -0
- package/lib/cjs/decorators/method/view.js.map +1 -0
- package/lib/cjs/decorators/multer/index.js +7 -0
- package/lib/cjs/decorators/multer/index.js.map +1 -0
- package/lib/cjs/decorators/multer/multerFileSize.js +35 -0
- package/lib/cjs/decorators/multer/multerFileSize.js.map +1 -0
- package/lib/cjs/decorators/multer/multerOptions.js +52 -0
- package/lib/cjs/decorators/multer/multerOptions.js.map +1 -0
- package/lib/cjs/decorators/multer/multipartFile.js +78 -0
- package/lib/cjs/decorators/multer/multipartFile.js.map +1 -0
- package/lib/cjs/decorators/params/error.js +20 -0
- package/lib/cjs/decorators/params/error.js.map +1 -0
- package/lib/cjs/decorators/params/next.js +21 -0
- package/lib/cjs/decorators/params/next.js.map +1 -0
- package/lib/cjs/decorators/params/request.js +39 -0
- package/lib/cjs/decorators/params/request.js.map +1 -0
- package/lib/cjs/decorators/params/response.js +33 -0
- package/lib/cjs/decorators/params/response.js.map +1 -0
- package/lib/cjs/domain/AnyToPromiseWithCtx.js +27 -0
- package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -0
- package/lib/cjs/domain/ControllerProvider.js +51 -0
- package/lib/cjs/domain/ControllerProvider.js.map +1 -0
- package/lib/cjs/domain/EndpointMetadata.js +70 -0
- package/lib/cjs/domain/EndpointMetadata.js.map +1 -0
- package/lib/cjs/domain/HandlerMetadata.js +57 -0
- package/lib/cjs/domain/HandlerMetadata.js.map +1 -0
- package/lib/cjs/domain/PlatformContext.js +92 -0
- package/lib/cjs/domain/PlatformContext.js.map +1 -0
- package/lib/cjs/domain/PlatformRouteDetails.js +24 -0
- package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -0
- package/lib/cjs/domain/index.js +10 -0
- package/lib/cjs/domain/index.js.map +1 -0
- package/lib/cjs/index.js +34 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/interfaces/AfterInit.js +3 -0
- package/lib/cjs/interfaces/AfterInit.js.map +1 -0
- package/lib/cjs/interfaces/AfterListen.js +3 -0
- package/lib/cjs/interfaces/AfterListen.js.map +1 -0
- package/lib/cjs/interfaces/AfterRoutesInit.js +3 -0
- package/lib/cjs/interfaces/AfterRoutesInit.js.map +1 -0
- package/lib/cjs/interfaces/BeforeInit.js +3 -0
- package/lib/cjs/interfaces/BeforeInit.js.map +1 -0
- package/lib/cjs/interfaces/BeforeListen.js +3 -0
- package/lib/cjs/interfaces/BeforeListen.js.map +1 -0
- package/lib/cjs/interfaces/BeforeRoutesInit.js +3 -0
- package/lib/cjs/interfaces/BeforeRoutesInit.js.map +1 -0
- package/lib/cjs/interfaces/HandlerType.js +17 -0
- package/lib/cjs/interfaces/HandlerType.js.map +1 -0
- package/lib/cjs/interfaces/IncomingEvent.js +3 -0
- package/lib/cjs/interfaces/IncomingEvent.js.map +1 -0
- package/lib/cjs/interfaces/OnReady.js +3 -0
- package/lib/cjs/interfaces/OnReady.js.map +1 -0
- package/lib/cjs/interfaces/OnRequest.js +3 -0
- package/lib/cjs/interfaces/OnRequest.js.map +1 -0
- package/lib/cjs/interfaces/OnResponse.js +3 -0
- package/lib/cjs/interfaces/OnResponse.js.map +1 -0
- package/lib/cjs/interfaces/OnRoutesInit.js +3 -0
- package/lib/cjs/interfaces/OnRoutesInit.js.map +1 -0
- package/lib/cjs/interfaces/PathType.js +3 -0
- package/lib/cjs/interfaces/PathType.js.map +1 -0
- package/lib/cjs/interfaces/PlatformAdapter.js +3 -0
- package/lib/cjs/interfaces/PlatformAdapter.js.map +1 -0
- package/lib/cjs/interfaces/PlatformRouteOptions.js +3 -0
- package/lib/cjs/interfaces/PlatformRouteOptions.js.map +1 -0
- package/lib/cjs/interfaces/ResponseErrorObject.js +3 -0
- package/lib/cjs/interfaces/ResponseErrorObject.js.map +1 -0
- package/lib/cjs/interfaces/Route.js +3 -0
- package/lib/cjs/interfaces/Route.js.map +1 -0
- package/lib/cjs/interfaces/index.js +21 -0
- package/lib/cjs/interfaces/index.js.map +1 -0
- package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js +37 -0
- package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
- package/lib/cjs/middlewares/PlatformMulterMiddleware.js +55 -0
- package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -0
- package/lib/cjs/middlewares/__mock__/FakeCtrl.js +12 -0
- package/lib/cjs/middlewares/__mock__/FakeCtrl.js.map +1 -0
- package/lib/cjs/middlewares/bindEndpointMiddleware.js +13 -0
- package/lib/cjs/middlewares/bindEndpointMiddleware.js.map +1 -0
- package/lib/cjs/middlewares/index.js +7 -0
- package/lib/cjs/middlewares/index.js.map +1 -0
- package/lib/cjs/services/FakeRawDriver.js +26 -0
- package/lib/cjs/services/FakeRawDriver.js.map +1 -0
- package/lib/cjs/services/Platform.js +107 -0
- package/lib/cjs/services/Platform.js.map +1 -0
- package/lib/cjs/services/PlatformApplication.js +34 -0
- package/lib/cjs/services/PlatformApplication.js.map +1 -0
- package/lib/cjs/services/PlatformHandler.js +233 -0
- package/lib/cjs/services/PlatformHandler.js.map +1 -0
- package/lib/cjs/services/PlatformMiddlewaresChain.js +34 -0
- package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -0
- package/lib/cjs/services/PlatformRequest.js +138 -0
- package/lib/cjs/services/PlatformRequest.js.map +1 -0
- package/lib/cjs/services/PlatformResponse.js +271 -0
- package/lib/cjs/services/PlatformResponse.js.map +1 -0
- package/lib/cjs/services/PlatformRouter.js +126 -0
- package/lib/cjs/services/PlatformRouter.js.map +1 -0
- package/lib/cjs/services/PlatformTest.js +166 -0
- package/lib/cjs/services/PlatformTest.js.map +1 -0
- package/lib/cjs/services/index.js +12 -0
- package/lib/cjs/services/index.js.map +1 -0
- package/lib/cjs/utils/createContext.js +38 -0
- package/lib/cjs/utils/createContext.js.map +1 -0
- package/lib/cjs/utils/createHandlerMetadata.js +49 -0
- package/lib/cjs/utils/createHandlerMetadata.js.map +1 -0
- package/lib/cjs/utils/createHttpServer.js +34 -0
- package/lib/cjs/utils/createHttpServer.js.map +1 -0
- package/lib/cjs/utils/createHttpsServer.js +34 -0
- package/lib/cjs/utils/createHttpsServer.js.map +1 -0
- package/lib/cjs/utils/createInjector.js +38 -0
- package/lib/cjs/utils/createInjector.js.map +1 -0
- package/lib/cjs/utils/getConfiguration.js +42 -0
- package/lib/cjs/utils/getConfiguration.js.map +1 -0
- package/lib/cjs/utils/getStaticsOptions.js +21 -0
- package/lib/cjs/utils/getStaticsOptions.js.map +1 -0
- package/lib/cjs/utils/index.js +11 -0
- package/lib/cjs/utils/index.js.map +1 -0
- package/lib/cjs/utils/listenServer.js +21 -0
- package/lib/cjs/utils/listenServer.js.map +1 -0
- package/lib/cjs/utils/mapReturnedResponse.js +15 -0
- package/lib/cjs/utils/mapReturnedResponse.js.map +1 -0
- package/lib/cjs/utils/printRoutes.js +36 -0
- package/lib/cjs/utils/printRoutes.js.map +1 -0
- package/lib/cjs/utils/setResponseHeaders.js +35 -0
- package/lib/cjs/utils/setResponseHeaders.js.map +1 -0
- package/lib/cjs/utils/useCtxHandler.js +15 -0
- package/lib/cjs/utils/useCtxHandler.js.map +1 -0
- package/lib/esm/builder/PlatformBuilder.js +271 -0
- package/lib/esm/builder/PlatformBuilder.js.map +1 -0
- package/lib/esm/builder/PlatformControllerBuilder.js +79 -0
- package/lib/esm/builder/PlatformControllerBuilder.js.map +1 -0
- package/lib/esm/config/index.js +4 -0
- package/lib/esm/config/index.js.map +1 -0
- package/lib/esm/config/interfaces/ConverterSettings.js +2 -0
- package/lib/esm/config/interfaces/ConverterSettings.js.map +1 -0
- package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js +2 -0
- package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js.map +1 -0
- package/lib/esm/config/interfaces/PlatformLoggerSettings.js +2 -0
- package/lib/esm/config/interfaces/PlatformLoggerSettings.js.map +1 -0
- package/lib/esm/config/interfaces/PlatformMulterSettings.js +2 -0
- package/lib/esm/config/interfaces/PlatformMulterSettings.js.map +1 -0
- package/lib/esm/config/interfaces/PlatformStaticsSettings.js +2 -0
- package/lib/esm/config/interfaces/PlatformStaticsSettings.js.map +1 -0
- package/lib/esm/config/interfaces/index.js +5 -0
- package/lib/esm/config/interfaces/index.js.map +1 -0
- package/lib/esm/config/services/PlatformConfiguration.js +178 -0
- package/lib/esm/config/services/PlatformConfiguration.js.map +1 -0
- package/lib/esm/constants/routerOptions.js +2 -0
- package/lib/esm/constants/routerOptions.js.map +1 -0
- package/lib/esm/decorators/httpServer.js +28 -0
- package/lib/esm/decorators/httpServer.js.map +1 -0
- package/lib/esm/decorators/httpsServer.js +28 -0
- package/lib/esm/decorators/httpsServer.js.map +1 -0
- package/lib/esm/decorators/index.js +18 -0
- package/lib/esm/decorators/index.js.map +1 -0
- package/lib/esm/decorators/method/acceptMime.js +24 -0
- package/lib/esm/decorators/method/acceptMime.js.map +1 -0
- package/lib/esm/decorators/method/endpointFn.js +11 -0
- package/lib/esm/decorators/method/endpointFn.js.map +1 -0
- package/lib/esm/decorators/method/location.js +2 -0
- package/lib/esm/decorators/method/location.js.map +1 -0
- package/lib/esm/decorators/method/redirect.js +2 -0
- package/lib/esm/decorators/method/redirect.js.map +1 -0
- package/lib/esm/decorators/method/route.js +2 -0
- package/lib/esm/decorators/method/route.js.map +1 -0
- package/lib/esm/decorators/method/view.js +30 -0
- package/lib/esm/decorators/method/view.js.map +1 -0
- package/lib/esm/decorators/multer/index.js +4 -0
- package/lib/esm/decorators/multer/index.js.map +1 -0
- package/lib/esm/decorators/multer/multerFileSize.js +31 -0
- package/lib/esm/decorators/multer/multerFileSize.js.map +1 -0
- package/lib/esm/decorators/multer/multerOptions.js +48 -0
- package/lib/esm/decorators/multer/multerOptions.js.map +1 -0
- package/lib/esm/decorators/multer/multipartFile.js +74 -0
- package/lib/esm/decorators/multer/multipartFile.js.map +1 -0
- package/lib/esm/decorators/params/error.js +16 -0
- package/lib/esm/decorators/params/error.js.map +1 -0
- package/lib/esm/decorators/params/next.js +17 -0
- package/lib/esm/decorators/params/next.js.map +1 -0
- package/lib/esm/decorators/params/request.js +34 -0
- package/lib/esm/decorators/params/request.js.map +1 -0
- package/lib/esm/decorators/params/response.js +28 -0
- package/lib/esm/decorators/params/response.js.map +1 -0
- package/lib/esm/domain/AnyToPromiseWithCtx.js +23 -0
- package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -0
- package/lib/esm/domain/ControllerProvider.js +47 -0
- package/lib/esm/domain/ControllerProvider.js.map +1 -0
- package/lib/esm/domain/EndpointMetadata.js +67 -0
- package/lib/esm/domain/EndpointMetadata.js.map +1 -0
- package/lib/esm/domain/HandlerMetadata.js +53 -0
- package/lib/esm/domain/HandlerMetadata.js.map +1 -0
- package/lib/esm/domain/PlatformContext.js +88 -0
- package/lib/esm/domain/PlatformContext.js.map +1 -0
- package/lib/esm/domain/PlatformRouteDetails.js +20 -0
- package/lib/esm/domain/PlatformRouteDetails.js.map +1 -0
- package/lib/esm/domain/index.js +7 -0
- package/lib/esm/domain/index.js.map +1 -0
- package/lib/esm/index.js +28 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/AfterInit.js +2 -0
- package/lib/esm/interfaces/AfterInit.js.map +1 -0
- package/lib/esm/interfaces/AfterListen.js +2 -0
- package/lib/esm/interfaces/AfterListen.js.map +1 -0
- package/lib/esm/interfaces/AfterRoutesInit.js +2 -0
- package/lib/esm/interfaces/AfterRoutesInit.js.map +1 -0
- package/lib/esm/interfaces/BeforeInit.js +2 -0
- package/lib/esm/interfaces/BeforeInit.js.map +1 -0
- package/lib/esm/interfaces/BeforeListen.js +2 -0
- package/lib/esm/interfaces/BeforeListen.js.map +1 -0
- package/lib/esm/interfaces/BeforeRoutesInit.js +2 -0
- package/lib/esm/interfaces/BeforeRoutesInit.js.map +1 -0
- package/lib/esm/interfaces/HandlerType.js +14 -0
- package/lib/esm/interfaces/HandlerType.js.map +1 -0
- package/lib/esm/interfaces/IncomingEvent.js +2 -0
- package/lib/esm/interfaces/IncomingEvent.js.map +1 -0
- package/lib/esm/interfaces/OnReady.js +2 -0
- package/lib/esm/interfaces/OnReady.js.map +1 -0
- package/lib/esm/interfaces/OnRequest.js +2 -0
- package/lib/esm/interfaces/OnRequest.js.map +1 -0
- package/lib/esm/interfaces/OnResponse.js +2 -0
- package/lib/esm/interfaces/OnResponse.js.map +1 -0
- package/lib/esm/interfaces/OnRoutesInit.js +2 -0
- package/lib/esm/interfaces/OnRoutesInit.js.map +1 -0
- package/lib/esm/interfaces/PathType.js +2 -0
- package/lib/esm/interfaces/PathType.js.map +1 -0
- package/lib/esm/interfaces/PlatformAdapter.js +2 -0
- package/lib/esm/interfaces/PlatformAdapter.js.map +1 -0
- package/lib/esm/interfaces/PlatformRouteOptions.js +2 -0
- package/lib/esm/interfaces/PlatformRouteOptions.js.map +1 -0
- package/lib/esm/interfaces/ResponseErrorObject.js +2 -0
- package/lib/esm/interfaces/ResponseErrorObject.js.map +1 -0
- package/lib/esm/interfaces/Route.js +2 -0
- package/lib/esm/interfaces/Route.js.map +1 -0
- package/lib/esm/interfaces/index.js +18 -0
- package/lib/esm/interfaces/index.js.map +1 -0
- package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js +34 -0
- package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
- package/lib/esm/middlewares/PlatformMulterMiddleware.js +52 -0
- package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -0
- package/lib/esm/middlewares/__mock__/FakeCtrl.js +9 -0
- package/lib/esm/middlewares/__mock__/FakeCtrl.js.map +1 -0
- package/lib/esm/middlewares/bindEndpointMiddleware.js +9 -0
- package/lib/esm/middlewares/bindEndpointMiddleware.js.map +1 -0
- package/lib/esm/middlewares/index.js +4 -0
- package/lib/esm/middlewares/index.js.map +1 -0
- package/lib/esm/services/FakeRawDriver.js +22 -0
- package/lib/esm/services/FakeRawDriver.js.map +1 -0
- package/lib/esm/services/Platform.js +104 -0
- package/lib/esm/services/Platform.js.map +1 -0
- package/lib/esm/services/PlatformApplication.js +31 -0
- package/lib/esm/services/PlatformApplication.js.map +1 -0
- package/lib/esm/services/PlatformHandler.js +230 -0
- package/lib/esm/services/PlatformHandler.js.map +1 -0
- package/lib/esm/services/PlatformMiddlewaresChain.js +31 -0
- package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -0
- package/lib/esm/services/PlatformRequest.js +135 -0
- package/lib/esm/services/PlatformRequest.js.map +1 -0
- package/lib/esm/services/PlatformResponse.js +268 -0
- package/lib/esm/services/PlatformResponse.js.map +1 -0
- package/lib/esm/services/PlatformRouter.js +123 -0
- package/lib/esm/services/PlatformRouter.js.map +1 -0
- package/lib/esm/services/PlatformTest.js +162 -0
- package/lib/esm/services/PlatformTest.js.map +1 -0
- package/lib/esm/services/index.js +9 -0
- package/lib/esm/services/index.js.map +1 -0
- package/lib/esm/utils/createContext.js +34 -0
- package/lib/esm/utils/createContext.js.map +1 -0
- package/lib/esm/utils/createHandlerMetadata.js +45 -0
- package/lib/esm/utils/createHandlerMetadata.js.map +1 -0
- package/lib/esm/utils/createHttpServer.js +29 -0
- package/lib/esm/utils/createHttpServer.js.map +1 -0
- package/lib/esm/utils/createHttpsServer.js +29 -0
- package/lib/esm/utils/createHttpsServer.js.map +1 -0
- package/lib/esm/utils/createInjector.js +34 -0
- package/lib/esm/utils/createInjector.js.map +1 -0
- package/lib/esm/utils/getConfiguration.js +38 -0
- package/lib/esm/utils/getConfiguration.js.map +1 -0
- package/lib/esm/utils/getStaticsOptions.js +17 -0
- package/lib/esm/utils/getStaticsOptions.js.map +1 -0
- package/lib/esm/utils/index.js +8 -0
- package/lib/esm/utils/index.js.map +1 -0
- package/lib/esm/utils/listenServer.js +17 -0
- package/lib/esm/utils/listenServer.js.map +1 -0
- package/lib/esm/utils/mapReturnedResponse.js +11 -0
- package/lib/esm/utils/mapReturnedResponse.js.map +1 -0
- package/lib/esm/utils/printRoutes.js +32 -0
- package/lib/esm/utils/printRoutes.js.map +1 -0
- package/lib/esm/utils/setResponseHeaders.js +31 -0
- package/lib/esm/utils/setResponseHeaders.js.map +1 -0
- package/lib/esm/utils/useCtxHandler.js +11 -0
- package/lib/esm/utils/useCtxHandler.js.map +1 -0
- package/lib/{builder → types/builder}/PlatformBuilder.d.ts +25 -30
- package/lib/types/builder/PlatformControllerBuilder.d.ts +17 -0
- package/lib/{config → types/config}/index.d.ts +0 -0
- package/lib/{config → types/config}/interfaces/ConverterSettings.d.ts +0 -0
- package/lib/{config → types/config}/interfaces/EndpointDirectoriesSettings.d.ts +0 -0
- package/lib/{config → types/config}/interfaces/PlatformLoggerSettings.d.ts +0 -0
- package/lib/{config → types/config}/interfaces/PlatformMulterSettings.d.ts +0 -0
- package/lib/{config → types/config}/interfaces/PlatformStaticsSettings.d.ts +1 -0
- package/lib/{config → types/config}/interfaces/index.d.ts +14 -1
- package/lib/{config → types/config}/services/PlatformConfiguration.d.ts +12 -11
- package/lib/{constants → types/constants}/routerOptions.d.ts +0 -0
- package/lib/{decorators → types/decorators}/httpServer.d.ts +1 -0
- package/lib/{decorators → types/decorators}/httpsServer.d.ts +1 -0
- package/lib/{decorators → types/decorators}/index.d.ts +1 -0
- package/lib/{decorators → types/decorators}/method/acceptMime.d.ts +0 -0
- package/lib/{decorators → types/decorators}/method/endpointFn.d.ts +1 -0
- package/lib/{decorators → types/decorators}/method/location.d.ts +0 -0
- package/lib/{decorators → types/decorators}/method/redirect.d.ts +0 -0
- package/lib/{decorators → types/decorators}/method/route.d.ts +0 -0
- package/lib/types/decorators/method/view.d.ts +25 -0
- package/lib/{decorators → types/decorators}/multer/index.d.ts +0 -0
- package/lib/{decorators → types/decorators}/multer/multerFileSize.d.ts +0 -0
- package/lib/{decorators → types/decorators}/multer/multerOptions.d.ts +0 -0
- package/lib/{decorators → types/decorators}/multer/multipartFile.d.ts +0 -0
- package/lib/{decorators → types/decorators}/params/error.d.ts +0 -0
- package/lib/{decorators → types/decorators}/params/next.d.ts +0 -0
- package/lib/{decorators → types/decorators}/params/request.d.ts +0 -0
- package/lib/{decorators → types/decorators}/params/response.d.ts +0 -0
- package/lib/{domain → types/domain}/AnyToPromiseWithCtx.d.ts +0 -0
- package/lib/types/domain/ControllerProvider.d.ts +24 -0
- package/lib/{domain → types/domain}/EndpointMetadata.d.ts +3 -41
- package/lib/{domain → types/domain}/HandlerMetadata.d.ts +2 -2
- package/lib/{domain → types/domain}/PlatformContext.d.ts +0 -0
- package/lib/{domain → types/domain}/PlatformRouteDetails.d.ts +4 -10
- package/lib/{domain → types/domain}/index.d.ts +0 -0
- package/lib/{index.d.ts → types/index.d.ts} +1 -3
- package/lib/{interfaces → types/interfaces}/AfterInit.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/AfterListen.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/AfterRoutesInit.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/BeforeInit.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/BeforeListen.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/BeforeRoutesInit.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/HandlerType.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/IncomingEvent.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/OnReady.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/OnRequest.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/OnResponse.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/OnRoutesInit.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/PathType.d.ts +0 -0
- package/lib/types/interfaces/PlatformAdapter.d.ts +19 -0
- package/lib/{interfaces → types/interfaces}/PlatformRouteOptions.d.ts +6 -4
- package/lib/{interfaces → types/interfaces}/ResponseErrorObject.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/Route.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/index.d.ts +1 -1
- package/lib/{middlewares → types/middlewares}/PlatformAcceptMimesMiddleware.d.ts +0 -0
- package/lib/{middlewares → types/middlewares}/PlatformMulterMiddleware.d.ts +0 -0
- package/lib/{middlewares/data → types/middlewares/__mock__}/FakeCtrl.d.ts +0 -0
- package/lib/{middlewares → types/middlewares}/bindEndpointMiddleware.d.ts +0 -0
- package/lib/{middlewares → types/middlewares}/index.d.ts +0 -0
- package/lib/{services → types/services}/FakeRawDriver.d.ts +0 -0
- package/lib/{services → types/services}/Platform.d.ts +12 -6
- package/lib/{services → types/services}/PlatformApplication.d.ts +0 -0
- package/lib/{services → types/services}/PlatformHandler.d.ts +0 -0
- package/lib/types/services/PlatformMiddlewaresChain.d.ts +6 -0
- package/lib/{services → types/services}/PlatformRequest.d.ts +2 -1
- package/lib/{services → types/services}/PlatformResponse.d.ts +4 -4
- package/lib/{services → types/services}/PlatformRouter.d.ts +3 -2
- package/lib/{services → types/services}/PlatformTest.d.ts +7 -6
- package/lib/{services → types/services}/index.d.ts +1 -0
- package/lib/{utils → types/utils}/createContext.d.ts +0 -0
- package/lib/{utils → types/utils}/createHandlerMetadata.d.ts +0 -0
- package/lib/types/utils/createHttpServer.d.ts +4 -0
- package/lib/types/utils/createHttpsServer.d.ts +4 -0
- package/lib/types/utils/createInjector.d.ts +7 -0
- package/lib/types/utils/getConfiguration.d.ts +2 -0
- package/lib/types/utils/getStaticsOptions.d.ts +5 -0
- package/lib/{utils → types/utils}/index.d.ts +0 -1
- package/lib/types/utils/listenServer.d.ts +7 -0
- package/lib/{utils → types/utils}/mapReturnedResponse.d.ts +0 -0
- package/lib/{utils → types/utils}/printRoutes.d.ts +0 -0
- package/lib/{utils → types/utils}/setResponseHeaders.d.ts +0 -0
- package/lib/{utils → types/utils}/useCtxHandler.d.ts +0 -0
- package/package.json +29 -28
- package/tsconfig.compile.esm.json +23 -0
- package/lib/PlatformModule.d.ts +0 -15
- package/lib/builder/PlatformControllerBuilder.d.ts +0 -19
- package/lib/domain/ControllerProvider.d.ts +0 -53
- package/lib/index.js +0 -3651
- package/lib/index.js.map +0 -1
- package/lib/index.modern.js +0 -3464
- package/lib/index.modern.js.map +0 -1
- package/lib/interfaces/PlatformRouterMethods.d.ts +0 -10
- package/lib/registries/ControllerRegistry.d.ts +0 -1
- package/lib/utils/createHttpServer.d.ts +0 -3
- package/lib/utils/createHttpsServer.d.ts +0 -3
- package/lib/utils/createInjector.d.ts +0 -2
- package/lib/utils/createPlatformApplication.d.ts +0 -2
- package/lib/utils/getControllerPath.d.ts +0 -2
- package/lib/utils/listenServer.d.ts +0 -10
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { Injectable } from "@tsed/di";
|
|
3
|
+
import { ParamTypes } from "@tsed/platform-params";
|
|
4
|
+
import { bindEndpointMiddleware } from "../middlewares/bindEndpointMiddleware";
|
|
5
|
+
import { PlatformAcceptMimesMiddleware } from "../middlewares/PlatformAcceptMimesMiddleware";
|
|
6
|
+
import { PlatformMulterMiddleware } from "../middlewares/PlatformMulterMiddleware";
|
|
7
|
+
import { useCtxHandler } from "../utils/useCtxHandler";
|
|
8
|
+
let PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
|
|
9
|
+
get(provider, operationRoute) {
|
|
10
|
+
const { endpoint } = operationRoute;
|
|
11
|
+
const { beforeMiddlewares, middlewares: mldwrs, afterMiddlewares } = endpoint;
|
|
12
|
+
const { middlewares: { use, useAfter } } = provider;
|
|
13
|
+
const hasFiles = [...operationRoute.endpoint.children.values()].find((item) => item.paramType === ParamTypes.FILES);
|
|
14
|
+
return []
|
|
15
|
+
.concat(useCtxHandler(bindEndpointMiddleware(endpoint)))
|
|
16
|
+
.concat(PlatformAcceptMimesMiddleware)
|
|
17
|
+
.concat(hasFiles && PlatformMulterMiddleware)
|
|
18
|
+
.concat(beforeMiddlewares) // Endpoint before-middlewares
|
|
19
|
+
.concat(use) // Controller use-middlewares
|
|
20
|
+
.concat(mldwrs) // Endpoint middlewares
|
|
21
|
+
.concat(endpoint) // Endpoint metadata
|
|
22
|
+
.concat(afterMiddlewares) // Endpoint after-middlewares
|
|
23
|
+
.concat(useAfter) // Controller after middlewares (equivalent to afterEach)
|
|
24
|
+
.filter((item) => !!item);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
PlatformMiddlewaresChain = __decorate([
|
|
28
|
+
Injectable()
|
|
29
|
+
], PlatformMiddlewaresChain);
|
|
30
|
+
export { PlatformMiddlewaresChain };
|
|
31
|
+
//# sourceMappingURL=PlatformMiddlewaresChain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformMiddlewaresChain.js","sourceRoot":"","sources":["../../../src/services/PlatformMiddlewaresChain.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACpC,OAAO,EAAgB,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAIhE,OAAO,EAAC,sBAAsB,EAAC,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAC,6BAA6B,EAAC,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EAAC,wBAAwB,EAAC,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAGrD,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;IACnC,GAAG,CAAC,QAA4B,EAAE,cAAoD;QACpF,MAAM,EAAC,QAAQ,EAAC,GAAG,cAAc,CAAC;QAClC,MAAM,EAAC,iBAAiB,EAAE,WAAW,EAAE,MAAM,EAAE,gBAAgB,EAAC,GAAG,QAAQ,CAAC;QAE5E,MAAM,EACJ,WAAW,EAAE,EAAC,GAAG,EAAE,QAAQ,EAAC,EAC7B,GAAG,QAAQ,CAAC;QAEb,MAAM,QAAQ,GAAG,CAAC,GAAG,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAmB,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,UAAU,CAAC,KAAK,CAAC,CAAC;QAEnI,OAAQ,EAAY;aACjB,MAAM,CAAC,aAAa,CAAC,sBAAsB,CAAC,QAAQ,CAAC,CAAC,CAAC;aACvD,MAAM,CAAC,6BAA6B,CAAC;aACrC,MAAM,CAAC,QAAQ,IAAI,wBAAwB,CAAC;aAC5C,MAAM,CAAC,iBAAiB,CAAC,CAAC,8BAA8B;aACxD,MAAM,CAAC,GAAG,CAAC,CAAC,6BAA6B;aACzC,MAAM,CAAC,MAAM,CAAC,CAAC,uBAAuB;aACtC,MAAM,CAAC,QAAQ,CAAC,CAAC,oBAAoB;aACrC,MAAM,CAAC,gBAAgB,CAAC,CAAC,6BAA6B;aACtD,MAAM,CAAC,QAAQ,CAAC,CAAC,yDAAyD;aAC1E,MAAM,CAAC,CAAC,IAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;CACF,CAAA;AAvBY,wBAAwB;IADpC,UAAU,EAAE;GACA,wBAAwB,CAuBpC;SAvBY,wBAAwB","sourcesContent":["import {Injectable} from \"@tsed/di\";\nimport {ParamMetadata, ParamTypes} from \"@tsed/platform-params\";\nimport {JsonOperationRoute} from \"@tsed/schema\";\nimport {ControllerProvider} from \"../domain/ControllerProvider\";\nimport {EndpointMetadata} from \"../domain/EndpointMetadata\";\nimport {bindEndpointMiddleware} from \"../middlewares/bindEndpointMiddleware\";\nimport {PlatformAcceptMimesMiddleware} from \"../middlewares/PlatformAcceptMimesMiddleware\";\nimport {PlatformMulterMiddleware} from \"../middlewares/PlatformMulterMiddleware\";\nimport {useCtxHandler} from \"../utils/useCtxHandler\";\n\n@Injectable()\nexport class PlatformMiddlewaresChain {\n get(provider: ControllerProvider, operationRoute: JsonOperationRoute<EndpointMetadata>) {\n const {endpoint} = operationRoute;\n const {beforeMiddlewares, middlewares: mldwrs, afterMiddlewares} = endpoint;\n\n const {\n middlewares: {use, useAfter}\n } = provider;\n\n const hasFiles = [...operationRoute.endpoint.children.values()].find((item: ParamMetadata) => item.paramType === ParamTypes.FILES);\n\n return ([] as any[])\n .concat(useCtxHandler(bindEndpointMiddleware(endpoint)))\n .concat(PlatformAcceptMimesMiddleware)\n .concat(hasFiles && PlatformMulterMiddleware)\n .concat(beforeMiddlewares) // Endpoint before-middlewares\n .concat(use) // Controller use-middlewares\n .concat(mldwrs) // Endpoint middlewares\n .concat(endpoint) // Endpoint metadata\n .concat(afterMiddlewares) // Endpoint after-middlewares\n .concat(useAfter) // Controller after middlewares (equivalent to afterEach)\n .filter((item: any) => !!item);\n }\n}\n"]}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Injectable, ProviderScope, Scope } from "@tsed/di";
|
|
3
|
+
/**
|
|
4
|
+
* Platform Request abstraction layer.
|
|
5
|
+
* @platform
|
|
6
|
+
*/
|
|
7
|
+
let PlatformRequest = class PlatformRequest {
|
|
8
|
+
constructor({ request }, $ctx) {
|
|
9
|
+
this.$ctx = $ctx;
|
|
10
|
+
this.raw = request;
|
|
11
|
+
}
|
|
12
|
+
get secure() {
|
|
13
|
+
return this.raw.secure;
|
|
14
|
+
}
|
|
15
|
+
get host() {
|
|
16
|
+
return this.get("host");
|
|
17
|
+
}
|
|
18
|
+
get protocol() {
|
|
19
|
+
return this.raw.protocol;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the url of the request.
|
|
23
|
+
*
|
|
24
|
+
* Is equivalent of `express.response.originalUrl || express.response.url`.
|
|
25
|
+
*/
|
|
26
|
+
get url() {
|
|
27
|
+
return this.raw.originalUrl || this.raw.url;
|
|
28
|
+
}
|
|
29
|
+
get headers() {
|
|
30
|
+
return this.raw.headers;
|
|
31
|
+
}
|
|
32
|
+
get method() {
|
|
33
|
+
return this.raw.method;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Contains key-value pairs of data submitted in the request body. By default, it is `undefined`, and is populated when you use
|
|
37
|
+
* `body-parsing` middleware such as `express.json()` or `express.urlencoded()`.
|
|
38
|
+
*/
|
|
39
|
+
get body() {
|
|
40
|
+
return this.raw.body;
|
|
41
|
+
}
|
|
42
|
+
get rawBody() {
|
|
43
|
+
return this.raw.rawBody || this.raw.body;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* When using `cookie-parser` middleware, this property is an object that contains cookies sent by the request.
|
|
47
|
+
* If the request contains no cookies, it defaults to `{}`.
|
|
48
|
+
*/
|
|
49
|
+
get cookies() {
|
|
50
|
+
return this.raw.cookies;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* This property is an object containing properties mapped to the named route `parameters`.
|
|
54
|
+
* For example, if you have the route `/user/:name`, then the `name` property is available as `req.params.name`.
|
|
55
|
+
* This object defaults to `{}`.
|
|
56
|
+
*/
|
|
57
|
+
get params() {
|
|
58
|
+
return this.raw.params;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* This property is an object containing a property for each query string parameter in the route.
|
|
62
|
+
* When query parser is set to disabled, it is an empty object `{}`, otherwise it is the result of the configured query parser.
|
|
63
|
+
*/
|
|
64
|
+
get query() {
|
|
65
|
+
return this.raw.query;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* This property is an object containing a property for each session attributes set by any code.
|
|
69
|
+
* It require to install a middleware like express-session to work.
|
|
70
|
+
*/
|
|
71
|
+
get session() {
|
|
72
|
+
return this.raw.session;
|
|
73
|
+
}
|
|
74
|
+
get files() {
|
|
75
|
+
return this.raw.files;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Return the original request framework instance
|
|
79
|
+
*/
|
|
80
|
+
get request() {
|
|
81
|
+
return this.getRequest();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Return the original request node.js instance
|
|
85
|
+
*/
|
|
86
|
+
get req() {
|
|
87
|
+
return this.getReq();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Returns the HTTP request header specified by field. The match is case-insensitive.
|
|
91
|
+
*
|
|
92
|
+
* ```typescript
|
|
93
|
+
* request.get('Content-Type') // => "text/plain"
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @param name
|
|
97
|
+
*/
|
|
98
|
+
get(name) {
|
|
99
|
+
return this.raw.get(name);
|
|
100
|
+
}
|
|
101
|
+
accepts(mime) {
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
return this.raw.accepts(mime);
|
|
104
|
+
}
|
|
105
|
+
isAborted() {
|
|
106
|
+
return this.raw.aborted;
|
|
107
|
+
}
|
|
108
|
+
destroy() {
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
delete this.raw;
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
delete this.response;
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
delete this.$ctx;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Return the Framework response object (express, koa, etc...)
|
|
118
|
+
*/
|
|
119
|
+
getRequest() {
|
|
120
|
+
return this.raw;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Return the Node.js response object
|
|
124
|
+
*/
|
|
125
|
+
getReq() {
|
|
126
|
+
return this.raw;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
PlatformRequest = __decorate([
|
|
130
|
+
Injectable(),
|
|
131
|
+
Scope(ProviderScope.INSTANCE),
|
|
132
|
+
__metadata("design:paramtypes", [Object, Function])
|
|
133
|
+
], PlatformRequest);
|
|
134
|
+
export { PlatformRequest };
|
|
135
|
+
//# sourceMappingURL=PlatformRequest.js.map
|
|
@@ -0,0 +1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HttpHeaders, 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,268 @@
|
|
|
1
|
+
var PlatformResponse_1;
|
|
2
|
+
import { __decorate, __metadata } from "tslib";
|
|
3
|
+
import { isBoolean, isNumber, isStream, isString } from "@tsed/core";
|
|
4
|
+
import { Injectable, ProviderScope, Scope } from "@tsed/di";
|
|
5
|
+
const onFinished = require("on-finished");
|
|
6
|
+
/**
|
|
7
|
+
* Platform Response abstraction layer.
|
|
8
|
+
* @platform
|
|
9
|
+
*/
|
|
10
|
+
let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
|
|
11
|
+
constructor({ response }, $ctx) {
|
|
12
|
+
this.$ctx = $ctx;
|
|
13
|
+
this.raw = response;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get the current statusCode
|
|
17
|
+
*/
|
|
18
|
+
get statusCode() {
|
|
19
|
+
return this.raw.statusCode;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* An object that contains response local variables scoped to the request, and therefore available only to the view(s) rendered during that request / response cycle (if any). Otherwise, this property is identical to app.locals.
|
|
23
|
+
*
|
|
24
|
+
* This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.
|
|
25
|
+
*/
|
|
26
|
+
get locals() {
|
|
27
|
+
return this.raw.locals;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Return the original response framework instance
|
|
31
|
+
*/
|
|
32
|
+
get response() {
|
|
33
|
+
return this.getResponse();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Return the original response node.js instance
|
|
37
|
+
*/
|
|
38
|
+
get res() {
|
|
39
|
+
return this.getRes();
|
|
40
|
+
}
|
|
41
|
+
static onFinished(res, cb) {
|
|
42
|
+
onFinished(res, cb);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns the HTTP response header specified by field. The match is case-insensitive.
|
|
46
|
+
*
|
|
47
|
+
* ```typescript
|
|
48
|
+
* response.get('Content-Type') // => "text/plain"
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @param name
|
|
52
|
+
*/
|
|
53
|
+
get(name) {
|
|
54
|
+
return this.raw.get(name);
|
|
55
|
+
}
|
|
56
|
+
getHeaders() {
|
|
57
|
+
return this.raw.getHeaders();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Return the Framework response object (express, koa, etc...)
|
|
61
|
+
*/
|
|
62
|
+
getResponse() {
|
|
63
|
+
return this.raw;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Return the Node.js response object
|
|
67
|
+
*/
|
|
68
|
+
getRes() {
|
|
69
|
+
return this.raw;
|
|
70
|
+
}
|
|
71
|
+
hasStatus() {
|
|
72
|
+
return this.statusCode !== 200;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Sets the HTTP status for the response.
|
|
76
|
+
*
|
|
77
|
+
* @param status
|
|
78
|
+
*/
|
|
79
|
+
status(status) {
|
|
80
|
+
this.raw.status(status);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Set header `field` to `val`, or pass
|
|
85
|
+
* an object of header fields.
|
|
86
|
+
*
|
|
87
|
+
* Examples:
|
|
88
|
+
* ```typescript
|
|
89
|
+
* response.setHeaders({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* Aliased as `res.header()`.
|
|
93
|
+
*/
|
|
94
|
+
setHeaders(headers) {
|
|
95
|
+
// apply headers
|
|
96
|
+
Object.entries(headers).forEach(([key, item]) => {
|
|
97
|
+
this.setHeader(key, item);
|
|
98
|
+
});
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
setHeader(key, item) {
|
|
102
|
+
if (key.toLowerCase() === "location") {
|
|
103
|
+
return this.location(String(item));
|
|
104
|
+
}
|
|
105
|
+
this.raw.set(key, item);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Set `Content-Type` response header with `type` through `mime.lookup()`
|
|
110
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
111
|
+
*
|
|
112
|
+
* Examples:
|
|
113
|
+
*
|
|
114
|
+
* res.type('.html');
|
|
115
|
+
* res.type('html');
|
|
116
|
+
* res.type('json');
|
|
117
|
+
* res.type('application/json');
|
|
118
|
+
* res.type('png');
|
|
119
|
+
*/
|
|
120
|
+
contentType(contentType) {
|
|
121
|
+
this.raw.contentType(contentType);
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
contentLength(length) {
|
|
125
|
+
this.setHeader("Content-Length", length);
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
getContentLength() {
|
|
129
|
+
if (this.get("Content-Length")) {
|
|
130
|
+
return parseInt(this.get("Content-Length"), 10) || 0;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
getContentType() {
|
|
134
|
+
return (this.get("Content-Type") || "").split(";")[0];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Sets the HTTP response Content-Disposition header field to “attachment”.
|
|
138
|
+
* If a filename is given, then it sets the Content-Type based on the extension name via res.type(), and sets the Content-Disposition “filename=” parameter.
|
|
139
|
+
*
|
|
140
|
+
* ```typescript
|
|
141
|
+
* res.attachment()
|
|
142
|
+
* // Content-Disposition: attachment
|
|
143
|
+
*
|
|
144
|
+
* res.attachment('path/to/logo.png')
|
|
145
|
+
* // Content-Disposition: attachment; filename="logo.png"
|
|
146
|
+
* // Content-Type: image/png
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* @param filename
|
|
150
|
+
*/
|
|
151
|
+
attachment(filename) {
|
|
152
|
+
this.raw.attachment(filename);
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an [HTTP status code](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html).
|
|
157
|
+
* If not specified, status defaults to `302 Found`.
|
|
158
|
+
*
|
|
159
|
+
* @param status
|
|
160
|
+
* @param url
|
|
161
|
+
*/
|
|
162
|
+
redirect(status, url) {
|
|
163
|
+
this.raw.redirect(status, url);
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Sets the response Location HTTP header to the specified path parameter.
|
|
168
|
+
*
|
|
169
|
+
* @param location
|
|
170
|
+
*/
|
|
171
|
+
location(location) {
|
|
172
|
+
this.raw.location(location);
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Stream the given data.
|
|
177
|
+
*
|
|
178
|
+
* @param data
|
|
179
|
+
*/
|
|
180
|
+
stream(data) {
|
|
181
|
+
data.pipe(this.raw);
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Renders a view and sends the rendered HTML string to the client.
|
|
186
|
+
*
|
|
187
|
+
* @param path
|
|
188
|
+
* @param options
|
|
189
|
+
*/
|
|
190
|
+
async render(path, options = {}) {
|
|
191
|
+
const { PlatformViews } = await import("@tsed/platform-views");
|
|
192
|
+
const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);
|
|
193
|
+
return platformViews.render(path, {
|
|
194
|
+
...this.locals,
|
|
195
|
+
...options
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Send any data to your consumer.
|
|
200
|
+
*
|
|
201
|
+
* This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.
|
|
202
|
+
* It choose the better way to send the data.
|
|
203
|
+
*
|
|
204
|
+
* @param data
|
|
205
|
+
*/
|
|
206
|
+
body(data) {
|
|
207
|
+
this.data = data;
|
|
208
|
+
if (data === undefined) {
|
|
209
|
+
this.raw.send();
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
if (isStream(data)) {
|
|
213
|
+
this.stream(data);
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
if (Buffer.isBuffer(data)) {
|
|
217
|
+
if (!this.getContentType()) {
|
|
218
|
+
this.contentType("application/octet-stream");
|
|
219
|
+
}
|
|
220
|
+
this.contentLength(data.length);
|
|
221
|
+
this.raw.send(data);
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
if (isBoolean(data) || isNumber(data) || isString(data) || data === null) {
|
|
225
|
+
this.raw.send(data);
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
this.raw.json(data);
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
getBody() {
|
|
232
|
+
return this.data;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Add a listener to handler the end of the request/response.
|
|
236
|
+
* @param cb
|
|
237
|
+
*/
|
|
238
|
+
onEnd(cb) {
|
|
239
|
+
PlatformResponse_1.onFinished(this.getRes(), cb);
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
isDone() {
|
|
243
|
+
if (!this.raw) {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
const res = this.getRes();
|
|
247
|
+
return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);
|
|
248
|
+
}
|
|
249
|
+
destroy() {
|
|
250
|
+
// @ts-ignore
|
|
251
|
+
delete this.raw;
|
|
252
|
+
delete this.data;
|
|
253
|
+
// @ts-ignore
|
|
254
|
+
delete this.request;
|
|
255
|
+
// @ts-ignore
|
|
256
|
+
delete this.$ctx;
|
|
257
|
+
}
|
|
258
|
+
isHeadersSent() {
|
|
259
|
+
return this.getRes().headersSent;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
PlatformResponse = PlatformResponse_1 = __decorate([
|
|
263
|
+
Injectable(),
|
|
264
|
+
Scope(ProviderScope.INSTANCE),
|
|
265
|
+
__metadata("design:paramtypes", [Object, Function])
|
|
266
|
+
], PlatformResponse);
|
|
267
|
+
export { PlatformResponse };
|
|
268
|
+
//# sourceMappingURL=PlatformResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformResponse.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACnE,OAAO,EAAC,UAAU,EAAE,aAAa,EAAE,KAAK,EAAC,MAAM,UAAU,CAAC;AAM1D,MAAM,UAAU,GAAG,O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AAC;IACnB,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC;IACnC,CAAC;CACF,CAAA;AAtTY,gBAAgB;IAF5B,UAAU,EAAE;IACZ,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC;;GACjB,gBAAgB,CAsT5B;SAtTY,gBAAgB","sourcesContent":["import {isBoolean, isNumber, isStream, isString} from \"@tsed/core\";\nimport {Injectable, ProviderScope, Scope} from \"@tsed/di\";\nimport {ServerResponse} from \"http\";\nimport {IncomingEvent} from \"../interfaces/IncomingEvent\";\nimport type {PlatformRequest} from \"./PlatformRequest\";\nimport type {PlatformContext} from \"../domain/PlatformContext\";\n\nconst onFinished = require(\"on-finished\");\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Response {\n // req: any;\n }\n }\n}\n\nexport type HeaderValue = Array<boolean | number | string> | boolean | number | string;\n\n/**\n * Platform Response abstraction layer.\n * @platform\n */\n@Injectable()\n@Scope(ProviderScope.INSTANCE)\nexport class PlatformResponse<T extends Record<string, any> = any> {\n /**\n * The current @@PlatformRequest@@.\n */\n public request: PlatformRequest;\n\n data: any;\n\n raw: T;\n\n constructor({response}: IncomingEvent, protected $ctx: PlatformContext) {\n this.raw = response as any;\n }\n\n /**\n * Get the current statusCode\n */\n get statusCode() {\n return this.raw.statusCode;\n }\n\n /**\n * An object that contains response local variables scoped to the request, and therefore available only to the view(s) rendered during that request / response cycle (if any). Otherwise, this property is identical to app.locals.\n *\n * This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.\n */\n get locals() {\n return this.raw.locals;\n }\n\n /**\n * Return the original response framework instance\n */\n get response() {\n return this.getResponse();\n }\n\n /**\n * Return the original response node.js instance\n */\n get res() {\n return this.getRes();\n }\n\n static onFinished(res: any, cb: Function) {\n onFinished(res, cb);\n }\n\n /**\n * Returns the HTTP response header specified by field. The match is case-insensitive.\n *\n * ```typescript\n * response.get('Content-Type') // => \"text/plain\"\n * ```\n *\n * @param name\n */\n get(name: string) {\n return this.raw.get(name);\n }\n\n getHeaders(): Record<string, HeaderValue> {\n return this.raw.getHeaders();\n }\n\n /**\n * Return the Framework response object (express, koa, etc...)\n */\n getResponse<Res = T>(): Res {\n return this.raw as any;\n }\n\n /**\n * Return the Node.js response object\n */\n getRes(): ServerResponse {\n return this.raw as any;\n }\n\n hasStatus() {\n return this.statusCode !== 200;\n }\n\n /**\n * Sets the HTTP status for the response.\n *\n * @param status\n */\n status(status: number) {\n this.raw.status(status);\n\n return this;\n }\n\n /**\n * Set header `field` to `val`, or pass\n * an object of header fields.\n *\n * Examples:\n * ```typescript\n * response.setHeaders({ Accept: 'text/plain', 'X-API-Key': 'tobi' });\n * ```\n *\n * Aliased as `res.header()`.\n */\n setHeaders(headers: Record<string, HeaderValue>) {\n // apply headers\n Object.entries(headers).forEach(([key, item]) => {\n this.setHeader(key, item);\n });\n\n return this;\n }\n\n setHeader(key: string, item: any) {\n if (key.toLowerCase() === \"location\") {\n return this.location(String(item));\n }\n\n this.raw.set(key, item);\n\n return this;\n }\n\n /**\n * Set `Content-Type` response header with `type` through `mime.lookup()`\n * when it does not contain \"/\", or set the Content-Type to `type` otherwise.\n *\n * Examples:\n *\n * res.type('.html');\n * res.type('html');\n * res.type('json');\n * res.type('application/json');\n * res.type('png');\n */\n contentType(contentType: string) {\n this.raw.contentType(contentType);\n\n return this;\n }\n\n contentLength(length: number) {\n this.setHeader(\"Content-Length\", length);\n return this;\n }\n\n getContentLength() {\n if (this.get(\"Content-Length\")) {\n return parseInt(this.get(\"Content-Length\"), 10) || 0;\n }\n }\n\n getContentType() {\n return (this.get(\"Content-Type\") || \"\").split(\";\")[0];\n }\n\n /**\n * Sets the HTTP response Content-Disposition header field to “attachment”.\n * If a filename is given, then it sets the Content-Type based on the extension name via res.type(), and sets the Content-Disposition “filename=” parameter.\n *\n * ```typescript\n * res.attachment()\n * // Content-Disposition: attachment\n *\n * res.attachment('path/to/logo.png')\n * // Content-Disposition: attachment; filename=\"logo.png\"\n * // Content-Type: image/png\n * ```\n *\n * @param filename\n */\n attachment(filename: string) {\n this.raw.attachment(filename);\n return this;\n }\n\n /**\n * Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an [HTTP status code](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html).\n * If not specified, status defaults to `302 Found`.\n *\n * @param status\n * @param url\n */\n redirect(status: number, url: string) {\n this.raw.redirect(status, url);\n\n return this;\n }\n\n /**\n * Sets the response Location HTTP header to the specified path parameter.\n *\n * @param location\n */\n location(location: string) {\n this.raw.location(location);\n\n return this;\n }\n\n /**\n * Stream the given data.\n *\n * @param data\n */\n stream(data: ReadableStream | any) {\n data.pipe(this.raw);\n\n return this;\n }\n\n /**\n * Renders a view and sends the rendered HTML string to the client.\n *\n * @param path\n * @param options\n */\n async render(path: string, options: any = {}) {\n const {PlatformViews} = await import(\"@tsed/platform-views\");\n const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);\n\n return platformViews.render(path, {\n ...this.locals,\n ...options\n });\n }\n\n /**\n * Send any data to your consumer.\n *\n * This method accept a ReadableStream, a plain object, boolean, string, number, null and undefined data.\n * It choose the better way to send the data.\n *\n * @param data\n */\n body(data: any) {\n this.data = data;\n\n if (data === undefined) {\n this.raw.send();\n\n return this;\n }\n\n if (isStream(data)) {\n this.stream(data);\n\n return this;\n }\n\n if (Buffer.isBuffer(data)) {\n if (!this.getContentType()) {\n this.contentType(\"application/octet-stream\");\n }\n\n this.contentLength(data.length);\n this.raw.send(data);\n\n return this;\n }\n\n if (isBoolean(data) || isNumber(data) || isString(data) || data === null) {\n this.raw.send(data);\n\n return this;\n }\n\n this.raw.json(data);\n\n return this;\n }\n\n getBody() {\n return this.data;\n }\n\n /**\n * Add a listener to handler the end of the request/response.\n * @param cb\n */\n onEnd(cb: Function): this {\n PlatformResponse.onFinished(this.getRes(), cb);\n\n return this;\n }\n\n isDone(): boolean {\n if (!this.raw) {\n return true;\n }\n\n const res = this.getRes();\n\n return Boolean(this.isHeadersSent() || res.writableEnded || res.writableFinished);\n }\n\n destroy() {\n // @ts-ignore\n delete this.raw;\n delete this.data;\n // @ts-ignore\n delete this.request;\n // @ts-ignore\n delete this.$ctx;\n }\n\n isHeadersSent() {\n return this.getRes().headersSent;\n }\n}\n"]}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
var PlatformRouter_1;
|
|
2
|
+
import { __decorate, __metadata } from "tslib";
|
|
3
|
+
import { Inject, Injectable, InjectorService, ProviderScope } from "@tsed/di";
|
|
4
|
+
import { promisify } from "util";
|
|
5
|
+
import { createFakeRawDriver } from "./FakeRawDriver";
|
|
6
|
+
import { PlatformHandler } from "./PlatformHandler";
|
|
7
|
+
/**
|
|
8
|
+
* @ignore
|
|
9
|
+
*/
|
|
10
|
+
export const PLATFORM_ROUTER_OPTIONS = Symbol.for("PlatformRouterOptions");
|
|
11
|
+
/**
|
|
12
|
+
* Platform Router abstraction layer.
|
|
13
|
+
* @platform
|
|
14
|
+
*/
|
|
15
|
+
let PlatformRouter = PlatformRouter_1 = class PlatformRouter {
|
|
16
|
+
constructor(platformHandler) {
|
|
17
|
+
this.platformHandler = platformHandler;
|
|
18
|
+
this.isBuilt = false;
|
|
19
|
+
this.rawRouter = this.raw = PlatformRouter_1.createRawRouter();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a new instance of PlatformRouter
|
|
23
|
+
* @param injector
|
|
24
|
+
* @param routerOptions
|
|
25
|
+
*/
|
|
26
|
+
static create(injector, routerOptions = {}) {
|
|
27
|
+
const locals = new Map();
|
|
28
|
+
locals.set(PLATFORM_ROUTER_OPTIONS, routerOptions);
|
|
29
|
+
return injector.invoke(PlatformRouter_1, locals);
|
|
30
|
+
}
|
|
31
|
+
static createRawRouter() {
|
|
32
|
+
return createFakeRawDriver();
|
|
33
|
+
}
|
|
34
|
+
callback() {
|
|
35
|
+
return this.raw;
|
|
36
|
+
}
|
|
37
|
+
getRouter() {
|
|
38
|
+
return this.rawRouter;
|
|
39
|
+
}
|
|
40
|
+
use(...handlers) {
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
this.getRouter().use(...this.mapHandlers(handlers));
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
addRoute(options) {
|
|
46
|
+
const { method, path, handlers, ...opts } = options;
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
this.getRouter()[method](path, ...this.mapHandlers(handlers, { method, path, ...opts }));
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
all(path, ...handlers) {
|
|
52
|
+
return this.addRoute({ method: "all", path, handlers, isFinal: true });
|
|
53
|
+
}
|
|
54
|
+
get(path, ...handlers) {
|
|
55
|
+
return this.addRoute({ method: "get", path, handlers, isFinal: true });
|
|
56
|
+
}
|
|
57
|
+
post(path, ...handlers) {
|
|
58
|
+
return this.addRoute({ method: "post", path, handlers, isFinal: true });
|
|
59
|
+
}
|
|
60
|
+
put(path, ...handlers) {
|
|
61
|
+
return this.addRoute({ method: "put", path, handlers, isFinal: true });
|
|
62
|
+
}
|
|
63
|
+
delete(path, ...handlers) {
|
|
64
|
+
return this.addRoute({ method: "delete", path, handlers, isFinal: true });
|
|
65
|
+
}
|
|
66
|
+
patch(path, ...handlers) {
|
|
67
|
+
return this.addRoute({ method: "patch", path, handlers, isFinal: true });
|
|
68
|
+
}
|
|
69
|
+
head(path, ...handlers) {
|
|
70
|
+
return this.addRoute({ method: "head", path, handlers, isFinal: true });
|
|
71
|
+
}
|
|
72
|
+
options(path, ...handlers) {
|
|
73
|
+
return this.addRoute({ method: "options", path, handlers, isFinal: true });
|
|
74
|
+
}
|
|
75
|
+
statics(path, options) {
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
multer(options) {
|
|
79
|
+
const m = require("multer")(options);
|
|
80
|
+
const makePromise = (multer, name) => {
|
|
81
|
+
// istanbul ignore next
|
|
82
|
+
if (!multer[name])
|
|
83
|
+
return;
|
|
84
|
+
const fn = multer[name];
|
|
85
|
+
multer[name] = function apply(...args) {
|
|
86
|
+
const middleware = Reflect.apply(fn, this, args);
|
|
87
|
+
return (req, res) => promisify(middleware)(req, res);
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
makePromise(m, "any");
|
|
91
|
+
makePromise(m, "array");
|
|
92
|
+
makePromise(m, "fields");
|
|
93
|
+
makePromise(m, "none");
|
|
94
|
+
makePromise(m, "single");
|
|
95
|
+
return m;
|
|
96
|
+
}
|
|
97
|
+
mapHandlers(handlers, options = {}) {
|
|
98
|
+
return handlers.reduce((list, handler, index) => {
|
|
99
|
+
if (typeof handler === "string") {
|
|
100
|
+
return list.concat(handler);
|
|
101
|
+
}
|
|
102
|
+
if (handler instanceof PlatformRouter_1) {
|
|
103
|
+
return list.concat(handler.callback());
|
|
104
|
+
}
|
|
105
|
+
return list.concat(this.platformHandler.createHandler(handler, {
|
|
106
|
+
...options,
|
|
107
|
+
isFinal: options.isFinal ? index === handlers.length - 1 : false
|
|
108
|
+
}));
|
|
109
|
+
}, []);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
__decorate([
|
|
113
|
+
Inject(),
|
|
114
|
+
__metadata("design:type", InjectorService)
|
|
115
|
+
], PlatformRouter.prototype, "injector", void 0);
|
|
116
|
+
PlatformRouter = PlatformRouter_1 = __decorate([
|
|
117
|
+
Injectable({
|
|
118
|
+
scope: ProviderScope.INSTANCE
|
|
119
|
+
}),
|
|
120
|
+
__metadata("design:paramtypes", [PlatformHandler])
|
|
121
|
+
], PlatformRouter);
|
|
122
|
+
export { PlatformRouter };
|
|
123
|
+
//# sourceMappingURL=PlatformRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformRouter.js","sourceRoot":"","sources":["../../../src/services/PlatformRouter.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAY,aAAa,EAAC,MAAM,UAAU,CAAC;AACtF,OAAO,EAAC,S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,CAAC,CAAC;QACzB,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACvB,WAAW,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QAEzB,OAAO,CAAC,CAAC;IACX,CAAC;IAES,WAAW,CAAC,QAAe,EAAE,UAAwC,EAAE;QAC/E,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;YAC9C,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;gBAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;aAC7B;YAED,IAAI,OAAO,YAAY,gBAAc,EAAE;gBACrC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;aACxC;YAED,OAAO,IAAI,CAAC,MAAM,CAChB,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,OAAO,EAAE;gBAC1C,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK;aACjE,CAAC,CACH,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AA7HC;IADC,MAAM,EAAE;8BACC,eAAe;gDAAC;AANf,cAAc;IAH1B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,QAAQ;KAC9B,CAAC;qCASuC,eAAe;GAR3C,cAAc,CAmI1B;SAnIY,cAAc","sourcesContent":["import {Inject, Injectable, InjectorService, PathType, ProviderScope} from \"@tsed/di\";\nimport {promisify} from \"util\";\nimport {PlatformMulter, PlatformMulterSettings, PlatformStaticsOptions} from \"../config\";\nimport {PlatformRouteOptions, PlatformRouteWithoutHandlers} from \"../interfaces\";\nimport {createFakeRawDriver} from \"./FakeRawDriver\";\nimport {PlatformHandler} from \"./PlatformHandler\";\n\n/**\n * @ignore\n */\nexport const PLATFORM_ROUTER_OPTIONS = Symbol.for(\"PlatformRouterOptions\");\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Router {}\n }\n}\n\n/**\n * Platform Router abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.INSTANCE\n})\nexport class PlatformRouter<Router = TsED.Router> {\n rawRouter: Router;\n raw: any;\n isBuilt: boolean = false;\n\n @Inject()\n injector: InjectorService;\n\n constructor(protected platformHandler: PlatformHandler) {\n this.rawRouter = this.raw = PlatformRouter.createRawRouter();\n }\n\n /**\n * Create a new instance of PlatformRouter\n * @param injector\n * @param routerOptions\n */\n static create(injector: InjectorService, routerOptions: any = {}) {\n const locals = new Map();\n locals.set(PLATFORM_ROUTER_OPTIONS, routerOptions);\n\n return injector.invoke<PlatformRouter>(PlatformRouter, locals);\n }\n\n protected static createRawRouter(): any {\n return createFakeRawDriver();\n }\n\n callback(): any {\n return this.raw;\n }\n\n getRouter(): Router {\n return this.rawRouter;\n }\n\n use(...handlers: any[]) {\n // @ts-ignore\n this.getRouter().use(...this.mapHandlers(handlers));\n\n return this;\n }\n\n addRoute(options: Partial<PlatformRouteOptions>) {\n const {method, path, handlers, ...opts} = options;\n\n // @ts-ignore\n this.getRouter()[method](path, ...this.mapHandlers(handlers, {method, path, ...opts}));\n\n return this;\n }\n\n all(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"all\", path, handlers, isFinal: true});\n }\n\n get(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"get\", path, handlers, isFinal: true});\n }\n\n post(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"post\", path, handlers, isFinal: true});\n }\n\n put(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"put\", path, handlers, isFinal: true});\n }\n\n delete(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"delete\", path, handlers, isFinal: true});\n }\n\n patch(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"patch\", path, handlers, isFinal: true});\n }\n\n head(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"head\", path, handlers, isFinal: true});\n }\n\n options(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"options\", path, handlers, isFinal: true});\n }\n\n statics(path: string, options: PlatformStaticsOptions): this {\n return this;\n }\n\n multer(options: PlatformMulterSettings): PlatformMulter {\n const m = require(\"multer\")(options);\n\n const makePromise = (multer: any, name: string) => {\n // istanbul ignore next\n if (!multer[name]) return;\n\n const fn = multer[name];\n\n multer[name] = function apply(...args: any[]) {\n const middleware = Reflect.apply(fn, this, args);\n\n return (req: any, res: any) => promisify(middleware)(req, res);\n };\n };\n\n makePromise(m, \"any\");\n makePromise(m, \"array\");\n makePromise(m, \"fields\");\n makePromise(m, \"none\");\n makePromise(m, \"single\");\n\n return m;\n }\n\n protected mapHandlers(handlers: any[], options: PlatformRouteWithoutHandlers = {}): any[] {\n return handlers.reduce((list, handler, index) => {\n if (typeof handler === \"string\") {\n return list.concat(handler);\n }\n\n if (handler instanceof PlatformRouter) {\n return list.concat(handler.callback());\n }\n\n return list.concat(\n this.platformHandler.createHandler(handler, {\n ...options,\n isFinal: options.isFinal ? index === handlers.length - 1 : false\n })\n );\n }, []);\n }\n}\n"]}
|