flingit 0.0.63 → 0.0.65

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 (517) hide show
  1. package/dist/cli/commands/dev.d.ts.map +1 -1
  2. package/dist/cli/commands/dev.js +9 -5
  3. package/dist/cli/commands/dev.js.map +1 -1
  4. package/dist/cli/commands/workflow.d.ts +51 -0
  5. package/dist/cli/commands/workflow.d.ts.map +1 -0
  6. package/dist/cli/commands/workflow.js +479 -0
  7. package/dist/cli/commands/workflow.js.map +1 -0
  8. package/dist/cli/deploy/bundler.d.ts.map +1 -1
  9. package/dist/cli/deploy/bundler.js +17 -1
  10. package/dist/cli/deploy/bundler.js.map +1 -1
  11. package/dist/cli/index.d.ts.map +1 -1
  12. package/dist/cli/index.js +2 -0
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/index.d.ts +4 -1
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +3 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/runtime/entry.d.ts +7 -0
  19. package/dist/runtime/entry.d.ts.map +1 -1
  20. package/dist/runtime/entry.js +71 -2
  21. package/dist/runtime/entry.js.map +1 -1
  22. package/dist/types/workflow.d.ts +82 -0
  23. package/dist/types/workflow.d.ts.map +1 -0
  24. package/dist/types/workflow.js +8 -0
  25. package/dist/types/workflow.js.map +1 -0
  26. package/dist/worker-runtime/d1-event-store.d.ts +22 -0
  27. package/dist/worker-runtime/d1-event-store.d.ts.map +1 -0
  28. package/dist/worker-runtime/d1-event-store.js +227 -0
  29. package/dist/worker-runtime/d1-event-store.js.map +1 -0
  30. package/dist/worker-runtime/entry-extract.d.ts.map +1 -1
  31. package/dist/worker-runtime/entry-extract.js +6 -3
  32. package/dist/worker-runtime/entry-extract.js.map +1 -1
  33. package/dist/worker-runtime/entry.d.ts.map +1 -1
  34. package/dist/worker-runtime/entry.js +105 -3
  35. package/dist/worker-runtime/entry.js.map +1 -1
  36. package/dist/worker-runtime/index.d.ts +2 -0
  37. package/dist/worker-runtime/index.d.ts.map +1 -1
  38. package/dist/worker-runtime/index.js +5 -0
  39. package/dist/worker-runtime/index.js.map +1 -1
  40. package/dist/workflow/runtime.d.ts +56 -0
  41. package/dist/workflow/runtime.d.ts.map +1 -0
  42. package/dist/workflow/runtime.js +450 -0
  43. package/dist/workflow/runtime.js.map +1 -0
  44. package/node_modules/@glideapps/ts-necessities/LICENSE +21 -0
  45. package/node_modules/@glideapps/ts-necessities/README.md +16 -0
  46. package/node_modules/@glideapps/ts-necessities/dist/branded-strings.d.ts +39 -0
  47. package/node_modules/@glideapps/ts-necessities/dist/default-map.d.ts +53 -0
  48. package/node_modules/@glideapps/ts-necessities/dist/index.d.mts +113 -0
  49. package/node_modules/@glideapps/ts-necessities/dist/index.d.ts +113 -0
  50. package/node_modules/@glideapps/ts-necessities/dist/index.js +237 -0
  51. package/node_modules/@glideapps/ts-necessities/dist/index.mjs +189 -0
  52. package/node_modules/@glideapps/ts-necessities/package.json +52 -0
  53. package/node_modules/@rollup/rollup-linux-x64-gnu/README.md +3 -0
  54. package/node_modules/@rollup/rollup-linux-x64-gnu/package.json +25 -0
  55. package/node_modules/@rollup/rollup-linux-x64-gnu/rollup.linux-x64-gnu.node +0 -0
  56. package/node_modules/base64-js/LICENSE +21 -0
  57. package/node_modules/base64-js/README.md +34 -0
  58. package/node_modules/base64-js/base64js.min.js +1 -0
  59. package/node_modules/base64-js/index.d.ts +3 -0
  60. package/node_modules/base64-js/index.js +150 -0
  61. package/node_modules/base64-js/package.json +47 -0
  62. package/node_modules/better-sqlite3/LICENSE +21 -0
  63. package/node_modules/better-sqlite3/README.md +99 -0
  64. package/node_modules/better-sqlite3/binding.gyp +38 -0
  65. package/node_modules/better-sqlite3/deps/common.gypi +68 -0
  66. package/node_modules/better-sqlite3/deps/copy.js +31 -0
  67. package/node_modules/better-sqlite3/deps/defines.gypi +41 -0
  68. package/node_modules/better-sqlite3/deps/download.sh +122 -0
  69. package/node_modules/better-sqlite3/deps/patches/1208.patch +15 -0
  70. package/node_modules/better-sqlite3/deps/sqlite3/sqlite3.c +265994 -0
  71. package/node_modules/better-sqlite3/deps/sqlite3/sqlite3.h +13968 -0
  72. package/node_modules/better-sqlite3/deps/sqlite3/sqlite3ext.h +730 -0
  73. package/node_modules/better-sqlite3/deps/sqlite3.gyp +80 -0
  74. package/node_modules/better-sqlite3/deps/test_extension.c +21 -0
  75. package/node_modules/better-sqlite3/lib/database.js +90 -0
  76. package/node_modules/better-sqlite3/lib/index.js +3 -0
  77. package/node_modules/better-sqlite3/lib/methods/aggregate.js +43 -0
  78. package/node_modules/better-sqlite3/lib/methods/backup.js +67 -0
  79. package/node_modules/better-sqlite3/lib/methods/function.js +31 -0
  80. package/node_modules/better-sqlite3/lib/methods/inspect.js +7 -0
  81. package/node_modules/better-sqlite3/lib/methods/pragma.js +12 -0
  82. package/node_modules/better-sqlite3/lib/methods/serialize.js +16 -0
  83. package/node_modules/better-sqlite3/lib/methods/table.js +189 -0
  84. package/node_modules/better-sqlite3/lib/methods/transaction.js +78 -0
  85. package/node_modules/better-sqlite3/lib/methods/wrappers.js +54 -0
  86. package/node_modules/better-sqlite3/lib/sqlite-error.js +20 -0
  87. package/node_modules/better-sqlite3/lib/util.js +12 -0
  88. package/node_modules/better-sqlite3/package.json +59 -0
  89. package/node_modules/better-sqlite3/src/addon.cpp +47 -0
  90. package/node_modules/better-sqlite3/src/better_sqlite3.cpp +74 -0
  91. package/node_modules/better-sqlite3/src/objects/backup.cpp +120 -0
  92. package/node_modules/better-sqlite3/src/objects/backup.hpp +36 -0
  93. package/node_modules/better-sqlite3/src/objects/database.cpp +417 -0
  94. package/node_modules/better-sqlite3/src/objects/database.hpp +103 -0
  95. package/node_modules/better-sqlite3/src/objects/statement-iterator.cpp +113 -0
  96. package/node_modules/better-sqlite3/src/objects/statement-iterator.hpp +50 -0
  97. package/node_modules/better-sqlite3/src/objects/statement.cpp +383 -0
  98. package/node_modules/better-sqlite3/src/objects/statement.hpp +58 -0
  99. package/node_modules/better-sqlite3/src/util/bind-map.cpp +73 -0
  100. package/node_modules/better-sqlite3/src/util/binder.cpp +193 -0
  101. package/node_modules/better-sqlite3/src/util/constants.cpp +172 -0
  102. package/node_modules/better-sqlite3/src/util/custom-aggregate.cpp +121 -0
  103. package/node_modules/better-sqlite3/src/util/custom-function.cpp +59 -0
  104. package/node_modules/better-sqlite3/src/util/custom-table.cpp +409 -0
  105. package/node_modules/better-sqlite3/src/util/data-converter.cpp +17 -0
  106. package/node_modules/better-sqlite3/src/util/data.cpp +194 -0
  107. package/node_modules/better-sqlite3/src/util/helpers.cpp +109 -0
  108. package/node_modules/better-sqlite3/src/util/macros.cpp +83 -0
  109. package/node_modules/better-sqlite3/src/util/query-macros.cpp +71 -0
  110. package/node_modules/better-sqlite3/src/util/row-builder.cpp +49 -0
  111. package/node_modules/bindings/LICENSE.md +22 -0
  112. package/node_modules/bindings/README.md +98 -0
  113. package/node_modules/bindings/bindings.js +221 -0
  114. package/node_modules/bindings/package.json +28 -0
  115. package/node_modules/bl/.travis.yml +17 -0
  116. package/node_modules/bl/BufferList.js +396 -0
  117. package/node_modules/bl/LICENSE.md +13 -0
  118. package/node_modules/bl/README.md +247 -0
  119. package/node_modules/bl/bl.js +84 -0
  120. package/node_modules/bl/package.json +37 -0
  121. package/node_modules/bl/test/convert.js +21 -0
  122. package/node_modules/bl/test/indexOf.js +492 -0
  123. package/node_modules/bl/test/isBufferList.js +32 -0
  124. package/node_modules/bl/test/test.js +869 -0
  125. package/node_modules/buffer/AUTHORS.md +70 -0
  126. package/node_modules/buffer/LICENSE +21 -0
  127. package/node_modules/buffer/README.md +410 -0
  128. package/node_modules/buffer/index.d.ts +186 -0
  129. package/node_modules/buffer/index.js +1817 -0
  130. package/node_modules/buffer/package.json +96 -0
  131. package/node_modules/chownr/LICENSE +15 -0
  132. package/node_modules/chownr/README.md +3 -0
  133. package/node_modules/chownr/chownr.js +167 -0
  134. package/node_modules/chownr/package.json +29 -0
  135. package/node_modules/decompress-response/index.d.ts +22 -0
  136. package/node_modules/decompress-response/index.js +58 -0
  137. package/node_modules/decompress-response/license +9 -0
  138. package/node_modules/decompress-response/package.json +56 -0
  139. package/node_modules/decompress-response/readme.md +48 -0
  140. package/node_modules/deep-extend/LICENSE +20 -0
  141. package/node_modules/deep-extend/README.md +91 -0
  142. package/node_modules/deep-extend/index.js +1 -0
  143. package/node_modules/deep-extend/lib/deep-extend.js +150 -0
  144. package/node_modules/deep-extend/package.json +62 -0
  145. package/node_modules/detect-libc/LICENSE +201 -0
  146. package/node_modules/detect-libc/README.md +163 -0
  147. package/node_modules/detect-libc/index.d.ts +14 -0
  148. package/node_modules/detect-libc/lib/detect-libc.js +313 -0
  149. package/node_modules/detect-libc/lib/elf.js +39 -0
  150. package/node_modules/detect-libc/lib/filesystem.js +51 -0
  151. package/node_modules/detect-libc/lib/process.js +24 -0
  152. package/node_modules/detect-libc/package.json +44 -0
  153. package/node_modules/determined/LICENSE +18 -0
  154. package/node_modules/determined/README.md +317 -0
  155. package/node_modules/determined/dist/index.cjs +370 -0
  156. package/node_modules/determined/dist/index.d.cts +110 -0
  157. package/node_modules/determined/dist/index.d.ts +110 -0
  158. package/node_modules/determined/dist/index.js +332 -0
  159. package/node_modules/determined/package.json +45 -0
  160. package/node_modules/end-of-stream/LICENSE +21 -0
  161. package/node_modules/end-of-stream/README.md +54 -0
  162. package/node_modules/end-of-stream/index.js +96 -0
  163. package/node_modules/end-of-stream/package.json +37 -0
  164. package/node_modules/expand-template/.travis.yml +6 -0
  165. package/node_modules/expand-template/LICENSE +21 -0
  166. package/node_modules/expand-template/README.md +43 -0
  167. package/node_modules/expand-template/index.js +26 -0
  168. package/node_modules/expand-template/package.json +29 -0
  169. package/node_modules/expand-template/test.js +67 -0
  170. package/node_modules/file-uri-to-path/.npmignore +1 -0
  171. package/node_modules/file-uri-to-path/.travis.yml +30 -0
  172. package/node_modules/file-uri-to-path/History.md +21 -0
  173. package/node_modules/file-uri-to-path/LICENSE +20 -0
  174. package/node_modules/file-uri-to-path/README.md +74 -0
  175. package/node_modules/file-uri-to-path/index.d.ts +2 -0
  176. package/node_modules/file-uri-to-path/index.js +66 -0
  177. package/node_modules/file-uri-to-path/package.json +32 -0
  178. package/node_modules/file-uri-to-path/test/test.js +24 -0
  179. package/node_modules/file-uri-to-path/test/tests.json +13 -0
  180. package/node_modules/flingflow/.nvmrc +1 -0
  181. package/node_modules/flingflow/AGENTS.md +5 -0
  182. package/node_modules/flingflow/README.md +679 -0
  183. package/node_modules/flingflow/SPEC.md +554 -0
  184. package/node_modules/flingflow/TESTING.md +506 -0
  185. package/node_modules/flingflow/dist/backoff.d.ts +9 -0
  186. package/node_modules/flingflow/dist/backoff.js +14 -0
  187. package/node_modules/flingflow/dist/backoff.js.map +1 -0
  188. package/node_modules/flingflow/dist/clock.d.ts +13 -0
  189. package/node_modules/flingflow/dist/clock.js +21 -0
  190. package/node_modules/flingflow/dist/clock.js.map +1 -0
  191. package/node_modules/flingflow/dist/context.d.ts +8 -0
  192. package/node_modules/flingflow/dist/context.js +45 -0
  193. package/node_modules/flingflow/dist/context.js.map +1 -0
  194. package/node_modules/flingflow/dist/engine.d.ts +29 -0
  195. package/node_modules/flingflow/dist/engine.js +306 -0
  196. package/node_modules/flingflow/dist/engine.js.map +1 -0
  197. package/node_modules/flingflow/dist/index.d.ts +18 -0
  198. package/node_modules/flingflow/dist/index.js +14 -0
  199. package/node_modules/flingflow/dist/index.js.map +1 -0
  200. package/node_modules/flingflow/dist/recovery.d.ts +16 -0
  201. package/node_modules/flingflow/dist/recovery.js +118 -0
  202. package/node_modules/flingflow/dist/recovery.js.map +1 -0
  203. package/node_modules/flingflow/dist/registry.d.ts +24 -0
  204. package/node_modules/flingflow/dist/registry.js +29 -0
  205. package/node_modules/flingflow/dist/registry.js.map +1 -0
  206. package/node_modules/flingflow/dist/store-memory.d.ts +29 -0
  207. package/node_modules/flingflow/dist/store-memory.js +349 -0
  208. package/node_modules/flingflow/dist/store-memory.js.map +1 -0
  209. package/node_modules/flingflow/dist/store-sqlite.d.ts +30 -0
  210. package/node_modules/flingflow/dist/store-sqlite.js +400 -0
  211. package/node_modules/flingflow/dist/store-sqlite.js.map +1 -0
  212. package/node_modules/flingflow/dist/store.d.ts +39 -0
  213. package/node_modules/flingflow/dist/store.js +21 -0
  214. package/node_modules/flingflow/dist/store.js.map +1 -0
  215. package/node_modules/flingflow/dist/stress.d.ts +1 -0
  216. package/node_modules/flingflow/dist/stress.js +377 -0
  217. package/node_modules/flingflow/dist/stress.js.map +1 -0
  218. package/node_modules/flingflow/dist/transitions.d.ts +14 -0
  219. package/node_modules/flingflow/dist/transitions.js +28 -0
  220. package/node_modules/flingflow/dist/transitions.js.map +1 -0
  221. package/node_modules/flingflow/dist/types.d.ts +114 -0
  222. package/node_modules/flingflow/dist/types.js +10 -0
  223. package/node_modules/flingflow/dist/types.js.map +1 -0
  224. package/node_modules/flingflow/eslint.config.js +94 -0
  225. package/node_modules/flingflow/package.json +66 -0
  226. package/node_modules/flingflow/src/backoff.ts +14 -0
  227. package/node_modules/flingflow/src/clock.ts +29 -0
  228. package/node_modules/flingflow/src/context.ts +60 -0
  229. package/node_modules/flingflow/src/engine.ts +367 -0
  230. package/node_modules/flingflow/src/index.ts +52 -0
  231. package/node_modules/flingflow/src/recovery.ts +144 -0
  232. package/node_modules/flingflow/src/registry.ts +52 -0
  233. package/node_modules/flingflow/src/store-memory.ts +378 -0
  234. package/node_modules/flingflow/src/store-sqlite.ts +451 -0
  235. package/node_modules/flingflow/src/store.ts +55 -0
  236. package/node_modules/flingflow/src/stress.ts +423 -0
  237. package/node_modules/flingflow/src/transitions.ts +38 -0
  238. package/node_modules/flingflow/src/types.ts +84 -0
  239. package/node_modules/flingflow/test/backoff.test.ts +54 -0
  240. package/node_modules/flingflow/test/context.test.ts +94 -0
  241. package/node_modules/flingflow/test/engine.test.ts +362 -0
  242. package/node_modules/flingflow/test/fixtures.ts +58 -0
  243. package/node_modules/flingflow/test/recovery.test.ts +176 -0
  244. package/node_modules/flingflow/test/simulation.test.ts +395 -0
  245. package/node_modules/flingflow/test/store-conformance.ts +344 -0
  246. package/node_modules/flingflow/test/store-memory.test.ts +8 -0
  247. package/node_modules/flingflow/test/store-sqlite.test.ts +8 -0
  248. package/node_modules/flingflow/tsconfig.json +18 -0
  249. package/node_modules/flingflow/tsconfig.lint.json +5 -0
  250. package/node_modules/flingflow/tsconfig.typecheck.json +20 -0
  251. package/node_modules/flingflow/vitest.config.ts +10 -0
  252. package/node_modules/fs-constants/LICENSE +21 -0
  253. package/node_modules/fs-constants/README.md +26 -0
  254. package/node_modules/fs-constants/browser.js +1 -0
  255. package/node_modules/fs-constants/index.js +1 -0
  256. package/node_modules/fs-constants/package.json +19 -0
  257. package/node_modules/github-from-package/.travis.yml +4 -0
  258. package/node_modules/github-from-package/LICENSE +18 -0
  259. package/node_modules/github-from-package/example/package.json +8 -0
  260. package/node_modules/github-from-package/example/url.js +3 -0
  261. package/node_modules/github-from-package/index.js +17 -0
  262. package/node_modules/github-from-package/package.json +30 -0
  263. package/node_modules/github-from-package/readme.markdown +53 -0
  264. package/node_modules/github-from-package/test/a.json +8 -0
  265. package/node_modules/github-from-package/test/b.json +5 -0
  266. package/node_modules/github-from-package/test/c.json +5 -0
  267. package/node_modules/github-from-package/test/d.json +7 -0
  268. package/node_modules/github-from-package/test/e.json +5 -0
  269. package/node_modules/github-from-package/test/url.js +19 -0
  270. package/node_modules/ieee754/LICENSE +11 -0
  271. package/node_modules/ieee754/README.md +51 -0
  272. package/node_modules/ieee754/index.d.ts +10 -0
  273. package/node_modules/ieee754/index.js +85 -0
  274. package/node_modules/ieee754/package.json +52 -0
  275. package/node_modules/inherits/LICENSE +16 -0
  276. package/node_modules/inherits/README.md +42 -0
  277. package/node_modules/inherits/inherits.js +9 -0
  278. package/node_modules/inherits/inherits_browser.js +27 -0
  279. package/node_modules/inherits/package.json +29 -0
  280. package/node_modules/ini/LICENSE +15 -0
  281. package/node_modules/ini/README.md +102 -0
  282. package/node_modules/ini/ini.js +206 -0
  283. package/node_modules/ini/package.json +33 -0
  284. package/node_modules/mimic-response/index.d.ts +17 -0
  285. package/node_modules/mimic-response/index.js +77 -0
  286. package/node_modules/mimic-response/license +9 -0
  287. package/node_modules/mimic-response/package.json +42 -0
  288. package/node_modules/mimic-response/readme.md +78 -0
  289. package/node_modules/minimist/.eslintrc +29 -0
  290. package/node_modules/minimist/.github/FUNDING.yml +12 -0
  291. package/node_modules/minimist/.nycrc +14 -0
  292. package/node_modules/minimist/CHANGELOG.md +298 -0
  293. package/node_modules/minimist/LICENSE +18 -0
  294. package/node_modules/minimist/README.md +121 -0
  295. package/node_modules/minimist/example/parse.js +4 -0
  296. package/node_modules/minimist/index.js +263 -0
  297. package/node_modules/minimist/package.json +75 -0
  298. package/node_modules/minimist/test/all_bool.js +34 -0
  299. package/node_modules/minimist/test/bool.js +177 -0
  300. package/node_modules/minimist/test/dash.js +43 -0
  301. package/node_modules/minimist/test/default_bool.js +37 -0
  302. package/node_modules/minimist/test/dotted.js +24 -0
  303. package/node_modules/minimist/test/kv_short.js +32 -0
  304. package/node_modules/minimist/test/long.js +33 -0
  305. package/node_modules/minimist/test/num.js +38 -0
  306. package/node_modules/minimist/test/parse.js +209 -0
  307. package/node_modules/minimist/test/parse_modified.js +11 -0
  308. package/node_modules/minimist/test/proto.js +64 -0
  309. package/node_modules/minimist/test/short.js +69 -0
  310. package/node_modules/minimist/test/stop_early.js +17 -0
  311. package/node_modules/minimist/test/unknown.js +104 -0
  312. package/node_modules/minimist/test/whitespace.js +10 -0
  313. package/node_modules/mkdirp-classic/LICENSE +21 -0
  314. package/node_modules/mkdirp-classic/README.md +18 -0
  315. package/node_modules/mkdirp-classic/index.js +98 -0
  316. package/node_modules/mkdirp-classic/package.json +18 -0
  317. package/node_modules/napi-build-utils/.github/workflows/run-npm-tests.yml +31 -0
  318. package/node_modules/napi-build-utils/LICENSE +21 -0
  319. package/node_modules/napi-build-utils/README.md +52 -0
  320. package/node_modules/napi-build-utils/index.js +214 -0
  321. package/node_modules/napi-build-utils/index.md +0 -0
  322. package/node_modules/napi-build-utils/package.json +42 -0
  323. package/node_modules/neverthrow/LICENSE +22 -0
  324. package/node_modules/neverthrow/README.md +1683 -0
  325. package/node_modules/neverthrow/dist/index.cjs.js +510 -0
  326. package/node_modules/neverthrow/dist/index.d.ts +408 -0
  327. package/node_modules/neverthrow/dist/index.es.js +497 -0
  328. package/node_modules/neverthrow/package.json +64 -0
  329. package/node_modules/node-abi/LICENSE +21 -0
  330. package/node_modules/node-abi/README.md +54 -0
  331. package/node_modules/node-abi/abi_registry.json +425 -0
  332. package/node_modules/node-abi/index.js +179 -0
  333. package/node_modules/node-abi/package.json +45 -0
  334. package/node_modules/once/LICENSE +15 -0
  335. package/node_modules/once/README.md +79 -0
  336. package/node_modules/once/once.js +42 -0
  337. package/node_modules/once/package.json +33 -0
  338. package/node_modules/prebuild-install/CHANGELOG.md +131 -0
  339. package/node_modules/prebuild-install/CONTRIBUTING.md +6 -0
  340. package/node_modules/prebuild-install/LICENSE +21 -0
  341. package/node_modules/prebuild-install/README.md +163 -0
  342. package/node_modules/prebuild-install/asset.js +44 -0
  343. package/node_modules/prebuild-install/bin.js +78 -0
  344. package/node_modules/prebuild-install/download.js +142 -0
  345. package/node_modules/prebuild-install/error.js +14 -0
  346. package/node_modules/prebuild-install/help.txt +16 -0
  347. package/node_modules/prebuild-install/index.js +1 -0
  348. package/node_modules/prebuild-install/log.js +33 -0
  349. package/node_modules/prebuild-install/package.json +67 -0
  350. package/node_modules/prebuild-install/proxy.js +35 -0
  351. package/node_modules/prebuild-install/rc.js +64 -0
  352. package/node_modules/prebuild-install/util.js +143 -0
  353. package/node_modules/pump/.github/FUNDING.yml +2 -0
  354. package/node_modules/pump/.travis.yml +5 -0
  355. package/node_modules/pump/LICENSE +21 -0
  356. package/node_modules/pump/README.md +74 -0
  357. package/node_modules/pump/SECURITY.md +5 -0
  358. package/node_modules/pump/index.js +86 -0
  359. package/node_modules/pump/package.json +24 -0
  360. package/node_modules/pump/test-browser.js +66 -0
  361. package/node_modules/pump/test-node.js +53 -0
  362. package/node_modules/rc/LICENSE.APACHE2 +15 -0
  363. package/node_modules/rc/LICENSE.BSD +26 -0
  364. package/node_modules/rc/LICENSE.MIT +24 -0
  365. package/node_modules/rc/README.md +227 -0
  366. package/node_modules/rc/browser.js +7 -0
  367. package/node_modules/rc/cli.js +4 -0
  368. package/node_modules/rc/index.js +53 -0
  369. package/node_modules/rc/lib/utils.js +104 -0
  370. package/node_modules/rc/package.json +29 -0
  371. package/node_modules/rc/test/ini.js +16 -0
  372. package/node_modules/rc/test/nested-env-vars.js +50 -0
  373. package/node_modules/rc/test/test.js +59 -0
  374. package/node_modules/readable-stream/CONTRIBUTING.md +38 -0
  375. package/node_modules/readable-stream/GOVERNANCE.md +136 -0
  376. package/node_modules/readable-stream/LICENSE +47 -0
  377. package/node_modules/readable-stream/README.md +106 -0
  378. package/node_modules/readable-stream/errors-browser.js +127 -0
  379. package/node_modules/readable-stream/errors.js +116 -0
  380. package/node_modules/readable-stream/experimentalWarning.js +17 -0
  381. package/node_modules/readable-stream/lib/_stream_duplex.js +126 -0
  382. package/node_modules/readable-stream/lib/_stream_passthrough.js +37 -0
  383. package/node_modules/readable-stream/lib/_stream_readable.js +1027 -0
  384. package/node_modules/readable-stream/lib/_stream_transform.js +190 -0
  385. package/node_modules/readable-stream/lib/_stream_writable.js +641 -0
  386. package/node_modules/readable-stream/lib/internal/streams/async_iterator.js +180 -0
  387. package/node_modules/readable-stream/lib/internal/streams/buffer_list.js +183 -0
  388. package/node_modules/readable-stream/lib/internal/streams/destroy.js +96 -0
  389. package/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +86 -0
  390. package/node_modules/readable-stream/lib/internal/streams/from-browser.js +3 -0
  391. package/node_modules/readable-stream/lib/internal/streams/from.js +52 -0
  392. package/node_modules/readable-stream/lib/internal/streams/pipeline.js +86 -0
  393. package/node_modules/readable-stream/lib/internal/streams/state.js +22 -0
  394. package/node_modules/readable-stream/lib/internal/streams/stream-browser.js +1 -0
  395. package/node_modules/readable-stream/lib/internal/streams/stream.js +1 -0
  396. package/node_modules/readable-stream/package.json +68 -0
  397. package/node_modules/readable-stream/readable-browser.js +9 -0
  398. package/node_modules/readable-stream/readable.js +16 -0
  399. package/node_modules/safe-buffer/LICENSE +21 -0
  400. package/node_modules/safe-buffer/README.md +584 -0
  401. package/node_modules/safe-buffer/index.d.ts +187 -0
  402. package/node_modules/safe-buffer/index.js +65 -0
  403. package/node_modules/safe-buffer/package.json +51 -0
  404. package/node_modules/semver/LICENSE +15 -0
  405. package/node_modules/semver/README.md +664 -0
  406. package/node_modules/semver/bin/semver.js +191 -0
  407. package/node_modules/semver/classes/comparator.js +143 -0
  408. package/node_modules/semver/classes/index.js +7 -0
  409. package/node_modules/semver/classes/range.js +557 -0
  410. package/node_modules/semver/classes/semver.js +333 -0
  411. package/node_modules/semver/functions/clean.js +8 -0
  412. package/node_modules/semver/functions/cmp.js +54 -0
  413. package/node_modules/semver/functions/coerce.js +62 -0
  414. package/node_modules/semver/functions/compare-build.js +9 -0
  415. package/node_modules/semver/functions/compare-loose.js +5 -0
  416. package/node_modules/semver/functions/compare.js +7 -0
  417. package/node_modules/semver/functions/diff.js +60 -0
  418. package/node_modules/semver/functions/eq.js +5 -0
  419. package/node_modules/semver/functions/gt.js +5 -0
  420. package/node_modules/semver/functions/gte.js +5 -0
  421. package/node_modules/semver/functions/inc.js +21 -0
  422. package/node_modules/semver/functions/lt.js +5 -0
  423. package/node_modules/semver/functions/lte.js +5 -0
  424. package/node_modules/semver/functions/major.js +5 -0
  425. package/node_modules/semver/functions/minor.js +5 -0
  426. package/node_modules/semver/functions/neq.js +5 -0
  427. package/node_modules/semver/functions/parse.js +18 -0
  428. package/node_modules/semver/functions/patch.js +5 -0
  429. package/node_modules/semver/functions/prerelease.js +8 -0
  430. package/node_modules/semver/functions/rcompare.js +5 -0
  431. package/node_modules/semver/functions/rsort.js +5 -0
  432. package/node_modules/semver/functions/satisfies.js +12 -0
  433. package/node_modules/semver/functions/sort.js +5 -0
  434. package/node_modules/semver/functions/valid.js +8 -0
  435. package/node_modules/semver/index.js +91 -0
  436. package/node_modules/semver/internal/constants.js +37 -0
  437. package/node_modules/semver/internal/debug.js +11 -0
  438. package/node_modules/semver/internal/identifiers.js +29 -0
  439. package/node_modules/semver/internal/lrucache.js +42 -0
  440. package/node_modules/semver/internal/parse-options.js +17 -0
  441. package/node_modules/semver/internal/re.js +223 -0
  442. package/node_modules/semver/package.json +78 -0
  443. package/node_modules/semver/preload.js +4 -0
  444. package/node_modules/semver/range.bnf +16 -0
  445. package/node_modules/semver/ranges/gtr.js +6 -0
  446. package/node_modules/semver/ranges/intersects.js +9 -0
  447. package/node_modules/semver/ranges/ltr.js +6 -0
  448. package/node_modules/semver/ranges/max-satisfying.js +27 -0
  449. package/node_modules/semver/ranges/min-satisfying.js +26 -0
  450. package/node_modules/semver/ranges/min-version.js +63 -0
  451. package/node_modules/semver/ranges/outside.js +82 -0
  452. package/node_modules/semver/ranges/simplify.js +49 -0
  453. package/node_modules/semver/ranges/subset.js +249 -0
  454. package/node_modules/semver/ranges/to-comparators.js +10 -0
  455. package/node_modules/semver/ranges/valid.js +13 -0
  456. package/node_modules/simple-concat/.travis.yml +3 -0
  457. package/node_modules/simple-concat/LICENSE +20 -0
  458. package/node_modules/simple-concat/README.md +44 -0
  459. package/node_modules/simple-concat/index.js +15 -0
  460. package/node_modules/simple-concat/package.json +47 -0
  461. package/node_modules/simple-concat/test/basic.js +41 -0
  462. package/node_modules/simple-get/.github/dependabot.yml +15 -0
  463. package/node_modules/simple-get/.github/workflows/ci.yml +23 -0
  464. package/node_modules/simple-get/LICENSE +20 -0
  465. package/node_modules/simple-get/README.md +333 -0
  466. package/node_modules/simple-get/index.js +108 -0
  467. package/node_modules/simple-get/package.json +67 -0
  468. package/node_modules/string_decoder/LICENSE +48 -0
  469. package/node_modules/string_decoder/README.md +47 -0
  470. package/node_modules/string_decoder/lib/string_decoder.js +296 -0
  471. package/node_modules/string_decoder/package.json +34 -0
  472. package/node_modules/strip-json-comments/index.js +70 -0
  473. package/node_modules/strip-json-comments/license +21 -0
  474. package/node_modules/strip-json-comments/package.json +42 -0
  475. package/node_modules/strip-json-comments/readme.md +64 -0
  476. package/node_modules/tar-fs/.travis.yml +6 -0
  477. package/node_modules/tar-fs/LICENSE +21 -0
  478. package/node_modules/tar-fs/README.md +165 -0
  479. package/node_modules/tar-fs/index.js +363 -0
  480. package/node_modules/tar-fs/package.json +41 -0
  481. package/node_modules/tar-fs/test/fixtures/a/hello.txt +1 -0
  482. package/node_modules/tar-fs/test/fixtures/b/a/test.txt +1 -0
  483. package/node_modules/tar-fs/test/fixtures/d/file1 +0 -0
  484. package/node_modules/tar-fs/test/fixtures/d/file2 +0 -0
  485. package/node_modules/tar-fs/test/fixtures/d/sub-dir/file5 +0 -0
  486. package/node_modules/tar-fs/test/fixtures/d/sub-files/file3 +0 -0
  487. package/node_modules/tar-fs/test/fixtures/d/sub-files/file4 +0 -0
  488. package/node_modules/tar-fs/test/fixtures/e/directory/.ignore +0 -0
  489. package/node_modules/tar-fs/test/fixtures/e/file +0 -0
  490. package/node_modules/tar-fs/test/fixtures/invalid.tar +0 -0
  491. package/node_modules/tar-fs/test/index.js +346 -0
  492. package/node_modules/tar-stream/LICENSE +21 -0
  493. package/node_modules/tar-stream/README.md +168 -0
  494. package/node_modules/tar-stream/extract.js +257 -0
  495. package/node_modules/tar-stream/headers.js +295 -0
  496. package/node_modules/tar-stream/index.js +2 -0
  497. package/node_modules/tar-stream/pack.js +255 -0
  498. package/node_modules/tar-stream/package.json +58 -0
  499. package/node_modules/tar-stream/sandbox.js +11 -0
  500. package/node_modules/tunnel-agent/LICENSE +55 -0
  501. package/node_modules/tunnel-agent/README.md +4 -0
  502. package/node_modules/tunnel-agent/index.js +244 -0
  503. package/node_modules/tunnel-agent/package.json +22 -0
  504. package/node_modules/util-deprecate/History.md +16 -0
  505. package/node_modules/util-deprecate/LICENSE +24 -0
  506. package/node_modules/util-deprecate/README.md +53 -0
  507. package/node_modules/util-deprecate/browser.js +67 -0
  508. package/node_modules/util-deprecate/node.js +6 -0
  509. package/node_modules/util-deprecate/package.json +27 -0
  510. package/node_modules/wrappy/LICENSE +15 -0
  511. package/node_modules/wrappy/README.md +36 -0
  512. package/node_modules/wrappy/package.json +29 -0
  513. package/node_modules/wrappy/wrappy.js +33 -0
  514. package/package.json +12 -2
  515. package/templates/default/dot-claude/skills/fling/.hash +1 -1
  516. package/templates/default/dot-claude/skills/fling/SKILL.md +56 -29
  517. package/templates/default/dot-claude/skills/fling/references/WORKFLOWS.md +368 -0
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Workflow runtime — the single source of truth for all workflow logic.
3
+ *
4
+ * Imported by both the local runtime (Node.js) and worker runtime (Cloudflare Workers).
5
+ * Uses flingflow subpath imports to avoid pulling in better-sqlite3.
6
+ */
7
+ import type { EventStore } from "flingflow/store";
8
+ import { NonRetryableError } from "flingflow/types";
9
+ import type { WorkflowApi } from "../types/workflow.js";
10
+ export { NonRetryableError };
11
+ export declare const __WORKFLOW_MIGRATION_NAME = "__fling_001_workflow_events";
12
+ export declare const __WORKFLOW_DDL: string[];
13
+ /**
14
+ * Register the internal workflow migration. Called by each runtime's entry
15
+ * point BEFORE runMigrations() to ensure the _workflow_events table is
16
+ * created via the migration mechanism rather than hard-coded in event stores.
17
+ */
18
+ export declare function __registerWorkflowMigration(migrateFn: (name: string, handler: () => Promise<void>) => void, execSql: (sql: string) => Promise<void>): void;
19
+ /** For testing only — resets the registration guard. */
20
+ export declare function __resetWorkflowMigrationRegistration(): void;
21
+ type CronRegistrar = (name: string, schedule: string, handler: (...args: any[]) => any) => void;
22
+ /**
23
+ * Set the cron registration function. Must be called by each runtime's entry
24
+ * point BEFORE user code runs (so that workflow() can register the recovery cron).
25
+ */
26
+ export declare function __setCronRegistrar(fn: CronRegistrar): void;
27
+ interface QueueSender {
28
+ send(message: {
29
+ type: string;
30
+ runId: string;
31
+ }): Promise<void>;
32
+ }
33
+ export declare function __setQueueSender(sender: QueueSender): void;
34
+ export declare function __executeWorkflowSteps(runId: string): Promise<boolean>;
35
+ /**
36
+ * Initialize the workflow engine with the given event store.
37
+ *
38
+ * Populates a flingflow WorkflowRegistry from the module-scope definitions,
39
+ * creates the Engine, and calls store.initialize() to ensure the events table
40
+ * exists.
41
+ *
42
+ * Idempotent — second and subsequent calls are no-ops.
43
+ */
44
+ export declare function __initWorkflowEngine(eventStore: EventStore): Promise<void>;
45
+ /**
46
+ * Returns a mapping of workflow names to their step names.
47
+ * Used during `fling push` to extract workflow metadata without running workflows.
48
+ */
49
+ export declare function __getWorkflowMetadata(): Record<string, string[]>;
50
+ /**
51
+ * Reset all module-scope state so tests can start fresh.
52
+ * **Test-only** — never call this in production code.
53
+ */
54
+ export declare function __resetForTesting(): void;
55
+ export declare const workflow: WorkflowApi;
56
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/workflow/runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGpD,OAAO,KAAK,EACV,WAAW,EAOZ,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAO7B,eAAO,MAAM,yBAAyB,gCAAgC,CAAC;AAEvE,eAAO,MAAM,cAAc,UAY1B,CAAC;AAIF;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,EAC/D,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GACtC,IAAI,CAQN;AAED,wDAAwD;AACxD,wBAAgB,oCAAoC,IAAI,IAAI,CAE3D;AAOD,KAAK,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,KAAK,IAAI,CAAC;AAIhG;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,aAAa,GAAG,IAAI,CAE1D;AA0BD,UAAU,WAAW;IACnB,IAAI,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/D;AAGD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAE1D;AAqGD,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,OAAO,CAAC,CAkClB;AAqOD;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAoChF;AAMD;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAMhE;AAMD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAQxC;AAMD,eAAO,MAAM,QAAQ,EAAE,WAIrB,CAAC"}
@@ -0,0 +1,450 @@
1
+ /**
2
+ * Workflow runtime — the single source of truth for all workflow logic.
3
+ *
4
+ * Imported by both the local runtime (Node.js) and worker runtime (Cloudflare Workers).
5
+ * Uses flingflow subpath imports to avoid pulling in better-sqlite3.
6
+ */
7
+ import { Engine } from "flingflow/engine";
8
+ import { WorkflowRegistry } from "flingflow/registry";
9
+ import { runRecovery } from "flingflow/recovery";
10
+ import { WorkflowAlreadyActiveError } from "flingflow/store";
11
+ import { SystemClock } from "flingflow/clock";
12
+ import { NonRetryableError } from "flingflow/types";
13
+ import { NoSimulationTask } from "determined";
14
+ // Re-export NonRetryableError so users can import it from "flingit"
15
+ export { NonRetryableError };
16
+ // ---------------------------------------------------------------------------
17
+ // Workflow event store DDL — single source of truth for Fling runtimes.
18
+ // Each statement is separate for D1 compatibility (no multi-statement exec).
19
+ // ---------------------------------------------------------------------------
20
+ export const __WORKFLOW_MIGRATION_NAME = "__fling_001_workflow_events";
21
+ export const __WORKFLOW_DDL = [
22
+ `CREATE TABLE IF NOT EXISTS _workflow_events (
23
+ run_id TEXT NOT NULL,
24
+ workflow_id TEXT NOT NULL,
25
+ seq INTEGER NOT NULL,
26
+ event_type TEXT NOT NULL,
27
+ payload TEXT NOT NULL,
28
+ created_at INTEGER NOT NULL,
29
+ PRIMARY KEY (run_id, seq)
30
+ )`,
31
+ `CREATE INDEX IF NOT EXISTS idx__workflow_events_last ON _workflow_events(run_id, seq DESC)`,
32
+ `CREATE INDEX IF NOT EXISTS idx__workflow_events_workflow ON _workflow_events(workflow_id)`,
33
+ ];
34
+ let workflowMigrationRegistered = false;
35
+ /**
36
+ * Register the internal workflow migration. Called by each runtime's entry
37
+ * point BEFORE runMigrations() to ensure the _workflow_events table is
38
+ * created via the migration mechanism rather than hard-coded in event stores.
39
+ */
40
+ export function __registerWorkflowMigration(migrateFn, execSql) {
41
+ if (workflowMigrationRegistered)
42
+ return;
43
+ workflowMigrationRegistered = true;
44
+ migrateFn(__WORKFLOW_MIGRATION_NAME, async () => {
45
+ for (const ddl of __WORKFLOW_DDL) {
46
+ await execSql(ddl);
47
+ }
48
+ });
49
+ }
50
+ /** For testing only — resets the registration guard. */
51
+ export function __resetWorkflowMigrationRegistration() {
52
+ workflowMigrationRegistered = false;
53
+ }
54
+ let cronRegistrar = null;
55
+ let recoveryCronRegistered = false;
56
+ /**
57
+ * Set the cron registration function. Must be called by each runtime's entry
58
+ * point BEFORE user code runs (so that workflow() can register the recovery cron).
59
+ */
60
+ export function __setCronRegistrar(fn) {
61
+ cronRegistrar = fn;
62
+ }
63
+ // ---------------------------------------------------------------------------
64
+ // Module-scope registration map
65
+ // ---------------------------------------------------------------------------
66
+ const definitions = new Map();
67
+ // ---------------------------------------------------------------------------
68
+ // Engine singleton (populated by __initWorkflowEngine)
69
+ // ---------------------------------------------------------------------------
70
+ let engine = null;
71
+ let store = null;
72
+ let registry = null;
73
+ /** Shared NoSimulationTask — workflows run without deterministic simulation. */
74
+ const noSim = new NoSimulationTask("fling", false);
75
+ let queueSender = null;
76
+ export function __setQueueSender(sender) {
77
+ queueSender = sender;
78
+ }
79
+ // ---------------------------------------------------------------------------
80
+ // Helpers
81
+ // ---------------------------------------------------------------------------
82
+ function requireEngine() {
83
+ if (!engine) {
84
+ throw new Error("Workflow engine not initialized. Only call workflow methods inside route handlers or cron jobs.");
85
+ }
86
+ return engine;
87
+ }
88
+ function requireStore() {
89
+ if (!store) {
90
+ throw new Error("Workflow engine not initialized. Only call workflow methods inside route handlers or cron jobs.");
91
+ }
92
+ return store;
93
+ }
94
+ /**
95
+ * Convert a Record<string, WorkflowStepHandler> to flingflow's WorkflowFn.
96
+ *
97
+ * Dispatches by ctx.step, wrapping flingflow's Ctx into the user-facing
98
+ * WorkflowCtx (which omits the `sim` field).
99
+ */
100
+ function stepsToWorkflowFn(steps) {
101
+ return async (ctx) => {
102
+ const handler = steps[ctx.step];
103
+ if (!handler) {
104
+ throw new NonRetryableError(`Unknown step "${ctx.step}". Available steps: ${Object.keys(steps).join(", ")}`);
105
+ }
106
+ // Build user-facing context (hides `sim`)
107
+ const userCtx = {
108
+ workflowId: ctx.workflowId,
109
+ runId: ctx.runId,
110
+ step: ctx.step,
111
+ get: (key) => ctx.get(key),
112
+ set: (key, value) => { ctx.set(key, value); },
113
+ };
114
+ return handler(userCtx);
115
+ };
116
+ }
117
+ /**
118
+ * Poll for a workflow run's result. Waits until the run reaches a terminal
119
+ * state (completed or failed) or the timeout expires.
120
+ */
121
+ async function getResult(runId) {
122
+ const s = requireStore();
123
+ const POLL_INTERVAL_MS = 1000;
124
+ const MAX_POLL_MS = 300_000; // 5 minutes
125
+ const startTime = Date.now();
126
+ for (;;) {
127
+ const lastEventResult = await s.getLastEvent(runId, noSim);
128
+ if (lastEventResult.isErr()) {
129
+ throw new Error(`Failed to read result for run ${runId}: ${lastEventResult.error.message}`);
130
+ }
131
+ const lastEvent = lastEventResult.value;
132
+ if (!lastEvent) {
133
+ throw new Error(`Workflow run ${runId} has no events`);
134
+ }
135
+ if (lastEvent.event_type === "workflow_completed") {
136
+ return lastEvent.payload.result;
137
+ }
138
+ if (lastEvent.event_type === "workflow_failed") {
139
+ throw new Error(`Workflow run ${runId} failed: ${lastEvent.payload.reason}`);
140
+ }
141
+ if (Date.now() - startTime >= MAX_POLL_MS) {
142
+ throw new Error(`Timed out waiting for workflow run ${runId} to complete`);
143
+ }
144
+ await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL_MS));
145
+ }
146
+ }
147
+ /**
148
+ * Execute workflow steps in a loop until the workflow reaches a terminal state,
149
+ * or the time budget is exhausted.
150
+ *
151
+ * Returns `true` when the workflow is terminal (completed/failed/nothing to claim),
152
+ * or `false` when the time budget is exceeded and the caller should re-enqueue.
153
+ * Throws on transient errors so the caller can retry.
154
+ *
155
+ * Exported so the worker runtime and local dev entry can call it directly.
156
+ */
157
+ const MAX_EXECUTION_MS = 50_000; // 50 seconds
158
+ const MAX_INLINE_BACKOFF_MS = 60_000; // Sleep inline for backoffs up to 60s
159
+ export async function __executeWorkflowSteps(runId) {
160
+ const eng = requireEngine();
161
+ const startTime = Date.now();
162
+ for (;;) {
163
+ const stepResult = await eng.executeStep(runId, noSim);
164
+ if (stepResult.isErr()) {
165
+ const msg = stepResult.error.message;
166
+ if (msg.includes("Invariant violation")) {
167
+ // stuck_terminal: the step should have been finalized but wasn't.
168
+ // Nothing we can do here — log and treat as terminal.
169
+ console.error(`[workflow] Invariant violation for ${runId}: ${msg}`);
170
+ return true;
171
+ }
172
+ // Transient error — throw so caller can retry
173
+ throw new Error(`Step execution error for ${runId}: ${msg}`);
174
+ }
175
+ const outcome = stepResult.value;
176
+ if (outcome === false)
177
+ return true; // Terminal or nothing to claim
178
+ if (outcome !== true) {
179
+ // Backoff case — sleep inline for short delays, exit for long ones
180
+ const remaining = MAX_EXECUTION_MS - (Date.now() - startTime);
181
+ if (outcome.backoffMS > MAX_INLINE_BACKOFF_MS || outcome.backoffMS > remaining) {
182
+ return false; // Leave for recovery cron
183
+ }
184
+ await new Promise(r => setTimeout(r, outcome.backoffMS));
185
+ }
186
+ if (Date.now() - startTime >= MAX_EXECUTION_MS) {
187
+ return false; // Time budget exceeded — needs continuation
188
+ }
189
+ }
190
+ }
191
+ /**
192
+ * Read status info for a run from its events.
193
+ * Returns null if the run doesn't exist.
194
+ */
195
+ async function readRunStatus(runId) {
196
+ const s = requireStore();
197
+ const event0Result = await s.getEvent(runId, 0, noSim);
198
+ if (event0Result.isErr()) {
199
+ throw new Error(`Failed to read event 0 for run ${runId}: ${event0Result.error.message}`);
200
+ }
201
+ const event0 = event0Result.value;
202
+ if (!event0 || event0.event_type !== "workflow_created") {
203
+ return null;
204
+ }
205
+ const lastEventResult = await s.getLastEvent(runId, noSim);
206
+ if (lastEventResult.isErr()) {
207
+ throw new Error(`Failed to read last event for run ${runId}: ${lastEventResult.error.message}`);
208
+ }
209
+ const lastEvent = lastEventResult.value;
210
+ if (!lastEvent) {
211
+ return null;
212
+ }
213
+ let status;
214
+ if (lastEvent.event_type === "workflow_completed") {
215
+ status = "completed";
216
+ }
217
+ else if (lastEvent.event_type === "workflow_failed") {
218
+ status = "failed";
219
+ }
220
+ else {
221
+ status = "running";
222
+ }
223
+ return {
224
+ workflowId: event0.workflow_id,
225
+ name: event0.payload.workflowName,
226
+ status,
227
+ createdAt: event0.created_at,
228
+ };
229
+ }
230
+ /**
231
+ * Build a WorkflowRun object for a given runId.
232
+ */
233
+ function makeRun(runId, workflowId, name, status, created, createdAt) {
234
+ return {
235
+ runId,
236
+ workflowId,
237
+ name,
238
+ status,
239
+ created,
240
+ createdAt,
241
+ result: () => getResult(runId),
242
+ };
243
+ }
244
+ // ---------------------------------------------------------------------------
245
+ // Registration function
246
+ // ---------------------------------------------------------------------------
247
+ function registerWorkflow(name, steps, options) {
248
+ if (definitions.has(name)) {
249
+ throw new Error(`Workflow "${name}" is already registered. Each workflow name must be unique.`);
250
+ }
251
+ definitions.set(name, { steps, options: options ?? {} });
252
+ // Register the recovery cron on the first workflow registration.
253
+ // This ensures the cron is collected during `fling push` metadata extraction.
254
+ if (!recoveryCronRegistered && cronRegistrar !== null) {
255
+ cronRegistrar("__workflow-recovery", "* * * * *", async () => {
256
+ // Recovery is a no-op if engine isn't initialized (e.g., during extraction)
257
+ if (engine === null || store === null || registry === null)
258
+ return;
259
+ return recoverStuckWorkflows();
260
+ });
261
+ recoveryCronRegistered = true;
262
+ }
263
+ }
264
+ // ---------------------------------------------------------------------------
265
+ // Runtime operations
266
+ // ---------------------------------------------------------------------------
267
+ async function start(name, data, options) {
268
+ const eng = requireEngine();
269
+ const s = requireStore();
270
+ const workflowId = options?.id ?? crypto.randomUUID();
271
+ const createResult = await eng.createWorkflow(workflowId, name, data, noSim);
272
+ if (createResult.isOk()) {
273
+ const runId = createResult.value;
274
+ // Read the actual created_at from the stored event
275
+ const event0Result = await s.getEvent(runId, 0, noSim);
276
+ const createdAt = event0Result.isOk() && event0Result.value
277
+ ? event0Result.value.created_at
278
+ : Date.now(); // fallback (should not happen)
279
+ // Enqueue workflow execution. If this fails, the workflow is still created
280
+ // in D1 and the recovery cron will pick it up within ~1 minute.
281
+ if (queueSender) {
282
+ try {
283
+ await queueSender.send({ type: "workflow-execute", runId });
284
+ }
285
+ catch (e) {
286
+ console.error(`[workflow] Failed to enqueue execution for ${runId} — recovery cron will pick it up:`, e instanceof Error ? e.message : String(e));
287
+ }
288
+ }
289
+ else {
290
+ console.error(`[workflow] No queue sender configured — workflow ${runId} was created but will rely on recovery cron. Ensure the project has FLING_API and FLING_WORKER_SECRET bindings.`);
291
+ }
292
+ return makeRun(runId, workflowId, name, "running", true, createdAt);
293
+ }
294
+ const error = createResult.error;
295
+ if (error instanceof WorkflowAlreadyActiveError) {
296
+ const runId = error.activeRunId;
297
+ const info = await readRunStatus(runId);
298
+ return makeRun(runId, workflowId, info?.name ?? name, info?.status ?? "running", false, info?.createdAt ?? Date.now());
299
+ }
300
+ throw error;
301
+ }
302
+ async function get(runId) {
303
+ const info = await readRunStatus(runId);
304
+ if (!info)
305
+ return null;
306
+ return makeRun(runId, info.workflowId, info.name, info.status, false, info.createdAt);
307
+ }
308
+ async function list(filters) {
309
+ const s = requireStore();
310
+ const limit = filters?.limit ?? 100;
311
+ // Fetch recent runs (all statuses — workflow_created events ordered by created_at DESC).
312
+ // Over-fetch to account for filtering.
313
+ const fetchLimit = limit * 3;
314
+ const recentResult = await s.getRecentRuns(fetchLimit, noSim);
315
+ if (recentResult.isErr()) {
316
+ throw new Error(`Failed to list workflows: ${recentResult.error.message}`);
317
+ }
318
+ const results = [];
319
+ for (const event0 of recentResult.value) {
320
+ const runId = event0.run_id;
321
+ const info = await readRunStatus(runId);
322
+ if (!info)
323
+ continue;
324
+ // Apply filters
325
+ if (filters?.name && info.name !== filters.name)
326
+ continue;
327
+ if (filters?.status && info.status !== filters.status)
328
+ continue;
329
+ results.push(makeRun(runId, info.workflowId, info.name, info.status, false, info.createdAt));
330
+ if (results.length >= limit)
331
+ break;
332
+ }
333
+ return results;
334
+ }
335
+ // ---------------------------------------------------------------------------
336
+ // Recovery
337
+ // ---------------------------------------------------------------------------
338
+ const clock = new SystemClock();
339
+ /**
340
+ * Scan for stuck and timed-out workflows and drive them to completion.
341
+ */
342
+ async function recoverStuckWorkflows() {
343
+ if (engine === null || store === null || registry === null) {
344
+ return { recovered: 0 };
345
+ }
346
+ const result = await runRecovery({ store, registry: registry, clock }, noSim);
347
+ if (result.isErr()) {
348
+ console.error("[workflow-recovery] Recovery scan failed:", result.error.message);
349
+ return { recovered: 0 };
350
+ }
351
+ const recoveryResults = result.value;
352
+ let recovered = 0;
353
+ for (const r of recoveryResults) {
354
+ // Re-enqueue each stuck workflow for execution
355
+ if (queueSender) {
356
+ try {
357
+ await queueSender.send({ type: "workflow-execute", runId: r.runId });
358
+ recovered++;
359
+ }
360
+ catch (e) {
361
+ console.error(`[workflow-recovery] Failed to re-enqueue ${r.runId}:`, e instanceof Error ? e.message : String(e));
362
+ }
363
+ }
364
+ }
365
+ if (recovered > 0) {
366
+ console.log(`[workflow-recovery] Recovered ${String(recovered)} workflow(s)`);
367
+ }
368
+ return { recovered };
369
+ }
370
+ // ---------------------------------------------------------------------------
371
+ // Engine initialization (called by entry points)
372
+ // ---------------------------------------------------------------------------
373
+ let initialized = false;
374
+ /**
375
+ * Initialize the workflow engine with the given event store.
376
+ *
377
+ * Populates a flingflow WorkflowRegistry from the module-scope definitions,
378
+ * creates the Engine, and calls store.initialize() to ensure the events table
379
+ * exists.
380
+ *
381
+ * Idempotent — second and subsequent calls are no-ops.
382
+ */
383
+ export async function __initWorkflowEngine(eventStore) {
384
+ if (initialized)
385
+ return;
386
+ registry = new WorkflowRegistry();
387
+ for (const [name, def] of definitions) {
388
+ const regDef = { name, fn: stepsToWorkflowFn(def.steps) };
389
+ if (def.options.maxAttempts !== undefined)
390
+ regDef.maxAttempts = def.options.maxAttempts;
391
+ if (def.options.initialBackoffMS !== undefined)
392
+ regDef.initialBackoffMS = def.options.initialBackoffMS;
393
+ if (def.options.backoffMultiplier !== undefined)
394
+ regDef.backoffMultiplier = def.options.backoffMultiplier;
395
+ if (def.options.maxBackoffMS !== undefined)
396
+ regDef.maxBackoffMS = def.options.maxBackoffMS;
397
+ if (def.options.stepTimeoutMS !== undefined)
398
+ regDef.stepTimeoutMS = def.options.stepTimeoutMS;
399
+ registry.register(regDef);
400
+ }
401
+ engine = new Engine({ store: eventStore, registry: registry });
402
+ store = eventStore;
403
+ const initResult = await eventStore.initialize();
404
+ if (initResult.isErr()) {
405
+ // Reset state so a subsequent call can retry
406
+ engine = null;
407
+ store = null;
408
+ throw new Error(`Failed to initialize workflow event store: ${initResult.error.message}`);
409
+ }
410
+ initialized = true;
411
+ }
412
+ // ---------------------------------------------------------------------------
413
+ // Metadata extraction (used by `fling push`)
414
+ // ---------------------------------------------------------------------------
415
+ /**
416
+ * Returns a mapping of workflow names to their step names.
417
+ * Used during `fling push` to extract workflow metadata without running workflows.
418
+ */
419
+ export function __getWorkflowMetadata() {
420
+ const metadata = {};
421
+ for (const [name, def] of definitions) {
422
+ metadata[name] = Object.keys(def.steps);
423
+ }
424
+ return metadata;
425
+ }
426
+ // ---------------------------------------------------------------------------
427
+ // Test-only reset (clears all module-scope state)
428
+ // ---------------------------------------------------------------------------
429
+ /**
430
+ * Reset all module-scope state so tests can start fresh.
431
+ * **Test-only** — never call this in production code.
432
+ */
433
+ export function __resetForTesting() {
434
+ definitions.clear();
435
+ engine = null;
436
+ store = null;
437
+ registry = null;
438
+ initialized = false;
439
+ recoveryCronRegistered = false;
440
+ queueSender = null;
441
+ }
442
+ // ---------------------------------------------------------------------------
443
+ // Public API — callable function with methods
444
+ // ---------------------------------------------------------------------------
445
+ export const workflow = Object.assign(registerWorkflow, {
446
+ start,
447
+ get,
448
+ list,
449
+ });
450
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/workflow/runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBA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,EAAE,CAAC;QACvB,6CAA6C;QAC7C,MAAM,GAAG,IAAI,CAAC;QACd,KAAK,GAAG,IAAI,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,8CAA8C,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5F,CAAC;IAED,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAED,8EAA8E;AAC9E,6CAA6C;AAC7C,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,UAAU,qBAAqB;IACnC,MAAM,QAAQ,GAA6B,EAAE,CAAC;IAC9C,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,WAAW,EAAE,CAAC;QACtC,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,8EAA8E;AAC9E,kDAAkD;AAClD,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,WAAW,CAAC,KAAK,EAAE,CAAC;IACpB,MAAM,GAAG,IAAI,CAAC;IACd,KAAK,GAAG,IAAI,CAAC;IACb,QAAQ,GAAG,IAAI,CAAC;IAChB,WAAW,GAAG,KAAK,CAAC;IACpB,sBAAsB,GAAG,KAAK,CAAC;IAC/B,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAED,8EAA8E;AAC9E,8CAA8C;AAC9C,8EAA8E;AAE9E,MAAM,CAAC,MAAM,QAAQ,GAAgB,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE;IACnE,KAAK;IACL,GAAG;IACH,IAAI;CACL,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 typeguard, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,16 @@
1
+ # TS Necessities
2
+
3
+ [![CI](https://github.com/glideapps/ts-necessities/actions/workflows/ci.yml/badge.svg)](https://github.com/glideapps/ts-necessities/actions/workflows/ci.yml)
4
+ [![Docs](https://img.shields.io/badge/docs-TypeDoc-blue)](https://glideapps.github.io/ts-necessities/)
5
+
6
+ These are some very basic functions and classes that we use at [Glide](https://glideapps.com/) to make coding with TypeScript easier and safer.
7
+
8
+ [📚 API Documentation](https://glideapps.github.io/ts-necessities/)
9
+
10
+ ## Installation
11
+
12
+ To add the package to your own project:
13
+
14
+ ```shell
15
+ $ npm install @glideapps/ts-necessities
16
+ ```
@@ -0,0 +1,39 @@
1
+ /**
2
+ * A branded string is a string that has a unique type, so that it can be
3
+ * distinguished from other strings. This is useful when you want to ensure
4
+ * that a string is only used in a specific context. When assigning to a
5
+ * branded string type it's not allowed to assign a non-branded string, or a
6
+ * string of the wrong brand:
7
+ *
8
+ * ```ts
9
+ * type Apple = BrandedString<"apple">;
10
+ * type Orange = BrandedString<"orange">;
11
+ *
12
+ * const apple: Apple = brandString("Pink Lady");
13
+ * let orange: Orange = apple; // error!
14
+ * orange = "jalapeño"; // error!
15
+ * let justAString: string = apple; // This is ok
16
+ * ```
17
+ */
18
+ export type BrandedString<T extends string> = string & {
19
+ __brand: T;
20
+ };
21
+ /**
22
+ * Brands a string with the specified brand.
23
+ *
24
+ * @param s The string to brand.
25
+ */
26
+ export declare function brandString<T extends string>(s: string): BrandedString<T>;
27
+ /**
28
+ * Returns a function that brands a string with the specified brand. For
29
+ * example:
30
+ *
31
+ * ```ts
32
+ * type Apple = BrandedString<"apple">;
33
+ * // `makeApple` will be of type `(s: string) => Apple`
34
+ * const makeApple = makeBrandString<Apple>();
35
+ * // `apple` will be of type `Apple`
36
+ * const apple = makeApple("Pink Lady");
37
+ * ```
38
+ */
39
+ export declare function makeBrandString<T>(): T extends BrandedString<string> ? (s: string) => T : never;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The read-only interface of [[DefaultMap]].
3
+ *
4
+ * @typeParam K The key type.
5
+ * @typeParam V The value type.
6
+ */
7
+ export interface ReadonlyDefaultMap<K, V> extends ReadonlyMap<K, V> {
8
+ get(k: K): V;
9
+ }
10
+ /**
11
+ * A `Map` that returns default values for keys that are not present.
12
+ *
13
+ * To map strings to `Set`s of numbers, for example, `DefaultMap` can
14
+ * be used like this:
15
+ *
16
+ * ```
17
+ * const m = new DefaultMap<string, Set<number>>(() => new Set());
18
+ * m.get("foo"); // returns an empty `Set`
19
+ * m.get("bar").add(1);
20
+ * m.get("bar"); // returns a `Set` containing `1`.
21
+ * ```
22
+ *
23
+ * @typeParam K The key type.
24
+ * @typeParam V The value type.
25
+ */
26
+ export declare class DefaultMap<K, V> extends Map<K, V> implements ReadonlyDefaultMap<K, V> {
27
+ private readonly _defaultFunc;
28
+ /**
29
+ *
30
+ * @param _defaultFunc Must return the default value for key `k`. Will only be called when necessary.
31
+ * @param initKVPs An array of [key, value] arrays to initialize the map with.
32
+ */
33
+ constructor(_defaultFunc: (k: K) => V, initKVPs?: readonly (readonly [K, V])[]);
34
+ /**
35
+ * Returns the value for `k`. If `k` is not present, creates
36
+ * the default value via [[_defaultFunc]], sets that default
37
+ * as the value for `k` and returns it.
38
+ */
39
+ get(k: K): V;
40
+ /**
41
+ * Sets the value for `k` to `f(v)` where `v` is the previous
42
+ * value for `k`, or the default if not present. Returns the new
43
+ * value.
44
+ *
45
+ * These two lines are equivalent:
46
+ *
47
+ * ```
48
+ * m.set("foo", m.get("foo") + 1);
49
+ * m.update("foo", x => x + 1);
50
+ * ```
51
+ */
52
+ update(k: K, f: (v: V) => V): V;
53
+ }