@tsed/di 7.0.0-beta.9 → 7.0.0-rc.1
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/decorators/controller.js.map +1 -1
- package/lib/cjs/decorators/inject.js +2 -2
- package/lib/cjs/decorators/inject.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 +8 -1
- 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/TokenProvider.js.map +1 -1
- package/lib/cjs/interfaces/TokenRoute.js +3 -0
- package/lib/cjs/interfaces/TokenRoute.js.map +1 -0
- package/lib/cjs/registries/GlobalProviders.js +7 -12
- 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/DIConfiguration.js +56 -43
- package/lib/cjs/services/DIConfiguration.js.map +1 -1
- package/lib/cjs/services/DITest.js +5 -6
- package/lib/cjs/services/DITest.js.map +1 -1
- package/lib/cjs/services/InjectorService.js +94 -92
- 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/decorators/controller.js.map +1 -1
- package/lib/esm/decorators/inject.js +1 -1
- package/lib/esm/decorators/inject.js.map +1 -1
- package/lib/esm/domain/Container.js +1 -2
- 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 +86 -30
- 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 +21 -2
- package/lib/esm/domain/Provider.js.map +1 -1
- package/lib/esm/errors/InjectionError.js +3 -2
- 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 +8 -1
- 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/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/registries/GlobalProviders.js +7 -12
- 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/DIConfiguration.js +57 -44
- package/lib/esm/services/DIConfiguration.js.map +1 -1
- package/lib/esm/services/DITest.js +5 -6
- package/lib/esm/services/DITest.js.map +1 -1
- package/lib/esm/services/InjectorService.js +96 -94
- 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/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/decorators/controller.d.ts +0 -1
- 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 -29
- package/lib/types/domain/LocalsContainer.d.ts +3 -22
- package/lib/types/domain/Provider.d.ts +2 -1
- package/lib/types/index.d.ts +8 -1
- 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/TokenProvider.d.ts +1 -1
- package/lib/types/interfaces/TokenRoute.d.ts +5 -0
- package/lib/types/registries/GlobalProviders.d.ts +6 -5
- package/lib/types/registries/ProviderRegistry.d.ts +2 -1
- package/lib/types/services/DIConfiguration.d.ts +19 -11
- package/lib/types/services/InjectorService.d.ts +20 -28
- 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 +15 -11
- package/readme.md +3 -2
- package/lib/cjs/utils/runInContext.js +0 -20
- package/lib/cjs/utils/runInContext.js.map +0 -1
- package/lib/esm/utils/runInContext.js +0 -14
- package/lib/esm/utils/runInContext.js.map +0 -1
- package/lib/types/utils/runInContext.d.ts +0 -6
|
@@ -5,7 +5,7 @@ declare global {
|
|
|
5
5
|
namespace TsED {
|
|
6
6
|
interface Context {
|
|
7
7
|
}
|
|
8
|
-
interface Configuration {
|
|
8
|
+
interface Configuration extends Record<string, any> {
|
|
9
9
|
scopes: {
|
|
10
10
|
[key: string]: ProviderScope;
|
|
11
11
|
};
|
|
@@ -17,7 +17,10 @@ declare global {
|
|
|
17
17
|
* Define dependencies to build the provider
|
|
18
18
|
*/
|
|
19
19
|
imports: TokenProvider[];
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Mount controllers
|
|
22
|
+
*/
|
|
23
|
+
mount: Record<string, TokenProvider[]>;
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
}
|
|
@@ -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;
|
|
@@ -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,10 +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 { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
5
|
+
import { RegistrySettings } from "../interfaces/RegistrySettings";
|
|
4
6
|
import { ResolvedInvokeOptions } from "../interfaces/ResolvedInvokeOptions";
|
|
5
7
|
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
6
|
-
import {
|
|
7
|
-
import { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
8
|
+
import type { InjectorService } from "../services/InjectorService";
|
|
8
9
|
export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider> {
|
|
9
10
|
#private;
|
|
10
11
|
/**
|
|
@@ -30,7 +31,7 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
|
|
|
30
31
|
* @param target
|
|
31
32
|
* @param options
|
|
32
33
|
*/
|
|
33
|
-
merge(target: TokenProvider, options: Partial<ProviderOpts>):
|
|
34
|
+
merge(target: TokenProvider, options: Partial<ProviderOpts>): Provider<any>;
|
|
34
35
|
/**
|
|
35
36
|
* The delete() method removes the specified element from a Map object.
|
|
36
37
|
* @param key Required. The key of the element to remove from the Map object.
|
|
@@ -38,7 +39,7 @@ export declare class GlobalProviderRegistry extends Map<TokenProvider, Provider>
|
|
|
38
39
|
*/
|
|
39
40
|
delete(key: TokenProvider): boolean;
|
|
40
41
|
createRegistry(type: string, model: Type<Provider>, options?: Partial<RegistrySettings>): this;
|
|
41
|
-
onInvoke(provider: Provider, locals:
|
|
42
|
+
onInvoke(provider: Provider, locals: LocalsContainer, options: ResolvedInvokeOptions & {
|
|
42
43
|
injector: InjectorService;
|
|
43
44
|
}): void;
|
|
44
45
|
getRegistrySettings(target: string | TokenProvider): RegistrySettings;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { Provider } from "../domain/Provider";
|
|
1
2
|
import type { ProviderOpts } from "../interfaces/ProviderOpts";
|
|
2
3
|
/**
|
|
3
4
|
* Register a provider configuration.
|
|
4
5
|
* @param {ProviderOpts<any>} provider
|
|
5
6
|
*/
|
|
6
|
-
export declare function registerProvider<Type = any>(provider: Partial<ProviderOpts<Type>>):
|
|
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
|
*
|
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Env } from "@tsed/core";
|
|
2
|
+
import type { ProviderScope } from "../domain/ProviderScope";
|
|
3
|
+
import type { DILoggerOptions } from "../interfaces/DILoggerOptions";
|
|
2
4
|
import type { DIResolver } from "../interfaces/DIResolver";
|
|
3
5
|
import type { TokenProvider } from "../interfaces/TokenProvider";
|
|
6
|
+
import type { TokenRoute } from "../interfaces/TokenRoute";
|
|
4
7
|
export declare class DIConfiguration {
|
|
5
8
|
readonly default: Map<string, any>;
|
|
6
9
|
protected map: Map<string, any>;
|
|
7
|
-
[key: string]: any;
|
|
8
10
|
constructor(initialProps?: {});
|
|
9
|
-
get
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
set
|
|
13
|
-
|
|
14
|
-
|
|
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>);
|
|
15
19
|
get resolvers(): DIResolver[];
|
|
16
20
|
set resolvers(resolvers: DIResolver[]);
|
|
17
21
|
get imports(): TokenProvider[];
|
|
18
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);
|
|
19
29
|
/**
|
|
20
30
|
*
|
|
21
31
|
* @param callbackfn
|
|
@@ -36,13 +46,11 @@ export declare class DIConfiguration {
|
|
|
36
46
|
* @returns {undefined|any}
|
|
37
47
|
*/
|
|
38
48
|
get<T = any>(propertyKey: string, defaultValue?: T): T;
|
|
39
|
-
getRaw(propertyKey: string, defaultValue?: any): any;
|
|
40
|
-
merge(obj: Partial<TsED.Configuration>): void;
|
|
49
|
+
protected getRaw(propertyKey: string, defaultValue?: any): any;
|
|
41
50
|
/**
|
|
42
51
|
*
|
|
43
52
|
* @param value
|
|
44
53
|
* @returns {any}
|
|
45
54
|
*/
|
|
46
55
|
resolve(value: any): any;
|
|
47
|
-
build(): void;
|
|
48
56
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { Container } from "../domain/Container";
|
|
2
2
|
import { LocalsContainer } from "../domain/LocalsContainer";
|
|
3
3
|
import { Provider } from "../domain/Provider";
|
|
4
|
-
import { DIConfiguration } from "./DIConfiguration";
|
|
5
4
|
import { ProviderScope } from "../domain/ProviderScope";
|
|
6
5
|
import { DILogger } from "../interfaces/DILogger";
|
|
7
|
-
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
8
|
-
import { InvokeOptions } from "../interfaces/InvokeOptions";
|
|
9
6
|
import { InjectablePropertyOptions, InjectablePropertyValue } from "../interfaces/InjectableProperties";
|
|
10
|
-
import {
|
|
7
|
+
import { InvokeOptions } from "../interfaces/InvokeOptions";
|
|
8
|
+
import { TokenProvider } from "../interfaces/TokenProvider";
|
|
9
|
+
import { DIConfiguration } from "./DIConfiguration";
|
|
11
10
|
/**
|
|
12
11
|
* This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.
|
|
13
12
|
*
|
|
@@ -21,7 +20,7 @@ import { DIContext } from "../domain/DIContext";
|
|
|
21
20
|
* import MyService2 from "./services/service2";
|
|
22
21
|
* import MyService3 from "./services/service3";
|
|
23
22
|
*
|
|
24
|
-
* // When all services
|
|
23
|
+
* // When all services are imported, you can load InjectorService.
|
|
25
24
|
* const injector = new InjectorService()
|
|
26
25
|
*
|
|
27
26
|
* await injector.load();
|
|
@@ -31,16 +30,12 @@ import { DIContext } from "../domain/DIContext";
|
|
|
31
30
|
*/
|
|
32
31
|
export declare class InjectorService extends Container {
|
|
33
32
|
#private;
|
|
34
|
-
settings:
|
|
33
|
+
settings: DIConfiguration;
|
|
35
34
|
logger: DILogger;
|
|
36
35
|
private resolvedConfiguration;
|
|
37
36
|
constructor();
|
|
38
37
|
get resolvers(): import("..").DIResolver[];
|
|
39
|
-
get scopes():
|
|
40
|
-
[key: string]: ProviderScope;
|
|
41
|
-
} & {
|
|
42
|
-
[key: string]: ProviderScope;
|
|
43
|
-
};
|
|
38
|
+
get scopes(): Record<string, ProviderScope>;
|
|
44
39
|
/**
|
|
45
40
|
* Retrieve default scope for a given provider.
|
|
46
41
|
* @param provider
|
|
@@ -70,7 +65,7 @@ export declare class InjectorService extends Container {
|
|
|
70
65
|
* @param options
|
|
71
66
|
* @returns {boolean}
|
|
72
67
|
*/
|
|
73
|
-
get<T = any>(token: TokenProvider
|
|
68
|
+
get<T = any>(token: TokenProvider<T>, options?: any): T | undefined;
|
|
74
69
|
/**
|
|
75
70
|
* Return all instance of the same provider type
|
|
76
71
|
* @param type
|
|
@@ -103,25 +98,29 @@ export declare class InjectorService extends Container {
|
|
|
103
98
|
* @param options
|
|
104
99
|
* @returns {T} The class constructed.
|
|
105
100
|
*/
|
|
106
|
-
invoke<T>(token: TokenProvider, locals?:
|
|
101
|
+
invoke<T = any>(token: TokenProvider, locals?: LocalsContainer, options?: Partial<InvokeOptions<T>>): T;
|
|
107
102
|
/**
|
|
108
103
|
* Build only providers which are asynchronous.
|
|
109
104
|
*/
|
|
110
|
-
loadAsync(
|
|
111
|
-
loadSync(
|
|
105
|
+
loadAsync(): Promise<void>;
|
|
106
|
+
loadSync(): void;
|
|
112
107
|
/**
|
|
113
108
|
* Boostrap injector from container and resolve configuration.
|
|
114
109
|
*
|
|
115
110
|
* @param container
|
|
116
111
|
*/
|
|
117
112
|
bootstrap(container?: Container): this;
|
|
113
|
+
/**
|
|
114
|
+
* Load injector from a given module
|
|
115
|
+
* @param rootModule
|
|
116
|
+
*/
|
|
117
|
+
loadModule(rootModule: TokenProvider): Promise<void>;
|
|
118
118
|
/**
|
|
119
119
|
* Build all providers from given container (or GlobalProviders) and emit `$onInit` event.
|
|
120
120
|
*
|
|
121
121
|
* @param container
|
|
122
|
-
* @param rootModule
|
|
123
122
|
*/
|
|
124
|
-
load(container?: Container
|
|
123
|
+
load(container?: Container): Promise<void>;
|
|
125
124
|
/**
|
|
126
125
|
* Load all configurations registered on providers
|
|
127
126
|
*/
|
|
@@ -132,9 +131,8 @@ export declare class InjectorService extends Container {
|
|
|
132
131
|
* @param locals
|
|
133
132
|
* @param options
|
|
134
133
|
*/
|
|
135
|
-
bindInjectableProperties(instance: any, locals:
|
|
134
|
+
bindInjectableProperties(instance: any, locals: LocalsContainer, options: Partial<InvokeOptions>): void;
|
|
136
135
|
/**
|
|
137
|
-
*
|
|
138
136
|
* @param instance
|
|
139
137
|
* @param {string} propertyKey
|
|
140
138
|
*/
|
|
@@ -150,7 +148,7 @@ export declare class InjectorService extends Container {
|
|
|
150
148
|
* @param locals
|
|
151
149
|
* @param invokeOptions
|
|
152
150
|
*/
|
|
153
|
-
bindProperty(instance: any, { propertyKey, resolver, options }: InjectablePropertyOptions, locals:
|
|
151
|
+
bindProperty(instance: any, { propertyKey, resolver, options }: InjectablePropertyOptions, locals: LocalsContainer, invokeOptions: Partial<InvokeOptions>): void;
|
|
154
152
|
/**
|
|
155
153
|
*
|
|
156
154
|
* @param instance
|
|
@@ -173,18 +171,11 @@ export declare class InjectorService extends Container {
|
|
|
173
171
|
* @param options
|
|
174
172
|
*/
|
|
175
173
|
bindInterceptor(instance: any, { propertyKey, useType, options }: InjectablePropertyOptions): void;
|
|
176
|
-
/**
|
|
177
|
-
* Allow handler hack for AsyncHookContext plugin.
|
|
178
|
-
* @param ctx
|
|
179
|
-
* @param cb
|
|
180
|
-
* @protected
|
|
181
|
-
*/
|
|
182
|
-
runInContext(ctx: DIContext, cb: any): any;
|
|
183
174
|
lazyInvoke<T = any>(token: TokenProvider): Promise<any>;
|
|
184
175
|
/**
|
|
185
176
|
* Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
|
|
186
177
|
* @param eventName The event name to emit at all services.
|
|
187
|
-
* @param args List of the parameters to give to each
|
|
178
|
+
* @param args List of the parameters to give to each service.
|
|
188
179
|
* @returns {Promise<any[]>} A list of promises.
|
|
189
180
|
*/
|
|
190
181
|
emit(eventName: string, ...args: any[]): Promise<void>;
|
|
@@ -228,4 +219,5 @@ export declare class InjectorService extends Container {
|
|
|
228
219
|
* @param options
|
|
229
220
|
*/
|
|
230
221
|
private mapInvokeOptions;
|
|
222
|
+
private registerHooks;
|
|
231
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/di",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-rc.1",
|
|
4
4
|
"description": "DI module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -17,20 +17,21 @@
|
|
|
17
17
|
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
18
18
|
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
19
19
|
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
20
|
-
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\""
|
|
20
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\"",
|
|
21
|
+
"test": "cross-env NODE_ENV=test yarn jest --max-workers=2"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"tslib": "2.
|
|
24
|
+
"tslib": "2.4.0"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"@tsed/core": "7.0.0-
|
|
27
|
-
"@tsed/logger": ">=6.
|
|
28
|
-
"@tsed/schema": "7.0.0-
|
|
27
|
+
"@tsed/core": "7.0.0-rc.1",
|
|
28
|
+
"@tsed/logger": ">=6.2.0",
|
|
29
|
+
"@tsed/schema": "7.0.0-rc.1"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
|
31
|
-
"@tsed/core": "^7.0.0-
|
|
32
|
-
"@tsed/logger": ">=6.
|
|
33
|
-
"@tsed/schema": "^7.0.0-
|
|
32
|
+
"@tsed/core": "^7.0.0-rc.1",
|
|
33
|
+
"@tsed/logger": ">=6.2.0",
|
|
34
|
+
"@tsed/schema": "^7.0.0-rc.1"
|
|
34
35
|
},
|
|
35
36
|
"peerDependenciesMeta": {
|
|
36
37
|
"@tsed/core": {
|
|
@@ -47,7 +48,10 @@
|
|
|
47
48
|
"bugs": {
|
|
48
49
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
49
50
|
},
|
|
50
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
51
|
+
"homepage": "https://github.com/tsedio/tsed/tree/rc/packages/di",
|
|
51
52
|
"author": "Romain Lenzotti",
|
|
52
|
-
"license": "MIT"
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"tag": "rc"
|
|
56
|
+
}
|
|
53
57
|
}
|
package/readme.md
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
[](https://badge.fury.io/js/%40tsed%2Fcommon)
|
|
12
12
|
[](https://github.com/semantic-release/semantic-release)
|
|
13
13
|
[](https://github.com/prettier/prettier)
|
|
14
|
-
[](https://github.com/sponsors/romakita)
|
|
15
|
+
[](https://opencollective.com/tsed)
|
|
15
16
|
|
|
16
17
|
</div>
|
|
17
18
|
|
|
@@ -168,7 +169,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
|
|
168
169
|
|
|
169
170
|
The MIT License (MIT)
|
|
170
171
|
|
|
171
|
-
Copyright (c) 2016 -
|
|
172
|
+
Copyright (c) 2016 - 2022 Romain Lenzotti
|
|
172
173
|
|
|
173
174
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
174
175
|
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runInContext = exports.getContext = exports.getAsyncStore = void 0;
|
|
4
|
-
const async_hooks_1 = require("async_hooks");
|
|
5
|
-
let store;
|
|
6
|
-
function getAsyncStore() {
|
|
7
|
-
store = store || new async_hooks_1.AsyncLocalStorage();
|
|
8
|
-
return store;
|
|
9
|
-
}
|
|
10
|
-
exports.getAsyncStore = getAsyncStore;
|
|
11
|
-
function getContext() {
|
|
12
|
-
return store === null || store === void 0 ? void 0 : store.getStore();
|
|
13
|
-
}
|
|
14
|
-
exports.getContext = getContext;
|
|
15
|
-
function runInContext(ctx, cb) {
|
|
16
|
-
// istanbul ignore else
|
|
17
|
-
return async_hooks_1.AsyncLocalStorage ? getAsyncStore().run(ctx, cb) : cb();
|
|
18
|
-
}
|
|
19
|
-
exports.runInContext = runInContext;
|
|
20
|
-
//# sourceMappingURL=runInContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runInContext.js","sourceRoot":"","sources":["../../../src/utils/runInContext.ts"],"names":[],"mappings":";;;AAAA,6CAA8C;AAG9C,IAAI,KAAmC,CAAC;AAExC,SAAgB,aAAa;IAC3B,KAAK,GAAG,KAAK,IAAI,IAAI,+BAAiB,EAAE,CAAC;IACzC,OAAO,KAAK,CAAC;AACf,CAAC;AAHD,sCAGC;AAED,SAAgB,UAAU;IACxB,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,EAAE,CAAC;AAC3B,CAAC;AAFD,gCAEC;AAED,SAAgB,YAAY,CAAC,GAAc,EAAE,EAAO;IAClD,uBAAuB;IACvB,OAAO,+BAAiB,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACjE,CAAC;AAHD,oCAGC","sourcesContent":["import {AsyncLocalStorage} from \"async_hooks\";\nimport {DIContext} from \"../domain/DIContext\";\n\nlet store: AsyncLocalStorage<DIContext>;\n\nexport function getAsyncStore() {\n store = store || new AsyncLocalStorage();\n return store;\n}\n\nexport function getContext() {\n return store?.getStore();\n}\n\nexport function runInContext(ctx: DIContext, cb: any) {\n // istanbul ignore else\n return AsyncLocalStorage ? getAsyncStore().run(ctx, cb) : cb();\n}\n"]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
2
|
-
let store;
|
|
3
|
-
export function getAsyncStore() {
|
|
4
|
-
store = store || new AsyncLocalStorage();
|
|
5
|
-
return store;
|
|
6
|
-
}
|
|
7
|
-
export function getContext() {
|
|
8
|
-
return store === null || store === void 0 ? void 0 : store.getStore();
|
|
9
|
-
}
|
|
10
|
-
export function runInContext(ctx, cb) {
|
|
11
|
-
// istanbul ignore else
|
|
12
|
-
return AsyncLocalStorage ? getAsyncStore().run(ctx, cb) : cb();
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=runInContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runInContext.js","sourceRoot":"","sources":["../../../src/utils/runInContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAG9C,IAAI,KAAmC,CAAC;AAExC,MAAM,UAAU,aAAa;IAC3B,KAAK,GAAG,KAAK,IAAI,IAAI,iBAAiB,EAAE,CAAC;IACzC,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAc,EAAE,EAAO;IAClD,uBAAuB;IACvB,OAAO,iBAAiB,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACjE,CAAC","sourcesContent":["import {AsyncLocalStorage} from \"async_hooks\";\nimport {DIContext} from \"../domain/DIContext\";\n\nlet store: AsyncLocalStorage<DIContext>;\n\nexport function getAsyncStore() {\n store = store || new AsyncLocalStorage();\n return store;\n}\n\nexport function getContext() {\n return store?.getStore();\n}\n\nexport function runInContext(ctx: DIContext, cb: any) {\n // istanbul ignore else\n return AsyncLocalStorage ? getAsyncStore().run(ctx, cb) : cb();\n}\n"]}
|
|
@@ -1,6 +0,0 @@
|
|
|
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): any;
|