UNPKG

sui-explorer-local

Version:
2 lines (1 loc) 12.5 kB
var X=(e,t,s)=>{if(!t.has(e))throw TypeError("Cannot "+s)};var i=(e,t,s)=>(X(e,t,"read from private field"),s?s.call(e):t.get(e)),o=(e,t,s)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,s)},n=(e,t,s,r)=>(X(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s);var W=(e,t,s,r)=>({set _(a){n(e,t,a,s)},get _(){return i(e,t,r)}}),w=(e,t,s)=>(X(e,t,"access private method"),s);import{b as ht,h as ot,c as lt,d as f,m as Y,R as dt,e as ft,f as yt,g as Z,i as Q,s as ct,j as pt,k as mt,l as gt,o as tt,p as vt,q as et,r as st}from"./index-d4ae957a.js";var v,rt,Pt=(rt=class extends ht{constructor(t={}){super();o(this,v,void 0);this.config=t,n(this,v,new Map)}build(t,s,r){const a=s.queryKey,c=s.queryHash??ot(a,s);let l=this.get(c);return l||(l=new lt({cache:this,queryKey:a,queryHash:c,options:t.defaultQueryOptions(s),state:r,defaultOptions:t.getQueryDefaults(a)}),this.add(l)),l}add(t){i(this,v).has(t.queryHash)||(i(this,v).set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const s=i(this,v).get(t.queryHash);s&&(t.destroy(),s===t&&i(this,v).delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){f.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return i(this,v).get(t)}getAll(){return[...i(this,v).values()]}find(t){const s={exact:!0,...t};return this.getAll().find(r=>Y(s,r))}findAll(t={}){const s=this.getAll();return Object.keys(t).length>0?s.filter(r=>Y(t,r)):s}notify(t){f.batch(()=>{this.listeners.forEach(s=>{s(t)})})}onFocus(){f.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){f.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},v=new WeakMap,rt),P,U,y,K,O,M,at,Ot=(at=class extends dt{constructor(t){super();o(this,O);o(this,P,void 0);o(this,U,void 0);o(this,y,void 0);o(this,K,void 0);this.mutationId=t.mutationId,n(this,U,t.defaultOptions),n(this,y,t.mutationCache),n(this,P,[]),this.state=t.state||bt(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options={...i(this,U),...t},this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){i(this,P).includes(t)||(i(this,P).push(t),this.clearGcTimeout(),i(this,y).notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){n(this,P,i(this,P).filter(s=>s!==t)),this.scheduleGc(),i(this,y).notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){i(this,P).length||(this.state.status==="pending"?this.scheduleGc():i(this,y).remove(this))}continue(){var t;return((t=i(this,K))==null?void 0:t.continue())??this.execute(this.state.variables)}async execute(t){var a,c,l,x,$,S,z,J,R,b,j,G,B,_,N,d,m,g,D,V;const s=()=>(n(this,K,ft({fn:()=>this.options.mutationFn?this.options.mutationFn(t):Promise.reject(new Error("No mutationFn found")),onFail:(h,A)=>{w(this,O,M).call(this,{type:"failed",failureCount:h,error:A})},onPause:()=>{w(this,O,M).call(this,{type:"pause"})},onContinue:()=>{w(this,O,M).call(this,{type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode})),i(this,K).promise),r=this.state.status==="pending";try{if(!r){w(this,O,M).call(this,{type:"pending",variables:t}),await((c=(a=i(this,y).config).onMutate)==null?void 0:c.call(a,t,this));const A=await((x=(l=this.options).onMutate)==null?void 0:x.call(l,t));A!==this.state.context&&w(this,O,M).call(this,{type:"pending",context:A,variables:t})}const h=await s();return await((S=($=i(this,y).config).onSuccess)==null?void 0:S.call($,h,t,this.state.context,this)),await((J=(z=this.options).onSuccess)==null?void 0:J.call(z,h,t,this.state.context)),await((b=(R=i(this,y).config).onSettled)==null?void 0:b.call(R,h,null,this.state.variables,this.state.context,this)),await((G=(j=this.options).onSettled)==null?void 0:G.call(j,h,null,t,this.state.context)),w(this,O,M).call(this,{type:"success",data:h}),h}catch(h){try{throw await((_=(B=i(this,y).config).onError)==null?void 0:_.call(B,h,t,this.state.context,this)),await((d=(N=this.options).onError)==null?void 0:d.call(N,h,t,this.state.context)),await((g=(m=i(this,y).config).onSettled)==null?void 0:g.call(m,void 0,h,this.state.variables,this.state.context,this)),await((V=(D=this.options).onSettled)==null?void 0:V.call(D,void 0,h,t,this.state.context)),h}finally{w(this,O,M).call(this,{type:"error",error:h})}}}},P=new WeakMap,U=new WeakMap,y=new WeakMap,K=new WeakMap,O=new WeakSet,M=function(t){const s=r=>{switch(t.type){case"failed":return{...r,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:!yt(this.options.networkMode),status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...r,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:t.error,failureCount:r.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=s(this.state),f.batch(()=>{i(this,P).forEach(r=>{r.onMutationUpdate(t)}),i(this,y).notify({mutation:this,type:"updated",action:t})})},at);function bt(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var p,L,E,nt,Qt=(nt=class extends ht{constructor(t={}){super();o(this,p,void 0);o(this,L,void 0);o(this,E,void 0);this.config=t,n(this,p,[]),n(this,L,0)}build(t,s,r){const a=new Ot({mutationCache:this,mutationId:++W(this,L)._,options:t.defaultMutationOptions(s),state:r});return this.add(a),a}add(t){i(this,p).push(t),this.notify({type:"added",mutation:t})}remove(t){n(this,p,i(this,p).filter(s=>s!==t)),this.notify({type:"removed",mutation:t})}clear(){f.batch(()=>{i(this,p).forEach(t=>{this.remove(t)})})}getAll(){return i(this,p)}find(t){const s={exact:!0,...t};return i(this,p).find(r=>Z(s,r))}findAll(t={}){return i(this,p).filter(s=>Z(t,s))}notify(t){f.batch(()=>{this.listeners.forEach(s=>{s(t)})})}resumePausedMutations(){return n(this,E,(i(this,E)??Promise.resolve()).then(()=>{const t=i(this,p).filter(s=>s.state.isPaused);return f.batch(()=>t.reduce((s,r)=>s.then(()=>r.continue().catch(Q)),Promise.resolve()))}).then(()=>{n(this,E,void 0)})),i(this,E)}},p=new WeakMap,L=new WeakMap,E=new WeakMap,nt);function wt(e){return{onFetch:(t,s)=>{const r=async()=>{var j,G,B,_,N;const a=t.options,c=(B=(G=(j=t.fetchOptions)==null?void 0:j.meta)==null?void 0:G.fetchMore)==null?void 0:B.direction,l=((_=t.state.data)==null?void 0:_.pages)||[],x=((N=t.state.data)==null?void 0:N.pageParams)||[],$={pages:[],pageParams:[]};let S=!1;const z=d=>{Object.defineProperty(d,"signal",{enumerable:!0,get:()=>(t.signal.aborted?S=!0:t.signal.addEventListener("abort",()=>{S=!0}),t.signal)})},J=t.options.queryFn&&t.options.queryFn!==ct?t.options.queryFn:()=>Promise.reject(new Error(`Missing queryFn: '${t.options.queryHash}'`)),R=async(d,m,g)=>{if(S)return Promise.reject();if(m==null&&d.pages.length)return Promise.resolve(d);const D={queryKey:t.queryKey,pageParam:m,direction:g?"backward":"forward",meta:t.options.meta};z(D);const V=await J(D),{maxPages:h}=t.options,A=g?pt:mt;return{pages:A(d.pages,V,h),pageParams:A(d.pageParams,m,h)}};let b;if(c&&l.length){const d=c==="backward",m=d?Mt:it,g={pages:l,pageParams:x},D=m(a,g);b=await R(g,D,d)}else{b=await R($,x[0]??a.initialPageParam);const d=e??l.length;for(let m=1;m<d;m++){const g=it(a,b);b=await R(b,g)}}return b};t.options.persister?t.fetchFn=()=>{var a,c;return(c=(a=t.options).persister)==null?void 0:c.call(a,r,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},s)}:t.fetchFn=r}}}function it(e,{pages:t,pageParams:s}){const r=t.length-1;return e.getNextPageParam(t[r],t,s[r],s)}function Mt(e,{pages:t,pageParams:s}){var r;return(r=e.getPreviousPageParam)==null?void 0:r.call(e,t[0],t,s[0],s)}var u,q,F,T,k,C,H,I,ut,Ct=(ut=class{constructor(e={}){o(this,u,void 0);o(this,q,void 0);o(this,F,void 0);o(this,T,void 0);o(this,k,void 0);o(this,C,void 0);o(this,H,void 0);o(this,I,void 0);n(this,u,e.queryCache||new Pt),n(this,q,e.mutationCache||new Qt),n(this,F,e.defaultOptions||{}),n(this,T,new Map),n(this,k,new Map),n(this,C,0)}mount(){W(this,C)._++,i(this,C)===1&&(n(this,H,gt.subscribe(async e=>{e&&(await this.resumePausedMutations(),i(this,u).onFocus())})),n(this,I,tt.subscribe(async e=>{e&&(await this.resumePausedMutations(),i(this,u).onOnline())})))}unmount(){var e,t;W(this,C)._--,i(this,C)===0&&((e=i(this,H))==null||e.call(this),n(this,H,void 0),(t=i(this,I))==null||t.call(this),n(this,I,void 0))}isFetching(e){return i(this,u).findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return i(this,q).findAll({...e,status:"pending"}).length}getQueryData(e){var s;const t=this.defaultQueryOptions({queryKey:e});return(s=i(this,u).get(t.queryHash))==null?void 0:s.state.data}ensureQueryData(e){const t=this.getQueryData(e.queryKey);if(t===void 0)return this.fetchQuery(e);{const s=this.defaultQueryOptions(e),r=i(this,u).build(this,s);return e.revalidateIfStale&&r.isStaleByTime(s.staleTime)&&this.prefetchQuery(s),Promise.resolve(t)}}getQueriesData(e){return i(this,u).findAll(e).map(({queryKey:t,state:s})=>{const r=s.data;return[t,r]})}setQueryData(e,t,s){const r=this.defaultQueryOptions({queryKey:e}),a=i(this,u).get(r.queryHash),c=a==null?void 0:a.state.data,l=vt(t,c);if(l!==void 0)return i(this,u).build(this,r).setData(l,{...s,manual:!0})}setQueriesData(e,t,s){return f.batch(()=>i(this,u).findAll(e).map(({queryKey:r})=>[r,this.setQueryData(r,t,s)]))}getQueryState(e){var s;const t=this.defaultQueryOptions({queryKey:e});return(s=i(this,u).get(t.queryHash))==null?void 0:s.state}removeQueries(e){const t=i(this,u);f.batch(()=>{t.findAll(e).forEach(s=>{t.remove(s)})})}resetQueries(e,t){const s=i(this,u),r={type:"active",...e};return f.batch(()=>(s.findAll(e).forEach(a=>{a.reset()}),this.refetchQueries(r,t)))}cancelQueries(e={},t={}){const s={revert:!0,...t},r=f.batch(()=>i(this,u).findAll(e).map(a=>a.cancel(s)));return Promise.all(r).then(Q).catch(Q)}invalidateQueries(e={},t={}){return f.batch(()=>{if(i(this,u).findAll(e).forEach(r=>{r.invalidate()}),e.refetchType==="none")return Promise.resolve();const s={...e,type:e.refetchType??e.type??"active"};return this.refetchQueries(s,t)})}refetchQueries(e={},t){const s={...t,cancelRefetch:(t==null?void 0:t.cancelRefetch)??!0},r=f.batch(()=>i(this,u).findAll(e).filter(a=>!a.isDisabled()).map(a=>{let c=a.fetch(void 0,s);return s.throwOnError||(c=c.catch(Q)),a.state.fetchStatus==="paused"?Promise.resolve():c}));return Promise.all(r).then(Q)}fetchQuery(e){const t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);const s=i(this,u).build(this,t);return s.isStaleByTime(t.staleTime)?s.fetch(t):Promise.resolve(s.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Q).catch(Q)}fetchInfiniteQuery(e){return e.behavior=wt(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Q).catch(Q)}resumePausedMutations(){return tt.isOnline()?i(this,q).resumePausedMutations():Promise.resolve()}getQueryCache(){return i(this,u)}getMutationCache(){return i(this,q)}getDefaultOptions(){return i(this,F)}setDefaultOptions(e){n(this,F,e)}setQueryDefaults(e,t){i(this,T).set(et(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...i(this,T).values()];let s={};return t.forEach(r=>{st(e,r.queryKey)&&(s={...s,...r.defaultOptions})}),s}setMutationDefaults(e,t){i(this,k).set(et(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...i(this,k).values()];let s={};return t.forEach(r=>{st(e,r.mutationKey)&&(s={...s,...r.defaultOptions})}),s}defaultQueryOptions(e){if(e._defaulted)return e;const t={...i(this,F).queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=ot(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.enabled!==!0&&t.queryFn===ct&&(t.enabled=!1),t}defaultMutationOptions(e){return e!=null&&e._defaulted?e:{...i(this,F).mutations,...(e==null?void 0:e.mutationKey)&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){i(this,u).clear(),i(this,q).clear()}},u=new WeakMap,q=new WeakMap,F=new WeakMap,T=new WeakMap,k=new WeakMap,C=new WeakMap,H=new WeakMap,I=new WeakMap,ut);export{Ct as Q};