@navios/di 0.4.1 → 0.5.0

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.
Files changed (128) hide show
  1. package/README.md +211 -1
  2. package/coverage/clover.xml +1912 -1277
  3. package/coverage/coverage-final.json +37 -28
  4. package/coverage/docs/examples/basic-usage.mts.html +1 -1
  5. package/coverage/docs/examples/factory-pattern.mts.html +1 -1
  6. package/coverage/docs/examples/index.html +1 -1
  7. package/coverage/docs/examples/injection-tokens.mts.html +1 -1
  8. package/coverage/docs/examples/request-scope-example.mts.html +1 -1
  9. package/coverage/docs/examples/service-lifecycle.mts.html +1 -1
  10. package/coverage/index.html +71 -41
  11. package/coverage/lib/_tsup-dts-rollup.d.mts.html +682 -43
  12. package/coverage/lib/index.d.mts.html +7 -4
  13. package/coverage/lib/index.html +5 -5
  14. package/coverage/lib/testing/index.d.mts.html +91 -0
  15. package/coverage/lib/testing/index.html +116 -0
  16. package/coverage/src/base-instance-holder-manager.mts.html +589 -0
  17. package/coverage/src/container.mts.html +257 -74
  18. package/coverage/src/decorators/factory.decorator.mts.html +1 -1
  19. package/coverage/src/decorators/index.html +1 -1
  20. package/coverage/src/decorators/index.mts.html +1 -1
  21. package/coverage/src/decorators/injectable.decorator.mts.html +20 -20
  22. package/coverage/src/enums/index.html +1 -1
  23. package/coverage/src/enums/index.mts.html +1 -1
  24. package/coverage/src/enums/injectable-scope.enum.mts.html +1 -1
  25. package/coverage/src/enums/injectable-type.enum.mts.html +1 -1
  26. package/coverage/src/errors/di-error.mts.html +292 -0
  27. package/coverage/src/errors/errors.enum.mts.html +30 -21
  28. package/coverage/src/errors/factory-not-found.mts.html +31 -22
  29. package/coverage/src/errors/factory-token-not-resolved.mts.html +29 -26
  30. package/coverage/src/errors/index.html +56 -41
  31. package/coverage/src/errors/index.mts.html +15 -9
  32. package/coverage/src/errors/instance-destroying.mts.html +31 -22
  33. package/coverage/src/errors/instance-expired.mts.html +31 -22
  34. package/coverage/src/errors/instance-not-found.mts.html +31 -22
  35. package/coverage/src/errors/unknown-error.mts.html +31 -43
  36. package/coverage/src/event-emitter.mts.html +14 -14
  37. package/coverage/src/factory-context.mts.html +1 -1
  38. package/coverage/src/index.html +121 -46
  39. package/coverage/src/index.mts.html +7 -4
  40. package/coverage/src/injection-token.mts.html +28 -28
  41. package/coverage/src/injector.mts.html +1 -1
  42. package/coverage/src/instance-resolver.mts.html +1762 -0
  43. package/coverage/src/interfaces/factory.interface.mts.html +1 -1
  44. package/coverage/src/interfaces/index.html +1 -1
  45. package/coverage/src/interfaces/index.mts.html +1 -1
  46. package/coverage/src/interfaces/on-service-destroy.interface.mts.html +1 -1
  47. package/coverage/src/interfaces/on-service-init.interface.mts.html +1 -1
  48. package/coverage/src/registry.mts.html +28 -28
  49. package/coverage/src/request-context-holder.mts.html +183 -102
  50. package/coverage/src/request-context-manager.mts.html +532 -0
  51. package/coverage/src/service-instantiator.mts.html +49 -49
  52. package/coverage/src/service-invalidator.mts.html +1372 -0
  53. package/coverage/src/service-locator-event-bus.mts.html +48 -48
  54. package/coverage/src/service-locator-instance-holder.mts.html +2 -14
  55. package/coverage/src/service-locator-manager.mts.html +71 -335
  56. package/coverage/src/service-locator.mts.html +240 -2328
  57. package/coverage/src/symbols/index.html +1 -1
  58. package/coverage/src/symbols/index.mts.html +1 -1
  59. package/coverage/src/symbols/injectable-token.mts.html +1 -1
  60. package/coverage/src/testing/index.html +131 -0
  61. package/coverage/src/testing/index.mts.html +88 -0
  62. package/coverage/src/testing/test-container.mts.html +445 -0
  63. package/coverage/src/token-processor.mts.html +607 -0
  64. package/coverage/src/utils/defer.mts.html +28 -214
  65. package/coverage/src/utils/get-injectable-token.mts.html +7 -7
  66. package/coverage/src/utils/get-injectors.mts.html +99 -99
  67. package/coverage/src/utils/index.html +15 -15
  68. package/coverage/src/utils/index.mts.html +4 -7
  69. package/coverage/src/utils/types.mts.html +1 -1
  70. package/docs/injectable.md +51 -11
  71. package/docs/scopes.md +63 -29
  72. package/lib/_tsup-dts-rollup.d.mts +447 -212
  73. package/lib/_tsup-dts-rollup.d.ts +447 -212
  74. package/lib/chunk-44F3LXW5.mjs +2043 -0
  75. package/lib/chunk-44F3LXW5.mjs.map +1 -0
  76. package/lib/index.d.mts +6 -4
  77. package/lib/index.d.ts +6 -4
  78. package/lib/index.js +1199 -773
  79. package/lib/index.js.map +1 -1
  80. package/lib/index.mjs +4 -1599
  81. package/lib/index.mjs.map +1 -1
  82. package/lib/testing/index.d.mts +2 -0
  83. package/lib/testing/index.d.ts +2 -0
  84. package/lib/testing/index.js +2060 -0
  85. package/lib/testing/index.js.map +1 -0
  86. package/lib/testing/index.mjs +73 -0
  87. package/lib/testing/index.mjs.map +1 -0
  88. package/package.json +11 -1
  89. package/src/__tests__/container.spec.mts +47 -13
  90. package/src/__tests__/errors.spec.mts +53 -27
  91. package/src/__tests__/injectable.spec.mts +73 -0
  92. package/src/__tests__/request-scope.spec.mts +0 -2
  93. package/src/__tests__/service-locator-manager.spec.mts +12 -82
  94. package/src/__tests__/service-locator.spec.mts +1009 -1
  95. package/src/__type-tests__/inject.spec-d.mts +30 -7
  96. package/src/__type-tests__/injectable.spec-d.mts +76 -37
  97. package/src/base-instance-holder-manager.mts +2 -9
  98. package/src/container.mts +70 -10
  99. package/src/decorators/injectable.decorator.mts +29 -5
  100. package/src/errors/di-error.mts +69 -0
  101. package/src/errors/index.mts +9 -7
  102. package/src/injection-token.mts +1 -0
  103. package/src/injector.mts +2 -0
  104. package/src/instance-resolver.mts +559 -0
  105. package/src/request-context-holder.mts +0 -2
  106. package/src/request-context-manager.mts +149 -0
  107. package/src/service-invalidator.mts +429 -0
  108. package/src/service-locator-instance-holder.mts +0 -4
  109. package/src/service-locator-manager.mts +10 -40
  110. package/src/service-locator.mts +86 -782
  111. package/src/testing/README.md +80 -0
  112. package/src/testing/__tests__/test-container.spec.mts +173 -0
  113. package/src/testing/index.mts +1 -0
  114. package/src/testing/test-container.mts +120 -0
  115. package/src/token-processor.mts +174 -0
  116. package/src/utils/get-injectors.mts +161 -24
  117. package/src/utils/index.mts +0 -1
  118. package/src/utils/types.mts +12 -8
  119. package/tsup.config.mts +1 -1
  120. package/src/__tests__/defer.spec.mts +0 -166
  121. package/src/errors/errors.enum.mts +0 -8
  122. package/src/errors/factory-not-found.mts +0 -8
  123. package/src/errors/factory-token-not-resolved.mts +0 -10
  124. package/src/errors/instance-destroying.mts +0 -8
  125. package/src/errors/instance-expired.mts +0 -8
  126. package/src/errors/instance-not-found.mts +0 -8
  127. package/src/errors/unknown-error.mts +0 -15
  128. package/src/utils/defer.mts +0 -73
