@graphrefly/graphrefly 0.30.0 → 0.32.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 (253) hide show
  1. package/dist/{cascading-dNCtjW8j.d.cts → cascading-BfQmSmjU.d.cts} +21 -2
  2. package/dist/{cascading-BszPheHD.d.ts → cascading-D3sapjue.d.ts} +21 -2
  3. package/dist/chunk-2JNT5NDF.js +61 -0
  4. package/dist/{chunk-DDPYNMGG.js → chunk-2RH4QNDQ.js} +1 -1
  5. package/dist/chunk-4JBKKUCJ.js +7 -0
  6. package/dist/{chunk-SLMYTGTU.js → chunk-4UUDNFYG.js} +1 -1
  7. package/dist/chunk-4VXL3UZK.js +1 -0
  8. package/dist/{chunk-SHYH5SXV.js → chunk-4YGJ7KZ6.js} +1 -1
  9. package/dist/{chunk-GJR3P6JG.js → chunk-5PBXUVHI.js} +1 -1
  10. package/dist/{chunk-W4TSQ6RJ.js → chunk-7AJKUA36.js} +1 -1
  11. package/dist/{chunk-XQAXYVXX.js → chunk-7EMUF2RY.js} +1 -1
  12. package/dist/chunk-7JZ3YORY.js +80 -0
  13. package/dist/chunk-7QMVU3IX.js +1 -0
  14. package/dist/{chunk-WANIEEKV.js → chunk-7QS77X6G.js} +1 -1
  15. package/dist/{chunk-BA5URFYW.js → chunk-A4JT4SAD.js} +1 -1
  16. package/dist/{chunk-Y36UZ5VS.js → chunk-BU4SUZSA.js} +1 -1
  17. package/dist/{chunk-P7JXGKDO.js → chunk-CNXUW2CU.js} +1 -1
  18. package/dist/{chunk-Y32RJO24.js → chunk-CZVYLXFK.js} +1 -1
  19. package/dist/{chunk-567NWZ3T.js → chunk-DWIAG62L.js} +1 -1
  20. package/dist/chunk-EIFHFDFD.js +1 -0
  21. package/dist/chunk-FTA5TB2A.js +1 -0
  22. package/dist/{chunk-T5SHIKJD.js → chunk-JAHAJU4G.js} +1 -1
  23. package/dist/{chunk-AV3PIDFQ.js → chunk-JYMNVEH6.js} +1 -1
  24. package/dist/{chunk-5Z4HDCO6.js → chunk-K54OKWNY.js} +1 -1
  25. package/dist/chunk-KD3IYBTD.js +3 -0
  26. package/dist/{chunk-3NEPQO2E.js → chunk-LG73TUF4.js} +2 -2
  27. package/dist/chunk-LJGPOJHS.js +1 -0
  28. package/dist/chunk-LWGLBCMU.js +1 -0
  29. package/dist/{chunk-BKPLTBL5.js → chunk-M2VFLRPJ.js} +1 -1
  30. package/dist/{chunk-GNCBXARM.js → chunk-MFNOZ5E6.js} +1 -1
  31. package/dist/{chunk-TWMEGG45.js → chunk-N2KKISCE.js} +1 -1
  32. package/dist/chunk-PNTBXOQ6.js +5 -0
  33. package/dist/{chunk-73Z3W2RN.js → chunk-PWKLZ2XU.js} +1 -1
  34. package/dist/{chunk-7TDOES3L.js → chunk-Q2SY7M7K.js} +1 -1
  35. package/dist/{chunk-OL33ZI6R.js → chunk-RWGJQQLT.js} +1 -1
  36. package/dist/chunk-SGS4OJGS.js +1 -0
  37. package/dist/{chunk-4OFIQ66T.js → chunk-TOCCHQI6.js} +1 -1
  38. package/dist/chunk-UMH3HSP7.js +1 -0
  39. package/dist/{chunk-XHVB6G6M.js → chunk-UXEB35L4.js} +1 -1
  40. package/dist/{chunk-33FA6V4B.js → chunk-VXJX3ZZP.js} +1 -1
  41. package/dist/{chunk-BZP5T4X6.js → chunk-W6FQIFVE.js} +1 -1
  42. package/dist/{chunk-RD52SNH2.js → chunk-WE32AFFA.js} +1 -1
  43. package/dist/{chunk-KA6MMXIY.js → chunk-WF3V5X2L.js} +1 -1
  44. package/dist/chunk-WQ7I7JVU.js +1 -0
  45. package/dist/{chunk-4JJCCD5S.js → chunk-X4OOM6QU.js} +1 -1
  46. package/dist/{chunk-AUY2YKCO.js → chunk-XRSHMHEG.js} +1 -1
  47. package/dist/chunk-Y26UN6J5.js +18 -0
  48. package/dist/{chunk-VWPRPPKR.js → chunk-ZWETYYQG.js} +1 -1
  49. package/dist/compat/index.cjs +2 -2
  50. package/dist/compat/index.d.cts +5 -5
  51. package/dist/compat/index.d.ts +5 -5
  52. package/dist/compat/index.js +1 -1
  53. package/dist/compat/jotai/index.cjs +1 -1
  54. package/dist/compat/jotai/index.js +1 -1
  55. package/dist/compat/nanostores/index.cjs +1 -1
  56. package/dist/compat/nanostores/index.js +1 -1
  57. package/dist/compat/nestjs/index.cjs +5 -5
  58. package/dist/compat/nestjs/index.d.cts +3 -3
  59. package/dist/compat/nestjs/index.d.ts +3 -3
  60. package/dist/compat/nestjs/index.js +1 -1
  61. package/dist/compat/zustand/index.cjs +2 -2
  62. package/dist/compat/zustand/index.d.cts +2 -2
  63. package/dist/compat/zustand/index.d.ts +2 -2
  64. package/dist/compat/zustand/index.js +1 -1
  65. package/dist/{composite-DGspwCqk.d.ts → composite-BY9hMxN7.d.ts} +1 -1
  66. package/dist/{composite-nrRumJ7l.d.cts → composite-CH0S8DFn.d.cts} +1 -1
  67. package/dist/content-addressed-storage-BUiREIuj.d.ts +124 -0
  68. package/dist/content-addressed-storage-DqIWCmZG.d.cts +124 -0
  69. package/dist/core/index.cjs +1 -1
  70. package/dist/core/index.js +1 -1
  71. package/dist/extra/browser.cjs +1 -1
  72. package/dist/extra/browser.js +1 -1
  73. package/dist/extra/index.cjs +18 -18
  74. package/dist/extra/index.d.cts +7 -6
  75. package/dist/extra/index.d.ts +7 -6
  76. package/dist/extra/index.js +1 -1
  77. package/dist/extra/node.cjs +2 -2
  78. package/dist/extra/node.js +1 -1
  79. package/dist/extra/operators.cjs +1 -1
  80. package/dist/extra/operators.d.cts +41 -1
  81. package/dist/extra/operators.d.ts +41 -1
  82. package/dist/extra/operators.js +1 -1
  83. package/dist/extra/reactive.cjs +1 -1
  84. package/dist/extra/reactive.d.cts +1 -1
  85. package/dist/extra/reactive.d.ts +1 -1
  86. package/dist/extra/reactive.js +1 -1
  87. package/dist/extra/sources.cjs +1 -1
  88. package/dist/extra/sources.d.cts +62 -2
  89. package/dist/extra/sources.d.ts +62 -2
  90. package/dist/extra/sources.js +1 -1
  91. package/dist/extra/storage-browser.cjs +1 -1
  92. package/dist/extra/storage-browser.js +1 -1
  93. package/dist/{fallback-BaTS7vVY.d.cts → fallback-Cb3GH1O7.d.cts} +6 -14
  94. package/dist/{fallback-eOm3LNxP.d.ts → fallback-DRjJ_ZM8.d.ts} +6 -14
  95. package/dist/graph/index.cjs +4 -4
  96. package/dist/graph/index.d.cts +3 -3
  97. package/dist/graph/index.d.ts +3 -3
  98. package/dist/graph/index.js +1 -1
  99. package/dist/{graph-CWeI0aHd.d.ts → graph-BOhEGJ6E.d.ts} +10 -0
  100. package/dist/{graph-C4Uxwv0T.d.cts → graph-CdJeX7O7.d.cts} +10 -0
  101. package/dist/{index-B-z8WaSd.d.cts → index-BDLy6CQ9.d.cts} +1 -1
  102. package/dist/{index-iBp74eGU.d.cts → index-BJDXj9Wf.d.cts} +2 -2
  103. package/dist/{index-BBINVimG.d.ts → index-BUZPTPSQ.d.ts} +2 -2
  104. package/dist/{index-DnrZghBB.d.ts → index-BbcSZCAG.d.ts} +1 -1
  105. package/dist/{index-lKuLYmHO.d.cts → index-BiGeETJs.d.cts} +1 -1
  106. package/dist/{index-BHu_Wba0.d.cts → index-BmZb8fNF.d.cts} +3 -3
  107. package/dist/{index-Docdiu9a.d.ts → index-Bnmttu35.d.ts} +1 -1
  108. package/dist/{index-D6ajK8Mh.d.cts → index-BuN2wGJs.d.cts} +517 -134
  109. package/dist/{index-Cy7eFeIX.d.cts → index-BwdPDWI4.d.cts} +1 -1
  110. package/dist/{index-DylQCKEL.d.cts → index-BzxU4yhV.d.cts} +11 -2
  111. package/dist/{index-D9Y_u6BG.d.cts → index-C-Gsh-0a.d.cts} +2 -2
  112. package/dist/{index-ybtSyjWB.d.cts → index-C22aTC1X.d.cts} +5 -5
  113. package/dist/{index-yIdWFo2b.d.cts → index-C4QTaDli.d.cts} +2 -2
  114. package/dist/{index-BJHQUCZx.d.ts → index-C7RqYbOZ.d.ts} +82 -7
  115. package/dist/{index-C5Ghnp5B.d.ts → index-C9qCLIN4.d.ts} +2 -2
  116. package/dist/{index-DVNLe3pS.d.cts → index-CCdg0JLX.d.cts} +1 -1
  117. package/dist/{index-B5iVOD7w.d.ts → index-CEoU-r-g.d.ts} +2 -2
  118. package/dist/{index-CfFYyLR8.d.ts → index-CHfBm51k.d.ts} +11 -2
  119. package/dist/{index-Dljd76bC.d.ts → index-CNyiYQWF.d.ts} +5 -5
  120. package/dist/{index-C6NBfXj-.d.ts → index-CVevMZ0n.d.ts} +2 -2
  121. package/dist/{index-DGb1awva.d.ts → index-CZUzi6Dy.d.ts} +2 -2
  122. package/dist/{index-FrYrV-Vf.d.ts → index-Ckl03Q0s.d.ts} +1 -1
  123. package/dist/{index-Bvi5uJxX.d.ts → index-CmSjld-4.d.ts} +1 -1
  124. package/dist/{index-9iguV3bF.d.cts → index-CnjUhRbs.d.cts} +2 -2
  125. package/dist/{index-C98oJsEs.d.cts → index-D3HcdZ4d.d.cts} +1 -1
  126. package/dist/{index-IZ3l_vQ9.d.ts → index-DD1czHj3.d.ts} +1 -1
  127. package/dist/{index-BS220yqj.d.cts → index-DNhTQReY.d.cts} +82 -7
  128. package/dist/{index-UZO988ox.d.cts → index-DSawGt8n.d.cts} +2 -2
  129. package/dist/{index-CcpEvuPl.d.cts → index-DUkuH3jP.d.cts} +1 -1
  130. package/dist/{index-CRAkoq-y.d.cts → index-DY2QbdoP.d.cts} +1 -1
  131. package/dist/{index-CvS9IuTG.d.ts → index-Dbmj0iYR.d.ts} +1 -1
  132. package/dist/{index-ClgKmOHe.d.ts → index-DhlAMlm9.d.ts} +517 -134
  133. package/dist/{index-ClB7TCfL.d.cts → index-DlGaEBW5.d.cts} +2 -2
  134. package/dist/{index-CotRMjtJ.d.ts → index-Dp_pS7Bw.d.ts} +1 -1
  135. package/dist/{index-Cc8VQIgL.d.ts → index-Dxk-pUQI.d.ts} +2 -2
  136. package/dist/{index-DBQUKh59.d.cts → index-EGjF6iSY.d.cts} +3 -3
  137. package/dist/{index-D9HrBx2J.d.ts → index-LGzAYqdR.d.ts} +1 -1
  138. package/dist/{index-DR3gf_DG.d.cts → index-LzCJ0kMT.d.cts} +2 -2
  139. package/dist/{index-RQg6lTrN.d.ts → index-MV2yGIAq.d.ts} +2 -2
  140. package/dist/{index-Bs3-LC83.d.cts → index-_BXz9K7b.d.cts} +1 -1
  141. package/dist/{index-SSGqF8mI.d.cts → index-aBqZUx3B.d.cts} +1 -1
  142. package/dist/{index-CFW32Dy1.d.ts → index-eYHRkoK-.d.ts} +1 -1
  143. package/dist/{index-B2HBxvMb.d.ts → index-gXTVbSax.d.ts} +3 -3
  144. package/dist/{index-B8Aj_z8S.d.cts → index-j33Lfb1G.d.cts} +23 -2
  145. package/dist/{index-BEpRsvhg.d.ts → index-lpGUhTBn.d.ts} +3 -3
  146. package/dist/{index-BXbQUn4n.d.ts → index-zMQIQuDu.d.ts} +23 -2
  147. package/dist/index.cjs +106 -125
  148. package/dist/index.d.cts +34 -33
  149. package/dist/index.d.ts +34 -33
  150. package/dist/index.js +1 -1
  151. package/dist/patterns/ai/browser.cjs +5 -22
  152. package/dist/patterns/ai/browser.d.cts +3 -3
  153. package/dist/patterns/ai/browser.d.ts +3 -3
  154. package/dist/patterns/ai/browser.js +1 -1
  155. package/dist/patterns/ai/index.cjs +30 -44
  156. package/dist/patterns/ai/index.d.cts +13 -11
  157. package/dist/patterns/ai/index.d.ts +13 -11
  158. package/dist/patterns/ai/index.js +1 -1
  159. package/dist/patterns/ai/node.cjs +2 -2
  160. package/dist/patterns/ai/node.d.cts +5 -4
  161. package/dist/patterns/ai/node.d.ts +5 -4
  162. package/dist/patterns/ai/node.js +1 -1
  163. package/dist/patterns/audit/index.cjs +3 -3
  164. package/dist/patterns/audit/index.d.cts +3 -3
  165. package/dist/patterns/audit/index.d.ts +3 -3
  166. package/dist/patterns/audit/index.js +1 -1
  167. package/dist/patterns/cqrs/index.cjs +6 -6
  168. package/dist/patterns/cqrs/index.d.cts +2 -2
  169. package/dist/patterns/cqrs/index.d.ts +2 -2
  170. package/dist/patterns/cqrs/index.js +1 -1
  171. package/dist/patterns/demo-shell/index.cjs +2 -2
  172. package/dist/patterns/demo-shell/index.d.cts +3 -3
  173. package/dist/patterns/demo-shell/index.d.ts +3 -3
  174. package/dist/patterns/demo-shell/index.js +1 -1
  175. package/dist/patterns/domain-templates/index.cjs +6 -6
  176. package/dist/patterns/domain-templates/index.d.cts +2 -2
  177. package/dist/patterns/domain-templates/index.d.ts +2 -2
  178. package/dist/patterns/domain-templates/index.js +1 -1
  179. package/dist/patterns/graphspec/index.cjs +27 -25
  180. package/dist/patterns/graphspec/index.d.cts +3 -3
  181. package/dist/patterns/graphspec/index.d.ts +3 -3
  182. package/dist/patterns/graphspec/index.js +1 -1
  183. package/dist/patterns/guarded-execution/index.cjs +7 -7
  184. package/dist/patterns/guarded-execution/index.d.cts +4 -4
  185. package/dist/patterns/guarded-execution/index.d.ts +4 -4
  186. package/dist/patterns/guarded-execution/index.js +1 -1
  187. package/dist/patterns/harness/index.cjs +12 -11
  188. package/dist/patterns/harness/index.d.cts +6 -6
  189. package/dist/patterns/harness/index.d.ts +6 -6
  190. package/dist/patterns/harness/index.js +1 -1
  191. package/dist/patterns/job-queue/index.cjs +5 -5
  192. package/dist/patterns/job-queue/index.d.cts +2 -2
  193. package/dist/patterns/job-queue/index.d.ts +2 -2
  194. package/dist/patterns/job-queue/index.js +1 -1
  195. package/dist/patterns/lens/index.cjs +5 -5
  196. package/dist/patterns/lens/index.d.cts +4 -4
  197. package/dist/patterns/lens/index.d.ts +4 -4
  198. package/dist/patterns/lens/index.js +1 -1
  199. package/dist/patterns/memory/index.cjs +4 -4
  200. package/dist/patterns/memory/index.d.cts +2 -2
  201. package/dist/patterns/memory/index.d.ts +2 -2
  202. package/dist/patterns/memory/index.js +1 -1
  203. package/dist/patterns/messaging/index.cjs +5 -5
  204. package/dist/patterns/messaging/index.d.cts +2 -2
  205. package/dist/patterns/messaging/index.d.ts +2 -2
  206. package/dist/patterns/messaging/index.js +1 -1
  207. package/dist/patterns/orchestration/index.cjs +7 -7
  208. package/dist/patterns/orchestration/index.d.cts +2 -2
  209. package/dist/patterns/orchestration/index.d.ts +2 -2
  210. package/dist/patterns/orchestration/index.js +1 -1
  211. package/dist/patterns/reactive-layout/index.cjs +2 -2
  212. package/dist/patterns/reactive-layout/index.d.cts +3 -3
  213. package/dist/patterns/reactive-layout/index.d.ts +3 -3
  214. package/dist/patterns/reactive-layout/index.js +1 -1
  215. package/dist/patterns/reduction/index.cjs +5 -5
  216. package/dist/patterns/reduction/index.d.cts +2 -2
  217. package/dist/patterns/reduction/index.d.ts +2 -2
  218. package/dist/patterns/reduction/index.js +1 -1
  219. package/dist/patterns/refine-loop/index.cjs +8 -8
  220. package/dist/patterns/refine-loop/index.d.cts +3 -3
  221. package/dist/patterns/refine-loop/index.d.ts +3 -3
  222. package/dist/patterns/refine-loop/index.js +1 -1
  223. package/dist/patterns/resilient-pipeline/index.cjs +1 -1
  224. package/dist/patterns/resilient-pipeline/index.d.cts +3 -3
  225. package/dist/patterns/resilient-pipeline/index.d.ts +3 -3
  226. package/dist/patterns/resilient-pipeline/index.js +1 -1
  227. package/dist/patterns/surface/index.cjs +15 -13
  228. package/dist/patterns/surface/index.d.cts +4 -4
  229. package/dist/patterns/surface/index.d.ts +4 -4
  230. package/dist/patterns/surface/index.js +1 -1
  231. package/dist/{reactive-layout-BAr6-_o5.d.ts → reactive-layout-Bq0rA2Wb.d.ts} +1 -1
  232. package/dist/{reactive-layout-5oEn8lHM.d.cts → reactive-layout-Dhhe54Oj.d.cts} +1 -1
  233. package/dist/{reactive-map-BvDrRuwt.d.ts → reactive-map-CtRaCddO.d.ts} +59 -1
  234. package/dist/{reactive-map-CmlPPKHN.d.cts → reactive-map-IJIfZxoh.d.cts} +59 -1
  235. package/dist/{resilience-XRUF267O.js → resilience-IVNDYORD.js} +1 -1
  236. package/dist/{topology-tree-CVREibAc.d.cts → topology-tree-CpSjvIXp.d.cts} +1 -1
  237. package/dist/{topology-tree-CkjojcB6.d.ts → topology-tree-DAbCV2Yw.d.ts} +1 -1
  238. package/dist/{types-O3GzJY2U.d.cts → types-BgMqbc7N.d.cts} +41 -14
  239. package/dist/{types-u64Ose53.d.ts → types-CdfO2QTt.d.ts} +41 -14
  240. package/package.json +1 -1
  241. package/dist/chunk-2GQREQ6C.js +0 -1
  242. package/dist/chunk-4C2OR2GH.js +0 -18
  243. package/dist/chunk-5JDE5JHE.js +0 -1
  244. package/dist/chunk-7JDLFI6N.js +0 -1
  245. package/dist/chunk-AMBYCIOH.js +0 -3
  246. package/dist/chunk-GLSM33ZM.js +0 -78
  247. package/dist/chunk-ISCENNXS.js +0 -1
  248. package/dist/chunk-IUK4EFCE.js +0 -1
  249. package/dist/chunk-KASHOCF5.js +0 -1
  250. package/dist/chunk-LI3E75VE.js +0 -64
  251. package/dist/chunk-MGKAO4EK.js +0 -7
  252. package/dist/chunk-NSG4C6BF.js +0 -23
  253. package/dist/chunk-VIEUJSTT.js +0 -1
