awaitly 1.34.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 +35 -5
  14. package/dist/result.d.ts +35 -5
  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-D2MmJFj9.d.cts → types-B8NfNRGX.d.ts} +1152 -1499
  24. package/dist/{run-entry-Dduz-is2.d.ts → types-BZ2f4MRR.d.cts} +1152 -1499
  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 +13 -178
  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-COl5oFnR.d.cts +0 -15
  75. package/dist/di-CyDj_JyZ.d.ts +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-BodHXLzX.d.cts +0 -72
  123. package/dist/guards-CeWoQ8fn.d.ts +0 -72
  124. package/dist/hitl-BPE_1UiM.d.cts +0 -468
  125. package/dist/hitl-byp570uC.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-BYT3amEz.d.ts +0 -417
  133. package/dist/index-C_ak66jy.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-DOMx3woy.d.ts +0 -822
  149. package/dist/persistence-entry-ymCA4iDu.d.cts +0 -822
  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-DQmzO9f4.d.ts +0 -323
  235. package/dist/types-qBUOYi-4.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
package/dist/errors.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var h=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var V=(e,r)=>{for(var n in r)h(e,n,{get:r[n],enumerable:!0})},q=(e,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of j(r))!M.call(e,a)&&a!==n&&h(e,a,{get:()=>r[a],enumerable:!(s=I(r,a))||s.enumerable});return e};var W=e=>q(h({},"__esModule",{value:!0}),e);var D={};V(D,{AWAITLY_SYSTEM_ERROR_CLASSES:()=>b,CircuitBreakerOpenError:()=>E,CompensationError:()=>m,NetworkError:()=>T,NotFoundError:()=>x,RateLimitError:()=>p,RetryExhaustedError:()=>l,TimeoutError:()=>d,UnauthorizedError:()=>k,UnexpectedError:()=>y,ValidationError:()=>w,isAwaitlyError:()=>v,isCircuitBreakerOpenError:()=>S,isCompensationError:()=>L,isNetworkError:()=>U,isNotFoundError:()=>H,isRateLimitError:()=>P,isRetryExhaustedError:()=>O,isTimeoutError:()=>C,isUnauthorizedError:()=>N,isValidationError:()=>$,makeError:()=>A});module.exports=W(D);var Y={"step-require-id":"step-require-id","step-no-immediate-execution":"step-no-immediate-execution","step-require-thunk-for-key":"step-require-thunk-for-key","step-no-bare-await":"step-no-bare-await","step-no-try-catch-wrap":"step-no-try-catch-wrap","step-stable-cache-keys":"step-stable-cache-keys","workflow-no-floating":"workflow-no-floating","workflow-options-position":"workflow-options-position","workflow-callback-shape":"workflow-callback-shape","workflow-no-callable-form":"workflow-no-callable-form","workflow-no-dynamic-import":"workflow-no-dynamic-import","result-no-floating":"result-no-floating","result-require-handling":"result-require-handling","result-no-double-wrap":"result-no-double-wrap","result-no-manual-propagation":"result-no-manual-propagation","result-no-direct-ok-err":"result-no-direct-ok-err","error-check-unexpected-first":"error-check-unexpected-first","error-access-cause":"error-access-cause","error-normalize":"error-normalize","error-no-throw-in-deps":"error-no-throw-in-deps","concurrency-no-promise-all":"concurrency-no-promise-all","concurrency-no-promise-race":"concurrency-no-promise-race","concurrency-no-promise-allsettled":"concurrency-no-promise-allsettled","runtime-step-timeout":"runtime-step-timeout","runtime-step-aborted":"runtime-step-aborted","runtime-retry-exhausted":"runtime-retry-exhausted","runtime-rate-limit":"runtime-rate-limit","runtime-circuit-open":"runtime-circuit-open","runtime-unexpected":"runtime-unexpected","runtime-resolver-not-found":"runtime-resolver-not-found","runtime-saga-compensation":"runtime-saga-compensation"};function _(e){return`https://jagreehal.github.io/awaitly/rules/#${e}`}var X=Object.keys(Y);var g=class extends Error{_tag};function t(e,r){return class extends g{_tag=e;constructor(n,s){let a=r?.message?r.message(n??{}):e;if(super(a),this.name=e,r?.slug!==void 0){if(!r.hint)throw new TypeError(`TaggedError: 'hint' is required when 'slug' is set (slug: "${r.slug}")`);Object.defineProperty(this,"code",{value:r.slug,enumerable:!0,writable:!1,configurable:!1}),Object.defineProperty(this,"hint",{value:r.hint,enumerable:!0,writable:!1,configurable:!1}),Object.defineProperty(this,"docsUrl",{value:_(r.slug),enumerable:!0,writable:!1,configurable:!1})}if(Object.setPrototypeOf(this,new.target.prototype),n&&typeof n=="object"){let o;if(r?.slug!==void 0){let{_tag:f,name:B,message:F,stack:K,code:R,hint:G,docsUrl:J,...z}=n;o=z}else{let{_tag:f,name:B,message:F,stack:K,...R}=n;o=R}let i=Object.prototype.hasOwnProperty.call(o,"cause"),c=i?o.cause:void 0;i&&delete o.cause;let u=s?.cause!==void 0;if(i&&u)throw new TypeError("TaggedError: cannot provide 'cause' in props when also setting ErrorOptions.cause");Object.assign(this,o),i&&(this.cause=c),u&&(this.cause=s?.cause)}else s?.cause!==void 0&&(this.cause=s.cause)}}}Object.defineProperty(t,Symbol.hasInstance,{value:e=>e instanceof g});(a=>{function e(o){return o instanceof Error}a.isError=e;function r(o){return o instanceof g}a.isTaggedError=r;function n(o,i){let c=o._tag,u=i[c];return u(o)}a.match=n;function s(o,i,c){let u=o._tag,f=i[u];return f?f(o):c(o)}a.matchPartial=s})(t||={});function A(e,r){let n=r?.message??(()=>e),s=r?.defaults??{},a=t(e,{message:o=>n({...s,...o})});return class extends a{constructor(o){super({...s,...o}),Object.assign(this,{...s,...o})}}}var d=class extends t("TimeoutError",{slug:"runtime-step-timeout",hint:"Increase the step's timeout option, or check why the upstream operation is slow.",message:r=>r.operation?`TimeoutError: ${r.operation} timed out after ${r.ms}ms`:`TimeoutError: Operation timed out after ${r.ms}ms`}){},l=class extends t("RetryExhaustedError",{slug:"runtime-retry-exhausted",hint:"All retry attempts failed. Inspect lastError and decide whether to surface it or compensate.",message:r=>r.operation?`RetryExhaustedError: ${r.operation} failed after ${r.attempts} attempts`:`RetryExhaustedError: Operation failed after ${r.attempts} attempts`}){},p=class extends t("RateLimitError",{slug:"runtime-rate-limit",hint:"Wait retryAfterMs before retrying, or apply step.cache to deduplicate calls.",message:r=>r.limiterName?`RateLimitError: Rate limit exceeded for ${r.limiterName}${r.retryAfterMs?`, retry after ${r.retryAfterMs}ms`:""}`:`RateLimitError: Rate limit exceeded${r.retryAfterMs?`, retry after ${r.retryAfterMs}ms`:""}`}){},E=class extends t("CircuitBreakerOpenError",{slug:"runtime-circuit-open",hint:"The circuit is open. Wait for it to half-open or fall back to a degraded path.",message:r=>`CircuitBreakerOpenError: Circuit ${r.circuitName} is ${r.state??"OPEN"}${r.retryAfterMs?`, retry after ${Math.ceil(r.retryAfterMs/1e3)}s`:""}`}){},w=class extends t("ValidationError",{message:r=>`ValidationError: Invalid ${r.field} - ${r.reason}`}){},x=class extends t("NotFoundError",{message:r=>r.id?`NotFoundError: ${r.resource} with id ${r.id} not found`:`NotFoundError: ${r.resource} not found`}){},k=class extends t("UnauthorizedError",{message:r=>r.reason?`UnauthorizedError: ${r.reason}`:r.action&&r.resource?`UnauthorizedError: Not authorized to ${r.action} ${r.resource}`:"UnauthorizedError: Access denied"}){},T=class extends t("NetworkError",{message:r=>r.url?`NetworkError: ${r.reason} (${r.url})`:`NetworkError: ${r.reason}`}){},m=class extends t("CompensationError",{slug:"runtime-saga-compensation",hint:"A saga compensation step failed. Inspect compensationError and ensure compensation is idempotent.",message:r=>`CompensationError: Failed to compensate step ${r.step}`}){},y=class extends t("UnexpectedError",{slug:"runtime-unexpected",hint:"An unexpected exception escaped a step. Inspect cause; consider returning a typed Result instead of throwing.",message:r=>`UnexpectedError: ${r.cause instanceof Error?r.cause.message:String(r.cause??"unknown")}`}){},b=[d,l,p,E,m,y];function C(e){return t.isTaggedError(e)&&e._tag==="TimeoutError"}function O(e){return t.isTaggedError(e)&&e._tag==="RetryExhaustedError"}function P(e){return t.isTaggedError(e)&&e._tag==="RateLimitError"}function S(e){return t.isTaggedError(e)&&e._tag==="CircuitBreakerOpenError"}function $(e){return t.isTaggedError(e)&&e._tag==="ValidationError"}function H(e){return t.isTaggedError(e)&&e._tag==="NotFoundError"}function N(e){return t.isTaggedError(e)&&e._tag==="UnauthorizedError"}function U(e){return t.isTaggedError(e)&&e._tag==="NetworkError"}function L(e){return t.isTaggedError(e)&&e._tag==="CompensationError"}function v(e){if(!t.isTaggedError(e))return!1;let r=e._tag;return["TimeoutError","RetryExhaustedError","RateLimitError","CircuitBreakerOpenError","ValidationError","NotFoundError","UnauthorizedError","NetworkError","CompensationError","UnexpectedError"].includes(r)}0&&(module.exports={AWAITLY_SYSTEM_ERROR_CLASSES,CircuitBreakerOpenError,CompensationError,NetworkError,NotFoundError,RateLimitError,RetryExhaustedError,TimeoutError,UnauthorizedError,UnexpectedError,ValidationError,isAwaitlyError,isCircuitBreakerOpenError,isCompensationError,isNetworkError,isNotFoundError,isRateLimitError,isRetryExhaustedError,isTimeoutError,isUnauthorizedError,isValidationError,makeError});
2
- //# sourceMappingURL=errors.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/errors-entry.ts","../src/slugs.ts","../src/tagged-error.ts","../src/errors.ts"],"sourcesContent":["/**\n * awaitly/errors entry point\n *\n * Pre-built error types for common failure scenarios.\n */\nexport {\n // Factory\n makeError,\n // Pre-built errors\n TimeoutError,\n RetryExhaustedError,\n RateLimitError,\n CircuitBreakerOpenError,\n ValidationError,\n NotFoundError,\n UnauthorizedError,\n NetworkError,\n CompensationError,\n UnexpectedError,\n // Union types\n type AwaitlyError,\n type AwaitlySystemError,\n // Roster\n AWAITLY_SYSTEM_ERROR_CLASSES,\n // Type guards\n isTimeoutError,\n isRetryExhaustedError,\n isRateLimitError,\n isCircuitBreakerOpenError,\n isValidationError,\n isNotFoundError,\n isUnauthorizedError,\n isNetworkError,\n isCompensationError,\n isAwaitlyError,\n} from \"./errors\";\n","/**\n * awaitly/slugs\n *\n * Source-of-truth slug namespace. Every concept that surfaces as a runtime\n * error, lint rule, static-analyzer diagnostic, visualizer event, or skill rule\n * has exactly one canonical kebab-case slug here.\n *\n * Slugs are public API. Renames are a major version bump. Adds are non-breaking.\n *\n * Categories:\n * - step-* step() discipline\n * - workflow-* createWorkflow / run / runWithState shape\n * - result-* Result usage\n * - error-* Boundary handling\n * - concurrency-* step.all/map/race vs Promise.*\n * - runtime-* Failures only observable at runtime\n */\n\nexport const AWAITLY_SLUGS = {\n // --- step-* ---\n \"step-require-id\": \"step-require-id\",\n \"step-no-immediate-execution\": \"step-no-immediate-execution\",\n \"step-require-thunk-for-key\": \"step-require-thunk-for-key\",\n \"step-no-bare-await\": \"step-no-bare-await\",\n \"step-no-try-catch-wrap\": \"step-no-try-catch-wrap\",\n \"step-stable-cache-keys\": \"step-stable-cache-keys\",\n\n // --- workflow-* ---\n \"workflow-no-floating\": \"workflow-no-floating\",\n \"workflow-options-position\": \"workflow-options-position\",\n \"workflow-callback-shape\": \"workflow-callback-shape\",\n \"workflow-no-callable-form\": \"workflow-no-callable-form\",\n \"workflow-no-dynamic-import\": \"workflow-no-dynamic-import\",\n\n // --- result-* ---\n \"result-no-floating\": \"result-no-floating\",\n \"result-require-handling\": \"result-require-handling\",\n \"result-no-double-wrap\": \"result-no-double-wrap\",\n \"result-no-manual-propagation\": \"result-no-manual-propagation\",\n \"result-no-direct-ok-err\": \"result-no-direct-ok-err\",\n\n // --- error-* ---\n \"error-check-unexpected-first\": \"error-check-unexpected-first\",\n \"error-access-cause\": \"error-access-cause\",\n \"error-normalize\": \"error-normalize\",\n \"error-no-throw-in-deps\": \"error-no-throw-in-deps\",\n\n // --- concurrency-* ---\n \"concurrency-no-promise-all\": \"concurrency-no-promise-all\",\n \"concurrency-no-promise-race\": \"concurrency-no-promise-race\",\n \"concurrency-no-promise-allsettled\": \"concurrency-no-promise-allsettled\",\n\n // --- runtime-* ---\n \"runtime-step-timeout\": \"runtime-step-timeout\",\n \"runtime-step-aborted\": \"runtime-step-aborted\",\n \"runtime-retry-exhausted\": \"runtime-retry-exhausted\",\n \"runtime-rate-limit\": \"runtime-rate-limit\",\n \"runtime-circuit-open\": \"runtime-circuit-open\",\n \"runtime-unexpected\": \"runtime-unexpected\",\n \"runtime-resolver-not-found\": \"runtime-resolver-not-found\",\n \"runtime-saga-compensation\": \"runtime-saga-compensation\",\n} as const;\n\n/** All canonical awaitly slugs as a string-literal union. */\nexport type AwaitlySlug = keyof typeof AWAITLY_SLUGS;\n\n/** Categories derived from slug prefixes. */\nexport type AwaitlySlugCategory =\n | \"step\"\n | \"workflow\"\n | \"result\"\n | \"error\"\n | \"concurrency\"\n | \"runtime\";\n\n/** Returns the category (prefix) of a slug. */\nexport function slugCategory(slug: AwaitlySlug): AwaitlySlugCategory {\n return slug.split(\"-\")[0] as AwaitlySlugCategory;\n}\n\n/**\n * Returns the canonical docs URL for a slug. Resolves to the matching\n * anchored section on the consolidated rule index page.\n */\nexport function slugDocsUrl(slug: AwaitlySlug): string {\n return `https://jagreehal.github.io/awaitly/rules/#${slug}`;\n}\n\n/** Type guard: is a string a known awaitly slug? */\nexport function isAwaitlySlug(value: string): value is AwaitlySlug {\n return Object.prototype.hasOwnProperty.call(AWAITLY_SLUGS, value);\n}\n\n/** All slugs as an array. */\n// Object.keys returns string[] — cast is safe because AWAITLY_SLUGS is `as const`\n// and the module's keys are never mutated.\nexport const ALL_SLUGS: readonly AwaitlySlug[] = Object.keys(\n AWAITLY_SLUGS\n) as AwaitlySlug[];\n","/**\n * awaitly/tagged-error\n *\n * Factory for creating tagged error types with exhaustive pattern matching.\n * Enables TypeScript to enforce that all error variants are handled.\n *\n * @example\n * ```typescript\n * // Define error types (Props via generic)\n * class NotFoundError extends TaggedError(\"NotFoundError\")<{\n * id: string;\n * resource: string;\n * }> {}\n *\n * // Define with type-safe message (Props inferred from callback annotation)\n * class ValidationError extends TaggedError(\"ValidationError\", {\n * message: (p: { field: string; reason: string }) => `Invalid ${p.field}: ${p.reason}`,\n * }) {}\n *\n * // Create instances\n * const error = new NotFoundError({ id: \"123\", resource: \"User\" });\n *\n * // Runtime type check: instanceof TaggedError works!\n * console.log(error instanceof TaggedError); // true\n *\n * // Exhaustive matching\n * type AppError = NotFoundError | ValidationError;\n * const message = TaggedError.match(error as AppError, {\n * NotFoundError: (e) => `Missing: ${e.resource} ${e.id}`,\n * ValidationError: (e) => `Invalid ${e.field}: ${e.reason}`,\n * });\n * ```\n */\n\nimport { type AwaitlySlug, slugDocsUrl } from \"./slugs\";\n\n/**\n * Options for Error constructor (compatible with ES2022 ErrorOptions).\n */\nexport interface TaggedErrorOptions {\n cause?: unknown;\n}\n\n/**\n * Options for TaggedError factory with type-safe message callback.\n */\nexport interface TaggedErrorCreateOptions<Props extends Record<string, unknown>> {\n /** Custom message generator from props. Annotate parameter for type safety. */\n message: (props: Props) => string;\n /**\n * Canonical awaitly slug for this error class. When set, instances carry\n * `code`, `hint`, and `docsUrl` populated from the slugs namespace.\n * Required together with `hint` for awaitly-system errors.\n */\n slug?: AwaitlySlug;\n /**\n * One-line \"do X instead\" guidance shown alongside the error.\n * Required when `slug` is set.\n */\n hint?: string;\n}\n\n/**\n * Base interface for all tagged errors.\n */\nexport interface TaggedErrorBase extends Error {\n readonly _tag: string;\n /** Canonical slug for awaitly-system errors. Undefined for user errors that opt out. */\n readonly code?: AwaitlySlug;\n /** One-line guidance. Undefined when no slug is set. */\n readonly hint?: string;\n /** Canonical docs URL. Undefined when no slug is set. */\n readonly docsUrl?: string;\n}\n\n/**\n * Internal base class for instanceof checks.\n * All TaggedError-created classes extend this.\n * @internal\n */\nclass InternalTaggedErrorBase extends Error implements TaggedErrorBase {\n readonly _tag!: string;\n}\n\n/**\n * Instance type for factory-created TaggedErrors.\n */\ntype TaggedErrorInstance<Tag extends string, Props> = TaggedErrorBase & {\n readonly _tag: Tag;\n} & Readonly<Props>;\n\n/**\n * Constructor args type - conditionally optional based on whether Props has required fields.\n * - If Props is empty or all properties are optional: props argument is optional\n * - If Props has any required properties: props argument is required\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\ntype ConstructorArgs<Props extends Record<string, unknown>> = {} extends Props\n ? [props?: Props | void, options?: TaggedErrorOptions]\n : [props: Props, options?: TaggedErrorOptions];\n\n/**\n * Constructor type returned by TaggedError factory.\n */\nexport interface TaggedErrorConstructor<\n Tag extends string,\n Props extends Record<string, unknown>,\n> {\n new (...args: ConstructorArgs<Props>): TaggedErrorInstance<Tag, Props>;\n readonly prototype: TaggedErrorInstance<Tag, Props>;\n}\n\n/**\n * Generic class factory type that allows `<Props>` parameterization.\n * This enables the Effect.js-style syntax: `class X extends TaggedError(\"X\")<Props> {}`\n * @internal\n */\nexport interface TaggedErrorClassFactory<Tag extends string> {\n new <Props extends Record<string, unknown> = Record<string, never>>(\n ...args: ConstructorArgs<Props>\n ): TaggedErrorInstance<Tag, Props>;\n}\n\n/**\n * Helper type to extract return type from a function type.\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype FnReturnType<T> = T extends (...args: any[]) => infer R ? R : never;\n\n/**\n * Helper type to get union of return types from all handlers.\n * @internal\n */\ntype HandlersReturnType<H> = { [K in keyof H]: FnReturnType<H[K]> }[keyof H];\n\n/**\n * Helper type to extract keys whose values are definitely functions (not undefined).\n * Only excludes a tag from the fallback type if its handler is guaranteed to be\n * a function. Keys where the value type includes undefined are NOT excluded,\n * ensuring type safety with dynamic/conditional handlers.\n * @internal\n */\ntype DefinitelyHandledKeys<H> = {\n [K in keyof H]-?: undefined extends H[K] ? never : K;\n}[keyof H];\n\n/**\n * Factory function to create tagged error classes.\n *\n * Two usage patterns:\n *\n * 1. **Props via generic** (default message is tag name):\n * ```typescript\n * class NotFoundError extends TaggedError(\"NotFoundError\")<{ id: string }> {}\n * ```\n *\n * 2. **Props inferred from message callback** (type-safe message):\n * ```typescript\n * class NotFoundError extends TaggedError(\"NotFoundError\", {\n * message: (p: { id: string }) => `Not found: ${p.id}`,\n * }) {}\n * ```\n *\n * Both support `instanceof TaggedError` checks at runtime.\n *\n * @param tag - The unique tag string for this error type\n * @param options - Optional configuration with message generator (annotate param for type safety)\n * @returns A class constructor that can be extended\n */\n\n// Overload 1: No options - use <Props> generic syntax, default message is tag\nfunction TaggedError<Tag extends string>(\n tag: Tag\n): TaggedErrorClassFactory<Tag>;\n\n// Overload 2: With message option - Props inferred from callback parameter annotation\nfunction TaggedError<Tag extends string, Props extends Record<string, unknown>>(\n tag: Tag,\n options: TaggedErrorCreateOptions<Props>\n): TaggedErrorConstructor<Tag, Props>;\n\n// Implementation\nfunction TaggedError<Tag extends string, Props extends Record<string, unknown>>(\n tag: Tag,\n options?: TaggedErrorCreateOptions<Props>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any {\n return class extends InternalTaggedErrorBase {\n override readonly _tag: Tag = tag;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(props?: any, errorOptions?: TaggedErrorOptions) {\n // Generate message: call callback if provided (even for prop-less errors), else use tag\n const message = options?.message ? options.message(props ?? {}) : tag;\n\n super(message);\n this.name = tag;\n\n // Spine fields: populate when factory was given a slug\n if (options?.slug !== undefined) {\n if (!options.hint) {\n throw new TypeError(\n `TaggedError: 'hint' is required when 'slug' is set (slug: \"${options.slug}\")`\n );\n }\n Object.defineProperty(this, \"code\", {\n value: options.slug,\n enumerable: true,\n writable: false,\n configurable: false,\n });\n Object.defineProperty(this, \"hint\", {\n value: options.hint,\n enumerable: true,\n writable: false,\n configurable: false,\n });\n Object.defineProperty(this, \"docsUrl\", {\n value: slugDocsUrl(options.slug),\n enumerable: true,\n writable: false,\n configurable: false,\n });\n }\n\n // Maintains proper prototype chain for instanceof checks\n Object.setPrototypeOf(this, new.target.prototype);\n\n // Assign props to instance, stripping reserved keys:\n // - _tag: discriminant for pattern matching (cannot be forged)\n // - name, message, stack: Error internals (preserve for logging/debugging)\n // - code, hint, docsUrl: spine fields stripped when slug is set, to prevent\n // Object.assign from clobbering the non-configurable/non-writable own props\n // Note: 'cause' is allowed as a user prop (common for domain errors)\n if (props && typeof props === \"object\") {\n let safeProps: Record<string, unknown>;\n if (options?.slug !== undefined) {\n const {\n _tag: _,\n name: _n,\n message: _m,\n stack: _s,\n code: _c,\n hint: _h,\n docsUrl: _d,\n ...rest\n } = props;\n safeProps = rest;\n } else {\n const {\n _tag: _,\n name: _n,\n message: _m,\n stack: _s,\n ...rest\n } = props;\n safeProps = rest;\n }\n\n const hasUserCause = Object.prototype.hasOwnProperty.call(\n safeProps,\n \"cause\"\n );\n const userCause = hasUserCause\n ? (safeProps as { cause?: unknown }).cause\n : undefined;\n if (hasUserCause) {\n delete (safeProps as { cause?: unknown }).cause;\n }\n\n const hasOptionsCause = errorOptions?.cause !== undefined;\n if (hasUserCause && hasOptionsCause) {\n throw new TypeError(\n \"TaggedError: cannot provide 'cause' in props when also setting ErrorOptions.cause\"\n );\n }\n\n Object.assign(this, safeProps);\n\n if (hasUserCause) {\n (this as { cause?: unknown }).cause = userCause;\n }\n if (hasOptionsCause) {\n (this as { cause?: unknown }).cause = errorOptions?.cause;\n }\n } else if (errorOptions?.cause !== undefined) {\n (this as { cause?: unknown }).cause = errorOptions.cause;\n }\n }\n };\n}\n\n// Add Symbol.hasInstance so `instanceof TaggedError` works\nObject.defineProperty(TaggedError, Symbol.hasInstance, {\n value: (instance: unknown): boolean => instance instanceof InternalTaggedErrorBase,\n});\n\n/**\n * Namespace for static methods on TaggedError.\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nnamespace TaggedError {\n /**\n * Type guard to check if a value is an Error instance.\n */\n export function isError(value: unknown): value is Error {\n return value instanceof Error;\n }\n\n /**\n * Type guard to check if a value is a TaggedError instance.\n * Uses the same check as `instanceof TaggedError` - only genuine\n * TaggedError instances (created via the factory) pass this guard.\n */\n export function isTaggedError(value: unknown): value is TaggedErrorBase {\n return value instanceof InternalTaggedErrorBase;\n }\n\n /**\n * Exhaustively matches on a tagged error, requiring handlers for all variants.\n *\n * TypeScript will error if any variant in the error union is not handled.\n *\n * @remarks When to use: You want compile-time enforcement that every tagged variant is handled.\n *\n * @param error - The tagged error to match\n * @param handlers - Object mapping _tag values to handler functions\n * @returns The return value of the matched handler\n *\n * @example\n * ```typescript\n * type AppError = NotFoundError | ValidationError;\n *\n * const message = TaggedError.match(error, {\n * NotFoundError: (e) => `Not found: ${e.id}`,\n * ValidationError: (e) => `Invalid: ${e.field}`,\n * });\n * ```\n */\n export function match<\n E extends TaggedErrorBase,\n H extends { [K in E[\"_tag\"]]: (e: Extract<E, { _tag: K }>) => unknown },\n >(error: E, handlers: H): HandlersReturnType<H> {\n const tag = error._tag as E[\"_tag\"];\n const handler = handlers[tag];\n return handler(\n error as Extract<E, { _tag: typeof tag }>\n ) as HandlersReturnType<H>;\n }\n\n /**\n * Partially matches on a tagged error with a fallback for unhandled variants.\n *\n * The fallback receives variants that are NOT definitely handled. A tag is\n * considered \"definitely handled\" only if its handler is a function (not\n * `undefined`). This ensures type safety even with dynamic/conditional handlers:\n *\n * ```typescript\n * const maybeHandle = featureFlag ? (e) => e.id : undefined;\n * TaggedError.matchPartial(\n * error,\n * { NotFoundError: maybeHandle }, // maybeHandle might be undefined\n * (e) => e._tag // e correctly includes NotFoundError\n * );\n * ```\n *\n * @param error - The tagged error to match\n * @param handlers - Partial object mapping _tag values to handler functions\n * @param otherwise - Fallback handler for unmatched variants\n * @returns The return value of the matched handler or fallback\n *\n * @example\n * ```typescript\n * const message = TaggedError.matchPartial(\n * error,\n * { NotFoundError: (e) => `Not found: ${e.id}` },\n * (e) => `Other error: ${e.message}`\n * );\n * ```\n */\n export function matchPartial<\n E extends TaggedErrorBase,\n H extends Partial<{\n [K in E[\"_tag\"]]: (e: Extract<E, { _tag: K }>) => unknown;\n }>,\n T,\n >(\n error: E,\n handlers: H,\n otherwise: (e: Exclude<E, { _tag: DefinitelyHandledKeys<H> }>) => T\n ): HandlersReturnType<H> | T {\n const tag = error._tag as E[\"_tag\"];\n const handler = handlers[tag];\n if (handler) {\n return handler(\n error as Extract<E, { _tag: typeof tag }>\n ) as HandlersReturnType<H>;\n }\n return otherwise(error as Exclude<E, { _tag: DefinitelyHandledKeys<H> }>);\n }\n}\n\nexport { TaggedError };\n\n/**\n * Helper type to extract the _tag literal type from a TaggedError.\n *\n * @example\n * ```typescript\n * class MyError extends TaggedError(\"MyError\")<{ id: string }> {}\n * type Tag = TagOf<MyError>; // \"MyError\"\n * ```\n */\nexport type TagOf<E extends TaggedErrorBase> = E[\"_tag\"];\n\n/**\n * Helper type to extract a specific variant from a TaggedError union by tag.\n *\n * @example\n * ```typescript\n * type AppError = NotFoundError | ValidationError;\n * type NotFound = ErrorByTag<AppError, \"NotFoundError\">; // NotFoundError\n * ```\n */\nexport type ErrorByTag<\n E extends TaggedErrorBase,\n Tag extends E[\"_tag\"],\n> = Extract<E, { _tag: Tag }>;\n\n/**\n * Reserved keys that are stripped from user props at runtime.\n * These keys cannot be used as user-defined properties:\n * - _tag: discriminant for pattern matching\n * - name, message, stack: Error internals (preserved for logging/debugging)\n * - code, hint, docsUrl: spine fields (non-configurable own properties when slug is set)\n *\n * Note: 'cause' is NOT reserved - it can be used as a user prop.\n */\ntype ReservedErrorKeys = \"_tag\" | \"name\" | \"message\" | \"stack\" | \"code\" | \"hint\" | \"docsUrl\";\n\n/**\n * Helper type to extract props from a TaggedError.\n * Excludes reserved keys that are stripped at runtime.\n *\n * @example\n * ```typescript\n * class MyError extends TaggedError(\"MyError\")<{ id: string }> {}\n * type Props = PropsOf<MyError>; // { id: string }\n *\n * // 'cause' is allowed as a user prop\n * class DomainError extends TaggedError(\"DomainError\")<{ cause: { field: string } }> {}\n * type DomainProps = PropsOf<DomainError>; // { cause: { field: string } }\n * ```\n */\nexport type PropsOf<E extends TaggedErrorBase> = Omit<E, ReservedErrorKeys>;\n","/**\n * awaitly/errors\n *\n * Pre-built error types for common failure scenarios.\n * Uses TaggedError for type-safe exhaustive matching.\n *\n * @example\n * ```typescript\n * import { TimeoutError, RetryExhaustedError, RateLimitError, CircuitBreakerOpenError } from 'awaitly/errors';\n *\n * // Create errors\n * const timeout = new TimeoutError({ operation: 'fetchUser', ms: 5000 });\n * const retryFailed = new RetryExhaustedError({ operation: 'sendEmail', attempts: 3 });\n *\n * // Pattern match\n * TaggedError.match(error, {\n * TimeoutError: (e) => `${e.operation} timed out after ${e.ms}ms`,\n * RetryExhaustedError: (e) => `${e.operation} failed after ${e.attempts} attempts`,\n * RateLimitError: (e) => `Rate limit exceeded, retry after ${e.retryAfterMs}ms`,\n * CircuitBreakerOpenError: (e) => `Circuit ${e.circuitName} is open`,\n * });\n * ```\n */\n\n/**\n * Spine policy:\n *\n * Awaitly-system errors (raised by awaitly internals on workflow execution\n * failure modes) carry a `slug` + `hint` so they participate in the\n * AI-DX spine: TimeoutError, RetryExhaustedError, RateLimitError,\n * CircuitBreakerOpenError, CompensationError, UnexpectedError.\n *\n * Convenience domain errors (ValidationError, NotFoundError,\n * UnauthorizedError, NetworkError) are deliberately NOT slugged — they\n * represent USER domain failures and would force user code into the\n * awaitly slug namespace. Users can opt in by adding `slug` + `hint`\n * to their own TaggedError subclasses.\n */\n\nimport { TaggedError } from \"./tagged-error\";\n\n// =============================================================================\n// Error Factory\n// =============================================================================\n\n/**\n * Factory function to create tagged error classes with default values.\n *\n * This is a convenience wrapper around TaggedError that allows specifying\n * default property values for error types.\n *\n * @example\n * ```typescript\n * const NetworkError = makeError('NetworkError', {\n * defaults: { retryable: true },\n * message: (p) => `Network error: ${p.reason}`,\n * });\n *\n * class MyNetworkError extends NetworkError<{ reason: string; code?: number }> {}\n * ```\n */\nexport function makeError<Tag extends string>(\n tag: Tag,\n options?: {\n message?: (props: Record<string, unknown>) => string;\n defaults?: Record<string, unknown>;\n }\n) {\n const messageGenerator = options?.message ?? (() => tag);\n const defaults = options?.defaults ?? {};\n\n const BaseClass = TaggedError(tag, {\n message: (props: Record<string, unknown>) =>\n messageGenerator({ ...defaults, ...props }),\n });\n\n return class extends BaseClass {\n constructor(props?: Record<string, unknown>) {\n super({ ...defaults, ...props } as Record<string, unknown>);\n Object.assign(this, { ...defaults, ...props });\n }\n };\n}\n\n// =============================================================================\n// Pre-built Error Types\n// =============================================================================\n\n/**\n * Error thrown when an operation times out.\n *\n * @example\n * ```typescript\n * const error = new TimeoutError({\n * operation: 'fetchUser',\n * ms: 5000,\n * });\n * console.log(error.message); // \"TimeoutError: fetchUser timed out after 5000ms\"\n * ```\n */\nexport class TimeoutError extends TaggedError(\"TimeoutError\", {\n slug: \"runtime-step-timeout\",\n hint: \"Increase the step's timeout option, or check why the upstream operation is slow.\",\n message: (p: {\n /** Name of the operation that timed out */\n operation?: string;\n /** Timeout duration in milliseconds */\n ms: number;\n }) =>\n p.operation\n ? `TimeoutError: ${p.operation} timed out after ${p.ms}ms`\n : `TimeoutError: Operation timed out after ${p.ms}ms`,\n}) {}\n\n/**\n * Error thrown when all retry attempts are exhausted.\n *\n * @example\n * ```typescript\n * const error = new RetryExhaustedError({\n * operation: 'sendEmail',\n * attempts: 3,\n * lastError: originalError,\n * });\n * console.log(error.message); // \"RetryExhaustedError: sendEmail failed after 3 attempts\"\n * ```\n */\nexport class RetryExhaustedError extends TaggedError(\"RetryExhaustedError\", {\n slug: \"runtime-retry-exhausted\",\n hint: \"All retry attempts failed. Inspect lastError and decide whether to surface it or compensate.\",\n message: (p: {\n /** Name of the operation that failed */\n operation?: string;\n /** Total number of retry attempts made */\n attempts: number;\n /** The last error encountered before giving up */\n lastError?: unknown;\n }) =>\n p.operation\n ? `RetryExhaustedError: ${p.operation} failed after ${p.attempts} attempts`\n : `RetryExhaustedError: Operation failed after ${p.attempts} attempts`,\n}) {}\n\n/**\n * Error thrown when a rate limit is exceeded.\n *\n * @example\n * ```typescript\n * const error = new RateLimitError({\n * limiterName: 'api-calls',\n * retryAfterMs: 1000,\n * });\n * console.log(error.message); // \"RateLimitError: Rate limit exceeded for api-calls\"\n * ```\n */\nexport class RateLimitError extends TaggedError(\"RateLimitError\", {\n slug: \"runtime-rate-limit\",\n hint: \"Wait retryAfterMs before retrying, or apply step.cache to deduplicate calls.\",\n message: (p: {\n /** Name of the rate limiter that was exceeded */\n limiterName?: string;\n /** Time in milliseconds until the rate limit resets */\n retryAfterMs?: number;\n }) =>\n p.limiterName\n ? `RateLimitError: Rate limit exceeded for ${p.limiterName}${p.retryAfterMs ? `, retry after ${p.retryAfterMs}ms` : \"\"}`\n : `RateLimitError: Rate limit exceeded${p.retryAfterMs ? `, retry after ${p.retryAfterMs}ms` : \"\"}`,\n}) {}\n\n/**\n * Error thrown when a circuit breaker is open.\n *\n * @example\n * ```typescript\n * const error = new CircuitBreakerOpenError({\n * circuitName: 'payment-api',\n * state: 'OPEN',\n * retryAfterMs: 30000,\n * });\n * console.log(error.message); // \"CircuitBreakerOpenError: Circuit payment-api is OPEN\"\n * ```\n */\nexport class CircuitBreakerOpenError extends TaggedError(\n \"CircuitBreakerOpenError\",\n {\n slug: \"runtime-circuit-open\",\n hint: \"The circuit is open. Wait for it to half-open or fall back to a degraded path.\",\n message: (p: {\n /** Name of the circuit breaker */\n circuitName: string;\n /** Current state of the circuit */\n state?: \"OPEN\" | \"HALF_OPEN\";\n /** Time in milliseconds until the circuit may close */\n retryAfterMs?: number;\n }) =>\n `CircuitBreakerOpenError: Circuit ${p.circuitName} is ${p.state ?? \"OPEN\"}${p.retryAfterMs ? `, retry after ${Math.ceil(p.retryAfterMs / 1000)}s` : \"\"}`,\n }\n) {}\n\n/**\n * Error thrown when validation fails.\n *\n * @example\n * ```typescript\n * const error = new ValidationError({\n * field: 'email',\n * reason: 'Invalid email format',\n * });\n * console.log(error.message); // \"ValidationError: Invalid email - Invalid email format\"\n * ```\n */\nexport class ValidationError extends TaggedError(\"ValidationError\", {\n message: (p: {\n /** Field that failed validation */\n field: string;\n /** Reason for validation failure */\n reason: string;\n /** Raw value that failed validation */\n value?: unknown;\n }) => `ValidationError: Invalid ${p.field} - ${p.reason}`,\n}) {}\n\n/**\n * Error thrown when a resource is not found.\n *\n * @example\n * ```typescript\n * const error = new NotFoundError({\n * resource: 'User',\n * id: '123',\n * });\n * console.log(error.message); // \"NotFoundError: User with id 123 not found\"\n * ```\n */\nexport class NotFoundError extends TaggedError(\"NotFoundError\", {\n message: (p: {\n /** Type of resource that was not found */\n resource: string;\n /** Identifier of the missing resource */\n id?: string;\n }) =>\n p.id\n ? `NotFoundError: ${p.resource} with id ${p.id} not found`\n : `NotFoundError: ${p.resource} not found`,\n}) {}\n\n/**\n * Error thrown when access is denied.\n *\n * @example\n * ```typescript\n * const error = new UnauthorizedError({\n * action: 'delete',\n * resource: 'User',\n * });\n * console.log(error.message); // \"UnauthorizedError: Not authorized to delete User\"\n * ```\n */\nexport class UnauthorizedError extends TaggedError(\"UnauthorizedError\", {\n message: (p: {\n /** Action that was attempted */\n action?: string;\n /** Resource that was being accessed */\n resource?: string;\n /** Reason for denial */\n reason?: string;\n }) =>\n p.reason\n ? `UnauthorizedError: ${p.reason}`\n : p.action && p.resource\n ? `UnauthorizedError: Not authorized to ${p.action} ${p.resource}`\n : \"UnauthorizedError: Access denied\",\n}) {}\n\n/**\n * Error thrown for network-related failures.\n *\n * @example\n * ```typescript\n * const error = new NetworkError({\n * url: 'https://api.example.com/users',\n * reason: 'Connection refused',\n * retryable: true,\n * });\n * ```\n */\nexport class NetworkError extends TaggedError(\"NetworkError\", {\n message: (p: {\n /** URL that was being accessed */\n url?: string;\n /** Reason for the network failure */\n reason: string;\n /** Whether this error is retryable */\n retryable?: boolean;\n /** HTTP status code if applicable */\n statusCode?: number;\n }) =>\n p.url\n ? `NetworkError: ${p.reason} (${p.url})`\n : `NetworkError: ${p.reason}`,\n}) {}\n\n/**\n * Error thrown when a saga compensation fails.\n *\n * @example\n * ```typescript\n * const error = new CompensationError({\n * step: 'chargeCard',\n * originalError: paymentError,\n * compensationError: refundError,\n * });\n * ```\n */\nexport class CompensationError extends TaggedError(\"CompensationError\", {\n slug: \"runtime-saga-compensation\",\n hint: \"A saga compensation step failed. Inspect compensationError and ensure compensation is idempotent.\",\n message: (p: {\n /** Step that triggered compensation */\n step: string;\n /** The original error that caused compensation */\n originalError?: unknown;\n /** Error that occurred during compensation */\n compensationError?: unknown;\n }) => `CompensationError: Failed to compensate step ${p.step}`,\n}) {}\n\n// =============================================================================\n// Unexpected Error\n// =============================================================================\n\n/**\n * Default error type for uncaught exceptions and cancellation in workflows.\n * This is the default `U` type when `catchUnexpected` is not provided.\n *\n * @example\n * ```typescript\n * // Automatically used as the default — no need to pass catchUnexpected:\n * const workflow = createWorkflow(\"checkout\", { chargeCard, sendEmail });\n *\n * // Equivalent to:\n * const workflow = createWorkflow(\"checkout\", { chargeCard, sendEmail }, {\n * catchUnexpected: (cause) => new UnexpectedError({ cause }),\n * });\n * ```\n */\nexport class UnexpectedError extends TaggedError(\"UnexpectedError\", {\n slug: \"runtime-unexpected\",\n hint: \"An unexpected exception escaped a step. Inspect cause; consider returning a typed Result instead of throwing.\",\n message: (p: {\n /** The original thrown value or cancellation error */\n cause?: unknown;\n }) => `UnexpectedError: ${p.cause instanceof Error ? p.cause.message : String(p.cause ?? \"unknown\")}`,\n}) {}\n\n// =============================================================================\n// Union Type for Common Errors\n// =============================================================================\n\n/**\n * Union of all pre-built error types.\n * Useful for exhaustive pattern matching.\n *\n * @example\n * ```typescript\n * function handleError(error: AwaitlyError): string {\n * return TaggedError.match(error, {\n * TimeoutError: (e) => `Timeout: ${e.ms}ms`,\n * RetryExhaustedError: (e) => `Retries: ${e.attempts}`,\n * RateLimitError: (e) => `Rate limited`,\n * CircuitBreakerOpenError: (e) => `Circuit open: ${e.circuitName}`,\n * ValidationError: (e) => `Invalid: ${e.field}`,\n * NotFoundError: (e) => `Not found: ${e.resource}`,\n * UnauthorizedError: (e) => `Unauthorized`,\n * NetworkError: (e) => `Network: ${e.reason}`,\n * CompensationError: (e) => `Compensation failed: ${e.step}`,\n * UnexpectedError: (e) => e.message,\n * });\n * }\n * ```\n */\nexport type AwaitlyError =\n | TimeoutError\n | RetryExhaustedError\n | RateLimitError\n | CircuitBreakerOpenError\n | ValidationError\n | NotFoundError\n | UnauthorizedError\n | NetworkError\n | CompensationError\n | UnexpectedError;\n\n/**\n * The six awaitly-system errors that carry slug + hint + docsUrl spine fields.\n *\n * Distinguishes spine-bearing errors from user-domain convenience errors\n * (ValidationError, NotFoundError, UnauthorizedError, NetworkError) so that\n * downstream tooling (lint, analyzer, docs generator) can target the spine\n * roster without duplicating the class list.\n */\nexport type AwaitlySystemError =\n | TimeoutError\n | RetryExhaustedError\n | RateLimitError\n | CircuitBreakerOpenError\n | CompensationError\n | UnexpectedError;\n\n/**\n * Roster of awaitly-system error classes that participate in the slug spine.\n *\n * Adding a new system error means adding it to `AwaitlySystemError`, this\n * roster, and `slugs.ts`. The integrity test in `spine-integrity.test.ts`\n * iterates this roster, so a missing entry there is caught at CI time.\n *\n * @internal Tooling integration point (docs generator, integrity tests). Not\n * a stable user-facing API — application code should not depend on this\n * array's identity or order.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const AWAITLY_SYSTEM_ERROR_CLASSES: ReadonlyArray<new (...args: any[]) => AwaitlySystemError> = [\n TimeoutError,\n RetryExhaustedError,\n RateLimitError,\n CircuitBreakerOpenError,\n CompensationError,\n UnexpectedError,\n];\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Check if an error is a TimeoutError.\n */\nexport function isTimeoutError(error: unknown): error is TimeoutError {\n return TaggedError.isTaggedError(error) && error._tag === \"TimeoutError\";\n}\n\n/**\n * Check if an error is a RetryExhaustedError.\n */\nexport function isRetryExhaustedError(\n error: unknown\n): error is RetryExhaustedError {\n return (\n TaggedError.isTaggedError(error) && error._tag === \"RetryExhaustedError\"\n );\n}\n\n/**\n * Check if an error is a RateLimitError.\n */\nexport function isRateLimitError(error: unknown): error is RateLimitError {\n return TaggedError.isTaggedError(error) && error._tag === \"RateLimitError\";\n}\n\n/**\n * Check if an error is a CircuitBreakerOpenError.\n */\nexport function isCircuitBreakerOpenError(\n error: unknown\n): error is CircuitBreakerOpenError {\n return (\n TaggedError.isTaggedError(error) && error._tag === \"CircuitBreakerOpenError\"\n );\n}\n\n/**\n * Check if an error is a ValidationError.\n */\nexport function isValidationError(error: unknown): error is ValidationError {\n return TaggedError.isTaggedError(error) && error._tag === \"ValidationError\";\n}\n\n/**\n * Check if an error is a NotFoundError.\n */\nexport function isNotFoundError(error: unknown): error is NotFoundError {\n return TaggedError.isTaggedError(error) && error._tag === \"NotFoundError\";\n}\n\n/**\n * Check if an error is an UnauthorizedError.\n */\nexport function isUnauthorizedError(\n error: unknown\n): error is UnauthorizedError {\n return TaggedError.isTaggedError(error) && error._tag === \"UnauthorizedError\";\n}\n\n/**\n * Check if an error is a NetworkError.\n */\nexport function isNetworkError(error: unknown): error is NetworkError {\n return TaggedError.isTaggedError(error) && error._tag === \"NetworkError\";\n}\n\n/**\n * Check if an error is a CompensationError.\n */\nexport function isCompensationError(\n error: unknown\n): error is CompensationError {\n return TaggedError.isTaggedError(error) && error._tag === \"CompensationError\";\n}\n\n/**\n * Check if an error is any AwaitlyError.\n */\nexport function isAwaitlyError(error: unknown): error is AwaitlyError {\n if (!TaggedError.isTaggedError(error)) return false;\n const tag = error._tag;\n return [\n \"TimeoutError\",\n \"RetryExhaustedError\",\n \"RateLimitError\",\n \"CircuitBreakerOpenError\",\n \"ValidationError\",\n \"NotFoundError\",\n \"UnauthorizedError\",\n \"NetworkError\",\n \"CompensationError\",\n \"UnexpectedError\",\n ].includes(tag);\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,EAAA,4BAAAC,EAAA,sBAAAC,EAAA,iBAAAC,EAAA,kBAAAC,EAAA,mBAAAC,EAAA,wBAAAC,EAAA,iBAAAC,EAAA,sBAAAC,EAAA,oBAAAC,EAAA,oBAAAC,EAAA,mBAAAC,EAAA,8BAAAC,EAAA,wBAAAC,EAAA,mBAAAC,EAAA,oBAAAC,EAAA,qBAAAC,EAAA,0BAAAC,EAAA,mBAAAC,EAAA,wBAAAC,EAAA,sBAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAxB,GCkBO,IAAMyB,EAAgB,CAE3B,kBAAmB,kBACnB,8BAA+B,8BAC/B,6BAA8B,6BAC9B,qBAAsB,qBACtB,yBAA0B,yBAC1B,yBAA0B,yBAG1B,uBAAwB,uBACxB,4BAA6B,4BAC7B,0BAA2B,0BAC3B,4BAA6B,4BAC7B,6BAA8B,6BAG9B,qBAAsB,qBACtB,0BAA2B,0BAC3B,wBAAyB,wBACzB,+BAAgC,+BAChC,0BAA2B,0BAG3B,+BAAgC,+BAChC,qBAAsB,qBACtB,kBAAmB,kBACnB,yBAA0B,yBAG1B,6BAA8B,6BAC9B,8BAA+B,8BAC/B,oCAA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S,iBAC5D,CAKO,SAASK,EAAgBL,EAAwC,CACtE,OAAOf,EAAY,cAAce,CAAK,GAAKA,EAAM,OAAS,eAC5D,CAKO,SAASM,EACdN,EAC4B,CAC5B,OAAOf,EAAY,cAAce,CAAK,GAAKA,EAAM,OAAS,mBAC5D,CAKO,SAASO,EAAeP,EAAuC,CACpE,OAAOf,EAAY,cAAce,CAAK,GAAKA,EAAM,OAAS,cAC5D,CAKO,SAASQ,EACdR,EAC4B,CAC5B,OAAOf,EAAY,cAAce,CAAK,GAAKA,EAAM,OAAS,mBAC5D,CAKO,SAASS,EAAeT,EAAuC,CACpE,GAAI,CAACf,EAAY,cAAce,CAAK,EAAG,MAAO,GAC9C,IAAMpB,EAAMoB,EAAM,KAClB,MAAO,CACL,eACA,sBACA,iBACA,0BACA,kBACA,gBACA,oBACA,eACA,oBACA,iBACF,EAAE,SAASpB,CAAG,CAChB","names":["errors_entry_exports","__export","AWAITLY_SYSTEM_ERROR_CLASSES","CircuitBreakerOpenError","CompensationError","NetworkError","NotFoundError","RateLimitError","RetryExhaustedError","TimeoutError","UnauthorizedError","UnexpectedError","ValidationError","isAwaitlyError","isCircuitBreakerOpenError","isCompensationError","isNetworkError","isNotFoundError","isRateLimitError","isRetryExhaustedError","isTimeoutError","isUnauthorizedError","isValidationError","makeError","__toCommonJS","AWAITLY_SLUGS","slugDocsUrl","slug","ALL_SLUGS","AWAITLY_SLUGS","InternalTaggedErrorBase","TaggedError","tag","options","props","errorOptions","message","slugDocsUrl","safeProps","_","_n","_m","_s","_c","_h","_d","rest","hasUserCause","userCause","hasOptionsCause","instance","isError","value","isTaggedError","match","error","handlers","handler","matchPartial","otherwise","makeError","tag","options","messageGenerator","defaults","BaseClass","TaggedError","props","TimeoutError","p","RetryExhaustedError","RateLimitError","CircuitBreakerOpenError","ValidationError","NotFoundError","UnauthorizedError","NetworkError","CompensationError","UnexpectedError","AWAITLY_SYSTEM_ERROR_CLASSES","isTimeoutError","error","isRetryExhaustedError","isRateLimitError","isCircuitBreakerOpenError","isValidationError","isNotFoundError","isUnauthorizedError","isNetworkError","isCompensationError","isAwaitlyError"]}
package/dist/errors.d.cts DELETED
@@ -1,361 +0,0 @@
1
- import { TaggedErrorConstructor } from './tagged-error.cjs';
2
- import { AwaitlySlug } from './slugs.cjs';
3
-
4
- /**
5
- * awaitly/errors
6
- *
7
- * Pre-built error types for common failure scenarios.
8
- * Uses TaggedError for type-safe exhaustive matching.
9
- *
10
- * @example
11
- * ```typescript
12
- * import { TimeoutError, RetryExhaustedError, RateLimitError, CircuitBreakerOpenError } from 'awaitly/errors';
13
- *
14
- * // Create errors
15
- * const timeout = new TimeoutError({ operation: 'fetchUser', ms: 5000 });
16
- * const retryFailed = new RetryExhaustedError({ operation: 'sendEmail', attempts: 3 });
17
- *
18
- * // Pattern match
19
- * TaggedError.match(error, {
20
- * TimeoutError: (e) => `${e.operation} timed out after ${e.ms}ms`,
21
- * RetryExhaustedError: (e) => `${e.operation} failed after ${e.attempts} attempts`,
22
- * RateLimitError: (e) => `Rate limit exceeded, retry after ${e.retryAfterMs}ms`,
23
- * CircuitBreakerOpenError: (e) => `Circuit ${e.circuitName} is open`,
24
- * });
25
- * ```
26
- */
27
- /**
28
- * Factory function to create tagged error classes with default values.
29
- *
30
- * This is a convenience wrapper around TaggedError that allows specifying
31
- * default property values for error types.
32
- *
33
- * @example
34
- * ```typescript
35
- * const NetworkError = makeError('NetworkError', {
36
- * defaults: { retryable: true },
37
- * message: (p) => `Network error: ${p.reason}`,
38
- * });
39
- *
40
- * class MyNetworkError extends NetworkError<{ reason: string; code?: number }> {}
41
- * ```
42
- */
43
- declare function makeError<Tag extends string>(tag: Tag, options?: {
44
- message?: (props: Record<string, unknown>) => string;
45
- defaults?: Record<string, unknown>;
46
- }): {
47
- new (props?: Record<string, unknown>): {
48
- readonly [x: string]: unknown;
49
- readonly _tag: Tag;
50
- readonly code?: AwaitlySlug;
51
- readonly hint?: string;
52
- readonly docsUrl?: string;
53
- name: string;
54
- message: string;
55
- stack?: string;
56
- cause?: unknown;
57
- };
58
- };
59
- declare const TimeoutError_base: TaggedErrorConstructor<"TimeoutError", {
60
- /** Name of the operation that timed out */
61
- operation?: string;
62
- /** Timeout duration in milliseconds */
63
- ms: number;
64
- }>;
65
- /**
66
- * Error thrown when an operation times out.
67
- *
68
- * @example
69
- * ```typescript
70
- * const error = new TimeoutError({
71
- * operation: 'fetchUser',
72
- * ms: 5000,
73
- * });
74
- * console.log(error.message); // "TimeoutError: fetchUser timed out after 5000ms"
75
- * ```
76
- */
77
- declare class TimeoutError extends TimeoutError_base {
78
- }
79
- declare const RetryExhaustedError_base: TaggedErrorConstructor<"RetryExhaustedError", {
80
- /** Name of the operation that failed */
81
- operation?: string;
82
- /** Total number of retry attempts made */
83
- attempts: number;
84
- /** The last error encountered before giving up */
85
- lastError?: unknown;
86
- }>;
87
- /**
88
- * Error thrown when all retry attempts are exhausted.
89
- *
90
- * @example
91
- * ```typescript
92
- * const error = new RetryExhaustedError({
93
- * operation: 'sendEmail',
94
- * attempts: 3,
95
- * lastError: originalError,
96
- * });
97
- * console.log(error.message); // "RetryExhaustedError: sendEmail failed after 3 attempts"
98
- * ```
99
- */
100
- declare class RetryExhaustedError extends RetryExhaustedError_base {
101
- }
102
- declare const RateLimitError_base: TaggedErrorConstructor<"RateLimitError", {
103
- /** Name of the rate limiter that was exceeded */
104
- limiterName?: string;
105
- /** Time in milliseconds until the rate limit resets */
106
- retryAfterMs?: number;
107
- }>;
108
- /**
109
- * Error thrown when a rate limit is exceeded.
110
- *
111
- * @example
112
- * ```typescript
113
- * const error = new RateLimitError({
114
- * limiterName: 'api-calls',
115
- * retryAfterMs: 1000,
116
- * });
117
- * console.log(error.message); // "RateLimitError: Rate limit exceeded for api-calls"
118
- * ```
119
- */
120
- declare class RateLimitError extends RateLimitError_base {
121
- }
122
- declare const CircuitBreakerOpenError_base: TaggedErrorConstructor<"CircuitBreakerOpenError", {
123
- /** Name of the circuit breaker */
124
- circuitName: string;
125
- /** Current state of the circuit */
126
- state?: "OPEN" | "HALF_OPEN";
127
- /** Time in milliseconds until the circuit may close */
128
- retryAfterMs?: number;
129
- }>;
130
- /**
131
- * Error thrown when a circuit breaker is open.
132
- *
133
- * @example
134
- * ```typescript
135
- * const error = new CircuitBreakerOpenError({
136
- * circuitName: 'payment-api',
137
- * state: 'OPEN',
138
- * retryAfterMs: 30000,
139
- * });
140
- * console.log(error.message); // "CircuitBreakerOpenError: Circuit payment-api is OPEN"
141
- * ```
142
- */
143
- declare class CircuitBreakerOpenError extends CircuitBreakerOpenError_base {
144
- }
145
- declare const ValidationError_base: TaggedErrorConstructor<"ValidationError", {
146
- /** Field that failed validation */
147
- field: string;
148
- /** Reason for validation failure */
149
- reason: string;
150
- /** Raw value that failed validation */
151
- value?: unknown;
152
- }>;
153
- /**
154
- * Error thrown when validation fails.
155
- *
156
- * @example
157
- * ```typescript
158
- * const error = new ValidationError({
159
- * field: 'email',
160
- * reason: 'Invalid email format',
161
- * });
162
- * console.log(error.message); // "ValidationError: Invalid email - Invalid email format"
163
- * ```
164
- */
165
- declare class ValidationError extends ValidationError_base {
166
- }
167
- declare const NotFoundError_base: TaggedErrorConstructor<"NotFoundError", {
168
- /** Type of resource that was not found */
169
- resource: string;
170
- /** Identifier of the missing resource */
171
- id?: string;
172
- }>;
173
- /**
174
- * Error thrown when a resource is not found.
175
- *
176
- * @example
177
- * ```typescript
178
- * const error = new NotFoundError({
179
- * resource: 'User',
180
- * id: '123',
181
- * });
182
- * console.log(error.message); // "NotFoundError: User with id 123 not found"
183
- * ```
184
- */
185
- declare class NotFoundError extends NotFoundError_base {
186
- }
187
- declare const UnauthorizedError_base: TaggedErrorConstructor<"UnauthorizedError", {
188
- /** Action that was attempted */
189
- action?: string;
190
- /** Resource that was being accessed */
191
- resource?: string;
192
- /** Reason for denial */
193
- reason?: string;
194
- }>;
195
- /**
196
- * Error thrown when access is denied.
197
- *
198
- * @example
199
- * ```typescript
200
- * const error = new UnauthorizedError({
201
- * action: 'delete',
202
- * resource: 'User',
203
- * });
204
- * console.log(error.message); // "UnauthorizedError: Not authorized to delete User"
205
- * ```
206
- */
207
- declare class UnauthorizedError extends UnauthorizedError_base {
208
- }
209
- declare const NetworkError_base: TaggedErrorConstructor<"NetworkError", {
210
- /** URL that was being accessed */
211
- url?: string;
212
- /** Reason for the network failure */
213
- reason: string;
214
- /** Whether this error is retryable */
215
- retryable?: boolean;
216
- /** HTTP status code if applicable */
217
- statusCode?: number;
218
- }>;
219
- /**
220
- * Error thrown for network-related failures.
221
- *
222
- * @example
223
- * ```typescript
224
- * const error = new NetworkError({
225
- * url: 'https://api.example.com/users',
226
- * reason: 'Connection refused',
227
- * retryable: true,
228
- * });
229
- * ```
230
- */
231
- declare class NetworkError extends NetworkError_base {
232
- }
233
- declare const CompensationError_base: TaggedErrorConstructor<"CompensationError", {
234
- /** Step that triggered compensation */
235
- step: string;
236
- /** The original error that caused compensation */
237
- originalError?: unknown;
238
- /** Error that occurred during compensation */
239
- compensationError?: unknown;
240
- }>;
241
- /**
242
- * Error thrown when a saga compensation fails.
243
- *
244
- * @example
245
- * ```typescript
246
- * const error = new CompensationError({
247
- * step: 'chargeCard',
248
- * originalError: paymentError,
249
- * compensationError: refundError,
250
- * });
251
- * ```
252
- */
253
- declare class CompensationError extends CompensationError_base {
254
- }
255
- declare const UnexpectedError_base: TaggedErrorConstructor<"UnexpectedError", {
256
- /** The original thrown value or cancellation error */
257
- cause?: unknown;
258
- }>;
259
- /**
260
- * Default error type for uncaught exceptions and cancellation in workflows.
261
- * This is the default `U` type when `catchUnexpected` is not provided.
262
- *
263
- * @example
264
- * ```typescript
265
- * // Automatically used as the default — no need to pass catchUnexpected:
266
- * const workflow = createWorkflow("checkout", { chargeCard, sendEmail });
267
- *
268
- * // Equivalent to:
269
- * const workflow = createWorkflow("checkout", { chargeCard, sendEmail }, {
270
- * catchUnexpected: (cause) => new UnexpectedError({ cause }),
271
- * });
272
- * ```
273
- */
274
- declare class UnexpectedError extends UnexpectedError_base {
275
- }
276
- /**
277
- * Union of all pre-built error types.
278
- * Useful for exhaustive pattern matching.
279
- *
280
- * @example
281
- * ```typescript
282
- * function handleError(error: AwaitlyError): string {
283
- * return TaggedError.match(error, {
284
- * TimeoutError: (e) => `Timeout: ${e.ms}ms`,
285
- * RetryExhaustedError: (e) => `Retries: ${e.attempts}`,
286
- * RateLimitError: (e) => `Rate limited`,
287
- * CircuitBreakerOpenError: (e) => `Circuit open: ${e.circuitName}`,
288
- * ValidationError: (e) => `Invalid: ${e.field}`,
289
- * NotFoundError: (e) => `Not found: ${e.resource}`,
290
- * UnauthorizedError: (e) => `Unauthorized`,
291
- * NetworkError: (e) => `Network: ${e.reason}`,
292
- * CompensationError: (e) => `Compensation failed: ${e.step}`,
293
- * UnexpectedError: (e) => e.message,
294
- * });
295
- * }
296
- * ```
297
- */
298
- type AwaitlyError = TimeoutError | RetryExhaustedError | RateLimitError | CircuitBreakerOpenError | ValidationError | NotFoundError | UnauthorizedError | NetworkError | CompensationError | UnexpectedError;
299
- /**
300
- * The six awaitly-system errors that carry slug + hint + docsUrl spine fields.
301
- *
302
- * Distinguishes spine-bearing errors from user-domain convenience errors
303
- * (ValidationError, NotFoundError, UnauthorizedError, NetworkError) so that
304
- * downstream tooling (lint, analyzer, docs generator) can target the spine
305
- * roster without duplicating the class list.
306
- */
307
- type AwaitlySystemError = TimeoutError | RetryExhaustedError | RateLimitError | CircuitBreakerOpenError | CompensationError | UnexpectedError;
308
- /**
309
- * Roster of awaitly-system error classes that participate in the slug spine.
310
- *
311
- * Adding a new system error means adding it to `AwaitlySystemError`, this
312
- * roster, and `slugs.ts`. The integrity test in `spine-integrity.test.ts`
313
- * iterates this roster, so a missing entry there is caught at CI time.
314
- *
315
- * @internal Tooling integration point (docs generator, integrity tests). Not
316
- * a stable user-facing API — application code should not depend on this
317
- * array's identity or order.
318
- */
319
- declare const AWAITLY_SYSTEM_ERROR_CLASSES: ReadonlyArray<new (...args: any[]) => AwaitlySystemError>;
320
- /**
321
- * Check if an error is a TimeoutError.
322
- */
323
- declare function isTimeoutError(error: unknown): error is TimeoutError;
324
- /**
325
- * Check if an error is a RetryExhaustedError.
326
- */
327
- declare function isRetryExhaustedError(error: unknown): error is RetryExhaustedError;
328
- /**
329
- * Check if an error is a RateLimitError.
330
- */
331
- declare function isRateLimitError(error: unknown): error is RateLimitError;
332
- /**
333
- * Check if an error is a CircuitBreakerOpenError.
334
- */
335
- declare function isCircuitBreakerOpenError(error: unknown): error is CircuitBreakerOpenError;
336
- /**
337
- * Check if an error is a ValidationError.
338
- */
339
- declare function isValidationError(error: unknown): error is ValidationError;
340
- /**
341
- * Check if an error is a NotFoundError.
342
- */
343
- declare function isNotFoundError(error: unknown): error is NotFoundError;
344
- /**
345
- * Check if an error is an UnauthorizedError.
346
- */
347
- declare function isUnauthorizedError(error: unknown): error is UnauthorizedError;
348
- /**
349
- * Check if an error is a NetworkError.
350
- */
351
- declare function isNetworkError(error: unknown): error is NetworkError;
352
- /**
353
- * Check if an error is a CompensationError.
354
- */
355
- declare function isCompensationError(error: unknown): error is CompensationError;
356
- /**
357
- * Check if an error is any AwaitlyError.
358
- */
359
- declare function isAwaitlyError(error: unknown): error is AwaitlyError;
360
-
361
- export { AWAITLY_SYSTEM_ERROR_CLASSES, type AwaitlyError, type AwaitlySystemError, CircuitBreakerOpenError, CompensationError, NetworkError, NotFoundError, RateLimitError, RetryExhaustedError, TimeoutError, UnauthorizedError, UnexpectedError, ValidationError, isAwaitlyError, isCircuitBreakerOpenError, isCompensationError, isNetworkError, isNotFoundError, isRateLimitError, isRetryExhaustedError, isTimeoutError, isUnauthorizedError, isValidationError, makeError };