@graphrefly/graphrefly 0.45.0 → 0.46.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 (714) hide show
  1. package/README.md +1 -2
  2. package/dist/_internal-B23BagFd.d.cts +33 -0
  3. package/dist/_internal-B23BagFd.d.ts +33 -0
  4. package/dist/adaptive-rate-limiter-Dch_xYIi.d.cts +111 -0
  5. package/dist/adaptive-rate-limiter-Dch_xYIi.d.ts +111 -0
  6. package/dist/agents-C0Ji9ldU.d.cts +629 -0
  7. package/dist/agents-C9zexT7I.d.ts +629 -0
  8. package/dist/audit-BAXb3VOg.d.ts +246 -0
  9. package/dist/audit-C_bPfkqS.d.cts +246 -0
  10. package/dist/backoff-7KIK3WQW.js +24 -0
  11. package/dist/backoff-7KIK3WQW.js.map +1 -0
  12. package/dist/backoff-Bnb9OoPh.d.cts +6 -0
  13. package/dist/backoff-Bnb9OoPh.d.ts +6 -0
  14. package/dist/base/composition/index.cjs +811 -0
  15. package/dist/base/composition/index.cjs.map +1 -0
  16. package/dist/base/composition/index.d.cts +469 -0
  17. package/dist/base/composition/index.d.ts +469 -0
  18. package/dist/base/composition/index.js +40 -0
  19. package/dist/base/composition/index.js.map +1 -0
  20. package/dist/base/index.cjs +6336 -0
  21. package/dist/base/index.cjs.map +1 -0
  22. package/dist/base/index.d.cts +22 -0
  23. package/dist/base/index.d.ts +22 -0
  24. package/dist/base/index.js +259 -0
  25. package/dist/base/index.js.map +1 -0
  26. package/dist/base/io/index.cjs +3270 -0
  27. package/dist/base/io/index.cjs.map +1 -0
  28. package/dist/base/io/index.d.cts +2245 -0
  29. package/dist/base/io/index.d.ts +2245 -0
  30. package/dist/base/io/index.js +117 -0
  31. package/dist/base/io/index.js.map +1 -0
  32. package/dist/base/meta/index.cjs +43 -0
  33. package/dist/base/meta/index.cjs.map +1 -0
  34. package/dist/base/meta/index.d.cts +45 -0
  35. package/dist/base/meta/index.d.ts +45 -0
  36. package/dist/base/meta/index.js +13 -0
  37. package/dist/base/meta/index.js.map +1 -0
  38. package/dist/base/mutation/index.cjs +200 -0
  39. package/dist/base/mutation/index.cjs.map +1 -0
  40. package/dist/base/mutation/index.d.cts +177 -0
  41. package/dist/base/mutation/index.d.ts +177 -0
  42. package/dist/base/mutation/index.js +22 -0
  43. package/dist/base/mutation/index.js.map +1 -0
  44. package/dist/base/render/index.cjs +1120 -0
  45. package/dist/base/render/index.cjs.map +1 -0
  46. package/dist/base/render/index.d.cts +227 -0
  47. package/dist/base/render/index.d.ts +227 -0
  48. package/dist/base/render/index.js +24 -0
  49. package/dist/base/render/index.js.map +1 -0
  50. package/dist/base/sources/browser/index.cjs +172 -0
  51. package/dist/base/sources/browser/index.cjs.map +1 -0
  52. package/dist/base/sources/browser/index.d.cts +84 -0
  53. package/dist/base/sources/browser/index.d.ts +84 -0
  54. package/dist/base/sources/browser/index.js +151 -0
  55. package/dist/base/sources/browser/index.js.map +1 -0
  56. package/dist/base/sources/event/index.cjs +98 -0
  57. package/dist/base/sources/event/index.cjs.map +1 -0
  58. package/dist/base/sources/event/index.d.cts +91 -0
  59. package/dist/base/sources/event/index.d.ts +91 -0
  60. package/dist/base/sources/event/index.js +13 -0
  61. package/dist/base/sources/event/index.js.map +1 -0
  62. package/dist/base/sources/index.cjs +755 -0
  63. package/dist/base/sources/index.cjs.map +1 -0
  64. package/dist/base/sources/index.d.cts +357 -0
  65. package/dist/base/sources/index.d.ts +357 -0
  66. package/dist/base/sources/index.js +42 -0
  67. package/dist/base/sources/index.js.map +1 -0
  68. package/dist/base/sources/node/index.cjs +320 -0
  69. package/dist/base/sources/node/index.cjs.map +1 -0
  70. package/dist/base/sources/node/index.d.cts +185 -0
  71. package/dist/base/sources/node/index.d.ts +185 -0
  72. package/dist/base/sources/node/index.js +306 -0
  73. package/dist/base/sources/node/index.js.map +1 -0
  74. package/dist/base/utils/index.cjs +37 -0
  75. package/dist/base/utils/index.cjs.map +1 -0
  76. package/dist/base/utils/index.d.cts +37 -0
  77. package/dist/base/utils/index.d.ts +37 -0
  78. package/dist/base/utils/index.js +11 -0
  79. package/dist/base/utils/index.js.map +1 -0
  80. package/dist/base/worker/index.cjs +548 -0
  81. package/dist/base/worker/index.cjs.map +1 -0
  82. package/dist/base/worker/index.d.cts +207 -0
  83. package/dist/base/worker/index.d.ts +207 -0
  84. package/dist/base/worker/index.js +20 -0
  85. package/dist/base/worker/index.js.map +1 -0
  86. package/dist/breaker-C9skL3d8.d.ts +175 -0
  87. package/dist/breaker-ugSdq54q.d.cts +175 -0
  88. package/dist/cascading-CSSbKGrJ.d.ts +199 -0
  89. package/dist/cascading-baGkiihI.d.cts +199 -0
  90. package/dist/chunk-255UCBG4.js +58 -0
  91. package/dist/chunk-255UCBG4.js.map +1 -0
  92. package/dist/chunk-2LO3EL4W.js +1 -0
  93. package/dist/chunk-2LO3EL4W.js.map +1 -0
  94. package/dist/chunk-2OB3CEJS.js +1065 -0
  95. package/dist/chunk-2OB3CEJS.js.map +1 -0
  96. package/dist/chunk-36NMM65U.js +144 -0
  97. package/dist/chunk-36NMM65U.js.map +1 -0
  98. package/dist/chunk-3CEXCBN6.js +1 -0
  99. package/dist/chunk-3CEXCBN6.js.map +1 -0
  100. package/dist/chunk-3MUSLI6E.js +105 -0
  101. package/dist/chunk-3MUSLI6E.js.map +1 -0
  102. package/dist/chunk-3PSLNJDU.js +884 -0
  103. package/dist/chunk-3PSLNJDU.js.map +1 -0
  104. package/dist/chunk-3QZY5BI7.js +92 -0
  105. package/dist/chunk-3QZY5BI7.js.map +1 -0
  106. package/dist/chunk-42FQ27MQ.js +594 -0
  107. package/dist/chunk-42FQ27MQ.js.map +1 -0
  108. package/dist/chunk-4GYMCUDZ.js +1085 -0
  109. package/dist/chunk-4GYMCUDZ.js.map +1 -0
  110. package/dist/chunk-4S53H2KR.js +382 -0
  111. package/dist/chunk-4S53H2KR.js.map +1 -0
  112. package/dist/chunk-4XCHZRUJ.js +128 -0
  113. package/dist/chunk-4XCHZRUJ.js.map +1 -0
  114. package/dist/chunk-5THCXDWY.js +725 -0
  115. package/dist/chunk-5THCXDWY.js.map +1 -0
  116. package/dist/chunk-6XZYT4SW.js +256 -0
  117. package/dist/chunk-6XZYT4SW.js.map +1 -0
  118. package/dist/chunk-7EGRP2VX.js +76 -0
  119. package/dist/chunk-7EGRP2VX.js.map +1 -0
  120. package/dist/chunk-A7KV5UK4.js +150 -0
  121. package/dist/chunk-A7KV5UK4.js.map +1 -0
  122. package/dist/chunk-APY2SS5X.js +156 -0
  123. package/dist/chunk-APY2SS5X.js.map +1 -0
  124. package/dist/chunk-AZDQPQ3V.js +66 -0
  125. package/dist/chunk-AZDQPQ3V.js.map +1 -0
  126. package/dist/chunk-BU3SEFA5.js +90 -0
  127. package/dist/chunk-BU3SEFA5.js.map +1 -0
  128. package/dist/chunk-BXGZFGZ4.js +189 -0
  129. package/dist/chunk-BXGZFGZ4.js.map +1 -0
  130. package/dist/chunk-CGHORL6G.js +579 -0
  131. package/dist/chunk-CGHORL6G.js.map +1 -0
  132. package/dist/chunk-CXANAIZU.js +530 -0
  133. package/dist/chunk-CXANAIZU.js.map +1 -0
  134. package/dist/chunk-CZQHCKKG.js +1 -0
  135. package/dist/chunk-CZQHCKKG.js.map +1 -0
  136. package/dist/chunk-DKNHAICT.js +133 -0
  137. package/dist/chunk-DKNHAICT.js.map +1 -0
  138. package/dist/chunk-DM4OMPWK.js +584 -0
  139. package/dist/chunk-DM4OMPWK.js.map +1 -0
  140. package/dist/chunk-DMSNO6ZB.js +452 -0
  141. package/dist/chunk-DMSNO6ZB.js.map +1 -0
  142. package/dist/chunk-E5OZPDIW.js +229 -0
  143. package/dist/chunk-E5OZPDIW.js.map +1 -0
  144. package/dist/chunk-EVYY4X5A.js +509 -0
  145. package/dist/chunk-EVYY4X5A.js.map +1 -0
  146. package/dist/chunk-FDFD67UO.js +1 -0
  147. package/dist/chunk-FDFD67UO.js.map +1 -0
  148. package/dist/chunk-FMPF42Q4.js +13 -0
  149. package/dist/chunk-FMPF42Q4.js.map +1 -0
  150. package/dist/chunk-FR6RGA3B.js +1277 -0
  151. package/dist/chunk-FR6RGA3B.js.map +1 -0
  152. package/dist/chunk-FW23JYNQ.js +454 -0
  153. package/dist/chunk-FW23JYNQ.js.map +1 -0
  154. package/dist/chunk-GBCENOLN.js +1575 -0
  155. package/dist/chunk-GBCENOLN.js.map +1 -0
  156. package/dist/chunk-HL7HUJIX.js +1 -0
  157. package/dist/chunk-HL7HUJIX.js.map +1 -0
  158. package/dist/chunk-HULCUY35.js +2508 -0
  159. package/dist/chunk-HULCUY35.js.map +1 -0
  160. package/dist/chunk-IHTWQEDR.js +169 -0
  161. package/dist/chunk-IHTWQEDR.js.map +1 -0
  162. package/dist/chunk-IJRR6YAI.js +128 -0
  163. package/dist/chunk-IJRR6YAI.js.map +1 -0
  164. package/dist/chunk-JGFRAFDL.js +221 -0
  165. package/dist/chunk-JGFRAFDL.js.map +1 -0
  166. package/dist/chunk-KIIXR252.js +211 -0
  167. package/dist/chunk-KIIXR252.js.map +1 -0
  168. package/dist/chunk-KN3H5CNT.js +11 -0
  169. package/dist/chunk-KN3H5CNT.js.map +1 -0
  170. package/dist/chunk-KPG3DGLA.js +1 -0
  171. package/dist/chunk-KPG3DGLA.js.map +1 -0
  172. package/dist/chunk-KRNQ6RGQ.js +1 -0
  173. package/dist/chunk-KRNQ6RGQ.js.map +1 -0
  174. package/dist/chunk-LBAJK24K.js +1071 -0
  175. package/dist/chunk-LBAJK24K.js.map +1 -0
  176. package/dist/chunk-MLTPJMH6.js +417 -0
  177. package/dist/chunk-MLTPJMH6.js.map +1 -0
  178. package/dist/chunk-N3SZ7BMH.js +95 -0
  179. package/dist/chunk-N3SZ7BMH.js.map +1 -0
  180. package/dist/chunk-NDUD3IMO.js +540 -0
  181. package/dist/chunk-NDUD3IMO.js.map +1 -0
  182. package/dist/chunk-NY2PYHNC.js +873 -0
  183. package/dist/chunk-NY2PYHNC.js.map +1 -0
  184. package/dist/chunk-O3MT7DYI.js +225 -0
  185. package/dist/chunk-O3MT7DYI.js.map +1 -0
  186. package/dist/chunk-OCUDSN63.js +2386 -0
  187. package/dist/chunk-OCUDSN63.js.map +1 -0
  188. package/dist/chunk-OIWU3NYV.js +199 -0
  189. package/dist/chunk-OIWU3NYV.js.map +1 -0
  190. package/dist/chunk-OO5BM6CJ.js +1153 -0
  191. package/dist/chunk-OO5BM6CJ.js.map +1 -0
  192. package/dist/chunk-OQUIJT7A.js +1 -0
  193. package/dist/chunk-OQUIJT7A.js.map +1 -0
  194. package/dist/chunk-P5LBT622.js +105 -0
  195. package/dist/chunk-P5LBT622.js.map +1 -0
  196. package/dist/chunk-PKGQG5QQ.js +519 -0
  197. package/dist/chunk-PKGQG5QQ.js.map +1 -0
  198. package/dist/chunk-PKPO3JTZ.js +561 -0
  199. package/dist/chunk-PKPO3JTZ.js.map +1 -0
  200. package/dist/chunk-PL5UDIQ5.js +118 -0
  201. package/dist/chunk-PL5UDIQ5.js.map +1 -0
  202. package/dist/chunk-PZWISPIQ.js +432 -0
  203. package/dist/chunk-PZWISPIQ.js.map +1 -0
  204. package/dist/chunk-Q3EYOCZB.js +510 -0
  205. package/dist/chunk-Q3EYOCZB.js.map +1 -0
  206. package/dist/chunk-QMBYUVRL.js +15 -0
  207. package/dist/chunk-QMBYUVRL.js.map +1 -0
  208. package/dist/chunk-RAGGHLCV.js +200 -0
  209. package/dist/chunk-RAGGHLCV.js.map +1 -0
  210. package/dist/chunk-RGL53X5G.js +574 -0
  211. package/dist/chunk-RGL53X5G.js.map +1 -0
  212. package/dist/chunk-RJOG4IJU.js +1039 -0
  213. package/dist/chunk-RJOG4IJU.js.map +1 -0
  214. package/dist/chunk-SOOKUYVM.js +403 -0
  215. package/dist/chunk-SOOKUYVM.js.map +1 -0
  216. package/dist/chunk-T5BN5KG7.js +1 -0
  217. package/dist/chunk-T5BN5KG7.js.map +1 -0
  218. package/dist/chunk-TP7244Y6.js +207 -0
  219. package/dist/chunk-TP7244Y6.js.map +1 -0
  220. package/dist/chunk-TSBFTJKM.js +57 -0
  221. package/dist/chunk-TSBFTJKM.js.map +1 -0
  222. package/dist/chunk-URQ2CBBF.js +143 -0
  223. package/dist/chunk-URQ2CBBF.js.map +1 -0
  224. package/dist/chunk-W2BOPXTI.js +1 -0
  225. package/dist/chunk-W2BOPXTI.js.map +1 -0
  226. package/dist/chunk-WKSWLSCX.js +207 -0
  227. package/dist/chunk-WKSWLSCX.js.map +1 -0
  228. package/dist/chunk-Y52CS6YA.js +88 -0
  229. package/dist/chunk-Y52CS6YA.js.map +1 -0
  230. package/dist/chunk-YCBUWK77.js +92 -0
  231. package/dist/chunk-YCBUWK77.js.map +1 -0
  232. package/dist/chunk-YJ4U2D2C.js +314 -0
  233. package/dist/chunk-YJ4U2D2C.js.map +1 -0
  234. package/dist/chunk-Z4YXAUDN.js +239 -0
  235. package/dist/chunk-Z4YXAUDN.js.map +1 -0
  236. package/dist/chunk-Z6EGP5D7.js +92 -0
  237. package/dist/chunk-Z6EGP5D7.js.map +1 -0
  238. package/dist/compat/index.cjs +3083 -2
  239. package/dist/compat/index.cjs.map +1 -1
  240. package/dist/compat/index.d.cts +116 -1
  241. package/dist/compat/index.d.ts +116 -1
  242. package/dist/compat/index.js +175 -2
  243. package/dist/compat/index.js.map +1 -1
  244. package/dist/compat/jotai/index.cjs +130 -2
  245. package/dist/compat/jotai/index.cjs.map +1 -1
  246. package/dist/compat/jotai/index.d.cts +2 -1
  247. package/dist/compat/jotai/index.d.ts +2 -1
  248. package/dist/compat/jotai/index.js +7 -2
  249. package/dist/compat/jotai/index.js.map +1 -1
  250. package/dist/compat/nanostores/index.cjs +186 -2
  251. package/dist/compat/nanostores/index.cjs.map +1 -1
  252. package/dist/compat/nanostores/index.d.cts +2 -1
  253. package/dist/compat/nanostores/index.d.ts +2 -1
  254. package/dist/compat/nanostores/index.js +21 -2
  255. package/dist/compat/nanostores/index.js.map +1 -1
  256. package/dist/compat/nestjs/index.cjs +2224 -2
  257. package/dist/compat/nestjs/index.cjs.map +1 -1
  258. package/dist/compat/nestjs/index.d.cts +10 -1
  259. package/dist/compat/nestjs/index.d.ts +10 -1
  260. package/dist/compat/nestjs/index.js +77 -2
  261. package/dist/compat/nestjs/index.js.map +1 -1
  262. package/dist/compat/react/index.cjs +95 -2
  263. package/dist/compat/react/index.cjs.map +1 -1
  264. package/dist/compat/react/index.d.cts +2 -1
  265. package/dist/compat/react/index.d.ts +2 -1
  266. package/dist/compat/react/index.js +11 -2
  267. package/dist/compat/react/index.js.map +1 -1
  268. package/dist/compat/solid/index.cjs +82 -2
  269. package/dist/compat/solid/index.cjs.map +1 -1
  270. package/dist/compat/solid/index.d.cts +2 -1
  271. package/dist/compat/solid/index.d.ts +2 -1
  272. package/dist/compat/solid/index.js +11 -2
  273. package/dist/compat/solid/index.js.map +1 -1
  274. package/dist/compat/svelte/index.cjs +85 -2
  275. package/dist/compat/svelte/index.cjs.map +1 -1
  276. package/dist/compat/svelte/index.d.cts +2 -1
  277. package/dist/compat/svelte/index.d.ts +2 -1
  278. package/dist/compat/svelte/index.js +11 -2
  279. package/dist/compat/svelte/index.js.map +1 -1
  280. package/dist/compat/vue/index.cjs +100 -2
  281. package/dist/compat/vue/index.cjs.map +1 -1
  282. package/dist/compat/vue/index.d.cts +3 -1
  283. package/dist/compat/vue/index.d.ts +3 -1
  284. package/dist/compat/vue/index.js +11 -2
  285. package/dist/compat/vue/index.js.map +1 -1
  286. package/dist/compat/zustand/index.cjs +50 -2
  287. package/dist/compat/zustand/index.cjs.map +1 -1
  288. package/dist/compat/zustand/index.d.cts +2 -1
  289. package/dist/compat/zustand/index.d.ts +2 -1
  290. package/dist/compat/zustand/index.js +7 -2
  291. package/dist/compat/zustand/index.js.map +1 -1
  292. package/dist/distill-De6Rnn15.d.cts +48 -0
  293. package/dist/distill-De6Rnn15.d.ts +48 -0
  294. package/dist/external-register-CWyroXb_.d.cts +138 -0
  295. package/dist/external-register-CWyroXb_.d.ts +138 -0
  296. package/dist/fallback-Bx46zqky.d.cts +243 -0
  297. package/dist/fallback-pIWW8A2d.d.ts +243 -0
  298. package/dist/guarded-execution-BcdtxeBk.d.ts +207 -0
  299. package/dist/guarded-execution-C-3hnP6A.d.cts +207 -0
  300. package/dist/index-5SU_O78r.d.cts +754 -0
  301. package/dist/index-B6pxYJzO.d.cts +36 -0
  302. package/dist/index-B6pxYJzO.d.ts +36 -0
  303. package/dist/index-BFsng6v1.d.cts +44 -0
  304. package/dist/index-BFsng6v1.d.ts +44 -0
  305. package/dist/index-Bg-LwEt-.d.cts +45 -0
  306. package/dist/index-Bg-LwEt-.d.ts +45 -0
  307. package/dist/index-Brp888t0.d.cts +127 -0
  308. package/dist/index-Brp888t0.d.ts +127 -0
  309. package/dist/index-CDfk6jHN.d.cts +37 -0
  310. package/dist/index-CDfk6jHN.d.ts +37 -0
  311. package/dist/index-CEXCtYYJ.d.ts +754 -0
  312. package/dist/index-DLAxYaN5.d.cts +169 -0
  313. package/dist/index-DLAxYaN5.d.ts +169 -0
  314. package/dist/index-DeWbQzMe.d.cts +34 -0
  315. package/dist/index-DeWbQzMe.d.ts +34 -0
  316. package/dist/index-dX9IzPqj.d.cts +86 -0
  317. package/dist/index-dX9IzPqj.d.ts +86 -0
  318. package/dist/index.cjs +25950 -0
  319. package/dist/index.cjs.map +1 -1
  320. package/dist/index.d.cts +56 -42
  321. package/dist/index.d.ts +56 -42
  322. package/dist/index.js +849 -0
  323. package/dist/index.js.map +1 -1
  324. package/dist/layout-types-B5aiHYgk.d.cts +72 -0
  325. package/dist/layout-types-B5aiHYgk.d.ts +72 -0
  326. package/dist/memory-composers-BryDrRBX.d.cts +529 -0
  327. package/dist/memory-composers-CVQqPYEV.d.ts +529 -0
  328. package/dist/observable-BXQoW1P-.d.cts +36 -0
  329. package/dist/observable-BXQoW1P-.d.ts +36 -0
  330. package/dist/pipeline-graph-Ce47CB6Y.d.cts +145 -0
  331. package/dist/pipeline-graph-DXCwY9vG.d.ts +145 -0
  332. package/dist/presets/ai/index.cjs +4377 -0
  333. package/dist/presets/ai/index.cjs.map +1 -0
  334. package/dist/presets/ai/index.d.cts +98 -0
  335. package/dist/presets/ai/index.d.ts +98 -0
  336. package/dist/presets/ai/index.js +54 -0
  337. package/dist/presets/ai/index.js.map +1 -0
  338. package/dist/presets/harness/index.cjs +5929 -0
  339. package/dist/presets/harness/index.cjs.map +1 -0
  340. package/dist/presets/harness/index.d.cts +566 -0
  341. package/dist/presets/harness/index.d.ts +566 -0
  342. package/dist/presets/harness/index.js +71 -0
  343. package/dist/presets/harness/index.js.map +1 -0
  344. package/dist/presets/index.cjs +9782 -0
  345. package/dist/presets/index.cjs.map +1 -0
  346. package/dist/presets/index.d.cts +28 -0
  347. package/dist/presets/index.d.ts +28 -0
  348. package/dist/presets/index.js +129 -0
  349. package/dist/presets/index.js.map +1 -0
  350. package/dist/presets/inspect/index.cjs +1087 -0
  351. package/dist/presets/inspect/index.cjs.map +1 -0
  352. package/dist/presets/inspect/index.d.cts +172 -0
  353. package/dist/presets/inspect/index.d.ts +172 -0
  354. package/dist/presets/inspect/index.js +21 -0
  355. package/dist/presets/inspect/index.js.map +1 -0
  356. package/dist/presets/resilience/index.cjs +1593 -0
  357. package/dist/presets/resilience/index.cjs.map +1 -0
  358. package/dist/presets/resilience/index.d.cts +205 -0
  359. package/dist/presets/resilience/index.d.ts +205 -0
  360. package/dist/presets/resilience/index.js +18 -0
  361. package/dist/presets/resilience/index.js.map +1 -0
  362. package/dist/rate-limiter-CEALq4N1.d.ts +559 -0
  363. package/dist/rate-limiter-DpVbSYdH.d.cts +559 -0
  364. package/dist/reactive-layout-fswlBUvX.d.cts +195 -0
  365. package/dist/reactive-layout-fswlBUvX.d.ts +195 -0
  366. package/dist/retry-BDbRZ_gx.d.ts +125 -0
  367. package/dist/retry-DWuhjvsA.d.cts +125 -0
  368. package/dist/solutions/index.cjs +8200 -0
  369. package/dist/solutions/index.cjs.map +1 -0
  370. package/dist/solutions/index.d.cts +23 -0
  371. package/dist/solutions/index.d.ts +23 -0
  372. package/dist/solutions/index.js +55 -0
  373. package/dist/solutions/index.js.map +1 -0
  374. package/dist/spawnable-5mDY501F.d.cts +746 -0
  375. package/dist/spawnable-D3lR0oQu.d.ts +746 -0
  376. package/dist/status-U-rUI79b.d.cts +84 -0
  377. package/dist/status-U-rUI79b.d.ts +84 -0
  378. package/dist/timeout-U5O4ESK3.js +12 -0
  379. package/dist/timeout-U5O4ESK3.js.map +1 -0
  380. package/dist/types-BB5Lw-pB.d.cts +442 -0
  381. package/dist/types-BB5Lw-pB.d.ts +442 -0
  382. package/dist/types-CJWIMJiZ.d.ts +548 -0
  383. package/dist/types-vCq7ShIm.d.cts +548 -0
  384. package/dist/utils/ai/browser.cjs +2169 -0
  385. package/dist/utils/ai/browser.cjs.map +1 -0
  386. package/dist/utils/ai/browser.d.cts +129 -0
  387. package/dist/utils/ai/browser.d.ts +129 -0
  388. package/dist/utils/ai/browser.js +255 -0
  389. package/dist/utils/ai/browser.js.map +1 -0
  390. package/dist/utils/ai/index.cjs +8468 -0
  391. package/dist/utils/ai/index.cjs.map +1 -0
  392. package/dist/utils/ai/index.d.cts +1777 -0
  393. package/dist/utils/ai/index.d.ts +1777 -0
  394. package/dist/utils/ai/index.js +173 -0
  395. package/dist/utils/ai/index.js.map +1 -0
  396. package/dist/utils/ai/node.cjs +648 -0
  397. package/dist/utils/ai/node.cjs.map +1 -0
  398. package/dist/utils/ai/node.d.cts +57 -0
  399. package/dist/utils/ai/node.d.ts +57 -0
  400. package/dist/utils/ai/node.js +84 -0
  401. package/dist/utils/ai/node.js.map +1 -0
  402. package/dist/utils/cqrs/index.cjs +1036 -0
  403. package/dist/utils/cqrs/index.cjs.map +1 -0
  404. package/dist/utils/cqrs/index.d.cts +438 -0
  405. package/dist/utils/cqrs/index.d.ts +438 -0
  406. package/dist/utils/cqrs/index.js +18 -0
  407. package/dist/utils/cqrs/index.js.map +1 -0
  408. package/dist/utils/demo-shell/index.cjs +865 -0
  409. package/dist/utils/demo-shell/index.cjs.map +1 -0
  410. package/dist/utils/demo-shell/index.d.cts +90 -0
  411. package/dist/utils/demo-shell/index.d.ts +90 -0
  412. package/dist/utils/demo-shell/index.js +13 -0
  413. package/dist/utils/demo-shell/index.js.map +1 -0
  414. package/dist/utils/domain-templates/index.cjs +732 -0
  415. package/dist/utils/domain-templates/index.cjs.map +1 -0
  416. package/dist/utils/domain-templates/index.d.cts +214 -0
  417. package/dist/utils/domain-templates/index.d.ts +214 -0
  418. package/dist/utils/domain-templates/index.js +17 -0
  419. package/dist/utils/domain-templates/index.js.map +1 -0
  420. package/dist/utils/graphspec/index.cjs +1174 -0
  421. package/dist/utils/graphspec/index.cjs.map +1 -0
  422. package/dist/utils/graphspec/index.d.cts +449 -0
  423. package/dist/utils/graphspec/index.d.ts +449 -0
  424. package/dist/utils/graphspec/index.js +35 -0
  425. package/dist/utils/graphspec/index.js.map +1 -0
  426. package/dist/utils/harness/index.cjs +656 -0
  427. package/dist/utils/harness/index.cjs.map +1 -0
  428. package/dist/utils/harness/index.d.cts +542 -0
  429. package/dist/utils/harness/index.d.ts +542 -0
  430. package/dist/utils/harness/index.js +56 -0
  431. package/dist/utils/harness/index.js.map +1 -0
  432. package/dist/utils/index.cjs +17609 -0
  433. package/dist/utils/index.cjs.map +1 -0
  434. package/dist/utils/index.d.cts +96 -0
  435. package/dist/utils/index.d.ts +96 -0
  436. package/dist/utils/index.js +514 -0
  437. package/dist/utils/index.js.map +1 -0
  438. package/dist/utils/inspect/index.cjs +807 -0
  439. package/dist/utils/inspect/index.cjs.map +1 -0
  440. package/dist/utils/inspect/index.d.cts +123 -0
  441. package/dist/utils/inspect/index.d.ts +123 -0
  442. package/dist/utils/inspect/index.js +30 -0
  443. package/dist/utils/inspect/index.js.map +1 -0
  444. package/dist/utils/job-queue/index.cjs +717 -0
  445. package/dist/utils/job-queue/index.cjs.map +1 -0
  446. package/dist/utils/job-queue/index.d.cts +200 -0
  447. package/dist/utils/job-queue/index.d.ts +200 -0
  448. package/dist/utils/job-queue/index.js +18 -0
  449. package/dist/utils/job-queue/index.js.map +1 -0
  450. package/dist/utils/memory/index.cjs +1451 -0
  451. package/dist/utils/memory/index.cjs.map +1 -0
  452. package/dist/utils/memory/index.d.cts +582 -0
  453. package/dist/utils/memory/index.d.ts +582 -0
  454. package/dist/utils/memory/index.js +19 -0
  455. package/dist/utils/memory/index.js.map +1 -0
  456. package/dist/utils/messaging/index.cjs +666 -0
  457. package/dist/utils/messaging/index.cjs.map +1 -0
  458. package/dist/utils/messaging/index.d.cts +562 -0
  459. package/dist/utils/messaging/index.d.ts +562 -0
  460. package/dist/utils/messaging/index.js +50 -0
  461. package/dist/utils/messaging/index.js.map +1 -0
  462. package/dist/utils/orchestration/index.cjs +876 -0
  463. package/dist/utils/orchestration/index.cjs.map +1 -0
  464. package/dist/utils/orchestration/index.d.cts +233 -0
  465. package/dist/utils/orchestration/index.d.ts +233 -0
  466. package/dist/utils/orchestration/index.js +19 -0
  467. package/dist/utils/orchestration/index.js.map +1 -0
  468. package/dist/utils/process/index.cjs +743 -0
  469. package/dist/utils/process/index.cjs.map +1 -0
  470. package/dist/utils/process/index.d.cts +411 -0
  471. package/dist/utils/process/index.d.ts +411 -0
  472. package/dist/utils/process/index.js +14 -0
  473. package/dist/utils/process/index.js.map +1 -0
  474. package/dist/utils/reactive-layout/index.cjs +1607 -0
  475. package/dist/utils/reactive-layout/index.cjs.map +1 -0
  476. package/dist/utils/reactive-layout/index.d.cts +492 -0
  477. package/dist/utils/reactive-layout/index.d.ts +492 -0
  478. package/dist/utils/reactive-layout/index.js +52 -0
  479. package/dist/utils/reactive-layout/index.js.map +1 -0
  480. package/dist/utils/reduction/index.cjs +203 -0
  481. package/dist/utils/reduction/index.cjs.map +1 -0
  482. package/dist/utils/reduction/index.d.cts +102 -0
  483. package/dist/utils/reduction/index.d.ts +102 -0
  484. package/dist/utils/reduction/index.js +14 -0
  485. package/dist/utils/reduction/index.js.map +1 -0
  486. package/dist/utils/resilience/index.cjs +1617 -0
  487. package/dist/utils/resilience/index.cjs.map +1 -0
  488. package/dist/utils/resilience/index.d.cts +9 -0
  489. package/dist/utils/resilience/index.d.ts +9 -0
  490. package/dist/utils/resilience/index.js +44 -0
  491. package/dist/utils/resilience/index.js.map +1 -0
  492. package/dist/utils/surface/index.cjs +1070 -0
  493. package/dist/utils/surface/index.cjs.map +1 -0
  494. package/dist/utils/surface/index.d.cts +240 -0
  495. package/dist/utils/surface/index.d.ts +240 -0
  496. package/dist/utils/surface/index.js +30 -0
  497. package/dist/utils/surface/index.js.map +1 -0
  498. package/dist/utils/topology-view/index.cjs +620 -0
  499. package/dist/utils/topology-view/index.cjs.map +1 -0
  500. package/dist/utils/topology-view/index.d.cts +68 -0
  501. package/dist/utils/topology-view/index.d.ts +68 -0
  502. package/dist/utils/topology-view/index.js +11 -0
  503. package/dist/utils/topology-view/index.js.map +1 -0
  504. package/package.json +293 -237
  505. package/dist/core/index.cjs +0 -21
  506. package/dist/core/index.cjs.map +0 -1
  507. package/dist/core/index.d.cts +0 -1
  508. package/dist/core/index.d.ts +0 -1
  509. package/dist/core/index.js +0 -3
  510. package/dist/core/index.js.map +0 -1
  511. package/dist/extra/browser.cjs +0 -21
  512. package/dist/extra/browser.cjs.map +0 -1
  513. package/dist/extra/browser.d.cts +0 -1
  514. package/dist/extra/browser.d.ts +0 -1
  515. package/dist/extra/browser.js +0 -3
  516. package/dist/extra/browser.js.map +0 -1
  517. package/dist/extra/index.cjs +0 -21
  518. package/dist/extra/index.cjs.map +0 -1
  519. package/dist/extra/index.d.cts +0 -1
  520. package/dist/extra/index.d.ts +0 -1
  521. package/dist/extra/index.js +0 -3
  522. package/dist/extra/index.js.map +0 -1
  523. package/dist/extra/node.cjs +0 -21
  524. package/dist/extra/node.cjs.map +0 -1
  525. package/dist/extra/node.d.cts +0 -1
  526. package/dist/extra/node.d.ts +0 -1
  527. package/dist/extra/node.js +0 -3
  528. package/dist/extra/node.js.map +0 -1
  529. package/dist/extra/operators.cjs +0 -21
  530. package/dist/extra/operators.cjs.map +0 -1
  531. package/dist/extra/operators.d.cts +0 -1
  532. package/dist/extra/operators.d.ts +0 -1
  533. package/dist/extra/operators.js +0 -3
  534. package/dist/extra/operators.js.map +0 -1
  535. package/dist/extra/reactive.cjs +0 -21
  536. package/dist/extra/reactive.cjs.map +0 -1
  537. package/dist/extra/reactive.d.cts +0 -1
  538. package/dist/extra/reactive.d.ts +0 -1
  539. package/dist/extra/reactive.js +0 -3
  540. package/dist/extra/reactive.js.map +0 -1
  541. package/dist/extra/render/index.cjs +0 -21
  542. package/dist/extra/render/index.cjs.map +0 -1
  543. package/dist/extra/render/index.d.cts +0 -1
  544. package/dist/extra/render/index.d.ts +0 -1
  545. package/dist/extra/render/index.js +0 -3
  546. package/dist/extra/render/index.js.map +0 -1
  547. package/dist/extra/sources.cjs +0 -21
  548. package/dist/extra/sources.cjs.map +0 -1
  549. package/dist/extra/sources.d.cts +0 -1
  550. package/dist/extra/sources.d.ts +0 -1
  551. package/dist/extra/sources.js +0 -3
  552. package/dist/extra/sources.js.map +0 -1
  553. package/dist/extra/storage-browser.cjs +0 -21
  554. package/dist/extra/storage-browser.cjs.map +0 -1
  555. package/dist/extra/storage-browser.d.cts +0 -1
  556. package/dist/extra/storage-browser.d.ts +0 -1
  557. package/dist/extra/storage-browser.js +0 -3
  558. package/dist/extra/storage-browser.js.map +0 -1
  559. package/dist/extra/storage-core.cjs +0 -21
  560. package/dist/extra/storage-core.cjs.map +0 -1
  561. package/dist/extra/storage-core.d.cts +0 -1
  562. package/dist/extra/storage-core.d.ts +0 -1
  563. package/dist/extra/storage-core.js +0 -3
  564. package/dist/extra/storage-core.js.map +0 -1
  565. package/dist/extra/storage-node.cjs +0 -21
  566. package/dist/extra/storage-node.cjs.map +0 -1
  567. package/dist/extra/storage-node.d.cts +0 -1
  568. package/dist/extra/storage-node.d.ts +0 -1
  569. package/dist/extra/storage-node.js +0 -3
  570. package/dist/extra/storage-node.js.map +0 -1
  571. package/dist/extra/storage-tiers-browser.cjs +0 -21
  572. package/dist/extra/storage-tiers-browser.cjs.map +0 -1
  573. package/dist/extra/storage-tiers-browser.d.cts +0 -1
  574. package/dist/extra/storage-tiers-browser.d.ts +0 -1
  575. package/dist/extra/storage-tiers-browser.js +0 -3
  576. package/dist/extra/storage-tiers-browser.js.map +0 -1
  577. package/dist/extra/storage-tiers-node.cjs +0 -21
  578. package/dist/extra/storage-tiers-node.cjs.map +0 -1
  579. package/dist/extra/storage-tiers-node.d.cts +0 -1
  580. package/dist/extra/storage-tiers-node.d.ts +0 -1
  581. package/dist/extra/storage-tiers-node.js +0 -3
  582. package/dist/extra/storage-tiers-node.js.map +0 -1
  583. package/dist/extra/storage-tiers.cjs +0 -21
  584. package/dist/extra/storage-tiers.cjs.map +0 -1
  585. package/dist/extra/storage-tiers.d.cts +0 -1
  586. package/dist/extra/storage-tiers.d.ts +0 -1
  587. package/dist/extra/storage-tiers.js +0 -3
  588. package/dist/extra/storage-tiers.js.map +0 -1
  589. package/dist/extra/storage-wal.cjs +0 -21
  590. package/dist/extra/storage-wal.cjs.map +0 -1
  591. package/dist/extra/storage-wal.d.cts +0 -1
  592. package/dist/extra/storage-wal.d.ts +0 -1
  593. package/dist/extra/storage-wal.js +0 -3
  594. package/dist/extra/storage-wal.js.map +0 -1
  595. package/dist/graph/index.cjs +0 -21
  596. package/dist/graph/index.cjs.map +0 -1
  597. package/dist/graph/index.d.cts +0 -1
  598. package/dist/graph/index.d.ts +0 -1
  599. package/dist/graph/index.js +0 -3
  600. package/dist/graph/index.js.map +0 -1
  601. package/dist/patterns/ai/browser.cjs +0 -21
  602. package/dist/patterns/ai/browser.cjs.map +0 -1
  603. package/dist/patterns/ai/browser.d.cts +0 -1
  604. package/dist/patterns/ai/browser.d.ts +0 -1
  605. package/dist/patterns/ai/browser.js +0 -3
  606. package/dist/patterns/ai/browser.js.map +0 -1
  607. package/dist/patterns/ai/index.cjs +0 -21
  608. package/dist/patterns/ai/index.cjs.map +0 -1
  609. package/dist/patterns/ai/index.d.cts +0 -1
  610. package/dist/patterns/ai/index.d.ts +0 -1
  611. package/dist/patterns/ai/index.js +0 -3
  612. package/dist/patterns/ai/index.js.map +0 -1
  613. package/dist/patterns/ai/node.cjs +0 -21
  614. package/dist/patterns/ai/node.cjs.map +0 -1
  615. package/dist/patterns/ai/node.d.cts +0 -1
  616. package/dist/patterns/ai/node.d.ts +0 -1
  617. package/dist/patterns/ai/node.js +0 -3
  618. package/dist/patterns/ai/node.js.map +0 -1
  619. package/dist/patterns/cqrs/index.cjs +0 -21
  620. package/dist/patterns/cqrs/index.cjs.map +0 -1
  621. package/dist/patterns/cqrs/index.d.cts +0 -1
  622. package/dist/patterns/cqrs/index.d.ts +0 -1
  623. package/dist/patterns/cqrs/index.js +0 -3
  624. package/dist/patterns/cqrs/index.js.map +0 -1
  625. package/dist/patterns/demo-shell/index.cjs +0 -21
  626. package/dist/patterns/demo-shell/index.cjs.map +0 -1
  627. package/dist/patterns/demo-shell/index.d.cts +0 -1
  628. package/dist/patterns/demo-shell/index.d.ts +0 -1
  629. package/dist/patterns/demo-shell/index.js +0 -3
  630. package/dist/patterns/demo-shell/index.js.map +0 -1
  631. package/dist/patterns/domain-templates/index.cjs +0 -21
  632. package/dist/patterns/domain-templates/index.cjs.map +0 -1
  633. package/dist/patterns/domain-templates/index.d.cts +0 -1
  634. package/dist/patterns/domain-templates/index.d.ts +0 -1
  635. package/dist/patterns/domain-templates/index.js +0 -3
  636. package/dist/patterns/domain-templates/index.js.map +0 -1
  637. package/dist/patterns/graphspec/index.cjs +0 -21
  638. package/dist/patterns/graphspec/index.cjs.map +0 -1
  639. package/dist/patterns/graphspec/index.d.cts +0 -1
  640. package/dist/patterns/graphspec/index.d.ts +0 -1
  641. package/dist/patterns/graphspec/index.js +0 -3
  642. package/dist/patterns/graphspec/index.js.map +0 -1
  643. package/dist/patterns/harness/index.cjs +0 -21
  644. package/dist/patterns/harness/index.cjs.map +0 -1
  645. package/dist/patterns/harness/index.d.cts +0 -1
  646. package/dist/patterns/harness/index.d.ts +0 -1
  647. package/dist/patterns/harness/index.js +0 -3
  648. package/dist/patterns/harness/index.js.map +0 -1
  649. package/dist/patterns/inspect/index.cjs +0 -21
  650. package/dist/patterns/inspect/index.cjs.map +0 -1
  651. package/dist/patterns/inspect/index.d.cts +0 -1
  652. package/dist/patterns/inspect/index.d.ts +0 -1
  653. package/dist/patterns/inspect/index.js +0 -3
  654. package/dist/patterns/inspect/index.js.map +0 -1
  655. package/dist/patterns/job-queue/index.cjs +0 -21
  656. package/dist/patterns/job-queue/index.cjs.map +0 -1
  657. package/dist/patterns/job-queue/index.d.cts +0 -1
  658. package/dist/patterns/job-queue/index.d.ts +0 -1
  659. package/dist/patterns/job-queue/index.js +0 -3
  660. package/dist/patterns/job-queue/index.js.map +0 -1
  661. package/dist/patterns/memory/index.cjs +0 -21
  662. package/dist/patterns/memory/index.cjs.map +0 -1
  663. package/dist/patterns/memory/index.d.cts +0 -1
  664. package/dist/patterns/memory/index.d.ts +0 -1
  665. package/dist/patterns/memory/index.js +0 -3
  666. package/dist/patterns/memory/index.js.map +0 -1
  667. package/dist/patterns/messaging/index.cjs +0 -21
  668. package/dist/patterns/messaging/index.cjs.map +0 -1
  669. package/dist/patterns/messaging/index.d.cts +0 -1
  670. package/dist/patterns/messaging/index.d.ts +0 -1
  671. package/dist/patterns/messaging/index.js +0 -3
  672. package/dist/patterns/messaging/index.js.map +0 -1
  673. package/dist/patterns/orchestration/index.cjs +0 -21
  674. package/dist/patterns/orchestration/index.cjs.map +0 -1
  675. package/dist/patterns/orchestration/index.d.cts +0 -1
  676. package/dist/patterns/orchestration/index.d.ts +0 -1
  677. package/dist/patterns/orchestration/index.js +0 -3
  678. package/dist/patterns/orchestration/index.js.map +0 -1
  679. package/dist/patterns/process/index.cjs +0 -21
  680. package/dist/patterns/process/index.cjs.map +0 -1
  681. package/dist/patterns/process/index.d.cts +0 -1
  682. package/dist/patterns/process/index.d.ts +0 -1
  683. package/dist/patterns/process/index.js +0 -3
  684. package/dist/patterns/process/index.js.map +0 -1
  685. package/dist/patterns/reactive-layout/index.cjs +0 -21
  686. package/dist/patterns/reactive-layout/index.cjs.map +0 -1
  687. package/dist/patterns/reactive-layout/index.d.cts +0 -1
  688. package/dist/patterns/reactive-layout/index.d.ts +0 -1
  689. package/dist/patterns/reactive-layout/index.js +0 -3
  690. package/dist/patterns/reactive-layout/index.js.map +0 -1
  691. package/dist/patterns/reduction/index.cjs +0 -21
  692. package/dist/patterns/reduction/index.cjs.map +0 -1
  693. package/dist/patterns/reduction/index.d.cts +0 -1
  694. package/dist/patterns/reduction/index.d.ts +0 -1
  695. package/dist/patterns/reduction/index.js +0 -3
  696. package/dist/patterns/reduction/index.js.map +0 -1
  697. package/dist/patterns/surface/index.cjs +0 -21
  698. package/dist/patterns/surface/index.cjs.map +0 -1
  699. package/dist/patterns/surface/index.d.cts +0 -1
  700. package/dist/patterns/surface/index.d.ts +0 -1
  701. package/dist/patterns/surface/index.js +0 -3
  702. package/dist/patterns/surface/index.js.map +0 -1
  703. package/dist/patterns/topology-view/index.cjs +0 -21
  704. package/dist/patterns/topology-view/index.cjs.map +0 -1
  705. package/dist/patterns/topology-view/index.d.cts +0 -1
  706. package/dist/patterns/topology-view/index.d.ts +0 -1
  707. package/dist/patterns/topology-view/index.js +0 -3
  708. package/dist/patterns/topology-view/index.js.map +0 -1
  709. package/dist/testing/index.cjs +0 -21
  710. package/dist/testing/index.cjs.map +0 -1
  711. package/dist/testing/index.d.cts +0 -1
  712. package/dist/testing/index.d.ts +0 -1
  713. package/dist/testing/index.js +0 -3
  714. package/dist/testing/index.js.map +0 -1
