@tsed/common 7.0.0-beta.9 → 7.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage.json +6 -0
- package/jest.config.js +9 -0
- package/lib/cjs/builder/PlatformBuilder.js +86 -68
- package/lib/cjs/builder/PlatformBuilder.js.map +1 -1
- package/lib/cjs/config/interfaces/PlatformLoggerSettings.js.map +1 -1
- package/lib/cjs/config/services/PlatformConfiguration.js +0 -64
- package/lib/cjs/config/services/PlatformConfiguration.js.map +1 -1
- package/lib/cjs/decorators/params/error.js +1 -1
- package/lib/cjs/decorators/params/error.js.map +1 -1
- package/lib/cjs/domain/AnyToPromiseWithCtx.js +4 -5
- package/lib/cjs/domain/AnyToPromiseWithCtx.js.map +1 -1
- package/lib/cjs/domain/PlatformContext.js +46 -38
- package/lib/cjs/domain/PlatformContext.js.map +1 -1
- package/lib/cjs/domain/PlatformRouteDetails.js +0 -21
- package/lib/cjs/domain/PlatformRouteDetails.js.map +1 -1
- package/lib/cjs/exports.js +1 -0
- package/lib/cjs/exports.js.map +1 -1
- package/lib/cjs/index.js +1 -9
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/PlatformRouteOptions.js.map +1 -1
- package/lib/cjs/interfaces/Route.js.map +1 -1
- package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js +2 -1
- package/lib/cjs/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -1
- package/lib/cjs/middlewares/PlatformMulterMiddleware.js +2 -0
- package/lib/cjs/middlewares/PlatformMulterMiddleware.js.map +1 -1
- package/lib/cjs/services/FakeAdapter.js +6 -12
- package/lib/cjs/services/FakeAdapter.js.map +1 -1
- package/lib/cjs/services/Platform.js +30 -86
- package/lib/cjs/services/Platform.js.map +1 -1
- package/lib/cjs/services/PlatformAdapter.js +10 -0
- package/lib/cjs/services/PlatformAdapter.js.map +1 -1
- package/lib/cjs/services/PlatformApplication.js +23 -9
- package/lib/cjs/services/PlatformApplication.js.map +1 -1
- package/lib/cjs/services/PlatformHandler.js +112 -171
- package/lib/cjs/services/PlatformHandler.js.map +1 -1
- package/lib/cjs/services/PlatformMiddlewaresChain.js +5 -19
- package/lib/cjs/services/PlatformMiddlewaresChain.js.map +1 -1
- package/lib/cjs/services/PlatformRequest.js +16 -12
- package/lib/cjs/services/PlatformRequest.js.map +1 -1
- package/lib/cjs/services/PlatformResponse.js +19 -22
- package/lib/cjs/services/PlatformResponse.js.map +1 -1
- package/lib/cjs/services/PlatformTest.js +29 -9
- package/lib/cjs/services/PlatformTest.js.map +1 -1
- package/lib/cjs/utils/createContext.js +32 -21
- package/lib/cjs/utils/createContext.js.map +1 -1
- package/lib/cjs/utils/createHttpServer.js +3 -3
- package/lib/cjs/utils/createHttpServer.js.map +1 -1
- package/lib/cjs/utils/createHttpsServer.js +3 -3
- package/lib/cjs/utils/createHttpsServer.js.map +1 -1
- package/lib/cjs/utils/createInjector.js +6 -8
- package/lib/cjs/utils/createInjector.js.map +1 -1
- package/lib/cjs/utils/ensureContext.js +16 -0
- package/lib/cjs/utils/ensureContext.js.map +1 -0
- package/lib/cjs/utils/getConfiguration.js +6 -12
- package/lib/cjs/utils/getConfiguration.js.map +1 -1
- package/lib/cjs/utils/printRoutes.js +10 -8
- package/lib/cjs/utils/printRoutes.js.map +1 -1
- package/lib/cjs/utils/setResponseHeaders.js +8 -14
- package/lib/cjs/utils/setResponseHeaders.js.map +1 -1
- package/lib/esm/builder/PlatformBuilder.js +63 -68
- package/lib/esm/builder/PlatformBuilder.js.map +1 -1
- package/lib/esm/config/interfaces/PlatformLoggerSettings.js.map +1 -1
- package/lib/esm/config/services/PlatformConfiguration.js +0 -64
- package/lib/esm/config/services/PlatformConfiguration.js.map +1 -1
- package/lib/esm/decorators/params/error.js +1 -1
- package/lib/esm/decorators/params/error.js.map +1 -1
- package/lib/esm/domain/AnyToPromiseWithCtx.js +4 -5
- package/lib/esm/domain/AnyToPromiseWithCtx.js.map +1 -1
- package/lib/esm/domain/PlatformContext.js +46 -38
- package/lib/esm/domain/PlatformContext.js.map +1 -1
- package/lib/esm/domain/PlatformRouteDetails.js +1 -19
- package/lib/esm/domain/PlatformRouteDetails.js.map +1 -1
- package/lib/esm/exports.js +1 -0
- package/lib/esm/exports.js.map +1 -1
- package/lib/esm/index.js +1 -9
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/PlatformRouteOptions.js.map +1 -1
- package/lib/esm/interfaces/Route.js.map +1 -1
- package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js +2 -1
- package/lib/esm/middlewares/PlatformAcceptMimesMiddleware.js.map +1 -1
- package/lib/esm/middlewares/PlatformMulterMiddleware.js +2 -0
- package/lib/esm/middlewares/PlatformMulterMiddleware.js.map +1 -1
- package/lib/esm/services/FakeAdapter.js +6 -12
- package/lib/esm/services/FakeAdapter.js.map +1 -1
- package/lib/esm/services/Platform.js +31 -87
- package/lib/esm/services/Platform.js.map +1 -1
- package/lib/esm/services/PlatformAdapter.js +10 -0
- package/lib/esm/services/PlatformAdapter.js.map +1 -1
- package/lib/esm/services/PlatformApplication.js +23 -9
- package/lib/esm/services/PlatformApplication.js.map +1 -1
- package/lib/esm/services/PlatformHandler.js +114 -173
- package/lib/esm/services/PlatformHandler.js.map +1 -1
- package/lib/esm/services/PlatformMiddlewaresChain.js +5 -19
- package/lib/esm/services/PlatformMiddlewaresChain.js.map +1 -1
- package/lib/esm/services/PlatformRequest.js +16 -12
- package/lib/esm/services/PlatformRequest.js.map +1 -1
- package/lib/esm/services/PlatformResponse.js +19 -22
- package/lib/esm/services/PlatformResponse.js.map +1 -1
- package/lib/esm/services/PlatformTest.js +29 -9
- package/lib/esm/services/PlatformTest.js.map +1 -1
- package/lib/esm/utils/createContext.js +30 -20
- package/lib/esm/utils/createContext.js.map +1 -1
- package/lib/esm/utils/createHttpServer.js +3 -3
- package/lib/esm/utils/createHttpServer.js.map +1 -1
- package/lib/esm/utils/createHttpsServer.js +3 -3
- package/lib/esm/utils/createHttpsServer.js.map +1 -1
- package/lib/esm/utils/createInjector.js +7 -9
- package/lib/esm/utils/createInjector.js.map +1 -1
- package/lib/esm/utils/ensureContext.js +12 -0
- package/lib/esm/utils/ensureContext.js.map +1 -0
- package/lib/esm/utils/getConfiguration.js +8 -14
- package/lib/esm/utils/getConfiguration.js.map +1 -1
- package/lib/esm/utils/printRoutes.js +10 -8
- package/lib/esm/utils/printRoutes.js.map +1 -1
- package/lib/esm/utils/setResponseHeaders.js +8 -14
- package/lib/esm/utils/setResponseHeaders.js.map +1 -1
- package/lib/types/builder/PlatformBuilder.d.ts +17 -16
- package/lib/types/config/interfaces/PlatformLoggerSettings.d.ts +2 -43
- package/lib/types/config/services/PlatformConfiguration.d.ts +6 -22
- package/lib/types/domain/AnyToPromiseWithCtx.d.ts +1 -9
- package/lib/types/domain/PlatformContext.d.ts +32 -18
- package/lib/types/domain/PlatformRouteDetails.d.ts +4 -19
- package/lib/types/exports.d.ts +1 -0
- package/lib/types/index.d.ts +1 -9
- package/lib/types/interfaces/PlatformRouteOptions.d.ts +0 -1
- package/lib/types/interfaces/Route.d.ts +2 -3
- package/lib/types/middlewares/PlatformMulterMiddleware.d.ts +1 -1
- package/lib/types/services/FakeAdapter.d.ts +7 -6
- package/lib/types/services/Platform.d.ts +7 -28
- package/lib/types/services/PlatformAdapter.d.ts +22 -11
- package/lib/types/services/PlatformApplication.d.ts +14 -6
- package/lib/types/services/PlatformHandler.d.ts +21 -59
- package/lib/types/services/PlatformMiddlewaresChain.d.ts +1 -2
- package/lib/types/services/PlatformRequest.d.ts +8 -10
- package/lib/types/services/PlatformResponse.d.ts +11 -15
- package/lib/types/services/PlatformTest.d.ts +4 -3
- package/lib/types/utils/createContext.d.ts +4 -1
- package/lib/types/utils/createHttpsServer.d.ts +1 -0
- package/lib/types/utils/createInjector.d.ts +2 -2
- package/lib/types/utils/ensureContext.d.ts +2 -0
- package/lib/types/utils/listenServer.d.ts +2 -0
- package/package.json +28 -23
- package/readme.md +2 -1
- package/lib/cjs/builder/PlatformControllerBuilder.js +0 -82
- package/lib/cjs/builder/PlatformControllerBuilder.js.map +0 -1
- package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js +0 -3
- package/lib/cjs/config/interfaces/EndpointDirectoriesSettings.js.map +0 -1
- package/lib/cjs/domain/ControllerProvider.js +0 -51
- package/lib/cjs/domain/ControllerProvider.js.map +0 -1
- package/lib/cjs/domain/HandlerMetadata.js +0 -57
- package/lib/cjs/domain/HandlerMetadata.js.map +0 -1
- package/lib/cjs/middlewares/__mock__/FakeCtrl.js +0 -12
- package/lib/cjs/middlewares/__mock__/FakeCtrl.js.map +0 -1
- package/lib/cjs/middlewares/bindEndpointMiddleware.js +0 -13
- package/lib/cjs/middlewares/bindEndpointMiddleware.js.map +0 -1
- package/lib/cjs/services/PlatformRouter.js +0 -108
- package/lib/cjs/services/PlatformRouter.js.map +0 -1
- package/lib/cjs/utils/__mock__/Test1.js +0 -8
- package/lib/cjs/utils/__mock__/Test1.js.map +0 -1
- package/lib/cjs/utils/__mock__/Test2.js +0 -8
- package/lib/cjs/utils/__mock__/Test2.js.map +0 -1
- package/lib/cjs/utils/createHandlerMetadata.js +0 -49
- package/lib/cjs/utils/createHandlerMetadata.js.map +0 -1
- package/lib/cjs/utils/importProviders.js +0 -29
- package/lib/cjs/utils/importProviders.js.map +0 -1
- package/lib/cjs/utils/useCtxHandler.js +0 -15
- package/lib/cjs/utils/useCtxHandler.js.map +0 -1
- package/lib/esm/builder/PlatformControllerBuilder.js +0 -76
- package/lib/esm/builder/PlatformControllerBuilder.js.map +0 -1
- package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js +0 -2
- package/lib/esm/config/interfaces/EndpointDirectoriesSettings.js.map +0 -1
- package/lib/esm/domain/ControllerProvider.js +0 -47
- package/lib/esm/domain/ControllerProvider.js.map +0 -1
- package/lib/esm/domain/HandlerMetadata.js +0 -53
- package/lib/esm/domain/HandlerMetadata.js.map +0 -1
- package/lib/esm/middlewares/__mock__/FakeCtrl.js +0 -9
- package/lib/esm/middlewares/__mock__/FakeCtrl.js.map +0 -1
- package/lib/esm/middlewares/bindEndpointMiddleware.js +0 -9
- package/lib/esm/middlewares/bindEndpointMiddleware.js.map +0 -1
- package/lib/esm/services/PlatformRouter.js +0 -105
- package/lib/esm/services/PlatformRouter.js.map +0 -1
- package/lib/esm/utils/__mock__/Test1.js +0 -4
- package/lib/esm/utils/__mock__/Test1.js.map +0 -1
- package/lib/esm/utils/__mock__/Test2.js +0 -4
- package/lib/esm/utils/__mock__/Test2.js.map +0 -1
- package/lib/esm/utils/createHandlerMetadata.js +0 -45
- package/lib/esm/utils/createHandlerMetadata.js.map +0 -1
- package/lib/esm/utils/importProviders.js +0 -25
- package/lib/esm/utils/importProviders.js.map +0 -1
- package/lib/esm/utils/useCtxHandler.js +0 -11
- package/lib/esm/utils/useCtxHandler.js.map +0 -1
- package/lib/types/builder/PlatformControllerBuilder.d.ts +0 -18
- package/lib/types/config/interfaces/EndpointDirectoriesSettings.d.ts +0 -3
- package/lib/types/domain/ControllerProvider.d.ts +0 -24
- package/lib/types/domain/HandlerMetadata.d.ts +0 -32
- package/lib/types/middlewares/__mock__/FakeCtrl.d.ts +0 -2
- package/lib/types/middlewares/bindEndpointMiddleware.d.ts +0 -6
- package/lib/types/services/PlatformRouter.d.ts +0 -51
- package/lib/types/utils/__mock__/Test1.d.ts +0 -3
- package/lib/types/utils/__mock__/Test2.d.ts +0 -3
- package/lib/types/utils/createHandlerMetadata.d.ts +0 -8
- package/lib/types/utils/importProviders.d.ts +0 -10
- package/lib/types/utils/useCtxHandler.d.ts +0 -13
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ControllerProvider = void 0;
|
|
4
|
-
const di_1 = require("@tsed/di");
|
|
5
|
-
const routerOptions_1 = require("../constants/routerOptions");
|
|
6
|
-
let AUTO_INC = 0;
|
|
7
|
-
class ControllerProvider extends di_1.Provider {
|
|
8
|
-
constructor(provide, options = {}) {
|
|
9
|
-
super(provide, options);
|
|
10
|
-
this.type = di_1.ProviderType.CONTROLLER;
|
|
11
|
-
this.tokenRouter = `${this.name}_ROUTER_${AUTO_INC++}`;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
get routerOptions() {
|
|
17
|
-
return this.store.get(routerOptions_1.ROUTER_OPTIONS) || {};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @param value
|
|
22
|
-
*/
|
|
23
|
-
set routerOptions(value) {
|
|
24
|
-
this.store.set(routerOptions_1.ROUTER_OPTIONS, value);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
* @returns {any[]}
|
|
29
|
-
*/
|
|
30
|
-
get middlewares() {
|
|
31
|
-
return Object.assign({
|
|
32
|
-
use: [],
|
|
33
|
-
useAfter: [],
|
|
34
|
-
useBefore: []
|
|
35
|
-
}, this.store.get("middlewares", {}));
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
*
|
|
39
|
-
* @param middlewares
|
|
40
|
-
*/
|
|
41
|
-
set middlewares(middlewares) {
|
|
42
|
-
const mdlwrs = this.middlewares;
|
|
43
|
-
const concat = (key, a, b) => (a[key] = a[key].concat(b[key]));
|
|
44
|
-
Object.keys(middlewares).forEach((key) => {
|
|
45
|
-
concat(key, mdlwrs, middlewares);
|
|
46
|
-
});
|
|
47
|
-
this.store.set("middlewares", mdlwrs);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.ControllerProvider = ControllerProvider;
|
|
51
|
-
//# sourceMappingURL=ControllerProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ControllerProvider.js","sourceRoot":"","sources":["../../../src/domain/ControllerProvider.ts"],"names":[],"mappings":";;;AAAA,iCAAsF;AAC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C,CAAC;QACnC,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;CACF;AApDD,gDAoDC","sourcesContent":["import {ControllerMiddlewares, Provider, ProviderType, TokenProvider} from \"@tsed/di\";\nimport {ROUTER_OPTIONS} from \"../constants/routerOptions\";\n\nlet AUTO_INC = 0;\n\nexport class ControllerProvider<T = any> extends Provider<T> {\n readonly tokenRouter: string;\n\n constructor(provide: TokenProvider, options: Partial<Provider> = {}) {\n super(provide, options);\n this.type = ProviderType.CONTROLLER;\n this.tokenRouter = `${this.name}_ROUTER_${AUTO_INC++}`;\n }\n\n /**\n *\n */\n get routerOptions(): any {\n return this.store.get(ROUTER_OPTIONS) || ({} as any);\n }\n\n /**\n *\n * @param value\n */\n set routerOptions(value: any) {\n this.store.set(ROUTER_OPTIONS, value);\n }\n\n /**\n *\n * @returns {any[]}\n */\n get middlewares(): ControllerMiddlewares {\n return Object.assign(\n {\n use: [],\n useAfter: [],\n useBefore: []\n },\n this.store.get(\"middlewares\", {})\n );\n }\n\n /**\n *\n * @param middlewares\n */\n set middlewares(middlewares: ControllerMiddlewares) {\n const mdlwrs = this.middlewares;\n const concat = (key: string, a: any, b: any) => (a[key] = a[key].concat(b[key]));\n\n Object.keys(middlewares).forEach((key: string) => {\n concat(key, mdlwrs, middlewares);\n });\n this.store.set(\"middlewares\", mdlwrs);\n }\n}\n"]}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HandlerMetadata = void 0;
|
|
4
|
-
const core_1 = require("@tsed/core");
|
|
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 HandlerType_1 = require("../interfaces/HandlerType");
|
|
9
|
-
class HandlerMetadata {
|
|
10
|
-
constructor(options) {
|
|
11
|
-
this.injectable = false;
|
|
12
|
-
this.type = HandlerType_1.HandlerType.RAW_FN;
|
|
13
|
-
this.hasNextFunction = false;
|
|
14
|
-
const { target, token, propertyKey, type, scope, routeOptions } = options;
|
|
15
|
-
this.type = type || target.type || HandlerType_1.HandlerType.RAW_FN;
|
|
16
|
-
this.scope = scope || di_1.ProviderScope.SINGLETON;
|
|
17
|
-
this.routeOptions = routeOptions || {};
|
|
18
|
-
const handler = propertyKey ? target.prototype[propertyKey] : target;
|
|
19
|
-
if (propertyKey) {
|
|
20
|
-
this.target = target;
|
|
21
|
-
this.token = token;
|
|
22
|
-
this.propertyKey = propertyKey;
|
|
23
|
-
this.hasNextFunction = this.hasParamType(platform_params_1.ParamTypes.NEXT_FN);
|
|
24
|
-
if (this.hasParamType(platform_params_1.ParamTypes.ERR)) {
|
|
25
|
-
this.type = HandlerType_1.HandlerType.ERR_MIDDLEWARE;
|
|
26
|
-
}
|
|
27
|
-
this.injectable = schema_1.JsonParameterStore.getParams(target, propertyKey).length > 0;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
this.handler = handler;
|
|
31
|
-
}
|
|
32
|
-
if (!this.injectable) {
|
|
33
|
-
if (handler.length === 4) {
|
|
34
|
-
this.type = HandlerType_1.HandlerType.RAW_ERR_FN;
|
|
35
|
-
}
|
|
36
|
-
this.hasNextFunction = handler.length >= 3;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
get hasErrorParam() {
|
|
40
|
-
return this.type === HandlerType_1.HandlerType.ERR_MIDDLEWARE || this.type === HandlerType_1.HandlerType.RAW_ERR_FN;
|
|
41
|
-
}
|
|
42
|
-
getParams() {
|
|
43
|
-
return schema_1.JsonParameterStore.getParams(this.target, this.propertyKey) || [];
|
|
44
|
-
}
|
|
45
|
-
hasParamType(paramType) {
|
|
46
|
-
return this.getParams().findIndex((p) => p.paramType === paramType) > -1;
|
|
47
|
-
}
|
|
48
|
-
isFinal() {
|
|
49
|
-
var _a;
|
|
50
|
-
return ((_a = this.routeOptions) === null || _a === void 0 ? void 0 : _a.isFinal) || false;
|
|
51
|
-
}
|
|
52
|
-
toString() {
|
|
53
|
-
return [this.target && (0, core_1.nameOf)(this.target), this.propertyKey].filter(Boolean).join(".");
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.HandlerMetadata = HandlerMetadata;
|
|
57
|
-
//# sourceMappingURL=HandlerMetadata.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HandlerMetadata.js","sourceRoot":"","sources":["../../../src/domain/HandlerMetadata.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AACxC,iCAAuC;AACvC,2DAAiD;AACjD,yCAAgD;AAChD,2DAAsD;AAYtD,MAAa,eAAe;IAY1B,YAAY,OAA+B;QARlC,eAAU,GAAY,KAAK,CAAC;QAC5B,SAAI,GAAgB,yBAAW,CAAC,MAAM,CAAC;QACvC,oBAAe,GAAY,KAAK,CAAC;QAOxC,MAAM,EAAC,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAC,GAAG,OAAO,CAAC;QAExE,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,CAAC,IAAI,IAAI,yBAAW,CAAC,MAAM,CAAC;QACtD,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,kBAAa,CAAC,SAAS,CAAC;QAC9C,IAAI,CAAC,YAAY,GAAG,YAAY,IAAI,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAErE,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YACrB,IAAI,CAAC,KAAK,GAAG,KAAM,CAAC;YACpB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;YAC/B,IAAI,CAAC,eA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MAAM,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1F,CAAC;CACF;AA9DD,0CA8DC","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {ProviderScope} from \"@tsed/di\";\nimport {ParamTypes} from \"@tsed/platform-params\";\nimport {JsonParameterStore} from \"@tsed/schema\";\nimport {HandlerType} from \"../interfaces/HandlerType\";\nimport {PlatformRouteOptions, PlatformRouteWithoutHandlers} from \"../interfaces/PlatformRouteOptions\";\n\nexport interface HandlerMetadataOptions {\n target: (Type<any> | Function) & {type?: HandlerType};\n routeOptions?: PlatformRouteWithoutHandlers;\n token?: Type<any>;\n propertyKey?: string | symbol;\n scope?: ProviderScope;\n type?: HandlerType;\n}\n\nexport class HandlerMetadata {\n readonly target: any;\n readonly token: Type<any>;\n readonly propertyKey: string | symbol;\n readonly injectable: boolean = false;\n readonly type: HandlerType = HandlerType.RAW_FN;\n readonly hasNextFunction: boolean = false;\n readonly routeOptions: Partial<PlatformRouteOptions>;\n readonly scope: ProviderScope;\n\n handler: any;\n\n constructor(options: HandlerMetadataOptions) {\n const {target, token, propertyKey, type, scope, routeOptions} = options;\n\n this.type = type || target.type || HandlerType.RAW_FN;\n this.scope = scope || ProviderScope.SINGLETON;\n this.routeOptions = routeOptions || {};\n const handler = propertyKey ? target.prototype[propertyKey] : target;\n\n if (propertyKey) {\n this.target = target;\n this.token = token!;\n this.propertyKey = propertyKey;\n this.hasNextFunction = this.hasParamType(ParamTypes.NEXT_FN);\n\n if (this.hasParamType(ParamTypes.ERR)) {\n this.type = HandlerType.ERR_MIDDLEWARE;\n }\n\n this.injectable = JsonParameterStore.getParams(target as any, propertyKey).length > 0;\n } else {\n this.handler = handler;\n }\n\n if (!this.injectable) {\n if (handler.length === 4) {\n this.type = HandlerType.RAW_ERR_FN;\n }\n this.hasNextFunction = handler.length >= 3;\n }\n }\n\n get hasErrorParam() {\n return this.type === HandlerType.ERR_MIDDLEWARE || this.type === HandlerType.RAW_ERR_FN;\n }\n\n public getParams() {\n return JsonParameterStore.getParams(this.target, this.propertyKey) || [];\n }\n\n public hasParamType(paramType: any): boolean {\n return this.getParams().findIndex((p) => p.paramType === paramType) > -1;\n }\n\n public isFinal() {\n return this.routeOptions?.isFinal || false;\n }\n\n toString() {\n return [this.target && nameOf(this.target), this.propertyKey].filter(Boolean).join(\".\");\n }\n}\n"]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FakeCtrl = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const di_1 = require("@tsed/di");
|
|
6
|
-
let FakeCtrl = class FakeCtrl {
|
|
7
|
-
};
|
|
8
|
-
FakeCtrl = tslib_1.__decorate([
|
|
9
|
-
(0, di_1.Controller)("/")
|
|
10
|
-
], FakeCtrl);
|
|
11
|
-
exports.FakeCtrl = FakeCtrl;
|
|
12
|
-
//# sourceMappingURL=FakeCtrl.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FakeCtrl.js","sourceRoot":"","sources":["../../../../src/middlewares/__mock__/FakeCtrl.ts"],"names":[],"mappings":";;;;AAAA,iCAAoC;AAGpC,IAAa,QAAQ,GAArB,MAAa,QAAQ;CAAG,CAAA;AAAX,QAAQ;IADpB,IAAA,eAAU,EAAC,GAAG,CAAC;GACH,QAAQ,CAAG;AAAX,4BAAQ","sourcesContent":["import {Controller} from \"@tsed/di\";\n\n@Controller(\"/\")\nexport class FakeCtrl {}\n"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.bindEndpointMiddleware = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @ignore
|
|
6
|
-
*/
|
|
7
|
-
function bindEndpointMiddleware(endpoint) {
|
|
8
|
-
return (ctx) => {
|
|
9
|
-
ctx.endpoint = endpoint;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
exports.bindEndpointMiddleware = bindEndpointMiddleware;
|
|
13
|
-
//# sourceMappingURL=bindEndpointMiddleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bindEndpointMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/bindEndpointMiddleware.ts"],"names":[],"mappings":";;;AAGA;;GAEG;AACH,SAAgB,sBAAsB,CAAC,QAA0B;IAC/D,OAAO,CAAC,GAAoB,EAAE,EAAE;QAC9B,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC,CAAC;AACJ,CAAC;AAJD,wDAIC","sourcesContent":["import type {EndpointMetadata} from \"../domain/EndpointMetadata\";\nimport type {PlatformContext} from \"../domain/PlatformContext\";\n\n/**\n * @ignore\n */\nexport function bindEndpointMiddleware(endpoint: EndpointMetadata) {\n return (ctx: PlatformContext) => {\n ctx.endpoint = endpoint;\n };\n}\n"]}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var PlatformRouter_1;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.PlatformRouter = exports.PLATFORM_ROUTER_OPTIONS = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const di_1 = require("@tsed/di");
|
|
7
|
-
const PlatformHandler_1 = require("./PlatformHandler");
|
|
8
|
-
const PlatformAdapter_1 = require("./PlatformAdapter");
|
|
9
|
-
/**
|
|
10
|
-
* @ignore
|
|
11
|
-
*/
|
|
12
|
-
exports.PLATFORM_ROUTER_OPTIONS = Symbol.for("PlatformRouterOptions");
|
|
13
|
-
/**
|
|
14
|
-
* Platform Router abstraction layer.
|
|
15
|
-
* @platform
|
|
16
|
-
*/
|
|
17
|
-
let PlatformRouter = PlatformRouter_1 = class PlatformRouter {
|
|
18
|
-
constructor(platformHandler, adapter, routerOptions = {}) {
|
|
19
|
-
this.platformHandler = platformHandler;
|
|
20
|
-
this.adapter = adapter;
|
|
21
|
-
this.isBuilt = false;
|
|
22
|
-
const { router, callback } = adapter.router(routerOptions);
|
|
23
|
-
this.rawRouter = this.raw = router;
|
|
24
|
-
this.callback = callback;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Create a new instance of PlatformRouter
|
|
28
|
-
* @param injector
|
|
29
|
-
* @param routerOptions
|
|
30
|
-
*/
|
|
31
|
-
static create(injector, routerOptions = {}) {
|
|
32
|
-
const locals = new Map();
|
|
33
|
-
locals.set(exports.PLATFORM_ROUTER_OPTIONS, routerOptions);
|
|
34
|
-
return injector.invoke(PlatformRouter_1, locals);
|
|
35
|
-
}
|
|
36
|
-
getRouter() {
|
|
37
|
-
return this.rawRouter;
|
|
38
|
-
}
|
|
39
|
-
use(...handlers) {
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
this.getRouter().use(...this.mapHandlers(handlers));
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
addRoute(options) {
|
|
45
|
-
const { method, path, handlers, ...opts } = options;
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
this.getRouter()[method](path, ...this.mapHandlers(handlers, { method, path, ...opts }));
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
all(path, ...handlers) {
|
|
51
|
-
return this.addRoute({ method: "all", path, handlers, isFinal: true });
|
|
52
|
-
}
|
|
53
|
-
get(path, ...handlers) {
|
|
54
|
-
return this.addRoute({ method: "get", path, handlers, isFinal: true });
|
|
55
|
-
}
|
|
56
|
-
post(path, ...handlers) {
|
|
57
|
-
return this.addRoute({ method: "post", path, handlers, isFinal: true });
|
|
58
|
-
}
|
|
59
|
-
put(path, ...handlers) {
|
|
60
|
-
return this.addRoute({ method: "put", path, handlers, isFinal: true });
|
|
61
|
-
}
|
|
62
|
-
delete(path, ...handlers) {
|
|
63
|
-
return this.addRoute({ method: "delete", path, handlers, isFinal: true });
|
|
64
|
-
}
|
|
65
|
-
patch(path, ...handlers) {
|
|
66
|
-
return this.addRoute({ method: "patch", path, handlers, isFinal: true });
|
|
67
|
-
}
|
|
68
|
-
head(path, ...handlers) {
|
|
69
|
-
return this.addRoute({ method: "head", path, handlers, isFinal: true });
|
|
70
|
-
}
|
|
71
|
-
options(path, ...handlers) {
|
|
72
|
-
return this.addRoute({ method: "options", path, handlers, isFinal: true });
|
|
73
|
-
}
|
|
74
|
-
statics(path, options) {
|
|
75
|
-
return this.use(path, this.adapter.statics(path, options));
|
|
76
|
-
}
|
|
77
|
-
multer(options) {
|
|
78
|
-
return this.adapter.multipart(options);
|
|
79
|
-
}
|
|
80
|
-
mapHandlers(handlers, options = {}) {
|
|
81
|
-
return handlers.reduce((list, handler, index) => {
|
|
82
|
-
if (typeof handler === "string") {
|
|
83
|
-
return list.concat(handler);
|
|
84
|
-
}
|
|
85
|
-
if (handler instanceof PlatformRouter_1) {
|
|
86
|
-
return list.concat(handler.callback());
|
|
87
|
-
}
|
|
88
|
-
return list.concat(this.platformHandler.createHandler(handler, {
|
|
89
|
-
...options,
|
|
90
|
-
isFinal: options.isFinal ? index === handlers.length - 1 : false
|
|
91
|
-
}));
|
|
92
|
-
}, []);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
tslib_1.__decorate([
|
|
96
|
-
(0, di_1.Inject)(),
|
|
97
|
-
tslib_1.__metadata("design:type", di_1.InjectorService)
|
|
98
|
-
], PlatformRouter.prototype, "injector", void 0);
|
|
99
|
-
PlatformRouter = PlatformRouter_1 = tslib_1.__decorate([
|
|
100
|
-
(0, di_1.Injectable)({
|
|
101
|
-
scope: di_1.ProviderScope.INSTANCE
|
|
102
|
-
}),
|
|
103
|
-
tslib_1.__param(2, (0, di_1.Inject)(exports.PLATFORM_ROUTER_OPTIONS)),
|
|
104
|
-
tslib_1.__metadata("design:paramtypes", [PlatformHandler_1.PlatformHandler,
|
|
105
|
-
PlatformAdapter_1.PlatformAdapter, Object])
|
|
106
|
-
], PlatformRouter);
|
|
107
|
-
exports.PlatformRouter = PlatformRouter;
|
|
108
|
-
//# sourceMappingURL=PlatformRouter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformRouter.js","sourceRoot":"","sources":["../../../src/services/PlatformRouter.ts"],"names":[],"mappings":";;;;;AAAA,iCAAsF;AACtF,uDAAkD;AAIlD,uDAAkD;AAGlD;;GAEG;AACU,QAAA,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAS3E;;;GAGG;AAIH,IAAa,cAAc,sBAA3B,MAAa,cAAc;IAUzB,YACY,eAAgC,EACjC,OAAqC,EACb,gBAAwC,EAAE;QAFjE,oBAAe,GAAf,eAAe,CAAiB;QACjC,YAAO,GAAP,OAAO,CAA8B;QAThD,YAAO,GAAY,KAAK,CAAC;QAYvB,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,GAAG,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QAEzD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,QAAyB,EAAE,gBAAqB,EAAE;QAC9D,MAAM,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,CAAC,+BAAuB,EAAE,aAAa,CAAC,CAAC;QAEnD,OAAO,QAAQ,CAAC,MAAM,CAAiB,gBAAc,EAAE,MAAM,CAAC,CAAC;IACjE,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,GAAG,CAAC,GAAG,QAAe;QACpB,aAAa;QACb,IAAI,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,WAAW,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,EAAE,CAAC,CAAC;aACxC;YAED,OAAO,IAAI,CAAC,MAAM,CAChB,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,OAAO,EAAE;gBAC1C,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK;aACjE,CAAC,CACH,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AAzGC;IADC,IAAA,WAAM,GAAE;sCACC,oBAAe;gDAAC;AANf,cAAc;IAH1B,IAAA,eAAU,EAAC;QACV,KAAK,EAAE,kBAAa,CAAC,QAAQ;KAC9B,CAAC;IAcG,mBAAA,IAAA,WAAM,EAAC,+BAAuB,CAAC,CAAA;6CAFL,iCAAe;QACxB,iCAAe;GAZxB,cAAc,CA+G1B;AA/GY,wCAAc","sourcesContent":["import {Inject, Injectable, InjectorService, PathType, ProviderScope} from \"@tsed/di\";\nimport {PlatformHandler} from \"./PlatformHandler\";\nimport {PlatformRouteOptions, PlatformRouteWithoutHandlers} from \"../interfaces/PlatformRouteOptions\";\nimport {PlatformStaticsOptions} from \"../config/interfaces/PlatformStaticsSettings\";\nimport {PlatformMulter, PlatformMulterSettings} from \"../config/interfaces/PlatformMulterSettings\";\nimport {PlatformAdapter} from \"./PlatformAdapter\";\nimport {RouterOptions} from \"express\";\n\n/**\n * @ignore\n */\nexport const PLATFORM_ROUTER_OPTIONS = Symbol.for(\"PlatformRouterOptions\");\n\ndeclare global {\n namespace TsED {\n // @ts-ignore\n export interface Router {}\n }\n}\n\n/**\n * Platform Router abstraction layer.\n * @platform\n */\n@Injectable({\n scope: ProviderScope.INSTANCE\n})\nexport class PlatformRouter<App = TsED.Application, Router = TsED.Router> {\n rawRouter: Router;\n raw: any;\n isBuilt: boolean = false;\n\n @Inject()\n injector: InjectorService;\n\n callback: () => any;\n\n constructor(\n protected platformHandler: PlatformHandler,\n readonly adapter: PlatformAdapter<App, Router>,\n @Inject(PLATFORM_ROUTER_OPTIONS) routerOptions: Partial<RouterOptions> = {}\n ) {\n const {router, callback} = adapter.router(routerOptions);\n\n this.rawRouter = this.raw = router;\n this.callback = callback;\n }\n\n /**\n * Create a new instance of PlatformRouter\n * @param injector\n * @param routerOptions\n */\n static create(injector: InjectorService, routerOptions: any = {}) {\n const locals = new Map();\n locals.set(PLATFORM_ROUTER_OPTIONS, routerOptions);\n\n return injector.invoke<PlatformRouter>(PlatformRouter, locals);\n }\n\n getRouter(): Router {\n return this.rawRouter;\n }\n\n use(...handlers: any[]) {\n // @ts-ignore\n this.getRouter().use(...this.mapHandlers(handlers));\n\n return this;\n }\n\n addRoute(options: Partial<PlatformRouteOptions>) {\n const {method, path, handlers, ...opts} = options;\n\n // @ts-ignore\n this.getRouter()[method](path, ...this.mapHandlers(handlers, {method, path, ...opts}));\n\n return this;\n }\n\n all(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"all\", path, handlers, isFinal: true});\n }\n\n get(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"get\", path, handlers, isFinal: true});\n }\n\n post(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"post\", path, handlers, isFinal: true});\n }\n\n put(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"put\", path, handlers, isFinal: true});\n }\n\n delete(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"delete\", path, handlers, isFinal: true});\n }\n\n patch(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"patch\", path, handlers, isFinal: true});\n }\n\n head(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"head\", path, handlers, isFinal: true});\n }\n\n options(path: PathType, ...handlers: any[]) {\n return this.addRoute({method: \"options\", path, handlers, isFinal: true});\n }\n\n statics(path: string, options: PlatformStaticsOptions) {\n return this.use(path, this.adapter.statics(path, options));\n }\n\n multer(options: PlatformMulterSettings): PlatformMulter {\n return this.adapter.multipart(options);\n }\n\n protected mapHandlers(handlers: any[], options: PlatformRouteWithoutHandlers = {}): any[] {\n return handlers.reduce((list, handler, index) => {\n if (typeof handler === \"string\") {\n return list.concat(handler);\n }\n\n if (handler instanceof PlatformRouter) {\n return list.concat(handler.callback());\n }\n\n return list.concat(\n this.platformHandler.createHandler(handler, {\n ...options,\n isFinal: options.isFinal ? index === handlers.length - 1 : false\n })\n );\n }, []);\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Test1.js","sourceRoot":"","sources":["../../../../src/utils/__mock__/Test1.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAG,OAAO,CAAC;AAE9B,MAAa,KAAK;CAAG;AAArB,sBAAqB","sourcesContent":["export const value1 = \"value\";\n\nexport class Test1 {}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Test2.js","sourceRoot":"","sources":["../../../../src/utils/__mock__/Test2.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAG,OAAO,CAAC;AAE9B,MAAa,KAAK;CAAG;AAArB,sBAAqB","sourcesContent":["export const value2 = \"value\";\n\nexport class Test2 {}\n"]}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createHandlerMetadata = void 0;
|
|
4
|
-
const schema_1 = require("@tsed/schema");
|
|
5
|
-
const HandlerMetadata_1 = require("../domain/HandlerMetadata");
|
|
6
|
-
const HandlerType_1 = require("../interfaces/HandlerType");
|
|
7
|
-
function isMetadata(input) {
|
|
8
|
-
return input instanceof HandlerMetadata_1.HandlerMetadata;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* @ignore
|
|
12
|
-
*/
|
|
13
|
-
function createHandlerMetadata(injector, obj, routeOptions = {}) {
|
|
14
|
-
if (isMetadata(obj)) {
|
|
15
|
-
return obj;
|
|
16
|
-
}
|
|
17
|
-
let options;
|
|
18
|
-
if (obj instanceof schema_1.EndpointMetadata) {
|
|
19
|
-
const provider = injector.getProvider(routeOptions.token);
|
|
20
|
-
options = {
|
|
21
|
-
token: provider.token,
|
|
22
|
-
target: provider.useClass,
|
|
23
|
-
scope: provider.scope,
|
|
24
|
-
type: HandlerType_1.HandlerType.ENDPOINT,
|
|
25
|
-
propertyKey: obj.propertyKey
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
const provider = injector.getProvider(obj);
|
|
30
|
-
if (provider) {
|
|
31
|
-
options = {
|
|
32
|
-
token: provider.token,
|
|
33
|
-
target: provider.useClass,
|
|
34
|
-
scope: provider.scope,
|
|
35
|
-
type: HandlerType_1.HandlerType.MIDDLEWARE,
|
|
36
|
-
propertyKey: "use"
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
options = {
|
|
41
|
-
target: obj
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
options.routeOptions = routeOptions;
|
|
46
|
-
return new HandlerMetadata_1.HandlerMetadata(options);
|
|
47
|
-
}
|
|
48
|
-
exports.createHandlerMetadata = createHandlerMetadata;
|
|
49
|
-
//# sourceMappingURL=createHandlerMetadata.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHandlerMetadata.js","sourceRoot":"","sources":["../../../src/utils/createHandlerMetadata.ts"],"names":[],"mappings":";;;AACA,yCAA8C;AAC9C,+DAAkF;AAClF,2DAAsD;AAGtD,SAAS,UAAU,CAAC,KAAU;IAC5B,OAAO,KAAK,YAAY,iCAAe,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CACnC,QAAyB,EACzB,GAA2B,EAC3B,eAA6C,EAAE;IAE/C,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE;QACnB,OAAO,GAAsB,CAAC;KAC/B;IAED,IAAI,OAA+B,CAAC;IAEpC,IAAI,GAAG,YAAY,yBAAgB,EAAE;QACnC,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAE,CAAC;QAE3D,OAAO,GAAG;YACR,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,MAAM,EAAE,QAAQ,CAAC,QAAQ;YACzB,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,IAAI,EAAE,yBAAW,CAAC,QAAQ;YAC1B,WAAW,EAAE,GAAG,CAAC,WAAW;SAC7B,CAAC;KACH;SAAM;QACL,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAE3C,IAAI,QAAQ,EAAE;YACZ,OAAO,GAAG;gBACR,KAAK,EAAE,QAAQ,CAAC,KAAK;gBACrB,MAAM,EAAE,QAAQ,CAAC,QAAQ;gBACzB,KAAK,EAAE,QAAQ,CAAC,KAAK;gBACrB,IAAI,EAAE,yBAAW,CAAC,UAAU;gBAC5B,WAAW,EAAE,KAAK;aACnB,CAAC;SACH;aAAM;YACL,OAAO,GAAG;gBACR,MAAM,EAAE,GAAG;aACZ,CAAC;SACH;KACF;IAED,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC;IAEpC,OAAO,IAAI,iCAAe,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AA1CD,sDA0CC","sourcesContent":["import {InjectorService} from \"@tsed/di\";\nimport {EndpointMetadata} from \"@tsed/schema\";\nimport {HandlerMetadata, HandlerMetadataOptions} from \"../domain/HandlerMetadata\";\nimport {HandlerType} from \"../interfaces/HandlerType\";\nimport {PlatformRouteWithoutHandlers} from \"../interfaces/PlatformRouteOptions\";\n\nfunction isMetadata(input: any) {\n return input instanceof HandlerMetadata;\n}\n\n/**\n * @ignore\n */\nexport function createHandlerMetadata(\n injector: InjectorService,\n obj: any | EndpointMetadata,\n routeOptions: PlatformRouteWithoutHandlers = {}\n): HandlerMetadata {\n if (isMetadata(obj)) {\n return obj as HandlerMetadata;\n }\n\n let options: HandlerMetadataOptions;\n\n if (obj instanceof EndpointMetadata) {\n const provider = injector.getProvider(routeOptions.token)!;\n\n options = {\n token: provider.token,\n target: provider.useClass,\n scope: provider.scope,\n type: HandlerType.ENDPOINT,\n propertyKey: obj.propertyKey\n };\n } else {\n const provider = injector.getProvider(obj);\n\n if (provider) {\n options = {\n token: provider.token,\n target: provider.useClass,\n scope: provider.scope,\n type: HandlerType.MIDDLEWARE,\n propertyKey: \"use\"\n };\n } else {\n options = {\n target: obj\n };\n }\n }\n\n options.routeOptions = routeOptions;\n\n return new HandlerMetadata(options);\n}\n"]}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.importProviders = void 0;
|
|
4
|
-
const di_1 = require("@tsed/di");
|
|
5
|
-
const components_scan_1 = require("@tsed/components-scan");
|
|
6
|
-
async function recursiveImports(providers, settings, properties) {
|
|
7
|
-
const { exclude = [] } = settings;
|
|
8
|
-
const promises = providers
|
|
9
|
-
.map(({ token }) => di_1.GlobalProviders.get(token))
|
|
10
|
-
.filter((provider) => (provider === null || provider === void 0 ? void 0 : provider.type) === di_1.ProviderType.MODULE && provider.configuration)
|
|
11
|
-
.map((provider) => importProviders({ exclude, ...provider.configuration }, properties));
|
|
12
|
-
return (await Promise.all(promises)).flat();
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Import providers from given patterns.
|
|
16
|
-
*
|
|
17
|
-
* @param settings
|
|
18
|
-
* @param properties
|
|
19
|
-
*/
|
|
20
|
-
async function importProviders(settings, properties = ["imports"]) {
|
|
21
|
-
const { exclude = [] } = settings;
|
|
22
|
-
const disableComponentsScan = settings.disableComponentsScan || !!process.env.WEBPACK;
|
|
23
|
-
const promises = properties.map((key) => (0, components_scan_1.importComponents)(settings[key], exclude, disableComponentsScan));
|
|
24
|
-
const providers = (await Promise.all(promises)).flat();
|
|
25
|
-
const children = await recursiveImports(providers, settings, properties);
|
|
26
|
-
return [...children, ...providers];
|
|
27
|
-
}
|
|
28
|
-
exports.importProviders = importProviders;
|
|
29
|
-
//# sourceMappingURL=importProviders.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"importProviders.js","sourceRoot":"","sources":["../../../src/utils/importProviders.ts"],"names":[],"mappings":";;;AAAA,iCAAiE;AACjE,2DAAuD;AAEvD,KAAK,UAAU,gBAAgB,CAAC,SAA4C,EAAE,QAAqC,EAAE,UAAoB;IACvI,MAAM,EAAC,OAAO,GAAG,EAAE,EAAC,GAAG,QAAQ,CAAC;IAEhC,MAAM,QAAQ,GAAG,SAAS;SACvB,GAAG,CAAC,CAAC,EAAC,KAAK,EAAC,EAAE,EAAE,CAAC,oBAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC5C,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,MAAK,iBAAY,CAAC,MAAM,IAAI,QAAQ,CAAC,aAAa,CAAC;SACtF,GAAG,CAAC,CAAC,QAAkB,EAAE,EAAE,CAAC,eAAe,CAAC,EAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,aAAa,EAAC,EAAE,UAAU,CAAC,CAAC,CAAC;IAElG,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC9C,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,eAAe,CACnC,QAAqC,EACrC,aAAuB,CAAC,SAAS,CAAC;IAElC,MAAM,EAAC,OAAO,GAAG,EAAE,EAAC,GAAG,QAAQ,CAAC;IAChC,MAAM,qBAAqB,GAAG,QAAQ,CAAC,qBAAqB,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IAEtF,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,kCAAgB,EAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,qBAAqB,CAAC,CAAC,CAAC;IAC1G,MAAM,SAAS,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACvD,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IAEzE,OAAO,CAAC,GAAG,QAAQ,EAAE,GAAG,SAAS,CAAC,CAAC;AACrC,CAAC;AAZD,0CAYC","sourcesContent":["import {GlobalProviders, Provider, ProviderType} from \"@tsed/di\";\nimport {importComponents} from \"@tsed/components-scan\";\n\nasync function recursiveImports(providers: {token: string; route?: string}[], settings: Partial<TsED.Configuration>, properties: string[]) {\n const {exclude = []} = settings;\n\n const promises = providers\n .map(({token}) => GlobalProviders.get(token))\n .filter((provider) => provider?.type === ProviderType.MODULE && provider.configuration)\n .map((provider: Provider) => importProviders({exclude, ...provider.configuration}, properties));\n\n return (await Promise.all(promises)).flat();\n}\n\n/**\n * Import providers from given patterns.\n *\n * @param settings\n * @param properties\n */\nexport async function importProviders(\n settings: Partial<TsED.Configuration>,\n properties: string[] = [\"imports\"]\n): Promise<{token: string; route?: string}[]> {\n const {exclude = []} = settings;\n const disableComponentsScan = settings.disableComponentsScan || !!process.env.WEBPACK;\n\n const promises = properties.map((key) => importComponents(settings[key], exclude, disableComponentsScan));\n const providers = (await Promise.all(promises)).flat();\n const children = await recursiveImports(providers, settings, properties);\n\n return [...children, ...providers];\n}\n"]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useCtxHandler = void 0;
|
|
4
|
-
const HandlerType_1 = require("../interfaces/HandlerType");
|
|
5
|
-
/**
|
|
6
|
-
* Create Ts.ED context handler
|
|
7
|
-
* @param fn
|
|
8
|
-
* @ignore
|
|
9
|
-
*/
|
|
10
|
-
function useCtxHandler(fn) {
|
|
11
|
-
fn.type = HandlerType_1.HandlerType.CTX_FN;
|
|
12
|
-
return fn;
|
|
13
|
-
}
|
|
14
|
-
exports.useCtxHandler = useCtxHandler;
|
|
15
|
-
//# sourceMappingURL=useCtxHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCtxHandler.js","sourceRoot":"","sources":["../../../src/utils/useCtxHandler.ts"],"names":[],"mappings":";;;AACA,2DAAsD;AAItD;;;;GAIG;AACH,SAAgB,aAAa,CAAC,EAA6C;IACzE,EAAE,CAAC,IAAI,GAAG,yBAAW,CAAC,MAAM,CAAC;IAE7B,OAAO,EAAE,CAAC;AACZ,CAAC;AAJD,sCAIC","sourcesContent":["import {PlatformContext} from \"../domain/PlatformContext\";\nimport {HandlerType} from \"../interfaces/HandlerType\";\n\nexport type PlatformCtxHandler = ($ctx: PlatformContext) => any | Promise<any>;\n\n/**\n * Create Ts.ED context handler\n * @param fn\n * @ignore\n */\nexport function useCtxHandler(fn: PlatformCtxHandler & {type?: HandlerType}) {\n fn.type = HandlerType.CTX_FN;\n\n return fn;\n}\n"]}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { GlobalProviders, ProviderType } from "@tsed/di";
|
|
2
|
-
import { getOperationsRoutes, OperationMethods } from "@tsed/schema";
|
|
3
|
-
import { ControllerProvider } from "../domain/ControllerProvider.js";
|
|
4
|
-
import { PlatformRouter } from "../services/PlatformRouter.js";
|
|
5
|
-
import { PlatformMiddlewaresChain } from "../services/PlatformMiddlewaresChain.js";
|
|
6
|
-
GlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {
|
|
7
|
-
onInvoke(provider, locals, { injector }) {
|
|
8
|
-
const router = createRouter(injector, provider);
|
|
9
|
-
locals.set(PlatformRouter, router);
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
/**
|
|
13
|
-
* @ignore
|
|
14
|
-
*/
|
|
15
|
-
function formatMethod(method) {
|
|
16
|
-
return (method === OperationMethods.CUSTOM ? "use" : method || "use").toLowerCase();
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* @ignore
|
|
20
|
-
*/
|
|
21
|
-
export function getRouter(injector, provider) {
|
|
22
|
-
return injector.get(provider.tokenRouter);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @ignore
|
|
26
|
-
*/
|
|
27
|
-
export function createRouter(injector, provider) {
|
|
28
|
-
const token = provider.tokenRouter;
|
|
29
|
-
if (injector.has(token)) {
|
|
30
|
-
return getRouter(injector, provider);
|
|
31
|
-
}
|
|
32
|
-
const router = PlatformRouter.create(injector, provider.routerOptions);
|
|
33
|
-
return injector
|
|
34
|
-
.add(token, {
|
|
35
|
-
useValue: router
|
|
36
|
-
})
|
|
37
|
-
.invoke(token);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* @ignore
|
|
41
|
-
* @param injector
|
|
42
|
-
* @param provider
|
|
43
|
-
* @param parentUseBefore
|
|
44
|
-
*/
|
|
45
|
-
export function buildRouter(injector, provider, parentUseBefore = []) {
|
|
46
|
-
const { middlewares: { useBefore }, children } = provider;
|
|
47
|
-
// Controller lifecycle
|
|
48
|
-
const router = createRouter(injector, provider);
|
|
49
|
-
if (!router.isBuilt) {
|
|
50
|
-
router.isBuilt = true;
|
|
51
|
-
const platformMiddlewaresChain = injector.get(PlatformMiddlewaresChain);
|
|
52
|
-
// build all endpoints and his middlewares
|
|
53
|
-
getOperationsRoutes(provider.token).forEach((operationRoute) => {
|
|
54
|
-
const handlers = platformMiddlewaresChain === null || platformMiddlewaresChain === void 0 ? void 0 : platformMiddlewaresChain.get(provider, operationRoute, parentUseBefore);
|
|
55
|
-
router.addRoute({
|
|
56
|
-
handlers,
|
|
57
|
-
token: operationRoute.token,
|
|
58
|
-
method: formatMethod(operationRoute.method),
|
|
59
|
-
path: operationRoute.path,
|
|
60
|
-
isFinal: operationRoute.isFinal
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
const middlewares = [...parentUseBefore, ...useBefore];
|
|
64
|
-
// build children controllers
|
|
65
|
-
children.forEach((child) => {
|
|
66
|
-
const childProvider = injector.getProvider(child);
|
|
67
|
-
/* istanbul ignore next */
|
|
68
|
-
if (!childProvider) {
|
|
69
|
-
throw new Error("Controller component not found in the ControllerRegistry");
|
|
70
|
-
}
|
|
71
|
-
router.use(childProvider.path, buildRouter(injector, childProvider, middlewares));
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return router;
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=PlatformControllerBuilder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformControllerBuilder.js","sourceRoot":"","sources":["../../../src/builder/PlatformControllerBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAmB,YAAY,EAAC,MAAM,UAAU,CAAC;AACxE,OAAO,EAAC,mBAAmB,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnE,OAAO,EAAC,kBAAkB,EAAC,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAC,wBAAwB,EAAC,MAAM,sCAAsC,CAAC;AAE9E,eAAe,CAAC,cAAc,CAAC,YAAY,CAAC,UAAU,EAAE,kBAAkB,EAAE;IAC1E,QAAQ,CAAC,QAA4B,EAAE,MAAW,EAAE,EAAC,QAAQ,EAAC;QAC5D,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAChD,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;CACF,CAAC,CAAC;AAEH;;GAEG;AACH,SAAS,YAAY,CAAC,MAA0B;IAC9C,OAAO,CAAC,MAAM,KAAK,gBAAgB,CAAC,MAAM,C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,QAAQ,GAAG,wBAAwB,aAAxB,wBAAwB,uBAAxB,wBAAwB,CAAE,GAAG,CAAC,QAAQ,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;YAE1F,MAAM,CAAC,QAAQ,CAAC;gBACd,QAAQ;gBACR,KAAK,EAAE,cAAc,CAAC,KAAK;gBAC3B,MAAM,EAAE,YAAY,CAAC,cAAc,CAAC,MAAM,CAAC;gBAC3C,IAAI,EAAE,cAAc,CAAC,IAAI;gBACzB,OAAO,EAAE,cAAc,CAAC,OAAO;aAChC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,WAAW,GAAU,CAAC,GAAG,eAAe,EAAE,GAAG,SAAS,CAAC,CAAC;QAC9D,6BAA6B;QAC7B,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAgB,EAAE,EAAE;YACpC,MAAM,aAAa,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAuB,CAAC;YAExE,0BAA0B;YAC1B,IAAI,CAAC,aAAa,EAAE;gBAClB,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;aAC7E;YAED,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC;QACpF,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {GlobalProviders, InjectorService, ProviderType} from \"@tsed/di\";\nimport {getOperationsRoutes, OperationMethods} from \"@tsed/schema\";\nimport {ControllerProvider} from \"../domain/ControllerProvider\";\nimport {PlatformRouter} from \"../services/PlatformRouter\";\nimport {PlatformMiddlewaresChain} from \"../services/PlatformMiddlewaresChain\";\n\nGlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {\n onInvoke(provider: ControllerProvider, locals: any, {injector}) {\n const router = createRouter(injector, provider);\n locals.set(PlatformRouter, router);\n }\n});\n\n/**\n * @ignore\n */\nfunction formatMethod(method: string | undefined) {\n return (method === OperationMethods.CUSTOM ? \"use\" : method || \"use\").toLowerCase();\n}\n\n/**\n * @ignore\n */\nexport function getRouter(injector: InjectorService, provider: ControllerProvider) {\n return injector.get(provider.tokenRouter)!;\n}\n\n/**\n * @ignore\n */\nexport function createRouter(injector: InjectorService, provider: ControllerProvider): PlatformRouter {\n const token = provider.tokenRouter;\n\n if (injector.has(token)) {\n return getRouter(injector, provider);\n }\n\n const router = PlatformRouter.create(injector, provider.routerOptions);\n\n return injector\n .add(token, {\n useValue: router\n })\n .invoke<PlatformRouter>(token);\n}\n\n/**\n * @ignore\n * @param injector\n * @param provider\n * @param parentUseBefore\n */\nexport function buildRouter(injector: InjectorService, provider: ControllerProvider, parentUseBefore: any[] = []) {\n const {\n middlewares: {useBefore},\n children\n } = provider;\n\n // Controller lifecycle\n const router = createRouter(injector, provider);\n\n if (!router.isBuilt) {\n router.isBuilt = true;\n\n const platformMiddlewaresChain = injector.get<PlatformMiddlewaresChain>(PlatformMiddlewaresChain);\n\n // build all endpoints and his middlewares\n getOperationsRoutes(provider.token).forEach((operationRoute) => {\n const handlers = platformMiddlewaresChain?.get(provider, operationRoute, parentUseBefore);\n\n router.addRoute({\n handlers,\n token: operationRoute.token,\n method: formatMethod(operationRoute.method),\n path: operationRoute.path,\n isFinal: operationRoute.isFinal\n });\n });\n\n const middlewares: any[] = [...parentUseBefore, ...useBefore];\n // build children controllers\n children.forEach((child: Type<any>) => {\n const childProvider = injector.getProvider(child) as ControllerProvider;\n\n /* istanbul ignore next */\n if (!childProvider) {\n throw new Error(\"Controller component not found in the ControllerRegistry\");\n }\n\n router.use(childProvider.path, buildRouter(injector, childProvider, middlewares));\n });\n }\n\n return router;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EndpointDirectoriesSettings.js","sourceRoot":"","sources":["../../../../src/config/interfaces/EndpointDirectoriesSettings.ts"],"names":[],"mappings":"","sourcesContent":["export interface EndpointDirectoriesSettings {\n [endpoint: string]: any | string | (any | string)[];\n}\n"]}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Provider, ProviderType } from "@tsed/di";
|
|
2
|
-
import { ROUTER_OPTIONS } from "../constants/routerOptions.js";
|
|
3
|
-
let AUTO_INC = 0;
|
|
4
|
-
export class ControllerProvider extends Provider {
|
|
5
|
-
constructor(provide, options = {}) {
|
|
6
|
-
super(provide, options);
|
|
7
|
-
this.type = ProviderType.CONTROLLER;
|
|
8
|
-
this.tokenRouter = `${this.name}_ROUTER_${AUTO_INC++}`;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
get routerOptions() {
|
|
14
|
-
return this.store.get(ROUTER_OPTIONS) || {};
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param value
|
|
19
|
-
*/
|
|
20
|
-
set routerOptions(value) {
|
|
21
|
-
this.store.set(ROUTER_OPTIONS, value);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* @returns {any[]}
|
|
26
|
-
*/
|
|
27
|
-
get middlewares() {
|
|
28
|
-
return Object.assign({
|
|
29
|
-
use: [],
|
|
30
|
-
useAfter: [],
|
|
31
|
-
useBefore: []
|
|
32
|
-
}, this.store.get("middlewares", {}));
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
* @param middlewares
|
|
37
|
-
*/
|
|
38
|
-
set middlewares(middlewares) {
|
|
39
|
-
const mdlwrs = this.middlewares;
|
|
40
|
-
const concat = (key, a, b) => (a[key] = a[key].concat(b[key]));
|
|
41
|
-
Object.keys(middlewares).forEach((key) => {
|
|
42
|
-
concat(key, mdlwrs, middlewares);
|
|
43
|
-
});
|
|
44
|
-
this.store.set("middlewares", mdlwrs);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=ControllerProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ControllerProvider.js","sourceRoot":"","sources":["../../../src/domain/ControllerProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,QAAQ,EAAE,YAAY,EAAgB,MAAM,UAAU,CAAC;AACtF,OAAO,EAAC,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAE1D,IAAI,QAAQ,GAAG,CAAC,CAAC;AAEjB,MAAM,OAAO,kBAA4B,SAAQ,QAAW;IAG1D,YAAY,OAAsB,EAAE,UAA6B,EAAE;QACjE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,WAAW,GAAG,GAAG,IAAI,CAAC,IAAI,WAAW,QAAQ,EAAE,EAAE,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,IAAK,EAAU,CAAC;IACvD,CAAC;IAED;;;OAGG;IACH,IAAI,aAAa,CAAC,KAAU;QAC1B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,IAAI,WAAW;QACb,OAAO,MAAM,CAAC,MAAM,CAClB;YACE,GAAG,EAAE,EAAE;YACP,QAAQ,EAAE,EAAE;YACZ,SAAS,EAAE,EAAE;SACd,EACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE,EAAE,CAAC,CAClC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,IAAI,WAAW,CAAC,WAAkC;QAChD,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC;QAChC,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,CAAM,EAAE,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAEjF,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;YAC/C,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import {ControllerMiddlewares, Provider, ProviderType, TokenProvider} from \"@tsed/di\";\nimport {ROUTER_OPTIONS} from \"../constants/routerOptions\";\n\nlet AUTO_INC = 0;\n\nexport class ControllerProvider<T = any> extends Provider<T> {\n readonly tokenRouter: string;\n\n constructor(provide: TokenProvider, options: Partial<Provider> = {}) {\n super(provide, options);\n this.type = ProviderType.CONTROLLER;\n this.tokenRouter = `${this.name}_ROUTER_${AUTO_INC++}`;\n }\n\n /**\n *\n */\n get routerOptions(): any {\n return this.store.get(ROUTER_OPTIONS) || ({} as any);\n }\n\n /**\n *\n * @param value\n */\n set routerOptions(value: any) {\n this.store.set(ROUTER_OPTIONS, value);\n }\n\n /**\n *\n * @returns {any[]}\n */\n get middlewares(): ControllerMiddlewares {\n return Object.assign(\n {\n use: [],\n useAfter: [],\n useBefore: []\n },\n this.store.get(\"middlewares\", {})\n );\n }\n\n /**\n *\n * @param middlewares\n */\n set middlewares(middlewares: ControllerMiddlewares) {\n const mdlwrs = this.middlewares;\n const concat = (key: string, a: any, b: any) => (a[key] = a[key].concat(b[key]));\n\n Object.keys(middlewares).forEach((key: string) => {\n concat(key, mdlwrs, middlewares);\n });\n this.store.set(\"middlewares\", mdlwrs);\n }\n}\n"]}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { nameOf } from "@tsed/core";
|
|
2
|
-
import { ProviderScope } from "@tsed/di";
|
|
3
|
-
import { ParamTypes } from "@tsed/platform-params";
|
|
4
|
-
import { JsonParameterStore } from "@tsed/schema";
|
|
5
|
-
import { HandlerType } from "../interfaces/HandlerType.js";
|
|
6
|
-
export class HandlerMetadata {
|
|
7
|
-
constructor(options) {
|
|
8
|
-
this.injectable = false;
|
|
9
|
-
this.type = HandlerType.RAW_FN;
|
|
10
|
-
this.hasNextFunction = false;
|
|
11
|
-
const { target, token, propertyKey, type, scope, routeOptions } = options;
|
|
12
|
-
this.type = type || target.type || HandlerType.RAW_FN;
|
|
13
|
-
this.scope = scope || ProviderScope.SINGLETON;
|
|
14
|
-
this.routeOptions = routeOptions || {};
|
|
15
|
-
const handler = propertyKey ? target.prototype[propertyKey] : target;
|
|
16
|
-
if (propertyKey) {
|
|
17
|
-
this.target = target;
|
|
18
|
-
this.token = token;
|
|
19
|
-
this.propertyKey = propertyKey;
|
|
20
|
-
this.hasNextFunction = this.hasParamType(ParamTypes.NEXT_FN);
|
|
21
|
-
if (this.hasParamType(ParamTypes.ERR)) {
|
|
22
|
-
this.type = HandlerType.ERR_MIDDLEWARE;
|
|
23
|
-
}
|
|
24
|
-
this.injectable = JsonParameterStore.getParams(target, propertyKey).length > 0;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
this.handler = handler;
|
|
28
|
-
}
|
|
29
|
-
if (!this.injectable) {
|
|
30
|
-
if (handler.length === 4) {
|
|
31
|
-
this.type = HandlerType.RAW_ERR_FN;
|
|
32
|
-
}
|
|
33
|
-
this.hasNextFunction = handler.length >= 3;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
get hasErrorParam() {
|
|
37
|
-
return this.type === HandlerType.ERR_MIDDLEWARE || this.type === HandlerType.RAW_ERR_FN;
|
|
38
|
-
}
|
|
39
|
-
getParams() {
|
|
40
|
-
return JsonParameterStore.getParams(this.target, this.propertyKey) || [];
|
|
41
|
-
}
|
|
42
|
-
hasParamType(paramType) {
|
|
43
|
-
return this.getParams().findIndex((p) => p.paramType === paramType) > -1;
|
|
44
|
-
}
|
|
45
|
-
isFinal() {
|
|
46
|
-
var _a;
|
|
47
|
-
return ((_a = this.routeOptions) === null || _a === void 0 ? void 0 : _a.isFinal) || false;
|
|
48
|
-
}
|
|
49
|
-
toString() {
|
|
50
|
-
return [this.target && nameOf(this.target), this.propertyKey].filter(Boolean).join(".");
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
//# sourceMappingURL=HandlerMetadata.js.map
|