1 line
8.9 KiB
JavaScript
1 line
8.9 KiB
JavaScript
|
|
import{An as e,Cn as t,Dn as n,En as r,Fn as i,In as a,Ln as o,Mn as s,Nn as c,On as l,Pn as u,Rn as d,Sn as f,Tn as p,Vn as m,bn as h,jn as g,kn as _,qn as v,wn as y,xn as b,zn as x}from"./index-BaTxSAlR.js";var S,C,w,T,E,D,O,k,A,j,M,N,P,F,I,L=(S=new WeakMap,C=new WeakMap,w=new WeakMap,T=new WeakMap,E=new WeakMap,D=new WeakMap,O=new WeakMap,k=new WeakMap,A=new WeakMap,j=new WeakMap,M=new WeakMap,N=new WeakMap,P=new WeakMap,F=new WeakMap,I=new WeakSet,class extends y{constructor(e,t){super(),b(this,I),o(this,S,void 0),o(this,C,void 0),o(this,w,void 0),o(this,T,void 0),o(this,E,void 0),o(this,D,void 0),o(this,O,void 0),o(this,k,void 0),o(this,A,void 0),o(this,j,void 0),o(this,M,void 0),o(this,N,void 0),o(this,P,void 0),o(this,F,new Set),this.options=t,u(S,this,e),u(O,this,null),this.bindMethods(),this.setOptions(t)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(i(C,this).addObserver(this),J(i(C,this),this.options)?a(I,this,R).call(this):this.updateResult(),a(I,this,U).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return Y(i(C,this),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return Y(i(C,this),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,a(I,this,W).call(this),a(I,this,G).call(this),i(C,this).removeObserver(this)}setOptions(t){let n=this.options,r=i(C,this);if(this.options=i(S,this).defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!=`boolean`&&typeof this.options.enabled!=`function`&&typeof _(this.options.enabled,i(C,this))!=`boolean`)throw Error(`Expected enabled to be a boolean or a callback that returns a boolean`);a(I,this,K).call(this),i(C,this).setOptions(this.options),n._defaulted&&!e(this.options,n)&&i(S,this).getQueryCache().notify({type:`observerOptionsUpdated`,query:i(C,this),observer:this});let o=this.hasListeners();o&&X(i(C,this),r,this.options,n)&&a(I,this,R).call(this),this.updateResult(),o&&(i(C,this)!==r||_(this.options.enabled,i(C,this))!==_(n.enabled,i(C,this))||_(this.options.staleTime,i(C,this))!==_(n.staleTime,i(C,this)))&&a(I,this,B).call(this);let s=a(I,this,V).call(this);o&&(i(C,this)!==r||_(this.options.enabled,i(C,this))!==_(n.enabled,i(C,this))||s!==i(P,this))&&a(I,this,H).call(this,s)}getOptimisticResult(t){let n=i(S,this).getQueryCache().build(i(S,this),t),r=this.createResult(n,t);return e(this.getCurrentResult(),r)||(u(T,this,r),u(D,this,this.options),u(E,this,i(C,this).state)),r}getCurrentResult(){return i(T,this)}trackResult(e,t){return new Proxy(e,{get:(e,n)=>(this.trackProp(n),t==null||t(n),Reflect.get(e,n))})}trackProp(e){i(F,this).add(e)}getCurrentQuery(){return i(C,this)}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=i(S,this).defaultQueryOptions(e),n=i(S,this).getQueryCache().build(i(S,this),t),r=()=>{},a,o=new Promise(e=>{a=e,r=i(S,this).getQueryCache().subscribe(i=>{i.type===`updated`&&i.query.queryHash===n.queryHash&&n.state.data!==void 0&&(r(),e(this.createResult(n,t)))})});return Promise.race([n.fetch(t).then(()=>{let e=this.createResult(n,t);return a==null||a(e),e}).finally(()=>{r()}),o])}fetch(e){return a(I,this,R).call(this,{...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),i(T,this)))}createResult(e,t){let n=i(C,this),r=this.options,a=i(T,this),o=i(E,this),s=i(D,this),c=e===n?i(w,this):e.state,{state:d}=e,f={...d},p=!1,m;if(t._optimisticResults){let i=this.hasListeners(),a=!i&&J(e,t),o=i&&X(e,n,t,r);(a||o)&&(f={...f,...h(d.data,e.options)}),t._optimisticResults===`isRestoring`&&(f.fetchStatus=`idle`)}let{error:g,errorUpdatedAt:v,status:y}=f;m=f.data;let b=!1;if(t.placeholderData!==void 0&&m===void 0&&y===`pending`){var x;let e;a!=null&&a.isPlaceholderData&&t.placeholderData===(s==null?void 0:s.placeholderData)?(e=a.data,b=!0):e=typeof t.placeholderData==`function`?t.placeholderData((x=i(j,this))==null?void 0:x.state.data,i(j,this)):t.placeholderData,e!==void 0&&(y=`success`,m=l(a==null?void 0:a.data,e,t),p=!0)}if(t.select&&m!==void 0&&!b)if(a&&m===(o
|