@graphrefly/graphrefly 0.25.0 → 0.27.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 (231) hide show
  1. package/README.md +8 -0
  2. package/dist/ai-CaR_912Q.d.cts +1033 -0
  3. package/dist/ai-WlRltJV7.d.ts +1033 -0
  4. package/dist/audit-ClmqGOCx.d.cts +245 -0
  5. package/dist/audit-DRlSzBu9.d.ts +245 -0
  6. package/dist/{chunk-QOWVNWOC.js → chunk-3ZWCKRHX.js} +27 -25
  7. package/dist/{chunk-QOWVNWOC.js.map → chunk-3ZWCKRHX.js.map} +1 -1
  8. package/dist/chunk-APFNLIRG.js +62 -0
  9. package/dist/chunk-APFNLIRG.js.map +1 -0
  10. package/dist/chunk-AT5LKYNL.js +395 -0
  11. package/dist/chunk-AT5LKYNL.js.map +1 -0
  12. package/dist/{chunk-IAHGTNOZ.js → chunk-BQ6RQQFF.js} +351 -2095
  13. package/dist/chunk-BQ6RQQFF.js.map +1 -0
  14. package/dist/{chunk-L2GLW2U7.js → chunk-BVZYTZ5H.js} +9 -103
  15. package/dist/chunk-BVZYTZ5H.js.map +1 -0
  16. package/dist/{chunk-EVR6UFUV.js → chunk-DST5DKZS.js} +19 -15
  17. package/dist/{chunk-EVR6UFUV.js.map → chunk-DST5DKZS.js.map} +1 -1
  18. package/dist/{chunk-TKE3JGOH.js → chunk-GTE6PWRZ.js} +5 -692
  19. package/dist/chunk-GTE6PWRZ.js.map +1 -0
  20. package/dist/chunk-HXZEYDUR.js +94 -0
  21. package/dist/chunk-HXZEYDUR.js.map +1 -0
  22. package/dist/chunk-J22W6HV3.js +107 -0
  23. package/dist/chunk-J22W6HV3.js.map +1 -0
  24. package/dist/{chunk-PY4XCDLR.js → chunk-J2VBW3DZ.js} +6 -95
  25. package/dist/chunk-J2VBW3DZ.js.map +1 -0
  26. package/dist/{chunk-HWPIFSW2.js → chunk-JSCT3CR4.js} +6 -4
  27. package/dist/{chunk-HWPIFSW2.js.map → chunk-JSCT3CR4.js.map} +1 -1
  28. package/dist/chunk-JWBCY4NC.js +330 -0
  29. package/dist/chunk-JWBCY4NC.js.map +1 -0
  30. package/dist/chunk-K2AUJHVP.js +2251 -0
  31. package/dist/chunk-K2AUJHVP.js.map +1 -0
  32. package/dist/chunk-MJ2NKQQL.js +119 -0
  33. package/dist/chunk-MJ2NKQQL.js.map +1 -0
  34. package/dist/chunk-N6UR7YVY.js +198 -0
  35. package/dist/chunk-N6UR7YVY.js.map +1 -0
  36. package/dist/chunk-NC6S43JJ.js +456 -0
  37. package/dist/chunk-NC6S43JJ.js.map +1 -0
  38. package/dist/chunk-OFVJBJXR.js +98 -0
  39. package/dist/chunk-OFVJBJXR.js.map +1 -0
  40. package/dist/chunk-OHISZPOJ.js +97 -0
  41. package/dist/chunk-OHISZPOJ.js.map +1 -0
  42. package/dist/chunk-OU5CQKNW.js +102 -0
  43. package/dist/chunk-OU5CQKNW.js.map +1 -0
  44. package/dist/{chunk-XOFWRC73.js → chunk-PF7GRZMW.js} +316 -21
  45. package/dist/chunk-PF7GRZMW.js.map +1 -0
  46. package/dist/{chunk-5DJTTKX3.js → chunk-PHOUUNK7.js} +74 -111
  47. package/dist/chunk-PHOUUNK7.js.map +1 -0
  48. package/dist/chunk-RNHBMHKA.js +1665 -0
  49. package/dist/chunk-RNHBMHKA.js.map +1 -0
  50. package/dist/chunk-SX52TAR4.js +110 -0
  51. package/dist/chunk-SX52TAR4.js.map +1 -0
  52. package/dist/{chunk-H4RVA4VE.js → chunk-VYPWMZ6H.js} +2 -2
  53. package/dist/chunk-WBZOVTYK.js +171 -0
  54. package/dist/chunk-WBZOVTYK.js.map +1 -0
  55. package/dist/chunk-WKNUIZOY.js +354 -0
  56. package/dist/chunk-WKNUIZOY.js.map +1 -0
  57. package/dist/chunk-X3VMZYBT.js +713 -0
  58. package/dist/chunk-X3VMZYBT.js.map +1 -0
  59. package/dist/chunk-X5R3GL6H.js +525 -0
  60. package/dist/chunk-X5R3GL6H.js.map +1 -0
  61. package/dist/chunk-XGPU467M.js +136 -0
  62. package/dist/chunk-XGPU467M.js.map +1 -0
  63. package/dist/compat/index.cjs +7656 -0
  64. package/dist/compat/index.cjs.map +1 -0
  65. package/dist/compat/index.d.cts +18 -0
  66. package/dist/compat/index.d.ts +18 -0
  67. package/dist/compat/index.js +50 -0
  68. package/dist/compat/index.js.map +1 -0
  69. package/dist/compat/jotai/index.cjs +2048 -0
  70. package/dist/compat/jotai/index.cjs.map +1 -0
  71. package/dist/compat/jotai/index.d.cts +2 -0
  72. package/dist/compat/jotai/index.d.ts +2 -0
  73. package/dist/compat/jotai/index.js +9 -0
  74. package/dist/compat/jotai/index.js.map +1 -0
  75. package/dist/compat/nanostores/index.cjs +2175 -0
  76. package/dist/compat/nanostores/index.cjs.map +1 -0
  77. package/dist/compat/nanostores/index.d.cts +2 -0
  78. package/dist/compat/nanostores/index.d.ts +2 -0
  79. package/dist/compat/nanostores/index.js +23 -0
  80. package/dist/compat/nanostores/index.js.map +1 -0
  81. package/dist/compat/nestjs/index.cjs +350 -16
  82. package/dist/compat/nestjs/index.cjs.map +1 -1
  83. package/dist/compat/nestjs/index.d.cts +6 -6
  84. package/dist/compat/nestjs/index.d.ts +6 -6
  85. package/dist/compat/nestjs/index.js +11 -9
  86. package/dist/compat/react/index.cjs +141 -0
  87. package/dist/compat/react/index.cjs.map +1 -0
  88. package/dist/compat/react/index.d.cts +2 -0
  89. package/dist/compat/react/index.d.ts +2 -0
  90. package/dist/compat/react/index.js +12 -0
  91. package/dist/compat/react/index.js.map +1 -0
  92. package/dist/compat/solid/index.cjs +128 -0
  93. package/dist/compat/solid/index.cjs.map +1 -0
  94. package/dist/compat/solid/index.d.cts +2 -0
  95. package/dist/compat/solid/index.d.ts +2 -0
  96. package/dist/compat/solid/index.js +12 -0
  97. package/dist/compat/solid/index.js.map +1 -0
  98. package/dist/compat/svelte/index.cjs +131 -0
  99. package/dist/compat/svelte/index.cjs.map +1 -0
  100. package/dist/compat/svelte/index.d.cts +2 -0
  101. package/dist/compat/svelte/index.d.ts +2 -0
  102. package/dist/compat/svelte/index.js +12 -0
  103. package/dist/compat/svelte/index.js.map +1 -0
  104. package/dist/compat/vue/index.cjs +146 -0
  105. package/dist/compat/vue/index.cjs.map +1 -0
  106. package/dist/compat/vue/index.d.cts +3 -0
  107. package/dist/compat/vue/index.d.ts +3 -0
  108. package/dist/compat/vue/index.js +12 -0
  109. package/dist/compat/vue/index.js.map +1 -0
  110. package/dist/compat/zustand/index.cjs +4931 -0
  111. package/dist/compat/zustand/index.cjs.map +1 -0
  112. package/dist/compat/zustand/index.d.cts +5 -0
  113. package/dist/compat/zustand/index.d.ts +5 -0
  114. package/dist/compat/zustand/index.js +12 -0
  115. package/dist/compat/zustand/index.js.map +1 -0
  116. package/dist/composite-C7PcQvcs.d.cts +303 -0
  117. package/dist/composite-aUCvjZVR.d.ts +303 -0
  118. package/dist/core/index.cjs +53 -4
  119. package/dist/core/index.cjs.map +1 -1
  120. package/dist/core/index.d.cts +4 -3
  121. package/dist/core/index.d.ts +4 -3
  122. package/dist/core/index.js +26 -24
  123. package/dist/demo-shell-BDkOptd6.d.ts +102 -0
  124. package/dist/demo-shell-Crid1WdR.d.cts +102 -0
  125. package/dist/extra/index.cjs +222 -110
  126. package/dist/extra/index.cjs.map +1 -1
  127. package/dist/extra/index.d.cts +6 -4
  128. package/dist/extra/index.d.ts +6 -4
  129. package/dist/extra/index.js +72 -65
  130. package/dist/extra/sources.cjs +2486 -0
  131. package/dist/extra/sources.cjs.map +1 -0
  132. package/dist/extra/sources.d.cts +465 -0
  133. package/dist/extra/sources.d.ts +465 -0
  134. package/dist/extra/sources.js +57 -0
  135. package/dist/extra/sources.js.map +1 -0
  136. package/dist/graph/index.cjs +408 -14
  137. package/dist/graph/index.cjs.map +1 -1
  138. package/dist/graph/index.d.cts +5 -5
  139. package/dist/graph/index.d.ts +5 -5
  140. package/dist/graph/index.js +13 -5
  141. package/dist/{graph-D-3JIQme.d.cts → graph-CCwGKLCm.d.ts} +195 -4
  142. package/dist/{graph-B6NFqv3z.d.ts → graph-DNCrvZSn.d.cts} +195 -4
  143. package/dist/index-3lsddbbS.d.ts +86 -0
  144. package/dist/index-B1tloyhO.d.cts +34 -0
  145. package/dist/{index-CYkjxu3s.d.ts → index-B6D3QNSA.d.ts} +33 -4
  146. package/dist/index-B6EhDnjH.d.cts +37 -0
  147. package/dist/index-B9B7_HEY.d.ts +37 -0
  148. package/dist/{index-Ds23Wvou.d.ts → index-BHlKbUwO.d.cts} +131 -883
  149. package/dist/{index-DiobMNwE.d.ts → index-BPVt8kqc.d.ts} +3 -3
  150. package/dist/index-BaSM3aYt.d.ts +195 -0
  151. package/dist/index-BuEoe-Qu.d.ts +121 -0
  152. package/dist/{index-Ch0IpIO0.d.cts → index-BwfLUNw4.d.ts} +131 -883
  153. package/dist/index-ByQxazQJ.d.cts +86 -0
  154. package/dist/index-C0svESO4.d.ts +127 -0
  155. package/dist/{index-OXImXMq6.d.ts → index-C8oil6M6.d.ts} +18 -196
  156. package/dist/{index-DKE1EATr.d.cts → index-CI3DprxP.d.cts} +18 -196
  157. package/dist/{index-AMWewNDe.d.cts → index-CO8uBlUh.d.cts} +33 -4
  158. package/dist/index-CxFrXH4m.d.ts +45 -0
  159. package/dist/index-D8wS_PeY.d.cts +121 -0
  160. package/dist/index-DO_6JN9Z.d.cts +127 -0
  161. package/dist/index-DVGiGFGT.d.cts +195 -0
  162. package/dist/index-DYme44FM.d.cts +44 -0
  163. package/dist/{index-J7Kc0oIQ.d.cts → index-DlLp-2Xn.d.cts} +3 -3
  164. package/dist/index-Dzk2hrlR.d.ts +44 -0
  165. package/dist/index-VHqptjhu.d.cts +45 -0
  166. package/dist/index-VdHQMPy1.d.ts +36 -0
  167. package/dist/index-Xi3u0HCQ.d.cts +36 -0
  168. package/dist/index-wEn0eFe8.d.ts +34 -0
  169. package/dist/index.cjs +1780 -176
  170. package/dist/index.cjs.map +1 -1
  171. package/dist/index.d.cts +784 -2082
  172. package/dist/index.d.ts +784 -2082
  173. package/dist/index.js +955 -4349
  174. package/dist/index.js.map +1 -1
  175. package/dist/memory-C6Z2tGpC.d.cts +139 -0
  176. package/dist/memory-li6FL5RM.d.ts +139 -0
  177. package/dist/messaging-Gt4LPbyA.d.cts +269 -0
  178. package/dist/messaging-XDoYablx.d.ts +269 -0
  179. package/dist/{meta-DWbkoq1s.d.cts → meta-BxCA7rcr.d.cts} +1 -1
  180. package/dist/{meta-CnkLA_43.d.ts → meta-CbznRPYJ.d.ts} +1 -1
  181. package/dist/{node-B-f-Lu-k.d.cts → node-BmerH3kS.d.cts} +26 -1
  182. package/dist/{node-B-f-Lu-k.d.ts → node-BmerH3kS.d.ts} +26 -1
  183. package/dist/{observable-uP-wy_uK.d.ts → observable-BgGUwcqp.d.ts} +1 -1
  184. package/dist/{observable-DBnrwcar.d.cts → observable-DJt_AxzQ.d.cts} +1 -1
  185. package/dist/patterns/ai.cjs +7930 -0
  186. package/dist/patterns/ai.cjs.map +1 -0
  187. package/dist/patterns/ai.d.cts +10 -0
  188. package/dist/patterns/ai.d.ts +10 -0
  189. package/dist/patterns/ai.js +71 -0
  190. package/dist/patterns/ai.js.map +1 -0
  191. package/dist/patterns/audit.cjs +5805 -0
  192. package/dist/patterns/audit.cjs.map +1 -0
  193. package/dist/patterns/audit.d.cts +6 -0
  194. package/dist/patterns/audit.d.ts +6 -0
  195. package/dist/patterns/audit.js +29 -0
  196. package/dist/patterns/audit.js.map +1 -0
  197. package/dist/patterns/demo-shell.cjs +5604 -0
  198. package/dist/patterns/demo-shell.cjs.map +1 -0
  199. package/dist/patterns/demo-shell.d.cts +6 -0
  200. package/dist/patterns/demo-shell.d.ts +6 -0
  201. package/dist/patterns/demo-shell.js +15 -0
  202. package/dist/patterns/demo-shell.js.map +1 -0
  203. package/dist/patterns/memory.cjs +5283 -0
  204. package/dist/patterns/memory.cjs.map +1 -0
  205. package/dist/patterns/memory.d.cts +5 -0
  206. package/dist/patterns/memory.d.ts +5 -0
  207. package/dist/patterns/memory.js +20 -0
  208. package/dist/patterns/memory.js.map +1 -0
  209. package/dist/patterns/reactive-layout/index.cjs +355 -13
  210. package/dist/patterns/reactive-layout/index.cjs.map +1 -1
  211. package/dist/patterns/reactive-layout/index.d.cts +6 -5
  212. package/dist/patterns/reactive-layout/index.d.ts +6 -5
  213. package/dist/patterns/reactive-layout/index.js +15 -12
  214. package/dist/reactive-layout-MQP--J3F.d.cts +183 -0
  215. package/dist/reactive-layout-u5Ulnqag.d.ts +183 -0
  216. package/dist/{storage-BuTdpCI1.d.cts → storage-CMjUUuxn.d.ts} +10 -2
  217. package/dist/{storage-F2X1U1x0.d.ts → storage-DdWlZo6U.d.cts} +10 -2
  218. package/dist/sugar-CCOxXK1e.d.ts +201 -0
  219. package/dist/sugar-D02n5JjF.d.cts +201 -0
  220. package/package.json +63 -3
  221. package/dist/chunk-5DJTTKX3.js.map +0 -1
  222. package/dist/chunk-IAHGTNOZ.js.map +0 -1
  223. package/dist/chunk-L2GLW2U7.js.map +0 -1
  224. package/dist/chunk-MW4VAKAO.js +0 -47
  225. package/dist/chunk-MW4VAKAO.js.map +0 -1
  226. package/dist/chunk-PY4XCDLR.js.map +0 -1
  227. package/dist/chunk-TKE3JGOH.js.map +0 -1
  228. package/dist/chunk-XOFWRC73.js.map +0 -1
  229. package/dist/index-BJB7t9gg.d.cts +0 -392
  230. package/dist/index-C-TXEa7C.d.ts +0 -392
  231. /package/dist/{chunk-H4RVA4VE.js.map → chunk-VYPWMZ6H.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/extra/backoff.ts","../src/extra/operators.ts","../src/extra/composite.ts"],"sourcesContent":["/**\n * Backoff strategies for {@link retry} (roadmap §3.1). Delays are in **nanoseconds**.\n *\n * Convention: all graphrefly-ts timestamps and durations use nanoseconds (`_ns` suffix).\n * 1 second = 1_000_000_000 ns, 1 ms = 1_000_000 ns.\n */\n\nexport const NS_PER_MS = 1_000_000;\nexport const NS_PER_SEC = 1_000_000_000;\n\nexport type JitterMode = \"none\" | \"full\" | \"equal\";\n\nexport type BackoffPreset =\n\t| \"constant\"\n\t| \"linear\"\n\t| \"exponential\"\n\t| \"fibonacci\"\n\t| \"decorrelatedJitter\";\n\n/** `(attempt, error?, previousDelayNs?) => delayNs | null` — `null` means zero delay. */\nexport type BackoffStrategy = (\n\tattempt: number,\n\terror?: unknown,\n\tprevDelayNs?: number | null,\n) => number | null;\n\nfunction clampNonNegative(value: number): number {\n\treturn value < 0 ? 0 : value;\n}\n\nfunction applyJitter(delay: number, jitter: JitterMode): number {\n\tif (jitter === \"none\") return delay;\n\tif (jitter === \"full\") return Math.random() * delay;\n\treturn delay / 2 + Math.random() * (delay / 2);\n}\n\nfunction randomBetween(min: number, max: number): number {\n\treturn min + Math.random() * (max - min);\n}\n\n/**\n * Builds a strategy that always returns the same delay in nanoseconds.\n *\n * @param delayNs - Non-negative delay in nanoseconds; values below zero are clamped to zero.\n * @returns `BackoffStrategy` for use with {@link retry} or custom timers.\n *\n * @example\n * ```ts\n * import { constant, retry, NS_PER_SEC } from \"@graphrefly/graphrefly-ts\";\n *\n * const out = retry(source, { count: 3, backoff: constant(0.25 * NS_PER_SEC) });\n * ```\n *\n * @category extra\n */\nexport function constant(delayNs: number): BackoffStrategy {\n\tconst safe = clampNonNegative(delayNs);\n\treturn () => safe;\n}\n\n/**\n * Builds linear backoff: `baseNs + stepNs * attempt` (`stepNs` defaults to `baseNs`).\n *\n * @param baseNs - Base delay in nanoseconds (clamped non-negative).\n * @param stepNs - Added per retry attempt in nanoseconds (clamped non-negative).\n * @returns `BackoffStrategy` for {@link retry}.\n *\n * @example\n * ```ts\n * import { linear, retry, NS_PER_SEC } from \"@graphrefly/graphrefly-ts\";\n *\n * // Attempt 0 → 1 s, attempt 1 → 2 s, attempt 2 → 3 s …\n * const out = retry(source, { count: 4, backoff: linear(NS_PER_SEC) });\n * ```\n *\n * @category extra\n */\nexport function linear(baseNs: number, stepNs?: number): BackoffStrategy {\n\tconst safeBase = clampNonNegative(baseNs);\n\tconst safeStep = stepNs === undefined ? safeBase : clampNonNegative(stepNs);\n\treturn (attempt: number) => safeBase + safeStep * Math.max(0, attempt);\n}\n\nexport type ExponentialBackoffOptions = {\n\tbaseNs?: number;\n\tfactor?: number;\n\tmaxDelayNs?: number;\n\tjitter?: JitterMode;\n};\n\n/**\n * Builds exponential backoff in nanoseconds, capped by `maxDelayNs`, with optional jitter.\n *\n * @param options - Base, factor, cap, and jitter mode.\n * @returns `BackoffStrategy` for {@link retry}.\n *\n * @remarks\n * **Jitter:** `\"full\"` spreads delay across `[0, delay]`; `\"equal\"` uses `[delay/2, delay]`.\n *\n * @example\n * ```ts\n * import { exponential, retry, NS_PER_SEC } from \"@graphrefly/graphrefly-ts\";\n *\n * // 100 ms → 200 ms → 400 ms … capped at 30 s, with full jitter\n * const out = retry(source, {\n * count: 5,\n * backoff: exponential({ baseNs: 100 * NS_PER_SEC / 1000, jitter: \"full\" }),\n * });\n * ```\n *\n * @category extra\n */\nexport function exponential(options?: ExponentialBackoffOptions): BackoffStrategy {\n\tconst baseNs = clampNonNegative(options?.baseNs ?? 100 * NS_PER_MS);\n\tconst factor = options?.factor !== undefined && options.factor < 1 ? 1 : (options?.factor ?? 2);\n\tconst maxDelayNs = clampNonNegative(options?.maxDelayNs ?? 30 * NS_PER_SEC);\n\tconst jitter = options?.jitter ?? \"none\";\n\n\treturn (attempt: number) => {\n\t\tlet delay: number;\n\t\tif (baseNs === 0) {\n\t\t\tdelay = 0;\n\t\t} else if (factor === 1) {\n\t\t\tdelay = baseNs;\n\t\t} else {\n\t\t\tconst capRatio = maxDelayNs / baseNs;\n\t\t\tlet growth = 1;\n\t\t\tfor (let i = 0; i < Math.max(0, attempt); i++) {\n\t\t\t\tif (growth >= capRatio) {\n\t\t\t\t\tgrowth = capRatio;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tgrowth *= factor;\n\t\t\t}\n\t\t\tdelay = baseNs * growth;\n\t\t\tif (delay > maxDelayNs) delay = maxDelayNs;\n\t\t}\n\t\treturn applyJitter(delay, jitter);\n\t};\n}\n\n/**\n * Builds Fibonacci-scaled delays: `1, 2, 3, 5, … × baseNs`, capped at `maxDelayNs`.\n *\n * @param baseNs - Multiplier applied to the Fibonacci unit (default `100ms` in nanoseconds).\n * @param maxDelayNs - Upper bound in nanoseconds (default `30s`).\n * @returns `BackoffStrategy` for {@link retry}.\n *\n * @example\n * ```ts\n * import { fibonacci, retry, NS_PER_MS } from \"@graphrefly/graphrefly-ts\";\n *\n * // Delays: 100 ms, 200 ms, 300 ms, 500 ms, 800 ms … (× 100 ms base)\n * const out = retry(source, { count: 5, backoff: fibonacci(100 * NS_PER_MS) });\n * ```\n *\n * @category extra\n */\nexport function fibonacci(baseNs = 100 * NS_PER_MS, maxDelayNs = 30 * NS_PER_SEC): BackoffStrategy {\n\tconst safeBase = clampNonNegative(baseNs);\n\tconst safeMax = clampNonNegative(maxDelayNs);\n\n\tfunction fibUnit(attempt: number): number {\n\t\tif (attempt <= 0) return 1;\n\t\tlet prev = 1;\n\t\tlet cur = 2;\n\t\tfor (let i = 1; i < attempt; i++) {\n\t\t\tconst next = prev + cur;\n\t\t\tprev = cur;\n\t\t\tcur = next;\n\t\t}\n\t\treturn cur;\n\t}\n\n\treturn (attempt: number) => {\n\t\tconst raw = fibUnit(attempt) * safeBase;\n\t\treturn raw <= safeMax ? raw : safeMax;\n\t};\n}\n\n/**\n * Decorrelated jitter (AWS-recommended): `random(baseNs, min(maxNs, lastDelay * 3))`.\n *\n * Stateless — uses `prevDelayNs` (passed by the consumer) instead of closure state.\n * Safe to share across concurrent retry sequences.\n *\n * @param baseNs - Floor of the random range (default `100ms` in nanoseconds).\n * @param maxNs - Ceiling cap (default `30s` in nanoseconds).\n * @returns `BackoffStrategy` for {@link retry}.\n *\n * @example\n * ```ts\n * import { decorrelatedJitter, retry, NS_PER_MS, NS_PER_SEC } from \"@graphrefly/graphrefly-ts\";\n *\n * const out = retry(source, {\n * count: 6,\n * backoff: decorrelatedJitter(100 * NS_PER_MS, 10 * NS_PER_SEC),\n * });\n * ```\n *\n * @category extra\n */\nexport function decorrelatedJitter(\n\tbaseNs = 100 * NS_PER_MS,\n\tmaxNs = 30 * NS_PER_SEC,\n): BackoffStrategy {\n\treturn (_attempt, _error, prevDelayNs) => {\n\t\tconst last = prevDelayNs ?? baseNs;\n\t\tconst ceiling = Math.min(maxNs, last * 3);\n\t\treturn randomBetween(baseNs, ceiling);\n\t};\n}\n\n/**\n * Decorator that caps any strategy at `maxAttempts`. Returns `null` (stop retrying) after the cap.\n *\n * @param strategy - Inner strategy to wrap.\n * @param maxAttempts - Maximum number of attempts (inclusive).\n * @returns Wrapped `BackoffStrategy`.\n *\n * @example\n * ```ts\n * import { withMaxAttempts, exponential } from \"@graphrefly/graphrefly-ts\";\n *\n * const capped = withMaxAttempts(exponential(), 3);\n * capped(3); // null — no more retries beyond attempt 3\n * ```\n *\n * @category extra\n */\nexport function withMaxAttempts(strategy: BackoffStrategy, maxAttempts: number): BackoffStrategy {\n\treturn (attempt, error, prevDelayNs) => {\n\t\tif (attempt >= maxAttempts) return null;\n\t\treturn strategy(attempt, error, prevDelayNs);\n\t};\n}\n\n/**\n * Maps a preset name to a concrete {@link BackoffStrategy} with library-default parameters.\n *\n * @param name - One of `constant`, `linear`, `exponential`, `fibonacci`, or `decorrelatedJitter`.\n * @returns Configured strategy with default parameters.\n * @throws Error when `name` is not a known preset.\n *\n * @example\n * ```ts\n * import { resolveBackoffPreset, retry } from \"@graphrefly/graphrefly-ts\";\n *\n * const out = retry(source, { count: 3, backoff: resolveBackoffPreset(\"exponential\") });\n * // Equivalent to retry(source, { count: 3, backoff: exponential() })\n * ```\n *\n * @category extra\n */\nexport function resolveBackoffPreset(name: BackoffPreset): BackoffStrategy {\n\tif (name === \"constant\") return constant(1 * NS_PER_SEC);\n\tif (name === \"linear\") return linear(1 * NS_PER_SEC);\n\tif (name === \"exponential\") return exponential();\n\tif (name === \"fibonacci\") return fibonacci();\n\tif (name === \"decorrelatedJitter\") return decorrelatedJitter();\n\tthrow new Error(\n\t\t`Unknown backoff preset: \"${String(name)}\". Use one of: constant, linear, exponential, fibonacci, decorrelatedJitter`,\n\t);\n}\n","/**\n * Tier 1 sync operators (roadmap §2.1) and Tier 2 async/dynamic operators (roadmap §2.2) —\n * each returns a {@link Node} built with {@link node} (or {@link producer} for cold sources).\n *\n * v5 foundation redesign: all operators use `actions.emit()` for value emission,\n * `ctx.store` for persistent state, `ctx.terminalDeps` for terminal handling,\n * and `data[i]` batch shape for DATA vs RESOLVED discrimination. `onMessage`\n * and `onResubscribe` are removed.\n */\n\nimport { monotonicNs } from \"../core/clock.js\";\nimport type { NodeActions } from \"../core/config.js\";\nimport {\n\tCOMPLETE,\n\tDATA,\n\tDIRTY,\n\tERROR,\n\ttype Message,\n\ttype Messages,\n\tRESOLVED,\n\tSTART,\n} from \"../core/messages.js\";\nimport { type Node, type NodeOptions, node } from \"../core/node.js\";\nimport { derived, producer } from \"../core/sugar.js\";\nimport { NS_PER_MS } from \"./backoff.js\";\nimport { fromAny, type NodeInput } from \"./sources.js\";\n\ntype ExtraOpts = Omit<NodeOptions<unknown>, \"describeKind\">;\n\nfunction operatorOpts<T = unknown>(opts?: ExtraOpts): NodeOptions<T> {\n\treturn { describeKind: \"derived\", ...opts } as NodeOptions<T>;\n}\n\n/**\n * Maps each settled value from `source` through `project`.\n *\n * @param source - Upstream node.\n * @param project - Transform for each value.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<R>` - Derived node emitting mapped values.\n *\n * @example\n * ```ts\n * import { map, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = map(state(2), (x) => x * 3);\n * ```\n *\n * @category extra\n */\nexport function map<T, R>(source: Node<T>, project: (value: T) => R, opts?: ExtraOpts): Node<R> {\n\treturn node<R>(\n\t\t[source as Node],\n\t\t(data, a) => {\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor (const v of batch0) {\n\t\t\t\ta.emit(project(v as T));\n\t\t\t}\n\t\t},\n\t\toperatorOpts<R>(opts),\n\t);\n}\n\n/**\n * Forwards values that satisfy `predicate`; otherwise emits `RESOLVED` with no `DATA` (two-phase semantics).\n *\n * @param source - Upstream node.\n * @param predicate - Inclusion test.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Filtered node.\n *\n * @example\n * ```ts\n * import { filter, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = filter(state(1), (x) => x > 0);\n * ```\n *\n * @category extra\n */\nexport function filter<T>(\n\tsource: Node<T>,\n\tpredicate: (value: T) => boolean,\n\topts?: ExtraOpts,\n): Node<T> {\n\treturn node<T>(\n\t\t[source as Node],\n\t\t(data, a) => {\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet emitted = false;\n\t\t\tfor (const v of batch0) {\n\t\t\t\tif (predicate(v as T)) {\n\t\t\t\t\ta.emit(v as T);\n\t\t\t\t\temitted = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!emitted) a.down([[RESOLVED]]);\n\t\t},\n\t\toperatorOpts(opts),\n\t);\n}\n\n/**\n * Folds each upstream value into an accumulator; emits the new accumulator every time.\n *\n * Unlike RxJS, `seed` is always required — there is no seedless mode where the first\n * value silently becomes the accumulator.\n *\n * @param source - Upstream node.\n * @param reducer - `(acc, value) => nextAcc`.\n * @param seed - Initial accumulator (required).\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<R>` - Scan node.\n *\n * @example\n * ```ts\n * import { scan, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = scan(state(1), (a, x) => a + x, 0);\n * ```\n *\n * @category extra\n */\nexport function scan<T, R>(\n\tsource: Node<T>,\n\treducer: (acc: R, value: T) => R,\n\tseed: R,\n\topts?: ExtraOpts,\n): Node<R> {\n\treturn node<R>(\n\t\t[source as Node],\n\t\t(data, a, ctx) => {\n\t\t\tif (!(\"acc\" in ctx.store)) ctx.store.acc = seed;\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor (const v of batch0) {\n\t\t\t\tctx.store.acc = reducer(ctx.store.acc as R, v as T);\n\t\t\t\ta.emit(ctx.store.acc as R);\n\t\t\t}\n\t\t},\n\t\t{ ...operatorOpts(opts), initial: seed, resetOnTeardown: true },\n\t);\n}\n\n/**\n * Reduces to one value emitted when `source` completes; if no `DATA` arrived, emits `seed`.\n *\n * Unlike RxJS, `seed` is always required. If the source completes without emitting\n * DATA, the seed value is emitted (RxJS would throw without a seed).\n *\n * @param source - Upstream node.\n * @param reducer - `(acc, value) => nextAcc`.\n * @param seed - Empty-completion default and initial accumulator (required).\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<R>` - Node that emits once on completion.\n *\n * @example\n * ```ts\n * import { reduce, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = reduce(state(1), (a, x) => a + x, 0);\n * ```\n *\n * @category extra\n */\nexport function reduce<T, R>(\n\tsource: Node<T>,\n\treducer: (acc: R, value: T) => R,\n\tseed: R,\n\topts?: ExtraOpts,\n): Node<R> {\n\treturn node<R>(\n\t\t[source as Node],\n\t\t(data, a, ctx) => {\n\t\t\tif (!(\"acc\" in ctx.store)) ctx.store.acc = seed;\n\t\t\t// COMPLETE: emit accumulated value then COMPLETE.\n\t\t\t// ERROR: autoError propagates automatically; nothing to emit.\n\t\t\tif (ctx.terminalDeps[0] === true) {\n\t\t\t\ta.emit(ctx.store.acc as R);\n\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst batch0 = data[0];\n\t\t\t// RESOLVED wave (empty batch): propagate RESOLVED. After fn has run once\n\t\t\t// the pre-fn skip handles this; this guard covers the first-wave case.\n\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// DATA: accumulate silently — emit nothing until COMPLETE.\n\t\t\tfor (const v of batch0) {\n\t\t\t\tctx.store.acc = reducer(ctx.store.acc as R, v as T);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t...operatorOpts(opts),\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t},\n\t);\n}\n\n/**\n * Emits at most `count` **`DATA`** values, then **`COMPLETE`**. `RESOLVED` does not advance the counter.\n *\n * @param source - Upstream node.\n * @param count - Maximum `DATA` emissions (≤0 completes immediately).\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Limited stream.\n *\n * @example\n * ```ts\n * import { take, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = take(state(0), 3);\n * ```\n *\n * @category extra\n */\nexport function take<T>(source: Node<T>, count: number, opts?: ExtraOpts): Node<T> {\n\tif (count <= 0) {\n\t\treturn node<T>(\n\t\t\t[source as Node],\n\t\t\t(_d, a, ctx) => {\n\t\t\t\tif (ctx.store.completed) return;\n\t\t\t\tctx.store.completed = true;\n\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t},\n\t\t\t{\n\t\t\t\t...operatorOpts(opts),\n\t\t\t\tcompleteWhenDepsComplete: false,\n\t\t\t},\n\t\t);\n\t}\n\treturn node<T>(\n\t\t[source as Node],\n\t\t(data, a, ctx) => {\n\t\t\tif (!(\"taken\" in ctx.store)) ctx.store.taken = 0;\n\t\t\tif (ctx.store.done) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Upstream COMPLETE before count reached → forward COMPLETE.\n\t\t\tif (ctx.terminalDeps[0] === true) {\n\t\t\t\tctx.store.done = true;\n\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// DATA wave: iterate full batch, stop at count\n\t\t\tfor (const v of batch0) {\n\t\t\t\t(ctx.store.taken as number)++;\n\t\t\t\ta.emit(v as T);\n\t\t\t\tif ((ctx.store.taken as number) >= count) {\n\t\t\t\t\tctx.store.done = true;\n\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t...operatorOpts(opts),\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t},\n\t);\n}\n\n/**\n * Skips the first `count` **`DATA`** emissions. `RESOLVED` does not advance the counter.\n *\n * @param source - Upstream node.\n * @param count - Number of `DATA` values to drop.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Skipped stream.\n *\n * @example\n * ```ts\n * import { skip, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = skip(state(0), 2);\n * ```\n *\n * @category extra\n */\nexport function skip<T>(source: Node<T>, count: number, opts?: ExtraOpts): Node<T> {\n\treturn node<T>(\n\t\t[source as Node],\n\t\t(data, a, ctx) => {\n\t\t\tif (!(\"skipped\" in ctx.store)) ctx.store.skipped = 0;\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\t// RESOLVED wave — pass through\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet emitted = false;\n\t\t\tfor (const v of batch0) {\n\t\t\t\t(ctx.store.skipped as number)++;\n\t\t\t\tif ((ctx.store.skipped as number) <= count) {\n\t\t\t\t\t// Still in skip window\n\t\t\t\t} else {\n\t\t\t\t\ta.emit(v as T);\n\t\t\t\t\temitted = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!emitted) a.down([[RESOLVED]]);\n\t\t},\n\t\toperatorOpts(opts),\n\t);\n}\n\n/**\n * Emits while `predicate` holds; on first false, sends **`COMPLETE`**.\n *\n * @param source - Upstream node.\n * @param predicate - Continuation test.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Truncated stream.\n *\n * @example\n * ```ts\n * import { takeWhile, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = takeWhile(state(1), (x) => x < 10);\n * ```\n *\n * @category extra\n */\nexport function takeWhile<T>(\n\tsource: Node<T>,\n\tpredicate: (value: T) => boolean,\n\topts?: ExtraOpts,\n): Node<T> {\n\treturn node<T>(\n\t\t[source as Node],\n\t\t(data, a, ctx) => {\n\t\t\tif (ctx.store.done) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor (const v of batch0) {\n\t\t\t\tif (!predicate(v as T)) {\n\t\t\t\t\tctx.store.done = true;\n\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ta.emit(v as T);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t...operatorOpts(opts),\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t},\n\t);\n}\n\n/**\n * Forwards `source` until `notifier` matches `predicate` (default: notifier **`DATA`**), then **`COMPLETE`**.\n *\n * @param source - Main upstream.\n * @param notifier - Triggers completion when `predicate(msg)` is true.\n * @param opts - Optional {@link NodeOptions}, plus `predicate` for custom notifier matching.\n * @returns `Node<T>` - Truncated stream.\n *\n * @example\n * ```ts\n * import { producer, takeUntil, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const src = state(1);\n * const stop = producer((_d, a) => a.emit(undefined));\n * const n = takeUntil(src, stop);\n * ```\n *\n * @category extra\n */\nexport function takeUntil<T>(\n\tsource: Node<T>,\n\tnotifier: Node,\n\topts?: ExtraOpts & { predicate?: (msg: Message) => boolean },\n): Node<T> {\n\tconst pred = opts?.predicate ?? ((m: Message) => m[0] === DATA);\n\tconst { predicate: _, ...restOpts } = opts ?? {};\n\t// Use producer pattern — subscribe to both manually for message-level control.\n\treturn producer<T>(\n\t\t(a) => {\n\t\t\tlet stopped = false;\n\t\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\t\tif (stopped) return;\n\t\t\t\tfor (const m of msgs) {\n\t\t\t\t\tif (stopped) return;\n\t\t\t\t\tif (m[0] === DATA) a.emit(m[1] as T);\n\t\t\t\t\telse if (m[0] === COMPLETE || m[0] === ERROR) {\n\t\t\t\t\t\tstopped = true;\n\t\t\t\t\t\ta.down([m]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t\tconst notUnsub = notifier.subscribe((msgs) => {\n\t\t\t\tif (stopped) return;\n\t\t\t\tfor (const m of msgs) {\n\t\t\t\t\tif (stopped) return;\n\t\t\t\t\tif (pred(m)) {\n\t\t\t\t\t\tstopped = true;\n\t\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn () => {\n\t\t\t\tsrcUnsub();\n\t\t\t\tnotUnsub();\n\t\t\t};\n\t\t},\n\t\toperatorOpts(restOpts as ExtraOpts),\n\t);\n}\n\n/**\n * Emits the first **`DATA`** then **`COMPLETE`** (same as `take(source, 1)`).\n *\n * @param source - Upstream node.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Single-value stream.\n *\n * @example\n * ```ts\n * import { first, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = first(state(42));\n * ```\n *\n * @category extra\n */\nexport function first<T>(source: Node<T>, opts?: ExtraOpts): Node<T> {\n\treturn take(source, 1, opts);\n}\n\n/**\n * Buffers values and emits the last **`DATA`** on **`COMPLETE`**; optional `defaultValue` if none arrived.\n *\n * @param source - Upstream node.\n * @param options - Optional {@link NodeOptions} and `defaultValue` when empty.\n * @returns `Node<T>` - Last-or-default node.\n *\n * @example\n * ```ts\n * import { last, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = last(state(1), { defaultValue: 0 });\n * ```\n *\n * @category extra\n */\nexport function last<T>(source: Node<T>, options?: ExtraOpts & { defaultValue?: T }): Node<T> {\n\tconst { defaultValue, ...rest } = options ?? {};\n\tconst useDefault = options != null && Object.hasOwn(options, \"defaultValue\");\n\treturn node<T>(\n\t\t[source as Node],\n\t\t(data, a, ctx) => {\n\t\t\t// COMPLETE (terminal === true): emit latest or default, then COMPLETE.\n\t\t\t// ERROR: autoError propagates automatically.\n\t\t\tif (ctx.terminalDeps[0] === true) {\n\t\t\t\tif (ctx.store.has) {\n\t\t\t\t\ta.emit(ctx.store.latest as T);\n\t\t\t\t} else if (useDefault) {\n\t\t\t\t\ta.emit(defaultValue as T);\n\t\t\t\t}\n\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst batch0 = data[0];\n\t\t\t// RESOLVED wave: propagate RESOLVED. Covers first-wave case; after first\n\t\t\t// call the pre-fn skip handles this automatically.\n\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// DATA: accumulate latest — emit nothing until COMPLETE.\n\t\t\tctx.store.latest = batch0.at(-1) as T;\n\t\t\tctx.store.has = true;\n\t\t},\n\t\t{\n\t\t\t...operatorOpts(rest),\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t},\n\t);\n}\n\n/**\n * Emits the first value matching `predicate`, then **`COMPLETE`**.\n *\n * @param source - Upstream node.\n * @param predicate - Match test.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - First-match stream.\n *\n * @example\n * ```ts\n * import { find, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = find(state(1), (x) => x > 0);\n * ```\n *\n * @category extra\n */\nexport function find<T>(\n\tsource: Node<T>,\n\tpredicate: (value: T) => boolean,\n\topts?: ExtraOpts,\n): Node<T> {\n\treturn take(filter(source, predicate, opts), 1, opts);\n}\n\n/**\n * Emits the `index`th **`DATA`** (zero-based), then **`COMPLETE`**.\n *\n * @param source - Upstream node.\n * @param index - Zero-based emission index.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Single indexed value.\n *\n * @example\n * ```ts\n * import { elementAt, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = elementAt(state(0), 2);\n * ```\n *\n * @category extra\n */\nexport function elementAt<T>(source: Node<T>, index: number, opts?: ExtraOpts): Node<T> {\n\treturn take(skip(source, index, opts), 1, opts);\n}\n\n/**\n * Observer shape for {@link tap} — side effects for data, error, and/or complete.\n */\nexport type TapObserver<T> = {\n\tdata?: (value: T) => void;\n\terror?: (err: unknown) => void;\n\tcomplete?: () => void;\n};\n\n/**\n * Invokes side effects; values pass through unchanged.\n *\n * Accepts either a function (called on each DATA) or an observer object\n * `{ data?, error?, complete? }` for lifecycle-aware side effects.\n *\n * @param source - Upstream node.\n * @param fnOrObserver - Side effect function or observer object.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Passthrough node.\n *\n * @example\n * ```ts\n * import { tap, state } from \"@graphrefly/graphrefly-ts\";\n *\n * // Function form (DATA only)\n * tap(state(1), (x) => console.log(x));\n *\n * // Observer form (DATA + ERROR + COMPLETE)\n * tap(state(1), { data: console.log, error: console.error, complete: () => console.log(\"done\") });\n * ```\n *\n * @category extra\n */\nexport function tap<T>(\n\tsource: Node<T>,\n\tfnOrObserver: ((value: T) => void) | TapObserver<T>,\n\topts?: ExtraOpts,\n): Node<T> {\n\tif (typeof fnOrObserver === \"function\") {\n\t\treturn node<T>(\n\t\t\t[source as Node],\n\t\t\t(data, a) => {\n\t\t\t\tconst batch0 = data[0];\n\t\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tfor (const v of batch0) {\n\t\t\t\t\tfnOrObserver(v as T);\n\t\t\t\t\ta.emit(v as T);\n\t\t\t\t}\n\t\t\t},\n\t\t\toperatorOpts(opts),\n\t\t);\n\t}\n\tconst obs = fnOrObserver;\n\treturn node<T>(\n\t\t[source as Node],\n\t\t(data, a, ctx) => {\n\t\t\t// Check for terminal events\n\t\t\tif (ctx.terminalDeps[0] !== undefined) {\n\t\t\t\tif (ctx.terminalDeps[0] === true) {\n\t\t\t\t\tobs.complete?.();\n\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t} else {\n\t\t\t\t\tobs.error?.(ctx.terminalDeps[0]);\n\t\t\t\t\ta.down([[ERROR, ctx.terminalDeps[0]]]);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor (const v of batch0) {\n\t\t\t\tobs.data?.(v as T);\n\t\t\t\ta.emit(v as T);\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t...operatorOpts(opts),\n\t\t\tcompleteWhenDepsComplete: false,\n\t\t},\n\t);\n}\n\n/**\n * Suppresses adjacent duplicates using `equals` (default `Object.is`).\n *\n * @param source - Upstream node.\n * @param equals - Optional equality for consecutive values.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Deduped stream.\n *\n * @example\n * ```ts\n * import { distinctUntilChanged, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = distinctUntilChanged(state(1));\n * ```\n *\n * @category extra\n */\nexport function distinctUntilChanged<T>(\n\tsource: Node<T>,\n\tequals: (a: T, b: T) => boolean = Object.is,\n\topts?: ExtraOpts,\n): Node<T> {\n\treturn node<T>(\n\t\t[source as Node],\n\t\t(data, a, ctx) => {\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet emitted = false;\n\t\t\tfor (const val of batch0 as T[]) {\n\t\t\t\tif (ctx.store.hasPrev && equals(ctx.store.prev as T, val)) {\n\t\t\t\t\t// Suppressed — same as previous\n\t\t\t\t} else {\n\t\t\t\t\tctx.store.prev = val;\n\t\t\t\t\tctx.store.hasPrev = true;\n\t\t\t\t\ta.emit(val);\n\t\t\t\t\temitted = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!emitted) a.down([[RESOLVED]]);\n\t\t},\n\t\toperatorOpts(opts),\n\t);\n}\n\n/**\n * Emits `[previous, current]` pairs starting after the second value (first pair uses `RESOLVED` only).\n *\n * @param source - Upstream node.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<readonly [T, T]>` - Pair stream.\n *\n * @example\n * ```ts\n * import { pairwise, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = pairwise(state(0));\n * ```\n *\n * @category extra\n */\nexport function pairwise<T>(source: Node<T>, opts?: ExtraOpts): Node<readonly [T, T]> {\n\treturn node<readonly [T, T]>(\n\t\t[source as Node],\n\t\t(data, a, ctx) => {\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet emitted = false;\n\t\t\tfor (const x of batch0 as T[]) {\n\t\t\t\tif (!ctx.store.hasPrev) {\n\t\t\t\t\tctx.store.prev = x;\n\t\t\t\t\tctx.store.hasPrev = true;\n\t\t\t\t\t// First value — no pair yet\n\t\t\t\t} else {\n\t\t\t\t\tconst pair = [ctx.store.prev as T, x] as const;\n\t\t\t\t\tctx.store.prev = x;\n\t\t\t\t\ta.emit(pair);\n\t\t\t\t\temitted = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!emitted) a.down([[RESOLVED]]);\n\t\t},\n\t\toperatorOpts(opts),\n\t);\n}\n\n/**\n * Combines the latest value from each dependency whenever any dep settles (combineLatest).\n *\n * @param sources - Nodes to combine (variadic).\n * @returns `Node<T>` - Tuple of latest values.\n *\n * @example\n * ```ts\n * import { combine, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = combine(state(1), state(\"a\"));\n * ```\n *\n * @remarks\n * Unlike RxJS `combineLatest`, this is named `combine`. Use the {@link combineLatest} alias\n * if you prefer the RxJS name. Seed is always required for `scan`/`reduce` (no seedless mode).\n *\n * @category extra\n */\nexport function combine<const T extends readonly unknown[]>(\n\t...sources: { [K in keyof T]: Node<T[K]> }\n): Node<T> {\n\tconst deps = [...sources] as unknown as Node[];\n\treturn derived(deps, (vals) => vals as unknown as T, {\n\t\t...operatorOpts<T>(),\n\t\tequals: (a, b) => {\n\t\t\tif (a.length !== b.length) return false;\n\t\t\tfor (let i = 0; i < a.length; i++) {\n\t\t\t\tif (!Object.is(a[i], b[i])) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t},\n\t});\n}\n\n/**\n * When `primary` settles, emits `[primary, latestSecondary]`. `secondary` alone updates cache only.\n *\n * @param primary - Main stream.\n * @param secondary - Latest value is paired on each primary emission.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<readonly [A, B]>` - Paired stream.\n *\n * @example\n * ```ts\n * import { state, withLatestFrom } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = withLatestFrom(state(1), state(\"x\"));\n * ```\n *\n * @category extra\n */\nexport function withLatestFrom<A, B>(\n\tprimary: Node<A>,\n\tsecondary: Node<B>,\n\topts?: ExtraOpts,\n): Node<readonly [A, B]> {\n\t// Known semantic (documented): on initial activation when BOTH deps are\n\t// `state()` nodes with cached values, the paired emission is dropped.\n\t// `_activate` (src/core/node.ts:1002) subscribes deps sequentially in\n\t// declaration order; primary's push-on-subscribe fires before secondary\n\t// has subscribed, so the first-run gate (§2.7) forces RESOLVED. Secondary\n\t// then fires in a separate wave with primary silent, and the fn's\n\t// \"emit only when primary fired this wave\" rule takes the else branch.\n\t// Use the factory-time seed pattern for initial-value pairing (see\n\t// stratify, budgetGate, distill for examples; COMPOSITION-GUIDE §21).\n\t// A naïve `[secondary, primary]` flip breaks topology-sensitive diamond\n\t// callers like `harness/loop.ts` — the fix needs a deeper design pass.\n\treturn node<readonly [A, B]>(\n\t\t[primary as Node, secondary as Node],\n\t\t(data, a, ctx) => {\n\t\t\tconst batch0 = data[0];\n\t\t\tconst batch1 = data[1];\n\t\t\t// Current secondary value: this wave's last DATA if secondary fired,\n\t\t\t// otherwise last known value from ctx.prevData (previous wave).\n\t\t\tconst secondaryVal = (\n\t\t\t\tbatch1 != null && batch1.length > 0 ? batch1.at(-1) : ctx.prevData[1]\n\t\t\t) as B | undefined;\n\n\t\t\t// Only emit when primary (dep 0) sent DATA this wave.\n\t\t\tif (batch0 != null && batch0.length > 0) {\n\t\t\t\t// secondary has never produced DATA — undefined is the protocol\n\t\t\t\t// sentinel for \"never sent DATA\"; null is a valid DATA value.\n\t\t\t\tif (!(batch1 != null && batch1.length > 0) && ctx.prevData[1] === undefined) {\n\t\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tfor (const v of batch0 as A[]) {\n\t\t\t\t\ta.emit([v, secondaryVal]);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Secondary update only (or both RESOLVED) — no downstream DATA.\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t}\n\t\t},\n\t\toperatorOpts(opts),\n\t);\n}\n\n/**\n * Merges **`DATA`** from any source with correct two-phase dirty tracking. **`COMPLETE`** after **all** sources complete (spec §1.3.5).\n *\n * @param sources - Nodes to merge (variadic; empty completes immediately).\n * @returns `Node<T>` - Merged stream.\n *\n * @remarks\n * **Ordering:** DIRTY/RESOLVED rules follow multi-source semantics in `~/src/graphrefly/GRAPHREFLY-SPEC.md`.\n *\n * @example\n * ```ts\n * import { merge, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = merge(state(1), state(2));\n * ```\n *\n * @category extra\n */\nexport function merge<T>(...sources: readonly Node<T>[]): Node<T> {\n\tif (sources.length === 0) {\n\t\treturn producer<T>((a) => {\n\t\t\ta.down([[COMPLETE]]);\n\t\t}, operatorOpts());\n\t}\n\t// producer pattern: node() cannot be used here because the sentinel gate\n\t// would block the fn until ALL sources have sent their first DATA, which\n\t// defeats the purpose of merge (forward whichever source fires first).\n\treturn producer<T>((a) => {\n\t\tconst n = sources.length;\n\t\tlet completed = 0;\n\t\tconst unsubs: (() => void)[] = [];\n\t\tfor (const src of sources) {\n\t\t\tconst u = src.subscribe((msgs) => {\n\t\t\t\tfor (const m of msgs) {\n\t\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\t\ta.emit(m[1] as T);\n\t\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\t\tcompleted += 1;\n\t\t\t\t\t\tif (completed >= n) {\n\t\t\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\t\ta.down([m]);\n\t\t\t\t\t}\n\t\t\t\t\t// DIRTY, RESOLVED, START silently absorbed\n\t\t\t\t}\n\t\t\t});\n\t\t\tunsubs.push(u);\n\t\t}\n\t\treturn () => {\n\t\t\tfor (const u of unsubs) u();\n\t\t};\n\t}, operatorOpts());\n}\n\n/**\n * Zips one **`DATA`** from each source per cycle into a tuple. Only **`DATA`** enqueues (spec §1.3.3).\n *\n * @param sources - Nodes to zip (variadic).\n * @returns `Node<T>` - Zipped tuples.\n *\n * @example\n * ```ts\n * import { state, zip } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = zip(state(1), state(2));\n * ```\n *\n * @category extra\n */\nexport function zip<const T extends readonly unknown[]>(\n\t...sources: { [K in keyof T]: Node<T[K]> }\n): Node<T> {\n\tconst n = sources.length;\n\tif (n === 0) {\n\t\treturn producer<T>((a) => {\n\t\t\ta.emit([] as unknown as T);\n\t\t\ta.down([[COMPLETE]]);\n\t\t}, operatorOpts());\n\t}\n\t// Producer pattern: manage queues internally.\n\treturn producer<T>((a) => {\n\t\tconst queues: unknown[][] = Array.from({ length: n }, () => []);\n\t\tlet active = n;\n\n\t\tfunction tryEmit(): void {\n\t\t\twhile (queues.every((q) => q.length > 0)) {\n\t\t\t\tconst tuple = queues.map((q) => q.shift()!) as unknown as T;\n\t\t\t\ta.emit(tuple);\n\t\t\t}\n\t\t}\n\n\t\tconst unsubs: (() => void)[] = [];\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tconst idx = i;\n\t\t\tconst u = (sources[i] as Node).subscribe((msgs) => {\n\t\t\t\tfor (const m of msgs) {\n\t\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\t\tqueues[idx].push(m[1]);\n\t\t\t\t\t\ttryEmit();\n\t\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\t\tactive -= 1;\n\t\t\t\t\t\tif (active === 0 || queues[idx].length === 0) {\n\t\t\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\t\ta.down([m]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t\tunsubs.push(u);\n\t\t}\n\t\treturn () => {\n\t\t\tfor (const u of unsubs) u();\n\t\t};\n\t}, operatorOpts());\n}\n\n/**\n * Plays all of `firstSrc`, then all of `secondSrc`. **`DATA`** from `secondSrc` during phase one is buffered until handoff.\n *\n * @param firstSrc - First segment.\n * @param secondSrc - Second segment.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Concatenated stream.\n *\n * @example\n * ```ts\n * import { concat, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = concat(state(1), state(2));\n * ```\n *\n * @category extra\n */\nexport function concat<T>(firstSrc: Node<T>, secondSrc: Node<T>, opts?: ExtraOpts): Node<T> {\n\t// producer pattern: node() cannot be used here because the sentinel gate\n\t// would block the fn until ALL sources have sent their first DATA, which\n\t// defeats the purpose of concat (start forwarding firstSrc immediately,\n\t// regardless of secondSrc state).\n\treturn producer<T>((a) => {\n\t\tlet phase: 0 | 1 = 0;\n\t\tconst pending: unknown[] = [];\n\t\tlet firstUnsub: (() => void) | undefined;\n\t\tlet secondUnsub: (() => void) | undefined;\n\n\t\tsecondUnsub = secondSrc.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (phase === 0) {\n\t\t\t\t\tif (m[0] === DATA) pending.push(m[1]);\n\t\t\t\t\telse if (m[0] === ERROR) a.down([m]);\n\t\t\t\t} else {\n\t\t\t\t\t// phase 1 — forward everything from second\n\t\t\t\t\tif (m[0] === DATA) a.emit(m[1] as T);\n\t\t\t\t\telse if (m[0] === COMPLETE || m[0] === ERROR) a.down([m]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tfirstUnsub = firstSrc.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (phase === 0) {\n\t\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\t\ta.emit(m[1] as T);\n\t\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\t\tphase = 1;\n\t\t\t\t\t\t// Flush buffered second-source DATA\n\t\t\t\t\t\tfor (const v of pending) {\n\t\t\t\t\t\t\ta.emit(v as T);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpending.length = 0;\n\t\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\t\ta.down([m]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// phase 1: ignore further first-source messages\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tfirstUnsub?.();\n\t\t\tsecondUnsub?.();\n\t\t};\n\t}, operatorOpts(opts));\n}\n\n/**\n * First source to emit **`DATA`** wins; later traffic follows only the winner (Rx-style `race`).\n *\n * @param sources - Contestants (variadic; empty completes immediately; one node is identity).\n * @returns `Node<T>` - Winning stream.\n *\n * @example\n * ```ts\n * import { race, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = race(state(1), state(2));\n * ```\n *\n * @category extra\n */\nexport function race<T>(...sources: readonly Node<T>[]): Node<T> {\n\tif (sources.length === 0) {\n\t\treturn producer<T>((a) => {\n\t\t\ta.down([[COMPLETE]]);\n\t\t}, operatorOpts());\n\t}\n\tif (sources.length === 1) {\n\t\t// Identity passthrough — full batch iteration, not derived's .at(-1).\n\t\treturn node<T>(\n\t\t\t[sources[0] as Node],\n\t\t\t(data, a) => {\n\t\t\t\tconst batch0 = data[0];\n\t\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tfor (const v of batch0) a.emit(v as T);\n\t\t\t},\n\t\t\toperatorOpts<T>(),\n\t\t);\n\t}\n\t// Producer pattern: first DATA wins.\n\treturn producer<T>((a) => {\n\t\tlet winner: number | null = null;\n\t\tconst unsubs: (() => void)[] = [];\n\t\tfor (let i = 0; i < sources.length; i++) {\n\t\t\tconst idx = i;\n\t\t\tconst u = (sources[i] as Node).subscribe((msgs) => {\n\t\t\t\tfor (const m of msgs) {\n\t\t\t\t\tif (winner !== null && idx !== winner) return;\n\t\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\t\tif (winner === null) winner = idx;\n\t\t\t\t\t\ta.emit(m[1] as T);\n\t\t\t\t\t} else if (m[0] === COMPLETE || m[0] === ERROR) {\n\t\t\t\t\t\tif (winner === null || idx === winner) {\n\t\t\t\t\t\t\ta.down([m]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t\tunsubs.push(u);\n\t\t}\n\t\treturn () => {\n\t\t\tfor (const u of unsubs) u();\n\t\t};\n\t}, operatorOpts());\n}\n\n// --- Tier 2: async / dynamic (roadmap §2.2), all on `node` / `producer` ---\n\nfunction forwardInner<R>(inner: Node<R>, a: NodeActions, onInnerComplete: () => void): () => void {\n\tlet unsub: (() => void) | undefined;\n\tlet finished = false;\n\tconst finish = (): void => {\n\t\tif (finished) return;\n\t\tfinished = true;\n\t\tonInnerComplete();\n\t};\n\tunsub = inner.subscribe((msgs) => {\n\t\tlet sawComplete = false;\n\t\tlet sawError = false;\n\t\tfor (const m of msgs) {\n\t\t\tif (m[0] === START) continue;\n\t\t\tif (m[0] === DATA) {\n\t\t\t\ta.emit(m[1] as R);\n\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\tsawComplete = true;\n\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\tsawError = true;\n\t\t\t\ta.down([m]);\n\t\t\t} else if (m[0] === DIRTY || m[0] === RESOLVED) {\n\t\t\t\t// Reactive wave signals forwarded to outer output.\n\t\t\t\ta.down([m]);\n\t\t\t}\n\t\t\t// INVALIDATE, PAUSE, RESUME, TEARDOWN from inner are intentionally\n\t\t\t// dropped. Inner lifecycle and flow-control signals are internal to\n\t\t\t// the *Map operator. INVALIDATE is dropped because the inner will\n\t\t\t// follow up with DIRTY+DATA when it recomputes — forwarding\n\t\t\t// INVALIDATE to the outer output's sinks is redundant and wrong for\n\t\t\t// mergeMap (one inner's cache state must not invalidate the whole\n\t\t\t// merged output). PAUSE/RESUME/TEARDOWN: RxJS/callbag precedent —\n\t\t\t// no backpressure forwarding in merge-style operators.\n\t\t}\n\t\tif (sawError) {\n\t\t\tunsub?.();\n\t\t\tunsub = undefined;\n\t\t\tfinish();\n\t\t} else if (sawComplete) {\n\t\t\tfinish();\n\t\t}\n\t});\n\t// P4 START handshake guarantees: subscribe delivers [[START], [DATA, cache]]\n\t// synchronously for settled nodes. Any relevant state is already handled by\n\t// the callback above — no post-subscribe .status/.cache reads needed.\n\treturn () => {\n\t\tunsub?.();\n\t\tunsub = undefined;\n\t};\n}\n\n/**\n * Maps each settled value to an inner node; unsubscribes the previous inner (Rx-style `switchMap`).\n *\n * @param source - Upstream node.\n * @param project - Maps each outer value to an inner source shape (`Node`, scalar, `PromiseLike`, `Iterable`, or `AsyncIterable`) coerced via {@link fromAny}.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<R>` - Emissions from the active inner subscription.\n * @example\n * ```ts\n * import { switchMap, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const src = state(0);\n * switchMap(src, (n) => state((n as number) * 2));\n * ```\n *\n * @category extra\n */\nexport function switchMap<T, R>(\n\tsource: Node<T>,\n\tproject: (value: T) => NodeInput<R>,\n\topts?: ExtraOpts,\n): Node<R> {\n\tlet innerUnsub: (() => void) | undefined;\n\tlet sourceDone = false;\n\n\tfunction clearInner(): void {\n\t\tinnerUnsub?.();\n\t\tinnerUnsub = undefined;\n\t}\n\n\treturn node<R>(\n\t\t[source as Node],\n\t\t(data, a, ctx) => {\n\t\t\t// Source ERROR: cleanup inner, autoError forwards\n\t\t\tif (ctx.terminalDeps[0] != null && ctx.terminalDeps[0] !== true) {\n\t\t\t\tclearInner();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Source COMPLETE\n\t\t\tif (ctx.terminalDeps[0] === true) {\n\t\t\t\tsourceDone = true;\n\t\t\t\tif (!innerUnsub) a.down([[COMPLETE]]);\n\t\t\t\t// inner active: onInnerComplete will fire COMPLETE later\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) return;\n\n\t\t\t// Switch: only the latest value matters; skip to the last in the\n\t\t\t// batch to avoid creating and immediately discarding N-1 inners.\n\t\t\t// clearInner() runs once to cancel any prior-wave inner.\n\t\t\tclearInner();\n\t\t\tinnerUnsub = forwardInner(fromAny(project(batch0[batch0.length - 1] as T)), a, () => {\n\t\t\t\tclearInner();\n\t\t\t\tif (sourceDone) a.down([[COMPLETE]]);\n\t\t\t});\n\n\t\t\t// Deactivation-only cleanup: must NOT fire before fn reruns\n\t\t\t// because the terminal wave needs to see innerUnsub intact.\n\t\t\treturn {\n\t\t\t\tdeactivation: () => {\n\t\t\t\t\tclearInner();\n\t\t\t\t\tsourceDone = false;\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\t{ ...operatorOpts(opts), completeWhenDepsComplete: false },\n\t);\n}\n\n/**\n * Like {@link switchMap}, but ignores outer `DATA` while an inner subscription is active (`exhaustMap`).\n *\n * @param source - Upstream node.\n * @param project - Maps each outer value to an inner source shape (`Node`, scalar, `PromiseLike`, `Iterable`, or `AsyncIterable`) coerced via {@link fromAny}.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<R>` - Emissions from the active inner while it runs.\n * @example\n * ```ts\n * import { exhaustMap, state } from \"@graphrefly/graphrefly-ts\";\n *\n * exhaustMap(state(0), () => state(1));\n * ```\n *\n * @category extra\n */\nexport function exhaustMap<T, R>(\n\tsource: Node<T>,\n\tproject: (value: T) => NodeInput<R>,\n\topts?: ExtraOpts,\n): Node<R> {\n\tlet innerUnsub: (() => void) | undefined;\n\tlet sourceDone = false;\n\n\tfunction clearInner(): void {\n\t\tinnerUnsub?.();\n\t\tinnerUnsub = undefined;\n\t}\n\n\treturn node<R>(\n\t\t[source as Node],\n\t\t(data, a, ctx) => {\n\t\t\tif (ctx.terminalDeps[0] != null && ctx.terminalDeps[0] !== true) {\n\t\t\t\tclearInner();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (ctx.terminalDeps[0] === true) {\n\t\t\t\tsourceDone = true;\n\t\t\t\tif (!innerUnsub) a.down([[COMPLETE]]);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) return;\n\n\t\t\tif (innerUnsub === undefined) {\n\t\t\t\t// First value in batch wins (FIFO exhaustMap gate)\n\t\t\t\tinnerUnsub = forwardInner(fromAny(project(batch0[0] as T)), a, () => {\n\t\t\t\t\tclearInner();\n\t\t\t\t\tif (sourceDone) a.down([[COMPLETE]]);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\t// Inner active — drop, settle the dep-wave\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tdeactivation: () => {\n\t\t\t\t\tclearInner();\n\t\t\t\t\tsourceDone = false;\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\t{ ...operatorOpts(opts), completeWhenDepsComplete: false },\n\t);\n}\n\n/**\n * Enqueues each outer value and subscribes to inners one at a time (`concatMap`).\n *\n * @param source - Upstream node.\n * @param project - Maps each outer value to an inner source shape (`Node`, scalar, `PromiseLike`, `Iterable`, or `AsyncIterable`) coerced via {@link fromAny}.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<R>` - Sequential concatenation of inner streams.\n * @example\n * ```ts\n * import { concatMap, state } from \"@graphrefly/graphrefly-ts\";\n *\n * concatMap(state(0), (n) => state((n as number) + 1));\n * ```\n *\n * @category extra\n */\nexport function concatMap<T, R>(\n\tsource: Node<T>,\n\tproject: (value: T) => NodeInput<R>,\n\topts?: ExtraOpts & { maxBuffer?: number },\n): Node<R> {\n\tconst { maxBuffer: maxBuf, ...concatNodeOpts } = opts ?? {};\n\tconst queue: T[] = [];\n\tlet innerUnsub: (() => void) | undefined;\n\tlet sourceDone = false;\n\tlet actions: NodeActions | undefined;\n\n\tfunction clearInner(): void {\n\t\tinnerUnsub?.();\n\t\tinnerUnsub = undefined;\n\t}\n\n\tfunction tryPump(): void {\n\t\tif (!actions || innerUnsub !== undefined) return;\n\t\tif (queue.length === 0) {\n\t\t\tif (sourceDone) actions.down([[COMPLETE]]);\n\t\t\treturn;\n\t\t}\n\t\tconst v = queue.shift()!;\n\t\tinnerUnsub = forwardInner(fromAny(project(v)), actions, () => {\n\t\t\tclearInner();\n\t\t\ttryPump();\n\t\t});\n\t}\n\n\tfunction enqueue(v: T): void {\n\t\tif (maxBuf && maxBuf > 0 && queue.length >= maxBuf) queue.shift();\n\t\tqueue.push(v);\n\t\ttryPump();\n\t}\n\n\treturn node<R>(\n\t\t[source as Node],\n\t\t(data, a, ctx) => {\n\t\t\tactions = a;\n\n\t\t\tif (ctx.terminalDeps[0] != null && ctx.terminalDeps[0] !== true) {\n\t\t\t\tclearInner();\n\t\t\t\tqueue.length = 0;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (ctx.terminalDeps[0] === true) {\n\t\t\t\tsourceDone = true;\n\t\t\t\ttryPump();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) return;\n\n\t\t\tfor (const v of batch0 as T[]) {\n\t\t\t\tenqueue(v as T);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tdeactivation: () => {\n\t\t\t\t\tclearInner();\n\t\t\t\t\tqueue.length = 0;\n\t\t\t\t\tsourceDone = false;\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\t{ ...operatorOpts(concatNodeOpts), completeWhenDepsComplete: false },\n\t);\n}\n\n/** Options for {@link mergeMap}. */\nexport type MergeMapOptions = ExtraOpts & {\n\t/** Maximum number of concurrent inner subscriptions. Default: `Infinity` (unbounded). */\n\tconcurrent?: number;\n};\n\n/**\n * Subscribes to inner nodes in parallel (up to `concurrent`) and merges outputs (`mergeMap` / `flatMap`).\n *\n * @param source - Upstream node.\n * @param project - Maps each outer value to an inner source shape (`Node`, scalar, `PromiseLike`, `Iterable`, or `AsyncIterable`) coerced via {@link fromAny}.\n * @param opts - Optional options including `concurrent` limit.\n * @returns `Node<R>` - Merged output of all active inners; completes when the outer and every inner complete.\n *\n * @remarks\n * **ERROR handling:** An `ERROR` from the outer source cancels all active inner\n * subscriptions and propagates the error downstream. An `ERROR` from an inner\n * subscription propagates downstream immediately but does **not** cancel sibling\n * inner subscriptions — other active inners continue until they complete or the\n * outer errors/completes. This is intentional: for parallel work, isolating\n * failures per-inner is more useful than Rx-style \"first error cancels all.\"\n *\n * @example\n * ```ts\n * import { mergeMap, state } from \"@graphrefly/graphrefly-ts\";\n *\n * // Unbounded (default)\n * mergeMap(state(0), (n) => state((n as number) + 1));\n *\n * // Limited concurrency\n * mergeMap(state(0), (n) => state((n as number) + 1), { concurrent: 3 });\n * ```\n *\n * @category extra\n */\nexport function mergeMap<T, R>(\n\tsource: Node<T>,\n\tproject: (value: T) => NodeInput<R>,\n\topts?: MergeMapOptions,\n): Node<R> {\n\tconst { concurrent: concurrentOpt, ...mergeNodeOpts } = opts ?? {};\n\tconst maxConcurrent =\n\t\tconcurrentOpt != null && concurrentOpt > 0 ? concurrentOpt : Number.POSITIVE_INFINITY;\n\n\tlet active = 0;\n\tlet sourceDone = false;\n\tconst innerStops = new Set<() => void>();\n\tconst buffer: T[] = [];\n\tlet actions: NodeActions | undefined;\n\n\tfunction tryComplete(): void {\n\t\tif (sourceDone && active === 0 && buffer.length === 0 && actions) {\n\t\t\tactions.down([[COMPLETE]]);\n\t\t}\n\t}\n\n\tfunction spawn(v: T): void {\n\t\tif (!actions) return;\n\t\tactive++;\n\t\t// Use `let` (not `const`) so the closure can reference `stop` safely even\n\t\t// if onInnerComplete fires synchronously (e.g. already-completed inner node).\n\t\tlet stop: (() => void) | undefined;\n\t\tstop = forwardInner(fromAny(project(v)), actions, () => {\n\t\t\tif (stop) innerStops.delete(stop);\n\t\t\tactive--;\n\t\t\tdrainBuffer();\n\t\t\ttryComplete();\n\t\t});\n\t\tinnerStops.add(stop);\n\t}\n\n\tfunction drainBuffer(): void {\n\t\twhile (buffer.length > 0 && active < maxConcurrent) {\n\t\t\tspawn(buffer.shift()!);\n\t\t}\n\t}\n\n\tfunction enqueue(v: T): void {\n\t\tif (active < maxConcurrent) spawn(v);\n\t\telse buffer.push(v);\n\t}\n\n\tfunction clearAll(): void {\n\t\tfor (const u of innerStops) u();\n\t\tinnerStops.clear();\n\t\tactive = 0;\n\t\tbuffer.length = 0;\n\t}\n\n\treturn node<R>(\n\t\t[source as Node],\n\t\t(data, a, ctx) => {\n\t\t\tactions = a;\n\n\t\t\tif (ctx.terminalDeps[0] != null && ctx.terminalDeps[0] !== true) {\n\t\t\t\tclearAll();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (ctx.terminalDeps[0] === true) {\n\t\t\t\tsourceDone = true;\n\t\t\t\ttryComplete();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) return;\n\n\t\t\tfor (const v of batch0 as T[]) {\n\t\t\t\tenqueue(v as T);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tdeactivation: () => {\n\t\t\t\t\tclearAll();\n\t\t\t\t\tsourceDone = false;\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\t{ ...operatorOpts(mergeNodeOpts), completeWhenDepsComplete: false },\n\t);\n}\n\n/**\n * RxJS-named alias for {@link mergeMap} — projects each `DATA` to an inner node and merges outputs.\n *\n * @param source - Upstream node.\n * @param project - Returns an inner `Node<R>` per value.\n * @param opts - Optional concurrency cap and node options (excluding `describeKind`).\n * @returns Merged projection; behavior matches `mergeMap`.\n *\n * @example\n * ```ts\n * import { flatMap, state } from \"@graphrefly/graphrefly-ts\";\n *\n * flatMap(state(0), (n) => state(n));\n * ```\n *\n * @category extra\n */\nexport const flatMap = mergeMap;\n\n/**\n * Delays phase-2 emissions by `ms` (timers). `DIRTY` still forwards immediately.\n *\n * @param source - Upstream node.\n * @param ms - Delay in milliseconds.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Same values, shifted in time.\n * @example\n * ```ts\n * import { delay, state } from \"@graphrefly/graphrefly-ts\";\n *\n * delay(state(1), 100);\n * ```\n *\n * @category extra\n */\nexport function delay<T>(source: Node<T>, ms: number, opts?: ExtraOpts): Node<T> {\n\treturn producer<T>((a) => {\n\t\tconst timers = new Set<ReturnType<typeof setTimeout>>();\n\t\tfunction clearAll(): void {\n\t\t\tfor (const id of timers) clearTimeout(id);\n\t\t\ttimers.clear();\n\t\t}\n\n\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tconst id = setTimeout(() => {\n\t\t\t\t\t\ttimers.delete(id);\n\t\t\t\t\t\ta.emit(m[1] as T);\n\t\t\t\t\t}, ms);\n\t\t\t\t\ttimers.add(id);\n\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\t// Wait for all pending timers, then complete\n\t\t\t\t\tconst id = setTimeout(() => {\n\t\t\t\t\t\ttimers.delete(id);\n\t\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t\t}, ms);\n\t\t\t\t\ttimers.add(id);\n\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\tclearAll();\n\t\t\t\t\ta.down([m]);\n\t\t\t\t}\n\t\t\t\t// DIRTY from source is NOT forwarded — delay transforms the\n\t\t\t\t// timeline. a.emit(v) in the timer callback handles full\n\t\t\t\t// DIRTY+DATA framing atomically at the delayed time.\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tsrcUnsub();\n\t\t\tclearAll();\n\t\t};\n\t}, operatorOpts(opts));\n}\n\n/**\n * Emits the latest value only after `ms` quiet time since the last trigger (`debounce`).\n *\n * @param source - Upstream node.\n * @param ms - Quiet window in milliseconds.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Debounced stream.\n * @example\n * ```ts\n * import { debounce, state } from \"@graphrefly/graphrefly-ts\";\n *\n * debounce(state(0), 50);\n * ```\n *\n * @category extra\n */\nexport function debounce<T>(source: Node<T>, ms: number, opts?: ExtraOpts): Node<T> {\n\treturn producer<T>((a) => {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tlet pending: T | undefined;\n\n\t\tfunction clearTimer(): void {\n\t\t\tif (timer !== undefined) {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\ttimer = undefined;\n\t\t\t}\n\t\t}\n\n\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tclearTimer();\n\t\t\t\t\tpending = m[1] as T;\n\t\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\t\ttimer = undefined;\n\t\t\t\t\t\ta.emit(pending as T);\n\t\t\t\t\t}, ms);\n\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\tif (timer !== undefined) {\n\t\t\t\t\t\tclearTimer();\n\t\t\t\t\t\ta.emit(pending as T);\n\t\t\t\t\t}\n\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\tclearTimer();\n\t\t\t\t\ta.down([m]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tsrcUnsub();\n\t\t\tclearTimer();\n\t\t};\n\t}, operatorOpts(opts));\n}\n\nexport type ThrottleOptions = { leading?: boolean; trailing?: boolean };\n\n/**\n * Rate-limits emissions to at most once per `ms` window (`throttleTime`).\n *\n * @param source - Upstream node.\n * @param ms - Minimum spacing in milliseconds.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`) plus `leading` / `trailing`.\n * @returns `Node<T>` - Throttled stream.\n * @example\n * ```ts\n * import { throttle, state } from \"@graphrefly/graphrefly-ts\";\n *\n * throttle(state(0), 1_000, { trailing: false });\n * ```\n *\n * @category extra\n */\nexport function throttle<T>(\n\tsource: Node<T>,\n\tms: number,\n\topts?: ExtraOpts & ThrottleOptions,\n): Node<T> {\n\tconst { leading: leadingOpt, trailing: trailingOpt, ...throttleNodeOpts } = opts ?? {};\n\tconst leading = leadingOpt !== false;\n\tconst trailing = trailingOpt === true;\n\tconst windowNs = ms * NS_PER_MS;\n\n\treturn producer<T>((a) => {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tlet lastEmitNs = -Infinity;\n\t\tlet pending: T | undefined;\n\t\tlet hasPending = false;\n\n\t\tfunction clearTimer(): void {\n\t\t\tif (timer !== undefined) {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\ttimer = undefined;\n\t\t\t}\n\t\t}\n\n\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tconst v = m[1] as T;\n\t\t\t\t\tconst nowNs = monotonicNs();\n\t\t\t\t\tif (leading && nowNs - lastEmitNs >= windowNs) {\n\t\t\t\t\t\tlastEmitNs = nowNs;\n\t\t\t\t\t\ta.emit(v);\n\t\t\t\t\t\tclearTimer();\n\t\t\t\t\t\tif (trailing) {\n\t\t\t\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\t\t\t\ttimer = undefined;\n\t\t\t\t\t\t\t\tif (hasPending) {\n\t\t\t\t\t\t\t\t\tlastEmitNs = monotonicNs();\n\t\t\t\t\t\t\t\t\ta.emit(pending as T);\n\t\t\t\t\t\t\t\t\thasPending = false;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}, ms);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (trailing) {\n\t\t\t\t\t\tpending = v;\n\t\t\t\t\t\thasPending = true;\n\t\t\t\t\t\tif (timer === undefined) {\n\t\t\t\t\t\t\tconst elapsedMs = (nowNs - lastEmitNs) / NS_PER_MS;\n\t\t\t\t\t\t\ttimer = setTimeout(\n\t\t\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t\t\ttimer = undefined;\n\t\t\t\t\t\t\t\t\tif (hasPending) {\n\t\t\t\t\t\t\t\t\t\tlastEmitNs = monotonicNs();\n\t\t\t\t\t\t\t\t\t\ta.emit(pending as T);\n\t\t\t\t\t\t\t\t\t\thasPending = false;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tMath.max(0, ms - elapsedMs),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (m[0] === COMPLETE || m[0] === ERROR) {\n\t\t\t\t\tclearTimer();\n\t\t\t\t\ta.down([m]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tsrcUnsub();\n\t\t\tclearTimer();\n\t\t};\n\t}, operatorOpts(throttleNodeOpts));\n}\n\n/**\n * Emits the most recent source value whenever `notifier` emits `DATA` (`sample`).\n *\n * Source `COMPLETE` stops sampling (clears held value); notifier `COMPLETE` terminates the\n * operator. `ERROR` from either dep terminates immediately. At most one terminal message is\n * emitted downstream (latch). Supports `resubscribable` — `ctx.store` resets automatically.\n *\n * @param source - Node whose latest value is sampled.\n * @param notifier - When this node emits `DATA`, a sample is taken.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Sampled snapshots of `source`.\n * @example\n * ```ts\n * import { sample, state } from \"@graphrefly/graphrefly-ts\";\n *\n * sample(state(1), state(0));\n * ```\n *\n * @category extra\n */\nexport function sample<T>(source: Node<T>, notifier: Node<unknown>, opts?: ExtraOpts): Node<T> {\n\treturn producer<T>((a) => {\n\t\tlet lastSourceValue: { v: T } | undefined;\n\t\tlet terminated = false;\n\t\tlet sourceCompleted = false;\n\n\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\tif (terminated) return;\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (terminated) return;\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tlastSourceValue = { v: m[1] as T };\n\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\tterminated = true;\n\t\t\t\t\ta.down([m]);\n\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\tsourceCompleted = true;\n\t\t\t\t\tlastSourceValue = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tconst notUnsub = notifier.subscribe((msgs) => {\n\t\t\tif (terminated) return;\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (terminated) return;\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tif (lastSourceValue !== undefined && !sourceCompleted) {\n\t\t\t\t\t\ta.emit(lastSourceValue.v);\n\t\t\t\t\t}\n\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\tterminated = true;\n\t\t\t\t\ta.down([m]);\n\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\tterminated = true;\n\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tsrcUnsub();\n\t\t\tnotUnsub();\n\t\t};\n\t}, operatorOpts(opts));\n}\n\n/**\n * After each source `DATA`, waits `ms` then emits the latest value if another `DATA` has not arrived (`auditTime` / trailing window).\n *\n * @param source - Upstream node.\n * @param ms - Window in milliseconds after each `DATA`.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Trailing-edge sampled stream.\n * @example\n * ```ts\n * import { audit, state } from \"@graphrefly/graphrefly-ts\";\n *\n * audit(state(0), 100);\n * ```\n *\n * @category extra\n */\nexport function audit<T>(source: Node<T>, ms: number, opts?: ExtraOpts): Node<T> {\n\treturn producer<T>((a) => {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\tlet latest: T | undefined;\n\t\tlet has = false;\n\n\t\tfunction clearTimer(): void {\n\t\t\tif (timer !== undefined) {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\ttimer = undefined;\n\t\t\t}\n\t\t}\n\n\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tlatest = m[1] as T;\n\t\t\t\t\thas = true;\n\t\t\t\t\tclearTimer();\n\t\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\t\ttimer = undefined;\n\t\t\t\t\t\tif (has) {\n\t\t\t\t\t\t\thas = false;\n\t\t\t\t\t\t\ta.emit(latest as T);\n\t\t\t\t\t\t}\n\t\t\t\t\t}, ms);\n\t\t\t\t} else if (m[0] === COMPLETE || m[0] === ERROR) {\n\t\t\t\t\tclearTimer();\n\t\t\t\t\ta.down([m]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tsrcUnsub();\n\t\t\tclearTimer();\n\t\t};\n\t}, operatorOpts(opts));\n}\n\n/**\n * Errors if no `DATA` arrives within `ms` after subscribe or after the previous `DATA`.\n *\n * @param source - Upstream node.\n * @param ms - Idle budget in milliseconds.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`) and `with` for a custom error payload.\n * @returns `Node<T>` - Pass-through with idle watchdog.\n * @example\n * ```ts\n * import { timeout, state } from \"@graphrefly/graphrefly-ts\";\n *\n * timeout(state(0), 5_000);\n * ```\n *\n * @category extra\n */\nexport function timeout<T>(\n\tsource: Node<T>,\n\tms: number,\n\topts?: ExtraOpts & { with?: unknown },\n): Node<T> {\n\tconst { with: withPayload, ...timeoutNodeOpts } = opts ?? {};\n\tconst err = withPayload ?? new Error(\"timeout\");\n\n\treturn producer<T>((a) => {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\n\t\tfunction arm(): void {\n\t\t\tclearTimeout(timer);\n\t\t\ttimer = setTimeout(() => {\n\t\t\t\ttimer = undefined;\n\t\t\t\ta.down([[ERROR, err]]);\n\t\t\t}, ms);\n\t\t}\n\n\t\t// Arm immediately on subscribe\n\t\tarm();\n\n\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tarm();\n\t\t\t\t\ta.emit(m[1] as T);\n\t\t\t\t} else if (m[0] === COMPLETE || m[0] === ERROR) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\ta.down([m]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tsrcUnsub();\n\t\t\tclearTimeout(timer);\n\t\t};\n\t}, operatorOpts(timeoutNodeOpts));\n}\n\n/**\n * Buffers source `DATA` values; flushes an array when `notifier` settles (`buffer`).\n *\n * @param source - Upstream node.\n * @param notifier - Flush trigger on each settlement.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T[]>` - Emits buffered arrays (may be empty-handled via `RESOLVED` when nothing buffered).\n * @example\n * ```ts\n * import { buffer, state } from \"@graphrefly/graphrefly-ts\";\n *\n * buffer(state(0), state(0));\n * ```\n *\n * @category extra\n */\nexport function buffer<T>(source: Node<T>, notifier: Node<unknown>, opts?: ExtraOpts): Node<T[]> {\n\treturn producer<T[]>((a) => {\n\t\tconst buf: T[] = [];\n\n\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tbuf.push(m[1] as T);\n\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\tif (buf.length > 0) a.emit([...buf]);\n\t\t\t\t\tbuf.length = 0;\n\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\ta.down([m]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tconst notUnsub = notifier.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tif (buf.length > 0) {\n\t\t\t\t\t\ta.emit([...buf]);\n\t\t\t\t\t\tbuf.length = 0;\n\t\t\t\t\t}\n\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\t// Notifier complete — forward\n\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\ta.down([m]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tsrcUnsub();\n\t\t\tnotUnsub();\n\t\t\tbuf.length = 0;\n\t\t};\n\t}, operatorOpts(opts));\n}\n\n/**\n * Batches consecutive `DATA` values into arrays of length `count` (`bufferCount` / `windowCount`).\n *\n * @param source - Upstream node.\n * @param count - Buffer size before emit; must be > 0.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T[]>` - Emits fixed-size arrays; remainder flushes on `COMPLETE`.\n * @example\n * ```ts\n * import { bufferCount, state } from \"@graphrefly/graphrefly-ts\";\n *\n * bufferCount(state(0), 3);\n * ```\n *\n * @category extra\n */\nexport function bufferCount<T>(source: Node<T>, count: number, opts?: ExtraOpts): Node<T[]> {\n\tif (count <= 0) throw new RangeError(\"bufferCount expects count > 0\");\n\treturn producer<T[]>((a) => {\n\t\tconst buf: T[] = [];\n\n\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tbuf.push(m[1] as T);\n\t\t\t\t\tif (buf.length >= count) {\n\t\t\t\t\t\ta.emit(buf.splice(0, buf.length));\n\t\t\t\t\t}\n\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\tif (buf.length > 0) a.emit([...buf]);\n\t\t\t\t\tbuf.length = 0;\n\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\ta.down([m]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tsrcUnsub();\n\t\t\tbuf.length = 0;\n\t\t};\n\t}, operatorOpts(opts));\n}\n\n/**\n * Splits source `DATA` into sub-nodes of `count` values each. Each sub-node completes after `count` items or when source completes.\n *\n * @param source - Upstream node.\n * @param count - Items per window.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<Node<T>>` - Each emission is a sub-node carrying that window's values.\n *\n * @example\n * ```ts\n * import { windowCount, state } from \"@graphrefly/graphrefly-ts\";\n *\n * windowCount(state(0), 3);\n * ```\n *\n * @category extra\n */\nexport function windowCount<T>(source: Node<T>, count: number, opts?: ExtraOpts): Node<Node<T>> {\n\tif (count <= 0) throw new RangeError(\"windowCount expects count > 0\");\n\n\treturn producer<Node<T>>((a) => {\n\t\tlet winDown: ((msgs: Messages) => void) | undefined;\n\t\tlet n = 0;\n\n\t\tfunction openWindow(): void {\n\t\t\tconst s = producer<T>((actions) => {\n\t\t\t\twinDown = actions.down.bind(actions);\n\t\t\t\treturn () => {\n\t\t\t\t\twinDown = undefined;\n\t\t\t\t};\n\t\t\t}, operatorOpts());\n\t\t\tn = 0;\n\t\t\ta.emit(s);\n\t\t}\n\n\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tif (!winDown) openWindow();\n\t\t\t\t\twinDown?.([[DATA, m[1]]]);\n\t\t\t\t\tn += 1;\n\t\t\t\t\tif (n >= count) {\n\t\t\t\t\t\twinDown?.([[COMPLETE]]);\n\t\t\t\t\t\twinDown = undefined;\n\t\t\t\t\t}\n\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\twinDown?.([[COMPLETE]]);\n\t\t\t\t\twinDown = undefined;\n\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\twinDown?.([m]);\n\t\t\t\t\twinDown = undefined;\n\t\t\t\t\ta.down([m]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tsrcUnsub();\n\t\t\twinDown?.([[COMPLETE]]);\n\t\t\twinDown = undefined;\n\t\t};\n\t}, operatorOpts(opts));\n}\n\n/**\n * Flushes buffered `DATA` values every `ms` (`bufferTime` / `windowTime`).\n *\n * @param source - Upstream node.\n * @param ms - Flush interval in milliseconds.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T[]>` - Time-windowed batches.\n * @example\n * ```ts\n * import { bufferTime, state } from \"@graphrefly/graphrefly-ts\";\n *\n * bufferTime(state(0), 250);\n * ```\n *\n * @category extra\n */\nexport function bufferTime<T>(source: Node<T>, ms: number, opts?: ExtraOpts): Node<T[]> {\n\treturn producer<T[]>((a) => {\n\t\tconst buf: T[] = [];\n\n\t\tconst iv = setInterval(() => {\n\t\t\tif (buf.length > 0) {\n\t\t\t\ta.emit([...buf]);\n\t\t\t\tbuf.length = 0;\n\t\t\t}\n\t\t}, ms);\n\n\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tbuf.push(m[1] as T);\n\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\tclearInterval(iv);\n\t\t\t\t\tif (buf.length > 0) a.emit([...buf]);\n\t\t\t\t\tbuf.length = 0;\n\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\tclearInterval(iv);\n\t\t\t\t\ta.down([m]);\n\t\t\t\t}\n\t\t\t\t// DIRTY from source is NOT forwarded — bufferTime\n\t\t\t\t// transforms the timeline. a.emit(buf) handles full\n\t\t\t\t// DIRTY+DATA framing when the interval fires.\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tsrcUnsub();\n\t\t\tclearInterval(iv);\n\t\t\tbuf.length = 0;\n\t\t};\n\t}, operatorOpts(opts));\n}\n\n/**\n * Splits source `DATA` into time-windowed sub-nodes; each window lasts `ms`.\n *\n * @param source - Upstream node.\n * @param ms - Window duration in milliseconds.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<Node<T>>` - Each emission is a sub-node carrying that window's values.\n *\n * @example\n * ```ts\n * import { windowTime, state } from \"@graphrefly/graphrefly-ts\";\n *\n * windowTime(state(0), 500);\n * ```\n *\n * @category extra\n */\nexport function windowTime<T>(source: Node<T>, ms: number, opts?: ExtraOpts): Node<Node<T>> {\n\treturn producer<Node<T>>((a) => {\n\t\tlet winDown: ((msgs: Messages) => void) | undefined;\n\n\t\tfunction closeWindow(): void {\n\t\t\twinDown?.([[COMPLETE]]);\n\t\t\twinDown = undefined;\n\t\t}\n\n\t\tfunction openWindow(): void {\n\t\t\tconst s = producer<T>((actions) => {\n\t\t\t\twinDown = actions.down.bind(actions);\n\t\t\t\treturn () => {\n\t\t\t\t\twinDown = undefined;\n\t\t\t\t};\n\t\t\t}, operatorOpts());\n\t\t\ta.emit(s);\n\t\t}\n\n\t\topenWindow();\n\t\tconst iv = setInterval(() => {\n\t\t\tcloseWindow();\n\t\t\topenWindow();\n\t\t}, ms);\n\n\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\twinDown?.([[DATA, m[1]]]);\n\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\tclearInterval(iv);\n\t\t\t\t\tcloseWindow();\n\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\tclearInterval(iv);\n\t\t\t\t\twinDown?.([m]);\n\t\t\t\t\tcloseWindow();\n\t\t\t\t\ta.down([m]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tsrcUnsub();\n\t\t\tclearInterval(iv);\n\t\t\tcloseWindow();\n\t\t};\n\t}, operatorOpts(opts));\n}\n\n/**\n * Splits source `DATA` into sub-nodes, opening a new window each time `notifier` emits `DATA`.\n *\n * @param source - Upstream node.\n * @param notifier - Each `DATA` from `notifier` closes the current window and opens a new one.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<Node<T>>` - Each emission is a sub-node carrying that window's values.\n *\n * @example\n * ```ts\n * import { state, window } from \"@graphrefly/graphrefly-ts\";\n *\n * window(state(0), state(0));\n * ```\n *\n * @category extra\n */\nexport function window<T>(\n\tsource: Node<T>,\n\tnotifier: Node<unknown>,\n\topts?: ExtraOpts,\n): Node<Node<T>> {\n\treturn producer<Node<T>>((a) => {\n\t\tlet winDown: ((msgs: Messages) => void) | undefined;\n\n\t\tfunction closeWindow(): void {\n\t\t\twinDown?.([[COMPLETE]]);\n\t\t\twinDown = undefined;\n\t\t}\n\n\t\tfunction openWindow(): void {\n\t\t\tconst s = producer<T>((actions) => {\n\t\t\t\twinDown = actions.down.bind(actions);\n\t\t\t\treturn () => {\n\t\t\t\t\twinDown = undefined;\n\t\t\t\t};\n\t\t\t}, operatorOpts());\n\t\t\ta.emit(s);\n\t\t}\n\n\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tif (!winDown) openWindow();\n\t\t\t\t\twinDown?.([[DATA, m[1]]]);\n\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\tcloseWindow();\n\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\twinDown?.([m]);\n\t\t\t\t\twinDown = undefined;\n\t\t\t\t\ta.down([m]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tconst notUnsub = notifier.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\tcloseWindow();\n\t\t\t\t\topenWindow();\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\treturn () => {\n\t\t\tsrcUnsub();\n\t\t\tnotUnsub();\n\t\t\tcloseWindow();\n\t\t};\n\t}, operatorOpts(opts));\n}\n\n/**\n * Increments on each tick (`interval`); uses `setInterval` via {@link producer}.\n *\n * @param periodMs - Time between ticks.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<number>` - Emits `0`, `1`, `2`, … while subscribed.\n * @example\n * ```ts\n * import { interval } from \"@graphrefly/graphrefly-ts\";\n *\n * interval(1_000);\n * ```\n *\n * @category extra\n */\nexport function interval(periodMs: number, opts?: ExtraOpts): Node<number> {\n\treturn producer<number>((a, ctx) => {\n\t\tif (!(\"n\" in ctx.store)) ctx.store.n = 0;\n\t\tconst id = setInterval(() => {\n\t\t\ta.emit(ctx.store.n as number);\n\t\t\tctx.store.n = (ctx.store.n as number) + 1;\n\t\t}, periodMs);\n\t\treturn () => clearInterval(id);\n\t}, operatorOpts(opts));\n}\n\n/**\n * Subscribes to `source` repeatedly (`count` times, sequentially). Best with a fresh or `resubscribable` source.\n *\n * @param source - Upstream node to replay.\n * @param count - Number of subscription rounds.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Forwards each round then completes after the last inner `COMPLETE`.\n * @example\n * ```ts\n * import { repeat, state } from \"@graphrefly/graphrefly-ts\";\n *\n * repeat(state(1, { resubscribable: true }), 2);\n * ```\n *\n * @category extra\n */\nexport function repeat<T>(source: Node<T>, count: number, opts?: ExtraOpts): Node<T> {\n\tif (count <= 0) throw new RangeError(\"repeat expects count > 0\");\n\treturn producer<T>((a) => {\n\t\tlet remaining = count;\n\t\tlet innerU: (() => void) | undefined;\n\n\t\tconst start = (): void => {\n\t\t\tinnerU?.();\n\t\t\tinnerU = source.subscribe((msgs) => {\n\t\t\t\tlet completed = false;\n\t\t\t\tconst fwd: Message[] = [];\n\t\t\t\tfor (const m of msgs) {\n\t\t\t\t\tif (m[0] === COMPLETE) completed = true;\n\t\t\t\t\telse fwd.push(m);\n\t\t\t\t}\n\t\t\t\tif (fwd.length > 0) a.down(fwd as unknown as Messages);\n\t\t\t\tif (completed) {\n\t\t\t\t\tinnerU?.();\n\t\t\t\t\tinnerU = undefined;\n\t\t\t\t\tremaining -= 1;\n\t\t\t\t\tif (remaining > 0) start();\n\t\t\t\t\telse a.down([[COMPLETE]]);\n\t\t\t\t}\n\t\t\t});\n\t\t};\n\n\t\tstart();\n\t\treturn () => {\n\t\t\tinnerU?.();\n\t\t};\n\t}, operatorOpts(opts));\n}\n\n/**\n * Identity passthrough — `pausable()` has been promoted to default node behavior in v5 (§4).\n *\n * @deprecated Default node behavior now handles PAUSE/RESUME. This operator is a no-op\n * identity passthrough kept only for migration compatibility.\n *\n * @param source - Upstream node.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Pass-through (identity).\n * @example\n * ```ts\n * import { pausable, state } from \"@graphrefly/graphrefly-ts\";\n *\n * // No longer needed — default nodes handle PAUSE/RESUME.\n * const s = state(0);\n * pausable(s); // identity passthrough\n * ```\n *\n * @category extra\n */\nexport function pausable<T>(source: Node<T>, opts?: ExtraOpts): Node<T> {\n\treturn node<T>(\n\t\t[source as Node],\n\t\t(data, a) => {\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 == null || batch0.length === 0) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor (const v of batch0) a.emit(v as T);\n\t\t},\n\t\toperatorOpts<T>(opts),\n\t);\n}\n\n/**\n * Replaces an upstream `ERROR` with a recovered value (`catchError`-style).\n *\n * @param source - Upstream node.\n * @param recover - Maps the error payload to a replacement value; if it throws, `ERROR` is forwarded.\n * @param opts - Optional {@link NodeOptions} (excluding `describeKind`).\n * @returns `Node<T>` - Recovered stream.\n * @example\n * ```ts\n * import { rescue, state } from \"@graphrefly/graphrefly-ts\";\n *\n * rescue(state(0), () => 0);\n * ```\n *\n * @category extra\n */\nexport function rescue<T>(\n\tsource: Node<T>,\n\trecover: (err: unknown) => T,\n\topts?: ExtraOpts,\n): Node<T> {\n\treturn producer<T>((a) => {\n\t\tconst srcUnsub = source.subscribe((msgs) => {\n\t\t\tfor (const m of msgs) {\n\t\t\t\tif (m[0] === DATA) {\n\t\t\t\t\ta.emit(m[1] as T);\n\t\t\t\t} else if (m[0] === ERROR) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\ta.emit(recover(m[1]));\n\t\t\t\t\t} catch (recoverErr) {\n\t\t\t\t\t\ta.down([[ERROR, recoverErr]]);\n\t\t\t\t\t}\n\t\t\t\t} else if (m[0] === COMPLETE) {\n\t\t\t\t\ta.down([[COMPLETE]]);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\treturn () => {\n\t\t\tsrcUnsub();\n\t\t};\n\t}, operatorOpts(opts));\n}\n\n/**\n * Forwards upstream `DATA` only while `control.get()` is truthy; when closed, emits `RESOLVED`\n * instead of repeating the last value (value-level valve). For protocol pause/resume, use default\n * node PAUSE/RESUME behavior.\n *\n * @param source - Upstream value node.\n * @param control - Boolean node; when falsy, output stays \"closed\" for that tick.\n * @param opts - Optional node options (excluding `describeKind`).\n * @returns `Node<T>` gated by `control`.\n *\n * @example\n * ```ts\n * import { valve, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const data = state(1);\n * const open = state(true);\n * valve(data, open);\n * ```\n *\n * @category extra\n */\nexport function valve<T>(source: Node<T>, control: Node<boolean>, opts?: ExtraOpts): Node<T> {\n\treturn node<T>(\n\t\t[source as Node, control as Node],\n\t\t(data, a, ctx) => {\n\t\t\tconst batch1 = data[1];\n\t\t\t// undefined = control never sent DATA (gate closed); falsy = explicitly closed.\n\t\t\tconst controlValue = batch1 != null && batch1.length > 0 ? batch1.at(-1) : ctx.prevData[1];\n\t\t\tif (!controlValue) {\n\t\t\t\ta.down([[RESOLVED]]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst batch0 = data[0];\n\t\t\tif (batch0 != null && batch0.length > 0) {\n\t\t\t\t// Source data this wave: forward it.\n\t\t\t\tfor (const v of batch0) a.emit(v as T);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Control just opened this wave but source didn't fire this wave.\n\t\t\t// Re-emit the last known source value so downstream sees the current\n\t\t\t// value when the gate opens (only when source has a prior value).\n\t\t\tif (batch1 != null && batch1.length > 0 && ctx.prevData[0] !== undefined) {\n\t\t\t\ta.emit(ctx.prevData[0] as T);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ta.down([[RESOLVED]]);\n\t\t},\n\t\toperatorOpts(opts),\n\t);\n}\n\n// ——————————————————————————————————————————————————————————————\n// RxJS-compatible aliases — improve AI code-generation accuracy\n// ——————————————————————————————————————————————————————————————\n\n/**\n * RxJS-named alias for {@link combine} — emits when any dep updates with latest tuple of values.\n *\n * @param sources - Upstream nodes as separate arguments (same calling shape as `combine`).\n * @returns Combined node; signature matches `combine`.\n *\n * @example\n * ```ts\n * import { combineLatest, state } from \"@graphrefly/graphrefly-ts\";\n *\n * const n = combineLatest(state(1), state(\"a\"));\n * ```\n *\n * @category extra\n */\nexport const combineLatest = combine;\n\n/**\n * RxJS-named alias for {@link debounce} — drops rapid `DATA` until `ms` of quiet.\n *\n * @param source - Upstream node.\n * @param ms - Quiet period in milliseconds.\n * @param opts - Optional node options (excluding `describeKind`).\n * @returns Debounced node; behavior matches `debounce`.\n *\n * @example\n * ```ts\n * import { debounceTime, state } from \"@graphrefly/graphrefly-ts\";\n *\n * debounceTime(state(0), 100);\n * ```\n *\n * @category extra\n */\nexport const debounceTime = debounce;\n\n/**\n * RxJS-named alias for {@link throttle} — emits on leading/trailing edges within `ms`.\n *\n * @param source - Upstream node.\n * @param ms - Minimum spacing in milliseconds.\n * @param opts - Optional throttle shape (`leading` / `trailing`) and node options.\n * @returns Throttled node; behavior matches `throttle`.\n *\n * @example\n * ```ts\n * import { throttleTime, state } from \"@graphrefly/graphrefly-ts\";\n *\n * throttleTime(state(0), 100);\n * ```\n *\n * @category extra\n */\nexport const throttleTime = throttle;\n\n/**\n * RxJS-named alias for {@link rescue} — replaces upstream `ERROR` with a recovered value.\n *\n * @param source - Upstream node.\n * @param recover - Maps error payload to replacement value.\n * @param opts - Optional node options (excluding `describeKind`).\n * @returns Recovered stream; behavior matches `rescue`.\n *\n * @example\n * ```ts\n * import { catchError, state } from \"@graphrefly/graphrefly-ts\";\n *\n * catchError(state(0), () => 0);\n * ```\n *\n * @category extra\n */\nexport const catchError = rescue;\n","/**\n * Composite data patterns (roadmap §3.2b).\n *\n * These helpers compose existing primitives (`node`, `switchMap`, `reactiveMap`,\n * `dynamicNode`, `fromAny`) without introducing new protocol semantics.\n */\n\nimport { batch } from \"../core/batch.js\";\nimport { DATA } from \"../core/messages.js\";\nimport type { Node, NodeOptions } from \"../core/node.js\";\nimport { derived, state } from \"../core/sugar.js\";\nimport { merge, switchMap } from \"./operators.js\";\nimport { type ReactiveMapBundle, type ReactiveMapOptions, reactiveMap } from \"./reactive-map.js\";\nimport { forEach, fromAny, type NodeInput } from \"./sources.js\";\n\nfunction isNodeLike<T>(value: unknown): value is Node<T> {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t\"cache\" in (value as Node<T>) &&\n\t\ttypeof (value as Node<T>).subscribe === \"function\"\n\t);\n}\n\n/**\n * Verification payload shape is intentionally user-defined.\n */\nexport type VerifyValue = unknown;\n\nexport type VerifiableOptions<TVerify = VerifyValue> = Omit<\n\tNodeOptions,\n\t\"describeKind\" | \"initial\"\n> & {\n\t/** Reactive re-verification trigger. */\n\ttrigger?: NodeInput<unknown>;\n\t/** Re-run verification whenever `source` settles. */\n\tautoVerify?: boolean;\n\t/** Initial verification companion value. */\n\tinitialVerified?: TVerify | null;\n};\n\nexport type VerifiableBundle<T, TVerify = VerifyValue> = {\n\t/** Coerced source node. */\n\tnode: Node<T>;\n\t/** Latest verification result (`null` before first verification). */\n\tverified: Node<TVerify | null>;\n\t/** Effective trigger node used for verification, if any. */\n\ttrigger: Node<unknown> | null;\n};\n\n/**\n * Composes a value node with a reactive verification companion.\n *\n * Uses `switchMap` so newer triggers cancel stale in-flight verification work.\n */\nexport function verifiable<T, TVerify = VerifyValue>(\n\tsource: NodeInput<T>,\n\tverifyFn: (value: T) => NodeInput<TVerify>,\n\topts?: VerifiableOptions<TVerify>,\n): VerifiableBundle<T, TVerify> {\n\tconst sourceNode = fromAny(source);\n\tconst hasSourceVersioning = sourceNode.v != null;\n\tconst verified = state<TVerify | null>(opts?.initialVerified ?? null, {\n\t\t...(hasSourceVersioning ? { meta: { sourceVersion: null } } : {}),\n\t});\n\tconst hasTrigger = opts?.trigger !== undefined && opts.trigger !== null;\n\n\tlet triggerNode: Node<unknown> | null = null;\n\tif (hasTrigger && opts?.autoVerify) {\n\t\ttriggerNode = merge(fromAny(opts.trigger) as Node<unknown>, sourceNode as Node<unknown>);\n\t} else if (hasTrigger) {\n\t\ttriggerNode = fromAny(opts.trigger);\n\t} else if (opts?.autoVerify) {\n\t\ttriggerNode = sourceNode as Node<unknown>;\n\t}\n\n\tif (triggerNode !== null) {\n\t\t// Closes P3 audit #2. Two patterns used depending on trigger shape:\n\t\t// - autoVerify-only (triggerNode === sourceNode): the projected\n\t\t// switchMap value IS the source DATA, pass it directly.\n\t\t// - explicit trigger: capture the source value into a closure\n\t\t// (`latestSource`) seeded from `sourceNode.cache` at wiring time\n\t\t// (§3.6 boundary read) and kept current via a subscribe handler.\n\t\t// The switchMap fn reads the closure, never `sourceNode.cache`\n\t\t// from a reactive context.\n\t\tlet verifyStream: Node<TVerify>;\n\t\tif (triggerNode === (sourceNode as Node<unknown>)) {\n\t\t\tverifyStream = switchMap(sourceNode, (src) => verifyFn(src as T));\n\t\t} else {\n\t\t\tlet latestSource: T | undefined = sourceNode.cache as T | undefined;\n\t\t\tsourceNode.subscribe((msgs) => {\n\t\t\t\tfor (const m of msgs) {\n\t\t\t\t\tif (m[0] === DATA) latestSource = m[1] as T;\n\t\t\t\t}\n\t\t\t});\n\t\t\tverifyStream = switchMap(triggerNode, () => verifyFn(latestSource as T));\n\t\t}\n\t\tforEach(verifyStream, (value) => {\n\t\t\tbatch(() => {\n\t\t\t\tverified.down([[DATA, value]]);\n\t\t\t\t// V0 backfill: stamp which source version was verified (§6.0b).\n\t\t\t\tif (hasSourceVersioning) {\n\t\t\t\t\tconst sv = sourceNode.v;\n\t\t\t\t\tif (sv != null) {\n\t\t\t\t\t\tverified.meta.sourceVersion.down([[DATA, { id: sv.id, version: sv.version }]]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\treturn { node: sourceNode, verified, trigger: triggerNode };\n}\n\nexport type Extraction<TMem> = {\n\tupsert: Array<{ key: string; value: TMem }>;\n\tremove?: string[];\n};\n\nexport type DistillOptions<TMem> = {\n\tscore: (mem: TMem, context: unknown) => number;\n\tcost: (mem: TMem) => number;\n\tbudget?: number;\n\tevict?: (key: string, mem: TMem) => boolean | Node<boolean>;\n\tconsolidate?: (entries: ReadonlyMap<string, TMem>) => NodeInput<Extraction<TMem>>;\n\tconsolidateTrigger?: NodeInput<unknown>;\n\tcontext?: NodeInput<unknown>;\n\tmapOptions?: ReactiveMapOptions<string, TMem>;\n};\n\nexport type DistillBundle<TMem> = {\n\tstore: ReactiveMapBundle<string, TMem>;\n\tcompact: Node<Array<{ key: string; value: TMem; score: number }>>;\n\tsize: Node<number>;\n};\n\nfunction keepalive(node: Node): void {\n\tnode.subscribe(() => undefined);\n}\n\nfunction mapFromSnapshot<TMem>(snapshot: unknown): ReadonlyMap<string, TMem> {\n\tif (snapshot instanceof Map) return snapshot as ReadonlyMap<string, TMem>;\n\treturn new Map<string, TMem>();\n}\n\nfunction applyExtraction<TMem>(\n\tstore: ReactiveMapBundle<string, TMem>,\n\textraction: Extraction<TMem>,\n): void {\n\tif (!Array.isArray(extraction.upsert)) {\n\t\tthrow new TypeError(\"distill extraction requires upsert: Array<{ key, value }>\");\n\t}\n\tbatch(() => {\n\t\tfor (const { key, value } of extraction.upsert) {\n\t\t\tstore.set(key, value);\n\t\t}\n\t\tfor (const key of extraction.remove ?? []) {\n\t\t\tstore.delete(key);\n\t\t}\n\t});\n}\n\n/**\n * Budget-constrained reactive memory composition.\n */\nexport function distill<TRaw, TMem>(\n\tsource: NodeInput<TRaw>,\n\textractFn: (raw: TRaw, existing: ReadonlyMap<string, TMem>) => NodeInput<Extraction<TMem>>,\n\topts: DistillOptions<TMem>,\n): DistillBundle<TMem> {\n\tconst sourceNode = fromAny(source);\n\tconst store = reactiveMap<string, TMem>(opts.mapOptions ?? {});\n\tconst budget = opts.budget ?? 2000;\n\tconst hasContext = opts.context !== undefined && opts.context !== null;\n\tconst contextNode = hasContext ? fromAny(opts.context) : state<unknown>(null);\n\n\t// Closes P3 audit #7. `latestStore` is seeded at wiring time (§3.6\n\t// boundary read) and kept current via a subscribe handler. `extractFn`\n\t// and `consolidate` read the closure, never `store.entries.cache` from\n\t// inside a reactive callback. `withLatestFrom` would swallow the initial\n\t// source emission because primary's push-on-subscribe fires before\n\t// secondary subscribes — same reason stratify/budgetGate use this pattern.\n\tlet latestStore: ReadonlyMap<string, TMem> = mapFromSnapshot<TMem>(store.entries.cache);\n\tstore.entries.subscribe((msgs) => {\n\t\tfor (const m of msgs) {\n\t\t\tif (m[0] === DATA) latestStore = mapFromSnapshot<TMem>(m[1]);\n\t\t}\n\t});\n\n\tconst extractionStream = switchMap(sourceNode, (raw) => extractFn(raw as TRaw, latestStore));\n\tforEach(extractionStream, (extraction) => {\n\t\tapplyExtraction(store, extraction);\n\t});\n\n\tif (opts.evict) {\n\t\t// Track active verdict-node subscriptions so we can react to Node<boolean> changes.\n\t\tconst verdictUnsubs = new Map<string, () => void>();\n\n\t\tconst evictionKeys = derived([store.entries], ([snapshot]) => {\n\t\t\tconst out: string[] = [];\n\t\t\tconst entries = mapFromSnapshot<TMem>(snapshot);\n\t\t\t// Clean up verdict subscriptions for removed keys.\n\t\t\tfor (const key of verdictUnsubs.keys()) {\n\t\t\t\tif (!entries.has(key)) {\n\t\t\t\t\tverdictUnsubs.get(key)!();\n\t\t\t\t\tverdictUnsubs.delete(key);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const [key, mem] of entries) {\n\t\t\t\tconst verdict = opts.evict!(key, mem);\n\t\t\t\tif (isNodeLike<boolean>(verdict)) {\n\t\t\t\t\t// Subscribe if not already — push-on-subscribe fires with\n\t\t\t\t\t// the verdict's current value on first subscribe, so an\n\t\t\t\t\t// already-true verdict deletes via the callback without\n\t\t\t\t\t// needing a `verdict.cache` read (closes P3 audit #3).\n\t\t\t\t\t// Future transitions to `true` flow through the same path.\n\t\t\t\t\tif (!verdictUnsubs.has(key)) {\n\t\t\t\t\t\tconst unsub = forEach(verdict, (val) => {\n\t\t\t\t\t\t\tif (val === true && store.has(key)) {\n\t\t\t\t\t\t\t\tstore.delete(key);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t\tverdictUnsubs.set(key, unsub);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (typeof verdict === \"boolean\") {\n\t\t\t\t\tif (verdict) out.push(key);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthrow new TypeError(\"distill evict() must return boolean or Node<boolean>\");\n\t\t\t}\n\t\t\treturn out;\n\t\t});\n\t\tforEach(evictionKeys, (keys) => {\n\t\t\tfor (const key of keys) store.delete(key);\n\t\t});\n\t}\n\n\tconst hasConsolidateTrigger =\n\t\topts.consolidateTrigger !== undefined && opts.consolidateTrigger !== null;\n\tif (opts.consolidate && hasConsolidateTrigger) {\n\t\tconst consolidateTriggerNode = fromAny(opts.consolidateTrigger);\n\t\tconst consolidationStream = switchMap(consolidateTriggerNode, () =>\n\t\t\topts.consolidate!(latestStore),\n\t\t);\n\t\tforEach(consolidationStream, (extraction) => {\n\t\t\tapplyExtraction(store, extraction);\n\t\t});\n\t}\n\n\tconst compact = derived([store.entries, contextNode], ([snapshot, context]) => {\n\t\tconst entries = [...mapFromSnapshot<TMem>(snapshot).entries()].map(([key, value]) => ({\n\t\t\tkey,\n\t\t\tvalue,\n\t\t\tscore: opts.score(value, context),\n\t\t\tcost: opts.cost(value),\n\t\t}));\n\t\tentries.sort((a, b) => b.score - a.score);\n\n\t\tconst packed: Array<{ key: string; value: TMem; score: number }> = [];\n\t\tlet remaining = budget;\n\t\tfor (const item of entries) {\n\t\t\tif (item.cost <= remaining) {\n\t\t\t\tpacked.push({ key: item.key, value: item.value, score: item.score });\n\t\t\t\tremaining -= item.cost;\n\t\t\t}\n\t\t}\n\t\treturn packed;\n\t});\n\n\tconst size = derived([store.entries], ([snapshot]) => mapFromSnapshot<TMem>(snapshot).size);\n\tkeepalive(compact);\n\tkeepalive(size);\n\n\treturn { store, compact, size };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAOO,IAAM,YAAY;AAClB,IAAM,aAAa;AAkB1B,SAAS,iBAAiB,OAAuB;AAChD,SAAO,QAAQ,IAAI,IAAI;AACxB;AAEA,SAAS,YAAYA,QAAe,QAA4B;AAC/D,MAAI,WAAW,OAAQ,QAAOA;AAC9B,MAAI,WAAW,OAAQ,QAAO,KAAK,OAAO,IAAIA;AAC9C,SAAOA,SAAQ,IAAI,KAAK,OAAO,KAAKA,SAAQ;AAC7C;AAEA,SAAS,cAAc,KAAa,KAAqB;AACxD,SAAO,MAAM,KAAK,OAAO,KAAK,MAAM;AACrC;AAiBO,SAAS,SAAS,SAAkC;AAC1D,QAAM,OAAO,iBAAiB,OAAO;AACrC,SAAO,MAAM;AACd;AAmBO,SAAS,OAAO,QAAgB,QAAkC;AACxE,QAAM,WAAW,iBAAiB,MAAM;AACxC,QAAM,WAAW,WAAW,SAAY,WAAW,iBAAiB,MAAM;AAC1E,SAAO,CAAC,YAAoB,WAAW,WAAW,KAAK,IAAI,GAAG,OAAO;AACtE;AA+BO,SAAS,YAAY,SAAsD;AACjF,QAAM,SAAS,iBAAiB,SAAS,UAAU,MAAM,SAAS;AAClE,QAAM,SAAS,SAAS,WAAW,UAAa,QAAQ,SAAS,IAAI,IAAK,SAAS,UAAU;AAC7F,QAAM,aAAa,iBAAiB,SAAS,cAAc,KAAK,UAAU;AAC1E,QAAM,SAAS,SAAS,UAAU;AAElC,SAAO,CAAC,YAAoB;AAC3B,QAAIA;AACJ,QAAI,WAAW,GAAG;AACjB,MAAAA,S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__getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
5
+ var __typeError = (msg) => {
6
+ throw TypeError(msg);
7
+ };
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
11
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
12
+ }) : x)(function(x) {
13
+ if (typeof require !== "undefined") return require.apply(this, arguments);
14
+ throw Error('Dynamic require of "' + x + '" is not supported');
15
+ });
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
21
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
22
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
23
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
24
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
25
+ var __runInitializers = (array, flags, self, value) => {
26
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
27
+ return value;
28
+ };
29
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
30
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
31
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
32
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
33
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
34
+ return __privateGet(this, extra);
35
+ }, set [name](x) {
36
+ return __privateSet(this, extra, x);
37
+ } }, name));
38
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
39
+ for (var i = decorators.length - 1; i >= 0; i--) {
40
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
41
+ if (k) {
42
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
43
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
44
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
45
+ }
46
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
47
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
48
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
49
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
50
+ }
51
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
52
+ };
53
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
54
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
55
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
56
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
57
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
58
+
59
+ // src/core/messages.ts
60
+ var START = /* @__PURE__ */ Symbol.for("graphrefly/START");
61
+ var DATA = /* @__PURE__ */ Symbol.for("graphrefly/DATA");
62
+ var DIRTY = /* @__PURE__ */ Symbol.for("graphrefly/DIRTY");
63
+ var RESOLVED = /* @__PURE__ */ Symbol.for("graphrefly/RESOLVED");
64
+ var INVALIDATE = /* @__PURE__ */ Symbol.for("graphrefly/INVALIDATE");
65
+ var PAUSE = /* @__PURE__ */ Symbol.for("graphrefly/PAUSE");
66
+ var RESUME = /* @__PURE__ */ Symbol.for("graphrefly/RESUME");
67
+ var TEARDOWN = /* @__PURE__ */ Symbol.for("graphrefly/TEARDOWN");
68
+ var COMPLETE = /* @__PURE__ */ Symbol.for("graphrefly/COMPLETE");
69
+ var ERROR = /* @__PURE__ */ Symbol.for("graphrefly/ERROR");
70
+ var DIRTY_MSG = Object.freeze([DIRTY]);
71
+ var RESOLVED_MSG = Object.freeze([RESOLVED]);
72
+ var INVALIDATE_MSG = Object.freeze([INVALIDATE]);
73
+ var START_MSG = Object.freeze([START]);
74
+ var COMPLETE_MSG = Object.freeze([COMPLETE]);
75
+ var TEARDOWN_MSG = Object.freeze([TEARDOWN]);
76
+ var DIRTY_ONLY_BATCH = Object.freeze([DIRTY_MSG]);
77
+ var RESOLVED_ONLY_BATCH = Object.freeze([RESOLVED_MSG]);
78
+ var INVALIDATE_ONLY_BATCH = Object.freeze([INVALIDATE_MSG]);
79
+ var COMPLETE_ONLY_BATCH = Object.freeze([COMPLETE_MSG]);
80
+ var TEARDOWN_ONLY_BATCH = Object.freeze([TEARDOWN_MSG]);
81
+
82
+ export {
83
+ __require,
84
+ __export,
85
+ __decoratorStart,
86
+ __runInitializers,
87
+ __decorateElement,
88
+ START,
89
+ DATA,
90
+ DIRTY,
91
+ RESOLVED,
92
+ INVALIDATE,
93
+ PAUSE,
94
+ RESUME,
95
+ TEARDOWN,
96
+ COMPLETE,
97
+ ERROR,
98
+ DIRTY_MSG,
99
+ RESOLVED_MSG,
100
+ INVALIDATE_MSG,
101
+ START_MSG,
102
+ COMPLETE_MSG,
103
+ TEARDOWN_MSG,
104
+ DIRTY_ONLY_BATCH,
105
+ RESOLVED_ONLY_BATCH,
106
+ INVALIDATE_ONLY_BATCH,
107
+ COMPLETE_ONLY_BATCH,
108
+ TEARDOWN_ONLY_BATCH
109
+ };
110
+ //# sourceMappingURL=chunk-SX52TAR4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/messages.ts"],"sourcesContent":["/**\n * GraphReFly message protocol — §1 `~/src/graphrefly/GRAPHREFLY-SPEC.md`.\n * Emissions are always `[[Type, Data?], ...]` (no single-tuple shorthand).\n *\n * This file is protocol-pure:\n * - Message type symbols (10 built-ins).\n * - `Message` / `Messages` tuple types.\n * - `MessageTypeRegistration` interface (shape of a registry entry).\n *\n * It does NOT own the registry, tier lookups, or any cross-cutting singleton\n * state — that lives in `GraphReFlyConfig` (see `config.ts`) so custom\n * protocols can build isolated instances. Import this module when you need\n * the symbol constants or the tuple types; import `config.ts` when you need\n * tier / wire-crossing / registry lookups.\n */\n\n/** Subscribe-time handshake. Delivered to each new sink at the top of `subscribe()`. Tier 0. */\nexport const START = Symbol.for(\"graphrefly/START\");\n/** Value delivery (`DATA`, value). Tier 3 — deferred inside `batch()`. */\nexport const DATA = Symbol.for(\"graphrefly/DATA\");\n/** Phase 1: value about to change. Tier 1 — immediate. */\nexport const DIRTY = Symbol.for(\"graphrefly/DIRTY\");\n/** Phase 2: dirty pass completed, value unchanged. Tier 3 — deferred inside `batch()`. */\nexport const RESOLVED = Symbol.for(\"graphrefly/RESOLVED\");\n/** Clear cached state; do not auto-emit. Tier 1 — immediate. */\nexport const INVALIDATE = Symbol.for(\"graphrefly/INVALIDATE\");\n/** Suspend activity. Tier 2 — immediate. */\nexport const PAUSE = Symbol.for(\"graphrefly/PAUSE\");\n/** Resume after pause. Tier 2 — immediate. */\nexport const RESUME = Symbol.for(\"graphrefly/RESUME\");\n/** Permanent cleanup. Tier 5 — deferred to batch phase 4. */\nexport const TEARDOWN = Symbol.for(\"graphrefly/TEARDOWN\");\n/** Clean termination. Tier 4 — deferred to batch phase 3. */\nexport const COMPLETE = Symbol.for(\"graphrefly/COMPLETE\");\n/** Error termination. Tier 4 — deferred to batch phase 3. */\nexport const ERROR = Symbol.for(\"graphrefly/ERROR\");\n\n/** One protocol tuple: `[Type, optional payload]`. */\nexport type Message = readonly [symbol, unknown?];\n\n/** A batch of tuples — the wire shape for `node.down()` / `node.up()`. */\nexport type Messages = readonly Message[];\n\n// ---------------------------------------------------------------------------\n// Interned singletons for payload-free tuples\n// ---------------------------------------------------------------------------\n//\n// Every emission path used to allocate fresh `[[DIRTY]]`, `[[RESOLVED]]`,\n// etc. — two arrays per emit in the hot path. Since none of these tuples\n// carry a payload, one frozen instance is indistinguishable from a\n// fresh one. We intern them at module load and reuse forever. Only\n// `[DATA, v]`, `[ERROR, e]`, `[PAUSE, lockId]`, `[RESUME, lockId]` still\n// allocate per-call because they carry payloads.\n//\n// Downstream code MUST treat these as immutable. `Object.freeze` makes\n// accidental mutation throw in strict mode. Do not `push`, splice, or\n// otherwise mutate a Messages array that came from one of these.\n\n/** Singleton `[DIRTY]` tuple — payload-free, interned. */\nexport const DIRTY_MSG: Message = Object.freeze([DIRTY]) as Message;\n/** Singleton `[RESOLVED]` tuple — payload-free, interned. */\nexport const RESOLVED_MSG: Message = Object.freeze([RESOLVED]) as Message;\n/** Singleton `[INVALIDATE]` tuple — payload-free, interned. */\nexport const INVALIDATE_MSG: Message = Object.freeze([INVALIDATE]) as Message;\n/** Singleton `[START]` tuple — payload-free, interned. */\nexport const START_MSG: Message = Object.freeze([START]) as Message;\n/** Singleton `[COMPLETE]` tuple — payload-free, interned. */\nexport const COMPLETE_MSG: Message = Object.freeze([COMPLETE]) as Message;\n/** Singleton `[TEARDOWN]` tuple — payload-free, interned. */\nexport const TEARDOWN_MSG: Message = Object.freeze([TEARDOWN]) as Message;\n\n/** Pre-wrapped `[[DIRTY]]` for `_emit([DIRTY_ONLY_BATCH])`-style callers. */\nexport const DIRTY_ONLY_BATCH: Messages = Object.freeze([DIRTY_MSG]) as Messages;\n/** Pre-wrapped `[[RESOLVED]]`. */\nexport const RESOLVED_ONLY_BATCH: Messages = Object.freeze([RESOLVED_MSG]) as Messages;\n/** Pre-wrapped `[[INVALIDATE]]`. */\nexport const INVALIDATE_ONLY_BATCH: Messages = Object.freeze([INVALIDATE_MSG]) as Messages;\n/** Pre-wrapped `[[COMPLETE]]`. */\nexport const COMPLETE_ONLY_BATCH: Messages = Object.freeze([COMPLETE_MSG]) as Messages;\n/** Pre-wrapped `[[TEARDOWN]]`. */\nexport const TEARDOWN_ONLY_BATCH: Messages = Object.freeze([TEARDOWN_MSG]) as Messages;\n\n// ---------------------------------------------------------------------------\n// Registry entry shape\n// ---------------------------------------------------------------------------\n\n/**\n * Per-type record stored in a {@link GraphReFlyConfig}'s registry.\n *\n * - `tier` — signal tier (0–5 built-in; custom tiers allowed but should fit\n * the phase model used by `batch.ts`).\n * - `wireCrossing` — when `true`, forwarded across SSE/WebSocket/worker\n * adapters. Defaults to `tier >= 3` if omitted in registration input.\n * - `metaPassthrough` — when `false`, this message type is filtered out of\n * `Graph.signal` deliveries to meta companion nodes (spec §2.3). Meta\n * companions still receive everything via their primary's own cascade.\n * Defaults to `true` (meta receives the message).\n */\nexport interface MessageTypeRegistration {\n\ttier: number;\n\twireCrossing: boolean;\n\tmetaPassthrough: boolean;\n}\n\n/**\n * Input accepted by {@link GraphReFlyConfig.registerMessageType}. Only `tier`\n * is required; `wireCrossing` defaults to `tier >= 3`; `metaPassthrough`\n * defaults to `true`.\n */\nexport interface MessageTypeRegistrationInput {\n\ttier: number;\n\twireCrossing?: boolean;\n\tmetaPassth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function resolveDescribeFields(detail, fields) {
@@ -95,4 +95,4 @@ export {
95
95
  resolveDescribeFields,
96
96
  describeNode
97
97
  };
