@tsed/di 7.79.4 → 7.80.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/lib/types-esm/common/constants/constants.d.ts +3 -0
- package/lib/types-esm/common/decorators/configuration.d.ts +8 -0
- package/lib/types-esm/common/decorators/constant.d.ts +36 -0
- package/lib/types-esm/common/decorators/controller.d.ts +42 -0
- package/lib/types-esm/common/decorators/inject.d.ts +22 -0
- package/lib/types-esm/common/decorators/injectable.d.ts +20 -0
- package/lib/types-esm/common/decorators/intercept.d.ts +10 -0
- package/lib/types-esm/common/decorators/interceptor.d.ts +10 -0
- package/lib/types-esm/common/decorators/lazyInject.d.ts +43 -0
- package/lib/types-esm/common/decorators/module.d.ts +37 -0
- package/lib/types-esm/common/decorators/opts.d.ts +41 -0
- package/lib/types-esm/common/decorators/overrideProvider.d.ts +8 -0
- package/lib/types-esm/common/decorators/scope.d.ts +8 -0
- package/lib/types-esm/common/decorators/service.d.ts +10 -0
- package/lib/types-esm/common/decorators/useOpts.d.ts +42 -0
- package/lib/types-esm/common/decorators/value.d.ts +36 -0
- package/lib/types-esm/common/domain/Container.d.ts +43 -0
- package/lib/types-esm/common/domain/ControllerProvider.d.ts +17 -0
- package/lib/types-esm/common/domain/InjectablePropertyType.d.ts +7 -0
- package/lib/types-esm/common/domain/LocalsContainer.d.ts +6 -0
- package/lib/types-esm/common/domain/Provider.d.ts +71 -0
- package/lib/types-esm/common/domain/ProviderScope.d.ts +5 -0
- package/lib/types-esm/common/domain/ProviderType.d.ts +10 -0
- package/lib/types-esm/common/errors/InjectionError.d.ts +8 -0
- package/lib/types-esm/common/errors/InvalidPropertyTokenError.d.ts +4 -0
- package/lib/types-esm/common/errors/UndefinedTokenError.d.ts +4 -0
- package/lib/types-esm/common/index.d.ts +55 -0
- package/lib/types-esm/common/interfaces/DIConfigurationOptions.d.ts +29 -0
- package/lib/types-esm/common/interfaces/DILogger.d.ts +8 -0
- package/lib/types-esm/common/interfaces/DILoggerOptions.d.ts +53 -0
- package/lib/types-esm/common/interfaces/DIResolver.d.ts +5 -0
- package/lib/types-esm/common/interfaces/ImportTokenProviderOpts.d.ts +19 -0
- package/lib/types-esm/common/interfaces/InjectableProperties.d.ts +25 -0
- package/lib/types-esm/common/interfaces/InterceptorContext.d.ts +11 -0
- package/lib/types-esm/common/interfaces/InterceptorMethods.d.ts +4 -0
- package/lib/types-esm/common/interfaces/InvokeOptions.d.ts +10 -0
- package/lib/types-esm/common/interfaces/OnDestroy.d.ts +3 -0
- package/lib/types-esm/common/interfaces/OnInit.d.ts +3 -0
- package/lib/types-esm/common/interfaces/ProviderOpts.d.ts +59 -0
- package/lib/types-esm/common/interfaces/RegistrySettings.d.ts +20 -0
- package/lib/types-esm/common/interfaces/ResolvedInvokeOptions.d.ts +12 -0
- package/lib/types-esm/common/interfaces/TokenProvider.d.ts +6 -0
- package/lib/types-esm/common/interfaces/TokenRoute.d.ts +5 -0
- package/lib/types-esm/common/registries/GlobalProviders.d.ts +58 -0
- package/lib/types-esm/common/registries/ProviderRegistry.d.ts +58 -0
- package/lib/types-esm/common/services/DIConfiguration.d.ts +57 -0
- package/lib/types-esm/common/services/DILogger.d.ts +3 -0
- package/lib/types-esm/common/services/InjectorService.d.ts +224 -0
- package/lib/types-esm/common/utils/colors.d.ts +5 -0
- package/lib/types-esm/common/utils/createContainer.d.ts +3 -0
- package/lib/types-esm/common/utils/getConfiguration.d.ts +3 -0
- package/lib/types-esm/common/utils/getConstructorDependencies.d.ts +2 -0
- package/lib/types-esm/common/utils/resolveControllers.d.ts +12 -0
- package/lib/types-esm/index.d.ts +2 -0
- package/lib/types-esm/node/decorators/injectContext.d.ts +15 -0
- package/lib/types-esm/node/domain/ContextLogger.d.ts +37 -0
- package/lib/types-esm/node/domain/DIContext.d.ts +61 -0
- package/lib/types-esm/node/index.d.ts +14 -0
- package/lib/types-esm/node/interfaces/AlterRunInContext.d.ts +3 -0
- package/lib/types-esm/node/services/DILogger.d.ts +1 -0
- package/lib/types-esm/node/services/DITest.d.ts +37 -0
- package/lib/types-esm/node/utils/asyncHookContext.d.ts +14 -0
- package/lib/types-esm/node/utils/attachLogger.d.ts +2 -0
- package/lib/types-esm/node/utils/setLoggerConfiguration.d.ts +2 -0
- package/lib/types-esm/node/utils/setLoggerFormat.d.ts +6 -0
- package/lib/types-esm/node/utils/setLoggerLevel.d.ts +6 -0
- package/package.json +19 -16
- package/vitest.config.mts +21 -0
- package/jest.config.js +0 -14
- package/lib/cjs/package.json +0 -3
- package/lib/esm/package.json +0 -3
- package/tsconfig.esm.json +0 -39
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { Container } from "../domain/Container.js";
|
|
2
|
+
import { LocalsContainer } from "../domain/LocalsContainer.js";
|
|
3
|
+
import { Provider } from "../domain/Provider.js";
|
|
4
|
+
import { ProviderScope } from "../domain/ProviderScope.js";
|
|
5
|
+
import type { DILogger } from "../interfaces/DILogger.js";
|
|
6
|
+
import { InjectablePropertyOptions, InjectablePropertyValue } from "../interfaces/InjectableProperties.js";
|
|
7
|
+
import type { InvokeOptions } from "../interfaces/InvokeOptions.js";
|
|
8
|
+
import type { TokenProvider } from "../interfaces/TokenProvider.js";
|
|
9
|
+
import { DIConfiguration } from "./DIConfiguration.js";
|
|
10
|
+
/**
|
|
11
|
+
* This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.
|
|
12
|
+
*
|
|
13
|
+
* ### Example:
|
|
14
|
+
*
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import {InjectorService} from "@tsed/di";
|
|
17
|
+
*
|
|
18
|
+
* // Import the services (all services are decorated with @Service()";
|
|
19
|
+
* import MyService1 from "./services/service1.js";
|
|
20
|
+
* import MyService2 from "./services/service2.js";
|
|
21
|
+
* import MyService3 from "./services/service3.js";
|
|
22
|
+
*
|
|
23
|
+
* // When all services are imported, you can load InjectorService.
|
|
24
|
+
* const injector = new InjectorService()
|
|
25
|
+
*
|
|
26
|
+
* await injector.load();
|
|
27
|
+
*
|
|
28
|
+
* const myService1 = injector.get<MyService1>(MyServcice1);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class InjectorService extends Container {
|
|
32
|
+
#private;
|
|
33
|
+
settings: DIConfiguration;
|
|
34
|
+
logger: DILogger;
|
|
35
|
+
private resolvedConfiguration;
|
|
36
|
+
constructor();
|
|
37
|
+
get resolvers(): import("../index.js").DIResolver[];
|
|
38
|
+
get scopes(): Record<string, ProviderScope>;
|
|
39
|
+
/**
|
|
40
|
+
* Retrieve default scope for a given provider.
|
|
41
|
+
* @param provider
|
|
42
|
+
*/
|
|
43
|
+
scopeOf(provider: Provider): ProviderScope;
|
|
44
|
+
/**
|
|
45
|
+
* Return a list of instance build by the injector.
|
|
46
|
+
*/
|
|
47
|
+
toArray(): any[];
|
|
48
|
+
/**
|
|
49
|
+
* Get a service or factory already constructed from his symbol or class.
|
|
50
|
+
*
|
|
51
|
+
* #### Example
|
|
52
|
+
*
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import {InjectorService} from "@tsed/di";
|
|
55
|
+
* import MyService from "./services.js";
|
|
56
|
+
*
|
|
57
|
+
* class OtherService {
|
|
58
|
+
* constructor(injectorService: InjectorService) {
|
|
59
|
+
* const myService = injectorService.get<MyService>(MyService);
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @param token The class or symbol registered in InjectorService.
|
|
65
|
+
* @param options
|
|
66
|
+
* @returns {boolean}
|
|
67
|
+
*/
|
|
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
|
+
* @param locals
|
|
73
|
+
* @param options
|
|
74
|
+
*/
|
|
75
|
+
getMany<Type = any>(type: any, locals?: LocalsContainer, options?: Partial<InvokeOptions<Type>>): Type[];
|
|
76
|
+
/**
|
|
77
|
+
* The has() method returns a boolean indicating whether an element with the specified key exists or not.
|
|
78
|
+
* @returns {boolean}
|
|
79
|
+
* @param token
|
|
80
|
+
*/
|
|
81
|
+
has(token: TokenProvider): boolean;
|
|
82
|
+
alias(token: TokenProvider, alias: TokenProvider): this;
|
|
83
|
+
/**
|
|
84
|
+
* Invoke the class and inject all services that required by the class constructor.
|
|
85
|
+
*
|
|
86
|
+
* #### Example
|
|
87
|
+
*
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import {InjectorService} from "@tsed/di";
|
|
90
|
+
* import MyService from "./services.js";
|
|
91
|
+
*
|
|
92
|
+
* class OtherService {
|
|
93
|
+
* constructor(injectorService: InjectorService) {
|
|
94
|
+
* const myService = injectorService.invoke<MyService>(MyService);
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @param token The injectable class to invoke. Class parameters are injected according constructor signature.
|
|
100
|
+
* @param locals Optional object. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.
|
|
101
|
+
* @param options
|
|
102
|
+
* @returns {T} The class constructed.
|
|
103
|
+
*/
|
|
104
|
+
invoke<T = any>(token: TokenProvider, locals?: LocalsContainer, options?: Partial<InvokeOptions<T>>): T;
|
|
105
|
+
/**
|
|
106
|
+
* Build only providers which are asynchronous.
|
|
107
|
+
*/
|
|
108
|
+
loadAsync(): Promise<void>;
|
|
109
|
+
loadSync(): void;
|
|
110
|
+
/**
|
|
111
|
+
* Boostrap injector from container and resolve configuration.
|
|
112
|
+
*
|
|
113
|
+
* @param container
|
|
114
|
+
*/
|
|
115
|
+
bootstrap(container?: Container): this;
|
|
116
|
+
/**
|
|
117
|
+
* Load injector from a given module
|
|
118
|
+
* @param rootModule
|
|
119
|
+
*/
|
|
120
|
+
loadModule(rootModule: TokenProvider): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Build all providers from given container (or GlobalProviders) and emit `$onInit` event.
|
|
123
|
+
*
|
|
124
|
+
* @param container
|
|
125
|
+
*/
|
|
126
|
+
load(container?: Container): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Load all configurations registered on providers
|
|
129
|
+
*/
|
|
130
|
+
resolveConfiguration(): void;
|
|
131
|
+
/**
|
|
132
|
+
*
|
|
133
|
+
* @param instance
|
|
134
|
+
* @param locals
|
|
135
|
+
* @param options
|
|
136
|
+
*/
|
|
137
|
+
bindInjectableProperties(instance: any, locals: LocalsContainer, options: Partial<InvokeOptions>): void;
|
|
138
|
+
/**
|
|
139
|
+
* Create an injectable property.
|
|
140
|
+
*
|
|
141
|
+
* @param instance
|
|
142
|
+
* @param {string} propertyKey
|
|
143
|
+
* @param {any} useType
|
|
144
|
+
* @param resolver
|
|
145
|
+
* @param options
|
|
146
|
+
* @param locals
|
|
147
|
+
* @param invokeOptions
|
|
148
|
+
*/
|
|
149
|
+
bindProperty(instance: any, { propertyKey, resolver, options }: InjectablePropertyOptions, locals: LocalsContainer, invokeOptions: Partial<InvokeOptions>): void;
|
|
150
|
+
/**
|
|
151
|
+
*
|
|
152
|
+
* @param instance
|
|
153
|
+
* @param {string} propertyKey
|
|
154
|
+
* @param {any} useType
|
|
155
|
+
*/
|
|
156
|
+
bindValue(instance: any, { propertyKey, expression, defaultValue }: InjectablePropertyValue): void;
|
|
157
|
+
/**
|
|
158
|
+
*
|
|
159
|
+
* @param instance
|
|
160
|
+
* @param {string} propertyKey
|
|
161
|
+
* @param {any} useType
|
|
162
|
+
*/
|
|
163
|
+
bindConstant(instance: any, { propertyKey, expression, defaultValue }: InjectablePropertyValue): void;
|
|
164
|
+
/**
|
|
165
|
+
*
|
|
166
|
+
* @param instance
|
|
167
|
+
* @param propertyKey
|
|
168
|
+
* @param useType
|
|
169
|
+
* @param options
|
|
170
|
+
*/
|
|
171
|
+
bindInterceptor(instance: any, { propertyKey, useType, options }: InjectablePropertyOptions): void;
|
|
172
|
+
lazyInvoke<T = any>(token: TokenProvider): Promise<any>;
|
|
173
|
+
/**
|
|
174
|
+
* Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
|
|
175
|
+
* @param eventName The event name to emit at all services.
|
|
176
|
+
* @param args List of the parameters to give to each service.
|
|
177
|
+
* @returns {Promise<any[]>} A list of promises.
|
|
178
|
+
*/
|
|
179
|
+
emit(eventName: string, ...args: any[]): Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* @param eventName
|
|
182
|
+
* @param value
|
|
183
|
+
* @param args
|
|
184
|
+
*/
|
|
185
|
+
alter<T = any>(eventName: string, value: any, ...args: any[]): T;
|
|
186
|
+
/**
|
|
187
|
+
* @param eventName
|
|
188
|
+
* @param value
|
|
189
|
+
* @param args
|
|
190
|
+
*/
|
|
191
|
+
alterAsync<T = any>(eventName: string, value: any, ...args: any[]): Promise<T>;
|
|
192
|
+
destroy(): Promise<void>;
|
|
193
|
+
protected ensureProvider(token: TokenProvider, force: true): Provider;
|
|
194
|
+
protected ensureProvider(token: TokenProvider, force: false): Provider | undefined;
|
|
195
|
+
protected ensureProvider(token: TokenProvider): Provider | undefined;
|
|
196
|
+
protected getInstance(token: any): any;
|
|
197
|
+
/**
|
|
198
|
+
* Invoke a class method and inject service.
|
|
199
|
+
*
|
|
200
|
+
* #### IInjectableMethod options
|
|
201
|
+
*
|
|
202
|
+
* * **target**: Optional. The class instance.
|
|
203
|
+
* * **methodName**: `string` Optional. The method name.
|
|
204
|
+
* * **designParamTypes**: `any[]` Optional. List of injectable types.
|
|
205
|
+
* * **locals**: `Map<Function, any>` Optional. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.
|
|
206
|
+
*
|
|
207
|
+
* #### Example
|
|
208
|
+
*
|
|
209
|
+
* @param target
|
|
210
|
+
* @param locals
|
|
211
|
+
* @param options
|
|
212
|
+
* @private
|
|
213
|
+
*/
|
|
214
|
+
protected resolve<T>(target: TokenProvider, locals?: LocalsContainer, options?: Partial<InvokeOptions<T>>): T | Promise<T>;
|
|
215
|
+
private resolveImportsProviders;
|
|
216
|
+
/**
|
|
217
|
+
* Create options to invoke a provider or class.
|
|
218
|
+
* @param token
|
|
219
|
+
* @param locals
|
|
220
|
+
* @param options
|
|
221
|
+
*/
|
|
222
|
+
private mapInvokeOptions;
|
|
223
|
+
private registerHooks;
|
|
224
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TokenProvider } from "../interfaces/TokenProvider.js";
|
|
2
|
+
import { TokenRoute } from "../interfaces/TokenRoute.js";
|
|
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[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inject a context like PlatformContext or any BaseContext.
|
|
3
|
+
*
|
|
4
|
+
* ```typescript
|
|
5
|
+
* @Injectable()
|
|
6
|
+
* export class MyService {
|
|
7
|
+
* @InjectContext()
|
|
8
|
+
* ctx?: Context;
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @returns {Function}
|
|
13
|
+
* @decorator
|
|
14
|
+
*/
|
|
15
|
+
export declare function InjectContext(): PropertyDecorator;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { DILogger } from "../../common/index.js";
|
|
2
|
+
import { Hooks } from "@tsed/core";
|
|
3
|
+
import { LogLevel } from "@tsed/logger";
|
|
4
|
+
export interface ContextLoggerOptions extends Record<string, any> {
|
|
5
|
+
id: string;
|
|
6
|
+
logger?: DILogger;
|
|
7
|
+
level?: "debug" | "info" | "warn" | "error" | "off" | "all";
|
|
8
|
+
maxStackSize?: number;
|
|
9
|
+
additionalProps?: Record<any, any>;
|
|
10
|
+
}
|
|
11
|
+
export declare class ContextLogger {
|
|
12
|
+
#private;
|
|
13
|
+
readonly dateStart: Date;
|
|
14
|
+
readonly id: string;
|
|
15
|
+
maxStackSize: number;
|
|
16
|
+
level: LogLevel;
|
|
17
|
+
constructor({ id, logger, dateStart, level, maxStackSize, additionalProps }: ContextLoggerOptions);
|
|
18
|
+
get hooks(): Hooks;
|
|
19
|
+
private get stack();
|
|
20
|
+
alterLog(cb: (data: any, level: "debug" | "info" | "warn" | "error" | "off" | "all", withRequest: boolean) => any): Hooks;
|
|
21
|
+
alterIgnoreLog(cb: (ignore: boolean, data: any) => boolean): Hooks;
|
|
22
|
+
info(obj: any): this;
|
|
23
|
+
debug(obj: any, withRequest?: boolean): this;
|
|
24
|
+
warn(obj: any): this;
|
|
25
|
+
error(obj: any): this;
|
|
26
|
+
fatal(obj: any): this;
|
|
27
|
+
trace(obj: any): this;
|
|
28
|
+
flush(stream?: boolean): void;
|
|
29
|
+
isLevelEnabled(otherLevel: string | LogLevel): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Return the duration between the time when LogIncomingRequest has handle the request and now.
|
|
32
|
+
* @returns {number}
|
|
33
|
+
*/
|
|
34
|
+
protected getDuration(): number;
|
|
35
|
+
protected getData(obj: any): any;
|
|
36
|
+
protected run(level: LogLevel, obj: any, withRequest?: boolean): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { InjectorService, LocalsContainer } from "../../common/index.js";
|
|
2
|
+
import { ContextLogger, ContextLoggerOptions } from "./ContextLogger.js";
|
|
3
|
+
export interface DIContextOptions extends Omit<ContextLoggerOptions, "dateStart"> {
|
|
4
|
+
id: string;
|
|
5
|
+
injector: InjectorService;
|
|
6
|
+
logger: any;
|
|
7
|
+
platform?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class DIContext {
|
|
10
|
+
#private;
|
|
11
|
+
opts: DIContextOptions;
|
|
12
|
+
[x: string]: any;
|
|
13
|
+
readonly PLATFORM: string;
|
|
14
|
+
constructor(opts: DIContextOptions);
|
|
15
|
+
/**
|
|
16
|
+
* Logger attached to the context request.
|
|
17
|
+
*/
|
|
18
|
+
get logger(): ContextLogger;
|
|
19
|
+
/**
|
|
20
|
+
* Request id generated by @@contextMiddleware@@.
|
|
21
|
+
*
|
|
22
|
+
* ::: tip
|
|
23
|
+
* By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, ""))`.
|
|
24
|
+
* Dash are removed to simplify tracking logs in Kibana
|
|
25
|
+
* :::
|
|
26
|
+
*
|
|
27
|
+
* ::: tip
|
|
28
|
+
* Request id can by customized by changing the server configuration.
|
|
29
|
+
*
|
|
30
|
+
* ```typescript
|
|
31
|
+
* @Configuration({
|
|
32
|
+
* logger: {
|
|
33
|
+
* reqIdBuilder: createUniqId // give your own id generator function
|
|
34
|
+
* }
|
|
35
|
+
* })
|
|
36
|
+
* class Server {
|
|
37
|
+
*
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
* :::
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
get id(): string;
|
|
44
|
+
get dateStart(): Date;
|
|
45
|
+
get injector(): InjectorService;
|
|
46
|
+
get env(): any;
|
|
47
|
+
/**
|
|
48
|
+
* The request container used by the Ts.ED DI. It contains all services annotated with `@Scope(ProviderScope.REQUEST)`
|
|
49
|
+
*/
|
|
50
|
+
get container(): LocalsContainer;
|
|
51
|
+
destroy(): Promise<any>;
|
|
52
|
+
emit(eventName: string, ...args: any[]): Promise<void>;
|
|
53
|
+
runInContext(next: Function): Promise<any>;
|
|
54
|
+
cache<Value = any>(key: string, cb: () => Value): Value;
|
|
55
|
+
cacheAsync<Value = any>(key: string, cb: () => Promise<Value>): Promise<Value>;
|
|
56
|
+
delete(key: any): boolean;
|
|
57
|
+
get<T = any>(key: any): T;
|
|
58
|
+
has(key: any): boolean;
|
|
59
|
+
set(key: any, value: any): this;
|
|
60
|
+
}
|
|
61
|
+
export type BaseContext = DIContext & TsED.Context;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by @tsed/barrels.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./decorators/injectContext.js";
|
|
5
|
+
export * from "./domain/ContextLogger.js";
|
|
6
|
+
export * from "./domain/DIContext.js";
|
|
7
|
+
export * from "./interfaces/AlterRunInContext.js";
|
|
8
|
+
export * from "./services/DILogger.js";
|
|
9
|
+
export * from "./services/DITest.js";
|
|
10
|
+
export * from "./utils/asyncHookContext.js";
|
|
11
|
+
export * from "./utils/attachLogger.js";
|
|
12
|
+
export * from "./utils/setLoggerConfiguration.js";
|
|
13
|
+
export * from "./utils/setLoggerFormat.js";
|
|
14
|
+
export * from "./utils/setLoggerLevel.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { InjectorService, TokenProvider, type UseImportTokenProviderOpts } from "../../common/index.js";
|
|
2
|
+
import { DIContext } from "../domain/DIContext.js";
|
|
3
|
+
/**
|
|
4
|
+
* Tool to run test with lightweight DI sandbox.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DITest {
|
|
7
|
+
static options: Partial<TsED.Configuration>;
|
|
8
|
+
protected static _injector: InjectorService | null;
|
|
9
|
+
static get injector(): InjectorService;
|
|
10
|
+
static set injector(injector: InjectorService);
|
|
11
|
+
static set(key: string, value: any): void;
|
|
12
|
+
static hasInjector(): boolean;
|
|
13
|
+
static create(settings?: Partial<TsED.Configuration>): Promise<void>;
|
|
14
|
+
static createContainer(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Create a new injector with the right default services
|
|
17
|
+
*/
|
|
18
|
+
static createInjector(settings?: any): InjectorService;
|
|
19
|
+
/**
|
|
20
|
+
* Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.
|
|
21
|
+
*/
|
|
22
|
+
static reset(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Invoke a provider and return a fresh instance
|
|
25
|
+
* @param target
|
|
26
|
+
* @param providers
|
|
27
|
+
*/
|
|
28
|
+
static invoke<T = any>(target: TokenProvider, providers?: UseImportTokenProviderOpts[]): Promise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Return the instance from injector registry
|
|
31
|
+
* @param target
|
|
32
|
+
* @param options
|
|
33
|
+
*/
|
|
34
|
+
static get<T = any>(target: TokenProvider, options?: any): T;
|
|
35
|
+
static createDIContext(): DIContext;
|
|
36
|
+
protected static configure(settings?: Partial<TsED.Configuration>): Partial<TsED.Configuration>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
+
import { InjectorService } from "../../common/index.js";
|
|
4
|
+
import type { DIContext } from "../domain/DIContext.js";
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,45 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/di",
|
|
3
|
-
"version": "7.79.4",
|
|
4
3
|
"description": "DI module for Ts.ED Framework",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"version": "7.80.1",
|
|
5
6
|
"source": "./src/index.ts",
|
|
6
|
-
"main": "lib/
|
|
7
|
+
"main": "lib/esm/index.js",
|
|
7
8
|
"module": "lib/esm/index.js",
|
|
8
9
|
"typings": "./lib/types/index.d.ts",
|
|
9
10
|
"browser": "./lib/browser/di.umd.min.js",
|
|
10
11
|
"exports": {
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/types/index.d.ts",
|
|
14
|
+
"browser": "./lib/browser/di.umd.min.js",
|
|
15
|
+
"import": "./lib/esm/index.js",
|
|
16
|
+
"default": "./lib/cjs/index.js"
|
|
17
|
+
}
|
|
16
18
|
},
|
|
17
19
|
"scripts": {
|
|
18
20
|
"build": "yarn barrels && yarn build:ts && yarn run build:browser",
|
|
19
21
|
"build:browser": "webpack",
|
|
20
22
|
"barrels": "barrels",
|
|
21
|
-
"test": "
|
|
22
|
-
"build:ts": "tsc --build tsconfig.json
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"build:ts": "tsc --build tsconfig.json",
|
|
25
|
+
"test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
|
|
23
26
|
},
|
|
24
27
|
"dependencies": {
|
|
25
28
|
"tslib": "2.6.2"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
|
-
"@tsed/barrels": "7.
|
|
29
|
-
"@tsed/core": "7.
|
|
31
|
+
"@tsed/barrels": "7.80.1",
|
|
32
|
+
"@tsed/core": "7.80.1",
|
|
30
33
|
"@tsed/logger": ">=6.7.5",
|
|
31
|
-
"@tsed/schema": "7.
|
|
32
|
-
"@tsed/typescript": "7.
|
|
34
|
+
"@tsed/schema": "7.80.1",
|
|
35
|
+
"@tsed/typescript": "7.80.1",
|
|
33
36
|
"cross-env": "7.0.3",
|
|
34
37
|
"eslint": "^8.57.0",
|
|
35
|
-
"jest": "^29.7.0",
|
|
36
38
|
"typescript": "4.9.5",
|
|
39
|
+
"vitest": "2.0.4",
|
|
37
40
|
"webpack": "^5.75.0"
|
|
38
41
|
},
|
|
39
42
|
"peerDependencies": {
|
|
40
|
-
"@tsed/core": "7.
|
|
43
|
+
"@tsed/core": "7.80.1",
|
|
41
44
|
"@tsed/logger": ">=6.7.5",
|
|
42
|
-
"@tsed/schema": "7.
|
|
45
|
+
"@tsed/schema": "7.80.1"
|
|
43
46
|
},
|
|
44
47
|
"peerDependenciesMeta": {
|
|
45
48
|
"@tsed/core": {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import {presets} from "@tsed/vitest/presets";
|
|
3
|
+
import {defineConfig} from "vitest/config";
|
|
4
|
+
|
|
5
|
+
export default defineConfig(
|
|
6
|
+
{
|
|
7
|
+
...presets,
|
|
8
|
+
test: {
|
|
9
|
+
...presets.test,
|
|
10
|
+
coverage: {
|
|
11
|
+
...presets.test.coverage,
|
|
12
|
+
thresholds: {
|
|
13
|
+
statements: 0,
|
|
14
|
+
branches: 0,
|
|
15
|
+
functions: 0,
|
|
16
|
+
lines: 0
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
);
|
package/jest.config.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// For a detailed explanation regarding each configuration property, visit:
|
|
2
|
-
// https://jestjs.io/docs/en/configuration.html
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
...require("@tsed/jest-config"),
|
|
6
|
-
coverageThreshold: {
|
|
7
|
-
global: {
|
|
8
|
-
statements: 99.27,
|
|
9
|
-
branches: 96.99,
|
|
10
|
-
lines: 99.27,
|
|
11
|
-
functions: 99.17
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
};
|
package/lib/cjs/package.json
DELETED
package/lib/esm/package.json
DELETED
package/tsconfig.esm.json
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@tsed/typescript/tsconfig.node.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"baseUrl": "./",
|
|
5
|
-
"module": "ES2020",
|
|
6
|
-
"rootDir": "src",
|
|
7
|
-
"outDir": "./lib/esm",
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"declarationDir": "./lib/types",
|
|
10
|
-
"composite": true,
|
|
11
|
-
"noEmit": false
|
|
12
|
-
},
|
|
13
|
-
"include": ["src", "src/**/*.json"],
|
|
14
|
-
"exclude": [
|
|
15
|
-
"node_modules",
|
|
16
|
-
"test",
|
|
17
|
-
"lib",
|
|
18
|
-
"benchmark",
|
|
19
|
-
"coverage",
|
|
20
|
-
"spec",
|
|
21
|
-
"**/*.benchmark.ts",
|
|
22
|
-
"**/*.spec.ts",
|
|
23
|
-
"keys",
|
|
24
|
-
"jest.config.js",
|
|
25
|
-
"**/__mock__/**",
|
|
26
|
-
"webpack.config.js"
|
|
27
|
-
],
|
|
28
|
-
"references": [
|
|
29
|
-
{
|
|
30
|
-
"path": "../core"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"path": "../core"
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"path": "../specs/schema"
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
}
|