@@ -1,8 +1,19 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
8
+ var __typeError = (msg) => {
9
+ throw TypeError(msg);
10
+ };
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
+ var __export = (target, all) => {
14
+ for (var name in all)
15
+ __defProp(target, name, { get: all[name], enumerable: true });
16
+ };
6
17
  var __copyProps = (to, from, except, desc) => {
7
18
  if (from && typeof from === "object" || typeof from === "function") {
8
19
  for (let key of __getOwnPropNames(from))
@@ -11,11 +22,2222 @@ var __copyProps = (to, from, except, desc) => {
11
22
  }
12
23
  return to;
13
24
  };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
25
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
27
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
28
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
29
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
30
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
31
+ var __runInitializers = (array, flags, self, value) => {
32
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
33
+ return value;
34
+ };
35
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
36
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
37
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
38
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
39
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
40
+ return __privateGet(this, extra);
41
+ }, set [name](x) {
42
+ return __privateSet(this, extra, x);
43
+ } }, name));
44
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
45
+ for (var i = decorators.length - 1; i >= 0; i--) {
46
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
47
+ if (k) {
48
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
49
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
50
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
51
+ }
52
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
53
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
54
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
55
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
56
+ }
57
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
58
+ };
59
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
60
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
61
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
62
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
63
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
16
64
 
