reactjrx 1.67.3 → 1.67.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var fe=Object.defineProperty;var de=(r,t,n)=>t in r?fe(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n;var S=(r,t,n)=>(de(r,typeof t!="symbol"?t+"":t,n),n),he=(r,t,n)=>{if(!t.has(r))throw TypeError("Cannot "+n)};var x=(r,t,n)=>(he(r,t,"read from private field"),n?n.call(r):t.get(r)),z=(r,t,n)=>{if(t.has(r))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(r):t.set(r,n)};Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),e=require("rxjs"),P=require("rxjs/operators"),D=require("react/jsx-runtime"),R=r=>{const t=b.useRef(r);return b.useMemo(()=>{t.current=r},[r]),t};function ge(r,t){return typeof r=="string"&&r===t||typeof r=="number"&&r===t||typeof r=="boolean"&&r===t||typeof r=="symbol"&&r===t||typeof r=="bigint"&&r===t||typeof r>"u"&&r===t||r===null&&r===t}function N(r,t,n){const s=t!=null&&!Array.isArray(t)?t:{defaultValue:void 0,key:"",unsubscribeOnUnmount:!0},i=n==null&&Array.isArray(t)?t:typeof r=="function"?n??[]:[r],a=b.useRef("getValue"in r&&typeof r.getValue=="function"?r.getValue():s.defaultValue),u=R(r),p=R(s),f=b.useCallback(g=>{const l=u.current,o=(typeof l=="function"?l:()=>l)().pipe(e.distinctUntilChanged(ge),e.tap(m=>{a.current=m}),e.finalize(g),e.catchError(m=>(console.error(m),a.current=void 0,e.EMPTY))).subscribe(g);return()=>{p.current.unsubscribeOnUnmount!==!1&&o.unsubscribe()}},[...i]),d=b.useCallback(()=>a.current,[]);return b.useSyncExternalStore(f,d,d)}function Y(r,t=[]){const n=R(r),s=typeof r=="function"?void 0:r;b.useEffect(()=>{const i=n.current,u=(typeof i=="function"?i:()=>i)().pipe(e.catchError(p=>(console.error("Uncaught error at useSubscribe. Please consider adding a catchError or other handling."),console.error(p),e.EMPTY))).subscribe();return()=>{u.unsubscribe()}},[...t,s,n])}const J=r=>{const t=b.useRef();return t.current||(t.current=r()),b.useEffect(()=>{process.env.NODE_ENV},[]),t},K=({onBeforeComplete:r,completeOnUnmount:t=!0}={})=>{const n=J(()=>new e.Subject),s=b.useRef(!1),i=R(r),a=R(t);return b.useEffect(()=>(s.current&&(n.current=new e.Subject,s.current=!1),()=>{if(!a.current){s.current=!0;return}s.current||(i.current!=null&&i.current(),n.current.complete(),s.current=!0)}),[a,i,n]),n},me=(r,t)=>{const n=K();return Y(()=>r(n.current),[n,...t]),[b.useCallback(i=>{n.current.next(i)},[n]),n]};function be(r=e.identity){const t=new e.Subject;return[t.asObservable(),(...n)=>{t.next(r(...n))}]}const X=r=>{const t=J(()=>new e.BehaviorSubject(r)),n=b.useRef(!1),s=b.useRef(r);return b.useEffect(()=>(n.current&&(t.current=new e.BehaviorSubject(s.current),n.current=!1),()=>{n.current||(t.current.complete(),n.current=!0)}),[t]),t},Z=Symbol("SIGNAL_RESET");function ye(r){const{default:t}=r??{},n=new e.BehaviorSubject(t);return{setValue:a=>{if(typeof a=="function"){const u=a(n.getValue());if(u===n.getValue())return;n.next(u);return}if(a===Z){n.next(t??void 0);return}n.next(a)},getValue:()=>n.getValue(),config:r,subject:n}}function Se(r,t){const n=t??(s=>s);return N(()=>r.subject.pipe(e.map(s=>n(s)),e.distinctUntilChanged()),{defaultValue:n(r.getValue())},[])}const H=r=>{if(!(!r||typeof r!="object"))return r},ve=({adapter:r,key:t})=>({getItem:async n=>{const s=await r.getItem(t),i=H(s)??{};if(n in i)return i[n]},setItem:async(n,s)=>{const i=await r.getItem(t),a=H(i)??{};await r.setItem(t,{...a,[n]:s})}}),$e=r=>({getItem:async t=>{const n=await r.getItem(t);if(n)return JSON.parse(n)},setItem:async(t,n)=>{await r.setItem(t,JSON.stringify(n))}}),we=r=>({getItem:async t=>{const n=r.getItem(t);if(n)return JSON.parse(n)},setItem:async(t,n)=>{r.setItem(t,JSON.stringify(n))}}),j="__reactjrx",Ee=r=>{if(typeof r=="object"&&r!==null&&j in r&&r[j]===j)return r},Ce=async({adapter:r,signal:t,version:n})=>{const i={value:t.getValue(),[j]:j,migrationVersion:n};await r.setItem(t.config.key,i)},Me=({adapter:r,version:t,signal:n})=>e.from(r.getItem(n.config.key)).pipe(e.switchMap(s=>{const i=Ee(s);return!i||i.migrationVersion!==void 0&&t>i.migrationVersion||n.setValue(s.value),e.of(s)})),Re=({entries:r=[],onReady:t,adapter:n=we(localStorage)})=>{const s=R(r),i=R(t),a=R(n),u=N(()=>{const p=s.current;return(p.length===0?e.of(!0):e.zip(...p.map(({signal:d,version:h})=>Me({adapter:a.current,signal:d,version:h}))).pipe(e.map(()=>!0))).pipe(e.tap(()=>{i.current!=null&&i.current()}),e.catchError(d=>(console.error("Unable to hydrate",d),e.EMPTY)))},{defaultValue:!1},[]);return Y(()=>u?e.merge(...s.current.map(({signal:p,version:f})=>p.subject.pipe(e.throttleTime(500,e.asyncScheduler,{trailing:!0}),e.switchMap(()=>e.from(Ce({adapter:a.current,signal:p,version:f})))))):e.EMPTY,[u,a]),{isHydrated:u}},Oe=()=>{const r=K({onBeforeComplete:()=>{r.current.next()}});return r};function q(r,t){return Math.min(r,t)}function ee(r,t){return Math.pow(2,r)*t}function te(r){const{initialInterval:t,maxRetries:n=1/0,maxInterval:s=1/0,shouldRetry:i=()=>!0,resetOnSuccess:a=!1,backoffDelay:u=ee}=r;return p=>e.defer(()=>{let f=0;const d=(h,g)=>h<n&&i(h,g);return p.pipe(P.catchError(h=>{var l;if(f++,!d(f-1,h))throw h;const g=(l=r.caughtError)==null?void 0:l.call(r,f,h);if(!g)throw h;return e.merge(g,e.throwError(()=>h))}),P.retryWhen(h=>h.pipe(P.concatMap(g=>{const l=f-1;return e.iif(()=>d(l,g),e.timer(q(u(l,t),s)),e.throwError(()=>g))}))),P.catchError(h=>{if(r.catchError)return r.catchError(f,h);throw h}),P.tap(()=>{a&&(f=0)}))})}const re=b.createContext({client:null}),xe=({client:r})=>(b.useEffect(()=>{const t=r.mount();return()=>{t()}},[r]),null),Te=b.memo(({children:r,client:t})=>{const n=b.useMemo(()=>({client:t}),[t]);return D.jsxs(re.Provider,{value:n,children:[D.jsx(xe,{client:n.client}),r]})}),G=({unsafe:r=!1}={})=>{const t=b.useContext(re);if(!r&&t.client===null)throw new Error("You forgot to register the provider");return t.client},L=r=>Array.isArray(r)?r.reduce((t,n,s)=>s===r.length-1?`${t}${L(n)}]`:`${t}${L(n)},`,"["):r===void 0?"":JSON.stringify(r,Object.keys(r).sort()),O=r=>r.length===0?"[]":L(r),ne=(r=21)=>crypto.getRandomValues(new Uint8Array(r)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),""),U=()=>({context:void 0,data:void 0,error:null,status:"idle",submittedAt:0,variables:void 0,failureCount:0,failureReason:null,isPaused:!1});function I(r){return r!=null}function C(r,t){if(r==null||t===void 0||typeof r!="object"||typeof t!="object")return r===t;if(r.constructor!==(t==null?void 0:t.constructor))return!1;const n=Object.keys(r),s=Object.keys(t);if(n.length!==s.length)return!1;for(const i of n)if(!t.hasOwnProperty(i)||r[i]!==t[i])return!1;return!0}function se(r){let t=0;return function(s){return new e.Observable(i=>{t++,r(t);const a=s.subscribe(i);return()=>{t--,r(t),a.unsubscribe()}})}}class Ve{constructor({__queryFinalizeHook:t}={}){S(this,"trigger$",new e.Subject);S(this,"mapOperator$",new e.BehaviorSubject("merge"));S(this,"state$");const n=new e.BehaviorSubject(0),s=n.pipe(e.filter(a=>a===0)),i=this.mapOperator$.pipe(e.filter(I),e.distinctUntilChanged());this.state$=i.pipe(e.mergeMap(a=>{const u=a==="concat"?e.concatMap:a==="switch"?e.switchMap:e.mergeMap,p=this.trigger$.pipe(e.filter(()=>a==="merge"));return this.trigger$.pipe(e.takeUntil(i.pipe(e.skip(1))),u(({args:f,mutation:d})=>{const h=e.defer(()=>(d.execute(f),e.EMPTY)),g=d.observeTillFinished().pipe(e.last(),e.mergeMap(()=>d.state$),e.takeUntil(this.trigger$)),l=d.observeTillFinished().pipe(e.skip(1));return e.merge(l,g,h).pipe(t??e.identity,e.takeUntil(e.merge(s,p)))}),e.scan((f,d)=>({...f,...d,...d.status==="pending"&&{data:d.data??f.data},...d.status==="pending"&&{error:d.error??f.error}}),U()),e.distinctUntilChanged(({data:f,...d},{data:h,...g})=>C(d,g)&&C(f,h)))}),e.shareReplay({refCount:!0,bufferSize:1}),se(a=>{n.next(a)}))}trigger({args:t,options:n,mutation:s}){n.mapOperator&&this.mapOperator$.next(n.mapOperator),this.trigger$.next({args:t,options:n,mutation:s})}}var T;class ke{constructor(t,n={},s){S(this,"numberOfObservers",0);S(this,"mutationRunner");z(this,T,new e.BehaviorSubject(void 0));S(this,"observed$");S(this,"result$");S(this,"getObserverResultFromState",t=>({...U(),...t,isSuccess:t.status==="success",isPending:t.status==="pending",isIdle:t.status==="idle",isError:t.status==="error",mutate:this.mutate,reset:this.reset}));var i;this.client=t,this.options=n,this.options.mutationKey=((i=this.options)==null?void 0:i.mutationKey)??[ne()],this.mutationRunner=s??new Ve(this.options),this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this),this.result$=this.mutationRunner.state$.pipe(e.map(a=>({state:this.getObserverResultFromState(a),options:{}}))),x(this,T).pipe(e.filter(I),e.mergeMap(a=>this.mutationRunner.state$.pipe(e.takeUntil(a.mutation.observeTillFinished().pipe(e.last()))))).subscribe(),this.observed$=x(this,T).pipe(e.switchMap(a=>(a==null?void 0:a.mutation.state$.pipe(e.map(u=>({state:this.getObserverResultFromState(u),options:a.options}))))??e.EMPTY),e.mergeMap(({state:a,options:u})=>(a.status==="error"&&(u!=null&&u.onError&&(u==null||u.onError(a.error,a.variables,a.context)),u!=null&&u.onSettled&&(u==null||u.onSettled(a.data,a.error,a.variables,a.context))),a.status==="success"&&(u!=null&&u.onSuccess&&(u==null||u.onSuccess(a.data,a.variables,a.context)),u!=null&&u.onSettled&&(u==null||u.onSettled(a.data,a.error,a.variables,a.context))),e.EMPTY)))}setOptions(t){this.options=this.client.defaultMutationOptions({mutationKey:this.options.mutationKey,...t}),this.options.mutationKey&&this.client.getMutationCache().findAll({exact:!0,mutationKey:this.options.mutationKey}).forEach(n=>{n.setOptions(t)})}observe(){var s;const t=this.getObserverResultFromState(((s=x(this,T).getValue())==null?void 0:s.mutation.state)??U());return{result$:e.merge(this.observed$,this.result$).pipe(e.map(({state:i})=>(console.log({state:i}),i))),lastValue:t}}subscribe(t){const n=this.observe().result$.subscribe(s=>{t(s)});return()=>{n.unsubscribe()}}async mutate(t,n={}){const s=this.client.getMutationCache().build(this.client,this.options);return x(this,T).next({mutation:s,options:n}),this.mutationRunner.trigger({args:t,options:this.options,mutation:s}),await new Promise((i,a)=>{s.observeTillFinished().pipe(e.last()).subscribe({error:u=>{a(u)},next:u=>{u.error?a(u.error):i(u.data)}})})}getCurrentResult(){var n;const t=this.client.getMutationCache().find({exact:!0,mutationKey:(n=this.options)==null?void 0:n.mutationKey});return this.getObserverResultFromState((t==null?void 0:t.state)??U())}reset(){var t;(t=x(this,T).getValue())==null||t.mutation.reset()}cancel(){var t;console.log("cancel"),(t=x(this,T).getValue())==null||t.mutation.destroy()}}T=new WeakMap;function Ue(){}function Ie(r,t){const n=G({unsafe:!!t}),s=t??n,i=R(r),a=J(()=>[ne()]),u=O(r.mutationKey??a.current),[p]=b.useState(()=>new ke(s,r));b.useEffect(()=>{},[p,r]);const f=b.useMemo(()=>p.observe(),[u,p]),d=N(f.result$)??f.lastValue,h=b.useCallback((g,l)=>{p.mutate(g,l).catch(Ue)},[p]);return b.useEffect(()=>()=>{i.current.cancelOnUnMount&&p.cancel()},[p,i]),{...d,mutate:h,mutateAsync:d.mutate}}const ie=(r,t)=>r.length===t.length&&r.every((n,s)=>n===t[s]),Qe=r=>r.pipe(e.switchMap(({options:{refetchOnWindowFocus:t=!0}})=>{const n=typeof t=="function"?t({}):t;return n!==!1?e.merge(e.fromEvent(document,"visibilitychange").pipe(e.filter(()=>!document.hidden),e.map(()=>({type:"refetch",ignoreStale:n==="always"}))),e.fromEvent(window,"focus").pipe(e.map(()=>({type:"refetch",ignoreStale:n==="always"})))):e.EMPTY})),Pe=r=>r.pipe(e.switchMap(({options:{refetchOnReconnect:t=!0}})=>{const n=typeof t=="function"?t({}):t;return n!==!1?e.fromEvent(window,"online").pipe(e.map(()=>({type:"refetch",ignoreStale:n==="always"}))):e.EMPTY})),je=({queryKey:r,queryFn:t,...n})=>{const s=X({queryKey:r,options:n,queryFn:t});return b.useEffect(()=>{s.current.next({queryKey:r,options:n,queryFn:t})},[r,n,t,s]),s},Fe={data:void 0,isLoading:!0,error:void 0,status:"loading",fetchStatus:"idle"};function Le({queryKey:r,queryFn:t,...n}){const s=K(),i=G(),a=je({queryFn:t,queryKey:r,...n}),u=N(()=>{const f=a.current.pipe(e.map(({queryKey:v})=>v??[])),d=e.of(null),h=f.pipe(e.distinctUntilChanged(ie),e.skip(1)),g=v=>!!v&&typeof v!="function",l=a.current.pipe(e.map(({queryFn:v})=>v),e.filter(g),e.distinctUntilChanged(C),g(a.current.getValue().queryFn)?e.skip(1):e.identity),c=a.current.pipe(e.map(({queryFn:v})=>v),e.filter(I)),o=a.current.pipe(e.map(({options:v})=>v)),m=Qe(a.current),w=Pe(a.current),y=e.merge(d,h,l),V=e.merge(s.current,e.merge(m,w).pipe(e.throttleTime(500)));return y.pipe(e.withLatestFrom(f),e.switchMap(([,v])=>{const{result$:$}=i.client.query({key:v,fn$:c,options$:o,trigger$:V});return $.pipe(e.scan((M,{data:k,...B})=>({data:void 0,...M,...B,isLoading:B.status==="loading",...k&&{data:k.result}}),{}))}))},{defaultValue:{...Fe,isLoading:a.current.getValue().options.enabled!==!1}},[i]),p=b.useCallback(()=>{s.current.next({type:"refetch",ignoreStale:!0})},[s]);return{...u,refetch:p}}function _e(r,t,n=[]){const i=(t!=null&&!Array.isArray(t)?t:{}).retry??!0,a=typeof r=="function",u=b.useCallback(a?r:()=>r,a?n:[r]),p=b.useCallback(()=>u().pipe(e.catchError(f=>{throw console.error(f),f}),i?e.retry():e.identity),[u,i]);Y(p,n)}const ae=({retryDelay:r,retry:t,...n})=>te({initialInterval:typeof r=="number"?r:100,...typeof t=="function"?{shouldRetry:t}:{maxRetries:t===!1?0:t??0},...n}),Ne=r=>r.pipe(e.scan((t,n)=>({...t,...n}),{data:void 0,error:void 0,fetchStatus:"idle",status:"loading"}),e.distinctUntilChanged(({data:t,...n},{data:s,...i})=>C(n,i)&&C(t,s))),Ae={backgroundColor:"transparent",color:"inherit"};function ue(r){const t={namespaces:[{name:"@reactjrx",style:{backgroundColor:"#d02f4e",color:"white"}}],namespace(n,s){const i=ue(r);return i.namespaces.push({name:n,style:s??Ae}),i},printNamespaces(){return{namespaces:t.namespaces.map(({name:n})=>`%c ${n} %c`).join(" "),styles:t.namespaces.reduce((n,{style:s})=>(n.push(`background-color: ${s.backgroundColor}; color: ${s.color};`),n.push("background-color: transparent; color: inherit;"),n),[])}},print(n,...s){if(r==="development"){const{namespaces:i,styles:a}=t.printNamespaces();console[n](i,...a,...s)}return t},printWithoutNamespace(n,...s){return r==="development"&&console[n](...s),t},log(...n){return t.print("log",...n)},warn(...n){return t.print("warn",...n)},error(...n){return t.print("error",...n)},group(...n){return t.print("group",...n)},groupEnd(){return r==="development"&&console.groupEnd(),t}};return t}const Q=ue("production"),Ye=Q.namespace("store"),Ke=r=>r.pipe(e.map(t=>[...t.keys()].reduce((n,s)=>{var i;return n[s]=(i=t.get(s))==null?void 0:i.getValue(),n},{})),e.distinctUntilChanged(C)).subscribe(t=>{Ye.log("store","update",t)}),ze=()=>{const r=new Map,t=new e.BehaviorSubject(r),n=new e.Subject,s=new e.Subject,i=()=>{t.next(r)},a=(c,o)=>{r.set(c,new e.BehaviorSubject(o)),i()},u=c=>{var o;return(o=r.get(c))==null?void 0:o.getValue()},p=c=>t.pipe(e.map(()=>r.get(c)),e.filter(I),e.map(o=>o.getValue()),e.distinctUntilChanged(C)),f=(c,o)=>{const m=r.get(c);m&&(typeof o=="function"?m.next({...m.getValue(),...o(m.getValue())}):m.next({...m.getValue(),...o}),t.next(r))},d=(c,o=()=>!0)=>{r.forEach(m=>{const w=m.getValue();o(w)&&m.next({...w,...c})}),t.next(r)},h=c=>{r.delete(c),t.next(r)},g=(c,o)=>(f(c,m=>({...m,runners:[...m.runners,o]})),()=>{var w;const m=((w=r.get(c))==null?void 0:w.getValue().runners.filter(y=>y!==o))??[];f(c,y=>({...y,runners:m}))}),l=()=>{const c=Ke(t);return()=>{c.unsubscribe()}};return{set:a,get:u,get$:p,delete:h,update:f,keys:()=>r.keys(),updateMany:d,addRunner:g,store$:t,queryEvent$:n.asObservable(),dispatchQueryEvent:c=>{n.next(c)},queryTrigger$:s.asObservable(),dispatchQueryTrigger:c=>{s.next(c)},size:()=>r.size,start:l}},We=({options$:r,queryStore:t,key:n})=>{const i=r.pipe(e.map(({enabled:a=!0})=>a),e.distinctUntilChanged()).pipe(e.skip(1),e.filter(a=>a));return e.merge(t.queryTrigger$.pipe(e.filter(a=>n===a.key),e.map(({trigger:a})=>a)),i.pipe(e.map(()=>({type:"enabled",ignoreStale:!1}))))},Je=(r,t)=>n=>r===O([])?n:e.defer(()=>{var u;const s=(u=t.get(r))==null?void 0:u.deduplication_fn;if(s)return s;let i;const a=()=>{var p;((p=t.get(r))==null?void 0:p.deduplication_fn)===i&&t.update(r,{deduplication_fn:void 0})};return i=n.pipe(e.tap({error:a,complete:a}),e.finalize(a),e.shareReplay({refCount:!0,bufferSize:1})),t.update(r,{deduplication_fn:i}),i}),Ge=r=>t=>t.pipe(e.withLatestFrom(r),e.map(([n,s])=>{var i,a;return n.error?(i=s.onError)==null||i.call(s,n.error):(a=s.onSuccess)==null||a.call(s,n),n})),Be=({queryStore:r,serializedKey:t,options:n})=>s=>s.pipe(e.tap(({data:i})=>{if(i!=null&&i.result){const a=i==null?void 0:i.result;r.update(t,{...n.cacheTime!==0&&{cache_fnResult:{result:a}}})}})),De=({options$:r,options:t,fn:n,queryStore:s,serializedKey:i,trigger:a,trigger$:u})=>{const f=r.pipe(e.map(({enabled:y=!0})=>y),e.distinctUntilChanged()).pipe(e.distinctUntilChanged(),e.filter(y=>!y)),h=e.defer(()=>{const y=typeof n=="function"?n():n;return e.from(y)}).pipe(ae(t),Je(i,s),e.tap(()=>{s.dispatchQueryEvent({key:i,type:"fetchSuccess"}),s.update(i,{lastFetchedAt:new Date().getTime()})}),e.map(y=>({status:"success",data:{result:y},error:void 0})),e.endWith({fetchStatus:"idle"}),e.catchError(y=>(s.dispatchQueryEvent({key:i,type:"fetchError"}),e.of({fetchStatus:"idle",status:"error",data:void 0,error:y}))),Ge(r),Be({serializedKey:i,options:t,queryStore:s})),g=s.queryEvent$.pipe(e.filter(y=>y.key===i&&y.type==="queryDataSet"),e.map(()=>{var y,V;return(V=(y=s.get(i))==null?void 0:y.cache_fnResult)==null?void 0:V.result}),e.filter(I),e.map(y=>({status:"success",data:{result:y}})),e.delay(1)),l=e.merge(f.pipe(e.take(1),e.map(()=>({fetchStatus:"idle"}))),e.merge(e.of({fetchStatus:"fetching",error:void 0}),h).pipe(e.takeUntil(f)),g).pipe(e.takeUntil(u)),c=s.get(i),o=c==null?void 0:c.cache_fnResult,m=!!o,w=a.type==="refetch"&&a.ignoreStale;return m?!(c!=null&&c.isStale)&&!w?e.of({fetchStatus:"idle",status:"success",data:{result:o.result},error:void 0}):e.merge(e.of({fetchStatus:"fetching",status:"success",data:{result:o.result},error:void 0}),l):l},A=(r,t,{exact:n=!1}={})=>n?O(r)===O(t):r.reduce((s,i,a)=>s?i===void 0&&!r.slice(a,r.length-1).some(p=>p!==void 0)?!0:L(i)===L(t[a]):!1,!0),F=Q.namespace("invalidation"),He=({queryStore:r})=>({invalidateQueries:({queryKey:n,exact:s=!1,predicate:i}={})=>{let a=[];n?(F.log("invalidation requested for",n),r.updateMany({isStale:!0},u=>{const p=A(n,u.queryKey,{exact:s});return p&&a.push(O(u.queryKey)),p})):i?r.updateMany({isStale:!0},u=>{const p=i(u);return p&&a.push(O(u.queryKey)),p}):(F.log("Invalidation requested for all queries"),r.updateMany({isStale:!0}),a=Array.from(r.keys())),a.forEach(u=>{r.update(u,{deduplication_fn:void 0}),r.dispatchQueryTrigger({key:u,trigger:{ignoreStale:!0,type:"refetch"}})})}}),Xe=r=>({pipeQueryResult:({options$:s})=>i=>{const a=i.pipe(e.share());return e.merge(a,a.pipe(e.filter(u=>!!u.data&&u.fetchStatus!=="fetching"),e.distinctUntilChanged((u,p)=>u.data===p.data),e.withLatestFrom(s),e.map(([,{refetchInterval:u}])=>u),e.filter(I),e.switchMap(u=>typeof u=="number"?e.timer(u).pipe(e.map(()=>({type:"refetch",ignoreStale:!0})),e.switchMap(()=>e.EMPTY)):e.EMPTY)))},refetchQueries:s=>{}}),Ze=(r,t)=>r.filter(n=>!t.includes(n)),qe=(r,t)=>r.store$.pipe(e.map(n=>[...n.keys()]),e.startWith([]),e.pairwise(),e.mergeMap(([n,s])=>{const i=Ze(s,n);return e.merge(...i.map(a=>{const u=r.store$.pipe(e.map(()=>r.get(a)),e.filter(p=>p===void 0));return e.merge(e.NEVER,e.of(a)).pipe(e.tap(()=>{}),t,e.finalize(()=>{}),e.takeUntil(u))}))})),ce=r=>r.pipe(e.switchMap(t=>e.combineLatest(t.runners)),e.map(t=>t.map(({options:n})=>n))),et=r=>r.pipe(e.map(t=>t.reduce((n,s)=>({...n,lowestStaleTime:s.staleTime===void 0?n.lowestStaleTime:Math.min(s.staleTime??1/0,n.lowestStaleTime??1/0)}),{lowestStaleTime:void 0})),e.distinctUntilChanged(C)),tt=r=>t=>t.pipe(e.filter(n=>n.key===r&&(n.type==="fetchError"||n.type==="fetchSuccess"))),rt=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>{const s=r.get$(n);return r.queryEvent$.pipe(tt(n),e.switchMap(()=>s.pipe(ce,et,e.tap(({lowestStaleTime:i=0})=>{var a;i===0?(F.log(n,"marked as stale!",{staleTime:i}),r.update(n,{isStale:!0})):(a=r.get(n))!=null&&a.isStale&&(F.log(n,"marked non stale",{staleTime:i}),r.update(n,{isStale:!1}))}),e.filter(({lowestStaleTime:i})=>i!==1/0&&i!==0),e.switchMap(({lowestStaleTime:i=0})=>e.timer(i)),e.tap(()=>{var i;(i=r.get(n))!=null&&i.isStale||(F.log(n,"marked as stale!"),r.update(n,{isStale:!0}))}))),e.map(()=>n))})),nt=r=>r.pipe(e.map(t=>t.reduce((n,s)=>({...n,lowestCacheTime:s.cacheTime===void 0?n.lowestCacheTime:Math.min(s.cacheTime??1/0,n.lowestCacheTime??1/0)}),{lowestCacheTime:void 0})),e.distinctUntilChanged(C)),st=r=>r.pipe(e.map(t=>t.cache_fnResult),e.distinctUntilChanged(C)),it=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>{const s=r.get$(n);return s.pipe(st,e.switchMap(()=>s.pipe(ce,nt,e.switchMap(({lowestCacheTime:a=5*60*1e3})=>e.timer(a).pipe(e.tap(()=>{r.update(n,{cache_fnResult:void 0})})))))).pipe(e.map(()=>n))})),at=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>r.get$(n).pipe(e.filter(i=>!i.cache_fnResult),e.map(i=>i.runners.length>0),e.pairwise(),e.filter(([i,a])=>i&&!a),e.tap(()=>{r.delete(n)}),e.map(()=>n)))),oe=({key:r})=>({isStale:!0,queryKey:r,runners:[]}),ut=({queryStore:r,serializedKey:t,runner$:n,options$:s,key:i})=>a=>a.pipe(e.withLatestFrom(s),e.map(([u,p])=>i.length===0?[u,void 0]:u.type!=="initial"?[u,void 0]:(r.get(t)?r.update(t,{queryKey:i,...p.markStale&&{isStale:!0}}):r.set(t,oe({key:i})),[u,r.addRunner(t,n)]))),ct=Q.namespace("cache"),ot=({queryStore:r})=>({setQueryData:({queryKey:n,updater:s})=>{const i=O(n);n.length!==0&&(ct.log("set cache for query",O),r.get(i)||r.set(i,oe({key:n})),r.update(i,a=>{var u;return typeof s=="function"?{...a,cache_fnResult:{result:s((u=a.cache_fnResult)==null?void 0:u.result)}}:{...a,cache_fnResult:{result:s}}}),r.dispatchQueryEvent({key:i,type:"queryDataSet"}))}}),lt=Q.namespace("refetch"),pt=({key:r,serializedKey:t,queryStore:n})=>s=>s.pipe(e.tap(i=>{if(i.type!=="refetch")return;const a=n.get(t);a&&i.ignoreStale&&!a.isStale&&(lt.log(r,"marked stale by trigger!"),n.update(t,{isStale:!0}))})),ft=({queryStore:r,serializedKey:t})=>n=>n.pipe(e.tap(s=>{s.type==="refetch"&&(r.update(t,{deduplication_fn:void 0}),r.dispatchQueryTrigger({key:t,trigger:s}))}),e.filter(s=>s.type!=="refetch")),E=r=>e.defer(()=>{const t=r();return t instanceof Promise?e.from(t):t instanceof e.Observable?t:e.of(t)}),dt=({variables:r,state:t,options:n})=>{const s=t.isPaused,i=async()=>await Promise.reject(new Error("No mutationFn found")),a=n.mutationFn??i,p=e.iif(()=>s,e.of(t.context),E(()=>{var l;return((l=n.onMutate)==null?void 0:l.call(n,r))??void 0})).pipe(e.share()),f=(l,c,o)=>(console.error(l),E(()=>{var w;return(w=n.onError)==null?void 0:w.call(n,l,r,c)}).pipe(e.catchError(()=>e.of(l)),e.map(()=>({failureCount:o,error:l,failureReason:l,context:c,status:"error"})))),d=p.pipe(e.switchMap(l=>(typeof a=="function"?E(()=>a(r)):a).pipe(e.map(o=>({result:{data:o},error:null,context:l})),ae({...n,caughtError:(o,m)=>e.of({failureCount:o,failureReason:m}),catchError:(o,m)=>f(m,l,o).pipe(e.map(w=>({...w,result:void 0})))}),e.takeWhile(({result:o,error:m})=>(o==null?void 0:o.data)===void 0&&m===void 0,!0)))),h=e.of({...t,variables:r,status:"pending",isPaused:!1,failureCount:0,failureReason:null,submittedAt:t.submittedAt??new Date().getTime()});return e.merge(h,p.pipe(e.map(l=>({context:l}))),d.pipe(e.switchMap(({result:l,error:c,...o})=>{if(!l&&!c)return e.of({...o});const m=c?e.of(null):E(()=>{var v;return(v=n.onSuccess)==null?void 0:v.call(n,l==null?void 0:l.data,r,o.context)}),y=E(()=>{var v;return(v=n.onSettled)==null?void 0:v.call(n,l==null?void 0:l.data,c,r,o.context)}).pipe(e.catchError(v=>l?e.of(l):e.of(v)));return e.concat(m,y).pipe(e.toArray(),e.map(()=>c?{error:c,data:void 0,variables:r,...o}:{status:"success",error:c,data:l==null?void 0:l.data,variables:r,...o}),e.catchError(v=>f(v,o.context,0).pipe(e.map($=>({...$,data:void 0})))))}))).pipe(e.scan((l,c)=>({...l,...c,data:c.data??l.data,error:c.error??l.error}),U()),e.distinctUntilChanged(({data:l,...c},{data:o,...m})=>C(c,m)&&C(l,o)))};class ht{constructor({options:t,mutationCache:n,state:s}){S(this,"mutationCache");S(this,"observerCount",new e.BehaviorSubject(0));S(this,"destroySubject",new e.Subject);S(this,"resetSubject",new e.Subject);S(this,"executeSubject",new e.Subject);S(this,"state",U());S(this,"state$");S(this,"options");S(this,"observerCount$",this.observerCount.asObservable());S(this,"destroyed$",this.destroySubject.asObservable());this.options=t,this.mutationCache=n,this.state=s??this.state;const i=e.of(this.state),a=this.resetSubject.pipe(e.map(()=>U())),u=this.executeSubject.pipe(e.switchMap(p=>dt({options:{...this.options,onMutate:f=>{const d=E(()=>{var g,l;return(l=(g=n.config).onMutate)==null?void 0:l.call(g,f,this)}),h=E(()=>{var g,l;return((l=(g=this.options).onMutate)==null?void 0:l.call(g,f))??void 0});return d.pipe(e.mergeMap(()=>h))},onError:(f,d,h)=>{const g=E(()=>{var c,o;return(o=(c=n.config).onError)==null?void 0:o.call(c,f,d,h,this)}),l=E(()=>{var c,o;return(o=(c=this.options).onError)==null?void 0:o.call(c,f,d,h)});return e.concat(g,l).pipe(e.toArray())},onSettled:(f,d,h,g)=>{const l=E(()=>{var o,m;return(m=(o=n.config).onSettled)==null?void 0:m.call(o,f,d,h,g,this)}),c=E(()=>{var o,m;return(m=(o=this.options).onSettled)==null?void 0:m.call(o,f,d,h,g)});return e.concat(l,c).pipe(e.toArray())},onSuccess:(f,d,h)=>{const g=E(()=>{var c,o;return(o=(c=n.config).onSuccess)==null?void 0:o.call(c,f,d,h,this)}),l=E(()=>{var c,o;return(o=(c=this.options).onSuccess)==null?void 0:o.call(c,f,d,h)});return e.concat(g,l).pipe(e.toArray())}},state:this.state,variables:p})),e.tap(p=>{this.state={...this.state,...p}}),e.takeUntil(this.destroySubject));this.state$=e.merge(i,u,a).pipe(e.shareReplay({bufferSize:1,refCount:!1}),e.takeUntil(this.destroySubject),se(p=>{this.observerCount.next(p)}))}get meta(){return this.options.meta}setOptions(t){this.options={...this.options,...t}}observeTillFinished(){return this.state$.pipe(e.takeWhile(t=>t.status!=="error"&&t.status!=="success",!0))}execute(t){return this.executeSubject.next(t),this.executeSubject.complete(),this.observeTillFinished()}continue(){return this.execute(this.state.variables)}destroy(){this.destroySubject.next(),this.destroySubject.complete(),this.executeSubject.complete()}reset(){this.resetSubject.next(),this.resetSubject.complete(),this.destroy()}}const W=({mutationKey:r,status:t,predicate:n,exact:s=!0}={})=>a=>s&&r!==void 0&&a.options.mutationKey!==void 0&&!A(a.options.mutationKey,r,{exact:s})||!s&&r!==void 0&&a.options.mutationKey!==void 0&&!A(r,a.options.mutationKey,{exact:s})||t&&a.state.status!==t?!1:n?n(a):!0;class le{constructor(t={}){S(this,"mutationsSubject",new e.BehaviorSubject([]));S(this,"mutations$",this.mutationsSubject.pipe(e.map(t=>t.map(n=>n)),e.distinctUntilChanged(ie),e.share()));S(this,"added$",this.mutations$.pipe(e.pairwise(),e.map(([t,n])=>n.filter(s=>!t.includes(s))[0]),e.filter(I),e.share()));S(this,"removed$",this.mutations$.pipe(e.pairwise(),e.map(([t,n])=>t.filter(s=>!n.includes(s))),e.mergeMap(t=>e.from(t)),e.share()));S(this,"stateChange$",this.added$.pipe(e.mergeMap(t=>t.state$.pipe(e.map(()=>t),e.takeUntil(this.removed$.pipe(e.filter(n=>n===t))))),e.share()));this.config=t}build(t,n,s){const i=new ht({mutationCache:this,options:t.defaultMutationOptions(n),state:s});return i.state$.pipe(e.filter(({status:a})=>a==="success"||a==="error"),e.switchMap(()=>i.observerCount$.pipe(e.filter(a=>a<=1),e.take(1))),e.switchMap(()=>e.timer(i.options.gcTime??5*60*1e3)),e.take(1)).subscribe({complete:()=>{this.mutationsSubject.next(this.mutationsSubject.getValue().filter(a=>i!==a))}}),this.mutationsSubject.next([...this.mutationsSubject.getValue(),i]),i}getAll(){return this.findAll()}remove(t){const n=this.mutationsSubject.getValue().find(s=>s===t);n==null||n.destroy()}find(t){const n={exact:!0,...t},s=W(n);return this.mutationsSubject.getValue().find(i=>s(i))}findAll(t={}){const n={exact:!0,...t},s=W(n);return this.mutationsSubject.getValue().filter(i=>s(i)).map(i=>i)}observe({filters:t,select:n}={}){const s=W(t),i=n??(p=>p.state),a=this.getAll().reduce((p,f)=>[...p,f],[]).filter(s).map(p=>i(p));return{value$:this.stateChange$.pipe(e.startWith(),e.map(()=>this.getAll().filter(s).map(i)),e.distinctUntilChanged(C)),lastValue:a}}subscribe(t){const n=e.merge(this.added$.pipe(e.tap(s=>{t({type:"added",mutation:s})})),this.removed$.pipe(e.tap(s=>{t({type:"removed",mutation:s})})),this.stateChange$.pipe(e.tap(s=>{t({type:"updated",action:{...s.state,type:"success"},mutation:s})}))).subscribe();return()=>{n.unsubscribe()}}resumePausedMutations(){const t=this.findAll({predicate:s=>s.state.isPaused});if(!t.length)return e.EMPTY;const n=t.map(s=>s.continue());return e.combineLatest(n)}clear(){this.getAll().forEach(t=>{this.remove(t)})}}const pe=()=>{const r=ze(),t=He({queryStore:r}),n=ot({queryStore:r}),s=Xe();let i=!1;const a=({key:d,fn$:h,fn:g,trigger$:l=new e.Subject,options$:c=new e.BehaviorSubject({})})=>{if(!i)throw new Error("You forgot to start client");const o=O(d),m=h??(g?e.of(g):e.NEVER);Q.log("query$)",o);const w=c.pipe(e.map($=>({options:$})));let y=()=>{};const V=e.merge(l.pipe(ft({queryStore:r,serializedKey:o})),We({options$:c,key:o,queryStore:r})).pipe(e.share());return{result$:e.merge(e.of({type:"initial"}),V).pipe(ut({key:d,queryStore:r,runner$:w,serializedKey:o,options$:c}),e.map(([$,M])=>(M&&(y=M),$)),pt({key:d,options$:c,queryStore:r,serializedKey:o}),e.withLatestFrom(m,c),e.map(([$,M,k])=>({trigger:$,fn:M,options:k})),e.map($=>(Q.log(o,"query trigger",{trigger:$.trigger,options:$.options}),$)),e.filter(({options:$})=>$.enabled!==!1),e.mergeMap(({fn:$,options:M,trigger:k})=>De({options$:c,options:M,fn:$,queryStore:r,serializedKey:o,trigger:k,trigger$:V})),Ne,e.withLatestFrom(c),e.takeWhile(([$,M])=>!($.data!==void 0&&M.terminateOnFirstResult),!0),e.map(([$])=>$),e.finalize(()=>{y()}))}},u=qe(r,d=>d.pipe(e.switchMap(h=>{const g=e.of(h);return e.merge(it({queryStore:r})(g),rt({queryStore:r})(g),at({queryStore:r})(g))})));return{start:()=>{i=!0;const d=u.subscribe(),h=[r.start()];return()=>{h.forEach(g=>{g()}),d.unsubscribe()}},query:a,queryStore:r,...t,...n,...s,destroy:()=>{}}};var _;class gt{constructor({mutationCache:t}={mutationCache:new le}){S(this,"client");S(this,"mutationCache");z(this,_,new Map);this.mutationCache=t,this.client=pe()}mount(){const t=this.client.start();return()=>{t()}}getMutationCache(){return this.mutationCache}defaultMutationOptions(t){return{...(t==null?void 0:t.mutationKey)&&this.getMutationDefaults(t.mutationKey),...t}}getMutationDefaults(t){const n=[...x(this,_).values()];let s={};return n.forEach(i=>{A(t,i.mutationKey)&&(s={...s,...i.defaultOptions})}),s}setMutationDefaults(t,n){x(this,_).set(O(t),{mutationKey:t,defaultOptions:n})}async resumePausedMutations(){return await e.lastValueFrom(this.mutationCache.resumePausedMutations())}clear(){}}_=new WeakMap;exports.MutationCache=le;exports.QueryClient=gt;exports.QueryClientProvider=Te;exports.SIGNAL_RESET=Z;exports.createClient=pe;exports.createLocalforageAdapter=$e;exports.createSharedStoreAdapter=ve;exports.exponentialBackoffDelay=ee;exports.getDelay=q;exports.retryBackoff=te;exports.signal=ye;exports.trigger=be;exports.useBehaviorSubject=X;exports.useLiveRef=R;exports.useMutation=Ie;exports.useObserve=N;exports.useObserveCallback=me;exports.usePersistSignals=Re;exports.useQuery=Le;exports.useQueryClient=G;exports.useSignalValue=Se;exports.useSubject=K;exports.useSubscribe=Y;exports.useSubscribeEffect=_e;exports.useUnmountObservable=Oe;
|
|
1
|
+
"use strict";var fe=Object.defineProperty;var de=(r,t,n)=>t in r?fe(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n;var S=(r,t,n)=>(de(r,typeof t!="symbol"?t+"":t,n),n),he=(r,t,n)=>{if(!t.has(r))throw TypeError("Cannot "+n)};var x=(r,t,n)=>(he(r,t,"read from private field"),n?n.call(r):t.get(r)),z=(r,t,n)=>{if(t.has(r))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(r):t.set(r,n)};Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),e=require("rxjs"),P=require("rxjs/operators"),D=require("react/jsx-runtime"),R=r=>{const t=b.useRef(r);return b.useMemo(()=>{t.current=r},[r]),t};function ge(r,t){return typeof r=="string"&&r===t||typeof r=="number"&&r===t||typeof r=="boolean"&&r===t||typeof r=="symbol"&&r===t||typeof r=="bigint"&&r===t||typeof r>"u"&&r===t||r===null&&r===t}function A(r,t,n){const s=t!=null&&!Array.isArray(t)?t:{defaultValue:void 0,key:"",unsubscribeOnUnmount:!0},i=n==null&&Array.isArray(t)?t:typeof r=="function"?n??[]:[r],u=b.useRef("getValue"in r&&typeof r.getValue=="function"?r.getValue():s.defaultValue),a=R(r),p=R(s),f=b.useCallback(g=>{const l=a.current,o=(typeof l=="function"?l:()=>l)().pipe(e.distinctUntilChanged(ge),e.tap(m=>{u.current=m}),e.finalize(g),e.catchError(m=>(console.error(m),u.current=void 0,e.EMPTY))).subscribe(g);return()=>{p.current.unsubscribeOnUnmount!==!1&&o.unsubscribe()}},[...i]),d=b.useCallback(()=>u.current,[]);return b.useSyncExternalStore(f,d,d)}function Y(r,t=[]){const n=R(r),s=typeof r=="function"?void 0:r;b.useEffect(()=>{const i=n.current,a=(typeof i=="function"?i:()=>i)().pipe(e.catchError(p=>(console.error("Uncaught error at useSubscribe. Please consider adding a catchError or other handling."),console.error(p),e.EMPTY))).subscribe();return()=>{a.unsubscribe()}},[...t,s,n])}const J=r=>{const t=b.useRef();return t.current||(t.current=r()),b.useEffect(()=>{process.env.NODE_ENV},[]),t},K=({onBeforeComplete:r,completeOnUnmount:t=!0}={})=>{const n=J(()=>new e.Subject),s=b.useRef(!1),i=R(r),u=R(t);return b.useEffect(()=>(s.current&&(n.current=new e.Subject,s.current=!1),()=>{if(!u.current){s.current=!0;return}s.current||(i.current!=null&&i.current(),n.current.complete(),s.current=!0)}),[u,i,n]),n},me=(r,t)=>{const n=K();return Y(()=>r(n.current),[n,...t]),[b.useCallback(i=>{n.current.next(i)},[n]),n]};function be(r=e.identity){const t=new e.Subject;return[t.asObservable(),(...n)=>{t.next(r(...n))}]}const X=r=>{const t=J(()=>new e.BehaviorSubject(r)),n=b.useRef(!1),s=b.useRef(r);return b.useEffect(()=>(n.current&&(t.current=new e.BehaviorSubject(s.current),n.current=!1),()=>{n.current||(t.current.complete(),n.current=!0)}),[t]),t},Z=Symbol("SIGNAL_RESET");function ye(r){const{default:t}=r??{},n=new e.BehaviorSubject(t);return{setValue:u=>{if(typeof u=="function"){const a=u(n.getValue());if(a===n.getValue())return;n.next(a);return}if(u===Z){n.next(t??void 0);return}n.next(u)},getValue:()=>n.getValue(),config:r,subject:n}}function Se(r,t){const n=t??(s=>s);return A(()=>r.subject.pipe(e.map(s=>n(s)),e.distinctUntilChanged()),{defaultValue:n(r.getValue())},[])}const H=r=>{if(!(!r||typeof r!="object"))return r},ve=({adapter:r,key:t})=>({getItem:async n=>{const s=await r.getItem(t),i=H(s)??{};if(n in i)return i[n]},setItem:async(n,s)=>{const i=await r.getItem(t),u=H(i)??{};await r.setItem(t,{...u,[n]:s})}}),$e=r=>({getItem:async t=>{const n=await r.getItem(t);if(n)return JSON.parse(n)},setItem:async(t,n)=>{await r.setItem(t,JSON.stringify(n))}}),we=r=>({getItem:async t=>{const n=r.getItem(t);if(n)return JSON.parse(n)},setItem:async(t,n)=>{r.setItem(t,JSON.stringify(n))}}),j="__reactjrx",Ee=r=>{if(typeof r=="object"&&r!==null&&j in r&&r[j]===j)return r},Ce=async({adapter:r,signal:t,version:n})=>{const i={value:t.getValue(),[j]:j,migrationVersion:n};await r.setItem(t.config.key,i)},Me=({adapter:r,version:t,signal:n})=>e.from(r.getItem(n.config.key)).pipe(e.switchMap(s=>{const i=Ee(s);return!i||i.migrationVersion!==void 0&&t>i.migrationVersion||n.setValue(s.value),e.of(s)})),Re=({entries:r=[],onReady:t,adapter:n=we(localStorage)})=>{const s=R(r),i=R(t),u=R(n),a=A(()=>{const p=s.current;return(p.length===0?e.of(!0):e.zip(...p.map(({signal:d,version:h})=>Me({adapter:u.current,signal:d,version:h}))).pipe(e.map(()=>!0))).pipe(e.tap(()=>{i.current!=null&&i.current()}),e.catchError(d=>(console.error("Unable to hydrate",d),e.EMPTY)))},{defaultValue:!1},[]);return Y(()=>a?e.merge(...s.current.map(({signal:p,version:f})=>p.subject.pipe(e.throttleTime(500,e.asyncScheduler,{trailing:!0}),e.switchMap(()=>e.from(Ce({adapter:u.current,signal:p,version:f})))))):e.EMPTY,[a,u]),{isHydrated:a}},Oe=()=>{const r=K({onBeforeComplete:()=>{r.current.next()}});return r};function q(r,t){return Math.min(r,t)}function ee(r,t){return Math.pow(2,r)*t}function te(r){const{initialInterval:t,maxRetries:n=1/0,maxInterval:s=1/0,shouldRetry:i=()=>!0,resetOnSuccess:u=!1,backoffDelay:a=ee}=r;return p=>e.defer(()=>{let f=0;const d=(h,g)=>h<n&&i(h,g);return p.pipe(P.catchError(h=>{var l;if(f++,!d(f-1,h))throw h;const g=(l=r.caughtError)==null?void 0:l.call(r,f,h);if(!g)throw h;return e.merge(g,e.throwError(()=>h))}),P.retryWhen(h=>h.pipe(P.concatMap(g=>{const l=f-1;return e.iif(()=>d(l,g),e.timer(q(a(l,t),s)),e.throwError(()=>g))}))),P.catchError(h=>{if(r.catchError)return r.catchError(f,h);throw h}),P.tap(()=>{u&&(f=0)}))})}const re=b.createContext({client:null}),xe=({client:r})=>(b.useEffect(()=>{const t=r.mount();return()=>{t()}},[r]),null),Te=b.memo(({children:r,client:t})=>{const n=b.useMemo(()=>({client:t}),[t]);return D.jsxs(re.Provider,{value:n,children:[D.jsx(xe,{client:n.client}),r]})}),G=({unsafe:r=!1}={})=>{const t=b.useContext(re);if(!r&&t.client===null)throw new Error("You forgot to register the provider");return t.client},L=r=>Array.isArray(r)?r.reduce((t,n,s)=>s===r.length-1?`${t}${L(n)}]`:`${t}${L(n)},`,"["):r===void 0?"":JSON.stringify(r,Object.keys(r).sort()),O=r=>r.length===0?"[]":L(r),ne=(r=21)=>crypto.getRandomValues(new Uint8Array(r)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),""),U=()=>({context:void 0,data:void 0,error:null,status:"idle",submittedAt:0,variables:void 0,failureCount:0,failureReason:null,isPaused:!1});function I(r){return r!=null}function C(r,t){if(r==null||t===void 0||typeof r!="object"||typeof t!="object")return r===t;if(r.constructor!==(t==null?void 0:t.constructor))return!1;const n=Object.keys(r),s=Object.keys(t);if(n.length!==s.length)return!1;for(const i of n)if(!t.hasOwnProperty(i)||r[i]!==t[i])return!1;return!0}function se(r){let t=0;return function(s){return new e.Observable(i=>{t++,r(t);const u=s.subscribe(i);return()=>{t--,r(t),u.unsubscribe()}})}}class Ve{constructor({__queryFinalizeHook:t}={}){S(this,"trigger$",new e.Subject);S(this,"mapOperator$",new e.BehaviorSubject("merge"));S(this,"state$");const n=new e.BehaviorSubject(0),s=n.pipe(e.filter(u=>u===0)),i=this.mapOperator$.pipe(e.filter(I),e.distinctUntilChanged());this.state$=i.pipe(e.mergeMap(u=>{const a=u==="concat"?e.concatMap:u==="switch"?e.switchMap:e.mergeMap,p=this.trigger$.pipe(e.filter(()=>u==="merge"));return this.trigger$.pipe(e.takeUntil(i.pipe(e.skip(1))),a(({args:f,mutation:d})=>{const h=e.defer(()=>(d.execute(f),e.EMPTY)),g=d.observeTillFinished().pipe(e.last(),e.mergeMap(()=>d.state$),e.takeUntil(this.trigger$)),l=d.observeTillFinished().pipe(e.skip(1));return e.merge(l,g,h).pipe(t??e.identity,e.takeUntil(e.merge(s,p)))}),e.scan((f,d)=>({...f,...d,...d.status==="pending"&&{data:d.data??f.data},...d.status==="pending"&&{error:d.error??f.error}}),U()),e.distinctUntilChanged(({data:f,...d},{data:h,...g})=>C(d,g)&&C(f,h)))}),e.shareReplay({refCount:!0,bufferSize:1}),se(u=>{n.next(u)}))}trigger({args:t,options:n,mutation:s}){n.mapOperator&&this.mapOperator$.next(n.mapOperator),this.trigger$.next({args:t,options:n,mutation:s})}}const _=(r,t,{exact:n=!1}={})=>n?O(r)===O(t):r.reduce((s,i,u)=>s?i===void 0&&!r.slice(u,r.length-1).some(p=>p!==void 0)?!0:L(i)===L(t[u]):!1,!0);var T;class ke{constructor(t,n={},s){S(this,"numberOfObservers",0);S(this,"mutationRunner");z(this,T,new e.BehaviorSubject(void 0));S(this,"observed$");S(this,"result$");S(this,"getObserverResultFromState",t=>({...U(),...t,isSuccess:t.status==="success",isPending:t.status==="pending",isIdle:t.status==="idle",isError:t.status==="error",mutate:this.mutate,reset:this.reset}));var i;this.client=t,this.options=n,this.options.mutationKey=((i=this.options)==null?void 0:i.mutationKey)??[ne()],this.mutationRunner=s??new Ve(this.options),this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this),this.result$=this.mutationRunner.state$.pipe(e.map(u=>({state:this.getObserverResultFromState(u),options:{}}))),x(this,T).pipe(e.filter(I),e.mergeMap(u=>this.mutationRunner.state$.pipe(e.takeUntil(u.mutation.observeTillFinished().pipe(e.last()))))).subscribe(),this.observed$=x(this,T).pipe(e.switchMap(u=>(u==null?void 0:u.mutation.state$.pipe(e.map(a=>({state:this.getObserverResultFromState(a),options:u.options}))))??e.EMPTY),e.mergeMap(({state:u,options:a})=>(u.status==="error"&&(a!=null&&a.onError&&(a==null||a.onError(u.error,u.variables,u.context)),a!=null&&a.onSettled&&(a==null||a.onSettled(u.data,u.error,u.variables,u.context))),u.status==="success"&&(a!=null&&a.onSuccess&&(a==null||a.onSuccess(u.data,u.variables,u.context)),a!=null&&a.onSettled&&(a==null||a.onSettled(u.data,u.error,u.variables,u.context))),e.EMPTY)))}setOptions(t){var s;const n=this.options;this.options=this.client.defaultMutationOptions({mutationKey:this.options.mutationKey,...t}),(s=x(this,T).getValue())==null||s.mutation.setOptions(this.options),this.options.mutationKey&&n.mutationKey&&!_(this.options.mutationKey,n.mutationKey,{exact:!0})&&this.reset()}observe(){var s;const t=this.getObserverResultFromState(((s=x(this,T).getValue())==null?void 0:s.mutation.state)??U());return{result$:e.merge(this.observed$,this.result$).pipe(e.map(({state:i})=>(console.log({state:i}),i))),lastValue:t}}subscribe(t){const n=this.observe().result$.subscribe(s=>{t(s)});return()=>{n.unsubscribe()}}async mutate(t,n={}){const s=this.client.getMutationCache().build(this.client,this.options);return x(this,T).next({mutation:s,options:n}),this.mutationRunner.trigger({args:t,options:this.options,mutation:s}),await new Promise((i,u)=>{s.observeTillFinished().pipe(e.last()).subscribe({error:a=>{u(a)},next:a=>{a.error?u(a.error):i(a.data)}})})}getCurrentResult(){var n;const t=this.client.getMutationCache().find({exact:!0,mutationKey:(n=this.options)==null?void 0:n.mutationKey});return this.getObserverResultFromState((t==null?void 0:t.state)??U())}reset(){var t;(t=x(this,T).getValue())==null||t.mutation.reset()}}T=new WeakMap;function Ue(){}function Ie(r,t){const n=G({unsafe:!!t}),s=t??n,i=R(r),u=J(()=>[ne()]),a=O(r.mutationKey??u.current),[p]=b.useState(()=>new ke(s,r));b.useEffect(()=>{p.setOptions(r)},[p,r]);const f=b.useMemo(()=>p.observe(),[a,p]),d=A(f.result$)??f.lastValue,h=b.useCallback((g,l)=>{p.mutate(g,l).catch(Ue)},[p]);return b.useEffect(()=>()=>{i.current.cancelOnUnMount&&p.reset()},[p,i]),{...d,mutate:h,mutateAsync:d.mutate}}const ie=(r,t)=>r.length===t.length&&r.every((n,s)=>n===t[s]),Qe=r=>r.pipe(e.switchMap(({options:{refetchOnWindowFocus:t=!0}})=>{const n=typeof t=="function"?t({}):t;return n!==!1?e.merge(e.fromEvent(document,"visibilitychange").pipe(e.filter(()=>!document.hidden),e.map(()=>({type:"refetch",ignoreStale:n==="always"}))),e.fromEvent(window,"focus").pipe(e.map(()=>({type:"refetch",ignoreStale:n==="always"})))):e.EMPTY})),Pe=r=>r.pipe(e.switchMap(({options:{refetchOnReconnect:t=!0}})=>{const n=typeof t=="function"?t({}):t;return n!==!1?e.fromEvent(window,"online").pipe(e.map(()=>({type:"refetch",ignoreStale:n==="always"}))):e.EMPTY})),je=({queryKey:r,queryFn:t,...n})=>{const s=X({queryKey:r,options:n,queryFn:t});return b.useEffect(()=>{s.current.next({queryKey:r,options:n,queryFn:t})},[r,n,t,s]),s},Fe={data:void 0,isLoading:!0,error:void 0,status:"loading",fetchStatus:"idle"};function Le({queryKey:r,queryFn:t,...n}){const s=K(),i=G(),u=je({queryFn:t,queryKey:r,...n}),a=A(()=>{const f=u.current.pipe(e.map(({queryKey:v})=>v??[])),d=e.of(null),h=f.pipe(e.distinctUntilChanged(ie),e.skip(1)),g=v=>!!v&&typeof v!="function",l=u.current.pipe(e.map(({queryFn:v})=>v),e.filter(g),e.distinctUntilChanged(C),g(u.current.getValue().queryFn)?e.skip(1):e.identity),c=u.current.pipe(e.map(({queryFn:v})=>v),e.filter(I)),o=u.current.pipe(e.map(({options:v})=>v)),m=Qe(u.current),w=Pe(u.current),y=e.merge(d,h,l),V=e.merge(s.current,e.merge(m,w).pipe(e.throttleTime(500)));return y.pipe(e.withLatestFrom(f),e.switchMap(([,v])=>{const{result$:$}=i.client.query({key:v,fn$:c,options$:o,trigger$:V});return $.pipe(e.scan((M,{data:k,...B})=>({data:void 0,...M,...B,isLoading:B.status==="loading",...k&&{data:k.result}}),{}))}))},{defaultValue:{...Fe,isLoading:u.current.getValue().options.enabled!==!1}},[i]),p=b.useCallback(()=>{s.current.next({type:"refetch",ignoreStale:!0})},[s]);return{...a,refetch:p}}function _e(r,t,n=[]){const i=(t!=null&&!Array.isArray(t)?t:{}).retry??!0,u=typeof r=="function",a=b.useCallback(u?r:()=>r,u?n:[r]),p=b.useCallback(()=>a().pipe(e.catchError(f=>{throw console.error(f),f}),i?e.retry():e.identity),[a,i]);Y(p,n)}const ue=({retryDelay:r,retry:t,...n})=>te({initialInterval:typeof r=="number"?r:100,...typeof t=="function"?{shouldRetry:t}:{maxRetries:t===!1?0:t??0},...n}),Ne=r=>r.pipe(e.scan((t,n)=>({...t,...n}),{data:void 0,error:void 0,fetchStatus:"idle",status:"loading"}),e.distinctUntilChanged(({data:t,...n},{data:s,...i})=>C(n,i)&&C(t,s))),Ae={backgroundColor:"transparent",color:"inherit"};function ae(r){const t={namespaces:[{name:"@reactjrx",style:{backgroundColor:"#d02f4e",color:"white"}}],namespace(n,s){const i=ae(r);return i.namespaces.push({name:n,style:s??Ae}),i},printNamespaces(){return{namespaces:t.namespaces.map(({name:n})=>`%c ${n} %c`).join(" "),styles:t.namespaces.reduce((n,{style:s})=>(n.push(`background-color: ${s.backgroundColor}; color: ${s.color};`),n.push("background-color: transparent; color: inherit;"),n),[])}},print(n,...s){if(r==="development"){const{namespaces:i,styles:u}=t.printNamespaces();console[n](i,...u,...s)}return t},printWithoutNamespace(n,...s){return r==="development"&&console[n](...s),t},log(...n){return t.print("log",...n)},warn(...n){return t.print("warn",...n)},error(...n){return t.print("error",...n)},group(...n){return t.print("group",...n)},groupEnd(){return r==="development"&&console.groupEnd(),t}};return t}const Q=ae("production"),Ye=Q.namespace("store"),Ke=r=>r.pipe(e.map(t=>[...t.keys()].reduce((n,s)=>{var i;return n[s]=(i=t.get(s))==null?void 0:i.getValue(),n},{})),e.distinctUntilChanged(C)).subscribe(t=>{Ye.log("store","update",t)}),ze=()=>{const r=new Map,t=new e.BehaviorSubject(r),n=new e.Subject,s=new e.Subject,i=()=>{t.next(r)},u=(c,o)=>{r.set(c,new e.BehaviorSubject(o)),i()},a=c=>{var o;return(o=r.get(c))==null?void 0:o.getValue()},p=c=>t.pipe(e.map(()=>r.get(c)),e.filter(I),e.map(o=>o.getValue()),e.distinctUntilChanged(C)),f=(c,o)=>{const m=r.get(c);m&&(typeof o=="function"?m.next({...m.getValue(),...o(m.getValue())}):m.next({...m.getValue(),...o}),t.next(r))},d=(c,o=()=>!0)=>{r.forEach(m=>{const w=m.getValue();o(w)&&m.next({...w,...c})}),t.next(r)},h=c=>{r.delete(c),t.next(r)},g=(c,o)=>(f(c,m=>({...m,runners:[...m.runners,o]})),()=>{var w;const m=((w=r.get(c))==null?void 0:w.getValue().runners.filter(y=>y!==o))??[];f(c,y=>({...y,runners:m}))}),l=()=>{const c=Ke(t);return()=>{c.unsubscribe()}};return{set:u,get:a,get$:p,delete:h,update:f,keys:()=>r.keys(),updateMany:d,addRunner:g,store$:t,queryEvent$:n.asObservable(),dispatchQueryEvent:c=>{n.next(c)},queryTrigger$:s.asObservable(),dispatchQueryTrigger:c=>{s.next(c)},size:()=>r.size,start:l}},We=({options$:r,queryStore:t,key:n})=>{const i=r.pipe(e.map(({enabled:u=!0})=>u),e.distinctUntilChanged()).pipe(e.skip(1),e.filter(u=>u));return e.merge(t.queryTrigger$.pipe(e.filter(u=>n===u.key),e.map(({trigger:u})=>u)),i.pipe(e.map(()=>({type:"enabled",ignoreStale:!1}))))},Je=(r,t)=>n=>r===O([])?n:e.defer(()=>{var a;const s=(a=t.get(r))==null?void 0:a.deduplication_fn;if(s)return s;let i;const u=()=>{var p;((p=t.get(r))==null?void 0:p.deduplication_fn)===i&&t.update(r,{deduplication_fn:void 0})};return i=n.pipe(e.tap({error:u,complete:u}),e.finalize(u),e.shareReplay({refCount:!0,bufferSize:1})),t.update(r,{deduplication_fn:i}),i}),Ge=r=>t=>t.pipe(e.withLatestFrom(r),e.map(([n,s])=>{var i,u;return n.error?(i=s.onError)==null||i.call(s,n.error):(u=s.onSuccess)==null||u.call(s,n),n})),Be=({queryStore:r,serializedKey:t,options:n})=>s=>s.pipe(e.tap(({data:i})=>{if(i!=null&&i.result){const u=i==null?void 0:i.result;r.update(t,{...n.cacheTime!==0&&{cache_fnResult:{result:u}}})}})),De=({options$:r,options:t,fn:n,queryStore:s,serializedKey:i,trigger:u,trigger$:a})=>{const f=r.pipe(e.map(({enabled:y=!0})=>y),e.distinctUntilChanged()).pipe(e.distinctUntilChanged(),e.filter(y=>!y)),h=e.defer(()=>{const y=typeof n=="function"?n():n;return e.from(y)}).pipe(ue(t),Je(i,s),e.tap(()=>{s.dispatchQueryEvent({key:i,type:"fetchSuccess"}),s.update(i,{lastFetchedAt:new Date().getTime()})}),e.map(y=>({status:"success",data:{result:y},error:void 0})),e.endWith({fetchStatus:"idle"}),e.catchError(y=>(s.dispatchQueryEvent({key:i,type:"fetchError"}),e.of({fetchStatus:"idle",status:"error",data:void 0,error:y}))),Ge(r),Be({serializedKey:i,options:t,queryStore:s})),g=s.queryEvent$.pipe(e.filter(y=>y.key===i&&y.type==="queryDataSet"),e.map(()=>{var y,V;return(V=(y=s.get(i))==null?void 0:y.cache_fnResult)==null?void 0:V.result}),e.filter(I),e.map(y=>({status:"success",data:{result:y}})),e.delay(1)),l=e.merge(f.pipe(e.take(1),e.map(()=>({fetchStatus:"idle"}))),e.merge(e.of({fetchStatus:"fetching",error:void 0}),h).pipe(e.takeUntil(f)),g).pipe(e.takeUntil(a)),c=s.get(i),o=c==null?void 0:c.cache_fnResult,m=!!o,w=u.type==="refetch"&&u.ignoreStale;return m?!(c!=null&&c.isStale)&&!w?e.of({fetchStatus:"idle",status:"success",data:{result:o.result},error:void 0}):e.merge(e.of({fetchStatus:"fetching",status:"success",data:{result:o.result},error:void 0}),l):l},F=Q.namespace("invalidation"),He=({queryStore:r})=>({invalidateQueries:({queryKey:n,exact:s=!1,predicate:i}={})=>{let u=[];n?(F.log("invalidation requested for",n),r.updateMany({isStale:!0},a=>{const p=_(n,a.queryKey,{exact:s});return p&&u.push(O(a.queryKey)),p})):i?r.updateMany({isStale:!0},a=>{const p=i(a);return p&&u.push(O(a.queryKey)),p}):(F.log("Invalidation requested for all queries"),r.updateMany({isStale:!0}),u=Array.from(r.keys())),u.forEach(a=>{r.update(a,{deduplication_fn:void 0}),r.dispatchQueryTrigger({key:a,trigger:{ignoreStale:!0,type:"refetch"}})})}}),Xe=r=>({pipeQueryResult:({options$:s})=>i=>{const u=i.pipe(e.share());return e.merge(u,u.pipe(e.filter(a=>!!a.data&&a.fetchStatus!=="fetching"),e.distinctUntilChanged((a,p)=>a.data===p.data),e.withLatestFrom(s),e.map(([,{refetchInterval:a}])=>a),e.filter(I),e.switchMap(a=>typeof a=="number"?e.timer(a).pipe(e.map(()=>({type:"refetch",ignoreStale:!0})),e.switchMap(()=>e.EMPTY)):e.EMPTY)))},refetchQueries:s=>{}}),Ze=(r,t)=>r.filter(n=>!t.includes(n)),qe=(r,t)=>r.store$.pipe(e.map(n=>[...n.keys()]),e.startWith([]),e.pairwise(),e.mergeMap(([n,s])=>{const i=Ze(s,n);return e.merge(...i.map(u=>{const a=r.store$.pipe(e.map(()=>r.get(u)),e.filter(p=>p===void 0));return e.merge(e.NEVER,e.of(u)).pipe(e.tap(()=>{}),t,e.finalize(()=>{}),e.takeUntil(a))}))})),ce=r=>r.pipe(e.switchMap(t=>e.combineLatest(t.runners)),e.map(t=>t.map(({options:n})=>n))),et=r=>r.pipe(e.map(t=>t.reduce((n,s)=>({...n,lowestStaleTime:s.staleTime===void 0?n.lowestStaleTime:Math.min(s.staleTime??1/0,n.lowestStaleTime??1/0)}),{lowestStaleTime:void 0})),e.distinctUntilChanged(C)),tt=r=>t=>t.pipe(e.filter(n=>n.key===r&&(n.type==="fetchError"||n.type==="fetchSuccess"))),rt=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>{const s=r.get$(n);return r.queryEvent$.pipe(tt(n),e.switchMap(()=>s.pipe(ce,et,e.tap(({lowestStaleTime:i=0})=>{var u;i===0?(F.log(n,"marked as stale!",{staleTime:i}),r.update(n,{isStale:!0})):(u=r.get(n))!=null&&u.isStale&&(F.log(n,"marked non stale",{staleTime:i}),r.update(n,{isStale:!1}))}),e.filter(({lowestStaleTime:i})=>i!==1/0&&i!==0),e.switchMap(({lowestStaleTime:i=0})=>e.timer(i)),e.tap(()=>{var i;(i=r.get(n))!=null&&i.isStale||(F.log(n,"marked as stale!"),r.update(n,{isStale:!0}))}))),e.map(()=>n))})),nt=r=>r.pipe(e.map(t=>t.reduce((n,s)=>({...n,lowestCacheTime:s.cacheTime===void 0?n.lowestCacheTime:Math.min(s.cacheTime??1/0,n.lowestCacheTime??1/0)}),{lowestCacheTime:void 0})),e.distinctUntilChanged(C)),st=r=>r.pipe(e.map(t=>t.cache_fnResult),e.distinctUntilChanged(C)),it=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>{const s=r.get$(n);return s.pipe(st,e.switchMap(()=>s.pipe(ce,nt,e.switchMap(({lowestCacheTime:u=5*60*1e3})=>e.timer(u).pipe(e.tap(()=>{r.update(n,{cache_fnResult:void 0})})))))).pipe(e.map(()=>n))})),ut=({queryStore:r})=>t=>t.pipe(e.switchMap(n=>r.get$(n).pipe(e.filter(i=>!i.cache_fnResult),e.map(i=>i.runners.length>0),e.pairwise(),e.filter(([i,u])=>i&&!u),e.tap(()=>{r.delete(n)}),e.map(()=>n)))),oe=({key:r})=>({isStale:!0,queryKey:r,runners:[]}),at=({queryStore:r,serializedKey:t,runner$:n,options$:s,key:i})=>u=>u.pipe(e.withLatestFrom(s),e.map(([a,p])=>i.length===0?[a,void 0]:a.type!=="initial"?[a,void 0]:(r.get(t)?r.update(t,{queryKey:i,...p.markStale&&{isStale:!0}}):r.set(t,oe({key:i})),[a,r.addRunner(t,n)]))),ct=Q.namespace("cache"),ot=({queryStore:r})=>({setQueryData:({queryKey:n,updater:s})=>{const i=O(n);n.length!==0&&(ct.log("set cache for query",O),r.get(i)||r.set(i,oe({key:n})),r.update(i,u=>{var a;return typeof s=="function"?{...u,cache_fnResult:{result:s((a=u.cache_fnResult)==null?void 0:a.result)}}:{...u,cache_fnResult:{result:s}}}),r.dispatchQueryEvent({key:i,type:"queryDataSet"}))}}),lt=Q.namespace("refetch"),pt=({key:r,serializedKey:t,queryStore:n})=>s=>s.pipe(e.tap(i=>{if(i.type!=="refetch")return;const u=n.get(t);u&&i.ignoreStale&&!u.isStale&&(lt.log(r,"marked stale by trigger!"),n.update(t,{isStale:!0}))})),ft=({queryStore:r,serializedKey:t})=>n=>n.pipe(e.tap(s=>{s.type==="refetch"&&(r.update(t,{deduplication_fn:void 0}),r.dispatchQueryTrigger({key:t,trigger:s}))}),e.filter(s=>s.type!=="refetch")),E=r=>e.defer(()=>{const t=r();return t instanceof Promise?e.from(t):t instanceof e.Observable?t:e.of(t)}),dt=({variables:r,state:t,options:n})=>{const s=t.isPaused,i=async()=>await Promise.reject(new Error("No mutationFn found")),u=n.mutationFn??i,p=e.iif(()=>s,e.of(t.context),E(()=>{var l;return((l=n.onMutate)==null?void 0:l.call(n,r))??void 0})).pipe(e.share()),f=(l,c,o)=>(console.error(l),E(()=>{var w;return(w=n.onError)==null?void 0:w.call(n,l,r,c)}).pipe(e.catchError(()=>e.of(l)),e.map(()=>({failureCount:o,error:l,failureReason:l,context:c,status:"error"})))),d=p.pipe(e.switchMap(l=>(typeof u=="function"?E(()=>u(r)):u).pipe(e.map(o=>({result:{data:o},error:null,context:l})),ue({...n,caughtError:(o,m)=>e.of({failureCount:o,failureReason:m}),catchError:(o,m)=>f(m,l,o).pipe(e.map(w=>({...w,result:void 0})))}),e.takeWhile(({result:o,error:m})=>(o==null?void 0:o.data)===void 0&&m===void 0,!0)))),h=e.of({...t,variables:r,status:"pending",isPaused:!1,failureCount:0,failureReason:null,submittedAt:t.submittedAt??new Date().getTime()});return e.merge(h,p.pipe(e.map(l=>({context:l}))),d.pipe(e.switchMap(({result:l,error:c,...o})=>{if(!l&&!c)return e.of({...o});const m=c?e.of(null):E(()=>{var v;return(v=n.onSuccess)==null?void 0:v.call(n,l==null?void 0:l.data,r,o.context)}),y=E(()=>{var v;return(v=n.onSettled)==null?void 0:v.call(n,l==null?void 0:l.data,c,r,o.context)}).pipe(e.catchError(v=>l?e.of(l):e.of(v)));return e.concat(m,y).pipe(e.toArray(),e.map(()=>c?{error:c,data:void 0,variables:r,...o}:{status:"success",error:c,data:l==null?void 0:l.data,variables:r,...o}),e.catchError(v=>f(v,o.context,0).pipe(e.map($=>({...$,data:void 0})))))}))).pipe(e.scan((l,c)=>({...l,...c,data:c.data??l.data,error:c.error??l.error}),U()),e.distinctUntilChanged(({data:l,...c},{data:o,...m})=>C(c,m)&&C(l,o)))};class ht{constructor({options:t,mutationCache:n,state:s}){S(this,"mutationCache");S(this,"observerCount",new e.BehaviorSubject(0));S(this,"destroySubject",new e.Subject);S(this,"resetSubject",new e.Subject);S(this,"executeSubject",new e.Subject);S(this,"state",U());S(this,"state$");S(this,"options");S(this,"observerCount$",this.observerCount.asObservable());S(this,"destroyed$",this.destroySubject.asObservable());this.options=t,this.mutationCache=n,this.state=s??this.state;const i=e.of(this.state),u=this.resetSubject.pipe(e.map(()=>U())),a=this.executeSubject.pipe(e.switchMap(p=>dt({options:{...this.options,onMutate:f=>{const d=E(()=>{var g,l;return(l=(g=n.config).onMutate)==null?void 0:l.call(g,f,this)}),h=E(()=>{var g,l;return((l=(g=this.options).onMutate)==null?void 0:l.call(g,f))??void 0});return d.pipe(e.mergeMap(()=>h))},onError:(f,d,h)=>{const g=E(()=>{var c,o;return(o=(c=n.config).onError)==null?void 0:o.call(c,f,d,h,this)}),l=E(()=>{var c,o;return(o=(c=this.options).onError)==null?void 0:o.call(c,f,d,h)});return e.concat(g,l).pipe(e.toArray())},onSettled:(f,d,h,g)=>{const l=E(()=>{var o,m;return(m=(o=n.config).onSettled)==null?void 0:m.call(o,f,d,h,g,this)}),c=E(()=>{var o,m;return(m=(o=this.options).onSettled)==null?void 0:m.call(o,f,d,h,g)});return e.concat(l,c).pipe(e.toArray())},onSuccess:(f,d,h)=>{const g=E(()=>{var c,o;return(o=(c=n.config).onSuccess)==null?void 0:o.call(c,f,d,h,this)}),l=E(()=>{var c,o;return(o=(c=this.options).onSuccess)==null?void 0:o.call(c,f,d,h)});return e.concat(g,l).pipe(e.toArray())}},state:this.state,variables:p})),e.tap(p=>{this.state={...this.state,...p}}),e.takeUntil(this.destroySubject));this.state$=e.merge(i,a,u).pipe(e.shareReplay({bufferSize:1,refCount:!1}),e.takeUntil(this.destroySubject),se(p=>{this.observerCount.next(p)}))}get meta(){return this.options.meta}setOptions(t){this.options={...this.options,...t}}observeTillFinished(){return this.state$.pipe(e.takeWhile(t=>t.status!=="error"&&t.status!=="success",!0))}execute(t){return this.executeSubject.next(t),this.executeSubject.complete(),this.observeTillFinished()}continue(){return this.execute(this.state.variables)}destroy(){this.destroySubject.next(),this.destroySubject.complete(),this.executeSubject.complete()}reset(){this.resetSubject.next(),this.resetSubject.complete(),this.destroy()}}const W=({mutationKey:r,status:t,predicate:n,exact:s=!0}={})=>u=>s&&r!==void 0&&u.options.mutationKey!==void 0&&!_(u.options.mutationKey,r,{exact:s})||!s&&r!==void 0&&u.options.mutationKey!==void 0&&!_(r,u.options.mutationKey,{exact:s})||t&&u.state.status!==t?!1:n?n(u):!0;class le{constructor(t={}){S(this,"mutationsSubject",new e.BehaviorSubject([]));S(this,"mutations$",this.mutationsSubject.pipe(e.map(t=>t.map(n=>n)),e.distinctUntilChanged(ie),e.share()));S(this,"added$",this.mutations$.pipe(e.pairwise(),e.map(([t,n])=>n.filter(s=>!t.includes(s))[0]),e.filter(I),e.share()));S(this,"removed$",this.mutations$.pipe(e.pairwise(),e.map(([t,n])=>t.filter(s=>!n.includes(s))),e.mergeMap(t=>e.from(t)),e.share()));S(this,"stateChange$",this.added$.pipe(e.mergeMap(t=>t.state$.pipe(e.map(()=>t),e.takeUntil(this.removed$.pipe(e.filter(n=>n===t))))),e.share()));this.config=t}build(t,n,s){const i=new ht({mutationCache:this,options:t.defaultMutationOptions(n),state:s});return i.state$.pipe(e.filter(({status:u})=>u==="success"||u==="error"),e.switchMap(()=>i.observerCount$.pipe(e.filter(u=>u<=1),e.take(1))),e.switchMap(()=>e.timer(i.options.gcTime??5*60*1e3)),e.take(1)).subscribe({complete:()=>{this.mutationsSubject.next(this.mutationsSubject.getValue().filter(u=>i!==u))}}),this.mutationsSubject.next([...this.mutationsSubject.getValue(),i]),i}getAll(){return this.findAll()}remove(t){const n=this.mutationsSubject.getValue().find(s=>s===t);n==null||n.destroy()}find(t){const n={exact:!0,...t},s=W(n);return this.mutationsSubject.getValue().find(i=>s(i))}findAll(t={}){const n={exact:!0,...t},s=W(n);return this.mutationsSubject.getValue().filter(i=>s(i)).map(i=>i)}observe({filters:t,select:n}={}){const s=W(t),i=n??(p=>p.state),u=this.getAll().reduce((p,f)=>[...p,f],[]).filter(s).map(p=>i(p));return{value$:this.stateChange$.pipe(e.startWith(),e.map(()=>this.getAll().filter(s).map(i)),e.distinctUntilChanged(C)),lastValue:u}}subscribe(t){const n=e.merge(this.added$.pipe(e.tap(s=>{t({type:"added",mutation:s})})),this.removed$.pipe(e.tap(s=>{t({type:"removed",mutation:s})})),this.stateChange$.pipe(e.tap(s=>{t({type:"updated",action:{...s.state,type:"success"},mutation:s})}))).subscribe();return()=>{n.unsubscribe()}}resumePausedMutations(){const t=this.findAll({predicate:s=>s.state.isPaused});if(!t.length)return e.EMPTY;const n=t.map(s=>s.continue());return e.combineLatest(n)}clear(){this.getAll().forEach(t=>{this.remove(t)})}}const pe=()=>{const r=ze(),t=He({queryStore:r}),n=ot({queryStore:r}),s=Xe();let i=!1;const u=({key:d,fn$:h,fn:g,trigger$:l=new e.Subject,options$:c=new e.BehaviorSubject({})})=>{if(!i)throw new Error("You forgot to start client");const o=O(d),m=h??(g?e.of(g):e.NEVER);Q.log("query$)",o);const w=c.pipe(e.map($=>({options:$})));let y=()=>{};const V=e.merge(l.pipe(ft({queryStore:r,serializedKey:o})),We({options$:c,key:o,queryStore:r})).pipe(e.share());return{result$:e.merge(e.of({type:"initial"}),V).pipe(at({key:d,queryStore:r,runner$:w,serializedKey:o,options$:c}),e.map(([$,M])=>(M&&(y=M),$)),pt({key:d,options$:c,queryStore:r,serializedKey:o}),e.withLatestFrom(m,c),e.map(([$,M,k])=>({trigger:$,fn:M,options:k})),e.map($=>(Q.log(o,"query trigger",{trigger:$.trigger,options:$.options}),$)),e.filter(({options:$})=>$.enabled!==!1),e.mergeMap(({fn:$,options:M,trigger:k})=>De({options$:c,options:M,fn:$,queryStore:r,serializedKey:o,trigger:k,trigger$:V})),Ne,e.withLatestFrom(c),e.takeWhile(([$,M])=>!($.data!==void 0&&M.terminateOnFirstResult),!0),e.map(([$])=>$),e.finalize(()=>{y()}))}},a=qe(r,d=>d.pipe(e.switchMap(h=>{const g=e.of(h);return e.merge(it({queryStore:r})(g),rt({queryStore:r})(g),ut({queryStore:r})(g))})));return{start:()=>{i=!0;const d=a.subscribe(),h=[r.start()];return()=>{h.forEach(g=>{g()}),d.unsubscribe()}},query:u,queryStore:r,...t,...n,...s,destroy:()=>{}}};var N;class gt{constructor({mutationCache:t}={mutationCache:new le}){S(this,"client");S(this,"mutationCache");z(this,N,new Map);this.mutationCache=t,this.client=pe()}mount(){const t=this.client.start();return()=>{t()}}getMutationCache(){return this.mutationCache}defaultMutationOptions(t){return{...(t==null?void 0:t.mutationKey)&&this.getMutationDefaults(t.mutationKey),...t}}getMutationDefaults(t){const n=[...x(this,N).values()];let s={};return n.forEach(i=>{_(t,i.mutationKey)&&(s={...s,...i.defaultOptions})}),s}setMutationDefaults(t,n){x(this,N).set(O(t),{mutationKey:t,defaultOptions:n})}async resumePausedMutations(){return await e.lastValueFrom(this.mutationCache.resumePausedMutations())}clear(){}}N=new WeakMap;exports.MutationCache=le;exports.QueryClient=gt;exports.QueryClientProvider=Te;exports.SIGNAL_RESET=Z;exports.createClient=pe;exports.createLocalforageAdapter=$e;exports.createSharedStoreAdapter=ve;exports.exponentialBackoffDelay=ee;exports.getDelay=q;exports.retryBackoff=te;exports.signal=ye;exports.trigger=be;exports.useBehaviorSubject=X;exports.useLiveRef=R;exports.useMutation=Ie;exports.useObserve=A;exports.useObserveCallback=me;exports.usePersistSignals=Re;exports.useQuery=Le;exports.useQueryClient=G;exports.useSignalValue=Se;exports.useSubject=K;exports.useSubscribe=Y;exports.useSubscribeEffect=_e;exports.useUnmountObservable=Oe;
|
package/dist/index.js
CHANGED
|
@@ -10,8 +10,8 @@ var k = (t, e, r) => (We(t, e, "read from private field"), r ? r.call(t) : e.get
|
|
|
10
10
|
e instanceof WeakSet ? e.add(t) : e.set(t, r);
|
|
11
11
|
};
|
|
12
12
|
import { useRef as H, useMemo as ye, useCallback as Y, useSyncExternalStore as Ye, useEffect as K, createContext as Ge, memo as He, useContext as De, useState as Xe } from "react";
|
|
13
|
-
import { distinctUntilChanged as
|
|
14
|
-
import { catchError as
|
|
13
|
+
import { distinctUntilChanged as R, tap as x, finalize as ae, catchError as A, EMPTY as M, Subject as F, identity as le, BehaviorSubject as I, map as p, of as S, zip as Ze, merge as O, throttleTime as Ve, asyncScheduler as qe, switchMap as w, from as ne, defer as se, throwError as Re, iif as Te, timer as ie, Observable as Me, filter as $, mergeMap as _, takeUntil as P, skip as B, last as ge, scan as pe, shareReplay as $e, concatMap as Be, fromEvent as me, withLatestFrom as D, retry as et, endWith as tt, delay as rt, take as be, share as J, startWith as Ie, pairwise as oe, NEVER as Qe, combineLatest as Fe, takeWhile as ve, concat as ue, toArray as ce, lastValueFrom as nt } from "rxjs";
|
|
14
|
+
import { catchError as Ce, retryWhen as st, concatMap as it, tap as ut } from "rxjs/operators";
|
|
15
15
|
import { jsxs as ct, jsx as ot } from "react/jsx-runtime";
|
|
16
16
|
const U = (t) => {
|
|
17
17
|
const e = H(t);
|
|
@@ -38,12 +38,12 @@ function fe(t, e, r) {
|
|
|
38
38
|
* be using objects and keeping same reference but pushing new
|
|
39
39
|
* properties values
|
|
40
40
|
*/
|
|
41
|
-
|
|
41
|
+
R(at),
|
|
42
42
|
x((m) => {
|
|
43
43
|
i.current = m;
|
|
44
44
|
}),
|
|
45
45
|
ae(g),
|
|
46
|
-
|
|
46
|
+
A((m) => (console.error(m), i.current = void 0, M))
|
|
47
47
|
).subscribe(g);
|
|
48
48
|
return () => {
|
|
49
49
|
l.current.unsubscribeOnUnmount !== !1 && o.unsubscribe();
|
|
@@ -58,9 +58,9 @@ function Se(t, e = []) {
|
|
|
58
58
|
const r = U(t), n = typeof t == "function" ? void 0 : t;
|
|
59
59
|
K(() => {
|
|
60
60
|
const s = r.current, u = (typeof s == "function" ? s : () => s)().pipe(
|
|
61
|
-
|
|
61
|
+
A((l) => (console.error(
|
|
62
62
|
"Uncaught error at useSubscribe. Please consider adding a catchError or other handling."
|
|
63
|
-
), console.error(l),
|
|
63
|
+
), console.error(l), M))
|
|
64
64
|
).subscribe();
|
|
65
65
|
return () => {
|
|
66
66
|
u.unsubscribe();
|
|
@@ -77,7 +77,7 @@ const we = (t) => {
|
|
|
77
77
|
return e.current || (e.current = t()), K(() => {
|
|
78
78
|
process.env.NODE_ENV;
|
|
79
79
|
}, []), e;
|
|
80
|
-
},
|
|
80
|
+
}, Oe = ({
|
|
81
81
|
onBeforeComplete: t,
|
|
82
82
|
completeOnUnmount: e = !0
|
|
83
83
|
} = {}) => {
|
|
@@ -90,7 +90,7 @@ const we = (t) => {
|
|
|
90
90
|
n.current || (s.current != null && s.current(), r.current.complete(), n.current = !0);
|
|
91
91
|
}), [i, s, r]), r;
|
|
92
92
|
}, ar = (t, e) => {
|
|
93
|
-
const r =
|
|
93
|
+
const r = Oe();
|
|
94
94
|
return Se(() => t(r.current), [r, ...e]), [Y((s) => {
|
|
95
95
|
r.current.next(s);
|
|
96
96
|
}, [r]), r];
|
|
@@ -137,7 +137,7 @@ function fr(t, e) {
|
|
|
137
137
|
return fe(
|
|
138
138
|
() => t.subject.pipe(
|
|
139
139
|
p((n) => r(n)),
|
|
140
|
-
|
|
140
|
+
R()
|
|
141
141
|
),
|
|
142
142
|
{
|
|
143
143
|
defaultValue: r(t.getValue())
|
|
@@ -197,7 +197,7 @@ const xe = (t) => {
|
|
|
197
197
|
adapter: t,
|
|
198
198
|
version: e,
|
|
199
199
|
signal: r
|
|
200
|
-
}) =>
|
|
200
|
+
}) => ne(t.getItem(r.config.key)).pipe(
|
|
201
201
|
w((n) => {
|
|
202
202
|
const s = dt(n);
|
|
203
203
|
return s ? s.migrationVersion !== void 0 && e > s.migrationVersion ? S(n) : (r.setValue(n.value), S(n)) : S(n);
|
|
@@ -222,28 +222,28 @@ const xe = (t) => {
|
|
|
222
222
|
x(() => {
|
|
223
223
|
s.current != null && s.current();
|
|
224
224
|
}),
|
|
225
|
-
|
|
225
|
+
A((d) => (console.error("Unable to hydrate", d), M))
|
|
226
226
|
);
|
|
227
227
|
},
|
|
228
228
|
{ defaultValue: !1 },
|
|
229
229
|
[]
|
|
230
230
|
);
|
|
231
|
-
return Se(() => u ?
|
|
231
|
+
return Se(() => u ? O(
|
|
232
232
|
...n.current.map(
|
|
233
233
|
({ signal: l, version: f }) => l.subject.pipe(
|
|
234
234
|
Ve(500, qe, {
|
|
235
235
|
trailing: !0
|
|
236
236
|
}),
|
|
237
237
|
w(
|
|
238
|
-
() =>
|
|
238
|
+
() => ne(
|
|
239
239
|
ht({ adapter: i.current, signal: l, version: f })
|
|
240
240
|
)
|
|
241
241
|
)
|
|
242
242
|
)
|
|
243
243
|
)
|
|
244
|
-
) :
|
|
244
|
+
) : M, [u, i]), { isHydrated: u };
|
|
245
245
|
}, mr = () => {
|
|
246
|
-
const t =
|
|
246
|
+
const t = Oe({
|
|
247
247
|
onBeforeComplete: () => {
|
|
248
248
|
t.current.next();
|
|
249
249
|
}
|
|
@@ -265,35 +265,35 @@ function yt(t) {
|
|
|
265
265
|
resetOnSuccess: i = !1,
|
|
266
266
|
backoffDelay: u = bt
|
|
267
267
|
} = t;
|
|
268
|
-
return (l) =>
|
|
268
|
+
return (l) => se(() => {
|
|
269
269
|
let f = 0;
|
|
270
270
|
const d = (h, g) => h < r && s(h, g);
|
|
271
271
|
return l.pipe(
|
|
272
|
-
|
|
272
|
+
Ce((h) => {
|
|
273
273
|
var a;
|
|
274
274
|
if (f++, !d(f - 1, h))
|
|
275
275
|
throw h;
|
|
276
276
|
const g = (a = t.caughtError) == null ? void 0 : a.call(t, f, h);
|
|
277
277
|
if (!g)
|
|
278
278
|
throw h;
|
|
279
|
-
return
|
|
279
|
+
return O(
|
|
280
280
|
g,
|
|
281
|
-
|
|
281
|
+
Re(() => h)
|
|
282
282
|
);
|
|
283
283
|
}),
|
|
284
284
|
st((h) => h.pipe(
|
|
285
285
|
it((g) => {
|
|
286
286
|
const a = f - 1;
|
|
287
|
-
return
|
|
287
|
+
return Te(
|
|
288
288
|
() => d(a, g),
|
|
289
|
-
|
|
289
|
+
ie(
|
|
290
290
|
mt(u(a, e), n)
|
|
291
291
|
),
|
|
292
|
-
|
|
292
|
+
Re(() => g)
|
|
293
293
|
);
|
|
294
294
|
})
|
|
295
295
|
)),
|
|
296
|
-
|
|
296
|
+
Ce((h) => {
|
|
297
297
|
if (t.catchError)
|
|
298
298
|
return t.catchError(f, h);
|
|
299
299
|
throw h;
|
|
@@ -340,7 +340,7 @@ const _e = Ge({
|
|
|
340
340
|
function G(t) {
|
|
341
341
|
return t != null;
|
|
342
342
|
}
|
|
343
|
-
function
|
|
343
|
+
function T(t, e) {
|
|
344
344
|
if (t == null || e === void 0 || typeof t != "object" || typeof e != "object")
|
|
345
345
|
return t === e;
|
|
346
346
|
if (t.constructor !== (e == null ? void 0 : e.constructor))
|
|
@@ -356,7 +356,7 @@ function M(t, e) {
|
|
|
356
356
|
function ke(t) {
|
|
357
357
|
let e = 0;
|
|
358
358
|
return function(n) {
|
|
359
|
-
return new
|
|
359
|
+
return new Me((s) => {
|
|
360
360
|
e++, t(e);
|
|
361
361
|
const i = n.subscribe(s);
|
|
362
362
|
return () => {
|
|
@@ -376,7 +376,7 @@ class vt {
|
|
|
376
376
|
$((i) => i === 0)
|
|
377
377
|
), s = this.mapOperator$.pipe(
|
|
378
378
|
$(G),
|
|
379
|
-
|
|
379
|
+
R()
|
|
380
380
|
);
|
|
381
381
|
this.state$ = s.pipe(
|
|
382
382
|
_((i) => {
|
|
@@ -386,14 +386,14 @@ class vt {
|
|
|
386
386
|
return this.trigger$.pipe(
|
|
387
387
|
P(s.pipe(B(1))),
|
|
388
388
|
u(({ args: f, mutation: d }) => {
|
|
389
|
-
const h =
|
|
389
|
+
const h = se(() => (d.execute(f), M)), g = d.observeTillFinished().pipe(
|
|
390
390
|
ge(),
|
|
391
391
|
_(() => d.state$),
|
|
392
392
|
P(this.trigger$)
|
|
393
393
|
), a = d.observeTillFinished().pipe(B(1));
|
|
394
|
-
return
|
|
394
|
+
return O(a, g, h).pipe(
|
|
395
395
|
e ?? le,
|
|
396
|
-
P(
|
|
396
|
+
P(O(n, l))
|
|
397
397
|
);
|
|
398
398
|
}),
|
|
399
399
|
pe((f, d) => ({
|
|
@@ -406,8 +406,8 @@ class vt {
|
|
|
406
406
|
error: d.error ?? f.error
|
|
407
407
|
}
|
|
408
408
|
}), W()),
|
|
409
|
-
|
|
410
|
-
({ data: f, ...d }, { data: h, ...g }) =>
|
|
409
|
+
R(
|
|
410
|
+
({ data: f, ...d }, { data: h, ...g }) => T(d, g) && T(f, h)
|
|
411
411
|
)
|
|
412
412
|
);
|
|
413
413
|
}),
|
|
@@ -424,6 +424,7 @@ class vt {
|
|
|
424
424
|
r.mapOperator && this.mapOperator$.next(r.mapOperator), this.trigger$.next({ args: e, options: r, mutation: n });
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
|
+
const te = (t, e, { exact: r = !1 } = {}) => r ? N(t) === N(e) : t.reduce((n, s, i) => n ? s === void 0 && !t.slice(i, t.length - 1).some((l) => l !== void 0) ? !0 : ee(s) === ee(e[i]) : !1, !0);
|
|
427
428
|
var L;
|
|
428
429
|
class St {
|
|
429
430
|
constructor(e, r = {}, n) {
|
|
@@ -462,7 +463,7 @@ class St {
|
|
|
462
463
|
state: this.getObserverResultFromState(u),
|
|
463
464
|
options: i.options
|
|
464
465
|
}))
|
|
465
|
-
)) ??
|
|
466
|
+
)) ?? M
|
|
466
467
|
),
|
|
467
468
|
_(({ state: i, options: u }) => (i.status === "error" && (u != null && u.onError && (u == null || u.onError(
|
|
468
469
|
i.error,
|
|
@@ -482,26 +483,25 @@ class St {
|
|
|
482
483
|
i.error,
|
|
483
484
|
i.variables,
|
|
484
485
|
i.context
|
|
485
|
-
))),
|
|
486
|
+
))), M))
|
|
486
487
|
);
|
|
487
488
|
}
|
|
488
489
|
setOptions(e) {
|
|
490
|
+
var n;
|
|
491
|
+
const r = this.options;
|
|
489
492
|
this.options = this.client.defaultMutationOptions({
|
|
490
493
|
mutationKey: this.options.mutationKey,
|
|
491
494
|
...e
|
|
492
|
-
}), this.options.mutationKey && this.
|
|
493
|
-
exact: !0
|
|
494
|
-
|
|
495
|
-
}).forEach((r) => {
|
|
496
|
-
r.setOptions(e);
|
|
497
|
-
});
|
|
495
|
+
}), (n = k(this, L).getValue()) == null || n.mutation.setOptions(this.options), this.options.mutationKey && r.mutationKey && !te(this.options.mutationKey, r.mutationKey, {
|
|
496
|
+
exact: !0
|
|
497
|
+
}) && this.reset();
|
|
498
498
|
}
|
|
499
499
|
observe() {
|
|
500
500
|
var n;
|
|
501
501
|
const e = this.getObserverResultFromState(
|
|
502
502
|
((n = k(this, L).getValue()) == null ? void 0 : n.mutation.state) ?? W()
|
|
503
503
|
);
|
|
504
|
-
return { result$:
|
|
504
|
+
return { result$: O(this.observed$, this.result$).pipe(
|
|
505
505
|
p(({ state: s }) => (console.log({ state: s }), s))
|
|
506
506
|
), lastValue: e };
|
|
507
507
|
}
|
|
@@ -545,10 +545,6 @@ class St {
|
|
|
545
545
|
var e;
|
|
546
546
|
(e = k(this, L).getValue()) == null || e.mutation.reset();
|
|
547
547
|
}
|
|
548
|
-
cancel() {
|
|
549
|
-
var e;
|
|
550
|
-
console.log("cancel"), (e = k(this, L).getValue()) == null || e.mutation.destroy();
|
|
551
|
-
}
|
|
552
548
|
}
|
|
553
549
|
L = new WeakMap();
|
|
554
550
|
function wt() {
|
|
@@ -561,6 +557,7 @@ function yr(t, e) {
|
|
|
561
557
|
)
|
|
562
558
|
);
|
|
563
559
|
K(() => {
|
|
560
|
+
l.setOptions(t);
|
|
564
561
|
}, [l, t]);
|
|
565
562
|
const f = ye(() => l.observe(), [u, l]), d = fe(f.result$) ?? f.lastValue, h = Y(
|
|
566
563
|
(g, a) => {
|
|
@@ -569,13 +566,13 @@ function yr(t, e) {
|
|
|
569
566
|
[l]
|
|
570
567
|
);
|
|
571
568
|
return K(() => () => {
|
|
572
|
-
s.current.cancelOnUnMount && l.
|
|
569
|
+
s.current.cancelOnUnMount && l.reset();
|
|
573
570
|
}, [l, s]), { ...d, mutate: h, mutateAsync: d.mutate };
|
|
574
571
|
}
|
|
575
|
-
const Le = (t, e) => t.length === e.length && t.every((r, n) => r === e[n]),
|
|
572
|
+
const Le = (t, e) => t.length === e.length && t.every((r, n) => r === e[n]), Ot = (t) => t.pipe(
|
|
576
573
|
w(({ options: { refetchOnWindowFocus: e = !0 } }) => {
|
|
577
574
|
const r = typeof e == "function" ? e({}) : e;
|
|
578
|
-
return r !== !1 ?
|
|
575
|
+
return r !== !1 ? O(
|
|
579
576
|
me(document, "visibilitychange").pipe(
|
|
580
577
|
$(() => !document.hidden),
|
|
581
578
|
p(() => ({
|
|
@@ -589,9 +586,9 @@ const Le = (t, e) => t.length === e.length && t.every((r, n) => r === e[n]), Et
|
|
|
589
586
|
ignoreStale: r === "always"
|
|
590
587
|
}))
|
|
591
588
|
)
|
|
592
|
-
) :
|
|
589
|
+
) : M;
|
|
593
590
|
})
|
|
594
|
-
),
|
|
591
|
+
), Et = (t) => t.pipe(
|
|
595
592
|
w(({ options: { refetchOnReconnect: e = !0 } }) => {
|
|
596
593
|
const r = typeof e == "function" ? e({}) : e;
|
|
597
594
|
return r !== !1 ? me(window, "online").pipe(
|
|
@@ -599,9 +596,9 @@ const Le = (t, e) => t.length === e.length && t.every((r, n) => r === e[n]), Et
|
|
|
599
596
|
type: "refetch",
|
|
600
597
|
ignoreStale: r === "always"
|
|
601
598
|
}))
|
|
602
|
-
) :
|
|
599
|
+
) : M;
|
|
603
600
|
})
|
|
604
|
-
),
|
|
601
|
+
), Rt = ({
|
|
605
602
|
queryKey: t,
|
|
606
603
|
queryFn: e,
|
|
607
604
|
...r
|
|
@@ -614,7 +611,7 @@ const Le = (t, e) => t.length === e.length && t.every((r, n) => r === e[n]), Et
|
|
|
614
611
|
queryFn: e
|
|
615
612
|
});
|
|
616
613
|
}, [t, r, e, n]), n;
|
|
617
|
-
},
|
|
614
|
+
}, Ct = {
|
|
618
615
|
data: void 0,
|
|
619
616
|
isLoading: !0,
|
|
620
617
|
error: void 0,
|
|
@@ -626,43 +623,43 @@ function $r({
|
|
|
626
623
|
queryFn: e,
|
|
627
624
|
...r
|
|
628
625
|
}) {
|
|
629
|
-
const n =
|
|
626
|
+
const n = Oe(), s = Pe(), i = Rt({ queryFn: e, queryKey: t, ...r }), u = fe(
|
|
630
627
|
() => {
|
|
631
628
|
const f = i.current.pipe(p(({ queryKey: v }) => v ?? [])), d = S(null), h = f.pipe(
|
|
632
|
-
|
|
629
|
+
R(Le),
|
|
633
630
|
B(1)
|
|
634
631
|
), g = (v) => !!v && typeof v != "function", a = i.current.pipe(
|
|
635
632
|
p(({ queryFn: v }) => v),
|
|
636
633
|
$(g),
|
|
637
|
-
|
|
634
|
+
R(T),
|
|
638
635
|
g(i.current.getValue().queryFn) ? B(1) : le
|
|
639
636
|
), c = i.current.pipe(
|
|
640
637
|
p(({ queryFn: v }) => v),
|
|
641
638
|
$(G)
|
|
642
|
-
), o = i.current.pipe(p(({ options: v }) => v)), m =
|
|
639
|
+
), o = i.current.pipe(p(({ options: v }) => v)), m = Ot(i.current), C = Et(i.current), b = O(
|
|
643
640
|
d,
|
|
644
641
|
h,
|
|
645
642
|
a
|
|
646
|
-
),
|
|
643
|
+
), j = O(
|
|
647
644
|
n.current,
|
|
648
|
-
|
|
645
|
+
O(m, C).pipe(Ve(500))
|
|
649
646
|
);
|
|
650
647
|
return b.pipe(
|
|
651
648
|
D(f),
|
|
652
649
|
w(([, v]) => {
|
|
653
|
-
const { result$:
|
|
650
|
+
const { result$: E } = s.client.query({
|
|
654
651
|
key: v,
|
|
655
652
|
fn$: c,
|
|
656
653
|
options$: o,
|
|
657
|
-
trigger$:
|
|
654
|
+
trigger$: j
|
|
658
655
|
});
|
|
659
|
-
return
|
|
656
|
+
return E.pipe(
|
|
660
657
|
pe(
|
|
661
|
-
(Q, { data: z, ...
|
|
658
|
+
(Q, { data: z, ...Ee }) => ({
|
|
662
659
|
data: void 0,
|
|
663
660
|
...Q,
|
|
664
|
-
...
|
|
665
|
-
isLoading:
|
|
661
|
+
...Ee,
|
|
662
|
+
isLoading: Ee.status === "loading",
|
|
666
663
|
...z && {
|
|
667
664
|
data: z.result
|
|
668
665
|
}
|
|
@@ -684,7 +681,7 @@ function $r({
|
|
|
684
681
|
},
|
|
685
682
|
{
|
|
686
683
|
defaultValue: {
|
|
687
|
-
...
|
|
684
|
+
...Ct,
|
|
688
685
|
isLoading: i.current.getValue().options.enabled !== !1
|
|
689
686
|
}
|
|
690
687
|
},
|
|
@@ -700,7 +697,7 @@ function vr(t, e, r = []) {
|
|
|
700
697
|
i ? r : [t]
|
|
701
698
|
), l = Y(
|
|
702
699
|
() => u().pipe(
|
|
703
|
-
|
|
700
|
+
A((f) => {
|
|
704
701
|
throw console.error(f), f;
|
|
705
702
|
}),
|
|
706
703
|
s ? et() : le
|
|
@@ -734,11 +731,11 @@ const Ue = ({
|
|
|
734
731
|
status: "loading"
|
|
735
732
|
}
|
|
736
733
|
),
|
|
737
|
-
|
|
738
|
-
({ data: e, ...r }, { data: n, ...s }) =>
|
|
734
|
+
R(
|
|
735
|
+
({ data: e, ...r }, { data: n, ...s }) => T(r, s) && T(e, n)
|
|
739
736
|
)
|
|
740
737
|
), Vt = { backgroundColor: "transparent", color: "inherit" };
|
|
741
|
-
function
|
|
738
|
+
function je(t) {
|
|
742
739
|
const e = {
|
|
743
740
|
namespaces: [
|
|
744
741
|
{
|
|
@@ -747,7 +744,7 @@ function Ae(t) {
|
|
|
747
744
|
}
|
|
748
745
|
],
|
|
749
746
|
namespace(r, n) {
|
|
750
|
-
const s =
|
|
747
|
+
const s = je(t);
|
|
751
748
|
return s.namespaces.push({
|
|
752
749
|
name: r,
|
|
753
750
|
style: n ?? Vt
|
|
@@ -789,16 +786,16 @@ function Ae(t) {
|
|
|
789
786
|
};
|
|
790
787
|
return e;
|
|
791
788
|
}
|
|
792
|
-
const X =
|
|
789
|
+
const X = je("production"), Tt = X.namespace("store"), Mt = (t) => t.pipe(
|
|
793
790
|
p(
|
|
794
791
|
(e) => [...e.keys()].reduce((r, n) => {
|
|
795
792
|
var s;
|
|
796
793
|
return r[n] = (s = e.get(n)) == null ? void 0 : s.getValue(), r;
|
|
797
794
|
}, {})
|
|
798
795
|
),
|
|
799
|
-
|
|
796
|
+
R(T)
|
|
800
797
|
).subscribe((e) => {
|
|
801
|
-
|
|
798
|
+
Tt.log("store", "update", e);
|
|
802
799
|
}), It = () => {
|
|
803
800
|
const t = /* @__PURE__ */ new Map(), e = new I(t), r = new F(), n = new F(), s = () => {
|
|
804
801
|
e.next(t);
|
|
@@ -811,7 +808,7 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
811
808
|
p(() => t.get(c)),
|
|
812
809
|
$(G),
|
|
813
810
|
p((o) => o.getValue()),
|
|
814
|
-
|
|
811
|
+
R(T)
|
|
815
812
|
), f = (c, o) => {
|
|
816
813
|
const m = t.get(c);
|
|
817
814
|
m && (typeof o == "function" ? m.next({
|
|
@@ -820,8 +817,8 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
820
817
|
}) : m.next({ ...m.getValue(), ...o }), e.next(t));
|
|
821
818
|
}, d = (c, o = () => !0) => {
|
|
822
819
|
t.forEach((m) => {
|
|
823
|
-
const
|
|
824
|
-
o(
|
|
820
|
+
const C = m.getValue();
|
|
821
|
+
o(C) && m.next({ ...C, ...c });
|
|
825
822
|
}), e.next(t);
|
|
826
823
|
}, h = (c) => {
|
|
827
824
|
t.delete(c), e.next(t);
|
|
@@ -829,14 +826,14 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
829
826
|
...m,
|
|
830
827
|
runners: [...m.runners, o]
|
|
831
828
|
})), () => {
|
|
832
|
-
var
|
|
833
|
-
const m = ((
|
|
829
|
+
var C;
|
|
830
|
+
const m = ((C = t.get(c)) == null ? void 0 : C.getValue().runners.filter((b) => b !== o)) ?? [];
|
|
834
831
|
f(c, (b) => ({
|
|
835
832
|
...b,
|
|
836
833
|
runners: m
|
|
837
834
|
}));
|
|
838
835
|
}), a = () => {
|
|
839
|
-
const c =
|
|
836
|
+
const c = Mt(e);
|
|
840
837
|
return () => {
|
|
841
838
|
c.unsubscribe();
|
|
842
839
|
};
|
|
@@ -869,12 +866,12 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
869
866
|
}) => {
|
|
870
867
|
const s = t.pipe(
|
|
871
868
|
p(({ enabled: i = !0 }) => i),
|
|
872
|
-
|
|
869
|
+
R()
|
|
873
870
|
).pipe(
|
|
874
871
|
B(1),
|
|
875
872
|
$((i) => i)
|
|
876
873
|
);
|
|
877
|
-
return
|
|
874
|
+
return O(
|
|
878
875
|
e.queryTrigger$.pipe(
|
|
879
876
|
$((i) => r === i.key),
|
|
880
877
|
p(({ trigger: i }) => i)
|
|
@@ -886,7 +883,7 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
886
883
|
}))
|
|
887
884
|
)
|
|
888
885
|
);
|
|
889
|
-
}, Ft = (t, e) => (r) => t === N([]) ? r :
|
|
886
|
+
}, Ft = (t, e) => (r) => t === N([]) ? r : se(() => {
|
|
890
887
|
var u;
|
|
891
888
|
const n = (u = e.get(t)) == null ? void 0 : u.deduplication_fn;
|
|
892
889
|
if (n)
|
|
@@ -952,13 +949,13 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
952
949
|
}) => {
|
|
953
950
|
const f = t.pipe(
|
|
954
951
|
p(({ enabled: b = !0 }) => b),
|
|
955
|
-
|
|
952
|
+
R()
|
|
956
953
|
).pipe(
|
|
957
|
-
|
|
954
|
+
R(),
|
|
958
955
|
$((b) => !b)
|
|
959
|
-
), h =
|
|
956
|
+
), h = se(() => {
|
|
960
957
|
const b = typeof r == "function" ? r() : r;
|
|
961
|
-
return
|
|
958
|
+
return ne(b);
|
|
962
959
|
}).pipe(
|
|
963
960
|
Ue(e),
|
|
964
961
|
Ft(s, n),
|
|
@@ -978,7 +975,7 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
978
975
|
tt({
|
|
979
976
|
fetchStatus: "idle"
|
|
980
977
|
}),
|
|
981
|
-
|
|
978
|
+
A((b) => (n.dispatchQueryEvent({
|
|
982
979
|
key: s,
|
|
983
980
|
type: "fetchError"
|
|
984
981
|
}), S({
|
|
@@ -994,8 +991,8 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
994
991
|
(b) => b.key === s && b.type === "queryDataSet"
|
|
995
992
|
),
|
|
996
993
|
p(() => {
|
|
997
|
-
var b,
|
|
998
|
-
return (
|
|
994
|
+
var b, j;
|
|
995
|
+
return (j = (b = n.get(s)) == null ? void 0 : b.cache_fnResult) == null ? void 0 : j.result;
|
|
999
996
|
}),
|
|
1000
997
|
$(G),
|
|
1001
998
|
p((b) => ({
|
|
@@ -1009,25 +1006,25 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1009
1006
|
* a small delay to ensure it happens after.
|
|
1010
1007
|
*/
|
|
1011
1008
|
rt(1)
|
|
1012
|
-
), a =
|
|
1009
|
+
), a = O(
|
|
1013
1010
|
f.pipe(
|
|
1014
1011
|
be(1),
|
|
1015
1012
|
p(() => ({
|
|
1016
1013
|
fetchStatus: "idle"
|
|
1017
1014
|
}))
|
|
1018
1015
|
),
|
|
1019
|
-
|
|
1016
|
+
O(
|
|
1020
1017
|
S({ fetchStatus: "fetching", error: void 0 }),
|
|
1021
1018
|
h
|
|
1022
1019
|
).pipe(P(f)),
|
|
1023
1020
|
g
|
|
1024
|
-
).pipe(P(u)), c = n.get(s), o = c == null ? void 0 : c.cache_fnResult, m = !!o,
|
|
1025
|
-
return m ? !(c != null && c.isStale) && !
|
|
1021
|
+
).pipe(P(u)), c = n.get(s), o = c == null ? void 0 : c.cache_fnResult, m = !!o, C = i.type === "refetch" && i.ignoreStale;
|
|
1022
|
+
return m ? !(c != null && c.isStale) && !C ? S({
|
|
1026
1023
|
fetchStatus: "idle",
|
|
1027
1024
|
status: "success",
|
|
1028
1025
|
data: { result: o.result },
|
|
1029
1026
|
error: void 0
|
|
1030
|
-
}) :
|
|
1027
|
+
}) : O(
|
|
1031
1028
|
S({
|
|
1032
1029
|
fetchStatus: "fetching",
|
|
1033
1030
|
status: "success",
|
|
@@ -1036,7 +1033,7 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1036
1033
|
}),
|
|
1037
1034
|
a
|
|
1038
1035
|
) : a;
|
|
1039
|
-
},
|
|
1036
|
+
}, q = X.namespace("invalidation"), kt = ({
|
|
1040
1037
|
queryStore: t
|
|
1041
1038
|
}) => ({
|
|
1042
1039
|
invalidateQueries: ({
|
|
@@ -1046,7 +1043,7 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1046
1043
|
} = {}) => {
|
|
1047
1044
|
let i = [];
|
|
1048
1045
|
r ? (q.log("invalidation requested for", r), t.updateMany({ isStale: !0 }, (u) => {
|
|
1049
|
-
const l =
|
|
1046
|
+
const l = te(r, u.queryKey, { exact: n });
|
|
1050
1047
|
return l && i.push(N(u.queryKey)), l;
|
|
1051
1048
|
})) : s ? t.updateMany({ isStale: !0 }, (u) => {
|
|
1052
1049
|
const l = s(u);
|
|
@@ -1065,41 +1062,41 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1065
1062
|
options$: n
|
|
1066
1063
|
}) => (s) => {
|
|
1067
1064
|
const i = s.pipe(J());
|
|
1068
|
-
return
|
|
1065
|
+
return O(
|
|
1069
1066
|
i,
|
|
1070
1067
|
i.pipe(
|
|
1071
1068
|
$(
|
|
1072
1069
|
(u) => !!u.data && u.fetchStatus !== "fetching"
|
|
1073
1070
|
),
|
|
1074
|
-
|
|
1071
|
+
R((u, l) => u.data === l.data),
|
|
1075
1072
|
D(n),
|
|
1076
1073
|
p(([, { refetchInterval: u }]) => u),
|
|
1077
1074
|
$(G),
|
|
1078
|
-
w((u) => typeof u == "number" ?
|
|
1075
|
+
w((u) => typeof u == "number" ? ie(u).pipe(
|
|
1079
1076
|
p(() => ({
|
|
1080
1077
|
type: "refetch",
|
|
1081
1078
|
ignoreStale: !0
|
|
1082
1079
|
})),
|
|
1083
|
-
w(() =>
|
|
1084
|
-
) :
|
|
1080
|
+
w(() => M)
|
|
1081
|
+
) : M)
|
|
1085
1082
|
)
|
|
1086
1083
|
);
|
|
1087
1084
|
},
|
|
1088
1085
|
refetchQueries: (n) => {
|
|
1089
1086
|
}
|
|
1090
|
-
}), Ut = (t, e) => t.filter((r) => !e.includes(r)),
|
|
1087
|
+
}), Ut = (t, e) => t.filter((r) => !e.includes(r)), jt = (t, e) => t.store$.pipe(
|
|
1091
1088
|
p((r) => [...r.keys()]),
|
|
1092
1089
|
Ie([]),
|
|
1093
|
-
|
|
1090
|
+
oe(),
|
|
1094
1091
|
_(([r, n]) => {
|
|
1095
1092
|
const s = Ut(n, r);
|
|
1096
|
-
return
|
|
1093
|
+
return O(
|
|
1097
1094
|
...s.map((i) => {
|
|
1098
1095
|
const u = t.store$.pipe(
|
|
1099
1096
|
p(() => t.get(i)),
|
|
1100
1097
|
$((l) => l === void 0)
|
|
1101
1098
|
);
|
|
1102
|
-
return
|
|
1099
|
+
return O(Qe, S(i)).pipe(
|
|
1103
1100
|
x(() => {
|
|
1104
1101
|
}),
|
|
1105
1102
|
e,
|
|
@@ -1110,10 +1107,10 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1110
1107
|
})
|
|
1111
1108
|
);
|
|
1112
1109
|
})
|
|
1113
|
-
),
|
|
1110
|
+
), Ae = (t) => t.pipe(
|
|
1114
1111
|
w((e) => Fe(e.runners)),
|
|
1115
1112
|
p((e) => e.map(({ options: r }) => r))
|
|
1116
|
-
),
|
|
1113
|
+
), At = (t) => t.pipe(
|
|
1117
1114
|
p(
|
|
1118
1115
|
(e) => e.reduce(
|
|
1119
1116
|
(r, n) => ({
|
|
@@ -1126,7 +1123,7 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1126
1123
|
{ lowestStaleTime: void 0 }
|
|
1127
1124
|
)
|
|
1128
1125
|
),
|
|
1129
|
-
|
|
1126
|
+
R(T)
|
|
1130
1127
|
), Kt = (t) => (e) => e.pipe(
|
|
1131
1128
|
$(
|
|
1132
1129
|
(r) => r.key === t && (r.type === "fetchError" || r.type === "fetchSuccess")
|
|
@@ -1140,8 +1137,8 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1140
1137
|
Kt(r),
|
|
1141
1138
|
w(
|
|
1142
1139
|
() => n.pipe(
|
|
1143
|
-
|
|
1144
|
-
|
|
1140
|
+
Ae,
|
|
1141
|
+
At,
|
|
1145
1142
|
x(({ lowestStaleTime: s = 0 }) => {
|
|
1146
1143
|
var i;
|
|
1147
1144
|
s === 0 ? (q.log(r, "marked as stale!", {
|
|
@@ -1153,7 +1150,7 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1153
1150
|
$(
|
|
1154
1151
|
({ lowestStaleTime: s }) => s !== 1 / 0 && s !== 0
|
|
1155
1152
|
),
|
|
1156
|
-
w(({ lowestStaleTime: s = 0 }) =>
|
|
1153
|
+
w(({ lowestStaleTime: s = 0 }) => ie(s)),
|
|
1157
1154
|
x(() => {
|
|
1158
1155
|
var s;
|
|
1159
1156
|
(s = t.get(r)) != null && s.isStale || (q.log(r, "marked as stale!"), t.update(r, { isStale: !0 }));
|
|
@@ -1176,10 +1173,10 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1176
1173
|
{ lowestCacheTime: void 0 }
|
|
1177
1174
|
)
|
|
1178
1175
|
),
|
|
1179
|
-
|
|
1176
|
+
R(T)
|
|
1180
1177
|
), Wt = (t) => t.pipe(
|
|
1181
1178
|
p((e) => e.cache_fnResult),
|
|
1182
|
-
|
|
1179
|
+
R(T)
|
|
1183
1180
|
), Yt = ({
|
|
1184
1181
|
queryStore: t
|
|
1185
1182
|
}) => (e) => e.pipe(
|
|
@@ -1189,13 +1186,13 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1189
1186
|
Wt,
|
|
1190
1187
|
w(
|
|
1191
1188
|
() => n.pipe(
|
|
1192
|
-
|
|
1189
|
+
Ae,
|
|
1193
1190
|
Jt,
|
|
1194
1191
|
w(
|
|
1195
1192
|
({
|
|
1196
1193
|
lowestCacheTime: i = 5 * 60 * 1e3
|
|
1197
1194
|
/* 5mn */
|
|
1198
|
-
}) =>
|
|
1195
|
+
}) => ie(i).pipe(
|
|
1199
1196
|
x(() => {
|
|
1200
1197
|
t.update(r, { cache_fnResult: void 0 });
|
|
1201
1198
|
})
|
|
@@ -1211,7 +1208,7 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1211
1208
|
w((r) => t.get$(r).pipe(
|
|
1212
1209
|
$((s) => !s.cache_fnResult),
|
|
1213
1210
|
p((s) => s.runners.length > 0),
|
|
1214
|
-
|
|
1211
|
+
oe(),
|
|
1215
1212
|
$(([s, i]) => s && !i),
|
|
1216
1213
|
x(() => {
|
|
1217
1214
|
t.delete(r);
|
|
@@ -1290,15 +1287,15 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1290
1287
|
}));
|
|
1291
1288
|
}),
|
|
1292
1289
|
$((n) => n.type !== "refetch")
|
|
1293
|
-
), V = (t) =>
|
|
1290
|
+
), V = (t) => se(() => {
|
|
1294
1291
|
const e = t();
|
|
1295
|
-
return e instanceof Promise ?
|
|
1292
|
+
return e instanceof Promise ? ne(e) : e instanceof Me ? e : S(e);
|
|
1296
1293
|
}), er = ({
|
|
1297
1294
|
variables: t,
|
|
1298
1295
|
state: e,
|
|
1299
1296
|
options: r
|
|
1300
1297
|
}) => {
|
|
1301
|
-
const n = e.isPaused, s = async () => await Promise.reject(new Error("No mutationFn found")), i = r.mutationFn ?? s, l =
|
|
1298
|
+
const n = e.isPaused, s = async () => await Promise.reject(new Error("No mutationFn found")), i = r.mutationFn ?? s, l = Te(
|
|
1302
1299
|
() => n,
|
|
1303
1300
|
S(e.context),
|
|
1304
1301
|
V(
|
|
@@ -1310,11 +1307,11 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1310
1307
|
)
|
|
1311
1308
|
).pipe(J()), f = (a, c, o) => (console.error(a), V(
|
|
1312
1309
|
() => {
|
|
1313
|
-
var
|
|
1314
|
-
return (
|
|
1310
|
+
var C;
|
|
1311
|
+
return (C = r.onError) == null ? void 0 : C.call(r, a, t, c);
|
|
1315
1312
|
}
|
|
1316
1313
|
).pipe(
|
|
1317
|
-
|
|
1314
|
+
A(() => S(a)),
|
|
1318
1315
|
p(
|
|
1319
1316
|
() => ({
|
|
1320
1317
|
failureCount: o,
|
|
@@ -1345,8 +1342,8 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1345
1342
|
failureReason: m
|
|
1346
1343
|
}),
|
|
1347
1344
|
catchError: (o, m) => f(m, a, o).pipe(
|
|
1348
|
-
p((
|
|
1349
|
-
...
|
|
1345
|
+
p((C) => ({
|
|
1346
|
+
...C,
|
|
1350
1347
|
result: void 0
|
|
1351
1348
|
}))
|
|
1352
1349
|
)
|
|
@@ -1365,7 +1362,7 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1365
1362
|
failureReason: null,
|
|
1366
1363
|
submittedAt: e.submittedAt ?? (/* @__PURE__ */ new Date()).getTime()
|
|
1367
1364
|
});
|
|
1368
|
-
return
|
|
1365
|
+
return O(
|
|
1369
1366
|
h,
|
|
1370
1367
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1371
1368
|
l.pipe(p((a) => ({ context: a }))),
|
|
@@ -1397,10 +1394,10 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1397
1394
|
);
|
|
1398
1395
|
}
|
|
1399
1396
|
).pipe(
|
|
1400
|
-
|
|
1397
|
+
A((v) => a ? S(a) : S(v))
|
|
1401
1398
|
);
|
|
1402
|
-
return
|
|
1403
|
-
|
|
1399
|
+
return ue(m, b).pipe(
|
|
1400
|
+
ce(),
|
|
1404
1401
|
p(
|
|
1405
1402
|
() => c ? {
|
|
1406
1403
|
error: c,
|
|
@@ -1415,10 +1412,10 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1415
1412
|
...o
|
|
1416
1413
|
}
|
|
1417
1414
|
),
|
|
1418
|
-
|
|
1415
|
+
A(
|
|
1419
1416
|
(v) => f(v, o.context, 0).pipe(
|
|
1420
|
-
p((
|
|
1421
|
-
...
|
|
1417
|
+
p((E) => ({
|
|
1418
|
+
...E,
|
|
1422
1419
|
data: void 0
|
|
1423
1420
|
}))
|
|
1424
1421
|
)
|
|
@@ -1433,8 +1430,8 @@ const X = Ae("production"), Mt = X.namespace("store"), Tt = (t) => t.pipe(
|
|
|
1433
1430
|
data: c.data ?? a.data,
|
|
1434
1431
|
error: c.error ?? a.error
|
|
1435
1432
|
}), W()),
|
|
1436
|
-
|
|
1437
|
-
({ data: a, ...c }, { data: o, ...m }) =>
|
|
1433
|
+
R(
|
|
1434
|
+
({ data: a, ...c }, { data: o, ...m }) => T(c, m) && T(a, o)
|
|
1438
1435
|
)
|
|
1439
1436
|
);
|
|
1440
1437
|
};
|
|
@@ -1499,7 +1496,7 @@ class tr {
|
|
|
1499
1496
|
return (o = (c = this.options).onError) == null ? void 0 : o.call(c, f, d, h);
|
|
1500
1497
|
}
|
|
1501
1498
|
);
|
|
1502
|
-
return
|
|
1499
|
+
return ue(g, a).pipe(ce());
|
|
1503
1500
|
},
|
|
1504
1501
|
onSettled: (f, d, h, g) => {
|
|
1505
1502
|
const a = V(
|
|
@@ -1520,7 +1517,7 @@ class tr {
|
|
|
1520
1517
|
return (m = (o = this.options).onSettled) == null ? void 0 : m.call(o, f, d, h, g);
|
|
1521
1518
|
}
|
|
1522
1519
|
);
|
|
1523
|
-
return
|
|
1520
|
+
return ue(a, c).pipe(ce());
|
|
1524
1521
|
},
|
|
1525
1522
|
onSuccess: (f, d, h) => {
|
|
1526
1523
|
const g = V(
|
|
@@ -1540,7 +1537,7 @@ class tr {
|
|
|
1540
1537
|
return (o = (c = this.options).onSuccess) == null ? void 0 : o.call(c, f, d, h);
|
|
1541
1538
|
}
|
|
1542
1539
|
);
|
|
1543
|
-
return
|
|
1540
|
+
return ue(g, a).pipe(ce());
|
|
1544
1541
|
}
|
|
1545
1542
|
},
|
|
1546
1543
|
state: this.state,
|
|
@@ -1552,7 +1549,7 @@ class tr {
|
|
|
1552
1549
|
}),
|
|
1553
1550
|
P(this.destroySubject)
|
|
1554
1551
|
);
|
|
1555
|
-
this.state$ =
|
|
1552
|
+
this.state$ = O(s, u, i).pipe(
|
|
1556
1553
|
/**
|
|
1557
1554
|
* refCount as true somewhat make NEVER complete when there are
|
|
1558
1555
|
* no more observers. I thought I should have to complete manually (which is
|
|
@@ -1602,17 +1599,17 @@ const he = ({
|
|
|
1602
1599
|
status: e,
|
|
1603
1600
|
predicate: r,
|
|
1604
1601
|
exact: n = !0
|
|
1605
|
-
} = {}) => (i) => n && t !== void 0 && i.options.mutationKey !== void 0 && !
|
|
1602
|
+
} = {}) => (i) => n && t !== void 0 && i.options.mutationKey !== void 0 && !te(i.options.mutationKey, t, { exact: n }) || !n && t !== void 0 && i.options.mutationKey !== void 0 && !te(t, i.options.mutationKey, { exact: n }) || e && i.state.status !== e ? !1 : r ? r(i) : !0;
|
|
1606
1603
|
class rr {
|
|
1607
1604
|
constructor(e = {}) {
|
|
1608
1605
|
y(this, "mutationsSubject", new I([]));
|
|
1609
1606
|
y(this, "mutations$", this.mutationsSubject.pipe(
|
|
1610
1607
|
p((e) => e.map((r) => r)),
|
|
1611
|
-
|
|
1608
|
+
R(Le),
|
|
1612
1609
|
J()
|
|
1613
1610
|
));
|
|
1614
1611
|
y(this, "added$", this.mutations$.pipe(
|
|
1615
|
-
|
|
1612
|
+
oe(),
|
|
1616
1613
|
p(
|
|
1617
1614
|
([e, r]) => r.filter((n) => !e.includes(n))[0]
|
|
1618
1615
|
),
|
|
@@ -1620,11 +1617,11 @@ class rr {
|
|
|
1620
1617
|
J()
|
|
1621
1618
|
));
|
|
1622
1619
|
y(this, "removed$", this.mutations$.pipe(
|
|
1623
|
-
|
|
1620
|
+
oe(),
|
|
1624
1621
|
p(
|
|
1625
1622
|
([e, r]) => e.filter((n) => !r.includes(n))
|
|
1626
1623
|
),
|
|
1627
|
-
_((e) =>
|
|
1624
|
+
_((e) => ne(e)),
|
|
1628
1625
|
J()
|
|
1629
1626
|
));
|
|
1630
1627
|
y(this, "stateChange$", this.added$.pipe(
|
|
@@ -1661,7 +1658,7 @@ class rr {
|
|
|
1661
1658
|
)
|
|
1662
1659
|
),
|
|
1663
1660
|
// defaults to 5mn
|
|
1664
|
-
w(() =>
|
|
1661
|
+
w(() => ie(s.options.gcTime ?? 5 * 60 * 1e3)),
|
|
1665
1662
|
be(1)
|
|
1666
1663
|
).subscribe({
|
|
1667
1664
|
complete: () => {
|
|
@@ -1694,7 +1691,7 @@ class rr {
|
|
|
1694
1691
|
return { value$: this.stateChange$.pipe(
|
|
1695
1692
|
Ie(),
|
|
1696
1693
|
p(() => this.getAll().filter(n).map(s)),
|
|
1697
|
-
|
|
1694
|
+
R(T)
|
|
1698
1695
|
), lastValue: i };
|
|
1699
1696
|
}
|
|
1700
1697
|
/**
|
|
@@ -1702,7 +1699,7 @@ class rr {
|
|
|
1702
1699
|
* ISO api react-query
|
|
1703
1700
|
*/
|
|
1704
1701
|
subscribe(e) {
|
|
1705
|
-
const r =
|
|
1702
|
+
const r = O(
|
|
1706
1703
|
this.added$.pipe(
|
|
1707
1704
|
x((n) => {
|
|
1708
1705
|
e({
|
|
@@ -1741,7 +1738,7 @@ class rr {
|
|
|
1741
1738
|
predicate: (n) => n.state.isPaused
|
|
1742
1739
|
});
|
|
1743
1740
|
if (!e.length)
|
|
1744
|
-
return
|
|
1741
|
+
return M;
|
|
1745
1742
|
const r = e.map((n) => n.continue());
|
|
1746
1743
|
return Fe(r);
|
|
1747
1744
|
}
|
|
@@ -1765,10 +1762,10 @@ const nr = () => {
|
|
|
1765
1762
|
throw new Error("You forgot to start client");
|
|
1766
1763
|
const o = N(d), m = h ?? (g ? S(g) : Qe);
|
|
1767
1764
|
X.log("query$)", o);
|
|
1768
|
-
const
|
|
1765
|
+
const C = c.pipe(p((E) => ({ options: E })));
|
|
1769
1766
|
let b = () => {
|
|
1770
1767
|
};
|
|
1771
|
-
const
|
|
1768
|
+
const j = O(
|
|
1772
1769
|
a.pipe(
|
|
1773
1770
|
Bt({
|
|
1774
1771
|
queryStore: t,
|
|
@@ -1782,20 +1779,20 @@ const nr = () => {
|
|
|
1782
1779
|
})
|
|
1783
1780
|
).pipe(J());
|
|
1784
1781
|
return {
|
|
1785
|
-
result$:
|
|
1782
|
+
result$: O(
|
|
1786
1783
|
S({
|
|
1787
1784
|
type: "initial"
|
|
1788
1785
|
}),
|
|
1789
|
-
|
|
1786
|
+
j
|
|
1790
1787
|
).pipe(
|
|
1791
1788
|
Ht({
|
|
1792
1789
|
key: d,
|
|
1793
1790
|
queryStore: t,
|
|
1794
|
-
runner$:
|
|
1791
|
+
runner$: C,
|
|
1795
1792
|
serializedKey: o,
|
|
1796
1793
|
options$: c
|
|
1797
1794
|
}),
|
|
1798
|
-
p(([
|
|
1795
|
+
p(([E, Q]) => (Q && (b = Q), E)),
|
|
1799
1796
|
qt({
|
|
1800
1797
|
key: d,
|
|
1801
1798
|
options$: c,
|
|
@@ -1803,38 +1800,38 @@ const nr = () => {
|
|
|
1803
1800
|
serializedKey: o
|
|
1804
1801
|
}),
|
|
1805
1802
|
D(m, c),
|
|
1806
|
-
p(([
|
|
1807
|
-
p((
|
|
1808
|
-
trigger:
|
|
1809
|
-
options:
|
|
1810
|
-
}),
|
|
1811
|
-
$(({ options:
|
|
1803
|
+
p(([E, Q, z]) => ({ trigger: E, fn: Q, options: z })),
|
|
1804
|
+
p((E) => (X.log(o, "query trigger", {
|
|
1805
|
+
trigger: E.trigger,
|
|
1806
|
+
options: E.options
|
|
1807
|
+
}), E)),
|
|
1808
|
+
$(({ options: E }) => E.enabled !== !1),
|
|
1812
1809
|
_(
|
|
1813
|
-
({ fn:
|
|
1810
|
+
({ fn: E, options: Q, trigger: z }) => Nt({
|
|
1814
1811
|
options$: c,
|
|
1815
1812
|
options: Q,
|
|
1816
|
-
fn:
|
|
1813
|
+
fn: E,
|
|
1817
1814
|
queryStore: t,
|
|
1818
1815
|
serializedKey: o,
|
|
1819
1816
|
trigger: z,
|
|
1820
|
-
trigger$:
|
|
1817
|
+
trigger$: j
|
|
1821
1818
|
})
|
|
1822
1819
|
),
|
|
1823
1820
|
xt,
|
|
1824
1821
|
D(c),
|
|
1825
|
-
ve(([
|
|
1826
|
-
p(([
|
|
1822
|
+
ve(([E, Q]) => !(E.data !== void 0 && Q.terminateOnFirstResult), !0),
|
|
1823
|
+
p(([E]) => E),
|
|
1827
1824
|
ae(() => {
|
|
1828
1825
|
b();
|
|
1829
1826
|
})
|
|
1830
1827
|
)
|
|
1831
1828
|
};
|
|
1832
|
-
}, u =
|
|
1829
|
+
}, u = jt(
|
|
1833
1830
|
t,
|
|
1834
1831
|
(d) => d.pipe(
|
|
1835
1832
|
w((h) => {
|
|
1836
1833
|
const g = S(h);
|
|
1837
|
-
return
|
|
1834
|
+
return O(
|
|
1838
1835
|
Yt({
|
|
1839
1836
|
queryStore: t
|
|
1840
1837
|
})(g),
|
|
@@ -1867,14 +1864,14 @@ const nr = () => {
|
|
|
1867
1864
|
}
|
|
1868
1865
|
};
|
|
1869
1866
|
};
|
|
1870
|
-
var
|
|
1867
|
+
var re;
|
|
1871
1868
|
class Sr {
|
|
1872
1869
|
constructor({ mutationCache: e } = {
|
|
1873
1870
|
mutationCache: new rr()
|
|
1874
1871
|
}) {
|
|
1875
1872
|
y(this, "client");
|
|
1876
1873
|
y(this, "mutationCache");
|
|
1877
|
-
de(this,
|
|
1874
|
+
de(this, re, /* @__PURE__ */ new Map());
|
|
1878
1875
|
this.mutationCache = e, this.client = nr();
|
|
1879
1876
|
}
|
|
1880
1877
|
mount() {
|
|
@@ -1893,14 +1890,14 @@ class Sr {
|
|
|
1893
1890
|
};
|
|
1894
1891
|
}
|
|
1895
1892
|
getMutationDefaults(e) {
|
|
1896
|
-
const r = [...k(this,
|
|
1893
|
+
const r = [...k(this, re).values()];
|
|
1897
1894
|
let n = {};
|
|
1898
1895
|
return r.forEach((s) => {
|
|
1899
|
-
|
|
1896
|
+
te(e, s.mutationKey) && (n = { ...n, ...s.defaultOptions });
|
|
1900
1897
|
}), n;
|
|
1901
1898
|
}
|
|
1902
1899
|
setMutationDefaults(e, r) {
|
|
1903
|
-
k(this,
|
|
1900
|
+
k(this, re).set(N(e), {
|
|
1904
1901
|
mutationKey: e,
|
|
1905
1902
|
defaultOptions: r
|
|
1906
1903
|
});
|
|
@@ -1911,7 +1908,7 @@ class Sr {
|
|
|
1911
1908
|
clear() {
|
|
1912
1909
|
}
|
|
1913
1910
|
}
|
|
1914
|
-
|
|
1911
|
+
re = new WeakMap();
|
|
1915
1912
|
export {
|
|
1916
1913
|
rr as MutationCache,
|
|
1917
1914
|
Sr as QueryClient,
|
|
@@ -1934,7 +1931,7 @@ export {
|
|
|
1934
1931
|
$r as useQuery,
|
|
1935
1932
|
Pe as useQueryClient,
|
|
1936
1933
|
fr as useSignalValue,
|
|
1937
|
-
|
|
1934
|
+
Oe as useSubject,
|
|
1938
1935
|
Se as useSubscribe,
|
|
1939
1936
|
vr as useSubscribeEffect,
|
|
1940
1937
|
mr as useUnmountObservable
|
|
@@ -38,5 +38,4 @@ export declare class MutationObserver<TData = unknown, TError = DefaultError, TV
|
|
|
38
38
|
mutate(variables: TVariables, options?: MutateOptions<TData, TError, TVariables, TContext>): Promise<TData>;
|
|
39
39
|
getCurrentResult(): MutationObserverResult<TData, TError, TVariables, TContext>;
|
|
40
40
|
reset(): void;
|
|
41
|
-
cancel(): void;
|
|
42
41
|
}
|