@codefast/di 0.3.16-canary.1 → 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 +10 -0
- package/README.md +4 -4
- package/dist/binding-select.d.mts +1 -1
- package/dist/binding-select.mjs +5 -5
- package/dist/binding.d.mts +6 -6
- package/dist/binding.mjs +8 -8
- package/dist/constraints.mjs +2 -2
- package/dist/container.mjs +70 -70
- package/dist/decorators/inject.d.mts +1 -1
- package/dist/decorators/inject.mjs +8 -8
- package/dist/dependency-graph.mjs +13 -13
- package/dist/environment.d.mts +15 -15
- package/dist/environment.mjs +21 -21
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/inspector.mjs +13 -13
- package/dist/module.d.mts +1 -1
- package/dist/module.mjs +2 -2
- package/dist/registry.d.mts +4 -4
- package/dist/registry.mjs +27 -27
- package/dist/resolve-options.d.mts +5 -5
- package/dist/resolve-options.mjs +8 -8
- package/dist/resolver.d.mts +10 -10
- package/dist/resolver.mjs +152 -152
- package/dist/token.d.mts +1 -1
- package/dist/token.mjs +4 -4
- package/dist/types.d.mts +5 -5
- package/package.json +9 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @codefast/di
|
|
2
2
|
|
|
3
|
+
## 0.3.16-canary.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`1ad2cb7`](https://github.com/codefastlabs/codefast/commit/1ad2cb73a3f6f8bff2b001e9df2f2492efd89aa2) Thanks [@thevuong](https://github.com/thevuong)! - chore: align package config globs
|
|
8
|
+
|
|
9
|
+
- [`4fda78b`](https://github.com/codefastlabs/codefast/commit/4fda78b20f98646d114cfddb09e66af609a625a2) Thanks [@thevuong](https://github.com/thevuong)! - fix: support Node 26 mirror export verification
|
|
10
|
+
|
|
11
|
+
- [`1b0df2e`](https://github.com/codefastlabs/codefast/commit/1b0df2e55140c927b7f3ba39ccdcb4cba87ec7ff) Thanks [@thevuong](https://github.com/thevuong)! - refactor(di): clarify contextual names
|
|
12
|
+
|
|
3
13
|
## 0.3.16-canary.1
|
|
4
14
|
|
|
5
15
|
## 0.3.16-canary.0
|
package/README.md
CHANGED
|
@@ -181,7 +181,7 @@ Start with `container.bind(key)` and chain a strategy, then optional constraints
|
|
|
181
181
|
| `.toDynamicAsync(factory)` | Async factory `(ctx: ResolutionContext) => Promise<Value>`. |
|
|
182
182
|
| `.toResolved(factory, deps)` | Factory with a typed dependency tuple; dependencies are resolved in order. |
|
|
183
183
|
| `.toResolvedAsync(factory, deps)` | Like `toResolved`, but the factory returns a `Promise`. |
|
|
184
|
-
| `.toAlias(targetToken)` | Redirect resolution to another token; the alias follows the target’s
|
|
184
|
+
| `.toAlias(targetToken)` | Redirect resolution to another token; the alias follows the target’s resolution. |
|
|
185
185
|
|
|
186
186
|
```typescript
|
|
187
187
|
container.bind(AppConfigToken).toConstantValue({ port: 3000 });
|
|
@@ -271,7 +271,7 @@ Built-in predicates (all from `@codefast/di/constraints`):
|
|
|
271
271
|
| ----------------------------------- | -------------------------------------------------------------------------- |
|
|
272
272
|
| `whenParentIs(key)` | The direct parent binding was registered for `key`. |
|
|
273
273
|
| `whenNoParentIs(key)` | There is no parent, or the parent is not registered for `key`. |
|
|
274
|
-
| `whenAnyAncestorIs(key)` | Any ancestor on the
|
|
274
|
+
| `whenAnyAncestorIs(key)` | Any ancestor on the resolution stack was registered for `key`. |
|
|
275
275
|
| `whenNoAncestorIs(key)` | No ancestor was registered for `key`. |
|
|
276
276
|
| `whenParentNamed(name)` | The immediate parent binding’s slot name is `name`. |
|
|
277
277
|
| `whenAnyAncestorNamed(name)` | Some ancestor’s slot name is `name`. |
|
|
@@ -645,7 +645,7 @@ The root entry re-exports the full façade (`package.json` → `"."`). Subpaths
|
|
|
645
645
|
| `@codefast/di/decorators/injectable` | `injectable`, `createAutoRegisterRegistry`, `AutoRegisterRegistry` |
|
|
646
646
|
| `@codefast/di/decorators/lifecycle-decorators` | `postConstruct`, `preDestroy` |
|
|
647
647
|
| `@codefast/di/dependency-graph` | `buildDependencyGraph`, `ContainerGraphJson`, `GraphOptions`, … |
|
|
648
|
-
| `@codefast/di/environment` | `runWithContainer`, `getActiveContainer`, `DefaultResolutionContext`, `ResolverCallbacks`, `
|
|
648
|
+
| `@codefast/di/environment` | `runWithContainer`, `getActiveContainer`, `DefaultResolutionContext`, `ResolverCallbacks`, `buildResolutionFrame` |
|
|
649
649
|
| `@codefast/di/errors` | Full `DiError` hierarchy |
|
|
650
650
|
| `@codefast/di/graph-adapters/cytoscape` | `toCytoscapeGraph` |
|
|
651
651
|
| `@codefast/di/graph-adapters/dot` | `toDotGraph` |
|
|
@@ -659,7 +659,7 @@ The root entry re-exports the full façade (`package.json` → `"."`). Subpaths
|
|
|
659
659
|
| `@codefast/di/metadata/symbol-metadata-reader` | `SymbolMetadataReader`, `defaultMetadataReader` |
|
|
660
660
|
| `@codefast/di/module` | `Module`, `AsyncModule`, `SyncModule`, `isSyncModule`, builders |
|
|
661
661
|
| `@codefast/di/registry` | `BindingRegistry` |
|
|
662
|
-
| `@codefast/di/resolve-options` | `
|
|
662
|
+
| `@codefast/di/resolve-options` | `injectionSlotToResolveOptions`, `bindingSlotToResolveOptions` |
|
|
663
663
|
| `@codefast/di/resolver` | `DependencyResolver` |
|
|
664
664
|
| `@codefast/di/scope` | `ScopeManager` |
|
|
665
665
|
| `@codefast/di/token` | `token`, `Token`, `tokenName`, … |
|
|
@@ -8,7 +8,7 @@ import { Binding } from "./binding.mjs";
|
|
|
8
8
|
*
|
|
9
9
|
* @since 0.3.16-canary.0
|
|
10
10
|
*/
|
|
11
|
-
declare function selectBinding(bindings: ReadonlyArray<Binding>, hint: ResolveOptions | undefined, ctx: ConstraintContext,
|
|
11
|
+
declare function selectBinding(bindings: ReadonlyArray<Binding>, hint: ResolveOptions | undefined, ctx: ConstraintContext, tokenDisplayName: string): Binding | undefined;
|
|
12
12
|
/**
|
|
13
13
|
* Select all candidates matching hint + predicates.
|
|
14
14
|
*
|
package/dist/binding-select.mjs
CHANGED
|
@@ -6,11 +6,11 @@ import { AmbiguousBindingError } from "./errors.mjs";
|
|
|
6
6
|
*
|
|
7
7
|
* @since 0.3.16-canary.0
|
|
8
8
|
*/
|
|
9
|
-
function selectBinding(bindings, hint, ctx,
|
|
9
|
+
function selectBinding(bindings, hint, ctx, tokenDisplayName) {
|
|
10
10
|
const candidates = filterBindings(bindings, hint, ctx);
|
|
11
11
|
if (candidates.length === 0) return;
|
|
12
12
|
if (candidates.length === 1) return candidates[0];
|
|
13
|
-
throw new AmbiguousBindingError(
|
|
13
|
+
throw new AmbiguousBindingError(tokenDisplayName, candidates.map((c) => c.id));
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Select all candidates matching hint + predicates.
|
|
@@ -20,10 +20,10 @@ function selectBinding(bindings, hint, ctx, tName) {
|
|
|
20
20
|
function selectAllBindings(bindings, hint, ctx) {
|
|
21
21
|
return filterBindings(bindings, hint, ctx, "all");
|
|
22
22
|
}
|
|
23
|
-
function filterBindings(bindings, hint, ctx,
|
|
23
|
+
function filterBindings(bindings, hint, ctx, selectionMode = "single") {
|
|
24
24
|
if (hint === void 0) {
|
|
25
25
|
const resultWithoutHint = [];
|
|
26
|
-
if (
|
|
26
|
+
if (selectionMode === "all") {
|
|
27
27
|
for (const binding of bindings) if (matchesPredicate(binding, ctx)) resultWithoutHint.push(binding);
|
|
28
28
|
} else for (const binding of bindings) {
|
|
29
29
|
const slot = binding.slot;
|
|
@@ -32,7 +32,7 @@ function filterBindings(bindings, hint, ctx, mode = "single") {
|
|
|
32
32
|
return resultWithoutHint;
|
|
33
33
|
}
|
|
34
34
|
const result = [];
|
|
35
|
-
for (const binding of bindings) if ((
|
|
35
|
+
for (const binding of bindings) if ((selectionMode === "all" ? matchesSlotForResolveAll(binding, hint) : matchesSlot(binding, hint)) && matchesPredicate(binding, ctx)) result.push(binding);
|
|
36
36
|
return result;
|
|
37
37
|
}
|
|
38
38
|
function matchesSlotForResolveAll(binding, hint) {
|
package/dist/binding.d.mts
CHANGED
|
@@ -7,26 +7,26 @@ import { InjectionDescriptor } from "./decorators/inject.mjs";
|
|
|
7
7
|
/**
|
|
8
8
|
* @since 0.3.16-canary.0
|
|
9
9
|
*/
|
|
10
|
-
interface
|
|
10
|
+
interface BindingSlot {
|
|
11
11
|
readonly name: string | undefined;
|
|
12
12
|
readonly tags: ReadonlyArray<readonly [tag: string, value: unknown]>;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* @since 0.3.16-canary.0
|
|
16
16
|
*/
|
|
17
|
-
declare function
|
|
17
|
+
declare function bindingSlotEquals(left: BindingSlot, right: BindingSlot): boolean;
|
|
18
18
|
/**
|
|
19
19
|
* @since 0.3.16-canary.0
|
|
20
20
|
*/
|
|
21
|
-
declare const
|
|
21
|
+
declare const DEFAULT_BINDING_SLOT: BindingSlot;
|
|
22
22
|
/**
|
|
23
23
|
* @since 0.3.16-canary.0
|
|
24
24
|
*/
|
|
25
|
-
declare function
|
|
25
|
+
declare function bindingSlotToString(slot: BindingSlot): string;
|
|
26
26
|
interface BindingBase<Value> {
|
|
27
27
|
readonly id: BindingIdentifier;
|
|
28
28
|
readonly token: Token<Value> | Constructor<Value>;
|
|
29
|
-
readonly slot:
|
|
29
|
+
readonly slot: BindingSlot;
|
|
30
30
|
readonly predicate?: (ctx: ConstraintContext) => boolean;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -188,4 +188,4 @@ interface SingletonLifecycleBuilder<Value> {
|
|
|
188
188
|
id(): BindingIdentifier;
|
|
189
189
|
}
|
|
190
190
|
//#endregion
|
|
191
|
-
export { AliasBinding, AliasBindingBuilder, BindToBuilder, Binding, BindingBuilder, ClassBinding, ConstantBinding, ConstantBindingBuilder,
|
|
191
|
+
export { AliasBinding, AliasBindingBuilder, BindToBuilder, Binding, BindingBuilder, BindingSlot, ClassBinding, ConstantBinding, ConstantBindingBuilder, DEFAULT_BINDING_SLOT, DynamicAsyncBinding, DynamicBinding, PartialBinding, ResolvedAsyncBinding, ResolvedBinding, ScopedBindingBuilder, SingletonBindingBuilder, SingletonLifecycleBuilder, TransientBindingBuilder, bindingSlotEquals, bindingSlotToString, generateBindingId };
|
package/dist/binding.mjs
CHANGED
|
@@ -2,27 +2,27 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @since 0.3.16-canary.0
|
|
4
4
|
*/
|
|
5
|
-
function
|
|
6
|
-
if (
|
|
7
|
-
if (
|
|
8
|
-
for (const [tagKey, tagValue] of
|
|
5
|
+
function bindingSlotEquals(left, right) {
|
|
6
|
+
if (left.name !== right.name) return false;
|
|
7
|
+
if (left.tags.length !== right.tags.length) return false;
|
|
8
|
+
for (const [tagKey, tagValue] of left.tags) if (!right.tags.some(([otherKey, otherValue]) => otherKey === tagKey && Object.is(otherValue, tagValue))) return false;
|
|
9
9
|
return true;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* @since 0.3.16-canary.0
|
|
13
13
|
*/
|
|
14
|
-
const
|
|
14
|
+
const DEFAULT_BINDING_SLOT = {
|
|
15
15
|
name: void 0,
|
|
16
16
|
tags: []
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
19
|
* @since 0.3.16-canary.0
|
|
20
20
|
*/
|
|
21
|
-
function
|
|
21
|
+
function bindingSlotToString(slot) {
|
|
22
22
|
if (slot.name === void 0 && slot.tags.length === 0) return "default";
|
|
23
23
|
const parts = [];
|
|
24
24
|
if (slot.name !== void 0) parts.push(`name:${slot.name}`);
|
|
25
|
-
for (const [
|
|
25
|
+
for (const [tagKey, tagValue] of slot.tags) parts.push(`tag:${tagKey}=${String(tagValue)}`);
|
|
26
26
|
return parts.join(",");
|
|
27
27
|
}
|
|
28
28
|
let _idCounter = 0;
|
|
@@ -33,4 +33,4 @@ function generateBindingId() {
|
|
|
33
33
|
return String(++_idCounter);
|
|
34
34
|
}
|
|
35
35
|
//#endregion
|
|
36
|
-
export {
|
|
36
|
+
export { DEFAULT_BINDING_SLOT, bindingSlotEquals, bindingSlotToString, generateBindingId };
|
package/dist/constraints.mjs
CHANGED
|
@@ -67,7 +67,7 @@ function whenParentTaggedAll(tags) {
|
|
|
67
67
|
const { parent } = constraintContext;
|
|
68
68
|
if (parent === void 0) return false;
|
|
69
69
|
const { tags: parentTags } = parent.slot;
|
|
70
|
-
return tags.every(([tagKey, tagValue]) => parentTags.some(([
|
|
70
|
+
return tags.every(([tagKey, tagValue]) => parentTags.some(([otherKey, otherValue]) => otherKey === tagKey && Object.is(otherValue, tagValue)));
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
@@ -80,7 +80,7 @@ function whenParentTaggedAll(tags) {
|
|
|
80
80
|
function whenAnyAncestorTaggedAll(tags) {
|
|
81
81
|
return (constraintContext) => constraintContext.ancestors.some((frame) => {
|
|
82
82
|
const { tags: frameTags } = frame.slot;
|
|
83
|
-
return tags.every(([tagKey, tagValue]) => frameTags.some(([
|
|
83
|
+
return tags.every(([tagKey, tagValue]) => frameTags.some(([otherKey, otherValue]) => otherKey === tagKey && Object.is(otherValue, tagValue)));
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
//#endregion
|
package/dist/container.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { effectiveBindingScope } from "./binding-scope.mjs";
|
|
2
2
|
import { AsyncModuleLoadError, CircularDependencyError, DisposedContainerError, InternalError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError } from "./errors.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { DEFAULT_BINDING_SLOT, generateBindingId } from "./binding.mjs";
|
|
4
4
|
import { tokenName } from "./token.mjs";
|
|
5
5
|
import { BindingRegistry } from "./registry.mjs";
|
|
6
6
|
import { ScopeManager } from "./scope.mjs";
|
|
7
7
|
import { LifecycleManager } from "./lifecycle.mjs";
|
|
8
|
-
import {
|
|
8
|
+
import { bindingSlotToResolveOptions, injectionSlotToResolveOptions } from "./resolve-options.mjs";
|
|
9
9
|
import { DependencyResolver } from "./resolver.mjs";
|
|
10
10
|
import { Inspector } from "./inspector.mjs";
|
|
11
11
|
import { buildDependencyGraph } from "./dependency-graph.mjs";
|
|
@@ -53,7 +53,7 @@ var DefaultContainer = class DefaultContainer {
|
|
|
53
53
|
}
|
|
54
54
|
_createBindToBuilder(token, moduleRef) {
|
|
55
55
|
const registry = this._registry;
|
|
56
|
-
const commitBinding = (
|
|
56
|
+
const commitBinding = (binding, previousId) => {
|
|
57
57
|
if (previousId !== void 0) {
|
|
58
58
|
registry.removeById(previousId);
|
|
59
59
|
if (moduleRef !== void 0) {
|
|
@@ -64,18 +64,18 @@ var DefaultContainer = class DefaultContainer {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
registry.add(
|
|
67
|
+
registry.add(binding);
|
|
68
68
|
if (moduleRef !== void 0) {
|
|
69
69
|
let ids = this._moduleBindingIds.get(moduleRef);
|
|
70
70
|
if (ids === void 0) {
|
|
71
71
|
ids = [];
|
|
72
72
|
this._moduleBindingIds.set(moduleRef, ids);
|
|
73
73
|
}
|
|
74
|
-
ids.push(
|
|
74
|
+
ids.push(binding.id);
|
|
75
75
|
}
|
|
76
|
-
return
|
|
76
|
+
return binding.id;
|
|
77
77
|
};
|
|
78
|
-
return new
|
|
78
|
+
return new BindingEntry(token, commitBinding);
|
|
79
79
|
}
|
|
80
80
|
unbind(tokenOrId) {
|
|
81
81
|
this._assertNotDisposed();
|
|
@@ -130,8 +130,8 @@ var DefaultContainer = class DefaultContainer {
|
|
|
130
130
|
}
|
|
131
131
|
_getBindingsForTokenOrId(tokenOrId) {
|
|
132
132
|
if (typeof tokenOrId === "string") {
|
|
133
|
-
const
|
|
134
|
-
return
|
|
133
|
+
const binding = this._registry.getById(tokenOrId);
|
|
134
|
+
return binding !== void 0 ? [binding] : [];
|
|
135
135
|
}
|
|
136
136
|
return [...this._registry.getAll(tokenOrId)];
|
|
137
137
|
}
|
|
@@ -141,72 +141,72 @@ var DefaultContainer = class DefaultContainer {
|
|
|
141
141
|
}
|
|
142
142
|
_loadSyncModules(modules) {
|
|
143
143
|
const toLoad = this._collectModuleDeps(modules);
|
|
144
|
-
for (const
|
|
145
|
-
if (!isSyncModule(
|
|
146
|
-
const
|
|
147
|
-
const existing = this._moduleRefs.get(
|
|
144
|
+
for (const module of toLoad) {
|
|
145
|
+
if (!isSyncModule(module)) throw new AsyncModuleLoadError(module.name);
|
|
146
|
+
const moduleRef = module;
|
|
147
|
+
const existing = this._moduleRefs.get(moduleRef);
|
|
148
148
|
if (existing !== void 0) {
|
|
149
|
-
this._moduleRefs.set(
|
|
149
|
+
this._moduleRefs.set(moduleRef, existing + 1);
|
|
150
150
|
continue;
|
|
151
151
|
}
|
|
152
|
-
this._moduleRefs.set(
|
|
153
|
-
const builder = this._createModuleBuilder(
|
|
154
|
-
|
|
152
|
+
this._moduleRefs.set(moduleRef, 1);
|
|
153
|
+
const builder = this._createModuleBuilder(moduleRef);
|
|
154
|
+
module._setup(builder);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
_collectModuleDeps(modules) {
|
|
158
158
|
const seen = /* @__PURE__ */ new Set();
|
|
159
159
|
const result = [];
|
|
160
|
-
const visit = (
|
|
161
|
-
const
|
|
162
|
-
if (seen.has(
|
|
163
|
-
seen.add(
|
|
164
|
-
result.push(
|
|
160
|
+
const visit = (module) => {
|
|
161
|
+
const moduleRef = module;
|
|
162
|
+
if (seen.has(moduleRef)) return;
|
|
163
|
+
seen.add(moduleRef);
|
|
164
|
+
result.push(module);
|
|
165
165
|
};
|
|
166
|
-
for (const
|
|
166
|
+
for (const module of modules) visit(module);
|
|
167
167
|
return result;
|
|
168
168
|
}
|
|
169
169
|
async loadAsync(...modules) {
|
|
170
170
|
this._assertNotDisposed();
|
|
171
|
-
for (const
|
|
171
|
+
for (const module of modules) await this._loadOneModuleAsync(module);
|
|
172
172
|
}
|
|
173
|
-
async _loadOneModuleAsync(
|
|
174
|
-
const
|
|
175
|
-
const existing = this._moduleRefs.get(
|
|
173
|
+
async _loadOneModuleAsync(module) {
|
|
174
|
+
const moduleRef = module;
|
|
175
|
+
const existing = this._moduleRefs.get(moduleRef);
|
|
176
176
|
if (existing !== void 0) {
|
|
177
|
-
this._moduleRefs.set(
|
|
177
|
+
this._moduleRefs.set(moduleRef, existing + 1);
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
|
-
this._moduleRefs.set(
|
|
181
|
-
if (isSyncModule(
|
|
182
|
-
const builder = this._createModuleBuilder(
|
|
183
|
-
|
|
180
|
+
this._moduleRefs.set(moduleRef, 1);
|
|
181
|
+
if (isSyncModule(module)) {
|
|
182
|
+
const builder = this._createModuleBuilder(moduleRef);
|
|
183
|
+
module._setup(builder);
|
|
184
184
|
} else {
|
|
185
185
|
const importPromises = [];
|
|
186
|
-
const builder = this._createAsyncModuleBuilder(
|
|
187
|
-
await
|
|
186
|
+
const builder = this._createAsyncModuleBuilder(moduleRef, importPromises);
|
|
187
|
+
await module._setup(builder);
|
|
188
188
|
if (importPromises.length > 0) await Promise.all(importPromises);
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
_createModuleBuilder(moduleRef) {
|
|
192
192
|
return {
|
|
193
|
-
bind: (
|
|
194
|
-
import: (...
|
|
195
|
-
this._loadSyncModules(
|
|
193
|
+
bind: (token) => this._createBindToBuilder(token, moduleRef),
|
|
194
|
+
import: (...modules) => {
|
|
195
|
+
this._loadSyncModules(modules);
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
199
|
_createAsyncModuleBuilder(moduleRef, importPromises) {
|
|
200
200
|
return {
|
|
201
|
-
bind: (
|
|
202
|
-
import: (...
|
|
203
|
-
for (const
|
|
201
|
+
bind: (token) => this._createBindToBuilder(token, moduleRef),
|
|
202
|
+
import: (...modules) => {
|
|
203
|
+
for (const module of modules) importPromises.push(this._loadOneModuleAsync(module));
|
|
204
204
|
}
|
|
205
205
|
};
|
|
206
206
|
}
|
|
207
207
|
unload(...modules) {
|
|
208
208
|
this._assertNotDisposed();
|
|
209
|
-
for (const
|
|
209
|
+
for (const module of modules) this._unloadModuleSync(module);
|
|
210
210
|
}
|
|
211
211
|
_unloadModuleSync(ref) {
|
|
212
212
|
const count = this._moduleRefs.get(ref) ?? 0;
|
|
@@ -229,7 +229,7 @@ var DefaultContainer = class DefaultContainer {
|
|
|
229
229
|
}
|
|
230
230
|
async unloadAsync(...modules) {
|
|
231
231
|
this._assertNotDisposed();
|
|
232
|
-
for (const
|
|
232
|
+
for (const module of modules) await this._unloadModuleAsync(module);
|
|
233
233
|
}
|
|
234
234
|
async _unloadModuleAsync(ref) {
|
|
235
235
|
const count = this._moduleRefs.get(ref) ?? 0;
|
|
@@ -254,10 +254,10 @@ var DefaultContainer = class DefaultContainer {
|
|
|
254
254
|
this._assertNotDisposed();
|
|
255
255
|
const entries = registry.entries();
|
|
256
256
|
for (const { target, scope } of entries) {
|
|
257
|
-
const
|
|
258
|
-
if (scope === "singleton")
|
|
259
|
-
else if (scope === "scoped")
|
|
260
|
-
else
|
|
257
|
+
const bindingBuilder = this._createBindToBuilder(target).toSelf();
|
|
258
|
+
if (scope === "singleton") bindingBuilder.singleton();
|
|
259
|
+
else if (scope === "scoped") bindingBuilder.scoped();
|
|
260
|
+
else bindingBuilder.transient();
|
|
261
261
|
}
|
|
262
262
|
return entries.length;
|
|
263
263
|
}
|
|
@@ -323,7 +323,7 @@ var DefaultContainer = class DefaultContainer {
|
|
|
323
323
|
if (effectiveBindingScope(binding) === "singleton" && !this._scope.hasSingleton(binding.id)) {
|
|
324
324
|
if (binding.predicate !== void 0) continue;
|
|
325
325
|
if (binding.kind === "constant" && binding.onActivation === void 0) continue;
|
|
326
|
-
const slotHint =
|
|
326
|
+
const slotHint = bindingSlotToResolveOptions(binding.slot);
|
|
327
327
|
await this.resolveAsync(binding.token, slotHint);
|
|
328
328
|
}
|
|
329
329
|
}
|
|
@@ -407,7 +407,7 @@ var DefaultContainer = class DefaultContainer {
|
|
|
407
407
|
const meta = reader.getConstructorMetadata(binding.target);
|
|
408
408
|
if (meta === void 0) return edges;
|
|
409
409
|
for (const param of meta.params) {
|
|
410
|
-
const paramHint =
|
|
410
|
+
const paramHint = injectionSlotToResolveOptions(param);
|
|
411
411
|
if (param.optional) continue;
|
|
412
412
|
const tokenRef = param.token;
|
|
413
413
|
if (param.multi) {
|
|
@@ -426,7 +426,7 @@ var DefaultContainer = class DefaultContainer {
|
|
|
426
426
|
return edges;
|
|
427
427
|
}
|
|
428
428
|
if (binding.kind === "resolved" || binding.kind === "resolved-async") for (const dep of binding.deps) {
|
|
429
|
-
const depHint =
|
|
429
|
+
const depHint = injectionSlotToResolveOptions(dep);
|
|
430
430
|
if (dep.optional) continue;
|
|
431
431
|
const tokenRef = dep.token;
|
|
432
432
|
if (dep.multi) {
|
|
@@ -478,7 +478,7 @@ function updateSlotTag(slot, tag, value) {
|
|
|
478
478
|
tags: existing
|
|
479
479
|
};
|
|
480
480
|
}
|
|
481
|
-
var
|
|
481
|
+
var BindingEntry = class {
|
|
482
482
|
_token;
|
|
483
483
|
_commit;
|
|
484
484
|
constructor(_token, _commit) {
|
|
@@ -486,7 +486,7 @@ var BindToBuilderImpl = class {
|
|
|
486
486
|
this._commit = _commit;
|
|
487
487
|
}
|
|
488
488
|
to(type) {
|
|
489
|
-
return new
|
|
489
|
+
return new ConstraintBuilder(this._token, {
|
|
490
490
|
kind: "class",
|
|
491
491
|
target: type,
|
|
492
492
|
scope: "transient"
|
|
@@ -494,32 +494,32 @@ var BindToBuilderImpl = class {
|
|
|
494
494
|
}
|
|
495
495
|
toSelf() {
|
|
496
496
|
if (typeof this._token !== "function") throw new Error("toSelf() requires token to be a Constructor");
|
|
497
|
-
return new
|
|
497
|
+
return new ConstraintBuilder(this._token, {
|
|
498
498
|
kind: "class",
|
|
499
499
|
target: this._token,
|
|
500
500
|
scope: "transient"
|
|
501
501
|
}, this._commit);
|
|
502
502
|
}
|
|
503
503
|
toConstantValue(value) {
|
|
504
|
-
return new
|
|
504
|
+
return new ConstantBuilder(this._token, value, this._commit);
|
|
505
505
|
}
|
|
506
506
|
toDynamic(factory) {
|
|
507
|
-
return new
|
|
507
|
+
return new ConstraintBuilder(this._token, {
|
|
508
508
|
kind: "dynamic",
|
|
509
509
|
factory,
|
|
510
510
|
scope: "transient"
|
|
511
511
|
}, this._commit);
|
|
512
512
|
}
|
|
513
513
|
toDynamicAsync(factory) {
|
|
514
|
-
return new
|
|
514
|
+
return new ConstraintBuilder(this._token, {
|
|
515
515
|
kind: "dynamic-async",
|
|
516
516
|
factory,
|
|
517
517
|
scope: "transient"
|
|
518
518
|
}, this._commit);
|
|
519
519
|
}
|
|
520
520
|
toResolved(factory, deps) {
|
|
521
|
-
const normalizedDeps = deps.map((
|
|
522
|
-
return new
|
|
521
|
+
const normalizedDeps = deps.map((dependency) => normalizeToDescriptor(dependency));
|
|
522
|
+
return new ConstraintBuilder(this._token, {
|
|
523
523
|
kind: "resolved",
|
|
524
524
|
factory,
|
|
525
525
|
deps: normalizedDeps,
|
|
@@ -527,8 +527,8 @@ var BindToBuilderImpl = class {
|
|
|
527
527
|
}, this._commit);
|
|
528
528
|
}
|
|
529
529
|
toResolvedAsync(factory, deps) {
|
|
530
|
-
const normalizedDeps = deps.map((
|
|
531
|
-
return new
|
|
530
|
+
const normalizedDeps = deps.map((dependency) => normalizeToDescriptor(dependency));
|
|
531
|
+
return new ConstraintBuilder(this._token, {
|
|
532
532
|
kind: "resolved-async",
|
|
533
533
|
factory,
|
|
534
534
|
deps: normalizedDeps,
|
|
@@ -536,10 +536,10 @@ var BindToBuilderImpl = class {
|
|
|
536
536
|
}, this._commit);
|
|
537
537
|
}
|
|
538
538
|
toAlias(target) {
|
|
539
|
-
return new
|
|
539
|
+
return new AliasBuilder(this._token, target, this._commit);
|
|
540
540
|
}
|
|
541
541
|
};
|
|
542
|
-
var
|
|
542
|
+
var ConstraintBuilder = class {
|
|
543
543
|
_token;
|
|
544
544
|
_partial;
|
|
545
545
|
_commit;
|
|
@@ -551,7 +551,7 @@ var BindingBuilderImpl = class {
|
|
|
551
551
|
this._partial = _partial;
|
|
552
552
|
this._commit = _commit;
|
|
553
553
|
this._slot = {
|
|
554
|
-
...
|
|
554
|
+
...DEFAULT_BINDING_SLOT,
|
|
555
555
|
tags: []
|
|
556
556
|
};
|
|
557
557
|
this._doCommit();
|
|
@@ -591,7 +591,7 @@ var BindingBuilderImpl = class {
|
|
|
591
591
|
singleton() {
|
|
592
592
|
const previousId = this._committed;
|
|
593
593
|
this._committed = void 0;
|
|
594
|
-
return new
|
|
594
|
+
return new ScopeBuilder(this._token, {
|
|
595
595
|
...this._partial,
|
|
596
596
|
scope: "singleton"
|
|
597
597
|
}, this._slot, this._predicate, this._commit, "singleton", previousId);
|
|
@@ -599,7 +599,7 @@ var BindingBuilderImpl = class {
|
|
|
599
599
|
transient() {
|
|
600
600
|
const previousId = this._committed;
|
|
601
601
|
this._committed = void 0;
|
|
602
|
-
return new
|
|
602
|
+
return new ScopeBuilder(this._token, {
|
|
603
603
|
...this._partial,
|
|
604
604
|
scope: "transient"
|
|
605
605
|
}, this._slot, this._predicate, this._commit, "transient", previousId);
|
|
@@ -607,7 +607,7 @@ var BindingBuilderImpl = class {
|
|
|
607
607
|
scoped() {
|
|
608
608
|
const previousId = this._committed;
|
|
609
609
|
this._committed = void 0;
|
|
610
|
-
return new
|
|
610
|
+
return new ScopeBuilder(this._token, {
|
|
611
611
|
...this._partial,
|
|
612
612
|
scope: "scoped"
|
|
613
613
|
}, this._slot, this._predicate, this._commit, "scoped", previousId);
|
|
@@ -616,7 +616,7 @@ var BindingBuilderImpl = class {
|
|
|
616
616
|
return this._committed;
|
|
617
617
|
}
|
|
618
618
|
};
|
|
619
|
-
var
|
|
619
|
+
var ScopeBuilder = class {
|
|
620
620
|
_token;
|
|
621
621
|
_partial;
|
|
622
622
|
_slot;
|
|
@@ -664,7 +664,7 @@ var ScopeBuilderImpl = class {
|
|
|
664
664
|
return this._committed;
|
|
665
665
|
}
|
|
666
666
|
};
|
|
667
|
-
var
|
|
667
|
+
var ConstantBuilder = class {
|
|
668
668
|
_token;
|
|
669
669
|
_value;
|
|
670
670
|
_commit;
|
|
@@ -678,7 +678,7 @@ var ConstantBindingBuilderImpl = class {
|
|
|
678
678
|
this._value = _value;
|
|
679
679
|
this._commit = _commit;
|
|
680
680
|
this._slot = {
|
|
681
|
-
...
|
|
681
|
+
...DEFAULT_BINDING_SLOT,
|
|
682
682
|
tags: []
|
|
683
683
|
};
|
|
684
684
|
this._doCommit();
|
|
@@ -733,7 +733,7 @@ var ConstantBindingBuilderImpl = class {
|
|
|
733
733
|
return this._committed;
|
|
734
734
|
}
|
|
735
735
|
};
|
|
736
|
-
var
|
|
736
|
+
var AliasBuilder = class {
|
|
737
737
|
_token;
|
|
738
738
|
_target;
|
|
739
739
|
_commit;
|
|
@@ -745,7 +745,7 @@ var AliasBindingBuilderImpl = class {
|
|
|
745
745
|
this._target = _target;
|
|
746
746
|
this._commit = _commit;
|
|
747
747
|
this._slot = {
|
|
748
|
-
...
|
|
748
|
+
...DEFAULT_BINDING_SLOT,
|
|
749
749
|
tags: []
|
|
750
750
|
};
|
|
751
751
|
this._doCommit();
|
|
@@ -30,7 +30,7 @@ declare function isInjectionDescriptor(value: unknown): value is InjectionDescri
|
|
|
30
30
|
/**
|
|
31
31
|
* @since 0.3.16-canary.0
|
|
32
32
|
*/
|
|
33
|
-
declare function normalizeToDescriptor(
|
|
33
|
+
declare function normalizeToDescriptor(dependency: InjectableDependency): InjectionDescriptor;
|
|
34
34
|
type ClassAccessorDecorator<This, Value> = (target: ClassAccessorDecoratorTarget<This, Value>, context: ClassAccessorDecoratorContext<This, Value>) => ClassAccessorDecoratorResult<This, Value> | void;
|
|
35
35
|
/**
|
|
36
36
|
* @since 0.3.16-canary.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InternalError, MissingContainerContextError } from "../errors.mjs";
|
|
2
2
|
import { getActiveContainer } from "../environment.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { injectionSlotToResolveOptions } from "../resolve-options.mjs";
|
|
4
4
|
import { INJECT_ACCESSOR_KEY, accessorMetadataByMetadataObjectMap } from "../metadata/metadata-keys.mjs";
|
|
5
5
|
//#region src/decorators/inject.ts
|
|
6
6
|
/**
|
|
@@ -15,10 +15,10 @@ function isInjectionDescriptor(value) {
|
|
|
15
15
|
/**
|
|
16
16
|
* @since 0.3.16-canary.0
|
|
17
17
|
*/
|
|
18
|
-
function normalizeToDescriptor(
|
|
19
|
-
if (isInjectionDescriptor(
|
|
18
|
+
function normalizeToDescriptor(dependency) {
|
|
19
|
+
if (isInjectionDescriptor(dependency)) return materializeInjectionDescriptor(dependency);
|
|
20
20
|
return {
|
|
21
|
-
token:
|
|
21
|
+
token: dependency,
|
|
22
22
|
optional: false,
|
|
23
23
|
multi: false
|
|
24
24
|
};
|
|
@@ -27,9 +27,9 @@ function normalizeToDescriptor(dep) {
|
|
|
27
27
|
* Dual-role `inject()` values are functions: [[Function]].name must not be treated as a DI slot name.
|
|
28
28
|
* Only enumerable own `name` / `tags` from `Object.defineProperties` are real injection options.
|
|
29
29
|
*/
|
|
30
|
-
function materializeInjectionDescriptor(
|
|
31
|
-
if (typeof
|
|
32
|
-
const dualRole =
|
|
30
|
+
function materializeInjectionDescriptor(dependency) {
|
|
31
|
+
if (typeof dependency !== "function") return dependency;
|
|
32
|
+
const dualRole = dependency;
|
|
33
33
|
const base = {
|
|
34
34
|
token: dualRole.token,
|
|
35
35
|
optional: dualRole.optional,
|
|
@@ -92,7 +92,7 @@ function inject(token, options) {
|
|
|
92
92
|
context.addInitializer(function() {
|
|
93
93
|
const container = getActiveContainer();
|
|
94
94
|
if (container === void 0) throw new MissingContainerContextError(String(context.name));
|
|
95
|
-
const hint = options === void 0 ? void 0 :
|
|
95
|
+
const hint = options === void 0 ? void 0 : injectionSlotToResolveOptions({
|
|
96
96
|
...options.name !== void 0 ? { name: options.name } : {},
|
|
97
97
|
...options.tags !== void 0 ? { tags: options.tags } : {}
|
|
98
98
|
});
|