@@ -68,11 +68,10 @@ declare abstract class BaseInstanceHolderManager {
68
68
  * @param type The injectable type
69
69
  * @param scope The injectable scope
70
70
  * @param deps Optional set of dependencies
71
- * @param ttl Optional time-to-live in milliseconds (defaults to Infinity)
72
71
  * @returns A tuple containing the deferred promise and the holder
73
72
  */
74
- createCreatingHolder<Instance>(name: string, type: InjectableType, scope: InjectableScope, deps?: Set<string>, ttl?: number): [
75
- ReturnType<typeof createDeferred<[undefined, Instance]>>,
73
+ createCreatingHolder<Instance>(name: string, type: InjectableType, scope: InjectableScope, deps?: Set<string>): [
74
+ ReturnType<typeof Promise.withResolvers<[undefined, Instance]>>,
76
75
  ServiceLocatorInstanceHolder<Instance>
77
76
  ];
78
77
  /**
@@ -83,10 +82,9 @@ declare abstract class BaseInstanceHolderManager {
83
82
  * @param type The injectable type
84
83
  * @param scope The injectable scope
85
84
  * @param deps Optional set of dependencies
86
- * @param ttl Optional time-to-live in milliseconds (defaults to Infinity)
87
85
  * @returns The created holder
88
86
  */
89
- protected createCreatedHolder<Instance>(name: string, instance: Instance, type: InjectableType, scope: InjectableScope, deps?: Set<string>, ttl?: number): ServiceLocatorInstanceHolder<Instance>;
87
+ protected createCreatedHolder<Instance>(name: string, instance: Instance, type: InjectableType, scope: InjectableScope, deps?: Set<string>): ServiceLocatorInstanceHolder<Instance>;
90
88
  /**
91
89
  * Gets all holder names currently managed.
92
90
  */
@@ -145,11 +143,27 @@ declare type ClassTypeWithOptionalArgument<Arg> = new (arg?: Arg) => any;
145
143
  export { ClassTypeWithOptionalArgument }
146
144
  export { ClassTypeWithOptionalArgument as ClassTypeWithOptionalArgument_alias_1 }
147
145
 
146
+ declare type ClassTypeWithoutArguments = new () => any;
147
+ export { ClassTypeWithoutArguments }
148
+ export { ClassTypeWithoutArguments as ClassTypeWithoutArguments_alias_1 }
149
+
150
+ export declare interface ClearAllOptions {
151
+ /** Whether to also clear request contexts (default: true) */
152
+ clearRequestContexts?: boolean;
153
+ /** Maximum number of invalidation rounds to prevent infinite loops (default: 10) */
154
+ maxRounds?: number;
155
+ /** Whether to wait for all services to settle before starting (default: true) */
156
+ waitForSettlement?: boolean;
157
+ }
158
+
148
159
  /**
149
160
  * Container class that provides a simplified public API for dependency injection.
150
161
  * It wraps a ServiceLocator instance and provides convenient methods for getting instances.
151
162
  */
152
163
  declare class Container {
164
+ protected readonly registry: Registry;
165
+ protected readonly logger: Console | null;
166
+ protected readonly injectors: Injectors;
153
167
  private readonly serviceLocator;
154
168
  constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
155
169
  private registerSelf;
@@ -171,6 +185,19 @@ declare class Container {
171
185
  * Invalidates a service and its dependencies
172
186
  */
173
187
  invalidate(service: unknown): Promise<void>;
188
+ /**
189
+ * Gets a service holder by instance (reverse lookup)
190
+ */
191
+ private getHolderByInstance;
192
+ private getRequestHolderByInstance;
193
+ /**
194
+ * Checks if a service is registered in the container
195
+ */
196
+ isRegistered(token: any): boolean;
197
+ /**
198
+ * Disposes the container and cleans up all resources
199
+ */
200
+ dispose(): Promise<void>;
174
201
  /**
175
202
  * Waits for all pending operations to complete
176
203
  */
@@ -198,19 +225,15 @@ declare class Container {
198
225
  * @param requestId The request ID to set as current
199
226
  */
200
227
  setCurrentRequestContext(requestId: string): void;
228
+ /**
229
+ * Clears all instances and bindings from the container.
230
+ * This is useful for testing or resetting the container state.
231
+ */
232
+ clear(): Promise<void>;
201
233
  }
202
234
  export { Container }
203
235
  export { Container as Container_alias_1 }
204
236
 
205
- /**
206
- * Creates a new deferred promise.
207
- * @returns A new Deferred instance
208
- */
209
- declare function createDeferred<T>(): Deferred<T>;
210
- export { createDeferred }
211
- export { createDeferred as createDeferred_alias_1 }
212
- export { createDeferred as createDeferred_alias_2 }
213
-
214
237
  /**
215
238
  * Creates a new request context holder with the given parameters.
216
239
  */
@@ -255,57 +278,42 @@ declare class DefaultRequestContextHolder extends BaseInstanceHolderManager impl
255
278
  export { DefaultRequestContextHolder }
256
279
  export { DefaultRequestContextHolder as DefaultRequestContextHolder_alias_1 }
257
280
 
258
- /**
259
- * Creates a deferred promise that can be resolved or rejected externally.
260
- * This is useful for creating stub holders that can be fulfilled later.
261
- */
262
- declare class Deferred<T> {
263
- readonly promise: Promise<T>;
264
- private _resolve;
265
- private _reject;
266
- private _isResolved;
267
- private _isRejected;
268
- constructor();
269
- /**
270
- * Resolves the deferred promise with the given value.
271
- * @param value The value to resolve with
272
- * @throws Error if the promise has already been resolved or rejected
273
- */
274
- resolve(value: T): void;
275
- /**
276
- * Rejects the deferred promise with the given reason.
277
- * @param reason The reason for rejection
278
- * @throws Error if the promise has already been resolved or rejected
279
- */
280
- reject(reason?: any): void;
281
- /**
282
- * Returns true if the promise has been resolved.
283
- */
284
- get isResolved(): boolean;
285
- /**
286
- * Returns true if the promise has been rejected.
287
- */
288
- get isRejected(): boolean;
289
- /**
290
- * Returns true if the promise has been settled (resolved or rejected).
291
- */
292
- get isSettled(): boolean;
281
+ declare class DIError extends Error {
282
+ readonly code: DIErrorCode;
283
+ readonly context?: Record<string, unknown>;
284
+ constructor(code: DIErrorCode, message: string, context?: Record<string, unknown>);
285
+ static factoryNotFound(name: string): DIError;
286
+ static factoryTokenNotResolved(token: string | symbol | unknown): DIError;
287
+ static instanceNotFound(name: string): DIError;
288
+ static instanceDestroying(name: string): DIError;
289
+ static unknown(message: string | Error, context?: Record<string, unknown>): DIError;
293
290
  }
294
- export { Deferred }
295
- export { Deferred as Deferred_alias_1 }
296
- export { Deferred as Deferred_alias_2 }
297
-
298
- declare enum ErrorsEnum {
299
- InstanceExpired = "InstanceExpired",
291
+ export { DIError }
292
+ export { DIError as DIError_alias_1 }
293
+ export { DIError as DIError_alias_2 }
294
+ export { DIError as FactoryNotFound }
295
+ export { DIError as FactoryNotFound_alias_1 }
296
+ export { DIError as FactoryTokenNotResolved }
297
+ export { DIError as FactoryTokenNotResolved_alias_1 }
298
+ export { DIError as InstanceDestroying }
299
+ export { DIError as InstanceDestroying_alias_1 }
300
+ export { DIError as InstanceNotFound }
301
+ export { DIError as InstanceNotFound_alias_1 }
302
+ export { DIError as UnknownError }
303
+ export { DIError as UnknownError_alias_1 }
304
+
305
+ declare enum DIErrorCode {
306
+ FactoryNotFound = "FactoryNotFound",
307
+ FactoryTokenNotResolved = "FactoryTokenNotResolved",
300
308
  InstanceNotFound = "InstanceNotFound",
301
309
  InstanceDestroying = "InstanceDestroying",
302
- UnknownError = "UnknownError",
303
- FactoryNotFound = "FactoryNotFound",
304
- FactoryTokenNotResolved = "FactoryTokenNotResolved"
310
+ UnknownError = "UnknownError"
305
311
  }
306
- export { ErrorsEnum }
307
- export { ErrorsEnum as ErrorsEnum_alias_1 }
308
- export { ErrorsEnum as ErrorsEnum_alias_2 }
312
+ export { DIErrorCode }
313
+ export { DIErrorCode as DIErrorCode_alias_1 }
314
+ export { DIErrorCode as DIErrorCode_alias_2 }
315
+ export { DIErrorCode as ErrorsEnum }
316
+ export { DIErrorCode as ErrorsEnum_alias_1 }
309
317
 
310
318
  declare class EventEmitter<Events extends EventsConfig = {}> implements EventEmitterInterface<Events> {
311
319
  private listeners;
@@ -391,15 +399,6 @@ declare class FactoryInjectionToken<T, S extends InjectionTokenSchemaType> {
391
399
  export { FactoryInjectionToken }
392
400
  export { FactoryInjectionToken as FactoryInjectionToken_alias_1 }
393
401
 
394
- declare class FactoryNotFound extends Error {
395
- name: string;
396
- code: ErrorsEnum;
397
- constructor(name: string);
398
- }
399
- export { FactoryNotFound }
400
- export { FactoryNotFound as FactoryNotFound_alias_1 }
401
- export { FactoryNotFound as FactoryNotFound_alias_2 }
402
-
403
402
  declare interface FactoryOptions {
404
403
  scope?: InjectableScope;
405
404
  token?: InjectionToken<any, any>;
@@ -418,14 +417,6 @@ declare type FactoryRecord<Instance = any, Schema = any> = {
418
417
  export { FactoryRecord }
419
418
  export { FactoryRecord as FactoryRecord_alias_1 }
420
419
 
421
- declare class FactoryTokenNotResolved extends Error {
422
- code: ErrorsEnum;
423
- constructor(name: string | symbol | ClassType);
424
- }
425
- export { FactoryTokenNotResolved }
426
- export { FactoryTokenNotResolved as FactoryTokenNotResolved_alias_1 }
427
- export { FactoryTokenNotResolved as FactoryTokenNotResolved_alias_2 }
428
-
429
420
  declare function getInjectableToken<R>(target: ClassType): R extends {
430
421
  create(...args: any[]): infer V;
431
422
  } ? InjectionToken<V> : InjectionToken<R>;
@@ -446,16 +437,22 @@ declare const inject: Injectors['inject'];
446
437
  export { inject }
447
438
  export { inject as inject_alias_1 }
448
439
 
449
- declare function Injectable(): <T extends ClassType>(target: T, context?: ClassDecoratorContext) => T;
440
+ declare function Injectable(): <T extends ClassTypeWithoutArguments>(target: T, context?: ClassDecoratorContext) => T;
450
441
 
451
442
  declare function Injectable(options: {
452
443
  scope?: InjectableScope;
453
444
  registry: Registry;
454
- }): <T extends ClassType>(target: T, context?: ClassDecoratorContext) => T;
445
+ }): <T extends ClassTypeWithoutArguments>(target: T, context?: ClassDecoratorContext) => T;
455
446
 
456
447
  declare function Injectable(options: {
457
448
  scope: InjectableScope;
458
- }): <T extends ClassType>(target: T, context?: ClassDecoratorContext) => T;
449
+ }): <T extends ClassTypeWithoutArguments>(target: T, context?: ClassDecoratorContext) => T;
450
+
451
+ declare function Injectable<Schema extends InjectionTokenSchemaType>(options: {
452
+ scope?: InjectableScope;
453
+ schema: Schema;
454
+ registry?: Registry;
455
+ }): <T extends ClassTypeWithArgument<z.output<Schema>>>(target: T, context?: ClassDecoratorContext) => T;
459
456
 
460
457
  declare function Injectable<Type, Schema>(options: {
461
458
  scope?: InjectableScope;
@@ -473,6 +470,7 @@ export { Injectable as Injectable_alias_2 }
473
470
  declare interface InjectableOptions {
474
471
  scope?: InjectableScope;
475
472
  token?: InjectionToken<any, any>;
473
+ schema?: InjectionTokenSchemaType;
476
474
  registry?: Registry;
477
475
  }
478
476
  export { InjectableOptions }
@@ -537,18 +535,46 @@ export { InjectionTokenType }
537
535
  export { InjectionTokenType as InjectionTokenType_alias_1 }
538
536
 
539
537
  declare interface Injectors {
540
- asyncInject<T extends ClassType>(token: T): InstanceType<T> extends Factorable<infer R> ? Promise<R> : Promise<InstanceType<T>>;
538
+ asyncInject<T extends ClassTypeWithoutArguments>(token: T): InstanceType<T> extends Factorable<infer R> ? Promise<R> : Promise<InstanceType<T>>;
539
+ asyncInject<Args, T extends ClassTypeWithArgument<Args>>(token: T, args: Args): Promise<InstanceType<T>>;
540
+ asyncInject<Schema extends InjectionTokenSchemaType, R, T extends FactorableWithArgs<R, Schema>>(token: T, args: z.input<Schema>): Promise<R>;
541
541
  asyncInject<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): Promise<T>;
542
542
  asyncInject<T, S extends InjectionTokenSchemaType, R extends boolean>(token: InjectionToken<T, S, R>): R extends false ? Promise<T> : S extends ZodType<infer Type> ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}` : 'Error: Your token requires args';
543
543
  asyncInject<T>(token: InjectionToken<T, undefined>): Promise<T>;
544
544
  asyncInject<T>(token: BoundInjectionToken<T, any>): Promise<T>;
545
545
  asyncInject<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
546
- inject<T extends ClassType>(token: T): InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>;
546
+ inject<T extends ClassTypeWithoutArguments>(token: T): InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>;
547
+ inject<Args, T extends ClassTypeWithArgument<Args>>(token: T, args: Args): InstanceType<T>;
548
+ inject<Schema extends InjectionTokenSchemaType, R, T extends FactorableWithArgs<R, Schema>>(token: T, args: z.input<Schema>): R;
547
549
  inject<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): T;
548
550
  inject<T, S extends InjectionTokenSchemaType, R extends boolean>(token: InjectionToken<T, S, R>): R extends false ? T : S extends ZodType<infer Type> ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}` : 'Error: Your token requires args';
549
551
  inject<T>(token: InjectionToken<T, undefined>): T;
550
552
  inject<T>(token: BoundInjectionToken<T, any>): T;
551
553
  inject<T>(token: FactoryInjectionToken<T, any>): T;
554
+ /**
555
+ * Optional injection that returns null if the service fails to initialize
556
+ * or is not available. This is useful when you want to inject a service
557
+ * that may not be configured or may fail gracefully.
558
+ *
559
+ * @example
560
+ * ```ts
561
+ * class MyService {
562
+ * constructor() {
563
+ * const optionalService = optional(OptionalServiceToken)
564
+ * // optionalService will be null if initialization fails
565
+ * if (optionalService) {
566
+ * optionalService.doSomething()
567
+ * }
568
+ * }
569
+ * }
570
+ * ```
571
+ */
572
+ optional<T extends ClassType>(token: T): (InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>) | null;
573
+ optional<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): T | null;
574
+ optional<T, S extends InjectionTokenSchemaType, R extends boolean>(token: InjectionToken<T, S, R>): R extends false ? T | null : S extends ZodType<infer Type> ? `Error: Your token requires args: ${Join<UnionToArray<keyof Type>, ', '>}` : 'Error: Your token requires args';
575
+ optional<T>(token: InjectionToken<T, undefined>): T | null;
576
+ optional<T>(token: BoundInjectionToken<T, any>): T | null;
577
+ optional<T>(token: FactoryInjectionToken<T, any>): T | null;
552
578
  wrapSyncInit(cb: () => any): (injectState?: InjectState) => [any, Promise<any>[], InjectState];
553
579
  provideFactoryContext(context: FactoryContext | null): FactoryContext | null;
554
580
  }
@@ -556,44 +582,100 @@ export { Injectors }
556
582
  export { Injectors as Injectors_alias_1 }
557
583
  export { Injectors as Injectors_alias_2 }
558
584
 
585
+ declare type InjectRequest = {
586
+ token: InjectionToken<any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any> | ClassType;
587
+ promise: Promise<any>;
588
+ readonly result: any;
589
+ readonly error: Error | null;
590
+ };
591
+ export { InjectRequest }
592
+ export { InjectRequest as InjectRequest_alias_1 }
593
+ export { InjectRequest as InjectRequest_alias_2 }
594
+
559
595
  declare interface InjectState {
560
596
  currentIndex: number;
561
597
  isFrozen: boolean;
562
- requests: {
563
- token: InjectionToken<any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any> | ClassType;
564
- promise: Promise<any>;
565
- }[];
598
+ requests: InjectRequest[];
566
599
  }
567
600
  export { InjectState }
568
601
  export { InjectState as InjectState_alias_1 }
569
602
  export { InjectState as InjectState_alias_2 }
570
603
 
571
- declare class InstanceDestroying extends Error {
572
- name: string;
573
- code: ErrorsEnum;
574
- constructor(name: string);
575
- }
576
- export { InstanceDestroying }
577
- export { InstanceDestroying as InstanceDestroying_alias_1 }
578
- export { InstanceDestroying as InstanceDestroying_alias_2 }
579
-
580
- declare class InstanceExpired extends Error {
581
- name: string;
582
- code: ErrorsEnum;
583
- constructor(name: string);
584
- }
585
- export { InstanceExpired }
586
- export { InstanceExpired as InstanceExpired_alias_1 }
587
- export { InstanceExpired as InstanceExpired_alias_2 }
588
-
589
- declare class InstanceNotFound extends Error {
590
- name: string;
591
- code: ErrorsEnum;
592
- constructor(name: string);
604
+ /**
605
+ * InstanceResolver handles instance resolution, creation, and lifecycle management.
606
+ * Extracted from ServiceLocator to improve separation of concerns.
607
+ */
608
+ export declare class InstanceResolver {
609
+ private readonly registry;
610
+ private readonly manager;
611
+ private readonly serviceInstantiator;
612
+ private readonly tokenProcessor;
613
+ private readonly logger;
614
+ private readonly serviceLocator;
615
+ constructor(registry: Registry, manager: ServiceLocatorManager, serviceInstantiator: ServiceInstantiator, tokenProcessor: TokenProcessor, logger: (Console | null) | undefined, serviceLocator: ServiceLocator);
616
+ /**
617
+ * Resolves an instance for the given token and arguments.
618
+ */
619
+ resolveInstance(token: AnyInjectableType, args?: any, requestContext?: RequestContextHolder): Promise<[undefined, any] | [DIError]>;
620
+ /**
621
+ * Gets a synchronous instance (for sync operations).
622
+ */
623
+ getSyncInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: AnyInjectableType, args: Schema extends ZodObject ? z.input<Schema> : Schema extends ZodOptional<ZodObject> ? z.input<Schema> | undefined : undefined, currentRequestContext: RequestContextHolder | null): Instance | null;
624
+ /**
625
+ * Internal method to resolve token args and create instance name.
626
+ * Handles factory token resolution and validation.
627
+ */
628
+ private resolveTokenAndPrepareInstanceName;
629
+ /**
630
+ * Gets an instance by its instance name, handling all the logic after instance name creation.
631
+ */
632
+ private retrieveOrCreateInstanceByInstanceName;
633
+ /**
634
+ * Attempts to retrieve an existing instance, handling request-scoped and singleton instances.
635
+ * Returns null if no instance exists and a new one should be created.
636
+ */
637
+ private tryGetExistingInstance;
638
+ /**
639
+ * Attempts to get a request-scoped instance if applicable.
640
+ */
641
+ private tryGetRequestScopedInstance;
642
+ /**
643
+ * Attempts to get a singleton instance from the manager.
644
+ */
645
+ private tryGetSingletonInstance;
646
+ /**
647
+ * Waits for an instance holder to be ready and returns the appropriate result.
648
+ */
649
+ private waitForInstanceReady;
650
+ /**
651
+ * Creates a new instance for the given token and arguments.
652
+ */
653
+ private createNewInstance;
654
+ /**
655
+ * Instantiates a service from the registry using the service instantiator.
656
+ */
657
+ private instantiateServiceFromRegistry;
658
+ /**
659
+ * Handles the result of service instantiation.
660
+ */
661
+ private handleInstantiationResult;
662
+ /**
663
+ * Handles successful service instantiation.
664
+ */
665
+ private handleInstantiationSuccess;
666
+ /**
667
+ * Handles service instantiation errors.
668
+ */
669
+ private handleInstantiationError;
670
+ /**
671
+ * Stores an instance holder based on its scope.
672
+ */
673
+ private storeInstanceByScope;
674
+ /**
675
+ * Creates a factory context for dependency injection during service instantiation.
676
+ */
677
+ private createFactoryContext;
593
678
  }
594
- export { InstanceNotFound }
595
- export { InstanceNotFound as InstanceNotFound_alias_1 }
596
- export { InstanceNotFound as InstanceNotFound_alias_2 }
597
679
 
598
680
  declare type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
599
681
  export { IsUnion }
@@ -619,6 +701,10 @@ export { OnServiceInit }
619
701
  export { OnServiceInit as OnServiceInit_alias_1 }
620
702
  export { OnServiceInit as OnServiceInit_alias_2 }
621
703
 
704
+ declare const optional: Injectors['optional'];
705
+ export { optional }
706
+ export { optional as optional_alias_1 }
707
+
622
708
  declare type OptionalInjectionTokenSchemaType = ZodOptional<ZodObject> | ZodOptional<ZodRecord>;
623
709
  export { OptionalInjectionTokenSchemaType }
624
710
  export { OptionalInjectionTokenSchemaType as OptionalInjectionTokenSchemaType_alias_1 }
@@ -718,6 +804,49 @@ declare interface RequestContextHolder {
718
804
  export { RequestContextHolder }
719
805
  export { RequestContextHolder as RequestContextHolder_alias_1 }
720
806
 
807
+ /**
808
+ * RequestContextManager handles request context lifecycle management.
809
+ * Extracted from ServiceLocator to improve separation of concerns.
810
+ */
811
+ export declare class RequestContextManager {
812
+ private readonly logger;
813
+ private readonly requestContexts;
814
+ private currentRequestContext;
815
+ constructor(logger?: Console | null);
816
+ /**
817
+ * Begins a new request context with the given parameters.
818
+ * @param requestId Unique identifier for this request
819
+ * @param metadata Optional metadata for the request
820
+ * @param priority Priority for resolution (higher = more priority)
821
+ * @returns The created request context holder
822
+ */
823
+ beginRequest(requestId: string, metadata?: Record<string, any>, priority?: number): RequestContextHolder;
824
+ /**
825
+ * Ends a request context and cleans up all associated instances.
826
+ * @param requestId The request ID to end
827
+ */
828
+ endRequest(requestId: string): Promise<void>;
829
+ /**
830
+ * Gets the current request context.
831
+ * @returns The current request context holder or null
832
+ */
833
+ getCurrentRequestContext(): RequestContextHolder | null;
834
+ /**
835
+ * Sets the current request context.
836
+ * @param requestId The request ID to set as current
837
+ */
838
+ setCurrentRequestContext(requestId: string): void;
839
+ /**
840
+ * Gets all request contexts.
841
+ * @returns Map of request contexts
842
+ */
843
+ getRequestContexts(): Map<string, RequestContextHolder>;
844
+ /**
845
+ * Clears all request contexts.
846
+ */
847
+ clearAllRequestContexts(): Promise<void>;
848
+ }
849
+
721
850
  /**
722
851
  * ServiceInstantiator handles the instantiation of services based on registry records.
723
852
  * It replaces the hard-coded logic in Injectable and Factory decorators.
@@ -753,138 +882,155 @@ declare class ServiceInstantiator {
753
882
  export { ServiceInstantiator }
754
883
  export { ServiceInstantiator as ServiceInstantiator_alias_1 }
755
884
 
756
- declare class ServiceLocator {
757
- private readonly registry;
758
- private readonly logger;
759
- private readonly injectors;
760
- private readonly eventBus;
885
+ /**
886
+ * ServiceInvalidator handles service invalidation, cleanup, and graceful clearing.
887
+ * Extracted from ServiceLocator to improve separation of concerns.
888
+ */
889
+ export declare class ServiceInvalidator {
761
890
  private readonly manager;
762
- private readonly serviceInstantiator;
763
- private readonly requestContexts;
764
- private currentRequestContext;
765
- constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
766
- getEventBus(): ServiceLocatorEventBus;
767
- getManager(): ServiceLocatorManager;
768
- getInstanceIdentifier(token: AnyInjectableType, args?: any): string;
769
- getInstance(token: AnyInjectableType, args?: any, onPrepare?: (data: {
770
- instanceName: string;
771
- actualToken: InjectionTokenType;
772
- validatedArgs?: any;
773
- }) => void): Promise<any[]>;
774
- getOrThrowInstance<Instance>(token: AnyInjectableType, args: any): Promise<Instance>;
775
- getSyncInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: AnyInjectableType, args: Schema extends ZodObject ? z.input<Schema> : Schema extends ZodOptional<ZodObject> ? z.input<Schema> | undefined : undefined): Instance | null;
776
- invalidate(service: string, round?: number): Promise<any>;
891
+ private readonly requestContextManager;
892
+ private readonly eventBus;
893
+ private readonly logger;
894
+ constructor(manager: ServiceLocatorManager, requestContextManager: RequestContextManager, eventBus: ServiceLocatorEventBus, logger?: Console | null);
777
895
  /**
778
- * Invalidates a single holder based on its current status.
896
+ * Invalidates a service and all its dependencies.
779
897
  */
780
- private invalidateHolder;
898
+ invalidate(service: string, round?: number): Promise<any>;
781
899
  /**
782
- * Destroys a holder and cleans up its resources.
900
+ * Gracefully clears all services in the ServiceLocator using invalidation logic.
901
+ * This method respects service dependencies and ensures proper cleanup order.
902
+ * Services that depend on others will be invalidated first, then their dependencies.
783
903
  */
784
- private destroyHolder;
785
- ready(): Promise<void>;
904
+ clearAll(options?: ClearAllOptions): Promise<void>;
786
905
  /**
787
- * Waits for a holder to settle (either created, destroyed, or error state).
906
+ * Waits for all services to settle (either created, destroyed, or error state).
788
907
  */
789
- private waitForHolderToSettle;
908
+ ready(): Promise<void>;
790
909
  /**
791
- * Begins a new request context with the given parameters.
792
- * @param requestId Unique identifier for this request
793
- * @param metadata Optional metadata for the request
794
- * @param priority Priority for resolution (higher = more priority)
795
- * @returns The created request context holder
910
+ * Invalidates a single holder based on its current status.
796
911
  */
797
- beginRequest(requestId: string, metadata?: Record<string, any>, priority?: number): RequestContextHolder;
912
+ private invalidateHolder;
798
913
  /**
799
- * Ends a request context and cleans up all associated instances.
800
- * @param requestId The request ID to end
914
+ * Invalidates a request-scoped holder based on its current status.
801
915
  */
802
- endRequest(requestId: string): Promise<void>;
916
+ private invalidateRequestHolder;
803
917
  /**
804
- * Gets the current request context.
805
- * @returns The current request context holder or null
918
+ * Common invalidation logic for holders based on their status.
806
919
  */
807
- getCurrentRequestContext(): RequestContextHolder | null;
920
+ private invalidateHolderByStatus;
808
921
  /**
809
- * Sets the current request context.
810
- * @param requestId The request ID to set as current
922
+ * Destroys a holder and cleans up its resources.
811
923
  */
812
- setCurrentRequestContext(requestId: string): void;
924
+ private destroyHolder;
813
925
  /**
814
- * Validates and resolves token arguments, handling factory token resolution and validation.
926
+ * Destroys a request-scoped holder and cleans up its resources.
815
927
  */
816
- private validateAndResolveTokenArgs;
928
+ private destroyRequestHolder;
817
929
  /**
818
- * Internal method to resolve token args and create instance name.
819
- * Handles factory token resolution and validation.
930
+ * Common destroy logic for holders with customizable cleanup.
820
931
  */
821
- private resolveTokenAndPrepareInstanceName;
932
+ private destroyHolderWithCleanup;
822
933
  /**
823
- * Gets an instance by its instance name, handling all the logic after instance name creation.
934
+ * Waits for a holder to settle (either created, destroyed, or error state).
824
935
  */
825
- private retrieveOrCreateInstanceByInstanceName;
936
+ private waitForHolderToSettle;
826
937
  /**
827
- * Attempts to retrieve an existing instance, handling request-scoped and singleton instances.
828
- * Returns null if no instance exists and a new one should be created.
938
+ * Clears services with dependency awareness, ensuring proper cleanup order.
939
+ * Services with no dependencies are cleared first, then services that depend on them.
829
940
  */
830
- private tryGetExistingInstance;
941
+ private clearServicesWithDependencyAwareness;
831
942
  /**
832
- * Attempts to get a request-scoped instance if applicable.
943
+ * Finds services that are ready to be cleared in the current round.
944
+ * A service is ready if all its dependencies have already been cleared.
833
945
  */
834
- private tryGetRequestScopedInstance;
946
+ private findServicesReadyForClearing;
835
947
  /**
836
- * Attempts to get a singleton instance from the manager.
948
+ * Force clears services that couldn't be cleared through normal dependency resolution.
949
+ * This handles edge cases like circular dependencies.
837
950
  */
838
- private tryGetSingletonInstance;
951
+ private forceClearServices;
839
952
  /**
840
- * Waits for an instance holder to be ready and returns the appropriate result.
953
+ * Gets all service names currently managed by the ServiceLocator.
841
954
  */
842
- private waitForInstanceReady;
955
+ private getAllServiceNames;
843
956
  /**
844
957
  * Emits events to listeners for instance lifecycle events.
845
958
  */
846
959
  private emitInstanceEvent;
960
+ }
961
+
962
+ declare class ServiceLocator {
963
+ private readonly registry;
964
+ private readonly logger;
965
+ private readonly injectors;
966
+ private readonly eventBus;
967
+ private readonly manager;
968
+ private readonly serviceInstantiator;
969
+ private readonly tokenProcessor;
970
+ private readonly requestContextManager;
971
+ private readonly serviceInvalidator;
972
+ private readonly instanceResolver;
973
+ constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
974
+ getEventBus(): ServiceLocatorEventBus;
975
+ getManager(): ServiceLocatorManager;
976
+ getRequestContexts(): Map<string, RequestContextHolder>;
977
+ getRequestContextManager(): RequestContextManager;
978
+ getServiceInvalidator(): ServiceInvalidator;
979
+ getInstanceIdentifier(token: AnyInjectableType, args?: any): string;
980
+ getInstance(token: AnyInjectableType, args?: any, onPrepare?: (data: {
981
+ instanceName: string;
982
+ actualToken: any;
983
+ validatedArgs?: any;
984
+ }) => void): Promise<any[]>;
985
+ getOrThrowInstance<Instance>(token: AnyInjectableType, args: any): Promise<Instance>;
986
+ getSyncInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: AnyInjectableType, args: Schema extends ZodObject ? z.input<Schema> : Schema extends ZodOptional<ZodObject> ? z.input<Schema> | undefined : undefined): Instance | null;
987
+ invalidate(service: string, round?: number): Promise<any>;
847
988
  /**
848
- * Creates a new instance for the given token and arguments.
849
- */
850
- private createNewInstance;
851
- /**
852
- * Instantiates a service from the registry using the service instantiator.
853
- */
854
- private instantiateServiceFromRegistry;
855
- /**
856
- * Handles the result of service instantiation.
989
+ * Gracefully clears all services in the ServiceLocator using invalidation logic.
990
+ * This method respects service dependencies and ensures proper cleanup order.
991
+ * Services that depend on others will be invalidated first, then their dependencies.
992
+ *
993
+ * @param options Optional configuration for the clearing process
994
+ * @returns Promise that resolves when all services have been cleared
857
995
  */
858
- private handleInstantiationResult;
996
+ clearAll(options?: ClearAllOptions): Promise<void>;
859
997
  /**
860
- * Handles successful service instantiation.
998
+ * Begins a new request context with the given parameters.
999
+ * @param requestId Unique identifier for this request
1000
+ * @param metadata Optional metadata for the request
1001
+ * @param priority Priority for resolution (higher = more priority)
1002
+ * @returns The created request context holder
861
1003
  */
862
- private handleInstantiationSuccess;
1004
+ beginRequest(requestId: string, metadata?: Record<string, any>, priority?: number): RequestContextHolder;
863
1005
  /**
864
- * Handles service instantiation errors.
1006
+ * Ends a request context and cleans up all associated instances.
1007
+ * @param requestId The request ID to end
865
1008
  */
866
- private handleInstantiationError;
1009
+ endRequest(requestId: string): Promise<void>;
867
1010
  /**
868
- * Stores an instance holder based on its scope.
1011
+ * Gets the current request context.
1012
+ * @returns The current request context holder or null
869
1013
  */
870
- private storeInstanceByScope;
1014
+ getCurrentRequestContext(): RequestContextHolder | null;
871
1015
  /**
872
- * Tries to get a pre-prepared instance from request contexts.
1016
+ * Sets the current request context.
1017
+ * @param requestId The request ID to set as current
873
1018
  */
874
- private tryGetPrePreparedInstance;
1019
+ setCurrentRequestContext(requestId: string): void;
875
1020
  /**
876
- * Creates a factory context for dependency injection during service instantiation.
877
- * @param contextHolder Optional request context holder for priority-based resolution
1021
+ * Waits for all services to settle (either created, destroyed, or error state).
878
1022
  */
879
- private createFactoryContext;
1023
+ ready(): Promise<void>;
880
1024
  /**
881
- * Generates a unique instance name based on token and arguments.
1025
+ * Helper method for TokenProcessor to access pre-prepared instances.
1026
+ * This is needed for the factory context creation.
882
1027
  */
883
- private generateInstanceName;
1028
+ tryGetPrePreparedInstance(instanceName: string, contextHolder: RequestContextHolder | undefined, deps: Set<string>): any;
884
1029
  /**
885
- * Formats a single argument value for instance name generation.
1030
+ * Helper method for InstanceResolver to generate instance names.
1031
+ * This is needed for the factory context creation.
886
1032
  */
887
- private formatArgValue;
1033
+ generateInstanceName(token: any, args: any): string;
888
1034
  }
889
1035
  export { ServiceLocator }
890
1036
  export { ServiceLocator as ServiceLocator_alias_1 }
@@ -922,7 +1068,6 @@ declare interface ServiceLocatorInstanceHolderCreated<Instance> {
922
1068
  deps: Set<string>;
923
1069
  destroyListeners: ServiceLocatorInstanceDestroyListener[];
924
1070
  createdAt: number;
925
- ttl: number;
926
1071
  }
927
1072
  export { ServiceLocatorInstanceHolderCreated }
928
1073
  export { ServiceLocatorInstanceHolderCreated as ServiceLocatorInstanceHolderCreated_alias_1 }
@@ -938,7 +1083,6 @@ declare interface ServiceLocatorInstanceHolderCreating<Instance> {
938
1083
  deps: Set<string>;
939
1084
  destroyListeners: ServiceLocatorInstanceDestroyListener[];
940
1085
  createdAt: number;
941
- ttl: number;
942
1086
  }
943
1087
  export { ServiceLocatorInstanceHolderCreating }
944
1088
  export { ServiceLocatorInstanceHolderCreating as ServiceLocatorInstanceHolderCreating_alias_1 }
@@ -954,7 +1098,6 @@ declare interface ServiceLocatorInstanceHolderDestroying<Instance> {
954
1098
  deps: Set<string>;
955
1099
  destroyListeners: ServiceLocatorInstanceDestroyListener[];
956
1100
  createdAt: number;
957
- ttl: number;
958
1101
  }
959
1102
  export { ServiceLocatorInstanceHolderDestroying }
960
1103
  export { ServiceLocatorInstanceHolderDestroying as ServiceLocatorInstanceHolderDestroying_alias_1 }
@@ -970,7 +1113,6 @@ declare interface ServiceLocatorInstanceHolderError {
970
1113
  deps: Set<string>;
971
1114
  destroyListeners: ServiceLocatorInstanceDestroyListener[];
972
1115
  createdAt: number;
973
- ttl: number;
974
1116
  }
975
1117
  export { ServiceLocatorInstanceHolderError }
976
1118
  export { ServiceLocatorInstanceHolderError as ServiceLocatorInstanceHolderError_alias_1 }
@@ -986,9 +1128,9 @@ export { ServiceLocatorInstanceHolderStatus as ServiceLocatorInstanceHolderStatu
986
1128
 
987
1129
  declare class ServiceLocatorManager extends BaseInstanceHolderManager {
988
1130
  constructor(logger?: Console | null);
989
- get(name: string): [InstanceExpired | InstanceDestroying, ServiceLocatorInstanceHolder] | [InstanceNotFound] | [undefined, ServiceLocatorInstanceHolder];
1131
+ get(name: string): [DIError, ServiceLocatorInstanceHolder] | [DIError] | [undefined, ServiceLocatorInstanceHolder];
990
1132
  set(name: string, holder: ServiceLocatorInstanceHolder): void;
991
- has(name: string): [InstanceExpired | InstanceDestroying] | [undefined, boolean];
1133
+ has(name: string): [DIError] | [undefined, boolean];
992
1134
  /**
993
1135
  * Creates a new holder with Created status and an actual instance.
994
1136
  * This is useful for creating holders that already have their instance ready.
@@ -997,10 +1139,9 @@ declare class ServiceLocatorManager extends BaseInstanceHolderManager {
997
1139
  * @param type The injectable type
998
1140
  * @param scope The injectable scope
999
1141
  * @param deps Optional set of dependencies
1000
- * @param ttl Optional time-to-live in milliseconds (defaults to Infinity)
1001
1142
  * @returns The created holder
1002
1143
  */
1003
- storeCreatedHolder<Instance>(name: string, instance: Instance, type: InjectableType, scope: InjectableScope, deps?: Set<string>, ttl?: number): ServiceLocatorInstanceHolder<Instance>;
1144
+ storeCreatedHolder<Instance>(name: string, instance: Instance, type: InjectableType, scope: InjectableScope, deps?: Set<string>): ServiceLocatorInstanceHolder<Instance>;
1004
1145
  }
1005
1146
  export { ServiceLocatorManager }
1006
1147
  export { ServiceLocatorManager as ServiceLocatorManager_alias_1 }
@@ -1017,6 +1158,109 @@ export declare const test4: {
1017
1158
 
1018
1159
  export declare const test5: object;
1019
1160
 
1161
+ /**
1162
+ * A binding builder for the TestContainer that allows chaining binding operations.
1163
+ */
1164
+ declare class TestBindingBuilder<T> {
1165
+ private readonly container;
1166
+ private readonly token;
1167
+ constructor(container: TestContainer, token: InjectionToken<T, any>);
1168
+ /**
1169
+ * Binds the token to a specific value.
1170
+ * This is useful for testing with mock values or constants.
1171
+ * @param value The value to bind to the token
1172
+ */
1173
+ toValue(value: T): TestContainer;
1174
+ /**
1175
+ * Binds the token to a class constructor.
1176
+ * @param target The class constructor to bind to
1177
+ */
1178
+ toClass(target: ClassType): TestContainer;
1179
+ }
1180
+ export { TestBindingBuilder }
1181
+ export { TestBindingBuilder as TestBindingBuilder_alias_1 }
1182
+
1183
+ /**
1184
+ * TestContainer extends the base Container with additional methods useful for testing.
1185
+ * It provides a simplified API for binding values and classes during test setup.
1186
+ */
1187
+ declare class TestContainer extends Container {
1188
+ constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
1189
+ /**
1190
+ * Creates a binding builder for the given token.
1191
+ * This allows chaining binding operations like bind(Token).toValue(value).
1192
+ * @param token The injection token to bind
1193
+ * @returns A TestBindingBuilder for chaining binding operations
1194
+ */
1195
+ bind<T>(token: ClassType): TestBindingBuilder<T>;
1196
+ bind<T>(token: InjectionToken<T, any>): TestBindingBuilder<T>;
1197
+ /**
1198
+ * Binds a value directly to a token.
1199
+ * This is a convenience method equivalent to bind(token).toValue(value).
1200
+ * @param token The injection token to bind
1201
+ * @param value The value to bind to the token
1202
+ * @returns The TestContainer instance for chaining
1203
+ */
1204
+ bindValue<T>(token: ClassType, value: T): TestContainer;
1205
+ bindValue<T>(token: InjectionToken<T, any>, value: T): TestContainer;
1206
+ /**
1207
+ * Binds a class to a token.
1208
+ * This is a convenience method equivalent to bind(token).toClass(target).
1209
+ * @param token The injection token to bind
1210
+ * @param target The class constructor to bind to
1211
+ * @returns The TestContainer instance for chaining
1212
+ */
1213
+ bindClass(token: ClassType, target: ClassType): TestContainer;
1214
+ bindClass<T>(token: InjectionToken<T, any>, target: ClassType): TestContainer;
1215
+ /**
1216
+ * Creates a new TestContainer instance with the same configuration.
1217
+ * This is useful for creating isolated test containers.
1218
+ * @returns A new TestContainer instance
1219
+ */
1220
+ createChild(): TestContainer;
1221
+ }
1222
+ export { TestContainer }
1223
+ export { TestContainer as TestContainer_alias_1 }
1224
+
1225
+ /**
1226
+ * TokenProcessor handles token validation, resolution, and instance name generation.
1227
+ * Extracted from ServiceLocator to improve separation of concerns.
1228
+ */
1229
+ export declare class TokenProcessor {
1230
+ private readonly logger;
1231
+ constructor(logger?: Console | null);
1232
+ /**
1233
+ * Validates and resolves token arguments, handling factory token resolution and validation.
1234
+ */
1235
+ validateAndResolveTokenArgs(token: AnyInjectableType, args?: any): [
1236
+ DIError | undefined,
1237
+ {
1238
+ actualToken: InjectionTokenType;
1239
+ validatedArgs?: any;
1240
+ }
1241
+ ];
1242
+ /**
1243
+ * Generates a unique instance name based on token and arguments.
1244
+ */
1245
+ generateInstanceName(token: InjectionTokenType, args: any): string;
1246
+ /**
1247
+ * Formats a single argument value for instance name generation.
1248
+ */
1249
+ formatArgValue(value: any): string;
1250
+ /**
1251
+ * Creates a factory context for dependency injection during service instantiation.
1252
+ * @param serviceLocator Reference to the service locator for dependency resolution
1253
+ */
1254
+ createFactoryContext(serviceLocator: ServiceLocator): FactoryContext & {
1255
+ getDestroyListeners: () => (() => void)[];
1256
+ deps: Set<string>;
1257
+ };
1258
+ /**
1259
+ * Tries to get a pre-prepared instance from request contexts.
1260
+ */
1261
+ tryGetPrePreparedInstance(instanceName: string, contextHolder: RequestContextHolder | undefined, deps: Set<string>, currentRequestContext: RequestContextHolder | null): any;
1262
+ }
1263
+
1020
1264
  declare type UnionToArray<T, A extends unknown[] = []> = IsUnion<T> extends true ? UnionToArray<Exclude<T, PopUnion<T>>, [PopUnion<T>, ...A]> : [T, ...A];
1021
1265
  export { UnionToArray }
1022
1266
  export { UnionToArray as UnionToArray_alias_1 }
@@ -1032,15 +1276,6 @@ export { UnionToOvlds }
1032
1276
  export { UnionToOvlds as UnionToOvlds_alias_1 }
1033
1277
  export { UnionToOvlds as UnionToOvlds_alias_2 }
1034
1278
 
1035
- declare class UnknownError extends Error {
1036
- code: ErrorsEnum;
1037
- parent?: Error;
1038
- constructor(message: string | Error);
1039
- }
1040
- export { UnknownError }
1041
- export { UnknownError as UnknownError_alias_1 }
1042
- export { UnknownError as UnknownError_alias_2 }
1043
-
1044
1279
  declare const wrapSyncInit: Injectors['wrapSyncInit'];
1045
1280
  export { wrapSyncInit }
1046
1281
  export { wrapSyncInit as wrapSyncInit_alias_1 }