@navios/di 0.4.2 → 0.5.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/README.md +211 -1
- package/coverage/clover.xml +1912 -1277
- package/coverage/coverage-final.json +37 -28
- package/coverage/docs/examples/basic-usage.mts.html +1 -1
- package/coverage/docs/examples/factory-pattern.mts.html +1 -1
- package/coverage/docs/examples/index.html +1 -1
- package/coverage/docs/examples/injection-tokens.mts.html +1 -1
- package/coverage/docs/examples/request-scope-example.mts.html +1 -1
- package/coverage/docs/examples/service-lifecycle.mts.html +1 -1
- package/coverage/index.html +71 -41
- package/coverage/lib/_tsup-dts-rollup.d.mts.html +682 -43
- package/coverage/lib/index.d.mts.html +7 -4
- package/coverage/lib/index.html +5 -5
- package/coverage/lib/testing/index.d.mts.html +91 -0
- package/coverage/lib/testing/index.html +116 -0
- package/coverage/src/base-instance-holder-manager.mts.html +589 -0
- package/coverage/src/container.mts.html +257 -74
- package/coverage/src/decorators/factory.decorator.mts.html +1 -1
- package/coverage/src/decorators/index.html +1 -1
- package/coverage/src/decorators/index.mts.html +1 -1
- package/coverage/src/decorators/injectable.decorator.mts.html +20 -20
- package/coverage/src/enums/index.html +1 -1
- package/coverage/src/enums/index.mts.html +1 -1
- package/coverage/src/enums/injectable-scope.enum.mts.html +1 -1
- package/coverage/src/enums/injectable-type.enum.mts.html +1 -1
- package/coverage/src/errors/di-error.mts.html +292 -0
- package/coverage/src/errors/errors.enum.mts.html +30 -21
- package/coverage/src/errors/factory-not-found.mts.html +31 -22
- package/coverage/src/errors/factory-token-not-resolved.mts.html +29 -26
- package/coverage/src/errors/index.html +56 -41
- package/coverage/src/errors/index.mts.html +15 -9
- package/coverage/src/errors/instance-destroying.mts.html +31 -22
- package/coverage/src/errors/instance-expired.mts.html +31 -22
- package/coverage/src/errors/instance-not-found.mts.html +31 -22
- package/coverage/src/errors/unknown-error.mts.html +31 -43
- package/coverage/src/event-emitter.mts.html +14 -14
- package/coverage/src/factory-context.mts.html +1 -1
- package/coverage/src/index.html +121 -46
- package/coverage/src/index.mts.html +7 -4
- package/coverage/src/injection-token.mts.html +28 -28
- package/coverage/src/injector.mts.html +1 -1
- package/coverage/src/instance-resolver.mts.html +1762 -0
- package/coverage/src/interfaces/factory.interface.mts.html +1 -1
- package/coverage/src/interfaces/index.html +1 -1
- package/coverage/src/interfaces/index.mts.html +1 -1
- package/coverage/src/interfaces/on-service-destroy.interface.mts.html +1 -1
- package/coverage/src/interfaces/on-service-init.interface.mts.html +1 -1
- package/coverage/src/registry.mts.html +28 -28
- package/coverage/src/request-context-holder.mts.html +183 -102
- package/coverage/src/request-context-manager.mts.html +532 -0
- package/coverage/src/service-instantiator.mts.html +49 -49
- package/coverage/src/service-invalidator.mts.html +1372 -0
- package/coverage/src/service-locator-event-bus.mts.html +48 -48
- package/coverage/src/service-locator-instance-holder.mts.html +2 -14
- package/coverage/src/service-locator-manager.mts.html +71 -335
- package/coverage/src/service-locator.mts.html +240 -2328
- package/coverage/src/symbols/index.html +1 -1
- package/coverage/src/symbols/index.mts.html +1 -1
- package/coverage/src/symbols/injectable-token.mts.html +1 -1
- package/coverage/src/testing/index.html +131 -0
- package/coverage/src/testing/index.mts.html +88 -0
- package/coverage/src/testing/test-container.mts.html +445 -0
- package/coverage/src/token-processor.mts.html +607 -0
- package/coverage/src/utils/defer.mts.html +28 -214
- package/coverage/src/utils/get-injectable-token.mts.html +7 -7
- package/coverage/src/utils/get-injectors.mts.html +99 -99
- package/coverage/src/utils/index.html +15 -15
- package/coverage/src/utils/index.mts.html +4 -7
- package/coverage/src/utils/types.mts.html +1 -1
- package/docs/injectable.md +51 -11
- package/docs/scopes.md +63 -29
- package/lib/_tsup-dts-rollup.d.mts +376 -213
- package/lib/_tsup-dts-rollup.d.ts +376 -213
- package/lib/{chunk-3NLYPYBY.mjs → chunk-2M576LCC.mjs} +1024 -608
- package/lib/chunk-2M576LCC.mjs.map +1 -0
- package/lib/index.d.mts +6 -4
- package/lib/index.d.ts +6 -4
- package/lib/index.js +1189 -773
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +2 -2
- package/lib/testing/index.js +1261 -843
- package/lib/testing/index.js.map +1 -1
- package/lib/testing/index.mjs +1 -1
- package/package.json +4 -4
- package/src/__tests__/container.spec.mts +47 -13
- package/src/__tests__/errors.spec.mts +53 -27
- package/src/__tests__/injectable.spec.mts +73 -0
- package/src/__tests__/request-scope.spec.mts +0 -2
- package/src/__tests__/service-instantiator.spec.mts +1 -0
- package/src/__tests__/service-locator-manager.spec.mts +12 -82
- package/src/__tests__/service-locator.spec.mts +1009 -1
- package/src/__type-tests__/inject.spec-d.mts +30 -7
- package/src/__type-tests__/injectable.spec-d.mts +76 -37
- package/src/base-instance-holder-manager.mts +2 -9
- package/src/container.mts +61 -9
- package/src/decorators/injectable.decorator.mts +29 -5
- package/src/errors/di-error.mts +69 -0
- package/src/errors/index.mts +9 -7
- package/src/injection-token.mts +1 -0
- package/src/injector.mts +2 -0
- package/src/instance-resolver.mts +559 -0
- package/src/request-context-holder.mts +0 -2
- package/src/request-context-manager.mts +149 -0
- package/src/service-invalidator.mts +429 -0
- package/src/service-locator-event-bus.mts +1 -1
- package/src/service-locator-instance-holder.mts +0 -4
- package/src/service-locator-manager.mts +10 -40
- package/src/service-locator.mts +86 -782
- package/src/token-processor.mts +174 -0
- package/src/utils/get-injectors.mts +161 -24
- package/src/utils/index.mts +0 -1
- package/src/utils/types.mts +12 -8
- package/lib/chunk-3NLYPYBY.mjs.map +0 -1
- package/src/__tests__/defer.spec.mts +0 -166
- package/src/errors/errors.enum.mts +0 -8
- package/src/errors/factory-not-found.mts +0 -8
- package/src/errors/factory-token-not-resolved.mts +0 -10
- package/src/errors/instance-destroying.mts +0 -8
- package/src/errors/instance-expired.mts +0 -8
- package/src/errors/instance-not-found.mts +0 -8
- package/src/errors/unknown-error.mts +0 -15
- 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
|
|
75
|
-
ReturnType<typeof
|
|
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
|
|
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,6 +143,19 @@ 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.
|
|
@@ -174,6 +185,19 @@ declare class Container {
|
|
|
174
185
|
* Invalidates a service and its dependencies
|
|
175
186
|
*/
|
|
176
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>;
|
|
177
201
|
/**
|
|
178
202
|
* Waits for all pending operations to complete
|
|
179
203
|
*/
|
|
@@ -205,20 +229,11 @@ declare class Container {
|
|
|
205
229
|
* Clears all instances and bindings from the container.
|
|
206
230
|
* This is useful for testing or resetting the container state.
|
|
207
231
|
*/
|
|
208
|
-
clear(): void
|
|
232
|
+
clear(): Promise<void>;
|
|
209
233
|
}
|
|
210
234
|
export { Container }
|
|
211
235
|
export { Container as Container_alias_1 }
|
|
212
236
|
|
|
213
|
-
/**
|
|
214
|
-
* Creates a new deferred promise.
|
|
215
|
-
* @returns A new Deferred instance
|
|
216
|
-
*/
|
|
217
|
-
declare function createDeferred<T>(): Deferred<T>;
|
|
218
|
-
export { createDeferred }
|
|
219
|
-
export { createDeferred as createDeferred_alias_1 }
|
|
220
|
-
export { createDeferred as createDeferred_alias_2 }
|
|
221
|
-
|
|
222
237
|
/**
|
|
223
238
|
* Creates a new request context holder with the given parameters.
|
|
224
239
|
*/
|
|
@@ -263,57 +278,42 @@ declare class DefaultRequestContextHolder extends BaseInstanceHolderManager impl
|
|
|
263
278
|
export { DefaultRequestContextHolder }
|
|
264
279
|
export { DefaultRequestContextHolder as DefaultRequestContextHolder_alias_1 }
|
|
265
280
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
private _isRejected;
|
|
276
|
-
constructor();
|
|
277
|
-
/**
|
|
278
|
-
* Resolves the deferred promise with the given value.
|
|
279
|
-
* @param value The value to resolve with
|
|
280
|
-
* @throws Error if the promise has already been resolved or rejected
|
|
281
|
-
*/
|
|
282
|
-
resolve(value: T): void;
|
|
283
|
-
/**
|
|
284
|
-
* Rejects the deferred promise with the given reason.
|
|
285
|
-
* @param reason The reason for rejection
|
|
286
|
-
* @throws Error if the promise has already been resolved or rejected
|
|
287
|
-
*/
|
|
288
|
-
reject(reason?: any): void;
|
|
289
|
-
/**
|
|
290
|
-
* Returns true if the promise has been resolved.
|
|
291
|
-
*/
|
|
292
|
-
get isResolved(): boolean;
|
|
293
|
-
/**
|
|
294
|
-
* Returns true if the promise has been rejected.
|
|
295
|
-
*/
|
|
296
|
-
get isRejected(): boolean;
|
|
297
|
-
/**
|
|
298
|
-
* Returns true if the promise has been settled (resolved or rejected).
|
|
299
|
-
*/
|
|
300
|
-
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;
|
|
301
290
|
}
|
|
302
|
-
export {
|
|
303
|
-
export {
|
|
304
|
-
export {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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",
|
|
308
308
|
InstanceNotFound = "InstanceNotFound",
|
|
309
309
|
InstanceDestroying = "InstanceDestroying",
|
|
310
|
-
UnknownError = "UnknownError"
|
|
311
|
-
FactoryNotFound = "FactoryNotFound",
|
|
312
|
-
FactoryTokenNotResolved = "FactoryTokenNotResolved"
|
|
310
|
+
UnknownError = "UnknownError"
|
|
313
311
|
}
|
|
314
|
-
export {
|
|
315
|
-
export {
|
|
316
|
-
export {
|
|
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 }
|
|
317
317
|
|
|
318
318
|
declare class EventEmitter<Events extends EventsConfig = {}> implements EventEmitterInterface<Events> {
|
|
319
319
|
private listeners;
|
|
@@ -399,15 +399,6 @@ declare class FactoryInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
|
399
399
|
export { FactoryInjectionToken }
|
|
400
400
|
export { FactoryInjectionToken as FactoryInjectionToken_alias_1 }
|
|
401
401
|
|
|
402
|
-
declare class FactoryNotFound extends Error {
|
|
403
|
-
name: string;
|
|
404
|
-
code: ErrorsEnum;
|
|
405
|
-
constructor(name: string);
|
|
406
|
-
}
|
|
407
|
-
export { FactoryNotFound }
|
|
408
|
-
export { FactoryNotFound as FactoryNotFound_alias_1 }
|
|
409
|
-
export { FactoryNotFound as FactoryNotFound_alias_2 }
|
|
410
|
-
|
|
411
402
|
declare interface FactoryOptions {
|
|
412
403
|
scope?: InjectableScope;
|
|
413
404
|
token?: InjectionToken<any, any>;
|
|
@@ -426,14 +417,6 @@ declare type FactoryRecord<Instance = any, Schema = any> = {
|
|
|
426
417
|
export { FactoryRecord }
|
|
427
418
|
export { FactoryRecord as FactoryRecord_alias_1 }
|
|
428
419
|
|
|
429
|
-
declare class FactoryTokenNotResolved extends Error {
|
|
430
|
-
code: ErrorsEnum;
|
|
431
|
-
constructor(name: string | symbol | ClassType);
|
|
432
|
-
}
|
|
433
|
-
export { FactoryTokenNotResolved }
|
|
434
|
-
export { FactoryTokenNotResolved as FactoryTokenNotResolved_alias_1 }
|
|
435
|
-
export { FactoryTokenNotResolved as FactoryTokenNotResolved_alias_2 }
|
|
436
|
-
|
|
437
420
|
declare function getInjectableToken<R>(target: ClassType): R extends {
|
|
438
421
|
create(...args: any[]): infer V;
|
|
439
422
|
} ? InjectionToken<V> : InjectionToken<R>;
|
|
@@ -454,16 +437,22 @@ declare const inject: Injectors['inject'];
|
|
|
454
437
|
export { inject }
|
|
455
438
|
export { inject as inject_alias_1 }
|
|
456
439
|
|
|
457
|
-
declare function Injectable(): <T extends
|
|
440
|
+
declare function Injectable(): <T extends ClassTypeWithoutArguments>(target: T, context?: ClassDecoratorContext) => T;
|
|
458
441
|
|
|
459
442
|
declare function Injectable(options: {
|
|
460
443
|
scope?: InjectableScope;
|
|
461
444
|
registry: Registry;
|
|
462
|
-
}): <T extends
|
|
445
|
+
}): <T extends ClassTypeWithoutArguments>(target: T, context?: ClassDecoratorContext) => T;
|
|
463
446
|
|
|
464
447
|
declare function Injectable(options: {
|
|
465
448
|
scope: InjectableScope;
|
|
466
|
-
}): <T extends
|
|
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;
|
|
467
456
|
|
|
468
457
|
declare function Injectable<Type, Schema>(options: {
|
|
469
458
|
scope?: InjectableScope;
|
|
@@ -481,6 +470,7 @@ export { Injectable as Injectable_alias_2 }
|
|
|
481
470
|
declare interface InjectableOptions {
|
|
482
471
|
scope?: InjectableScope;
|
|
483
472
|
token?: InjectionToken<any, any>;
|
|
473
|
+
schema?: InjectionTokenSchemaType;
|
|
484
474
|
registry?: Registry;
|
|
485
475
|
}
|
|
486
476
|
export { InjectableOptions }
|
|
@@ -545,18 +535,46 @@ export { InjectionTokenType }
|
|
|
545
535
|
export { InjectionTokenType as InjectionTokenType_alias_1 }
|
|
546
536
|
|
|
547
537
|
declare interface Injectors {
|
|
548
|
-
asyncInject<T extends
|
|
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>;
|
|
549
541
|
asyncInject<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): Promise<T>;
|
|
550
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';
|
|
551
543
|
asyncInject<T>(token: InjectionToken<T, undefined>): Promise<T>;
|
|
552
544
|
asyncInject<T>(token: BoundInjectionToken<T, any>): Promise<T>;
|
|
553
545
|
asyncInject<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
|
|
554
|
-
inject<T extends
|
|
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;
|
|
555
549
|
inject<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): T;
|
|
556
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';
|
|
557
551
|
inject<T>(token: InjectionToken<T, undefined>): T;
|
|
558
552
|
inject<T>(token: BoundInjectionToken<T, any>): T;
|
|
559
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;
|
|
560
578
|
wrapSyncInit(cb: () => any): (injectState?: InjectState) => [any, Promise<any>[], InjectState];
|
|
561
579
|
provideFactoryContext(context: FactoryContext | null): FactoryContext | null;
|
|
562
580
|
}
|
|
@@ -564,44 +582,100 @@ export { Injectors }
|
|
|
564
582
|
export { Injectors as Injectors_alias_1 }
|
|
565
583
|
export { Injectors as Injectors_alias_2 }
|
|
566
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
|
+
|
|
567
595
|
declare interface InjectState {
|
|
568
596
|
currentIndex: number;
|
|
569
597
|
isFrozen: boolean;
|
|
570
|
-
requests:
|
|
571
|
-
token: InjectionToken<any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any> | ClassType;
|
|
572
|
-
promise: Promise<any>;
|
|
573
|
-
}[];
|
|
598
|
+
requests: InjectRequest[];
|
|
574
599
|
}
|
|
575
600
|
export { InjectState }
|
|
576
601
|
export { InjectState as InjectState_alias_1 }
|
|
577
602
|
export { InjectState as InjectState_alias_2 }
|
|
578
603
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
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;
|
|
601
678
|
}
|
|
602
|
-
export { InstanceNotFound }
|
|
603
|
-
export { InstanceNotFound as InstanceNotFound_alias_1 }
|
|
604
|
-
export { InstanceNotFound as InstanceNotFound_alias_2 }
|
|
605
679
|
|
|
606
680
|
declare type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
|
|
607
681
|
export { IsUnion }
|
|
@@ -627,6 +701,10 @@ export { OnServiceInit }
|
|
|
627
701
|
export { OnServiceInit as OnServiceInit_alias_1 }
|
|
628
702
|
export { OnServiceInit as OnServiceInit_alias_2 }
|
|
629
703
|
|
|
704
|
+
declare const optional: Injectors['optional'];
|
|
705
|
+
export { optional }
|
|
706
|
+
export { optional as optional_alias_1 }
|
|
707
|
+
|
|
630
708
|
declare type OptionalInjectionTokenSchemaType = ZodOptional<ZodObject> | ZodOptional<ZodRecord>;
|
|
631
709
|
export { OptionalInjectionTokenSchemaType }
|
|
632
710
|
export { OptionalInjectionTokenSchemaType as OptionalInjectionTokenSchemaType_alias_1 }
|
|
@@ -726,6 +804,49 @@ declare interface RequestContextHolder {
|
|
|
726
804
|
export { RequestContextHolder }
|
|
727
805
|
export { RequestContextHolder as RequestContextHolder_alias_1 }
|
|
728
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
|
+
|
|
729
850
|
/**
|
|
730
851
|
* ServiceInstantiator handles the instantiation of services based on registry records.
|
|
731
852
|
* It replaces the hard-coded logic in Injectable and Factory decorators.
|
|
@@ -761,138 +882,155 @@ declare class ServiceInstantiator {
|
|
|
761
882
|
export { ServiceInstantiator }
|
|
762
883
|
export { ServiceInstantiator as ServiceInstantiator_alias_1 }
|
|
763
884
|
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
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 {
|
|
769
890
|
private readonly manager;
|
|
770
|
-
private readonly
|
|
771
|
-
private readonly
|
|
772
|
-
private
|
|
773
|
-
constructor(
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
getInstance(token: AnyInjectableType, args?: any, onPrepare?: (data: {
|
|
778
|
-
instanceName: string;
|
|
779
|
-
actualToken: InjectionTokenType;
|
|
780
|
-
validatedArgs?: any;
|
|
781
|
-
}) => void): Promise<any[]>;
|
|
782
|
-
getOrThrowInstance<Instance>(token: AnyInjectableType, args: any): Promise<Instance>;
|
|
783
|
-
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;
|
|
891
|
+
private readonly requestContextManager;
|
|
892
|
+
private readonly eventBus;
|
|
893
|
+
private readonly logger;
|
|
894
|
+
constructor(manager: ServiceLocatorManager, requestContextManager: RequestContextManager, eventBus: ServiceLocatorEventBus, logger?: Console | null);
|
|
895
|
+
/**
|
|
896
|
+
* Invalidates a service and all its dependencies.
|
|
897
|
+
*/
|
|
784
898
|
invalidate(service: string, round?: number): Promise<any>;
|
|
785
899
|
/**
|
|
786
|
-
*
|
|
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.
|
|
787
903
|
*/
|
|
788
|
-
|
|
904
|
+
clearAll(options?: ClearAllOptions): Promise<void>;
|
|
789
905
|
/**
|
|
790
|
-
*
|
|
906
|
+
* Waits for all services to settle (either created, destroyed, or error state).
|
|
791
907
|
*/
|
|
792
|
-
private destroyHolder;
|
|
793
908
|
ready(): Promise<void>;
|
|
794
909
|
/**
|
|
795
|
-
*
|
|
910
|
+
* Invalidates a single holder based on its current status.
|
|
796
911
|
*/
|
|
797
|
-
private
|
|
912
|
+
private invalidateHolder;
|
|
798
913
|
/**
|
|
799
|
-
*
|
|
800
|
-
* @param requestId Unique identifier for this request
|
|
801
|
-
* @param metadata Optional metadata for the request
|
|
802
|
-
* @param priority Priority for resolution (higher = more priority)
|
|
803
|
-
* @returns The created request context holder
|
|
914
|
+
* Invalidates a request-scoped holder based on its current status.
|
|
804
915
|
*/
|
|
805
|
-
|
|
916
|
+
private invalidateRequestHolder;
|
|
806
917
|
/**
|
|
807
|
-
*
|
|
808
|
-
* @param requestId The request ID to end
|
|
918
|
+
* Common invalidation logic for holders based on their status.
|
|
809
919
|
*/
|
|
810
|
-
|
|
920
|
+
private invalidateHolderByStatus;
|
|
811
921
|
/**
|
|
812
|
-
*
|
|
813
|
-
* @returns The current request context holder or null
|
|
922
|
+
* Destroys a holder and cleans up its resources.
|
|
814
923
|
*/
|
|
815
|
-
|
|
924
|
+
private destroyHolder;
|
|
816
925
|
/**
|
|
817
|
-
*
|
|
818
|
-
* @param requestId The request ID to set as current
|
|
926
|
+
* Destroys a request-scoped holder and cleans up its resources.
|
|
819
927
|
*/
|
|
820
|
-
|
|
928
|
+
private destroyRequestHolder;
|
|
821
929
|
/**
|
|
822
|
-
*
|
|
930
|
+
* Common destroy logic for holders with customizable cleanup.
|
|
823
931
|
*/
|
|
824
|
-
private
|
|
932
|
+
private destroyHolderWithCleanup;
|
|
825
933
|
/**
|
|
826
|
-
*
|
|
827
|
-
* Handles factory token resolution and validation.
|
|
934
|
+
* Waits for a holder to settle (either created, destroyed, or error state).
|
|
828
935
|
*/
|
|
829
|
-
private
|
|
936
|
+
private waitForHolderToSettle;
|
|
830
937
|
/**
|
|
831
|
-
*
|
|
938
|
+
* Clears services with dependency awareness, ensuring proper cleanup order.
|
|
939
|
+
* Services with no dependencies are cleared first, then services that depend on them.
|
|
832
940
|
*/
|
|
833
|
-
private
|
|
941
|
+
private clearServicesWithDependencyAwareness;
|
|
834
942
|
/**
|
|
835
|
-
*
|
|
836
|
-
*
|
|
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.
|
|
837
945
|
*/
|
|
838
|
-
private
|
|
946
|
+
private findServicesReadyForClearing;
|
|
839
947
|
/**
|
|
840
|
-
*
|
|
948
|
+
* Force clears services that couldn't be cleared through normal dependency resolution.
|
|
949
|
+
* This handles edge cases like circular dependencies.
|
|
841
950
|
*/
|
|
842
|
-
private
|
|
951
|
+
private forceClearServices;
|
|
843
952
|
/**
|
|
844
|
-
*
|
|
953
|
+
* Gets all service names currently managed by the ServiceLocator.
|
|
845
954
|
*/
|
|
846
|
-
private
|
|
847
|
-
/**
|
|
848
|
-
* Waits for an instance holder to be ready and returns the appropriate result.
|
|
849
|
-
*/
|
|
850
|
-
private waitForInstanceReady;
|
|
955
|
+
private getAllServiceNames;
|
|
851
956
|
/**
|
|
852
957
|
* Emits events to listeners for instance lifecycle events.
|
|
853
958
|
*/
|
|
854
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>;
|
|
855
988
|
/**
|
|
856
|
-
*
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
*
|
|
861
|
-
|
|
862
|
-
private instantiateServiceFromRegistry;
|
|
863
|
-
/**
|
|
864
|
-
* 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
|
|
865
995
|
*/
|
|
866
|
-
|
|
996
|
+
clearAll(options?: ClearAllOptions): Promise<void>;
|
|
867
997
|
/**
|
|
868
|
-
*
|
|
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
|
|
869
1003
|
*/
|
|
870
|
-
|
|
1004
|
+
beginRequest(requestId: string, metadata?: Record<string, any>, priority?: number): RequestContextHolder;
|
|
871
1005
|
/**
|
|
872
|
-
*
|
|
1006
|
+
* Ends a request context and cleans up all associated instances.
|
|
1007
|
+
* @param requestId The request ID to end
|
|
873
1008
|
*/
|
|
874
|
-
|
|
1009
|
+
endRequest(requestId: string): Promise<void>;
|
|
875
1010
|
/**
|
|
876
|
-
*
|
|
1011
|
+
* Gets the current request context.
|
|
1012
|
+
* @returns The current request context holder or null
|
|
877
1013
|
*/
|
|
878
|
-
|
|
1014
|
+
getCurrentRequestContext(): RequestContextHolder | null;
|
|
879
1015
|
/**
|
|
880
|
-
*
|
|
1016
|
+
* Sets the current request context.
|
|
1017
|
+
* @param requestId The request ID to set as current
|
|
881
1018
|
*/
|
|
882
|
-
|
|
1019
|
+
setCurrentRequestContext(requestId: string): void;
|
|
883
1020
|
/**
|
|
884
|
-
*
|
|
885
|
-
* @param contextHolder Optional request context holder for priority-based resolution
|
|
1021
|
+
* Waits for all services to settle (either created, destroyed, or error state).
|
|
886
1022
|
*/
|
|
887
|
-
|
|
1023
|
+
ready(): Promise<void>;
|
|
888
1024
|
/**
|
|
889
|
-
*
|
|
1025
|
+
* Helper method for TokenProcessor to access pre-prepared instances.
|
|
1026
|
+
* This is needed for the factory context creation.
|
|
890
1027
|
*/
|
|
891
|
-
|
|
1028
|
+
tryGetPrePreparedInstance(instanceName: string, contextHolder: RequestContextHolder | undefined, deps: Set<string>): any;
|
|
892
1029
|
/**
|
|
893
|
-
*
|
|
1030
|
+
* Helper method for InstanceResolver to generate instance names.
|
|
1031
|
+
* This is needed for the factory context creation.
|
|
894
1032
|
*/
|
|
895
|
-
|
|
1033
|
+
generateInstanceName(token: any, args: any): string;
|
|
896
1034
|
}
|
|
897
1035
|
export { ServiceLocator }
|
|
898
1036
|
export { ServiceLocator as ServiceLocator_alias_1 }
|
|
@@ -930,7 +1068,6 @@ declare interface ServiceLocatorInstanceHolderCreated<Instance> {
|
|
|
930
1068
|
deps: Set<string>;
|
|
931
1069
|
destroyListeners: ServiceLocatorInstanceDestroyListener[];
|
|
932
1070
|
createdAt: number;
|
|
933
|
-
ttl: number;
|
|
934
1071
|
}
|
|
935
1072
|
export { ServiceLocatorInstanceHolderCreated }
|
|
936
1073
|
export { ServiceLocatorInstanceHolderCreated as ServiceLocatorInstanceHolderCreated_alias_1 }
|
|
@@ -946,7 +1083,6 @@ declare interface ServiceLocatorInstanceHolderCreating<Instance> {
|
|
|
946
1083
|
deps: Set<string>;
|
|
947
1084
|
destroyListeners: ServiceLocatorInstanceDestroyListener[];
|
|
948
1085
|
createdAt: number;
|
|
949
|
-
ttl: number;
|
|
950
1086
|
}
|
|
951
1087
|
export { ServiceLocatorInstanceHolderCreating }
|
|
952
1088
|
export { ServiceLocatorInstanceHolderCreating as ServiceLocatorInstanceHolderCreating_alias_1 }
|
|
@@ -962,7 +1098,6 @@ declare interface ServiceLocatorInstanceHolderDestroying<Instance> {
|
|
|
962
1098
|
deps: Set<string>;
|
|
963
1099
|
destroyListeners: ServiceLocatorInstanceDestroyListener[];
|
|
964
1100
|
createdAt: number;
|
|
965
|
-
ttl: number;
|
|
966
1101
|
}
|
|
967
1102
|
export { ServiceLocatorInstanceHolderDestroying }
|
|
968
1103
|
export { ServiceLocatorInstanceHolderDestroying as ServiceLocatorInstanceHolderDestroying_alias_1 }
|
|
@@ -978,7 +1113,6 @@ declare interface ServiceLocatorInstanceHolderError {
|
|
|
978
1113
|
deps: Set<string>;
|
|
979
1114
|
destroyListeners: ServiceLocatorInstanceDestroyListener[];
|
|
980
1115
|
createdAt: number;
|
|
981
|
-
ttl: number;
|
|
982
1116
|
}
|
|
983
1117
|
export { ServiceLocatorInstanceHolderError }
|
|
984
1118
|
export { ServiceLocatorInstanceHolderError as ServiceLocatorInstanceHolderError_alias_1 }
|
|
@@ -994,9 +1128,9 @@ export { ServiceLocatorInstanceHolderStatus as ServiceLocatorInstanceHolderStatu
|
|
|
994
1128
|
|
|
995
1129
|
declare class ServiceLocatorManager extends BaseInstanceHolderManager {
|
|
996
1130
|
constructor(logger?: Console | null);
|
|
997
|
-
get(name: string): [
|
|
1131
|
+
get(name: string): [DIError, ServiceLocatorInstanceHolder] | [DIError] | [undefined, ServiceLocatorInstanceHolder];
|
|
998
1132
|
set(name: string, holder: ServiceLocatorInstanceHolder): void;
|
|
999
|
-
has(name: string): [
|
|
1133
|
+
has(name: string): [DIError] | [undefined, boolean];
|
|
1000
1134
|
/**
|
|
1001
1135
|
* Creates a new holder with Created status and an actual instance.
|
|
1002
1136
|
* This is useful for creating holders that already have their instance ready.
|
|
@@ -1005,10 +1139,9 @@ declare class ServiceLocatorManager extends BaseInstanceHolderManager {
|
|
|
1005
1139
|
* @param type The injectable type
|
|
1006
1140
|
* @param scope The injectable scope
|
|
1007
1141
|
* @param deps Optional set of dependencies
|
|
1008
|
-
* @param ttl Optional time-to-live in milliseconds (defaults to Infinity)
|
|
1009
1142
|
* @returns The created holder
|
|
1010
1143
|
*/
|
|
1011
|
-
storeCreatedHolder<Instance>(name: string, instance: Instance, type: InjectableType, scope: InjectableScope, deps?: Set<string
|
|
1144
|
+
storeCreatedHolder<Instance>(name: string, instance: Instance, type: InjectableType, scope: InjectableScope, deps?: Set<string>): ServiceLocatorInstanceHolder<Instance>;
|
|
1012
1145
|
}
|
|
1013
1146
|
export { ServiceLocatorManager }
|
|
1014
1147
|
export { ServiceLocatorManager as ServiceLocatorManager_alias_1 }
|
|
@@ -1089,6 +1222,45 @@ declare class TestContainer extends Container {
|
|
|
1089
1222
|
export { TestContainer }
|
|
1090
1223
|
export { TestContainer as TestContainer_alias_1 }
|
|
1091
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
|
+
|
|
1092
1264
|
declare type UnionToArray<T, A extends unknown[] = []> = IsUnion<T> extends true ? UnionToArray<Exclude<T, PopUnion<T>>, [PopUnion<T>, ...A]> : [T, ...A];
|
|
1093
1265
|
export { UnionToArray }
|
|
1094
1266
|
export { UnionToArray as UnionToArray_alias_1 }
|
|
@@ -1104,15 +1276,6 @@ export { UnionToOvlds }
|
|
|
1104
1276
|
export { UnionToOvlds as UnionToOvlds_alias_1 }
|
|
1105
1277
|
export { UnionToOvlds as UnionToOvlds_alias_2 }
|
|
1106
1278
|
|
|
1107
|
-
declare class UnknownError extends Error {
|
|
1108
|
-
code: ErrorsEnum;
|
|
1109
|
-
parent?: Error;
|
|
1110
|
-
constructor(message: string | Error);
|
|
1111
|
-
}
|
|
1112
|
-
export { UnknownError }
|
|
1113
|
-
export { UnknownError as UnknownError_alias_1 }
|
|
1114
|
-
export { UnknownError as UnknownError_alias_2 }
|
|
1115
|
-
|
|
1116
1279
|
declare const wrapSyncInit: Injectors['wrapSyncInit'];
|
|
1117
1280
|
export { wrapSyncInit }
|
|
1118
1281
|
export { wrapSyncInit as wrapSyncInit_alias_1 }
|