awaitly 1.35.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/dist/{duration.d.ts → di-BDlT7InM.d.cts} +15 -1
  2. package/dist/{duration.d.cts → di-BbFFfO8y.d.ts} +15 -1
  3. package/dist/errors-DtXvrCiO.d.cts +708 -0
  4. package/dist/errors-DtXvrCiO.d.ts +708 -0
  5. package/dist/index.cjs +4594 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +1970 -141
  8. package/dist/index.d.ts +1970 -141
  9. package/dist/index.js +4398 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/result.cjs +641 -1
  12. package/dist/result.cjs.map +1 -1
  13. package/dist/result.d.cts +29 -4
  14. package/dist/result.d.ts +29 -4
  15. package/dist/result.js +561 -1
  16. package/dist/result.js.map +1 -1
  17. package/dist/testing.cjs +4202 -8
  18. package/dist/testing.cjs.map +1 -1
  19. package/dist/testing.d.cts +2 -6
  20. package/dist/testing.d.ts +2 -6
  21. package/dist/testing.js +4154 -8
  22. package/dist/testing.js.map +1 -1
  23. package/dist/{run-entry-DGs0tySr.d.cts → types-B8NfNRGX.d.ts} +1078 -1502
  24. package/dist/{run-entry-BOuNyVoO.d.ts → types-BZ2f4MRR.d.cts} +1078 -1502
  25. package/dist/workflow.cjs +7096 -6
  26. package/dist/workflow.cjs.map +1 -1
  27. package/dist/workflow.d.cts +3346 -22
  28. package/dist/workflow.d.ts +3346 -22
  29. package/dist/workflow.js +6929 -6
  30. package/dist/workflow.js.map +1 -1
  31. package/package.json +3 -168
  32. package/dist/adapters.cjs +0 -7
  33. package/dist/adapters.cjs.map +0 -1
  34. package/dist/adapters.d.cts +0 -179
  35. package/dist/adapters.d.ts +0 -179
  36. package/dist/adapters.js +0 -7
  37. package/dist/adapters.js.map +0 -1
  38. package/dist/batch.cjs +0 -7
  39. package/dist/batch.cjs.map +0 -1
  40. package/dist/batch.d.cts +0 -200
  41. package/dist/batch.d.ts +0 -200
  42. package/dist/batch.js +0 -7
  43. package/dist/batch.js.map +0 -1
  44. package/dist/bind-deps.cjs +0 -2
  45. package/dist/bind-deps.cjs.map +0 -1
  46. package/dist/bind-deps.d.cts +0 -28
  47. package/dist/bind-deps.d.ts +0 -28
  48. package/dist/bind-deps.js +0 -2
  49. package/dist/bind-deps.js.map +0 -1
  50. package/dist/cache.cjs +0 -2
  51. package/dist/cache.cjs.map +0 -1
  52. package/dist/cache.d.cts +0 -269
  53. package/dist/cache.d.ts +0 -269
  54. package/dist/cache.js +0 -2
  55. package/dist/cache.js.map +0 -1
  56. package/dist/circuit-breaker.cjs +0 -7
  57. package/dist/circuit-breaker.cjs.map +0 -1
  58. package/dist/circuit-breaker.d.cts +0 -211
  59. package/dist/circuit-breaker.d.ts +0 -211
  60. package/dist/circuit-breaker.js +0 -7
  61. package/dist/circuit-breaker.js.map +0 -1
  62. package/dist/conditional.cjs +0 -2
  63. package/dist/conditional.cjs.map +0 -1
  64. package/dist/conditional.d.cts +0 -252
  65. package/dist/conditional.d.ts +0 -252
  66. package/dist/conditional.js +0 -2
  67. package/dist/conditional.js.map +0 -1
  68. package/dist/core.cjs +0 -7
  69. package/dist/core.cjs.map +0 -1
  70. package/dist/core.d.cts +0 -5
  71. package/dist/core.d.ts +0 -5
  72. package/dist/core.js +0 -7
  73. package/dist/core.js.map +0 -1
  74. package/dist/di-By77n4Fa.d.ts +0 -15
  75. package/dist/di-OJfsohf-.d.cts +0 -15
  76. package/dist/diagnostics.cjs +0 -8
  77. package/dist/diagnostics.cjs.map +0 -1
  78. package/dist/diagnostics.d.cts +0 -68
  79. package/dist/diagnostics.d.ts +0 -68
  80. package/dist/diagnostics.js +0 -8
  81. package/dist/diagnostics.js.map +0 -1
  82. package/dist/durable.cjs +0 -11
  83. package/dist/durable.cjs.map +0 -1
  84. package/dist/durable.d.cts +0 -9
  85. package/dist/durable.d.ts +0 -9
  86. package/dist/durable.js +0 -11
  87. package/dist/durable.js.map +0 -1
  88. package/dist/duration.cjs +0 -2
  89. package/dist/duration.cjs.map +0 -1
  90. package/dist/duration.js +0 -2
  91. package/dist/duration.js.map +0 -1
  92. package/dist/engine.cjs +0 -11
  93. package/dist/engine.cjs.map +0 -1
  94. package/dist/engine.d.cts +0 -115
  95. package/dist/engine.d.ts +0 -115
  96. package/dist/engine.js +0 -11
  97. package/dist/engine.js.map +0 -1
  98. package/dist/errors.cjs +0 -2
  99. package/dist/errors.cjs.map +0 -1
  100. package/dist/errors.d.cts +0 -361
  101. package/dist/errors.d.ts +0 -361
  102. package/dist/errors.js +0 -2
  103. package/dist/errors.js.map +0 -1
  104. package/dist/fetch.cjs +0 -7
  105. package/dist/fetch.cjs.map +0 -1
  106. package/dist/fetch.d.cts +0 -86
  107. package/dist/fetch.d.ts +0 -86
  108. package/dist/fetch.js +0 -7
  109. package/dist/fetch.js.map +0 -1
  110. package/dist/flow.cjs +0 -7
  111. package/dist/flow.cjs.map +0 -1
  112. package/dist/flow.d.cts +0 -163
  113. package/dist/flow.d.ts +0 -163
  114. package/dist/flow.js +0 -7
  115. package/dist/flow.js.map +0 -1
  116. package/dist/functional.cjs +0 -2
  117. package/dist/functional.cjs.map +0 -1
  118. package/dist/functional.d.cts +0 -444
  119. package/dist/functional.d.ts +0 -444
  120. package/dist/functional.js +0 -2
  121. package/dist/functional.js.map +0 -1
  122. package/dist/guards-4sV7mTqj.d.cts +0 -72
  123. package/dist/guards-BIX05ALH.d.ts +0 -72
  124. package/dist/hitl-DFn4Xa_l.d.cts +0 -468
  125. package/dist/hitl-DU5VpKq7.d.ts +0 -468
  126. package/dist/hitl.cjs +0 -7
  127. package/dist/hitl.cjs.map +0 -1
  128. package/dist/hitl.d.cts +0 -442
  129. package/dist/hitl.d.ts +0 -442
  130. package/dist/hitl.js +0 -7
  131. package/dist/hitl.js.map +0 -1
  132. package/dist/index-CnvBryQB.d.ts +0 -417
  133. package/dist/index-DEZEf8Fs.d.cts +0 -417
  134. package/dist/match-entry-DjI2bLpD.d.cts +0 -209
  135. package/dist/match-entry-DjI2bLpD.d.ts +0 -209
  136. package/dist/match.cjs +0 -2
  137. package/dist/match.cjs.map +0 -1
  138. package/dist/match.d.cts +0 -1
  139. package/dist/match.d.ts +0 -1
  140. package/dist/match.js +0 -2
  141. package/dist/match.js.map +0 -1
  142. package/dist/otel.cjs +0 -2
  143. package/dist/otel.cjs.map +0 -1
  144. package/dist/otel.d.cts +0 -188
  145. package/dist/otel.d.ts +0 -188
  146. package/dist/otel.js +0 -2
  147. package/dist/otel.js.map +0 -1
  148. package/dist/persistence-entry-B-8PjnSR.d.cts +0 -831
  149. package/dist/persistence-entry-D8zRkLiT.d.ts +0 -831
  150. package/dist/persistence.cjs +0 -2
  151. package/dist/persistence.cjs.map +0 -1
  152. package/dist/persistence.d.cts +0 -7
  153. package/dist/persistence.d.ts +0 -7
  154. package/dist/persistence.js +0 -2
  155. package/dist/persistence.js.map +0 -1
  156. package/dist/policies.cjs +0 -2
  157. package/dist/policies.cjs.map +0 -1
  158. package/dist/policies.d.cts +0 -379
  159. package/dist/policies.d.ts +0 -379
  160. package/dist/policies.js +0 -2
  161. package/dist/policies.js.map +0 -1
  162. package/dist/ratelimit.cjs +0 -7
  163. package/dist/ratelimit.cjs.map +0 -1
  164. package/dist/ratelimit.d.cts +0 -458
  165. package/dist/ratelimit.d.ts +0 -458
  166. package/dist/ratelimit.js +0 -7
  167. package/dist/ratelimit.js.map +0 -1
  168. package/dist/reliability.cjs +0 -11
  169. package/dist/reliability.cjs.map +0 -1
  170. package/dist/reliability.d.cts +0 -11
  171. package/dist/reliability.d.ts +0 -11
  172. package/dist/reliability.js +0 -11
  173. package/dist/reliability.js.map +0 -1
  174. package/dist/resolver.cjs +0 -7
  175. package/dist/resolver.cjs.map +0 -1
  176. package/dist/resolver.d.cts +0 -68
  177. package/dist/resolver.d.ts +0 -68
  178. package/dist/resolver.js +0 -7
  179. package/dist/resolver.js.map +0 -1
  180. package/dist/resource.cjs +0 -7
  181. package/dist/resource.cjs.map +0 -1
  182. package/dist/resource.d.cts +0 -174
  183. package/dist/resource.d.ts +0 -174
  184. package/dist/resource.js +0 -7
  185. package/dist/resource.js.map +0 -1
  186. package/dist/result/retry.cjs +0 -2
  187. package/dist/result/retry.cjs.map +0 -1
  188. package/dist/result/retry.d.cts +0 -70
  189. package/dist/result/retry.d.ts +0 -70
  190. package/dist/result/retry.js +0 -2
  191. package/dist/result/retry.js.map +0 -1
  192. package/dist/retry.cjs +0 -2
  193. package/dist/retry.cjs.map +0 -1
  194. package/dist/retry.d.cts +0 -388
  195. package/dist/retry.d.ts +0 -388
  196. package/dist/retry.js +0 -2
  197. package/dist/retry.js.map +0 -1
  198. package/dist/run.cjs +0 -7
  199. package/dist/run.cjs.map +0 -1
  200. package/dist/run.d.cts +0 -4
  201. package/dist/run.d.ts +0 -4
  202. package/dist/run.js +0 -7
  203. package/dist/run.js.map +0 -1
  204. package/dist/saga.cjs +0 -11
  205. package/dist/saga.cjs.map +0 -1
  206. package/dist/saga.d.cts +0 -164
  207. package/dist/saga.d.ts +0 -164
  208. package/dist/saga.js +0 -11
  209. package/dist/saga.js.map +0 -1
  210. package/dist/singleflight.cjs +0 -2
  211. package/dist/singleflight.cjs.map +0 -1
  212. package/dist/singleflight.d.cts +0 -145
  213. package/dist/singleflight.d.ts +0 -145
  214. package/dist/singleflight.js +0 -2
  215. package/dist/singleflight.js.map +0 -1
  216. package/dist/slugs.cjs +0 -2
  217. package/dist/slugs.cjs.map +0 -1
  218. package/dist/slugs.d.cts +0 -67
  219. package/dist/slugs.d.ts +0 -67
  220. package/dist/slugs.js +0 -2
  221. package/dist/slugs.js.map +0 -1
  222. package/dist/streaming.cjs +0 -9
  223. package/dist/streaming.cjs.map +0 -1
  224. package/dist/streaming.d.cts +0 -596
  225. package/dist/streaming.d.ts +0 -596
  226. package/dist/streaming.js +0 -9
  227. package/dist/streaming.js.map +0 -1
  228. package/dist/tagged-error.cjs +0 -2
  229. package/dist/tagged-error.cjs.map +0 -1
  230. package/dist/tagged-error.d.cts +0 -275
  231. package/dist/tagged-error.d.ts +0 -275
  232. package/dist/tagged-error.js +0 -2
  233. package/dist/tagged-error.js.map +0 -1
  234. package/dist/types-BziYHFkD.d.ts +0 -323
  235. package/dist/types-C5jLEUqY.d.cts +0 -323
  236. package/dist/webhook.cjs +0 -7
  237. package/dist/webhook.cjs.map +0 -1
  238. package/dist/webhook.d.cts +0 -499
  239. package/dist/webhook.d.ts +0 -499
  240. package/dist/webhook.js +0 -7
  241. package/dist/webhook.js.map +0 -1
