@temelj/workflow 0.0.0-alpha.1

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 (393) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -0
  3. package/dist/attributes.d.mts +15 -0
  4. package/dist/attributes.mjs +30 -0
  5. package/dist/client/create.d.mts +31 -0
  6. package/dist/client/create.mjs +67 -0
  7. package/dist/client/facades.d.mts +21 -0
  8. package/dist/client/facades.mjs +142 -0
  9. package/dist/client/mod.d.mts +2 -0
  10. package/dist/client/mod.mjs +2 -0
  11. package/dist/client/run-handle.d.mts +66 -0
  12. package/dist/client/run-handle.mjs +156 -0
  13. package/dist/client/worker-options.d.mts +17 -0
  14. package/dist/client/worker-options.mjs +25 -0
  15. package/dist/collection.d.mts +15 -0
  16. package/dist/collection.mjs +33 -0
  17. package/dist/compiled-function.d.mts +27 -0
  18. package/dist/compiled-function.mjs +54 -0
  19. package/dist/definition.d.mts +37 -0
  20. package/dist/definition.mjs +83 -0
  21. package/dist/engine/child-workflow.d.mts +10 -0
  22. package/dist/engine/child-workflow.mjs +333 -0
  23. package/dist/engine/command-identity.d.mts +9 -0
  24. package/dist/engine/command-identity.mjs +14 -0
  25. package/dist/engine/create.d.mts +106 -0
  26. package/dist/engine/create.mjs +402 -0
  27. package/dist/engine/deterministic.d.mts +12 -0
  28. package/dist/engine/deterministic.mjs +102 -0
  29. package/dist/engine/durable-command.d.mts +10 -0
  30. package/dist/engine/durable-command.mjs +17 -0
  31. package/dist/engine/execution-api.d.mts +29 -0
  32. package/dist/engine/execution-api.mjs +33 -0
  33. package/dist/engine/execution-service.d.mts +41 -0
  34. package/dist/engine/execution-service.mjs +288 -0
  35. package/dist/engine/hooks.d.mts +56 -0
  36. package/dist/engine/hooks.mjs +237 -0
  37. package/dist/engine/inspection-api.d.mts +34 -0
  38. package/dist/engine/inspection-api.mjs +77 -0
  39. package/dist/engine/inspection.d.mts +18 -0
  40. package/dist/engine/inspection.mjs +149 -0
  41. package/dist/engine/lifecycle.d.mts +18 -0
  42. package/dist/engine/lifecycle.mjs +38 -0
  43. package/dist/engine/lock-replay.d.mts +30 -0
  44. package/dist/engine/lock-replay.mjs +38 -0
  45. package/dist/engine/lock.d.mts +21 -0
  46. package/dist/engine/lock.mjs +197 -0
  47. package/dist/engine/message.d.mts +47 -0
  48. package/dist/engine/message.mjs +357 -0
  49. package/dist/engine/mod.d.mts +4 -0
  50. package/dist/engine/mod.mjs +2 -0
  51. package/dist/engine/observation.d.mts +35 -0
  52. package/dist/engine/observation.mjs +201 -0
  53. package/dist/engine/recovery.d.mts +26 -0
  54. package/dist/engine/recovery.mjs +92 -0
  55. package/dist/engine/replay.d.mts +41 -0
  56. package/dist/engine/replay.mjs +122 -0
  57. package/dist/engine/retry-policy.d.mts +4 -0
  58. package/dist/engine/retry-policy.mjs +4 -0
  59. package/dist/engine/retry.d.mts +23 -0
  60. package/dist/engine/retry.mjs +75 -0
  61. package/dist/engine/run-data.d.mts +9 -0
  62. package/dist/engine/run-data.mjs +74 -0
  63. package/dist/engine/run-service.d.mts +38 -0
  64. package/dist/engine/run-service.mjs +133 -0
  65. package/dist/engine/run-utils.d.mts +16 -0
  66. package/dist/engine/run-utils.mjs +83 -0
  67. package/dist/engine/schedule.d.mts +25 -0
  68. package/dist/engine/schedule.mjs +207 -0
  69. package/dist/engine/serialization.d.mts +9 -0
  70. package/dist/engine/serialization.mjs +85 -0
  71. package/dist/engine/start-api.d.mts +30 -0
  72. package/dist/engine/start-api.mjs +98 -0
  73. package/dist/engine/state.d.mts +77 -0
  74. package/dist/engine/state.mjs +464 -0
  75. package/dist/engine/step-api.d.mts +9 -0
  76. package/dist/engine/step-api.mjs +25 -0
  77. package/dist/engine/stream.d.mts +55 -0
  78. package/dist/engine/stream.mjs +333 -0
  79. package/dist/engine/summary/active-events.d.mts +34 -0
  80. package/dist/engine/summary/active-events.mjs +69 -0
  81. package/dist/engine/summary/child-workflow-runs.d.mts +24 -0
  82. package/dist/engine/summary/child-workflow-runs.mjs +138 -0
  83. package/dist/engine/summary/child-workflow-waits.d.mts +21 -0
  84. package/dist/engine/summary/child-workflow-waits.mjs +67 -0
  85. package/dist/engine/summary/recovery-child-workflow-waits.d.mts +11 -0
  86. package/dist/engine/summary/recovery-child-workflow-waits.mjs +89 -0
  87. package/dist/engine/summary/recovery-due-runs.d.mts +16 -0
  88. package/dist/engine/summary/recovery-due-runs.mjs +52 -0
  89. package/dist/engine/summary/recovery-failed-runs.d.mts +14 -0
  90. package/dist/engine/summary/recovery-failed-runs.mjs +33 -0
  91. package/dist/engine/summary/recovery-lease-runs.d.mts +16 -0
  92. package/dist/engine/summary/recovery-lease-runs.mjs +69 -0
  93. package/dist/engine/summary/recovery-locks.d.mts +18 -0
  94. package/dist/engine/summary/recovery-locks.mjs +100 -0
  95. package/dist/engine/summary/recovery-message-waits.d.mts +11 -0
  96. package/dist/engine/summary/recovery-message-waits.mjs +74 -0
  97. package/dist/engine/summary/recovery-retry-runs.d.mts +17 -0
  98. package/dist/engine/summary/recovery-retry-runs.mjs +65 -0
  99. package/dist/engine/summary/recovery-run-timestamps.d.mts +13 -0
  100. package/dist/engine/summary/recovery-run-timestamps.mjs +18 -0
  101. package/dist/engine/summary/recovery-runs.d.mts +23 -0
  102. package/dist/engine/summary/recovery-runs.mjs +54 -0
  103. package/dist/engine/summary/recovery-schedules.d.mts +10 -0
  104. package/dist/engine/summary/recovery-schedules.mjs +46 -0
  105. package/dist/engine/summary/recovery-sleep-waits.d.mts +10 -0
  106. package/dist/engine/summary/recovery-sleep-waits.mjs +53 -0
  107. package/dist/engine/summary/recovery-waits.d.mts +21 -0
  108. package/dist/engine/summary/recovery-waits.mjs +29 -0
  109. package/dist/engine/summary/run-availability.d.mts +13 -0
  110. package/dist/engine/summary/run-availability.mjs +37 -0
  111. package/dist/engine/summary/run-cleanup.d.mts +14 -0
  112. package/dist/engine/summary/run-cleanup.mjs +44 -0
  113. package/dist/engine/summary/run-failure.d.mts +14 -0
  114. package/dist/engine/summary/run-failure.mjs +62 -0
  115. package/dist/engine/summary/run-hooks.d.mts +14 -0
  116. package/dist/engine/summary/run-hooks.mjs +63 -0
  117. package/dist/engine/summary/run-lease.d.mts +11 -0
  118. package/dist/engine/summary/run-lease.mjs +64 -0
  119. package/dist/engine/summary/run-message-waits.d.mts +15 -0
  120. package/dist/engine/summary/run-message-waits.mjs +62 -0
  121. package/dist/engine/summary/run-metrics.d.mts +31 -0
  122. package/dist/engine/summary/run-metrics.mjs +93 -0
  123. package/dist/engine/summary/run-retry.d.mts +9 -0
  124. package/dist/engine/summary/run-retry.mjs +69 -0
  125. package/dist/engine/summary/run-sleeps.d.mts +15 -0
  126. package/dist/engine/summary/run-sleeps.mjs +61 -0
  127. package/dist/engine/summary/run-state.d.mts +26 -0
  128. package/dist/engine/summary/run-state.mjs +48 -0
  129. package/dist/engine/summary/run-status.d.mts +16 -0
  130. package/dist/engine/summary/run-status.mjs +35 -0
  131. package/dist/engine/summary/run-streams.d.mts +14 -0
  132. package/dist/engine/summary/run-streams.mjs +46 -0
  133. package/dist/engine/summary/run-transition.d.mts +9 -0
  134. package/dist/engine/summary/run-transition.mjs +39 -0
  135. package/dist/engine/summary/run-workflow.d.mts +9 -0
  136. package/dist/engine/summary/run-workflow.mjs +47 -0
  137. package/dist/engine/summary/step-attempt-active-child-workflows.d.mts +13 -0
  138. package/dist/engine/summary/step-attempt-active-child-workflows.mjs +55 -0
  139. package/dist/engine/summary/step-attempt-active-fields.d.mts +23 -0
  140. package/dist/engine/summary/step-attempt-active-fields.mjs +14 -0
  141. package/dist/engine/summary/step-attempt-active-message-waits.d.mts +12 -0
  142. package/dist/engine/summary/step-attempt-active-message-waits.mjs +47 -0
  143. package/dist/engine/summary/step-attempt-active-sleeps.d.mts +19 -0
  144. package/dist/engine/summary/step-attempt-active-sleeps.mjs +44 -0
  145. package/dist/engine/summary/step-attempt-buckets.d.mts +22 -0
  146. package/dist/engine/summary/step-attempt-buckets.mjs +152 -0
  147. package/dist/engine/summary/step-attempt-failure.d.mts +12 -0
  148. package/dist/engine/summary/step-attempt-failure.mjs +61 -0
  149. package/dist/engine/summary/step-attempt-lifecycle.d.mts +13 -0
  150. package/dist/engine/summary/step-attempt-lifecycle.mjs +19 -0
  151. package/dist/engine/summary/step-attempts.d.mts +11 -0
  152. package/dist/engine/summary/step-attempts.mjs +43 -0
  153. package/dist/engine/summary.d.mts +32 -0
  154. package/dist/engine/summary.mjs +37 -0
  155. package/dist/engine/task.d.mts +6 -0
  156. package/dist/engine/task.mjs +207 -0
  157. package/dist/errors/base.d.mts +99 -0
  158. package/dist/errors/base.mjs +426 -0
  159. package/dist/errors/capability.d.mts +11 -0
  160. package/dist/errors/capability.mjs +23 -0
  161. package/dist/errors/definition.d.mts +21 -0
  162. package/dist/errors/definition.mjs +51 -0
  163. package/dist/errors/details.d.mts +13 -0
  164. package/dist/errors/details.mjs +65 -0
  165. package/dist/errors/failures.d.mts +81 -0
  166. package/dist/errors/failures.mjs +168 -0
  167. package/dist/errors/hook.d.mts +14 -0
  168. package/dist/errors/hook.mjs +30 -0
  169. package/dist/errors/implementation.d.mts +11 -0
  170. package/dist/errors/implementation.mjs +25 -0
  171. package/dist/errors/lock.d.mts +28 -0
  172. package/dist/errors/lock.mjs +70 -0
  173. package/dist/errors/message.d.mts +106 -0
  174. package/dist/errors/message.mjs +122 -0
  175. package/dist/errors/mod.d.mts +17 -0
  176. package/dist/errors/mod.mjs +17 -0
  177. package/dist/errors/record-view.d.mts +11 -0
  178. package/dist/errors/record-view.mjs +24 -0
  179. package/dist/errors/records.d.mts +7 -0
  180. package/dist/errors/records.mjs +280 -0
  181. package/dist/errors/run.d.mts +116 -0
  182. package/dist/errors/run.mjs +232 -0
  183. package/dist/errors/runtime.d.mts +12 -0
  184. package/dist/errors/runtime.mjs +24 -0
  185. package/dist/errors/schedule.d.mts +27 -0
  186. package/dist/errors/schedule.mjs +65 -0
  187. package/dist/errors/step.d.mts +76 -0
  188. package/dist/errors/step.mjs +113 -0
  189. package/dist/errors/stream.d.mts +24 -0
  190. package/dist/errors/stream.mjs +64 -0
  191. package/dist/esbuild.d.mts +7 -0
  192. package/dist/esbuild.mjs +6 -0
  193. package/dist/events/descriptors.d.mts +245 -0
  194. package/dist/events/descriptors.mjs +405 -0
  195. package/dist/events/mod.d.mts +3 -0
  196. package/dist/events/mod.mjs +2 -0
  197. package/dist/history/attempt-key.d.mts +6 -0
  198. package/dist/history/attempt-key.mjs +7 -0
  199. package/dist/history/mod.d.mts +71 -0
  200. package/dist/history/mod.mjs +195 -0
  201. package/dist/history/projection.d.mts +8 -0
  202. package/dist/history/projection.mjs +259 -0
  203. package/dist/history/replay-projection.d.mts +88 -0
  204. package/dist/history/replay-projection.mjs +369 -0
  205. package/dist/history/sequencer.d.mts +16 -0
  206. package/dist/history/sequencer.mjs +78 -0
  207. package/dist/history/step-attempts.d.mts +9 -0
  208. package/dist/history/step-attempts.mjs +50 -0
  209. package/dist/history/timeline.d.mts +16 -0
  210. package/dist/history/timeline.mjs +272 -0
  211. package/dist/history/validator.d.mts +9 -0
  212. package/dist/history/validator.mjs +110 -0
  213. package/dist/inspection/mod.d.mts +5 -0
  214. package/dist/inspection/mod.mjs +3 -0
  215. package/dist/message-options.d.mts +8 -0
  216. package/dist/message-options.mjs +25 -0
  217. package/dist/mod.d.mts +52 -0
  218. package/dist/mod.mjs +26 -0
  219. package/dist/otel/support.d.mts +18 -0
  220. package/dist/otel/support.mjs +102 -0
  221. package/dist/otel.d.mts +30 -0
  222. package/dist/otel.mjs +588 -0
  223. package/dist/pagination.d.mts +25 -0
  224. package/dist/pagination.mjs +73 -0
  225. package/dist/registry.d.mts +20 -0
  226. package/dist/registry.mjs +48 -0
  227. package/dist/rolldown.d.mts +7 -0
  228. package/dist/rolldown.mjs +6 -0
  229. package/dist/rollup.d.mts +7 -0
  230. package/dist/rollup.mjs +6 -0
  231. package/dist/rspack.d.mts +7 -0
  232. package/dist/rspack.mjs +6 -0
  233. package/dist/runtime.d.mts +34 -0
  234. package/dist/runtime.mjs +194 -0
  235. package/dist/step-definition.d.mts +10 -0
  236. package/dist/step-definition.mjs +15 -0
  237. package/dist/store/append-projection.d.mts +15 -0
  238. package/dist/store/append-projection.mjs +26 -0
  239. package/dist/store/capabilities.d.mts +14 -0
  240. package/dist/store/capabilities.mjs +42 -0
  241. package/dist/store/cleanup.d.mts +18 -0
  242. package/dist/store/cleanup.mjs +338 -0
  243. package/dist/store/compaction.d.mts +5 -0
  244. package/dist/store/compaction.mjs +8 -0
  245. package/dist/store/create.d.mts +52 -0
  246. package/dist/store/create.mjs +159 -0
  247. package/dist/store/event-append-project.d.mts +15 -0
  248. package/dist/store/event-append-project.mjs +77 -0
  249. package/dist/store/event-append.d.mts +37 -0
  250. package/dist/store/event-append.mjs +80 -0
  251. package/dist/store/event-history.d.mts +22 -0
  252. package/dist/store/event-history.mjs +75 -0
  253. package/dist/store/event.d.mts +10 -0
  254. package/dist/store/event.mjs +28 -0
  255. package/dist/store/idempotency.d.mts +10 -0
  256. package/dist/store/idempotency.mjs +167 -0
  257. package/dist/store/instrumentation.d.mts +7 -0
  258. package/dist/store/instrumentation.mjs +123 -0
  259. package/dist/store/lock.d.mts +8 -0
  260. package/dist/store/lock.mjs +28 -0
  261. package/dist/store/materialization.d.mts +30 -0
  262. package/dist/store/materialization.mjs +127 -0
  263. package/dist/store/message-index.d.mts +21 -0
  264. package/dist/store/message-index.mjs +121 -0
  265. package/dist/store/mod.d.mts +5 -0
  266. package/dist/store/mod.mjs +4 -0
  267. package/dist/store/query.d.mts +24 -0
  268. package/dist/store/query.mjs +82 -0
  269. package/dist/store/revision.d.mts +4 -0
  270. package/dist/store/revision.mjs +7 -0
  271. package/dist/store/run.d.mts +49 -0
  272. package/dist/store/run.mjs +236 -0
  273. package/dist/store/schedule.d.mts +12 -0
  274. package/dist/store/schedule.mjs +41 -0
  275. package/dist/store/schema.d.mts +14 -0
  276. package/dist/store/schema.mjs +17 -0
  277. package/dist/store/step-attempt.d.mts +14 -0
  278. package/dist/store/step-attempt.mjs +23 -0
  279. package/dist/store/storage-value.d.mts +5 -0
  280. package/dist/store/storage-value.mjs +6 -0
  281. package/dist/store/validation.d.mts +35 -0
  282. package/dist/store/validation.mjs +77 -0
  283. package/dist/store-keys.d.mts +49 -0
  284. package/dist/store-keys.mjs +63 -0
  285. package/dist/telemetry.d.mts +132 -0
  286. package/dist/telemetry.mjs +172 -0
  287. package/dist/temporal.d.mts +23 -0
  288. package/dist/temporal.mjs +59 -0
  289. package/dist/timer.d.mts +12 -0
  290. package/dist/timer.mjs +28 -0
  291. package/dist/types/cleanup.d.mts +112 -0
  292. package/dist/types/cleanup.mjs +22 -0
  293. package/dist/types/client.d.mts +270 -0
  294. package/dist/types/client.mjs +1 -0
  295. package/dist/types/common.d.mts +19 -0
  296. package/dist/types/common.mjs +15 -0
  297. package/dist/types/definition.d.mts +92 -0
  298. package/dist/types/definition.mjs +1 -0
  299. package/dist/types/engine-options.d.mts +76 -0
  300. package/dist/types/engine-options.mjs +1 -0
  301. package/dist/types/engine.d.mts +309 -0
  302. package/dist/types/engine.mjs +1 -0
  303. package/dist/types/error-code.d.mts +256 -0
  304. package/dist/types/error-code.mjs +131 -0
  305. package/dist/types/error.d.mts +236 -0
  306. package/dist/types/error.mjs +48 -0
  307. package/dist/types/events.d.mts +2869 -0
  308. package/dist/types/events.mjs +283 -0
  309. package/dist/types/hook.d.mts +149 -0
  310. package/dist/types/hook.mjs +66 -0
  311. package/dist/types/lock.d.mts +63 -0
  312. package/dist/types/lock.mjs +18 -0
  313. package/dist/types/message-id.d.mts +7 -0
  314. package/dist/types/message-id.mjs +5 -0
  315. package/dist/types/message.d.mts +87 -0
  316. package/dist/types/message.mjs +1 -0
  317. package/dist/types/observation.d.mts +146 -0
  318. package/dist/types/observation.mjs +1 -0
  319. package/dist/types/pagination.d.mts +32 -0
  320. package/dist/types/pagination.mjs +13 -0
  321. package/dist/types/result.d.mts +62 -0
  322. package/dist/types/result.mjs +1 -0
  323. package/dist/types/retry.d.mts +48 -0
  324. package/dist/types/retry.mjs +1 -0
  325. package/dist/types/run-id.d.mts +7 -0
  326. package/dist/types/run-id.mjs +5 -0
  327. package/dist/types/run-list.d.mts +43 -0
  328. package/dist/types/run-list.mjs +1 -0
  329. package/dist/types/run-options.d.mts +86 -0
  330. package/dist/types/run-options.mjs +1 -0
  331. package/dist/types/run.d.mts +355 -0
  332. package/dist/types/run.mjs +207 -0
  333. package/dist/types/runtime.d.mts +143 -0
  334. package/dist/types/runtime.mjs +21 -0
  335. package/dist/types/schedule.d.mts +127 -0
  336. package/dist/types/schedule.mjs +48 -0
  337. package/dist/types/step-attempts.d.mts +326 -0
  338. package/dist/types/step-attempts.mjs +43 -0
  339. package/dist/types/step-id.d.mts +7 -0
  340. package/dist/types/step-id.mjs +5 -0
  341. package/dist/types/step.d.mts +183 -0
  342. package/dist/types/step.mjs +5 -0
  343. package/dist/types/store.d.mts +254 -0
  344. package/dist/types/store.mjs +1 -0
  345. package/dist/types/stream-id.d.mts +7 -0
  346. package/dist/types/stream-id.mjs +5 -0
  347. package/dist/types/stream.d.mts +126 -0
  348. package/dist/types/stream.mjs +1 -0
  349. package/dist/types/summary.d.mts +318 -0
  350. package/dist/types/summary.mjs +1 -0
  351. package/dist/types/telemetry.d.mts +74 -0
  352. package/dist/types/telemetry.mjs +9 -0
  353. package/dist/types/timeline.d.mts +237 -0
  354. package/dist/types/timeline.mjs +1 -0
  355. package/dist/types/vite.d.mts +65 -0
  356. package/dist/types/vite.mjs +1 -0
  357. package/dist/types/worker-id.d.mts +7 -0
  358. package/dist/types/worker-id.mjs +5 -0
  359. package/dist/types/worker.d.mts +94 -0
  360. package/dist/types/worker.mjs +1 -0
  361. package/dist/utility.d.mts +49 -0
  362. package/dist/utility.mjs +122 -0
  363. package/dist/vite/ast.d.mts +23 -0
  364. package/dist/vite/ast.mjs +73 -0
  365. package/dist/vite/error.d.mts +19 -0
  366. package/dist/vite/error.mjs +47 -0
  367. package/dist/vite/generated-name.d.mts +7 -0
  368. package/dist/vite/generated-name.mjs +9 -0
  369. package/dist/vite/manifest.d.mts +7 -0
  370. package/dist/vite/manifest.mjs +106 -0
  371. package/dist/vite/plugin.d.mts +7 -0
  372. package/dist/vite/plugin.mjs +190 -0
  373. package/dist/vite/safety.d.mts +12 -0
  374. package/dist/vite/safety.mjs +96 -0
  375. package/dist/vite/source-edit.d.mts +12 -0
  376. package/dist/vite/source-edit.mjs +44 -0
  377. package/dist/vite/source-map.d.mts +11 -0
  378. package/dist/vite/source-map.mjs +53 -0
  379. package/dist/vite/source.d.mts +7 -0
  380. package/dist/vite/source.mjs +14 -0
  381. package/dist/vite/transform.d.mts +7 -0
  382. package/dist/vite/transform.mjs +405 -0
  383. package/dist/vite.d.mts +6 -0
  384. package/dist/vite.mjs +5 -0
  385. package/dist/webhook.d.mts +16 -0
  386. package/dist/webhook.mjs +17 -0
  387. package/dist/webpack.d.mts +7 -0
  388. package/dist/webpack.mjs +6 -0
  389. package/dist/worker/error.d.mts +11 -0
  390. package/dist/worker/error.mjs +40 -0
  391. package/dist/worker.d.mts +18 -0
  392. package/dist/worker.mjs +427 -0
  393. package/package.json +144 -0
