@sonamu-kit/tasks 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/.oxlintrc.json +3 -0
  2. package/AGENTS.md +21 -0
  3. package/dist/backend.d.ts +126 -103
  4. package/dist/backend.d.ts.map +1 -1
  5. package/dist/backend.js +4 -1
  6. package/dist/backend.js.map +1 -1
  7. package/dist/client.d.ts +145 -132
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +220 -212
  10. package/dist/client.js.map +1 -1
  11. package/dist/config.d.ts +15 -8
  12. package/dist/config.d.ts.map +1 -1
  13. package/dist/config.js +22 -17
  14. package/dist/config.js.map +1 -1
  15. package/dist/core/duration.d.ts +5 -4
  16. package/dist/core/duration.d.ts.map +1 -1
  17. package/dist/core/duration.js +54 -59
  18. package/dist/core/duration.js.map +1 -1
  19. package/dist/core/error.d.ts +10 -7
  20. package/dist/core/error.d.ts.map +1 -1
  21. package/dist/core/error.js +21 -21
  22. package/dist/core/error.js.map +1 -1
  23. package/dist/core/json.d.ts +8 -3
  24. package/dist/core/json.d.ts.map +1 -1
  25. package/dist/core/result.d.ts +10 -14
  26. package/dist/core/result.d.ts.map +1 -1
  27. package/dist/core/result.js +21 -16
  28. package/dist/core/result.js.map +1 -1
  29. package/dist/core/retry.d.ts +42 -20
  30. package/dist/core/retry.d.ts.map +1 -1
  31. package/dist/core/retry.js +49 -20
  32. package/dist/core/retry.js.map +1 -1
  33. package/dist/core/schema.d.ts +57 -53
  34. package/dist/core/schema.d.ts.map +1 -1
  35. package/dist/core/step.d.ts +28 -78
  36. package/dist/core/step.d.ts.map +1 -1
  37. package/dist/core/step.js +53 -63
  38. package/dist/core/step.js.map +1 -1
  39. package/dist/core/workflow.d.ts +33 -61
  40. package/dist/core/workflow.d.ts.map +1 -1
  41. package/dist/core/workflow.js +31 -41
  42. package/dist/core/workflow.js.map +1 -1
  43. package/dist/database/backend.d.ts +53 -46
  44. package/dist/database/backend.d.ts.map +1 -1
  45. package/dist/database/backend.js +544 -545
  46. package/dist/database/backend.js.map +1 -1
  47. package/dist/database/base.js +48 -25
  48. package/dist/database/base.js.map +1 -1
  49. package/dist/database/migrations/20251212000000_0_init.d.ts +10 -0
  50. package/dist/database/migrations/20251212000000_0_init.d.ts.map +1 -0
  51. package/dist/database/migrations/20251212000000_0_init.js +8 -4
  52. package/dist/database/migrations/20251212000000_0_init.js.map +1 -1
  53. package/dist/database/migrations/20251212000000_1_tables.d.ts +10 -0
  54. package/dist/database/migrations/20251212000000_1_tables.d.ts.map +1 -0
  55. package/dist/database/migrations/20251212000000_1_tables.js +81 -83
  56. package/dist/database/migrations/20251212000000_1_tables.js.map +1 -1
  57. package/dist/database/migrations/20251212000000_2_fk.d.ts +10 -0
  58. package/dist/database/migrations/20251212000000_2_fk.d.ts.map +1 -0
  59. package/dist/database/migrations/20251212000000_2_fk.js +20 -43
  60. package/dist/database/migrations/20251212000000_2_fk.js.map +1 -1
  61. package/dist/database/migrations/20251212000000_3_indexes.d.ts +10 -0
  62. package/dist/database/migrations/20251212000000_3_indexes.d.ts.map +1 -0
  63. package/dist/database/migrations/20251212000000_3_indexes.js +88 -102
  64. package/dist/database/migrations/20251212000000_3_indexes.js.map +1 -1
  65. package/dist/database/pubsub.d.ts +7 -16
  66. package/dist/database/pubsub.d.ts.map +1 -1
  67. package/dist/database/pubsub.js +75 -73
  68. package/dist/database/pubsub.js.map +1 -1
  69. package/dist/execution.d.ts +20 -57
  70. package/dist/execution.d.ts.map +1 -1
  71. package/dist/execution.js +175 -174
  72. package/dist/execution.js.map +1 -1
  73. package/dist/index.d.ts +5 -8
  74. package/dist/index.js +5 -5
  75. package/dist/internal.d.ts +12 -12
  76. package/dist/internal.js +4 -4
  77. package/dist/registry.d.ts +33 -27
  78. package/dist/registry.d.ts.map +1 -1
  79. package/dist/registry.js +58 -49
  80. package/dist/registry.js.map +1 -1
  81. package/dist/worker.d.ts +57 -50
  82. package/dist/worker.d.ts.map +1 -1
  83. package/dist/worker.js +194 -198
  84. package/dist/worker.js.map +1 -1
  85. package/dist/workflow.d.ts +26 -27
  86. package/dist/workflow.d.ts.map +1 -1
  87. package/dist/workflow.js +20 -15
  88. package/dist/workflow.js.map +1 -1
  89. package/nodemon.json +1 -1
  90. package/package.json +18 -20
  91. package/src/backend.ts +28 -8
  92. package/src/chaos.test.ts +3 -1
  93. package/src/client.test.ts +2 -0
  94. package/src/client.ts +32 -8
  95. package/src/config.test.ts +1 -0
  96. package/src/config.ts +3 -2
  97. package/src/core/duration.test.ts +2 -1
  98. package/src/core/duration.ts +1 -1
  99. package/src/core/error.test.ts +1 -0
  100. package/src/core/error.ts +1 -1
  101. package/src/core/result.test.ts +1 -0
  102. package/src/core/retry.test.ts +181 -11
  103. package/src/core/retry.ts +95 -19
  104. package/src/core/schema.ts +2 -2
  105. package/src/core/step.test.ts +2 -1
  106. package/src/core/step.ts +4 -3
  107. package/src/core/workflow.test.ts +2 -1
  108. package/src/core/workflow.ts +4 -3
  109. package/src/database/backend.test.ts +1 -0
  110. package/src/database/backend.testsuite.ts +162 -39
  111. package/src/database/backend.ts +271 -35
  112. package/src/database/base.test.ts +41 -0
  113. package/src/database/base.ts +51 -2
  114. package/src/database/migrations/20251212000000_0_init.ts +2 -1
  115. package/src/database/migrations/20251212000000_1_tables.ts +2 -1
  116. package/src/database/migrations/20251212000000_2_fk.ts +2 -1
  117. package/src/database/migrations/20251212000000_3_indexes.ts +2 -1
  118. package/src/database/pubsub.test.ts +6 -3
  119. package/src/database/pubsub.ts +55 -33
  120. package/src/execution.test.ts +117 -0
  121. package/src/execution.ts +65 -10
  122. package/src/internal.ts +21 -1
  123. package/src/practices/01-remote-workflow.ts +1 -0
  124. package/src/registry.test.ts +1 -0
  125. package/src/registry.ts +1 -1
  126. package/src/testing/connection.ts +3 -1
  127. package/src/worker.test.ts +2 -0
  128. package/src/worker.ts +31 -9
  129. package/src/workflow.test.ts +1 -0
  130. package/src/workflow.ts +5 -2
  131. package/templates/openworkflow.config.ts +2 -1
  132. package/tsdown.config.ts +31 -0
  133. package/.swcrc +0 -17
  134. package/dist/chaos.test.d.ts +0 -2
  135. package/dist/chaos.test.d.ts.map +0 -1
  136. package/dist/chaos.test.js +0 -92
  137. package/dist/chaos.test.js.map +0 -1
  138. package/dist/client.test.d.ts +0 -2
  139. package/dist/client.test.d.ts.map +0 -1
  140. package/dist/client.test.js +0 -340
  141. package/dist/client.test.js.map +0 -1
  142. package/dist/config.test.d.ts +0 -2
  143. package/dist/config.test.d.ts.map +0 -1
  144. package/dist/config.test.js +0 -24
  145. package/dist/config.test.js.map +0 -1
  146. package/dist/core/duration.test.d.ts +0 -2
  147. package/dist/core/duration.test.d.ts.map +0 -1
  148. package/dist/core/duration.test.js +0 -265
  149. package/dist/core/duration.test.js.map +0 -1
  150. package/dist/core/error.test.d.ts +0 -2
  151. package/dist/core/error.test.d.ts.map +0 -1
  152. package/dist/core/error.test.js +0 -63
  153. package/dist/core/error.test.js.map +0 -1
  154. package/dist/core/json.js +0 -3
  155. package/dist/core/json.js.map +0 -1
  156. package/dist/core/result.test.d.ts +0 -2
  157. package/dist/core/result.test.d.ts.map +0 -1
  158. package/dist/core/result.test.js +0 -19
  159. package/dist/core/result.test.js.map +0 -1
  160. package/dist/core/retry.test.d.ts +0 -2
  161. package/dist/core/retry.test.d.ts.map +0 -1
  162. package/dist/core/retry.test.js +0 -37
  163. package/dist/core/retry.test.js.map +0 -1
  164. package/dist/core/schema.js +0 -4
  165. package/dist/core/schema.js.map +0 -1
  166. package/dist/core/step.test.d.ts +0 -2
  167. package/dist/core/step.test.d.ts.map +0 -1
  168. package/dist/core/step.test.js +0 -356
  169. package/dist/core/step.test.js.map +0 -1
  170. package/dist/core/workflow.test.d.ts +0 -2
  171. package/dist/core/workflow.test.d.ts.map +0 -1
  172. package/dist/core/workflow.test.js +0 -172
  173. package/dist/core/workflow.test.js.map +0 -1
  174. package/dist/database/backend.test.d.ts +0 -2
  175. package/dist/database/backend.test.d.ts.map +0 -1
  176. package/dist/database/backend.test.js +0 -19
  177. package/dist/database/backend.test.js.map +0 -1
  178. package/dist/database/backend.testsuite.d.ts +0 -20
  179. package/dist/database/backend.testsuite.d.ts.map +0 -1
  180. package/dist/database/backend.testsuite.js +0 -1174
  181. package/dist/database/backend.testsuite.js.map +0 -1
  182. package/dist/database/base.d.ts +0 -12
  183. package/dist/database/base.d.ts.map +0 -1
  184. package/dist/database/pubsub.test.d.ts +0 -2
  185. package/dist/database/pubsub.test.d.ts.map +0 -1
  186. package/dist/database/pubsub.test.js +0 -86
  187. package/dist/database/pubsub.test.js.map +0 -1
  188. package/dist/execution.test.d.ts +0 -2
  189. package/dist/execution.test.d.ts.map +0 -1
  190. package/dist/execution.test.js +0 -558
  191. package/dist/execution.test.js.map +0 -1
  192. package/dist/index.d.ts.map +0 -1
  193. package/dist/index.js.map +0 -1
  194. package/dist/internal.d.ts.map +0 -1
  195. package/dist/internal.js.map +0 -1
  196. package/dist/practices/01-remote-workflow.d.ts +0 -2
  197. package/dist/practices/01-remote-workflow.d.ts.map +0 -1
  198. package/dist/practices/01-remote-workflow.js +0 -70
  199. package/dist/practices/01-remote-workflow.js.map +0 -1
  200. package/dist/registry.test.d.ts +0 -2
  201. package/dist/registry.test.d.ts.map +0 -1
  202. package/dist/registry.test.js +0 -95
  203. package/dist/registry.test.js.map +0 -1
  204. package/dist/testing/connection.d.ts +0 -7
  205. package/dist/testing/connection.d.ts.map +0 -1
  206. package/dist/testing/connection.js +0 -39
  207. package/dist/testing/connection.js.map +0 -1
  208. package/dist/worker.test.d.ts +0 -2
  209. package/dist/worker.test.d.ts.map +0 -1
  210. package/dist/worker.test.js +0 -1164
  211. package/dist/worker.test.js.map +0 -1
  212. package/dist/workflow.test.d.ts +0 -2
  213. package/dist/workflow.test.d.ts.map +0 -1
  214. package/dist/workflow.test.js +0 -73
  215. package/dist/workflow.test.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import type { Result } from "./result";
