@codefast/di 0.3.16-canary.1 → 0.3.16-canary.3

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.
Files changed (73) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +4 -4
  3. package/dist/binding-select.d.mts +1 -1
  4. package/dist/binding-select.mjs +5 -5
  5. package/dist/binding.d.mts +28 -28
  6. package/dist/binding.mjs +8 -8
  7. package/dist/constraints.d.mts +3 -3
  8. package/dist/constraints.mjs +2 -2
  9. package/dist/container.mjs +146 -214
  10. package/dist/decorators/inject.d.mts +4 -3
  11. package/dist/decorators/inject.mjs +21 -48
  12. package/dist/decorators/injectable.mjs +4 -12
  13. package/dist/decorators/lifecycle-decorators.mjs +11 -72
  14. package/dist/dependency-graph.mjs +17 -15
  15. package/dist/environment.d.mts +15 -15
  16. package/dist/environment.mjs +21 -21
  17. package/dist/graph-adapters/cytoscape.d.mts +12 -12
  18. package/dist/graph-adapters/cytoscape.mjs +7 -7
  19. package/dist/graph-adapters/reactflow.d.mts +15 -15
  20. package/dist/graph-adapters/reactflow.mjs +6 -9
  21. package/dist/index.d.mts +4 -4
  22. package/dist/index.mjs +2 -2
  23. package/dist/inspector.d.mts +3 -2
  24. package/dist/inspector.mjs +19 -22
  25. package/dist/lifecycle.mjs +2 -12
  26. package/dist/metadata/metadata-keys.d.mts +8 -33
  27. package/dist/metadata/metadata-keys.mjs +8 -21
  28. package/dist/metadata/metadata-types.d.mts +5 -0
  29. package/dist/metadata/symbol-metadata-reader.d.mts +1 -0
  30. package/dist/metadata/symbol-metadata-reader.mjs +11 -33
  31. package/dist/module.d.mts +1 -1
  32. package/dist/module.mjs +2 -2
  33. package/dist/registry.d.mts +4 -4
  34. package/dist/registry.mjs +26 -45
  35. package/dist/resolve-options.d.mts +7 -7
  36. package/dist/resolve-options.mjs +14 -12
  37. package/dist/resolver.d.mts +15 -10
  38. package/dist/resolver.mjs +167 -173
  39. package/dist/token.d.mts +1 -1
  40. package/dist/token.mjs +4 -4
  41. package/dist/types.d.mts +14 -8
  42. package/package.json +40 -13
  43. package/src/binding-scope.ts +26 -0
  44. package/src/binding-select.ts +167 -0
  45. package/src/binding.ts +281 -0
  46. package/src/constraints.ts +149 -0
  47. package/src/constructor-type.ts +19 -0
  48. package/src/container.ts +1213 -0
  49. package/src/decorators/inject.ts +233 -0
  50. package/src/decorators/injectable.ts +85 -0
  51. package/src/decorators/lifecycle-decorators.ts +55 -0
  52. package/src/dependency-graph.ts +116 -0
  53. package/src/environment.ts +232 -0
  54. package/src/errors.ts +262 -0
  55. package/src/graph-adapters/cytoscape.ts +64 -0
  56. package/src/graph-adapters/dot.ts +22 -0
  57. package/src/graph-adapters/reactflow.ts +58 -0
  58. package/src/index.ts +101 -0
  59. package/src/inspector.ts +133 -0
  60. package/src/lifecycle.ts +238 -0
  61. package/src/metadata/metadata-keys.ts +25 -0
  62. package/src/metadata/metadata-reader-token.ts +8 -0
  63. package/src/metadata/metadata-types.ts +53 -0
  64. package/src/metadata/symbol-metadata-reader.ts +57 -0
  65. package/src/module.ts +93 -0
  66. package/src/registry.ts +241 -0
  67. package/src/resolve-options.ts +42 -0
  68. package/src/resolver.ts +1837 -0
  69. package/src/scope.ts +77 -0
  70. package/src/token.ts +40 -0
  71. package/src/types.ts +145 -0
  72. package/dist/graph-adapters/types.d.mts +0 -2
  73. package/dist/graph-adapters/types.mjs +0 -1
