@sonamu-kit/tasks 0.0.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 (280) hide show
  1. package/.swcrc +17 -0
  2. package/README.md +7 -0
  3. package/dist/backend.d.ts +107 -0
  4. package/dist/backend.d.ts.map +1 -0
  5. package/dist/backend.js +3 -0
  6. package/dist/backend.js.map +1 -0
  7. package/dist/chaos.test.d.ts +2 -0
  8. package/dist/chaos.test.d.ts.map +1 -0
  9. package/dist/chaos.test.js +92 -0
  10. package/dist/chaos.test.js.map +1 -0
  11. package/dist/client.d.ts +178 -0
  12. package/dist/client.d.ts.map +1 -0
  13. package/dist/client.js +223 -0
  14. package/dist/client.js.map +1 -0
  15. package/dist/client.test.d.ts +2 -0
  16. package/dist/client.test.d.ts.map +1 -0
  17. package/dist/client.test.js +339 -0
  18. package/dist/client.test.js.map +1 -0
  19. package/dist/config.d.ts +22 -0
  20. package/dist/config.d.ts.map +1 -0
  21. package/dist/config.js +23 -0
  22. package/dist/config.js.map +1 -0
  23. package/dist/config.test.d.ts +2 -0
  24. package/dist/config.test.d.ts.map +1 -0
  25. package/dist/config.test.js +24 -0
  26. package/dist/config.test.js.map +1 -0
  27. package/dist/core/duration.d.ts +22 -0
  28. package/dist/core/duration.d.ts.map +1 -0
  29. package/dist/core/duration.js +64 -0
  30. package/dist/core/duration.js.map +1 -0
  31. package/dist/core/duration.test.d.ts +2 -0
  32. package/dist/core/duration.test.d.ts.map +1 -0
  33. package/dist/core/duration.test.js +265 -0
  34. package/dist/core/duration.test.js.map +1 -0
  35. package/dist/core/error.d.ts +15 -0
  36. package/dist/core/error.d.ts.map +1 -0
  37. package/dist/core/error.js +25 -0
  38. package/dist/core/error.js.map +1 -0
  39. package/dist/core/error.test.d.ts +2 -0
  40. package/dist/core/error.test.d.ts.map +1 -0
  41. package/dist/core/error.test.js +63 -0
  42. package/dist/core/error.test.js.map +1 -0
  43. package/dist/core/json.d.ts +5 -0
  44. package/dist/core/json.d.ts.map +1 -0
  45. package/dist/core/json.js +3 -0
  46. package/dist/core/json.js.map +1 -0
  47. package/dist/core/result.d.ts +22 -0
  48. package/dist/core/result.d.ts.map +1 -0
  49. package/dist/core/result.js +22 -0
  50. package/dist/core/result.js.map +1 -0
  51. package/dist/core/result.test.d.ts +2 -0
  52. package/dist/core/result.test.d.ts.map +1 -0
  53. package/dist/core/result.test.js +19 -0
  54. package/dist/core/result.test.js.map +1 -0
  55. package/dist/core/retry.d.ts +21 -0
  56. package/dist/core/retry.d.ts.map +1 -0
  57. package/dist/core/retry.js +25 -0
  58. package/dist/core/retry.js.map +1 -0
  59. package/dist/core/retry.test.d.ts +2 -0
  60. package/dist/core/retry.test.d.ts.map +1 -0
  61. package/dist/core/retry.test.js +37 -0
  62. package/dist/core/retry.test.js.map +1 -0
  63. package/dist/core/schema.d.ts +57 -0
  64. package/dist/core/schema.d.ts.map +1 -0
  65. package/dist/core/schema.js +4 -0
  66. package/dist/core/schema.js.map +1 -0
  67. package/dist/core/step.d.ts +96 -0
  68. package/dist/core/step.d.ts.map +1 -0
  69. package/dist/core/step.js +78 -0
  70. package/dist/core/step.js.map +1 -0
  71. package/dist/core/step.test.d.ts +2 -0
  72. package/dist/core/step.test.d.ts.map +1 -0
  73. package/dist/core/step.test.js +356 -0
  74. package/dist/core/step.test.js.map +1 -0
  75. package/dist/core/workflow.d.ts +78 -0
  76. package/dist/core/workflow.d.ts.map +1 -0
  77. package/dist/core/workflow.js +46 -0
  78. package/dist/core/workflow.js.map +1 -0
  79. package/dist/core/workflow.test.d.ts +2 -0
  80. package/dist/core/workflow.test.d.ts.map +1 -0
  81. package/dist/core/workflow.test.js +172 -0
  82. package/dist/core/workflow.test.js.map +1 -0
  83. package/dist/database/backend.d.ts +60 -0
  84. package/dist/database/backend.d.ts.map +1 -0
  85. package/dist/database/backend.js +387 -0
  86. package/dist/database/backend.js.map +1 -0
  87. package/dist/database/backend.test.d.ts +2 -0
  88. package/dist/database/backend.test.d.ts.map +1 -0
  89. package/dist/database/backend.test.js +17 -0
  90. package/dist/database/backend.test.js.map +1 -0
  91. package/dist/database/backend.testsuite.d.ts +20 -0
  92. package/dist/database/backend.testsuite.d.ts.map +1 -0
  93. package/dist/database/backend.testsuite.js +1174 -0
  94. package/dist/database/backend.testsuite.js.map +1 -0
  95. package/dist/database/base.d.ts +12 -0
  96. package/dist/database/base.d.ts.map +1 -0
  97. package/dist/database/base.js +19 -0
  98. package/dist/database/base.js.map +1 -0
  99. package/dist/database/migrations/20251212000000_0_init.js +9 -0
  100. package/dist/database/migrations/20251212000000_0_init.js.map +1 -0
  101. package/dist/database/migrations/20251212000000_1_tables.js +88 -0
  102. package/dist/database/migrations/20251212000000_1_tables.js.map +1 -0
  103. package/dist/database/migrations/20251212000000_2_fk.js +48 -0
  104. package/dist/database/migrations/20251212000000_2_fk.js.map +1 -0
  105. package/dist/database/migrations/20251212000000_3_indexes.js +107 -0
  106. package/dist/database/migrations/20251212000000_3_indexes.js.map +1 -0
  107. package/dist/database/pubsub.d.ts +17 -0
  108. package/dist/database/pubsub.d.ts.map +1 -0
  109. package/dist/database/pubsub.js +70 -0
  110. package/dist/database/pubsub.js.map +1 -0
  111. package/dist/database/pubsub.test.d.ts +2 -0
  112. package/dist/database/pubsub.test.d.ts.map +1 -0
  113. package/dist/database/pubsub.test.js +86 -0
  114. package/dist/database/pubsub.test.js.map +1 -0
  115. package/dist/errors.d.ts +8 -0
  116. package/dist/errors.d.ts.map +1 -0
  117. package/dist/errors.js +21 -0
  118. package/dist/errors.js.map +1 -0
  119. package/dist/execution.d.ts +82 -0
  120. package/dist/execution.d.ts.map +1 -0
  121. package/dist/execution.js +182 -0
  122. package/dist/execution.js.map +1 -0
  123. package/dist/execution.test.d.ts +2 -0
  124. package/dist/execution.test.d.ts.map +1 -0
  125. package/dist/execution.test.js +556 -0
  126. package/dist/execution.test.js.map +1 -0
  127. package/dist/index.d.ts +8 -0
  128. package/dist/index.d.ts.map +1 -0
  129. package/dist/index.js +6 -0
  130. package/dist/index.js.map +1 -0
  131. package/dist/internal.d.ts +12 -0
  132. package/dist/internal.d.ts.map +1 -0
  133. package/dist/internal.js +5 -0
  134. package/dist/internal.js.map +1 -0
  135. package/dist/practices/01-remote-workflow.d.ts +2 -0
  136. package/dist/practices/01-remote-workflow.d.ts.map +1 -0
  137. package/dist/practices/01-remote-workflow.js +69 -0
  138. package/dist/practices/01-remote-workflow.js.map +1 -0
  139. package/dist/practices/01-remote.d.ts +2 -0
  140. package/dist/practices/01-remote.d.ts.map +1 -0
  141. package/dist/practices/01-remote.js +87 -0
  142. package/dist/practices/01-remote.js.map +1 -0
  143. package/dist/practices/02-local.d.ts +2 -0
  144. package/dist/practices/02-local.d.ts.map +1 -0
  145. package/dist/practices/02-local.js +84 -0
  146. package/dist/practices/02-local.js.map +1 -0
  147. package/dist/practices/03-local-retry.d.ts +2 -0
  148. package/dist/practices/03-local-retry.d.ts.map +1 -0
  149. package/dist/practices/03-local-retry.js +85 -0
  150. package/dist/practices/03-local-retry.js.map +1 -0
  151. package/dist/practices/04-scheduler-dispose.d.ts +2 -0
  152. package/dist/practices/04-scheduler-dispose.d.ts.map +1 -0
  153. package/dist/practices/04-scheduler-dispose.js +65 -0
  154. package/dist/practices/04-scheduler-dispose.js.map +1 -0
  155. package/dist/practices/05-router.d.ts +2 -0
  156. package/dist/practices/05-router.d.ts.map +1 -0
  157. package/dist/practices/05-router.js +80 -0
  158. package/dist/practices/05-router.js.map +1 -0
  159. package/dist/registry.d.ts +33 -0
  160. package/dist/registry.d.ts.map +1 -0
  161. package/dist/registry.js +54 -0
  162. package/dist/registry.js.map +1 -0
  163. package/dist/registry.test.d.ts +2 -0
  164. package/dist/registry.test.d.ts.map +1 -0
  165. package/dist/registry.test.js +95 -0
  166. package/dist/registry.test.js.map +1 -0
  167. package/dist/scheduler.d.ts +22 -0
  168. package/dist/scheduler.d.ts.map +1 -0
  169. package/dist/scheduler.js +117 -0
  170. package/dist/scheduler.js.map +1 -0
  171. package/dist/tasks/index.d.ts +4 -0
  172. package/dist/tasks/index.d.ts.map +1 -0
  173. package/dist/tasks/index.js +5 -0
  174. package/dist/tasks/index.js.map +1 -0
  175. package/dist/tasks/local-task.d.ts +6 -0
  176. package/dist/tasks/local-task.d.ts.map +1 -0
  177. package/dist/tasks/local-task.js +95 -0
  178. package/dist/tasks/local-task.js.map +1 -0
  179. package/dist/tasks/remote-task.d.ts +11 -0
  180. package/dist/tasks/remote-task.d.ts.map +1 -0
  181. package/dist/tasks/remote-task.js +213 -0
  182. package/dist/tasks/remote-task.js.map +1 -0
  183. package/dist/tasks/shared.d.ts +8 -0
  184. package/dist/tasks/shared.d.ts.map +1 -0
  185. package/dist/tasks/shared.js +41 -0
  186. package/dist/tasks/shared.js.map +1 -0
  187. package/dist/testing/connection.d.ts +7 -0
  188. package/dist/testing/connection.d.ts.map +1 -0
  189. package/dist/testing/connection.js +38 -0
  190. package/dist/testing/connection.js.map +1 -0
  191. package/dist/types/config.d.ts +44 -0
  192. package/dist/types/config.d.ts.map +1 -0
  193. package/dist/types/config.js +3 -0
  194. package/dist/types/config.js.map +1 -0
  195. package/dist/types/context.d.ts +18 -0
  196. package/dist/types/context.d.ts.map +1 -0
  197. package/dist/types/context.js +4 -0
  198. package/dist/types/context.js.map +1 -0
  199. package/dist/types/events.d.ts +43 -0
  200. package/dist/types/events.d.ts.map +1 -0
  201. package/dist/types/events.js +3 -0
  202. package/dist/types/events.js.map +1 -0
  203. package/dist/types/index.d.ts +6 -0
  204. package/dist/types/index.d.ts.map +1 -0
  205. package/dist/types/index.js +3 -0
  206. package/dist/types/index.js.map +1 -0
  207. package/dist/types/task-items.d.ts +12 -0
  208. package/dist/types/task-items.d.ts.map +1 -0
  209. package/dist/types/task-items.js +3 -0
  210. package/dist/types/task-items.js.map +1 -0
  211. package/dist/types/utils.d.ts +4 -0
  212. package/dist/types/utils.d.ts.map +1 -0
  213. package/dist/types/utils.js +8 -0
  214. package/dist/types/utils.js.map +1 -0
  215. package/dist/worker.d.ts +61 -0
  216. package/dist/worker.d.ts.map +1 -0
  217. package/dist/worker.js +206 -0
  218. package/dist/worker.js.map +1 -0
  219. package/dist/worker.test.d.ts +2 -0
  220. package/dist/worker.test.d.ts.map +1 -0
  221. package/dist/worker.test.js +1163 -0
  222. package/dist/worker.test.js.map +1 -0
  223. package/dist/workflow.d.ts +44 -0
  224. package/dist/workflow.d.ts.map +1 -0
  225. package/dist/workflow.js +21 -0
  226. package/dist/workflow.js.map +1 -0
  227. package/dist/workflow.test.d.ts +2 -0
  228. package/dist/workflow.test.d.ts.map +1 -0
  229. package/dist/workflow.test.js +73 -0
  230. package/dist/workflow.test.js.map +1 -0
  231. package/nodemon.json +6 -0
  232. package/package.json +63 -0
  233. package/scripts/migrate.ts +11 -0
  234. package/src/backend.ts +133 -0
  235. package/src/chaos.test.ts +108 -0
  236. package/src/client.test.ts +297 -0
  237. package/src/client.ts +331 -0
  238. package/src/config.test.ts +23 -0
  239. package/src/config.ts +35 -0
  240. package/src/core/duration.test.ts +326 -0
  241. package/src/core/duration.ts +86 -0
  242. package/src/core/error.test.ts +77 -0
  243. package/src/core/error.ts +30 -0
  244. package/src/core/json.ts +2 -0
  245. package/src/core/result.test.ts +13 -0
  246. package/src/core/result.ts +29 -0
  247. package/src/core/retry.test.ts +41 -0
  248. package/src/core/retry.ts +29 -0
  249. package/src/core/schema.ts +74 -0
  250. package/src/core/step.test.ts +362 -0
  251. package/src/core/step.ts +152 -0
  252. package/src/core/workflow.test.ts +184 -0
  253. package/src/core/workflow.ts +127 -0
  254. package/src/database/backend.test.ts +16 -0
  255. package/src/database/backend.testsuite.ts +1376 -0
  256. package/src/database/backend.ts +655 -0
  257. package/src/database/base.ts +23 -0
  258. package/src/database/migrations/20251212000000_0_init.ts +10 -0
  259. package/src/database/migrations/20251212000000_1_tables.ts +54 -0
  260. package/src/database/migrations/20251212000000_2_fk.ts +46 -0
  261. package/src/database/migrations/20251212000000_3_indexes.ts +82 -0
  262. package/src/database/pubsub.test.ts +92 -0
  263. package/src/database/pubsub.ts +92 -0
  264. package/src/execution.test.ts +508 -0
  265. package/src/execution.ts +291 -0
  266. package/src/index.ts +7 -0
  267. package/src/internal.ts +11 -0
  268. package/src/practices/01-remote-workflow.ts +61 -0
  269. package/src/registry.test.ts +122 -0
  270. package/src/registry.ts +65 -0
  271. package/src/testing/connection.ts +44 -0
  272. package/src/worker.test.ts +1138 -0
  273. package/src/worker.ts +281 -0
  274. package/src/workflow.test.ts +68 -0
  275. package/src/workflow.ts +84 -0
  276. package/table_ddl.sql +60 -0
  277. package/templates/openworkflow.config.ts +22 -0
  278. package/tsconfig.json +40 -0
  279. package/tsconfig.test.json +4 -0
  280. package/vite.config.ts +13 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/error.test.ts"],"sourcesContent":["import { describe, expect, test } from \"vitest\";\nimport { serializeError } from \"./error\";\n\ndescribe(\"serializeError\", () => {\n test(\"serializes Error instance with name, message, and stack\", () => {\n const error = new Error(\"Something went wrong\");\n const result = serializeError(error);\n\n expect(result.name).toBe(\"Error\");\n expect(result.message).toBe(\"Something went wrong\");\n expect(result.stack).toBeDefined();\n expect(typeof result.stack).toBe(\"string\");\n });\n\n test(\"serializes TypeError with correct name\", () => {\n const error = new TypeError(\"Invalid type\");\n const result = serializeError(error);\n\n expect(result.name).toBe(\"TypeError\");\n expect(result.message).toBe(\"Invalid type\");\n });\n\n test(\"serializes custom Error subclass\", () => {\n class CustomError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"CustomError\";\n }\n }\n const error = new CustomError(\"Custom error message\");\n const result = serializeError(error);\n\n expect(result.name).toBe(\"CustomError\");\n expect(result.message).toBe(\"Custom error message\");\n });\n\n test(\"serializes Error without stack as undefined\", () => {\n const error = new Error(\"No stack\");\n error.stack = undefined;\n const result = serializeError(error);\n\n expect(result.stack).toBeUndefined();\n });\n\n test(\"serializes string to message\", () => {\n const result = serializeError(\"string error\");\n\n expect(result.message).toBe(\"string error\");\n expect(result.name).toBeUndefined();\n expect(result.stack).toBeUndefined();\n });\n\n test(\"serializes number to message\", () => {\n const result = serializeError(42);\n\n expect(result.message).toBe(\"42\");\n });\n\n test(\"serializes null to message\", () => {\n const result = serializeError(null);\n\n expect(result.message).toBe(\"null\");\n });\n\n test(\"serializes undefined to message\", () => {\n // eslint-disable-next-line unicorn/no-useless-undefined\n const result = serializeError(undefined);\n\n expect(result.message).toBe(\"undefined\");\n });\n\n test(\"serializes object to message using String()\", () => {\n const result = serializeError({ foo: \"bar\" });\n\n expect(result.message).toBe(\"[object Object]\");\n });\n});\n"],"names":["describe","expect","test","serializeError","error","Error","result","name","toBe","message","stack","toBeDefined","TypeError","CustomError","undefined","toBeUndefined","foo"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,IAAI,QAAQ,SAAS;AAChD,SAASC,cAAc,QAAQ,aAAU;AAEzCH,SAAS,kBAAkB;IACzBE,KAAK,2DAA2D;QAC9D,MAAME,QAAQ,IAAIC,MAAM;QACxB,MAAMC,SAASH,eAAeC;QAE9BH,OAAOK,OAAOC,IAAI,EAAEC,IAAI,CAAC;QACzBP,OAAOK,OAAOG,OAAO,EAAED,IAAI,CAAC;QAC5BP,OAAOK,OAAOI,KAAK,EAAEC,WAAW;QAChCV,OAAO,OAAOK,OAAOI,KAAK,EAAEF,IAAI,CAAC;IACnC;IAEAN,KAAK,0CAA0C;QAC7C,MAAME,QAAQ,IAAIQ,UAAU;QAC5B,MAAMN,SAASH,eAAeC;QAE9BH,OAAOK,OAAOC,IAAI,EAAEC,IAAI,CAAC;QACzBP,OAAOK,OAAOG,OAAO,EAAED,IAAI,CAAC;IAC9B;IAEAN,KAAK,oCAAoC;QACvC,MAAMW,oBAAoBR;YACxB,YAAYI,OAAe,CAAE;gBAC3B,KAAK,CAACA;gBACN,IAAI,CAACF,IAAI,GAAG;YACd;QACF;QACA,MAAMH,QAAQ,IAAIS,YAAY;QAC9B,MAAMP,SAASH,eAAeC;QAE9BH,OAAOK,OAAOC,IAAI,EAAEC,IAAI,CAAC;QACzBP,OAAOK,OAAOG,OAAO,EAAED,IAAI,CAAC;IAC9B;IAEAN,KAAK,+CAA+C;QAClD,MAAME,QAAQ,IAAIC,MAAM;QACxBD,MAAMM,KAAK,GAAGI;QACd,MAAMR,SAASH,eAAeC;QAE9BH,OAAOK,OAAOI,KAAK,EAAEK,aAAa;IACpC;IAEAb,KAAK,gCAAgC;QACnC,MAAMI,SAASH,eAAe;QAE9BF,OAAOK,OAAOG,OAAO,EAAED,IAAI,CAAC;QAC5BP,OAAOK,OAAOC,IAAI,EAAEQ,aAAa;QACjCd,OAAOK,OAAOI,KAAK,EAAEK,aAAa;IACpC;IAEAb,KAAK,gCAAgC;QACnC,MAAMI,SAASH,eAAe;QAE9BF,OAAOK,OAAOG,OAAO,EAAED,IAAI,CAAC;IAC9B;IAEAN,KAAK,8BAA8B;QACjC,MAAMI,SAASH,eAAe;QAE9BF,OAAOK,OAAOG,OAAO,EAAED,IAAI,CAAC;IAC9B;IAEAN,KAAK,mCAAmC;QACtC,wDAAwD;QACxD,MAAMI,SAASH,eAAeW;QAE9Bb,OAAOK,OAAOG,OAAO,EAAED,IAAI,CAAC;IAC9B;IAEAN,KAAK,+CAA+C;QAClD,MAAMI,SAASH,eAAe;YAAEa,KAAK;QAAM;QAE3Cf,OAAOK,OAAOG,OAAO,EAAED,IAAI,CAAC;IAC9B;AACF"}
@@ -0,0 +1,5 @@
1
+ export type JsonPrimitive = string | number | boolean | null;
2
+ export type JsonValue = JsonPrimitive | JsonValue[] | {
3
+ [key: string]: JsonValue;
4
+ };
5
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/core/json.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAC7D,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/json.ts"],"sourcesContent":["export type JsonPrimitive = string | number | boolean | null;\nexport type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue };\n"],"names":[],"mappings":"AACA,WAAmF"}
@@ -0,0 +1,22 @@
1
+ export type Result<T> = Ok<T> | Err;
2
+ export interface Ok<T> {
3
+ ok: true;
4
+ value: T;
5
+ }
6
+ export interface Err {
7
+ ok: false;
8
+ error: Error;
9
+ }
10
+ /**
11
+ * Create an Ok result.
12
+ * @param value - Result value
13
+ * @returns Ok result
14
+ */
15
+ export declare function ok<T>(value: T): Ok<T>;
16
+ /**
17
+ * Create an Err result.
18
+ * @param error - Result error
19
+ * @returns Err result
20
+ */
21
+ export declare function err(error: Readonly<Error>): Err;
22
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/core/result.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;AAEpC,MAAM,WAAW,EAAE,CAAC,CAAC;IACnB,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,CAAC,CAAC;CACV;AAED,MAAM,WAAW,GAAG;IAClB,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,KAAK,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAErC;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,CAE/C"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Create an Ok result.
3
+ * @param value - Result value
4
+ * @returns Ok result
5
+ */ export function ok(value) {
6
+ return {
7
+ ok: true,
8
+ value
9
+ };
10
+ }
11
+ /**
12
+ * Create an Err result.
13
+ * @param error - Result error
14
+ * @returns Err result
15
+ */ export function err(error) {
16
+ return {
17
+ ok: false,
18
+ error
19
+ };
20
+ }
21
+
22
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/result.ts"],"sourcesContent":["export type Result<T> = Ok<T> | Err;\n\nexport interface Ok<T> {\n ok: true;\n value: T;\n}\n\nexport interface Err {\n ok: false;\n error: Error;\n}\n\n/**\n * Create an Ok result.\n * @param value - Result value\n * @returns Ok result\n */\nexport function ok<T>(value: T): Ok<T> {\n return { ok: true, value };\n}\n\n/**\n * Create an Err result.\n * @param error - Result error\n * @returns Err result\n */\nexport function err(error: Readonly<Error>): Err {\n return { ok: false, error };\n}\n"],"names":["ok","value","err","error"],"mappings":"AAYA;;;;CAIC,GACD,OAAO,SAASA,GAAMC,KAAQ;IAC5B,OAAO;QAAED,IAAI;QAAMC;IAAM;AAC3B;AAEA;;;;CAIC,GACD,OAAO,SAASC,IAAIC,KAAsB;IACxC,OAAO;QAAEH,IAAI;QAAOG;IAAM;AAC5B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=result.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.test.d.ts","sourceRoot":"","sources":["../../src/core/result.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { err, ok } from "./result.js";
3
+ describe("Result helpers", ()=>{
4
+ test("ok creates success result", ()=>{
5
+ expect(ok(123)).toEqual({
6
+ ok: true,
7
+ value: 123
8
+ });
9
+ });
10
+ test("err creates error result", ()=>{
11
+ const error = new Error("oops");
12
+ expect(err(error)).toEqual({
13
+ ok: false,
14
+ error
15
+ });
16
+ });
17
+ });
18
+
19
+ //# sourceMappingURL=result.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/result.test.ts"],"sourcesContent":["import { describe, expect, test } from \"vitest\";\nimport { err, ok } from \"./result\";\n\ndescribe(\"Result helpers\", () => {\n test(\"ok creates success result\", () => {\n expect(ok(123)).toEqual({ ok: true, value: 123 });\n });\n\n test(\"err creates error result\", () => {\n const error = new Error(\"oops\");\n expect(err(error)).toEqual({ ok: false, error });\n });\n});\n"],"names":["describe","expect","test","err","ok","toEqual","value","error","Error"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,IAAI,QAAQ,SAAS;AAChD,SAASC,GAAG,EAAEC,EAAE,QAAQ,cAAW;AAEnCJ,SAAS,kBAAkB;IACzBE,KAAK,6BAA6B;QAChCD,OAAOG,GAAG,MAAMC,OAAO,CAAC;YAAED,IAAI;YAAME,OAAO;QAAI;IACjD;IAEAJ,KAAK,4BAA4B;QAC/B,MAAMK,QAAQ,IAAIC,MAAM;QACxBP,OAAOE,IAAII,QAAQF,OAAO,CAAC;YAAED,IAAI;YAAOG;QAAM;IAChD;AACF"}
@@ -0,0 +1,21 @@
1
+ export declare const DEFAULT_RETRY_POLICY: {
2
+ readonly initialIntervalMs: 1000;
3
+ readonly backoffCoefficient: 2;
4
+ readonly maximumIntervalMs: number;
5
+ readonly maximumAttempts: number;
6
+ };
7
+ export type RetryPolicy = typeof DEFAULT_RETRY_POLICY;
8
+ /**
9
+ * Calculate the next retry delay using exponential backoff.
10
+ * @param attemptNumber - Attempt number (1-based)
11
+ * @returns Delay in milliseconds
12
+ */
13
+ export declare function calculateRetryDelayMs(attemptNumber: number): number;
14
+ /**
15
+ * Check if an operation should be retried based on the retry policy.
16
+ * @param retryPolicy - Retry policy
17
+ * @param attemptNumber - Attempt number (1-based)
18
+ * @returns True if another attempt should be made
19
+ */
20
+ export declare function shouldRetry(retryPolicy: RetryPolicy, attemptNumber: number): boolean;
21
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/core/retry.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,OAAO,oBAAoB,CAAC;AAEtD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAInE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAEpF"}
@@ -0,0 +1,25 @@
1
+ export const DEFAULT_RETRY_POLICY = {
2
+ initialIntervalMs: 1000,
3
+ backoffCoefficient: 2,
4
+ maximumIntervalMs: 100 * 1000,
5
+ maximumAttempts: Infinity
6
+ };
7
+ /**
8
+ * Calculate the next retry delay using exponential backoff.
9
+ * @param attemptNumber - Attempt number (1-based)
10
+ * @returns Delay in milliseconds
11
+ */ export function calculateRetryDelayMs(attemptNumber) {
12
+ const { initialIntervalMs, backoffCoefficient, maximumIntervalMs } = DEFAULT_RETRY_POLICY;
13
+ const backoffMs = initialIntervalMs * backoffCoefficient ** (attemptNumber - 1);
14
+ return Math.min(backoffMs, maximumIntervalMs);
15
+ }
16
+ /**
17
+ * Check if an operation should be retried based on the retry policy.
18
+ * @param retryPolicy - Retry policy
19
+ * @param attemptNumber - Attempt number (1-based)
20
+ * @returns True if another attempt should be made
21
+ */ export function shouldRetry(retryPolicy, attemptNumber) {
22
+ return attemptNumber < retryPolicy.maximumAttempts;
23
+ }
24
+
25
+ //# sourceMappingURL=retry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/retry.ts"],"sourcesContent":["export const DEFAULT_RETRY_POLICY = {\n initialIntervalMs: 1000, // 1s\n backoffCoefficient: 2,\n maximumIntervalMs: 100 * 1000, // 100s\n maximumAttempts: Infinity, // unlimited\n} as const;\n\nexport type RetryPolicy = typeof DEFAULT_RETRY_POLICY;\n\n/**\n * Calculate the next retry delay using exponential backoff.\n * @param attemptNumber - Attempt number (1-based)\n * @returns Delay in milliseconds\n */\nexport function calculateRetryDelayMs(attemptNumber: number): number {\n const { initialIntervalMs, backoffCoefficient, maximumIntervalMs } = DEFAULT_RETRY_POLICY;\n const backoffMs = initialIntervalMs * backoffCoefficient ** (attemptNumber - 1);\n return Math.min(backoffMs, maximumIntervalMs);\n}\n\n/**\n * Check if an operation should be retried based on the retry policy.\n * @param retryPolicy - Retry policy\n * @param attemptNumber - Attempt number (1-based)\n * @returns True if another attempt should be made\n */\nexport function shouldRetry(retryPolicy: RetryPolicy, attemptNumber: number): boolean {\n return attemptNumber < retryPolicy.maximumAttempts;\n}\n"],"names":["DEFAULT_RETRY_POLICY","initialIntervalMs","backoffCoefficient","maximumIntervalMs","maximumAttempts","Infinity","calculateRetryDelayMs","attemptNumber","backoffMs","Math","min","shouldRetry","retryPolicy"],"mappings":"AAAA,OAAO,MAAMA,uBAAuB;IAClCC,mBAAmB;IACnBC,oBAAoB;IACpBC,mBAAmB,MAAM;IACzBC,iBAAiBC;AACnB,EAAW;AAIX;;;;CAIC,GACD,OAAO,SAASC,sBAAsBC,aAAqB;IACzD,MAAM,EAAEN,iBAAiB,EAAEC,kBAAkB,EAAEC,iBAAiB,EAAE,GAAGH;IACrE,MAAMQ,YAAYP,oBAAoBC,sBAAuBK,CAAAA,gBAAgB,CAAA;IAC7E,OAAOE,KAAKC,GAAG,CAACF,WAAWL;AAC7B;AAEA;;;;;CAKC,GACD,OAAO,SAASQ,YAAYC,WAAwB,EAAEL,aAAqB;IACzE,OAAOA,gBAAgBK,YAAYR,eAAe;AACpD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=retry.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.test.d.ts","sourceRoot":"","sources":["../../src/core/retry.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,37 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { calculateRetryDelayMs, DEFAULT_RETRY_POLICY, shouldRetry } from "./retry.js";
3
+ describe("calculateRetryDelayMs", ()=>{
4
+ test("calculates exponential backoff correctly", ()=>{
5
+ expect(calculateRetryDelayMs(1)).toBe(1000);
6
+ expect(calculateRetryDelayMs(2)).toBe(2000);
7
+ expect(calculateRetryDelayMs(3)).toBe(4000);
8
+ expect(calculateRetryDelayMs(4)).toBe(8000);
9
+ expect(calculateRetryDelayMs(5)).toBe(16_000);
10
+ expect(calculateRetryDelayMs(6)).toBe(32_000);
11
+ expect(calculateRetryDelayMs(7)).toBe(64_000);
12
+ });
13
+ test("caps delay at maximum interval", ()=>{
14
+ const { maximumIntervalMs } = DEFAULT_RETRY_POLICY;
15
+ // attempt 8: 1s * 2^7 = 128s = 128000ms, but capped at 100000ms (max)
16
+ expect(calculateRetryDelayMs(8)).toBe(maximumIntervalMs);
17
+ // attempts 10 & 100: should still be capped
18
+ expect(calculateRetryDelayMs(10)).toBe(maximumIntervalMs);
19
+ expect(calculateRetryDelayMs(100)).toBe(maximumIntervalMs);
20
+ });
21
+ test("handles edge cases", ()=>{
22
+ // attempt 0: 1s * 2^-1 = 0.5s = 500ms
23
+ expect(calculateRetryDelayMs(0)).toBe(500);
24
+ expect(calculateRetryDelayMs(Infinity)).toBe(100_000);
25
+ });
26
+ });
27
+ describe("shouldRetry", ()=>{
28
+ test("always returns true with default policy (infinite retries)", ()=>{
29
+ const retryPolicy = DEFAULT_RETRY_POLICY;
30
+ expect(shouldRetry(retryPolicy, 1)).toBe(true);
31
+ expect(shouldRetry(retryPolicy, 10)).toBe(true);
32
+ expect(shouldRetry(retryPolicy, 100)).toBe(true);
33
+ expect(shouldRetry(retryPolicy, 1000)).toBe(true);
34
+ });
35
+ });
36
+
37
+ //# sourceMappingURL=retry.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/retry.test.ts"],"sourcesContent":["import { describe, expect, test } from \"vitest\";\nimport { calculateRetryDelayMs, DEFAULT_RETRY_POLICY, shouldRetry } from \"./retry\";\n\ndescribe(\"calculateRetryDelayMs\", () => {\n test(\"calculates exponential backoff correctly\", () => {\n expect(calculateRetryDelayMs(1)).toBe(1000);\n expect(calculateRetryDelayMs(2)).toBe(2000);\n expect(calculateRetryDelayMs(3)).toBe(4000);\n expect(calculateRetryDelayMs(4)).toBe(8000);\n expect(calculateRetryDelayMs(5)).toBe(16_000);\n expect(calculateRetryDelayMs(6)).toBe(32_000);\n expect(calculateRetryDelayMs(7)).toBe(64_000);\n });\n\n test(\"caps delay at maximum interval\", () => {\n const { maximumIntervalMs } = DEFAULT_RETRY_POLICY;\n\n // attempt 8: 1s * 2^7 = 128s = 128000ms, but capped at 100000ms (max)\n expect(calculateRetryDelayMs(8)).toBe(maximumIntervalMs);\n\n // attempts 10 & 100: should still be capped\n expect(calculateRetryDelayMs(10)).toBe(maximumIntervalMs);\n expect(calculateRetryDelayMs(100)).toBe(maximumIntervalMs);\n });\n\n test(\"handles edge cases\", () => {\n // attempt 0: 1s * 2^-1 = 0.5s = 500ms\n expect(calculateRetryDelayMs(0)).toBe(500);\n expect(calculateRetryDelayMs(Infinity)).toBe(100_000);\n });\n});\n\ndescribe(\"shouldRetry\", () => {\n test(\"always returns true with default policy (infinite retries)\", () => {\n const retryPolicy = DEFAULT_RETRY_POLICY;\n expect(shouldRetry(retryPolicy, 1)).toBe(true);\n expect(shouldRetry(retryPolicy, 10)).toBe(true);\n expect(shouldRetry(retryPolicy, 100)).toBe(true);\n expect(shouldRetry(retryPolicy, 1000)).toBe(true);\n });\n});\n"],"names":["describe","expect","test","calculateRetryDelayMs","DEFAULT_RETRY_POLICY","shouldRetry","toBe","maximumIntervalMs","Infinity","retryPolicy"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,IAAI,QAAQ,SAAS;AAChD,SAASC,qBAAqB,EAAEC,oBAAoB,EAAEC,WAAW,QAAQ,aAAU;AAEnFL,SAAS,yBAAyB;IAChCE,KAAK,4CAA4C;QAC/CD,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;IACxC;IAEAJ,KAAK,kCAAkC;QACrC,MAAM,EAAEK,iBAAiB,EAAE,GAAGH;QAE9B,sEAAsE;QACtEH,OAAOE,sBAAsB,IAAIG,IAAI,CAACC;QAEtC,4CAA4C;QAC5CN,OAAOE,sBAAsB,KAAKG,IAAI,CAACC;QACvCN,OAAOE,sBAAsB,MAAMG,IAAI,CAACC;IAC1C;IAEAL,KAAK,sBAAsB;QACzB,sCAAsC;QACtCD,OAAOE,sBAAsB,IAAIG,IAAI,CAAC;QACtCL,OAAOE,sBAAsBK,WAAWF,IAAI,CAAC;IAC/C;AACF;AAEAN,SAAS,eAAe;IACtBE,KAAK,8DAA8D;QACjE,MAAMO,cAAcL;QACpBH,OAAOI,YAAYI,aAAa,IAAIH,IAAI,CAAC;QACzCL,OAAOI,YAAYI,aAAa,KAAKH,IAAI,CAAC;QAC1CL,OAAOI,YAAYI,aAAa,MAAMH,IAAI,CAAC;QAC3CL,OAAOI,YAAYI,aAAa,OAAOH,IAAI,CAAC;IAC9C;AACF"}
@@ -0,0 +1,57 @@
1
+ /** The Standard Schema interface. https://standardschema.dev */
2
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
3
+ /** The Standard Schema properties. */
4
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
5
+ }
6
+ export declare namespace StandardSchemaV1 {
7
+ /** The Standard Schema properties interface. */
8
+ export interface Props<Input = unknown, Output = Input> {
9
+ /** The version number of the standard. */
10
+ readonly version: 1;
11
+ /** The vendor name of the schema library. */
12
+ readonly vendor: string;
13
+ /** Validates unknown input values. */
14
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
15
+ /** Inferred types associated with the schema. */
16
+ readonly types?: Types<Input, Output> | undefined;
17
+ }
18
+ /** The result interface of the validate function. */
19
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
20
+ /** The result interface if validation succeeds. */
21
+ export interface SuccessResult<Output> {
22
+ /** The typed output value. */
23
+ readonly value: Output;
24
+ /** The non-existent issues. */
25
+ readonly issues?: undefined;
26
+ }
27
+ /** The result interface if validation fails. */
28
+ export interface FailureResult {
29
+ /** The issues of failed validation. */
30
+ readonly issues: readonly Issue[];
31
+ }
32
+ /** The issue interface of the failure output. */
33
+ export interface Issue {
34
+ /** The error message of the issue. */
35
+ readonly message: string;
36
+ /** The path of the issue, if any. */
37
+ readonly path?: readonly (PropertyKey | PathSegment)[] | undefined;
38
+ }
39
+ /** The path segment interface of the issue. */
40
+ export interface PathSegment {
41
+ /** The key representing a path segment. */
42
+ readonly key: PropertyKey;
43
+ }
44
+ /** The Standard Schema types interface. */
45
+ export interface Types<Input = unknown, Output = Input> {
46
+ /** The input type of the schema. */
47
+ readonly input: Input;
48
+ /** The output type of the schema. */
49
+ readonly output: Output;
50
+ }
51
+ /** Infers the input type of a Standard Schema. */
52
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
53
+ /** Infers the output type of a Standard Schema. */
54
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
55
+ export {};
56
+ }
57
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,MAAM,WAAW,gBAAgB,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;IAC/D,sCAAsC;IACtC,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;CAC7D;AAGD,MAAM,CAAC,OAAO,WAAW,gBAAgB,CAAC;IACxC,gDAAgD;IAEhD,MAAM,WAAW,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;QACpD,0CAA0C;QAC1C,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QACpB,6CAA6C;QAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,sCAAsC;QACtC,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QAChF,iDAAiD;QACjD,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;KACnD;IAED,qDAAqD;IACrD,MAAM,MAAM,MAAM,CAAC,MAAM,IAAI,aAAa,CAAC,MAAM,CAAC,GAAG,aAAa,CAAC;IAEnE,mDAAmD;IACnD,MAAM,WAAW,aAAa,CAAC,MAAM;QACnC,8BAA8B;QAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,+BAA+B;QAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;KAC7B;IAED,gDAAgD;IAChD,MAAM,WAAW,aAAa;QAC5B,uCAAuC;QACvC,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;KACnC;IAED,iDAAiD;IACjD,MAAM,WAAW,KAAK;QACpB,sCAAsC;QACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,qCAAqC;QACrC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,WAAW,GAAG,WAAW,CAAC,EAAE,GAAG,SAAS,CAAC;KACpE;IAED,+CAA+C;IAC/C,MAAM,WAAW,WAAW;QAC1B,2CAA2C;QAC3C,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;KAC3B;IAED,2CAA2C;IAC3C,MAAM,WAAW,KAAK,CAAC,KAAK,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK;QACpD,oCAAoC;QACpC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;QACtB,qCAAqC;QACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACzB;IAED,kDAAkD;IAClD,MAAM,MAAM,UAAU,CAAC,MAAM,SAAS,gBAAgB,IAAI,WAAW,CACnE,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAC7B,CAAC,OAAO,CAAC,CAAC;IAEX,mDAAmD;IACnD,MAAM,MAAM,WAAW,CAAC,MAAM,SAAS,gBAAgB,IAAI,WAAW,CACpE,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAC7B,CAAC,QAAQ,CAAC,CAAC;IAIZ,OAAO,EAAE,CAAC;CACX"}
@@ -0,0 +1,4 @@
1
+ /** The Standard Schema interface. https://standardschema.dev */ // eslint-disable-next-line @typescript-eslint/no-namespace
2
+ export { };
3
+
4
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/schema.ts"],"sourcesContent":["/** The Standard Schema interface. https://standardschema.dev */\nexport interface StandardSchemaV1<Input = unknown, Output = Input> {\n /** The Standard Schema properties. */\n readonly \"~standard\": StandardSchemaV1.Props<Input, Output>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace StandardSchemaV1 {\n /** The Standard Schema properties interface. */\n // eslint-disable-next-line functional/no-mixed-types\n export interface Props<Input = unknown, Output = Input> {\n /** The version number of the standard. */\n readonly version: 1;\n /** The vendor name of the schema library. */\n readonly vendor: string;\n /** Validates unknown input values. */\n readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;\n /** Inferred types associated with the schema. */\n readonly types?: Types<Input, Output> | undefined;\n }\n\n /** The result interface of the validate function. */\n export type Result<Output> = SuccessResult<Output> | FailureResult;\n\n /** The result interface if validation succeeds. */\n export interface SuccessResult<Output> {\n /** The typed output value. */\n readonly value: Output;\n /** The non-existent issues. */\n readonly issues?: undefined;\n }\n\n /** The result interface if validation fails. */\n export interface FailureResult {\n /** The issues of failed validation. */\n readonly issues: readonly Issue[];\n }\n\n /** The issue interface of the failure output. */\n export interface Issue {\n /** The error message of the issue. */\n readonly message: string;\n /** The path of the issue, if any. */\n readonly path?: readonly (PropertyKey | PathSegment)[] | undefined;\n }\n\n /** The path segment interface of the issue. */\n export interface PathSegment {\n /** The key representing a path segment. */\n readonly key: PropertyKey;\n }\n\n /** The Standard Schema types interface. */\n export interface Types<Input = unknown, Output = Input> {\n /** The input type of the schema. */\n readonly input: Input;\n /** The output type of the schema. */\n readonly output: Output;\n }\n\n /** Infers the input type of a Standard Schema. */\n export type InferInput<Schema extends StandardSchemaV1> = NonNullable<\n Schema[\"~standard\"][\"types\"]\n >[\"input\"];\n\n /** Infers the output type of a Standard Schema. */\n export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<\n Schema[\"~standard\"][\"types\"]\n >[\"output\"];\n\n // eslint-disable-next-line unicorn/require-module-specifiers\n // biome-ignore lint/complexity/noUselessEmptyExport: needed for granular visibility control of TS namespace\n export {};\n}\n"],"names":[],"mappings":"AAAA,8DAA8D,GAM9D,2DAA2D;AAC3D,WAkEC"}
@@ -0,0 +1,96 @@
1
+ import type { DurationString } from "./duration";
2
+ import type { JsonValue } from "./json";
3
+ import type { Result } from "./result";
4
+ /**
5
+ * The kind of step in a workflow.
6
+ */
7
+ export type StepKind = "function" | "sleep";
8
+ /**
9
+ * Status of a step attempt through its lifecycle.
10
+ */
11
+ export type StepAttemptStatus = "running" | "succeeded" | "completed" | "failed";
12
+ /**
13
+ * Context for a step attempt (currently only used for sleep steps).
14
+ */
15
+ export interface StepAttemptContext {
16
+ kind: "sleep";
17
+ resumeAt: string;
18
+ }
19
+ /**
20
+ * StepAttempt represents a single attempt of a step within a workflow.
21
+ */
22
+ export interface StepAttempt {
23
+ namespaceId: string;
24
+ id: string;
25
+ workflowRunId: string;
26
+ stepName: string;
27
+ kind: StepKind;
28
+ status: StepAttemptStatus;
29
+ config: JsonValue;
30
+ context: StepAttemptContext | null;
31
+ output: JsonValue | null;
32
+ error: JsonValue | null;
33
+ childWorkflowRunNamespaceId: string | null;
34
+ childWorkflowRunId: string | null;
35
+ startedAt: Date | null;
36
+ finishedAt: Date | null;
37
+ createdAt: Date;
38
+ updatedAt: Date;
39
+ }
40
+ /**
41
+ * Immutable cache for step attempts, keyed by step name.
42
+ */
43
+ export type StepAttemptCache = ReadonlyMap<string, StepAttempt>;
44
+ /**
45
+ * Create a step attempt cache from an array of attempts. Only includes
46
+ * successful attempts (completed or succeeded status).
47
+ * @param attempts - Array of step attempts to cache
48
+ * @returns An immutable map of step name to successful attempt
49
+ */
50
+ export declare function createStepAttemptCacheFromAttempts(attempts: readonly StepAttempt[]): StepAttemptCache;
51
+ /**
52
+ * Get a cached step attempt by name.
53
+ * @param cache - The step attempt cache
54
+ * @param stepName - The name of the step to look up
55
+ * @returns The cached attempt or undefined if not found
56
+ */
57
+ export declare function getCachedStepAttempt(cache: StepAttemptCache, stepName: string): StepAttempt | undefined;
58
+ /**
59
+ * Check if a step attempt is cached (has completed successfully).
60
+ * @param cache - The step attempt cache
61
+ * @param stepName - The name of the step to check
62
+ * @returns True if the step has a cached successful result
63
+ */
64
+ export declare function hasCompletedStep(cache: StepAttemptCache, stepName: string): boolean;
65
+ /**
66
+ * Add a step attempt to the cache (returns new cache, original unchanged). This
67
+ * is an immutable operation.
68
+ * @param cache - The existing step attempt cache
69
+ * @param attempt - The attempt to add
70
+ * @returns A new cache with the attempt added
71
+ */
72
+ export declare function addToStepAttemptCache(cache: StepAttemptCache, attempt: Readonly<StepAttempt>): StepAttemptCache;
73
+ /**
74
+ * Convert a step function result to a JSON-compatible value. Undefined values
75
+ * are converted to null for JSON serialization.
76
+ * @param result - The result from a step function
77
+ * @returns A JSON-serializable value
78
+ */
79
+ export declare function normalizeStepOutput(result: unknown): JsonValue;
80
+ /**
81
+ * Calculate the resume time for a sleep step.
82
+ * @param duration - The duration string to sleep for
83
+ * @param now - The current timestamp (defaults to Date.now())
84
+ * @returns A Result containing the resume Date or an Error
85
+ */
86
+ export declare function calculateSleepResumeAt(duration: DurationString, now?: number): Result<Date>;
87
+ /**
88
+ * Create the context object for a sleep step attempt.
89
+ * @param resumeAt - The time when the sleep should resume
90
+ * @returns The context object for the sleep step
91
+ */
92
+ export declare function createSleepContext(resumeAt: Readonly<Date>): {
93
+ kind: "sleep";
94
+ resumeAt: string;
95
+ };
96
+ //# sourceMappingURL=step.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../src/core/step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGvC;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,WAAW,GACX,WAAW,GACX,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,iBAAiB,CAAC;IAC1B,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACnC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACxB,2BAA2B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAEhE;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAChD,QAAQ,EAAE,SAAS,WAAW,EAAE,GAC/B,gBAAgB,CAOlB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,MAAM,GACf,WAAW,GAAG,SAAS,CAEzB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEnF;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,GAC7B,gBAAgB,CAElB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,cAAc,EACxB,GAAG,GAAE,MAAmB,GACvB,MAAM,CAAC,IAAI,CAAC,CAQd;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG;IAC5D,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,CAKA"}
@@ -0,0 +1,78 @@
1
+ import { parseDuration } from "./duration.js";
2
+ import { err, ok } from "./result.js";
3
+ /**
4
+ * Create a step attempt cache from an array of attempts. Only includes
5
+ * successful attempts (completed or succeeded status).
6
+ * @param attempts - Array of step attempts to cache
7
+ * @returns An immutable map of step name to successful attempt
8
+ */ export function createStepAttemptCacheFromAttempts(attempts) {
9
+ // 'succeeded' status is deprecated in favor of 'completed'
10
+ const successfulAttempts = attempts.filter((attempt)=>attempt.status === "succeeded" || attempt.status === "completed");
11
+ return new Map(successfulAttempts.map((attempt)=>[
12
+ attempt.stepName,
13
+ attempt
14
+ ]));
15
+ }
16
+ /**
17
+ * Get a cached step attempt by name.
18
+ * @param cache - The step attempt cache
19
+ * @param stepName - The name of the step to look up
20
+ * @returns The cached attempt or undefined if not found
21
+ */ export function getCachedStepAttempt(cache, stepName) {
22
+ return cache.get(stepName);
23
+ }
24
+ /**
25
+ * Check if a step attempt is cached (has completed successfully).
26
+ * @param cache - The step attempt cache
27
+ * @param stepName - The name of the step to check
28
+ * @returns True if the step has a cached successful result
29
+ */ export function hasCompletedStep(cache, stepName) {
30
+ return cache.has(stepName);
31
+ }
32
+ /**
33
+ * Add a step attempt to the cache (returns new cache, original unchanged). This
34
+ * is an immutable operation.
35
+ * @param cache - The existing step attempt cache
36
+ * @param attempt - The attempt to add
37
+ * @returns A new cache with the attempt added
38
+ */ export function addToStepAttemptCache(cache, attempt) {
39
+ return new Map([
40
+ ...cache,
41
+ [
42
+ attempt.stepName,
43
+ attempt
44
+ ]
45
+ ]);
46
+ }
47
+ /**
48
+ * Convert a step function result to a JSON-compatible value. Undefined values
49
+ * are converted to null for JSON serialization.
50
+ * @param result - The result from a step function
51
+ * @returns A JSON-serializable value
52
+ */ export function normalizeStepOutput(result) {
53
+ return result ?? null;
54
+ }
55
+ /**
56
+ * Calculate the resume time for a sleep step.
57
+ * @param duration - The duration string to sleep for
58
+ * @param now - The current timestamp (defaults to Date.now())
59
+ * @returns A Result containing the resume Date or an Error
60
+ */ export function calculateSleepResumeAt(duration, now = Date.now()) {
61
+ const result = parseDuration(duration);
62
+ if (!result.ok) {
63
+ return err(result.error);
64
+ }
65
+ return ok(new Date(now + result.value));
66
+ }
67
+ /**
68
+ * Create the context object for a sleep step attempt.
69
+ * @param resumeAt - The time when the sleep should resume
70
+ * @returns The context object for the sleep step
71
+ */ export function createSleepContext(resumeAt) {
72
+ return {
73
+ kind: "sleep",
74
+ resumeAt: resumeAt.toISOString()
75
+ };
76
+ }
77
+
78
+ //# sourceMappingURL=step.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/step.ts"],"sourcesContent":["import type { DurationString } from \"./duration\";\nimport { parseDuration } from \"./duration\";\nimport type { JsonValue } from \"./json\";\nimport type { Result } from \"./result\";\nimport { err, ok } from \"./result\";\n\n/**\n * The kind of step in a workflow.\n */\nexport type StepKind = \"function\" | \"sleep\";\n\n/**\n * Status of a step attempt through its lifecycle.\n */\nexport type StepAttemptStatus =\n | \"running\"\n | \"succeeded\" // deprecated in favor of 'completed'\n | \"completed\"\n | \"failed\";\n\n/**\n * Context for a step attempt (currently only used for sleep steps).\n */\nexport interface StepAttemptContext {\n kind: \"sleep\";\n resumeAt: string;\n}\n\n/**\n * StepAttempt represents a single attempt of a step within a workflow.\n */\nexport interface StepAttempt {\n namespaceId: string;\n id: string;\n workflowRunId: string;\n stepName: string;\n kind: StepKind;\n status: StepAttemptStatus;\n config: JsonValue; // user-defined config\n context: StepAttemptContext | null; // runtime execution metadata\n output: JsonValue | null;\n error: JsonValue | null;\n childWorkflowRunNamespaceId: string | null;\n childWorkflowRunId: string | null;\n startedAt: Date | null;\n finishedAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\n/**\n * Immutable cache for step attempts, keyed by step name.\n */\nexport type StepAttemptCache = ReadonlyMap<string, StepAttempt>;\n\n/**\n * Create a step attempt cache from an array of attempts. Only includes\n * successful attempts (completed or succeeded status).\n * @param attempts - Array of step attempts to cache\n * @returns An immutable map of step name to successful attempt\n */\nexport function createStepAttemptCacheFromAttempts(\n attempts: readonly StepAttempt[],\n): StepAttemptCache {\n // 'succeeded' status is deprecated in favor of 'completed'\n const successfulAttempts = attempts.filter(\n (attempt) => attempt.status === \"succeeded\" || attempt.status === \"completed\",\n );\n\n return new Map(successfulAttempts.map((attempt) => [attempt.stepName, attempt]));\n}\n\n/**\n * Get a cached step attempt by name.\n * @param cache - The step attempt cache\n * @param stepName - The name of the step to look up\n * @returns The cached attempt or undefined if not found\n */\nexport function getCachedStepAttempt(\n cache: StepAttemptCache,\n stepName: string,\n): StepAttempt | undefined {\n return cache.get(stepName);\n}\n\n/**\n * Check if a step attempt is cached (has completed successfully).\n * @param cache - The step attempt cache\n * @param stepName - The name of the step to check\n * @returns True if the step has a cached successful result\n */\nexport function hasCompletedStep(cache: StepAttemptCache, stepName: string): boolean {\n return cache.has(stepName);\n}\n\n/**\n * Add a step attempt to the cache (returns new cache, original unchanged). This\n * is an immutable operation.\n * @param cache - The existing step attempt cache\n * @param attempt - The attempt to add\n * @returns A new cache with the attempt added\n */\nexport function addToStepAttemptCache(\n cache: StepAttemptCache,\n attempt: Readonly<StepAttempt>,\n): StepAttemptCache {\n return new Map([...cache, [attempt.stepName, attempt]]);\n}\n\n/**\n * Convert a step function result to a JSON-compatible value. Undefined values\n * are converted to null for JSON serialization.\n * @param result - The result from a step function\n * @returns A JSON-serializable value\n */\nexport function normalizeStepOutput(result: unknown): JsonValue {\n return (result ?? null) as JsonValue;\n}\n\n/**\n * Calculate the resume time for a sleep step.\n * @param duration - The duration string to sleep for\n * @param now - The current timestamp (defaults to Date.now())\n * @returns A Result containing the resume Date or an Error\n */\nexport function calculateSleepResumeAt(\n duration: DurationString,\n now: number = Date.now(),\n): Result<Date> {\n const result = parseDuration(duration);\n\n if (!result.ok) {\n return err(result.error);\n }\n\n return ok(new Date(now + result.value));\n}\n\n/**\n * Create the context object for a sleep step attempt.\n * @param resumeAt - The time when the sleep should resume\n * @returns The context object for the sleep step\n */\nexport function createSleepContext(resumeAt: Readonly<Date>): {\n kind: \"sleep\";\n resumeAt: string;\n} {\n return {\n kind: \"sleep\" as const,\n resumeAt: resumeAt.toISOString(),\n };\n}\n"],"names":["parseDuration","err","ok","createStepAttemptCacheFromAttempts","attempts","successfulAttempts","filter","attempt","status","Map","map","stepName","getCachedStepAttempt","cache","get","hasCompletedStep","has","addToStepAttemptCache","normalizeStepOutput","result","calculateSleepResumeAt","duration","now","Date","error","value","createSleepContext","resumeAt","kind","toISOString"],"mappings":"AACA,SAASA,aAAa,QAAQ,gBAAa;AAG3C,SAASC,GAAG,EAAEC,EAAE,QAAQ,cAAW;AAmDnC;;;;;CAKC,GACD,OAAO,SAASC,mCACdC,QAAgC;IAEhC,2DAA2D;IAC3D,MAAMC,qBAAqBD,SAASE,MAAM,CACxC,CAACC,UAAYA,QAAQC,MAAM,KAAK,eAAeD,QAAQC,MAAM,KAAK;IAGpE,OAAO,IAAIC,IAAIJ,mBAAmBK,GAAG,CAAC,CAACH,UAAY;YAACA,QAAQI,QAAQ;YAAEJ;SAAQ;AAChF;AAEA;;;;;CAKC,GACD,OAAO,SAASK,qBACdC,KAAuB,EACvBF,QAAgB;IAEhB,OAAOE,MAAMC,GAAG,CAACH;AACnB;AAEA;;;;;CAKC,GACD,OAAO,SAASI,iBAAiBF,KAAuB,EAAEF,QAAgB;IACxE,OAAOE,MAAMG,GAAG,CAACL;AACnB;AAEA;;;;;;CAMC,GACD,OAAO,SAASM,sBACdJ,KAAuB,EACvBN,OAA8B;IAE9B,OAAO,IAAIE,IAAI;WAAII;QAAO;YAACN,QAAQI,QAAQ;YAAEJ;SAAQ;KAAC;AACxD;AAEA;;;;;CAKC,GACD,OAAO,SAASW,oBAAoBC,MAAe;IACjD,OAAQA,UAAU;AACpB;AAEA;;;;;CAKC,GACD,OAAO,SAASC,uBACdC,QAAwB,EACxBC,MAAcC,KAAKD,GAAG,EAAE;IAExB,MAAMH,SAASnB,cAAcqB;IAE7B,IAAI,CAACF,OAAOjB,EAAE,EAAE;QACd,OAAOD,IAAIkB,OAAOK,KAAK;IACzB;IAEA,OAAOtB,GAAG,IAAIqB,KAAKD,MAAMH,OAAOM,KAAK;AACvC;AAEA;;;;CAIC,GACD,OAAO,SAASC,mBAAmBC,QAAwB;IAIzD,OAAO;QACLC,MAAM;QACND,UAAUA,SAASE,WAAW;IAChC;AACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=step.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"step.test.d.ts","sourceRoot":"","sources":["../../src/core/step.test.ts"],"names":[],"mappings":""}