98
- //# sourceMappingURL=chunk-H4RVA4VE.js.map
98
+ //# sourceMappingURL=chunk-VYPWMZ6H.js.map
@@ -0,0 +1,171 @@
1
+ import {
2
+ vue_exports
3
+ } from "./chunk-MJ2NKQQL.js";
4
+ import {
5
+ zustand_exports
6
+ } from "./chunk-APFNLIRG.js";
7
+ import {
8
+ jotai_exports
9
+ } from "./chunk-XGPU467M.js";
10
+ import {
11
+ nanostores_exports
12
+ } from "./chunk-N6UR7YVY.js";
13
+ import {
14
+ nestjs_exports
15
+ } from "./chunk-DST5DKZS.js";
16
+ import {
17
+ react_exports
18
+ } from "./chunk-J22W6HV3.js";
19
+ import {
20
+ solid_exports
21
+ } from "./chunk-HXZEYDUR.js";
22
+ import {
23
+ svelte_exports
24
+ } from "./chunk-OHISZPOJ.js";
25
+ import {
26
+ autoTrackNode,
27
+ batch,
28
+ state
29
+ } from "./chunk-PHOUUNK7.js";
30
+ import {
31
+ COMPLETE,
32
+ DATA,
33
+ DIRTY,
34
+ ERROR,
35
+ __export
36
+ } from "./chunk-SX52TAR4.js";
37
+
38
+ // src/compat/index.ts
39
+ var compat_exports = {};
40
+ __export(compat_exports, {
41
+ jotai: () => jotai_exports,
42
+ nanostores: () => nanostores_exports,
43
+ nestjs: () => nestjs_exports,
44
+ react: () => react_exports,
45
+ signals: () => signals_exports,
46
+ solid: () => solid_exports,
47
+ svelte: () => svelte_exports,
48
+ vue: () => vue_exports,
49
+ zustand: () => zustand_exports
50
+ });
51
+
52
+ // src/compat/signals/index.ts
53
+ var signals_exports = {};
54
+ __export(signals_exports, {
55
+ Signal: () => Signal
56
+ });
57
+ var trackingStack = [];
58
+ function pull(n) {
59
+ let val = n.cache;
60
+ const unsub = n.subscribe((msgs) => {
61
+ for (const [t, v] of msgs) {
62
+ if (t === DATA) val = v;
63
+ }
64
+ });
65
+ unsub();
66
+ return val;
67
+ }
68
+ var SignalState = class {
69
+ /** @internal */
70
+ _node;
71
+ _equals;
72
+ constructor(initial, opts) {
73
+ this._equals = opts?.equals ?? Object.is;
74
+ this._node = state(initial, {
75
+ ...opts,
76
+ resubscribable: true,
77
+ resetOnTeardown: true
78
+ });
79
+ }
80
+ get() {
81
+ const tracker = trackingStack[trackingStack.length - 1];
82
+ if (tracker) {
83
+ if (this._node.status === "sentinel") {
84
+ pull(this._node);
85
+ }
86
+ return tracker(this._node);
87
+ }
88
+ if (this._node.status === "sentinel") {
89
+ return pull(this._node);
90
+ }
91
+ return this._node.cache;
92
+ }
93
+ set(value) {
94
+ if (this._equals(this.get(), value)) return;
95
+ batch(() => {
96
+ this._node.down([[DIRTY], [DATA, value]]);
97
+ });
98
+ }
99
+ };
100
+ var SignalComputed = class {
101
+ /** @internal */
102
+ _node;
103
+ constructor(computation, opts) {
104
+ this._node = autoTrackNode(
105
+ (track) => {
106
+ trackingStack.push(track);
107
+ try {
108
+ return computation();
109
+ } finally {
110
+ trackingStack.pop();
111
+ }
112
+ },
113
+ {
114
+ ...opts,
115
+ describeKind: "derived",
116
+ resubscribable: true,
117
+ resetOnTeardown: true
118
+ }
119
+ );
120
+ }
121
+ get() {
122
+ const tracker = trackingStack[trackingStack.length - 1];
123
+ if (tracker) {
124
+ if (this._node.status === "sentinel") {
125
+ pull(this._node);
126
+ }
127
+ return tracker(this._node);
128
+ }
129
+ if (this._node.status === "sentinel") {
130
+ return pull(this._node);
131
+ }
132
+ return this._node.cache;
133
+ }
134
+ };
135
+ var Signal = {
136
+ State: SignalState,
137
+ Computed: SignalComputed,
138
+ /**
139
+ * Subscribes to changes on a signal.
140
+ * Returns an unsubscribe callback.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * const count = new Signal.State(0);
145
+ * const unsub = Signal.sub(count, v => console.log(v));
146
+ * ```
147
+ */
148
+ sub: (signal, callback) => {
149
+ const handlers = typeof callback === "function" ? { data: callback, error: void 0, complete: void 0 } : callback;
150
+ let initial = true;
151
+ return signal._node.subscribe((msgs) => {
152
+ for (const [t, v] of msgs) {
153
+ if (t === DATA) {
154
+ if (initial) {
155
+ initial = false;
156
+ continue;
157
+ }
158
+ handlers.data?.(v);
159
+ }
160
+ if (t === ERROR) handlers.error?.(v);
161
+ if (t === COMPLETE) handlers.complete?.();
162
+ }
163
+ });
164
+ }
165
+ };
166
+
167
+ export {
168
+ signals_exports,
169
+ compat_exports
170
+ };
171
+ //# sourceMappingURL=chunk-WBZOVTYK.js.map