@@ -1,7 +1,7 @@
1
1
  import { InternalError, MissingContainerContextError } from "../errors.mjs";
2
2
  import { getActiveContainer } from "../environment.mjs";
3
- import { injectableSlotToResolveOptions } from "../resolve-options.mjs";
4
- import { INJECT_ACCESSOR_KEY, accessorMetadataByMetadataObjectMap } from "../metadata/metadata-keys.mjs";
3
+ import { injectionSlotToResolveOptions } from "../resolve-options.mjs";
4
+ import { INJECT_ACCESSOR_KEY } 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(dep) {
19
- if (isInjectionDescriptor(dep)) return materializeInjectionDescriptor(dep);
18
+ function normalizeToDescriptor(dependency) {
19
+ if (isInjectionDescriptor(dependency)) return materializeInjectionDescriptor(dependency);
20
20
  return {
21
- token: dep,
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(dep) {
31
- if (typeof dep !== "function") return dep;
32
- const dualRole = dep;
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,12 +54,7 @@ function materializeInjectionDescriptor(dep) {
54
54
  };
55
55
  return base;
56
56
  }
57
- function buildInjectionDescriptor(token, options) {
58
- const base = {
59
- token,
60
- optional: false,
61
- multi: false
62
- };
57
+ function withOptions(base, options) {
63
58
  if (options?.name !== void 0 && options.tags !== void 0) return {
64
59
  ...base,
65
60
  name: options.name,
@@ -75,6 +70,13 @@ function buildInjectionDescriptor(token, options) {
75
70
  };
76
71
  return base;
77
72
  }
73
+ function buildInjectionDescriptor(token, options) {
74
+ return withOptions({
75
+ token,
76
+ optional: false,
77
+ multi: false
78
+ }, options);
79
+ }
78
80
  /**
79
81
  * @since 0.3.16-canary.0
80
82
  */
@@ -88,11 +90,10 @@ function inject(token, options) {
88
90
  key: context.name,
89
91
  descriptor
90
92
  });
91
- accessorMetadataByMetadataObjectMap.set(context.metadata, meta[INJECT_ACCESSOR_KEY]);
92
93
  context.addInitializer(function() {
93
94
  const container = getActiveContainer();
94
95
  if (container === void 0) throw new MissingContainerContextError(String(context.name));
95
- const hint = options === void 0 ? void 0 : injectableSlotToResolveOptions({
96
+ const hint = options === void 0 ? void 0 : injectionSlotToResolveOptions({
96
97
  ...options.name !== void 0 ? { name: options.name } : {},
97
98
  ...options.tags !== void 0 ? { tags: options.tags } : {}
98
99
  });
@@ -115,49 +116,21 @@ function inject(token, options) {
115
116
  * @since 0.3.16-canary.0
116
117
  */
117
118
  function optional(token, options) {
118
- const base = {
119
+ return withOptions({
119
120
  token,
120
121
  optional: true,
121
122
  multi: false
122
- };
123
- if (options?.name !== void 0 && options.tags !== void 0) return {
124
- ...base,
125
- name: options.name,
126
- tags: options.tags
127
- };
128
- if (options?.name !== void 0) return {
129
- ...base,
130
- name: options.name
131
- };
132
- if (options?.tags !== void 0) return {
133
- ...base,
134
- tags: options.tags
135
- };
136
- return base;
123
+ }, options);
137
124
  }
138
125
  /**
139
126
  * @since 0.3.16-canary.0
140
127
  */
141
128
  function injectAll(token, options) {
142
- const base = {
129
+ return withOptions({
143
130
  token,
144
131
  optional: false,
145
132
  multi: true
146
- };
147
- if (options?.name !== void 0 && options.tags !== void 0) return {
148
- ...base,
149
- name: options.name,
150
- tags: options.tags
151
- };
152
- if (options?.name !== void 0) return {
153
- ...base,
154
- name: options.name
155
- };
156
- if (options?.tags !== void 0) return {
157
- ...base,
158
- tags: options.tags
159
- };
160
- return base;
133
+ }, options);
161
134
  }
162
135
  //#endregion
163
136
  export { inject, injectAll, isInjectionDescriptor, normalizeToDescriptor, optional };
@@ -1,4 +1,4 @@
1
- import { INJECTABLE_KEY, INJECT_ACCESSOR_KEY, accessorMetadataByConstructorMap, constructorMetadataMap } from "../metadata/metadata-keys.mjs";
1
+ import { INJECTABLE_KEY } from "../metadata/metadata-keys.mjs";
2
2
  import { normalizeToDescriptor } from "./inject.mjs";
3
3
  //#region src/decorators/injectable.ts
4
4
  /**
@@ -23,7 +23,7 @@ function createAutoRegisterRegistry() {
23
23
  */
24
24
  function injectable(deps, options) {
25
25
  return function(target, context) {
26
- const constructorMetadata = { params: (deps ?? []).map((dependency, index) => {
26
+ const parameterMetadataList = (deps ?? []).map((dependency, index) => {
27
27
  const descriptor = normalizeToDescriptor(dependency);
28
28
  const baseParameterMetadata = {
29
29
  index,
@@ -45,16 +45,8 @@ function injectable(deps, options) {
45
45
  tags: descriptor.tags
46
46
  };
47
47
  return baseParameterMetadata;
48
- }) };
49
- constructorMetadataMap.set(target, constructorMetadata);
50
- try {
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
- }
57
- } catch {}
48
+ });
49
+ context.metadata[INJECTABLE_KEY] = { params: parameterMetadataList };
58
50
  if (options?.autoRegister !== void 0) {
59
51
  const scope = options.scope ?? "transient";
60
52
  options.autoRegister.register(target, scope);
@@ -1,26 +1,9 @@
1
1
  import { InternalError } from "../errors.mjs";
2
- import { LIFECYCLE_KEY, lifecycleByConstructorMetadataMap, lifecycleMetadataMap } from "../metadata/metadata-keys.mjs";
2
+ import { LIFECYCLE_KEY } from "../metadata/metadata-keys.mjs";
3
3
  //#region src/decorators/lifecycle-decorators.ts
4
4
  function appendUniqueMethod(metadata, phase, methodName) {
5
5
  if (!metadata[phase].includes(methodName)) metadata[phase].push(methodName);
6
6
  }
7
- function resolveConstructorFromDecoratorTarget(target) {
8
- if (typeof target === "function") return target;
9
- if (typeof target === "object" && target !== null) {
10
- const ctor = target.constructor;
11
- if (typeof ctor === "function") return ctor;
12
- }
13
- }
14
- function registerByConstructor(target, phase, methodName) {
15
- const ctor = resolveConstructorFromDecoratorTarget(target);
16
- if (ctor === void 0) return;
17
- const ctorExisting = lifecycleByConstructorMetadataMap.get(ctor);
18
- if (ctorExisting !== void 0) appendUniqueMethod(ctorExisting, phase, methodName);
19
- else lifecycleByConstructorMetadataMap.set(ctor, {
20
- postConstruct: phase === "postConstruct" ? [methodName] : [],
21
- preDestroy: phase === "preDestroy" ? [methodName] : []
22
- });
23
- }
24
7
  /**
25
8
  * @since 0.3.16-canary.0
26
9
  */
@@ -28,34 +11,12 @@ function postConstruct() {
28
11
  return function(target, context) {
29
12
  if (context.static === true) throw new InternalError("@postConstruct() applies to instance methods only; static methods are not invoked during instance lifecycle.");
30
13
  const methodName = String(context.name);
31
- registerByConstructor(target, "postConstruct", methodName);
32
- const existing = lifecycleMetadataMap.get(context.metadata);
33
- if (existing !== void 0) appendUniqueMethod(existing, "postConstruct", methodName);
34
- else lifecycleMetadataMap.set(context.metadata, {
35
- postConstruct: [methodName],
14
+ const meta = context.metadata;
15
+ if (!meta[LIFECYCLE_KEY]) meta[LIFECYCLE_KEY] = {
16
+ postConstruct: [],
36
17
  preDestroy: []
37
- });
38
- context.addInitializer(function() {
39
- const targetOrInstance = this;
40
- const ctor = typeof targetOrInstance === "function" ? targetOrInstance : targetOrInstance.constructor;
41
- const ctorExisting = lifecycleByConstructorMetadataMap.get(ctor);
42
- if (ctorExisting !== void 0) appendUniqueMethod(ctorExisting, "postConstruct", methodName);
43
- else lifecycleByConstructorMetadataMap.set(ctor, {
44
- postConstruct: [methodName],
45
- preDestroy: []
46
- });
47
- });
48
- try {
49
- const meta = context.metadata;
50
- if (meta !== null && typeof meta === "object") {
51
- if (!meta[LIFECYCLE_KEY]) meta[LIFECYCLE_KEY] = {
52
- postConstruct: [],
53
- preDestroy: []
54
- };
55
- const lifecycle = meta[LIFECYCLE_KEY];
56
- appendUniqueMethod(lifecycle, "postConstruct", methodName);
57
- }
58
- } catch {}
18
+ };
19
+ appendUniqueMethod(meta[LIFECYCLE_KEY], "postConstruct", methodName);
59
20
  };
60
21
  }
61
22
  /**
@@ -65,34 +26,12 @@ function preDestroy() {
65
26
  return function(target, context) {
66
27
  if (context.static === true) throw new InternalError("@preDestroy() applies to instance methods only; static methods are not invoked during instance teardown.");
67
28
  const methodName = String(context.name);
68
- registerByConstructor(target, "preDestroy", methodName);
69
- const existing = lifecycleMetadataMap.get(context.metadata);
70
- if (existing !== void 0) appendUniqueMethod(existing, "preDestroy", methodName);
71
- else lifecycleMetadataMap.set(context.metadata, {
29
+ const meta = context.metadata;
30
+ if (!meta[LIFECYCLE_KEY]) meta[LIFECYCLE_KEY] = {
72
31
  postConstruct: [],
73
- preDestroy: [methodName]
74
- });
75
- context.addInitializer(function() {
76
- const targetOrInstance = this;
77
- const ctor = typeof targetOrInstance === "function" ? targetOrInstance : targetOrInstance.constructor;
78
- const ctorExisting = lifecycleByConstructorMetadataMap.get(ctor);
79
- if (ctorExisting !== void 0) appendUniqueMethod(ctorExisting, "preDestroy", methodName);
80
- else lifecycleByConstructorMetadataMap.set(ctor, {
81
- postConstruct: [],
82
- preDestroy: [methodName]
83
- });
84
- });
85
- try {
86
- const meta = context.metadata;
87
- if (meta !== null && typeof meta === "object") {
88
- if (!meta[LIFECYCLE_KEY]) meta[LIFECYCLE_KEY] = {
89
- postConstruct: [],
90
- preDestroy: []
91
- };
92
- const lifecycle = meta[LIFECYCLE_KEY];
93
- appendUniqueMethod(lifecycle, "preDestroy", methodName);
94
- }
95
- } catch {}
32
+ preDestroy: []
33
+ };
34
+ appendUniqueMethod(meta[LIFECYCLE_KEY], "preDestroy", methodName);
96
35
  };
97
36
  }
98
37
  //#endregion
@@ -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 = (reg, fromParent) => {
12
- for (const binding of reg.allBindings()) {
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,29 @@ 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, idx) => {
24
- const depBinding = reg.getAll(param.token)[0];
25
- if (depBinding !== void 0) edges.push({
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({
26
27
  from: binding.id,
27
- to: depBinding.id,
28
- label: `[${idx}]`
28
+ to: dependencyBinding.id,
29
+ label: `[${index}]`
29
30
  });
30
- });
31
- } else if (binding.kind === "resolved" || binding.kind === "resolved-async") binding.deps.forEach((dep, idx) => {
32
- const depBindings = reg.getAll(dep.token);
33
- if (depBindings.length > 0 && depBindings[0] !== void 0) {
34
- const label = dep.name !== void 0 ? `name:${dep.name}` : dep.tags !== void 0 && dep.tags.length > 0 ? `tag:${dep.tags[0]?.[0]}=${String(dep.tags[0]?.[1])}` : `[${idx}]`;
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}]`;
35
37
  edges.push({
36
38
  from: binding.id,
37
- to: depBindings[0].id,
39
+ to: dependencyBindings[0].id,
38
40
  label
39
41
  });
40
42
  }
41
- });
43
+ }
42
44
  else if (binding.kind === "alias") {
43
- const targetBindings = reg.getAll(binding.target);
45
+ const targetBindings = sourceRegistry.getAll(binding.target);
44
46
  if (targetBindings.length > 0 && targetBindings[0] !== void 0) edges.push({
45
47
  from: binding.id,
46
48
  to: targetBindings[0].id,
@@ -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, MaterializationFrame, ResolutionContext, ResolveOptions } from "./types.mjs";
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>, path: Array<string>, stack: Array<MaterializationFrame>): Value;
20
- resolve<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: Array<string>, stack: Array<MaterializationFrame>): Value;
21
- resolveAsyncFromContext<const Value>(token: Token<Value> | Constructor<Value>, path: Array<string>, stack: Array<MaterializationFrame>): Promise<Value>;
22
- resolveAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: Array<string>, stack: Array<MaterializationFrame>): Promise<Value>;
23
- resolveOptional<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: Array<string>, stack: Array<MaterializationFrame>): Value | undefined;
24
- resolveOptionalAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: Array<string>, stack: Array<MaterializationFrame>): Promise<Value | undefined>;
25
- resolveAll<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: Array<string>, stack: Array<MaterializationFrame>): Array<Value>;
26
- resolveAllAsync<const Value>(token: Token<Value> | Constructor<Value>, hint: ResolveOptions | undefined, path: Array<string>, stack: Array<MaterializationFrame>): Promise<Array<Value>>;
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 _materializationStack;
34
+ private _resolutionStack;
35
35
  private _currentHint;
36
- constructor(resolver: ResolverCallbacks, resolutionPath: Array<string>, materializationStack: Array<MaterializationFrame>, currentHint: ResolveOptions | undefined);
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>, materializationStack: Array<MaterializationFrame>, currentHint: ResolveOptions | undefined): void;
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 buildMaterializationFrame(tokenName: string, scope: BindingScope, bindingId: BindingIdentifier, kind: BindingKind, slot: {
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
- }): MaterializationFrame;
53
+ }): ResolutionFrame;
54
54
  //#endregion
55
- export { DefaultResolutionContext, ResolverCallbacks, buildMaterializationFrame, getActiveContainer, runWithContainer };
55
+ export { DefaultResolutionContext, ResolverCallbacks, buildResolutionFrame, getActiveContainer, runWithContainer };
@@ -24,68 +24,68 @@ function getActiveContainer() {
24
24
  var DefaultResolutionContext = class {
25
25
  _resolver;
26
26
  _resolutionPath;
27
- _materializationStack;
27
+ _resolutionStack;
28
28
  _currentHint;
29
- constructor(resolver, resolutionPath, materializationStack, currentHint) {
29
+ constructor(resolver, resolutionPath, resolutionStack, currentHint) {
30
30
  this._resolver = resolver;
31
31
  this._resolutionPath = resolutionPath;
32
- this._materializationStack = materializationStack;
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._materializationStack, this._currentHint);
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, materializationStack, currentHint) {
40
+ reset(resolver, resolutionPath, resolutionStack, currentHint) {
41
41
  this._resolver = resolver;
42
42
  this._resolutionPath = resolutionPath;
43
- this._materializationStack = materializationStack;
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._materializationStack);
49
- return this._resolver.resolve(token, hint, this._resolutionPath, this._materializationStack);
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._materializationStack);
53
- return this._resolver.resolveAsync(token, hint, this._resolutionPath, this._materializationStack);
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._materializationStack);
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._materializationStack);
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._materializationStack);
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._materializationStack);
65
+ return this._resolver.resolveAllAsync(token, hint, this._resolutionPath, this._resolutionStack);
66
66
  }
67
67
  };
68
68
  var DefaultConstraintContext = class {
69
69
  resolutionPath;
70
- materializationStack;
70
+ resolutionStack;
71
71
  parent;
72
72
  currentResolveHint;
73
- constructor(resolutionPath, materializationStack, currentResolveHint) {
73
+ constructor(resolutionPath, resolutionStack, currentResolveHint) {
74
74
  this.resolutionPath = resolutionPath;
75
- this.materializationStack = materializationStack;
76
- this.parent = materializationStack.at(-1);
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.materializationStack.length > 1 ? this.materializationStack.slice(0, -1) : [];
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 buildMaterializationFrame(tokenName, scope, bindingId, kind, slot) {
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, buildMaterializationFrame, getActiveContainer, runWithContainer };
98
+ export { DefaultResolutionContext, buildResolutionFrame, getActiveContainer, runWithContainer };
@@ -5,29 +5,29 @@ import { ContainerGraphJson } from "../dependency-graph.mjs";
5
5
  * @since 0.3.16-canary.0
6
6
  */
7
7
  interface CytoscapeNode {
8
- data: {
9
- id: string;
10
- label: string;
11
- kind: string;
12
- scope: string;
13
- fromParent: boolean;
8
+ readonly data: {
9
+ readonly id: string;
10
+ readonly label: string;
11
+ readonly kind: string;
12
+ readonly scope: string;
13
+ readonly fromParent: boolean;
14
14
  };
15
15
  }
16
16
  /**
17
17
  * @since 0.3.16-canary.0
18
18
  */
19
19
  interface CytoscapeEdge {
20
- data: {
21
- id: string;
22
- source: string;
23
- target: string;
24
- label?: string;
20
+ readonly data: {
21
+ readonly id: string;
22
+ readonly source: string;
23
+ readonly target: string;
24
+ readonly label?: string;
25
25
  };
26
26
  }
27
27
  /**
28
28
  * @since 0.3.16-canary.0
29
29
  */
30
- type CytoscapeElements = Array<CytoscapeNode | CytoscapeEdge>;
30
+ type CytoscapeElements = ReadonlyArray<CytoscapeNode | CytoscapeEdge>;
31
31
  /**
32
32
  * @since 0.3.16-canary.0
33
33
  */
@@ -11,15 +11,15 @@ function toCytoscapeGraph(graph) {
11
11
  scope: node.scope,
12
12
  fromParent: node.fromParent
13
13
  } });
14
- graph.edges.forEach((edge, idx) => {
15
- const data = {
14
+ for (let idx = 0; idx < graph.edges.length; idx += 1) {
15
+ const edge = graph.edges[idx];
16
+ elements.push({ data: {
16
17
  id: `edge-${idx}`,
17
18
  source: edge.from,
18
- target: edge.to
19
- };
20
- if (edge.label !== void 0) data.label = edge.label;
21
- elements.push({ data });
22
- });
19
+ target: edge.to,
20
+ ...edge.label !== void 0 ? { label: edge.label } : {}
21
+ } });
22
+ }
23
23
  return elements;
24
24
  }
25
25
  //#endregion
@@ -5,33 +5,33 @@ import { ContainerGraphJson } from "../dependency-graph.mjs";
5
5
  * @since 0.3.16-canary.0
6
6
  */
7
7
  interface ReactFlowNode {
8
- id: string;
9
- data: {
10
- label: string;
11
- kind: string;
12
- scope: string;
13
- fromParent: boolean;
8
+ readonly id: string;
9
+ readonly data: {
10
+ readonly label: string;
11
+ readonly kind: string;
12
+ readonly scope: string;
13
+ readonly fromParent: boolean;
14
14
  };
15
- position: {
16
- x: number;
17
- y: number;
15
+ readonly position: {
16
+ readonly x: number;
17
+ readonly y: number;
18
18
  };
19
19
  }
20
20
  /**
21
21
  * @since 0.3.16-canary.0
22
22
  */
23
23
  interface ReactFlowEdge {
24
- id: string;
25
- source: string;
26
- target: string;
27
- label?: string;
24
+ readonly id: string;
25
+ readonly source: string;
26
+ readonly target: string;
27
+ readonly label?: string;
28
28
  }
29
29
  /**
30
30
  * @since 0.3.16-canary.0
31
31
  */
32
32
  interface ReactFlowGraph {
33
- nodes: Array<ReactFlowNode>;
34
- edges: Array<ReactFlowEdge>;
33
+ readonly nodes: ReadonlyArray<ReactFlowNode>;
34
+ readonly edges: ReadonlyArray<ReactFlowEdge>;
35
35
  }
36
36
  /**
37
37
  * @since 0.3.16-canary.0
@@ -17,15 +17,12 @@ function toReactFlowGraph(graph) {
17
17
  y: Math.floor(idx / 5) * 100
18
18
  }
19
19
  })),
20
- edges: graph.edges.map((edge, idx) => {
21
- const reactFlowEdge = {
22
- id: `edge-${idx}`,
23
- source: edge.from,
24
- target: edge.to
25
- };
26
- if (edge.label !== void 0) reactFlowEdge.label = edge.label;
27
- return reactFlowEdge;
28
- })
20
+ edges: graph.edges.map((edge, idx) => ({
21
+ id: `edge-${idx}`,
22
+ source: edge.from,
23
+ target: edge.to,
24
+ ...edge.label !== void 0 ? { label: edge.label } : {}
25
+ }))
29
26
  };
30
27
  }
31
28
  //#endregion
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
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, MaterializationFrame, ResolutionContext, ResolveOptions, TokenValue } from "./types.mjs";
3
+ import { ActivationHandler, BindingIdentifier, BindingKind, BindingScope, BindingTag, 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
- import { AliasBindingBuilder, BindToBuilder, BindingBuilder, ConstantBindingBuilder, ScopedBindingBuilder, SingletonBindingBuilder, SingletonLifecycleBuilder, TransientBindingBuilder } from "./binding.mjs";
5
+ import { AliasBindingBuilder, BindToBuilder, BindingBuilder, ConstantBindingBuilder, ScopedBindingBuilder, SingletonBindingBuilder, SingletonLifecycleBuilder, SlotConstrainedBuilder, TransientBindingBuilder } from "./binding.mjs";
6
6
  import { effectiveBindingScope } from "./binding-scope.mjs";
7
7
  import { whenAnyAncestorIs, whenAnyAncestorNamed, whenAnyAncestorTagged, whenAnyAncestorTaggedAll, whenNoAncestorIs, whenNoParentIs, whenParentIs, whenParentNamed, whenParentTagged, whenParentTaggedAll } from "./constraints.mjs";
8
8
  import { AsyncModule, AsyncModuleBuilder, Module, ModuleBuilder, SyncModule, isSyncModule } from "./module.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 { injectableSlotToResolveOptions, slotKeyToResolveOptions } from "./resolve-options.mjs";
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 MaterializationFrame, type MetadataReader, MetadataReaderToken, MissingContainerContextError, MissingMetadataError, MissingScopeContextError, Module, type ModuleBuilder, type MutableLifecycleMetadata, NoMatchingBindingError, RebindUnboundTokenError, type ResolutionContext, type ResolveOptions, type ScopeViolationDetails, ScopeViolationError, type ScopedBindingBuilder, type SingletonBindingBuilder, type SingletonLifecycleBuilder, SyncDisposalNotSupportedError, SyncModule, type Token, TokenNotBoundError, type TokenValue, type TransientBindingBuilder, createAutoRegisterRegistry, effectiveBindingScope, inject, injectAll, injectable, injectableSlotToResolveOptions, isInjectionDescriptor, isSyncModule, isToken, optional, postConstruct, preDestroy, slotKeyToResolveOptions, token, tokenName, whenAnyAncestorIs, whenAnyAncestorNamed, whenAnyAncestorTagged, whenAnyAncestorTaggedAll, whenNoAncestorIs, whenNoParentIs, whenParentIs, whenParentNamed, whenParentTagged, whenParentTaggedAll };
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, type BindingTag, 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, type SlotConstrainedBuilder, 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 };