@codefast/di 0.3.16-canary.0 → 0.3.16-canary.2
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 +12 -0
- package/README.md +8 -5
- package/dist/binding-select.d.mts +2 -2
- package/dist/binding-select.mjs +5 -5
- package/dist/binding.d.mts +12 -12
- package/dist/binding.mjs +8 -8
- package/dist/constraints.d.mts +25 -9
- package/dist/constraints.mjs +47 -19
- package/dist/constructor-type.d.mts +2 -2
- package/dist/container.d.mts +6 -6
- package/dist/container.mjs +202 -121
- package/dist/decorators/inject.d.mts +4 -4
- package/dist/decorators/inject.mjs +21 -19
- package/dist/decorators/injectable.d.mts +1 -1
- package/dist/decorators/injectable.mjs +18 -14
- package/dist/decorators/lifecycle-decorators.mjs +3 -0
- package/dist/dependency-graph.d.mts +2 -2
- package/dist/dependency-graph.mjs +13 -13
- package/dist/environment.d.mts +17 -17
- package/dist/environment.mjs +21 -21
- package/dist/errors.d.mts +18 -8
- package/dist/errors.mjs +17 -1
- package/dist/graph-adapters/reactflow.d.mts +2 -2
- package/dist/index.d.mts +6 -5
- package/dist/index.mjs +5 -4
- package/dist/inspector.d.mts +2 -3
- package/dist/inspector.mjs +18 -16
- package/dist/lifecycle.d.mts +5 -6
- package/dist/lifecycle.mjs +45 -52
- package/dist/metadata/metadata-keys.d.mts +24 -1
- package/dist/metadata/metadata-keys.mjs +14 -1
- package/dist/metadata/metadata-types.d.mts +5 -5
- package/dist/metadata/symbol-metadata-reader.mjs +31 -24
- package/dist/module.d.mts +2 -2
- package/dist/module.mjs +2 -2
- package/dist/registry.d.mts +6 -6
- package/dist/registry.mjs +55 -62
- package/dist/resolve-options.d.mts +5 -5
- package/dist/resolve-options.mjs +8 -8
- package/dist/resolver.d.mts +22 -10
- package/dist/resolver.mjs +206 -185
- package/dist/token.d.mts +1 -1
- package/dist/token.mjs +4 -4
- package/dist/types.d.mts +12 -8
- package/package.json +15 -8
package/dist/registry.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bindingSlotEquals, bindingSlotToString } from "./binding.mjs";
|
|
2
2
|
//#region src/registry.ts
|
|
3
3
|
/**
|
|
4
4
|
* @since 0.3.16-canary.0
|
|
@@ -12,35 +12,35 @@ var BindingRegistry = class {
|
|
|
12
12
|
/** Add or replace binding using slot-aware last-wins. */
|
|
13
13
|
add(binding) {
|
|
14
14
|
const key = binding.token;
|
|
15
|
-
let
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
this._bindings.set(key,
|
|
15
|
+
let bindingsForToken = this._bindings.get(key);
|
|
16
|
+
if (bindingsForToken === void 0) {
|
|
17
|
+
bindingsForToken = [];
|
|
18
|
+
this._bindings.set(key, bindingsForToken);
|
|
19
19
|
}
|
|
20
20
|
if (!this._isPurePredicateBinding(binding)) {
|
|
21
|
-
const existingIndex =
|
|
21
|
+
const existingIndex = bindingsForToken.findIndex((candidate) => !this._isPurePredicateBinding(candidate) && bindingSlotEquals(candidate.slot, binding.slot));
|
|
22
22
|
if (existingIndex !== -1) {
|
|
23
|
-
const
|
|
24
|
-
this._byId.delete(
|
|
25
|
-
|
|
23
|
+
const replacedBinding = bindingsForToken[existingIndex];
|
|
24
|
+
this._byId.delete(replacedBinding.id);
|
|
25
|
+
bindingsForToken.splice(existingIndex, 1);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
bindingsForToken.push(binding);
|
|
29
29
|
this._byId.set(binding.id, binding);
|
|
30
30
|
this._indexSimpleNamedBinding(key, binding);
|
|
31
31
|
this._indexSimpleTaggedBinding(key, binding);
|
|
32
32
|
this._refreshFastDefaultForToken(key);
|
|
33
33
|
}
|
|
34
34
|
/** Remove all bindings for a token. Returns removed bindings. */
|
|
35
|
-
removeByToken(
|
|
36
|
-
const key =
|
|
37
|
-
const
|
|
35
|
+
removeByToken(token) {
|
|
36
|
+
const key = token;
|
|
37
|
+
const bindingsForToken = this._bindings.get(key) ?? [];
|
|
38
38
|
this._bindings.delete(key);
|
|
39
39
|
this._simpleNamed.delete(key);
|
|
40
40
|
this._simpleTagged.delete(key);
|
|
41
41
|
this._fastDefault.delete(key);
|
|
42
|
-
for (const
|
|
43
|
-
return
|
|
42
|
+
for (const binding of bindingsForToken) this._byId.delete(binding.id);
|
|
43
|
+
return bindingsForToken;
|
|
44
44
|
}
|
|
45
45
|
/** Remove a specific binding by ID. Returns the removed binding or undefined. */
|
|
46
46
|
removeById(id) {
|
|
@@ -48,13 +48,13 @@ var BindingRegistry = class {
|
|
|
48
48
|
if (binding === void 0) return;
|
|
49
49
|
this._byId.delete(id);
|
|
50
50
|
const key = binding.token;
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
51
|
+
const bindingsForToken = this._bindings.get(key);
|
|
52
|
+
if (bindingsForToken !== void 0) {
|
|
53
|
+
const bindingIndex = bindingsForToken.findIndex((candidate) => candidate.id === id);
|
|
54
|
+
if (bindingIndex !== -1) bindingsForToken.splice(bindingIndex, 1);
|
|
55
55
|
this._deindexSimpleNamedBinding(key, binding);
|
|
56
56
|
this._deindexSimpleTaggedBinding(key, binding);
|
|
57
|
-
if (
|
|
57
|
+
if (bindingsForToken.length === 0) {
|
|
58
58
|
this._bindings.delete(key);
|
|
59
59
|
this._simpleNamed.delete(key);
|
|
60
60
|
this._simpleTagged.delete(key);
|
|
@@ -64,24 +64,24 @@ var BindingRegistry = class {
|
|
|
64
64
|
return binding;
|
|
65
65
|
}
|
|
66
66
|
/** Get all bindings for a token. */
|
|
67
|
-
getAll(
|
|
68
|
-
return this._bindings.get(
|
|
67
|
+
getAll(token) {
|
|
68
|
+
return this._bindings.get(token) ?? [];
|
|
69
69
|
}
|
|
70
70
|
/** Get binding by ID. */
|
|
71
71
|
getById(id) {
|
|
72
72
|
return this._byId.get(id);
|
|
73
73
|
}
|
|
74
74
|
/** Check if any binding exists for token. */
|
|
75
|
-
has(
|
|
76
|
-
const key =
|
|
75
|
+
has(token) {
|
|
76
|
+
const key = token;
|
|
77
77
|
const list = this._bindings.get(key);
|
|
78
78
|
return list !== void 0 && list.length > 0;
|
|
79
79
|
}
|
|
80
80
|
/** All bindings in the registry. */
|
|
81
81
|
allBindings() {
|
|
82
|
-
const
|
|
83
|
-
for (const
|
|
84
|
-
return
|
|
82
|
+
const allBindings = [];
|
|
83
|
+
for (const bindingsForToken of this._bindings.values()) allBindings.push(...bindingsForToken);
|
|
84
|
+
return allBindings;
|
|
85
85
|
}
|
|
86
86
|
/** Remove all bindings. Returns all removed. */
|
|
87
87
|
clear() {
|
|
@@ -103,24 +103,17 @@ var BindingRegistry = class {
|
|
|
103
103
|
return this._fastDefault.get(token);
|
|
104
104
|
}
|
|
105
105
|
/** Summarize available slot strings for a token (for error messages). */
|
|
106
|
-
availableSlotStrings(
|
|
107
|
-
return (this._bindings.get(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const parts = [];
|
|
111
|
-
if (s.name !== void 0) parts.push(`name:${s.name}`);
|
|
112
|
-
for (const [k, v] of s.tags) parts.push(`tag:${k}=${String(v)}`);
|
|
113
|
-
return parts.join(",");
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
_indexSimpleTaggedBinding(tokenKeyValue, binding) {
|
|
106
|
+
availableSlotStrings(token) {
|
|
107
|
+
return (this._bindings.get(token) ?? []).map((binding) => bindingSlotToString(binding.slot));
|
|
108
|
+
}
|
|
109
|
+
_indexSimpleTaggedBinding(tokenKey, binding) {
|
|
117
110
|
const slot = binding.slot;
|
|
118
111
|
if (slot.name !== void 0 || slot.tags.length !== 1 || binding.predicate !== void 0) return;
|
|
119
112
|
const [tagKey, tagValue] = slot.tags[0];
|
|
120
|
-
let byTagKey = this._simpleTagged.get(
|
|
113
|
+
let byTagKey = this._simpleTagged.get(tokenKey);
|
|
121
114
|
if (byTagKey === void 0) {
|
|
122
115
|
byTagKey = /* @__PURE__ */ new Map();
|
|
123
|
-
this._simpleTagged.set(
|
|
116
|
+
this._simpleTagged.set(tokenKey, byTagKey);
|
|
124
117
|
}
|
|
125
118
|
let byTagValue = byTagKey.get(tagKey);
|
|
126
119
|
if (byTagValue === void 0) {
|
|
@@ -129,11 +122,11 @@ var BindingRegistry = class {
|
|
|
129
122
|
}
|
|
130
123
|
byTagValue.set(tagValue, binding);
|
|
131
124
|
}
|
|
132
|
-
_deindexSimpleTaggedBinding(
|
|
125
|
+
_deindexSimpleTaggedBinding(tokenKey, binding) {
|
|
133
126
|
const slot = binding.slot;
|
|
134
127
|
if (slot.name !== void 0 || slot.tags.length !== 1 || binding.predicate !== void 0) return;
|
|
135
128
|
const [tagKey, tagValue] = slot.tags[0];
|
|
136
|
-
const byTagKey = this._simpleTagged.get(
|
|
129
|
+
const byTagKey = this._simpleTagged.get(tokenKey);
|
|
137
130
|
if (byTagKey === void 0) return;
|
|
138
131
|
const byTagValue = byTagKey.get(tagKey);
|
|
139
132
|
if (byTagValue === void 0) return;
|
|
@@ -141,7 +134,7 @@ var BindingRegistry = class {
|
|
|
141
134
|
byTagValue.delete(tagValue);
|
|
142
135
|
if (byTagValue.size === 0) {
|
|
143
136
|
byTagKey.delete(tagKey);
|
|
144
|
-
if (byTagKey.size === 0) this._simpleTagged.delete(
|
|
137
|
+
if (byTagKey.size === 0) this._simpleTagged.delete(tokenKey);
|
|
145
138
|
}
|
|
146
139
|
}
|
|
147
140
|
}
|
|
@@ -151,38 +144,38 @@ var BindingRegistry = class {
|
|
|
151
144
|
const hasConstraint = slot.name !== void 0 || slot.tags.length > 0;
|
|
152
145
|
return hasPredicate && !hasConstraint;
|
|
153
146
|
}
|
|
154
|
-
_indexSimpleNamedBinding(
|
|
147
|
+
_indexSimpleNamedBinding(tokenKey, binding) {
|
|
155
148
|
const slot = binding.slot;
|
|
156
149
|
if (slot.name === void 0 || slot.tags.length > 0) return;
|
|
157
|
-
let
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
this._simpleNamed.set(
|
|
150
|
+
let bindingsByName = this._simpleNamed.get(tokenKey);
|
|
151
|
+
if (bindingsByName === void 0) {
|
|
152
|
+
bindingsByName = /* @__PURE__ */ new Map();
|
|
153
|
+
this._simpleNamed.set(tokenKey, bindingsByName);
|
|
161
154
|
}
|
|
162
|
-
|
|
155
|
+
bindingsByName.set(slot.name, binding);
|
|
163
156
|
}
|
|
164
|
-
_deindexSimpleNamedBinding(
|
|
157
|
+
_deindexSimpleNamedBinding(tokenKey, binding) {
|
|
165
158
|
const slot = binding.slot;
|
|
166
159
|
if (slot.name === void 0 || slot.tags.length > 0) return;
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
if (
|
|
170
|
-
|
|
171
|
-
if (
|
|
160
|
+
const bindingsByName = this._simpleNamed.get(tokenKey);
|
|
161
|
+
if (bindingsByName === void 0) return;
|
|
162
|
+
if (bindingsByName.get(slot.name)?.id === binding.id) {
|
|
163
|
+
bindingsByName.delete(slot.name);
|
|
164
|
+
if (bindingsByName.size === 0) this._simpleNamed.delete(tokenKey);
|
|
172
165
|
}
|
|
173
166
|
}
|
|
174
|
-
_refreshFastDefaultForToken(
|
|
175
|
-
const
|
|
176
|
-
if (
|
|
177
|
-
this._fastDefault.delete(
|
|
167
|
+
_refreshFastDefaultForToken(tokenKey) {
|
|
168
|
+
const bindingsForToken = this._bindings.get(tokenKey);
|
|
169
|
+
if (bindingsForToken === void 0 || bindingsForToken.length !== 1) {
|
|
170
|
+
this._fastDefault.delete(tokenKey);
|
|
178
171
|
return;
|
|
179
172
|
}
|
|
180
|
-
const onlyBinding =
|
|
173
|
+
const onlyBinding = bindingsForToken[0];
|
|
181
174
|
if (!(onlyBinding.slot.name === void 0 && onlyBinding.slot.tags.length === 0) || onlyBinding.predicate !== void 0) {
|
|
182
|
-
this._fastDefault.delete(
|
|
175
|
+
this._fastDefault.delete(tokenKey);
|
|
183
176
|
return;
|
|
184
177
|
}
|
|
185
|
-
this._fastDefault.set(
|
|
178
|
+
this._fastDefault.set(tokenKey, onlyBinding);
|
|
186
179
|
}
|
|
187
180
|
};
|
|
188
181
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ResolveOptions } from "./types.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { BindingSlot } from "./binding.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/resolve-options.d.ts
|
|
5
5
|
/**
|
|
@@ -8,15 +8,15 @@ import { SlotKey } from "./binding.mjs";
|
|
|
8
8
|
*
|
|
9
9
|
* @since 0.3.16-canary.0
|
|
10
10
|
*/
|
|
11
|
-
declare function
|
|
11
|
+
declare function injectionSlotToResolveOptions(injectionSlot: {
|
|
12
12
|
readonly name?: string;
|
|
13
13
|
readonly tags?: ReadonlyArray<readonly [string, unknown]>;
|
|
14
14
|
}): ResolveOptions | undefined;
|
|
15
15
|
/**
|
|
16
|
-
* Hint from a binding {@link
|
|
16
|
+
* Hint from a binding {@link BindingSlot} (tags may be empty; omits when nothing to match).
|
|
17
17
|
*
|
|
18
18
|
* @since 0.3.16-canary.0
|
|
19
19
|
*/
|
|
20
|
-
declare function
|
|
20
|
+
declare function bindingSlotToResolveOptions(bindingSlot: BindingSlot): ResolveOptions | undefined;
|
|
21
21
|
//#endregion
|
|
22
|
-
export {
|
|
22
|
+
export { bindingSlotToResolveOptions, injectionSlotToResolveOptions };
|
package/dist/resolve-options.mjs
CHANGED
|
@@ -5,22 +5,22 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @since 0.3.16-canary.0
|
|
7
7
|
*/
|
|
8
|
-
function
|
|
8
|
+
function injectionSlotToResolveOptions(injectionSlot) {
|
|
9
9
|
const options = {};
|
|
10
|
-
if (
|
|
11
|
-
if (
|
|
10
|
+
if (injectionSlot.name !== void 0) options.name = injectionSlot.name;
|
|
11
|
+
if (injectionSlot.tags !== void 0) options.tags = injectionSlot.tags;
|
|
12
12
|
return options.name !== void 0 || options.tags !== void 0 ? options : void 0;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Hint from a binding {@link
|
|
15
|
+
* Hint from a binding {@link BindingSlot} (tags may be empty; omits when nothing to match).
|
|
16
16
|
*
|
|
17
17
|
* @since 0.3.16-canary.0
|
|
18
18
|
*/
|
|
19
|
-
function
|
|
19
|
+
function bindingSlotToResolveOptions(bindingSlot) {
|
|
20
20
|
const options = {};
|
|
21
|
-
if (
|
|
22
|
-
if (
|
|
21
|
+
if (bindingSlot.name !== void 0) options.name = bindingSlot.name;
|
|
22
|
+
if (bindingSlot.tags.length > 0) options.tags = bindingSlot.tags;
|
|
23
23
|
return options.name !== void 0 || options.tags !== void 0 ? options : void 0;
|
|
24
24
|
}
|
|
25
25
|
//#endregion
|
|
26
|
-
export {
|
|
26
|
+
export { bindingSlotToResolveOptions, injectionSlotToResolveOptions };
|
package/dist/resolver.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Constructor } from "./constructor-type.mjs";
|
|
2
2
|
import { Token } from "./token.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { ResolutionFrame, ResolveOptions } from "./types.mjs";
|
|
4
|
+
import { Binding } from "./binding.mjs";
|
|
4
5
|
import { BindingRegistry } from "./registry.mjs";
|
|
5
6
|
import { ScopeManager } from "./scope.mjs";
|
|
6
7
|
import { MetadataReader } from "./metadata/metadata-types.mjs";
|
|
@@ -35,22 +36,33 @@ declare class DependencyResolver {
|
|
|
35
36
|
private _activationCacheVersion;
|
|
36
37
|
constructor(_registry: BindingRegistry, _scope: ScopeManager, _lifecycle: LifecycleManager, _metadataReader: MetadataReader, _container: Container, _parent: DependencyResolver | undefined);
|
|
37
38
|
private _findBinding;
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Binding lookup aligned with `resolve` — used by `Container.validate` without instantiating.
|
|
41
|
+
*/
|
|
42
|
+
peekBindingForValidate(token: Token<unknown> | Constructor, hint: ResolveOptions | undefined): {
|
|
43
|
+
binding: Binding;
|
|
44
|
+
owner: DependencyResolver;
|
|
45
|
+
} | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Mirrors {@link DependencyResolver.resolveAll} candidate selection only (no instantiation).
|
|
48
|
+
*/
|
|
49
|
+
peekCandidateBindingsForValidate(token: Token<unknown> | Constructor, hint: ResolveOptions | undefined): Array<Binding>;
|
|
50
|
+
resolveFromContext<const Value>(token: Token<Value> | Constructor<Value>, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Value;
|
|
51
|
+
resolve<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Value;
|
|
40
52
|
private _resolveBinding;
|
|
41
53
|
private _instantiateSync;
|
|
42
54
|
private _resolveClassDeps;
|
|
43
55
|
private _resolveDescriptorDeps;
|
|
44
|
-
resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: string
|
|
45
|
-
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: string
|
|
46
|
-
resolveAsyncFromContext<const Value>(token: Token<Value> | Constructor<Value>, resolutionPath: string
|
|
47
|
-
resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: string
|
|
56
|
+
resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Value | undefined;
|
|
57
|
+
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Array<Value>;
|
|
58
|
+
resolveAsyncFromContext<const Value>(token: Token<Value> | Constructor<Value>, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value>;
|
|
59
|
+
resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value>;
|
|
48
60
|
private _resolveBindingAsync;
|
|
49
61
|
private _instantiateAsync;
|
|
50
62
|
private _resolveClassDepsAsync;
|
|
51
63
|
private _resolveDescriptorDepsAsync;
|
|
52
|
-
resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: string
|
|
53
|
-
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: string
|
|
64
|
+
resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value | undefined>;
|
|
65
|
+
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Array<Value>>;
|
|
54
66
|
private _getAllBindingsFromChain;
|
|
55
67
|
private _getSimpleNamedBindingsFromChain;
|
|
56
68
|
private _getAvailableSlots;
|
|
@@ -67,7 +79,7 @@ declare class DependencyResolver {
|
|
|
67
79
|
private _resolveTransientDynamicAsyncSlow;
|
|
68
80
|
private _resolveCandidateSync;
|
|
69
81
|
private _resolveCandidateAsync;
|
|
70
|
-
private
|
|
82
|
+
private _getResolutionFrame;
|
|
71
83
|
private _needsActivation;
|
|
72
84
|
private _refreshClassPostConstructCache;
|
|
73
85
|
private _requiresResolutionContext;
|