1
+ //#region src/core/duration.d.ts
2
2
  type Years = "years" | "year" | "yrs" | "yr" | "y";
3
3
  type Months = "months" | "month" | "mo";
4
4
  type Weeks = "weeks" | "week" | "w";
@@ -9,7 +9,7 @@ type Seconds = "seconds" | "second" | "secs" | "sec" | "s";
9
9
  type Milliseconds = "milliseconds" | "millisecond" | "msecs" | "msec" | "ms";
10
10
  type Unit = Years | Months | Weeks | Days | Hours | Minutes | Seconds | Milliseconds;
11
11
  type UnitAnyCase = Capitalize<Unit> | Uppercase<Unit> | Lowercase<Unit>;
12
- export type DurationString = `${number}` | `${number}${UnitAnyCase}` | `${number} ${UnitAnyCase}`;
12
+ type DurationString = `${number}` | `${number}${UnitAnyCase}` | `${number} ${UnitAnyCase}`;
13
13
  /**
14
14
  * Parse a duration string into milliseconds. Examples:
15
15
  * - short units: "1ms", "5s", "30m", "2h", "7d", "3w", "1y"
@@ -17,6 +17,7 @@ export type DurationString = `${number}` | `${number}${UnitAnyCase}` | `${number
17
17
  * @param str - Duration string
18
18
  * @returns Milliseconds
19
19
  */
20
- export declare function parseDuration(str: DurationString): Result<number>;
21
- export {};
20
+
21
+ //#endregion
22
+ export { DurationString };
22
23
  //# sourceMappingURL=duration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/core/duration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGvC,KAAK,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC;AACnD,KAAK,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC;AACxC,KAAK,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,GAAG,CAAC;AACpC,KAAK,IAAI,GAAG,MAAM,GAAG,KAAK,GAAG,GAAG,CAAC;AACjC,KAAK,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC;AACnD,KAAK,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,GAAG,CAAC;AAC3D,KAAK,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,GAAG,CAAC;AAC3D,KAAK,YAAY,GAAG,cAAc,GAAG,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;AAC7E,KAAK,IAAI,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,YAAY,CAAC;AACrF,KAAK,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AACxE,MAAM,MAAM,cAAc,GAAG,GAAG,MAAM,EAAE,GAAG,GAAG,MAAM,GAAG,WAAW,EAAE,GAAG,GAAG,MAAM,IAAI,WAAW,EAAE,CAAC;AAElG;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,CA+DjE"}
