@codefast/di 0.9.0 → 0.10.1

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 +165 -0
  2. package/README.md +6 -5
  3. package/dist/ambient/active-container.d.ts +14 -4
  4. package/dist/ambient/active-container.js +22 -1
  5. package/dist/container/binding-builders.d.ts +35 -13
  6. package/dist/container/binding-builders.js +174 -97
  7. package/dist/container/container.d.ts +10 -10
  8. package/dist/container/container.js +53 -36
  9. package/dist/core/binding-scope.d.ts +2 -2
  10. package/dist/core/binding.d.ts +42 -49
  11. package/dist/core/binding.js +12 -38
  12. package/dist/core/constraint-requirement.d.ts +1 -1
  13. package/dist/core/module.d.ts +3 -3
  14. package/dist/core/registry.d.ts +52 -9
  15. package/dist/core/registry.js +376 -162
  16. package/dist/core/state-epoch.d.ts +16 -0
  17. package/dist/core/state-epoch.js +21 -0
  18. package/dist/core/token.d.ts +1 -1
  19. package/dist/core/types.d.ts +12 -9
  20. package/dist/decorators/inject.d.ts +3 -3
  21. package/dist/decorators/inject.js +5 -5
  22. package/dist/decorators/injectable.d.ts +2 -2
  23. package/dist/decorators/injectable.js +2 -2
  24. package/dist/decorators/lifecycle-decorators.js +2 -2
  25. package/dist/errors/diagnostics.d.ts +2 -0
  26. package/dist/errors/errors.d.ts +29 -3
  27. package/dist/errors/errors.js +34 -2
  28. package/dist/index.d.ts +35 -35
  29. package/dist/index.js +19 -19
  30. package/dist/injection/descriptor.d.ts +9 -7
  31. package/dist/injection/descriptor.js +3 -1
  32. package/dist/injection/resolve-options.d.ts +9 -3
  33. package/dist/injection/resolve-options.js +17 -1
  34. package/dist/introspection/dependency-graph.d.ts +3 -3
  35. package/dist/introspection/dependency-graph.js +15 -10
  36. package/dist/introspection/graph-adapters/cytoscape.d.ts +1 -1
  37. package/dist/introspection/graph-adapters/dot.d.ts +1 -1
  38. package/dist/introspection/graph-adapters/mermaid.d.ts +1 -1
  39. package/dist/introspection/graph-adapters/reactflow.d.ts +1 -1
  40. package/dist/introspection/inspector.d.ts +7 -5
  41. package/dist/introspection/inspector.js +13 -27
  42. package/dist/lifecycle/lifecycle-manager.d.ts +4 -4
  43. package/dist/lifecycle/lifecycle-manager.js +13 -11
  44. package/dist/lifecycle/scope-manager.d.ts +2 -2
  45. package/dist/lifecycle/scope-manager.js +4 -4
  46. package/dist/metadata/metadata-reader-token.d.ts +2 -2
  47. package/dist/metadata/metadata-reader-token.js +1 -1
  48. package/dist/metadata/metadata-types.d.ts +3 -3
  49. package/dist/metadata/symbol-metadata-reader.d.ts +3 -3
  50. package/dist/metadata/symbol-metadata-reader.js +1 -1
  51. package/dist/metadata/verifying-metadata-reader.d.ts +1 -1
  52. package/dist/metadata/verifying-metadata-reader.js +2 -2
  53. package/dist/resolution/cache/activation-need.d.ts +6 -4
  54. package/dist/resolution/cache/activation-need.js +13 -6
  55. package/dist/resolution/cache/binding-lookup-cache.d.ts +39 -6
  56. package/dist/resolution/cache/binding-lookup-cache.js +97 -13
  57. package/dist/resolution/cache/class-introspector.d.ts +6 -6
  58. package/dist/resolution/cache/class-introspector.js +82 -69
  59. package/dist/resolution/context.d.ts +11 -11
  60. package/dist/resolution/context.js +1 -1
  61. package/dist/resolution/path/resolution-path.d.ts +1 -1
  62. package/dist/resolution/path/resolution-path.js +1 -1
  63. package/dist/resolution/plan/instantiation-plan.d.ts +16 -4
  64. package/dist/resolution/plan/instantiation-plan.js +160 -69
  65. package/dist/resolution/plan/plan-codegen.d.ts +100 -0
  66. package/dist/resolution/plan/plan-codegen.js +185 -0
  67. package/dist/resolution/resolver.d.ts +26 -16
  68. package/dist/resolution/resolver.js +401 -147
  69. package/dist/resolution/select/binding-select.d.ts +6 -5
  70. package/dist/resolution/select/binding-select.js +17 -11
  71. package/dist/resolution/select/constraints.d.ts +3 -3
  72. package/dist/resolution/select/constraints.js +4 -4
  73. package/package.json +11 -3
