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/result.js CHANGED
@@ -1,2 +1,562 @@
1
- var j={"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 w(e){return`https://jagreehal.github.io/awaitly/rules/#${e}`}var M=Object.keys(j);var p=class extends Error{_tag};function c(e,r){return class extends p{_tag=e;constructor(n,t){let u=r?.message?r.message(n??{}):e;if(super(u),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:w(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:T,name:b,message:S,stack:K,code:y,hint:H,docsUrl:L,...I}=n;o=I}else{let{_tag:T,name:b,message:S,stack:K,...y}=n;o=y}let a=Object.prototype.hasOwnProperty.call(o,"cause"),E=a?o.cause:void 0;a&&delete o.cause;let l=t?.cause!==void 0;if(a&&l)throw new TypeError("TaggedError: cannot provide 'cause' in props when also setting ErrorOptions.cause");Object.assign(this,o),a&&(this.cause=E),l&&(this.cause=t?.cause)}else t?.cause!==void 0&&(this.cause=t.cause)}}}Object.defineProperty(c,Symbol.hasInstance,{value:e=>e instanceof p});(u=>{function e(o){return o instanceof Error}u.isError=e;function r(o){return o instanceof p}u.isTaggedError=r;function n(o,a){let E=o._tag,l=a[E];return l(o)}u.match=n;function t(o,a,E){let l=o._tag,T=a[l];return T?T(o):E(o)}u.matchPartial=t})(c||={});var x=class extends c("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`}){},m=class extends c("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`}){},R=class extends c("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`:""}`}){},C=class extends c("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`:""}`}){},h=class extends c("ValidationError",{message:r=>`ValidationError: Invalid ${r.field} - ${r.reason}`}){},A=class extends c("NotFoundError",{message:r=>r.id?`NotFoundError: ${r.resource} with id ${r.id} not found`:`NotFoundError: ${r.resource} not found`}){},P=class extends c("UnauthorizedError",{message:r=>r.reason?`UnauthorizedError: ${r.reason}`:r.action&&r.resource?`UnauthorizedError: Not authorized to ${r.action} ${r.resource}`:"UnauthorizedError: Access denied"}){},O=class extends c("NetworkError",{message:r=>r.url?`NetworkError: ${r.reason} (${r.url})`:`NetworkError: ${r.reason}`}){},v=class extends c("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}`}){},f=class extends c("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")}`}){};var d="PROMISE_REJECTED",q="AWAITLY_UNEXPECTED",J="AWAITLY_CANCELLED",G="AWAITLY_TIMEOUT",Z=(...e)=>e;function i(e){return{ok:!0,value:e}}function s(e,r){let n=r?.cause;return{ok:!1,error:e,...n!==void 0?{cause:n}:{}}}var Q=e=>e.ok,ee=e=>!e.ok,U=e=>e instanceof f||typeof e=="object"&&e!==null&&"_tag"in e&&e._tag==="UnexpectedError",re=e=>typeof e=="object"&&e!==null&&"type"in e&&e.type===d;function F(e,r){if(r===void 0){let t=e;return u=>F(u,t)}let n=e;return U(n)?r.UnexpectedError(n):r[n](n)}var g=class extends Error{error;cause;constructor(r){let n=typeof r.error=="string"?r.error:JSON.stringify(r.error);super(`Attempted to unwrap an Err: ${n}`),this.name="UnwrapError",this.error=r.error,this.cause=r.cause}},_=e=>{if(e.ok)return e.value;throw new g(e)},ne=(e,r)=>e.ok?e.value:r,te=(e,r)=>e.ok?e.value:r(e.error,e.cause),oe=e=>_(e),se=e=>Promise.resolve(e).then(_),ue=e=>e.ok?e.value:null,ae=e=>e.ok?e.value:void 0;function ie(e,r){try{return i(e())}catch(n){return r?s(r(n),{cause:n}):s(n)}}async function ce(e,r){try{return i(await e)}catch(n){return r?s(r(n),{cause:n}):s(n)}}async function le(e,r){try{return i(await e())}catch(n){return r?s(r(n),{cause:n}):s(n)}}function Ee(e,r){return e!=null?i(e):s(r())}function pe(e,r){return e.ok?i(r(e.value)):e}function de(e,r){return e.ok?e:s(r(e.error,e.cause),{cause:e.cause})}function N(e,r){if(r===void 0){let n=e;return t=>N(t,n)}return e.ok?r.ok(e.value):r.err(e.error,e.cause)}function Te(e,r){return e.ok?r(e.value):e}function fe(e,r){return e.ok&&r(e.value),e}function ke(e,r){return e.ok||r(e.error,e.cause),e}function ge(e,r,n){if(!e.ok)return e;try{return i(r(e.value))}catch(t){return s(n(t),{cause:t})}}function ye(e,r,n){if(e.ok)return e;try{return s(r(e.error),{cause:e.cause})}catch(t){return s(n(t),{cause:t})}}function we(e,r,n){return e.ok?i(r(e.value)):s(n(e.error,e.cause),{cause:e.cause})}function xe(e,r){return e.ok?e:r(e.error,e.cause)}async function me(e,r){return e.ok?e:r(e.error,e.cause)}function Re(e,r){return e.ok?i(e.value):i(r(e.error,e.cause))}async function Ce(e,r){let n=await e;return n.ok?i(n.value):i(await r(n.error,n.cause))}function he(e){if(typeof e!="object"||e===null||!("ok"in e))return null;let r=e;return r.ok===!0&&"value"in r?i(r.value):r.ok===!1&&"error"in r?s(r.error,{cause:r.cause}):null}function Ae(e){if(typeof e!="object"||e===null||!("ok"in e))return!1;let r=e;return r.ok===!0&&"value"in r||r.ok===!1&&"error"in r}function Pe(e){let r=[];for(let n of e){if(!n.ok)return n;r.push(n.value)}return i(r)}async function Oe(e){let r=[];for(let n of e)try{let t=await n;if(!t.ok)return t;r.push(t.value)}catch(t){return s({type:d,cause:t},{cause:{type:"PROMISE_REJECTION",reason:t}})}return i(r)}function ve(e){let r=[],n=[];for(let t of e)t.ok?r.push(t.value):n.push({error:t.error,cause:t.cause});return n.length>0?s(n):i(r)}async function Ue(e){let r=await Promise.all(e.map(u=>Promise.resolve(u).then(o=>({status:"result",result:o})).catch(o=>({status:"rejected",error:{type:d,cause:o},cause:{type:"PROMISE_REJECTION",reason:o}})))),n=[],t=[];for(let u of r)u.status==="rejected"?t.push({error:u.error,cause:u.cause}):u.result.ok?n.push(u.result.value):t.push({error:u.result.error,cause:u.result.cause});return t.length>0?s(t):i(n)}function _e(e){let r=[],n=[];for(let t of e)t.ok?r.push(t.value):n.push(t.error);return{values:r,errors:n}}function be(e){if(e.length===0)return s({type:"EMPTY_INPUT",message:"any() requires at least one Result"});let r;for(let n of e){if(n.ok)return n;r||(r=n)}return r}async function Se(e){return e.length===0?s({type:"EMPTY_INPUT",message:"anyAsync() requires at least one Result"}):new Promise(r=>{let n=!1,t=e.length,u=null;for(let o of e)Promise.resolve(o).catch(a=>s({type:d,cause:a},{cause:{type:"PROMISE_REJECTION",reason:a}})).then(a=>{if(!n){if(a.ok){n=!0,r(a);return}u||(u=a),t--,t===0&&r(u)}})})}function B(e,r){return e.ok?r.ok?i([e.value,r.value]):r:e}async function Ke(e,r){let n=o=>Promise.resolve(o).catch(a=>s({type:d,cause:a},{cause:{type:"PROMISE_REJECTION",reason:a}})),[t,u]=await Promise.all([n(e),n(r)]);return B(t,u)}function Ie(e){return e.ok?e.value:e}var k="DESERIALIZATION_ERROR";function je(e){if(typeof e!="object"||e===null)return s({type:k,value:e});if(!("ok"in e))return s({type:k,value:e});let r=e;return r.ok===!0&&"value"in r?i(r.value):r.ok===!1&&"error"in r?s(r.error,{cause:r.cause}):s({type:k,value:e})}function Fe(e){return e.ok?{ok:!0,value:e.value}:{ok:!1,error:e.error}}function Ne(e,r,n){if(U(e)){let u=r.UnexpectedError;return u?u(e):n(e)}let t=r[e];return t?t(e):n(e)}export{J as AWAITLY_CANCELLED,G as AWAITLY_TIMEOUT,q as AWAITLY_UNEXPECTED,k as DESERIALIZATION_ERROR,d as PROMISE_REJECTED,f as UnexpectedError,g as UnwrapError,Pe as all,Oe as allAsync,ve as allSettled,Ue as allSettledAsync,Te as andThen,be as any,Se as anyAsync,we as bimap,je as deserialize,s as err,Ie as flatten,ie as from,Ee as fromNullable,ce as fromPromise,he as hydrate,ee as isErr,Q as isOk,re as isPromiseRejectedError,Ae as isSerializedResult,U as isUnexpectedError,pe as map,de as mapError,ye as mapErrorTry,ge as mapTry,N as match,F as matchError,Ne as matchErrorPartial,i as ok,xe as orElse,me as orElseAsync,_e as partition,Re as recover,Ce as recoverAsync,ue as runOrNull,oe as runOrThrow,se as runOrThrowAsync,ae as runOrUndefined,Fe as serialize,Z as tags,fe as tap,ke as tapError,le as tryAsync,_ as unwrap,ne as unwrapOr,te as unwrapOrElse,B as zip,Ke as zipAsync};
1
+ // src/slugs.ts
2
+ var AWAITLY_SLUGS = {
3
+ // --- step-* ---
4
+ "step-require-id": "step-require-id",
5
+ "step-no-immediate-execution": "step-no-immediate-execution",
6
+ "step-require-thunk-for-key": "step-require-thunk-for-key",
7
+ "step-no-bare-await": "step-no-bare-await",
8
+ "step-no-try-catch-wrap": "step-no-try-catch-wrap",
9
+ "step-stable-cache-keys": "step-stable-cache-keys",
10
+ // --- workflow-* ---
11
+ "workflow-no-floating": "workflow-no-floating",
12
+ "workflow-options-position": "workflow-options-position",
13
+ "workflow-callback-shape": "workflow-callback-shape",
14
+ "workflow-no-callable-form": "workflow-no-callable-form",
15
+ "workflow-no-dynamic-import": "workflow-no-dynamic-import",
16
+ "workflow-prefer-step-if": "workflow-prefer-step-if",
17
+ "workflow-prefer-step-foreach": "workflow-prefer-step-foreach",
18
+ // --- result-* ---
19
+ "result-no-floating": "result-no-floating",
20
+ "result-require-handling": "result-require-handling",
21
+ "result-no-double-wrap": "result-no-double-wrap",
22
+ "result-no-manual-propagation": "result-no-manual-propagation",
23
+ "result-no-direct-ok-err": "result-no-direct-ok-err",
24
+ // --- error-* ---
25
+ "error-check-unexpected-first": "error-check-unexpected-first",
26
+ "error-access-cause": "error-access-cause",
27
+ "error-normalize": "error-normalize",
28
+ "error-no-throw-in-deps": "error-no-throw-in-deps",
29
+ // --- concurrency-* ---
30
+ "concurrency-no-promise-all": "concurrency-no-promise-all",
31
+ "concurrency-no-promise-race": "concurrency-no-promise-race",
32
+ "concurrency-no-promise-allsettled": "concurrency-no-promise-allsettled",
33
+ // --- runtime-* ---
34
+ "runtime-step-timeout": "runtime-step-timeout",
35
+ "runtime-step-aborted": "runtime-step-aborted",
36
+ "runtime-retry-exhausted": "runtime-retry-exhausted",
37
+ "runtime-rate-limit": "runtime-rate-limit",
38
+ "runtime-circuit-open": "runtime-circuit-open",
39
+ "runtime-unexpected": "runtime-unexpected",
40
+ "runtime-resolver-not-found": "runtime-resolver-not-found",
41
+ "runtime-saga-compensation": "runtime-saga-compensation"
42
+ };
43
+ function slugDocsUrl(slug) {
44
+ return `https://jagreehal.github.io/awaitly/rules/#${slug}`;
45
+ }
46
+ var ALL_SLUGS = Object.keys(
47
+ AWAITLY_SLUGS
48
+ );
49
+
50
+ // src/tagged-error.ts
51
+ var InternalTaggedErrorBase = class extends Error {
52
+ type;
53
+ /** @deprecated Use `type`. */
54
+ _tag;
55
+ };
56
+ function TaggedError(tag, options) {
57
+ return class extends InternalTaggedErrorBase {
58
+ type = tag;
59
+ /** @deprecated Use `type`. */
60
+ _tag = tag;
61
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
+ constructor(props, errorOptions) {
63
+ const message = options?.message ? options.message(props ?? {}) : tag;
64
+ super(message);
65
+ this.name = tag;
66
+ if (options?.slug !== void 0) {
67
+ if (!options.hint) {
68
+ throw new TypeError(
69
+ `TaggedError: 'hint' is required when 'slug' is set (slug: "${options.slug}")`
70
+ );
71
+ }
72
+ Object.defineProperty(this, "code", {
73
+ value: options.slug,
74
+ enumerable: true,
75
+ writable: false,
76
+ configurable: false
77
+ });
78
+ Object.defineProperty(this, "hint", {
79
+ value: options.hint,
80
+ enumerable: true,
81
+ writable: false,
82
+ configurable: false
83
+ });
84
+ Object.defineProperty(this, "docsUrl", {
85
+ value: slugDocsUrl(options.slug),
86
+ enumerable: true,
87
+ writable: false,
88
+ configurable: false
89
+ });
90
+ }
91
+ Object.setPrototypeOf(this, new.target.prototype);
92
+ if (props && typeof props === "object") {
93
+ let safeProps;
94
+ if (options?.slug !== void 0) {
95
+ const {
96
+ _tag: _,
97
+ type: _t,
98
+ name: _n,
99
+ message: _m,
100
+ stack: _s,
101
+ code: _c,
102
+ hint: _h,
103
+ docsUrl: _d,
104
+ ...rest
105
+ } = props;
106
+ safeProps = rest;
107
+ } else {
108
+ const {
109
+ _tag: _,
110
+ type: _t,
111
+ name: _n,
112
+ message: _m,
113
+ stack: _s,
114
+ ...rest
115
+ } = props;
116
+ safeProps = rest;
117
+ }
118
+ const hasUserCause = Object.prototype.hasOwnProperty.call(
119
+ safeProps,
120
+ "cause"
121
+ );
122
+ const userCause = hasUserCause ? safeProps.cause : void 0;
123
+ if (hasUserCause) {
124
+ delete safeProps.cause;
125
+ }
126
+ const hasOptionsCause = errorOptions?.cause !== void 0;
127
+ if (hasUserCause && hasOptionsCause) {
128
+ throw new TypeError(
129
+ "TaggedError: cannot provide 'cause' in props when also setting ErrorOptions.cause"
130
+ );
131
+ }
132
+ Object.assign(this, safeProps);
133
+ if (hasUserCause) {
134
+ this.cause = userCause;
135
+ }
136
+ if (hasOptionsCause) {
137
+ this.cause = errorOptions?.cause;
138
+ }
139
+ } else if (errorOptions?.cause !== void 0) {
140
+ this.cause = errorOptions.cause;
141
+ }
142
+ }
143
+ };
144
+ }
145
+ Object.defineProperty(TaggedError, Symbol.hasInstance, {
146
+ value: (instance) => instance instanceof InternalTaggedErrorBase
147
+ });
148
+ ((TaggedError2) => {
149
+ function isError(value) {
150
+ return value instanceof Error;
151
+ }
152
+ TaggedError2.isError = isError;
153
+ function isTaggedError(value) {
154
+ return value instanceof InternalTaggedErrorBase;
155
+ }
156
+ TaggedError2.isTaggedError = isTaggedError;
157
+ function match2(error, handlers) {
158
+ const tag = error._tag;
159
+ const handler = handlers[tag];
160
+ return handler(
161
+ error
162
+ );
163
+ }
164
+ TaggedError2.match = match2;
165
+ function matchPartial(error, handlers, otherwise) {
166
+ const tag = error._tag;
167
+ const handler = handlers[tag];
168
+ if (handler) {
169
+ return handler(
170
+ error
171
+ );
172
+ }
173
+ return otherwise(error);
174
+ }
175
+ TaggedError2.matchPartial = matchPartial;
176
+ })(TaggedError || (TaggedError = {}));
177
+
178
+ // src/errors.ts
179
+ var UnexpectedError = class extends (/* @__PURE__ */ TaggedError("UnexpectedError", {
180
+ slug: "runtime-unexpected",
181
+ hint: "An unexpected exception escaped a step. Inspect cause; consider returning a typed Result instead of throwing.",
182
+ message: (p) => `UnexpectedError: ${p.cause instanceof Error ? p.cause.message : String(p.cause ?? "unknown")}`
183
+ })) {
184
+ };
185
+
186
+ // src/result/index.ts
187
+ var PROMISE_REJECTED = "PROMISE_REJECTED";
188
+ var AWAITLY_UNEXPECTED = "AWAITLY_UNEXPECTED";
189
+ var AWAITLY_CANCELLED = "AWAITLY_CANCELLED";
190
+ var AWAITLY_TIMEOUT = "AWAITLY_TIMEOUT";
191
+ var tags = (...t) => t;
192
+ function ok(value) {
193
+ return { ok: true, value };
194
+ }
195
+ function err(error, options) {
196
+ const cause = options?.cause;
197
+ return { ok: false, error, ...cause !== void 0 ? { cause } : {} };
198
+ }
199
+ var isOk = (r) => r.ok;
200
+ var isErr = (r) => !r.ok;
201
+ var isUnexpectedError = (e) => e instanceof UnexpectedError || typeof e === "object" && e !== null && "_tag" in e && e._tag === "UnexpectedError";
202
+ var isPromiseRejectedError = (e) => typeof e === "object" && e !== null && "type" in e && e.type === PROMISE_REJECTED;
203
+ function matchError(errorOrHandlers, handlers) {
204
+ if (handlers === void 0) {
205
+ const h = errorOrHandlers;
206
+ return (e) => matchError(e, h);
207
+ }
208
+ const error = errorOrHandlers;
209
+ if (isUnexpectedError(error)) {
210
+ return handlers.UnexpectedError(error);
211
+ }
212
+ return handlers[error](error);
213
+ }
214
+ var UnwrapError = class extends Error {
215
+ error;
216
+ cause;
217
+ constructor(result) {
218
+ const errorStr = typeof result.error === "string" ? result.error : JSON.stringify(result.error);
219
+ super(`Attempted to unwrap an Err: ${errorStr}`);
220
+ this.name = "UnwrapError";
221
+ this.error = result.error;
222
+ this.cause = result.cause;
223
+ }
224
+ };
225
+ var unwrap = (r) => {
226
+ if (r.ok) return r.value;
227
+ throw new UnwrapError(r);
228
+ };
229
+ var unwrapOr = (r, defaultValue) => r.ok ? r.value : defaultValue;
230
+ var unwrapOrElse = (r, fn) => r.ok ? r.value : fn(r.error, r.cause);
231
+ var runOrThrow = (r) => unwrap(r);
232
+ var runOrThrowAsync = (ar) => Promise.resolve(ar).then(unwrap);
233
+ var runOrNull = (r) => r.ok ? r.value : null;
234
+ var runOrUndefined = (r) => r.ok ? r.value : void 0;
235
+ function from(fn, onError) {
236
+ try {
237
+ return ok(fn());
238
+ } catch (cause) {
239
+ return onError ? err(onError(cause), { cause }) : err(cause);
240
+ }
241
+ }
242
+ async function fromPromise(promise, onError) {
243
+ try {
244
+ return ok(await promise);
245
+ } catch (cause) {
246
+ return onError ? err(onError(cause), { cause }) : err(cause);
247
+ }
248
+ }
249
+ async function tryAsync(fn, onError) {
250
+ try {
251
+ return ok(await fn());
252
+ } catch (cause) {
253
+ return onError ? err(onError(cause), { cause }) : err(cause);
254
+ }
255
+ }
256
+ function fromNullable(value, onNull) {
257
+ return value != null ? ok(value) : err(onNull());
258
+ }
259
+ function map(r, fn) {
260
+ return r.ok ? ok(fn(r.value)) : r;
261
+ }
262
+ function mapError(r, fn) {
263
+ return r.ok ? r : err(fn(r.error, r.cause), { cause: r.cause });
264
+ }
265
+ function match(r, handlers) {
266
+ if (handlers === void 0) {
267
+ const h = r;
268
+ return (result) => match(result, h);
269
+ }
270
+ if (r.ok) return handlers.ok(r.value);
271
+ if (typeof handlers.err === "function") return handlers.err(r.error, r.cause);
272
+ const e = r.error;
273
+ const key = typeof e === "string" ? e : e?.type ?? e?._tag;
274
+ const handler = key === void 0 ? void 0 : handlers[key];
275
+ if (typeof handler === "function") return handler(e, r.cause);
276
+ throw new TypeError(
277
+ `match: no handler for error type "${String(key)}". Add a handler for it, or use the { ok, err } form for a catch-all.`
278
+ );
279
+ }
280
+ function andThen(r, fn) {
281
+ return r.ok ? fn(r.value) : r;
282
+ }
283
+ function tap(r, fn) {
284
+ if (r.ok) fn(r.value);
285
+ return r;
286
+ }
287
+ function tapError(r, fn) {
288
+ if (!r.ok) fn(r.error, r.cause);
289
+ return r;
290
+ }
291
+ function mapTry(r, fn, onError) {
292
+ if (!r.ok) return r;
293
+ try {
294
+ return ok(fn(r.value));
295
+ } catch (error) {
296
+ return err(onError(error), { cause: error });
297
+ }
298
+ }
299
+ function mapErrorTry(r, fn, onError) {
300
+ if (r.ok) return r;
301
+ try {
302
+ return err(fn(r.error), { cause: r.cause });
303
+ } catch (error) {
304
+ return err(onError(error), { cause: error });
305
+ }
306
+ }
307
+ function bimap(r, onOk, onErr) {
308
+ return r.ok ? ok(onOk(r.value)) : err(onErr(r.error, r.cause), { cause: r.cause });
309
+ }
310
+ function orElse(r, fn) {
311
+ return r.ok ? r : fn(r.error, r.cause);
312
+ }
313
+ async function orElseAsync(r, fn) {
314
+ return r.ok ? r : fn(r.error, r.cause);
315
+ }
316
+ function recover(r, fn) {
317
+ return r.ok ? ok(r.value) : ok(fn(r.error, r.cause));
318
+ }
319
+ async function recoverAsync(r, fn) {
320
+ const resolved = await r;
321
+ if (resolved.ok) return ok(resolved.value);
322
+ return ok(await fn(resolved.error, resolved.cause));
323
+ }
324
+ function hydrate(value) {
325
+ if (typeof value !== "object" || value === null) return null;
326
+ if (!("ok" in value)) return null;
327
+ const obj = value;
328
+ if (obj.ok === true && "value" in obj) {
329
+ return ok(obj.value);
330
+ }
331
+ if (obj.ok === false && "error" in obj) {
332
+ return err(obj.error, { cause: obj.cause });
333
+ }
334
+ return null;
335
+ }
336
+ function isSerializedResult(value) {
337
+ if (typeof value !== "object" || value === null) return false;
338
+ if (!("ok" in value)) return false;
339
+ const obj = value;
340
+ return obj.ok === true && "value" in obj || obj.ok === false && "error" in obj;
341
+ }
342
+ function all(results) {
343
+ const values = [];
344
+ for (const result of results) {
345
+ if (!result.ok) {
346
+ return result;
347
+ }
348
+ values.push(result.value);
349
+ }
350
+ return ok(values);
351
+ }
352
+ async function allAsync(results) {
353
+ const values = [];
354
+ for (const resultOrPromise of results) {
355
+ try {
356
+ const r = await resultOrPromise;
357
+ if (!r.ok) return r;
358
+ values.push(r.value);
359
+ } catch (reason) {
360
+ return err(
361
+ { type: PROMISE_REJECTED, cause: reason },
362
+ { cause: { type: "PROMISE_REJECTION", reason } }
363
+ );
364
+ }
365
+ }
366
+ return ok(values);
367
+ }
368
+ function allSettled(results) {
369
+ const values = [];
370
+ const errors = [];
371
+ for (const result of results) {
372
+ if (result.ok) {
373
+ values.push(result.value);
374
+ } else {
375
+ errors.push({ error: result.error, cause: result.cause });
376
+ }
377
+ }
378
+ if (errors.length > 0) {
379
+ return err(errors);
380
+ }
381
+ return ok(values);
382
+ }
383
+ async function allSettledAsync(results) {
384
+ const settled = await Promise.all(
385
+ results.map(
386
+ (item) => Promise.resolve(item).then((result) => ({ status: "result", result })).catch((reason) => ({
387
+ status: "rejected",
388
+ error: { type: PROMISE_REJECTED, cause: reason },
389
+ cause: { type: "PROMISE_REJECTION", reason }
390
+ }))
391
+ )
392
+ );
393
+ const values = [];
394
+ const errors = [];
395
+ for (const item of settled) {
396
+ if (item.status === "rejected") {
397
+ errors.push({ error: item.error, cause: item.cause });
398
+ } else if (item.result.ok) {
399
+ values.push(item.result.value);
400
+ } else {
401
+ errors.push({ error: item.result.error, cause: item.result.cause });
402
+ }
403
+ }
404
+ if (errors.length > 0) {
405
+ return err(errors);
406
+ }
407
+ return ok(values);
408
+ }
409
+ function partition(results) {
410
+ const values = [];
411
+ const errors = [];
412
+ for (const r of results) {
413
+ if (r.ok) values.push(r.value);
414
+ else errors.push(r.error);
415
+ }
416
+ return { values, errors };
417
+ }
418
+ function any(results) {
419
+ if (results.length === 0) {
420
+ return err({ type: "EMPTY_INPUT", message: "any() requires at least one Result" });
421
+ }
422
+ let firstErr;
423
+ for (const r of results) {
424
+ if (r.ok) return r;
425
+ if (!firstErr) firstErr = r;
426
+ }
427
+ return firstErr;
428
+ }
429
+ async function anyAsync(results) {
430
+ if (results.length === 0) {
431
+ return err({ type: "EMPTY_INPUT", message: "anyAsync() requires at least one Result" });
432
+ }
433
+ return new Promise((resolve) => {
434
+ let settled = false;
435
+ let pendingCount = results.length;
436
+ let firstError = null;
437
+ for (const item of results) {
438
+ Promise.resolve(item).catch(
439
+ (reason) => err(
440
+ { type: PROMISE_REJECTED, cause: reason },
441
+ { cause: { type: "PROMISE_REJECTION", reason } }
442
+ )
443
+ ).then((result) => {
444
+ if (settled) return;
445
+ if (result.ok) {
446
+ settled = true;
447
+ resolve(result);
448
+ return;
449
+ }
450
+ if (!firstError) firstError = result;
451
+ pendingCount--;
452
+ if (pendingCount === 0) {
453
+ resolve(firstError);
454
+ }
455
+ });
456
+ }
457
+ });
458
+ }
459
+ function zip(a, b) {
460
+ if (!a.ok) return a;
461
+ if (!b.ok) return b;
462
+ return ok([a.value, b.value]);
463
+ }
464
+ async function zipAsync(a, b) {
465
+ const wrapRejection = (p) => Promise.resolve(p).catch(
466
+ (reason) => err(
467
+ { type: PROMISE_REJECTED, cause: reason },
468
+ { cause: { type: "PROMISE_REJECTION", reason } }
469
+ )
470
+ );
471
+ const [ra, rb] = await Promise.all([wrapRejection(a), wrapRejection(b)]);
472
+ return zip(ra, rb);
473
+ }
474
+ function flatten(result) {
475
+ if (!result.ok) return result;
476
+ return result.value;
477
+ }
478
+ var DESERIALIZATION_ERROR = "DESERIALIZATION_ERROR";
479
+ function deserialize(value) {
480
+ if (typeof value !== "object" || value === null) {
481
+ return err({ type: DESERIALIZATION_ERROR, value });
482
+ }
483
+ if (!("ok" in value)) {
484
+ return err({ type: DESERIALIZATION_ERROR, value });
485
+ }
486
+ const obj = value;
487
+ if (obj.ok === true && "value" in obj) {
488
+ return ok(obj.value);
489
+ }
490
+ if (obj.ok === false && "error" in obj) {
491
+ return err(obj.error, { cause: obj.cause });
492
+ }
493
+ return err({ type: DESERIALIZATION_ERROR, value });
494
+ }
495
+ function serialize(result) {
496
+ return result.ok ? { ok: true, value: result.value } : { ok: false, error: result.error };
497
+ }
498
+ function matchErrorPartial(error, handlers, fallback) {
499
+ if (isUnexpectedError(error)) {
500
+ const h2 = handlers.UnexpectedError;
501
+ return h2 ? h2(error) : fallback(error);
502
+ }
503
+ const h = handlers[error];
504
+ return h ? h(error) : fallback(error);
505
+ }
506
+ export {
507
+ AWAITLY_CANCELLED,
508
+ AWAITLY_TIMEOUT,
509
+ AWAITLY_UNEXPECTED,
510
+ DESERIALIZATION_ERROR,
511
+ PROMISE_REJECTED,
512
+ UnexpectedError,
513
+ UnwrapError,
514
+ all,
515
+ allAsync,
516
+ allSettled,
517
+ allSettledAsync,
518
+ andThen,
519
+ any,
520
+ anyAsync,
521
+ bimap,
522
+ deserialize,
523
+ err,
524
+ flatten,
525
+ from,
526
+ fromNullable,
527
+ fromPromise,
528
+ hydrate,
529
+ isErr,
530
+ isOk,
531
+ isPromiseRejectedError,
532
+ isSerializedResult,
533
+ isUnexpectedError,
534
+ map,
535
+ mapError,
536
+ mapErrorTry,
537
+ mapTry,
538
+ match,
539
+ matchError,
540
+ matchErrorPartial,
541
+ ok,
542
+ orElse,
543
+ orElseAsync,
544
+ partition,
545
+ recover,
546
+ recoverAsync,
547
+ runOrNull,
548
+ runOrThrow,
549
+ runOrThrowAsync,
550
+ runOrUndefined,
551
+ serialize,
552
+ tags,
553
+ tap,
554
+ tapError,
555
+ tryAsync,
556
+ unwrap,
557
+ unwrapOr,
558
+ unwrapOrElse,
559
+ zip,
560
+ zipAsync
561
+ };
2
562
  //# sourceMappingURL=result.js.map