awaitly 2.0.0 → 3.0.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 (88) hide show
  1. package/dist/di-Biw_plBn.d.cts +15 -0
  2. package/dist/di-DxyH2N3i.d.ts +15 -0
  3. package/dist/durable.cjs +4670 -0
  4. package/dist/durable.cjs.map +1 -0
  5. package/dist/durable.d.cts +9 -0
  6. package/dist/durable.d.ts +9 -0
  7. package/dist/durable.js +4610 -0
  8. package/dist/durable.js.map +1 -0
  9. package/dist/{di-BbFFfO8y.d.ts → duration-BjVn3QpB.d.cts} +1 -15
  10. package/dist/{di-BDlT7InM.d.cts → duration-BjVn3QpB.d.ts} +1 -15
  11. package/dist/engine.cjs +4501 -0
  12. package/dist/engine.cjs.map +1 -0
  13. package/dist/engine.d.cts +113 -0
  14. package/dist/engine.d.ts +113 -0
  15. package/dist/engine.js +4474 -0
  16. package/dist/engine.js.map +1 -0
  17. package/dist/{errors-DtXvrCiO.d.cts → errors-sDSeaZBO.d.cts} +1 -1
  18. package/dist/{errors-DtXvrCiO.d.ts → errors-sDSeaZBO.d.ts} +1 -1
  19. package/dist/guards-CwQZro1F.d.ts +72 -0
  20. package/dist/guards-DhhOJZda.d.cts +72 -0
  21. package/dist/hitl-BnnnLzh2.d.cts +468 -0
  22. package/dist/hitl-pYfkQMv_.d.ts +468 -0
  23. package/dist/hitl.cjs +646 -0
  24. package/dist/hitl.cjs.map +1 -0
  25. package/dist/hitl.d.cts +440 -0
  26. package/dist/hitl.d.ts +440 -0
  27. package/dist/hitl.js +605 -0
  28. package/dist/hitl.js.map +1 -0
  29. package/dist/index-Bew12SZ8.d.ts +417 -0
  30. package/dist/index-Bwt-iz50.d.cts +417 -0
  31. package/dist/{types-B8NfNRGX.d.ts → index-Cv4K_3sZ.d.ts} +2 -1162
  32. package/dist/{types-BZ2f4MRR.d.cts → index-ICmfQi08.d.cts} +2 -1162
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +11 -1527
  35. package/dist/index.d.ts +11 -1527
  36. package/dist/persistence.cjs +552 -0
  37. package/dist/persistence.cjs.map +1 -0
  38. package/dist/persistence.d.cts +254 -0
  39. package/dist/persistence.d.ts +254 -0
  40. package/dist/persistence.js +499 -0
  41. package/dist/persistence.js.map +1 -0
  42. package/dist/reliability.cjs +1651 -0
  43. package/dist/reliability.cjs.map +1 -0
  44. package/dist/reliability.d.cts +1442 -0
  45. package/dist/reliability.d.ts +1442 -0
  46. package/dist/reliability.js +1589 -0
  47. package/dist/reliability.js.map +1 -0
  48. package/dist/result.d.cts +1 -1
  49. package/dist/result.d.ts +1 -1
  50. package/dist/run.cjs +2283 -0
  51. package/dist/run.cjs.map +1 -0
  52. package/dist/run.d.cts +90 -0
  53. package/dist/run.d.ts +90 -0
  54. package/dist/run.js +2247 -0
  55. package/dist/run.js.map +1 -0
  56. package/dist/saga.cjs +3699 -0
  57. package/dist/saga.cjs.map +1 -0
  58. package/dist/saga.d.cts +162 -0
  59. package/dist/saga.d.ts +162 -0
  60. package/dist/saga.js +3670 -0
  61. package/dist/saga.js.map +1 -0
  62. package/dist/store-contract-BI98VYmX.d.ts +66 -0
  63. package/dist/store-contract-C2HyR_o6.d.cts +66 -0
  64. package/dist/streaming.cjs +895 -0
  65. package/dist/streaming.cjs.map +1 -0
  66. package/dist/streaming.d.cts +594 -0
  67. package/dist/streaming.d.ts +594 -0
  68. package/dist/streaming.js +832 -0
  69. package/dist/streaming.js.map +1 -0
  70. package/dist/testing.d.cts +4 -2
  71. package/dist/testing.d.ts +4 -2
  72. package/dist/types-BDTxgKKc.d.ts +845 -0
  73. package/dist/types-C9Y71dua.d.cts +845 -0
  74. package/dist/types-d8q8iQlk.d.cts +323 -0
  75. package/dist/types-sObbY4mX.d.ts +323 -0
  76. package/dist/webhook.cjs +461 -0
  77. package/dist/webhook.cjs.map +1 -0
  78. package/dist/webhook.d.cts +497 -0
  79. package/dist/webhook.d.ts +497 -0
  80. package/dist/webhook.js +422 -0
  81. package/dist/webhook.js.map +1 -0
  82. package/dist/workflow.cjs +2 -2614
  83. package/dist/workflow.cjs.map +1 -1
  84. package/dist/workflow.d.cts +12 -3023
  85. package/dist/workflow.d.ts +12 -3023
  86. package/dist/workflow.js +2 -2535
  87. package/dist/workflow.js.map +1 -1
  88. package/package.json +46 -1
