@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
|
@@ -8,8 +8,8 @@ function buildDependencyGraph(registry, metadataReader, options, parentRegistry)
|
|
|
8
8
|
const nodes = [];
|
|
9
9
|
const edges = [];
|
|
10
10
|
const includesParent = options?.includeParent === true;
|
|
11
|
-
const addBindings = (
|
|
12
|
-
for (const binding of
|
|
11
|
+
const addBindings = (sourceRegistry, fromParent) => {
|
|
12
|
+
for (const binding of sourceRegistry.allBindings()) {
|
|
13
13
|
const scope = effectiveBindingScope(binding);
|
|
14
14
|
nodes.push({
|
|
15
15
|
id: binding.id,
|
|
@@ -20,27 +20,27 @@ function buildDependencyGraph(registry, metadataReader, options, parentRegistry)
|
|
|
20
20
|
});
|
|
21
21
|
if (binding.kind === "class") {
|
|
22
22
|
const meta = metadataReader.getConstructorMetadata(binding.target);
|
|
23
|
-
if (meta !== void 0) meta.params.forEach((param,
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
23
|
+
if (meta !== void 0) meta.params.forEach((param, index) => {
|
|
24
|
+
const dependencyBinding = sourceRegistry.getAll(param.token)[0];
|
|
25
|
+
if (dependencyBinding !== void 0) edges.push({
|
|
26
26
|
from: binding.id,
|
|
27
|
-
to:
|
|
28
|
-
label: `[${
|
|
27
|
+
to: dependencyBinding.id,
|
|
28
|
+
label: `[${index}]`
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
|
-
} else if (binding.kind === "resolved" || binding.kind === "resolved-async") binding.deps.forEach((
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
const label =
|
|
31
|
+
} else if (binding.kind === "resolved" || binding.kind === "resolved-async") binding.deps.forEach((dependency, index) => {
|
|
32
|
+
const dependencyBindings = sourceRegistry.getAll(dependency.token);
|
|
33
|
+
if (dependencyBindings.length > 0 && dependencyBindings[0] !== void 0) {
|
|
34
|
+
const label = dependency.name !== void 0 ? `name:${dependency.name}` : dependency.tags !== void 0 && dependency.tags.length > 0 ? `tag:${dependency.tags[0]?.[0]}=${String(dependency.tags[0]?.[1])}` : `[${index}]`;
|
|
35
35
|
edges.push({
|
|
36
36
|
from: binding.id,
|
|
37
|
-
to:
|
|
37
|
+
to: dependencyBindings[0].id,
|
|
38
38
|
label
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
else if (binding.kind === "alias") {
|
|
43
|
-
const targetBindings =
|
|
43
|
+
const targetBindings = sourceRegistry.getAll(binding.target);
|
|
44
44
|
if (targetBindings.length > 0 && targetBindings[0] !== void 0) edges.push({
|
|
45
45
|
from: binding.id,
|
|
46
46
|
to: targetBindings[0].id,
|
package/dist/environment.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Constructor } from "./constructor-type.mjs";
|
|
2
2
|
import { Token } from "./token.mjs";
|
|
3
|
-
import { BindingIdentifier, BindingKind, BindingScope, ConstraintContext,
|
|
3
|
+
import { BindingIdentifier, BindingKind, BindingScope, ConstraintContext, ResolutionContext, ResolutionFrame, ResolveOptions } from "./types.mjs";
|
|
4
4
|
import { Container } from "./container.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/environment.d.ts
|
|
@@ -16,14 +16,14 @@ declare function getActiveContainer(): Container | undefined;
|
|
|
16
16
|
* @since 0.3.16-canary.0
|
|
17
17
|
*/
|
|
18
18
|
interface ResolverCallbacks {
|
|
19
|
-
resolveFromContext<const Value>(token: Token<Value> | Constructor<Value>,
|
|
20
|
-
resolve<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined,
|
|
21
|
-
resolveAsyncFromContext<const Value>(token: Token<Value> | Constructor<Value>,
|
|
22
|
-
resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined,
|
|
23
|
-
resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined,
|
|
24
|
-
resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined,
|
|
25
|
-
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined,
|
|
26
|
-
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined,
|
|
19
|
+
resolveFromContext<const Value>(token: Token<Value> | Constructor<Value>, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Value;
|
|
20
|
+
resolve<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Value;
|
|
21
|
+
resolveAsyncFromContext<const Value>(token: Token<Value> | Constructor<Value>, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value>;
|
|
22
|
+
resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value>;
|
|
23
|
+
resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Value | undefined;
|
|
24
|
+
resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value | undefined>;
|
|
25
|
+
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Array<Value>;
|
|
26
|
+
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Array<Value>>;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* @since 0.3.16-canary.0
|
|
@@ -31,12 +31,12 @@ interface ResolverCallbacks {
|
|
|
31
31
|
declare class DefaultResolutionContext implements ResolutionContext {
|
|
32
32
|
private _resolver;
|
|
33
33
|
private _resolutionPath;
|
|
34
|
-
private
|
|
34
|
+
private _resolutionStack;
|
|
35
35
|
private _currentHint;
|
|
36
|
-
constructor(resolver: ResolverCallbacks, resolutionPath: Array<string>,
|
|
36
|
+
constructor(resolver: ResolverCallbacks, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>, currentHint: ResolveOptions | undefined);
|
|
37
37
|
private _graph;
|
|
38
38
|
get graph(): ConstraintContext;
|
|
39
|
-
reset(resolver: ResolverCallbacks, resolutionPath: Array<string>,
|
|
39
|
+
reset(resolver: ResolverCallbacks, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>, currentHint: ResolveOptions | undefined): void;
|
|
40
40
|
resolve<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Value;
|
|
41
41
|
resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Promise<Value>;
|
|
42
42
|
resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Value | undefined;
|
|
@@ -47,9 +47,9 @@ declare class DefaultResolutionContext implements ResolutionContext {
|
|
|
47
47
|
/**
|
|
48
48
|
* @since 0.3.16-canary.0
|
|
49
49
|
*/
|
|
50
|
-
declare function
|
|
50
|
+
declare function buildResolutionFrame(tokenName: string, scope: BindingScope, bindingId: BindingIdentifier, kind: BindingKind, slot: {
|
|
51
51
|
name: string | undefined;
|
|
52
52
|
tags: ReadonlyArray<readonly [string, unknown]>;
|
|
53
|
-
}):
|
|
53
|
+
}): ResolutionFrame;
|
|
54
54
|
//#endregion
|
|
55
|
-
export { DefaultResolutionContext, ResolverCallbacks,
|
|
55
|
+
export { DefaultResolutionContext, ResolverCallbacks, buildResolutionFrame, getActiveContainer, runWithContainer };
|
package/dist/environment.mjs
CHANGED
|
@@ -24,68 +24,68 @@ function getActiveContainer() {
|
|
|
24
24
|
var DefaultResolutionContext = class {
|
|
25
25
|
_resolver;
|
|
26
26
|
_resolutionPath;
|
|
27
|
-
|
|
27
|
+
_resolutionStack;
|
|
28
28
|
_currentHint;
|
|
29
|
-
constructor(resolver, resolutionPath,
|
|
29
|
+
constructor(resolver, resolutionPath, resolutionStack, currentHint) {
|
|
30
30
|
this._resolver = resolver;
|
|
31
31
|
this._resolutionPath = resolutionPath;
|
|
32
|
-
this.
|
|
32
|
+
this._resolutionStack = resolutionStack;
|
|
33
33
|
this._currentHint = currentHint;
|
|
34
34
|
}
|
|
35
35
|
_graph;
|
|
36
36
|
get graph() {
|
|
37
|
-
if (this._graph === void 0) this._graph = new DefaultConstraintContext(this._resolutionPath, this.
|
|
37
|
+
if (this._graph === void 0) this._graph = new DefaultConstraintContext(this._resolutionPath, this._resolutionStack, this._currentHint);
|
|
38
38
|
return this._graph;
|
|
39
39
|
}
|
|
40
|
-
reset(resolver, resolutionPath,
|
|
40
|
+
reset(resolver, resolutionPath, resolutionStack, currentHint) {
|
|
41
41
|
this._resolver = resolver;
|
|
42
42
|
this._resolutionPath = resolutionPath;
|
|
43
|
-
this.
|
|
43
|
+
this._resolutionStack = resolutionStack;
|
|
44
44
|
this._currentHint = currentHint;
|
|
45
45
|
this._graph = void 0;
|
|
46
46
|
}
|
|
47
47
|
resolve(token, hint) {
|
|
48
|
-
if (hint === void 0) return this._resolver.resolveFromContext(token, this._resolutionPath, this.
|
|
49
|
-
return this._resolver.resolve(token, hint, this._resolutionPath, this.
|
|
48
|
+
if (hint === void 0) return this._resolver.resolveFromContext(token, this._resolutionPath, this._resolutionStack);
|
|
49
|
+
return this._resolver.resolve(token, hint, this._resolutionPath, this._resolutionStack);
|
|
50
50
|
}
|
|
51
51
|
resolveAsync(token, hint) {
|
|
52
|
-
if (hint === void 0) return this._resolver.resolveAsyncFromContext(token, this._resolutionPath, this.
|
|
53
|
-
return this._resolver.resolveAsync(token, hint, this._resolutionPath, this.
|
|
52
|
+
if (hint === void 0) return this._resolver.resolveAsyncFromContext(token, this._resolutionPath, this._resolutionStack);
|
|
53
|
+
return this._resolver.resolveAsync(token, hint, this._resolutionPath, this._resolutionStack);
|
|
54
54
|
}
|
|
55
55
|
resolveOptional(token, hint) {
|
|
56
|
-
return this._resolver.resolveOptional(token, hint, this._resolutionPath, this.
|
|
56
|
+
return this._resolver.resolveOptional(token, hint, this._resolutionPath, this._resolutionStack);
|
|
57
57
|
}
|
|
58
58
|
resolveOptionalAsync(token, hint) {
|
|
59
|
-
return this._resolver.resolveOptionalAsync(token, hint, this._resolutionPath, this.
|
|
59
|
+
return this._resolver.resolveOptionalAsync(token, hint, this._resolutionPath, this._resolutionStack);
|
|
60
60
|
}
|
|
61
61
|
resolveAll(token, hint) {
|
|
62
|
-
return this._resolver.resolveAll(token, hint, this._resolutionPath, this.
|
|
62
|
+
return this._resolver.resolveAll(token, hint, this._resolutionPath, this._resolutionStack);
|
|
63
63
|
}
|
|
64
64
|
resolveAllAsync(token, hint) {
|
|
65
|
-
return this._resolver.resolveAllAsync(token, hint, this._resolutionPath, this.
|
|
65
|
+
return this._resolver.resolveAllAsync(token, hint, this._resolutionPath, this._resolutionStack);
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
var DefaultConstraintContext = class {
|
|
69
69
|
resolutionPath;
|
|
70
|
-
|
|
70
|
+
resolutionStack;
|
|
71
71
|
parent;
|
|
72
72
|
currentResolveHint;
|
|
73
|
-
constructor(resolutionPath,
|
|
73
|
+
constructor(resolutionPath, resolutionStack, currentResolveHint) {
|
|
74
74
|
this.resolutionPath = resolutionPath;
|
|
75
|
-
this.
|
|
76
|
-
this.parent =
|
|
75
|
+
this.resolutionStack = resolutionStack;
|
|
76
|
+
this.parent = resolutionStack.at(-1);
|
|
77
77
|
this.currentResolveHint = currentResolveHint;
|
|
78
78
|
}
|
|
79
79
|
_ancestors;
|
|
80
80
|
get ancestors() {
|
|
81
|
-
if (this._ancestors === void 0) this._ancestors = this.
|
|
81
|
+
if (this._ancestors === void 0) this._ancestors = this.resolutionStack.length > 1 ? this.resolutionStack.slice(0, -1) : [];
|
|
82
82
|
return this._ancestors;
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
/**
|
|
86
86
|
* @since 0.3.16-canary.0
|
|
87
87
|
*/
|
|
88
|
-
function
|
|
88
|
+
function buildResolutionFrame(tokenName, scope, bindingId, kind, slot) {
|
|
89
89
|
return {
|
|
90
90
|
tokenName,
|
|
91
91
|
scope,
|
|
@@ -95,4 +95,4 @@ function buildMaterializationFrame(tokenName, scope, bindingId, kind, slot) {
|
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
//#endregion
|
|
98
|
-
export { DefaultResolutionContext,
|
|
98
|
+
export { DefaultResolutionContext, buildResolutionFrame, getActiveContainer, runWithContainer };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Constructor } from "./constructor-type.mjs";
|
|
2
2
|
import { Token, isToken, token, tokenName } from "./token.mjs";
|
|
3
|
-
import { ActivationHandler, BindingIdentifier, BindingKind, BindingScope, ConstraintContext, DeactivationHandler, DependencyKey,
|
|
3
|
+
import { ActivationHandler, BindingIdentifier, BindingKind, BindingScope, ConstraintContext, DeactivationHandler, DependencyKey, ResolutionContext, ResolutionFrame, ResolveOptions, TokenValue } from "./types.mjs";
|
|
4
4
|
import { InjectOptions, InjectableDependency, InjectionDescriptor, inject, injectAll, isInjectionDescriptor, optional } from "./decorators/inject.mjs";
|
|
5
5
|
import { AliasBindingBuilder, BindToBuilder, BindingBuilder, ConstantBindingBuilder, ScopedBindingBuilder, SingletonBindingBuilder, SingletonLifecycleBuilder, TransientBindingBuilder } from "./binding.mjs";
|
|
6
6
|
import { effectiveBindingScope } from "./binding-scope.mjs";
|
|
@@ -13,6 +13,6 @@ import { AutoRegisterRegistry, InjectableOptions, createAutoRegisterRegistry, in
|
|
|
13
13
|
import { Container, ContainerStatic } from "./container.mjs";
|
|
14
14
|
import { postConstruct, preDestroy } from "./decorators/lifecycle-decorators.mjs";
|
|
15
15
|
import { AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationDetails, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError } from "./errors.mjs";
|
|
16
|
-
import {
|
|
16
|
+
import { bindingSlotToResolveOptions, injectionSlotToResolveOptions } from "./resolve-options.mjs";
|
|
17
17
|
import { MetadataReaderToken } from "./metadata/metadata-reader-token.mjs";
|
|
18
|
-
export { type ActivationHandler, type AliasBindingBuilder, AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModule, type AsyncModuleBuilder, AsyncModuleLoadError, AsyncResolutionError, type AutoRegisterRegistry, type BindToBuilder, type BindingBuilder, type BindingIdentifier, type BindingKind, type BindingScope, type BindingSnapshot, CircularDependencyError, type ConstantBindingBuilder, type ConstraintContext, type Constructor, Container, type ContainerGraphJson, type Container as ContainerInterface, type ContainerSnapshot, type ContainerStatic, type DeactivationHandler, type DependencyKey, DiError, DisposedContainerError, type GraphEdge, type GraphNode, type GraphOptions, type InjectOptions, type InjectableDependency, type InjectableOptions, type InjectionDescriptor, InternalError, type
|
|
18
|
+
export { type ActivationHandler, type AliasBindingBuilder, AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModule, type AsyncModuleBuilder, AsyncModuleLoadError, AsyncResolutionError, type AutoRegisterRegistry, type BindToBuilder, type BindingBuilder, type BindingIdentifier, type BindingKind, type BindingScope, type BindingSnapshot, CircularDependencyError, type ConstantBindingBuilder, type ConstraintContext, type Constructor, Container, type ContainerGraphJson, type Container as ContainerInterface, type ContainerSnapshot, type ContainerStatic, type DeactivationHandler, type DependencyKey, DiError, DisposedContainerError, type GraphEdge, type GraphNode, type GraphOptions, type InjectOptions, type InjectableDependency, type InjectableOptions, type InjectionDescriptor, InternalError, type MetadataReader, MetadataReaderToken, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, Module, type ModuleBuilder, type MutableLifecycleMetadata, NoMatchingBindingError, RebindUnboundTokenError, type ResolutionContext, type ResolutionFrame, type ResolveOptions, type ScopeViolationDetails, ScopeViolationError, type ScopedBindingBuilder, type SingletonBindingBuilder, type SingletonLifecycleBuilder, SyncDisposalNotSupportedError, SyncModule, type Token, TokenNotBoundError, type TokenValue, type TransientBindingBuilder, bindingSlotToResolveOptions, createAutoRegisterRegistry, effectiveBindingScope, inject, injectAll, injectable, injectionSlotToResolveOptions, isInjectionDescriptor, isSyncModule, isToken, optional, postConstruct, preDestroy, token, tokenName, whenAnyAncestorIs, whenAnyAncestorNamed, whenAnyAncestorTagged, whenAnyAncestorTaggedAll, whenNoAncestorIs, whenNoParentIs, whenParentIs, whenParentNamed, whenParentTagged, whenParentTaggedAll };
|
package/dist/index.mjs
CHANGED
|
@@ -2,11 +2,11 @@ import { effectiveBindingScope } from "./binding-scope.mjs";
|
|
|
2
2
|
import { AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError } from "./errors.mjs";
|
|
3
3
|
import { isToken, token, tokenName } from "./token.mjs";
|
|
4
4
|
import { whenAnyAncestorIs, whenAnyAncestorNamed, whenAnyAncestorTagged, whenAnyAncestorTaggedAll, whenNoAncestorIs, whenNoParentIs, whenParentIs, whenParentNamed, whenParentTagged, whenParentTaggedAll } from "./constraints.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { bindingSlotToResolveOptions, injectionSlotToResolveOptions } from "./resolve-options.mjs";
|
|
6
6
|
import { MetadataReaderToken } from "./metadata/metadata-reader-token.mjs";
|
|
7
7
|
import { inject, injectAll, isInjectionDescriptor, optional } from "./decorators/inject.mjs";
|
|
8
8
|
import { AsyncModule, Module, SyncModule, isSyncModule } from "./module.mjs";
|
|
9
9
|
import { Container } from "./container.mjs";
|
|
10
10
|
import { createAutoRegisterRegistry, injectable } from "./decorators/injectable.mjs";
|
|
11
11
|
import { postConstruct, preDestroy } from "./decorators/lifecycle-decorators.mjs";
|
|
12
|
-
export { AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModule, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, Container, DiError, DisposedContainerError, InternalError, MetadataReaderToken, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, Module, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError, SyncModule, TokenNotBoundError, createAutoRegisterRegistry, effectiveBindingScope, inject, injectAll, injectable,
|
|
12
|
+
export { AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModule, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, Container, DiError, DisposedContainerError, InternalError, MetadataReaderToken, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, Module, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError, SyncModule, TokenNotBoundError, bindingSlotToResolveOptions, createAutoRegisterRegistry, effectiveBindingScope, inject, injectAll, injectable, injectionSlotToResolveOptions, isInjectionDescriptor, isSyncModule, isToken, optional, postConstruct, preDestroy, token, tokenName, whenAnyAncestorIs, whenAnyAncestorNamed, whenAnyAncestorTagged, whenAnyAncestorTaggedAll, whenNoAncestorIs, whenNoParentIs, whenParentIs, whenParentNamed, whenParentTagged, whenParentTaggedAll };
|
package/dist/inspector.mjs
CHANGED
|
@@ -25,14 +25,14 @@ var Inspector = class {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
lookupBindings(token) {
|
|
28
|
-
return this._registry.getAll(token).map((
|
|
28
|
+
return this._registry.getAll(token).map((binding) => this._toSnapshot(binding));
|
|
29
29
|
}
|
|
30
30
|
has(token, hint, parentHas) {
|
|
31
31
|
const bindings = this._registry.getAll(token);
|
|
32
32
|
if (bindings.length > 0) if (hint !== void 0) {
|
|
33
33
|
if (selectBinding(bindings, hint, {
|
|
34
34
|
resolutionPath: [],
|
|
35
|
-
|
|
35
|
+
resolutionStack: [],
|
|
36
36
|
parent: void 0,
|
|
37
37
|
ancestors: [],
|
|
38
38
|
currentResolveHint: hint
|
|
@@ -45,7 +45,7 @@ var Inspector = class {
|
|
|
45
45
|
if (bindings.length === 0) return false;
|
|
46
46
|
if (hint !== void 0) return selectBinding(bindings, hint, {
|
|
47
47
|
resolutionPath: [],
|
|
48
|
-
|
|
48
|
+
resolutionStack: [],
|
|
49
49
|
parent: void 0,
|
|
50
50
|
ancestors: [],
|
|
51
51
|
currentResolveHint: hint
|
|
@@ -53,20 +53,20 @@ var Inspector = class {
|
|
|
53
53
|
return true;
|
|
54
54
|
}
|
|
55
55
|
allBindingSnapshots() {
|
|
56
|
-
return this._registry.allBindings().map((
|
|
56
|
+
return this._registry.allBindings().map((binding) => this._toSnapshot(binding));
|
|
57
57
|
}
|
|
58
|
-
_toSnapshot(
|
|
59
|
-
const scope = effectiveBindingScope(
|
|
60
|
-
const slot =
|
|
61
|
-
name:
|
|
62
|
-
tags:
|
|
63
|
-
} : { tags:
|
|
58
|
+
_toSnapshot(binding) {
|
|
59
|
+
const scope = effectiveBindingScope(binding);
|
|
60
|
+
const slot = binding.slot.name !== void 0 ? {
|
|
61
|
+
name: binding.slot.name,
|
|
62
|
+
tags: binding.slot.tags
|
|
63
|
+
} : { tags: binding.slot.tags };
|
|
64
64
|
return {
|
|
65
|
-
tokenName: tokenName(
|
|
66
|
-
kind:
|
|
65
|
+
tokenName: tokenName(binding.token),
|
|
66
|
+
kind: binding.kind,
|
|
67
67
|
scope,
|
|
68
68
|
slot,
|
|
69
|
-
id:
|
|
69
|
+
id: binding.id
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
};
|
package/dist/module.d.mts
CHANGED
|
@@ -57,6 +57,6 @@ declare const Module: {
|
|
|
57
57
|
/**
|
|
58
58
|
* @since 0.3.16-canary.0
|
|
59
59
|
*/
|
|
60
|
-
declare function isSyncModule(
|
|
60
|
+
declare function isSyncModule(module: SyncModule | AsyncModule): module is SyncModule;
|
|
61
61
|
//#endregion
|
|
62
62
|
export { AsyncModule, AsyncModuleBuilder, Module, ModuleBuilder, SyncModule, isSyncModule };
|
package/dist/module.mjs
CHANGED
|
@@ -35,8 +35,8 @@ const Module = {
|
|
|
35
35
|
/**
|
|
36
36
|
* @since 0.3.16-canary.0
|
|
37
37
|
*/
|
|
38
|
-
function isSyncModule(
|
|
39
|
-
return
|
|
38
|
+
function isSyncModule(module) {
|
|
39
|
+
return module[SYNC_MODULE_BRAND] === true;
|
|
40
40
|
}
|
|
41
41
|
//#endregion
|
|
42
42
|
export { AsyncModule, Module, SyncModule, isSyncModule };
|
package/dist/registry.d.mts
CHANGED
|
@@ -16,15 +16,15 @@ declare class BindingRegistry {
|
|
|
16
16
|
/** Add or replace binding using slot-aware last-wins. */
|
|
17
17
|
add(binding: Binding): void;
|
|
18
18
|
/** Remove all bindings for a token. Returns removed bindings. */
|
|
19
|
-
removeByToken(
|
|
19
|
+
removeByToken(token: Token<unknown> | Constructor): Array<Binding>;
|
|
20
20
|
/** Remove a specific binding by ID. Returns the removed binding or undefined. */
|
|
21
21
|
removeById(id: BindingIdentifier): Binding | undefined;
|
|
22
22
|
/** Get all bindings for a token. */
|
|
23
|
-
getAll(
|
|
23
|
+
getAll(token: Token<unknown> | Constructor): ReadonlyArray<Binding>;
|
|
24
24
|
/** Get binding by ID. */
|
|
25
25
|
getById(id: BindingIdentifier): Binding | undefined;
|
|
26
26
|
/** Check if any binding exists for token. */
|
|
27
|
-
has(
|
|
27
|
+
has(token: Token<unknown> | Constructor): boolean;
|
|
28
28
|
/** All bindings in the registry. */
|
|
29
29
|
allBindings(): ReadonlyArray<Binding>;
|
|
30
30
|
/** Remove all bindings. Returns all removed. */
|
|
@@ -33,7 +33,7 @@ declare class BindingRegistry {
|
|
|
33
33
|
getSimpleTagged(token: Token<unknown> | Constructor, tagKey: string, tagValue: unknown): Binding | undefined;
|
|
34
34
|
getFastDefault(token: Token<unknown> | Constructor): Binding | undefined;
|
|
35
35
|
/** Summarize available slot strings for a token (for error messages). */
|
|
36
|
-
availableSlotStrings(
|
|
36
|
+
availableSlotStrings(token: Token<unknown> | Constructor): Array<string>;
|
|
37
37
|
private _indexSimpleTaggedBinding;
|
|
38
38
|
private _deindexSimpleTaggedBinding;
|
|
39
39
|
private _isPurePredicateBinding;
|
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
|
|
@@ -18,7 +18,7 @@ var BindingRegistry = class {
|
|
|
18
18
|
this._bindings.set(key, bindingsForToken);
|
|
19
19
|
}
|
|
20
20
|
if (!this._isPurePredicateBinding(binding)) {
|
|
21
|
-
const existingIndex = bindingsForToken.findIndex((
|
|
21
|
+
const existingIndex = bindingsForToken.findIndex((candidate) => !this._isPurePredicateBinding(candidate) && bindingSlotEquals(candidate.slot, binding.slot));
|
|
22
22
|
if (existingIndex !== -1) {
|
|
23
23
|
const replacedBinding = bindingsForToken[existingIndex];
|
|
24
24
|
this._byId.delete(replacedBinding.id);
|
|
@@ -32,8 +32,8 @@ var BindingRegistry = class {
|
|
|
32
32
|
this._refreshFastDefaultForToken(key);
|
|
33
33
|
}
|
|
34
34
|
/** Remove all bindings for a token. Returns removed bindings. */
|
|
35
|
-
removeByToken(
|
|
36
|
-
const key =
|
|
35
|
+
removeByToken(token) {
|
|
36
|
+
const key = token;
|
|
37
37
|
const bindingsForToken = this._bindings.get(key) ?? [];
|
|
38
38
|
this._bindings.delete(key);
|
|
39
39
|
this._simpleNamed.delete(key);
|
|
@@ -64,16 +64,16 @@ 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
|
}
|
|
@@ -103,17 +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(
|
|
106
|
+
availableSlotStrings(token) {
|
|
107
|
+
return (this._bindings.get(token) ?? []).map((binding) => bindingSlotToString(binding.slot));
|
|
108
108
|
}
|
|
109
|
-
_indexSimpleTaggedBinding(
|
|
109
|
+
_indexSimpleTaggedBinding(tokenKey, binding) {
|
|
110
110
|
const slot = binding.slot;
|
|
111
111
|
if (slot.name !== void 0 || slot.tags.length !== 1 || binding.predicate !== void 0) return;
|
|
112
112
|
const [tagKey, tagValue] = slot.tags[0];
|
|
113
|
-
let byTagKey = this._simpleTagged.get(
|
|
113
|
+
let byTagKey = this._simpleTagged.get(tokenKey);
|
|
114
114
|
if (byTagKey === void 0) {
|
|
115
115
|
byTagKey = /* @__PURE__ */ new Map();
|
|
116
|
-
this._simpleTagged.set(
|
|
116
|
+
this._simpleTagged.set(tokenKey, byTagKey);
|
|
117
117
|
}
|
|
118
118
|
let byTagValue = byTagKey.get(tagKey);
|
|
119
119
|
if (byTagValue === void 0) {
|
|
@@ -122,11 +122,11 @@ var BindingRegistry = class {
|
|
|
122
122
|
}
|
|
123
123
|
byTagValue.set(tagValue, binding);
|
|
124
124
|
}
|
|
125
|
-
_deindexSimpleTaggedBinding(
|
|
125
|
+
_deindexSimpleTaggedBinding(tokenKey, binding) {
|
|
126
126
|
const slot = binding.slot;
|
|
127
127
|
if (slot.name !== void 0 || slot.tags.length !== 1 || binding.predicate !== void 0) return;
|
|
128
128
|
const [tagKey, tagValue] = slot.tags[0];
|
|
129
|
-
const byTagKey = this._simpleTagged.get(
|
|
129
|
+
const byTagKey = this._simpleTagged.get(tokenKey);
|
|
130
130
|
if (byTagKey === void 0) return;
|
|
131
131
|
const byTagValue = byTagKey.get(tagKey);
|
|
132
132
|
if (byTagValue === void 0) return;
|
|
@@ -134,7 +134,7 @@ var BindingRegistry = class {
|
|
|
134
134
|
byTagValue.delete(tagValue);
|
|
135
135
|
if (byTagValue.size === 0) {
|
|
136
136
|
byTagKey.delete(tagKey);
|
|
137
|
-
if (byTagKey.size === 0) this._simpleTagged.delete(
|
|
137
|
+
if (byTagKey.size === 0) this._simpleTagged.delete(tokenKey);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -144,38 +144,38 @@ var BindingRegistry = class {
|
|
|
144
144
|
const hasConstraint = slot.name !== void 0 || slot.tags.length > 0;
|
|
145
145
|
return hasPredicate && !hasConstraint;
|
|
146
146
|
}
|
|
147
|
-
_indexSimpleNamedBinding(
|
|
147
|
+
_indexSimpleNamedBinding(tokenKey, binding) {
|
|
148
148
|
const slot = binding.slot;
|
|
149
149
|
if (slot.name === void 0 || slot.tags.length > 0) return;
|
|
150
|
-
let bindingsByName = this._simpleNamed.get(
|
|
150
|
+
let bindingsByName = this._simpleNamed.get(tokenKey);
|
|
151
151
|
if (bindingsByName === void 0) {
|
|
152
152
|
bindingsByName = /* @__PURE__ */ new Map();
|
|
153
|
-
this._simpleNamed.set(
|
|
153
|
+
this._simpleNamed.set(tokenKey, bindingsByName);
|
|
154
154
|
}
|
|
155
155
|
bindingsByName.set(slot.name, binding);
|
|
156
156
|
}
|
|
157
|
-
_deindexSimpleNamedBinding(
|
|
157
|
+
_deindexSimpleNamedBinding(tokenKey, binding) {
|
|
158
158
|
const slot = binding.slot;
|
|
159
159
|
if (slot.name === void 0 || slot.tags.length > 0) return;
|
|
160
|
-
const bindingsByName = this._simpleNamed.get(
|
|
160
|
+
const bindingsByName = this._simpleNamed.get(tokenKey);
|
|
161
161
|
if (bindingsByName === void 0) return;
|
|
162
162
|
if (bindingsByName.get(slot.name)?.id === binding.id) {
|
|
163
163
|
bindingsByName.delete(slot.name);
|
|
164
|
-
if (bindingsByName.size === 0) this._simpleNamed.delete(
|
|
164
|
+
if (bindingsByName.size === 0) this._simpleNamed.delete(tokenKey);
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
_refreshFastDefaultForToken(
|
|
168
|
-
const bindingsForToken = this._bindings.get(
|
|
167
|
+
_refreshFastDefaultForToken(tokenKey) {
|
|
168
|
+
const bindingsForToken = this._bindings.get(tokenKey);
|
|
169
169
|
if (bindingsForToken === void 0 || bindingsForToken.length !== 1) {
|
|
170
|
-
this._fastDefault.delete(
|
|
170
|
+
this._fastDefault.delete(tokenKey);
|
|
171
171
|
return;
|
|
172
172
|
}
|
|
173
173
|
const onlyBinding = bindingsForToken[0];
|
|
174
174
|
if (!(onlyBinding.slot.name === void 0 && onlyBinding.slot.tags.length === 0) || onlyBinding.predicate !== void 0) {
|
|
175
|
-
this._fastDefault.delete(
|
|
175
|
+
this._fastDefault.delete(tokenKey);
|
|
176
176
|
return;
|
|
177
177
|
}
|
|
178
|
-
this._fastDefault.set(
|
|
178
|
+
this._fastDefault.set(tokenKey, onlyBinding);
|
|
179
179
|
}
|
|
180
180
|
};
|
|
181
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,6 @@
|
|
|
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
4
|
import { Binding } from "./binding.mjs";
|
|
5
5
|
import { BindingRegistry } from "./registry.mjs";
|
|
6
6
|
import { ScopeManager } from "./scope.mjs";
|
|
@@ -47,22 +47,22 @@ declare class DependencyResolver {
|
|
|
47
47
|
* Mirrors {@link DependencyResolver.resolveAll} candidate selection only (no instantiation).
|
|
48
48
|
*/
|
|
49
49
|
peekCandidateBindingsForValidate(token: Token<unknown> | Constructor, hint: ResolveOptions | undefined): Array<Binding>;
|
|
50
|
-
resolveFromContext<const Value>(token: Token<Value> | Constructor<Value>, resolutionPath: Array<string>,
|
|
51
|
-
resolve<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>,
|
|
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;
|
|
52
52
|
private _resolveBinding;
|
|
53
53
|
private _instantiateSync;
|
|
54
54
|
private _resolveClassDeps;
|
|
55
55
|
private _resolveDescriptorDeps;
|
|
56
|
-
resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>,
|
|
57
|
-
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>,
|
|
58
|
-
resolveAsyncFromContext<const Value>(token: Token<Value> | Constructor<Value>, resolutionPath: Array<string>,
|
|
59
|
-
resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<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>;
|
|
60
60
|
private _resolveBindingAsync;
|
|
61
61
|
private _instantiateAsync;
|
|
62
62
|
private _resolveClassDepsAsync;
|
|
63
63
|
private _resolveDescriptorDepsAsync;
|
|
64
|
-
resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<string>,
|
|
65
|
-
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, resolutionPath: Array<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>>;
|
|
66
66
|
private _getAllBindingsFromChain;
|
|
67
67
|
private _getSimpleNamedBindingsFromChain;
|
|
68
68
|
private _getAvailableSlots;
|
|
@@ -79,7 +79,7 @@ declare class DependencyResolver {
|
|
|
79
79
|
private _resolveTransientDynamicAsyncSlow;
|
|
80
80
|
private _resolveCandidateSync;
|
|
81
81
|
private _resolveCandidateAsync;
|
|
82
|
-
private
|
|
82
|
+
private _getResolutionFrame;
|
|
83
83
|
private _needsActivation;
|
|
84
84
|
private _refreshClassPostConstructCache;
|
|
85
85
|
private _requiresResolutionContext;
|