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