@vielzeug/courier 1.1.2 → 1.1.3

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/dist/courier.js CHANGED
@@ -1,4 +1,4 @@
1
- import{backoff as e,hash as t,isAbortError as n,retry as r,sleep as i,uuid as a}from"@vielzeug/arsenal";var o=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},s=class e extends o{url;method;status;data;headers;constructor(e){super(e.message),this.url=e.url,this.method=e.method,this.status=e.status,this.data=e.data,this.headers=e.headers}static fromResponse(t,n,r,i){return new e({data:n,headers:t.headers,message:t.statusText||`HTTP ${t.status}`,method:r,status:t.status,url:i})}static is(t,n){return t instanceof e&&(n===void 0||t.status===n)}},c=class extends o{url;method;constructor(e){super(e.message,{cause:e.cause}),this.url=e.url,this.method=e.method}},l=class extends o{url;method;constructor(e){super(e.message,{cause:e.cause}),this.url=e.url,this.method=e.method}},u=class extends o{url;method;constructor(e){super(e.message,{cause:e.cause}),this.url=e.url,this.method=e.method}},d=class extends o{data;constructor(e,t){super(e instanceof Error?e.message:String(e),{cause:e}),this.data=t}},f=class extends o{},p=class extends o{constructor(e){super(`[courier] ${e} disposed`)}},m=class extends o{};function h(e,t,n,r){let i=e instanceof Error?e.message:String(e),a=r?.reason;return a instanceof Error&&a.name===`TimeoutError`?new l({cause:e,message:i,method:t,url:n}):e instanceof DOMException?e.name===`TimeoutError`?new l({cause:e,message:i,method:t,url:n}):new u({cause:e,message:i,method:t,url:n}):e instanceof Error&&e.name===`AbortError`||r?.aborted?new u({cause:e,message:i,method:t,url:n}):new c({cause:e,message:i,method:t,url:n})}async function g(e,t=`auto`){if(t===`raw`)return e;if(e.status===204||e.status===205||e.status===304)return;if(t===`json`)return e.json();if(t===`text`)return e.text();if(t===`blob`)return e.blob();if(t===`arrayBuffer`)return e.arrayBuffer();let n=e.headers.get(`content-type`)??``;return n.includes(`application/json`)||n.includes(`+json`)?e.json():n.startsWith(`text/`)?e.text():n.startsWith(`image/`)||n.startsWith(`audio/`)||n.startsWith(`video/`)?e.blob():e.text()}function _(e,t,n,r,i){return n!==void 0&&!v(n)?{...i,body:JSON.stringify(n),headers:{"content-type":`application/json`,...t},method:e.toUpperCase(),signal:r}:{...i,...n!==void 0&&{body:n},headers:t,method:e.toUpperCase(),signal:r}}function v(e){return e instanceof FormData||e instanceof Blob||e instanceof URLSearchParams||typeof e==`string`||e instanceof ArrayBuffer||ArrayBuffer.isView(e)||typeof ReadableStream<`u`&&e instanceof ReadableStream}function y(e,t,n){return{headers:t,init:n,url:e,withHeaders(r){let i={...t};for(let[e,t]of Object.entries(r))i[e.toLowerCase()]=t;return y(e,i,n)}}}function b(...e){let t=e.filter(e=>e!=null);if(t.length!==0)return t.length===1?t[0]:AbortSignal.any(t)}var x=3e4;function S(e){if((e<=0||!Number.isFinite(e))&&e!==1/0)throw new o(`[courier] timeout must be a positive number or Infinity`)}function C(e,t){return e===1/0?t??void 0:b(AbortSignal.timeout(e),t)}function w(e={}){let{baseUrl:t=``,fetch:n=globalThis.fetch,headers:r={},timeout:i=x}=e;S(i);let a=Object.fromEntries(Object.entries(r).map(([e,t])=>[e.toLowerCase(),t])),o=new Set,s=new AbortController,c=[],l=null,u=!1;function d(){if(l)return l;let e=e=>n(e.url,{...e.init,headers:e.headers});return l=c.length===0?e:c.reduceRight((e,t)=>n=>t(n,e),e),l}function f(e){return c.push(e),l=null,()=>{let t=c.indexOf(e);t!==-1&&(c.splice(t,1),l=null)}}function p(e){for(let[t,n]of Object.entries(e)){let e=t.toLowerCase();n===void 0?delete a[e]:a[e]=n}}function m(){return{...a}}function h(e,t){let n=e?Object.fromEntries(Object.entries(e).map(([e,t])=>[e.toLowerCase(),t])):void 0;return{...a,...n,...t}}function g(e){return o.add(e),()=>o.delete(e)}function _(e){return d()(y(e.url,e.headers,e.init))}function v(){for(let e of[...o])e.abort();o.clear()}function b(){if(!u){u=!0,s.abort();for(let e of o)e.abort();o.clear(),c.length=0,l=null}}return{baseUrl:t,cancelAll:v,dispatch:_,get disposalSignal(){return s.signal},dispose:b,get disposed(){return u},getHeaders:m,getTimeout(){return i},headers:p,mergeHeaders:h,track:g,use:f}}function T(e,t,n,r){let i=e.replace(/\/+$/,``),a=t.replace(/^\/+/,``);a=a.replace(/\{([^}]+)\}/g,(e,r)=>{let i=n?.[r];if(i==null)throw new m(`unresolved path param {${r}} in '${t}'`);return encodeURIComponent(String(i))});let o=i&&a?`${i}/${a}`:i||a;if(!r)return o;let s=new URLSearchParams;for(let[e,t]of Object.entries(r))if(t!==void 0){if(Array.isArray(t)){for(let n of t)n!==void 0&&s.append(e,n===null?``:String(n));continue}s.append(e,t===null?``:String(t))}let c=s.toString();return c?`${o}${o.includes(`?`)?`&`:`?`}${c}`:o}var E=new Set([`GET`,`HEAD`,`OPTIONS`]);function D(e,n,r,i){if(E.has(e))return`${e}:${n}:${r}`;if(i!==void 0)return`${e}:${n}:${t(i)}`}function O(e){let{transport:t,...n}=e??{},r=t??w(n),i=!t,a=new Map;async function o(e,t,n,i,a,o){let c=t.signal,l;try{l=await r.dispatch({headers:e,init:t,url:n})}catch(e){throw h(e,i,n,c)}if(!l.ok){let e;try{e=await g(l,a??`auto`)}catch{e=await l.text().catch(()=>``)}throw s.fromResponse(l,e,i,n)}let u;try{u=await g(l,a??`auto`)}catch(e){throw h(e,i,n,c)}if(o)try{return o.parse(u)}catch(e){throw new d(e,u)}return u}async function c(e,t,n={}){if(r.disposed)throw new p(`ApiClient`);let i=e.toUpperCase(),s;try{s=T(r.baseUrl,t,n.params,n.query)}catch(e){throw h(e,i,t)}let{body:c,dedupe:l=!0,dedupeKey:u,fetchInit:d,headers:f,responseType:m,schema:g,signal:v,timeout:y}=n;y!==void 0&&S(y);let x=r.mergeHeaders(f),w=l?D(i,s,m??`auto`,u):void 0;if(w){let e=a.get(w);if(e)return e}let E=new AbortController,O=r.track(E),k=b(v,E.signal)??E.signal,{headers:A,...j}=_(i,x,c,C(y??r.getTimeout(),k),d??{}),M=o(A,j,s,i,m,g);w&&a.set(w,M);try{return await M}finally{w&&a.delete(w),O()}}return{cancelAll(){r.cancelAll(),a.clear()},delete:(e,t)=>c(`DELETE`,e,t),get disposalSignal(){return r.disposalSignal},dispose(){a.clear(),i&&r.dispose()},get disposed(){return r.disposed},get:(e,t)=>c(`GET`,e,t),getHeaders:r.getHeaders,headers:r.headers,patch:(e,t)=>c(`PATCH`,e,t),post:(e,t)=>c(`POST`,e,t),put:(e,t)=>c(`PUT`,e,t),request:c,[Symbol.dispose](){this.dispose()},use:r.use}}function k(e){let{maxSize:t=25,resolve:n,resolveSettled:r,window:i=0}=e,a=[],o=new AbortController,s=!1,c=null,l=!1;function u(){if(a.length===0)return;let e=a.splice(0,t);a.length>0&&d();let i=e.map(e=>e.key);try{r?r(i).then(t=>{if(t.length!==e.length){let n=new f(`Batcher: resolveSettled() returned ${t.length} results for ${e.length} keys`);for(let t of e)t.reject(n);return}e.forEach((e,n)=>{let r=t[n];r.status===`fulfilled`?e.resolve(r.value):e.reject(r.reason)})}).catch(t=>{for(let n of e)n.reject(t)}):n(i).then(t=>{if(t.length!==e.length){let n=new f(`Batcher: resolve() returned ${t.length} results for ${e.length} keys`);for(let t of e)t.reject(n);return}e.forEach((e,n)=>e.resolve(t[n]))}).catch(t=>{for(let n of e)n.reject(t)})}catch(t){for(let n of e)n.reject(t)}}function d(){s||(s=!0,i===0?queueMicrotask(()=>{s=!1,u()}):c=setTimeout(()=>{c=null,s=!1,u()},i))}return{get disposalSignal(){return o.signal},dispose(){if(l)return;l=!0,c!==null&&(clearTimeout(c),c=null);let e=new p(`Batcher`);for(let t of a.splice(0))t.reject(e);s=!1,o.abort()},get disposed(){return l},load(e){return l?Promise.reject(new p(`Batcher`)):new Promise((n,r)=>{a.push({key:e,reject:r,resolve:n}),a.length>=t?(c!==null&&(clearTimeout(c),c=null),s=!1,u()):d()})},[Symbol.dispose](){this.dispose()}}}function A(t){return Math.random()*e(t)}function j(e,t){if(typeof t==`function`){let n=t(e);return Number.isFinite(n)?Math.max(0,n):0}return typeof t==`number`?Number.isFinite(t)?Math.max(0,t):0:A(e)}var M=Object.freeze({data:void 0,error:null,isFetching:!1,isLoading:!1,status:`loading`,updatedAt:void 0});function N(e,t){let i=M,a=0,o=null,s=new Set,c=!1,l=null;function u(){s.forEach(e=>e())}async function d(e){try{await e?.()}catch(e){if(t?.onCallbackError)try{t.onCallbackError(e instanceof Error?e:Error(String(e)))}catch{}}}return{async cancel(){let e=o;e&&(e.controller.abort(),await e.promise.catch(()=>{}))},dispose(){c||(c=!0,o?.controller.abort(),o=null,s.clear())},get disposed(){return c},async mutate(s,l){if(c)throw new p(`Mutation`);let f=new AbortController,m=l?.signal?b(l.signal,f.signal):f.signal,h=++a;i={data:void 0,error:null,isFetching:!0,isLoading:!0,status:`loading`,updatedAt:void 0},u();let g={controller:f,promise:null};o=g;let _=(async()=>{try{let n=await r(()=>e(s,m),{delay:e=>j(e,t?.delay),shouldRetry:t?.shouldRetry,signal:m,times:t?.times??1});return h===a&&(i={data:n,error:null,isFetching:!1,isLoading:!1,status:`success`,updatedAt:Date.now()},u()),await d(()=>t?.onSuccess?.(n,s)),await d(()=>t?.onFinally?.(s)),await d(()=>t?.onSettled?.({data:n,status:`success`,variables:s})),n}catch(e){let r=e instanceof Error?e:Error(String(e)),o=m.aborted||n(r);throw h===a&&(i=o?M:{data:void 0,error:r,isFetching:!1,isLoading:!1,status:`error`,updatedAt:Date.now()},u()),o||await d(()=>t?.onError?.(r,s)),await d(()=>t?.onFinally?.(s)),await d(()=>t?.onSettled?.(o?{status:`aborted`,variables:s}:{error:r,status:`error`,variables:s})),r}finally{o?.controller===f&&(o=null)}})();return g.promise=_,_},peek(){return i},reset(){i=M,u()},get store(){return l??={peek:()=>i,subscribe:e=>(s.add(e),()=>s.delete(e))}},subscribe(e){return s.add(e),()=>s.delete(e)},[Symbol.dispose](){this.dispose()}}}function P(e){return typeof e==`function`?e():e}function F(e){return t(e)}function ee(e){return t(e)}function I(e,n){let r=t(n),i=e.entries.get(r);return i||(i={data:void 0,error:null,hash:r,inflight:null,isFetching:!1,key:n,lastConfig:void 0,observers:new Set,segmentHashes:n.map(e=>t(e)),status:`loading`,updatedAt:void 0},e.entries.set(r,i)),i}function L(e,t){let n=e.gcTimers.get(t);n&&(clearTimeout(n),e.gcTimers.delete(t))}function R(e,t,n){if(e.disposed||(L(e,t.hash),t.observers.size>0))return;if(n===0){e.entries.delete(t.hash);return}let r=setTimeout(()=>{let n=e.entries.get(t.hash);!n||n.observers.size>0||n.isFetching||(e.entries.delete(t.hash),e.gcTimers.delete(t.hash))},n);e.gcTimers.set(t.hash,r)}function z(e,t){t.inflight?.controller.abort(),L(e,t.hash),e.entries.delete(t.hash)}function te(e,t){return t.length>e.segmentHashes.length?!1:t.every((t,n)=>t===e.segmentHashes[n])}function B(e,t){t.isFetching=!0,t.status=`loading`,t.error=null,e.notify(t)}function V(e,t,n,r){t.data=n,t.error=null,t.status=`success`,t.updatedAt=Date.now(),t.isFetching=!1,t.inflight=null,R(e,t,r),e.notify(t)}function H(e,t,n,r){t.error=n,t.status=`error`,t.updatedAt=Date.now(),t.isFetching=!1,t.inflight=null,R(e,t,r),e.notify(t)}function ne(e,t,n,r){if(t.data=n.data,t.error=n.error,t.status=n.status,t.updatedAt=n.updatedAt,t.isFetching=!1,t.inflight=null,t.observers.size===0&&t.status===`loading`&&t.data===void 0){z(e,t);return}R(e,t,r),e.notify(t)}function U(e,t){if(t.inflight?.controller.abort(),t.observers.size>0){t.inflight=null,t.isFetching=!1,t.status=`loading`,t.data=void 0,t.error=null,t.updatedAt=void 0,e.notify(t);return}z(e,t)}function W(e,t,i){if(t.inflight)return t.inflight.promise;let{delay:a,fn:o,gcTime:s,shouldRetry:c,times:l}=i,u=new AbortController,d={data:t.data,error:t.error,status:t.status,updatedAt:t.updatedAt},f=(async()=>{try{let n=await r(()=>o({key:t.key,signal:u.signal}),{delay:e=>j(e,a),shouldRetry:c,signal:u.signal,times:l});return V(e,t,n,s),n}catch(r){let i=r instanceof Error?r:Error(String(r));throw u.signal.aborted||n(i)?ne(e,t,d,s):H(e,t,i,s),i}})();return t.inflight={controller:u,promise:f},B(e,t),f}function re(e,t){return{delay:t.delay??e.delayDefault,fn:t.fn,gcTime:t.gcTime??e.gcTimeDefault,shouldRetry:t.shouldRetry??e.shouldRetryDefault,staleTime:t.staleTime??e.staleTimeDefault,times:t.times??e.timesDefault}}function ie(e,t,n,r){return{delayDefault:e.delay,disposed:!1,entries:t,gcTimeDefault:e.gcTime??3e5,gcTimers:n,notify:r,shouldRetryDefault:e.shouldRetry,staleTimeDefault:e.staleTime??0,timesDefault:e.times??1}}var G=Object.freeze({data:void 0,error:null,isFetching:!1,isLoading:!0,status:`loading`,updatedAt:void 0});function K(e){return e.status===`loading`?{data:void 0,error:null,isFetching:e.isFetching,isLoading:!0,status:`loading`,updatedAt:void 0}:e.status===`success`?{data:e.data,error:null,isFetching:e.isFetching,isLoading:!1,status:`success`,updatedAt:e.updatedAt}:{data:e.data,error:e.error,isFetching:e.isFetching,isLoading:!1,status:`error`,updatedAt:e.updatedAt}}function q(e,t){let n=K(e);if(n.status===`loading`){let e=P(t.placeholderData);return{...n,data:e}}let r=t.select?t.select(n.data):n.data;return{...n,data:r}}function J(e){for(let t of e.observers){let n=t,r=q(e,n),i=n.previous,a=Object.is(i?.data,r.data),o=!!i&&i.status===r.status&&i.isFetching===r.isFetching&&Object.is(i.error,r.error);(n.select?o&&a:o&&i?.updatedAt===r.updatedAt&&a)||(n.previous=r,n.listener())}}function Y(e,t,n){let r={listener:()=>{},...n};return{peek(){let n=e.entries.get(F(t));return n?q(n,r):G},subscribe(i){let a=I(e,t);L(e,a.hash);let o={...n,listener:i,previous:q(a,r)};return a.observers.add(o),()=>{a.observers.delete(o),a.observers.size===0&&R(e,a,a.lastConfig?.gcTime??e.gcTimeDefault)}}}}function X(e){let t=!1,n=new AbortController,r=new Map,i=new Map,a=ie({delay:e?.delay,gcTime:e?.gcTime,shouldRetry:e?.shouldRetry,staleTime:e?.staleTime,times:e?.times},r,i,J);async function o(e){if(t)throw new p(`QueryClient`);let{enabled:n=!0,fn:i,gcTime:o,initialData:s,key:c,staleTime:l,...u}=e;if(!n){let e=F(c);return r.get(e)?.data??void 0}let d=I(a,c),f=re(a,{fn:i,gcTime:o,staleTime:l,...u});if(s!==void 0&&d.status===`loading`&&d.data===void 0){let e=P(s);e!==void 0&&(d.data=e,d.error=null,d.status=`success`,d.updatedAt=Date.now())}return d.status===`success`&&d.updatedAt!==void 0&&Date.now()-d.updatedAt<f.staleTime&&!d.isFetching?(d.lastConfig=f,d.data):(d.lastConfig=f,d.inflight?d.inflight.promise:W(a,d,f))}function s(e){if(!e.lastConfig){U(a,e);return}e.isFetching||W(a,e,e.lastConfig).catch(()=>{})}function c(e){let t=e.map(e=>ee(e));for(let e of[...r.values()])if(te(e,t)){if(e.observers.size>0){s(e);continue}U(a,e)}}function l(e,t,n){let r=I(a,e),i=n?.gcTime??r.lastConfig?.gcTime??a.gcTimeDefault;r.data=typeof t==`function`?t(r.data):t,r.error=null,r.status=`success`,r.updatedAt=n?.updatedAt??Date.now(),r.isFetching=!1,r.inflight=null,J(r),R(a,r,i)}function u(e){return e.observers.size===0||!e.lastConfig||e.isFetching?!1:e.status===`success`&&e.updatedAt!==void 0||e.status===`error`&&e.data!==void 0&&e.updatedAt!==void 0?Date.now()-e.updatedAt>=e.lastConfig.staleTime:!1}function d(e){let{fetch:t=!0,key:n,placeholderData:r,select:i}=e,s=Y(a,n,{placeholderData:r,select:i});return t&&e.fn&&o({...e}).catch(()=>{}),s}return{cancel(e){let t=r.get(F(e));t?.inflight&&t.inflight.controller.abort()},cancelAll(){for(let e of r.values())e.inflight?.controller.abort()},clear(){for(let e of[...r.values()])U(a,e)},get disposalSignal(){return n.signal},dispose(){if(!t){t=!0,a.disposed=!0,n.abort();for(let[,e]of r)e.observers.clear(),e.inflight?.controller.abort();for(let[,e]of i)clearTimeout(e);i.clear(),r.clear()}},get disposed(){return t},fetch:o,fetchMany(e){return Promise.all(e.map(e=>o(e)))},get(e){let t=r.get(F(e));return t?t.data:void 0},getState(e){let t=r.get(F(e));return t?K(t):null},invalidate:c,keys(){return[...r.values()].map(e=>e.key)},observe:d,observeMany(e){let t=e.map(e=>Y(a,e));return{peek(){return t.map(e=>e.peek())},subscribe(e){let n=t.map(t=>t.subscribe(e));return()=>{for(let e of n)e()}}}},refetchStale(){for(let e of[...r.values()])u(e)&&W(a,e,e.lastConfig).catch(()=>{})},remove(e){let t=r.get(F(e));t&&U(a,t)},set:l,get size(){return r.size},[Symbol.dispose](){this.dispose()}}}function ae(e){try{return JSON.parse(e)}catch{return e}}async function Z(e,t,n,r,i){let a=r.method.toUpperCase(),o=T(e.baseUrl,t,r.params,r.query),c=b(r.extSignal,n.signal)??n.signal,l=C(r.timeout??1/0,c),{headers:u,...d}=_(a,e.mergeHeaders(r.headers,i),r.body,l,r.fetchInit??{}),f;try{f=await e.dispatch({headers:u,init:d,url:o})}catch(e){throw h(e,a,o,l??c)}if(!f.ok){let e=await f.text().catch(()=>``);throw s.fromResponse(f,e,a,o)}if(!f.body)throw new m(`Response has no body`);return f}function Q(e){let{transport:t,...n}=e??{},r=!t,a=t??w(n);function o(e,t={}){if(a.disposed)throw new p(`StreamClient`);let{body:n,fetchInit:r,headers:o,method:s=n===void 0?`GET`:`POST`,onError:c,params:l,query:u,reconnect:d=!1,signal:f,timeout:m}=t;m!==void 0&&S(m);let h=new Map,g=new AbortController,_=a.track(g),v=!1,y=`connecting`,b=``,x=d===!0?{}:d===!1?{times:0}:d,C=x.times??(d?5:0),w=x.delay??A;function T(e,t){let n=h.get(e);if(!n?.size)return;let r=ae(t);for(let e of n)e(r)}async function E(){let t=(await Z(a,e,g,{body:n,extSignal:f,fetchInit:r,headers:o,method:s,params:l,query:u,timeout:m},{accept:`text/event-stream`,"cache-control":`no-cache`,...b?{"last-event-id":b}:{}})).body.getReader(),i=new TextDecoder,c=``,d=`message`,p=``,h=``;try{for(;;){let{done:e,value:n}=await t.read();if(e)break;c+=i.decode(n,{stream:!0}).replace(/\r\n/g,`
1
+ import{backoff as e,hash as t,isAbortError as n,retry as r,sleep as i,uuid as a}from"@vielzeug/arsenal";var o=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}},s=class e extends o{url;method;status;data;headers;constructor(e){super(e.message),this.url=e.url,this.method=e.method,this.status=e.status,this.data=e.data,this.headers=e.headers}static fromResponse(t,n,r,i){return new e({data:n,headers:t.headers,message:t.statusText||`HTTP ${t.status}`,method:r,status:t.status,url:i})}static is(t,n){return t instanceof e&&(n===void 0||t.status===n)}},c=class extends o{url;method;constructor(e){super(e.message,{cause:e.cause}),this.url=e.url,this.method=e.method}},l=class extends o{url;method;constructor(e){super(e.message,{cause:e.cause}),this.url=e.url,this.method=e.method}},u=class extends o{url;method;constructor(e){super(e.message,{cause:e.cause}),this.url=e.url,this.method=e.method}},d=class extends o{data;constructor(e,t){super(e instanceof Error?e.message:String(e),{cause:e}),this.data=t}},f=class extends o{},p=class extends o{constructor(e){super(`[courier] ${e} disposed`)}},m=class extends o{};function h(e,t,n,r){let i=e instanceof Error?e.message:String(e),a=r?.reason;return a instanceof Error&&a.name===`TimeoutError`?new l({cause:e,message:i,method:t,url:n}):e instanceof DOMException?e.name===`TimeoutError`?new l({cause:e,message:i,method:t,url:n}):new u({cause:e,message:i,method:t,url:n}):e instanceof Error&&e.name===`AbortError`||r?.aborted?new u({cause:e,message:i,method:t,url:n}):new c({cause:e,message:i,method:t,url:n})}async function g(e,t=`auto`){if(t===`raw`)return e;if(e.status===204||e.status===205||e.status===304)return;if(t===`json`)return e.json();if(t===`text`)return e.text();if(t===`blob`)return e.blob();if(t===`arrayBuffer`)return e.arrayBuffer();let n=e.headers.get(`content-type`)??``;return n.includes(`application/json`)||n.includes(`+json`)?e.json():n.startsWith(`text/`)?e.text():n.startsWith(`image/`)||n.startsWith(`audio/`)||n.startsWith(`video/`)?e.blob():e.text()}function _(e,t,n,r,i){return n!==void 0&&!v(n)?{...i,body:JSON.stringify(n),headers:{"content-type":`application/json`,...t},method:e.toUpperCase(),signal:r}:{...i,...n!==void 0&&{body:n},headers:t,method:e.toUpperCase(),signal:r}}function v(e){return e instanceof FormData||e instanceof Blob||e instanceof URLSearchParams||typeof e==`string`||e instanceof ArrayBuffer||ArrayBuffer.isView(e)||typeof ReadableStream<`u`&&e instanceof ReadableStream}function y(e,t,n){return{headers:t,init:n,url:e,withHeaders(r){let i={...t};for(let[e,t]of Object.entries(r))i[e.toLowerCase()]=t;return y(e,i,n)}}}function b(...e){let t=e.filter(e=>e!=null);if(t.length!==0)return t.length===1?t[0]:AbortSignal.any(t)}var x=3e4;function S(e){if((e<=0||!Number.isFinite(e))&&e!==1/0)throw new o(`[courier] timeout must be a positive number or Infinity`)}function C(e,t){return e===1/0?t??void 0:b(AbortSignal.timeout(e),t)}function w(e={}){let{baseUrl:t=``,fetch:n=globalThis.fetch,headers:r={},timeout:i=x}=e;S(i);let a=Object.fromEntries(Object.entries(r).map(([e,t])=>[e.toLowerCase(),t])),o=new Set,s=new AbortController,c=[],l=null,u=!1;function d(){if(l)return l;let e=e=>n(e.url,{...e.init,headers:e.headers});return l=c.length===0?e:c.reduceRight((e,t)=>n=>t(n,e),e),l}function f(e){return c.push(e),l=null,()=>{let t=c.indexOf(e);t!==-1&&(c.splice(t,1),l=null)}}function p(e){for(let[t,n]of Object.entries(e)){let e=t.toLowerCase();n===void 0?delete a[e]:a[e]=n}}function m(){return{...a}}function h(e,t){let n=e?Object.fromEntries(Object.entries(e).map(([e,t])=>[e.toLowerCase(),t])):void 0;return{...a,...n,...t}}function g(e){return o.add(e),()=>o.delete(e)}function _(e){return d()(y(e.url,e.headers,e.init))}function v(){for(let e of[...o])e.abort();o.clear()}function b(){if(!u){u=!0,s.abort();for(let e of o)e.abort();o.clear(),c.length=0,l=null}}return{baseUrl:t,cancelAll:v,dispatch:_,get disposalSignal(){return s.signal},dispose:b,get disposed(){return u},getHeaders:m,getTimeout(){return i},headers:p,mergeHeaders:h,track:g,use:f}}function T(e,t,n,r){let i=e.replace(/\/+$/,``),a=t.replace(/^\/+/,``);a=a.replace(/\{([^}]+)\}/g,(e,r)=>{let i=n?.[r];if(i==null)throw new m(`unresolved path param {${r}} in '${t}'`);return encodeURIComponent(String(i))});let o=i&&a?`${i}/${a}`:i||a;if(!r)return o;let s=new URLSearchParams;for(let[e,t]of Object.entries(r))if(t!==void 0){if(Array.isArray(t)){for(let n of t)n!==void 0&&s.append(e,n===null?``:String(n));continue}s.append(e,t===null?``:String(t))}let c=s.toString();return c?`${o}${o.includes(`?`)?`&`:`?`}${c}`:o}var E=new Set([`GET`,`HEAD`,`OPTIONS`]);function D(e,n,r,i){if(E.has(e))return`${e}:${n}:${r}`;if(i!==void 0)return`${e}:${n}:${t(i)}`}function O(e){let{transport:t,...n}=e??{},r=t??w(n),i=!t,a=new Map;async function o(e,t,n,i,a,o){let c=t.signal,l;try{l=await r.dispatch({headers:e,init:t,url:n})}catch(e){throw h(e,i,n,c)}if(!l.ok){let e;try{e=await g(l,a??`auto`)}catch{e=await l.text().catch(()=>``)}throw s.fromResponse(l,e,i,n)}let u;try{u=await g(l,a??`auto`)}catch(e){throw h(e,i,n,c)}if(o)try{return o.parse(u)}catch(e){throw new d(e,u)}return u}async function c(e,t,n={}){if(r.disposed)throw new p(`ApiClient`);let i=e.toUpperCase(),s;try{s=T(r.baseUrl,t,n.params,n.query)}catch(e){throw h(e,i,t)}let{body:c,dedupe:l=!0,dedupeKey:u,fetchInit:d,headers:f,responseType:m,schema:g,signal:v,timeout:y}=n;y!==void 0&&S(y);let x=r.mergeHeaders(f),w=l?D(i,s,m??`auto`,u):void 0;if(w){let e=a.get(w);if(e)return e}let E=new AbortController,O=r.track(E),k=b(v,E.signal)??E.signal,{headers:A,...j}=_(i,x,c,C(y??r.getTimeout(),k),d??{}),M=o(A,j,s,i,m,g);w&&a.set(w,M);try{return await M}finally{w&&a.delete(w),O()}}return{cancelAll(){r.cancelAll(),a.clear()},delete:(e,t)=>c(`DELETE`,e,t),get disposalSignal(){return r.disposalSignal},dispose(){a.clear(),i&&r.dispose()},get disposed(){return r.disposed},get:(e,t)=>c(`GET`,e,t),getHeaders:r.getHeaders,headers:r.headers,patch:(e,t)=>c(`PATCH`,e,t),post:(e,t)=>c(`POST`,e,t),put:(e,t)=>c(`PUT`,e,t),request:c,[Symbol.dispose](){this.dispose()},use:r.use}}function k(e){let{maxSize:t=25,resolve:n,resolveSettled:r,window:i=0}=e,a=[],o=new AbortController,s=!1,c=null,l=!1;function u(){if(a.length===0)return;let e=a.splice(0,t);a.length>0&&d();let i=e.map(e=>e.key);try{r?r(i).then(t=>{if(t.length!==e.length){let n=new f(`Batcher: resolveSettled() returned ${t.length} results for ${e.length} keys`);for(let t of e)t.reject(n);return}e.forEach((e,n)=>{let r=t[n];r.status===`fulfilled`?e.resolve(r.value):e.reject(r.reason)})}).catch(t=>{for(let n of e)n.reject(t)}):n(i).then(t=>{if(t.length!==e.length){let n=new f(`Batcher: resolve() returned ${t.length} results for ${e.length} keys`);for(let t of e)t.reject(n);return}e.forEach((e,n)=>e.resolve(t[n]))}).catch(t=>{for(let n of e)n.reject(t)})}catch(t){for(let n of e)n.reject(t)}}function d(){s||(s=!0,i===0?queueMicrotask(()=>{s=!1,u()}):c=setTimeout(()=>{c=null,s=!1,u()},i))}return{get disposalSignal(){return o.signal},dispose(){if(l)return;l=!0,c!==null&&(clearTimeout(c),c=null);let e=new p(`Batcher`);for(let t of a.splice(0))t.reject(e);s=!1,o.abort()},get disposed(){return l},load(e){return l?Promise.reject(new p(`Batcher`)):new Promise((n,r)=>{a.push({key:e,reject:r,resolve:n}),a.length>=t?(c!==null&&(clearTimeout(c),c=null),s=!1,u()):d()})},[Symbol.dispose](){this.dispose()}}}function A(t){return Math.random()*e(t)}function j(e,t){if(typeof t==`function`){let n=t(e);return Number.isFinite(n)?Math.max(0,n):0}return typeof t==`number`?Number.isFinite(t)?Math.max(0,t):0:A(e)}var M=Object.freeze({data:void 0,error:null,isFetching:!1,isLoading:!0,status:`loading`,updatedAt:void 0});function N(e,t){let i=M,a=0,o=null,s=new Set,c=!1,l=null;function u(){s.forEach(e=>e())}async function d(e){try{await e?.()}catch(e){if(t?.onCallbackError)try{t.onCallbackError(e instanceof Error?e:Error(String(e)))}catch{}}}return{async cancel(){let e=o;e&&(e.controller.abort(),await e.promise.catch(()=>{}))},dispose(){c||(c=!0,o?.controller.abort(),o=null,s.clear())},get disposed(){return c},async mutate(s,l){if(c)throw new p(`Mutation`);let f=new AbortController,m=l?.signal?b(l.signal,f.signal):f.signal,h=++a;i={data:void 0,error:null,isFetching:!0,isLoading:!0,status:`loading`,updatedAt:void 0},u();let g={controller:f,promise:null};o=g;let _=(async()=>{try{let n=await r(()=>e(s,m),{delay:e=>j(e,t?.delay),shouldRetry:t?.shouldRetry,signal:m,times:t?.times??1});return h===a&&(i={data:n,error:null,isFetching:!1,isLoading:!1,status:`success`,updatedAt:Date.now()},u()),await d(()=>t?.onSuccess?.(n,s)),await d(()=>t?.onFinally?.(s)),await d(()=>t?.onSettled?.({data:n,status:`success`,variables:s})),n}catch(e){let r=e instanceof Error?e:Error(String(e)),o=m.aborted||n(r);throw h===a&&(i=o?M:{data:void 0,error:r,isFetching:!1,isLoading:!1,status:`error`,updatedAt:Date.now()},u()),o||await d(()=>t?.onError?.(r,s)),await d(()=>t?.onFinally?.(s)),await d(()=>t?.onSettled?.(o?{status:`aborted`,variables:s}:{error:r,status:`error`,variables:s})),r}finally{o?.controller===f&&(o=null)}})();return g.promise=_,_},peek(){return i},reset(){i=M,u()},get store(){return l??={peek:()=>i,subscribe:e=>c?()=>{}:(s.add(e),()=>s.delete(e))}},subscribe(e){return c?()=>{}:(s.add(e),()=>s.delete(e))},[Symbol.dispose](){this.dispose()}}}function P(e){return typeof e==`function`?e():e}function F(e){return t(e)}function ee(e){return t(e)}function I(e,n){let r=t(n),i=e.entries.get(r);return i||(i={data:void 0,error:null,hash:r,inflight:null,isFetching:!1,key:n,lastConfig:void 0,observers:new Set,segmentHashes:n.map(e=>t(e)),status:`loading`,updatedAt:void 0},e.entries.set(r,i)),i}function L(e,t){let n=e.gcTimers.get(t);n&&(clearTimeout(n),e.gcTimers.delete(t))}function R(e,t,n){if(e.disposed||(L(e,t.hash),t.observers.size>0))return;if(n===0){e.entries.delete(t.hash);return}let r=setTimeout(()=>{let n=e.entries.get(t.hash);!n||n.observers.size>0||n.isFetching||(e.entries.delete(t.hash),e.gcTimers.delete(t.hash))},n);e.gcTimers.set(t.hash,r)}function z(e,t){t.inflight?.controller.abort(),L(e,t.hash),e.entries.delete(t.hash)}function te(e,t){return t.length>e.segmentHashes.length?!1:t.every((t,n)=>t===e.segmentHashes[n])}function B(e,t){t.isFetching=!0,t.status=`loading`,t.error=null,e.notify(t)}function V(e,t,n,r){t.data=n,t.error=null,t.status=`success`,t.updatedAt=Date.now(),t.isFetching=!1,t.inflight=null,R(e,t,r),e.notify(t)}function H(e,t,n,r){t.error=n,t.status=`error`,t.updatedAt=Date.now(),t.isFetching=!1,t.inflight=null,R(e,t,r),e.notify(t)}function ne(e,t,n,r){if(t.data=n.data,t.error=n.error,t.status=n.status,t.updatedAt=n.updatedAt,t.isFetching=!1,t.inflight=null,t.observers.size===0&&t.status===`loading`&&t.data===void 0){z(e,t);return}R(e,t,r),e.notify(t)}function U(e,t){if(t.inflight?.controller.abort(),t.observers.size>0){t.inflight=null,t.isFetching=!1,t.status=`loading`,t.data=void 0,t.error=null,t.updatedAt=void 0,e.notify(t);return}z(e,t)}function W(e,t,i){if(t.inflight)return t.inflight.promise;let{delay:a,fn:o,gcTime:s,shouldRetry:c,times:l}=i,u=new AbortController,d={data:t.data,error:t.error,status:t.status,updatedAt:t.updatedAt},f=(async()=>{try{let n=await r(()=>o({key:t.key,signal:u.signal}),{delay:e=>j(e,a),shouldRetry:c,signal:u.signal,times:l});return V(e,t,n,s),n}catch(r){let i=r instanceof Error?r:Error(String(r));throw u.signal.aborted||n(i)?ne(e,t,d,s):H(e,t,i,s),i}})();return t.inflight={controller:u,promise:f},B(e,t),f}function re(e,t){return{delay:t.delay??e.delayDefault,fn:t.fn,gcTime:t.gcTime??e.gcTimeDefault,shouldRetry:t.shouldRetry??e.shouldRetryDefault,staleTime:t.staleTime??e.staleTimeDefault,times:t.times??e.timesDefault}}function ie(e,t,n,r){return{delayDefault:e.delay,disposed:!1,entries:t,gcTimeDefault:e.gcTime??3e5,gcTimers:n,notify:r,shouldRetryDefault:e.shouldRetry,staleTimeDefault:e.staleTime??0,timesDefault:e.times??1}}var G=Object.freeze({data:void 0,error:null,isFetching:!1,isLoading:!0,status:`loading`,updatedAt:void 0});function K(e){return e.status===`loading`?{data:void 0,error:null,isFetching:e.isFetching,isLoading:!0,status:`loading`,updatedAt:void 0}:e.status===`success`?{data:e.data,error:null,isFetching:e.isFetching,isLoading:!1,status:`success`,updatedAt:e.updatedAt}:{data:e.data,error:e.error,isFetching:e.isFetching,isLoading:!1,status:`error`,updatedAt:e.updatedAt}}function q(e,t){let n=K(e);if(n.status===`loading`){let e=P(t.placeholderData);return{...n,data:e}}let r=t.select?t.select(n.data):n.data;return{...n,data:r}}function J(e){for(let t of e.observers){let n=t,r=q(e,n),i=n.previous,a=Object.is(i?.data,r.data),o=!!i&&i.status===r.status&&i.isFetching===r.isFetching&&Object.is(i.error,r.error);(n.select?o&&a:o&&i?.updatedAt===r.updatedAt&&a)||(n.previous=r,n.listener())}}function Y(e,t,n){let r={listener:()=>{},...n};return{peek(){let n=e.entries.get(F(t));return n?q(n,r):G},subscribe(i){if(e.disposed)return()=>{};let a=I(e,t);L(e,a.hash);let o={...n,listener:i,previous:q(a,r)};return a.observers.add(o),()=>{a.observers.delete(o),a.observers.size===0&&R(e,a,a.lastConfig?.gcTime??e.gcTimeDefault)}}}}function X(e){let t=!1,n=new AbortController,r=new Map,i=new Map,a=ie({delay:e?.delay,gcTime:e?.gcTime,shouldRetry:e?.shouldRetry,staleTime:e?.staleTime,times:e?.times},r,i,J);async function o(e){if(t)throw new p(`QueryClient`);let{enabled:n=!0,fn:i,gcTime:o,initialData:s,key:c,staleTime:l,...u}=e;if(!n){let e=F(c);return r.get(e)?.data??void 0}let d=I(a,c),f=re(a,{fn:i,gcTime:o,staleTime:l,...u});if(s!==void 0&&d.status===`loading`&&d.data===void 0){let e=P(s);e!==void 0&&(d.data=e,d.error=null,d.status=`success`,d.updatedAt=Date.now())}return d.status===`success`&&d.updatedAt!==void 0&&Date.now()-d.updatedAt<f.staleTime&&!d.isFetching?(d.lastConfig=f,d.data):(d.lastConfig=f,d.inflight?d.inflight.promise:W(a,d,f))}function s(e){if(!e.lastConfig){U(a,e);return}e.isFetching||W(a,e,e.lastConfig).catch(()=>{})}function c(e){let t=e.map(e=>ee(e));for(let e of[...r.values()])if(te(e,t)){if(e.observers.size>0){s(e);continue}U(a,e)}}function l(e,t,n){let r=I(a,e),i=n?.gcTime??r.lastConfig?.gcTime??a.gcTimeDefault;r.data=typeof t==`function`?t(r.data):t,r.error=null,r.status=`success`,r.updatedAt=n?.updatedAt??Date.now(),r.isFetching=!1,r.inflight=null,J(r),R(a,r,i)}function u(e){return e.observers.size===0||!e.lastConfig||e.isFetching?!1:e.status===`success`&&e.updatedAt!==void 0||e.status===`error`&&e.data!==void 0&&e.updatedAt!==void 0?Date.now()-e.updatedAt>=e.lastConfig.staleTime:!1}function d(e){let{fetch:t=!0,key:n,placeholderData:r,select:i}=e,s=Y(a,n,{placeholderData:r,select:i});return t&&e.fn&&o({...e}).catch(()=>{}),s}return{cancel(e){let t=r.get(F(e));t?.inflight&&t.inflight.controller.abort()},cancelAll(){for(let e of r.values())e.inflight?.controller.abort()},clear(){for(let e of[...r.values()])U(a,e)},get disposalSignal(){return n.signal},dispose(){if(!t){t=!0,a.disposed=!0,n.abort();for(let[,e]of r)e.observers.clear(),e.inflight?.controller.abort();for(let[,e]of i)clearTimeout(e);i.clear(),r.clear()}},get disposed(){return t},fetch:o,fetchMany(e){return Promise.all(e.map(e=>o(e)))},get(e){let t=r.get(F(e));return t?t.data:void 0},getState(e){let t=r.get(F(e));return t?K(t):null},invalidate:c,keys(){return[...r.values()].map(e=>e.key)},observe:d,observeMany(e){let t=e.map(e=>Y(a,e));return{peek(){return t.map(e=>e.peek())},subscribe(e){let n=t.map(t=>t.subscribe(e));return()=>{for(let e of n)e()}}}},refetchStale(){for(let e of[...r.values()])u(e)&&W(a,e,e.lastConfig).catch(()=>{})},remove(e){let t=r.get(F(e));t&&U(a,t)},set:l,get size(){return r.size},[Symbol.dispose](){this.dispose()}}}function ae(e){try{return JSON.parse(e)}catch{return e}}async function Z(e,t,n,r,i){let a=r.method.toUpperCase(),o=T(e.baseUrl,t,r.params,r.query),c=b(r.extSignal,n.signal)??n.signal,l=C(r.timeout??1/0,c),{headers:u,...d}=_(a,e.mergeHeaders(r.headers,i),r.body,l,r.fetchInit??{}),f;try{f=await e.dispatch({headers:u,init:d,url:o})}catch(e){throw h(e,a,o,l??c)}if(!f.ok){let e=await f.text().catch(()=>``);throw s.fromResponse(f,e,a,o)}if(!f.body)throw new m(`Response has no body`);return f}function Q(e){let{transport:t,...n}=e??{},r=!t,a=t??w(n);function o(e,t={}){if(a.disposed)throw new p(`StreamClient`);let{body:n,fetchInit:r,headers:o,method:s=n===void 0?`GET`:`POST`,onError:c,params:l,query:u,reconnect:d=!1,signal:f,timeout:m}=t;m!==void 0&&S(m);let h=new Map,g=new AbortController,_=a.track(g),v=!1,y=`connecting`,b=``,x=d===!0?{}:d===!1?{times:0}:d,C=x.times??(d?5:0),w=x.delay??A;function T(e,t){let n=h.get(e);if(!n?.size)return;let r=ae(t);for(let e of n)e(r)}async function E(){let t=(await Z(a,e,g,{body:n,extSignal:f,fetchInit:r,headers:o,method:s,params:l,query:u,timeout:m},{accept:`text/event-stream`,"cache-control":`no-cache`,...b?{"last-event-id":b}:{}})).body.getReader(),i=new TextDecoder,c=``,d=`message`,p=``,h=``;try{for(;;){let{done:e,value:n}=await t.read();if(e)break;c+=i.decode(n,{stream:!0}).replace(/\r\n/g,`
2
2
  `).replace(/\r/g,`
3
3
  `);let r;for(;(r=c.indexOf(`
4
4
  `))!==-1;){let e=c.slice(0,r);if(c=c.slice(r+1),e===``)p!==``&&(h&&(b=h),T(d,p.replace(/\n$/,``))),d=`message`,p=``,h=``;else if(!e.startsWith(`:`)){let t=e.indexOf(`:`),n=t===-1?e:e.slice(0,t),r=t===-1?``:e.slice(t+1).replace(/^ /,``);if(n===`event`)d=r;else if(n===`data`)p+=(p?`