const i=new Set([5,6,10,14]),d=new Set(["SQLITE_BUSY","SQLITE_LOCKED","SQLITE_IOERR","SQLITE_CANTOPEN","SERVER_ERROR","HRANA_CLOSED_ERROR","HRANA_WEBSOCKET_ERROR","HRANA_PROTO_ERROR","INTERNAL_ERROR","UNKNOWN"]),l=[/\bCode:\s*(5|6|10|14)\b/,"SQLITE_BUSY","SQLITE_LOCKED","SQLITE_IOERR","SQLITE_CANTOPEN","SERVER_ERROR","HRANA_CLOSED_ERROR","HRANA_WEBSOCKET_ERROR","HRANA_PROTO_ERROR","INTERNAL_ERROR","database is locked","unable to open database file","Connection reset by peer","connection refused","connection closed","stream error received","stream closed","stream has been closed","response failed","classification=Code","ECONNRESET","ECONNREFUSED","ETIMEDOUT","socket hang up","Replication(Client","Replication(Server","snapshot not found","code: Unavailable","code: Internal","code: DeadlineExceeded","code: Aborted","code: ResourceExhausted","Status { code: Unavailable","Status { code: Internal","bottomless","namespace doesn","write delegation"];function S(r){const n=new Set;for(let t=r;t instanceof Error&&!n.has(t);t=t.cause){n.add(t);const s=t.rawCode;if(typeof s=="number"&&i.has(s))return!0;const e=t.code;if(typeof e=="string"&&d.has(e))return!0;const o=t.message??"";for(const a of l)if(typeof a=="string"?o.includes(a):a.test(o))return!0}return!1}function T(r){if(!(r instanceof Error))return`non-error: ${String(r)}`;const n=[],t=new Set;let s=0;for(let e=r;e instanceof Error&&!t.has(e);e=e.cause,s++){t.add(e);const o=e.rawCode,a=e.code,E=e.message??"",R=E.length>240?`${E.slice(0,240)}\u2026`:E,c=s===0?"top":`cause${s}`;n.push(`[${c}] name=${e.name} code=${String(a??"n/a")} rawCode=${String(o??"n/a")} message=${JSON.stringify(R)}`)}return n.join(" <- ")}const _={maxAttempts:17,initialDelayMs:1e3,maxDelayMs:4e3},N={maxAttempts:3,initialDelayMs:200,maxDelayMs:600};async function O(r,n){let t=n.initialDelayMs,s;for(let e=1;e<=n.maxAttempts;e++)try{return await r()}catch(o){if(!S(o))throw o;if(s=o,e===n.maxAttempts)break;await new Promise(a=>setTimeout(a,t)),t=Math.min(t*2,n.maxDelayMs)}throw s}export{_ as BATCH_TRANSIENT_RETRY,N as HTTP_TRANSIENT_RETRY,d as TRANSIENT_SQLD_CODE_STRINGS,l as TRANSIENT_SQLD_MESSAGE_PATTERNS,i as TRANSIENT_SQLITE_RAW_CODES,T as describeTransientError,S as isTransientSqldError,O as withTransientErrorRetry};
