@tsed/di 6.107.5 → 6.110.0
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/decorators/controller.js.map +1 -1
- package/lib/cjs/decorators/injectable.js.map +1 -1
- package/lib/cjs/domain/Container.js.map +1 -1
- package/lib/cjs/domain/Provider.js.map +1 -1
- package/lib/cjs/index.js +49 -49
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/{IProvider.js → ProviderOpts.js} +1 -1
- package/lib/cjs/interfaces/ProviderOpts.js.map +1 -0
- package/lib/cjs/registries/GlobalProviders.js +4 -4
- package/lib/cjs/registries/GlobalProviders.js.map +1 -1
- package/lib/cjs/registries/ProviderRegistry.js +1 -1
- package/lib/cjs/registries/ProviderRegistry.js.map +1 -1
- package/lib/cjs/services/InjectorService.js +31 -17
- package/lib/cjs/services/InjectorService.js.map +1 -1
- package/lib/esm/decorators/controller.js.map +1 -1
- package/lib/esm/decorators/injectable.js.map +1 -1
- package/lib/esm/domain/Container.js.map +1 -1
- package/lib/esm/domain/Provider.js.map +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/ProviderOpts.js +2 -0
- package/lib/esm/interfaces/ProviderOpts.js.map +1 -0
- package/lib/esm/registries/GlobalProviders.js.map +1 -1
- package/lib/esm/registries/ProviderRegistry.js +1 -1
- package/lib/esm/registries/ProviderRegistry.js.map +1 -1
- package/lib/esm/services/InjectorService.js +14 -0
- package/lib/esm/services/InjectorService.js.map +1 -1
- package/lib/types/decorators/controller.d.ts +2 -2
- package/lib/types/decorators/injectable.d.ts +2 -2
- package/lib/types/domain/Container.d.ts +3 -3
- package/lib/types/domain/Provider.d.ts +3 -2
- package/lib/types/index.d.ts +1 -1
- package/lib/types/interfaces/{IProvider.d.ts → ProviderOpts.d.ts} +10 -4
- package/lib/types/registries/GlobalProviders.d.ts +4 -4
- package/lib/types/registries/ProviderRegistry.d.ts +4 -4
- package/lib/types/services/InjectorService.d.ts +7 -2
- package/package.json +19 -8
- package/lib/cjs/interfaces/IProvider.js.map +0 -1
- package/lib/esm/interfaces/IProvider.js +0 -2
- package/lib/esm/interfaces/IProvider.js.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
|
-
import {
|
|
2
|
+
import { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
3
3
|
export declare type PathType = string | RegExp | (string | RegExp)[];
|
|
4
4
|
export interface ControllerMiddlewares {
|
|
5
5
|
useBefore: any[];
|
|
6
6
|
use: any[];
|
|
7
7
|
useAfter: any[];
|
|
8
8
|
}
|
|
9
|
-
export interface ControllerOptions extends Partial<
|
|
9
|
+
export interface ControllerOptions extends Partial<ProviderOpts<any>> {
|
|
10
10
|
path?: PathType;
|
|
11
11
|
children?: Type<any>[];
|
|
12
12
|
routerOptions?: any;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
2
2
|
/**
|
|
3
3
|
* The decorators `@Injectable()` declare a new service can be injected in other service, controller, interceptor, etc.. on there `constructor`.
|
|
4
4
|
* All classes annotated with `@Injectable()` are built one time, excepted if you change the default provider configuration.
|
|
@@ -17,4 +17,4 @@ import type { IProvider } from "../interfaces/IProvider";
|
|
|
17
17
|
* @returns {Function}
|
|
18
18
|
* @decorator
|
|
19
19
|
*/
|
|
20
|
-
export declare function Injectable(options?: Partial<
|
|
20
|
+
export declare function Injectable(options?: Partial<ProviderOpts>): ClassDecorator;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
2
2
|
import type { ProviderType } from "./ProviderType";
|
|
3
3
|
import type { TokenProvider } from "../interfaces/TokenProvider";
|
|
4
4
|
import { Provider } from "./Provider";
|
|
@@ -8,13 +8,13 @@ export declare class Container extends Map<TokenProvider, Provider> {
|
|
|
8
8
|
* @param token
|
|
9
9
|
* @param settings
|
|
10
10
|
*/
|
|
11
|
-
add(token: TokenProvider, settings?: Partial<
|
|
11
|
+
add(token: TokenProvider, settings?: Partial<ProviderOpts>): this;
|
|
12
12
|
/**
|
|
13
13
|
* Add a provider to the
|
|
14
14
|
* @param token
|
|
15
15
|
* @param settings
|
|
16
16
|
*/
|
|
17
|
-
addProvider(token: TokenProvider, settings?: Partial<
|
|
17
|
+
addProvider(token: TokenProvider, settings?: Partial<ProviderOpts>): this;
|
|
18
18
|
/**
|
|
19
19
|
*
|
|
20
20
|
* @param token
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Store, Type } from "@tsed/core";
|
|
2
|
-
import {
|
|
2
|
+
import { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
3
3
|
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
4
4
|
import { ProviderScope } from "./ProviderScope";
|
|
5
5
|
import { ProviderType } from "./ProviderType";
|
|
6
|
-
export declare class Provider<T = any> implements
|
|
6
|
+
export declare class Provider<T = any> implements ProviderOpts<T> {
|
|
7
7
|
type: ProviderType | any;
|
|
8
8
|
/**
|
|
9
9
|
* @deprecated Use injector.get(provider.token) instead.
|
|
@@ -14,6 +14,7 @@ export declare class Provider<T = any> implements IProvider<T> {
|
|
|
14
14
|
useFactory: Function;
|
|
15
15
|
useAsyncFactory: Function;
|
|
16
16
|
useValue: any;
|
|
17
|
+
hooks?: Record<string, (instance: T, ...args: any[]) => Promise<void> | void>;
|
|
17
18
|
private _useClass;
|
|
18
19
|
private _provide;
|
|
19
20
|
private _store;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -30,13 +30,13 @@ export * from "./errors/UndefinedTokenError";
|
|
|
30
30
|
export * from "./interfaces/DIConfigurationOptions";
|
|
31
31
|
export * from "./interfaces/DILogger";
|
|
32
32
|
export * from "./interfaces/DIResolver";
|
|
33
|
-
export * from "./interfaces/IProvider";
|
|
34
33
|
export * from "./interfaces/InjectableProperties";
|
|
35
34
|
export * from "./interfaces/InterceptorContext";
|
|
36
35
|
export * from "./interfaces/InterceptorMethods";
|
|
37
36
|
export * from "./interfaces/InvokeOptions";
|
|
38
37
|
export * from "./interfaces/OnDestroy";
|
|
39
38
|
export * from "./interfaces/OnInit";
|
|
39
|
+
export * from "./interfaces/ProviderOpts";
|
|
40
40
|
export * from "./interfaces/RegistrySettings";
|
|
41
41
|
export * from "./interfaces/ResolvedInvokeOptions";
|
|
42
42
|
export * from "./interfaces/TokenProvider";
|
|
@@ -3,10 +3,7 @@ import type { DIResolver } from "./DIResolver";
|
|
|
3
3
|
import type { ProviderScope } from "../domain/ProviderScope";
|
|
4
4
|
import type { ProviderType } from "../domain/ProviderType";
|
|
5
5
|
import type { TokenProvider } from "./TokenProvider";
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
export interface IProvider<T = any> {
|
|
6
|
+
export interface ProviderOpts<T = any> {
|
|
10
7
|
/**
|
|
11
8
|
* An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).
|
|
12
9
|
*/
|
|
@@ -47,8 +44,17 @@ export interface IProvider<T = any> {
|
|
|
47
44
|
* A list of resolvers which will be used to resolve missing Symbol/Class when injector invoke a Class. This property allow external DI usage.
|
|
48
45
|
*/
|
|
49
46
|
resolvers?: DIResolver[];
|
|
47
|
+
/**
|
|
48
|
+
* hooks to intercept custom events
|
|
49
|
+
*/
|
|
50
|
+
hooks?: Record<string, (instance: T, ...args: any[]) => Promise<any> | any>;
|
|
50
51
|
/**
|
|
51
52
|
*
|
|
52
53
|
*/
|
|
53
54
|
[key: string]: any;
|
|
54
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated
|
|
58
|
+
*/
|
|
59
|
+
export interface IProvider<T = any> extends ProviderOpts<T> {
|
|
60
|
+
}
|
|
@@ -4,7 +4,7 @@ import type { InjectorService } from "../services/InjectorService";
|
|
|
4
4
|
import { ResolvedInvokeOptions } from "../interfaces/ResolvedInvokeOptions";
|
|
5
5
|
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
6
6
|
import { RegistrySettings } from "../interfaces/RegistrySettings";
|
|
7
|
-
import {
|
|
7
|
+
import { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
8
8
|
export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider> {
|
|
9
9
|
#private;
|
|
10
10
|
/**
|
|
@@ -30,7 +30,7 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
|
|
|
30
30
|
* @param target
|
|
31
31
|
* @param options
|
|
32
32
|
*/
|
|
33
|
-
merge(target: TokenProvider, options: Partial<
|
|
33
|
+
merge(target: TokenProvider, options: Partial<ProviderOpts>): void;
|
|
34
34
|
/**
|
|
35
35
|
* The delete() method removes the specified element from a Map object.
|
|
36
36
|
* @param key Required. The key of the element to remove from the Map object.
|
|
@@ -42,13 +42,13 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
|
|
|
42
42
|
injector: InjectorService;
|
|
43
43
|
}): void;
|
|
44
44
|
getRegistrySettings(target: string | TokenProvider): RegistrySettings;
|
|
45
|
-
createRegisterFn(type: string): (provider: any |
|
|
45
|
+
createRegisterFn(type: string): (provider: any | ProviderOpts, instance?: any) => void;
|
|
46
46
|
/**
|
|
47
47
|
*
|
|
48
48
|
* @param key
|
|
49
49
|
* @param options
|
|
50
50
|
*/
|
|
51
|
-
protected createIfNotExists(key: TokenProvider, options: Partial<
|
|
51
|
+
protected createIfNotExists(key: TokenProvider, options: Partial<ProviderOpts>): Provider;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
*
|
|
@@ -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 factory in the `ProviderRegistry`.
|
|
9
9
|
*
|
|
@@ -89,7 +89,7 @@ export declare const registerFactory: typeof registerProvider;
|
|
|
89
89
|
* }
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
92
|
-
export declare const registerValue: (provider: any |
|
|
92
|
+
export declare const registerValue: (provider: any | ProviderOpts<any>, value?: any) => void;
|
|
93
93
|
/**
|
|
94
94
|
* Add a new controller in the `ProviderRegistry`. This controller will be built when `InjectorService` will be loaded.
|
|
95
95
|
*
|
|
@@ -5,7 +5,7 @@ import { DIConfiguration } from "./DIConfiguration";
|
|
|
5
5
|
import { ProviderScope } from "../domain/ProviderScope";
|
|
6
6
|
import { DILogger } from "../interfaces/DILogger";
|
|
7
7
|
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
8
|
-
import {
|
|
8
|
+
import { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
9
9
|
import { InvokeOptions } from "../interfaces/InvokeOptions";
|
|
10
10
|
import { InjectablePropertyOptions, InjectablePropertyValue } from "../interfaces/InjectableProperties";
|
|
11
11
|
import { DIContext } from "../domain/DIContext";
|
|
@@ -53,7 +53,7 @@ export declare class InjectorService extends Container {
|
|
|
53
53
|
* @param settings
|
|
54
54
|
* @deprecated
|
|
55
55
|
*/
|
|
56
|
-
forkProvider(token: TokenProvider, settings?: Partial<
|
|
56
|
+
forkProvider(token: TokenProvider, settings?: Partial<ProviderOpts<any>>): Provider;
|
|
57
57
|
/**
|
|
58
58
|
* Return a list of instance build by the injector.
|
|
59
59
|
*/
|
|
@@ -79,6 +79,11 @@ export declare class InjectorService extends Container {
|
|
|
79
79
|
* @returns {boolean}
|
|
80
80
|
*/
|
|
81
81
|
get<T = any>(token: TokenProvider, options?: any): T | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Return all instance of the same provider type
|
|
84
|
+
* @param type
|
|
85
|
+
*/
|
|
86
|
+
getAll(type: string): any[];
|
|
82
87
|
/**
|
|
83
88
|
* The has() method returns a boolean indicating whether an element with the specified key exists or not.
|
|
84
89
|
* @returns {boolean}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/di",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.110.0",
|
|
4
4
|
"description": "DI module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -20,17 +20,28 @@
|
|
|
20
20
|
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\""
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"tslib": "2.
|
|
23
|
+
"tslib": "2.3.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@tsed/core": "6.
|
|
27
|
-
"@tsed/logger": ">=6.1.
|
|
28
|
-
"@tsed/schema": "6.
|
|
26
|
+
"@tsed/core": "6.110.0",
|
|
27
|
+
"@tsed/logger": ">=6.1.1",
|
|
28
|
+
"@tsed/schema": "6.110.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@tsed/core": "^6.
|
|
32
|
-
"@tsed/logger": ">=6.1.
|
|
33
|
-
"@tsed/schema": "^6.
|
|
31
|
+
"@tsed/core": "^6.110.0",
|
|
32
|
+
"@tsed/logger": ">=6.1.1",
|
|
33
|
+
"@tsed/schema": "^6.110.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"@tsed/core": {
|
|
37
|
+
"optional": false
|
|
38
|
+
},
|
|
39
|
+
"@tsed/logger": {
|
|
40
|
+
"optional": false
|
|
41
|
+
},
|
|
42
|
+
"@tsed/schema": {
|
|
43
|
+
"optional": false
|
|
44
|
+
}
|
|
34
45
|
},
|
|
35
46
|
"repository": "https://github.com/tsedio/tsed",
|
|
36
47
|
"bugs": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../../src/interfaces/IProvider.ts"],"names":[],"mappings":"","sourcesContent":["import type {Type} from \"@tsed/core\";\nimport type {DIResolver} from \"./DIResolver\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {ProviderType} from \"../domain/ProviderType\";\nimport type {TokenProvider} from \"./TokenProvider\";\n/**\n *\n */\nexport interface IProvider<T = any> {\n /**\n * An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).\n */\n provide: TokenProvider;\n /**\n * Provider type\n */\n type?: ProviderType | string;\n /**\n * Instance build by the injector\n */\n instance?: T;\n /**\n * Define dependencies to build the provider\n */\n deps?: TokenProvider[];\n /**\n * Class to instantiate for the `token`.\n */\n useClass?: Type<T>;\n /**\n * Provide a function to build the provider\n */\n useFactory?: Function;\n /**\n * Provide an async function to build the provider\n */\n useAsyncFactory?: Function;\n /**\n * Provide predefined value\n */\n useValue?: any;\n /**\n * Scope used by the injector to build the provider.\n */\n scope?: ProviderScope;\n /**\n * A list of resolvers which will be used to resolve missing Symbol/Class when injector invoke a Class. This property allow external DI usage.\n */\n resolvers?: DIResolver[];\n\n /**\n *\n */\n [key: string]: any;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../../src/interfaces/IProvider.ts"],"names":[],"mappings":"","sourcesContent":["import type {Type} from \"@tsed/core\";\nimport type {DIResolver} from \"./DIResolver\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {ProviderType} from \"../domain/ProviderType\";\nimport type {TokenProvider} from \"./TokenProvider\";\n/**\n *\n */\nexport interface IProvider<T = any> {\n /**\n * An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).\n */\n provide: TokenProvider;\n /**\n * Provider type\n */\n type?: ProviderType | string;\n /**\n * Instance build by the injector\n */\n instance?: T;\n /**\n * Define dependencies to build the provider\n */\n deps?: TokenProvider[];\n /**\n * Class to instantiate for the `token`.\n */\n useClass?: Type<T>;\n /**\n * Provide a function to build the provider\n */\n useFactory?: Function;\n /**\n * Provide an async function to build the provider\n */\n useAsyncFactory?: Function;\n /**\n * Provide predefined value\n */\n useValue?: any;\n /**\n * Scope used by the injector to build the provider.\n */\n scope?: ProviderScope;\n /**\n * A list of resolvers which will be used to resolve missing Symbol/Class when injector invoke a Class. This property allow external DI usage.\n */\n resolvers?: DIResolver[];\n\n /**\n *\n */\n [key: string]: any;\n}\n"]}
|