@distilled.cloud/core 1.0.0-rc.20 → 1.0.0-rc.21
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.
- package/README.md +33 -0
- package/lib/_bundle/aws.js +1 -1
- package/lib/_bundle/aws.js.map +1 -1
- package/lib/_bundle/base.js +2 -2
- package/lib/_bundle/base.js.map +1 -1
- package/lib/_bundle/graphql.js +2 -2
- package/lib/_bundle/graphql.js.map +1 -1
- package/lib/_bundle/grpc.js +2 -1
- package/lib/_bundle/grpc.js.map +1 -1
- package/lib/_bundle/rest.js +1 -1
- package/lib/_bundle/rest.js.map +1 -1
- package/lib/annotations.d.ts.map +1 -1
- package/lib/api.d.ts +71 -58
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -1
- package/lib/category.d.ts +15 -12
- package/lib/category.d.ts.map +1 -1
- package/lib/chunks.d.ts.map +1 -1
- package/lib/config.d.ts +13 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/crypto.d.ts.map +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/errors.d.ts +35 -2
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -1
- package/lib/graphql.d.ts +21 -4
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.types.d.ts +0 -1
- package/lib/graphql.types.d.ts.map +1 -1
- package/lib/grpc-transport-cloudflare-http2.d.ts.map +1 -1
- package/lib/grpc-transport-cloudflare-http2.js +2 -2
- package/lib/grpc-transport-cloudflare-http2.js.map +1 -1
- package/lib/grpc-transport-cloudflare-sockets.d.ts.map +1 -1
- package/lib/grpc-transport-cloudflare-sockets.js +4 -4
- package/lib/grpc-transport-cloudflare-sockets.js.map +1 -1
- package/lib/grpc-transport-node-http2.d.ts.map +1 -1
- package/lib/grpc-transport-node-http2.js +1 -1
- package/lib/grpc-transport-node-http2.js.map +1 -1
- package/lib/grpc-transport.d.ts +53 -18
- package/lib/grpc-transport.d.ts.map +1 -1
- package/lib/grpc-transport.js +1 -1
- package/lib/hpack.d.ts.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/max-message-bytes.d.ts +42 -0
- package/lib/max-message-bytes.d.ts.map +1 -0
- package/lib/max-message-bytes.js +2 -0
- package/lib/max-message-bytes.js.map +1 -0
- package/lib/ndjson.d.ts +3 -0
- package/lib/ndjson.d.ts.map +1 -0
- package/lib/ndjson.js +2 -0
- package/lib/ndjson.js.map +1 -0
- package/lib/pagination.d.ts +4 -1
- package/lib/pagination.d.ts.map +1 -1
- package/lib/plain-values.d.ts +11 -0
- package/lib/plain-values.d.ts.map +1 -1
- package/lib/plain-values.js +1 -1
- package/lib/plain-values.js.map +1 -1
- package/lib/protobuf.d.ts +12 -19
- package/lib/protobuf.d.ts.map +1 -1
- package/lib/protobuf.js +1 -1
- package/lib/protocol-grpc.d.ts +47 -10
- package/lib/protocol-grpc.d.ts.map +1 -1
- package/lib/protocol-grpc.js +1 -1
- package/lib/protocol-http.d.ts +110 -8
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +1 -1
- package/lib/protocol-rest.d.ts +161 -37
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +1 -1
- package/lib/protocol.d.ts +113 -0
- package/lib/protocol.d.ts.map +1 -0
- package/lib/protocol.js +0 -0
- package/lib/query.d.ts.map +1 -1
- package/lib/response-validation-strict.d.ts.map +1 -1
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/retry-after.d.ts +1 -1
- package/lib/retry-after.d.ts.map +1 -1
- package/lib/retry-state.d.ts +26 -0
- package/lib/retry-state.d.ts.map +1 -0
- package/lib/retry-state.js +2 -0
- package/lib/retry-state.js.map +1 -0
- package/lib/retry.d.ts +100 -20
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -1
- package/lib/schema-lite-impl.d.ts +25 -4
- package/lib/schema-lite-impl.d.ts.map +1 -1
- package/lib/schema-lite-impl.js +1 -1
- package/lib/schema-lite-typed.d.ts.map +1 -1
- package/lib/schema-lite.d.ts +1 -0
- package/lib/schema-lite.d.ts.map +1 -1
- package/lib/schema-lite.js +1 -1
- package/lib/schema.d.ts.map +1 -1
- package/lib/sdk-error.d.ts +4 -0
- package/lib/sdk-error.d.ts.map +1 -1
- package/lib/send.d.ts +37 -0
- package/lib/send.d.ts.map +1 -0
- package/lib/send.js +2 -0
- package/lib/send.js.map +1 -0
- package/lib/sensitive.d.ts.map +1 -1
- package/lib/sensitive.js +1 -1
- package/lib/sensitive.js.map +1 -1
- package/lib/telemetry-debug.d.ts.map +1 -1
- package/lib/telemetry-debug.js +1 -1
- package/lib/telemetry-debug.js.map +1 -1
- package/lib/telemetry-hooks.d.ts.map +1 -1
- package/lib/telemetry-host-rules.d.ts.map +1 -1
- package/lib/telemetry-lambda-context.d.ts.map +1 -1
- package/lib/telemetry-message-context.d.ts.map +1 -1
- package/lib/telemetry-metrics.d.ts.map +1 -1
- package/lib/telemetry-metrics.js +1 -1
- package/lib/telemetry-metrics.js.map +1 -1
- package/lib/telemetry-name-template.d.ts.map +1 -1
- package/lib/telemetry-stream.d.ts.map +1 -1
- package/lib/telemetry-stream.js +1 -1
- package/lib/telemetry-stream.js.map +1 -1
- package/lib/telemetry-xray.d.ts.map +1 -1
- package/lib/telemetry.d.ts +29 -0
- package/lib/telemetry.d.ts.map +1 -1
- package/lib/telemetry.js +2 -2
- package/lib/telemetry.js.map +1 -1
- package/lib/token-cache.d.ts +31 -0
- package/lib/token-cache.d.ts.map +1 -0
- package/lib/token-cache.js +2 -0
- package/lib/token-cache.js.map +1 -0
- package/lib/trait.d.ts +24 -1
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +1 -1
- package/lib/unknown-error.d.ts.map +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/api.ts +402 -209
- package/src/category.ts +21 -28
- package/src/config.ts +17 -1
- package/src/errors.ts +24 -2
- package/src/graphql.ts +65 -26
- package/src/graphql.types.ts +15 -0
- package/src/grpc-transport-cloudflare-http2.ts +374 -299
- package/src/grpc-transport-cloudflare-sockets.ts +150 -81
- package/src/grpc-transport-node-http2.ts +119 -46
- package/src/grpc-transport.ts +211 -42
- package/src/max-message-bytes.ts +58 -0
- package/src/ndjson.ts +55 -0
- package/src/pagination.ts +26 -15
- package/src/plain-values.ts +30 -1
- package/src/protobuf.ts +40 -5
- package/src/protocol-grpc.ts +518 -348
- package/src/protocol-http.ts +474 -100
- package/src/protocol-rest.ts +580 -140
- package/src/protocol.ts +150 -0
- package/src/response-validation-strict.ts +9 -3
- package/src/retry-after.ts +1 -1
- package/src/retry-state.ts +105 -0
- package/src/retry.ts +176 -47
- package/src/schema-lite-impl.ts +81 -10
- package/src/schema-lite.ts +1 -0
- package/src/sdk-error.ts +4 -0
- package/src/send.ts +156 -0
- package/src/sensitive.ts +49 -15
- package/src/telemetry.ts +2 -34
- package/src/token-cache.ts +117 -0
- package/src/trait.ts +34 -1
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @distilled.cloud/core
|
|
2
|
+
|
|
3
|
+
The shared runtime behind every [distilled](https://distilled.cloud) SDK. It
|
|
4
|
+
sends the requests, decodes the responses, retries, paginates and turns
|
|
5
|
+
provider errors into typed Effect failures.
|
|
6
|
+
|
|
7
|
+
You do not need to install it yourself. Each SDK, for example
|
|
8
|
+
`@distilled.cloud/aws` or `@distilled.cloud/cloudflare`, depends on it. To get
|
|
9
|
+
started, read the [root README](https://github.com/alchemy-run/distilled#readme)
|
|
10
|
+
and the README of the SDK you use.
|
|
11
|
+
|
|
12
|
+
## What it holds
|
|
13
|
+
|
|
14
|
+
Each module is its own import path, `@distilled.cloud/core/<module>`.
|
|
15
|
+
|
|
16
|
+
| Module | What it does |
|
|
17
|
+
|---|---|
|
|
18
|
+
| `retry` | Retry policies and backoff. Each SDK re-exports them as its own `Retry` |
|
|
19
|
+
| `category` | Error categories (`AuthError`, `ThrottlingError`, `NotFoundError` and the rest) with `is*` and `catch*` helpers |
|
|
20
|
+
| `errors` | Shared HTTP errors such as `Unauthorized`, `NotFound` and `TooManyRequests` |
|
|
21
|
+
| `sdk-error` | `SdkError`, the failure for a call this SDK cannot make |
|
|
22
|
+
| `sensitive` | Redaction of fields the spec marks as secrets |
|
|
23
|
+
| `pagination` | Paginated operations as a `Stream` |
|
|
24
|
+
| `telemetry`, `telemetry-metrics` | A span for each call, and opt-in call metrics |
|
|
25
|
+
| `crypto` | HMAC and hashing for request signing |
|
|
26
|
+
| `protocol-rest`, `protocol-http`, `protocol-grpc`, `xml`, `query`, `protobuf`, `graphql` | The wire protocols the generated SDKs use |
|
|
27
|
+
|
|
28
|
+
The generated SDKs call these modules. Most programs use them only through an
|
|
29
|
+
SDK.
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
[Apache-2.0](https://github.com/alchemy-run/distilled/blob/main/LICENSE)
|
package/lib/_bundle/aws.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as e from"effect/Context";import*as t from"effect/Effect";import
|
|
1
|
+
import*as e from"effect/Context";import*as t from"effect/Effect";import{pipeArguments as n}from"effect/Pipeable";import*as r from"effect/Schema";import{Duration as i,Redacted as a,declare as o,instanceOf as s}from"effect/Schema";import*as c from"effect/Data";import*as l from"effect/Layer";const u=r.optional;const d=r.Struct;const f=r.StructWithRest;const suspend=e=>lazySuspend(e);const Array$1=e=>lazyArray(e);const Record=(e,t)=>lazyRecord(e,t);const p=r.Union;const m=r.Literal;const h=r.Literals;const g=r.NullOr;const _=r.Tuple;const v=r.encodeKeys;const y=r.String;const b=r.Number;const x=r.Boolean;const S=r.Date;const C=r.Unknown;const w=r.Null;const T=r.Void;const E=r.Any;const D=/*@__PURE__*/ Object.getPrototypeOf(r.String);const O=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/schema/build`);const k=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/schema/annotations`);const A=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/schema/data`);const force=e=>{const t=e[O];if(!t)return;const n=e[k];const r=typeof t===`function`?t():t.build(e[A]);const i=n?r.annotate(n):r;delete e[O];delete e[A];delete e[k];Object.defineProperties(e,Object.getOwnPropertyDescriptors(i))};const forwarded=e=>({configurable:true,get(){if(!this[O])return void 0;force(this);return this[e]}});const j=/*@__PURE__*/ Object.create(D,{ast:/*@__PURE__*/ forwarded(`ast`),value:/*@__PURE__*/ forwarded(`value`),key:/*@__PURE__*/ forwarded(`key`),annotate:{configurable:true,writable:true,value(e){const t=this[O];if(!t)return D.annotate.call(this,e);const n=this[k];return lazy(t,n?{...n,...e}:e,this[A])}}});const M=D[`~effect/Schema/Schema`]!==void 0;const lazy=(e,t,n)=>{if(!M){const r=typeof e===`function`?e():e.build(n);return t?r.annotate(t):r}const r=Object.create(j);r[O]=e;if(n!==void 0)r[A]=n;if(t)r[k]=t;return r};const lazyFrom=(e,t)=>lazy(e,void 0,t);const lazySuspend=e=>lazy(()=>r.suspend(e));const lazyArray=e=>lazy(()=>r.Array(e));const lazyRecord=(e,t)=>lazy(()=>r.Record(e,t));const N=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/schema/lazyError`);const P=`~effect/Schema/Schema`;let F;const ErrorBase=()=>F??=Object.getPrototypeOf(r.TaggedError()(`Probe`,{}));const realErrorClass=e=>{const t=e[N];if(!t.real){const e=r.TaggedError(t.identifier)(...t.args);t.real=e;Object.setPrototypeOf(t.lazy.prototype,e.prototype)}return t.real};const I=[`ast`,`fields`,`make`,`makeOption`,`makeEffect`,`annotate`,`annotateKey`,`check`,`rebuild`,`extend`,`mapFields`];let L;const LazyErrorStatics=()=>L??=Object.create(ErrorBase(),{[P]:{value:P,configurable:true},identifier:{configurable:true,get(){const e=this[N];return e.identifier??e.args[0]}},pipe:{configurable:true,writable:true,value(){return n(this,arguments)}},...Object.fromEntries(I.map(e=>[e,{configurable:true,get(){let t=realErrorClass(this);let n;while(t&&!(n=Object.getOwnPropertyDescriptor(t,e)))t=Object.getPrototypeOf(t);if(!n)return void 0;if(n.get)return n.get.call(this);return typeof n.value===`function`?n.value.bind(this):n.value}}]))});const lazyTaggedError=e=>(...t)=>{function LazyTaggedError(e,t){if(!new.target)throw new TypeError(`Class constructor cannot be invoked without 'new'`);return Reflect.construct(realErrorClass(new.target),[e,t],new.target)}Object.setPrototypeOf(LazyTaggedError,LazyErrorStatics());LazyTaggedError.prototype=Object.create(ErrorBase().prototype,{constructor:{value:LazyTaggedError,writable:true,configurable:true}});Object.defineProperty(LazyTaggedError,N,{value:{identifier:e,args:t,lazy:LazyTaggedError}});return LazyTaggedError};const R=lazyTaggedError;const z=/*@__PURE__*/ new WeakMap;const at=(e,t)=>{let n=z.get(e);if(!n)z.set(e,n={build:t=>e(t)});return lazyFrom(n,t)};var CryptoError=class extends (/*@__PURE__*/ c.TaggedError(`CryptoError`)){};const nodeModule=()=>{try{return globalThis.process?.getBuiltinModule?.(`node:crypto`)}catch{return}};const B=/*@__PURE__*/ new TextEncoder;const toBytes=e=>typeof e===`string`?B.encode(e):e;const makeNodeCrypto=()=>{const e=nodeModule();if(!e)return void 0;return{name:`node:crypto`,sync:{sha256:t=>e.createHash(`sha256`).update(t).digest(),importHmacKey:t=>e.createSecretKey(toBytes(t)),hmacSha256:(t,n)=>e.createHmac(`sha256`,t).update(n).digest(),sha256Hex:e.hash?t=>e.hash(`sha256`,t,`hex`):t=>e.createHash(`sha256`).update(t).digest(`hex`),hmacSha256Hex:(t,n)=>e.createHmac(`sha256`,t).update(n).digest(`hex`)},sha256:n=>t.try({try:()=>e.createHash(`sha256`).update(n).digest(),catch:e=>new CryptoError({operation:`sha256`,cause:e})}),importHmacKey:n=>t.try({try:()=>e.createSecretKey(toBytes(n)),catch:e=>new CryptoError({operation:`importKey`,cause:e})}),hmacSha256:(n,r)=>t.try({try:()=>e.createHmac(`sha256`,n).update(r).digest(),catch:e=>new CryptoError({operation:`hmac`,cause:e})})}};const buffer=e=>{const t=toBytes(e);return t.buffer instanceof ArrayBuffer?t:new Uint8Array(t)};const makeWebCrypto=()=>({name:`webcrypto`,sha256:e=>t.tryPromise({try:async()=>new Uint8Array(await crypto.subtle.digest(`SHA-256`,buffer(e))),catch:e=>new CryptoError({operation:`sha256`,cause:e})}),importHmacKey:e=>t.tryPromise({try:()=>crypto.subtle.importKey(`raw`,buffer(e),{name:`HMAC`,hash:`SHA-256`},false,[`sign`]),catch:e=>new CryptoError({operation:`importKey`,cause:e})}),hmacSha256:(e,n)=>t.tryPromise({try:async()=>new Uint8Array(await crypto.subtle.sign(`HMAC`,e,buffer(n))),catch:e=>new CryptoError({operation:`hmac`,cause:e})})});const V=/*@__PURE__*/ e.Reference(`@distilled.cloud/core/Crypto`,{defaultValue:()=>makeNodeCrypto()??makeWebCrypto()});const layer=e=>l.succeed(V,e);const H=/*@__PURE__*/ l.sync(V,makeWebCrypto);const U=/*@__PURE__*/ l.effect(V,/*@__PURE__*/ t.suspend(()=>{const e=makeNodeCrypto();return e?t.succeed(e):t.fail(new CryptoError({operation:`importKey`,cause:`node:crypto is not available`}))}));const W=/*@__PURE__*/ Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));const hex=e=>{let t=``;for(let n=0;n<e.length;n++)t+=W[e[n]];return t};export{at as chunks$at,V as crypto$Crypto,CryptoError as crypto$CryptoError,hex as crypto$hex,layer as crypto$layer,makeNodeCrypto as crypto$makeNodeCrypto,makeWebCrypto as crypto$makeWebCrypto,U as crypto$nodeCrypto,H as crypto$webCrypto,E as schema$Any,Array$1 as schema$Array,x as schema$Boolean,S as schema$Date,i as schema$Duration,m as schema$Literal,h as schema$Literals,w as schema$Null,g as schema$NullOr,b as schema$Number,Record as schema$Record,a as schema$Redacted,y as schema$String,d as schema$Struct,f as schema$StructWithRest,R as schema$TaggedError,_ as schema$Tuple,p as schema$Union,C as schema$Unknown,T as schema$Void,o as schema$declare,v as schema$encodeKeys,s as schema$instanceOf,lazyFrom as schema$lazyFrom,u as schema$optional,suspend as schema$suspend};
|
|
2
2
|
//# sourceMappingURL=aws.js.map
|
package/lib/_bundle/aws.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.js","names":["Array","Context","Effect","
|
|
1
|
+
{"version":3,"file":"aws.js","names":["Array","Context","Effect","S","Data","Layer","optional","Struct","StructWithRest","f","item","key","value","Union","Literal","Literals","NullOr","Tuple","encodeKeys","String","Number","Boolean","Date","Unknown","Null","Void","Any","SchemaProto","buildKey","annotationsKey","dataKey","build","self","annotations","built","real","name","LazyProto","previous","supported","data","builder","lazyErrorKey","SchemaTypeId","errorBase","state","cls","FORWARDED_STATICS","lazyErrorStatics","pipeArguments","owner","descriptor","args","input","options","TaggedError","builders","j","encoder","c","b","Crypto","impl","webCrypto","nodeCrypto","HEX","i","out","bytes","Duration","Redacted","declare","instanceOf"],"sources":["../../src/schema.ts","../../src/chunks.ts","../../src/crypto.ts"],"mappings":"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"}
|
package/lib/_bundle/base.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{getAnn as e,rawResponseRootSymbol as t}from"../annotations.js";import{Debug as n,captureCallSite as r,execute as i,operationInfo as a,operationSpan as o,phase as s,retried as c}from"../telemetry.js";import*as l from"effect/Context";import*as u from"effect/Effect";import*as d from"effect/Exit";import*as f from"effect/http/HttpClient";import*as p from"effect/Layer";import*as m from"effect/Option";import{pipeArguments as h}from"effect/Pipeable";import*as ee from"effect/Ref";import"effect/Schema";import*as te from"effect/Scope";import*as g from"effect/Stream";import{SingleShotGen as ne}from"effect/Utils";import*as re from"effect/http/HttpClientError";import*as _ from"effect/Predicate";import*as ie from"effect/Data";import*as v from"effect/Duration";import"effect/Function";import*as ae from"effect/Schedule";import*as oe from"effect/Redacted";const y=`AuthError`;const b=`BadRequestError`;const x=`ConflictError`;const S=`NotFoundError`;const w=`QuotaError`;const T=`ServerError`;const E=`ThrottlingError`;const D=`NetworkError`;const O=`ParseError`;const k=`ConfigurationError`;const A=`TimeoutError`;const j=`RetryableError`;const M=`LockedError`;const N=`AbortedError`;const P=`AlreadyExistsError`;const F=`DependencyViolationError`;const I=`@distilled.cloud/error/categories`;const se=`@distilled.cloud/error/retryable`;const withCategory=(...e)=>t=>{for(const n of e){if(!(`@distilled.cloud/error/categories`in t.prototype))t.prototype[I]={};t.prototype[I][n]=true}return t};const withRetryable=(e={})=>t=>{t.prototype[se]=e;return t};const ce=/*@__PURE__*/ withCategory(y);const le=/*@__PURE__*/ withCategory(b);const ue=/*@__PURE__*/ withCategory(x);const de=/*@__PURE__*/ withCategory(S);const fe=/*@__PURE__*/ withCategory(w);const pe=/*@__PURE__*/ withCategory(T);const me=/*@__PURE__*/ withCategory(E);const he=/*@__PURE__*/ withCategory(D);const ge=/*@__PURE__*/ withCategory(O);const _e=/*@__PURE__*/ withCategory(k);const ve=/*@__PURE__*/ withCategory(A);const ye=/*@__PURE__*/ withCategory(j);const be=/*@__PURE__*/ withCategory(M);const xe=/*@__PURE__*/ withCategory(N);const Se=/*@__PURE__*/ withCategory(P);const Ce=/*@__PURE__*/ withCategory(F);const hasCategory=(e,t)=>{if(_.isObject(e)&&_.hasProperty(`@distilled.cloud/error/categories`)(e))return t in e[I];return false};const isAuthError=e=>hasCategory(e,y);const isBadRequestError=e=>hasCategory(e,b);const isConflictError=e=>hasCategory(e,x);const isNotFoundError=e=>hasCategory(e,S);const isQuotaError=e=>hasCategory(e,w);const isServerError=e=>hasCategory(e,T);const isThrottlingError=e=>hasCategory(e,E);const isNetworkError=e=>hasCategory(e,D);const isParseError=e=>hasCategory(e,O);const isConfigurationError=e=>hasCategory(e,k);const isTimeoutError=e=>hasCategory(e,A);const isRetryableError=e=>hasCategory(e,j);const isLockedError=e=>hasCategory(e,M);const isAbortedError=e=>hasCategory(e,N);const isAlreadyExistsError=e=>hasCategory(e,P);const isDependencyViolationError=e=>hasCategory(e,F);const isRetryable=e=>{if(_.isObject(e)&&_.hasProperty(`@distilled.cloud/error/retryable`)(e))return true;return false};const isThrottling=e=>{if(_.isObject(e)&&_.hasProperty(`@distilled.cloud/error/retryable`)(e))return e[se]?.throttling===true;return hasCategory(e,E)};const isHttpTransportError=e=>re.isHttpClientError(e)&&e.reason._tag===`TransportError`;const isTransientError=e=>{if(isRetryable(e))return true;return hasCategory(e,`RetryableError`)||hasCategory(e,`ThrottlingError`)||hasCategory(e,`ServerError`)||hasCategory(e,`NetworkError`)||hasCategory(e,`TimeoutError`)||hasCategory(e,`LockedError`)||isHttpTransportError(e)};const makeCatcher=e=>t=>n=>u.catchIf(n,t=>hasCategory(t,e),t);const catchErrors=(...e)=>{const t=e[e.length-1];const n=e.slice(0,-1);return e=>u.catchIf(e,e=>n.some(t=>hasCategory(e,t)),t)};const we=/*@__PURE__*/ makeCatcher(y);const Te=/*@__PURE__*/ makeCatcher(b);const Ee=/*@__PURE__*/ makeCatcher(x);const De=/*@__PURE__*/ makeCatcher(S);const Oe=/*@__PURE__*/ makeCatcher(w);const ke=/*@__PURE__*/ makeCatcher(T);const Ae=/*@__PURE__*/ makeCatcher(E);const je=/*@__PURE__*/ makeCatcher(D);const Me=/*@__PURE__*/ makeCatcher(O);const Ne=/*@__PURE__*/ makeCatcher(k);const Pe=/*@__PURE__*/ makeCatcher(A);const Fe=/*@__PURE__*/ makeCatcher(j);const Ie=/*@__PURE__*/ makeCatcher(M);const Le=/*@__PURE__*/ makeCatcher(N);const Re=/*@__PURE__*/ makeCatcher(P);const ze=/*@__PURE__*/ makeCatcher(F);const catchCategory=(...e)=>{const t=e[e.length-1];const n=e.slice(0,-1);return e=>u.catchIf(e,e=>{if(_.isObject(e)&&_.hasProperty(`@distilled.cloud/error/categories`)(e)){for(const t of n)if(t in e[`@distilled.cloud/error/categories`])return true}return false},e=>t(e))};const Be=`~lite`;const node$1=e=>Object.assign(e,{[Be]:true});const Ve={"~lite":true,pipe(){return h(this,arguments)},annotate(e){return make$1({...this.ast,annotations:{...this.ast.annotations,...e}},this)}};const make$1=(e,t)=>{const n=Object.create(Ve);n.ast=e;if(t){for(const e of[`fields`,`key`,`value`])if(e in t)n[e]=t[e]}return n};const fromNode=e=>make$1(node$1(e));const isLite=e=>(typeof e===`object`||typeof e===`function`)&&e!==null&&e[`~lite`]===true;const astOf=e=>e.ast;const He=/*@__PURE__*/ make$1(node$1({_tag:`String`}));const Ue=/*@__PURE__*/ make$1(node$1({_tag:`Number`}));const We=/*@__PURE__*/ make$1(node$1({_tag:`Boolean`}));const Ge=/*@__PURE__*/ make$1(node$1({_tag:`Unknown`}));const Ke=/*@__PURE__*/ make$1(node$1({_tag:`Any`}));const qe=/*@__PURE__*/ make$1(node$1({_tag:`Null`}));const Je=/*@__PURE__*/ make$1(node$1({_tag:`Void`}));const Ye=/*@__PURE__*/ make$1(node$1({_tag:`Undefined`}));const Literal=e=>make$1(node$1({_tag:`Literal`,literal:e}));const Literals=e=>make$1(node$1({_tag:`Union`,types:e.map(e=>node$1({_tag:`Literal`,literal:e}))}));const optional=e=>{const t=astOf(e);return make$1(node$1({_tag:`Union`,types:[t,node$1({_tag:`Undefined`})],context:{isOptional:true}}))};const NullOr=e=>make$1(node$1({_tag:`Union`,types:[astOf(e),node$1({_tag:`Null`})]}));const Union=e=>make$1(node$1({_tag:`Union`,types:e.map(astOf)}));const Array$1=e=>make$1(node$1({_tag:`Arrays`,elements:[],rest:[astOf(e)]}));const Tuple=e=>make$1(node$1({_tag:`Arrays`,elements:e.map(astOf),rest:[]}));const Record=(e,t)=>{const n=make$1(node$1({_tag:`Objects`,propertySignatures:[],indexSignatures:[{parameter:astOf(e),type:astOf(t)}]}));n.key=e;n.value=t;return n};const Struct=e=>{const t=make$1(node$1({_tag:`Objects`,propertySignatures:Object.keys(e).map(t=>{return{name:t,type:astOf(e[t])}}),indexSignatures:[]}));t.fields=e;return t};const StructWithRest=(e,t)=>{const n=resolveObjects(astOf(e));const r=make$1(node$1({_tag:`Objects`,propertySignatures:n.propertySignatures??[],indexSignatures:[...n.indexSignatures??[],...t.flatMap(e=>resolveObjects(astOf(e)).indexSignatures??[])]}));r.fields=e.fields;return r};const resolveObjects=e=>e._tag===`Suspend`?resolveObjects(e.thunk()):e;const suspend=e=>{let t;return make$1(node$1({_tag:`Suspend`,thunk:()=>t??=astOf(e())}))};const encodeKeys=e=>t=>t.annotate({[Xe]:e});const Xe=`@distilled.cloud/core/schema-lite/encodeKeys`;const declaration=e=>make$1(node$1({_tag:`Declaration`,typeParameters:[],annotations:{identifier:e}}));const Ze=/*@__PURE__*/ declaration(`Date`);const Qe=/*@__PURE__*/ declaration(`Duration`);const Redacted$1=e=>make$1(node$1({_tag:`Declaration`,typeParameters:[astOf(e)],annotations:{identifier:`Redacted`}}));const instanceOf=(e,t)=>make$1(node$1({_tag:`Declaration`,typeParameters:[],annotations:{identifier:e.name,...t}}));const declare=(e,t)=>make$1(node$1({_tag:`Declaration`,typeParameters:[],annotations:{...t}}));const L=`~distilled/tag`;const $e=`~distilled/keys`;const et=`~distilled/ast`;const tt=`~distilled/annotations`;const nt=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/annotation-meta`);const ownAnnotations=e=>{const t={};for(const n of Reflect.ownKeys(e))if(n!==nt&&Object.prototype.propertyIsEnumerable.call(e,n))t[n]=e[n];return t};let rt;const LiteErrorBase=()=>rt??=class LiteError extends ie.Error{constructor(e){const t=new.target[$e];const n={};if(e){for(const r of t)if(e[r]!==void 0)n[r]=e[r]}super(n);this._tag=new.target[L]}static get ast(){const e=this;if(Object.hasOwn(e,et))return e[et];const t=e.fields;return e[et]=node$1({_tag:`Objects`,propertySignatures:Object.keys(t).map(e=>({name:e,type:astOf(t[e])})),indexSignatures:[],annotations:{identifier:e[L],...e[tt]}})}static pipe(){return h(this,arguments)}static make(e){return new this(e)}static is(e){return typeof e===`object`&&e!==null&&e._tag===this[L]}};const TaggedError=e=>(e,t={},n)=>{const C=class extends LiteErrorBase(){};C[L]=e;C[$e]=Object.keys(t);if(n)C[tt]=ownAnnotations(n);C.fields=t;C.identifier=e;C.prototype.name=e;return C};const at=(e,t)=>{const n=Object.create(it);n.b=e;n.j=t;return n};const resolveAt=e=>e.s??=e.b(e.j);const it=/*@__PURE__*/ Object.create(Ve,{ast:{get(){return resolveAt(this).ast}},fields:{get(){return resolveAt(this).fields}},key:{get(){return resolveAt(this).key}},value:{get(){return resolveAt(this).value}}});const toEffect=(e,t)=>{const n=/* @__PURE__ */ new Map;const r=/* @__PURE__ */ new Map;const hasLite=e=>{const t=r.get(e);if(t!==void 0)return t;r.set(e,false);const n=[...e.types??[],...e.elements??[],...e.rest??[],...e.typeParameters??[],...(e.propertySignatures??[]).map(e=>e.type),...(e.indexSignatures??[]).flatMap(e=>[e.parameter,e.type]),...(e.encoding??[]).map(e=>e.to),...e._tag===`Suspend`&&e.thunk?[e.thunk()]:[]];const i=!!e[`~lite`]||n.some(hasLite);r.set(e,i);return i};const build=t=>{const r=n.get(t);if(r)return r;if(!t[`~lite`]&&!hasLite(t)){const r=e.make(t);n.set(t,r);return r}let i;switch(t._tag){case`String`:i=e.String;break;case`Number`:i=e.Number;break;case`Boolean`:i=e.Boolean;break;case`Null`:i=e.Null;break;case`Undefined`:i=e.Undefined;break;case`Void`:i=e.Void;break;case`Any`:i=e.Any;break;case`Literal`:i=e.Literal(t.literal);break;case`Union`:i=t.context?.isOptional?e.optional(build(t.types[0])):e.Union(t.types.map(build));break;case`Arrays`:i=t.rest.length?e.Array(build(t.rest[0])):e.Tuple(t.elements.map(build));break;case`Objects`:{const n=t.propertySignatures??[];const r=(t.indexSignatures??[]).map(t=>e.Record(build(t.parameter),build(t.type)));if(n.length===0&&r.length===1){i=r[0];break}const a=e.Struct(Object.fromEntries(n.map(e=>[e.name,build(e.type)])));i=r.length?e.StructWithRest(a,r):a;break}case`Suspend`:{const n=t.thunk;i=e.suspend(()=>build(n()));break}case`Declaration`:i=t.check?e.declare(t.check):e.Unknown;break;case`Unknown`:i=e.Unknown;break;default:i=t[`~lite`]?e.Unknown:e.make(t)}n.set(t,i);return i};return build(t)};const R=optional;const ot=Struct;const st=StructWithRest;const ct=suspend;const lt=Array$1;const ut=Record;const dt=Union;const ft=Literal;const pt=Literals;const mt=NullOr;const ht=Tuple;const gt=declare;const _t=instanceOf;const vt=Redacted$1;const z=He;const yt=Ue;const bt=Ue;const xt=We;const St=Ze;const Ct=Qe;const wt=Ge;const Tt=qe;const Et=Je;const Dt=Ke;const B=TaggedError;var SdkError=class extends (/*@__PURE__*/ B()(`SdkError`,{message:z})){};const loadModule=e=>u.tryPromise({try:()=>e(),catch:e=>new SdkError({message:`an SDK module failed to load: ${e instanceof Error?e.message:String(e)}`})});const getPath=(e,t)=>{const n=t.split(`.`);let r=e;for(const e of n){if(r==null||typeof r!==`object`)return;r=r[e]}return r};const getItems=(e,t)=>{let n=[e];for(const e of t.split(`.`)){const t=[];for(const r of n){if(r==null||typeof r!==`object`)continue;const n=r[e];if(Array.isArray(n))for(const e of n)t.push(e);else if(n!=null)t.push(n)}n=t}return n};const missingPaginationConfig=e=>g.fail(new SdkError({message:e}));const isTerminalToken=e=>e===void 0||e===null||e===``;const paginateSingle=(e,t)=>g.fromEffect(u.suspend(()=>e(t)));const paginatePageNumber=(e,t,n)=>{const r=n.inputToken;const i=n.outputToken;if(!r||!i)return missingPaginationConfig(`Page-number pagination requires inputToken and outputToken`);const a=typeof t[r]===`number`?t[r]:1;return g.unfold({page:a,done:false},a=>u.gen(function*(){if(a.done)return void 0;const o=yield*e({...t,[r]:a.page});const s=getPath(o,i);const c=n.items?getPath(o,n.items):void 0;return[o,{page:typeof s===`number`&&s>a.page?s:a.page+1,done:s===null||s===void 0||c===null||c!==void 0&&c.length===0}]}))};const paginateCursor=(e,t,n)=>{const r=n.inputToken;const i=n.outputToken;if(!r||!i)return missingPaginationConfig(`Cursor pagination requires inputToken and outputToken`);const a=typeof t[r]===`string`?t[r]:void 0;return g.suspend(()=>{const n=/* @__PURE__ */ new Set;return g.unfold({cursor:a,done:false},a=>u.gen(function*(){if(a.done)return void 0;if(a.cursor!==void 0)n.add(a.cursor);const o=yield*e({...t,...a.cursor?{[r]:a.cursor}:{}});const s=getPath(o,i);return[o,{cursor:s??void 0,done:isTerminalToken(s)||s!=null&&n.has(s)}]}))})};const paginateToken=(e,t,n)=>{const r=n.inputToken;const i=n.outputToken;if(!r||!i)return missingPaginationConfig(`Token pagination requires inputToken and outputToken`);const a=t[r];return g.unfold({token:a,done:false},n=>u.gen(function*(){if(n.done)return void 0;const a=yield*e(n.token!==void 0?{...t,[r]:n.token}:t);const o=getPath(a,i);return[a,{token:o,done:isTerminalToken(o)}]}))};const setPath=(e,t,n)=>{const[r,...i]=t.split(`.`);const a=r;if(i.length===0)return{...e,[a]:n};const o=e[a];return{...e,[a]:setPath(o!==null&&typeof o===`object`?o:{},i.join(`.`),n)}};const paginateKeyset=(e,t,n)=>{const{inputToken:r,outputToken:i,items:a}=n;if(!r||!i||!a)return missingPaginationConfig(`Keyset pagination requires inputToken, outputToken and items`);const o=n.pageSize?getPath(t,n.pageSize):void 0;return g.unfold({request:t,key:getPath(t,r)},t=>t===void 0?u.succeed(void 0):u.map(e(t.request),e=>{const n=getItems(e,a);const s=n.length>0?getPath(n[n.length-1],i):void 0;return[e,n.length===0||isTerminalToken(s)||s===t.key||typeof o===`number`&&n.length<o?void 0:{request:setPath(t.request,r,s),key:s}]}))};const paginateRelay=(e,t,n)=>{const r=n.inputToken;const i=n.outputToken;if(!r||!i)return missingPaginationConfig(`Relay pagination requires inputToken and outputToken`);const a=n.hasNextPage??`${i.split(`.`).slice(0,-1).concat(`hasNextPage`).join(`.`)}`;const o=typeof t[r]===`string`?t[r]:void 0;return g.unfold({cursor:o,done:false},o=>u.gen(function*(){if(o.done)return void 0;const s=yield*e({...t,...o.cursor?{[r]:o.cursor}:{}});const c=getPath(s,i);const l=getPath(s,a)===true;const u=n.items!==void 0&&getItems(s,n.items).length===0;const d=o.cursor!==void 0&&c!==void 0&&c!==null&&c===o.cursor;return[s,{cursor:c??void 0,done:!l||isTerminalToken(c)||u||d}]}))};const Ot=/*@__PURE__*/ l.Reference(`@distilled.cloud/core/Pagination/PageHeaders`,{defaultValue:()=>void 0});const recordPageHeaders=(e,t)=>{const n=l.get(e,Ot);if(n!==void 0)n.headers=t};const nextLink=e=>{if(e===void 0)return void 0;for(const t of e.split(/,\s*(?=<)/)){const e=/^\s*<([^>]*)>(.*)$/.exec(t);const n=e&&/;\s*rel\s*=\s*"?([^";]*)"?/i.exec(e[2]);if(n&&n[1].toLowerCase().split(/\s+/).includes(`next`))return e[1]}};const paginateLink=(e,t,n)=>{const r=n.inputToken;if(!r)return missingPaginationConfig(`Link pagination requires inputToken`);return g.unfold({token:t[r],done:false},n=>u.gen(function*(){if(n.done)return void 0;const i=n.token!==void 0?{...t,[r]:n.token}:t;const a={headers:void 0};const o=yield*u.provideService(e(i),Ot,a);const s=nextLink(a.headers?.[`link`]);const c=s===void 0?void 0:new URL(s,`http://_`).searchParams.get(r)??void 0;return[o,{token:c,done:isTerminalToken(c)||n.token!==void 0&&c===String(n.token)}]}))};const paginateWithDefaults=(e,t,n)=>{switch(n.mode??`token`){case`page`:return paginatePageNumber(e,t,n);case`cursor`:return paginateCursor(e,t,n);case`relay`:return paginateRelay(e,t,n);case`link`:return paginateLink(e,t,n);case`keyset`:return paginateKeyset(e,t,n);case`single`:return paginateSingle(e,t,n);default:return paginateToken(e,t,n)}};const extractItems=(e,t)=>flattenPages(e,e=>getItems(e,t));const extractArrayItems=e=>flattenPages(e,e=>Array.isArray(e)?e:[]);const flattenPages=(e,t)=>g.transformPull(e,e=>{const n=u.flatMap(e,e=>{const r=[];for(const n of e)for(const e of t(n))r.push(e);return r.length>0?u.succeed(r):n});return u.succeed(n)});const makeRetryService=e=>l.Service()(e);const kt=/*@__PURE__*/ ae.addDelay(()=>u.succeed(v.millis(Math.random()*50)));const capped=e=>ae.modifyDelay(({duration:t})=>u.succeed(v.isGreaterThan(t,e)?e:t));const V=6e4;const At=`DISTILLED_SERVER_RETRY_HINT_CAP_MS`;const H=/*@__PURE__*/ l.Service(`@distilled.cloud/core/ServerRetryHintCapMs`);const serverRetryHintCapLayer=e=>p.succeed(H,e);const readServerRetryHintCapMsFromEnv=()=>parseCapMs(globalThis.process?.env?.[At]);const parseCapMs=e=>{if(e===void 0||e===``)return V;const t=Number(e);return Number.isFinite(t)&&t>=0?Math.trunc(t):V};const jt=`effect/ConfigProvider`;const resolveServerRetryHintCapMs=()=>u.gen(function*(){const e=yield*u.serviceOption(H);if(m.isSome(e)){const t=e.value;if(Number.isFinite(t)&&t>=0)return Math.trunc(t)}const t=(yield*u.context()).mapUnsafe.get(jt);if(!t)return readServerRetryHintCapMsFromEnv();const n=yield*t.load([At]).pipe(u.orElseSucceed(()=>void 0));return parseCapMs(n?._tag===`Value`?n.value:void 0)});const serverHintMillis=(e,t)=>{const n=e?.retryAfter;if(!v.isDuration(n))return void 0;return Math.min(v.toMillis(n),t)};const Mt={while:e=>isTransientError(e),backoff:{baseMs:250,factor:2,capMs:5e3,maxRetries:8,jitterMs:50,minThrottleMs:500,serverHint:true}};const makeDefault=()=>Mt;const Nt={baseMs:1e3,factor:2,capMs:5e3,jitterMs:50,serverHint:true};const Pt={baseMs:1e3,factor:2,capMs:5e3,jitterMs:50};const throttlingFactory=()=>Ft;const Ft={while:e=>isThrottling(e),backoff:Nt};const It={while:e=>isThrottling(e),backoff:Pt};const transientFactory=()=>Lt;const Lt={while:isTransientError,backoff:Nt};const Rt={while:isTransientError,backoff:Pt};var Protocol=class extends (/*@__PURE__*/ l.Service()(`Protocol`)){};const withValue=(e,t)=>d.isExit(e)?d.isSuccess(e)?t(e.value):e:u.flatMap(e,t);const zt=/*@__PURE__*/ p.makeMemoMapUnsafe();const Bt=/*@__PURE__*/ te.makeUnsafe();const Vt=/*@__PURE__*/ new WeakMap;const protocolContext=e=>{const t=Vt.get(e);if(t)return u.succeed(t);return u.map(p.buildWithMemoMap(e,zt,Bt),t=>{Vt.set(e,t);return t})};const backoffDelay=(e,t,n)=>{const r=Math.min(e.baseMs*e.factor**t,e.capMs);const jitter=()=>Math.random()*(e.jitterMs??0);if(e.serverHint&&n?.retryAfter!==void 0)return u.map(resolveServerRetryHintCapMs(),e=>{return(serverHintMillis(n,e)??r)+jitter()});const i=e.minThrottleMs!==void 0&&r<e.minThrottleMs&&isThrottling(n)?e.minThrottleMs:r;return u.succeed(i+jitter())};const Ht={baseMs:0,factor:1,capMs:0};const backoffSleep=(e,t,n)=>u.withFiber(r=>{const i=r.context;const a=typeof e===`number`?e:0;c(i,t,n,a);return s(i,`distilled.retry.backoff`,u.sleep(e),{"distilled.retry.attempt":t,"distilled.retry.delay_ms":Math.round(a),"distilled.retry.reason":n?._tag})});const applyRetry=(e,t,n)=>{const r=n===void 0?e:n.attempt(e,1);return t===void 0?r:u.catch(r,r=>u.flatMap(u.serviceOption(t),t=>{if(m.isNone(t))return retryWith(e,Mt,r,n);const i=t.value;if(typeof i!==`function`)return retryWith(e,i,r,n);return u.flatMap(ee.make(r),t=>retryWith(u.tapError(e,e=>ee.set(t,e)),i(t),r,n))}))};const retryWith=(e,t,n,r)=>{const i=t.while;if(!i||!i(n))return u.fail(n);const again=t=>r===void 0?e:r.attempt(e,t);if(t.schedule){const e=t.schedule;return u.flatMap(e.step,e=>{let t=0;const loop=n=>!i(n)?u.fail(n):u.clockWith(r=>u.matchEffect(e(r.currentTimeMillisUnsafe(),n),{onFailure:()=>u.fail(n),onSuccess:([,e])=>u.flatMap(backoffSleep(e,++t,n),()=>u.catch(again(t+1),loop))}));return loop(n)})}const a=t.backoff??Ht;const step=(e,t)=>!i(e)||a.maxRetries!==void 0&&t>=a.maxRetries?u.fail(e):u.flatMap(backoffDelay(a,t,e),n=>u.flatMap(backoffSleep(n,t+1,e),()=>u.catch(again(t+2),e=>step(e,t+1))));return step(n,0)};const infoOf=e=>e.info??=a(e.cfg.telemetry,e.cfg.span,e.cfg.operationName,e.inputAst);const U=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/api/OperationState`);const prepare=e=>{if(e.prepared)return e.prepared;const t=e.configFn();return e.prepared={cfg:t,config:t,inputAst:t.input.ast,outputAst:t.output.ast,errors:t.errors??[],compiled:void 0,service:void 0}};const prepareOr=e=>{if(e.prepared)return e.prepared;try{return prepare(e)}catch(e){return new SdkError({message:`the operation could not be loaded: ${e instanceof Error?e.message:String(e)}`})}};const stateOf=e=>e[U];const describeOperation=e=>infoOf(prepare(stateOf(e)));const defineState=(e,t)=>{Object.defineProperty(e,U,{value:t});return t};const runWith=(e,t,n)=>{if(t.call!==void 0)return t.call(e,n);const{cfg:r,inputAst:a,outputAst:o,errors:s}=e;return u.withFiber(e=>{const c=e.context;const d=l.get(c,f.HttpClient);return u.flatMap(t.encode({input:n,inputAst:a,config:r}),e=>u.flatMap(i(c,d,e),e=>t.decode({response:e,outputAst:o,errors:s,config:r})))})};const callUntraced=(e,t,n)=>{const r=e.prepared;if(r?.service!==void 0)return applyRetry(runWith(r,r.service,t),r.cfg.retry,n);return u.suspend(()=>{const r=prepareOr(e);if(r instanceof SdkError)return u.fail(r);const i=u.flatMap(n===void 0?protocolContext(r.cfg.protocol):n.phase(`distilled.setup`,protocolContext(r.cfg.protocol),{"distilled.setup.first_call":true}),e=>{const n=r.service=l.get(e,Protocol);return runWith(r,n,t)});return applyRetry(i,r.cfg.retry,n)})};const callOperation=(e,t,i)=>{const a=r(i);return u.withFiber(r=>{const i=r.getRef(n);const s=prepareOr(e);if(s instanceof SdkError)return u.fail(s);return o(r,i,infoOf(s),a,t,t=>callUntraced(e,t,i),i===void 0?void 0:{input:s.inputAst,output:s.outputAst})})};const bindContext=e=>u.map(u.context(),t=>n=>u.updateContext(e(n),e=>l.merge(t,e)));const W=/*@__PURE__*/ Object.setPrototypeOf({[Symbol.iterator](){return new ne(this.asEffect())},pipe(){return h(this.asEffect(),arguments)},asEffect(){return bindContext(this)},get input(){return prepare(stateOf(this)).cfg.input},get output(){return prepare(stateOf(this)).cfg.output},get errors(){return prepare(stateOf(this)).cfg.errors??[]},get operationName(){return prepare(stateOf(this)).cfg.operationName},get pagination(){return prepare(stateOf(this)).cfg.pagination}},Function.prototype);const makeOperation=(e,t)=>{const fn=t=>callOperation(e,t,fn);defineState(fn,e);return Object.setPrototypeOf(fn,t)};function make(e){return makeOperation({configFn:e},W)}const streamsOf=(n,r)=>{const pagesOf=(e,t)=>{const i=e.cfg;return(n.strategy??i.strategy??paginateWithDefaults)(r,t,i.pagination)};const pages=e=>{const t=prepareOr(n);return t instanceof SdkError?g.fail(t):pagesOf(t,e)};const items=r=>{const i=prepareOr(n);if(i instanceof SdkError)return g.fail(i);const a=i.cfg.pagination;if(!a.items)return pagesOf(i,r);return e(i.outputAst,t)!==void 0?extractArrayItems(pagesOf(i,r)):extractItems(pagesOf(i,r),a.items)};return{pages,items}};const streamGetter=e=>function(){const t=streamsOf(stateOf(this),this);Object.defineProperties(this,{pages:{value:t.pages,configurable:true},items:{value:t.items,configurable:true}});return t[e]};const Ut=/*@__PURE__*/ Object.create(W,{pages:{get:/*@__PURE__*/ streamGetter(`pages`),configurable:true},items:{get:/*@__PURE__*/ streamGetter(`items`),configurable:true},asEffect:{value(){const e=stateOf(this);return u.map(bindContext(this),t=>Object.assign(t,streamsOf(e,t)))},configurable:true,writable:true}});function makePaginated(e,t){return makeOperation(t?{configFn:e,strategy:t}:{configFn:e},Ut)}const streamCall=e=>t=>g.unwrap(u.suspend(()=>{const n=prepareOr(e);if(n instanceof SdkError)return u.succeed(g.fail(n));const run=e=>e.stream===void 0?g.fail(new SdkError({message:`${n.cfg.operationName??`this operation`}: its protocol can't stream`})):e.stream(n,t);return n.service!==void 0?u.succeed(run(n.service)):u.map(protocolContext(n.cfg.protocol),e=>run(n.service=l.get(e,Protocol)))}));const Wt=/*@__PURE__*/ Object.create(W,{stream:{get(){const e=streamCall(stateOf(this));Object.defineProperty(this,"stream",{value:e,configurable:true});return e},configurable:true},asEffect:{value(){const e=stateOf(this);return u.map(u.context(),t=>{const merge=e=>l.merge(t,e);const call=e=>u.updateContext(this(e),merge);return Object.assign(call,{stream:t=>g.updateContext(streamCall(e)(t),merge)})})},configurable:true,writable:true}});function makeStreaming(e){return makeOperation({configFn:e},Wt)}const G=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/api/D`);const K=/*@__PURE__*/ new WeakMap;const sourceOf=e=>{let t=K.get(e);if(!t)K.set(e,t={fn:e,c:[]});if(!t.e){const[n,r]=e.call(e,G);t.e=n.split(`;`);t.r=r}return t};const schemaOf=(e,t)=>e.c[t]??=e.r[0](e.b??=t=>evalEntry(e,t),t);const schema=(e,t)=>schemaOf(sourceOf(e),t);const q=/"(?:[^"\\]|\\.)*"|[\w$.+-]*/y;const Gt=/[\w$]*/y;const evalEntry=(e,t)=>{const n=e.e[t];const r=e.r;let i=0;const tok=(e=Gt)=>{e.lastIndex=i;const t=e.exec(n)[0];i+=t.length;return t};const list=e=>{const t=[];if(n[i]===e)i++;else do t.push(expr());while(n[i++]!==e);return t};const expr=()=>{let t;const a=n[i++];if(a===`{`){t={};if(n[i]===`}`)i++;else do{const e=tok(q);i++;t[e[0]===`"`?JSON.parse(e):e]=expr()}while(n[i++]!==`}`)}else if(a===`[`)t=list(`]`);else if(`$#~>`.includes(a)){let o=e;let s=+tok();if(n[i]===`:`){i++;o=sourceOf(r[s]);s=+tok()}t=a===`$`?r[s]:a===`>`?()=>evalEntry(e,s):a===`#`?schemaOf(o,s):o.c[s]??=evalEntry(o,s)}else{i--;const e=tok(q);t=e===`u`?void 0:JSON.parse(e)}for(;;){const e=n[i++];if(e===`(`)t=t(...list(`)`));else if(e===`@`)t=t.annotate({identifier:JSON.parse(tok(q))});else if(e===`.`){const e=tok();t=n[i]===`(`?(i++,t[e](...list(`)`))):t[e]}else return i--,t}};return expr()};const dataState=function(){return defineState(this,{configFn:()=>evalEntry(sourceOf(this),0)})};let Kt;let qt;let Jt;let J;const defining=(e,t)=>{const n=J;J=e;try{t()}finally{J=n}};const named=(e,t,n)=>[t.replaceAll(`%`,e),n];const asOp=e=>Object.setPrototypeOf(e,Kt??=Object.create(W,{[U]:{get:dataState,configurable:true}}));const asOpPaginated=e=>Object.setPrototypeOf(e,qt??=Object.create(Ut,{[U]:{get:dataState,configurable:true}}));const asOpStreaming=e=>Object.setPrototypeOf(e,Jt??=Object.create(Wt,{[U]:{get:dataState,configurable:true}}));const op=e=>J?J(e,0):asOp(e);const opPaginated=e=>J?J(e,1):asOpPaginated(e);const opStreaming=e=>J?J(e,3):asOpStreaming(e);const call=(e,t)=>callOperation(stateOf(e),t,e);const errorBase=e=>{while(e&&Object.getPrototypeOf(e)!==Yt&&!K.get(e)?.k)e=Object.getPrototypeOf(e);if(!e)return void 0;const t=sourceOf(e);if(!t.k){const n=evalEntry(t,0);t.k=n;Object.setPrototypeOf(e,n);Object.setPrototypeOf(e.prototype,n.prototype)}return t.k};let Yt;const LazyErrorStatics=()=>Yt??=new Proxy(Object.create(Function.prototype),{get:(e,t,n)=>t in e||!errorBase(n)?Reflect.get(e,t,n):Reflect.get(n,t,n)});const asError=e=>Object.setPrototypeOf(e,LazyErrorStatics());const error=e=>J?J(e,2):asError(e);const newError=(e,t,n)=>t?Reflect.construct(errorBase(t),[e],t):n;const Xt=[`o`,`p`,``,`s`];const define=(e,t,n)=>{if(n===2){const n=e.ei++;if(n>=e.e.length)throw new Error(`distilled: ${e.spec}: error ${n} has no stub`);e.ed[n]=t;return e.e[n]}const r=e.oi++;if(r>=e.o.length||e.kinds[r]!==Xt[n])throw new Error(`distilled: ${e.spec}: operation ${r} does not match its stub`);e.od[r]=t;return e.o[r]};const load=e=>{if(e.od)return;e.od=[];e.ed=[];try{defining((t,n)=>define(e,t,n),()=>globalThis.process.getBuiltinModule(`node:module`).createRequire(e.url)(e.spec))}catch(t){e.od=e.ed=void 0;e.oi=e.ei=0;throw t}if(e.oi!==e.o.length||e.ei!==e.e.length)throw new Error(`distilled: ${e.spec} defined ${e.oi} of ${e.o.length} operations and ${e.ei} of ${e.e.length} errors (was it imported directly before?)`)};const Zt={};const node=e=>globalThis.process?.getBuiltinModule?.(e);const read=(e,t,n)=>{const r=node(`node:fs`);if(e.fd===void 0){e.fd=r.openSync(e.file,`r`);queueMicrotask(()=>{r.closeSync(e.fd);e.fd=void 0})}const i=globalThis.Buffer.allocUnsafe(n);r.readSync(e.fd,i,0,n,t);return i.toString(`utf8`,0,n)};const indexOf=(e,t)=>{const n=t.indexOf(`
|
|
1
|
+
import{getAnn as e,getProps as t,rawResponseRootSymbol as n}from"../annotations.js";import{successesOf as r,takeLastRequest as i}from"../retry-state.js";import{Debug as a,captureCallSite as o,operationInfo as s,operationSpan as c,phase as l,retried as u}from"../telemetry.js";import{send as d}from"../send.js";import*as f from"effect/Cause";import*as p from"effect/Context";import*as m from"effect/Duration";import*as h from"effect/Effect";import*as ee from"effect/Exit";import*as te from"effect/http/HttpClient";import*as g from"effect/Option";import{pipeArguments as _}from"effect/Pipeable";import*as ne from"effect/Ref";import*as re from"effect/References";import"effect/Schema";import*as v from"effect/Stream";import{SingleShotGen as ie}from"effect/Utils";import*as ae from"effect/http/HttpClientError";import*as y from"effect/Predicate";import*as oe from"effect/Data";import*as se from"effect/Layer";import*as ce from"effect/Schedule";import*as le from"effect/Redacted";const b=`AuthError`;const x=`BadRequestError`;const S=`ConflictError`;const w=`NotFoundError`;const T=`QuotaError`;const E=`ServerError`;const D=`ThrottlingError`;const O=`NetworkError`;const k=`ParseError`;const A=`ConfigurationError`;const j=`TimeoutError`;const M=`RetryableError`;const N=`LockedError`;const P=`AbortedError`;const F=`AlreadyExistsError`;const I=`DependencyViolationError`;const L=`@distilled.cloud/error/categories`;const ue=`@distilled.cloud/error/retryable`;const withCategory=(...e)=>t=>{for(const n of e){if(!(`@distilled.cloud/error/categories`in t.prototype))t.prototype[L]={};t.prototype[L][n]=true}return t};const withRetryable=(e={})=>t=>{t.prototype[ue]=e;return t};const de=/*@__PURE__*/ withCategory(b);const fe=/*@__PURE__*/ withCategory(x);const pe=/*@__PURE__*/ withCategory(S);const me=/*@__PURE__*/ withCategory(w);const he=/*@__PURE__*/ withCategory(T);const ge=/*@__PURE__*/ withCategory(E);const _e=/*@__PURE__*/ withCategory(D);const ve=/*@__PURE__*/ withCategory(O);const ye=/*@__PURE__*/ withCategory(k);const be=/*@__PURE__*/ withCategory(A);const xe=/*@__PURE__*/ withCategory(j);const Se=/*@__PURE__*/ withCategory(M);const Ce=/*@__PURE__*/ withCategory(N);const we=/*@__PURE__*/ withCategory(P);const Te=/*@__PURE__*/ withCategory(F);const Ee=/*@__PURE__*/ withCategory(I);const hasCategory=(e,t)=>{if(y.isObject(e)&&y.hasProperty(`@distilled.cloud/error/categories`)(e))return t in e[L];return false};const isAuthError=e=>hasCategory(e,b);const isBadRequestError=e=>hasCategory(e,x);const isConflictError=e=>hasCategory(e,S);const isNotFoundError=e=>hasCategory(e,w);const isQuotaError=e=>hasCategory(e,T);const isServerError=e=>hasCategory(e,E);const isThrottlingError=e=>hasCategory(e,D);const isNetworkError=e=>hasCategory(e,O);const isParseError=e=>hasCategory(e,k);const isConfigurationError=e=>hasCategory(e,A);const isTimeoutError=e=>hasCategory(e,j);const isRetryableError=e=>hasCategory(e,M);const isLockedError=e=>hasCategory(e,N);const isAbortedError=e=>hasCategory(e,P);const isAlreadyExistsError=e=>hasCategory(e,F);const isDependencyViolationError=e=>hasCategory(e,I);const isRetryable=e=>{if(y.isObject(e)&&y.hasProperty(`@distilled.cloud/error/retryable`)(e))return true;return false};const isThrottling=e=>{if(y.isObject(e)&&y.hasProperty(`@distilled.cloud/error/retryable`)(e))return e[ue]?.throttling===true;return hasCategory(e,D)};const isHttpTransportError=e=>ae.isHttpClientError(e)&&e.reason._tag===`TransportError`;const isTransientError=e=>isRetryable(e)||hasCategory(e,`RetryableError`)||hasCategory(e,`ThrottlingError`)||hasCategory(e,`NetworkError`)||isHttpTransportError(e);const makeCatcher=e=>t=>n=>h.catchIf(n,t=>hasCategory(t,e),t);const catchErrors=(...e)=>{const t=e[e.length-1];const n=e.slice(0,-1);return e=>h.catchIf(e,e=>n.some(t=>hasCategory(e,t)),t)};const De=/*@__PURE__*/ makeCatcher(b);const Oe=/*@__PURE__*/ makeCatcher(x);const ke=/*@__PURE__*/ makeCatcher(S);const Ae=/*@__PURE__*/ makeCatcher(w);const je=/*@__PURE__*/ makeCatcher(T);const Me=/*@__PURE__*/ makeCatcher(E);const Ne=/*@__PURE__*/ makeCatcher(D);const Pe=/*@__PURE__*/ makeCatcher(O);const Fe=/*@__PURE__*/ makeCatcher(k);const Ie=/*@__PURE__*/ makeCatcher(A);const Le=/*@__PURE__*/ makeCatcher(j);const Re=/*@__PURE__*/ makeCatcher(M);const ze=/*@__PURE__*/ makeCatcher(N);const Be=/*@__PURE__*/ makeCatcher(P);const Ve=/*@__PURE__*/ makeCatcher(F);const He=/*@__PURE__*/ makeCatcher(I);const catchCategory=(...e)=>{const t=e[e.length-1];const n=e.slice(0,-1);return e=>h.catchIf(e,e=>{if(y.isObject(e)&&y.hasProperty(`@distilled.cloud/error/categories`)(e)){for(const t of n)if(t in e[`@distilled.cloud/error/categories`])return true}return false},e=>t(e))};const Ue=`~lite`;const node$1=e=>Object.assign(e,{[Ue]:true});const We={"~lite":true,pipe(){return _(this,arguments)},annotate(e){return make$1({...this.ast,annotations:{...this.ast.annotations,...e}},this)}};const make$1=(e,t)=>{const n=Object.create(We);n.ast=e;if(t){for(const e of[`fields`,`key`,`value`])if(e in t)n[e]=t[e]}return n};const fromNode=e=>make$1(node$1(e));const isLite=e=>(typeof e===`object`||typeof e===`function`)&&e!==null&&e[`~lite`]===true;const astOf=e=>e.ast;const Ge=/*@__PURE__*/ make$1(node$1({_tag:`String`}));const R=/*@__PURE__*/ make$1(node$1({_tag:`Number`}));const Ke=/*@__PURE__*/ make$1(node$1({_tag:`Boolean`}));const qe=/*@__PURE__*/ make$1(node$1({_tag:`Unknown`}));const Je=/*@__PURE__*/ make$1(node$1({_tag:`Any`}));const Ye=/*@__PURE__*/ make$1(node$1({_tag:`Null`}));const Xe=/*@__PURE__*/ make$1(node$1({_tag:`Void`}));const Ze=/*@__PURE__*/ make$1(node$1({_tag:`Undefined`}));const Literal=e=>make$1(node$1({_tag:`Literal`,literal:e}));const Literals=e=>make$1(node$1({_tag:`Union`,types:e.map(e=>node$1({_tag:`Literal`,literal:e}))}));const optional=e=>{const t=astOf(e);return make$1(node$1({_tag:`Union`,types:[t,node$1({_tag:`Undefined`})],context:{isOptional:true}}))};const NullOr=e=>make$1(node$1({_tag:`Union`,types:[astOf(e),node$1({_tag:`Null`})]}));const Union=e=>make$1(node$1({_tag:`Union`,types:e.map(astOf)}));const Array$1=e=>make$1(node$1({_tag:`Arrays`,elements:[],rest:[astOf(e)]}));const Tuple=e=>make$1(node$1({_tag:`Arrays`,elements:e.map(astOf),rest:[]}));const Record=(e,t)=>{const n=make$1(node$1({_tag:`Objects`,propertySignatures:[],indexSignatures:[{parameter:astOf(e),type:astOf(t)}]}));n.key=e;n.value=t;return n};const Struct=e=>{const t=make$1(node$1({_tag:`Objects`,propertySignatures:Object.keys(e).map(t=>{return{name:t,type:astOf(e[t])}}),indexSignatures:[]}));t.fields=e;return t};const StructWithRest=(e,t)=>{const n=resolveObjects(astOf(e));const r=make$1(node$1({_tag:`Objects`,propertySignatures:n.propertySignatures??[],indexSignatures:[...n.indexSignatures??[],...t.flatMap(e=>resolveObjects(astOf(e)).indexSignatures??[])]}));r.fields=e.fields;return r};const resolveObjects=e=>e._tag===`Suspend`?resolveObjects(e.thunk()):e;const Extend=(e,t)=>{const n=resolveObjects(astOf(t));const r=new Set((n.propertySignatures??[]).map(e=>e.name));const i=resolveObjects(astOf(e)).propertySignatures??[];return make$1(node$1({_tag:`Objects`,propertySignatures:[...n.propertySignatures??[],...i.filter(e=>!r.has(e.name))],indexSignatures:n.indexSignatures??[]}))};const suspend=e=>{let t;return make$1(node$1({_tag:`Suspend`,thunk:()=>t??=astOf(e())}))};const encodeKeys=e=>t=>t.annotate({[Qe]:e});const Qe=`@distilled.cloud/core/schema-lite/encodeKeys`;const representation=e=>({id:e,payload:null});const declaration=e=>make$1(node$1({_tag:`Declaration`,typeParameters:[],annotations:{identifier:e,representation:representation(`effect/schema/${e}`)}}));const $e=/*@__PURE__*/ declaration(`Date`);const et=/*@__PURE__*/ declaration(`Duration`);const Redacted$1=e=>make$1(node$1({_tag:`Declaration`,typeParameters:[astOf(e)],annotations:{identifier:`Redacted`,representation:representation(`effect/schema/Redacted`)}}));const instanceOf=(e,t)=>make$1(node$1({_tag:`Declaration`,typeParameters:[],annotations:{identifier:e.name,...e===globalThis.Uint8Array&&{representation:representation(`effect/schema/Uint8Array`)},...t}}));const declare=(e,t)=>make$1(node$1({_tag:`Declaration`,typeParameters:[],annotations:{...t}}));const z=`~distilled/tag`;const tt=`~distilled/keys`;const B=`~distilled/ast`;const nt=`~distilled/annotations`;const rt=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/annotation-meta`);const ownAnnotations=e=>{const t={};for(const n of Reflect.ownKeys(e))if(n!==rt&&Object.prototype.propertyIsEnumerable.call(e,n))t[n]=e[n];return t};let it;const LiteErrorBase=()=>it??=class LiteError extends oe.Error{constructor(e){const t=new.target[tt];const n={};if(e){for(const r of t)if(e[r]!==void 0)n[r]=e[r]}super(n);this._tag=new.target[z]}static get ast(){const e=this;if(Object.hasOwn(e,B))return e[B];const t=e.fields;return e[B]=node$1({_tag:`Objects`,propertySignatures:Object.keys(t).map(e=>({name:e,type:astOf(t[e])})),indexSignatures:[],annotations:{identifier:e[z],...e[nt]}})}static pipe(){return _(this,arguments)}static make(e){return new this(e)}static is(e){return typeof e===`object`&&e!==null&&e._tag===this[z]}};const TaggedError=e=>(e,t={},n)=>{const C=class extends LiteErrorBase(){};C[z]=e;C[tt]=Object.keys(t);if(n)C[nt]=ownAnnotations(n);C.fields=t;C.identifier=e;C.prototype.name=e;return C};const at=(e,t)=>{const n=Object.create(ot);n.b=e;n.j=t;return n};const resolveAt=e=>e.s??=e.b(e.j);const ot=/*@__PURE__*/ Object.create(We,{ast:{get(){return resolveAt(this).ast}},fields:{get(){return resolveAt(this).fields}},key:{get(){return resolveAt(this).key}},value:{get(){return resolveAt(this).value}}});const toEffect=(e,t)=>{const n=/* @__PURE__ */ new Map;const r=/* @__PURE__ */ new Map;const hasLite=e=>{const t=r.get(e);if(t!==void 0)return t;r.set(e,false);const n=[...e.types??[],...e.elements??[],...e.rest??[],...e.typeParameters??[],...(e.propertySignatures??[]).map(e=>e.type),...(e.indexSignatures??[]).flatMap(e=>[e.parameter,e.type]),...(e.encoding??[]).map(e=>e.to),...e._tag===`Suspend`&&e.thunk?[e.thunk()]:[]];const i=!!e[`~lite`]||n.some(hasLite);r.set(e,i);return i};const builtIn=t=>{switch((t.annotations?.representation)?.id){case`effect/schema/Date`:return e.Date;case`effect/schema/Duration`:return e.Duration;case`effect/schema/Uint8Array`:return e.Uint8Array;case`effect/schema/Redacted`:{const n=t.typeParameters?.[0];return n&&e.Redacted?.(build(n))}}};const build=t=>{const r=n.get(t);if(r)return r;if(!t[`~lite`]&&!hasLite(t)){const r=e.make(t);n.set(t,r);return r}let i;switch(t._tag){case`String`:i=e.String;break;case`Number`:i=e.Number;break;case`Boolean`:i=e.Boolean;break;case`Null`:i=e.Null;break;case`Undefined`:i=e.Undefined;break;case`Void`:i=e.Void;break;case`Any`:i=e.Any;break;case`Literal`:i=e.Literal(t.literal);break;case`Union`:i=t.context?.isOptional?e.optional(build(t.types[0])):e.Union(t.types.map(build));break;case`Arrays`:i=t.rest.length?e.Array(build(t.rest[0])):e.Tuple(t.elements.map(build));break;case`Objects`:{const n=t.propertySignatures??[];const r=(t.indexSignatures??[]).map(t=>e.Record(build(t.parameter),t.type._tag===`Union`&&t.type.context?.isOptional?e.Union([build(t.type.types[0]),e.Undefined]):build(t.type)));if(n.length===0&&r.length===1){i=r[0];break}const a=e.Struct(Object.fromEntries(n.map(e=>[e.name,build(e.type)])));i=r.length?e.StructWithRest(a,r):a;break}case`Suspend`:{const n=t.thunk;i=e.suspend(()=>build(n()));break}case`Declaration`:i=builtIn(t)??(t.check?e.declare(t.check):e.Unknown);break;case`Unknown`:i=e.Unknown;break;default:i=t[`~lite`]?e.Unknown:e.make(t)}n.set(t,i);return i};return build(t)};const V=optional;const st=Struct;const ct=StructWithRest;const lt=suspend;const ut=Array$1;const dt=Record;const ft=Union;const pt=Literal;const mt=Literals;const ht=NullOr;const gt=Tuple;const _t=declare;const vt=instanceOf;const yt=Redacted$1;const H=Ge;const bt=R;const xt=R;const St=Ke;const Ct=$e;const wt=et;const Tt=qe;const Et=Ye;const Dt=Xe;const Ot=Je;const kt=TaggedError;var SdkError=class extends (/*@__PURE__*/ kt()(`SdkError`,{message:H})){};const loadModule=e=>h.tryPromise({try:()=>e(),catch:e=>new SdkError({message:`an SDK module failed to load: ${e instanceof Error?e.message:String(e)}`})});const getPath=(e,t)=>{const n=t.split(`.`);let r=e;for(const e of n){if(r==null||typeof r!==`object`)return;r=r[e]}return r};const getItems=(e,t)=>{let n=[e];for(const e of t.split(`.`)){const t=[];for(const r of n){if(r==null||typeof r!==`object`)continue;const n=r[e];if(Array.isArray(n))for(const e of n)t.push(e);else if(n!=null)t.push(n)}n=t}return n};const missingPaginationConfig=e=>v.fail(new SdkError({message:e}));const isTerminalToken=e=>e===void 0||e===null||e===``;const paginateSingle=(e,t)=>v.fromEffect(h.suspend(()=>e(t)));const paginatePageNumber=(e,t,n)=>{const r=n.inputToken;const i=n.outputToken;if(!r||!i)return missingPaginationConfig(`Page-number pagination requires inputToken and outputToken`);const a=typeof t[r]===`number`?t[r]:1;return v.unfold({page:a,done:false},a=>h.gen(function*(){if(a.done)return void 0;const o=yield*e({...t,[r]:a.page});const s=getPath(o,i);const c=n.items?getPath(o,n.items):void 0;return[o,{page:typeof s===`number`&&s>a.page?s:a.page+1,done:s===null||s===void 0||c===null||c!==void 0&&c.length===0}]}))};const paginateCursor=(e,t,n)=>{const r=n.inputToken;const i=n.outputToken;if(!r||!i)return missingPaginationConfig(`Cursor pagination requires inputToken and outputToken`);const a=typeof t[r]===`string`?t[r]:void 0;return v.suspend(()=>{const n=/* @__PURE__ */ new Set;return v.unfold({cursor:a,done:false},a=>h.gen(function*(){if(a.done)return void 0;if(a.cursor!==void 0)n.add(a.cursor);const o=yield*e({...t,...a.cursor?{[r]:a.cursor}:{}});const s=getPath(o,i);return[o,{cursor:s??void 0,done:isTerminalToken(s)||s!=null&&n.has(s)}]}))})};const paginateToken=(e,t,n)=>{const r=n.inputToken;const i=n.outputToken;if(!r||!i)return missingPaginationConfig(`Token pagination requires inputToken and outputToken`);const a=t[r];return v.suspend(()=>{const n=/* @__PURE__ */ new Set;return v.unfold({token:a,done:false},a=>h.gen(function*(){if(a.done)return void 0;if(typeof a.token===`string`)n.add(a.token);const o=yield*e(a.token!==void 0?{...t,[r]:a.token}:t);const s=getPath(o,i);return[o,{token:s,done:isTerminalToken(s)||typeof s===`string`&&n.has(s)}]}))})};const setPath=(e,t,n)=>{const[r,...i]=t.split(`.`);const a=r;if(i.length===0)return{...e,[a]:n};const o=e[a];return{...e,[a]:setPath(o!==null&&typeof o===`object`?o:{},i.join(`.`),n)}};const paginateKeyset=(e,t,n)=>{const{inputToken:r,outputToken:i,items:a}=n;if(!r||!i||!a)return missingPaginationConfig(`Keyset pagination requires inputToken, outputToken and items`);const o=n.pageSize?getPath(t,n.pageSize):void 0;return v.unfold({request:t,key:getPath(t,r)},t=>t===void 0?h.succeed(void 0):h.map(e(t.request),e=>{const n=getItems(e,a);const s=n.length>0?getPath(n[n.length-1],i):void 0;return[e,n.length===0||isTerminalToken(s)||s===t.key||typeof o===`number`&&n.length<o?void 0:{request:setPath(t.request,r,s),key:s}]}))};const paginateRelay=(e,t,n)=>{const r=n.inputToken;const i=n.outputToken;if(!r||!i)return missingPaginationConfig(`Relay pagination requires inputToken and outputToken`);const a=n.hasNextPage??`${i.split(`.`).slice(0,-1).concat(`hasNextPage`).join(`.`)}`;const o=typeof t[r]===`string`?t[r]:void 0;return v.unfold({cursor:o,done:false},o=>h.gen(function*(){if(o.done)return void 0;const s=yield*e({...t,...o.cursor?{[r]:o.cursor}:{}});const c=getPath(s,i);const l=getPath(s,a)===true;const u=n.items!==void 0&&getItems(s,n.items).length===0;const d=o.cursor!==void 0&&c!==void 0&&c!==null&&c===o.cursor;return[s,{cursor:c??void 0,done:!l||isTerminalToken(c)||u||d}]}))};const At=/*@__PURE__*/ p.Reference(`@distilled.cloud/core/Pagination/PageHeaders`,{defaultValue:()=>void 0});const recordPageHeaders=(e,t)=>{const n=p.get(e,At);if(n!==void 0)n.headers=t};const nextLink=e=>{if(e===void 0)return void 0;for(const t of e.split(/,\s*(?=<)/)){const e=/^\s*<([^>]*)>(.*)$/.exec(t);const n=e&&/;\s*rel\s*=\s*"?([^";]*)"?/i.exec(e[2]);if(n&&n[1].toLowerCase().split(/\s+/).includes(`next`))return e[1]}};const paginateLink=(e,t,n)=>{const r=n.inputToken;if(!r)return missingPaginationConfig(`Link pagination requires inputToken`);return v.unfold({token:t[r],done:false},n=>h.gen(function*(){if(n.done)return void 0;const i=n.token!==void 0?{...t,[r]:n.token}:t;const a={headers:void 0};const o=yield*h.provideService(e(i),At,a);const s=nextLink(a.headers?.[`link`]);const c=s===void 0?void 0:new URL(s,`http://_`).searchParams.get(r)??void 0;return[o,{token:c,done:isTerminalToken(c)||n.token!==void 0&&c===String(n.token)}]}))};const paginateWithDefaults=(e,t,n)=>{switch(n.mode??`token`){case`page`:return paginatePageNumber(e,t,n);case`cursor`:return paginateCursor(e,t,n);case`relay`:return paginateRelay(e,t,n);case`link`:return paginateLink(e,t,n);case`keyset`:return paginateKeyset(e,t,n);case`single`:return paginateSingle(e,t,n);default:return paginateToken(e,t,n)}};const extractItems=(e,t)=>flattenPages(e,e=>getItems(e,t));const extractArrayItems=e=>flattenPages(e,e=>Array.isArray(e)?e:[]);const flattenPages=(e,t)=>v.transformPull(e,e=>{const n=h.flatMap(e,e=>{const r=[];for(const n of e)for(const e of t(n))r.push(e);return r.length>0?h.succeed(r):n});return h.succeed(n)});const jt=5e3;const makeBudget=(e={})=>{const t=e.initial??100;const n=e.max??500;const i=e.transientCost??14;const a=e.throttlingCost??5;const o=/* @__PURE__ */ new Map;const bucket=e=>{const i=r(e);let a=o.get(e);if(a===void 0){a={tokens:t,seen:i};o.set(e,a)}else if(i!==a.seen){a.tokens=Math.min(n,a.tokens+(i-a.seen));a.seen=i}return a};return{withdraw:(e,t)=>{const n=bucket(e);const r=t?a:i;if(n.tokens<r)return void 0;n.tokens-=r;return r},refund:(e,t)=>{const r=bucket(e);r.tokens=Math.min(n,r.tokens+t-1)},tokens:e=>bucket(e).tokens,reset:()=>o.clear()}};const Mt=/*@__PURE__*/ makeBudget();const makeRetryService=e=>p.Service()(e);const Nt=/*@__PURE__*/ ce.addDelay(()=>h.succeed(m.millis(Math.random()*50)));const capped=e=>ce.modifyDelay(({duration:t})=>h.succeed(m.isGreaterThan(t,e)?e:t));const Pt=6e4;const Ft=`DISTILLED_SERVER_RETRY_HINT_CAP_MS`;const It=/*@__PURE__*/ p.Service(`@distilled.cloud/core/ServerRetryHintCapMs`);const serverRetryHintCapLayer=e=>se.succeed(It,e);const readServerRetryHintCapMsFromEnv=()=>parseCapMs(globalThis.process?.env?.[Ft]);const parseCapMs=e=>{if(e===void 0||e===``)return Pt;const t=Number(e);return Number.isFinite(t)&&t>=0?Math.trunc(t):Pt};const Lt=`effect/ConfigProvider`;const resolveServerRetryHintCapMs=()=>h.gen(function*(){const e=yield*h.serviceOption(It);if(g.isSome(e)){const t=e.value;if(Number.isFinite(t)&&t>=0)return Math.trunc(t)}const t=(yield*h.context()).mapUnsafe.get(Lt);if(!t)return readServerRetryHintCapMsFromEnv();const n=yield*t.load([Ft]).pipe(h.orElseSucceed(()=>void 0));return parseCapMs(n?._tag===`Value`?n.value:void 0)});const serverHintMillis=(e,t)=>{const n=e?.retryAfter;if(!m.isDuration(n))return void 0;return Math.min(m.toMillis(n),t)};const U={while:e=>isTransientError(e),backoff:{baseMs:50,throttlingBaseMs:1e3,factor:2,capMs:2e4,maxRetries:2,fullJitter:true,serverHint:true,budget:Mt}};const makeDefault=()=>U;const Rt=/* @__PURE__ */ new WeakMap;const defaultWith=e=>{const t=Rt.get(e);if(t!==void 0)return t;const n=U.backoff;const r={...U,backoff:{...n,...e.maxAttempts!==void 0?{maxRetries:e.maxAttempts-1}:{},...e.baseMs!==void 0?{baseMs:e.baseMs}:{},...e.throttlingBaseMs!==void 0?{throttlingBaseMs:e.throttlingBaseMs}:{},...e.capMs!==void 0?{capMs:e.capMs}:{},...e.factor!==void 0?{factor:e.factor}:{},...e.longPoll!==void 0?{longPoll:e.longPoll}:{}}};Rt.set(e,r);return r};const zt={baseMs:1e3,factor:2,capMs:5e3,jitterMs:50,serverHint:true};const Bt={baseMs:1e3,factor:2,capMs:5e3,jitterMs:50};const throttlingFactory=()=>Vt;const Vt={while:e=>isThrottling(e),backoff:zt};const Ht={while:e=>isThrottling(e),backoff:Bt};const transientFactory=()=>Ut;const Ut={while:isTransientError,backoff:zt};const Wt={while:isTransientError,backoff:Bt};const W=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/annotation-meta`);function makeAnnotation(e,t){const fn=n=>n.annotate({[e]:t});fn[W]=[{symbol:e,value:t}];fn[e]=t;return fn}function all$1(...e){const t=[];const n={};for(const r of e)for(const e of r[W]){t.push(e);n[e.symbol]=e.value}const fn=e=>e.annotate(n);fn[W]=t;for(const{symbol:e,value:n}of t)fn[e]=n;return fn}const Gt=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http`);const Http=e=>makeAnnotation(Gt,e);const Kt=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/label`);const Label=e=>makeAnnotation(Kt,e??true);const qt=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/label-encoding`);const LabelEncoding=e=>{if(!/^[!$&'()*+,;=:@]*$/.test(e.preserve))throw new TypeError(`LabelEncoding can preserve only URI path-segment delimiters`);return makeAnnotation(qt,e.preserve)};const Jt=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/response-code`);const ResponseCode=()=>makeAnnotation(Jt,true);const Yt=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/header`);const Header=e=>makeAnnotation(Yt,e??true);const Xt=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/body`);const Body=e=>makeAnnotation(Xt,e??true);const Zt=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/query`);const Query=e=>makeAnnotation(Zt,e??true);const Qt=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/idempotency-token`);const IdempotencyToken=e=>makeAnnotation(Qt,e??true);const $t=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/comma-delimited`);const CommaDelimited=e=>makeAnnotation($t,true);const en=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/deep-query`);const DeepQuery=e=>makeAnnotation(en,e??true);const tn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http-body`);const HttpBody=()=>makeAnnotation(tn,true);const nn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/string-encoded`);const StringEncoded=()=>makeAnnotation(nn,true);const rn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/form-data-file`);const FormDataFile=()=>makeAnnotation(rn,true);const an=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/key-dictionary`);const KeyDictionary=e=>makeAnnotation(an,e);const on=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/union-cases`);const UnionCases=(e,t,n)=>makeAnnotation(on,{cases:e,...t?{discriminator:t}:{},...n?{dictionaries:n}:{}});const sn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/error-matchers`);const applyErrorMatchers=(e,t)=>{e[sn]=t;return e};const getErrorMatchers=e=>e?.[sn];const withValue=(e,t)=>ee.isExit(e)?ee.isSuccess(e)?t(e.value):e:h.flatMap(e,t);const protocolOf=e=>h.succeed(e.service=e.cfg.protocol);const backoffDelay=(e,t,n,r)=>{const i=isThrottling(n);let a;if(e.fullJitter){const n=i&&e.throttlingBaseMs!==void 0?e.throttlingBaseMs:e.baseMs;a=Math.random()*Math.min(n*e.factor**t,e.capMs)}else{const n=Math.min(e.baseMs*e.factor**t,e.capMs);a=(e.minThrottleMs!==void 0&&n<e.minThrottleMs&&i?e.minThrottleMs:n)+Math.random()*(e.jitterMs??0)}if(!e.serverHint)return h.succeed(a);if(r!==void 0)return h.succeed(Math.min(Math.max(r,a),a+jt));const o=n?.retryAfter;if(!m.isDuration(o))return h.succeed(a);const s=m.toMillis(o);return h.map(resolveServerRetryHintCapMs(),e=>s>e?void 0:Math.max(a,s))};const cn={baseMs:0,factor:1,capMs:0};const backoffSleep=(e,t,n)=>h.withFiber(r=>{const i=r.context;const a=typeof e===`number`?e:0;u(i,t,n,a);return l(i,`distilled.retry.backoff`,h.sleep(e),{"distilled.retry.attempt":t,"distilled.retry.delay_ms":Math.round(a),"distilled.retry.reason":n?._tag})});const applyRetry=(e,t,n)=>{const r=t.retry;const i=n===void 0?e:n.attempt(e,1);return r===void 0?i:h.catch(i,i=>h.flatMap(h.serviceOption(r),r=>{if(g.isNone(r)){const r=t.retryPolicy===void 0?U:defaultWith(t.retryPolicy);return retryWith(e,r,i,n)}const a=r.value;if(typeof a!==`function`)return retryWith(e,a,i,n);return h.flatMap(ne.make(i),t=>retryWith(h.tapError(e,e=>ne.set(t,e)),a(t),i,n))}))};const retryWith=(e,t,n,r)=>{const a=t.while;if(!a||!a(n))return h.fail(n);const again=t=>r===void 0?e:r.attempt(e,t);if(t.schedule){const e=t.schedule;return h.flatMap(e.step,e=>{let t=0;const loop=n=>!a(n)||i().oneShot?h.fail(n):h.clockWith(r=>h.matchEffect(e(r.currentTimeMillisUnsafe(),n),{onFailure:()=>h.fail(n),onSuccess:([,e])=>h.flatMap(backoffSleep(e,++t,n),()=>h.catch(again(t+1),loop))}));return loop(n)})}const o=t.backoff??cn;const s=o.budget;const step=(e,t)=>{if(!a(e)||o.maxRetries!==void 0&&t>=o.maxRetries)return h.fail(e);const n=i();if(n.oneShot)return h.fail(e);return h.flatMap(backoffDelay(o,t,e,n.hintMs),r=>{if(r===void 0)return h.fail(e);const i=s!==void 0&&n.host!==``;const a=i?s.withdraw(n.host,isThrottling(e)):void 0;if(i&&a===void 0)return o.longPoll?h.flatMap(h.sleep(r),()=>h.fail(e)):h.fail(e);const c=a===void 0?again(t+2):h.map(again(t+2),e=>{s.refund(n.host,a);return e});return h.flatMap(backoffSleep(r,t+1,e),()=>h.catch(c,e=>step(e,t+1)))})};return step(n,0)};const uuidv7=()=>{const e=globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));const t=Date.now();const n=Math.floor(t/2**32);const r=t%2**32;e[0]=n>>>8;e[1]=n&255;e[2]=r>>>24;e[3]=r>>>16&255;e[4]=r>>>8&255;e[5]=r&255;e[6]=e[6]&15|112;e[8]=e[8]&63|128;let i=``;for(const t of e)i+=t.toString(16).padStart(2,`0`);return`${i.slice(0,8)}-${i.slice(8,12)}-${i.slice(12,16)}-${i.slice(16,20)}-${i.slice(20)}`};const withIdempotencyTokens=(n,r)=>{const i=n.idempotencyTokens??=t(n.inputAst).flatMap(t=>{const n=e(t.type,Qt);return typeof t.name===`string`&&n!==void 0?[[t.name,n]]:[]});if(i.length===0||r===null||typeof r!==`object`)return r;let a;for(const[e,t]of i)if(r[e]===void 0){a??={...r};a[e]=t===`uuidv7`?uuidv7():globalThis.crypto.randomUUID()}return a??r};const G=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/api/OperationState`);const prepare=e=>{if(e.prepared)return e.prepared;const t=e.configFn();const n=t.input.ast;return e.prepared={cfg:t,config:t,inputAst:n,info:s(t.telemetry,t.span,t.operationName,n),outputAst:t.output.ast,errors:t.serviceErrors===void 0?t.errors??[]:[...t.errors??[],...t.serviceErrors],compiled:void 0,service:void 0}};const prepareOr=e=>{if(e.prepared)return e.prepared;try{return prepare(e)}catch(e){return new SdkError({message:`the operation could not be loaded: ${e instanceof Error?e.message:String(e)}`})}};const stateOf=e=>e[G];const failed=(e,t,n)=>{const r=e.prepared;if(r===void 0)return h.failCause(t);const i=r.info.name;const a=t.reasons.find(f.isDieReason);if(a!==void 0){const e=new SdkError({message:`${i} threw: ${String(a.defect)}`});e.cause=a.defect;t=f.fail(e)}if(n===void 0)return h.failCause(t);return h.withFiber(e=>h.failCause(f.annotate(t,p.make(f.StackTrace,{name:i,stack:n,parent:p.getOrUndefined(f.annotations(t),f.StackTrace)??e.getRef(re.CurrentStackFrame)}),{overwrite:true})))};const describeOperation=e=>prepare(stateOf(e)).info;const encodeRequest=(e,t)=>h.suspend(()=>{const n=stateOf(e);if(n===void 0)return h.fail(new SdkError({message:`not an operation`}));const r=prepareOr(n);if(r instanceof SdkError)return h.fail(r);const encode=e=>h.catchCause(h.suspend(()=>e.encode({input:withIdempotencyTokens(r,t),inputAst:r.inputAst,config:r.cfg})),e=>failed(n,e));if(r.service!==void 0)return encode(r.service);return h.flatMap(protocolOf(r),encode)});const defineState=(e,t)=>{Object.defineProperty(e,G,{value:t});return t};const runWith=(e,t,n)=>{if(t.call!==void 0)return t.call(e,n);const{cfg:r,inputAst:i,outputAst:a,errors:o}=e;return h.withFiber(e=>{const s=e.context;const c=p.get(s,te.HttpClient);return h.flatMap(t.encode({input:n,inputAst:i,config:r}),e=>h.flatMap(d(s,c,e),e=>t.decode({response:e,outputAst:a,errors:o,config:r})))})};const callUntraced=(e,t,n)=>{if(e.service!==void 0)return applyRetry(runWith(e,e.service,withIdempotencyTokens(e,t)),e.cfg,n);return h.suspend(()=>{const r=withIdempotencyTokens(e,t);return h.flatMap(n===void 0?protocolOf(e):n.phase(`distilled.setup`,protocolOf(e),{"distilled.setup.first_call":true}),t=>applyRetry(runWith(e,t,r),e.cfg,n))})};const callOperation=(e,t,n)=>{const r=o(n);return h.catchCause(h.withFiber(n=>{const i=n.getRef(a);const o=prepareOr(e);if(o instanceof SdkError)return h.fail(o);return c(n,i,o.info,r,t,e=>callUntraced(o,e,i),i===void 0?void 0:{input:o.inputAst,output:o.outputAst})}),t=>failed(e,t,r))};const bindContext=e=>h.map(h.context(),t=>n=>h.updateContext(e(n),e=>p.merge(t,e)));const K=/*@__PURE__*/ Object.setPrototypeOf({[Symbol.iterator](){return new ie(this.asEffect())},pipe(){return _(this.asEffect(),arguments)},asEffect(){return bindContext(this)},get input(){return prepare(stateOf(this)).cfg.input},get output(){return prepare(stateOf(this)).cfg.output},get errors(){return prepare(stateOf(this)).cfg.errors??[]},get operationName(){return prepare(stateOf(this)).cfg.operationName},get pagination(){return prepare(stateOf(this)).cfg.pagination}},Function.prototype);const makeOperation=(e,t)=>{const fn=t=>callOperation(e,t,fn);defineState(fn,e);return Object.setPrototypeOf(fn,t)};function make(e){return makeOperation({configFn:e},K)}const streamsOf=(t,r)=>{const guarded=e=>v.transformPull(v.suspend(e),e=>h.succeed(h.catchCause(e,e=>failed(t,e))));const pagesOf=(e,n)=>{const i=e.cfg;return(t.strategy??i.strategy??paginateWithDefaults)(r,n,i.pagination)};const pages=e=>guarded(()=>{const n=prepareOr(t);return n instanceof SdkError?v.fail(n):pagesOf(n,e)});const items=r=>guarded(()=>{const i=prepareOr(t);if(i instanceof SdkError)return v.fail(i);const a=i.cfg.pagination;if(!a.items)return pagesOf(i,r);return e(i.outputAst,n)!==void 0?extractArrayItems(pagesOf(i,r)):extractItems(pagesOf(i,r),a.items)});return{pages,items}};const streamGetter=e=>function(){const t=streamsOf(stateOf(this),this);Object.defineProperties(this,{pages:{value:t.pages,configurable:true},items:{value:t.items,configurable:true}});return t[e]};const ln=/*@__PURE__*/ Object.create(K,{pages:{get:/*@__PURE__*/ streamGetter(`pages`),configurable:true},items:{get:/*@__PURE__*/ streamGetter(`items`),configurable:true},asEffect:{value(){const e=stateOf(this);return h.map(bindContext(this),t=>Object.assign(t,streamsOf(e,t)))},configurable:true,writable:true}});function makePaginated(e,t){return makeOperation(t?{configFn:e,strategy:t}:{configFn:e},ln)}const cannotStream=e=>v.fail(new SdkError({message:`${e.config.operationName??`this operation`}: its protocol can't stream`}));const streamCall=e=>t=>v.catchCause(v.unwrap(h.suspend(()=>{const n=prepareOr(e);if(n instanceof SdkError)return h.succeed(v.fail(n));const r=n.cfg.streamInput;const i=r===void 0?t:{...t,...r};const run=e=>e.stream===void 0?cannotStream(n):e.stream(n,i);return n.service!==void 0?h.succeed(run(n.service)):h.map(protocolOf(n),run)})),t=>v.fromEffect(failed(e,t)));const un=/*@__PURE__*/ Object.create(K,{stream:{get(){const e=streamCall(stateOf(this));Object.defineProperty(this,"stream",{value:e,configurable:true});return e},configurable:true},asEffect:{value(){const e=stateOf(this);return h.map(h.context(),t=>{const merge=e=>p.merge(t,e);const call=e=>h.updateContext(this(e),merge);return Object.assign(call,{stream:t=>v.updateContext(streamCall(e)(t),merge)})})},configurable:true,writable:true}});function makeStreaming(e){return makeOperation({configFn:e},un)}const q=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/api/D`);const J=/*@__PURE__*/ new WeakMap;const sourceOf=e=>{let t=J.get(e);if(!t)J.set(e,t={fn:e,c:[]});if(!t.e){const[n,r]=e.call(e,q);t.e=n.split(`;`);t.r=r}return t};const schemaOf=(e,t)=>e.c[t]??=e.r[0](e.b??=t=>evalEntry(e,t),t);const schema=(e,t)=>schemaOf(sourceOf(e),t);const dn=/"(?:[^"\\]|\\.)*"|[\w$.+-]*/y;const pn=/[\w$]*/y;const evalEntry=(e,t)=>{const n=e.e[t];const r=e.r;let i=0;const tok=(e=pn)=>{e.lastIndex=i;const t=e.exec(n)[0];i+=t.length;return t};const list=e=>{const t=[];if(n[i]===e)i++;else do t.push(expr());while(n[i++]!==e);return t};const expr=()=>{let t;const a=n[i++];if(a===`{`){t={};if(n[i]===`}`)i++;else do{const e=tok(dn);i++;t[e[0]===`"`?JSON.parse(e):e]=expr()}while(n[i++]!==`}`)}else if(a===`[`)t=list(`]`);else if(`$#~>`.includes(a)){let o=e;let s=+tok();if(n[i]===`:`){i++;o=sourceOf(r[s]);s=+tok()}t=a===`$`?r[s]:a===`>`?()=>evalEntry(e,s):a===`#`?schemaOf(o,s):o.c[s]??=evalEntry(o,s)}else{i--;const e=tok(dn);t=e===`u`?void 0:JSON.parse(e)}for(;;){const e=n[i++];if(e===`(`)t=t(...list(`)`));else if(e===`@`)t=t.annotate({identifier:JSON.parse(tok(dn))});else if(e===`.`){const e=tok();t=n[i]===`(`?(i++,t[e](...list(`)`))):t[e]}else return i--,t}};return expr()};const dataState=function(){return defineState(this,{configFn:()=>evalEntry(sourceOf(this),0)})};let mn;let hn;let gn;let Y;const defining=(e,t)=>{const n=Y;Y=e;try{t()}finally{Y=n}};const named=(e,t,n)=>[t.replaceAll(`%`,e),n];const asOp=e=>Object.setPrototypeOf(e,mn??=Object.create(K,{[G]:{get:dataState,configurable:true}}));const asOpPaginated=e=>Object.setPrototypeOf(e,hn??=Object.create(ln,{[G]:{get:dataState,configurable:true}}));const asOpStreaming=e=>Object.setPrototypeOf(e,gn??=Object.create(un,{[G]:{get:dataState,configurable:true}}));const op=e=>Y?Y(e,0):asOp(e);const opPaginated=e=>Y?Y(e,1):asOpPaginated(e);const opStreaming=e=>Y?Y(e,3):asOpStreaming(e);const call=(e,t)=>callOperation(stateOf(e),t,e);const errorBase=e=>{while(e&&Object.getPrototypeOf(e)!==_n&&!J.get(e)?.k)e=Object.getPrototypeOf(e);if(!e)return void 0;const t=sourceOf(e);if(!t.k){const n=evalEntry(t,0);t.k=n;Object.setPrototypeOf(e,n);Object.setPrototypeOf(e.prototype,n.prototype)}return t.k};let _n;const LazyErrorStatics=()=>_n??=new Proxy(Object.create(Function.prototype),{get:(e,t,n)=>t in e||!errorBase(n)?Reflect.get(e,t,n):Reflect.get(n,t,n)});const asError=e=>Object.setPrototypeOf(e,LazyErrorStatics());const error=e=>Y?Y(e,2):asError(e);const newError=(e,t,n)=>t?Reflect.construct(errorBase(t),[e],t):n;const vn=[`o`,`p`,``,`s`];const define=(e,t,n)=>{if(n===2){const n=e.ei++;if(n>=e.e.length)throw new Error(`distilled: ${e.spec}: error ${n} has no stub`);e.ed[n]=t;return e.e[n]}const r=e.oi++;if(r>=e.o.length||e.kinds[r]!==vn[n])throw new Error(`distilled: ${e.spec}: operation ${r} does not match its stub`);e.od[r]=t;return e.o[r]};const load=e=>{if(e.od)return;e.od=[];e.ed=[];try{defining((t,n)=>define(e,t,n),()=>globalThis.process.getBuiltinModule(`node:module`).createRequire(e.url)(e.spec))}catch(t){e.od=e.ed=void 0;e.oi=e.ei=0;throw t}if(e.oi!==e.o.length||e.ei!==e.e.length)throw new Error(`distilled: ${e.spec} defined ${e.oi} of ${e.o.length} operations and ${e.ei} of ${e.e.length} errors (was it imported directly before?)`)};const yn={};const node=e=>globalThis.process?.getBuiltinModule?.(e);const read=(e,t,n)=>{const r=node(`node:fs`);if(e.fd===void 0){e.fd=r.openSync(e.file,`r`);queueMicrotask(()=>{r.closeSync(e.fd);e.fd=void 0})}const i=globalThis.Buffer.allocUnsafe(n);r.readSync(e.fd,i,0,n,t);return i.toString(`utf8`,0,n)};const indexOf=(e,t)=>{const n=t.indexOf(`
|
|
2
2
|
`)+1;const r=t.indexOf(`
|
|
3
3
|
`,n)+1;return{file:e,raw:t,imports:parseInt(t),importsAt:n,tableAt:r,linesAt:t.indexOf(`
|
|
4
|
-
`,r)+1,importValues:[],v:[]}};const fileOf=e=>/^file:\/\/\/[^%?#]*$/.test(e.url)&&globalThis.process.platform!==`win32`?e.url.slice(7,e.url.lastIndexOf(`/`)+1)+e.spec:node(`node:url`).fileURLToPath(new URL(e.spec,e.url));const sliced=e=>{if(e.ix!==void 0)return e.ix;e.ix=false;if(e.at===void 0||e.od)return false;try{Function(``);const t=fileOf(e);e.ix=indexOf(t,read({file:t},e.at,e.len));e.od=[];e.ed=[]}catch{e.ix=false}return e.ix};let Qt=false;const prime=e=>{Qt=true;queueMicrotask(()=>{const t=sliced(e);if(t&&t.imports>0)importOf(e,t,0)})};const lineOf=(e,t)=>{const n=e.tableAt+5*t;return e.raw.slice(e.linesAt+parseInt(e.raw.slice(n,n+5),36),e.linesAt+parseInt(e.raw.slice(n+5,n+10),36)-1)};const nameOf=(e,t)=>lineOf(e,t).split(`|`)[0].split(` `)[3];const importSpec=(e,t)=>(e.specs??=e.raw.slice(e.importsAt,e.tableAt-1).split(` `))[t].split(`:`);const importOf=(e,t,n)=>{if(n in t.importValues)return t.importValues[n];const[,r,i]=importSpec(t,n);return t.importValues[n]=e.ns[+r][i]};const refOf=(e,t,n)=>n<t.imports?importOf(e,t,n):valueOf(e,t,n-t.imports);const evaluate=(e,t,n)=>{const[r,i,a]=lineOf(t,n).split(`|`);const o=a?a.split(` `).map(e=>parseInt(e,36)):[];const s=o.map(e=>e<t.imports?importSpec(t,e)[0]:nameOf(t,e-t.imports));const c=o.map(n=>refOf(e,t,n));const l=`\n//# sourceURL=${t.file}#${nameOf(t,n)}`;if(i&&i[0]!==`(`){const[e,n]=i.split(`;`);const[r,a,o]=n.split(` `).map(e=>parseInt(e,36));return compileBody(t,s,c,e?e.split(`,`):[],r,a,o,l)}const[,u,d]=r.split(` `).map(e=>parseInt(e,36));let f;if(i?.[0]===`(`){const e=i.slice(1).split(`,`);const n={names:s.slice(),values:c.slice()};f=``;let r=u;e.forEach((e,i)=>{const[a,o,u,d,p]=e.split(` `).map(e=>parseInt(e,36));const m=e.split(` `)[5];let h;s.push(`$lazy${i}`);c.push(function(){h??=compileBody(t,n.names,n.values,m?m.split(`+`):[],u,d,p,l);return h.apply(this,arguments)});f+=`${read(t,r,a-r)}$lazy${i}`;r=o});f+=read(t,r,d-r)}else f=read(t,u,d-u);return Function(...s,`"use strict";return(${f}\n)${l}`)(...c)};const compileBody=(e,t,n,r,i,a,o,s)=>{const c=read(e,i,a-i);const l=t.map(e=>!r.includes(e));return Function(...t.filter((e,t)=>l[t]),...r,`"use strict";${o?`return(${c}\n)`:`{${c}\n}`}${s}`).bind(void 0,...n.filter((e,t)=>l[t]))};const dataFn=(e,t,n)=>{const[r,i,a]=n.slice(1).split(`;`);const o=i.indexOf(` `);const s=parseInt(i,36);const c=read(t,s,parseInt(i.slice(o+1),36)-s);const l=[];if(a)for(const n of a.split(`,`)){const r=parseInt(n,36);l.push(r<t.imports?importOf(e,t,r):slot(e,t,r-t.imports,false))}return[r?c.replaceAll(`%`,r):c,l]};const slot=(e,t,n,r)=>{if(!r){if(n in t.v)return t.v[n]===Zt?void 0:t.v[n];const r=e.o.length;if(n<r)return t.v[n]=e.o[n];if(n<r+e.e.length)return t.v[n]=e.e[n-r]}const i=t.tableAt+5*n;const a=t.raw.slice(t.linesAt+parseInt(t.raw.slice(i,i+5),36),t.linesAt+parseInt(t.raw.slice(i+5,i+10),36)-1);const o=a.indexOf(`|`);if(a[o+1]===`=`){const i=dataFn.bind(void 0,e,t,a.slice(o+1));return r?i:t.v[n]=i}if(r)return evaluate(e,t,n);if(a[0]===`1`){let r;return t.v[n]=function(){return(r??=evaluate(e,t,n)).apply(this,arguments)}}t.v[n]=Zt;return t.v[n]=evaluate(e,t,n)};const valueOf=(e,t,n)=>slot(e,t,n,false);const dataOf=(e,t,n)=>{const r=t===0?e.od:e.ed;if(r?.[n])return r[n];const i=sliced(e);if(!i){load(e);return(t===0?e.od:e.ed)[n]}return(t===0?e.od:e.ed)[n]=slot(e,i,t===0?n:e.o.length+n,true)};const lazyService=(e,t,n,r,i,a)=>{const o={url:e,spec:t,kinds:n,ns:r,at:i,len:a,o:[],e:[],oi:0,ei:0};if(!Qt&&i!==void 0)prime(o);return{o:()=>{const e=n[o.o.length];const t=function op(e){return e===G?dataOf(o,0,o.o.indexOf(op))(G):call(op,e)};o.o.push(e===`p`?asOpPaginated(t):e===`s`?asOpStreaming(t):asOp(t));return t},e:e=>{const t={[e]:function(e){return new.target?newError(e,new.target,void 0):dataOf(o,1,o.e.indexOf(this))(e)}}[e];o.e.push(asError(t));return t},get E(){const e=this.e;return new Proxy({},{get:(t,n)=>e(n)})}}};const namespaceOf=e=>e.ns??=globalThis.process.getBuiltinModule(`node:module`).createRequire(e.url)(e.spec);let $t;const lazyNamespace=(e,t)=>new Proxy({url:e,spec:t},$t??={get:(e,t)=>namespaceOf(e)[t],has:(e,t)=>t in namespaceOf(e),ownKeys:e=>Reflect.ownKeys(namespaceOf(e)),getOwnPropertyDescriptor:(e,t)=>{const n=Reflect.getOwnPropertyDescriptor(namespaceOf(e),t);return n&&{...n,configurable:true}},getPrototypeOf:()=>null,set:()=>false,defineProperty:()=>false,deleteProperty:()=>false});var ConfigError=class extends (/*@__PURE__*/ B()(`ConfigError`,{message:z,key:/*@__PURE__*/ R(z)}).pipe(_e)){};const en=`effect/ConfigProvider`;const fromEnv=e=>globalThis.process?.env?.[e];var Missing=class{name;constructor(e){this.name=e}};const Y=/*@__PURE__*/ Symbol(`defer`);const tn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/config/read`);const readerOf=e=>e[tn];const nn={key:en};const hasProvider=e=>l.getOrUndefined(e,nn)!==void 0;const missingError=e=>new ConfigError({key:e.name,message:`Expected ${e.name} to be set`});const fromReader=e=>{const t=u.withFiber(t=>{if(hasProvider(t.context))return e.viaEffect();const n=e.read();if(n===Y)return e.viaEffect();return n instanceof Missing?u.fail(missingError(n)):u.succeed(n)});t[tn]=e;return t};const lookup=e=>u.flatMap(u.context(),t=>{const n=t.mapUnsafe.get(en);if(!n)return u.succeed(fromEnv(e));return u.map(n.load([e]),e=>e?._tag===`Value`?e.value:void 0)});const required=e=>fromReader({read:()=>fromEnv(e)??new Missing(e),viaEffect:()=>u.flatMap(lookup(e),t=>t===void 0?u.fail(missingError(new Missing(e))):u.succeed(t))});const String$1=e=>required(e);const Redacted=e=>map(e=>oe.make(e))(required(e));const isMissed=e=>typeof e===`object`&&e!==null&&e._tag===`ConfigError`;const catchMissed=(e,t)=>u.catchIf(e,isMissed,t);const option=e=>{const viaEffect=()=>catchMissed(u.map(e,m.some),()=>u.succeed(m.none()));const t=readerOf(e);if(!t)return viaEffect();return fromReader({read:()=>{const e=t.read();if(e===Y)return Y;return e instanceof Missing?m.none():m.some(e)},viaEffect})};const withDefault=e=>t=>{const viaEffect=()=>catchMissed(t,()=>u.succeed(e));const n=readerOf(t);if(!n)return viaEffect();return fromReader({read:()=>{const t=n.read();return t instanceof Missing?e:t},viaEffect})};const orElse=e=>t=>{const viaEffect=()=>catchMissed(t,e);const n=readerOf(t);if(!n)return viaEffect();return fromReader({read:()=>{const t=n.read();if(!(t instanceof Missing))return t;const r=readerOf(e());return r?r.read():Y},viaEffect})};const map=e=>t=>{const n=readerOf(t);if(!n)return u.map(t,e);return fromReader({read:()=>{const t=n.read();return t===Y||t instanceof Missing?t:e(t)},viaEffect:()=>u.map(n.viaEffect(),e)})};const all=e=>{const viaEffect=()=>u.all(e);const t=Object.keys(e);const n=t.map(t=>readerOf(e[t]));if(n.some(e=>e===void 0))return viaEffect();return fromReader({read:()=>{const e={};for(let r=0;r<t.length;r++){const i=n[r].read();if(i===Y||i instanceof Missing)return i;e[t[r]]=i}return e},viaEffect})};const X=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/annotation-meta`);function makeAnnotation(e,t){const fn=n=>n.annotate({[e]:t});fn[X]=[{symbol:e,value:t}];fn[e]=t;return fn}function all$1(...e){const t=[];const n={};for(const r of e)for(const e of r[X]){t.push(e);n[e.symbol]=e.value}const fn=e=>e.annotate(n);fn[X]=t;for(const{symbol:e,value:n}of t)fn[e]=n;return fn}const rn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http`);const Http=e=>makeAnnotation(rn,e);const an=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/label`);const Label=e=>makeAnnotation(an,e??true);const on=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/label-encoding`);const LabelEncoding=e=>{if(!/^[!$&'()*+,;=:@]*$/.test(e.preserve))throw new TypeError(`LabelEncoding can preserve only URI path-segment delimiters`);return makeAnnotation(on,e.preserve)};const sn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/response-code`);const ResponseCode=()=>makeAnnotation(sn,true);const cn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/header`);const Header=e=>makeAnnotation(cn,e??true);const ln=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/body`);const Body=e=>makeAnnotation(ln,e??true);const un=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/query`);const Query=e=>makeAnnotation(un,e??true);const dn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/comma-delimited`);const CommaDelimited=e=>makeAnnotation(dn,true);const pn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/deep-query`);const DeepQuery=e=>makeAnnotation(pn,e??true);const mn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http-body`);const HttpBody=()=>makeAnnotation(mn,true);const hn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/http/string-encoded`);const StringEncoded=()=>makeAnnotation(hn,true);const gn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/form-data-file`);const FormDataFile=()=>makeAnnotation(gn,true);const _n=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/key-dictionary`);const KeyDictionary=e=>makeAnnotation(_n,e);const vn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/union-cases`);const UnionCases=(e,t)=>makeAnnotation(vn,t?{cases:e,discriminator:t}:{cases:e});const yn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/error-matchers`);const applyErrorMatchers=(e,t)=>{e[yn]=t;return e};const getErrorMatchers=e=>e?.[yn];const bn={status:yt,code:/*@__PURE__*/ R(z),message:/*@__PURE__*/ R(z),body:wt};var SchemaMismatch=class extends Error{name=`SchemaError`;path;expected;actual;constructor(e,t,n){super(`Expected ${t}, got ${show(n)}${e.length?` at ${JSON.stringify(e.map(e=>typeof e===`symbol`?String(e):e))}`:``}`);this.path=e;this.expected=t;this.actual=n}};const withholdActual=e=>new SchemaMismatch(e.path,e.expected,`[REDACTED]`);const show=e=>{if(e===Z)return`nothing (missing key)`;if(e===void 0)return`undefined`;if(typeof e===`string`)return JSON.stringify(e.length>40?`${e.slice(0,40)}...`:e);if(Array.isArray(e))return`an array`;if(e!==null&&typeof e===`object`)return`an object`;return String(e)};const Z=Symbol(`missing`);const makeCompile=e=>{const fail=(e,t)=>({path:[],expected:e,actual:t});const ok=()=>void 0;const typeOf=e=>t=>typeof t===e?void 0:fail(e,t);const t=/* @__PURE__ */ new WeakMap;const compile=e=>{let n=t.get(e);if(n===void 0){let r;t.set(e,e=>r(e));r=n=withChecks(e,build(e));t.set(e,n)}return n};const withChecks=(e,t)=>{const n=e.checks;if(!n?.length||isLite(e))return t;const r=[];const add=e=>e._tag===`FilterGroup`?e.checks.forEach(add):r.push(e);n.forEach(add);return n=>{const i=t(n);if(i)return i;for(const t of r){const r=t.run(n,e,{});if(r!==void 0&&r!==true)return fail(String(t.annotations?.expected??`a valid value`),n)}}};const isLite=e=>e[`~lite`]===true;const isOptional=e=>e.context?.isOptional===true;const build=e=>{const t=e.encoding;if(t?.length&&!isLite(e))return compile(t[t.length-1].to);switch(e._tag){case`String`:case`TemplateLiteral`:return typeOf(`string`);case`Number`:return typeOf(`number`);case`Boolean`:return typeOf(`boolean`);case`BigInt`:return typeOf(`bigint`);case`Symbol`:return typeOf(`symbol`);case`Null`:return e=>e===null?void 0:fail(`null`,e);case`Undefined`:return e=>e===void 0?void 0:fail(`undefined`,e);case`Never`:return e=>fail(`never`,e);case`Literal`:case`UniqueSymbol`:{const t=e._tag===`Literal`?e.literal:e.symbol;return e=>e===t?void 0:fail(show(t),e)}case`Enum`:{const t=e.enums.map(e=>e[1]);return e=>t.includes(e)?void 0:fail(`an enum value`,e)}case`ObjectKeyword`:return e=>typeof e===`object`&&e!==null||typeof e===`function`?void 0:fail(`object | function`,e);case`Union`:return union(e);case`Arrays`:return arrays(e);case`Objects`:return objects(e);case`Suspend`:{let t;return n=>(t??=compile(e.thunk()))(n)}case`Declaration`:if(isLite(e)){const t=e.check;const n=String(e.annotations?.identifier??`a valid value`);return t?e=>t(e)?void 0:fail(n,e):ok}return declaration(e);default:return ok}};const declaration=e=>{const t=e.run;if(!t||e.typeParameters?.length)return ok;let n;return r=>{return(n??=t([]))(r,e,{})?._tag===`Failure`?fail(String(e.annotations?.identifier??e.annotations?.expected??`a valid value`),r):void 0}};const union=e=>{const t=e.types.map(compile);return e=>{let n;for(let r=0;r<t.length;r++){const i=t[r](e);if(i===void 0)return void 0;n??=i}return t.length===1?n:fail(`a union member`,e)}};const arrays=e=>{const t=(e.elements??[]).map(e=>[compile(e),isOptional(e)]);const n=(e.rest??[]).map(compile);const r=n[0];const i=n.slice(1);return e=>{if(!Array.isArray(e))return fail(`array`,e);const n=e.length;for(let r=0;r<t.length;r++){const[i,a]=t[r];if(r>=n){if(a)continue;return at(fail(`an element`,Z),r)}const o=i(e[r]);if(o)return at(o,r)}if(r===void 0)return n>t.length?at(fail(`never`,e[t.length]),t.length):void 0;const a=n-i.length;if(a<t.length)return at(fail(`an element`,Z),n);for(let n=t.length;n<a;n++){const t=r(e[n]);if(t)return at(t,n)}for(let t=0;t<i.length;t++){const n=i[t](e[a+t]);if(n)return at(n,a+t)}}};const at=(e,t)=>{e.path.push(t);return e};const objects=t=>{const n=(t.propertySignatures??[]).map(e=>[e.name,compile(e.type),isOptional(e.type)]);const r=(t.indexSignatures??[]).map(e=>[compile(e.parameter),compile(e.type)]);const i=new Set(n.map(e=>e[0]));if(n.length===0&&r.length===0)return e=>e===null||e===void 0?fail(`{}`,e):void 0;return t=>{if(typeof t!==`object`||t===null||Array.isArray(t))return fail(`object`,t);const a=t;for(let e=0;e<n.length;e++){const[t,r,i]=n[e];if(!(t===`__proto__`?Object.hasOwn(a,t):t in a)){if(i)continue;return at(fail(`a value`,Z),t)}const o=r(a[t]);if(o)return at(o,t)}if(r.length||e)for(const t of Object.keys(a)){if(i.has(t))continue;let n=false;for(const[e,i]of r){if(e(t)!==void 0)continue;n=true;const r=i(a[t]);if(r)return at(r,t)}if(e&&!n)return at(fail(`no value (the schema does not model this key)`,a[t]),t)}}};return compile};let xn;let Sn;const decoderFor=(e,t=false)=>{const n=t?wn:Cn;let decode=n.get(e);if(decode===void 0){const r=t?(Sn??=makeCompile(true))(e):(xn??=makeCompile(false))(e);decode=e=>{const t=r(e);return t===void 0?void 0:new SchemaMismatch(t.path.reverse(),t.expected,t.actual)};n.set(e,decode)}return decode};const Cn=/*@__PURE__*/ new WeakMap;const wn=/*@__PURE__*/ new WeakMap;const Q=/*@__PURE__*/ l.Reference(`@distilled.cloud/core/ResponseValidation`,{defaultValue:()=>`lenient`});const $=/*@__PURE__*/ l.Reference(`@distilled.cloud/core/ResponseValidation/StrictDecoder`,{defaultValue:()=>void 0});const layerOfContext=e=>{const t=p.succeedContext(e);const n=Object.create(e);const r=Object.getPrototypeOf(t);for(const e of Reflect.ownKeys(r))if(e!==`pipe`)n[e]=r[e];n.build=t.build;return n};const Tn=/*@__PURE__*/ layerOfContext(/*@__PURE__*/ l.add(/*@__PURE__*/ l.make(Q,`strict`),$,decoderFor));const En=/*@__PURE__*/ layerOfContext(/*@__PURE__*/ l.add(/*@__PURE__*/ l.make(Q,`additionalProperties`),$,decoderFor));const Dn=/*@__PURE__*/ layerOfContext(/*@__PURE__*/ l.make(Q,`lenient`));const On=/*@__PURE__*/ u.map(Q,e=>e!==`lenient`);const failUnlessLenient=(e,t)=>u.flatMap(Q,n=>n===`lenient`?u.succeed(t):u.fail(e));const checkResponse=(e,t,n)=>{const r=l.get(e,Q);if(r===`lenient`)return void 0;const i=l.get(e,$);if(!i)return new SchemaMismatch([],`the ResponseValidation.${r} layer`,r);return i(t,r===`strict`)(n)};const validateResponse=(e,t,n)=>u.withFiber(r=>{const i=checkResponse(r.context,e,t);return i===void 0?u.succeed(t):u.fail(n(i))});export{G as api$D,Protocol as api$Protocol,call as api$call,describeOperation as api$describeOperation,error as api$error,lazyNamespace as api$lazyNamespace,lazyService as api$lazyService,make as api$make,makePaginated as api$makePaginated,makeStreaming as api$makeStreaming,named as api$named,newError as api$newError,op as api$op,opPaginated as api$opPaginated,opStreaming as api$opStreaming,schema as api$schema,withValue as api$withValue,N as category$AbortedError,P as category$AlreadyExistsError,y as category$AuthError,b as category$BadRequestError,k as category$ConfigurationError,x as category$ConflictError,F as category$DependencyViolationError,M as category$LockedError,D as category$NetworkError,S as category$NotFoundError,O as category$ParseError,w as category$QuotaError,j as category$RetryableError,T as category$ServerError,E as category$ThrottlingError,A as category$TimeoutError,catchErrors as category$catch,catchErrors as category$catchErrors,Le as category$catchAbortedError,Re as category$catchAlreadyExistsError,we as category$catchAuthError,Te as category$catchBadRequestError,catchCategory as category$catchCategory,Ne as category$catchConfigurationError,Ee as category$catchConflictError,ze as category$catchDependencyViolationError,Ie as category$catchLockedError,je as category$catchNetworkError,De as category$catchNotFoundError,Me as category$catchParseError,Oe as category$catchQuotaError,Fe as category$catchRetryableError,ke as category$catchServerError,Ae as category$catchThrottlingError,Pe as category$catchTimeoutError,I as category$categoriesKey,hasCategory as category$hasCategory,isAbortedError as category$isAbortedError,isAlreadyExistsError as category$isAlreadyExistsError,isAuthError as category$isAuthError,isBadRequestError as category$isBadRequestError,isConfigurationError as category$isConfigurationError,isConflictError as category$isConflictError,isDependencyViolationError as category$isDependencyViolationError,isLockedError as category$isLockedError,isNetworkError as category$isNetworkError,isNotFoundError as category$isNotFoundError,isParseError as category$isParseError,isQuotaError as category$isQuotaError,isRetryable as category$isRetryable,isRetryableError as category$isRetryableError,isServerError as category$isServerError,isThrottling as category$isThrottling,isThrottlingError as category$isThrottlingError,isTimeoutError as category$isTimeoutError,isTransientError as category$isTransientError,se as category$retryableKey,xe as category$withAbortedError,Se as category$withAlreadyExistsError,ce as category$withAuthError,le as category$withBadRequestError,withCategory as category$withCategory,_e as category$withConfigurationError,ue as category$withConflictError,Ce as category$withDependencyViolationError,be as category$withLockedError,he as category$withNetworkError,de as category$withNotFoundError,ge as category$withParseError,fe as category$withQuotaError,withRetryable as category$withRetryable,ye as category$withRetryableError,pe as category$withServerError,me as category$withThrottlingError,ve as category$withTimeoutError,ConfigError as config$ConfigError,Redacted as config$Redacted,String$1 as config$String,all as config$all,map as config$map,option as config$option,orElse as config$orElse,withDefault as config$withDefault,extractArrayItems as pagination$extractArrayItems,extractItems as pagination$extractItems,getItems as pagination$getItems,getPath as pagination$getPath,isTerminalToken as pagination$isTerminalToken,missingPaginationConfig as pagination$missingPaginationConfig,nextLink as pagination$nextLink,paginateCursor as pagination$paginateCursor,paginateKeyset as pagination$paginateKeyset,paginateLink as pagination$paginateLink,paginatePageNumber as pagination$paginatePageNumber,paginateRelay as pagination$paginateRelay,paginateSingle as pagination$paginateSingle,paginateToken as pagination$paginateToken,paginateWithDefaults as pagination$paginateWithDefaults,recordPageHeaders as pagination$recordPageHeaders,Q as response_validation$ResponseValidation,SchemaMismatch as response_validation$SchemaMismatch,SchemaMismatch as response_validation_strict$SchemaMismatch,$ as response_validation$StrictDecoder,En as response_validation$additionalProperties,checkResponse as response_validation$checkResponse,failUnlessLenient as response_validation$failUnlessLenient,On as response_validation$isValidating,Dn as response_validation$lenient,Tn as response_validation$strict,validateResponse as response_validation$validateResponse,withholdActual as response_validation$withholdActual,withholdActual as response_validation_strict$withholdActual,decoderFor as response_validation_strict$decoderFor,V as retry$DEFAULT_SERVER_RETRY_HINT_CAP_MS,H as retry$ServerRetryHintCapMs,capped as retry$capped,Mt as retry$defaultOptions,kt as retry$jittered,makeDefault as retry$makeDefault,makeRetryService as retry$makeRetryService,readServerRetryHintCapMsFromEnv as retry$readServerRetryHintCapMsFromEnv,resolveServerRetryHintCapMs as retry$resolveServerRetryHintCapMs,serverHintMillis as retry$serverHintMillis,serverRetryHintCapLayer as retry$serverRetryHintCapLayer,throttlingFactory as retry$throttlingFactory,It as retry$throttlingOptions,transientFactory as retry$transientFactory,Rt as retry$transientOptions,Ke as schema_lite_impl$Any,Array$1 as schema_lite_impl$Array,We as schema_lite_impl$Boolean,Ze as schema_lite_impl$Date,Qe as schema_lite_impl$Duration,Literal as schema_lite_impl$Literal,Literals as schema_lite_impl$Literals,qe as schema_lite_impl$Null,NullOr as schema_lite_impl$NullOr,Ue as schema_lite_impl$Number,Record as schema_lite_impl$Record,Redacted$1 as schema_lite_impl$Redacted,He as schema_lite_impl$String,Struct as schema_lite_impl$Struct,StructWithRest as schema_lite_impl$StructWithRest,TaggedError as schema_lite_impl$TaggedError,Tuple as schema_lite_impl$Tuple,Ye as schema_lite_impl$Undefined,Union as schema_lite_impl$Union,Ge as schema_lite_impl$Unknown,Je as schema_lite_impl$Void,at as schema_lite_impl$at,declare as schema_lite_impl$declare,encodeKeys as schema_lite_impl$encodeKeys,Xe as schema_lite_impl$encodeKeysKey,fromNode as schema_lite_impl$fromNode,instanceOf as schema_lite_impl$instanceOf,isLite as schema_lite_impl$isLite,Be as schema_lite_impl$liteKey,optional as schema_lite_impl$optional,suspend as schema_lite_impl$suspend,toEffect as schema_lite_impl$toEffect,Dt as schema_lite_typed$Any,lt as schema_lite_typed$Array,xt as schema_lite_typed$Boolean,St as schema_lite_typed$Date,Ct as schema_lite_typed$Duration,bt as schema_lite_typed$Int,ft as schema_lite_typed$Literal,pt as schema_lite_typed$Literals,Tt as schema_lite_typed$Null,mt as schema_lite_typed$NullOr,yt as schema_lite_typed$Number,ut as schema_lite_typed$Record,vt as schema_lite_typed$Redacted,z as schema_lite_typed$String,ot as schema_lite_typed$Struct,st as schema_lite_typed$StructWithRest,B as schema_lite_typed$TaggedError,ht as schema_lite_typed$Tuple,dt as schema_lite_typed$Union,wt as schema_lite_typed$Unknown,Et as schema_lite_typed$Void,gt as schema_lite_typed$declare,_t as schema_lite_typed$instanceOf,R as schema_lite_typed$optional,ct as schema_lite_typed$suspend,SdkError as sdk_error$SdkError,loadModule as sdk_error$loadModule,Body as trait$Body,CommaDelimited as trait$CommaDelimited,DeepQuery as trait$DeepQuery,FormDataFile as trait$FormDataFile,Header as trait$Header,Http as trait$Http,HttpBody as trait$HttpBody,KeyDictionary as trait$KeyDictionary,Label as trait$Label,LabelEncoding as trait$LabelEncoding,Query as trait$Query,ResponseCode as trait$ResponseCode,StringEncoded as trait$StringEncoded,UnionCases as trait$UnionCases,all$1 as trait$all,X as trait$annotationMetaSymbol,applyErrorMatchers as trait$applyErrorMatchers,ln as trait$bodySymbol,dn as trait$commaDelimitedSymbol,pn as trait$deepQuerySymbol,yn as trait$errorMatchersSymbol,gn as trait$formDataFileSymbol,getErrorMatchers as trait$getErrorMatchers,cn as trait$headerSymbol,mn as trait$httpBodySymbol,rn as trait$httpSymbol,_n as trait$keyDictionarySymbol,on as trait$labelEncodingSymbol,an as trait$labelSymbol,makeAnnotation as trait$makeAnnotation,un as trait$querySymbol,sn as trait$responseCodeSymbol,hn as trait$stringEncodedSymbol,vn as trait$unionCasesSymbol,bn as unknown_error$UnknownErrorFields};
|
|
4
|
+
`,r)+1,importValues:[],v:[]}};const fileOf=e=>/^file:\/\/\/[^%?#]*$/.test(e.url)&&globalThis.process.platform!==`win32`?e.url.slice(7,e.url.lastIndexOf(`/`)+1)+e.spec:node(`node:url`).fileURLToPath(new URL(e.spec,e.url));const sliced=e=>{if(e.ix!==void 0)return e.ix;e.ix=false;if(e.at===void 0||e.od)return false;try{Function(``);const t=fileOf(e);e.ix=indexOf(t,read({file:t},e.at,e.len));e.od=[];e.ed=[]}catch{e.ix=false}return e.ix};let bn=false;const prime=e=>{bn=true;queueMicrotask(()=>{const t=sliced(e);if(t&&t.imports>0)importOf(e,t,0)})};const lineOf=(e,t)=>{const n=e.tableAt+5*t;return e.raw.slice(e.linesAt+parseInt(e.raw.slice(n,n+5),36),e.linesAt+parseInt(e.raw.slice(n+5,n+10),36)-1)};const nameOf=(e,t)=>lineOf(e,t).split(`|`)[0].split(` `)[3];const importSpec=(e,t)=>(e.specs??=e.raw.slice(e.importsAt,e.tableAt-1).split(` `))[t].split(`:`);const importOf=(e,t,n)=>{if(n in t.importValues)return t.importValues[n];const[,r,i]=importSpec(t,n);return t.importValues[n]=e.ns[+r][i]};const refOf=(e,t,n)=>n<t.imports?importOf(e,t,n):valueOf(e,t,n-t.imports);const evaluate=(e,t,n)=>{const[r,i,a]=lineOf(t,n).split(`|`);const o=a?a.split(` `).map(e=>parseInt(e,36)):[];const s=o.map(e=>e<t.imports?importSpec(t,e)[0]:nameOf(t,e-t.imports));const c=o.map(n=>refOf(e,t,n));const l=`\n//# sourceURL=${t.file}#${nameOf(t,n)}`;if(i&&i[0]!==`(`){const[e,n]=i.split(`;`);const[r,a,o]=n.split(` `).map(e=>parseInt(e,36));return compileBody(t,s,c,e?e.split(`,`):[],r,a,o,l)}const[,u,d]=r.split(` `).map(e=>parseInt(e,36));let f;if(i?.[0]===`(`){const e=i.slice(1).split(`,`);const n={names:s.slice(),values:c.slice()};f=``;let r=u;e.forEach((e,i)=>{const[a,o,u,d,p]=e.split(` `).map(e=>parseInt(e,36));const m=e.split(` `)[5];let h;s.push(`$lazy${i}`);c.push(function(){h??=compileBody(t,n.names,n.values,m?m.split(`+`):[],u,d,p,l);return h.apply(this,arguments)});f+=`${read(t,r,a-r)}$lazy${i}`;r=o});f+=read(t,r,d-r)}else f=read(t,u,d-u);return Function(...s,`"use strict";return(${f}\n)${l}`)(...c)};const compileBody=(e,t,n,r,i,a,o,s)=>{const c=read(e,i,a-i);const l=t.map(e=>!r.includes(e));return Function(...t.filter((e,t)=>l[t]),...r,`"use strict";${o?`return(${c}\n)`:`{${c}\n}`}${s}`).bind(void 0,...n.filter((e,t)=>l[t]))};const dataFn=(e,t,n)=>{const[r,i,a]=n.slice(1).split(`;`);const o=i.indexOf(` `);const s=parseInt(i,36);const c=read(t,s,parseInt(i.slice(o+1),36)-s);const l=[];if(a)for(const n of a.split(`,`)){const r=parseInt(n,36);l.push(r<t.imports?importOf(e,t,r):slot(e,t,r-t.imports,false))}return[r?c.replaceAll(`%`,r):c,l]};const slot=(e,t,n,r)=>{if(!r){if(n in t.v)return t.v[n]===yn?void 0:t.v[n];const r=e.o.length;if(n<r)return t.v[n]=e.o[n];if(n<r+e.e.length)return t.v[n]=e.e[n-r]}const i=t.tableAt+5*n;const a=t.raw.slice(t.linesAt+parseInt(t.raw.slice(i,i+5),36),t.linesAt+parseInt(t.raw.slice(i+5,i+10),36)-1);const o=a.indexOf(`|`);if(a[o+1]===`=`){const i=dataFn.bind(void 0,e,t,a.slice(o+1));return r?i:t.v[n]=i}if(r)return evaluate(e,t,n);if(a[0]===`1`){let r;return t.v[n]=function(){return(r??=evaluate(e,t,n)).apply(this,arguments)}}t.v[n]=yn;return t.v[n]=evaluate(e,t,n)};const valueOf=(e,t,n)=>slot(e,t,n,false);const dataOf=(e,t,n)=>{const r=t===0?e.od:e.ed;if(r?.[n])return r[n];const i=sliced(e);if(!i){load(e);return(t===0?e.od:e.ed)[n]}return(t===0?e.od:e.ed)[n]=slot(e,i,t===0?n:e.o.length+n,true)};const lazyService=(e,t,n,r,i,a)=>{const o={url:e,spec:t,kinds:n,ns:r,at:i,len:a,o:[],e:[],oi:0,ei:0};if(!bn&&i!==void 0)prime(o);return{o:()=>{const e=n[o.o.length];const t=function op(e){return e===q?dataOf(o,0,o.o.indexOf(op))(q):call(op,e)};o.o.push(e===`p`?asOpPaginated(t):e===`s`?asOpStreaming(t):asOp(t));return t},e:e=>{const t={[e]:function(e){return new.target?newError(e,new.target,void 0):dataOf(o,1,o.e.indexOf(this))(e)}}[e];o.e.push(asError(t));return t},get E(){const e=this.e;return new Proxy({},{get:(t,n)=>e(n)})}}};const namespaceOf=e=>e.ns??=globalThis.process.getBuiltinModule(`node:module`).createRequire(e.url)(e.spec);let xn;const lazyNamespace=(e,t)=>new Proxy({url:e,spec:t},xn??={get:(e,t)=>namespaceOf(e)[t],has:(e,t)=>t in namespaceOf(e),ownKeys:e=>Reflect.ownKeys(namespaceOf(e)),getOwnPropertyDescriptor:(e,t)=>{const n=Reflect.getOwnPropertyDescriptor(namespaceOf(e),t);return n&&{...n,configurable:true}},getPrototypeOf:()=>null,set:()=>false,defineProperty:()=>false,deleteProperty:()=>false});var ConfigError=class extends (/*@__PURE__*/ kt()(`ConfigError`,{message:H,key:/*@__PURE__*/ V(H)}).pipe(be)){};const Sn=`effect/ConfigProvider`;const fromEnv=e=>globalThis.process?.env?.[e];var Missing=class{name;constructor(e){this.name=e}};const X=/*@__PURE__*/ Symbol(`defer`);const Cn=/*@__PURE__*/ Symbol.for(`@distilled.cloud/core/config/read`);const readerOf=e=>e[Cn];const wn={key:Sn};const hasProvider=e=>p.getOrUndefined(e,wn)!==void 0;const missingError=e=>new ConfigError({key:e.name,message:`Expected ${e.name} to be set`});const fromReader=e=>{const t=h.withFiber(t=>{if(hasProvider(t.context))return e.viaEffect();const n=e.read();if(n===X)return e.viaEffect();return n instanceof Missing?h.fail(missingError(n)):h.succeed(n)});t[Cn]=e;return t};const lookup=e=>h.flatMap(h.context(),t=>{const n=t.mapUnsafe.get(Sn);if(!n)return h.succeed(fromEnv(e));return h.map(n.load([e]),e=>e?._tag===`Value`?e.value:void 0)});const required=e=>fromReader({read:()=>fromEnv(e)??new Missing(e),viaEffect:()=>h.flatMap(lookup(e),t=>t===void 0?h.fail(missingError(new Missing(e))):h.succeed(t))});const String$1=e=>required(e);const Redacted=e=>map(e=>le.make(e))(required(e));const isMissed=e=>typeof e===`object`&&e!==null&&e._tag===`ConfigError`;const catchMissed=(e,t)=>h.catchIf(e,isMissed,t);const option=e=>{const viaEffect=()=>catchMissed(h.map(e,g.some),()=>h.succeed(g.none()));const t=readerOf(e);if(!t)return viaEffect();return fromReader({read:()=>{const e=t.read();if(e===X)return X;return e instanceof Missing?g.none():g.some(e)},viaEffect})};const withDefault=e=>t=>{const viaEffect=()=>catchMissed(t,()=>h.succeed(e));const n=readerOf(t);if(!n)return viaEffect();return fromReader({read:()=>{const t=n.read();return t instanceof Missing?e:t},viaEffect})};const orElse=e=>t=>{const viaEffect=()=>catchMissed(t,e);const n=readerOf(t);if(!n)return viaEffect();return fromReader({read:()=>{const t=n.read();if(!(t instanceof Missing))return t;const r=readerOf(e());return r?r.read():X},viaEffect})};const map=e=>t=>{const n=readerOf(t);if(!n)return h.map(t,e);return fromReader({read:()=>{const t=n.read();return t===X||t instanceof Missing?t:e(t)},viaEffect:()=>h.map(n.viaEffect(),e)})};const all=e=>{const viaEffect=()=>h.all(e);const t=Object.keys(e);const n=t.map(t=>readerOf(e[t]));if(n.some(e=>e===void 0))return viaEffect();return fromReader({read:()=>{const e={};for(let r=0;r<t.length;r++){const i=n[r].read();if(i===X||i instanceof Missing)return i;e[t[r]]=i}return e},viaEffect})};const Tn={status:bt,code:/*@__PURE__*/ V(H),message:/*@__PURE__*/ V(H),body:Tt};var SchemaMismatch=class extends Error{name=`SchemaError`;path;expected;actual;constructor(e,t,n){super(`Expected ${t}, got ${show(n)}${e.length?` at ${JSON.stringify(e.map(e=>typeof e===`symbol`?String(e):e))}`:``}`);this.path=e;this.expected=t;this.actual=n}};const withholdActual=e=>new SchemaMismatch(e.path,e.expected,`[REDACTED]`);const show=e=>{if(e===Z)return`nothing (missing key)`;if(e===void 0)return`undefined`;if(typeof e===`string`)return JSON.stringify(e.length>40?`${e.slice(0,40)}...`:e);if(Array.isArray(e))return`an array`;if(e!==null&&typeof e===`object`)return`an object`;return String(e)};const Z=Symbol(`missing`);const makeCompile=e=>{const fail=(e,t)=>({path:[],expected:e,actual:t});const ok=()=>void 0;const t=new Set(Reflect.ownKeys(Object.prototype)).add(`__proto__`);const ownOnly=e=>t.has(typeof e===`number`?String(e):e);const typeOf=e=>t=>typeof t===e?void 0:fail(e,t);const n=/* @__PURE__ */ new WeakMap;const compile=e=>{let t=n.get(e);if(t===void 0){let r;n.set(e,e=>r(e));r=t=withChecks(e,build(e));n.set(e,t)}return t};const withChecks=(e,t)=>{const n=e.checks;if(!n?.length||isLite(e))return t;const r=[];const add=e=>e._tag===`FilterGroup`?e.checks.forEach(add):r.push(e);n.forEach(add);return n=>{const i=t(n);if(i)return i;for(const t of r){const r=t.run(n,e,{});if(r!==void 0&&r!==true)return fail(String(t.annotations?.expected??`a valid value`),n)}}};const isLite=e=>e[`~lite`]===true;const isOptional=e=>e.context?.isOptional===true;const build=e=>{const t=e.encoding;if(t?.length&&!isLite(e))return compile(t[t.length-1].to);switch(e._tag){case`String`:case`TemplateLiteral`:return typeOf(`string`);case`Number`:return typeOf(`number`);case`Boolean`:return typeOf(`boolean`);case`BigInt`:return typeOf(`bigint`);case`Symbol`:return typeOf(`symbol`);case`Null`:return e=>e===null?void 0:fail(`null`,e);case`Undefined`:return e=>e===void 0?void 0:fail(`undefined`,e);case`Never`:return e=>fail(`never`,e);case`Literal`:case`UniqueSymbol`:{const t=e._tag===`Literal`?e.literal:e.symbol;return e=>e===t?void 0:fail(show(t),e)}case`Enum`:{const t=e.enums.map(e=>e[1]);return e=>t.includes(e)?void 0:fail(`an enum value`,e)}case`ObjectKeyword`:return e=>typeof e===`object`&&e!==null||typeof e===`function`?void 0:fail(`object | function`,e);case`Union`:return union(e);case`Arrays`:return arrays(e);case`Objects`:return objects(e);case`Suspend`:{let t;return n=>(t??=compile(e.thunk()))(n)}case`Declaration`:if(isLite(e)){const t=e.check;const n=String(e.annotations?.identifier??`a valid value`);return t?e=>t(e)?void 0:fail(n,e):ok}return declaration(e);default:return ok}};const declaration=e=>{const t=e.run;if(!t||e.typeParameters?.length)return ok;let n;return r=>{return(n??=t([]))(r,e,{})?._tag===`Failure`?fail(String(e.annotations?.identifier??e.annotations?.expected??`a valid value`),r):void 0}};const union=e=>{const t=e.types.map(compile);return e=>{let n;for(let r=0;r<t.length;r++){const i=t[r](e);if(i===void 0)return void 0;n??=i}return t.length===1?n:fail(`a union member`,e)}};const arrays=e=>{const t=(e.elements??[]).map(e=>[compile(e),isOptional(e)]);const n=(e.rest??[]).map(compile);const r=n[0];const i=n.slice(1);return e=>{if(!Array.isArray(e))return fail(`array`,e);const n=e.length;for(let r=0;r<t.length;r++){const[i,a]=t[r];if(r>=n){if(a)continue;return at(fail(`an element`,Z),r)}const o=i(e[r]);if(o)return at(o,r)}if(r===void 0)return n>t.length?at(fail(`never`,e[t.length]),t.length):void 0;const a=n-i.length;if(a<t.length)return at(fail(`an element`,Z),n);for(let n=t.length;n<a;n++){const t=r(e[n]);if(t)return at(t,n)}for(let t=0;t<i.length;t++){const n=i[t](e[a+t]);if(n)return at(n,a+t)}}};const at=(e,t)=>{e.path.push(t);return e};const objects=t=>{const n=(t.propertySignatures??[]).map(e=>[e.name,compile(e.type),isOptional(e.type),ownOnly(e.name)]);const r=(t.indexSignatures??[]).map(e=>[compile(e.parameter),compile(e.type)]);const i=new Set(n.map(e=>e[0]));if(n.length===0&&r.length===0)return e=>e===null||e===void 0?fail(`{}`,e):void 0;return t=>{if(typeof t!==`object`||t===null||Array.isArray(t))return fail(`object`,t);const a=t;for(let e=0;e<n.length;e++){const[t,r,i,o]=n[e];if(!(Object.hasOwn(a,t)||!o&&t in a)){if(i)continue;return at(fail(`a value`,Z),t)}const s=r(a[t]);if(s)return at(s,t)}if(r.length||e)for(const t of Object.keys(a)){if(i.has(t))continue;let n=false;for(const[e,i]of r){if(e(t)!==void 0)continue;n=true;const r=i(a[t]);if(r)return at(r,t)}if(e&&!n)return at(fail(`no value (the schema does not model this key)`,a[t]),t)}}};return compile};let En;let Dn;const decoderFor=(e,t=false)=>{const n=t?kn:On;let decode=n.get(e);if(decode===void 0){const r=t?(Dn??=makeCompile(true))(e):(En??=makeCompile(false))(e);decode=e=>{const t=r(e);return t===void 0?void 0:new SchemaMismatch(t.path.reverse(),t.expected,t.actual)};n.set(e,decode)}return decode};const On=/*@__PURE__*/ new WeakMap;const kn=/*@__PURE__*/ new WeakMap;const Q=/*@__PURE__*/ p.Reference(`@distilled.cloud/core/ResponseValidation`,{defaultValue:()=>`lenient`});const $=/*@__PURE__*/ p.Reference(`@distilled.cloud/core/ResponseValidation/StrictDecoder`,{defaultValue:()=>void 0});const layerOfContext=e=>{const t=se.succeedContext(e);const n=Object.create(e);const r=Object.getPrototypeOf(t);for(const e of Reflect.ownKeys(r))if(e!==`pipe`)n[e]=r[e];n.build=t.build;return n};const An=/*@__PURE__*/ layerOfContext(/*@__PURE__*/ p.add(/*@__PURE__*/ p.make(Q,`strict`),$,decoderFor));const jn=/*@__PURE__*/ layerOfContext(/*@__PURE__*/ p.add(/*@__PURE__*/ p.make(Q,`additionalProperties`),$,decoderFor));const Mn=/*@__PURE__*/ layerOfContext(/*@__PURE__*/ p.make(Q,`lenient`));const Nn=/*@__PURE__*/ h.map(Q,e=>e!==`lenient`);const failUnlessLenient=(e,t)=>h.flatMap(Q,n=>n===`lenient`?h.succeed(t):h.fail(e));const checkResponse=(e,t,n)=>{const r=p.get(e,Q);if(r===`lenient`)return void 0;const i=p.get(e,$);if(!i)return new SchemaMismatch([],`the ResponseValidation.${r} layer`,r);return i(t,r===`strict`)(n)};const validateResponse=(e,t,n)=>h.withFiber(r=>{const i=checkResponse(r.context,e,t);return i===void 0?h.succeed(t):h.fail(n(i))});export{q as api$D,call as api$call,cannotStream as api$cannotStream,describeOperation as api$describeOperation,encodeRequest as api$encodeRequest,error as api$error,lazyNamespace as api$lazyNamespace,lazyService as api$lazyService,make as api$make,makePaginated as api$makePaginated,makeStreaming as api$makeStreaming,named as api$named,newError as api$newError,op as api$op,opPaginated as api$opPaginated,opStreaming as api$opStreaming,schema as api$schema,withValue as api$withValue,P as category$AbortedError,F as category$AlreadyExistsError,b as category$AuthError,x as category$BadRequestError,A as category$ConfigurationError,S as category$ConflictError,I as category$DependencyViolationError,N as category$LockedError,O as category$NetworkError,w as category$NotFoundError,k as category$ParseError,T as category$QuotaError,M as category$RetryableError,E as category$ServerError,D as category$ThrottlingError,j as category$TimeoutError,catchErrors as category$catch,catchErrors as category$catchErrors,Be as category$catchAbortedError,Ve as category$catchAlreadyExistsError,De as category$catchAuthError,Oe as category$catchBadRequestError,catchCategory as category$catchCategory,Ie as category$catchConfigurationError,ke as category$catchConflictError,He as category$catchDependencyViolationError,ze as category$catchLockedError,Pe as category$catchNetworkError,Ae as category$catchNotFoundError,Fe as category$catchParseError,je as category$catchQuotaError,Re as category$catchRetryableError,Me as category$catchServerError,Ne as category$catchThrottlingError,Le as category$catchTimeoutError,L as category$categoriesKey,hasCategory as category$hasCategory,isAbortedError as category$isAbortedError,isAlreadyExistsError as category$isAlreadyExistsError,isAuthError as category$isAuthError,isBadRequestError as category$isBadRequestError,isConfigurationError as category$isConfigurationError,isConflictError as category$isConflictError,isDependencyViolationError as category$isDependencyViolationError,isLockedError as category$isLockedError,isNetworkError as category$isNetworkError,isNotFoundError as category$isNotFoundError,isParseError as category$isParseError,isQuotaError as category$isQuotaError,isRetryable as category$isRetryable,isRetryableError as category$isRetryableError,isServerError as category$isServerError,isThrottling as category$isThrottling,isThrottlingError as category$isThrottlingError,isTimeoutError as category$isTimeoutError,isTransientError as category$isTransientError,ue as category$retryableKey,we as category$withAbortedError,Te as category$withAlreadyExistsError,de as category$withAuthError,fe as category$withBadRequestError,withCategory as category$withCategory,be as category$withConfigurationError,pe as category$withConflictError,Ee as category$withDependencyViolationError,Ce as category$withLockedError,ve as category$withNetworkError,me as category$withNotFoundError,ye as category$withParseError,he as category$withQuotaError,withRetryable as category$withRetryable,Se as category$withRetryableError,ge as category$withServerError,_e as category$withThrottlingError,xe as category$withTimeoutError,ConfigError as config$ConfigError,Redacted as config$Redacted,String$1 as config$String,all as config$all,map as config$map,option as config$option,orElse as config$orElse,withDefault as config$withDefault,extractArrayItems as pagination$extractArrayItems,extractItems as pagination$extractItems,getItems as pagination$getItems,getPath as pagination$getPath,isTerminalToken as pagination$isTerminalToken,missingPaginationConfig as pagination$missingPaginationConfig,nextLink as pagination$nextLink,paginateCursor as pagination$paginateCursor,paginateKeyset as pagination$paginateKeyset,paginateLink as pagination$paginateLink,paginatePageNumber as pagination$paginatePageNumber,paginateRelay as pagination$paginateRelay,paginateSingle as pagination$paginateSingle,paginateToken as pagination$paginateToken,paginateWithDefaults as pagination$paginateWithDefaults,recordPageHeaders as pagination$recordPageHeaders,Q as response_validation$ResponseValidation,SchemaMismatch as response_validation$SchemaMismatch,SchemaMismatch as response_validation_strict$SchemaMismatch,$ as response_validation$StrictDecoder,jn as response_validation$additionalProperties,checkResponse as response_validation$checkResponse,failUnlessLenient as response_validation$failUnlessLenient,Nn as response_validation$isValidating,Mn as response_validation$lenient,An as response_validation$strict,validateResponse as response_validation$validateResponse,withholdActual as response_validation$withholdActual,withholdActual as response_validation_strict$withholdActual,decoderFor as response_validation_strict$decoderFor,jt as retry$BOUNDED_HINT_MAX_EXTRA_MS,Pt as retry$DEFAULT_SERVER_RETRY_HINT_CAP_MS,It as retry$ServerRetryHintCapMs,capped as retry$capped,Mt as retry$defaultBudget,U as retry$defaultOptions,defaultWith as retry$defaultWith,Nt as retry$jittered,makeBudget as retry$makeBudget,makeDefault as retry$makeDefault,makeRetryService as retry$makeRetryService,readServerRetryHintCapMsFromEnv as retry$readServerRetryHintCapMsFromEnv,resolveServerRetryHintCapMs as retry$resolveServerRetryHintCapMs,serverHintMillis as retry$serverHintMillis,serverRetryHintCapLayer as retry$serverRetryHintCapLayer,throttlingFactory as retry$throttlingFactory,Ht as retry$throttlingOptions,transientFactory as retry$transientFactory,Wt as retry$transientOptions,Je as schema_lite_impl$Any,Array$1 as schema_lite_impl$Array,Ke as schema_lite_impl$Boolean,$e as schema_lite_impl$Date,et as schema_lite_impl$Duration,Extend as schema_lite_impl$Extend,Literal as schema_lite_impl$Literal,Literals as schema_lite_impl$Literals,Ye as schema_lite_impl$Null,NullOr as schema_lite_impl$NullOr,R as schema_lite_impl$Number,Record as schema_lite_impl$Record,Redacted$1 as schema_lite_impl$Redacted,Ge as schema_lite_impl$String,Struct as schema_lite_impl$Struct,StructWithRest as schema_lite_impl$StructWithRest,TaggedError as schema_lite_impl$TaggedError,Tuple as schema_lite_impl$Tuple,Ze as schema_lite_impl$Undefined,Union as schema_lite_impl$Union,qe as schema_lite_impl$Unknown,Xe as schema_lite_impl$Void,at as schema_lite_impl$at,declare as schema_lite_impl$declare,encodeKeys as schema_lite_impl$encodeKeys,Qe as schema_lite_impl$encodeKeysKey,fromNode as schema_lite_impl$fromNode,instanceOf as schema_lite_impl$instanceOf,isLite as schema_lite_impl$isLite,Ue as schema_lite_impl$liteKey,optional as schema_lite_impl$optional,representation as schema_lite_impl$representation,suspend as schema_lite_impl$suspend,toEffect as schema_lite_impl$toEffect,Ot as schema_lite_typed$Any,ut as schema_lite_typed$Array,St as schema_lite_typed$Boolean,Ct as schema_lite_typed$Date,wt as schema_lite_typed$Duration,xt as schema_lite_typed$Int,pt as schema_lite_typed$Literal,mt as schema_lite_typed$Literals,Et as schema_lite_typed$Null,ht as schema_lite_typed$NullOr,bt as schema_lite_typed$Number,dt as schema_lite_typed$Record,yt as schema_lite_typed$Redacted,H as schema_lite_typed$String,st as schema_lite_typed$Struct,ct as schema_lite_typed$StructWithRest,kt as schema_lite_typed$TaggedError,gt as schema_lite_typed$Tuple,ft as schema_lite_typed$Union,Tt as schema_lite_typed$Unknown,Dt as schema_lite_typed$Void,_t as schema_lite_typed$declare,vt as schema_lite_typed$instanceOf,V as schema_lite_typed$optional,lt as schema_lite_typed$suspend,SdkError as sdk_error$SdkError,loadModule as sdk_error$loadModule,Body as trait$Body,CommaDelimited as trait$CommaDelimited,DeepQuery as trait$DeepQuery,FormDataFile as trait$FormDataFile,Header as trait$Header,Http as trait$Http,HttpBody as trait$HttpBody,IdempotencyToken as trait$IdempotencyToken,KeyDictionary as trait$KeyDictionary,Label as trait$Label,LabelEncoding as trait$LabelEncoding,Query as trait$Query,ResponseCode as trait$ResponseCode,StringEncoded as trait$StringEncoded,UnionCases as trait$UnionCases,all$1 as trait$all,W as trait$annotationMetaSymbol,applyErrorMatchers as trait$applyErrorMatchers,Xt as trait$bodySymbol,$t as trait$commaDelimitedSymbol,en as trait$deepQuerySymbol,sn as trait$errorMatchersSymbol,rn as trait$formDataFileSymbol,getErrorMatchers as trait$getErrorMatchers,Yt as trait$headerSymbol,tn as trait$httpBodySymbol,Gt as trait$httpSymbol,Qt as trait$idempotencyTokenSymbol,an as trait$keyDictionarySymbol,qt as trait$labelEncodingSymbol,Kt as trait$labelSymbol,makeAnnotation as trait$makeAnnotation,Zt as trait$querySymbol,Jt as trait$responseCodeSymbol,nn as trait$stringEncodedSymbol,on as trait$unionCasesSymbol,Tn as unknown_error$UnknownErrorFields};
|
|
5
5
|
//# sourceMappingURL=base.js.map
|