bunqueue-client 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (580) hide show
  1. package/CHANGELOG.md +162 -0
  2. package/LEGACY.md +460 -0
  3. package/README.md +204 -349
  4. package/dist/ack-batcher.js +7 -67
  5. package/dist/canonical-manifest.json +930 -0
  6. package/dist/chunk-b967v3w3.js +79 -0
  7. package/dist/chunk-fekm0ma6.js +110 -0
  8. package/dist/chunk-jxkszwqp.js +573 -0
  9. package/dist/embedded.js +16418 -0
  10. package/dist/frame.js +14 -57
  11. package/dist/index.d.ts +1 -27
  12. package/dist/index.js +10905 -16
  13. package/dist/legacy.d.ts +1 -0
  14. package/dist/legacy.js +2081 -0
  15. package/dist/{ack-batcher.d.ts → types/sdk/typescript/src/ack-batcher.d.ts} +3 -3
  16. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/aging.d.ts +2 -2
  17. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/batch.d.ts +2 -2
  18. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/bunqueue-api.d.ts +5 -5
  19. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/bunqueue.d.ts +13 -13
  20. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/circuit-breaker.d.ts +2 -2
  21. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/dedup-debounce.d.ts +2 -2
  22. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/dlq-rate-limit.d.ts +2 -2
  23. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/rate-gate.d.ts +1 -1
  24. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/retry.d.ts +1 -1
  25. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/triggers.d.ts +3 -3
  26. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/ttl.d.ts +1 -1
  27. package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/types.d.ts +4 -4
  28. package/dist/types/sdk/typescript/src/canonical-transport/bun-sqlite-types.d.ts +21 -0
  29. package/dist/{connection-pool.d.ts → types/sdk/typescript/src/connection-pool.d.ts} +1 -1
  30. package/dist/{connection-types.d.ts → types/sdk/typescript/src/connection-types.d.ts} +1 -1
  31. package/dist/{connection.d.ts → types/sdk/typescript/src/connection.d.ts} +6 -19
  32. package/dist/{errors.d.ts → types/sdk/typescript/src/errors.d.ts} +3 -0
  33. package/dist/types/sdk/typescript/src/flow-commit.d.ts +5 -0
  34. package/dist/types/sdk/typescript/src/flow-plan-legacy.d.ts +13 -0
  35. package/dist/types/sdk/typescript/src/flow-plan.d.ts +29 -0
  36. package/dist/{flow-types.d.ts → types/sdk/typescript/src/flow-types.d.ts} +7 -4
  37. package/dist/{flow.d.ts → types/sdk/typescript/src/flow.d.ts} +6 -10
  38. package/dist/{frame.d.ts → types/sdk/typescript/src/frame.d.ts} +1 -1
  39. package/dist/types/sdk/typescript/src/index.d.ts +10 -0
  40. package/dist/{job.d.ts → types/sdk/typescript/src/job.d.ts} +4 -3
  41. package/dist/types/sdk/typescript/src/legacy.d.ts +27 -0
  42. package/dist/{observability.d.ts → types/sdk/typescript/src/observability.d.ts} +14 -0
  43. package/dist/{queue-admin.d.ts → types/sdk/typescript/src/queue-admin.d.ts} +3 -4
  44. package/dist/{queue-control.d.ts → types/sdk/typescript/src/queue-control.d.ts} +7 -6
  45. package/dist/{queue-query.d.ts → types/sdk/typescript/src/queue-query.d.ts} +3 -3
  46. package/dist/{queue.d.ts → types/sdk/typescript/src/queue.d.ts} +8 -8
  47. package/dist/{responses.d.ts → types/sdk/typescript/src/responses.d.ts} +2 -2
  48. package/dist/types/sdk/typescript/src/serialization.d.ts +10 -0
  49. package/dist/{socket-factory.d.ts → types/sdk/typescript/src/socket-factory.d.ts} +1 -1
  50. package/dist/types/sdk/typescript/src/terminal-outcome.d.ts +8 -0
  51. package/dist/{types.d.ts → types/sdk/typescript/src/types.d.ts} +5 -2
  52. package/dist/{worker-base.d.ts → types/sdk/typescript/src/worker-base.d.ts} +6 -6
  53. package/dist/types/sdk/typescript/src/worker-slot-signal.d.ts +6 -0
  54. package/dist/{worker-types.d.ts → types/sdk/typescript/src/worker-types.d.ts} +3 -3
  55. package/dist/{worker.d.ts → types/sdk/typescript/src/worker.d.ts} +3 -2
  56. package/dist/types/src/application/background/dlq.d.ts +2 -0
  57. package/dist/types/src/application/background/lifecycle.d.ts +4 -0
  58. package/dist/types/src/application/background/recovery/active.d.ts +5 -0
  59. package/dist/types/src/application/background/recovery/index.d.ts +2 -0
  60. package/dist/types/src/application/background/recovery/pending.d.ts +3 -0
  61. package/dist/types/src/application/background/recovery/restore.d.ts +5 -0
  62. package/dist/types/src/application/background/recovery/shared.d.ts +6 -0
  63. package/dist/types/src/application/background/timeouts.d.ts +25 -0
  64. package/dist/types/src/application/backgroundTasks.d.ts +7 -0
  65. package/dist/types/src/application/cleanupTasks.d.ts +10 -0
  66. package/dist/types/src/application/clientTracking.d.ts +44 -0
  67. package/dist/types/src/application/completedCleanup.d.ts +34 -0
  68. package/dist/types/src/application/completedRetry.d.ts +21 -0
  69. package/dist/types/src/application/contextFactory.d.ts +49 -0
  70. package/dist/types/src/application/dependencyCompletions.d.ts +63 -0
  71. package/dist/types/src/application/dependencyProcessor.d.ts +15 -0
  72. package/dist/types/src/application/dependencyResultTracker.d.ts +18 -0
  73. package/dist/types/src/application/dlqManager.d.ts +49 -0
  74. package/dist/types/src/application/dlqRetry.d.ts +12 -0
  75. package/dist/types/src/application/emptyQueueCleanup.d.ts +3 -0
  76. package/dist/types/src/application/eventsManager.d.ts +50 -0
  77. package/dist/types/src/application/flowFailureRecovery.d.ts +20 -0
  78. package/dist/types/src/application/flowParentBackpatch.d.ts +27 -0
  79. package/dist/types/src/application/jobLogsManager.d.ts +21 -0
  80. package/dist/types/src/application/latencyTracker.d.ts +39 -0
  81. package/dist/types/src/application/lockManager.d.ts +15 -0
  82. package/dist/types/src/application/lockOperations.d.ts +38 -0
  83. package/dist/types/src/application/metricsExporter.d.ts +27 -0
  84. package/dist/types/src/application/monitoringChecks.d.ts +36 -0
  85. package/dist/types/src/application/operations/ack/batch.d.ts +8 -0
  86. package/dist/types/src/application/operations/ack/completion.d.ts +3 -0
  87. package/dist/types/src/application/operations/ack/failure.d.ts +3 -0
  88. package/dist/types/src/application/operations/ack.d.ts +5 -0
  89. package/dist/types/src/application/operations/ackHelpers.d.ts +36 -0
  90. package/dist/types/src/application/operations/customId.d.ts +51 -0
  91. package/dist/types/src/application/operations/flowPush.d.ts +9 -0
  92. package/dist/types/src/application/operations/flowTopologyValidation.d.ts +3 -0
  93. package/dist/types/src/application/operations/flowValidation.d.ts +3 -0
  94. package/dist/types/src/application/operations/jobClaim.d.ts +17 -0
  95. package/dist/types/src/application/operations/jobManagement.d.ts +43 -0
  96. package/dist/types/src/application/operations/jobMoveOperations.d.ts +9 -0
  97. package/dist/types/src/application/operations/jobPromotion.d.ts +7 -0
  98. package/dist/types/src/application/operations/jobStateTransitions.d.ts +15 -0
  99. package/dist/types/src/application/operations/parentLink.d.ts +36 -0
  100. package/dist/types/src/application/operations/parentLinkInput.d.ts +8 -0
  101. package/dist/types/src/application/operations/pull.d.ts +20 -0
  102. package/dist/types/src/application/operations/pullFinalization.d.ts +6 -0
  103. package/dist/types/src/application/operations/pullStateTransition.d.ts +51 -0
  104. package/dist/types/src/application/operations/push.d.ts +13 -0
  105. package/dist/types/src/application/operations/pushAdmission.d.ts +36 -0
  106. package/dist/types/src/application/operations/pushBatch.d.ts +4 -0
  107. package/dist/types/src/application/operations/pushContext.d.ts +48 -0
  108. package/dist/types/src/application/operations/pushDeduplication.d.ts +42 -0
  109. package/dist/types/src/application/operations/pushInsert.d.ts +39 -0
  110. package/dist/types/src/application/operations/pushLocks.d.ts +15 -0
  111. package/dist/types/src/application/operations/query/collect.d.ts +12 -0
  112. package/dist/types/src/application/operations/query/jobLookup.d.ts +9 -0
  113. package/dist/types/src/application/operations/query/pagination.d.ts +8 -0
  114. package/dist/types/src/application/operations/query/state.d.ts +4 -0
  115. package/dist/types/src/application/operations/queryOperations.d.ts +5 -0
  116. package/dist/types/src/application/operations/queueControl.d.ts +50 -0
  117. package/dist/types/src/application/prometheusOperationalMetrics.d.ts +31 -0
  118. package/dist/types/src/application/queue-manager/ack.d.ts +23 -0
  119. package/dist/types/src/application/queue-manager/configuration.d.ts +27 -0
  120. package/dist/types/src/application/queue-manager/context.d.ts +5 -0
  121. package/dist/types/src/application/queue-manager/control.d.ts +20 -0
  122. package/dist/types/src/application/queue-manager/delivery.d.ts +33 -0
  123. package/dist/types/src/application/queue-manager/dependencies.d.ts +8 -0
  124. package/dist/types/src/application/queue-manager/dependency-runtime.d.ts +8 -0
  125. package/dist/types/src/application/queue-manager/flow-failures.d.ts +18 -0
  126. package/dist/types/src/application/queue-manager/flow-options.d.ts +8 -0
  127. package/dist/types/src/application/queue-manager/job-management.d.ts +17 -0
  128. package/dist/types/src/application/queue-manager/lifecycle.d.ts +4 -0
  129. package/dist/types/src/application/queue-manager/limits.d.ts +58 -0
  130. package/dist/types/src/application/queue-manager/locks.d.ts +21 -0
  131. package/dist/types/src/application/queue-manager/observability.d.ts +16 -0
  132. package/dist/types/src/application/queue-manager/queries.d.ts +24 -0
  133. package/dist/types/src/application/queue-manager/repeat.d.ts +4 -0
  134. package/dist/types/src/application/queue-manager/services.d.ts +19 -0
  135. package/dist/types/src/application/queue-manager/state.d.ts +96 -0
  136. package/dist/types/src/application/queue-manager/stats.d.ts +28 -0
  137. package/dist/types/src/application/queueManager.d.ts +5 -0
  138. package/dist/types/src/application/queueStatsAggregator.d.ts +23 -0
  139. package/dist/types/src/application/queueTelemetryJournal.d.ts +24 -0
  140. package/dist/types/src/application/repeatJobs.d.ts +7 -0
  141. package/dist/types/src/application/stallDetection.d.ts +10 -0
  142. package/dist/types/src/application/statsManager.d.ts +59 -0
  143. package/dist/types/src/application/taskErrorTracking.d.ts +22 -0
  144. package/dist/types/src/application/throughputTracker.d.ts +34 -0
  145. package/dist/types/src/application/types/ack.d.ts +136 -0
  146. package/dist/types/src/application/types/background.d.ts +18 -0
  147. package/dist/types/src/application/types/config.d.ts +41 -0
  148. package/dist/types/src/application/types/contextFactory.d.ts +87 -0
  149. package/dist/types/src/application/types/contexts.d.ts +114 -0
  150. package/dist/types/src/application/types/index.d.ts +7 -0
  151. package/dist/types/src/application/types/query.d.ts +23 -0
  152. package/dist/types/src/application/types/queueManager.d.ts +98 -0
  153. package/dist/types/src/application/webhookManager.d.ts +47 -0
  154. package/dist/types/src/application/workerManager.d.ts +61 -0
  155. package/dist/types/src/client/bunqueue/aging.d.ts +16 -0
  156. package/dist/types/src/client/bunqueue/batch.d.ts +16 -0
  157. package/dist/types/src/client/bunqueue/cancellation.d.ts +21 -0
  158. package/dist/types/src/client/bunqueue/circuitBreaker.d.ts +21 -0
  159. package/dist/types/src/client/bunqueue/dedupDebounce.d.ts +12 -0
  160. package/dist/types/src/client/bunqueue/dlqRateLimit.d.ts +26 -0
  161. package/dist/types/src/client/bunqueue/retry.d.ts +8 -0
  162. package/dist/types/src/client/bunqueue/runtime.d.ts +35 -0
  163. package/dist/types/src/client/bunqueue/triggers.d.ts +17 -0
  164. package/dist/types/src/client/bunqueue/ttl.d.ts +17 -0
  165. package/dist/types/src/client/bunqueue/types.d.ts +147 -0
  166. package/dist/types/src/client/bunqueue.d.ts +73 -0
  167. package/dist/types/src/client/dlqConversion.d.ts +5 -0
  168. package/dist/types/src/client/errors.d.ts +24 -0
  169. package/dist/types/src/client/events.d.ts +85 -0
  170. package/dist/types/src/client/flow.d.ts +70 -0
  171. package/dist/types/src/client/flowAtomic.d.ts +9 -0
  172. package/dist/types/src/client/flowJobCoreMethods.d.ts +28 -0
  173. package/dist/types/src/client/flowJobDependencies.d.ts +7 -0
  174. package/dist/types/src/client/flowJobFactory.d.ts +24 -0
  175. package/dist/types/src/client/flowJobMoveMethods.d.ts +16 -0
  176. package/dist/types/src/client/flowJobTypes.d.ts +29 -0
  177. package/dist/types/src/client/flowLegacyPlan.d.ts +16 -0
  178. package/dist/types/src/client/flowOptions.d.ts +10 -0
  179. package/dist/types/src/client/flowPlan.d.ts +16 -0
  180. package/dist/types/src/client/flowPush.d.ts +27 -0
  181. package/dist/types/src/client/flowReader.d.ts +10 -0
  182. package/dist/types/src/client/flowResults.d.ts +11 -0
  183. package/dist/types/src/client/flowTypes.d.ts +77 -0
  184. package/dist/types/src/client/forwarder.d.ts +74 -0
  185. package/dist/types/src/client/groupId.d.ts +1 -0
  186. package/dist/types/src/client/index.d.ts +46 -0
  187. package/dist/types/src/client/jobConversion.d.ts +10 -0
  188. package/dist/types/src/client/jobConversionHelpers.d.ts +28 -0
  189. package/dist/types/src/client/jobConversionTypes.d.ts +88 -0
  190. package/dist/types/src/client/jobDeduplication.d.ts +6 -0
  191. package/dist/types/src/client/jobHelpers.d.ts +31 -0
  192. package/dist/types/src/client/legacyConnectionOptions.d.ts +8 -0
  193. package/dist/types/src/client/manager.d.ts +15 -0
  194. package/dist/types/src/client/pro.d.ts +9 -0
  195. package/dist/types/src/client/queue/addBatcher.d.ts +59 -0
  196. package/dist/types/src/client/queue/bullmqCompat.d.ts +57 -0
  197. package/dist/types/src/client/queue/deduplication.d.ts +14 -0
  198. package/dist/types/src/client/queue/dlq.d.ts +61 -0
  199. package/dist/types/src/client/queue/dlqJobMethods.d.ts +9 -0
  200. package/dist/types/src/client/queue/dlqOps.d.ts +26 -0
  201. package/dist/types/src/client/queue/dlqStats.d.ts +3 -0
  202. package/dist/types/src/client/queue/failWire.d.ts +17 -0
  203. package/dist/types/src/client/queue/helpers.d.ts +19 -0
  204. package/dist/types/src/client/queue/job-proxy/dependencies.d.ts +9 -0
  205. package/dist/types/src/client/queue/job-proxy/reflection.d.ts +2 -0
  206. package/dist/types/src/client/queue/job-proxy/simple.d.ts +3 -0
  207. package/dist/types/src/client/queue/job-proxy/tcp.d.ts +4 -0
  208. package/dist/types/src/client/queue/jobMetadata.d.ts +10 -0
  209. package/dist/types/src/client/queue/jobMove.d.ts +32 -0
  210. package/dist/types/src/client/queue/jobProxy.d.ts +4 -0
  211. package/dist/types/src/client/queue/operations/add/bulk.d.ts +7 -0
  212. package/dist/types/src/client/queue/operations/add/payload.d.ts +25 -0
  213. package/dist/types/src/client/queue/operations/add/single.d.ts +3 -0
  214. package/dist/types/src/client/queue/operations/add.d.ts +2 -0
  215. package/dist/types/src/client/queue/operations/control.d.ts +42 -0
  216. package/dist/types/src/client/queue/operations/counts.d.ts +48 -0
  217. package/dist/types/src/client/queue/operations/groups.d.ts +24 -0
  218. package/dist/types/src/client/queue/operations/management.d.ts +51 -0
  219. package/dist/types/src/client/queue/operations/query.d.ts +50 -0
  220. package/dist/types/src/client/queue/operations/queryStates.d.ts +13 -0
  221. package/dist/types/src/client/queue/operations/queryTcpPages.d.ts +14 -0
  222. package/dist/types/src/client/queue/queue.d.ts +12 -0
  223. package/dist/types/src/client/queue/rateLimit.d.ts +46 -0
  224. package/dist/types/src/client/queue/runtime/compatibility.d.ts +13 -0
  225. package/dist/types/src/client/queue/runtime/configuration.d.ts +46 -0
  226. package/dist/types/src/client/queue/runtime/connection.d.ts +6 -0
  227. package/dist/types/src/client/queue/runtime/control.d.ts +41 -0
  228. package/dist/types/src/client/queue/runtime/queries.d.ts +66 -0
  229. package/dist/types/src/client/queue/runtime/scheduling.d.ts +33 -0
  230. package/dist/types/src/client/queue/runtime/state.d.ts +101 -0
  231. package/dist/types/src/client/queue/scheduler.d.ts +58 -0
  232. package/dist/types/src/client/queue/schedulerPagination.d.ts +7 -0
  233. package/dist/types/src/client/queue/stall.d.ts +20 -0
  234. package/dist/types/src/client/queue/types/add.d.ts +40 -0
  235. package/dist/types/src/client/queue/types/contexts.d.ts +33 -0
  236. package/dist/types/src/client/queue/types/index.d.ts +3 -0
  237. package/dist/types/src/client/queue/types/job.d.ts +50 -0
  238. package/dist/types/src/client/queue/types/runtime.d.ts +35 -0
  239. package/dist/types/src/client/queue/workers.d.ts +36 -0
  240. package/dist/types/src/client/queue-events/tcpSubscription.d.ts +23 -0
  241. package/dist/types/src/client/queue.d.ts +5 -0
  242. package/dist/types/src/client/queueGroup.d.ts +51 -0
  243. package/dist/types/src/client/resolveToken.d.ts +10 -0
  244. package/dist/types/src/client/sandboxed/index.d.ts +7 -0
  245. package/dist/types/src/client/sandboxed/queueOps.d.ts +24 -0
  246. package/dist/types/src/client/sandboxed/runtime/dispatch.d.ts +13 -0
  247. package/dist/types/src/client/sandboxed/runtime/lifecycle.d.ts +20 -0
  248. package/dist/types/src/client/sandboxed/runtime/log.d.ts +1 -0
  249. package/dist/types/src/client/sandboxed/runtime/pool.d.ts +11 -0
  250. package/dist/types/src/client/sandboxed/runtime/recovery.d.ts +11 -0
  251. package/dist/types/src/client/sandboxed/runtime/state.d.ts +39 -0
  252. package/dist/types/src/client/sandboxed/types/index.d.ts +2 -0
  253. package/dist/types/src/client/sandboxed/types/options.d.ts +27 -0
  254. package/dist/types/src/client/sandboxed/types/process.d.ts +39 -0
  255. package/dist/types/src/client/sandboxed/worker.d.ts +4 -0
  256. package/dist/types/src/client/sandboxed/wrapper.d.ts +12 -0
  257. package/dist/types/src/client/sandboxedWorker.d.ts +6 -0
  258. package/dist/types/src/client/tcp/client.d.ts +6 -0
  259. package/dist/types/src/client/tcp/commandQueue.d.ts +23 -0
  260. package/dist/types/src/client/tcp/connection.d.ts +4 -0
  261. package/dist/types/src/client/tcp/errors.d.ts +6 -0
  262. package/dist/types/src/client/tcp/health.d.ts +60 -0
  263. package/dist/types/src/client/tcp/index.d.ts +11 -0
  264. package/dist/types/src/client/tcp/reconnect.d.ts +47 -0
  265. package/dist/types/src/client/tcp/runtime/commands.d.ts +9 -0
  266. package/dist/types/src/client/tcp/runtime/connectivity.d.ts +13 -0
  267. package/dist/types/src/client/tcp/runtime/health.d.ts +14 -0
  268. package/dist/types/src/client/tcp/runtime/lifecycle.d.ts +8 -0
  269. package/dist/types/src/client/tcp/runtime/state.d.ts +50 -0
  270. package/dist/types/src/client/tcp/shared.d.ts +12 -0
  271. package/dist/types/src/client/tcp/transport.d.ts +18 -0
  272. package/dist/types/src/client/tcp/types/command.d.ts +9 -0
  273. package/dist/types/src/client/tcp/types/connection.d.ts +31 -0
  274. package/dist/types/src/client/tcp/types/index.d.ts +5 -0
  275. package/dist/types/src/client/tcp/types/socket.d.ts +8 -0
  276. package/dist/types/src/client/tcp/types/tls.d.ts +4 -0
  277. package/dist/types/src/client/tcp/types.d.ts +2 -0
  278. package/dist/types/src/client/tcpClient.d.ts +6 -0
  279. package/dist/types/src/client/tcpPool.d.ts +69 -0
  280. package/dist/types/src/client/types/connection.d.ts +30 -0
  281. package/dist/types/src/client/types/dlq.d.ts +45 -0
  282. package/dist/types/src/client/types/events.d.ts +54 -0
  283. package/dist/types/src/client/types/flow.d.ts +22 -0
  284. package/dist/types/src/client/types/index.d.ts +10 -0
  285. package/dist/types/src/client/types/job.d.ts +131 -0
  286. package/dist/types/src/client/types/metrics.d.ts +1 -0
  287. package/dist/types/src/client/types/options.d.ts +70 -0
  288. package/dist/types/src/client/types/worker.d.ts +54 -0
  289. package/dist/types/src/client/types.d.ts +2 -0
  290. package/dist/types/src/client/worker/ackBatcher.d.ts +55 -0
  291. package/dist/types/src/client/worker/ackFrontier.d.ts +21 -0
  292. package/dist/types/src/client/worker/ackOutcome.d.ts +8 -0
  293. package/dist/types/src/client/worker/batchExecution.d.ts +14 -0
  294. package/dist/types/src/client/worker/constants.d.ts +7 -0
  295. package/dist/types/src/client/worker/groupConcurrency.d.ts +49 -0
  296. package/dist/types/src/client/worker/handlers/completion.d.ts +29 -0
  297. package/dist/types/src/client/worker/handlers/dependencies.d.ts +11 -0
  298. package/dist/types/src/client/worker/handlers/mutations.d.ts +23 -0
  299. package/dist/types/src/client/worker/handlers/queries.d.ts +15 -0
  300. package/dist/types/src/client/worker/jobParser.d.ts +9 -0
  301. package/dist/types/src/client/worker/processor.d.ts +11 -0
  302. package/dist/types/src/client/worker/processorHandlers.d.ts +4 -0
  303. package/dist/types/src/client/worker/processorOutcome.d.ts +14 -0
  304. package/dist/types/src/client/worker/processorResult.d.ts +2 -0
  305. package/dist/types/src/client/worker/runtime/buffer.d.ts +8 -0
  306. package/dist/types/src/client/worker/runtime/control.d.ts +28 -0
  307. package/dist/types/src/client/worker/runtime/execution.d.ts +16 -0
  308. package/dist/types/src/client/worker/runtime/lifecycle.d.ts +7 -0
  309. package/dist/types/src/client/worker/runtime/manual.d.ts +10 -0
  310. package/dist/types/src/client/worker/runtime/options.d.ts +5 -0
  311. package/dist/types/src/client/worker/runtime/polling.d.ts +14 -0
  312. package/dist/types/src/client/worker/runtime/state.d.ts +121 -0
  313. package/dist/types/src/client/worker/types/index.d.ts +5 -0
  314. package/dist/types/src/client/worker/types/manual.d.ts +7 -0
  315. package/dist/types/src/client/worker/types/options.d.ts +26 -0
  316. package/dist/types/src/client/worker/types/outcome.d.ts +23 -0
  317. package/dist/types/src/client/worker/types/processor.d.ts +25 -0
  318. package/dist/types/src/client/worker/types/transport.d.ts +11 -0
  319. package/dist/types/src/client/worker/worker.d.ts +6 -0
  320. package/dist/types/src/client/worker/workerHeartbeat.d.ts +15 -0
  321. package/dist/types/src/client/worker/workerPull.d.ts +24 -0
  322. package/dist/types/src/client/worker/workerRateLimiter.d.ts +51 -0
  323. package/dist/types/src/client/worker.d.ts +6 -0
  324. package/dist/types/src/client/workflow/admission.d.ts +45 -0
  325. package/dist/types/src/client/workflow/clock.d.ts +60 -0
  326. package/dist/types/src/client/workflow/compensationChild.d.ts +33 -0
  327. package/dist/types/src/client/workflow/compensationClaim.d.ts +11 -0
  328. package/dist/types/src/client/workflow/compensationPass.d.ts +17 -0
  329. package/dist/types/src/client/workflow/compensationSupport.d.ts +24 -0
  330. package/dist/types/src/client/workflow/compensator.d.ts +34 -0
  331. package/dist/types/src/client/workflow/definitionGuard.d.ts +11 -0
  332. package/dist/types/src/client/workflow/emitter.d.ts +17 -0
  333. package/dist/types/src/client/workflow/engine.d.ts +66 -0
  334. package/dist/types/src/client/workflow/eventTypes.d.ts +44 -0
  335. package/dist/types/src/client/workflow/executionFence.d.ts +15 -0
  336. package/dist/types/src/client/workflow/executionTypes.d.ts +133 -0
  337. package/dist/types/src/client/workflow/executor.d.ts +52 -0
  338. package/dist/types/src/client/workflow/executorLifecycle.d.ts +19 -0
  339. package/dist/types/src/client/workflow/executorNodes.d.ts +18 -0
  340. package/dist/types/src/client/workflow/executorQueue.d.ts +9 -0
  341. package/dist/types/src/client/workflow/forEachRunner.d.ts +4 -0
  342. package/dist/types/src/client/workflow/identity.d.ts +48 -0
  343. package/dist/types/src/client/workflow/index.d.ts +23 -0
  344. package/dist/types/src/client/workflow/loops.d.ts +11 -0
  345. package/dist/types/src/client/workflow/mapRunner.d.ts +4 -0
  346. package/dist/types/src/client/workflow/recovery.d.ts +32 -0
  347. package/dist/types/src/client/workflow/rollbackControl.d.ts +37 -0
  348. package/dist/types/src/client/workflow/runner.d.ts +23 -0
  349. package/dist/types/src/client/workflow/runnerTiming.d.ts +14 -0
  350. package/dist/types/src/client/workflow/stepTypes.d.ts +171 -0
  351. package/dist/types/src/client/workflow/store.d.ts +83 -0
  352. package/dist/types/src/client/workflow/storeCodec.d.ts +7 -0
  353. package/dist/types/src/client/workflow/storeExecutionCodec.d.ts +11 -0
  354. package/dist/types/src/client/workflow/storeListing.d.ts +11 -0
  355. package/dist/types/src/client/workflow/storeMaintenance.d.ts +4 -0
  356. package/dist/types/src/client/workflow/storeSignals.d.ts +70 -0
  357. package/dist/types/src/client/workflow/subWorkflowRunner.d.ts +14 -0
  358. package/dist/types/src/client/workflow/types.d.ts +4 -0
  359. package/dist/types/src/client/workflow/unwindPlan.d.ts +87 -0
  360. package/dist/types/src/client/workflow/waitFor.d.ts +56 -0
  361. package/dist/types/src/client/workflow/workflow.d.ts +70 -0
  362. package/dist/types/src/client/workflow/workflowDecisions.d.ts +11 -0
  363. package/dist/types/src/client/workflow/workflowDefinition.d.ts +16 -0
  364. package/dist/types/src/client/workflow/workflowIntrospection.d.ts +5 -0
  365. package/dist/types/src/client/workflow/workflowValidation.d.ts +44 -0
  366. package/dist/types/src/config/index.d.ts +9 -0
  367. package/dist/types/src/config/loader.d.ts +7 -0
  368. package/dist/types/src/config/resolve.d.ts +59 -0
  369. package/dist/types/src/config/types.d.ts +88 -0
  370. package/dist/types/src/domain/job/constants.d.ts +12 -0
  371. package/dist/types/src/domain/job/create.d.ts +2 -0
  372. package/dist/types/src/domain/job/groupFifoOrder.d.ts +9 -0
  373. package/dist/types/src/domain/job/ids.d.ts +7 -0
  374. package/dist/types/src/domain/job/locks.d.ts +4 -0
  375. package/dist/types/src/domain/job/payload.d.ts +18 -0
  376. package/dist/types/src/domain/job/state.d.ts +8 -0
  377. package/dist/types/src/domain/job/terminal.d.ts +3 -0
  378. package/dist/types/src/domain/queue/dependencyTracker.d.ts +78 -0
  379. package/dist/types/src/domain/queue/dlqShard.d.ts +66 -0
  380. package/dist/types/src/domain/queue/groupLimiterManager.d.ts +30 -0
  381. package/dist/types/src/domain/queue/groupScheduler.d.ts +31 -0
  382. package/dist/types/src/domain/queue/groupSchedulerOrder.d.ts +6 -0
  383. package/dist/types/src/domain/queue/limiterManager.d.ts +68 -0
  384. package/dist/types/src/domain/queue/priorityQueue.d.ts +54 -0
  385. package/dist/types/src/domain/queue/priorityQueueOrder.d.ts +3 -0
  386. package/dist/types/src/domain/queue/shard/dependencies.d.ts +11 -0
  387. package/dist/types/src/domain/queue/shard/dlq.d.ts +26 -0
  388. package/dist/types/src/domain/queue/shard/keys.d.ts +19 -0
  389. package/dist/types/src/domain/queue/shard/lifecycle.d.ts +10 -0
  390. package/dist/types/src/domain/queue/shard/limits.d.ts +47 -0
  391. package/dist/types/src/domain/queue/shard/metrics.d.ts +32 -0
  392. package/dist/types/src/domain/queue/shard/state.d.ts +40 -0
  393. package/dist/types/src/domain/queue/shard.d.ts +7 -0
  394. package/dist/types/src/domain/queue/shardCounters.d.ts +35 -0
  395. package/dist/types/src/domain/queue/temporalIndex.d.ts +24 -0
  396. package/dist/types/src/domain/queue/temporalManager.d.ts +72 -0
  397. package/dist/types/src/domain/queue/uniqueKeyManager.d.ts +33 -0
  398. package/dist/types/src/domain/queue/waiterManager.d.ts +18 -0
  399. package/dist/types/src/domain/response/builders.d.ts +15 -0
  400. package/dist/types/src/domain/types/command.d.ts +2 -0
  401. package/dist/types/src/domain/types/commands/base.d.ts +5 -0
  402. package/dist/types/src/domain/types/commands/core.d.ts +110 -0
  403. package/dist/types/src/domain/types/commands/cron.d.ts +36 -0
  404. package/dist/types/src/domain/types/commands/dashboard.d.ts +13 -0
  405. package/dist/types/src/domain/types/commands/dlq.d.ts +44 -0
  406. package/dist/types/src/domain/types/commands/extended.d.ts +63 -0
  407. package/dist/types/src/domain/types/commands/index.d.ts +12 -0
  408. package/dist/types/src/domain/types/commands/limits.d.ts +108 -0
  409. package/dist/types/src/domain/types/commands/management.d.ts +73 -0
  410. package/dist/types/src/domain/types/commands/monitoring.d.ts +49 -0
  411. package/dist/types/src/domain/types/commands/protocol.d.ts +20 -0
  412. package/dist/types/src/domain/types/commands/query.d.ts +46 -0
  413. package/dist/types/src/domain/types/commands/union.d.ts +13 -0
  414. package/dist/types/src/domain/types/commands/workers.d.ts +39 -0
  415. package/dist/types/src/domain/types/cron.d.ts +91 -0
  416. package/dist/types/src/domain/types/deduplication.d.ts +43 -0
  417. package/dist/types/src/domain/types/dlq.d.ts +136 -0
  418. package/dist/types/src/domain/types/flow.d.ts +25 -0
  419. package/dist/types/src/domain/types/group.d.ts +26 -0
  420. package/dist/types/src/domain/types/job.d.ts +8 -0
  421. package/dist/types/src/domain/types/jobs/model.d.ts +153 -0
  422. package/dist/types/src/domain/types/metrics.d.ts +16 -0
  423. package/dist/types/src/domain/types/priorityQueue.d.ts +13 -0
  424. package/dist/types/src/domain/types/protocol.d.ts +5 -0
  425. package/dist/types/src/domain/types/queue.d.ts +110 -0
  426. package/dist/types/src/domain/types/response.d.ts +3 -0
  427. package/dist/types/src/domain/types/responses/model.d.ts +152 -0
  428. package/dist/types/src/domain/types/shard.d.ts +4 -0
  429. package/dist/types/src/domain/types/stall.d.ts +48 -0
  430. package/dist/types/src/domain/types/webhook.d.ts +42 -0
  431. package/dist/types/src/domain/types/worker.d.ts +40 -0
  432. package/dist/types/src/infrastructure/backup/backupTelemetry.d.ts +30 -0
  433. package/dist/types/src/infrastructure/backup/s3BackupConfig.d.ts +80 -0
  434. package/dist/types/src/infrastructure/cloud/types/config.d.ts +18 -0
  435. package/dist/types/src/infrastructure/cloud/types/event.d.ts +14 -0
  436. package/dist/types/src/infrastructure/cloud/types/snapshot.d.ts +52 -0
  437. package/dist/types/src/infrastructure/cloud/types/snapshotCore.d.ts +125 -0
  438. package/dist/types/src/infrastructure/cloud/types/snapshotJobs.d.ts +124 -0
  439. package/dist/types/src/infrastructure/cloud/types/snapshotTelemetry.d.ts +100 -0
  440. package/dist/types/src/infrastructure/cloud/types.d.ts +3 -0
  441. package/dist/types/src/infrastructure/persistence/batchInsert.d.ts +13 -0
  442. package/dist/types/src/infrastructure/persistence/completedJobCountSchema.d.ts +6 -0
  443. package/dist/types/src/infrastructure/persistence/dependencyCompletionSchema.d.ts +6 -0
  444. package/dist/types/src/infrastructure/persistence/dependencyCompletionStore.d.ts +40 -0
  445. package/dist/types/src/infrastructure/persistence/index.d.ts +5 -0
  446. package/dist/types/src/infrastructure/persistence/jobOptionsBlob.d.ts +19 -0
  447. package/dist/types/src/infrastructure/persistence/legacyNameMigration.d.ts +17 -0
  448. package/dist/types/src/infrastructure/persistence/migrationProgressSchema.d.ts +2 -0
  449. package/dist/types/src/infrastructure/persistence/migrations.d.ts +3 -0
  450. package/dist/types/src/infrastructure/persistence/schema.d.ts +8 -0
  451. package/dist/types/src/infrastructure/persistence/sqlite/admission.d.ts +9 -0
  452. package/dist/types/src/infrastructure/persistence/sqlite/completed.d.ts +17 -0
  453. package/dist/types/src/infrastructure/persistence/sqlite/control.d.ts +48 -0
  454. package/dist/types/src/infrastructure/persistence/sqlite/flows.d.ts +26 -0
  455. package/dist/types/src/infrastructure/persistence/sqlite/jobLifecycle.d.ts +17 -0
  456. package/dist/types/src/infrastructure/persistence/sqlite/jobs.d.ts +15 -0
  457. package/dist/types/src/infrastructure/persistence/sqlite/lifecycle.d.ts +6 -0
  458. package/dist/types/src/infrastructure/persistence/sqlite/mutations.d.ts +27 -0
  459. package/dist/types/src/infrastructure/persistence/sqlite/queries.d.ts +23 -0
  460. package/dist/types/src/infrastructure/persistence/sqlite/queueDeletionSql.d.ts +3 -0
  461. package/dist/types/src/infrastructure/persistence/sqlite/records.d.ts +24 -0
  462. package/dist/types/src/infrastructure/persistence/sqlite/state.d.ts +42 -0
  463. package/dist/types/src/infrastructure/persistence/sqlite/telemetry.d.ts +17 -0
  464. package/dist/types/src/infrastructure/persistence/sqlite/telemetryStore.d.ts +30 -0
  465. package/dist/types/src/infrastructure/persistence/sqlite/telemetryWrites.d.ts +47 -0
  466. package/dist/types/src/infrastructure/persistence/sqlite.d.ts +6 -0
  467. package/dist/types/src/infrastructure/persistence/sqliteBatch.d.ts +4 -0
  468. package/dist/types/src/infrastructure/persistence/sqliteMigration.d.ts +5 -0
  469. package/dist/types/src/infrastructure/persistence/sqliteSerializer.d.ts +50 -0
  470. package/dist/types/src/infrastructure/persistence/statements.d.ts +86 -0
  471. package/dist/types/src/infrastructure/persistence/types/admission.d.ts +8 -0
  472. package/dist/types/src/infrastructure/persistence/types/batch.d.ts +12 -0
  473. package/dist/types/src/infrastructure/persistence/types/sqlite.d.ts +27 -0
  474. package/dist/types/src/infrastructure/persistence/writeBuffer.d.ts +48 -0
  475. package/dist/types/src/infrastructure/persistence/writeBufferPending.d.ts +11 -0
  476. package/dist/types/src/infrastructure/scheduler/cron/execution.d.ts +12 -0
  477. package/dist/types/src/infrastructure/scheduler/cron/persisted.d.ts +5 -0
  478. package/dist/types/src/infrastructure/scheduler/cron/runtime.d.ts +31 -0
  479. package/dist/types/src/infrastructure/scheduler/cron/validation.d.ts +3 -0
  480. package/dist/types/src/infrastructure/scheduler/cronParser.d.ts +45 -0
  481. package/dist/types/src/infrastructure/scheduler/cronScheduler.d.ts +5 -0
  482. package/dist/types/src/infrastructure/scheduler/types/cronScheduler.d.ts +16 -0
  483. package/dist/types/src/infrastructure/server/protocol/commands.d.ts +8 -0
  484. package/dist/types/src/infrastructure/server/protocol/frameParser.d.ts +16 -0
  485. package/dist/types/src/infrastructure/server/protocol/lineBuffer.d.ts +6 -0
  486. package/dist/types/src/infrastructure/server/protocol/validation.d.ts +10 -0
  487. package/dist/types/src/infrastructure/server/protocol.d.ts +6 -0
  488. package/dist/types/src/infrastructure/server/socketWriteQueue.d.ts +66 -0
  489. package/dist/types/src/infrastructure/server/types/protocol.d.ts +4 -0
  490. package/dist/types/src/require-bun.d.ts +13 -0
  491. package/dist/types/src/shared/asyncLock.d.ts +13 -0
  492. package/dist/types/src/shared/boundedMap.d.ts +30 -0
  493. package/dist/types/src/shared/boundedSet.d.ts +26 -0
  494. package/dist/types/src/shared/hash.d.ts +30 -0
  495. package/dist/types/src/shared/histogram.d.ts +23 -0
  496. package/dist/types/src/shared/lock.d.ts +13 -0
  497. package/dist/types/src/shared/lockError.d.ts +3 -0
  498. package/dist/types/src/shared/lockTimeout.d.ts +2 -0
  499. package/dist/types/src/shared/logger.d.ts +48 -0
  500. package/dist/types/src/shared/lru.d.ts +9 -0
  501. package/dist/types/src/shared/lruMap.d.ts +42 -0
  502. package/dist/types/src/shared/lruSet.d.ts +36 -0
  503. package/dist/types/src/shared/minHeap.d.ts +43 -0
  504. package/dist/types/src/shared/msgpack.d.ts +3 -0
  505. package/dist/types/src/shared/pausedView.d.ts +19 -0
  506. package/dist/types/src/shared/rwLock.d.ts +22 -0
  507. package/dist/types/src/shared/serialization.d.ts +24 -0
  508. package/dist/types/src/shared/skipList.d.ts +97 -0
  509. package/dist/types/src/shared/skipListNodes.d.ts +6 -0
  510. package/dist/types/src/shared/storageHealth.d.ts +9 -0
  511. package/dist/types/src/shared/ttlMap.d.ts +81 -0
  512. package/dist/types/src/shared/types/lock.d.ts +7 -0
  513. package/dist/types/src/shared/types/skipList.d.ts +4 -0
  514. package/dist/types/src/shared/version.d.ts +4 -0
  515. package/dist/types/src/shared/webhookValidation.d.ts +6 -0
  516. package/package.json +27 -9
  517. package/src/ack-batcher.ts +8 -5
  518. package/src/bunqueue/bunqueue-api.ts +1 -1
  519. package/src/bunqueue/bunqueue.ts +2 -1
  520. package/src/canonical-transport/bun-sqlite-types.ts +22 -0
  521. package/src/canonical-transport/dlq.ts +12 -0
  522. package/src/canonical-transport/embedded.ts +55 -0
  523. package/src/canonical-transport/runtime.ts +49 -0
  524. package/src/canonical-transport/thread-worker.ts +83 -0
  525. package/src/canonical-transport/transport.ts +153 -0
  526. package/src/connection.ts +25 -30
  527. package/src/errors.ts +3 -0
  528. package/src/flow-commit.ts +45 -0
  529. package/src/flow-plan-legacy.ts +117 -0
  530. package/src/flow-plan.ts +209 -0
  531. package/src/flow-types.ts +4 -0
  532. package/src/flow.ts +31 -163
  533. package/src/frame.ts +5 -2
  534. package/src/index.ts +7 -75
  535. package/src/job.ts +43 -9
  536. package/src/legacy.ts +91 -0
  537. package/src/observability.ts +59 -1
  538. package/src/queue-admin.ts +5 -5
  539. package/src/queue-control.ts +12 -8
  540. package/src/queue.ts +10 -6
  541. package/src/serialization.ts +93 -0
  542. package/src/terminal-outcome.ts +58 -0
  543. package/src/types.ts +3 -6
  544. package/src/worker-base.ts +9 -6
  545. package/src/worker-slot-signal.ts +23 -0
  546. package/src/worker.ts +11 -5
  547. package/dist/backpressure.js +0 -39
  548. package/dist/bunqueue/aging.js +0 -53
  549. package/dist/bunqueue/batch.js +0 -60
  550. package/dist/bunqueue/bunqueue-api.js +0 -116
  551. package/dist/bunqueue/bunqueue.js +0 -194
  552. package/dist/bunqueue/cancellation.js +0 -48
  553. package/dist/bunqueue/circuit-breaker.js +0 -69
  554. package/dist/bunqueue/dedup-debounce.js +0 -37
  555. package/dist/bunqueue/dlq-rate-limit.js +0 -65
  556. package/dist/bunqueue/rate-gate.js +0 -61
  557. package/dist/bunqueue/retry.js +0 -56
  558. package/dist/bunqueue/triggers.js +0 -42
  559. package/dist/bunqueue/ttl.js +0 -31
  560. package/dist/bunqueue/types.js +0 -6
  561. package/dist/connection-pool.js +0 -60
  562. package/dist/connection-types.js +0 -2
  563. package/dist/connection.js +0 -281
  564. package/dist/errors.js +0 -25
  565. package/dist/flow-types.js +0 -2
  566. package/dist/flow.js +0 -212
  567. package/dist/job.js +0 -155
  568. package/dist/observability.js +0 -110
  569. package/dist/queue-admin.js +0 -158
  570. package/dist/queue-control.js +0 -105
  571. package/dist/queue-query.js +0 -187
  572. package/dist/queue.js +0 -92
  573. package/dist/responses.js +0 -10
  574. package/dist/socket-factory.js +0 -47
  575. package/dist/types.js +0 -50
  576. package/dist/worker-base.js +0 -159
  577. package/dist/worker-types.js +0 -5
  578. package/dist/worker.js +0 -211
  579. /package/dist/{backpressure.d.ts → types/sdk/typescript/src/backpressure.d.ts} +0 -0
  580. /package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/cancellation.d.ts +0 -0
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Timing primitives used while running a workflow step.
3
+ *
4
+ * Kept separate from runner.ts so the runner stays focused on state transitions.
5
+ */
6
+ /** Exponential retry backoff with jitter. */
7
+ export declare function retryBackoffDelay(attempt: number, baseMs?: number, maxMs?: number): number;
8
+ /**
9
+ * Bound a value or PromiseLike without passing an overflowing delay to the runtime.
10
+ *
11
+ * Long deadlines are re-armed in platform-sized chunks. Promise.resolve is
12
+ * intentional: it assimilates userland thenables as well as native promises.
13
+ */
14
+ export declare function runWithTimeout<T>(value: PromiseLike<T> | T, timeoutMs: number, controller?: AbortController): Promise<T>;
@@ -0,0 +1,171 @@
1
+ /** Workflow handler, definition, and graph types. */
2
+ /** Context passed to step handlers */
3
+ export interface StepContext<TInput = unknown, TSteps extends Record<string, unknown> = Record<string, unknown>> {
4
+ /** Original workflow input */
5
+ readonly input: TInput;
6
+ /** Results from completed steps (step name → result) */
7
+ readonly steps: Readonly<TSteps>;
8
+ /** Signals received via engine.signal() */
9
+ readonly signals: Readonly<Record<string, unknown>>;
10
+ /** Current execution ID */
11
+ readonly executionId: string;
12
+ /**
13
+ * Aborted when this handler attempt reaches its timeout.
14
+ *
15
+ * Handlers that support cooperative cancellation should pass this signal to
16
+ * downstream I/O so timed-out work does not continue after the workflow moves on.
17
+ */
18
+ readonly signal?: AbortSignal;
19
+ /**
20
+ * Idempotency key for THIS execution of the step. Stable across automatic retries
21
+ * and across crash-resume; different for a different run. Pass it straight to the
22
+ * provider so a repeat lands on the same operation instead of a new one.
23
+ */
24
+ readonly idempotencyKey?: string;
25
+ /**
26
+ * Compensation only: the key the FORWARD step used. When the forward outcome is
27
+ * in doubt, this is what lets a rollback ask the provider "did this actually
28
+ * happen?" instead of depending on an output that may never have been persisted.
29
+ */
30
+ readonly forwardIdempotencyKey?: string;
31
+ }
32
+ /** Step handler function (type-erased for internal storage) */
33
+ export type StepHandler<TInput = unknown, TResult = unknown> = (ctx: StepContext<TInput, any>) => Promise<TResult> | TResult;
34
+ /** Typed step handler — preserves accumulated step types */
35
+ export type TypedStepHandler<TInput, TSteps extends Record<string, unknown>, TResult> = (ctx: StepContext<TInput, TSteps>) => Promise<TResult> | TResult;
36
+ /** Compensate handler (type-erased for internal storage) */
37
+ export type CompensateHandler<TInput = unknown> = (ctx: StepContext<TInput, any>) => Promise<void> | void;
38
+ /** Typed compensate handler — preserves accumulated step types */
39
+ export type TypedCompensateHandler<TInput, TSteps extends Record<string, unknown>> = (ctx: StepContext<TInput, TSteps>) => Promise<void> | void;
40
+ /** Schema-like object — any object with a .parse() method (Zod, ArkType, Valibot, etc.) */
41
+ export interface SchemaLike {
42
+ parse(data: unknown): unknown;
43
+ }
44
+ /**
45
+ * Options for a single step.
46
+ *
47
+ * `TSteps` is part of the signature for source compatibility and for symmetry with
48
+ * `TypedStepHandler`, even though `compensate` no longer narrows on it (see below).
49
+ * Removing the parameter would break every explicit `StepOptions<In, Steps>` in
50
+ * user code.
51
+ */
52
+ export interface StepOptions<TInput = unknown, TSteps extends Record<string, unknown> = Record<string, unknown>> {
53
+ retry?: number;
54
+ timeout?: number;
55
+ /**
56
+ * A METHOD taking a permissively-typed context, and every part of that is load
57
+ * bearing. Three forms were measured against real handler shapes:
58
+ *
59
+ * shape union method<TSteps> method<any>
60
+ * compensate: async (ctx) => ... TS7006 ok ok
61
+ * annotated with steps it reads ok ok ok
62
+ * annotated with a step that does not exist ok TS2322 ok
63
+ * CompensateHandler<TInput> alias ok ok ok
64
+ *
65
+ * Not a union (`TypedCompensateHandler | CompensateHandler`): TypeScript cannot
66
+ * contextually type a parameter against a union of signatures, so the inline arrow
67
+ * every documented example uses was an implicit `any` and failed `noImplicitAny`.
68
+ *
69
+ * A method rather than a property so parameters stay bivariant under
70
+ * `strictFunctionTypes`, which is what lets an explicitly annotated handler through.
71
+ *
72
+ * `any` rather than `TSteps` for the step map, deliberately: with `TSteps` an
73
+ * annotation naming a step this workflow does not declare is rejected, and the
74
+ * published union accepted it. Keeping the looser map costs typed access to
75
+ * `ctx.steps` inside a rollback, which handlers already narrow with a cast in
76
+ * practice, and buys source compatibility with every handler written before.
77
+ */
78
+ compensate?(ctx: StepContext<TInput, TSteps extends never ? never : any>): Promise<void> | void;
79
+ /** Validate step input before execution */
80
+ inputSchema?: SchemaLike;
81
+ /** Validate step output after execution */
82
+ outputSchema?: SchemaLike;
83
+ }
84
+ /** Internal step definition */
85
+ export interface StepDefinition {
86
+ name: string;
87
+ handler: StepHandler;
88
+ compensate?: CompensateHandler;
89
+ retry: number;
90
+ timeout: number;
91
+ inputSchema?: SchemaLike;
92
+ outputSchema?: SchemaLike;
93
+ }
94
+ /** Branch condition function */
95
+ export type BranchCondition<TInput = unknown, TSteps extends Record<string, unknown> = Record<string, unknown>> = (ctx: StepContext<TInput, TSteps>) => string;
96
+ /** Internal branch definition (type-erased) */
97
+ export interface BranchDefinition {
98
+ condition: BranchCondition<any, any>;
99
+ paths: Map<string, StepDefinition[]>;
100
+ }
101
+ /** Definition of a parallel step group */
102
+ export interface ParallelDefinition {
103
+ steps: StepDefinition[];
104
+ }
105
+ /** Input mapper for sub-workflows */
106
+ export type SubWorkflowInputMapper<TInput = unknown, TSteps extends Record<string, unknown> = Record<string, unknown>> = (ctx: StepContext<TInput, TSteps>) => unknown;
107
+ /** Bounds for polling a child workflow. */
108
+ export interface SubWorkflowOptions {
109
+ /** Maximum time to wait for the child. Defaults to five minutes. */
110
+ timeout?: number;
111
+ /** Delay between durable child-state reads. Defaults to 100ms. */
112
+ pollInterval?: number;
113
+ }
114
+ /** Loop condition: receives context + iteration count, returns boolean */
115
+ export type LoopCondition<TInput = unknown, TSteps extends Record<string, unknown> = Record<string, unknown>> = (ctx: StepContext<TInput, TSteps>, iteration: number) => boolean | Promise<boolean>;
116
+ /** Definition of a doUntil/doWhile loop (type-erased) */
117
+ export interface LoopDefinition {
118
+ condition: LoopCondition<any, any>;
119
+ steps: StepDefinition[];
120
+ maxIterations: number;
121
+ }
122
+ /** Item extractor for forEach */
123
+ export type ForEachItemsExtractor<TInput = unknown, TSteps extends Record<string, unknown> = Record<string, unknown>> = (ctx: StepContext<TInput, TSteps>) => unknown[];
124
+ /** Definition of a forEach loop (type-erased) */
125
+ export interface ForEachDefinition {
126
+ items: ForEachItemsExtractor<any, any>;
127
+ step: StepDefinition;
128
+ maxIterations: number;
129
+ }
130
+ /** Transform function for map */
131
+ export type MapTransformFn<TInput = unknown, TSteps extends Record<string, unknown> = Record<string, unknown>> = (ctx: StepContext<TInput, TSteps>) => unknown;
132
+ /** Definition of a map node (type-erased) */
133
+ export interface MapDefinition {
134
+ name: string;
135
+ transform: MapTransformFn<any, any>;
136
+ }
137
+ /** Workflow node (discriminated union) */
138
+ export type WorkflowNode = {
139
+ type: 'step';
140
+ def: StepDefinition;
141
+ } | {
142
+ type: 'branch';
143
+ def: BranchDefinition;
144
+ } | {
145
+ type: 'waitFor';
146
+ event: string;
147
+ timeout?: number;
148
+ } | {
149
+ type: 'parallel';
150
+ def: ParallelDefinition;
151
+ } | {
152
+ type: 'subWorkflow';
153
+ name: string;
154
+ inputMapper: SubWorkflowInputMapper<any, any>;
155
+ timeout: number;
156
+ pollInterval: number;
157
+ } | {
158
+ type: 'doUntil';
159
+ def: LoopDefinition;
160
+ } | {
161
+ type: 'doWhile';
162
+ def: LoopDefinition;
163
+ } | {
164
+ type: 'forEach';
165
+ def: ForEachDefinition;
166
+ } | {
167
+ type: 'map';
168
+ def: MapDefinition;
169
+ } | {
170
+ type: 'pivot';
171
+ };
@@ -0,0 +1,83 @@
1
+ /**
2
+ * WorkflowStore - SQLite persistence for workflow executions
3
+ */
4
+ import type { Execution, ExecutionListOptions, ExecutionState, ParkOutcome, SignalOutcome } from "./types.js";
5
+ export declare class WorkflowStore {
6
+ private readonly db;
7
+ private readonly stmts;
8
+ /** Sole owner of the `signals` column — see storeSignals.ts */
9
+ private readonly signals;
10
+ private readonly listing;
11
+ constructor(dbPath?: string);
12
+ /**
13
+ * Insert a fresh execution. A plain INSERT exposes id collisions instead of
14
+ * replacing live runs. This is the only signal writer outside SignalCoordinator and
15
+ * is safe because callers pass a new execution with no signals.
16
+ */
17
+ save(exec: Execution): void;
18
+ get(id: string): Execution | null;
19
+ findChild(parentExecutionId: string, workflowName: string): Execution | null;
20
+ /** Remove an execution whose initial queue publication failed. */
21
+ remove(id: string): boolean;
22
+ /**
23
+ * Persist the step-level columns of an execution.
24
+ *
25
+ * Deliberately does NOT write `signals`. A worker holds one in-memory `Execution`
26
+ * for the whole duration of a node, so its `signals` snapshot goes stale as soon as
27
+ * `recordSignal()` writes to the row. Rewriting the column from that stale snapshot
28
+ * silently destroyed signals delivered mid-step and parked the run forever
29
+ * (`test/repro-workflow-signal-lost-update.test.ts`). Signal payloads are owned
30
+ * exclusively by `recordSignal()`/`parkForSignal()`, which read-modify-write the
31
+ * column inside a transaction.
32
+ */
33
+ update(exec: Execution): void;
34
+ /**
35
+ * Record a signal payload and, if the run is parked at a `waitFor`, atomically
36
+ * claim the single resume for this caller.
37
+ */
38
+ recordSignal(id: string, event: string, payload: unknown): SignalOutcome;
39
+ /**
40
+ * Restore the wait claim if publishing its resume job failed.
41
+ *
42
+ * The signal remains durable, so recover() can publish the resume again.
43
+ */
44
+ restoreSignalWait(id: string, event: string, nodeIndex: number): boolean;
45
+ /**
46
+ * Park a running execution at a `waitFor`, unless the awaited signal has already
47
+ * been recorded (in which case the caller must advance instead).
48
+ */
49
+ parkForSignal(id: string, event: string): ParkOutcome;
50
+ list(workflowName?: string, state?: ExecutionState, options?: ExecutionListOptions): Execution[];
51
+ /** Runs whose registered definition must remain available and structurally stable. */
52
+ listActive(workflowName: string): Execution[];
53
+ /**
54
+ * Executions in a recoverable state that recovery may drive ON ITS OWN.
55
+ *
56
+ * A `subWorkflow` child is a row like any other, so the state filter alone offered
57
+ * it to `recover()` as if it were a top-level run. Driving it independently re-ran
58
+ * its steps and produced fresh records with no `compensation`, which defeats the
59
+ * "a step that already carries an outcome is not re-run" guard: the parent's later
60
+ * unwind dispatched the child's reversal a SECOND time, against a provider that had
61
+ * already been refunded (`test/repro-model-child-recovered-alone.test.ts`; found by
62
+ * the state-machine model, seed 1267197984).
63
+ *
64
+ * A child's lifecycle belongs to its parent, which unwinds it through `unwindChild`.
65
+ * One exception: if the parent row is gone, nothing owns the child any more, so it
66
+ * is returned rather than stranded forever in a non-terminal state.
67
+ */
68
+ listRecoverable(): Execution[];
69
+ /**
70
+ * Delete executions at least `maxAgeMs` old in terminal states.
71
+ *
72
+ * The cutoff is INCLUSIVE. A strict `<` makes `cleanup(0)`, the documented way to
73
+ * flush everything terminal right now, skip every row whose `updated_at` lands on
74
+ * the current millisecond, which is precisely where a run that just finished lands
75
+ * (`test/repro-workflow-archive-boundary.test.ts`).
76
+ */
77
+ cleanup(maxAgeMs: number, states?: string[]): number;
78
+ /** Archive executions at least `maxAgeMs` old to the archive table. Cutoff inclusive, as in `cleanup`. */
79
+ archive(maxAgeMs: number, states?: string[]): number;
80
+ /** Get archived execution count */
81
+ getArchivedCount(): number;
82
+ close(): void;
83
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * msgpack codec shared by the workflow store and its signal coordinator.
3
+ * Kept in its own module so both can encode blobs identically without either
4
+ * owning the packer.
5
+ */
6
+ export declare function pack(data: unknown): Uint8Array;
7
+ export declare function unpack(buf: Uint8Array | null | undefined): unknown;
@@ -0,0 +1,11 @@
1
+ import type { Execution } from "./types.js";
2
+ export interface ExecutionMeta {
3
+ rollbackStatus?: Execution['rollbackStatus'];
4
+ failureReason?: string;
5
+ committedAt?: number;
6
+ parentExecutionId?: string;
7
+ decisions?: Record<string, unknown>;
8
+ definitionHash?: string;
9
+ }
10
+ export declare function packExecutionMeta(exec: Execution): Uint8Array | null;
11
+ export declare function decodeExecution(row: Record<string, unknown>): Execution;
@@ -0,0 +1,11 @@
1
+ import type { Database } from "../../../sdk/typescript/src/canonical-transport/bun-sqlite-types.js";
2
+ import type { Execution, ExecutionListOptions, ExecutionState } from "./types.js";
3
+ /** Prepared, consistently ordered execution-list queries. */
4
+ export declare class ExecutionListing {
5
+ private readonly all;
6
+ private readonly byName;
7
+ private readonly byState;
8
+ private readonly byBoth;
9
+ constructor(db: Database);
10
+ list(workflowName?: string, state?: ExecutionState, options?: ExecutionListOptions): Execution[];
11
+ }
@@ -0,0 +1,4 @@
1
+ import type { Database } from "../../../sdk/typescript/src/canonical-transport/bun-sqlite-types.js";
2
+ export declare function cleanupExecutions(db: Database, maxAgeMs: number, states?: string[]): number;
3
+ export declare function archiveExecutions(db: Database, maxAgeMs: number, states?: string[]): number;
4
+ export declare function archivedExecutionCount(db: Database): number;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * SignalCoordinator — sole owner of the `signals` column.
3
+ *
4
+ * Signal payloads cannot be persisted the way step state is. A worker holds one
5
+ * in-memory `Execution` for the whole duration of a node, so any full-row write from
6
+ * that snapshot silently reverts a signal that landed while the node was running —
7
+ * the approval disappears and the run parks forever
8
+ * (test/repro-workflow-signal-lost-update.test.ts).
9
+ *
10
+ * So every mutation of `signals` goes through here instead: read-modify-write inside
11
+ * a transaction, and the two state transitions that pair with it ('waiting' ->
12
+ * 'running' on resume, 'running' -> 'waiting' on park) expressed as conditional
13
+ * UPDATEs. Making those conditional is also what collapses duplicate or concurrent
14
+ * signals to exactly one resume, at the database rather than relying on the event
15
+ * loop never yielding at the right moment.
16
+ */
17
+ import type { Database } from "../../../sdk/typescript/src/canonical-transport/bun-sqlite-types.js";
18
+ import type { ParkOutcome, SignalOutcome } from "./types.js";
19
+ /**
20
+ * Has this signal arrived? A KEY test, deliberately not a value test.
21
+ *
22
+ * `payload` is optional on `Engine.signal()`, so "the human said go" with nothing to
23
+ * carry is recorded as `signals[event] = undefined`. The codec is configured with
24
+ * `structuredClone: true` and round-trips that faithfully — the key is present, the
25
+ * value is `undefined` — so `signals[event] !== undefined` answers "did it arrive?"
26
+ * with NO for the most idiomatic call in the whole human-in-the-loop API.
27
+ *
28
+ * That disagreed with `record()`, which claims the resume without inspecting the
29
+ * payload: the run resumed, re-entered the waitFor, was told no signal had arrived,
30
+ * and parked again. With a timeout it then expired and compensated work the approver
31
+ * had just authorised (`test/repro-workflow-signal-no-payload.test.ts`).
32
+ *
33
+ * The predicate itself is `Object.hasOwn`, and an earlier revision of this comment
34
+ * claimed `in` was safe here because the object is always a fresh decode. That was
35
+ * wrong twice over: `in` walks the prototype chain regardless of where the object came
36
+ * from, and the EVENT NAME is user-supplied even when the object is not.
37
+ */
38
+ export declare function hasSignal(signals: Record<string, unknown>, event: string): boolean;
39
+ export declare class SignalCoordinator {
40
+ private readonly db;
41
+ private readonly read;
42
+ private readonly write;
43
+ private readonly claimResume;
44
+ private readonly restoreWait;
45
+ private readonly claimPark;
46
+ constructor(db: Database);
47
+ /**
48
+ * Record a signal payload and, if the run is parked at a `waitFor`, atomically
49
+ * claim the single resume for this caller.
50
+ */
51
+ record(id: string, event: string, payload: unknown): SignalOutcome;
52
+ /**
53
+ * Put a claimed wait back when publishing its resume job failed.
54
+ *
55
+ * The signal stays recorded: recovery sees the waiting row plus the signal key and
56
+ * retries the resume. The cursor predicate prevents a delayed enqueue rejection
57
+ * from parking an execution that another driver has already advanced.
58
+ */
59
+ restoreWaiting(id: string, event: string, nodeIndex: number): boolean;
60
+ /**
61
+ * Park a running execution at a `waitFor`, unless the awaited signal has already
62
+ * been recorded.
63
+ *
64
+ * Closes the window where a signal lands after `runWaitFor` read its in-memory
65
+ * snapshot but before the run reaches state `waiting`: without the re-check the
66
+ * payload is stored, nobody claims the resume, and the run hangs.
67
+ */
68
+ park(id: string, event: string): ParkOutcome;
69
+ private decode;
70
+ }
@@ -0,0 +1,14 @@
1
+ import type { Execution } from "./types.js";
2
+ export interface SubWorkflowRunOptions {
3
+ pollIntervalMs?: number;
4
+ maxWaitMs?: number;
5
+ existingChildId?: string;
6
+ assertActive?: () => void;
7
+ }
8
+ /** Start or resume a child execution and poll its durable terminal state. */
9
+ export declare function executeSubWorkflow(workflowName: string, input: unknown, startFn: (name: string, input: unknown) => Promise<{
10
+ id: string;
11
+ }>, getFn: (id: string) => Execution | null, options?: SubWorkflowRunOptions): Promise<{
12
+ results: Record<string, unknown>;
13
+ executionId: string;
14
+ }>;
@@ -0,0 +1,4 @@
1
+ /** Stable public barrel for workflow types. */
2
+ export type * from "./stepTypes.js";
3
+ export type * from "./executionTypes.js";
4
+ export type * from "./eventTypes.js";
@@ -0,0 +1,87 @@
1
+ /**
2
+ * What the unwind should DO with each eligible record, decided as a pure function.
3
+ *
4
+ * WHY THIS FILE EXISTS. Every rollback defect this engine shipped lived in the four
5
+ * lines that decide whether a record is skipped, halted on, or reversed: a loop
6
+ * mirror compensated twice, a step called `charge:extra` resolved to the loop `charge`,
7
+ * a renamed step dropped so the unwind reported a clean rollback over money that was
8
+ * never refunded. None of those are I/O bugs. They are decisions, and while they lived
9
+ * inside a 90-line async function that also wrote to SQLite and emitted events, the
10
+ * only way to test them was to stand up an Engine, a database and a real failure, and
11
+ * then infer the decision from its side effects.
12
+ *
13
+ * Here the decision is a value. It takes data and returns what to do, so it can be
14
+ * exercised with generated inputs in microseconds and read without tracing an await.
15
+ * The impure loop in `compensator.ts` becomes what it should be: a dispatcher that
16
+ * performs the actions this file names.
17
+ *
18
+ * The ORDER of the checks is load-bearing and each one earned its place by breaking:
19
+ *
20
+ * 1. vanished before settled — a record settled by an earlier attempt whose step
21
+ * no longer resolves must halt, and the settled check would have skipped it.
22
+ * 2. settled before halted — "never twice" outranks "stop after a failure": a
23
+ * record already carrying an outcome is never re-run, halted or not.
24
+ * 3. halted before owes — once something has failed definitively the rest
25
+ * are left WITHOUT an outcome on purpose, so a resume can still reach them.
26
+ */
27
+ import type { Execution, StepRecord } from "./types.js";
28
+ import type { Workflow } from "./workflow.js";
29
+ /** What to do with one eligible record. */
30
+ export type UnwindAction =
31
+ /** Already has an outcome, or owes none. Move on, nothing to record. */
32
+ {
33
+ kind: 'skip';
34
+ reason: 'already-settled' | 'owes-no-outcome';
35
+ }
36
+ /** A previous failure stopped the chain. Leave the rest untouched. */
37
+ | {
38
+ kind: 'stop';
39
+ }
40
+ /**
41
+ * This record already FAILED and is not being retried. The chain is still blocked
42
+ * here, so the pass must stop rather than walk past it.
43
+ */
44
+ | {
45
+ kind: 'halt-failed';
46
+ }
47
+ /** The step is gone from the workflow. Record why and stop the chain. */
48
+ | {
49
+ kind: 'halt-vanished';
50
+ error: string;
51
+ }
52
+ /** Roll back a nested workflow by running the child's own unwind. */
53
+ | {
54
+ kind: 'unwind-child';
55
+ }
56
+ /** Run this step's compensate handler, bounded by `timeoutMs`. */
57
+ | {
58
+ kind: 'compensate';
59
+ timeoutMs: number;
60
+ };
61
+ /** Bound applied to a reversal whose step declined to set one (`timeout: 0`). */
62
+ export declare const DEFAULT_COMPENSATE_TIMEOUT_MS = 30000;
63
+ /**
64
+ * Decide what to do with `record`, named `name`, in workflow `wf`.
65
+ *
66
+ * `halted` is whether an earlier record in this same pass already failed definitively.
67
+ */
68
+ export declare function decideUnwindAction(wf: Workflow, name: string, record: StepRecord, halted: boolean,
69
+ /**
70
+ * An operator resume. A record that FAILED is retried instead of skipped.
71
+ *
72
+ * This replaced wiping the failed outcome before the pass. The wipe worked and cost
73
+ * more than it bought: the operator's `compensation-failed` record was destroyed on
74
+ * the way in, so a resume that then hit a failing store left a run with the
75
+ * diagnostic gone from disk and nothing saying which reversal had failed. Retrying
76
+ * from a flag leaves the record in place until a real outcome replaces it.
77
+ */
78
+ retryFailed?: boolean): UnwindAction;
79
+ /**
80
+ * Does this step still owe an outcome when the run terminates?
81
+ *
82
+ * Used by `abandonCompensation` to discharge "exactly one outcome per eligible step,
83
+ * never zero" for everything the unwind never reached.
84
+ */
85
+ export declare function owesOutcome(wf: Workflow, name: string, record?: StepRecord): boolean;
86
+ /** Is the pivot committed, making the whole run ineligible for rollback? */
87
+ export declare function isCommitted(exec: Execution): boolean;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * waitFor node execution — parking a run for a human/external signal, and the
3
+ * timeout timers that bound the wait.
4
+ *
5
+ * Split out of the executor because parking is the one node type with a genuinely
6
+ * concurrent counterpart: `signal()` mutates the same row from outside the worker,
7
+ * so every transition here has to be expressed as a claim against the store rather
8
+ * than an in-memory state change. See storeSignals.ts for the ownership rules.
9
+ */
10
+ import type { Queue } from "../queue/queue.js";
11
+ import type { Workflow } from "./workflow.js";
12
+ import type { WorkflowStore } from "./store.js";
13
+ import type { WorkflowEmitter } from "./emitter.js";
14
+ import type { Execution, WorkflowNode } from "./types.js";
15
+ import { type TimerHandle } from "./clock.js";
16
+ /** Largest delay setTimeout accepts before wrapping (2**31-1 ms, ~24.8 days) */
17
+ export declare const MAX_TIMER_MS = 2147483647;
18
+ export interface TimerDeps {
19
+ queue: Queue;
20
+ timers: Map<string, TimerHandle>;
21
+ assertActive: () => void;
22
+ isActive: () => boolean;
23
+ }
24
+ export interface WaitForDeps {
25
+ store: WorkflowStore;
26
+ emitter: WorkflowEmitter | null;
27
+ advance: (exec: Execution, nextIdx: number, wf: Workflow) => Promise<void>;
28
+ compensate: (exec: Execution, wf: Workflow) => Promise<void>;
29
+ scheduleTimeoutCheck: (execId: string, workflowName: string, nodeIdx: number, ms: number) => void;
30
+ updateFn: (exec: Execution) => void;
31
+ assertActive: () => void;
32
+ }
33
+ /**
34
+ * Arm the timer that re-enters a parked node once its wait budget elapses.
35
+ *
36
+ * setTimeout takes a 32-bit signed delay; anything larger wraps to 1ms and fires
37
+ * immediately (`TimeoutOverflowWarning`). Clamping and letting the re-check job
38
+ * re-arm for whatever remains is what makes multi-week approval windows survive
39
+ * (test/repro-workflow-timeout-overflow.test.ts).
40
+ */
41
+ export declare function scheduleTimeoutCheck(deps: TimerDeps, execId: string, workflowName: string, nodeIdx: number, ms: number): void;
42
+ /**
43
+ * Cancel every armed wait timer. Called on engine shutdown: `unref` alone lets a
44
+ * process exit, but a still-armed timer can also fire into a queue that is closing,
45
+ * and a caller that shuts one engine down while keeping the process alive has no
46
+ * other way to release them.
47
+ */
48
+ export declare function clearTimers(timers: Map<string, TimerHandle>): void;
49
+ /**
50
+ * Execute a `waitFor` node: advance if the signal is already there, fail if the wait
51
+ * has expired, otherwise park the run and throw the sentinel so processStep
52
+ * short-circuits without treating the pause as an error.
53
+ */
54
+ export declare function runWaitFor(deps: WaitForDeps, exec: Execution, node: Extract<WorkflowNode, {
55
+ type: 'waitFor';
56
+ }>, idx: number, wf: Workflow): Promise<void>;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Workflow - DSL builder for defining workflow step graphs
3
+ * Pure data structure, no side effects.
4
+ *
5
+ * Supports type-safe step chaining: each .step() narrows the return type
6
+ * so subsequent steps can access previous results without casting.
7
+ */
8
+ import type { WorkflowNode, StepOptions, StepContext, BranchCondition, SubWorkflowOptions, LoopCondition, ForEachItemsExtractor, TypedStepHandler } from "./types.js";
9
+ export { assertNoDuplicateWaitFor, assertNoIndexCollision, unusableEventName, } from "./workflowValidation.js";
10
+ export declare class Workflow<TInput = unknown, TSteps extends Record<string, unknown> = Record<string, unknown>> {
11
+ readonly name: string;
12
+ /**
13
+ * Explicit semantic revision. Bump it when handler or condition behavior changes
14
+ * incompatibly without changing the graph shape.
15
+ */
16
+ readonly revision: string;
17
+ readonly nodes: WorkflowNode[];
18
+ private sealed;
19
+ private sealedHash?;
20
+ constructor(name: string, options?: {
21
+ revision?: string | number;
22
+ });
23
+ /** Freeze this definition and return its durable structural identity. */
24
+ seal(): string;
25
+ private assertMutable;
26
+ /** Add a step to the workflow — return type accumulates into TSteps */
27
+ step<TName extends string, TResult>(name: TName, handler: TypedStepHandler<TInput, TSteps, TResult>, options?: StepOptions<TInput, TSteps & Record<TName, Awaited<TResult>>>): Workflow<TInput, TSteps & Record<TName, Awaited<TResult>>>;
28
+ /** Add a branch point — call .path() after this to define paths */
29
+ branch(condition: BranchCondition<TInput, TSteps>): this;
30
+ /** Define a branch path (must follow a .branch() call) */
31
+ path(name: string, builder: (w: Workflow<TInput, TSteps>) => Workflow<TInput, any>): this;
32
+ /** Run multiple steps in parallel — accumulated types from sub-builder merge into TSteps */
33
+ parallel<TNewSteps extends Record<string, unknown>>(builder: (w: Workflow<TInput, TSteps>) => Workflow<TInput, TSteps & TNewSteps>): Workflow<TInput, TSteps & TNewSteps>;
34
+ /** Call another registered workflow as a step */
35
+ subWorkflow<TName extends string>(name: TName, inputMapper: (ctx: StepContext<TInput, TSteps>) => unknown, options?: SubWorkflowOptions): Workflow<TInput, TSteps & Record<`sub:${TName}`, Record<string, unknown>>>;
36
+ /** Wait for an external signal before continuing */
37
+ waitFor(event: string, options?: {
38
+ timeout?: number;
39
+ }): this;
40
+ /** Repeat steps until condition returns true (checked after each iteration) */
41
+ doUntil(condition: LoopCondition<TInput, TSteps>, builder: (w: Workflow<TInput, TSteps>) => Workflow<TInput, any>, options?: {
42
+ maxIterations?: number;
43
+ }): this;
44
+ /** Repeat steps while condition returns true (checked before each iteration) */
45
+ doWhile(condition: LoopCondition<TInput, TSteps>, builder: (w: Workflow<TInput, TSteps>) => Workflow<TInput, any>, options?: {
46
+ maxIterations?: number;
47
+ }): this;
48
+ /** Iterate over items, executing a step for each */
49
+ forEach<TName extends string, TResult>(items: ForEachItemsExtractor<TInput, TSteps>, name: TName, handler: TypedStepHandler<TInput, TSteps, TResult>, options?: StepOptions<TInput, TSteps> & {
50
+ maxIterations?: number;
51
+ }): Workflow<TInput, TSteps & Record<TName, Awaited<TResult>>>;
52
+ /** Transform step results into a new value stored under the given name */
53
+ map<TName extends string, TResult>(name: TName, transform: (ctx: StepContext<TInput, TSteps>) => TResult): Workflow<TInput, TSteps & Record<TName, Awaited<TResult>>>;
54
+ /**
55
+ * Mark the point of no return.
56
+ *
57
+ * Everything before it stays compensatable; everything after is committed and is
58
+ * never rolled back, however the run ends. Past the pivot the only correct
59
+ * recovery is forward — retry, alert, fix — because there is no semantic inverse
60
+ * for "the welcome email was sent". Declare it explicitly; it is never inferred.
61
+ */
62
+ pivot(): this;
63
+ /**
64
+ * Step names that generate indexed per-iteration records (`name:0`, `name:1`, ...).
65
+ * Loop bodies and forEach steps both do; a plain step never does.
66
+ */
67
+ getIndexedStepNames(): string[];
68
+ /** Get flat list of step names for validation */
69
+ getStepNames(): string[];
70
+ }
@@ -0,0 +1,11 @@
1
+ /** Durable control-flow decision journal. */
2
+ import type { Execution } from "./types.js";
3
+ /**
4
+ * Return an already persisted decision, or evaluate and persist it before the caller
5
+ * performs any effects selected by that decision.
6
+ */
7
+ export declare function resolveDecision<T>(exec: Execution, key: string, evaluate: () => T | Promise<T>, updateFn: (exec: Execution) => void, assertActive: () => void): Promise<T>;
8
+ export declare function branchDecisionKey(nodeIndex: number): string;
9
+ export declare function forEachItemsDecisionKey(stepName: string): string;
10
+ export declare function loopDecisionKey(kind: 'doUntil' | 'doWhile', firstStepName: string, iteration: number): string;
11
+ export declare function subWorkflowInputDecisionKey(nodeIndex: number): string;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Stable workflow-definition identity and sealing.
3
+ *
4
+ * Executions persist the hash produced here. It describes the durable graph, while
5
+ * `revision` lets callers explicitly mark handler/condition changes that cannot be
6
+ * inferred safely from closures.
7
+ */
8
+ import type { WorkflowNode } from "./types.js";
9
+ interface WorkflowDefinitionSource {
10
+ readonly name: string;
11
+ readonly revision: string;
12
+ readonly nodes: WorkflowNode[];
13
+ }
14
+ export declare function workflowDefinitionHash(workflow: WorkflowDefinitionSource): string;
15
+ export declare function sealWorkflowDefinition(workflow: WorkflowDefinitionSource): string;
16
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { WorkflowNode } from "./types.js";
2
+ /** Names that produce indexed records such as `name:0`. */
3
+ export declare function indexedStepNames(nodes: readonly WorkflowNode[]): string[];
4
+ /** Every record name declared by a workflow graph. */
5
+ export declare function stepNames(nodes: readonly WorkflowNode[]): string[];