reactjrx 1.67.3 → 1.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var fe=Object.defineProperty;var de=(r,t,n)=>t in r?fe(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n;var S=(r,t,n)=>(de(r,typeof t!="symbol"?t+"":t,n),n),he=(r,t,n)=>{if(!t.has(r))throw TypeError("Cannot "+n)};var x=(r,t,n)=>(he(r,t,"read from private field"),n?n.call(r):t.get(r)),z=(r,t,n)=>{if(t.has(r))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(r):t.set(r,n)};Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),e=require("rxjs"),P=require("rxjs/operators"),D=require("react/jsx-runtime"),R=r=>{const t=b.useRef(r);return b.useMemo(()=>{t.current=r},[r]),t};function ge(r,t){return typeof r=="string"&&r===t||typeof r=="number"&&r===t||typeof r=="boolean"&&r===t||typeof r=="symbol"&&r===t||typeof r=="bigint"&&r===t||typeof r>"u"&&r===t||r===null&&r===t}function N(r,t,n){const s=t!=null&&!Array.isArray(t)?t:{defaultValue:void 0,key:"",unsubscribeOnUnmount:!0},i=n==null&&Array.isArray(t)?t:typeof r=="function"?n??[]:[r],a=b.useRef("getValue"in r&&typeof r.getValue=="function"?r.getValue():s.defaultValue),u=R(r),p=R(s),f=b.useCallback(g=>{const l=u.current,o=(typeof l=="function"?l:()=>l)().pipe(e.distinctUntilChanged(ge),e.tap(m=>{a.current=m}),e.finalize(g),e.catchError(m=>(console.error(m),a.current=void 0,e.EMPTY))).subscribe(g);return()=>{p.current.unsubscribeOnUnmount!==!1&&o.unsubscribe()}},[...i]),d=b.useCallback(()=>a.current,[]);return b.useSyncExternalStore(f,d,d)}function Y(r,t=[]){const n=R(r),s=typeof r=="function"?void 0:r;b.useEffect(()=>{const i=n.current,u=(typeof i=="function"?i:()=>i)().pipe(e.catchError(p=>(console.error("Uncaught error at useSubscribe. Please consider adding a catchError or other handling."),console.error(p),e.EMPTY))).subscribe();return()=>{u.unsubscribe()}},[...t,s,n])}const J=r=>{const t=b.useRef();return t.current||(t.current=r()),b.useEffect(()=>{process.env.NODE_ENV},[]),t},K=({onBeforeComplete:r,completeOnUnmount:t=!0}={})=>{const n=J(()=>new e.Subject),s=b.useRef(!1),i=R(r),a=R(t);return b.useEffect(()=>(s.current&&(n.current=new e.Subject,s.current=!1),()=>{if(!a.current){s.current=!0;return}s.current||(i.current!=null&&i.current(),n.current.complete(),s.current=!0)}),[a,i,n]),n},me=(r,t)=>{const n=K();return Y(()=>r(n.current),[n,...t]),[b.useCallback(i=>{n.current.next(i)},[n]),n]};function be(r=e.identity){const t=new e.Subject;return[t.asObservable(),(...n)=>{t.next(r(...n))}]}const X=r=>{const t=J(()=>new e.BehaviorSubject(r)),n=b.useRef(!1),s=b.useRef(r);return b.useEffect(()=>(n.current&&(t.current=new e.BehaviorSubject(s.current),n.current=!1),()=>{n.current||(t.current.complete(),n.current=!0)}),[t]),t},Z=Symbol("SIGNAL_RESET");function ye(r){const{default:t}=r??{},n=new e.BehaviorSubject(t);return{setValue:a=>{if(typeof a=="function"){const u=a(n.getValue());if(u===n.getValue())return;n.next(u);return}if(a===Z){n.next(t??void 0);return}n.next(a)},getValue:()=>n.getValue(),config:r,subject:n}}function Se(r,t){const n=t??(s=>s);return N(()=>r.subject.pipe(e.map(s=>n(s)),e.distinctUntilChanged()),{defaultValue:n(r.getValue())},[])}const H=r=>{if(!(!r||typeof r!="object"))return r},ve=({adapter:r,key:t})=>({getItem:async n=>{const s=await r.getItem(t),i=H(s)??{};if(n in i)return i[n]},setItem:async(n,s)=>{const i=await r.getItem(t),a=H(i)??{};await r.setItem(t,{...a,[n]:s})}}),$e=r=>({getItem:async t=>{const n=await r.getItem(t);if(n)return JSON.parse(n)},setItem:async(t,n)=>{await r.setItem(t,JSON.stringify(n))}}),we=r=>({getItem:async t=>{const n=r.getItem(t);if(n)return JSON.parse(n)},setItem:async(t,n)=>{r.setItem(t,JSON.stringify(n))}}),j="__reactjrx",Ee=r=>{if(typeof r=="object"&&r!==null&&j in r&&r[j]===j)return r},Ce=async({adapter:r,signal:t,version:n})=>{const i={value:t.getValue(),[j]:j,migrationVersion:n};await r.setItem(t.config.key,i)},Me=({adapter:r,version:t,signal:n})=>e.from(r.getItem(n.config.key)).pipe(e.switchMap(s=>{const i=Ee(s);return!i||i.migrationVersion!==void 0&&t>i.migrationVersion||n.setValue(s.value),e.of(s)})),Re=({entries:r=[],onReady:t,adapter:n=we(localStorage)})=>{const s=R(r),i=R(t),a=R(n),u=N(()=>{const p=s.current;return(p.length===0?e.of(!0):e.zip(...p.map(({signal:d,version:h})=>Me({adapter:a.current,signal:d,version:h}))).pipe(e.map(()=>!0))).pipe(e.tap(()=>{i.current!=null&&i.current()}),e.catchError(d=>(console.error("Unable to hydrate",d),e.EMPTY)))},{defaultValue:!1},[]);return Y(()=>u?e.merge(...s.current.map(({signal:p,version:f})=>p.subject.pipe(e.throttleTime(500,e.asyncScheduler,{trailing:!0}),e.switchMap(()=>e.from(Ce({adapter:a.current,signal:p,version:f})))))):e.EMPTY,[u,a]),{isHydrated:u}},Oe=()=>{const r=K({onBeforeComplete:()=>{r.current.next()}});return r};function q(r,t){return Math.min(r,t)}function ee(r,t){return Math.pow(2,r)*t}function te(r){const{initialInterval:t,maxRetries:n=1/0,maxInterval:s=1/0,shouldRetry:i=()=>!0,resetOnSuccess:a=!1,backoffDelay:u=ee}=r;return p=>e.defer(()=>{let f=0;const d=(h,g)=>h<n&&i(h,g);return p.pipe(P.catchError(h=>{var l;if(f++,!d(f-1,h))throw h;const g=(l=r.caughtError)==null?void 0:l.call(r,f,h);if(!g)throw h;return e.merge(g,e.throwError(()=>h))}),P.retryWhen(h=>h.pipe(P.concatMap(g=>{const l=f-1;return e.iif(()=>d(l,g),e.timer(q(u(l,t),s)),e.throwError(()=>g))}))),P.catchError(h=>{if(r.catchError)return r.catchError(f,h);throw h}),P.tap(()=>{a&&(f=0)}))})}const re=b.createContext({client:null}),xe=({client:r})=>(b.useEffect(()=>{const t=r.mount();return()=>{t()}},[r]),null),Te=b.memo(({children:r,client:t})=>{const n=b.useMemo(()=>({client:t}),[t]);return D.jsxs(re.Provider,{value:n,children:[D.jsx(xe,{client:n.client}),r]})}),G=({unsafe:r=!1}={})=>{const t=b.useContext(re);if(!r&&t.client===null)throw new Error("You forgot to register the provider");return t.client},L=r=>Array.isArray(r)?r.reduce((t,n,s)=>s===r.length-1?`${t}${L(n)}]`:`${t}${L(n)},`,"["):r===void 0?"":JSON.stringify(r,Object.keys(r).sort()),O=r=>r.length===0?"[]":L(r),ne=(r=21)=>crypto.getRandomValues(new Uint8Array(r)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),""),U=()=>({context:void 0,data:void 0,error:null,status:"idle",submittedAt:0,variables:void 0,failureCount:0,failureReason:null,isPaused:!1});function I(r){return r!=null}function C(r,t){if(r==null||t===void 0||typeof r!="object"||typeof t!="object")return r===t;if(r.constructor!==(t==null?void 0:t.constructor))return!1;const n=Object.keys(r),s=Object.keys(t);if(n.length!==s.length)return!1;for(const i of n)if(!t.hasOwnProperty(i)||r[i]!==t[i])return!1;return!0}function se(r){let t=0;return function(s){return new e.Observable(i=>{t++,r(t);const a=s.subscribe(i);return()=>{t--,r(t),a.unsubscribe()}})}}class Ve{constructor({__queryFinalizeHook:t}={}){S(this,"trigger$",new e.Subject);S(this,"mapOperator$",new e.BehaviorSubject("merge"));S(this,"state$");const n=new e.BehaviorSubject(0),s=n.pipe(e.filter(a=>a===0)),i=this.mapOperator$.pipe(e.filter(I),e.distinctUntilChanged());this.state$=i.pipe(e.mergeMap(a=>{const u=a==="concat"?e.concatMap:a==="switch"?e.switchMap:e.mergeMap,p=this.trigger$.pipe(e.filter(()=>a==="merge"));return this.trigger$.pipe(e.takeUntil(i.pipe(e.skip(1))),u(({args:f,mutation:d})=>{const h=e.defer(()=>(d.execute(f),e.EMPTY)),g=d.observeTillFinished().pipe(e.last(),e.mergeMap(()=>d.state$),e.takeUntil(this.trigger$)),l=d.observeTillFinished().pipe(e.skip(1));return e.merge(l,g,h).pipe(t??e.identity,e.takeUntil(e.merge(s,p)))}),e.scan((f,d)=>({...f,...d,...d.status==="pending"&&{data:d.data??f.data},...d.status==="pending"&&{error:d.error??f.error}}),U()),e.distinctUntilChanged(({data:f,...d},{data:h,...g})=>C(d,g)&&C(f,h)))}),e.shareReplay({refCount:!0,bufferSize:1}),se(a=>{n.next(a)}))}trigger({args:t,options:n,mutation:s}){n.mapOperator&&this.mapOperator$.next(n.mapOperator),this.trigger$.next({args:t,options:n,mutation:s})}}var T;class ke{constructor(t,n={},s){S(this,"numberOfObservers",0);S(this,"mutationRunner");z(this,T,new e.BehaviorSubject(void 0));S(this,"observed$");S(this,"result$");S(this,"getObserverResultFromState",t=>({...U(),...t,isSuccess:t.status==="success",isPending:t.status==="pending",isIdle:t.status==="idle",isError:t.status==="error",mutate:this.mutate,reset:this.reset}));var i;this.client=t,this.options=n,this.options.mutationKey=((i=this.options)==null?void 0:i.mutationKey)??[ne()],this.mutationRunner=s??new Ve(this.options),this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this),this.result$=this.mutationRunner.state$.pipe(e.map(a=>({state:this.getObserverResultFromState(a),options:{}}))),x(this,T).pipe(e.filter(I),e.mergeMap(a=>this.mutationRunner.state$.pipe(e.takeUntil(a.mutation.observeTillFinished().pipe(e.last()))))).subscribe(),this.observed$=x(this,T).pipe(e.switchMap(a=>(a==null?void 0:a.mutation.state$.pipe(e.map(u=>({state:this.getObserverResultFromState(u),options:a.options}))))??e.EMPTY),e.mergeMap(({state:a,options:u})=>(a.status==="error"&&(u!=null&&u.onError&&(u==null||u.onError(a.error,a.variables,a.context)),u!=null&&u.onSettled&&(u==null||u.onSettled(a.data,a.error,a.variables,a.context))),a.status==="success"&&(u!=null&&u.onSuccess&&(u==null||u.onSuccess(a.data,a.variables,a.context)),u!=null&&u.onSettled&&(u==null||u.onSettled(a.data,a.error,a.variables,a.context))),e.EMPTY)))}setOptions(t){this.options=this.client.defaultMutationOptions({mutationKey:this.options.mutationKey,...t}),this.options.mutationKey&&this.client.getMutationCache().findAll({exact:!0,mutationKey:this.options.mutationKey}).forEach(n=>{n.setOptions(t)})}observe(){var s;const t=this.getObserverResultFromState(((s=x(this,T).getValue())==null?void 0:s.mutation.state)??U());return{result$:e.merge(this.observed$,this.result$).pipe(e.map(({state:i})=>(console.log({state:i}),i))),lastValue:t}}subscribe(t){const n=this.observe().result$.subscribe(s=>{t(s)});return()=>{n.unsubscribe()}}async mutate(t,n={}){const s=this.client.getMutationCache().build(this.client,this.options);return x(this,T).next({mutation:s,options:n}),this.mutationRunner.trigger({args:t,options:this.options,mutation:s}),await new Promise((i,a)=>{s.observeTillFinished().pipe(e.last()).subscribe({error:u=>{a(u)},next:u=>{u.error?a(u.error):i(u.data)}})})}getCurrentResult(){var n;const t=this.client.getMutationCache().find({exact:!0,mutationKey:(n=this.options)==null?void 0:n.mutationKey});return this.getObserverResultFromState((t==null?void 0:t.state)??U())}reset(){var t;(t=x(this,T).getValue())==null||t.mutation.reset()}cancel(){var t;console.log("cancel"),(t=x(this,T).getValue())==null||t.mutation.destroy()}}T=new WeakMap;function Ue(){}function Ie(r,t){const n=G({unsafe:!!t}),s=t??n,i=R(r),a=J(()=>[ne()]),u=O(r.mutationKey??a.current),[p]=b.useState(()=>new ke(s,r));b.useEffect(()=>{},[p,r]);const f=b.useMemo(()=>p.observe(),[u,p]),d=N(f.result$)??f.lastValue,h=b.useCallback((g,l)=>{p.mutate(g,l).catch(Ue)},[p]);return b.useEffect(()=>()=>{i.current.cancelOnUnMount&&p.cancel()},[p,i]),{...d,mutate:h,mutateAsync:d.mutate}}const ie=(r,t)=>r.length===t.length&&r.every((n,s)=>n===t[s]),Qe=r=>r.pipe(e.switchMap(({options:{refetchOnWindowFocus:t=!0}})=>{const n=typeof t=="function"?t({}):t;return n!==!1?e.merge(e.fromEvent(document,"visibilitychange").pipe(e.filter(()=>!document.hidden),e.map(()=>({type:"refetch",ignoreStale:n==="always"}))),e.fromEvent(window,"focus").pipe(e.map(()=>({type:"refetch",ignoreStale:n==="always"})))):e.EMPTY})),Pe=r=>r.pipe(e.switchMap(({options:{refetchOnReconnect:t=!0}})=>{const n=typeof t=="function"?t({}):t;return n!==!1?e.fromEvent(window,"online").pipe(e.map(()=>({type:"refetch",ignoreStale:n==="always"}))):e.EMPTY})),je=({queryKey:r,queryFn:t,...n})=>{const s=X({queryKey:r,options:n,queryFn:t});return b.useEffect(()=>{s.current.next({queryKey:r,options:n,queryFn:t})},[r,n,t,s]),s},Fe={data:void 0,isLoading:!0,error:void 0,status:"loading",fetchStatus:"idle"};function Le({queryKey:r,queryFn:t,...n}){const s=K(),i=G(),a=je({queryFn:t,queryKey:r,...n}),u=N(()=>{const f=a.current.pipe(e.map(({queryKey:v})=>v??[])),d=e.of(null),h=f.pipe(e.distinctUntilChanged(ie),e.skip(1)),g=v=>!!v&&typeof v!="function",l=a.current.pipe(e.map(({queryFn:v})=>v),e.filter(g),e.distinctUntilChanged(C),g(a.current.getValue().queryFn)?e.skip(1):e.identity),c=a.current.pipe(e.map(({queryFn:v})=>v),e.filter(I)),o=a.current.pipe(e.map(({options:v})=>v)),m=Qe(a.current),w=Pe(a.current),y=e.merge(d,h,l),V=e.merge(s.current,e.merge(m,w).pipe(e.throttleTime(500)));return y.pipe(e.withLatestFrom(f),e.switchMap(([,v])=>{const{result$:$}=i.client.query({key:v,fn$:c,options$:o,trigger$:V});return $.pipe(e.scan((M,{data:k,...B})=>({data:void 0,...M,...B,isLoading:B.status==="loading",...k&&{data:k.result}}),{}))}))},{defaultValue:{...Fe,isLoading:a.current.getValue().options.enabled!==!1}},[i]),p=b.useCallback(()=>{s.current.next({type:"refetch",ignoreStale:!0})},[s]);return{...u,refetch:p}}function _e(r,t,n=[]){const i=(t!=null&&!Array.isArray(t)?t:{}).retry??!0,a=typeof r=="function",u=b.useCallback(a?r:()=>r,a?n:[r]),p=b.useCallback(()=>u().pipe(e.catchError(f=>{throw console.error(f),f}),i?e.retry():e.identity),[u,i]);Y(p,n)}const ae=({retryDelay:r,retry:t,...n})=>te({initialInterval:typeof r=="number"?r:100,...typeof t=="function"?{shouldRetry:t}:{maxRetries:t===!1?0:t??0},...n}),Ne=r=>r.pipe(e.scan((t,n)=>({...t,...n}),{data:void 0,error:void 0,fetchStatus:"idle",status:"loading"}),e.distinctUntilChanged(({data:t,...n},{data:s,...i})=>C(n,i)&&C(t,s))),Ae={backgroundColor:"transparent",color:"inherit"};function ue(r){const t={namespaces:[{name:"@reactjrx",style:{backgroundColor:"#d02f4e",color:"white"}}],namespace(n,s){const i=ue(r);return i.namespaces.push({name:n,style:s??Ae}),i},printNamespaces(){return{namespaces:t.namespaces.map(({name:n})=>`%c ${n} %c`).join(" "),styles:t.namespaces.reduce((n,{style:s})=>(n.push(`background-color: ${s.backgroundColor}; color: ${s.color};`),n.push("background-color: transparent; color: inherit;"),n),[])}},print(n,...s){if(r==="development"){const{namespaces:i,styles:a}=t.printNamespaces();console[n](i,...a,...s)}return t},printWithoutNamespace(n,...s){return r==="development"&&console[n](...s),t},log(...n){return t.print("log",...n)},warn(...n){return t.print("warn",...n)},error(...n){return t.print("error",...n)},group(...n){return t.print("group",...n)},groupEnd(){return r==="development"&&console.groupEnd(),t}};return t}const Q=ue("production"),Ye=Q.namespace("store"),Ke=r=>r.pipe(e.map(t=>[...t.keys()].reduce((n,s)=>{var i;return n[s]=(i=t.get(s))==null?void 0:i.getValue(),n},{})),e.distinctUntilChanged(C)).subscribe(t=>{Ye.log("store","update",t)}),ze=()=>{const r=new Map,t=new e.BehaviorSubject(r),n=new e.Subject,s=new e.Subject,i=()=>{t.next(r)},a=(c,o)=>{r.set(c,new e.BehaviorSubject(o)),i()},u=c=>{var o;return(o=r.get(c))==null?void 0:o.getValue()},p=c=>t.pipe(e.map(()=>r.get(c)),e.filter(I),e.map(o=>o.getValue()),e.distinctUntilChanged(C)),f=(c,o)=>{const m=r.get(c);m&&(typeof o=="function"?m.next({...m.getValue(),...o(m.getValue())}):m.next({...m.getValue(),...o}),t.next(r))},d=(c,o=()=>!0)=>{r.forEach(m=>{const w=m.getValue();o(w)&&m.next({...w,...c})}),t.next(r)},h=c=>{r.delete(c),t.next(r)},g=(c,o)=>(f(c,m=>({...m,runners:[...m.runners,o]})),()=>{var w;const m=((w=r.get(c))==null?void 0:w.getValue().runners.filter(y=>y!==o))??[];f(c,y=>({...y,runners:m}))}),l=()=>{const c=Ke(t);return()=>{c.unsubscribe()}};return{set:a,get:u,get$:p,delete:h,update:f,keys:()=>r.keys(),updateMany:d,addRunner:g,store$:t,queryEvent$:n.asObservable(),dispatchQueryEvent:c=>{n.next(c)},queryTrigger$:s.asObservable(),dispatchQueryTrigger:c=>{s.next(c)},size:()=>r.size,start:l}},We=({options$:r,queryStore:t,key:n})=>{const i=r.pipe(e.map(({enabled:a=!0})=>a),e.distinctUntilChanged()).pipe(e.skip(1),e.filter(a=>a));return e.merge(t.queryTrigger$.pipe(e.filter(a=>n===a.key),e.map(({trigger:a})=>a)),i.pipe(e.map(()=>({type:"enabled",ignoreStale:!1}))))},Je=(r,t)=>n=>r===O([])?n:e.defer(()=>{var u;const s=(u=t.get(r))==null?void 0:u.deduplication_fn;if(s)return s;let i;const a=()=>{var p;((p=t.get(r))==null?void 0:p.deduplication_fn)===i&&t.update(r,{deduplication_fn:void 0})};return i=n.pipe(e.tap({error:a,complete:a}),e.finalize(a),e.shareReplay({refCount:!0,bufferSize:1})),t.update(r,{deduplication_fn:i}),i}),Ge=r=>t=>t.pipe(e.withLatestFrom(r),e.map(([n,s])=>{var i,a;return n.error?(i=s.onError)==null||i.call(s,n.error):(a=s.onSuccess)==null||a.call(s,n),n})),Be=({queryStore:r,serializedKey:t,options:n})=>s=>s.pipe(e.tap(({data:i})=>{if(i!=null&&i.result){const a=i==null?void 0:i.result;r.update(t,{...n.cacheTime!==0&&{cache_fnResult:{result:a}}})}})),De=({options$:r,options:t,fn:n,queryStore:s,serializedKey:i,trigger:a,trigger$:u})=>{const f=r.pipe(e.map(({enabled:y=!0})=>y),e.distinctUntilChanged()).pipe(e.distinctUntilChanged(),e.filter(y=>!y)),h=e.defer(()=>{const y=typeof n=="function"?n():n;return e.from(y)}).pipe(ae(t),Je(i,s),e.tap(()=>{s.dispatchQueryEvent({key:i,type:"fetchSuccess"}),s.update(i,{lastFetchedAt:new Date().getTime()})}),e.map(y=>({status:"success",data:{result:y},error:void 0})),e.endWith({fetchStatus:"idle"}),e.catchError(y=>(s.dispatchQueryEvent({key:i,type:"fetchError"}),e.of({fetchStatus:"idle",status:"error",data:void 0,error:y}))),Ge(r),Be({serializedKey:i,options:t,queryStore:s})),g=s.queryEvent$.pipe(e.filter(y=>y.key===i&&y.type==="queryDataSet"),e.map(()=>{var y,V;return(V=(y=s.get(i))==null?void 0:y.cache_fnResult)==null?void 0:V.result}),e.filter(I),e.map(y=>({status:"success",data:{result:y}})),e.delay(1)),l=e.merge(f.pipe(e.take(1),e.map(()=>({fetchStatus:"idle"}))),e.merge(e.of({fetchStatus:"fetching",error:void 0}),h).pipe(e.takeUntil(f)),g).pipe(e.takeUntil(u)),c=s.get(i),o=c==null?void 0:c.cache_fnResult,m=!!o,w=a.type==="refetch"&&a.ignoreStale;return m?!(c!=null&&c.isStale)&&!w?e.of({fetchStatus:"idle",status:"success",data:{result:o.result},error:void 0}):e.merge(e.of({fetchStatus:"fetching",status:"success",data:{result:o.result},error:void 0}),l):l},A=(r,t,{exact:n=!1}={})=>n?O(r)===O(t):r.reduce((s,i,a)=>s?i===void 0&&!r.slice(a,r.length-1).some(p=>p!==void 0)?!0:L(i)===L(t[a]):!1,!0),F=Q.namespace("invalidation"),He=({queryStore:r})=>({invalidateQueries:({queryKey:n,exact:s=!1,predicate:i}={})=>{let a=[];n?(F.log("invalidation requested for",n),r.updateMany({isStale:!0},u=>{const p=A(n,u.queryKey,{exact:s});return p&&a.push(O(u.queryKey)),p})):i?r.updateMany({isStale:!0},u=>{const p=i(u);return p&&a.push(O(u.queryKey)),p}):(F.log("Invalidation requested for all queries"),r.updateMany({isStale:!0}),a=Array.from(r.keys())),a.forEach(u=>{r.update(u,{deduplication_fn:void 0}),r.dispatchQueryTrigger({key:u,trigger:{ignoreStale:!0,type:"refetch"}})})}}),Xe=r=>({pipeQueryResult:({options$:s})=>i=>{const a=i.pipe(e.share());return e.merge(a,a.pipe(e.filter(u=>!!u.data&&u.fetchStatus!=="fetching"),e.distinctUntilChanged((u,p)=>u.data===p.data),e.withLatestFrom(s),e.map(([,{refetchInterval:u}])=>u),e.filter(I),e.switchMap(u=>typeof u=="number"?e.timer(u).pipe(e.map(()=>({type:"refetch",ignoreStale:!0})),e.switchMap(()=>e.EMPTY)):e.EMPTY)))},refetchQueries:s=>{}}),Ze=(r,t)=>r.filter(n=>!t.includes(n)),qe=(r,t)=>r.store$.pipe(e.map(n=>[...n.keys()]),e.startWith([]),e.pairwise(),e.mergeMap(([n,s])=>{const i=Ze(s,n);return e.merge(...i.map(a=>{const u=r.store$.pipe(e.map(()=>r.get(a)),e.filter(p=>p===void 0));return e.merge(e.NEVER,e.of(a)).pipe(e.tap(()=>{}),t,e.finalize(()=>{}),e.takeUntil(u))}))})),ce=r=>r.pipe(e.switchMap(t=>e.combineLatest(t.runners)),e.map(t=>t.map(({options:n})=>n))),et=r=>r.pipe(e.map(t=>t.reduce((n,s)=>({...n,lowestStaleTime:s.staleTime===void 0?n.lowestStaleTime:Math.min(s.staleTime??1/0,n.lowestStaleTime??1/0)}),{lowestStaleTime:void 0})),e.distinctUntilChanged(C)),tt=r=>t=>t.pipe(e.filter(n=>n.key===r&&(n.type==="fetchError"||n.type==="fetchSuccess"))),rt=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>{const s=r.get$(n);return r.queryEvent$.pipe(tt(n),e.switchMap(()=>s.pipe(ce,et,e.tap(({lowestStaleTime:i=0})=>{var a;i===0?(F.log(n,"marked as stale!",{staleTime:i}),r.update(n,{isStale:!0})):(a=r.get(n))!=null&&a.isStale&&(F.log(n,"marked non stale",{staleTime:i}),r.update(n,{isStale:!1}))}),e.filter(({lowestStaleTime:i})=>i!==1/0&&i!==0),e.switchMap(({lowestStaleTime:i=0})=>e.timer(i)),e.tap(()=>{var i;(i=r.get(n))!=null&&i.isStale||(F.log(n,"marked as stale!"),r.update(n,{isStale:!0}))}))),e.map(()=>n))})),nt=r=>r.pipe(e.map(t=>t.reduce((n,s)=>({...n,lowestCacheTime:s.cacheTime===void 0?n.lowestCacheTime:Math.min(s.cacheTime??1/0,n.lowestCacheTime??1/0)}),{lowestCacheTime:void 0})),e.distinctUntilChanged(C)),st=r=>r.pipe(e.map(t=>t.cache_fnResult),e.distinctUntilChanged(C)),it=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>{const s=r.get$(n);return s.pipe(st,e.switchMap(()=>s.pipe(ce,nt,e.switchMap(({lowestCacheTime:a=5*60*1e3})=>e.timer(a).pipe(e.tap(()=>{r.update(n,{cache_fnResult:void 0})})))))).pipe(e.map(()=>n))})),at=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>r.get$(n).pipe(e.filter(i=>!i.cache_fnResult),e.map(i=>i.runners.length>0),e.pairwise(),e.filter(([i,a])=>i&&!a),e.tap(()=>{r.delete(n)}),e.map(()=>n)))),oe=({key:r})=>({isStale:!0,queryKey:r,runners:[]}),ut=({queryStore:r,serializedKey:t,runner$:n,options$:s,key:i})=>a=>a.pipe(e.withLatestFrom(s),e.map(([u,p])=>i.length===0?[u,void 0]:u.type!=="initial"?[u,void 0]:(r.get(t)?r.update(t,{queryKey:i,...p.markStale&&{isStale:!0}}):r.set(t,oe({key:i})),[u,r.addRunner(t,n)]))),ct=Q.namespace("cache"),ot=({queryStore:r})=>({setQueryData:({queryKey:n,updater:s})=>{const i=O(n);n.length!==0&&(ct.log("set cache for query",O),r.get(i)||r.set(i,oe({key:n})),r.update(i,a=>{var u;return typeof s=="function"?{...a,cache_fnResult:{result:s((u=a.cache_fnResult)==null?void 0:u.result)}}:{...a,cache_fnResult:{result:s}}}),r.dispatchQueryEvent({key:i,type:"queryDataSet"}))}}),lt=Q.namespace("refetch"),pt=({key:r,serializedKey:t,queryStore:n})=>s=>s.pipe(e.tap(i=>{if(i.type!=="refetch")return;const a=n.get(t);a&&i.ignoreStale&&!a.isStale&&(lt.log(r,"marked stale by trigger!"),n.update(t,{isStale:!0}))})),ft=({queryStore:r,serializedKey:t})=>n=>n.pipe(e.tap(s=>{s.type==="refetch"&&(r.update(t,{deduplication_fn:void 0}),r.dispatchQueryTrigger({key:t,trigger:s}))}),e.filter(s=>s.type!=="refetch")),E=r=>e.defer(()=>{const t=r();return t instanceof Promise?e.from(t):t instanceof e.Observable?t:e.of(t)}),dt=({variables:r,state:t,options:n})=>{const s=t.isPaused,i=async()=>await Promise.reject(new Error("No mutationFn found")),a=n.mutationFn??i,p=e.iif(()=>s,e.of(t.context),E(()=>{var l;return((l=n.onMutate)==null?void 0:l.call(n,r))??void 0})).pipe(e.share()),f=(l,c,o)=>(console.error(l),E(()=>{var w;return(w=n.onError)==null?void 0:w.call(n,l,r,c)}).pipe(e.catchError(()=>e.of(l)),e.map(()=>({failureCount:o,error:l,failureReason:l,context:c,status:"error"})))),d=p.pipe(e.switchMap(l=>(typeof a=="function"?E(()=>a(r)):a).pipe(e.map(o=>({result:{data:o},error:null,context:l})),ae({...n,caughtError:(o,m)=>e.of({failureCount:o,failureReason:m}),catchError:(o,m)=>f(m,l,o).pipe(e.map(w=>({...w,result:void 0})))}),e.takeWhile(({result:o,error:m})=>(o==null?void 0:o.data)===void 0&&m===void 0,!0)))),h=e.of({...t,variables:r,status:"pending",isPaused:!1,failureCount:0,failureReason:null,submittedAt:t.submittedAt??new Date().getTime()});return e.merge(h,p.pipe(e.map(l=>({context:l}))),d.pipe(e.switchMap(({result:l,error:c,...o})=>{if(!l&&!c)return e.of({...o});const m=c?e.of(null):E(()=>{var v;return(v=n.onSuccess)==null?void 0:v.call(n,l==null?void 0:l.data,r,o.context)}),y=E(()=>{var v;return(v=n.onSettled)==null?void 0:v.call(n,l==null?void 0:l.data,c,r,o.context)}).pipe(e.catchError(v=>l?e.of(l):e.of(v)));return e.concat(m,y).pipe(e.toArray(),e.map(()=>c?{error:c,data:void 0,variables:r,...o}:{status:"success",error:c,data:l==null?void 0:l.data,variables:r,...o}),e.catchError(v=>f(v,o.context,0).pipe(e.map($=>({...$,data:void 0})))))}))).pipe(e.scan((l,c)=>({...l,...c,data:c.data??l.data,error:c.error??l.error}),U()),e.distinctUntilChanged(({data:l,...c},{data:o,...m})=>C(c,m)&&C(l,o)))};class ht{constructor({options:t,mutationCache:n,state:s}){S(this,"mutationCache");S(this,"observerCount",new e.BehaviorSubject(0));S(this,"destroySubject",new e.Subject);S(this,"resetSubject",new e.Subject);S(this,"executeSubject",new e.Subject);S(this,"state",U());S(this,"state$");S(this,"options");S(this,"observerCount$",this.observerCount.asObservable());S(this,"destroyed$",this.destroySubject.asObservable());this.options=t,this.mutationCache=n,this.state=s??this.state;const i=e.of(this.state),a=this.resetSubject.pipe(e.map(()=>U())),u=this.executeSubject.pipe(e.switchMap(p=>dt({options:{...this.options,onMutate:f=>{const d=E(()=>{var g,l;return(l=(g=n.config).onMutate)==null?void 0:l.call(g,f,this)}),h=E(()=>{var g,l;return((l=(g=this.options).onMutate)==null?void 0:l.call(g,f))??void 0});return d.pipe(e.mergeMap(()=>h))},onError:(f,d,h)=>{const g=E(()=>{var c,o;return(o=(c=n.config).onError)==null?void 0:o.call(c,f,d,h,this)}),l=E(()=>{var c,o;return(o=(c=this.options).onError)==null?void 0:o.call(c,f,d,h)});return e.concat(g,l).pipe(e.toArray())},onSettled:(f,d,h,g)=>{const l=E(()=>{var o,m;return(m=(o=n.config).onSettled)==null?void 0:m.call(o,f,d,h,g,this)}),c=E(()=>{var o,m;return(m=(o=this.options).onSettled)==null?void 0:m.call(o,f,d,h,g)});return e.concat(l,c).pipe(e.toArray())},onSuccess:(f,d,h)=>{const g=E(()=>{var c,o;return(o=(c=n.config).onSuccess)==null?void 0:o.call(c,f,d,h,this)}),l=E(()=>{var c,o;return(o=(c=this.options).onSuccess)==null?void 0:o.call(c,f,d,h)});return e.concat(g,l).pipe(e.toArray())}},state:this.state,variables:p})),e.tap(p=>{this.state={...this.state,...p}}),e.takeUntil(this.destroySubject));this.state$=e.merge(i,u,a).pipe(e.shareReplay({bufferSize:1,refCount:!1}),e.takeUntil(this.destroySubject),se(p=>{this.observerCount.next(p)}))}get meta(){return this.options.meta}setOptions(t){this.options={...this.options,...t}}observeTillFinished(){return this.state$.pipe(e.takeWhile(t=>t.status!=="error"&&t.status!=="success",!0))}execute(t){return this.executeSubject.next(t),this.executeSubject.complete(),this.observeTillFinished()}continue(){return this.execute(this.state.variables)}destroy(){this.destroySubject.next(),this.destroySubject.complete(),this.executeSubject.complete()}reset(){this.resetSubject.next(),this.resetSubject.complete(),this.destroy()}}const W=({mutationKey:r,status:t,predicate:n,exact:s=!0}={})=>a=>s&&r!==void 0&&a.options.mutationKey!==void 0&&!A(a.options.mutationKey,r,{exact:s})||!s&&r!==void 0&&a.options.mutationKey!==void 0&&!A(r,a.options.mutationKey,{exact:s})||t&&a.state.status!==t?!1:n?n(a):!0;class le{constructor(t={}){S(this,"mutationsSubject",new e.BehaviorSubject([]));S(this,"mutations$",this.mutationsSubject.pipe(e.map(t=>t.map(n=>n)),e.distinctUntilChanged(ie),e.share()));S(this,"added$",this.mutations$.pipe(e.pairwise(),e.map(([t,n])=>n.filter(s=>!t.includes(s))[0]),e.filter(I),e.share()));S(this,"removed$",this.mutations$.pipe(e.pairwise(),e.map(([t,n])=>t.filter(s=>!n.includes(s))),e.mergeMap(t=>e.from(t)),e.share()));S(this,"stateChange$",this.added$.pipe(e.mergeMap(t=>t.state$.pipe(e.map(()=>t),e.takeUntil(this.removed$.pipe(e.filter(n=>n===t))))),e.share()));this.config=t}build(t,n,s){const i=new ht({mutationCache:this,options:t.defaultMutationOptions(n),state:s});return i.state$.pipe(e.filter(({status:a})=>a==="success"||a==="error"),e.switchMap(()=>i.observerCount$.pipe(e.filter(a=>a<=1),e.take(1))),e.switchMap(()=>e.timer(i.options.gcTime??5*60*1e3)),e.take(1)).subscribe({complete:()=>{this.mutationsSubject.next(this.mutationsSubject.getValue().filter(a=>i!==a))}}),this.mutationsSubject.next([...this.mutationsSubject.getValue(),i]),i}getAll(){return this.findAll()}remove(t){const n=this.mutationsSubject.getValue().find(s=>s===t);n==null||n.destroy()}find(t){const n={exact:!0,...t},s=W(n);return this.mutationsSubject.getValue().find(i=>s(i))}findAll(t={}){const n={exact:!0,...t},s=W(n);return this.mutationsSubject.getValue().filter(i=>s(i)).map(i=>i)}observe({filters:t,select:n}={}){const s=W(t),i=n??(p=>p.state),a=this.getAll().reduce((p,f)=>[...p,f],[]).filter(s).map(p=>i(p));return{value$:this.stateChange$.pipe(e.startWith(),e.map(()=>this.getAll().filter(s).map(i)),e.distinctUntilChanged(C)),lastValue:a}}subscribe(t){const n=e.merge(this.added$.pipe(e.tap(s=>{t({type:"added",mutation:s})})),this.removed$.pipe(e.tap(s=>{t({type:"removed",mutation:s})})),this.stateChange$.pipe(e.tap(s=>{t({type:"updated",action:{...s.state,type:"success"},mutation:s})}))).subscribe();return()=>{n.unsubscribe()}}resumePausedMutations(){const t=this.findAll({predicate:s=>s.state.isPaused});if(!t.length)return e.EMPTY;const n=t.map(s=>s.continue());return e.combineLatest(n)}clear(){this.getAll().forEach(t=>{this.remove(t)})}}const pe=()=>{const r=ze(),t=He({queryStore:r}),n=ot({queryStore:r}),s=Xe();let i=!1;const a=({key:d,fn$:h,fn:g,trigger$:l=new e.Subject,options$:c=new e.BehaviorSubject({})})=>{if(!i)throw new Error("You forgot to start client");const o=O(d),m=h??(g?e.of(g):e.NEVER);Q.log("query$)",o);const w=c.pipe(e.map($=>({options:$})));let y=()=>{};const V=e.merge(l.pipe(ft({queryStore:r,serializedKey:o})),We({options$:c,key:o,queryStore:r})).pipe(e.share());return{result$:e.merge(e.of({type:"initial"}),V).pipe(ut({key:d,queryStore:r,runner$:w,serializedKey:o,options$:c}),e.map(([$,M])=>(M&&(y=M),$)),pt({key:d,options$:c,queryStore:r,serializedKey:o}),e.withLatestFrom(m,c),e.map(([$,M,k])=>({trigger:$,fn:M,options:k})),e.map($=>(Q.log(o,"query trigger",{trigger:$.trigger,options:$.options}),$)),e.filter(({options:$})=>$.enabled!==!1),e.mergeMap(({fn:$,options:M,trigger:k})=>De({options$:c,options:M,fn:$,queryStore:r,serializedKey:o,trigger:k,trigger$:V})),Ne,e.withLatestFrom(c),e.takeWhile(([$,M])=>!($.data!==void 0&&M.terminateOnFirstResult),!0),e.map(([$])=>$),e.finalize(()=>{y()}))}},u=qe(r,d=>d.pipe(e.switchMap(h=>{const g=e.of(h);return e.merge(it({queryStore:r})(g),rt({queryStore:r})(g),at({queryStore:r})(g))})));return{start:()=>{i=!0;const d=u.subscribe(),h=[r.start()];return()=>{h.forEach(g=>{g()}),d.unsubscribe()}},query:a,queryStore:r,...t,...n,...s,destroy:()=>{}}};var _;class gt{constructor({mutationCache:t}={mutationCache:new le}){S(this,"client");S(this,"mutationCache");z(this,_,new Map);this.mutationCache=t,this.client=pe()}mount(){const t=this.client.start();return()=>{t()}}getMutationCache(){return this.mutationCache}defaultMutationOptions(t){return{...(t==null?void 0:t.mutationKey)&&this.getMutationDefaults(t.mutationKey),...t}}getMutationDefaults(t){const n=[...x(this,_).values()];let s={};return n.forEach(i=>{A(t,i.mutationKey)&&(s={...s,...i.defaultOptions})}),s}setMutationDefaults(t,n){x(this,_).set(O(t),{mutationKey:t,defaultOptions:n})}async resumePausedMutations(){return await e.lastValueFrom(this.mutationCache.resumePausedMutations())}clear(){}}_=new WeakMap;exports.MutationCache=le;exports.QueryClient=gt;exports.QueryClientProvider=Te;exports.SIGNAL_RESET=Z;exports.createClient=pe;exports.createLocalforageAdapter=$e;exports.createSharedStoreAdapter=ve;exports.exponentialBackoffDelay=ee;exports.getDelay=q;exports.retryBackoff=te;exports.signal=ye;exports.trigger=be;exports.useBehaviorSubject=X;exports.useLiveRef=R;exports.useMutation=Ie;exports.useObserve=N;exports.useObserveCallback=me;exports.usePersistSignals=Re;exports.useQuery=Le;exports.useQueryClient=G;exports.useSignalValue=Se;exports.useSubject=K;exports.useSubscribe=Y;exports.useSubscribeEffect=_e;exports.useUnmountObservable=Oe;
1
+ "use strict";var fe=Object.defineProperty;var de=(r,t,n)=>t in r?fe(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n;var S=(r,t,n)=>(de(r,typeof t!="symbol"?t+"":t,n),n),he=(r,t,n)=>{if(!t.has(r))throw TypeError("Cannot "+n)};var T=(r,t,n)=>(he(r,t,"read from private field"),n?n.call(r):t.get(r)),z=(r,t,n)=>{if(t.has(r))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(r):t.set(r,n)};Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),e=require("rxjs"),P=require("rxjs/operators"),B=require("react/jsx-runtime"),R=r=>{const t=b.useRef(r);return b.useMemo(()=>{t.current=r},[r]),t};function ge(r,t){return typeof r=="string"&&r===t||typeof r=="number"&&r===t||typeof r=="boolean"&&r===t||typeof r=="symbol"&&r===t||typeof r=="bigint"&&r===t||typeof r>"u"&&r===t||r===null&&r===t}function A(r,t,n){const s=t!=null&&!Array.isArray(t)?t:{defaultValue:void 0,key:"",unsubscribeOnUnmount:!0},i=n==null&&Array.isArray(t)?t:typeof r=="function"?n??[]:[r],u=b.useRef("getValue"in r&&typeof r.getValue=="function"?r.getValue():s.defaultValue),a=R(r),l=R(s),f=b.useCallback(h=>{const p=a.current,o=(typeof p=="function"?p:()=>p)().pipe(e.distinctUntilChanged(ge),e.tap(m=>{u.current=m}),e.finalize(h),e.catchError(m=>(console.error(m),u.current=void 0,e.EMPTY))).subscribe(h);return()=>{l.current.unsubscribeOnUnmount!==!1&&o.unsubscribe()}},[...i]),g=b.useCallback(()=>u.current,[]);return b.useSyncExternalStore(f,g,g)}function Y(r,t=[]){const n=R(r),s=typeof r=="function"?void 0:r;b.useEffect(()=>{const i=n.current,a=(typeof i=="function"?i:()=>i)().pipe(e.catchError(l=>(console.error("Uncaught error at useSubscribe. Please consider adding a catchError or other handling."),console.error(l),e.EMPTY))).subscribe();return()=>{a.unsubscribe()}},[...t,s,n])}const J=r=>{const t=b.useRef();return t.current||(t.current=r()),b.useEffect(()=>{process.env.NODE_ENV},[]),t},K=({onBeforeComplete:r,completeOnUnmount:t=!0}={})=>{const n=J(()=>new e.Subject),s=b.useRef(!1),i=R(r),u=R(t);return b.useEffect(()=>(s.current&&(n.current=new e.Subject,s.current=!1),()=>{if(!u.current){s.current=!0;return}s.current||(i.current!=null&&i.current(),n.current.complete(),s.current=!0)}),[u,i,n]),n},me=(r,t)=>{const n=K();return Y(()=>r(n.current),[n,...t]),[b.useCallback(i=>{n.current.next(i)},[n]),n]};function be(r=e.identity){const t=new e.Subject;return[t.asObservable(),(...n)=>{t.next(r(...n))}]}const X=r=>{const t=J(()=>new e.BehaviorSubject(r)),n=b.useRef(!1),s=b.useRef(r);return b.useEffect(()=>(n.current&&(t.current=new e.BehaviorSubject(s.current),n.current=!1),()=>{n.current||(t.current.complete(),n.current=!0)}),[t]),t},Z=Symbol("SIGNAL_RESET");function ye(r){const{default:t}=r??{},n=new e.BehaviorSubject(t);return{setValue:u=>{if(typeof u=="function"){const a=u(n.getValue());if(a===n.getValue())return;n.next(a);return}if(u===Z){n.next(t??void 0);return}n.next(u)},getValue:()=>n.getValue(),config:r,subject:n}}function Se(r,t){const n=t??(s=>s);return A(()=>r.subject.pipe(e.map(s=>n(s)),e.distinctUntilChanged()),{defaultValue:n(r.getValue())},[])}const H=r=>{if(!(!r||typeof r!="object"))return r},ve=({adapter:r,key:t})=>({getItem:async n=>{const s=await r.getItem(t),i=H(s)??{};if(n in i)return i[n]},setItem:async(n,s)=>{const i=await r.getItem(t),u=H(i)??{};await r.setItem(t,{...u,[n]:s})}}),$e=r=>({getItem:async t=>{const n=await r.getItem(t);if(n)return JSON.parse(n)},setItem:async(t,n)=>{await r.setItem(t,JSON.stringify(n))}}),we=r=>({getItem:async t=>{const n=r.getItem(t);if(n)return JSON.parse(n)},setItem:async(t,n)=>{r.setItem(t,JSON.stringify(n))}}),j="__reactjrx",Ee=r=>{if(typeof r=="object"&&r!==null&&j in r&&r[j]===j)return r},Ce=async({adapter:r,signal:t,version:n})=>{const i={value:t.getValue(),[j]:j,migrationVersion:n};await r.setItem(t.config.key,i)},Me=({adapter:r,version:t,signal:n})=>e.from(r.getItem(n.config.key)).pipe(e.switchMap(s=>{const i=Ee(s);return!i||i.migrationVersion!==void 0&&t>i.migrationVersion||n.setValue(s.value),e.of(s)})),Re=({entries:r=[],onReady:t,adapter:n=we(localStorage)})=>{const s=R(r),i=R(t),u=R(n),a=A(()=>{const l=s.current;return(l.length===0?e.of(!0):e.zip(...l.map(({signal:g,version:d})=>Me({adapter:u.current,signal:g,version:d}))).pipe(e.map(()=>!0))).pipe(e.tap(()=>{i.current!=null&&i.current()}),e.catchError(g=>(console.error("Unable to hydrate",g),e.EMPTY)))},{defaultValue:!1},[]);return Y(()=>a?e.merge(...s.current.map(({signal:l,version:f})=>l.subject.pipe(e.throttleTime(500,e.asyncScheduler,{trailing:!0}),e.switchMap(()=>e.from(Ce({adapter:u.current,signal:l,version:f})))))):e.EMPTY,[a,u]),{isHydrated:a}},Oe=()=>{const r=K({onBeforeComplete:()=>{r.current.next()}});return r};function q(r,t){return Math.min(r,t)}function ee(r,t){return Math.pow(2,r)*t}function te(r){const{initialInterval:t,maxRetries:n=1/0,maxInterval:s=1/0,shouldRetry:i=()=>!0,resetOnSuccess:u=!1,backoffDelay:a=ee}=r;return l=>e.defer(()=>{let f=0;const g=(d,h)=>d<n&&i(d,h);return l.pipe(P.catchError(d=>{var p;if(f++,!g(f-1,d))throw d;const h=(p=r.caughtError)==null?void 0:p.call(r,f,d);if(!h)throw d;return e.merge(h,e.throwError(()=>d))}),P.retryWhen(d=>d.pipe(P.concatMap(h=>{const p=f-1;return e.iif(()=>g(p,h),e.timer(q(a(p,t),s)),e.throwError(()=>h))}))),P.catchError(d=>{if(r.catchError)return r.catchError(f,d);throw d}),P.tap(()=>{u&&(f=0)}))})}const re=b.createContext({client:null}),Te=({client:r})=>(b.useEffect(()=>{const t=r.mount();return()=>{t()}},[r]),null),xe=b.memo(({children:r,client:t})=>{const n=b.useMemo(()=>({client:t}),[t]);return B.jsxs(re.Provider,{value:n,children:[B.jsx(Te,{client:n.client}),r]})}),G=({unsafe:r=!1}={})=>{const t=b.useContext(re);if(!r&&t.client===null)throw new Error("You forgot to register the provider");return t.client},L=r=>Array.isArray(r)?r.reduce((t,n,s)=>s===r.length-1?`${t}${L(n)}]`:`${t}${L(n)},`,"["):r===void 0?"":JSON.stringify(r,Object.keys(r).sort()),O=r=>r.length===0?"[]":L(r),ne=(r=21)=>crypto.getRandomValues(new Uint8Array(r)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),""),U=()=>({context:void 0,data:void 0,error:null,status:"idle",submittedAt:0,variables:void 0,failureCount:0,failureReason:null,isPaused:!1});function C(r,t){if(r==null||t===void 0||typeof r!="object"||typeof t!="object")return r===t;if(r.constructor!==(t==null?void 0:t.constructor))return!1;const n=Object.keys(r),s=Object.keys(t);if(n.length!==s.length)return!1;for(const i of n)if(!t.hasOwnProperty(i)||r[i]!==t[i])return!1;return!0}function se(r){let t=0;return function(s){return new e.Observable(i=>{t++,r(t);const u=s.subscribe(i);return()=>{t--,r(t),u.unsubscribe()}})}}class Ve{constructor({__queryFinalizeHook:t}={}){S(this,"trigger$",new e.Subject);S(this,"state$");const n=new e.BehaviorSubject(0),s=n.pipe(e.filter(i=>i===0));this.state$=this.trigger$.pipe(e.concatMap(({args:i,mutation:u,options:a})=>{const l=a.mapOperator??"merge",f=this.trigger$.pipe(e.filter(()=>l==="merge")),g=this.trigger$.pipe(e.filter(()=>l==="switch"),e.tap(()=>{u.reset()})),d=e.defer(()=>(u.execute(i),e.EMPTY)),h=u.observeTillFinished().pipe(e.last(),e.mergeMap(()=>u.state$),e.takeUntil(this.trigger$)),p=u.observeTillFinished().pipe(e.skip(1));return e.merge(p,h,d).pipe(t??e.identity,e.takeUntil(e.merge(s,f,g)))}),e.scan((i,u)=>({...i,...u,...u.status==="pending"&&{data:u.data??i.data},...u.status==="pending"&&{error:u.error??i.error}}),U()),e.distinctUntilChanged(({data:i,...u},{data:a,...l})=>C(u,l)&&C(i,a)),e.shareReplay({refCount:!0,bufferSize:1}),se(i=>{n.next(i)}))}trigger({args:t,options:n,mutation:s}){this.trigger$.next({args:t,options:n,mutation:s})}}function Q(r){return r!=null}const _=(r,t,{exact:n=!1}={})=>n?O(r)===O(t):r.reduce((s,i,u)=>s?i===void 0&&!r.slice(u,r.length-1).some(l=>l!==void 0)?!0:L(i)===L(t[u]):!1,!0);var x;class ke{constructor(t,n={},s){S(this,"numberOfObservers",0);S(this,"mutationRunner");z(this,x,new e.BehaviorSubject(void 0));S(this,"observed$");S(this,"result$");S(this,"getObserverResultFromState",t=>({...U(),...t,isSuccess:t.status==="success",isPending:t.status==="pending",isIdle:t.status==="idle",isError:t.status==="error",mutate:this.mutate,reset:this.reset}));var i;this.client=t,this.options=n,this.options.mutationKey=((i=this.options)==null?void 0:i.mutationKey)??[ne()],this.mutationRunner=s??new Ve(this.options),this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this),this.result$=this.mutationRunner.state$.pipe(e.map(u=>({state:this.getObserverResultFromState(u),options:{}}))),T(this,x).pipe(e.filter(Q),e.mergeMap(u=>this.mutationRunner.state$.pipe(e.takeUntil(u.mutation.observeTillFinished().pipe(e.last()))))).subscribe(),this.observed$=T(this,x).pipe(e.switchMap(u=>(u==null?void 0:u.mutation.observeTillFinished().pipe(e.last(),e.map(a=>({state:a,options:u.options}))))??e.EMPTY),e.mergeMap(({state:u,options:a})=>(u.status==="error"&&(a!=null&&a.onError&&(a==null||a.onError(u.error,u.variables,u.context)),a!=null&&a.onSettled&&(a==null||a.onSettled(u.data,u.error,u.variables,u.context))),u.status==="success"&&(a!=null&&a.onSuccess&&(a==null||a.onSuccess(u.data,u.variables,u.context)),a!=null&&a.onSettled&&(a==null||a.onSettled(u.data,u.error,u.variables,u.context))),e.EMPTY)))}setOptions(t){var s;const n=this.options;this.options=this.client.defaultMutationOptions({mutationKey:this.options.mutationKey,...t}),(s=T(this,x).getValue())==null||s.mutation.setOptions(this.options),this.options.mutationKey&&n.mutationKey&&!_(this.options.mutationKey,n.mutationKey,{exact:!0})&&this.reset()}observe(){var s;const t=this.getObserverResultFromState(((s=T(this,x).getValue())==null?void 0:s.mutation.state)??U());return{result$:e.merge(this.observed$,this.result$.pipe(e.map(({state:i})=>i))),lastValue:t}}subscribe(t){const n=this.observe().result$.subscribe(s=>{t(s)});return()=>{n.unsubscribe()}}async mutate(t,n={}){const s=this.client.getMutationCache().build(this.client,this.options);return T(this,x).next({mutation:s,options:n}),this.mutationRunner.trigger({args:t,options:this.options,mutation:s}),await new Promise((i,u)=>{s.observeTillFinished().pipe(e.last()).subscribe({error:a=>{u(a)},next:a=>{a.error?u(a.error):i(a.data)}})})}getCurrentResult(){var n;const t=this.client.getMutationCache().find({exact:!0,mutationKey:(n=this.options)==null?void 0:n.mutationKey});return this.getObserverResultFromState((t==null?void 0:t.state)??U())}reset(){var t;(t=T(this,x).getValue())==null||t.mutation.reset()}}x=new WeakMap;function Ue(){}function Ie(r,t){const n=G({unsafe:!!t}),s=t??n,i=R(r),u=J(()=>[ne()]),a=O(r.mutationKey??u.current),[l]=b.useState(()=>new ke(s,r));b.useEffect(()=>{l.setOptions(r)},[l,r]);const f=b.useMemo(()=>l.observe(),[a,l]),g=A(f.result$)??f.lastValue,d=b.useCallback((h,p)=>{l.mutate(h,p).catch(Ue)},[l]);return b.useEffect(()=>()=>{i.current.cancelOnUnMount&&l.reset()},[l,i]),{...g,mutate:d,mutateAsync:g.mutate}}const ie=(r,t)=>r.length===t.length&&r.every((n,s)=>n===t[s]),Qe=r=>r.pipe(e.switchMap(({options:{refetchOnWindowFocus:t=!0}})=>{const n=typeof t=="function"?t({}):t;return n!==!1?e.merge(e.fromEvent(document,"visibilitychange").pipe(e.filter(()=>!document.hidden),e.map(()=>({type:"refetch",ignoreStale:n==="always"}))),e.fromEvent(window,"focus").pipe(e.map(()=>({type:"refetch",ignoreStale:n==="always"})))):e.EMPTY})),Pe=r=>r.pipe(e.switchMap(({options:{refetchOnReconnect:t=!0}})=>{const n=typeof t=="function"?t({}):t;return n!==!1?e.fromEvent(window,"online").pipe(e.map(()=>({type:"refetch",ignoreStale:n==="always"}))):e.EMPTY})),je=({queryKey:r,queryFn:t,...n})=>{const s=X({queryKey:r,options:n,queryFn:t});return b.useEffect(()=>{s.current.next({queryKey:r,options:n,queryFn:t})},[r,n,t,s]),s},Fe={data:void 0,isLoading:!0,error:void 0,status:"loading",fetchStatus:"idle"};function Le({queryKey:r,queryFn:t,...n}){const s=K(),i=G(),u=je({queryFn:t,queryKey:r,...n}),a=A(()=>{const f=u.current.pipe(e.map(({queryKey:v})=>v??[])),g=e.of(null),d=f.pipe(e.distinctUntilChanged(ie),e.skip(1)),h=v=>!!v&&typeof v!="function",p=u.current.pipe(e.map(({queryFn:v})=>v),e.filter(h),e.distinctUntilChanged(C),h(u.current.getValue().queryFn)?e.skip(1):e.identity),c=u.current.pipe(e.map(({queryFn:v})=>v),e.filter(Q)),o=u.current.pipe(e.map(({options:v})=>v)),m=Qe(u.current),w=Pe(u.current),y=e.merge(g,d,p),V=e.merge(s.current,e.merge(m,w).pipe(e.throttleTime(500)));return y.pipe(e.withLatestFrom(f),e.switchMap(([,v])=>{const{result$:$}=i.client.query({key:v,fn$:c,options$:o,trigger$:V});return $.pipe(e.scan((M,{data:k,...D})=>({data:void 0,...M,...D,isLoading:D.status==="loading",...k&&{data:k.result}}),{}))}))},{defaultValue:{...Fe,isLoading:u.current.getValue().options.enabled!==!1}},[i]),l=b.useCallback(()=>{s.current.next({type:"refetch",ignoreStale:!0})},[s]);return{...a,refetch:l}}function _e(r,t,n=[]){const i=(t!=null&&!Array.isArray(t)?t:{}).retry??!0,u=typeof r=="function",a=b.useCallback(u?r:()=>r,u?n:[r]),l=b.useCallback(()=>a().pipe(e.catchError(f=>{throw console.error(f),f}),i?e.retry():e.identity),[a,i]);Y(l,n)}const ue=({retryDelay:r,retry:t,...n})=>te({initialInterval:typeof r=="number"?r:100,...typeof t=="function"?{shouldRetry:t}:{maxRetries:t===!1?0:t??0},...n}),Ne=r=>r.pipe(e.scan((t,n)=>({...t,...n}),{data:void 0,error:void 0,fetchStatus:"idle",status:"loading"}),e.distinctUntilChanged(({data:t,...n},{data:s,...i})=>C(n,i)&&C(t,s))),Ae={backgroundColor:"transparent",color:"inherit"};function ae(r){const t={namespaces:[{name:"@reactjrx",style:{backgroundColor:"#d02f4e",color:"white"}}],namespace(n,s){const i=ae(r);return i.namespaces.push({name:n,style:s??Ae}),i},printNamespaces(){return{namespaces:t.namespaces.map(({name:n})=>`%c ${n} %c`).join(" "),styles:t.namespaces.reduce((n,{style:s})=>(n.push(`background-color: ${s.backgroundColor}; color: ${s.color};`),n.push("background-color: transparent; color: inherit;"),n),[])}},print(n,...s){if(r==="development"){const{namespaces:i,styles:u}=t.printNamespaces();console[n](i,...u,...s)}return t},printWithoutNamespace(n,...s){return r==="development"&&console[n](...s),t},log(...n){return t.print("log",...n)},warn(...n){return t.print("warn",...n)},error(...n){return t.print("error",...n)},group(...n){return t.print("group",...n)},groupEnd(){return r==="development"&&console.groupEnd(),t}};return t}const I=ae("production"),Ye=I.namespace("store"),Ke=r=>r.pipe(e.map(t=>[...t.keys()].reduce((n,s)=>{var i;return n[s]=(i=t.get(s))==null?void 0:i.getValue(),n},{})),e.distinctUntilChanged(C)).subscribe(t=>{Ye.log("store","update",t)}),ze=()=>{const r=new Map,t=new e.BehaviorSubject(r),n=new e.Subject,s=new e.Subject,i=()=>{t.next(r)},u=(c,o)=>{r.set(c,new e.BehaviorSubject(o)),i()},a=c=>{var o;return(o=r.get(c))==null?void 0:o.getValue()},l=c=>t.pipe(e.map(()=>r.get(c)),e.filter(Q),e.map(o=>o.getValue()),e.distinctUntilChanged(C)),f=(c,o)=>{const m=r.get(c);m&&(typeof o=="function"?m.next({...m.getValue(),...o(m.getValue())}):m.next({...m.getValue(),...o}),t.next(r))},g=(c,o=()=>!0)=>{r.forEach(m=>{const w=m.getValue();o(w)&&m.next({...w,...c})}),t.next(r)},d=c=>{r.delete(c),t.next(r)},h=(c,o)=>(f(c,m=>({...m,runners:[...m.runners,o]})),()=>{var w;const m=((w=r.get(c))==null?void 0:w.getValue().runners.filter(y=>y!==o))??[];f(c,y=>({...y,runners:m}))}),p=()=>{const c=Ke(t);return()=>{c.unsubscribe()}};return{set:u,get:a,get$:l,delete:d,update:f,keys:()=>r.keys(),updateMany:g,addRunner:h,store$:t,queryEvent$:n.asObservable(),dispatchQueryEvent:c=>{n.next(c)},queryTrigger$:s.asObservable(),dispatchQueryTrigger:c=>{s.next(c)},size:()=>r.size,start:p}},We=({options$:r,queryStore:t,key:n})=>{const i=r.pipe(e.map(({enabled:u=!0})=>u),e.distinctUntilChanged()).pipe(e.skip(1),e.filter(u=>u));return e.merge(t.queryTrigger$.pipe(e.filter(u=>n===u.key),e.map(({trigger:u})=>u)),i.pipe(e.map(()=>({type:"enabled",ignoreStale:!1}))))},Je=(r,t)=>n=>r===O([])?n:e.defer(()=>{var a;const s=(a=t.get(r))==null?void 0:a.deduplication_fn;if(s)return s;let i;const u=()=>{var l;((l=t.get(r))==null?void 0:l.deduplication_fn)===i&&t.update(r,{deduplication_fn:void 0})};return i=n.pipe(e.tap({error:u,complete:u}),e.finalize(u),e.shareReplay({refCount:!0,bufferSize:1})),t.update(r,{deduplication_fn:i}),i}),Ge=r=>t=>t.pipe(e.withLatestFrom(r),e.map(([n,s])=>{var i,u;return n.error?(i=s.onError)==null||i.call(s,n.error):(u=s.onSuccess)==null||u.call(s,n),n})),De=({queryStore:r,serializedKey:t,options:n})=>s=>s.pipe(e.tap(({data:i})=>{if(i!=null&&i.result){const u=i==null?void 0:i.result;r.update(t,{...n.cacheTime!==0&&{cache_fnResult:{result:u}}})}})),Be=({options$:r,options:t,fn:n,queryStore:s,serializedKey:i,trigger:u,trigger$:a})=>{const f=r.pipe(e.map(({enabled:y=!0})=>y),e.distinctUntilChanged()).pipe(e.distinctUntilChanged(),e.filter(y=>!y)),d=e.defer(()=>{const y=typeof n=="function"?n():n;return e.from(y)}).pipe(ue(t),Je(i,s),e.tap(()=>{s.dispatchQueryEvent({key:i,type:"fetchSuccess"}),s.update(i,{lastFetchedAt:new Date().getTime()})}),e.map(y=>({status:"success",data:{result:y},error:void 0})),e.endWith({fetchStatus:"idle"}),e.catchError(y=>(s.dispatchQueryEvent({key:i,type:"fetchError"}),e.of({fetchStatus:"idle",status:"error",data:void 0,error:y}))),Ge(r),De({serializedKey:i,options:t,queryStore:s})),h=s.queryEvent$.pipe(e.filter(y=>y.key===i&&y.type==="queryDataSet"),e.map(()=>{var y,V;return(V=(y=s.get(i))==null?void 0:y.cache_fnResult)==null?void 0:V.result}),e.filter(Q),e.map(y=>({status:"success",data:{result:y}})),e.delay(1)),p=e.merge(f.pipe(e.take(1),e.map(()=>({fetchStatus:"idle"}))),e.merge(e.of({fetchStatus:"fetching",error:void 0}),d).pipe(e.takeUntil(f)),h).pipe(e.takeUntil(a)),c=s.get(i),o=c==null?void 0:c.cache_fnResult,m=!!o,w=u.type==="refetch"&&u.ignoreStale;return m?!(c!=null&&c.isStale)&&!w?e.of({fetchStatus:"idle",status:"success",data:{result:o.result},error:void 0}):e.merge(e.of({fetchStatus:"fetching",status:"success",data:{result:o.result},error:void 0}),p):p},F=I.namespace("invalidation"),He=({queryStore:r})=>({invalidateQueries:({queryKey:n,exact:s=!1,predicate:i}={})=>{let u=[];n?(F.log("invalidation requested for",n),r.updateMany({isStale:!0},a=>{const l=_(n,a.queryKey,{exact:s});return l&&u.push(O(a.queryKey)),l})):i?r.updateMany({isStale:!0},a=>{const l=i(a);return l&&u.push(O(a.queryKey)),l}):(F.log("Invalidation requested for all queries"),r.updateMany({isStale:!0}),u=Array.from(r.keys())),u.forEach(a=>{r.update(a,{deduplication_fn:void 0}),r.dispatchQueryTrigger({key:a,trigger:{ignoreStale:!0,type:"refetch"}})})}}),Xe=r=>({pipeQueryResult:({options$:s})=>i=>{const u=i.pipe(e.share());return e.merge(u,u.pipe(e.filter(a=>!!a.data&&a.fetchStatus!=="fetching"),e.distinctUntilChanged((a,l)=>a.data===l.data),e.withLatestFrom(s),e.map(([,{refetchInterval:a}])=>a),e.filter(Q),e.switchMap(a=>typeof a=="number"?e.timer(a).pipe(e.map(()=>({type:"refetch",ignoreStale:!0})),e.switchMap(()=>e.EMPTY)):e.EMPTY)))},refetchQueries:s=>{}}),Ze=(r,t)=>r.filter(n=>!t.includes(n)),qe=(r,t)=>r.store$.pipe(e.map(n=>[...n.keys()]),e.startWith([]),e.pairwise(),e.mergeMap(([n,s])=>{const i=Ze(s,n);return e.merge(...i.map(u=>{const a=r.store$.pipe(e.map(()=>r.get(u)),e.filter(l=>l===void 0));return e.merge(e.NEVER,e.of(u)).pipe(e.tap(()=>{}),t,e.finalize(()=>{}),e.takeUntil(a))}))})),ce=r=>r.pipe(e.switchMap(t=>e.combineLatest(t.runners)),e.map(t=>t.map(({options:n})=>n))),et=r=>r.pipe(e.map(t=>t.reduce((n,s)=>({...n,lowestStaleTime:s.staleTime===void 0?n.lowestStaleTime:Math.min(s.staleTime??1/0,n.lowestStaleTime??1/0)}),{lowestStaleTime:void 0})),e.distinctUntilChanged(C)),tt=r=>t=>t.pipe(e.filter(n=>n.key===r&&(n.type==="fetchError"||n.type==="fetchSuccess"))),rt=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>{const s=r.get$(n);return r.queryEvent$.pipe(tt(n),e.switchMap(()=>s.pipe(ce,et,e.tap(({lowestStaleTime:i=0})=>{var u;i===0?(F.log(n,"marked as stale!",{staleTime:i}),r.update(n,{isStale:!0})):(u=r.get(n))!=null&&u.isStale&&(F.log(n,"marked non stale",{staleTime:i}),r.update(n,{isStale:!1}))}),e.filter(({lowestStaleTime:i})=>i!==1/0&&i!==0),e.switchMap(({lowestStaleTime:i=0})=>e.timer(i)),e.tap(()=>{var i;(i=r.get(n))!=null&&i.isStale||(F.log(n,"marked as stale!"),r.update(n,{isStale:!0}))}))),e.map(()=>n))})),nt=r=>r.pipe(e.map(t=>t.reduce((n,s)=>({...n,lowestCacheTime:s.cacheTime===void 0?n.lowestCacheTime:Math.min(s.cacheTime??1/0,n.lowestCacheTime??1/0)}),{lowestCacheTime:void 0})),e.distinctUntilChanged(C)),st=r=>r.pipe(e.map(t=>t.cache_fnResult),e.distinctUntilChanged(C)),it=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>{const s=r.get$(n);return s.pipe(st,e.switchMap(()=>s.pipe(ce,nt,e.switchMap(({lowestCacheTime:u=5*60*1e3})=>e.timer(u).pipe(e.tap(()=>{r.update(n,{cache_fnResult:void 0})})))))).pipe(e.map(()=>n))})),ut=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>r.get$(n).pipe(e.filter(i=>!i.cache_fnResult),e.map(i=>i.runners.length>0),e.pairwise(),e.filter(([i,u])=>i&&!u),e.tap(()=>{r.delete(n)}),e.map(()=>n)))),oe=({key:r})=>({isStale:!0,queryKey:r,runners:[]}),at=({queryStore:r,serializedKey:t,runner$:n,options$:s,key:i})=>u=>u.pipe(e.withLatestFrom(s),e.map(([a,l])=>i.length===0?[a,void 0]:a.type!=="initial"?[a,void 0]:(r.get(t)?r.update(t,{queryKey:i,...l.markStale&&{isStale:!0}}):r.set(t,oe({key:i})),[a,r.addRunner(t,n)]))),ct=I.namespace("cache"),ot=({queryStore:r})=>({setQueryData:({queryKey:n,updater:s})=>{const i=O(n);n.length!==0&&(ct.log("set cache for query",O),r.get(i)||r.set(i,oe({key:n})),r.update(i,u=>{var a;return typeof s=="function"?{...u,cache_fnResult:{result:s((a=u.cache_fnResult)==null?void 0:a.result)}}:{...u,cache_fnResult:{result:s}}}),r.dispatchQueryEvent({key:i,type:"queryDataSet"}))}}),lt=I.namespace("refetch"),pt=({key:r,serializedKey:t,queryStore:n})=>s=>s.pipe(e.tap(i=>{if(i.type!=="refetch")return;const u=n.get(t);u&&i.ignoreStale&&!u.isStale&&(lt.log(r,"marked stale by trigger!"),n.update(t,{isStale:!0}))})),ft=({queryStore:r,serializedKey:t})=>n=>n.pipe(e.tap(s=>{s.type==="refetch"&&(r.update(t,{deduplication_fn:void 0}),r.dispatchQueryTrigger({key:t,trigger:s}))}),e.filter(s=>s.type!=="refetch")),E=r=>e.defer(()=>{const t=r();return t instanceof Promise?e.from(t):t instanceof e.Observable?t:e.of(t)}),dt=({variables:r,state:t,options:n})=>{const s=t.isPaused,i=async()=>await Promise.reject(new Error("No mutationFn found")),u=n.mutationFn??i,l=e.iif(()=>s,e.of(t.context),E(()=>{var p;return((p=n.onMutate)==null?void 0:p.call(n,r))??void 0})).pipe(e.share()),f=(p,c,o)=>(console.error(p),E(()=>{var w;return(w=n.onError)==null?void 0:w.call(n,p,r,c)}).pipe(e.catchError(()=>e.of(p)),e.map(()=>({failureCount:o,error:p,failureReason:p,context:c,status:"error"})))),g=l.pipe(e.switchMap(p=>(typeof u=="function"?E(()=>u(r)):u).pipe(e.map(o=>({result:{data:o},error:null,context:p})),ue({...n,caughtError:(o,m)=>e.of({failureCount:o,failureReason:m}),catchError:(o,m)=>f(m,p,o).pipe(e.map(w=>({...w,result:void 0})))}),e.takeWhile(({result:o,error:m})=>(o==null?void 0:o.data)===void 0&&m===void 0,!0)))),d=e.of({...t,variables:r,status:"pending",isPaused:!1,failureCount:0,failureReason:null,submittedAt:t.submittedAt??new Date().getTime()});return e.merge(d,l.pipe(e.map(p=>({context:p}))),g.pipe(e.switchMap(({result:p,error:c,...o})=>{if(!p&&!c)return e.of({...o});const m=c?e.of(null):E(()=>{var v;return(v=n.onSuccess)==null?void 0:v.call(n,p==null?void 0:p.data,r,o.context)}),y=E(()=>{var v;return(v=n.onSettled)==null?void 0:v.call(n,p==null?void 0:p.data,c,r,o.context)}).pipe(e.catchError(v=>p?e.of(p):e.of(v)));return e.concat(m,y).pipe(e.toArray(),e.map(()=>c?{error:c,data:void 0,variables:r,...o}:{status:"success",error:c,data:p==null?void 0:p.data,variables:r,...o}),e.catchError(v=>f(v,o.context,0).pipe(e.map($=>({...$,data:void 0})))))}))).pipe(e.scan((p,c)=>({...p,...c,data:c.data??p.data,error:c.error??p.error}),U()),e.distinctUntilChanged(({data:p,...c},{data:o,...m})=>C(c,m)&&C(p,o)))};class ht{constructor({options:t,mutationCache:n,state:s}){S(this,"mutationCache");S(this,"observerCount",new e.BehaviorSubject(0));S(this,"destroySubject",new e.Subject);S(this,"resetSubject",new e.Subject);S(this,"executeSubject",new e.Subject);S(this,"state",U());S(this,"state$");S(this,"options");S(this,"observerCount$",this.observerCount.asObservable());S(this,"destroyed$",this.destroySubject.asObservable());this.options=t,this.mutationCache=n,this.state=s??this.state;const i=e.of(this.state),u=this.resetSubject.pipe(e.map(()=>U())),a=this.executeSubject.pipe(e.switchMap(l=>dt({options:{...this.options,onMutate:f=>{const g=E(()=>{var h,p;return(p=(h=n.config).onMutate)==null?void 0:p.call(h,f,this)}),d=E(()=>{var h,p;return((p=(h=this.options).onMutate)==null?void 0:p.call(h,f))??void 0});return g.pipe(e.mergeMap(()=>d))},onError:(f,g,d)=>{const h=E(()=>{var c,o;return(o=(c=n.config).onError)==null?void 0:o.call(c,f,g,d,this)}),p=E(()=>{var c,o;return(o=(c=this.options).onError)==null?void 0:o.call(c,f,g,d)});return e.concat(h,p).pipe(e.toArray())},onSettled:(f,g,d,h)=>{const p=E(()=>{var o,m;return(m=(o=n.config).onSettled)==null?void 0:m.call(o,f,g,d,h,this)}),c=E(()=>{var o,m;return(m=(o=this.options).onSettled)==null?void 0:m.call(o,f,g,d,h)});return e.concat(p,c).pipe(e.toArray())},onSuccess:(f,g,d)=>{const h=E(()=>{var c,o;return(o=(c=n.config).onSuccess)==null?void 0:o.call(c,f,g,d,this)}),p=E(()=>{var c,o;return(o=(c=this.options).onSuccess)==null?void 0:o.call(c,f,g,d)});return e.concat(h,p).pipe(e.toArray())}},state:this.state,variables:l})),e.tap(l=>{this.state={...this.state,...l}}),e.takeUntil(this.destroySubject));this.state$=e.merge(i,a,u).pipe(e.shareReplay({bufferSize:1,refCount:!1}),e.takeUntil(this.destroySubject),se(l=>{this.observerCount.next(l)}))}get meta(){return this.options.meta}setOptions(t){this.options={...this.options,...t}}observeTillFinished(){return this.state$.pipe(e.takeWhile(t=>t.status!=="error"&&t.status!=="success",!0))}execute(t){return this.executeSubject.next(t),this.executeSubject.complete(),this.observeTillFinished()}continue(){return this.execute(this.state.variables)}destroy(){this.destroySubject.next(),this.destroySubject.complete(),this.executeSubject.complete()}reset(){this.resetSubject.next(),this.resetSubject.complete(),this.destroy()}}const W=({mutationKey:r,status:t,predicate:n,exact:s=!0}={})=>u=>s&&r!==void 0&&u.options.mutationKey!==void 0&&!_(u.options.mutationKey,r,{exact:s})||!s&&r!==void 0&&u.options.mutationKey!==void 0&&!_(r,u.options.mutationKey,{exact:s})||t&&u.state.status!==t?!1:n?n(u):!0;class le{constructor(t={}){S(this,"mutationsSubject",new e.BehaviorSubject([]));S(this,"mutations$",this.mutationsSubject.pipe(e.map(t=>t.map(n=>n)),e.distinctUntilChanged(ie),e.share()));S(this,"added$",this.mutations$.pipe(e.pairwise(),e.map(([t,n])=>n.filter(s=>!t.includes(s))[0]),e.filter(Q),e.share()));S(this,"removed$",this.mutations$.pipe(e.pairwise(),e.map(([t,n])=>t.filter(s=>!n.includes(s))),e.mergeMap(t=>e.from(t)),e.share()));S(this,"stateChange$",this.added$.pipe(e.mergeMap(t=>t.state$.pipe(e.map(()=>t),e.takeUntil(this.removed$.pipe(e.filter(n=>n===t))))),e.share()));this.config=t}build(t,n,s){const i=new ht({mutationCache:this,options:t.defaultMutationOptions(n),state:s});return i.state$.pipe(e.filter(({status:u})=>u==="success"||u==="error"),e.switchMap(()=>i.observerCount$.pipe(e.filter(u=>u<=1),e.take(1))),e.switchMap(()=>e.timer(i.options.gcTime??5*60*1e3)),e.take(1)).subscribe({complete:()=>{this.mutationsSubject.next(this.mutationsSubject.getValue().filter(u=>i!==u))}}),this.mutationsSubject.next([...this.mutationsSubject.getValue(),i]),i}getAll(){return this.findAll()}remove(t){const n=this.mutationsSubject.getValue().find(s=>s===t);n==null||n.destroy()}find(t){const n={exact:!0,...t},s=W(n);return this.mutationsSubject.getValue().find(i=>s(i))}findAll(t={}){const n={exact:!0,...t},s=W(n);return this.mutationsSubject.getValue().filter(i=>s(i)).map(i=>i)}observe({filters:t,select:n}={}){const s=W(t),i=n??(l=>l.state),u=this.getAll().reduce((l,f)=>[...l,f],[]).filter(s).map(l=>i(l));return{value$:this.stateChange$.pipe(e.startWith(),e.map(()=>this.getAll().filter(s).map(i)),e.distinctUntilChanged(C)),lastValue:u}}subscribe(t){const n=e.merge(this.added$.pipe(e.tap(s=>{t({type:"added",mutation:s})})),this.removed$.pipe(e.tap(s=>{t({type:"removed",mutation:s})})),this.stateChange$.pipe(e.tap(s=>{t({type:"updated",action:{...s.state,type:"success"},mutation:s})}))).subscribe();return()=>{n.unsubscribe()}}resumePausedMutations(){const t=this.findAll({predicate:s=>s.state.isPaused});if(!t.length)return e.EMPTY;const n=t.map(s=>s.continue());return e.combineLatest(n)}clear(){this.getAll().forEach(t=>{this.remove(t)})}}const pe=()=>{const r=ze(),t=He({queryStore:r}),n=ot({queryStore:r}),s=Xe();let i=!1;const u=({key:g,fn$:d,fn:h,trigger$:p=new e.Subject,options$:c=new e.BehaviorSubject({})})=>{if(!i)throw new Error("You forgot to start client");const o=O(g),m=d??(h?e.of(h):e.NEVER);I.log("query$)",o);const w=c.pipe(e.map($=>({options:$})));let y=()=>{};const V=e.merge(p.pipe(ft({queryStore:r,serializedKey:o})),We({options$:c,key:o,queryStore:r})).pipe(e.share());return{result$:e.merge(e.of({type:"initial"}),V).pipe(at({key:g,queryStore:r,runner$:w,serializedKey:o,options$:c}),e.map(([$,M])=>(M&&(y=M),$)),pt({key:g,options$:c,queryStore:r,serializedKey:o}),e.withLatestFrom(m,c),e.map(([$,M,k])=>({trigger:$,fn:M,options:k})),e.map($=>(I.log(o,"query trigger",{trigger:$.trigger,options:$.options}),$)),e.filter(({options:$})=>$.enabled!==!1),e.mergeMap(({fn:$,options:M,trigger:k})=>Be({options$:c,options:M,fn:$,queryStore:r,serializedKey:o,trigger:k,trigger$:V})),Ne,e.withLatestFrom(c),e.takeWhile(([$,M])=>!($.data!==void 0&&M.terminateOnFirstResult),!0),e.map(([$])=>$),e.finalize(()=>{y()}))}},a=qe(r,g=>g.pipe(e.switchMap(d=>{const h=e.of(d);return e.merge(it({queryStore:r})(h),rt({queryStore:r})(h),ut({queryStore:r})(h))})));return{start:()=>{i=!0;const g=a.subscribe(),d=[r.start()];return()=>{d.forEach(h=>{h()}),g.unsubscribe()}},query:u,queryStore:r,...t,...n,...s,destroy:()=>{}}};var N;class gt{constructor({mutationCache:t}={mutationCache:new le}){S(this,"client");S(this,"mutationCache");z(this,N,new Map);this.mutationCache=t,this.client=pe()}mount(){const t=this.client.start();return()=>{t()}}getMutationCache(){return this.mutationCache}defaultMutationOptions(t){return{...(t==null?void 0:t.mutationKey)&&this.getMutationDefaults(t.mutationKey),...t}}getMutationDefaults(t){const n=[...T(this,N).values()];let s={};return n.forEach(i=>{_(t,i.mutationKey)&&(s={...s,...i.defaultOptions})}),s}setMutationDefaults(t,n){T(this,N).set(O(t),{mutationKey:t,defaultOptions:n})}async resumePausedMutations(){return await e.lastValueFrom(this.mutationCache.resumePausedMutations())}clear(){}}N=new WeakMap;exports.MutationCache=le;exports.QueryClient=gt;exports.QueryClientProvider=xe;exports.SIGNAL_RESET=Z;exports.createClient=pe;exports.createLocalforageAdapter=$e;exports.createSharedStoreAdapter=ve;exports.exponentialBackoffDelay=ee;exports.getDelay=q;exports.retryBackoff=te;exports.signal=ye;exports.trigger=be;exports.useBehaviorSubject=X;exports.useLiveRef=R;exports.useMutation=Ie;exports.useObserve=A;exports.useObserveCallback=me;exports.usePersistSignals=Re;exports.useQuery=Le;exports.useQueryClient=G;exports.useSignalValue=Se;exports.useSubject=K;exports.useSubscribe=Y;exports.useSubscribeEffect=_e;exports.useUnmountObservable=Oe;