@graphrefly/ts 0.0.0 → 0.0.2

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 (405) hide show
  1. package/README.md +135 -0
  2. package/dist/actions-types-CSC3NMDl.d.ts +657 -0
  3. package/dist/actions-types-wl9Mgkmr.d.cts +657 -0
  4. package/dist/adapters/index.cjs +5219 -2974
  5. package/dist/adapters/index.cjs.map +1 -1
  6. package/dist/adapters/index.d.cts +204 -192
  7. package/dist/adapters/index.d.ts +204 -192
  8. package/dist/adapters/index.js +3685 -1833
  9. package/dist/adapters/index.js.map +1 -1
  10. package/dist/adapters/nestjs/microservices.cjs +841 -0
  11. package/dist/adapters/nestjs/microservices.cjs.map +1 -0
  12. package/dist/adapters/nestjs/microservices.d.cts +45 -0
  13. package/dist/adapters/nestjs/microservices.d.ts +45 -0
  14. package/dist/adapters/nestjs/microservices.js +206 -0
  15. package/dist/adapters/nestjs/microservices.js.map +1 -0
  16. package/dist/adapters/nestjs/native.cjs +1391 -0
  17. package/dist/adapters/nestjs/native.cjs.map +1 -0
  18. package/dist/adapters/nestjs/native.d.cts +111 -0
  19. package/dist/adapters/nestjs/native.d.ts +111 -0
  20. package/dist/adapters/nestjs/native.js +577 -0
  21. package/dist/adapters/nestjs/native.js.map +1 -0
  22. package/dist/adapters/nestjs/websockets.cjs +924 -0
  23. package/dist/adapters/nestjs/websockets.cjs.map +1 -0
  24. package/dist/adapters/nestjs/websockets.d.cts +47 -0
  25. package/dist/adapters/nestjs/websockets.d.ts +47 -0
  26. package/dist/adapters/nestjs/websockets.js +286 -0
  27. package/dist/adapters/nestjs/websockets.js.map +1 -0
  28. package/dist/adapters/nestjs.cjs +1085 -0
  29. package/dist/adapters/nestjs.cjs.map +1 -0
  30. package/dist/adapters/nestjs.d.cts +385 -0
  31. package/dist/adapters/nestjs.d.ts +385 -0
  32. package/dist/adapters/nestjs.js +112 -0
  33. package/dist/adapters/nestjs.js.map +1 -0
  34. package/dist/adapters/observe-storage.d.cts +4 -4
  35. package/dist/adapters/observe-storage.d.ts +4 -4
  36. package/dist/adapters/observe-storage.js +5 -4
  37. package/dist/adapters/observe-storage.js.map +1 -1
  38. package/dist/adapters/react.cjs +166 -0
  39. package/dist/adapters/react.cjs.map +1 -0
  40. package/dist/adapters/react.d.cts +31 -0
  41. package/dist/adapters/react.d.ts +31 -0
  42. package/dist/adapters/react.js +51 -0
  43. package/dist/adapters/react.js.map +1 -0
  44. package/dist/adapters/solid.cjs +157 -0
  45. package/dist/adapters/solid.cjs.map +1 -0
  46. package/dist/adapters/solid.d.cts +26 -0
  47. package/dist/adapters/solid.d.ts +26 -0
  48. package/dist/adapters/solid.js +48 -0
  49. package/dist/adapters/solid.js.map +1 -0
  50. package/dist/adapters/svelte.cjs +148 -0
  51. package/dist/adapters/svelte.cjs.map +1 -0
  52. package/dist/adapters/svelte.d.cts +31 -0
  53. package/dist/adapters/svelte.d.ts +31 -0
  54. package/dist/adapters/svelte.js +46 -0
  55. package/dist/adapters/svelte.js.map +1 -0
  56. package/dist/adapters/vue.cjs +155 -0
  57. package/dist/adapters/vue.cjs.map +1 -0
  58. package/dist/adapters/vue.d.cts +26 -0
  59. package/dist/adapters/vue.d.ts +26 -0
  60. package/dist/adapters/vue.js +46 -0
  61. package/dist/adapters/vue.js.map +1 -0
  62. package/dist/agent-runtime-types-core-CaXfKNtY.d.cts +406 -0
  63. package/dist/agent-runtime-types-core-hU299uIC.d.ts +406 -0
  64. package/dist/agent-runtime-types-tool-BEpSINol.d.ts +695 -0
  65. package/dist/agent-runtime-types-tool-DninPEzk.d.cts +695 -0
  66. package/dist/agentic-memory-retention-BmGX368S.d.ts +14 -0
  67. package/dist/agentic-memory-retention-Ih1qhX9Z.d.cts +14 -0
  68. package/dist/agentic-memory-types-CVSUS6XR.d.ts +473 -0
  69. package/dist/agentic-memory-types-FnnYlVUs.d.cts +473 -0
  70. package/dist/capability-admission-BW2CziT6.d.ts +102 -0
  71. package/dist/capability-admission-lwSecxXs.d.cts +102 -0
  72. package/dist/chunk-2KUAG2GZ.js +9693 -0
  73. package/dist/chunk-2KUAG2GZ.js.map +1 -0
  74. package/dist/chunk-2NJP6GO4.js +1320 -0
  75. package/dist/chunk-2NJP6GO4.js.map +1 -0
  76. package/dist/{chunk-GDL26N2T.js → chunk-3KN7NJDR.js} +2 -2
  77. package/dist/{chunk-COHO25CZ.js → chunk-4NWSNI4K.js} +2232 -1672
  78. package/dist/chunk-4NWSNI4K.js.map +1 -0
  79. package/dist/{chunk-Z2ANQ6JW.js → chunk-4Q77MMJY.js} +2 -2
  80. package/dist/chunk-6E76H4OU.js +132 -0
  81. package/dist/chunk-6E76H4OU.js.map +1 -0
  82. package/dist/chunk-7GOTIIQ7.js +819 -0
  83. package/dist/chunk-7GOTIIQ7.js.map +1 -0
  84. package/dist/{chunk-D6BG7U6A.js → chunk-7HZRJMN6.js} +3 -3
  85. package/dist/{chunk-SCRFRCGR.js → chunk-BSQGE5PS.js} +1 -1
  86. package/dist/{chunk-PKVBHGBM.js → chunk-CJIFGJQG.js} +7 -7
  87. package/dist/{chunk-G4M3NHRJ.js → chunk-CX6B6PO2.js} +93 -10
  88. package/dist/chunk-CX6B6PO2.js.map +1 -0
  89. package/dist/chunk-DGUM43GV.js +11 -0
  90. package/dist/chunk-DGUM43GV.js.map +1 -0
  91. package/dist/{chunk-JIMUDQN3.js → chunk-E4QCH32M.js} +449 -447
  92. package/dist/chunk-E4QCH32M.js.map +1 -0
  93. package/dist/{chunk-RIIOUTGM.js → chunk-ECURQ3HD.js} +19 -129
  94. package/dist/chunk-ECURQ3HD.js.map +1 -0
  95. package/dist/{chunk-2ILL7HQI.js → chunk-EOKT4QFF.js} +134 -128
  96. package/dist/chunk-EOKT4QFF.js.map +1 -0
  97. package/dist/{chunk-K3FXTC3I.js → chunk-HJACH5PU.js} +3 -3
  98. package/dist/{chunk-GTPCOEOZ.js → chunk-IDMLXLLG.js} +3 -3
  99. package/dist/{chunk-DKP56CSW.js → chunk-JKAYLDQV.js} +2 -2
  100. package/dist/{chunk-4VLAQHZI.js → chunk-K7FB3JTD.js} +17 -1
  101. package/dist/chunk-K7FB3JTD.js.map +1 -0
  102. package/dist/chunk-L6LDXRWE.js +219 -0
  103. package/dist/chunk-L6LDXRWE.js.map +1 -0
  104. package/dist/chunk-M7J6Z4IJ.js +1930 -0
  105. package/dist/chunk-M7J6Z4IJ.js.map +1 -0
  106. package/dist/chunk-MQEQMS7B.js +1009 -0
  107. package/dist/chunk-MQEQMS7B.js.map +1 -0
  108. package/dist/chunk-MTELVIYR.js +1421 -0
  109. package/dist/chunk-MTELVIYR.js.map +1 -0
  110. package/dist/chunk-PVC7WDKI.js +885 -0
  111. package/dist/chunk-PVC7WDKI.js.map +1 -0
  112. package/dist/chunk-RAHNUYA5.js +368 -0
  113. package/dist/chunk-RAHNUYA5.js.map +1 -0
  114. package/dist/{chunk-DK554R7P.js → chunk-S6HXABGL.js} +2 -1
  115. package/dist/chunk-S6HXABGL.js.map +1 -0
  116. package/dist/{chunk-I3IHOHCJ.js → chunk-SHZDP2MQ.js} +1181 -1001
  117. package/dist/chunk-SHZDP2MQ.js.map +1 -0
  118. package/dist/{chunk-Y3ZLRGHC.js → chunk-SIDJO2T4.js} +16 -16
  119. package/dist/chunk-STXRMPW4.js +4131 -0
  120. package/dist/chunk-STXRMPW4.js.map +1 -0
  121. package/dist/{chunk-JR4IKCR2.js → chunk-TPND5MJS.js} +5 -5
  122. package/dist/chunk-TQPCAIQI.js +612 -0
  123. package/dist/chunk-TQPCAIQI.js.map +1 -0
  124. package/dist/chunk-UT3MHJCW.js +49 -0
  125. package/dist/chunk-UT3MHJCW.js.map +1 -0
  126. package/dist/{chunk-TEW47IVR.js → chunk-VPEFSDME.js} +2 -2
  127. package/dist/{chunk-SWTLEQL6.js → chunk-WQIA3GFB.js} +2 -2
  128. package/dist/chunk-WQIA3GFB.js.map +1 -0
  129. package/dist/{chunk-DJC4CHLQ.js → chunk-YDWBXXQZ.js} +5 -5
  130. package/dist/{chunk-6PHB5CJS.js → chunk-ZLFRB6FI.js} +2 -2
  131. package/dist/composition/index.cjs +1256 -1059
  132. package/dist/composition/index.cjs.map +1 -1
  133. package/dist/composition/index.d.cts +4 -4
  134. package/dist/composition/index.d.ts +4 -4
  135. package/dist/composition/index.js +7 -6
  136. package/dist/core/index.cjs +1218 -1021
  137. package/dist/core/index.cjs.map +1 -1
  138. package/dist/core/index.d.cts +2 -2
  139. package/dist/core/index.d.ts +2 -2
  140. package/dist/core/index.js +5 -4
  141. package/dist/cqrs/index.cjs.map +1 -1
  142. package/dist/cqrs/index.d.cts +4 -4
  143. package/dist/cqrs/index.d.ts +4 -4
  144. package/dist/cqrs/index.js +3 -2
  145. package/dist/cqrs/index.js.map +1 -1
  146. package/dist/cqrs/messaging.cjs +312 -0
  147. package/dist/cqrs/messaging.cjs.map +1 -0
  148. package/dist/cqrs/messaging.d.cts +57 -0
  149. package/dist/cqrs/messaging.d.ts +57 -0
  150. package/dist/cqrs/messaging.js +274 -0
  151. package/dist/cqrs/messaging.js.map +1 -0
  152. package/dist/cqrs/work-queue.cjs +329 -0
  153. package/dist/cqrs/work-queue.cjs.map +1 -0
  154. package/dist/cqrs/work-queue.d.cts +90 -0
  155. package/dist/cqrs/work-queue.d.ts +90 -0
  156. package/dist/cqrs/work-queue.js +292 -0
  157. package/dist/cqrs/work-queue.js.map +1 -0
  158. package/dist/data/index.cjs +19 -0
  159. package/dist/data/index.cjs.map +1 -0
  160. package/dist/data/index.d.cts +36 -0
  161. package/dist/data/index.d.ts +36 -0
  162. package/dist/data/index.js +1 -0
  163. package/dist/data/index.js.map +1 -0
  164. package/dist/data-structures/index.cjs +1252 -1052
  165. package/dist/data-structures/index.cjs.map +1 -1
  166. package/dist/data-structures/index.d.cts +9 -8
  167. package/dist/data-structures/index.d.ts +9 -8
  168. package/dist/data-structures/index.js +9 -7
  169. package/dist/{describe-BZb7AS2y.d.ts → describe-B_A5fbXH.d.ts} +1 -1
  170. package/dist/{describe-Ciu8SUnN.d.cts → describe-CQRrkv-Q.d.cts} +1 -1
  171. package/dist/executors/tool-provider-adapters.cjs +3091 -0
  172. package/dist/executors/tool-provider-adapters.cjs.map +1 -0
  173. package/dist/executors/tool-provider-adapters.d.cts +174 -0
  174. package/dist/executors/tool-provider-adapters.d.ts +174 -0
  175. package/dist/executors/tool-provider-adapters.js +1336 -0
  176. package/dist/executors/tool-provider-adapters.js.map +1 -0
  177. package/dist/executors/tool-provider-runtime.cjs +5178 -0
  178. package/dist/executors/tool-provider-runtime.cjs.map +1 -0
  179. package/dist/executors/tool-provider-runtime.d.cts +17 -0
  180. package/dist/executors/tool-provider-runtime.d.ts +17 -0
  181. package/dist/executors/tool-provider-runtime.js +15 -0
  182. package/dist/executors/tool-provider-runtime.js.map +1 -0
  183. package/dist/executors/tool-provider.cjs +6392 -0
  184. package/dist/executors/tool-provider.cjs.map +1 -0
  185. package/dist/executors/tool-provider.d.cts +60 -0
  186. package/dist/executors/tool-provider.d.ts +60 -0
  187. package/dist/executors/tool-provider.js +89 -0
  188. package/dist/executors/tool-provider.js.map +1 -0
  189. package/dist/executors/work-queue.cjs +342 -0
  190. package/dist/executors/work-queue.cjs.map +1 -0
  191. package/dist/executors/work-queue.d.cts +90 -0
  192. package/dist/executors/work-queue.d.ts +90 -0
  193. package/dist/executors/work-queue.js +306 -0
  194. package/dist/executors/work-queue.js.map +1 -0
  195. package/dist/graph/index.cjs +1536 -1324
  196. package/dist/graph/index.cjs.map +1 -1
  197. package/dist/graph/index.d.cts +10 -9
  198. package/dist/graph/index.d.ts +10 -9
  199. package/dist/graph/index.js +22 -20
  200. package/dist/{graph-s23RbbFO.d.cts → graph-CWK3HLPB.d.cts} +134 -132
  201. package/dist/{graph-DfdF9zy4.d.ts → graph-ho5sotHP.d.ts} +134 -132
  202. package/dist/{index-SnzZu3x7.d.ts → index-CQWcE0Dw.d.ts} +18 -4
  203. package/dist/{index-CAEmLCYF.d.cts → index-DHA1i67c.d.cts} +18 -4
  204. package/dist/index.cjs +3331 -3020
  205. package/dist/index.cjs.map +1 -1
  206. package/dist/index.d.cts +14 -10
  207. package/dist/index.d.ts +14 -10
  208. package/dist/index.js +114 -108
  209. package/dist/inspection/boundary.cjs +98 -0
  210. package/dist/inspection/boundary.cjs.map +1 -0
  211. package/dist/inspection/boundary.d.cts +61 -0
  212. package/dist/inspection/boundary.d.ts +61 -0
  213. package/dist/inspection/boundary.js +75 -0
  214. package/dist/inspection/boundary.js.map +1 -0
  215. package/dist/measurements-C0mAvWU1.d.cts +164 -0
  216. package/dist/measurements-OMpCeBwh.d.ts +164 -0
  217. package/dist/{messages-BZqrGGm1.d.ts → messages-CAzUPPJM.d.cts} +10 -5
  218. package/dist/{messages-BZqrGGm1.d.cts → messages-CAzUPPJM.d.ts} +10 -5
  219. package/dist/messaging/index.cjs +756 -619
  220. package/dist/messaging/index.cjs.map +1 -1
  221. package/dist/messaging/index.d.cts +17 -226
  222. package/dist/messaging/index.d.ts +17 -226
  223. package/dist/messaging/index.js +19 -749
  224. package/dist/messaging/index.js.map +1 -1
  225. package/dist/operators/index.cjs +1256 -1059
  226. package/dist/operators/index.cjs.map +1 -1
  227. package/dist/operators/index.d.cts +6 -6
  228. package/dist/operators/index.d.ts +6 -6
  229. package/dist/operators/index.js +9 -8
  230. package/dist/orchestration/index.cjs +8664 -2617
  231. package/dist/orchestration/index.cjs.map +1 -1
  232. package/dist/orchestration/index.d.cts +171 -221
  233. package/dist/orchestration/index.d.ts +171 -221
  234. package/dist/orchestration/index.js +74 -982
  235. package/dist/orchestration/index.js.map +1 -1
  236. package/dist/orchestration/messaging.cjs +314 -0
  237. package/dist/orchestration/messaging.cjs.map +1 -0
  238. package/dist/orchestration/messaging.d.cts +56 -0
  239. package/dist/orchestration/messaging.d.ts +56 -0
  240. package/dist/orchestration/messaging.js +276 -0
  241. package/dist/orchestration/messaging.js.map +1 -0
  242. package/dist/orchestration/work-queue.cjs +1500 -0
  243. package/dist/orchestration/work-queue.cjs.map +1 -0
  244. package/dist/orchestration/work-queue.d.cts +196 -0
  245. package/dist/orchestration/work-queue.d.ts +196 -0
  246. package/dist/orchestration/work-queue.js +1289 -0
  247. package/dist/orchestration/work-queue.js.map +1 -0
  248. package/dist/patterns/event-flow.cjs +433 -0
  249. package/dist/patterns/event-flow.cjs.map +1 -0
  250. package/dist/patterns/event-flow.d.cts +115 -0
  251. package/dist/patterns/event-flow.d.ts +115 -0
  252. package/dist/patterns/event-flow.js +14 -0
  253. package/dist/patterns/event-flow.js.map +1 -0
  254. package/dist/patterns/index.cjs +748 -355
  255. package/dist/patterns/index.cjs.map +1 -1
  256. package/dist/patterns/index.d.cts +9 -5
  257. package/dist/patterns/index.d.ts +9 -5
  258. package/dist/patterns/index.js +13 -4
  259. package/dist/process-types-C9uMYz3i.d.ts +200 -0
  260. package/dist/process-types-h3uRlzDc.d.cts +200 -0
  261. package/dist/{reactive-collection-BxBqtIOE.d.cts → reactive-collection-B9R0Bl1P.d.cts} +11 -41
  262. package/dist/{reactive-collection-Cb1II1Fi.d.ts → reactive-collection-BXFrH0U2.d.ts} +11 -41
  263. package/dist/{reactive-collection-storage-D-KmjE0J.d.cts → reactive-collection-storage-BLGv8Xp8.d.cts} +5 -5
  264. package/dist/{reactive-collection-storage-BNiEc-Gd.d.ts → reactive-collection-storage-a4zD3665.d.ts} +5 -5
  265. package/dist/{reactive-map-BcB4KsQR.d.ts → reactive-map-C_8sOfdS.d.cts} +7 -6
  266. package/dist/{reactive-map-D-g3dv8I.d.cts → reactive-map-jle5dnok.d.ts} +7 -6
  267. package/dist/render/index.d.cts +3 -3
  268. package/dist/render/index.d.ts +3 -3
  269. package/dist/render/index.js +1 -0
  270. package/dist/scheduled-readiness-5rwQlyjV.d.ts +91 -0
  271. package/dist/scheduled-readiness-DpRY8jI0.d.cts +91 -0
  272. package/dist/semantic-memory-graph-C2ZUwIlq.d.ts +30 -0
  273. package/dist/semantic-memory-graph-DlZBD_Eu.d.cts +30 -0
  274. package/dist/{semantic-memory-graph-BYoIlP35.d.cts → semantic-memory-graph-types-BvzdqmkY.d.cts} +2 -28
  275. package/dist/{semantic-memory-graph-CxyXLms3.d.ts → semantic-memory-graph-types-Ci-OtahO.d.ts} +2 -28
  276. package/dist/solutions/index.cjs +6788 -2128
  277. package/dist/solutions/index.cjs.map +1 -1
  278. package/dist/solutions/index.d.cts +15 -519
  279. package/dist/solutions/index.d.ts +15 -519
  280. package/dist/solutions/index.js +91 -7
  281. package/dist/solutions/reactive-layout/browser/index.cjs +457 -0
  282. package/dist/solutions/reactive-layout/browser/index.cjs.map +1 -0
  283. package/dist/solutions/reactive-layout/browser/index.d.cts +44 -0
  284. package/dist/solutions/reactive-layout/browser/index.d.ts +44 -0
  285. package/dist/solutions/reactive-layout/browser/index.js +69 -0
  286. package/dist/solutions/reactive-layout/browser/index.js.map +1 -0
  287. package/dist/solutions/reactive-layout/index.cjs +4494 -0
  288. package/dist/solutions/reactive-layout/index.cjs.map +1 -0
  289. package/dist/solutions/reactive-layout/index.d.cts +37 -0
  290. package/dist/solutions/reactive-layout/index.d.ts +37 -0
  291. package/dist/solutions/reactive-layout/index.js +146 -0
  292. package/dist/solutions/reactive-layout/index.js.map +1 -0
  293. package/dist/solutions/reactive-layout/node-canvas/index.cjs +555 -0
  294. package/dist/solutions/reactive-layout/node-canvas/index.cjs.map +1 -0
  295. package/dist/solutions/reactive-layout/node-canvas/index.d.cts +54 -0
  296. package/dist/solutions/reactive-layout/node-canvas/index.d.ts +54 -0
  297. package/dist/solutions/reactive-layout/node-canvas/index.js +131 -0
  298. package/dist/solutions/reactive-layout/node-canvas/index.js.map +1 -0
  299. package/dist/solutions/reactive-layout/react-native/index.cjs +504 -0
  300. package/dist/solutions/reactive-layout/react-native/index.cjs.map +1 -0
  301. package/dist/solutions/reactive-layout/react-native/index.d.cts +51 -0
  302. package/dist/solutions/reactive-layout/react-native/index.d.ts +51 -0
  303. package/dist/solutions/reactive-layout/react-native/index.js +77 -0
  304. package/dist/solutions/reactive-layout/react-native/index.js.map +1 -0
  305. package/dist/solutions/reactive-layout/skia/index.cjs +557 -0
  306. package/dist/solutions/reactive-layout/skia/index.cjs.map +1 -0
  307. package/dist/solutions/reactive-layout/skia/index.d.cts +64 -0
  308. package/dist/solutions/reactive-layout/skia/index.d.ts +64 -0
  309. package/dist/solutions/reactive-layout/skia/index.js +70 -0
  310. package/dist/solutions/reactive-layout/skia/index.js.map +1 -0
  311. package/dist/solutions/work-item/actions.cjs +2345 -0
  312. package/dist/solutions/work-item/actions.cjs.map +1 -0
  313. package/dist/solutions/work-item/actions.d.cts +40 -0
  314. package/dist/solutions/work-item/actions.d.ts +40 -0
  315. package/dist/solutions/work-item/actions.js +2078 -0
  316. package/dist/solutions/work-item/actions.js.map +1 -0
  317. package/dist/solutions/work-item/scheduling.cjs +9797 -0
  318. package/dist/solutions/work-item/scheduling.cjs.map +1 -0
  319. package/dist/solutions/work-item/scheduling.d.cts +1868 -0
  320. package/dist/solutions/work-item/scheduling.d.ts +1868 -0
  321. package/dist/solutions/work-item/scheduling.js +146 -0
  322. package/dist/solutions/work-item/scheduling.js.map +1 -0
  323. package/dist/solutions/work-item/work-queue.cjs +306 -0
  324. package/dist/solutions/work-item/work-queue.cjs.map +1 -0
  325. package/dist/solutions/work-item/work-queue.d.cts +71 -0
  326. package/dist/solutions/work-item/work-queue.d.ts +71 -0
  327. package/dist/solutions/work-item/work-queue.js +270 -0
  328. package/dist/solutions/work-item/work-queue.js.map +1 -0
  329. package/dist/sources/browser.cjs +1399 -1052
  330. package/dist/sources/browser.cjs.map +1 -1
  331. package/dist/sources/browser.d.cts +33 -6
  332. package/dist/sources/browser.d.ts +33 -6
  333. package/dist/sources/browser.js +73 -6
  334. package/dist/sources/browser.js.map +1 -1
  335. package/dist/sources/index.cjs +1345 -1065
  336. package/dist/sources/index.cjs.map +1 -1
  337. package/dist/sources/index.d.cts +5 -5
  338. package/dist/sources/index.d.ts +5 -5
  339. package/dist/sources/index.js +7 -6
  340. package/dist/sources/node.cjs.map +1 -1
  341. package/dist/sources/node.d.cts +4 -4
  342. package/dist/sources/node.d.ts +4 -4
  343. package/dist/sources/node.js +2 -1
  344. package/dist/sources/node.js.map +1 -1
  345. package/dist/storage/browser.cjs +16 -0
  346. package/dist/storage/browser.cjs.map +1 -1
  347. package/dist/storage/browser.js +4 -3
  348. package/dist/storage/browser.js.map +1 -1
  349. package/dist/storage/index.cjs +16 -0
  350. package/dist/storage/index.cjs.map +1 -1
  351. package/dist/storage/index.d.cts +6 -5
  352. package/dist/storage/index.d.ts +6 -5
  353. package/dist/storage/index.js +10 -9
  354. package/dist/storage/node.cjs +16 -0
  355. package/dist/storage/node.cjs.map +1 -1
  356. package/dist/storage/node.js +4 -3
  357. package/dist/storage/node.js.map +1 -1
  358. package/dist/store-BmtEs9mG.d.ts +123 -0
  359. package/dist/store-PAAsYvML.d.cts +123 -0
  360. package/dist/testing/index.cjs +1 -0
  361. package/dist/testing/index.cjs.map +1 -1
  362. package/dist/testing/index.d.cts +1 -1
  363. package/dist/testing/index.d.ts +1 -1
  364. package/dist/testing/index.js +3 -2
  365. package/dist/types-BRNKoFHj.d.ts +357 -0
  366. package/dist/{types-h12mNYbq.d.ts → types-BS6CyR-x.d.cts} +49 -130
  367. package/dist/types-BWK2ay3e.d.cts +457 -0
  368. package/dist/types-BXKSAoE1.d.cts +357 -0
  369. package/dist/types-BaPpZItj.d.ts +457 -0
  370. package/dist/types-BhveCMg5.d.cts +274 -0
  371. package/dist/{types-bNMSWKqF.d.cts → types-C9NOgNJw.d.ts} +49 -130
  372. package/dist/types-CTsQ8Ww4.d.ts +274 -0
  373. package/dist/types-DL_05n2M.d.ts +34 -0
  374. package/dist/types-XDoqxYO9.d.cts +34 -0
  375. package/dist/work-item-runtime-types-BqtWnSCS.d.ts +138 -0
  376. package/dist/work-item-runtime-types-CHO03AKh.d.cts +138 -0
  377. package/dist/work-queue/index.cjs +1136 -0
  378. package/dist/work-queue/index.cjs.map +1 -0
  379. package/dist/work-queue/index.d.cts +21 -0
  380. package/dist/work-queue/index.d.ts +21 -0
  381. package/dist/work-queue/index.js +1082 -0
  382. package/dist/work-queue/index.js.map +1 -0
  383. package/package.json +603 -249
  384. package/dist/chunk-2ILL7HQI.js.map +0 -1
  385. package/dist/chunk-4VLAQHZI.js.map +0 -1
  386. package/dist/chunk-COHO25CZ.js.map +0 -1
  387. package/dist/chunk-DK554R7P.js.map +0 -1
  388. package/dist/chunk-G4M3NHRJ.js.map +0 -1
  389. package/dist/chunk-I3IHOHCJ.js.map +0 -1
  390. package/dist/chunk-JIMUDQN3.js.map +0 -1
  391. package/dist/chunk-RIIOUTGM.js.map +0 -1
  392. package/dist/chunk-SWTLEQL6.js.map +0 -1
  393. /package/dist/{chunk-GDL26N2T.js.map → chunk-3KN7NJDR.js.map} +0 -0
  394. /package/dist/{chunk-Z2ANQ6JW.js.map → chunk-4Q77MMJY.js.map} +0 -0
  395. /package/dist/{chunk-D6BG7U6A.js.map → chunk-7HZRJMN6.js.map} +0 -0
  396. /package/dist/{chunk-SCRFRCGR.js.map → chunk-BSQGE5PS.js.map} +0 -0
  397. /package/dist/{chunk-PKVBHGBM.js.map → chunk-CJIFGJQG.js.map} +0 -0
  398. /package/dist/{chunk-K3FXTC3I.js.map → chunk-HJACH5PU.js.map} +0 -0
  399. /package/dist/{chunk-GTPCOEOZ.js.map → chunk-IDMLXLLG.js.map} +0 -0
  400. /package/dist/{chunk-DKP56CSW.js.map → chunk-JKAYLDQV.js.map} +0 -0
  401. /package/dist/{chunk-Y3ZLRGHC.js.map → chunk-SIDJO2T4.js.map} +0 -0
  402. /package/dist/{chunk-JR4IKCR2.js.map → chunk-TPND5MJS.js.map} +0 -0
  403. /package/dist/{chunk-TEW47IVR.js.map → chunk-VPEFSDME.js.map} +0 -0
  404. /package/dist/{chunk-DJC4CHLQ.js.map → chunk-YDWBXXQZ.js.map} +0 -0
  405. /package/dist/{chunk-6PHB5CJS.js.map → chunk-ZLFRB6FI.js.map} +0 -0
