UNPKG

@xcpcio/board-app

Version:
2 lines (1 loc) 11 kB
var ut=i=>{throw TypeError(i)};var Y=(i,t,e)=>t.has(i)||ut("Cannot "+e);var s=(i,t,e)=>(Y(i,t,"read from private field"),e?e.call(i):t.get(i)),b=(i,t,e)=>t.has(i)?ut("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e),c=(i,t,e,n)=>(Y(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e),d=(i,t,e)=>(Y(i,t,"access private method"),e);import{a4 as St,a5 as ct,a6 as w,a7 as q,a8 as K,a9 as wt,aa as lt,ab as ft,ac as Ct,ad as It,ae as Tt,af as dt,ag as Et,ah as Qt,ai as Dt,aj as Ut,f as Rt,ak as Ft,al as jt,C as H,am as pt,an as xt,ao as bt,ap as Pt}from"./index-CYsJ2gG-.js";import{a as Lt}from"./constant-2MSuUQN9.js";import{u as gt}from"./index-DXMw63yv.js";var v,r,B,y,D,A,T,S,V,_,k,U,F,E,N,u,W,J,X,Z,tt,et,st,it,Ot,vt,Mt=(vt=class extends St{constructor(t,e){super();b(this,u);b(this,v);b(this,r);b(this,B);b(this,y);b(this,D);b(this,A);b(this,T);b(this,S);b(this,V);b(this,_);b(this,k);b(this,U);b(this,F);b(this,E);b(this,N,new Set);this.options=e,c(this,v,t),c(this,S,null),c(this,T,ct()),this.options.experimental_prefetchInRender||s(this,T).reject(new Error("experimental_prefetchInRender feature flag is not enabled")),this.bindMethods(),this.setOptions(e)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(s(this,r).addObserver(this),mt(s(this,r),this.options)?d(this,u,W).call(this):this.updateResult(),d(this,u,tt).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return nt(s(this,r),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return nt(s(this,r),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,d(this,u,et).call(this),d(this,u,st).call(this),s(this,r).removeObserver(this)}setOptions(t){const e=this.options,n=s(this,r);if(this.options=s(this,v).defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof w(this.options.enabled,s(this,r))!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");d(this,u,it).call(this),s(this,r).setOptions(this.options),e._defaulted&&!q(this.options,e)&&s(this,v).getQueryCache().notify({type:"observerOptionsUpdated",query:s(this,r),observer:this});const o=this.hasListeners();o&&yt(s(this,r),n,this.options,e)&&d(this,u,W).call(this),this.updateResult(),o&&(s(this,r)!==n||w(this.options.enabled,s(this,r))!==w(e.enabled,s(this,r))||K(this.options.staleTime,s(this,r))!==K(e.staleTime,s(this,r)))&&d(this,u,J).call(this);const a=d(this,u,X).call(this);o&&(s(this,r)!==n||w(this.options.enabled,s(this,r))!==w(e.enabled,s(this,r))||a!==s(this,E))&&d(this,u,Z).call(this,a)}getOptimisticResult(t){const e=s(this,v).getQueryCache().build(s(this,v),t),n=this.createResult(e,t);return At(this,n)&&(c(this,y,n),c(this,A,this.options),c(this,D,s(this,r).state)),n}getCurrentResult(){return s(this,y)}trackResult(t,e){const n={};return Object.keys(t).forEach(o=>{Object.defineProperty(n,o,{configurable:!1,enumerable:!0,get:()=>(this.trackProp(o),e==null||e(o),t[o])})}),n}trackProp(t){s(this,N).add(t)}getCurrentQuery(){return s(this,r)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const e=s(this,v).defaultQueryOptions(t),n=s(this,v).getQueryCache().build(s(this,v),e);return n.fetch().then(()=>this.createResult(n,e))}fetch(t){return d(this,u,W).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),s(this,y)))}createResult(t,e){var ht;const n=s(this,r),o=this.options,a=s(this,y),l=s(this,D),R=s(this,A),j=t!==n?t.state:s(this,B),{state:p}=t;let f={...p},Q=!1,h;if(e._optimisticResults){const m=this.hasListeners(),M=!m&&mt(t,e),$=m&&yt(t,n,e,o);(M||$)&&(f={...f,...Tt(p.data,t.options)}),e._optimisticResults==="isRestoring"&&(f.fetchStatus="idle")}let{error:I,errorUpdatedAt:x,status:g}=f;if(e.select&&f.data!==void 0)if(a&&f.data===(l==null?void 0:l.data)&&e.select===s(this,V))h=s(this,_);else try{c(this,V,e.select),h=e.select(f.data),h=dt(a==null?void 0:a.data,h,e),c(this,_,h),c(this,S,null)}catch(m){c(this,S,m)}else h=f.data;if(e.placeholderData!==void 0&&h===void 0&&g==="pending"){let m;if(a!=null&&a.isPlaceholderData&&e.placeholderData===(R==null?void 0:R.placeholderData))m=a.data;else if(m=typeof e.placeholderData=="function"?e.placeholderData((ht=s(this,k))==null?void 0:ht.state.data,s(this,k)):e.placeholderData,e.select&&m!==void 0)try{m=e.select(m),c(this,S,null)}catch(M){c(this,S,M)}m!==void 0&&(g="success",h=dt(a==null?void 0:a.data,m,e),Q=!0)}s(this,S)&&(I=s(this,S),h=s(this,_),x=Date.now(),g="error");const P=f.fetchStatus==="fetching",L=g==="pending",G=g==="error",rt=L&&P,ot=h!==void 0,O={status:g,fetchStatus:f.fetchStatus,isPending:L,isSuccess:g==="success",isError:G,isInitialLoading:rt,isLoading:rt,data:h,dataUpdatedAt:f.dataUpdatedAt,error:I,errorUpdatedAt:x,failureCount:f.fetchFailureCount,failureReason:f.fetchFailureReason,errorUpdateCount:f.errorUpdateCount,isFetched:f.dataUpdateCount>0||f.errorUpdateCount>0,isFetchedAfterMount:f.dataUpdateCount>j.dataUpdateCount||f.errorUpdateCount>j.errorUpdateCount,isFetching:P,isRefetching:P&&!L,isLoadingError:G&&!ot,isPaused:f.fetchStatus==="paused",isPlaceholderData:Q,isRefetchError:G&&ot,isStale:at(t,e),refetch:this.refetch,promise:s(this,T)};if(this.options.experimental_prefetchInRender){const m=z=>{O.status==="error"?z.reject(O.error):O.data!==void 0&&z.resolve(O.data)},M=()=>{const z=c(this,T,O.promise=ct());m(z)},$=s(this,T);switch($.status){case"pending":t.queryHash===n.queryHash&&m($);break;case"fulfilled":(O.status==="error"||O.data!==$.value)&&M();break;case"rejected":(O.status!=="error"||O.error!==$.reason)&&M();break}}return O}updateResult(){const t=s(this,y),e=this.createResult(s(this,r),this.options);if(c(this,D,s(this,r).state),c(this,A,this.options),s(this,D).data!==void 0&&c(this,k,s(this,r)),q(e,t))return;c(this,y,e);const n=()=>{if(!t)return!0;const{notifyOnChangeProps:o}=this.options,a=typeof o=="function"?o():o;if(a==="all"||!a&&!s(this,N).size)return!0;const l=new Set(a??s(this,N));return this.options.throwOnError&&l.add("error"),Object.keys(s(this,y)).some(R=>{const C=R;return s(this,y)[C]!==t[C]&&l.has(C)})};d(this,u,Ot).call(this,{listeners:n()})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&d(this,u,tt).call(this)}},v=new WeakMap,r=new WeakMap,B=new WeakMap,y=new WeakMap,D=new WeakMap,A=new WeakMap,T=new WeakMap,S=new WeakMap,V=new WeakMap,_=new WeakMap,k=new WeakMap,U=new WeakMap,F=new WeakMap,E=new WeakMap,N=new WeakMap,u=new WeakSet,W=function(t){d(this,u,it).call(this);let e=s(this,r).fetch(this.options,t);return t!=null&&t.throwOnError||(e=e.catch(wt)),e},J=function(){d(this,u,et).call(this);const t=K(this.options.staleTime,s(this,r));if(lt||s(this,y).isStale||!ft(t))return;const n=Ct(s(this,y).dataUpdatedAt,t)+1;c(this,U,setTimeout(()=>{s(this,y).isStale||this.updateResult()},n))},X=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(s(this,r)):this.options.refetchInterval)??!1},Z=function(t){d(this,u,st).call(this),c(this,E,t),!(lt||w(this.options.enabled,s(this,r))===!1||!ft(s(this,E))||s(this,E)===0)&&c(this,F,setInterval(()=>{(this.options.refetchIntervalInBackground||It.isFocused())&&d(this,u,W).call(this)},s(this,E)))},tt=function(){d(this,u,J).call(this),d(this,u,Z).call(this,d(this,u,X).call(this))},et=function(){s(this,U)&&(clearTimeout(s(this,U)),c(this,U,void 0))},st=function(){s(this,F)&&(clearInterval(s(this,F)),c(this,F,void 0))},it=function(){const t=s(this,v).getQueryCache().build(s(this,v),this.options);if(t===s(this,r))return;const e=s(this,r);c(this,r,t),c(this,B,t.state),this.hasListeners()&&(e==null||e.removeObserver(this),t.addObserver(this))},Ot=function(t){Et.batch(()=>{t.listeners&&this.listeners.forEach(e=>{e(s(this,y))}),s(this,v).getQueryCache().notify({query:s(this,r),type:"observerResultsUpdated"})})},vt);function $t(i,t){return w(t.enabled,i)!==!1&&i.state.data===void 0&&!(i.state.status==="error"&&t.retryOnMount===!1)}function mt(i,t){return $t(i,t)||i.state.data!==void 0&&nt(i,t,t.refetchOnMount)}function nt(i,t,e){if(w(t.enabled,i)!==!1){const n=typeof e=="function"?e(i):e;return n==="always"||n!==!1&&at(i,t)}return!1}function yt(i,t,e,n){return(i!==t||w(n.enabled,i)===!1)&&(!e.suspense||i.state.status!=="error")&&at(i,e)}function at(i,t){return w(t.enabled,i)!==!1&&i.isStaleByTime(K(t.staleTime,i))}function At(i,t){return!q(i.getCurrentResult(),t)}function _t(i=""){if(!Qt())throw new Error("vue-query hooks can only be used inside setup() function or functions that support injection context.");const t=Ut(i),e=Dt(t);if(!e)throw new Error("No 'queryClient' found in Vue context, use 'VueQueryPlugin' to properly initialize the library.");return e}function kt(i,t,e){const n=_t(),o=Rt(()=>{const h=Ft(t);typeof h.enabled=="function"&&(h.enabled=h.enabled());const I=n.defaultQueryOptions(h);return I._optimisticResults=n.isRestoring.value?"isRestoring":"optimistic",I}),a=new i(n,o.value),l=jt(a.getCurrentResult());let R=()=>{};H(n.isRestoring,h=>{h||(R(),R=a.subscribe(I=>{pt(l,I)}))},{immediate:!0});const C=()=>{a.setOptions(o.value),pt(l,a.getCurrentResult())};H(o,C),xt(()=>{R()});const j=(...h)=>(C(),l.refetch(...h)),p=()=>new Promise((h,I)=>{let x=()=>{};const g=()=>{if(o.value.enabled!==!1){a.setOptions(o.value);const P=a.getOptimisticResult(o.value);P.isStale?(x(),a.fetchOptimistic(o.value).then(h,L=>{bt(o.value.throwOnError,[L,a.getCurrentQuery()])?I(L):h(a.getCurrentResult())})):(x(),h(P))}};g(),x=H(o,g)});H(()=>l.error,h=>{if(l.isError&&!l.isFetching&&bt(o.value.throwOnError,[h,a.getCurrentQuery()]))throw h});const Q=Pt(l);for(const h in l)typeof l[h]=="function"&&(Q[h]=l[h]);return Q.suspense=p,Q.refetch=j,Q}function Nt(i,t){return kt(Mt,i)}const Wt=3;async function Bt(i,t){const e=i.startsWith("/")?i.slice(1):i;let n=`${window.DATA_HOST}${e}`;const o={allInOne:!1};if(n.includes("#")){const p=new URLSearchParams(n.split("#")[1]);o.allInOne=p.get("allInOne")==="true",n=n.split("#")[0]}i.startsWith("http")&&(n=i),n.endsWith("/")&&(n=n.slice(0,-1));const a=p=>p.includes("?")?`${p}&t=${t??0}`:`${p}?t=${t??0}`,l=o.allInOne?[await fetch(a(n))]:[await fetch(a(`${n}/config.json`)),await fetch(a(`${n}/team.json`)),await fetch(a(`${n}/run.json`))],{status:R,statusText:C}=l[0];if(R>=300||R<200)throw new Error(`fetch data failed. [status=${R}] [statusText=${C}]`);return Promise.all(l.map(p=>p.json())).then(p=>o.allInOne?p[0]:{contest:p[0],teams:p[1],submissions:p[2]})}function Yt(i,t,e=!1){let n=3e4,o=n;const a=Rt(()=>Math.floor(t.value.getTime()/1e3/10));return Lt.value==="I18N"&&(n=10*1e3,o=n),e&&(n=Number.POSITIVE_INFINITY,o=!1),Nt({queryKey:[i,a.value],queryFn:()=>Bt(i,a.value),retry:Wt,staleTime:n,refetchInterval:o})}function qt(){return gt("data-source","",{transform:String})}function Jt(){return gt("battle-of-giants","",{transform:String})}export{Jt as a,qt as g,Yt as u};