17
65
  // src/compat/nestjs/index.ts
18
66
  var nestjs_exports = {};
67
+ __export(nestjs_exports, {
68
+ ACTOR_KEY: () => ACTOR_KEY,
69
+ COMMAND_HANDLERS: () => COMMAND_HANDLERS,
70
+ CQRS_EVENT_HANDLERS: () => CQRS_EVENT_HANDLERS,
71
+ CRON_HANDLERS: () => CRON_HANDLERS,
72
+ CommandHandler: () => CommandHandler,
73
+ EVENT_HANDLERS: () => EVENT_HANDLERS,
74
+ EventHandler: () => EventHandler,
75
+ GRAPHREFLY_REQUEST_GRAPH: () => GRAPHREFLY_REQUEST_GRAPH,
76
+ GRAPHREFLY_ROOT_GRAPH: () => GRAPHREFLY_ROOT_GRAPH,
77
+ GraphCron: () => GraphCron,
78
+ GraphInterval: () => GraphInterval,
79
+ GraphReflyEventExplorer: () => GraphReflyEventExplorer,
80
+ GraphReflyGuard: () => GraphReflyGuard,
81
+ GraphReflyGuardImpl: () => GraphReflyGuardImpl,
82
+ GraphReflyModule: () => GraphReflyModule,
83
+ INTERVAL_HANDLERS: () => INTERVAL_HANDLERS,
84
+ InjectCqrsGraph: () => InjectCqrsGraph,
85
+ InjectGraph: () => InjectGraph,
86
+ InjectNode: () => InjectNode,
87
+ ObserveGateway: () => ObserveGateway,
88
+ OnGraphEvent: () => OnGraphEvent,
89
+ QUERY_HANDLERS: () => QUERY_HANDLERS,
90
+ QueryHandler: () => QueryHandler,
91
+ SAGA_HANDLERS: () => SAGA_HANDLERS,
92
+ SagaHandler: () => SagaHandler,
93
+ fromHeader: () => fromHeader,
94
+ fromJwtPayload: () => fromJwtPayload,
95
+ getActor: () => getActor,
96
+ getGraphToken: () => getGraphToken,
97
+ getNodeToken: () => getNodeToken,
98
+ observeSSE: () => observeSSE,
99
+ observeSubscription: () => observeSubscription,
100
+ toObservable: () => toObservable
101
+ });
19
102
  module.exports = __toCommonJS(nestjs_exports);
