UNPKG

@clerk/clerk-js

Version:
1 lines • 34.4 kB
"use strict";(globalThis.rspackChunk_clerk_clerk_js=globalThis.rspackChunk_clerk_clerk_js||[]).push([[662],{638(t,e,i){let s,r,n,a,o,l,u;function h(t,e,i){if(!e.has(t))throw TypeError("attempted to "+i+" private field on non-instance");return e.get(t)}function c(t,e){var i=h(t,e,"get");return i.get?i.get.call(t):i.value}function d(t,e,i){if(e.has(t))throw TypeError("Cannot initialize the same private elements twice on an object");e.set(t,i)}i.d(e,{E:()=>ea}),i(6395),i(3560),i(2949),i(7891),i(4086),i(8723),i(4330),i(6455),i(1178),i(5254);var f,p,y,w,m,g,b,O,E,T,M,P,k,S,F,C,q,A,j,W,D,Q,R,x,_,U,I,K,H,L,G,z,N,B,J,V,X={setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t),setInterval:(t,e)=>setInterval(t,e),clearInterval:t=>clearInterval(t)},Y=new(f=new WeakMap,p=new WeakMap,class{setTimeoutProvider(t){var e=this,i=f,s=t,r=h(e,i,"set");if(r.set)r.set.call(e,s);else{if(!r.writable)throw TypeError("attempted to set read only private field");r.value=s}}setTimeout(t,e){return c(this,f).setTimeout(t,e)}clearTimeout(t){c(this,f).clearTimeout(t)}setInterval(t,e){return c(this,f).setInterval(t,e)}clearInterval(t){c(this,f).clearInterval(t)}constructor(){d(this,f,{writable:!0,value:X}),d(this,p,{writable:!0,value:!1})}}),Z="u"<typeof window||"Deno"in globalThis;function $(){}function tt(t,e){return"function"==typeof t?t(e):t}function te(t,e){let{type:i="all",exact:s,fetchStatus:r,predicate:n,queryKey:a,stale:o}=t;if(a){if(s){if(e.queryHash!==ts(a,e.options))return!1}else if(!tn(e.queryKey,a))return!1}if("all"!==i){let t=e.isActive();if("active"===i&&!t||"inactive"===i&&t)return!1}return("boolean"!=typeof o||e.isStale()===o)&&(!r||r===e.state.fetchStatus)&&(!n||!!n(e))}function ti(t,e){let{exact:i,status:s,predicate:r,mutationKey:n}=t;if(n){if(!e.options.mutationKey)return!1;if(i){if(tr(e.options.mutationKey)!==tr(n))return!1}else if(!tn(e.options.mutationKey,n))return!1}return(!s||e.state.status===s)&&(!r||!!r(e))}function ts(t,e){return((null==e?void 0:e.queryKeyHashFn)||tr)(t)}function tr(t){return JSON.stringify(t,(t,e)=>tl(e)?Object.keys(e).sort().reduce((t,i)=>(t[i]=e[i],t),{}):e)}function tn(t,e){return t===e||typeof t==typeof e&&!!t&&!!e&&"object"==typeof t&&"object"==typeof e&&Object.keys(e).every(i=>tn(t[i],e[i]))}var ta=Object.prototype.hasOwnProperty;function to(t){return Array.isArray(t)&&t.length===Object.keys(t).length}function tl(t){if(!tu(t))return!1;let e=t.constructor;if(void 0===e)return!0;let i=e.prototype;return!!tu(i)&&!!i.hasOwnProperty("isPrototypeOf")&&Object.getPrototypeOf(t)===Object.prototype}function tu(t){return"[object Object]"===Object.prototype.toString.call(t)}function th(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=[...t,e];return i&&s.length>i?s.slice(1):s}function tc(t,e){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=[e,...t];return i&&s.length>i?s.slice(0,-1):s}var td=Symbol();function tf(t,e){return!t.queryFn&&(null==e?void 0:e.initialPromise)?()=>e.initialPromise:t.queryFn&&t.queryFn!==td?t.queryFn:()=>Promise.reject(Error("Missing queryFn: '".concat(t.queryHash,"'")))}i(9678),i(2021),i(2277),i(4104);var tp=(s=[],r=0,n=t=>{t()},a=t=>{t()},o=function(t){setTimeout(t,0)},{batch:t=>{let e;r++;try{e=t()}finally{let t;--r||(t=s,s=[],t.length&&o(()=>{a(()=>{t.forEach(t=>{n(t)})})}))}return e},batchCalls:t=>function(){for(var e=arguments.length,i=Array(e),s=0;s<e;s++)i[s]=arguments[s];l(()=>{t(...i)})},schedule:l=t=>{r?s.push(t):o(()=>{n(t)})},setNotifyFunction:t=>{n=t},setBatchNotifyFunction:t=>{a=t},setScheduler:t=>{o=t}});i(7548),i(954),i(8803),i(9162),i(5385),i(9342),i(9152);var tv=class{subscribe(t){return this.listeners.add(t),this.onSubscribe(),()=>{this.listeners.delete(t),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}};function ty(t,e,i){if(!e.has(t))throw TypeError("attempted to "+i+" private field on non-instance");return e.get(t)}function tw(t,e){var i=ty(t,e,"get");return i.get?i.get.call(t):i.value}function tm(t,e,i){if(e.has(t))throw TypeError("Cannot initialize the same private elements twice on an object");e.set(t,i)}function tg(t,e,i){var s=ty(t,e,"set");if(s.set)s.set.call(t,i);else{if(!s.writable)throw TypeError("attempted to set read only private field");s.value=i}return i}var tb=new(y=new WeakMap,w=new WeakMap,m=new WeakMap,class extends tv{onSubscribe(){tw(this,w)||this.setEventListener(tw(this,m))}onUnsubscribe(){var t;this.hasListeners()||(null==(t=tw(this,w))||t.call(this),tg(this,w,void 0))}setEventListener(t){var e;tg(this,m,t),null==(e=tw(this,w))||e.call(this),tg(this,w,t(t=>{"boolean"==typeof t?this.setFocused(t):this.onFocus()}))}setFocused(t){tw(this,y)!==t&&(tg(this,y,t),this.onFocus())}onFocus(){let t=this.isFocused();this.listeners.forEach(e=>{e(t)})}isFocused(){var t;return"boolean"==typeof tw(this,y)?tw(this,y):(null==(t=globalThis.document)?void 0:t.visibilityState)!=="hidden"}constructor(){super(),tm(this,y,{writable:!0,value:void 0}),tm(this,w,{writable:!0,value:void 0}),tm(this,m,{writable:!0,value:void 0}),tg(this,m,t=>{if("u">typeof window&&window.addEventListener){let e=()=>t();return window.addEventListener("visibilitychange",e,!1),()=>{window.removeEventListener("visibilitychange",e)}}})}});function tO(t,e,i){if(!e.has(t))throw TypeError("attempted to "+i+" private field on non-instance");return e.get(t)}function tE(t,e){var i=tO(t,e,"get");return i.get?i.get.call(t):i.value}function tT(t,e,i){if(e.has(t))throw TypeError("Cannot initialize the same private elements twice on an object");e.set(t,i)}function tM(t,e,i){var s=tO(t,e,"set");if(s.set)s.set.call(t,i);else{if(!s.writable)throw TypeError("attempted to set read only private field");s.value=i}return i}var tP=new(g=new WeakMap,b=new WeakMap,O=new WeakMap,class extends tv{onSubscribe(){tE(this,b)||this.setEventListener(tE(this,O))}onUnsubscribe(){var t;this.hasListeners()||(null==(t=tE(this,b))||t.call(this),tM(this,b,void 0))}setEventListener(t){var e;tM(this,O,t),null==(e=tE(this,b))||e.call(this),tM(this,b,t(this.setOnline.bind(this)))}setOnline(t){tE(this,g)!==t&&(tM(this,g,t),this.listeners.forEach(e=>{e(t)}))}isOnline(){return tE(this,g)}constructor(){super(),tT(this,g,{writable:!0,value:!0}),tT(this,b,{writable:!0,value:void 0}),tT(this,O,{writable:!0,value:void 0}),tM(this,O,t=>{if("u">typeof window&&window.addEventListener){let e=()=>t(!0),i=()=>t(!1);return window.addEventListener("online",e,!1),window.addEventListener("offline",i,!1),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",i)}}})}}),tk=(u=()=>Z,{isServer:()=>u(),setIsServer(t){u=t}});function tS(t){return Math.min(1e3*2**t,3e4)}function tF(t){return(null!=t?t:"online")!=="online"||tP.isOnline()}var tC=class extends Error{constructor(t){super("CancelledError"),this.revert=null==t?void 0:t.revert,this.silent=null==t?void 0:t.silent}};function tq(t){let e,i=!1,s=0,r=function(){let t,e,i=new Promise((i,s)=>{t=i,e=s});function s(t){Object.assign(i,t),delete i.resolve,delete i.reject}return i.status="pending",i.catch(()=>{}),i.resolve=e=>{s({status:"fulfilled",value:e}),t(e)},i.reject=t=>{s({status:"rejected",reason:t}),e(t)},i}(),n=()=>tb.isFocused()&&("always"===t.networkMode||tP.isOnline())&&t.canRun(),a=()=>tF(t.networkMode)&&t.canRun(),o=t=>{"pending"===r.status&&(null==e||e(),r.resolve(t))},l=t=>{"pending"===r.status&&(null==e||e(),r.reject(t))},u=()=>new Promise(i=>{var s;e=t=>{("pending"!==r.status||n())&&i(t)},null==(s=t.onPause)||s.call(t)}).then(()=>{if(e=void 0,"pending"===r.status){var i;null==(i=t.onContinue)||i.call(t)}}),h=()=>{let e;if("pending"!==r.status)return;let a=0===s?t.initialPromise:void 0;try{e=null!=a?a:t.fn()}catch(t){e=Promise.reject(t)}Promise.resolve(e).then(o).catch(e=>{var a,o,c;if("pending"!==r.status)return;let d=null!=(a=t.retry)?a:3*!tk.isServer(),f=null!=(o=t.retryDelay)?o:tS,p="function"==typeof f?f(s,e):f,y=!0===d||"number"==typeof d&&s<d||"function"==typeof d&&d(s,e);i||!y?l(e):(s++,null==(c=t.onFail)||c.call(t,s,e),new Promise(t=>{Y.setTimeout(t,p)}).then(()=>n()?void 0:u()).then(()=>{i?l(e):h()}))})};return{promise:r,status:()=>r.status,cancel:e=>{if("pending"===r.status){var i;let s=new tC(e);l(s),null==(i=t.onCancel)||i.call(t,s)}},continue:()=>(null==e||e(),r),cancelRetry:()=>{i=!0},continueRetry:()=>{i=!1},canStart:a,start:()=>(a()?h():u().then(h),r)}}function tA(t,e,i){if(!e.has(t))throw TypeError("attempted to "+i+" private field on non-instance");return e.get(t)}function tj(t,e){var i=tA(t,e,"get");return i.get?i.get.call(t):i.value}function tW(t,e,i){var s=tA(t,e,"set");if(s.set)s.set.call(t,i);else{if(!s.writable)throw TypeError("attempted to set read only private field");s.value=i}return i}var tD=(E=new WeakMap,class{destroy(){this.clearGcTimeout()}scheduleGc(){var t;this.clearGcTimeout(),"number"==typeof(t=this.gcTime)&&t>=0&&t!==1/0&&tW(this,E,Y.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(t){this.gcTime=Math.max(this.gcTime||0,null!=t?t:tk.isServer()?1/0:3e5)}clearGcTimeout(){void 0!==tj(this,E)&&(Y.clearTimeout(tj(this,E)),tW(this,E,void 0))}constructor(){!function(t,e,i){if(e.has(t))throw TypeError("Cannot initialize the same private elements twice on an object");e.set(t,i)}(this,E,{writable:!0,value:void 0})}});function tQ(t,e){let{pages:i,pageParams:s}=e,r=i.length-1;return i.length>0?t.getNextPageParam(i[r],i,s[r],s):void 0}function tR(t,e){if(e.has(t))throw TypeError("Cannot initialize the same private elements twice on an object")}function tx(t,e,i){if(!e.has(t))throw TypeError("attempted to "+i+" private field on non-instance");return e.get(t)}function t_(t,e){var i=tx(t,e,"get");return i.get?i.get.call(t):i.value}function tU(t,e,i){tR(t,e),e.set(t,i)}function tI(t,e,i){var s=tx(t,e,"set");if(s.set)s.set.call(t,i);else{if(!s.writable)throw TypeError("attempted to set read only private field");s.value=i}return i}function tK(t,e,i){if(!e.has(t))throw TypeError("attempted to get private field on non-instance");return i}function tH(t,e){tR(t,e),e.add(t)}var tL=(T=new WeakMap,M=new WeakMap,P=new WeakMap,k=new WeakMap,S=new WeakMap,F=new WeakMap,C=new WeakMap,q=new WeakMap,A=new WeakSet,j=new WeakSet,class extends tD{get meta(){return this.options.meta}get queryType(){return t_(this,T)}get promise(){var t;return null==(t=t_(this,F))?void 0:t.promise}setOptions(t){if(this.options={...t_(this,C),...t},(null==t?void 0:t._type)&&tI(this,T,t._type),this.updateGcTime(this.options.gcTime),this.state&&void 0===this.state.data){let t=tz(this.options);void 0!==t.data&&(this.setState(tG(t.data,t.dataUpdatedAt)),tI(this,M,t))}}optionalRemove(){this.observers.length||"idle"!==this.state.fetchStatus||t_(this,k).remove(this)}setData(t,e){var i,s;let r=(i=this.state.data,"function"==typeof(s=this.options).structuralSharing?s.structuralSharing(i,t):!1!==s.structuralSharing?function t(e,i){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(e===i)return e;if(s>500)return i;let r=to(e)&&to(i);if(!r&&!(tl(e)&&tl(i)))return i;let n=(r?e:Object.keys(e)).length,a=r?i:Object.keys(i),o=a.length,l=r?Array(o):{},u=0;for(let h=0;h<o;h++){let o=r?h:a[h],c=e[o],d=i[o];if(c===d){l[o]=c,(r?h<n:ta.call(e,o))&&u++;continue}if(null===c||null===d||"object"!=typeof c||"object"!=typeof d){l[o]=d;continue}let f=t(c,d,s+1);l[o]=f,f===c&&u++}return n===o&&u===n?e:l}(i,t):t);return tK(this,j,tB).call(this,{data:r,type:"success",dataUpdatedAt:null==e?void 0:e.updatedAt,manual:null==e?void 0:e.manual}),r}setState(t){tK(this,j,tB).call(this,{type:"setState",state:t})}cancel(t){var e,i;let s=null==(e=t_(this,F))?void 0:e.promise;return null==(i=t_(this,F))||i.cancel(t),s?s.then($).catch($):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}get resetState(){return t_(this,M)}reset(){this.destroy(),this.setState(this.resetState)}isActive(){return this.observers.some(t=>{var e;return!1!==(e=t.options.enabled,"function"==typeof e?e(this):e)})}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===td||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0&&this.observers.some(t=>"static"===tt(t.options.staleTime,this))}isStale(){return this.getObserversCount()>0?this.observers.some(t=>t.getCurrentResult().isStale):void 0===this.state.data||this.state.isInvalidated}isStaleByTime(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return void 0===this.state.data||"static"!==t&&(!!this.state.isInvalidated||!Math.max(this.state.dataUpdatedAt+(t||0)-Date.now(),0))}onFocus(){var t;let e=this.observers.find(t=>t.shouldFetchOnWindowFocus());null==e||e.refetch({cancelRefetch:!1}),null==(t=t_(this,F))||t.continue()}onOnline(){var t;let e=this.observers.find(t=>t.shouldFetchOnReconnect());null==e||e.refetch({cancelRefetch:!1}),null==(t=t_(this,F))||t.continue()}addObserver(t){this.observers.includes(t)||(this.observers.push(t),this.clearGcTimeout(),t_(this,k).notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){this.observers.includes(t)&&(this.observers=this.observers.filter(e=>e!==t),this.observers.length||(t_(this,F)&&(t_(this,q)||tK(this,A,tN).call(this)?t_(this,F).cancel({revert:!0}):t_(this,F).cancelRetry()),this.scheduleGc()),t_(this,k).notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||tK(this,j,tB).call(this,{type:"invalidate"})}async fetch(t,e){var i,s,r,n,a,o,l,u,h,c,d,f;let p;if("idle"!==this.state.fetchStatus&&(null==(i=t_(this,F))?void 0:i.status())!=="rejected"){if(void 0!==this.state.data&&(null==e?void 0:e.cancelRefetch))this.cancel({silent:!0});else if(t_(this,F))return t_(this,F).continueRetry(),t_(this,F).promise}if(t&&this.setOptions(t),!this.options.queryFn){let t=this.observers.find(t=>t.options.queryFn);t&&this.setOptions(t.options)}let y=new AbortController,w=t=>{Object.defineProperty(t,"signal",{enumerable:!0,get:()=>(tI(this,q,!0),y.signal)})},m=()=>{let t,i=tf(this.options,e),s=(w(t={client:t_(this,S),queryKey:this.queryKey,meta:this.meta}),t);return(tI(this,q,!1),this.options.persister)?this.options.persister(i,s,this):i(s)},g=(w(p={fetchOptions:e,options:this.options,queryKey:this.queryKey,client:t_(this,S),state:this.state,fetchFn:m}),p),b="infinite"===t_(this,T)?(f=this.options.pages,{onFetch:(t,e)=>{var i,s,r,n,a;let o=t.options,l=null==(r=t.fetchOptions)||null==(s=r.meta)||null==(i=s.fetchMore)?void 0:i.direction,u=(null==(n=t.state.data)?void 0:n.pages)||[],h=(null==(a=t.state.data)?void 0:a.pageParams)||[],c={pages:[],pageParams:[]},d=0,p=async()=>{let e=!1,i=tf(t.options,t.fetchOptions),s=async(s,r,n)=>{if(e)return Promise.reject(t.signal.reason);if(null==r&&s.pages.length)return Promise.resolve(s);let a=(()=>{var i,s;let a,o,l={client:t.client,queryKey:t.queryKey,pageParam:r,direction:n?"backward":"forward",meta:t.options.meta};return i=()=>t.signal,s=()=>e=!0,o=!1,Object.defineProperty(l,"signal",{enumerable:!0,get:()=>(null!=a||(a=i()),o||(o=!0,a.aborted?s():a.addEventListener("abort",s,{once:!0})),a)}),l})(),o=await i(a),{maxPages:l}=t.options,u=n?tc:th;return{pages:u(s.pages,o,l),pageParams:u(s.pageParams,r,l)}};if(l&&u.length){let t="backward"===l,e={pages:u,pageParams:h},i=(t?function(t,e){var i;let{pages:s,pageParams:r}=e;return s.length>0?null==(i=t.getPreviousPageParam)?void 0:i.call(t,s[0],s,r[0],r):void 0}:tQ)(o,e);c=await s(e,i,t)}else{let t=null!=f?f:u.length;do{var r;let t=0===d?null!=(r=h[0])?r:o.initialPageParam:tQ(o,c);if(d>0&&null==t)break;c=await s(c,t),d++}while(d<t)}return c};t.options.persister?t.fetchFn=()=>{var i,s;return null==(i=(s=t.options).persister)?void 0:i.call(s,p,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},e)}:t.fetchFn=p}}):this.options.behavior;null==b||b.onFetch(g,this),tI(this,P,this.state),("idle"===this.state.fetchStatus||this.state.fetchMeta!==(null==(s=g.fetchOptions)?void 0:s.meta))&&tK(this,j,tB).call(this,{type:"fetch",meta:null==(r=g.fetchOptions)?void 0:r.meta}),tI(this,F,tq({initialPromise:null==e?void 0:e.initialPromise,fn:g.fetchFn,onCancel:t=>{t instanceof tC&&t.revert&&this.setState({...t_(this,P),fetchStatus:"idle"}),y.abort()},onFail:(t,e)=>{tK(this,j,tB).call(this,{type:"failed",failureCount:t,error:e})},onPause:()=>{tK(this,j,tB).call(this,{type:"pause"})},onContinue:()=>{tK(this,j,tB).call(this,{type:"continue"})},retry:g.options.retry,retryDelay:g.options.retryDelay,networkMode:g.options.networkMode,canRun:()=>!0}));try{let t=await t_(this,F).start();if(void 0===t)throw Error("".concat(this.queryHash," data is undefined"));return this.setData(t),null==(n=(a=t_(this,k).config).onSuccess)||n.call(a,t,this),null==(o=(l=t_(this,k).config).onSettled)||o.call(l,t,this.state.error,this),t}catch(t){if(t instanceof tC){if(t.silent)return t_(this,F).promise;else if(t.revert){if(void 0===this.state.data)throw t;return this.state.data}}throw tK(this,j,tB).call(this,{type:"error",error:t}),null==(u=(h=t_(this,k).config).onError)||u.call(h,t,this),null==(c=(d=t_(this,k).config).onSettled)||c.call(d,this.state.data,t,this),t}finally{this.scheduleGc()}}constructor(t){var e;super(),tH(this,A),tH(this,j),tU(this,T,{writable:!0,value:void 0}),tU(this,M,{writable:!0,value:void 0}),tU(this,P,{writable:!0,value:void 0}),tU(this,k,{writable:!0,value:void 0}),tU(this,S,{writable:!0,value:void 0}),tU(this,F,{writable:!0,value:void 0}),tU(this,C,{writable:!0,value:void 0}),tU(this,q,{writable:!0,value:void 0}),tI(this,q,!1),tI(this,C,t.defaultOptions),this.setOptions(t.options),this.observers=[],tI(this,S,t.client),tI(this,k,t_(this,S).getQueryCache()),this.queryKey=t.queryKey,this.queryHash=t.queryHash,tI(this,M,tz(this.options)),this.state=null!=(e=t.state)?e:t_(this,M),this.scheduleGc()}});function tG(t,e){return{data:t,dataUpdatedAt:null!=e?e:Date.now(),error:null,isInvalidated:!1,status:"success"}}function tz(t){let e="function"==typeof t.initialData?t.initialData():t.initialData,i=void 0!==e,s=i?"function"==typeof t.initialDataUpdatedAt?t.initialDataUpdatedAt():t.initialDataUpdatedAt:0;return{data:e,dataUpdateCount:0,dataUpdatedAt:i?null!=s?s:Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:i?"success":"pending",fetchStatus:"idle"}}function tN(){return"paused"===this.state.fetchStatus&&"pending"===this.state.status}function tB(t){let e=e=>{switch(t.type){case"failed":return{...e,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...e,fetchStatus:"paused"};case"continue":return{...e,fetchStatus:"fetching"};case"fetch":var i,s;return{...e,...(s=e.data,{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:tF(this.options.networkMode)?"fetching":"paused",...void 0===s&&{error:null,status:"pending"}}),fetchMeta:null!=(i=t.meta)?i:null};case"success":let r={...e,...tG(t.data,t.dataUpdatedAt),dataUpdateCount:e.dataUpdateCount+1,...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return tI(this,P,t.manual?r:void 0),r;case"error":let n=t.error;return{...e,error:n,errorUpdateCount:e.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:e.fetchFailureCount+1,fetchFailureReason:n,fetchStatus:"idle",status:"error",isInvalidated:!0};case"invalidate":return{...e,isInvalidated:!0};case"setState":return{...e,...t.state}}};this.state=e(this.state),tp.batch(()=>{this.observers.forEach(t=>{t.onQueryUpdate()}),t_(this,k).notify({query:this,type:"updated",action:t})})}function tJ(t,e,i){if(!e.has(t))throw TypeError("attempted to "+i+" private field on non-instance");return e.get(t)}function tV(t,e){var i=tJ(t,e,"get");return i.get?i.get.call(t):i.value}var tX=(W=new WeakMap,class extends tv{build(t,e,i){var s;let r=e.queryKey,n=null!=(s=e.queryHash)?s:ts(r,e),a=this.get(n);return a||(a=new tL({client:t,queryKey:r,queryHash:n,options:t.defaultQueryOptions(e),state:i,defaultOptions:t.getQueryDefaults(r)}),this.add(a)),a}add(t){tV(this,W).has(t.queryHash)||(tV(this,W).set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){let e=tV(this,W).get(t.queryHash);e&&(t.destroy(),e===t&&tV(this,W).delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){tp.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return tV(this,W).get(t)}getAll(){return[...tV(this,W).values()]}find(t){let e={exact:!0,...t};return this.getAll().find(t=>te(e,t))}findAll(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=this.getAll();return Object.keys(t).length>0?e.filter(e=>te(t,e)):e}notify(t){tp.batch(()=>{this.listeners.forEach(e=>{e(t)})})}onFocus(){tp.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){tp.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}constructor(t={}){super(),function(t,e,i){if(e.has(t))throw TypeError("Cannot initialize the same private elements twice on an object");e.set(t,i)}(this,W,{writable:!0,value:void 0}),this.config=t,function(t,e,i){var s=tJ(t,e,"set");if(s.set)s.set.call(t,i);else{if(!s.writable)throw TypeError("attempted to set read only private field");s.value=i}}(this,W,new Map)}});function tY(t,e){if(e.has(t))throw TypeError("Cannot initialize the same private elements twice on an object")}function tZ(t,e,i){if(!e.has(t))throw TypeError("attempted to "+i+" private field on non-instance");return e.get(t)}function t$(t,e){var i=tZ(t,e,"get");return i.get?i.get.call(t):i.value}function t0(t,e,i){tY(t,e),e.set(t,i)}function t1(t,e,i){var s=tZ(t,e,"set");if(s.set)s.set.call(t,i);else{if(!s.writable)throw TypeError("attempted to set read only private field");s.value=i}return i}function t2(t,e,i){if(!e.has(t))throw TypeError("attempted to get private field on non-instance");return i}var t3=(D=new WeakMap,Q=new WeakMap,R=new WeakMap,x=new WeakMap,_=new WeakSet,class extends tD{setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){t$(this,Q).includes(t)||(t$(this,Q).push(t),this.clearGcTimeout(),t$(this,R).notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){t1(this,Q,t$(this,Q).filter(e=>e!==t)),this.scheduleGc(),t$(this,R).notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){t$(this,Q).length||("pending"===this.state.status?this.scheduleGc():t$(this,R).remove(this))}continue(){var t,e;return null!=(t=null==(e=t$(this,x))?void 0:e.continue())?t:this.execute(this.state.variables)}async execute(t){var e,i,s,r,n,a,o,l,u,h,c,d,f,p,y,w,m,g,b;let O=()=>{t2(this,_,t5).call(this,{type:"continue"})},E={client:t$(this,D),meta:this.options.meta,mutationKey:this.options.mutationKey};t1(this,x,tq({fn:()=>this.options.mutationFn?this.options.mutationFn(t,E):Promise.reject(Error("No mutationFn found")),onFail:(t,e)=>{t2(this,_,t5).call(this,{type:"failed",failureCount:t,error:e})},onPause:()=>{t2(this,_,t5).call(this,{type:"pause"})},onContinue:O,retry:null!=(e=this.options.retry)?e:0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>t$(this,R).canRun(this)}));let T="pending"===this.state.status,M=!t$(this,x).canStart();try{if(T)O();else{t2(this,_,t5).call(this,{type:"pending",variables:t,isPaused:M}),t$(this,R).config.onMutate&&await t$(this,R).config.onMutate(t,this,E);let e=await (null==(h=(c=this.options).onMutate)?void 0:h.call(c,t,E));e!==this.state.context&&t2(this,_,t5).call(this,{type:"pending",context:e,variables:t,isPaused:M})}let e=await t$(this,x).start();return await (null==(i=(s=t$(this,R).config).onSuccess)?void 0:i.call(s,e,t,this.state.context,this,E)),await (null==(r=(n=this.options).onSuccess)?void 0:r.call(n,e,t,this.state.context,E)),await (null==(a=(o=t$(this,R).config).onSettled)?void 0:a.call(o,e,null,this.state.variables,this.state.context,this,E)),await (null==(l=(u=this.options).onSettled)?void 0:l.call(u,e,null,t,this.state.context,E)),t2(this,_,t5).call(this,{type:"success",data:e}),e}catch(e){try{await (null==(d=(f=t$(this,R).config).onError)?void 0:d.call(f,e,t,this.state.context,this,E))}catch(t){Promise.reject(t)}try{await (null==(p=(y=this.options).onError)?void 0:p.call(y,e,t,this.state.context,E))}catch(t){Promise.reject(t)}try{await (null==(w=(m=t$(this,R).config).onSettled)?void 0:w.call(m,void 0,e,this.state.variables,this.state.context,this,E))}catch(t){Promise.reject(t)}try{await (null==(g=(b=this.options).onSettled)?void 0:g.call(b,void 0,e,t,this.state.context,E))}catch(t){Promise.reject(t)}throw t2(this,_,t5).call(this,{type:"error",error:e}),e}finally{t$(this,R).runNext(this)}}constructor(t){super(),function(t,e){tY(t,e),e.add(t)}(this,_),t0(this,D,{writable:!0,value:void 0}),t0(this,Q,{writable:!0,value:void 0}),t0(this,R,{writable:!0,value:void 0}),t0(this,x,{writable:!0,value:void 0}),t1(this,D,t.client),this.mutationId=t.mutationId,t1(this,R,t.mutationCache),t1(this,Q,[]),this.state=t.state||{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0},this.setOptions(t.options),this.scheduleGc()}});function t5(t){this.state=(e=>{switch(t.type){case"failed":return{...e,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...e,isPaused:!0};case"continue":return{...e,isPaused:!1};case"pending":return{...e,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:t.isPaused,status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...e,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...e,data:void 0,error:t.error,failureCount:e.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}})(this.state),tp.batch(()=>{t$(this,Q).forEach(e=>{e.onMutationUpdate(t)}),t$(this,R).notify({mutation:this,type:"updated",action:t})})}function t4(t,e,i){if(!e.has(t))throw TypeError("attempted to "+i+" private field on non-instance");return e.get(t)}function t8(t,e){var i=t4(t,e,"get");return i.get?i.get.call(t):i.value}function t6(t,e,i){if(e.has(t))throw TypeError("Cannot initialize the same private elements twice on an object");e.set(t,i)}function t9(t,e,i){var s=t4(t,e,"set");if(s.set)s.set.call(t,i);else{if(!s.writable)throw TypeError("attempted to set read only private field");s.value=i}return i}var t7=(U=new WeakMap,I=new WeakMap,K=new WeakMap,class extends tv{build(t,e,i){let s=new t3({client:t,mutationCache:this,mutationId:++function(t,e){var i=t4(t,e,"update");if(i.set){if(!i.get)throw TypeError("attempted to read set only private field");return"__destrWrapper"in i||(i.__destrWrapper={set value(v){i.set.call(t,v)},get value(){return i.get.call(t)}}),i.__destrWrapper}if(!i.writable)throw TypeError("attempted to set read only private field");return i}(this,K).value,options:t.defaultMutationOptions(e),state:i});return this.add(s),s}add(t){t8(this,U).add(t);let e=et(t);if("string"==typeof e){let i=t8(this,I).get(e);i?i.push(t):t8(this,I).set(e,[t])}this.notify({type:"added",mutation:t})}remove(t){if(t8(this,U).delete(t)){let e=et(t);if("string"==typeof e){let i=t8(this,I).get(e);if(i)if(i.length>1){let e=i.indexOf(t);-1!==e&&i.splice(e,1)}else i[0]===t&&t8(this,I).delete(e)}}this.notify({type:"removed",mutation:t})}canRun(t){let e=et(t);if("string"!=typeof e)return!0;{let i=t8(this,I).get(e),s=null==i?void 0:i.find(t=>"pending"===t.state.status);return!s||s===t}}runNext(t){let e=et(t);if("string"!=typeof e)return Promise.resolve();{var i,s;let r=null==(s=t8(this,I).get(e))?void 0:s.find(e=>e!==t&&e.state.isPaused);return null!=(i=null==r?void 0:r.continue())?i:Promise.resolve()}}clear(){tp.batch(()=>{t8(this,U).forEach(t=>{this.notify({type:"removed",mutation:t})}),t8(this,U).clear(),t8(this,I).clear()})}getAll(){return Array.from(t8(this,U))}find(t){let e={exact:!0,...t};return this.getAll().find(t=>ti(e,t))}findAll(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.getAll().filter(e=>ti(t,e))}notify(t){tp.batch(()=>{this.listeners.forEach(e=>{e(t)})})}resumePausedMutations(){let t=this.getAll().filter(t=>t.state.isPaused);return tp.batch(()=>Promise.all(t.map(t=>t.continue().catch($))))}constructor(t={}){super(),t6(this,U,{writable:!0,value:void 0}),t6(this,I,{writable:!0,value:void 0}),t6(this,K,{writable:!0,value:void 0}),this.config=t,t9(this,U,new Set),t9(this,I,new Map),t9(this,K,0)}});function et(t){var e;return null==(e=t.options.scope)?void 0:e.id}function ee(t,e,i){if(!e.has(t))throw TypeError("attempted to "+i+" private field on non-instance");return e.get(t)}function ei(t,e){var i=ee(t,e,"get");return i.get?i.get.call(t):i.value}function es(t,e,i){if(e.has(t))throw TypeError("Cannot initialize the same private elements twice on an object");e.set(t,i)}function er(t,e,i){var s=ee(t,e,"set");if(s.set)s.set.call(t,i);else{if(!s.writable)throw TypeError("attempted to set read only private field");s.value=i}return i}function en(t,e){var i=ee(t,e,"update");if(i.set){if(!i.get)throw TypeError("attempted to read set only private field");return"__destrWrapper"in i||(i.__destrWrapper={set value(v){i.set.call(t,v)},get value(){return i.get.call(t)}}),i.__destrWrapper}if(!i.writable)throw TypeError("attempted to set read only private field");return i}var ea=(H=new WeakMap,L=new WeakMap,G=new WeakMap,z=new WeakMap,N=new WeakMap,B=new WeakMap,J=new WeakMap,V=new WeakMap,class{mount(){en(this,B).value++,1===ei(this,B)&&(er(this,J,tb.subscribe(async t=>{t&&(await this.resumePausedMutations(),ei(this,H).onFocus())})),er(this,V,tP.subscribe(async t=>{t&&(await this.resumePausedMutations(),ei(this,H).onOnline())})))}unmount(){var t,e;en(this,B).value--,0===ei(this,B)&&(null==(t=ei(this,J))||t.call(this),er(this,J,void 0),null==(e=ei(this,V))||e.call(this),er(this,V,void 0))}isFetching(t){return ei(this,H).findAll({...t,fetchStatus:"fetching"}).length}isMutating(t){return ei(this,L).findAll({...t,status:"pending"}).length}getQueryData(t){var e;let i=this.defaultQueryOptions({queryKey:t});return null==(e=ei(this,H).get(i.queryHash))?void 0:e.state.data}ensureQueryData(t){let e=this.defaultQueryOptions(t),i=ei(this,H).build(this,e),s=i.state.data;return void 0===s?this.fetchQuery(t):(t.revalidateIfStale&&i.isStaleByTime(tt(e.staleTime,i))&&this.prefetchQuery(e),Promise.resolve(s))}getQueriesData(t){return ei(this,H).findAll(t).map(t=>{let{queryKey:e,state:i}=t;return[e,i.data]})}setQueryData(t,e,i){let s=this.defaultQueryOptions({queryKey:t}),r=ei(this,H).get(s.queryHash),n=null==r?void 0:r.state.data,a="function"==typeof e?e(n):e;if(void 0!==a)return ei(this,H).build(this,s).setData(a,{...i,manual:!0})}setQueriesData(t,e,i){return tp.batch(()=>ei(this,H).findAll(t).map(t=>{let{queryKey:s}=t;return[s,this.setQueryData(s,e,i)]}))}getQueryState(t){var e;let i=this.defaultQueryOptions({queryKey:t});return null==(e=ei(this,H).get(i.queryHash))?void 0:e.state}removeQueries(t){let e=ei(this,H);tp.batch(()=>{e.findAll(t).forEach(t=>{e.remove(t)})})}resetQueries(t,e){let i=ei(this,H);return tp.batch(()=>(i.findAll(t).forEach(t=>{t.reset()}),this.refetchQueries({type:"active",...t},e)))}cancelQueries(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i={revert:!0,...e};return Promise.all(tp.batch(()=>ei(this,H).findAll(t).map(t=>t.cancel(i)))).then($).catch($)}invalidateQueries(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return tp.batch(()=>{var i,s;return(ei(this,H).findAll(t).forEach(t=>{t.invalidate()}),(null==t?void 0:t.refetchType)==="none")?Promise.resolve():this.refetchQueries({...t,type:null!=(i=null!=(s=null==t?void 0:t.refetchType)?s:null==t?void 0:t.type)?i:"active"},e)})}refetchQueries(t){var e;let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s={...i,cancelRefetch:null==(e=i.cancelRefetch)||e};return Promise.all(tp.batch(()=>ei(this,H).findAll(t).filter(t=>!t.isDisabled()&&!t.isStatic()).map(t=>{let e=t.fetch(void 0,s);return s.throwOnError||(e=e.catch($)),"paused"===t.state.fetchStatus?Promise.resolve():e}))).then($)}fetchQuery(t){let e=this.defaultQueryOptions(t);void 0===e.retry&&(e.retry=!1);let i=ei(this,H).build(this,e);return i.isStaleByTime(tt(e.staleTime,i))?i.fetch(e):Promise.resolve(i.state.data)}prefetchQuery(t){return this.fetchQuery(t).then($).catch($)}fetchInfiniteQuery(t){return t._type="infinite",this.fetchQuery(t)}prefetchInfiniteQuery(t){return this.fetchInfiniteQuery(t).then($).catch($)}ensureInfiniteQueryData(t){return t._type="infinite",this.ensureQueryData(t)}resumePausedMutations(){return tP.isOnline()?ei(this,L).resumePausedMutations():Promise.resolve()}getQueryCache(){return ei(this,H)}getMutationCache(){return ei(this,L)}getDefaultOptions(){return ei(this,G)}setDefaultOptions(t){er(this,G,t)}setQueryDefaults(t,e){ei(this,z).set(tr(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){let e=[...ei(this,z).values()],i={};return e.forEach(e=>{tn(t,e.queryKey)&&Object.assign(i,e.defaultOptions)}),i}setMutationDefaults(t,e){ei(this,N).set(tr(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){let e=[...ei(this,N).values()],i={};return e.forEach(e=>{tn(t,e.mutationKey)&&Object.assign(i,e.defaultOptions)}),i}defaultQueryOptions(t){if(t._defaulted)return t;let e={...ei(this,G).queries,...this.getQueryDefaults(t.queryKey),...t,_defaulted:!0};return e.queryHash||(e.queryHash=ts(e.queryKey,e)),void 0===e.refetchOnReconnect&&(e.refetchOnReconnect="always"!==e.networkMode),void 0===e.throwOnError&&(e.throwOnError=!!e.suspense),!e.networkMode&&e.persister&&(e.networkMode="offlineFirst"),e.queryFn===td&&(e.enabled=!1),e}defaultMutationOptions(t){return(null==t?void 0:t._defaulted)?t:{...ei(this,G).mutations,...(null==t?void 0:t.mutationKey)&&this.getMutationDefaults(t.mutationKey),...t,_defaulted:!0}}clear(){ei(this,H).clear(),ei(this,L).clear()}constructor(t={}){es(this,H,{writable:!0,value:void 0}),es(this,L,{writable:!0,value:void 0}),es(this,G,{writable:!0,value:void 0}),es(this,z,{writable:!0,value:void 0}),es(this,N,{writable:!0,value:void 0}),es(this,B,{writable:!0,value:void 0}),es(this,J,{writable:!0,value:void 0}),es(this,V,{writable:!0,value:void 0}),er(this,H,t.queryCache||new tX),er(this,L,t.mutationCache||new t7),er(this,G,t.defaultOptions||{}),er(this,z,new Map),er(this,N,new Map),er(this,B,0)}})}}]);