@tsed/common 6.95.9 → 6.96.2
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 +1 -1
- package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
- package/lib/cjs/domain/AnyToPromiseWithCtx.js +1 -9
- package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -1
- package/lib/cjs/domain/PlatformContext.js +8 -1
- package/lib/cjs/domain/PlatformContext.js.map +1 -1
- package/lib/cjs/services/PlatformHandler.js +3 -5
- package/lib/cjs/services/PlatformHandler.js.map +1 -1
- package/lib/cjs/services/PlatformTest.js +1 -2
- package/lib/cjs/services/PlatformTest.js.map +1 -1
- package/lib/esm/builder/PlatformBuilder.js +1 -1
- package/lib/esm/builder/PlatformBuilder.js.map +1 -1
- package/lib/esm/domain/AnyToPromiseWithCtx.js +2 -10
- package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -1
- package/lib/esm/domain/PlatformContext.js +8 -1
- package/lib/esm/domain/PlatformContext.js.map +1 -1
- package/lib/esm/services/PlatformHandler.js +3 -5
- package/lib/esm/services/PlatformHandler.js.map +1 -1
- package/lib/esm/services/PlatformTest.js +2 -3
- package/lib/esm/services/PlatformTest.js.map +1 -1
- package/lib/types/services/PlatformTest.d.ts +2 -2
- package/package.json +15 -15
- package/lib/cjs/PlatformModule.d.ts +0 -6
- package/lib/cjs/builder/PlatformBuilder.d.ts +0 -104
- package/lib/cjs/builder/PlatformControllerBuilder.d.ts +0 -17
- package/lib/cjs/config/index.d.ts +0 -3
- package/lib/cjs/config/interfaces/ConverterSettings.d.ts +0 -6
- package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.d.ts +0 -3
- package/lib/cjs/config/interfaces/PlatformLoggerSettings.d.ts +0 -44
- package/lib/cjs/config/interfaces/PlatformMulterSettings.d.ts +0 -138
- package/lib/cjs/config/interfaces/PlatformStaticsSettings.d.ts +0 -17
- package/lib/cjs/config/interfaces/index.d.ts +0 -97
- package/lib/cjs/config/services/PlatformConfiguration.d.ts +0 -81
- package/lib/cjs/constants/routerOptions.d.ts +0 -1
- package/lib/cjs/decorators/httpServer.d.ts +0 -28
- package/lib/cjs/decorators/httpsServer.d.ts +0 -28
- package/lib/cjs/decorators/index.d.ts +0 -16
- package/lib/cjs/decorators/method/acceptMime.d.ts +0 -19
- package/lib/cjs/decorators/method/endpointFn.d.ts +0 -9
- package/lib/cjs/decorators/method/location.d.ts +0 -1
- package/lib/cjs/decorators/method/redirect.d.ts +0 -1
- package/lib/cjs/decorators/method/route.d.ts +0 -1
- package/lib/cjs/decorators/method/view.d.ts +0 -25
- package/lib/cjs/decorators/multer/index.d.ts +0 -3
- package/lib/cjs/decorators/multer/multerFileSize.d.ts +0 -27
- package/lib/cjs/decorators/multer/multerOptions.d.ts +0 -41
- package/lib/cjs/decorators/multer/multipartFile.d.ts +0 -47
- package/lib/cjs/decorators/params/endpointInfo.d.ts +0 -13
- package/lib/cjs/decorators/params/error.d.ts +0 -7
- package/lib/cjs/decorators/params/next.d.ts +0 -22
- package/lib/cjs/decorators/params/request.d.ts +0 -46
- package/lib/cjs/decorators/params/response.d.ts +0 -40
- package/lib/cjs/decorators/params/responseData.d.ts +0 -9
- package/lib/cjs/domain/AnyToPromiseWithCtx.d.ts +0 -18
- package/lib/cjs/domain/ControllerProvider.d.ts +0 -24
- package/lib/cjs/domain/EndpointMetadata.d.ts +0 -50
- package/lib/cjs/domain/HandlerMetadata.d.ts +0 -32
- package/lib/cjs/domain/PlatformContext.d.ts +0 -65
- package/lib/cjs/domain/PlatformRouteDetails.d.ts +0 -23
- package/lib/cjs/domain/PropertyMetadata.d.ts +0 -17
- package/lib/cjs/domain/index.d.ts +0 -7
- package/lib/cjs/index.d.ts +0 -22
- package/lib/cjs/interfaces/AfterInit.d.ts +0 -3
- package/lib/cjs/interfaces/AfterListen.d.ts +0 -3
- package/lib/cjs/interfaces/AfterRoutesInit.d.ts +0 -3
- package/lib/cjs/interfaces/BeforeInit.d.ts +0 -3
- package/lib/cjs/interfaces/BeforeListen.d.ts +0 -3
- package/lib/cjs/interfaces/BeforeRoutesInit.d.ts +0 -3
- package/lib/cjs/interfaces/HandlerType.d.ts +0 -12
- package/lib/cjs/interfaces/IncomingEvent.d.ts +0 -6
- package/lib/cjs/interfaces/OnReady.d.ts +0 -3
- package/lib/cjs/interfaces/OnRequest.d.ts +0 -4
- package/lib/cjs/interfaces/OnResponse.d.ts +0 -4
- package/lib/cjs/interfaces/OnRoutesInit.d.ts +0 -3
- package/lib/cjs/interfaces/PathType.d.ts +0 -1
- package/lib/cjs/interfaces/PlatformAdapter.d.ts +0 -19
- package/lib/cjs/interfaces/PlatformRouteOptions.d.ts +0 -16
- package/lib/cjs/interfaces/ResponseErrorObject.d.ts +0 -8
- package/lib/cjs/interfaces/Route.d.ts +0 -10
- package/lib/cjs/interfaces/index.d.ts +0 -17
- package/lib/cjs/middlewares/AcceptMimesMiddleware.d.ts +0 -10
- package/lib/cjs/middlewares/GlobalAcceptMimesMiddleware.d.ts +0 -9
- package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.d.ts +0 -10
- package/lib/cjs/middlewares/PlatformMulterMiddleware.d.ts +0 -19
- package/lib/cjs/middlewares/__mock__/FakeCtrl.d.ts +0 -2
- package/lib/cjs/middlewares/bindEndpointMiddleware.d.ts +0 -5
- package/lib/cjs/middlewares/index.d.ts +0 -5
- package/lib/cjs/services/FakeRawDriver.d.ts +0 -15
- package/lib/cjs/services/Platform.d.ts +0 -37
- package/lib/cjs/services/PlatformApplication.d.ts +0 -21
- package/lib/cjs/services/PlatformHandler.d.ts +0 -80
- package/lib/cjs/services/PlatformMiddlewaresChain.d.ts +0 -6
- package/lib/cjs/services/PlatformRequest.d.ts +0 -112
- package/lib/cjs/services/PlatformResponse.d.ts +0 -161
- package/lib/cjs/services/PlatformRouter.d.ts +0 -48
- package/lib/cjs/services/PlatformTest.d.ts +0 -58
- package/lib/cjs/services/index.d.ts +0 -8
- package/lib/cjs/utils/createContext.d.ts +0 -9
- package/lib/cjs/utils/createHandlerMetadata.d.ts +0 -8
- package/lib/cjs/utils/createHttpServer.d.ts +0 -4
- package/lib/cjs/utils/createHttpsServer.d.ts +0 -4
- package/lib/cjs/utils/createInjector.d.ts +0 -7
- package/lib/cjs/utils/getConfiguration.d.ts +0 -2
- package/lib/cjs/utils/getStaticsOptions.d.ts +0 -5
- package/lib/cjs/utils/index.d.ts +0 -8
- package/lib/cjs/utils/listenServer.d.ts +0 -7
- package/lib/cjs/utils/loadInjector.d.ts +0 -6
- package/lib/cjs/utils/mapReturnedResponse.d.ts +0 -4
- package/lib/cjs/utils/printRoutes.d.ts +0 -2
- package/lib/cjs/utils/setResponseHeaders.d.ts +0 -5
- package/lib/cjs/utils/useCtxHandler.d.ts +0 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformHandler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,kBAAkB,EAAE,UAAU,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpE,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAY,aAAa,EAAC,MAAM,UAAU,CAAC;AACtF,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAA6B,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACjF,OAAO,EAAC,sBAAsB,EAAC,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAC,mBAAmB,EAAC,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAEtD,OAAO,EAAC,qBAAqB,EAAC,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAY/D;;;GAGG;AAIH,IAAa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AC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;KAC/B,CAAC;qCAKgC,eAAe,EAAoB,cAAc;GAJtE,eAAe,CAkP3B;SAlPY,eAAe","sourcesContent":["import {AnyToPromiseStatus, isFunction, isStream} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService, Provider, ProviderScope} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {ArgScope, HandlerWithScope, PlatformParams} from \"@tsed/platform-params\";\nimport {PlatformResponseFilter} from \"@tsed/platform-response-filter\";\nimport {AnyToPromiseWithCtx} from \"../domain/AnyToPromiseWithCtx\";\nimport {EndpointMetadata} from \"../domain/EndpointMetadata\";\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) {\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 this.injector.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 $ctx.data = er;\n\n if (!next) {\n throw er;\n }\n\n // istanbul ignore next\n if (!$ctx?.response?.isHeadersSent || $ctx.response.isHeadersSent()) {\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 && 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 // TODO see this control is necessary\n // istanbul ignore next\n if ($ctx.request.isAborted() || $ctx.response.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"]}
|
|
1
|
+
{"version":3,"file":"PlatformHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformHandler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,kBAAkB,EAAE,UAAU,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpE,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAY,aAAa,EAAC,MAAM,UAAU,CAAC;AACtF,OAAO,EAAC,IAAI,EAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAA6B,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACjF,OAAO,EAAC,sBAAsB,EAAC,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAC,mBAAmB,EAAC,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAC,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AAEtD,OAAO,EAAC,qBAAqB,EAAC,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;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,qBAAqB,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,E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;QAE9C,OAAO,KAAK,EAAE,OAAY,EAAE,QAAa,EAAE,IAAS,EAAE,EAAE;YACtD,OAAO,OAAO,CAAC;gBACb,IAAI;gBACJ,IAAI,EAAE,OAAO,CAAC,IAAI;aACnB,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACO,UAAU,CAAC,GAAoB;QACvC,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAES,IAAI,CAAC,cAAgC;QAC7C,MAAM,EAAC,IAAI,EAAE,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;AA/OC;IADC,MAAM,EAAE;8BACiB,sBAAsB;uDAAC;AAFtC,eAAe;IAH3B,UAAU,CAAC;QACV,KAAK,EAAE,aAAa,CAAC,SAAS;KAC/B,CAAC;qCAKgC,eAAe,EAAoB,cAAc;GAJtE,eAAe,CAiP3B;SAjPY,eAAe","sourcesContent":["import {AnyToPromiseStatus, isFunction, isStream} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService, Provider, ProviderScope} from \"@tsed/di\";\nimport {$log} from \"@tsed/logger\";\nimport {ArgScope, HandlerWithScope, PlatformParams} from \"@tsed/platform-params\";\nimport {PlatformResponseFilter} from \"@tsed/platform-response-filter\";\nimport {AnyToPromiseWithCtx} from \"../domain/AnyToPromiseWithCtx\";\nimport {EndpointMetadata} from \"../domain/EndpointMetadata\";\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 this.injector.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 $ctx.data = er;\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 && 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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DITest } from "@tsed/di";
|
|
2
2
|
import { PlatformBuilder } from "../builder/PlatformBuilder";
|
|
3
3
|
import { PlatformContext } from "../domain/PlatformContext";
|
|
4
4
|
import { createInjector } from "../utils/createInjector";
|
|
@@ -10,8 +10,7 @@ import { getConfiguration } from "../utils/getConfiguration";
|
|
|
10
10
|
export class PlatformTest extends DITest {
|
|
11
11
|
static async create(settings = {}) {
|
|
12
12
|
DITest.injector = PlatformTest.createInjector(getConfiguration(settings));
|
|
13
|
-
|
|
14
|
-
await DITest.injector.load(container);
|
|
13
|
+
await DITest.createContainer(settings);
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
16
|
* Create a new injector with the right default services
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformTest.js","sourceRoot":"","sources":["../../../src/services/PlatformTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"PlatformTest.js","sourceRoot":"","sources":["../../../src/services/PlatformTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAiC,MAAM,UAAU,CAAC;AAChE,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAC,eAAe,EAAyB,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAI3D;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,MAAM;IAGtC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAA0B,EAAE;QAC9C,MAAM,CAAC,QAAQ,GAAG,YAAY,CAAC,cAAc,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC1E,MAAM,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,WAAgB,EAAE;QACtC,OAAO,cAAc,CAAC;YACpB,SAA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AI,YAAY,CAAC,cAAc,EAAE;SACnG,CAAC;QAEF,OAAO,IAAI,eAAe,CAAC;YACzB,EAAE,EAAE,IAAI;YACR,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;YAC9B,GAAG,EAAE,GAAG;YACR,GAAG,OAAO;YACV,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import {DITest, DITestOptions, InjectorService} from \"@tsed/di\";\nimport {PlatformBuilder} from \"../builder/PlatformBuilder\";\nimport {PlatformContext, PlatformContextOptions} from \"../domain/PlatformContext\";\nimport {createInjector} from \"../utils/createInjector\";\nimport {PlatformApplication} from \"./PlatformApplication\";\nimport {getConfiguration} from \"../utils/getConfiguration\";\nimport {PlatformAdapter, PlatformBuilderSettings} from \"../interfaces/PlatformAdapter\";\nimport {Type} from \"@tsed/core\";\n\n/**\n * @platform\n */\nexport class PlatformTest extends DITest {\n public static adapter: Type<PlatformAdapter>;\n\n static async create(settings: DITestOptions = {}) {\n DITest.injector = PlatformTest.createInjector(getConfiguration(settings));\n await DITest.createContainer(settings);\n }\n\n /**\n * Create a new injector with the right default services\n */\n static createInjector(settings: any = {}): InjectorService {\n return createInjector({\n providers: [],\n settings: DITest.configure({httpPort: false, httpsPort: false, ...settings})\n });\n }\n\n /**\n * Load the server silently without listening port and configure it on test profile.\n * @decorator\n * @param mod\n * @param listen\n * @param settings\n * @returns {Promise<void>}\n */\n static bootstrap(mod: any, {listen, ...settings}: Partial<PlatformBuilderSettings & {listen: boolean}> = {}): () => Promise<void> {\n return async function before(): Promise<void> {\n let instance: PlatformBuilder;\n const adapter: Type<PlatformAdapter> = settings.platform || settings.adapter || PlatformTest.adapter;\n\n /* istanbul ignore next */\n if (!adapter) {\n throw new Error(\n \"Platform adapter is not specified. Have you added at least `import @tsed/platform-express` (or equivalent) on your Server.ts ?\"\n );\n }\n\n // @ts-ignore\n settings = DITest.configure(settings);\n settings.adapter = adapter as any;\n\n instance = await PlatformBuilder.build(mod, settings).bootstrap();\n await instance.listen(!!listen);\n\n // used by inject method\n DITest.injector = instance.injector;\n };\n }\n\n /**\n * It injects services into the test function where you can alter, spy on, and manipulate them.\n *\n * The inject function has two parameters\n *\n * * an array of Service dependency injection tokens,\n * * a test function whose parameters correspond exactly to each item in the injection token array.\n *\n * @param targets\n * @param func\n */\n static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T> {\n return async (): Promise<T> => {\n if (!DITest.hasInjector()) {\n await PlatformTest.create();\n }\n\n const injector: InjectorService = DITest.injector;\n const deps = [];\n\n for (const target of targets) {\n deps.push(injector.has(target) ? injector.get(target) : await injector.invoke(target));\n }\n\n return await func(...deps);\n };\n }\n\n /**\n * Return the raw application (express or koa).\n * Use this callback with SuperTest.\n *\n * ```typescript\n * let request: SuperTest.SuperTest<SuperTest.Test>;\n * beforeEach(PlatformTest.bootstrap(Server, {\n * mount: {\n * \"/rest\": [ProductsController]\n * }\n * }));\n * beforeEach(() => {\n * request = SuperTest(PlatformTest.callback());\n * });\n * ```\n */\n static callback() {\n return DITest.injector.get<PlatformApplication>(PlatformApplication)?.callback();\n }\n\n static createRequest(options: any = {}): any {\n return {\n headers: {},\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n accepts(mime?: string | string[]) {\n return require(\"accepts\")(this).types([].concat(mime as never));\n },\n ...options\n };\n }\n\n static createResponse(options: any = {}): any {\n return {\n headers: {},\n locals: {},\n statusCode: 200,\n status(code: number) {\n this.statusCode = code;\n return this;\n },\n contentType(content: string) {\n this.set(\"content-type\", content);\n },\n contentLength(content: number) {\n this.set(\"content-length\", content);\n },\n redirect(status: number, path: string) {\n this.statusCode = status;\n this.set(\"location\", path);\n },\n location(path: string) {\n this.set(\"location\", path);\n },\n get(key: string) {\n return this.headers[key.toLowerCase()];\n },\n getHeaders() {\n return this.headers;\n },\n set(key: string, value: any) {\n this.headers[key.toLowerCase()] = value;\n return this;\n },\n send(data: any) {\n this.data = data;\n },\n json(data: any) {\n this.data = data;\n },\n ...options\n };\n }\n\n static createRequestContext(options: Partial<PlatformContextOptions & any> = {}) {\n const event = {\n request: options?.request?.request || options?.event?.request || PlatformTest.createRequest(),\n response: options?.response?.response || options?.event?.response || PlatformTest.createResponse()\n };\n\n return new PlatformContext({\n id: \"id\",\n injector: DITest.injector,\n logger: DITest.injector.logger,\n url: \"/\",\n ...options,\n event\n });\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DITest, InjectorService } from "@tsed/di";
|
|
1
|
+
import { DITest, DITestOptions, InjectorService } from "@tsed/di";
|
|
2
2
|
import { PlatformContext, PlatformContextOptions } from "../domain/PlatformContext";
|
|
3
3
|
import { PlatformAdapter, PlatformBuilderSettings } from "../interfaces/PlatformAdapter";
|
|
4
4
|
import { Type } from "@tsed/core";
|
|
@@ -7,7 +7,7 @@ import { Type } from "@tsed/core";
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class PlatformTest extends DITest {
|
|
9
9
|
static adapter: Type<PlatformAdapter>;
|
|
10
|
-
static create(settings?:
|
|
10
|
+
static create(settings?: DITestOptions): Promise<void>;
|
|
11
11
|
/**
|
|
12
12
|
* Create a new injector with the right default services
|
|
13
13
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/common",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.96.2",
|
|
4
4
|
"description": "A TypeScript Framework on top of Express",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -59,22 +59,22 @@
|
|
|
59
59
|
}
|
|
60
60
|
],
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@tsed/components-scan": "6.
|
|
63
|
-
"@tsed/core": "6.
|
|
64
|
-
"@tsed/di": "6.
|
|
65
|
-
"@tsed/exceptions": "6.
|
|
66
|
-
"@tsed/json-mapper": "6.
|
|
62
|
+
"@tsed/components-scan": "6.96.2",
|
|
63
|
+
"@tsed/core": "6.96.2",
|
|
64
|
+
"@tsed/di": "6.96.2",
|
|
65
|
+
"@tsed/exceptions": "6.96.2",
|
|
66
|
+
"@tsed/json-mapper": "6.96.2",
|
|
67
67
|
"@tsed/logger": "^6.0.0",
|
|
68
68
|
"@tsed/logger-file": "^6.0.0",
|
|
69
|
-
"@tsed/perf": "6.
|
|
70
|
-
"@tsed/platform-cache": "6.
|
|
71
|
-
"@tsed/platform-exceptions": "6.
|
|
72
|
-
"@tsed/platform-log-middleware": "6.
|
|
73
|
-
"@tsed/platform-middlewares": "6.
|
|
74
|
-
"@tsed/platform-params": "6.
|
|
75
|
-
"@tsed/platform-response-filter": "6.
|
|
76
|
-
"@tsed/platform-views": "6.
|
|
77
|
-
"@tsed/schema": "6.
|
|
69
|
+
"@tsed/perf": "6.96.2",
|
|
70
|
+
"@tsed/platform-cache": "6.96.2",
|
|
71
|
+
"@tsed/platform-exceptions": "6.96.2",
|
|
72
|
+
"@tsed/platform-log-middleware": "6.96.2",
|
|
73
|
+
"@tsed/platform-middlewares": "6.96.2",
|
|
74
|
+
"@tsed/platform-params": "6.96.2",
|
|
75
|
+
"@tsed/platform-response-filter": "6.96.2",
|
|
76
|
+
"@tsed/platform-views": "6.96.2",
|
|
77
|
+
"@tsed/schema": "6.96.2",
|
|
78
78
|
"@types/json-schema": "7.0.7",
|
|
79
79
|
"on-finished": "2.3.0",
|
|
80
80
|
"tslib": "2.2.0",
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Type } from "@tsed/core";
|
|
3
|
-
import { InjectorService, IProvider } from "@tsed/di";
|
|
4
|
-
import { Platform } from "../services/Platform";
|
|
5
|
-
import { PlatformApplication } from "../services/PlatformApplication";
|
|
6
|
-
import { IncomingMessage, ServerResponse } from "http";
|
|
7
|
-
import { PlatformAdapter, PlatformBuilderSettings } from "../interfaces/PlatformAdapter";
|
|
8
|
-
/**
|
|
9
|
-
* @platform
|
|
10
|
-
*/
|
|
11
|
-
export declare class PlatformBuilder<App = TsED.Application, Router = TsED.Router> {
|
|
12
|
-
#private;
|
|
13
|
-
static adapter: Type<PlatformAdapter>;
|
|
14
|
-
readonly name: string;
|
|
15
|
-
protected startedAt: Date;
|
|
16
|
-
protected current: Date;
|
|
17
|
-
protected constructor(adapter: Type<PlatformAdapter<App, Router>> | undefined, module: Type, settings: Partial<TsED.Configuration>);
|
|
18
|
-
get injector(): InjectorService;
|
|
19
|
-
get rootModule(): any;
|
|
20
|
-
get app(): PlatformApplication<App, Router>;
|
|
21
|
-
get platform(): Platform;
|
|
22
|
-
/**
|
|
23
|
-
* Return the settings configured by the decorator @@Configuration@@.
|
|
24
|
-
*
|
|
25
|
-
* ```typescript
|
|
26
|
-
* @Configuration({
|
|
27
|
-
* rootDir: Path.resolve(__dirname),
|
|
28
|
-
* port: 8000,
|
|
29
|
-
* httpsPort: 8080,
|
|
30
|
-
* mount: {
|
|
31
|
-
* "/rest": "${rootDir}/controllers/**\/*.js"
|
|
32
|
-
* }
|
|
33
|
-
* })
|
|
34
|
-
* export class Server {
|
|
35
|
-
* $onInit(){
|
|
36
|
-
* console.log(this.settings); // {rootDir, port, httpsPort,...}
|
|
37
|
-
* }
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* @returns {PlatformConfiguration}
|
|
42
|
-
*/
|
|
43
|
-
get settings(): TsED.Configuration & import("@tsed/di").DIConfiguration;
|
|
44
|
-
get logger(): import("@tsed/di").DILogger;
|
|
45
|
-
get disableBootstrapLog(): boolean | undefined;
|
|
46
|
-
static create<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>): PlatformBuilder<App, Router>;
|
|
47
|
-
static build<App = TsED.Application, Router = TsED.Router>(module: Type<any>, { adapter, ...settings }: PlatformBuilderSettings<App, Router>): PlatformBuilder<App, Router>;
|
|
48
|
-
/**
|
|
49
|
-
* Bootstrap a server application
|
|
50
|
-
* @param module
|
|
51
|
-
* @param settings
|
|
52
|
-
*/
|
|
53
|
-
static bootstrap<App = TsED.Application, Router = TsED.Router>(module: Type<any>, settings: PlatformBuilderSettings<App, Router>): Promise<PlatformBuilder<App, Router>>;
|
|
54
|
-
callback(): (req: IncomingMessage, res: ServerResponse) => void;
|
|
55
|
-
callback(req: IncomingMessage, res: ServerResponse): void;
|
|
56
|
-
log(...data: any[]): any;
|
|
57
|
-
/**
|
|
58
|
-
* Add classes to the components list
|
|
59
|
-
* @param classes
|
|
60
|
-
*/
|
|
61
|
-
addComponents(classes: any | any[]): this;
|
|
62
|
-
/**
|
|
63
|
-
* Add classes decorated by @@Controller@@ to components container.
|
|
64
|
-
*
|
|
65
|
-
* ### Example
|
|
66
|
-
*
|
|
67
|
-
* ```typescript
|
|
68
|
-
* @Controller('/ctrl')
|
|
69
|
-
* class MyController{
|
|
70
|
-
* }
|
|
71
|
-
*
|
|
72
|
-
* platform.addControllers('/rest', [MyController])
|
|
73
|
-
* ```
|
|
74
|
-
*
|
|
75
|
-
* ::: tip
|
|
76
|
-
* If the MyController class isn't decorated, the class will be ignored.
|
|
77
|
-
* :::
|
|
78
|
-
*
|
|
79
|
-
* @param {string} endpoint
|
|
80
|
-
* @param {any[]} controllers
|
|
81
|
-
*/
|
|
82
|
-
addControllers(endpoint: string, controllers: any | string | (any | string)[]): void;
|
|
83
|
-
runLifecycle(): Promise<this>;
|
|
84
|
-
loadInjector(): Promise<void>;
|
|
85
|
-
listen(network?: boolean): Promise<void>;
|
|
86
|
-
stop(): Promise<void>;
|
|
87
|
-
ready(): Promise<void>;
|
|
88
|
-
callHook(hook: string, ...args: any[]): Promise<void>;
|
|
89
|
-
loadStatics(hook: string): Promise<void>;
|
|
90
|
-
useProvider(token: Type<any>, settings?: Partial<IProvider>): this;
|
|
91
|
-
bootstrap(): Promise<this>;
|
|
92
|
-
protected loadRoutes(): Promise<void>;
|
|
93
|
-
protected diff(): string;
|
|
94
|
-
protected importProviders(): Promise<void>;
|
|
95
|
-
/**
|
|
96
|
-
* Load middlewares from configuration for the given hook
|
|
97
|
-
* @param hook
|
|
98
|
-
* @protected
|
|
99
|
-
*/
|
|
100
|
-
protected loadMiddlewaresFor(hook: string): void;
|
|
101
|
-
protected createHttpServers(): void;
|
|
102
|
-
protected listenServers(): Promise<void>;
|
|
103
|
-
protected logRoutes(): Promise<void>;
|
|
104
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { InjectorService } from "@tsed/di";
|
|
2
|
-
import { ControllerProvider } from "../domain/ControllerProvider";
|
|
3
|
-
import { PlatformRouter } from "../services/PlatformRouter";
|
|
4
|
-
/**
|
|
5
|
-
* @ignore
|
|
6
|
-
*/
|
|
7
|
-
export declare function getRouter(injector: InjectorService, provider: ControllerProvider): any;
|
|
8
|
-
/**
|
|
9
|
-
* @ignore
|
|
10
|
-
*/
|
|
11
|
-
export declare function createRouter(injector: InjectorService, provider: ControllerProvider): PlatformRouter;
|
|
12
|
-
/**
|
|
13
|
-
* @ignore
|
|
14
|
-
* @param injector
|
|
15
|
-
* @param provider
|
|
16
|
-
*/
|
|
17
|
-
export declare function buildRouter(injector: InjectorService, provider: ControllerProvider): PlatformRouter<TsED.Router>;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export interface PlatformLoggerSettings {
|
|
2
|
-
/**
|
|
3
|
-
* Enable debug mode. By default debug is false.
|
|
4
|
-
*/
|
|
5
|
-
debug?: boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Enable info mode. By default debug is false.
|
|
8
|
-
*/
|
|
9
|
-
level?: "debug" | "info" | "warn" | "error" | "off";
|
|
10
|
-
/**
|
|
11
|
-
* Enable log performance tracker and disable log server.
|
|
12
|
-
*/
|
|
13
|
-
perf?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* List of regexp to ignore log.
|
|
16
|
-
*/
|
|
17
|
-
ignoreUrlPatterns?: string[];
|
|
18
|
-
/**
|
|
19
|
-
* The number of space characters to use as white space in JSON output. Default is 2 (0 in production).
|
|
20
|
-
*/
|
|
21
|
-
jsonIndentation?: number;
|
|
22
|
-
/**
|
|
23
|
-
* A function called for each incoming request to create a request id.
|
|
24
|
-
* @returns {number}
|
|
25
|
-
*/
|
|
26
|
-
reqIdBuilder?: (req: TsED.Request) => string;
|
|
27
|
-
/**
|
|
28
|
-
* Disable routes table displayed in the logger. By default debug is `false`.
|
|
29
|
-
*/
|
|
30
|
-
disableRoutesSummary?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Disable bootstrap log displayed in the logger. By default debug is `false`.
|
|
33
|
-
*/
|
|
34
|
-
disableBootstrapLog?: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Specify log format. Example: `%[%d{[yyyy-MM-dd hh:mm:ss,SSS}] %p%] %m`. See [@tsed/logger configuration](https://tsedio.github.io/logger/).
|
|
37
|
-
*/
|
|
38
|
-
format?: string;
|
|
39
|
-
/**
|
|
40
|
-
* Specify the log stack size for the context.logger. When the stack.length is reach, the logger is flushed during the request.
|
|
41
|
-
* Default size is set to 30.
|
|
42
|
-
*/
|
|
43
|
-
maxStackSize?: number;
|
|
44
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { FileFilterCallback } from "multer";
|
|
3
|
-
import { Readable } from "stream";
|
|
4
|
-
declare global {
|
|
5
|
-
namespace TsED {
|
|
6
|
-
interface MulterFile {
|
|
7
|
-
/** Name of the form field associated with this file. */
|
|
8
|
-
fieldname: string;
|
|
9
|
-
/** Name of the file on the uploader's computer. */
|
|
10
|
-
originalname: string;
|
|
11
|
-
/** Value of the `Content-Type` header for this file. */
|
|
12
|
-
mimetype: string;
|
|
13
|
-
/** Size of the file in bytes. */
|
|
14
|
-
size: number;
|
|
15
|
-
/**
|
|
16
|
-
* A readable stream of this file. Only available to the `_handleFile`
|
|
17
|
-
* callback for custom `StorageEngine`s.
|
|
18
|
-
*/
|
|
19
|
-
stream: Readable;
|
|
20
|
-
/** `DiskStorage` only: Directory to which this file has been uploaded. */
|
|
21
|
-
destination: string;
|
|
22
|
-
/** `DiskStorage` only: Name of this file within `destination`. */
|
|
23
|
-
filename: string;
|
|
24
|
-
/** `DiskStorage` only: Full path to the uploaded file. */
|
|
25
|
-
path: string;
|
|
26
|
-
/** `MemoryStorage` only: A Buffer containing the entire file. */
|
|
27
|
-
buffer: Buffer;
|
|
28
|
-
}
|
|
29
|
-
interface MulterStorageEngine {
|
|
30
|
-
}
|
|
31
|
-
interface MulterOptions {
|
|
32
|
-
/**
|
|
33
|
-
* A `StorageEngine` responsible for processing files uploaded via Multer.
|
|
34
|
-
* Takes precedence over `dest`.
|
|
35
|
-
*/
|
|
36
|
-
storage?: MulterStorageEngine;
|
|
37
|
-
/**
|
|
38
|
-
* The destination directory for uploaded files. If `storage` is not set
|
|
39
|
-
* and `dest` is, Multer will create a `DiskStorage` instance configured
|
|
40
|
-
* to store files at `dest` with random filenames.
|
|
41
|
-
*
|
|
42
|
-
* Ignored if `storage` is set.
|
|
43
|
-
*/
|
|
44
|
-
dest?: string;
|
|
45
|
-
/**
|
|
46
|
-
* An object specifying various limits on incoming data. This object is
|
|
47
|
-
* passed to Busboy directly, and the details of properties can be found
|
|
48
|
-
* at https://github.com/mscdex/busboy#busboy-methods.
|
|
49
|
-
*/
|
|
50
|
-
limits?: {
|
|
51
|
-
/** Maximum size of each form field name in bytes. (Default: 100) */
|
|
52
|
-
fieldNameSize?: number;
|
|
53
|
-
/** Maximum size of each form field value in bytes. (Default: 1048576) */
|
|
54
|
-
fieldSize?: number;
|
|
55
|
-
/** Maximum number of non-file form fields. (Default: Infinity) */
|
|
56
|
-
fields?: number;
|
|
57
|
-
/** Maximum size of each file in bytes. (Default: Infinity) */
|
|
58
|
-
fileSize?: number;
|
|
59
|
-
/** Maximum number of file fields. (Default: Infinity) */
|
|
60
|
-
files?: number;
|
|
61
|
-
/** Maximum number of parts (non-file fields + files). (Default: Infinity) */
|
|
62
|
-
parts?: number;
|
|
63
|
-
/** Maximum number of headers. (Default: 2000) */
|
|
64
|
-
headerPairs?: number;
|
|
65
|
-
};
|
|
66
|
-
/** Preserve the full path of the original filename rather than the basename. (Default: false) */
|
|
67
|
-
preservePath?: boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Optional function to control which files are uploaded. This is called
|
|
70
|
-
* for every file that is processed.
|
|
71
|
-
*
|
|
72
|
-
* @param req The Express `Request` object.
|
|
73
|
-
* @param file Object containing information about the processed file.
|
|
74
|
-
* @param callback a function to control which files should be uploaded and which should be skipped.
|
|
75
|
-
*/
|
|
76
|
-
fileFilter?(req: Request, file: MulterFile, callback: FileFilterCallback): void;
|
|
77
|
-
}
|
|
78
|
-
interface MulterField {
|
|
79
|
-
name: string;
|
|
80
|
-
maxCount?: number;
|
|
81
|
-
}
|
|
82
|
-
type MulterHandler = (req: any, res: any) => Promise<any>;
|
|
83
|
-
interface Multer {
|
|
84
|
-
/**
|
|
85
|
-
* Returns middleware that processes a single file associated with the
|
|
86
|
-
* given form field.
|
|
87
|
-
*
|
|
88
|
-
* The `Request` object will be populated with a `file` object containing
|
|
89
|
-
* information about the processed file.
|
|
90
|
-
*
|
|
91
|
-
* @param fieldName Name of the multipart form field to process.
|
|
92
|
-
*/
|
|
93
|
-
single(fieldName: string): MulterHandler;
|
|
94
|
-
/**
|
|
95
|
-
* Returns middleware that processes multiple files sharing the same field
|
|
96
|
-
* name.
|
|
97
|
-
*
|
|
98
|
-
* The `Request` object will be populated with a `files` array containing
|
|
99
|
-
* an information object for each processed file.
|
|
100
|
-
*
|
|
101
|
-
* @param fieldName Shared name of the multipart form fields to process.
|
|
102
|
-
* @param maxCount Optional. Maximum number of files to process. (default: Infinity)
|
|
103
|
-
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if more than `maxCount` files are associated with `fieldName`
|
|
104
|
-
*/
|
|
105
|
-
array(fieldName: string, maxCount?: number): MulterHandler;
|
|
106
|
-
/**
|
|
107
|
-
* Returns middleware that processes multiple files associated with the
|
|
108
|
-
* given form fields.
|
|
109
|
-
*
|
|
110
|
-
* The `Request` object will be populated with a `files` object which
|
|
111
|
-
* maps each field name to an array of the associated file information
|
|
112
|
-
* objects.
|
|
113
|
-
*
|
|
114
|
-
* @param fields Array of `Field` objects describing multipart form fields to process.
|
|
115
|
-
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if more than `maxCount` files are associated with `fieldName` for any field.
|
|
116
|
-
*/
|
|
117
|
-
fields(fields: MulterField[]): MulterHandler;
|
|
118
|
-
/**
|
|
119
|
-
* Returns middleware that processes all files contained in the multipart
|
|
120
|
-
* request.
|
|
121
|
-
*
|
|
122
|
-
* The `Request` object will be populated with a `files` array containing
|
|
123
|
-
* an information object for each processed file.
|
|
124
|
-
*/
|
|
125
|
-
any(): MulterHandler;
|
|
126
|
-
/**
|
|
127
|
-
* Returns middleware that accepts only non-file multipart form fields.
|
|
128
|
-
*
|
|
129
|
-
* @throws `MulterError('LIMIT_UNEXPECTED_FILE')` if any file is encountered.
|
|
130
|
-
*/
|
|
131
|
-
none(): MulterHandler;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
export declare type PlatformMulter = TsED.Multer;
|
|
136
|
-
export declare type PlatformMulterSettings = TsED.MulterOptions;
|
|
137
|
-
export declare type PlatformMulterFile = TsED.MulterFile;
|
|
138
|
-
export declare type PlatformMulterField = TsED.MulterField;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
namespace TsED {
|
|
3
|
-
interface StaticsOptions {
|
|
4
|
-
root: string;
|
|
5
|
-
hook?: "$beforeRoutesInit" | "$afterRoutesInit";
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export interface PlatformStaticsOptions extends TsED.StaticsOptions {
|
|
11
|
-
root: string;
|
|
12
|
-
[key: string]: any;
|
|
13
|
-
}
|
|
14
|
-
export declare type PathOrStaticsOptions = string | PlatformStaticsOptions;
|
|
15
|
-
export interface PlatformStaticsSettings {
|
|
16
|
-
[endpoint: string]: PathOrStaticsOptions | PathOrStaticsOptions[];
|
|
17
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Env } from "@tsed/core";
|
|
3
|
-
import { ConverterSettings } from "./ConverterSettings";
|
|
4
|
-
import { EndpointDirectoriesSettings } from "./EndpointDirectoriesSettings";
|
|
5
|
-
import { PlatformLoggerSettings } from "./PlatformLoggerSettings";
|
|
6
|
-
import { PlatformMulterSettings } from "./PlatformMulterSettings";
|
|
7
|
-
import { PlatformStaticsSettings } from "./PlatformStaticsSettings";
|
|
8
|
-
import type Http from "http";
|
|
9
|
-
import type Https from "https";
|
|
10
|
-
declare global {
|
|
11
|
-
namespace TsED {
|
|
12
|
-
interface LoggerConfiguration extends Partial<PlatformLoggerSettings> {
|
|
13
|
-
}
|
|
14
|
-
interface Configuration {
|
|
15
|
-
/**
|
|
16
|
-
* The root directory where you build run project. By default, it's equal to `process.cwd().
|
|
17
|
-
*/
|
|
18
|
-
rootDir: string;
|
|
19
|
-
/**
|
|
20
|
-
* The environment profile. By default the environment profile is equals to `NODE_ENV`.
|
|
21
|
-
*/
|
|
22
|
-
env: Env;
|
|
23
|
-
/**
|
|
24
|
-
* Port number for the [HTTP.Server](https://nodejs.org/api/http.html#http_class_http_server).
|
|
25
|
-
*/
|
|
26
|
-
port: string | number;
|
|
27
|
-
/**
|
|
28
|
-
* Port number for the [HTTP.Server](https://nodejs.org/api/http.html#http_class_http_server).
|
|
29
|
-
*/
|
|
30
|
-
httpPort: string | number | boolean;
|
|
31
|
-
/**
|
|
32
|
-
* [Https.ServerOptions](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener)):
|
|
33
|
-
* - `key` <string> | <string[]> | [<Buffer>](https://nodejs.org/api/buffer.html#buffer_class_buffer) | <Object[]>: The private key of the server in PEM format. To support multiple keys using different algorithms an array can be provided either as a plain array of key strings or an array of objects in the format `{pem: key, passphrase: passphrase}`. This option is required for ciphers that make use of private keys.
|
|
34
|
-
* - `passphrase` <string> A string containing the passphrase for the private key or pfx.
|
|
35
|
-
* - `cert` <string> | <string[]> | [<Buffer>](https://nodejs.org/api/buffer.html#buffer_class_buffer) | [<Buffer[]>](https://nodejs.org/api/buffer.html#buffer_class_buffer): A string, Buffer, array of strings, or array of Buffers containing the certificate key of the server in PEM format. (Required)
|
|
36
|
-
* - `ca` <string> | <string[]> | [<Buffer>](https://nodejs.org/api/buffer.html#buffer_class_buffer) | [<Buffer[]>](https://nodejs.org/api/buffer.html#buffer_class_buffer): A string, Buffer, array of strings, or array of Buffers of trusted certificates in PEM format. If this is omitted several well known "root" CAs (like VeriSign) will be used. These are used to authorize connections.
|
|
37
|
-
*/
|
|
38
|
-
httpOptions: Http.ServerOptions;
|
|
39
|
-
/**
|
|
40
|
-
* Port number for the [HTTPs.Server](https://nodejs.org/api/https.html#https_class_https_server).
|
|
41
|
-
*/
|
|
42
|
-
httpsPort: string | number | boolean;
|
|
43
|
-
/**
|
|
44
|
-
* [Https.ServerOptions](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener)):
|
|
45
|
-
* - `key` <string> | <string[]> | [<Buffer>](https://nodejs.org/api/buffer.html#buffer_class_buffer) | <Object[]>: The private key of the server in PEM format. To support multiple keys using different algorithms an array can be provided either as a plain array of key strings or an array of objects in the format `{pem: key, passphrase: passphrase}`. This option is required for ciphers that make use of private keys.
|
|
46
|
-
* - `passphrase` <string> A string containing the passphrase for the private key or pfx.
|
|
47
|
-
* - `cert` <string> | <string[]> | [<Buffer>](https://nodejs.org/api/buffer.html#buffer_class_buffer) | [<Buffer[]>](https://nodejs.org/api/buffer.html#buffer_class_buffer): A string, Buffer, array of strings, or array of Buffers containing the certificate key of the server in PEM format. (Required)
|
|
48
|
-
* - `ca` <string> | <string[]> | [<Buffer>](https://nodejs.org/api/buffer.html#buffer_class_buffer) | [<Buffer[]>](https://nodejs.org/api/buffer.html#buffer_class_buffer): A string, Buffer, array of strings, or array of Buffers of trusted certificates in PEM format. If this is omitted several well known "root" CAs (like VeriSign) will be used. These are used to authorize connections.
|
|
49
|
-
*/
|
|
50
|
-
httpsOptions: Https.ServerOptions;
|
|
51
|
-
/**
|
|
52
|
-
* Mount all controllers under a directories to an endpoint.
|
|
53
|
-
*/
|
|
54
|
-
mount: EndpointDirectoriesSettings;
|
|
55
|
-
/**
|
|
56
|
-
* List of directories to scan [Services](/docs/services.md), [Middlewares](/docs/middlewares.md) or [Converters](/docs/converters.md).
|
|
57
|
-
*/
|
|
58
|
-
componentsScan: (string | RegExp)[];
|
|
59
|
-
/**
|
|
60
|
-
* Disable the glob pattern. In v7 the componentsScan options will be removed in favor of external module loader.
|
|
61
|
-
*/
|
|
62
|
-
disableComponentsScan: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* List of glob patterns. Exclude all files which matching with this list when Server scan all components with the `mount` or `scanComponents` options.
|
|
65
|
-
*/
|
|
66
|
-
exclude: string[];
|
|
67
|
-
/**
|
|
68
|
-
* Configure the mimes accepted by default by the server.
|
|
69
|
-
*/
|
|
70
|
-
acceptMimes: string[];
|
|
71
|
-
/**
|
|
72
|
-
* Enable debug mode. By default debug is false.
|
|
73
|
-
*/
|
|
74
|
-
debug: boolean;
|
|
75
|
-
/**
|
|
76
|
-
* Converter configuration.
|
|
77
|
-
*/
|
|
78
|
-
converter: Partial<ConverterSettings>;
|
|
79
|
-
/**
|
|
80
|
-
* Logger configuration.
|
|
81
|
-
*/
|
|
82
|
-
logger?: LoggerConfiguration;
|
|
83
|
-
/**
|
|
84
|
-
* Object to mount all directories under to his endpoints. See more on [Serve Static](/tutorials/serve-static-files.md).
|
|
85
|
-
*/
|
|
86
|
-
statics: PlatformStaticsSettings;
|
|
87
|
-
/**
|
|
88
|
-
* Object configure Multer. See more on [Upload file](/tutorials/serve-static-files.md).
|
|
89
|
-
*/
|
|
90
|
-
multer: PlatformMulterSettings;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
export * from "./PlatformLoggerSettings";
|
|
95
|
-
export * from "./EndpointDirectoriesSettings";
|
|
96
|
-
export * from "./PlatformStaticsSettings";
|
|
97
|
-
export * from "./PlatformMulterSettings";
|