@tsed/di 7.0.0-alpha.1 → 7.0.0-beta.10
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 +57 -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/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 +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 +116 -0
- package/lib/cjs/services/DITest.js.map +1 -0
- package/lib/cjs/services/InjectorService.js +572 -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 +20 -0
- package/lib/cjs/utils/getConfiguration.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 +54 -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/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 +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 +112 -0
- package/lib/esm/services/DITest.js.map +1 -0
- package/lib/esm/services/InjectorService.js +569 -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 +16 -0
- package/lib/esm/utils/getConfiguration.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/types/decorators/controller.d.ts +43 -0
- 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 +5 -1
- package/lib/{domain → types/domain}/DIContext.d.ts +6 -13
- 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 +21 -5
- 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 +53 -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}/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/{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 +3 -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 +39 -21
- 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 +0 -0
- package/lib/types/utils/runInContext.d.ts +6 -0
- package/lib/{utils → types/utils}/setLoggerLevel.d.ts +0 -0
- package/package.json +31 -12
- package/readme.md +38 -42
- package/tsconfig.compile.esm.json +25 -0
- package/lib/decorators/index.d.ts +0 -13
- 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 -2271
- package/lib/index.js.map +0 -1
- package/lib/index.modern.js +0 -2235
- package/lib/index.modern.js.map +0 -1
- package/lib/interfaces/index.d.ts +0 -13
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
2
2
|
/**
|
|
3
3
|
* Register a provider configuration.
|
|
4
|
-
* @param {
|
|
4
|
+
* @param {ProviderOpts<any>} provider
|
|
5
5
|
*/
|
|
6
|
-
export declare function registerProvider(provider: Partial<
|
|
6
|
+
export declare function registerProvider<Type = any>(provider: Partial<ProviderOpts<Type>>): void;
|
|
7
7
|
/**
|
|
8
8
|
* Add a new value in the `ProviderRegistry`.
|
|
9
9
|
*
|
|
@@ -25,7 +25,7 @@ export declare function registerProvider(provider: Partial<IProvider>): void;
|
|
|
25
25
|
* }
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export declare const registerValue: (provider: any |
|
|
28
|
+
export declare const registerValue: (provider: any | ProviderOpts<any>, value?: any) => void;
|
|
29
29
|
/**
|
|
30
30
|
* Add a new controller in the `ProviderRegistry`. This controller will be built when `InjectorService` will be loaded.
|
|
31
31
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ProviderScope } from "../domain";
|
|
2
|
-
import type { DIResolver
|
|
1
|
+
import { ProviderScope } from "../domain/ProviderScope";
|
|
2
|
+
import type { DIResolver } from "../interfaces/DIResolver";
|
|
3
|
+
import type { TokenProvider } from "../interfaces/TokenProvider";
|
|
3
4
|
export declare class DIConfiguration {
|
|
4
5
|
readonly default: Map<string, any>;
|
|
5
6
|
protected map: Map<string, any>;
|
|
File without changes
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
2
2
|
import { InjectorService } from "./InjectorService";
|
|
3
|
+
import { DIContext } from "../domain/DIContext";
|
|
3
4
|
export interface DITestInvokeOptions {
|
|
4
5
|
token?: TokenProvider;
|
|
5
6
|
use: any;
|
|
6
7
|
}
|
|
8
|
+
export interface DITestOptions extends Partial<TsED.Configuration> {
|
|
9
|
+
imports?: DITestInvokeOptions[];
|
|
10
|
+
}
|
|
7
11
|
/**
|
|
8
12
|
* Tool to run test with lightweight DI sandbox.
|
|
9
13
|
*/
|
|
@@ -12,7 +16,8 @@ export declare class DITest {
|
|
|
12
16
|
static get injector(): InjectorService;
|
|
13
17
|
static set injector(injector: InjectorService);
|
|
14
18
|
static hasInjector(): boolean;
|
|
15
|
-
static create(settings?:
|
|
19
|
+
static create(settings?: DITestOptions): Promise<void>;
|
|
20
|
+
static createContainer(settings?: DITestOptions): Promise<void>;
|
|
16
21
|
/**
|
|
17
22
|
* Create a new injector with the right default services
|
|
18
23
|
*/
|
|
@@ -33,5 +38,6 @@ export declare class DITest {
|
|
|
33
38
|
* @param options
|
|
34
39
|
*/
|
|
35
40
|
static get<T = any>(target: TokenProvider, options?: any): T;
|
|
41
|
+
static createDIContext(): DIContext;
|
|
36
42
|
protected static configure(settings?: Partial<TsED.Configuration>): Partial<TsED.Configuration>;
|
|
37
43
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { DIContext, ProviderScope } from "../domain";
|
|
2
1
|
import { Container } from "../domain/Container";
|
|
3
2
|
import { LocalsContainer } from "../domain/LocalsContainer";
|
|
4
3
|
import { Provider } from "../domain/Provider";
|
|
5
|
-
import { DILogger, InjectablePropertyService, InjectablePropertyValue, InvokeOptions, IProvider, TokenProvider } from "../interfaces";
|
|
6
4
|
import { DIConfiguration } from "./DIConfiguration";
|
|
5
|
+
import { ProviderScope } from "../domain/ProviderScope";
|
|
6
|
+
import { DILogger } from "../interfaces/DILogger";
|
|
7
|
+
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
8
|
+
import { InvokeOptions } from "../interfaces/InvokeOptions";
|
|
9
|
+
import { InjectablePropertyOptions, InjectablePropertyValue } from "../interfaces/InjectableProperties";
|
|
7
10
|
/**
|
|
8
11
|
* This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.
|
|
9
12
|
*
|
|
@@ -26,11 +29,12 @@ import { DIConfiguration } from "./DIConfiguration";
|
|
|
26
29
|
* ```
|
|
27
30
|
*/
|
|
28
31
|
export declare class InjectorService extends Container {
|
|
32
|
+
#private;
|
|
29
33
|
settings: TsED.Configuration & DIConfiguration;
|
|
30
34
|
logger: DILogger;
|
|
31
35
|
private resolvedConfiguration;
|
|
32
36
|
constructor();
|
|
33
|
-
get resolvers(): import("
|
|
37
|
+
get resolvers(): import("..").DIResolver[];
|
|
34
38
|
get scopes(): {
|
|
35
39
|
[key: string]: ProviderScope;
|
|
36
40
|
} & {
|
|
@@ -41,12 +45,6 @@ export declare class InjectorService extends Container {
|
|
|
41
45
|
* @param provider
|
|
42
46
|
*/
|
|
43
47
|
scopeOf(provider: Provider): ProviderScope;
|
|
44
|
-
/**
|
|
45
|
-
* Clone a provider from GlobalProviders and the given token. forkProvider method build automatically the provider if the instance parameter ins't given.
|
|
46
|
-
* @param token
|
|
47
|
-
* @param settings
|
|
48
|
-
*/
|
|
49
|
-
forkProvider(token: TokenProvider, settings?: Partial<IProvider<any>>): Provider;
|
|
50
48
|
/**
|
|
51
49
|
* Return a list of instance build by the injector.
|
|
52
50
|
*/
|
|
@@ -72,6 +70,11 @@ export declare class InjectorService extends Container {
|
|
|
72
70
|
* @returns {boolean}
|
|
73
71
|
*/
|
|
74
72
|
get<T = any>(token: TokenProvider, options?: any): T | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Return all instance of the same provider type
|
|
75
|
+
* @param type
|
|
76
|
+
*/
|
|
77
|
+
getAll(type: string): any[];
|
|
75
78
|
/**
|
|
76
79
|
* The has() method returns a boolean indicating whether an element with the specified key exists or not.
|
|
77
80
|
* @returns {boolean}
|
|
@@ -103,8 +106,8 @@ export declare class InjectorService extends Container {
|
|
|
103
106
|
/**
|
|
104
107
|
* Build only providers which are asynchronous.
|
|
105
108
|
*/
|
|
106
|
-
loadAsync(locals?: LocalsContainer
|
|
107
|
-
loadSync(locals?: LocalsContainer
|
|
109
|
+
loadAsync(locals?: LocalsContainer): Promise<LocalsContainer<any>>;
|
|
110
|
+
loadSync(locals?: LocalsContainer): LocalsContainer<any>;
|
|
108
111
|
/**
|
|
109
112
|
* Boostrap injector from container and resolve configuration.
|
|
110
113
|
*
|
|
@@ -134,19 +137,19 @@ export declare class InjectorService extends Container {
|
|
|
134
137
|
* @param instance
|
|
135
138
|
* @param {string} propertyKey
|
|
136
139
|
*/
|
|
137
|
-
bindMethod(instance: any, { propertyKey }:
|
|
140
|
+
bindMethod(instance: any, { propertyKey }: InjectablePropertyOptions): void;
|
|
138
141
|
/**
|
|
139
142
|
* Create an injectable property.
|
|
140
143
|
*
|
|
141
144
|
* @param instance
|
|
142
145
|
* @param {string} propertyKey
|
|
143
146
|
* @param {any} useType
|
|
144
|
-
* @param
|
|
147
|
+
* @param resolver
|
|
145
148
|
* @param options
|
|
146
149
|
* @param locals
|
|
147
150
|
* @param invokeOptions
|
|
148
151
|
*/
|
|
149
|
-
bindProperty(instance: any, { propertyKey,
|
|
152
|
+
bindProperty(instance: any, { propertyKey, resolver, options }: InjectablePropertyOptions, locals: Map<TokenProvider, any>, invokeOptions: Partial<InvokeOptions>): void;
|
|
150
153
|
/**
|
|
151
154
|
*
|
|
152
155
|
* @param instance
|
|
@@ -160,7 +163,7 @@ export declare class InjectorService extends Container {
|
|
|
160
163
|
* @param {string} propertyKey
|
|
161
164
|
* @param {any} useType
|
|
162
165
|
*/
|
|
163
|
-
bindConstant(instance: any, { propertyKey, expression, defaultValue }: InjectablePropertyValue):
|
|
166
|
+
bindConstant(instance: any, { propertyKey, expression, defaultValue }: InjectablePropertyValue): void;
|
|
164
167
|
/**
|
|
165
168
|
*
|
|
166
169
|
* @param instance
|
|
@@ -168,15 +171,30 @@ export declare class InjectorService extends Container {
|
|
|
168
171
|
* @param useType
|
|
169
172
|
* @param options
|
|
170
173
|
*/
|
|
171
|
-
bindInterceptor(instance: any, { propertyKey, useType, options }:
|
|
174
|
+
bindInterceptor(instance: any, { propertyKey, useType, options }: InjectablePropertyOptions): void;
|
|
175
|
+
lazyInvoke<T = any>(token: TokenProvider): Promise<any>;
|
|
176
|
+
/**
|
|
177
|
+
* Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
|
|
178
|
+
* @param eventName The event name to emit at all services.
|
|
179
|
+
* @param args List of the parameters to give to each services.
|
|
180
|
+
* @returns {Promise<any[]>} A list of promises.
|
|
181
|
+
*/
|
|
182
|
+
emit(eventName: string, ...args: any[]): Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* @param eventName
|
|
185
|
+
* @param value
|
|
186
|
+
* @param args
|
|
187
|
+
*/
|
|
188
|
+
alter<T = any>(eventName: string, value: any, ...args: any[]): T;
|
|
172
189
|
/**
|
|
173
|
-
*
|
|
174
|
-
* @param
|
|
175
|
-
* @param
|
|
176
|
-
* @protected
|
|
190
|
+
* @param eventName
|
|
191
|
+
* @param value
|
|
192
|
+
* @param args
|
|
177
193
|
*/
|
|
178
|
-
|
|
194
|
+
alterAsync<T = any>(eventName: string, value: any, ...args: any[]): Promise<T>;
|
|
195
|
+
destroy(): Promise<void>;
|
|
179
196
|
protected ensureProvider(token: TokenProvider): Provider | undefined;
|
|
197
|
+
protected getInstance(token: any): any;
|
|
180
198
|
/**
|
|
181
199
|
* Invoke a class method and inject service.
|
|
182
200
|
*
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
+
import { DIContext } from "../domain/DIContext";
|
|
4
|
+
export declare function getAsyncStore(): AsyncLocalStorage<DIContext>;
|
|
5
|
+
export declare function getContext(): DIContext | undefined;
|
|
6
|
+
export declare function runInContext(ctx: DIContext, cb: any): unknown;
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,34 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/di",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-beta.10",
|
|
4
4
|
"description": "DI module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
|
-
"main": "./lib/index.js",
|
|
8
|
-
"
|
|
7
|
+
"main": "./lib/cjs/index.js",
|
|
8
|
+
"module": "./lib/esm/index.js",
|
|
9
|
+
"typings": "./lib/types/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
11
|
+
"types": "./lib/types/index.d.ts",
|
|
12
|
+
"import": "./lib/esm/index.js",
|
|
13
|
+
"require": "./lib/cjs/index.js",
|
|
14
|
+
"default": "./lib/esm/index.js"
|
|
12
15
|
},
|
|
13
16
|
"scripts": {
|
|
14
|
-
"build": "
|
|
17
|
+
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
18
|
+
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
19
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
20
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\""
|
|
15
21
|
},
|
|
16
22
|
"dependencies": {
|
|
17
|
-
"
|
|
18
|
-
"chalk": "4.1.0",
|
|
19
|
-
"tslib": "2.2.0"
|
|
23
|
+
"tslib": "2.3.1"
|
|
20
24
|
},
|
|
21
25
|
"devDependencies": {
|
|
22
|
-
"@tsed/
|
|
26
|
+
"@tsed/core": "7.0.0-beta.10",
|
|
27
|
+
"@tsed/logger": ">=6.1.1",
|
|
28
|
+
"@tsed/schema": "7.0.0-beta.10"
|
|
23
29
|
},
|
|
24
30
|
"peerDependencies": {
|
|
25
|
-
"@tsed/
|
|
31
|
+
"@tsed/core": "^7.0.0-beta.10",
|
|
32
|
+
"@tsed/logger": ">=6.1.1",
|
|
33
|
+
"@tsed/schema": "^7.0.0-beta.10"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"@tsed/core": {
|
|
37
|
+
"optional": false
|
|
38
|
+
},
|
|
39
|
+
"@tsed/logger": {
|
|
40
|
+
"optional": false
|
|
41
|
+
},
|
|
42
|
+
"@tsed/schema": {
|
|
43
|
+
"optional": false
|
|
44
|
+
}
|
|
26
45
|
},
|
|
27
46
|
"repository": "https://github.com/tsedio/tsed",
|
|
28
47
|
"bugs": {
|
|
29
48
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
30
49
|
},
|
|
31
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
50
|
+
"homepage": "https://github.com/tsedio/tsed/tree/beta/packages/di",
|
|
32
51
|
"author": "Romain Lenzotti",
|
|
33
52
|
"license": "MIT"
|
|
34
53
|
}
|
package/readme.md
CHANGED
|
@@ -32,39 +32,36 @@ A package of Ts.ED framework. See website: https://tsed.io/
|
|
|
32
32
|
# Installation
|
|
33
33
|
|
|
34
34
|
You can get the latest release and the type definitions using npm:
|
|
35
|
+
|
|
35
36
|
```bash
|
|
36
37
|
npm install --save @tsed/di
|
|
37
38
|
```
|
|
38
39
|
|
|
39
|
-
> **Important!** TsExpressDecorators requires Node >= 6, Express >= 4, TypeScript >= 2.0 and
|
|
40
|
-
the `experimentalDecorators`, `emitDecoratorMetadata`, `types` and `lib` compilation
|
|
41
|
-
options in your `tsconfig.json` file.
|
|
40
|
+
> **Important!** TsExpressDecorators requires Node >= 6, Express >= 4, TypeScript >= 2.0 and
|
|
41
|
+
> the `experimentalDecorators`, `emitDecoratorMetadata`, `types` and `lib` compilation
|
|
42
|
+
> options in your `tsconfig.json` file.
|
|
42
43
|
|
|
43
44
|
```json
|
|
44
45
|
{
|
|
45
46
|
"compilerOptions": {
|
|
46
47
|
"target": "es2016",
|
|
47
48
|
"lib": ["es2016"],
|
|
48
|
-
"typeRoots": [
|
|
49
|
-
"./node_modules/@types"
|
|
50
|
-
],
|
|
49
|
+
"typeRoots": ["./node_modules/@types"],
|
|
51
50
|
"module": "commonjs",
|
|
52
51
|
"moduleResolution": "node",
|
|
53
|
-
"experimentalDecorators":true,
|
|
52
|
+
"experimentalDecorators": true,
|
|
54
53
|
"emitDecoratorMetadata": true,
|
|
55
54
|
"allowSyntheticDefaultImports": true
|
|
56
55
|
},
|
|
57
|
-
"exclude": [
|
|
58
|
-
"node_modules"
|
|
59
|
-
]
|
|
56
|
+
"exclude": ["node_modules"]
|
|
60
57
|
}
|
|
61
58
|
```
|
|
62
59
|
|
|
63
60
|
## Introduction
|
|
64
61
|
|
|
65
|
-
Basically, almost everything may be considered as a provider – service, factory, intereceptors, and so on.
|
|
62
|
+
Basically, almost everything may be considered as a provider – service, factory, intereceptors, and so on.
|
|
66
63
|
All of them can inject dependencies, meaning, they can create various relationships with each other.
|
|
67
|
-
|
|
64
|
+
But in fact, a provider is nothing else than just a simple class annotated with an `@Injectable()` decorator.
|
|
68
65
|
|
|
69
66
|
## Usage
|
|
70
67
|
|
|
@@ -77,28 +74,29 @@ import {Calendar} from "./models/calendar";
|
|
|
77
74
|
@Injectable()
|
|
78
75
|
export class CalendarsService {
|
|
79
76
|
private readonly calendars: Calendar[] = [];
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
77
|
+
|
|
78
|
+
create(calendar: Calendar) {
|
|
79
|
+
this.calendars.push(calendar);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
findAll(): Calendar[] {
|
|
83
|
+
return this.calendars;
|
|
84
|
+
}
|
|
88
85
|
}
|
|
89
86
|
```
|
|
90
87
|
|
|
91
88
|
Here's a CalendarsService, a basic class with one property and two methods. The only new trait is that it uses the `@Injectable()` decorator.
|
|
92
89
|
The `@Injectable()` attaches the metadata, thereby Ts.ED knows that this class is a provider.
|
|
93
|
-
|
|
90
|
+
|
|
94
91
|
Now we have the service class already done, let's use it inside a controller:
|
|
92
|
+
|
|
95
93
|
```typescript
|
|
96
|
-
import {
|
|
97
|
-
import {
|
|
98
|
-
import {
|
|
94
|
+
import {Controller, Post, Body, Get} from "@tsed/common";
|
|
95
|
+
import {CalendarsService} from "./CalendarsService";
|
|
96
|
+
import {Calendar} from "./models/Calendar";
|
|
99
97
|
|
|
100
|
-
@Controller(
|
|
101
|
-
export class
|
|
98
|
+
@Controller("/calendars")
|
|
99
|
+
export class CalendarCtrl {
|
|
102
100
|
constructor(private readonly calendarsService: CalendarsService) {}
|
|
103
101
|
|
|
104
102
|
@Post()
|
|
@@ -112,30 +110,31 @@ export class CalendarService {
|
|
|
112
110
|
}
|
|
113
111
|
}
|
|
114
112
|
```
|
|
115
|
-
> Note: Controller isn't a part of `@tsed/di`. `@Controller` decorator is exposed by `@tsed/common` package because it's a specific provider
|
|
116
|
-
used by the Ts.ED framework. Ts.ED DI allow you to define your own Provider and decorator.
|
|
117
113
|
|
|
114
|
+
> Note: Controller isn't a part of `@tsed/di`. `@Controller` decorator is exposed by `@tsed/common` package because it's a specific provider
|
|
115
|
+
> used by the Ts.ED framework. Ts.ED DI allow you to define your own Provider and decorator.
|
|
118
116
|
|
|
119
117
|
Finally, we can load the injector and use:
|
|
118
|
+
|
|
120
119
|
```typescript
|
|
121
120
|
import {InjectorService} from "@tsed/di";
|
|
122
121
|
import {CalendarCtrl} from "./CalendarCtrl";
|
|
123
122
|
|
|
124
123
|
async function bootstrap() {
|
|
125
|
-
const injector = new InjectorService()
|
|
126
|
-
|
|
124
|
+
const injector = new InjectorService();
|
|
125
|
+
|
|
127
126
|
// Load all providers registered via @Injectable decorator
|
|
128
|
-
await injector.load()
|
|
129
|
-
|
|
130
|
-
const calendarController = injector.get<CalendarCtrl>()
|
|
131
|
-
|
|
132
|
-
await calendarController.create(new Calendar())
|
|
133
|
-
|
|
127
|
+
await injector.load();
|
|
128
|
+
|
|
129
|
+
const calendarController = injector.get<CalendarCtrl>();
|
|
130
|
+
|
|
131
|
+
await calendarController.create(new Calendar());
|
|
132
|
+
|
|
134
133
|
// And finally destroy injector and his instances (see injector hooks)
|
|
135
|
-
await injector.destroy()
|
|
134
|
+
await injector.destroy();
|
|
136
135
|
}
|
|
137
136
|
|
|
138
|
-
bootstrap()
|
|
137
|
+
bootstrap();
|
|
139
138
|
```
|
|
140
139
|
|
|
141
140
|
## Custom providers
|
|
@@ -147,23 +146,20 @@ To organize your code Ts.ED DI provide different kind of providers:
|
|
|
147
146
|
- Interceptor can be declared with `@Interceptor`,
|
|
148
147
|
- Factory and Value can be declared with `registerProvider` and `registerValue`.
|
|
149
148
|
|
|
150
|
-
|
|
151
149
|
See more details on our documentation https://tsed.io/providers.html
|
|
152
150
|
|
|
153
|
-
|
|
154
151
|
## Contributors
|
|
152
|
+
|
|
155
153
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
|
|
156
154
|
|
|
157
155
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
158
156
|
|
|
159
|
-
|
|
160
157
|
## Backers
|
|
161
158
|
|
|
162
159
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
163
160
|
|
|
164
161
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
|
|
165
162
|
|
|
166
|
-
|
|
167
163
|
## Sponsors
|
|
168
164
|
|
|
169
165
|
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.compile.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"module": "ES2020",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"outDir": "./lib/esm",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationDir": "./lib/types"
|
|
10
|
+
},
|
|
11
|
+
"include": ["src"],
|
|
12
|
+
"exclude": [
|
|
13
|
+
"node_modules",
|
|
14
|
+
"test",
|
|
15
|
+
"lib",
|
|
16
|
+
"benchmark",
|
|
17
|
+
"coverage",
|
|
18
|
+
"spec",
|
|
19
|
+
"**/*.benchmark.ts",
|
|
20
|
+
"**/*.spec.ts",
|
|
21
|
+
"keys",
|
|
22
|
+
"jest.config.js",
|
|
23
|
+
"**/__mock__/**"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from "./scope";
|
|
2
|
-
export * from "./service";
|
|
3
|
-
export * from "./overrideProvider";
|
|
4
|
-
export * from "./inject";
|
|
5
|
-
export * from "./injectable";
|
|
6
|
-
export * from "./constant";
|
|
7
|
-
export * from "./value";
|
|
8
|
-
export * from "./intercept";
|
|
9
|
-
export * from "./interceptor";
|
|
10
|
-
export * from "./configuration";
|
|
11
|
-
export * from "./module";
|
|
12
|
-
export * from "./opts";
|
|
13
|
-
export * from "./useOpts";
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Inject a provider to another provider.
|
|
3
|
-
*
|
|
4
|
-
* Use this decorator to inject a custom provider on constructor parameter or property.
|
|
5
|
-
*
|
|
6
|
-
* ```typescript
|
|
7
|
-
* @Injectable()
|
|
8
|
-
* export class MyService {
|
|
9
|
-
* @Inject(CONNECTION)
|
|
10
|
-
* connection: CONNECTION;
|
|
11
|
-
* }
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* @param symbol
|
|
15
|
-
* @param onGet Use the given name method to inject
|
|
16
|
-
* @returns {Function}
|
|
17
|
-
* @decorator
|
|
18
|
-
*/
|
|
19
|
-
export declare function Inject(symbol?: any, onGet?: (bean: any) => any): Function;
|
package/lib/domain/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from "./Container";
|
|
2
|
-
export * from "./InjectablePropertyType";
|
|
3
|
-
export * from "./LocalsContainer";
|
|
4
|
-
export * from "./Provider";
|
|
5
|
-
export * from "./ProviderScope";
|
|
6
|
-
export * from "./ProviderType";
|
|
7
|
-
export * from "./ContextLogger";
|
|
8
|
-
export * from "./DIContext";
|
package/lib/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export * from "./constants/index";
|
|
2
|
-
export * from "./domain";
|
|
3
|
-
export * from "./interfaces";
|
|
4
|
-
export * from "./decorators";
|
|
5
|
-
export * from "./registries/ProviderRegistry";
|
|
6
|
-
export * from "./registries/GlobalProviders";
|
|
7
|
-
export * from "./services/InjectorService";
|
|
8
|
-
export * from "./services/DILogger";
|
|
9
|
-
export * from "./services/DIConfiguration";
|
|
10
|
-
export * from "./services/DITest";
|
|
11
|
-
export * from "./errors/InjectionError";
|
|
12
|
-
export * from "./errors/UndefinedTokenError";
|
|
13
|
-
export * from "./utils/createContainer";
|
|
14
|
-
export * from "./utils/getConfiguration";
|
|
15
|
-
export * from "./utils/getConfiguration";
|
|
16
|
-
export * from "./utils/setLoggerLevel";
|