@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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MissingContainerContextError } from "../errors.mjs";
|
|
1
|
+
import { InternalError, MissingContainerContextError } from "../errors.mjs";
|
|
2
2
|
import { getActiveContainer } from "../environment.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { INJECT_ACCESSOR_KEY } from "../metadata/metadata-keys.mjs";
|
|
3
|
+
import { injectionSlotToResolveOptions } from "../resolve-options.mjs";
|
|
4
|
+
import { INJECT_ACCESSOR_KEY, accessorMetadataByMetadataObjectMap } from "../metadata/metadata-keys.mjs";
|
|
5
5
|
//#region src/decorators/inject.ts
|
|
6
6
|
/**
|
|
7
7
|
* @since 0.3.16-canary.0
|
|
@@ -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,
|
|
@@ -54,9 +54,9 @@ function materializeInjectionDescriptor(dep) {
|
|
|
54
54
|
};
|
|
55
55
|
return base;
|
|
56
56
|
}
|
|
57
|
-
function buildInjectionDescriptor(
|
|
57
|
+
function buildInjectionDescriptor(token, options) {
|
|
58
58
|
const base = {
|
|
59
|
-
token
|
|
59
|
+
token,
|
|
60
60
|
optional: false,
|
|
61
61
|
multi: false
|
|
62
62
|
};
|
|
@@ -78,23 +78,25 @@ function buildInjectionDescriptor(t, options) {
|
|
|
78
78
|
/**
|
|
79
79
|
* @since 0.3.16-canary.0
|
|
80
80
|
*/
|
|
81
|
-
function inject(
|
|
82
|
-
const descriptor = buildInjectionDescriptor(
|
|
81
|
+
function inject(token, options) {
|
|
82
|
+
const descriptor = buildInjectionDescriptor(token, options);
|
|
83
83
|
const decoratorFn = (_target, context) => {
|
|
84
|
+
if (context.static === true) throw new InternalError("@inject() on static accessors is not supported; only instance accessors participate in runWithContainer-based property injection.");
|
|
84
85
|
const meta = context.metadata;
|
|
85
86
|
if (!Array.isArray(meta[INJECT_ACCESSOR_KEY])) meta[INJECT_ACCESSOR_KEY] = [];
|
|
86
87
|
meta[INJECT_ACCESSOR_KEY].push({
|
|
87
88
|
key: context.name,
|
|
88
89
|
descriptor
|
|
89
90
|
});
|
|
91
|
+
accessorMetadataByMetadataObjectMap.set(context.metadata, meta[INJECT_ACCESSOR_KEY]);
|
|
90
92
|
context.addInitializer(function() {
|
|
91
93
|
const container = getActiveContainer();
|
|
92
94
|
if (container === void 0) throw new MissingContainerContextError(String(context.name));
|
|
93
|
-
const hint = options === void 0 ? void 0 :
|
|
95
|
+
const hint = options === void 0 ? void 0 : injectionSlotToResolveOptions({
|
|
94
96
|
...options.name !== void 0 ? { name: options.name } : {},
|
|
95
97
|
...options.tags !== void 0 ? { tags: options.tags } : {}
|
|
96
98
|
});
|
|
97
|
-
const value = descriptor.optional ? container.resolveOptional(
|
|
99
|
+
const value = descriptor.optional ? container.resolveOptional(token, hint) : container.resolve(token, hint);
|
|
98
100
|
context.access.set(this, value);
|
|
99
101
|
});
|
|
100
102
|
return {};
|
|
@@ -112,9 +114,9 @@ function inject(t, options) {
|
|
|
112
114
|
/**
|
|
113
115
|
* @since 0.3.16-canary.0
|
|
114
116
|
*/
|
|
115
|
-
function optional(
|
|
117
|
+
function optional(token, options) {
|
|
116
118
|
const base = {
|
|
117
|
-
token
|
|
119
|
+
token,
|
|
118
120
|
optional: true,
|
|
119
121
|
multi: false
|
|
120
122
|
};
|
|
@@ -136,9 +138,9 @@ function optional(t, options) {
|
|
|
136
138
|
/**
|
|
137
139
|
* @since 0.3.16-canary.0
|
|
138
140
|
*/
|
|
139
|
-
function injectAll(
|
|
141
|
+
function injectAll(token, options) {
|
|
140
142
|
const base = {
|
|
141
|
-
token
|
|
143
|
+
token,
|
|
142
144
|
optional: false,
|
|
143
145
|
multi: true
|
|
144
146
|
};
|
|
@@ -27,6 +27,6 @@ interface InjectableOptions {
|
|
|
27
27
|
/**
|
|
28
28
|
* @since 0.3.16-canary.0
|
|
29
29
|
*/
|
|
30
|
-
declare function injectable(deps?:
|
|
30
|
+
declare function injectable(deps?: ReadonlyArray<InjectableDependency>, options?: InjectableOptions): (target: unknown, context: ClassDecoratorContext) => void;
|
|
31
31
|
//#endregion
|
|
32
32
|
export { AutoRegisterRegistry, type InjectableDependency, InjectableOptions, createAutoRegisterRegistry, injectable };
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { INJECTABLE_KEY, constructorMetadataMap } from "../metadata/metadata-keys.mjs";
|
|
1
|
+
import { INJECTABLE_KEY, INJECT_ACCESSOR_KEY, accessorMetadataByConstructorMap, constructorMetadataMap } from "../metadata/metadata-keys.mjs";
|
|
2
2
|
import { normalizeToDescriptor } from "./inject.mjs";
|
|
3
3
|
//#region src/decorators/injectable.ts
|
|
4
4
|
/**
|
|
5
5
|
* @since 0.3.16-canary.0
|
|
6
6
|
*/
|
|
7
7
|
function createAutoRegisterRegistry() {
|
|
8
|
-
const
|
|
8
|
+
const _registeredEntries = [];
|
|
9
9
|
return {
|
|
10
10
|
register(target, scope) {
|
|
11
|
-
|
|
11
|
+
_registeredEntries.push({
|
|
12
12
|
target,
|
|
13
13
|
scope
|
|
14
14
|
});
|
|
15
15
|
},
|
|
16
16
|
entries() {
|
|
17
|
-
return
|
|
17
|
+
return _registeredEntries;
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
}
|
|
@@ -23,33 +23,37 @@ function createAutoRegisterRegistry() {
|
|
|
23
23
|
*/
|
|
24
24
|
function injectable(deps, options) {
|
|
25
25
|
return function(target, context) {
|
|
26
|
-
const
|
|
27
|
-
const descriptor = normalizeToDescriptor(
|
|
28
|
-
const
|
|
26
|
+
const constructorMetadata = { params: (deps ?? []).map((dependency, index) => {
|
|
27
|
+
const descriptor = normalizeToDescriptor(dependency);
|
|
28
|
+
const baseParameterMetadata = {
|
|
29
29
|
index,
|
|
30
30
|
token: descriptor.token,
|
|
31
31
|
optional: descriptor.optional,
|
|
32
32
|
multi: descriptor.multi
|
|
33
33
|
};
|
|
34
34
|
if (descriptor.name !== void 0 && descriptor.tags !== void 0) return {
|
|
35
|
-
...
|
|
35
|
+
...baseParameterMetadata,
|
|
36
36
|
name: descriptor.name,
|
|
37
37
|
tags: descriptor.tags
|
|
38
38
|
};
|
|
39
39
|
if (descriptor.name !== void 0) return {
|
|
40
|
-
...
|
|
40
|
+
...baseParameterMetadata,
|
|
41
41
|
name: descriptor.name
|
|
42
42
|
};
|
|
43
43
|
if (descriptor.tags !== void 0) return {
|
|
44
|
-
...
|
|
44
|
+
...baseParameterMetadata,
|
|
45
45
|
tags: descriptor.tags
|
|
46
46
|
};
|
|
47
|
-
return
|
|
47
|
+
return baseParameterMetadata;
|
|
48
48
|
}) };
|
|
49
|
-
constructorMetadataMap.set(target,
|
|
49
|
+
constructorMetadataMap.set(target, constructorMetadata);
|
|
50
50
|
try {
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
51
|
+
const metadata = context.metadata;
|
|
52
|
+
if (metadata !== null && typeof metadata === "object") {
|
|
53
|
+
const accessorList = metadata[INJECT_ACCESSOR_KEY];
|
|
54
|
+
if (Array.isArray(accessorList) && accessorList.length > 0) accessorMetadataByConstructorMap.set(target, accessorList);
|
|
55
|
+
metadata[INJECTABLE_KEY] = constructorMetadata;
|
|
56
|
+
}
|
|
53
57
|
} catch {}
|
|
54
58
|
if (options?.autoRegister !== void 0) {
|
|
55
59
|
const scope = options.scope ?? "transient";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InternalError } from "../errors.mjs";
|
|
1
2
|
import { LIFECYCLE_KEY, lifecycleByConstructorMetadataMap, lifecycleMetadataMap } from "../metadata/metadata-keys.mjs";
|
|
2
3
|
//#region src/decorators/lifecycle-decorators.ts
|
|
3
4
|
function appendUniqueMethod(metadata, phase, methodName) {
|
|
@@ -25,6 +26,7 @@ function registerByConstructor(target, phase, methodName) {
|
|
|
25
26
|
*/
|
|
26
27
|
function postConstruct() {
|
|
27
28
|
return function(target, context) {
|
|
29
|
+
if (context.static === true) throw new InternalError("@postConstruct() applies to instance methods only; static methods are not invoked during instance lifecycle.");
|
|
28
30
|
const methodName = String(context.name);
|
|
29
31
|
registerByConstructor(target, "postConstruct", methodName);
|
|
30
32
|
const existing = lifecycleMetadataMap.get(context.metadata);
|
|
@@ -61,6 +63,7 @@ function postConstruct() {
|
|
|
61
63
|
*/
|
|
62
64
|
function preDestroy() {
|
|
63
65
|
return function(target, context) {
|
|
66
|
+
if (context.static === true) throw new InternalError("@preDestroy() applies to instance methods only; static methods are not invoked during instance teardown.");
|
|
64
67
|
const methodName = String(context.name);
|
|
65
68
|
registerByConstructor(target, "preDestroy", methodName);
|
|
66
69
|
const existing = lifecycleMetadataMap.get(context.metadata);
|
|
@@ -25,8 +25,8 @@ interface GraphEdge {
|
|
|
25
25
|
* @since 0.3.16-canary.0
|
|
26
26
|
*/
|
|
27
27
|
interface ContainerGraphJson {
|
|
28
|
-
readonly nodes:
|
|
29
|
-
readonly edges:
|
|
28
|
+
readonly nodes: ReadonlyArray<GraphNode>;
|
|
29
|
+
readonly edges: ReadonlyArray<GraphEdge>;
|
|
30
30
|
readonly includesParent: boolean;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -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,25 +31,25 @@ 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: 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: 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;
|
|
43
43
|
resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Promise<Value | undefined>;
|
|
44
|
-
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Value
|
|
45
|
-
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Promise<Value
|
|
44
|
+
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Array<Value>;
|
|
45
|
+
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint?: ResolveOptions): Promise<Array<Value>>;
|
|
46
46
|
}
|
|
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/errors.d.mts
CHANGED
|
@@ -30,8 +30,8 @@ declare class NoMatchingBindingError extends DiError {
|
|
|
30
30
|
readonly code = "NO_MATCHING_BINDING";
|
|
31
31
|
readonly tokenName: string;
|
|
32
32
|
readonly hint: ResolveOptions;
|
|
33
|
-
readonly availableSlots: string
|
|
34
|
-
constructor(tokenName: string, hint: ResolveOptions, availableSlots: string
|
|
33
|
+
readonly availableSlots: Array<string>;
|
|
34
|
+
constructor(tokenName: string, hint: ResolveOptions, availableSlots: Array<string>);
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* @since 0.3.16-canary.0
|
|
@@ -39,16 +39,16 @@ declare class NoMatchingBindingError extends DiError {
|
|
|
39
39
|
declare class AmbiguousBindingError extends DiError {
|
|
40
40
|
readonly code = "AMBIGUOUS_BINDING";
|
|
41
41
|
readonly tokenName: string;
|
|
42
|
-
readonly candidateIds:
|
|
43
|
-
constructor(tokenName: string, candidateIds:
|
|
42
|
+
readonly candidateIds: ReadonlyArray<BindingIdentifier>;
|
|
43
|
+
constructor(tokenName: string, candidateIds: ReadonlyArray<BindingIdentifier>);
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* @since 0.3.16-canary.0
|
|
47
47
|
*/
|
|
48
48
|
declare class CircularDependencyError extends DiError {
|
|
49
49
|
readonly code = "CIRCULAR_DEPENDENCY";
|
|
50
|
-
readonly cycle: string
|
|
51
|
-
constructor(cycle: string
|
|
50
|
+
readonly cycle: Array<string>;
|
|
51
|
+
constructor(cycle: Array<string>);
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* @since 0.3.16-canary.0
|
|
@@ -75,7 +75,7 @@ interface ScopeViolationDetails {
|
|
|
75
75
|
readonly consumerScope: BindingScope;
|
|
76
76
|
readonly dependencyToken: string;
|
|
77
77
|
readonly dependencyScope: BindingScope;
|
|
78
|
-
readonly path: string
|
|
78
|
+
readonly path: Array<string>;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* @since 0.3.16-canary.0
|
|
@@ -139,5 +139,15 @@ declare class DisposedContainerError extends DiError {
|
|
|
139
139
|
readonly code = "DISPOSED_CONTAINER";
|
|
140
140
|
constructor();
|
|
141
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* @since 0.3.16-canary.0
|
|
144
|
+
*/
|
|
145
|
+
declare class AsyncActivationError extends DiError {
|
|
146
|
+
readonly code = "ASYNC_ACTIVATION";
|
|
147
|
+
readonly tokenName: string;
|
|
148
|
+
readonly hookKind: "postConstruct" | "onActivation";
|
|
149
|
+
readonly methodName: string | undefined;
|
|
150
|
+
constructor(tokenName: string, hookKind: "postConstruct" | "onActivation", methodName?: string);
|
|
151
|
+
}
|
|
142
152
|
//#endregion
|
|
143
|
-
export { AmbiguousBindingError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationDetails, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError };
|
|
153
|
+
export { AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationDetails, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError };
|
package/dist/errors.mjs
CHANGED
|
@@ -177,5 +177,21 @@ var DisposedContainerError = class extends DiError {
|
|
|
177
177
|
super("Cannot perform operations on a disposed container.");
|
|
178
178
|
}
|
|
179
179
|
};
|
|
180
|
+
/**
|
|
181
|
+
* @since 0.3.16-canary.0
|
|
182
|
+
*/
|
|
183
|
+
var AsyncActivationError = class extends DiError {
|
|
184
|
+
code = "ASYNC_ACTIVATION";
|
|
185
|
+
tokenName;
|
|
186
|
+
hookKind;
|
|
187
|
+
methodName;
|
|
188
|
+
constructor(tokenName, hookKind, methodName) {
|
|
189
|
+
const detail = hookKind === "postConstruct" ? `@postConstruct method '${methodName ?? ""}' returned a Promise` : `onActivation for '${tokenName}' returned a Promise`;
|
|
190
|
+
super(`${detail}. Use resolveAsync() instead.`);
|
|
191
|
+
this.tokenName = tokenName;
|
|
192
|
+
this.hookKind = hookKind;
|
|
193
|
+
this.methodName = methodName;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
180
196
|
//#endregion
|
|
181
|
-
export { AmbiguousBindingError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError };
|
|
197
|
+
export { AmbiguousBindingError, AsyncActivationError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
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";
|
|
7
|
-
import {
|
|
7
|
+
import { whenAnyAncestorIs, whenAnyAncestorNamed, whenAnyAncestorTagged, whenAnyAncestorTaggedAll, whenNoAncestorIs, whenNoParentIs, whenParentIs, whenParentNamed, whenParentTagged, whenParentTaggedAll } from "./constraints.mjs";
|
|
8
|
+
import { AsyncModule, AsyncModuleBuilder, Module, ModuleBuilder, SyncModule, isSyncModule } from "./module.mjs";
|
|
8
9
|
import { BindingSnapshot, ContainerSnapshot } from "./inspector.mjs";
|
|
9
10
|
import { MetadataReader, MutableLifecycleMetadata } from "./metadata/metadata-types.mjs";
|
|
10
11
|
import { ContainerGraphJson, GraphEdge, GraphNode, GraphOptions } from "./dependency-graph.mjs";
|
|
11
12
|
import { AutoRegisterRegistry, InjectableOptions, createAutoRegisterRegistry, injectable } from "./decorators/injectable.mjs";
|
|
12
13
|
import { Container, ContainerStatic } from "./container.mjs";
|
|
13
14
|
import { postConstruct, preDestroy } from "./decorators/lifecycle-decorators.mjs";
|
|
14
|
-
import { AmbiguousBindingError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationDetails, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError } from "./errors.mjs";
|
|
15
|
-
import {
|
|
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 { bindingSlotToResolveOptions, injectionSlotToResolveOptions } from "./resolve-options.mjs";
|
|
16
17
|
import { MetadataReaderToken } from "./metadata/metadata-reader-token.mjs";
|
|
17
|
-
export { type ActivationHandler, type AliasBindingBuilder, AmbiguousBindingError, 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
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { effectiveBindingScope } from "./binding-scope.mjs";
|
|
2
|
-
import { AmbiguousBindingError, AsyncDeactivationError, AsyncModuleLoadError, AsyncResolutionError, CircularDependencyError, DiError, DisposedContainerError, InternalError, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, NoMatchingBindingError, RebindUnboundTokenError, ScopeViolationError, SyncDisposalNotSupportedError, TokenNotBoundError } from "./errors.mjs";
|
|
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
|
-
import {
|
|
4
|
+
import { whenAnyAncestorIs, whenAnyAncestorNamed, whenAnyAncestorTagged, whenAnyAncestorTaggedAll, whenNoAncestorIs, whenNoParentIs, whenParentIs, whenParentNamed, whenParentTagged, whenParentTaggedAll } from "./constraints.mjs";
|
|
5
|
+
import { bindingSlotToResolveOptions, injectionSlotToResolveOptions } from "./resolve-options.mjs";
|
|
5
6
|
import { MetadataReaderToken } from "./metadata/metadata-reader-token.mjs";
|
|
6
7
|
import { inject, injectAll, isInjectionDescriptor, optional } from "./decorators/inject.mjs";
|
|
7
|
-
import { AsyncModule, Module, SyncModule } from "./module.mjs";
|
|
8
|
+
import { AsyncModule, Module, SyncModule, isSyncModule } from "./module.mjs";
|
|
8
9
|
import { Container } from "./container.mjs";
|
|
9
10
|
import { createAutoRegisterRegistry, injectable } from "./decorators/injectable.mjs";
|
|
10
11
|
import { postConstruct, preDestroy } from "./decorators/lifecycle-decorators.mjs";
|
|
11
|
-
export { AmbiguousBindingError, 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.d.mts
CHANGED
|
@@ -22,8 +22,7 @@ interface BindingSnapshot {
|
|
|
22
22
|
* @since 0.3.16-canary.0
|
|
23
23
|
*/
|
|
24
24
|
interface ContainerSnapshot {
|
|
25
|
-
readonly ownBindings:
|
|
26
|
-
readonly bindings: readonly BindingSnapshot[];
|
|
25
|
+
readonly ownBindings: ReadonlyArray<BindingSnapshot>;
|
|
27
26
|
readonly cachedSingletonCount: number;
|
|
28
27
|
readonly hasParent: boolean;
|
|
29
28
|
readonly isDisposed: boolean;
|
|
@@ -38,7 +37,7 @@ declare class Inspector {
|
|
|
38
37
|
private readonly _isDisposed;
|
|
39
38
|
constructor(_registry: BindingRegistry, _scope: ScopeManager, _hasParent: boolean, _isDisposed: () => boolean);
|
|
40
39
|
inspect(): ContainerSnapshot;
|
|
41
|
-
lookupBindings<Value>(token: Token<Value> | Constructor<Value>):
|
|
40
|
+
lookupBindings<Value>(token: Token<Value> | Constructor<Value>): ReadonlyArray<BindingSnapshot>;
|
|
42
41
|
has(token: Token<unknown> | Constructor, hint?: ResolveOptions, parentHas?: () => boolean): boolean;
|
|
43
42
|
hasOwn(token: Token<unknown> | Constructor, hint?: ResolveOptions): boolean;
|
|
44
43
|
private allBindingSnapshots;
|