@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
package/lib/browser/index.d.mts
CHANGED
|
@@ -1,1508 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* Gets an instance from the container.
|
|
39
|
-
*/
|
|
40
|
-
get<T extends ClassType>(token: T): InstanceType<T> extends Factorable<infer R> ? Promise<R> : Promise<InstanceType<T>>;
|
|
41
|
-
get<T extends ClassTypeWithArgument<R>, R>(token: T, args: R): Promise<InstanceType<T>>;
|
|
42
|
-
get<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): Promise<T>;
|
|
43
|
-
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';
|
|
44
|
-
get<T>(token: InjectionToken<T, undefined>): Promise<T>;
|
|
45
|
-
get<T>(token: BoundInjectionToken<T, any>): Promise<T>;
|
|
46
|
-
get<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
|
|
47
|
-
/**
|
|
48
|
-
* Invalidates a service and its dependencies.
|
|
49
|
-
*/
|
|
50
|
-
invalidate(service: unknown): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Checks if a service is registered in the container.
|
|
53
|
-
*/
|
|
54
|
-
isRegistered(token: any): boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Disposes the container and cleans up all resources.
|
|
57
|
-
*/
|
|
58
|
-
dispose(): Promise<void>;
|
|
59
|
-
/**
|
|
60
|
-
* Waits for all pending operations to complete.
|
|
61
|
-
*/
|
|
62
|
-
ready(): Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* @internal
|
|
65
|
-
* Attempts to get an instance synchronously if it already exists.
|
|
66
|
-
* Returns null if the instance doesn't exist or is not ready.
|
|
67
|
-
* Used internally by the inject system for synchronous property initialization.
|
|
68
|
-
*/
|
|
69
|
-
tryGetSync<T>(token: any, args?: any): T | null;
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region src/utils/get-injectors.d.mts
|
|
73
|
-
interface Injectors {
|
|
74
|
-
asyncInject<T extends ClassTypeWithoutArguments>(token: T): InstanceType<T> extends Factorable<infer R> ? Promise<R> : Promise<InstanceType<T>>;
|
|
75
|
-
asyncInject<Args, T extends ClassTypeWithArgument<Args>>(token: T, args: Args): Promise<InstanceType<T>>;
|
|
76
|
-
asyncInject<Schema extends InjectionTokenSchemaType, R, T extends FactorableWithArgs<R, Schema>>(token: T, args: z.input<Schema>): Promise<R>;
|
|
77
|
-
asyncInject<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): Promise<T>;
|
|
78
|
-
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';
|
|
79
|
-
asyncInject<T>(token: InjectionToken<T, undefined>): Promise<T>;
|
|
80
|
-
asyncInject<T>(token: BoundInjectionToken<T, any>): Promise<T>;
|
|
81
|
-
asyncInject<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
|
|
82
|
-
inject<T extends ClassTypeWithoutArguments>(token: T): InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>;
|
|
83
|
-
inject<Args, T extends ClassTypeWithArgument<Args>>(token: T, args: Args): InstanceType<T>;
|
|
84
|
-
inject<Schema extends InjectionTokenSchemaType, R, T extends FactorableWithArgs<R, Schema>>(token: T, args: z.input<Schema>): R;
|
|
85
|
-
inject<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): T;
|
|
86
|
-
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';
|
|
87
|
-
inject<T>(token: InjectionToken<T, undefined>): T;
|
|
88
|
-
inject<T>(token: BoundInjectionToken<T, any>): T;
|
|
89
|
-
inject<T>(token: FactoryInjectionToken<T, any>): T;
|
|
90
|
-
/**
|
|
91
|
-
* Optional injection that returns null if the service fails to initialize
|
|
92
|
-
* or is not available. This is useful when you want to inject a service
|
|
93
|
-
* that may not be configured or may fail gracefully.
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```ts
|
|
97
|
-
* class MyService {
|
|
98
|
-
* constructor() {
|
|
99
|
-
* const optionalService = optional(OptionalServiceToken)
|
|
100
|
-
* // optionalService will be null if initialization fails
|
|
101
|
-
* if (optionalService) {
|
|
102
|
-
* optionalService.doSomething()
|
|
103
|
-
* }
|
|
104
|
-
* }
|
|
105
|
-
* }
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
optional<T extends ClassType>(token: T): (InstanceType<T> extends Factorable<infer R> ? R : InstanceType<T>) | null;
|
|
109
|
-
optional<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): T | null;
|
|
110
|
-
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';
|
|
111
|
-
optional<T>(token: InjectionToken<T, undefined>): T | null;
|
|
112
|
-
optional<T>(token: BoundInjectionToken<T, any>): T | null;
|
|
113
|
-
optional<T>(token: FactoryInjectionToken<T, any>): T | null;
|
|
114
|
-
wrapSyncInit(cb: () => any): (injectState?: InjectState) => [any, Promise<any>[], InjectState];
|
|
115
|
-
provideFactoryContext(context: FactoryContext | null): FactoryContext | null;
|
|
116
|
-
}
|
|
117
|
-
declare function getInjectors(): Injectors;
|
|
118
|
-
//#endregion
|
|
119
|
-
//#region src/utils/get-injectable-token.d.mts
|
|
120
|
-
declare function getInjectableToken<R>(target: ClassType): R extends {
|
|
121
|
-
create(...args: any[]): infer V;
|
|
122
|
-
} ? InjectionToken<V> : InjectionToken<R>;
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region src/internal/context/factory-context.d.mts
|
|
125
|
-
/**
|
|
126
|
-
* Context provided to factory functions during service instantiation.
|
|
127
|
-
*
|
|
128
|
-
* Provides access to dependency injection (via inject), the container,
|
|
129
|
-
* and lifecycle hooks for cleanup.
|
|
130
|
-
*/
|
|
131
|
-
interface FactoryContext {
|
|
132
|
-
inject: Injectors['asyncInject'];
|
|
133
|
-
/**
|
|
134
|
-
* The container instance for dependency resolution.
|
|
135
|
-
* This may be either a Container or ScopedContainer.
|
|
136
|
-
*/
|
|
137
|
-
container: IContainer;
|
|
138
|
-
addDestroyListener: (listener: () => void) => void;
|
|
139
|
-
}
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region src/token/injection-token.d.mts
|
|
142
|
-
type ClassType = new (...args: any[]) => any;
|
|
143
|
-
type ClassTypeWithoutArguments = new () => any;
|
|
144
|
-
type ClassTypeWithArgument<Arg> = new (arg: Arg) => any;
|
|
145
|
-
type ClassTypeWithOptionalArgument<Arg> = new (arg?: Arg) => any;
|
|
146
|
-
type ClassTypeWithInstance<T> = new (...args: any[]) => T;
|
|
147
|
-
type ClassTypeWithInstanceAndArgument<T, Arg> = new (arg: Arg) => T;
|
|
148
|
-
type ClassTypeWithInstanceAndOptionalArgument<T, Arg> = new (arg?: Arg) => T;
|
|
149
|
-
type BaseInjectionTokenSchemaType = ZodObject | ZodRecord;
|
|
150
|
-
type OptionalInjectionTokenSchemaType = ZodOptional<ZodObject> | ZodOptional<ZodRecord>;
|
|
151
|
-
type InjectionTokenSchemaType = BaseInjectionTokenSchemaType | OptionalInjectionTokenSchemaType;
|
|
152
|
-
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)> {
|
|
153
|
-
readonly name: string | symbol | ClassType;
|
|
154
|
-
readonly schema: ZodObject | undefined;
|
|
155
|
-
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
156
|
-
private formattedName;
|
|
157
|
-
constructor(name: string | symbol | ClassType, schema: ZodObject | undefined);
|
|
158
|
-
static create<T extends ClassType>(name: T): InjectionToken<InstanceType<T>, undefined>;
|
|
159
|
-
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>;
|
|
160
|
-
static create<T>(name: string | symbol): InjectionToken<T, undefined>;
|
|
161
|
-
static create<T, Schema extends InjectionTokenSchemaType>(name: string | any, schema: Schema): InjectionToken<T, Schema>;
|
|
162
|
-
static bound<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, value: z.input<S>): BoundInjectionToken<T, S>;
|
|
163
|
-
static factory<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, factory: (ctx: FactoryContext) => Promise<z.input<S>>): FactoryInjectionToken<T, S>;
|
|
164
|
-
static refineType<T>(token: BoundInjectionToken<any, any>): BoundInjectionToken<T, any>;
|
|
165
|
-
toString(): string;
|
|
166
|
-
}
|
|
167
|
-
declare class BoundInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
168
|
-
readonly token: InjectionToken<T, S>;
|
|
169
|
-
readonly value: z.input<S>;
|
|
170
|
-
id: string;
|
|
171
|
-
name: string | symbol | ClassType;
|
|
172
|
-
schema: InjectionTokenSchemaType;
|
|
173
|
-
constructor(token: InjectionToken<T, S>, value: z.input<S>);
|
|
174
|
-
toString(): string;
|
|
175
|
-
}
|
|
176
|
-
declare class FactoryInjectionToken<T, S extends InjectionTokenSchemaType> {
|
|
177
|
-
readonly token: InjectionToken<T, S>;
|
|
178
|
-
readonly factory: (ctx: FactoryContext) => Promise<z.input<S>>;
|
|
179
|
-
value?: z.input<S>;
|
|
180
|
-
resolved: boolean;
|
|
181
|
-
id: string;
|
|
182
|
-
name: string | symbol | ClassType;
|
|
183
|
-
schema: InjectionTokenSchemaType;
|
|
184
|
-
constructor(token: InjectionToken<T, S>, factory: (ctx: FactoryContext) => Promise<z.input<S>>);
|
|
185
|
-
resolve(ctx: FactoryContext): Promise<z.input<S>>;
|
|
186
|
-
toString(): string;
|
|
187
|
-
}
|
|
188
|
-
type AnyInjectableType = ClassType | InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>;
|
|
189
|
-
type InjectionTokenType = InjectionToken<any, any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>;
|
|
190
|
-
//#endregion
|
|
191
|
-
//#region src/enums/injectable-scope.enum.d.mts
|
|
192
|
-
declare enum InjectableScope {
|
|
193
|
-
/**
|
|
194
|
-
* Singleton scope: The instance is created once and shared across the application.
|
|
195
|
-
*/
|
|
196
|
-
Singleton = "Singleton",
|
|
197
|
-
/**
|
|
198
|
-
* Instance scope: A new instance is created for each injection.
|
|
199
|
-
*/
|
|
200
|
-
Transient = "Transient",
|
|
201
|
-
/**
|
|
202
|
-
* Request scope: The instance is created once per request and shared within that request context.
|
|
203
|
-
*/
|
|
204
|
-
Request = "Request",
|
|
205
|
-
}
|
|
206
|
-
//#endregion
|
|
207
|
-
//#region src/enums/injectable-type.enum.d.mts
|
|
208
|
-
declare enum InjectableType {
|
|
209
|
-
Class = "Class",
|
|
210
|
-
Factory = "Factory",
|
|
211
|
-
}
|
|
212
|
-
//#endregion
|
|
213
|
-
//#region src/token/registry.d.mts
|
|
214
|
-
type FactoryRecord<Instance = any, Schema = any> = {
|
|
215
|
-
scope: InjectableScope;
|
|
216
|
-
originalToken: InjectionToken<Instance, Schema>;
|
|
217
|
-
target: ClassType;
|
|
218
|
-
type: InjectableType;
|
|
219
|
-
};
|
|
220
|
-
declare class Registry {
|
|
221
|
-
private readonly parent?;
|
|
222
|
-
private readonly factories;
|
|
223
|
-
constructor(parent?: Registry | undefined);
|
|
224
|
-
has(token: InjectionToken<any, any>): boolean;
|
|
225
|
-
get<Instance, Schema>(token: InjectionToken<Instance, Schema>): FactoryRecord<Instance, Schema>;
|
|
226
|
-
set<Instance, Schema>(token: InjectionToken<Instance, Schema>, scope: InjectableScope, target: ClassType, type: InjectableType): void;
|
|
227
|
-
delete(token: InjectionToken<any, any>): void;
|
|
228
|
-
/**
|
|
229
|
-
* Updates the scope of an already registered factory.
|
|
230
|
-
* This is useful when you need to dynamically change a service's scope
|
|
231
|
-
* (e.g., when a singleton controller has request-scoped dependencies).
|
|
232
|
-
*
|
|
233
|
-
* @param token The injection token to update
|
|
234
|
-
* @param scope The new scope to set
|
|
235
|
-
* @returns true if the scope was updated, false if the token was not found
|
|
236
|
-
*/
|
|
237
|
-
updateScope(token: InjectionToken<any, any>, scope: InjectableScope): boolean;
|
|
238
|
-
}
|
|
239
|
-
declare const globalRegistry: Registry;
|
|
240
|
-
//#endregion
|
|
241
|
-
//#region src/errors/di-error.d.mts
|
|
242
|
-
declare enum DIErrorCode {
|
|
243
|
-
FactoryNotFound = "FactoryNotFound",
|
|
244
|
-
FactoryTokenNotResolved = "FactoryTokenNotResolved",
|
|
245
|
-
InstanceNotFound = "InstanceNotFound",
|
|
246
|
-
InstanceDestroying = "InstanceDestroying",
|
|
247
|
-
CircularDependency = "CircularDependency",
|
|
248
|
-
UnknownError = "UnknownError",
|
|
249
|
-
}
|
|
250
|
-
declare class DIError extends Error {
|
|
251
|
-
readonly code: DIErrorCode;
|
|
252
|
-
readonly message: string;
|
|
253
|
-
readonly context?: Record<string, unknown>;
|
|
254
|
-
constructor(code: DIErrorCode, message: string, context?: Record<string, unknown>);
|
|
255
|
-
static factoryNotFound(name: string): DIError;
|
|
256
|
-
static factoryTokenNotResolved(token: string | symbol | unknown): DIError;
|
|
257
|
-
static instanceNotFound(name: string): DIError;
|
|
258
|
-
static instanceDestroying(name: string): DIError;
|
|
259
|
-
static unknown(message: string | Error, context?: Record<string, unknown>): DIError;
|
|
260
|
-
static circularDependency(cycle: string[]): DIError;
|
|
261
|
-
}
|
|
262
|
-
//#endregion
|
|
263
|
-
//#region src/internal/holder/instance-holder.d.mts
|
|
264
|
-
/**
|
|
265
|
-
* Represents the lifecycle status of an instance holder.
|
|
266
|
-
*/
|
|
267
|
-
declare enum InstanceStatus {
|
|
268
|
-
/** Instance has been successfully created and is ready for use */
|
|
269
|
-
Created = "created",
|
|
270
|
-
/** Instance is currently being created (async initialization in progress) */
|
|
271
|
-
Creating = "creating",
|
|
272
|
-
/** Instance is being destroyed (cleanup in progress) */
|
|
273
|
-
Destroying = "destroying",
|
|
274
|
-
/** Instance creation failed with an error */
|
|
275
|
-
Error = "error",
|
|
276
|
-
}
|
|
277
|
-
/** Callback function for instance effects */
|
|
278
|
-
type InstanceEffect = () => void;
|
|
279
|
-
/** Callback function for instance destruction listeners */
|
|
280
|
-
type InstanceDestroyListener = () => void | Promise<void>;
|
|
281
|
-
/**
|
|
282
|
-
* Instance holder in the Creating state.
|
|
283
|
-
* The instance is null while creation is in progress.
|
|
284
|
-
*/
|
|
285
|
-
interface InstanceHolderCreating<Instance> {
|
|
286
|
-
status: InstanceStatus.Creating;
|
|
287
|
-
name: string;
|
|
288
|
-
instance: null;
|
|
289
|
-
creationPromise: Promise<[undefined, Instance]> | null;
|
|
290
|
-
destroyPromise: null;
|
|
291
|
-
type: InjectableType;
|
|
292
|
-
scope: InjectableScope;
|
|
293
|
-
deps: Set<string>;
|
|
294
|
-
destroyListeners: InstanceDestroyListener[];
|
|
295
|
-
createdAt: number;
|
|
296
|
-
/** Tracks which services this holder is currently waiting for (for circular dependency detection) */
|
|
297
|
-
waitingFor: Set<string>;
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Instance holder in the Created state.
|
|
301
|
-
* The instance is available and ready for use.
|
|
302
|
-
*/
|
|
303
|
-
interface InstanceHolderCreated<Instance> {
|
|
304
|
-
status: InstanceStatus.Created;
|
|
305
|
-
name: string;
|
|
306
|
-
instance: Instance;
|
|
307
|
-
creationPromise: null;
|
|
308
|
-
destroyPromise: null;
|
|
309
|
-
type: InjectableType;
|
|
310
|
-
scope: InjectableScope;
|
|
311
|
-
deps: Set<string>;
|
|
312
|
-
destroyListeners: InstanceDestroyListener[];
|
|
313
|
-
createdAt: number;
|
|
314
|
-
/** Tracks which services this holder is currently waiting for (for circular dependency detection) */
|
|
315
|
-
waitingFor: Set<string>;
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Instance holder in the Destroying state.
|
|
319
|
-
* The instance may still be available but is being cleaned up.
|
|
320
|
-
*/
|
|
321
|
-
interface InstanceHolderDestroying<Instance> {
|
|
322
|
-
status: InstanceStatus.Destroying;
|
|
323
|
-
name: string;
|
|
324
|
-
instance: Instance | null;
|
|
325
|
-
creationPromise: null;
|
|
326
|
-
destroyPromise: Promise<void>;
|
|
327
|
-
type: InjectableType;
|
|
328
|
-
scope: InjectableScope;
|
|
329
|
-
deps: Set<string>;
|
|
330
|
-
destroyListeners: InstanceDestroyListener[];
|
|
331
|
-
createdAt: number;
|
|
332
|
-
/** Tracks which services this holder is currently waiting for (for circular dependency detection) */
|
|
333
|
-
waitingFor: Set<string>;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Instance holder in the Error state.
|
|
337
|
-
* The instance field contains the error that occurred during creation.
|
|
338
|
-
*/
|
|
339
|
-
interface InstanceHolderError {
|
|
340
|
-
status: InstanceStatus.Error;
|
|
341
|
-
name: string;
|
|
342
|
-
instance: Error;
|
|
343
|
-
creationPromise: null;
|
|
344
|
-
destroyPromise: null;
|
|
345
|
-
type: InjectableType;
|
|
346
|
-
scope: InjectableScope;
|
|
347
|
-
deps: Set<string>;
|
|
348
|
-
destroyListeners: InstanceDestroyListener[];
|
|
349
|
-
createdAt: number;
|
|
350
|
-
/** Tracks which services this holder is currently waiting for (for circular dependency detection) */
|
|
351
|
-
waitingFor: Set<string>;
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Holds the state of a service instance throughout its lifecycle.
|
|
355
|
-
*
|
|
356
|
-
* Tracks creation/destruction promises, dependency relationships,
|
|
357
|
-
* destroy listeners, and current status (Creating, Created, Destroying, Error).
|
|
358
|
-
*/
|
|
359
|
-
type InstanceHolder<Instance = unknown> = InstanceHolderCreating<Instance> | InstanceHolderCreated<Instance> | InstanceHolderDestroying<Instance> | InstanceHolderError;
|
|
360
|
-
//#endregion
|
|
361
|
-
//#region src/internal/holder/holder-storage.interface.d.mts
|
|
362
|
-
/**
|
|
363
|
-
* Result type for holder retrieval operations.
|
|
364
|
-
* - [undefined, holder] - Holder found successfully
|
|
365
|
-
* - [DIError, holder?] - Error occurred (holder may be available for waiting)
|
|
366
|
-
* - null - No holder exists
|
|
367
|
-
*/
|
|
368
|
-
type HolderGetResult<T = unknown> = [undefined, InstanceHolder<T>] | [DIError, InstanceHolder<T>?] | null;
|
|
369
|
-
/**
|
|
370
|
-
* Interface for abstracting holder storage operations.
|
|
371
|
-
*
|
|
372
|
-
* Enables unified instance resolution logic regardless of where
|
|
373
|
-
* holders are stored (singleton manager, request context, etc.).
|
|
374
|
-
* This is the key abstraction for the Storage Strategy pattern.
|
|
375
|
-
*/
|
|
376
|
-
interface IHolderStorage {
|
|
377
|
-
/**
|
|
378
|
-
* The scope this storage handles.
|
|
379
|
-
*/
|
|
380
|
-
readonly scope: InjectableScope;
|
|
381
|
-
/**
|
|
382
|
-
* Retrieves an existing holder by instance name.
|
|
383
|
-
*
|
|
384
|
-
* @param instanceName The unique identifier for the instance
|
|
385
|
-
* @returns
|
|
386
|
-
* - [undefined, holder] if found and ready/creating
|
|
387
|
-
* - [DIError, holder?] if found but in error/destroying state
|
|
388
|
-
* - null if not found
|
|
389
|
-
*/
|
|
390
|
-
get<T = unknown>(instanceName: string): HolderGetResult<T>;
|
|
391
|
-
/**
|
|
392
|
-
* Stores a holder by instance name.
|
|
393
|
-
*
|
|
394
|
-
* @param instanceName The unique identifier for the instance
|
|
395
|
-
* @param holder The holder to store
|
|
396
|
-
*/
|
|
397
|
-
set(instanceName: string, holder: InstanceHolder): void;
|
|
398
|
-
/**
|
|
399
|
-
* Deletes a holder by instance name.
|
|
400
|
-
*
|
|
401
|
-
* @param instanceName The unique identifier for the instance
|
|
402
|
-
* @returns true if the holder was deleted, false if it didn't exist
|
|
403
|
-
*/
|
|
404
|
-
delete(instanceName: string): boolean;
|
|
405
|
-
/**
|
|
406
|
-
* Creates a new holder in "Creating" state with a deferred promise.
|
|
407
|
-
* The holder is NOT automatically stored - call set() to store it.
|
|
408
|
-
*
|
|
409
|
-
* @param instanceName The unique identifier for the instance
|
|
410
|
-
* @param type The injectable type
|
|
411
|
-
* @param deps The set of dependency names
|
|
412
|
-
* @returns A tuple containing the deferred promise resolver and the holder
|
|
413
|
-
*/
|
|
414
|
-
createHolder<T>(instanceName: string, type: InjectableType, deps: Set<string>): [ReturnType<typeof Promise.withResolvers<[undefined, T]>>, InstanceHolder<T>];
|
|
415
|
-
/**
|
|
416
|
-
* Checks if this storage should be used for the given scope.
|
|
417
|
-
*/
|
|
418
|
-
handles(scope: InjectableScope): boolean;
|
|
419
|
-
/**
|
|
420
|
-
* Gets all instance names in this storage.
|
|
421
|
-
*/
|
|
422
|
-
getAllNames(): string[];
|
|
423
|
-
/**
|
|
424
|
-
* Iterates over all holders with a callback.
|
|
425
|
-
*
|
|
426
|
-
* @param callback Function called for each holder with (name, holder)
|
|
427
|
-
*/
|
|
428
|
-
forEach(callback: (name: string, holder: InstanceHolder) => void): void;
|
|
429
|
-
/**
|
|
430
|
-
* Finds a holder by its instance value (reverse lookup).
|
|
431
|
-
*
|
|
432
|
-
* @param instance The instance to search for
|
|
433
|
-
* @returns The holder if found, null otherwise
|
|
434
|
-
*/
|
|
435
|
-
findByInstance(instance: unknown): InstanceHolder | null;
|
|
436
|
-
/**
|
|
437
|
-
* Finds all instance names that depend on the given instance name.
|
|
438
|
-
*
|
|
439
|
-
* @param instanceName The instance name to find dependents for
|
|
440
|
-
* @returns Array of instance names that have this instance as a dependency
|
|
441
|
-
*/
|
|
442
|
-
findDependents(instanceName: string): string[];
|
|
443
|
-
}
|
|
444
|
-
//#endregion
|
|
445
|
-
//#region src/internal/holder/base-holder-manager.d.mts
|
|
446
|
-
/**
|
|
447
|
-
* Result type for waitForHolderReady.
|
|
448
|
-
* Returns either [undefined, holder] on success or [error] on failure.
|
|
449
|
-
*/
|
|
450
|
-
type HolderReadyResult<T> = [undefined, InstanceHolder<T>] | [DIError];
|
|
451
|
-
/**
|
|
452
|
-
* Abstract base class providing common functionality for managing InstanceHolder objects.
|
|
453
|
-
*
|
|
454
|
-
* Provides shared patterns for holder storage, creation, and lifecycle management
|
|
455
|
-
* used by both singleton (HolderManager) and request-scoped (RequestContext) managers.
|
|
456
|
-
*/
|
|
457
|
-
declare abstract class BaseHolderManager {
|
|
458
|
-
protected readonly logger: Console | null;
|
|
459
|
-
protected readonly _holders: Map<string, InstanceHolder>;
|
|
460
|
-
constructor(logger?: Console | null);
|
|
461
|
-
/**
|
|
462
|
-
* Protected getter for accessing the holders map from subclasses.
|
|
463
|
-
*/
|
|
464
|
-
protected get holders(): Map<string, InstanceHolder>;
|
|
465
|
-
/**
|
|
466
|
-
* Abstract method to get a holder by name. Each implementation defines its own return type
|
|
467
|
-
* based on their specific error handling and validation needs.
|
|
468
|
-
*/
|
|
469
|
-
abstract get(name: string): any;
|
|
470
|
-
/**
|
|
471
|
-
* Abstract method to set a holder by name. Each implementation may have different validation logic.
|
|
472
|
-
*/
|
|
473
|
-
abstract set(name: string, holder: InstanceHolder): void;
|
|
474
|
-
/**
|
|
475
|
-
* Abstract method to check if a holder exists. Each implementation may have different validation logic.
|
|
476
|
-
*/
|
|
477
|
-
abstract has(name: string): any;
|
|
478
|
-
/**
|
|
479
|
-
* Deletes a holder by name.
|
|
480
|
-
* @param name The name of the holder to delete
|
|
481
|
-
* @returns true if the holder was deleted, false if it didn't exist
|
|
482
|
-
*/
|
|
483
|
-
delete(name: string): boolean;
|
|
484
|
-
/**
|
|
485
|
-
* Filters holders based on a predicate function.
|
|
486
|
-
* @param predicate Function to test each holder
|
|
487
|
-
* @returns A new Map containing only the holders that match the predicate
|
|
488
|
-
*/
|
|
489
|
-
filter(predicate: (value: InstanceHolder<any>, key: string) => boolean): Map<string, InstanceHolder>;
|
|
490
|
-
/**
|
|
491
|
-
* Clears all holders from this manager.
|
|
492
|
-
*/
|
|
493
|
-
clear(): void;
|
|
494
|
-
/**
|
|
495
|
-
* Gets the number of holders currently managed.
|
|
496
|
-
*/
|
|
497
|
-
size(): number;
|
|
498
|
-
/**
|
|
499
|
-
* Creates a new holder with Creating status and a deferred creation promise.
|
|
500
|
-
* This is useful for creating placeholder holders that can be fulfilled later.
|
|
501
|
-
* @param name The name of the instance
|
|
502
|
-
* @param type The injectable type
|
|
503
|
-
* @param scope The injectable scope
|
|
504
|
-
* @param deps Optional set of dependencies
|
|
505
|
-
* @returns A tuple containing the deferred promise and the holder
|
|
506
|
-
*/
|
|
507
|
-
createCreatingHolder<Instance>(name: string, type: InjectableType, scope: InjectableScope, deps?: Set<string>): [ReturnType<typeof Promise.withResolvers<[undefined, Instance]>>, InstanceHolder<Instance>];
|
|
508
|
-
/**
|
|
509
|
-
* Creates a new holder with Created status and an actual instance.
|
|
510
|
-
* This is useful for creating holders that already have their instance ready.
|
|
511
|
-
* @param name The name of the instance
|
|
512
|
-
* @param instance The actual instance to store
|
|
513
|
-
* @param type The injectable type
|
|
514
|
-
* @param scope The injectable scope
|
|
515
|
-
* @param deps Optional set of dependencies
|
|
516
|
-
* @returns The created holder
|
|
517
|
-
*/
|
|
518
|
-
protected createCreatedHolder<Instance>(name: string, instance: Instance, type: InjectableType, scope: InjectableScope, deps?: Set<string>): InstanceHolder<Instance>;
|
|
519
|
-
/**
|
|
520
|
-
* Gets all holder names currently managed.
|
|
521
|
-
*/
|
|
522
|
-
getAllNames(): string[];
|
|
523
|
-
/**
|
|
524
|
-
* Gets all holders currently managed.
|
|
525
|
-
*/
|
|
526
|
-
getAllHolders(): InstanceHolder[];
|
|
527
|
-
/**
|
|
528
|
-
* Checks if this manager has any holders.
|
|
529
|
-
*/
|
|
530
|
-
isEmpty(): boolean;
|
|
531
|
-
/**
|
|
532
|
-
* Waits for a holder to be ready and returns the appropriate result.
|
|
533
|
-
* This is a shared utility used by both singleton and request-scoped resolution.
|
|
534
|
-
*
|
|
535
|
-
* @param holder The holder to wait for
|
|
536
|
-
* @param waiterHolder Optional holder that is doing the waiting (for circular dependency detection)
|
|
537
|
-
* @param getHolder Optional function to retrieve holders by name (required if waiterHolder is provided)
|
|
538
|
-
* @returns A promise that resolves with [undefined, holder] on success or [DIError] on failure
|
|
539
|
-
*/
|
|
540
|
-
static waitForHolderReady<T>(holder: InstanceHolder<T>, waiterHolder?: InstanceHolder, getHolder?: (name: string) => InstanceHolder | undefined): Promise<HolderReadyResult<T>>;
|
|
541
|
-
}
|
|
542
|
-
//#endregion
|
|
543
|
-
//#region src/internal/context/request-context.d.mts
|
|
544
|
-
/**
|
|
545
|
-
* Interface for request context that manages pre-prepared instances for a specific request.
|
|
546
|
-
*
|
|
547
|
-
* Provides isolated storage for request-scoped services, enabling efficient
|
|
548
|
-
* instantiation and cleanup within the lifecycle of a single request.
|
|
549
|
-
*/
|
|
550
|
-
interface RequestContext {
|
|
551
|
-
/**
|
|
552
|
-
* Unique identifier for this request context.
|
|
553
|
-
*/
|
|
554
|
-
readonly requestId: string;
|
|
555
|
-
/**
|
|
556
|
-
* Instance holders for request-scoped services.
|
|
557
|
-
*/
|
|
558
|
-
readonly holders: Map<string, InstanceHolder>;
|
|
559
|
-
/**
|
|
560
|
-
* Priority for resolution in FactoryContext.inject method.
|
|
561
|
-
* Higher values take precedence.
|
|
562
|
-
*/
|
|
563
|
-
readonly priority: number;
|
|
564
|
-
/**
|
|
565
|
-
* Request-specific metadata that can be used during instantiation.
|
|
566
|
-
*/
|
|
567
|
-
readonly metadata: Map<string, any>;
|
|
568
|
-
/**
|
|
569
|
-
* Timestamp when this context was created.
|
|
570
|
-
*/
|
|
571
|
-
readonly createdAt: number;
|
|
572
|
-
/**
|
|
573
|
-
* Adds a pre-prepared instance to this context.
|
|
574
|
-
*/
|
|
575
|
-
addInstance(instanceName: string, instance: any, holder: InstanceHolder): void;
|
|
576
|
-
/**
|
|
577
|
-
* Adds a pre-prepared instance to this context.
|
|
578
|
-
*/
|
|
579
|
-
addInstance(token: InjectionToken<any, undefined>, instance: any): void;
|
|
580
|
-
/**
|
|
581
|
-
* Gets an instance holder from this context.
|
|
582
|
-
*/
|
|
583
|
-
get(instanceName: string): InstanceHolder | undefined;
|
|
584
|
-
/**
|
|
585
|
-
* Sets an instance holder by name.
|
|
586
|
-
*/
|
|
587
|
-
set(instanceName: string, holder: InstanceHolder): void;
|
|
588
|
-
/**
|
|
589
|
-
* Checks if this context has a pre-prepared instance.
|
|
590
|
-
*/
|
|
591
|
-
has(instanceName: string): boolean;
|
|
592
|
-
/**
|
|
593
|
-
* Clears all instances and holders from this context.
|
|
594
|
-
*/
|
|
595
|
-
clear(): void;
|
|
596
|
-
/**
|
|
597
|
-
* Gets metadata value by key.
|
|
598
|
-
*/
|
|
599
|
-
getMetadata(key: string): any | undefined;
|
|
600
|
-
/**
|
|
601
|
-
* Sets metadata value by key.
|
|
602
|
-
*/
|
|
603
|
-
setMetadata(key: string, value: any): void;
|
|
604
|
-
/**
|
|
605
|
-
* Filters holders based on a predicate function.
|
|
606
|
-
*/
|
|
607
|
-
filter(predicate: (value: InstanceHolder<any>, key: string) => boolean): Map<string, InstanceHolder>;
|
|
608
|
-
/**
|
|
609
|
-
* Deletes a holder by name.
|
|
610
|
-
*/
|
|
611
|
-
delete(name: string): boolean;
|
|
612
|
-
/**
|
|
613
|
-
* Gets the number of holders currently managed.
|
|
614
|
-
*/
|
|
615
|
-
size(): number;
|
|
616
|
-
/**
|
|
617
|
-
* Checks if this manager has any holders.
|
|
618
|
-
*/
|
|
619
|
-
isEmpty(): boolean;
|
|
620
|
-
}
|
|
621
|
-
/** @deprecated Use RequestContext instead */
|
|
622
|
-
type RequestContextHolder = RequestContext;
|
|
623
|
-
/**
|
|
624
|
-
* Default implementation of RequestContext.
|
|
625
|
-
*
|
|
626
|
-
* Extends BaseHolderManager to provide holder management functionality
|
|
627
|
-
* with request-specific metadata and lifecycle support.
|
|
628
|
-
*/
|
|
629
|
-
declare class DefaultRequestContext extends BaseHolderManager implements RequestContext {
|
|
630
|
-
readonly requestId: string;
|
|
631
|
-
readonly priority: number;
|
|
632
|
-
readonly metadata: Map<string, any>;
|
|
633
|
-
readonly createdAt: number;
|
|
634
|
-
constructor(requestId: string, priority?: number, initialMetadata?: Record<string, any>);
|
|
635
|
-
/**
|
|
636
|
-
* Public getter for holders to maintain interface compatibility.
|
|
637
|
-
*/
|
|
638
|
-
get holders(): Map<string, InstanceHolder>;
|
|
639
|
-
/**
|
|
640
|
-
* Gets a holder by name. For RequestContext, this is a simple lookup.
|
|
641
|
-
*/
|
|
642
|
-
get(name: string): InstanceHolder | undefined;
|
|
643
|
-
/**
|
|
644
|
-
* Sets a holder by name.
|
|
645
|
-
*/
|
|
646
|
-
set(name: string, holder: InstanceHolder): void;
|
|
647
|
-
/**
|
|
648
|
-
* Checks if a holder exists by name.
|
|
649
|
-
*/
|
|
650
|
-
has(name: string): boolean;
|
|
651
|
-
addInstance(instanceName: string | InjectionToken<any, undefined>, instance: any, holder?: InstanceHolder): void;
|
|
652
|
-
clear(): void;
|
|
653
|
-
getMetadata(key: string): any | undefined;
|
|
654
|
-
setMetadata(key: string, value: any): void;
|
|
655
|
-
}
|
|
656
|
-
/**
|
|
657
|
-
* Creates a new request context with the given parameters.
|
|
658
|
-
*/
|
|
659
|
-
declare function createRequestContext(requestId: string, priority?: number, initialMetadata?: Record<string, any>): RequestContext;
|
|
660
|
-
//#endregion
|
|
661
|
-
//#region src/container/scoped-container.d.mts
|
|
662
|
-
/**
|
|
663
|
-
* Request-scoped dependency injection container.
|
|
664
|
-
*
|
|
665
|
-
* Wraps a parent Container and provides isolated request-scoped instances
|
|
666
|
-
* while delegating singleton and transient resolution to the parent.
|
|
667
|
-
* This design eliminates race conditions that can occur with async operations
|
|
668
|
-
* when multiple requests are processed concurrently.
|
|
669
|
-
*/
|
|
670
|
-
declare class ScopedContainer implements IContainer {
|
|
671
|
-
private readonly parent;
|
|
672
|
-
private readonly registry;
|
|
673
|
-
readonly requestId: string;
|
|
674
|
-
private readonly requestContextHolder;
|
|
675
|
-
private readonly holderStorage;
|
|
676
|
-
private disposed;
|
|
677
|
-
constructor(parent: Container, registry: Registry, requestId: string, metadata?: Record<string, any>, priority?: number);
|
|
678
|
-
/**
|
|
679
|
-
* Gets the request context holder for this scoped container.
|
|
680
|
-
*/
|
|
681
|
-
getRequestContextHolder(): RequestContext;
|
|
682
|
-
/**
|
|
683
|
-
* Gets the holder storage for this scoped container.
|
|
684
|
-
* Used by InstanceResolver for request-scoped resolution.
|
|
685
|
-
*/
|
|
686
|
-
getHolderStorage(): IHolderStorage;
|
|
687
|
-
/**
|
|
688
|
-
* Gets the request ID for this scoped container.
|
|
689
|
-
*/
|
|
690
|
-
getRequestId(): string;
|
|
691
|
-
/**
|
|
692
|
-
* Gets the parent container.
|
|
693
|
-
*/
|
|
694
|
-
getParent(): Container;
|
|
695
|
-
/**
|
|
696
|
-
* Gets metadata from the request context.
|
|
697
|
-
*/
|
|
698
|
-
getMetadata(key: string): any | undefined;
|
|
699
|
-
/**
|
|
700
|
-
* Sets metadata on the request context.
|
|
701
|
-
*/
|
|
702
|
-
setMetadata(key: string, value: any): void;
|
|
703
|
-
/**
|
|
704
|
-
* Adds a pre-prepared instance to the request context.
|
|
705
|
-
*/
|
|
706
|
-
addInstance(token: InjectionToken<any, undefined>, instance: any): void;
|
|
707
|
-
/**
|
|
708
|
-
* Gets an instance from the container.
|
|
709
|
-
* Request-scoped services are resolved from this container's context.
|
|
710
|
-
* All other services are delegated to the parent container.
|
|
711
|
-
*/
|
|
712
|
-
get<T extends ClassType>(token: T): InstanceType<T> extends Factorable<infer R> ? Promise<R> : Promise<InstanceType<T>>;
|
|
713
|
-
get<T extends ClassTypeWithArgument<R>, R>(token: T, args: R): Promise<InstanceType<T>>;
|
|
714
|
-
get<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): Promise<T>;
|
|
715
|
-
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';
|
|
716
|
-
get<T>(token: InjectionToken<T, undefined>): Promise<T>;
|
|
717
|
-
get<T>(token: BoundInjectionToken<T, any>): Promise<T>;
|
|
718
|
-
get<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
|
|
719
|
-
/**
|
|
720
|
-
* Invalidates a service and its dependencies.
|
|
721
|
-
* For request-scoped services, invalidation is handled within this context.
|
|
722
|
-
*/
|
|
723
|
-
invalidate(service: unknown): Promise<void>;
|
|
724
|
-
/**
|
|
725
|
-
* Checks if a service is registered.
|
|
726
|
-
*/
|
|
727
|
-
isRegistered(token: any): boolean;
|
|
728
|
-
/**
|
|
729
|
-
* Disposes this scoped container and cleans up all request-scoped instances.
|
|
730
|
-
* This is an alias for endRequest() for IContainer compatibility.
|
|
731
|
-
*/
|
|
732
|
-
dispose(): Promise<void>;
|
|
733
|
-
/**
|
|
734
|
-
* Ends the request and cleans up all request-scoped instances.
|
|
735
|
-
* Uses the invalidation system to properly cascade to dependent singletons.
|
|
736
|
-
*/
|
|
737
|
-
endRequest(): Promise<void>;
|
|
738
|
-
/**
|
|
739
|
-
* Waits for all pending operations to complete.
|
|
740
|
-
*/
|
|
741
|
-
ready(): Promise<void>;
|
|
742
|
-
/**
|
|
743
|
-
* @internal
|
|
744
|
-
* Attempts to get an instance synchronously if it already exists and is ready.
|
|
745
|
-
* For request-scoped services, checks this container's context first.
|
|
746
|
-
* For other services, delegates to the parent container.
|
|
747
|
-
*
|
|
748
|
-
* Returns null if the instance doesn't exist or is not yet ready (still creating).
|
|
749
|
-
*/
|
|
750
|
-
tryGetSync<T>(token: any, args?: any): T | null;
|
|
751
|
-
/**
|
|
752
|
-
* Checks if a token is for a request-scoped service.
|
|
753
|
-
*/
|
|
754
|
-
private isRequestScoped;
|
|
755
|
-
/**
|
|
756
|
-
* Resolves a request-scoped service from this container's context.
|
|
757
|
-
* Uses locking to prevent duplicate initialization during concurrent resolution.
|
|
758
|
-
*/
|
|
759
|
-
private resolveRequestScoped;
|
|
760
|
-
/**
|
|
761
|
-
* Stores an instance in the request context.
|
|
762
|
-
* Called by Container during request-scoped service resolution.
|
|
763
|
-
*/
|
|
764
|
-
storeRequestInstance(instanceName: string, instance: any, holder: InstanceHolder): void;
|
|
765
|
-
/**
|
|
766
|
-
* Gets an existing instance from the request context.
|
|
767
|
-
* Called by Container during resolution to check for existing instances.
|
|
768
|
-
*/
|
|
769
|
-
getRequestInstance(instanceName: string): InstanceHolder | undefined;
|
|
770
|
-
/**
|
|
771
|
-
* Generates a prefixed event name for request-scoped services.
|
|
772
|
-
* Format: {requestId}:{instanceName}
|
|
773
|
-
*/
|
|
774
|
-
getPrefixedEventName(instanceName: string): string;
|
|
775
|
-
}
|
|
776
|
-
//#endregion
|
|
777
|
-
//#region src/internal/lifecycle/lifecycle-event-bus.d.mts
|
|
778
|
-
/**
|
|
779
|
-
* Event bus for service lifecycle events (create, destroy, etc.).
|
|
780
|
-
*
|
|
781
|
-
* Enables loose coupling between services by allowing them to subscribe
|
|
782
|
-
* to lifecycle events of their dependencies without direct references.
|
|
783
|
-
* Used primarily for invalidation cascading.
|
|
784
|
-
*/
|
|
785
|
-
declare class LifecycleEventBus {
|
|
786
|
-
private readonly logger;
|
|
787
|
-
private listeners;
|
|
788
|
-
constructor(logger?: Console | null);
|
|
789
|
-
on<Event extends string | `pre:${string}` | `post:${string}`>(ns: string, event: Event, listener: (event: Event) => void): () => void;
|
|
790
|
-
emit(key: string, event: string): Promise<PromiseSettledResult<any>[] | undefined>;
|
|
791
|
-
}
|
|
792
|
-
//#endregion
|
|
793
|
-
//#region src/internal/holder/holder-manager.d.mts
|
|
794
|
-
/**
|
|
795
|
-
* Manages the storage and retrieval of singleton instance holders.
|
|
796
|
-
*
|
|
797
|
-
* Provides CRUD operations and filtering for the holder map.
|
|
798
|
-
* Handles holder state validation (destroying, error states) on retrieval.
|
|
799
|
-
*/
|
|
800
|
-
declare class HolderManager extends BaseHolderManager {
|
|
801
|
-
constructor(logger?: Console | null);
|
|
802
|
-
get(name: string): [DIError, InstanceHolder] | [DIError] | [undefined, InstanceHolder];
|
|
803
|
-
set(name: string, holder: InstanceHolder): void;
|
|
804
|
-
has(name: string): [DIError] | [undefined, boolean];
|
|
805
|
-
/**
|
|
806
|
-
* Creates a new holder with Created status and stores it.
|
|
807
|
-
* This is useful for creating holders that already have their instance ready.
|
|
808
|
-
* @param name The name of the instance
|
|
809
|
-
* @param instance The actual instance to store
|
|
810
|
-
* @param type The injectable type
|
|
811
|
-
* @param scope The injectable scope
|
|
812
|
-
* @param deps Optional set of dependencies
|
|
813
|
-
* @returns The created holder
|
|
814
|
-
*/
|
|
815
|
-
storeCreatedHolder<Instance>(name: string, instance: Instance, type: InjectableType, scope: InjectableScope, deps?: Set<string>): InstanceHolder<Instance>;
|
|
816
|
-
}
|
|
817
|
-
//#endregion
|
|
818
|
-
//#region src/internal/core/invalidator.d.mts
|
|
819
|
-
interface ClearAllOptions {
|
|
820
|
-
/** Maximum number of invalidation rounds to prevent infinite loops (default: 10) */
|
|
821
|
-
maxRounds?: number;
|
|
822
|
-
/** Whether to wait for all services to settle before starting (default: true) */
|
|
823
|
-
waitForSettlement?: boolean;
|
|
824
|
-
}
|
|
825
|
-
interface InvalidationOptions {
|
|
826
|
-
/** Whether to emit events after invalidation (default: true for singletons) */
|
|
827
|
-
emitEvents?: boolean;
|
|
828
|
-
/** Custom event emitter function */
|
|
829
|
-
onInvalidated?: (instanceName: string) => Promise<void>;
|
|
830
|
-
/** Whether to cascade invalidation to dependents (default: true) */
|
|
831
|
-
cascade?: boolean;
|
|
832
|
-
/** Internal: tracks services being invalidated in the current call chain to prevent circular loops */
|
|
833
|
-
_invalidating?: Set<string>;
|
|
834
|
-
}
|
|
835
|
-
/**
|
|
836
|
-
* Manages graceful service cleanup with dependency-aware invalidation.
|
|
837
|
-
*
|
|
838
|
-
* Ensures services are destroyed in the correct order based on their dependencies.
|
|
839
|
-
* Works with any IHolderStorage implementation, enabling unified invalidation
|
|
840
|
-
* for both singleton and request-scoped services.
|
|
841
|
-
*/
|
|
842
|
-
declare class Invalidator {
|
|
843
|
-
private readonly eventBus;
|
|
844
|
-
private readonly logger;
|
|
845
|
-
private readonly storage;
|
|
846
|
-
constructor(manager: HolderManager, eventBus: LifecycleEventBus | null, logger?: Console | null);
|
|
847
|
-
/**
|
|
848
|
-
* Invalidates a service and all its dependencies.
|
|
849
|
-
* Works with the configured storage (singleton by default).
|
|
850
|
-
*/
|
|
851
|
-
invalidate(service: string, round?: number): Promise<any>;
|
|
852
|
-
/**
|
|
853
|
-
* Invalidates a service using a specific storage.
|
|
854
|
-
* This allows request-scoped invalidation using a RequestStorage.
|
|
855
|
-
*
|
|
856
|
-
* @param service The instance name to invalidate
|
|
857
|
-
* @param storage The storage to use for this invalidation
|
|
858
|
-
* @param round Current invalidation round (for recursion limiting)
|
|
859
|
-
* @param options Additional options for invalidation behavior
|
|
860
|
-
*/
|
|
861
|
-
invalidateWithStorage(service: string, storage: IHolderStorage, round?: number, options?: InvalidationOptions): Promise<void>;
|
|
862
|
-
/**
|
|
863
|
-
* Gracefully clears all services using invalidation logic.
|
|
864
|
-
* This method respects service dependencies and ensures proper cleanup order.
|
|
865
|
-
* Services that depend on others will be invalidated first, then their dependencies.
|
|
866
|
-
*/
|
|
867
|
-
clearAll(options?: ClearAllOptions): Promise<void>;
|
|
868
|
-
/**
|
|
869
|
-
* Gracefully clears all services in a specific storage.
|
|
870
|
-
* This allows clearing request-scoped services using a RequestStorage.
|
|
871
|
-
*/
|
|
872
|
-
clearAllWithStorage(storage: IHolderStorage, options?: ClearAllOptions): Promise<void>;
|
|
873
|
-
/**
|
|
874
|
-
* Waits for all services to settle (either created, destroyed, or error state).
|
|
875
|
-
*/
|
|
876
|
-
ready(): Promise<void>;
|
|
877
|
-
/**
|
|
878
|
-
* Waits for all services in a specific storage to settle.
|
|
879
|
-
*/
|
|
880
|
-
readyWithStorage(storage: IHolderStorage): Promise<void>;
|
|
881
|
-
/**
|
|
882
|
-
* Invalidates a single holder using a specific storage.
|
|
883
|
-
*/
|
|
884
|
-
private invalidateHolderWithStorage;
|
|
885
|
-
/**
|
|
886
|
-
* Common invalidation logic for holders based on their status.
|
|
887
|
-
*/
|
|
888
|
-
private invalidateHolderByStatus;
|
|
889
|
-
/**
|
|
890
|
-
* Destroys a holder using a specific storage.
|
|
891
|
-
*/
|
|
892
|
-
private destroyHolderWithStorage;
|
|
893
|
-
/**
|
|
894
|
-
* Waits for a holder to settle (either created, destroyed, or error state).
|
|
895
|
-
*/
|
|
896
|
-
private waitForHolderToSettle;
|
|
897
|
-
/**
|
|
898
|
-
* Clears services with dependency awareness for a specific storage.
|
|
899
|
-
*/
|
|
900
|
-
private clearServicesWithDependencyAwarenessForStorage;
|
|
901
|
-
/**
|
|
902
|
-
* Finds services that are ready to be cleared in the current round.
|
|
903
|
-
* A service is ready if all its dependencies have already been cleared.
|
|
904
|
-
*/
|
|
905
|
-
private findServicesReadyForClearingInStorage;
|
|
906
|
-
/**
|
|
907
|
-
* Force clears services that couldn't be cleared through normal dependency resolution.
|
|
908
|
-
* This handles edge cases like circular dependencies.
|
|
909
|
-
*/
|
|
910
|
-
private forceClearServicesInStorage;
|
|
911
|
-
/**
|
|
912
|
-
* Emits events to listeners for instance lifecycle events.
|
|
913
|
-
*/
|
|
914
|
-
private emitInstanceEvent;
|
|
915
|
-
}
|
|
916
|
-
//#endregion
|
|
917
|
-
//#region src/internal/core/token-processor.d.mts
|
|
918
|
-
/**
|
|
919
|
-
* Handles token validation, normalization, and instance name generation.
|
|
920
|
-
*
|
|
921
|
-
* Provides utilities for resolving tokens to their underlying InjectionToken,
|
|
922
|
-
* validating arguments against schemas, and generating unique instance identifiers.
|
|
923
|
-
*/
|
|
924
|
-
declare class TokenProcessor {
|
|
925
|
-
private readonly logger;
|
|
926
|
-
constructor(logger?: Console | null);
|
|
927
|
-
/**
|
|
928
|
-
* Normalizes a token to an InjectionToken.
|
|
929
|
-
* Handles class constructors by getting their injectable token.
|
|
930
|
-
*
|
|
931
|
-
* @param token A class constructor, InjectionToken, BoundInjectionToken, or FactoryInjectionToken
|
|
932
|
-
* @returns The normalized InjectionTokenType
|
|
933
|
-
*/
|
|
934
|
-
normalizeToken(token: AnyInjectableType): InjectionTokenType;
|
|
935
|
-
/**
|
|
936
|
-
* Gets the underlying "real" token from wrapped tokens.
|
|
937
|
-
* For BoundInjectionToken and FactoryInjectionToken, returns the wrapped token.
|
|
938
|
-
* For other tokens, returns the token itself.
|
|
939
|
-
*
|
|
940
|
-
* @param token The token to unwrap
|
|
941
|
-
* @returns The underlying InjectionToken
|
|
942
|
-
*/
|
|
943
|
-
getRealToken<T = unknown>(token: InjectionTokenType): InjectionToken<T>;
|
|
944
|
-
/**
|
|
945
|
-
* Convenience method that normalizes a token and then gets the real token.
|
|
946
|
-
* Useful for checking registry entries where you need the actual registered token.
|
|
947
|
-
*
|
|
948
|
-
* @param token Any injectable type
|
|
949
|
-
* @returns The underlying InjectionToken
|
|
950
|
-
*/
|
|
951
|
-
getRegistryToken<T = unknown>(token: AnyInjectableType): InjectionToken<T>;
|
|
952
|
-
/**
|
|
953
|
-
* Validates and resolves token arguments, handling factory token resolution and validation.
|
|
954
|
-
*/
|
|
955
|
-
validateAndResolveTokenArgs(token: AnyInjectableType, args?: any): [DIError | undefined, {
|
|
956
|
-
actualToken: InjectionTokenType;
|
|
957
|
-
validatedArgs?: any;
|
|
958
|
-
}];
|
|
959
|
-
/**
|
|
960
|
-
* Generates a unique instance name based on token and arguments.
|
|
961
|
-
*/
|
|
962
|
-
generateInstanceName(token: InjectionTokenType, args: any): string;
|
|
963
|
-
/**
|
|
964
|
-
* Formats a single argument value for instance name generation.
|
|
965
|
-
*/
|
|
966
|
-
formatArgValue(value: any): string;
|
|
967
|
-
/**
|
|
968
|
-
* Creates a factory context for dependency injection during service instantiation.
|
|
969
|
-
* @param container The container instance (Container or ScopedContainer) for dependency resolution
|
|
970
|
-
* @param onDependencyResolved Callback when a dependency is resolved, receives the instance name
|
|
971
|
-
*/
|
|
972
|
-
createFactoryContext(container: IContainer, onDependencyResolved?: (instanceName: string) => void): FactoryContext & {
|
|
973
|
-
getDestroyListeners: () => (() => void)[];
|
|
974
|
-
deps: Set<string>;
|
|
975
|
-
};
|
|
976
|
-
}
|
|
977
|
-
//#endregion
|
|
978
|
-
//#region src/internal/core/service-locator.d.mts
|
|
979
|
-
/**
|
|
980
|
-
* Core DI engine that coordinates service instantiation, resolution, and lifecycle.
|
|
981
|
-
*
|
|
982
|
-
* Acts as the central orchestrator for dependency injection operations,
|
|
983
|
-
* delegating to specialized components (InstanceResolver, Instantiator, Invalidator)
|
|
984
|
-
* for specific tasks.
|
|
985
|
-
*/
|
|
986
|
-
declare class ServiceLocator {
|
|
987
|
-
private readonly registry;
|
|
988
|
-
private readonly logger;
|
|
989
|
-
private readonly injectors;
|
|
990
|
-
private readonly eventBus;
|
|
991
|
-
private readonly manager;
|
|
992
|
-
private readonly instantiator;
|
|
993
|
-
private readonly tokenProcessor;
|
|
994
|
-
private readonly invalidator;
|
|
995
|
-
private readonly instanceResolver;
|
|
996
|
-
constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
|
|
997
|
-
getEventBus(): LifecycleEventBus;
|
|
998
|
-
getManager(): HolderManager;
|
|
999
|
-
getInvalidator(): Invalidator;
|
|
1000
|
-
getTokenProcessor(): TokenProcessor;
|
|
1001
|
-
getInstanceIdentifier(token: AnyInjectableType, args?: any): string;
|
|
1002
|
-
/**
|
|
1003
|
-
* Gets or creates an instance for the given token.
|
|
1004
|
-
* @param token The injection token
|
|
1005
|
-
* @param args Optional arguments
|
|
1006
|
-
* @param contextContainer The container to use for creating FactoryContext
|
|
1007
|
-
*/
|
|
1008
|
-
getInstance(token: AnyInjectableType, args: any, contextContainer: IContainer): Promise<any[]>;
|
|
1009
|
-
/**
|
|
1010
|
-
* Gets or throws an instance for the given token.
|
|
1011
|
-
* @param token The injection token
|
|
1012
|
-
* @param args Optional arguments
|
|
1013
|
-
* @param contextContainer The container to use for creating FactoryContext
|
|
1014
|
-
*/
|
|
1015
|
-
getOrThrowInstance<Instance>(token: AnyInjectableType, args: any, contextContainer: IContainer): Promise<Instance>;
|
|
1016
|
-
/**
|
|
1017
|
-
* Resolves a request-scoped service for a ScopedContainer.
|
|
1018
|
-
* The service will be stored in the ScopedContainer's request context.
|
|
1019
|
-
*
|
|
1020
|
-
* @param token The injection token
|
|
1021
|
-
* @param args Optional arguments
|
|
1022
|
-
* @param scopedContainer The ScopedContainer that owns the request context
|
|
1023
|
-
*/
|
|
1024
|
-
resolveRequestScoped(token: AnyInjectableType, args: any, scopedContainer: ScopedContainer): Promise<any>;
|
|
1025
|
-
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;
|
|
1026
|
-
invalidate(service: string, round?: number): Promise<any>;
|
|
1027
|
-
/**
|
|
1028
|
-
* Gracefully clears all services in the ServiceLocator using invalidation logic.
|
|
1029
|
-
* This method respects service dependencies and ensures proper cleanup order.
|
|
1030
|
-
* Services that depend on others will be invalidated first, then their dependencies.
|
|
1031
|
-
*
|
|
1032
|
-
* @param options Optional configuration for the clearing process
|
|
1033
|
-
* @returns Promise that resolves when all services have been cleared
|
|
1034
|
-
*/
|
|
1035
|
-
clearAll(options?: ClearAllOptions): Promise<void>;
|
|
1036
|
-
/**
|
|
1037
|
-
* Waits for all services to settle (either created, destroyed, or error state).
|
|
1038
|
-
*/
|
|
1039
|
-
ready(): Promise<void>;
|
|
1040
|
-
/**
|
|
1041
|
-
* Helper method for InstanceResolver to generate instance names.
|
|
1042
|
-
* This is needed for the factory context creation.
|
|
1043
|
-
*/
|
|
1044
|
-
generateInstanceName(token: any, args: any): string;
|
|
1045
|
-
}
|
|
1046
|
-
//#endregion
|
|
1047
|
-
//#region src/container/container.d.mts
|
|
1048
|
-
/**
|
|
1049
|
-
* Main dependency injection container.
|
|
1050
|
-
*
|
|
1051
|
-
* Provides a simplified public API for dependency injection, wrapping
|
|
1052
|
-
* a ServiceLocator instance. Handles singleton and transient services directly,
|
|
1053
|
-
* while request-scoped services require using beginRequest() to create a ScopedContainer.
|
|
1054
|
-
*/
|
|
1055
|
-
declare class Container implements IContainer {
|
|
1056
|
-
protected readonly registry: Registry;
|
|
1057
|
-
protected readonly logger: Console | null;
|
|
1058
|
-
protected readonly injectors: Injectors;
|
|
1059
|
-
private readonly serviceLocator;
|
|
1060
|
-
private readonly activeRequestIds;
|
|
1061
|
-
constructor(registry?: Registry, logger?: Console | null, injectors?: Injectors);
|
|
1062
|
-
private registerSelf;
|
|
1063
|
-
/**
|
|
1064
|
-
* Gets an instance from the container.
|
|
1065
|
-
* This method has the same type signature as the inject method from get-injectors.mts
|
|
1066
|
-
*
|
|
1067
|
-
* NOTE: Request-scoped services cannot be resolved directly from Container.
|
|
1068
|
-
* Use beginRequest() to create a ScopedContainer for request-scoped services.
|
|
1069
|
-
*/
|
|
1070
|
-
get<T extends ClassType>(token: T): InstanceType<T> extends Factorable<infer R> ? Promise<R> : Promise<InstanceType<T>>;
|
|
1071
|
-
get<T extends ClassTypeWithArgument<R>, R>(token: T, args: R): Promise<InstanceType<T>>;
|
|
1072
|
-
get<T, S extends InjectionTokenSchemaType>(token: InjectionToken<T, S>, args: z.input<S>): Promise<T>;
|
|
1073
|
-
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';
|
|
1074
|
-
get<T>(token: InjectionToken<T, undefined>): Promise<T>;
|
|
1075
|
-
get<T>(token: BoundInjectionToken<T, any>): Promise<T>;
|
|
1076
|
-
get<T>(token: FactoryInjectionToken<T, any>): Promise<T>;
|
|
1077
|
-
/**
|
|
1078
|
-
* Gets an instance with a specific container context.
|
|
1079
|
-
* Used by ScopedContainer to delegate singleton/transient resolution
|
|
1080
|
-
* while maintaining the correct container context for nested inject() calls.
|
|
1081
|
-
*
|
|
1082
|
-
* @internal
|
|
1083
|
-
*/
|
|
1084
|
-
getWithContext(token: ClassType | InjectionToken<any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>, args: unknown, contextContainer: IContainer): Promise<any>;
|
|
1085
|
-
/**
|
|
1086
|
-
* Resolves a request-scoped service for a ScopedContainer.
|
|
1087
|
-
* The service will be stored in the ScopedContainer's request context.
|
|
1088
|
-
*
|
|
1089
|
-
* @internal
|
|
1090
|
-
*/
|
|
1091
|
-
resolveForRequest(token: ClassType | InjectionToken<any> | BoundInjectionToken<any, any> | FactoryInjectionToken<any, any>, args: unknown, scopedContainer: ScopedContainer): Promise<any>;
|
|
1092
|
-
/**
|
|
1093
|
-
* Gets the underlying ServiceLocator instance for advanced usage
|
|
1094
|
-
*/
|
|
1095
|
-
getServiceLocator(): ServiceLocator;
|
|
1096
|
-
/**
|
|
1097
|
-
* Gets the registry
|
|
1098
|
-
*/
|
|
1099
|
-
getRegistry(): Registry;
|
|
1100
|
-
/**
|
|
1101
|
-
* Invalidates a service and its dependencies
|
|
1102
|
-
*/
|
|
1103
|
-
invalidate(service: unknown): Promise<void>;
|
|
1104
|
-
/**
|
|
1105
|
-
* Gets a service holder by instance (reverse lookup)
|
|
1106
|
-
*/
|
|
1107
|
-
private getHolderByInstance;
|
|
1108
|
-
/**
|
|
1109
|
-
* Checks if a service is registered in the container
|
|
1110
|
-
*/
|
|
1111
|
-
isRegistered(token: any): boolean;
|
|
1112
|
-
/**
|
|
1113
|
-
* Disposes the container and cleans up all resources
|
|
1114
|
-
*/
|
|
1115
|
-
dispose(): Promise<void>;
|
|
1116
|
-
/**
|
|
1117
|
-
* Waits for all pending operations to complete
|
|
1118
|
-
*/
|
|
1119
|
-
ready(): Promise<void>;
|
|
1120
|
-
/**
|
|
1121
|
-
* @internal
|
|
1122
|
-
* Attempts to get an instance synchronously if it already exists.
|
|
1123
|
-
* Returns null if the instance doesn't exist or is not ready.
|
|
1124
|
-
*/
|
|
1125
|
-
tryGetSync<T>(token: any, args?: any): T | null;
|
|
1126
|
-
/**
|
|
1127
|
-
* Begins a new request context and returns a ScopedContainer.
|
|
1128
|
-
*
|
|
1129
|
-
* The ScopedContainer provides isolated request-scoped service resolution
|
|
1130
|
-
* while delegating singleton and transient services to this Container.
|
|
1131
|
-
*
|
|
1132
|
-
* @param requestId Unique identifier for this request
|
|
1133
|
-
* @param metadata Optional metadata for the request
|
|
1134
|
-
* @param priority Priority for resolution (higher = more priority)
|
|
1135
|
-
* @returns A ScopedContainer for this request
|
|
1136
|
-
*/
|
|
1137
|
-
beginRequest(requestId: string, metadata?: Record<string, any>, priority?: number): ScopedContainer;
|
|
1138
|
-
/**
|
|
1139
|
-
* Removes a request ID from the active set.
|
|
1140
|
-
* Called by ScopedContainer when the request ends.
|
|
1141
|
-
*
|
|
1142
|
-
* @internal
|
|
1143
|
-
*/
|
|
1144
|
-
removeActiveRequest(requestId: string): void;
|
|
1145
|
-
/**
|
|
1146
|
-
* Gets the set of active request IDs.
|
|
1147
|
-
*/
|
|
1148
|
-
getActiveRequestIds(): ReadonlySet<string>;
|
|
1149
|
-
/**
|
|
1150
|
-
* Checks if a request ID is currently active.
|
|
1151
|
-
*/
|
|
1152
|
-
hasActiveRequest(requestId: string): boolean;
|
|
1153
|
-
/**
|
|
1154
|
-
* Clears all instances and bindings from the container.
|
|
1155
|
-
* This is useful for testing or resetting the container state.
|
|
1156
|
-
*/
|
|
1157
|
-
clear(): Promise<void>;
|
|
1158
|
-
}
|
|
1159
|
-
//#endregion
|
|
1160
|
-
//#region src/interfaces/on-service-init.interface.d.mts
|
|
1161
|
-
interface OnServiceInit {
|
|
1162
|
-
onServiceInit(): Promise<void> | void;
|
|
1163
|
-
}
|
|
1164
|
-
//#endregion
|
|
1165
|
-
//#region src/interfaces/on-service-destroy.interface.d.mts
|
|
1166
|
-
interface OnServiceDestroy {
|
|
1167
|
-
onServiceDestroy(): Promise<void> | void;
|
|
1168
|
-
}
|
|
1169
|
-
//#endregion
|
|
1170
|
-
//#region src/decorators/factory.decorator.d.mts
|
|
1171
|
-
interface FactoryOptions {
|
|
1172
|
-
scope?: InjectableScope;
|
|
1173
|
-
token?: InjectionToken<any, any>;
|
|
1174
|
-
registry?: Registry;
|
|
1175
|
-
}
|
|
1176
|
-
declare function Factory<R>(options?: {
|
|
1177
|
-
scope?: InjectableScope;
|
|
1178
|
-
registry?: Registry;
|
|
1179
|
-
}): <T extends ClassTypeWithInstance<Factorable<R>>>(target: T, context?: ClassDecoratorContext) => T;
|
|
1180
|
-
declare function Factory<R, S>(options: {
|
|
1181
|
-
scope?: InjectableScope;
|
|
1182
|
-
token: InjectionToken<R, S>;
|
|
1183
|
-
registry?: Registry;
|
|
1184
|
-
}): R extends undefined ? never : S extends InjectionTokenSchemaType ? <T extends ClassTypeWithInstance<FactorableWithArgs<R, S>>>(
|
|
1185
|
-
// #2.2.1 Token have a schema
|
|
1186
|
-
target: T, context?: ClassDecoratorContext) => T : S extends undefined ? <T extends ClassTypeWithInstance<Factorable<R>>>(
|
|
1187
|
-
// #2.3.1 Token without a schema
|
|
1188
|
-
target: T, context?: ClassDecoratorContext) => T : never;
|
|
1189
|
-
//#endregion
|
|
1190
|
-
//#region src/decorators/injectable.decorator.d.mts
|
|
1191
|
-
interface InjectableOptions {
|
|
1192
|
-
scope?: InjectableScope;
|
|
1193
|
-
token?: InjectionToken<any, any>;
|
|
1194
|
-
schema?: InjectionTokenSchemaType;
|
|
1195
|
-
registry?: Registry;
|
|
1196
|
-
}
|
|
1197
|
-
declare function Injectable(): <T extends ClassTypeWithoutArguments>(target: T, context?: ClassDecoratorContext) => T;
|
|
1198
|
-
declare function Injectable(options: {
|
|
1199
|
-
scope?: InjectableScope;
|
|
1200
|
-
registry: Registry;
|
|
1201
|
-
}): <T extends ClassTypeWithoutArguments>(target: T, context?: ClassDecoratorContext) => T;
|
|
1202
|
-
declare function Injectable(options: {
|
|
1203
|
-
scope: InjectableScope;
|
|
1204
|
-
}): <T extends ClassTypeWithoutArguments>(target: T, context?: ClassDecoratorContext) => T;
|
|
1205
|
-
declare function Injectable<Schema extends InjectionTokenSchemaType>(options: {
|
|
1206
|
-
scope?: InjectableScope;
|
|
1207
|
-
schema: Schema;
|
|
1208
|
-
registry?: Registry;
|
|
1209
|
-
}): <T extends ClassTypeWithArgument<z.output<Schema>>>(target: T, context?: ClassDecoratorContext) => T;
|
|
1210
|
-
declare function Injectable<Type$1, Schema>(options: {
|
|
1211
|
-
scope?: InjectableScope;
|
|
1212
|
-
token: InjectionToken<Type$1, Schema>;
|
|
1213
|
-
registry?: Registry;
|
|
1214
|
-
}): Schema extends BaseInjectionTokenSchemaType ? Type$1 extends undefined ? <T extends ClassTypeWithArgument<z.output<Schema>>>(
|
|
1215
|
-
// #3.1.1 Typeless token
|
|
1216
|
-
target: T, context?: ClassDecoratorContext) => T : <T extends ClassTypeWithInstanceAndArgument<Type$1, z.output<Schema>>>(
|
|
1217
|
-
// #3.1.2 Typed token
|
|
1218
|
-
target: T, context?: ClassDecoratorContext) => T : Schema extends OptionalInjectionTokenSchemaType ? Type$1 extends undefined ? <T extends ClassTypeWithOptionalArgument<z.output<Schema>>>(
|
|
1219
|
-
// #3.2.1 Typeless token
|
|
1220
|
-
target: T, context?: ClassDecoratorContext) => T : <T extends ClassTypeWithInstanceAndOptionalArgument<Type$1, z.output<Schema>>>(target: T, context?: ClassDecoratorContext) => T : Schema extends undefined ? <R extends ClassTypeWithInstance<Type$1>>(
|
|
1221
|
-
// #3.3.1 Token must have a type
|
|
1222
|
-
target: R, context?: ClassDecoratorContext) => R : never;
|
|
1223
|
-
//#endregion
|
|
1224
|
-
//#region src/symbols/injectable-token.d.mts
|
|
1225
|
-
declare const InjectableTokenMeta: unique symbol;
|
|
1226
|
-
//#endregion
|
|
1227
|
-
//#region src/event-emitter.d.mts
|
|
1228
|
-
type EventsConfig = {
|
|
1229
|
-
[event: string]: any[];
|
|
1230
|
-
};
|
|
1231
|
-
type EventsNames<Events extends EventsConfig> = Exclude<keyof Events, symbol | number>;
|
|
1232
|
-
type EventsArgs<Events extends EventsConfig, Name extends EventsNames<Events>> = Events[Name] extends any[] ? Events[Name] : [];
|
|
1233
|
-
interface EventEmitterInterface<Events extends EventsConfig> {
|
|
1234
|
-
on<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void | Promise<void>): () => void;
|
|
1235
|
-
emit<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, ...args: Args): void | Promise<void>;
|
|
1236
|
-
}
|
|
1237
|
-
declare class EventEmitter<Events extends EventsConfig = {}> implements EventEmitterInterface<Events> {
|
|
1238
|
-
private listeners;
|
|
1239
|
-
on<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void | Promise<void>): () => void;
|
|
1240
|
-
off<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void | Promise<void>): void;
|
|
1241
|
-
once<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, listener: (...args: Args) => void | Promise<void>): () => void;
|
|
1242
|
-
emit<E extends EventsNames<Events>, Args extends EventsArgs<Events, E>>(event: E, ...args: Args): Promise<any>;
|
|
1243
|
-
}
|
|
1244
|
-
//#endregion
|
|
1245
|
-
//#region src/injectors.d.mts
|
|
1246
|
-
declare const defaultInjectors: Injectors;
|
|
1247
|
-
declare const asyncInject: Injectors['asyncInject'];
|
|
1248
|
-
declare const inject: Injectors['inject'];
|
|
1249
|
-
declare const optional: Injectors['optional'];
|
|
1250
|
-
declare const wrapSyncInit: Injectors['wrapSyncInit'];
|
|
1251
|
-
declare const provideFactoryContext: Injectors['provideFactoryContext'];
|
|
1252
|
-
//#endregion
|
|
1253
|
-
//#region src/internal/context/resolution-context.d.mts
|
|
1254
|
-
/**
|
|
1255
|
-
* Data stored in the resolution context during service instantiation.
|
|
1256
|
-
*/
|
|
1257
|
-
interface ResolutionContextData {
|
|
1258
|
-
/** The holder that is currently being instantiated */
|
|
1259
|
-
waiterHolder: InstanceHolder;
|
|
1260
|
-
/** Function to get a holder by name (for cycle detection) */
|
|
1261
|
-
getHolder: (name: string) => InstanceHolder | undefined;
|
|
1262
|
-
}
|
|
1263
|
-
/**
|
|
1264
|
-
* Runs a function within a resolution context.
|
|
1265
|
-
*
|
|
1266
|
-
* The context tracks which holder is currently being instantiated,
|
|
1267
|
-
* allowing circular dependency detection to work correctly.
|
|
1268
|
-
*
|
|
1269
|
-
* @param waiterHolder The holder being instantiated
|
|
1270
|
-
* @param getHolder Function to retrieve holders by name
|
|
1271
|
-
* @param fn The function to run within the context
|
|
1272
|
-
*/
|
|
1273
|
-
declare function withResolutionContext<T>(waiterHolder: InstanceHolder, getHolder: (name: string) => InstanceHolder | undefined, fn: () => T): T;
|
|
1274
|
-
/**
|
|
1275
|
-
* Gets the current resolution context, if any.
|
|
1276
|
-
*
|
|
1277
|
-
* Returns undefined if we're not inside a resolution context
|
|
1278
|
-
* (e.g., when resolving a top-level service that has no parent).
|
|
1279
|
-
*/
|
|
1280
|
-
declare function getCurrentResolutionContext(): ResolutionContextData | undefined;
|
|
1281
|
-
/**
|
|
1282
|
-
* Runs a function outside any resolution context.
|
|
1283
|
-
*
|
|
1284
|
-
* This is useful for async injections that should not participate
|
|
1285
|
-
* in circular dependency detection since they don't block.
|
|
1286
|
-
*
|
|
1287
|
-
* @param fn The function to run without resolution context
|
|
1288
|
-
*/
|
|
1289
|
-
declare function withoutResolutionContext<T>(fn: () => T): T;
|
|
1290
|
-
//#endregion
|
|
1291
|
-
//#region src/internal/holder/singleton-storage.d.mts
|
|
1292
|
-
/**
|
|
1293
|
-
* Storage implementation for Singleton-scoped services.
|
|
1294
|
-
*
|
|
1295
|
-
* Wraps a HolderManager instance and provides the IHolderStorage interface.
|
|
1296
|
-
* This allows the InstanceResolver to work with singleton storage
|
|
1297
|
-
* using the same interface as request-scoped storage.
|
|
1298
|
-
*/
|
|
1299
|
-
declare class SingletonStorage implements IHolderStorage {
|
|
1300
|
-
private readonly manager;
|
|
1301
|
-
readonly scope = InjectableScope.Singleton;
|
|
1302
|
-
constructor(manager: HolderManager);
|
|
1303
|
-
get<T = unknown>(instanceName: string): HolderGetResult<T>;
|
|
1304
|
-
set(instanceName: string, holder: InstanceHolder): void;
|
|
1305
|
-
delete(instanceName: string): boolean;
|
|
1306
|
-
createHolder<T>(instanceName: string, type: InjectableType, deps: Set<string>): [ReturnType<typeof Promise.withResolvers<[undefined, T]>>, InstanceHolder<T>];
|
|
1307
|
-
handles(scope: InjectableScope): boolean;
|
|
1308
|
-
getAllNames(): string[];
|
|
1309
|
-
forEach(callback: (name: string, holder: InstanceHolder) => void): void;
|
|
1310
|
-
findByInstance(instance: unknown): InstanceHolder | null;
|
|
1311
|
-
findDependents(instanceName: string): string[];
|
|
1312
|
-
}
|
|
1313
|
-
//#endregion
|
|
1314
|
-
//#region src/internal/holder/request-storage.d.mts
|
|
1315
|
-
/**
|
|
1316
|
-
* Storage implementation for Request-scoped services.
|
|
1317
|
-
*
|
|
1318
|
-
* Wraps a RequestContext instance from a ScopedContainer and provides
|
|
1319
|
-
* the IHolderStorage interface. This allows the InstanceResolver to work
|
|
1320
|
-
* with request-scoped storage using the same interface as singleton storage.
|
|
1321
|
-
*/
|
|
1322
|
-
declare class RequestStorage implements IHolderStorage {
|
|
1323
|
-
private readonly contextHolder;
|
|
1324
|
-
private readonly holderManager;
|
|
1325
|
-
readonly scope = InjectableScope.Request;
|
|
1326
|
-
constructor(contextHolder: RequestContext, holderManager: BaseHolderManager);
|
|
1327
|
-
get<T = unknown>(instanceName: string): HolderGetResult<T>;
|
|
1328
|
-
set(instanceName: string, holder: InstanceHolder): void;
|
|
1329
|
-
delete(instanceName: string): boolean;
|
|
1330
|
-
createHolder<T>(instanceName: string, type: InjectableType, deps: Set<string>): [ReturnType<typeof Promise.withResolvers<[undefined, T]>>, InstanceHolder<T>];
|
|
1331
|
-
handles(scope: InjectableScope): boolean;
|
|
1332
|
-
getAllNames(): string[];
|
|
1333
|
-
forEach(callback: (name: string, holder: InstanceHolder) => void): void;
|
|
1334
|
-
findByInstance(instance: unknown): InstanceHolder | null;
|
|
1335
|
-
findDependents(instanceName: string): string[];
|
|
1336
|
-
}
|
|
1337
|
-
//#endregion
|
|
1338
|
-
//#region src/internal/lifecycle/circular-detector.d.mts
|
|
1339
|
-
/**
|
|
1340
|
-
* Detects circular dependencies by analyzing the waitingFor relationships
|
|
1341
|
-
* between service holders.
|
|
1342
|
-
*
|
|
1343
|
-
* Uses BFS to traverse the waitingFor graph starting from a target holder
|
|
1344
|
-
* and checks if following the chain leads back to the waiter, indicating a circular dependency.
|
|
1345
|
-
*
|
|
1346
|
-
* Note: In production (NODE_ENV === 'production'), detection is skipped for performance.
|
|
1347
|
-
*/
|
|
1348
|
-
declare class CircularDetector {
|
|
1349
|
-
/**
|
|
1350
|
-
* Detects if waiting for `targetName` from `waiterName` would create a cycle.
|
|
1351
|
-
*
|
|
1352
|
-
* This works by checking if `targetName` (or any holder in its waitingFor chain)
|
|
1353
|
-
* is currently waiting for `waiterName`. If so, waiting would create a deadlock.
|
|
1354
|
-
*
|
|
1355
|
-
* In production mode, this always returns null to skip the BFS traversal overhead.
|
|
1356
|
-
*
|
|
1357
|
-
* @param waiterName The name of the holder that wants to wait
|
|
1358
|
-
* @param targetName The name of the holder being waited on
|
|
1359
|
-
* @param getHolder Function to retrieve a holder by name
|
|
1360
|
-
* @returns The cycle path if a cycle is detected, null otherwise
|
|
1361
|
-
*/
|
|
1362
|
-
static detectCycle(waiterName: string, targetName: string, getHolder: (name: string) => InstanceHolder | undefined): string[] | null;
|
|
1363
|
-
/**
|
|
1364
|
-
* Formats a cycle path into a human-readable string.
|
|
1365
|
-
*
|
|
1366
|
-
* @param cycle The cycle path (array of service names)
|
|
1367
|
-
* @returns Formatted string like "ServiceA -> ServiceB -> ServiceA"
|
|
1368
|
-
*/
|
|
1369
|
-
static formatCycle(cycle: string[]): string;
|
|
1370
|
-
}
|
|
1371
|
-
//#endregion
|
|
1372
|
-
//#region src/internal/core/instantiator.d.mts
|
|
1373
|
-
/**
|
|
1374
|
-
* Creates service instances from registry records.
|
|
1375
|
-
*
|
|
1376
|
-
* Handles both class-based (@Injectable) and factory-based (@Factory) services,
|
|
1377
|
-
* managing the instantiation lifecycle including sync initialization retries
|
|
1378
|
-
* and lifecycle hook invocation (onServiceInit, onServiceDestroy).
|
|
1379
|
-
*/
|
|
1380
|
-
declare class Instantiator {
|
|
1381
|
-
private readonly injectors;
|
|
1382
|
-
constructor(injectors: Injectors);
|
|
1383
|
-
/**
|
|
1384
|
-
* Instantiates a service based on its registry record.
|
|
1385
|
-
* @param ctx The factory context for dependency injection
|
|
1386
|
-
* @param record The factory record from the registry
|
|
1387
|
-
* @param args Optional arguments for the service
|
|
1388
|
-
* @returns Promise resolving to [undefined, instance] or [error]
|
|
1389
|
-
*/
|
|
1390
|
-
instantiateService<T>(ctx: FactoryContext, record: FactoryRecord<T, any>, args?: any): Promise<[undefined, T] | [DIError]>;
|
|
1391
|
-
/**
|
|
1392
|
-
* Instantiates a class-based service (Injectable decorator).
|
|
1393
|
-
* @param ctx The factory context for dependency injection
|
|
1394
|
-
* @param record The factory record from the registry
|
|
1395
|
-
* @param args Optional arguments for the service constructor
|
|
1396
|
-
* @returns Promise resolving to [undefined, instance] or [error]
|
|
1397
|
-
*/
|
|
1398
|
-
private instantiateClass;
|
|
1399
|
-
/**
|
|
1400
|
-
* Instantiates a factory-based service (Factory decorator).
|
|
1401
|
-
* @param ctx The factory context for dependency injection
|
|
1402
|
-
* @param record The factory record from the registry
|
|
1403
|
-
* @param args Optional arguments for the factory
|
|
1404
|
-
* @returns Promise resolving to [undefined, instance] or [error]
|
|
1405
|
-
*/
|
|
1406
|
-
private instantiateFactory;
|
|
1407
|
-
}
|
|
1408
|
-
//#endregion
|
|
1409
|
-
//#region src/internal/core/instance-resolver.d.mts
|
|
1410
|
-
/**
|
|
1411
|
-
* Resolves instances from tokens, handling caching, creation, and scope rules.
|
|
1412
|
-
*
|
|
1413
|
-
* Uses the Storage Strategy pattern for unified singleton/request-scoped handling.
|
|
1414
|
-
* Coordinates with Instantiator for actual service creation.
|
|
1415
|
-
*/
|
|
1416
|
-
declare class InstanceResolver {
|
|
1417
|
-
private readonly registry;
|
|
1418
|
-
private readonly manager;
|
|
1419
|
-
private readonly instantiator;
|
|
1420
|
-
private readonly tokenProcessor;
|
|
1421
|
-
private readonly logger;
|
|
1422
|
-
private readonly serviceLocator;
|
|
1423
|
-
private readonly singletonStorage;
|
|
1424
|
-
constructor(registry: Registry, manager: HolderManager, instantiator: Instantiator, tokenProcessor: TokenProcessor, logger: (Console | null) | undefined, serviceLocator: ServiceLocator);
|
|
1425
|
-
/**
|
|
1426
|
-
* Resolves an instance for the given token and arguments.
|
|
1427
|
-
* This method is used for singleton and transient services.
|
|
1428
|
-
*
|
|
1429
|
-
* @param token The injection token
|
|
1430
|
-
* @param args Optional arguments
|
|
1431
|
-
* @param contextContainer The container to use for creating FactoryContext
|
|
1432
|
-
*/
|
|
1433
|
-
resolveInstance(token: AnyInjectableType, args: any, contextContainer: IContainer): Promise<[undefined, any] | [DIError]>;
|
|
1434
|
-
/**
|
|
1435
|
-
* Resolves a request-scoped instance for a ScopedContainer.
|
|
1436
|
-
* The service will be stored in the ScopedContainer's request context.
|
|
1437
|
-
*
|
|
1438
|
-
* @param token The injection token
|
|
1439
|
-
* @param args Optional arguments
|
|
1440
|
-
* @param scopedContainer The ScopedContainer that owns the request context
|
|
1441
|
-
*/
|
|
1442
|
-
resolveRequestScopedInstance(token: AnyInjectableType, args: any, scopedContainer: ScopedContainer): Promise<[undefined, any] | [DIError]>;
|
|
1443
|
-
/**
|
|
1444
|
-
* Unified resolution method that works with any IHolderStorage.
|
|
1445
|
-
* This eliminates duplication between singleton and request-scoped resolution.
|
|
1446
|
-
*
|
|
1447
|
-
* IMPORTANT: The check-and-store logic is carefully designed to avoid race conditions.
|
|
1448
|
-
* The storage check and holder creation must happen synchronously (no awaits between).
|
|
1449
|
-
*
|
|
1450
|
-
* @param token The injection token
|
|
1451
|
-
* @param args Optional arguments
|
|
1452
|
-
* @param contextContainer The container for FactoryContext
|
|
1453
|
-
* @param storage The storage strategy to use
|
|
1454
|
-
* @param scopedContainer Optional scoped container for request-scoped services
|
|
1455
|
-
*/
|
|
1456
|
-
private resolveWithStorage;
|
|
1457
|
-
/**
|
|
1458
|
-
* Handles storage error states (destroying, error, etc.).
|
|
1459
|
-
* Returns a result if handled, null if should proceed with creation.
|
|
1460
|
-
*/
|
|
1461
|
-
private handleStorageError;
|
|
1462
|
-
/**
|
|
1463
|
-
* Creates a new instance and stores it using the provided storage strategy.
|
|
1464
|
-
* This unified method replaces instantiateServiceFromRegistry and createRequestScopedInstance.
|
|
1465
|
-
*
|
|
1466
|
-
* For transient services, the instance is created but not stored (no caching).
|
|
1467
|
-
*/
|
|
1468
|
-
private createAndStoreInstance;
|
|
1469
|
-
/**
|
|
1470
|
-
* Creates a transient instance without storage or locking.
|
|
1471
|
-
* Each call creates a new instance.
|
|
1472
|
-
*/
|
|
1473
|
-
private createTransientInstance;
|
|
1474
|
-
/**
|
|
1475
|
-
* Gets a synchronous instance (for sync operations).
|
|
1476
|
-
*/
|
|
1477
|
-
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;
|
|
1478
|
-
/**
|
|
1479
|
-
* Internal method to resolve token args and create instance name.
|
|
1480
|
-
* Handles factory token resolution and validation.
|
|
1481
|
-
*/
|
|
1482
|
-
private resolveTokenAndPrepareInstanceName;
|
|
1483
|
-
/**
|
|
1484
|
-
* Waits for an instance holder to be ready and returns the appropriate result.
|
|
1485
|
-
* Uses the shared utility from BaseHolderManager.
|
|
1486
|
-
* Passes the current resolution context for circular dependency detection.
|
|
1487
|
-
*/
|
|
1488
|
-
private waitForInstanceReady;
|
|
1489
|
-
/**
|
|
1490
|
-
* Handles the result of service instantiation.
|
|
1491
|
-
*/
|
|
1492
|
-
private handleInstantiationResult;
|
|
1493
|
-
/**
|
|
1494
|
-
* Handles successful service instantiation.
|
|
1495
|
-
*/
|
|
1496
|
-
private handleInstantiationSuccess;
|
|
1497
|
-
/**
|
|
1498
|
-
* Handles service instantiation errors.
|
|
1499
|
-
*/
|
|
1500
|
-
private handleInstantiationError;
|
|
1501
|
-
/**
|
|
1502
|
-
* Creates a factory context for dependency injection during service instantiation.
|
|
1503
|
-
*/
|
|
1504
|
-
private createFactoryContext;
|
|
1505
|
-
}
|
|
1506
|
-
//#endregion
|
|
1507
|
-
export { type AnyInjectableType, BaseHolderManager, BoundInjectionToken, CircularDetector, type ClassType, type ClassTypeWithArgument, type ClassTypeWithInstance, type ClassTypeWithInstanceAndArgument, type ClassTypeWithInstanceAndOptionalArgument, type ClassTypeWithOptionalArgument, type ClassTypeWithoutArguments, Container, DIError, DIErrorCode, DefaultRequestContext, EventEmitter, Factorable, FactorableWithArgs, Factory, type FactoryContext, FactoryInjectionToken, FactoryOptions, type FactoryRecord, type HolderGetResult, HolderManager, type HolderReadyResult, IContainer, type IHolderStorage, InjectRequest, InjectState, Injectable, InjectableOptions, InjectableScope, InjectableTokenMeta, InjectableType, InjectionToken, type InjectionTokenSchemaType, type InjectionTokenType, Injectors, type InstanceDestroyListener, type InstanceEffect, type InstanceHolder, type InstanceHolderCreated, type InstanceHolderCreating, type InstanceHolderDestroying, type InstanceHolderError, InstanceResolver, InstanceStatus, Instantiator, Invalidator, IsUnion, Join, LifecycleEventBus, OnServiceDestroy, OnServiceInit, PopUnion, Registry, type RequestContext, type RequestContextHolder, RequestStorage, type ResolutionContextData, ScopedContainer, ServiceLocator, SingletonStorage, TokenProcessor, UnionToArray, UnionToIntersection, UnionToOvlds, asyncInject, createRequestContext, defaultInjectors, getCurrentResolutionContext, getInjectableToken, getInjectors, globalRegistry, inject, optional, provideFactoryContext, withResolutionContext, withoutResolutionContext, wrapSyncInit };
|
|
1508
|
-
//# sourceMappingURL=index.d.mts.map
|
|
1
|
+
import { AnyInjectableType, BaseInjectionTokenSchemaType, BoundInjectionToken, ClassType, ClassTypeWithArgument, ClassTypeWithInstance, ClassTypeWithInstanceAndArgument, ClassTypeWithInstanceAndOptionalArgument, ClassTypeWithOptionalArgument, ClassTypeWithoutArguments, FactoryInjectionToken, InjectionToken, InjectionTokenSchemaType, InjectionTokenType, OptionalInjectionTokenSchemaType } from "./token/injection-token.mjs";
|
|
2
|
+
import { InjectRequest, InjectState, IsUnion, Join, PopUnion, UnionToArray, UnionToIntersection, UnionToOvlds } from "./utils/types.mjs";
|
|
3
|
+
import { IContainer } from "./interfaces/container.interface.mjs";
|
|
4
|
+
import { InjectableScope } from "./enums/injectable-scope.enum.mjs";
|
|
5
|
+
import { InjectableType } from "./enums/injectable-type.enum.mjs";
|
|
6
|
+
import { ServiceInitializationContext } from "./internal/context/service-initialization-context.mjs";
|
|
7
|
+
import { Injectors, getInjectors } from "./utils/get-injectors.mjs";
|
|
8
|
+
import { asyncInject, defaultInjectors, inject, optional, provideFactoryContext, wrapSyncInit } from "./utils/default-injectors.mjs";
|
|
9
|
+
import { getInjectableToken } from "./utils/get-injectable-token.mjs";
|
|
10
|
+
import { FactoryContext } from "./internal/context/factory-context.mjs";
|
|
11
|
+
import { Factorable, FactorableWithArgs } from "./interfaces/factory.interface.mjs";
|
|
12
|
+
import { FactoryRecord, Registry, globalRegistry } from "./token/registry.mjs";
|
|
13
|
+
import { NameResolver } from "./internal/core/name-resolver.mjs";
|
|
14
|
+
import { DIError, DIErrorCode } from "./errors/di-error.mjs";
|
|
15
|
+
import { InstanceDestroyListener, InstanceHolder, InstanceHolderCreated, InstanceHolderCreating, InstanceHolderDestroying, InstanceHolderError, InstanceStatus } from "./internal/holder/instance-holder.mjs";
|
|
16
|
+
import { HolderGetResult, IHolderStorage } from "./internal/holder/holder-storage.interface.mjs";
|
|
17
|
+
import { LifecycleEventBus } from "./internal/lifecycle/lifecycle-event-bus.mjs";
|
|
18
|
+
import { ClearAllOptions, InvalidationOptions, ServiceInvalidator } from "./internal/core/service-invalidator.mjs";
|
|
19
|
+
import { TokenResolver } from "./internal/core/token-resolver.mjs";
|
|
20
|
+
import { UnifiedStorage } from "./internal/holder/unified-storage.mjs";
|
|
21
|
+
import { ScopedContainer } from "./container/scoped-container.mjs";
|
|
22
|
+
import { ScopeTracker } from "./internal/core/scope-tracker.mjs";
|
|
23
|
+
import { ServiceInitializer } from "./internal/core/service-initializer.mjs";
|
|
24
|
+
import { InstanceResolver } from "./internal/core/instance-resolver.mjs";
|
|
25
|
+
import { Container } from "./container/container.mjs";
|
|
26
|
+
import { OnServiceDestroy } from "./interfaces/on-service-destroy.interface.mjs";
|
|
27
|
+
import { OnServiceInit } from "./interfaces/on-service-init.interface.mjs";
|
|
28
|
+
import { Factory, FactoryOptions } from "./decorators/factory.decorator.mjs";
|
|
29
|
+
import { Injectable, InjectableOptions } from "./decorators/injectable.decorator.mjs";
|
|
30
|
+
import { IAsyncLocalStorage } from "./internal/context/async-local-storage.types.mjs";
|
|
31
|
+
import { createAsyncLocalStorage, isUsingNativeAsyncLocalStorage } from "./internal/context/async-local-storage.mjs";
|
|
32
|
+
import { ResolutionContextData, getCurrentResolutionContext, withResolutionContext, withoutResolutionContext } from "./internal/context/resolution-context.mjs";
|
|
33
|
+
import { CircularDetector } from "./internal/lifecycle/circular-detector.mjs";
|
|
34
|
+
import { StubFactoryClass } from "./internal/stub-factory-class.mjs";
|
|
35
|
+
import { InjectableTokenMeta } from "./symbols/injectable-token.mjs";
|
|
36
|
+
import { EventEmitter, EventsArgs, EventsConfig, EventsNames } from "./event-emitter.mjs";
|
|
37
|
+
export { AnyInjectableType, BaseInjectionTokenSchemaType, BoundInjectionToken, CircularDetector, ClassType, ClassTypeWithArgument, ClassTypeWithInstance, ClassTypeWithInstanceAndArgument, ClassTypeWithInstanceAndOptionalArgument, ClassTypeWithOptionalArgument, ClassTypeWithoutArguments, ClearAllOptions, Container, DIError, DIErrorCode, EventEmitter, EventsArgs, EventsConfig, EventsNames, Factorable, FactorableWithArgs, Factory, FactoryContext, FactoryInjectionToken, FactoryOptions, FactoryRecord, HolderGetResult, IAsyncLocalStorage, IContainer, IHolderStorage, InjectRequest, InjectState, Injectable, InjectableOptions, InjectableScope, InjectableTokenMeta, InjectableType, InjectionToken, InjectionTokenSchemaType, InjectionTokenType, Injectors, InstanceDestroyListener, InstanceHolder, InstanceHolderCreated, InstanceHolderCreating, InstanceHolderDestroying, InstanceHolderError, InstanceResolver, InstanceStatus, InvalidationOptions, IsUnion, Join, LifecycleEventBus, NameResolver, OnServiceDestroy, OnServiceInit, OptionalInjectionTokenSchemaType, PopUnion, Registry, ResolutionContextData, ScopeTracker, ScopedContainer, ServiceInitializationContext, ServiceInitializer, ServiceInvalidator, StubFactoryClass, TokenResolver, UnifiedStorage, UnionToArray, UnionToIntersection, UnionToOvlds, asyncInject, createAsyncLocalStorage, defaultInjectors, getCurrentResolutionContext, getInjectableToken, getInjectors, globalRegistry, inject, isUsingNativeAsyncLocalStorage, optional, provideFactoryContext, withResolutionContext, withoutResolutionContext, wrapSyncInit };
|