@@ -0,0 +1,124 @@
1
+ import { StorageTier } from './extra/storage-core.cjs';
2
+
3
+ /**
4
+ * Content-addressed storage substrate — a generic lookup / store helper over
5
+ * any {@link StorageTier}. Hashes an arbitrary context object via
6
+ * {@link canonicalJson} + sha256 to produce a stable key, then reads or writes
7
+ * the record from the underlying tier.
8
+ *
9
+ * Substrate shared by LLM adapters (`withReplayCache`, `fallbackAdapter`) —
10
+ * the LLM-specific shape (key prefix, `ChatMessage` + `LLMInvokeOptions`
11
+ * context) lives in a thin wrapper inside `patterns/ai/adapters/_internal/`.
12
+ * Any consumer that wants "memoize by content hash over a pluggable tier"
13
+ * (tool result caches, embedding caches, deterministic function memoization,
14
+ * fixtures for replay tests) can use this primitive directly.
15
+ *
16
+ * Universal tier — browser + Node safe. `sha256Hex` is pulled from
17
+ * `core/hash.ts` (Web Crypto), `canonicalJson` is a pure function in this
18
+ * module.
19
+ *
20
+ * @module
21
+ */
22
+
23
+ /**
24
+ * Read / write / read-write / read-strict.
25
+ *
26
+ * - `"read"` — lookups hit storage; misses fall through to the caller.
27
+ * - `"write"` — store only; lookups always return `undefined`.
28
+ * - `"read-write"` — lookups hit storage, misses are writable by the caller.
29
+ * - `"read-strict"` — lookups hit storage, misses throw (no fallthrough).
30
+ * Used by fixture-based replay flows where a missing fixture is a test bug.
31
+ *
32
+ * @category extra
33
+ */
34
+ type ContentAddressedMode = "read" | "write" | "read-write" | "read-strict";
35
+ /** Error thrown when `read-strict` mode misses. */
36
+ declare class ContentAddressedMissError extends Error {
37
+ readonly key: string;
38
+ readonly context: unknown;
39
+ constructor(key: string, context: unknown);
40
+ }
41
+ /**
42
+ * Options for {@link contentAddressedStorage}.
43
+ *
44
+ * @category extra
45
+ */
46
+ type ContentAddressedStorageOptions<Ctx> = {
47
+ /** Underlying storage tier (any `StorageTier` — memory, file, indexed-db). */
48
+ storage: StorageTier;
49
+ /**
50
+ * Derive the hashable context from `ctx`. Defaults to `ctx` itself.
51
+ * Use when the caller's `ctx` carries fields that should NOT participate in
52
+ * the key (e.g. an `AbortSignal`, a retry count).
53
+ */
54
+ keyContext?: (ctx: Ctx) => unknown;
55
+ /**
56
+ * Optional key prefix — applied as `${prefix}:${hex}` so multiple consumers
57
+ * can share one storage tier without collisions.
58
+ */
59
+ keyPrefix?: string;
60
+ /** Mode — see {@link ContentAddressedMode}. Default `"read-write"`. */
61
+ mode?: ContentAddressedMode;
62
+ };
63
+ /**
64
+ * Handle returned by {@link contentAddressedStorage}.
65
+ *
66
+ * @category extra
67
+ */
68
+ type ContentAddressedStorage<Ctx, V> = {
69
+ /**
70
+ * Compute the content-addressed key for `ctx` — useful when a caller needs
71
+ * to thread the same key through a singleflight / dedup stage without
72
+ * re-hashing.
73
+ */
74
+ keyFor(ctx: Ctx): Promise<string>;
75
+ /**
76
+ * Look up a value by hashing `ctx`. In `read-strict` mode, throws
77
+ * {@link ContentAddressedMissError} on miss.
78
+ */
79
+ lookup(ctx: Ctx): Promise<V | undefined>;
80
+ /** Store `value` under the hash of `ctx`. No-op in `"read"` mode. */
81
+ store(ctx: Ctx, value: V): Promise<void>;
82
+ /** Clear the entry for `ctx`. No-op in `"read"` or `"write"` mode, or when the tier lacks `clear()`. */
83
+ forget(ctx: Ctx): Promise<void>;
84
+ };
85
+ /**
86
+ * Canonical JSON — sorts object keys for stable sha256 while detecting true
87
+ * cycles (not sibling shared refs).
88
+ *
89
+ * We recurse manually with a **path stack** (`seen` contains only the current
90
+ * ancestor chain, not every previously-visited object). On enter we push; on
91
+ * exit we pop. Back-edges to ancestors serialize as `{"__cycle": true}`;
92
+ * siblings that share the same reference serialize normally, producing
93
+ * identical hashes to a freshly-reconstructed equivalent.
94
+ *
95
+ * @category extra
96
+ */
97
+ declare function canonicalJson(value: unknown): string;
98
+ /**
99
+ * Creates a content-addressed lookup / store handle over `storage`. The key
100
+ * is `sha256Hex(canonicalJson(keyContext(ctx)))`, optionally prefixed by
101
+ * `keyPrefix`.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * import { contentAddressedStorage, memoryStorage } from "@graphrefly/graphrefly-ts";
106
+ *
107
+ * const cache = contentAddressedStorage<{ query: string }, { answer: string }>({
108
+ * storage: memoryStorage(),
109
+ * keyPrefix: "qa",
110
+ * mode: "read-write",
111
+ * });
112
+ *
113
+ * const hit = await cache.lookup({ query: "what is graphrefly?" });
114
+ * if (!hit) {
115
+ * const ans = await computeAnswer({ query: "what is graphrefly?" });
116
+ * await cache.store({ query: "what is graphrefly?" }, { answer: ans.text });
117
+ * }
118
+ * ```
119
+ *
120
+ * @category extra
121
+ */
122
+ declare function contentAddressedStorage<Ctx, V>(opts: ContentAddressedStorageOptions<Ctx>): ContentAddressedStorage<Ctx, V>;
123
+
124
+ export { ContentAddressedMissError as C, type ContentAddressedMode as a, type ContentAddressedStorage as b, type ContentAddressedStorageOptions as c, canonicalJson as d, contentAddressedStorage as e };
@@ -1 +1 @@
1
- "use strict";var _e=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Ke=Object.prototype.hasOwnProperty;var Je=(n,e)=>{for(var t in e)_e(n,t,{get:e[t],enumerable:!0})},Xe=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of qe(e))!Ke.call(n,r)&&r!==t&&_e(n,r,{get:()=>e[r],enumerable:!(s=Ye(e,r))||s.enumerable});return n};var Ze=n=>Xe(_e({},"__esModule",{value:!0}),n);var ut={};Je(ut,{COMPLETE:()=>A,COMPLETE_MSG:()=>me,COMPLETE_ONLY_BATCH:()=>le,DATA:()=>_,DEFAULT_ACTOR:()=>Ne,DIRTY:()=>w,DIRTY_MSG:()=>S,DIRTY_ONLY_BATCH:()=>Z,ERROR:()=>p,GraphReFlyConfig:()=>W,GuardDenied:()=>F,INVALIDATE:()=>T,INVALIDATE_MSG:()=>ye,INVALIDATE_ONLY_BATCH:()=>de,NodeImpl:()=>H,PAUSE:()=>N,RESOLVED:()=>x,RESOLVED_MSG:()=>J,RESOLVED_ONLY_BATCH:()=>ae,RESUME:()=>I,START:()=>C,START_MSG:()=>X,TEARDOWN:()=>b,TEARDOWN_MSG:()=>be,TEARDOWN_ONLY_BATCH:()=>Q,accessHintForGuard:()=>st,advanceVersion:()=>ue,autoTrackNode:()=>Be,batch:()=>Me,configure:()=>He,createVersioning:()=>te,defaultConfig:()=>G,defaultHash:()=>ee,derived:()=>Te,downWithBatch:()=>U,dynamicNode:()=>We,effect:()=>Ue,isBatching:()=>ie,isV1:()=>Re,monotonicNs:()=>ke,node:()=>L,normalizeActor:()=>Y,pipe:()=>je,policy:()=>De,policyFromRules:()=>tt,producer:()=>Pe,registerBuiltins:()=>ce,resolveDescribeFields:()=>Le,state:()=>Ve,wallClockNs:()=>oe});module.exports=Ze(ut);var Ne={type:"system",id:""};function Y(n){if(n==null)return Ne;let{type:e,id:t,...s}=n;return{type:e??"system",id:t??"",...s}}var V=0,q=!1,O=[],R=[],P=[],K=[];function ie(){return V>0||q}function Ae(){return V>0}function Ee(n){V>0?K.push(n):n()}function Me(n){V+=1;let e=!1;try{n()}catch(t){throw e=!0,t}finally{if(V-=1,V===0)if(e){if(!q){let t=K.splice(0);for(let s of t)try{s()}catch{}O.length=0,R.length=0,P.length=0}}else Qe()}}function Qe(){let n=!q;n&&(q=!0);let e=[],t=0;try{for(;O.length>0||R.length>0||P.length>0||n&&K.length>0;){if(n&&K.length>0){let o=K.splice(0);for(let a of o)try{a()}catch(i){e.push(i)}continue}if(t+=1,t>1e3)throw O.length=0,R.length=0,P.length=0,new Error("batch drain exceeded 1000 iterations \u2014 likely a reactive cycle");let r=(O.length>0?O:R.length>0?R:P).splice(0);for(let o of r)try{o()}catch(a){e.push(a)}}}finally{n&&(q=!1)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"batch drain: multiple callbacks threw")}function U(n,e,t){if(e.length===0)return;if(e.length===1){let l=t(e[0][0]);if(l<3||!ie()){n(e);return}(l>=5?P:l===4?R:O).push(()=>n(e));return}let s=e.length,r=s,o=s,a=s,i=0;for(;i<s&&t(e[i][0])<3;)i++;for(r=i;i<s&&t(e[i][0])===3;)i++;for(o=i;i<s&&t(e[i][0])===4;)i++;a=i;let d=ie();if(r>0){let l=e.slice(0,r);n(l)}if(o>r){let l=e.slice(r,o);d?O.push(()=>n(l)):n(l)}if(a>o){let l=e.slice(o,a);d?R.push(()=>n(l)):n(l)}if(s>a){let l=e.slice(a,s);d?P.push(()=>n(l)):n(l)}}function ke(){return Math.trunc(performance.now()*1e6)}function oe(){return Date.now()*1e6}var C=Symbol.for("graphrefly/START"),_=Symbol.for("graphrefly/DATA"),w=Symbol.for("graphrefly/DIRTY"),x=Symbol.for("graphrefly/RESOLVED"),T=Symbol.for("graphrefly/INVALIDATE"),N=Symbol.for("graphrefly/PAUSE"),I=Symbol.for("graphrefly/RESUME"),b=Symbol.for("graphrefly/TEARDOWN"),A=Symbol.for("graphrefly/COMPLETE"),p=Symbol.for("graphrefly/ERROR"),S=Object.freeze([w]),J=Object.freeze([x]),ye=Object.freeze([T]),X=Object.freeze([C]),me=Object.freeze([A]),be=Object.freeze([b]),Z=Object.freeze([S]),ae=Object.freeze([J]),de=Object.freeze([ye]),le=Object.freeze([me]),Q=Object.freeze([be]);var W=class{_messageTypes=new Map;_codecs=new Map;_onMessage;_onSubscribe;_defaultVersioning;_defaultHashFn;_inspectorEnabled=!(typeof process<"u"&&process.env?.NODE_ENV==="production");_globalInspector;_frozen=!1;tierOf;constructor(e){this._onMessage=e.onMessage,this._onSubscribe=e.onSubscribe,this._defaultVersioning=e.defaultVersioning,this._defaultHashFn=e.defaultHashFn,this.tierOf=t=>{let s=this._messageTypes.get(t);return s!=null?s.tier:1}}get onMessage(){return this._frozen=!0,this._onMessage}get onSubscribe(){return this._frozen=!0,this._onSubscribe}set onMessage(e){this._assertUnfrozen(),this._onMessage=e}set onSubscribe(e){this._assertUnfrozen(),this._onSubscribe=e}get defaultVersioning(){return this._defaultVersioning}set defaultVersioning(e){this._assertUnfrozen(),this._defaultVersioning=e}get defaultHashFn(){return this._defaultHashFn}set defaultHashFn(e){this._assertUnfrozen(),this._defaultHashFn=e}get inspectorEnabled(){return this._inspectorEnabled}set inspectorEnabled(e){this._inspectorEnabled=e}get globalInspector(){return this._globalInspector}set globalInspector(e){this._globalInspector=e}registerMessageType(e,t){return this._assertUnfrozen(),this._messageTypes.set(e,{tier:t.tier,wireCrossing:t.wireCrossing??t.tier>=3,metaPassthrough:t.metaPassthrough??!0}),this}messageTier(e){let t=this._messageTypes.get(e);return t!=null?t.tier:1}isWireCrossing(e){let t=this._messageTypes.get(e);return t!=null?t.wireCrossing:!0}isLocalOnly(e){return!this.isWireCrossing(e)}isMetaPassthrough(e){let t=this._messageTypes.get(e);return t!=null?t.metaPassthrough:!0}isKnownMessageType(e){return this._messageTypes.has(e)}registerCodec(e){return this._assertUnfrozen(),this._codecs.set(e.name,e),this}lookupCodec(e){return this._codecs.get(e)}_isFrozen(){return this._frozen}_assertUnfrozen(){if(this._frozen)throw new Error("GraphReFlyConfig is frozen: a node has already captured this config. Register custom types and set hooks before creating any node.")}};function ce(n){n.registerMessageType(C,{tier:0,wireCrossing:!1}),n.registerMessageType(w,{tier:1,wireCrossing:!1}),n.registerMessageType(T,{tier:1,wireCrossing:!1,metaPassthrough:!1}),n.registerMessageType(N,{tier:2,wireCrossing:!1}),n.registerMessageType(I,{tier:2,wireCrossing:!1}),n.registerMessageType(_,{tier:3,wireCrossing:!0}),n.registerMessageType(x,{tier:3,wireCrossing:!0}),n.registerMessageType(A,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(p,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(b,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var F=class extends Error{actor;action;nodeName;constructor(e,t){super(t??`GuardDenied: action "${String(e.action)}" denied for actor type "${String(e.actor.type)}"`),this.name="GuardDenied",this.actor=e.actor,this.action=e.action,this.nodeName=e.nodeName}get node(){return this.nodeName}};function Se(n){return Array.isArray(n)?[...n]:[n]}function et(n,e){return n.has(e)||n.has("*")}function De(n){let e=[];return n((r,o)=>{e.push({kind:"allow",actions:new Set(Se(r)),where:o?.where??(()=>!0)})},(r,o)=>{e.push({kind:"deny",actions:new Set(Se(r)),where:o?.where??(()=>!0)})}),(r,o)=>{let a=!1,i=!1;for(let d of e)et(d.actions,o)&&d.where(r)&&(d.kind==="deny"?a=!0:i=!0);return a?!1:i}}function tt(n){return De((e,t)=>{for(let s of n){let r=s.actorType==null?null:new Set(Array.isArray(s.actorType)?s.actorType:[s.actorType]),o=s.actorId==null?null:new Set(Array.isArray(s.actorId)?s.actorId:[s.actorId]),a=Object.entries(s.claims??{}),i=d=>{if(r!==null&&!r.has(String(d.type))||o!==null&&!o.has(String(d.id??"")))return!1;for(let[l,c]of a)if(d[l]!==c)return!1;return!0};s.effect==="deny"?t(s.action,{where:i}):e(s.action,{where:i})}})}var nt=["human","llm","wallet","system"];function st(n){let e=nt.filter(t=>n({type:t,id:""},"write"));return e.length===0?"restricted":e.includes("human")&&e.includes("llm")&&e.every(t=>t==="human"||t==="llm"||t==="system")?"both":e.length===1?e[0]:e.join("+")}var rt={name:"json",version:1,contentType:"application/json",encode(n){let e=JSON.stringify(n);return new TextEncoder().encode(e)},decode(n,e){let t=new TextDecoder().decode(n);return JSON.parse(t)}};function Oe(n){n.registerCodec(rt)}function ve(n){if(n===void 0)return null;if(typeof n=="number"){if(!Number.isFinite(n))throw new TypeError(`Cannot hash non-finite number: ${n}`);if(Number.isInteger(n)&&!Number.isSafeInteger(n))throw new TypeError(`Cannot hash integer outside safe range (|n| > 2^53-1): ${n}. Cross-language cid parity is not guaranteed for unsafe integers.`);return n}if(typeof n=="string"||typeof n=="boolean"||n===null)return n;if(Array.isArray(n))return n.map(ve);if(typeof n=="object"&&n!==null){let e={};for(let t of Object.keys(n).sort())e[t]=ve(n[t]);return e}return null}var it=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ot=new TextEncoder;function at(n){let e=ot.encode(n),t=e.length,s=t*8,r=t+9+63&-64,o=new Uint8Array(r);o.set(e),o[t]=128;let a=new DataView(o.buffer);a.setUint32(r-4,s>>>0,!1),a.setUint32(r-8,Math.floor(s/4294967296)>>>0,!1);let i=1779033703,d=3144134277,l=1013904242,c=2773480762,u=1359893119,g=2600822924,f=528734635,v=1541459225,D=new Uint32Array(64),m=(M,y)=>M>>>y|M<<32-y;for(let M=0;M<r;M+=64){for(let h=0;h<16;h++)D[h]=a.getUint32(M+h*4,!1);for(let h=16;h<64;h++){let z=D[h-15],$=D[h-2],re=m(z,7)^m(z,18)^z>>>3,ge=m($,17)^m($,19)^$>>>10;D[h]=D[h-16]+re+D[h-7]+ge>>>0}let y=i,B=d,j=l,he=c,k=u,ne=g,se=f,pe=v;for(let h=0;h<64;h++){let z=m(k,6)^m(k,11)^m(k,25),$=k&ne^~k&se,re=pe+z+$+it[h]+D[h]>>>0,ge=m(y,2)^m(y,13)^m(y,22),ze=y&B^y&j^B&j,$e=ge+ze>>>0;pe=se,se=ne,ne=k,k=he+re>>>0,he=j,j=B,B=y,y=re+$e>>>0}i=i+y>>>0,d=d+B>>>0,l=l+j>>>0,c=c+he>>>0,u=u+k>>>0,g=g+ne>>>0,f=f+se>>>0,v=v+pe>>>0}let E=M=>M.toString(16).padStart(8,"0");return E(i)+E(d)+E(l)+E(c)+E(u)+E(g)+E(f)+E(v)}function ee(n){let e=ve(n??null),t=JSON.stringify(e);return at(t).slice(0,16)}function dt(){let n=globalThis.crypto;if(n?.randomUUID)return n.randomUUID();let e=()=>Math.floor(Math.random()*4294967296).toString(16).padStart(8,"0"),t=e()+e()+e()+e();return`${t.slice(0,8)}-${t.slice(8,12)}-4${t.slice(13,16)}-${(parseInt(t.slice(16,17),16)&3|8).toString(16)}${t.slice(17,20)}-${t.slice(20,32)}`}function te(n,e,t){let s=t?.id??dt();if(n===0)return{id:s,version:0};let o=(t?.hash??ee)(e);return{id:s,version:0,cid:o,prev:null}}function ue(n,e,t){n.version+=1,"cid"in n&&(n.prev=n.cid,n.cid=t(e))}function Re(n){return"cid"in n}var Ce=()=>{},Ie=100;function Fe(n){return{node:n,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function we(n){n.prevData=void 0,n.dirty=!1,n.involvedThisWave=!1,n.dataBatch.length=0,n.terminal=void 0}function fe(n){return n.length===0?n:typeof n[0]=="symbol"?[n]:n}var lt=(n,e,t,s)=>{t.direction==="down-in"&&n._onDepMessage(t.depIndex,e)},ct=(n,e,t,s)=>{let r=n;if(r._status==="completed"||r._status==="errored")return;let o=r._cached,a=o===void 0?[X]:[X,[_,o]];r._status==="dirty"&&a.push(S),U(e,a,r._config.tierOf)},G=new W({onMessage:lt,onSubscribe:ct});ce(G);Oe(G);function He(n){if(G._isFrozen())throw new Error("configure() called after a node was created \u2014 the default GraphReFlyConfig is frozen. Call configure(...) at application startup, before any node factories run.");n(G)}var H=class n{_optsName;_describeKind;meta;_hasMeta;_config;_deps;_sinks=null;_sinkCount=0;_cached;_status;_cleanup;_store={};_waveHasNewData=!1;_hasNewTerminal=!1;_hasCalledFnOnce=!1;_paused=!1;_pendingWave=!1;_isExecutingFn=!1;_pendingRerun=!1;_rerunDepth=0;_dirtyDepCount=0;_batchPendingMessages=null;_pauseLocks=null;_pauseBuffer=null;_fn;_equals;_resubscribable;_resetOnTeardown;_autoComplete;_autoError;_pausable;_partial;_guard;_extraGuards;_hashFn;_versioning;_versioningLevel;_lastMutation;_inspectorHooks;_actions;constructor(e,t,s){this._config=s.config??G,this._config.onMessage,this._optsName=s.name,this._describeKind=s.describeKind,this._equals=s.equals??Object.is,this._resubscribable=s.resubscribable??!1,this._resetOnTeardown=s.resetOnTeardown??!1,this._autoComplete=s.completeWhenDepsComplete??!0,this._autoError=s.errorWhenDepsError??!0,this._pausable=s.pausable??!0,this._guard=s.guard,this._fn=t,this._partial=s.partial??!1,this._cached=s.initial!==void 0?s.initial:void 0,this._status=e.length===0&&t==null&&this._cached!==void 0?"settled":"sentinel",this._hashFn=s.versioningHash??this._config.defaultHashFn??ee;let r=s.versioning??this._config.defaultVersioning;this._versioningLevel=r,this._versioning=r!=null?te(r,this._cached===void 0?void 0:this._cached,{id:s.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(Fe);let o={};for(let[i,d]of Object.entries(s.meta??{})){let l={initial:d,name:`${s.name??"node"}:meta:${i}`,describeKind:"state",config:this._config};s.guard!=null&&(l.guard=s.guard),o[i]=new n([],void 0,l)}Object.freeze(o),this.meta=o,this._hasMeta=Object.keys(o).length>0;let a=this;this._actions={emit(i){a._emit([[_,i]])},down(i){a._emit(fe(i))},up(i){a._emitUp(fe(i))}},this.down=this.down.bind(this),this.up=this.up.bind(this)}get _isTerminal(){return this._status==="completed"||this._status==="errored"}get name(){return this._optsName}get status(){return this._status}get cache(){return this._cached===void 0?void 0:this._cached}get lastMutation(){return this._lastMutation}get v(){return this._versioning}hasGuard(){return this._guard!=null}_applyVersioning(e,t){if(this._isExecutingFn)throw new Error(`Node "${this.name}": _applyVersioning cannot run mid-fn \u2014 call it outside of \`_execFn\` (typically at graph setup time before the first subscribe).`);let s=this._versioningLevel;if(s!=null&&e<=s)return;let r=t?.hash??this._hashFn;r!==this._hashFn&&(this._hashFn=r);let o=this._cached===void 0?void 0:this._cached,a=this._versioning,i=a?.id??t?.id,d=a?.version??0,l=te(e,o,{id:i,hash:r});l.version=d,this._versioning=l,this._versioningLevel=e}_setInspectorHook(e){return e==null?()=>{}:(this._inspectorHooks==null&&(this._inspectorHooks=new Set),this._inspectorHooks.add(e),()=>{this._inspectorHooks?.delete(e),this._inspectorHooks?.size===0&&(this._inspectorHooks=void 0)})}_pushGuard(e){return this._extraGuards==null&&(this._extraGuards=new Set),this._extraGuards.add(e),()=>{this._extraGuards?.delete(e),this._extraGuards?.size===0&&(this._extraGuards=void 0)}}allowsObserve(e){if(this._guard==null&&this._extraGuards==null)return!0;let t=Y(e);if(this._guard!=null&&!this._guard(t,"observe"))return!1;if(this._extraGuards!=null){for(let s of this._extraGuards)if(!s(t,"observe"))return!1}return!0}_checkGuard(e){if(e?.internal)return;let t=this._guard!=null||this._extraGuards!=null,s=e?.actor!=null;if(!t&&!s)return;let r=Y(e?.actor),o=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(r,o))throw new F({actor:r,action:o,nodeName:this.name});if(this._extraGuards!=null){for(let a of this._extraGuards)if(!a(r,o))throw new F({actor:r,action:o,nodeName:this.name})}this._lastMutation={actor:r,timestamp_ns:oe()}}down(e,t){let s=fe(e);s.length!==0&&(this._checkGuard(t),this._emit(s))}emit(e,t){this._checkGuard(t),this._emit([[_,e]])}up(e,t){if(this._deps.length===0)return;let s=fe(e);if(s.length===0)return;this._checkGuard(t);let r=t??{internal:!0};this._validateUpTiers(s);for(let o of this._deps)o.node.up?.(s,r)}_emitUp(e){if(this._deps.length!==0&&e.length!==0){this._validateUpTiers(e);for(let t of this._deps)t.node.up?.(e,{internal:!0})}}_validateUpTiers(e){let t=this._config.tierOf;for(let s of e){let r=t(s[0]);if(r===3||r===4)throw new Error(`Node "${this.name}": tier-${r} messages cannot flow up \u2014 DATA/RESOLVED/COMPLETE/ERROR are downstream-only. Use \`down(...)\` for value delivery; \`up(...)\` is for control signals (DIRTY, INVALIDATE, PAUSE, RESUME, TEARDOWN).`)}}subscribe(e,t){if(t!=null&&this._guard!=null){let d=Y(t);if(!this._guard(d,"observe"))throw new F({actor:d,action:"observe",nodeName:this.name})}let r=this._isTerminal&&this._resubscribable;if(r){this._cached=void 0,this._status="sentinel",this._store={},this._hasCalledFnOnce=!1,this._waveHasNewData=!1,this._hasNewTerminal=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._isExecutingFn=!1,this._rerunDepth=0,this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null;for(let d of this._deps)we(d);if(this._partial===!1){for(let d of this._deps)if(d.prevData!==void 0||d.dataBatch.length!==0||d.terminal!==void 0||d.dirty)throw new Error(`resubscribable-reset invariant: DepRecord not fully reset for node ${this._optsName??"(anonymous)"}`)}}this._sinkCount+=1;let o;try{o=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:r},this._actions)}catch(d){throw this._sinkCount-=1,d}this._sinks==null?this._sinks=e:typeof this._sinks=="function"?this._sinks=new Set([this._sinks,e]):this._sinks.add(e);let a=this._isTerminal;if(this._sinkCount===1&&!a)try{this._activate()}catch(d){if(this._sinkCount-=1,this._removeSink(e),this._sinkCount===0&&(this._status="sentinel"),typeof o=="function")try{o()}catch{}throw d}this._status==="sentinel"&&this._cached===void 0&&(this._status="pending");let i=!1;return()=>{i||(i=!0,this._sinkCount-=1,this._removeSink(e),typeof o=="function"&&o(),this._sinks==null&&this._deactivate())}}_removeSink(e){if(this._sinks===e)this._sinks=null;else if(this._sinks!=null&&typeof this._sinks!="function")if(this._sinks.delete(e),this._sinks.size===1){let[t]=this._sinks;this._sinks=t}else this._sinks.size===0&&(this._sinks=null)}_activate(){if(this._deps.length===0){this._fn&&this._execFn();return}this._dirtyDepCount=0;let e=this._deps.length,t=0;try{for(let s=0;s<e;s++){let r=s,o=this._deps[s];o.unsub=Ce,o.unsub=o.node.subscribe(a=>{if(o.unsub===null)return;let i=this._config.tierOf,d=!1;for(let l of a)i(l[0])>=3&&(d=!0),this._config.onMessage(this,l,{direction:"down-in",depIndex:r},this._actions);d&&this._maybeRunFnOnSettlement()}),t++}}catch(s){this._deps[t].unsub=null;for(let r=0;r<t;r++){let o=this._deps[r];if(o.unsub!=null){let a=o.unsub;o.unsub=null;try{a()}catch{}we(o)}}throw this._dirtyDepCount=0,s}}_addDep(e){for(let r=0;r<this._deps.length;r++)if(this._deps[r].node===e)return r;let t=this._deps.length,s=Fe(e);if(this._deps.push(s),this._sinks==null)return t;s.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Z),s.unsub=Ce;try{s.unsub=e.subscribe(r=>{if(s.unsub===null)return;let o=this._config.tierOf,a=!1;for(let i of r)o(i[0])>=3&&(a=!0),this._config.onMessage(this,i,{direction:"down-in",depIndex:t},this._actions);a&&this._maybeRunFnOnSettlement()})}catch(r){throw s.unsub=null,this._deps.pop(),this._dirtyDepCount--,r}return t}_deactivate(e=!1){let t=this._cleanup;if(this._cleanup=void 0,typeof t=="function")try{t()}catch(s){this._emit([[p,this._wrapFnError("cleanup threw",s)]])}else if(t!=null&&typeof t=="object"){let s=t.deactivate;if(typeof s=="function")try{s()}catch(r){this._emit([[p,this._wrapFnError("cleanup.deactivate threw",r)]])}}for(let s of this._deps){if(s.unsub!=null){let r=s.unsub;s.unsub=null;try{r()}catch{}}we(s)}this._waveHasNewData=!1,this._hasNewTerminal=!1,this._hasCalledFnOnce=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._rerunDepth=0,this._store={},this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null,this._fn!=null&&(this._cached=void 0),e||(this._fn!=null||this._deps.length>0)&&(!this._isTerminal||this._resubscribable)&&(this._status="sentinel")}_onDepMessage(e,t){let s=this._deps[e],r=t[0];if(this._inspectorHooks!=null){let o={kind:"dep_message",depIndex:e,message:t};for(let a of this._inspectorHooks)a(o)}if(r!==C){if(r===w){this._depDirtied(s);return}if(r===T){this._depInvalidated(s),this._emit(de);return}if(r===N||r===I){this._emit([t]);return}if(r===b){this._emit(Q);return}if(r===_)this._depSettledAsData(s,t[1]);else if(r===x)this._depSettledAsResolved(s);else if(r===A)this._depSettledAsTerminal(s,!0);else if(r===p)this._depSettledAsTerminal(s,t[1]);else{this._emit([t]);return}if(!this._fn){(r===_||r===x)&&this._emit([t]),(r===A||r===p)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Z))}_depSettledAsData(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.involvedThisWave=!0,e.dataBatch.push(t),this._waveHasNewData=!0}_depSettledAsResolved(e){e.dirty&&(e.dirty=!1,this._dirtyDepCount--)}_depSettledAsTerminal(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.terminal=t,e.involvedThisWave=!0,this._hasNewTerminal=!0}_depInvalidated(e){e.prevData=void 0,e.terminal=void 0,e.dataBatch.length=0,e.dirty?e.involvedThisWave=!1:(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++)}_maybeRunFnOnSettlement(){if(!(this._isTerminal&&!this._resubscribable)&&!(this._dirtyDepCount>0)){if(!this._partial&&!this._hasCalledFnOnce)for(let e=0;e<this._deps.length;e++){let t=this._deps[e];if(t.dataBatch.length===0&&t.prevData===void 0&&t.terminal===void 0){this._maybeAutoTerminalAfterWave();return}}if(this._paused){this._pendingWave=!0;return}if(!this._waveHasNewData&&!this._hasNewTerminal&&this._hasCalledFnOnce){this._clearWaveFlags(),this._emit(ae),this._maybeAutoTerminalAfterWave();return}this._fn&&this._execFn(),this._maybeAutoTerminalAfterWave()}}_maybeAutoTerminalAfterWave(){if(this._deps.length===0||this._isTerminal)return;let e=this._deps.find(t=>t.terminal!==void 0&&t.terminal!==!0);if(e!=null){this._autoError&&this._emit([[p,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.terminal!==void 0)&&this._emit(le)}_execFn(){if(!this._fn||this._isTerminal&&!this._resubscribable)return;if(this._isExecutingFn){this._pendingRerun=!0;return}let e=this._cleanup;if(typeof e=="function"){this._cleanup=void 0;try{e()}catch(a){this._emit([[p,this._wrapFnError("cleanup threw",a)]]);return}}else if(e!=null&&typeof e=="object"){let a=e.beforeRun;if(typeof a=="function"){e.beforeRun=void 0;try{a()}catch(i){this._emit([[p,this._wrapFnError("cleanup.beforeRun threw",i)]]);return}}}let t=this._deps.map(a=>a.involvedThisWave?a.dataBatch.length>0?[...a.dataBatch]:[]:void 0),s=this._deps.map(a=>a.prevData);for(let a=0;a<this._deps.length;a++){let i=t[a];i!=null&&i.length>0&&(this._deps[a].prevData=i[i.length-1])}let r=this._deps.map(a=>a.terminal),o={prevData:s,terminalDeps:r,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let a={kind:"run",batchData:t,prevData:s};for(let i of this._inspectorHooks)i(a)}this._isExecutingFn=!0;try{let a=this._fn(t,this._actions,o);if(typeof a=="function")this._cleanup=a;else if(a!=null&&typeof a=="object"){let i=a;(typeof i.beforeRun=="function"||typeof i.deactivate=="function"||typeof i.invalidate=="function")&&(this._cleanup=a)}}catch(a){this._emit([[p,this._wrapFnError("fn threw",a)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>Ie?(this._rerunDepth=0,this._emit([[p,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${Ie} \u2014 likely a reactive cycle`)]])):this._maybeRunFnOnSettlement()):this._rerunDepth=0,this._clearWaveFlags()}}_clearWaveFlags(){this._waveHasNewData=!1,this._hasNewTerminal=!1;for(let e of this._deps)e.involvedThisWave=!1,e.dataBatch.length=0}_wrapFnError(e,t){let s=t instanceof Error?t.message:String(t);return new Error(`Node "${this.name}": ${e}: ${s}`,{cause:t})}_frameBatch(e){let t=this._config.tierOf;if(e.length===1)return t(e[0][0])===3&&this._status!=="dirty"?[S,e[0]]:e;let s=!0,r=!1,o=!1,a=-1;for(let d of e){let l=t(d[0]);l<a&&(s=!1),l===3&&(r=!0),d[0]===w&&(o=!0),a=l}let i=e;if(!s){let d=e.map((l,c)=>({m:l,i:c,tier:t(l[0])}));d.sort((l,c)=>l.tier-c.tier||l.i-c.i),i=d.map(l=>l.m)}if(r&&!o&&this._status!=="dirty"){let d=0;for(;d<i.length&&t(i[d][0])===0;)d++;return d===0?[S,...i]:[...i.slice(0,d),S,...i.slice(d)]}return i}_emit(e){if(e.length===0)return;for(let i=0;i<e.length;i++){let d=e[i];if(d[0]===p&&d[1]===void 0)throw new TypeError('[ERROR, payload] requires a non-undefined payload (spec \xA71.2). Pass an Error object or domain tag instead \u2014 e.g. node.down([[ERROR, new Error("reason")]])')}let t=e;if(this._isTerminal&&!this._resubscribable){let i=e.filter(d=>d[0]===b||d[0]===T);if(i.length===0)return;t=i}t=this._frameBatch(t);let r=null;for(let i=0;i<t.length;i++){let d=t[i],l=d[0];if(l!==N&&l!==I){r?.push(d);continue}if(d.length<2)throw new Error(`Node "${this.name}": [[${l===N?"PAUSE":"RESUME"}]] must carry a lockId payload \u2014 bare PAUSE/RESUME is a protocol violation (C0 rule). Use \`[[PAUSE, lockId]]\` / \`[[RESUME, lockId]]\`.`);let c=!0;if(this._pausable!==!1){let u=d[1];if(l===N)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(u),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(u))c=!1;else if(this._pauseLocks.delete(u),this._pauseLocks.size===0){if(this._paused=!1,this._pauseBuffer!=null&&this._pauseBuffer.length>0){let g=this._pauseBuffer;this._pauseBuffer=[],this._emit(g)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}c?r?.push(d):r==null&&(r=t.slice(0,i))}if(r!=null){if(r.length===0)return;t=r}if(this._hasMeta&&t.some(i=>i[0]===b))for(let i of Object.keys(this.meta))try{this.meta[i]._emit(Q)}catch{}let{finalMessages:o,equalsError:a}=this._updateState(t);if(o.length>0&&this._config.inspectorEnabled){let i=this._config.globalInspector;if(i!=null)try{i({kind:"emit",node:this,messages:o})}catch{}}if(o.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let i=this._config.tierOf,d=[];for(let l of o)i(l[0])===3?this._pauseBuffer.push(l):d.push(l);d.length>0&&this._dispatchOrAccumulate(d)}else this._dispatchOrAccumulate(o);a!=null&&this._emit([[p,a]])}_updateState(e){let t=this._config.tierOf,s,r,o=-1,a=0;for(let c of e)t(c[0])===3&&a++;let i=a<=1,d=-1;if(this._versioning!=null&&a>1){for(let c=e.length-1;c>=0;c--)if(e[c][0]===_){d=c;break}}for(let c=0;c<e.length;c++){let u=e[c],g=u[0];if(g===_){if(u.length>=2){let f=!1;if(i&&this._cached!==void 0)try{f=this._equals(this._cached,u[1])}catch(v){r=this._wrapFnError("equals threw",v),o=c;break}if(f){s==null&&(s=e.slice(0,c)),s.push(J),this._status="resolved";continue}this._cached=u[1],this._versioning!=null&&(d<0||c===d)&&ue(this._versioning,u[1],this._hashFn)}this._status="settled",s?.push(u)}else if(s?.push(u),g===w)this._status="dirty";else if(g===x)this._status="resolved";else if(g===A)this._status="completed";else if(g===p)this._status="errored";else if(g===T){this._cached=void 0,this._status="dirty";let f=this._cleanup;if(typeof f=="function"){this._cleanup=void 0;try{f()}catch{}}else if(f!=null&&typeof f=="object"){let v=f.invalidate;if(typeof v=="function")try{v()}catch{}}}else g===b&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let l=o>=0?s??e.slice(0,o):s??e;return r!=null?{finalMessages:l,equalsError:r}:{finalMessages:l}}_deliverToSinks=e=>{if(this._sinks==null)return;if(typeof this._sinks=="function"){this._sinks(e);return}let t=[...this._sinks];for(let s of t)s(e)};_dispatchOrAccumulate(e){if(Ae()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],Ee(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}U(this._deliverToSinks,e,this._config.tierOf)}_flushBatchPending(){let e=this._batchPendingMessages;if(e===null||(this._batchPendingMessages=null,e.length===0))return;let t=this._frameBatch(e);U(this._deliverToSinks,t,this._config.tierOf)}},Ge=n=>Array.isArray(n),xe=n=>typeof n=="object"&&n!=null&&!Array.isArray(n);function L(n,e,t){let s=Ge(n)?n:[],r=typeof n=="function"?n:typeof e=="function"?e:void 0,o={};return Ge(n)?o=(xe(e)?e:t)??{}:xe(n)?o=n:o=(xe(e)?e:t)??{},new H(s,r,o)}function Le(n,e){if(e!=null&&e.length>0)return new Set(e);switch(n){case"standard":return new Set(["type","status","value","deps","meta","v"]);case"full":return null;default:return new Set(["type","deps"])}}function Ve(n,e){return L([],{...e,initial:n})}function Pe(n,e){return L((s,r,o)=>n(r,o)??void 0,{describeKind:"producer",...e})}function Te(n,e,t){return L(n,(r,o,a)=>{let i=r.map((d,l)=>d!=null&&d.length>0?d.at(-1):a.prevData[l]);o.emit(e(i,a))},{describeKind:"derived",...t})}function Ue(n,e,t){return L(n,(r,o,a)=>{let i=r.map((d,l)=>d!=null&&d.length>0?d.at(-1):a.prevData[l]);return e(i,o,a)??void 0},{describeKind:"effect",...t})}function We(n,e,t){let s=new Map;return n.forEach((r,o)=>{s.set(r,o)}),Te(n,(r,o)=>e(i=>{let d=s.get(i);if(d==null)throw new Error(`dynamicNode: untracked dep "${i.name??"<unnamed>"}"`);return r[d]},o),t)}function Be(n,e){let t,s=new Map,r=(o,a,i)=>{let d=!1,l=c=>{let u=s.get(c);if(u!==void 0){if(u<o.length){let f=o[u];return f!=null&&f.length>0?f.at(-1):i.prevData[u]}return c.cache}d=!0;let g=t._addDep(c);return s.set(c,g),c.cache};try{let c=n(l,i);d||(a.emit(c),i.store.__autoTrackLastDiscoveryError!=null&&delete i.store.__autoTrackLastDiscoveryError)}catch(c){if(!d)throw c;i.store.__autoTrackLastDiscoveryError=c}};return t=new H([],r,{describeKind:"derived",...e}),t}function je(n,...e){let t=n;for(let s of e)t=s(t);return t}0&&(module.exports={COMPLETE,COMPLETE_MSG,COMPLETE_ONLY_BATCH,DATA,DEFAULT_ACTOR,DIRTY,DIRTY_MSG,DIRTY_ONLY_BATCH,ERROR,GraphReFlyConfig,GuardDenied,INVALIDATE,INVALIDATE_MSG,INVALIDATE_ONLY_BATCH,NodeImpl,PAUSE,RESOLVED,RESOLVED_MSG,RESOLVED_ONLY_BATCH,RESUME,START,START_MSG,TEARDOWN,TEARDOWN_MSG,TEARDOWN_ONLY_BATCH,accessHintForGuard,advanceVersion,autoTrackNode,batch,configure,createVersioning,defaultConfig,defaultHash,derived,downWithBatch,dynamicNode,effect,isBatching,isV1,monotonicNs,node,normalizeActor,pipe,policy,policyFromRules,producer,registerBuiltins,resolveDescribeFields,state,wallClockNs});
1
+ "use strict";var _e=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Ke=Object.prototype.hasOwnProperty;var Je=(n,e)=>{for(var t in e)_e(n,t,{get:e[t],enumerable:!0})},Xe=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of qe(e))!Ke.call(n,r)&&r!==t&&_e(n,r,{get:()=>e[r],enumerable:!(s=Ye(e,r))||s.enumerable});return n};var Ze=n=>Xe(_e({},"__esModule",{value:!0}),n);var ut={};Je(ut,{COMPLETE:()=>A,COMPLETE_MSG:()=>me,COMPLETE_ONLY_BATCH:()=>le,DATA:()=>_,DEFAULT_ACTOR:()=>Ne,DIRTY:()=>w,DIRTY_MSG:()=>S,DIRTY_ONLY_BATCH:()=>Z,ERROR:()=>p,GraphReFlyConfig:()=>W,GuardDenied:()=>F,INVALIDATE:()=>T,INVALIDATE_MSG:()=>ye,INVALIDATE_ONLY_BATCH:()=>de,NodeImpl:()=>H,PAUSE:()=>N,RESOLVED:()=>x,RESOLVED_MSG:()=>J,RESOLVED_ONLY_BATCH:()=>ae,RESUME:()=>I,START:()=>C,START_MSG:()=>X,TEARDOWN:()=>b,TEARDOWN_MSG:()=>be,TEARDOWN_ONLY_BATCH:()=>Q,accessHintForGuard:()=>st,advanceVersion:()=>ue,autoTrackNode:()=>Be,batch:()=>Me,configure:()=>He,createVersioning:()=>te,defaultConfig:()=>G,defaultHash:()=>ee,derived:()=>Te,downWithBatch:()=>U,dynamicNode:()=>We,effect:()=>Ue,isBatching:()=>ie,isV1:()=>Re,monotonicNs:()=>ke,node:()=>L,normalizeActor:()=>Y,pipe:()=>je,policy:()=>De,policyFromRules:()=>tt,producer:()=>Pe,registerBuiltins:()=>ce,resolveDescribeFields:()=>Le,state:()=>Ve,wallClockNs:()=>oe});module.exports=Ze(ut);var Ne={type:"system",id:""};function Y(n){if(n==null)return Ne;let{type:e,id:t,...s}=n;return{type:e??"system",id:t??"",...s}}var V=0,q=!1,O=[],R=[],P=[],K=[];function ie(){return V>0||q}function Ae(){return V>0}function Ee(n){V>0?K.push(n):n()}function Me(n){V+=1;let e=!1;try{n()}catch(t){throw e=!0,t}finally{if(V-=1,V===0)if(e){if(!q){let t=K.splice(0);for(let s of t)try{s()}catch{}O.length=0,R.length=0,P.length=0}}else Qe()}}function Qe(){let n=!q;n&&(q=!0);let e=[],t=0;try{for(;O.length>0||R.length>0||P.length>0||n&&K.length>0;){if(n&&K.length>0){let o=K.splice(0);for(let a of o)try{a()}catch(i){e.push(i)}continue}if(t+=1,t>1e3)throw O.length=0,R.length=0,P.length=0,new Error("batch drain exceeded 1000 iterations \u2014 likely a reactive cycle");let r=(O.length>0?O:R.length>0?R:P).splice(0);for(let o of r)try{o()}catch(a){e.push(a)}}}finally{n&&(q=!1)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"batch drain: multiple callbacks threw")}function U(n,e,t){if(e.length===0)return;if(e.length===1){let l=t(e[0][0]);if(l<3||!ie()){n(e);return}(l>=5?P:l===4?R:O).push(()=>n(e));return}let s=e.length,r=s,o=s,a=s,i=0;for(;i<s&&t(e[i][0])<3;)i++;for(r=i;i<s&&t(e[i][0])===3;)i++;for(o=i;i<s&&t(e[i][0])===4;)i++;a=i;let d=ie();if(r>0){let l=e.slice(0,r);n(l)}if(o>r){let l=e.slice(r,o);d?O.push(()=>n(l)):n(l)}if(a>o){let l=e.slice(o,a);d?R.push(()=>n(l)):n(l)}if(s>a){let l=e.slice(a,s);d?P.push(()=>n(l)):n(l)}}function ke(){return Math.trunc(performance.now()*1e6)}function oe(){return Date.now()*1e6}var C=Symbol.for("graphrefly/START"),_=Symbol.for("graphrefly/DATA"),w=Symbol.for("graphrefly/DIRTY"),x=Symbol.for("graphrefly/RESOLVED"),T=Symbol.for("graphrefly/INVALIDATE"),N=Symbol.for("graphrefly/PAUSE"),I=Symbol.for("graphrefly/RESUME"),b=Symbol.for("graphrefly/TEARDOWN"),A=Symbol.for("graphrefly/COMPLETE"),p=Symbol.for("graphrefly/ERROR"),S=Object.freeze([w]),J=Object.freeze([x]),ye=Object.freeze([T]),X=Object.freeze([C]),me=Object.freeze([A]),be=Object.freeze([b]),Z=Object.freeze([S]),ae=Object.freeze([J]),de=Object.freeze([ye]),le=Object.freeze([me]),Q=Object.freeze([be]);var W=class{_messageTypes=new Map;_codecs=new Map;_onMessage;_onSubscribe;_defaultVersioning;_defaultHashFn;_inspectorEnabled=!(typeof process<"u"&&process.env?.NODE_ENV==="production");_globalInspector;_frozen=!1;tierOf;constructor(e){this._onMessage=e.onMessage,this._onSubscribe=e.onSubscribe,this._defaultVersioning=e.defaultVersioning,this._defaultHashFn=e.defaultHashFn,this.tierOf=t=>{let s=this._messageTypes.get(t);return s!=null?s.tier:1}}get onMessage(){return this._frozen=!0,this._onMessage}get onSubscribe(){return this._frozen=!0,this._onSubscribe}set onMessage(e){this._assertUnfrozen(),this._onMessage=e}set onSubscribe(e){this._assertUnfrozen(),this._onSubscribe=e}get defaultVersioning(){return this._defaultVersioning}set defaultVersioning(e){this._assertUnfrozen(),this._defaultVersioning=e}get defaultHashFn(){return this._defaultHashFn}set defaultHashFn(e){this._assertUnfrozen(),this._defaultHashFn=e}get inspectorEnabled(){return this._inspectorEnabled}set inspectorEnabled(e){this._inspectorEnabled=e}get globalInspector(){return this._globalInspector}set globalInspector(e){this._globalInspector=e}registerMessageType(e,t){return this._assertUnfrozen(),this._messageTypes.set(e,{tier:t.tier,wireCrossing:t.wireCrossing??t.tier>=3,metaPassthrough:t.metaPassthrough??!0}),this}messageTier(e){let t=this._messageTypes.get(e);return t!=null?t.tier:1}isWireCrossing(e){let t=this._messageTypes.get(e);return t!=null?t.wireCrossing:!0}isLocalOnly(e){return!this.isWireCrossing(e)}isMetaPassthrough(e){let t=this._messageTypes.get(e);return t!=null?t.metaPassthrough:!0}isKnownMessageType(e){return this._messageTypes.has(e)}registerCodec(e){return this._assertUnfrozen(),this._codecs.set(e.name,e),this}lookupCodec(e){return this._codecs.get(e)}_isFrozen(){return this._frozen}_assertUnfrozen(){if(this._frozen)throw new Error("GraphReFlyConfig is frozen: a node has already captured this config. Register custom types and set hooks before creating any node.")}};function ce(n){n.registerMessageType(C,{tier:0,wireCrossing:!1}),n.registerMessageType(w,{tier:1,wireCrossing:!1}),n.registerMessageType(T,{tier:1,wireCrossing:!1,metaPassthrough:!1}),n.registerMessageType(N,{tier:2,wireCrossing:!1}),n.registerMessageType(I,{tier:2,wireCrossing:!1}),n.registerMessageType(_,{tier:3,wireCrossing:!0}),n.registerMessageType(x,{tier:3,wireCrossing:!0}),n.registerMessageType(A,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(p,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(b,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var F=class extends Error{actor;action;nodeName;constructor(e,t){super(t??`GuardDenied: action "${String(e.action)}" denied for actor type "${String(e.actor.type)}"`),this.name="GuardDenied",this.actor=e.actor,this.action=e.action,this.nodeName=e.nodeName}get node(){return this.nodeName}};function Se(n){return Array.isArray(n)?[...n]:[n]}function et(n,e){return n.has(e)||n.has("*")}function De(n){let e=[];return n((r,o)=>{e.push({kind:"allow",actions:new Set(Se(r)),where:o?.where??(()=>!0)})},(r,o)=>{e.push({kind:"deny",actions:new Set(Se(r)),where:o?.where??(()=>!0)})}),(r,o)=>{let a=!1,i=!1;for(let d of e)et(d.actions,o)&&d.where(r)&&(d.kind==="deny"?a=!0:i=!0);return a?!1:i}}function tt(n){return De((e,t)=>{for(let s of n){let r=s.actorType==null?null:new Set(Array.isArray(s.actorType)?s.actorType:[s.actorType]),o=s.actorId==null?null:new Set(Array.isArray(s.actorId)?s.actorId:[s.actorId]),a=Object.entries(s.claims??{}),i=d=>{if(r!==null&&!r.has(String(d.type))||o!==null&&!o.has(String(d.id??"")))return!1;for(let[l,c]of a)if(d[l]!==c)return!1;return!0};s.effect==="deny"?t(s.action,{where:i}):e(s.action,{where:i})}})}var nt=["human","llm","wallet","system"];function st(n){let e=nt.filter(t=>n({type:t,id:""},"write"));return e.length===0?"restricted":e.includes("human")&&e.includes("llm")&&e.every(t=>t==="human"||t==="llm"||t==="system")?"both":e.length===1?e[0]:e.join("+")}var rt={name:"json",version:1,contentType:"application/json",encode(n){let e=JSON.stringify(n);return new TextEncoder().encode(e)},decode(n,e){let t=new TextDecoder().decode(n);return JSON.parse(t)}};function Oe(n){n.registerCodec(rt)}function ve(n){if(n===void 0)return null;if(typeof n=="number"){if(!Number.isFinite(n))throw new TypeError(`Cannot hash non-finite number: ${n}`);if(Number.isInteger(n)&&!Number.isSafeInteger(n))throw new TypeError(`Cannot hash integer outside safe range (|n| > 2^53-1): ${n}. Cross-language cid parity is not guaranteed for unsafe integers.`);return n}if(typeof n=="string"||typeof n=="boolean"||n===null)return n;if(Array.isArray(n))return n.map(ve);if(typeof n=="object"&&n!==null){let e={};for(let t of Object.keys(n).sort())e[t]=ve(n[t]);return e}return null}var it=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ot=new TextEncoder;function at(n){let e=ot.encode(n),t=e.length,s=t*8,r=t+9+63&-64,o=new Uint8Array(r);o.set(e),o[t]=128;let a=new DataView(o.buffer);a.setUint32(r-4,s>>>0,!1),a.setUint32(r-8,Math.floor(s/4294967296)>>>0,!1);let i=1779033703,d=3144134277,l=1013904242,c=2773480762,u=1359893119,g=2600822924,f=528734635,v=1541459225,D=new Uint32Array(64),m=(M,y)=>M>>>y|M<<32-y;for(let M=0;M<r;M+=64){for(let h=0;h<16;h++)D[h]=a.getUint32(M+h*4,!1);for(let h=16;h<64;h++){let z=D[h-15],$=D[h-2],re=m(z,7)^m(z,18)^z>>>3,ge=m($,17)^m($,19)^$>>>10;D[h]=D[h-16]+re+D[h-7]+ge>>>0}let y=i,B=d,j=l,he=c,k=u,ne=g,se=f,pe=v;for(let h=0;h<64;h++){let z=m(k,6)^m(k,11)^m(k,25),$=k&ne^~k&se,re=pe+z+$+it[h]+D[h]>>>0,ge=m(y,2)^m(y,13)^m(y,22),ze=y&B^y&j^B&j,$e=ge+ze>>>0;pe=se,se=ne,ne=k,k=he+re>>>0,he=j,j=B,B=y,y=re+$e>>>0}i=i+y>>>0,d=d+B>>>0,l=l+j>>>0,c=c+he>>>0,u=u+k>>>0,g=g+ne>>>0,f=f+se>>>0,v=v+pe>>>0}let E=M=>M.toString(16).padStart(8,"0");return E(i)+E(d)+E(l)+E(c)+E(u)+E(g)+E(f)+E(v)}function ee(n){let e=ve(n??null),t=JSON.stringify(e);return at(t).slice(0,16)}function dt(){let n=globalThis.crypto;if(n?.randomUUID)return n.randomUUID();let e=()=>Math.floor(Math.random()*4294967296).toString(16).padStart(8,"0"),t=e()+e()+e()+e();return`${t.slice(0,8)}-${t.slice(8,12)}-4${t.slice(13,16)}-${(parseInt(t.slice(16,17),16)&3|8).toString(16)}${t.slice(17,20)}-${t.slice(20,32)}`}function te(n,e,t){let s=t?.id??dt();if(n===0)return{id:s,version:0};let o=(t?.hash??ee)(e);return{id:s,version:0,cid:o,prev:null}}function ue(n,e,t){n.version+=1,"cid"in n&&(n.prev=n.cid,n.cid=t(e))}function Re(n){return"cid"in n}var Ce=()=>{},Ie=100;function Fe(n){return{node:n,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function we(n){n.prevData=void 0,n.dirty=!1,n.involvedThisWave=!1,n.dataBatch.length=0,n.terminal=void 0}function fe(n){return n.length===0?n:typeof n[0]=="symbol"?[n]:n}var lt=(n,e,t,s)=>{t.direction==="down-in"&&n._onDepMessage(t.depIndex,e)},ct=(n,e,t,s)=>{let r=n;if(r._status==="completed"||r._status==="errored")return;let o=r._cached,a=o===void 0?[X]:[X,[_,o]];r._status==="dirty"&&a.push(S),U(e,a,r._config.tierOf)},G=new W({onMessage:lt,onSubscribe:ct});ce(G);Oe(G);function He(n){if(G._isFrozen())throw new Error("configure() called after a node was created \u2014 the default GraphReFlyConfig is frozen. Call configure(...) at application startup, before any node factories run.");n(G)}var H=class n{_optsName;_describeKind;meta;_hasMeta;_config;_deps;_sinks=null;_sinkCount=0;_cached;_status;_cleanup;_store={};_waveHasNewData=!1;_hasNewTerminal=!1;_hasCalledFnOnce=!1;_paused=!1;_pendingWave=!1;_isExecutingFn=!1;_pendingRerun=!1;_rerunDepth=0;_dirtyDepCount=0;_batchPendingMessages=null;_pauseLocks=null;_pauseBuffer=null;_fn;_equals;_resubscribable;_resetOnTeardown;_autoComplete;_autoError;_pausable;_partial;_guard;_extraGuards;_hashFn;_versioning;_versioningLevel;_lastMutation;_inspectorHooks;_actions;constructor(e,t,s){this._config=s.config??G,this._config.onMessage,this._optsName=s.name,this._describeKind=s.describeKind,this._equals=s.equals??Object.is,this._resubscribable=s.resubscribable??!1,this._resetOnTeardown=s.resetOnTeardown??!1,this._autoComplete=s.completeWhenDepsComplete??!0,this._autoError=s.errorWhenDepsError??!0,this._pausable=s.pausable??!0,this._guard=s.guard,this._fn=t,this._partial=s.partial??!1,this._cached=s.initial!==void 0?s.initial:void 0,this._status=e.length===0&&t==null&&this._cached!==void 0?"settled":"sentinel",this._hashFn=s.versioningHash??this._config.defaultHashFn??ee;let r=s.versioning??this._config.defaultVersioning;this._versioningLevel=r,this._versioning=r!=null?te(r,this._cached===void 0?void 0:this._cached,{id:s.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(Fe);let o={};for(let[i,d]of Object.entries(s.meta??{})){let l={initial:d,name:`${s.name??"node"}:meta:${i}`,describeKind:"state",config:this._config};s.guard!=null&&(l.guard=s.guard),o[i]=new n([],void 0,l)}Object.freeze(o),this.meta=o,this._hasMeta=Object.keys(o).length>0;let a=this;this._actions={emit(i){a._emit([[_,i]])},down(i){a._emit(fe(i))},up(i){a._emitUp(fe(i))}},this.down=this.down.bind(this),this.up=this.up.bind(this)}get _isTerminal(){return this._status==="completed"||this._status==="errored"}get name(){return this._optsName}get status(){return this._status}get cache(){return this._cached===void 0?void 0:this._cached}get lastMutation(){return this._lastMutation}get v(){return this._versioning}hasGuard(){return this._guard!=null}_applyVersioning(e,t){if(this._isExecutingFn)throw new Error(`Node "${this.name}": _applyVersioning cannot run mid-fn \u2014 call it outside of \`_execFn\` (typically at graph setup time before the first subscribe).`);let s=this._versioningLevel;if(s!=null&&e<=s)return;let r=t?.hash??this._hashFn;r!==this._hashFn&&(this._hashFn=r);let o=this._cached===void 0?void 0:this._cached,a=this._versioning,i=a?.id??t?.id,d=a?.version??0,l=te(e,o,{id:i,hash:r});l.version=d,this._versioning=l,this._versioningLevel=e}_setInspectorHook(e){return e==null?()=>{}:(this._inspectorHooks==null&&(this._inspectorHooks=new Set),this._inspectorHooks.add(e),()=>{this._inspectorHooks?.delete(e),this._inspectorHooks?.size===0&&(this._inspectorHooks=void 0)})}_pushGuard(e){return this._extraGuards==null&&(this._extraGuards=new Set),this._extraGuards.add(e),()=>{this._extraGuards?.delete(e),this._extraGuards?.size===0&&(this._extraGuards=void 0)}}allowsObserve(e){if(this._guard==null&&this._extraGuards==null)return!0;let t=Y(e);if(this._guard!=null&&!this._guard(t,"observe"))return!1;if(this._extraGuards!=null){for(let s of this._extraGuards)if(!s(t,"observe"))return!1}return!0}_checkGuard(e){if(e?.internal)return;let t=this._guard!=null||this._extraGuards!=null,s=e?.actor!=null;if(!t&&!s)return;let r=Y(e?.actor),o=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(r,o))throw new F({actor:r,action:o,nodeName:this.name});if(this._extraGuards!=null){for(let a of this._extraGuards)if(!a(r,o))throw new F({actor:r,action:o,nodeName:this.name})}this._lastMutation={actor:r,timestamp_ns:oe()}}down(e,t){let s=fe(e);s.length!==0&&(this._checkGuard(t),this._emit(s))}emit(e,t){this._checkGuard(t),this._emit([[_,e]])}up(e,t){if(this._deps.length===0)return;let s=fe(e);if(s.length===0)return;this._checkGuard(t);let r=t??{internal:!0};this._validateUpTiers(s);for(let o of this._deps)o.node.up?.(s,r)}_emitUp(e){if(this._deps.length!==0&&e.length!==0){this._validateUpTiers(e);for(let t of this._deps)t.node.up?.(e,{internal:!0})}}_validateUpTiers(e){let t=this._config.tierOf;for(let s of e){let r=t(s[0]);if(r===3||r===4)throw new Error(`Node "${this.name}": tier-${r} messages cannot flow up \u2014 DATA/RESOLVED/COMPLETE/ERROR are downstream-only. Use \`down(...)\` for value delivery; \`up(...)\` is for control signals (DIRTY, INVALIDATE, PAUSE, RESUME, TEARDOWN).`)}}subscribe(e,t){if(t!=null&&this._guard!=null){let d=Y(t);if(!this._guard(d,"observe"))throw new F({actor:d,action:"observe",nodeName:this.name})}let r=this._isTerminal&&this._resubscribable;if(r){this._cached=void 0,this._status="sentinel",this._store={},this._hasCalledFnOnce=!1,this._waveHasNewData=!1,this._hasNewTerminal=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._isExecutingFn=!1,this._rerunDepth=0,this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null;for(let d of this._deps)we(d);if(this._partial===!1){for(let d of this._deps)if(d.prevData!==void 0||d.dataBatch.length!==0||d.terminal!==void 0||d.dirty)throw new Error(`resubscribable-reset invariant: DepRecord not fully reset for node ${this._optsName??"(anonymous)"}`)}}this._sinkCount+=1;let o;try{o=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:r},this._actions)}catch(d){throw this._sinkCount-=1,d}this._sinks==null?this._sinks=e:typeof this._sinks=="function"?this._sinks=new Set([this._sinks,e]):this._sinks.add(e);let a=this._isTerminal;if(this._sinkCount===1&&!a)try{this._activate()}catch(d){if(this._sinkCount-=1,this._removeSink(e),this._sinkCount===0&&(this._status="sentinel"),typeof o=="function")try{o()}catch{}throw d}this._status==="sentinel"&&this._cached===void 0&&(this._status="pending");let i=!1;return()=>{i||(i=!0,this._sinkCount-=1,this._removeSink(e),typeof o=="function"&&o(),this._sinks==null&&this._deactivate())}}_removeSink(e){if(this._sinks===e)this._sinks=null;else if(this._sinks!=null&&typeof this._sinks!="function")if(this._sinks.delete(e),this._sinks.size===1){let[t]=this._sinks;this._sinks=t}else this._sinks.size===0&&(this._sinks=null)}_activate(){if(this._deps.length===0){this._fn&&this._execFn();return}this._dirtyDepCount=0;let e=this._deps.length,t=0;try{for(let s=0;s<e;s++){let r=s,o=this._deps[s];o.unsub=Ce,o.unsub=o.node.subscribe(a=>{if(o.unsub===null)return;let i=this._config.tierOf,d=!1;for(let l of a)i(l[0])>=3&&(d=!0),this._config.onMessage(this,l,{direction:"down-in",depIndex:r},this._actions);d&&this._maybeRunFnOnSettlement()}),t++}}catch(s){this._deps[t].unsub=null;for(let r=0;r<t;r++){let o=this._deps[r];if(o.unsub!=null){let a=o.unsub;o.unsub=null;try{a()}catch{}we(o)}}throw this._dirtyDepCount=0,s}}_addDep(e){for(let r=0;r<this._deps.length;r++)if(this._deps[r].node===e)return r;let t=this._deps.length,s=Fe(e);if(this._deps.push(s),this._sinks==null)return t;s.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Z),s.unsub=Ce;try{s.unsub=e.subscribe(r=>{if(s.unsub===null)return;let o=this._config.tierOf,a=!1;for(let i of r)o(i[0])>=3&&(a=!0),this._config.onMessage(this,i,{direction:"down-in",depIndex:t},this._actions);a&&this._maybeRunFnOnSettlement()})}catch(r){throw s.unsub=null,this._deps.pop(),this._dirtyDepCount--,r}return t}_deactivate(e=!1){let t=this._cleanup;if(this._cleanup=void 0,typeof t=="function")try{t()}catch(s){this._emit([[p,this._wrapFnError("cleanup threw",s)]])}else if(t!=null&&typeof t=="object"){let s=t.deactivate;if(typeof s=="function")try{s()}catch(r){this._emit([[p,this._wrapFnError("cleanup.deactivate threw",r)]])}}for(let s of this._deps){if(s.unsub!=null){let r=s.unsub;s.unsub=null;try{r()}catch{}}we(s)}this._waveHasNewData=!1,this._hasNewTerminal=!1,this._hasCalledFnOnce=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._rerunDepth=0,this._store={},this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null,this._fn!=null&&(this._cached=void 0),e||(this._fn!=null||this._deps.length>0)&&(!this._isTerminal||this._resubscribable)&&(this._status="sentinel")}_onDepMessage(e,t){let s=this._deps[e],r=t[0];if(this._inspectorHooks!=null){let o={kind:"dep_message",depIndex:e,message:t};for(let a of this._inspectorHooks)a(o)}if(r!==C){if(r===w){this._depDirtied(s);return}if(r===T){if(this._depInvalidated(s),this._cached===void 0)return;this._emit(de);return}if(r===N||r===I){this._emit([t]);return}if(r===b){this._emit(Q);return}if(r===_)this._depSettledAsData(s,t[1]);else if(r===x)this._depSettledAsResolved(s);else if(r===A)this._depSettledAsTerminal(s,!0);else if(r===p)this._depSettledAsTerminal(s,t[1]);else{this._emit([t]);return}if(!this._fn){(r===_||r===x)&&this._emit([t]),(r===A||r===p)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Z))}_depSettledAsData(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.involvedThisWave=!0,e.dataBatch.push(t),this._waveHasNewData=!0}_depSettledAsResolved(e){e.dirty&&(e.dirty=!1,this._dirtyDepCount--)}_depSettledAsTerminal(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.terminal=t,e.involvedThisWave=!0,this._hasNewTerminal=!0}_depInvalidated(e){e.prevData=void 0,e.terminal=void 0,e.dataBatch.length=0,e.dirty?e.involvedThisWave=!1:(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++)}_maybeRunFnOnSettlement(){if(!(this._isTerminal&&!this._resubscribable)&&!(this._dirtyDepCount>0)){if(!this._partial&&!this._hasCalledFnOnce)for(let e=0;e<this._deps.length;e++){let t=this._deps[e];if(t.dataBatch.length===0&&t.prevData===void 0&&t.terminal===void 0){this._maybeAutoTerminalAfterWave();return}}if(this._paused){this._pendingWave=!0;return}if(!this._waveHasNewData&&!this._hasNewTerminal&&this._hasCalledFnOnce){this._clearWaveFlags(),this._emit(ae),this._maybeAutoTerminalAfterWave();return}this._fn&&this._execFn(),this._maybeAutoTerminalAfterWave()}}_maybeAutoTerminalAfterWave(){if(this._deps.length===0||this._isTerminal)return;let e=this._deps.find(t=>t.terminal!==void 0&&t.terminal!==!0);if(e!=null){this._autoError&&this._emit([[p,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.terminal!==void 0)&&this._emit(le)}_execFn(){if(!this._fn||this._isTerminal&&!this._resubscribable)return;if(this._isExecutingFn){this._pendingRerun=!0;return}let e=this._cleanup;if(typeof e=="function"){this._cleanup=void 0;try{e()}catch(a){this._emit([[p,this._wrapFnError("cleanup threw",a)]]);return}}else if(e!=null&&typeof e=="object"){let a=e.beforeRun;if(typeof a=="function"){e.beforeRun=void 0;try{a()}catch(i){this._emit([[p,this._wrapFnError("cleanup.beforeRun threw",i)]]);return}}}let t=this._deps.map(a=>a.involvedThisWave?a.dataBatch.length>0?[...a.dataBatch]:[]:void 0),s=this._deps.map(a=>a.prevData);for(let a=0;a<this._deps.length;a++){let i=t[a];i!=null&&i.length>0&&(this._deps[a].prevData=i[i.length-1])}let r=this._deps.map(a=>a.terminal),o={prevData:s,terminalDeps:r,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let a={kind:"run",batchData:t,prevData:s};for(let i of this._inspectorHooks)i(a)}this._isExecutingFn=!0;try{let a=this._fn(t,this._actions,o);if(typeof a=="function")this._cleanup=a;else if(a!=null&&typeof a=="object"){let i=a;(typeof i.beforeRun=="function"||typeof i.deactivate=="function"||typeof i.invalidate=="function")&&(this._cleanup=a)}}catch(a){this._emit([[p,this._wrapFnError("fn threw",a)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>Ie?(this._rerunDepth=0,this._emit([[p,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${Ie} \u2014 likely a reactive cycle`)]])):this._maybeRunFnOnSettlement()):this._rerunDepth=0,this._clearWaveFlags()}}_clearWaveFlags(){this._waveHasNewData=!1,this._hasNewTerminal=!1;for(let e of this._deps)e.involvedThisWave=!1,e.dataBatch.length=0}_wrapFnError(e,t){let s=t instanceof Error?t.message:String(t);return new Error(`Node "${this.name}": ${e}: ${s}`,{cause:t})}_frameBatch(e){let t=this._config.tierOf;if(e.length===1)return t(e[0][0])===3&&this._status!=="dirty"?[S,e[0]]:e;let s=!0,r=!1,o=!1,a=-1;for(let d of e){let l=t(d[0]);l<a&&(s=!1),l===3&&(r=!0),d[0]===w&&(o=!0),a=l}let i=e;if(!s){let d=e.map((l,c)=>({m:l,i:c,tier:t(l[0])}));d.sort((l,c)=>l.tier-c.tier||l.i-c.i),i=d.map(l=>l.m)}if(r&&!o&&this._status!=="dirty"){let d=0;for(;d<i.length&&t(i[d][0])===0;)d++;return d===0?[S,...i]:[...i.slice(0,d),S,...i.slice(d)]}return i}_emit(e){if(e.length===0)return;for(let i=0;i<e.length;i++){let d=e[i];if(d[0]===p&&d[1]===void 0)throw new TypeError('[ERROR, payload] requires a non-undefined payload (spec \xA71.2). Pass an Error object or domain tag instead \u2014 e.g. node.down([[ERROR, new Error("reason")]])')}let t=e;if(this._isTerminal&&!this._resubscribable){let i=e.filter(d=>d[0]===b||d[0]===T);if(i.length===0)return;t=i}t=this._frameBatch(t);let r=null;for(let i=0;i<t.length;i++){let d=t[i],l=d[0];if(l!==N&&l!==I){r?.push(d);continue}if(d.length<2)throw new Error(`Node "${this.name}": [[${l===N?"PAUSE":"RESUME"}]] must carry a lockId payload \u2014 bare PAUSE/RESUME is a protocol violation (C0 rule). Use \`[[PAUSE, lockId]]\` / \`[[RESUME, lockId]]\`.`);let c=!0;if(this._pausable!==!1){let u=d[1];if(l===N)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(u),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(u))c=!1;else if(this._pauseLocks.delete(u),this._pauseLocks.size===0){if(this._paused=!1,this._pauseBuffer!=null&&this._pauseBuffer.length>0){let g=this._pauseBuffer;this._pauseBuffer=[],this._emit(g)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}c?r?.push(d):r==null&&(r=t.slice(0,i))}if(r!=null){if(r.length===0)return;t=r}if(this._hasMeta&&t.some(i=>i[0]===b))for(let i of Object.keys(this.meta))try{this.meta[i]._emit(Q)}catch{}let{finalMessages:o,equalsError:a}=this._updateState(t);if(o.length>0&&this._config.inspectorEnabled){let i=this._config.globalInspector;if(i!=null)try{i({kind:"emit",node:this,messages:o})}catch{}}if(o.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let i=this._config.tierOf,d=[];for(let l of o)i(l[0])===3?this._pauseBuffer.push(l):d.push(l);d.length>0&&this._dispatchOrAccumulate(d)}else this._dispatchOrAccumulate(o);a!=null&&this._emit([[p,a]])}_updateState(e){let t=this._config.tierOf,s,r,o=-1,a=0;for(let c of e)t(c[0])===3&&a++;let i=a<=1,d=-1;if(this._versioning!=null&&a>1){for(let c=e.length-1;c>=0;c--)if(e[c][0]===_){d=c;break}}for(let c=0;c<e.length;c++){let u=e[c],g=u[0];if(g===_){if(u.length>=2){let f=!1;if(i&&this._cached!==void 0)try{f=this._equals(this._cached,u[1])}catch(v){r=this._wrapFnError("equals threw",v),o=c;break}if(f){s==null&&(s=e.slice(0,c)),s.push(J),this._status="resolved";continue}this._cached=u[1],this._versioning!=null&&(d<0||c===d)&&ue(this._versioning,u[1],this._hashFn)}this._status="settled",s?.push(u)}else if(s?.push(u),g===w)this._status="dirty";else if(g===x)this._status="resolved";else if(g===A)this._status="completed";else if(g===p)this._status="errored";else if(g===T){this._cached=void 0,this._status="dirty";let f=this._cleanup;if(typeof f=="function"){this._cleanup=void 0;try{f()}catch{}}else if(f!=null&&typeof f=="object"){let v=f.invalidate;if(typeof v=="function")try{v()}catch{}}}else g===b&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let l=o>=0?s??e.slice(0,o):s??e;return r!=null?{finalMessages:l,equalsError:r}:{finalMessages:l}}_deliverToSinks=e=>{if(this._sinks==null)return;if(typeof this._sinks=="function"){this._sinks(e);return}let t=[...this._sinks];for(let s of t)s(e)};_dispatchOrAccumulate(e){if(Ae()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],Ee(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}U(this._deliverToSinks,e,this._config.tierOf)}_flushBatchPending(){let e=this._batchPendingMessages;if(e===null||(this._batchPendingMessages=null,e.length===0))return;let t=this._frameBatch(e);U(this._deliverToSinks,t,this._config.tierOf)}},Ge=n=>Array.isArray(n),xe=n=>typeof n=="object"&&n!=null&&!Array.isArray(n);function L(n,e,t){let s=Ge(n)?n:[],r=typeof n=="function"?n:typeof e=="function"?e:void 0,o={};return Ge(n)?o=(xe(e)?e:t)??{}:xe(n)?o=n:o=(xe(e)?e:t)??{},new H(s,r,o)}function Le(n,e){if(e!=null&&e.length>0)return new Set(e);switch(n){case"standard":return new Set(["type","status","value","deps","meta","v"]);case"full":return null;default:return new Set(["type","deps"])}}function Ve(n,e){return L([],{...e,initial:n})}function Pe(n,e){return L((s,r,o)=>n(r,o)??void 0,{describeKind:"producer",...e})}function Te(n,e,t){return L(n,(r,o,a)=>{let i=r.map((d,l)=>d!=null&&d.length>0?d.at(-1):a.prevData[l]);o.emit(e(i,a))},{describeKind:"derived",...t})}function Ue(n,e,t){return L(n,(r,o,a)=>{let i=r.map((d,l)=>d!=null&&d.length>0?d.at(-1):a.prevData[l]);return e(i,o,a)??void 0},{describeKind:"effect",...t})}function We(n,e,t){let s=new Map;return n.forEach((r,o)=>{s.set(r,o)}),Te(n,(r,o)=>e(i=>{let d=s.get(i);if(d==null)throw new Error(`dynamicNode: untracked dep "${i.name??"<unnamed>"}"`);return r[d]},o),t)}function Be(n,e){let t,s=new Map,r=(o,a,i)=>{let d=!1,l=c=>{let u=s.get(c);if(u!==void 0){if(u<o.length){let f=o[u];return f!=null&&f.length>0?f.at(-1):i.prevData[u]}return c.cache}d=!0;let g=t._addDep(c);return s.set(c,g),c.cache};try{let c=n(l,i);d||(a.emit(c),i.store.__autoTrackLastDiscoveryError!=null&&delete i.store.__autoTrackLastDiscoveryError)}catch(c){if(!d)throw c;i.store.__autoTrackLastDiscoveryError=c}};return t=new H([],r,{describeKind:"derived",...e}),t}function je(n,...e){let t=n;for(let s of e)t=s(t);return t}0&&(module.exports={COMPLETE,COMPLETE_MSG,COMPLETE_ONLY_BATCH,DATA,DEFAULT_ACTOR,DIRTY,DIRTY_MSG,DIRTY_ONLY_BATCH,ERROR,GraphReFlyConfig,GuardDenied,INVALIDATE,INVALIDATE_MSG,INVALIDATE_ONLY_BATCH,NodeImpl,PAUSE,RESOLVED,RESOLVED_MSG,RESOLVED_ONLY_BATCH,RESUME,START,START_MSG,TEARDOWN,TEARDOWN_MSG,TEARDOWN_ONLY_BATCH,accessHintForGuard,advanceVersion,autoTrackNode,batch,configure,createVersioning,defaultConfig,defaultHash,derived,downWithBatch,dynamicNode,effect,isBatching,isV1,monotonicNs,node,normalizeActor,pipe,policy,policyFromRules,producer,registerBuiltins,resolveDescribeFields,state,wallClockNs});
@@ -1 +1 @@
1
- import"../chunk-Y32RJO24.js";import{a as X}from"../chunk-TWMEGG45.js";import{A as M,B as N,C as O,D as P,E as Q,F as R,G as S,H as T,I as U,J as V,K as W,i as v,j as w,k as x,m as y,n as z,o as A,p as B,q as C,r as D,s as E,t as F,u as G,v as H,w as I,x as J,y as K,z as L}from"../chunk-W4TSQ6RJ.js";import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u}from"../chunk-CK2E7BTU.js";import"../chunk-QYADASLV.js";export{i as COMPLETE,o as COMPLETE_MSG,t as COMPLETE_ONLY_BATCH,b as DATA,v as DEFAULT_ACTOR,c as DIRTY,k as DIRTY_MSG,q as DIRTY_ONLY_BATCH,j as ERROR,C as GraphReFlyConfig,E as GuardDenied,e as INVALIDATE,m as INVALIDATE_MSG,s as INVALIDATE_ONLY_BATCH,O as NodeImpl,f as PAUSE,d as RESOLVED,l as RESOLVED_MSG,r as RESOLVED_ONLY_BATCH,g as RESUME,a as START,n as START_MSG,h as TEARDOWN,p as TEARDOWN_MSG,u as TEARDOWN_ONLY_BATCH,H as accessHintForGuard,K as advanceVersion,V as autoTrackNode,y as batch,N as configure,J as createVersioning,M as defaultConfig,I as defaultHash,S as derived,z as downWithBatch,U as dynamicNode,T as effect,x as isBatching,L as isV1,A as monotonicNs,P as node,w as normalizeActor,W as pipe,F as policy,G as policyFromRules,R as producer,D as registerBuiltins,X as resolveDescribeFields,Q as state,B as wallClockNs};
1
+ import"../chunk-CZVYLXFK.js";import{a as X}from"../chunk-N2KKISCE.js";import{A as M,B as N,C as O,D as P,E as Q,F as R,G as S,H as T,I as U,J as V,K as W,i as v,j as w,k as x,m as y,n as z,o as A,p as B,q as C,r as D,s as E,t as F,u as G,v as H,w as I,x as J,y as K,z as L}from"../chunk-7AJKUA36.js";import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u}from"../chunk-CK2E7BTU.js";import"../chunk-QYADASLV.js";export{i as COMPLETE,o as COMPLETE_MSG,t as COMPLETE_ONLY_BATCH,b as DATA,v as DEFAULT_ACTOR,c as DIRTY,k as DIRTY_MSG,q as DIRTY_ONLY_BATCH,j as ERROR,C as GraphReFlyConfig,E as GuardDenied,e as INVALIDATE,m as INVALIDATE_MSG,s as INVALIDATE_ONLY_BATCH,O as NodeImpl,f as PAUSE,d as RESOLVED,l as RESOLVED_MSG,r as RESOLVED_ONLY_BATCH,g as RESUME,a as START,n as START_MSG,h as TEARDOWN,p as TEARDOWN_MSG,u as TEARDOWN_ONLY_BATCH,H as accessHintForGuard,K as advanceVersion,V as autoTrackNode,y as batch,N as configure,J as createVersioning,M as defaultConfig,I as defaultHash,S as derived,z as downWithBatch,U as dynamicNode,T as effect,x as isBatching,L as isV1,A as monotonicNs,P as node,w as normalizeActor,W as pipe,F as policy,G as policyFromRules,R as producer,D as registerBuiltins,X as resolveDescribeFields,Q as state,B as wallClockNs};
@@ -1 +1 @@
1
- "use strict";var K=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var Ie=Object.prototype.hasOwnProperty;var Fe=(n,e)=>{for(var t in e)K(n,t,{get:e[t],enumerable:!0})},Ge=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ce(e))!Ie.call(n,r)&&r!==t&&K(n,r,{get:()=>e[r],enumerable:!(s=Re(e,r))||s.enumerable});return n};var He=n=>Ge(K({},"__esModule",{value:!0}),n);var Ze={};Fe(Ze,{fromIDBRequest:()=>Ee,fromIDBTransaction:()=>Me,indexedDbStorage:()=>Se});module.exports=He(Ze);var G=Symbol.for("graphrefly/START"),_=Symbol.for("graphrefly/DATA"),k=Symbol.for("graphrefly/DIRTY"),E=Symbol.for("graphrefly/RESOLVED"),M=Symbol.for("graphrefly/INVALIDATE"),S=Symbol.for("graphrefly/PAUSE"),H=Symbol.for("graphrefly/RESUME"),N=Symbol.for("graphrefly/TEARDOWN"),v=Symbol.for("graphrefly/COMPLETE"),f=Symbol.for("graphrefly/ERROR"),D=Object.freeze([k]),J=Object.freeze([E]),Le=Object.freeze([M]),X=Object.freeze([G]),Ve=Object.freeze([v]),Pe=Object.freeze([N]),Z=Object.freeze([D]),le=Object.freeze([J]),ce=Object.freeze([Le]),ue=Object.freeze([Ve]),Q=Object.freeze([Pe]);var Be={name:"json",version:1,contentType:"application/json",encode(n){let e=JSON.stringify(n);return new TextEncoder().encode(e)},decode(n,e){let t=new TextDecoder().decode(n);return JSON.parse(t)}};function fe(n){n.registerCodec(Be)}var Ue={type:"system",id:""};function B(n){if(n==null)return Ue;let{type:e,id:t,...s}=n;return{type:e??"system",id:t??"",...s}}var ee=0,We=!1,he=[],pe=[],ge=[],je=[];function _e(){return ee>0||We}function ye(){return ee>0}function be(n){ee>0?je.push(n):n()}function U(n,e,t){if(e.length===0)return;if(e.length===1){let l=t(e[0][0]);if(l<3||!_e()){n(e);return}(l>=5?ge:l===4?pe:he).push(()=>n(e));return}let s=e.length,r=s,i=s,a=s,o=0;for(;o<s&&t(e[o][0])<3;)o++;for(r=o;o<s&&t(e[o][0])===3;)o++;for(i=o;o<s&&t(e[o][0])===4;)o++;a=o;let d=_e();if(r>0){let l=e.slice(0,r);n(l)}if(i>r){let l=e.slice(r,i);d?he.push(()=>n(l)):n(l)}if(a>i){let l=e.slice(i,a);d?pe.push(()=>n(l)):n(l)}if(s>a){let l=e.slice(a,s);d?ge.push(()=>n(l)):n(l)}}function me(){return Date.now()*1e6}var W=class{_messageTypes=new Map;_codecs=new Map;_onMessage;_onSubscribe;_defaultVersioning;_defaultHashFn;_inspectorEnabled=!(typeof process<"u"&&process.env?.NODE_ENV==="production");_globalInspector;_frozen=!1;tierOf;constructor(e){this._onMessage=e.onMessage,this._onSubscribe=e.onSubscribe,this._defaultVersioning=e.defaultVersioning,this._defaultHashFn=e.defaultHashFn,this.tierOf=t=>{let s=this._messageTypes.get(t);return s!=null?s.tier:1}}get onMessage(){return this._frozen=!0,this._onMessage}get onSubscribe(){return this._frozen=!0,this._onSubscribe}set onMessage(e){this._assertUnfrozen(),this._onMessage=e}set onSubscribe(e){this._assertUnfrozen(),this._onSubscribe=e}get defaultVersioning(){return this._defaultVersioning}set defaultVersioning(e){this._assertUnfrozen(),this._defaultVersioning=e}get defaultHashFn(){return this._defaultHashFn}set defaultHashFn(e){this._assertUnfrozen(),this._defaultHashFn=e}get inspectorEnabled(){return this._inspectorEnabled}set inspectorEnabled(e){this._inspectorEnabled=e}get globalInspector(){return this._globalInspector}set globalInspector(e){this._globalInspector=e}registerMessageType(e,t){return this._assertUnfrozen(),this._messageTypes.set(e,{tier:t.tier,wireCrossing:t.wireCrossing??t.tier>=3,metaPassthrough:t.metaPassthrough??!0}),this}messageTier(e){let t=this._messageTypes.get(e);return t!=null?t.tier:1}isWireCrossing(e){let t=this._messageTypes.get(e);return t!=null?t.wireCrossing:!0}isLocalOnly(e){return!this.isWireCrossing(e)}isMetaPassthrough(e){let t=this._messageTypes.get(e);return t!=null?t.metaPassthrough:!0}isKnownMessageType(e){return this._messageTypes.has(e)}registerCodec(e){return this._assertUnfrozen(),this._codecs.set(e.name,e),this}lookupCodec(e){return this._codecs.get(e)}_isFrozen(){return this._frozen}_assertUnfrozen(){if(this._frozen)throw new Error("GraphReFlyConfig is frozen: a node has already captured this config. Register custom types and set hooks before creating any node.")}};function ve(n){n.registerMessageType(G,{tier:0,wireCrossing:!1}),n.registerMessageType(k,{tier:1,wireCrossing:!1}),n.registerMessageType(M,{tier:1,wireCrossing:!1,metaPassthrough:!1}),n.registerMessageType(S,{tier:2,wireCrossing:!1}),n.registerMessageType(H,{tier:2,wireCrossing:!1}),n.registerMessageType(_,{tier:3,wireCrossing:!0}),n.registerMessageType(E,{tier:3,wireCrossing:!0}),n.registerMessageType(v,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(f,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(N,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var O=class extends Error{actor;action;nodeName;constructor(e,t){super(t??`GuardDenied: action "${String(e.action)}" denied for actor type "${String(e.actor.type)}"`),this.name="GuardDenied",this.actor=e.actor,this.action=e.action,this.nodeName=e.nodeName}get node(){return this.nodeName}};function te(n){if(n===void 0)return null;if(typeof n=="number"){if(!Number.isFinite(n))throw new TypeError(`Cannot hash non-finite number: ${n}`);if(Number.isInteger(n)&&!Number.isSafeInteger(n))throw new TypeError(`Cannot hash integer outside safe range (|n| > 2^53-1): ${n}. Cross-language cid parity is not guaranteed for unsafe integers.`);return n}if(typeof n=="string"||typeof n=="boolean"||n===null)return n;if(Array.isArray(n))return n.map(te);if(typeof n=="object"&&n!==null){let e={};for(let t of Object.keys(n).sort())e[t]=te(n[t]);return e}return null}var ze=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),$e=new TextEncoder;function qe(n){let e=$e.encode(n),t=e.length,s=t*8,r=t+9+63&-64,i=new Uint8Array(r);i.set(e),i[t]=128;let a=new DataView(i.buffer);a.setUint32(r-4,s>>>0,!1),a.setUint32(r-8,Math.floor(s/4294967296)>>>0,!1);let o=1779033703,d=3144134277,l=1013904242,c=2773480762,u=1359893119,h=2600822924,g=528734635,y=1541459225,A=new Uint32Array(64),m=(x,b)=>x>>>b|x<<32-b;for(let x=0;x<r;x+=64){for(let p=0;p<16;p++)A[p]=a.getUint32(x+p*4,!1);for(let p=16;p<64;p++){let I=A[p-15],F=A[p-2],P=m(I,7)^m(I,18)^I>>>3,Y=m(F,17)^m(F,19)^F>>>10;A[p]=A[p-16]+P+A[p-7]+Y>>>0}let b=o,R=d,C=l,$=c,T=u,L=h,V=g,q=y;for(let p=0;p<64;p++){let I=m(T,6)^m(T,11)^m(T,25),F=T&L^~T&V,P=q+I+F+ze[p]+A[p]>>>0,Y=m(b,2)^m(b,13)^m(b,22),De=b&R^b&C^R&C,Oe=Y+De>>>0;q=V,V=L,L=T,T=$+P>>>0,$=C,C=R,R=b,b=P+Oe>>>0}o=o+b>>>0,d=d+R>>>0,l=l+C>>>0,c=c+$>>>0,u=u+T>>>0,h=h+L>>>0,g=g+V>>>0,y=y+q>>>0}let w=x=>x.toString(16).padStart(8,"0");return w(o)+w(d)+w(l)+w(c)+w(u)+w(h)+w(g)+w(y)}function ne(n){let e=te(n??null),t=JSON.stringify(e);return qe(t).slice(0,16)}function Ye(){let n=globalThis.crypto;if(n?.randomUUID)return n.randomUUID();let e=()=>Math.floor(Math.random()*4294967296).toString(16).padStart(8,"0"),t=e()+e()+e()+e();return`${t.slice(0,8)}-${t.slice(8,12)}-4${t.slice(13,16)}-${(parseInt(t.slice(16,17),16)&3|8).toString(16)}${t.slice(17,20)}-${t.slice(20,32)}`}function se(n,e,t){let s=t?.id??Ye();if(n===0)return{id:s,version:0};let i=(t?.hash??ne)(e);return{id:s,version:0,cid:i,prev:null}}function we(n,e,t){n.version+=1,"cid"in n&&(n.prev=n.cid,n.cid=t(e))}var xe=()=>{},Te=100;function Ne(n){return{node:n,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function re(n){n.prevData=void 0,n.dirty=!1,n.involvedThisWave=!1,n.dataBatch.length=0,n.terminal=void 0}function j(n){return n.length===0?n:typeof n[0]=="symbol"?[n]:n}var Ke=(n,e,t,s)=>{t.direction==="down-in"&&n._onDepMessage(t.depIndex,e)},Je=(n,e,t,s)=>{let r=n;if(r._status==="completed"||r._status==="errored")return;let i=r._cached,a=i===void 0?[X]:[X,[_,i]];r._status==="dirty"&&a.push(D),U(e,a,r._config.tierOf)},ie=new W({onMessage:Ke,onSubscribe:Je});ve(ie);fe(ie);var z=class n{_optsName;_describeKind;meta;_hasMeta;_config;_deps;_sinks=null;_sinkCount=0;_cached;_status;_cleanup;_store={};_waveHasNewData=!1;_hasNewTerminal=!1;_hasCalledFnOnce=!1;_paused=!1;_pendingWave=!1;_isExecutingFn=!1;_pendingRerun=!1;_rerunDepth=0;_dirtyDepCount=0;_batchPendingMessages=null;_pauseLocks=null;_pauseBuffer=null;_fn;_equals;_resubscribable;_resetOnTeardown;_autoComplete;_autoError;_pausable;_partial;_guard;_extraGuards;_hashFn;_versioning;_versioningLevel;_lastMutation;_inspectorHooks;_actions;constructor(e,t,s){this._config=s.config??ie,this._config.onMessage,this._optsName=s.name,this._describeKind=s.describeKind,this._equals=s.equals??Object.is,this._resubscribable=s.resubscribable??!1,this._resetOnTeardown=s.resetOnTeardown??!1,this._autoComplete=s.completeWhenDepsComplete??!0,this._autoError=s.errorWhenDepsError??!0,this._pausable=s.pausable??!0,this._guard=s.guard,this._fn=t,this._partial=s.partial??!1,this._cached=s.initial!==void 0?s.initial:void 0,this._status=e.length===0&&t==null&&this._cached!==void 0?"settled":"sentinel",this._hashFn=s.versioningHash??this._config.defaultHashFn??ne;let r=s.versioning??this._config.defaultVersioning;this._versioningLevel=r,this._versioning=r!=null?se(r,this._cached===void 0?void 0:this._cached,{id:s.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(Ne);let i={};for(let[o,d]of Object.entries(s.meta??{})){let l={initial:d,name:`${s.name??"node"}:meta:${o}`,describeKind:"state",config:this._config};s.guard!=null&&(l.guard=s.guard),i[o]=new n([],void 0,l)}Object.freeze(i),this.meta=i,this._hasMeta=Object.keys(i).length>0;let a=this;this._actions={emit(o){a._emit([[_,o]])},down(o){a._emit(j(o))},up(o){a._emitUp(j(o))}},this.down=this.down.bind(this),this.up=this.up.bind(this)}get _isTerminal(){return this._status==="completed"||this._status==="errored"}get name(){return this._optsName}get status(){return this._status}get cache(){return this._cached===void 0?void 0:this._cached}get lastMutation(){return this._lastMutation}get v(){return this._versioning}hasGuard(){return this._guard!=null}_applyVersioning(e,t){if(this._isExecutingFn)throw new Error(`Node "${this.name}": _applyVersioning cannot run mid-fn \u2014 call it outside of \`_execFn\` (typically at graph setup time before the first subscribe).`);let s=this._versioningLevel;if(s!=null&&e<=s)return;let r=t?.hash??this._hashFn;r!==this._hashFn&&(this._hashFn=r);let i=this._cached===void 0?void 0:this._cached,a=this._versioning,o=a?.id??t?.id,d=a?.version??0,l=se(e,i,{id:o,hash:r});l.version=d,this._versioning=l,this._versioningLevel=e}_setInspectorHook(e){return e==null?()=>{}:(this._inspectorHooks==null&&(this._inspectorHooks=new Set),this._inspectorHooks.add(e),()=>{this._inspectorHooks?.delete(e),this._inspectorHooks?.size===0&&(this._inspectorHooks=void 0)})}_pushGuard(e){return this._extraGuards==null&&(this._extraGuards=new Set),this._extraGuards.add(e),()=>{this._extraGuards?.delete(e),this._extraGuards?.size===0&&(this._extraGuards=void 0)}}allowsObserve(e){if(this._guard==null&&this._extraGuards==null)return!0;let t=B(e);if(this._guard!=null&&!this._guard(t,"observe"))return!1;if(this._extraGuards!=null){for(let s of this._extraGuards)if(!s(t,"observe"))return!1}return!0}_checkGuard(e){if(e?.internal)return;let t=this._guard!=null||this._extraGuards!=null,s=e?.actor!=null;if(!t&&!s)return;let r=B(e?.actor),i=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(r,i))throw new O({actor:r,action:i,nodeName:this.name});if(this._extraGuards!=null){for(let a of this._extraGuards)if(!a(r,i))throw new O({actor:r,action:i,nodeName:this.name})}this._lastMutation={actor:r,timestamp_ns:me()}}down(e,t){let s=j(e);s.length!==0&&(this._checkGuard(t),this._emit(s))}emit(e,t){this._checkGuard(t),this._emit([[_,e]])}up(e,t){if(this._deps.length===0)return;let s=j(e);if(s.length===0)return;this._checkGuard(t);let r=t??{internal:!0};this._validateUpTiers(s);for(let i of this._deps)i.node.up?.(s,r)}_emitUp(e){if(this._deps.length!==0&&e.length!==0){this._validateUpTiers(e);for(let t of this._deps)t.node.up?.(e,{internal:!0})}}_validateUpTiers(e){let t=this._config.tierOf;for(let s of e){let r=t(s[0]);if(r===3||r===4)throw new Error(`Node "${this.name}": tier-${r} messages cannot flow up \u2014 DATA/RESOLVED/COMPLETE/ERROR are downstream-only. Use \`down(...)\` for value delivery; \`up(...)\` is for control signals (DIRTY, INVALIDATE, PAUSE, RESUME, TEARDOWN).`)}}subscribe(e,t){if(t!=null&&this._guard!=null){let d=B(t);if(!this._guard(d,"observe"))throw new O({actor:d,action:"observe",nodeName:this.name})}let r=this._isTerminal&&this._resubscribable;if(r){this._cached=void 0,this._status="sentinel",this._store={},this._hasCalledFnOnce=!1,this._waveHasNewData=!1,this._hasNewTerminal=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._isExecutingFn=!1,this._rerunDepth=0,this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null;for(let d of this._deps)re(d);if(this._partial===!1){for(let d of this._deps)if(d.prevData!==void 0||d.dataBatch.length!==0||d.terminal!==void 0||d.dirty)throw new Error(`resubscribable-reset invariant: DepRecord not fully reset for node ${this._optsName??"(anonymous)"}`)}}this._sinkCount+=1;let i;try{i=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:r},this._actions)}catch(d){throw this._sinkCount-=1,d}this._sinks==null?this._sinks=e:typeof this._sinks=="function"?this._sinks=new Set([this._sinks,e]):this._sinks.add(e);let a=this._isTerminal;if(this._sinkCount===1&&!a)try{this._activate()}catch(d){if(this._sinkCount-=1,this._removeSink(e),this._sinkCount===0&&(this._status="sentinel"),typeof i=="function")try{i()}catch{}throw d}this._status==="sentinel"&&this._cached===void 0&&(this._status="pending");let o=!1;return()=>{o||(o=!0,this._sinkCount-=1,this._removeSink(e),typeof i=="function"&&i(),this._sinks==null&&this._deactivate())}}_removeSink(e){if(this._sinks===e)this._sinks=null;else if(this._sinks!=null&&typeof this._sinks!="function")if(this._sinks.delete(e),this._sinks.size===1){let[t]=this._sinks;this._sinks=t}else this._sinks.size===0&&(this._sinks=null)}_activate(){if(this._deps.length===0){this._fn&&this._execFn();return}this._dirtyDepCount=0;let e=this._deps.length,t=0;try{for(let s=0;s<e;s++){let r=s,i=this._deps[s];i.unsub=xe,i.unsub=i.node.subscribe(a=>{if(i.unsub===null)return;let o=this._config.tierOf,d=!1;for(let l of a)o(l[0])>=3&&(d=!0),this._config.onMessage(this,l,{direction:"down-in",depIndex:r},this._actions);d&&this._maybeRunFnOnSettlement()}),t++}}catch(s){this._deps[t].unsub=null;for(let r=0;r<t;r++){let i=this._deps[r];if(i.unsub!=null){let a=i.unsub;i.unsub=null;try{a()}catch{}re(i)}}throw this._dirtyDepCount=0,s}}_addDep(e){for(let r=0;r<this._deps.length;r++)if(this._deps[r].node===e)return r;let t=this._deps.length,s=Ne(e);if(this._deps.push(s),this._sinks==null)return t;s.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Z),s.unsub=xe;try{s.unsub=e.subscribe(r=>{if(s.unsub===null)return;let i=this._config.tierOf,a=!1;for(let o of r)i(o[0])>=3&&(a=!0),this._config.onMessage(this,o,{direction:"down-in",depIndex:t},this._actions);a&&this._maybeRunFnOnSettlement()})}catch(r){throw s.unsub=null,this._deps.pop(),this._dirtyDepCount--,r}return t}_deactivate(e=!1){let t=this._cleanup;if(this._cleanup=void 0,typeof t=="function")try{t()}catch(s){this._emit([[f,this._wrapFnError("cleanup threw",s)]])}else if(t!=null&&typeof t=="object"){let s=t.deactivate;if(typeof s=="function")try{s()}catch(r){this._emit([[f,this._wrapFnError("cleanup.deactivate threw",r)]])}}for(let s of this._deps){if(s.unsub!=null){let r=s.unsub;s.unsub=null;try{r()}catch{}}re(s)}this._waveHasNewData=!1,this._hasNewTerminal=!1,this._hasCalledFnOnce=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._rerunDepth=0,this._store={},this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null,this._fn!=null&&(this._cached=void 0),e||(this._fn!=null||this._deps.length>0)&&(!this._isTerminal||this._resubscribable)&&(this._status="sentinel")}_onDepMessage(e,t){let s=this._deps[e],r=t[0];if(this._inspectorHooks!=null){let i={kind:"dep_message",depIndex:e,message:t};for(let a of this._inspectorHooks)a(i)}if(r!==G){if(r===k){this._depDirtied(s);return}if(r===M){this._depInvalidated(s),this._emit(ce);return}if(r===S||r===H){this._emit([t]);return}if(r===N){this._emit(Q);return}if(r===_)this._depSettledAsData(s,t[1]);else if(r===E)this._depSettledAsResolved(s);else if(r===v)this._depSettledAsTerminal(s,!0);else if(r===f)this._depSettledAsTerminal(s,t[1]);else{this._emit([t]);return}if(!this._fn){(r===_||r===E)&&this._emit([t]),(r===v||r===f)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Z))}_depSettledAsData(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.involvedThisWave=!0,e.dataBatch.push(t),this._waveHasNewData=!0}_depSettledAsResolved(e){e.dirty&&(e.dirty=!1,this._dirtyDepCount--)}_depSettledAsTerminal(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.terminal=t,e.involvedThisWave=!0,this._hasNewTerminal=!0}_depInvalidated(e){e.prevData=void 0,e.terminal=void 0,e.dataBatch.length=0,e.dirty?e.involvedThisWave=!1:(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++)}_maybeRunFnOnSettlement(){if(!(this._isTerminal&&!this._resubscribable)&&!(this._dirtyDepCount>0)){if(!this._partial&&!this._hasCalledFnOnce)for(let e=0;e<this._deps.length;e++){let t=this._deps[e];if(t.dataBatch.length===0&&t.prevData===void 0&&t.terminal===void 0){this._maybeAutoTerminalAfterWave();return}}if(this._paused){this._pendingWave=!0;return}if(!this._waveHasNewData&&!this._hasNewTerminal&&this._hasCalledFnOnce){this._clearWaveFlags(),this._emit(le),this._maybeAutoTerminalAfterWave();return}this._fn&&this._execFn(),this._maybeAutoTerminalAfterWave()}}_maybeAutoTerminalAfterWave(){if(this._deps.length===0||this._isTerminal)return;let e=this._deps.find(t=>t.terminal!==void 0&&t.terminal!==!0);if(e!=null){this._autoError&&this._emit([[f,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.terminal!==void 0)&&this._emit(ue)}_execFn(){if(!this._fn||this._isTerminal&&!this._resubscribable)return;if(this._isExecutingFn){this._pendingRerun=!0;return}let e=this._cleanup;if(typeof e=="function"){this._cleanup=void 0;try{e()}catch(a){this._emit([[f,this._wrapFnError("cleanup threw",a)]]);return}}else if(e!=null&&typeof e=="object"){let a=e.beforeRun;if(typeof a=="function"){e.beforeRun=void 0;try{a()}catch(o){this._emit([[f,this._wrapFnError("cleanup.beforeRun threw",o)]]);return}}}let t=this._deps.map(a=>a.involvedThisWave?a.dataBatch.length>0?[...a.dataBatch]:[]:void 0),s=this._deps.map(a=>a.prevData);for(let a=0;a<this._deps.length;a++){let o=t[a];o!=null&&o.length>0&&(this._deps[a].prevData=o[o.length-1])}let r=this._deps.map(a=>a.terminal),i={prevData:s,terminalDeps:r,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let a={kind:"run",batchData:t,prevData:s};for(let o of this._inspectorHooks)o(a)}this._isExecutingFn=!0;try{let a=this._fn(t,this._actions,i);if(typeof a=="function")this._cleanup=a;else if(a!=null&&typeof a=="object"){let o=a;(typeof o.beforeRun=="function"||typeof o.deactivate=="function"||typeof o.invalidate=="function")&&(this._cleanup=a)}}catch(a){this._emit([[f,this._wrapFnError("fn threw",a)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>Te?(this._rerunDepth=0,this._emit([[f,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${Te} \u2014 likely a reactive cycle`)]])):this._maybeRunFnOnSettlement()):this._rerunDepth=0,this._clearWaveFlags()}}_clearWaveFlags(){this._waveHasNewData=!1,this._hasNewTerminal=!1;for(let e of this._deps)e.involvedThisWave=!1,e.dataBatch.length=0}_wrapFnError(e,t){let s=t instanceof Error?t.message:String(t);return new Error(`Node "${this.name}": ${e}: ${s}`,{cause:t})}_frameBatch(e){let t=this._config.tierOf;if(e.length===1)return t(e[0][0])===3&&this._status!=="dirty"?[D,e[0]]:e;let s=!0,r=!1,i=!1,a=-1;for(let d of e){let l=t(d[0]);l<a&&(s=!1),l===3&&(r=!0),d[0]===k&&(i=!0),a=l}let o=e;if(!s){let d=e.map((l,c)=>({m:l,i:c,tier:t(l[0])}));d.sort((l,c)=>l.tier-c.tier||l.i-c.i),o=d.map(l=>l.m)}if(r&&!i&&this._status!=="dirty"){let d=0;for(;d<o.length&&t(o[d][0])===0;)d++;return d===0?[D,...o]:[...o.slice(0,d),D,...o.slice(d)]}return o}_emit(e){if(e.length===0)return;for(let o=0;o<e.length;o++){let d=e[o];if(d[0]===f&&d[1]===void 0)throw new TypeError('[ERROR, payload] requires a non-undefined payload (spec \xA71.2). Pass an Error object or domain tag instead \u2014 e.g. node.down([[ERROR, new Error("reason")]])')}let t=e;if(this._isTerminal&&!this._resubscribable){let o=e.filter(d=>d[0]===N||d[0]===M);if(o.length===0)return;t=o}t=this._frameBatch(t);let r=null;for(let o=0;o<t.length;o++){let d=t[o],l=d[0];if(l!==S&&l!==H){r?.push(d);continue}if(d.length<2)throw new Error(`Node "${this.name}": [[${l===S?"PAUSE":"RESUME"}]] must carry a lockId payload \u2014 bare PAUSE/RESUME is a protocol violation (C0 rule). Use \`[[PAUSE, lockId]]\` / \`[[RESUME, lockId]]\`.`);let c=!0;if(this._pausable!==!1){let u=d[1];if(l===S)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(u),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(u))c=!1;else if(this._pauseLocks.delete(u),this._pauseLocks.size===0){if(this._paused=!1,this._pauseBuffer!=null&&this._pauseBuffer.length>0){let h=this._pauseBuffer;this._pauseBuffer=[],this._emit(h)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}c?r?.push(d):r==null&&(r=t.slice(0,o))}if(r!=null){if(r.length===0)return;t=r}if(this._hasMeta&&t.some(o=>o[0]===N))for(let o of Object.keys(this.meta))try{this.meta[o]._emit(Q)}catch{}let{finalMessages:i,equalsError:a}=this._updateState(t);if(i.length>0&&this._config.inspectorEnabled){let o=this._config.globalInspector;if(o!=null)try{o({kind:"emit",node:this,messages:i})}catch{}}if(i.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let o=this._config.tierOf,d=[];for(let l of i)o(l[0])===3?this._pauseBuffer.push(l):d.push(l);d.length>0&&this._dispatchOrAccumulate(d)}else this._dispatchOrAccumulate(i);a!=null&&this._emit([[f,a]])}_updateState(e){let t=this._config.tierOf,s,r,i=-1,a=0;for(let c of e)t(c[0])===3&&a++;let o=a<=1,d=-1;if(this._versioning!=null&&a>1){for(let c=e.length-1;c>=0;c--)if(e[c][0]===_){d=c;break}}for(let c=0;c<e.length;c++){let u=e[c],h=u[0];if(h===_){if(u.length>=2){let g=!1;if(o&&this._cached!==void 0)try{g=this._equals(this._cached,u[1])}catch(y){r=this._wrapFnError("equals threw",y),i=c;break}if(g){s==null&&(s=e.slice(0,c)),s.push(J),this._status="resolved";continue}this._cached=u[1],this._versioning!=null&&(d<0||c===d)&&we(this._versioning,u[1],this._hashFn)}this._status="settled",s?.push(u)}else if(s?.push(u),h===k)this._status="dirty";else if(h===E)this._status="resolved";else if(h===v)this._status="completed";else if(h===f)this._status="errored";else if(h===M){this._cached=void 0,this._status="dirty";let g=this._cleanup;if(typeof g=="function"){this._cleanup=void 0;try{g()}catch{}}else if(g!=null&&typeof g=="object"){let y=g.invalidate;if(typeof y=="function")try{y()}catch{}}}else h===N&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let l=i>=0?s??e.slice(0,i):s??e;return r!=null?{finalMessages:l,equalsError:r}:{finalMessages:l}}_deliverToSinks=e=>{if(this._sinks==null)return;if(typeof this._sinks=="function"){this._sinks(e);return}let t=[...this._sinks];for(let s of t)s(e)};_dispatchOrAccumulate(e){if(ye()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],be(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}U(this._deliverToSinks,e,this._config.tierOf)}_flushBatchPending(){let e=this._batchPendingMessages;if(e===null||(this._batchPendingMessages=null,e.length===0))return;let t=this._frameBatch(e);U(this._deliverToSinks,t,this._config.tierOf)}},Ae=n=>Array.isArray(n),oe=n=>typeof n=="object"&&n!=null&&!Array.isArray(n);function ke(n,e,t){let s=Ae(n)?n:[],r=typeof n=="function"?n:typeof e=="function"?e:void 0,i={};return Ae(n)?i=(oe(e)?e:t)??{}:oe(n)?i=n:i=(oe(e)?e:t)??{},new z(s,r,i)}function ae(n,e){return ke((s,r,i)=>n(r,i)??void 0,{describeKind:"producer",...e})}function Ee(n){return ae(e=>{let t=!1,s=()=>{n.onsuccess=null,n.onerror=null};return n.onsuccess=()=>{t||(t=!0,s(),e.down([[_,n.result],[v]]))},n.onerror=()=>{t||(t=!0,s(),e.down([[f,n.error??new Error("IndexedDB request failed")]]))},()=>{t=!0,s()}})}function Me(n){return ae(e=>{let t=!1,s=()=>{n.oncomplete=null,n.onerror=null,n.onabort=null};return n.oncomplete=()=>{t||(t=!0,s(),e.down([[_,void 0],[v]]))},n.onerror=()=>{t||(t=!0,s(),e.down([[f,n.error??new Error("IndexedDB transaction failed")]]))},n.onabort=()=>{t||(t=!0,s(),e.down([[f,n.error??new Error("IndexedDB transaction aborted")]]))},()=>{t=!0,s()}})}function Xe(n,e,t){return new Promise((s,r)=>{if(typeof indexedDB>"u"){r(new TypeError("indexedDB is not available in this environment"));return}let i=indexedDB.open(n,t);i.onupgradeneeded=()=>{let a=i.result;a.objectStoreNames.contains(e)||a.createObjectStore(e)},i.onsuccess=()=>s(i.result),i.onerror=()=>r(i.error??new Error("IndexedDB open failed"))})}function de(n,e,t,s,r){return Xe(n,e,t).then(i=>new Promise((a,o)=>{let d=i.transaction(e,s),l=d.objectStore(e),c=r(l),u,h=!1,g=!1,y=()=>{!h||!g||(i.close(),a(u))};c.onsuccess=()=>{u=c.result,h=!0,y()},c.onerror=()=>{i.close(),o(c.error??new Error("IndexedDB request failed"))},d.oncomplete=()=>{if(g=!0,!h){i.close(),o(new Error("IndexedDB transaction completed without request result"));return}y()},d.onerror=()=>{i.close(),o(d.error??new Error("IndexedDB transaction failed"))},d.onabort=()=>{i.close(),o(d.error??new Error("IndexedDB transaction aborted"))}}))}function Se(n){let{dbName:e,storeName:t}=n,s=n.version??1,r=n.key??"graphrefly_checkpoint";return{async save(i,a){await de(e,t,s,"readwrite",o=>o.put(a,r))},async load(i){let a=await de(e,t,s,"readonly",o=>o.get(r));return a==null||typeof a!="object"||Array.isArray(a)?null:a},async clear(i){await de(e,t,s,"readwrite",a=>a.delete(r))}}}0&&(module.exports={fromIDBRequest,fromIDBTransaction,indexedDbStorage});
1
+ "use strict";var K=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var Ie=Object.prototype.hasOwnProperty;var Fe=(n,e)=>{for(var t in e)K(n,t,{get:e[t],enumerable:!0})},Ge=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ce(e))!Ie.call(n,r)&&r!==t&&K(n,r,{get:()=>e[r],enumerable:!(s=Re(e,r))||s.enumerable});return n};var He=n=>Ge(K({},"__esModule",{value:!0}),n);var Ze={};Fe(Ze,{fromIDBRequest:()=>Ee,fromIDBTransaction:()=>Me,indexedDbStorage:()=>Se});module.exports=He(Ze);var G=Symbol.for("graphrefly/START"),_=Symbol.for("graphrefly/DATA"),k=Symbol.for("graphrefly/DIRTY"),E=Symbol.for("graphrefly/RESOLVED"),M=Symbol.for("graphrefly/INVALIDATE"),S=Symbol.for("graphrefly/PAUSE"),H=Symbol.for("graphrefly/RESUME"),N=Symbol.for("graphrefly/TEARDOWN"),v=Symbol.for("graphrefly/COMPLETE"),f=Symbol.for("graphrefly/ERROR"),D=Object.freeze([k]),J=Object.freeze([E]),Le=Object.freeze([M]),X=Object.freeze([G]),Ve=Object.freeze([v]),Pe=Object.freeze([N]),Z=Object.freeze([D]),le=Object.freeze([J]),ce=Object.freeze([Le]),ue=Object.freeze([Ve]),Q=Object.freeze([Pe]);var Be={name:"json",version:1,contentType:"application/json",encode(n){let e=JSON.stringify(n);return new TextEncoder().encode(e)},decode(n,e){let t=new TextDecoder().decode(n);return JSON.parse(t)}};function fe(n){n.registerCodec(Be)}var Ue={type:"system",id:""};function B(n){if(n==null)return Ue;let{type:e,id:t,...s}=n;return{type:e??"system",id:t??"",...s}}var ee=0,We=!1,he=[],pe=[],ge=[],je=[];function _e(){return ee>0||We}function ye(){return ee>0}function be(n){ee>0?je.push(n):n()}function U(n,e,t){if(e.length===0)return;if(e.length===1){let l=t(e[0][0]);if(l<3||!_e()){n(e);return}(l>=5?ge:l===4?pe:he).push(()=>n(e));return}let s=e.length,r=s,i=s,a=s,o=0;for(;o<s&&t(e[o][0])<3;)o++;for(r=o;o<s&&t(e[o][0])===3;)o++;for(i=o;o<s&&t(e[o][0])===4;)o++;a=o;let d=_e();if(r>0){let l=e.slice(0,r);n(l)}if(i>r){let l=e.slice(r,i);d?he.push(()=>n(l)):n(l)}if(a>i){let l=e.slice(i,a);d?pe.push(()=>n(l)):n(l)}if(s>a){let l=e.slice(a,s);d?ge.push(()=>n(l)):n(l)}}function me(){return Date.now()*1e6}var W=class{_messageTypes=new Map;_codecs=new Map;_onMessage;_onSubscribe;_defaultVersioning;_defaultHashFn;_inspectorEnabled=!(typeof process<"u"&&process.env?.NODE_ENV==="production");_globalInspector;_frozen=!1;tierOf;constructor(e){this._onMessage=e.onMessage,this._onSubscribe=e.onSubscribe,this._defaultVersioning=e.defaultVersioning,this._defaultHashFn=e.defaultHashFn,this.tierOf=t=>{let s=this._messageTypes.get(t);return s!=null?s.tier:1}}get onMessage(){return this._frozen=!0,this._onMessage}get onSubscribe(){return this._frozen=!0,this._onSubscribe}set onMessage(e){this._assertUnfrozen(),this._onMessage=e}set onSubscribe(e){this._assertUnfrozen(),this._onSubscribe=e}get defaultVersioning(){return this._defaultVersioning}set defaultVersioning(e){this._assertUnfrozen(),this._defaultVersioning=e}get defaultHashFn(){return this._defaultHashFn}set defaultHashFn(e){this._assertUnfrozen(),this._defaultHashFn=e}get inspectorEnabled(){return this._inspectorEnabled}set inspectorEnabled(e){this._inspectorEnabled=e}get globalInspector(){return this._globalInspector}set globalInspector(e){this._globalInspector=e}registerMessageType(e,t){return this._assertUnfrozen(),this._messageTypes.set(e,{tier:t.tier,wireCrossing:t.wireCrossing??t.tier>=3,metaPassthrough:t.metaPassthrough??!0}),this}messageTier(e){let t=this._messageTypes.get(e);return t!=null?t.tier:1}isWireCrossing(e){let t=this._messageTypes.get(e);return t!=null?t.wireCrossing:!0}isLocalOnly(e){return!this.isWireCrossing(e)}isMetaPassthrough(e){let t=this._messageTypes.get(e);return t!=null?t.metaPassthrough:!0}isKnownMessageType(e){return this._messageTypes.has(e)}registerCodec(e){return this._assertUnfrozen(),this._codecs.set(e.name,e),this}lookupCodec(e){return this._codecs.get(e)}_isFrozen(){return this._frozen}_assertUnfrozen(){if(this._frozen)throw new Error("GraphReFlyConfig is frozen: a node has already captured this config. Register custom types and set hooks before creating any node.")}};function ve(n){n.registerMessageType(G,{tier:0,wireCrossing:!1}),n.registerMessageType(k,{tier:1,wireCrossing:!1}),n.registerMessageType(M,{tier:1,wireCrossing:!1,metaPassthrough:!1}),n.registerMessageType(S,{tier:2,wireCrossing:!1}),n.registerMessageType(H,{tier:2,wireCrossing:!1}),n.registerMessageType(_,{tier:3,wireCrossing:!0}),n.registerMessageType(E,{tier:3,wireCrossing:!0}),n.registerMessageType(v,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(f,{tier:4,wireCrossing:!0,metaPassthrough:!1}),n.registerMessageType(N,{tier:5,wireCrossing:!0,metaPassthrough:!1})}var O=class extends Error{actor;action;nodeName;constructor(e,t){super(t??`GuardDenied: action "${String(e.action)}" denied for actor type "${String(e.actor.type)}"`),this.name="GuardDenied",this.actor=e.actor,this.action=e.action,this.nodeName=e.nodeName}get node(){return this.nodeName}};function te(n){if(n===void 0)return null;if(typeof n=="number"){if(!Number.isFinite(n))throw new TypeError(`Cannot hash non-finite number: ${n}`);if(Number.isInteger(n)&&!Number.isSafeInteger(n))throw new TypeError(`Cannot hash integer outside safe range (|n| > 2^53-1): ${n}. Cross-language cid parity is not guaranteed for unsafe integers.`);return n}if(typeof n=="string"||typeof n=="boolean"||n===null)return n;if(Array.isArray(n))return n.map(te);if(typeof n=="object"&&n!==null){let e={};for(let t of Object.keys(n).sort())e[t]=te(n[t]);return e}return null}var ze=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),$e=new TextEncoder;function qe(n){let e=$e.encode(n),t=e.length,s=t*8,r=t+9+63&-64,i=new Uint8Array(r);i.set(e),i[t]=128;let a=new DataView(i.buffer);a.setUint32(r-4,s>>>0,!1),a.setUint32(r-8,Math.floor(s/4294967296)>>>0,!1);let o=1779033703,d=3144134277,l=1013904242,c=2773480762,u=1359893119,h=2600822924,g=528734635,y=1541459225,A=new Uint32Array(64),m=(x,b)=>x>>>b|x<<32-b;for(let x=0;x<r;x+=64){for(let p=0;p<16;p++)A[p]=a.getUint32(x+p*4,!1);for(let p=16;p<64;p++){let I=A[p-15],F=A[p-2],P=m(I,7)^m(I,18)^I>>>3,Y=m(F,17)^m(F,19)^F>>>10;A[p]=A[p-16]+P+A[p-7]+Y>>>0}let b=o,R=d,C=l,$=c,T=u,L=h,V=g,q=y;for(let p=0;p<64;p++){let I=m(T,6)^m(T,11)^m(T,25),F=T&L^~T&V,P=q+I+F+ze[p]+A[p]>>>0,Y=m(b,2)^m(b,13)^m(b,22),De=b&R^b&C^R&C,Oe=Y+De>>>0;q=V,V=L,L=T,T=$+P>>>0,$=C,C=R,R=b,b=P+Oe>>>0}o=o+b>>>0,d=d+R>>>0,l=l+C>>>0,c=c+$>>>0,u=u+T>>>0,h=h+L>>>0,g=g+V>>>0,y=y+q>>>0}let w=x=>x.toString(16).padStart(8,"0");return w(o)+w(d)+w(l)+w(c)+w(u)+w(h)+w(g)+w(y)}function ne(n){let e=te(n??null),t=JSON.stringify(e);return qe(t).slice(0,16)}function Ye(){let n=globalThis.crypto;if(n?.randomUUID)return n.randomUUID();let e=()=>Math.floor(Math.random()*4294967296).toString(16).padStart(8,"0"),t=e()+e()+e()+e();return`${t.slice(0,8)}-${t.slice(8,12)}-4${t.slice(13,16)}-${(parseInt(t.slice(16,17),16)&3|8).toString(16)}${t.slice(17,20)}-${t.slice(20,32)}`}function se(n,e,t){let s=t?.id??Ye();if(n===0)return{id:s,version:0};let i=(t?.hash??ne)(e);return{id:s,version:0,cid:i,prev:null}}function we(n,e,t){n.version+=1,"cid"in n&&(n.prev=n.cid,n.cid=t(e))}var xe=()=>{},Te=100;function Ne(n){return{node:n,unsub:null,prevData:void 0,dirty:!1,involvedThisWave:!1,dataBatch:[],terminal:void 0}}function re(n){n.prevData=void 0,n.dirty=!1,n.involvedThisWave=!1,n.dataBatch.length=0,n.terminal=void 0}function j(n){return n.length===0?n:typeof n[0]=="symbol"?[n]:n}var Ke=(n,e,t,s)=>{t.direction==="down-in"&&n._onDepMessage(t.depIndex,e)},Je=(n,e,t,s)=>{let r=n;if(r._status==="completed"||r._status==="errored")return;let i=r._cached,a=i===void 0?[X]:[X,[_,i]];r._status==="dirty"&&a.push(D),U(e,a,r._config.tierOf)},ie=new W({onMessage:Ke,onSubscribe:Je});ve(ie);fe(ie);var z=class n{_optsName;_describeKind;meta;_hasMeta;_config;_deps;_sinks=null;_sinkCount=0;_cached;_status;_cleanup;_store={};_waveHasNewData=!1;_hasNewTerminal=!1;_hasCalledFnOnce=!1;_paused=!1;_pendingWave=!1;_isExecutingFn=!1;_pendingRerun=!1;_rerunDepth=0;_dirtyDepCount=0;_batchPendingMessages=null;_pauseLocks=null;_pauseBuffer=null;_fn;_equals;_resubscribable;_resetOnTeardown;_autoComplete;_autoError;_pausable;_partial;_guard;_extraGuards;_hashFn;_versioning;_versioningLevel;_lastMutation;_inspectorHooks;_actions;constructor(e,t,s){this._config=s.config??ie,this._config.onMessage,this._optsName=s.name,this._describeKind=s.describeKind,this._equals=s.equals??Object.is,this._resubscribable=s.resubscribable??!1,this._resetOnTeardown=s.resetOnTeardown??!1,this._autoComplete=s.completeWhenDepsComplete??!0,this._autoError=s.errorWhenDepsError??!0,this._pausable=s.pausable??!0,this._guard=s.guard,this._fn=t,this._partial=s.partial??!1,this._cached=s.initial!==void 0?s.initial:void 0,this._status=e.length===0&&t==null&&this._cached!==void 0?"settled":"sentinel",this._hashFn=s.versioningHash??this._config.defaultHashFn??ne;let r=s.versioning??this._config.defaultVersioning;this._versioningLevel=r,this._versioning=r!=null?se(r,this._cached===void 0?void 0:this._cached,{id:s.versioningId,hash:this._hashFn}):void 0,this._deps=e.map(Ne);let i={};for(let[o,d]of Object.entries(s.meta??{})){let l={initial:d,name:`${s.name??"node"}:meta:${o}`,describeKind:"state",config:this._config};s.guard!=null&&(l.guard=s.guard),i[o]=new n([],void 0,l)}Object.freeze(i),this.meta=i,this._hasMeta=Object.keys(i).length>0;let a=this;this._actions={emit(o){a._emit([[_,o]])},down(o){a._emit(j(o))},up(o){a._emitUp(j(o))}},this.down=this.down.bind(this),this.up=this.up.bind(this)}get _isTerminal(){return this._status==="completed"||this._status==="errored"}get name(){return this._optsName}get status(){return this._status}get cache(){return this._cached===void 0?void 0:this._cached}get lastMutation(){return this._lastMutation}get v(){return this._versioning}hasGuard(){return this._guard!=null}_applyVersioning(e,t){if(this._isExecutingFn)throw new Error(`Node "${this.name}": _applyVersioning cannot run mid-fn \u2014 call it outside of \`_execFn\` (typically at graph setup time before the first subscribe).`);let s=this._versioningLevel;if(s!=null&&e<=s)return;let r=t?.hash??this._hashFn;r!==this._hashFn&&(this._hashFn=r);let i=this._cached===void 0?void 0:this._cached,a=this._versioning,o=a?.id??t?.id,d=a?.version??0,l=se(e,i,{id:o,hash:r});l.version=d,this._versioning=l,this._versioningLevel=e}_setInspectorHook(e){return e==null?()=>{}:(this._inspectorHooks==null&&(this._inspectorHooks=new Set),this._inspectorHooks.add(e),()=>{this._inspectorHooks?.delete(e),this._inspectorHooks?.size===0&&(this._inspectorHooks=void 0)})}_pushGuard(e){return this._extraGuards==null&&(this._extraGuards=new Set),this._extraGuards.add(e),()=>{this._extraGuards?.delete(e),this._extraGuards?.size===0&&(this._extraGuards=void 0)}}allowsObserve(e){if(this._guard==null&&this._extraGuards==null)return!0;let t=B(e);if(this._guard!=null&&!this._guard(t,"observe"))return!1;if(this._extraGuards!=null){for(let s of this._extraGuards)if(!s(t,"observe"))return!1}return!0}_checkGuard(e){if(e?.internal)return;let t=this._guard!=null||this._extraGuards!=null,s=e?.actor!=null;if(!t&&!s)return;let r=B(e?.actor),i=e?.delivery==="signal"?"signal":"write";if(this._guard!=null&&!this._guard(r,i))throw new O({actor:r,action:i,nodeName:this.name});if(this._extraGuards!=null){for(let a of this._extraGuards)if(!a(r,i))throw new O({actor:r,action:i,nodeName:this.name})}this._lastMutation={actor:r,timestamp_ns:me()}}down(e,t){let s=j(e);s.length!==0&&(this._checkGuard(t),this._emit(s))}emit(e,t){this._checkGuard(t),this._emit([[_,e]])}up(e,t){if(this._deps.length===0)return;let s=j(e);if(s.length===0)return;this._checkGuard(t);let r=t??{internal:!0};this._validateUpTiers(s);for(let i of this._deps)i.node.up?.(s,r)}_emitUp(e){if(this._deps.length!==0&&e.length!==0){this._validateUpTiers(e);for(let t of this._deps)t.node.up?.(e,{internal:!0})}}_validateUpTiers(e){let t=this._config.tierOf;for(let s of e){let r=t(s[0]);if(r===3||r===4)throw new Error(`Node "${this.name}": tier-${r} messages cannot flow up \u2014 DATA/RESOLVED/COMPLETE/ERROR are downstream-only. Use \`down(...)\` for value delivery; \`up(...)\` is for control signals (DIRTY, INVALIDATE, PAUSE, RESUME, TEARDOWN).`)}}subscribe(e,t){if(t!=null&&this._guard!=null){let d=B(t);if(!this._guard(d,"observe"))throw new O({actor:d,action:"observe",nodeName:this.name})}let r=this._isTerminal&&this._resubscribable;if(r){this._cached=void 0,this._status="sentinel",this._store={},this._hasCalledFnOnce=!1,this._waveHasNewData=!1,this._hasNewTerminal=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._isExecutingFn=!1,this._rerunDepth=0,this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null;for(let d of this._deps)re(d);if(this._partial===!1){for(let d of this._deps)if(d.prevData!==void 0||d.dataBatch.length!==0||d.terminal!==void 0||d.dirty)throw new Error(`resubscribable-reset invariant: DepRecord not fully reset for node ${this._optsName??"(anonymous)"}`)}}this._sinkCount+=1;let i;try{i=this._config.onSubscribe(this,e,{sinkCount:this._sinkCount,afterTerminalReset:r},this._actions)}catch(d){throw this._sinkCount-=1,d}this._sinks==null?this._sinks=e:typeof this._sinks=="function"?this._sinks=new Set([this._sinks,e]):this._sinks.add(e);let a=this._isTerminal;if(this._sinkCount===1&&!a)try{this._activate()}catch(d){if(this._sinkCount-=1,this._removeSink(e),this._sinkCount===0&&(this._status="sentinel"),typeof i=="function")try{i()}catch{}throw d}this._status==="sentinel"&&this._cached===void 0&&(this._status="pending");let o=!1;return()=>{o||(o=!0,this._sinkCount-=1,this._removeSink(e),typeof i=="function"&&i(),this._sinks==null&&this._deactivate())}}_removeSink(e){if(this._sinks===e)this._sinks=null;else if(this._sinks!=null&&typeof this._sinks!="function")if(this._sinks.delete(e),this._sinks.size===1){let[t]=this._sinks;this._sinks=t}else this._sinks.size===0&&(this._sinks=null)}_activate(){if(this._deps.length===0){this._fn&&this._execFn();return}this._dirtyDepCount=0;let e=this._deps.length,t=0;try{for(let s=0;s<e;s++){let r=s,i=this._deps[s];i.unsub=xe,i.unsub=i.node.subscribe(a=>{if(i.unsub===null)return;let o=this._config.tierOf,d=!1;for(let l of a)o(l[0])>=3&&(d=!0),this._config.onMessage(this,l,{direction:"down-in",depIndex:r},this._actions);d&&this._maybeRunFnOnSettlement()}),t++}}catch(s){this._deps[t].unsub=null;for(let r=0;r<t;r++){let i=this._deps[r];if(i.unsub!=null){let a=i.unsub;i.unsub=null;try{a()}catch{}re(i)}}throw this._dirtyDepCount=0,s}}_addDep(e){for(let r=0;r<this._deps.length;r++)if(this._deps[r].node===e)return r;let t=this._deps.length,s=Ne(e);if(this._deps.push(s),this._sinks==null)return t;s.dirty=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Z),s.unsub=xe;try{s.unsub=e.subscribe(r=>{if(s.unsub===null)return;let i=this._config.tierOf,a=!1;for(let o of r)i(o[0])>=3&&(a=!0),this._config.onMessage(this,o,{direction:"down-in",depIndex:t},this._actions);a&&this._maybeRunFnOnSettlement()})}catch(r){throw s.unsub=null,this._deps.pop(),this._dirtyDepCount--,r}return t}_deactivate(e=!1){let t=this._cleanup;if(this._cleanup=void 0,typeof t=="function")try{t()}catch(s){this._emit([[f,this._wrapFnError("cleanup threw",s)]])}else if(t!=null&&typeof t=="object"){let s=t.deactivate;if(typeof s=="function")try{s()}catch(r){this._emit([[f,this._wrapFnError("cleanup.deactivate threw",r)]])}}for(let s of this._deps){if(s.unsub!=null){let r=s.unsub;s.unsub=null;try{r()}catch{}}re(s)}this._waveHasNewData=!1,this._hasNewTerminal=!1,this._hasCalledFnOnce=!1,this._paused=!1,this._pendingWave=!1,this._pendingRerun=!1,this._rerunDepth=0,this._store={},this._dirtyDepCount=0,this._pauseLocks=null,this._pauseBuffer=null,this._fn!=null&&(this._cached=void 0),e||(this._fn!=null||this._deps.length>0)&&(!this._isTerminal||this._resubscribable)&&(this._status="sentinel")}_onDepMessage(e,t){let s=this._deps[e],r=t[0];if(this._inspectorHooks!=null){let i={kind:"dep_message",depIndex:e,message:t};for(let a of this._inspectorHooks)a(i)}if(r!==G){if(r===k){this._depDirtied(s);return}if(r===M){if(this._depInvalidated(s),this._cached===void 0)return;this._emit(ce);return}if(r===S||r===H){this._emit([t]);return}if(r===N){this._emit(Q);return}if(r===_)this._depSettledAsData(s,t[1]);else if(r===E)this._depSettledAsResolved(s);else if(r===v)this._depSettledAsTerminal(s,!0);else if(r===f)this._depSettledAsTerminal(s,t[1]);else{this._emit([t]);return}if(!this._fn){(r===_||r===E)&&this._emit([t]),(r===v||r===f)&&this._maybeAutoTerminalAfterWave();return}}}_depDirtied(e){e.dirty||(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++,this._status!=="dirty"&&this._emit(Z))}_depSettledAsData(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.involvedThisWave=!0,e.dataBatch.push(t),this._waveHasNewData=!0}_depSettledAsResolved(e){e.dirty&&(e.dirty=!1,this._dirtyDepCount--)}_depSettledAsTerminal(e,t){e.dirty&&(e.dirty=!1,this._dirtyDepCount--),e.terminal=t,e.involvedThisWave=!0,this._hasNewTerminal=!0}_depInvalidated(e){e.prevData=void 0,e.terminal=void 0,e.dataBatch.length=0,e.dirty?e.involvedThisWave=!1:(e.dirty=!0,e.involvedThisWave=!0,this._dirtyDepCount++)}_maybeRunFnOnSettlement(){if(!(this._isTerminal&&!this._resubscribable)&&!(this._dirtyDepCount>0)){if(!this._partial&&!this._hasCalledFnOnce)for(let e=0;e<this._deps.length;e++){let t=this._deps[e];if(t.dataBatch.length===0&&t.prevData===void 0&&t.terminal===void 0){this._maybeAutoTerminalAfterWave();return}}if(this._paused){this._pendingWave=!0;return}if(!this._waveHasNewData&&!this._hasNewTerminal&&this._hasCalledFnOnce){this._clearWaveFlags(),this._emit(le),this._maybeAutoTerminalAfterWave();return}this._fn&&this._execFn(),this._maybeAutoTerminalAfterWave()}}_maybeAutoTerminalAfterWave(){if(this._deps.length===0||this._isTerminal)return;let e=this._deps.find(t=>t.terminal!==void 0&&t.terminal!==!0);if(e!=null){this._autoError&&this._emit([[f,e.terminal]]);return}this._autoComplete&&this._deps.every(t=>t.terminal!==void 0)&&this._emit(ue)}_execFn(){if(!this._fn||this._isTerminal&&!this._resubscribable)return;if(this._isExecutingFn){this._pendingRerun=!0;return}let e=this._cleanup;if(typeof e=="function"){this._cleanup=void 0;try{e()}catch(a){this._emit([[f,this._wrapFnError("cleanup threw",a)]]);return}}else if(e!=null&&typeof e=="object"){let a=e.beforeRun;if(typeof a=="function"){e.beforeRun=void 0;try{a()}catch(o){this._emit([[f,this._wrapFnError("cleanup.beforeRun threw",o)]]);return}}}let t=this._deps.map(a=>a.involvedThisWave?a.dataBatch.length>0?[...a.dataBatch]:[]:void 0),s=this._deps.map(a=>a.prevData);for(let a=0;a<this._deps.length;a++){let o=t[a];o!=null&&o.length>0&&(this._deps[a].prevData=o[o.length-1])}let r=this._deps.map(a=>a.terminal),i={prevData:s,terminalDeps:r,store:this._store};if(this._hasCalledFnOnce=!0,this._clearWaveFlags(),this._inspectorHooks!=null){let a={kind:"run",batchData:t,prevData:s};for(let o of this._inspectorHooks)o(a)}this._isExecutingFn=!0;try{let a=this._fn(t,this._actions,i);if(typeof a=="function")this._cleanup=a;else if(a!=null&&typeof a=="object"){let o=a;(typeof o.beforeRun=="function"||typeof o.deactivate=="function"||typeof o.invalidate=="function")&&(this._cleanup=a)}}catch(a){this._emit([[f,this._wrapFnError("fn threw",a)]])}finally{this._isExecutingFn=!1,this._pendingRerun?(this._pendingRerun=!1,this._rerunDepth+=1,this._rerunDepth>Te?(this._rerunDepth=0,this._emit([[f,new Error(`Node "${this.name}": _pendingRerun depth exceeded ${Te} \u2014 likely a reactive cycle`)]])):this._maybeRunFnOnSettlement()):this._rerunDepth=0,this._clearWaveFlags()}}_clearWaveFlags(){this._waveHasNewData=!1,this._hasNewTerminal=!1;for(let e of this._deps)e.involvedThisWave=!1,e.dataBatch.length=0}_wrapFnError(e,t){let s=t instanceof Error?t.message:String(t);return new Error(`Node "${this.name}": ${e}: ${s}`,{cause:t})}_frameBatch(e){let t=this._config.tierOf;if(e.length===1)return t(e[0][0])===3&&this._status!=="dirty"?[D,e[0]]:e;let s=!0,r=!1,i=!1,a=-1;for(let d of e){let l=t(d[0]);l<a&&(s=!1),l===3&&(r=!0),d[0]===k&&(i=!0),a=l}let o=e;if(!s){let d=e.map((l,c)=>({m:l,i:c,tier:t(l[0])}));d.sort((l,c)=>l.tier-c.tier||l.i-c.i),o=d.map(l=>l.m)}if(r&&!i&&this._status!=="dirty"){let d=0;for(;d<o.length&&t(o[d][0])===0;)d++;return d===0?[D,...o]:[...o.slice(0,d),D,...o.slice(d)]}return o}_emit(e){if(e.length===0)return;for(let o=0;o<e.length;o++){let d=e[o];if(d[0]===f&&d[1]===void 0)throw new TypeError('[ERROR, payload] requires a non-undefined payload (spec \xA71.2). Pass an Error object or domain tag instead \u2014 e.g. node.down([[ERROR, new Error("reason")]])')}let t=e;if(this._isTerminal&&!this._resubscribable){let o=e.filter(d=>d[0]===N||d[0]===M);if(o.length===0)return;t=o}t=this._frameBatch(t);let r=null;for(let o=0;o<t.length;o++){let d=t[o],l=d[0];if(l!==S&&l!==H){r?.push(d);continue}if(d.length<2)throw new Error(`Node "${this.name}": [[${l===S?"PAUSE":"RESUME"}]] must carry a lockId payload \u2014 bare PAUSE/RESUME is a protocol violation (C0 rule). Use \`[[PAUSE, lockId]]\` / \`[[RESUME, lockId]]\`.`);let c=!0;if(this._pausable!==!1){let u=d[1];if(l===S)this._pauseLocks==null&&(this._pauseLocks=new Set),this._pauseLocks.add(u),this._paused=!0,this._pausable==="resumeAll"&&this._pauseBuffer==null&&(this._pauseBuffer=[]);else if(this._pauseLocks==null||!this._pauseLocks.has(u))c=!1;else if(this._pauseLocks.delete(u),this._pauseLocks.size===0){if(this._paused=!1,this._pauseBuffer!=null&&this._pauseBuffer.length>0){let h=this._pauseBuffer;this._pauseBuffer=[],this._emit(h)}this._pendingWave&&(this._pendingWave=!1,this._maybeRunFnOnSettlement())}}c?r?.push(d):r==null&&(r=t.slice(0,o))}if(r!=null){if(r.length===0)return;t=r}if(this._hasMeta&&t.some(o=>o[0]===N))for(let o of Object.keys(this.meta))try{this.meta[o]._emit(Q)}catch{}let{finalMessages:i,equalsError:a}=this._updateState(t);if(i.length>0&&this._config.inspectorEnabled){let o=this._config.globalInspector;if(o!=null)try{o({kind:"emit",node:this,messages:i})}catch{}}if(i.length>0)if(this._paused&&this._pausable==="resumeAll"&&this._pauseBuffer!=null){let o=this._config.tierOf,d=[];for(let l of i)o(l[0])===3?this._pauseBuffer.push(l):d.push(l);d.length>0&&this._dispatchOrAccumulate(d)}else this._dispatchOrAccumulate(i);a!=null&&this._emit([[f,a]])}_updateState(e){let t=this._config.tierOf,s,r,i=-1,a=0;for(let c of e)t(c[0])===3&&a++;let o=a<=1,d=-1;if(this._versioning!=null&&a>1){for(let c=e.length-1;c>=0;c--)if(e[c][0]===_){d=c;break}}for(let c=0;c<e.length;c++){let u=e[c],h=u[0];if(h===_){if(u.length>=2){let g=!1;if(o&&this._cached!==void 0)try{g=this._equals(this._cached,u[1])}catch(y){r=this._wrapFnError("equals threw",y),i=c;break}if(g){s==null&&(s=e.slice(0,c)),s.push(J),this._status="resolved";continue}this._cached=u[1],this._versioning!=null&&(d<0||c===d)&&we(this._versioning,u[1],this._hashFn)}this._status="settled",s?.push(u)}else if(s?.push(u),h===k)this._status="dirty";else if(h===E)this._status="resolved";else if(h===v)this._status="completed";else if(h===f)this._status="errored";else if(h===M){this._cached=void 0,this._status="dirty";let g=this._cleanup;if(typeof g=="function"){this._cleanup=void 0;try{g()}catch{}}else if(g!=null&&typeof g=="object"){let y=g.invalidate;if(typeof y=="function")try{y()}catch{}}}else h===N&&(this._resetOnTeardown&&(this._cached=void 0),this._deactivate(!0),this._status="sentinel")}let l=i>=0?s??e.slice(0,i):s??e;return r!=null?{finalMessages:l,equalsError:r}:{finalMessages:l}}_deliverToSinks=e=>{if(this._sinks==null)return;if(typeof this._sinks=="function"){this._sinks(e);return}let t=[...this._sinks];for(let s of t)s(e)};_dispatchOrAccumulate(e){if(ye()){this._batchPendingMessages===null&&(this._batchPendingMessages=[],be(()=>this._flushBatchPending()));for(let t of e)this._batchPendingMessages.push(t);return}U(this._deliverToSinks,e,this._config.tierOf)}_flushBatchPending(){let e=this._batchPendingMessages;if(e===null||(this._batchPendingMessages=null,e.length===0))return;let t=this._frameBatch(e);U(this._deliverToSinks,t,this._config.tierOf)}},Ae=n=>Array.isArray(n),oe=n=>typeof n=="object"&&n!=null&&!Array.isArray(n);function ke(n,e,t){let s=Ae(n)?n:[],r=typeof n=="function"?n:typeof e=="function"?e:void 0,i={};return Ae(n)?i=(oe(e)?e:t)??{}:oe(n)?i=n:i=(oe(e)?e:t)??{},new z(s,r,i)}function ae(n,e){return ke((s,r,i)=>n(r,i)??void 0,{describeKind:"producer",...e})}function Ee(n){return ae(e=>{let t=!1,s=()=>{n.onsuccess=null,n.onerror=null};return n.onsuccess=()=>{t||(t=!0,s(),e.down([[_,n.result],[v]]))},n.onerror=()=>{t||(t=!0,s(),e.down([[f,n.error??new Error("IndexedDB request failed")]]))},()=>{t=!0,s()}})}function Me(n){return ae(e=>{let t=!1,s=()=>{n.oncomplete=null,n.onerror=null,n.onabort=null};return n.oncomplete=()=>{t||(t=!0,s(),e.down([[_,void 0],[v]]))},n.onerror=()=>{t||(t=!0,s(),e.down([[f,n.error??new Error("IndexedDB transaction failed")]]))},n.onabort=()=>{t||(t=!0,s(),e.down([[f,n.error??new Error("IndexedDB transaction aborted")]]))},()=>{t=!0,s()}})}function Xe(n,e,t){return new Promise((s,r)=>{if(typeof indexedDB>"u"){r(new TypeError("indexedDB is not available in this environment"));return}let i=indexedDB.open(n,t);i.onupgradeneeded=()=>{let a=i.result;a.objectStoreNames.contains(e)||a.createObjectStore(e)},i.onsuccess=()=>s(i.result),i.onerror=()=>r(i.error??new Error("IndexedDB open failed"))})}function de(n,e,t,s,r){return Xe(n,e,t).then(i=>new Promise((a,o)=>{let d=i.transaction(e,s),l=d.objectStore(e),c=r(l),u,h=!1,g=!1,y=()=>{!h||!g||(i.close(),a(u))};c.onsuccess=()=>{u=c.result,h=!0,y()},c.onerror=()=>{i.close(),o(c.error??new Error("IndexedDB request failed"))},d.oncomplete=()=>{if(g=!0,!h){i.close(),o(new Error("IndexedDB transaction completed without request result"));return}y()},d.onerror=()=>{i.close(),o(d.error??new Error("IndexedDB transaction failed"))},d.onabort=()=>{i.close(),o(d.error??new Error("IndexedDB transaction aborted"))}}))}function Se(n){let{dbName:e,storeName:t}=n,s=n.version??1,r=n.key??"graphrefly_checkpoint";return{async save(i,a){await de(e,t,s,"readwrite",o=>o.put(a,r))},async load(i){let a=await de(e,t,s,"readonly",o=>o.get(r));return a==null||typeof a!="object"||Array.isArray(a)?null:a},async clear(i){await de(e,t,s,"readwrite",a=>a.delete(r))}}}0&&(module.exports={fromIDBRequest,fromIDBTransaction,indexedDbStorage});
@@ -1 +1 @@
1
- import{a as e,b as o,c as r}from"../chunk-7TDOES3L.js";import"../chunk-W4TSQ6RJ.js";import"../chunk-CK2E7BTU.js";import"../chunk-QYADASLV.js";export{e as fromIDBRequest,o as fromIDBTransaction,r as indexedDbStorage};
1
+ import{a as e,b as o,c as r}from"../chunk-Q2SY7M7K.js";import"../chunk-7AJKUA36.js";import"../chunk-CK2E7BTU.js";import"../chunk-QYADASLV.js";export{e as fromIDBRequest,o as fromIDBTransaction,r as indexedDbStorage};