@tsed/di 7.0.0-alpha.2 → 7.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/constants/index.js +7 -0
- package/lib/cjs/constants/index.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/index.js +19 -0
- package/lib/cjs/decorators/index.js.map +1 -0
- package/lib/cjs/decorators/inject.js +79 -0
- package/lib/cjs/decorators/inject.js.map +1 -0
- package/lib/cjs/decorators/injectable.js +34 -0
- package/lib/cjs/decorators/injectable.js.map +1 -0
- package/lib/cjs/decorators/intercept.js +28 -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 +31 -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/domain/index.js +12 -0
- package/lib/cjs/domain/index.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 +21 -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/IProvider.js +3 -0
- package/lib/cjs/interfaces/IProvider.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/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/index.js +18 -0
- package/lib/cjs/interfaces/index.js.map +1 -0
- package/lib/cjs/registries/GlobalProviders.js +124 -0
- package/lib/cjs/registries/GlobalProviders.js.map +1 -0
- package/lib/cjs/registries/ProviderRegistry.js +85 -0
- package/lib/cjs/registries/ProviderRegistry.js.map +1 -0
- package/lib/cjs/services/DIConfiguration.js +129 -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 +108 -0
- package/lib/cjs/services/DITest.js.map +1 -0
- package/lib/cjs/services/InjectorService.js +581 -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/data/Test1.js +8 -0
- package/lib/cjs/utils/data/Test1.js.map +1 -0
- package/lib/cjs/utils/data/Test2.js +8 -0
- package/lib/cjs/utils/data/Test2.js.map +1 -0
- package/lib/cjs/utils/getConfiguration.js +20 -0
- package/lib/cjs/utils/getConfiguration.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/index.js +4 -0
- package/lib/esm/constants/index.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/index.js +16 -0
- package/lib/esm/decorators/index.js.map +1 -0
- package/lib/esm/decorators/inject.js +74 -0
- package/lib/esm/decorators/inject.js.map +1 -0
- package/lib/esm/decorators/injectable.js +30 -0
- package/lib/esm/decorators/injectable.js.map +1 -0
- package/lib/esm/decorators/intercept.js +24 -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 +27 -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/domain/index.js +9 -0
- package/lib/esm/domain/index.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 +18 -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/IProvider.js +2 -0
- package/lib/esm/interfaces/IProvider.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/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/index.js +15 -0
- package/lib/esm/interfaces/index.js.map +1 -0
- package/lib/esm/registries/GlobalProviders.js +120 -0
- package/lib/esm/registries/GlobalProviders.js.map +1 -0
- package/lib/esm/registries/ProviderRegistry.js +80 -0
- package/lib/esm/registries/ProviderRegistry.js.map +1 -0
- package/lib/esm/services/DIConfiguration.js +125 -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 +104 -0
- package/lib/esm/services/DITest.js.map +1 -0
- package/lib/esm/services/InjectorService.js +578 -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/data/Test1.js +4 -0
- package/lib/esm/utils/data/Test1.js.map +1 -0
- package/lib/esm/utils/data/Test2.js +4 -0
- package/lib/esm/utils/data/Test2.js.map +1 -0
- package/lib/esm/utils/getConfiguration.js +16 -0
- package/lib/esm/utils/getConfiguration.js.map +1 -0
- package/lib/esm/utils/setLoggerLevel.js +12 -0
- package/lib/esm/utils/setLoggerLevel.js.map +1 -0
- package/lib/{constants → types/constants}/index.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 +0 -0
- package/lib/{decorators → types/decorators}/index.d.ts +1 -0
- package/lib/{decorators → types/decorators}/inject.d.ts +2 -0
- package/lib/{decorators → types/decorators}/injectable.d.ts +2 -1
- package/lib/{decorators → types/decorators}/intercept.d.ts +0 -0
- 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 +0 -0
- 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 +2 -3
- package/lib/{domain → types/domain}/ContextLogger.d.ts +0 -0
- package/lib/{domain → types/domain}/DIContext.d.ts +0 -0
- 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 +16 -0
- package/lib/{domain → types/domain}/ProviderScope.d.ts +0 -0
- package/lib/{domain → types/domain}/ProviderType.d.ts +0 -0
- package/lib/{domain → types/domain}/index.d.ts +0 -0
- package/lib/{errors → types/errors}/InjectionError.d.ts +0 -0
- package/lib/{errors → types/errors}/UndefinedTokenError.d.ts +0 -0
- package/lib/{index.d.ts → types/index.d.ts} +1 -0
- package/lib/{interfaces → types/interfaces}/DIConfigurationOptions.d.ts +0 -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}/IProvider.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 → types/interfaces}/RegistrySettings.d.ts +6 -2
- package/lib/types/interfaces/ResolvedInvokeOptions.d.ts +12 -0
- package/lib/{interfaces → types/interfaces}/TokenProvider.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/index.d.ts +1 -0
- package/lib/{registries → types/registries}/GlobalProviders.d.ts +5 -1
- package/lib/{registries → types/registries}/ProviderRegistry.d.ts +0 -0
- package/lib/{services → types/services}/DIConfiguration.d.ts +0 -0
- package/lib/{services → types/services}/DILogger.d.ts +0 -0
- package/lib/{services → types/services}/DITest.d.ts +5 -1
- package/lib/{services → types/services}/InjectorService.d.ts +32 -8
- package/lib/types/utils/colors.d.ts +5 -0
- package/lib/{utils → types/utils}/createContainer.d.ts +0 -0
- package/lib/types/utils/data/Test1.d.ts +3 -0
- package/lib/types/utils/data/Test2.d.ts +3 -0
- package/lib/{utils → types/utils}/getConfiguration.d.ts +0 -0
- package/lib/{utils → types/utils}/setLoggerLevel.d.ts +0 -0
- package/package.json +15 -14
- package/tsconfig.compile.esm.json +24 -0
- 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
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"Test1.js","sourceRoot":"","sources":["../../../../src/utils/data/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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Test2.js","sourceRoot":"","sources":["../../../../src/utils/data/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"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConfiguration = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
function getConfiguration(module, configuration = {}) {
|
|
6
|
+
const store = core_1.Store.from(module).get("configuration") || {};
|
|
7
|
+
const config = {
|
|
8
|
+
...store,
|
|
9
|
+
...configuration
|
|
10
|
+
};
|
|
11
|
+
if (store.mount && configuration.mount) {
|
|
12
|
+
config.mount = (0, core_1.deepMerge)(store.mount, configuration.mount);
|
|
13
|
+
}
|
|
14
|
+
if (store.componentsScan && configuration.componentsScan) {
|
|
15
|
+
config.componentsScan = [...store.componentsScan, ...configuration.componentsScan];
|
|
16
|
+
}
|
|
17
|
+
return config;
|
|
18
|
+
}
|
|
19
|
+
exports.getConfiguration = getConfiguration;
|
|
20
|
+
//# sourceMappingURL=getConfiguration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getConfiguration.js","sourceRoot":"","sources":["../../../src/utils/getConfiguration.ts"],"names":[],"mappings":";;;AAAA,qCAAkD;AAElD,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,IAAA,gBAAS,EAAC,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;KAC5D;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 {deepMerge, Store, Type} from \"@tsed/core\";\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 = deepMerge(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,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":"index.js","sourceRoot":"","sources":["../../../src/constants/index.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";
|
|
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";
|
|
3
|
+
import { InjectablePropertyType } from "../domain/InjectablePropertyType";
|
|
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,cAAc,CAAC;AAE7C,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\";\nimport type {InjectableProperties} from \"../interfaces\";\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";
|
|
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 {IProvider} from \"../interfaces/IProvider\";\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<IProvider<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,16 @@
|
|
|
1
|
+
export * from "./scope";
|
|
2
|
+
export * from "./service";
|
|
3
|
+
export * from "./overrideProvider";
|
|
4
|
+
export * from "./inject";
|
|
5
|
+
export * from "./lazyInject";
|
|
6
|
+
export * from "./injectable";
|
|
7
|
+
export * from "./constant";
|
|
8
|
+
export * from "./value";
|
|
9
|
+
export * from "./intercept";
|
|
10
|
+
export * from "./interceptor";
|
|
11
|
+
export * from "./configuration";
|
|
12
|
+
export * from "./module";
|
|
13
|
+
export * from "./opts";
|
|
14
|
+
export * from "./useOpts";
|
|
15
|
+
export * from "./controller";
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC","sourcesContent":["export * from \"./scope\";\nexport * from \"./service\";\nexport * from \"./overrideProvider\";\nexport * from \"./inject\";\nexport * from \"./lazyInject\";\nexport * from \"./injectable\";\nexport * from \"./constant\";\nexport * from \"./value\";\nexport * from \"./intercept\";\nexport * from \"./interceptor\";\nexport * from \"./configuration\";\nexport * from \"./module\";\nexport * from \"./opts\";\nexport * from \"./useOpts\";\nexport * from \"./controller\";\n"]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { decoratorTypeOf, DecoratorTypes, isPromise, Metadata, Store, UnsupportedDecoratorType } from "@tsed/core";
|
|
2
|
+
import { DI_PARAM_OPTIONS, INJECTABLE_PROP } from "../constants";
|
|
3
|
+
export function injectProperty(target, propertyKey, options) {
|
|
4
|
+
Store.from(target).merge(INJECTABLE_PROP, {
|
|
5
|
+
[propertyKey]: {
|
|
6
|
+
bindingType: DecoratorTypes.PROP,
|
|
7
|
+
propertyKey,
|
|
8
|
+
...options
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Inject a provider to another provider.
|
|
14
|
+
*
|
|
15
|
+
* Use this decorator to inject a custom provider on constructor parameter or property.
|
|
16
|
+
*
|
|
17
|
+
* ```typescript
|
|
18
|
+
* @Injectable()
|
|
19
|
+
* export class MyService {
|
|
20
|
+
* @Inject(CONNECTION)
|
|
21
|
+
* connection: CONNECTION;
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param symbol
|
|
26
|
+
* @param onGet Use the given name method to inject
|
|
27
|
+
* @returns {Function}
|
|
28
|
+
* @decorator
|
|
29
|
+
*/
|
|
30
|
+
export function Inject(symbol, onGet = (bean) => bean) {
|
|
31
|
+
return (target, propertyKey, descriptor) => {
|
|
32
|
+
const bindingType = decoratorTypeOf([target, propertyKey, descriptor]);
|
|
33
|
+
switch (bindingType) {
|
|
34
|
+
case DecoratorTypes.PARAM:
|
|
35
|
+
case DecoratorTypes.PARAM_CTOR:
|
|
36
|
+
if (symbol) {
|
|
37
|
+
const paramTypes = Metadata.getParamTypes(target, propertyKey);
|
|
38
|
+
paramTypes[descriptor] = symbol;
|
|
39
|
+
Metadata.setParamTypes(target, propertyKey, paramTypes);
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
case DecoratorTypes.PROP:
|
|
43
|
+
injectProperty(target, propertyKey, {
|
|
44
|
+
resolver(injector, locals, { options, ...invokeOptions }) {
|
|
45
|
+
locals.set(DI_PARAM_OPTIONS, { ...options });
|
|
46
|
+
let bean;
|
|
47
|
+
if (!bean) {
|
|
48
|
+
const useType = symbol || Metadata.getType(target, propertyKey);
|
|
49
|
+
bean = injector.invoke(useType, locals, invokeOptions);
|
|
50
|
+
locals.delete(DI_PARAM_OPTIONS);
|
|
51
|
+
}
|
|
52
|
+
if (isPromise(bean)) {
|
|
53
|
+
bean.then((result) => {
|
|
54
|
+
bean = result;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return () => onGet(bean);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
break;
|
|
61
|
+
case DecoratorTypes.METHOD:
|
|
62
|
+
Store.from(target).merge(INJECTABLE_PROP, {
|
|
63
|
+
[propertyKey]: {
|
|
64
|
+
bindingType,
|
|
65
|
+
propertyKey
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return descriptor;
|
|
69
|
+
default:
|
|
70
|
+
throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# 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,cAAc,CAAC;AAG/D,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","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, isPromise, Metadata, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants\";\nimport type {InjectablePropertyOptions} from \"../interfaces/InjectableProperties\";\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"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { registerProvider } from "../registries/ProviderRegistry";
|
|
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
|
+
* <<< @/docs/snippets/providers/getting-started-injectable.ts
|
|
7
|
+
*
|
|
8
|
+
* ::: tip
|
|
9
|
+
* `@Injectable()` use the `reflect-metadata` to collect and inject the built provided to other services.
|
|
10
|
+
* :::
|
|
11
|
+
*
|
|
12
|
+
* ### Options
|
|
13
|
+
*
|
|
14
|
+
* - type (@@ProviderType@@ or `string`): Kind of provider. (Default: `ProviderType.PROVIDER`)
|
|
15
|
+
* - scope (@@ProviderScope@@): Kind of provider. (Default: `ProviderScope.SINGLETON`)
|
|
16
|
+
* - provide (@@TokenProvider@@): An injection token (Note: This option override default metadata generated by Typescript).
|
|
17
|
+
* - deps (`Type<any>`): List of class or provider which will be injected to the constructor (Note: This options override default metadata generated by Typescript).
|
|
18
|
+
*
|
|
19
|
+
* @returns {Function}
|
|
20
|
+
* @decorator
|
|
21
|
+
*/
|
|
22
|
+
export function Injectable(options = {}) {
|
|
23
|
+
return (target) => {
|
|
24
|
+
registerProvider({
|
|
25
|
+
...options,
|
|
26
|
+
...(options.provide ? { useClass: target } : { provide: target })
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# 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;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,UAAU,CAAC,UAA8B,EAAE;IACzD,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 {IProvider} from \"../interfaces\";\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 * <<< @/docs/snippets/providers/getting-started-injectable.ts\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<IProvider> = {}): ClassDecorator {\n return (target: any) => {\n registerProvider({\n ...options,\n ...(options.provide ? {useClass: target} : {provide: target})\n });\n };\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Store } from "@tsed/core";
|
|
2
|
+
import { INJECTABLE_PROP } from "../constants";
|
|
3
|
+
import { InjectablePropertyType } from "../domain";
|
|
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 (target, propertyKey, descriptor) => {
|
|
13
|
+
Store.from(target).merge(INJECTABLE_PROP, {
|
|
14
|
+
[propertyKey]: {
|
|
15
|
+
bindingType: InjectablePropertyType.INTERCEPTOR,
|
|
16
|
+
propertyKey,
|
|
17
|
+
useType: interceptor,
|
|
18
|
+
options
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return descriptor;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=intercept.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../src/decorators/intercept.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAO,MAAM,YAAY,CAAC;AACvC,OAAO,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAC,sBAAsB,EAAC,MAAM,WAAW,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAA+B,WAAoB,EAAE,OAAa;IACzF,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAA8B,EAAE,EAAE;QAC1E,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE;YACxC,CAAC,WAAW,CAAC,EAAE;gBACb,WAAW,EAAE,sBAAsB,CAAC,WAAW;gBAC/C,WAAW;gBACX,OAAO,EAAE,WAAW;gBACpB,OAAO;aACR;SACsB,CAAC,CAAC;QAE3B,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Store, Type} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants\";\nimport type {InjectableProperties, InterceptorMethods} from \"../interfaces\";\nimport {InjectablePropertyType} from \"../domain\";\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): MethodDecorator {\n return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: InjectablePropertyType.INTERCEPTOR,\n propertyKey,\n useType: interceptor,\n options\n }\n } as InjectableProperties);\n\n return descriptor;\n };\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ProviderType } from "../domain/ProviderType";
|
|
2
|
+
import { Injectable } from "./injectable";
|
|
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";
|
|
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,27 @@
|
|
|
1
|
+
import { useDecorators } from "@tsed/core";
|
|
2
|
+
import { ProviderScope, ProviderType } from "../domain";
|
|
3
|
+
import { Configuration } from "./configuration";
|
|
4
|
+
import { Injectable } from "./injectable";
|
|
5
|
+
/**
|
|
6
|
+
* Declare a new Ts.ED module
|
|
7
|
+
*
|
|
8
|
+
* ## Options
|
|
9
|
+
* - imports: List of Provider which must be built by injector before invoking the module
|
|
10
|
+
* - resolvers: List of external DI must be used to resolve unknown provider
|
|
11
|
+
* - deps: List of provider must be injected to the module constructor (explicit declaration)
|
|
12
|
+
*
|
|
13
|
+
* @param options
|
|
14
|
+
* @decorator
|
|
15
|
+
*/
|
|
16
|
+
export function Module(options = {}) {
|
|
17
|
+
const { scopes, imports, resolvers, deps, scope, ...configuration } = options;
|
|
18
|
+
return useDecorators(Configuration(configuration), Injectable({
|
|
19
|
+
type: ProviderType.MODULE,
|
|
20
|
+
scope: ProviderScope.SINGLETON,
|
|
21
|
+
imports,
|
|
22
|
+
deps,
|
|
23
|
+
injectable: false,
|
|
24
|
+
resolvers
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../src/decorators/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,aAAa,EAAE,YAAY,EAAC,MAAM,WAAW,CAAC;AAEtD,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AA0BxC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,MAAM,CAAC,UAAkC,EAAE;IACzD,MAAM,EAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,aAAa,EAAC,GAAG,OAAO,CAAC;IAE5E,OAAO,aAAa,CAClB,aAAa,CAAC,aAAa,CAAC,EAC5B,UAAU,CAAC;QACT,IAAI,EAAE,YAAY,CAAC,MAAM;QACzB,KAAK,EAAE,aAAa,CAAC,SAAS;QAC9B,OAAO;QACP,IAAI;QACJ,UAAU,EAAE,KAAK;QACjB,SAAS;KACV,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {useDecorators} from \"@tsed/core\";\nimport {ProviderScope, ProviderType} from \"../domain\";\nimport type {DIResolver, TokenProvider} from \"../interfaces\";\nimport {Configuration} from \"./configuration\";\nimport {Injectable} from \"./injectable\";\n\nexport interface ModuleOptions extends Omit<TsED.Configuration, \"scopes\"> {\n /**\n * Provider scope\n */\n scope?: ProviderScope;\n /**\n * Providers must be initialized before building this module\n */\n imports?: TokenProvider[];\n /**\n * Explicit token must be injected in the constructor\n */\n deps?: TokenProvider[];\n /**\n * A list of resolvers to inject provider from external DI.\n */\n resolvers?: DIResolver[];\n\n /**\n * Additional properties are stored as provider configuration.\n */\n [key: string]: any;\n}\n\n/**\n * Declare a new Ts.ED module\n *\n * ## Options\n * - imports: List of Provider which must be built by injector before invoking the module\n * - resolvers: List of external DI must be used to resolve unknown provider\n * - deps: List of provider must be injected to the module constructor (explicit declaration)\n *\n * @param options\n * @decorator\n */\nexport function Module(options: Partial<ModuleOptions> = {}) {\n const {scopes, imports, resolvers, deps, scope, ...configuration} = options;\n\n return useDecorators(\n Configuration(configuration),\n Injectable({\n type: ProviderType.MODULE,\n scope: ProviderScope.SINGLETON,\n imports,\n deps,\n injectable: false,\n resolvers\n })\n );\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { classOf } from "@tsed/core";
|
|
2
|
+
import { DI_PARAM_OPTIONS } from "../constants";
|
|
3
|
+
import { ProviderScope } from "../domain/ProviderScope";
|
|
4
|
+
import { Inject } from "./inject";
|
|
5
|
+
import { Scope } from "./scope";
|
|
6
|
+
/**
|
|
7
|
+
* Get instance options. This options depending on his invocation context.
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import {Injectable, Opts, UseOpts} from "@tsed/di";
|
|
11
|
+
*
|
|
12
|
+
* @Injectable()
|
|
13
|
+
* class MyConfigurableService {
|
|
14
|
+
* source: string;
|
|
15
|
+
* constructor(@Opts options: any = {}) {
|
|
16
|
+
* console.log("Hello ", options.source); // log: Hello Service1 then Hello Service2
|
|
17
|
+
*
|
|
18
|
+
* this.source = options.source;
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* @Injectable()
|
|
23
|
+
* class MyService1 {
|
|
24
|
+
* constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {
|
|
25
|
+
* console.log(service.source) // log: Service1
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* @Injectable()
|
|
30
|
+
* class MyService2 {
|
|
31
|
+
* constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {
|
|
32
|
+
* console.log(service.source) // log: Service2
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* ::: warning
|
|
38
|
+
* Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.
|
|
39
|
+
* :::
|
|
40
|
+
*
|
|
41
|
+
* @param target
|
|
42
|
+
* @param propertyKey
|
|
43
|
+
* @param index
|
|
44
|
+
* @decorator
|
|
45
|
+
*/
|
|
46
|
+
export function Opts(target, propertyKey, index) {
|
|
47
|
+
Scope(ProviderScope.INSTANCE)(classOf(target));
|
|
48
|
+
Inject(DI_PARAM_OPTIONS)(target, propertyKey, index);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=opts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opts.js","sourceRoot":"","sources":["../../../src/decorators/opts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AACnC,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,IAAI,CAAC,MAAW,EAAE,WAA4B,EAAE,KAAa;IAC3E,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,MAAM,CAAC,gBAAgB,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import {classOf} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS} from \"../constants\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\nimport {Inject} from \"./inject\";\nimport {Scope} from \"./scope\";\n\n/**\n * Get instance options. This options depending on his invocation context.\n *\n * ```typescript\n * import {Injectable, Opts, UseOpts} from \"@tsed/di\";\n *\n * @Injectable()\n * class MyConfigurableService {\n * source: string;\n * constructor(@Opts options: any = {}) {\n * console.log(\"Hello \", options.source); // log: Hello Service1 then Hello Service2\n *\n * this.source = options.source;\n * }\n * }\n *\n * @Injectable()\n * class MyService1 {\n * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service1\n * }\n * }\n *\n * @Injectable()\n * class MyService2 {\n * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service2\n * }\n * }\n * ```\n *\n * ::: warning\n * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.\n * :::\n *\n * @param target\n * @param propertyKey\n * @param index\n * @decorator\n */\nexport function Opts(target: any, propertyKey: string | symbol, index: number) {\n Scope(ProviderScope.INSTANCE)(classOf(target));\n Inject(DI_PARAM_OPTIONS)(target, propertyKey, index);\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GlobalProviders } from "../registries/GlobalProviders";
|
|
2
|
+
/**
|
|
3
|
+
* Override a provider which is already registered in ProviderRegistry.
|
|
4
|
+
* @returns {Function}
|
|
5
|
+
* @decorators
|
|
6
|
+
* @param originalProvider
|
|
7
|
+
*/
|
|
8
|
+
export function OverrideProvider(originalProvider) {
|
|
9
|
+
return (target) => {
|
|
10
|
+
GlobalProviders.get(originalProvider).useClass = target;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=overrideProvider.js.map
|