@tsed/di 7.0.0-beta.2 → 7.0.0-beta.20
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/coverage.json +6 -0
- package/jest.config.js +9 -0
- package/lib/cjs/constants/{index.js → constants.js} +1 -1
- package/lib/cjs/constants/constants.js.map +1 -0
- package/lib/cjs/decorators/constant.js +1 -1
- package/lib/cjs/decorators/constant.js.map +1 -1
- package/lib/cjs/decorators/controller.js.map +1 -1
- package/lib/cjs/decorators/inject.js +27 -2
- package/lib/cjs/decorators/inject.js.map +1 -1
- package/lib/cjs/decorators/injectable.js +0 -2
- package/lib/cjs/decorators/injectable.js.map +1 -1
- package/lib/cjs/decorators/intercept.js +20 -12
- package/lib/cjs/decorators/intercept.js.map +1 -1
- package/lib/cjs/decorators/module.js +4 -3
- package/lib/cjs/decorators/module.js.map +1 -1
- package/lib/cjs/decorators/opts.js +1 -1
- package/lib/cjs/decorators/opts.js.map +1 -1
- package/lib/cjs/decorators/useOpts.js +1 -1
- package/lib/cjs/decorators/useOpts.js.map +1 -1
- package/lib/cjs/decorators/value.js +1 -1
- package/lib/cjs/decorators/value.js.map +1 -1
- package/lib/cjs/domain/Container.js +1 -2
- package/lib/cjs/domain/Container.js.map +1 -1
- package/lib/cjs/domain/ContextLogger.js +41 -30
- package/lib/cjs/domain/ContextLogger.js.map +1 -1
- package/lib/cjs/domain/ControllerProvider.js +37 -0
- package/lib/cjs/domain/ControllerProvider.js.map +1 -0
- package/lib/cjs/domain/DIContext.js +86 -30
- package/lib/cjs/domain/DIContext.js.map +1 -1
- package/lib/cjs/domain/LocalsContainer.js +3 -46
- package/lib/cjs/domain/LocalsContainer.js.map +1 -1
- package/lib/cjs/domain/Provider.js +20 -1
- package/lib/cjs/domain/Provider.js.map +1 -1
- package/lib/cjs/errors/InjectionError.js +3 -2
- package/lib/cjs/errors/InjectionError.js.map +1 -1
- package/lib/cjs/errors/UndefinedTokenError.js +1 -1
- package/lib/cjs/errors/UndefinedTokenError.js.map +1 -1
- package/lib/cjs/index.js +60 -17
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/AlterRunInContext.js +3 -0
- package/lib/cjs/interfaces/AlterRunInContext.js.map +1 -0
- package/lib/cjs/interfaces/DIConfigurationOptions.js.map +1 -1
- package/lib/cjs/interfaces/DILoggerOptions.js +3 -0
- package/lib/cjs/interfaces/DILoggerOptions.js.map +1 -0
- package/lib/cjs/interfaces/InjectableProperties.js.map +1 -1
- package/lib/cjs/interfaces/InterceptorMethods.js.map +1 -1
- package/lib/cjs/interfaces/ProviderOpts.js +3 -0
- package/lib/cjs/interfaces/ProviderOpts.js.map +1 -0
- package/lib/cjs/interfaces/RegistrySettings.js.map +1 -1
- package/lib/cjs/interfaces/TokenProvider.js.map +1 -1
- package/lib/cjs/interfaces/{IProvider.js → TokenRoute.js} +1 -1
- package/lib/cjs/interfaces/TokenRoute.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/registries/GlobalProviders.js +7 -12
- package/lib/cjs/registries/GlobalProviders.js.map +1 -1
- package/lib/cjs/registries/ProviderRegistry.js +8 -7
- package/lib/cjs/registries/ProviderRegistry.js.map +1 -1
- package/lib/cjs/services/DIConfiguration.js +56 -43
- package/lib/cjs/services/DIConfiguration.js.map +1 -1
- package/lib/cjs/services/DITest.js +13 -6
- package/lib/cjs/services/DITest.js.map +1 -1
- package/lib/cjs/services/InjectorService.js +115 -113
- package/lib/cjs/services/InjectorService.js.map +1 -1
- package/lib/cjs/utils/asyncHookContext.js +42 -0
- package/lib/cjs/utils/asyncHookContext.js.map +1 -0
- package/lib/cjs/utils/getConfiguration.js +13 -10
- package/lib/cjs/utils/getConfiguration.js.map +1 -1
- package/lib/cjs/utils/resolveControllers.js +47 -0
- package/lib/cjs/utils/resolveControllers.js.map +1 -0
- package/lib/cjs/utils/setLoggerConfiguration.js +11 -0
- package/lib/cjs/utils/setLoggerConfiguration.js.map +1 -0
- package/lib/cjs/utils/setLoggerFormat.js +33 -0
- package/lib/cjs/utils/setLoggerFormat.js.map +1 -0
- package/lib/cjs/utils/setLoggerLevel.js +1 -2
- package/lib/cjs/utils/setLoggerLevel.js.map +1 -1
- package/lib/esm/constants/{index.js → constants.js} +1 -1
- package/lib/esm/constants/constants.js.map +1 -0
- package/lib/esm/decorators/configuration.js +1 -1
- package/lib/esm/decorators/constant.js +2 -2
- package/lib/esm/decorators/constant.js.map +1 -1
- package/lib/esm/decorators/controller.js +1 -1
- package/lib/esm/decorators/controller.js.map +1 -1
- package/lib/esm/decorators/inject.js +25 -1
- package/lib/esm/decorators/inject.js.map +1 -1
- package/lib/esm/decorators/injectable.js +1 -3
- package/lib/esm/decorators/injectable.js.map +1 -1
- package/lib/esm/decorators/intercept.js +21 -13
- package/lib/esm/decorators/intercept.js.map +1 -1
- package/lib/esm/decorators/interceptor.js +2 -2
- package/lib/esm/decorators/lazyInject.js +1 -1
- package/lib/esm/decorators/module.js +4 -3
- package/lib/esm/decorators/module.js.map +1 -1
- package/lib/esm/decorators/opts.js +4 -4
- package/lib/esm/decorators/opts.js.map +1 -1
- package/lib/esm/decorators/overrideProvider.js +1 -1
- package/lib/esm/decorators/scope.js +1 -1
- package/lib/esm/decorators/service.js +1 -1
- package/lib/esm/decorators/useOpts.js +1 -1
- package/lib/esm/decorators/useOpts.js.map +1 -1
- package/lib/esm/decorators/value.js +2 -2
- package/lib/esm/decorators/value.js.map +1 -1
- package/lib/esm/domain/Container.js +3 -4
- package/lib/esm/domain/Container.js.map +1 -1
- package/lib/esm/domain/ContextLogger.js +41 -30
- package/lib/esm/domain/ContextLogger.js.map +1 -1
- package/lib/esm/domain/ControllerProvider.js +33 -0
- package/lib/esm/domain/ControllerProvider.js.map +1 -0
- package/lib/esm/domain/DIContext.js +88 -32
- package/lib/esm/domain/DIContext.js.map +1 -1
- package/lib/esm/domain/LocalsContainer.js +3 -46
- package/lib/esm/domain/LocalsContainer.js.map +1 -1
- package/lib/esm/domain/Provider.js +23 -4
- package/lib/esm/domain/Provider.js.map +1 -1
- package/lib/esm/errors/InjectionError.js +4 -3
- package/lib/esm/errors/InjectionError.js.map +1 -1
- package/lib/esm/errors/UndefinedTokenError.js +1 -1
- package/lib/esm/errors/UndefinedTokenError.js.map +1 -1
- package/lib/esm/index.js +60 -17
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/AlterRunInContext.js +2 -0
- package/lib/esm/interfaces/AlterRunInContext.js.map +1 -0
- package/lib/esm/interfaces/DIConfigurationOptions.js.map +1 -1
- package/lib/esm/interfaces/DILoggerOptions.js +2 -0
- package/lib/esm/interfaces/DILoggerOptions.js.map +1 -0
- package/lib/esm/interfaces/InjectableProperties.js.map +1 -1
- package/lib/esm/interfaces/InterceptorMethods.js.map +1 -1
- package/lib/esm/interfaces/ProviderOpts.js +2 -0
- package/lib/esm/interfaces/ProviderOpts.js.map +1 -0
- package/lib/esm/interfaces/RegistrySettings.js.map +1 -1
- package/lib/esm/interfaces/TokenProvider.js.map +1 -1
- 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 +9 -14
- package/lib/esm/registries/GlobalProviders.js.map +1 -1
- package/lib/esm/registries/ProviderRegistry.js +6 -5
- package/lib/esm/registries/ProviderRegistry.js.map +1 -1
- package/lib/esm/services/DIConfiguration.js +57 -44
- package/lib/esm/services/DIConfiguration.js.map +1 -1
- package/lib/esm/services/DILogger.js +2 -2
- package/lib/esm/services/DITest.js +16 -9
- package/lib/esm/services/DITest.js.map +1 -1
- package/lib/esm/services/InjectorService.js +116 -114
- package/lib/esm/services/InjectorService.js.map +1 -1
- package/lib/esm/utils/asyncHookContext.js +33 -0
- package/lib/esm/utils/asyncHookContext.js.map +1 -0
- package/lib/esm/utils/createContainer.js +2 -2
- package/lib/esm/utils/getConfiguration.js +12 -10
- package/lib/esm/utils/getConfiguration.js.map +1 -1
- package/lib/esm/utils/resolveControllers.js +42 -0
- package/lib/esm/utils/resolveControllers.js.map +1 -0
- package/lib/esm/utils/setLoggerConfiguration.js +7 -0
- package/lib/esm/utils/setLoggerConfiguration.js.map +1 -0
- package/lib/esm/utils/setLoggerFormat.js +29 -0
- package/lib/esm/utils/setLoggerFormat.js.map +1 -0
- package/lib/esm/utils/setLoggerLevel.js +1 -2
- package/lib/esm/utils/setLoggerLevel.js.map +1 -1
- package/lib/types/constants/{index.d.ts → constants.d.ts} +0 -0
- package/lib/types/decorators/controller.d.ts +2 -3
- package/lib/types/decorators/inject.d.ts +15 -0
- package/lib/types/decorators/injectable.d.ts +2 -4
- package/lib/types/decorators/intercept.d.ts +2 -2
- package/lib/types/decorators/module.d.ts +3 -2
- package/lib/types/domain/Container.d.ts +3 -3
- package/lib/types/domain/ContextLogger.d.ts +13 -18
- package/lib/types/domain/ControllerProvider.d.ts +17 -0
- package/lib/types/domain/DIContext.d.ts +23 -35
- package/lib/types/domain/LocalsContainer.d.ts +3 -22
- package/lib/types/domain/Provider.d.ts +5 -6
- package/lib/types/errors/InjectionError.d.ts +1 -1
- package/lib/types/index.d.ts +54 -11
- package/lib/types/interfaces/AlterRunInContext.d.ts +3 -0
- package/lib/types/interfaces/DIConfigurationOptions.d.ts +5 -2
- package/lib/types/interfaces/DILoggerOptions.d.ts +44 -0
- package/lib/types/interfaces/InjectableProperties.d.ts +2 -1
- package/lib/types/interfaces/InterceptorMethods.d.ts +1 -1
- package/lib/types/interfaces/{IProvider.d.ts → ProviderOpts.d.ts} +5 -4
- package/lib/types/interfaces/RegistrySettings.d.ts +1 -1
- package/lib/types/interfaces/TokenProvider.d.ts +1 -1
- package/lib/types/interfaces/TokenRoute.d.ts +5 -0
- package/lib/types/registries/GlobalProviders.d.ts +9 -6
- package/lib/types/registries/ProviderRegistry.d.ts +5 -4
- package/lib/types/services/DIConfiguration.d.ts +21 -12
- package/lib/types/services/DITest.d.ts +2 -0
- package/lib/types/services/InjectorService.d.ts +28 -34
- package/lib/types/utils/asyncHookContext.d.ts +14 -0
- package/lib/types/utils/getConfiguration.d.ts +1 -0
- package/lib/types/utils/resolveControllers.d.ts +12 -0
- package/lib/types/utils/setLoggerConfiguration.d.ts +2 -0
- package/lib/types/utils/setLoggerFormat.d.ts +6 -0
- package/lib/types/utils/setLoggerLevel.d.ts +1 -1
- package/package.json +29 -10
- package/readme.md +40 -43
- package/tsconfig.compile.esm.json +1 -0
- package/lib/cjs/constants/index.js.map +0 -1
- package/lib/cjs/decorators/index.js +0 -19
- package/lib/cjs/decorators/index.js.map +0 -1
- package/lib/cjs/domain/index.js +0 -12
- package/lib/cjs/domain/index.js.map +0 -1
- package/lib/cjs/interfaces/IProvider.js.map +0 -1
- package/lib/cjs/interfaces/index.js +0 -18
- package/lib/cjs/interfaces/index.js.map +0 -1
- package/lib/cjs/utils/data/Test1.js +0 -8
- package/lib/cjs/utils/data/Test1.js.map +0 -1
- package/lib/cjs/utils/data/Test2.js +0 -8
- package/lib/cjs/utils/data/Test2.js.map +0 -1
- package/lib/esm/constants/index.js.map +0 -1
- package/lib/esm/decorators/index.js +0 -16
- package/lib/esm/decorators/index.js.map +0 -1
- package/lib/esm/domain/index.js +0 -9
- package/lib/esm/domain/index.js.map +0 -1
- package/lib/esm/interfaces/IProvider.js +0 -2
- package/lib/esm/interfaces/IProvider.js.map +0 -1
- package/lib/esm/interfaces/index.js +0 -15
- package/lib/esm/interfaces/index.js.map +0 -1
- package/lib/esm/utils/data/Test1.js +0 -4
- package/lib/esm/utils/data/Test1.js.map +0 -1
- package/lib/esm/utils/data/Test2.js +0 -4
- package/lib/esm/utils/data/Test2.js.map +0 -1
- package/lib/types/decorators/index.d.ts +0 -15
- package/lib/types/domain/index.d.ts +0 -8
- package/lib/types/interfaces/index.d.ts +0 -14
- package/lib/types/utils/data/Test1.d.ts +0 -3
- package/lib/types/utils/data/Test2.d.ts +0 -3
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface DILoggerOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Enable debug mode. By default debug is false.
|
|
4
|
+
*/
|
|
5
|
+
debug?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Enable info mode. By default debug is false.
|
|
8
|
+
*/
|
|
9
|
+
level?: "debug" | "info" | "warn" | "error" | "off";
|
|
10
|
+
/**
|
|
11
|
+
* Enable log performance tracker and disable log server.
|
|
12
|
+
*/
|
|
13
|
+
perf?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* List of regexp to ignore log.
|
|
16
|
+
*/
|
|
17
|
+
ignoreUrlPatterns?: (string | RegExp)[];
|
|
18
|
+
/**
|
|
19
|
+
* The number of space characters to use as white space in JSON output. Default is 2 (0 in production).
|
|
20
|
+
*/
|
|
21
|
+
jsonIndentation?: number;
|
|
22
|
+
/**
|
|
23
|
+
* A function called for each incoming request to create a request id.
|
|
24
|
+
* @returns {number}
|
|
25
|
+
*/
|
|
26
|
+
reqIdBuilder?: (req: any) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Disable routes table displayed in the logger. By default debug is `false`.
|
|
29
|
+
*/
|
|
30
|
+
disableRoutesSummary?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Disable bootstrap log displayed in the logger. By default debug is `false`.
|
|
33
|
+
*/
|
|
34
|
+
disableBootstrapLog?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Specify log format. Example: `%[%d{[yyyy-MM-dd hh:mm:ss,SSS}] %p%] %m`. See [@tsed/logger configuration](https://tsedio.github.io/logger/).
|
|
37
|
+
*/
|
|
38
|
+
format?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Specify the log stack size for the context.logger. When the stack.length is reach, the logger is flushed during the request.
|
|
41
|
+
* Default size is set to 30.
|
|
42
|
+
*/
|
|
43
|
+
maxStackSize?: number;
|
|
44
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { InjectablePropertyType } from "../domain/InjectablePropertyType";
|
|
2
|
+
import type { LocalsContainer } from "../domain/LocalsContainer";
|
|
2
3
|
import type { TokenProvider } from "./TokenProvider";
|
|
3
4
|
import type { InjectorService } from "../services/InjectorService";
|
|
4
5
|
import type { InvokeOptions } from "./InvokeOptions";
|
|
@@ -9,7 +10,7 @@ export interface InjectablePropertyOptions extends InjectableProperty {
|
|
|
9
10
|
bindingType: InjectablePropertyType.METHOD | InjectablePropertyType.PROPERTY | InjectablePropertyType.INTERCEPTOR;
|
|
10
11
|
propertyType: string;
|
|
11
12
|
useType?: TokenProvider;
|
|
12
|
-
resolver: (injector: InjectorService, locals:
|
|
13
|
+
resolver: (injector: InjectorService, locals: LocalsContainer, options: Partial<InvokeOptions> & {
|
|
13
14
|
options: any;
|
|
14
15
|
}) => () => any;
|
|
15
16
|
options?: any;
|
|
@@ -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,6 +44,10 @@ 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
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
|
-
import type { Provider } from "../domain";
|
|
2
|
+
import type { Provider } from "../domain/Provider";
|
|
3
3
|
import type { InjectorService } from "../services/InjectorService";
|
|
4
4
|
import type { ResolvedInvokeOptions } from "./ResolvedInvokeOptions";
|
|
5
5
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Type } from "@tsed/core";
|
|
2
|
-
export declare type TokenProvider = string | symbol | Type | Function | any;
|
|
2
|
+
export declare type TokenProvider<T = any> = string | symbol | Type<T> | Function | any;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
|
+
import type { LocalsContainer } from "../domain/LocalsContainer";
|
|
2
3
|
import { Provider } from "../domain/Provider";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
4
|
+
import { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
5
|
+
import { RegistrySettings } from "../interfaces/RegistrySettings";
|
|
5
6
|
import { ResolvedInvokeOptions } from "../interfaces/ResolvedInvokeOptions";
|
|
7
|
+
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
8
|
+
import type { InjectorService } from "../services/InjectorService";
|
|
6
9
|
export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider> {
|
|
7
10
|
#private;
|
|
8
11
|
/**
|
|
@@ -28,7 +31,7 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
|
|
|
28
31
|
* @param target
|
|
29
32
|
* @param options
|
|
30
33
|
*/
|
|
31
|
-
merge(target: TokenProvider, options: Partial<
|
|
34
|
+
merge(target: TokenProvider, options: Partial<ProviderOpts>): Provider<any>;
|
|
32
35
|
/**
|
|
33
36
|
* The delete() method removes the specified element from a Map object.
|
|
34
37
|
* @param key Required. The key of the element to remove from the Map object.
|
|
@@ -36,17 +39,17 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
|
|
|
36
39
|
*/
|
|
37
40
|
delete(key: TokenProvider): boolean;
|
|
38
41
|
createRegistry(type: string, model: Type<Provider>, options?: Partial<RegistrySettings>): this;
|
|
39
|
-
onInvoke(provider: Provider, locals:
|
|
42
|
+
onInvoke(provider: Provider, locals: LocalsContainer, options: ResolvedInvokeOptions & {
|
|
40
43
|
injector: InjectorService;
|
|
41
44
|
}): void;
|
|
42
45
|
getRegistrySettings(target: string | TokenProvider): RegistrySettings;
|
|
43
|
-
createRegisterFn(type: string): (provider: any |
|
|
46
|
+
createRegisterFn(type: string): (provider: any | ProviderOpts, instance?: any) => void;
|
|
44
47
|
/**
|
|
45
48
|
*
|
|
46
49
|
* @param key
|
|
47
50
|
* @param options
|
|
48
51
|
*/
|
|
49
|
-
protected createIfNotExists(key: TokenProvider, options: Partial<
|
|
52
|
+
protected createIfNotExists(key: TokenProvider, options: Partial<ProviderOpts>): Provider;
|
|
50
53
|
}
|
|
51
54
|
/**
|
|
52
55
|
*
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Provider } from "../domain/Provider";
|
|
2
|
+
import type { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
2
3
|
/**
|
|
3
4
|
* Register a provider configuration.
|
|
4
|
-
* @param {
|
|
5
|
+
* @param {ProviderOpts<any>} provider
|
|
5
6
|
*/
|
|
6
|
-
export declare function registerProvider(provider: Partial<
|
|
7
|
+
export declare function registerProvider<Type = any>(provider: Partial<ProviderOpts<Type>>): Provider<any>;
|
|
7
8
|
/**
|
|
8
9
|
* Add a new value in the `ProviderRegistry`.
|
|
9
10
|
*
|
|
@@ -25,7 +26,7 @@ export declare function registerProvider(provider: Partial<IProvider>): void;
|
|
|
25
26
|
* }
|
|
26
27
|
* ```
|
|
27
28
|
*/
|
|
28
|
-
export declare const registerValue: (provider: any |
|
|
29
|
+
export declare const registerValue: (provider: any | ProviderOpts<any>, value?: any) => void;
|
|
29
30
|
/**
|
|
30
31
|
* Add a new controller in the `ProviderRegistry`. This controller will be built when `InjectorService` will be loaded.
|
|
31
32
|
*
|
|
@@ -1,20 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import { Env } from "@tsed/core";
|
|
2
|
+
import type { ProviderScope } from "../domain/ProviderScope";
|
|
3
|
+
import type { DILoggerOptions } from "../interfaces/DILoggerOptions";
|
|
4
|
+
import type { DIResolver } from "../interfaces/DIResolver";
|
|
5
|
+
import type { TokenProvider } from "../interfaces/TokenProvider";
|
|
6
|
+
import type { TokenRoute } from "../interfaces/TokenRoute";
|
|
3
7
|
export declare class DIConfiguration {
|
|
4
8
|
readonly default: Map<string, any>;
|
|
5
9
|
protected map: Map<string, any>;
|
|
6
|
-
[key: string]: any;
|
|
7
10
|
constructor(initialProps?: {});
|
|
8
|
-
get
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
set
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
get version(): string;
|
|
12
|
+
set version(v: string);
|
|
13
|
+
get rootDir(): string;
|
|
14
|
+
set rootDir(value: string);
|
|
15
|
+
get env(): Env;
|
|
16
|
+
set env(value: Env);
|
|
17
|
+
get scopes(): Record<string, ProviderScope>;
|
|
18
|
+
set scopes(value: Record<string, ProviderScope>);
|
|
14
19
|
get resolvers(): DIResolver[];
|
|
15
20
|
set resolvers(resolvers: DIResolver[]);
|
|
16
21
|
get imports(): TokenProvider[];
|
|
17
22
|
set imports(imports: TokenProvider[]);
|
|
23
|
+
get routes(): TokenRoute[];
|
|
24
|
+
set routes(routes: TokenRoute[]);
|
|
25
|
+
get logger(): Partial<DILoggerOptions>;
|
|
26
|
+
set logger(value: Partial<DILoggerOptions>);
|
|
27
|
+
get debug(): boolean;
|
|
28
|
+
set debug(debug: boolean);
|
|
18
29
|
/**
|
|
19
30
|
*
|
|
20
31
|
* @param callbackfn
|
|
@@ -35,13 +46,11 @@ export declare class DIConfiguration {
|
|
|
35
46
|
* @returns {undefined|any}
|
|
36
47
|
*/
|
|
37
48
|
get<T = any>(propertyKey: string, defaultValue?: T): T;
|
|
38
|
-
getRaw(propertyKey: string, defaultValue?: any): any;
|
|
39
|
-
merge(obj: Partial<TsED.Configuration>): void;
|
|
49
|
+
protected getRaw(propertyKey: string, defaultValue?: any): any;
|
|
40
50
|
/**
|
|
41
51
|
*
|
|
42
52
|
* @param value
|
|
43
53
|
* @returns {any}
|
|
44
54
|
*/
|
|
45
55
|
resolve(value: any): any;
|
|
46
|
-
build(): void;
|
|
47
56
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
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;
|
|
@@ -37,5 +38,6 @@ export declare class DITest {
|
|
|
37
38
|
* @param options
|
|
38
39
|
*/
|
|
39
40
|
static get<T = any>(target: TokenProvider, options?: any): T;
|
|
41
|
+
static createDIContext(): DIContext;
|
|
40
42
|
protected static configure(settings?: Partial<TsED.Configuration>): Partial<TsED.Configuration>;
|
|
41
43
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
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 {
|
|
4
|
+
import { ProviderScope } from "../domain/ProviderScope";
|
|
5
|
+
import { DILogger } from "../interfaces/DILogger";
|
|
6
|
+
import { InjectablePropertyOptions, InjectablePropertyValue } from "../interfaces/InjectableProperties";
|
|
7
|
+
import { InvokeOptions } from "../interfaces/InvokeOptions";
|
|
8
|
+
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
6
9
|
import { DIConfiguration } from "./DIConfiguration";
|
|
7
10
|
/**
|
|
8
11
|
* This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.
|
|
@@ -17,7 +20,7 @@ import { DIConfiguration } from "./DIConfiguration";
|
|
|
17
20
|
* import MyService2 from "./services/service2";
|
|
18
21
|
* import MyService3 from "./services/service3";
|
|
19
22
|
*
|
|
20
|
-
* // When all services
|
|
23
|
+
* // When all services are imported, you can load InjectorService.
|
|
21
24
|
* const injector = new InjectorService()
|
|
22
25
|
*
|
|
23
26
|
* await injector.load();
|
|
@@ -27,28 +30,17 @@ import { DIConfiguration } from "./DIConfiguration";
|
|
|
27
30
|
*/
|
|
28
31
|
export declare class InjectorService extends Container {
|
|
29
32
|
#private;
|
|
30
|
-
settings:
|
|
33
|
+
settings: DIConfiguration;
|
|
31
34
|
logger: DILogger;
|
|
32
35
|
private resolvedConfiguration;
|
|
33
36
|
constructor();
|
|
34
|
-
get resolvers(): import("
|
|
35
|
-
get scopes():
|
|
36
|
-
[key: string]: ProviderScope;
|
|
37
|
-
} & {
|
|
38
|
-
[key: string]: ProviderScope;
|
|
39
|
-
};
|
|
37
|
+
get resolvers(): import("..").DIResolver[];
|
|
38
|
+
get scopes(): Record<string, ProviderScope>;
|
|
40
39
|
/**
|
|
41
40
|
* Retrieve default scope for a given provider.
|
|
42
41
|
* @param provider
|
|
43
42
|
*/
|
|
44
43
|
scopeOf(provider: Provider): ProviderScope;
|
|
45
|
-
/**
|
|
46
|
-
* Clone a provider from GlobalProviders and the given token. forkProvider method build automatically the provider if the instance parameter ins't given.
|
|
47
|
-
* @param token
|
|
48
|
-
* @param settings
|
|
49
|
-
* @deprecated
|
|
50
|
-
*/
|
|
51
|
-
forkProvider(token: TokenProvider, settings?: Partial<IProvider<any>>): Provider;
|
|
52
44
|
/**
|
|
53
45
|
* Return a list of instance build by the injector.
|
|
54
46
|
*/
|
|
@@ -73,7 +65,12 @@ export declare class InjectorService extends Container {
|
|
|
73
65
|
* @param options
|
|
74
66
|
* @returns {boolean}
|
|
75
67
|
*/
|
|
76
|
-
get<T = any>(token: TokenProvider
|
|
68
|
+
get<T = any>(token: TokenProvider<T>, options?: any): T | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Return all instance of the same provider type
|
|
71
|
+
* @param type
|
|
72
|
+
*/
|
|
73
|
+
getAll(type: string): any[];
|
|
77
74
|
/**
|
|
78
75
|
* The has() method returns a boolean indicating whether an element with the specified key exists or not.
|
|
79
76
|
* @returns {boolean}
|
|
@@ -101,25 +98,29 @@ export declare class InjectorService extends Container {
|
|
|
101
98
|
* @param options
|
|
102
99
|
* @returns {T} The class constructed.
|
|
103
100
|
*/
|
|
104
|
-
invoke<T>(token: TokenProvider, locals?:
|
|
101
|
+
invoke<T = any>(token: TokenProvider, locals?: LocalsContainer, options?: Partial<InvokeOptions<T>>): T;
|
|
105
102
|
/**
|
|
106
103
|
* Build only providers which are asynchronous.
|
|
107
104
|
*/
|
|
108
|
-
loadAsync(
|
|
109
|
-
loadSync(
|
|
105
|
+
loadAsync(): Promise<void>;
|
|
106
|
+
loadSync(): void;
|
|
110
107
|
/**
|
|
111
108
|
* Boostrap injector from container and resolve configuration.
|
|
112
109
|
*
|
|
113
110
|
* @param container
|
|
114
111
|
*/
|
|
115
112
|
bootstrap(container?: Container): this;
|
|
113
|
+
/**
|
|
114
|
+
* Load injector from a given module
|
|
115
|
+
* @param rootModule
|
|
116
|
+
*/
|
|
117
|
+
loadModule(rootModule: TokenProvider): Promise<void>;
|
|
116
118
|
/**
|
|
117
119
|
* Build all providers from given container (or GlobalProviders) and emit `$onInit` event.
|
|
118
120
|
*
|
|
119
121
|
* @param container
|
|
120
|
-
* @param rootModule
|
|
121
122
|
*/
|
|
122
|
-
load(container?: Container
|
|
123
|
+
load(container?: Container): Promise<void>;
|
|
123
124
|
/**
|
|
124
125
|
* Load all configurations registered on providers
|
|
125
126
|
*/
|
|
@@ -130,9 +131,8 @@ export declare class InjectorService extends Container {
|
|
|
130
131
|
* @param locals
|
|
131
132
|
* @param options
|
|
132
133
|
*/
|
|
133
|
-
bindInjectableProperties(instance: any, locals:
|
|
134
|
+
bindInjectableProperties(instance: any, locals: LocalsContainer, options: Partial<InvokeOptions>): void;
|
|
134
135
|
/**
|
|
135
|
-
*
|
|
136
136
|
* @param instance
|
|
137
137
|
* @param {string} propertyKey
|
|
138
138
|
*/
|
|
@@ -148,7 +148,7 @@ export declare class InjectorService extends Container {
|
|
|
148
148
|
* @param locals
|
|
149
149
|
* @param invokeOptions
|
|
150
150
|
*/
|
|
151
|
-
bindProperty(instance: any, { propertyKey, resolver, options }: InjectablePropertyOptions, locals:
|
|
151
|
+
bindProperty(instance: any, { propertyKey, resolver, options }: InjectablePropertyOptions, locals: LocalsContainer, invokeOptions: Partial<InvokeOptions>): void;
|
|
152
152
|
/**
|
|
153
153
|
*
|
|
154
154
|
* @param instance
|
|
@@ -171,18 +171,11 @@ export declare class InjectorService extends Container {
|
|
|
171
171
|
* @param options
|
|
172
172
|
*/
|
|
173
173
|
bindInterceptor(instance: any, { propertyKey, useType, options }: InjectablePropertyOptions): void;
|
|
174
|
-
/**
|
|
175
|
-
* Allow handler hack for AsyncHookContext plugin.
|
|
176
|
-
* @param ctx
|
|
177
|
-
* @param cb
|
|
178
|
-
* @protected
|
|
179
|
-
*/
|
|
180
|
-
runInContext(ctx: DIContext, cb: any): any;
|
|
181
174
|
lazyInvoke<T = any>(token: TokenProvider): Promise<any>;
|
|
182
175
|
/**
|
|
183
176
|
* Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
|
|
184
177
|
* @param eventName The event name to emit at all services.
|
|
185
|
-
* @param args List of the parameters to give to each
|
|
178
|
+
* @param args List of the parameters to give to each service.
|
|
186
179
|
* @returns {Promise<any[]>} A list of promises.
|
|
187
180
|
*/
|
|
188
181
|
emit(eventName: string, ...args: any[]): Promise<void>;
|
|
@@ -226,4 +219,5 @@ export declare class InjectorService extends Container {
|
|
|
226
219
|
* @param options
|
|
227
220
|
*/
|
|
228
221
|
private mapInvokeOptions;
|
|
222
|
+
private registerHooks;
|
|
229
223
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
+
import type { DIContext } from "../domain/DIContext";
|
|
4
|
+
import type { InjectorService } from "../services/InjectorService";
|
|
5
|
+
export declare function getAsyncStore(): AsyncLocalStorage<{
|
|
6
|
+
current: DIContext | undefined;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function useContextRef(): {
|
|
9
|
+
current: DIContext | undefined;
|
|
10
|
+
} | undefined;
|
|
11
|
+
export declare function getContext<Context = DIContext>(): Context | undefined;
|
|
12
|
+
export declare function runInContext(ctx: DIContext | undefined, cb: any, injector?: InjectorService): Promise<any>;
|
|
13
|
+
export declare function setContext(ctx: DIContext): void;
|
|
14
|
+
export declare function bindContext(cb: any): any;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
2
|
+
import { TokenRoute } from "../interfaces/TokenRoute";
|
|
3
|
+
export declare function getTokens(config: any): {
|
|
4
|
+
route?: string;
|
|
5
|
+
token: TokenProvider;
|
|
6
|
+
}[];
|
|
7
|
+
/**
|
|
8
|
+
* Return controllers and is base route according to his configuration in module configuration.
|
|
9
|
+
*
|
|
10
|
+
* @param settings
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveControllers(settings: Partial<TsED.Configuration>): TokenRoute[];
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/di",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.20",
|
|
4
4
|
"description": "DI module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/cjs/index.js",
|
|
8
|
+
"module": "./lib/esm/index.js",
|
|
8
9
|
"typings": "./lib/types/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
11
|
"types": "./lib/types/index.d.ts",
|
|
@@ -13,26 +14,44 @@
|
|
|
13
14
|
"default": "./lib/esm/index.js"
|
|
14
15
|
},
|
|
15
16
|
"scripts": {
|
|
16
|
-
"build": "yarn run build:esm && yarn run build:cjs",
|
|
17
|
+
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
17
18
|
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
18
|
-
"build:esm": "tsc --build tsconfig.compile.esm.json"
|
|
19
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
20
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\"",
|
|
21
|
+
"test": "cross-env NODE_ENV=test yarn jest --max-workers=2"
|
|
19
22
|
},
|
|
20
23
|
"dependencies": {
|
|
21
|
-
"
|
|
22
|
-
"@tsed/schema": "7.0.0-beta.2",
|
|
23
|
-
"tslib": "2.2.0"
|
|
24
|
+
"tslib": "2.4.0"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"@tsed/
|
|
27
|
+
"@tsed/core": "7.0.0-beta.20",
|
|
28
|
+
"@tsed/logger": ">=6.2.0",
|
|
29
|
+
"@tsed/schema": "7.0.0-beta.20"
|
|
27
30
|
},
|
|
28
31
|
"peerDependencies": {
|
|
29
|
-
"@tsed/
|
|
32
|
+
"@tsed/core": "^7.0.0-beta.20",
|
|
33
|
+
"@tsed/logger": ">=6.2.0",
|
|
34
|
+
"@tsed/schema": "^7.0.0-beta.20"
|
|
35
|
+
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"@tsed/core": {
|
|
38
|
+
"optional": false
|
|
39
|
+
},
|
|
40
|
+
"@tsed/logger": {
|
|
41
|
+
"optional": false
|
|
42
|
+
},
|
|
43
|
+
"@tsed/schema": {
|
|
44
|
+
"optional": false
|
|
45
|
+
}
|
|
30
46
|
},
|
|
31
47
|
"repository": "https://github.com/tsedio/tsed",
|
|
32
48
|
"bugs": {
|
|
33
49
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
34
50
|
},
|
|
35
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
51
|
+
"homepage": "https://github.com/tsedio/tsed/tree/beta/packages/di",
|
|
36
52
|
"author": "Romain Lenzotti",
|
|
37
|
-
"license": "MIT"
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"tag": "beta"
|
|
56
|
+
}
|
|
38
57
|
}
|