awaitly 1.35.0 → 2.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 (241) hide show
  1. package/dist/{duration.d.ts → di-BDlT7InM.d.cts} +15 -1
  2. package/dist/{duration.d.cts → di-BbFFfO8y.d.ts} +15 -1
  3. package/dist/errors-DtXvrCiO.d.cts +708 -0
  4. package/dist/errors-DtXvrCiO.d.ts +708 -0
  5. package/dist/index.cjs +4594 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +1970 -141
  8. package/dist/index.d.ts +1970 -141
  9. package/dist/index.js +4398 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/result.cjs +641 -1
  12. package/dist/result.cjs.map +1 -1
  13. package/dist/result.d.cts +29 -4
  14. package/dist/result.d.ts +29 -4
  15. package/dist/result.js +561 -1
  16. package/dist/result.js.map +1 -1
  17. package/dist/testing.cjs +4202 -8
  18. package/dist/testing.cjs.map +1 -1
  19. package/dist/testing.d.cts +2 -6
  20. package/dist/testing.d.ts +2 -6
  21. package/dist/testing.js +4154 -8
  22. package/dist/testing.js.map +1 -1
  23. package/dist/{run-entry-DGs0tySr.d.cts → types-B8NfNRGX.d.ts} +1078 -1502
  24. package/dist/{run-entry-BOuNyVoO.d.ts → types-BZ2f4MRR.d.cts} +1078 -1502
  25. package/dist/workflow.cjs +7096 -6
  26. package/dist/workflow.cjs.map +1 -1
  27. package/dist/workflow.d.cts +3346 -22
  28. package/dist/workflow.d.ts +3346 -22
  29. package/dist/workflow.js +6929 -6
  30. package/dist/workflow.js.map +1 -1
  31. package/package.json +3 -168
  32. package/dist/adapters.cjs +0 -7
  33. package/dist/adapters.cjs.map +0 -1
  34. package/dist/adapters.d.cts +0 -179
  35. package/dist/adapters.d.ts +0 -179
  36. package/dist/adapters.js +0 -7
  37. package/dist/adapters.js.map +0 -1
  38. package/dist/batch.cjs +0 -7
  39. package/dist/batch.cjs.map +0 -1
  40. package/dist/batch.d.cts +0 -200
  41. package/dist/batch.d.ts +0 -200
  42. package/dist/batch.js +0 -7
  43. package/dist/batch.js.map +0 -1
  44. package/dist/bind-deps.cjs +0 -2
  45. package/dist/bind-deps.cjs.map +0 -1
  46. package/dist/bind-deps.d.cts +0 -28
  47. package/dist/bind-deps.d.ts +0 -28
  48. package/dist/bind-deps.js +0 -2
  49. package/dist/bind-deps.js.map +0 -1
  50. package/dist/cache.cjs +0 -2
  51. package/dist/cache.cjs.map +0 -1
  52. package/dist/cache.d.cts +0 -269
  53. package/dist/cache.d.ts +0 -269
  54. package/dist/cache.js +0 -2
  55. package/dist/cache.js.map +0 -1
  56. package/dist/circuit-breaker.cjs +0 -7
  57. package/dist/circuit-breaker.cjs.map +0 -1
  58. package/dist/circuit-breaker.d.cts +0 -211
  59. package/dist/circuit-breaker.d.ts +0 -211
  60. package/dist/circuit-breaker.js +0 -7
  61. package/dist/circuit-breaker.js.map +0 -1
  62. package/dist/conditional.cjs +0 -2
  63. package/dist/conditional.cjs.map +0 -1
  64. package/dist/conditional.d.cts +0 -252
  65. package/dist/conditional.d.ts +0 -252
  66. package/dist/conditional.js +0 -2
  67. package/dist/conditional.js.map +0 -1
  68. package/dist/core.cjs +0 -7
  69. package/dist/core.cjs.map +0 -1
  70. package/dist/core.d.cts +0 -5
  71. package/dist/core.d.ts +0 -5
  72. package/dist/core.js +0 -7
  73. package/dist/core.js.map +0 -1
  74. package/dist/di-By77n4Fa.d.ts +0 -15
  75. package/dist/di-OJfsohf-.d.cts +0 -15
  76. package/dist/diagnostics.cjs +0 -8
  77. package/dist/diagnostics.cjs.map +0 -1
  78. package/dist/diagnostics.d.cts +0 -68
  79. package/dist/diagnostics.d.ts +0 -68
  80. package/dist/diagnostics.js +0 -8
  81. package/dist/diagnostics.js.map +0 -1
  82. package/dist/durable.cjs +0 -11
  83. package/dist/durable.cjs.map +0 -1
  84. package/dist/durable.d.cts +0 -9
  85. package/dist/durable.d.ts +0 -9
  86. package/dist/durable.js +0 -11
  87. package/dist/durable.js.map +0 -1
  88. package/dist/duration.cjs +0 -2
  89. package/dist/duration.cjs.map +0 -1
  90. package/dist/duration.js +0 -2
  91. package/dist/duration.js.map +0 -1
  92. package/dist/engine.cjs +0 -11
  93. package/dist/engine.cjs.map +0 -1
  94. package/dist/engine.d.cts +0 -115
  95. package/dist/engine.d.ts +0 -115
  96. package/dist/engine.js +0 -11
  97. package/dist/engine.js.map +0 -1
  98. package/dist/errors.cjs +0 -2
  99. package/dist/errors.cjs.map +0 -1
  100. package/dist/errors.d.cts +0 -361
  101. package/dist/errors.d.ts +0 -361
  102. package/dist/errors.js +0 -2
  103. package/dist/errors.js.map +0 -1
  104. package/dist/fetch.cjs +0 -7
  105. package/dist/fetch.cjs.map +0 -1
  106. package/dist/fetch.d.cts +0 -86
  107. package/dist/fetch.d.ts +0 -86
  108. package/dist/fetch.js +0 -7
  109. package/dist/fetch.js.map +0 -1
  110. package/dist/flow.cjs +0 -7
  111. package/dist/flow.cjs.map +0 -1
  112. package/dist/flow.d.cts +0 -163
  113. package/dist/flow.d.ts +0 -163
  114. package/dist/flow.js +0 -7
  115. package/dist/flow.js.map +0 -1
  116. package/dist/functional.cjs +0 -2
  117. package/dist/functional.cjs.map +0 -1
  118. package/dist/functional.d.cts +0 -444
  119. package/dist/functional.d.ts +0 -444
  120. package/dist/functional.js +0 -2
  121. package/dist/functional.js.map +0 -1
  122. package/dist/guards-4sV7mTqj.d.cts +0 -72
  123. package/dist/guards-BIX05ALH.d.ts +0 -72
  124. package/dist/hitl-DFn4Xa_l.d.cts +0 -468
  125. package/dist/hitl-DU5VpKq7.d.ts +0 -468
  126. package/dist/hitl.cjs +0 -7
  127. package/dist/hitl.cjs.map +0 -1
  128. package/dist/hitl.d.cts +0 -442
  129. package/dist/hitl.d.ts +0 -442
  130. package/dist/hitl.js +0 -7
  131. package/dist/hitl.js.map +0 -1
  132. package/dist/index-CnvBryQB.d.ts +0 -417
  133. package/dist/index-DEZEf8Fs.d.cts +0 -417
  134. package/dist/match-entry-DjI2bLpD.d.cts +0 -209
  135. package/dist/match-entry-DjI2bLpD.d.ts +0 -209
  136. package/dist/match.cjs +0 -2
  137. package/dist/match.cjs.map +0 -1
  138. package/dist/match.d.cts +0 -1
  139. package/dist/match.d.ts +0 -1
  140. package/dist/match.js +0 -2
  141. package/dist/match.js.map +0 -1
  142. package/dist/otel.cjs +0 -2
  143. package/dist/otel.cjs.map +0 -1
  144. package/dist/otel.d.cts +0 -188
  145. package/dist/otel.d.ts +0 -188
  146. package/dist/otel.js +0 -2
  147. package/dist/otel.js.map +0 -1
  148. package/dist/persistence-entry-B-8PjnSR.d.cts +0 -831
  149. package/dist/persistence-entry-D8zRkLiT.d.ts +0 -831
  150. package/dist/persistence.cjs +0 -2
  151. package/dist/persistence.cjs.map +0 -1
  152. package/dist/persistence.d.cts +0 -7
  153. package/dist/persistence.d.ts +0 -7
  154. package/dist/persistence.js +0 -2
  155. package/dist/persistence.js.map +0 -1
  156. package/dist/policies.cjs +0 -2
  157. package/dist/policies.cjs.map +0 -1
  158. package/dist/policies.d.cts +0 -379
  159. package/dist/policies.d.ts +0 -379
  160. package/dist/policies.js +0 -2
  161. package/dist/policies.js.map +0 -1
  162. package/dist/ratelimit.cjs +0 -7
  163. package/dist/ratelimit.cjs.map +0 -1
  164. package/dist/ratelimit.d.cts +0 -458
  165. package/dist/ratelimit.d.ts +0 -458
  166. package/dist/ratelimit.js +0 -7
  167. package/dist/ratelimit.js.map +0 -1
  168. package/dist/reliability.cjs +0 -11
  169. package/dist/reliability.cjs.map +0 -1
  170. package/dist/reliability.d.cts +0 -11
  171. package/dist/reliability.d.ts +0 -11
  172. package/dist/reliability.js +0 -11
  173. package/dist/reliability.js.map +0 -1
  174. package/dist/resolver.cjs +0 -7
  175. package/dist/resolver.cjs.map +0 -1
  176. package/dist/resolver.d.cts +0 -68
  177. package/dist/resolver.d.ts +0 -68
  178. package/dist/resolver.js +0 -7
  179. package/dist/resolver.js.map +0 -1
  180. package/dist/resource.cjs +0 -7
  181. package/dist/resource.cjs.map +0 -1
  182. package/dist/resource.d.cts +0 -174
  183. package/dist/resource.d.ts +0 -174
  184. package/dist/resource.js +0 -7
  185. package/dist/resource.js.map +0 -1
  186. package/dist/result/retry.cjs +0 -2
  187. package/dist/result/retry.cjs.map +0 -1
  188. package/dist/result/retry.d.cts +0 -70
  189. package/dist/result/retry.d.ts +0 -70
  190. package/dist/result/retry.js +0 -2
  191. package/dist/result/retry.js.map +0 -1
  192. package/dist/retry.cjs +0 -2
  193. package/dist/retry.cjs.map +0 -1
  194. package/dist/retry.d.cts +0 -388
  195. package/dist/retry.d.ts +0 -388
  196. package/dist/retry.js +0 -2
  197. package/dist/retry.js.map +0 -1
  198. package/dist/run.cjs +0 -7
  199. package/dist/run.cjs.map +0 -1
  200. package/dist/run.d.cts +0 -4
  201. package/dist/run.d.ts +0 -4
  202. package/dist/run.js +0 -7
  203. package/dist/run.js.map +0 -1
  204. package/dist/saga.cjs +0 -11
  205. package/dist/saga.cjs.map +0 -1
  206. package/dist/saga.d.cts +0 -164
  207. package/dist/saga.d.ts +0 -164
  208. package/dist/saga.js +0 -11
  209. package/dist/saga.js.map +0 -1
  210. package/dist/singleflight.cjs +0 -2
  211. package/dist/singleflight.cjs.map +0 -1
  212. package/dist/singleflight.d.cts +0 -145
  213. package/dist/singleflight.d.ts +0 -145
  214. package/dist/singleflight.js +0 -2
  215. package/dist/singleflight.js.map +0 -1
  216. package/dist/slugs.cjs +0 -2
  217. package/dist/slugs.cjs.map +0 -1
  218. package/dist/slugs.d.cts +0 -67
  219. package/dist/slugs.d.ts +0 -67
  220. package/dist/slugs.js +0 -2
  221. package/dist/slugs.js.map +0 -1
  222. package/dist/streaming.cjs +0 -9
  223. package/dist/streaming.cjs.map +0 -1
  224. package/dist/streaming.d.cts +0 -596
  225. package/dist/streaming.d.ts +0 -596
  226. package/dist/streaming.js +0 -9
  227. package/dist/streaming.js.map +0 -1
  228. package/dist/tagged-error.cjs +0 -2
  229. package/dist/tagged-error.cjs.map +0 -1
  230. package/dist/tagged-error.d.cts +0 -275
  231. package/dist/tagged-error.d.ts +0 -275
  232. package/dist/tagged-error.js +0 -2
  233. package/dist/tagged-error.js.map +0 -1
  234. package/dist/types-BziYHFkD.d.ts +0 -323
  235. package/dist/types-C5jLEUqY.d.cts +0 -323
  236. package/dist/webhook.cjs +0 -7
  237. package/dist/webhook.cjs.map +0 -1
  238. package/dist/webhook.d.cts +0 -499
  239. package/dist/webhook.d.ts +0 -499
  240. package/dist/webhook.js +0 -7
  241. package/dist/webhook.js.map +0 -1