20
- __reExport(nestjs_exports, require("@graphrefly/pure-ts/compat/nestjs"), module.exports);
103
+
104
+ // src/base/composition/observable.ts
105
+ var import_core = require("@graphrefly/pure-ts/core");
106
+ var import_rxjs = require("rxjs");
107
+ function toObservable(node4, options) {
108
+ if (options?.raw) {
109
+ return new import_rxjs.Observable((subscriber) => {
110
+ const unsub = node4.subscribe((msgs) => {
111
+ if (subscriber.closed) return;
112
+ subscriber.next(msgs);
113
+ for (const m of msgs) {
114
+ if (m[0] === import_core.ERROR) {
115
+ subscriber.error(m[1]);
116
+ return;
117
+ }
118
+ if (m[0] === import_core.COMPLETE) {
119
+ subscriber.complete();
120
+ return;
121
+ }
122
+ }
123
+ });
124
+ return unsub;
125
+ });
126
+ }
127
+ return new import_rxjs.Observable((subscriber) => {
128
+ const unsub = node4.subscribe((msgs) => {
129
+ for (const m of msgs) {
130
+ if (subscriber.closed) return;
131
+ if (m[0] === import_core.DATA) {
132
+ subscriber.next(m[1]);
133
+ } else if (m[0] === import_core.ERROR) {
134
+ subscriber.error(m[1]);
135
+ return;
136
+ } else if (m[0] === import_core.COMPLETE) {
137
+ subscriber.complete();
138
+ return;
139
+ }
140
+ }
141
+ });
142
+ return unsub;
143
+ });
144
+ }
145
+
146
+ // src/compat/nestjs/decorators.ts
147
+ var import_common = require("@nestjs/common");
148
+
149
+ // src/compat/nestjs/tokens.ts
150
+ var GRAPHREFLY_ROOT_GRAPH = /* @__PURE__ */ Symbol.for("graphrefly:root-graph");
151
+ var GRAPHREFLY_REQUEST_GRAPH = /* @__PURE__ */ Symbol.for("graphrefly:request-graph");
152
+ function getGraphToken(name) {
153
+ return /* @__PURE__ */ Symbol.for(`graphrefly:graph:${name}`);
154
+ }
155
+ function getNodeToken(path) {
156
+ return /* @__PURE__ */ Symbol.for(`graphrefly:node:${path}`);
157
+ }
158
+
159
+ // src/compat/nestjs/decorators.ts
160
+ var EVENT_HANDLERS = /* @__PURE__ */ new Map();
161
+ var INTERVAL_HANDLERS = /* @__PURE__ */ new Map();
162
+ var CRON_HANDLERS = /* @__PURE__ */ new Map();
163
+ var COMMAND_HANDLERS = /* @__PURE__ */ new Map();
164
+ var CQRS_EVENT_HANDLERS = /* @__PURE__ */ new Map();
165
+ var QUERY_HANDLERS = /* @__PURE__ */ new Map();
166
+ var SAGA_HANDLERS = /* @__PURE__ */ new Map();
167
+ function InjectGraph(name) {
168
+ if (name === "request") return (0, import_common.Inject)(GRAPHREFLY_REQUEST_GRAPH);
169
+ return (0, import_common.Inject)(name ? getGraphToken(name) : GRAPHREFLY_ROOT_GRAPH);
170
+ }
171
+ function InjectCqrsGraph(name) {
172
+ return (0, import_common.Inject)(getGraphToken(name));
173
+ }
174
+ function InjectNode(path) {
175
+ return (0, import_common.Inject)(getNodeToken(path));
176
+ }
177
+ function OnGraphEvent(nodeName) {
178
+ return (_value, context) => {
179
+ const methodKey = context.name;
180
+ context.addInitializer(function() {
181
+ const ctor = this.constructor;
182
+ const existing = EVENT_HANDLERS.get(ctor) ?? [];
183
+ existing.push({ nodeName, methodKey });
184
+ EVENT_HANDLERS.set(ctor, existing);
185
+ });
186
+ };
187
+ }
188
+ function GraphInterval(ms) {
189
+ return (_value, context) => {
190
+ const methodKey = context.name;
191
+ context.addInitializer(function() {
192
+ const ctor = this.constructor;
193
+ const existing = INTERVAL_HANDLERS.get(ctor) ?? [];
194
+ existing.push({ ms, methodKey });
195
+ INTERVAL_HANDLERS.set(ctor, existing);
196
+ });
197
+ };
198
+ }
199
+ function GraphCron(expr) {
200
+ return (_value, context) => {
201
+ const methodKey = context.name;
202
+ context.addInitializer(function() {
203
+ const ctor = this.constructor;
204
+ const existing = CRON_HANDLERS.get(ctor) ?? [];
205
+ existing.push({ expr, methodKey });
206
+ CRON_HANDLERS.set(ctor, existing);
207
+ });
208
+ };
209
+ }
210
+ function CommandHandler(cqrsName, commandName) {
211
+ return (_value, context) => {
212
+ const methodKey = context.name;
213
+ context.addInitializer(function() {
214
+ const ctor = this.constructor;
215
+ const existing = COMMAND_HANDLERS.get(ctor) ?? [];
216
+ existing.push({ cqrsName, commandName, methodKey });
217
+ COMMAND_HANDLERS.set(ctor, existing);
218
+ });
219
+ };
220
+ }
221
+ function EventHandler(cqrsName, eventName) {
222
+ return (_value, context) => {
223
+ const methodKey = context.name;
224
+ context.addInitializer(function() {
225
+ const ctor = this.constructor;
226
+ const existing = CQRS_EVENT_HANDLERS.get(ctor) ?? [];
227
+ existing.push({ cqrsName, eventName, methodKey });
228
+ CQRS_EVENT_HANDLERS.set(ctor, existing);
229
+ });
230
+ };
231
+ }
232
+ function QueryHandler(cqrsName, projectionName) {
233
+ return (_value, context) => {
234
+ const methodKey = context.name;
235
+ context.addInitializer(function() {
236
+ const ctor = this.constructor;
237
+ const existing = QUERY_HANDLERS.get(ctor) ?? [];
238
+ existing.push({ cqrsName, projectionName, methodKey });
239
+ QUERY_HANDLERS.set(ctor, existing);
240
+ });
241
+ };
242
+ }
243
+ function SagaHandler(cqrsName, sagaName, eventNames) {
244
+ return (_value, context) => {
245
+ const methodKey = context.name;
246
+ context.addInitializer(function() {
247
+ const ctor = this.constructor;
248
+ const existing = SAGA_HANDLERS.get(ctor) ?? [];
249
+ existing.push({ cqrsName, eventNames, sagaName, methodKey });
250
+ SAGA_HANDLERS.set(ctor, existing);
251
+ });
252
+ };
253
+ }
254
+
255
+ // src/compat/nestjs/explorer.ts
256
+ var import_core3 = require("@graphrefly/pure-ts/core");
257
+ var import_extra = require("@graphrefly/pure-ts/extra");
258
+
259
+ // src/base/sources/event/cron.ts
260
+ var import_core2 = require("@graphrefly/pure-ts/core");
261
+ function sourceOpts(opts) {
262
+ return { describeKind: "producer", ...opts };
263
+ }
264
+ function parseField(field, min, max) {
265
+ const result = /* @__PURE__ */ new Set();
266
+ for (const part of field.split(",")) {
267
+ const [range, stepStr] = part.split("/");
268
+ const step = stepStr ? Number.parseInt(stepStr, 10) : 1;
269
+ if (Number.isNaN(step) || step < 1) throw new Error(`Invalid cron step: ${part}`);
270
+ let start;
271
+ let end;
272
+ if (range === "*") {
273
+ start = min;
274
+ end = max;
275
+ } else if (range.includes("-")) {
276
+ const [a, b] = range.split("-");
277
+ start = Number.parseInt(a, 10);
278
+ end = Number.parseInt(b, 10);
279
+ } else {
280
+ start = Number.parseInt(range, 10);
281
+ end = start;
282
+ }
283
+ if (Number.isNaN(start) || Number.isNaN(end)) throw new Error(`Invalid cron field: ${field}`);
284
+ if (start < min || end > max)
285
+ throw new Error(`Cron field out of range: ${field} (${min}-${max})`);
286
+ if (start > end) throw new Error(`Invalid cron range: ${start}-${end} in ${field}`);
287
+ for (let i = start; i <= end; i += step) result.add(i);
288
+ }
289
+ return result;
290
+ }
291
+ function parseCron(expr) {
292
+ const parts = expr.trim().split(/\s+/);
293
+ if (parts.length !== 5) throw new Error(`Invalid cron: expected 5 fields, got ${parts.length}`);
294
+ return {
295
+ minutes: parseField(parts[0], 0, 59),
296
+ hours: parseField(parts[1], 0, 23),
297
+ daysOfMonth: parseField(parts[2], 1, 31),
298
+ months: parseField(parts[3], 1, 12),
299
+ daysOfWeek: parseField(parts[4], 0, 6)
300
+ };
301
+ }
302
+ function matchesCron(schedule, date) {
303
+ return schedule.minutes.has(date.getMinutes()) && schedule.hours.has(date.getHours()) && schedule.daysOfMonth.has(date.getDate()) && schedule.months.has(date.getMonth() + 1) && schedule.daysOfWeek.has(date.getDay());
304
+ }
305
+ function fromCron(expr, opts) {
306
+ const schedule = parseCron(expr);
307
+ const { tickMs: tickOpt, output, ...rest } = opts ?? {};
308
+ const tickMs = tickOpt ?? 6e4;
309
+ const emitDate = output === "date";
310
+ return (0, import_core2.node)(
311
+ (_data, a) => {
312
+ let lastFiredKey = -1;
313
+ const check = () => {
314
+ const now = /* @__PURE__ */ new Date();
315
+ const key = now.getFullYear() * 1e8 + (now.getMonth() + 1) * 1e6 + now.getDate() * 1e4 + now.getHours() * 100 + now.getMinutes();
316
+ if (key !== lastFiredKey && matchesCron(schedule, now)) {
317
+ lastFiredKey = key;
318
+ a.emit(emitDate ? now : (0, import_core2.wallClockNs)());
319
+ }
320
+ };
321
+ check();
322
+ const id = setInterval(check, tickMs);
323
+ return () => clearInterval(id);
324
+ },
325
+ { ...sourceOpts(rest), name: rest.name ?? `cron:${expr}` }
326
+ );
327
+ }
328
+
329
+ // src/compat/nestjs/explorer.ts
330
+ var scheduleSeq = 0;
331
+ var GraphReflyEventExplorer = class {
332
+ constructor(graph, moduleRef) {
333
+ this.graph = graph;
334
+ this.moduleRef = moduleRef;
335
+ }
336
+ disposers = [];
337
+ scheduleNodeNames = [];
338
+ onModuleInit() {
339
+ this.wireEvents();
340
+ this.wireIntervals();
341
+ this.wireCrons();
342
+ this.wireCqrsCommands();
343
+ this.wireCqrsEvents();
344
+ this.wireCqrsQueries();
345
+ this.wireCqrsSagas();
346
+ }
347
+ onModuleDestroy() {
348
+ for (const dispose of this.disposers) dispose();
349
+ this.disposers.length = 0;
350
+ for (const name of this.scheduleNodeNames) {
351
+ try {
352
+ this.graph.remove(name);
353
+ } catch {
354
+ }
355
+ }
356
+ this.scheduleNodeNames.length = 0;
357
+ }
358
+ // -----------------------------------------------------------------------
359
+ // @OnGraphEvent — reactive subscription via graph.observe()
360
+ // -----------------------------------------------------------------------
361
+ wireEvents() {
362
+ for (const [ctor, metas] of EVENT_HANDLERS) {
363
+ const instance = this.resolveInstance(ctor);
364
+ if (!instance) continue;
365
+ for (const meta of metas) {
366
+ this.wireEventHandler(instance, meta);
367
+ }
368
+ }
369
+ }
370
+ wireEventHandler(instance, meta) {
371
+ const method = instance[meta.methodKey];
372
+ if (typeof method !== "function") return;
373
+ const bound = method.bind(instance);
374
+ const handle = this.observeNode(meta.nodeName);
375
+ const unsub = handle.subscribe((msgs) => {
376
+ for (const m of msgs) {
377
+ if (m[0] === import_core3.DATA) {
378
+ bound(m[1]);
379
+ }
380
+ }
381
+ });
382
+ this.disposers.push(unsub);
383
+ }
384
+ // -----------------------------------------------------------------------
385
+ // @GraphInterval — reactive via fromTimer central timer primitive
386
+ // -----------------------------------------------------------------------
387
+ wireIntervals() {
388
+ for (const [ctor, metas] of INTERVAL_HANDLERS) {
389
+ const instance = this.resolveInstance(ctor);
390
+ if (!instance) continue;
391
+ for (const meta of metas) {
392
+ this.wireIntervalHandler(instance, ctor, meta);
393
+ }
394
+ }
395
+ }
396
+ wireIntervalHandler(instance, ctor, meta) {
397
+ const method = instance[meta.methodKey];
398
+ if (typeof method !== "function") return;
399
+ const bound = method.bind(instance);
400
+ const className = ctor.name ?? "anonymous";
401
+ const nodeName = `__schedule__.${className}.${String(meta.methodKey)}.${scheduleSeq++}`;
402
+ const timerNode = (0, import_extra.fromTimer)(meta.ms, { period: meta.ms, name: nodeName });
403
+ this.graph.add(timerNode);
404
+ this.scheduleNodeNames.push(nodeName);
405
+ const handle = this.observeNode(nodeName);
406
+ const unsub = handle.subscribe((msgs) => {
407
+ for (const m of msgs) {
408
+ if (m[0] === import_core3.DATA) bound(m[1]);
409
+ }
410
+ });
411
+ this.disposers.push(unsub);
412
+ }
413
+ // -----------------------------------------------------------------------
414
+ // @GraphCron — reactive via fromCron central timer primitive
415
+ // -----------------------------------------------------------------------
416
+ wireCrons() {
417
+ for (const [ctor, metas] of CRON_HANDLERS) {
418
+ const instance = this.resolveInstance(ctor);
419
+ if (!instance) continue;
420
+ for (const meta of metas) {
421
+ this.wireCronHandler(instance, ctor, meta);
422
+ }
423
+ }
424
+ }
425
+ wireCronHandler(instance, ctor, meta) {
426
+ const method = instance[meta.methodKey];
427
+ if (typeof method !== "function") return;
428
+ const bound = method.bind(instance);
429
+ const className = ctor.name ?? "anonymous";
430
+ const nodeName = `__schedule__.${className}.${String(meta.methodKey)}.${scheduleSeq++}`;
431
+ const cronNode = fromCron(meta.expr, { name: nodeName });
432
+ this.graph.add(cronNode);
433
+ this.scheduleNodeNames.push(nodeName);
434
+ const handle = this.observeNode(nodeName);
435
+ const unsub = handle.subscribe((msgs) => {
436
+ for (const m of msgs) {
437
+ if (m[0] === import_core3.DATA) bound(m[1]);
438
+ }
439
+ });
440
+ this.disposers.push(unsub);
441
+ }
442
+ // -----------------------------------------------------------------------
443
+ // @CommandHandler — register method as CqrsGraph command handler
444
+ // -----------------------------------------------------------------------
445
+ wireCqrsCommands() {
446
+ for (const [ctor, metas] of COMMAND_HANDLERS) {
447
+ const instance = this.resolveInstance(ctor);
448
+ if (!instance) continue;
449
+ for (const meta of metas) {
450
+ this.wireCqrsCommand(instance, meta);
451
+ }
452
+ }
453
+ }
454
+ wireCqrsCommand(instance, meta) {
455
+ const method = instance[meta.methodKey];
456
+ if (typeof method !== "function") return;
457
+ const bound = method.bind(instance);
458
+ const cqrsGraph = this.resolveCqrsGraph(meta.cqrsName);
459
+ if (!cqrsGraph) return;
460
+ cqrsGraph.command(meta.commandName, bound);
461
+ }
462
+ // -----------------------------------------------------------------------
463
+ // @EventHandler — subscribe method to CQRS event stream
464
+ // -----------------------------------------------------------------------
465
+ wireCqrsEvents() {
466
+ for (const [ctor, metas] of CQRS_EVENT_HANDLERS) {
467
+ const instance = this.resolveInstance(ctor);
468
+ if (!instance) continue;
469
+ for (const meta of metas) {
470
+ this.wireCqrsEventHandler(instance, meta);
471
+ }
472
+ }
473
+ }
474
+ wireCqrsEventHandler(instance, meta) {
475
+ const method = instance[meta.methodKey];
476
+ if (typeof method !== "function") return;
477
+ const bound = method.bind(instance);
478
+ const cqrsGraph = this.resolveCqrsGraph(meta.cqrsName);
479
+ if (!cqrsGraph) return;
480
+ cqrsGraph.event(meta.eventName);
481
+ const eventNode = cqrsGraph.resolve(meta.eventName);
482
+ const existingEntries = eventNode.cache;
483
+ let lastSeq = existingEntries && existingEntries.length > 0 ? existingEntries[existingEntries.length - 1].seq : 0;
484
+ const handle = this.observeNodeOn(cqrsGraph, meta.eventName);
485
+ const unsub = handle.subscribe((msgs) => {
486
+ for (const m of msgs) {
487
+ if (m[0] === import_core3.DATA) {
488
+ const entries = m[1];
489
+ for (const entry of entries) {
490
+ if (entry.seq > lastSeq) {
491
+ bound(entry);
492
+ lastSeq = entry.seq;
493
+ }
494
+ }
495
+ }
496
+ }
497
+ });
498
+ this.disposers.push(unsub);
499
+ }
500
+ // -----------------------------------------------------------------------
501
+ // @QueryHandler — subscribe method to CQRS projection changes
502
+ // -----------------------------------------------------------------------
503
+ wireCqrsQueries() {
504
+ for (const [ctor, metas] of QUERY_HANDLERS) {
505
+ const instance = this.resolveInstance(ctor);
506
+ if (!instance) continue;
507
+ for (const meta of metas) {
508
+ this.wireCqrsQuery(instance, meta);
509
+ }
510
+ }
511
+ }
512
+ wireCqrsQuery(instance, meta) {
513
+ const method = instance[meta.methodKey];
514
+ if (typeof method !== "function") return;
515
+ const bound = method.bind(instance);
516
+ const cqrsGraph = this.resolveCqrsGraph(meta.cqrsName);
517
+ if (!cqrsGraph) return;
518
+ const handle = this.observeNodeOn(cqrsGraph, meta.projectionName);
519
+ const unsub = handle.subscribe((msgs) => {
520
+ for (const m of msgs) {
521
+ if (m[0] === import_core3.DATA) {
522
+ bound(m[1]);
523
+ }
524
+ }
525
+ });
526
+ this.disposers.push(unsub);
527
+ }
528
+ // -----------------------------------------------------------------------
529
+ // @SagaHandler — register method as CqrsGraph saga (subgraph side effect)
530
+ // -----------------------------------------------------------------------
531
+ wireCqrsSagas() {
532
+ for (const [ctor, metas] of SAGA_HANDLERS) {
533
+ const instance = this.resolveInstance(ctor);
534
+ if (!instance) continue;
535
+ for (const meta of metas) {
536
+ this.wireCqrsSaga(instance, meta);
537
+ }
538
+ }
539
+ }
540
+ wireCqrsSaga(instance, meta) {
541
+ const method = instance[meta.methodKey];
542
+ if (typeof method !== "function") return;
543
+ const bound = method.bind(instance);
544
+ const cqrsGraph = this.resolveCqrsGraph(meta.cqrsName);
545
+ if (!cqrsGraph) return;
546
+ cqrsGraph.saga(meta.sagaName, meta.eventNames, bound);
547
+ }
548
+ // -----------------------------------------------------------------------
549
+ // Helpers
550
+ // -----------------------------------------------------------------------
551
+ observeNode(name) {
552
+ return this.graph.observe(name);
553
+ }
554
+ observeNodeOn(graph, name) {
555
+ return graph.observe(name);
556
+ }
557
+ resolveCqrsGraph(name) {
558
+ try {
559
+ return this.moduleRef.get(getGraphToken(name), { strict: false });
560
+ } catch {
561
+ console.warn(
562
+ `[GraphReFly] CqrsGraph "${name}" not found in DI \u2014 did you import GraphReflyModule.forCqrs({ name: "${name}" })?`
563
+ );
564
+ return null;
565
+ }
566
+ }
567
+ resolveInstance(ctor) {
568
+ try {
569
+ return this.moduleRef.get(ctor, { strict: false });
570
+ } catch {
571
+ return null;
572
+ }
573
+ }
574
+ };
575
+
576
+ // src/compat/nestjs/gateway.ts
577
+ var import_core5 = require("@graphrefly/pure-ts/core");
578
+
579
+ // src/base/composition/backpressure.ts
580
+ var import_core4 = require("@graphrefly/pure-ts/core");
581
+ var nextLockId = 0;
582
+ function createWatermarkController(sendUp, opts) {
583
+ if (opts.highWaterMark < 1) throw new RangeError("highWaterMark must be >= 1");
584
+ if (opts.lowWaterMark < 0) throw new RangeError("lowWaterMark must be >= 0");
585
+ if (opts.lowWaterMark >= opts.highWaterMark)
586
+ throw new RangeError("lowWaterMark must be < highWaterMark");
587
+ const lockId = /* @__PURE__ */ Symbol(`bp-${++nextLockId}`);
588
+ let pending = 0;
589
+ let paused = false;
590
+ return {
591
+ onEnqueue() {
592
+ pending += 1;
593
+ if (!paused && pending >= opts.highWaterMark) {
594
+ paused = true;
595
+ sendUp([[import_core4.PAUSE, lockId]]);
596
+ return true;
597
+ }
598
+ return false;
599
+ },
600
+ onDequeue() {
601
+ if (pending > 0) pending -= 1;
602
+ if (paused && pending <= opts.lowWaterMark) {
603
+ paused = false;
604
+ sendUp([[import_core4.RESUME, lockId]]);
605
+ return true;
606
+ }
607
+ return false;
608
+ },
609
+ get pending() {
610
+ return pending;
611
+ },
612
+ get paused() {
613
+ return paused;
614
+ },
615
+ dispose() {
616
+ if (paused) {
617
+ paused = false;
618
+ sendUp([[import_core4.RESUME, lockId]]);
619
+ }
620
+ }
621
+ };
622
+ }
623
+
624
+ // src/compat/nestjs/gateway.ts
625
+ function observeSSE(graph, path, opts) {
626
+ const { actor, serialize = defaultSerialize, keepAliveMs, signal } = opts ?? {};
627
+ const encoder = new TextEncoder();
628
+ let stop;
629
+ const useBackpressure = opts?.highWaterMark != null;
630
+ let wm;
631
+ let pullResolve;
632
+ const taggedBuf = [];
633
+ let closed = false;
634
+ return new ReadableStream({
635
+ start(controller) {
636
+ let keepAlive;
637
+ let unsub = () => {
638
+ };
639
+ const close = () => {
640
+ if (closed) return;
641
+ closed = true;
642
+ if (keepAlive !== void 0) clearInterval(keepAlive);
643
+ signal?.removeEventListener("abort", onAbort);
644
+ unsub();
645
+ wm?.dispose();
646
+ pullResolve?.();
647
+ pullResolve = void 0;
648
+ for (const entry of taggedBuf) controller.enqueue(entry.frame);
649
+ taggedBuf.length = 0;
650
+ controller.close();
651
+ };
652
+ stop = close;
653
+ const onAbort = () => close();
654
+ const handle = graph.observe(path, { actor });
655
+ if (useBackpressure) {
656
+ wm = createWatermarkController((msgs) => handle.up(msgs), {
657
+ highWaterMark: opts.highWaterMark,
658
+ lowWaterMark: opts.lowWaterMark ?? Math.floor(opts.highWaterMark / 2)
659
+ });
660
+ }
661
+ unsub = handle.subscribe((msgs) => {
662
+ for (const msg of msgs) {
663
+ if (closed) return;
664
+ const t = msg[0];
665
+ if (t === import_core5.DATA) {
666
+ const frame = encoder.encode(sseFrame("data", serialize(msg[1])));
667
+ if (useBackpressure) {
668
+ taggedBuf.push({ frame, counted: true });
669
+ wm.onEnqueue();
670
+ pullResolve?.();
671
+ pullResolve = void 0;
672
+ } else {
673
+ controller.enqueue(frame);
674
+ }
675
+ } else if (t === import_core5.ERROR) {
676
+ const frame = encoder.encode(sseFrame("error", serialize(msg[1])));
677
+ if (useBackpressure) {
678
+ taggedBuf.push({ frame, counted: false });
679
+ pullResolve?.();
680
+ pullResolve = void 0;
681
+ } else {
682
+ controller.enqueue(frame);
683
+ }
684
+ close();
685
+ return;
686
+ } else if (t === import_core5.COMPLETE || t === import_core5.TEARDOWN) {
687
+ if (t === import_core5.COMPLETE) {
688
+ const frame = encoder.encode(sseFrame("complete"));
689
+ if (useBackpressure) {
690
+ taggedBuf.push({ frame, counted: false });
691
+ pullResolve?.();
692
+ pullResolve = void 0;
693
+ } else {
694
+ controller.enqueue(frame);
695
+ }
696
+ }
697
+ close();
698
+ return;
699
+ }
700
+ }
701
+ });
702
+ if (keepAliveMs !== void 0 && keepAliveMs > 0) {
703
+ keepAlive = setInterval(() => {
704
+ if (closed) return;
705
+ if (useBackpressure) {
706
+ taggedBuf.push({ frame: encoder.encode(": keepalive\n\n"), counted: false });
707
+ pullResolve?.();
708
+ pullResolve = void 0;
709
+ } else {
710
+ controller.enqueue(encoder.encode(": keepalive\n\n"));
711
+ }
712
+ }, keepAliveMs);
713
+ }
714
+ if (signal?.aborted) onAbort();
715
+ else signal?.addEventListener("abort", onAbort, { once: true });
716
+ },
717
+ pull(controller) {
718
+ if (!useBackpressure) return;
719
+ if (closed) return;
720
+ if (taggedBuf.length > 0) {
721
+ const entry = taggedBuf.shift();
722
+ controller.enqueue(entry.frame);
723
+ if (entry.counted) wm.onDequeue();
724
+ return;
725
+ }
726
+ return new Promise((resolve) => {
727
+ pullResolve = resolve;
728
+ });
729
+ },
730
+ cancel() {
731
+ try {
732
+ stop?.();
733
+ } catch {
734
+ }
735
+ }
736
+ });
737
+ }
738
+ function observeSubscription(graph, path, opts) {
739
+ const { actor, filter } = opts ?? {};
740
+ const queue = [];
741
+ const waiters = [];
742
+ let disposed = false;
743
+ const handle = graph.observe(path, { actor });
744
+ const wm = opts?.highWaterMark != null ? createWatermarkController((msgs) => handle.up(msgs), {
745
+ highWaterMark: opts.highWaterMark,
746
+ lowWaterMark: opts.lowWaterMark ?? Math.floor(opts.highWaterMark / 2)
747
+ }) : void 0;
748
+ const dispose = () => {
749
+ if (disposed) return;
750
+ disposed = true;
751
+ wm?.dispose();
752
+ unsub();
753
+ };
754
+ const push = (item) => {
755
+ if (disposed) return;
756
+ if (waiters.length > 0) {
757
+ const w = waiters.shift();
758
+ if (item.done && item.error) w.reject(item.error);
759
+ else if (item.done) w.resolve({ done: true, value: void 0 });
760
+ else w.resolve({ done: false, value: item.value });
761
+ } else {
762
+ queue.push(item);
763
+ if (!item.done) wm?.onEnqueue();
764
+ }
765
+ };
766
+ const unsub = handle.subscribe((msgs) => {
767
+ for (const msg of msgs) {
768
+ const t = msg[0];
769
+ if (t === import_core5.DATA) {
770
+ const value = msg[1];
771
+ if (filter && !filter(value)) continue;
772
+ push({ done: false, value });
773
+ } else if (t === import_core5.ERROR) {
774
+ const err = msg[1] instanceof Error ? msg[1] : new Error(String(msg[1]));
775
+ push({ done: true, error: err });
776
+ dispose();
777
+ return;
778
+ } else if (t === import_core5.COMPLETE || t === import_core5.TEARDOWN) {
779
+ push({ done: true });
780
+ dispose();
781
+ return;
782
+ }
783
+ }
784
+ });
785
+ const iterator = {
786
+ next() {
787
+ if (queue.length > 0) {
788
+ const item = queue.shift();
789
+ if (!item.done) wm?.onDequeue();
790
+ if (item.done && item.error) return Promise.reject(item.error);
791
+ return Promise.resolve(
792
+ item.done ? { done: true, value: void 0 } : { done: false, value: item.value }
793
+ );
794
+ }
795
+ if (disposed) return Promise.resolve({ done: true, value: void 0 });
796
+ return new Promise((resolve, reject) => {
797
+ waiters.push({ resolve, reject });
798
+ });
799
+ },
800
+ return() {
801
+ dispose();
802
+ for (const w of waiters) w.resolve({ done: true, value: void 0 });
803
+ waiters.length = 0;
804
+ return Promise.resolve({ done: true, value: void 0 });
805
+ },
806
+ throw(err) {
807
+ dispose();
808
+ return Promise.reject(err);
809
+ },
810
+ [Symbol.asyncIterator]() {
811
+ return this;
812
+ }
813
+ };
814
+ return iterator;
815
+ }
816
+ var ObserveGateway = class {
817
+ constructor(graph, opts) {
818
+ this.graph = graph;
819
+ this.extractActor = opts?.extractActor ?? (() => void 0);
820
+ this.parse = opts?.parse ?? defaultParseCommand;
821
+ this.highWaterMark = opts?.highWaterMark;
822
+ this.lowWaterMark = opts?.lowWaterMark;
823
+ }
824
+ clients = /* @__PURE__ */ new Map();
825
+ extractActor;
826
+ parse;
827
+ highWaterMark;
828
+ lowWaterMark;
829
+ /**
830
+ * Register a new client. Call from `handleConnection`.
831
+ */
832
+ handleConnection(client) {
833
+ if (!this.clients.has(client)) {
834
+ this.clients.set(client, /* @__PURE__ */ new Map());
835
+ }
836
+ }
837
+ /**
838
+ * Unregister a client and dispose all its subscriptions. Call from `handleDisconnect`.
839
+ */
840
+ handleDisconnect(client) {
841
+ const subs = this.clients.get(client);
842
+ if (!subs) return;
843
+ for (const entry of subs.values()) {
844
+ entry.wm?.dispose();
845
+ entry.unsub();
846
+ }
847
+ this.clients.delete(client);
848
+ }
849
+ /**
850
+ * Handle an incoming client message (subscribe/unsubscribe/ack command).
851
+ *
852
+ * @param client - The WebSocket client reference.
853
+ * @param raw - Raw message data (string or parsed object).
854
+ * @param send - Function to send a message back to the client.
855
+ * Defaults to `client.send(JSON.stringify(msg))`.
856
+ */
857
+ handleMessage(client, raw, send) {
858
+ const sender = send ?? defaultSend.bind(null, client);
859
+ let cmd;
860
+ try {
861
+ cmd = typeof raw === "string" ? this.parse(raw) : raw;
862
+ } catch {
863
+ sender({ type: "err", message: "invalid command" });
864
+ return;
865
+ }
866
+ if (cmd.type === "subscribe") {
867
+ this.subscribe(client, cmd.path, sender);
868
+ } else if (cmd.type === "unsubscribe") {
869
+ this.unsubscribe(client, cmd.path, sender);
870
+ } else if (cmd.type === "ack") {
871
+ this.ack(client, cmd.path, cmd.count ?? 1);
872
+ } else {
873
+ sender({ type: "err", message: `unknown command type: ${cmd.type}` });
874
+ }
875
+ }
876
+ /**
877
+ * Number of active subscriptions for a client. Useful for tests.
878
+ */
879
+ subscriptionCount(client) {
880
+ return this.clients.get(client)?.size ?? 0;
881
+ }
882
+ /**
883
+ * Dispose all clients and subscriptions.
884
+ */
885
+ destroy() {
886
+ for (const [client] of this.clients) {
887
+ this.handleDisconnect(client);
888
+ }
889
+ }
890
+ // -----------------------------------------------------------------------
891
+ // Internal
892
+ // -----------------------------------------------------------------------
893
+ subscribe(client, path, send) {
894
+ let subs = this.clients.get(client);
895
+ if (!subs) {
896
+ subs = /* @__PURE__ */ new Map();
897
+ this.clients.set(client, subs);
898
+ }
899
+ if (subs.has(path)) {
900
+ send({ type: "subscribed", path });
901
+ return;
902
+ }
903
+ const actor = this.extractActor(client);
904
+ let handle;
905
+ try {
906
+ handle = this.graph.observe(path, { actor });
907
+ } catch (err) {
908
+ const message = err instanceof Error ? err.message : String(err);
909
+ send({ type: "err", message });
910
+ return;
911
+ }
912
+ const wm = this.highWaterMark != null ? createWatermarkController((msgs) => handle.up(msgs), {
913
+ highWaterMark: this.highWaterMark,
914
+ lowWaterMark: this.lowWaterMark ?? Math.floor(this.highWaterMark / 2)
915
+ }) : void 0;
916
+ const cleanup = () => {
917
+ wm?.dispose();
918
+ unsub();
919
+ subs.delete(path);
920
+ };
921
+ const unsub = handle.subscribe((msgs) => {
922
+ for (const msg of msgs) {
923
+ const t = msg[0];
924
+ if (t === import_core5.DATA) {
925
+ wm?.onEnqueue();
926
+ trySend(send, { type: "data", path, value: msg[1] });
927
+ } else if (t === import_core5.ERROR) {
928
+ const errMsg = msg[1] instanceof Error ? msg[1].message : String(msg[1]);
929
+ trySend(send, { type: "error", path, error: errMsg });
930
+ cleanup();
931
+ return;
932
+ } else if (t === import_core5.COMPLETE || t === import_core5.TEARDOWN) {
933
+ trySend(send, { type: "complete", path });
934
+ cleanup();
935
+ return;
936
+ }
937
+ }
938
+ });
939
+ subs.set(path, { unsub, wm });
940
+ send({ type: "subscribed", path });
941
+ }
942
+ unsubscribe(client, path, send) {
943
+ const subs = this.clients.get(client);
944
+ const entry = subs?.get(path);
945
+ if (entry) {
946
+ entry.wm?.dispose();
947
+ entry.unsub();
948
+ subs.delete(path);
949
+ }
950
+ send({ type: "unsubscribed", path });
951
+ }
952
+ ack(client, path, count) {
953
+ const entry = this.clients.get(client)?.get(path);
954
+ if (!entry?.wm) return;
955
+ const n = Math.min(Math.max(0, Math.floor(count)), 1024);
956
+ for (let i = 0; i < n; i++) entry.wm.onDequeue();
957
+ }
958
+ };
959
+ function defaultSerialize(value) {
960
+ if (value instanceof Error) return value.message;
961
+ try {
962
+ return JSON.stringify(value);
963
+ } catch {
964
+ return String(value);
965
+ }
966
+ }
967
+ function sseFrame(event, data) {
968
+ let frame = `event: ${event}
969
+ `;
970
+ if (data !== void 0) {
971
+ for (const line of data.split("\n")) {
972
+ frame += `data: ${line}
973
+ `;
974
+ }
975
+ }
976
+ frame += "\n";
977
+ return frame;
978
+ }
979
+ function defaultParseCommand(data) {
980
+ return JSON.parse(data);
981
+ }
982
+ function defaultSend(client, msg) {
983
+ try {
984
+ client.send(JSON.stringify(msg));
985
+ } catch {
986
+ }
987
+ }
988
+ function trySend(send, msg) {
989
+ try {
990
+ send(msg);
991
+ } catch {
992
+ }
993
+ }
994
+
995
+ // src/compat/nestjs/guard.ts
996
+ var import_core6 = require("@graphrefly/pure-ts/core");
997
+ var ACTOR_KEY = "graphReflyActor";
998
+ function fromJwtPayload(mapping) {
999
+ return (context) => {
1000
+ const req = context.switchToHttp().getRequest();
1001
+ const user = req?.user;
1002
+ if (user == null) return void 0;
1003
+ if (mapping) return mapping(user);
1004
+ return user;
1005
+ };
1006
+ }
1007
+ function fromHeader(headerName = "x-graphrefly-actor") {
1008
+ return (context) => {
1009
+ const req = context.switchToHttp().getRequest();
1010
+ const raw = req?.headers?.[headerName.toLowerCase()];
1011
+ if (typeof raw !== "string" || raw.length === 0) return void 0;
1012
+ try {
1013
+ return JSON.parse(raw);
1014
+ } catch {
1015
+ return void 0;
1016
+ }
1017
+ };
1018
+ }
1019
+ function getActor(req) {
1020
+ const actor = req?.[ACTOR_KEY];
1021
+ return actor != null ? (0, import_core6.normalizeActor)(actor) : import_core6.DEFAULT_ACTOR;
1022
+ }
1023
+ var GraphReflyGuardImpl = class {
1024
+ constructor(extractor) {
1025
+ this.extractor = extractor;
1026
+ }
1027
+ canActivate(context) {
1028
+ const actor = (0, import_core6.normalizeActor)(this.extractor(context));
1029
+ const req = context.switchToHttp().getRequest();
1030
+ if (req != null) {
1031
+ req[ACTOR_KEY] = actor;
1032
+ }
1033
+ return true;
1034
+ }
1035
+ };
1036
+ function GraphReflyGuard(extractor) {
1037
+ return new GraphReflyGuardImpl(extractor ?? fromJwtPayload());
1038
+ }
1039
+
1040
+ // src/compat/nestjs/module.ts
1041
+ var import_graph3 = require("@graphrefly/pure-ts/graph");
1042
+ var import_common2 = require("@nestjs/common");
1043
+ var import_core9 = require("@nestjs/core");
1044
+
1045
+ // src/utils/cqrs/index.ts
1046
+ var import_core8 = require("@graphrefly/pure-ts/core");
1047
+ var import_extra3 = require("@graphrefly/pure-ts/extra");
1048
+ var import_graph2 = require("@graphrefly/pure-ts/graph");
1049
+
1050
+ // src/base/mutation/index.ts
1051
+ var import_core7 = require("@graphrefly/pure-ts/core");
1052
+ var import_extra2 = require("@graphrefly/pure-ts/extra");
1053
+ var import_graph = require("@graphrefly/pure-ts/graph");
1054
+ var DEFAULT_AUDIT_GUARD = (0, import_core7.policy)((allow, deny) => {
1055
+ allow("observe");
1056
+ allow("signal");
1057
+ deny("write");
1058
+ });
1059
+ function createAuditLog(opts) {
1060
+ const log = (0, import_extra2.reactiveLog)([], {
1061
+ name: opts.name,
1062
+ maxSize: opts.retainedLimit ?? 1024,
1063
+ guard: opts.guard ?? DEFAULT_AUDIT_GUARD,
1064
+ ...opts.versioning != null ? { versioning: opts.versioning } : {}
1065
+ });
1066
+ log.withLatest();
1067
+ if (opts.graph) {
1068
+ opts.graph.add(log.entries, { name: opts.name });
1069
+ }
1070
+ return log;
1071
+ }
1072
+ function deepFreeze(value) {
1073
+ if (value === null || typeof value !== "object" || Object.isFrozen(value)) return value;
1074
+ for (const k of Object.keys(value)) {
1075
+ deepFreeze(value[k]);
1076
+ }
1077
+ return Object.freeze(value);
1078
+ }
1079
+ function mutate(act, opts) {
1080
+ const { up, down } = typeof act === "function" ? { up: act, down: void 0 } : act;
1081
+ const freeze = opts.freeze ?? true;
1082
+ if (opts.frame === "inline") {
1083
+ return function wrapped(...args) {
1084
+ const sealed = freeze ? args.map(deepFreeze) : args;
1085
+ const t_ns = (0, import_core7.wallClockNs)();
1086
+ const seq = opts.seq ? bumpCursor(opts.seq) : void 0;
1087
+ try {
1088
+ const result = up(...sealed);
1089
+ if (opts.log && opts.onSuccessRecord) {
1090
+ appendAudit(
1091
+ opts.log,
1092
+ opts.onSuccessRecord,
1093
+ sealed,
1094
+ result,
1095
+ { t_ns, seq },
1096
+ opts.handlerVersion
1097
+ );
1098
+ }
1099
+ return result;
1100
+ } catch (err) {
1101
+ if (opts.log && opts.onFailureRecord) {
1102
+ const errorType = err instanceof Error ? err.name : typeof err;
1103
+ appendAudit(
1104
+ opts.log,
1105
+ opts.onFailureRecord,
1106
+ sealed,
1107
+ err,
1108
+ { t_ns, seq, errorType },
1109
+ opts.handlerVersion
1110
+ );
1111
+ }
1112
+ throw err;
1113
+ }
1114
+ };
1115
+ }
1116
+ return function wrapped(...args) {
1117
+ const sealed = freeze ? args.map(deepFreeze) : args;
1118
+ const t_ns = (0, import_core7.wallClockNs)();
1119
+ let result;
1120
+ let captured;
1121
+ let captureSet = false;
1122
+ let seq;
1123
+ try {
1124
+ (0, import_core7.batch)(() => {
1125
+ if (opts.seq) seq = bumpCursor(opts.seq);
1126
+ try {
1127
+ result = up(...sealed);
1128
+ if (opts.log && opts.onSuccessRecord) {
1129
+ appendAudit(
1130
+ opts.log,
1131
+ opts.onSuccessRecord,
1132
+ sealed,
1133
+ result,
1134
+ { t_ns, seq },
1135
+ opts.handlerVersion
1136
+ );
1137
+ }
1138
+ } catch (err) {
1139
+ captured = err;
1140
+ captureSet = true;
1141
+ throw err;
1142
+ }
1143
+ });
1144
+ } catch (outerErr) {
1145
+ if (captureSet && down) {
1146
+ try {
1147
+ down(...sealed);
1148
+ } catch (downErr) {
1149
+ console.error(
1150
+ `mutate: down hook threw \u2014 original action error preserved (${captured instanceof Error ? captured.name : typeof captured}). Down error:`,
1151
+ downErr
1152
+ );
1153
+ }
1154
+ }
1155
+ if (captureSet && opts.log && opts.onFailureRecord) {
1156
+ const errorType = captured instanceof Error ? captured.name : typeof captured;
1157
+ appendAudit(
1158
+ opts.log,
1159
+ opts.onFailureRecord,
1160
+ sealed,
1161
+ captured,
1162
+ { t_ns, seq, errorType },
1163
+ opts.handlerVersion
1164
+ );
1165
+ }
1166
+ throw captureSet ? captured : outerErr;
1167
+ }
1168
+ return result;
1169
+ };
1170
+ }
1171
+ var _bumpCursorWarned = /* @__PURE__ */ new WeakSet();
1172
+ function bumpCursor(seq) {
1173
+ const raw = seq.cache;
1174
+ const valid = typeof raw === "number" && Number.isFinite(raw);
1175
+ if (!valid && raw !== void 0 && !_bumpCursorWarned.has(seq)) {
1176
+ _bumpCursorWarned.add(seq);
1177
+ console.warn(
1178
+ `bumpCursor: cursor cache held a non-numeric value (${String(raw)}); resetting to 0. Causes include: a snapshot codec round-tripping the cursor as a string / null / NaN, OR a malformed initial seed (e.g. state<number>(NaN)). Audit consumers may see colliding seq values after this point.`
1179
+ );
1180
+ }
1181
+ const cur = valid ? raw : 0;
1182
+ const next = cur + 1;
1183
+ seq.down([[import_core7.DIRTY], [import_core7.DATA, next]]);
1184
+ return next;
1185
+ }
1186
+ function appendAudit(audit, builder, args, value, meta, handlerVersion) {
1187
+ const record = builder(args, value, meta);
1188
+ if (record === void 0) return;
1189
+ const stamped = handlerVersion != null ? { ...record, handlerVersion } : record;
1190
+ audit.append(stamped);
1191
+ }
1192
+ function registerCursor(graph, name, initial = 0) {
1193
+ const cursor = (0, import_core7.node)([], { initial, name, describeKind: "state" });
1194
+ graph.add(cursor, { name });
1195
+ return cursor;
1196
+ }
1197
+ function registerCursorMap(graph, name, keys, initial = 0) {
1198
+ const out = {};
1199
+ const sub = new import_graph.Graph(name);
1200
+ for (const k of keys) {
1201
+ const cursor = (0, import_core7.node)([], {
1202
+ initial,
1203
+ name: k,
1204
+ describeKind: "state"
1205
+ });
1206
+ sub.add(cursor, { name: k });
1207
+ out[k] = cursor;
1208
+ }
1209
+ graph.mount(name, sub);
1210
+ return out;
1211
+ }
1212
+
1213
+ // src/utils/_errors/index.ts
1214
+ var GraphReFlyError = class extends Error {
1215
+ constructor(message, options) {
1216
+ super(message, options);
1217
+ this.name = this.constructor.name;
1218
+ }
1219
+ };
1220
+ var DuplicateRegistrationError = class extends GraphReFlyError {
1221
+ constructor(kind, registrationName) {
1222
+ super(`Duplicate ${kind} registration: "${registrationName}"`);
1223
+ this.kind = kind;
1224
+ this.registrationName = registrationName;
1225
+ }
1226
+ };
1227
+ var UndeclaredEmitError = class extends GraphReFlyError {
1228
+ constructor(commandName, eventName, declaredEmits) {
1229
+ super(
1230
+ `Command "${commandName}" emitted undeclared event "${eventName}". Declared emits: [${declaredEmits.join(", ")}]`
1231
+ );
1232
+ this.commandName = commandName;
1233
+ this.eventName = eventName;
1234
+ this.declaredEmits = declaredEmits;
1235
+ }
1236
+ };
1237
+ var OptimisticConcurrencyError = class extends GraphReFlyError {
1238
+ constructor(aggregateId, expected, actual) {
1239
+ super(
1240
+ `Optimistic concurrency conflict on aggregate "${aggregateId}": expected version ${expected}, got ${actual}`
1241
+ );
1242
+ this.aggregateId = aggregateId;
1243
+ this.expected = expected;
1244
+ this.actual = actual;
1245
+ }
1246
+ };
1247
+ var UnknownCommandError = class extends GraphReFlyError {
1248
+ constructor(commandName) {
1249
+ super(`Unknown command: "${commandName}". Register with command() first.`);
1250
+ this.commandName = commandName;
1251
+ }
1252
+ };
1253
+ var CommandHandlerError = class extends GraphReFlyError {
1254
+ constructor(commandName, cause) {
1255
+ super(
1256
+ `Command handler "${commandName}" threw: ${cause instanceof Error ? cause.message : String(cause)}`,
1257
+ { cause }
1258
+ );
1259
+ this.commandName = commandName;
1260
+ }
1261
+ };
1262
+ var RebuildError = class extends GraphReFlyError {
1263
+ constructor(projectionName, cause) {
1264
+ super(
1265
+ `Projection "${projectionName}" rebuild failed: ${cause instanceof Error ? cause.message : String(cause)}`,
1266
+ { cause }
1267
+ );
1268
+ this.projectionName = projectionName;
1269
+ }
1270
+ };
1271
+
1272
+ // src/utils/cqrs/index.ts
1273
+ var import_extra4 = require("@graphrefly/pure-ts/extra");
1274
+
1275
+ // src/base/meta/domain-meta.ts
1276
+ function domainMeta(domain, kind, extra) {
1277
+ return {
1278
+ [domain]: true,
1279
+ [`${domain}_type`]: kind,
1280
+ ...extra ?? {}
1281
+ };
1282
+ }
1283
+
1284
+ // src/utils/cqrs/index.ts
1285
+ var COMMAND_GUARD = (0, import_core8.policy)((allow, deny) => {
1286
+ allow("write");
1287
+ allow("signal");
1288
+ deny("observe");
1289
+ });
1290
+ var PROJECTION_GUARD = (0, import_core8.policy)((allow, deny) => {
1291
+ allow("observe");
1292
+ allow("signal");
1293
+ deny("write");
1294
+ });
1295
+ var EVENT_GUARD = (0, import_core8.policy)((allow, deny) => {
1296
+ allow("observe");
1297
+ allow("signal");
1298
+ deny("write");
1299
+ });
1300
+ function cqrsMeta(kind, extra) {
1301
+ return domainMeta("cqrs", kind, extra);
1302
+ }
1303
+ function deepFreeze2(value) {
1304
+ if (value === null || typeof value !== "object" || Object.isFrozen(value)) return value;
1305
+ for (const k of Object.keys(value)) {
1306
+ deepFreeze2(value[k]);
1307
+ }
1308
+ return Object.freeze(value);
1309
+ }
1310
+ var CqrsGraph = class extends import_graph2.Graph {
1311
+ /** Fan-in event streams (one per type, all aggregates merged). */
1312
+ _eventLogs = /* @__PURE__ */ new Map();
1313
+ /**
1314
+ * Per-aggregate event streams: type → aggregateId → entry. Used for
1315
+ * `event(type, aggregateId)` dual-form access and per-aggregate version
1316
+ * tracking. Only populated when an event with `aggregateId` is emitted.
1317
+ */
1318
+ _eventLogsByAggregate = /* @__PURE__ */ new Map();
1319
+ /** Per-aggregate version counters: `${type}::${aggregateId}` → current version. */
1320
+ _aggregateVersions = /* @__PURE__ */ new Map();
1321
+ /**
1322
+ * LRU access order for `${type}::${aggregateId}`. Map insertion order
1323
+ * tracks recency — `delete` + `set` on access moves to the end.
1324
+ */
1325
+ _aggregateLru = /* @__PURE__ */ new Map();
1326
+ _commandRegs = /* @__PURE__ */ new Map();
1327
+ _projections = /* @__PURE__ */ new Set();
1328
+ _sagas = /* @__PURE__ */ new Set();
1329
+ _seq = 0;
1330
+ _retainedLimit;
1331
+ _freezeCommandPayload;
1332
+ _freezeEventPayload;
1333
+ _maxAggregates;
1334
+ _dispatchSeqCursor;
1335
+ /** Audit log of every command dispatch (Audit 2). */
1336
+ dispatches;
1337
+ /** Alias for {@link CqrsGraph.dispatches} (Audit 2 `.audit` duplication). */
1338
+ audit;
1339
+ /** Per-aggregate LRU eviction observability; secondary log to `dispatches`. */
1340
+ aggregateEvictions;
1341
+ constructor(name, opts = {}) {
1342
+ super(name, opts.graph);
1343
+ this._retainedLimit = opts.retainedLimit ?? 1024;
1344
+ this._freezeCommandPayload = opts.freezeCommandPayload ?? true;
1345
+ this._freezeEventPayload = opts.freezeEventPayload ?? true;
1346
+ this._maxAggregates = opts.maxAggregates ?? 1e4;
1347
+ this.dispatches = createAuditLog({
1348
+ name: "dispatches",
1349
+ retainedLimit: this._retainedLimit,
1350
+ graph: this
1351
+ });
1352
+ this.audit = this.dispatches;
1353
+ this.aggregateEvictions = createAuditLog({
1354
+ name: "aggregateEvictions",
1355
+ retainedLimit: this._retainedLimit,
1356
+ graph: this
1357
+ });
1358
+ this._dispatchSeqCursor = registerCursor(this, "dispatch_seq", 0);
1359
+ }
1360
+ /**
1361
+ * Read the current per-aggregate version (last emitted `aggregateVersion`
1362
+ * for that `(type, aggregateId)` pair). Returns `0` if no events have been
1363
+ * emitted yet for this aggregate. Useful for callers preparing
1364
+ * {@link DispatchOptions.expectedAggregateVersion}.
1365
+ */
1366
+ aggregateVersion(type, aggregateId) {
1367
+ return this._aggregateVersions.get(`${type}::${aggregateId}`) ?? 0;
1368
+ }
1369
+ /** LRU touch — moves the key to the end of the access order. */
1370
+ _touchAggregate(key) {
1371
+ this._aggregateLru.delete(key);
1372
+ this._aggregateLru.set(key, true);
1373
+ }
1374
+ /**
1375
+ * Evict the oldest aggregate streams (least-recently-touched) until the
1376
+ * aggregate count is back within `_maxAggregates`. Emits one
1377
+ * `AggregateEvictionRecord` per eviction. The fan-in stream is NOT touched
1378
+ * — events stay in the type-level log; only the per-aggregate stream and
1379
+ * version counter are removed.
1380
+ */
1381
+ _enforceAggregateLru() {
1382
+ while (this._aggregateLru.size > this._maxAggregates) {
1383
+ const oldest = this._aggregateLru.keys().next();
1384
+ if (oldest.done) break;
1385
+ const key = oldest.value;
1386
+ this._aggregateLru.delete(key);
1387
+ const sep = key.indexOf("::");
1388
+ if (sep < 0) continue;
1389
+ const type = key.slice(0, sep);
1390
+ const aggregateId = key.slice(sep + 2);
1391
+ const lastVersion = this._aggregateVersions.get(key) ?? 0;
1392
+ this._aggregateVersions.delete(key);
1393
+ const byType = this._eventLogsByAggregate.get(type);
1394
+ if (byType) {
1395
+ byType.delete(aggregateId);
1396
+ if (byType.size === 0) this._eventLogsByAggregate.delete(type);
1397
+ }
1398
+ this.aggregateEvictions.append({
1399
+ aggregateId,
1400
+ type,
1401
+ lastVersion,
1402
+ t_ns: (0, import_core8.wallClockNs)()
1403
+ });
1404
+ }
1405
+ }
1406
+ /** Tiers attached via {@link attachEventStorage}; auto-wired into future event streams. */
1407
+ _attachedEventTiers = [];
1408
+ _attachedTierDisposers = /* @__PURE__ */ new Map();
1409
+ /**
1410
+ * Wire append-log storage tiers for ALL CQRS event streams — both currently
1411
+ * registered AND any future streams created via `event(name)` /
1412
+ * `event(name, aggregateId)` / handler emit. (M4 fix.)
1413
+ *
1414
+ * Returns a disposer that releases all storage subscriptions wired by this
1415
+ * call (including those for streams that were created after the call).
1416
+ */
1417
+ attachEventStorage(tiers) {
1418
+ this._attachedEventTiers.push(tiers);
1419
+ for (const [name, entry] of this._eventLogs) {
1420
+ const dispose = entry.log.attachStorage(tiers);
1421
+ let arr = this._attachedTierDisposers.get(name);
1422
+ if (!arr) {
1423
+ arr = [];
1424
+ this._attachedTierDisposers.set(name, arr);
1425
+ }
1426
+ arr.push(dispose);
1427
+ }
1428
+ for (const [type, byAgg] of this._eventLogsByAggregate) {
1429
+ for (const [aggId, entry] of byAgg) {
1430
+ const key = `${type}::${aggId}`;
1431
+ const dispose = entry.log.attachStorage(tiers);
1432
+ let arr = this._attachedTierDisposers.get(key);
1433
+ if (!arr) {
1434
+ arr = [];
1435
+ this._attachedTierDisposers.set(key, arr);
1436
+ }
1437
+ arr.push(dispose);
1438
+ }
1439
+ }
1440
+ return () => {
1441
+ const idx = this._attachedEventTiers.indexOf(tiers);
1442
+ if (idx >= 0) this._attachedEventTiers.splice(idx, 1);
1443
+ };
1444
+ }
1445
+ /** Wire newly-created event stream into all currently-attached tier sets. */
1446
+ _autoWireStreamStorage(key, log) {
1447
+ if (this._attachedEventTiers.length === 0) return;
1448
+ let arr = this._attachedTierDisposers.get(key);
1449
+ if (!arr) {
1450
+ arr = [];
1451
+ this._attachedTierDisposers.set(key, arr);
1452
+ }
1453
+ for (const tiers of this._attachedEventTiers) {
1454
+ arr.push(log.attachStorage(tiers));
1455
+ }
1456
+ }
1457
+ event(name, aggregateId) {
1458
+ if (aggregateId !== void 0) {
1459
+ return this._ensureAggregateStream(name, aggregateId).node;
1460
+ }
1461
+ const existing = this._eventLogs.get(name);
1462
+ if (existing) return existing.node;
1463
+ const log = (0, import_extra3.reactiveLog)([], {
1464
+ name,
1465
+ versioning: 0,
1466
+ maxSize: this._retainedLimit
1467
+ });
1468
+ log.withLatest();
1469
+ const entries = log.entries;
1470
+ const guarded = this.derived(
1471
+ name,
1472
+ [entries],
1473
+ (batchData, ctx) => {
1474
+ const latest = batchData[0] != null && batchData[0].length > 0 ? batchData[0].at(-1) : ctx.prevData[0];
1475
+ return [latest];
1476
+ },
1477
+ {
1478
+ meta: cqrsMeta("event", { event_name: name }),
1479
+ guard: EVENT_GUARD,
1480
+ initial: entries.cache
1481
+ }
1482
+ );
1483
+ this.addDisposer((0, import_extra4.keepalive)(guarded));
1484
+ this._eventLogs.set(name, { log, node: guarded });
1485
+ this._autoWireStreamStorage(name, log);
1486
+ return guarded;
1487
+ }
1488
+ /**
1489
+ * Get-or-create the per-aggregate event stream for `(type, aggregateId)`.
1490
+ * Mounts the stream as a sibling node named `<type>_<aggregateId>` so it
1491
+ * appears in `describe()`. LRU access is touched on every call.
1492
+ */
1493
+ _ensureAggregateStream(type, aggregateId) {
1494
+ if (!this._eventLogs.has(type)) this.event(type);
1495
+ let byType = this._eventLogsByAggregate.get(type);
1496
+ if (!byType) {
1497
+ byType = /* @__PURE__ */ new Map();
1498
+ this._eventLogsByAggregate.set(type, byType);
1499
+ }
1500
+ const lruKey = `${type}::${aggregateId}`;
1501
+ this._touchAggregate(lruKey);
1502
+ const existing = byType.get(aggregateId);
1503
+ if (existing) return existing;
1504
+ const nodeName = `${type}_${aggregateId.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
1505
+ const log = (0, import_extra3.reactiveLog)([], {
1506
+ name: nodeName,
1507
+ versioning: 0,
1508
+ maxSize: this._retainedLimit
1509
+ });
1510
+ log.withLatest();
1511
+ const entries = log.entries;
1512
+ let mountName = nodeName;
1513
+ let collisionIdx = 0;
1514
+ while (this.resolveOptional(mountName) !== void 0) {
1515
+ collisionIdx += 1;
1516
+ mountName = `${nodeName}_${collisionIdx}`;
1517
+ }
1518
+ let guarded;
1519
+ try {
1520
+ guarded = this.derived(
1521
+ mountName,
1522
+ [entries],
1523
+ (batchData, ctx) => {
1524
+ const latest = batchData[0] != null && batchData[0].length > 0 ? batchData[0].at(-1) : ctx.prevData[0];
1525
+ return [latest];
1526
+ },
1527
+ {
1528
+ meta: cqrsMeta("event_aggregate", {
1529
+ event_name: type,
1530
+ aggregate_id: aggregateId
1531
+ }),
1532
+ guard: EVENT_GUARD,
1533
+ initial: entries.cache
1534
+ }
1535
+ );
1536
+ } catch {
1537
+ guarded = (0, import_core8.node)(
1538
+ [entries],
1539
+ (batchData, actions, ctx) => {
1540
+ const latest = batchData[0] != null && batchData[0].length > 0 ? batchData[0].at(-1) : ctx.prevData[0];
1541
+ actions.emit(latest);
1542
+ },
1543
+ {
1544
+ name: nodeName,
1545
+ describeKind: "derived",
1546
+ meta: cqrsMeta("event_aggregate", {
1547
+ event_name: type,
1548
+ aggregate_id: aggregateId
1549
+ }),
1550
+ guard: EVENT_GUARD,
1551
+ initial: entries.cache
1552
+ }
1553
+ );
1554
+ }
1555
+ this.addDisposer((0, import_extra4.keepalive)(guarded));
1556
+ const entry = { log, node: guarded };
1557
+ byType.set(aggregateId, entry);
1558
+ this._autoWireStreamStorage(`${type}::${aggregateId}`, log);
1559
+ this._enforceAggregateLru();
1560
+ return entry;
1561
+ }
1562
+ /** Try `resolve(path)`; return `undefined` instead of throwing on missing. */
1563
+ resolveOptional(path) {
1564
+ try {
1565
+ return this.resolve(path);
1566
+ } catch {
1567
+ return void 0;
1568
+ }
1569
+ }
1570
+ /** Internal: append to an event log, auto-registering if needed. */
1571
+ _appendEvent(eventName, payload, extra) {
1572
+ let entry = this._eventLogs.get(eventName);
1573
+ if (!entry) {
1574
+ this.event(eventName);
1575
+ entry = this._eventLogs.get(eventName);
1576
+ }
1577
+ if (entry.node.status === "completed" || entry.node.status === "errored") {
1578
+ throw new Error(
1579
+ `Cannot dispatch to terminated event stream "${eventName}" (status: ${entry.node.status}).`
1580
+ );
1581
+ }
1582
+ let aggregateVersion;
1583
+ let aggregateEntry;
1584
+ if (extra?.aggregateId !== void 0) {
1585
+ const lruKey = `${eventName}::${extra.aggregateId}`;
1586
+ aggregateVersion = (this._aggregateVersions.get(lruKey) ?? 0) + 1;
1587
+ this._aggregateVersions.set(lruKey, aggregateVersion);
1588
+ aggregateEntry = this._ensureAggregateStream(eventName, extra.aggregateId);
1589
+ }
1590
+ const nv = entry.log.entries.v;
1591
+ const frozenPayload = this._freezeEventPayload ? deepFreeze2(payload) : payload;
1592
+ const evt = {
1593
+ type: eventName,
1594
+ payload: frozenPayload,
1595
+ timestampNs: (0, import_core8.wallClockNs)(),
1596
+ seq: ++this._seq,
1597
+ ...extra?.aggregateId !== void 0 ? { aggregateId: extra.aggregateId } : {},
1598
+ ...aggregateVersion !== void 0 ? { aggregateVersion } : {},
1599
+ ...extra?.correlationId !== void 0 ? { correlationId: extra.correlationId } : {},
1600
+ ...extra?.causationId !== void 0 ? { causationId: extra.causationId } : {},
1601
+ ...extra?.metadata !== void 0 ? { metadata: Object.freeze({ ...extra.metadata }) } : {},
1602
+ ...extra?.handlerVersion !== void 0 ? { handlerVersion: extra.handlerVersion } : {},
1603
+ ...nv != null ? { v0: { id: nv.id, version: nv.version } } : {}
1604
+ };
1605
+ entry.log.append(evt);
1606
+ if (aggregateEntry) {
1607
+ aggregateEntry.log.append(evt);
1608
+ }
1609
+ return evt;
1610
+ }
1611
+ // -- Commands -------------------------------------------------------------
1612
+ /**
1613
+ * Register a command with its handler. Guard denies `observe` (write-only).
1614
+ * Use `dispatch(name, payload)` to execute.
1615
+ *
1616
+ * The command node carries dynamic `meta.error` — a reactive companion
1617
+ * that holds the last handler error (or `null` on success).
1618
+ */
1619
+ command(name, handlerOrReg) {
1620
+ if (this._commandRegs.has(name)) {
1621
+ throw new DuplicateRegistrationError("command", name);
1622
+ }
1623
+ const reg = typeof handlerOrReg === "function" ? { handler: handlerOrReg } : handlerOrReg;
1624
+ const cmdNode = this.state(name, void 0, {
1625
+ meta: {
1626
+ ...cqrsMeta("command", { command_name: name }),
1627
+ error: null
1628
+ },
1629
+ guard: COMMAND_GUARD
1630
+ });
1631
+ this._commandRegs.set(name, {
1632
+ handler: reg.handler,
1633
+ ...reg.emits !== void 0 ? { emits: reg.emits } : {},
1634
+ ...reg.handlerVersion !== void 0 ? { handlerVersion: reg.handlerVersion } : {}
1635
+ });
1636
+ if (reg.emits) {
1637
+ for (const e of reg.emits) {
1638
+ if (!this._eventLogs.has(e)) this.event(e);
1639
+ }
1640
+ }
1641
+ return cmdNode;
1642
+ }
1643
+ /**
1644
+ * Execute a registered command. Wraps the entire dispatch in `batch()` so
1645
+ * the command node DATA and all emitted events settle atomically.
1646
+ *
1647
+ * If the handler throws, `meta.error` on the command node is set to the
1648
+ * error and the exception is re-thrown.
1649
+ *
1650
+ * **Tier 8 / COMPOSITION-GUIDE §35:** dispatch routes through the shared
1651
+ * {@link mutate} framework so freeze / rollback-on-throw / seq-cursor
1652
+ * advance / audit-record stamping flow through one centralized helper.
1653
+ * Failure records emit OUTSIDE the rolled-back batch (M5 / C4 invariants
1654
+ * preserved by the framework).
1655
+ */
1656
+ dispatch(commandName, payload, opts) {
1657
+ const reg = this._commandRegs.get(commandName);
1658
+ if (!reg) throw new UnknownCommandError(commandName);
1659
+ if (opts?.aggregateId !== void 0 && opts.expectedAggregateVersion !== void 0 && reg.emits !== void 0) {
1660
+ let observedVersion = 0;
1661
+ for (const t of reg.emits) {
1662
+ const v = this._aggregateVersions.get(`${t}::${opts.aggregateId}`);
1663
+ if (v !== void 0 && v > observedVersion) observedVersion = v;
1664
+ }
1665
+ if (observedVersion !== opts.expectedAggregateVersion) {
1666
+ throw new OptimisticConcurrencyError(
1667
+ opts.aggregateId,
1668
+ opts.expectedAggregateVersion,
1669
+ observedVersion
1670
+ );
1671
+ }
1672
+ }
1673
+ const cmdNode = this.resolve(commandName);
1674
+ const emittedEvents = [];
1675
+ let actionThrew = false;
1676
+ const action = (sealed) => {
1677
+ cmdNode.emit(sealed, { internal: true });
1678
+ try {
1679
+ reg.handler(sealed, {
1680
+ emit: (eName, data) => {
1681
+ if (reg.emits !== void 0 && !reg.emits.includes(eName)) {
1682
+ throw new UndeclaredEmitError(commandName, eName, reg.emits);
1683
+ }
1684
+ emittedEvents.push(eName);
1685
+ this._appendEvent(eName, data, {
1686
+ // D1: thread the dispatch's aggregateId through so events
1687
+ // participate in per-aggregate versioning. Handlers can
1688
+ // override per-emit by passing their own through a richer
1689
+ // emit signature (future extension).
1690
+ ...opts?.aggregateId !== void 0 ? { aggregateId: opts.aggregateId } : {},
1691
+ ...opts?.correlationId !== void 0 ? { correlationId: opts.correlationId } : {},
1692
+ ...opts?.causationId !== void 0 ? { causationId: opts.causationId } : {},
1693
+ ...opts?.metadata !== void 0 ? { metadata: Object.freeze({ ...opts.metadata }) } : {},
1694
+ ...reg.handlerVersion !== void 0 ? { handlerVersion: reg.handlerVersion } : {}
1695
+ });
1696
+ }
1697
+ });
1698
+ cmdNode.meta.error.emit(null, { internal: true });
1699
+ } catch (err) {
1700
+ actionThrew = true;
1701
+ throw err;
1702
+ }
1703
+ };
1704
+ try {
1705
+ mutate(action, {
1706
+ frame: "transactional",
1707
+ log: this.dispatches,
1708
+ seq: this._dispatchSeqCursor,
1709
+ freeze: this._freezeCommandPayload,
1710
+ onSuccessRecord: ([sealed], _result, { t_ns, seq }) => ({
1711
+ commandName,
1712
+ payload: sealed,
1713
+ outcome: "success",
1714
+ emittedEvents: [...emittedEvents],
1715
+ t_ns,
1716
+ seq: seq ?? 0,
1717
+ ...reg.handlerVersion !== void 0 ? { handlerVersion: reg.handlerVersion } : {}
1718
+ }),
1719
+ onFailureRecord: ([sealed], err, { t_ns, seq, errorType }) => {
1720
+ const wrapped = err instanceof CommandHandlerError ? err : new CommandHandlerError(commandName, err);
1721
+ return {
1722
+ commandName,
1723
+ payload: sealed,
1724
+ outcome: "failure",
1725
+ error: wrapped,
1726
+ errorType,
1727
+ emittedEvents: [...emittedEvents],
1728
+ t_ns,
1729
+ seq: seq ?? 0,
1730
+ ...reg.handlerVersion !== void 0 ? { handlerVersion: reg.handlerVersion } : {}
1731
+ };
1732
+ }
1733
+ })(payload);
1734
+ } catch (outerErr) {
1735
+ if (actionThrew) {
1736
+ cmdNode.meta.error.emit(outerErr, { internal: true });
1737
+ }
1738
+ throw outerErr;
1739
+ }
1740
+ }
1741
+ // -- Projections ----------------------------------------------------------
1742
+ /**
1743
+ * Register a read-only projection derived from event streams.
1744
+ * Guard denies `write` — value is computed from events only.
1745
+ *
1746
+ * **Wave C.3 Unit 21 (locked 2026-04-24):**
1747
+ * - Object-bag signature replaces the positional `(name, events, reducer, initial)` form.
1748
+ * - `mode: "scan"` (default) — incremental fold; `"replay"` — full replay each wave.
1749
+ * - `snapshot` integration for cold-start load + auto-checkpoint save.
1750
+ * - `freezeInputs` (default `true`) — freeze the event array before passing to reducer.
1751
+ * - Returns `ProjectionController<TState>` with `.node`, `.rebuild()`, `.reset()`.
1752
+ *
1753
+ * Fan-in across `events` is implemented by depending on all event-type fan-in
1754
+ * nodes directly, which preserves `describe()` edges (e.g. `orderPlaced →
1755
+ * orderCount`). Events are sorted by `(timestampNs, seq, aggregateId)` before
1756
+ * passing to the reducer (Option-3 cross-aggregate ordering, C.3).
1757
+ */
1758
+ projection(opts) {
1759
+ const { name, events: eventNames, reducer, initial } = opts;
1760
+ const mode = opts.mode ?? "scan";
1761
+ const freezeInputs = opts.freezeInputs ?? true;
1762
+ const snapshotOpts = opts.snapshot;
1763
+ const eventNodes = eventNames.map((eName) => {
1764
+ if (!this._eventLogs.has(eName)) this.event(eName);
1765
+ return this._eventLogs.get(eName).node;
1766
+ });
1767
+ function sortEvents(evts) {
1768
+ evts.sort(
1769
+ (a, b) => a.timestampNs - b.timestampNs || a.seq - b.seq || (a.aggregateId ?? "").localeCompare(b.aggregateId ?? "")
1770
+ );
1771
+ }
1772
+ function collectAllEvents(snapshots) {
1773
+ const evts = [];
1774
+ for (const snap of snapshots) evts.push(...snap);
1775
+ sortEvents(evts);
1776
+ return evts;
1777
+ }
1778
+ const seedSnapshots = eventNodes.map(
1779
+ (n) => n.cache ?? []
1780
+ );
1781
+ const sortedSeed = collectAllEvents(seedSnapshots);
1782
+ const frozenSeed = freezeInputs ? Object.freeze(sortedSeed) : sortedSeed;
1783
+ let lastProcessedCount = 0;
1784
+ let scanState = initial;
1785
+ if (mode === "scan" && sortedSeed.length > 0) {
1786
+ scanState = reducer(initial, frozenSeed);
1787
+ lastProcessedCount = sortedSeed.length;
1788
+ }
1789
+ const seedState = mode === "replay" ? reducer(initial, frozenSeed) : scanState;
1790
+ const saveDebounceMs = snapshotOpts?.saveDebounceMs ?? 1e3;
1791
+ const saveEvery = snapshotOpts?.saveEvery ?? 1e3;
1792
+ let saveTimer;
1793
+ let savesSinceLastFlush = 0;
1794
+ function scheduleSave(currentState) {
1795
+ if (!snapshotOpts?.save) return;
1796
+ savesSinceLastFlush += 1;
1797
+ if (savesSinceLastFlush >= saveEvery) {
1798
+ savesSinceLastFlush = 0;
1799
+ if (saveTimer !== void 0) {
1800
+ clearTimeout(saveTimer);
1801
+ saveTimer = void 0;
1802
+ }
1803
+ const result = snapshotOpts.save(currentState);
1804
+ if (result instanceof Promise) result.catch(() => void 0);
1805
+ return;
1806
+ }
1807
+ if (saveTimer !== void 0) clearTimeout(saveTimer);
1808
+ saveTimer = setTimeout(() => {
1809
+ saveTimer = void 0;
1810
+ savesSinceLastFlush = 0;
1811
+ const result = snapshotOpts.save(currentState);
1812
+ if (result instanceof Promise) result.catch(() => void 0);
1813
+ }, saveDebounceMs);
1814
+ }
1815
+ const projNode = this.derived(
1816
+ name,
1817
+ eventNames,
1818
+ (batchData, ctx) => {
1819
+ const snapshots = batchData.map(
1820
+ (batch2, i) => batch2 != null && batch2.length > 0 ? batch2.at(-1) : ctx.prevData[i]
1821
+ );
1822
+ const allEvents = collectAllEvents(snapshots);
1823
+ let newState;
1824
+ if (mode === "replay") {
1825
+ const frozen = freezeInputs ? Object.freeze(allEvents) : allEvents;
1826
+ newState = reducer(initial, frozen);
1827
+ } else {
1828
+ const newOnly = allEvents.slice(lastProcessedCount);
1829
+ lastProcessedCount = allEvents.length;
1830
+ const frozenNew = freezeInputs ? Object.freeze(newOnly) : newOnly;
1831
+ newState = reducer(scanState, frozenNew);
1832
+ scanState = newState;
1833
+ }
1834
+ scheduleSave(newState);
1835
+ return [newState];
1836
+ },
1837
+ {
1838
+ meta: cqrsMeta("projection", { projection_name: name, source_events: eventNames }),
1839
+ guard: PROJECTION_GUARD,
1840
+ initial: seedState
1841
+ }
1842
+ );
1843
+ this.addDisposer((0, import_extra4.keepalive)(projNode));
1844
+ this.addDisposer(() => {
1845
+ if (saveTimer !== void 0) {
1846
+ clearTimeout(saveTimer);
1847
+ saveTimer = void 0;
1848
+ }
1849
+ });
1850
+ this._projections.add(name);
1851
+ const rebuild = async (rebuildOpts) => {
1852
+ try {
1853
+ const pageSize = rebuildOpts?.pageSize ?? 1e3;
1854
+ const tier = rebuildOpts?.fromTier ?? this._attachedEventTiers[0]?.[0];
1855
+ const preBuildCount = collectAllEvents(
1856
+ eventNodes.map((n) => n.cache ?? [])
1857
+ ).length;
1858
+ let rebuildState = initial;
1859
+ if (snapshotOpts?.load) {
1860
+ const loaded = await snapshotOpts.load();
1861
+ if (loaded !== void 0) rebuildState = loaded;
1862
+ }
1863
+ if (!tier || !tier.loadEntries) {
1864
+ const inMemory = collectAllEvents(
1865
+ eventNodes.map((n) => n.cache ?? [])
1866
+ );
1867
+ const frozen = freezeInputs ? Object.freeze(inMemory) : inMemory;
1868
+ rebuildState = reducer(rebuildState, frozen);
1869
+ } else {
1870
+ const watchedEvents = new Set(eventNames);
1871
+ let cursor;
1872
+ let done = false;
1873
+ while (!done) {
1874
+ const result = await tier.loadEntries({ cursor, pageSize });
1875
+ const page = [...result.entries].filter((e) => watchedEvents.has(e.type));
1876
+ sortEvents(page);
1877
+ const frozenPage = freezeInputs ? Object.freeze(page) : page;
1878
+ rebuildState = reducer(rebuildState, frozenPage);
1879
+ cursor = result.cursor;
1880
+ done = !cursor || result.entries.length === 0;
1881
+ }
1882
+ }
1883
+ if (mode === "scan") {
1884
+ const allInMemory = collectAllEvents(
1885
+ eventNodes.map((n) => n.cache ?? [])
1886
+ );
1887
+ const pendingEvents = allInMemory.slice(preBuildCount);
1888
+ if (pendingEvents.length > 0) {
1889
+ const frozenPending = freezeInputs ? Object.freeze(pendingEvents) : pendingEvents;
1890
+ rebuildState = reducer(rebuildState, frozenPending);
1891
+ }
1892
+ scanState = rebuildState;
1893
+ lastProcessedCount = allInMemory.length;
1894
+ }
1895
+ projNode.emit(rebuildState, { internal: true });
1896
+ return rebuildState;
1897
+ } catch (err) {
1898
+ throw new RebuildError(name, err);
1899
+ }
1900
+ };
1901
+ const reset = async () => {
1902
+ try {
1903
+ let baseState = initial;
1904
+ if (snapshotOpts?.load) {
1905
+ const loaded = await snapshotOpts.load();
1906
+ if (loaded !== void 0) baseState = loaded;
1907
+ }
1908
+ const inMemory = collectAllEvents(
1909
+ eventNodes.map((n) => n.cache ?? [])
1910
+ );
1911
+ const frozen = freezeInputs ? Object.freeze(inMemory) : inMemory;
1912
+ const newState = reducer(baseState, frozen);
1913
+ if (mode === "scan") {
1914
+ scanState = newState;
1915
+ lastProcessedCount = inMemory.length;
1916
+ }
1917
+ projNode.emit(newState, { internal: true });
1918
+ return newState;
1919
+ } catch (err) {
1920
+ throw new RebuildError(name, err);
1921
+ }
1922
+ };
1923
+ return { node: projNode, rebuild, reset };
1924
+ }
1925
+ // -- Sagas ----------------------------------------------------------------
1926
+ /**
1927
+ * Register an event-driven side effect. Runs handler for each **new** event
1928
+ * from the specified streams (tracks last-processed entry count per stream).
1929
+ *
1930
+ * The saga node carries dynamic `meta.error` — a reactive companion that
1931
+ * holds the last handler error (or `null` on success). Handler errors do
1932
+ * not propagate out of the saga run (the event cursor still advances so
1933
+ * the same entry is not delivered twice).
1934
+ */
1935
+ saga(name, eventNames, handler, opts = {}) {
1936
+ const _eventNodes = eventNames.map((eName) => {
1937
+ if (!this._eventLogs.has(eName)) this.event(eName);
1938
+ return this._eventLogs.get(eName).node;
1939
+ });
1940
+ const cursors = registerCursorMap(this, `${name}_cursor`, eventNames, 0);
1941
+ const invocations = createAuditLog({
1942
+ name: `${name}_invocations`,
1943
+ retainedLimit: this._retainedLimit,
1944
+ graph: this
1945
+ });
1946
+ const aggregateFilter = opts.aggregateId;
1947
+ const errorPolicy = opts.errorPolicy ?? "advance";
1948
+ const latestCursors = /* @__PURE__ */ new Map();
1949
+ for (const eName of eventNames) {
1950
+ const cursor = cursors[eName];
1951
+ latestCursors.set(eName, cursor.cache ?? 0);
1952
+ const sub = cursor.subscribe((msgs) => {
1953
+ for (const m of msgs) if (m[0] === import_core8.DATA) latestCursors.set(eName, m[1]);
1954
+ });
1955
+ this.addDisposer(sub);
1956
+ }
1957
+ const auditedHandler = mutate(
1958
+ (ev, _eName) => {
1959
+ handler(ev);
1960
+ },
1961
+ {
1962
+ frame: "inline",
1963
+ log: invocations,
1964
+ freeze: false,
1965
+ ...opts.handlerVersion !== void 0 ? { handlerVersion: opts.handlerVersion } : {},
1966
+ // D5 (qa lock): always include the `aggregateId` key (even when
1967
+ // undefined) for parity with the pre-Tier-8 saga record shape.
1968
+ // Consumers using `Object.hasOwn(record, "aggregateId")` or JSON
1969
+ // serialization shape would observe a pre-1.0 break otherwise.
1970
+ onSuccessRecord: ([ev, eName], _r, { t_ns }) => ({
1971
+ eventType: eName,
1972
+ outcome: "success",
1973
+ aggregateId: ev.aggregateId,
1974
+ event: ev,
1975
+ t_ns
1976
+ }),
1977
+ onFailureRecord: ([ev, eName], err, { t_ns, errorType }) => ({
1978
+ eventType: eName,
1979
+ outcome: "failure",
1980
+ error: err,
1981
+ errorType,
1982
+ aggregateId: ev.aggregateId,
1983
+ event: ev,
1984
+ t_ns
1985
+ })
1986
+ }
1987
+ );
1988
+ const sagaRef = {};
1989
+ const sagaNode = this.effect(
1990
+ name,
1991
+ eventNames,
1992
+ (snapshots, _up) => {
1993
+ const errNode = sagaRef.n.meta.error;
1994
+ for (let i = 0; i < snapshots.length; i++) {
1995
+ const batch2 = snapshots[i];
1996
+ if (batch2 == null || batch2.length === 0) continue;
1997
+ const entries = batch2.at(-1);
1998
+ if (!entries) continue;
1999
+ const eName = eventNames[i];
2000
+ const cursor = cursors[eName];
2001
+ const lastCount = latestCursors.get(eName) ?? 0;
2002
+ if (entries.length > lastCount) {
2003
+ const newEntries = entries.slice(lastCount);
2004
+ let advancedTo = lastCount;
2005
+ for (const entry of newEntries) {
2006
+ const ev = entry;
2007
+ if (aggregateFilter !== void 0 && ev.aggregateId !== aggregateFilter) {
2008
+ advancedTo += 1;
2009
+ continue;
2010
+ }
2011
+ try {
2012
+ auditedHandler(ev, eName);
2013
+ errNode.emit(null, { internal: true });
2014
+ advancedTo += 1;
2015
+ } catch (err) {
2016
+ errNode.emit(err, { internal: true });
2017
+ if (errorPolicy === "hold") break;
2018
+ advancedTo += 1;
2019
+ }
2020
+ }
2021
+ cursor.emit(advancedTo);
2022
+ }
2023
+ }
2024
+ },
2025
+ {
2026
+ meta: {
2027
+ ...cqrsMeta("saga", { saga_name: name, source_events: eventNames }),
2028
+ error: null
2029
+ }
2030
+ }
2031
+ );
2032
+ sagaRef.n = sagaNode;
2033
+ this.addDisposer((0, import_extra4.keepalive)(sagaNode));
2034
+ this._sagas.add(name);
2035
+ return {
2036
+ node: sagaNode,
2037
+ invocations,
2038
+ audit: invocations,
2039
+ cursors
2040
+ };
2041
+ }
2042
+ };
2043
+ function cqrs(name, opts) {
2044
+ const g = new CqrsGraph(name, opts);
2045
+ const { factory: _f, factoryArgs: _fa, ...tagArgs } = opts ?? {};
2046
+ g.tagFactory("cqrs", (0, import_core8.placeholderArgs)(tagArgs));
2047
+ return g;
2048
+ }
2049
+
2050
+ // src/compat/nestjs/module.ts
2051
+ var GraphReflyRootLifecycle = class {
2052
+ constructor(graph) {
2053
+ this.graph = graph;
2054
+ }
2055
+ onModuleDestroy() {
2056
+ this.graph.destroy();
2057
+ }
2058
+ };
2059
+ var GraphReflyRequestLifecycle = class {
2060
+ graph = new import_graph3.Graph("request");
2061
+ onModuleDestroy() {
2062
+ this.graph.destroy();
2063
+ }
2064
+ };
2065
+ var _GraphReflyModule_decorators, _init;
2066
+ _GraphReflyModule_decorators = [(0, import_common2.Module)({})];
2067
+ var _GraphReflyModule = class _GraphReflyModule {
2068
+ /**
2069
+ * Register the root `Graph` singleton in the NestJS DI container.
2070
+ *
2071
+ * The root graph is `@Global()` — injectable everywhere without importing
2072
+ * the module again. Use `@InjectGraph()` to inject it.
2073
+ *
2074
+ * Lifecycle:
2075
+ * - **init:** Graph created in factory. If `build` is provided, it runs
2076
+ * first (registers nodes/mounts). If `snapshot` is provided, values
2077
+ * are restored via `graph.restore()`.
2078
+ * - **destroy:** Calls `graph.destroy()` — sends `[[TEARDOWN]]` to all
2079
+ * nodes, including mounted feature subgraphs (cascading teardown).
2080
+ */
2081
+ static forRoot(opts) {
2082
+ const options = opts ?? {};
2083
+ const graphName = options.name ?? "root";
2084
+ const providers = [
2085
+ {
2086
+ provide: GRAPHREFLY_ROOT_GRAPH,
2087
+ useFactory: () => {
2088
+ const g = new import_graph3.Graph(graphName);
2089
+ if (options.build) options.build(g);
2090
+ if (options.snapshot) g.restore(options.snapshot);
2091
+ return g;
2092
+ }
2093
+ },
2094
+ {
2095
+ provide: /* @__PURE__ */ Symbol.for("graphrefly:root-lifecycle"),
2096
+ useFactory: (graph) => new GraphReflyRootLifecycle(graph),
2097
+ inject: [GRAPHREFLY_ROOT_GRAPH]
2098
+ },
2099
+ {
2100
+ provide: GraphReflyEventExplorer,
2101
+ useFactory: (graph, moduleRef) => new GraphReflyEventExplorer(graph, moduleRef),
2102
+ inject: [GRAPHREFLY_ROOT_GRAPH, import_core9.ModuleRef]
2103
+ }
2104
+ ];
2105
+ if (options.nodes) {
2106
+ for (const path of options.nodes) {
2107
+ providers.push({
2108
+ provide: getNodeToken(path),
2109
+ useFactory: (graph) => graph.resolve(path),
2110
+ inject: [GRAPHREFLY_ROOT_GRAPH]
2111
+ });
2112
+ }
2113
+ }
2114
+ if (options.requestScope) {
2115
+ providers.push(
2116
+ {
2117
+ provide: /* @__PURE__ */ Symbol.for("graphrefly:request-lifecycle"),
2118
+ useFactory: () => new GraphReflyRequestLifecycle(),
2119
+ scope: import_common2.Scope.REQUEST
2120
+ },
2121
+ {
2122
+ provide: GRAPHREFLY_REQUEST_GRAPH,
2123
+ useFactory: (lifecycle) => lifecycle.graph,
2124
+ inject: [/* @__PURE__ */ Symbol.for("graphrefly:request-lifecycle")],
2125
+ scope: import_common2.Scope.REQUEST
2126
+ }
2127
+ );
2128
+ }
2129
+ return {
2130
+ module: _GraphReflyModule,
2131
+ global: true,
2132
+ providers,
2133
+ exports: [
2134
+ GRAPHREFLY_ROOT_GRAPH,
2135
+ ...(options.nodes ?? []).map(getNodeToken),
2136
+ ...options.requestScope ? [GRAPHREFLY_REQUEST_GRAPH] : []
2137
+ ]
2138
+ };
2139
+ }
2140
+ /**
2141
+ * Register a feature subgraph that auto-mounts into the root graph.
2142
+ *
2143
+ * The feature graph is created in the factory, built/restored, then
2144
+ * mounted into root via `root.mount(name, featureGraph)`. On app
2145
+ * shutdown, root's `graph.destroy()` cascades TEARDOWN through all
2146
+ * mounted subgraphs (no explicit remove needed).
2147
+ *
2148
+ * Node tokens are auto-qualified as `featureName::path` to prevent
2149
+ * collisions between features declaring nodes with the same local name.
2150
+ *
2151
+ * Injectable via `@InjectGraph(name)`.
2152
+ */
2153
+ static forFeature(opts) {
2154
+ const providers = [
2155
+ {
2156
+ provide: getGraphToken(opts.name),
2157
+ useFactory: (rootGraph) => {
2158
+ const g = new import_graph3.Graph(opts.name);
2159
+ if (opts.build) opts.build(g);
2160
+ if (opts.snapshot) g.restore(opts.snapshot);
2161
+ rootGraph.mount(opts.name, g);
2162
+ return g;
2163
+ },
2164
+ inject: [GRAPHREFLY_ROOT_GRAPH]
2165
+ }
2166
+ ];
2167
+ if (opts.nodes) {
2168
+ for (const path of opts.nodes) {
2169
+ providers.push({
2170
+ provide: getNodeToken(`${opts.name}::${path}`),
2171
+ useFactory: (graph) => graph.resolve(path),
2172
+ inject: [getGraphToken(opts.name)]
2173
+ });
2174
+ }
2175
+ }
2176
+ return {
2177
+ module: _GraphReflyModule,
2178
+ providers,
2179
+ exports: [
2180
+ getGraphToken(opts.name),
2181
+ ...(opts.nodes ?? []).map((p) => getNodeToken(`${opts.name}::${p}`))
2182
+ ]
2183
+ };
2184
+ }
2185
+ /**
2186
+ * Register a CQRS subgraph that auto-mounts into the root graph.
2187
+ *
2188
+ * Creates a `CqrsGraph` via the `cqrs()` factory (roadmap §4.5), mounts it
2189
+ * into the root graph, and exposes it for DI via `@InjectGraph(name)`.
2190
+ *
2191
+ * CQRS decorators (`@CommandHandler`, `@EventHandler`, `@QueryHandler`,
2192
+ * `@SagaHandler`) are discovered by the explorer and wired to this graph
2193
+ * on module init.
2194
+ *
2195
+ * @example
2196
+ * ```ts
2197
+ * GraphReflyModule.forCqrs({
2198
+ * name: "orders",
2199
+ * build: (g) => {
2200
+ * g.event("orderPlaced");
2201
+ * g.projection({ name: "orderCount", events: ["orderPlaced"], reducer: (_s, evts) => evts.length, initial: 0 });
2202
+ * },
2203
+ * })
2204
+ * ```
2205
+ */
2206
+ static forCqrs(opts) {
2207
+ const providers = [
2208
+ {
2209
+ provide: getGraphToken(opts.name),
2210
+ useFactory: (rootGraph) => {
2211
+ const g = cqrs(opts.name, opts.cqrs);
2212
+ if (opts.eventStorage) g.attachEventStorage(opts.eventStorage);
2213
+ if (opts.build) opts.build(g);
2214
+ rootGraph.mount(opts.name, g);
2215
+ return g;
2216
+ },
2217
+ inject: [GRAPHREFLY_ROOT_GRAPH]
2218
+ }
2219
+ ];
2220
+ if (opts.nodes) {
2221
+ for (const path of opts.nodes) {
2222
+ providers.push({
2223
+ provide: getNodeToken(`${opts.name}::${path}`),
2224
+ useFactory: (graph) => graph.resolve(path),
2225
+ inject: [getGraphToken(opts.name)]
2226
+ });
2227
+ }
2228
+ }
2229
+ return {
2230
+ module: _GraphReflyModule,
2231
+ providers,
2232
+ exports: [
2233
+ getGraphToken(opts.name),
2234
+ ...(opts.nodes ?? []).map((p) => getNodeToken(`${opts.name}::${p}`))
2235
+ ]
2236
+ };
2237
+ }
2238
+ };
2239
+ _init = __decoratorStart(null);
2240
+ _GraphReflyModule = __decorateElement(_init, 0, "GraphReflyModule", _GraphReflyModule_decorators, _GraphReflyModule);
2241
+ __runInitializers(_init, 1, _GraphReflyModule);
2242
+ var GraphReflyModule = _GraphReflyModule;
21
2243
  //# sourceMappingURL=index.cjs.map