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