reactjrx 1.96.0 → 1.97.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var yt=Object.defineProperty;var De=s=>{throw TypeError(s)};var St=(s,e,t)=>e in s?yt(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var m=(s,e,t)=>St(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 S=require("react"),r=require("rxjs"),K=require("rxjs/operators"),Ne=require("react/jsx-runtime");function vt(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=vt(S),Q=s=>{const e=S.useRef(s);return S.useMemo(()=>{e.current=s},[s]),e};function Ot(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=S.useRef("getValue"in s&&typeof s.getValue=="function"?s.getValue():n.defaultValue),a=Q(s),l=Q(n),h=S.useCallback(b=>{const $=a.current,p=(typeof $=="function"?$:()=>$)().pipe(r.distinctUntilChanged(Ot),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=S.useCallback(()=>u.current,[]);return S.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);S.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=S.useRef();return e.current||(e.current=s()),S.useEffect(()=>{process.env.NODE_ENV},[]),e},Re=({onBeforeComplete:s,completeOnUnmount:e=!0}={})=>{const t=$e(()=>new r.Subject),n=S.useRef(!1),i=Q(s),u=Q(e);return S.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},wt=()=>{const s=Re(),e=Q(s.current.asObservable()),t=S.useCallback(n=>{s.current.next(n)},[]);return[e.current,t]},xe=s=>{const e=$e(()=>new r.BehaviorSubject(s)),t=S.useRef(!1),n=S.useRef(s);return S.useEffect(()=>(t.current&&(e.current=new r.BehaviorSubject(n.current),t.current=!1),()=>{t.current||(e.current.complete(),t.current=!0)}),[e]),e},$t=s=>{const e=xe(s),t=Q(e.current.asObservable()),n=S.useCallback(i=>{e.current.next(i)},[e.current]);return[t.current,n,e.current.getValue()]},Je=Symbol("SIGNAL_RESET");function Xe(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 Ze(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=>{const[e]=S.useState(()=>Xe(s));return[Ze(e),e]},Ct=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},Mt=({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})}}),et=({key:s}={})=>s?Mt({adapter:et(),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",jt=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 S.useEffect(()=>{e.current.next(s)},[s,e]),e},Ft=({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 Rt({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=jt(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 xt({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=>Rt({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(Ft({adapter:h,config:f})))))))),[l,u]),{isHydrated:a}}const Ut=()=>{const s=Re({onBeforeComplete:()=>{s.current.next()}});return s};function tt(s,e){return Math.min(s,e)}function rt(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=rt}=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(tt(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 At=(s,e)=>s.length===e.length&&s.every((t,n)=>t===e[n]),st=s=>{S.useEffect(s,[])},Qt=s=>{st(()=>{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 Pt{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 nt=s=>s.pipe(r.distinctUntilChanged(({data:e,...t},{data:n,...i})=>x(t,i)&&x(e,n)));var z,I;class kt{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 Pt(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(nt),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 it=S.createContext(void 0),Vt=({client:s})=>(S.useEffect(()=>(s.mount(),()=>{s.unmount()}),[s]),null),It=S.memo(({children:s,client:e})=>{const t=S.useMemo(()=>e,[e]);return Ne.jsxs(it.Provider,{value:t,children:[Ne.jsx(Vt,{client:e}),s]})}),Pe=s=>{const e=S.useContext(it);if(s)return s;if(!e)throw new Error("No QueryClient set, use QueryClientProvider to set one");return e};function Tt(){}function Dt(s,e){const t=Pe(e),n=Q(s),i=$e(()=>[Ae()]),u=re(s.mutationKey??i.current),[a]=S.useState(()=>new kt(t,s));S.useEffect(()=>{a.setOptions(s)},[a,s]);const l=S.useMemo(()=>a.observe(),[u,a]),h=fe(l.result$)??l.lastValue,f=S.useCallback((o,b)=>{a.mutate(o,b).catch(Tt)},[a]);return S.useEffect(()=>()=>{n.current.cancelOnUnMount&&a.reset()},[a,n]),{...h,mutate:f,mutateAsync:h.mutate}}function Kt(s){return e=>e.pipe(K.tap(t=>{s.next(t)}))}const X=typeof window>"u"||"Deno"in window;class Nt{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(Kt(this.isOnlineSubject)).subscribe()}isOnline(){return this.isOnlineSubject.getValue()}setOnline(e){this.isOnlineSubject.getValue()!==e&&this.isOnlineSubject.next(e)}}const _=new Nt;function ke(s,e){return s.isStaleByTime(e.staleTime)}function qt(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 qt(s,e)||s.state.dataUpdatedAt>0&&at(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 Ht(s,e){return at(s,e,e.refetchOnWindowFocus)}function at(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 Wt(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 ut(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]=ut(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 Lt(s,e){return Math.max(s+(e??0)-Date.now(),0)}function _t(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?ut(s,e):e}const je=Symbol(),zt=({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 v=i.status==="pending"?"pending":a.status??i.status;return{...i,...a,status:v}}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)),Bt=s=>s.pipe(r.map(({status:e,fetchStatus:t})=>t==="idle"&&(e==="success"||e==="error"))),ct=s=>s.pipe(r.takeWhile(e=>e.fetchStatus!=="idle",!0));var Oe,W;class Yt{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 Yt,Gt=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 ot{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),mt=P&&_e(t,$,e,d);(Te||mt)&&(E=Wt(t.options.networkMode)?"fetching":"paused")}const U=b&&E==="fetching";let v,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)v=f;else try{T=e.select,v=e.select(o.data),v=Se(i==null?void 0:i.data,v,e),D=v,y=null}catch(P){v=f,y=P}else v=o.data,y=null;let V=E!=="idle"&&!o.dataUpdatedAt?"pending":o.status;y&&(O=y,v=f,C=(i==null?void 0:i.errorUpdatedAt)??C,V="error");const de=V==="error";let pe=!1;if(typeof e.placeholderData<"u"&&typeof v>"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",v=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:v,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 Jt(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(Gt,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$),ct),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])=>{Ht(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})),v=r.merge(E,$,a.state$,o).pipe(O,r.distinctUntilChanged(x),r.distinctUntilChanged(b));return r.merge(d,C,v)})).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 Jt(s,e){return!x(s.getCurrentResult(),e)}const lt=we.createContext(!1),Xt=()=>we.useContext(lt);lt.Provider;function Zt(){let s=!1;return{clearReset:()=>{s=!1},reset:()=>{s=!0},isReset:()=>s}}const er=we.createContext(Zt()),tr=()=>we.useContext(er);function rr(s,e){return typeof s=="function"?s(...e):!!s}const sr=({result:s,errorResetBoundary:e,throwOnError:t,query:n})=>s.isError&&!e.isReset()&&!s.isFetching&&n&&rr(t,[s.error,n]);function ht(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=Xt(),u=tr(),a=n.defaultQueryOptions(s);a._optimisticResults=i?"isRestoring":"optimistic";const[l]=S.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))),[]),S.useEffect(()=>{l.setOptions(a)},[a,l]);const b=o.error;if(b&&sr({result:o,errorResetBoundary:u,throwOnError:a.throwOnError,query:n.getQueryCache().get(a.queryHash)}))throw b;return f.current}function nr(s,e){return ht(s,ot,e)}function ir(s,e){return ht({refetchOnMount:"idle",refetchOnReconnect:!1,refetchInterval:!1,refetchOnWindowFocus:!1,...s},ot,e)}function ar(s,e,t=[]){const n=e!=null&&!Array.isArray(e)?e:{},i=n.retry??!0,u=Q(n.onError??(h=>{console.error(h)})),a=S.useCallback(()=>R(s),t),l=S.useCallback(()=>a().pipe(r.catchError(h=>{throw u.current(h),h}),i?r.retry():r.identity),[a,i,u]);Fe(l,t)}const ft=()=>s=>r.merge(r.of({isPaused:!0}),_.backToOnline$.pipe(r.mergeMap(()=>r.merge(r.of({isPaused:!1}),s)))),ur=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(ft())))):r.throwError(()=>t))))},cr=({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})),ur,Ue({...t,retry:(O,U)=>{const v=t.retry??0;return typeof v=="function"?v(O,U):typeof v=="boolean"?v:O<v},caughtError:(O,U)=>r.of({failureCount:O,failureReason:U}),catchError:(O,U)=>f(U,d,O).pipe(r.map(v=>({...v,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(ft())})),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 v;return(v=t.onSuccess)==null?void 0:v.call(t,d==null?void 0:d.data,s,g.context)}),O=R(()=>{var v;return(v=t.onSettled)==null?void 0:v.call(t,d==null?void 0:d.data,p,s,g.context)}).pipe(r.catchError(v=>d?r.of(d):r.of(v)));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(v=>f(v,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 or{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=>cr({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),nt,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 dt{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 pt{constructor(e={}){w(this,k,new dt);this.config=e}build(e,t,n){const i=new or({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 lr(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 hr=s=>r.defer(()=>ve.isFocused()?s:ve.focusRegained$.pipe(r.mergeMap(()=>s))),fr=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))}},dr=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))},pr=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(dr(s.observers$),r.tap({complete:()=>{t=!0}}),r.map(o=>({data:o})),fr(s),Ue({...s,retryAfter:()=>r.of(!0).pipe(hr),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 br{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 gr={backgroundColor:"transparent",color:"inherit"};function bt(s){const e={namespaces:[{name:"@reactjrx",style:{backgroundColor:"#d02f4e",color:"white"}}],namespace(t,n){const i=bt();return i.namespaces.push({name:t,style:n??gr}),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 mr=bt();var ce,Y;class yr{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??lr(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 br(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}=pr({...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(zt({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 mr.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||!Lt(this.state.dataUpdatedAt,e)}async getFetchResultAsPromise(){return await new Promise((e,t)=>{this.state$.pipe(ct,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 gt{constructor(e={}){w(this,oe,new r.Subject);w(this,N,new dt);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 yr({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(Bt,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 Sr{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 pt),j(this,F,t??new gt),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=_t(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=pt;exports.QueryCache=gt;exports.QueryClient=Sr;exports.QueryClientProvider=It;exports.SIGNAL_RESET=Je;exports.arrayEqual=At;exports.createLocalStorageAdapter=et;exports.createLocalforageAdapter=Ct;exports.exponentialBackoffDelay=rt;exports.getDelay=tt;exports.isDefined=me;exports.retryBackoff=Ue;exports.signal=Xe;exports.useBehaviorSubject=xe;exports.useEffectOnce=st;exports.useForeverQuery=ir;exports.useLiveRef=Q;exports.useMount=Qt;exports.useMutation=Dt;exports.useObservableState=$t;exports.useObserve=fe;exports.useObserveCallback=wt;exports.usePersistSignals=xt;exports.useQuery=nr;exports.useQueryClient=Pe;exports.useSignal=Et;exports.useSignalValue=Ze;exports.useSubject=Re;exports.useSubscribe=Fe;exports.useSubscribeEffect=ar;exports.useUnmountObservable=Ut;
1
+ "use strict";var yt=Object.defineProperty;var De=s=>{throw TypeError(s)};var St=(s,e,t)=>e in s?yt(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var g=(s,e,t)=>St(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 S=require("react"),r=require("rxjs"),K=require("rxjs/operators"),Ne=require("react/jsx-runtime");function vt(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=vt(S),Q=s=>{const e=S.useRef(s);return S.useMemo(()=>{e.current=s},[s]),e};function Ot(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 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,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=S.useRef("getValue"in s&&typeof s.getValue=="function"?s.getValue():n.defaultValue),a=Q(s),l=Q(n),h=S.useCallback(b=>{const E=a.current,d=R(E).pipe(r.distinctUntilChanged(Ot),r.tap(p=>{u.current=p}),r.catchError(p=>(console.error(p),r.EMPTY))).subscribe(b);return()=>{l.current.unsubscribeOnUnmount!==!1&&d.unsubscribe()}},[...i]),f=S.useCallback(()=>u.current,[]);return S.useSyncExternalStore(h,f,f)}function Fe(s,e=[]){const t=Q(s);S.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=S.useRef();return e.current||(e.current=s()),S.useEffect(()=>{process.env.NODE_ENV},[]),e},Re=({onBeforeComplete:s,completeOnUnmount:e=!0}={})=>{const t=$e(()=>new r.Subject),n=S.useRef(!1),i=Q(s),u=Q(e);return S.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},wt=()=>{const s=Re(),e=Q(s.current.asObservable()),t=S.useCallback(n=>{s.current.next(n)},[]);return[e.current,t]},xe=s=>{const e=$e(()=>new r.BehaviorSubject(s)),t=S.useRef(!1),n=S.useRef(s);return S.useEffect(()=>(t.current&&(e.current=new r.BehaviorSubject(n.current),t.current=!1),()=>{t.current||(e.current.complete(),t.current=!0)}),[e]),e},$t=s=>{const e=xe(s),t=Q(e.current.asObservable()),n=S.useCallback(i=>{e.current.next(i)},[e.current]);return[t.current,n,e.current.getValue()]},Je=Symbol("SIGNAL_RESET");function Xe(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 Ze(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=>{const[e]=S.useState(()=>Xe(s));return[Ze(e),e]},Ct=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},Mt=({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})}}),et=({key:s}={})=>s?Mt({adapter:et(),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",jt=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 S.useEffect(()=>{e.current.next(s)},[s,e]),e},Ft=({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 Rt({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=jt(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 xt({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=>Rt({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(Ft({adapter:h,config:f})))))))),[l,u]),{isHydrated:a}}const Ut=()=>{const s=Re({onBeforeComplete:()=>{s.current.next()}});return s};function tt(s,e){return Math.min(s,e)}function rt(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=rt}=h;return E=>r.defer(()=>{let d=0;const p=(m,C)=>m<u?a(m,C):!1;return E.pipe(K.catchError(m=>{var $;if(d++,!p(d-1,m))throw m;const C=($=s.caughtError)==null?void 0:$.call(s,d,m);if(!C)throw m;return C.pipe(K.mergeMap(O=>r.merge(r.of(O),r.throwError(()=>m))))}),K.retryWhen(m=>m.pipe(K.concatMap(C=>{const $=d-1;return i().pipe(K.first(),K.mergeMap(()=>p($,C)?r.timer(tt(b($,l),f)).pipe(K.mergeMap(O=>n&&!n($,C)?r.throwError(()=>C):r.of(O))):r.throwError(()=>C)))}))),K.catchError(m=>{if(s.catchError)return s.catchError(d,m);throw m}),K.tap(()=>{o&&(d=0)}))})}const At=(s,e)=>s.length===e.length&&s.every((t,n)=>t===e[n]),st=s=>{S.useEffect(s,[])},Qt=s=>{st(()=>{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 Pt{constructor({__queryFinalizeHook:e}={}){w(this,H,new r.Subject);g(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))),E=u.state$.pipe(ne,r.skip(1)),d=r.merge(n,h,f,u.cancelled$);return r.merge(E,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 nt=s=>s.pipe(r.distinctUntilChanged(({data:e,...t},{data:n,...i})=>x(t,i)&&x(e,n)));var z,I;class kt{constructor(e,t={},n){w(this,z);w(this,I,new r.BehaviorSubject(void 0));g(this,"observed$");g(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 Pt(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(nt),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 it=S.createContext(void 0),Vt=({client:s})=>(S.useEffect(()=>(s.mount(),()=>{s.unmount()}),[s]),null),It=S.memo(({children:s,client:e})=>{const t=S.useMemo(()=>e,[e]);return Ne.jsxs(it.Provider,{value:t,children:[Ne.jsx(Vt,{client:e}),s]})}),Pe=s=>{const e=S.useContext(it);if(s)return s;if(!e)throw new Error("No QueryClient set, use QueryClientProvider to set one");return e};function Tt(){}function Dt(s,e){const t=Pe(e),n=Q(s),i=$e(()=>[Ae()]),u=re(s.mutationKey??i.current),[a]=S.useState(()=>new kt(t,s));S.useEffect(()=>{a.setOptions(s)},[a,s]);const l=S.useMemo(()=>a.observe(),[u,a]),h=fe(l.result$)??l.lastValue,f=S.useCallback((o,b)=>{a.mutate(o,b).catch(Tt)},[a]);return S.useEffect(()=>()=>{n.current.cancelOnUnMount&&a.reset()},[a,n]),{...h,mutate:f,mutateAsync:h.mutate}}function Kt(s){return e=>e.pipe(K.tap(t=>{s.next(t)}))}const X=typeof window>"u"||"Deno"in window;class Nt{constructor(){g(this,"isOnlineSubject",new r.BehaviorSubject(!0));g(this,"online$",this.isOnlineSubject.pipe(r.distinctUntilChanged()));g(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(Kt(this.isOnlineSubject)).subscribe()}isOnline(){return this.isOnlineSubject.getValue()}setOnline(e){this.isOnlineSubject.getValue()!==e&&this.isOnlineSubject.next(e)}}const _=new Nt;function ke(s,e){return s.isStaleByTime(e.staleTime)}function qt(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 qt(s,e)||s.state.dataUpdatedAt>0&&at(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 Ht(s,e){return at(s,e,e.refetchOnWindowFocus)}function at(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 Wt(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 ut(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]=ut(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 Lt(s,e){return Math.max(s+(e??0)-Date.now(),0)}function _t(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?ut(s,e):e}const je=Symbol(),zt=({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 v=i.status==="pending"?"pending":a.status??i.status;return{...i,...a,status:v}}const l=a.data,h=l!==void 0&&l!==i.data,f="data"in a,o=a.status==="success",b=i.data!==void 0,E=i.error!==void 0||i.error!==null,d=a.status??i.status,p=h?Se(e().data,l,s()):f?a.data:i.data,m=i.status==="error"||i.status==="success",C=a.status==="error"&&(i.status==="error"&&i.fetchStatus==="fetching"||i.status!=="error")?i.errorUpdateCount+1:i.errorUpdateCount,$=h?i.dataUpdateCount+1:a.dataUpdateCount??i.dataUpdateCount,O=a.status==="pending"&&m&&(b||E),U=d==="pending"?null:a.error??i.error;return{...i,...a,status:d,error:U,errorUpdateCount:C,...o&&{isInvalidated:!1},data:p,dataUpdateCount:$,...O&&{status:i.status}}},t)),Bt=s=>s.pipe(r.map(({status:e,fetchStatus:t})=>t==="idle"&&(e==="success"||e==="error"))),ct=s=>s.pipe(r.takeWhile(e=>e.fetchStatus!=="idle",!0));var Oe,W;class Yt{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"));g(this,"focused$",c(this,W));g(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 Yt,Gt=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 ot{constructor(e,t){w(this,q);w(this,M);w(this,ie,new r.Subject);g(this,"queryUpdateSubject",new r.Subject);w(this,B);w(this,A);w(this,Z);w(this,ae,0);g(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",E=c(this,M),d=this.options,m=t!==E?t.state:c(this,B);let{errorUpdatedAt:C,fetchStatus:$,error:O}=o;if(n){const P=!!c(this,ae),Te=!P&&Le(t,e),mt=P&&_e(t,E,e,d);(Te||mt)&&($=Wt(t.options.networkMode)?"fetching":"paused")}const U=b&&$==="fetching";let v,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)v=f;else try{T=e.select,v=e.select(o.data),v=Se(i==null?void 0:i.data,v,e),D=v,y=null}catch(P){v=f,y=P}else v=o.data,y=null;let V=$!=="idle"&&!o.dataUpdatedAt?"pending":o.status;y&&(O=y,v=f,C=(i==null?void 0:i.errorUpdatedAt)??C,V="error");const de=V==="error";let pe=!1;if(typeof e.placeholderData<"u"&&typeof v>"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",v=Se(i==null?void 0:i.data,P,e),pe=!0)}const be=$==="fetching";return{result:{status:V,fetchStatus:$,isPending:b,isSuccess:V==="success",isError:de,isInitialLoading:U,isLoading:U,data:v,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>m.dataUpdateCount||o.errorUpdateCount>m.errorUpdateCount,isFetching:be,isRefetching:be&&!b,isLoadingError:de&&o.dataUpdatedAt===0,isPaused:$==="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 Jt(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(Gt,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)},E=f.pipe(r.switchMap(()=>a.state$),ct),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()),m=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])=>{Ht(a,y)&&this.fetch({cancelRefetch:!1}).catch(r.noop)}),r.ignoreElements()),$=m.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})),v=r.merge($,E,a.state$,o).pipe(O,r.distinctUntilChanged(x),r.distinctUntilChanged(b));return r.merge(d,C,v)})).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 Jt(s,e){return!x(s.getCurrentResult(),e)}const lt=we.createContext(!1),Xt=()=>we.useContext(lt);lt.Provider;function Zt(){let s=!1;return{clearReset:()=>{s=!1},reset:()=>{s=!0},isReset:()=>s}}const er=we.createContext(Zt()),tr=()=>we.useContext(er);function rr(s,e){return typeof s=="function"?s(...e):!!s}const sr=({result:s,errorResetBoundary:e,throwOnError:t,query:n})=>s.isError&&!e.isReset()&&!s.isFetching&&n&&rr(t,[s.error,n]);function ht(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=Xt(),u=tr(),a=n.defaultQueryOptions(s);a._optimisticResults=i?"isRestoring":"optimistic";const[l]=S.useState(()=>new e(n,a)),h=$e(()=>l.observe()),f=Q(l.getOptimisticResult(a)),o=f.current;fe(()=>h.current.pipe(r.filter(E=>!x(E,f.current))),[]),S.useEffect(()=>{l.setOptions(a)},[a,l]);const b=o.error;if(b&&sr({result:o,errorResetBoundary:u,throwOnError:a.throwOnError,query:n.getQueryCache().get(a.queryHash)}))throw b;return f.current}function nr(s,e){return ht(s,ot,e)}function ir(s,e){return ht({refetchOnMount:"idle",refetchOnReconnect:!1,refetchInterval:!1,refetchOnWindowFocus:!1,...s},ot,e)}function ar(s,e,t=[]){const n=e!=null&&!Array.isArray(e)?e:{},i=n.retry??!0,u=Q(n.onError??(h=>{console.error(h)})),a=S.useCallback(()=>R(s),t),l=S.useCallback(()=>a().pipe(r.catchError(h=>{throw u.current(h),h}),i?r.retry():r.identity),[a,i,u]);Fe(l,t)}const ft=()=>s=>r.merge(r.of({isPaused:!0}),_.backToOnline$.pipe(r.mergeMap(()=>r.merge(r.of({isPaused:!1}),s)))),ur=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(ft())))):r.throwError(()=>t))))},cr=({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,m)=>R(()=>{var $;return($=t.onError)==null?void 0:$.call(t,d,s,p)}).pipe(r.catchError(()=>r.of(d)),r.map(()=>({failureCount:m,error:d,failureReason:d,context:p,status:"error"}))),o=h.pipe(r.switchMap(d=>{const m=(typeof u=="function"?R(()=>u(s)):u).pipe(r.share()),C=m.pipe(r.isEmpty(),r.tap(O=>{if(O)throw new Error("Mutation completed without any emission (EMPTY)")}),r.ignoreElements()),$=r.merge(m,C).pipe(r.map(O=>({result:{data:O},error:null,context:d})),ur,Ue({...t,retry:(O,U)=>{const v=t.retry??0;return typeof v=="function"?v(O,U):typeof v=="boolean"?v:O<v},caughtError:(O,U)=>r.of({failureCount:O,failureReason:U}),catchError:(O,U)=>f(U,d,O).pipe(r.map(v=>({...v,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"?$:$.pipe(ft())})),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,...m})=>{if(!d&&!p)return r.of({...m});const C=p?r.of(null):R(()=>{var v;return(v=t.onSuccess)==null?void 0:v.call(t,d==null?void 0:d.data,s,m.context)}),O=R(()=>{var v;return(v=t.onSettled)==null?void 0:v.call(t,d==null?void 0:d.data,p,s,m.context)}).pipe(r.catchError(v=>d?r.of(d):r.of(v)));return r.concat(C,O).pipe(r.toArray(),r.map(()=>p?{error:p,data:void 0,variables:s,...m}:{status:"success",error:p,data:d==null?void 0:d.data,variables:s,failureCount:0,failureReason:null,...m}),r.catchError(v=>f(v,m.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 or{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);g(this,"state",J());g(this,"state$");g(this,"options");g(this,"observerCount$",c(this,ue).asObservable());g(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=>cr({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)}),E=R(()=>{var d,p;return(p=(d=this.options).onError)==null?void 0:p.call(d,h,f,o)});return r.concat(b,E).pipe(r.toArray())},onSettled:(h,f,o,b)=>{const E=R(()=>{var p,m;return(m=(p=t.config).onSettled)==null?void 0:m.call(p,h,f,o,b,this)}),d=R(()=>{var p,m;return(m=(p=this.options).onSettled)==null?void 0:m.call(p,h,f,o,b)});return r.concat(E,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)}),E=R(()=>{var d,p;return(p=(d=this.options).onSuccess)==null?void 0:p.call(d,h,f,o)});return r.concat(b,E).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),nt,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 dt{constructor(){g(this,"entriesSubject",new r.BehaviorSubject([]));g(this,"changeSubject",new r.Subject);g(this,"entries$",this.entriesSubject.pipe(r.share()));g(this,"added$",this.changeSubject.pipe(r.filter(({type:e})=>e==="added"),r.map(({entity:e})=>e),r.share()));g(this,"removed$",this.changeSubject.pipe(r.filter(({type:e})=>e==="removed"),r.map(({entity:e})=>e),r.share()));g(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 pt{constructor(e={}){w(this,k,new dt);this.config=e}build(e,t,n){const i=new or({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 lr(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 hr=s=>r.defer(()=>ve.isFocused()?s:ve.focusRegained$.pipe(r.mergeMap(()=>s))),fr=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))}},dr=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))},pr=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(dr(s.observers$),r.tap({complete:()=>{t=!0}}),r.map(o=>({data:o})),fr(s),Ue({...s,retryAfter:()=>r.of(!0).pipe(hr),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 br{constructor(e){g(this,"revert");g(this,"silent");this.revert=e==null?void 0:e.revert,this.silent=e==null?void 0:e.silent}}const gr={backgroundColor:"transparent",color:"inherit"};function bt(s){const e={namespaces:[{name:"@reactjrx",style:{backgroundColor:"#d02f4e",color:"white"}}],namespace(t,n){const i=bt();return i.namespaces.push({name:t,style:n??gr}),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 mr=bt();var ce,Y;class yr{constructor(e){g(this,"queryKey");g(this,"queryHash");g(this,"gcTime");g(this,"options");w(this,ce);w(this,Y);g(this,"state");g(this,"executeSubject",new r.Subject);g(this,"cancelSubject",new r.Subject);g(this,"setDataSubject",new r.Subject);g(this,"invalidatedSubject",new r.Subject);g(this,"resetSubject",new r.Subject);g(this,"destroySubject",new r.Subject);g(this,"observersSubject",new r.BehaviorSubject([]));g(this,"abortSignalConsumed",!1);g(this,"observerCount$",this.observersSubject.asObservable().pipe(r.map(e=>e.length)));g(this,"observers$",this.observersSubject.asObservable());g(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??lr(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 br(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}=pr({...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(zt({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 mr.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||!Lt(this.state.dataUpdatedAt,e)}async getFetchResultAsPromise(){return await new Promise((e,t)=>{this.state$.pipe(ct,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 gt{constructor(e={}){w(this,oe,new r.Subject);w(this,N,new dt);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 yr({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(Bt,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 Sr{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 pt),j(this,F,t??new gt),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=_t(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=pt;exports.QueryCache=gt;exports.QueryClient=Sr;exports.QueryClientProvider=It;exports.SIGNAL_RESET=Je;exports.arrayEqual=At;exports.createLocalStorageAdapter=et;exports.createLocalforageAdapter=Ct;exports.exponentialBackoffDelay=rt;exports.getDelay=tt;exports.isDefined=me;exports.retryBackoff=Ue;exports.signal=Xe;exports.useBehaviorSubject=xe;exports.useEffectOnce=st;exports.useForeverQuery=ir;exports.useLiveRef=Q;exports.useMount=Qt;exports.useMutation=Dt;exports.useObservableState=$t;exports.useObserve=fe;exports.useObserveCallback=wt;exports.usePersistSignals=xt;exports.useQuery=nr;exports.useQueryClient=Pe;exports.useSignal=Et;exports.useSignalValue=Ze;exports.useSubject=Re;exports.useSubscribe=Fe;exports.useSubscribeEffect=ar;exports.useUnmountObservable=Ut;
package/dist/index.js CHANGED
@@ -3,11 +3,11 @@ var bt = (s) => {
3
3
  throw TypeError(s);
4
4
  };
5
5
  var Bt = (s, e, t) => e in s ? Yt(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
6
- var g = (s, e, t) => Bt(s, typeof e != "symbol" ? e + "" : e, t), gt = (s, e, t) => e.has(s) || bt("Cannot " + t);
6
+ var b = (s, e, t) => Bt(s, typeof e != "symbol" ? e + "" : e, t), gt = (s, e, t) => e.has(s) || bt("Cannot " + t);
7
7
  var a = (s, e, t) => (gt(s, e, "read from private field"), t ? t.call(s) : e.get(s)), w = (s, e, t) => e.has(s) ? bt("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(s) : e.set(s, t), A = (s, e, t, r) => (gt(s, e, "write to private field"), r ? r.call(s, t) : e.set(s, t), t);
8
8
  import * as Ge from "react";
9
9
  import { useRef as me, useMemo as ut, useCallback as de, useSyncExternalStore as Xt, useEffect as Y, useState as at, createContext as Zt, memo as es, useContext as ts } from "react";
10
- import { distinctUntilChanged as U, tap as R, catchError as J, EMPTY as B, isObservable as mt, from as Se, of as v, defer as Ae, Subject as I, BehaviorSubject as X, skip as ot, 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 ct, interval as as, withLatestFrom as St, 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";
10
+ import { isObservable as mt, from as Se, of as v, defer as Ae, distinctUntilChanged as V, tap as R, catchError as J, EMPTY as B, Subject as I, BehaviorSubject as X, skip as ot, first as Je, map as y, 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 ct, interval as as, withLatestFrom as St, 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 vt, 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) => {
@@ -19,6 +19,19 @@ const H = (s) => {
19
19
  function Ss(s, e) {
20
20
  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;
21
21
  }
22
+ function Ot(s) {
23
+ return s instanceof Promise || s && typeof s.then == "function" && typeof s.catch == "function";
24
+ }
25
+ function U(s) {
26
+ if (mt(s)) return s;
27
+ if (Ot(s)) return Se(s);
28
+ if (typeof s != "function") return v(s);
29
+ const e = s;
30
+ return Ae(() => {
31
+ const t = e();
32
+ return Ot(t) ? Se(t) : mt(t) ? t : v(t);
33
+ });
34
+ }
22
35
  function Xe(s, e, t) {
23
36
  const r = e != null && !Array.isArray(e) ? e : {
24
37
  defaultValue: void 0,
@@ -27,21 +40,21 @@ function Xe(s, e, t) {
27
40
  "getValue" in s && typeof s.getValue == "function" ? s.getValue() : r.defaultValue
28
41
  ), i = H(s), c = H(r), l = de(
29
42
  (p) => {
30
- const F = i.current, f = (typeof F == "function" ? F : () => F)().pipe(
43
+ const E = i.current, d = U(E).pipe(
31
44
  /**
32
45
  * @important
33
46
  * We only check primitives because underlying subscription might
34
47
  * be using objects and keeping same reference but pushing new
35
48
  * properties values
36
49
  */
37
- U(Ss),
38
- R((y) => {
39
- u.current = y;
50
+ V(Ss),
51
+ R((f) => {
52
+ u.current = f;
40
53
  }),
41
- J((y) => (console.error(y), B))
54
+ J((f) => (console.error(f), B))
42
55
  ).subscribe(p);
43
56
  return () => {
44
- c.current.unsubscribeOnUnmount !== !1 && f.unsubscribe();
57
+ c.current.unsubscribeOnUnmount !== !1 && d.unsubscribe();
45
58
  };
46
59
  },
47
60
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -49,23 +62,10 @@ function Xe(s, e, t) {
49
62
  ), h = de(() => u.current, []);
50
63
  return Xt(l, h, h);
51
64
  }
52
- function Ot(s) {
53
- return s instanceof Promise || s && typeof s.then == "function" && typeof s.catch == "function";
54
- }
55
- function V(s) {
56
- if (mt(s)) return s;
57
- if (Ot(s)) return Se(s);
58
- if (typeof s != "function") return v(s);
59
- const e = s;
60
- return Ae(() => {
61
- const t = e();
62
- return Ot(t) ? Se(t) : mt(t) ? t : v(t);
63
- });
64
- }
65
65
  function Ut(s, e = []) {
66
66
  const t = H(s);
67
67
  Y(() => {
68
- const r = V(t.current).pipe(
68
+ const r = U(t.current).pipe(
69
69
  J((n) => (console.error(n), B))
70
70
  ).subscribe();
71
71
  return () => {
@@ -158,8 +158,8 @@ function $s(s, e) {
158
158
  const r = e ?? (() => s.getValue());
159
159
  return Xe(
160
160
  () => s.subject.pipe(
161
- b((u) => r(u)),
162
- U()
161
+ y((u) => r(u)),
162
+ V()
163
163
  ),
164
164
  {
165
165
  defaultValue: r(s.getValue())
@@ -281,7 +281,7 @@ function $r({
281
281
  config: p
282
282
  })
283
283
  )
284
- ).pipe(b(() => !0))).pipe(
284
+ ).pipe(y(() => !0))).pipe(
285
285
  R(() => {
286
286
  n.current != null && n.current();
287
287
  }),
@@ -351,46 +351,46 @@ function Pt(s) {
351
351
  resetOnSuccess: o = !1,
352
352
  backoffDelay: p = js
353
353
  } = l;
354
- return (F) => Ae(() => {
354
+ return (E) => Ae(() => {
355
355
  let d = 0;
356
- const f = (y, x) => y < u ? i(y, x) : !1;
357
- return F.pipe(
358
- vt((y) => {
359
- var E;
360
- if (d++, !f(d - 1, y)) throw y;
361
- const x = (E = s.caughtError) == null ? void 0 : E.call(s, d, y);
362
- if (!x) throw y;
356
+ const f = (g, x) => g < u ? i(g, x) : !1;
357
+ return E.pipe(
358
+ vt((g) => {
359
+ var F;
360
+ if (d++, !f(d - 1, g)) throw g;
361
+ const x = (F = s.caughtError) == null ? void 0 : F.call(s, d, g);
362
+ if (!x) throw g;
363
363
  return x.pipe(
364
364
  tt(
365
365
  ($) => C(
366
366
  v($),
367
- Oe(() => y)
367
+ Oe(() => g)
368
368
  )
369
369
  )
370
370
  );
371
371
  }),
372
- ps((y) => y.pipe(
372
+ ps((g) => g.pipe(
373
373
  ys((x) => {
374
- const E = d - 1;
374
+ const F = d - 1;
375
375
  return n().pipe(
376
376
  bs(),
377
377
  tt(
378
- () => f(E, x) ? Qe(
378
+ () => f(F, x) ? Qe(
379
379
  Rs(
380
- p(E, c),
380
+ p(F, c),
381
381
  h
382
382
  )
383
383
  ).pipe(
384
- tt(($) => r && !r(E, x) ? Oe(() => x) : v($))
384
+ tt(($) => r && !r(F, x) ? Oe(() => x) : v($))
385
385
  ) : Oe(() => x)
386
386
  )
387
387
  );
388
388
  })
389
389
  )),
390
- vt((y) => {
390
+ vt((g) => {
391
391
  if (s.catchError)
392
- return s.catchError(d, y);
393
- throw y;
392
+ return s.catchError(d, g);
393
+ throw g;
394
394
  }),
395
395
  Qt(() => {
396
396
  o && (d = 0);
@@ -455,7 +455,7 @@ class As {
455
455
  __queryFinalizeHook: e
456
456
  } = {}) {
457
457
  w(this, ee, new I());
458
- g(this, "state$");
458
+ b(this, "state$");
459
459
  const t = new X(0), r = t.pipe(
460
460
  O((n) => n === 0)
461
461
  );
@@ -473,7 +473,7 @@ class As {
473
473
  Ke(),
474
474
  q(() => u.state$),
475
475
  ne(a(this, ee))
476
- ), F = u.state$.pipe(
476
+ ), E = u.state$.pipe(
477
477
  we,
478
478
  ot(1)
479
479
  ), d = C(
@@ -483,7 +483,7 @@ class As {
483
483
  u.cancelled$
484
484
  );
485
485
  return C(
486
- F,
486
+ E,
487
487
  p,
488
488
  /**
489
489
  * We defer execution so that we return at least
@@ -491,7 +491,7 @@ class As {
491
491
  */
492
492
  o
493
493
  ).pipe(
494
- b((f) => ({ state: f, mutation: u })),
494
+ y((f) => ({ state: f, mutation: u })),
495
495
  e ?? Mt,
496
496
  ne(d)
497
497
  );
@@ -532,7 +532,7 @@ function P(s, e) {
532
532
  return !0;
533
533
  }
534
534
  const Dt = (s) => s.pipe(
535
- U(
535
+ V(
536
536
  ({ data: e, ...t }, { data: r, ...n }) => P(t, n) && P(e, r)
537
537
  )
538
538
  );
@@ -547,8 +547,8 @@ class Qs {
547
547
  * - mutation does not get garbage collected
548
548
  * - mutation mutate options are run on finish
549
549
  */
550
- g(this, "observed$");
551
- g(this, "getObserverResultFromState", (e) => ({
550
+ b(this, "observed$");
551
+ b(this, "getObserverResultFromState", (e) => ({
552
552
  ...fe(),
553
553
  ...e,
554
554
  isSuccess: e.status === "success",
@@ -573,7 +573,7 @@ class Qs {
573
573
  ).subscribe(), this.observed$ = a(this, L).pipe(
574
574
  j((u) => (u == null ? void 0 : u.mutation.state$.pipe(
575
575
  // last(),
576
- b((i) => ({
576
+ y((i) => ({
577
577
  state: i,
578
578
  options: u.options
579
579
  }))
@@ -619,10 +619,10 @@ class Qs {
619
619
  const e = this.getObserverResultFromState(
620
620
  ((u = a(this, L).getValue()) == null ? void 0 : u.mutation.state) ?? fe()
621
621
  ), t = a(this, ae).state$.pipe(
622
- U(
622
+ V(
623
623
  ({ mutation: i, state: { data: c, ...l } }, { mutation: h, state: { data: o, ...p } }) => i === h && P(l, p) && P(c, o)
624
624
  ),
625
- b(({ state: i }) => i),
625
+ y(({ state: i }) => i),
626
626
  Be((i, c) => ({
627
627
  ...i,
628
628
  ...c,
@@ -633,11 +633,11 @@ class Qs {
633
633
  error: c.error ?? i.error
634
634
  }
635
635
  })),
636
- b((i) => this.getObserverResultFromState(i))
636
+ y((i) => this.getObserverResultFromState(i))
637
637
  ), r = a(this, L).pipe(
638
638
  O(rt),
639
639
  j((i) => i.mutation.cancelled$),
640
- b(() => this.getObserverResultFromState(fe()))
640
+ y(() => this.getObserverResultFromState(fe()))
641
641
  );
642
642
  return { result$: C(
643
643
  this.observed$,
@@ -737,15 +737,15 @@ function Is(s) {
737
737
  const pe = typeof window > "u" || "Deno" in window;
738
738
  class Ps {
739
739
  constructor() {
740
- g(this, "isOnlineSubject", new X(!0));
741
- g(this, "online$", this.isOnlineSubject.pipe(U()));
742
- g(this, "backToOnline$", this.online$.pipe(
740
+ b(this, "isOnlineSubject", new X(!0));
741
+ b(this, "online$", this.isOnlineSubject.pipe(V()));
742
+ b(this, "backToOnline$", this.online$.pipe(
743
743
  O((e) => e),
744
744
  Je()
745
745
  ));
746
746
  C(
747
- pe ? B : Ne(window, "offline").pipe(b(() => !1)),
748
- pe ? B : Ne(window, "online").pipe(b(() => !0))
747
+ pe ? B : Ne(window, "offline").pipe(y(() => !1)),
748
+ pe ? B : Ne(window, "online").pipe(y(() => !0))
749
749
  ).pipe(Is(this.isOnlineSubject)).subscribe();
750
750
  }
751
751
  isOnline() {
@@ -851,8 +851,8 @@ const it = Symbol(), qs = ({
851
851
  const S = n.status === "pending" ? "pending" : i.status ?? n.status;
852
852
  return { ...n, ...i, status: S };
853
853
  }
854
- const c = i.data, l = c !== void 0 && c !== n.data, h = "data" in i, o = i.status === "success", p = n.data !== void 0, F = n.error !== void 0 || n.error !== null, d = i.status ?? n.status, f = l ? Le(e().data, c, s()) : h ? i.data : n.data, y = n.status === "error" || n.status === "success", x = i.status === "error" && (n.status === "error" && n.fetchStatus === "fetching" || n.status !== "error") ? n.errorUpdateCount + 1 : n.errorUpdateCount, E = l ? n.dataUpdateCount + 1 : i.dataUpdateCount ?? n.dataUpdateCount, $ = i.status === "pending" && y && // (dataUpdateCount !== 0 || errorUpdateCount !== 0)
855
- (p || F), D = d === "pending" ? null : i.error ?? n.error;
854
+ const c = i.data, l = c !== void 0 && c !== n.data, h = "data" in i, o = i.status === "success", p = n.data !== void 0, E = n.error !== void 0 || n.error !== null, d = i.status ?? n.status, f = l ? Le(e().data, c, s()) : h ? i.data : n.data, g = n.status === "error" || n.status === "success", x = i.status === "error" && (n.status === "error" && n.fetchStatus === "fetching" || n.status !== "error") ? n.errorUpdateCount + 1 : n.errorUpdateCount, F = l ? n.dataUpdateCount + 1 : i.dataUpdateCount ?? n.dataUpdateCount, $ = i.status === "pending" && g && // (dataUpdateCount !== 0 || errorUpdateCount !== 0)
855
+ (p || E), D = d === "pending" ? null : i.error ?? n.error;
856
856
  return {
857
857
  ...n,
858
858
  ...i,
@@ -863,14 +863,14 @@ const it = Symbol(), qs = ({
863
863
  isInvalidated: !1
864
864
  },
865
865
  data: f,
866
- dataUpdateCount: E,
866
+ dataUpdateCount: F,
867
867
  ...$ && {
868
868
  status: n.status
869
869
  }
870
870
  };
871
871
  }, t)
872
872
  ), Hs = (s) => s.pipe(
873
- b(
873
+ y(
874
874
  ({ status: e, fetchStatus: t }) => t === "idle" && (e === "success" || e === "error")
875
875
  )
876
876
  ), qt = (s) => s.pipe(
@@ -882,13 +882,13 @@ class _s {
882
882
  w(this, We, C(
883
883
  pe ? B : Ne(document, "visibilitychange"),
884
884
  pe ? B : Ne(window, "visibilitychange")
885
- ).pipe(b(() => document.visibilityState)));
885
+ ).pipe(y(() => document.visibilityState)));
886
886
  w(this, te, new X(
887
887
  pe ? !0 : document.visibilityState === "visible"
888
888
  ));
889
889
  // public readonly focused$ = this.#focusedSubject.pipe(distinctUntilChanged())
890
- g(this, "focused$", a(this, te));
891
- g(this, "focusRegained$", this.focused$.pipe(
890
+ b(this, "focused$", a(this, te));
891
+ b(this, "focusRegained$", this.focused$.pipe(
892
892
  ot(1),
893
893
  O((e) => e)
894
894
  ));
@@ -924,12 +924,12 @@ class _s {
924
924
  We = new WeakMap(), te = new WeakMap();
925
925
  const ze = new _s(), Ls = (s) => s.pipe(
926
926
  O((e) => e.status === "success"),
927
- b((e) => ({
927
+ y((e) => ({
928
928
  data: e.data,
929
929
  status: e.status,
930
930
  dataUpdatedAt: e.dataUpdatedAt
931
931
  })),
932
- U(P)
932
+ V(P)
933
933
  );
934
934
  var Z, M, Ce, oe, T, ye, Fe;
935
935
  class Ht {
@@ -942,7 +942,7 @@ class Ht {
942
942
  * We need to be able to track change to both of them at the same time
943
943
  * in order to react accordingly and in order (such as refetch on options change)
944
944
  */
945
- g(this, "queryUpdateSubject", new I());
945
+ b(this, "queryUpdateSubject", new I());
946
946
  /**
947
947
  * Mostly used to compare the state before and after mount
948
948
  */
@@ -956,7 +956,7 @@ class Ht {
956
956
  // It will be used to pass the previous data and query to the placeholder function between renders.
957
957
  w(this, ye);
958
958
  w(this, Fe, 0);
959
- g(this, "getObserverResultFromQuery", ({
959
+ b(this, "getObserverResultFromQuery", ({
960
960
  options: e,
961
961
  query: t,
962
962
  optimisticResult: r,
@@ -970,13 +970,13 @@ class Ht {
970
970
  }
971
971
  }) => {
972
972
  var De;
973
- const o = t.state, p = t.state.status === "pending", F = a(this, M), d = this.options, y = t !== F ? t.state : a(this, oe);
974
- let { errorUpdatedAt: x, fetchStatus: E, error: $ } = o;
973
+ const o = t.state, p = t.state.status === "pending", E = a(this, M), d = this.options, g = t !== E ? t.state : a(this, oe);
974
+ let { errorUpdatedAt: x, fetchStatus: F, error: $ } = o;
975
975
  if (r) {
976
- const k = !!a(this, Fe), yt = !k && Ct(t, e), Jt = k && Ft(t, F, e, d);
977
- (yt || Jt) && (E = ks(t.options.networkMode) ? "fetching" : "paused");
976
+ const k = !!a(this, Fe), yt = !k && Ct(t, e), Jt = k && Ft(t, E, e, d);
977
+ (yt || Jt) && (F = ks(t.options.networkMode) ? "fetching" : "paused");
978
978
  }
979
- const D = p && E === "fetching";
979
+ const D = p && F === "fetching";
980
980
  let S, m = l, z = c ?? null, W = h;
981
981
  if (e.select && typeof o.data < "u")
982
982
  if (n && o.data === (i == null ? void 0 : i.data) && e.select === c)
@@ -989,7 +989,7 @@ class Ht {
989
989
  }
990
990
  else
991
991
  S = o.data, m = null;
992
- let _ = E !== "idle" && !o.dataUpdatedAt ? "pending" : o.status;
992
+ let _ = F !== "idle" && !o.dataUpdatedAt ? "pending" : o.status;
993
993
  m && ($ = m, S = h, x = (n == null ? void 0 : n.errorUpdatedAt) ?? x, _ = "error");
994
994
  const Ve = _ === "error";
995
995
  let Ie = !1;
@@ -1011,11 +1011,11 @@ class Ht {
1011
1011
  e
1012
1012
  ), Ie = !0);
1013
1013
  }
1014
- const Pe = E === "fetching";
1014
+ const Pe = F === "fetching";
1015
1015
  return {
1016
1016
  result: {
1017
1017
  status: _,
1018
- fetchStatus: E,
1018
+ fetchStatus: F,
1019
1019
  isPending: p,
1020
1020
  isSuccess: _ === "success",
1021
1021
  isError: Ve,
@@ -1029,11 +1029,11 @@ class Ht {
1029
1029
  failureReason: o.fetchFailureReason,
1030
1030
  errorUpdateCount: o.errorUpdateCount,
1031
1031
  isFetched: o.dataUpdateCount > 0 || o.errorUpdateCount > 0,
1032
- isFetchedAfterMount: o.dataUpdateCount > y.dataUpdateCount || o.errorUpdateCount > y.errorUpdateCount,
1032
+ isFetchedAfterMount: o.dataUpdateCount > g.dataUpdateCount || o.errorUpdateCount > g.errorUpdateCount,
1033
1033
  isFetching: Pe,
1034
1034
  isRefetching: Pe && !p,
1035
1035
  isLoadingError: Ve && o.dataUpdatedAt === 0,
1036
- isPaused: E === "paused",
1036
+ isPaused: F === "paused",
1037
1037
  isPlaceholderData: Ie,
1038
1038
  isRefetchError: Ve && o.dataUpdatedAt !== 0,
1039
1039
  isStale: dt(t, e),
@@ -1152,9 +1152,9 @@ class Ht {
1152
1152
  }
1153
1153
  observe() {
1154
1154
  const e = a(this, M), t = this.queryUpdateSubject.pipe(
1155
- b(({ query: i }) => i),
1155
+ y(({ query: i }) => i),
1156
1156
  he(a(this, M)),
1157
- U()
1157
+ V()
1158
1158
  ), r = this.queryUpdateSubject.pipe(
1159
1159
  he({
1160
1160
  query: a(this, M),
@@ -1183,8 +1183,8 @@ class Ht {
1183
1183
  const c = this.options, l = this.queryUpdateSubject.pipe(
1184
1184
  he({ query: i, options: c }),
1185
1185
  O((m) => m.query === i),
1186
- b((m) => m.options),
1187
- U(),
1186
+ y((m) => m.options),
1187
+ V(),
1188
1188
  Ue(1)
1189
1189
  ), h = a(this, Ce).pipe(
1190
1190
  O((m) => m.query === i)
@@ -1206,15 +1206,15 @@ class Ht {
1206
1206
  );
1207
1207
  return P(pt, De);
1208
1208
  } : P)(m, z);
1209
- }, F = h.pipe(
1209
+ }, E = h.pipe(
1210
1210
  j(() => i.state$),
1211
1211
  qt
1212
1212
  ), d = l.pipe(
1213
- b(({ refetchInterval: m, refetchIntervalInBackground: z }) => ({
1213
+ y(({ refetchInterval: m, refetchIntervalInBackground: z }) => ({
1214
1214
  refetchInterval: (typeof m == "function" ? m(a(this, M)) : m) ?? !1,
1215
1215
  refetchIntervalInBackground: z
1216
1216
  })),
1217
- U(P),
1217
+ V(P),
1218
1218
  j(({ refetchInterval: m, refetchIntervalInBackground: z }) => m ? as(m).pipe(
1219
1219
  R(() => {
1220
1220
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
@@ -1223,11 +1223,11 @@ class Ht {
1223
1223
  ) : qe),
1224
1224
  ie()
1225
1225
  ), f = l.pipe(
1226
- b(({ enabled: m }) => m ?? !0),
1227
- U()
1228
- ), y = f.pipe(
1226
+ y(({ enabled: m }) => m ?? !0),
1227
+ V()
1228
+ ), g = f.pipe(
1229
1229
  O((m) => !m),
1230
- b(() => i.state)
1230
+ y(() => i.state)
1231
1231
  ), x = f.pipe(
1232
1232
  O((m) => m),
1233
1233
  j(() => ze.focusRegained$),
@@ -1236,11 +1236,11 @@ class Ht {
1236
1236
  Ts(i, m) && this.fetch({ cancelRefetch: !1 }).catch(N);
1237
1237
  }),
1238
1238
  ie()
1239
- ), E = y.pipe(
1240
- b(() => i.state)
1239
+ ), F = g.pipe(
1240
+ y(() => i.state)
1241
1241
  ), $ = (m) => m.pipe(
1242
1242
  St(l),
1243
- b(([, z]) => {
1243
+ y(([, z]) => {
1244
1244
  const W = this.getObserverResultFromQuery({
1245
1245
  query: i,
1246
1246
  options: z,
@@ -1249,17 +1249,17 @@ class Ht {
1249
1249
  return this.updateResult({ query: i, ...W }), W.result;
1250
1250
  })
1251
1251
  ), S = C(
1252
- E,
1253
1252
  F,
1253
+ E,
1254
1254
  i.state$,
1255
1255
  // options$,
1256
1256
  o
1257
1257
  ).pipe(
1258
1258
  $,
1259
1259
  // This one ensure we don't re-trigger same state
1260
- U(P),
1260
+ V(P),
1261
1261
  // This one make sure we dispatch based on user preference
1262
- U(p)
1262
+ V(p)
1263
1263
  );
1264
1264
  return C(d, x, S);
1265
1265
  })
@@ -1326,7 +1326,7 @@ function Lt(s, e, t) {
1326
1326
  * It's important to not skip the first result (even tho most of the time they are equal).
1327
1327
  * We only skip if they are the same.
1328
1328
  */
1329
- O((F) => !P(F, h.current))
1329
+ O((E) => !P(E, h.current))
1330
1330
  ),
1331
1331
  []
1332
1332
  ), Y(() => {
@@ -1363,7 +1363,7 @@ function Mr(s, e, t = []) {
1363
1363
  r.onError ?? ((l) => {
1364
1364
  console.error(l);
1365
1365
  })
1366
- ), i = de(() => V(s), t), c = de(
1366
+ ), i = de(() => U(s), t), c = de(
1367
1367
  () => i().pipe(
1368
1368
  J((l) => {
1369
1369
  throw u.current(l), l;
@@ -1409,7 +1409,7 @@ const zt = () => (s) => C(
1409
1409
  state: e,
1410
1410
  options: t
1411
1411
  }) => {
1412
- const r = e.isPaused, n = async () => await Promise.reject(new Error("No mutationFn found")), u = t.mutationFn ?? n, i = V(
1412
+ const r = e.isPaused, n = async () => await Promise.reject(new Error("No mutationFn found")), u = t.mutationFn ?? n, i = U(
1413
1413
  // eslint-disable-next-line @typescript-eslint/promise-function-async
1414
1414
  () => {
1415
1415
  var d;
@@ -1417,16 +1417,16 @@ const zt = () => (s) => C(
1417
1417
  }
1418
1418
  ), c = v(e.context), l = cs(() => r, c, i).pipe(
1419
1419
  Ue(1)
1420
- ), h = (d, f, y) => V(
1420
+ ), h = (d, f, g) => U(
1421
1421
  () => {
1422
- var E;
1423
- return (E = t.onError) == null ? void 0 : E.call(t, d, s, f);
1422
+ var F;
1423
+ return (F = t.onError) == null ? void 0 : F.call(t, d, s, f);
1424
1424
  }
1425
1425
  ).pipe(
1426
1426
  J(() => v(d)),
1427
- b(
1427
+ y(
1428
1428
  () => ({
1429
- failureCount: y,
1429
+ failureCount: g,
1430
1430
  error: d,
1431
1431
  failureReason: d,
1432
1432
  context: f,
@@ -1435,18 +1435,18 @@ const zt = () => (s) => C(
1435
1435
  )
1436
1436
  ), o = l.pipe(
1437
1437
  j((d) => {
1438
- const y = (typeof u == "function" ? (
1438
+ const g = (typeof u == "function" ? (
1439
1439
  // eslint-disable-next-line @typescript-eslint/promise-function-async
1440
- V(() => u(s))
1441
- ) : u).pipe(ue()), x = y.pipe(
1440
+ U(() => u(s))
1441
+ ) : u).pipe(ue()), x = g.pipe(
1442
1442
  ls(),
1443
1443
  R(($) => {
1444
1444
  if ($)
1445
1445
  throw new Error("Mutation completed without any emission (EMPTY)");
1446
1446
  }),
1447
1447
  ie()
1448
- ), E = C(y, x).pipe(
1449
- b(
1448
+ ), F = C(g, x).pipe(
1449
+ y(
1450
1450
  ($) => ({
1451
1451
  result: {
1452
1452
  data: $
@@ -1470,7 +1470,7 @@ const zt = () => (s) => C(
1470
1470
  })
1471
1471
  ),
1472
1472
  catchError: ($, D) => h(D, d, $).pipe(
1473
- b((S) => ({
1473
+ y((S) => ({
1474
1474
  ...S,
1475
1475
  result: void 0
1476
1476
  }))
@@ -1481,7 +1481,7 @@ const zt = () => (s) => C(
1481
1481
  !0
1482
1482
  )
1483
1483
  );
1484
- return re.isOnline() || t.networkMode === "offlineFirst" || t.networkMode === "always" ? E : E.pipe(zt());
1484
+ return re.isOnline() || t.networkMode === "offlineFirst" || t.networkMode === "always" ? F : F.pipe(zt());
1485
1485
  })
1486
1486
  ), p = v({
1487
1487
  ...e,
@@ -1495,24 +1495,24 @@ const zt = () => (s) => C(
1495
1495
  return C(
1496
1496
  p,
1497
1497
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1498
- l.pipe(b((d) => ({ context: d }))),
1498
+ l.pipe(y((d) => ({ context: d }))),
1499
1499
  o.pipe(
1500
- j(({ result: d, error: f, ...y }) => {
1500
+ j(({ result: d, error: f, ...g }) => {
1501
1501
  if (!d && !f)
1502
1502
  return v({
1503
- ...y
1503
+ ...g
1504
1504
  });
1505
- const x = f ? v(null) : V(
1505
+ const x = f ? v(null) : U(
1506
1506
  () => {
1507
1507
  var S;
1508
1508
  return (S = t.onSuccess) == null ? void 0 : S.call(
1509
1509
  t,
1510
1510
  d == null ? void 0 : d.data,
1511
1511
  s,
1512
- y.context
1512
+ g.context
1513
1513
  );
1514
1514
  }
1515
- ), $ = V(
1515
+ ), $ = U(
1516
1516
  () => {
1517
1517
  var S;
1518
1518
  return (S = t.onSettled) == null ? void 0 : S.call(
@@ -1520,7 +1520,7 @@ const zt = () => (s) => C(
1520
1520
  d == null ? void 0 : d.data,
1521
1521
  f,
1522
1522
  s,
1523
- y.context
1523
+ g.context
1524
1524
  );
1525
1525
  }
1526
1526
  ).pipe(
@@ -1528,12 +1528,12 @@ const zt = () => (s) => C(
1528
1528
  );
1529
1529
  return Te(x, $).pipe(
1530
1530
  ke(),
1531
- b(
1531
+ y(
1532
1532
  () => f ? {
1533
1533
  error: f,
1534
1534
  data: void 0,
1535
1535
  variables: s,
1536
- ...y
1536
+ ...g
1537
1537
  } : {
1538
1538
  status: "success",
1539
1539
  error: f,
@@ -1541,12 +1541,12 @@ const zt = () => (s) => C(
1541
1541
  variables: s,
1542
1542
  failureCount: 0,
1543
1543
  failureReason: null,
1544
- ...y
1544
+ ...g
1545
1545
  }
1546
1546
  ),
1547
1547
  J(
1548
- (S) => h(S, y.context, 0).pipe(
1549
- b((m) => ({
1548
+ (S) => h(S, g.context, 0).pipe(
1549
+ y((m) => ({
1550
1550
  ...m,
1551
1551
  data: void 0
1552
1552
  }))
@@ -1574,15 +1574,15 @@ class tr {
1574
1574
  w(this, Ee, new X(0));
1575
1575
  w(this, se, new I());
1576
1576
  w(this, be, new I());
1577
- g(this, "state", fe());
1578
- g(this, "state$");
1579
- g(this, "options");
1580
- g(this, "observerCount$", a(this, Ee).asObservable());
1581
- g(this, "cancelled$", a(this, se).asObservable());
1577
+ b(this, "state", fe());
1578
+ b(this, "state$");
1579
+ b(this, "options");
1580
+ b(this, "observerCount$", a(this, Ee).asObservable());
1581
+ b(this, "cancelled$", a(this, se).asObservable());
1582
1582
  this.options = e, this.state = r ?? this.state;
1583
1583
  const n = a(this, se).pipe(
1584
1584
  O(() => this.state.status === "pending"),
1585
- b(() => ({
1585
+ y(() => ({
1586
1586
  status: "idle"
1587
1587
  }))
1588
1588
  ), u = a(this, be).pipe(
@@ -1591,7 +1591,7 @@ class tr {
1591
1591
  options: {
1592
1592
  ...this.options,
1593
1593
  onMutate: (l) => {
1594
- const h = V(
1594
+ const h = U(
1595
1595
  () => {
1596
1596
  var d, f;
1597
1597
  return (f = (d = t.config).onMutate) == null ? void 0 : f.call(
@@ -1600,7 +1600,7 @@ class tr {
1600
1600
  this
1601
1601
  );
1602
1602
  }
1603
- ), p = V(() => {
1603
+ ), p = U(() => {
1604
1604
  var d, f;
1605
1605
  return (f = (d = this.options).onMutate) == null ? void 0 : f.call(d, l);
1606
1606
  });
@@ -1609,7 +1609,7 @@ class tr {
1609
1609
  );
1610
1610
  },
1611
1611
  onError: (l, h, o) => {
1612
- const p = V(
1612
+ const p = U(
1613
1613
  () => {
1614
1614
  var d, f;
1615
1615
  return (f = (d = t.config).onError) == null ? void 0 : f.call(
@@ -1620,19 +1620,19 @@ class tr {
1620
1620
  this
1621
1621
  );
1622
1622
  }
1623
- ), F = V(
1623
+ ), E = U(
1624
1624
  () => {
1625
1625
  var d, f;
1626
1626
  return (f = (d = this.options).onError) == null ? void 0 : f.call(d, l, h, o);
1627
1627
  }
1628
1628
  );
1629
- return Te(p, F).pipe(ke());
1629
+ return Te(p, E).pipe(ke());
1630
1630
  },
1631
1631
  onSettled: (l, h, o, p) => {
1632
- const F = V(
1632
+ const E = U(
1633
1633
  () => {
1634
- var f, y;
1635
- return (y = (f = t.config).onSettled) == null ? void 0 : y.call(
1634
+ var f, g;
1635
+ return (g = (f = t.config).onSettled) == null ? void 0 : g.call(
1636
1636
  f,
1637
1637
  l,
1638
1638
  h,
@@ -1641,16 +1641,16 @@ class tr {
1641
1641
  this
1642
1642
  );
1643
1643
  }
1644
- ), d = V(
1644
+ ), d = U(
1645
1645
  () => {
1646
- var f, y;
1647
- return (y = (f = this.options).onSettled) == null ? void 0 : y.call(f, l, h, o, p);
1646
+ var f, g;
1647
+ return (g = (f = this.options).onSettled) == null ? void 0 : g.call(f, l, h, o, p);
1648
1648
  }
1649
1649
  );
1650
- return Te(F, d).pipe(ke());
1650
+ return Te(E, d).pipe(ke());
1651
1651
  },
1652
1652
  onSuccess: (l, h, o) => {
1653
- const p = V(
1653
+ const p = U(
1654
1654
  () => {
1655
1655
  var d, f;
1656
1656
  return (f = (d = t.config).onSuccess) == null ? void 0 : f.call(
@@ -1661,13 +1661,13 @@ class tr {
1661
1661
  this
1662
1662
  );
1663
1663
  }
1664
- ), F = V(
1664
+ ), E = U(
1665
1665
  () => {
1666
1666
  var d, f;
1667
1667
  return (f = (d = this.options).onSuccess) == null ? void 0 : f.call(d, l, h, o);
1668
1668
  }
1669
1669
  );
1670
- return Te(p, F).pipe(ke());
1670
+ return Te(p, E).pipe(ke());
1671
1671
  }
1672
1672
  },
1673
1673
  state: this.state,
@@ -1733,20 +1733,20 @@ class Wt {
1733
1733
  * @important
1734
1734
  * Query store. Could be turned into a map for more performance.
1735
1735
  */
1736
- g(this, "entriesSubject", new X([]));
1737
- g(this, "changeSubject", new I());
1738
- g(this, "entries$", this.entriesSubject.pipe(ue()));
1739
- g(this, "added$", this.changeSubject.pipe(
1736
+ b(this, "entriesSubject", new X([]));
1737
+ b(this, "changeSubject", new I());
1738
+ b(this, "entries$", this.entriesSubject.pipe(ue()));
1739
+ b(this, "added$", this.changeSubject.pipe(
1740
1740
  O(({ type: e }) => e === "added"),
1741
- b(({ entity: e }) => e),
1741
+ y(({ entity: e }) => e),
1742
1742
  ue()
1743
1743
  ));
1744
- g(this, "removed$", this.changeSubject.pipe(
1744
+ b(this, "removed$", this.changeSubject.pipe(
1745
1745
  O(({ type: e }) => e === "removed"),
1746
- b(({ entity: e }) => e),
1746
+ y(({ entity: e }) => e),
1747
1747
  ue()
1748
1748
  ));
1749
- g(this, "stateChange$", C(
1749
+ b(this, "stateChange$", C(
1750
1750
  this.entriesSubject.pipe(
1751
1751
  Je(),
1752
1752
  q((e) => Se(e))
@@ -1755,7 +1755,7 @@ class Wt {
1755
1755
  ).pipe(
1756
1756
  q(
1757
1757
  (e) => e.state$.pipe(
1758
- b(() => e),
1758
+ y(() => e),
1759
1759
  ne(
1760
1760
  this.removed$.pipe(
1761
1761
  O((t) => t === e)
@@ -1956,7 +1956,7 @@ const nr = (s) => Ae(() => ze.isFocused() ? s : ze.focusRegained$.pipe(q(() => s
1956
1956
  })(u);
1957
1957
  const l = (typeof r == "function" ? (
1958
1958
  // eslint-disable-next-line @typescript-eslint/promise-function-async
1959
- V(
1959
+ U(
1960
1960
  () => r(u)
1961
1961
  )
1962
1962
  ) : r).pipe(
@@ -1966,7 +1966,7 @@ const nr = (s) => Ae(() => ze.isFocused() ? s : ze.focusRegained$.pipe(q(() => s
1966
1966
  t = !0;
1967
1967
  }
1968
1968
  }),
1969
- b(
1969
+ y(
1970
1970
  (o) => ({
1971
1971
  data: o
1972
1972
  })
@@ -2015,7 +2015,7 @@ const nr = (s) => Ae(() => ze.isFocused() ? s : ze.focusRegained$.pipe(q(() => s
2015
2015
  * There is in theory no problem associated to that.
2016
2016
  */
2017
2017
  ct(1),
2018
- b(
2018
+ y(
2019
2019
  (p) => t ? p : { ...p, fetchStatus: "fetching" }
2020
2020
  )
2021
2021
  ) : v(o)),
@@ -2041,8 +2041,8 @@ const nr = (s) => Ae(() => ze.isFocused() ? s : ze.focusRegained$.pipe(q(() => s
2041
2041
  };
2042
2042
  class or {
2043
2043
  constructor(e) {
2044
- g(this, "revert");
2045
- g(this, "silent");
2044
+ b(this, "revert");
2045
+ b(this, "silent");
2046
2046
  this.revert = e == null ? void 0 : e.revert, this.silent = e == null ? void 0 : e.silent;
2047
2047
  }
2048
2048
  }
@@ -2098,32 +2098,32 @@ const lr = Gt();
2098
2098
  var xe, ce;
2099
2099
  class hr {
2100
2100
  constructor(e) {
2101
- g(this, "queryKey");
2102
- g(this, "queryHash");
2103
- g(this, "gcTime");
2104
- g(this, "options");
2101
+ b(this, "queryKey");
2102
+ b(this, "queryHash");
2103
+ b(this, "gcTime");
2104
+ b(this, "options");
2105
2105
  w(this, xe);
2106
2106
  w(this, ce);
2107
- g(this, "state");
2107
+ b(this, "state");
2108
2108
  // @todo to share with mutation
2109
- g(this, "executeSubject", new I());
2110
- g(this, "cancelSubject", new I());
2111
- g(this, "setDataSubject", new I());
2112
- g(this, "invalidatedSubject", new I());
2113
- g(this, "resetSubject", new I());
2114
- g(this, "destroySubject", new I());
2115
- g(this, "observersSubject", new X([]));
2116
- g(this, "abortSignalConsumed", !1);
2117
- g(this, "observerCount$", this.observersSubject.asObservable().pipe(b((e) => e.length)));
2118
- g(this, "observers$", this.observersSubject.asObservable());
2119
- g(this, "state$");
2109
+ b(this, "executeSubject", new I());
2110
+ b(this, "cancelSubject", new I());
2111
+ b(this, "setDataSubject", new I());
2112
+ b(this, "invalidatedSubject", new I());
2113
+ b(this, "resetSubject", new I());
2114
+ b(this, "destroySubject", new I());
2115
+ b(this, "observersSubject", new X([]));
2116
+ b(this, "abortSignalConsumed", !1);
2117
+ b(this, "observerCount$", this.observersSubject.asObservable().pipe(y((e) => e.length)));
2118
+ b(this, "observers$", this.observersSubject.asObservable());
2119
+ b(this, "state$");
2120
2120
  A(this, xe, e.defaultOptions), this.options = this.setOptions(e.options), this.queryKey = e.queryKey, this.queryHash = e.queryHash, A(this, ce, e.state ?? rr(this.options)), this.state = a(this, ce), this.gcTime = this.updateGcTime(this.options.gcTime), this.state$ = C(
2121
2121
  this.resetSubject.pipe(
2122
- b(() => ({ command: "reset", state: a(this, ce) }))
2122
+ y(() => ({ command: "reset", state: a(this, ce) }))
2123
2123
  ),
2124
2124
  this.invalidatedSubject.pipe(
2125
2125
  O(() => !this.state.isInvalidated),
2126
- b(() => ({
2126
+ y(() => ({
2127
2127
  command: "invalidate",
2128
2128
  state: {
2129
2129
  isInvalidated: !0
@@ -2132,7 +2132,7 @@ class hr {
2132
2132
  ),
2133
2133
  this.cancelSubject.pipe(
2134
2134
  O(() => !(this.state.error && this.state.status === "error")),
2135
- b((t) => ({
2135
+ y((t) => ({
2136
2136
  command: "cancel",
2137
2137
  state: {
2138
2138
  status: t != null && t.revert ? this.state.status : "error",
@@ -2182,7 +2182,7 @@ class hr {
2182
2182
  })
2183
2183
  );
2184
2184
  return C(u, n).pipe(
2185
- b((h) => ({
2185
+ y((h) => ({
2186
2186
  command: "execute",
2187
2187
  state: h
2188
2188
  })),
@@ -2191,7 +2191,7 @@ class hr {
2191
2191
  })
2192
2192
  ),
2193
2193
  this.setDataSubject.pipe(
2194
- b(({ data: t, options: r }) => ({
2194
+ y(({ data: t, options: r }) => ({
2195
2195
  command: "setData",
2196
2196
  state: {
2197
2197
  status: "success",
@@ -2207,7 +2207,7 @@ class hr {
2207
2207
  getState: () => this.state
2208
2208
  }),
2209
2209
  he(a(this, ce)),
2210
- U(P),
2210
+ V(P),
2211
2211
  R((t) => {
2212
2212
  this.state = t;
2213
2213
  }),
@@ -2226,22 +2226,22 @@ class hr {
2226
2226
  }
2227
2227
  get success$() {
2228
2228
  return this.state$.pipe(
2229
- b(({ data: e, status: t }) => ({ data: e, status: t })),
2230
- U(P),
2229
+ y(({ data: e, status: t }) => ({ data: e, status: t })),
2230
+ V(P),
2231
2231
  O(({ status: e }) => e === "success")
2232
2232
  );
2233
2233
  }
2234
2234
  get error$() {
2235
2235
  return this.state$.pipe(
2236
- b(({ error: e, status: t }) => ({ error: e, status: t })),
2237
- U(P),
2236
+ y(({ error: e, status: t }) => ({ error: e, status: t })),
2237
+ V(P),
2238
2238
  O(({ status: e }) => e === "error")
2239
2239
  );
2240
2240
  }
2241
2241
  get settled$() {
2242
2242
  return this.state$.pipe(
2243
- b(({ status: e }) => ({ status: e })),
2244
- U(P),
2243
+ y(({ status: e }) => ({ status: e })),
2244
+ V(P),
2245
2245
  O(({ status: e }) => e === "success" || e === "error")
2246
2246
  );
2247
2247
  }
@@ -2338,11 +2338,11 @@ class dr {
2338
2338
  return a(this, G).stateChange$.pipe(
2339
2339
  // we force a first result
2340
2340
  he(),
2341
- b(() => this.findAll({
2341
+ y(() => this.findAll({
2342
2342
  ...e,
2343
2343
  fetchStatus: "fetching"
2344
2344
  }).length),
2345
- U()
2345
+ V()
2346
2346
  );
2347
2347
  }
2348
2348
  getAll() {
@@ -8,6 +8,7 @@ interface Option<R = undefined> {
8
8
  export declare function useObserve<T>(source: BehaviorSubject<T>): T;
9
9
  export declare function useObserve<T>(source: Observable<T>): T | undefined;
10
10
  export declare function useObserve<T>(source: () => Observable<T>, deps: DependencyList): T | undefined;
11
+ export declare function useObserve<T>(source: () => Observable<T> | undefined, deps: DependencyList): T | undefined;
11
12
  export declare function useObserve<T>(source: Observable<T>, options: Option<T>): T;
12
13
  export declare function useObserve<T>(source: () => Observable<T>, options: Option<T>, deps: DependencyList): T;
13
14
  export {};
@@ -3,10 +3,12 @@ import { SIGNAL_RESET } from './constants';
3
3
 
4
4
  type setValue<S> = (stateOrUpdater: typeof SIGNAL_RESET | S | ((prev: S) => S)) => void;
5
5
  type Getter<Value> = (get: <GetSignal extends Signal<any, any, any>>(signal: GetSignal) => ReturnType<GetSignal["getValue"]>) => Value;
6
- export interface Config<DefaultValue = undefined, Key = undefined> {
6
+ export type Config<DefaultValue = undefined, Key = undefined> = Key extends undefined ? {
7
+ default: DefaultValue;
8
+ } : {
7
9
  default: DefaultValue;
8
10
  key: Key;
9
- }
11
+ };
10
12
  interface ReadOnlySignalConfig<Value> {
11
13
  get: Getter<Value>;
12
14
  }
@@ -5,4 +5,6 @@ import { Config } from './signal';
5
5
  * - you need reactive state
6
6
  * - you don't need global state
7
7
  */
8
- export declare const useSignal: <T>(config: Config<T, undefined>) => readonly [T, import('./signal').Signal<T, T, undefined>];
8
+ export declare const useSignal: <T>(config: {
9
+ default: T;
10
+ }) => readonly [T, import('./signal').Signal<T, T, undefined>];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reactjrx",
3
3
  "private": false,
4
- "version": "1.96.0",
4
+ "version": "1.97.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"