@navios/di 0.4.0 → 0.4.2
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/_tsup-dts-rollup.d.mts +77 -5
- package/lib/_tsup-dts-rollup.d.ts +77 -5
- package/lib/chunk-3NLYPYBY.mjs +1627 -0
- package/lib/chunk-3NLYPYBY.mjs.map +1 -0
- package/lib/index.js +11 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +4 -1599
- package/lib/index.mjs.map +1 -1
- package/lib/testing/index.d.mts +2 -0
- package/lib/testing/index.d.ts +2 -0
- package/lib/testing/index.js +1642 -0
- package/lib/testing/index.js.map +1 -0
- package/lib/testing/index.mjs +73 -0
- package/lib/testing/index.mjs.map +1 -0
- package/package.json +11 -1
- package/src/container.mts +11 -3
- package/src/event-emitter.mts +5 -5
- package/src/testing/README.md +80 -0
- package/src/testing/__tests__/test-container.spec.mts +173 -0
- package/src/testing/index.mts +1 -0
- package/src/testing/test-container.mts +120 -0
- package/tsup.config.mts +1 -1
|
@@ -150,6 +150,9 @@ export { ClassTypeWithOptionalArgument as ClassTypeWithOptionalArgument_alias_1
|
|
|
150
150
|
* It wraps a ServiceLocator instance and provides convenient methods for getting instances.
|
|
151
151
|
*/
|
|
152
152
|
declare class Container {
|
|
153
|
+
protected readonly registry: Registry;
|
|
154
|
+
protected readonly logger: Console | null;
|
|
155
|
+
protected readonly injectors: Injectors;
|
|
153
156
|
private readonly serviceLocator;
|
|
154
157
|
constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
|
|
155
158
|
private registerSelf;
|
|
@@ -198,6 +201,11 @@ declare class Container {
|
|
|
198
201
|
* @param requestId The request ID to set as current
|
|
199
202
|
*/
|
|
200
203
|
setCurrentRequestContext(requestId: string): void;
|
|
204
|
+
/**
|
|
205
|
+
* Clears all instances and bindings from the container.
|
|
206
|
+
* This is useful for testing or resetting the container state.
|
|
207
|
+
*/
|
|
208
|
+
clear(): void;
|
|
201
209
|
}
|
|
202
210
|
export { Container }
|
|
203
211
|
export { Container as Container_alias_1 }
|
|
@@ -309,17 +317,17 @@ export { ErrorsEnum as ErrorsEnum_alias_2 }
|
|
|
309
317
|
|
|
310
318
|
declare class EventEmitter<Events extends EventsConfig = {}> implements EventEmitterInterface<Events> {
|
|
311
319
|
private listeners;
|
|
312
|
-
on<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void): () => void;
|
|
313
|
-
off<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void): void;
|
|
314
|
-
once<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void): () => void;
|
|
320
|
+
on<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void | Promise<void>): () => void;
|
|
321
|
+
off<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void | Promise<void>): void;
|
|
322
|
+
once<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void | Promise<void>): () => void;
|
|
315
323
|
emit<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, ...args: Args): Promise<any>;
|
|
316
324
|
}
|
|
317
325
|
export { EventEmitter }
|
|
318
326
|
export { EventEmitter as EventEmitter_alias_1 }
|
|
319
327
|
|
|
320
328
|
declare interface EventEmitterInterface<Events extends EventsConfig> {
|
|
321
|
-
on<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void): () => void;
|
|
322
|
-
emit<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, ...args: Args): void
|
|
329
|
+
on<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void | Promise<void>): () => void;
|
|
330
|
+
emit<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, ...args: Args): void | Promise<void>;
|
|
323
331
|
}
|
|
324
332
|
export { EventEmitterInterface }
|
|
325
333
|
export { EventEmitterInterface as EventEmitterInterface_alias_1 }
|
|
@@ -1017,6 +1025,70 @@ export declare const test4: {
|
|
|
1017
1025
|
|
|
1018
1026
|
export declare const test5: object;
|
|
1019
1027
|
|
|
1028
|
+
/**
|
|
1029
|
+
* A binding builder for the TestContainer that allows chaining binding operations.
|
|
1030
|
+
*/
|
|
1031
|
+
declare class TestBindingBuilder<T> {
|
|
1032
|
+
private readonly container;
|
|
1033
|
+
private readonly token;
|
|
1034
|
+
constructor(container: TestContainer, token: InjectionToken<T, any>);
|
|
1035
|
+
/**
|
|
1036
|
+
* Binds the token to a specific value.
|
|
1037
|
+
* This is useful for testing with mock values or constants.
|
|
1038
|
+
* @param value The value to bind to the token
|
|
1039
|
+
*/
|
|
1040
|
+
toValue(value: T): TestContainer;
|
|
1041
|
+
/**
|
|
1042
|
+
* Binds the token to a class constructor.
|
|
1043
|
+
* @param target The class constructor to bind to
|
|
1044
|
+
*/
|
|
1045
|
+
toClass(target: ClassType): TestContainer;
|
|
1046
|
+
}
|
|
1047
|
+
export { TestBindingBuilder }
|
|
1048
|
+
export { TestBindingBuilder as TestBindingBuilder_alias_1 }
|
|
1049
|
+
|
|
1050
|
+
/**
|
|
1051
|
+
* TestContainer extends the base Container with additional methods useful for testing.
|
|
1052
|
+
* It provides a simplified API for binding values and classes during test setup.
|
|
1053
|
+
*/
|
|
1054
|
+
declare class TestContainer extends Container {
|
|
1055
|
+
constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
|
|
1056
|
+
/**
|
|
1057
|
+
* Creates a binding builder for the given token.
|
|
1058
|
+
* This allows chaining binding operations like bind(Token).toValue(value).
|
|
1059
|
+
* @param token The injection token to bind
|
|
1060
|
+
* @returns A TestBindingBuilder for chaining binding operations
|
|
1061
|
+
*/
|
|
1062
|
+
bind<T>(token: ClassType): TestBindingBuilder<T>;
|
|
1063
|
+
bind<T>(token: InjectionToken<T, any>): TestBindingBuilder<T>;
|
|
1064
|
+
/**
|
|
1065
|
+
* Binds a value directly to a token.
|
|
1066
|
+
* This is a convenience method equivalent to bind(token).toValue(value).
|
|
1067
|
+
* @param token The injection token to bind
|
|
1068
|
+
* @param value The value to bind to the token
|
|
1069
|
+
* @returns The TestContainer instance for chaining
|
|
1070
|
+
*/
|
|
1071
|
+
bindValue<T>(token: ClassType, value: T): TestContainer;
|
|
1072
|
+
bindValue<T>(token: InjectionToken<T, any>, value: T): TestContainer;
|
|
1073
|
+
/**
|
|
1074
|
+
* Binds a class to a token.
|
|
1075
|
+
* This is a convenience method equivalent to bind(token).toClass(target).
|
|
1076
|
+
* @param token The injection token to bind
|
|
1077
|
+
* @param target The class constructor to bind to
|
|
1078
|
+
* @returns The TestContainer instance for chaining
|
|
1079
|
+
*/
|
|
1080
|
+
bindClass(token: ClassType, target: ClassType): TestContainer;
|
|
1081
|
+
bindClass<T>(token: InjectionToken<T, any>, target: ClassType): TestContainer;
|
|
1082
|
+
/**
|
|
1083
|
+
* Creates a new TestContainer instance with the same configuration.
|
|
1084
|
+
* This is useful for creating isolated test containers.
|
|
1085
|
+
* @returns A new TestContainer instance
|
|
1086
|
+
*/
|
|
1087
|
+
createChild(): TestContainer;
|
|
1088
|
+
}
|
|
1089
|
+
export { TestContainer }
|
|
1090
|
+
export { TestContainer as TestContainer_alias_1 }
|
|
1091
|
+
|
|
1020
1092
|
declare type UnionToArray<T, A extends unknown[] = []> = IsUnion<T> extends true ? UnionToArray<Exclude<T, PopUnion<T>>, [PopUnion<T>, ...A]> : [T, ...A];
|
|
1021
1093
|
export { UnionToArray }
|
|
1022
1094
|
export { UnionToArray as UnionToArray_alias_1 }
|
|
@@ -150,6 +150,9 @@ export { ClassTypeWithOptionalArgument as ClassTypeWithOptionalArgument_alias_1
|
|
|
150
150
|
* It wraps a ServiceLocator instance and provides convenient methods for getting instances.
|
|
151
151
|
*/
|
|
152
152
|
declare class Container {
|
|
153
|
+
protected readonly registry: Registry;
|
|
154
|
+
protected readonly logger: Console | null;
|
|
155
|
+
protected readonly injectors: Injectors;
|
|
153
156
|
private readonly serviceLocator;
|
|
154
157
|
constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
|
|
155
158
|
private registerSelf;
|
|
@@ -198,6 +201,11 @@ declare class Container {
|
|
|
198
201
|
* @param requestId The request ID to set as current
|
|
199
202
|
*/
|
|
200
203
|
setCurrentRequestContext(requestId: string): void;
|
|
204
|
+
/**
|
|
205
|
+
* Clears all instances and bindings from the container.
|
|
206
|
+
* This is useful for testing or resetting the container state.
|
|
207
|
+
*/
|
|
208
|
+
clear(): void;
|
|
201
209
|
}
|
|
202
210
|
export { Container }
|
|
203
211
|
export { Container as Container_alias_1 }
|
|
@@ -309,17 +317,17 @@ export { ErrorsEnum as ErrorsEnum_alias_2 }
|
|
|
309
317
|
|
|
310
318
|
declare class EventEmitter<Events extends EventsConfig = {}> implements EventEmitterInterface<Events> {
|
|
311
319
|
private listeners;
|
|
312
|
-
on<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void): () => void;
|
|
313
|
-
off<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void): void;
|
|
314
|
-
once<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void): () => void;
|
|
320
|
+
on<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void | Promise<void>): () => void;
|
|
321
|
+
off<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void | Promise<void>): void;
|
|
322
|
+
once<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void | Promise<void>): () => void;
|
|
315
323
|
emit<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, ...args: Args): Promise<any>;
|
|
316
324
|
}
|
|
317
325
|
export { EventEmitter }
|
|
318
326
|
export { EventEmitter as EventEmitter_alias_1 }
|
|
319
327
|
|
|
320
328
|
declare interface EventEmitterInterface<Events extends EventsConfig> {
|
|
321
|
-
on<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void): () => void;
|
|
322
|
-
emit<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, ...args: Args): void
|
|
329
|
+
on<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void | Promise<void>): () => void;
|
|
330
|
+
emit<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, ...args: Args): void | Promise<void>;
|
|
323
331
|
}
|
|
324
332
|
export { EventEmitterInterface }
|
|
325
333
|
export { EventEmitterInterface as EventEmitterInterface_alias_1 }
|
|
@@ -1017,6 +1025,70 @@ export declare const test4: {
|
|
|
1017
1025
|
|
|
1018
1026
|
export declare const test5: object;
|
|
1019
1027
|
|
|
1028
|
+
/**
|
|
1029
|
+
* A binding builder for the TestContainer that allows chaining binding operations.
|
|
1030
|
+
*/
|
|
1031
|
+
declare class TestBindingBuilder<T> {
|
|
1032
|
+
private readonly container;
|
|
1033
|
+
private readonly token;
|
|
1034
|
+
constructor(container: TestContainer, token: InjectionToken<T, any>);
|
|
1035
|
+
/**
|
|
1036
|
+
* Binds the token to a specific value.
|
|
1037
|
+
* This is useful for testing with mock values or constants.
|
|
1038
|
+
* @param value The value to bind to the token
|
|
1039
|
+
*/
|
|
1040
|
+
toValue(value: T): TestContainer;
|
|
1041
|
+
/**
|
|
1042
|
+
* Binds the token to a class constructor.
|
|
1043
|
+
* @param target The class constructor to bind to
|
|
1044
|
+
*/
|
|
1045
|
+
toClass(target: ClassType): TestContainer;
|
|
1046
|
+
}
|
|
1047
|
+
export { TestBindingBuilder }
|
|
1048
|
+
export { TestBindingBuilder as TestBindingBuilder_alias_1 }
|
|
1049
|
+
|
|
1050
|
+
/**
|
|
1051
|
+
* TestContainer extends the base Container with additional methods useful for testing.
|
|
1052
|
+
* It provides a simplified API for binding values and classes during test setup.
|
|
1053
|
+
*/
|
|
1054
|
+
declare class TestContainer extends Container {
|
|
1055
|
+
constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
|
|
1056
|
+
/**
|
|
1057
|
+
* Creates a binding builder for the given token.
|
|
1058
|
+
* This allows chaining binding operations like bind(Token).toValue(value).
|
|
1059
|
+
* @param token The injection token to bind
|
|
1060
|
+
* @returns A TestBindingBuilder for chaining binding operations
|
|
1061
|
+
*/
|
|
1062
|
+
bind<T>(token: ClassType): TestBindingBuilder<T>;
|
|
1063
|
+
bind<T>(token: InjectionToken<T, any>): TestBindingBuilder<T>;
|
|
1064
|
+
/**
|
|
1065
|
+
* Binds a value directly to a token.
|
|
1066
|
+
* This is a convenience method equivalent to bind(token).toValue(value).
|
|
1067
|
+
* @param token The injection token to bind
|
|
1068
|
+
* @param value The value to bind to the token
|
|
1069
|
+
* @returns The TestContainer instance for chaining
|
|
1070
|
+
*/
|
|
1071
|
+
bindValue<T>(token: ClassType, value: T): TestContainer;
|
|
1072
|
+
bindValue<T>(token: InjectionToken<T, any>, value: T): TestContainer;
|
|
1073
|
+
/**
|
|
1074
|
+
* Binds a class to a token.
|
|
1075
|
+
* This is a convenience method equivalent to bind(token).toClass(target).
|
|
1076
|
+
* @param token The injection token to bind
|
|
1077
|
+
* @param target The class constructor to bind to
|
|
1078
|
+
* @returns The TestContainer instance for chaining
|
|
1079
|
+
*/
|
|
1080
|
+
bindClass(token: ClassType, target: ClassType): TestContainer;
|
|
1081
|
+
bindClass<T>(token: InjectionToken<T, any>, target: ClassType): TestContainer;
|
|
1082
|
+
/**
|
|
1083
|
+
* Creates a new TestContainer instance with the same configuration.
|
|
1084
|
+
* This is useful for creating isolated test containers.
|
|
1085
|
+
* @returns A new TestContainer instance
|
|
1086
|
+
*/
|
|
1087
|
+
createChild(): TestContainer;
|
|
1088
|
+
}
|
|
1089
|
+
export { TestContainer }
|
|
1090
|
+
export { TestContainer as TestContainer_alias_1 }
|
|
1091
|
+
|
|
1020
1092
|
declare type UnionToArray<T, A extends unknown[] = []> = IsUnion<T> extends true ? UnionToArray<Exclude<T, PopUnion<T>>, [PopUnion<T>, ...A]> : [T, ...A];
|
|
1021
1093
|
export { UnionToArray }
|
|
1022
1094
|
export { UnionToArray as UnionToArray_alias_1 }
|