@tsed/di 7.0.0-beta.7 → 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 +26 -1
- 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 -0
- 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 +13 -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 +24 -0
- 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 -0
- 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 +13 -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/decorators/inject.d.ts +15 -0
- 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 -0
- 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/DITest.d.ts +2 -0
- 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
|
@@ -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
|
|