@codefast/di 0.5.0-canary.5 → 0.5.0-canary.7
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 +65 -0
- package/README.md +73 -496
- package/dist/binding.d.ts +211 -0
- package/dist/binding.d.ts.map +1 -0
- package/dist/binding.js +46 -0
- package/dist/binding.js.map +1 -0
- package/dist/{constructor-type.d.mts → constructor-type.d.ts} +3 -5
- package/dist/constructor-type.d.ts.map +1 -0
- package/dist/constructor-type.js +2 -0
- package/dist/constructor-type.js.map +1 -0
- package/dist/container/binding-builders.d.ts +35 -0
- package/dist/container/binding-builders.d.ts.map +1 -0
- package/dist/container/binding-builders.js +247 -0
- package/dist/container/binding-builders.js.map +1 -0
- package/dist/container/container.d.ts +58 -0
- package/dist/container/container.d.ts.map +1 -0
- package/dist/container/container.js +641 -0
- package/dist/container/container.js.map +1 -0
- package/dist/decorators/inject.d.ts +57 -0
- package/dist/decorators/inject.d.ts.map +1 -0
- package/dist/decorators/inject.js +145 -0
- package/dist/decorators/inject.js.map +1 -0
- package/dist/decorators/injectable.d.ts +29 -0
- package/dist/decorators/injectable.d.ts.map +1 -0
- package/dist/decorators/injectable.js +53 -0
- package/dist/decorators/injectable.js.map +1 -0
- package/dist/decorators/lifecycle-decorators.d.ts +9 -0
- package/dist/decorators/lifecycle-decorators.d.ts.map +1 -0
- package/dist/decorators/lifecycle-decorators.js +40 -0
- package/dist/decorators/lifecycle-decorators.js.map +1 -0
- package/dist/errors.d.ts +150 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +197 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/introspection/dependency-graph.d.ts +40 -0
- package/dist/introspection/dependency-graph.d.ts.map +1 -0
- package/dist/introspection/dependency-graph.js +66 -0
- package/dist/introspection/dependency-graph.js.map +1 -0
- package/dist/introspection/graph-adapters/cytoscape.d.ts +33 -0
- package/dist/introspection/graph-adapters/cytoscape.d.ts.map +1 -0
- package/dist/introspection/graph-adapters/cytoscape.js +30 -0
- package/dist/introspection/graph-adapters/cytoscape.js.map +1 -0
- package/dist/introspection/graph-adapters/dot.d.ts +6 -0
- package/dist/introspection/graph-adapters/dot.d.ts.map +1 -0
- package/dist/introspection/graph-adapters/dot.js +18 -0
- package/dist/introspection/graph-adapters/dot.js.map +1 -0
- package/dist/introspection/graph-adapters/reactflow.d.ts +38 -0
- package/dist/introspection/graph-adapters/reactflow.d.ts.map +1 -0
- package/dist/introspection/graph-adapters/reactflow.js +33 -0
- package/dist/introspection/graph-adapters/reactflow.js.map +1 -0
- package/dist/introspection/inspector.d.ts +39 -0
- package/dist/introspection/inspector.d.ts.map +1 -0
- package/dist/introspection/inspector.js +82 -0
- package/dist/introspection/inspector.js.map +1 -0
- package/dist/metadata/{metadata-keys.d.mts → metadata-keys.d.ts} +5 -7
- package/dist/metadata/metadata-keys.d.ts.map +1 -0
- package/dist/metadata/metadata-keys.js +25 -0
- package/dist/metadata/metadata-keys.js.map +1 -0
- package/dist/metadata/metadata-reader-token.d.ts +7 -0
- package/dist/metadata/metadata-reader-token.d.ts.map +1 -0
- package/dist/metadata/metadata-reader-token.js +6 -0
- package/dist/metadata/metadata-reader-token.js.map +1 -0
- package/dist/metadata/metadata-types.d.ts +48 -0
- package/dist/metadata/metadata-types.d.ts.map +1 -0
- package/dist/metadata/metadata-types.js +2 -0
- package/dist/metadata/metadata-types.js.map +1 -0
- package/dist/metadata/symbol-metadata-reader.d.ts +20 -0
- package/dist/metadata/symbol-metadata-reader.d.ts.map +1 -0
- package/dist/metadata/symbol-metadata-reader.js +34 -0
- package/dist/metadata/symbol-metadata-reader.js.map +1 -0
- package/dist/module.d.ts +67 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +54 -0
- package/dist/module.js.map +1 -0
- package/dist/registry.d.ts +33 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +249 -0
- package/dist/registry.js.map +1 -0
- package/dist/resolution/binding-scope.d.ts +10 -0
- package/dist/resolution/binding-scope.d.ts.map +1 -0
- package/dist/resolution/binding-scope.js +24 -0
- package/dist/resolution/binding-scope.js.map +1 -0
- package/dist/resolution/binding-select.d.ts +16 -0
- package/dist/resolution/binding-select.d.ts.map +1 -0
- package/dist/resolution/binding-select.js +143 -0
- package/dist/resolution/binding-select.js.map +1 -0
- package/dist/resolution/constraints.d.ts +51 -0
- package/dist/resolution/constraints.d.ts.map +1 -0
- package/dist/resolution/constraints.js +88 -0
- package/dist/resolution/constraints.js.map +1 -0
- package/dist/resolution/environment.d.ts +47 -0
- package/dist/resolution/environment.d.ts.map +1 -0
- package/dist/resolution/environment.js +100 -0
- package/dist/resolution/environment.js.map +1 -0
- package/dist/resolution/instantiation-plan.d.ts +67 -0
- package/dist/resolution/instantiation-plan.d.ts.map +1 -0
- package/dist/resolution/instantiation-plan.js +163 -0
- package/dist/resolution/instantiation-plan.js.map +1 -0
- package/dist/resolution/lifecycle.d.ts +21 -0
- package/dist/resolution/lifecycle.d.ts.map +1 -0
- package/dist/resolution/lifecycle.js +178 -0
- package/dist/resolution/lifecycle.js.map +1 -0
- package/dist/resolution/resolution-path.d.ts +31 -0
- package/dist/resolution/resolution-path.d.ts.map +1 -0
- package/dist/resolution/resolution-path.js +53 -0
- package/dist/resolution/resolution-path.js.map +1 -0
- package/dist/resolution/resolve-options.d.ts +19 -0
- package/dist/resolution/resolve-options.d.ts.map +1 -0
- package/dist/resolution/resolve-options.js +32 -0
- package/dist/resolution/resolve-options.js.map +1 -0
- package/dist/resolution/resolver.d.ts +35 -0
- package/dist/resolution/resolver.d.ts.map +1 -0
- package/dist/resolution/resolver.js +1320 -0
- package/dist/resolution/resolver.js.map +1 -0
- package/dist/resolution/scope.d.ts +32 -0
- package/dist/resolution/scope.d.ts.map +1 -0
- package/dist/resolution/scope.js +76 -0
- package/dist/resolution/scope.js.map +1 -0
- package/dist/token.d.ts +23 -0
- package/dist/token.d.ts.map +1 -0
- package/dist/token.js +22 -0
- package/dist/token.js.map +1 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +143 -120
- package/src/binding.ts +38 -22
- package/src/container/binding-builders.ts +397 -0
- package/src/container/container.ts +838 -0
- package/src/decorators/inject.ts +16 -3
- package/src/decorators/injectable.ts +3 -3
- package/src/index.ts +14 -7
- package/src/{dependency-graph.ts → introspection/dependency-graph.ts} +1 -1
- package/src/{graph-adapters → introspection/graph-adapters}/cytoscape.ts +1 -1
- package/src/{graph-adapters → introspection/graph-adapters}/dot.ts +1 -1
- package/src/{graph-adapters → introspection/graph-adapters}/reactflow.ts +13 -2
- package/src/{inspector.ts → introspection/inspector.ts} +26 -21
- package/src/metadata/symbol-metadata-reader.ts +4 -4
- package/src/module.ts +14 -6
- package/src/registry.ts +115 -61
- package/src/{binding-select.ts → resolution/binding-select.ts} +16 -3
- package/src/{environment.ts → resolution/environment.ts} +35 -35
- package/src/resolution/instantiation-plan.ts +240 -0
- package/src/{lifecycle.ts → resolution/lifecycle.ts} +20 -13
- package/src/resolution/resolution-path.ts +77 -0
- package/src/resolution/resolver.ts +1755 -0
- package/src/{scope.ts → resolution/scope.ts} +35 -18
- package/src/token.ts +0 -3
- package/dist/binding-scope.d.mts +0 -13
- package/dist/binding-scope.mjs +0 -21
- package/dist/binding-select.d.mts +0 -19
- package/dist/binding-select.mjs +0 -72
- package/dist/binding.d.mts +0 -191
- package/dist/binding.mjs +0 -36
- package/dist/constraints.d.mts +0 -55
- package/dist/constraints.mjs +0 -87
- package/dist/constructor-type.mjs +0 -1
- package/dist/container.d.mts +0 -62
- package/dist/container.mjs +0 -741
- package/dist/decorators/inject.d.mts +0 -49
- package/dist/decorators/inject.mjs +0 -136
- package/dist/decorators/injectable.d.mts +0 -32
- package/dist/decorators/injectable.mjs +0 -57
- package/dist/decorators/lifecycle-decorators.d.mts +0 -11
- package/dist/decorators/lifecycle-decorators.mjs +0 -38
- package/dist/dependency-graph.d.mts +0 -43
- package/dist/dependency-graph.mjs +0 -63
- package/dist/environment.d.mts +0 -55
- package/dist/environment.mjs +0 -98
- package/dist/errors.d.mts +0 -153
- package/dist/errors.mjs +0 -197
- package/dist/graph-adapters/cytoscape.d.mts +0 -36
- package/dist/graph-adapters/cytoscape.mjs +0 -26
- package/dist/graph-adapters/dot.d.mts +0 -9
- package/dist/graph-adapters/dot.mjs +0 -20
- package/dist/graph-adapters/reactflow.d.mts +0 -41
- package/dist/graph-adapters/reactflow.mjs +0 -29
- package/dist/index.d.mts +0 -18
- package/dist/index.mjs +0 -12
- package/dist/inspector.d.mts +0 -48
- package/dist/inspector.mjs +0 -71
- package/dist/lifecycle.d.mts +0 -25
- package/dist/lifecycle.mjs +0 -118
- package/dist/metadata/metadata-keys.mjs +0 -27
- package/dist/metadata/metadata-reader-token.d.mts +0 -10
- package/dist/metadata/metadata-reader-token.mjs +0 -8
- package/dist/metadata/metadata-types.d.mts +0 -51
- package/dist/metadata/metadata-types.mjs +0 -1
- package/dist/metadata/symbol-metadata-reader.d.mts +0 -23
- package/dist/metadata/symbol-metadata-reader.mjs +0 -29
- package/dist/module.d.mts +0 -62
- package/dist/module.mjs +0 -42
- package/dist/registry.d.mts +0 -45
- package/dist/registry.mjs +0 -163
- package/dist/resolve-options.d.mts +0 -22
- package/dist/resolve-options.mjs +0 -28
- package/dist/resolver.d.mts +0 -94
- package/dist/resolver.mjs +0 -767
- package/dist/scope.d.mts +0 -28
- package/dist/scope.mjs +0 -58
- package/dist/token.d.mts +0 -25
- package/dist/token.mjs +0 -22
- package/dist/types.d.mts +0 -92
- package/dist/types.mjs +0 -1
- package/src/container.ts +0 -1141
- package/src/resolver.ts +0 -1626
- /package/src/{binding-scope.ts → resolution/binding-scope.ts} +0 -0
- /package/src/{constraints.ts → resolution/constraints.ts} +0 -0
- /package/src/{resolve-options.ts → resolution/resolve-options.ts} +0 -0
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Constructor } from "../constructor-type.mjs";
|
|
2
|
-
import { Token } from "../token.mjs";
|
|
3
|
-
import { BindingTag } from "../types.mjs";
|
|
4
|
-
|
|
5
|
-
//#region src/decorators/inject.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* @since 0.3.16-canary.0
|
|
8
|
-
*/
|
|
9
|
-
interface InjectOptions {
|
|
10
|
-
name?: string;
|
|
11
|
-
tags?: ReadonlyArray<BindingTag>;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* @since 0.3.16-canary.0
|
|
15
|
-
*/
|
|
16
|
-
interface InjectionDescriptor<Value = unknown> {
|
|
17
|
-
readonly token: Token<Value> | Constructor<Value>;
|
|
18
|
-
readonly optional: boolean;
|
|
19
|
-
readonly multi: boolean;
|
|
20
|
-
readonly name?: string;
|
|
21
|
-
readonly tags?: ReadonlyArray<BindingTag>;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @since 0.3.16-canary.0
|
|
25
|
-
*/
|
|
26
|
-
type InjectableDependency<Value = unknown> = Token<Value> | Constructor<Value> | InjectionDescriptor<Value>;
|
|
27
|
-
/**
|
|
28
|
-
* @since 0.3.16-canary.0
|
|
29
|
-
*/
|
|
30
|
-
declare function isInjectionDescriptor(value: unknown): value is InjectionDescriptor;
|
|
31
|
-
/**
|
|
32
|
-
* @since 0.3.16-canary.0
|
|
33
|
-
*/
|
|
34
|
-
declare function normalizeToDescriptor(dependency: InjectableDependency): InjectionDescriptor;
|
|
35
|
-
type ClassAccessorDecorator<This, Value> = (target: ClassAccessorDecoratorTarget<This, Value>, context: ClassAccessorDecoratorContext<This, Value>) => ClassAccessorDecoratorResult<This, Value> | void;
|
|
36
|
-
/**
|
|
37
|
-
* @since 0.3.16-canary.0
|
|
38
|
-
*/
|
|
39
|
-
declare function inject<const Value>(token: Token<Value> | Constructor<Value>, options?: InjectOptions): InjectionDescriptor<Value> & ClassAccessorDecorator<unknown, Value>;
|
|
40
|
-
/**
|
|
41
|
-
* @since 0.3.16-canary.0
|
|
42
|
-
*/
|
|
43
|
-
declare function optional<const Value>(token: Token<Value> | Constructor<Value>, options?: InjectOptions): InjectionDescriptor<Value | undefined>;
|
|
44
|
-
/**
|
|
45
|
-
* @since 0.3.16-canary.0
|
|
46
|
-
*/
|
|
47
|
-
declare function injectAll<const Value>(token: Token<Value> | Constructor<Value>, options?: InjectOptions): InjectionDescriptor<Array<Value>>;
|
|
48
|
-
//#endregion
|
|
49
|
-
export { InjectOptions, InjectableDependency, InjectionDescriptor, inject, injectAll, isInjectionDescriptor, normalizeToDescriptor, optional };
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { InternalError, MissingContainerContextError } from "../errors.mjs";
|
|
2
|
-
import { getActiveContainer } from "../environment.mjs";
|
|
3
|
-
import { INJECT_ACCESSOR_KEY } from "../metadata/metadata-keys.mjs";
|
|
4
|
-
import { injectionSlotToResolveOptions } from "../resolve-options.mjs";
|
|
5
|
-
//#region src/decorators/inject.ts
|
|
6
|
-
/**
|
|
7
|
-
* @since 0.3.16-canary.0
|
|
8
|
-
*/
|
|
9
|
-
function isInjectionDescriptor(value) {
|
|
10
|
-
if (value === null || value === void 0) return false;
|
|
11
|
-
const type = typeof value;
|
|
12
|
-
if (type !== "object" && type !== "function") return false;
|
|
13
|
-
return "token" in value && "optional" in value && "multi" in value && typeof value.optional === "boolean" && typeof value.multi === "boolean";
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* @since 0.3.16-canary.0
|
|
17
|
-
*/
|
|
18
|
-
function normalizeToDescriptor(dependency) {
|
|
19
|
-
if (isInjectionDescriptor(dependency)) return materializeInjectionDescriptor(dependency);
|
|
20
|
-
return {
|
|
21
|
-
token: dependency,
|
|
22
|
-
optional: false,
|
|
23
|
-
multi: false
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Dual-role `inject()` values are functions: [[Function]].name must not be treated as a DI slot name.
|
|
28
|
-
* Only enumerable own `name` / `tags` from `Object.defineProperties` are real injection options.
|
|
29
|
-
*/
|
|
30
|
-
function materializeInjectionDescriptor(dependency) {
|
|
31
|
-
if (typeof dependency !== "function") return dependency;
|
|
32
|
-
const dualRole = dependency;
|
|
33
|
-
const base = {
|
|
34
|
-
token: dualRole.token,
|
|
35
|
-
optional: dualRole.optional,
|
|
36
|
-
multi: dualRole.multi
|
|
37
|
-
};
|
|
38
|
-
const nameDesc = Object.getOwnPropertyDescriptor(dualRole, "name");
|
|
39
|
-
const tagsDesc = Object.getOwnPropertyDescriptor(dualRole, "tags");
|
|
40
|
-
const explicitName = nameDesc?.enumerable === true && typeof nameDesc.value === "string" ? nameDesc.value : void 0;
|
|
41
|
-
const explicitTags = tagsDesc?.enumerable === true ? tagsDesc.value : void 0;
|
|
42
|
-
if (explicitName !== void 0 && explicitTags !== void 0) return {
|
|
43
|
-
...base,
|
|
44
|
-
name: explicitName,
|
|
45
|
-
tags: explicitTags
|
|
46
|
-
};
|
|
47
|
-
if (explicitName !== void 0) return {
|
|
48
|
-
...base,
|
|
49
|
-
name: explicitName
|
|
50
|
-
};
|
|
51
|
-
if (explicitTags !== void 0) return {
|
|
52
|
-
...base,
|
|
53
|
-
tags: explicitTags
|
|
54
|
-
};
|
|
55
|
-
return base;
|
|
56
|
-
}
|
|
57
|
-
function withOptions(base, options) {
|
|
58
|
-
if (options?.name !== void 0 && options.tags !== void 0) return {
|
|
59
|
-
...base,
|
|
60
|
-
name: options.name,
|
|
61
|
-
tags: options.tags
|
|
62
|
-
};
|
|
63
|
-
if (options?.name !== void 0) return {
|
|
64
|
-
...base,
|
|
65
|
-
name: options.name
|
|
66
|
-
};
|
|
67
|
-
if (options?.tags !== void 0) return {
|
|
68
|
-
...base,
|
|
69
|
-
tags: options.tags
|
|
70
|
-
};
|
|
71
|
-
return base;
|
|
72
|
-
}
|
|
73
|
-
function buildInjectionDescriptor(token, options) {
|
|
74
|
-
return withOptions({
|
|
75
|
-
token,
|
|
76
|
-
optional: false,
|
|
77
|
-
multi: false
|
|
78
|
-
}, options);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* @since 0.3.16-canary.0
|
|
82
|
-
*/
|
|
83
|
-
function inject(token, options) {
|
|
84
|
-
const descriptor = buildInjectionDescriptor(token, options);
|
|
85
|
-
const decoratorFn = (_target, context) => {
|
|
86
|
-
if (context.static) throw new InternalError("@inject() on static accessors is not supported; only instance accessors participate in runWithContainer-based property injection.");
|
|
87
|
-
const meta = context.metadata;
|
|
88
|
-
if (!Array.isArray(meta[INJECT_ACCESSOR_KEY])) meta[INJECT_ACCESSOR_KEY] = [];
|
|
89
|
-
meta[INJECT_ACCESSOR_KEY].push({
|
|
90
|
-
key: context.name,
|
|
91
|
-
descriptor
|
|
92
|
-
});
|
|
93
|
-
context.addInitializer(function() {
|
|
94
|
-
const container = getActiveContainer();
|
|
95
|
-
if (container === void 0) throw new MissingContainerContextError(String(context.name));
|
|
96
|
-
const resolveOptions = options === void 0 ? void 0 : injectionSlotToResolveOptions({
|
|
97
|
-
...options.name !== void 0 ? { name: options.name } : {},
|
|
98
|
-
...options.tags !== void 0 ? { tags: options.tags } : {}
|
|
99
|
-
});
|
|
100
|
-
const value = descriptor.optional ? container.resolveOptional(token, resolveOptions) : container.resolve(token, resolveOptions);
|
|
101
|
-
context.access.set(this, value);
|
|
102
|
-
});
|
|
103
|
-
return {};
|
|
104
|
-
};
|
|
105
|
-
const props = {};
|
|
106
|
-
for (const key of Object.keys(descriptor)) props[key] = {
|
|
107
|
-
value: descriptor[key],
|
|
108
|
-
writable: true,
|
|
109
|
-
enumerable: true,
|
|
110
|
-
configurable: true
|
|
111
|
-
};
|
|
112
|
-
Object.defineProperties(decoratorFn, props);
|
|
113
|
-
return decoratorFn;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* @since 0.3.16-canary.0
|
|
117
|
-
*/
|
|
118
|
-
function optional(token, options) {
|
|
119
|
-
return withOptions({
|
|
120
|
-
token,
|
|
121
|
-
optional: true,
|
|
122
|
-
multi: false
|
|
123
|
-
}, options);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* @since 0.3.16-canary.0
|
|
127
|
-
*/
|
|
128
|
-
function injectAll(token, options) {
|
|
129
|
-
return withOptions({
|
|
130
|
-
token,
|
|
131
|
-
optional: false,
|
|
132
|
-
multi: true
|
|
133
|
-
}, options);
|
|
134
|
-
}
|
|
135
|
-
//#endregion
|
|
136
|
-
export { inject, injectAll, isInjectionDescriptor, normalizeToDescriptor, optional };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Constructor } from "../constructor-type.mjs";
|
|
2
|
-
import { BindingScope } from "../types.mjs";
|
|
3
|
-
import { InjectableDependency } from "./inject.mjs";
|
|
4
|
-
|
|
5
|
-
//#region src/decorators/injectable.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* @since 0.3.16-canary.0
|
|
8
|
-
*/
|
|
9
|
-
interface AutoRegisterRegistry {
|
|
10
|
-
register(target: Constructor, scope: BindingScope): void;
|
|
11
|
-
entries(): ReadonlyArray<{
|
|
12
|
-
target: Constructor;
|
|
13
|
-
scope: BindingScope;
|
|
14
|
-
}>;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* @since 0.3.16-canary.0
|
|
18
|
-
*/
|
|
19
|
-
declare function createAutoRegisterRegistry(): AutoRegisterRegistry;
|
|
20
|
-
/**
|
|
21
|
-
* @since 0.3.16-canary.0
|
|
22
|
-
*/
|
|
23
|
-
interface InjectableOptions {
|
|
24
|
-
autoRegister?: AutoRegisterRegistry;
|
|
25
|
-
scope?: BindingScope;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @since 0.3.16-canary.0
|
|
29
|
-
*/
|
|
30
|
-
declare function injectable(deps?: ReadonlyArray<InjectableDependency>, options?: InjectableOptions): (target: unknown, context: ClassDecoratorContext) => void;
|
|
31
|
-
//#endregion
|
|
32
|
-
export { AutoRegisterRegistry, type InjectableDependency, InjectableOptions, createAutoRegisterRegistry, injectable };
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { INJECTABLE_KEY } from "../metadata/metadata-keys.mjs";
|
|
2
|
-
import { normalizeToDescriptor } from "./inject.mjs";
|
|
3
|
-
//#region src/decorators/injectable.ts
|
|
4
|
-
/**
|
|
5
|
-
* @since 0.3.16-canary.0
|
|
6
|
-
*/
|
|
7
|
-
function createAutoRegisterRegistry() {
|
|
8
|
-
const _registeredEntries = [];
|
|
9
|
-
return {
|
|
10
|
-
register(target, scope) {
|
|
11
|
-
_registeredEntries.push({
|
|
12
|
-
target,
|
|
13
|
-
scope
|
|
14
|
-
});
|
|
15
|
-
},
|
|
16
|
-
entries() {
|
|
17
|
-
return _registeredEntries;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* @since 0.3.16-canary.0
|
|
23
|
-
*/
|
|
24
|
-
function injectable(deps, options) {
|
|
25
|
-
return function(target, context) {
|
|
26
|
-
const parameterMetadataList = (deps ?? []).map((dependency, index) => {
|
|
27
|
-
const descriptor = normalizeToDescriptor(dependency);
|
|
28
|
-
const baseParameterMetadata = {
|
|
29
|
-
index,
|
|
30
|
-
token: descriptor.token,
|
|
31
|
-
optional: descriptor.optional,
|
|
32
|
-
multi: descriptor.multi
|
|
33
|
-
};
|
|
34
|
-
if (descriptor.name !== void 0 && descriptor.tags !== void 0) return {
|
|
35
|
-
...baseParameterMetadata,
|
|
36
|
-
name: descriptor.name,
|
|
37
|
-
tags: descriptor.tags
|
|
38
|
-
};
|
|
39
|
-
if (descriptor.name !== void 0) return {
|
|
40
|
-
...baseParameterMetadata,
|
|
41
|
-
name: descriptor.name
|
|
42
|
-
};
|
|
43
|
-
if (descriptor.tags !== void 0) return {
|
|
44
|
-
...baseParameterMetadata,
|
|
45
|
-
tags: descriptor.tags
|
|
46
|
-
};
|
|
47
|
-
return baseParameterMetadata;
|
|
48
|
-
});
|
|
49
|
-
context.metadata[INJECTABLE_KEY] = { params: parameterMetadataList };
|
|
50
|
-
if (options?.autoRegister !== void 0) {
|
|
51
|
-
const scope = options.scope ?? "transient";
|
|
52
|
-
options.autoRegister.register(target, scope);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
//#endregion
|
|
57
|
-
export { createAutoRegisterRegistry, injectable };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
//#region src/decorators/lifecycle-decorators.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* @since 0.3.16-canary.0
|
|
4
|
-
*/
|
|
5
|
-
declare function postConstruct(): (target: unknown, context: ClassMethodDecoratorContext) => void;
|
|
6
|
-
/**
|
|
7
|
-
* @since 0.3.16-canary.0
|
|
8
|
-
*/
|
|
9
|
-
declare function preDestroy(): (target: unknown, context: ClassMethodDecoratorContext) => void;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { postConstruct, preDestroy };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { InternalError } from "../errors.mjs";
|
|
2
|
-
import { LIFECYCLE_KEY } from "../metadata/metadata-keys.mjs";
|
|
3
|
-
//#region src/decorators/lifecycle-decorators.ts
|
|
4
|
-
function appendUniqueMethod(metadata, phase, methodName) {
|
|
5
|
-
if (!metadata[phase].includes(methodName)) metadata[phase].push(methodName);
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* @since 0.3.16-canary.0
|
|
9
|
-
*/
|
|
10
|
-
function postConstruct() {
|
|
11
|
-
return function(target, context) {
|
|
12
|
-
if (context.static) throw new InternalError("@postConstruct() applies to instance methods only; static methods are not invoked during instance lifecycle.");
|
|
13
|
-
const methodName = String(context.name);
|
|
14
|
-
const meta = context.metadata;
|
|
15
|
-
if (!meta[LIFECYCLE_KEY]) meta[LIFECYCLE_KEY] = {
|
|
16
|
-
postConstruct: [],
|
|
17
|
-
preDestroy: []
|
|
18
|
-
};
|
|
19
|
-
appendUniqueMethod(meta[LIFECYCLE_KEY], "postConstruct", methodName);
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* @since 0.3.16-canary.0
|
|
24
|
-
*/
|
|
25
|
-
function preDestroy() {
|
|
26
|
-
return function(target, context) {
|
|
27
|
-
if (context.static) throw new InternalError("@preDestroy() applies to instance methods only; static methods are not invoked during instance teardown.");
|
|
28
|
-
const methodName = String(context.name);
|
|
29
|
-
const meta = context.metadata;
|
|
30
|
-
if (!meta[LIFECYCLE_KEY]) meta[LIFECYCLE_KEY] = {
|
|
31
|
-
postConstruct: [],
|
|
32
|
-
preDestroy: []
|
|
33
|
-
};
|
|
34
|
-
appendUniqueMethod(meta[LIFECYCLE_KEY], "preDestroy", methodName);
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
//#endregion
|
|
38
|
-
export { postConstruct, preDestroy };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { BindingScope } from "./types.mjs";
|
|
2
|
-
import { MetadataReader } from "./metadata/metadata-types.mjs";
|
|
3
|
-
import { BindingRegistry } from "./registry.mjs";
|
|
4
|
-
|
|
5
|
-
//#region src/dependency-graph.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* @since 0.3.16-canary.0
|
|
8
|
-
*/
|
|
9
|
-
interface GraphNode {
|
|
10
|
-
readonly id: string;
|
|
11
|
-
readonly tokenName: string;
|
|
12
|
-
readonly kind: string;
|
|
13
|
-
readonly scope: BindingScope;
|
|
14
|
-
readonly fromParent: boolean;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* @since 0.3.16-canary.0
|
|
18
|
-
*/
|
|
19
|
-
interface GraphEdge {
|
|
20
|
-
readonly from: string;
|
|
21
|
-
readonly to: string;
|
|
22
|
-
readonly label?: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @since 0.3.16-canary.0
|
|
26
|
-
*/
|
|
27
|
-
interface ContainerGraphJson {
|
|
28
|
-
readonly nodes: ReadonlyArray<GraphNode>;
|
|
29
|
-
readonly edges: ReadonlyArray<GraphEdge>;
|
|
30
|
-
readonly includesParent: boolean;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @since 0.3.16-canary.0
|
|
34
|
-
*/
|
|
35
|
-
interface GraphOptions {
|
|
36
|
-
readonly includeParent?: boolean;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @since 0.3.16-canary.0
|
|
40
|
-
*/
|
|
41
|
-
declare function buildDependencyGraph(registry: BindingRegistry, metadataReader: MetadataReader, options: GraphOptions | undefined, parentRegistry?: BindingRegistry): ContainerGraphJson;
|
|
42
|
-
//#endregion
|
|
43
|
-
export { ContainerGraphJson, GraphEdge, GraphNode, GraphOptions, buildDependencyGraph };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { effectiveBindingScope } from "./binding-scope.mjs";
|
|
2
|
-
import { tokenName } from "./token.mjs";
|
|
3
|
-
//#region src/dependency-graph.ts
|
|
4
|
-
/**
|
|
5
|
-
* @since 0.3.16-canary.0
|
|
6
|
-
*/
|
|
7
|
-
function buildDependencyGraph(registry, metadataReader, options, parentRegistry) {
|
|
8
|
-
const nodes = [];
|
|
9
|
-
const edges = [];
|
|
10
|
-
const includesParent = options?.includeParent === true;
|
|
11
|
-
const addBindings = (sourceRegistry, fromParent) => {
|
|
12
|
-
for (const binding of sourceRegistry.allBindings()) {
|
|
13
|
-
const scope = effectiveBindingScope(binding);
|
|
14
|
-
nodes.push({
|
|
15
|
-
id: binding.id,
|
|
16
|
-
tokenName: tokenName(binding.token),
|
|
17
|
-
kind: binding.kind,
|
|
18
|
-
scope,
|
|
19
|
-
fromParent
|
|
20
|
-
});
|
|
21
|
-
if (binding.kind === "class") {
|
|
22
|
-
const meta = metadataReader.getConstructorMetadata(binding.target);
|
|
23
|
-
if (meta !== void 0) for (let index = 0; index < meta.params.length; index += 1) {
|
|
24
|
-
const param = meta.params[index];
|
|
25
|
-
const dependencyBinding = sourceRegistry.getAll(param.token)[0];
|
|
26
|
-
if (dependencyBinding !== void 0) edges.push({
|
|
27
|
-
from: binding.id,
|
|
28
|
-
to: dependencyBinding.id,
|
|
29
|
-
label: `[${index}]`
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
} else if (binding.kind === "resolved" || binding.kind === "resolved-async") for (let index = 0; index < binding.deps.length; index += 1) {
|
|
33
|
-
const dependency = binding.deps[index];
|
|
34
|
-
const dependencyBindings = sourceRegistry.getAll(dependency.token);
|
|
35
|
-
if (dependencyBindings.length > 0 && dependencyBindings[0] !== void 0) {
|
|
36
|
-
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}]`;
|
|
37
|
-
edges.push({
|
|
38
|
-
from: binding.id,
|
|
39
|
-
to: dependencyBindings[0].id,
|
|
40
|
-
label
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else if (binding.kind === "alias") {
|
|
45
|
-
const targetBindings = sourceRegistry.getAll(binding.target);
|
|
46
|
-
if (targetBindings.length > 0 && targetBindings[0] !== void 0) edges.push({
|
|
47
|
-
from: binding.id,
|
|
48
|
-
to: targetBindings[0].id,
|
|
49
|
-
label: "alias"
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
addBindings(registry, false);
|
|
55
|
-
if (includesParent && parentRegistry !== void 0) addBindings(parentRegistry, true);
|
|
56
|
-
return {
|
|
57
|
-
nodes,
|
|
58
|
-
edges,
|
|
59
|
-
includesParent
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
//#endregion
|
|
63
|
-
export { buildDependencyGraph };
|
package/dist/environment.d.mts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Constructor } from "./constructor-type.mjs";
|
|
2
|
-
import { Token } from "./token.mjs";
|
|
3
|
-
import { BindingIdentifier, BindingKind, BindingScope, ConstraintContext, ResolutionContext, ResolutionFrame, ResolveOptions } from "./types.mjs";
|
|
4
|
-
import { Container } from "./container.mjs";
|
|
5
|
-
|
|
6
|
-
//#region src/environment.d.ts
|
|
7
|
-
/**
|
|
8
|
-
* @since 0.3.16-canary.0
|
|
9
|
-
*/
|
|
10
|
-
declare function runWithContainer<Result>(container: Container, fn: () => Result): Result;
|
|
11
|
-
/**
|
|
12
|
-
* @since 0.3.16-canary.0
|
|
13
|
-
*/
|
|
14
|
-
declare function getActiveContainer(): Container | undefined;
|
|
15
|
-
/**
|
|
16
|
-
* @since 0.3.16-canary.0
|
|
17
|
-
*/
|
|
18
|
-
interface ResolverCallbacks {
|
|
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>, options: 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>, options: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value>;
|
|
23
|
-
resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, options: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Value | undefined;
|
|
24
|
-
resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, options: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Value | undefined>;
|
|
25
|
-
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, options: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Array<Value>;
|
|
26
|
-
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, options: ResolveOptions | undefined, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): Promise<Array<Value>>;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @since 0.3.16-canary.0
|
|
30
|
-
*/
|
|
31
|
-
declare class DefaultResolutionContext implements ResolutionContext {
|
|
32
|
-
private _resolver;
|
|
33
|
-
private _resolutionPath;
|
|
34
|
-
private _resolutionStack;
|
|
35
|
-
private _currentOptions;
|
|
36
|
-
constructor(resolver: ResolverCallbacks, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>, currentOptions: ResolveOptions | undefined);
|
|
37
|
-
private _graph;
|
|
38
|
-
get graph(): ConstraintContext;
|
|
39
|
-
reset(resolver: ResolverCallbacks, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>, currentOptions: ResolveOptions | undefined): void;
|
|
40
|
-
resolve<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Value;
|
|
41
|
-
resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Promise<Value>;
|
|
42
|
-
resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Value | undefined;
|
|
43
|
-
resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Promise<Value | undefined>;
|
|
44
|
-
resolveAll<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Array<Value>;
|
|
45
|
-
resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, options?: ResolveOptions): Promise<Array<Value>>;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* @since 0.3.16-canary.0
|
|
49
|
-
*/
|
|
50
|
-
declare function buildResolutionFrame(tokenName: string, scope: BindingScope, bindingId: BindingIdentifier, kind: BindingKind, slot: {
|
|
51
|
-
name: string | undefined;
|
|
52
|
-
tags: ReadonlyArray<readonly [string, unknown]>;
|
|
53
|
-
}): ResolutionFrame;
|
|
54
|
-
//#endregion
|
|
55
|
-
export { DefaultResolutionContext, ResolverCallbacks, buildResolutionFrame, getActiveContainer, runWithContainer };
|
package/dist/environment.mjs
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
//#region src/environment.ts
|
|
2
|
-
let _activeContainer;
|
|
3
|
-
/**
|
|
4
|
-
* @since 0.3.16-canary.0
|
|
5
|
-
*/
|
|
6
|
-
function runWithContainer(container, fn) {
|
|
7
|
-
const prev = _activeContainer;
|
|
8
|
-
_activeContainer = container;
|
|
9
|
-
try {
|
|
10
|
-
return fn();
|
|
11
|
-
} finally {
|
|
12
|
-
_activeContainer = prev;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* @since 0.3.16-canary.0
|
|
17
|
-
*/
|
|
18
|
-
function getActiveContainer() {
|
|
19
|
-
return _activeContainer;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* @since 0.3.16-canary.0
|
|
23
|
-
*/
|
|
24
|
-
var DefaultResolutionContext = class {
|
|
25
|
-
_resolver;
|
|
26
|
-
_resolutionPath;
|
|
27
|
-
_resolutionStack;
|
|
28
|
-
_currentOptions;
|
|
29
|
-
constructor(resolver, resolutionPath, resolutionStack, currentOptions) {
|
|
30
|
-
this._resolver = resolver;
|
|
31
|
-
this._resolutionPath = resolutionPath;
|
|
32
|
-
this._resolutionStack = resolutionStack;
|
|
33
|
-
this._currentOptions = currentOptions;
|
|
34
|
-
}
|
|
35
|
-
_graph;
|
|
36
|
-
get graph() {
|
|
37
|
-
if (this._graph === void 0) this._graph = new DefaultConstraintContext(this._resolutionPath, this._resolutionStack, this._currentOptions);
|
|
38
|
-
return this._graph;
|
|
39
|
-
}
|
|
40
|
-
reset(resolver, resolutionPath, resolutionStack, currentOptions) {
|
|
41
|
-
this._resolver = resolver;
|
|
42
|
-
this._resolutionPath = resolutionPath;
|
|
43
|
-
this._resolutionStack = resolutionStack;
|
|
44
|
-
this._currentOptions = currentOptions;
|
|
45
|
-
this._graph = void 0;
|
|
46
|
-
}
|
|
47
|
-
resolve(token, options) {
|
|
48
|
-
if (options === void 0) return this._resolver.resolveFromContext(token, this._resolutionPath, this._resolutionStack);
|
|
49
|
-
return this._resolver.resolve(token, options, this._resolutionPath, this._resolutionStack);
|
|
50
|
-
}
|
|
51
|
-
resolveAsync(token, options) {
|
|
52
|
-
if (options === void 0) return this._resolver.resolveAsyncFromContext(token, this._resolutionPath, this._resolutionStack);
|
|
53
|
-
return this._resolver.resolveAsync(token, options, this._resolutionPath, this._resolutionStack);
|
|
54
|
-
}
|
|
55
|
-
resolveOptional(token, options) {
|
|
56
|
-
return this._resolver.resolveOptional(token, options, this._resolutionPath, this._resolutionStack);
|
|
57
|
-
}
|
|
58
|
-
resolveOptionalAsync(token, options) {
|
|
59
|
-
return this._resolver.resolveOptionalAsync(token, options, this._resolutionPath, this._resolutionStack);
|
|
60
|
-
}
|
|
61
|
-
resolveAll(token, options) {
|
|
62
|
-
return this._resolver.resolveAll(token, options, this._resolutionPath, this._resolutionStack);
|
|
63
|
-
}
|
|
64
|
-
resolveAllAsync(token, options) {
|
|
65
|
-
return this._resolver.resolveAllAsync(token, options, this._resolutionPath, this._resolutionStack);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
var DefaultConstraintContext = class {
|
|
69
|
-
resolutionPath;
|
|
70
|
-
resolutionStack;
|
|
71
|
-
parent;
|
|
72
|
-
currentResolveOptions;
|
|
73
|
-
constructor(resolutionPath, resolutionStack, currentResolveOptions) {
|
|
74
|
-
this.resolutionPath = resolutionPath;
|
|
75
|
-
this.resolutionStack = resolutionStack;
|
|
76
|
-
this.parent = resolutionStack.at(-1);
|
|
77
|
-
this.currentResolveOptions = currentResolveOptions;
|
|
78
|
-
}
|
|
79
|
-
_ancestors;
|
|
80
|
-
get ancestors() {
|
|
81
|
-
if (this._ancestors === void 0) this._ancestors = this.resolutionStack.length > 1 ? this.resolutionStack.slice(0, -1) : [];
|
|
82
|
-
return this._ancestors;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* @since 0.3.16-canary.0
|
|
87
|
-
*/
|
|
88
|
-
function buildResolutionFrame(tokenName, scope, bindingId, kind, slot) {
|
|
89
|
-
return {
|
|
90
|
-
tokenName,
|
|
91
|
-
scope,
|
|
92
|
-
bindingId,
|
|
93
|
-
kind,
|
|
94
|
-
slot
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
//#endregion
|
|
98
|
-
export { DefaultResolutionContext, buildResolutionFrame, getActiveContainer, runWithContainer };
|