@navios/di 0.7.1 → 0.9.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.
- package/CHANGELOG.md +110 -0
- package/README.md +117 -17
- package/lib/browser/container/abstract-container.d.mts +112 -0
- package/lib/browser/container/abstract-container.d.mts.map +1 -0
- package/lib/browser/container/abstract-container.mjs +100 -0
- package/lib/browser/container/abstract-container.mjs.map +1 -0
- package/lib/browser/container/container.d.mts +100 -0
- package/lib/browser/container/container.d.mts.map +1 -0
- package/lib/browser/container/container.mjs +424 -0
- package/lib/browser/container/container.mjs.map +1 -0
- package/lib/browser/container/scoped-container.d.mts +93 -0
- package/lib/browser/container/scoped-container.d.mts.map +1 -0
- package/lib/browser/container/scoped-container.mjs +119 -0
- package/lib/browser/container/scoped-container.mjs.map +1 -0
- package/lib/browser/decorators/factory.decorator.d.mts +26 -0
- package/lib/browser/decorators/factory.decorator.d.mts.map +1 -0
- package/lib/browser/decorators/factory.decorator.mjs +20 -0
- package/lib/browser/decorators/factory.decorator.mjs.map +1 -0
- package/lib/browser/decorators/injectable.decorator.d.mts +38 -0
- package/lib/browser/decorators/injectable.decorator.d.mts.map +1 -0
- package/lib/browser/decorators/injectable.decorator.mjs +21 -0
- package/lib/browser/decorators/injectable.decorator.mjs.map +1 -0
- package/lib/browser/enums/injectable-scope.enum.d.mts +18 -0
- package/lib/browser/enums/injectable-scope.enum.d.mts.map +1 -0
- package/lib/browser/enums/injectable-scope.enum.mjs +20 -0
- package/lib/browser/enums/injectable-scope.enum.mjs.map +1 -0
- package/lib/browser/enums/injectable-type.enum.d.mts +8 -0
- package/lib/browser/enums/injectable-type.enum.d.mts.map +1 -0
- package/lib/browser/enums/injectable-type.enum.mjs +10 -0
- package/lib/browser/enums/injectable-type.enum.mjs.map +1 -0
- package/lib/browser/errors/di-error.d.mts +43 -0
- package/lib/browser/errors/di-error.d.mts.map +1 -0
- package/lib/browser/errors/di-error.mjs +98 -0
- package/lib/browser/errors/di-error.mjs.map +1 -0
- package/lib/browser/event-emitter.d.mts +16 -0
- package/lib/browser/event-emitter.d.mts.map +1 -0
- package/lib/browser/event-emitter.mjs +320 -0
- package/lib/browser/event-emitter.mjs.map +1 -0
- package/lib/browser/index.d.mts +37 -1508
- package/lib/browser/index.mjs +29 -2650
- package/lib/browser/interfaces/container.interface.d.mts +59 -0
- package/lib/browser/interfaces/container.interface.d.mts.map +1 -0
- package/lib/browser/interfaces/factory.interface.d.mts +14 -0
- package/lib/browser/interfaces/factory.interface.d.mts.map +1 -0
- package/lib/browser/interfaces/on-service-destroy.interface.d.mts +7 -0
- package/lib/browser/interfaces/on-service-destroy.interface.d.mts.map +1 -0
- package/lib/browser/interfaces/on-service-init.interface.d.mts +7 -0
- package/lib/browser/interfaces/on-service-init.interface.d.mts.map +1 -0
- package/lib/browser/internal/context/async-local-storage.browser.mjs +20 -0
- package/lib/browser/internal/context/async-local-storage.browser.mjs.map +1 -0
- package/lib/browser/internal/context/async-local-storage.d.mts +9 -0
- package/lib/browser/internal/context/async-local-storage.d.mts.map +1 -0
- package/lib/browser/internal/context/async-local-storage.types.d.mts +11 -0
- package/lib/browser/internal/context/async-local-storage.types.d.mts.map +1 -0
- package/lib/browser/internal/context/factory-context.d.mts +23 -0
- package/lib/browser/internal/context/factory-context.d.mts.map +1 -0
- package/lib/browser/internal/context/resolution-context.d.mts +43 -0
- package/lib/browser/internal/context/resolution-context.d.mts.map +1 -0
- package/lib/browser/internal/context/resolution-context.mjs +56 -0
- package/lib/browser/internal/context/resolution-context.mjs.map +1 -0
- package/lib/browser/internal/context/service-initialization-context.d.mts +48 -0
- package/lib/browser/internal/context/service-initialization-context.d.mts.map +1 -0
- package/lib/browser/internal/context/sync-local-storage.mjs +53 -0
- package/lib/browser/internal/context/sync-local-storage.mjs.map +1 -0
- package/lib/browser/internal/core/instance-resolver.d.mts +119 -0
- package/lib/browser/internal/core/instance-resolver.d.mts.map +1 -0
- package/lib/browser/internal/core/instance-resolver.mjs +306 -0
- package/lib/browser/internal/core/instance-resolver.mjs.map +1 -0
- package/lib/browser/internal/core/name-resolver.d.mts +52 -0
- package/lib/browser/internal/core/name-resolver.d.mts.map +1 -0
- package/lib/browser/internal/core/name-resolver.mjs +118 -0
- package/lib/browser/internal/core/name-resolver.mjs.map +1 -0
- package/lib/browser/internal/core/scope-tracker.d.mts +65 -0
- package/lib/browser/internal/core/scope-tracker.d.mts.map +1 -0
- package/lib/browser/internal/core/scope-tracker.mjs +120 -0
- package/lib/browser/internal/core/scope-tracker.mjs.map +1 -0
- package/lib/browser/internal/core/service-initializer.d.mts +44 -0
- package/lib/browser/internal/core/service-initializer.d.mts.map +1 -0
- package/lib/browser/internal/core/service-initializer.mjs +109 -0
- package/lib/browser/internal/core/service-initializer.mjs.map +1 -0
- package/lib/browser/internal/core/service-invalidator.d.mts +81 -0
- package/lib/browser/internal/core/service-invalidator.d.mts.map +1 -0
- package/lib/browser/internal/core/service-invalidator.mjs +142 -0
- package/lib/browser/internal/core/service-invalidator.mjs.map +1 -0
- package/lib/browser/internal/core/token-resolver.d.mts +54 -0
- package/lib/browser/internal/core/token-resolver.d.mts.map +1 -0
- package/lib/browser/internal/core/token-resolver.mjs +77 -0
- package/lib/browser/internal/core/token-resolver.mjs.map +1 -0
- package/lib/browser/internal/holder/holder-storage.interface.d.mts +99 -0
- package/lib/browser/internal/holder/holder-storage.interface.d.mts.map +1 -0
- package/lib/browser/internal/holder/instance-holder.d.mts +101 -0
- package/lib/browser/internal/holder/instance-holder.d.mts.map +1 -0
- package/lib/browser/internal/holder/instance-holder.mjs +19 -0
- package/lib/browser/internal/holder/instance-holder.mjs.map +1 -0
- package/lib/browser/internal/holder/unified-storage.d.mts +53 -0
- package/lib/browser/internal/holder/unified-storage.d.mts.map +1 -0
- package/lib/browser/internal/holder/unified-storage.mjs +144 -0
- package/lib/browser/internal/holder/unified-storage.mjs.map +1 -0
- package/lib/browser/internal/lifecycle/circular-detector.d.mts +39 -0
- package/lib/browser/internal/lifecycle/circular-detector.d.mts.map +1 -0
- package/lib/browser/internal/lifecycle/circular-detector.mjs +55 -0
- package/lib/browser/internal/lifecycle/circular-detector.mjs.map +1 -0
- package/lib/browser/internal/lifecycle/lifecycle-event-bus.d.mts +18 -0
- package/lib/browser/internal/lifecycle/lifecycle-event-bus.d.mts.map +1 -0
- package/lib/browser/internal/lifecycle/lifecycle-event-bus.mjs +43 -0
- package/lib/browser/internal/lifecycle/lifecycle-event-bus.mjs.map +1 -0
- package/lib/browser/internal/stub-factory-class.d.mts +14 -0
- package/lib/browser/internal/stub-factory-class.d.mts.map +1 -0
- package/lib/browser/internal/stub-factory-class.mjs +18 -0
- package/lib/browser/internal/stub-factory-class.mjs.map +1 -0
- package/lib/browser/symbols/injectable-token.d.mts +5 -0
- package/lib/browser/symbols/injectable-token.d.mts.map +1 -0
- package/lib/browser/symbols/injectable-token.mjs +6 -0
- package/lib/browser/symbols/injectable-token.mjs.map +1 -0
- package/lib/browser/token/injection-token.d.mts +55 -0
- package/lib/browser/token/injection-token.d.mts.map +1 -0
- package/lib/browser/token/injection-token.mjs +100 -0
- package/lib/browser/token/injection-token.mjs.map +1 -0
- package/lib/browser/token/registry.d.mts +37 -0
- package/lib/browser/token/registry.d.mts.map +1 -0
- package/lib/browser/token/registry.mjs +86 -0
- package/lib/browser/token/registry.mjs.map +1 -0
- package/lib/browser/utils/default-injectors.d.mts +12 -0
- package/lib/browser/utils/default-injectors.d.mts.map +1 -0
- package/lib/browser/utils/default-injectors.mjs +13 -0
- package/lib/browser/utils/default-injectors.mjs.map +1 -0
- package/lib/browser/utils/get-injectable-token.d.mts +9 -0
- package/lib/browser/utils/get-injectable-token.d.mts.map +1 -0
- package/lib/browser/utils/get-injectable-token.mjs +13 -0
- package/lib/browser/utils/get-injectable-token.mjs.map +1 -0
- package/lib/browser/utils/get-injectors.d.mts +55 -0
- package/lib/browser/utils/get-injectors.d.mts.map +1 -0
- package/lib/browser/utils/get-injectors.mjs +121 -0
- package/lib/browser/utils/get-injectors.mjs.map +1 -0
- package/lib/browser/utils/types.d.mts +23 -0
- package/lib/browser/utils/types.d.mts.map +1 -0
- package/lib/{container-Pb_Y4Z4x.mjs → container-8-z89TyQ.mjs} +1269 -1305
- package/lib/container-8-z89TyQ.mjs.map +1 -0
- package/lib/{container-BuAutHGg.d.mts → container-CNiqesCL.d.mts} +600 -569
- package/lib/container-CNiqesCL.d.mts.map +1 -0
- package/lib/{container-DnzgpfBe.cjs → container-CaY2fDuk.cjs} +1287 -1329
- package/lib/container-CaY2fDuk.cjs.map +1 -0
- package/lib/{container-oGTgX2iX.d.cts → container-D-0Ho3qL.d.cts} +601 -565
- package/lib/container-D-0Ho3qL.d.cts.map +1 -0
- package/lib/index.cjs +13 -15
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +58 -223
- package/lib/index.d.cts.map +1 -1
- package/lib/index.d.mts +62 -222
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +5 -6
- package/lib/index.mjs.map +1 -1
- package/lib/testing/index.cjs +569 -311
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.d.cts +370 -41
- package/lib/testing/index.d.cts.map +1 -1
- package/lib/testing/index.d.mts +370 -41
- package/lib/testing/index.d.mts.map +1 -1
- package/lib/testing/index.mjs +568 -305
- package/lib/testing/index.mjs.map +1 -1
- package/package.json +2 -1
- package/src/__tests__/circular-detector.spec.mts +193 -0
- package/src/__tests__/concurrent.spec.mts +368 -0
- package/src/__tests__/container.spec.mts +32 -30
- package/src/__tests__/di-error.spec.mts +351 -0
- package/src/__tests__/e2e.browser.spec.mts +0 -4
- package/src/__tests__/e2e.spec.mts +10 -19
- package/src/__tests__/event-emitter.spec.mts +232 -109
- package/src/__tests__/get-injectors.spec.mts +250 -39
- package/src/__tests__/injection-token.spec.mts +293 -349
- package/src/__tests__/library-findings.spec.mts +8 -8
- package/src/__tests__/registry.spec.mts +358 -210
- package/src/__tests__/resolution-context.spec.mts +255 -0
- package/src/__tests__/scope-tracker.spec.mts +598 -0
- package/src/__tests__/scope-upgrade.spec.mts +808 -0
- package/src/__tests__/scoped-container.spec.mts +595 -0
- package/src/__tests__/test-container.spec.mts +293 -0
- package/src/__tests__/token-resolver.spec.mts +207 -0
- package/src/__tests__/unified-storage.spec.mts +535 -0
- package/src/__tests__/unit-test-container.spec.mts +405 -0
- package/src/__type-tests__/container.spec-d.mts +180 -0
- package/src/__type-tests__/factory.spec-d.mts +15 -3
- package/src/__type-tests__/inject.spec-d.mts +115 -20
- package/src/__type-tests__/injectable.spec-d.mts +69 -52
- package/src/__type-tests__/injection-token.spec-d.mts +176 -0
- package/src/__type-tests__/scoped-container.spec-d.mts +212 -0
- package/src/container/abstract-container.mts +327 -0
- package/src/container/container.mts +142 -170
- package/src/container/scoped-container.mts +126 -208
- package/src/decorators/factory.decorator.mts +16 -11
- package/src/decorators/injectable.decorator.mts +20 -16
- package/src/enums/index.mts +2 -2
- package/src/enums/injectable-scope.enum.mts +1 -0
- package/src/enums/injectable-type.enum.mts +1 -0
- package/src/errors/di-error.mts +96 -0
- package/src/event-emitter.mts +3 -27
- package/src/index.mts +6 -153
- package/src/interfaces/container.interface.mts +13 -0
- package/src/interfaces/factory.interface.mts +1 -1
- package/src/interfaces/index.mts +1 -1
- package/src/internal/context/async-local-storage.mts +3 -2
- package/src/internal/context/async-local-storage.types.mts +1 -0
- package/src/internal/context/factory-context.mts +1 -0
- package/src/internal/context/index.mts +3 -1
- package/src/internal/context/resolution-context.mts +1 -0
- package/src/internal/context/service-initialization-context.mts +43 -0
- package/src/internal/core/index.mts +5 -4
- package/src/internal/core/instance-resolver.mts +461 -292
- package/src/internal/core/name-resolver.mts +196 -0
- package/src/internal/core/scope-tracker.mts +242 -0
- package/src/internal/core/{instantiator.mts → service-initializer.mts} +51 -29
- package/src/internal/core/service-invalidator.mts +290 -0
- package/src/internal/core/{token-processor.mts → token-resolver.mts} +17 -88
- package/src/internal/holder/holder-storage.interface.mts +11 -5
- package/src/internal/holder/index.mts +2 -5
- package/src/internal/holder/instance-holder.mts +1 -3
- package/src/internal/holder/unified-storage.mts +245 -0
- package/src/internal/index.mts +2 -1
- package/src/internal/lifecycle/circular-detector.mts +1 -0
- package/src/internal/lifecycle/index.mts +1 -1
- package/src/internal/lifecycle/lifecycle-event-bus.mts +1 -0
- package/src/internal/stub-factory-class.mts +16 -0
- package/src/symbols/injectable-token.mts +3 -1
- package/src/testing/index.mts +2 -0
- package/src/testing/test-container.mts +546 -85
- package/src/testing/types.mts +117 -0
- package/src/testing/unit-test-container.mts +509 -0
- package/src/token/injection-token.mts +41 -4
- package/src/token/registry.mts +75 -9
- package/src/utils/default-injectors.mts +16 -0
- package/src/utils/get-injectable-token.mts +2 -3
- package/src/utils/get-injectors.mts +26 -15
- package/src/utils/index.mts +3 -1
- package/src/utils/types.mts +1 -0
- package/tsdown.config.mts +11 -1
- package/lib/browser/index.d.mts.map +0 -1
- package/lib/browser/index.mjs.map +0 -1
- package/lib/container-BuAutHGg.d.mts.map +0 -1
- package/lib/container-DnzgpfBe.cjs.map +0 -1
- package/lib/container-Pb_Y4Z4x.mjs.map +0 -1
- package/lib/container-oGTgX2iX.d.cts.map +0 -1
- package/src/__tests__/async-local-storage.browser.spec.mts +0 -166
- package/src/__tests__/async-local-storage.spec.mts +0 -333
- package/src/__tests__/errors.spec.mts +0 -87
- package/src/__tests__/factory.spec.mts +0 -137
- package/src/__tests__/injectable.spec.mts +0 -246
- package/src/__tests__/request-scope.spec.mts +0 -416
- package/src/__tests__/service-instantiator.spec.mts +0 -410
- package/src/__tests__/service-locator-event-bus.spec.mts +0 -242
- package/src/__tests__/service-locator-manager.spec.mts +0 -300
- package/src/__tests__/service-locator.spec.mts +0 -966
- package/src/__tests__/unified-api.spec.mts +0 -130
- package/src/browser.mts +0 -11
- package/src/injectors.mts +0 -18
- package/src/internal/context/request-context.mts +0 -214
- package/src/internal/core/invalidator.mts +0 -437
- package/src/internal/core/service-locator.mts +0 -202
- package/src/internal/holder/base-holder-manager.mts +0 -238
- package/src/internal/holder/holder-manager.mts +0 -85
- package/src/internal/holder/request-storage.mts +0 -134
- package/src/internal/holder/singleton-storage.mts +0 -105
- package/src/testing/README.md +0 -80
- package/src/testing/__tests__/test-container.spec.mts +0 -173
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
import { ZodObject, ZodOptional, ZodRecord, ZodType, z } from "zod/v4";
|
|
2
2
|
|
|
3
|
+
//#region src/token/injection-token.d.mts
|
|
4
|
+
type ClassType = new (...args: any[]) => any;
|
|
5
|
+
type ClassTypeWithoutArguments = new () => any;
|
|
6
|
+
type ClassTypeWithArgument<Arg> = new (arg: Arg) => any;
|
|
7
|
+
type ClassTypeWithOptionalArgument<Arg> = new (arg?: Arg) => any;
|
|
8
|
+
type ClassTypeWithInstance<T> = new (...args: any[]) => T;
|
|
9
|
+
type ClassTypeWithInstanceAndArgument<T, Arg> = new (arg: Arg) => T;
|
|
10
|
+
type ClassTypeWithInstanceAndOptionalArgument<T, Arg> = new (arg?: Arg) => T;
|
|
11
|
+
type BaseInjectionTokenSchemaType = ZodObject | ZodRecord;
|
|
12
|
+
type OptionalInjectionTokenSchemaType = ZodOptional<ZodObject> | ZodOptional<ZodRecord>;
|
|
13
|
+
type InjectionTokenSchemaType = BaseInjectionTokenSchemaType | OptionalInjectionTokenSchemaType;
|
|
14
|
+
declare class InjectionToken<T, S extends InjectionTokenSchemaType | unknown = unknown, Required extends boolean = (S extends ZodOptional<ZodObject> ? false : S extends ZodOptional<ZodRecord> ? false : S extends ZodObject ? true : S extends ZodRecord ? true : false)> {
|
|
15
|
+
readonly name: string | symbol | ClassType;
|
|
16
|
+
readonly schema: ZodObject | undefined;
|
|
17
|
+
readonly id: string;
|
|
18
|
+
private formattedName;
|
|
19
|
+
constructor(name: string | symbol | ClassType, schema: ZodObject | undefined, customId?: string);
|
|
20
|
+
static create<T extends ClassType>(name: T): InjectionToken<InstanceType<T>, undefined>;
|
|
21
|
+
static create<T extends ClassType, Schema extends InjectionTokenSchemaType>(name: T, schema: Schema): Schema['_def']['type'] extends 'ZodOptional' ? InjectionToken<InstanceType<T>, Schema, false> : InjectionToken<InstanceType<T>, Schema, true>;
|
|
22
|
+
static create<T>(name: string | symbol): InjectionToken<T, undefined>;
|
|
23
|
+
static create<T, Schema extends InjectionTokenSchemaType>(name: string | any, schema: Schema): InjectionToken<T, Schema>;
|
|
24
|
+
static bound<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, value: z.input<S>): BoundInjectionToken<T, S>;
|
|
25
|
+
static factory<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, factory: (ctx: FactoryContext) => Promise<z.input<S>>): FactoryInjectionToken<T, S>;
|
|
26
|
+
static refineType<T>(token: BoundInjectionToken<any, any>): BoundInjectionToken<T, any>;
|
|
27
|
+
toString(): string;
|
|
28
|
+
}
|
|
29
|
+
declare class BoundInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
30
|
+
readonly token: InjectionToken<T, S>;
|
|
31
|
+
readonly value: z.input<S>;
|
|
32
|
+
id: string;
|
|
33
|
+
name: string | symbol | ClassType;
|
|
34
|
+
schema: InjectionTokenSchemaType;
|
|
35
|
+
constructor(token: InjectionToken<T, S>, value: z.input<S>);
|
|
36
|
+
toString(): string;
|
|
37
|
+
}
|
|
38
|
+
declare class FactoryInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
39
|
+
readonly token: InjectionToken<T, S>;
|
|
40
|
+
readonly factory: (ctx: FactoryContext) => Promise<z.input<S>>;
|
|
41
|
+
value?: z.input<S>;
|
|
42
|
+
resolved: boolean;
|
|
43
|
+
id: string;
|
|
44
|
+
name: string | symbol | ClassType;
|
|
45
|
+
schema: InjectionTokenSchemaType;
|
|
46
|
+
constructor(token: InjectionToken<T, S>, factory: (ctx: FactoryContext) => Promise<z.input<S>>);
|
|
47
|
+
resolve(ctx: FactoryContext): Promise<z.input<S>>;
|
|
48
|
+
toString(): string;
|
|
49
|
+
}
|
|
50
|
+
type AnyInjectableType = ClassType | InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>;
|
|
51
|
+
type InjectionTokenType = InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>;
|
|
52
|
+
//#endregion
|
|
3
53
|
//#region src/utils/types.d.mts
|
|
4
54
|
type Join<TElements, TSeparator extends string> = TElements extends Readonly<[infer First, ...infer Rest]> ? Rest extends ReadonlyArray<string> ? First extends string ? `${First}${Rest extends [] ? '' : TSeparator}${Join<Rest, TSeparator>}` : never : never : '';
|
|
5
55
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
@@ -19,14 +69,6 @@ interface InjectState {
|
|
|
19
69
|
requests: InjectRequest[];
|
|
20
70
|
}
|
|
21
71
|
//#endregion
|
|
22
|
-
//#region src/interfaces/factory.interface.d.mts
|
|
23
|
-
interface Factorable<T> {
|
|
24
|
-
create(ctx?: FactoryContext): Promise<T> | T;
|
|
25
|
-
}
|
|
26
|
-
interface FactorableWithArgs<T, A extends InjectionTokenSchemaType> {
|
|
27
|
-
create(ctx?: FactoryContext, ...args: [z.output<A>]): Promise<T> | T;
|
|
28
|
-
}
|
|
29
|
-
//#endregion
|
|
30
72
|
//#region src/interfaces/container.interface.d.mts
|
|
31
73
|
/**
|
|
32
74
|
* Interface for dependency injection containers.
|
|
@@ -52,6 +94,15 @@ interface IContainer {
|
|
|
52
94
|
* Checks if a service is registered in the container.
|
|
53
95
|
*/
|
|
54
96
|
isRegistered(token: any): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Adds an instance to the container.
|
|
99
|
+
* Accepts class types, InjectionTokens, and BoundInjectionTokens.
|
|
100
|
+
* Rejects InjectionTokens with required schemas (use BoundInjectionToken instead).
|
|
101
|
+
*
|
|
102
|
+
* @param token The class type, InjectionToken, or BoundInjectionToken to register the instance for
|
|
103
|
+
* @param instance The instance to store
|
|
104
|
+
*/
|
|
105
|
+
addInstance<T>(token: ClassType | InjectionToken<T, any> | BoundInjectionToken<T, any>, instance: T): void;
|
|
55
106
|
/**
|
|
56
107
|
* Disposes the container and cleans up all resources.
|
|
57
108
|
*/
|
|
@@ -69,6 +120,69 @@ interface IContainer {
|
|
|
69
120
|
tryGetSync<T>(token: any, args?: any): T | null;
|
|
70
121
|
}
|
|
71
122
|
//#endregion
|
|
123
|
+
//#region src/enums/injectable-scope.enum.d.mts
|
|
124
|
+
declare enum InjectableScope {
|
|
125
|
+
/**
|
|
126
|
+
* Singleton scope: The instance is created once and shared across the application.
|
|
127
|
+
*/
|
|
128
|
+
Singleton = "Singleton",
|
|
129
|
+
/**
|
|
130
|
+
* Instance scope: A new instance is created for each injection.
|
|
131
|
+
*/
|
|
132
|
+
Transient = "Transient",
|
|
133
|
+
/**
|
|
134
|
+
* Request scope: The instance is created once per request and shared within that request context.
|
|
135
|
+
*/
|
|
136
|
+
Request = "Request",
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/enums/injectable-type.enum.d.mts
|
|
140
|
+
declare enum InjectableType {
|
|
141
|
+
Class = "Class",
|
|
142
|
+
Factory = "Factory",
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/internal/context/service-initialization-context.d.mts
|
|
146
|
+
/**
|
|
147
|
+
* Context provided to injectors during service initialization.
|
|
148
|
+
*
|
|
149
|
+
* Extends FactoryContext with additional tracking information about
|
|
150
|
+
* the service being initialized, its dependencies, and scope.
|
|
151
|
+
* Used for scope upgrade tracking and dependency management.
|
|
152
|
+
*/
|
|
153
|
+
interface ServiceInitializationContext {
|
|
154
|
+
inject: Injectors['asyncInject'];
|
|
155
|
+
/**
|
|
156
|
+
* The container instance for dependency resolution.
|
|
157
|
+
* This may be either a Container or ScopedContainer.
|
|
158
|
+
*/
|
|
159
|
+
container: IContainer;
|
|
160
|
+
addDestroyListener: (listener: () => void) => void;
|
|
161
|
+
getDestroyListeners: () => (() => void)[];
|
|
162
|
+
/**
|
|
163
|
+
* The name of the service being initialized.
|
|
164
|
+
*/
|
|
165
|
+
serviceName: string;
|
|
166
|
+
/**
|
|
167
|
+
* Set of dependency names that this service depends on.
|
|
168
|
+
* Automatically populated as dependencies are resolved.
|
|
169
|
+
*/
|
|
170
|
+
dependencies: Set<string>;
|
|
171
|
+
/**
|
|
172
|
+
* The scope of the service being initialized.
|
|
173
|
+
*/
|
|
174
|
+
scope: InjectableScope;
|
|
175
|
+
/**
|
|
176
|
+
* Track a dependency that was resolved.
|
|
177
|
+
* Used for scope upgrade tracking - if a Singleton service
|
|
178
|
+
* resolves a Request dependency, the scope can be upgraded.
|
|
179
|
+
*
|
|
180
|
+
* @param name The name of the dependency
|
|
181
|
+
* @param scope The scope of the dependency
|
|
182
|
+
*/
|
|
183
|
+
trackDependency(name: string, scope: InjectableScope): void;
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
72
186
|
//#region src/utils/get-injectors.d.mts
|
|
73
187
|
interface Injectors {
|
|
74
188
|
asyncInject<T extends ClassTypeWithoutArguments>(token: T): InstanceType<T> extends Factorable<infer R> ? Promise<R> : Promise<InstanceType<T>>;
|
|
@@ -112,7 +226,7 @@ interface Injectors {
|
|
|
112
226
|
optional<T>(token: BoundInjectionToken<T, any>): T | null;
|
|
113
227
|
optional<T>(token: FactoryInjectionToken<T, any>): T | null;
|
|
114
228
|
wrapSyncInit(cb: () => any): (injectState?: InjectState) => [any, Promise<any>[], InjectState];
|
|
115
|
-
provideFactoryContext(context:
|
|
229
|
+
provideFactoryContext(context: ServiceInitializationContext | null): ServiceInitializationContext | null;
|
|
116
230
|
}
|
|
117
231
|
declare function getInjectors(): Injectors;
|
|
118
232
|
//#endregion
|
|
@@ -133,76 +247,12 @@ interface FactoryContext {
|
|
|
133
247
|
addDestroyListener: (listener: () => void) => void;
|
|
134
248
|
}
|
|
135
249
|
//#endregion
|
|
136
|
-
//#region src/
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
type ClassTypeWithArgument<Arg> = new (arg: Arg) => any;
|
|
140
|
-
type ClassTypeWithOptionalArgument<Arg> = new (arg?: Arg) => any;
|
|
141
|
-
type ClassTypeWithInstance<T> = new (...args: any[]) => T;
|
|
142
|
-
type ClassTypeWithInstanceAndArgument<T, Arg> = new (arg: Arg) => T;
|
|
143
|
-
type ClassTypeWithInstanceAndOptionalArgument<T, Arg> = new (arg?: Arg) => T;
|
|
144
|
-
type BaseInjectionTokenSchemaType = ZodObject | ZodRecord;
|
|
145
|
-
type OptionalInjectionTokenSchemaType = ZodOptional<ZodObject> | ZodOptional<ZodRecord>;
|
|
146
|
-
type InjectionTokenSchemaType = BaseInjectionTokenSchemaType | OptionalInjectionTokenSchemaType;
|
|
147
|
-
declare class InjectionToken<T, S extends InjectionTokenSchemaType | unknown = unknown, Required extends boolean = (S extends ZodOptional<ZodObject> ? false : S extends ZodOptional<ZodRecord> ? false : S extends ZodObject ? true : S extends ZodRecord ? true : false)> {
|
|
148
|
-
readonly name: string | symbol | ClassType;
|
|
149
|
-
readonly schema: ZodObject | undefined;
|
|
150
|
-
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
151
|
-
private formattedName;
|
|
152
|
-
constructor(name: string | symbol | ClassType, schema: ZodObject | undefined);
|
|
153
|
-
static create<T extends ClassType>(name: T): InjectionToken<InstanceType<T>, undefined>;
|
|
154
|
-
static create<T extends ClassType, Schema extends InjectionTokenSchemaType>(name: T, schema: Schema): Schema['_def']['type'] extends 'ZodOptional' ? InjectionToken<InstanceType<T>, Schema, false> : InjectionToken<InstanceType<T>, Schema, true>;
|
|
155
|
-
static create<T>(name: string | symbol): InjectionToken<T, undefined>;
|
|
156
|
-
static create<T, Schema extends InjectionTokenSchemaType>(name: string | any, schema: Schema): InjectionToken<T, Schema>;
|
|
157
|
-
static bound<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, value: z.input<S>): BoundInjectionToken<T, S>;
|
|
158
|
-
static factory<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, factory: (ctx: FactoryContext) => Promise<z.input<S>>): FactoryInjectionToken<T, S>;
|
|
159
|
-
static refineType<T>(token: BoundInjectionToken<any, any>): BoundInjectionToken<T, any>;
|
|
160
|
-
toString(): string;
|
|
161
|
-
}
|
|
162
|
-
declare class BoundInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
163
|
-
readonly token: InjectionToken<T, S>;
|
|
164
|
-
readonly value: z.input<S>;
|
|
165
|
-
id: string;
|
|
166
|
-
name: string | symbol | ClassType;
|
|
167
|
-
schema: InjectionTokenSchemaType;
|
|
168
|
-
constructor(token: InjectionToken<T, S>, value: z.input<S>);
|
|
169
|
-
toString(): string;
|
|
170
|
-
}
|
|
171
|
-
declare class FactoryInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
172
|
-
readonly token: InjectionToken<T, S>;
|
|
173
|
-
readonly factory: (ctx: FactoryContext) => Promise<z.input<S>>;
|
|
174
|
-
value?: z.input<S>;
|
|
175
|
-
resolved: boolean;
|
|
176
|
-
id: string;
|
|
177
|
-
name: string | symbol | ClassType;
|
|
178
|
-
schema: InjectionTokenSchemaType;
|
|
179
|
-
constructor(token: InjectionToken<T, S>, factory: (ctx: FactoryContext) => Promise<z.input<S>>);
|
|
180
|
-
resolve(ctx: FactoryContext): Promise<z.input<S>>;
|
|
181
|
-
toString(): string;
|
|
182
|
-
}
|
|
183
|
-
type AnyInjectableType = ClassType | InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>;
|
|
184
|
-
type InjectionTokenType = InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>;
|
|
185
|
-
//#endregion
|
|
186
|
-
//#region src/enums/injectable-scope.enum.d.mts
|
|
187
|
-
declare enum InjectableScope {
|
|
188
|
-
/**
|
|
189
|
-
* Singleton scope: The instance is created once and shared across the application.
|
|
190
|
-
*/
|
|
191
|
-
Singleton = "Singleton",
|
|
192
|
-
/**
|
|
193
|
-
* Instance scope: A new instance is created for each injection.
|
|
194
|
-
*/
|
|
195
|
-
Transient = "Transient",
|
|
196
|
-
/**
|
|
197
|
-
* Request scope: The instance is created once per request and shared within that request context.
|
|
198
|
-
*/
|
|
199
|
-
Request = "Request",
|
|
250
|
+
//#region src/interfaces/factory.interface.d.mts
|
|
251
|
+
interface Factorable<T> {
|
|
252
|
+
create(ctx?: FactoryContext): Promise<T> | T;
|
|
200
253
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
declare enum InjectableType {
|
|
204
|
-
Class = "Class",
|
|
205
|
-
Factory = "Factory",
|
|
254
|
+
interface FactorableWithArgs<T, A extends InjectionTokenSchemaType> {
|
|
255
|
+
create(ctx?: FactoryContext, ...args: [z.output<A>]): Promise<T> | T;
|
|
206
256
|
}
|
|
207
257
|
//#endregion
|
|
208
258
|
//#region src/token/registry.d.mts
|
|
@@ -211,14 +261,17 @@ type FactoryRecord<Instance = any, Schema = any> = {
|
|
|
211
261
|
originalToken: InjectionToken<Instance, Schema>;
|
|
212
262
|
target: ClassType;
|
|
213
263
|
type: InjectableType;
|
|
264
|
+
priority: number;
|
|
214
265
|
};
|
|
215
266
|
declare class Registry {
|
|
216
267
|
private readonly parent?;
|
|
217
268
|
private readonly factories;
|
|
269
|
+
private readonly highestPriority;
|
|
218
270
|
constructor(parent?: Registry | undefined);
|
|
219
271
|
has(token: InjectionToken<any, any>): boolean;
|
|
220
272
|
get<Instance, Schema>(token: InjectionToken<Instance, Schema>): FactoryRecord<Instance, Schema>;
|
|
221
|
-
|
|
273
|
+
getAll<Instance, Schema>(token: InjectionToken<Instance, Schema>): FactoryRecord<Instance, Schema>[];
|
|
274
|
+
set<Instance, Schema>(token: InjectionToken<Instance, Schema>, scope: InjectableScope, target: ClassType, type: InjectableType, priority?: number): void;
|
|
222
275
|
delete(token: InjectionToken<any, any>): void;
|
|
223
276
|
/**
|
|
224
277
|
* Updates the scope of an already registered factory.
|
|
@@ -233,6 +286,52 @@ declare class Registry {
|
|
|
233
286
|
}
|
|
234
287
|
declare const globalRegistry: Registry;
|
|
235
288
|
//#endregion
|
|
289
|
+
//#region src/internal/core/name-resolver.d.mts
|
|
290
|
+
/**
|
|
291
|
+
* Handles instance name generation with support for requestId and scope.
|
|
292
|
+
*
|
|
293
|
+
* Generates unique instance identifiers based on token, arguments, and scope.
|
|
294
|
+
* Request-scoped services MUST include requestId in their name for proper isolation.
|
|
295
|
+
*/
|
|
296
|
+
declare class NameResolver {
|
|
297
|
+
private readonly logger;
|
|
298
|
+
private readonly instanceNameCache;
|
|
299
|
+
constructor(logger?: Console | null);
|
|
300
|
+
/**
|
|
301
|
+
* Generates a unique instance name based on token, arguments, requestId, and scope.
|
|
302
|
+
*
|
|
303
|
+
* Name formats:
|
|
304
|
+
* - Singleton/Transient without args: `${tokenId}`
|
|
305
|
+
* - Singleton/Transient with args: `${tokenId}:${argsHash}`
|
|
306
|
+
* - Request without args: `${tokenId}:requestId=${requestId}`
|
|
307
|
+
* - Request with args: `${tokenId}:requestId=${requestId}:${argsHash}`
|
|
308
|
+
*
|
|
309
|
+
* @param token The injection token
|
|
310
|
+
* @param args Optional arguments
|
|
311
|
+
* @param requestId Optional request ID (required for request-scoped services)
|
|
312
|
+
* @param scope Optional scope (used to determine if requestId should be included)
|
|
313
|
+
* @returns The generated instance name
|
|
314
|
+
*/
|
|
315
|
+
generateInstanceName(token: InjectionTokenType, args?: any, requestId?: string, scope?: InjectableScope): string;
|
|
316
|
+
/**
|
|
317
|
+
* Upgrades an existing instance name to include requestId.
|
|
318
|
+
* Preserves any args hash that might already be in the name.
|
|
319
|
+
*
|
|
320
|
+
* Examples:
|
|
321
|
+
* - `TokenName` → `TokenName:requestId=req-123`
|
|
322
|
+
* - `TokenName:abc123` → `TokenName:requestId=req-123:abc123`
|
|
323
|
+
*
|
|
324
|
+
* @param existingName The existing instance name (without requestId)
|
|
325
|
+
* @param requestId The request ID to add
|
|
326
|
+
* @returns The upgraded instance name with requestId
|
|
327
|
+
*/
|
|
328
|
+
upgradeInstanceNameToRequest(existingName: string, requestId: string): string;
|
|
329
|
+
/**
|
|
330
|
+
* Formats a single argument value for instance name generation.
|
|
331
|
+
*/
|
|
332
|
+
formatArgValue(value: any): string;
|
|
333
|
+
}
|
|
334
|
+
//#endregion
|
|
236
335
|
//#region src/errors/di-error.d.mts
|
|
237
336
|
declare enum DIErrorCode {
|
|
238
337
|
FactoryNotFound = "FactoryNotFound",
|
|
@@ -240,6 +339,14 @@ declare enum DIErrorCode {
|
|
|
240
339
|
InstanceNotFound = "InstanceNotFound",
|
|
241
340
|
InstanceDestroying = "InstanceDestroying",
|
|
242
341
|
CircularDependency = "CircularDependency",
|
|
342
|
+
TokenValidationError = "TokenValidationError",
|
|
343
|
+
TokenSchemaRequiredError = "TokenSchemaRequiredError",
|
|
344
|
+
ClassNotInjectable = "ClassNotInjectable",
|
|
345
|
+
ScopeMismatchError = "ScopeMismatchError",
|
|
346
|
+
PriorityConflictError = "PriorityConflictError",
|
|
347
|
+
StorageError = "StorageError",
|
|
348
|
+
InitializationError = "InitializationError",
|
|
349
|
+
DependencyResolutionError = "DependencyResolutionError",
|
|
243
350
|
UnknownError = "UnknownError",
|
|
244
351
|
}
|
|
245
352
|
declare class DIError extends Error {
|
|
@@ -253,6 +360,14 @@ declare class DIError extends Error {
|
|
|
253
360
|
static instanceDestroying(name: string): DIError;
|
|
254
361
|
static unknown(message: string | Error, context?: Record<string, unknown>): DIError;
|
|
255
362
|
static circularDependency(cycle: string[]): DIError;
|
|
363
|
+
static tokenValidationError(message: string, schema: InjectionTokenSchemaType | undefined, value: unknown): DIError;
|
|
364
|
+
static tokenSchemaRequiredError(token: string | symbol | unknown): DIError;
|
|
365
|
+
static classNotInjectable(className: string): DIError;
|
|
366
|
+
static scopeMismatchError(token: string | symbol | unknown, expectedScope: string, actualScope: string): DIError;
|
|
367
|
+
static priorityConflictError(token: string | symbol | unknown, records: FactoryRecord[]): DIError;
|
|
368
|
+
static storageError(message: string, operation: string, instanceName?: string): DIError;
|
|
369
|
+
static initializationError(serviceName: string, error: Error | string): DIError;
|
|
370
|
+
static dependencyResolutionError(serviceName: string, dependencyName: string, error: Error | string): DIError;
|
|
256
371
|
}
|
|
257
372
|
//#endregion
|
|
258
373
|
//#region src/internal/holder/instance-holder.d.mts
|
|
@@ -269,8 +384,6 @@ declare enum InstanceStatus {
|
|
|
269
384
|
/** Instance creation failed with an error */
|
|
270
385
|
Error = "error",
|
|
271
386
|
}
|
|
272
|
-
/** Callback function for instance effects */
|
|
273
|
-
type InstanceEffect = () => void;
|
|
274
387
|
/** Callback function for instance destruction listeners */
|
|
275
388
|
type InstanceDestroyListener = () => void | Promise<void>;
|
|
276
389
|
/**
|
|
@@ -365,8 +478,7 @@ type HolderGetResult<T = unknown> = [undefined, InstanceHolder<T>] | [DIError, I
|
|
|
365
478
|
* Interface for abstracting holder storage operations.
|
|
366
479
|
*
|
|
367
480
|
* Enables unified instance resolution logic regardless of where
|
|
368
|
-
* holders are stored
|
|
369
|
-
* This is the key abstraction for the Storage Strategy pattern.
|
|
481
|
+
* holders are stored. This is the key abstraction for the unified storage pattern.
|
|
370
482
|
*/
|
|
371
483
|
interface IHolderStorage {
|
|
372
484
|
/**
|
|
@@ -435,223 +547,296 @@ interface IHolderStorage {
|
|
|
435
547
|
* @returns Array of instance names that have this instance as a dependency
|
|
436
548
|
*/
|
|
437
549
|
findDependents(instanceName: string): string[];
|
|
550
|
+
/**
|
|
551
|
+
* Updates dependency references when instance names change.
|
|
552
|
+
* Used during scope upgrades when instance names are regenerated with requestId.
|
|
553
|
+
*
|
|
554
|
+
* @param oldName The old instance name
|
|
555
|
+
* @param newName The new instance name
|
|
556
|
+
*/
|
|
557
|
+
updateDependencyReference(oldName: string, newName: string): void;
|
|
438
558
|
}
|
|
439
559
|
//#endregion
|
|
440
|
-
//#region src/internal/
|
|
560
|
+
//#region src/internal/lifecycle/lifecycle-event-bus.d.mts
|
|
441
561
|
/**
|
|
442
|
-
*
|
|
443
|
-
*
|
|
562
|
+
* Event bus for service lifecycle events (create, destroy, etc.).
|
|
563
|
+
*
|
|
564
|
+
* Enables loose coupling between services by allowing them to subscribe
|
|
565
|
+
* to lifecycle events of their dependencies without direct references.
|
|
566
|
+
* Used primarily for invalidation cascading.
|
|
444
567
|
*/
|
|
445
|
-
|
|
568
|
+
declare class LifecycleEventBus {
|
|
569
|
+
private readonly logger;
|
|
570
|
+
private listeners;
|
|
571
|
+
constructor(logger?: Console | null);
|
|
572
|
+
on<Event extends string | `pre:${string}` | `post:${string}`>(ns: string, event: Event, listener: (event: Event) => void): () => void;
|
|
573
|
+
emit(key: string, event: string): Promise<PromiseSettledResult<any>[] | undefined>;
|
|
574
|
+
}
|
|
575
|
+
//#endregion
|
|
576
|
+
//#region src/internal/core/service-invalidator.d.mts
|
|
577
|
+
interface ClearAllOptions {
|
|
578
|
+
/** Whether to wait for all services to settle before starting (default: true) */
|
|
579
|
+
waitForSettlement?: boolean;
|
|
580
|
+
}
|
|
581
|
+
interface InvalidationOptions {
|
|
582
|
+
/** Whether to emit events after invalidation (default: true) */
|
|
583
|
+
emitEvents?: boolean;
|
|
584
|
+
/** Custom event emitter function */
|
|
585
|
+
onInvalidated?: (instanceName: string) => Promise<void>;
|
|
586
|
+
/** Whether to cascade invalidation to dependents (default: false - events handle it) */
|
|
587
|
+
cascade?: boolean;
|
|
588
|
+
}
|
|
446
589
|
/**
|
|
447
|
-
*
|
|
590
|
+
* Manages graceful service cleanup with event-based invalidation.
|
|
448
591
|
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
592
|
+
* Uses event subscriptions instead of manual dependent finding.
|
|
593
|
+
* When a service is created, it subscribes to destroy events of its dependencies.
|
|
594
|
+
* When a dependency is destroyed, the event automatically invalidates dependents.
|
|
451
595
|
*/
|
|
452
|
-
declare
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
constructor(logger?: Console | null);
|
|
456
|
-
/**
|
|
457
|
-
* Protected getter for accessing the holders map from subclasses.
|
|
458
|
-
*/
|
|
459
|
-
protected get holders(): Map<string, InstanceHolder>;
|
|
460
|
-
/**
|
|
461
|
-
* Abstract method to get a holder by name. Each implementation defines its own return type
|
|
462
|
-
* based on their specific error handling and validation needs.
|
|
463
|
-
*/
|
|
464
|
-
abstract get(name: string): any;
|
|
596
|
+
declare class ServiceInvalidator {
|
|
597
|
+
private readonly eventBus;
|
|
598
|
+
private readonly logger;
|
|
599
|
+
constructor(eventBus: LifecycleEventBus | null, logger?: Console | null);
|
|
465
600
|
/**
|
|
466
|
-
*
|
|
601
|
+
* Invalidates a service using a specific storage.
|
|
602
|
+
* Event-based invalidation means dependents are automatically invalidated
|
|
603
|
+
* via destroy event subscriptions - no need to manually find dependents.
|
|
604
|
+
*
|
|
605
|
+
* @param service The instance name to invalidate
|
|
606
|
+
* @param storage The storage to use for this invalidation
|
|
607
|
+
* @param options Additional options for invalidation behavior
|
|
467
608
|
*/
|
|
468
|
-
|
|
609
|
+
invalidateWithStorage(service: string, storage: IHolderStorage, options?: InvalidationOptions): Promise<void>;
|
|
469
610
|
/**
|
|
470
|
-
*
|
|
611
|
+
* Sets up destroy event subscriptions for a service's dependencies.
|
|
612
|
+
* Called when a service is successfully instantiated.
|
|
613
|
+
*
|
|
614
|
+
* @param serviceName The name of the service
|
|
615
|
+
* @param dependencies The set of dependency names
|
|
616
|
+
* @param storage The storage to use for invalidation
|
|
617
|
+
* @param holder The holder for the service (to add unsubscribe to destroy listeners)
|
|
471
618
|
*/
|
|
472
|
-
|
|
619
|
+
setupDependencySubscriptions(serviceName: string, dependencies: Set<string>, storage: IHolderStorage, holder: InstanceHolder): void;
|
|
473
620
|
/**
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
* @returns true if the holder was deleted, false if it didn't exist
|
|
621
|
+
* Gracefully clears all services in a specific storage.
|
|
622
|
+
* This allows clearing request-scoped services using a RequestStorage.
|
|
477
623
|
*/
|
|
478
|
-
|
|
624
|
+
clearAllWithStorage(storage: IHolderStorage, options?: ClearAllOptions): Promise<void>;
|
|
479
625
|
/**
|
|
480
|
-
*
|
|
481
|
-
* @param predicate Function to test each holder
|
|
482
|
-
* @returns A new Map containing only the holders that match the predicate
|
|
626
|
+
* Waits for all services in a specific storage to settle.
|
|
483
627
|
*/
|
|
484
|
-
|
|
628
|
+
readyWithStorage(storage: IHolderStorage): Promise<void>;
|
|
485
629
|
/**
|
|
486
|
-
*
|
|
630
|
+
* Invalidates a single holder using a specific storage.
|
|
487
631
|
*/
|
|
488
|
-
|
|
632
|
+
private invalidateHolderWithStorage;
|
|
489
633
|
/**
|
|
490
|
-
*
|
|
634
|
+
* Common invalidation logic for holders based on their status.
|
|
491
635
|
*/
|
|
492
|
-
|
|
636
|
+
private invalidateHolderByStatus;
|
|
493
637
|
/**
|
|
494
|
-
*
|
|
495
|
-
* This is useful for creating placeholder holders that can be fulfilled later.
|
|
496
|
-
* @param name The name of the instance
|
|
497
|
-
* @param type The injectable type
|
|
498
|
-
* @param scope The injectable scope
|
|
499
|
-
* @param deps Optional set of dependencies
|
|
500
|
-
* @returns A tuple containing the deferred promise and the holder
|
|
638
|
+
* Destroys a holder using a specific storage.
|
|
501
639
|
*/
|
|
502
|
-
|
|
640
|
+
private destroyHolderWithStorage;
|
|
503
641
|
/**
|
|
504
|
-
*
|
|
505
|
-
* This is useful for creating holders that already have their instance ready.
|
|
506
|
-
* @param name The name of the instance
|
|
507
|
-
* @param instance The actual instance to store
|
|
508
|
-
* @param type The injectable type
|
|
509
|
-
* @param scope The injectable scope
|
|
510
|
-
* @param deps Optional set of dependencies
|
|
511
|
-
* @returns The created holder
|
|
642
|
+
* Waits for a holder to settle (either created, destroyed, or error state).
|
|
512
643
|
*/
|
|
513
|
-
|
|
644
|
+
private waitForHolderToSettle;
|
|
514
645
|
/**
|
|
515
|
-
*
|
|
646
|
+
* Emits events to listeners for instance lifecycle events.
|
|
516
647
|
*/
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
648
|
+
private emitInstanceEvent;
|
|
649
|
+
}
|
|
650
|
+
//#endregion
|
|
651
|
+
//#region src/internal/core/token-resolver.d.mts
|
|
652
|
+
/**
|
|
653
|
+
* Handles token validation and resolution.
|
|
654
|
+
*
|
|
655
|
+
* Focuses on token validation, normalization, and argument validation.
|
|
656
|
+
* Name generation is handled by NameResolver.
|
|
657
|
+
*/
|
|
658
|
+
declare class TokenResolver {
|
|
659
|
+
private readonly logger;
|
|
660
|
+
constructor(logger?: Console | null);
|
|
661
|
+
/**
|
|
662
|
+
* Normalizes a token to an InjectionToken.
|
|
663
|
+
* Handles class constructors by getting their injectable token.
|
|
664
|
+
*
|
|
665
|
+
* @param token A class constructor, InjectionToken, BoundInjectionToken, or FactoryInjectionToken
|
|
666
|
+
* @returns The normalized InjectionTokenType
|
|
520
667
|
*/
|
|
521
|
-
|
|
668
|
+
normalizeToken(token: AnyInjectableType): InjectionTokenType;
|
|
522
669
|
/**
|
|
523
|
-
*
|
|
670
|
+
* Gets the underlying "real" token from wrapped tokens.
|
|
671
|
+
* For BoundInjectionToken and FactoryInjectionToken, returns the wrapped token.
|
|
672
|
+
* For other tokens, returns the token itself.
|
|
673
|
+
*
|
|
674
|
+
* @param token The token to unwrap
|
|
675
|
+
* @returns The underlying InjectionToken
|
|
524
676
|
*/
|
|
525
|
-
|
|
677
|
+
getRealToken<T = unknown>(token: InjectionTokenType): InjectionToken<T>;
|
|
526
678
|
/**
|
|
527
|
-
*
|
|
528
|
-
*
|
|
679
|
+
* Convenience method that normalizes a token and then gets the real token.
|
|
680
|
+
* Useful for checking registry entries where you need the actual registered token.
|
|
529
681
|
*
|
|
530
|
-
* @param
|
|
531
|
-
* @
|
|
532
|
-
* @param getHolder Optional function to retrieve holders by name (required if waiterHolder is provided)
|
|
533
|
-
* @returns A promise that resolves with [undefined, holder] on success or [DIError] on failure
|
|
682
|
+
* @param token Any injectable type
|
|
683
|
+
* @returns The underlying InjectionToken
|
|
534
684
|
*/
|
|
535
|
-
|
|
685
|
+
getRegistryToken<T = unknown>(token: AnyInjectableType): InjectionToken<T>;
|
|
686
|
+
/**
|
|
687
|
+
* Validates and resolves token arguments, handling factory token resolution and validation.
|
|
688
|
+
*
|
|
689
|
+
* @param token The token to validate
|
|
690
|
+
* @param args Optional arguments
|
|
691
|
+
* @returns [error, { actualToken, validatedArgs }]
|
|
692
|
+
*/
|
|
693
|
+
validateAndResolveTokenArgs(token: AnyInjectableType, args?: any): [DIError | undefined, {
|
|
694
|
+
actualToken: InjectionTokenType;
|
|
695
|
+
validatedArgs?: any;
|
|
696
|
+
}];
|
|
536
697
|
}
|
|
537
698
|
//#endregion
|
|
538
|
-
//#region src/internal/
|
|
699
|
+
//#region src/internal/holder/unified-storage.d.mts
|
|
539
700
|
/**
|
|
540
|
-
*
|
|
701
|
+
* Unified storage implementation that works the same way regardless of scope.
|
|
702
|
+
* Replaces RequestContext, HolderManager, SingletonStorage, RequestStorage.
|
|
541
703
|
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
704
|
+
* Scope is just metadata - storage operations are identical for all scopes.
|
|
705
|
+
* Different storage instances are just isolated storage spaces.
|
|
544
706
|
*/
|
|
545
|
-
|
|
707
|
+
declare class UnifiedStorage implements IHolderStorage {
|
|
708
|
+
readonly scope: InjectableScope;
|
|
709
|
+
private readonly holders;
|
|
546
710
|
/**
|
|
547
|
-
*
|
|
711
|
+
* Reverse dependency index: maps a dependency name to the set of holder names that depend on it.
|
|
712
|
+
* This allows O(1) lookup of dependents instead of O(n) iteration.
|
|
548
713
|
*/
|
|
549
|
-
readonly
|
|
714
|
+
private readonly dependents;
|
|
715
|
+
constructor(scope?: InjectableScope);
|
|
716
|
+
get<T = unknown>(instanceName: string): HolderGetResult<T>;
|
|
717
|
+
set(instanceName: string, holder: InstanceHolder): void;
|
|
718
|
+
delete(instanceName: string): boolean;
|
|
719
|
+
createHolder<T>(instanceName: string, type: InjectableType, deps: Set<string>): [ReturnType<typeof Promise.withResolvers<[undefined, T]>>, InstanceHolder<T>];
|
|
720
|
+
storeInstance(instanceName: string, instance: unknown): void;
|
|
721
|
+
handles(scope: InjectableScope): boolean;
|
|
722
|
+
getAllNames(): string[];
|
|
723
|
+
forEach(callback: (name: string, holder: InstanceHolder) => void): void;
|
|
724
|
+
findByInstance(instance: unknown): InstanceHolder | null;
|
|
725
|
+
findDependents(instanceName: string): string[];
|
|
550
726
|
/**
|
|
551
|
-
*
|
|
727
|
+
* Updates dependency references when instance names change.
|
|
728
|
+
* Used during scope upgrades when instance names are regenerated with requestId.
|
|
729
|
+
*
|
|
730
|
+
* @param oldName The old instance name
|
|
731
|
+
* @param newName The new instance name
|
|
552
732
|
*/
|
|
553
|
-
|
|
733
|
+
updateDependencyReference(oldName: string, newName: string): void;
|
|
554
734
|
/**
|
|
555
|
-
*
|
|
556
|
-
* Higher values take precedence.
|
|
735
|
+
* Registers a holder's dependencies in the reverse index.
|
|
557
736
|
*/
|
|
558
|
-
|
|
737
|
+
private registerDependencies;
|
|
559
738
|
/**
|
|
560
|
-
*
|
|
739
|
+
* Removes a holder from the reverse dependency index.
|
|
561
740
|
*/
|
|
562
|
-
|
|
741
|
+
private removeFromDependentsIndex;
|
|
742
|
+
}
|
|
743
|
+
//#endregion
|
|
744
|
+
//#region src/container/abstract-container.d.mts
|
|
745
|
+
/**
|
|
746
|
+
* Abstract base class for dependency injection containers.
|
|
747
|
+
*
|
|
748
|
+
* Provides shared implementation for common container operations.
|
|
749
|
+
* Both Container and ScopedContainer extend this class.
|
|
750
|
+
*/
|
|
751
|
+
declare abstract class AbstractContainer implements IContainer {
|
|
563
752
|
/**
|
|
564
|
-
*
|
|
753
|
+
* The default scope used when adding instances without explicit registration.
|
|
565
754
|
*/
|
|
566
|
-
readonly
|
|
755
|
+
protected abstract readonly defaultScope: InjectableScope;
|
|
567
756
|
/**
|
|
568
|
-
*
|
|
757
|
+
* The request ID for scoped containers, undefined for root container.
|
|
569
758
|
*/
|
|
570
|
-
|
|
759
|
+
protected abstract readonly requestId: string | undefined;
|
|
571
760
|
/**
|
|
572
|
-
*
|
|
761
|
+
* Gets the storage for this container.
|
|
573
762
|
*/
|
|
574
|
-
|
|
763
|
+
abstract getStorage(): UnifiedStorage;
|
|
575
764
|
/**
|
|
576
|
-
* Gets
|
|
765
|
+
* Gets the registry for this container.
|
|
577
766
|
*/
|
|
578
|
-
|
|
767
|
+
protected abstract getRegistry(): Registry;
|
|
579
768
|
/**
|
|
580
|
-
*
|
|
769
|
+
* Gets the token resolver.
|
|
581
770
|
*/
|
|
582
|
-
|
|
771
|
+
protected abstract getTokenResolver(): TokenResolver;
|
|
583
772
|
/**
|
|
584
|
-
*
|
|
773
|
+
* Gets the name resolver.
|
|
585
774
|
*/
|
|
586
|
-
|
|
775
|
+
protected abstract getNameResolver(): NameResolver;
|
|
587
776
|
/**
|
|
588
|
-
*
|
|
777
|
+
* Gets the service invalidator.
|
|
589
778
|
*/
|
|
590
|
-
|
|
779
|
+
protected abstract getServiceInvalidator(): ServiceInvalidator;
|
|
591
780
|
/**
|
|
592
|
-
* Gets
|
|
781
|
+
* Gets an instance from the container.
|
|
593
782
|
*/
|
|
594
|
-
|
|
783
|
+
abstract get<T extends ClassType>(token: T): InstanceType<T> extends Factorable<infer R> ? Promise<R> : Promise<InstanceType<T>>;
|
|
784
|
+
abstract get<T extends ClassTypeWithArgument<R>, R>(token: T, args: R): Promise<InstanceType<T>>;
|
|
785
|
+
abstract get<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): Promise<T>;
|
|
786
|
+
abstract get<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';
|
|
787
|
+
abstract get<T>(token: InjectionToken<T, undefined>): Promise<T>;
|
|
788
|
+
abstract get<T>(token: BoundInjectionToken<T, any>): Promise<T>;
|
|
789
|
+
abstract get<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
|
|
595
790
|
/**
|
|
596
|
-
*
|
|
791
|
+
* Invalidates a service and its dependencies.
|
|
597
792
|
*/
|
|
598
|
-
|
|
793
|
+
abstract invalidate(service: unknown): Promise<void>;
|
|
599
794
|
/**
|
|
600
|
-
*
|
|
795
|
+
* Disposes the container and cleans up all resources.
|
|
601
796
|
*/
|
|
602
|
-
|
|
797
|
+
abstract dispose(): Promise<void>;
|
|
603
798
|
/**
|
|
604
|
-
*
|
|
799
|
+
* Calculates the instance name for a given token and optional arguments.
|
|
800
|
+
*
|
|
801
|
+
* @internal
|
|
802
|
+
* @param token The class type, InjectionToken, BoundInjectionToken, or FactoryInjectionToken
|
|
803
|
+
* @param args Optional arguments (ignored for BoundInjectionToken which uses its bound value)
|
|
804
|
+
* @returns The calculated instance name string, or null if the token is a FactoryInjectionToken that is not yet resolved
|
|
605
805
|
*/
|
|
606
|
-
|
|
806
|
+
calculateInstanceName(token: ClassType | InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>, args?: unknown): string | null;
|
|
607
807
|
/**
|
|
608
|
-
*
|
|
808
|
+
* Checks if a service is registered in the container.
|
|
609
809
|
*/
|
|
610
|
-
|
|
810
|
+
isRegistered(token: any): boolean;
|
|
611
811
|
/**
|
|
612
|
-
*
|
|
812
|
+
* Waits for all pending operations to complete.
|
|
613
813
|
*/
|
|
614
|
-
|
|
615
|
-
}
|
|
616
|
-
/** @deprecated Use RequestContext instead */
|
|
617
|
-
type RequestContextHolder = RequestContext;
|
|
618
|
-
/**
|
|
619
|
-
* Default implementation of RequestContext.
|
|
620
|
-
*
|
|
621
|
-
* Extends BaseHolderManager to provide holder management functionality
|
|
622
|
-
* with request-specific metadata and lifecycle support.
|
|
623
|
-
*/
|
|
624
|
-
declare class DefaultRequestContext extends BaseHolderManager implements RequestContext {
|
|
625
|
-
readonly requestId: string;
|
|
626
|
-
readonly priority: number;
|
|
627
|
-
readonly metadata: Map<string, any>;
|
|
628
|
-
readonly createdAt: number;
|
|
629
|
-
constructor(requestId: string, priority?: number, initialMetadata?: Record<string, any>);
|
|
814
|
+
ready(): Promise<void>;
|
|
630
815
|
/**
|
|
631
|
-
*
|
|
816
|
+
* @internal
|
|
817
|
+
* Attempts to get an instance synchronously if it already exists.
|
|
632
818
|
*/
|
|
633
|
-
|
|
819
|
+
tryGetSync<T>(token: any, args?: any): T | null;
|
|
634
820
|
/**
|
|
635
|
-
*
|
|
821
|
+
* @internal
|
|
822
|
+
* Internal method for getting instances synchronously with configurable storage.
|
|
636
823
|
*/
|
|
637
|
-
|
|
824
|
+
protected tryGetSyncFromStorage<T>(token: any, args: any, storage: UnifiedStorage, requestId?: string): T | null;
|
|
638
825
|
/**
|
|
639
|
-
*
|
|
826
|
+
* Adds an instance to the container.
|
|
827
|
+
* Accepts class types, InjectionTokens, and BoundInjectionTokens.
|
|
828
|
+
* Rejects InjectionTokens with required schemas (use BoundInjectionToken instead).
|
|
829
|
+
*
|
|
830
|
+
* @param token The class type, InjectionToken, or BoundInjectionToken to register the instance for
|
|
831
|
+
* @param instance The instance to store
|
|
640
832
|
*/
|
|
641
|
-
|
|
833
|
+
addInstance<T>(token: ClassType | InjectionToken<T, any> | BoundInjectionToken<T, any>, instance: T): void;
|
|
642
834
|
/**
|
|
643
|
-
*
|
|
835
|
+
* @internal
|
|
836
|
+
* Internal method for adding instances with configurable scope and storage.
|
|
644
837
|
*/
|
|
645
|
-
|
|
646
|
-
addInstance(instanceName: string | InjectionToken<any, undefined>, instance: any, holder?: InstanceHolder): void;
|
|
647
|
-
clear(): void;
|
|
648
|
-
getMetadata(key: string): any | undefined;
|
|
649
|
-
setMetadata(key: string, value: any): void;
|
|
838
|
+
protected addInstanceToStorage<T>(token: ClassType | InjectionToken<T, any> | BoundInjectionToken<T, any>, instance: T, storage: UnifiedStorage, scope: InjectableScope, requestId?: string): void;
|
|
650
839
|
}
|
|
651
|
-
/**
|
|
652
|
-
* Creates a new request context with the given parameters.
|
|
653
|
-
*/
|
|
654
|
-
declare function createRequestContext(requestId: string, priority?: number, initialMetadata?: Record<string, any>): RequestContext;
|
|
655
840
|
//#endregion
|
|
656
841
|
//#region src/container/scoped-container.d.mts
|
|
657
842
|
/**
|
|
@@ -662,23 +847,20 @@ declare function createRequestContext(requestId: string, priority?: number, init
|
|
|
662
847
|
* This design eliminates race conditions that can occur with async operations
|
|
663
848
|
* when multiple requests are processed concurrently.
|
|
664
849
|
*/
|
|
665
|
-
declare class ScopedContainer
|
|
850
|
+
declare class ScopedContainer extends AbstractContainer {
|
|
666
851
|
private readonly parent;
|
|
667
852
|
private readonly registry;
|
|
668
853
|
readonly requestId: string;
|
|
669
|
-
|
|
670
|
-
private readonly
|
|
854
|
+
protected readonly defaultScope = InjectableScope.Request;
|
|
855
|
+
private readonly storage;
|
|
671
856
|
private disposed;
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
* Used by InstanceResolver for request-scoped resolution.
|
|
680
|
-
*/
|
|
681
|
-
getHolderStorage(): IHolderStorage;
|
|
857
|
+
private readonly metadata;
|
|
858
|
+
constructor(parent: Container, registry: Registry, requestId: string, metadata?: Record<string, any>);
|
|
859
|
+
getStorage(): UnifiedStorage;
|
|
860
|
+
protected getRegistry(): Registry;
|
|
861
|
+
protected getTokenResolver(): TokenResolver;
|
|
862
|
+
protected getNameResolver(): NameResolver;
|
|
863
|
+
protected getServiceInvalidator(): ServiceInvalidator;
|
|
682
864
|
/**
|
|
683
865
|
* Gets the request ID for this scoped container.
|
|
684
866
|
*/
|
|
@@ -695,13 +877,9 @@ declare class ScopedContainer implements IContainer {
|
|
|
695
877
|
* Sets metadata on the request context.
|
|
696
878
|
*/
|
|
697
879
|
setMetadata(key: string, value: any): void;
|
|
698
|
-
/**
|
|
699
|
-
* Adds a pre-prepared instance to the request context.
|
|
700
|
-
*/
|
|
701
|
-
addInstance(token: InjectionToken<any, undefined>, instance: any): void;
|
|
702
880
|
/**
|
|
703
881
|
* Gets an instance from the container.
|
|
704
|
-
* Request-scoped services are resolved from this container's
|
|
882
|
+
* Request-scoped services are resolved from this container's storage.
|
|
705
883
|
* All other services are delegated to the parent container.
|
|
706
884
|
*/
|
|
707
885
|
get<T extends ClassType>(token: T): InstanceType<T> extends Factorable<infer R> ? Promise<R> : Promise<InstanceType<T>>;
|
|
@@ -713,352 +891,251 @@ declare class ScopedContainer implements IContainer {
|
|
|
713
891
|
get<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
|
|
714
892
|
/**
|
|
715
893
|
* Invalidates a service and its dependencies.
|
|
716
|
-
* For request-scoped services, invalidation is handled within this context.
|
|
717
894
|
*/
|
|
718
895
|
invalidate(service: unknown): Promise<void>;
|
|
719
896
|
/**
|
|
720
|
-
*
|
|
721
|
-
|
|
722
|
-
isRegistered(token: any): boolean;
|
|
723
|
-
/**
|
|
724
|
-
* Disposes this scoped container and cleans up all request-scoped instances.
|
|
725
|
-
* This is an alias for endRequest() for IContainer compatibility.
|
|
897
|
+
* Disposes the container and cleans up all resources.
|
|
898
|
+
* Alias for endRequest().
|
|
726
899
|
*/
|
|
727
900
|
dispose(): Promise<void>;
|
|
728
|
-
/**
|
|
729
|
-
* Ends the request and cleans up all request-scoped instances.
|
|
730
|
-
* Uses the invalidation system to properly cascade to dependent singletons.
|
|
731
|
-
*/
|
|
732
|
-
endRequest(): Promise<void>;
|
|
733
|
-
/**
|
|
734
|
-
* Waits for all pending operations to complete.
|
|
735
|
-
*/
|
|
736
|
-
ready(): Promise<void>;
|
|
737
901
|
/**
|
|
738
902
|
* @internal
|
|
739
|
-
* Attempts to get an instance synchronously if it already exists
|
|
740
|
-
*
|
|
741
|
-
* For other services, delegates to the parent container.
|
|
742
|
-
*
|
|
743
|
-
* Returns null if the instance doesn't exist or is not yet ready (still creating).
|
|
903
|
+
* Attempts to get an instance synchronously if it already exists.
|
|
904
|
+
* Checks request storage first, then delegates to parent.
|
|
744
905
|
*/
|
|
745
906
|
tryGetSync<T>(token: any, args?: any): T | null;
|
|
746
907
|
/**
|
|
747
|
-
*
|
|
748
|
-
|
|
749
|
-
private isRequestScoped;
|
|
750
|
-
/**
|
|
751
|
-
* Resolves a request-scoped service from this container's context.
|
|
752
|
-
* Uses locking to prevent duplicate initialization during concurrent resolution.
|
|
753
|
-
*/
|
|
754
|
-
private resolveRequestScoped;
|
|
755
|
-
/**
|
|
756
|
-
* Stores an instance in the request context.
|
|
757
|
-
* Called by Container during request-scoped service resolution.
|
|
758
|
-
*/
|
|
759
|
-
storeRequestInstance(instanceName: string, instance: any, holder: InstanceHolder): void;
|
|
760
|
-
/**
|
|
761
|
-
* Gets an existing instance from the request context.
|
|
762
|
-
* Called by Container during resolution to check for existing instances.
|
|
908
|
+
* Adds an instance to the container.
|
|
909
|
+
* Overrides base class to check disposed state.
|
|
763
910
|
*/
|
|
764
|
-
|
|
911
|
+
addInstance<T>(token: ClassType | InjectionToken<T, any> | BoundInjectionToken<T, any>, instance: T): void;
|
|
765
912
|
/**
|
|
766
|
-
*
|
|
767
|
-
* Format: {requestId}:{instanceName}
|
|
913
|
+
* Ends the request and cleans up all request-scoped services.
|
|
768
914
|
*/
|
|
769
|
-
|
|
770
|
-
}
|
|
771
|
-
//#endregion
|
|
772
|
-
//#region src/internal/lifecycle/lifecycle-event-bus.d.mts
|
|
773
|
-
/**
|
|
774
|
-
* Event bus for service lifecycle events (create, destroy, etc.).
|
|
775
|
-
*
|
|
776
|
-
* Enables loose coupling between services by allowing them to subscribe
|
|
777
|
-
* to lifecycle events of their dependencies without direct references.
|
|
778
|
-
* Used primarily for invalidation cascading.
|
|
779
|
-
*/
|
|
780
|
-
declare class LifecycleEventBus {
|
|
781
|
-
private readonly logger;
|
|
782
|
-
private listeners;
|
|
783
|
-
constructor(logger?: Console | null);
|
|
784
|
-
on<Event extends string | `pre:${string}` | `post:${string}`>(ns: string, event: Event, listener: (event: Event) => void): () => void;
|
|
785
|
-
emit(key: string, event: string): Promise<PromiseSettledResult<any>[] | undefined>;
|
|
786
|
-
}
|
|
787
|
-
//#endregion
|
|
788
|
-
//#region src/internal/holder/holder-manager.d.mts
|
|
789
|
-
/**
|
|
790
|
-
* Manages the storage and retrieval of singleton instance holders.
|
|
791
|
-
*
|
|
792
|
-
* Provides CRUD operations and filtering for the holder map.
|
|
793
|
-
* Handles holder state validation (destroying, error states) on retrieval.
|
|
794
|
-
*/
|
|
795
|
-
declare class HolderManager extends BaseHolderManager {
|
|
796
|
-
constructor(logger?: Console | null);
|
|
797
|
-
get(name: string): [DIError, InstanceHolder] | [DIError] | [undefined, InstanceHolder];
|
|
798
|
-
set(name: string, holder: InstanceHolder): void;
|
|
799
|
-
has(name: string): [DIError] | [undefined, boolean];
|
|
800
|
-
/**
|
|
801
|
-
* Creates a new holder with Created status and stores it.
|
|
802
|
-
* This is useful for creating holders that already have their instance ready.
|
|
803
|
-
* @param name The name of the instance
|
|
804
|
-
* @param instance The actual instance to store
|
|
805
|
-
* @param type The injectable type
|
|
806
|
-
* @param scope The injectable scope
|
|
807
|
-
* @param deps Optional set of dependencies
|
|
808
|
-
* @returns The created holder
|
|
809
|
-
*/
|
|
810
|
-
storeCreatedHolder<Instance>(name: string, instance: Instance, type: InjectableType, scope: InjectableScope, deps?: Set<string>): InstanceHolder<Instance>;
|
|
915
|
+
endRequest(): Promise<void>;
|
|
811
916
|
}
|
|
812
917
|
//#endregion
|
|
813
|
-
//#region src/internal/core/
|
|
814
|
-
interface ClearAllOptions {
|
|
815
|
-
/** Maximum number of invalidation rounds to prevent infinite loops (default: 10) */
|
|
816
|
-
maxRounds?: number;
|
|
817
|
-
/** Whether to wait for all services to settle before starting (default: true) */
|
|
818
|
-
waitForSettlement?: boolean;
|
|
819
|
-
}
|
|
820
|
-
interface InvalidationOptions {
|
|
821
|
-
/** Whether to emit events after invalidation (default: true for singletons) */
|
|
822
|
-
emitEvents?: boolean;
|
|
823
|
-
/** Custom event emitter function */
|
|
824
|
-
onInvalidated?: (instanceName: string) => Promise<void>;
|
|
825
|
-
/** Whether to cascade invalidation to dependents (default: true) */
|
|
826
|
-
cascade?: boolean;
|
|
827
|
-
/** Internal: tracks services being invalidated in the current call chain to prevent circular loops */
|
|
828
|
-
_invalidating?: Set<string>;
|
|
829
|
-
}
|
|
918
|
+
//#region src/internal/core/scope-tracker.d.mts
|
|
830
919
|
/**
|
|
831
|
-
*
|
|
920
|
+
* Component for tracking and handling scope upgrades.
|
|
832
921
|
*
|
|
833
|
-
*
|
|
834
|
-
*
|
|
835
|
-
* for both singleton and request-scoped services.
|
|
922
|
+
* Detects when a Singleton service needs to be upgraded to Request scope
|
|
923
|
+
* and coordinates the scope upgrade process atomically.
|
|
836
924
|
*/
|
|
837
|
-
declare class
|
|
838
|
-
private readonly
|
|
925
|
+
declare class ScopeTracker {
|
|
926
|
+
private readonly registry;
|
|
927
|
+
private readonly nameResolver;
|
|
839
928
|
private readonly logger;
|
|
840
|
-
|
|
841
|
-
constructor(manager: HolderManager, eventBus: LifecycleEventBus | null, logger?: Console | null);
|
|
929
|
+
constructor(registry: Registry, nameResolver: NameResolver, logger?: Console | null);
|
|
842
930
|
/**
|
|
843
|
-
*
|
|
844
|
-
*
|
|
845
|
-
*/
|
|
846
|
-
invalidate(service: string, round?: number): Promise<any>;
|
|
847
|
-
/**
|
|
848
|
-
* Invalidates a service using a specific storage.
|
|
849
|
-
* This allows request-scoped invalidation using a RequestStorage.
|
|
931
|
+
* Checks if a dependency requires scope upgrade and performs it if needed.
|
|
932
|
+
* Called during service resolution when a dependency is resolved.
|
|
850
933
|
*
|
|
851
|
-
* @param
|
|
852
|
-
* @param
|
|
853
|
-
* @param
|
|
854
|
-
* @param
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
*
|
|
859
|
-
*
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
*
|
|
865
|
-
*
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
*
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
/**
|
|
873
|
-
* Waits for all services in a specific storage to settle.
|
|
874
|
-
*/
|
|
875
|
-
readyWithStorage(storage: IHolderStorage): Promise<void>;
|
|
876
|
-
/**
|
|
877
|
-
* Invalidates a single holder using a specific storage.
|
|
878
|
-
*/
|
|
879
|
-
private invalidateHolderWithStorage;
|
|
880
|
-
/**
|
|
881
|
-
* Common invalidation logic for holders based on their status.
|
|
882
|
-
*/
|
|
883
|
-
private invalidateHolderByStatus;
|
|
884
|
-
/**
|
|
885
|
-
* Destroys a holder using a specific storage.
|
|
934
|
+
* @param currentServiceName - Name of the service being created
|
|
935
|
+
* @param currentServiceScope - Current scope of the service being created
|
|
936
|
+
* @param dependencyName - Name of the dependency being resolved
|
|
937
|
+
* @param dependencyScope - Scope of the dependency
|
|
938
|
+
* @param dependencyToken - Token of the dependency
|
|
939
|
+
* @param singletonStorage - Singleton storage instance
|
|
940
|
+
* @param requestStorage - Request storage instance (if in request context)
|
|
941
|
+
* @param requestId - Request ID (if in request context)
|
|
942
|
+
* @returns [needsUpgrade: boolean, newName?: string] - whether upgrade occurred and new name
|
|
943
|
+
*/
|
|
944
|
+
checkAndUpgradeScope(currentServiceName: string, currentServiceScope: InjectableScope, dependencyName: string, dependencyScope: InjectableScope, dependencyToken: InjectionToken<any, any>, singletonStorage: IHolderStorage, requestStorage?: IHolderStorage, requestId?: string): [boolean, string?];
|
|
945
|
+
/**
|
|
946
|
+
* Performs the actual scope upgrade from Singleton to Request.
|
|
947
|
+
* This is the core migration logic.
|
|
948
|
+
*
|
|
949
|
+
* @param serviceName - Current service name (without requestId)
|
|
950
|
+
* @param token - Service injection token
|
|
951
|
+
* @param singletonStorage - Source storage
|
|
952
|
+
* @param requestStorage - Target storage
|
|
953
|
+
* @param requestId - Request ID to include in new name
|
|
954
|
+
* @returns [success: boolean, newName?: string, error?: DIError]
|
|
886
955
|
*/
|
|
887
|
-
|
|
956
|
+
upgradeScopeToRequest(serviceName: string, token: InjectionToken<any, any>, singletonStorage: IHolderStorage, requestStorage: IHolderStorage, requestId: string): Promise<[boolean, string?, DIError?]>;
|
|
888
957
|
/**
|
|
889
|
-
*
|
|
958
|
+
* Synchronous part of scope upgrade - handles immediate updates.
|
|
959
|
+
* Async operations (like waiting for holder creation) should be done separately.
|
|
890
960
|
*/
|
|
891
|
-
private
|
|
961
|
+
private upgradeScopeToRequestSync;
|
|
892
962
|
/**
|
|
893
|
-
*
|
|
963
|
+
* Updates all parent dependencies to reference the new service name.
|
|
964
|
+
*
|
|
965
|
+
* @param oldName - Original service name
|
|
966
|
+
* @param newName - New service name with requestId
|
|
967
|
+
* @param singletonStorage - Singleton storage to check
|
|
968
|
+
* @param requestStorage - Request storage to check
|
|
894
969
|
*/
|
|
895
|
-
|
|
970
|
+
updateParentDependencies(oldName: string, newName: string, singletonStorage: IHolderStorage, requestStorage?: IHolderStorage): void;
|
|
971
|
+
}
|
|
972
|
+
//#endregion
|
|
973
|
+
//#region src/internal/core/service-initializer.d.mts
|
|
974
|
+
/**
|
|
975
|
+
* Creates service instances from registry records.
|
|
976
|
+
*
|
|
977
|
+
* Handles both class-based (@Injectable) and factory-based (@Factory) services,
|
|
978
|
+
* managing the instantiation lifecycle including lifecycle hook invocation.
|
|
979
|
+
*/
|
|
980
|
+
declare class ServiceInitializer {
|
|
981
|
+
private readonly injectors;
|
|
982
|
+
constructor(injectors: Injectors);
|
|
896
983
|
/**
|
|
897
|
-
*
|
|
898
|
-
*
|
|
984
|
+
* Instantiates a service based on its registry record.
|
|
985
|
+
* @param ctx The factory context for dependency injection
|
|
986
|
+
* @param record The factory record from the registry
|
|
987
|
+
* @param args Optional arguments for the service
|
|
988
|
+
* @returns Promise resolving to [undefined, instance] or [error]
|
|
899
989
|
*/
|
|
900
|
-
|
|
990
|
+
instantiateService<T>(ctx: ServiceInitializationContext, record: FactoryRecord<T, any>, args?: any): Promise<[undefined, T] | [DIError]>;
|
|
901
991
|
/**
|
|
902
|
-
*
|
|
903
|
-
*
|
|
992
|
+
* Instantiates a class-based service (Injectable decorator).
|
|
993
|
+
* @param ctx The factory context for dependency injection
|
|
994
|
+
* @param record The factory record from the registry
|
|
995
|
+
* @param args Optional arguments for the service constructor
|
|
996
|
+
* @returns Promise resolving to [undefined, instance] or [error]
|
|
904
997
|
*/
|
|
905
|
-
private
|
|
998
|
+
private instantiateClass;
|
|
906
999
|
/**
|
|
907
|
-
*
|
|
1000
|
+
* Instantiates a factory-based service (Factory decorator).
|
|
1001
|
+
* @param ctx The factory context for dependency injection
|
|
1002
|
+
* @param record The factory record from the registry
|
|
1003
|
+
* @param args Optional arguments for the factory
|
|
1004
|
+
* @returns Promise resolving to [undefined, instance] or [error]
|
|
908
1005
|
*/
|
|
909
|
-
private
|
|
1006
|
+
private instantiateFactory;
|
|
910
1007
|
}
|
|
911
1008
|
//#endregion
|
|
912
|
-
//#region src/internal/core/
|
|
1009
|
+
//#region src/internal/core/instance-resolver.d.mts
|
|
913
1010
|
/**
|
|
914
|
-
*
|
|
1011
|
+
* Resolves instances from tokens, handling caching, creation, and scope rules.
|
|
915
1012
|
*
|
|
916
|
-
*
|
|
917
|
-
*
|
|
1013
|
+
* Uses unified storage for both singleton and request-scoped services.
|
|
1014
|
+
* Coordinates with ServiceInitializer for actual service creation.
|
|
1015
|
+
* Integrates ScopeTracker for automatic scope upgrades.
|
|
918
1016
|
*/
|
|
919
|
-
declare class
|
|
1017
|
+
declare class InstanceResolver {
|
|
1018
|
+
private readonly registry;
|
|
1019
|
+
private readonly storage;
|
|
1020
|
+
private readonly serviceInitializer;
|
|
1021
|
+
private readonly tokenResolver;
|
|
1022
|
+
private readonly nameResolver;
|
|
1023
|
+
private readonly scopeTracker;
|
|
1024
|
+
private readonly serviceInvalidator;
|
|
1025
|
+
private readonly eventBus;
|
|
920
1026
|
private readonly logger;
|
|
921
|
-
constructor(logger?: Console | null);
|
|
1027
|
+
constructor(registry: Registry, storage: IHolderStorage, serviceInitializer: ServiceInitializer, tokenResolver: TokenResolver, nameResolver: NameResolver, scopeTracker: ScopeTracker, serviceInvalidator: ServiceInvalidator, eventBus: LifecycleEventBus, logger?: Console | null);
|
|
922
1028
|
/**
|
|
923
|
-
*
|
|
924
|
-
*
|
|
1029
|
+
* Resolves an instance for the given token and arguments.
|
|
1030
|
+
* This method is used for singleton and transient services.
|
|
925
1031
|
*
|
|
926
|
-
* @param token
|
|
927
|
-
* @
|
|
1032
|
+
* @param token The injection token
|
|
1033
|
+
* @param args Optional arguments
|
|
1034
|
+
* @param contextContainer The container to use for creating context
|
|
1035
|
+
* @param requestStorage Optional request storage (for scope upgrades)
|
|
1036
|
+
* @param requestId Optional request ID (for scope upgrades)
|
|
928
1037
|
*/
|
|
929
|
-
|
|
1038
|
+
resolveInstance(token: AnyInjectableType, args: any, contextContainer: IContainer, requestStorage?: IHolderStorage, requestId?: string): Promise<[undefined, any] | [DIError]>;
|
|
930
1039
|
/**
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
* For other tokens, returns the token itself.
|
|
1040
|
+
* Resolves a request-scoped instance for a ScopedContainer.
|
|
1041
|
+
* The service will be stored in the ScopedContainer's request storage.
|
|
934
1042
|
*
|
|
935
|
-
* @param token The token
|
|
936
|
-
* @
|
|
1043
|
+
* @param token The injection token
|
|
1044
|
+
* @param args Optional arguments
|
|
1045
|
+
* @param scopedContainer The ScopedContainer that owns the request context
|
|
937
1046
|
*/
|
|
938
|
-
|
|
1047
|
+
resolveRequestScopedInstance(token: AnyInjectableType, args: any, scopedContainer: ScopedContainer): Promise<[undefined, any] | [DIError]>;
|
|
939
1048
|
/**
|
|
940
|
-
*
|
|
941
|
-
*
|
|
1049
|
+
* Unified resolution method that works with any IHolderStorage.
|
|
1050
|
+
* This eliminates duplication between singleton and request-scoped resolution.
|
|
942
1051
|
*
|
|
943
|
-
*
|
|
944
|
-
*
|
|
1052
|
+
* IMPORTANT: The check-and-store logic is carefully designed to avoid race conditions.
|
|
1053
|
+
* The storage check and holder creation must happen synchronously (no awaits between).
|
|
1054
|
+
*
|
|
1055
|
+
* @param token The injection token
|
|
1056
|
+
* @param args Optional arguments
|
|
1057
|
+
* @param contextContainer The container for context
|
|
1058
|
+
* @param storage The storage strategy to use
|
|
1059
|
+
* @param scopedContainer Optional scoped container for request-scoped services
|
|
1060
|
+
* @param requestStorage Optional request storage (for scope upgrades)
|
|
1061
|
+
* @param requestId Optional request ID (for scope upgrades)
|
|
945
1062
|
*/
|
|
946
|
-
|
|
1063
|
+
private resolveWithStorage;
|
|
947
1064
|
/**
|
|
948
|
-
*
|
|
1065
|
+
* Internal method to resolve token args and create instance name.
|
|
1066
|
+
* Handles factory token resolution and validation.
|
|
949
1067
|
*/
|
|
950
|
-
|
|
951
|
-
actualToken: InjectionTokenType;
|
|
952
|
-
validatedArgs?: any;
|
|
953
|
-
}];
|
|
1068
|
+
private resolveTokenAndPrepareInstanceName;
|
|
954
1069
|
/**
|
|
955
|
-
*
|
|
1070
|
+
* Handles storage error states (destroying, error, etc.).
|
|
1071
|
+
* Returns a result if handled, null if should proceed with creation.
|
|
956
1072
|
*/
|
|
957
|
-
|
|
1073
|
+
private handleStorageError;
|
|
958
1074
|
/**
|
|
959
|
-
*
|
|
1075
|
+
* Creates a new instance and stores it using the provided storage strategy.
|
|
1076
|
+
* This unified method replaces instantiateServiceFromRegistry and createRequestScopedInstance.
|
|
1077
|
+
*
|
|
1078
|
+
* For transient services, the instance is created but not stored (no caching).
|
|
960
1079
|
*/
|
|
961
|
-
|
|
1080
|
+
private createAndStoreInstance;
|
|
962
1081
|
/**
|
|
963
|
-
* Creates a
|
|
964
|
-
*
|
|
965
|
-
* @param onDependencyResolved Callback when a dependency is resolved, receives the instance name
|
|
1082
|
+
* Creates a transient instance without storage or locking.
|
|
1083
|
+
* Each call creates a new instance.
|
|
966
1084
|
*/
|
|
967
|
-
|
|
968
|
-
getDestroyListeners: () => (() => void)[];
|
|
969
|
-
deps: Set<string>;
|
|
970
|
-
};
|
|
971
|
-
}
|
|
972
|
-
//#endregion
|
|
973
|
-
//#region src/internal/core/service-locator.d.mts
|
|
974
|
-
/**
|
|
975
|
-
* Core DI engine that coordinates service instantiation, resolution, and lifecycle.
|
|
976
|
-
*
|
|
977
|
-
* Acts as the central orchestrator for dependency injection operations,
|
|
978
|
-
* delegating to specialized components (InstanceResolver, Instantiator, Invalidator)
|
|
979
|
-
* for specific tasks.
|
|
980
|
-
*/
|
|
981
|
-
declare class ServiceLocator {
|
|
982
|
-
private readonly registry;
|
|
983
|
-
private readonly logger;
|
|
984
|
-
private readonly injectors;
|
|
985
|
-
private readonly eventBus;
|
|
986
|
-
private readonly manager;
|
|
987
|
-
private readonly instantiator;
|
|
988
|
-
private readonly tokenProcessor;
|
|
989
|
-
private readonly invalidator;
|
|
990
|
-
private readonly instanceResolver;
|
|
991
|
-
constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
|
|
992
|
-
getEventBus(): LifecycleEventBus;
|
|
993
|
-
getManager(): HolderManager;
|
|
994
|
-
getInvalidator(): Invalidator;
|
|
995
|
-
getTokenProcessor(): TokenProcessor;
|
|
996
|
-
getInstanceIdentifier(token: AnyInjectableType, args?: any): string;
|
|
1085
|
+
private createTransientInstance;
|
|
997
1086
|
/**
|
|
998
|
-
*
|
|
999
|
-
* @param token The injection token
|
|
1000
|
-
* @param args Optional arguments
|
|
1001
|
-
* @param contextContainer The container to use for creating FactoryContext
|
|
1087
|
+
* Handles successful service instantiation.
|
|
1002
1088
|
*/
|
|
1003
|
-
|
|
1089
|
+
private handleInstantiationSuccess;
|
|
1004
1090
|
/**
|
|
1005
|
-
*
|
|
1006
|
-
* @param token The injection token
|
|
1007
|
-
* @param args Optional arguments
|
|
1008
|
-
* @param contextContainer The container to use for creating FactoryContext
|
|
1091
|
+
* Handles service instantiation errors.
|
|
1009
1092
|
*/
|
|
1010
|
-
|
|
1093
|
+
private handleInstantiationError;
|
|
1011
1094
|
/**
|
|
1012
|
-
*
|
|
1013
|
-
* The service will be stored in the ScopedContainer's request context.
|
|
1014
|
-
*
|
|
1015
|
-
* @param token The injection token
|
|
1016
|
-
* @param args Optional arguments
|
|
1017
|
-
* @param scopedContainer The ScopedContainer that owns the request context
|
|
1095
|
+
* Handles instantiation result (success or error).
|
|
1018
1096
|
*/
|
|
1019
|
-
|
|
1020
|
-
getSyncInstance<Instance, Schema extends InjectionTokenSchemaType | undefined>(token: AnyInjectableType, args: Schema extends ZodObject ? z.input<Schema> : Schema extends ZodOptional<ZodObject> ? z.input<Schema> | undefined : undefined, contextContainer: IContainer): Instance | null;
|
|
1021
|
-
invalidate(service: string, round?: number): Promise<any>;
|
|
1097
|
+
private handleInstantiationResult;
|
|
1022
1098
|
/**
|
|
1023
|
-
*
|
|
1024
|
-
* This method respects service dependencies and ensures proper cleanup order.
|
|
1025
|
-
* Services that depend on others will be invalidated first, then their dependencies.
|
|
1099
|
+
* Waits for an instance holder to be ready and returns the appropriate result.
|
|
1026
1100
|
*
|
|
1027
|
-
* @param
|
|
1028
|
-
* @
|
|
1029
|
-
|
|
1030
|
-
clearAll(options?: ClearAllOptions): Promise<void>;
|
|
1031
|
-
/**
|
|
1032
|
-
* Waits for all services to settle (either created, destroyed, or error state).
|
|
1101
|
+
* @param holder The holder to wait for
|
|
1102
|
+
* @param waiterHolder Optional holder that is doing the waiting (for circular dependency detection)
|
|
1103
|
+
* @param getHolder Optional function to retrieve holders by name (required if waiterHolder is provided)
|
|
1033
1104
|
*/
|
|
1034
|
-
|
|
1105
|
+
private waitForInstanceReady;
|
|
1035
1106
|
/**
|
|
1036
|
-
*
|
|
1037
|
-
* This is needed for the factory context creation.
|
|
1107
|
+
* Creates a ServiceInitializationContext for service instantiation.
|
|
1038
1108
|
*/
|
|
1039
|
-
|
|
1109
|
+
private createServiceInitializationContext;
|
|
1040
1110
|
}
|
|
1041
1111
|
//#endregion
|
|
1042
1112
|
//#region src/container/container.d.mts
|
|
1043
1113
|
/**
|
|
1044
1114
|
* Main dependency injection container.
|
|
1045
1115
|
*
|
|
1046
|
-
* Provides a simplified public API for dependency injection
|
|
1047
|
-
*
|
|
1116
|
+
* Provides a simplified public API for dependency injection.
|
|
1117
|
+
* Handles singleton and transient services directly,
|
|
1048
1118
|
* while request-scoped services require using beginRequest() to create a ScopedContainer.
|
|
1049
1119
|
*/
|
|
1050
|
-
declare class Container
|
|
1120
|
+
declare class Container extends AbstractContainer {
|
|
1051
1121
|
protected readonly registry: Registry;
|
|
1052
1122
|
protected readonly logger: Console | null;
|
|
1053
1123
|
protected readonly injectors: Injectors;
|
|
1054
|
-
|
|
1124
|
+
protected readonly defaultScope = InjectableScope.Singleton;
|
|
1125
|
+
protected readonly requestId: undefined;
|
|
1126
|
+
private readonly storage;
|
|
1127
|
+
private readonly serviceInitializer;
|
|
1128
|
+
private readonly serviceInvalidator;
|
|
1129
|
+
private readonly tokenResolver;
|
|
1130
|
+
private readonly nameResolver;
|
|
1131
|
+
private readonly scopeTracker;
|
|
1132
|
+
private readonly eventBus;
|
|
1133
|
+
private readonly instanceResolver;
|
|
1055
1134
|
private readonly activeRequestIds;
|
|
1056
1135
|
constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
|
|
1057
1136
|
private registerSelf;
|
|
1058
1137
|
/**
|
|
1059
1138
|
* Gets an instance from the container.
|
|
1060
|
-
* This method has the same type signature as the inject method from get-injectors.mts
|
|
1061
|
-
*
|
|
1062
1139
|
* NOTE: Request-scoped services cannot be resolved directly from Container.
|
|
1063
1140
|
* Use beginRequest() to create a ScopedContainer for request-scoped services.
|
|
1064
1141
|
*/
|
|
@@ -1070,87 +1147,46 @@ declare class Container implements IContainer {
|
|
|
1070
1147
|
get<T>(token: BoundInjectionToken<T, any>): Promise<T>;
|
|
1071
1148
|
get<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
|
|
1072
1149
|
/**
|
|
1073
|
-
*
|
|
1074
|
-
* Used by ScopedContainer to delegate singleton/transient resolution
|
|
1075
|
-
* while maintaining the correct container context for nested inject() calls.
|
|
1076
|
-
*
|
|
1077
|
-
* @internal
|
|
1078
|
-
*/
|
|
1079
|
-
getWithContext(token: ClassType | InjectionToken<any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>, args: unknown, contextContainer: IContainer): Promise<any>;
|
|
1080
|
-
/**
|
|
1081
|
-
* Resolves a request-scoped service for a ScopedContainer.
|
|
1082
|
-
* The service will be stored in the ScopedContainer's request context.
|
|
1083
|
-
*
|
|
1084
|
-
* @internal
|
|
1085
|
-
*/
|
|
1086
|
-
resolveForRequest(token: ClassType | InjectionToken<any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>, args: unknown, scopedContainer: ScopedContainer): Promise<any>;
|
|
1087
|
-
/**
|
|
1088
|
-
* Gets the underlying ServiceLocator instance for advanced usage
|
|
1089
|
-
*/
|
|
1090
|
-
getServiceLocator(): ServiceLocator;
|
|
1091
|
-
/**
|
|
1092
|
-
* Gets the registry
|
|
1093
|
-
*/
|
|
1094
|
-
getRegistry(): Registry;
|
|
1095
|
-
/**
|
|
1096
|
-
* Invalidates a service and its dependencies
|
|
1150
|
+
* Invalidates a service and its dependencies.
|
|
1097
1151
|
*/
|
|
1098
1152
|
invalidate(service: unknown): Promise<void>;
|
|
1099
1153
|
/**
|
|
1100
|
-
*
|
|
1101
|
-
*/
|
|
1102
|
-
private getHolderByInstance;
|
|
1103
|
-
/**
|
|
1104
|
-
* Checks if a service is registered in the container
|
|
1105
|
-
*/
|
|
1106
|
-
isRegistered(token: any): boolean;
|
|
1107
|
-
/**
|
|
1108
|
-
* Disposes the container and cleans up all resources
|
|
1154
|
+
* Disposes the container and cleans up all resources.
|
|
1109
1155
|
*/
|
|
1110
1156
|
dispose(): Promise<void>;
|
|
1111
|
-
/**
|
|
1112
|
-
* Waits for all pending operations to complete
|
|
1113
|
-
*/
|
|
1114
|
-
ready(): Promise<void>;
|
|
1115
1157
|
/**
|
|
1116
1158
|
* @internal
|
|
1117
1159
|
* Attempts to get an instance synchronously if it already exists.
|
|
1118
|
-
*
|
|
1160
|
+
* Overrides base class to support requestId parameter for ScopedContainer compatibility.
|
|
1119
1161
|
*/
|
|
1120
|
-
tryGetSync<T>(token: any, args?: any): T | null;
|
|
1162
|
+
tryGetSync<T>(token: any, args?: any, requestId?: string): T | null;
|
|
1121
1163
|
/**
|
|
1122
1164
|
* Begins a new request context and returns a ScopedContainer.
|
|
1123
|
-
*
|
|
1124
|
-
* The ScopedContainer provides isolated request-scoped service resolution
|
|
1125
|
-
* while delegating singleton and transient services to this Container.
|
|
1126
|
-
*
|
|
1127
|
-
* @param requestId Unique identifier for this request
|
|
1128
|
-
* @param metadata Optional metadata for the request
|
|
1129
|
-
* @param priority Priority for resolution (higher = more priority)
|
|
1130
|
-
* @returns A ScopedContainer for this request
|
|
1131
1165
|
*/
|
|
1132
|
-
beginRequest(requestId: string, metadata?: Record<string, any
|
|
1166
|
+
beginRequest(requestId: string, metadata?: Record<string, any>): ScopedContainer;
|
|
1133
1167
|
/**
|
|
1134
|
-
*
|
|
1135
|
-
* Called by ScopedContainer when the request ends.
|
|
1136
|
-
*
|
|
1137
|
-
* @internal
|
|
1138
|
-
*/
|
|
1139
|
-
removeActiveRequest(requestId: string): void;
|
|
1140
|
-
/**
|
|
1141
|
-
* Gets the set of active request IDs.
|
|
1168
|
+
* Gets all active request IDs.
|
|
1142
1169
|
*/
|
|
1143
1170
|
getActiveRequestIds(): ReadonlySet<string>;
|
|
1144
1171
|
/**
|
|
1145
|
-
* Checks if a request
|
|
1172
|
+
* Checks if a request is active.
|
|
1146
1173
|
*/
|
|
1147
1174
|
hasActiveRequest(requestId: string): boolean;
|
|
1148
1175
|
/**
|
|
1149
|
-
*
|
|
1150
|
-
*
|
|
1176
|
+
* Removes a request ID from active requests.
|
|
1177
|
+
* Called by ScopedContainer when request ends.
|
|
1151
1178
|
*/
|
|
1152
|
-
|
|
1179
|
+
removeRequestId(requestId: string): void;
|
|
1180
|
+
getStorage(): UnifiedStorage;
|
|
1181
|
+
getServiceInitializer(): ServiceInitializer;
|
|
1182
|
+
getServiceInvalidator(): ServiceInvalidator;
|
|
1183
|
+
getTokenResolver(): TokenResolver;
|
|
1184
|
+
getNameResolver(): NameResolver;
|
|
1185
|
+
getScopeTracker(): ScopeTracker;
|
|
1186
|
+
getEventBus(): LifecycleEventBus;
|
|
1187
|
+
getRegistry(): Registry;
|
|
1188
|
+
getInstanceResolver(): InstanceResolver;
|
|
1153
1189
|
}
|
|
1154
1190
|
//#endregion
|
|
1155
|
-
export {
|
|
1156
|
-
//# sourceMappingURL=container-
|
|
1191
|
+
export { ClassTypeWithoutArguments as $, Injectors as A, PopUnion as B, NameResolver as C, Factorable as D, globalRegistry as E, IContainer as F, BaseInjectionTokenSchemaType as G, UnionToIntersection as H, InjectRequest as I, ClassTypeWithArgument as J, BoundInjectionToken as K, InjectState as L, ServiceInitializationContext as M, InjectableType as N, FactorableWithArgs as O, InjectableScope as P, ClassTypeWithOptionalArgument as Q, IsUnion as R, DIErrorCode as S, Registry as T, UnionToOvlds as U, UnionToArray as V, AnyInjectableType as W, ClassTypeWithInstanceAndArgument as X, ClassTypeWithInstance as Y, ClassTypeWithInstanceAndOptionalArgument as Z, InstanceHolderCreating as _, ScopedContainer as a, InstanceStatus as b, ClearAllOptions as c, LifecycleEventBus as d, FactoryInjectionToken as et, HolderGetResult as f, InstanceHolderCreated as g, InstanceHolder as h, ScopeTracker as i, OptionalInjectionTokenSchemaType as it, getInjectors as j, FactoryContext as k, InvalidationOptions as l, InstanceDestroyListener as m, InstanceResolver as n, InjectionTokenSchemaType as nt, UnifiedStorage as o, IHolderStorage as p, ClassType as q, ServiceInitializer as r, InjectionTokenType as rt, TokenResolver as s, Container as t, InjectionToken as tt, ServiceInvalidator as u, InstanceHolderDestroying as v, FactoryRecord as w, DIError as x, InstanceHolderError as y, Join as z };
|
|
1192
|
+
//# sourceMappingURL=container-D-0Ho3qL.d.cts.map
|