@graphrefly/ts 0.0.0

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 (210) hide show
  1. package/LICENSE +21 -0
  2. package/dist/adapters/index.cjs +9015 -0
  3. package/dist/adapters/index.cjs.map +1 -0
  4. package/dist/adapters/index.d.cts +678 -0
  5. package/dist/adapters/index.d.ts +678 -0
  6. package/dist/adapters/index.js +2894 -0
  7. package/dist/adapters/index.js.map +1 -0
  8. package/dist/adapters/observe-storage.cjs +260 -0
  9. package/dist/adapters/observe-storage.cjs.map +1 -0
  10. package/dist/adapters/observe-storage.d.cts +77 -0
  11. package/dist/adapters/observe-storage.d.ts +77 -0
  12. package/dist/adapters/observe-storage.js +161 -0
  13. package/dist/adapters/observe-storage.js.map +1 -0
  14. package/dist/append-log-DisvEReb.d.cts +189 -0
  15. package/dist/append-log-DzKMmjxx.d.ts +189 -0
  16. package/dist/chunk-2ILL7HQI.js +1189 -0
  17. package/dist/chunk-2ILL7HQI.js.map +1 -0
  18. package/dist/chunk-4VLAQHZI.js +330 -0
  19. package/dist/chunk-4VLAQHZI.js.map +1 -0
  20. package/dist/chunk-6PHB5CJS.js +229 -0
  21. package/dist/chunk-6PHB5CJS.js.map +1 -0
  22. package/dist/chunk-COHO25CZ.js +2449 -0
  23. package/dist/chunk-COHO25CZ.js.map +1 -0
  24. package/dist/chunk-D6BG7U6A.js +161 -0
  25. package/dist/chunk-D6BG7U6A.js.map +1 -0
  26. package/dist/chunk-DJC4CHLQ.js +818 -0
  27. package/dist/chunk-DJC4CHLQ.js.map +1 -0
  28. package/dist/chunk-DK554R7P.js +67 -0
  29. package/dist/chunk-DK554R7P.js.map +1 -0
  30. package/dist/chunk-DKP56CSW.js +322 -0
  31. package/dist/chunk-DKP56CSW.js.map +1 -0
  32. package/dist/chunk-G4M3NHRJ.js +688 -0
  33. package/dist/chunk-G4M3NHRJ.js.map +1 -0
  34. package/dist/chunk-GAJW5I5P.js +1 -0
  35. package/dist/chunk-GAJW5I5P.js.map +1 -0
  36. package/dist/chunk-GDL26N2T.js +282 -0
  37. package/dist/chunk-GDL26N2T.js.map +1 -0
  38. package/dist/chunk-GTPCOEOZ.js +741 -0
  39. package/dist/chunk-GTPCOEOZ.js.map +1 -0
  40. package/dist/chunk-H2HTHFVN.js +1 -0
  41. package/dist/chunk-H2HTHFVN.js.map +1 -0
  42. package/dist/chunk-HDRL4VQQ.js +218 -0
  43. package/dist/chunk-HDRL4VQQ.js.map +1 -0
  44. package/dist/chunk-I3IHOHCJ.js +2267 -0
  45. package/dist/chunk-I3IHOHCJ.js.map +1 -0
  46. package/dist/chunk-JIMUDQN3.js +965 -0
  47. package/dist/chunk-JIMUDQN3.js.map +1 -0
  48. package/dist/chunk-JR4IKCR2.js +462 -0
  49. package/dist/chunk-JR4IKCR2.js.map +1 -0
  50. package/dist/chunk-K3FXTC3I.js +165 -0
  51. package/dist/chunk-K3FXTC3I.js.map +1 -0
  52. package/dist/chunk-OOEN33FB.js +65 -0
  53. package/dist/chunk-OOEN33FB.js.map +1 -0
  54. package/dist/chunk-PKVBHGBM.js +554 -0
  55. package/dist/chunk-PKVBHGBM.js.map +1 -0
  56. package/dist/chunk-RIIOUTGM.js +1857 -0
  57. package/dist/chunk-RIIOUTGM.js.map +1 -0
  58. package/dist/chunk-SCRFRCGR.js +33 -0
  59. package/dist/chunk-SCRFRCGR.js.map +1 -0
  60. package/dist/chunk-SWTLEQL6.js +53 -0
  61. package/dist/chunk-SWTLEQL6.js.map +1 -0
  62. package/dist/chunk-SZAETNNA.js +1 -0
  63. package/dist/chunk-SZAETNNA.js.map +1 -0
  64. package/dist/chunk-TEW47IVR.js +49 -0
  65. package/dist/chunk-TEW47IVR.js.map +1 -0
  66. package/dist/chunk-Y3ZLRGHC.js +1482 -0
  67. package/dist/chunk-Y3ZLRGHC.js.map +1 -0
  68. package/dist/chunk-Z2ANQ6JW.js +149 -0
  69. package/dist/chunk-Z2ANQ6JW.js.map +1 -0
  70. package/dist/codec-BB7p8fJc.d.cts +38 -0
  71. package/dist/codec-BB7p8fJc.d.ts +38 -0
  72. package/dist/composition/index.cjs +2505 -0
  73. package/dist/composition/index.cjs.map +1 -0
  74. package/dist/composition/index.d.cts +95 -0
  75. package/dist/composition/index.d.ts +95 -0
  76. package/dist/composition/index.js +19 -0
  77. package/dist/composition/index.js.map +1 -0
  78. package/dist/core/index.cjs +2475 -0
  79. package/dist/core/index.cjs.map +1 -0
  80. package/dist/core/index.d.cts +25 -0
  81. package/dist/core/index.d.ts +25 -0
  82. package/dist/core/index.js +74 -0
  83. package/dist/core/index.js.map +1 -0
  84. package/dist/cqrs/index.cjs +595 -0
  85. package/dist/cqrs/index.cjs.map +1 -0
  86. package/dist/cqrs/index.d.cts +200 -0
  87. package/dist/cqrs/index.d.ts +200 -0
  88. package/dist/cqrs/index.js +557 -0
  89. package/dist/cqrs/index.js.map +1 -0
  90. package/dist/data-structures/index.cjs +4277 -0
  91. package/dist/data-structures/index.cjs.map +1 -0
  92. package/dist/data-structures/index.d.cts +22 -0
  93. package/dist/data-structures/index.d.ts +22 -0
  94. package/dist/data-structures/index.js +31 -0
  95. package/dist/data-structures/index.js.map +1 -0
  96. package/dist/describe-BZb7AS2y.d.ts +57 -0
  97. package/dist/describe-Ciu8SUnN.d.cts +57 -0
  98. package/dist/graph/index.cjs +7832 -0
  99. package/dist/graph/index.cjs.map +1 -0
  100. package/dist/graph/index.d.cts +251 -0
  101. package/dist/graph/index.d.ts +251 -0
  102. package/dist/graph/index.js +131 -0
  103. package/dist/graph/index.js.map +1 -0
  104. package/dist/graph-DfdF9zy4.d.ts +666 -0
  105. package/dist/graph-s23RbbFO.d.cts +666 -0
  106. package/dist/index-CAEmLCYF.d.cts +166 -0
  107. package/dist/index-SnzZu3x7.d.ts +166 -0
  108. package/dist/index.cjs +15409 -0
  109. package/dist/index.cjs.map +1 -0
  110. package/dist/index.d.cts +23 -0
  111. package/dist/index.d.ts +23 -0
  112. package/dist/index.js +582 -0
  113. package/dist/index.js.map +1 -0
  114. package/dist/messages-BZqrGGm1.d.cts +55 -0
  115. package/dist/messages-BZqrGGm1.d.ts +55 -0
  116. package/dist/messaging/index.cjs +818 -0
  117. package/dist/messaging/index.cjs.map +1 -0
  118. package/dist/messaging/index.d.cts +235 -0
  119. package/dist/messaging/index.d.ts +235 -0
  120. package/dist/messaging/index.js +767 -0
  121. package/dist/messaging/index.js.map +1 -0
  122. package/dist/observe-event-log-0SVsx7JG.d.cts +88 -0
  123. package/dist/observe-event-log-Dnm76owp.d.ts +88 -0
  124. package/dist/operators/index.cjs +3774 -0
  125. package/dist/operators/index.cjs.map +1 -0
  126. package/dist/operators/index.d.cts +308 -0
  127. package/dist/operators/index.d.ts +308 -0
  128. package/dist/operators/index.js +112 -0
  129. package/dist/operators/index.js.map +1 -0
  130. package/dist/orchestration/index.cjs +3541 -0
  131. package/dist/orchestration/index.cjs.map +1 -0
  132. package/dist/orchestration/index.d.cts +302 -0
  133. package/dist/orchestration/index.d.ts +302 -0
  134. package/dist/orchestration/index.js +1004 -0
  135. package/dist/orchestration/index.js.map +1 -0
  136. package/dist/patterns/index.cjs +1045 -0
  137. package/dist/patterns/index.cjs.map +1 -0
  138. package/dist/patterns/index.d.cts +39 -0
  139. package/dist/patterns/index.d.ts +39 -0
  140. package/dist/patterns/index.js +33 -0
  141. package/dist/patterns/index.js.map +1 -0
  142. package/dist/reactive-collection-BxBqtIOE.d.cts +344 -0
  143. package/dist/reactive-collection-Cb1II1Fi.d.ts +344 -0
  144. package/dist/reactive-collection-storage-BNiEc-Gd.d.ts +217 -0
  145. package/dist/reactive-collection-storage-D-KmjE0J.d.cts +217 -0
  146. package/dist/reactive-map-BcB4KsQR.d.ts +256 -0
  147. package/dist/reactive-map-D-g3dv8I.d.cts +256 -0
  148. package/dist/read-through-B1CYPfq_.d.cts +82 -0
  149. package/dist/read-through-DwyJhGs1.d.ts +82 -0
  150. package/dist/render/index.cjs +250 -0
  151. package/dist/render/index.cjs.map +1 -0
  152. package/dist/render/index.d.cts +58 -0
  153. package/dist/render/index.d.ts +58 -0
  154. package/dist/render/index.js +20 -0
  155. package/dist/render/index.js.map +1 -0
  156. package/dist/resilience-Dig3Q7n0.d.cts +45 -0
  157. package/dist/resilience-Dig3Q7n0.d.ts +45 -0
  158. package/dist/semantic-memory-graph-BYoIlP35.d.cts +356 -0
  159. package/dist/semantic-memory-graph-CxyXLms3.d.ts +356 -0
  160. package/dist/solutions/index.cjs +3249 -0
  161. package/dist/solutions/index.cjs.map +1 -0
  162. package/dist/solutions/index.d.cts +520 -0
  163. package/dist/solutions/index.d.ts +520 -0
  164. package/dist/solutions/index.js +31 -0
  165. package/dist/solutions/index.js.map +1 -0
  166. package/dist/sources/browser.cjs +3095 -0
  167. package/dist/sources/browser.cjs.map +1 -0
  168. package/dist/sources/browser.d.cts +39 -0
  169. package/dist/sources/browser.d.ts +39 -0
  170. package/dist/sources/browser.js +137 -0
  171. package/dist/sources/browser.js.map +1 -0
  172. package/dist/sources/index.cjs +3021 -0
  173. package/dist/sources/index.cjs.map +1 -0
  174. package/dist/sources/index.d.cts +7 -0
  175. package/dist/sources/index.d.ts +7 -0
  176. package/dist/sources/index.js +63 -0
  177. package/dist/sources/index.js.map +1 -0
  178. package/dist/sources/node.cjs +675 -0
  179. package/dist/sources/node.cjs.map +1 -0
  180. package/dist/sources/node.d.cts +109 -0
  181. package/dist/sources/node.d.ts +109 -0
  182. package/dist/sources/node.js +639 -0
  183. package/dist/sources/node.js.map +1 -0
  184. package/dist/storage/browser.cjs +777 -0
  185. package/dist/storage/browser.cjs.map +1 -0
  186. package/dist/storage/browser.d.cts +40 -0
  187. package/dist/storage/browser.d.ts +40 -0
  188. package/dist/storage/browser.js +275 -0
  189. package/dist/storage/browser.js.map +1 -0
  190. package/dist/storage/index.cjs +1989 -0
  191. package/dist/storage/index.cjs.map +1 -0
  192. package/dist/storage/index.d.cts +92 -0
  193. package/dist/storage/index.d.ts +92 -0
  194. package/dist/storage/index.js +161 -0
  195. package/dist/storage/index.js.map +1 -0
  196. package/dist/storage/node.cjs +898 -0
  197. package/dist/storage/node.cjs.map +1 -0
  198. package/dist/storage/node.d.cts +66 -0
  199. package/dist/storage/node.d.ts +66 -0
  200. package/dist/storage/node.js +402 -0
  201. package/dist/storage/node.js.map +1 -0
  202. package/dist/testing/index.cjs +95 -0
  203. package/dist/testing/index.cjs.map +1 -0
  204. package/dist/testing/index.d.cts +20 -0
  205. package/dist/testing/index.d.ts +20 -0
  206. package/dist/testing/index.js +8 -0
  207. package/dist/testing/index.js.map +1 -0
  208. package/dist/types-bNMSWKqF.d.cts +732 -0
  209. package/dist/types-h12mNYbq.d.ts +732 -0
  210. package/package.json +250 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/graph/composition.ts"],"sourcesContent":["/**\n * CSP-2.8 composition helpers (D56).\n *\n * These are graph-layer, per-language helpers (D6/D24), not protocol primitives. The first cut is\n * intentionally static: branch nodes are declared at construction time, with real dep edges\n * `[source, rules]` that `describe()` can show. Dynamic rule add/remove is deferred by D56.\n */\n\nimport {\n\ttype Ctx,\n\tdepBatch,\n\tdepLatest,\n\tdepTerminal,\n\tisTerminalComplete,\n\tisTerminalError,\n\tterminalErrorValue,\n} from \"../ctx/types.js\";\nimport type { Node, NodeOptions } from \"../node/node.js\";\nimport type { DescribeEdge, DescribeNode, DescribeSnapshot } from \"./describe.js\";\nimport type { Graph, StateNode, SugarOpts } from \"./graph.js\";\nimport { initNode, type Operator } from \"./operators.js\";\n\n/** One unary operator step accepted by {@link pipe}. */\nexport type PipeOperator<TIn, TOut> = Operator<TIn, TOut>;\n\nexport type DescribeEvent =\n\t| { readonly type: \"node-added\"; readonly id: string; readonly node: DescribeNode }\n\t| { readonly type: \"node-removed\"; readonly id: string }\n\t| {\n\t\t\treadonly type: \"node-meta-changed\";\n\t\t\treadonly id: string;\n\t\t\treadonly prevMeta: Record<string, unknown>;\n\t\t\treadonly nextMeta: Record<string, unknown>;\n\t }\n\t| { readonly type: \"edge-added\"; readonly from: string; readonly to: string }\n\t| { readonly type: \"edge-removed\"; readonly from: string; readonly to: string }\n\t| { readonly type: \"subgraph-mounted\"; readonly path: string }\n\t| { readonly type: \"subgraph-unmounted\"; readonly path: string };\n\nexport interface DescribeChangeset {\n\treadonly events: readonly DescribeEvent[];\n}\n\nfunction metaEqual(a: unknown, b: unknown): boolean {\n\tif (Object.is(a, b)) return true;\n\tif (a == null || b == null || typeof a !== \"object\" || typeof b !== \"object\") return false;\n\tif (Array.isArray(a) || Array.isArray(b)) {\n\t\tif (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;\n\t\tfor (let i = 0; i < a.length; i++) if (!metaEqual(a[i], b[i])) return false;\n\t\treturn true;\n\t}\n\tconst ak = Object.keys(a as Record<string, unknown>).sort();\n\tconst bk = Object.keys(b as Record<string, unknown>).sort();\n\tif (ak.length !== bk.length) return false;\n\tfor (let i = 0; i < ak.length; i++) {\n\t\tif (ak[i] !== bk[i]) return false;\n\t\tif (!metaEqual((a as Record<string, unknown>)[ak[i]], (b as Record<string, unknown>)[bk[i]]))\n\t\t\treturn false;\n\t}\n\treturn true;\n}\n\nfunction edgeKey(e: DescribeEdge): string {\n\treturn `${e.from}\\0${e.to}`;\n}\n\nfunction cloneNode(n: DescribeNode): DescribeNode {\n\treturn {\n\t\t...n,\n\t\tdeps: [...n.deps],\n\t\t...(n.meta ? { meta: { ...n.meta } } : {}),\n\t};\n}\n\nfunction flattenSnapshot(snap: DescribeSnapshot): {\n\tnodes: Map<string, DescribeNode>;\n\tedges: Map<string, DescribeEdge>;\n\tsubgraphs: Set<string>;\n} {\n\tconst nodes = new Map<string, DescribeNode>();\n\tconst edges = new Map<string, DescribeEdge>();\n\tconst subgraphs = new Set<string>();\n\tconst visit = (s: DescribeSnapshot, indexPath = \"\"): void => {\n\t\tfor (const n of s.nodes) nodes.set(n.id, n);\n\t\tfor (const e of s.edges) edges.set(edgeKey(e), e);\n\t\ts.subgraphs?.forEach((child, i) => {\n\t\t\tconst prefixed = child.nodes.find((n) => n.id.includes(\"::\"))?.id;\n\t\t\tconst key =\n\t\t\t\tprefixed?.slice(0, prefixed.lastIndexOf(\"::\")) ??\n\t\t\t\t(child.name ? `${indexPath}${child.name}` : `${indexPath}${i}`);\n\t\t\tsubgraphs.add(key);\n\t\t\tvisit(child, `${key}/`);\n\t\t});\n\t};\n\tvisit(snap);\n\treturn { nodes, edges, subgraphs };\n}\n\n/**\n * Pure topology delta from one D39 `describe()` snapshot to another. No node refs, no clocks, no\n * old-core deps (D56). Values/status changes are not topology events; use `observe()` for data.\n */\nexport function topologyDiff(prev: DescribeSnapshot, next: DescribeSnapshot): DescribeChangeset {\n\tconst p = flattenSnapshot(prev);\n\tconst n = flattenSnapshot(next);\n\tconst events: DescribeEvent[] = [];\n\n\tfor (const path of [...n.subgraphs].filter((x) => !p.subgraphs.has(x)).sort())\n\t\tevents.push({ type: \"subgraph-mounted\", path });\n\n\tfor (const id of [...n.nodes.keys()].filter((x) => !p.nodes.has(x)).sort()) {\n\t\tevents.push({ type: \"node-added\", id, node: cloneNode(n.nodes.get(id) as DescribeNode) });\n\t}\n\n\tfor (const id of [...n.nodes.keys()].filter((x) => p.nodes.has(x)).sort()) {\n\t\tconst prevMeta = p.nodes.get(id)?.meta ?? {};\n\t\tconst nextMeta = n.nodes.get(id)?.meta ?? {};\n\t\tif (!metaEqual(prevMeta, nextMeta)) {\n\t\t\tevents.push({\n\t\t\t\ttype: \"node-meta-changed\",\n\t\t\t\tid,\n\t\t\t\tprevMeta: { ...prevMeta },\n\t\t\t\tnextMeta: { ...nextMeta },\n\t\t\t});\n\t\t}\n\t}\n\n\tfor (const [k, e] of [...n.edges.entries()].sort()) {\n\t\tif (!p.edges.has(k)) events.push({ type: \"edge-added\", from: e.from, to: e.to });\n\t}\n\tfor (const [k, e] of [...p.edges.entries()].sort()) {\n\t\tif (!n.edges.has(k)) events.push({ type: \"edge-removed\", from: e.from, to: e.to });\n\t}\n\n\tfor (const id of [...p.nodes.keys()].filter((x) => !n.nodes.has(x)).sort())\n\t\tevents.push({ type: \"node-removed\", id });\n\n\tfor (const path of [...p.subgraphs].filter((x) => !n.subgraphs.has(x)).sort())\n\t\tevents.push({ type: \"subgraph-unmounted\", path });\n\n\treturn { events };\n}\n\n/**\n * Compose unary operator factories into a graph-registered chain.\n *\n * Each step is instantiated through `g.initNode`, so `describe()` still shows the real\n * per-operator factory names and declared edges (D6/D39/D45). This is graph-layer sugar, not a\n * new verb or protocol primitive.\n */\nexport function pipe<S>(g: Graph, source: Node<S>): Node<S>;\nexport function pipe<S, A>(g: Graph, source: Node<S>, op1: PipeOperator<S, A>): Node<A>;\nexport function pipe<S, A, B>(\n\tg: Graph,\n\tsource: Node<S>,\n\top1: PipeOperator<S, A>,\n\top2: PipeOperator<A, B>,\n): Node<B>;\nexport function pipe<S, A, B, C>(\n\tg: Graph,\n\tsource: Node<S>,\n\top1: PipeOperator<S, A>,\n\top2: PipeOperator<A, B>,\n\top3: PipeOperator<B, C>,\n): Node<C>;\nexport function pipe<S, A, B, C, D>(\n\tg: Graph,\n\tsource: Node<S>,\n\top1: PipeOperator<S, A>,\n\top2: PipeOperator<A, B>,\n\top3: PipeOperator<B, C>,\n\top4: PipeOperator<C, D>,\n): Node<D>;\nexport function pipe<S, A, B, C, D, E>(\n\tg: Graph,\n\tsource: Node<S>,\n\top1: PipeOperator<S, A>,\n\top2: PipeOperator<A, B>,\n\top3: PipeOperator<B, C>,\n\top4: PipeOperator<C, D>,\n\top5: PipeOperator<D, E>,\n): Node<E>;\nexport function pipe<S, A, B, C, D, E, F>(\n\tg: Graph,\n\tsource: Node<S>,\n\top1: PipeOperator<S, A>,\n\top2: PipeOperator<A, B>,\n\top3: PipeOperator<B, C>,\n\top4: PipeOperator<C, D>,\n\top5: PipeOperator<D, E>,\n\top6: PipeOperator<E, F>,\n): Node<F>;\nexport function pipe<S>(\n\tg: Graph,\n\tsource: Node<S>,\n\t...ops: readonly PipeOperator<unknown, unknown>[]\n): Node<unknown>;\nexport function pipe(\n\tg: Graph,\n\tsource: Node<unknown>,\n\t...ops: readonly PipeOperator<unknown, unknown>[]\n): Node<unknown> {\n\tlet current = source;\n\tfor (const op of ops) current = g.initNode(op, [current]);\n\treturn current;\n}\n\nexport interface StratifyRule<R> {\n\treadonly name: string;\n\treadonly rule: R;\n\treadonly meta?: Record<string, unknown>;\n}\n\nexport interface StratifyBranchOptions<T> extends Omit<NodeOptions<T>, \"dispatcher\"> {}\n\n/** D56 branch node body: declared deps `[source, rules]`, no internal subscribe island. */\nexport function stratifyBranch<T, R>(\n\tsource: Node<T>,\n\trules: Node<R>,\n\tclassifier: (rules: R, value: T) => boolean,\n\topts: StratifyBranchOptions<T> = {},\n): Node<T> {\n\tconst op = stratifyBranchOperator<T, R>(classifier);\n\treturn initNode(op, [source as Node<unknown>, rules as Node<unknown>], opts);\n}\n\nfunction stratifyBranchOperator<T, R>(\n\tclassifier: (rules: R, value: T) => boolean,\n): Operator<unknown, T> {\n\treturn {\n\t\tfactory: \"stratifyBranch\",\n\t\topts: {\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t\terrorWhenDepsError: false,\n\t\t\tterminalAsRealInput: true,\n\t\t},\n\t\tbody: (ctx: Ctx) => {\n\t\t\tconst sourceBatch = depBatch(ctx, 0);\n\t\t\tconst sourceTerminal = depTerminal(ctx, 0);\n\t\t\tconst rules = depLatest(ctx, 1) as R | undefined;\n\t\t\tif (rules !== undefined && sourceBatch !== null) {\n\t\t\t\tfor (const value of sourceBatch as readonly T[]) {\n\t\t\t\t\tif (classifier(rules, value)) ctx.down([[\"DATA\", value]]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (isTerminalComplete(sourceTerminal)) {\n\t\t\t\tctx.down([[\"COMPLETE\"]]);\n\t\t\t} else if (isTerminalError(sourceTerminal)) {\n\t\t\t\tctx.down([[\"ERROR\", terminalErrorValue(sourceTerminal)]]);\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport interface StratifyOptions<R = unknown> {\n\t/** Branch id prefix. Default `branch`, yielding ids like `branch/even`. */\n\tprefix?: string;\n\t/** Optional graph sugar opts for the rules state node. */\n\trules?: SugarOpts<readonly StratifyRule<R>[]>;\n\t/** Optional graph sugar opts for each branch node, keyed by rule name. */\n\tbranches?: Record<string, SugarOpts<unknown>>;\n}\n\nexport interface Stratified<T, R> {\n\treadonly rules: StateNode<readonly StratifyRule<R>[]>;\n\treadonly branches: Record<string, Node<T>>;\n}\n\n/**\n * Build static stratification branches in `g` (D56 first cut). Rules are a state node so future\n * classifier data changes affect future source items, but branch count is fixed at construction.\n */\nexport function stratify<T, R>(\n\tg: Graph,\n\tsource: Node<T>,\n\trules: readonly StratifyRule<R>[],\n\tclassifier: (rule: R, value: T) => boolean,\n\topts: StratifyOptions<R> = {},\n): Stratified<T, R> {\n\tconst prefix = opts.prefix ?? \"branch\";\n\tconst seen = new Set<string>();\n\tfor (const { name } of rules) {\n\t\tif (seen.has(name)) throw new Error(`stratify: duplicate rule name '${name}'`);\n\t\tseen.add(name);\n\t}\n\tconst { meta: rulesMeta, ...rulesOpts } = opts.rules ?? {};\n\tconst rulesNode = g.state<readonly StratifyRule<R>[]>([...rules], {\n\t\t...rulesOpts,\n\t\tname: rulesOpts.name ?? `${prefix}/rules`,\n\t\tmeta: { ...(rulesMeta ?? {}), kind: \"stratify_rules\" },\n\t});\n\tconst branches: Record<string, Node<T>> = {};\n\tfor (const rule of rules) {\n\t\tconst op = stratifyBranchOperator<T, readonly StratifyRule<R>[]>((all, value) => {\n\t\t\tconst current = all.find((r) => r.name === rule.name);\n\t\t\treturn current === undefined ? false : classifier(current.rule, value);\n\t\t});\n\t\tconst { meta: branchMeta, ...branchOpts } = opts.branches?.[rule.name] ?? {};\n\t\tbranches[rule.name] = g.initNode(op, [source as Node<unknown>, rulesNode as Node<unknown>], {\n\t\t\t...branchOpts,\n\t\t\tname: branchOpts.name ?? `${prefix}/${rule.name}`,\n\t\t\tmeta: { ...(rule.me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