@@ -0,0 +1,1136 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/work-queue/index.ts
21
+ var work_queue_exports = {};
22
+ __export(work_queue_exports, {
23
+ workQueue: () => workQueue
24
+ });
25
+ module.exports = __toCommonJS(work_queue_exports);
26
+
27
+ // src/protocol/messages.ts
28
+ var SENTINEL = void 0;
29
+
30
+ // src/ctx/types.ts
31
+ function depWaves(ctx, depIndex) {
32
+ return ctx.waveData[depIndex] ?? [];
33
+ }
34
+ function depBatch(ctx, depIndex) {
35
+ const waves = depWaves(ctx, depIndex);
36
+ if (waves.length === 0) return null;
37
+ const flattened = waves.flat().filter((v) => v !== SENTINEL);
38
+ return flattened.length === 0 ? [] : flattened;
39
+ }
40
+
41
+ // src/messaging/internal.ts
42
+ var busStates = /* @__PURE__ */ new WeakMap();
43
+ function getMessageBusState(bus) {
44
+ return busStates.get(bus);
45
+ }
46
+ function attachMessageBusDeferredCommandSink(graph, bus, commands) {
47
+ const state = getMessageBusState(bus);
48
+ if (state === void 0) throw new Error("messageBus: unknown implementation");
49
+ if (state.graph !== graph) throw new Error("messageBus: command sink graph must match");
50
+ const busCommands = bus.commands;
51
+ if (busCommands === void 0) throw new Error("messageBus: missing commands node");
52
+ const boundary = commands;
53
+ const unsubscribe = commands.subscribe((msg) => {
54
+ if (msg[0] !== "DATA") return;
55
+ const command = msg[1];
56
+ const send = () => busCommands.down([["DATA", command]]);
57
+ if (boundary.__deferBoundary === void 0) send();
58
+ else boundary.__deferBoundary(send);
59
+ });
60
+ return unsubscribe;
61
+ }
62
+
63
+ // src/work-queue/utils.ts
64
+ function appendRecord(state, queueId, record) {
65
+ const full = { ...record, queueId, recordSeq: ++state.recordSeq };
66
+ state.records.push(full);
67
+ return full;
68
+ }
69
+ function recordEvent(record) {
70
+ return { kind: "record", record };
71
+ }
72
+ function statusEvent(queueId, kind, timestampMs, fields = {}) {
73
+ return {
74
+ kind: "status",
75
+ status: {
76
+ kind,
77
+ queueId,
78
+ timestampMs,
79
+ ...fields.workId === void 0 ? {} : { workId: fields.workId },
80
+ ...fields.commandId === void 0 ? {} : { commandId: fields.commandId },
81
+ ...fields.recordSeq === void 0 ? {} : { recordSeq: fields.recordSeq },
82
+ ...fields.asOfRecordSeq === void 0 ? {} : { asOfRecordSeq: fields.asOfRecordSeq },
83
+ ...fields.issueCode === void 0 ? {} : { issueCode: fields.issueCode },
84
+ ...fields.details === void 0 ? {} : { details: fields.details }
85
+ }
86
+ };
87
+ }
88
+ function issueEvent(queueId, code, message, timestampMs, details) {
89
+ return {
90
+ kind: "issue",
91
+ issue: {
92
+ kind: "issue",
93
+ code,
94
+ message,
95
+ severity: "error",
96
+ source: "workQueue",
97
+ details,
98
+ metadata: { queueId, timestampMs }
99
+ }
100
+ };
101
+ }
102
+ function rejectQueueCommand(queueId, command, code, message, nowMs, commandId = commandIdFrom(command)) {
103
+ return [
104
+ issueEvent(queueId, code, message, nowMs, command),
105
+ statusEvent(queueId, "command-rejected", nowMs, {
106
+ ...commandId === void 0 ? {} : { commandId },
107
+ issueCode: code
108
+ })
109
+ ];
110
+ }
111
+ function validateQueueCommand(queueId, command) {
112
+ if (!isObjectRecord(command))
113
+ return { code: "malformed-command", message: "command must be an object" };
114
+ if (typeof command.kind !== "string")
115
+ return { code: "malformed-command", message: "command kind is required" };
116
+ if (!isWorkQueueCommandKind(command.kind))
117
+ return { code: "malformed-command", message: `unknown command kind '${command.kind}'` };
118
+ if (typeof command.commandId !== "string" || command.commandId.length === 0)
119
+ return { code: "malformed-command", message: "commandId must be a non-empty string" };
120
+ if (command.queueId !== void 0 && command.queueId !== queueId)
121
+ return { code: "queue-mismatch", message: "command queueId does not match this queue" };
122
+ switch (command.kind) {
123
+ case "submit":
124
+ return command.payload === void 0 ? { code: "malformed-command", message: "submit payload is required" } : void 0;
125
+ case "claim":
126
+ if (typeof command.workerId !== "string" || command.workerId.length === 0)
127
+ return { code: "malformed-command", message: "claim workerId is required" };
128
+ if (command.limit !== void 0 && !isPositiveInteger(command.limit))
129
+ return { code: "malformed-command", message: "claim limit must be a positive integer" };
130
+ if (command.requestedWorkIds !== void 0 && (!Array.isArray(command.requestedWorkIds) || !command.requestedWorkIds.every((id) => typeof id === "string" && id.length > 0))) {
131
+ return { code: "malformed-command", message: "requestedWorkIds must be strings" };
132
+ }
133
+ if (command.leaseDurationMs !== void 0 && !isPositiveInteger(command.leaseDurationMs))
134
+ return {
135
+ code: "malformed-command",
136
+ message: "leaseDurationMs must be a positive integer"
137
+ };
138
+ return void 0;
139
+ case "renew-lease":
140
+ if (command.leaseDurationMs !== void 0 && !isPositiveInteger(command.leaseDurationMs))
141
+ return {
142
+ code: "malformed-command",
143
+ message: "leaseDurationMs must be a positive integer"
144
+ };
145
+ if (command.leaseExpiresAtMs !== void 0 && !isFiniteNumber(command.leaseExpiresAtMs))
146
+ return { code: "malformed-command", message: "leaseExpiresAtMs must be finite" };
147
+ return validateLeaseCommand(command);
148
+ case "release":
149
+ case "complete":
150
+ case "fail":
151
+ return validateLeaseCommand(command);
152
+ case "cancel":
153
+ return requiredString(command.workId, "workId");
154
+ case "schedule": {
155
+ const workIdError = requiredString(command.workId, "workId");
156
+ if (workIdError !== void 0) return workIdError;
157
+ if (!isFiniteNumber(command.notBeforeMs))
158
+ return { code: "malformed-command", message: "notBeforeMs must be finite" };
159
+ if (command.deadlineMs !== void 0 && !isFiniteNumber(command.deadlineMs))
160
+ return { code: "malformed-command", message: "deadlineMs must be finite" };
161
+ return void 0;
162
+ }
163
+ case "expire-leases":
164
+ if (command.limit !== void 0 && !isPositiveInteger(command.limit))
165
+ return {
166
+ code: "malformed-command",
167
+ message: "expire-leases limit must be a positive integer"
168
+ };
169
+ if (command.workIds !== void 0 && (!Array.isArray(command.workIds) || !command.workIds.every((id) => typeof id === "string" && id.length > 0))) {
170
+ return { code: "malformed-command", message: "workIds must be strings" };
171
+ }
172
+ return void 0;
173
+ }
174
+ }
175
+ function validateLeaseCommand(command) {
176
+ for (const key of ["workId", "leaseId", "workerId"]) {
177
+ const err = requiredString(command[key], key);
178
+ if (err !== void 0) return err;
179
+ }
180
+ if (!isPositiveInteger(command.attempt))
181
+ return { code: "malformed-command", message: "attempt must be a positive integer" };
182
+ return void 0;
183
+ }
184
+ function requiredString(value, name) {
185
+ return typeof value === "string" && value.length > 0 ? void 0 : { code: "malformed-command", message: `${name} must be a non-empty string` };
186
+ }
187
+ function commandIdFrom(command) {
188
+ return isObjectRecord(command) && typeof command.commandId === "string" ? command.commandId : void 0;
189
+ }
190
+ function isWorkQueueCommandKind(kind) {
191
+ return kind === "submit" || kind === "claim" || kind === "renew-lease" || kind === "release" || kind === "complete" || kind === "fail" || kind === "cancel" || kind === "schedule" || kind === "expire-leases";
192
+ }
193
+ function isObjectRecord(value) {
194
+ return typeof value === "object" && value !== null && !Array.isArray(value);
195
+ }
196
+ function isPositiveInteger(value) {
197
+ return Number.isInteger(value) && value > 0;
198
+ }
199
+ function isFiniteNumber(value) {
200
+ return typeof value === "number" && Number.isFinite(value);
201
+ }
202
+ function publishQueueCommand(node, command) {
203
+ node.down([["DATA", command]]);
204
+ return command;
205
+ }
206
+ var commandSeq = 0;
207
+ function nextCommandId(queueId, kind) {
208
+ commandSeq += 1;
209
+ return `${queueId}:${kind}:${commandSeq}`;
210
+ }
211
+ function isReady(work, nowMs) {
212
+ if (work.state === "scheduled")
213
+ return work.notBeforeMs !== void 0 && work.notBeforeMs <= nowMs;
214
+ if (work.state === "retry-wait") return work.retryAtMs !== void 0 && work.retryAtMs <= nowMs;
215
+ return work.state === "ready";
216
+ }
217
+ function isReadyForProjection(work, nowMs) {
218
+ if (work.state === "scheduled" || work.state === "retry-wait") {
219
+ return nowMs === void 0 ? false : isReady(work, nowMs);
220
+ }
221
+ return isReady(work, 0);
222
+ }
223
+ function isTerminal(state) {
224
+ return state === "completed" || state === "canceled" || state === "dead-lettered";
225
+ }
226
+ function payloadAsRecord(value) {
227
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
228
+ }
229
+ function numberOrUndefined(value) {
230
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
231
+ }
232
+ function stringArrayOrUndefined(value) {
233
+ return Array.isArray(value) && value.every((entry) => typeof entry === "string") ? value : void 0;
234
+ }
235
+ function pullParams(pull) {
236
+ return typeof pull?.params === "object" && pull.params !== null && !Array.isArray(pull.params) ? pull.params : {};
237
+ }
238
+ var SUBMIT_ENVELOPE = "__graphreflyWorkQueueSubmit";
239
+ function submitPayload(payload, meta) {
240
+ if (Object.keys(meta).length === 0) return payload;
241
+ return { [SUBMIT_ENVELOPE]: true, payload, ...meta };
242
+ }
243
+ function decodeSubmittedPayload(payload) {
244
+ if (isObjectRecord(payload) && payload[SUBMIT_ENVELOPE] === true && Object.hasOwn(payload, "payload")) {
245
+ const { payload: inner, [SUBMIT_ENVELOPE]: _tag, ...meta } = payload;
246
+ return { payload: inner, meta };
247
+ }
248
+ return { payload, meta: payloadAsRecord(payload) };
249
+ }
250
+ function commandNowMs(command, fallback) {
251
+ return typeof command.nowMs === "number" && Number.isFinite(command.nowMs) ? command.nowMs : fallback;
252
+ }
253
+ function positiveLimit(limit) {
254
+ if (!Number.isInteger(limit) || limit < 1)
255
+ throw new Error("workQueue: limit must be a positive integer");
256
+ return limit;
257
+ }
258
+ function assertNonEmpty(value, owner) {
259
+ if (typeof value !== "string" || value.length === 0)
260
+ throw new Error(`${owner} must be a non-empty string`);
261
+ }
262
+ function materializeLeaseExpired(queueId, state, work, commandId, nowMs, rejection) {
263
+ const record = appendRecord(state, queueId, {
264
+ kind: "lease-expired",
265
+ workId: work.workId,
266
+ ...commandId === void 0 ? {} : { commandId },
267
+ leaseId: work.leaseId,
268
+ attempt: work.attempt,
269
+ workerId: work.workerId,
270
+ leaseExpiresAtMs: work.leaseExpiresAtMs,
271
+ expiredAtMs: nowMs,
272
+ recordedAtMs: nowMs
273
+ });
274
+ work.state = "ready";
275
+ clearLease(work);
276
+ const events = [recordEvent(record)];
277
+ if (rejection !== void 0) {
278
+ events.push(
279
+ ...rejectQueueCommand(
280
+ queueId,
281
+ rejection.command,
282
+ rejection.code,
283
+ rejection.message,
284
+ nowMs,
285
+ commandId
286
+ )
287
+ );
288
+ }
289
+ return events;
290
+ }
291
+ function isExpiredLease(work, nowMs) {
292
+ return work.state === "leased" && work.leaseExpiresAtMs !== void 0 && work.leaseExpiresAtMs <= nowMs;
293
+ }
294
+ function clearLease(work) {
295
+ work.leaseId = void 0;
296
+ work.workerId = void 0;
297
+ work.leaseExpiresAtMs = void 0;
298
+ }
299
+
300
+ // src/work-queue/projections.ts
301
+ function availablePage(state, params) {
302
+ const limit = positiveLimit(params.limit ?? 100);
303
+ const orderByWorkId = params.afterWorkId !== void 0 && params.afterAdmissionSeq === void 0;
304
+ const all = [...state.works.values()].filter((work) => isReadyForProjection(work, params.nowMs)).filter((work) => params.afterWorkId === void 0 || work.workId > params.afterWorkId).filter(
305
+ (work) => params.afterAdmissionSeq === void 0 || work.admissionSeq > params.afterAdmissionSeq
306
+ ).sort(
307
+ (a, b) => orderByWorkId ? a.workId.localeCompare(b.workId) : a.admissionSeq - b.admissionSeq || a.workId.localeCompare(b.workId)
308
+ );
309
+ const items = all.map((work) => ({
310
+ workId: work.workId,
311
+ state: work.state,
312
+ payload: work.payload,
313
+ admissionSeq: work.admissionSeq,
314
+ priority: work.priority,
315
+ tags: work.tags,
316
+ requirements: work.requirements,
317
+ notBeforeMs: work.notBeforeMs,
318
+ retryAtMs: work.retryAtMs,
319
+ deadlineMs: work.deadlineMs
320
+ }));
321
+ const page = items.slice(0, limit);
322
+ return {
323
+ items: page,
324
+ ...items.length > limit && page.length > 0 ? { nextAfterWorkId: page[page.length - 1]?.workId } : {},
325
+ ...items.length > limit && page.length > 0 ? { nextAfterAdmissionSeq: page[page.length - 1]?.admissionSeq } : {},
326
+ hasMore: items.length > limit,
327
+ asOfRecordSeq: state.recordSeq
328
+ };
329
+ }
330
+ function workSnapshot(state, workId) {
331
+ const work = state.works.get(workId);
332
+ return {
333
+ workId,
334
+ state: work?.state,
335
+ payload: work?.payload,
336
+ ...work?.state !== "leased" || work.leaseId === void 0 ? {} : {
337
+ activeLease: {
338
+ leaseId: work.leaseId,
339
+ attempt: work.attempt,
340
+ workerId: work.workerId,
341
+ leaseExpiresAtMs: work.leaseExpiresAtMs
342
+ }
343
+ },
344
+ records: state.records.filter((record) => record.workId === workId),
345
+ asOfRecordSeq: state.recordSeq
346
+ };
347
+ }
348
+ function deadLetterPage(state, params) {
349
+ const limit = positiveLimit(params.limit ?? 100);
350
+ const entries = state.deadLetters.filter((record) => {
351
+ if (params.afterDeadLetterSeq !== void 0 && record.recordSeq <= params.afterDeadLetterSeq)
352
+ return false;
353
+ if (params.afterWorkId !== void 0 && (record.workId ?? "") <= params.afterWorkId)
354
+ return false;
355
+ return true;
356
+ });
357
+ const page = entries.slice(0, limit);
358
+ return {
359
+ entries: page,
360
+ ...entries.length > limit && page.length > 0 ? { nextAfterDeadLetterSeq: page[page.length - 1]?.recordSeq } : {},
361
+ hasMore: entries.length > limit,
362
+ asOfRecordSeq: state.recordSeq
363
+ };
364
+ }
365
+
366
+ // src/work-queue/index.ts
367
+ function workQueue(graph, opts) {
368
+ assertNonEmpty(opts.queueId, "workQueue.queueId");
369
+ assertNonEmpty(opts.topic, "workQueue.topic");
370
+ assertNonEmpty(opts.subscriptionId, "workQueue.subscriptionId");
371
+ const name = opts.name ?? `workQueue/${opts.queueId}`;
372
+ const now = opts.now ?? Date.now;
373
+ const leaseDurationMs = opts.leaseDurationMs ?? 3e4;
374
+ const retry = opts.retry ?? { maxAttempts: 3, delayMs: 0 };
375
+ const admission = opts.bus.subscription({
376
+ topic: opts.topic,
377
+ subscriptionId: opts.subscriptionId,
378
+ from: opts.from ?? "earliest",
379
+ name: `${name}/admission`
380
+ });
381
+ const commands = graph.node(
382
+ [],
383
+ (ctx) => {
384
+ for (const command of depBatch(ctx, 0) ?? []) ctx.down([["DATA", command]]);
385
+ },
386
+ {
387
+ name: `${name}/commands`,
388
+ factory: "workQueueCommands",
389
+ completeWhenDepsComplete: false,
390
+ errorWhenDepsError: false
391
+ }
392
+ );
393
+ const state = {
394
+ recordSeq: 0,
395
+ leaseSeq: 0,
396
+ works: /* @__PURE__ */ new Map(),
397
+ sourceSeqs: /* @__PURE__ */ new Set(),
398
+ commandIds: /* @__PURE__ */ new Set(),
399
+ idempotencyKeys: /* @__PURE__ */ new Set(),
400
+ records: [],
401
+ deadLetters: []
402
+ };
403
+ const admissionKick = graph.node([], null, {
404
+ name: `${name}/admissionKick`,
405
+ factory: "workQueueAdmissionKick",
406
+ initial: "poll",
407
+ completeWhenDepsComplete: false,
408
+ errorWhenDepsError: false
409
+ });
410
+ const admissionPages = graph.node(
411
+ [admission.available, admissionKick, opts.bus.messages, opts.bus.status],
412
+ (ctx) => {
413
+ for (const page of depBatch(ctx, 0) ?? []) {
414
+ ctx.down([["DATA", page]]);
415
+ }
416
+ let shouldPull = (depBatch(ctx, 1)?.length ?? 0) > 0;
417
+ for (const message of depBatch(ctx, 2) ?? []) {
418
+ if (message.topic === opts.topic) shouldPull = true;
419
+ }
420
+ for (const status2 of depBatch(ctx, 3) ?? []) {
421
+ if (shouldPollAdmission(status2, opts.topic, opts.subscriptionId)) {
422
+ shouldPull = true;
423
+ }
424
+ }
425
+ if (shouldPull) {
426
+ ctx.upNext([["PULL", { pullId: admission.availablePullId, params: { limit: 100 } }]], 0);
427
+ }
428
+ },
429
+ {
430
+ name: `${name}/admissionPages`,
431
+ factory: "workQueueAdmissionPages",
432
+ partial: true,
433
+ completeWhenDepsComplete: false,
434
+ errorWhenDepsError: false
435
+ }
436
+ );
437
+ const runtime = graph.node(
438
+ [commands, admissionPages],
439
+ (ctx) => {
440
+ for (const page of depBatch(ctx, 1) ?? []) {
441
+ for (const msg of page.messages) {
442
+ for (const event of admitMessage(opts, state, msg, now())) ctx.down([["DATA", event]]);
443
+ }
444
+ }
445
+ for (const command of depBatch(ctx, 0) ?? []) {
446
+ const commandTime = commandNowMs(command, now());
447
+ for (const event of reduceQueueCommand(
448
+ opts,
449
+ state,
450
+ command,
451
+ commandTime,
452
+ leaseDurationMs,
453
+ retry
454
+ )) {
455
+ ctx.down([["DATA", event]]);
456
+ }
457
+ }
458
+ },
459
+ {
460
+ name: `${name}/runtime`,
461
+ factory: "workQueueRuntime",
462
+ partial: true,
463
+ completeWhenDepsComplete: false,
464
+ errorWhenDepsError: false
465
+ }
466
+ );
467
+ const records = graph.node(
468
+ [runtime],
469
+ (ctx) => {
470
+ for (const event of depBatch(ctx, 0) ?? []) {
471
+ const typed = event;
472
+ if (typed.kind === "record") ctx.down([["DATA", typed.record]]);
473
+ }
474
+ },
475
+ {
476
+ name: `${name}/records`,
477
+ factory: "workQueueRecords",
478
+ completeWhenDepsComplete: false,
479
+ errorWhenDepsError: false
480
+ }
481
+ );
482
+ const status = graph.node(
483
+ [runtime],
484
+ (ctx) => {
485
+ for (const event of depBatch(ctx, 0) ?? []) {
486
+ const typed = event;
487
+ if (typed.kind === "status") ctx.down([["DATA", typed.status]]);
488
+ }
489
+ },
490
+ {
491
+ name: `${name}/status`,
492
+ factory: "workQueueStatus",
493
+ completeWhenDepsComplete: false,
494
+ errorWhenDepsError: false
495
+ }
496
+ );
497
+ const issues = graph.node(
498
+ [runtime],
499
+ (ctx) => {
500
+ for (const event of depBatch(ctx, 0) ?? []) {
501
+ const typed = event;
502
+ if (typed.kind === "issue") ctx.down([["DATA", typed.issue]]);
503
+ }
504
+ },
505
+ {
506
+ name: `${name}/issues`,
507
+ factory: "workQueueIssues",
508
+ completeWhenDepsComplete: false,
509
+ errorWhenDepsError: false
510
+ }
511
+ );
512
+ const admissionAckCommands = graph.node(
513
+ [records],
514
+ (ctx) => {
515
+ for (const record of depBatch(ctx, 0) ?? []) {
516
+ const command = admissionAckCommand(record);
517
+ if (command !== void 0) ctx.down([["DATA", command]]);
518
+ }
519
+ },
520
+ {
521
+ name: `${name}/admissionAckCommands`,
522
+ factory: "workQueueAdmissionAckCommands",
523
+ completeWhenDepsComplete: false,
524
+ errorWhenDepsError: false
525
+ }
526
+ );
527
+ attachMessageBusDeferredCommandSink(graph, opts.bus, admissionAckCommands);
528
+ graph.retain(runtime, { reason: `${name}.workQueue.runtime` });
529
+ const queue = {
530
+ commands,
531
+ records,
532
+ status,
533
+ issues,
534
+ submit(payload, submitOpts = {}) {
535
+ const command = opts.bus.publish(
536
+ opts.topic,
537
+ submitPayload(payload, {
538
+ ...submitOpts.workId === void 0 ? {} : { workId: submitOpts.workId },
539
+ ...submitOpts.priority === void 0 ? {} : { priority: submitOpts.priority },
540
+ ...submitOpts.tags === void 0 ? {} : { tags: submitOpts.tags },
541
+ ...submitOpts.requirements === void 0 ? {} : { requirements: submitOpts.requirements },
542
+ ...submitOpts.notBeforeMs === void 0 ? {} : { notBeforeMs: submitOpts.notBeforeMs },
543
+ ...submitOpts.deadlineMs === void 0 ? {} : { deadlineMs: submitOpts.deadlineMs }
544
+ }),
545
+ {
546
+ commandId: submitOpts.commandId ?? nextCommandId(opts.queueId, "submit"),
547
+ idempotencyKey: submitOpts.idempotencyKey
548
+ }
549
+ );
550
+ return command;
551
+ },
552
+ claim(claimOpts) {
553
+ return publishQueueCommand(commands, {
554
+ ...claimOpts,
555
+ kind: "claim",
556
+ commandId: claimOpts.commandId ?? nextCommandId(opts.queueId, "claim")
557
+ });
558
+ },
559
+ renewLease(renewOpts) {
560
+ return publishQueueCommand(commands, {
561
+ ...renewOpts,
562
+ kind: "renew-lease",
563
+ commandId: renewOpts.commandId ?? nextCommandId(opts.queueId, "renew")
564
+ });
565
+ },
566
+ release(releaseOpts) {
567
+ return publishQueueCommand(commands, {
568
+ ...releaseOpts,
569
+ kind: "release",
570
+ commandId: releaseOpts.commandId ?? nextCommandId(opts.queueId, "release")
571
+ });
572
+ },
573
+ complete(completeOpts) {
574
+ return publishQueueCommand(commands, {
575
+ ...completeOpts,
576
+ kind: "complete",
577
+ commandId: completeOpts.commandId ?? nextCommandId(opts.queueId, "complete")
578
+ });
579
+ },
580
+ fail(failOpts) {
581
+ return publishQueueCommand(commands, {
582
+ ...failOpts,
583
+ kind: "fail",
584
+ commandId: failOpts.commandId ?? nextCommandId(opts.queueId, "fail")
585
+ });
586
+ },
587
+ cancel(cancelOpts) {
588
+ return publishQueueCommand(commands, {
589
+ ...cancelOpts,
590
+ kind: "cancel",
591
+ commandId: cancelOpts.commandId ?? nextCommandId(opts.queueId, "cancel")
592
+ });
593
+ },
594
+ schedule(scheduleOpts) {
595
+ return publishQueueCommand(commands, {
596
+ ...scheduleOpts,
597
+ kind: "schedule",
598
+ commandId: scheduleOpts.commandId ?? nextCommandId(opts.queueId, "schedule")
599
+ });
600
+ },
601
+ expireLeases(expireOpts = {}) {
602
+ return publishQueueCommand(commands, {
603
+ ...expireOpts,
604
+ kind: "expire-leases",
605
+ commandId: expireOpts.commandId ?? nextCommandId(opts.queueId, "expire")
606
+ });
607
+ },
608
+ available(projectionOpts = {}) {
609
+ const availablePullId = /* @__PURE__ */ Symbol(`${name}/available`);
610
+ const available = graph.node(
611
+ [records],
612
+ (ctx) => {
613
+ const params = pullParams(ctx.pull);
614
+ ctx.down([["DATA", availablePage(state, params)]]);
615
+ },
616
+ {
617
+ name: projectionOpts.name ?? `${name}/available`,
618
+ factory: "workQueueAvailable",
619
+ pullId: availablePullId,
620
+ partial: true,
621
+ completeWhenDepsComplete: false,
622
+ errorWhenDepsError: false
623
+ }
624
+ );
625
+ return { available, availablePullId, status, issues };
626
+ },
627
+ work(workId, projectionOpts = {}) {
628
+ const snapshotPullId = /* @__PURE__ */ Symbol(`${name}/${workId}/snapshot`);
629
+ const snapshot = graph.node(
630
+ [records],
631
+ (ctx) => {
632
+ ctx.down([["DATA", workSnapshot(state, workId)]]);
633
+ },
634
+ {
635
+ name: projectionOpts.name ?? `${name}/${workId}`,
636
+ factory: "workQueueWorkSnapshot",
637
+ pullId: snapshotPullId,
638
+ partial: true,
639
+ completeWhenDepsComplete: false,
640
+ errorWhenDepsError: false
641
+ }
642
+ );
643
+ return { snapshot, snapshotPullId, status, issues };
644
+ },
645
+ deadLetter(projectionOpts = {}) {
646
+ const snapshotPullId = /* @__PURE__ */ Symbol(`${name}/deadLetter`);
647
+ const snapshot = graph.node(
648
+ [records],
649
+ (ctx) => {
650
+ const params = pullParams(ctx.pull);
651
+ ctx.down([["DATA", deadLetterPage(state, params)]]);
652
+ },
653
+ {
654
+ name: projectionOpts.name ?? `${name}/deadLetter`,
655
+ factory: "workQueueDeadLetter",
656
+ pullId: snapshotPullId,
657
+ partial: true,
658
+ completeWhenDepsComplete: false,
659
+ errorWhenDepsError: false
660
+ }
661
+ );
662
+ return { snapshot, snapshotPullId, status, issues };
663
+ }
664
+ };
665
+ return queue;
666
+ }
667
+ function shouldPollAdmission(status, topic, subscriptionId) {
668
+ if (status.topic !== topic) return false;
669
+ if (status.kind === "message-published" || status.kind === "retention-trimmed") return true;
670
+ return status.subscriptionId === subscriptionId && (status.kind === "subscription-acked" || status.kind === "subscription-sought");
671
+ }
672
+ function admissionAckCommand(record) {
673
+ const messageBus = admissionMessageBus(record);
674
+ if (messageBus === void 0) return void 0;
675
+ return {
676
+ kind: "ack",
677
+ topic: messageBus.topic,
678
+ subscriptionId: messageBus.subscriptionId,
679
+ seq: messageBus.seq,
680
+ commandId: `${record.queueId}:admission-ack:${messageBus.topic}:${messageBus.subscriptionId}:${messageBus.seq}`
681
+ };
682
+ }
683
+ function admissionMessageBus(record) {
684
+ return "messageBus" in record ? record.messageBus : void 0;
685
+ }
686
+ function admitMessage(opts, state, message, nowMs) {
687
+ const source = `${message.topic}:${message.seq}`;
688
+ if (state.sourceSeqs.has(source)) return [];
689
+ state.sourceSeqs.add(source);
690
+ const submitted = decodeSubmittedPayload(message.payload);
691
+ const payload = submitted.payload;
692
+ const payloadRecord = payloadAsRecord(submitted.meta);
693
+ const workId = typeof payloadRecord.workId === "string" ? payloadRecord.workId : `${opts.queueId}:${message.topic}:${message.seq}`;
694
+ if (state.works.has(workId)) {
695
+ const record2 = appendRecord(state, opts.queueId, {
696
+ kind: "admission-deduped",
697
+ workId,
698
+ messageBus: { topic: message.topic, seq: message.seq, subscriptionId: opts.subscriptionId },
699
+ reason: "duplicate-work",
700
+ existingWorkId: workId,
701
+ recordedAtMs: nowMs
702
+ });
703
+ return [
704
+ recordEvent(record2),
705
+ statusEvent(opts.queueId, "admission-rejected", nowMs, {
706
+ workId,
707
+ recordSeq: record2.recordSeq,
708
+ issueCode: "duplicate-work"
709
+ })
710
+ ];
711
+ }
712
+ const work = {
713
+ workId,
714
+ payload,
715
+ state: typeof payloadRecord.notBeforeMs === "number" && payloadRecord.notBeforeMs > nowMs ? "scheduled" : "ready",
716
+ admissionSeq: message.seq,
717
+ priority: numberOrUndefined(payloadRecord.priority),
718
+ tags: stringArrayOrUndefined(payloadRecord.tags),
719
+ requirements: stringArrayOrUndefined(payloadRecord.requirements),
720
+ notBeforeMs: numberOrUndefined(payloadRecord.notBeforeMs),
721
+ deadlineMs: numberOrUndefined(payloadRecord.deadlineMs),
722
+ attempt: 0
723
+ };
724
+ state.works.set(workId, work);
725
+ const record = appendRecord(state, opts.queueId, {
726
+ kind: "work-admitted",
727
+ workId,
728
+ payload,
729
+ messageBus: { topic: message.topic, seq: message.seq, subscriptionId: opts.subscriptionId },
730
+ priority: work.priority,
731
+ tags: work.tags,
732
+ requirements: work.requirements,
733
+ notBeforeMs: work.notBeforeMs,
734
+ deadlineMs: work.deadlineMs,
735
+ recordedAtMs: nowMs
736
+ });
737
+ return [
738
+ recordEvent(record),
739
+ statusEvent(opts.queueId, "admission-accepted", nowMs, { workId, recordSeq: record.recordSeq })
740
+ ];
741
+ }
742
+ function reduceQueueCommand(opts, state, command, nowMs, leaseDurationMs, retry) {
743
+ const invalid = validateQueueCommand(opts.queueId, command);
744
+ if (invalid !== void 0)
745
+ return rejectQueueCommand(opts.queueId, command, invalid.code, invalid.message, nowMs);
746
+ if (state.commandIds.has(command.commandId)) {
747
+ return rejectQueueCommand(
748
+ opts.queueId,
749
+ command,
750
+ "duplicate-command",
751
+ "duplicate commandId",
752
+ nowMs
753
+ );
754
+ }
755
+ if (command.idempotencyKey !== void 0 && state.idempotencyKeys.has(command.idempotencyKey)) {
756
+ return rejectQueueCommand(
757
+ opts.queueId,
758
+ command,
759
+ "duplicate-command",
760
+ "duplicate idempotencyKey",
761
+ nowMs
762
+ );
763
+ }
764
+ state.commandIds.add(command.commandId);
765
+ if (command.idempotencyKey !== void 0) state.idempotencyKeys.add(command.idempotencyKey);
766
+ switch (command.kind) {
767
+ case "claim":
768
+ return claimWork(opts.queueId, state, command, nowMs, leaseDurationMs);
769
+ case "renew-lease":
770
+ return renewLease(opts.queueId, state, command, nowMs, leaseDurationMs);
771
+ case "release":
772
+ return releaseWork(opts.queueId, state, command, nowMs);
773
+ case "complete":
774
+ return completeWork(opts.queueId, state, command, nowMs);
775
+ case "fail":
776
+ return failWork(opts.queueId, state, command, nowMs, retry);
777
+ case "cancel":
778
+ return cancelWork(opts.queueId, state, command, nowMs);
779
+ case "schedule":
780
+ return scheduleWork(opts.queueId, state, command, nowMs);
781
+ case "expire-leases":
782
+ return expireLeases(opts.queueId, state, command, nowMs);
783
+ case "submit":
784
+ return [
785
+ statusEvent(opts.queueId, "command-accepted", nowMs, {
786
+ commandId: command.commandId,
787
+ details: { submitUsesMessageBus: true }
788
+ })
789
+ ];
790
+ }
791
+ }
792
+ function claimWork(queueId, state, command, nowMs, defaultLeaseDurationMs) {
793
+ const limit = positiveLimit(command.limit ?? command.requestedWorkIds?.length ?? 1);
794
+ const requested = new Set(command.requestedWorkIds ?? []);
795
+ const events = [];
796
+ for (const work of [...state.works.values()].filter((entry) => requested.size === 0 ? true : requested.has(entry.workId)).filter((entry) => isExpiredLease(entry, nowMs))) {
797
+ events.push(...materializeLeaseExpired(queueId, state, work, command.commandId, nowMs));
798
+ }
799
+ const candidates = [...state.works.values()].filter((work) => requested.size === 0 ? true : requested.has(work.workId)).filter((work) => isReady(work, nowMs)).sort((a, b) => a.admissionSeq - b.admissionSeq).slice(0, limit);
800
+ if (candidates.length === 0)
801
+ return [
802
+ ...events,
803
+ ...requested.size === 0 ? rejectQueueCommand(queueId, command, "not-ready", "no ready work", nowMs) : claimMissEvents(queueId, state, command, requested, /* @__PURE__ */ new Set(), nowMs)
804
+ ];
805
+ const claimed = /* @__PURE__ */ new Set();
806
+ for (const work of candidates) {
807
+ claimed.add(work.workId);
808
+ work.state = "leased";
809
+ work.attempt += 1;
810
+ work.leaseId = `${work.workId}:lease:${++state.leaseSeq}`;
811
+ work.workerId = command.workerId;
812
+ work.leaseExpiresAtMs = nowMs + (command.leaseDurationMs ?? defaultLeaseDurationMs);
813
+ const record = appendRecord(state, queueId, {
814
+ kind: "work-claimed",
815
+ workId: work.workId,
816
+ commandId: command.commandId,
817
+ leaseId: work.leaseId,
818
+ attempt: work.attempt,
819
+ workerId: command.workerId,
820
+ claimedAtMs: nowMs,
821
+ leaseExpiresAtMs: work.leaseExpiresAtMs,
822
+ recordedAtMs: nowMs
823
+ });
824
+ events.push(
825
+ recordEvent(record),
826
+ statusEvent(queueId, "command-accepted", nowMs, {
827
+ workId: work.workId,
828
+ commandId: command.commandId,
829
+ recordSeq: record.recordSeq
830
+ })
831
+ );
832
+ }
833
+ if (requested.size > 0) {
834
+ events.push(...claimMissEvents(queueId, state, command, requested, claimed, nowMs));
835
+ }
836
+ return events;
837
+ }
838
+ function claimMissEvents(queueId, state, command, requested, claimed, nowMs) {
839
+ const events = [];
840
+ for (const workId of requested) {
841
+ if (claimed.has(workId)) continue;
842
+ const work = state.works.get(workId);
843
+ if (work === void 0) {
844
+ events.push(
845
+ ...rejectQueueCommand(
846
+ queueId,
847
+ command,
848
+ "unknown-work",
849
+ `unknown work '${workId}'`,
850
+ nowMs
851
+ )
852
+ );
853
+ continue;
854
+ }
855
+ if (isReady(work, nowMs)) continue;
856
+ const code = isTerminal(work.state) ? "terminal-work" : work.state === "leased" ? "already-leased" : "not-ready";
857
+ events.push(
858
+ ...rejectQueueCommand(
859
+ queueId,
860
+ command,
861
+ code,
862
+ `requested work '${workId}' is not claimable`,
863
+ nowMs
864
+ )
865
+ );
866
+ }
867
+ return events;
868
+ }
869
+ function renewLease(queueId, state, command, nowMs, defaultLeaseDurationMs) {
870
+ const checked = currentLease(queueId, state, command, nowMs);
871
+ if ("issue" in checked) return [checked.issue];
872
+ if ("events" in checked) return checked.events;
873
+ const work = checked.work;
874
+ const previous = work.leaseExpiresAtMs;
875
+ work.leaseExpiresAtMs = command.leaseExpiresAtMs ?? nowMs + (command.leaseDurationMs ?? defaultLeaseDurationMs);
876
+ const record = appendRecord(state, queueId, {
877
+ kind: "lease-renewed",
878
+ workId: work.workId,
879
+ commandId: command.commandId,
880
+ leaseId: command.leaseId,
881
+ attempt: command.attempt,
882
+ workerId: command.workerId,
883
+ previousLeaseExpiresAtMs: previous,
884
+ leaseExpiresAtMs: work.leaseExpiresAtMs,
885
+ renewedAtMs: nowMs,
886
+ recordedAtMs: nowMs
887
+ });
888
+ return [
889
+ recordEvent(record),
890
+ statusEvent(queueId, "command-accepted", nowMs, {
891
+ workId: work.workId,
892
+ commandId: command.commandId,
893
+ recordSeq: record.recordSeq
894
+ })
895
+ ];
896
+ }
897
+ function releaseWork(queueId, state, command, nowMs) {
898
+ const checked = currentLease(queueId, state, command, nowMs);
899
+ if ("issue" in checked) return [checked.issue];
900
+ if ("events" in checked) return checked.events;
901
+ const work = checked.work;
902
+ work.state = "ready";
903
+ work.leaseId = void 0;
904
+ work.workerId = void 0;
905
+ work.leaseExpiresAtMs = void 0;
906
+ const record = appendRecord(state, queueId, {
907
+ kind: "work-released",
908
+ workId: work.workId,
909
+ commandId: command.commandId,
910
+ leaseId: command.leaseId,
911
+ attempt: command.attempt,
912
+ workerId: command.workerId,
913
+ releasedAtMs: nowMs,
914
+ reason: command.reason,
915
+ recordedAtMs: nowMs
916
+ });
917
+ return [
918
+ recordEvent(record),
919
+ statusEvent(queueId, "command-accepted", nowMs, {
920
+ workId: work.workId,
921
+ commandId: command.commandId,
922
+ recordSeq: record.recordSeq
923
+ })
924
+ ];
925
+ }
926
+ function completeWork(queueId, state, command, nowMs) {
927
+ const checked = currentLease(queueId, state, command, nowMs);
928
+ if ("issue" in checked) return [checked.issue];
929
+ if ("events" in checked) return checked.events;
930
+ const work = checked.work;
931
+ work.state = "completed";
932
+ clearLease(work);
933
+ work.terminalRecordSeq = state.recordSeq + 2;
934
+ const attempt = appendRecord(state, queueId, {
935
+ kind: "attempt-completed",
936
+ workId: work.workId,
937
+ commandId: command.commandId,
938
+ leaseId: command.leaseId,
939
+ attempt: command.attempt,
940
+ workerId: command.workerId,
941
+ result: command.result,
942
+ recordedAtMs: nowMs
943
+ });
944
+ const done = appendRecord(state, queueId, {
945
+ kind: "work-completed",
946
+ workId: work.workId,
947
+ commandId: command.commandId,
948
+ leaseId: command.leaseId,
949
+ attempt: command.attempt,
950
+ workerId: command.workerId,
951
+ result: command.result,
952
+ recordedAtMs: nowMs
953
+ });
954
+ return [
955
+ recordEvent(attempt),
956
+ recordEvent(done),
957
+ statusEvent(queueId, "command-accepted", nowMs, {
958
+ workId: work.workId,
959
+ commandId: command.commandId,
960
+ recordSeq: done.recordSeq
961
+ })
962
+ ];
963
+ }
964
+ function failWork(queueId, state, command, nowMs, retry) {
965
+ const checked = currentLease(queueId, state, command, nowMs);
966
+ if ("issue" in checked) return [checked.issue];
967
+ if ("events" in checked) return checked.events;
968
+ const work = checked.work;
969
+ const failed = appendRecord(state, queueId, {
970
+ kind: "attempt-failed",
971
+ workId: work.workId,
972
+ commandId: command.commandId,
973
+ leaseId: command.leaseId,
974
+ attempt: command.attempt,
975
+ workerId: command.workerId,
976
+ error: command.error,
977
+ retryable: command.retryable,
978
+ recordedAtMs: nowMs
979
+ });
980
+ const maxAttempts = retry.maxAttempts ?? 3;
981
+ if (command.retryable === false || work.attempt >= maxAttempts) {
982
+ work.state = "dead-lettered";
983
+ clearLease(work);
984
+ work.retryAtMs = void 0;
985
+ const dead = appendRecord(state, queueId, {
986
+ kind: "work-dead-lettered",
987
+ workId: work.workId,
988
+ commandId: command.commandId,
989
+ reason: command.retryable === false ? "non-retryable" : "attempts-exhausted",
990
+ exhaustedAttempts: work.attempt,
991
+ recordedAtMs: nowMs
992
+ });
993
+ state.deadLetters.push(dead);
994
+ return [
995
+ recordEvent(failed),
996
+ recordEvent(dead),
997
+ statusEvent(queueId, "command-accepted", nowMs, {
998
+ workId: work.workId,
999
+ commandId: command.commandId,
1000
+ recordSeq: dead.recordSeq
1001
+ })
1002
+ ];
1003
+ }
1004
+ const delayMs = retry.delayMs ?? 0;
1005
+ work.state = delayMs > 0 ? "retry-wait" : "ready";
1006
+ work.retryAtMs = nowMs + delayMs;
1007
+ clearLease(work);
1008
+ const retryRecord = appendRecord(state, queueId, {
1009
+ kind: "retry-scheduled",
1010
+ workId: work.workId,
1011
+ commandId: command.commandId,
1012
+ retryAtMs: work.retryAtMs,
1013
+ delayMs,
1014
+ reason: "retry-policy",
1015
+ recordedAtMs: nowMs
1016
+ });
1017
+ return [
1018
+ recordEvent(failed),
1019
+ recordEvent(retryRecord),
1020
+ statusEvent(queueId, "command-accepted", nowMs, {
1021
+ workId: work.workId,
1022
+ commandId: command.commandId,
1023
+ recordSeq: retryRecord.recordSeq
1024
+ })
1025
+ ];
1026
+ }
1027
+ function cancelWork(queueId, state, command, nowMs) {
1028
+ const work = state.works.get(command.workId);
1029
+ if (work === void 0)
1030
+ return [issueEvent(queueId, "unknown-work", "unknown work", nowMs, command)];
1031
+ if (isTerminal(work.state))
1032
+ return [issueEvent(queueId, "terminal-work", "work is terminal", nowMs, command)];
1033
+ work.state = "canceled";
1034
+ const canceledLeaseId = work.leaseId;
1035
+ const attempt = work.attempt || void 0;
1036
+ const record = appendRecord(state, queueId, {
1037
+ kind: "work-canceled",
1038
+ workId: work.workId,
1039
+ commandId: command.commandId,
1040
+ reason: command.reason,
1041
+ canceledAtMs: nowMs,
1042
+ canceledLeaseId,
1043
+ attempt,
1044
+ recordedAtMs: nowMs
1045
+ });
1046
+ clearLease(work);
1047
+ return [
1048
+ recordEvent(record),
1049
+ statusEvent(queueId, "command-accepted", nowMs, {
1050
+ workId: work.workId,
1051
+ commandId: command.commandId,
1052
+ recordSeq: record.recordSeq
1053
+ })
1054
+ ];
1055
+ }
1056
+ function scheduleWork(queueId, state, command, nowMs) {
1057
+ const work = state.works.get(command.workId);
1058
+ if (work === void 0)
1059
+ return [issueEvent(queueId, "unknown-work", "unknown work", nowMs, command)];
1060
+ if (isTerminal(work.state))
1061
+ return [issueEvent(queueId, "terminal-work", "work is terminal", nowMs, command)];
1062
+ work.state = "scheduled";
1063
+ work.notBeforeMs = command.notBeforeMs;
1064
+ work.deadlineMs = command.deadlineMs;
1065
+ const record = appendRecord(state, queueId, {
1066
+ kind: "work-scheduled",
1067
+ workId: work.workId,
1068
+ commandId: command.commandId,
1069
+ scheduleId: command.scheduleId,
1070
+ scheduleAtMs: command.scheduleAtMs,
1071
+ runAtMs: command.runAtMs,
1072
+ notBeforeMs: command.notBeforeMs,
1073
+ deadlineMs: command.deadlineMs,
1074
+ reason: command.reason,
1075
+ recordedAtMs: nowMs
1076
+ });
1077
+ return [
1078
+ recordEvent(record),
1079
+ statusEvent(queueId, "command-accepted", nowMs, {
1080
+ workId: work.workId,
1081
+ commandId: command.commandId,
1082
+ recordSeq: record.recordSeq
1083
+ })
1084
+ ];
1085
+ }
1086
+ function expireLeases(queueId, state, command, nowMs) {
1087
+ const workIds = new Set(command.workIds ?? []);
1088
+ const limit = positiveLimit(command.limit ?? Number.MAX_SAFE_INTEGER);
1089
+ const expired = [...state.works.values()].filter(
1090
+ (work) => work.state === "leased" && work.leaseExpiresAtMs !== void 0 && work.leaseExpiresAtMs <= nowMs
1091
+ ).filter((work) => workIds.size === 0 || workIds.has(work.workId)).slice(0, limit);
1092
+ if (expired.length === 0)
1093
+ return [statusEvent(queueId, "maintenance-noop", nowMs, { commandId: command.commandId })];
1094
+ const events = [];
1095
+ for (const work of expired) {
1096
+ events.push(...materializeLeaseExpired(queueId, state, work, command.commandId, nowMs));
1097
+ }
1098
+ events.push(
1099
+ statusEvent(queueId, "maintenance-applied", nowMs, {
1100
+ commandId: command.commandId,
1101
+ details: { expired: expired.length }
1102
+ })
1103
+ );
1104
+ return events;
1105
+ }
1106
+ function currentLease(queueId, state, command, nowMs) {
1107
+ const work = state.works.get(command.workId);
1108
+ if (work === void 0)
1109
+ return { issue: issueEvent(queueId, "unknown-work", "unknown work", nowMs, command) };
1110
+ if (isTerminal(work.state))
1111
+ return { issue: issueEvent(queueId, "terminal-work", "work is terminal", nowMs, command) };
1112
+ if (work.state !== "leased")
1113
+ return {
1114
+ issue: issueEvent(queueId, "lease-not-current", "work is not leased", nowMs, command)
1115
+ };
1116
+ if (work.leaseId !== command.leaseId)
1117
+ return { issue: issueEvent(queueId, "stale-lease", "lease is not current", nowMs, command) };
1118
+ if (work.attempt !== command.attempt)
1119
+ return { issue: issueEvent(queueId, "attempt-mismatch", "attempt mismatch", nowMs, command) };
1120
+ if (work.workerId !== command.workerId)
1121
+ return { issue: issueEvent(queueId, "worker-mismatch", "worker mismatch", nowMs, command) };
1122
+ if (isExpiredLease(work, nowMs))
1123
+ return {
1124
+ events: materializeLeaseExpired(queueId, state, work, command.commandId, nowMs, {
1125
+ command,
1126
+ code: "lease-expired",
1127
+ message: "lease expired"
1128
+ })
1129
+ };
1130
+ return { work };
1131
+ }
1132
+ // Annotate the CommonJS export names for ESM import in node:
1133
+ 0 && (module.exports = {
1134
+ workQueue
1135
+ });
1136
+ //# sourceMappingURL=index.cjs.map