reactjrx 1.93.0 → 1.93.1

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 gt=Object.defineProperty;var De=s=>{throw TypeError(s)};var mt=(s,e,t)=>e in s?gt(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var m=(s,e,t)=>mt(s,typeof e!="symbol"?e+"":e,t),Ke=(s,e,t)=>e.has(s)||De("Cannot "+t);var c=(s,e,t)=>(Ke(s,e,"read from private field"),t?t.call(s):e.get(s)),w=(s,e,t)=>e.has(s)?De("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),j=(s,e,t,n)=>(Ke(s,e,"write to private field"),n?n.call(s,t):e.set(s,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react"),r=require("rxjs"),K=require("rxjs/operators"),Ne=require("react/jsx-runtime");function yt(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const we=yt(v),Q=s=>{const e=v.useRef(s);return v.useMemo(()=>{e.current=s},[s]),e};function St(s,e){return typeof s=="string"&&s===e||typeof s=="number"&&s===e||typeof s=="boolean"&&s===e||typeof s=="symbol"&&s===e||typeof s=="bigint"&&s===e||typeof s>"u"&&s===e||s===null&&s===e}function fe(s,e,t){const n=e!=null&&!Array.isArray(e)?e:{defaultValue:void 0,unsubscribeOnUnmount:!0},i=!t&&Array.isArray(e)?e:typeof s=="function"?t??[]:[s],u=v.useRef("getValue"in s&&typeof s.getValue=="function"?s.getValue():n.defaultValue),a=Q(s),l=Q(n),h=v.useCallback(b=>{const $=a.current,p=(typeof $=="function"?$:()=>$)().pipe(r.distinctUntilChanged(St),r.tap(g=>{u.current=g}),r.catchError(g=>(console.error(g),r.EMPTY))).subscribe(b);return()=>{l.current.unsubscribeOnUnmount!==!1&&p.unsubscribe()}},[...i]),f=v.useCallback(()=>u.current,[]);return v.useSyncExternalStore(h,f,f)}function qe(s){return s instanceof Promise||s&&typeof s.then=="function"&&typeof s.catch=="function"}function R(s){if(r.isObservable(s))return s;if(qe(s))return r.from(s);if(typeof s!="function")return r.of(s);const e=s;return r.defer(()=>{const t=e();return qe(t)?r.from(t):r.isObservable(t)?t:r.of(t)})}function Fe(s,e=[]){const t=Q(s);v.useEffect(()=>{const n=R(t.current).subscribe();return()=>{n.unsubscribe()}},[...e,t])}const $e=s=>{const e=v.useRef();return e.current||(e.current=s()),v.useEffect(()=>{process.env.NODE_ENV},[]),e},Re=({onBeforeComplete:s,completeOnUnmount:e=!0}={})=>{const t=$e(()=>new r.Subject),n=v.useRef(!1),i=Q(s),u=Q(e);return v.useEffect(()=>(n.current&&(t.current=new r.Subject,n.current=!1),()=>{if(!u.current){n.current=!0;return}n.current||(i.current!=null&&i.current(),t.current.complete(),n.current=!0)}),[u,i,t]),t},vt=()=>{const s=Re(),e=Q(s.current.asObservable()),t=v.useCallback(n=>{s.current.next(n)},[]);return[e.current,t]},xe=s=>{const e=$e(()=>new r.BehaviorSubject(s)),t=v.useRef(!1),n=v.useRef(s);return v.useEffect(()=>(t.current&&(e.current=new r.BehaviorSubject(n.current),t.current=!1),()=>{t.current||(e.current.complete(),t.current=!0)}),[e]),e},Ot=s=>{const e=xe(s),t=Q(e.current.asObservable()),n=v.useCallback(i=>{e.current.next(i)},[e.current]);return[t.current,n,e.current.getValue()]},Je=Symbol("SIGNAL_RESET");function wt(s={}){const e={default:s.default,key:s.key},{default:t}=e??{},n=new r.BehaviorSubject(t),i=a=>{if(typeof a=="function"){const l=a(n.getValue());if(l===n.getValue())return;n.next(l);return}if(a===Je){n.next(t??void 0);return}n.next(a)},u=()=>n.getValue();if("get"in s){const a=h=>(h.subject.pipe(r.skip(1),r.first()).subscribe(()=>{var o;const f=(o=s.get)==null?void 0:o.call(s,a);i(f)}),h.getValue()),l=s.get(a);return i(l),{getValue:u,config:s,subject:n}}return{setValue:i,getValue:u,config:e,subject:n}}function $t(s,e){const n=e??(()=>s.getValue());return fe(()=>s.subject.pipe(r.map(u=>n(u)),r.distinctUntilChanged()),{defaultValue:n(s.getValue())},[])}const Et=s=>({getItem:async e=>{const t=await s.getItem(e);if(t)return JSON.parse(t)},setItem:async(e,t)=>{await s.setItem(e,JSON.stringify(t))},removeItem:async e=>{},clear:async()=>{}}),Ce=s=>{if(!(!s||typeof s!="object"))return s},Ct=({adapter:s,key:e})=>({clear:async()=>await s.removeItem(e),removeItem:async t=>{const n=await s.getItem(e),{[t]:i,...u}=Ce(n)??{};await s.setItem(e,u)},getItem:async t=>{const n=await s.getItem(e),i=Ce(n)??{};if(t in i)return i[t]},setItem:async(t,n)=>{const i=await s.getItem(e),u=Ce(i)??{};await s.setItem(e,{...u,[t]:n})}}),Xe=({key:s}={})=>s?Ct({adapter:Xe(),key:s}):{clear:async()=>{localStorage.clear()},removeItem:async e=>{localStorage.removeItem(e)},getItem:async e=>{const t=localStorage.getItem(e);if(t)return JSON.parse(t)},setItem:async(e,t)=>{localStorage.setItem(e,JSON.stringify(t))}},se="__reactjrx",Mt=s=>{if(typeof s=="object"&&s!==null&&se in s&&s[se]===se)return s};function me(s){return s!=null}const He=s=>{const e=xe(s);return v.useEffect(()=>{e.current.next(s)},[s,e]),e},jt=({adapter:s,config:e})=>{const{signal:t,version:n}=e,u={value:t.getValue(),[se]:se,migrationVersion:n};return r.from(s.setItem(t.config.key,u)).pipe(r.catchError(a=>(console.error(a),r.of(null))))};function Ft({adapter:s,config:e}){const{hydrate:t=({value:u})=>u,signal:n,version:i}=e;return r.from(s.getItem(n.config.key)).pipe(r.switchMap(u=>{const a=Mt(u);if(!a||a.migrationVersion!==void 0&&i>a.migrationVersion||a.value===void 0)return r.of(u);const l=a.value;return n.setValue(t({value:l,version:i})),r.of(u)}))}function Rt({entries:s=[],onReady:e,adapter:t}){const n=Q(s),i=Q(e),u=He(t),a=fe(()=>{const h=n.current;return u.current.pipe(r.switchMap(f=>(h.length===0||!f?r.of(!0):r.zip(...h.map(b=>Ft({adapter:f,config:b}))).pipe(r.map(()=>!0))).pipe(r.tap(()=>{i.current!=null&&i.current()}),r.catchError(b=>(console.error("Unable to hydrate",b),r.EMPTY)))))},{defaultValue:!1},[u,n]),l=He(a);return Fe(()=>l.current.pipe(r.filter(h=>h),r.switchMap(()=>u.current),r.filter(me),r.switchMap(h=>r.merge(...n.current.map(f=>f.signal.subject.pipe(r.throttleTime(500,r.asyncScheduler,{trailing:!0}),r.switchMap(()=>r.from(jt({adapter:h,config:f})))))))),[l,u]),{isHydrated:a}}const xt=()=>{const s=Re({onBeforeComplete:()=>{s.current.next()}});return s};function Ze(s,e){return Math.min(s,e)}function et(s,e){return Math.pow(2,s)*e}function Ue(s){const{retry:e,retryDelay:t,retryAfterDelay:n,retryAfter:i=()=>r.of(!0)}=s,u=typeof e!="function"?e===!1?0:e===!0?1/0:e??1/0:1/0,a=typeof e=="function"?e:()=>!0,l=typeof t=="number"?t:100,h={shouldRetry:a,...s},{maxInterval:f=1/0,resetOnSuccess:o=!1,backoffDelay:b=et}=h;return $=>r.defer(()=>{let d=0;const p=(g,C)=>g<u?a(g,C):!1;return $.pipe(K.catchError(g=>{var E;if(d++,!p(d-1,g))throw g;const C=(E=s.caughtError)==null?void 0:E.call(s,d,g);if(!C)throw g;return C.pipe(K.mergeMap(O=>r.merge(r.of(O),r.throwError(()=>g))))}),K.retryWhen(g=>g.pipe(K.concatMap(C=>{const E=d-1;return i().pipe(K.first(),K.mergeMap(()=>p(E,C)?r.timer(Ze(b(E,l),f)).pipe(K.mergeMap(O=>n&&!n(E,C)?r.throwError(()=>C):r.of(O))):r.throwError(()=>C)))}))),K.catchError(g=>{if(s.catchError)return s.catchError(d,g);throw g}),K.tap(()=>{o&&(d=0)}))})}const Ut=(s,e)=>s.length===e.length&&s.every((t,n)=>t===e[n]),tt=s=>{v.useEffect(s,[])},At=s=>{tt(()=>{s()})};function We(s){return Object.prototype.toString.call(s)==="[object Object]"}function Me(s){if(!We(s))return!1;const e=s.constructor;if(typeof e>"u")return!0;const t=e.prototype;return!(!We(t)||!t.hasOwnProperty("isPrototypeOf"))}const re=s=>JSON.stringify(s,(e,t)=>Me(t)?Object.keys(t).sort().reduce((n,i)=>(n[i]=t[i],n),{}):t),Ae=(s=21)=>crypto.getRandomValues(new Uint8Array(s)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+="-":e+="_",e),""),J=()=>({context:void 0,data:void 0,error:null,status:"idle",submittedAt:0,variables:void 0,failureCount:0,failureReason:null,isPaused:!1});function Qe(s){let e=0;return function(n){return new r.Observable(i=>{e++;const u=n.subscribe(i);return s(e),()=>{e--,s(e),u.unsubscribe()}})}}const ne=s=>s.pipe(r.takeWhile(e=>e.status!=="error"&&e.status!=="success",!0));var H;class Qt{constructor({__queryFinalizeHook:e}={}){w(this,H,new r.Subject);m(this,"state$");const t=new r.BehaviorSubject(0),n=t.pipe(r.filter(i=>i===0));this.state$=c(this,H).pipe(r.concatMap(({args:i,mutation:u,options:a})=>{const l=a.mapOperator??"merge",h=c(this,H).pipe(r.filter(()=>l==="merge")),f=c(this,H).pipe(r.filter(()=>l==="switch"),r.tap(()=>{u.cancel()})),o=r.defer(()=>(u.execute(i),r.EMPTY)),b=u.state$.pipe(ne,r.last(),r.mergeMap(()=>u.state$),r.takeUntil(c(this,H))),$=u.state$.pipe(ne,r.skip(1)),d=r.merge(n,h,f,u.cancelled$);return r.merge($,b,o).pipe(r.map(p=>({state:p,mutation:u})),e??r.identity,r.takeUntil(d))}),r.shareReplay({refCount:!0,bufferSize:1}),Qe(i=>{t.next(i)}))}trigger({args:e,options:t,mutation:n}){c(this,H).next({args:e,options:t,mutation:n})}}H=new WeakMap;function Ee(s,e){return s===e?!0:typeof s!=typeof e?!1:s&&e&&typeof s=="object"&&typeof e=="object"?!Object.keys(e).some(t=>!Ee(s[t],e[t])):!1}const ye=(s,e,{exact:t=!1}={})=>t?re(s)===re(e):Ee(s,e);function x(s,e){if(s==null||e===void 0||typeof s!="object"||typeof e!="object")return s===e;if(s.constructor!==(e==null?void 0:e.constructor))return!1;const t=Object.keys(s),n=Object.keys(e);if(t.length!==n.length)return!1;for(const i of t)if(!e.hasOwnProperty(i)||s[i]!==e[i])return!1;return!0}const rt=s=>s.pipe(r.distinctUntilChanged(({data:e,...t},{data:n,...i})=>x(t,i)&&x(e,n)));var z,I;class Pt{constructor(e,t={},n){w(this,z);w(this,I,new r.BehaviorSubject(void 0));m(this,"observed$");m(this,"getObserverResultFromState",e=>({...J(),...e,isSuccess:e.status==="success",isPending:e.status==="pending",isIdle:e.status==="idle",isError:e.status==="error",mutate:this.mutate,reset:this.reset}));var i;this.client=e,this.options=t,this.options.mutationKey=((i=this.options)==null?void 0:i.mutationKey)??[Ae()],j(this,z,n??new Qt(this.options)),this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this),c(this,I).pipe(r.filter(me),r.mergeMap(u=>c(this,z).state$.pipe(r.takeUntil(u.mutation.state$.pipe(ne,r.last()))))).subscribe(),this.observed$=c(this,I).pipe(r.switchMap(u=>(u==null?void 0:u.mutation.state$.pipe(r.map(a=>({state:a,options:u.options}))))??r.EMPTY),r.tap(({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)))}),r.ignoreElements())}setOptions(e){var i;const t=this.options;this.options=this.client.defaultMutationOptions({mutationKey:this.options.mutationKey,...e});const n=(i=c(this,I).getValue())==null?void 0:i.mutation;this.options.mutationKey&&t.mutationKey&&!ye(this.options.mutationKey,t.mutationKey,{exact:!0})?this.reset():n==null||n.setOptions(this.options)}observe(){var u;const e=this.getObserverResultFromState(((u=c(this,I).getValue())==null?void 0:u.mutation.state)??J()),t=c(this,z).state$.pipe(r.distinctUntilChanged(({mutation:a,state:{data:l,...h}},{mutation:f,state:{data:o,...b}})=>a===f&&x(h,b)&&x(l,o)),r.map(({state:a})=>a),r.scan((a,l)=>({...a,...l,...l.status==="pending"&&{data:l.data??a.data},...l.status==="pending"&&{error:l.error??a.error}})),r.map(a=>this.getObserverResultFromState(a))),n=c(this,I).pipe(r.filter(me),r.switchMap(a=>a.mutation.cancelled$),r.map(()=>this.getObserverResultFromState(J())));return{result$:r.merge(this.observed$,t,n).pipe(rt),lastValue:e}}subscribe(e){const t=this.observe().result$.subscribe(n=>{e(n)});return()=>{t.unsubscribe()}}async mutate(e,t={}){const n=this.client.getMutationCache().build(this.client,this.options);return c(this,I).next({mutation:n,options:t}),c(this,z).trigger({args:e,options:this.options,mutation:n}),await new Promise((i,u)=>{n.state$.pipe(ne,r.last()).subscribe({error:a=>{u(a)},next:a=>{a.error?u(a.error):i(a.data)}})})}getCurrentResult(){var t;const e=this.client.getMutationCache().find({exact:!0,mutationKey:(t=this.options)==null?void 0:t.mutationKey});return this.getObserverResultFromState((e==null?void 0:e.state)??J())}reset(){const{mutation:e}=c(this,I).getValue()??{};c(this,I).next(void 0),e==null||e.cancel()}}z=new WeakMap,I=new WeakMap;const st=v.createContext(void 0),kt=({client:s})=>(v.useEffect(()=>(s.mount(),()=>{s.unmount()}),[s]),null),Vt=v.memo(({children:s,client:e})=>{const t=v.useMemo(()=>e,[e]);return Ne.jsxs(st.Provider,{value:t,children:[Ne.jsx(kt,{client:e}),s]})}),Pe=s=>{const e=v.useContext(st);if(s)return s;if(!e)throw new Error("No QueryClient set, use QueryClientProvider to set one");return e};function It(){}function Tt(s,e){const t=Pe(e),n=Q(s),i=$e(()=>[Ae()]),u=re(s.mutationKey??i.current),[a]=v.useState(()=>new Pt(t,s));v.useEffect(()=>{a.setOptions(s)},[a,s]);const l=v.useMemo(()=>a.observe(),[u,a]),h=fe(l.result$)??l.lastValue,f=v.useCallback((o,b)=>{a.mutate(o,b).catch(It)},[a]);return v.useEffect(()=>()=>{n.current.cancelOnUnMount&&a.reset()},[a,n]),{...h,mutate:f,mutateAsync:h.mutate}}function Dt(s){return e=>e.pipe(K.tap(t=>{s.next(t)}))}const X=typeof window>"u"||"Deno"in window;class Kt{constructor(){m(this,"isOnlineSubject",new r.BehaviorSubject(!0));m(this,"online$",this.isOnlineSubject.pipe(r.distinctUntilChanged()));m(this,"backToOnline$",this.online$.pipe(r.filter(e=>e),r.first()));r.merge(X?r.EMPTY:r.fromEvent(window,"offline").pipe(r.map(()=>!1)),X?r.EMPTY:r.fromEvent(window,"online").pipe(r.map(()=>!0))).pipe(Dt(this.isOnlineSubject)).subscribe()}isOnline(){return this.isOnlineSubject.getValue()}setOnline(e){this.isOnlineSubject.getValue()!==e&&this.isOnlineSubject.next(e)}}const _=new Kt;function ke(s,e){return s.isStaleByTime(e.staleTime)}function Nt(s,e){return e.enabled!==!1&&!s.state.dataUpdatedAt&&!(s.state.status==="error"&&e.retryOnMount===!1)&&s.state.fetchStatus!=="fetching"}function Le(s,e){return Nt(s,e)||s.state.dataUpdatedAt>0&&nt(s,e,e.refetchOnMount)}function _e(s,e,t,n){return s.state.fetchStatus!=="fetching"&&t.enabled!==!1&&(s!==e||n.enabled===!1)&&(!t.suspense||s.state.status!=="error")&&ke(s,t)}function qt(s,e){return nt(s,e,e.refetchOnWindowFocus)}function nt(s,e,t){if(e.enabled!==!1){const n=typeof t=="function"?t(s):t;return n==="idle"?s.state.fetchStatus==="idle":n==="always"||n!==!1&&ke(s,e)}return!1}function Ht(s){return(s??"online")==="online"?_.isOnline():!0}function ze(s,e){return e.reduce((t,n)=>n in s?{...t,[n]:s[n]}:t,{})}function Be(s){return Array.isArray(s)&&s.length===Object.keys(s).length}function it(s,e){if(s===e)return s;const t=Be(s)&&Be(e);if(t||Me(s)&&Me(e)){const n=t?s:Object.keys(s),i=n.length,u=t?e:Object.keys(e),a=u.length,l=t?[]:{};let h=0;for(let f=0;f<a;f++){const o=t?f:u[f];!t&&s[o]===void 0&&e[o]===void 0&&n.includes(o)?(l[o]=void 0,h++):(l[o]=it(s[o],e[o]),l[o]===s[o]&&s[o]!==void 0&&h++)}return i===a&&h===i?s:l}return e}function Ve(s,e){return((e==null?void 0:e.queryKeyHashFn)??re)(s)}function Ye(s,e){const{type:t="all",exact:n,fetchStatus:i,predicate:u,queryKey:a,stale:l}=s;if(a){if(n){if(e.queryHash!==Ve(a,e.options))return!1}else if(!Ee(e.queryKey,a))return!1}if(t!=="all"){const h=e.isActive();if(t==="active"&&!h||t==="inactive"&&h)return!1}return!(typeof l=="boolean"&&e.isStale()!==l||typeof i<"u"&&i!==e.state.fetchStatus||u&&!u(e))}function Wt(s,e){return Math.max(s+(e??0)-Date.now(),0)}function Lt(s,e){return typeof s=="function"?s(e):s}function Se(s,e,t){return typeof t.structuralSharing=="function"?t.structuralSharing(s,e):t.structuralSharing!==!1?it(s,e):e}const je=Symbol(),_t=({getOptions:s,getState:e,initialState:t})=>n=>n.pipe(r.scan((i,{command:u,state:a})=>{if(u==="reset")return{...i,...a};if(u==="cancel"){const S=i.status==="pending"?"pending":a.status??i.status;return{...i,...a,status:S}}const l=a.data,h=l!==void 0&&l!==i.data,f="data"in a,o=a.status==="success",b=i.data!==void 0,$=i.error!==void 0||i.error!==null,d=a.status??i.status,p=h?Se(e().data,l,s()):f?a.data:i.data,g=i.status==="error"||i.status==="success",C=a.status==="error"&&(i.status==="error"&&i.fetchStatus==="fetching"||i.status!=="error")?i.errorUpdateCount+1:i.errorUpdateCount,E=h?i.dataUpdateCount+1:a.dataUpdateCount??i.dataUpdateCount,O=a.status==="pending"&&g&&(b||$),U=d==="pending"?null:a.error??i.error;return{...i,...a,status:d,error:U,errorUpdateCount:C,...o&&{isInvalidated:!1},data:p,dataUpdateCount:E,...O&&{status:i.status}}},t)),zt=s=>s.pipe(r.map(({status:e,fetchStatus:t})=>t==="idle"&&(e==="success"||e==="error"))),at=s=>s.pipe(r.takeWhile(e=>e.fetchStatus!=="idle",!0));var Oe,W;class Bt{constructor(){w(this,Oe,r.merge(X?r.EMPTY:r.fromEvent(document,"visibilitychange"),X?r.EMPTY:r.fromEvent(window,"visibilitychange")).pipe(r.map(()=>document.visibilityState)));w(this,W,new r.BehaviorSubject(X?!0:document.visibilityState==="visible"));m(this,"focused$",c(this,W));m(this,"focusRegained$",this.focused$.pipe(r.skip(1),r.filter(e=>e)));c(this,Oe).pipe(r.tap(e=>{c(this,W).next(e==="visible")})).subscribe()}isFocused(){return c(this,W).getValue()}setFocused(e){c(this,W).getValue()!==(e??!0)&&c(this,W).next(e??!0)}subscribe(e){const t=this.focused$.subscribe(e);return()=>{t.unsubscribe()}}refresh(){document.dispatchEvent(new Event("visibilitychange"))}}Oe=new WeakMap,W=new WeakMap;const ve=new Bt,Yt=s=>s.pipe(r.filter(e=>e.status==="success"),r.map(e=>({data:e.data,status:e.status,dataUpdatedAt:e.dataUpdatedAt})),r.distinctUntilChanged(x));var q,M,ie,B,A,Z,ae;class ut{constructor(e,t){w(this,q);w(this,M);w(this,ie,new r.Subject);m(this,"queryUpdateSubject",new r.Subject);w(this,B);w(this,A);w(this,Z);w(this,ae,0);m(this,"getObserverResultFromQuery",({options:e,query:t,optimisticResult:n,prevResult:{result:i,options:u,state:a,select:l,selectError:h,selectResult:f}})=>{var ge;const o=t.state,b=t.state.status==="pending",$=c(this,M),d=this.options,g=t!==$?t.state:c(this,B);let{errorUpdatedAt:C,fetchStatus:E,error:O}=o;if(n){const P=!!c(this,ae),Te=!P&&Le(t,e),bt=P&&_e(t,$,e,d);(Te||bt)&&(E=Ht(t.options.networkMode)?"fetching":"paused")}const U=b&&E==="fetching";let S,y=h,T=l??null,D=f;if(e.select&&typeof o.data<"u")if(i&&o.data===(a==null?void 0:a.data)&&e.select===l)S=f;else try{T=e.select,S=e.select(o.data),S=Se(i==null?void 0:i.data,S,e),D=S,y=null}catch(P){S=f,y=P}else S=o.data,y=null;let V=E!=="idle"&&!o.dataUpdatedAt?"pending":o.status;y&&(O=y,S=f,C=(i==null?void 0:i.errorUpdatedAt)??C,V="error");const de=V==="error";let pe=!1;if(typeof e.placeholderData<"u"&&typeof S>"u"&&V==="pending"){let P;if(i!=null&&i.isPlaceholderData&&e.placeholderData===(u==null?void 0:u.placeholderData))P=i.data;else if(P=typeof e.placeholderData=="function"?e.placeholderData((ge=c(this,Z))==null?void 0:ge.state.data,c(this,Z)):e.placeholderData,e.select&&typeof P<"u")try{P=e.select(P)}catch{}typeof P<"u"&&(V="success",S=Se(i==null?void 0:i.data,P,e),pe=!0)}const be=E==="fetching";return{result:{status:V,fetchStatus:E,isPending:b,isSuccess:V==="success",isError:de,isInitialLoading:U,isLoading:U,data:S,dataUpdatedAt:o.dataUpdatedAt,error:O,errorUpdatedAt:C,failureCount:o.fetchFailureCount,failureReason:o.fetchFailureReason,errorUpdateCount:o.errorUpdateCount,isFetched:o.dataUpdateCount>0||o.errorUpdateCount>0,isFetchedAfterMount:o.dataUpdateCount>g.dataUpdateCount||o.errorUpdateCount>g.errorUpdateCount,isFetching:be,isRefetching:be&&!b,isLoadingError:de&&o.dataUpdatedAt===0,isPaused:E==="paused",isPlaceholderData:pe,isRefetchError:de&&o.dataUpdatedAt!==0,isStale:ke(t,e),refetch:this.refetch},selectError:y,select:T,selectResult:D}});this.options=t,j(this,q,e),this.bindMethods(),j(this,M,this.setOptions(t));const n=c(this,M);j(this,B,n.state);const{result:i,select:u}=this.getObserverResultFromQuery({query:n,options:this.options,prevResult:{options:this.options,state:n.state}});j(this,A,{state:n.state,options:t,result:i,select:u})}bindMethods(){this.refetch=this.refetch.bind(this)}setOptions(e){const t=this.options;if(this.options=c(this,q).defaultQueryOptions(e),x(this.options,t)||c(this,q).getQueryCache().notify({type:"observerOptionsUpdated",query:c(this,M),observer:this}),typeof this.options.enabled<"u"&&typeof this.options.enabled!="boolean")throw new Error("Expected enabled to be a boolean");const n=this.buildQuery(this.options);return n!==c(this,M)&&(j(this,B,n.state),j(this,M,n)),this.queryUpdateSubject.next({options:this.options,query:n}),n}buildQuery(e){const t=c(this,q).getQueryCache().build(c(this,q),e);return!t.options.queryFn&&this.options.queryFn&&t.setOptions(e),t}getCurrentResult(){return this.getObserverResultFromQuery({options:this.options,prevResult:c(this,A),query:c(this,M)}).result}getCurrentQuery(){return c(this,M)}getOptimisticResult(e){const t=this.buildQuery(e),n=this.getObserverResultFromQuery({query:t,options:e,optimisticResult:!0,prevResult:c(this,A)});return Gt(this,n.result)&&this.updateResult({query:t,...n}),n.result}updateResult({query:e,result:t,selectError:n,select:i,selectResult:u}){c(this,A).state=e.state,c(this,A).result=t,c(this,A).selectResult=u,n!==void 0&&(c(this,A).selectError=n),i!==void 0&&(c(this,A).select=i),c(this,A).options=this.options,e.state.data!==void 0&&j(this,Z,e),c(this,q).getQueryCache().notify({query:c(this,M),type:"observerResultsUpdated"})}async refetch({...e}={}){return await this.fetch({...e})}async fetch(e){const t=this.buildQuery(this.options);t!==c(this,M)&&(j(this,M,t),j(this,B,t.state),this.queryUpdateSubject.next({options:this.options,query:t}));const n={...e,cancelRefetch:(e==null?void 0:e.cancelRefetch)??!0};c(this,M).fetch(this.options,n).catch(r.noop),c(this,ie).next({query:t,fetchOptions:n}),await t.getFetchResultAsPromise();const{result:i}=this.getObserverResultFromQuery({query:t,options:this.options,prevResult:c(this,A)});return i}subscribe(e){const t=this.observe().subscribe(e);return()=>{t.unsubscribe()}}observe(){const e=c(this,M),t=this.queryUpdateSubject.pipe(r.map(({query:a})=>a),r.startWith(c(this,M)),r.distinctUntilChanged()),n=this.queryUpdateSubject.pipe(r.startWith({query:c(this,M),options:this.options}),r.pairwise(),r.tap(([{options:a,query:l},{options:h,query:f}])=>{_e(f,l,h,a)&&this.fetch().catch(r.noop)}),r.ignoreElements()),i=t.pipe(r.switchMap(a=>a.observe(this)),r.ignoreElements());return r.merge(i,n,t.pipe(r.switchMap(a=>{const l=this.options,h=this.queryUpdateSubject.pipe(r.startWith({query:a,options:l}),r.filter(y=>y.query===a),r.map(y=>y.options),r.distinctUntilChanged(),r.shareReplay(1)),f=c(this,ie).pipe(r.filter(y=>y.query===a)),o=a.state$.pipe(Yt,r.switchMap(y=>this.options.staleTime===1/0?r.NEVER:(this.options.staleTime??0)<=0?r.of(y).pipe(r.delay(1)):r.timer(this.options.staleTime??1)),r.takeWhile(()=>this.options.enabled??!0)),b=(y,T)=>{const D=l.notifyOnChangeProps,V=typeof D=="function"?D():D;return(Array.isArray(V)?V.length===0?()=>!0:(pe,be)=>{const Ie=ze(pe,V),ge=ze(be,V);return x(Ie,ge)}:x)(y,T)},$=f.pipe(r.switchMap(()=>a.state$),at),d=h.pipe(r.map(({refetchInterval:y,refetchIntervalInBackground:T})=>({refetchInterval:(typeof y=="function"?y(c(this,M)):y)??!1,refetchIntervalInBackground:T})),r.distinctUntilChanged(x),r.switchMap(({refetchInterval:y,refetchIntervalInBackground:T})=>y?r.interval(y).pipe(r.tap(()=>{(T||ve.isFocused())&&this.fetch({cancelRefetch:!1}).catch(r.noop)})):r.NEVER),r.ignoreElements()),p=h.pipe(r.map(({enabled:y})=>y??!0),r.distinctUntilChanged()),g=p.pipe(r.filter(y=>!y),r.map(()=>a.state)),C=p.pipe(r.filter(y=>y),r.switchMap(()=>ve.focusRegained$),r.withLatestFrom(h),r.tap(([,y])=>{qt(a,y)&&this.fetch({cancelRefetch:!1}).catch(r.noop)}),r.ignoreElements()),E=g.pipe(r.map(()=>a.state)),O=y=>y.pipe(r.withLatestFrom(h),r.map(([,T])=>{const D=this.getObserverResultFromQuery({query:a,options:T,prevResult:c(this,A)});return this.updateResult({query:a,...D}),D.result})),S=r.merge(E,$,a.state$,o).pipe(O,r.distinctUntilChanged(x),r.distinctUntilChanged(b));return r.merge(d,C,S)})).pipe(Qe(a=>j(this,ae,a)),r.tap({subscribe:()=>{Le(e,this.options)&&this.fetch().catch(r.noop)}})))}destroy(){}}q=new WeakMap,M=new WeakMap,ie=new WeakMap,B=new WeakMap,A=new WeakMap,Z=new WeakMap,ae=new WeakMap;function Gt(s,e){return!x(s.getCurrentResult(),e)}const ct=we.createContext(!1),Jt=()=>we.useContext(ct);ct.Provider;function Xt(){let s=!1;return{clearReset:()=>{s=!1},reset:()=>{s=!0},isReset:()=>s}}const Zt=we.createContext(Xt()),er=()=>we.useContext(Zt);function tr(s,e){return typeof s=="function"?s(...e):!!s}const rr=({result:s,errorResetBoundary:e,throwOnError:t,query:n})=>s.isError&&!e.isReset()&&!s.isFetching&&n&&tr(t,[s.error,n]);function ot(s,e,t){if(process.env.NODE_ENV!=="production"&&(typeof s!="object"||Array.isArray(s)))throw new Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');const n=Pe(t),i=Jt(),u=er(),a=n.defaultQueryOptions(s);a._optimisticResults=i?"isRestoring":"optimistic";const[l]=v.useState(()=>new e(n,a)),h=$e(()=>l.observe()),f=Q(l.getOptimisticResult(a)),o=f.current;fe(()=>h.current.pipe(r.filter($=>!x($,f.current))),[]),v.useEffect(()=>{l.setOptions(a)},[a,l]);const b=o.error;if(b&&rr({result:o,errorResetBoundary:u,throwOnError:a.throwOnError,query:n.getQueryCache().get(a.queryHash)}))throw b;return f.current}function sr(s,e){return ot(s,ut,e)}function nr(s,e){return ot({refetchOnMount:"idle",refetchOnReconnect:!1,refetchInterval:!1,refetchOnWindowFocus:!1,...s},ut,e)}function ir(s,e,t=[]){const n=e!=null&&!Array.isArray(e)?e:{},i=n.retry??!0,u=Q(n.onError??(h=>{console.error(h)})),a=v.useCallback(()=>R(s),t),l=v.useCallback(()=>a().pipe(r.catchError(h=>{throw u.current(h),h}),i?r.retry():r.identity),[a,i,u]);Fe(l,t)}const lt=()=>s=>r.merge(r.of({isPaused:!0}),_.backToOnline$.pipe(r.mergeMap(()=>r.merge(r.of({isPaused:!1}),s)))),ar=s=>{let e=0;return s.pipe(r.catchError(t=>(e++,e<=1&&!_.isOnline()?r.merge(r.of({failureCount:e,failureReason:t}),r.timer(1).pipe(r.mergeMap(()=>r.throwError(()=>t).pipe(lt())))):r.throwError(()=>t))))},ur=({variables:s,state:e,options:t})=>{const n=e.isPaused,i=async()=>await Promise.reject(new Error("No mutationFn found")),u=t.mutationFn??i,a=R(()=>{var d;return((d=t.onMutate)==null?void 0:d.call(t,s))??void 0}),l=r.of(e.context),h=r.iif(()=>n,l,a).pipe(r.shareReplay(1)),f=(d,p,g)=>R(()=>{var E;return(E=t.onError)==null?void 0:E.call(t,d,s,p)}).pipe(r.catchError(()=>r.of(d)),r.map(()=>({failureCount:g,error:d,failureReason:d,context:p,status:"error"}))),o=h.pipe(r.switchMap(d=>{const g=(typeof u=="function"?R(()=>u(s)):u).pipe(r.share()),C=g.pipe(r.isEmpty(),r.tap(O=>{if(O)throw new Error("Mutation completed without any emission (EMPTY)")}),r.ignoreElements()),E=r.merge(g,C).pipe(r.map(O=>({result:{data:O},error:null,context:d})),ar,Ue({...t,retry:(O,U)=>{const S=t.retry??0;return typeof S=="function"?S(O,U):typeof S=="boolean"?S:O<S},caughtError:(O,U)=>r.of({failureCount:O,failureReason:U}),catchError:(O,U)=>f(U,d,O).pipe(r.map(S=>({...S,result:void 0})))}),r.takeWhile(({result:O,error:U})=>(O==null?void 0:O.data)===void 0&&U===void 0,!0));return _.isOnline()||t.networkMode==="offlineFirst"||t.networkMode==="always"?E:E.pipe(lt())})),b=r.of({...e,variables:s,status:"pending",isPaused:!1,failureCount:0,failureReason:null,submittedAt:e.submittedAt??new Date().getTime()});return r.merge(b,h.pipe(r.map(d=>({context:d}))),o.pipe(r.switchMap(({result:d,error:p,...g})=>{if(!d&&!p)return r.of({...g});const C=p?r.of(null):R(()=>{var S;return(S=t.onSuccess)==null?void 0:S.call(t,d==null?void 0:d.data,s,g.context)}),O=R(()=>{var S;return(S=t.onSettled)==null?void 0:S.call(t,d==null?void 0:d.data,p,s,g.context)}).pipe(r.catchError(S=>d?r.of(d):r.of(S)));return r.concat(C,O).pipe(r.toArray(),r.map(()=>p?{error:p,data:void 0,variables:s,...g}:{status:"success",error:p,data:d==null?void 0:d.data,variables:s,failureCount:0,failureReason:null,...g}),r.catchError(S=>f(S,g.context,0).pipe(r.map(y=>({...y,data:void 0})))))}))).pipe(r.scan((d,p)=>({...d,...p,data:p.data??d.data,error:p.error??d.error}),J()))};var ue,L,ee;class cr{constructor({options:e,mutationCache:t,state:n}){w(this,ue,new r.BehaviorSubject(0));w(this,L,new r.Subject);w(this,ee,new r.Subject);m(this,"state",J());m(this,"state$");m(this,"options");m(this,"observerCount$",c(this,ue).asObservable());m(this,"cancelled$",c(this,L).asObservable());this.options=e,this.state=n??this.state;const i=c(this,L).pipe(r.filter(()=>this.state.status==="pending"),r.map(()=>({status:"idle"}))),u=c(this,ee).pipe(r.switchMap(l=>ur({options:{...this.options,onMutate:h=>{const f=R(()=>{var d,p;return(p=(d=t.config).onMutate)==null?void 0:p.call(d,h,this)}),b=R(()=>{var d,p;return(p=(d=this.options).onMutate)==null?void 0:p.call(d,h)});return f.pipe(r.mergeMap(()=>b))},onError:(h,f,o)=>{const b=R(()=>{var d,p;return(p=(d=t.config).onError)==null?void 0:p.call(d,h,f,o,this)}),$=R(()=>{var d,p;return(p=(d=this.options).onError)==null?void 0:p.call(d,h,f,o)});return r.concat(b,$).pipe(r.toArray())},onSettled:(h,f,o,b)=>{const $=R(()=>{var p,g;return(g=(p=t.config).onSettled)==null?void 0:g.call(p,h,f,o,b,this)}),d=R(()=>{var p,g;return(g=(p=this.options).onSettled)==null?void 0:g.call(p,h,f,o,b)});return r.concat($,d).pipe(r.toArray())},onSuccess:(h,f,o)=>{const b=R(()=>{var d,p;return(p=(d=t.config).onSuccess)==null?void 0:p.call(d,h,f,o,this)}),$=R(()=>{var d,p;return(p=(d=this.options).onSuccess)==null?void 0:p.call(d,h,f,o)});return r.concat(b,$).pipe(r.toArray())}},state:this.state,variables:l}).pipe(r.takeUntil(c(this,L))))),a=r.merge(i,u);this.state$=a.pipe(r.startWith(this.state),r.scan((l,h)=>({...l,...h}),this.state),rt,r.tap(l=>{this.state=l}),r.shareReplay(1),Qe(l=>{c(this,ue).next(l)}))}get meta(){return this.options.meta}setOptions(e){this.options={...this.options,...e}}execute(e){return c(this,ee).next(e),c(this,ee).complete(),this.state$.pipe(ne)}continue(){return this.execute(this.state.variables)}cancel(){c(this,L).next(),c(this,L).complete()}}ue=new WeakMap,L=new WeakMap,ee=new WeakMap;const Ge=({mutationKey:s,status:e,predicate:t,exact:n=!0}={})=>u=>n&&s!==void 0&&u.options.mutationKey!==void 0&&!ye(u.options.mutationKey,s,{exact:n})||!n&&s!==void 0&&u.options.mutationKey!==void 0&&!ye(u.options.mutationKey,s,{exact:n})||e&&u.state.status!==e?!1:t?t(u):!0;class ht{constructor(){m(this,"entriesSubject",new r.BehaviorSubject([]));m(this,"changeSubject",new r.Subject);m(this,"entries$",this.entriesSubject.pipe(r.share()));m(this,"added$",this.changeSubject.pipe(r.filter(({type:e})=>e==="added"),r.map(({entity:e})=>e),r.share()));m(this,"removed$",this.changeSubject.pipe(r.filter(({type:e})=>e==="removed"),r.map(({entity:e})=>e),r.share()));m(this,"stateChange$",r.merge(this.entriesSubject.pipe(r.first(),r.mergeMap(e=>r.from(e))),this.added$).pipe(r.mergeMap(e=>e.state$.pipe(r.map(()=>e),r.takeUntil(this.removed$.pipe(r.filter(t=>t===e))))),r.share()))}getValues(){return this.entriesSubject.getValue()}remove(e){this.entriesSubject.next(this.entriesSubject.getValue().filter(t=>e!==t)),this.changeSubject.next({type:"removed",entity:e})}add(e){this.entriesSubject.next([...this.entriesSubject.getValue(),e]),this.changeSubject.next({type:"added",entity:e})}find(e){return this.entriesSubject.getValue().find(e)}}var k;class ft{constructor(e={}){w(this,k,new ht);this.config=e}build(e,t,n){const i=new cr({mutationCache:this,options:e.defaultMutationOptions(t),state:n});return i.state$.pipe(r.filter(({status:u})=>u==="success"||u==="error"),r.switchMap(()=>i.observerCount$.pipe(r.filter(u=>u<=1),r.take(1))),r.switchMap(()=>r.timer(i.options.gcTime??5*60*1e3)),r.take(1)).subscribe({complete:()=>{this.remove(i)}}),c(this,k).add(i),i}getAll(){return this.findAll()}remove(e){const t=c(this,k).getValues().find(n=>n===e);t==null||t.cancel(),c(this,k).remove(e)}find(e){const t={exact:!0,...e},n=Ge(t);return c(this,k).getValues().find(i=>n(i))}findAll(e={}){const t={exact:!0,...e},n=Ge(t);return c(this,k).getValues().filter(i=>n(i)).map(i=>i)}observe(){return c(this,k).stateChange$.pipe(r.startWith())}subscribe(e){const t=r.merge(c(this,k).added$.pipe(r.tap(n=>{e({type:"added",mutation:n})})),c(this,k).removed$.pipe(r.tap(n=>{e({type:"removed",mutation:n})})),c(this,k).stateChange$.pipe(r.tap(n=>{e({type:"updated",action:{...n.state,type:"success"},mutation:n})}))).subscribe();return()=>{t.unsubscribe()}}resumePausedMutations(){const e=this.findAll({predicate:n=>n.state.isPaused});if(!e.length)return r.EMPTY;const t=e.map(n=>n.continue());return r.combineLatest(t)}clear(){this.getAll().forEach(e=>{this.remove(e)})}}k=new WeakMap;function or(s){const e=typeof s.initialData=="function"?s.initialData():s.initialData,t=typeof e<"u",n=t?typeof s.initialDataUpdatedAt=="function"?s.initialDataUpdatedAt():s.initialDataUpdatedAt:0;return{data:e,dataUpdateCount:0,dataUpdatedAt:t?n??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:t?"success":"pending",fetchStatus:"idle"}}const lr=s=>r.defer(()=>ve.isFocused()?s:ve.focusRegained$.pipe(r.mergeMap(()=>s))),hr=s=>{let e=0;return t=>{const n=_.backToOnline$.pipe(r.mergeMap(()=>r.merge(r.of({fetchStatus:"fetching"}),t)));return r.defer(()=>(e++,!_.isOnline()&&s.networkMode==="offlineFirst"&&e>1?r.merge(r.of({fetchStatus:"paused"}),n):!_.isOnline()&&s.networkMode!=="always"&&s.networkMode!=="offlineFirst"?r.merge(r.of({fetchStatus:"paused"}),n):t))}},fr=s=>e=>{const t=new r.Subject,n=t.pipe(r.first(),r.delay(1),r.mergeMap(()=>s.pipe(r.filter(i=>i===0))));return e.pipe(r.tap(()=>{t.next()}),r.takeUntil(n))},dr=s=>{const e=async()=>await Promise.reject(new Error("No query found"));process.env.NODE_ENV!=="production"&&s.queryFn===je&&console.error(`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${s.queryHash}'`);let t=!1;const n=s.queryFn&&s.queryFn!==je?s.queryFn:e,i=new AbortController,u={meta:s.meta,queryKey:s.queryKey};(o=>{Object.defineProperty(o,"signal",{enumerable:!0,get:()=>(s.onSignalConsumed(),i.signal)})})(u);const h=(typeof n=="function"?R(()=>n(u)):n).pipe(fr(s.observers$),r.tap({complete:()=>{t=!0}}),r.map(o=>({data:o})),hr(s),Ue({...s,retryAfter:()=>r.of(!0).pipe(lr),catchError:(o,b)=>r.of({status:"error",fetchStatus:"idle",fetchFailureCount:o,fetchFailureReason:b,error:b}),caughtError:(o,b)=>r.of({fetchFailureCount:o,fetchFailureReason:b})}),r.mergeMap(o=>"data"in o?r.of({...o,status:"success",fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null,dataUpdatedAt:new Date().getTime()}).pipe(r.delay(1),r.map(b=>t?b:{...b,fetchStatus:"fetching"})):r.of(o)),r.endWith({fetchStatus:"idle"}),r.share()),f=r.of({status:"pending",fetchStatus:_.isOnline()?"fetching":"paused"});return{state$:r.merge(f,h).pipe(r.share()),abortController:i}};class pr{constructor(e){m(this,"revert");m(this,"silent");this.revert=e==null?void 0:e.revert,this.silent=e==null?void 0:e.silent}}const br={backgroundColor:"transparent",color:"inherit"};function dt(s){const e={namespaces:[{name:"@reactjrx",style:{backgroundColor:"#d02f4e",color:"white"}}],namespace(t,n){const i=dt();return i.namespaces.push({name:t,style:n??br}),i},printNamespaces(){return{namespaces:e.namespaces.map(({name:t})=>`%c ${t} %c`).join(" "),styles:e.namespaces.reduce((t,{style:n})=>(t.push(`background-color: ${n.backgroundColor}; color: ${n.color};`),t.push("background-color: transparent; color: inherit;"),t),[])}},print(t,...n){return e},printWithoutNamespace(t,...n){return e},log(...t){return e.print("log",...t)},warn(...t){return e.print("warn",...t)},error(...t){return e.print("error",...t)},group(...t){return e.print("group",...t)},groupEnd(){return e}};return e}const gr=dt();var ce,Y;class mr{constructor(e){m(this,"queryKey");m(this,"queryHash");m(this,"gcTime");m(this,"options");w(this,ce);w(this,Y);m(this,"state");m(this,"executeSubject",new r.Subject);m(this,"cancelSubject",new r.Subject);m(this,"setDataSubject",new r.Subject);m(this,"invalidatedSubject",new r.Subject);m(this,"resetSubject",new r.Subject);m(this,"destroySubject",new r.Subject);m(this,"observersSubject",new r.BehaviorSubject([]));m(this,"abortSignalConsumed",!1);m(this,"observerCount$",this.observersSubject.asObservable().pipe(r.map(e=>e.length)));m(this,"observers$",this.observersSubject.asObservable());m(this,"state$");j(this,ce,e.defaultOptions),this.options=this.setOptions(e.options),this.queryKey=e.queryKey,this.queryHash=e.queryHash,j(this,Y,e.state??or(this.options)),this.state=c(this,Y),this.gcTime=this.updateGcTime(this.options.gcTime),this.state$=r.merge(this.resetSubject.pipe(r.map(()=>({command:"reset",state:c(this,Y)}))),this.invalidatedSubject.pipe(r.filter(()=>!this.state.isInvalidated),r.map(()=>({command:"invalidate",state:{isInvalidated:!0}}))),this.cancelSubject.pipe(r.filter(()=>!(this.state.error&&this.state.status==="error")),r.map(t=>({command:"cancel",state:{status:t!=null&&t.revert?this.state.status:"error",fetchStatus:"idle",error:new pr(t)}}))),this.executeSubject.pipe(r.mergeMap(()=>{let t=!1;const n=this.executeSubject.pipe(r.filter(f=>(f==null?void 0:f.cancelRefetch)!==!1)),i=this.observers$.pipe(r.pairwise(),r.tap(([f,o])=>{o.length===0&&f.length>0?t=!0:t=!1}),r.ignoreElements()),{state$:u,abortController:a}=dr({...this.options,observers$:this.observerCount$,queryKey:this.queryKey,retry:(f,o)=>{const b=this.options.retry??!0;return typeof b=="function"?b(f,o):typeof b=="boolean"?b:f<b},retryAfterDelay:()=>!t,onSignalConsumed:()=>{this.abortSignalConsumed=!0}}),l=this.observerCount$.pipe(r.filter(f=>f===0&&this.abortSignalConsumed),r.tap(()=>{this.cancelSubject.next({revert:!0})})),h=r.merge(this.cancelSubject,n,this.resetSubject,l).pipe(r.tap(()=>{this.abortSignalConsumed&&a.abort()}));return r.merge(u,i).pipe(r.map(f=>({command:"execute",state:f})),r.takeUntil(h))})),this.setDataSubject.pipe(r.map(({data:t,options:n})=>({command:"setData",state:{status:"success",data:t,dataUpdatedAt:(n==null?void 0:n.updatedAt)!==void 0?n.updatedAt:new Date().getTime()}})))).pipe(_t({initialState:this.state,getOptions:()=>this.options,getState:()=>this.state}),r.startWith(c(this,Y)),r.distinctUntilChanged(x),r.tap(t=>{this.state=t}),r.catchError(t=>{throw gr.error(t),t}),r.takeUntil(this.destroySubject),r.shareReplay({bufferSize:1,refCount:!1}))}setOptions(e){return this.options={...c(this,ce),...e},this.updateGcTime(this.options.gcTime),this.options}get meta(){return this.options.meta}get success$(){return this.state$.pipe(r.map(({data:e,status:t})=>({data:e,status:t})),r.distinctUntilChanged(x),r.filter(({status:e})=>e==="success"))}get error$(){return this.state$.pipe(r.map(({error:e,status:t})=>({error:e,status:t})),r.distinctUntilChanged(x),r.filter(({status:e})=>e==="error"))}get settled$(){return this.state$.pipe(r.map(({status:e})=>({status:e})),r.distinctUntilChanged(x),r.filter(({status:e})=>e==="success"||e==="error"))}observe(e){return this.state$.pipe(r.tap({subscribe:()=>{this.observersSubject.next([e,...this.observersSubject.getValue()])},unsubscribe:()=>{this.observersSubject.next(this.observersSubject.getValue().filter(n=>n!==e))}}))}getObserversCount(){return this.observersSubject.getValue().length}updateGcTime(e){return this.gcTime=Math.max(this.gcTime||0,e??(X?1/0:5*60*1e3)),this.gcTime}isActive(){return this.observersSubject.getValue().some(e=>e.options.enabled!==!1)}isDisabled(){return this.getObserversCount()>0&&!this.isActive()}isStale(){return this.state.isInvalidated||!this.state.dataUpdatedAt||this.observersSubject.getValue().some(e=>e.getCurrentResult().isStale)}isStaleByTime(e=0){return this.state.isInvalidated||!this.state.dataUpdatedAt||!Wt(this.state.dataUpdatedAt,e)}async getFetchResultAsPromise(){return await new Promise((e,t)=>{this.state$.pipe(at,r.last()).subscribe({error:t,next:n=>{n.error?t(n.error):e(n.data)}})})}async fetch(e,t){const{cancelRefetch:n}=t??{};return this.state.fetchStatus!=="idle"&&!(!!this.state.dataUpdatedAt&&n)?await this.getFetchResultAsPromise():(e&&this.setOptions(e),this.executeSubject.next(t),await this.getFetchResultAsPromise())}setData(e,t){const n=Se(this.state.data,e,this.options);return this.setDataSubject.next({data:n,options:t}),n}invalidate(){this.invalidatedSubject.next()}async cancel(e){this.cancelSubject.next(e)}destroy(){this.destroySubject.next(),this.destroySubject.complete(),this.executeSubject.complete()}reset(){this.resetSubject.next()}}ce=new WeakMap,Y=new WeakMap;var oe,N;class pt{constructor(e={}){w(this,oe,new r.Subject);w(this,N,new ht);this.config=e}mount(){}unmount(){}notify(e){c(this,oe).next(e)}observeIsFetching(e){return c(this,N).stateChange$.pipe(r.startWith(),r.map(()=>this.findAll({...e,fetchStatus:"fetching"}).length),r.distinctUntilChanged())}getAll(){return[...c(this,N).getValues()]}findAll(e={}){const t=this.getAll();return Object.keys(e).length>0?t.filter(n=>Ye(e,n)):t}build(e,t,n){const i=t.queryKey??[Ae()],u=t.queryHash??Ve(i,t);let a=this.get(u);return a||(a=new mr({cache:this,queryKey:i,queryHash:u,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(i)}),this.add(a)),a}add(e){if(!c(this,N).find(t=>t.queryHash===e.queryHash)){c(this,N).add(e);const t=e.observerCount$.pipe(r.filter(n=>n<1),r.take(1));e.success$.subscribe(()=>{var n,i;(i=(n=this.config).onSuccess)==null||i.call(n,e.state.data,e)}),e.error$.subscribe(()=>{var n,i;(i=(n=this.config).onError)==null||i.call(n,e.state.error,e)}),e.settled$.subscribe(()=>{var n,i;(i=(n=this.config).onSettled)==null||i.call(n,e.state.data,e.state.error,e)}),e.state$.pipe(zt,r.switchMap(n=>n?t.pipe(r.switchMap(()=>e.gcTime===1/0?r.NEVER:(setTimeout(r.noop,e.gcTime),r.timer(e.gcTime)))):r.NEVER),r.take(1)).subscribe({complete:()=>{this.remove(e)}})}}get(e){return c(this,N).find(t=>t.queryHash===e)}find(e){const t={exact:!0,...e};return this.getAll().find(n=>Ye(t,n))}subscribe(e){const t=r.merge(c(this,oe).pipe(r.tap(e))).subscribe();return()=>{t.unsubscribe()}}remove(e){const t=c(this,N).find(n=>n===e);t&&(e.destroy(),t===e&&c(this,N).remove(e))}clear(){}}oe=new WeakMap,N=new WeakMap;var G,F,le,he,te;class yr{constructor({mutationCache:e,queryCache:t,defaultOptions:n}={}){w(this,G);w(this,F);w(this,le,new Map);w(this,he,new Map);w(this,te);j(this,G,e??new ft),j(this,F,t??new pt),j(this,te,n??{})}mount(){}unmount(){}getMutationCache(){return c(this,G)}getQueryCache(){return c(this,F)}defaultMutationOptions(e){return{...c(this,te).mutations,...(e==null?void 0:e.mutationKey)&&this.getMutationDefaults(e.mutationKey),...e}}defaultQueryOptions(e){if(e._defaulted)return e;const t={...c(this,te).queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=Ve(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.enabled!==!0&&t.queryFn===je&&(t.enabled=!1),t}async fetchQuery(e){const t=this.defaultQueryOptions(e);typeof t.retry>"u"&&(t.retry=!1);const n=c(this,F).build(this,t);return n.isStaleByTime(t.staleTime)?await n.fetch(t):await Promise.resolve(n.state.data)}async prefetchQuery(e){await this.fetchQuery(e).then(r.noop).catch(r.noop)}async resetQueries(e,t){const n=c(this,F),i={type:"active",...e};n.findAll(e).forEach(u=>{u.reset()}),await this.refetchQueries(i,t)}async refetchQueries(e={},t){const n={...t,cancelRefetch:(t==null?void 0:t.cancelRefetch)??!0},i=c(this,F).findAll(e).filter(u=>!u.isDisabled()).map(async u=>{let a=u.fetch(void 0,n);return n.throwOnError||(a=a.catch(r.noop)),u.state.fetchStatus==="paused"?void 0:await a});await Promise.all(i).then(r.noop)}getQueryData(e){var n;const t=this.defaultQueryOptions({queryKey:e});return(n=c(this,F).get(t.queryHash))==null?void 0:n.state.data}setQueryData(e,t,n){const i=this.defaultQueryOptions({queryKey:e}),u=c(this,F).get(i.queryHash),a=u==null?void 0:u.state.data,l=Lt(t,a);if(l!==void 0)return c(this,F).build(this,i).setData(l,{...n,manual:!0})}getMutationDefaults(e){const t=[...c(this,le).values()];let n={};return t.forEach(i=>{ye(e,i.mutationKey)&&(n={...n,...i.defaultOptions})}),n}getQueryState(e){var t;return(t=c(this,F).find({queryKey:e}))==null?void 0:t.state}setMutationDefaults(e,t){c(this,le).set(re(e),{mutationKey:e,defaultOptions:t})}setQueryDefaults(e,t){c(this,he).set(re(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...c(this,he).values()];let n={};return t.forEach(i=>{Ee(e,i.queryKey)&&(n={...n,...i.defaultOptions})}),n}removeQueries(e){const t=c(this,F);t.findAll(e).forEach(n=>{t.remove(n)})}async cancelQueries(e={},t={}){const n={revert:!0,...t},i=c(this,F).findAll(e).map(async u=>{await u.cancel(n)});await Promise.all(i).then(r.noop).catch(r.noop)}async invalidateQueries(e={},t={}){if(c(this,F).findAll(e).forEach(i=>{i.invalidate()}),e.refetchType==="none"){await Promise.resolve();return}const n={...e,type:e.refetchType??e.type??"active"};await this.refetchQueries(n,t)}async resumePausedMutations(){return await r.lastValueFrom(c(this,G).resumePausedMutations())}isFetching(e){return c(this,F).findAll({...e,fetchStatus:"fetching"}).length}clear(){c(this,F).clear(),c(this,G).clear()}}G=new WeakMap,F=new WeakMap,le=new WeakMap,he=new WeakMap,te=new WeakMap;exports.MutationCache=ft;exports.QueryCache=pt;exports.QueryClient=yr;exports.QueryClientProvider=Vt;exports.SIGNAL_RESET=Je;exports.arrayEqual=Ut;exports.createLocalStorageAdapter=Xe;exports.createLocalforageAdapter=Et;exports.exponentialBackoffDelay=et;exports.getDelay=Ze;exports.isDefined=me;exports.retryBackoff=Ue;exports.signal=wt;exports.useBehaviorSubject=xe;exports.useEffectOnce=tt;exports.useForeverQuery=nr;exports.useLiveRef=Q;exports.useMount=At;exports.useMutation=Tt;exports.useObservableState=Ot;exports.useObserve=fe;exports.useObserveCallback=vt;exports.usePersistSignals=Rt;exports.useQuery=sr;exports.useQueryClient=Pe;exports.useSignalValue=$t;exports.useSubject=Re;exports.useSubscribe=Fe;exports.useSubscribeEffect=ir;exports.useUnmountObservable=xt;
1
+ "use strict";var gt=Object.defineProperty;var De=s=>{throw TypeError(s)};var mt=(s,e,t)=>e in s?gt(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var m=(s,e,t)=>mt(s,typeof e!="symbol"?e+"":e,t),Ke=(s,e,t)=>e.has(s)||De("Cannot "+t);var c=(s,e,t)=>(Ke(s,e,"read from private field"),t?t.call(s):e.get(s)),w=(s,e,t)=>e.has(s)?De("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),j=(s,e,t,n)=>(Ke(s,e,"write to private field"),n?n.call(s,t):e.set(s,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react"),r=require("rxjs"),K=require("rxjs/operators"),Ne=require("react/jsx-runtime");function yt(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const we=yt(v),Q=s=>{const e=v.useRef(s);return v.useMemo(()=>{e.current=s},[s]),e};function St(s,e){return typeof s=="string"&&s===e||typeof s=="number"&&s===e||typeof s=="boolean"&&s===e||typeof s=="symbol"&&s===e||typeof s=="bigint"&&s===e||typeof s>"u"&&s===e||s===null&&s===e}function fe(s,e,t){const n=e!=null&&!Array.isArray(e)?e:{defaultValue:void 0,unsubscribeOnUnmount:!0},i=!t&&Array.isArray(e)?e:typeof s=="function"?t??[]:[s],u=v.useRef("getValue"in s&&typeof s.getValue=="function"?s.getValue():n.defaultValue),a=Q(s),l=Q(n),h=v.useCallback(b=>{const $=a.current,p=(typeof $=="function"?$:()=>$)().pipe(r.distinctUntilChanged(St),r.tap(g=>{u.current=g}),r.catchError(g=>(console.error(g),r.EMPTY))).subscribe(b);return()=>{l.current.unsubscribeOnUnmount!==!1&&p.unsubscribe()}},[...i]),f=v.useCallback(()=>u.current,[]);return v.useSyncExternalStore(h,f,f)}function qe(s){return s instanceof Promise||s&&typeof s.then=="function"&&typeof s.catch=="function"}function R(s){if(r.isObservable(s))return s;if(qe(s))return r.from(s);if(typeof s!="function")return r.of(s);const e=s;return r.defer(()=>{const t=e();return qe(t)?r.from(t):r.isObservable(t)?t:r.of(t)})}function Fe(s,e=[]){const t=Q(s);v.useEffect(()=>{const n=R(t.current).pipe(r.catchError(i=>(console.error(i),r.EMPTY))).subscribe();return()=>{n.unsubscribe()}},[...e,t])}const $e=s=>{const e=v.useRef();return e.current||(e.current=s()),v.useEffect(()=>{process.env.NODE_ENV},[]),e},Re=({onBeforeComplete:s,completeOnUnmount:e=!0}={})=>{const t=$e(()=>new r.Subject),n=v.useRef(!1),i=Q(s),u=Q(e);return v.useEffect(()=>(n.current&&(t.current=new r.Subject,n.current=!1),()=>{if(!u.current){n.current=!0;return}n.current||(i.current!=null&&i.current(),t.current.complete(),n.current=!0)}),[u,i,t]),t},vt=()=>{const s=Re(),e=Q(s.current.asObservable()),t=v.useCallback(n=>{s.current.next(n)},[]);return[e.current,t]},xe=s=>{const e=$e(()=>new r.BehaviorSubject(s)),t=v.useRef(!1),n=v.useRef(s);return v.useEffect(()=>(t.current&&(e.current=new r.BehaviorSubject(n.current),t.current=!1),()=>{t.current||(e.current.complete(),t.current=!0)}),[e]),e},Ot=s=>{const e=xe(s),t=Q(e.current.asObservable()),n=v.useCallback(i=>{e.current.next(i)},[e.current]);return[t.current,n,e.current.getValue()]},Je=Symbol("SIGNAL_RESET");function wt(s={}){const e={default:s.default,key:s.key},{default:t}=e??{},n=new r.BehaviorSubject(t),i=a=>{if(typeof a=="function"){const l=a(n.getValue());if(l===n.getValue())return;n.next(l);return}if(a===Je){n.next(t??void 0);return}n.next(a)},u=()=>n.getValue();if("get"in s){const a=h=>(h.subject.pipe(r.skip(1),r.first()).subscribe(()=>{var o;const f=(o=s.get)==null?void 0:o.call(s,a);i(f)}),h.getValue()),l=s.get(a);return i(l),{getValue:u,config:s,subject:n}}return{setValue:i,getValue:u,config:e,subject:n}}function $t(s,e){const n=e??(()=>s.getValue());return fe(()=>s.subject.pipe(r.map(u=>n(u)),r.distinctUntilChanged()),{defaultValue:n(s.getValue())},[])}const Et=s=>({getItem:async e=>{const t=await s.getItem(e);if(t)return JSON.parse(t)},setItem:async(e,t)=>{await s.setItem(e,JSON.stringify(t))},removeItem:async e=>{},clear:async()=>{}}),Ce=s=>{if(!(!s||typeof s!="object"))return s},Ct=({adapter:s,key:e})=>({clear:async()=>await s.removeItem(e),removeItem:async t=>{const n=await s.getItem(e),{[t]:i,...u}=Ce(n)??{};await s.setItem(e,u)},getItem:async t=>{const n=await s.getItem(e),i=Ce(n)??{};if(t in i)return i[t]},setItem:async(t,n)=>{const i=await s.getItem(e),u=Ce(i)??{};await s.setItem(e,{...u,[t]:n})}}),Xe=({key:s}={})=>s?Ct({adapter:Xe(),key:s}):{clear:async()=>{localStorage.clear()},removeItem:async e=>{localStorage.removeItem(e)},getItem:async e=>{const t=localStorage.getItem(e);if(t)return JSON.parse(t)},setItem:async(e,t)=>{localStorage.setItem(e,JSON.stringify(t))}},se="__reactjrx",Mt=s=>{if(typeof s=="object"&&s!==null&&se in s&&s[se]===se)return s};function me(s){return s!=null}const He=s=>{const e=xe(s);return v.useEffect(()=>{e.current.next(s)},[s,e]),e},jt=({adapter:s,config:e})=>{const{signal:t,version:n}=e,u={value:t.getValue(),[se]:se,migrationVersion:n};return r.from(s.setItem(t.config.key,u)).pipe(r.catchError(a=>(console.error(a),r.of(null))))};function Ft({adapter:s,config:e}){const{hydrate:t=({value:u})=>u,signal:n,version:i}=e;return r.from(s.getItem(n.config.key)).pipe(r.switchMap(u=>{const a=Mt(u);if(!a||a.migrationVersion!==void 0&&i>a.migrationVersion||a.value===void 0)return r.of(u);const l=a.value;return n.setValue(t({value:l,version:i})),r.of(u)}))}function Rt({entries:s=[],onReady:e,adapter:t}){const n=Q(s),i=Q(e),u=He(t),a=fe(()=>{const h=n.current;return u.current.pipe(r.switchMap(f=>(h.length===0||!f?r.of(!0):r.zip(...h.map(b=>Ft({adapter:f,config:b}))).pipe(r.map(()=>!0))).pipe(r.tap(()=>{i.current!=null&&i.current()}),r.catchError(b=>(console.error("Unable to hydrate",b),r.EMPTY)))))},{defaultValue:!1},[u,n]),l=He(a);return Fe(()=>l.current.pipe(r.filter(h=>h),r.switchMap(()=>u.current),r.filter(me),r.switchMap(h=>r.merge(...n.current.map(f=>f.signal.subject.pipe(r.throttleTime(500,r.asyncScheduler,{trailing:!0}),r.switchMap(()=>r.from(jt({adapter:h,config:f})))))))),[l,u]),{isHydrated:a}}const xt=()=>{const s=Re({onBeforeComplete:()=>{s.current.next()}});return s};function Ze(s,e){return Math.min(s,e)}function et(s,e){return Math.pow(2,s)*e}function Ue(s){const{retry:e,retryDelay:t,retryAfterDelay:n,retryAfter:i=()=>r.of(!0)}=s,u=typeof e!="function"?e===!1?0:e===!0?1/0:e??1/0:1/0,a=typeof e=="function"?e:()=>!0,l=typeof t=="number"?t:100,h={shouldRetry:a,...s},{maxInterval:f=1/0,resetOnSuccess:o=!1,backoffDelay:b=et}=h;return $=>r.defer(()=>{let d=0;const p=(g,C)=>g<u?a(g,C):!1;return $.pipe(K.catchError(g=>{var E;if(d++,!p(d-1,g))throw g;const C=(E=s.caughtError)==null?void 0:E.call(s,d,g);if(!C)throw g;return C.pipe(K.mergeMap(O=>r.merge(r.of(O),r.throwError(()=>g))))}),K.retryWhen(g=>g.pipe(K.concatMap(C=>{const E=d-1;return i().pipe(K.first(),K.mergeMap(()=>p(E,C)?r.timer(Ze(b(E,l),f)).pipe(K.mergeMap(O=>n&&!n(E,C)?r.throwError(()=>C):r.of(O))):r.throwError(()=>C)))}))),K.catchError(g=>{if(s.catchError)return s.catchError(d,g);throw g}),K.tap(()=>{o&&(d=0)}))})}const Ut=(s,e)=>s.length===e.length&&s.every((t,n)=>t===e[n]),tt=s=>{v.useEffect(s,[])},At=s=>{tt(()=>{s()})};function We(s){return Object.prototype.toString.call(s)==="[object Object]"}function Me(s){if(!We(s))return!1;const e=s.constructor;if(typeof e>"u")return!0;const t=e.prototype;return!(!We(t)||!t.hasOwnProperty("isPrototypeOf"))}const re=s=>JSON.stringify(s,(e,t)=>Me(t)?Object.keys(t).sort().reduce((n,i)=>(n[i]=t[i],n),{}):t),Ae=(s=21)=>crypto.getRandomValues(new Uint8Array(s)).reduce((e,t)=>(t&=63,t<36?e+=t.toString(36):t<62?e+=(t-26).toString(36).toUpperCase():t>62?e+="-":e+="_",e),""),J=()=>({context:void 0,data:void 0,error:null,status:"idle",submittedAt:0,variables:void 0,failureCount:0,failureReason:null,isPaused:!1});function Qe(s){let e=0;return function(n){return new r.Observable(i=>{e++;const u=n.subscribe(i);return s(e),()=>{e--,s(e),u.unsubscribe()}})}}const ne=s=>s.pipe(r.takeWhile(e=>e.status!=="error"&&e.status!=="success",!0));var H;class Qt{constructor({__queryFinalizeHook:e}={}){w(this,H,new r.Subject);m(this,"state$");const t=new r.BehaviorSubject(0),n=t.pipe(r.filter(i=>i===0));this.state$=c(this,H).pipe(r.concatMap(({args:i,mutation:u,options:a})=>{const l=a.mapOperator??"merge",h=c(this,H).pipe(r.filter(()=>l==="merge")),f=c(this,H).pipe(r.filter(()=>l==="switch"),r.tap(()=>{u.cancel()})),o=r.defer(()=>(u.execute(i),r.EMPTY)),b=u.state$.pipe(ne,r.last(),r.mergeMap(()=>u.state$),r.takeUntil(c(this,H))),$=u.state$.pipe(ne,r.skip(1)),d=r.merge(n,h,f,u.cancelled$);return r.merge($,b,o).pipe(r.map(p=>({state:p,mutation:u})),e??r.identity,r.takeUntil(d))}),r.shareReplay({refCount:!0,bufferSize:1}),Qe(i=>{t.next(i)}))}trigger({args:e,options:t,mutation:n}){c(this,H).next({args:e,options:t,mutation:n})}}H=new WeakMap;function Ee(s,e){return s===e?!0:typeof s!=typeof e?!1:s&&e&&typeof s=="object"&&typeof e=="object"?!Object.keys(e).some(t=>!Ee(s[t],e[t])):!1}const ye=(s,e,{exact:t=!1}={})=>t?re(s)===re(e):Ee(s,e);function x(s,e){if(s==null||e===void 0||typeof s!="object"||typeof e!="object")return s===e;if(s.constructor!==(e==null?void 0:e.constructor))return!1;const t=Object.keys(s),n=Object.keys(e);if(t.length!==n.length)return!1;for(const i of t)if(!e.hasOwnProperty(i)||s[i]!==e[i])return!1;return!0}const rt=s=>s.pipe(r.distinctUntilChanged(({data:e,...t},{data:n,...i})=>x(t,i)&&x(e,n)));var z,I;class Pt{constructor(e,t={},n){w(this,z);w(this,I,new r.BehaviorSubject(void 0));m(this,"observed$");m(this,"getObserverResultFromState",e=>({...J(),...e,isSuccess:e.status==="success",isPending:e.status==="pending",isIdle:e.status==="idle",isError:e.status==="error",mutate:this.mutate,reset:this.reset}));var i;this.client=e,this.options=t,this.options.mutationKey=((i=this.options)==null?void 0:i.mutationKey)??[Ae()],j(this,z,n??new Qt(this.options)),this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this),c(this,I).pipe(r.filter(me),r.mergeMap(u=>c(this,z).state$.pipe(r.takeUntil(u.mutation.state$.pipe(ne,r.last()))))).subscribe(),this.observed$=c(this,I).pipe(r.switchMap(u=>(u==null?void 0:u.mutation.state$.pipe(r.map(a=>({state:a,options:u.options}))))??r.EMPTY),r.tap(({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)))}),r.ignoreElements())}setOptions(e){var i;const t=this.options;this.options=this.client.defaultMutationOptions({mutationKey:this.options.mutationKey,...e});const n=(i=c(this,I).getValue())==null?void 0:i.mutation;this.options.mutationKey&&t.mutationKey&&!ye(this.options.mutationKey,t.mutationKey,{exact:!0})?this.reset():n==null||n.setOptions(this.options)}observe(){var u;const e=this.getObserverResultFromState(((u=c(this,I).getValue())==null?void 0:u.mutation.state)??J()),t=c(this,z).state$.pipe(r.distinctUntilChanged(({mutation:a,state:{data:l,...h}},{mutation:f,state:{data:o,...b}})=>a===f&&x(h,b)&&x(l,o)),r.map(({state:a})=>a),r.scan((a,l)=>({...a,...l,...l.status==="pending"&&{data:l.data??a.data},...l.status==="pending"&&{error:l.error??a.error}})),r.map(a=>this.getObserverResultFromState(a))),n=c(this,I).pipe(r.filter(me),r.switchMap(a=>a.mutation.cancelled$),r.map(()=>this.getObserverResultFromState(J())));return{result$:r.merge(this.observed$,t,n).pipe(rt),lastValue:e}}subscribe(e){const t=this.observe().result$.subscribe(n=>{e(n)});return()=>{t.unsubscribe()}}async mutate(e,t={}){const n=this.client.getMutationCache().build(this.client,this.options);return c(this,I).next({mutation:n,options:t}),c(this,z).trigger({args:e,options:this.options,mutation:n}),await new Promise((i,u)=>{n.state$.pipe(ne,r.last()).subscribe({error:a=>{u(a)},next:a=>{a.error?u(a.error):i(a.data)}})})}getCurrentResult(){var t;const e=this.client.getMutationCache().find({exact:!0,mutationKey:(t=this.options)==null?void 0:t.mutationKey});return this.getObserverResultFromState((e==null?void 0:e.state)??J())}reset(){const{mutation:e}=c(this,I).getValue()??{};c(this,I).next(void 0),e==null||e.cancel()}}z=new WeakMap,I=new WeakMap;const st=v.createContext(void 0),kt=({client:s})=>(v.useEffect(()=>(s.mount(),()=>{s.unmount()}),[s]),null),Vt=v.memo(({children:s,client:e})=>{const t=v.useMemo(()=>e,[e]);return Ne.jsxs(st.Provider,{value:t,children:[Ne.jsx(kt,{client:e}),s]})}),Pe=s=>{const e=v.useContext(st);if(s)return s;if(!e)throw new Error("No QueryClient set, use QueryClientProvider to set one");return e};function It(){}function Tt(s,e){const t=Pe(e),n=Q(s),i=$e(()=>[Ae()]),u=re(s.mutationKey??i.current),[a]=v.useState(()=>new Pt(t,s));v.useEffect(()=>{a.setOptions(s)},[a,s]);const l=v.useMemo(()=>a.observe(),[u,a]),h=fe(l.result$)??l.lastValue,f=v.useCallback((o,b)=>{a.mutate(o,b).catch(It)},[a]);return v.useEffect(()=>()=>{n.current.cancelOnUnMount&&a.reset()},[a,n]),{...h,mutate:f,mutateAsync:h.mutate}}function Dt(s){return e=>e.pipe(K.tap(t=>{s.next(t)}))}const X=typeof window>"u"||"Deno"in window;class Kt{constructor(){m(this,"isOnlineSubject",new r.BehaviorSubject(!0));m(this,"online$",this.isOnlineSubject.pipe(r.distinctUntilChanged()));m(this,"backToOnline$",this.online$.pipe(r.filter(e=>e),r.first()));r.merge(X?r.EMPTY:r.fromEvent(window,"offline").pipe(r.map(()=>!1)),X?r.EMPTY:r.fromEvent(window,"online").pipe(r.map(()=>!0))).pipe(Dt(this.isOnlineSubject)).subscribe()}isOnline(){return this.isOnlineSubject.getValue()}setOnline(e){this.isOnlineSubject.getValue()!==e&&this.isOnlineSubject.next(e)}}const _=new Kt;function ke(s,e){return s.isStaleByTime(e.staleTime)}function Nt(s,e){return e.enabled!==!1&&!s.state.dataUpdatedAt&&!(s.state.status==="error"&&e.retryOnMount===!1)&&s.state.fetchStatus!=="fetching"}function Le(s,e){return Nt(s,e)||s.state.dataUpdatedAt>0&&nt(s,e,e.refetchOnMount)}function _e(s,e,t,n){return s.state.fetchStatus!=="fetching"&&t.enabled!==!1&&(s!==e||n.enabled===!1)&&(!t.suspense||s.state.status!=="error")&&ke(s,t)}function qt(s,e){return nt(s,e,e.refetchOnWindowFocus)}function nt(s,e,t){if(e.enabled!==!1){const n=typeof t=="function"?t(s):t;return n==="idle"?s.state.fetchStatus==="idle":n==="always"||n!==!1&&ke(s,e)}return!1}function Ht(s){return(s??"online")==="online"?_.isOnline():!0}function ze(s,e){return e.reduce((t,n)=>n in s?{...t,[n]:s[n]}:t,{})}function Be(s){return Array.isArray(s)&&s.length===Object.keys(s).length}function it(s,e){if(s===e)return s;const t=Be(s)&&Be(e);if(t||Me(s)&&Me(e)){const n=t?s:Object.keys(s),i=n.length,u=t?e:Object.keys(e),a=u.length,l=t?[]:{};let h=0;for(let f=0;f<a;f++){const o=t?f:u[f];!t&&s[o]===void 0&&e[o]===void 0&&n.includes(o)?(l[o]=void 0,h++):(l[o]=it(s[o],e[o]),l[o]===s[o]&&s[o]!==void 0&&h++)}return i===a&&h===i?s:l}return e}function Ve(s,e){return((e==null?void 0:e.queryKeyHashFn)??re)(s)}function Ye(s,e){const{type:t="all",exact:n,fetchStatus:i,predicate:u,queryKey:a,stale:l}=s;if(a){if(n){if(e.queryHash!==Ve(a,e.options))return!1}else if(!Ee(e.queryKey,a))return!1}if(t!=="all"){const h=e.isActive();if(t==="active"&&!h||t==="inactive"&&h)return!1}return!(typeof l=="boolean"&&e.isStale()!==l||typeof i<"u"&&i!==e.state.fetchStatus||u&&!u(e))}function Wt(s,e){return Math.max(s+(e??0)-Date.now(),0)}function Lt(s,e){return typeof s=="function"?s(e):s}function Se(s,e,t){return typeof t.structuralSharing=="function"?t.structuralSharing(s,e):t.structuralSharing!==!1?it(s,e):e}const je=Symbol(),_t=({getOptions:s,getState:e,initialState:t})=>n=>n.pipe(r.scan((i,{command:u,state:a})=>{if(u==="reset")return{...i,...a};if(u==="cancel"){const S=i.status==="pending"?"pending":a.status??i.status;return{...i,...a,status:S}}const l=a.data,h=l!==void 0&&l!==i.data,f="data"in a,o=a.status==="success",b=i.data!==void 0,$=i.error!==void 0||i.error!==null,d=a.status??i.status,p=h?Se(e().data,l,s()):f?a.data:i.data,g=i.status==="error"||i.status==="success",C=a.status==="error"&&(i.status==="error"&&i.fetchStatus==="fetching"||i.status!=="error")?i.errorUpdateCount+1:i.errorUpdateCount,E=h?i.dataUpdateCount+1:a.dataUpdateCount??i.dataUpdateCount,O=a.status==="pending"&&g&&(b||$),U=d==="pending"?null:a.error??i.error;return{...i,...a,status:d,error:U,errorUpdateCount:C,...o&&{isInvalidated:!1},data:p,dataUpdateCount:E,...O&&{status:i.status}}},t)),zt=s=>s.pipe(r.map(({status:e,fetchStatus:t})=>t==="idle"&&(e==="success"||e==="error"))),at=s=>s.pipe(r.takeWhile(e=>e.fetchStatus!=="idle",!0));var Oe,W;class Bt{constructor(){w(this,Oe,r.merge(X?r.EMPTY:r.fromEvent(document,"visibilitychange"),X?r.EMPTY:r.fromEvent(window,"visibilitychange")).pipe(r.map(()=>document.visibilityState)));w(this,W,new r.BehaviorSubject(X?!0:document.visibilityState==="visible"));m(this,"focused$",c(this,W));m(this,"focusRegained$",this.focused$.pipe(r.skip(1),r.filter(e=>e)));c(this,Oe).pipe(r.tap(e=>{c(this,W).next(e==="visible")})).subscribe()}isFocused(){return c(this,W).getValue()}setFocused(e){c(this,W).getValue()!==(e??!0)&&c(this,W).next(e??!0)}subscribe(e){const t=this.focused$.subscribe(e);return()=>{t.unsubscribe()}}refresh(){document.dispatchEvent(new Event("visibilitychange"))}}Oe=new WeakMap,W=new WeakMap;const ve=new Bt,Yt=s=>s.pipe(r.filter(e=>e.status==="success"),r.map(e=>({data:e.data,status:e.status,dataUpdatedAt:e.dataUpdatedAt})),r.distinctUntilChanged(x));var q,M,ie,B,A,Z,ae;class ut{constructor(e,t){w(this,q);w(this,M);w(this,ie,new r.Subject);m(this,"queryUpdateSubject",new r.Subject);w(this,B);w(this,A);w(this,Z);w(this,ae,0);m(this,"getObserverResultFromQuery",({options:e,query:t,optimisticResult:n,prevResult:{result:i,options:u,state:a,select:l,selectError:h,selectResult:f}})=>{var ge;const o=t.state,b=t.state.status==="pending",$=c(this,M),d=this.options,g=t!==$?t.state:c(this,B);let{errorUpdatedAt:C,fetchStatus:E,error:O}=o;if(n){const P=!!c(this,ae),Te=!P&&Le(t,e),bt=P&&_e(t,$,e,d);(Te||bt)&&(E=Ht(t.options.networkMode)?"fetching":"paused")}const U=b&&E==="fetching";let S,y=h,T=l??null,D=f;if(e.select&&typeof o.data<"u")if(i&&o.data===(a==null?void 0:a.data)&&e.select===l)S=f;else try{T=e.select,S=e.select(o.data),S=Se(i==null?void 0:i.data,S,e),D=S,y=null}catch(P){S=f,y=P}else S=o.data,y=null;let V=E!=="idle"&&!o.dataUpdatedAt?"pending":o.status;y&&(O=y,S=f,C=(i==null?void 0:i.errorUpdatedAt)??C,V="error");const de=V==="error";let pe=!1;if(typeof e.placeholderData<"u"&&typeof S>"u"&&V==="pending"){let P;if(i!=null&&i.isPlaceholderData&&e.placeholderData===(u==null?void 0:u.placeholderData))P=i.data;else if(P=typeof e.placeholderData=="function"?e.placeholderData((ge=c(this,Z))==null?void 0:ge.state.data,c(this,Z)):e.placeholderData,e.select&&typeof P<"u")try{P=e.select(P)}catch{}typeof P<"u"&&(V="success",S=Se(i==null?void 0:i.data,P,e),pe=!0)}const be=E==="fetching";return{result:{status:V,fetchStatus:E,isPending:b,isSuccess:V==="success",isError:de,isInitialLoading:U,isLoading:U,data:S,dataUpdatedAt:o.dataUpdatedAt,error:O,errorUpdatedAt:C,failureCount:o.fetchFailureCount,failureReason:o.fetchFailureReason,errorUpdateCount:o.errorUpdateCount,isFetched:o.dataUpdateCount>0||o.errorUpdateCount>0,isFetchedAfterMount:o.dataUpdateCount>g.dataUpdateCount||o.errorUpdateCount>g.errorUpdateCount,isFetching:be,isRefetching:be&&!b,isLoadingError:de&&o.dataUpdatedAt===0,isPaused:E==="paused",isPlaceholderData:pe,isRefetchError:de&&o.dataUpdatedAt!==0,isStale:ke(t,e),refetch:this.refetch},selectError:y,select:T,selectResult:D}});this.options=t,j(this,q,e),this.bindMethods(),j(this,M,this.setOptions(t));const n=c(this,M);j(this,B,n.state);const{result:i,select:u}=this.getObserverResultFromQuery({query:n,options:this.options,prevResult:{options:this.options,state:n.state}});j(this,A,{state:n.state,options:t,result:i,select:u})}bindMethods(){this.refetch=this.refetch.bind(this)}setOptions(e){const t=this.options;if(this.options=c(this,q).defaultQueryOptions(e),x(this.options,t)||c(this,q).getQueryCache().notify({type:"observerOptionsUpdated",query:c(this,M),observer:this}),typeof this.options.enabled<"u"&&typeof this.options.enabled!="boolean")throw new Error("Expected enabled to be a boolean");const n=this.buildQuery(this.options);return n!==c(this,M)&&(j(this,B,n.state),j(this,M,n)),this.queryUpdateSubject.next({options:this.options,query:n}),n}buildQuery(e){const t=c(this,q).getQueryCache().build(c(this,q),e);return!t.options.queryFn&&this.options.queryFn&&t.setOptions(e),t}getCurrentResult(){return this.getObserverResultFromQuery({options:this.options,prevResult:c(this,A),query:c(this,M)}).result}getCurrentQuery(){return c(this,M)}getOptimisticResult(e){const t=this.buildQuery(e),n=this.getObserverResultFromQuery({query:t,options:e,optimisticResult:!0,prevResult:c(this,A)});return Gt(this,n.result)&&this.updateResult({query:t,...n}),n.result}updateResult({query:e,result:t,selectError:n,select:i,selectResult:u}){c(this,A).state=e.state,c(this,A).result=t,c(this,A).selectResult=u,n!==void 0&&(c(this,A).selectError=n),i!==void 0&&(c(this,A).select=i),c(this,A).options=this.options,e.state.data!==void 0&&j(this,Z,e),c(this,q).getQueryCache().notify({query:c(this,M),type:"observerResultsUpdated"})}async refetch({...e}={}){return await this.fetch({...e})}async fetch(e){const t=this.buildQuery(this.options);t!==c(this,M)&&(j(this,M,t),j(this,B,t.state),this.queryUpdateSubject.next({options:this.options,query:t}));const n={...e,cancelRefetch:(e==null?void 0:e.cancelRefetch)??!0};c(this,M).fetch(this.options,n).catch(r.noop),c(this,ie).next({query:t,fetchOptions:n}),await t.getFetchResultAsPromise();const{result:i}=this.getObserverResultFromQuery({query:t,options:this.options,prevResult:c(this,A)});return i}subscribe(e){const t=this.observe().subscribe(e);return()=>{t.unsubscribe()}}observe(){const e=c(this,M),t=this.queryUpdateSubject.pipe(r.map(({query:a})=>a),r.startWith(c(this,M)),r.distinctUntilChanged()),n=this.queryUpdateSubject.pipe(r.startWith({query:c(this,M),options:this.options}),r.pairwise(),r.tap(([{options:a,query:l},{options:h,query:f}])=>{_e(f,l,h,a)&&this.fetch().catch(r.noop)}),r.ignoreElements()),i=t.pipe(r.switchMap(a=>a.observe(this)),r.ignoreElements());return r.merge(i,n,t.pipe(r.switchMap(a=>{const l=this.options,h=this.queryUpdateSubject.pipe(r.startWith({query:a,options:l}),r.filter(y=>y.query===a),r.map(y=>y.options),r.distinctUntilChanged(),r.shareReplay(1)),f=c(this,ie).pipe(r.filter(y=>y.query===a)),o=a.state$.pipe(Yt,r.switchMap(y=>this.options.staleTime===1/0?r.NEVER:(this.options.staleTime??0)<=0?r.of(y).pipe(r.delay(1)):r.timer(this.options.staleTime??1)),r.takeWhile(()=>this.options.enabled??!0)),b=(y,T)=>{const D=l.notifyOnChangeProps,V=typeof D=="function"?D():D;return(Array.isArray(V)?V.length===0?()=>!0:(pe,be)=>{const Ie=ze(pe,V),ge=ze(be,V);return x(Ie,ge)}:x)(y,T)},$=f.pipe(r.switchMap(()=>a.state$),at),d=h.pipe(r.map(({refetchInterval:y,refetchIntervalInBackground:T})=>({refetchInterval:(typeof y=="function"?y(c(this,M)):y)??!1,refetchIntervalInBackground:T})),r.distinctUntilChanged(x),r.switchMap(({refetchInterval:y,refetchIntervalInBackground:T})=>y?r.interval(y).pipe(r.tap(()=>{(T||ve.isFocused())&&this.fetch({cancelRefetch:!1}).catch(r.noop)})):r.NEVER),r.ignoreElements()),p=h.pipe(r.map(({enabled:y})=>y??!0),r.distinctUntilChanged()),g=p.pipe(r.filter(y=>!y),r.map(()=>a.state)),C=p.pipe(r.filter(y=>y),r.switchMap(()=>ve.focusRegained$),r.withLatestFrom(h),r.tap(([,y])=>{qt(a,y)&&this.fetch({cancelRefetch:!1}).catch(r.noop)}),r.ignoreElements()),E=g.pipe(r.map(()=>a.state)),O=y=>y.pipe(r.withLatestFrom(h),r.map(([,T])=>{const D=this.getObserverResultFromQuery({query:a,options:T,prevResult:c(this,A)});return this.updateResult({query:a,...D}),D.result})),S=r.merge(E,$,a.state$,o).pipe(O,r.distinctUntilChanged(x),r.distinctUntilChanged(b));return r.merge(d,C,S)})).pipe(Qe(a=>j(this,ae,a)),r.tap({subscribe:()=>{Le(e,this.options)&&this.fetch().catch(r.noop)}})))}destroy(){}}q=new WeakMap,M=new WeakMap,ie=new WeakMap,B=new WeakMap,A=new WeakMap,Z=new WeakMap,ae=new WeakMap;function Gt(s,e){return!x(s.getCurrentResult(),e)}const ct=we.createContext(!1),Jt=()=>we.useContext(ct);ct.Provider;function Xt(){let s=!1;return{clearReset:()=>{s=!1},reset:()=>{s=!0},isReset:()=>s}}const Zt=we.createContext(Xt()),er=()=>we.useContext(Zt);function tr(s,e){return typeof s=="function"?s(...e):!!s}const rr=({result:s,errorResetBoundary:e,throwOnError:t,query:n})=>s.isError&&!e.isReset()&&!s.isFetching&&n&&tr(t,[s.error,n]);function ot(s,e,t){if(process.env.NODE_ENV!=="production"&&(typeof s!="object"||Array.isArray(s)))throw new Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');const n=Pe(t),i=Jt(),u=er(),a=n.defaultQueryOptions(s);a._optimisticResults=i?"isRestoring":"optimistic";const[l]=v.useState(()=>new e(n,a)),h=$e(()=>l.observe()),f=Q(l.getOptimisticResult(a)),o=f.current;fe(()=>h.current.pipe(r.filter($=>!x($,f.current))),[]),v.useEffect(()=>{l.setOptions(a)},[a,l]);const b=o.error;if(b&&rr({result:o,errorResetBoundary:u,throwOnError:a.throwOnError,query:n.getQueryCache().get(a.queryHash)}))throw b;return f.current}function sr(s,e){return ot(s,ut,e)}function nr(s,e){return ot({refetchOnMount:"idle",refetchOnReconnect:!1,refetchInterval:!1,refetchOnWindowFocus:!1,...s},ut,e)}function ir(s,e,t=[]){const n=e!=null&&!Array.isArray(e)?e:{},i=n.retry??!0,u=Q(n.onError??(h=>{console.error(h)})),a=v.useCallback(()=>R(s),t),l=v.useCallback(()=>a().pipe(r.catchError(h=>{throw u.current(h),h}),i?r.retry():r.identity),[a,i,u]);Fe(l,t)}const lt=()=>s=>r.merge(r.of({isPaused:!0}),_.backToOnline$.pipe(r.mergeMap(()=>r.merge(r.of({isPaused:!1}),s)))),ar=s=>{let e=0;return s.pipe(r.catchError(t=>(e++,e<=1&&!_.isOnline()?r.merge(r.of({failureCount:e,failureReason:t}),r.timer(1).pipe(r.mergeMap(()=>r.throwError(()=>t).pipe(lt())))):r.throwError(()=>t))))},ur=({variables:s,state:e,options:t})=>{const n=e.isPaused,i=async()=>await Promise.reject(new Error("No mutationFn found")),u=t.mutationFn??i,a=R(()=>{var d;return((d=t.onMutate)==null?void 0:d.call(t,s))??void 0}),l=r.of(e.context),h=r.iif(()=>n,l,a).pipe(r.shareReplay(1)),f=(d,p,g)=>R(()=>{var E;return(E=t.onError)==null?void 0:E.call(t,d,s,p)}).pipe(r.catchError(()=>r.of(d)),r.map(()=>({failureCount:g,error:d,failureReason:d,context:p,status:"error"}))),o=h.pipe(r.switchMap(d=>{const g=(typeof u=="function"?R(()=>u(s)):u).pipe(r.share()),C=g.pipe(r.isEmpty(),r.tap(O=>{if(O)throw new Error("Mutation completed without any emission (EMPTY)")}),r.ignoreElements()),E=r.merge(g,C).pipe(r.map(O=>({result:{data:O},error:null,context:d})),ar,Ue({...t,retry:(O,U)=>{const S=t.retry??0;return typeof S=="function"?S(O,U):typeof S=="boolean"?S:O<S},caughtError:(O,U)=>r.of({failureCount:O,failureReason:U}),catchError:(O,U)=>f(U,d,O).pipe(r.map(S=>({...S,result:void 0})))}),r.takeWhile(({result:O,error:U})=>(O==null?void 0:O.data)===void 0&&U===void 0,!0));return _.isOnline()||t.networkMode==="offlineFirst"||t.networkMode==="always"?E:E.pipe(lt())})),b=r.of({...e,variables:s,status:"pending",isPaused:!1,failureCount:0,failureReason:null,submittedAt:e.submittedAt??new Date().getTime()});return r.merge(b,h.pipe(r.map(d=>({context:d}))),o.pipe(r.switchMap(({result:d,error:p,...g})=>{if(!d&&!p)return r.of({...g});const C=p?r.of(null):R(()=>{var S;return(S=t.onSuccess)==null?void 0:S.call(t,d==null?void 0:d.data,s,g.context)}),O=R(()=>{var S;return(S=t.onSettled)==null?void 0:S.call(t,d==null?void 0:d.data,p,s,g.context)}).pipe(r.catchError(S=>d?r.of(d):r.of(S)));return r.concat(C,O).pipe(r.toArray(),r.map(()=>p?{error:p,data:void 0,variables:s,...g}:{status:"success",error:p,data:d==null?void 0:d.data,variables:s,failureCount:0,failureReason:null,...g}),r.catchError(S=>f(S,g.context,0).pipe(r.map(y=>({...y,data:void 0})))))}))).pipe(r.scan((d,p)=>({...d,...p,data:p.data??d.data,error:p.error??d.error}),J()))};var ue,L,ee;class cr{constructor({options:e,mutationCache:t,state:n}){w(this,ue,new r.BehaviorSubject(0));w(this,L,new r.Subject);w(this,ee,new r.Subject);m(this,"state",J());m(this,"state$");m(this,"options");m(this,"observerCount$",c(this,ue).asObservable());m(this,"cancelled$",c(this,L).asObservable());this.options=e,this.state=n??this.state;const i=c(this,L).pipe(r.filter(()=>this.state.status==="pending"),r.map(()=>({status:"idle"}))),u=c(this,ee).pipe(r.switchMap(l=>ur({options:{...this.options,onMutate:h=>{const f=R(()=>{var d,p;return(p=(d=t.config).onMutate)==null?void 0:p.call(d,h,this)}),b=R(()=>{var d,p;return(p=(d=this.options).onMutate)==null?void 0:p.call(d,h)});return f.pipe(r.mergeMap(()=>b))},onError:(h,f,o)=>{const b=R(()=>{var d,p;return(p=(d=t.config).onError)==null?void 0:p.call(d,h,f,o,this)}),$=R(()=>{var d,p;return(p=(d=this.options).onError)==null?void 0:p.call(d,h,f,o)});return r.concat(b,$).pipe(r.toArray())},onSettled:(h,f,o,b)=>{const $=R(()=>{var p,g;return(g=(p=t.config).onSettled)==null?void 0:g.call(p,h,f,o,b,this)}),d=R(()=>{var p,g;return(g=(p=this.options).onSettled)==null?void 0:g.call(p,h,f,o,b)});return r.concat($,d).pipe(r.toArray())},onSuccess:(h,f,o)=>{const b=R(()=>{var d,p;return(p=(d=t.config).onSuccess)==null?void 0:p.call(d,h,f,o,this)}),$=R(()=>{var d,p;return(p=(d=this.options).onSuccess)==null?void 0:p.call(d,h,f,o)});return r.concat(b,$).pipe(r.toArray())}},state:this.state,variables:l}).pipe(r.takeUntil(c(this,L))))),a=r.merge(i,u);this.state$=a.pipe(r.startWith(this.state),r.scan((l,h)=>({...l,...h}),this.state),rt,r.tap(l=>{this.state=l}),r.shareReplay(1),Qe(l=>{c(this,ue).next(l)}))}get meta(){return this.options.meta}setOptions(e){this.options={...this.options,...e}}execute(e){return c(this,ee).next(e),c(this,ee).complete(),this.state$.pipe(ne)}continue(){return this.execute(this.state.variables)}cancel(){c(this,L).next(),c(this,L).complete()}}ue=new WeakMap,L=new WeakMap,ee=new WeakMap;const Ge=({mutationKey:s,status:e,predicate:t,exact:n=!0}={})=>u=>n&&s!==void 0&&u.options.mutationKey!==void 0&&!ye(u.options.mutationKey,s,{exact:n})||!n&&s!==void 0&&u.options.mutationKey!==void 0&&!ye(u.options.mutationKey,s,{exact:n})||e&&u.state.status!==e?!1:t?t(u):!0;class ht{constructor(){m(this,"entriesSubject",new r.BehaviorSubject([]));m(this,"changeSubject",new r.Subject);m(this,"entries$",this.entriesSubject.pipe(r.share()));m(this,"added$",this.changeSubject.pipe(r.filter(({type:e})=>e==="added"),r.map(({entity:e})=>e),r.share()));m(this,"removed$",this.changeSubject.pipe(r.filter(({type:e})=>e==="removed"),r.map(({entity:e})=>e),r.share()));m(this,"stateChange$",r.merge(this.entriesSubject.pipe(r.first(),r.mergeMap(e=>r.from(e))),this.added$).pipe(r.mergeMap(e=>e.state$.pipe(r.map(()=>e),r.takeUntil(this.removed$.pipe(r.filter(t=>t===e))))),r.share()))}getValues(){return this.entriesSubject.getValue()}remove(e){this.entriesSubject.next(this.entriesSubject.getValue().filter(t=>e!==t)),this.changeSubject.next({type:"removed",entity:e})}add(e){this.entriesSubject.next([...this.entriesSubject.getValue(),e]),this.changeSubject.next({type:"added",entity:e})}find(e){return this.entriesSubject.getValue().find(e)}}var k;class ft{constructor(e={}){w(this,k,new ht);this.config=e}build(e,t,n){const i=new cr({mutationCache:this,options:e.defaultMutationOptions(t),state:n});return i.state$.pipe(r.filter(({status:u})=>u==="success"||u==="error"),r.switchMap(()=>i.observerCount$.pipe(r.filter(u=>u<=1),r.take(1))),r.switchMap(()=>r.timer(i.options.gcTime??5*60*1e3)),r.take(1)).subscribe({complete:()=>{this.remove(i)}}),c(this,k).add(i),i}getAll(){return this.findAll()}remove(e){const t=c(this,k).getValues().find(n=>n===e);t==null||t.cancel(),c(this,k).remove(e)}find(e){const t={exact:!0,...e},n=Ge(t);return c(this,k).getValues().find(i=>n(i))}findAll(e={}){const t={exact:!0,...e},n=Ge(t);return c(this,k).getValues().filter(i=>n(i)).map(i=>i)}observe(){return c(this,k).stateChange$.pipe(r.startWith())}subscribe(e){const t=r.merge(c(this,k).added$.pipe(r.tap(n=>{e({type:"added",mutation:n})})),c(this,k).removed$.pipe(r.tap(n=>{e({type:"removed",mutation:n})})),c(this,k).stateChange$.pipe(r.tap(n=>{e({type:"updated",action:{...n.state,type:"success"},mutation:n})}))).subscribe();return()=>{t.unsubscribe()}}resumePausedMutations(){const e=this.findAll({predicate:n=>n.state.isPaused});if(!e.length)return r.EMPTY;const t=e.map(n=>n.continue());return r.combineLatest(t)}clear(){this.getAll().forEach(e=>{this.remove(e)})}}k=new WeakMap;function or(s){const e=typeof s.initialData=="function"?s.initialData():s.initialData,t=typeof e<"u",n=t?typeof s.initialDataUpdatedAt=="function"?s.initialDataUpdatedAt():s.initialDataUpdatedAt:0;return{data:e,dataUpdateCount:0,dataUpdatedAt:t?n??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:t?"success":"pending",fetchStatus:"idle"}}const lr=s=>r.defer(()=>ve.isFocused()?s:ve.focusRegained$.pipe(r.mergeMap(()=>s))),hr=s=>{let e=0;return t=>{const n=_.backToOnline$.pipe(r.mergeMap(()=>r.merge(r.of({fetchStatus:"fetching"}),t)));return r.defer(()=>(e++,!_.isOnline()&&s.networkMode==="offlineFirst"&&e>1?r.merge(r.of({fetchStatus:"paused"}),n):!_.isOnline()&&s.networkMode!=="always"&&s.networkMode!=="offlineFirst"?r.merge(r.of({fetchStatus:"paused"}),n):t))}},fr=s=>e=>{const t=new r.Subject,n=t.pipe(r.first(),r.delay(1),r.mergeMap(()=>s.pipe(r.filter(i=>i===0))));return e.pipe(r.tap(()=>{t.next()}),r.takeUntil(n))},dr=s=>{const e=async()=>await Promise.reject(new Error("No query found"));process.env.NODE_ENV!=="production"&&s.queryFn===je&&console.error(`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${s.queryHash}'`);let t=!1;const n=s.queryFn&&s.queryFn!==je?s.queryFn:e,i=new AbortController,u={meta:s.meta,queryKey:s.queryKey};(o=>{Object.defineProperty(o,"signal",{enumerable:!0,get:()=>(s.onSignalConsumed(),i.signal)})})(u);const h=(typeof n=="function"?R(()=>n(u)):n).pipe(fr(s.observers$),r.tap({complete:()=>{t=!0}}),r.map(o=>({data:o})),hr(s),Ue({...s,retryAfter:()=>r.of(!0).pipe(lr),catchError:(o,b)=>r.of({status:"error",fetchStatus:"idle",fetchFailureCount:o,fetchFailureReason:b,error:b}),caughtError:(o,b)=>r.of({fetchFailureCount:o,fetchFailureReason:b})}),r.mergeMap(o=>"data"in o?r.of({...o,status:"success",fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null,dataUpdatedAt:new Date().getTime()}).pipe(r.delay(1),r.map(b=>t?b:{...b,fetchStatus:"fetching"})):r.of(o)),r.endWith({fetchStatus:"idle"}),r.share()),f=r.of({status:"pending",fetchStatus:_.isOnline()?"fetching":"paused"});return{state$:r.merge(f,h).pipe(r.share()),abortController:i}};class pr{constructor(e){m(this,"revert");m(this,"silent");this.revert=e==null?void 0:e.revert,this.silent=e==null?void 0:e.silent}}const br={backgroundColor:"transparent",color:"inherit"};function dt(s){const e={namespaces:[{name:"@reactjrx",style:{backgroundColor:"#d02f4e",color:"white"}}],namespace(t,n){const i=dt();return i.namespaces.push({name:t,style:n??br}),i},printNamespaces(){return{namespaces:e.namespaces.map(({name:t})=>`%c ${t} %c`).join(" "),styles:e.namespaces.reduce((t,{style:n})=>(t.push(`background-color: ${n.backgroundColor}; color: ${n.color};`),t.push("background-color: transparent; color: inherit;"),t),[])}},print(t,...n){return e},printWithoutNamespace(t,...n){return e},log(...t){return e.print("log",...t)},warn(...t){return e.print("warn",...t)},error(...t){return e.print("error",...t)},group(...t){return e.print("group",...t)},groupEnd(){return e}};return e}const gr=dt();var ce,Y;class mr{constructor(e){m(this,"queryKey");m(this,"queryHash");m(this,"gcTime");m(this,"options");w(this,ce);w(this,Y);m(this,"state");m(this,"executeSubject",new r.Subject);m(this,"cancelSubject",new r.Subject);m(this,"setDataSubject",new r.Subject);m(this,"invalidatedSubject",new r.Subject);m(this,"resetSubject",new r.Subject);m(this,"destroySubject",new r.Subject);m(this,"observersSubject",new r.BehaviorSubject([]));m(this,"abortSignalConsumed",!1);m(this,"observerCount$",this.observersSubject.asObservable().pipe(r.map(e=>e.length)));m(this,"observers$",this.observersSubject.asObservable());m(this,"state$");j(this,ce,e.defaultOptions),this.options=this.setOptions(e.options),this.queryKey=e.queryKey,this.queryHash=e.queryHash,j(this,Y,e.state??or(this.options)),this.state=c(this,Y),this.gcTime=this.updateGcTime(this.options.gcTime),this.state$=r.merge(this.resetSubject.pipe(r.map(()=>({command:"reset",state:c(this,Y)}))),this.invalidatedSubject.pipe(r.filter(()=>!this.state.isInvalidated),r.map(()=>({command:"invalidate",state:{isInvalidated:!0}}))),this.cancelSubject.pipe(r.filter(()=>!(this.state.error&&this.state.status==="error")),r.map(t=>({command:"cancel",state:{status:t!=null&&t.revert?this.state.status:"error",fetchStatus:"idle",error:new pr(t)}}))),this.executeSubject.pipe(r.mergeMap(()=>{let t=!1;const n=this.executeSubject.pipe(r.filter(f=>(f==null?void 0:f.cancelRefetch)!==!1)),i=this.observers$.pipe(r.pairwise(),r.tap(([f,o])=>{o.length===0&&f.length>0?t=!0:t=!1}),r.ignoreElements()),{state$:u,abortController:a}=dr({...this.options,observers$:this.observerCount$,queryKey:this.queryKey,retry:(f,o)=>{const b=this.options.retry??!0;return typeof b=="function"?b(f,o):typeof b=="boolean"?b:f<b},retryAfterDelay:()=>!t,onSignalConsumed:()=>{this.abortSignalConsumed=!0}}),l=this.observerCount$.pipe(r.filter(f=>f===0&&this.abortSignalConsumed),r.tap(()=>{this.cancelSubject.next({revert:!0})})),h=r.merge(this.cancelSubject,n,this.resetSubject,l).pipe(r.tap(()=>{this.abortSignalConsumed&&a.abort()}));return r.merge(u,i).pipe(r.map(f=>({command:"execute",state:f})),r.takeUntil(h))})),this.setDataSubject.pipe(r.map(({data:t,options:n})=>({command:"setData",state:{status:"success",data:t,dataUpdatedAt:(n==null?void 0:n.updatedAt)!==void 0?n.updatedAt:new Date().getTime()}})))).pipe(_t({initialState:this.state,getOptions:()=>this.options,getState:()=>this.state}),r.startWith(c(this,Y)),r.distinctUntilChanged(x),r.tap(t=>{this.state=t}),r.catchError(t=>{throw gr.error(t),t}),r.takeUntil(this.destroySubject),r.shareReplay({bufferSize:1,refCount:!1}))}setOptions(e){return this.options={...c(this,ce),...e},this.updateGcTime(this.options.gcTime),this.options}get meta(){return this.options.meta}get success$(){return this.state$.pipe(r.map(({data:e,status:t})=>({data:e,status:t})),r.distinctUntilChanged(x),r.filter(({status:e})=>e==="success"))}get error$(){return this.state$.pipe(r.map(({error:e,status:t})=>({error:e,status:t})),r.distinctUntilChanged(x),r.filter(({status:e})=>e==="error"))}get settled$(){return this.state$.pipe(r.map(({status:e})=>({status:e})),r.distinctUntilChanged(x),r.filter(({status:e})=>e==="success"||e==="error"))}observe(e){return this.state$.pipe(r.tap({subscribe:()=>{this.observersSubject.next([e,...this.observersSubject.getValue()])},unsubscribe:()=>{this.observersSubject.next(this.observersSubject.getValue().filter(n=>n!==e))}}))}getObserversCount(){return this.observersSubject.getValue().length}updateGcTime(e){return this.gcTime=Math.max(this.gcTime||0,e??(X?1/0:5*60*1e3)),this.gcTime}isActive(){return this.observersSubject.getValue().some(e=>e.options.enabled!==!1)}isDisabled(){return this.getObserversCount()>0&&!this.isActive()}isStale(){return this.state.isInvalidated||!this.state.dataUpdatedAt||this.observersSubject.getValue().some(e=>e.getCurrentResult().isStale)}isStaleByTime(e=0){return this.state.isInvalidated||!this.state.dataUpdatedAt||!Wt(this.state.dataUpdatedAt,e)}async getFetchResultAsPromise(){return await new Promise((e,t)=>{this.state$.pipe(at,r.last()).subscribe({error:t,next:n=>{n.error?t(n.error):e(n.data)}})})}async fetch(e,t){const{cancelRefetch:n}=t??{};return this.state.fetchStatus!=="idle"&&!(!!this.state.dataUpdatedAt&&n)?await this.getFetchResultAsPromise():(e&&this.setOptions(e),this.executeSubject.next(t),await this.getFetchResultAsPromise())}setData(e,t){const n=Se(this.state.data,e,this.options);return this.setDataSubject.next({data:n,options:t}),n}invalidate(){this.invalidatedSubject.next()}async cancel(e){this.cancelSubject.next(e)}destroy(){this.destroySubject.next(),this.destroySubject.complete(),this.executeSubject.complete()}reset(){this.resetSubject.next()}}ce=new WeakMap,Y=new WeakMap;var oe,N;class pt{constructor(e={}){w(this,oe,new r.Subject);w(this,N,new ht);this.config=e}mount(){}unmount(){}notify(e){c(this,oe).next(e)}observeIsFetching(e){return c(this,N).stateChange$.pipe(r.startWith(),r.map(()=>this.findAll({...e,fetchStatus:"fetching"}).length),r.distinctUntilChanged())}getAll(){return[...c(this,N).getValues()]}findAll(e={}){const t=this.getAll();return Object.keys(e).length>0?t.filter(n=>Ye(e,n)):t}build(e,t,n){const i=t.queryKey??[Ae()],u=t.queryHash??Ve(i,t);let a=this.get(u);return a||(a=new mr({cache:this,queryKey:i,queryHash:u,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(i)}),this.add(a)),a}add(e){if(!c(this,N).find(t=>t.queryHash===e.queryHash)){c(this,N).add(e);const t=e.observerCount$.pipe(r.filter(n=>n<1),r.take(1));e.success$.subscribe(()=>{var n,i;(i=(n=this.config).onSuccess)==null||i.call(n,e.state.data,e)}),e.error$.subscribe(()=>{var n,i;(i=(n=this.config).onError)==null||i.call(n,e.state.error,e)}),e.settled$.subscribe(()=>{var n,i;(i=(n=this.config).onSettled)==null||i.call(n,e.state.data,e.state.error,e)}),e.state$.pipe(zt,r.switchMap(n=>n?t.pipe(r.switchMap(()=>e.gcTime===1/0?r.NEVER:(setTimeout(r.noop,e.gcTime),r.timer(e.gcTime)))):r.NEVER),r.take(1)).subscribe({complete:()=>{this.remove(e)}})}}get(e){return c(this,N).find(t=>t.queryHash===e)}find(e){const t={exact:!0,...e};return this.getAll().find(n=>Ye(t,n))}subscribe(e){const t=r.merge(c(this,oe).pipe(r.tap(e))).subscribe();return()=>{t.unsubscribe()}}remove(e){const t=c(this,N).find(n=>n===e);t&&(e.destroy(),t===e&&c(this,N).remove(e))}clear(){}}oe=new WeakMap,N=new WeakMap;var G,F,le,he,te;class yr{constructor({mutationCache:e,queryCache:t,defaultOptions:n}={}){w(this,G);w(this,F);w(this,le,new Map);w(this,he,new Map);w(this,te);j(this,G,e??new ft),j(this,F,t??new pt),j(this,te,n??{})}mount(){}unmount(){}getMutationCache(){return c(this,G)}getQueryCache(){return c(this,F)}defaultMutationOptions(e){return{...c(this,te).mutations,...(e==null?void 0:e.mutationKey)&&this.getMutationDefaults(e.mutationKey),...e}}defaultQueryOptions(e){if(e._defaulted)return e;const t={...c(this,te).queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=Ve(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.enabled!==!0&&t.queryFn===je&&(t.enabled=!1),t}async fetchQuery(e){const t=this.defaultQueryOptions(e);typeof t.retry>"u"&&(t.retry=!1);const n=c(this,F).build(this,t);return n.isStaleByTime(t.staleTime)?await n.fetch(t):await Promise.resolve(n.state.data)}async prefetchQuery(e){await this.fetchQuery(e).then(r.noop).catch(r.noop)}async resetQueries(e,t){const n=c(this,F),i={type:"active",...e};n.findAll(e).forEach(u=>{u.reset()}),await this.refetchQueries(i,t)}async refetchQueries(e={},t){const n={...t,cancelRefetch:(t==null?void 0:t.cancelRefetch)??!0},i=c(this,F).findAll(e).filter(u=>!u.isDisabled()).map(async u=>{let a=u.fetch(void 0,n);return n.throwOnError||(a=a.catch(r.noop)),u.state.fetchStatus==="paused"?void 0:await a});await Promise.all(i).then(r.noop)}getQueryData(e){var n;const t=this.defaultQueryOptions({queryKey:e});return(n=c(this,F).get(t.queryHash))==null?void 0:n.state.data}setQueryData(e,t,n){const i=this.defaultQueryOptions({queryKey:e}),u=c(this,F).get(i.queryHash),a=u==null?void 0:u.state.data,l=Lt(t,a);if(l!==void 0)return c(this,F).build(this,i).setData(l,{...n,manual:!0})}getMutationDefaults(e){const t=[...c(this,le).values()];let n={};return t.forEach(i=>{ye(e,i.mutationKey)&&(n={...n,...i.defaultOptions})}),n}getQueryState(e){var t;return(t=c(this,F).find({queryKey:e}))==null?void 0:t.state}setMutationDefaults(e,t){c(this,le).set(re(e),{mutationKey:e,defaultOptions:t})}setQueryDefaults(e,t){c(this,he).set(re(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...c(this,he).values()];let n={};return t.forEach(i=>{Ee(e,i.queryKey)&&(n={...n,...i.defaultOptions})}),n}removeQueries(e){const t=c(this,F);t.findAll(e).forEach(n=>{t.remove(n)})}async cancelQueries(e={},t={}){const n={revert:!0,...t},i=c(this,F).findAll(e).map(async u=>{await u.cancel(n)});await Promise.all(i).then(r.noop).catch(r.noop)}async invalidateQueries(e={},t={}){if(c(this,F).findAll(e).forEach(i=>{i.invalidate()}),e.refetchType==="none"){await Promise.resolve();return}const n={...e,type:e.refetchType??e.type??"active"};await this.refetchQueries(n,t)}async resumePausedMutations(){return await r.lastValueFrom(c(this,G).resumePausedMutations())}isFetching(e){return c(this,F).findAll({...e,fetchStatus:"fetching"}).length}clear(){c(this,F).clear(),c(this,G).clear()}}G=new WeakMap,F=new WeakMap,le=new WeakMap,he=new WeakMap,te=new WeakMap;exports.MutationCache=ft;exports.QueryCache=pt;exports.QueryClient=yr;exports.QueryClientProvider=Vt;exports.SIGNAL_RESET=Je;exports.arrayEqual=Ut;exports.createLocalStorageAdapter=Xe;exports.createLocalforageAdapter=Et;exports.exponentialBackoffDelay=et;exports.getDelay=Ze;exports.isDefined=me;exports.retryBackoff=Ue;exports.signal=wt;exports.useBehaviorSubject=xe;exports.useEffectOnce=tt;exports.useForeverQuery=nr;exports.useLiveRef=Q;exports.useMount=At;exports.useMutation=Tt;exports.useObservableState=Ot;exports.useObserve=fe;exports.useObserveCallback=vt;exports.usePersistSignals=Rt;exports.useQuery=sr;exports.useQueryClient=Pe;exports.useSignalValue=$t;exports.useSubject=Re;exports.useSubscribe=Fe;exports.useSubscribeEffect=ir;exports.useUnmountObservable=xt;
package/dist/index.js CHANGED
@@ -6,8 +6,8 @@ var Bt = (s, e, t) => e in s ? Yt(s, e, { enumerable: !0, configurable: !0, writ
6
6
  var g = (s, e, t) => Bt(s, typeof e != "symbol" ? e + "" : e, t), bt = (s, e, t) => e.has(s) || yt("Cannot " + t);
7
7
  var a = (s, e, t) => (bt(s, e, "read from private field"), t ? t.call(s) : e.get(s)), w = (s, e, t) => e.has(s) ? yt("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(s) : e.set(s, t), A = (s, e, t, r) => (bt(s, e, "write to private field"), r ? r.call(s, t) : e.set(s, t), t);
8
8
  import * as Ge from "react";
9
- import { useRef as me, useMemo as ut, useCallback as de, useSyncExternalStore as Xt, useEffect as J, createContext as Zt, memo as es, useContext as ts, useState as jt } from "react";
10
- import { distinctUntilChanged as U, tap as R, catchError as X, EMPTY as Z, isObservable as gt, from as Se, of as v, defer as Ae, Subject as I, BehaviorSubject as Y, skip as at, first as Je, map as b, switchMap as j, zip as ss, filter as O, merge as C, throttleTime as rs, asyncScheduler as ns, throwError as Oe, timer as Qe, Observable as is, takeWhile as Ye, concatMap as us, last as Ke, mergeMap as q, takeUntil as ne, identity as Mt, shareReplay as Ue, ignoreElements as ie, scan as Be, fromEvent as Ne, noop as N, startWith as he, pairwise as At, NEVER as qe, delay as ot, interval as as, withLatestFrom as mt, retry as os, iif as cs, share as ue, isEmpty as ls, concat as Te, toArray as ke, take as He, combineLatest as hs, endWith as ds, lastValueFrom as fs } from "rxjs";
9
+ import { useRef as me, useMemo as ut, useCallback as de, useSyncExternalStore as Xt, useEffect as Y, createContext as Zt, memo as es, useContext as ts, useState as jt } from "react";
10
+ import { distinctUntilChanged as U, tap as R, catchError as J, EMPTY as B, isObservable as gt, from as Se, of as v, defer as Ae, Subject as I, BehaviorSubject as X, skip as at, first as Je, map as b, switchMap as j, zip as ss, filter as O, merge as C, throttleTime as rs, asyncScheduler as ns, throwError as Oe, timer as Qe, Observable as is, takeWhile as Ye, concatMap as us, last as Ke, mergeMap as q, takeUntil as ne, identity as Mt, shareReplay as Ue, ignoreElements as ie, scan as Be, fromEvent as Ne, noop as N, startWith as he, pairwise as At, NEVER as qe, delay as ot, interval as as, withLatestFrom as mt, retry as os, iif as cs, share as ue, isEmpty as ls, concat as Te, toArray as ke, take as He, combineLatest as hs, endWith as ds, lastValueFrom as fs } from "rxjs";
11
11
  import { catchError as St, mergeMap as tt, retryWhen as ps, concatMap as ys, first as bs, tap as Qt } from "rxjs/operators";
12
12
  import { jsxs as gs, jsx as ms } from "react/jsx-runtime";
13
13
  const H = (s) => {
@@ -38,7 +38,7 @@ function Xe(s, e, t) {
38
38
  R((y) => {
39
39
  u.current = y;
40
40
  }),
41
- X((y) => (console.error(y), Z))
41
+ J((y) => (console.error(y), B))
42
42
  ).subscribe(p);
43
43
  return () => {
44
44
  c.current.unsubscribeOnUnmount !== !1 && f.unsubscribe();
@@ -64,8 +64,10 @@ function V(s) {
64
64
  }
65
65
  function Ut(s, e = []) {
66
66
  const t = H(s);
67
- J(() => {
68
- const r = V(t.current).subscribe();
67
+ Y(() => {
68
+ const r = V(t.current).pipe(
69
+ J((n) => (console.error(n), B))
70
+ ).subscribe();
69
71
  return () => {
70
72
  r.unsubscribe();
71
73
  };
@@ -77,7 +79,7 @@ function Ut(s, e = []) {
77
79
  }
78
80
  const Ze = (s) => {
79
81
  const e = me();
80
- return e.current || (e.current = s()), J(() => {
82
+ return e.current || (e.current = s()), Y(() => {
81
83
  process.env.NODE_ENV;
82
84
  }, []), e;
83
85
  }, Vt = ({
@@ -85,7 +87,7 @@ const Ze = (s) => {
85
87
  completeOnUnmount: e = !0
86
88
  } = {}) => {
87
89
  const t = Ze(() => new I()), r = me(!1), n = H(s), u = H(e);
88
- return J(() => (r.current && (t.current = new I(), r.current = !1), () => {
90
+ return Y(() => (r.current && (t.current = new I(), r.current = !1), () => {
89
91
  if (!u.current) {
90
92
  r.current = !0;
91
93
  return;
@@ -102,8 +104,8 @@ const Ze = (s) => {
102
104
  );
103
105
  return [e.current, t];
104
106
  }, It = (s) => {
105
- const e = Ze(() => new Y(s)), t = me(!1), r = me(s);
106
- return J(() => (t.current && (e.current = new Y(r.current), t.current = !1), () => {
107
+ const e = Ze(() => new X(s)), t = me(!1), r = me(s);
108
+ return Y(() => (t.current && (e.current = new X(r.current), t.current = !1), () => {
107
109
  t.current || (e.current.complete(), t.current = !0);
108
110
  }), [e]), e;
109
111
  }, gr = (s) => {
@@ -120,7 +122,7 @@ function mr(s = {}) {
120
122
  const e = {
121
123
  default: s.default,
122
124
  key: s.key
123
- }, { default: t } = e ?? {}, r = new Y(t), n = (i) => {
125
+ }, { default: t } = e ?? {}, r = new X(t), n = (i) => {
124
126
  if (typeof i == "function") {
125
127
  const c = i(r.getValue());
126
128
  if (c === r.getValue()) return;
@@ -228,7 +230,7 @@ function rt(s) {
228
230
  }
229
231
  const Ot = (s) => {
230
232
  const e = It(s);
231
- return J(() => {
233
+ return Y(() => {
232
234
  e.current.next(s);
233
235
  }, [s, e]), e;
234
236
  }, Cs = ({
@@ -241,7 +243,7 @@ const Ot = (s) => {
241
243
  migrationVersion: r
242
244
  };
243
245
  return Se(s.setItem(t.config.key, u)).pipe(
244
- X((i) => (console.error(i), v(null)))
246
+ J((i) => (console.error(i), v(null)))
245
247
  );
246
248
  };
247
249
  function Fs({
@@ -280,7 +282,7 @@ function Or({
280
282
  R(() => {
281
283
  n.current != null && n.current();
282
284
  }),
283
- X((p) => (console.error("Unable to hydrate", p), Z))
285
+ J((p) => (console.error("Unable to hydrate", p), B))
284
286
  ))
285
287
  );
286
288
  },
@@ -394,7 +396,7 @@ function Pt(s) {
394
396
  });
395
397
  }
396
398
  const wr = (s, e) => s.length === e.length && s.every((t, r) => t === e[r]), Rs = (s) => {
397
- J(s, []);
399
+ Y(s, []);
398
400
  }, Cr = (s) => {
399
401
  Rs(() => {
400
402
  s();
@@ -451,7 +453,7 @@ class js {
451
453
  } = {}) {
452
454
  w(this, ee, new I());
453
455
  g(this, "state$");
454
- const t = new Y(0), r = t.pipe(
456
+ const t = new X(0), r = t.pipe(
455
457
  O((n) => n === 0)
456
458
  );
457
459
  this.state$ = a(this, ee).pipe(
@@ -463,7 +465,7 @@ class js {
463
465
  R(() => {
464
466
  u.cancel();
465
467
  })
466
- ), o = Ae(() => (u.execute(n), Z)), p = u.state$.pipe(
468
+ ), o = Ae(() => (u.execute(n), B)), p = u.state$.pipe(
467
469
  we,
468
470
  Ke(),
469
471
  q(() => u.state$),
@@ -535,7 +537,7 @@ var ae, L;
535
537
  class Ms {
536
538
  constructor(e, t = {}, r) {
537
539
  w(this, ae);
538
- w(this, L, new Y(void 0));
540
+ w(this, L, new X(void 0));
539
541
  /**
540
542
  * @important
541
543
  * Used to maintain persistance to latest mutation. This ensure
@@ -572,7 +574,7 @@ class Ms {
572
574
  state: i,
573
575
  options: u.options
574
576
  }))
575
- )) ?? Z),
577
+ )) ?? B),
576
578
  R(({ state: u, options: i }) => {
577
579
  u.status === "error" && (i != null && i.onError && (i == null || i.onError(
578
580
  u.error,
@@ -682,7 +684,7 @@ class Ms {
682
684
  }
683
685
  }
684
686
  ae = new WeakMap(), L = new WeakMap();
685
- const Tt = Zt(void 0), As = ({ client: s }) => (J(() => (s.mount(), () => {
687
+ const Tt = Zt(void 0), As = ({ client: s }) => (Y(() => (s.mount(), () => {
686
688
  s.unmount();
687
689
  }), [s]), null), Fr = es(
688
690
  ({ children: s, client: e }) => {
@@ -709,7 +711,7 @@ function Er(s, e) {
709
711
  s
710
712
  )
711
713
  );
712
- J(() => {
714
+ Y(() => {
713
715
  i.setOptions(s);
714
716
  }, [i, s]);
715
717
  const c = ut(() => i.observe(), [u, i]), l = Xe(c.result$) ?? c.lastValue, h = de(
@@ -718,7 +720,7 @@ function Er(s, e) {
718
720
  },
719
721
  [i]
720
722
  );
721
- return J(() => () => {
723
+ return Y(() => () => {
722
724
  r.current.cancelOnUnMount && i.reset();
723
725
  }, [i, r]), { ...l, mutate: h, mutateAsync: l.mutate };
724
726
  }
@@ -732,15 +734,15 @@ function Us(s) {
732
734
  const pe = typeof window > "u" || "Deno" in window;
733
735
  class Vs {
734
736
  constructor() {
735
- g(this, "isOnlineSubject", new Y(!0));
737
+ g(this, "isOnlineSubject", new X(!0));
736
738
  g(this, "online$", this.isOnlineSubject.pipe(U()));
737
739
  g(this, "backToOnline$", this.online$.pipe(
738
740
  O((e) => e),
739
741
  Je()
740
742
  ));
741
743
  C(
742
- pe ? Z : Ne(window, "offline").pipe(b(() => !1)),
743
- pe ? Z : Ne(window, "online").pipe(b(() => !0))
744
+ pe ? B : Ne(window, "offline").pipe(b(() => !1)),
745
+ pe ? B : Ne(window, "online").pipe(b(() => !0))
744
746
  ).pipe(Us(this.isOnlineSubject)).subscribe();
745
747
  }
746
748
  isOnline() {
@@ -875,10 +877,10 @@ var We, te;
875
877
  class qs {
876
878
  constructor() {
877
879
  w(this, We, C(
878
- pe ? Z : Ne(document, "visibilitychange"),
879
- pe ? Z : Ne(window, "visibilitychange")
880
+ pe ? B : Ne(document, "visibilitychange"),
881
+ pe ? B : Ne(window, "visibilitychange")
880
882
  ).pipe(b(() => document.visibilityState)));
881
- w(this, te, new Y(
883
+ w(this, te, new X(
882
884
  pe ? !0 : document.visibilityState === "visible"
883
885
  ));
884
886
  // public readonly focused$ = this.#focusedSubject.pipe(distinctUntilChanged())
@@ -926,10 +928,10 @@ const ze = new qs(), Hs = (s) => s.pipe(
926
928
  })),
927
929
  U(P)
928
930
  );
929
- var B, M, Ce, oe, T, ye, Fe;
931
+ var Z, M, Ce, oe, T, ye, Fe;
930
932
  class Ht {
931
933
  constructor(e, t) {
932
- w(this, B);
934
+ w(this, Z);
933
935
  w(this, M);
934
936
  w(this, Ce, new I());
935
937
  /**
@@ -1040,7 +1042,7 @@ class Ht {
1040
1042
  selectResult: W
1041
1043
  };
1042
1044
  });
1043
- this.options = t, A(this, B, e), this.bindMethods(), A(this, M, this.setOptions(t));
1045
+ this.options = t, A(this, Z, e), this.bindMethods(), A(this, M, this.setOptions(t));
1044
1046
  const r = a(this, M);
1045
1047
  A(this, oe, r.state);
1046
1048
  const { result: n, select: u } = this.getObserverResultFromQuery({
@@ -1063,7 +1065,7 @@ class Ht {
1063
1065
  }
1064
1066
  setOptions(e) {
1065
1067
  const t = this.options;
1066
- if (this.options = a(this, B).defaultQueryOptions(e), P(this.options, t) || a(this, B).getQueryCache().notify({
1068
+ if (this.options = a(this, Z).defaultQueryOptions(e), P(this.options, t) || a(this, Z).getQueryCache().notify({
1067
1069
  type: "observerOptionsUpdated",
1068
1070
  query: a(this, M),
1069
1071
  observer: this
@@ -1076,7 +1078,7 @@ class Ht {
1076
1078
  }), r;
1077
1079
  }
1078
1080
  buildQuery(e) {
1079
- const t = a(this, B).getQueryCache().build(a(this, B), e);
1081
+ const t = a(this, Z).getQueryCache().build(a(this, Z), e);
1080
1082
  return !t.options.queryFn && this.options.queryFn && t.setOptions(e), t;
1081
1083
  }
1082
1084
  getCurrentResult() {
@@ -1105,7 +1107,7 @@ class Ht {
1105
1107
  select: n,
1106
1108
  selectResult: u
1107
1109
  }) {
1108
- a(this, T).state = e.state, a(this, T).result = t, a(this, T).selectResult = u, r !== void 0 && (a(this, T).selectError = r), n !== void 0 && (a(this, T).select = n), a(this, T).options = this.options, e.state.data !== void 0 && A(this, ye, e), a(this, B).getQueryCache().notify({
1110
+ a(this, T).state = e.state, a(this, T).result = t, a(this, T).selectResult = u, r !== void 0 && (a(this, T).selectError = r), n !== void 0 && (a(this, T).select = n), a(this, T).options = this.options, e.state.data !== void 0 && A(this, ye, e), a(this, Z).getQueryCache().notify({
1109
1111
  query: a(this, M),
1110
1112
  type: "observerResultsUpdated"
1111
1113
  });
@@ -1271,7 +1273,7 @@ class Ht {
1271
1273
  destroy() {
1272
1274
  }
1273
1275
  }
1274
- B = new WeakMap(), M = new WeakMap(), Ce = new WeakMap(), oe = new WeakMap(), T = new WeakMap(), ye = new WeakMap(), Fe = new WeakMap();
1276
+ Z = new WeakMap(), M = new WeakMap(), Ce = new WeakMap(), oe = new WeakMap(), T = new WeakMap(), ye = new WeakMap(), Fe = new WeakMap();
1275
1277
  function _s(s, e) {
1276
1278
  return !P(s.getCurrentResult(), e);
1277
1279
  }
@@ -1324,7 +1326,7 @@ function Lt(s, e, t) {
1324
1326
  O((F) => !P(F, h.current))
1325
1327
  ),
1326
1328
  []
1327
- ), J(() => {
1329
+ ), Y(() => {
1328
1330
  c.setOptions(i);
1329
1331
  }, [i, c]);
1330
1332
  const p = o.error;
@@ -1360,7 +1362,7 @@ function jr(s, e, t = []) {
1360
1362
  })
1361
1363
  ), i = de(() => V(s), t), c = de(
1362
1364
  () => i().pipe(
1363
- X((l) => {
1365
+ J((l) => {
1364
1366
  throw u.current(l), l;
1365
1367
  }),
1366
1368
  n ? os() : Mt
@@ -1383,7 +1385,7 @@ const zt = () => (s) => C(
1383
1385
  ), Bs = (s) => {
1384
1386
  let e = 0;
1385
1387
  return s.pipe(
1386
- X((t) => (e++, e <= 1 && !re.isOnline() ? C(
1388
+ J((t) => (e++, e <= 1 && !re.isOnline() ? C(
1387
1389
  v({
1388
1390
  failureCount: e,
1389
1391
  failureReason: t
@@ -1418,7 +1420,7 @@ const zt = () => (s) => C(
1418
1420
  return (E = t.onError) == null ? void 0 : E.call(t, d, s, f);
1419
1421
  }
1420
1422
  ).pipe(
1421
- X(() => v(d)),
1423
+ J(() => v(d)),
1422
1424
  b(
1423
1425
  () => ({
1424
1426
  failureCount: y,
@@ -1519,7 +1521,7 @@ const zt = () => (s) => C(
1519
1521
  );
1520
1522
  }
1521
1523
  ).pipe(
1522
- X((S) => d ? v(d) : v(S))
1524
+ J((S) => d ? v(d) : v(S))
1523
1525
  );
1524
1526
  return Te(x, $).pipe(
1525
1527
  ke(),
@@ -1539,7 +1541,7 @@ const zt = () => (s) => C(
1539
1541
  ...y
1540
1542
  }
1541
1543
  ),
1542
- X(
1544
+ J(
1543
1545
  (S) => h(S, y.context, 0).pipe(
1544
1546
  b((m) => ({
1545
1547
  ...m,
@@ -1566,7 +1568,7 @@ class Zs {
1566
1568
  mutationCache: t,
1567
1569
  state: r
1568
1570
  }) {
1569
- w(this, Ee, new Y(0));
1571
+ w(this, Ee, new X(0));
1570
1572
  w(this, se, new I());
1571
1573
  w(this, be, new I());
1572
1574
  g(this, "state", fe());
@@ -1728,7 +1730,7 @@ class Wt {
1728
1730
  * @important
1729
1731
  * Query store. Could be turned into a map for more performance.
1730
1732
  */
1731
- g(this, "entriesSubject", new Y([]));
1733
+ g(this, "entriesSubject", new X([]));
1732
1734
  g(this, "changeSubject", new I());
1733
1735
  g(this, "entries$", this.entriesSubject.pipe(ue()));
1734
1736
  g(this, "added$", this.changeSubject.pipe(
@@ -1870,7 +1872,7 @@ class er {
1870
1872
  const e = this.findAll({
1871
1873
  predicate: (r) => r.state.isPaused
1872
1874
  });
1873
- if (!e.length) return Z;
1875
+ if (!e.length) return B;
1874
1876
  const t = e.map((r) => r.continue());
1875
1877
  return hs(t);
1876
1878
  }
@@ -2107,7 +2109,7 @@ class cr {
2107
2109
  g(this, "invalidatedSubject", new I());
2108
2110
  g(this, "resetSubject", new I());
2109
2111
  g(this, "destroySubject", new I());
2110
- g(this, "observersSubject", new Y([]));
2112
+ g(this, "observersSubject", new X([]));
2111
2113
  g(this, "abortSignalConsumed", !1);
2112
2114
  g(this, "observerCount$", this.observersSubject.asObservable().pipe(b((e) => e.length)));
2113
2115
  g(this, "observers$", this.observersSubject.asObservable());
@@ -2206,7 +2208,7 @@ class cr {
2206
2208
  R((t) => {
2207
2209
  this.state = t;
2208
2210
  }),
2209
- X((t) => {
2211
+ J((t) => {
2210
2212
  throw or.error(t), t;
2211
2213
  }),
2212
2214
  ne(this.destroySubject),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reactjrx",
3
3
  "private": false,
4
- "version": "1.93.0",
4
+ "version": "1.93.1",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"