@tsed/common 7.0.0-alpha.1 → 7.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/builder/PlatformBuilder.js +286 -0
- package/lib/cjs/builder/PlatformBuilder.js.map +1 -0
- package/lib/cjs/builder/PlatformControllerBuilder.js +82 -0
- package/lib/cjs/builder/PlatformControllerBuilder.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/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/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 +6 -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/exports.js +31 -0
- package/lib/cjs/exports.js.map +1 -0
- package/lib/cjs/index.js +70 -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/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/middlewares/PlatformAcceptMimesMiddleware.js +37 -0
- package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
- package/lib/cjs/middlewares/PlatformMulterMiddleware.js +67 -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/package.json +3 -0
- package/lib/cjs/services/FakeAdapter.js +55 -0
- package/lib/cjs/services/FakeAdapter.js.map +1 -0
- package/lib/cjs/services/Platform.js +128 -0
- package/lib/cjs/services/Platform.js.map +1 -0
- package/lib/cjs/services/PlatformAdapter.js +14 -0
- package/lib/cjs/services/PlatformAdapter.js.map +1 -0
- package/lib/cjs/services/PlatformApplication.js +32 -0
- package/lib/cjs/services/PlatformApplication.js.map +1 -0
- package/lib/cjs/services/PlatformHandler.js +235 -0
- package/lib/cjs/services/PlatformHandler.js.map +1 -0
- package/lib/cjs/services/PlatformMiddlewaresChain.js +75 -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 +108 -0
- package/lib/cjs/services/PlatformRouter.js.map +1 -0
- package/lib/cjs/services/PlatformTest.js +167 -0
- package/lib/cjs/services/PlatformTest.js.map +1 -0
- package/lib/cjs/utils/__mock__/Test1.js +8 -0
- package/lib/cjs/utils/__mock__/Test1.js.map +1 -0
- package/lib/cjs/utils/__mock__/Test2.js +8 -0
- package/lib/cjs/utils/__mock__/Test2.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 +29 -0
- package/lib/cjs/utils/createHttpServer.js.map +1 -0
- package/lib/cjs/utils/createHttpsServer.js +29 -0
- package/lib/cjs/utils/createHttpsServer.js.map +1 -0
- package/lib/cjs/utils/createInjector.js +46 -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/importProviders.js +29 -0
- package/lib/cjs/utils/importProviders.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 +282 -0
- package/lib/esm/builder/PlatformBuilder.js.map +1 -0
- package/lib/esm/builder/PlatformControllerBuilder.js +76 -0
- package/lib/esm/builder/PlatformControllerBuilder.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/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/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 +2 -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/exports.js +13 -0
- package/lib/esm/exports.js.map +1 -0
- package/lib/esm/index.js +67 -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/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/middlewares/PlatformAcceptMimesMiddleware.js +34 -0
- package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -0
- package/lib/esm/middlewares/PlatformMulterMiddleware.js +63 -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/package.json +3 -0
- package/lib/esm/services/FakeAdapter.js +51 -0
- package/lib/esm/services/FakeAdapter.js.map +1 -0
- package/lib/esm/services/Platform.js +125 -0
- package/lib/esm/services/Platform.js.map +1 -0
- package/lib/esm/services/PlatformAdapter.js +10 -0
- package/lib/esm/services/PlatformAdapter.js.map +1 -0
- package/lib/esm/services/PlatformApplication.js +29 -0
- package/lib/esm/services/PlatformApplication.js.map +1 -0
- package/lib/esm/services/PlatformHandler.js +232 -0
- package/lib/esm/services/PlatformHandler.js.map +1 -0
- package/lib/esm/services/PlatformMiddlewaresChain.js +72 -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 +105 -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/utils/__mock__/Test1.js +4 -0
- package/lib/esm/utils/__mock__/Test1.js.map +1 -0
- package/lib/esm/utils/__mock__/Test2.js +4 -0
- package/lib/esm/utils/__mock__/Test2.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 +24 -0
- package/lib/esm/utils/createHttpServer.js.map +1 -0
- package/lib/esm/utils/createHttpsServer.js +24 -0
- package/lib/esm/utils/createHttpsServer.js.map +1 -0
- package/lib/esm/utils/createInjector.js +42 -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/importProviders.js +25 -0
- package/lib/esm/utils/importProviders.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 +28 -32
- package/lib/types/builder/PlatformControllerBuilder.d.ts +18 -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 -16
- package/lib/types/config/interfaces/PlatformMulterSettings.d.ts +14 -0
- package/lib/{config → types/config}/interfaces/PlatformStaticsSettings.d.ts +1 -0
- package/lib/{config → types/config}/services/PlatformConfiguration.d.ts +15 -12
- package/lib/{constants → types/constants}/routerOptions.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/types/domain/EndpointMetadata.d.ts +1 -0
- package/lib/{domain → types/domain}/HandlerMetadata.d.ts +2 -2
- package/lib/{domain → types/domain}/PlatformContext.d.ts +2 -2
- package/lib/types/domain/PlatformRouteDetails.d.ts +22 -0
- package/lib/types/exports.d.ts +12 -0
- package/lib/types/index.d.ts +66 -0
- 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}/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/{middlewares → types/middlewares}/PlatformAcceptMimesMiddleware.d.ts +0 -0
- package/lib/{middlewares → types/middlewares}/PlatformMulterMiddleware.d.ts +8 -3
- package/lib/{middlewares/data → types/middlewares/__mock__}/FakeCtrl.d.ts +0 -0
- package/lib/types/middlewares/bindEndpointMiddleware.d.ts +6 -0
- package/lib/types/services/FakeAdapter.d.ts +30 -0
- package/lib/{services → types/services}/Platform.d.ts +22 -7
- package/lib/types/services/PlatformAdapter.d.ts +47 -0
- package/lib/{services → types/services}/PlatformApplication.d.ts +3 -3
- package/lib/{services → types/services}/PlatformHandler.d.ts +4 -9
- package/lib/types/services/PlatformMiddlewaresChain.d.ts +10 -0
- package/lib/{services → types/services}/PlatformRequest.d.ts +2 -1
- package/lib/{services → types/services}/PlatformResponse.d.ts +10 -10
- package/lib/{services → types/services}/PlatformRouter.d.ts +13 -9
- package/lib/{services → types/services}/PlatformTest.d.ts +6 -5
- package/lib/types/utils/__mock__/Test1.d.ts +3 -0
- package/lib/types/utils/__mock__/Test2.d.ts +3 -0
- package/lib/{utils → types/utils}/createContext.d.ts +0 -0
- package/lib/{utils → types/utils}/createHandlerMetadata.d.ts +1 -1
- package/lib/types/utils/createHttpServer.d.ts +4 -0
- package/lib/types/utils/createHttpsServer.d.ts +5 -0
- package/lib/types/utils/createInjector.d.ts +9 -0
- package/lib/types/utils/getConfiguration.d.ts +2 -0
- package/lib/types/utils/getStaticsOptions.d.ts +5 -0
- package/lib/types/utils/importProviders.d.ts +10 -0
- 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 +47 -30
- package/readme.md +50 -57
- package/tsconfig.compile.esm.json +13 -0
- package/lib/PlatformModule.d.ts +0 -15
- package/lib/builder/PlatformControllerBuilder.d.ts +0 -19
- package/lib/config/index.d.ts +0 -3
- package/lib/config/interfaces/PlatformMulterSettings.d.ts +0 -138
- package/lib/config/interfaces/index.d.ts +0 -82
- package/lib/decorators/class/controller.d.ts +0 -43
- package/lib/decorators/httpServer.d.ts +0 -27
- package/lib/decorators/httpsServer.d.ts +0 -27
- package/lib/decorators/index.d.ts +0 -14
- package/lib/decorators/method/acceptMime.d.ts +0 -19
- package/lib/decorators/method/endpointFn.d.ts +0 -8
- package/lib/decorators/method/location.d.ts +0 -1
- package/lib/decorators/method/redirect.d.ts +0 -1
- package/lib/decorators/method/route.d.ts +0 -128
- package/lib/decorators/multer/index.d.ts +0 -3
- package/lib/domain/ControllerProvider.d.ts +0 -54
- package/lib/domain/EndpointMetadata.d.ts +0 -89
- package/lib/domain/PlatformRouteDetails.d.ts +0 -29
- package/lib/domain/index.d.ts +0 -6
- package/lib/index.d.ts +0 -21
- package/lib/index.js +0 -3990
- package/lib/index.js.map +0 -1
- package/lib/index.modern.js +0 -3870
- package/lib/index.modern.js.map +0 -1
- package/lib/interfaces/PathType.d.ts +0 -1
- package/lib/interfaces/PlatformRouterMethods.d.ts +0 -10
- package/lib/interfaces/index.d.ts +0 -18
- package/lib/middlewares/PlatformLogMiddleware.d.ts +0 -44
- package/lib/middlewares/bindEndpointMiddleware.d.ts +0 -5
- package/lib/middlewares/index.d.ts +0 -4
- package/lib/registries/ControllerRegistry.d.ts +0 -1
- package/lib/services/ConverterService.d.ts +0 -27
- package/lib/services/FakeRawDriver.d.ts +0 -15
- package/lib/services/index.d.ts +0 -8
- 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/index.d.ts +0 -8
- package/lib/utils/listenServer.d.ts +0 -10
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Platform = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const di_1 = require("@tsed/di");
|
|
6
|
+
const schema_1 = require("@tsed/schema");
|
|
7
|
+
const PlatformControllerBuilder_1 = require("../builder/PlatformControllerBuilder");
|
|
8
|
+
const PlatformRouteDetails_1 = require("../domain/PlatformRouteDetails");
|
|
9
|
+
const PlatformApplication_1 = require("./PlatformApplication");
|
|
10
|
+
const PlatformMiddlewaresChain_1 = require("./PlatformMiddlewaresChain");
|
|
11
|
+
/**
|
|
12
|
+
* `Platform` is used to provide all routes collected by annotation `@Controller`.
|
|
13
|
+
*
|
|
14
|
+
* @platform
|
|
15
|
+
*/
|
|
16
|
+
let Platform = class Platform {
|
|
17
|
+
constructor(injector, platformApplication) {
|
|
18
|
+
this.injector = injector;
|
|
19
|
+
this.platformApplication = platformApplication;
|
|
20
|
+
this._routes = [];
|
|
21
|
+
this._controllers = [];
|
|
22
|
+
this.createRouters();
|
|
23
|
+
}
|
|
24
|
+
get app() {
|
|
25
|
+
return this.platformApplication;
|
|
26
|
+
}
|
|
27
|
+
get routes() {
|
|
28
|
+
return this._routes;
|
|
29
|
+
}
|
|
30
|
+
addRoutes(routes) {
|
|
31
|
+
routes.forEach((routeSettings) => {
|
|
32
|
+
this.addRoute(routeSettings.route, routeSettings.token);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
addRoute(basePath, token) {
|
|
36
|
+
const { injector } = this;
|
|
37
|
+
const provider = injector.getProvider(token);
|
|
38
|
+
if (!provider || provider.hasParent()) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this._controllers.push(...this.getAllControllers(basePath, token));
|
|
42
|
+
const ctrlPath = (0, schema_1.concatPath)(basePath, schema_1.JsonEntityStore.from(provider.token).path);
|
|
43
|
+
this.app.use(ctrlPath, ...[].concat((0, PlatformControllerBuilder_1.getRouter)(injector, provider).callback()));
|
|
44
|
+
this._routes = (0, schema_1.getOperationsRoutes)(provider.token, {
|
|
45
|
+
withChildren: true,
|
|
46
|
+
basePath
|
|
47
|
+
}).reduce((routes, operationRoute) => {
|
|
48
|
+
if (injector.hasProvider(token)) {
|
|
49
|
+
const provider = injector.getProvider(operationRoute.token);
|
|
50
|
+
const route = new PlatformRouteDetails_1.PlatformRouteDetails({
|
|
51
|
+
...operationRoute,
|
|
52
|
+
provider
|
|
53
|
+
});
|
|
54
|
+
routes = routes.concat(route);
|
|
55
|
+
}
|
|
56
|
+
return routes;
|
|
57
|
+
}, this._routes);
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get all routes built by TsExpressDecorators and mounted on Express application.
|
|
62
|
+
* @returns {PlatformRouteDetails[]}
|
|
63
|
+
*/
|
|
64
|
+
getRoutes() {
|
|
65
|
+
return this._routes;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get all controllers mounted on the application.
|
|
69
|
+
* @returns {RouteController[]}
|
|
70
|
+
*/
|
|
71
|
+
getMountedControllers() {
|
|
72
|
+
return this._controllers;
|
|
73
|
+
}
|
|
74
|
+
$onInit() {
|
|
75
|
+
this.buildControllers();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create routers from the collected controllers.
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
createRouters() {
|
|
82
|
+
const { injector } = this;
|
|
83
|
+
injector.getProviders(di_1.ProviderType.CONTROLLER).map((provider) => {
|
|
84
|
+
(0, PlatformControllerBuilder_1.createRouter)(injector, provider);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get all router controllers from the controller token.
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
getAllControllers(basePath, token) {
|
|
92
|
+
const store = token.isStore ? token : (0, schema_1.getJsonEntityStore)(token);
|
|
93
|
+
const ctrlPath = (0, schema_1.concatPath)(basePath, schema_1.JsonEntityStore.from(token).path);
|
|
94
|
+
const children = store.get("childrenControllers", []);
|
|
95
|
+
return children
|
|
96
|
+
.reduce((controllers, token) => {
|
|
97
|
+
const childBasePath = (0, schema_1.concatPath)(basePath, store.path);
|
|
98
|
+
return controllers.concat(this.getAllControllers(childBasePath, token));
|
|
99
|
+
}, [])
|
|
100
|
+
.concat([
|
|
101
|
+
{
|
|
102
|
+
route: ctrlPath,
|
|
103
|
+
provider: this.injector.getProvider(token)
|
|
104
|
+
}
|
|
105
|
+
]);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create controllers from DI
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
buildControllers() {
|
|
112
|
+
const { injector } = this;
|
|
113
|
+
injector.getProviders(di_1.ProviderType.CONTROLLER).map((provider) => {
|
|
114
|
+
if (!provider.hasParent()) {
|
|
115
|
+
return (0, PlatformControllerBuilder_1.buildRouter)(injector, provider);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
Platform = tslib_1.__decorate([
|
|
121
|
+
(0, di_1.Injectable)({
|
|
122
|
+
scope: di_1.ProviderScope.SINGLETON,
|
|
123
|
+
imports: [PlatformMiddlewaresChain_1.PlatformMiddlewaresChain]
|
|
124
|
+
}),
|
|
125
|
+
tslib_1.__metadata("design:paramtypes", [di_1.InjectorService, PlatformApplication_1.PlatformApplication])
|
|
126
|
+
], Platform);
|
|
127
|
+
exports.Platform = Platform;
|
|
128
|
+
//# sourceMappingURL=Platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Platform.js","sourceRoot":"","sources":["../../../src/services/Platform.ts"],"names":[],"mappings":";;;;AACA,iCAAiG;AACjG,yCAAoH;AACpH,oFAA0F;AAE1F,yEAAoE;AAEpE,+DAA0D;AAC1D,yEAAoE;AAEpE;;;;GAIG;AAKH,IAAa,QAAQ,GAArB,MAAa,QAAQ;IAInB,YAAqB,QAAyB,EAAW,mBAAwC;QAA5E,aAAQ,GAAR,QAAQ,CAAiB;QAAW,wBAAmB,GAAnB,mBAAmB,CAAqB;QAHzF,YAAO,GAA2B,EAAE,CAAC;QACrC,iBAAY,GAAsB,EAAE,CAAC;QAG3C,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEM,SAAS,CAAC,MAAe;QAC9B,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE;YAC/B,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,QAAQ,CAAC,QAAgB,EAAE,KAAoB;QACpD,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QACxB,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAuB,CAAC;QAEnE,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,SAAS,EAAE,EAAE;YACrC,OAAO;SACR;QAED,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ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AAA,uCAAW,EAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;aACxC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA3HY,QAAQ;IAJpB,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;QAC9B,OAAO,EAAE,CAAC,mDAAwB,CAAC;KACpC,CAAC;6CAK+B,oBAAe,EAAgC,yCAAmB;GAJtF,QAAQ,CA2HpB;AA3HY,4BAAQ","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {Injectable, InjectorService, ProviderScope, ProviderType, TokenProvider} from \"@tsed/di\";\nimport {concatPath, EndpointMetadata, getJsonEntityStore, getOperationsRoutes, JsonEntityStore} from \"@tsed/schema\";\nimport {buildRouter, createRouter, getRouter} from \"../builder/PlatformControllerBuilder\";\nimport {ControllerProvider} from \"../domain/ControllerProvider\";\nimport {PlatformRouteDetails} from \"../domain/PlatformRouteDetails\";\nimport {Route, RouteController} from \"../interfaces/Route\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {PlatformMiddlewaresChain} from \"./PlatformMiddlewaresChain\";\n\n/**\n * `Platform` is used to provide all routes collected by annotation `@Controller`.\n *\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON,\n imports: [PlatformMiddlewaresChain]\n})\nexport class Platform {\n private _routes: PlatformRouteDetails[] = [];\n private _controllers: RouteController[] = [];\n\n constructor(readonly injector: InjectorService, readonly platformApplication: PlatformApplication) {\n this.createRouters();\n }\n\n get app() {\n return this.platformApplication;\n }\n\n get routes(): PlatformRouteDetails[] {\n return this._routes;\n }\n\n public addRoutes(routes: Route[]) {\n routes.forEach((routeSettings) => {\n this.addRoute(routeSettings.route, routeSettings.token);\n });\n }\n\n public addRoute(basePath: string, token: TokenProvider) {\n const {injector} = this;\n const provider = injector.getProvider(token) as ControllerProvider;\n\n if (!provider || provider.hasParent()) {\n return;\n }\n\n this._controllers.push(...this.getAllControllers(basePath, token));\n\n const ctrlPath = concatPath(basePath, JsonEntityStore.from(provider.token).path);\n\n this.app.use(ctrlPath, ...[].concat(getRouter(injector, provider).callback()));\n\n this._routes = getOperationsRoutes<EndpointMetadata>(provider.token, {\n withChildren: true,\n basePath\n }).reduce((routes, operationRoute) => {\n if (injector.hasProvider(token)) {\n const provider = injector.getProvider(operationRoute.token) as ControllerProvider;\n const route = new PlatformRouteDetails({\n ...operationRoute,\n provider\n });\n\n routes = routes.concat(route);\n }\n\n return routes;\n }, this._routes);\n\n return this;\n }\n\n /**\n * Get all routes built by TsExpressDecorators and mounted on Express application.\n * @returns {PlatformRouteDetails[]}\n */\n public getRoutes(): PlatformRouteDetails[] {\n return this._routes;\n }\n\n /**\n * Get all controllers mounted on the application.\n * @returns {RouteController[]}\n */\n public getMountedControllers(): RouteController[] {\n return this._controllers;\n }\n\n protected $onInit() {\n this.buildControllers();\n }\n\n /**\n * Create routers from the collected controllers.\n * @private\n */\n private createRouters() {\n const {injector} = this;\n\n injector.getProviders(ProviderType.CONTROLLER).map((provider: ControllerProvider) => {\n createRouter(injector, provider);\n });\n }\n\n /**\n * Get all router controllers from the controller token.\n * @private\n */\n private getAllControllers(basePath: string, token: Type<any> | any): RouteController[] {\n const store: JsonEntityStore = token.isStore ? token : getJsonEntityStore(token);\n const ctrlPath = concatPath(basePath, JsonEntityStore.from(token).path);\n const children = store.get<Type[]>(\"childrenControllers\", []);\n\n return children\n .reduce<RouteController[]>((controllers, token) => {\n const childBasePath = concatPath(basePath, store.path);\n return controllers.concat(this.getAllControllers(childBasePath, token));\n }, [])\n .concat([\n {\n route: ctrlPath,\n provider: this.injector.getProvider(token) as ControllerProvider\n }\n ]);\n }\n\n /**\n * Create controllers from DI\n * @private\n */\n private buildControllers() {\n const {injector} = this;\n\n injector.getProviders(ProviderType.CONTROLLER).map((provider: ControllerProvider) => {\n if (!provider.hasParent()) {\n return buildRouter(injector, provider);\n }\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlatformAdapter = void 0;
|
|
4
|
+
const di_1 = require("@tsed/di");
|
|
5
|
+
const FakeAdapter_1 = require("./FakeAdapter");
|
|
6
|
+
class PlatformAdapter {
|
|
7
|
+
}
|
|
8
|
+
exports.PlatformAdapter = PlatformAdapter;
|
|
9
|
+
(0, di_1.registerProvider)({
|
|
10
|
+
provide: PlatformAdapter,
|
|
11
|
+
deps: [di_1.InjectorService],
|
|
12
|
+
useClass: FakeAdapter_1.FakeAdapter
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=PlatformAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformAdapter.js","sourceRoot":"","sources":["../../../src/services/PlatformAdapter.ts"],"names":[],"mappings":";;;AACA,iCAAyE;AAIzE,+CAA0C;AAE1C,MAAsB,eAAe;CAoCpC;AApCD,0CAoCC;AAMD,IAAA,qBAAgB,EAAC;IACf,OAAO,EAAE,eAAe;IACxB,IAAI,EAAE,CAAC,oBAAe,CAAC;IACvB,QAAQ,EAAE,yBAAW;CACtB,CAAC,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {InjectorService, ProviderOpts, registerProvider} from \"@tsed/di\";\nimport {PlatformMulter, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformStaticsOptions} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {RouterOptions} from \"express\";\nimport {FakeAdapter} from \"./FakeAdapter\";\n\nexport abstract class PlatformAdapter<App = TsED.Application, Router = TsED.Router> {\n /**\n * Load providers in top priority\n */\n providers: ProviderOpts[];\n /**\n * Called after the injector instantiation\n */\n onInit?: () => any;\n beforeLoadRoutes?: () => Promise<any>;\n afterLoadRoutes?: () => Promise<any>;\n useRouter?: () => any;\n useContext?: () => any;\n\n abstract app(): {app: App; callback(): any};\n\n abstract router(routerOptions?: Partial<RouterOptions>): {router: Router; callback(): any};\n /**\n * Return the statics middlewares\n * @param endpoint\n * @param options\n */\n abstract statics(endpoint: string, options: PlatformStaticsOptions): any;\n\n /**\n * Return the multipart middleware\n * @param options\n */\n abstract multipart(options: PlatformMulterSettings): PlatformMulter;\n\n /**\n * Return the body parser for the given\n * @param type\n * @param opts\n */\n abstract bodyParser(type: string, opts?: Record<string, any>): any;\n}\n\nexport interface PlatformBuilderSettings<App = TsED.Application, Router = TsED.Router> extends Partial<TsED.Configuration> {\n adapter?: Type<PlatformAdapter<App, Router>>;\n}\n\nregisterProvider({\n provide: PlatformAdapter,\n deps: [InjectorService],\n useClass: FakeAdapter\n});\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlatformApplication = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const di_1 = require("@tsed/di");
|
|
6
|
+
const PlatformHandler_1 = require("./PlatformHandler");
|
|
7
|
+
const PlatformRouter_1 = require("./PlatformRouter");
|
|
8
|
+
const PlatformAdapter_1 = require("./PlatformAdapter");
|
|
9
|
+
/**
|
|
10
|
+
* `PlatformApplication` is used to provide all routes collected by annotation `@Controller`.
|
|
11
|
+
*
|
|
12
|
+
* @platform
|
|
13
|
+
*/
|
|
14
|
+
let PlatformApplication = class PlatformApplication extends PlatformRouter_1.PlatformRouter {
|
|
15
|
+
constructor(platformHandler, adapter) {
|
|
16
|
+
super(platformHandler, adapter);
|
|
17
|
+
const { app, callback } = adapter.app();
|
|
18
|
+
this.rawApp = this.raw = app;
|
|
19
|
+
this.callback = callback;
|
|
20
|
+
}
|
|
21
|
+
getApp() {
|
|
22
|
+
return this.raw;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
PlatformApplication = tslib_1.__decorate([
|
|
26
|
+
(0, di_1.Injectable)({
|
|
27
|
+
scope: di_1.ProviderScope.SINGLETON
|
|
28
|
+
}),
|
|
29
|
+
tslib_1.__metadata("design:paramtypes", [PlatformHandler_1.PlatformHandler, PlatformAdapter_1.PlatformAdapter])
|
|
30
|
+
], PlatformApplication);
|
|
31
|
+
exports.PlatformApplication = PlatformApplication;
|
|
32
|
+
//# sourceMappingURL=PlatformApplication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformApplication.ts"],"names":[],"mappings":";;;;AAAA,iCAAmD;AACnD,uDAAkD;AAClD,qDAAgD;AAChD,uDAAkD;AASlD;;;;GAIG;AAIH,IAAa,mBAAmB,GAAhC,MAAa,mBAAkE,SAAQ,+BAA2B;IAKhH,YAAY,eAAgC,EAAE,OAAqC;QACjF,KAAK,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAChC,MAAM,EAAC,GAAG,EAAE,QAAQ,EAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAEtC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF,CAAA;AAhBY,mBAAmB;IAH/B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;KAC/B,CAAC;6CAM6B,iCAAe,EAAW,iCAAe;GAL3D,mBAAmB,CAgB/B;AAhBY,kDAAmB","sourcesContent":["import {Injectable, ProviderScope} from \"@tsed/di\";\nimport {PlatformHandler} from \"./PlatformHandler\";\nimport {PlatformRouter} from \"./PlatformRouter\";\nimport {PlatformAdapter} from \"./PlatformAdapter\";\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Application {}\n }\n}\n\n/**\n * `PlatformApplication` is used to provide all routes collected by annotation `@Controller`.\n *\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON\n})\nexport class PlatformApplication<App = TsED.Application, Router = TsED.Router> extends PlatformRouter<App, Router> {\n raw: App;\n rawApp: App;\n declare rawRouter: Router;\n\n constructor(platformHandler: PlatformHandler, adapter: PlatformAdapter<App, Router>) {\n super(platformHandler, adapter);\n const {app, callback} = adapter.app();\n\n this.rawApp = this.raw = app;\n this.callback = callback;\n }\n\n getApp(): App {\n return this.raw;\n }\n}\n"]}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlatformHandler = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@tsed/core");
|
|
6
|
+
const di_1 = require("@tsed/di");
|
|
7
|
+
const logger_1 = require("@tsed/logger");
|
|
8
|
+
const platform_params_1 = require("@tsed/platform-params");
|
|
9
|
+
const platform_response_filter_1 = require("@tsed/platform-response-filter");
|
|
10
|
+
const AnyToPromiseWithCtx_1 = require("../domain/AnyToPromiseWithCtx");
|
|
11
|
+
const HandlerMetadata_1 = require("../domain/HandlerMetadata");
|
|
12
|
+
const HandlerType_1 = require("../interfaces/HandlerType");
|
|
13
|
+
const createHandlerMetadata_1 = require("../utils/createHandlerMetadata");
|
|
14
|
+
const setResponseHeaders_1 = require("../utils/setResponseHeaders");
|
|
15
|
+
/**
|
|
16
|
+
* Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).
|
|
17
|
+
* @platform
|
|
18
|
+
*/
|
|
19
|
+
let PlatformHandler = class PlatformHandler {
|
|
20
|
+
constructor(injector, params) {
|
|
21
|
+
this.injector = injector;
|
|
22
|
+
this.params = params;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a native middleware based on the given metadata and return an instance of AnyToPromiseWithCtx
|
|
26
|
+
* @param input
|
|
27
|
+
* @param options
|
|
28
|
+
*/
|
|
29
|
+
createHandler(input, options = {}) {
|
|
30
|
+
return this.createRawHandler((0, createHandlerMetadata_1.createHandlerMetadata)(this.injector, input, options));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create injectable handler from the given provider
|
|
34
|
+
* @param provider
|
|
35
|
+
* @param propertyKey
|
|
36
|
+
*/
|
|
37
|
+
createCustomHandler(provider, propertyKey) {
|
|
38
|
+
const handler = this.compileHandler(new HandlerMetadata_1.HandlerMetadata({
|
|
39
|
+
token: provider.provide,
|
|
40
|
+
target: provider.useClass,
|
|
41
|
+
type: HandlerType_1.HandlerType.CUSTOM,
|
|
42
|
+
scope: provider.scope,
|
|
43
|
+
propertyKey
|
|
44
|
+
}));
|
|
45
|
+
return async ($ctx, next) => handler({
|
|
46
|
+
$ctx,
|
|
47
|
+
next
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Send the response to the consumer.
|
|
52
|
+
* @param data
|
|
53
|
+
* @param ctx
|
|
54
|
+
* @protected
|
|
55
|
+
*/
|
|
56
|
+
async flush(data, ctx) {
|
|
57
|
+
const { response } = ctx;
|
|
58
|
+
if (!response.isDone()) {
|
|
59
|
+
data = await this.responseFilter.serialize(data, ctx);
|
|
60
|
+
data = await this.responseFilter.transform(data, ctx);
|
|
61
|
+
response.body(data);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
compileHandler(metadata) {
|
|
65
|
+
if (metadata.type === HandlerType_1.HandlerType.CTX_FN) {
|
|
66
|
+
return async (scope) => {
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
return this.onCtxRequest({
|
|
69
|
+
...scope,
|
|
70
|
+
handler: () => metadata.handler(scope.$ctx),
|
|
71
|
+
metadata
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const promise = this.params.compileHandler({
|
|
76
|
+
token: metadata.token,
|
|
77
|
+
propertyKey: metadata.propertyKey,
|
|
78
|
+
getCustomArgs: metadata.injectable ? undefined : this.getDefaultArgs(metadata)
|
|
79
|
+
});
|
|
80
|
+
return async (scope) => {
|
|
81
|
+
const handler = await promise;
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
return this.onRequest({
|
|
84
|
+
...scope,
|
|
85
|
+
handler,
|
|
86
|
+
metadata
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async onCtxRequest(requestOptions) {
|
|
91
|
+
await requestOptions.handler(requestOptions);
|
|
92
|
+
return this.next(requestOptions);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Call handler when a request his handle
|
|
96
|
+
* @param requestOptions
|
|
97
|
+
*/
|
|
98
|
+
async onRequest(requestOptions) {
|
|
99
|
+
const { $ctx, metadata, err, handler } = requestOptions;
|
|
100
|
+
// istanbul ignore next
|
|
101
|
+
if (!$ctx || $ctx.isDone()) {
|
|
102
|
+
logger_1.$log.error({
|
|
103
|
+
name: "HEADERS_SENT",
|
|
104
|
+
message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${metadata.toString()}`
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const resolver = new AnyToPromiseWithCtx_1.AnyToPromiseWithCtx({ $ctx, err });
|
|
109
|
+
return (0, di_1.runInContext)($ctx, async () => {
|
|
110
|
+
try {
|
|
111
|
+
const { state, data, status, headers } = await resolver.call(handler);
|
|
112
|
+
if (state === core_1.AnyToPromiseStatus.RESOLVED) {
|
|
113
|
+
if (status) {
|
|
114
|
+
$ctx.response.status(status);
|
|
115
|
+
}
|
|
116
|
+
if (headers) {
|
|
117
|
+
$ctx.response.setHeaders(headers);
|
|
118
|
+
}
|
|
119
|
+
if (data !== undefined) {
|
|
120
|
+
$ctx.data = data;
|
|
121
|
+
}
|
|
122
|
+
// Can be canceled by the handler itself
|
|
123
|
+
return await this.onSuccess($ctx.data, requestOptions);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (er) {
|
|
127
|
+
return this.onError(er, requestOptions);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
async onError(er, requestOptions) {
|
|
132
|
+
const { next, $ctx, metadata } = requestOptions;
|
|
133
|
+
if ($ctx) {
|
|
134
|
+
$ctx.data = er;
|
|
135
|
+
}
|
|
136
|
+
if (!next) {
|
|
137
|
+
throw er;
|
|
138
|
+
}
|
|
139
|
+
// istanbul ignore next
|
|
140
|
+
if (!$ctx || $ctx.isDone()) {
|
|
141
|
+
logger_1.$log.warn({
|
|
142
|
+
name: "HEADERS_SENT",
|
|
143
|
+
message: `An error was caught after the headers were sent to the client. The error comes from the handler: ${metadata.toString()}`,
|
|
144
|
+
stack: er.stack,
|
|
145
|
+
origin: er,
|
|
146
|
+
request_id: $ctx === null || $ctx === void 0 ? void 0 : $ctx.id
|
|
147
|
+
});
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
return next(er);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Manage success scenario
|
|
154
|
+
* @param data
|
|
155
|
+
* @param requestOptions
|
|
156
|
+
* @protected
|
|
157
|
+
*/
|
|
158
|
+
async onSuccess(data, requestOptions) {
|
|
159
|
+
const { metadata, $ctx, next } = requestOptions;
|
|
160
|
+
// istanbul ignore next
|
|
161
|
+
if ($ctx === null || $ctx === void 0 ? void 0 : $ctx.isDone()) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// set headers each times that an endpoint is called
|
|
165
|
+
if (metadata.type === HandlerType_1.HandlerType.ENDPOINT) {
|
|
166
|
+
this.setHeaders($ctx);
|
|
167
|
+
}
|
|
168
|
+
// call returned middleware
|
|
169
|
+
if ((0, core_1.isFunction)(data) && !(0, core_1.isStream)(data)) {
|
|
170
|
+
return this.callReturnedMiddleware(data, $ctx, next);
|
|
171
|
+
}
|
|
172
|
+
if (metadata.isFinal()) {
|
|
173
|
+
return this.flush(data, $ctx);
|
|
174
|
+
}
|
|
175
|
+
return this.next(requestOptions);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Call the returned middleware by the handler.
|
|
179
|
+
* @param middleware
|
|
180
|
+
* @param ctx
|
|
181
|
+
* @param next
|
|
182
|
+
* @protected
|
|
183
|
+
*/
|
|
184
|
+
callReturnedMiddleware(middleware, ctx, next) {
|
|
185
|
+
return middleware(ctx.getRequest(), ctx.getResponse(), next);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* create Raw handler
|
|
189
|
+
* @param metadata
|
|
190
|
+
*/
|
|
191
|
+
createRawHandler(metadata) {
|
|
192
|
+
if ([HandlerType_1.HandlerType.RAW_ERR_FN, HandlerType_1.HandlerType.RAW_FN].includes(metadata.type)) {
|
|
193
|
+
return metadata.handler;
|
|
194
|
+
}
|
|
195
|
+
const handler = this.compileHandler(metadata);
|
|
196
|
+
return async (request, response, next) => {
|
|
197
|
+
return handler({
|
|
198
|
+
next,
|
|
199
|
+
$ctx: request.$ctx
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Set response headers
|
|
205
|
+
* @param ctx
|
|
206
|
+
* @protected
|
|
207
|
+
*/
|
|
208
|
+
setHeaders(ctx) {
|
|
209
|
+
return (0, setResponseHeaders_1.setResponseHeaders)(ctx);
|
|
210
|
+
}
|
|
211
|
+
next(requestOptions) {
|
|
212
|
+
const { $ctx, next } = requestOptions;
|
|
213
|
+
return !$ctx.response.isDone() && next && next();
|
|
214
|
+
}
|
|
215
|
+
getDefaultArgs(metadata) {
|
|
216
|
+
return async (scope) => [
|
|
217
|
+
metadata.hasErrorParam && scope.err,
|
|
218
|
+
scope.$ctx.request.request,
|
|
219
|
+
scope.$ctx.response.response,
|
|
220
|
+
metadata.hasNextFunction && scope.next
|
|
221
|
+
].filter(Boolean);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
tslib_1.__decorate([
|
|
225
|
+
(0, di_1.Inject)(),
|
|
226
|
+
tslib_1.__metadata("design:type", platform_response_filter_1.PlatformResponseFilter)
|
|
227
|
+
], PlatformHandler.prototype, "responseFilter", void 0);
|
|
228
|
+
PlatformHandler = tslib_1.__decorate([
|
|
229
|
+
(0, di_1.Injectable)({
|
|
230
|
+
scope: di_1.ProviderScope.SINGLETON
|
|
231
|
+
}),
|
|
232
|
+
tslib_1.__metadata("design:paramtypes", [di_1.InjectorService, platform_params_1.PlatformParams])
|
|
233
|
+
], PlatformHandler);
|
|
234
|
+
exports.PlatformHandler = PlatformHandler;
|
|
235
|
+
//# sourceMappingURL=PlatformHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformHandler.ts"],"names":[],"mappings":";;;;AAAA,qCAAoE;AACpE,iCAAoG;AACpG,yCAAkC;AAClC,2DAAiF;AACjF,6EAAsE;AAEtE,uEAAkE;AAClE,+DAA0D;AAE1D,2DAAsD;AAEtD,0EAAqE;AACrE,oEAA+D;AAY/D;;;GAGG;AAIH,IAAa,eAAe,GAA5B,MAAa,eAAe;IAI1B,YAAsB,QAAyB,EAAY,MAAsB;QAA3D,aAAQ,GAAR,QAAQ,CAAiB;QAAY,WAAM,GAAN,MAAM,CAAgB;IAAG,CAAC;IAErF;;;;OAIG;IACH,aAAa,CAAC,KAA+C,EAAE,UAAwC,EAAE;QACvG,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAA,6CAAqB,EAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;IACrF,CAAC;IAED;;;;OAIG;IACH,mBAAmB,CAAC,QAAkB,EAAE,WAAmB;QACzD,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CACjC,IAAI,iCAAe,CAAC;YAClB,KAAK,EAAE,QAAQ,CAAC,OAAO;YACvB,MAAM,EAAE,QAAQ,CAAC,QAAQ;YACzB,IAAI,EAAE,yBAAW,CAAC,MAAM;YACxB,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,WAAW;SACZ,CAAC,CACH,CAAC;QAEF,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E,IAAI,EAAC,GAAG,cAAc,CAAC;QAEpC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;IACnD,CAAC;IAES,cAAc,CAAC,QAAyB;QAChD,OAAO,KAAK,EAAE,KAAgC,EAAE,EAAE,CAChD;YACE,QAAQ,CAAC,aAAa,IAAI,KAAK,CAAC,GAAG;YACnC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO;YAC1B,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ;YAC5B,QAAQ,CAAC,eAAe,IAAI,KAAK,CAAC,IAAI;SACvC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;CACF,CAAA;AAlPC;IADC,IAAA,WAAM,GAAE;sCACiB,iDAAsB;uDAAC;AAFtC,eAAe;IAH3B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,SAAS;KAC/B,CAAC;6CAKgC,oBAAe,EAAoB,gCAAc;GAJtE,eAAe,CAoP3B;AApPY,0CAAe","sourcesContent":["import {AnyToPromiseStatus, isFunction, isStream} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService, Provider, ProviderScope, runInContext} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {ArgScope, HandlerWithScope, PlatformParams} from \"@tsed/platform-params\";\nimport {PlatformResponseFilter} from \"@tsed/platform-response-filter\";\nimport {EndpointMetadata} from \"@tsed/schema\";\nimport {AnyToPromiseWithCtx} from \"../domain/AnyToPromiseWithCtx\";\nimport {HandlerMetadata} from \"../domain/HandlerMetadata\";\nimport {PlatformContext} from \"../domain/PlatformContext\";\nimport {HandlerType} from \"../interfaces/HandlerType\";\nimport {PlatformRouteWithoutHandlers} from \"../interfaces/PlatformRouteOptions\";\nimport {createHandlerMetadata} from \"../utils/createHandlerMetadata\";\nimport {setResponseHeaders} from \"../utils/setResponseHeaders\";\n\nexport interface OnRequestOptions {\n $ctx: PlatformContext;\n metadata: HandlerMetadata;\n handler: HandlerWithScope;\n next?: any;\n err?: any;\n\n [key: string]: any;\n}\n\n/**\n * Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).\n * @platform\n */\n@Injectable({\n scope: ProviderScope.SINGLETON\n})\nexport class PlatformHandler {\n @Inject()\n protected responseFilter: PlatformResponseFilter;\n\n constructor(protected injector: InjectorService, protected params: PlatformParams) {}\n\n /**\n * Create a native middleware based on the given metadata and return an instance of AnyToPromiseWithCtx\n * @param input\n * @param options\n */\n createHandler(input: EndpointMetadata | HandlerMetadata | any, options: PlatformRouteWithoutHandlers = {}) {\n return this.createRawHandler(createHandlerMetadata(this.injector, input, options));\n }\n\n /**\n * Create injectable handler from the given provider\n * @param provider\n * @param propertyKey\n */\n createCustomHandler(provider: Provider, propertyKey: string) {\n const handler = this.compileHandler(\n new HandlerMetadata({\n token: provider.provide,\n target: provider.useClass,\n type: HandlerType.CUSTOM,\n scope: provider.scope,\n propertyKey\n })\n );\n\n return async ($ctx: PlatformContext, next?: any) =>\n handler({\n $ctx,\n next\n });\n }\n\n /**\n * Send the response to the consumer.\n * @param data\n * @param ctx\n * @protected\n */\n async flush(data: any, ctx: PlatformContext) {\n const {response} = ctx;\n\n if (!response.isDone()) {\n data = await this.responseFilter.serialize(data, ctx);\n data = await this.responseFilter.transform(data, ctx);\n response.body(data);\n }\n }\n\n compileHandler(metadata: HandlerMetadata) {\n if (metadata.type === HandlerType.CTX_FN) {\n return async (scope: Record<string, any>) => {\n // @ts-ignore\n return this.onCtxRequest({\n ...scope,\n handler: () => metadata.handler(scope.$ctx),\n metadata\n });\n };\n }\n\n const promise = this.params.compileHandler<PlatformContext>({\n token: metadata.token,\n propertyKey: metadata.propertyKey,\n getCustomArgs: metadata.injectable ? undefined : this.getDefaultArgs(metadata)\n });\n\n return async (scope: Record<string, any>) => {\n const handler = await promise;\n // @ts-ignore\n return this.onRequest({\n ...scope,\n handler,\n metadata\n });\n };\n }\n\n protected async onCtxRequest(requestOptions: OnRequestOptions): Promise<any> {\n await requestOptions.handler(requestOptions);\n\n return this.next(requestOptions);\n }\n\n /**\n * Call handler when a request his handle\n * @param requestOptions\n */\n protected async onRequest(requestOptions: OnRequestOptions): Promise<any> {\n const {$ctx, metadata, err, handler} = requestOptions;\n // istanbul ignore next\n if (!$ctx || $ctx.isDone()) {\n $log.error({\n name: \"HEADERS_SENT\",\n message: `An endpoint is called but the response is already send to the client. The call comes from the handler: ${metadata.toString()}`\n });\n return;\n }\n\n const resolver = new AnyToPromiseWithCtx({$ctx, err});\n\n return runInContext($ctx, async () => {\n try {\n const {state, data, status, headers} = await resolver.call(handler);\n\n if (state === AnyToPromiseStatus.RESOLVED) {\n if (status) {\n $ctx.response.status(status);\n }\n\n if (headers) {\n $ctx.response.setHeaders(headers);\n }\n\n if (data !== undefined) {\n $ctx.data = data;\n }\n\n // Can be canceled by the handler itself\n return await this.onSuccess($ctx.data, requestOptions);\n }\n } catch (er) {\n return this.onError(er, requestOptions);\n }\n });\n }\n\n protected async onError(er: Error, requestOptions: OnRequestOptions) {\n const {next, $ctx, metadata} = requestOptions;\n\n if ($ctx) {\n $ctx.data = er;\n }\n\n if (!next) {\n throw er;\n }\n\n // istanbul ignore next\n if (!$ctx || $ctx.isDone()) {\n $log.warn({\n name: \"HEADERS_SENT\",\n message: `An error was caught after the headers were sent to the client. The error comes from the handler: ${metadata.toString()}`,\n stack: er.stack,\n origin: er,\n request_id: $ctx?.id\n });\n\n return;\n }\n\n return next(er);\n }\n\n /**\n * Manage success scenario\n * @param data\n * @param requestOptions\n * @protected\n */\n protected async onSuccess(data: any, requestOptions: OnRequestOptions) {\n const {metadata, $ctx, next} = requestOptions;\n\n // istanbul ignore next\n if ($ctx?.isDone()) {\n return;\n }\n\n // set headers each times that an endpoint is called\n if (metadata.type === HandlerType.ENDPOINT) {\n this.setHeaders($ctx);\n }\n\n // call returned middleware\n if (isFunction(data) && !isStream(data)) {\n return this.callReturnedMiddleware(data, $ctx, next);\n }\n\n if (metadata.isFinal()) {\n return this.flush(data, $ctx);\n }\n\n return this.next(requestOptions);\n }\n\n /**\n * Call the returned middleware by the handler.\n * @param middleware\n * @param ctx\n * @param next\n * @protected\n */\n protected callReturnedMiddleware(middleware: any, ctx: PlatformContext, next: any) {\n return middleware(ctx.getRequest(), ctx.getResponse(), next);\n }\n\n /**\n * create Raw handler\n * @param metadata\n */\n protected createRawHandler(metadata: HandlerMetadata) {\n if ([HandlerType.RAW_ERR_FN, HandlerType.RAW_FN].includes(metadata.type)) {\n return metadata.handler;\n }\n\n const handler = this.compileHandler(metadata);\n\n return async (request: any, response: any, next: any) => {\n return handler({\n next,\n $ctx: request.$ctx\n });\n };\n }\n\n /**\n * Set response headers\n * @param ctx\n * @protected\n */\n protected setHeaders(ctx: PlatformContext) {\n return setResponseHeaders(ctx);\n }\n\n protected next(requestOptions: OnRequestOptions) {\n const {$ctx, next} = requestOptions;\n\n return !$ctx.response.isDone() && next && next();\n }\n\n protected getDefaultArgs(metadata: HandlerMetadata) {\n return async (scope: ArgScope<PlatformContext>) =>\n [\n metadata.hasErrorParam && scope.err,\n scope.$ctx.request.request,\n scope.$ctx.response.response,\n metadata.hasNextFunction && scope.next\n ].filter(Boolean);\n }\n}\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlatformMiddlewaresChain = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const di_1 = require("@tsed/di");
|
|
6
|
+
const platform_params_1 = require("@tsed/platform-params");
|
|
7
|
+
const schema_1 = require("@tsed/schema");
|
|
8
|
+
const bindEndpointMiddleware_1 = require("../middlewares/bindEndpointMiddleware");
|
|
9
|
+
const PlatformAcceptMimesMiddleware_1 = require("../middlewares/PlatformAcceptMimesMiddleware");
|
|
10
|
+
const PlatformMulterMiddleware_1 = require("../middlewares/PlatformMulterMiddleware");
|
|
11
|
+
const useCtxHandler_1 = require("../utils/useCtxHandler");
|
|
12
|
+
const PlatformAdapter_1 = require("../services/PlatformAdapter");
|
|
13
|
+
const core_1 = require("@tsed/core");
|
|
14
|
+
let PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
|
|
15
|
+
get(provider, operationRoute, parentMiddlewares = []) {
|
|
16
|
+
const { endpoint } = operationRoute;
|
|
17
|
+
const { beforeMiddlewares, middlewares: mldwrs, afterMiddlewares } = endpoint;
|
|
18
|
+
const { middlewares: { useBefore, use, useAfter } } = provider;
|
|
19
|
+
const allMiddlewares = [
|
|
20
|
+
...parentMiddlewares,
|
|
21
|
+
...useBefore,
|
|
22
|
+
...beforeMiddlewares,
|
|
23
|
+
...use,
|
|
24
|
+
...mldwrs,
|
|
25
|
+
endpoint,
|
|
26
|
+
...afterMiddlewares,
|
|
27
|
+
...useAfter
|
|
28
|
+
];
|
|
29
|
+
const { ACCEPT_MIMES, FILE, RAW_BODY, BODY } = this.getParamTypes(allMiddlewares, operationRoute);
|
|
30
|
+
return [
|
|
31
|
+
(0, useCtxHandler_1.useCtxHandler)((0, bindEndpointMiddleware_1.bindEndpointMiddleware)(endpoint)),
|
|
32
|
+
ACCEPT_MIMES && PlatformAcceptMimesMiddleware_1.PlatformAcceptMimesMiddleware,
|
|
33
|
+
FILE && PlatformMulterMiddleware_1.PlatformMulterMiddleware,
|
|
34
|
+
!FILE && RAW_BODY && this.adapter.bodyParser("raw"),
|
|
35
|
+
!FILE && !RAW_BODY && BODY && this.adapter.bodyParser("json"),
|
|
36
|
+
!FILE && !RAW_BODY && BODY && this.adapter.bodyParser("urlencoded"),
|
|
37
|
+
...allMiddlewares
|
|
38
|
+
].filter(Boolean);
|
|
39
|
+
}
|
|
40
|
+
hasAcceptMimes(operationRoute) {
|
|
41
|
+
return operationRoute.endpoint.acceptMimes.length || this.acceptMimes.length;
|
|
42
|
+
}
|
|
43
|
+
getParamTypes(middlewares, operationRoute) {
|
|
44
|
+
return middlewares.filter(core_1.isClass).reduce((paramTypes, token) => {
|
|
45
|
+
if (token !== operationRoute.endpoint) {
|
|
46
|
+
const entity = schema_1.JsonEntityStore.fromMethod(token, "use");
|
|
47
|
+
if (entity.decoratorType === "method") {
|
|
48
|
+
const { FILE, RAW_BODY, BODY } = entity.getParamTypes();
|
|
49
|
+
paramTypes.FILE = paramTypes.FILE || FILE;
|
|
50
|
+
paramTypes.RAW_BODY = paramTypes.RAW_BODY || RAW_BODY;
|
|
51
|
+
paramTypes.BODY = paramTypes.BODY || BODY;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return paramTypes;
|
|
55
|
+
}, {
|
|
56
|
+
ACCEPT_MIMES: this.hasAcceptMimes(operationRoute),
|
|
57
|
+
FILE: operationRoute.has(platform_params_1.ParamTypes.FILES),
|
|
58
|
+
RAW_BODY: operationRoute.has(platform_params_1.ParamTypes.RAW_BODY),
|
|
59
|
+
BODY: operationRoute.has(platform_params_1.ParamTypes.BODY)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
tslib_1.__decorate([
|
|
64
|
+
(0, di_1.Constant)("acceptMimes", []),
|
|
65
|
+
tslib_1.__metadata("design:type", Array)
|
|
66
|
+
], PlatformMiddlewaresChain.prototype, "acceptMimes", void 0);
|
|
67
|
+
tslib_1.__decorate([
|
|
68
|
+
(0, di_1.Inject)(),
|
|
69
|
+
tslib_1.__metadata("design:type", PlatformAdapter_1.PlatformAdapter)
|
|
70
|
+
], PlatformMiddlewaresChain.prototype, "adapter", void 0);
|
|
71
|
+
PlatformMiddlewaresChain = tslib_1.__decorate([
|
|
72
|
+
(0, di_1.Injectable)()
|
|
73
|
+
], PlatformMiddlewaresChain);
|
|
74
|
+
exports.PlatformMiddlewaresChain = PlatformMiddlewaresChain;
|
|
75
|
+
//# sourceMappingURL=PlatformMiddlewaresChain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlatformMiddlewaresChain.js","s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IAAA,aAAQ,EAAC,aAAa,EAAE,EAAE,CAAC;;6DACI;AAGhC;IADC,IAAA,WAAM,GAAE;sCACU,iCAAe;yDAAC;AALxB,wBAAwB;IADpC,IAAA,eAAU,GAAE;GACA,wBAAwB,CAmEpC;AAnEY,4DAAwB","sourcesContent":["import {Constant, Inject, Injectable} from \"@tsed/di\";\nimport {ParamTypes} from \"@tsed/platform-params\";\nimport {JsonEntityStore, JsonOperationRoute} from \"@tsed/schema\";\nimport {ControllerProvider} from \"../domain/ControllerProvider\";\nimport {bindEndpointMiddleware} from \"../middlewares/bindEndpointMiddleware\";\nimport {PlatformAcceptMimesMiddleware} from \"../middlewares/PlatformAcceptMimesMiddleware\";\nimport {PlatformMulterMiddleware} from \"../middlewares/PlatformMulterMiddleware\";\nimport {useCtxHandler} from \"../utils/useCtxHandler\";\nimport {PlatformAdapter} from \"../services/PlatformAdapter\";\nimport {isClass} from \"@tsed/core\";\n\n@Injectable()\nexport class PlatformMiddlewaresChain {\n @Constant(\"acceptMimes\", [])\n protected acceptMimes: string[];\n\n @Inject()\n protected adapter: PlatformAdapter;\n\n get(provider: ControllerProvider, operationRoute: JsonOperationRoute, parentMiddlewares: any[] = []) {\n const {endpoint} = operationRoute;\n const {beforeMiddlewares, middlewares: mldwrs, afterMiddlewares} = endpoint;\n\n const {\n middlewares: {useBefore, use, useAfter}\n } = provider;\n\n const allMiddlewares = [\n ...parentMiddlewares,\n ...useBefore,\n ...beforeMiddlewares,\n ...use,\n ...mldwrs,\n endpoint,\n ...afterMiddlewares,\n ...useAfter\n ];\n\n const {ACCEPT_MIMES, FILE, RAW_BODY, BODY} = this.getParamTypes(allMiddlewares, operationRoute);\n\n return [\n useCtxHandler(bindEndpointMiddleware(endpoint)),\n ACCEPT_MIMES && PlatformAcceptMimesMiddleware,\n FILE && PlatformMulterMiddleware,\n !FILE && RAW_BODY && this.adapter.bodyParser(\"raw\"),\n !FILE && !RAW_BODY && BODY && this.adapter.bodyParser(\"json\"),\n !FILE && !RAW_BODY && BODY && this.adapter.bodyParser(\"urlencoded\"),\n ...allMiddlewares\n ].filter(Boolean);\n }\n\n protected hasAcceptMimes(operationRoute: JsonOperationRoute) {\n return operationRoute.endpoint.acceptMimes.length || this.acceptMimes.length;\n }\n\n protected getParamTypes(middlewares: any[], operationRoute: JsonOperationRoute) {\n return middlewares.filter(isClass).reduce(\n (paramTypes, token) => {\n if (token !== operationRoute.endpoint) {\n const entity = JsonEntityStore.fromMethod(token, \"use\");\n\n if (entity.decoratorType === \"method\") {\n const {FILE, RAW_BODY, BODY} = entity.getParamTypes();\n paramTypes.FILE = paramTypes.FILE || FILE;\n paramTypes.RAW_BODY = paramTypes.RAW_BODY || RAW_BODY;\n paramTypes.BODY = paramTypes.BODY || BODY;\n }\n }\n\n return paramTypes;\n },\n {\n ACCEPT_MIMES: this.hasAcceptMimes(operationRoute),\n FILE: operationRoute.has(ParamTypes.FILES),\n RAW_BODY: operationRoute.has(ParamTypes.RAW_BODY),\n BODY: operationRoute.has(ParamTypes.BODY)\n }\n );\n }\n}\n"]}
|