@codefast/di 0.5.0 → 0.6.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 (266) hide show
  1. package/CHANGELOG.md +712 -0
  2. package/README.md +119 -30
  3. package/dist/ambient/active-container.d.ts +37 -0
  4. package/dist/ambient/active-container.d.ts.map +1 -0
  5. package/dist/ambient/active-container.js +41 -0
  6. package/dist/ambient/active-container.js.map +1 -0
  7. package/dist/container/binding-builders.d.ts +12 -8
  8. package/dist/container/binding-builders.d.ts.map +1 -1
  9. package/dist/container/binding-builders.js +62 -31
  10. package/dist/container/binding-builders.js.map +1 -1
  11. package/dist/container/container.d.ts +33 -19
  12. package/dist/container/container.d.ts.map +1 -1
  13. package/dist/container/container.js +281 -118
  14. package/dist/container/container.js.map +1 -1
  15. package/dist/{resolution → core}/binding-scope.d.ts +2 -2
  16. package/dist/core/binding-scope.d.ts.map +1 -0
  17. package/dist/core/binding-scope.js.map +1 -0
  18. package/dist/{binding.d.ts → core/binding.d.ts} +70 -15
  19. package/dist/core/binding.d.ts.map +1 -0
  20. package/dist/{binding.js → core/binding.js} +27 -12
  21. package/dist/core/binding.js.map +1 -0
  22. package/dist/core/constraint-requirement.d.ts +53 -0
  23. package/dist/core/constraint-requirement.d.ts.map +1 -0
  24. package/dist/core/constraint-requirement.js +62 -0
  25. package/dist/core/constraint-requirement.js.map +1 -0
  26. package/dist/{constructor-type.d.ts → core/constructor-type.d.ts} +1 -1
  27. package/dist/core/constructor-type.d.ts.map +1 -0
  28. package/dist/core/constructor-type.js.map +1 -0
  29. package/dist/{module.d.ts → core/module.d.ts} +5 -5
  30. package/dist/core/module.d.ts.map +1 -0
  31. package/dist/{module.js → core/module.js} +4 -4
  32. package/dist/core/module.js.map +1 -0
  33. package/dist/{registry.d.ts → core/registry.d.ts} +27 -7
  34. package/dist/core/registry.d.ts.map +1 -0
  35. package/dist/{registry.js → core/registry.js} +125 -52
  36. package/dist/core/registry.js.map +1 -0
  37. package/dist/core/tag.d.ts +80 -0
  38. package/dist/core/tag.d.ts.map +1 -0
  39. package/dist/core/tag.js +96 -0
  40. package/dist/core/tag.js.map +1 -0
  41. package/dist/{token.d.ts → core/token.d.ts} +2 -6
  42. package/dist/core/token.d.ts.map +1 -0
  43. package/dist/core/token.js +13 -0
  44. package/dist/core/token.js.map +1 -0
  45. package/dist/{types.d.ts → core/types.d.ts} +27 -21
  46. package/dist/core/types.d.ts.map +1 -0
  47. package/dist/core/types.js.map +1 -0
  48. package/dist/decorators/inject.d.ts +5 -49
  49. package/dist/decorators/inject.d.ts.map +1 -1
  50. package/dist/decorators/inject.js +34 -104
  51. package/dist/decorators/inject.js.map +1 -1
  52. package/dist/decorators/injectable.d.ts +25 -5
  53. package/dist/decorators/injectable.d.ts.map +1 -1
  54. package/dist/decorators/injectable.js +2 -3
  55. package/dist/decorators/injectable.js.map +1 -1
  56. package/dist/decorators/lifecycle-decorators.d.ts +4 -2
  57. package/dist/decorators/lifecycle-decorators.d.ts.map +1 -1
  58. package/dist/decorators/lifecycle-decorators.js +19 -25
  59. package/dist/decorators/lifecycle-decorators.js.map +1 -1
  60. package/dist/{resolution → errors}/diagnostics.d.ts +2 -0
  61. package/dist/errors/diagnostics.d.ts.map +1 -0
  62. package/dist/errors/diagnostics.js.map +1 -0
  63. package/dist/{errors.d.ts → errors/errors.d.ts} +89 -4
  64. package/dist/errors/errors.d.ts.map +1 -0
  65. package/dist/{errors.js → errors/errors.js} +129 -7
  66. package/dist/errors/errors.js.map +1 -0
  67. package/dist/index.d.ts +21 -14
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +15 -7
  70. package/dist/index.js.map +1 -1
  71. package/dist/injection/descriptor.d.ts +79 -0
  72. package/dist/injection/descriptor.d.ts.map +1 -0
  73. package/dist/injection/descriptor.js +118 -0
  74. package/dist/injection/descriptor.js.map +1 -0
  75. package/dist/{resolution → injection}/resolve-options.d.ts +21 -11
  76. package/dist/injection/resolve-options.d.ts.map +1 -0
  77. package/dist/injection/resolve-options.js +101 -0
  78. package/dist/injection/resolve-options.js.map +1 -0
  79. package/dist/introspection/dependency-graph.d.ts +16 -5
  80. package/dist/introspection/dependency-graph.d.ts.map +1 -1
  81. package/dist/introspection/dependency-graph.js +138 -57
  82. package/dist/introspection/dependency-graph.js.map +1 -1
  83. package/dist/introspection/graph-adapters/cytoscape.d.ts +6 -3
  84. package/dist/introspection/graph-adapters/cytoscape.d.ts.map +1 -1
  85. package/dist/introspection/graph-adapters/cytoscape.js +3 -0
  86. package/dist/introspection/graph-adapters/cytoscape.js.map +1 -1
  87. package/dist/introspection/graph-adapters/dot.d.ts.map +1 -1
  88. package/dist/introspection/graph-adapters/dot.js +12 -5
  89. package/dist/introspection/graph-adapters/dot.js.map +1 -1
  90. package/dist/introspection/graph-adapters/mermaid.d.ts +9 -0
  91. package/dist/introspection/graph-adapters/mermaid.d.ts.map +1 -0
  92. package/dist/introspection/graph-adapters/mermaid.js +47 -0
  93. package/dist/introspection/graph-adapters/mermaid.js.map +1 -0
  94. package/dist/introspection/graph-adapters/reactflow.d.ts +6 -3
  95. package/dist/introspection/graph-adapters/reactflow.d.ts.map +1 -1
  96. package/dist/introspection/graph-adapters/reactflow.js +5 -1
  97. package/dist/introspection/graph-adapters/reactflow.js.map +1 -1
  98. package/dist/introspection/inspector.d.ts +4 -4
  99. package/dist/introspection/inspector.d.ts.map +1 -1
  100. package/dist/introspection/inspector.js +10 -6
  101. package/dist/introspection/inspector.js.map +1 -1
  102. package/dist/lifecycle/lifecycle-manager.d.ts +27 -0
  103. package/dist/lifecycle/lifecycle-manager.d.ts.map +1 -0
  104. package/dist/{resolution/lifecycle.js → lifecycle/lifecycle-manager.js} +39 -9
  105. package/dist/lifecycle/lifecycle-manager.js.map +1 -0
  106. package/dist/lifecycle/scope-manager.d.ts +48 -0
  107. package/dist/lifecycle/scope-manager.d.ts.map +1 -0
  108. package/dist/lifecycle/scope-manager.js +135 -0
  109. package/dist/lifecycle/scope-manager.js.map +1 -0
  110. package/dist/metadata/metadata-reader-token.d.ts +1 -1
  111. package/dist/metadata/metadata-reader-token.d.ts.map +1 -1
  112. package/dist/metadata/metadata-reader-token.js +1 -1
  113. package/dist/metadata/metadata-reader-token.js.map +1 -1
  114. package/dist/metadata/metadata-types.d.ts +9 -9
  115. package/dist/metadata/metadata-types.d.ts.map +1 -1
  116. package/dist/metadata/symbol-metadata-reader.d.ts +19 -6
  117. package/dist/metadata/symbol-metadata-reader.d.ts.map +1 -1
  118. package/dist/metadata/symbol-metadata-reader.js +89 -9
  119. package/dist/metadata/symbol-metadata-reader.js.map +1 -1
  120. package/dist/metadata/verifying-metadata-reader.d.ts +16 -0
  121. package/dist/metadata/verifying-metadata-reader.d.ts.map +1 -0
  122. package/dist/metadata/verifying-metadata-reader.js +32 -0
  123. package/dist/metadata/verifying-metadata-reader.js.map +1 -0
  124. package/dist/resolution/{activation-need.d.ts → cache/activation-need.d.ts} +5 -5
  125. package/dist/resolution/cache/activation-need.d.ts.map +1 -0
  126. package/dist/resolution/cache/activation-need.js.map +1 -0
  127. package/dist/resolution/{binding-lookup-cache.d.ts → cache/binding-lookup-cache.d.ts} +9 -5
  128. package/dist/resolution/cache/binding-lookup-cache.d.ts.map +1 -0
  129. package/dist/resolution/{binding-lookup-cache.js → cache/binding-lookup-cache.js} +55 -0
  130. package/dist/resolution/cache/binding-lookup-cache.js.map +1 -0
  131. package/dist/resolution/cache/class-introspector.d.ts +66 -0
  132. package/dist/resolution/cache/class-introspector.d.ts.map +1 -0
  133. package/dist/resolution/cache/class-introspector.js +194 -0
  134. package/dist/resolution/cache/class-introspector.js.map +1 -0
  135. package/dist/resolution/context.d.ts +84 -0
  136. package/dist/resolution/context.d.ts.map +1 -0
  137. package/dist/resolution/{environment.js → context.js} +54 -80
  138. package/dist/resolution/context.js.map +1 -0
  139. package/dist/resolution/path/resolution-path.d.ts +94 -0
  140. package/dist/resolution/path/resolution-path.d.ts.map +1 -0
  141. package/dist/resolution/path/resolution-path.js +117 -0
  142. package/dist/resolution/path/resolution-path.js.map +1 -0
  143. package/dist/resolution/{instantiation-plan.d.ts → plan/instantiation-plan.d.ts} +37 -7
  144. package/dist/resolution/plan/instantiation-plan.d.ts.map +1 -0
  145. package/dist/resolution/plan/instantiation-plan.js +419 -0
  146. package/dist/resolution/plan/instantiation-plan.js.map +1 -0
  147. package/dist/resolution/resolver.d.ts +28 -28
  148. package/dist/resolution/resolver.d.ts.map +1 -1
  149. package/dist/resolution/resolver.js +581 -239
  150. package/dist/resolution/resolver.js.map +1 -1
  151. package/dist/resolution/select/binding-select.d.ts +34 -0
  152. package/dist/resolution/select/binding-select.d.ts.map +1 -0
  153. package/dist/resolution/select/binding-select.js +175 -0
  154. package/dist/resolution/select/binding-select.js.map +1 -0
  155. package/dist/resolution/{constraints.d.ts → select/constraints.d.ts} +13 -12
  156. package/dist/resolution/select/constraints.d.ts.map +1 -0
  157. package/dist/resolution/{constraints.js → select/constraints.js} +33 -22
  158. package/dist/resolution/select/constraints.js.map +1 -0
  159. package/package.json +160 -20
  160. package/src/ambient/active-container.ts +65 -0
  161. package/src/container/binding-builders.ts +79 -44
  162. package/src/container/container.ts +357 -170
  163. package/src/{resolution → core}/binding-scope.ts +2 -2
  164. package/src/{binding.ts → core/binding.ts} +101 -39
  165. package/src/core/constraint-requirement.ts +94 -0
  166. package/src/{constructor-type.ts → core/constructor-type.ts} +1 -1
  167. package/src/{module.ts → core/module.ts} +10 -10
  168. package/src/core/registry.ts +365 -0
  169. package/src/core/tag.ts +158 -0
  170. package/src/{token.ts → core/token.ts} +2 -14
  171. package/src/{types.ts → core/types.ts} +37 -34
  172. package/src/decorators/inject.ts +39 -175
  173. package/src/decorators/injectable.ts +40 -10
  174. package/src/decorators/lifecycle-decorators.ts +22 -34
  175. package/src/{resolution → errors}/diagnostics.ts +2 -0
  176. package/src/{errors.ts → errors/errors.ts} +152 -8
  177. package/src/index.ts +43 -15
  178. package/src/injection/descriptor.ts +206 -0
  179. package/src/injection/resolve-options.ts +144 -0
  180. package/src/introspection/dependency-graph.ts +223 -63
  181. package/src/introspection/graph-adapters/cytoscape.ts +9 -3
  182. package/src/introspection/graph-adapters/dot.ts +13 -5
  183. package/src/introspection/graph-adapters/mermaid.ts +61 -0
  184. package/src/introspection/graph-adapters/reactflow.ts +11 -4
  185. package/src/introspection/inspector.ts +16 -12
  186. package/src/{resolution/lifecycle.ts → lifecycle/lifecycle-manager.ts} +68 -32
  187. package/src/lifecycle/scope-manager.ts +156 -0
  188. package/src/metadata/metadata-reader-token.ts +2 -2
  189. package/src/metadata/metadata-types.ts +9 -9
  190. package/src/metadata/symbol-metadata-reader.ts +95 -18
  191. package/src/metadata/verifying-metadata-reader.ts +41 -0
  192. package/src/resolution/{activation-need.ts → cache/activation-need.ts} +8 -8
  193. package/src/resolution/{binding-lookup-cache.ts → cache/binding-lookup-cache.ts} +63 -5
  194. package/src/resolution/cache/class-introspector.ts +251 -0
  195. package/src/resolution/{environment.ts → context.ts} +84 -145
  196. package/src/resolution/path/resolution-path.ts +167 -0
  197. package/src/resolution/plan/instantiation-plan.ts +615 -0
  198. package/src/resolution/resolver.ts +663 -313
  199. package/src/resolution/select/binding-select.ts +210 -0
  200. package/src/resolution/select/constraints.ts +130 -0
  201. package/dist/binding.d.ts.map +0 -1
  202. package/dist/binding.js.map +0 -1
  203. package/dist/constructor-type.d.ts.map +0 -1
  204. package/dist/constructor-type.js.map +0 -1
  205. package/dist/errors.d.ts.map +0 -1
  206. package/dist/errors.js.map +0 -1
  207. package/dist/module.d.ts.map +0 -1
  208. package/dist/module.js.map +0 -1
  209. package/dist/registry.d.ts.map +0 -1
  210. package/dist/registry.js.map +0 -1
  211. package/dist/resolution/activation-need.d.ts.map +0 -1
  212. package/dist/resolution/activation-need.js.map +0 -1
  213. package/dist/resolution/binding-lookup-cache.d.ts.map +0 -1
  214. package/dist/resolution/binding-lookup-cache.js.map +0 -1
  215. package/dist/resolution/binding-scope.d.ts.map +0 -1
  216. package/dist/resolution/binding-scope.js.map +0 -1
  217. package/dist/resolution/binding-select.d.ts +0 -23
  218. package/dist/resolution/binding-select.d.ts.map +0 -1
  219. package/dist/resolution/binding-select.js +0 -121
  220. package/dist/resolution/binding-select.js.map +0 -1
  221. package/dist/resolution/class-introspector.d.ts +0 -27
  222. package/dist/resolution/class-introspector.d.ts.map +0 -1
  223. package/dist/resolution/class-introspector.js +0 -60
  224. package/dist/resolution/class-introspector.js.map +0 -1
  225. package/dist/resolution/constraints.d.ts.map +0 -1
  226. package/dist/resolution/constraints.js.map +0 -1
  227. package/dist/resolution/diagnostics.d.ts.map +0 -1
  228. package/dist/resolution/diagnostics.js.map +0 -1
  229. package/dist/resolution/environment.d.ts +0 -94
  230. package/dist/resolution/environment.d.ts.map +0 -1
  231. package/dist/resolution/environment.js.map +0 -1
  232. package/dist/resolution/instantiation-plan.d.ts.map +0 -1
  233. package/dist/resolution/instantiation-plan.js +0 -183
  234. package/dist/resolution/instantiation-plan.js.map +0 -1
  235. package/dist/resolution/lifecycle.d.ts +0 -23
  236. package/dist/resolution/lifecycle.d.ts.map +0 -1
  237. package/dist/resolution/lifecycle.js.map +0 -1
  238. package/dist/resolution/resolution-path.d.ts +0 -98
  239. package/dist/resolution/resolution-path.d.ts.map +0 -1
  240. package/dist/resolution/resolution-path.js +0 -98
  241. package/dist/resolution/resolution-path.js.map +0 -1
  242. package/dist/resolution/resolve-options.d.ts.map +0 -1
  243. package/dist/resolution/resolve-options.js +0 -56
  244. package/dist/resolution/resolve-options.js.map +0 -1
  245. package/dist/resolution/scope.d.ts +0 -28
  246. package/dist/resolution/scope.d.ts.map +0 -1
  247. package/dist/resolution/scope.js +0 -88
  248. package/dist/resolution/scope.js.map +0 -1
  249. package/dist/token.d.ts.map +0 -1
  250. package/dist/token.js +0 -22
  251. package/dist/token.js.map +0 -1
  252. package/dist/types.d.ts.map +0 -1
  253. package/dist/types.js.map +0 -1
  254. package/src/registry.ts +0 -282
  255. package/src/resolution/binding-select.ts +0 -154
  256. package/src/resolution/class-introspector.ts +0 -74
  257. package/src/resolution/constraints.ts +0 -121
  258. package/src/resolution/instantiation-plan.ts +0 -292
  259. package/src/resolution/resolution-path.ts +0 -156
  260. package/src/resolution/resolve-options.ts +0 -89
  261. package/src/resolution/scope.ts +0 -105
  262. /package/dist/{resolution → core}/binding-scope.js +0 -0
  263. /package/dist/{constructor-type.js → core/constructor-type.js} +0 -0
  264. /package/dist/{types.js → core/types.js} +0 -0
  265. /package/dist/{resolution → errors}/diagnostics.js +0 -0
  266. /package/dist/resolution/{activation-need.js → cache/activation-need.js} +0 -0
