@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,65 @@
1
+ //#region src/types/vite.d.ts
2
+ /** Kind values for workflow directive. */
3
+ type DirectiveKind = "workflow" | "step";
4
+ /** Describes the workflow transform metadata entry contract. */
5
+ interface TransformMetadataEntry {
6
+ readonly kind: DirectiveKind;
7
+ readonly name: string;
8
+ readonly generatedName: string;
9
+ readonly workflowName: string;
10
+ readonly version?: string;
11
+ }
12
+ /** Describes the workflow transform metadata contract. */
13
+ interface TransformMetadata {
14
+ readonly file: string;
15
+ readonly entries: readonly TransformMetadataEntry[];
16
+ }
17
+ /** Describes the workflow transform manifest function contract. */
18
+ interface TransformManifestFunction {
19
+ readonly kind: DirectiveKind;
20
+ readonly exportName: string;
21
+ readonly localName: string;
22
+ readonly generatedName: string;
23
+ readonly workflowName: string;
24
+ readonly version?: string;
25
+ }
26
+ /** Describes the workflow transform manifest import edge contract. */
27
+ interface TransformManifestImportEdge {
28
+ readonly source: string;
29
+ readonly importName: string;
30
+ readonly localName: string;
31
+ readonly kind: DirectiveKind;
32
+ readonly workflowName: string;
33
+ readonly version?: string;
34
+ }
35
+ /** Describes the workflow transform manifest contract. */
36
+ interface TransformManifest {
37
+ readonly file: string;
38
+ readonly functions: readonly TransformManifestFunction[];
39
+ readonly imports: readonly TransformManifestImportEdge[];
40
+ }
41
+ /** Options for workflow transform. */
42
+ interface TransformOptions {
43
+ readonly root?: string;
44
+ readonly name?: (localName: string, file: string, kind: DirectiveKind) => string;
45
+ readonly version?: string | ((workflowName: string, file: string) => string | undefined);
46
+ readonly manifests?: readonly TransformManifest[];
47
+ readonly sourcemap?: boolean;
48
+ readonly runtimeImport?: string;
49
+ }
50
+ /** Result returned by workflow transform. */
51
+ interface TransformResult {
52
+ readonly code: string;
53
+ readonly map?: unknown;
54
+ readonly metadata: TransformMetadata;
55
+ readonly manifest: TransformManifest;
56
+ }
57
+ /** Options for workflow build-tool plugins. */
58
+ interface WorkflowPluginOptions extends TransformOptions {
59
+ readonly include?: readonly string[];
60
+ readonly exclude?: readonly string[];
61
+ }
62
+ /** Options for workflow Vite plugin. */
63
+ type VitePluginOptions = WorkflowPluginOptions;
64
+ //#endregion
65
+ export { DirectiveKind, TransformManifest, TransformManifestFunction, TransformManifestImportEdge, TransformMetadata, TransformMetadataEntry, TransformOptions, TransformResult, VitePluginOptions, WorkflowPluginOptions };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { z } from "zod";
2
+ //#region src/types/worker-id.d.ts
3
+ declare const workerIdSchema: z.ZodCustom<string, string>;
4
+ /** Non-empty identifier used when a worker claims and heartbeats workflow runs. */
5
+ type WorkerId = string;
6
+ //#endregion
7
+ export { WorkerId, workerIdSchema };
@@ -0,0 +1,5 @@
1
+ import { z } from "zod";
2
+ //#region src/types/worker-id.ts
3
+ const workerIdSchema = z.custom().refine((value) => typeof value === "string" && value.trim().length > 0, "Expected an ID");
4
+ //#endregion
5
+ export { workerIdSchema };
@@ -0,0 +1,94 @@
1
+ import { RunId } from "./run-id.mjs";
2
+ import { WorkflowMissingImplementationRetryConfig } from "./retry.mjs";
3
+ import { RegistryLike } from "./definition.mjs";
4
+ import { WorkerId } from "./worker-id.mjs";
5
+ import { ExecutionResult } from "./result.mjs";
6
+ import { WorkflowAttributeValue, WorkflowRunRecord, WorkflowRunRetryReason, WorkflowRunStatus, WorkflowRunTransitionReason } from "./run.mjs";
7
+ import { WorkflowWorkerEngine } from "./engine.mjs";
8
+ //#region src/types/worker.d.ts
9
+ /** Options for creating a direct workflow worker host. */
10
+ interface CreateWorkflowWorkerOptions {
11
+ readonly engine: WorkflowWorkerEngine;
12
+ readonly registry: RegistryLike;
13
+ readonly workerId?: WorkerId;
14
+ readonly leaseDuration?: Temporal.Duration;
15
+ readonly pollInterval?: Temporal.Duration;
16
+ readonly heartbeatInterval?: Temporal.Duration;
17
+ readonly stopDrainTimeout?: Temporal.Duration;
18
+ readonly missingImplementationRetry?: WorkflowMissingImplementationRetryConfig;
19
+ readonly now?: () => Temporal.Instant;
20
+ }
21
+ /** Describes the workflow worker contract. */
22
+ interface WorkflowWorker {
23
+ /** Claims and processes a specific run by ID. */
24
+ processRun(runId: RunId): Promise<ExecutionResult<unknown>>;
25
+ /** Claims and processes the next available run matching the optional filters. */
26
+ processNextRun(options?: WorkflowWorkerRunFilterOptions): Promise<ExecutionResult<unknown> | undefined>;
27
+ /** Extends the worker lease for a claimed run. */
28
+ extendLease(runId: RunId, options?: WorkflowWorkerLeaseOptions): Promise<WorkflowRunRecord | undefined>;
29
+ /** Releases the worker lease for a claimed run. */
30
+ releaseLease(runId: RunId, options?: WorkflowWorkerLeaseOptions): Promise<WorkflowRunRecord | undefined>;
31
+ /** Runs the worker polling loop until stopped, aborted, or maxRuns is reached. */
32
+ run(options?: WorkflowWorkerRunOptions): Promise<WorkflowWorkerRunResult>;
33
+ /** Stops the worker polling loop and waits for active work to settle. */
34
+ stop(): Promise<void>;
35
+ }
36
+ /** Options for workflow worker lease. */
37
+ interface WorkflowWorkerLeaseOptions {
38
+ readonly attempts?: number;
39
+ }
40
+ /** Run filters accepted by workers; worker identity is supplied by the worker itself. */
41
+ interface WorkflowWorkerRunFilterOptions {
42
+ readonly status?: WorkflowRunStatus | readonly WorkflowRunStatus[];
43
+ readonly workflowName?: string;
44
+ readonly workflowVersion?: string;
45
+ readonly idempotencyKey?: string;
46
+ readonly parentRunId?: string;
47
+ readonly parentStepId?: string;
48
+ readonly parentStepName?: string;
49
+ readonly parentStepAttempt?: number;
50
+ readonly lastTransitionReason?: WorkflowRunTransitionReason | readonly WorkflowRunTransitionReason[];
51
+ readonly createdAtFrom?: Temporal.Instant;
52
+ readonly createdAtTo?: Temporal.Instant;
53
+ readonly updatedAtFrom?: Temporal.Instant;
54
+ readonly updatedAtTo?: Temporal.Instant;
55
+ readonly finishedAtFrom?: Temporal.Instant;
56
+ readonly finishedAtTo?: Temporal.Instant;
57
+ readonly startedAtFrom?: Temporal.Instant;
58
+ readonly startedAtTo?: Temporal.Instant;
59
+ readonly availableAtFrom?: Temporal.Instant;
60
+ readonly availableAtTo?: Temporal.Instant;
61
+ readonly leaseExpiresAtFrom?: Temporal.Instant;
62
+ readonly leaseExpiresAtTo?: Temporal.Instant;
63
+ readonly retryReason?: WorkflowRunRetryReason | readonly WorkflowRunRetryReason[];
64
+ readonly retryAtFrom?: Temporal.Instant;
65
+ readonly retryAtTo?: Temporal.Instant;
66
+ readonly cleanupFinishedAtBefore?: Temporal.Instant;
67
+ readonly attributes?: Readonly<Record<string, WorkflowAttributeValue>>;
68
+ readonly attributeExists?: string | readonly string[];
69
+ readonly attributeMissing?: string | readonly string[];
70
+ readonly limit?: number;
71
+ }
72
+ /** Options for workflow worker run. */
73
+ interface WorkflowWorkerRunOptions extends WorkflowWorkerRunFilterOptions {
74
+ readonly signal?: AbortSignal;
75
+ readonly maxRuns?: number;
76
+ readonly concurrency?: number;
77
+ readonly pollInterval?: Temporal.Duration;
78
+ readonly tickSchedules?: boolean;
79
+ }
80
+ /** Result returned by workflow worker run. */
81
+ interface WorkflowWorkerRunResult {
82
+ readonly processedRuns: number;
83
+ }
84
+ /** Options for workflow wake due runs. */
85
+ interface WorkflowWakeDueRunsOptions extends WorkflowWorkerRunFilterOptions {
86
+ readonly workerId?: string;
87
+ readonly leaseDuration?: Temporal.Duration;
88
+ readonly heartbeatInterval?: Temporal.Duration;
89
+ readonly missingImplementationRetry?: WorkflowMissingImplementationRetryConfig;
90
+ readonly signal?: AbortSignal;
91
+ readonly maxRuns?: number;
92
+ }
93
+ //#endregion
94
+ export { CreateWorkflowWorkerOptions, WorkflowWakeDueRunsOptions, WorkflowWorker, WorkflowWorkerLeaseOptions, WorkflowWorkerRunFilterOptions, WorkflowWorkerRunOptions, WorkflowWorkerRunResult };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
1
+ import { RunId } from "./types/run-id.mjs";
2
+ import { WorkflowStepAttemptRecord } from "./types/step-attempts.mjs";
3
+ import { WorkerId } from "./types/worker-id.mjs";
4
+ import { WorkflowRunRecord, WorkflowRunStatus, WorkflowTerminalRunStatus } from "./types/run.mjs";
5
+ import { EventRecord } from "./types/events.mjs";
6
+ import { WorkflowRunReaderRepository } from "./types/store.mjs";
7
+ import { WorkflowRecordedIdContext } from "./types/engine-options.mjs";
8
+ import { StandardSchemaValidationError } from "@temelj/standard-schema";
9
+ //#region src/utility.d.ts
10
+ /** Converts arbitrary command ID text into a stable segment safe for recorded IDs. */
11
+ declare function sanitizeRecordedIdPart(value: string): string;
12
+ /** Formats standard-schema validation issues into a single human-readable message. */
13
+ declare function formatStandardSchemaIssues(error: StandardSchemaValidationError): string;
14
+ /** Returns the greatest positive safe integer from two optional values. */
15
+ declare function greatestOptionalNumber(current: number | undefined, next: number | undefined): number | undefined;
16
+ /** Returns whether a value is a positive safe integer. */
17
+ declare function isPositiveSafeInteger(value: unknown): value is number;
18
+ /** Returns whether a value is a non-negative safe integer. */
19
+ declare function isNonNegativeSafeInteger(value: unknown): value is number;
20
+ /** Returns the next positive safe integer, or undefined when the input cannot be advanced. */
21
+ declare function nextPositiveSafeInteger(value: number): number | undefined;
22
+ declare function isWorkflowRunStatus(status: string): status is WorkflowRunStatus;
23
+ declare function isActiveWorkflowRunStatus(status: WorkflowRunStatus): boolean;
24
+ declare function isScheduledWorkflowRunStatus(status: WorkflowRunStatus): boolean;
25
+ /** Returns whether a workflow run status is terminal for its current execution attempt. */
26
+ declare function isTerminalWorkflowRunStatus(status: WorkflowRunStatus): status is WorkflowTerminalRunStatus;
27
+ /** Returns whether an event is the terminal lifecycle event matching a run's current status. */
28
+ declare function isTerminalWorkflowLifecycleEventForRun(run: WorkflowRunRecord, event: EventRecord): boolean;
29
+ /** Creates a default worker identifier using the current time and a random suffix. */
30
+ declare function createDefaultWorkerId(): WorkerId;
31
+ /** Returns a duration's total milliseconds, or NaN when Temporal cannot represent it safely. */
32
+ declare function durationTotal(value: Temporal.Duration): number;
33
+ declare function safeDuration(value: number, label: string): number;
34
+ declare function durationAmount(value: Temporal.Duration, label: string): number;
35
+ /** Returns a retry delay in milliseconds and reports invalid numbers as duration errors. */
36
+ declare function resolveSafeRetryDelay(value: number | undefined, label: string): number | undefined;
37
+ declare function nextRunAttempt(value: number | undefined): number;
38
+ declare function limitWorkflowItems<T>(items: readonly T[], limit: number | undefined): readonly T[];
39
+ declare function isAbortError(error: unknown): boolean;
40
+ declare function positiveSafeInteger(value: number, label: string): number;
41
+ declare function resolvePositiveSafeIntegerOption(value: number | undefined, label: string): number | undefined;
42
+ declare function getRequiredRun(store: WorkflowRunReaderRepository, runId: RunId): Promise<WorkflowRunRecord>;
43
+ declare function makeWorkflowRunStepAttemptKey(runId: RunId, attempt: WorkflowStepAttemptRecord): string;
44
+ /** Creates the default workflow run ID factory. */
45
+ declare function createDefaultRunIdFactory(now?: () => Temporal.Instant): () => string;
46
+ /** Creates the default workflow recorded command ID factory. */
47
+ declare function createDefaultWorkflowRecordedIdFactory(createRunId: () => string): (context: WorkflowRecordedIdContext) => string;
48
+ //#endregion
49
+ export { createDefaultRunIdFactory, createDefaultWorkerId, createDefaultWorkflowRecordedIdFactory, durationAmount, durationTotal, formatStandardSchemaIssues, getRequiredRun, greatestOptionalNumber, isAbortError, isActiveWorkflowRunStatus, isNonNegativeSafeInteger, isPositiveSafeInteger, isScheduledWorkflowRunStatus, isTerminalWorkflowLifecycleEventForRun, isTerminalWorkflowRunStatus, isWorkflowRunStatus, limitWorkflowItems, makeWorkflowRunStepAttemptKey, nextPositiveSafeInteger, nextRunAttempt, positiveSafeInteger, resolvePositiveSafeIntegerOption, resolveSafeRetryDelay, safeDuration, sanitizeRecordedIdPart };
@@ -0,0 +1,122 @@
1
+ import { WorkflowOptionsError } from "./errors/base.mjs";
2
+ import { WorkflowDurationError } from "./errors/failures.mjs";
3
+ import { WorkflowRunNotFoundError } from "./errors/run.mjs";
4
+ import { makeWorkflowStepAttemptKey } from "./history/attempt-key.mjs";
5
+ //#region src/utility.ts
6
+ /** Converts arbitrary command ID text into a stable segment safe for recorded IDs. */
7
+ function sanitizeRecordedIdPart(value) {
8
+ const sanitized = value.replaceAll(/[^a-zA-Z0-9_-]/g, "_");
9
+ return sanitized === "" ? "run" : sanitized;
10
+ }
11
+ /** Formats standard-schema validation issues into a single human-readable message. */
12
+ function formatStandardSchemaIssues(error) {
13
+ return error.issues.map((issue) => {
14
+ const path = issue.path?.join(".");
15
+ return path === void 0 || path === "" ? issue.message : `${path}: ${issue.message}`;
16
+ }).join("; ");
17
+ }
18
+ /** Returns the greatest positive safe integer from two optional values. */
19
+ function greatestOptionalNumber(current, next) {
20
+ if (next === void 0 || !isPositiveSafeInteger(next)) return current;
21
+ if (current === void 0) return next;
22
+ return Math.max(current, next);
23
+ }
24
+ /** Returns whether a value is a positive safe integer. */
25
+ function isPositiveSafeInteger(value) {
26
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
27
+ }
28
+ /** Returns whether a value is a non-negative safe integer. */
29
+ function isNonNegativeSafeInteger(value) {
30
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
31
+ }
32
+ /** Returns the next positive safe integer, or undefined when the input cannot be advanced. */
33
+ function nextPositiveSafeInteger(value) {
34
+ return isPositiveSafeInteger(value) && value < Number.MAX_SAFE_INTEGER ? value + 1 : void 0;
35
+ }
36
+ function isWorkflowRunStatus(status) {
37
+ return status === "pending" || status === "running" || status === "waiting" || status === "completed" || status === "failed" || status === "canceled";
38
+ }
39
+ function isActiveWorkflowRunStatus(status) {
40
+ return status === "pending" || status === "running" || status === "waiting";
41
+ }
42
+ function isScheduledWorkflowRunStatus(status) {
43
+ return status === "pending" || status === "waiting";
44
+ }
45
+ /** Returns whether a workflow run status is terminal for its current execution attempt. */
46
+ function isTerminalWorkflowRunStatus(status) {
47
+ return status === "completed" || status === "failed" || status === "canceled";
48
+ }
49
+ /** Returns whether an event is the terminal lifecycle event matching a run's current status. */
50
+ function isTerminalWorkflowLifecycleEventForRun(run, event) {
51
+ return run.status === "completed" && event.kind === "workflow_completed" || run.status === "failed" && event.kind === "workflow_failed";
52
+ }
53
+ /** Creates a default worker identifier using the current time and a random suffix. */
54
+ function createDefaultWorkerId() {
55
+ return `worker_${Temporal.Now.instant().epochMilliseconds.toString(36)}_${Math.random().toString(36).slice(2)}`;
56
+ }
57
+ /** Returns a duration's total milliseconds, or NaN when Temporal cannot represent it safely. */
58
+ function durationTotal(value) {
59
+ const total = value.total({ unit: "millisecond" });
60
+ return Number.isFinite(total) ? total : NaN;
61
+ }
62
+ function safeDuration(value, label) {
63
+ try {
64
+ resolveSafeRetryDelay(value, label);
65
+ } catch (error) {
66
+ if (!(error instanceof WorkflowOptionsError)) throw error;
67
+ WorkflowDurationError.timerSafe(label);
68
+ }
69
+ return value;
70
+ }
71
+ function durationAmount(value, label) {
72
+ if (!(value instanceof Temporal.Duration)) WorkflowDurationError.temporalDuration(label);
73
+ const amount = value.total({ unit: "millisecond" });
74
+ if (!Number.isFinite(amount)) WorkflowDurationError.finite(label);
75
+ return amount;
76
+ }
77
+ /** Returns a retry delay in milliseconds and reports invalid numbers as duration errors. */
78
+ function resolveSafeRetryDelay(value, label) {
79
+ if (value !== void 0 && !Number.isSafeInteger(value)) WorkflowOptionsError.safeDuration(label);
80
+ return value;
81
+ }
82
+ function nextRunAttempt(value) {
83
+ if (value === void 0 || !isNonNegativeSafeInteger(value) || value >= Number.MAX_SAFE_INTEGER) return 1;
84
+ return value + 1;
85
+ }
86
+ function limitWorkflowItems(items, limit) {
87
+ if (limit === void 0) return items;
88
+ return items.slice(0, limit);
89
+ }
90
+ function isAbortError(error) {
91
+ return error instanceof Error && error.name === "AbortError" || error instanceof DOMException && error.name === "AbortError";
92
+ }
93
+ function positiveSafeInteger(value, label) {
94
+ if (!isPositiveSafeInteger(value)) WorkflowDurationError.positiveSafeInteger(label);
95
+ return value;
96
+ }
97
+ function resolvePositiveSafeIntegerOption(value, label) {
98
+ if (value === void 0) return;
99
+ if (!isPositiveSafeInteger(value)) WorkflowOptionsError.positiveSafeInteger(label);
100
+ return value;
101
+ }
102
+ async function getRequiredRun(store, runId) {
103
+ const run = await store.getRun(runId);
104
+ if (run === void 0) WorkflowRunNotFoundError.notFound(runId);
105
+ return run;
106
+ }
107
+ function makeWorkflowRunStepAttemptKey(runId, attempt) {
108
+ return `${runId}:${makeWorkflowStepAttemptKey(attempt.stepId, attempt.attempt)}`;
109
+ }
110
+ /** Creates the default workflow run ID factory. */
111
+ function createDefaultRunIdFactory(now = Temporal.Now.instant) {
112
+ return () => `run_${now().epochMilliseconds.toString(36)}_${randomIdPart()}`;
113
+ }
114
+ /** Creates the default workflow recorded command ID factory. */
115
+ function createDefaultWorkflowRecordedIdFactory(createRunId) {
116
+ return (context) => `wf_${sanitizeRecordedIdPart(context.runId)}_${createRunId()}`;
117
+ }
118
+ function randomIdPart() {
119
+ return Math.random().toString(36).slice(2);
120
+ }
121
+ //#endregion
122
+ export { createDefaultRunIdFactory, createDefaultWorkerId, createDefaultWorkflowRecordedIdFactory, durationAmount, durationTotal, formatStandardSchemaIssues, getRequiredRun, greatestOptionalNumber, isAbortError, isActiveWorkflowRunStatus, isNonNegativeSafeInteger, isPositiveSafeInteger, isScheduledWorkflowRunStatus, isTerminalWorkflowLifecycleEventForRun, isTerminalWorkflowRunStatus, isWorkflowRunStatus, limitWorkflowItems, makeWorkflowRunStepAttemptKey, nextPositiveSafeInteger, nextRunAttempt, positiveSafeInteger, resolvePositiveSafeIntegerOption, resolveSafeRetryDelay, safeDuration, sanitizeRecordedIdPart };
@@ -0,0 +1,23 @@
1
+ import { Node, Program } from "oxc-parser";
2
+ //#region src/vite/ast.d.ts
3
+ type WorkflowAstNode = Node | Program;
4
+ interface WorkflowSourceFile {
5
+ readonly fileName: string;
6
+ readonly text: string;
7
+ readonly program: Program;
8
+ }
9
+ interface WorkflowSpan {
10
+ readonly start: number;
11
+ readonly end: number;
12
+ }
13
+ declare function parseWorkflowSource(fileName: string, text: string): WorkflowSourceFile;
14
+ declare function spanText(sourceFile: WorkflowSourceFile, node: WorkflowSpan): string;
15
+ declare function leadingTriviaStart(text: string, start: number): number;
16
+ declare function lineAndColumnOfPosition(text: string, position: number): {
17
+ readonly line: number;
18
+ readonly column: number;
19
+ };
20
+ declare function visitWorkflowNode(node: WorkflowAstNode, visitor: (node: WorkflowAstNode) => void): void;
21
+ declare function workflowNodeChildren(node: WorkflowAstNode): readonly WorkflowAstNode[];
22
+ //#endregion
23
+ export { WorkflowAstNode, WorkflowSourceFile, WorkflowSpan, leadingTriviaStart, lineAndColumnOfPosition, parseWorkflowSource, spanText, visitWorkflowNode, workflowNodeChildren };
@@ -0,0 +1,73 @@
1
+ import { workflowSourceKindForId } from "./source.mjs";
2
+ import { parseSync } from "oxc-parser";
3
+ //#region src/vite/ast.ts
4
+ const PARSER_OPTIONS_BY_SOURCE_KIND = {
5
+ js: {
6
+ lang: "js",
7
+ astType: "js"
8
+ },
9
+ json: {
10
+ lang: "js",
11
+ astType: "js"
12
+ },
13
+ ts: {
14
+ lang: "ts",
15
+ astType: "ts"
16
+ },
17
+ tsx: {
18
+ lang: "tsx",
19
+ astType: "ts"
20
+ }
21
+ };
22
+ function parseWorkflowSource(fileName, text) {
23
+ const result = parseSync(fileName, text, {
24
+ ...PARSER_OPTIONS_BY_SOURCE_KIND[workflowSourceKindForId(fileName)],
25
+ sourceType: "module"
26
+ });
27
+ if (result.errors.length > 0) throw new Error(result.errors.map((error) => error.message).join("\n"));
28
+ return {
29
+ fileName,
30
+ text,
31
+ program: result.program
32
+ };
33
+ }
34
+ function spanText(sourceFile, node) {
35
+ return sourceFile.text.slice(node.start, node.end);
36
+ }
37
+ function leadingTriviaStart(text, start) {
38
+ let index = start;
39
+ while (index > 0 && /\s/.test(text[index - 1])) index--;
40
+ return index;
41
+ }
42
+ function lineAndColumnOfPosition(text, position) {
43
+ const lines = text.slice(0, position).split(/\r\n|\r|\n/);
44
+ return {
45
+ line: lines.length,
46
+ column: lines.at(-1).length + 1
47
+ };
48
+ }
49
+ function visitWorkflowNode(node, visitor) {
50
+ for (const child of workflowNodeChildren(node)) {
51
+ visitor(child);
52
+ visitWorkflowNode(child, visitor);
53
+ }
54
+ }
55
+ function workflowNodeChildren(node) {
56
+ const children = [];
57
+ for (const [key, value] of Object.entries(node)) {
58
+ if (key === "parent" || key === "decorators" || key === "typeAnnotation" || key === "typeArguments" || key === "typeParameters" || key === "returnType") continue;
59
+ if (isWorkflowAstNode(value)) {
60
+ children.push(value);
61
+ continue;
62
+ }
63
+ if (Array.isArray(value)) {
64
+ for (const item of value) if (isWorkflowAstNode(item)) children.push(item);
65
+ }
66
+ }
67
+ return children;
68
+ }
69
+ function isWorkflowAstNode(value) {
70
+ return typeof value === "object" && value !== null && typeof value.type === "string" && typeof value.start === "number" && typeof value.end === "number";
71
+ }
72
+ //#endregion
73
+ export { leadingTriviaStart, lineAndColumnOfPosition, parseWorkflowSource, spanText, visitWorkflowNode, workflowNodeChildren };
@@ -0,0 +1,19 @@
1
+ //#region src/vite/error.d.ts
2
+ /** Error thrown for transform failures. */
3
+ declare class WorkflowTransformError extends Error {
4
+ constructor(message: string, context?: Function);
5
+ static directiveParametersMustBeIdentifiers(this: void): never;
6
+ static metadataMissing(this: void, name: string): never;
7
+ static directiveFunctionMustBeNamed(this: void): never;
8
+ static directiveFunctionCannotBeGenerator(this: void, directive: string, name: string): never;
9
+ static workflowFunctionMustBeAsync(this: void, name: string): never;
10
+ static directivesMustBeTopLevel(this: void): never;
11
+ static directiveImportsMustBeNamed(this: void, specifier: string): never;
12
+ static directiveReExportsMustBeNamed(this: void, specifier: string): never;
13
+ static nondeterministicGlobal(this: void, workflowName: string, globalName: string, line: number, character: number): never;
14
+ static invalidSourceReplacementRange(this: void, start: number, end: number): never;
15
+ static invalidSourceReadRange(this: void, start: number, end: number): never;
16
+ static overlappingSourceReplacementRanges(this: void, currentStart: number, currentEnd: number, previousStart: number, previousEnd: number): never;
17
+ }
18
+ //#endregion
19
+ export { WorkflowTransformError };
@@ -0,0 +1,47 @@
1
+ //#region src/vite/error.ts
2
+ /** Error thrown for transform failures. */
3
+ var WorkflowTransformError = class WorkflowTransformError extends Error {
4
+ constructor(message, context) {
5
+ super(message);
6
+ this.name = "WorkflowTransformError";
7
+ if (Error.captureStackTrace !== void 0) Error.captureStackTrace(this, context ?? this.constructor);
8
+ }
9
+ static directiveParametersMustBeIdentifiers() {
10
+ throw new WorkflowTransformError("Workflow directive parameters must be identifiers", WorkflowTransformError.directiveParametersMustBeIdentifiers);
11
+ }
12
+ static metadataMissing(name) {
13
+ throw new WorkflowTransformError(`Workflow metadata was not collected for ${name}`, WorkflowTransformError.metadataMissing);
14
+ }
15
+ static directiveFunctionMustBeNamed() {
16
+ throw new WorkflowTransformError("Directive function declarations must be named", WorkflowTransformError.directiveFunctionMustBeNamed);
17
+ }
18
+ static directiveFunctionCannotBeGenerator(directive, name) {
19
+ throw new WorkflowTransformError(`"${directive}" function ${name} cannot be a generator`, WorkflowTransformError.directiveFunctionCannotBeGenerator);
20
+ }
21
+ static workflowFunctionMustBeAsync(name) {
22
+ throw new WorkflowTransformError(`"use workflow" function ${name} must be async`, WorkflowTransformError.workflowFunctionMustBeAsync);
23
+ }
24
+ static directivesMustBeTopLevel() {
25
+ throw new WorkflowTransformError("Workflow directives are only supported on top-level functions", WorkflowTransformError.directivesMustBeTopLevel);
26
+ }
27
+ static directiveImportsMustBeNamed(specifier) {
28
+ throw new WorkflowTransformError(`Workflow directive imports from ${specifier} must use named imports`, WorkflowTransformError.directiveImportsMustBeNamed);
29
+ }
30
+ static directiveReExportsMustBeNamed(specifier) {
31
+ throw new WorkflowTransformError(`Workflow directive re-exports from ${specifier} must use named exports`, WorkflowTransformError.directiveReExportsMustBeNamed);
32
+ }
33
+ static nondeterministicGlobal(workflowName, globalName, line, character) {
34
+ throw new WorkflowTransformError(`"use workflow" function ${workflowName} uses nondeterministic global ${globalName} at ${line}:${character}; use deterministic workflow helpers or durable steps`, WorkflowTransformError.nondeterministicGlobal);
35
+ }
36
+ static invalidSourceReplacementRange(start, end) {
37
+ throw new WorkflowTransformError(`Invalid source replacement range: ${start}..${end}`, WorkflowTransformError.invalidSourceReplacementRange);
38
+ }
39
+ static invalidSourceReadRange(start, end) {
40
+ throw new WorkflowTransformError(`Invalid source read range: ${start}..${end}`, WorkflowTransformError.invalidSourceReadRange);
41
+ }
42
+ static overlappingSourceReplacementRanges(currentStart, currentEnd, previousStart, previousEnd) {
43
+ throw new WorkflowTransformError(`Overlapping source replacement ranges: ${currentStart}..${currentEnd} and ${previousStart}..${previousEnd}`, WorkflowTransformError.overlappingSourceReplacementRanges);
44
+ }
45
+ };
46
+ //#endregion
47
+ export { WorkflowTransformError };
@@ -0,0 +1,7 @@
1
+ //#region src/vite/generated-name.d.ts
2
+ /** Prefix reserved for helper identifiers injected by the workflow transform. */
3
+ declare const GENERATED_PREFIX: string;
4
+ /** Creates a reserved helper identifier for generated workflow transform code. */
5
+ declare function makeGeneratedName(...parts: readonly string[]): string;
6
+ //#endregion
7
+ export { GENERATED_PREFIX, makeGeneratedName };
@@ -0,0 +1,9 @@
1
+ //#region src/vite/generated-name.ts
2
+ /** Prefix reserved for helper identifiers injected by the workflow transform. */
3
+ const GENERATED_PREFIX = "__temelj";
4
+ /** Creates a reserved helper identifier for generated workflow transform code. */
5
+ function makeGeneratedName(...parts) {
6
+ return [GENERATED_PREFIX, ...parts].join("_");
7
+ }
8
+ //#endregion
9
+ export { GENERATED_PREFIX, makeGeneratedName };
@@ -0,0 +1,7 @@
1
+ import { TransformManifest, TransformManifestFunction, TransformManifestImportEdge } from "../types/vite.mjs";
2
+ import { Program } from "oxc-parser";
3
+ //#region src/vite/manifest.d.ts
4
+ declare function collectImportedStepBindings(sourceFile: Program, file: string, manifests: readonly TransformManifest[]): ReadonlyMap<string, TransformManifestImportEdge>;
5
+ declare function collectReExportedManifestFunctions(sourceFile: Program, file: string, manifests: readonly TransformManifest[]): readonly TransformManifestFunction[];
6
+ //#endregion
7
+ export { collectImportedStepBindings, collectReExportedManifestFunctions };
@@ -0,0 +1,106 @@
1
+ import { WorkflowTransformError } from "./error.mjs";
2
+ import path from "node:path";
3
+ //#region src/vite/manifest.ts
4
+ const JS_TS_EXTENSION_PATTERN = /\.[cm]?[jt]sx?$/;
5
+ function collectImportedStepBindings(sourceFile, file, manifests) {
6
+ const manifestBySource = new Map(manifests.map((manifest) => [manifest.file, manifest]));
7
+ const importedSteps = /* @__PURE__ */ new Map();
8
+ for (const statement of sourceFile.body) {
9
+ if (statement.type !== "ImportDeclaration" || statement.importKind === "type") continue;
10
+ const resolved = resolveManifestImport(file, statement.source.value, manifestBySource);
11
+ if (resolved === void 0) continue;
12
+ if (hasNonNamedImportSpecifier(statement)) WorkflowTransformError.directiveImportsMustBeNamed(statement.source.value);
13
+ const exportedSteps = new Map(resolved.manifest.functions.filter((entry) => entry.kind === "step").map((entry) => [entry.exportName, entry]));
14
+ for (const element of statement.specifiers) {
15
+ if (element.type !== "ImportSpecifier" || element.importKind === "type") continue;
16
+ const importName = moduleExportNameText(element.imported);
17
+ const step = exportedSteps.get(importName);
18
+ if (step === void 0) continue;
19
+ importedSteps.set(element.local.name, {
20
+ source: resolved.source,
21
+ importName,
22
+ localName: element.local.name,
23
+ kind: "step",
24
+ workflowName: step.workflowName,
25
+ ...step.version === void 0 ? {} : { version: step.version }
26
+ });
27
+ }
28
+ }
29
+ return importedSteps;
30
+ }
31
+ function collectReExportedManifestFunctions(sourceFile, file, manifests) {
32
+ const manifestBySource = new Map(manifests.map((manifest) => [manifest.file, manifest]));
33
+ const functions = [];
34
+ for (const statement of sourceFile.body) {
35
+ if (!isSupportedReExportDeclaration(statement) || statement.exportKind === "type") continue;
36
+ if (statement.type === "ExportAllDeclaration" && statement.exported !== null) WorkflowTransformError.directiveReExportsMustBeNamed(statement.source.value);
37
+ const resolved = resolveManifestImport(file, statement.source.value, manifestBySource);
38
+ if (resolved === void 0) continue;
39
+ if (statement.type === "ExportAllDeclaration") {
40
+ functions.push(...resolved.manifest.functions);
41
+ continue;
42
+ }
43
+ const exported = new Map(resolved.manifest.functions.map((entry) => [entry.exportName, entry]));
44
+ for (const element of statement.specifiers) {
45
+ if (element.exportKind === "type") continue;
46
+ const importName = moduleExportNameText(element.local);
47
+ const entry = exported.get(importName);
48
+ if (entry === void 0) continue;
49
+ functions.push({
50
+ kind: entry.kind,
51
+ exportName: moduleExportNameText(element.exported),
52
+ localName: entry.localName,
53
+ generatedName: entry.generatedName,
54
+ workflowName: entry.workflowName,
55
+ ...entry.version === void 0 ? {} : { version: entry.version }
56
+ });
57
+ }
58
+ }
59
+ return functions;
60
+ }
61
+ function hasNonNamedImportSpecifier(statement) {
62
+ return statement.specifiers.some((specifier) => specifier.type !== "ImportSpecifier");
63
+ }
64
+ function isSupportedReExportDeclaration(statement) {
65
+ return statement.type === "ExportAllDeclaration" || statement.type === "ExportNamedDeclaration" && statement.source !== null;
66
+ }
67
+ function moduleExportNameText(name) {
68
+ return name.type === "Literal" ? String(name.value) : name.name;
69
+ }
70
+ function resolveManifestImport(file, specifier, manifestBySource) {
71
+ const source = resolveManifestImportSource(file, specifier);
72
+ const manifest = manifestBySource.get(source);
73
+ if (manifest !== void 0) return {
74
+ source,
75
+ manifest
76
+ };
77
+ for (const alias of sourceAliases(source)) {
78
+ const aliasManifest = manifestBySource.get(alias);
79
+ if (aliasManifest !== void 0) return {
80
+ source: alias,
81
+ manifest: aliasManifest
82
+ };
83
+ }
84
+ }
85
+ function resolveManifestImportSource(file, specifier) {
86
+ if (!specifier.startsWith(".")) return specifier;
87
+ const directory = path.posix.dirname(file);
88
+ const resolved = path.posix.normalize(path.posix.join(directory, specifier));
89
+ if (JS_TS_EXTENSION_PATTERN.test(resolved)) return resolved;
90
+ return `${resolved}.ts`;
91
+ }
92
+ function sourceAliases(source) {
93
+ const extension = path.posix.extname(source);
94
+ const aliases = ESM_SOURCE_EXTENSION_BY_IMPORT_EXTENSION.get(extension);
95
+ if (aliases === void 0) return [];
96
+ const withoutExtension = source.slice(0, -extension.length);
97
+ return aliases.map((alias) => `${withoutExtension}${alias}`);
98
+ }
99
+ const ESM_SOURCE_EXTENSION_BY_IMPORT_EXTENSION = /* @__PURE__ */ new Map([
100
+ [".js", [".ts", ".tsx"]],
101
+ [".jsx", [".tsx"]],
102
+ [".mjs", [".mts"]],
103
+ [".cjs", [".cts"]]
104
+ ]);
105
+ //#endregion
106
+ export { collectImportedStepBindings, collectReExportedManifestFunctions };