@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,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UseOpts = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
|
+
/**
|
|
7
|
+
* Add options to invoke the Service.
|
|
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
|
+
* @returns {Function}
|
|
42
|
+
* @decorator
|
|
43
|
+
* @param options
|
|
44
|
+
*/
|
|
45
|
+
function UseOpts(options) {
|
|
46
|
+
return (target, propertyKey, index) => {
|
|
47
|
+
const bindingType = (0, core_1.decoratorTypeOf)([target, propertyKey, index]);
|
|
48
|
+
switch (bindingType) {
|
|
49
|
+
case core_1.DecoratorTypes.PARAM_CTOR:
|
|
50
|
+
core_1.Store.from(target).merge(`${constants_1.DI_PARAM_OPTIONS}:${index}`, options);
|
|
51
|
+
break;
|
|
52
|
+
case core_1.DecoratorTypes.PROP:
|
|
53
|
+
core_1.Store.from(target).merge(constants_1.INJECTABLE_PROP, {
|
|
54
|
+
[propertyKey]: {
|
|
55
|
+
options
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
throw new core_1.UnsupportedDecoratorType(UseOpts, [target, propertyKey, index]);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
exports.UseOpts = UseOpts;
|
|
65
|
+
//# sourceMappingURL=useOpts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOpts.js","sourceRoot":"","sources":["../../../src/decorators/useOpts.ts"],"names":[],"mappings":";;;AAAA,qCAA4F;AAC5F,sDAAyE;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,SAAgB,OAAO,CAAC,OAA6B;IACnD,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,KAAc,EAAO,EAAE;QAC3E,MAAM,WAAW,GAAG,IAAA,sBAAe,EAAC,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;QAElE,QAAQ,WAAW,EAAE;YACnB,KAAK,qBAAc,CAAC,UAAU;gBAC5B,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,4BAAgB,IAAI,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;gBAClE,MAAM;YAER,KAAK,qBAAc,CAAC,IAAI;gBACtB,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,2BAAe,EAAE;oBACxC,CAAC,WAAqB,CAAC,EAAE;wBACvB,OAAO;qBACR;iBACF,CAAC,CAAC;gBACH,MAAM;YAER;gBACE,MAAM,IAAI,+BAAwB,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;SAC7E;IACH,CAAC,CAAC;AACJ,CAAC;AArBD,0BAqBC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\n\n/**\n * Add options to invoke the Service.\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 * @returns {Function}\n * @decorator\n * @param options\n */\nexport function UseOpts(options: {[key: string]: any}): Function {\n return (target: Object, propertyKey: string | symbol, index?: number): any => {\n const bindingType = decoratorTypeOf([target, propertyKey, index]);\n\n switch (bindingType) {\n case DecoratorTypes.PARAM_CTOR:\n Store.from(target).merge(`${DI_PARAM_OPTIONS}:${index}`, options);\n break;\n\n case DecoratorTypes.PROP:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey as string]: {\n options\n }\n });\n break;\n\n default:\n throw new UnsupportedDecoratorType(UseOpts, [target, propertyKey, index]);\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Value = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
|
+
const InjectablePropertyType_1 = require("../domain/InjectablePropertyType");
|
|
7
|
+
/**
|
|
8
|
+
* Return value from Configuration.
|
|
9
|
+
*
|
|
10
|
+
* ## Example
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import {Env} from "@tsed/core";
|
|
14
|
+
* import {Constant, Value} from "@tsed/di";
|
|
15
|
+
*
|
|
16
|
+
* export class MyClass {
|
|
17
|
+
*
|
|
18
|
+
* @Constant("env")
|
|
19
|
+
* env: Env;
|
|
20
|
+
*
|
|
21
|
+
* @Value("swagger.path")
|
|
22
|
+
* swaggerPath: string;
|
|
23
|
+
*
|
|
24
|
+
* @Value("swagger.path", "defaultValue")
|
|
25
|
+
* swaggerPath: string;
|
|
26
|
+
*
|
|
27
|
+
* constructor() {
|
|
28
|
+
* console.log(this.swaggerPath) // undefined. Not available on constructor
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* $onInit() {
|
|
32
|
+
* console.log(this.swaggerPath) // something
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @param expression
|
|
38
|
+
* @param defaultValue
|
|
39
|
+
* @returns {(targetClass: any, attributeName: string) => any}
|
|
40
|
+
* @decorator
|
|
41
|
+
*/
|
|
42
|
+
function Value(expression, defaultValue) {
|
|
43
|
+
return (target, propertyKey) => {
|
|
44
|
+
core_1.Store.from(target).merge(constants_1.INJECTABLE_PROP, {
|
|
45
|
+
[propertyKey]: {
|
|
46
|
+
bindingType: InjectablePropertyType_1.InjectablePropertyType.VALUE,
|
|
47
|
+
propertyKey,
|
|
48
|
+
expression,
|
|
49
|
+
defaultValue
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
exports.Value = Value;
|
|
55
|
+
//# sourceMappingURL=value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../../src/decorators/value.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,sDAAuD;AAEvD,6EAAwE;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,SAAgB,KAAK,CAAC,UAAe,EAAE,YAAkB;IACvD,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,2BAAe,EAAE;YACxC,CAAC,WAAW,CAAC,EAAE;gBACb,WAAW,EAAE,+CAAsB,CAAC,KAAK;gBACzC,WAAW;gBACX,UAAU;gBACV,YAAY;aACb;SACsB,CAAC,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC;AAXD,sBAWC","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 expression\n * @param defaultValue\n * @returns {(targetClass: any, attributeName: string) => any}\n * @decorator\n */\nexport function Value(expression: any, defaultValue?: any) {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: InjectablePropertyType.VALUE,\n propertyKey,\n expression,\n defaultValue\n }\n } as InjectableProperties);\n };\n}\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Container = void 0;
|
|
4
|
+
const GlobalProviders_1 = require("../registries/GlobalProviders");
|
|
5
|
+
const Provider_1 = require("./Provider");
|
|
6
|
+
class Container extends Map {
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param token
|
|
10
|
+
* @param settings
|
|
11
|
+
*/
|
|
12
|
+
add(token, settings = {}) {
|
|
13
|
+
var _a;
|
|
14
|
+
const provider = ((_a = GlobalProviders_1.GlobalProviders.get(token)) === null || _a === void 0 ? void 0 : _a.clone()) || new Provider_1.Provider(token);
|
|
15
|
+
Object.assign(provider, settings);
|
|
16
|
+
return super.set(token, provider);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Add a provider to the
|
|
20
|
+
* @param token
|
|
21
|
+
* @param settings
|
|
22
|
+
*/
|
|
23
|
+
addProvider(token, settings = {}) {
|
|
24
|
+
return this.add(token, settings);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param token
|
|
29
|
+
*/
|
|
30
|
+
hasProvider(token) {
|
|
31
|
+
return super.has(token);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Add a provider to the
|
|
35
|
+
* @param token
|
|
36
|
+
* @param provider
|
|
37
|
+
*/
|
|
38
|
+
setProvider(token, provider) {
|
|
39
|
+
return super.set(token, provider);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The getProvider() method returns a specified element from a Map object.
|
|
43
|
+
* @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.
|
|
44
|
+
* @param token
|
|
45
|
+
*/
|
|
46
|
+
getProvider(token) {
|
|
47
|
+
return super.get(token);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get all providers registered in the injector container.
|
|
51
|
+
*
|
|
52
|
+
* @param {ProviderType} type Filter the list by the given ProviderType.
|
|
53
|
+
* @returns {[TokenProvider , Provider<any>][]}
|
|
54
|
+
*/
|
|
55
|
+
getProviders(type) {
|
|
56
|
+
return [...this].reduce((providers, [_, provider]) => {
|
|
57
|
+
if (provider.type === type || !type) {
|
|
58
|
+
return [...providers, provider];
|
|
59
|
+
}
|
|
60
|
+
return providers;
|
|
61
|
+
}, []);
|
|
62
|
+
}
|
|
63
|
+
addProviders(container) {
|
|
64
|
+
container.forEach((provider) => {
|
|
65
|
+
if (!this.hasProvider(provider.provide)) {
|
|
66
|
+
this.setProvider(provider.provide, provider.clone());
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.Container = Container;
|
|
72
|
+
//# sourceMappingURL=Container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Container.js","sourceRoot":"","sources":["../../../src/domain/Container.ts"],"names":[],"mappings":";;;AAGA,mEAA8D;AAC9D,yCAAoC;AAEpC,MAAa,SAAU,SAAQ,GAA4B;IACzD;;;;OAIG;IACI,GAAG,CAAC,KAAoB,EAAE,WAAkC,EAAE;;QACnE,MAAM,QAAQ,GAAG,CAAA,MAAA,iCAAe,CAAC,GAAG,CAAC,KAAK,CAAC,0CAAE,KAAK,EAAE,KAAI,IAAI,mBAAQ,CAAC,KAAK,CAAC,CAAC;QAE5E,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAElC,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,KAAoB,EAAE,WAAkC,EAAE;QAC3E,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,WAAW,CAAC,KAAoB;QACrC,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,KAAoB,EAAE,QAAkB;QACzD,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAgC,KAAoB;QACpE,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAM,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACI,YAAY,CAAC,IAA4B;QAC9C,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,EAAE;YACnD,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE;gBACnC,OAAO,CAAC,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAC;aACjC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;IAEM,YAAY,CAAC,SAAuC;QACzD,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC7B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;gBACvC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;aACtD;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAvED,8BAuEC","sourcesContent":["import type {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport type {ProviderType} from \"./ProviderType\";\nimport type {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {Provider} from \"./Provider\";\n\nexport class Container extends Map<TokenProvider, Provider> {\n /**\n *\n * @param token\n * @param settings\n */\n public add(token: TokenProvider, settings: Partial<ProviderOpts> = {}): this {\n const provider = GlobalProviders.get(token)?.clone() || new Provider(token);\n\n Object.assign(provider, settings);\n\n return super.set(token, provider);\n }\n\n /**\n * Add a provider to the\n * @param token\n * @param settings\n */\n public addProvider(token: TokenProvider, settings: Partial<ProviderOpts> = {}): this {\n return this.add(token, settings);\n }\n\n /**\n *\n * @param token\n */\n public hasProvider(token: TokenProvider) {\n return super.has(token);\n }\n\n /**\n * Add a provider to the\n * @param token\n * @param provider\n */\n public setProvider(token: TokenProvider, provider: Provider) {\n return super.set(token, provider);\n }\n\n /**\n * The getProvider() method returns a specified element from a Map object.\n * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.\n * @param token\n */\n public getProvider<T extends Provider = Provider>(token: TokenProvider): T | undefined {\n return super.get(token) as T;\n }\n\n /**\n * Get all providers registered in the injector container.\n *\n * @param {ProviderType} type Filter the list by the given ProviderType.\n * @returns {[TokenProvider , Provider<any>][]}\n */\n public getProviders(type?: ProviderType | string): Provider[] {\n return [...this].reduce((providers, [_, provider]) => {\n if (provider.type === type || !type) {\n return [...providers, provider];\n }\n return providers;\n }, []);\n }\n\n public addProviders(container: Map<TokenProvider, Provider>) {\n container.forEach((provider) => {\n if (!this.hasProvider(provider.provide)) {\n this.setProvider(provider.provide, provider.clone());\n }\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContextLogger = void 0;
|
|
4
|
+
const logger_1 = require("@tsed/logger");
|
|
5
|
+
class ContextLogger {
|
|
6
|
+
constructor(logger, { id, url = "", dateStart = new Date(), ignoreUrlPatterns = [], minimalRequestPicker, completeRequestPicker, level = "all", maxStackSize = 30, ignoreLog, additionalProps }) {
|
|
7
|
+
this.logger = logger;
|
|
8
|
+
this.stack = [];
|
|
9
|
+
this.id = id;
|
|
10
|
+
this.url = url;
|
|
11
|
+
this.additionalProps = additionalProps || {};
|
|
12
|
+
this.dateStart = dateStart;
|
|
13
|
+
this.ignoreLog = ignoreLog || (() => false);
|
|
14
|
+
this.minimalRequestPicker = minimalRequestPicker || ((l) => l);
|
|
15
|
+
this.completeRequestPicker = completeRequestPicker || ((l) => l);
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
this.level = (0, logger_1.levels)()[level.toUpperCase()] || (0, logger_1.levels)().ALL;
|
|
18
|
+
this.maxStackSize = maxStackSize;
|
|
19
|
+
}
|
|
20
|
+
info(obj) {
|
|
21
|
+
this.run((0, logger_1.levels)().INFO, obj, (obj) => this.minimalRequestPicker(this.getData(obj)));
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
debug(obj, withRequest = true) {
|
|
25
|
+
this.run((0, logger_1.levels)().DEBUG, obj, (obj) => {
|
|
26
|
+
obj = this.getData(obj);
|
|
27
|
+
return withRequest ? this.completeRequestPicker(obj) : obj;
|
|
28
|
+
});
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
warn(obj) {
|
|
32
|
+
this.run((0, logger_1.levels)().WARN, obj, (obj) => this.completeRequestPicker(this.getData(obj)));
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
error(obj) {
|
|
36
|
+
this.run((0, logger_1.levels)().ERROR, obj, (obj) => this.completeRequestPicker(this.getData(obj)));
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
trace(obj) {
|
|
40
|
+
this.run((0, logger_1.levels)().TRACE, obj, (obj) => this.completeRequestPicker(this.getData(obj)));
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
flush() {
|
|
44
|
+
if (this.stack.length) {
|
|
45
|
+
this.stack.forEach(({ level, data }) => {
|
|
46
|
+
this.logger[level](data);
|
|
47
|
+
});
|
|
48
|
+
this.stack = [];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
isLevelEnabled(otherLevel) {
|
|
52
|
+
return this.level.isLessThanOrEqualTo(otherLevel);
|
|
53
|
+
}
|
|
54
|
+
destroy() {
|
|
55
|
+
this.flush();
|
|
56
|
+
this.logger = undefined;
|
|
57
|
+
this.stack = undefined;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Return the duration between the time when LogIncomingRequest has handle the request and now.
|
|
61
|
+
* @returns {number}
|
|
62
|
+
*/
|
|
63
|
+
getDuration() {
|
|
64
|
+
return new Date().getTime() - this.dateStart.getTime();
|
|
65
|
+
}
|
|
66
|
+
getData(obj) {
|
|
67
|
+
if (typeof obj === "string") {
|
|
68
|
+
obj = { message: obj };
|
|
69
|
+
}
|
|
70
|
+
return { ...this.additionalProps, reqId: this.id, time: new Date(), duration: this.getDuration(), ...obj };
|
|
71
|
+
}
|
|
72
|
+
run(level, obj, mapper) {
|
|
73
|
+
if (!this.isLevelEnabled(level)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (!this.ignoreLog(obj)) {
|
|
77
|
+
this.stack.push({ level: level.levelStr.toLowerCase(), data: mapper(obj) });
|
|
78
|
+
}
|
|
79
|
+
if (this.maxStackSize < this.stack.length) {
|
|
80
|
+
this.flush();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.ContextLogger = ContextLogger;
|
|
85
|
+
//# sourceMappingURL=ContextLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextLogger.js","sourceRoot":"","sources":["../../../src/domain/ContextLogger.ts"],"names":[],"mappings":";;;AAAA,yCAA8C;AAc9C,MAAa,aAAa;IAYxB,YACU,MAAW,EACnB,EACE,EAAE,EACF,GAAG,GAAG,EAAE,EACR,SAAS,GAAG,IAAI,IAAI,EAAE,EACtB,iBAAiB,GAAG,EAAE,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,GAAG,KAAK,EACb,YAAY,GAAG,EAAE,EACjB,SAAS,EACT,eAAe,EACM;QAZf,WAAM,GAAN,MAAM,CAAK;QAJb,UAAK,GAAQ,EAAE,CAAC;QAkBtB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,eAAe,GAAG,eAAe,IAAI,EAAE,CAAC;QAC7C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QACpE,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,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AE,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,GAAG,GAAG,EAAC,CAAC;IAC3G,CAAC;IAES,GAAG,CAAC,KAAe,EAAE,GAAQ,EAAE,MAA0B;QACjE,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;YAC/B,OAAO;SACR;QAED,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;YACxB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,EAAC,CAAC,CAAC;SAC3E;QAED,IAAI,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;YACzC,IAAI,CAAC,KAAK,EAAE,CAAC;SACd;IACH,CAAC;CACF;AArHD,sCAqHC","sourcesContent":["import {levels, LogLevel} from \"@tsed/logger\";\n\nexport interface ContextLoggerOptions extends Record<string, any> {\n id: string;\n url?: string;\n dateStart?: Date;\n level?: \"debug\" | \"info\" | \"warn\" | \"error\" | \"off\" | \"all\";\n maxStackSize?: number;\n minimalRequestPicker?: (o: any) => any;\n completeRequestPicker?: (o: any) => any;\n ignoreLog?: (data: any) => boolean;\n additionalProps?: Record<any, any>;\n}\n\nexport class ContextLogger {\n id: string;\n url: string;\n minimalRequestPicker: Function;\n completeRequestPicker: Function;\n maxStackSize: number;\n private readonly additionalProps: Record<string, unknown>;\n private readonly dateStart: Date;\n private readonly ignoreLog: (data: any) => boolean;\n private stack: any = [];\n private level: LogLevel;\n\n constructor(\n private logger: any,\n {\n id,\n url = \"\",\n dateStart = new Date(),\n ignoreUrlPatterns = [],\n minimalRequestPicker,\n completeRequestPicker,\n level = \"all\",\n maxStackSize = 30,\n ignoreLog,\n additionalProps\n }: ContextLoggerOptions\n ) {\n this.id = id;\n this.url = url;\n this.additionalProps = additionalProps || {};\n this.dateStart = dateStart;\n this.ignoreLog = ignoreLog || (() => false);\n this.minimalRequestPicker = minimalRequestPicker || ((l: any) => l);\n this.completeRequestPicker = completeRequestPicker || ((l: any) => l);\n // @ts-ignore\n this.level = levels()[level.toUpperCase()] || levels().ALL;\n this.maxStackSize = maxStackSize;\n }\n\n info(obj: any) {\n this.run(levels().INFO, obj, (obj) => this.minimalRequestPicker(this.getData(obj)));\n return this;\n }\n\n debug(obj: any, withRequest: boolean = true) {\n this.run(levels().DEBUG, obj, (obj) => {\n obj = this.getData(obj);\n return withRequest ? this.completeRequestPicker(obj) : obj;\n });\n return this;\n }\n\n warn(obj: any) {\n this.run(levels().WARN, obj, (obj) => this.completeRequestPicker(this.getData(obj)));\n return this;\n }\n\n error(obj: any) {\n this.run(levels().ERROR, obj, (obj) => this.completeRequestPicker(this.getData(obj)));\n return this;\n }\n\n trace(obj: any) {\n this.run(levels().TRACE, obj, (obj) => this.completeRequestPicker(this.getData(obj)));\n return this;\n }\n\n public flush() {\n if (this.stack.length) {\n this.stack.forEach(({level, data}: any) => {\n this.logger[level](data);\n });\n\n this.stack = [];\n }\n }\n\n public isLevelEnabled(otherLevel: string | LogLevel) {\n return this.level.isLessThanOrEqualTo(otherLevel);\n }\n\n destroy() {\n this.flush();\n\n this.logger = undefined;\n this.stack = undefined;\n }\n\n /**\n * Return the duration between the time when LogIncomingRequest has handle the request and now.\n * @returns {number}\n */\n protected getDuration(): number {\n return new Date().getTime() - this.dateStart.getTime();\n }\n\n protected getData(obj: any) {\n if (typeof obj === \"string\") {\n obj = {message: obj};\n }\n\n return {...this.additionalProps, reqId: this.id, time: new Date(), duration: this.getDuration(), ...obj};\n }\n\n protected run(level: LogLevel, obj: any, mapper: (data: any) => any) {\n if (!this.isLevelEnabled(level)) {\n return;\n }\n\n if (!this.ignoreLog(obj)) {\n this.stack.push({level: level.levelStr.toLowerCase(), data: mapper(obj)});\n }\n\n if (this.maxStackSize < this.stack.length) {\n this.flush();\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DIContext = void 0;
|
|
4
|
+
const ContextLogger_1 = require("./ContextLogger");
|
|
5
|
+
const LocalsContainer_1 = require("./LocalsContainer");
|
|
6
|
+
class DIContext extends Map {
|
|
7
|
+
constructor({ id, injector, logger, ignoreLog, ...options }) {
|
|
8
|
+
super();
|
|
9
|
+
/**
|
|
10
|
+
* Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.
|
|
11
|
+
*/
|
|
12
|
+
this.dateStart = new Date();
|
|
13
|
+
/**
|
|
14
|
+
* The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`
|
|
15
|
+
*/
|
|
16
|
+
this.container = new LocalsContainer_1.LocalsContainer();
|
|
17
|
+
this.id = id;
|
|
18
|
+
injector && (this.injector = injector);
|
|
19
|
+
this.logger = new ContextLogger_1.ContextLogger(logger, {
|
|
20
|
+
...options,
|
|
21
|
+
dateStart: this.dateStart,
|
|
22
|
+
id,
|
|
23
|
+
ignoreLog
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
get env() {
|
|
27
|
+
return this.injector.settings.env;
|
|
28
|
+
}
|
|
29
|
+
async destroy() {
|
|
30
|
+
await this.container.destroy();
|
|
31
|
+
this.logger.destroy();
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
delete this.container;
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
delete this.logger;
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
delete this.injector;
|
|
38
|
+
}
|
|
39
|
+
async emit(eventName, ...args) {
|
|
40
|
+
var _a;
|
|
41
|
+
return (_a = this.injector) === null || _a === void 0 ? void 0 : _a.emit(eventName, ...args);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.DIContext = DIContext;
|
|
45
|
+
//# sourceMappingURL=DIContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":";;;AAEA,mDAAoE;AACpE,uDAAkD;AAkBlD,MAAa,SAAU,SAAQ,GAAa;IA4C1C,YAAY,EAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAmB;QACzE,KAAK,EAAE,CAAC;QAlBV;;WAEG;QACM,cAAS,GAAS,IAAI,IAAI,EAAE,CAAC;QACtC;;WAEG;QACI,cAAS,GAAG,IAAI,iCAAe,EAAO,CAAC;QAY5C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QAEb,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,CAAC,MAAM,EAAE;YACtC,GAAG,OAAO;YACV,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,EAAE;YACF,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACtB,aAAa;QACb,OAAO,IAAI,CAAC,SAAS,CAAC;QACtB,aAAa;QACb,OAAO,IAAI,CAAC,MAAM,CAAC;QACnB,aAAa;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,GAAG,IAAW;;QAC1C,OAAO,MAAA,IAAI,CAAC,QAAQ,0CAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;CACF;AA5ED,8BA4EC","sourcesContent":["import type {Env} from \"@tsed/core\";\nimport {InjectorService} from \"../services/InjectorService\";\nimport {ContextLogger, ContextLoggerOptions} from \"./ContextLogger\";\nimport {LocalsContainer} from \"./LocalsContainer\";\n\nexport interface ContextMethods extends Map<any, any> {\n readonly id: string;\n readonly logger: ContextLogger;\n readonly injector: InjectorService;\n readonly container: LocalsContainer;\n readonly env: Env;\n\n destroy(): any;\n}\n\nexport interface DIContextOptions extends Omit<ContextLoggerOptions, \"dateStart\"> {\n id: string;\n logger: any;\n injector?: InjectorService;\n}\n\nexport class DIContext extends Map<any, any> implements ContextMethods {\n [x: string]: any;\n /**\n * Request id generated by @@contextMiddleware@@.\n *\n * ::: tip\n * By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, \"\"))`.\n * Dash are removed to simplify tracking logs in Kibana\n * :::\n *\n * ::: tip\n * Request id can by customized by changing the server configuration.\n *\n * ```typescript\n * @Configuration({\n * logger: {\n * reqIdBuilder: createUniqId // give your own id generator function\n * }\n * })\n * class Server {\n *\n * }\n * ```\n * :::\n *\n */\n readonly id: string;\n /**\n * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.\n */\n readonly dateStart: Date = new Date();\n /**\n * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`\n */\n public container = new LocalsContainer<any>();\n /**\n * Logger attached to the context request.\n */\n public logger: ContextLogger;\n /**\n *\n */\n public injector: InjectorService;\n\n constructor({id, injector, logger, ignoreLog, ...options}: DIContextOptions) {\n super();\n this.id = id;\n\n injector && (this.injector = injector);\n\n this.logger = new ContextLogger(logger, {\n ...options,\n dateStart: this.dateStart,\n id,\n ignoreLog\n });\n }\n\n get env() {\n return this.injector.settings.env;\n }\n\n async destroy() {\n await this.container.destroy();\n this.logger.destroy();\n // @ts-ignore\n delete this.container;\n // @ts-ignore\n delete this.logger;\n // @ts-ignore\n delete this.injector;\n }\n\n async emit(eventName: string, ...args: any[]) {\n return this.injector?.emit(eventName, ...args);\n }\n}\n\nexport type BaseContext = DIContext & TsED.Context;\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectablePropertyType = void 0;
|
|
4
|
+
var InjectablePropertyType;
|
|
5
|
+
(function (InjectablePropertyType) {
|
|
6
|
+
InjectablePropertyType["METHOD"] = "method";
|
|
7
|
+
InjectablePropertyType["PROPERTY"] = "property";
|
|
8
|
+
InjectablePropertyType["CONSTANT"] = "constant";
|
|
9
|
+
InjectablePropertyType["VALUE"] = "value";
|
|
10
|
+
InjectablePropertyType["INTERCEPTOR"] = "interceptor";
|
|
11
|
+
})(InjectablePropertyType = exports.InjectablePropertyType || (exports.InjectablePropertyType = {}));
|
|
12
|
+
//# sourceMappingURL=InjectablePropertyType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InjectablePropertyType.js","sourceRoot":"","sources":["../../../src/domain/InjectablePropertyType.ts"],"names":[],"mappings":";;;AAAA,IAAY,sBAMX;AAND,WAAY,sBAAsB;IAChC,2CAAiB,CAAA;IACjB,+CAAqB,CAAA;IACrB,+CAAqB,CAAA;IACrB,yCAAe,CAAA;IACf,qDAA2B,CAAA;AAC7B,CAAC,EANW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAMjC","sourcesContent":["export enum InjectablePropertyType {\n METHOD = \"method\",\n PROPERTY = \"property\",\n CONSTANT = \"constant\",\n VALUE = \"value\",\n INTERCEPTOR = \"interceptor\"\n}\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalsContainer = void 0;
|
|
4
|
+
class LocalsContainer extends Map {
|
|
5
|
+
/**
|
|
6
|
+
* Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
|
|
7
|
+
* @param eventName The event name to emit at all services.
|
|
8
|
+
* @param args List of the parameters to give to each services.
|
|
9
|
+
* @returns {Promise<any[]>} A list of promises.
|
|
10
|
+
*/
|
|
11
|
+
async emit(eventName, ...args) {
|
|
12
|
+
for (const handler of this.getListeners(eventName)) {
|
|
13
|
+
await handler(...args);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @param eventName
|
|
18
|
+
* @param value
|
|
19
|
+
* @param args
|
|
20
|
+
*/
|
|
21
|
+
alter(eventName, value, ...args) {
|
|
22
|
+
for (const handler of this.getListeners(eventName)) {
|
|
23
|
+
value = handler(value, ...args);
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @param eventName
|
|
29
|
+
* @param value
|
|
30
|
+
* @param args
|
|
31
|
+
*/
|
|
32
|
+
async alterAsync(eventName, value, ...args) {
|
|
33
|
+
for (const handler of this.getListeners(eventName)) {
|
|
34
|
+
value = handler(value, ...args);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
toArray() {
|
|
39
|
+
return [...this.values()];
|
|
40
|
+
}
|
|
41
|
+
async destroy() {
|
|
42
|
+
await this.emit("$onDestroy");
|
|
43
|
+
this.clear();
|
|
44
|
+
}
|
|
45
|
+
getListeners(event) {
|
|
46
|
+
return this.toArray().reduce((listeners, instance) => {
|
|
47
|
+
if (typeof instance === "object" && instance && event in instance) {
|
|
48
|
+
return listeners.concat(instance[event].bind(instance));
|
|
49
|
+
}
|
|
50
|
+
return listeners;
|
|
51
|
+
}, []);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.LocalsContainer = LocalsContainer;
|
|
55
|
+
//# sourceMappingURL=LocalsContainer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalsContainer.js","sourceRoot":"","sources":["../../../src/domain/LocalsContainer.ts"],"names":[],"mapp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,CAAC,QAAQ,CAAC,CAAC,CAAC;aAClE;YAED,OAAO,SAAS,CAAC;QACnB,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF;AAzDD,0CAyDC","sourcesContent":["import type {TokenProvider} from \"../interfaces/TokenProvider\";\n\nexport class LocalsContainer<V = any> extends Map<TokenProvider, V> {\n /**\n * Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).\n * @param eventName The event name to emit at all services.\n * @param args List of the parameters to give to each services.\n * @returns {Promise<any[]>} A list of promises.\n */\n public async emit(eventName: string, ...args: any[]) {\n for (const handler of this.getListeners(eventName)) {\n await handler(...args);\n }\n }\n\n /**\n * @param eventName\n * @param value\n * @param args\n */\n public alter<T = any>(eventName: string, value: any, ...args: any[]): T {\n for (const handler of this.getListeners(eventName)) {\n value = handler(value, ...args);\n }\n\n return value;\n }\n\n /**\n * @param eventName\n * @param value\n * @param args\n */\n public async alterAsync<T = any>(eventName: string, value: any, ...args: any[]): Promise<T> {\n for (const handler of this.getListeners(eventName)) {\n value = handler(value, ...args);\n }\n\n return value;\n }\n\n toArray() {\n return [...this.values()];\n }\n\n async destroy() {\n await this.emit(\"$onDestroy\");\n this.clear();\n }\n\n protected getListeners(event: string): any[] {\n return this.toArray().reduce((listeners, instance) => {\n if (typeof instance === \"object\" && instance && event in instance) {\n return listeners.concat((instance as any)[event].bind(instance));\n }\n\n return listeners;\n }, []);\n }\n}\n"]}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Provider = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const ProviderScope_1 = require("./ProviderScope");
|
|
6
|
+
const ProviderType_1 = require("./ProviderType");
|
|
7
|
+
class Provider {
|
|
8
|
+
constructor(token, options = {}) {
|
|
9
|
+
this.type = ProviderType_1.ProviderType.PROVIDER;
|
|
10
|
+
this.provide = token;
|
|
11
|
+
this.useClass = token;
|
|
12
|
+
Object.assign(this, options);
|
|
13
|
+
}
|
|
14
|
+
get token() {
|
|
15
|
+
return this._provide;
|
|
16
|
+
}
|
|
17
|
+
get provide() {
|
|
18
|
+
return this._provide;
|
|
19
|
+
}
|
|
20
|
+
set provide(value) {
|
|
21
|
+
if (value) {
|
|
22
|
+
this._provide = (0, core_1.getClassOrSymbol)(value);
|
|
23
|
+
this._tokenStore = this._store = core_1.Store.from(value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
get useClass() {
|
|
27
|
+
return this._useClass;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a new store if the given value is a class. Otherwise the value is ignored.
|
|
31
|
+
* @param value
|
|
32
|
+
*/
|
|
33
|
+
set useClass(value) {
|
|
34
|
+
if ((0, core_1.isClass)(value)) {
|
|
35
|
+
this._useClass = (0, core_1.classOf)(value);
|
|
36
|
+
this._store = core_1.Store.from(value);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
get className() {
|
|
40
|
+
return this.name;
|
|
41
|
+
}
|
|
42
|
+
get name() {
|
|
43
|
+
return (0, core_1.nameOf)(this.provide);
|
|
44
|
+
}
|
|
45
|
+
get store() {
|
|
46
|
+
return this._store;
|
|
47
|
+
}
|
|
48
|
+
get path() {
|
|
49
|
+
return this.store.get("path", "/");
|
|
50
|
+
}
|
|
51
|
+
set path(path) {
|
|
52
|
+
this.store.set("path", path);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get the scope of the provider.
|
|
56
|
+
*
|
|
57
|
+
* ::: tip Note
|
|
58
|
+
* Async provider is always a SINGLETON
|
|
59
|
+
* :::
|
|
60
|
+
*
|
|
61
|
+
* @returns {boolean}
|
|
62
|
+
*/
|
|
63
|
+
get scope() {
|
|
64
|
+
if (this.isAsync()) {
|
|
65
|
+
return ProviderScope_1.ProviderScope.SINGLETON;
|
|
66
|
+
}
|
|
67
|
+
return this.get("scope");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Change the scope value of the provider.
|
|
71
|
+
* @param scope
|
|
72
|
+
*/
|
|
73
|
+
set scope(scope) {
|
|
74
|
+
this.store.set("scope", scope);
|
|
75
|
+
}
|
|
76
|
+
get configuration() {
|
|
77
|
+
return this.get("configuration");
|
|
78
|
+
}
|
|
79
|
+
set configuration(configuration) {
|
|
80
|
+
this.store.set("configuration", configuration);
|
|
81
|
+
}
|
|
82
|
+
get children() {
|
|
83
|
+
return this.store.get("childrenControllers", []);
|
|
84
|
+
}
|
|
85
|
+
get(key) {
|
|
86
|
+
return this.store.get(key) || this._tokenStore.get(key);
|
|
87
|
+
}
|
|
88
|
+
isAsync() {
|
|
89
|
+
return !!this.useAsyncFactory;
|
|
90
|
+
}
|
|
91
|
+
clone() {
|
|
92
|
+
return new ((0, core_1.classOf)(this))(this._provide, this);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* @returns {boolean}
|
|
97
|
+
*/
|
|
98
|
+
hasChildren() {
|
|
99
|
+
return !!this.children.length;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
* @returns {boolean}
|
|
104
|
+
*/
|
|
105
|
+
hasParent() {
|
|
106
|
+
return !!this.store.get("parentController");
|
|
107
|
+
}
|
|
108
|
+
toString() {
|
|
109
|
+
return [
|
|
110
|
+
"Token",
|
|
111
|
+
this.name,
|
|
112
|
+
this.useClass && (0, core_1.nameOf)(this.useClass),
|
|
113
|
+
this.useFactory && "Factory",
|
|
114
|
+
this.useValue && "Value",
|
|
115
|
+
this.useAsyncFactory && "AsyncFactory"
|
|
116
|
+
]
|
|
117
|
+
.filter(Boolean)
|
|
118
|
+
.join(":");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.Provider = Provider;
|
|
122
|
+
//# sourceMappingURL=Provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provider.js","sourceRoot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I,WAAW;QAChB,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChC,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC9C,CAAC;IAED,QAAQ;QACN,OAAO;YACL,OAAO;YACP,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,QAAQ,IAAI,IAAA,aAAM,EAAC,IAAI,CAAC,QAAQ,CAAC;YACtC,IAAI,CAAC,UAAU,IAAI,SAAS;YAC5B,IAAI,CAAC,QAAQ,IAAI,OAAO;YACxB,IAAI,CAAC,eAAe,IAAI,cAAc;SACvC;aACE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;CACF;AArJD,4BAqJC","sourcesContent":["import {classOf, getClassOrSymbol, isClass, nameOf, Store, Type} from \"@tsed/core\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {ProviderScope} from \"./ProviderScope\";\nimport {ProviderType} from \"./ProviderType\";\n\nexport class Provider<T = any> implements ProviderOpts<T> {\n public type: ProviderType | any = ProviderType.PROVIDER;\n public deps: TokenProvider[];\n public imports: any[];\n public useFactory: Function;\n public useAsyncFactory: Function;\n public useValue: any;\n public hooks?: Record<string, (instance: T, ...args: any[]) => Promise<void> | void>;\n private _useClass: Type<T>;\n private _provide: TokenProvider;\n private _store: Store;\n private _tokenStore: Store;\n\n [key: string]: any;\n\n constructor(token: TokenProvider, options: Partial<Provider> = {}) {\n this.provide = token;\n this.useClass = token;\n\n Object.assign(this, options);\n }\n\n get token() {\n return this._provide;\n }\n\n get provide(): TokenProvider {\n return this._provide;\n }\n\n set provide(value: TokenProvider) {\n if (value) {\n this._provide = getClassOrSymbol(value);\n this._tokenStore = this._store = Store.from(value);\n }\n }\n\n get useClass(): Type<T> {\n return this._useClass;\n }\n\n /**\n * Create a new store if the given value is a class. Otherwise the value is ignored.\n * @param value\n */\n set useClass(value: Type<T>) {\n if (isClass(value)) {\n this._useClass = classOf(value);\n this._store = Store.from(value);\n }\n }\n\n get className() {\n return this.name;\n }\n\n get name() {\n return nameOf(this.provide);\n }\n\n get store(): Store {\n return this._store;\n }\n\n get path() {\n return this.store.get(\"path\", \"/\");\n }\n\n set path(path: string) {\n this.store.set(\"path\", path);\n }\n\n /**\n * Get the scope of the provider.\n *\n * ::: tip Note\n * Async provider is always a SINGLETON\n * :::\n *\n * @returns {boolean}\n */\n get scope(): ProviderScope {\n if (this.isAsync()) {\n return ProviderScope.SINGLETON;\n }\n\n return this.get(\"scope\");\n }\n\n /**\n * Change the scope value of the provider.\n * @param scope\n */\n set scope(scope: ProviderScope) {\n this.store.set(\"scope\", scope);\n }\n\n get configuration(): Partial<TsED.Configuration> {\n return this.get(\"configuration\");\n }\n\n set configuration(configuration: Partial<TsED.Configuration>) {\n this.store.set(\"configuration\", configuration);\n }\n\n get children(): TokenProvider[] {\n return this.store.get(\"childrenControllers\", []);\n }\n\n get(key: string) {\n return this.store.get(key) || this._tokenStore.get(key);\n }\n\n isAsync(): boolean {\n return !!this.useAsyncFactory;\n }\n\n clone(): Provider {\n return new (classOf(this))(this._provide, this);\n }\n\n /**\n *\n * @returns {boolean}\n */\n public hasChildren(): boolean {\n return !!this.children.length;\n }\n\n /**\n *\n * @returns {boolean}\n */\n public hasParent(): boolean {\n return !!this.store.get(\"parentController\");\n }\n\n toString() {\n return [\n \"Token\",\n this.name,\n this.useClass && nameOf(this.useClass),\n this.useFactory && \"Factory\",\n this.useValue && \"Value\",\n this.useAsyncFactory && \"AsyncFactory\"\n ]\n .filter(Boolean)\n .join(\":\");\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProviderScope = void 0;
|
|
4
|
+
var ProviderScope;
|
|
5
|
+
(function (ProviderScope) {
|
|
6
|
+
ProviderScope["SINGLETON"] = "singleton";
|
|
7
|
+
ProviderScope["REQUEST"] = "request";
|
|
8
|
+
ProviderScope["INSTANCE"] = "instance";
|
|
9
|
+
})(ProviderScope = exports.ProviderScope || (exports.ProviderScope = {}));
|
|
10
|
+
//# sourceMappingURL=ProviderScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProviderScope.js","sourceRoot":"","sources":["../../../src/domain/ProviderScope.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,wCAAuB,CAAA;IACvB,oCAAmB,CAAA;IACnB,sCAAqB,CAAA;AACvB,CAAC,EAJW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAIxB","sourcesContent":["export enum ProviderScope {\n SINGLETON = \"singleton\",\n REQUEST = \"request\",\n INSTANCE = \"instance\"\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProviderType = void 0;
|
|
4
|
+
var ProviderType;
|
|
5
|
+
(function (ProviderType) {
|
|
6
|
+
ProviderType["VALUE"] = "value";
|
|
7
|
+
ProviderType["FACTORY"] = "factory";
|
|
8
|
+
ProviderType["SERVICE"] = "service";
|
|
9
|
+
ProviderType["PROVIDER"] = "provider";
|
|
10
|
+
ProviderType["MODULE"] = "module";
|
|
11
|
+
ProviderType["CONTROLLER"] = "controller";
|
|
12
|
+
ProviderType["INTERCEPTOR"] = "interceptor";
|
|
13
|
+
ProviderType["MIDDLEWARE"] = "middleware";
|
|
14
|
+
})(ProviderType = exports.ProviderType || (exports.ProviderType = {}));
|
|
15
|
+
//# sourceMappingURL=ProviderType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProviderType.js","sourceRoot":"","sources":["../../../src/domain/ProviderType.ts"],"names":[],"mappings":";;;AAAA,IAAY,YASX;AATD,WAAY,YAAY;IACtB,+BAAe,CAAA;IACf,mCAAmB,CAAA;IACnB,mCAAmB,CAAA;IACnB,qCAAqB,CAAA;IACrB,iCAAiB,CAAA;IACjB,yCAAyB,CAAA;IACzB,2CAA2B,CAAA;IAC3B,yCAAyB,CAAA;AAC3B,CAAC,EATW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QASvB","sourcesContent":["export enum ProviderType {\n VALUE = \"value\",\n FACTORY = \"factory\",\n SERVICE = \"service\",\n PROVIDER = \"provider\",\n MODULE = \"module\",\n CONTROLLER = \"controller\",\n INTERCEPTOR = \"interceptor\",\n MIDDLEWARE = \"middleware\"\n}\n"]}
|