@@ -0,0 +1,94 @@
1
+ import type { BindingIdentifier, ResolutionFrame } from "#/core/types";
2
+ /**
3
+ * Where the cycle check switches from a linear frame scan to an attached Set.
4
+ *
5
+ * @remarks Measured rather than guessed: below this depth the linear scan wins, above it the Set does.
6
+ *
7
+ * @since 0.5.0-canary.7
8
+ */
9
+ export declare const RESOLUTION_SET_THRESHOLD = 32;
10
+ /**
11
+ * The token names along a stack plus the frame that closed the cycle — built only to throw.
12
+ *
13
+ * @since 0.6.0
14
+ */
15
+ export declare function cycleNamesOf(resolutionStack: ReadonlyArray<ResolutionFrame>, closingName: string): Array<string>;
16
+ /**
17
+ * Marks a level as in-flight on this stack, throwing if its binding is already an ancestor.
18
+ *
19
+ * @remarks The check keys on binding identity — two distinct tokens may share a display name — and
20
+ * the names an error prints are derived from the frames at the throw site. Unmark by popping the
21
+ * stack plus `set?.delete(frame.bindingId)`. Sync only — the async lane never removes an entry, so
22
+ * it extends a branch instead; see {@link extendResolutionBranch}.
23
+ *
24
+ * @returns the membership set once the stack is deep enough to carry one, else `undefined`.
25
+ *
26
+ * @since 0.5.0-canary.7
27
+ */
28
+ export declare function enterResolutionPath(resolutionStack: Array<ResolutionFrame>, frame: ResolutionFrame): Set<BindingIdentifier> | undefined;
29
+ declare const BRANCH_BRAND: unique symbol;
30
+ /**
31
+ * A resolution stack one async branch owns, so appending to it cannot disturb another branch.
32
+ *
33
+ * @remarks Only {@link extendResolutionBranch} mints one. That is what makes "may this lane append
34
+ * to this array" a question the compiler answers instead of a rule in a doc — a sync frame's stack,
35
+ * which that frame will pop, is a plain `Array<ResolutionFrame>` and cannot reach a level that owns
36
+ * its own.
37
+ *
38
+ * @since 0.5.0-canary.9
39
+ */
40
+ export type OwnedBranchStack = Array<ResolutionFrame> & {
41
+ readonly [BRANCH_BRAND]: true;
42
+ };
43
+ declare const BRANCH_DEPTH_BRAND: unique symbol;
44
+ /**
45
+ * How many leading entries of a stack belong to one async branch.
46
+ *
47
+ * @remarks Branded so a bare number cannot be passed: a depth from anywhere but this branch silently
48
+ * re-parents a level.
49
+ *
50
+ * @since 0.5.0-canary.9
51
+ */
52
+ export type OwnedBranchDepth = number & {
53
+ readonly [BRANCH_DEPTH_BRAND]: true;
54
+ };
55
+ /**
56
+ * A stack no async branch owns yet, so its first extension must copy rather than append.
57
+ *
58
+ * @since 0.5.0-canary.9
59
+ */
60
+ export declare const UNOWNED_BRANCH = -1;
61
+ /**
62
+ * How far into a stack one extension may reach: this branch's own depth, or nobody's.
63
+ *
64
+ * @remarks A union rather than a sentinel hidden inside the branded number, so the two cases are
65
+ * visible at every signature that takes one and `=== UNOWNED_BRANCH` narrows to the owned case.
66
+ *
67
+ * @since 0.5.0-canary.9
68
+ */
69
+ export type BranchDepth = OwnedBranchDepth | typeof UNOWNED_BRANCH;
70
+ /**
71
+ * The depth a chain's first level extends from, over an array its caller just minted.
72
+ *
73
+ * @since 0.5.0-canary.9
74
+ */
75
+ export declare const ROOT_BRANCH: OwnedBranchDepth;
76
+ /**
77
+ * A branch's own depth: the length its stack had when this level took it.
78
+ *
79
+ * @since 0.5.0-canary.9
80
+ */
81
+ export declare function branchDepthOf(branch: OwnedBranchStack): OwnedBranchDepth;
82
+ /**
83
+ * Extends one branch of an append-only stack, throwing if the binding is already an ancestor.
84
+ *
85
+ * @remarks The check compares binding ids on the frames; the names an error prints are derived at
86
+ * the throw site. Appends in place while this branch still owns the next slot, and copies its own
87
+ * prefix once a sibling has claimed it. Nothing is ever removed, so no async level has to observe
88
+ * its own settlement to unwind.
89
+ *
90
+ * @since 0.5.0-canary.9
91
+ */
92
+ export declare function extendResolutionBranch(resolutionStack: Array<ResolutionFrame>, branchDepth: BranchDepth, frame: ResolutionFrame): OwnedBranchStack;
93
+ export {};
94
+ //# sourceMappingURL=resolution-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolution-path.d.ts","sourceRoot":"","sources":["../../../src/resolution/path/resolution-path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAKvE;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAG3C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,eAAe,EAAE,aAAa,CAAC,eAAe,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAOhH;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,eAAe,EAAE,KAAK,CAAC,eAAe,CAAC,EACvC,KAAK,EAAE,eAAe,GACrB,GAAG,CAAC,iBAAiB,CAAC,GAAG,SAAS,CA6BpC;AAED,OAAO,CAAC,MAAM,YAAY,EAAE,OAAO,MAAM,CAAC;AAE1C;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,eAAe,CAAC,GAAG;IAAE,QAAQ,CAAC,CAAC,YAAY,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAE1F,OAAO,CAAC,MAAM,kBAAkB,EAAE,OAAO,MAAM,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAEhF;;;;GAIG;AACH,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,OAAO,cAAc,CAAC;AAEnE;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAQ,gBAAgB,CAAC;AAEjD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAExE;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,eAAe,EAAE,KAAK,CAAC,eAAe,CAAC,EACvC,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,eAAe,GACrB,gBAAgB,CAkBlB"}
@@ -0,0 +1,117 @@
1
+ /** Cycle-detection bookkeeping carried on the resolution stack itself. */
2
+ import { CircularDependencyError } from "#/errors/errors";
3
+ const RESOLUTION_SET_KEY = Symbol("di:resolution-set");
4
+ /**
5
+ * Where the cycle check switches from a linear frame scan to an attached Set.
6
+ *
7
+ * @remarks Measured rather than guessed: below this depth the linear scan wins, above it the Set does.
8
+ *
9
+ * @since 0.5.0-canary.7
10
+ */
11
+ export const RESOLUTION_SET_THRESHOLD = 32;
12
+ /**
13
+ * The token names along a stack plus the frame that closed the cycle — built only to throw.
14
+ *
15
+ * @since 0.6.0
16
+ */
17
+ export function cycleNamesOf(resolutionStack, closingName) {
18
+ const names = new Array(resolutionStack.length + 1);
19
+ for (let index = 0; index < resolutionStack.length; index += 1) {
20
+ names[index] = resolutionStack[index].tokenName;
21
+ }
22
+ names[resolutionStack.length] = closingName;
23
+ return names;
24
+ }
25
+ /**
26
+ * Marks a level as in-flight on this stack, throwing if its binding is already an ancestor.
27
+ *
28
+ * @remarks The check keys on binding identity — two distinct tokens may share a display name — and
29
+ * the names an error prints are derived from the frames at the throw site. Unmark by popping the
30
+ * stack plus `set?.delete(frame.bindingId)`. Sync only — the async lane never removes an entry, so
31
+ * it extends a branch instead; see {@link extendResolutionBranch}.
32
+ *
33
+ * @returns the membership set once the stack is deep enough to carry one, else `undefined`.
34
+ *
35
+ * @since 0.5.0-canary.7
36
+ */
37
+ export function enterResolutionPath(resolutionStack, frame) {
38
+ const stackWithSet = resolutionStack;
39
+ let resolutionSet = stackWithSet[RESOLUTION_SET_KEY];
40
+ // A live set mirrors the stack exactly, so a size that disagrees means it is holding ids of
41
+ // frames that unwound: the ones already on the stack when it attached were handed no set to
42
+ // delete from. Dropped rather than repaired, because the next deep frame rebuilds it.
43
+ if (resolutionSet !== undefined && resolutionSet.size !== resolutionStack.length) {
44
+ resolutionSet = undefined;
45
+ stackWithSet[RESOLUTION_SET_KEY] = undefined;
46
+ }
47
+ if (resolutionSet === undefined && resolutionStack.length >= RESOLUTION_SET_THRESHOLD) {
48
+ resolutionSet = new Set();
49
+ for (let index = 0; index < resolutionStack.length; index += 1) {
50
+ resolutionSet.add(resolutionStack[index].bindingId);
51
+ }
52
+ stackWithSet[RESOLUTION_SET_KEY] = resolutionSet;
53
+ }
54
+ if (resolutionSet === undefined) {
55
+ for (let index = 0; index < resolutionStack.length; index += 1) {
56
+ if (resolutionStack[index].bindingId === frame.bindingId) {
57
+ throw new CircularDependencyError(cycleNamesOf(resolutionStack, frame.tokenName));
58
+ }
59
+ }
60
+ }
61
+ else if (resolutionSet.has(frame.bindingId)) {
62
+ throw new CircularDependencyError(cycleNamesOf(resolutionStack, frame.tokenName));
63
+ }
64
+ resolutionStack.push(frame);
65
+ resolutionSet?.add(frame.bindingId);
66
+ return resolutionSet;
67
+ }
68
+ /**
69
+ * A stack no async branch owns yet, so its first extension must copy rather than append.
70
+ *
71
+ * @since 0.5.0-canary.9
72
+ */
73
+ export const UNOWNED_BRANCH = -1;
74
+ /**
75
+ * The depth a chain's first level extends from, over an array its caller just minted.
76
+ *
77
+ * @since 0.5.0-canary.9
78
+ */
79
+ export const ROOT_BRANCH = 0;
80
+ /**
81
+ * A branch's own depth: the length its stack had when this level took it.
82
+ *
83
+ * @since 0.5.0-canary.9
84
+ */
85
+ export function branchDepthOf(branch) {
86
+ return branch.length;
87
+ }
88
+ /**
89
+ * Extends one branch of an append-only stack, throwing if the binding is already an ancestor.
90
+ *
91
+ * @remarks The check compares binding ids on the frames; the names an error prints are derived at
92
+ * the throw site. Appends in place while this branch still owns the next slot, and copies its own
93
+ * prefix once a sibling has claimed it. Nothing is ever removed, so no async level has to observe
94
+ * its own settlement to unwind.
95
+ *
96
+ * @since 0.5.0-canary.9
97
+ */
98
+ export function extendResolutionBranch(resolutionStack, branchDepth, frame) {
99
+ const depth = branchDepth === UNOWNED_BRANCH ? resolutionStack.length : branchDepth;
100
+ for (let index = 0; index < depth; index += 1) {
101
+ if (resolutionStack[index].bindingId === frame.bindingId) {
102
+ throw new CircularDependencyError(cycleNamesOf(resolutionStack.slice(0, depth), frame.tokenName));
103
+ }
104
+ }
105
+ // An unowned array belongs to a sync frame that will pop it, or carries a membership Set this
106
+ // lane cannot keep true; copying is what makes the branch's own appends safe.
107
+ if (branchDepth === resolutionStack.length) {
108
+ // The sole mint: appending in place needs a depth that came from a branch already owned, or
109
+ // ROOT_BRANCH over an array its caller minted for this chain alone.
110
+ resolutionStack.push(frame);
111
+ return resolutionStack;
112
+ }
113
+ const branch = resolutionStack.slice(0, depth);
114
+ branch.push(frame);
115
+ return branch;
116
+ }
117
+ //# sourceMappingURL=resolution-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolution-path.js","sourceRoot":"","sources":["../../../src/resolution/path/resolution-path.ts"],"names":[],"mappings":"AACA,0EAA0E;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,MAAM,kBAAkB,GAAkB,MAAM,CAAC,mBAAmB,CAAC,CAAC;AACtE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAG3C;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,eAA+C,EAAE,WAAmB;IAC/F,MAAM,KAAK,GAAG,IAAI,KAAK,CAAS,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC5D,KAAK,IAAI,KA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K,CAAC,SAAS,CAAC,CAAC,CAAC;QACpG,CAAC;IACH,CAAC;IACD,8FAA8F;IAC9F,8EAA8E;IAC9E,IAAI,WAAW,KAAK,eAAe,CAAC,MAAM,EAAE,CAAC;QAC3C,4FAA4F;QAC5F,oEAAoE;QACpE,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5B,OAAO,eAAmC,CAAC;IAC7C,CAAC;IACD,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC/C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,OAAO,MAA0B,CAAC;AACpC,CAAC"}
@@ -1,12 +1,13 @@
1
1
  /**
2
2
  * Compiles a transient class or resolved-factory binding into a nested-constructor closure.
3
3
  *
4
- * @see `ARCHITECTURE.md` — the escape contract every dependency the compiler cannot inline must honour.
4
+ * @remarks A dependency the compiler cannot inline escapes to a resolver callback instead; the
5
+ * closure must stay callable for it, which is what bounds what may be inlined.
5
6
  */