@@ -0,0 +1,708 @@
1
+ /**
2
+ * awaitly/slugs
3
+ *
4
+ * Source-of-truth slug namespace. Every concept that surfaces as a runtime
5
+ * error, lint rule, static-analyzer diagnostic, visualizer event, or skill rule
6
+ * has exactly one canonical kebab-case slug here.
7
+ *
8
+ * Slugs are public API. Renames are a major version bump. Adds are non-breaking.
9
+ *
10
+ * Categories:
11
+ * - step-* step() discipline
12
+ * - workflow-* createWorkflow / run / runWithState shape
13
+ * - result-* Result usage
14
+ * - error-* Boundary handling
15
+ * - concurrency-* step.all/map/race vs Promise.*
16
+ * - runtime-* Failures only observable at runtime
17
+ */
18
+ declare const AWAITLY_SLUGS: {
19
+ readonly "step-require-id": "step-require-id";
20
+ readonly "step-no-immediate-execution": "step-no-immediate-execution";
21
+ readonly "step-require-thunk-for-key": "step-require-thunk-for-key";
22
+ readonly "step-no-bare-await": "step-no-bare-await";
23
+ readonly "step-no-try-catch-wrap": "step-no-try-catch-wrap";
24
+ readonly "step-stable-cache-keys": "step-stable-cache-keys";
25
+ readonly "workflow-no-floating": "workflow-no-floating";
26
+ readonly "workflow-options-position": "workflow-options-position";
27
+ readonly "workflow-callback-shape": "workflow-callback-shape";
28
+ readonly "workflow-no-callable-form": "workflow-no-callable-form";
29
+ readonly "workflow-no-dynamic-import": "workflow-no-dynamic-import";
30
+ readonly "workflow-prefer-step-if": "workflow-prefer-step-if";
31
+ readonly "workflow-prefer-step-foreach": "workflow-prefer-step-foreach";
32
+ readonly "result-no-floating": "result-no-floating";
33
+ readonly "result-require-handling": "result-require-handling";
34
+ readonly "result-no-double-wrap": "result-no-double-wrap";
35
+ readonly "result-no-manual-propagation": "result-no-manual-propagation";
36
+ readonly "result-no-direct-ok-err": "result-no-direct-ok-err";
37
+ readonly "error-check-unexpected-first": "error-check-unexpected-first";
38
+ readonly "error-access-cause": "error-access-cause";
39
+ readonly "error-normalize": "error-normalize";
40
+ readonly "error-no-throw-in-deps": "error-no-throw-in-deps";
41
+ readonly "concurrency-no-promise-all": "concurrency-no-promise-all";
42
+ readonly "concurrency-no-promise-race": "concurrency-no-promise-race";
43
+ readonly "concurrency-no-promise-allsettled": "concurrency-no-promise-allsettled";
44
+ readonly "runtime-step-timeout": "runtime-step-timeout";
45
+ readonly "runtime-step-aborted": "runtime-step-aborted";
46
+ readonly "runtime-retry-exhausted": "runtime-retry-exhausted";
47
+ readonly "runtime-rate-limit": "runtime-rate-limit";
48
+ readonly "runtime-circuit-open": "runtime-circuit-open";
49
+ readonly "runtime-unexpected": "runtime-unexpected";
50
+ readonly "runtime-resolver-not-found": "runtime-resolver-not-found";
51
+ readonly "runtime-saga-compensation": "runtime-saga-compensation";
52
+ };
53
+ /** All canonical awaitly slugs as a string-literal union. */
54
+ type AwaitlySlug = keyof typeof AWAITLY_SLUGS;
55
+ /** Categories derived from slug prefixes. */
56
+ type AwaitlySlugCategory = "step" | "workflow" | "result" | "error" | "concurrency" | "runtime";
57
+ /** Returns the category (prefix) of a slug. */
58
+ declare function slugCategory(slug: AwaitlySlug): AwaitlySlugCategory;
59
+ /**
60
+ * Returns the canonical docs URL for a slug. Resolves to the matching
61
+ * anchored section on the consolidated rule index page.
62
+ */
63
+ declare function slugDocsUrl(slug: AwaitlySlug): string;
64
+ /** Type guard: is a string a known awaitly slug? */
65
+ declare function isAwaitlySlug(value: string): value is AwaitlySlug;
66
+ /** All slugs as an array. */
67
+ declare const ALL_SLUGS: readonly AwaitlySlug[];
68
+
69
+ /**
70
+ * awaitly/tagged-error
71
+ *
72
+ * Factory for creating tagged error types with exhaustive pattern matching.
73
+ * Enables TypeScript to enforce that all error variants are handled.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * // Define error types (Props via generic)
78
+ * class NotFoundError extends TaggedError("NotFoundError")<{
79
+ * id: string;
80
+ * resource: string;
81
+ * }> {}
82
+ *
83
+ * // Define with type-safe message (Props inferred from callback annotation)
84
+ * class ValidationError extends TaggedError("ValidationError", {
85
+ * message: (p: { field: string; reason: string }) => `Invalid ${p.field}: ${p.reason}`,
86
+ * }) {}
87
+ *
88
+ * // Create instances
89
+ * const error = new NotFoundError({ id: "123", resource: "User" });
90
+ *
91
+ * // Runtime type check: instanceof TaggedError works!
92
+ * console.log(error instanceof TaggedError); // true
93
+ *
94
+ * // Exhaustive matching
95
+ * type AppError = NotFoundError | ValidationError;
96
+ * const message = TaggedError.match(error as AppError, {
97
+ * NotFoundError: (e) => `Missing: ${e.resource} ${e.id}`,
98
+ * ValidationError: (e) => `Invalid ${e.field}: ${e.reason}`,
99
+ * });
100
+ * ```
101
+ */
102
+
103
+ /**
104
+ * Options for Error constructor (compatible with ES2022 ErrorOptions).
105
+ */
106
+ interface TaggedErrorOptions {
107
+ cause?: unknown;
108
+ }
109
+ /**
110
+ * Options for TaggedError factory with type-safe message callback.
111
+ */
112
+ interface TaggedErrorCreateOptions<Props extends Record<string, unknown>> {
113
+ /** Custom message generator from props. Annotate parameter for type safety. */
114
+ message: (props: Props) => string;
115
+ /**
116
+ * Canonical awaitly slug for this error class. When set, instances carry
117
+ * `code`, `hint`, and `docsUrl` populated from the slugs namespace.
118
+ * Required together with `hint` for awaitly-system errors.
119
+ */
120
+ slug?: AwaitlySlug;
121
+ /**
122
+ * One-line "do X instead" guidance shown alongside the error.
123
+ * Required when `slug` is set.
124
+ */
125
+ hint?: string;
126
+ }
127
+ /**
128
+ * Base interface for all tagged errors.
129
+ *
130
+ * `type` is the canonical discriminant (the same key plain tagged-object
131
+ * errors use, so one `match` works across shapes). `_tag` is a deprecated
132
+ * alias kept through the migration window.
133
+ */
134
+ interface TaggedErrorBase extends Error {
135
+ /** Canonical discriminant — matches the tag passed to TaggedError(tag). */
136
+ readonly type: string;
137
+ /** @deprecated Use `type`. Effect-style alias retained for migration. */
138
+ readonly _tag: string;
139
+ /** Canonical slug for awaitly-system errors. Undefined for user errors that opt out. */
140
+ readonly code?: AwaitlySlug;
141
+ /** One-line guidance. Undefined when no slug is set. */
142
+ readonly hint?: string;
143
+ /** Canonical docs URL. Undefined when no slug is set. */
144
+ readonly docsUrl?: string;
145
+ }
146
+ /**
147
+ * Instance type for factory-created TaggedErrors.
148
+ */
149
+ type TaggedErrorInstance<Tag extends string, Props> = TaggedErrorBase & {
150
+ readonly type: Tag;
151
+ /** @deprecated Use `type`. */
152
+ readonly _tag: Tag;
153
+ } & Readonly<Props>;
154
+ /**
155
+ * Constructor args type - conditionally optional based on whether Props has required fields.
156
+ * - If Props is empty or all properties are optional: props argument is optional
157
+ * - If Props has any required properties: props argument is required
158
+ * @internal
159
+ */
160
+ type ConstructorArgs<Props extends Record<string, unknown>> = {} extends Props ? [props?: Props | void, options?: TaggedErrorOptions] : [props: Props, options?: TaggedErrorOptions];
161
+ /**
162
+ * Constructor type returned by TaggedError factory.
163
+ */
164
+ interface TaggedErrorConstructor<Tag extends string, Props extends Record<string, unknown>> {
165
+ new (...args: ConstructorArgs<Props>): TaggedErrorInstance<Tag, Props>;
166
+ readonly prototype: TaggedErrorInstance<Tag, Props>;
167
+ }
168
+ /**
169
+ * Generic class factory type that allows `<Props>` parameterization.
170
+ * This enables the Effect.js-style syntax: `class X extends TaggedError("X")<Props> {}`
171
+ * @internal
172
+ */
173
+ interface TaggedErrorClassFactory<Tag extends string> {
174
+ new <Props extends Record<string, unknown> = Record<string, never>>(...args: ConstructorArgs<Props>): TaggedErrorInstance<Tag, Props>;
175
+ }
176
+ /**
177
+ * Helper type to extract return type from a function type.
178
+ * @internal
179
+ */
180
+ type FnReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
181
+ /**
182
+ * Helper type to get union of return types from all handlers.
183
+ * @internal
184
+ */
185
+ type HandlersReturnType<H> = {
186
+ [K in keyof H]: FnReturnType<H[K]>;
187
+ }[keyof H];
188
+ /**
189
+ * Helper type to extract keys whose values are definitely functions (not undefined).
190
+ * Only excludes a tag from the fallback type if its handler is guaranteed to be
191
+ * a function. Keys where the value type includes undefined are NOT excluded,
192
+ * ensuring type safety with dynamic/conditional handlers.
193
+ * @internal
194
+ */
195
+ type DefinitelyHandledKeys<H> = {
196
+ [K in keyof H]-?: undefined extends H[K] ? never : K;
197
+ }[keyof H];
198
+ /**
199
+ * Factory function to create tagged error classes.
200
+ *
201
+ * Two usage patterns:
202
+ *
203
+ * 1. **Props via generic** (default message is tag name):
204
+ * ```typescript
205
+ * class NotFoundError extends TaggedError("NotFoundError")<{ id: string }> {}
206
+ * ```
207
+ *
208
+ * 2. **Props inferred from message callback** (type-safe message):
209
+ * ```typescript
210
+ * class NotFoundError extends TaggedError("NotFoundError", {
211
+ * message: (p: { id: string }) => `Not found: ${p.id}`,
212
+ * }) {}
213
+ * ```
214
+ *
215
+ * Both support `instanceof TaggedError` checks at runtime.
216
+ *
217
+ * @param tag - The unique tag string for this error type
218
+ * @param options - Optional configuration with message generator (annotate param for type safety)
219
+ * @returns A class constructor that can be extended
220
+ */
221
+ declare function TaggedError<Tag extends string>(tag: Tag): TaggedErrorClassFactory<Tag>;
222
+ declare function TaggedError<Tag extends string, Props extends Record<string, unknown>>(tag: Tag, options: TaggedErrorCreateOptions<Props>): TaggedErrorConstructor<Tag, Props>;
223
+ /**
224
+ * Namespace for static methods on TaggedError.
225
+ */
226
+ declare namespace TaggedError {
227
+ /**
228
+ * Type guard to check if a value is an Error instance.
229
+ */
230
+ function isError(value: unknown): value is Error;
231
+ /**
232
+ * Type guard to check if a value is a TaggedError instance.
233
+ * Uses the same check as `instanceof TaggedError` - only genuine
234
+ * TaggedError instances (created via the factory) pass this guard.
235
+ */
236
+ function isTaggedError(value: unknown): value is TaggedErrorBase;
237
+ /**
238
+ * Exhaustively matches on a tagged error, requiring handlers for all variants.
239
+ *
240
+ * TypeScript will error if any variant in the error union is not handled.
241
+ *
242
+ * @remarks When to use: You want compile-time enforcement that every tagged variant is handled.
243
+ *
244
+ * @param error - The tagged error to match
245
+ * @param handlers - Object mapping _tag values to handler functions
246
+ * @returns The return value of the matched handler
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * type AppError = NotFoundError | ValidationError;
251
+ *
252
+ * const message = TaggedError.match(error, {
253
+ * NotFoundError: (e) => `Not found: ${e.id}`,
254
+ * ValidationError: (e) => `Invalid: ${e.field}`,
255
+ * });
256
+ * ```
257
+ */
258
+ function match<E extends TaggedErrorBase, H extends {
259
+ [K in E["_tag"]]: (e: Extract<E, {
260
+ _tag: K;
261
+ }>) => unknown;
262
+ }>(error: E, handlers: H): HandlersReturnType<H>;
263
+ /**
264
+ * Partially matches on a tagged error with a fallback for unhandled variants.
265
+ *
266
+ * The fallback receives variants that are NOT definitely handled. A tag is
267
+ * considered "definitely handled" only if its handler is a function (not
268
+ * `undefined`). This ensures type safety even with dynamic/conditional handlers:
269
+ *
270
+ * ```typescript
271
+ * const maybeHandle = featureFlag ? (e) => e.id : undefined;
272
+ * TaggedError.matchPartial(
273
+ * error,
274
+ * { NotFoundError: maybeHandle }, // maybeHandle might be undefined
275
+ * (e) => e._tag // e correctly includes NotFoundError
276
+ * );
277
+ * ```
278
+ *
279
+ * @param error - The tagged error to match
280
+ * @param handlers - Partial object mapping _tag values to handler functions
281
+ * @param otherwise - Fallback handler for unmatched variants
282
+ * @returns The return value of the matched handler or fallback
283
+ *
284
+ * @example
285
+ * ```typescript
286
+ * const message = TaggedError.matchPartial(
287
+ * error,
288
+ * { NotFoundError: (e) => `Not found: ${e.id}` },
289
+ * (e) => `Other error: ${e.message}`
290
+ * );
291
+ * ```
292
+ */
293
+ function matchPartial<E extends TaggedErrorBase, H extends Partial<{
294
+ [K in E["_tag"]]: (e: Extract<E, {
295
+ _tag: K;
296
+ }>) => unknown;
297
+ }>, T>(error: E, handlers: H, otherwise: (e: Exclude<E, {
298
+ _tag: DefinitelyHandledKeys<H>;
299
+ }>) => T): HandlersReturnType<H> | T;
300
+ }
301
+
302
+ /**
303
+ * Helper type to extract the _tag literal type from a TaggedError.
304
+ *
305
+ * @example
306
+ * ```typescript
307
+ * class MyError extends TaggedError("MyError")<{ id: string }> {}
308
+ * type Tag = TagOf<MyError>; // "MyError"
309
+ * ```
310
+ */
311
+ type TagOf<E extends TaggedErrorBase> = E["_tag"];
312
+ /**
313
+ * Helper type to extract a specific variant from a TaggedError union by tag.
314
+ *
315
+ * @example
316
+ * ```typescript
317
+ * type AppError = NotFoundError | ValidationError;
318
+ * type NotFound = ErrorByTag<AppError, "NotFoundError">; // NotFoundError
319
+ * ```
320
+ */
321
+ type ErrorByTag<E extends TaggedErrorBase, Tag extends E["_tag"]> = Extract<E, {
322
+ _tag: Tag;
323
+ }>;
324
+ /**
325
+ * Reserved keys that are stripped from user props at runtime.
326
+ * These keys cannot be used as user-defined properties:
327
+ * - _tag: discriminant for pattern matching
328
+ * - name, message, stack: Error internals (preserved for logging/debugging)
329
+ * - code, hint, docsUrl: spine fields (non-configurable own properties when slug is set)
330
+ *
331
+ * Note: 'cause' is NOT reserved - it can be used as a user prop.
332
+ */
333
+ type ReservedErrorKeys = "_tag" | "name" | "message" | "stack" | "code" | "hint" | "docsUrl";
334
+ /**
335
+ * Helper type to extract props from a TaggedError.
336
+ * Excludes reserved keys that are stripped at runtime.
337
+ *
338
+ * @example
339
+ * ```typescript
340
+ * class MyError extends TaggedError("MyError")<{ id: string }> {}
341
+ * type Props = PropsOf<MyError>; // { id: string }
342
+ *
343
+ * // 'cause' is allowed as a user prop
344
+ * class DomainError extends TaggedError("DomainError")<{ cause: { field: string } }> {}
345
+ * type DomainProps = PropsOf<DomainError>; // { cause: { field: string } }
346
+ * ```
347
+ */
348
+ type PropsOf<E extends TaggedErrorBase> = Omit<E, ReservedErrorKeys>;
349
+
350
+ /**
351
+ * awaitly/errors
352
+ *
353
+ * Pre-built error types for common failure scenarios.
354
+ * Uses TaggedError for type-safe exhaustive matching.
355
+ *
356
+ * @example
357
+ * ```typescript
358
+ * import { TimeoutError, RetryExhaustedError, RateLimitError, CircuitBreakerOpenError } from 'awaitly';
359
+ *
360
+ * // Create errors
361
+ * const timeout = new TimeoutError({ operation: 'fetchUser', ms: 5000 });
362
+ * const retryFailed = new RetryExhaustedError({ operation: 'sendEmail', attempts: 3 });
363
+ *
364
+ * // Pattern match
365
+ * TaggedError.match(error, {
366
+ * TimeoutError: (e) => `${e.operation} timed out after ${e.ms}ms`,
367
+ * RetryExhaustedError: (e) => `${e.operation} failed after ${e.attempts} attempts`,
368
+ * RateLimitError: (e) => `Rate limit exceeded, retry after ${e.retryAfterMs}ms`,
369
+ * CircuitBreakerOpenError: (e) => `Circuit ${e.circuitName} is open`,
370
+ * });
371
+ * ```
372
+ */
373
+ /**
374
+ * Factory function to create tagged error classes with default values.
375
+ *
376
+ * This is a convenience wrapper around TaggedError that allows specifying
377
+ * default property values for error types.
378
+ *
379
+ * @example
380
+ * ```typescript
381
+ * const NetworkError = makeError('NetworkError', {
382
+ * defaults: { retryable: true },
383
+ * message: (p) => `Network error: ${p.reason}`,
384
+ * });
385
+ *
386
+ * class MyNetworkError extends NetworkError<{ reason: string; code?: number }> {}
387
+ * ```
388
+ */
389
+ declare function makeError<Tag extends string>(tag: Tag, options?: {
390
+ message?: (props: Record<string, unknown>) => string;
391
+ defaults?: Record<string, unknown>;
392
+ }): {
393
+ new (props?: Record<string, unknown>): {
394
+ readonly [x: string]: unknown;
395
+ readonly type: Tag;
396
+ readonly _tag: Tag;
397
+ readonly code?: AwaitlySlug;
398
+ readonly hint?: string;
399
+ readonly docsUrl?: string;
400
+ name: string;
401
+ message: string;
402
+ stack?: string;
403
+ cause?: unknown;
404
+ };
405
+ };
406
+ declare const TimeoutError_base: TaggedErrorConstructor<"TimeoutError", {
407
+ /** Name of the operation that timed out */
408
+ operation?: string;
409
+ /** Timeout duration in milliseconds */
410
+ ms: number;
411
+ }>;
412
+ /**
413
+ * Error thrown when an operation times out.
414
+ *
415
+ * @example
416
+ * ```typescript
417
+ * const error = new TimeoutError({
418
+ * operation: 'fetchUser',
419
+ * ms: 5000,
420
+ * });
421
+ * console.log(error.message); // "TimeoutError: fetchUser timed out after 5000ms"
422
+ * ```
423
+ */
424
+ declare class TimeoutError extends /* @__PURE__ */ TimeoutError_base {
425
+ }
426
+ declare const RetryExhaustedError_base: TaggedErrorConstructor<"RetryExhaustedError", {
427
+ /** Name of the operation that failed */
428
+ operation?: string;
429
+ /** Total number of retry attempts made */
430
+ attempts: number;
431
+ /** The last error encountered before giving up */
432
+ lastError?: unknown;
433
+ }>;
434
+ /**
435
+ * Error thrown when all retry attempts are exhausted.
436
+ *
437
+ * @example
438
+ * ```typescript
439
+ * const error = new RetryExhaustedError({
440
+ * operation: 'sendEmail',
441
+ * attempts: 3,
442
+ * lastError: originalError,
443
+ * });
444
+ * console.log(error.message); // "RetryExhaustedError: sendEmail failed after 3 attempts"
445
+ * ```
446
+ */
447
+ declare class RetryExhaustedError extends /* @__PURE__ */ RetryExhaustedError_base {
448
+ }
449
+ declare const RateLimitError_base: TaggedErrorConstructor<"RateLimitError", {
450
+ /** Name of the rate limiter that was exceeded */
451
+ limiterName?: string;
452
+ /** Time in milliseconds until the rate limit resets */
453
+ retryAfterMs?: number;
454
+ }>;
455
+ /**
456
+ * Error thrown when a rate limit is exceeded.
457
+ *
458
+ * @example
459
+ * ```typescript
460
+ * const error = new RateLimitError({
461
+ * limiterName: 'api-calls',
462
+ * retryAfterMs: 1000,
463
+ * });
464
+ * console.log(error.message); // "RateLimitError: Rate limit exceeded for api-calls"
465
+ * ```
466
+ */
467
+ declare class RateLimitError extends /* @__PURE__ */ RateLimitError_base {
468
+ }
469
+ declare const CircuitBreakerOpenError_base: TaggedErrorConstructor<"CircuitBreakerOpenError", {
470
+ /** Name of the circuit breaker */
471
+ circuitName: string;
472
+ /** Current state of the circuit */
473
+ state?: "OPEN" | "HALF_OPEN";
474
+ /** Time in milliseconds until the circuit may close */
475
+ retryAfterMs?: number;
476
+ }>;
477
+ /**
478
+ * Error thrown when a circuit breaker is open.
479
+ *
480
+ * @example
481
+ * ```typescript
482
+ * const error = new CircuitBreakerOpenError({
483
+ * circuitName: 'payment-api',
484
+ * state: 'OPEN',
485
+ * retryAfterMs: 30000,
486
+ * });
487
+ * console.log(error.message); // "CircuitBreakerOpenError: Circuit payment-api is OPEN"
488
+ * ```
489
+ */
490
+ declare class CircuitBreakerOpenError extends /* @__PURE__ */ CircuitBreakerOpenError_base {
491
+ }
492
+ declare const ValidationError_base: TaggedErrorConstructor<"ValidationError", {
493
+ /** Field that failed validation */
494
+ field: string;
495
+ /** Reason for validation failure */
496
+ reason: string;
497
+ /** Raw value that failed validation */
498
+ value?: unknown;
499
+ }>;
500
+ /**
501
+ * Error thrown when validation fails.
502
+ *
503
+ * @example
504
+ * ```typescript
505
+ * const error = new ValidationError({
506
+ * field: 'email',
507
+ * reason: 'Invalid email format',
508
+ * });
509
+ * console.log(error.message); // "ValidationError: Invalid email - Invalid email format"
510
+ * ```
511
+ */
512
+ declare class ValidationError extends /* @__PURE__ */ ValidationError_base {
513
+ }
514
+ declare const NotFoundError_base: TaggedErrorConstructor<"NotFoundError", {
515
+ /** Type of resource that was not found */
516
+ resource: string;
517
+ /** Identifier of the missing resource */
518
+ id?: string;
519
+ }>;
520
+ /**
521
+ * Error thrown when a resource is not found.
522
+ *
523
+ * @example
524
+ * ```typescript
525
+ * const error = new NotFoundError({
526
+ * resource: 'User',
527
+ * id: '123',
528
+ * });
529
+ * console.log(error.message); // "NotFoundError: User with id 123 not found"
530
+ * ```
531
+ */
532
+ declare class NotFoundError extends /* @__PURE__ */ NotFoundError_base {
533
+ }
534
+ declare const UnauthorizedError_base: TaggedErrorConstructor<"UnauthorizedError", {
535
+ /** Action that was attempted */
536
+ action?: string;
537
+ /** Resource that was being accessed */
538
+ resource?: string;
539
+ /** Reason for denial */
540
+ reason?: string;
541
+ }>;
542
+ /**
543
+ * Error thrown when access is denied.
544
+ *
545
+ * @example
546
+ * ```typescript
547
+ * const error = new UnauthorizedError({
548
+ * action: 'delete',
549
+ * resource: 'User',
550
+ * });
551
+ * console.log(error.message); // "UnauthorizedError: Not authorized to delete User"
552
+ * ```
553
+ */
554
+ declare class UnauthorizedError extends /* @__PURE__ */ UnauthorizedError_base {
555
+ }
556
+ declare const NetworkError_base: TaggedErrorConstructor<"NetworkError", {
557
+ /** URL that was being accessed */
558
+ url?: string;
559
+ /** Reason for the network failure */
560
+ reason: string;
561
+ /** Whether this error is retryable */
562
+ retryable?: boolean;
563
+ /** HTTP status code if applicable */
564
+ statusCode?: number;
565
+ }>;
566
+ /**
567
+ * Error thrown for network-related failures.
568
+ *
569
+ * @example
570
+ * ```typescript
571
+ * const error = new NetworkError({
572
+ * url: 'https://api.example.com/users',
573
+ * reason: 'Connection refused',
574
+ * retryable: true,
575
+ * });
576
+ * ```
577
+ */
578
+ declare class NetworkError extends /* @__PURE__ */ NetworkError_base {
579
+ }
580
+ declare const CompensationError_base: TaggedErrorConstructor<"CompensationError", {
581
+ /** Step that triggered compensation */
582
+ step: string;
583
+ /** The original error that caused compensation */
584
+ originalError?: unknown;
585
+ /** Error that occurred during compensation */
586
+ compensationError?: unknown;
587
+ }>;
588
+ /**
589
+ * Error thrown when a saga compensation fails.
590
+ *
591
+ * @example
592
+ * ```typescript
593
+ * const error = new CompensationError({
594
+ * step: 'chargeCard',
595
+ * originalError: paymentError,
596
+ * compensationError: refundError,
597
+ * });
598
+ * ```
599
+ */
600
+ declare class CompensationError extends /* @__PURE__ */ CompensationError_base {
601
+ }
602
+ declare const UnexpectedError_base: TaggedErrorConstructor<"UnexpectedError", {
603
+ /** The original thrown value or cancellation error */
604
+ cause?: unknown;
605
+ }>;
606
+ /**
607
+ * Default error type for uncaught exceptions and cancellation in workflows.
608
+ * This is the default `U` type when `catchUnexpected` is not provided.
609
+ *
610
+ * @example
611
+ * ```typescript
612
+ * // Automatically used as the default — no need to pass catchUnexpected:
613
+ * const workflow = createWorkflow("checkout", { chargeCard, sendEmail });
614
+ *
615
+ * // Equivalent to:
616
+ * const workflow = createWorkflow("checkout", { chargeCard, sendEmail }, {
617
+ * catchUnexpected: (cause) => new UnexpectedError({ cause }),
618
+ * });
619
+ * ```
620
+ */
621
+ declare class UnexpectedError extends /* @__PURE__ */ UnexpectedError_base {
622
+ }
623
+ /**
624
+ * Union of all pre-built error types.
625
+ * Useful for exhaustive pattern matching.
626
+ *
627
+ * @example
628
+ * ```typescript
629
+ * function handleError(error: AwaitlyError): string {
630
+ * return TaggedError.match(error, {
631
+ * TimeoutError: (e) => `Timeout: ${e.ms}ms`,
632
+ * RetryExhaustedError: (e) => `Retries: ${e.attempts}`,
633
+ * RateLimitError: (e) => `Rate limited`,
634
+ * CircuitBreakerOpenError: (e) => `Circuit open: ${e.circuitName}`,
635
+ * ValidationError: (e) => `Invalid: ${e.field}`,
636
+ * NotFoundError: (e) => `Not found: ${e.resource}`,
637
+ * UnauthorizedError: (e) => `Unauthorized`,
638
+ * NetworkError: (e) => `Network: ${e.reason}`,
639
+ * CompensationError: (e) => `Compensation failed: ${e.step}`,
640
+ * UnexpectedError: (e) => e.message,
641
+ * });
642
+ * }
643
+ * ```
644
+ */
645
+ type AwaitlyError = TimeoutError | RetryExhaustedError | RateLimitError | CircuitBreakerOpenError | ValidationError | NotFoundError | UnauthorizedError | NetworkError | CompensationError | UnexpectedError;
646
+ /**
647
+ * The six awaitly-system errors that carry slug + hint + docsUrl spine fields.
648
+ *
649
+ * Distinguishes spine-bearing errors from user-domain convenience errors
650
+ * (ValidationError, NotFoundError, UnauthorizedError, NetworkError) so that
651
+ * downstream tooling (lint, analyzer, docs generator) can target the spine
652
+ * roster without duplicating the class list.
653
+ */
654
+ type AwaitlySystemError = TimeoutError | RetryExhaustedError | RateLimitError | CircuitBreakerOpenError | CompensationError | UnexpectedError;
655
+ /**
656
+ * Roster of awaitly-system error classes that participate in the slug spine.
657
+ *
658
+ * Adding a new system error means adding it to `AwaitlySystemError`, this
659
+ * roster, and `slugs.ts`. The integrity test in `spine-integrity.test.ts`
660
+ * iterates this roster, so a missing entry there is caught at CI time.
661
+ *
662
+ * @internal Tooling integration point (docs generator, integrity tests). Not
663
+ * a stable user-facing API — application code should not depend on this
664
+ * array's identity or order.
665
+ */
666
+ declare const AWAITLY_SYSTEM_ERROR_CLASSES: ReadonlyArray<new (...args: any[]) => AwaitlySystemError>;
667
+ /**
668
+ * Check if an error is a TimeoutError.
669
+ */
670
+ declare function isTimeoutError(error: unknown): error is TimeoutError;
671
+ /**
672
+ * Check if an error is a RetryExhaustedError.
673
+ */
674
+ declare function isRetryExhaustedError(error: unknown): error is RetryExhaustedError;
675
+ /**
676
+ * Check if an error is a RateLimitError.
677
+ */
678
+ declare function isRateLimitError(error: unknown): error is RateLimitError;
679
+ /**
680
+ * Check if an error is a CircuitBreakerOpenError.
681
+ */
682
+ declare function isCircuitBreakerOpenError(error: unknown): error is CircuitBreakerOpenError;
683
+ /**
684
+ * Check if an error is a ValidationError.
685
+ */
686
+ declare function isValidationError(error: unknown): error is ValidationError;
687
+ /**
688
+ * Check if an error is a NotFoundError.
689
+ */
690
+ declare function isNotFoundError(error: unknown): error is NotFoundError;
691
+ /**
692
+ * Check if an error is an UnauthorizedError.
693
+ */
694
+ declare function isUnauthorizedError(error: unknown): error is UnauthorizedError;
695
+ /**
696
+ * Check if an error is a NetworkError.
697
+ */
698
+ declare function isNetworkError(error: unknown): error is NetworkError;
699
+ /**
700
+ * Check if an error is a CompensationError.
701
+ */
702
+ declare function isCompensationError(error: unknown): error is CompensationError;
703
+ /**
704
+ * Check if an error is any AwaitlyError.
705
+ */
706
+ declare function isAwaitlyError(error: unknown): error is AwaitlyError;
707
+
708
+ export { ALL_SLUGS as A, isValidationError as B, CircuitBreakerOpenError as C, makeError as D, type ErrorByTag as E, slugCategory as F, slugDocsUrl as G, NetworkError as N, type PropsOf as P, RateLimitError as R, TimeoutError as T, UnexpectedError as U, ValidationError as V, AWAITLY_SLUGS as a, AWAITLY_SYSTEM_ERROR_CLASSES as b, type AwaitlyError as c, type AwaitlySlug as d, type AwaitlySlugCategory as e, type AwaitlySystemError as f, CompensationError as g, NotFoundError as h, RetryExhaustedError as i, type TagOf as j, TaggedError as k, type TaggedErrorBase as l, type TaggedErrorConstructor as m, type TaggedErrorCreateOptions as n, type TaggedErrorOptions as o, UnauthorizedError as p, isAwaitlyError as q, isAwaitlySlug as r, isCircuitBreakerOpenError as s, isCompensationError as t, isNetworkError as u, isNotFoundError as v, isRateLimitError as w, isRetryExhaustedError as x, isTimeoutError as y, isUnauthorizedError as z };