package/dist/run.d.cts ADDED
@@ -0,0 +1,90 @@
1
+ import { v as DepValueOfReturn } from './index-ICmfQi08.cjs';
2
+ export { B as BackoffStrategy, b as BoundSteps, E as EARLY_EXIT_SYMBOL, c as EarlyExit, w as ErrorsOf, d as RetryOptions, e as RunOptions, f as RunOptionsWithCatch, g as RunOptionsWithoutCatch, a as RunStep, S as STEP_TIMEOUT_MARKER, h as ScopeType, i as StepFailureMeta, j as StepOptions, k as StepTimeoutError, l as StepTimeoutMarkerMeta, T as TimeoutOptions, W as WorkflowEvent, m as createEarlyExit, n as getStepTimeoutMeta, o as isEarlyExit, p as isStepTimeoutError, r as run } from './index-ICmfQi08.cjs';
3
+ import { AsyncResult, ErrorOf } from './result.cjs';
4
+ import { U as UnexpectedError, o as TimeoutError } from './errors-sDSeaZBO.cjs';
5
+ import { D as Duration } from './duration-BjVn3QpB.cjs';
6
+
7
+ /**
8
+ * Per-dependency policies: retry, timeout, fallback.
9
+ *
10
+ * Policies are value-level function wrappers declared where dependencies
11
+ * are declared — in the deps object — so call sites stay pristine and the
12
+ * policy is statically visible in the deps literal (the analyzer reads it
13
+ * as fact, not inference):
14
+ *
15
+ * ```typescript
16
+ * const result = await run(
17
+ * {
18
+ * getUser,
19
+ * charge: retry(timeout(charge, 5000), { attempts: 3 }),
20
+ * sendEmail: fallback(sendEmail, () => ({ queued: true })),
21
+ * },
22
+ * async (s) => {
23
+ * const user = await s.getUser(userId); // call sites unchanged
24
+ * const payment = await s.charge(user.id);
25
+ * return s.sendEmail(user.id);
26
+ * }
27
+ * );
28
+ * ```
29
+ *
30
+ * Every policy returns a Result-returning function with exact error-union
31
+ * math:
32
+ * - `retry(fn, opts)` — same errors as `fn` (the last failure propagates)
33
+ * - `timeout(fn, ms)` — errors of `fn` plus `TimeoutError`
34
+ * - `fallback(fn, fb)` — errors of `fn` are consumed; only `fb`'s errors remain
35
+ *
36
+ * Plain (non-Result) functions are valid inputs: their values are
37
+ * normalized to `ok()`, and their throws keep throwing (so they surface as
38
+ * `UnexpectedError` at the run/workflow layer, same as unwrapped deps).
39
+ */
40
+
41
+ type AnyFunction = (...args: never[]) => unknown;
42
+ /** Milliseconds or a Duration value. */
43
+ type PolicyDelay = number | Duration;
44
+ /** The unwrapped success value a policy resolves to for a given function. */
45
+ type PolicyValue<F extends AnyFunction> = DepValueOfReturn<ReturnType<F>>;
46
+ /** A function wrapped by a policy: same arguments, Result-returning. */
47
+ type PolicyFn<F extends AnyFunction, E> = (...args: Parameters<F>) => AsyncResult<PolicyValue<F>, E>;
48
+ interface RetryPolicyOptions {
49
+ /** Total attempts including the first call (minimum 1). */
50
+ attempts: number;
51
+ /** Base delay between attempts. Default: no delay. */
52
+ delay?: PolicyDelay;
53
+ /** How the delay grows per attempt. Default: "fixed". */
54
+ backoff?: "fixed" | "linear" | "exponential";
55
+ /** Upper bound for the computed delay. */
56
+ maxDelay?: PolicyDelay;
57
+ /**
58
+ * Decide whether a failure is retryable. Receives the Result error, or
59
+ * the thrown value for plain functions. Default: retry everything.
60
+ */
61
+ retryIf?: (failure: unknown) => boolean;
62
+ /** Observer invoked before each re-attempt. */
63
+ onRetry?: (info: {
64
+ attempt: number;
65
+ failure: unknown;
66
+ }) => void;
67
+ }
68
+ /**
69
+ * Retry a dependency. The error union is unchanged: if all attempts fail,
70
+ * the last failure propagates exactly as it would have without the policy
71
+ * (typed err for Result functions, throw for plain functions).
72
+ */
73
+ declare function retry<F extends AnyFunction>(fn: F, options: RetryPolicyOptions): PolicyFn<F, ErrorOf<F>>;
74
+ /**
75
+ * Bound a dependency's execution time. On timeout, resolves to
76
+ * `err(TimeoutError)` — adding `TimeoutError` to the error union. The
77
+ * underlying operation is not cancelled (no AbortSignal is threaded);
78
+ * its eventual result is discarded.
79
+ */
80
+ declare function timeout<F extends AnyFunction>(fn: F, after: PolicyDelay): PolicyFn<F, ErrorOf<F> | TimeoutError>;
81
+ /**
82
+ * Recover from a dependency's failure. The handler receives the failure
83
+ * (the typed Result error, or `UnexpectedError` wrapping a throw) plus the
84
+ * original arguments, and its result becomes the outcome. The base
85
+ * function's errors are consumed; only the handler's errors remain in the
86
+ * union — `fallback(fn, () => defaultValue)` has no typed errors at all.
87
+ */
88
+ declare function fallback<F extends AnyFunction, FB extends (failure: ErrorOf<F> | UnexpectedError, ...args: Parameters<F>) => unknown>(fn: F, onFailure: FB): (...args: Parameters<F>) => AsyncResult<PolicyValue<F> | DepValueOfReturn<ReturnType<FB>>, ErrorOf<FB>>;
89
+
90
+ export { type PolicyDelay, type PolicyFn, type RetryPolicyOptions, fallback, retry, timeout };
package/dist/run.d.ts ADDED
@@ -0,0 +1,90 @@
1
+ import { v as DepValueOfReturn } from './index-Cv4K_3sZ.js';
2
+ export { B as BackoffStrategy, b as BoundSteps, E as EARLY_EXIT_SYMBOL, c as EarlyExit, w as ErrorsOf, d as RetryOptions, e as RunOptions, f as RunOptionsWithCatch, g as RunOptionsWithoutCatch, a as RunStep, S as STEP_TIMEOUT_MARKER, h as ScopeType, i as StepFailureMeta, j as StepOptions, k as StepTimeoutError, l as StepTimeoutMarkerMeta, T as TimeoutOptions, W as WorkflowEvent, m as createEarlyExit, n as getStepTimeoutMeta, o as isEarlyExit, p as isStepTimeoutError, r as run } from './index-Cv4K_3sZ.js';
3
+ import { AsyncResult, ErrorOf } from './result.js';
4
+ import { U as UnexpectedError, o as TimeoutError } from './errors-sDSeaZBO.js';
5
+ import { D as Duration } from './duration-BjVn3QpB.js';
6
+
7
+ /**
8
+ * Per-dependency policies: retry, timeout, fallback.
9
+ *
10
+ * Policies are value-level function wrappers declared where dependencies
11
+ * are declared — in the deps object — so call sites stay pristine and the
12
+ * policy is statically visible in the deps literal (the analyzer reads it
13
+ * as fact, not inference):
14
+ *
15
+ * ```typescript
16
+ * const result = await run(
17
+ * {
18
+ * getUser,
19
+ * charge: retry(timeout(charge, 5000), { attempts: 3 }),
20
+ * sendEmail: fallback(sendEmail, () => ({ queued: true })),
21
+ * },
22
+ * async (s) => {
23
+ * const user = await s.getUser(userId); // call sites unchanged
24
+ * const payment = await s.charge(user.id);
25
+ * return s.sendEmail(user.id);
26
+ * }
27
+ * );
28
+ * ```
29
+ *
30
+ * Every policy returns a Result-returning function with exact error-union
31
+ * math:
32
+ * - `retry(fn, opts)` — same errors as `fn` (the last failure propagates)
33
+ * - `timeout(fn, ms)` — errors of `fn` plus `TimeoutError`
34
+ * - `fallback(fn, fb)` — errors of `fn` are consumed; only `fb`'s errors remain
35
+ *
36
+ * Plain (non-Result) functions are valid inputs: their values are
37
+ * normalized to `ok()`, and their throws keep throwing (so they surface as
38
+ * `UnexpectedError` at the run/workflow layer, same as unwrapped deps).
39
+ */
40
+
41
+ type AnyFunction = (...args: never[]) => unknown;
42
+ /** Milliseconds or a Duration value. */
43
+ type PolicyDelay = number | Duration;
44
+ /** The unwrapped success value a policy resolves to for a given function. */
45
+ type PolicyValue<F extends AnyFunction> = DepValueOfReturn<ReturnType<F>>;
46
+ /** A function wrapped by a policy: same arguments, Result-returning. */
47
+ type PolicyFn<F extends AnyFunction, E> = (...args: Parameters<F>) => AsyncResult<PolicyValue<F>, E>;
48
+ interface RetryPolicyOptions {
49
+ /** Total attempts including the first call (minimum 1). */
50
+ attempts: number;
51
+ /** Base delay between attempts. Default: no delay. */
52
+ delay?: PolicyDelay;
53
+ /** How the delay grows per attempt. Default: "fixed". */
54
+ backoff?: "fixed" | "linear" | "exponential";
55
+ /** Upper bound for the computed delay. */
56
+ maxDelay?: PolicyDelay;
57
+ /**
58
+ * Decide whether a failure is retryable. Receives the Result error, or
59
+ * the thrown value for plain functions. Default: retry everything.
60
+ */
61
+ retryIf?: (failure: unknown) => boolean;
62
+ /** Observer invoked before each re-attempt. */
63
+ onRetry?: (info: {
64
+ attempt: number;
65
+ failure: unknown;
66
+ }) => void;
67
+ }
68
+ /**
69
+ * Retry a dependency. The error union is unchanged: if all attempts fail,
70
+ * the last failure propagates exactly as it would have without the policy
71
+ * (typed err for Result functions, throw for plain functions).
72
+ */
73
+ declare function retry<F extends AnyFunction>(fn: F, options: RetryPolicyOptions): PolicyFn<F, ErrorOf<F>>;
74
+ /**
75
+ * Bound a dependency's execution time. On timeout, resolves to
76
+ * `err(TimeoutError)` — adding `TimeoutError` to the error union. The
77
+ * underlying operation is not cancelled (no AbortSignal is threaded);
78
+ * its eventual result is discarded.
79
+ */
80
+ declare function timeout<F extends AnyFunction>(fn: F, after: PolicyDelay): PolicyFn<F, ErrorOf<F> | TimeoutError>;
81
+ /**
82
+ * Recover from a dependency's failure. The handler receives the failure
83
+ * (the typed Result error, or `UnexpectedError` wrapping a throw) plus the
84
+ * original arguments, and its result becomes the outcome. The base
85
+ * function's errors are consumed; only the handler's errors remain in the
86
+ * union — `fallback(fn, () => defaultValue)` has no typed errors at all.
87
+ */
88
+ declare function fallback<F extends AnyFunction, FB extends (failure: ErrorOf<F> | UnexpectedError, ...args: Parameters<F>) => unknown>(fn: F, onFailure: FB): (...args: Parameters<F>) => AsyncResult<PolicyValue<F> | DepValueOfReturn<ReturnType<FB>>, ErrorOf<FB>>;
89
+
90
+ export { type PolicyDelay, type PolicyFn, type RetryPolicyOptions, fallback, retry, timeout };