package/dist/core.d.cts DELETED
@@ -1,5 +0,0 @@
1
- export { A as AWAITLY_CANCELLED, a as AWAITLY_TIMEOUT, b as AWAITLY_UNEXPECTED, c as AsyncResult, C as CauseOf, E as EmptyInputError, d as Err, e as ErrorClassification, f as ErrorOf, g as Errors, h as ErrorsOf, i as ExtractCause, j as ExtractError, k as ExtractValue, M as MatchErrorHandlers, l as MaybeAsyncResult, O as Ok, P as PROMISE_REJECTED, m as PromiseRejectedError, n as PromiseRejectionCause, R as Result, S as SettledError, o as StepErrorDiagnostics, p as StepMetadata, U as UnwrapError, q as all, r as allAsync, s as allSettled, t as allSettledAsync, u as andThen, v as any, w as anyAsync, x as bimap, y as err, z as extractErrorTag, B as extractStepMetadata, D as from, F as fromNullable, G as fromPromise, H as hydrate, I as isErr, J as isOk, K as isSerializedResult, L as isUnexpectedError, N as lookupErrorClassification, Q as map, T as mapError, V as mapErrorTry, W as mapTry, X as match, Y as matchError, Z as ok, _ as orElse, $ as orElseAsync, a0 as partition, a1 as recover, a2 as recoverAsync, a3 as runOrNull, a4 as runOrThrow, a5 as runOrThrowAsync, a6 as runOrUndefined, a7 as tags, a8 as tap, a9 as tapError, aa as tryAsync, ab as unwrap, ac as unwrapOr, ad as unwrapOrElse } from './run-entry-DGs0tySr.cjs';
2
- export { ErrorByTag, PropsOf, TagOf, TaggedError, TaggedErrorBase, TaggedErrorConstructor, TaggedErrorCreateOptions, TaggedErrorOptions } from './tagged-error.cjs';
3
- export { ALL_SLUGS, AWAITLY_SLUGS, AwaitlySlug, AwaitlySlugCategory, isAwaitlySlug, slugCategory, slugDocsUrl } from './slugs.cjs';
4
- export { M as Match, a as MatchTag, b as Matcher, T as Tagged, e as exhaustive, i as isOneOf, c as isTag, o as matchOrElse, t as matchTag, d as matchTags, m as matchValue, w as matchWhen, f as orElseValue } from './match-entry-DjI2bLpD.cjs';
5
- export { UnexpectedError } from './errors.cjs';
package/dist/core.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export { A as AWAITLY_CANCELLED, a as AWAITLY_TIMEOUT, b as AWAITLY_UNEXPECTED, c as AsyncResult, C as CauseOf, E as EmptyInputError, d as Err, e as ErrorClassification, f as ErrorOf, g as Errors, h as ErrorsOf, i as ExtractCause, j as ExtractError, k as ExtractValue, M as MatchErrorHandlers, l as MaybeAsyncResult, O as Ok, P as PROMISE_REJECTED, m as PromiseRejectedError, n as PromiseRejectionCause, R as Result, S as SettledError, o as StepErrorDiagnostics, p as StepMetadata, U as UnwrapError, q as all, r as allAsync, s as allSettled, t as allSettledAsync, u as andThen, v as any, w as anyAsync, x as bimap, y as err, z as extractErrorTag, B as extractStepMetadata, D as from, F as fromNullable, G as fromPromise, H as hydrate, I as isErr, J as isOk, K as isSerializedResult, L as isUnexpectedError, N as lookupErrorClassification, Q as map, T as mapError, V as mapErrorTry, W as mapTry, X as match, Y as matchError, Z as ok, _ as orElse, $ as orElseAsync, a0 as partition, a1 as recover, a2 as recoverAsync, a3 as runOrNull, a4 as runOrThrow, a5 as runOrThrowAsync, a6 as runOrUndefined, a7 as tags, a8 as tap, a9 as tapError, aa as tryAsync, ab as unwrap, ac as unwrapOr, ad as unwrapOrElse } from './run-entry-BOuNyVoO.js';
2
- export { ErrorByTag, PropsOf, TagOf, TaggedError, TaggedErrorBase, TaggedErrorConstructor, TaggedErrorCreateOptions, TaggedErrorOptions } from './tagged-error.js';
3
- export { ALL_SLUGS, AWAITLY_SLUGS, AwaitlySlug, AwaitlySlugCategory, isAwaitlySlug, slugCategory, slugDocsUrl } from './slugs.js';
4
- export { M as Match, a as MatchTag, b as Matcher, T as Tagged, e as exhaustive, i as isOneOf, c as isTag, o as matchOrElse, t as matchTag, d as matchTags, m as matchValue, w as matchWhen, f as orElseValue } from './match-entry-DjI2bLpD.js';
5
- export { UnexpectedError } from './errors.js';
package/dist/core.js DELETED
@@ -1,7 +0,0 @@
1
- var de={"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 rt(e){return e.split("-")[0]}function me(e){return`https://jagreehal.github.io/awaitly/rules/#${e}`}function nt(e){return Object.prototype.hasOwnProperty.call(de,e)}var ot=Object.keys(de);var oe=class extends Error{_tag};function K(e,t){return class extends oe{_tag=e;constructor(r,l){let T=t?.message?t.message(r??{}):e;if(super(T),this.name=e,t?.slug!==void 0){if(!t.hint)throw new TypeError(`TaggedError: 'hint' is required when 'slug' is set (slug: "${t.slug}")`);Object.defineProperty(this,"code",{value:t.slug,enumerable:!0,writable:!1,configurable:!1}),Object.defineProperty(this,"hint",{value:t.hint,enumerable:!0,writable:!1,configurable:!1}),Object.defineProperty(this,"docsUrl",{value:me(t.slug),enumerable:!0,writable:!1,configurable:!1})}if(Object.setPrototypeOf(this,new.target.prototype),r&&typeof r=="object"){let p;if(t?.slug!==void 0){let{_tag:j,name:v,message:N,stack:a,code:F,hint:L,docsUrl:Re,...re}=r;p=re}else{let{_tag:j,name:v,message:N,stack:a,...F}=r;p=F}let f=Object.prototype.hasOwnProperty.call(p,"cause"),S=f?p.cause:void 0;f&&delete p.cause;let D=l?.cause!==void 0;if(f&&D)throw new TypeError("TaggedError: cannot provide 'cause' in props when also setting ErrorOptions.cause");Object.assign(this,p),f&&(this.cause=S),D&&(this.cause=l?.cause)}else l?.cause!==void 0&&(this.cause=l.cause)}}}Object.defineProperty(K,Symbol.hasInstance,{value:e=>e instanceof oe});(T=>{function e(p){return p instanceof Error}T.isError=e;function t(p){return p instanceof oe}T.isTaggedError=t;function r(p,f){let S=p._tag,D=f[S];return D(p)}T.match=r;function l(p,f,S){let D=p._tag,j=f[D];return j?j(p):S(p)}T.matchPartial=l})(K||={});var xe=class extends K("TimeoutError",{slug:"runtime-step-timeout",hint:"Increase the step's timeout option, or check why the upstream operation is slow.",message:t=>t.operation?`TimeoutError: ${t.operation} timed out after ${t.ms}ms`:`TimeoutError: Operation timed out after ${t.ms}ms`}){},Ce=class extends K("RetryExhaustedError",{slug:"runtime-retry-exhausted",hint:"All retry attempts failed. Inspect lastError and decide whether to surface it or compensate.",message:t=>t.operation?`RetryExhaustedError: ${t.operation} failed after ${t.attempts} attempts`:`RetryExhaustedError: Operation failed after ${t.attempts} attempts`}){},he=class extends K("RateLimitError",{slug:"runtime-rate-limit",hint:"Wait retryAfterMs before retrying, or apply step.cache to deduplicate calls.",message:t=>t.limiterName?`RateLimitError: Rate limit exceeded for ${t.limiterName}${t.retryAfterMs?`, retry after ${t.retryAfterMs}ms`:""}`:`RateLimitError: Rate limit exceeded${t.retryAfterMs?`, retry after ${t.retryAfterMs}ms`:""}`}){},be=class extends K("CircuitBreakerOpenError",{slug:"runtime-circuit-open",hint:"The circuit is open. Wait for it to half-open or fall back to a degraded path.",message:t=>`CircuitBreakerOpenError: Circuit ${t.circuitName} is ${t.state??"OPEN"}${t.retryAfterMs?`, retry after ${Math.ceil(t.retryAfterMs/1e3)}s`:""}`}){},Ae=class extends K("ValidationError",{message:t=>`ValidationError: Invalid ${t.field} - ${t.reason}`}){},Se=class extends K("NotFoundError",{message:t=>t.id?`NotFoundError: ${t.resource} with id ${t.id} not found`:`NotFoundError: ${t.resource} not found`}){},Oe=class extends K("UnauthorizedError",{message:t=>t.reason?`UnauthorizedError: ${t.reason}`:t.action&&t.resource?`UnauthorizedError: Not authorized to ${t.action} ${t.resource}`:"UnauthorizedError: Access denied"}){},Pe=class extends K("NetworkError",{message:t=>t.url?`NetworkError: ${t.reason} (${t.url})`:`NetworkError: ${t.reason}`}){},ve=class extends K("CompensationError",{slug:"runtime-saga-compensation",hint:"A saga compensation step failed. Inspect compensationError and ensure compensation is idempotent.",message:t=>`CompensationError: Failed to compensate step ${t.step}`}){},Z=class extends K("UnexpectedError",{slug:"runtime-unexpected",hint:"An unexpected exception escaped a step. Inspect cause; consider returning a typed Result instead of throwing.",message:t=>`UnexpectedError: ${t.cause instanceof Error?t.cause.message:String(t.cause??"unknown")}`}){};function _e(e){return{ok:!0,value:e}}var st=e=>typeof e=="object"&&e!==null&&"ok"in e&&typeof e.ok=="boolean"&&(e.ok?"value"in e:"error"in e),Me=(e,t)=>{let r={},l=new Map;for(let T of Object.keys(e)){let p=e[T];typeof p=="function"&&(r[T]=(...f)=>{let S=(l.get(T)??0)+1;l.set(T,S);let D=S===1?T:`${T}#${S}`;return t(D,async()=>{let j=await p(...f);return st(j)?j:_e(j)})})}return r};function at(e){let t=e.trim().match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h|d)$/i);if(!t)return;let r=parseFloat(t[1]),l=t[2].toLowerCase();return{_tag:"Duration",millis:r*({ms:1,s:1e3,m:6e4,h:36e5,d:864e5}[l]??1)}}var ut="PROMISE_REJECTED",it="AWAITLY_UNEXPECTED",lt="AWAITLY_CANCELLED",ct="AWAITLY_TIMEOUT",pt=(...e)=>e;function Et(e){return new Z({cause:e})}function I(e){return{ok:!0,value:e}}function P(e,t){let r=t?.cause;return{ok:!1,error:e,...r!==void 0?{cause:r}:{}}}var dt=e=>e.ok,mt=e=>!e.ok,Ue=e=>e instanceof Z||typeof e=="object"&&e!==null&&"_tag"in e&&e._tag==="UnexpectedError";function Ne(e,t){if(t===void 0){let l=e;return T=>Ne(T,l)}let r=e;return Ue(r)?t.UnexpectedError(r):t[r](r)}function Ke(e){if(e==null)return"unknown";if(typeof e=="string")return e.trim()||"unknown";if(typeof e=="object"){let t=e;if(typeof t._tag=="string"){let r=t._tag.trim();if(r)return r}if(typeof t.tag=="string"){let r=t.tag.trim();if(r)return r}if(typeof t.code=="string"){let r=t.code.trim();if(r)return r}else if(typeof t.code=="number")return String(t.code);if(e instanceof Error&&e.name){let r=e.name.trim();if(r)return r}}return"unknown"}function je(e,t){if(!(!t||!e))return t[e]}function Fe(e){let{intent:t,domain:r,owner:l,tags:T,stateChanges:p,emits:f,calls:S}=e;if(!t&&!r&&!l&&!T?.length&&!p?.length&&!f?.length&&!S?.length)return;let D={};return t&&(D.intent=t),r&&(D.domain=r),l&&(D.owner=l),T?.length&&(D.tags=T),p?.length&&(D.stateChanges=p),f?.length&&(D.emits=f),S?.length&&(D.calls=S),D}function V(e,t,r,l,T){let p=Ke(e),f=je(p,t),S={tag:p,origin:r};return f!==void 0&&(S.classification=f),l!==void 0&&(S.attempt=l),T!==void 0&&(S.cumulativeDurationMs=T),S}var te=Symbol.for("step_timeout_marker");function Ie(e){return typeof e!="object"||e===null?!1:e.type==="STEP_TIMEOUT"?!0:te in e}function yt(e){if(!(typeof e!="object"||e===null)){if(e.type==="STEP_TIMEOUT"){let t=e;return{timeoutMs:t.timeoutMs,stepName:t.stepName,stepKey:t.stepKey,attempt:t.attempt}}if(te in e)return e[te]}}var Be=Symbol("early-exit");function wt(e,t){return{[Be]:!0,error:e,meta:t}}function ft(e){return typeof e=="object"&&e!==null&&e[Be]===!0}var Le=Symbol("mapper-exception");function Q(e){return{[Le]:!0,thrown:e}}function Tt(e){return typeof e=="object"&&e!==null&&e[Le]===!0}function ye(e,t){let{backoff:r,initialDelay:l,maxDelay:T,jitter:p}=t,f;switch(r){case"fixed":f=l;break;case"linear":f=l*e;break;case"exponential":f=l*Math.pow(2,e-1);break}if(f=Math.min(f,T),p){let S=f*.25*Math.random();f=f+S}return Math.floor(f)}function we(e){return new Promise(t=>setTimeout(t,e))}var De=Symbol("timeout"),ae=Symbol("timeout-option");function kt(e){return typeof e=="object"&&e!==null&&e[ae]===!0}async function gt(e,t,r,l){let T=new AbortController,p=t.onTimeout??"error",f=()=>typeof p=="function"?p({name:r.name,key:r.key,ms:t.ms}):t.error??{type:"STEP_TIMEOUT",stepName:r.name,stepKey:r.key,timeoutMs:t.ms,attempt:r.attempt},S;l?.aborted&&T.abort(l.reason);let D;l&&!l.aborted&&(D=()=>T.abort(l.reason),l.addEventListener("abort",D,{once:!0}));let j=new Promise((N,a)=>{S=setTimeout(()=>{if(p!=="disconnect"&&T.abort(),p==="option"){a({[ae]:!0,ms:t.ms});return}a({[De]:!0,error:f()})},t.ms)}),v;t.signal?v=Promise.resolve(e(T.signal)):v=Promise.resolve(e());try{return await Promise.race([v,j])}catch(N){if(typeof N=="object"&&N!==null&&N[ae]===!0)throw{[ae]:!0,ms:t.ms};if(typeof N=="object"&&N!==null&&N[De]===!0){p==="disconnect"&&v.catch(()=>{});let a=N.error;if(typeof a=="object"&&a!==null&&a.type!=="STEP_TIMEOUT"){let F={timeoutMs:t.ms,stepName:r.name,stepKey:r.key,attempt:r.attempt};te in a?a[te]=F:Object.defineProperty(a,te,{value:F,enumerable:!1,writable:!0,configurable:!1})}throw a}throw N}finally{clearTimeout(S),D&&l&&l.removeEventListener("abort",D)}}var ee={backoff:"exponential",initialDelay:100,maxDelay:3e4,jitter:!0,shouldRetry:()=>!0,onRetry:()=>{}};async function fe(e,t,r){if(typeof e!="function"){let d=e,B=t;if(typeof B!="function")throw new TypeError("[awaitly] run(deps, fn) requires a callback as the second argument. Example: run({ getUser }, async (s) => s.getUser(id))");return fe(({step:G})=>B(Me(d,G),{step:G}),r)}let l=e,T=t,{onError:p,onEvent:f,catchUnexpected:S,workflowId:D,workflowName:j,context:v,_workflowSignal:N}=T&&typeof T=="object"?T:{},a=D??crypto.randomUUID(),F=S??Et,L=[],Re=0,re=d=>d??`step_${++Re}`,c=d=>{let B=d.context!==void 0||v===void 0?d:{...d,context:v},W=j!==void 0&&B.workflowName===void 0?{...B,workflowName:j}:B;if(W.type==="step_success"){let G=W.stepId;for(let se=L.length-1;se>=0;se--){let H=L[se];if(H.type==="race"&&!H.winnerId){H.winnerId=G;break}}}f?.(W,v)},U=wt,J=d=>ft(d),Y=(d,B)=>d,Qe=d=>typeof d=="function"?!1:!!(d&&typeof d=="object"&&"ok"in d||d&&typeof d=="object"&&"then"in d&&typeof d.then=="function");try{let B=function(u){let m={};for(let[o,s]of Object.entries(u))if(typeof s=="function")m[o]=s;else if(s&&typeof s=="object"&&"fn"in s)m[o]=s.fn;else throw new TypeError(`step.all: operation "${o}" must be a function or { fn, errors? } object`);return m},W=function(u,m){let o=`scope_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return(async()=>{let s=performance.now(),n=!1;L.push({scopeId:o,type:"parallel"});let i=()=>{if(n)return;n=!0;let E=L.findIndex(y=>y.scopeId===o);E!==-1&&L.splice(E,1),c({type:"scope_end",workflowId:a,scopeId:o,ts:Date.now(),durationMs:performance.now()-s})};c({type:"scope_start",workflowId:a,scopeId:o,scopeType:"parallel",name:u,ts:Date.now()});try{let E=await m();if(i(),!E.ok)throw p?.(E.error,u,v),U(E.error,{origin:"result",resultCause:E.cause});return E.value}catch(E){throw i(),E}})()},G=function(u,m){let o=Object.keys(u),s=m.name??`Parallel(${o.join(", ")})`,n=`scope_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return(async()=>{let i=performance.now(),E=!1;L.push({scopeId:n,type:"parallel"});let y=()=>{if(E)return;E=!0;let w=L.findIndex(k=>k.scopeId===n);w!==-1&&L.splice(w,1),c({type:"scope_end",workflowId:a,scopeId:n,ts:Date.now(),durationMs:performance.now()-i})};c({type:"scope_start",workflowId:a,scopeId:n,scopeType:"parallel",name:s,ts:Date.now()});try{let w=await new Promise(R=>{if(o.length===0){R([]);return}let A=!1,M=o.length,x=new Array(o.length);for(let _=0;_<o.length;_++){let C=o[_],b=_;Promise.resolve(u[C]()).catch(h=>P({type:"PROMISE_REJECTED",cause:h},{cause:{type:"PROMISE_REJECTION",reason:h}})).then(h=>{if(!A){if(!h.ok){A=!0,R([{key:C,result:h}]);return}x[b]={key:C,result:h},M--,M===0&&R(x)}})}});y();let k={};for(let{key:R,result:A}of w){if(!A.ok)throw p?.(A.error,R,v),U(A.error,{origin:"result",resultCause:A.cause});k[R]=A.value}return k}catch(w){throw y(),w}})()};var Zt=B,Qt=W,er=G;let d=(u,m,o)=>(async()=>{if(typeof u!="string"||u.length===0)throw new Error('[awaitly] step() requires an explicit string ID as the first argument. Example: step("fetchUser", () => fetchUser(id))');let s=o??{},n=Fe(s),i=u,E=s.key??u,y=s.key??u,{description:w,retry:k,timeout:R}=s,A=re(E),M=f,x=M?performance.now():0,C=Qe(m)?()=>m:m,h={attempts:Math.max(1,k?.attempts??1),backoff:k?.backoff??ee.backoff,initialDelay:k?.initialDelay??ee.initialDelay,maxDelay:k?.maxDelay??ee.maxDelay,jitter:k?.jitter??ee.jitter,shouldRetry:k?.shouldRetry??ee.shouldRetry,onRetry:k?.onRetry??ee.onRetry};f&&c({type:"step_start",workflowId:a,stepId:A,stepKey:E,name:i,description:w,ts:Date.now(),...n&&{metadata:n}});let X;for(let O=1;O<=h.attempts;O++){let et=M?performance.now():0;try{let g;if(R?g=await gt(C,R,{name:i,key:E,attempt:O},N):g=await C(),g.ok){let z=performance.now()-x;return c({type:"step_success",workflowId:a,stepId:A,stepKey:E,name:i,description:w,ts:Date.now(),durationMs:z,...n&&{metadata:n}}),y&&c({type:"step_complete",workflowId:a,stepKey:y,name:i,description:w,ts:Date.now(),durationMs:z,result:g,...n&&{metadata:n}}),g.value}if(X=g,O<h.attempts&&h.shouldRetry(g.error,O)){let z=ye(O,h);c({type:"step_retry",workflowId:a,stepId:A,stepKey:E,name:i,ts:Date.now(),attempt:O+1,maxAttempts:h.attempts,delayMs:z,error:g.error,...n&&{metadata:n},diagnostics:V(g.error,s.errorMeta,"result",O,performance.now()-x)}),h.onRetry(g.error,O,z),await we(z);continue}h.attempts>1&&c({type:"step_retries_exhausted",workflowId:a,stepId:A,stepKey:E,name:i,ts:Date.now(),durationMs:performance.now()-x,attempts:O,lastError:g.error,...n&&{metadata:n},diagnostics:V(g.error,s.errorMeta,"result",O,performance.now()-x)});break}catch(g){let z=performance.now()-et;if(kt(g)){let $=g.ms;c({type:"step_timeout",workflowId:a,stepId:A,stepKey:E,name:i,ts:Date.now(),timeoutMs:$,attempt:O,...n&&{metadata:n},diagnostics:V(g,s.errorMeta,"timeout",O)}),c({type:"step_success",workflowId:a,stepId:A,stepKey:E,name:i,description:w,ts:Date.now(),durationMs:performance.now()-x,...n&&{metadata:n}}),y&&c({type:"step_complete",workflowId:a,stepKey:y,name:i,description:w,ts:Date.now(),durationMs:performance.now()-x,result:I(void 0),...n&&{metadata:n}});return}if(J(g))throw c({type:"step_aborted",workflowId:a,stepId:A,stepKey:E,name:i,description:w,ts:Date.now(),durationMs:z,...n&&{metadata:n}}),g;if(Ie(g)){let $=yt(g),tt=R?.ms??$?.timeoutMs??0;if(c({type:"step_timeout",workflowId:a,stepId:A,stepKey:E,name:i,ts:Date.now(),timeoutMs:tt,attempt:O,...n&&{metadata:n},diagnostics:V(g,s.errorMeta,"timeout",O)}),O<h.attempts&&h.shouldRetry(g,O)){let Ee=ye(O,h);c({type:"step_retry",workflowId:a,stepId:A,stepKey:E,name:i,ts:Date.now(),attempt:O+1,maxAttempts:h.attempts,delayMs:Ee,error:g,...n&&{metadata:n},diagnostics:V(g,s.errorMeta,"timeout",O,performance.now()-x)}),h.onRetry(g,O,Ee),await we(Ee);continue}h.attempts>1&&c({type:"step_retries_exhausted",workflowId:a,stepId:A,stepKey:E,name:i,ts:Date.now(),durationMs:performance.now()-x,attempts:O,lastError:g,...n&&{metadata:n},diagnostics:V(g,s.errorMeta,"timeout",O,performance.now()-x)});let pe=performance.now()-x;throw c({type:"step_error",workflowId:a,stepId:A,stepKey:E,name:i,description:w,ts:Date.now(),durationMs:pe,error:g,...n&&{metadata:n},diagnostics:V(g,s.errorMeta,"timeout",O,pe)}),y&&c({type:"step_complete",workflowId:a,stepKey:y,name:i,description:w,ts:Date.now(),durationMs:pe,result:P(g,{cause:g}),meta:{origin:"throw",thrown:g},...n&&{metadata:n}}),p?.(g,i,v),U(g,{origin:"throw",thrown:g})}if(O<h.attempts&&h.shouldRetry(g,O)){let $=ye(O,h);c({type:"step_retry",workflowId:a,stepId:A,stepKey:E,name:i,ts:Date.now(),attempt:O+1,maxAttempts:h.attempts,delayMs:$,error:g,...n&&{metadata:n},diagnostics:V(g,s.errorMeta,"throw",O,performance.now()-x)}),h.onRetry(g,O,$),await we($);continue}h.attempts>1&&!Ie(g)&&c({type:"step_retries_exhausted",workflowId:a,stepId:A,stepKey:E,name:i,ts:Date.now(),durationMs:performance.now()-x,attempts:O,lastError:g,...n&&{metadata:n},diagnostics:V(g,s.errorMeta,"throw",O,performance.now()-x)});let ce=performance.now()-x,ne;try{ne=F(g)}catch($){throw Q($)}throw c({type:"step_error",workflowId:a,stepId:A,stepKey:E,name:i,description:w,ts:Date.now(),durationMs:ce,error:ne,...n&&{metadata:n},diagnostics:V(g,s.errorMeta,"throw",O,ce)}),y&&c({type:"step_complete",workflowId:a,stepKey:y,name:i,description:w,ts:Date.now(),durationMs:ce,result:P(ne,{cause:g}),meta:{origin:"throw",thrown:g},...n&&{metadata:n}}),p?.(ne,i,v),U(ne,{origin:"throw",thrown:g})}}let q=X,ie=performance.now()-x,le=Y(q.error,{origin:"result",resultCause:q.cause});throw c({type:"step_error",workflowId:a,stepId:A,stepKey:E,name:i,description:w,ts:Date.now(),durationMs:ie,error:le,...n&&{metadata:n},diagnostics:V(q.error,s.errorMeta,"result",h.attempts,ie)}),y&&c({type:"step_complete",workflowId:a,stepKey:y,name:i,description:w,ts:Date.now(),durationMs:ie,result:q,meta:{origin:"result",resultCause:q.cause},...n&&{metadata:n}}),p?.(le,i,v),U(le,{origin:"result",resultCause:q.cause})})();d.try=(u,m,o)=>{if(typeof u!="string"||u.length===0)throw new Error('[awaitly] step.try() requires an explicit string ID as the first argument. Example: step.try("parse", () => JSON.parse(str), { error: "PARSE_ERROR" })');let s="error"in o?()=>o.error:o.onError;if(o.retry||o.timeout)return d.retry(u,async()=>{try{return I(await m())}catch(w){return P(s(w),{cause:w})}},{attempts:o.retry?.attempts??1,...o.retry??{},key:o.key,timeout:o.timeout});let n=o.key??u,i=u,E=u,y=f;return(async()=>{let w=y?performance.now():0;f&&c({type:"step_start",workflowId:a,stepId:E,stepKey:n,name:i,ts:Date.now()});try{let k=await m(),R=performance.now()-w;return c({type:"step_success",workflowId:a,stepId:E,stepKey:n,name:i,ts:Date.now(),durationMs:R}),n&&c({type:"step_complete",workflowId:a,stepKey:n,name:i,ts:Date.now(),durationMs:R,result:I(k)}),k}catch(k){let R=s(k),A=performance.now()-w,M=Y(R,{origin:"throw",thrown:k});throw c({type:"step_error",workflowId:a,stepId:E,stepKey:n,name:i,ts:Date.now(),durationMs:A,error:M}),n&&c({type:"step_complete",workflowId:a,stepKey:n,name:i,ts:Date.now(),durationMs:A,result:P(R,{cause:k}),meta:{origin:"throw",thrown:k}}),p?.(M,i,v),U(M,{origin:"throw",thrown:k})}})()},d.fromResult=(u,m,o)=>{if(typeof u!="string"||u.length===0)throw new Error('[awaitly] step.fromResult() requires an explicit string ID as the first argument. Example: step.fromResult("callProvider", () => callProvider(input), { onError: (e) => ({ type: "FAILED" }) })');let s=o.key??u,n=u,i=u,E="error"in o?()=>o.error:o.onError,y=f;return(async()=>{let w=y?performance.now():0;f&&c({type:"step_start",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now()});let k=await m();if(k.ok){let R=performance.now()-w;return c({type:"step_success",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:R}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:n,ts:Date.now(),durationMs:R,result:I(k.value)}),k.value}else{let R=E(k.error),A=performance.now()-w,M=Y(R,{origin:"result",resultCause:k.error});throw c({type:"step_error",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:A,error:M}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:n,ts:Date.now(),durationMs:A,result:P(R,{cause:k.error}),meta:{origin:"result",resultCause:k.error}}),p?.(M,n,v),U(M,{origin:"result",resultCause:k.error})}})()},d.fromNullable=(u,m,o,s)=>{if(typeof u!="string"||u.length===0)throw new Error('[awaitly] step.fromNullable() requires an explicit string ID as the first argument. Example: step.fromNullable("getUser", () => db.find(id), () => ({ type: "NOT_FOUND" }))');return d(u,async()=>{let n=await m();return n!=null?I(n):P(o())},s)},d.retry=(u,m,o)=>{if(typeof u!="string"||u.length===0)throw new Error('[awaitly] step.retry() requires an explicit string ID as the first argument. Example: step.retry("fetchData", () => fetchData(), { attempts: 3 })');return d(u,m,{key:o.key??u,retry:{attempts:o.attempts,backoff:o.backoff,initialDelay:o.initialDelay,maxDelay:o.maxDelay,jitter:o.jitter,shouldRetry:o.shouldRetry,onRetry:o.onRetry},timeout:o.timeout})},d.withTimeout=(u,m,o)=>{if(typeof u!="string"||u.length===0)throw new Error('[awaitly] step.withTimeout() requires an explicit string ID as the first argument. Example: step.withTimeout("slowOp", () => slowOp(), { ms: 5000 })');return d(u,m,{key:o.key??u,timeout:o})},d.sleep=(u,m,o)=>{if(typeof u!="string"||u.length===0)throw new Error('[awaitly] step.sleep() requires an explicit string ID as the first argument. Example: step.sleep("delay", "5s")');let s=typeof m=="string"?at(m):m;if(!s)throw new Error(`step.sleep: invalid duration '${m}'`);let n=s.millis,i=o?.signal;return d(u,async()=>{if(N?.aborted||i?.aborted){let E=new Error("Sleep aborted");throw E.name="AbortError",E}return new Promise((E,y)=>{let w={timeoutId:void 0},k=()=>{w.timeoutId&&clearTimeout(w.timeoutId);let R=new Error("Sleep aborted");R.name="AbortError",y(R)};N?.addEventListener("abort",k,{once:!0}),i?.addEventListener("abort",k,{once:!0}),w.timeoutId=setTimeout(()=>{N?.removeEventListener("abort",k),i?.removeEventListener("abort",k),E(I(void 0))},n)})},{key:o?.key??u,description:o?.description})},d.all=((...u)=>{if(typeof u[0]!="string")throw new TypeError("step.all(name, ...): first argument must be a string (step name). Example: step.all('Fetch data', { user: () => fetchUser(), posts: () => fetchPosts() })");let m=u[0],o=u[1];if(typeof o=="function")return W(m,o);if(o&&typeof o=="object"&&!Array.isArray(o)){let n=B(o);return G(n,{name:m})}throw new TypeError("step.all(name, ...): second argument must be a function (array form) or an object of operations (object form).")}),d.race=(u,m)=>{let o=`scope_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return(async()=>{let s=performance.now(),n=!1,i={scopeId:o,type:"race",winnerId:void 0};L.push(i);let E=()=>{if(n)return;n=!0;let y=L.findIndex(w=>w.scopeId===o);y!==-1&&L.splice(y,1),c({type:"scope_end",workflowId:a,scopeId:o,ts:Date.now(),durationMs:performance.now()-s,winnerId:i.winnerId})};c({type:"scope_start",workflowId:a,scopeId:o,scopeType:"race",name:u,ts:Date.now()});try{let y=await m();if(E(),!y.ok)throw p?.(y.error,u,v),U(y.error,{origin:"result",resultCause:y.cause});return y.value}catch(y){throw E(),y}})()},d.if=(u,m,o)=>o(),d.label=d.if,d.branch=async(u,m)=>{let{condition:o,then:s,else:n}=m;if(o())return await s();if(n)return await n()},d.arm=(u,m)=>({fn:u,errors:m}),d.forEach=async(u,m,o)=>{let s=[],n=o.maxIterations,i=0,E="run"in o,y=Symbol.asyncIterator in m?m:(async function*(){yield*m})();for await(let w of y){if(n!==void 0&&i>=n)break;let k;E?k=await o.run(w,i):k=await o.item.handler(w,i,d),s.push(k),i++}return s},d.item=u=>({__forEachItemHandler:!0,handler:u}),d.dep=(u,m)=>m,d.workflow=(u,m,o)=>d(u,m,o),d.map=async(u,m,o,s)=>{let n=s?.concurrency??m.length;return d(u,()=>n>=m.length?Te(m.map((i,E)=>o(i,E))):(async()=>{let i=[];for(let E=0;E<m.length;E+=n){let y=m.slice(E,E+n),w=await Te(y.map((k,R)=>o(k,E+R)));if(!w.ok)return w;i.push(...w.value)}return I(i)})(),{key:s?.key})},d.withFallback=(u,m,o)=>{if(typeof u!="string"||u.length===0)throw new Error('[awaitly] step.withFallback() requires an explicit string ID as the first argument. Example: step.withFallback("getUser", () => fetchUser(id), { fallback: () => fetchFromCache(id) })');let s=o.key??u,n=u,i=re(s),E=f;return(async()=>{let y=E?performance.now():0;f&&c({type:"step_start",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now()});let w;try{w=await m()}catch(x){if(J(x))throw c({type:"step_aborted",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:performance.now()-y}),x;let _;try{_=F(x)}catch(b){throw Q(b)}if(o.on!==void 0&&o.on!==_){let b=performance.now()-y;throw c({type:"step_error",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:b,error:_}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:n,ts:Date.now(),durationMs:b,result:P(_,{cause:x}),meta:{origin:"throw",thrown:x}}),p?.(_,n,v),U(_,{origin:"throw",thrown:x})}let C;try{C=await o.fallback()}catch(b){if(J(b))throw c({type:"step_aborted",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:performance.now()-y}),b;let h;try{h=F(b)}catch(q){throw Q(q)}let X=performance.now()-y;throw c({type:"step_error",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:X,error:h}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:n,ts:Date.now(),durationMs:X,result:P(h,{cause:b}),meta:{origin:"throw",thrown:b}}),p?.(h,n,v),U(h,{origin:"throw",thrown:b})}if(C.ok){let b=performance.now()-y;return c({type:"step_success",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:b}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:n,ts:Date.now(),durationMs:b,result:C,meta:{origin:"fallback",fallbackUsed:!0,fallbackReason:String(_)}}),C.value}else{let b=performance.now()-y,h=Y(C.error,{origin:"result",resultCause:C.cause});throw c({type:"step_error",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:b,error:h}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:n,ts:Date.now(),durationMs:b,result:C,meta:{origin:"result",resultCause:C.cause}}),p?.(h,n,v),U(h,{origin:"result",resultCause:C.cause})}}if(w.ok){let x=performance.now()-y;return c({type:"step_success",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:x}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:n,ts:Date.now(),durationMs:x,result:w}),w.value}let k=w.error;if(o.on!==void 0&&o.on!==k){let x=performance.now()-y,_=Y(k,{origin:"result",resultCause:w.cause});throw c({type:"step_error",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:x,error:_}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:n,ts:Date.now(),durationMs:x,result:w,meta:{origin:"result",resultCause:w.cause}}),p?.(_,n,v),U(_,{origin:"result",resultCause:w.cause})}let R;try{R=await o.fallback()}catch(x){if(J(x))throw c({type:"step_aborted",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:performance.now()-y}),x;let _;try{_=F(x)}catch(b){throw Q(b)}let C=performance.now()-y;throw c({type:"step_error",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:C,error:_}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:n,ts:Date.now(),durationMs:C,result:P(_,{cause:x}),meta:{origin:"throw",thrown:x}}),p?.(_,n,v),U(_,{origin:"throw",thrown:x})}if(R.ok){let x=performance.now()-y;return c({type:"step_success",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:x}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:n,ts:Date.now(),durationMs:x,result:R,meta:{origin:"fallback",fallbackUsed:!0,fallbackReason:String(k)}}),R.value}let A=performance.now()-y,M=Y(R.error,{origin:"result",resultCause:R.cause});throw c({type:"step_error",workflowId:a,stepId:i,stepKey:s,name:n,ts:Date.now(),durationMs:A,error:M}),s&&c({type:"step_complete",workflowId:a,stepKey:s,name:n,ts:Date.now(),durationMs:A,result:R,meta:{origin:"result",resultCause:R.cause}}),p?.(M,n,v),U(M,{origin:"result",resultCause:R.cause})})()},d.withResource=(u,m)=>{if(typeof u!="string"||u.length===0)throw new Error('[awaitly] step.withResource() requires an explicit string ID as the first argument. Example: step.withResource("useDb", { acquire: () => connect(), use: (db) => query(db), release: (db) => db.close() })');let o=u,s=u,n=re(o),i=f;return(async()=>{let E=i?performance.now():0;f&&c({type:"step_start",workflowId:a,stepId:n,stepKey:o,name:s,ts:Date.now()});let y;try{y=await m.acquire()}catch(C){if(J(C))throw c({type:"step_aborted",workflowId:a,stepId:n,stepKey:o,name:s,ts:Date.now(),durationMs:performance.now()-E}),C;let b;try{b=F(C)}catch(X){throw Q(X)}let h=performance.now()-E;throw c({type:"step_error",workflowId:a,stepId:n,stepKey:o,name:s,ts:Date.now(),durationMs:h,error:b}),o&&c({type:"step_complete",workflowId:a,stepKey:o,name:s,ts:Date.now(),durationMs:h,result:P(b,{cause:C}),meta:{origin:"throw",thrown:C}}),p?.(b,s,v),U(b,{origin:"throw",thrown:C})}if(!y.ok){let C=performance.now()-E,b=Y(y.error,{origin:"result",resultCause:y.cause});throw c({type:"step_error",workflowId:a,stepId:n,stepKey:o,name:s,ts:Date.now(),durationMs:C,error:b}),o&&c({type:"step_complete",workflowId:a,stepKey:o,name:s,ts:Date.now(),durationMs:C,result:y,meta:{origin:"result",resultCause:y.cause}}),p?.(b,s,v),U(b,{origin:"result",resultCause:y.cause})}let w=y.value,k,R,A=!1;try{k=await m.use(w)}catch(C){if(J(C)){try{await m.release(w)}catch(b){console.warn(`[awaitly] step.withResource("${u}"): release threw after earlyExit:`,b)}throw C}R=C,A=!0}try{await m.release(w)}catch(C){console.warn(`[awaitly] step.withResource("${u}"): release threw:`,C)}if(A){let C;try{C=F(R)}catch(h){throw Q(h)}let b=performance.now()-E;throw c({type:"step_error",workflowId:a,stepId:n,stepKey:o,name:s,ts:Date.now(),durationMs:b,error:C}),o&&c({type:"step_complete",workflowId:a,stepKey:o,name:s,ts:Date.now(),durationMs:b,result:P(C,{cause:R}),meta:{origin:"throw",thrown:R}}),p?.(C,s,v),U(C,{origin:"throw",thrown:R})}let M=k;if(M.ok){let C=performance.now()-E;return c({type:"step_success",workflowId:a,stepId:n,stepKey:o,name:s,ts:Date.now(),durationMs:C}),o&&c({type:"step_complete",workflowId:a,stepKey:o,name:s,ts:Date.now(),durationMs:C,result:M}),M.value}let x=performance.now()-E,_=Y(M.error,{origin:"result",resultCause:M.cause});throw c({type:"step_error",workflowId:a,stepId:n,stepKey:o,name:s,ts:Date.now(),durationMs:x,error:_}),o&&c({type:"step_complete",workflowId:a,stepKey:o,name:s,ts:Date.now(),durationMs:x,result:M,meta:{origin:"result",resultCause:M.cause}}),p?.(_,s,v),U(_,{origin:"result",resultCause:M.cause})})()};let H=await l({step:d});if(process.env.NODE_ENV!=="production"&&H!==null&&typeof H=="object"&&"ok"in H&&typeof H.ok=="boolean"){let u=H;(u.ok===!0&&"value"in u||u.ok===!1&&"error"in u)&&console.warn(`awaitly: Workflow executor returned a Result-like object. Return raw values, not ok() or err().
2
-
3
- Incorrect: return ok({ data });
4
- Correct: return { data };
5
-
6
- See: https://jagreehal.github.io/awaitly/guides/troubleshooting/#returning-ok-from-workflow-executor-double-wrapping`)}return I(H)}catch(d){if(Tt(d))throw d.thrown;if(J(d)){let W=d.meta.origin==="throw"?d.meta.thrown:d.meta.origin==="result"?d.meta.resultCause:void 0;return P(d.error,{cause:W})}let B=F(d);return p?.(B,"unexpected",v),P(B,{cause:d})}}fe.strict=(e,t)=>fe(e,t);var ue=class extends Error{constructor(r,l){super(`Unwrap called on an error result: ${String(r)}`);this.error=r;this.cause=l;this.name="UnwrapError"}error;cause},ke=e=>{if(e.ok)return e.value;throw new ue(e.error,e.cause)},Rt=(e,t)=>e.ok?e.value:t,xt=(e,t)=>e.ok?e.value:t(e.error,e.cause),Ct=e=>ke(e),ht=e=>Promise.resolve(e).then(ke),bt=e=>e.ok?e.value:null,At=e=>e.ok?e.value:void 0;function St(e,t){try{return I(e())}catch(r){return t?P(t(r),{cause:r}):P(r)}}async function Ot(e,t){try{return I(await e)}catch(r){return t?P(t(r),{cause:r}):P(r)}}async function Pt(e,t){try{return I(await e())}catch(r){return t?P(t(r),{cause:r}):P(r)}}function vt(e,t){return e!=null?I(e):P(t())}function _t(e,t){return e.ok?I(t(e.value)):e}function Mt(e,t){return e.ok?e:P(t(e.error),{cause:e.cause})}function Ve(e,t){if(t===void 0){let r=e;return l=>Ve(l,r)}return e.ok?t.ok(e.value):t.err(e.error,e.cause)}function It(e,t){return e.ok?t(e.value):e}function Dt(e,t){return e.ok&&t(e.value),e}function Ut(e,t){return e.ok||t(e.error,e.cause),e}function Nt(e,t,r){if(!e.ok)return e;try{return I(t(e.value))}catch(l){return P(r(l),{cause:l})}}function Kt(e,t,r){if(e.ok)return e;try{return P(t(e.error),{cause:e.cause})}catch(l){return P(r(l),{cause:l})}}function jt(e,t,r){return e.ok?I(t(e.value)):P(r(e.error),{cause:e.cause})}function Ft(e,t){return e.ok?e:t(e.error,e.cause)}async function Bt(e,t){let r=await e;return r.ok?r:t(r.error,r.cause)}function Lt(e,t){return e.ok?I(e.value):I(t(e.error,e.cause))}async function Vt(e,t){let r=await e;return r.ok?I(r.value):I(await t(r.error,r.cause))}function He(e){return e!==null&&typeof e=="object"&&"ok"in e&&typeof e.ok=="boolean"&&(e.ok===!0&&"value"in e||e.ok===!1&&"error"in e)?e:null}function Ht(e){return He(e)!==null}function Wt(e){let t=[];for(let r of e){if(!r.ok)return r;t.push(r.value)}return I(t)}async function Te(e){return e.length===0?I([]):new Promise(t=>{let r=!1,l=e.length,T=new Array(e.length);for(let p=0;p<e.length;p++){let f=p;Promise.resolve(e[f]).catch(S=>P({type:"PROMISE_REJECTED",cause:S},{cause:{type:"PROMISE_REJECTION",reason:S}})).then(S=>{if(!r){if(!S.ok){r=!0,t(S);return}T[f]=S.value,l--,l===0&&t(I(T))}})}})}function $t(e){let t=[],r=[];for(let l of e)l.ok?t.push(l.value):r.push({error:l.error,cause:l.cause});return r.length>0?P(r):I(t)}function Yt(e){let t=[],r=[];for(let l of e)l.ok?t.push(l.value):r.push(l.error);return{values:t,errors:r}}function qt(e){if(e.length===0)return P({type:"EMPTY_INPUT",message:"any() requires at least one Result"});let t=null;for(let r of e){if(r.ok)return r;t||(t=r)}return t}async function zt(e){return e.length===0?P({type:"EMPTY_INPUT",message:"anyAsync() requires at least one Result"}):new Promise(t=>{let r=!1,l=e.length,T=null;for(let p of e)Promise.resolve(p).catch(f=>P({type:"PROMISE_REJECTED",cause:f},{cause:{type:"PROMISE_REJECTION",reason:f}})).then(f=>{if(!r){if(f.ok){r=!0,t(f);return}T||(T=f),l--,l===0&&t(T)}})})}async function Jt(e){let t=await Promise.all(e.map(T=>Promise.resolve(T).then(p=>({status:"result",result:p})).catch(p=>({status:"rejected",error:{type:"PROMISE_REJECTED",cause:p},cause:{type:"PROMISE_REJECTION",reason:p}})))),r=[],l=[];for(let T of t)T.status==="rejected"?l.push({error:T.error,cause:T.cause}):T.result.ok?r.push(T.result.value):l.push({error:T.result.error,cause:T.result.cause});return l.length>0?P(l):I(r)}function We(e,t){return r=>{let l=new Map(r.handlers);return l.set(e,t),{_tag:"Matcher",value:r.value,handlers:l,_remaining:void 0,_output:void 0}}}function $e(e){return t=>{let r=new Map(t.handlers);for(let[l,T]of Object.entries(e))T&&r.set(l,T);return{_tag:"Matcher",value:t.value,handlers:r,_remaining:void 0,_output:void 0}}}function Ye(e){let t=e.handlers.get(e.value._tag);if(!t)throw new Error(`No handler for tag: ${e.value._tag}`);return t(e.value)}function ge(e){return t=>{let r=t.handlers.get(t.value._tag);return r?r(t.value):e(t.value)}}function qe(e){return ge(()=>e)}function ze(e,t,r){return l=>{let T=new Map(l.handlers),p=l.handlers.get(e);return T.set(e,f=>{let S=f;if(t(S))return r(S);if(p)return p(f);throw new Error(`No handler matched for tag: ${e}`)}),{_tag:"Matcher",value:l.value,handlers:T,_remaining:l._remaining,_output:void 0}}}function Je(e){return t=>t._tag===e}function Ge(...e){let t=new Set(e);return r=>t.has(r._tag)}function Gt(e){return typeof e=="object"&&e!==null&&"_tag"in e&&e._tag==="Matcher"}function Xe(e){return{...e,pipe(t){let r=t(e);return Gt(r)?Xe(r):r}}}function Ze(e){return Xe({_tag:"Matcher",value:e,handlers:new Map,_remaining:e,_output:void 0})}var Xt={value:Ze,tag:We,tags:$e,when:ze,exhaustive:Ye,orElse:ge,orElseValue:qe,is:Je,isOneOf:Ge};export{ot as ALL_SLUGS,lt as AWAITLY_CANCELLED,de as AWAITLY_SLUGS,ct as AWAITLY_TIMEOUT,it as AWAITLY_UNEXPECTED,Xt as Match,ut as PROMISE_REJECTED,K as TaggedError,Z as UnexpectedError,ue as UnwrapError,Wt as all,Te as allAsync,$t as allSettled,Jt as allSettledAsync,It as andThen,qt as any,zt as anyAsync,jt as bimap,P as err,Ye as exhaustive,Ke as extractErrorTag,Fe as extractStepMetadata,St as from,vt as fromNullable,Ot as fromPromise,He as hydrate,nt as isAwaitlySlug,mt as isErr,dt as isOk,Ge as isOneOf,Ht as isSerializedResult,Je as isTag,Ue as isUnexpectedError,je as lookupErrorClassification,_t as map,Mt as mapError,Kt as mapErrorTry,Nt as mapTry,Ve as match,Ne as matchError,ge as matchOrElse,We as matchTag,$e as matchTags,Ze as matchValue,ze as matchWhen,I as ok,Ft as orElse,Bt as orElseAsync,qe as orElseValue,Yt as partition,Lt as recover,Vt as recoverAsync,bt as runOrNull,Ct as runOrThrow,ht as runOrThrowAsync,At as runOrUndefined,rt as slugCategory,me as slugDocsUrl,pt as tags,Dt as tap,Ut as tapError,Pt as tryAsync,ke as unwrap,Rt as unwrapOr,xt as unwrapOrElse};
7
- //# sourceMappingURL=core.js.map