@@ -1,9 +1,10 @@
1
- import type { Binding, BindingSlot } from "#/core/binding";
2
- import type { TagKeyMask } from "#/core/tag";
3
- import type { ConstraintContext, ResolveOptions } from "#/core/types";
1
+ import type { Binding, BindingSlot } from "#core/binding";
2
+ import type { TagKeyMask } from "#core/tag";
3
+ import type { ConstraintContext, ResolveOptions } from "#core/types";
4
4
  /**
5
- * Selects a single candidate from a list of bindings using slot matching + predicates.
6
- * Returns undefined if no match, throws AmbiguousBindingError if multiple match.
5
+ * The single candidate a request selects from a list, by slot match then predicate.
6
+ *
7
+ * @remarks `undefined` when nothing matches; throws {@link AmbiguousBindingError} when several do.
7
8
  *
8
9
  * @since 0.3.16-canary.0
9
10
  */
@@ -1,13 +1,14 @@
1
- import { coversTagKeys, NO_TAG_KEYS, slotName, slotNameCriterionOf } from "#/core/tag";
2
- import { AmbiguousBindingError } from "#/errors/errors";
1
+ import { coversTagKeys, NO_TAG_KEYS, slotName, slotNameCriterionOf } from "#core/tag";
2
+ import { AmbiguousBindingError } from "#errors/errors";
3
3
  /**
4
- * Selects a single candidate from a list of bindings using slot matching + predicates.
5
- * Returns undefined if no match, throws AmbiguousBindingError if multiple match.
4
+ * The single candidate a request selects from a list, by slot match then predicate.
5
+ *
6
+ * @remarks `undefined` when nothing matches; throws {@link AmbiguousBindingError} when several do.
6
7
  *
7
8
  * @since 0.3.16-canary.0
8
9
  */