6
- import type { Binding } from "#/binding";
7
+ import type { Binding } from "#/core/binding";
8
+ import type { Token } from "#/core/token";
9
+ import type { Constructor, ResolutionFrame, ResolveOptions } from "#/core/types";
7
10
  import type { ConstructorMetadata } from "#/metadata/metadata-types";
8
- import type { Token } from "#/token";
9
- import type { Constructor, ResolutionFrame, ResolveOptions } from "#/types";
10
11
  /**
11
12
  * Compilation asked to retry later (class lifecycle metadata not discovered yet).
12
13
  *
@@ -35,17 +36,36 @@ export interface InstantiationPlanDependencyEntry {
35
36
  * @since 0.5.0-canary.7
36
37
  */
37
38
  export interface InstantiationPlanHost {
38
- hasActivationHandlers(token: Token<unknown> | Constructor): boolean;
39
+ /** Owner-aware: container-level hooks belong to the binding's owner, which may be a parent. */
40
+ hasActivationHandlers(binding: Binding): boolean;
39
41
  /** Cached postConstruct presence — `undefined` until a runtime resolve discovers it. */
40
42
  knownPostConstruct(target: Constructor): boolean | undefined;
41
43
  needsActiveContainer(target: Constructor): boolean;
42
44
  getConstructorMetadata(target: Constructor): ConstructorMetadata | undefined;
43
45
  /** Options-less lookup with alias hops folded; `null` when the fast lane can't answer. */
44
46
  lookupDependencyEntry(token: Token<unknown> | Constructor): InstantiationPlanDependencyEntry | null;
47
+ /**
48
+ * A name-only lookup a plan may bake in, or `null` when the answer is not the compiler's to make.
49
+ *
50
+ * @remarks Selection for a named request is an index hit *and* a predicate, and a predicate reads
51
+ * the resolution path — so only a candidate carrying none of one can be decided ahead of time.
52
+ */
53
+ lookupPathIndependentNamedEntry(token: Token<unknown> | Constructor, options: ResolveOptions & {
54
+ name: string;
55
+ }): InstantiationPlanDependencyEntry | null;
56
+ /**
57
+ * The named lookup's single-tag twin, or `null` under the same rule.
58
+ *
59
+ * @remarks Optional so a host predating it stays a valid host — a compiler given none simply
60
+ * escapes the dependency, which is exactly the pre-settlement behavior.
61
+ */
62
+ lookupPathIndependentTaggedEntry?(token: Token<unknown> | Constructor, options: ResolveOptions): InstantiationPlanDependencyEntry | null;
45
63
  /** The frame the interpreted path pushes for this binding, so escapes can replay it. */
46
64
  getResolutionFrame(binding: Binding): ResolutionFrame;
47
- /** Runtime resolve for an escaped dependency, seeded with the ancestors above it. */
48
- resolveEscaped(token: Token<unknown> | Constructor, options: ResolveOptions | undefined, arity: EscapeArity, resolutionPath: Array<string>, resolutionStack: Array<ResolutionFrame>): unknown;
65
+ /** Runtime resolve for an escaped dependency, seeded with the ancestor frames above it. */
66
+ resolveEscaped(token: Token<unknown> | Constructor, options: ResolveOptions | undefined, arity: EscapeArity, resolutionStack: Array<ResolutionFrame>): unknown;
67
+ /** The async counterpart of {@link InstantiationPlanHost.resolveEscaped}, replaying the async dispatch. */
68
+ resolveEscapedAsync(token: Token<unknown> | Constructor, options: ResolveOptions | undefined, arity: EscapeArity, resolutionStack: Array<ResolutionFrame>): Promise<unknown>;
49
69
  }