@@ -0,0 +1,132 @@
1
+ import { ObservationEventMap } from "./types/observation.mjs";
2
+ import { RunTelemetryContext, StepTelemetryContext, StorageTelemetryContext, Telemetry, TelemetryContext } from "./types/telemetry.mjs";
3
+ //#region src/telemetry.d.ts
4
+ /** Instrumentation scope used by workflow telemetry adapters. */
5
+ declare const WORKFLOW_INSTRUMENTATION_NAME = "temelj.workflow";
6
+ /** Version of the built-in workflow telemetry instrumentation. */
7
+ declare const WORKFLOW_INSTRUMENTATION_VERSION = "0.1.0";
8
+ /** Stable workflow system identifier used on spans, metrics, and logs. */
9
+ declare const WORKFLOW_SYSTEM = "temelj";
10
+ /** Stable OpenTelemetry span names emitted by `@temelj/workflow`. */
11
+ declare const WORKFLOW_SPAN_NAMES: {
12
+ readonly childWorkflowOperation: "temelj.workflow.child_workflow.operation";
13
+ readonly cleanupOperation: "temelj.workflow.cleanup.operation";
14
+ readonly hookResume: "temelj.workflow.hook.resume";
15
+ readonly messageSend: "temelj.workflow.message.send";
16
+ readonly messageWait: "temelj.workflow.message.wait";
17
+ readonly runExecution: "temelj.workflow.execute";
18
+ readonly scheduleTick: "temelj.workflow.schedule.tick";
19
+ readonly scheduleRunCreate: "temelj.workflow.schedule.run.create";
20
+ readonly sleep: "temelj.workflow.sleep";
21
+ readonly stepExecution: "temelj.workflow.step";
22
+ readonly storageOperation: "temelj.workflow.storage.operation";
23
+ readonly streamOperation: "temelj.workflow.stream.operation";
24
+ readonly workerOperation: "temelj.workflow.worker.operation";
25
+ };
26
+ /** Stable metric names emitted by `@temelj/workflow` telemetry. */
27
+ declare const WORKFLOW_METRIC_NAMES: {
28
+ readonly cleanupDeletedRuns: "temelj.workflow.cleanup.deleted_runs";
29
+ readonly eventsAppended: "temelj.workflow.events.appended";
30
+ readonly hooksResumed: "temelj.workflow.hooks.resumed";
31
+ readonly hookResumeLatency: "temelj.workflow.hooks.resume_latency";
32
+ readonly messageWaitLatency: "temelj.workflow.messages.wait_latency";
33
+ readonly messagesSent: "temelj.workflow.messages.sent";
34
+ readonly pendingToClaimedLatency: "temelj.workflow.run.pending_to_claimed_latency";
35
+ readonly runDuration: "temelj.workflow.run.duration";
36
+ readonly runTransitions: "temelj.workflow.run.transitions";
37
+ readonly runs: "temelj.workflow.runs";
38
+ readonly retryDelay: "temelj.workflow.retry.delay";
39
+ readonly retryExhausted: "temelj.workflow.retry.exhausted";
40
+ readonly retryScheduled: "temelj.workflow.retry.scheduled";
41
+ readonly runWaitingToResumedLatency: "temelj.workflow.run.waiting_to_resumed_latency";
42
+ readonly scheduleDueToRunCreatedLatency: "temelj.workflow.schedule.due_to_run_created_latency";
43
+ readonly stepAttempts: "temelj.workflow.step.attempts";
44
+ readonly stepDuration: "temelj.workflow.step.duration";
45
+ readonly storageOperationDuration: "temelj.workflow.storage.operation.duration";
46
+ readonly storageOperationErrors: "temelj.workflow.storage.operation.errors";
47
+ readonly streamUpdates: "temelj.workflow.stream.updates";
48
+ readonly workerActiveExecutions: "temelj.workflow.worker.active_executions";
49
+ readonly workerClaimFailures: "temelj.workflow.worker.claim_failures";
50
+ readonly workerClaims: "temelj.workflow.worker.claims";
51
+ readonly workerHeartbeatFailures: "temelj.workflow.worker.heartbeat_failures";
52
+ readonly workerLeaseExtensions: "temelj.workflow.worker.lease_extensions";
53
+ readonly workerLeaseReleases: "temelj.workflow.worker.lease_releases";
54
+ };
55
+ /** Stable workflow attribute names used by traces, metrics, and logs. */
56
+ declare const WORKFLOW_ATTRIBUTES: {
57
+ readonly canceled: "workflow.canceled";
58
+ readonly childWorkflowDurationMs: "workflow.child_workflow.duration_ms";
59
+ readonly childWorkflowOperation: "workflow.child_workflow.operation";
60
+ readonly childWorkflowRunId: "workflow.child_workflow.run.id";
61
+ readonly childWorkflowStatus: "workflow.child_workflow.status";
62
+ readonly childWorkflowName: "workflow.child_workflow.name";
63
+ readonly childWorkflowVersion: "workflow.child_workflow.version";
64
+ readonly cleanupCreatedMarkers: "workflow.cleanup.created_markers";
65
+ readonly cleanupDeletedEvents: "workflow.cleanup.deleted_events";
66
+ readonly cleanupDeletedIdempotencyKeys: "workflow.cleanup.deleted_idempotency_keys";
67
+ readonly cleanupDeletedMarkers: "workflow.cleanup.deleted_markers";
68
+ readonly cleanupDeletedMessageIdempotencyKeys: "workflow.cleanup.deleted_message_idempotency_keys";
69
+ readonly cleanupDeletedRuns: "workflow.cleanup.deleted_runs";
70
+ readonly cleanupDeletedStepAttempts: "workflow.cleanup.deleted_step_attempts";
71
+ readonly cleanupDryRun: "workflow.cleanup.dry_run";
72
+ readonly cleanupMatchedRuns: "workflow.cleanup.matched_runs";
73
+ readonly cleanupSource: "workflow.cleanup.source";
74
+ readonly deadlineExceeded: "workflow.deadline.exceeded";
75
+ readonly errorKind: "workflow.error.kind";
76
+ readonly errorRetryable: "workflow.error.retryable";
77
+ readonly eventCategory: "workflow.event.category";
78
+ readonly eventKind: "workflow.event.kind";
79
+ readonly hookKind: "workflow.hook.kind";
80
+ readonly messageId: "workflow.message.id";
81
+ readonly messageSource: "workflow.message.source";
82
+ readonly namespace: "workflow.namespace";
83
+ readonly replay: "workflow.replay";
84
+ readonly retryExhausted: "workflow.retry.exhausted";
85
+ readonly retryReason: "workflow.retry.reason";
86
+ readonly runAttempt: "workflow.run.attempt";
87
+ readonly runId: "workflow.run.id";
88
+ readonly runStatus: "workflow.run.status";
89
+ readonly runTransition: "workflow.run.transition";
90
+ readonly scheduleFireAt: "workflow.schedule.fire_at";
91
+ readonly scheduleId: "workflow.schedule.id";
92
+ readonly scheduleNextAt: "workflow.schedule.next_at";
93
+ readonly scheduleTickedRuns: "workflow.schedule.ticked_runs";
94
+ readonly scheduleTickedSchedules: "workflow.schedule.ticked_schedules";
95
+ readonly sleepActualMs: "workflow.sleep.actual_ms";
96
+ readonly sleepDurationMs: "workflow.sleep.duration_ms";
97
+ readonly sleepUntil: "workflow.sleep.until";
98
+ readonly stepAttempt: "workflow.step.attempt";
99
+ readonly stepId: "workflow.step.id";
100
+ readonly stepKind: "workflow.step.kind";
101
+ readonly stepName: "workflow.step.name";
102
+ readonly stepStatus: "workflow.step.status";
103
+ readonly stepTimeoutAt: "workflow.step.timeout_at";
104
+ readonly storageBackend: "workflow.storage.backend";
105
+ readonly storageOperation: "workflow.storage.operation";
106
+ readonly storageOperationStatus: "workflow.storage.operation.status";
107
+ readonly streamEventKind: "workflow.stream.event.kind";
108
+ readonly streamId: "workflow.stream.id";
109
+ readonly streamIndex: "workflow.stream.index";
110
+ readonly streamStatus: "workflow.stream.status";
111
+ readonly system: "workflow.system";
112
+ readonly workerId: "workflow.worker.id";
113
+ readonly workerOperation: "workflow.worker.operation";
114
+ readonly workerOperationStatus: "workflow.worker.operation.status";
115
+ readonly workflowName: "workflow.name";
116
+ readonly workflowVersion: "workflow.version";
117
+ };
118
+ /** OpenTelemetry semantic convention attributes used when workflow operations act like messages. */
119
+ declare const WORKFLOW_MESSAGING_ATTRIBUTES: {
120
+ readonly destinationName: "messaging.destination.name";
121
+ readonly messageId: "messaging.message.id";
122
+ readonly operationName: "messaging.operation.name";
123
+ readonly operationType: "messaging.operation.type";
124
+ readonly system: "messaging.system";
125
+ };
126
+ declare function captureTelemetryContext(telemetry: Telemetry | undefined): TelemetryContext | undefined;
127
+ declare function withRunTelemetry<T>(telemetry: Telemetry | undefined, context: RunTelemetryContext, callback: () => Promise<T>): Promise<T>;
128
+ declare function withStepTelemetry<T>(telemetry: Telemetry | undefined, context: StepTelemetryContext, callback: () => Promise<T>): Promise<T>;
129
+ declare function withStorageTelemetry<T>(telemetry: Telemetry | undefined, context: StorageTelemetryContext, callback: () => Promise<T>): Promise<T>;
130
+ declare function observeTelemetry<Key extends keyof ObservationEventMap>(telemetry: Telemetry | undefined, name: Key, payload: ObservationEventMap[Key]): void;
131
+ //#endregion
132
+ export { WORKFLOW_ATTRIBUTES, WORKFLOW_INSTRUMENTATION_NAME, WORKFLOW_INSTRUMENTATION_VERSION, WORKFLOW_MESSAGING_ATTRIBUTES, WORKFLOW_METRIC_NAMES, WORKFLOW_SPAN_NAMES, WORKFLOW_SYSTEM, captureTelemetryContext, observeTelemetry, withRunTelemetry, withStepTelemetry, withStorageTelemetry };
@@ -0,0 +1,172 @@
1
+ //#region src/telemetry.ts
2
+ /** Instrumentation scope used by workflow telemetry adapters. */
3
+ const WORKFLOW_INSTRUMENTATION_NAME = "temelj.workflow";
4
+ /** Version of the built-in workflow telemetry instrumentation. */
5
+ const WORKFLOW_INSTRUMENTATION_VERSION = "0.1.0";
6
+ /** Stable workflow system identifier used on spans, metrics, and logs. */
7
+ const WORKFLOW_SYSTEM = "temelj";
8
+ /** Stable OpenTelemetry span names emitted by `@temelj/workflow`. */
9
+ const WORKFLOW_SPAN_NAMES = {
10
+ childWorkflowOperation: "temelj.workflow.child_workflow.operation",
11
+ cleanupOperation: "temelj.workflow.cleanup.operation",
12
+ hookResume: "temelj.workflow.hook.resume",
13
+ messageSend: "temelj.workflow.message.send",
14
+ messageWait: "temelj.workflow.message.wait",
15
+ runExecution: "temelj.workflow.execute",
16
+ scheduleTick: "temelj.workflow.schedule.tick",
17
+ scheduleRunCreate: "temelj.workflow.schedule.run.create",
18
+ sleep: "temelj.workflow.sleep",
19
+ stepExecution: "temelj.workflow.step",
20
+ storageOperation: "temelj.workflow.storage.operation",
21
+ streamOperation: "temelj.workflow.stream.operation",
22
+ workerOperation: "temelj.workflow.worker.operation"
23
+ };
24
+ /** Stable metric names emitted by `@temelj/workflow` telemetry. */
25
+ const WORKFLOW_METRIC_NAMES = {
26
+ cleanupDeletedRuns: "temelj.workflow.cleanup.deleted_runs",
27
+ eventsAppended: "temelj.workflow.events.appended",
28
+ hooksResumed: "temelj.workflow.hooks.resumed",
29
+ hookResumeLatency: "temelj.workflow.hooks.resume_latency",
30
+ messageWaitLatency: "temelj.workflow.messages.wait_latency",
31
+ messagesSent: "temelj.workflow.messages.sent",
32
+ pendingToClaimedLatency: "temelj.workflow.run.pending_to_claimed_latency",
33
+ runDuration: "temelj.workflow.run.duration",
34
+ runTransitions: "temelj.workflow.run.transitions",
35
+ runs: "temelj.workflow.runs",
36
+ retryDelay: "temelj.workflow.retry.delay",
37
+ retryExhausted: "temelj.workflow.retry.exhausted",
38
+ retryScheduled: "temelj.workflow.retry.scheduled",
39
+ runWaitingToResumedLatency: "temelj.workflow.run.waiting_to_resumed_latency",
40
+ scheduleDueToRunCreatedLatency: "temelj.workflow.schedule.due_to_run_created_latency",
41
+ stepAttempts: "temelj.workflow.step.attempts",
42
+ stepDuration: "temelj.workflow.step.duration",
43
+ storageOperationDuration: "temelj.workflow.storage.operation.duration",
44
+ storageOperationErrors: "temelj.workflow.storage.operation.errors",
45
+ streamUpdates: "temelj.workflow.stream.updates",
46
+ workerActiveExecutions: "temelj.workflow.worker.active_executions",
47
+ workerClaimFailures: "temelj.workflow.worker.claim_failures",
48
+ workerClaims: "temelj.workflow.worker.claims",
49
+ workerHeartbeatFailures: "temelj.workflow.worker.heartbeat_failures",
50
+ workerLeaseExtensions: "temelj.workflow.worker.lease_extensions",
51
+ workerLeaseReleases: "temelj.workflow.worker.lease_releases"
52
+ };
53
+ /** Stable workflow attribute names used by traces, metrics, and logs. */
54
+ const WORKFLOW_ATTRIBUTES = {
55
+ canceled: "workflow.canceled",
56
+ childWorkflowDurationMs: "workflow.child_workflow.duration_ms",
57
+ childWorkflowOperation: "workflow.child_workflow.operation",
58
+ childWorkflowRunId: "workflow.child_workflow.run.id",
59
+ childWorkflowStatus: "workflow.child_workflow.status",
60
+ childWorkflowName: "workflow.child_workflow.name",
61
+ childWorkflowVersion: "workflow.child_workflow.version",
62
+ cleanupCreatedMarkers: "workflow.cleanup.created_markers",
63
+ cleanupDeletedEvents: "workflow.cleanup.deleted_events",
64
+ cleanupDeletedIdempotencyKeys: "workflow.cleanup.deleted_idempotency_keys",
65
+ cleanupDeletedMarkers: "workflow.cleanup.deleted_markers",
66
+ cleanupDeletedMessageIdempotencyKeys: "workflow.cleanup.deleted_message_idempotency_keys",
67
+ cleanupDeletedRuns: "workflow.cleanup.deleted_runs",
68
+ cleanupDeletedStepAttempts: "workflow.cleanup.deleted_step_attempts",
69
+ cleanupDryRun: "workflow.cleanup.dry_run",
70
+ cleanupMatchedRuns: "workflow.cleanup.matched_runs",
71
+ cleanupSource: "workflow.cleanup.source",
72
+ deadlineExceeded: "workflow.deadline.exceeded",
73
+ errorKind: "workflow.error.kind",
74
+ errorRetryable: "workflow.error.retryable",
75
+ eventCategory: "workflow.event.category",
76
+ eventKind: "workflow.event.kind",
77
+ hookKind: "workflow.hook.kind",
78
+ messageId: "workflow.message.id",
79
+ messageSource: "workflow.message.source",
80
+ namespace: "workflow.namespace",
81
+ replay: "workflow.replay",
82
+ retryExhausted: "workflow.retry.exhausted",
83
+ retryReason: "workflow.retry.reason",
84
+ runAttempt: "workflow.run.attempt",
85
+ runId: "workflow.run.id",
86
+ runStatus: "workflow.run.status",
87
+ runTransition: "workflow.run.transition",
88
+ scheduleFireAt: "workflow.schedule.fire_at",
89
+ scheduleId: "workflow.schedule.id",
90
+ scheduleNextAt: "workflow.schedule.next_at",
91
+ scheduleTickedRuns: "workflow.schedule.ticked_runs",
92
+ scheduleTickedSchedules: "workflow.schedule.ticked_schedules",
93
+ sleepActualMs: "workflow.sleep.actual_ms",
94
+ sleepDurationMs: "workflow.sleep.duration_ms",
95
+ sleepUntil: "workflow.sleep.until",
96
+ stepAttempt: "workflow.step.attempt",
97
+ stepId: "workflow.step.id",
98
+ stepKind: "workflow.step.kind",
99
+ stepName: "workflow.step.name",
100
+ stepStatus: "workflow.step.status",
101
+ stepTimeoutAt: "workflow.step.timeout_at",
102
+ storageBackend: "workflow.storage.backend",
103
+ storageOperation: "workflow.storage.operation",
104
+ storageOperationStatus: "workflow.storage.operation.status",
105
+ streamEventKind: "workflow.stream.event.kind",
106
+ streamId: "workflow.stream.id",
107
+ streamIndex: "workflow.stream.index",
108
+ streamStatus: "workflow.stream.status",
109
+ system: "workflow.system",
110
+ workerId: "workflow.worker.id",
111
+ workerOperation: "workflow.worker.operation",
112
+ workerOperationStatus: "workflow.worker.operation.status",
113
+ workflowName: "workflow.name",
114
+ workflowVersion: "workflow.version"
115
+ };
116
+ /** OpenTelemetry semantic convention attributes used when workflow operations act like messages. */
117
+ const WORKFLOW_MESSAGING_ATTRIBUTES = {
118
+ destinationName: "messaging.destination.name",
119
+ messageId: "messaging.message.id",
120
+ operationName: "messaging.operation.name",
121
+ operationType: "messaging.operation.type",
122
+ system: "messaging.system"
123
+ };
124
+ function captureTelemetryContext(telemetry) {
125
+ try {
126
+ return telemetry?.captureContext?.();
127
+ } catch {
128
+ return;
129
+ }
130
+ }
131
+ async function withRunTelemetry(telemetry, context, callback) {
132
+ if (telemetry?.withRunExecution === void 0) return await callback();
133
+ return await withTelemetry((wrappedCallback) => telemetry.withRunExecution(context, wrappedCallback), callback);
134
+ }
135
+ async function withStepTelemetry(telemetry, context, callback) {
136
+ if (telemetry?.withStepExecution === void 0) return await callback();
137
+ return await withTelemetry((wrappedCallback) => telemetry.withStepExecution(context, wrappedCallback), callback);
138
+ }
139
+ async function withStorageTelemetry(telemetry, context, callback) {
140
+ if (telemetry?.withStorageOperation === void 0) return await callback();
141
+ return await withTelemetry((wrappedCallback) => telemetry.withStorageOperation(context, wrappedCallback), callback);
142
+ }
143
+ function observeTelemetry(telemetry, name, payload) {
144
+ try {
145
+ telemetry?.observe?.(name, payload);
146
+ } catch {
147
+ return;
148
+ }
149
+ }
150
+ const UNSET = Symbol("workflow telemetry unset");
151
+ async function withTelemetry(runWithTelemetry, callback) {
152
+ let result = UNSET;
153
+ let callbackError = UNSET;
154
+ const wrappedCallback = async () => {
155
+ try {
156
+ result = await callback();
157
+ return result;
158
+ } catch (error) {
159
+ callbackError = error;
160
+ throw error;
161
+ }
162
+ };
163
+ try {
164
+ return await runWithTelemetry(wrappedCallback);
165
+ } catch {
166
+ if (callbackError !== UNSET) throw callbackError;
167
+ if (result !== UNSET) return result;
168
+ return await callback();
169
+ }
170
+ }
171
+ //#endregion
172
+ export { WORKFLOW_ATTRIBUTES, WORKFLOW_INSTRUMENTATION_NAME, WORKFLOW_INSTRUMENTATION_VERSION, WORKFLOW_MESSAGING_ATTRIBUTES, WORKFLOW_METRIC_NAMES, WORKFLOW_SPAN_NAMES, WORKFLOW_SYSTEM, captureTelemetryContext, observeTelemetry, withRunTelemetry, withStepTelemetry, withStorageTelemetry };
@@ -0,0 +1,23 @@
1
+ //#region src/temporal.d.ts
2
+ /** Returns a non-negative millisecond duration between two instants. */
3
+ declare function durationBetweenMilliseconds(from: Temporal.Instant, to: Temporal.Instant): number;
4
+ /** Returns a non-negative millisecond duration between optional instants. */
5
+ declare function optionalDurationBetweenMilliseconds(from: Temporal.Instant | undefined, to: Temporal.Instant | undefined): number | undefined;
6
+ /** Returns a non-negative Temporal duration between two instants. */
7
+ declare function durationBetween(from: Temporal.Instant, to: Temporal.Instant): Temporal.Duration;
8
+ /** Returns whether a timestamp falls inside an inclusive optional instant range. */
9
+ declare function matchesTimestampRange(timestamp: Temporal.Instant, from: Temporal.Instant | undefined, to: Temporal.Instant | undefined): boolean;
10
+ /** Returns whether an optional timestamp falls inside an inclusive optional instant range. */
11
+ declare function matchesOptionalTimestampRange(timestamp: Temporal.Instant | undefined, from: Temporal.Instant | undefined, to: Temporal.Instant | undefined): boolean;
12
+ /** Returns whether an optional duration falls inside an inclusive optional duration range. */
13
+ declare function matchesOptionalDurationRange(value: Temporal.Duration | undefined, from: Temporal.Duration | undefined, to: Temporal.Duration | undefined): boolean;
14
+ /** Compares optional timestamps, sorting present timestamps before undefined values. */
15
+ declare function compareOptionalTimestamps(left: Temporal.Instant | undefined, right: Temporal.Instant | undefined): number;
16
+ /** Returns the earlier of two optional timestamps. */
17
+ declare function earliestOptionalTimestamp(current: Temporal.Instant | undefined, next: Temporal.Instant | undefined): Temporal.Instant | undefined;
18
+ /** Returns the later of two optional timestamps. */
19
+ declare function latestOptionalTimestamp(current: Temporal.Instant | undefined, next: Temporal.Instant | undefined): Temporal.Instant | undefined;
20
+ /** Returns whether `next` should replace `current` as the earliest defined instant. */
21
+ declare function shouldReplaceWorkflowEarliestDefinedInstant(current: Temporal.Instant | undefined, next: Temporal.Instant | undefined): boolean;
22
+ //#endregion
23
+ export { compareOptionalTimestamps, durationBetween, durationBetweenMilliseconds, earliestOptionalTimestamp, latestOptionalTimestamp, matchesOptionalDurationRange, matchesOptionalTimestampRange, matchesTimestampRange, optionalDurationBetweenMilliseconds, shouldReplaceWorkflowEarliestDefinedInstant };
@@ -0,0 +1,59 @@
1
+ //#region src/temporal.ts
2
+ /** Returns a non-negative millisecond duration between two instants. */
3
+ function durationBetweenMilliseconds(from, to) {
4
+ return Math.max(0, to.epochMilliseconds - from.epochMilliseconds);
5
+ }
6
+ /** Returns a non-negative millisecond duration between optional instants. */
7
+ function optionalDurationBetweenMilliseconds(from, to) {
8
+ if (from === void 0 || to === void 0) return;
9
+ return durationBetweenMilliseconds(from, to);
10
+ }
11
+ /** Returns a non-negative Temporal duration between two instants. */
12
+ function durationBetween(from, to) {
13
+ return Temporal.Duration.from({ milliseconds: durationBetweenMilliseconds(from, to) });
14
+ }
15
+ /** Returns whether a timestamp falls inside an inclusive optional instant range. */
16
+ function matchesTimestampRange(timestamp, from, to) {
17
+ if (from === void 0 && to === void 0) return true;
18
+ return (from === void 0 || Temporal.Instant.compare(timestamp, from) >= 0) && (to === void 0 || Temporal.Instant.compare(timestamp, to) <= 0);
19
+ }
20
+ /** Returns whether an optional timestamp falls inside an inclusive optional instant range. */
21
+ function matchesOptionalTimestampRange(timestamp, from, to) {
22
+ if (from === void 0 && to === void 0) return true;
23
+ if (timestamp === void 0) return false;
24
+ return matchesTimestampRange(timestamp, from, to);
25
+ }
26
+ /** Returns whether an optional duration falls inside an inclusive optional duration range. */
27
+ function matchesOptionalDurationRange(value, from, to) {
28
+ if (from === void 0 && to === void 0) return true;
29
+ if (value === void 0) return false;
30
+ const current = value.total({ unit: "millisecond" });
31
+ const lower = from === void 0 ? void 0 : from.total({ unit: "millisecond" });
32
+ const upper = to === void 0 ? void 0 : to.total({ unit: "millisecond" });
33
+ return (lower === void 0 || current >= lower) && (upper === void 0 || current <= upper);
34
+ }
35
+ /** Compares optional timestamps, sorting present timestamps before undefined values. */
36
+ function compareOptionalTimestamps(left, right) {
37
+ if (left !== void 0 && right !== void 0) return Temporal.Instant.compare(left, right);
38
+ if (left !== void 0) return -1;
39
+ if (right !== void 0) return 1;
40
+ return 0;
41
+ }
42
+ /** Returns the earlier of two optional timestamps. */
43
+ function earliestOptionalTimestamp(current, next) {
44
+ if (next === void 0) return current;
45
+ if (current === void 0) return next;
46
+ return Temporal.Instant.compare(next, current) < 0 ? next : current;
47
+ }
48
+ /** Returns the later of two optional timestamps. */
49
+ function latestOptionalTimestamp(current, next) {
50
+ if (next === void 0) return current;
51
+ if (current === void 0) return next;
52
+ return Temporal.Instant.compare(next, current) > 0 ? next : current;
53
+ }
54
+ /** Returns whether `next` should replace `current` as the earliest defined instant. */
55
+ function shouldReplaceWorkflowEarliestDefinedInstant(current, next) {
56
+ return next !== void 0 && (current === void 0 || Temporal.Instant.compare(next, current) < 0);
57
+ }
58
+ //#endregion
59
+ export { compareOptionalTimestamps, durationBetween, durationBetweenMilliseconds, earliestOptionalTimestamp, latestOptionalTimestamp, matchesOptionalDurationRange, matchesOptionalTimestampRange, matchesTimestampRange, optionalDurationBetweenMilliseconds, shouldReplaceWorkflowEarliestDefinedInstant };
@@ -0,0 +1,12 @@
1
+ import { TimerDelay } from "./types/common.mjs";
2
+ //#region src/timer.d.ts
3
+ declare const MAX_TIMER_DELAY: number;
4
+ /** Runtime timer handle returned by setTimeout. */
5
+ type TimeoutHandle = ReturnType<typeof setTimeout>;
6
+ /** Runtime interval handle returned by setInterval. */
7
+ type IntervalHandle = ReturnType<typeof setInterval>;
8
+ declare function nonNegativeTimerDelay(duration: Temporal.Duration, label: string, maximumDelay?: number): TimerDelay;
9
+ declare function positiveTimerDelay(duration: Temporal.Duration, label: string, maximumDelay?: number): TimerDelay;
10
+ declare function sleep(duration: number): Promise<void>;
11
+ //#endregion
12
+ export { IntervalHandle, MAX_TIMER_DELAY, TimeoutHandle, nonNegativeTimerDelay, positiveTimerDelay, sleep };
package/dist/timer.mjs ADDED
@@ -0,0 +1,28 @@
1
+ import { WorkflowOptionsError } from "./errors/base.mjs";
2
+ import { durationTotal, isNonNegativeSafeInteger, isPositiveSafeInteger } from "./utility.mjs";
3
+ import "./errors/mod.mjs";
4
+ //#region src/timer.ts
5
+ const MAX_TIMER_DELAY = 2 ** 31 - 1;
6
+ function nonNegativeTimerDelay(duration, label, maximumDelay = MAX_TIMER_DELAY) {
7
+ const delay = durationTotal(duration);
8
+ if (!isNonNegativeSafeInteger(delay)) WorkflowOptionsError.nonNegativeDuration(label);
9
+ return {
10
+ duration,
11
+ clampedDelay: Math.min(delay, maximumDelay)
12
+ };
13
+ }
14
+ function positiveTimerDelay(duration, label, maximumDelay = MAX_TIMER_DELAY) {
15
+ const delay = durationTotal(duration);
16
+ if (!isPositiveSafeInteger(delay)) WorkflowOptionsError.positiveDuration(label);
17
+ return {
18
+ duration,
19
+ clampedDelay: Math.min(delay, maximumDelay)
20
+ };
21
+ }
22
+ async function sleep(duration) {
23
+ await new Promise((resolve) => {
24
+ setTimeout(resolve, Math.min(duration, MAX_TIMER_DELAY));
25
+ });
26
+ }
27
+ //#endregion
28
+ export { MAX_TIMER_DELAY, nonNegativeTimerDelay, positiveTimerDelay, sleep };
@@ -0,0 +1,112 @@
1
+ import { RunId } from "./run-id.mjs";
2
+ import { StepId } from "./step-id.mjs";
3
+ import { WorkflowTerminalRunStatus } from "./run.mjs";
4
+ import { z } from "zod";
5
+ //#region src/types/cleanup.d.ts
6
+ declare const workflowCleanupModeSchema: z.ZodLiteral<"best_effort">;
7
+ declare const workflowCleanupMarkerRecordSchema: z.ZodObject<{
8
+ mode: z.ZodLiteral<"best_effort">;
9
+ runId: z.ZodString;
10
+ workflowName: z.ZodString;
11
+ workflowVersion: z.ZodOptional<z.ZodString>;
12
+ status: z.ZodEnum<{
13
+ canceled: "canceled";
14
+ completed: "completed";
15
+ failed: "failed";
16
+ }>;
17
+ createdAt: z.ZodCustom<Temporal.Instant, Temporal.Instant>;
18
+ finishedAt: z.ZodCustom<Temporal.Instant, Temporal.Instant>;
19
+ cleanupStartedAt: z.ZodCustom<Temporal.Instant, Temporal.Instant>;
20
+ events: z.ZodNumber;
21
+ stepAttempts: z.ZodNumber;
22
+ idempotencyKeys: z.ZodNumber;
23
+ messageIdempotencyKeys: z.ZodNumber;
24
+ }, z.core.$strip>;
25
+ /** Cleanup strategy used when deleting terminal run data from the store. */
26
+ type CleanupMode = "best_effort";
27
+ /** Options for workflow cleanup runs. */
28
+ interface CleanupRunsOptions extends WorkflowCleanupRunFilterOptions {
29
+ readonly finishedAtBefore: Temporal.Instant;
30
+ }
31
+ /** Status filter accepted by workflow cleanup operations. */
32
+ type CleanupStatusFilter = WorkflowTerminalRunStatus | readonly WorkflowTerminalRunStatus[];
33
+ /** Options for workflow retention policy. */
34
+ interface RetentionPolicyOptions extends WorkflowCleanupRunFilterOptions {
35
+ readonly olderThan: Temporal.Duration;
36
+ readonly now?: Temporal.Instant;
37
+ }
38
+ interface WorkflowCleanupRunFilterOptions {
39
+ readonly status?: CleanupStatusFilter;
40
+ readonly workflowName?: string;
41
+ readonly workflowVersion?: string;
42
+ readonly idempotencyKey?: string;
43
+ readonly parentRunId?: RunId;
44
+ readonly parentStepId?: StepId;
45
+ readonly parentStepName?: string;
46
+ readonly parentStepAttempt?: number;
47
+ readonly dryRun?: boolean;
48
+ readonly limit?: number;
49
+ }
50
+ /** Stored record for workflow cleanup marker. */
51
+ interface CleanupMarkerRecord {
52
+ readonly mode: CleanupMode;
53
+ readonly runId: RunId;
54
+ readonly workflowName: string;
55
+ readonly workflowVersion?: string;
56
+ readonly status: WorkflowTerminalRunStatus;
57
+ readonly createdAt: Temporal.Instant;
58
+ readonly finishedAt: Temporal.Instant;
59
+ readonly cleanupStartedAt: Temporal.Instant;
60
+ readonly events: number;
61
+ readonly stepAttempts: number;
62
+ readonly idempotencyKeys: number;
63
+ readonly messageIdempotencyKeys: number;
64
+ }
65
+ /** Result returned by workflow cleanup runs. */
66
+ interface CleanupRunsResult {
67
+ readonly mode: CleanupMode;
68
+ readonly runIds: readonly RunId[];
69
+ readonly runs: readonly CleanupRunResult[];
70
+ readonly dryRun?: boolean;
71
+ readonly matchedRuns?: number;
72
+ readonly matchedEvents?: number;
73
+ readonly matchedStepAttempts?: number;
74
+ readonly matchedIdempotencyKeys?: number;
75
+ readonly matchedMessageIdempotencyKeys?: number;
76
+ readonly deletedRuns: number;
77
+ readonly createdCleanupMarkers: number;
78
+ readonly deletedCleanupMarkers: number;
79
+ readonly deletedEvents: number;
80
+ readonly deletedStepAttempts: number;
81
+ readonly deletedIdempotencyKeys: number;
82
+ readonly deletedMessageIdempotencyKeys: number;
83
+ }
84
+ /** Result returned by workflow cleanup run. */
85
+ interface CleanupRunResult {
86
+ readonly mode: CleanupMode;
87
+ readonly runId: RunId;
88
+ readonly workflowName: string;
89
+ readonly workflowVersion?: string;
90
+ readonly status: WorkflowTerminalRunStatus;
91
+ readonly createdAt: Temporal.Instant;
92
+ readonly updatedAt: Temporal.Instant;
93
+ readonly finishedAt: Temporal.Instant;
94
+ readonly idempotencyKey?: string;
95
+ readonly parentRunId?: RunId;
96
+ readonly parentStepId?: StepId;
97
+ readonly parentStepName?: string;
98
+ readonly parentStepAttempt?: number;
99
+ readonly events: number;
100
+ readonly stepAttempts: number;
101
+ readonly idempotencyKeys: number;
102
+ readonly messageIdempotencyKeys: number;
103
+ readonly cleanupMarkerCreated: boolean;
104
+ readonly cleanupMarkerDeleted: boolean;
105
+ readonly runDeleted: boolean;
106
+ readonly deletedEvents: number;
107
+ readonly deletedStepAttempts: number;
108
+ readonly deletedIdempotencyKeys: number;
109
+ readonly deletedMessageIdempotencyKeys: number;
110
+ }
111
+ //#endregion
112
+ export { CleanupMarkerRecord, CleanupMode, CleanupRunResult, CleanupRunsOptions, CleanupRunsResult, CleanupStatusFilter, RetentionPolicyOptions, workflowCleanupMarkerRecordSchema, workflowCleanupModeSchema };
@@ -0,0 +1,22 @@
1
+ import { nonBlankStringSchema, nonNegativeSafeIntegerSchema, temporalInstantSchema } from "./common.mjs";
2
+ import { runIdSchema } from "./run-id.mjs";
3
+ import { workflowTerminalRunStatusSchema } from "./run.mjs";
4
+ import { z } from "zod";
5
+ //#region src/types/cleanup.ts
6
+ const workflowCleanupModeSchema = z.literal("best_effort");
7
+ const workflowCleanupMarkerRecordSchema = z.object({
8
+ mode: workflowCleanupModeSchema,
9
+ runId: runIdSchema,
10
+ workflowName: nonBlankStringSchema,
11
+ workflowVersion: nonBlankStringSchema.optional(),
12
+ status: workflowTerminalRunStatusSchema,
13
+ createdAt: temporalInstantSchema,
14
+ finishedAt: temporalInstantSchema,
15
+ cleanupStartedAt: temporalInstantSchema,
16
+ events: nonNegativeSafeIntegerSchema,
17
+ stepAttempts: nonNegativeSafeIntegerSchema,
18
+ idempotencyKeys: nonNegativeSafeIntegerSchema,
19
+ messageIdempotencyKeys: nonNegativeSafeIntegerSchema
20
+ });
21
+ //#endregion
22
+ export { workflowCleanupMarkerRecordSchema, workflowCleanupModeSchema };