@tsed/di 7.83.0 → 8.0.0-alpha.2
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/browser/di.umd.min.js +1 -1
- package/lib/browser/di.umd.min.js.map +1 -1
- package/lib/cjs/common/constants/constants.js +6 -4
- package/lib/cjs/common/constants/constants.js.map +1 -1
- package/lib/cjs/common/decorators/autoInjectable.js +23 -3
- package/lib/cjs/common/decorators/autoInjectable.js.map +1 -1
- package/lib/cjs/common/decorators/constant.js +30 -11
- package/lib/cjs/common/decorators/constant.js.map +1 -1
- package/lib/cjs/common/decorators/inject.js +64 -73
- package/lib/cjs/common/decorators/inject.js.map +1 -1
- package/lib/cjs/common/decorators/intercept.js +41 -12
- package/lib/cjs/common/decorators/intercept.js.map +1 -1
- package/lib/cjs/common/decorators/lazyInject.js +13 -13
- package/lib/cjs/common/decorators/lazyInject.js.map +1 -1
- package/lib/cjs/common/decorators/opts.js +1 -1
- package/lib/cjs/common/decorators/opts.js.map +1 -1
- package/lib/cjs/common/decorators/useOpts.js +2 -6
- package/lib/cjs/common/decorators/useOpts.js.map +1 -1
- package/lib/cjs/common/decorators/value.js +18 -11
- package/lib/cjs/common/decorators/value.js.map +1 -1
- package/lib/cjs/common/domain/Container.js +3 -3
- package/lib/cjs/common/domain/Container.js.map +1 -1
- package/lib/cjs/common/domain/Provider.js +1 -1
- package/lib/cjs/common/domain/Provider.js.map +1 -1
- package/lib/cjs/common/index.js +0 -2
- package/lib/cjs/common/index.js.map +1 -1
- package/lib/cjs/common/registries/GlobalProviders.js +6 -2
- package/lib/cjs/common/registries/GlobalProviders.js.map +1 -1
- package/lib/cjs/common/services/DIConfiguration.js.map +1 -1
- package/lib/cjs/common/services/InjectorService.js +48 -165
- package/lib/cjs/common/services/InjectorService.js.map +1 -1
- package/lib/cjs/node/decorators/injectContext.js +12 -3
- package/lib/cjs/node/decorators/injectContext.js.map +1 -1
- package/lib/cjs/node/services/DITest.js +8 -3
- package/lib/cjs/node/services/DITest.js.map +1 -1
- package/lib/esm/common/constants/constants.js +5 -3
- package/lib/esm/common/constants/constants.js.map +1 -1
- package/lib/esm/common/decorators/autoInjectable.js +23 -3
- package/lib/esm/common/decorators/autoInjectable.js.map +1 -1
- package/lib/esm/common/decorators/constant.js +28 -11
- package/lib/esm/common/decorators/constant.js.map +1 -1
- package/lib/esm/common/decorators/inject.js +63 -73
- package/lib/esm/common/decorators/inject.js.map +1 -1
- package/lib/esm/common/decorators/intercept.js +40 -13
- package/lib/esm/common/decorators/intercept.js.map +1 -1
- package/lib/esm/common/decorators/lazyInject.js +14 -14
- package/lib/esm/common/decorators/lazyInject.js.map +1 -1
- package/lib/esm/common/decorators/opts.js +2 -2
- package/lib/esm/common/decorators/opts.js.map +1 -1
- package/lib/esm/common/decorators/useOpts.js +3 -7
- package/lib/esm/common/decorators/useOpts.js.map +1 -1
- package/lib/esm/common/decorators/value.js +17 -11
- package/lib/esm/common/decorators/value.js.map +1 -1
- package/lib/esm/common/domain/Container.js +3 -3
- package/lib/esm/common/domain/Container.js.map +1 -1
- package/lib/esm/common/domain/Provider.js +1 -1
- package/lib/esm/common/domain/Provider.js.map +1 -1
- package/lib/esm/common/index.js +0 -2
- package/lib/esm/common/index.js.map +1 -1
- package/lib/esm/common/registries/GlobalProviders.js +6 -2
- package/lib/esm/common/registries/GlobalProviders.js.map +1 -1
- package/lib/esm/common/services/DIConfiguration.js.map +1 -1
- package/lib/esm/common/services/InjectorService.js +50 -167
- package/lib/esm/common/services/InjectorService.js.map +1 -1
- package/lib/esm/node/decorators/injectContext.js +13 -4
- package/lib/esm/node/decorators/injectContext.js.map +1 -1
- package/lib/esm/node/services/DITest.js +10 -5
- package/lib/esm/node/services/DITest.js.map +1 -1
- package/lib/types/common/constants/constants.d.ts +5 -3
- package/lib/types/common/decorators/constant.d.ts +4 -1
- package/lib/types/common/decorators/inject.d.ts +17 -4
- package/lib/types/common/decorators/intercept.d.ts +3 -0
- package/lib/types/common/decorators/value.d.ts +2 -1
- package/lib/types/common/domain/Container.d.ts +3 -3
- package/lib/types/common/domain/Provider.d.ts +6 -6
- package/lib/types/common/index.d.ts +0 -2
- package/lib/types/common/interfaces/ImportTokenProviderOpts.d.ts +2 -2
- package/lib/types/common/interfaces/InterceptorContext.d.ts +1 -1
- package/lib/types/common/interfaces/InvokeOptions.d.ts +8 -2
- package/lib/types/common/interfaces/ProviderOpts.d.ts +1 -1
- package/lib/types/common/interfaces/RegistrySettings.d.ts +2 -1
- package/lib/types/common/interfaces/ResolvedInvokeOptions.d.ts +1 -1
- package/lib/types/common/interfaces/TokenProvider.d.ts +2 -6
- package/lib/types/common/registries/GlobalProviders.d.ts +2 -2
- package/lib/types/common/services/InjectorService.d.ts +30 -54
- package/lib/types/node/services/DITest.d.ts +1 -1
- package/lib/types-esm/common/constants/constants.d.ts +5 -3
- package/lib/types-esm/common/decorators/constant.d.ts +4 -1
- package/lib/types-esm/common/decorators/inject.d.ts +17 -4
- package/lib/types-esm/common/decorators/intercept.d.ts +3 -0
- package/lib/types-esm/common/decorators/value.d.ts +2 -1
- package/lib/types-esm/common/domain/Container.d.ts +3 -3
- package/lib/types-esm/common/domain/Provider.d.ts +6 -6
- package/lib/types-esm/common/index.d.ts +0 -2
- package/lib/types-esm/common/interfaces/ImportTokenProviderOpts.d.ts +2 -2
- package/lib/types-esm/common/interfaces/InterceptorContext.d.ts +1 -1
- package/lib/types-esm/common/interfaces/InvokeOptions.d.ts +8 -2
- package/lib/types-esm/common/interfaces/ProviderOpts.d.ts +1 -1
- package/lib/types-esm/common/interfaces/RegistrySettings.d.ts +2 -1
- package/lib/types-esm/common/interfaces/ResolvedInvokeOptions.d.ts +1 -1
- package/lib/types-esm/common/interfaces/TokenProvider.d.ts +2 -6
- package/lib/types-esm/common/registries/GlobalProviders.d.ts +2 -2
- package/lib/types-esm/common/services/InjectorService.d.ts +30 -54
- package/lib/types-esm/node/services/DITest.d.ts +1 -1
- package/package.json +13 -9
- package/vitest.config.mts +5 -5
- package/lib/cjs/common/errors/UndefinedTokenError.js +0 -11
- package/lib/cjs/common/errors/UndefinedTokenError.js.map +0 -1
- package/lib/cjs/common/interfaces/InjectableProperties.js +0 -3
- package/lib/cjs/common/interfaces/InjectableProperties.js.map +0 -1
- package/lib/esm/common/errors/UndefinedTokenError.js +0 -7
- package/lib/esm/common/errors/UndefinedTokenError.js.map +0 -1
- package/lib/esm/common/interfaces/InjectableProperties.js +0 -2
- package/lib/esm/common/interfaces/InjectableProperties.js.map +0 -1
- package/lib/types/common/errors/UndefinedTokenError.d.ts +0 -4
- package/lib/types/common/interfaces/InjectableProperties.d.ts +0 -25
- package/lib/types-esm/common/errors/UndefinedTokenError.d.ts +0 -4
- package/lib/types-esm/common/interfaces/InjectableProperties.d.ts +0 -25
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
2
|
import type { InterceptorMethods } from "../interfaces/InterceptorMethods.js";
|
|
3
|
+
import type { TokenProvider } from "../interfaces/TokenProvider.js";
|
|
4
|
+
export declare function getInterceptorOptions<T>(target: Type<any>, propertyKey: string | symbol): T;
|
|
5
|
+
export declare function bindIntercept(target: any, propertyKey: string | symbol, token: TokenProvider, options: Record<string, unknown>): TypedPropertyDescriptor<any> | undefined;
|
|
3
6
|
/**
|
|
4
7
|
* Attaches interceptor to method call and executes the before and after methods
|
|
5
8
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare function bindValue(target: any, propertyKey: string | symbol, expression: string, defaultValue?: any): void;
|
|
1
2
|
/**
|
|
2
3
|
* Return value from Configuration.
|
|
3
4
|
*
|
|
@@ -33,4 +34,4 @@
|
|
|
33
34
|
* @returns {(targetClass: any, attributeName: string) => any}
|
|
34
35
|
* @decorator
|
|
35
36
|
*/
|
|
36
|
-
export declare function Value(expression:
|
|
37
|
+
export declare function Value(expression: string, defaultValue?: unknown): PropertyDecorator;
|
|
@@ -31,13 +31,13 @@ export declare class Container extends Map<TokenProvider, Provider> {
|
|
|
31
31
|
* @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.
|
|
32
32
|
* @param token
|
|
33
33
|
*/
|
|
34
|
-
getProvider<T extends Provider = Provider>(token: TokenProvider): T | undefined;
|
|
34
|
+
getProvider<T extends Provider = Provider>(token: TokenProvider | undefined): T | undefined;
|
|
35
35
|
/**
|
|
36
36
|
* Get all providers registered in the injector container.
|
|
37
37
|
*
|
|
38
|
-
* @param
|
|
38
|
+
* @param type Filter the list by the given ProviderType.
|
|
39
39
|
* @returns {[TokenProvider , Provider<any>][]}
|
|
40
40
|
*/
|
|
41
|
-
getProviders(type?: ProviderType | string | string[]): Provider[];
|
|
41
|
+
getProviders(type?: TokenProvider | ProviderType | string | string[]): Provider[];
|
|
42
42
|
addProviders(container: Map<TokenProvider, Provider>): void;
|
|
43
43
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Store, Type } from "@tsed/core";
|
|
1
|
+
import { type AbstractType, Store, Type } from "@tsed/core";
|
|
2
2
|
import type { ProviderOpts } from "../interfaces/ProviderOpts.js";
|
|
3
3
|
import type { TokenProvider } from "../interfaces/TokenProvider.js";
|
|
4
4
|
import { ProviderScope } from "./ProviderScope.js";
|
|
@@ -8,7 +8,7 @@ export declare class Provider<T = any> implements ProviderOpts<T> {
|
|
|
8
8
|
/**
|
|
9
9
|
* Token group provider to retrieve all provider from the same type
|
|
10
10
|
*/
|
|
11
|
-
type:
|
|
11
|
+
type: ProviderType | TokenProvider;
|
|
12
12
|
deps: TokenProvider[];
|
|
13
13
|
imports: (TokenProvider | [TokenProvider])[];
|
|
14
14
|
alias?: string;
|
|
@@ -21,16 +21,16 @@ export declare class Provider<T = any> implements ProviderOpts<T> {
|
|
|
21
21
|
private _store;
|
|
22
22
|
private _tokenStore;
|
|
23
23
|
[key: string]: any;
|
|
24
|
-
constructor(token: TokenProvider
|
|
25
|
-
get token(): any
|
|
24
|
+
constructor(token: TokenProvider<T>, options?: Partial<Provider>);
|
|
25
|
+
get token(): TokenProvider<any>;
|
|
26
26
|
get provide(): TokenProvider;
|
|
27
27
|
set provide(value: TokenProvider);
|
|
28
28
|
get useClass(): Type<T>;
|
|
29
29
|
/**
|
|
30
|
-
* Create a new store if the given value is a class. Otherwise the value is ignored.
|
|
30
|
+
* Create a new store if the given value is a class. Otherwise, the value is ignored.
|
|
31
31
|
* @param value
|
|
32
32
|
*/
|
|
33
|
-
set useClass(value: Type<T>);
|
|
33
|
+
set useClass(value: Type<T> | AbstractType<T>);
|
|
34
34
|
get className(): string;
|
|
35
35
|
get name(): string;
|
|
36
36
|
get store(): Store;
|
|
@@ -27,13 +27,11 @@ export * from "./domain/ProviderScope.js";
|
|
|
27
27
|
export * from "./domain/ProviderType.js";
|
|
28
28
|
export * from "./errors/InjectionError.js";
|
|
29
29
|
export * from "./errors/InvalidPropertyTokenError.js";
|
|
30
|
-
export * from "./errors/UndefinedTokenError.js";
|
|
31
30
|
export * from "./interfaces/DIConfigurationOptions.js";
|
|
32
31
|
export * from "./interfaces/DILogger.js";
|
|
33
32
|
export * from "./interfaces/DILoggerOptions.js";
|
|
34
33
|
export * from "./interfaces/DIResolver.js";
|
|
35
34
|
export * from "./interfaces/ImportTokenProviderOpts.js";
|
|
36
|
-
export * from "./interfaces/InjectableProperties.js";
|
|
37
35
|
export * from "./interfaces/InterceptorContext.js";
|
|
38
36
|
export * from "./interfaces/InterceptorMethods.js";
|
|
39
37
|
export * from "./interfaces/InvokeOptions.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Type } from "@tsed/core";
|
|
1
|
+
import type { AbstractType, Type } from "@tsed/core";
|
|
2
2
|
import type { TokenProvider } from "./TokenProvider.js";
|
|
3
3
|
export type UseImportTokenProviderOpts = {
|
|
4
4
|
token: TokenProvider;
|
|
@@ -6,7 +6,7 @@ export type UseImportTokenProviderOpts = {
|
|
|
6
6
|
};
|
|
7
7
|
export type UseClassImportTokenProviderOpts = {
|
|
8
8
|
token: TokenProvider;
|
|
9
|
-
useClass: Type |
|
|
9
|
+
useClass: Type | AbstractType<any>;
|
|
10
10
|
};
|
|
11
11
|
export type UseFactoryImportTokenProviderOpts = {
|
|
12
12
|
token: TokenProvider;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import type { LocalsContainer } from "../domain/LocalsContainer.js";
|
|
1
2
|
import { ProviderScope } from "../domain/ProviderScope.js";
|
|
2
3
|
import { TokenProvider } from "./TokenProvider.js";
|
|
3
4
|
export interface InvokeOptions {
|
|
4
5
|
/**
|
|
5
6
|
* Define dependencies to build the provider and inject them in the constructor.
|
|
6
7
|
*/
|
|
7
|
-
deps:
|
|
8
|
+
deps: TokenProvider[];
|
|
8
9
|
/**
|
|
9
10
|
* List of imports to be created before the provider. Imports list aren't injected directly in the provider constructor.
|
|
10
11
|
*/
|
|
11
|
-
imports:
|
|
12
|
+
imports: TokenProvider[];
|
|
12
13
|
/**
|
|
13
14
|
* Parent provider.
|
|
14
15
|
*/
|
|
@@ -21,4 +22,9 @@ export interface InvokeOptions {
|
|
|
21
22
|
* If true, the injector will rebuild the instance.
|
|
22
23
|
*/
|
|
23
24
|
rebuild?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Option given to injectable props or parameter constructor (UseOpts).
|
|
27
|
+
*/
|
|
28
|
+
useOpts?: Record<string, unknown>;
|
|
29
|
+
locals?: LocalsContainer;
|
|
24
30
|
}
|
|
@@ -7,7 +7,7 @@ export interface ProviderOpts<T = any> {
|
|
|
7
7
|
/**
|
|
8
8
|
* An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
|
|
9
9
|
*/
|
|
10
|
-
provide: TokenProvider
|
|
10
|
+
provide: TokenProvider<T>;
|
|
11
11
|
/**
|
|
12
12
|
* Create alias token to retrieve the instance provider.
|
|
13
13
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
|
+
import type { LocalsContainer } from "../domain/LocalsContainer.js";
|
|
2
3
|
import type { Provider } from "../domain/Provider.js";
|
|
3
4
|
import type { InjectorService } from "../services/InjectorService.js";
|
|
4
5
|
import type { ResolvedInvokeOptions } from "./ResolvedInvokeOptions.js";
|
|
@@ -14,7 +15,7 @@ export interface RegistrySettings {
|
|
|
14
15
|
* @param {Map<string | Function, any>} locals
|
|
15
16
|
* @param options
|
|
16
17
|
*/
|
|
17
|
-
onInvoke?(provider: Provider, locals:
|
|
18
|
+
onInvoke?(provider: Provider, locals: LocalsContainer, options: ResolvedInvokeOptions & {
|
|
18
19
|
injector: InjectorService;
|
|
19
20
|
}): void;
|
|
20
21
|
}
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import type { Type } from "@tsed/core";
|
|
2
|
-
export type TokenProvider<T = any> = string | symbol | Type<T> |
|
|
3
|
-
export interface TokenProviderOpts {
|
|
4
|
-
token?: TokenProvider;
|
|
5
|
-
use: any;
|
|
6
|
-
}
|
|
1
|
+
import type { Type, AbstractType } from "@tsed/core";
|
|
2
|
+
export type TokenProvider<T = any> = string | symbol | Type<T> | AbstractType<T> | Function;
|
|
@@ -38,11 +38,11 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
|
|
|
38
38
|
* @returns {boolean} Returns true if an element in the Map object existed and has been removed, or false if the element does not exist.
|
|
39
39
|
*/
|
|
40
40
|
delete(key: TokenProvider): boolean;
|
|
41
|
-
createRegistry(type: string, model: Type<Provider>, options?: Partial<RegistrySettings>): this;
|
|
41
|
+
createRegistry(type: string | symbol, model: Type<Provider>, options?: Partial<RegistrySettings>): this;
|
|
42
42
|
onInvoke(provider: Provider, locals: LocalsContainer, options: ResolvedInvokeOptions & {
|
|
43
43
|
injector: InjectorService;
|
|
44
44
|
}): void;
|
|
45
|
-
getRegistrySettings(target:
|
|
45
|
+
getRegistrySettings(target: TokenProvider): RegistrySettings;
|
|
46
46
|
createRegisterFn(type: string): (provider: any | ProviderOpts, instance?: any) => void;
|
|
47
47
|
/**
|
|
48
48
|
*
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { type Type } from "@tsed/core";
|
|
2
1
|
import { Container } from "../domain/Container.js";
|
|
3
2
|
import { LocalsContainer } from "../domain/LocalsContainer.js";
|
|
4
3
|
import { Provider } from "../domain/Provider.js";
|
|
5
4
|
import { ProviderScope } from "../domain/ProviderScope.js";
|
|
6
5
|
import type { DILogger } from "../interfaces/DILogger.js";
|
|
7
|
-
import { InjectablePropertyOptions, InjectablePropertyValue } from "../interfaces/InjectableProperties.js";
|
|
8
6
|
import type { InvokeOptions } from "../interfaces/InvokeOptions.js";
|
|
9
7
|
import type { TokenProvider } from "../interfaces/TokenProvider.js";
|
|
10
8
|
import { DIConfiguration } from "./DIConfiguration.js";
|
|
@@ -37,8 +35,18 @@ export declare class InjectorService extends Container {
|
|
|
37
35
|
constructor();
|
|
38
36
|
get resolvers(): import("../index.js").DIResolver[];
|
|
39
37
|
get scopes(): Record<string, ProviderScope>;
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Return the current injector service.
|
|
40
|
+
*/
|
|
41
|
+
static getInstance(): InjectorService;
|
|
42
|
+
/**
|
|
43
|
+
* Get the locals container initiated by DITest or .bootstrap() method.
|
|
44
|
+
*/
|
|
45
|
+
static getLocals(): LocalsContainer;
|
|
46
|
+
/**
|
|
47
|
+
* Reset the locals container.
|
|
48
|
+
*/
|
|
49
|
+
static unsetLocals(): void;
|
|
42
50
|
/**
|
|
43
51
|
* Retrieve default scope for a given provider.
|
|
44
52
|
* @param provider
|
|
@@ -66,22 +74,19 @@ export declare class InjectorService extends Container {
|
|
|
66
74
|
*
|
|
67
75
|
* @param token The class or symbol registered in InjectorService.
|
|
68
76
|
* @param options
|
|
69
|
-
* @returns {boolean}
|
|
70
77
|
*/
|
|
71
|
-
get<T = any>(token: TokenProvider<T>, options?:
|
|
78
|
+
get<T = any>(token: TokenProvider<T>, options?: Record<string, unknown>): T | undefined;
|
|
72
79
|
/**
|
|
73
80
|
* Return all instance of the same provider type
|
|
74
|
-
* @param type
|
|
75
|
-
* @param locals
|
|
76
|
-
* @param options
|
|
77
81
|
*/
|
|
78
82
|
getMany<Type = any>(type: any, locals?: LocalsContainer, options?: Partial<InvokeOptions>): Type[];
|
|
79
83
|
/**
|
|
80
84
|
* The has() method returns a boolean indicating whether an element with the specified key exists or not.
|
|
81
|
-
* @returns {boolean}
|
|
82
|
-
* @param token
|
|
83
85
|
*/
|
|
84
86
|
has(token: TokenProvider): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Declare an alias for a given token.
|
|
89
|
+
*/
|
|
85
90
|
alias(token: TokenProvider, alias: TokenProvider): this;
|
|
86
91
|
/**
|
|
87
92
|
* Invoke the class and inject all services that required by the class constructor.
|
|
@@ -104,11 +109,14 @@ export declare class InjectorService extends Container {
|
|
|
104
109
|
* @param options
|
|
105
110
|
* @returns {Type} The class constructed.
|
|
106
111
|
*/
|
|
107
|
-
invoke<Type = any>(token: TokenProvider
|
|
112
|
+
invoke<Type = any>(token: TokenProvider<Type>, locals?: LocalsContainer, options?: Partial<InvokeOptions>): Type;
|
|
108
113
|
/**
|
|
109
114
|
* Build only providers which are asynchronous.
|
|
110
115
|
*/
|
|
111
116
|
loadAsync(): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Build only providers which are synchronous.
|
|
119
|
+
*/
|
|
112
120
|
loadSync(): void;
|
|
113
121
|
/**
|
|
114
122
|
* Boostrap injector from container and resolve configuration.
|
|
@@ -131,68 +139,36 @@ export declare class InjectorService extends Container {
|
|
|
131
139
|
* Load all configurations registered on providers
|
|
132
140
|
*/
|
|
133
141
|
resolveConfiguration(): void;
|
|
134
|
-
/**
|
|
135
|
-
*
|
|
136
|
-
* @param instance
|
|
137
|
-
* @param locals
|
|
138
|
-
* @param options
|
|
139
|
-
*/
|
|
140
|
-
bindInjectableProperties(instance: any, locals: LocalsContainer, options: Partial<InvokeOptions>): void;
|
|
141
|
-
/**
|
|
142
|
-
* Create an injectable property.
|
|
143
|
-
*
|
|
144
|
-
* @param instance
|
|
145
|
-
* @param {string} propertyKey
|
|
146
|
-
* @param {any} useType
|
|
147
|
-
* @param resolver
|
|
148
|
-
* @param options
|
|
149
|
-
* @param locals
|
|
150
|
-
* @param invokeOptions
|
|
151
|
-
*/
|
|
152
|
-
bindProperty(instance: any, { propertyKey, resolver, options }: InjectablePropertyOptions, locals: LocalsContainer, invokeOptions: Partial<InvokeOptions>): void;
|
|
153
|
-
/**
|
|
154
|
-
*
|
|
155
|
-
* @param instance
|
|
156
|
-
* @param {string} propertyKey
|
|
157
|
-
* @param {any} useType
|
|
158
|
-
*/
|
|
159
|
-
bindValue(instance: any, { propertyKey, expression, defaultValue }: InjectablePropertyValue): void;
|
|
160
|
-
/**
|
|
161
|
-
*
|
|
162
|
-
* @param instance
|
|
163
|
-
* @param {string} propertyKey
|
|
164
|
-
* @param {any} useType
|
|
165
|
-
*/
|
|
166
|
-
bindConstant(instance: any, { propertyKey, expression, defaultValue }: InjectablePropertyValue): void;
|
|
167
|
-
/**
|
|
168
|
-
*
|
|
169
|
-
* @param instance
|
|
170
|
-
* @param propertyKey
|
|
171
|
-
* @param useType
|
|
172
|
-
* @param options
|
|
173
|
-
*/
|
|
174
|
-
bindInterceptor(instance: any, { propertyKey, useType, options }: InjectablePropertyOptions): void;
|
|
175
142
|
lazyInvoke<T = any>(token: TokenProvider): Promise<any>;
|
|
176
143
|
/**
|
|
177
144
|
* Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
|
|
178
145
|
* @param eventName The event name to emit at all services.
|
|
179
146
|
* @param args List of the parameters to give to each service.
|
|
180
|
-
* @returns
|
|
147
|
+
* @returns A list of promises.
|
|
181
148
|
*/
|
|
182
149
|
emit(eventName: string, ...args: any[]): Promise<void>;
|
|
183
150
|
/**
|
|
151
|
+
* Alter value attached to an event.
|
|
184
152
|
* @param eventName
|
|
185
153
|
* @param value
|
|
186
154
|
* @param args
|
|
187
155
|
*/
|
|
188
156
|
alter<T = any>(eventName: string, value: any, ...args: any[]): T;
|
|
189
157
|
/**
|
|
158
|
+
* Alter value attached to an event asynchronously.
|
|
190
159
|
* @param eventName
|
|
191
160
|
* @param value
|
|
192
161
|
* @param args
|
|
193
162
|
*/
|
|
194
163
|
alterAsync<T = any>(eventName: string, value: any, ...args: any[]): Promise<T>;
|
|
164
|
+
/**
|
|
165
|
+
* Destroy the injector and all services.
|
|
166
|
+
*/
|
|
195
167
|
destroy(): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Ensure that a provider is added to the container.
|
|
170
|
+
* @protected
|
|
171
|
+
*/
|
|
196
172
|
protected ensureProvider(token: TokenProvider, force: true): Provider;
|
|
197
173
|
protected ensureProvider(token: TokenProvider, force: false): Provider | undefined;
|
|
198
174
|
protected ensureProvider(token: TokenProvider): Provider | undefined;
|
|
@@ -25,7 +25,7 @@ export declare class DITest {
|
|
|
25
25
|
* @param target
|
|
26
26
|
* @param providers
|
|
27
27
|
*/
|
|
28
|
-
static invoke<T = any>(target: TokenProvider
|
|
28
|
+
static invoke<T = any>(target: TokenProvider<T>, providers?: UseImportTokenProviderOpts[]): Promise<T>;
|
|
29
29
|
/**
|
|
30
30
|
* Return the instance from injector registry
|
|
31
31
|
* @param target
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
1
|
+
export declare const DI_INVOKE_OPTIONS: unique symbol;
|
|
2
|
+
export declare const DI_INJECTABLE_PROPS: unique symbol;
|
|
3
|
+
export declare const DI_USE_OPTIONS = "DI_USE_OPTIONS";
|
|
4
|
+
export declare const DI_USE_PARAM_OPTIONS = "DI_USE_PARAM_OPTIONS";
|
|
5
|
+
export declare const DI_INTERCEPTOR_OPTIONS = "DI_INTERCEPTOR_OPTIONS";
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export declare function constant<Type>(expression: string): Type | undefined;
|
|
2
|
+
export declare function constant<Type>(expression: string, defaultValue: Type | undefined): Type;
|
|
3
|
+
export declare function bindConstant(target: any, propertyKey: string | symbol, expression: string, defaultValue?: any): void;
|
|
1
4
|
/**
|
|
2
5
|
* Return value from Configuration.
|
|
3
6
|
*
|
|
@@ -33,4 +36,4 @@
|
|
|
33
36
|
* @returns {(targetClass: any, attributeName: string) => any}
|
|
34
37
|
* @decorator
|
|
35
38
|
*/
|
|
36
|
-
export declare function Constant(expression: string, defaultValue?:
|
|
39
|
+
export declare function Constant<Type = unknown>(expression: string, defaultValue?: Type): PropertyDecorator;
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Type } from "@tsed/core";
|
|
2
|
+
import type { InvokeOptions } from "../interfaces/InvokeOptions.js";
|
|
2
3
|
import { TokenProvider } from "../interfaces/TokenProvider.js";
|
|
3
|
-
export declare function
|
|
4
|
+
export declare function inject<T>(token: TokenProvider<T>, opts?: Partial<Pick<InvokeOptions, "useOpts" | "rebuild" | "locals">>): T;
|
|
5
|
+
export declare function injectMany<T>(token: string | symbol, opts?: Partial<Pick<InvokeOptions, "useOpts" | "rebuild" | "locals">>): T[];
|
|
6
|
+
export type TransformInjectedProviderCB<T, Klass = any> = (instance: T, { target, propertyKey }: {
|
|
7
|
+
self: Klass;
|
|
8
|
+
target: Type<Klass>;
|
|
9
|
+
propertyKey: symbol | string;
|
|
10
|
+
}) => unknown;
|
|
11
|
+
export interface BindInjectablePropertyOpts<T = any> {
|
|
12
|
+
token?: TokenProvider;
|
|
13
|
+
useOpts?: Record<string, unknown>;
|
|
14
|
+
transform?: TransformInjectedProviderCB<T>;
|
|
15
|
+
}
|
|
4
16
|
/**
|
|
5
17
|
* Inject a provider to another provider.
|
|
6
18
|
*
|
|
@@ -15,8 +27,9 @@ export declare function injectProperty(target: any, propertyKey: string, options
|
|
|
15
27
|
* ```
|
|
16
28
|
*
|
|
17
29
|
* @param token A token provider or token provider group
|
|
18
|
-
* @param
|
|
30
|
+
* @param transform
|
|
19
31
|
* @returns {Function}
|
|
20
32
|
* @decorator
|
|
21
33
|
*/
|
|
22
|
-
export declare function Inject(token?: TokenProvider | (() => TokenProvider),
|
|
34
|
+
export declare function Inject<T = any>(token?: TokenProvider<T> | (() => TokenProvider<T>), transform?: TransformInjectedProviderCB<T>): any;
|
|
35
|
+
export declare function Inject<T = any>(token?: TokenProvider<T> | (() => TokenProvider<T>), opts?: Partial<Omit<BindInjectablePropertyOpts<T>, "token">>): any;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
2
|
import type { InterceptorMethods } from "../interfaces/InterceptorMethods.js";
|
|
3
|
+
import type { TokenProvider } from "../interfaces/TokenProvider.js";
|
|
4
|
+
export declare function getInterceptorOptions<T>(target: Type<any>, propertyKey: string | symbol): T;
|
|
5
|
+
export declare function bindIntercept(target: any, propertyKey: string | symbol, token: TokenProvider, options: Record<string, unknown>): TypedPropertyDescriptor<any> | undefined;
|
|
3
6
|
/**
|
|
4
7
|
* Attaches interceptor to method call and executes the before and after methods
|
|
5
8
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare function bindValue(target: any, propertyKey: string | symbol, expression: string, defaultValue?: any): void;
|
|
1
2
|
/**
|
|
2
3
|
* Return value from Configuration.
|
|
3
4
|
*
|
|
@@ -33,4 +34,4 @@
|
|
|
33
34
|
* @returns {(targetClass: any, attributeName: string) => any}
|
|
34
35
|
* @decorator
|
|
35
36
|
*/
|
|
36
|
-
export declare function Value(expression:
|
|
37
|
+
export declare function Value(expression: string, defaultValue?: unknown): PropertyDecorator;
|
|
@@ -31,13 +31,13 @@ export declare class Container extends Map<TokenProvider, Provider> {
|
|
|
31
31
|
* @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.
|
|
32
32
|
* @param token
|
|
33
33
|
*/
|
|
34
|
-
getProvider<T extends Provider = Provider>(token: TokenProvider): T | undefined;
|
|
34
|
+
getProvider<T extends Provider = Provider>(token: TokenProvider | undefined): T | undefined;
|
|
35
35
|
/**
|
|
36
36
|
* Get all providers registered in the injector container.
|
|
37
37
|
*
|
|
38
|
-
* @param
|
|
38
|
+
* @param type Filter the list by the given ProviderType.
|
|
39
39
|
* @returns {[TokenProvider , Provider<any>][]}
|
|
40
40
|
*/
|
|
41
|
-
getProviders(type?: ProviderType | string | string[]): Provider[];
|
|
41
|
+
getProviders(type?: TokenProvider | ProviderType | string | string[]): Provider[];
|
|
42
42
|
addProviders(container: Map<TokenProvider, Provider>): void;
|
|
43
43
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Store, Type } from "@tsed/core";
|
|
1
|
+
import { type AbstractType, Store, Type } from "@tsed/core";
|
|
2
2
|
import type { ProviderOpts } from "../interfaces/ProviderOpts.js";
|
|
3
3
|
import type { TokenProvider } from "../interfaces/TokenProvider.js";
|
|
4
4
|
import { ProviderScope } from "./ProviderScope.js";
|
|
@@ -8,7 +8,7 @@ export declare class Provider<T = any> implements ProviderOpts<T> {
|
|
|
8
8
|
/**
|
|
9
9
|
* Token group provider to retrieve all provider from the same type
|
|
10
10
|
*/
|
|
11
|
-
type:
|
|
11
|
+
type: ProviderType | TokenProvider;
|
|
12
12
|
deps: TokenProvider[];
|
|
13
13
|
imports: (TokenProvider | [TokenProvider])[];
|
|
14
14
|
alias?: string;
|
|
@@ -21,16 +21,16 @@ export declare class Provider<T = any> implements ProviderOpts<T> {
|
|
|
21
21
|
private _store;
|
|
22
22
|
private _tokenStore;
|
|
23
23
|
[key: string]: any;
|
|
24
|
-
constructor(token: TokenProvider
|
|
25
|
-
get token(): any
|
|
24
|
+
constructor(token: TokenProvider<T>, options?: Partial<Provider>);
|
|
25
|
+
get token(): TokenProvider<any>;
|
|
26
26
|
get provide(): TokenProvider;
|
|
27
27
|
set provide(value: TokenProvider);
|
|
28
28
|
get useClass(): Type<T>;
|
|
29
29
|
/**
|
|
30
|
-
* Create a new store if the given value is a class. Otherwise the value is ignored.
|
|
30
|
+
* Create a new store if the given value is a class. Otherwise, the value is ignored.
|
|
31
31
|
* @param value
|
|
32
32
|
*/
|
|
33
|
-
set useClass(value: Type<T>);
|
|
33
|
+
set useClass(value: Type<T> | AbstractType<T>);
|
|
34
34
|
get className(): string;
|
|
35
35
|
get name(): string;
|
|
36
36
|
get store(): Store;
|
|
@@ -27,13 +27,11 @@ export * from "./domain/ProviderScope.js";
|
|
|
27
27
|
export * from "./domain/ProviderType.js";
|
|
28
28
|
export * from "./errors/InjectionError.js";
|
|
29
29
|
export * from "./errors/InvalidPropertyTokenError.js";
|
|
30
|
-
export * from "./errors/UndefinedTokenError.js";
|
|
31
30
|
export * from "./interfaces/DIConfigurationOptions.js";
|
|
32
31
|
export * from "./interfaces/DILogger.js";
|
|
33
32
|
export * from "./interfaces/DILoggerOptions.js";
|
|
34
33
|
export * from "./interfaces/DIResolver.js";
|
|
35
34
|
export * from "./interfaces/ImportTokenProviderOpts.js";
|
|
36
|
-
export * from "./interfaces/InjectableProperties.js";
|
|
37
35
|
export * from "./interfaces/InterceptorContext.js";
|
|
38
36
|
export * from "./interfaces/InterceptorMethods.js";
|
|
39
37
|
export * from "./interfaces/InvokeOptions.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Type } from "@tsed/core";
|
|
1
|
+
import type { AbstractType, Type } from "@tsed/core";
|
|
2
2
|
import type { TokenProvider } from "./TokenProvider.js";
|
|
3
3
|
export type UseImportTokenProviderOpts = {
|
|
4
4
|
token: TokenProvider;
|
|
@@ -6,7 +6,7 @@ export type UseImportTokenProviderOpts = {
|
|
|
6
6
|
};
|
|
7
7
|
export type UseClassImportTokenProviderOpts = {
|
|
8
8
|
token: TokenProvider;
|
|
9
|
-
useClass: Type |
|
|
9
|
+
useClass: Type | AbstractType<any>;
|
|
10
10
|
};
|
|
11
11
|
export type UseFactoryImportTokenProviderOpts = {
|
|
12
12
|
token: TokenProvider;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import type { LocalsContainer } from "../domain/LocalsContainer.js";
|
|
1
2
|
import { ProviderScope } from "../domain/ProviderScope.js";
|
|
2
3
|
import { TokenProvider } from "./TokenProvider.js";
|
|
3
4
|
export interface InvokeOptions {
|
|
4
5
|
/**
|
|
5
6
|
* Define dependencies to build the provider and inject them in the constructor.
|
|
6
7
|
*/
|
|
7
|
-
deps:
|
|
8
|
+
deps: TokenProvider[];
|
|
8
9
|
/**
|
|
9
10
|
* List of imports to be created before the provider. Imports list aren't injected directly in the provider constructor.
|
|
10
11
|
*/
|
|
11
|
-
imports:
|
|
12
|
+
imports: TokenProvider[];
|
|
12
13
|
/**
|
|
13
14
|
* Parent provider.
|
|
14
15
|
*/
|
|
@@ -21,4 +22,9 @@ export interface InvokeOptions {
|
|
|
21
22
|
* If true, the injector will rebuild the instance.
|
|
22
23
|
*/
|
|
23
24
|
rebuild?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Option given to injectable props or parameter constructor (UseOpts).
|
|
27
|
+
*/
|
|
28
|
+
useOpts?: Record<string, unknown>;
|
|
29
|
+
locals?: LocalsContainer;
|
|
24
30
|
}
|
|
@@ -7,7 +7,7 @@ export interface ProviderOpts<T = any> {
|
|
|
7
7
|
/**
|
|
8
8
|
* An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
|
|
9
9
|
*/
|
|
10
|
-
provide: TokenProvider
|
|
10
|
+
provide: TokenProvider<T>;
|
|
11
11
|
/**
|
|
12
12
|
* Create alias token to retrieve the instance provider.
|
|
13
13
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
|
+
import type { LocalsContainer } from "../domain/LocalsContainer.js";
|
|
2
3
|
import type { Provider } from "../domain/Provider.js";
|
|
3
4
|
import type { InjectorService } from "../services/InjectorService.js";
|
|
4
5
|
import type { ResolvedInvokeOptions } from "./ResolvedInvokeOptions.js";
|
|
@@ -14,7 +15,7 @@ export interface RegistrySettings {
|
|
|
14
15
|
* @param {Map<string | Function, any>} locals
|
|
15
16
|
* @param options
|
|
16
17
|
*/
|
|
17
|
-
onInvoke?(provider: Provider, locals:
|
|
18
|
+
onInvoke?(provider: Provider, locals: LocalsContainer, options: ResolvedInvokeOptions & {
|
|
18
19
|
injector: InjectorService;
|
|
19
20
|
}): void;
|
|
20
21
|
}
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import type { Type } from "@tsed/core";
|
|
2
|
-
export type TokenProvider<T = any> = string | symbol | Type<T> |
|
|
3
|
-
export interface TokenProviderOpts {
|
|
4
|
-
token?: TokenProvider;
|
|
5
|
-
use: any;
|
|
6
|
-
}
|
|
1
|
+
import type { Type, AbstractType } from "@tsed/core";
|
|
2
|
+
export type TokenProvider<T = any> = string | symbol | Type<T> | AbstractType<T> | Function;
|
|
@@ -38,11 +38,11 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
|
|
|
38
38
|
* @returns {boolean} Returns true if an element in the Map object existed and has been removed, or false if the element does not exist.
|
|
39
39
|
*/
|
|
40
40
|
delete(key: TokenProvider): boolean;
|
|
41
|
-
createRegistry(type: string, model: Type<Provider>, options?: Partial<RegistrySettings>): this;
|
|
41
|
+
createRegistry(type: string | symbol, model: Type<Provider>, options?: Partial<RegistrySettings>): this;
|
|
42
42
|
onInvoke(provider: Provider, locals: LocalsContainer, options: ResolvedInvokeOptions & {
|
|
43
43
|
injector: InjectorService;
|
|
44
44
|
}): void;
|
|
45
|
-
getRegistrySettings(target:
|
|
45
|
+
getRegistrySettings(target: TokenProvider): RegistrySettings;
|
|
46
46
|
createRegisterFn(type: string): (provider: any | ProviderOpts, instance?: any) => void;
|
|
47
47
|
/**
|
|
48
48
|
*
|