1
+ {"version":3,"file":"duration.d.ts","names":[],"sources":["../../src/core/duration.ts"],"sourcesContent":[],"mappings":";AAAuC,KAGlC,KAAA,GAAK,OAAA,GAAA,MAAA,GAAA,KAAA,GAAA,IAAA,GAAA,GAAA;AAAA,KACL,MAAA,GAAM,QAAA,GAAA,OAAA,GAAA,IAAA;AAAA,KACN,KAAA,GAAK,OAAA,GAAA,MAAA,GAAA,GAAA;AAAA,KACL,IAAA,GAAI,MAAA,GAAA,KAAA,GAAA,GAAA;AAAA,KACJ,KAAA,GAAK,OAAA,GAAA,MAAA,GAAA,KAAA,GAAA,IAAA,GAAA,GAAA;AAAA,KACL,OAAA,GAAO,SAAA,GAAA,QAAA,GAAA,MAAA,GAAA,KAAA,GAAA,GAAA;AAAA,KACP,OAAA,GAAO,SAAA,GAAA,QAAA,GAAA,MAAA,GAAA,KAAA,GAAA,GAAA;AAAA,KACP,YAAA,GAAY,cAAA,GAAA,aAAA,GAAA,OAAA,GAAA,MAAA,GAAA,IAAA;AAAA,KACZ,IAAA,GAAO,KAAH,GAAW,MAAX,GAAoB,KAApB,GAA4B,IAA5B,GAAmC,KAAnC,GAA2C,OAA3C,GAAqD,OAArD,GAA+D,YAA/D;KACJ,WAAA,GAAc,UADV,CACqB,IADrB,CAAA,GAC6B,SAD7B,CACuC,IADvC,CAAA,GAC+C,SAD/C,CACyD,IADzD,CAAA;AAAG,KAEA,cAAA,GAFA,GAAA,MAAA,EAAA,GAAA,GAAA,MAAA,GAE2C,WAF3C,EAAA,GAAA,GAAA,MAAA,IAEwE,WAFxE,EAAA"}
@@ -1,64 +1,59 @@
1
1
  import { err, ok } from "./result.js";