50
70
  /**
51
71
  * Which resolve an escaped dependency replays — mirrors how the interpreted path dispatches
@@ -63,5 +83,15 @@ export declare class InstantiationPlanCompiler {
63
83
  compile(binding: Binding & {
64
84
  kind: "class" | "resolved";
65
85
  }): InstantiationPlanCompileResult;
86
+ /**
87
+ * Compiles a transient binding whose graph is statically visible, for the async entry point.
88
+ *
89
+ * @remarks Same gates as the sync lane; the differences are downstream — escapes replay the async
90
+ * dispatch, and a node whose dependencies may yield promises awaits them together, exactly as the
91
+ * interpreted async path does.
92
+ */
93
+ compileAsync(binding: Binding & {
94
+ kind: "class" | "resolved" | "resolved-async";
95
+ }): InstantiationPlanCompileResult;
66
96
  }
67
97
  //# sourceMappingURL=instantiation-plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instantiation-plan.d.ts","sourceRoot":"","sources":["../../../src/resolution/plan/instantiation-plan.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAIjF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAMrE;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,OAAO,MAAgC,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,MAAM,8BAA8B,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,IAAI,GAAG,OAAO,UAAU,CAAC;AA0DxF;;;;GAIG;AACH,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,+FAA+F;IAC/F,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;IACjD,wFAAwF;IACxF,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,GAAG,SAAS,CAAC;IAC7D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