@tsed/di 7.0.0-alpha.2 → 7.0.0-beta.11
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/constants/constants.js +7 -0
- package/lib/cjs/constants/constants.js.map +1 -0
- package/lib/cjs/decorators/configuration.js +24 -0
- package/lib/cjs/decorators/configuration.js.map +1 -0
- package/lib/cjs/decorators/constant.js +55 -0
- package/lib/cjs/decorators/constant.js.map +1 -0
- package/lib/cjs/decorators/controller.js +53 -0
- package/lib/cjs/decorators/controller.js.map +1 -0
- package/lib/cjs/decorators/inject.js +104 -0
- package/lib/cjs/decorators/inject.js.map +1 -0
- package/lib/cjs/decorators/injectable.js +32 -0
- package/lib/cjs/decorators/injectable.js.map +1 -0
- package/lib/cjs/decorators/intercept.js +36 -0
- package/lib/cjs/decorators/intercept.js.map +1 -0
- package/lib/cjs/decorators/interceptor.js +21 -0
- package/lib/cjs/decorators/interceptor.js.map +1 -0
- package/lib/cjs/decorators/lazyInject.js +71 -0
- package/lib/cjs/decorators/lazyInject.js.map +1 -0
- package/lib/cjs/decorators/module.js +32 -0
- package/lib/cjs/decorators/module.js.map +1 -0
- package/lib/cjs/decorators/opts.js +54 -0
- package/lib/cjs/decorators/opts.js.map +1 -0
- package/lib/cjs/decorators/overrideProvider.js +17 -0
- package/lib/cjs/decorators/overrideProvider.js.map +1 -0
- package/lib/cjs/decorators/scope.js +16 -0
- package/lib/cjs/decorators/scope.js.map +1 -0
- package/lib/cjs/decorators/service.js +18 -0
- package/lib/cjs/decorators/service.js.map +1 -0
- package/lib/cjs/decorators/useOpts.js +65 -0
- package/lib/cjs/decorators/useOpts.js.map +1 -0
- package/lib/cjs/decorators/value.js +55 -0
- package/lib/cjs/decorators/value.js.map +1 -0
- package/lib/cjs/domain/Container.js +72 -0
- package/lib/cjs/domain/Container.js.map +1 -0
- package/lib/cjs/domain/ContextLogger.js +85 -0
- package/lib/cjs/domain/ContextLogger.js.map +1 -0
- package/lib/cjs/domain/DIContext.js +45 -0
- package/lib/cjs/domain/DIContext.js.map +1 -0
- package/lib/cjs/domain/InjectablePropertyType.js +12 -0
- package/lib/cjs/domain/InjectablePropertyType.js.map +1 -0
- package/lib/cjs/domain/LocalsContainer.js +55 -0
- package/lib/cjs/domain/LocalsContainer.js.map +1 -0
- package/lib/cjs/domain/Provider.js +122 -0
- package/lib/cjs/domain/Provider.js.map +1 -0
- package/lib/cjs/domain/ProviderScope.js +10 -0
- package/lib/cjs/domain/ProviderScope.js.map +1 -0
- package/lib/cjs/domain/ProviderType.js +15 -0
- package/lib/cjs/domain/ProviderType.js.map +1 -0
- package/lib/cjs/errors/InjectionError.js +58 -0
- package/lib/cjs/errors/InjectionError.js.map +1 -0
- package/lib/cjs/errors/UndefinedTokenError.js +11 -0
- package/lib/cjs/errors/UndefinedTokenError.js.map +1 -0
- package/lib/cjs/index.js +59 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/interfaces/DIConfigurationOptions.js +3 -0
- package/lib/cjs/interfaces/DIConfigurationOptions.js.map +1 -0
- package/lib/cjs/interfaces/DILogger.js +3 -0
- package/lib/cjs/interfaces/DILogger.js.map +1 -0
- package/lib/cjs/interfaces/DIResolver.js +3 -0
- package/lib/cjs/interfaces/DIResolver.js.map +1 -0
- package/lib/cjs/interfaces/InjectableProperties.js +3 -0
- package/lib/cjs/interfaces/InjectableProperties.js.map +1 -0
- package/lib/cjs/interfaces/InterceptorContext.js +3 -0
- package/lib/cjs/interfaces/InterceptorContext.js.map +1 -0
- package/lib/cjs/interfaces/InterceptorMethods.js +3 -0
- package/lib/cjs/interfaces/InterceptorMethods.js.map +1 -0
- package/lib/cjs/interfaces/InvokeOptions.js +3 -0
- package/lib/cjs/interfaces/InvokeOptions.js.map +1 -0
- package/lib/cjs/interfaces/OnDestroy.js +3 -0
- package/lib/cjs/interfaces/OnDestroy.js.map +1 -0
- package/lib/cjs/interfaces/OnInit.js +3 -0
- package/lib/cjs/interfaces/OnInit.js.map +1 -0
- package/lib/cjs/interfaces/ProviderOpts.js +3 -0
- package/lib/cjs/interfaces/ProviderOpts.js.map +1 -0
- package/lib/cjs/interfaces/RegistrySettings.js +3 -0
- package/lib/cjs/interfaces/RegistrySettings.js.map +1 -0
- package/lib/cjs/interfaces/ResolvedInvokeOptions.js +3 -0
- package/lib/cjs/interfaces/ResolvedInvokeOptions.js.map +1 -0
- package/lib/cjs/interfaces/TokenProvider.js +3 -0
- package/lib/cjs/interfaces/TokenProvider.js.map +1 -0
- package/lib/cjs/interfaces/TokenRoute.js +3 -0
- package/lib/cjs/interfaces/TokenRoute.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/registries/GlobalProviders.js +124 -0
- package/lib/cjs/registries/GlobalProviders.js.map +1 -0
- package/lib/cjs/registries/ProviderRegistry.js +86 -0
- package/lib/cjs/registries/ProviderRegistry.js.map +1 -0
- package/lib/cjs/services/DIConfiguration.js +136 -0
- package/lib/cjs/services/DIConfiguration.js.map +1 -0
- package/lib/cjs/services/DILogger.js +13 -0
- package/lib/cjs/services/DILogger.js.map +1 -0
- package/lib/cjs/services/DITest.js +116 -0
- package/lib/cjs/services/DITest.js.map +1 -0
- package/lib/cjs/services/InjectorService.js +589 -0
- package/lib/cjs/services/InjectorService.js.map +1 -0
- package/lib/cjs/utils/colors.js +10 -0
- package/lib/cjs/utils/colors.js.map +1 -0
- package/lib/cjs/utils/createContainer.js +14 -0
- package/lib/cjs/utils/createContainer.js.map +1 -0
- package/lib/cjs/utils/getConfiguration.js +29 -0
- package/lib/cjs/utils/getConfiguration.js.map +1 -0
- package/lib/cjs/utils/resolveControllers.js +47 -0
- package/lib/cjs/utils/resolveControllers.js.map +1 -0
- package/lib/cjs/utils/runInContext.js +19 -0
- package/lib/cjs/utils/runInContext.js.map +1 -0
- package/lib/cjs/utils/setLoggerLevel.js +16 -0
- package/lib/cjs/utils/setLoggerLevel.js.map +1 -0
- package/lib/esm/constants/constants.js +4 -0
- package/lib/esm/constants/constants.js.map +1 -0
- package/lib/esm/decorators/configuration.js +20 -0
- package/lib/esm/decorators/configuration.js.map +1 -0
- package/lib/esm/decorators/constant.js +51 -0
- package/lib/esm/decorators/constant.js.map +1 -0
- package/lib/esm/decorators/controller.js +49 -0
- package/lib/esm/decorators/controller.js.map +1 -0
- package/lib/esm/decorators/inject.js +98 -0
- package/lib/esm/decorators/inject.js.map +1 -0
- package/lib/esm/decorators/injectable.js +28 -0
- package/lib/esm/decorators/injectable.js.map +1 -0
- package/lib/esm/decorators/intercept.js +32 -0
- package/lib/esm/decorators/intercept.js.map +1 -0
- package/lib/esm/decorators/interceptor.js +17 -0
- package/lib/esm/decorators/interceptor.js.map +1 -0
- package/lib/esm/decorators/lazyInject.js +66 -0
- package/lib/esm/decorators/lazyInject.js.map +1 -0
- package/lib/esm/decorators/module.js +28 -0
- package/lib/esm/decorators/module.js.map +1 -0
- package/lib/esm/decorators/opts.js +50 -0
- package/lib/esm/decorators/opts.js.map +1 -0
- package/lib/esm/decorators/overrideProvider.js +13 -0
- package/lib/esm/decorators/overrideProvider.js.map +1 -0
- package/lib/esm/decorators/scope.js +12 -0
- package/lib/esm/decorators/scope.js.map +1 -0
- package/lib/esm/decorators/service.js +14 -0
- package/lib/esm/decorators/service.js.map +1 -0
- package/lib/esm/decorators/useOpts.js +61 -0
- package/lib/esm/decorators/useOpts.js.map +1 -0
- package/lib/esm/decorators/value.js +51 -0
- package/lib/esm/decorators/value.js.map +1 -0
- package/lib/esm/domain/Container.js +68 -0
- package/lib/esm/domain/Container.js.map +1 -0
- package/lib/esm/domain/ContextLogger.js +81 -0
- package/lib/esm/domain/ContextLogger.js.map +1 -0
- package/lib/esm/domain/DIContext.js +41 -0
- package/lib/esm/domain/DIContext.js.map +1 -0
- package/lib/esm/domain/InjectablePropertyType.js +9 -0
- package/lib/esm/domain/InjectablePropertyType.js.map +1 -0
- package/lib/esm/domain/LocalsContainer.js +51 -0
- package/lib/esm/domain/LocalsContainer.js.map +1 -0
- package/lib/esm/domain/Provider.js +118 -0
- package/lib/esm/domain/Provider.js.map +1 -0
- package/lib/esm/domain/ProviderScope.js +7 -0
- package/lib/esm/domain/ProviderScope.js.map +1 -0
- package/lib/esm/domain/ProviderType.js +12 -0
- package/lib/esm/domain/ProviderType.js.map +1 -0
- package/lib/esm/errors/InjectionError.js +54 -0
- package/lib/esm/errors/InjectionError.js.map +1 -0
- package/lib/esm/errors/UndefinedTokenError.js +7 -0
- package/lib/esm/errors/UndefinedTokenError.js.map +1 -0
- package/lib/esm/index.js +56 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/DIConfigurationOptions.js +2 -0
- package/lib/esm/interfaces/DIConfigurationOptions.js.map +1 -0
- package/lib/esm/interfaces/DILogger.js +2 -0
- package/lib/esm/interfaces/DILogger.js.map +1 -0
- package/lib/esm/interfaces/DIResolver.js +2 -0
- package/lib/esm/interfaces/DIResolver.js.map +1 -0
- package/lib/esm/interfaces/InjectableProperties.js +2 -0
- package/lib/esm/interfaces/InjectableProperties.js.map +1 -0
- package/lib/esm/interfaces/InterceptorContext.js +2 -0
- package/lib/esm/interfaces/InterceptorContext.js.map +1 -0
- package/lib/esm/interfaces/InterceptorMethods.js +2 -0
- package/lib/esm/interfaces/InterceptorMethods.js.map +1 -0
- package/lib/esm/interfaces/InvokeOptions.js +2 -0
- package/lib/esm/interfaces/InvokeOptions.js.map +1 -0
- package/lib/esm/interfaces/OnDestroy.js +2 -0
- package/lib/esm/interfaces/OnDestroy.js.map +1 -0
- package/lib/esm/interfaces/OnInit.js +2 -0
- package/lib/esm/interfaces/OnInit.js.map +1 -0
- package/lib/esm/interfaces/ProviderOpts.js +2 -0
- package/lib/esm/interfaces/ProviderOpts.js.map +1 -0
- package/lib/esm/interfaces/RegistrySettings.js +2 -0
- package/lib/esm/interfaces/RegistrySettings.js.map +1 -0
- package/lib/esm/interfaces/ResolvedInvokeOptions.js +2 -0
- package/lib/esm/interfaces/ResolvedInvokeOptions.js.map +1 -0
- package/lib/esm/interfaces/TokenProvider.js +2 -0
- package/lib/esm/interfaces/TokenProvider.js.map +1 -0
- package/lib/esm/interfaces/TokenRoute.js +2 -0
- package/lib/esm/interfaces/TokenRoute.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/registries/GlobalProviders.js +120 -0
- package/lib/esm/registries/GlobalProviders.js.map +1 -0
- package/lib/esm/registries/ProviderRegistry.js +81 -0
- package/lib/esm/registries/ProviderRegistry.js.map +1 -0
- package/lib/esm/services/DIConfiguration.js +132 -0
- package/lib/esm/services/DIConfiguration.js.map +1 -0
- package/lib/esm/services/DILogger.js +11 -0
- package/lib/esm/services/DILogger.js.map +1 -0
- package/lib/esm/services/DITest.js +112 -0
- package/lib/esm/services/DITest.js.map +1 -0
- package/lib/esm/services/InjectorService.js +586 -0
- package/lib/esm/services/InjectorService.js.map +1 -0
- package/lib/esm/utils/colors.js +7 -0
- package/lib/esm/utils/colors.js.map +1 -0
- package/lib/esm/utils/createContainer.js +10 -0
- package/lib/esm/utils/createContainer.js.map +1 -0
- package/lib/esm/utils/getConfiguration.js +24 -0
- package/lib/esm/utils/getConfiguration.js.map +1 -0
- package/lib/esm/utils/resolveControllers.js +42 -0
- package/lib/esm/utils/resolveControllers.js.map +1 -0
- package/lib/esm/utils/runInContext.js +13 -0
- package/lib/esm/utils/runInContext.js.map +1 -0
- package/lib/esm/utils/setLoggerLevel.js +12 -0
- package/lib/esm/utils/setLoggerLevel.js.map +1 -0
- package/lib/{constants/index.d.ts → types/constants/constants.d.ts} +0 -0
- package/lib/{decorators → types/decorators}/configuration.d.ts +0 -0
- package/lib/{decorators → types/decorators}/constant.d.ts +0 -0
- package/lib/{decorators → types/decorators}/controller.d.ts +2 -2
- package/lib/types/decorators/inject.d.ts +36 -0
- package/lib/{decorators → types/decorators}/injectable.d.ts +4 -5
- package/lib/{decorators → types/decorators}/intercept.d.ts +2 -2
- package/lib/{decorators → types/decorators}/interceptor.d.ts +0 -0
- package/lib/types/decorators/lazyInject.d.ts +43 -0
- package/lib/{decorators → types/decorators}/module.d.ts +3 -2
- package/lib/{decorators → types/decorators}/opts.d.ts +0 -0
- package/lib/{decorators → types/decorators}/overrideProvider.d.ts +0 -0
- package/lib/{decorators → types/decorators}/scope.d.ts +0 -0
- package/lib/{decorators → types/decorators}/service.d.ts +0 -0
- package/lib/{decorators → types/decorators}/useOpts.d.ts +0 -0
- package/lib/{decorators → types/decorators}/value.d.ts +0 -0
- package/lib/{domain → types/domain}/Container.d.ts +5 -6
- package/lib/{domain → types/domain}/ContextLogger.d.ts +0 -0
- package/lib/{domain → types/domain}/DIContext.d.ts +0 -6
- package/lib/{domain → types/domain}/InjectablePropertyType.d.ts +0 -0
- package/lib/{domain → types/domain}/LocalsContainer.d.ts +0 -0
- package/lib/{domain → types/domain}/Provider.d.ts +17 -3
- package/lib/{domain → types/domain}/ProviderScope.d.ts +0 -0
- package/lib/{domain → types/domain}/ProviderType.d.ts +0 -0
- package/lib/{errors → types/errors}/InjectionError.d.ts +1 -1
- package/lib/{errors → types/errors}/UndefinedTokenError.d.ts +0 -0
- package/lib/types/index.d.ts +55 -0
- package/lib/{interfaces → types/interfaces}/DIConfigurationOptions.d.ts +4 -0
- package/lib/{interfaces → types/interfaces}/DILogger.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/DIResolver.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/InjectableProperties.d.ts +8 -4
- package/lib/{interfaces → types/interfaces}/InterceptorContext.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/InterceptorMethods.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/InvokeOptions.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/OnDestroy.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/OnInit.d.ts +0 -0
- package/lib/{interfaces/IProvider.d.ts → types/interfaces/ProviderOpts.d.ts} +5 -4
- package/lib/{interfaces → types/interfaces}/RegistrySettings.d.ts +7 -3
- package/lib/types/interfaces/ResolvedInvokeOptions.d.ts +12 -0
- package/lib/{interfaces → types/interfaces}/TokenProvider.d.ts +0 -0
- package/lib/types/interfaces/TokenRoute.d.ts +5 -0
- package/lib/{registries → types/registries}/GlobalProviders.d.ts +11 -5
- package/lib/{registries → types/registries}/ProviderRegistry.d.ts +4 -4
- package/lib/{services → types/services}/DIConfiguration.d.ts +6 -2
- package/lib/{services → types/services}/DILogger.d.ts +0 -0
- package/lib/{services → types/services}/DITest.d.ts +7 -1
- package/lib/{services → types/services}/InjectorService.d.ts +45 -22
- package/lib/types/utils/colors.d.ts +5 -0
- package/lib/{utils → types/utils}/createContainer.d.ts +0 -0
- package/lib/{utils → types/utils}/getConfiguration.d.ts +1 -0
- package/lib/types/utils/resolveControllers.d.ts +12 -0
- package/lib/types/utils/runInContext.d.ts +6 -0
- package/lib/{utils → types/utils}/setLoggerLevel.d.ts +0 -0
- package/package.json +32 -16
- package/readme.md +37 -41
- package/tsconfig.compile.esm.json +25 -0
- package/lib/decorators/index.d.ts +0 -14
- package/lib/decorators/inject.d.ts +0 -19
- package/lib/domain/index.d.ts +0 -8
- package/lib/index.d.ts +0 -16
- package/lib/index.js +0 -2269
- package/lib/index.js.map +0 -1
- package/lib/index.modern.js +0 -2232
- package/lib/index.modern.js.map +0 -1
- package/lib/interfaces/index.d.ts +0 -13
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../../../src/utils/colors.ts"],"names":[],"mappings":";;;AAEA,uBAAuB;AACvB,MAAM,cAAc,GAAG,CAAC,OAAoB,EAAE,EAAE,CAAC,CAAC,IAAY,EAAE,EAAE,CAChE,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAExF,MAAM,GAAG,GAAG,cAAc,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,WAAW,IAAI,UAAU,CAAC,CAAC;AACxE,MAAM,MAAM,GAAG,cAAc,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,WAAW,IAAI,UAAU,CAAC,CAAC;AAC3E,MAAM,KAAK,GAAG,cAAc,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,WAAW,IAAI,UAAU,CAAC,CAAC;AAE7D,QAAA,MAAM,GAAG,EAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAC,CAAC","sourcesContent":["type ColorTextFn = (text: string) => string;\n\n// istanbul ignore next\nconst colorIfAllowed = (colorFn: ColorTextFn) => (text: string) =>\n !process.env.NO_COLOR && process.env.NODE_ENV !== \"production\" ? colorFn(text) : text;\n\nconst red = colorIfAllowed((text: string) => `\\x1B[31m${text}\\x1B[39m`);\nconst yellow = colorIfAllowed((text: string) => `\\x1B[33m${text}\\x1B[39m`);\nconst green = colorIfAllowed((text: string) => `\\x1B[32m${text}\\x1B[39m`);\n\nexport const colors = {red, yellow, green};\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createContainer = void 0;
|
|
4
|
+
const Container_1 = require("../domain/Container");
|
|
5
|
+
const GlobalProviders_1 = require("../registries/GlobalProviders");
|
|
6
|
+
function createContainer(rootModule) {
|
|
7
|
+
const container = new Container_1.Container(GlobalProviders_1.GlobalProviders.entries());
|
|
8
|
+
if (rootModule) {
|
|
9
|
+
container.delete(rootModule);
|
|
10
|
+
}
|
|
11
|
+
return container;
|
|
12
|
+
}
|
|
13
|
+
exports.createContainer = createContainer;
|
|
14
|
+
//# sourceMappingURL=createContainer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createContainer.js","sourceRoot":"","sources":["../../../src/utils/createContainer.ts"],"names":[],"mappings":";;;AACA,mDAA8C;AAC9C,mEAA8D;AAE9D,SAAgB,eAAe,CAAC,UAAsB;IACpD,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,iCAAe,CAAC,OAAO,EAAE,CAAC,CAAC;IAE3D,IAAI,UAAU,EAAE;QACd,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;KAC9B;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AARD,0CAQC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {Container} from \"../domain/Container\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\n\nexport function createContainer(rootModule?: Type<any>) {\n const container = new Container(GlobalProviders.entries());\n\n if (rootModule) {\n container.delete(rootModule);\n }\n\n return container;\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConfiguration = exports.mergeMount = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
function mergeMount(m1 = {}, m2 = {}) {
|
|
6
|
+
return Object.entries(m2).reduce((mount, [key, controllers]) => {
|
|
7
|
+
return {
|
|
8
|
+
...mount,
|
|
9
|
+
[key]: (mount[key] || []).concat(controllers)
|
|
10
|
+
};
|
|
11
|
+
}, m1);
|
|
12
|
+
}
|
|
13
|
+
exports.mergeMount = mergeMount;
|
|
14
|
+
function getConfiguration(module, configuration = {}) {
|
|
15
|
+
const store = core_1.Store.from(module).get("configuration") || {};
|
|
16
|
+
const config = {
|
|
17
|
+
...store,
|
|
18
|
+
...configuration
|
|
19
|
+
};
|
|
20
|
+
if (store.mount && configuration.mount) {
|
|
21
|
+
config.mount = mergeMount(store.mount, configuration.mount);
|
|
22
|
+
}
|
|
23
|
+
if (store.componentsScan && configuration.componentsScan) {
|
|
24
|
+
config.componentsScan = [...store.componentsScan, ...configuration.componentsScan];
|
|
25
|
+
}
|
|
26
|
+
return config;
|
|
27
|
+
}
|
|
28
|
+
exports.getConfiguration = getConfiguration;
|
|
29
|
+
//# sourceMappingURL=getConfiguration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getConfiguration.js","sourceRoot":"","sources":["../../../src/utils/getConfiguration.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AAEvC,SAAgB,UAAU,CAAC,KAAU,EAAE,EAAE,KAAU,EAAE;IACnD,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE;QAC7D,OAAO;YACL,GAAG,KAAK;YACR,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;SAC9C,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAPD,gCAOC;AAED,SAAgB,gBAAgB,CAAC,MAAiB,EAAE,gBAAqB,EAAE;IACzE,MAAM,KAAK,GAAG,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;IAE5D,MAAM,MAAM,GAAG;QACb,GAAG,KAAK;QACR,GAAG,aAAa;KACjB,CAAC;IAEF,IAAI,KAAK,CAAC,KAAK,IAAI,aAAa,CAAC,KAAK,EAAE;QACtC,MAAM,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;KAC7D;IAED,IAAI,KAAK,CAAC,cAAc,IAAI,aAAa,CAAC,cAAc,EAAE;QACxD,MAAM,CAAC,cAAc,GAAG,CAAC,GAAG,KAAK,CAAC,cAAc,EAAE,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;KACpF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAjBD,4CAiBC","sourcesContent":["import {Store, Type} from \"@tsed/core\";\n\nexport function mergeMount(m1: any = {}, m2: any = {}) {\n return Object.entries(m2).reduce((mount, [key, controllers]) => {\n return {\n ...mount,\n [key]: (mount[key] || []).concat(controllers)\n };\n }, m1);\n}\n\nexport function getConfiguration(module: Type<any>, configuration: any = {}) {\n const store = Store.from(module).get(\"configuration\") || {};\n\n const config = {\n ...store,\n ...configuration\n };\n\n if (store.mount && configuration.mount) {\n config.mount = mergeMount(store.mount, configuration.mount);\n }\n\n if (store.componentsScan && configuration.componentsScan) {\n config.componentsScan = [...store.componentsScan, ...configuration.componentsScan];\n }\n\n return config;\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveControllers = exports.getTokens = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const GlobalProviders_1 = require("../registries/GlobalProviders");
|
|
6
|
+
const ProviderType_1 = require("../domain/ProviderType");
|
|
7
|
+
const lookupProperties = ["mount", "imports"];
|
|
8
|
+
function getTokens(config) {
|
|
9
|
+
if (!config) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
if ((0, core_1.isArray)(config)) {
|
|
13
|
+
return config.filter(core_1.isClass).map((value) => {
|
|
14
|
+
return { token: value };
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return Object.keys(config).reduce((list, route) => {
|
|
18
|
+
return [
|
|
19
|
+
...list,
|
|
20
|
+
...[]
|
|
21
|
+
.concat(config[route])
|
|
22
|
+
.filter(core_1.isClass)
|
|
23
|
+
.map((token) => ({
|
|
24
|
+
route,
|
|
25
|
+
token
|
|
26
|
+
}))
|
|
27
|
+
];
|
|
28
|
+
}, []);
|
|
29
|
+
}
|
|
30
|
+
exports.getTokens = getTokens;
|
|
31
|
+
function resolveRecursively(providers) {
|
|
32
|
+
return providers
|
|
33
|
+
.map(({ token }) => GlobalProviders_1.GlobalProviders.get(token))
|
|
34
|
+
.filter((provider) => (provider === null || provider === void 0 ? void 0 : provider.type) === ProviderType_1.ProviderType.MODULE && provider.configuration)
|
|
35
|
+
.flatMap((provider) => resolveControllers(provider.configuration));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Return controllers and is base route according to his configuration in module configuration.
|
|
39
|
+
*
|
|
40
|
+
* @param settings
|
|
41
|
+
*/
|
|
42
|
+
function resolveControllers(settings) {
|
|
43
|
+
const providers = lookupProperties.flatMap((property) => getTokens(settings[property]));
|
|
44
|
+
return [...resolveRecursively(providers), ...providers].filter((provider) => !!provider.route);
|
|
45
|
+
}
|
|
46
|
+
exports.resolveControllers = resolveControllers;
|
|
47
|
+
//# sourceMappingURL=resolveControllers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveControllers.js","sourceRoot":"","sources":["../../../src/utils/resolveControllers.ts"],"names":[],"mappings":";;;AAAA,qCAA4C;AAE5C,mEAA8D;AAC9D,yDAAoD;AAIpD,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AAE9C,SAAgB,SAAS,CAAC,MAAW;IACnC,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAC;KACX;IAED,IAAI,IAAA,cAAO,EAAC,MAAM,CAAC,EAAE;QACnB,OAAO,MAAM,CAAC,MAAM,CAAC,cAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAU,EAAE,EAAE;YAC/C,OAAO,EAAC,KAAK,EAAE,KAAK,EAAC,CAAC;QACxB,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,IAAW,EAAE,KAAa,EAAE,EAAE;QAC/D,OAAO;YACL,GAAG,IAAI;YACP,GAAG,EAAE;iBACF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;iBACrB,MAAM,CAAC,cAAO,CAAC;iBACf,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBACf,KAAK;gBACL,KAAK;aACN,CAAC,CAAC;SACN,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAvBD,8BAuBC;AAED,SAAS,kBAAkB,CAAC,SAAmD;IAC7E,OAAO,SAAS;SACb,GAAG,CAAC,CAAC,EAAC,KAAK,EAAC,EAAE,EAAE,CAAC,iCAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC5C,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,MAAK,2BAAY,CAAC,MAAM,IAAI,QAAQ,CAAC,aAAa,CAAC;SACtF,OAAO,CAAC,CAAC,QAAkB,EAAE,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;AACjF,CAAC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,QAAqC;IACtE,MAAM,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAExF,OAAO,CAAC,GAAG,kBAAkB,CAAC,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAU,CAAC;AAC1G,CAAC;AAJD,gDAIC","sourcesContent":["import {isArray, isClass} from \"@tsed/core\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport {Provider} from \"../domain/Provider\";\nimport {TokenRoute} from \"../interfaces/TokenRoute\";\n\nconst lookupProperties = [\"mount\", \"imports\"];\n\nexport function getTokens(config: any): {route?: string; token: TokenProvider}[] {\n if (!config) {\n return [];\n }\n\n if (isArray(config)) {\n return config.filter(isClass).map((value: any) => {\n return {token: value};\n });\n }\n\n return Object.keys(config).reduce((list: any[], route: string) => {\n return [\n ...list,\n ...[]\n .concat(config[route])\n .filter(isClass)\n .map((token) => ({\n route,\n token\n }))\n ];\n }, []);\n}\n\nfunction resolveRecursively(providers: {token: TokenProvider; route?: string}[]) {\n return providers\n .map(({token}) => GlobalProviders.get(token))\n .filter((provider) => provider?.type === ProviderType.MODULE && provider.configuration)\n .flatMap((provider: Provider) => resolveControllers(provider.configuration));\n}\n\n/**\n * Return controllers and is base route according to his configuration in module configuration.\n *\n * @param settings\n */\nexport function resolveControllers(settings: Partial<TsED.Configuration>): TokenRoute[] {\n const providers = lookupProperties.flatMap((property) => getTokens(settings[property]));\n\n return [...resolveRecursively(providers), ...providers].filter((provider) => !!provider.route) as any[];\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runInContext = exports.getContext = exports.getAsyncStore = void 0;
|
|
4
|
+
const async_hooks_1 = require("async_hooks");
|
|
5
|
+
let store;
|
|
6
|
+
function getAsyncStore() {
|
|
7
|
+
store = store || new async_hooks_1.AsyncLocalStorage();
|
|
8
|
+
return store;
|
|
9
|
+
}
|
|
10
|
+
exports.getAsyncStore = getAsyncStore;
|
|
11
|
+
function getContext() {
|
|
12
|
+
return store === null || store === void 0 ? void 0 : store.getStore();
|
|
13
|
+
}
|
|
14
|
+
exports.getContext = getContext;
|
|
15
|
+
function runInContext(ctx, cb) {
|
|
16
|
+
return getAsyncStore().run(ctx, cb);
|
|
17
|
+
}
|
|
18
|
+
exports.runInContext = runInContext;
|
|
19
|
+
//# sourceMappingURL=runInContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runInContext.js","sourceRoot":"","sources":["../../../src/utils/runInContext.ts"],"names":[],"mappings":";;;AAAA,6CAA8C;AAG9C,IAAI,KAAmC,CAAC;AAExC,SAAgB,aAAa;IAC3B,KAAK,GAAG,KAAK,IAAI,IAAI,+BAAiB,EAAE,CAAC;IACzC,OAAO,KAAK,CAAC;AACf,CAAC;AAHD,sCAGC;AAED,SAAgB,UAAU;IACxB,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,EAAE,CAAC;AAC3B,CAAC;AAFD,gCAEC;AAED,SAAgB,YAAY,CAAC,GAAc,EAAE,EAAO;IAClD,OAAO,aAAa,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AACtC,CAAC;AAFD,oCAEC","sourcesContent":["import {AsyncLocalStorage} from \"async_hooks\";\nimport {DIContext} from \"../domain/DIContext\";\n\nlet store: AsyncLocalStorage<DIContext>;\n\nexport function getAsyncStore() {\n store = store || new AsyncLocalStorage();\n return store;\n}\n\nexport function getContext() {\n return store?.getStore();\n}\n\nexport function runInContext(ctx: DIContext, cb: any) {\n return getAsyncStore().run(ctx, cb);\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setLoggerLevel = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @ignore
|
|
6
|
+
* @param injector
|
|
7
|
+
*/
|
|
8
|
+
function setLoggerLevel(injector) {
|
|
9
|
+
var _a;
|
|
10
|
+
const level = (_a = injector.settings.logger) === null || _a === void 0 ? void 0 : _a.level;
|
|
11
|
+
if (level) {
|
|
12
|
+
injector.logger.level = level;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.setLoggerLevel = setLoggerLevel;
|
|
16
|
+
//# sourceMappingURL=setLoggerLevel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setLoggerLevel.js","sourceRoot":"","sources":["../../../src/utils/setLoggerLevel.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,SAAgB,cAAc,CAAC,QAAyB;;IACtD,MAAM,KAAK,GAAG,MAAA,QAAQ,CAAC,QAAQ,CAAC,MAAM,0CAAE,KAAK,CAAC;IAE9C,IAAI,KAAK,EAAE;QACT,QAAQ,CAAC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;KAC/B;AACH,CAAC;AAND,wCAMC","sourcesContent":["import {InjectorService} from \"../services/InjectorService\";\n\n/**\n * @ignore\n * @param injector\n */\nexport function setLoggerLevel(injector: InjectorService) {\n const level = injector.settings.logger?.level;\n\n if (level) {\n injector.logger.level = level;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,oBAAoB,CAAC;AACpD,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC;AACrC,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC","sourcesContent":["export const INJECTABLE_PROP = \"DI:INJECTABLE_PROP\";\nexport const DI_PARAMS = \"DI:PARAMS\";\nexport const DI_PARAM_OPTIONS = \"DI:PARAM:OPTIONS\";\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { decoratorTypeOf, DecoratorTypes, StoreSet } from "@tsed/core";
|
|
2
|
+
import { Inject } from "../decorators/inject.js";
|
|
3
|
+
/**
|
|
4
|
+
* Get or set Configuration on a class.
|
|
5
|
+
*
|
|
6
|
+
* @decorator
|
|
7
|
+
*/
|
|
8
|
+
export function Configuration(configuration = {}) {
|
|
9
|
+
return (...args) => {
|
|
10
|
+
switch (decoratorTypeOf(args)) {
|
|
11
|
+
case DecoratorTypes.CLASS:
|
|
12
|
+
StoreSet("configuration", configuration)(args[0]);
|
|
13
|
+
break;
|
|
14
|
+
default:
|
|
15
|
+
case DecoratorTypes.PARAM_CTOR:
|
|
16
|
+
return Inject(Configuration)(args[0], args[1], args[2]);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../../src/decorators/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,eAAe,EAAE,cAAc,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AAC1F,OAAO,EAAC,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAG5C;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,gBAA6C,EAAE;IAC3E,OAAO,CAAC,GAAG,IAAyB,EAAE,EAAE;QACtC,QAAQ,eAAe,CAAC,IAAI,CAAC,EAAE;YAC7B,KAAK,cAAc,CAAC,KAAK;gBACvB,QAAQ,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBAElD,MAAM;YACR,QAAQ;YACR,KAAK,cAAc,CAAC,UAAU;gBAC5B,OAAO,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAW,CAAC,CAAC;SACrE;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {DecoratorParameters, decoratorTypeOf, DecoratorTypes, StoreSet} from \"@tsed/core\";\nimport {Inject} from \"../decorators/inject\";\nimport {DIConfiguration} from \"../services/DIConfiguration\";\n\n/**\n * Get or set Configuration on a class.\n *\n * @decorator\n */\nexport function Configuration(configuration: Partial<TsED.Configuration> = {}): Function {\n return (...args: DecoratorParameters) => {\n switch (decoratorTypeOf(args)) {\n case DecoratorTypes.CLASS:\n StoreSet(\"configuration\", configuration)(args[0]);\n\n break;\n default:\n case DecoratorTypes.PARAM_CTOR:\n return Inject(Configuration)(args[0], args[1], args[2] as number);\n }\n };\n}\n\nexport type Configuration = TsED.Configuration & DIConfiguration;\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Store } from "@tsed/core";
|
|
2
|
+
import { INJECTABLE_PROP } from "../constants/constants.js";
|
|
3
|
+
import { InjectablePropertyType } from "../domain/InjectablePropertyType.js";
|
|
4
|
+
/**
|
|
5
|
+
* Return value from Configuration.
|
|
6
|
+
*
|
|
7
|
+
* ## Example
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import {Env} from "@tsed/core";
|
|
11
|
+
* import {Constant, Value} from "@tsed/di";
|
|
12
|
+
*
|
|
13
|
+
* export class MyClass {
|
|
14
|
+
*
|
|
15
|
+
* @Constant("env")
|
|
16
|
+
* env: Env;
|
|
17
|
+
*
|
|
18
|
+
* @Value("swagger.path")
|
|
19
|
+
* swaggerPath: string;
|
|
20
|
+
*
|
|
21
|
+
* @Value("swagger.path", "defaultValue")
|
|
22
|
+
* swaggerPath: string;
|
|
23
|
+
*
|
|
24
|
+
* constructor() {
|
|
25
|
+
* console.log(this.swaggerPath) // undefined. Not available on constructor
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* $onInit() {
|
|
29
|
+
* console.log(this.swaggerPath) // something
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param {string} expression
|
|
35
|
+
* @param defaultValue
|
|
36
|
+
* @returns {(targetClass: any, attributeName: string) => any}
|
|
37
|
+
* @decorator
|
|
38
|
+
*/
|
|
39
|
+
export function Constant(expression, defaultValue) {
|
|
40
|
+
return (target, propertyKey) => {
|
|
41
|
+
Store.from(target).merge(INJECTABLE_PROP, {
|
|
42
|
+
[propertyKey]: {
|
|
43
|
+
bindingType: InjectablePropertyType.CONSTANT,
|
|
44
|
+
propertyKey,
|
|
45
|
+
expression,
|
|
46
|
+
defaultValue
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../../src/decorators/constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AACjC,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAC,sBAAsB,EAAC,MAAM,kCAAkC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,QAAQ,CAAC,UAAkB,EAAE,YAAkB;IAC7D,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE;YACxC,CAAC,WAAW,CAAC,EAAE;gBACb,WAAW,EAAE,sBAAsB,CAAC,QAAQ;gBAC5C,WAAW;gBACX,UAAU;gBACV,YAAY;aACb;SACsB,CAAC,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants/constants\";\nimport type {InjectableProperties} from \"../interfaces/InjectableProperties\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\n\n/**\n * Return value from Configuration.\n *\n * ## Example\n *\n * ```typescript\n * import {Env} from \"@tsed/core\";\n * import {Constant, Value} from \"@tsed/di\";\n *\n * export class MyClass {\n *\n * @Constant(\"env\")\n * env: Env;\n *\n * @Value(\"swagger.path\")\n * swaggerPath: string;\n *\n * @Value(\"swagger.path\", \"defaultValue\")\n * swaggerPath: string;\n *\n * constructor() {\n * console.log(this.swaggerPath) // undefined. Not available on constructor\n * }\n *\n * $onInit() {\n * console.log(this.swaggerPath) // something\n * }\n * }\n * ```\n *\n * @param {string} expression\n * @param defaultValue\n * @returns {(targetClass: any, attributeName: string) => any}\n * @decorator\n */\nexport function Constant(expression: string, defaultValue?: any): any {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: InjectablePropertyType.CONSTANT,\n propertyKey,\n expression,\n defaultValue\n }\n } as InjectableProperties);\n };\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { isArrayOrArrayClass, useDecorators } from "@tsed/core";
|
|
2
|
+
import { Children, Path } from "@tsed/schema";
|
|
3
|
+
import { registerController } from "../registries/ProviderRegistry.js";
|
|
4
|
+
function mapOptions(options) {
|
|
5
|
+
if (typeof options === "string" || options instanceof RegExp || isArrayOrArrayClass(options)) {
|
|
6
|
+
return {
|
|
7
|
+
path: options
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
return options;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Declare a new controller with his Rest path. His methods annotated will be collected to build the routing list.
|
|
14
|
+
* This routing listing will be built with the `express.Router` object.
|
|
15
|
+
*
|
|
16
|
+
* ::: tip
|
|
17
|
+
* See [Controllers](/docs/controllers.md) section for more details
|
|
18
|
+
* :::
|
|
19
|
+
*
|
|
20
|
+
* ```typescript
|
|
21
|
+
* @Controller("/calendars")
|
|
22
|
+
* export provide CalendarCtrl {
|
|
23
|
+
*
|
|
24
|
+
* @Get("/:id")
|
|
25
|
+
* public get(
|
|
26
|
+
* @Req() request: Req,
|
|
27
|
+
* @Res() response: Res,
|
|
28
|
+
* @Next() next: Next
|
|
29
|
+
* ): void {
|
|
30
|
+
*
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param options
|
|
36
|
+
* @controller
|
|
37
|
+
* @decorator
|
|
38
|
+
* @classDecorator
|
|
39
|
+
*/
|
|
40
|
+
export function Controller(options) {
|
|
41
|
+
const { children = [], path, ...opts } = mapOptions(options);
|
|
42
|
+
return useDecorators((target) => {
|
|
43
|
+
registerController({
|
|
44
|
+
provide: target,
|
|
45
|
+
...opts
|
|
46
|
+
});
|
|
47
|
+
}, path && Path(path), Children(...children));
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../src/decorators/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAQ,aAAa,EAAC,MAAM,YAAY,CAAC;AACpE,OAAO,EAAC,QAAQ,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAiBlE,SAAS,UAAU,CAAC,OAAY;IAC9B,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,YAAY,MAAM,IAAI,mBAAmB,CAAC,OAAO,CAAC,EAAE;QAC5F,OAAO;YACL,IAAI,EAAE,OAAO;SACd,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,UAAU,CAAC,OAAqC;IAC9D,MAAM,EAAC,QAAQ,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,IAAI,EAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAE3D,OAAO,aAAa,CAClB,CAAC,MAAY,EAAE,EAAE;QACf,kBAAkB,CAAC;YACjB,OAAO,EAAE,MAAM;YACf,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC,EACD,IAAI,IAAI,IAAI,CAAC,IAAW,CAAC,EACzB,QAAQ,CAAC,GAAG,QAAQ,CAAC,CACtB,CAAC;AACJ,CAAC","sourcesContent":["import {isArrayOrArrayClass, Type, useDecorators} from \"@tsed/core\";\nimport {Children, Path} from \"@tsed/schema\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {registerController} from \"../registries/ProviderRegistry\";\n\nexport type PathType = string | RegExp | (string | RegExp)[];\n\nexport interface ControllerMiddlewares {\n useBefore: any[];\n use: any[];\n useAfter: any[];\n}\n\nexport interface ControllerOptions extends Partial<ProviderOpts<any>> {\n path?: PathType;\n children?: Type<any>[];\n routerOptions?: any;\n middlewares?: Partial<ControllerMiddlewares>;\n}\n\nfunction mapOptions(options: any): ControllerOptions {\n if (typeof options === \"string\" || options instanceof RegExp || isArrayOrArrayClass(options)) {\n return {\n path: options\n };\n }\n\n return options;\n}\n\n/**\n * Declare a new controller with his Rest path. His methods annotated will be collected to build the routing list.\n * This routing listing will be built with the `express.Router` object.\n *\n * ::: tip\n * See [Controllers](/docs/controllers.md) section for more details\n * :::\n *\n * ```typescript\n * @Controller(\"/calendars\")\n * export provide CalendarCtrl {\n *\n * @Get(\"/:id\")\n * public get(\n * @Req() request: Req,\n * @Res() response: Res,\n * @Next() next: Next\n * ): void {\n *\n * }\n * }\n * ```\n *\n * @param options\n * @controller\n * @decorator\n * @classDecorator\n */\nexport function Controller(options: PathType | ControllerOptions): ClassDecorator {\n const {children = [], path, ...opts} = mapOptions(options);\n\n return useDecorators(\n (target: Type) => {\n registerController({\n provide: target,\n ...opts\n });\n },\n path && Path(path as any),\n Children(...children)\n );\n}\n"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { decoratorTypeOf, DecoratorTypes, isPromise, Metadata, Store, UnsupportedDecoratorType } from "@tsed/core";
|
|
2
|
+
import { DI_PARAM_OPTIONS, INJECTABLE_PROP } from "../constants/constants.js";
|
|
3
|
+
import { getContext } from "../utils/runInContext.js";
|
|
4
|
+
export function injectProperty(target, propertyKey, options) {
|
|
5
|
+
Store.from(target).merge(INJECTABLE_PROP, {
|
|
6
|
+
[propertyKey]: {
|
|
7
|
+
bindingType: DecoratorTypes.PROP,
|
|
8
|
+
propertyKey,
|
|
9
|
+
...options
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Inject a provider to another provider.
|
|
15
|
+
*
|
|
16
|
+
* Use this decorator to inject a custom provider on constructor parameter or property.
|
|
17
|
+
*
|
|
18
|
+
* ```typescript
|
|
19
|
+
* @Injectable()
|
|
20
|
+
* export class MyService {
|
|
21
|
+
* @Inject(CONNECTION)
|
|
22
|
+
* connection: CONNECTION;
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param symbol
|
|
27
|
+
* @param onGet Use the given name method to inject
|
|
28
|
+
* @returns {Function}
|
|
29
|
+
* @decorator
|
|
30
|
+
*/
|
|
31
|
+
export function Inject(symbol, onGet = (bean) => bean) {
|
|
32
|
+
return (target, propertyKey, descriptor) => {
|
|
33
|
+
const bindingType = decoratorTypeOf([target, propertyKey, descriptor]);
|
|
34
|
+
switch (bindingType) {
|
|
35
|
+
case DecoratorTypes.PARAM:
|
|
36
|
+
case DecoratorTypes.PARAM_CTOR:
|
|
37
|
+
if (symbol) {
|
|
38
|
+
const paramTypes = Metadata.getParamTypes(target, propertyKey);
|
|
39
|
+
paramTypes[descriptor] = symbol;
|
|
40
|
+
Metadata.setParamTypes(target, propertyKey, paramTypes);
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
case DecoratorTypes.PROP:
|
|
44
|
+
injectProperty(target, propertyKey, {
|
|
45
|
+
resolver(injector, locals, { options, ...invokeOptions }) {
|
|
46
|
+
locals.set(DI_PARAM_OPTIONS, { ...options });
|
|
47
|
+
let bean;
|
|
48
|
+
if (!bean) {
|
|
49
|
+
const useType = symbol || Metadata.getType(target, propertyKey);
|
|
50
|
+
bean = injector.invoke(useType, locals, invokeOptions);
|
|
51
|
+
locals.delete(DI_PARAM_OPTIONS);
|
|
52
|
+
}
|
|
53
|
+
if (isPromise(bean)) {
|
|
54
|
+
bean.then((result) => {
|
|
55
|
+
bean = result;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return () => onGet(bean);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
break;
|
|
62
|
+
case DecoratorTypes.METHOD:
|
|
63
|
+
Store.from(target).merge(INJECTABLE_PROP, {
|
|
64
|
+
[propertyKey]: {
|
|
65
|
+
bindingType,
|
|
66
|
+
propertyKey
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return descriptor;
|
|
70
|
+
default:
|
|
71
|
+
throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Inject a context like PlatformContext or any BaseContext.
|
|
77
|
+
*
|
|
78
|
+
* ```typescript
|
|
79
|
+
* @Injectable()
|
|
80
|
+
* export class MyService {
|
|
81
|
+
* @InjectContext()
|
|
82
|
+
* ctx?: Context;
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @returns {Function}
|
|
87
|
+
* @decorator
|
|
88
|
+
*/
|
|
89
|
+
export function InjectContext() {
|
|
90
|
+
return (target, propertyKey) => {
|
|
91
|
+
injectProperty(target, propertyKey, {
|
|
92
|
+
resolver() {
|
|
93
|
+
return () => getContext();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=inject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/decorators/inject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAC;AACjH,OAAO,EAAC,gBAAgB,EAAE,eAAe,EAAC,MAAM,wBAAwB,CAAC;AAEzE,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAEjD,MAAM,UAAU,cAAc,CAAC,MAAW,EAAE,WAAmB,EAAE,OAA2C;IAC1G,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE;QACxC,CAAC,WAAW,CAAC,EAAE;YACb,WAAW,EAAE,cAAc,CAAC,IAAI;YAChC,WAAW;YACX,GAAG,OAAO;SACX;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM,CAAC,MAAY,EAAE,QAAQ,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI;IAC9D,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAAsD,EAAc,EAAE;QAC9G,MAAM,WAAW,GAAG,eAAe,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;QAEvE,QAAQ,WAAW,EAAE;YACnB,KAAK,cAAc,CAAC,KAAK,CAAC;YAC1B,KAAK,cAAc,CAAC,UAAU;gBAC5B,IAAI,MAAM,EAAE;oBACV,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;oBAE/D,UAAU,CAAC,UAAoB,CAAC,GAAG,MAAM,CAAC;oBAC1C,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;iBACzD;gBACD,MAAM;YAER,KAAK,cAAc,CAAC,IAAI;gBACtB,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;oBAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAC,OAAO,EAAE,GAAG,aAAa,EAAC;wBACpD,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,EAAC,GAAG,OAAO,EAAC,CAAC,CAAC;wBAE3C,IAAI,IAAS,CAAC;wBAEd,IAAI,CAAC,IAAI,EAAE;4BACT,MAAM,OAAO,GAAG,MAAM,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;4BAChE,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;4BACvD,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;yBACjC;wBAED,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE;4BACnB,IAAI,CAAC,IAAI,CAAC,CAAC,MAAW,EAAE,EAAE;gCACxB,IAAI,GAAG,MAAM,CAAC;4BAChB,CAAC,CAAC,CAAC;yBACJ;wBAED,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBAC3B,CAAC;iBACF,CAAC,CAAC;gBACH,MAAM;YAER,KAAK,cAAc,CAAC,MAAM;gBACxB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE;oBACxC,CAAC,WAAW,CAAC,EAAE;wBACb,WAAW;wBACX,WAAW;qBACZ;iBACF,CAAC,CAAC;gBAEH,OAAO,UAAU,CAAC;YAEpB;gBACE,MAAM,IAAI,wBAAwB,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;SACjF;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAc,EAAE;QACtD,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;YAClC,QAAQ;gBACN,OAAO,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC;YAC5B,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, isPromise, Metadata, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\nimport type {InjectablePropertyOptions} from \"../interfaces/InjectableProperties\";\nimport {getContext} from \"../utils/runInContext\";\n\nexport function injectProperty(target: any, propertyKey: string, options: Partial<InjectablePropertyOptions>) {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: DecoratorTypes.PROP,\n propertyKey,\n ...options\n }\n });\n}\n\n/**\n * Inject a provider to another provider.\n *\n * Use this decorator to inject a custom provider on constructor parameter or property.\n *\n * ```typescript\n * @Injectable()\n * export class MyService {\n * @Inject(CONNECTION)\n * connection: CONNECTION;\n * }\n * ```\n *\n * @param symbol\n * @param onGet Use the given name method to inject\n * @returns {Function}\n * @decorator\n */\nexport function Inject(symbol?: any, onGet = (bean: any) => bean): Function {\n return (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<Function> | number): any | void => {\n const bindingType = decoratorTypeOf([target, propertyKey, descriptor]);\n\n switch (bindingType) {\n case DecoratorTypes.PARAM:\n case DecoratorTypes.PARAM_CTOR:\n if (symbol) {\n const paramTypes = Metadata.getParamTypes(target, propertyKey);\n\n paramTypes[descriptor as number] = symbol;\n Metadata.setParamTypes(target, propertyKey, paramTypes);\n }\n break;\n\n case DecoratorTypes.PROP:\n injectProperty(target, propertyKey, {\n resolver(injector, locals, {options, ...invokeOptions}) {\n locals.set(DI_PARAM_OPTIONS, {...options});\n\n let bean: any;\n\n if (!bean) {\n const useType = symbol || Metadata.getType(target, propertyKey);\n bean = injector.invoke(useType, locals, invokeOptions);\n locals.delete(DI_PARAM_OPTIONS);\n }\n\n if (isPromise(bean)) {\n bean.then((result: any) => {\n bean = result;\n });\n }\n\n return () => onGet(bean);\n }\n });\n break;\n\n case DecoratorTypes.METHOD:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType,\n propertyKey\n }\n });\n\n return descriptor;\n\n default:\n throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);\n }\n };\n}\n\n/**\n * Inject a context like PlatformContext or any BaseContext.\n *\n * ```typescript\n * @Injectable()\n * export class MyService {\n * @InjectContext()\n * ctx?: Context;\n * }\n * ```\n *\n * @returns {Function}\n * @decorator\n */\nexport function InjectContext(): PropertyDecorator {\n return (target: any, propertyKey: string): any | void => {\n injectProperty(target, propertyKey, {\n resolver() {\n return () => getContext();\n }\n });\n };\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { registerProvider } from "../registries/ProviderRegistry.js";
|
|
2
|
+
/**
|
|
3
|
+
* The decorators `@Injectable()` declare a new service can be injected in other service, controller, interceptor, etc.. on there `constructor`.
|
|
4
|
+
* All classes annotated with `@Injectable()` are built one time, excepted if you change the default provider configuration.
|
|
5
|
+
*
|
|
6
|
+
* ::: tip
|
|
7
|
+
* `@Injectable()` use the `reflect-metadata` to collect and inject the built provided to other services.
|
|
8
|
+
* :::
|
|
9
|
+
*
|
|
10
|
+
* ### Options
|
|
11
|
+
*
|
|
12
|
+
* - type (@@ProviderType@@ or `string`): Kind of provider. (Default: `ProviderType.PROVIDER`)
|
|
13
|
+
* - scope (@@ProviderScope@@): Kind of provider. (Default: `ProviderScope.SINGLETON`)
|
|
14
|
+
* - provide (@@TokenProvider@@): An injection token (Note: This option override default metadata generated by Typescript).
|
|
15
|
+
* - deps (`Type<any>`): List of class or provider which will be injected to the constructor (Note: This options override default metadata generated by Typescript).
|
|
16
|
+
*
|
|
17
|
+
* @returns {Function}
|
|
18
|
+
* @decorator
|
|
19
|
+
*/
|
|
20
|
+
export function Injectable(options = {}) {
|
|
21
|
+
return (target) => {
|
|
22
|
+
registerProvider({
|
|
23
|
+
...options,
|
|
24
|
+
...(options.provide ? { useClass: target } : { provide: target })
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=injectable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectable.js","sourceRoot":"","sources":["../../../src/decorators/injectable.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,gCAAgC,CAAC;AAEhE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,UAAU,CAAC,UAAiC,EAAE;IAC5D,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,gBAAgB,CAAC;YACf,GAAG,OAAO;YACV,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC,CAAC,EAAC,OAAO,EAAE,MAAM,EAAC,CAAC;SAC9D,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {registerProvider} from \"../registries/ProviderRegistry\";\n\n/**\n * The decorators `@Injectable()` declare a new service can be injected in other service, controller, interceptor, etc.. on there `constructor`.\n * All classes annotated with `@Injectable()` are built one time, excepted if you change the default provider configuration.\n *\n * ::: tip\n * `@Injectable()` use the `reflect-metadata` to collect and inject the built provided to other services.\n * :::\n *\n * ### Options\n *\n * - type (@@ProviderType@@ or `string`): Kind of provider. (Default: `ProviderType.PROVIDER`)\n * - scope (@@ProviderScope@@): Kind of provider. (Default: `ProviderScope.SINGLETON`)\n * - provide (@@TokenProvider@@): An injection token (Note: This option override default metadata generated by Typescript).\n * - deps (`Type<any>`): List of class or provider which will be injected to the constructor (Note: This options override default metadata generated by Typescript).\n *\n * @returns {Function}\n * @decorator\n */\nexport function Injectable(options: Partial<ProviderOpts> = {}): ClassDecorator {\n return (target: any) => {\n registerProvider({\n ...options,\n ...(options.provide ? {useClass: target} : {provide: target})\n });\n };\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { decorateMethodsOf, decoratorTypeOf, DecoratorTypes, Store } from "@tsed/core";
|
|
2
|
+
import { INJECTABLE_PROP } from "../constants/constants.js";
|
|
3
|
+
import { InjectablePropertyType } from "../domain/InjectablePropertyType.js";
|
|
4
|
+
/**
|
|
5
|
+
* Attaches interceptor to method call and executes the before and after methods
|
|
6
|
+
*
|
|
7
|
+
* @param interceptor
|
|
8
|
+
* @param options
|
|
9
|
+
* @decorator
|
|
10
|
+
*/
|
|
11
|
+
export function Intercept(interceptor, options) {
|
|
12
|
+
return (...args) => {
|
|
13
|
+
const [target, propertyKey, descriptor] = args;
|
|
14
|
+
const type = decoratorTypeOf(args);
|
|
15
|
+
switch (type) {
|
|
16
|
+
case DecoratorTypes.CLASS:
|
|
17
|
+
decorateMethodsOf(target, Intercept(interceptor, options));
|
|
18
|
+
break;
|
|
19
|
+
case DecoratorTypes.METHOD:
|
|
20
|
+
Store.from(target).merge(INJECTABLE_PROP, {
|
|
21
|
+
[propertyKey]: {
|
|
22
|
+
options,
|
|
23
|
+
propertyKey,
|
|
24
|
+
useType: interceptor,
|
|
25
|
+
bindingType: InjectablePropertyType.INTERCEPTOR
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return descriptor;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=intercept.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../src/decorators/intercept.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAuB,eAAe,EAAE,cAAc,EAAE,KAAK,EAAO,MAAM,YAAY,CAAC;AAChH,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAC,sBAAsB,EAAC,MAAM,kCAAkC,CAAC;AAIxE;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAA+B,WAAoB,EAAE,OAAa;IACzF,OAAO,CAAC,GAAG,IAAyB,EAAE,EAAE;QACtC,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,IAAI,CAAC;QAC/C,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QACnC,QAAQ,IAAI,EAAE;YACZ,KAAK,cAAc,CAAC,KAAK;gBACvB,iBAAiB,CAAC,MAAM,EAAE,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;gBAC3D,MAAM;YACR,KAAK,cAAc,CAAC,MAAM;gBACxB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE;oBACxC,CAAC,WAAW,CAAC,EAAE;wBACb,OAAO;wBACP,WAAW;wBACX,OAAO,EAAE,WAAW;wBACpB,WAAW,EAAE,sBAAsB,CAAC,WAAW;qBAChD;iBACsB,CAAC,CAAC;gBAE3B,OAAO,UAAU,CAAC;SACrB;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {decorateMethodsOf, DecoratorParameters, decoratorTypeOf, DecoratorTypes, Store, Type} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants/constants\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport type {InterceptorMethods} from \"../interfaces/InterceptorMethods\";\nimport type {InjectableProperties} from \"../interfaces/InjectableProperties\";\n\n/**\n * Attaches interceptor to method call and executes the before and after methods\n *\n * @param interceptor\n * @param options\n * @decorator\n */\nexport function Intercept<T extends InterceptorMethods>(interceptor: Type<T>, options?: any): any {\n return (...args: DecoratorParameters) => {\n const [target, propertyKey, descriptor] = args;\n const type = decoratorTypeOf(args);\n switch (type) {\n case DecoratorTypes.CLASS:\n decorateMethodsOf(target, Intercept(interceptor, options));\n break;\n case DecoratorTypes.METHOD:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n options,\n propertyKey,\n useType: interceptor,\n bindingType: InjectablePropertyType.INTERCEPTOR\n }\n } as InjectableProperties);\n\n return descriptor;\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ProviderType } from "../domain/ProviderType.js";
|
|
2
|
+
import { Injectable } from "./injectable.js";
|
|
3
|
+
/**
|
|
4
|
+
* The decorators `@Service()` declare a new service can be injected in other service or controller on there `constructor`.
|
|
5
|
+
* All services annotated with `@Service()` are constructed one time.
|
|
6
|
+
*
|
|
7
|
+
* > `@Service()` use the `reflect-metadata` to collect and inject service on controllers or other services.
|
|
8
|
+
*
|
|
9
|
+
* @returns {Function}
|
|
10
|
+
* @decorator
|
|
11
|
+
*/
|
|
12
|
+
export function Interceptor() {
|
|
13
|
+
return Injectable({
|
|
14
|
+
type: ProviderType.INTERCEPTOR
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptor.js","sourceRoot":"","sources":["../../../src/decorators/interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAExC;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,UAAU,CAAC;QAChB,IAAI,EAAE,YAAY,CAAC,WAAW;KAC/B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {ProviderType} from \"../domain/ProviderType\";\nimport {Injectable} from \"./injectable\";\n\n/**\n * The decorators `@Service()` declare a new service can be injected in other service or controller on there `constructor`.\n * All services annotated with `@Service()` are constructed one time.\n *\n * > `@Service()` use the `reflect-metadata` to collect and inject service on controllers or other services.\n *\n * @returns {Function}\n * @decorator\n */\nexport function Interceptor(): Function {\n return Injectable({\n type: ProviderType.INTERCEPTOR\n });\n}\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { importPackage } from "@tsed/core";
|
|
2
|
+
import { injectProperty } from "./inject.js";
|
|
3
|
+
/**
|
|
4
|
+
* Lazy load a provider from his package and invoke only when the provider is used
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import type {PlatformException} from "@tsed/platform-exceptions";
|
|
8
|
+
*
|
|
9
|
+
* @Injectable()
|
|
10
|
+
* export class MyService {
|
|
11
|
+
* @LazyInject("PlatformException", () => import("@tsed/platform-exceptions"))
|
|
12
|
+
* exceptions: Promise<PlatformException>;
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param key
|
|
17
|
+
* @param packageName
|
|
18
|
+
* @param resolver
|
|
19
|
+
* @param optional
|
|
20
|
+
* @returns {Function}
|
|
21
|
+
* @decorator
|
|
22
|
+
*/
|
|
23
|
+
export function LazyInject(key, resolver, { optional = false, packageName = resolver.toString() } = {}) {
|
|
24
|
+
return (target, propertyKey) => {
|
|
25
|
+
let bean, token;
|
|
26
|
+
injectProperty(target, propertyKey, {
|
|
27
|
+
resolver(injector) {
|
|
28
|
+
return async () => {
|
|
29
|
+
if (!token) {
|
|
30
|
+
const exports = await importPackage(packageName, resolver, optional);
|
|
31
|
+
token = exports[key];
|
|
32
|
+
if (!token) {
|
|
33
|
+
if (!optional) {
|
|
34
|
+
throw new Error(`Unable to lazy load the "${key}". The token isn\'t a valid token provider.`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
bean = token ? await injector.lazyInvoke(token) : {};
|
|
38
|
+
}
|
|
39
|
+
return bean;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Optionally Lazy load a provider from his package and invoke only when the provider is used
|
|
47
|
+
*
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import type {PlatformException} from "@tsed/platform-exceptions";
|
|
50
|
+
*
|
|
51
|
+
* @Injectable()
|
|
52
|
+
* export class MyService {
|
|
53
|
+
* @OptionalLazyInject("@tsed/platform-exceptions")
|
|
54
|
+
* exceptions: Promise<PlatformException>;
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @param key
|
|
59
|
+
* @param resolver
|
|
60
|
+
* @returns {Function}
|
|
61
|
+
* @decorator
|
|
62
|
+
*/
|
|
63
|
+
export function OptionalLazyInject(key, resolver) {
|
|
64
|
+
return LazyInject(key, resolver, { optional: true });
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=lazyInject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazyInject.js","sourceRoot":"","sources":["../../../src/decorators/lazyInject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAExC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,UAAU,CACxB,GAAW,EACX,QAAmB,EACnB,EAAC,QAAQ,GAAG,KAAK,EAAE,WAAW,GAAG,QAAQ,CAAC,QAAQ,EAAE,KAAgD,EAAE;IAEtG,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAc,EAAE;QACtD,IAAI,IAAS,EAAE,KAAU,CAAC;QAC1B,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;YAClC,QAAQ,CAAC,QAAQ;gBACf,OAAO,KAAK,IAAI,EAAE;oBAChB,IAAI,CAAC,KAAK,EAAE;wBACV,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;wBACrE,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;wBAErB,IAAI,CAAC,KAAK,EAAE;4BACV,IAAI,CAAC,QAAQ,EAAE;gCACb,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,6CAA6C,CAAC,CAAC;6BAC/F;yBACF;wBAED,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;qBACtD;oBAED,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW,EAAE,QAAmB;IACjE,OAAQ,UAAkB,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import {importPackage} from \"@tsed/core\";\nimport {injectProperty} from \"./inject\";\n\n/**\n * Lazy load a provider from his package and invoke only when the provider is used\n *\n * ```typescript\n * import type {PlatformException} from \"@tsed/platform-exceptions\";\n *\n * @Injectable()\n * export class MyService {\n * @LazyInject(\"PlatformException\", () => import(\"@tsed/platform-exceptions\"))\n * exceptions: Promise<PlatformException>;\n * }\n * ```\n *\n * @param key\n * @param packageName\n * @param resolver\n * @param optional\n * @returns {Function}\n * @decorator\n */\nexport function LazyInject(\n key: string,\n resolver: () => any,\n {optional = false, packageName = resolver.toString()}: {optional?: boolean; packageName?: string} = {}\n): PropertyDecorator {\n return (target: any, propertyKey: string): any | void => {\n let bean: any, token: any;\n injectProperty(target, propertyKey, {\n resolver(injector) {\n return async () => {\n if (!token) {\n const exports = await importPackage(packageName, resolver, optional);\n token = exports[key];\n\n if (!token) {\n if (!optional) {\n throw new Error(`Unable to lazy load the \"${key}\". The token isn\\'t a valid token provider.`);\n }\n }\n\n bean = token ? await injector.lazyInvoke(token) : {};\n }\n\n return bean;\n };\n }\n });\n };\n}\n\n/**\n * Optionally Lazy load a provider from his package and invoke only when the provider is used\n *\n * ```typescript\n * import type {PlatformException} from \"@tsed/platform-exceptions\";\n *\n * @Injectable()\n * export class MyService {\n * @OptionalLazyInject(\"@tsed/platform-exceptions\")\n * exceptions: Promise<PlatformException>;\n * }\n * ```\n *\n * @param key\n * @param resolver\n * @returns {Function}\n * @decorator\n */\nexport function OptionalLazyInject(key: string, resolver: () => any): PropertyDecorator {\n return (LazyInject as any)(key, resolver, {optional: true});\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useDecorators } from "@tsed/core";
|
|
2
|
+
import { ProviderScope } from "../domain/ProviderScope.js";
|
|
3
|
+
import { Configuration } from "./configuration.js";
|
|
4
|
+
import { Injectable } from "./injectable.js";
|
|
5
|
+
import { ProviderType } from "../domain/ProviderType.js";
|
|
6
|
+
/**
|
|
7
|
+
* Declare a new Ts.ED module
|
|
8
|
+
*
|
|
9
|
+
* ## Options
|
|
10
|
+
* - imports: List of Provider which must be built by injector before invoking the module
|
|
11
|
+
* - resolvers: List of external DI must be used to resolve unknown provider
|
|
12
|
+
* - deps: List of provider must be injected to the module constructor (explicit declaration)
|
|
13
|
+
*
|
|
14
|
+
* @param options
|
|
15
|
+
* @decorator
|
|
16
|
+
*/
|
|
17
|
+
export function Module(options = {}) {
|
|
18
|
+
const { scopes, imports, resolvers, deps, scope, ...configuration } = options;
|
|
19
|
+
return useDecorators(Configuration(configuration), Injectable({
|
|
20
|
+
type: ProviderType.MODULE,
|
|
21
|
+
scope: ProviderScope.SINGLETON,
|
|
22
|
+
imports,
|
|
23
|
+
deps,
|
|
24
|
+
injectable: false,
|
|
25
|
+
resolvers
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=module.js.map
|