@fluojs/di 1.1.0 → 3.0.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/README.ko.md +129 -26
- package/README.md +129 -26
- package/dist/container.d.ts +79 -17
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js +564 -197
- package/dist/errors.d.ts +2 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +3 -2
- package/dist/internal.d.ts +18 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +26 -0
- package/dist/multi-contribution-registry.d.ts +26 -0
- package/dist/multi-contribution-registry.d.ts.map +1 -0
- package/dist/multi-contribution-registry.js +29 -0
- package/dist/provider-normalization.d.ts +17 -0
- package/dist/provider-normalization.d.ts.map +1 -0
- package/dist/provider-normalization.js +216 -0
- package/dist/types.d.ts +10 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -4
- package/package.json +9 -5
package/dist/container.d.ts
CHANGED
|
@@ -1,34 +1,60 @@
|
|
|
1
1
|
import { type Token } from '@fluojs/core';
|
|
2
2
|
import type { NormalizedProvider, Provider } from './types.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Factory provider resolution mode recorded after a factory returns either synchronously or through a promise.
|
|
5
|
+
*/
|
|
6
|
+
export type FactoryResolutionKind = 'async' | 'sync';
|
|
7
|
+
/**
|
|
8
|
+
* Controlled cache adoption seam for framework-owned testing and tooling that
|
|
9
|
+
* need synchronous helpers to preserve container-owned singleton disposal.
|
|
10
|
+
*/
|
|
11
|
+
export interface ContainerResolutionCacheOwner {
|
|
12
|
+
readonly deleteMultiSingleton: (provider: NormalizedProvider) => void;
|
|
13
|
+
readonly deleteSingleton: (token: Token) => void;
|
|
14
|
+
readonly recordFactoryResolution: (provider: NormalizedProvider, kind: FactoryResolutionKind) => void;
|
|
15
|
+
readonly setMultiSingleton: (provider: NormalizedProvider, promise: Promise<unknown>) => void;
|
|
16
|
+
readonly setSingleton: (token: Token, promise: Promise<unknown>) => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Read-only factory resolution diagnostics recorded by container-owned factory
|
|
20
|
+
* instantiation paths.
|
|
21
|
+
*/
|
|
22
|
+
export interface ContainerFactoryResolutionState {
|
|
23
|
+
readonly get: (provider: NormalizedProvider) => FactoryResolutionKind | undefined;
|
|
24
|
+
readonly has: (provider: NormalizedProvider) => boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Public read-only seam for framework-owned testing and tooling that need to
|
|
5
28
|
* inspect a container's resolved provider graph without depending on private
|
|
6
29
|
* field names or structural casts.
|
|
7
30
|
*/
|
|
8
31
|
export interface ContainerResolutionState {
|
|
32
|
+
readonly cacheOwner: ContainerResolutionCacheOwner;
|
|
33
|
+
readonly factoryResolutionKinds: ContainerFactoryResolutionState;
|
|
9
34
|
readonly parent?: ContainerResolutionState;
|
|
10
|
-
readonly registrations:
|
|
11
|
-
readonly multiRegistrations:
|
|
12
|
-
readonly multiSingletonCache:
|
|
35
|
+
readonly registrations: ReadonlyMap<Token, NormalizedProvider>;
|
|
36
|
+
readonly multiRegistrations: ReadonlyMap<Token, readonly NormalizedProvider[]>;
|
|
37
|
+
readonly multiSingletonCache: ReadonlyMap<NormalizedProvider, Promise<unknown>>;
|
|
13
38
|
readonly requestScopeEnabled: boolean;
|
|
14
|
-
readonly singletonCache:
|
|
39
|
+
readonly singletonCache: ReadonlyMap<Token, Promise<unknown>>;
|
|
15
40
|
}
|
|
16
41
|
/**
|
|
17
42
|
* Scope-aware dependency injection container for Fluo providers.
|
|
18
43
|
*/
|
|
19
44
|
export declare class Container {
|
|
20
|
-
private
|
|
21
|
-
private readonly requestScopeEnabled;
|
|
45
|
+
#private;
|
|
22
46
|
private readonly registrations;
|
|
23
47
|
private readonly multiRegistrations;
|
|
24
48
|
private readonly multiOverriddenTokens;
|
|
25
49
|
private requestCache;
|
|
26
50
|
private multiRequestCache;
|
|
27
51
|
private readonly multiSingletonCache;
|
|
52
|
+
private readonly materializedCachePromises;
|
|
53
|
+
private readonly pendingDisposables;
|
|
28
54
|
private readonly staleDisposalTasks;
|
|
29
|
-
private readonly staleDisposalErrors;
|
|
30
55
|
private readonly singletonCache;
|
|
31
56
|
private readonly forwardRefTokenCache;
|
|
57
|
+
private readonly factoryResolutionKinds;
|
|
32
58
|
private readonly providerLookupPlanCache;
|
|
33
59
|
private readonly multiProviderPlanCache;
|
|
34
60
|
private readonly requestScopeVerdictPlanCache;
|
|
@@ -36,9 +62,20 @@ export declare class Container {
|
|
|
36
62
|
private childScopes;
|
|
37
63
|
private disposePromise;
|
|
38
64
|
private disposed;
|
|
39
|
-
private
|
|
65
|
+
private trackedByParent;
|
|
40
66
|
private graphRevision;
|
|
41
|
-
|
|
67
|
+
private readonly parent;
|
|
68
|
+
private readonly requestScopeEnabled;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a root container that owns its own singleton cache.
|
|
71
|
+
*
|
|
72
|
+
* Child request scopes are package-owned and must be created with
|
|
73
|
+
* {@link Container.createRequestScope}; caller-supplied parent, request-scope,
|
|
74
|
+
* or singleton-cache wiring is rejected.
|
|
75
|
+
*
|
|
76
|
+
* @throws {ContainerResolutionError} When any constructor argument is supplied.
|
|
77
|
+
*/
|
|
78
|
+
constructor(...construction: never[]);
|
|
42
79
|
/**
|
|
43
80
|
* Registers providers in the current container scope.
|
|
44
81
|
*
|
|
@@ -59,10 +96,16 @@ export declare class Container {
|
|
|
59
96
|
* set — the whole set is replaced. If you need to preserve other entries, re-register them
|
|
60
97
|
* together with the replacement in one `override()` call.
|
|
61
98
|
*
|
|
99
|
+
* **Batch atomicity**: the whole batch is validated before any registration or cache is touched,
|
|
100
|
+
* so a rejected `override()` call leaves every provider, cached instance, and disposal ownership
|
|
101
|
+
* exactly as it was before the call.
|
|
102
|
+
*
|
|
62
103
|
* @param providers Provider definitions that should replace existing registrations for each token.
|
|
63
104
|
* @returns The same container instance for fluent override chains.
|
|
64
105
|
* @throws {ContainerResolutionError} When called after the container was disposed.
|
|
106
|
+
* @throws {ScopeMismatchError} When a request-scope override would introduce a new singleton token.
|
|
65
107
|
* @throws {InvalidProviderError} When a provider definition is structurally invalid.
|
|
108
|
+
* @throws {DuplicateProviderError} When one token mixes single and multi replacements or repeats a single replacement.
|
|
66
109
|
*/
|
|
67
110
|
override(...providers: Provider[]): this;
|
|
68
111
|
/**
|
|
@@ -77,12 +120,16 @@ export declare class Container {
|
|
|
77
120
|
*
|
|
78
121
|
* This method is the supported introspection seam for packages such as
|
|
79
122
|
* `@fluojs/testing`; callers should prefer ordinary `has(...)` and
|
|
80
|
-
* `resolve(...)` unless they need
|
|
81
|
-
* implementing a framework-level helper.
|
|
123
|
+
* `resolve(...)` unless they need read-only graph/cache visibility while
|
|
124
|
+
* implementing a framework-level helper. Cache adoption for synchronous
|
|
125
|
+
* helpers goes through `cacheOwner`; the returned maps are not mutable
|
|
126
|
+
* container internals.
|
|
82
127
|
*
|
|
83
|
-
* @returns
|
|
128
|
+
* @returns Read-only provider registrations and resolution caches for this container scope.
|
|
84
129
|
*/
|
|
85
130
|
inspectResolutionState(): ContainerResolutionState;
|
|
131
|
+
private createCacheOwner;
|
|
132
|
+
private createFactoryResolutionState;
|
|
86
133
|
/**
|
|
87
134
|
* Returns whether resolving a token may require a request-scope container.
|
|
88
135
|
*
|
|
@@ -108,13 +155,23 @@ export declare class Container {
|
|
|
108
155
|
* @throws {CircularDependencyError} When provider dependency resolution detects a cycle.
|
|
109
156
|
*/
|
|
110
157
|
resolve<T>(token: Token<T>): Promise<T>;
|
|
158
|
+
private resolveMultiContribution;
|
|
111
159
|
/**
|
|
112
160
|
* Disposes cached instances and nested request scopes.
|
|
113
161
|
*
|
|
162
|
+
* Concurrent callers share the active disposal attempt. After a failed attempt,
|
|
163
|
+
* a later explicit call retries only `onDestroy()` hooks that did not complete;
|
|
164
|
+
* successfully completed hooks are never repeated. Disposal remains terminal
|
|
165
|
+
* for registration, resolution, overrides, and child-scope creation. A directly
|
|
166
|
+
* disposed child owns its remaining retries after that attempt settles, while a
|
|
167
|
+
* parent-started failed attempt remains owned by the parent hierarchy.
|
|
168
|
+
*
|
|
114
169
|
* @returns A promise that settles after all cached disposable instances are torn down.
|
|
115
170
|
* @throws {Error} Propagates one or more disposal errors (`AggregateError` when multiple failures occur).
|
|
116
171
|
*/
|
|
117
172
|
dispose(): Promise<void>;
|
|
173
|
+
private disposeFromParent;
|
|
174
|
+
private disposeWithOrigin;
|
|
118
175
|
private disposeAll;
|
|
119
176
|
private isDisposedInHierarchy;
|
|
120
177
|
private hasMulti;
|
|
@@ -138,8 +195,7 @@ export declare class Container {
|
|
|
138
195
|
private resolveExistingProviderTarget;
|
|
139
196
|
private resolveScopedOrSingletonInstance;
|
|
140
197
|
private getCachedScopedOrSingletonInstance;
|
|
141
|
-
private
|
|
142
|
-
private shouldResolveMultiProviderFromRoot;
|
|
198
|
+
private cacheOwnerFor;
|
|
143
199
|
private resolveDepToken;
|
|
144
200
|
private withTokenInChain;
|
|
145
201
|
private root;
|
|
@@ -166,12 +222,18 @@ export declare class Container {
|
|
|
166
222
|
private collectDisposableInstances;
|
|
167
223
|
private disposeInstancesInReverseOrder;
|
|
168
224
|
private clearDisposalCaches;
|
|
225
|
+
private trackCacheMaterialization;
|
|
169
226
|
private currentLineageRevision;
|
|
170
227
|
private readCachedPlan;
|
|
171
228
|
private writePlanCache;
|
|
172
229
|
private advanceGraphRevision;
|
|
173
230
|
private clearResolutionPlanCaches;
|
|
174
|
-
private
|
|
231
|
+
private assertStaleDisposalsSettled;
|
|
232
|
+
private retainedStaleDisposalTasks;
|
|
233
|
+
private hasRetainedStaleDisposalTasksInSubtree;
|
|
234
|
+
private releaseNonOwnerStaleTaskObservers;
|
|
235
|
+
private releaseNonOwnerStaleTaskObserversInSubtree;
|
|
236
|
+
private retryFailedStaleDisposals;
|
|
175
237
|
private scheduleStaleDisposal;
|
|
176
238
|
private throwDisposalErrors;
|
|
177
239
|
private collectDisposalError;
|
|
@@ -180,12 +242,12 @@ export declare class Container {
|
|
|
180
242
|
private assertSingletonDependencyScopes;
|
|
181
243
|
private findRequestScopedDependency;
|
|
182
244
|
private findRequestScopedDependencyToken;
|
|
245
|
+
private findRequestScopedMultiContribution;
|
|
183
246
|
private resolveEffectiveProvider;
|
|
184
247
|
private resolveProviderDependencyToken;
|
|
185
248
|
private resolveForwardRefToken;
|
|
186
249
|
private resolveProviderDeps;
|
|
187
250
|
private invalidateAffectedCachedEntriesInHierarchy;
|
|
188
|
-
private isAncestorOf;
|
|
189
251
|
private invalidateAffectedCachedEntries;
|
|
190
252
|
private shouldInvalidateCachedToken;
|
|
191
253
|
private shouldInvalidateCachedProvider;
|
package/dist/container.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAY3E,OAAO,KAAK,EAGV,kBAAkB,EAElB,QAAQ,EACT,MAAM,YAAY,CAAC;AAGpB;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,MAAM,CAAC;AAyBrD;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,oBAAoB,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACtE,QAAQ,CAAC,eAAe,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjD,QAAQ,CAAC,uBAAuB,EAAE,CAAC,QAAQ,EAAE,kBAAkB,EAAE,IAAI,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACtG,QAAQ,CAAC,iBAAiB,EAAE,CAAC,QAAQ,EAAE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