2
+
3
+ //#region src/core/duration.ts
2
4
  /**
3
- * Parse a duration string into milliseconds. Examples:
4
- * - short units: "1ms", "5s", "30m", "2h", "7d", "3w", "1y"
5
- * - long units: "1 millisecond", "5 seconds", "30 minutes", "2 hours", "7 days", "3 weeks", "1 year"
6
- * @param str - Duration string
7
- * @returns Milliseconds
8
- */ export function parseDuration(str) {
9
- if (typeof str !== "string") {
10
- return err(new TypeError(`Invalid duration format: expected a string but received ${typeof str}`));
11
- }
12
- if (str.length === 0) {
13
- return err(new Error('Invalid duration format: ""'));
14
- }
15
- const match = /^(-?\.?\d+(?:\.\d+)?)\s*([a-z]+)?$/i.exec(str);
16
- if (!match?.[1]) {
17
- return err(new Error(`Invalid duration format: "${str}"`));
18
- }
19
- const numValue = Number.parseFloat(match[1]);
20
- const unit = match[2]?.toLowerCase() ?? "ms"; // default to ms if not provided
21
- const multipliers = {
22
- millisecond: 1,
23
- milliseconds: 1,
24
- msec: 1,
25
- msecs: 1,
26
- ms: 1,
27
- second: 1000,
28
- seconds: 1000,
29
- sec: 1000,
30
- secs: 1000,
31
- s: 1000,
32
- minute: 60 * 1000,
33
- minutes: 60 * 1000,
34
- min: 60 * 1000,
35
- mins: 60 * 1000,
36
- m: 60 * 1000,
37
- hour: 60 * 60 * 1000,
38
- hours: 60 * 60 * 1000,
39
- hr: 60 * 60 * 1000,
40
- hrs: 60 * 60 * 1000,
41
- h: 60 * 60 * 1000,
42
- day: 24 * 60 * 60 * 1000,
43
- days: 24 * 60 * 60 * 1000,
44
- d: 24 * 60 * 60 * 1000,
45
- week: 7 * 24 * 60 * 60 * 1000,
46
- weeks: 7 * 24 * 60 * 60 * 1000,
47
- w: 7 * 24 * 60 * 60 * 1000,
48
- month: 2_629_800_000,
49
- months: 2_629_800_000,
50
- mo: 2_629_800_000,
51
- year: 31_557_600_000,
52
- years: 31_557_600_000,
53
- yr: 31_557_600_000,
54
- yrs: 31_557_600_000,
55
- y: 31_557_600_000
56
- };
57
- const multiplier = multipliers[unit];
58
- if (multiplier === undefined) {
59
- return err(new Error(`Invalid duration format: "${str}"`));
60
- }
61
- return ok(numValue * multiplier);
5
+ * Parse a duration string into milliseconds. Examples:
6
+ * - short units: "1ms", "5s", "30m", "2h", "7d", "3w", "1y"
7
+ * - long units: "1 millisecond", "5 seconds", "30 minutes", "2 hours", "7 days", "3 weeks", "1 year"
8
+ * @param str - Duration string
9
+ * @returns Milliseconds
10
+ */
11
+ function parseDuration(str) {
12
+ if (typeof str !== "string") return err(/* @__PURE__ */ new TypeError(`Invalid duration format: expected a string but received ${typeof str}`));
13
+ if (str.length === 0) return err(/* @__PURE__ */ new Error("Invalid duration format: \"\""));
14
+ const match = /^(-?\.?\d+(?:\.\d+)?)\s*([a-z]+)?$/i.exec(str);
15
+ if (!match?.[1]) return err(/* @__PURE__ */ new Error(`Invalid duration format: "${str}"`));
16
+ const numValue = Number.parseFloat(match[1]);
17
+ const multiplier = {
18
+ millisecond: 1,
19
+ milliseconds: 1,
20
+ msec: 1,
21
+ msecs: 1,
22
+ ms: 1,
23
+ second: 1e3,
24
+ seconds: 1e3,
25
+ sec: 1e3,
26
+ secs: 1e3,
27
+ s: 1e3,
28
+ minute: 60 * 1e3,
29
+ minutes: 60 * 1e3,
30
+ min: 60 * 1e3,
31
+ mins: 60 * 1e3,
32
+ m: 60 * 1e3,
33
+ hour: 3600 * 1e3,
34
+ hours: 3600 * 1e3,
35
+ hr: 3600 * 1e3,
36
+ hrs: 3600 * 1e3,
37
+ h: 3600 * 1e3,
38
+ day: 1440 * 60 * 1e3,
39
+ days: 1440 * 60 * 1e3,
40
+ d: 1440 * 60 * 1e3,
41
+ week: 10080 * 60 * 1e3,
42
+ weeks: 10080 * 60 * 1e3,
43
+ w: 10080 * 60 * 1e3,
44
+ month: 26298e5,
45
+ months: 26298e5,
46
+ mo: 26298e5,
47
+ year: 315576e5,
48
+ years: 315576e5,
49
+ yr: 315576e5,
50
+ yrs: 315576e5,
51
+ y: 315576e5
52
+ }[match[2]?.toLowerCase() ?? "ms"];
53
+ if (multiplier === void 0) return err(/* @__PURE__ */ new Error(`Invalid duration format: "${str}"`));
54
+ return ok(numValue * multiplier);
62
55
  }
63
56
 
57
+ //#endregion
58
+ export { parseDuration };
64
59
  //# sourceMappingURL=duration.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/duration.ts"],"sourcesContent":["import type { Result } from \"./result\";\nimport { err, ok } from \"./result\";\n\ntype Years = \"years\" | \"year\" | \"yrs\" | \"yr\" | \"y\";\ntype Months = \"months\" | \"month\" | \"mo\";\ntype Weeks = \"weeks\" | \"week\" | \"w\";\ntype Days = \"days\" | \"day\" | \"d\";\ntype Hours = \"hours\" | \"hour\" | \"hrs\" | \"hr\" | \"h\";\ntype Minutes = \"minutes\" | \"minute\" | \"mins\" | \"min\" | \"m\";\ntype Seconds = \"seconds\" | \"second\" | \"secs\" | \"sec\" | \"s\";\ntype Milliseconds = \"milliseconds\" | \"millisecond\" | \"msecs\" | \"msec\" | \"ms\";\ntype Unit = Years | Months | Weeks | Days | Hours | Minutes | Seconds | Milliseconds;\ntype UnitAnyCase = Capitalize<Unit> | Uppercase<Unit> | Lowercase<Unit>;\nexport type DurationString = `${number}` | `${number}${UnitAnyCase}` | `${number} ${UnitAnyCase}`;\n\n/**\n * Parse a duration string into milliseconds. Examples:\n * - short units: \"1ms\", \"5s\", \"30m\", \"2h\", \"7d\", \"3w\", \"1y\"\n * - long units: \"1 millisecond\", \"5 seconds\", \"30 minutes\", \"2 hours\", \"7 days\", \"3 weeks\", \"1 year\"\n * @param str - Duration string\n * @returns Milliseconds\n */\nexport function parseDuration(str: DurationString): Result<number> {\n if (typeof str !== \"string\") {\n return err(\n new TypeError(`Invalid duration format: expected a string but received ${typeof str}`),\n );\n }\n\n if (str.length === 0) {\n return err(new Error('Invalid duration format: \"\"'));\n }\n\n const match = /^(-?\\.?\\d+(?:\\.\\d+)?)\\s*([a-z]+)?$/i.exec(str);\n\n if (!match?.[1]) {\n return err(new Error(`Invalid duration format: \"${str}\"`));\n }\n\n const numValue = Number.parseFloat(match[1]);\n const unit = match[2]?.toLowerCase() ?? \"ms\"; // default to ms if not provided\n\n const multipliers: Record<string, number> = {\n millisecond: 1,\n milliseconds: 1,\n msec: 1,\n msecs: 1,\n ms: 1,\n second: 1000,\n seconds: 1000,\n sec: 1000,\n secs: 1000,\n s: 1000,\n minute: 60 * 1000,\n minutes: 60 * 1000,\n min: 60 * 1000,\n mins: 60 * 1000,\n m: 60 * 1000,\n hour: 60 * 60 * 1000,\n hours: 60 * 60 * 1000,\n hr: 60 * 60 * 1000,\n hrs: 60 * 60 * 1000,\n h: 60 * 60 * 1000,\n day: 24 * 60 * 60 * 1000,\n days: 24 * 60 * 60 * 1000,\n d: 24 * 60 * 60 * 1000,\n week: 7 * 24 * 60 * 60 * 1000,\n weeks: 7 * 24 * 60 * 60 * 1000,\n w: 7 * 24 * 60 * 60 * 1000,\n month: 2_629_800_000,\n months: 2_629_800_000,\n mo: 2_629_800_000,\n year: 31_557_600_000,\n years: 31_557_600_000,\n yr: 31_557_600_000,\n yrs: 31_557_600_000,\n y: 31_557_600_000,\n };\n\n const multiplier = multipliers[unit];\n if (multiplier === undefined) {\n return err(new Error(`Invalid duration format: \"${str}\"`));\n }\n\n return ok(numValue * multiplier);\n}\n"],"names":["err","ok","parseDuration","str","TypeError","length","Error","match","exec","numValue","Number","parseFloat","unit","toLowerCase","multipliers","millisecond","milliseconds","msec","msecs","ms","second","seconds","sec","secs","s","minute","minutes","min","mins","m","hour","hours","hr","hrs","h","day","days","d","week","weeks","w","month","months","mo","year","years","yr","yrs","y","multiplier","undefined"],"mappings":"AACA,SAASA,GAAG,EAAEC,EAAE,QAAQ,cAAW;AAcnC;;;;;;CAMC,GACD,OAAO,SAASC,cAAcC,GAAmB;IAC/C,IAAI,OAAOA,QAAQ,UAAU;QAC3B,OAAOH,IACL,IAAII,UAAU,CAAC,wDAAwD,EAAE,OAAOD,KAAK;IAEzF;IAEA,IAAIA,IAAIE,MAAM,KAAK,GAAG;QACpB,OAAOL,IAAI,IAAIM,MAAM;IACvB;IAEA,MAAMC,QAAQ,sCAAsCC,IAAI,CAACL;IAEzD,IAAI,CAACI,OAAO,CAAC,EAAE,EAAE;QACf,OAAOP,IAAI,IAAIM,MAAM,CAAC,0BAA0B,EAAEH,IAAI,CAAC,CAAC;IAC1D;IAEA,MAAMM,WAAWC,OAAOC,UAAU,CAACJ,KAAK,CAAC,EAAE;IAC3C,MAAMK,OAAOL,KAAK,CAAC,EAAE,EAAEM,iBAAiB,MAAM,gCAAgC;IAE9E,MAAMC,cAAsC;QAC1CC,aAAa;QACbC,cAAc;QACdC,MAAM;QACNC,OAAO;QACPC,IAAI;QACJC,QAAQ;QACRC,SAAS;QACTC,KAAK;QACLC,MAAM;QACNC,GAAG;QACHC,QAAQ,KAAK;QACbC,SAAS,KAAK;QACdC,KAAK,KAAK;QACVC,MAAM,KAAK;QACXC,GAAG,KAAK;QACRC,MAAM,KAAK,KAAK;QAChBC,OAAO,KAAK,KAAK;QACjBC,IAAI,KAAK,KAAK;QACdC,KAAK,KAAK,KAAK;QACfC,GAAG,KAAK,KAAK;QACbC,KAAK,KAAK,KAAK,KAAK;QACpBC,MAAM,KAAK,KAAK,KAAK;QACrBC,GAAG,KAAK,KAAK,KAAK;QAClBC,MAAM,IAAI,KAAK,KAAK,KAAK;QACzBC,OAAO,IAAI,KAAK,KAAK,KAAK;QAC1BC,GAAG,IAAI,KAAK,KAAK,KAAK;QACtBC,OAAO;QACPC,QAAQ;QACRC,IAAI;QACJC,MAAM;QACNC,OAAO;QACPC,IAAI;QACJC,KAAK;QACLC,GAAG;IACL;IAEA,MAAMC,aAAanC,WAAW,CAACF,KAAK;IACpC,IAAIqC,eAAeC,WAAW;QAC5B,OAAOlD,IAAI,IAAIM,MAAM,CAAC,0BAA0B,EAAEH,IAAI,CAAC,CAAC;IAC1D;IAEA,OAAOF,GAAGQ,WAAWwC;AACvB"}
1
+ {"version":3,"file":"duration.js","names":[],"sources":["../../src/core/duration.ts"],"sourcesContent":["import { type Result } from \"./result\";\nimport { err, ok } from \"./result\";\n\ntype Years = \"years\" | \"year\" | \"yrs\" | \"yr\" | \"y\";\ntype Months = \"months\" | \"month\" | \"mo\";\ntype Weeks = \"weeks\" | \"week\" | \"w\";\ntype Days = \"days\" | \"day\" | \"d\";\ntype Hours = \"hours\" | \"hour\" | \"hrs\" | \"hr\" | \"h\";\ntype Minutes = \"minutes\" | \"minute\" | \"mins\" | \"min\" | \"m\";\ntype Seconds = \"seconds\" | \"second\" | \"secs\" | \"sec\" | \"s\";\ntype Milliseconds = \"milliseconds\" | \"millisecond\" | \"msecs\" | \"msec\" | \"ms\";\ntype Unit = Years | Months | Weeks | Days | Hours | Minutes | Seconds | Milliseconds;\ntype UnitAnyCase = Capitalize<Unit> | Uppercase<Unit> | Lowercase<Unit>;\nexport type DurationString = `${number}` | `${number}${UnitAnyCase}` | `${number} ${UnitAnyCase}`;\n\n/**\n * Parse a duration string into milliseconds. Examples:\n * - short units: \"1ms\", \"5s\", \"30m\", \"2h\", \"7d\", \"3w\", \"1y\"\n * - long units: \"1 millisecond\", \"5 seconds\", \"30 minutes\", \"2 hours\", \"7 days\", \"3 weeks\", \"1 year\"\n * @param str - Duration string\n * @returns Milliseconds\n */\nexport function parseDuration(str: DurationString): Result<number> {\n if (typeof str !== \"string\") {\n return err(\n new TypeError(`Invalid duration format: expected a string but received ${typeof str}`),\n );\n }\n\n if (str.length === 0) {\n return err(new Error('Invalid duration format: \"\"'));\n }\n\n const match = /^(-?\\.?\\d+(?:\\.\\d+)?)\\s*([a-z]+)?$/i.exec(str);\n\n if (!match?.[1]) {\n return err(new Error(`Invalid duration format: \"${str}\"`));\n }\n\n const numValue = Number.parseFloat(match[1]);\n const unit = match[2]?.toLowerCase() ?? \"ms\"; // default to ms if not provided\n\n const multipliers: Record<string, number> = {\n millisecond: 1,\n milliseconds: 1,\n msec: 1,\n msecs: 1,\n ms: 1,\n second: 1000,\n seconds: 1000,\n sec: 1000,\n secs: 1000,\n s: 1000,\n minute: 60 * 1000,\n minutes: 60 * 1000,\n min: 60 * 1000,\n mins: 60 * 1000,\n m: 60 * 1000,\n hour: 60 * 60 * 1000,\n hours: 60 * 60 * 1000,\n hr: 60 * 60 * 1000,\n hrs: 60 * 60 * 1000,\n h: 60 * 60 * 1000,\n day: 24 * 60 * 60 * 1000,\n days: 24 * 60 * 60 * 1000,\n d: 24 * 60 * 60 * 1000,\n week: 7 * 24 * 60 * 60 * 1000,\n weeks: 7 * 24 * 60 * 60 * 1000,\n w: 7 * 24 * 60 * 60 * 1000,\n month: 2_629_800_000,\n months: 2_629_800_000,\n mo: 2_629_800_000,\n year: 31_557_600_000,\n years: 31_557_600_000,\n yr: 31_557_600_000,\n yrs: 31_557_600_000,\n y: 31_557_600_000,\n };\n\n const multiplier = multipliers[unit];\n if (multiplier === undefined) {\n return err(new Error(`Invalid duration format: \"${str}\"`));\n }\n\n return ok(numValue * multiplier);\n}\n"],"mappings":";;;;;;;;;;AAsBA,SAAgB,cAAc,KAAqC;AACjE,KAAI,OAAO,QAAQ,SACjB,QAAO,oBACL,IAAI,UAAU,2DAA2D,OAAO,MAAM,CACvF;AAGH,KAAI,IAAI,WAAW,EACjB,QAAO,oBAAI,IAAI,MAAM,gCAA8B,CAAC;CAGtD,MAAM,QAAQ,sCAAsC,KAAK,IAAI;AAE7D,KAAI,CAAC,QAAQ,GACX,QAAO,oBAAI,IAAI,MAAM,6BAA6B,IAAI,GAAG,CAAC;CAG5D,MAAM,WAAW,OAAO,WAAW,MAAM,GAAG;CAwC5C,MAAM,aArCsC;EAC1C,aAAa;EACb,cAAc;EACd,MAAM;EACN,OAAO;EACP,IAAI;EACJ,QAAQ;EACR,SAAS;EACT,KAAK;EACL,MAAM;EACN,GAAG;EACH,QAAQ,KAAK;EACb,SAAS,KAAK;EACd,KAAK,KAAK;EACV,MAAM,KAAK;EACX,GAAG,KAAK;EACR,MAAM,OAAU;EAChB,OAAO,OAAU;EACjB,IAAI,OAAU;EACd,KAAK,OAAU;EACf,GAAG,OAAU;EACb,KAAK,OAAU,KAAK;EACpB,MAAM,OAAU,KAAK;EACrB,GAAG,OAAU,KAAK;EAClB,MAAM,QAAc,KAAK;EACzB,OAAO,QAAc,KAAK;EAC1B,GAAG,QAAc,KAAK;EACtB,OAAO;EACP,QAAQ;EACR,IAAI;EACJ,MAAM;EACN,OAAO;EACP,IAAI;EACJ,KAAK;EACL,GAAG;EACJ,CArCY,MAAM,IAAI,aAAa,IAAI;AAwCxC,KAAI,eAAe,OACjB,QAAO,oBAAI,IAAI,MAAM,6BAA6B,IAAI,GAAG,CAAC;AAG5D,QAAO,GAAG,WAAW,WAAW"}
@@ -1,15 +1,18 @@
1
- import type { JsonValue } from "./json";
2
- export type SerializedError = {
3
- name?: string;
4
- message: string;
5
- stack?: string;
1
+ import { JsonValue } from "./json.js";
2
+
3
+ //#region src/core/error.d.ts
4
+ type SerializedError = {
5
+ name?: string;
6
+ message: string;
7
+ stack?: string;
6
8
  } & {
7
- [key: string]: JsonValue;
9
+ [key: string]: JsonValue;
8
10
  };
9
11
  /**
10
12
  * Serialize an error to a JSON-compatible format.
11
13
  * @param error - The error to serialize (can be Error instance or any value)
12
14
  * @returns A JSON-serializable error object
13
15
  */
14
- export declare function serializeError(error: unknown): SerializedError;
16
+ //#endregion
17
+ export { SerializedError };
15
18
  //# sourceMappingURL=error.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/core/error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAc9D"}
1
+ {"version":3,"file":"error.d.ts","names":[],"sources":["../../src/core/error.ts"],"sourcesContent":[],"mappings":";;;KAEY,eAAA;;EAAA,OAAA,EAAA,MAAA;;;iBAKK"}
@@ -1,25 +1,25 @@
1
+ //#region src/core/error.ts
1
2
  /**
2
- * Serialize an error to a JSON-compatible format.
3
- * @param error - The error to serialize (can be Error instance or any value)
4
- * @returns A JSON-serializable error object
5
- */ export function serializeError(error) {
6
- if (error instanceof Error) {
7
- const { name, message, stack } = error;
8
- if (stack) {
9
- return {
10
- name,
11
- message,
12
- stack
13
- };
14
- }
15
- return {
16
- name,
17
- message
18
- };
19
- }
20
- return {
21
- message: String(error)
22
- };
3
+ * Serialize an error to a JSON-compatible format.
4
+ * @param error - The error to serialize (can be Error instance or any value)
5
+ * @returns A JSON-serializable error object
6
+ */
7
+ function serializeError(error) {
8
+ if (error instanceof Error) {
9
+ const { name, message, stack } = error;
10
+ if (stack) return {
11
+ name,
12
+ message,
13
+ stack
14
+ };
15
+ return {
16
+ name,
17
+ message
18
+ };
19
+ }
20
+ return { message: String(error) };
23
21
  }
24
22
 
23
+ //#endregion
24
+ export { serializeError };
25
25
  //# sourceMappingURL=error.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/error.ts"],"sourcesContent":["import type { JsonValue } from \"./json\";\n\nexport type SerializedError = {\n name?: string;\n message: string;\n stack?: string;\n} & {\n [key: string]: JsonValue;\n};\n\n/**\n * Serialize an error to a JSON-compatible format.\n * @param error - The error to serialize (can be Error instance or any value)\n * @returns A JSON-serializable error object\n */\nexport function serializeError(error: unknown): SerializedError {\n if (error instanceof Error) {\n const { name, message, stack } = error;\n\n if (stack) {\n return { name, message, stack };\n }\n\n return { name, message };\n }\n\n return {\n message: String(error),\n };\n}\n"],"names":["serializeError","error","Error","name","message","stack","String"],"mappings":"AAUA;;;;CAIC,GACD,OAAO,SAASA,eAAeC,KAAc;IAC3C,IAAIA,iBAAiBC,OAAO;QAC1B,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,KAAK,EAAE,GAAGJ;QAEjC,IAAII,OAAO;YACT,OAAO;gBAAEF;gBAAMC;gBAASC;YAAM;QAChC;QAEA,OAAO;YAAEF;YAAMC;QAAQ;IACzB;IAEA,OAAO;QACLA,SAASE,OAAOL;IAClB;AACF"}
1
+ {"version":3,"file":"error.js","names":[],"sources":["../../src/core/error.ts"],"sourcesContent":["import { type JsonValue } from \"./json\";\n\nexport type SerializedError = {\n name?: string;\n message: string;\n stack?: string;\n} & {\n [key: string]: JsonValue;\n};\n\n/**\n * Serialize an error to a JSON-compatible format.\n * @param error - The error to serialize (can be Error instance or any value)\n * @returns A JSON-serializable error object\n */\nexport function serializeError(error: unknown): SerializedError {\n if (error instanceof Error) {\n const { name, message, stack } = error;\n\n if (stack) {\n return { name, message, stack };\n }\n\n return { name, message };\n }\n\n return {\n message: String(error),\n };\n}\n"],"mappings":";;;;;;AAeA,SAAgB,eAAe,OAAiC;AAC9D,KAAI,iBAAiB,OAAO;EAC1B,MAAM,EAAE,MAAM,SAAS,UAAU;AAEjC,MAAI,MACF,QAAO;GAAE;GAAM;GAAS;GAAO;AAGjC,SAAO;GAAE;GAAM;GAAS;;AAG1B,QAAO,EACL,SAAS,OAAO,MAAM,EACvB"}
@@ -1,5 +1,10 @@
1
- export type JsonPrimitive = string | number | boolean | null;
2
- export type JsonValue = JsonPrimitive | JsonValue[] | {
3
- [key: string]: JsonValue;
1
+ //#region src/core/json.d.ts
2
+ type JsonPrimitive = string | number | boolean | null;
3
+ type JsonValue = JsonPrimitive | JsonValue[] | {
4
+ [key: string]: JsonValue;
4
5
  };
6
+ //# sourceMappingURL=json.d.ts.map
7
+
8
+ //#endregion
9
+ export { JsonValue };
5
10
  //# sourceMappingURL=json.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"json.d.ts","names":[],"sources":["../../src/core/json.ts"],"sourcesContent":[],"mappings":";KAAY,aAAA;AAAA,KACA,SAAA,GAAY,aADC,GACe,SADf,EAAA,GAAA;EACb,CAAA,GAAA,EAAA,MAAS,CAAA,EAAkD,SAAlD;CAAA"}
@@ -1,22 +1,18 @@
1
- export type Result<T> = Ok<T> | Err;
2
- export interface Ok<T> {
3
- ok: true;
4
- value: T;
1
+ //#region src/core/result.d.ts
2
+ type Result<T> = Ok<T> | Err;
3
+ interface Ok<T> {
4
+ ok: true;
5
+ value: T;
5
6
  }
6
- export interface Err {
7
- ok: false;
8
- error: Error;
7
+ interface Err {
8
+ ok: false;
9
+ error: Error;
9
10
  }
10
11
  /**
11
12
  * Create an Ok result.
12
13
  * @param value - Result value
13
14
  * @returns Ok result
14
15
  */
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;
16
+ //#endregion
17
+ export { Result };
22
18
  //# sourceMappingURL=result.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"result.d.ts","names":[],"sources":["../../src/core/result.ts"],"sourcesContent":[],"mappings":";KAAY,YAAY,GAAG,KAAK;AAApB,UAEK,EAFC,CAAA,CAAA,CAAA,CAAA;EAAA,EAAA,EAAA,IAAA;OAAS,EAIlB,CAJkB;;AAAK,UAOf,GAAA,CAPe;EAAG,EAAA,EAAA,KAAA;EAElB,KAAE,EAOV,KAPU;AAKnB"}
@@ -1,22 +1,27 @@
1
+ //#region src/core/result.ts
1
2
  /**
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
- };
3
+ * Create an Ok result.
4
+ * @param value - Result value
5
+ * @returns Ok result
6
+ */
7
+ function ok(value) {
8
+ return {
9
+ ok: true,
10
+ value
11
+ };
10
12
  }
11
13
  /**
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
- };
14
+ * Create an Err result.
15
+ * @param error - Result error
16
+ * @returns Err result
17
+ */
18
+ function err(error) {
19
+ return {
20
+ ok: false,
21
+ error
22
+ };
20
23
  }
21
24
 
25
+ //#endregion
26
+ export { err, ok };
22
27
  //# sourceMappingURL=result.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"result.js","names":[],"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"],"mappings":";;;;;;AAiBA,SAAgB,GAAM,OAAiB;AACrC,QAAO;EAAE,IAAI;EAAM;EAAO;;;;;;;AAQ5B,SAAgB,IAAI,OAA6B;AAC/C,QAAO;EAAE,IAAI;EAAO;EAAO"}
@@ -1,21 +1,43 @@
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;
1
+ import { SerializedError } from "./error.js";
2
+
3
+ //#region src/core/retry.d.ts
4
+ interface RetryDecision {
5
+ shouldRetry: boolean;
6
+ delayMs: number;
7
+ }
8
+ type RetryDecisionFn = (error: SerializedError, attempt: number) => RetryDecision;
9
+ interface StaticRetryPolicy {
10
+ maxAttempts?: number;
11
+ initialIntervalMs?: number;
12
+ backoffCoefficient?: number;
13
+ maximumIntervalMs?: number;
14
+ }
15
+ interface DynamicRetryPolicy {
16
+ maxAttempts?: number;
17
+ shouldRetry: RetryDecisionFn;
18
+ }
19
+ type RetryPolicy = StaticRetryPolicy | DynamicRetryPolicy;
20
+ interface SerializableRetryPolicy extends StaticRetryPolicy {
21
+ hasDynamicPolicy?: boolean;
22
+ }
23
+ type MergedStaticRetryPolicy = Required<StaticRetryPolicy>;
24
+ interface MergedDynamicRetryPolicy {
25
+ maxAttempts: number;
26
+ shouldRetry: RetryDecisionFn;
27
+ }
28
+ type MergedRetryPolicy = MergedStaticRetryPolicy | MergedDynamicRetryPolicy;
29
+ declare const DEFAULT_RETRY_POLICY: Required<StaticRetryPolicy>;
30
+ declare function isDynamicRetryPolicy(policy: RetryPolicy): policy is DynamicRetryPolicy;
31
+ declare function isStaticRetryPolicy(policy: RetryPolicy): policy is StaticRetryPolicy;
32
+ declare function calculateRetryDelayMs(attemptNumber: number): number;
33
+ declare function shouldRetry(retryPolicy: StaticRetryPolicy, attemptNumber: number): boolean;
34
+ declare function shouldRetryByPolicy(policy: StaticRetryPolicy, attemptNumber: number): boolean;
35
+ declare function mergeRetryPolicy(policy: StaticRetryPolicy | undefined): MergedStaticRetryPolicy;
36
+ declare function mergeRetryPolicy(policy: DynamicRetryPolicy): MergedDynamicRetryPolicy;
37
+ declare function mergeRetryPolicy(policy?: RetryPolicy): MergedRetryPolicy;
38
+ declare function serializeRetryPolicy(policy?: RetryPolicy): SerializableRetryPolicy;
39
+ //# sourceMappingURL=retry.d.ts.map
40
+
41
+ //#endregion
42
+ export { DEFAULT_RETRY_POLICY, DynamicRetryPolicy, MergedDynamicRetryPolicy, MergedRetryPolicy, MergedStaticRetryPolicy, RetryDecision, RetryDecisionFn, RetryPolicy, SerializableRetryPolicy, StaticRetryPolicy, calculateRetryDelayMs, isDynamicRetryPolicy, isStaticRetryPolicy, mergeRetryPolicy, serializeRetryPolicy, shouldRetry, shouldRetryByPolicy };
21
43
  //# sourceMappingURL=retry.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"retry.d.ts","names":[],"sources":["../../src/core/retry.ts"],"sourcesContent":[],"mappings":";;;UAEiB,aAAA;;EAAA,OAAA,EAAA,MAAA;AAKjB;AAA2B,KAAf,eAAA,GAAe,CAAA,KAAA,EAAW,eAAX,EAAA,OAAA,EAAA,MAAA,EAAA,GAAgD,aAAhD;AAAW,UAErB,iBAAA,CAFqB;aAAqC,CAAA,EAAA,MAAA;EAAa,iBAAA,CAAA,EAAA,MAAA;EAEvE,kBAAA,CAAA,EAAiB,MAAA;EAOjB,iBAAA,CAAA,EAAA,MAAkB;AAKnC;AAAuB,UALN,kBAAA,CAKM;aAAG,CAAA,EAAA,MAAA;aAAoB,EAH/B,eAG+B;;AAE7B,KAFL,WAAA,GAAc,iBAEuB,GAFH,kBAEoB;AAItD,UAJK,uBAAA,SAAgC,iBAId,CAAA;EAAA,gBAAA,CAAA,EAAA,OAAA;;AAAG,KAA1B,uBAAA,GAA0B,QAAA,CAAS,iBAAT,CAAA;AAAQ,UAE7B,wBAAA,CAF6B;EAE7B,WAAA,EAAA,MAAA;EAKL,WAAA,EAHG,eAGc;;AAAG,KAApB,iBAAA,GAAoB,uBAAA,GAA0B,wBAA1B;AAA0B,cAE7C,oBAF6C,EAEvB,QAFuB,CAEd,iBAFc,CAAA;AAAwB,iBASlE,oBAAA,CATkE,MAAA,EASrC,WATqC,CAAA,EAAA,MAAA,IASb,kBATa;AAErE,iBAWG,mBAAA,CANf,MAAA,EAM2C,WAN3C,CAAA,EAAA,MAAA,IAMmE,iBANnE;AAAA,iBAUe,qBAAA,CAVf,aAAA,EAAA,MAAA,CAAA,EAAA,MAAA;AAL2C,iBAqB5B,WAAA,CArB4B,WAAA,EAqBH,iBArBG,EAAA,aAAA,EAAA,MAAA,CAAA,EAAA,OAAA;AAAT,iBA0BnB,mBAAA,CA1BmB,MAAA,EA0BS,iBA1BT,EAAA,aAAA,EAAA,MAAA,CAAA,EAAA,OAAA;AAAQ,iBA+B3B,gBAAA,CA/B2B,MAAA,EA+BF,iBA/BE,GAAA,SAAA,CAAA,EA+B8B,uBA/B9B;AAO3B,iBAyBA,gBAAA,CAzBoB,MAAA,EAyBK,kBAzBL,CAAA,EAyB0B,wBAzB1B;AAAA,iBA0BpB,gBAAA,CA1BoB,MAAA,CAAA,EA0BM,WA1BN,CAAA,EA0BoB,iBA1BpB;AAAS,iBA0C7B,oBAAA,CA1C6B,MAAA,CAAA,EA0CC,WA1CD,CAAA,EA0Ce,uBA1Cf"}
@@ -1,25 +1,54 @@
1
- export const DEFAULT_RETRY_POLICY = {
2
- initialIntervalMs: 1000,
3
- backoffCoefficient: 2,
4
- maximumIntervalMs: 100 * 1000,
5
- maximumAttempts: Infinity
1
+ //#region src/core/retry.ts
2
+ const DEFAULT_RETRY_POLICY = {
3
+ maxAttempts: 5,
4
+ initialIntervalMs: 1e3,
5
+ backoffCoefficient: 2,
6
+ maximumIntervalMs: 6e4
6
7
  };
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);
8
+ function isDynamicRetryPolicy(policy) {
9
+ return "shouldRetry" in policy && typeof policy.shouldRetry === "function";
15
10
  }
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;
11
+ function isStaticRetryPolicy(policy) {
12
+ return !isDynamicRetryPolicy(policy);
13
+ }
14
+ function calculateRetryDelayMs(attemptNumber) {
15
+ const { initialIntervalMs, backoffCoefficient, maximumIntervalMs } = DEFAULT_RETRY_POLICY;
16
+ const backoffMs = initialIntervalMs * backoffCoefficient ** (attemptNumber - 1);
17
+ return Math.min(backoffMs, maximumIntervalMs);
18
+ }
19
+ function shouldRetry(retryPolicy, attemptNumber) {
20
+ return attemptNumber < (retryPolicy.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts);
21
+ }
22
+ function shouldRetryByPolicy(policy, attemptNumber) {
23
+ return attemptNumber < (policy.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts);
24
+ }
25
+ function mergeRetryPolicy(policy) {
26
+ if (policy && isDynamicRetryPolicy(policy)) return {
27
+ maxAttempts: policy.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts,
28
+ shouldRetry: policy.shouldRetry
29
+ };
30
+ return {
31
+ maxAttempts: policy?.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts,
32
+ initialIntervalMs: policy?.initialIntervalMs ?? DEFAULT_RETRY_POLICY.initialIntervalMs,
33
+ backoffCoefficient: policy?.backoffCoefficient ?? DEFAULT_RETRY_POLICY.backoffCoefficient,
34
+ maximumIntervalMs: policy?.maximumIntervalMs ?? DEFAULT_RETRY_POLICY.maximumIntervalMs
35
+ };
36
+ }
37
+ function serializeRetryPolicy(policy) {
38
+ if (!policy) return { hasDynamicPolicy: false };
39
+ if (isDynamicRetryPolicy(policy)) return {
40
+ maxAttempts: policy.maxAttempts,
41
+ hasDynamicPolicy: true
42
+ };
43
+ return {
44
+ maxAttempts: policy.maxAttempts,
45
+ initialIntervalMs: policy.initialIntervalMs,
46
+ backoffCoefficient: policy.backoffCoefficient,
47
+ maximumIntervalMs: policy.maximumIntervalMs,
48
+ hasDynamicPolicy: false
49
+ };
23
50
  }
24
51
 
52
+ //#endregion
53
+ export { DEFAULT_RETRY_POLICY, calculateRetryDelayMs, isDynamicRetryPolicy, isStaticRetryPolicy, mergeRetryPolicy, serializeRetryPolicy, shouldRetry, shouldRetryByPolicy };
25
54
  //# sourceMappingURL=retry.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"retry.js","names":["DEFAULT_RETRY_POLICY: Required<StaticRetryPolicy>"],"sources":["../../src/core/retry.ts"],"sourcesContent":["import { type SerializedError } from \"./error\";\n\nexport interface RetryDecision {\n shouldRetry: boolean;\n delayMs: number;\n}\n\nexport type RetryDecisionFn = (error: SerializedError, attempt: number) => RetryDecision;\n\nexport interface StaticRetryPolicy {\n maxAttempts?: number;\n initialIntervalMs?: number;\n backoffCoefficient?: number;\n maximumIntervalMs?: number;\n}\n\nexport interface DynamicRetryPolicy {\n maxAttempts?: number;\n shouldRetry: RetryDecisionFn;\n}\n\nexport type RetryPolicy = StaticRetryPolicy | DynamicRetryPolicy;\n\nexport interface SerializableRetryPolicy extends StaticRetryPolicy {\n hasDynamicPolicy?: boolean;\n}\n\nexport type MergedStaticRetryPolicy = Required<StaticRetryPolicy>;\n\nexport interface MergedDynamicRetryPolicy {\n maxAttempts: number;\n shouldRetry: RetryDecisionFn;\n}\n\nexport type MergedRetryPolicy = MergedStaticRetryPolicy | MergedDynamicRetryPolicy;\n\nexport const DEFAULT_RETRY_POLICY: Required<StaticRetryPolicy> = {\n maxAttempts: 5,\n initialIntervalMs: 1000,\n backoffCoefficient: 2,\n maximumIntervalMs: 60_000,\n};\n\nexport function isDynamicRetryPolicy(policy: RetryPolicy): policy is DynamicRetryPolicy {\n return \"shouldRetry\" in policy && typeof policy.shouldRetry === \"function\";\n}\n\nexport function isStaticRetryPolicy(policy: RetryPolicy): policy is StaticRetryPolicy {\n return !isDynamicRetryPolicy(policy);\n}\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\nexport function shouldRetry(retryPolicy: StaticRetryPolicy, attemptNumber: number): boolean {\n const maxAttempts = retryPolicy.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts;\n return attemptNumber < maxAttempts;\n}\n\nexport function shouldRetryByPolicy(policy: StaticRetryPolicy, attemptNumber: number): boolean {\n const maxAttempts = policy.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts;\n return attemptNumber < maxAttempts;\n}\n\nexport function mergeRetryPolicy(policy: StaticRetryPolicy | undefined): MergedStaticRetryPolicy;\nexport function mergeRetryPolicy(policy: DynamicRetryPolicy): MergedDynamicRetryPolicy;\nexport function mergeRetryPolicy(policy?: RetryPolicy): MergedRetryPolicy;\nexport function mergeRetryPolicy(policy?: RetryPolicy): MergedRetryPolicy {\n if (policy && isDynamicRetryPolicy(policy)) {\n return {\n maxAttempts: policy.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts,\n shouldRetry: policy.shouldRetry,\n };\n }\n return {\n maxAttempts: policy?.maxAttempts ?? DEFAULT_RETRY_POLICY.maxAttempts,\n initialIntervalMs: policy?.initialIntervalMs ?? DEFAULT_RETRY_POLICY.initialIntervalMs,\n backoffCoefficient: policy?.backoffCoefficient ?? DEFAULT_RETRY_POLICY.backoffCoefficient,\n maximumIntervalMs: policy?.maximumIntervalMs ?? DEFAULT_RETRY_POLICY.maximumIntervalMs,\n };\n}\n\nexport function serializeRetryPolicy(policy?: RetryPolicy): SerializableRetryPolicy {\n if (!policy) {\n return { hasDynamicPolicy: false };\n }\n\n if (isDynamicRetryPolicy(policy)) {\n return {\n maxAttempts: policy.maxAttempts,\n hasDynamicPolicy: true,\n };\n }\n\n return {\n maxAttempts: policy.maxAttempts,\n initialIntervalMs: policy.initialIntervalMs,\n backoffCoefficient: policy.backoffCoefficient,\n maximumIntervalMs: policy.maximumIntervalMs,\n hasDynamicPolicy: false,\n };\n}\n"],"mappings":";AAoCA,MAAaA,uBAAoD;CAC/D,aAAa;CACb,mBAAmB;CACnB,oBAAoB;CACpB,mBAAmB;CACpB;AAED,SAAgB,qBAAqB,QAAmD;AACtF,QAAO,iBAAiB,UAAU,OAAO,OAAO,gBAAgB;;AAGlE,SAAgB,oBAAoB,QAAkD;AACpF,QAAO,CAAC,qBAAqB,OAAO;;AAGtC,SAAgB,sBAAsB,eAA+B;CACnE,MAAM,EAAE,mBAAmB,oBAAoB,sBAAsB;CACrE,MAAM,YAAY,oBAAoB,uBAAuB,gBAAgB;AAC7E,QAAO,KAAK,IAAI,WAAW,kBAAkB;;AAG/C,SAAgB,YAAY,aAAgC,eAAgC;AAE1F,QAAO,iBADa,YAAY,eAAe,qBAAqB;;AAItE,SAAgB,oBAAoB,QAA2B,eAAgC;AAE7F,QAAO,iBADa,OAAO,eAAe,qBAAqB;;AAOjE,SAAgB,iBAAiB,QAAyC;AACxE,KAAI,UAAU,qBAAqB,OAAO,CACxC,QAAO;EACL,aAAa,OAAO,eAAe,qBAAqB;EACxD,aAAa,OAAO;EACrB;AAEH,QAAO;EACL,aAAa,QAAQ,eAAe,qBAAqB;EACzD,mBAAmB,QAAQ,qBAAqB,qBAAqB;EACrE,oBAAoB,QAAQ,sBAAsB,qBAAqB;EACvE,mBAAmB,QAAQ,qBAAqB,qBAAqB;EACtE;;AAGH,SAAgB,qBAAqB,QAA+C;AAClF,KAAI,CAAC,OACH,QAAO,EAAE,kBAAkB,OAAO;AAGpC,KAAI,qBAAqB,OAAO,CAC9B,QAAO;EACL,aAAa,OAAO;EACpB,kBAAkB;EACnB;AAGH,QAAO;EACL,aAAa,OAAO;EACpB,mBAAmB,OAAO;EAC1B,oBAAoB,OAAO;EAC3B,mBAAmB,OAAO;EAC1B,kBAAkB;EACnB"}