9
10
  export function selectBinding(bindings, options, ctx, tokenDisplayName) {
10
- const candidates = filterBindings(bindings, options, ctx, true);
11
+ const candidates = filterBindings(bindings, options, ctx, true, false);
11
12
  if (candidates.length === 0) {
12
13
  return undefined;
13
14
  }
@@ -36,7 +37,7 @@ export function selectBinding(bindings, options, ctx, tokenDisplayName) {
36
37
  if (mostSpecific !== undefined) {
37
38
  return mostSpecific;
38
39
  }
39
- throw new AmbiguousBindingError(tokenDisplayName, candidates.map((c) => c.id));
40
+ throw new AmbiguousBindingError(tokenDisplayName, candidates.map((c) => c.identifier));
40
41
  }
41
42
  /** The lone candidate declaring more criteria than every other, or `undefined` when that is a tie. */
42
43
  function mostSpecificByCriterionCount(candidates) {
@@ -64,7 +65,7 @@ function mostSpecificByCriterionCount(candidates) {
64
65
  export function selectAllBindings(bindings, options, ctx) {
65
66
  // `resolveAll` matches the slot only when the request carries a criterion; with none it takes
66
67
  // every binding, where `resolve` would read an absent criterion as "the default slot".
67
- return filterBindings(bindings, options, ctx, options !== undefined && hasSlotCriterion(options));
68
+ return filterBindings(bindings, options, ctx, options !== undefined && hasSlotCriterion(options), true);
68
69
  }
69
70
  /**
70
71
  * @param bindings - the token's candidates, in registration order
@@ -72,13 +73,18 @@ export function selectAllBindings(bindings, options, ctx) {
72
73
  * @param ctx - what the constraint predicates read
73
74
  * @param requiresSlotMatch - `resolve` always matches the slot, where an absent criterion means
74
75
  * "the default slot"; `resolveAll` matches only when the request carries one
76
+ * @param includesMembers - `resolveAll` takes collection members; a single `resolve` never does
75
77
  */
76
- function filterBindings(bindings, options, ctx, requiresSlotMatch) {
78
+ function filterBindings(bindings, options, ctx, requiresSlotMatch, includesMembers) {
77
79
  const result = [];
78
- // A predicate is user code that may rebind the token mid-walk, but the registry replaces a
79
- // token's list on mutation instead of splicing it, so this walk keeps its own list — no copy.
80
- for (let index = 0; index < bindings.length; index += 1) {
80
+ // A predicate is user code that may rebind the token mid-walk. A removal replaces the list, and an
81
+ // append lands past the length read here, so the walk offers exactly the candidates it started with.
82
+ const length = bindings.length;
83
+ for (let index = 0; index < length; index += 1) {
81
84
  const binding = bindings[index];
85
+ if (!includesMembers && binding.isMany) {
86
+ continue;
87
+ }
82
88
  if (requiresSlotMatch && !matchesSlot(binding.slot, options)) {
83
89
  continue;
84
90
  }
@@ -1,6 +1,6 @@
1
- import type { BindingTag } from "#/core/tag";
2
- import type { Token } from "#/core/token";
3
- import type { BindingConstraint, Constructor } from "#/core/types";
1
+ import type { BindingTag } from "#core/tag";
2
+ import type { Token } from "#core/token";
3
+ import type { BindingConstraint, Constructor } from "#core/types";
4
4
  /**
5
5
  * Matches when the direct parent frame resolves the given token.
6
6
  *
@@ -1,7 +1,7 @@
1
- import { requiringAncestorSlotName, requiringAncestorSlotNames } from "#/core/constraint-requirement";
2
- import { coversTagKeys, slotName, tagKeyMaskOf } from "#/core/tag";
3
- import { tokenName } from "#/core/token";
4
- import { EmptyTagCriteriaError } from "#/errors/errors";
1
+ import { requiringAncestorSlotName, requiringAncestorSlotNames } from "#core/constraint-requirement";
2
+ import { coversTagKeys, slotName, tagKeyMaskOf } from "#core/tag";
3
+ import { tokenName } from "#core/token";
4
+ import { EmptyTagCriteriaError } from "#errors/errors";
5
5
  /**
6
6
  * Matches when the direct parent frame resolves the given token.
7
7
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codefast/di",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
4
4
  "description": "Lightweight dependency injection primitives for Codefast",
5
5
  "keywords": [
6
6
  "codefast",
@@ -32,7 +32,7 @@
32
32
  "module": "./dist/index.js",
33
33
  "types": "./dist/index.d.ts",
34
34
  "imports": {
35
- "#/*": {
35
+ "#*": {
36
36
  "types": "./dist/*.d.ts",
37
37
  "default": "./dist/*.js"
38
38
  }
@@ -82,6 +82,10 @@
82
82
  "types": "./dist/core/registry.d.ts",
83
83
  "import": "./dist/core/registry.js"
84
84
  },
85
+ "./core/state-epoch": {
86
+ "types": "./dist/core/state-epoch.d.ts",
87
+ "import": "./dist/core/state-epoch.js"
88
+ },
85
89
  "./core/tag": {
86
90
  "types": "./dist/core/tag.d.ts",
87
91
  "import": "./dist/core/tag.js"
@@ -198,6 +202,10 @@
198
202
  "types": "./dist/resolution/plan/instantiation-plan.d.ts",
199
203
  "import": "./dist/resolution/plan/instantiation-plan.js"
200
204
  },
205
+ "./resolution/plan/plan-codegen": {
206
+ "types": "./dist/resolution/plan/plan-codegen.d.ts",
207
+ "import": "./dist/resolution/plan/plan-codegen.js"
208
+ },
201
209
  "./resolution/resolver": {
202
210
  "types": "./dist/resolution/resolver.d.ts",
203
211
  "import": "./dist/resolution/resolver.js"
@@ -216,6 +224,6 @@
216
224
  "access": "public"
217
225
  },
218
226
  "engines": {
219
- "node": ">=24.0.0"
227
+ "node": ">=22.12.0"
220
228
  }
221
229
  }