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