Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/pkg/ui/frontend/dist/assets/query-management-DbWM5GrR.js

1 lines
36 KiB

var at=t=>{throw TypeError(t)};var He=(t,e,s)=>e.has(t)||at("Cannot "+s);var r=(t,e,s)=>(He(t,e,"read from private field"),s?s.call(t):e.get(t)),l=(t,e,s)=>e.has(t)?at("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),u=(t,e,s,i)=>(He(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),p=(t,e,s)=>(He(t,e,"access private method"),s);var ke=(t,e,s,i)=>({set _(n){u(t,e,n,s)},get _(){return r(t,e,i)}});import{r as L}from"./react-core-D_V7s-9r.js";import{j as jt}from"./radix-core-ByqQ8fsu.js";var Ue=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(t){return this.listeners.add(t),this.onSubscribe(),()=>{this.listeners.delete(t),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},de=typeof window>"u"||"Deno"in globalThis;function k(){}function kt(t,e){return typeof t=="function"?t(e):t}function Ge(t){return typeof t=="number"&&t>=0&&t!==1/0}function Ft(t,e){return Math.max(t+(e||0)-Date.now(),0)}function pe(t,e){return typeof t=="function"?t(e):t}function G(t,e){return typeof t=="function"?t(e):t}function ut(t,e){const{type:s="all",exact:i,fetchStatus:n,predicate:a,queryKey:h,stale:c}=t;if(h){if(i){if(e.queryHash!==st(h,e.options))return!1}else if(!Te(e.queryKey,h))return!1}if(s!=="all"){const d=e.isActive();if(s==="active"&&!d||s==="inactive"&&d)return!1}return!(typeof c=="boolean"&&e.isStale()!==c||n&&n!==e.state.fetchStatus||a&&!a(e))}function ht(t,e){const{exact:s,status:i,predicate:n,mutationKey:a}=t;if(a){if(!e.options.mutationKey)return!1;if(s){if(Me(e.options.mutationKey)!==Me(a))return!1}else if(!Te(e.options.mutationKey,a))return!1}return!(i&&e.state.status!==i||n&&!n(e))}function st(t,e){return((e==null?void 0:e.queryKeyHashFn)||Me)(t)}function Me(t){return JSON.stringify(t,(e,s)=>Be(s)?Object.keys(s).sort().reduce((i,n)=>(i[n]=s[n],i),{}):s)}function Te(t,e){return t===e?!0:typeof t!=typeof e?!1:t&&e&&typeof t=="object"&&typeof e=="object"?!Object.keys(e).some(s=>!Te(t[s],e[s])):!1}function Qt(t,e){if(t===e)return t;const s=ot(t)&&ot(e);if(s||Be(t)&&Be(e)){const i=s?t:Object.keys(t),n=i.length,a=s?e:Object.keys(e),h=a.length,c=s?[]:{};let d=0;for(let w=0;w<h;w++){const b=s?w:a[w];(!s&&i.includes(b)||s)&&t[b]===void 0&&e[b]===void 0?(c[b]=void 0,d++):(c[b]=Qt(t[b],e[b]),c[b]===t[b]&&t[b]!==void 0&&d++)}return n===h&&d===n?t:c}return e}function Ne(t,e){if(!e||Object.keys(t).length!==Object.keys(e).length)return!1;for(const s in t)if(t[s]!==e[s])return!1;return!0}function ot(t){return Array.isArray(t)&&t.length===Object.keys(t).length}function Be(t){if(!ct(t))return!1;const e=t.constructor;if(e===void 0)return!0;const s=e.prototype;return!(!ct(s)||!s.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(t)!==Object.prototype)}function ct(t){return Object.prototype.toString.call(t)==="[object Object]"}function Lt(t){return new Promise(e=>{setTimeout(e,t)})}function ze(t,e,s){return typeof s.structuralSharing=="function"?s.structuralSharing(t,e):s.structuralSharing!==!1?Qt(t,e):e}function Kt(t,e,s=0){const i=[...t,e];return s&&i.length>s?i.slice(1):i}function Ht(t,e,s=0){const i=[e,...t];return s&&i.length>s?i.slice(0,-1):i}var it=Symbol();function Et(t,e){return!t.queryFn&&(e!=null&&e.initialPromise)?()=>e.initialPromise:!t.queryFn||t.queryFn===it?()=>Promise.reject(new Error(`Missing queryFn: '${t.queryHash}'`)):t.queryFn}var re,X,me,bt,_t=(bt=class extends Ue{constructor(){super();l(this,re);l(this,X);l(this,me);u(this,me,e=>{if(!de&&window.addEventListener){const s=()=>e();return window.addEventListener("visibilitychange",s,!1),()=>{window.removeEventListener("visibilitychange",s)}}})}onSubscribe(){r(this,X)||this.setEventListener(r(this,me))}onUnsubscribe(){var e;this.hasListeners()||((e=r(this,X))==null||e.call(this),u(this,X,void 0))}setEventListener(e){var s;u(this,me,e),(s=r(this,X))==null||s.call(this),u(this,X,e(i=>{typeof i=="boolean"?this.setFocused(i):this.onFocus()}))}setFocused(e){r(this,re)!==e&&(u(this,re,e),this.onFocus())}onFocus(){const e=this.isFocused();this.listeners.forEach(s=>{s(e)})}isFocused(){var e;return typeof r(this,re)=="boolean"?r(this,re):((e=globalThis.document)==null?void 0:e.visibilityState)!=="hidden"}},re=new WeakMap,X=new WeakMap,me=new WeakMap,bt),rt=new _t,be,Y,ge,gt,Gt=(gt=class extends Ue{constructor(){super();l(this,be,!0);l(this,Y);l(this,ge);u(this,ge,e=>{if(!de&&window.addEventListener){const s=()=>e(!0),i=()=>e(!1);return window.addEventListener("online",s,!1),window.addEventListener("offline",i,!1),()=>{window.removeEventListener("online",s),window.removeEventListener("offline",i)}}})}onSubscribe(){r(this,Y)||this.setEventListener(r(this,ge))}onUnsubscribe(){var e;this.hasListeners()||((e=r(this,Y))==null||e.call(this),u(this,Y,void 0))}setEventListener(e){var s;u(this,ge,e),(s=r(this,Y))==null||s.call(this),u(this,Y,e(this.setOnline.bind(this)))}setOnline(e){r(this,be)!==e&&(u(this,be,e),this.listeners.forEach(i=>{i(e)}))}isOnline(){return r(this,be)}},be=new WeakMap,Y=new WeakMap,ge=new WeakMap,gt),Ke=new Gt;function Ve(){let t,e;const s=new Promise((n,a)=>{t=n,e=a});s.status="pending",s.catch(()=>{});function i(n){Object.assign(s,n),delete s.resolve,delete s.reject}return s.resolve=n=>{i({status:"fulfilled",value:n}),t(n)},s.reject=n=>{i({status:"rejected",reason:n}),e(n)},s}function Nt(t){return Math.min(1e3*2**t,3e4)}function Dt(t){return(t??"online")==="online"?Ke.isOnline():!0}var Mt=class extends Error{constructor(t){super("CancelledError"),this.revert=t==null?void 0:t.revert,this.silent=t==null?void 0:t.silent}};function _e(t){return t instanceof Mt}function Tt(t){let e=!1,s=0,i=!1,n;const a=Ve(),h=f=>{var y;i||(C(new Mt(f)),(y=t.abort)==null||y.call(t))},c=()=>{e=!0},d=()=>{e=!1},w=()=>rt.isFocused()&&(t.networkMode==="always"||Ke.isOnline())&&t.canRun(),b=()=>Dt(t.networkMode)&&t.canRun(),o=f=>{var y;i||(i=!0,(y=t.onSuccess)==null||y.call(t,f),n==null||n(),a.resolve(f))},C=f=>{var y;i||(i=!0,(y=t.onError)==null||y.call(t,f),n==null||n(),a.reject(f))},g=()=>new Promise(f=>{var y;n=Q=>{(i||w())&&f(Q)},(y=t.onPause)==null||y.call(t)}).then(()=>{var f;n=void 0,i||(f=t.onContinue)==null||f.call(t)}),S=()=>{if(i)return;let f;const y=s===0?t.initialPromise:void 0;try{f=y??t.fn()}catch(Q){f=Promise.reject(Q)}Promise.resolve(f).then(o).catch(Q=>{var K;if(i)return;const T=t.retry??(de?0:3),R=t.retryDelay??Nt,D=typeof R=="function"?R(s,Q):R,U=T===!0||typeof T=="number"&&s<T||typeof T=="function"&&T(s,Q);if(e||!U){C(Q);return}s++,(K=t.onFail)==null||K.call(t,s,Q),Lt(D).then(()=>w()?void 0:g()).then(()=>{e?C(Q):S()})})};return{promise:a,cancel:h,continue:()=>(n==null||n(),a),cancelRetry:c,continueRetry:d,canStart:b,start:()=>(b()?S():g().then(S),a)}}function Bt(){let t=[],e=0,s=c=>{c()},i=c=>{c()},n=c=>setTimeout(c,0);const a=c=>{e?t.push(c):n(()=>{s(c)})},h=()=>{const c=t;t=[],c.length&&n(()=>{i(()=>{c.forEach(d=>{s(d)})})})};return{batch:c=>{let d;e++;try{d=c()}finally{e--,e||h()}return d},batchCalls:c=>(...d)=>{a(()=>{c(...d)})},schedule:a,setNotifyFunction:c=>{s=c},setBatchNotifyFunction:c=>{i=c},setScheduler:c=>{n=c}}}var E=Bt(),ne,vt,At=(vt=class{constructor(){l(this,ne)}destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Ge(this.gcTime)&&u(this,ne,setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(t){this.gcTime=Math.max(this.gcTime||0,t??(de?1/0:5*60*1e3))}clearGcTimeout(){r(this,ne)&&(clearTimeout(r(this,ne)),u(this,ne,void 0))}},ne=new WeakMap,vt),ve,we,j,ae,M,Ae,ue,H,$,wt,zt=(wt=class extends At{constructor(e){super();l(this,H);l(this,ve);l(this,we);l(this,j);l(this,ae);l(this,M);l(this,Ae);l(this,ue);u(this,ue,!1),u(this,Ae,e.defaultOptions),this.setOptions(e.options),this.observers=[],u(this,ae,e.client),u(this,j,r(this,ae).getQueryCache()),this.queryKey=e.queryKey,this.queryHash=e.queryHash,u(this,ve,Vt(this.options)),this.state=e.state??r(this,ve),this.scheduleGc()}get meta(){return this.options.meta}get promise(){var e;return(e=r(this,M))==null?void 0:e.promise}setOptions(e){this.options={...r(this,Ae),...e},this.updateGcTime(this.options.gcTime)}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&r(this,j).remove(this)}setData(e,s){const i=ze(this.state.data,e,this.options);return p(this,H,$).call(this,{data:i,type:"success",dataUpdatedAt:s==null?void 0:s.updatedAt,manual:s==null?void 0:s.manual}),i}setState(e,s){p(this,H,$).call(this,{type:"setState",state:e,setStateOptions:s})}cancel(e){var i,n;const s=(i=r(this,M))==null?void 0:i.promise;return(n=r(this,M))==null||n.cancel(e),s?s.then(k).catch(k):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(r(this,ve))}isActive(){return this.observers.some(e=>G(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===it||this.state.dataUpdateCount+this.state.errorUpdateCount===0}isStale(){return this.state.isInvalidated?!0:this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0}isStaleByTime(e=0){return this.state.isInvalidated||this.state.data===void 0||!Ft(this.state.dataUpdatedAt,e)}onFocus(){var s;const e=this.observers.find(i=>i.shouldFetchOnWindowFocus());e==null||e.refetch({cancelRefetch:!1}),(s=r(this,M))==null||s.continue()}onOnline(){var s;const e=this.observers.find(i=>i.shouldFetchOnReconnect());e==null||e.refetch({cancelRefetch:!1}),(s=r(this,M))==null||s.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),r(this,j).notify({type:"observerAdded",query:this,observer:e}))}removeObserver(e){this.observers.includes(e)&&(this.observers=this.observers.filter(s=>s!==e),this.observers.length||(r(this,M)&&(r(this,ue)?r(this,M).cancel({revert:!0}):r(this,M).cancelRetry()),this.scheduleGc()),r(this,j).notify({type:"observerRemoved",query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||p(this,H,$).call(this,{type:"invalidate"})}fetch(e,s){var d,w,b;if(this.state.fetchStatus!=="idle"){if(this.state.data!==void 0&&(s!=null&&s.cancelRefetch))this.cancel({silent:!0});else if(r(this,M))return r(this,M).continueRetry(),r(this,M).promise}if(e&&this.setOptions(e),!this.options.queryFn){const o=this.observers.find(C=>C.options.queryFn);o&&this.setOptions(o.options)}const i=new AbortController,n=o=>{Object.defineProperty(o,"signal",{enumerable:!0,get:()=>(u(this,ue,!0),i.signal)})},a=()=>{const o=Et(this.options,s),C={client:r(this,ae),queryKey:this.queryKey,meta:this.meta};return n(C),u(this,ue,!1),this.options.persister?this.options.persister(o,C,this):o(C)},h={fetchOptions:s,options:this.options,queryKey:this.queryKey,client:r(this,ae),state:this.state,fetchFn:a};n(h),(d=this.options.behavior)==null||d.onFetch(h,this),u(this,we,this.state),(this.state.fetchStatus==="idle"||this.state.fetchMeta!==((w=h.fetchOptions)==null?void 0:w.meta))&&p(this,H,$).call(this,{type:"fetch",meta:(b=h.fetchOptions)==null?void 0:b.meta});const c=o=>{var C,g,S,f;_e(o)&&o.silent||p(this,H,$).call(this,{type:"error",error:o}),_e(o)||((g=(C=r(this,j).config).onError)==null||g.call(C,o,this),(f=(S=r(this,j).config).onSettled)==null||f.call(S,this.state.data,o,this)),this.scheduleGc()};return u(this,M,Tt({initialPromise:s==null?void 0:s.initialPromise,fn:h.fetchFn,abort:i.abort.bind(i),onSuccess:o=>{var C,g,S,f;if(o===void 0){c(new Error(`${this.queryHash} data is undefined`));return}try{this.setData(o)}catch(y){c(y);return}(g=(C=r(this,j).config).onSuccess)==null||g.call(C,o,this),(f=(S=r(this,j).config).onSettled)==null||f.call(S,o,this.state.error,this),this.scheduleGc()},onError:c,onFail:(o,C)=>{p(this,H,$).call(this,{type:"failed",failureCount:o,error:C})},onPause:()=>{p(this,H,$).call(this,{type:"pause"})},onContinue:()=>{p(this,H,$).call(this,{type:"continue"})},retry:h.options.retry,retryDelay:h.options.retryDelay,networkMode:h.options.networkMode,canRun:()=>!0})),r(this,M).start()}},ve=new WeakMap,we=new WeakMap,j=new WeakMap,ae=new WeakMap,M=new WeakMap,Ae=new WeakMap,ue=new WeakMap,H=new WeakSet,$=function(e){const s=i=>{switch(e.type){case"failed":return{...i,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case"pause":return{...i,fetchStatus:"paused"};case"continue":return{...i,fetchStatus:"fetching"};case"fetch":return{...i,...It(i.data,this.options),fetchMeta:e.meta??null};case"success":return{...i,data:e.data,dataUpdateCount:i.dataUpdateCount+1,dataUpdatedAt:e.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!e.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":const n=e.error;return _e(n)&&n.revert&&r(this,we)?{...r(this,we),fetchStatus:"idle"}:{...i,error:n,errorUpdateCount:i.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:i.fetchFailureCount+1,fetchFailureReason:n,fetchStatus:"idle",status:"error"};case"invalidate":return{...i,isInvalidated:!0};case"setState":return{...i,...e.state}}};this.state=s(this.state),E.batch(()=>{this.observers.forEach(i=>{i.onQueryUpdate()}),r(this,j).notify({query:this,type:"updated",action:e})})},wt);function It(t,e){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:Dt(e.networkMode)?"fetching":"paused",...t===void 0&&{error:null,status:"pending"}}}function Vt(t){const e=typeof t.initialData=="function"?t.initialData():t.initialData,s=e!==void 0,i=s?typeof t.initialDataUpdatedAt=="function"?t.initialDataUpdatedAt():t.initialDataUpdatedAt:0;return{data:e,dataUpdateCount:0,dataUpdatedAt:s?i??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:s?"success":"pending",fetchStatus:"idle"}}var N,Ct,$t=(Ct=class extends Ue{constructor(e={}){super();l(this,N);this.config=e,u(this,N,new Map)}build(e,s,i){const n=s.queryKey,a=s.queryHash??st(n,s);let h=this.get(a);return h||(h=new zt({client:e,queryKey:n,queryHash:a,options:e.defaultQueryOptions(s),state:i,defaultOptions:e.getQueryDefaults(n)}),this.add(h)),h}add(e){r(this,N).has(e.queryHash)||(r(this,N).set(e.queryHash,e),this.notify({type:"added",query:e}))}remove(e){const s=r(this,N).get(e.queryHash);s&&(e.destroy(),s===e&&r(this,N).delete(e.queryHash),this.notify({type:"removed",query:e}))}clear(){E.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return r(this,N).get(e)}getAll(){return[...r(this,N).values()]}find(e){const s={exact:!0,...e};return this.getAll().find(i=>ut(s,i))}findAll(e={}){const s=this.getAll();return Object.keys(e).length>0?s.filter(i=>ut(e,i)):s}notify(e){E.batch(()=>{this.listeners.forEach(s=>{s(e)})})}onFocus(){E.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){E.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},N=new WeakMap,Ct),B,I,he,z,J,Ot,Wt=(Ot=class extends At{constructor(e){super();l(this,z);l(this,B);l(this,I);l(this,he);this.mutationId=e.mutationId,u(this,I,e.mutationCache),u(this,B,[]),this.state=e.state||Jt(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){r(this,B).includes(e)||(r(this,B).push(e),this.clearGcTimeout(),r(this,I).notify({type:"observerAdded",mutation:this,observer:e}))}removeObserver(e){u(this,B,r(this,B).filter(s=>s!==e)),this.scheduleGc(),r(this,I).notify({type:"observerRemoved",mutation:this,observer:e})}optionalRemove(){r(this,B).length||(this.state.status==="pending"?this.scheduleGc():r(this,I).remove(this))}continue(){var e;return((e=r(this,he))==null?void 0:e.continue())??this.execute(this.state.variables)}async execute(e){var n,a,h,c,d,w,b,o,C,g,S,f,y,Q,T,R,D,U,K,A;u(this,he,Tt({fn:()=>this.options.mutationFn?this.options.mutationFn(e):Promise.reject(new Error("No mutationFn found")),onFail:(F,O)=>{p(this,z,J).call(this,{type:"failed",failureCount:F,error:O})},onPause:()=>{p(this,z,J).call(this,{type:"pause"})},onContinue:()=>{p(this,z,J).call(this,{type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>r(this,I).canRun(this)}));const s=this.state.status==="pending",i=!r(this,he).canStart();try{if(!s){p(this,z,J).call(this,{type:"pending",variables:e,isPaused:i}),await((a=(n=r(this,I).config).onMutate)==null?void 0:a.call(n,e,this));const O=await((c=(h=this.options).onMutate)==null?void 0:c.call(h,e));O!==this.state.context&&p(this,z,J).call(this,{type:"pending",context:O,variables:e,isPaused:i})}const F=await r(this,he).start();return await((w=(d=r(this,I).config).onSuccess)==null?void 0:w.call(d,F,e,this.state.context,this)),await((o=(b=this.options).onSuccess)==null?void 0:o.call(b,F,e,this.state.context)),await((g=(C=r(this,I).config).onSettled)==null?void 0:g.call(C,F,null,this.state.variables,this.state.context,this)),await((f=(S=this.options).onSettled)==null?void 0:f.call(S,F,null,e,this.state.context)),p(this,z,J).call(this,{type:"success",data:F}),F}catch(F){try{throw await((Q=(y=r(this,I).config).onError)==null?void 0:Q.call(y,F,e,this.state.context,this)),await((R=(T=this.options).onError)==null?void 0:R.call(T,F,e,this.state.context)),await((U=(D=r(this,I).config).onSettled)==null?void 0:U.call(D,void 0,F,this.state.variables,this.state.context,this)),await((A=(K=this.options).onSettled)==null?void 0:A.call(K,void 0,F,e,this.state.context)),F}finally{p(this,z,J).call(this,{type:"error",error:F})}}finally{r(this,I).runNext(this)}}},B=new WeakMap,I=new WeakMap,he=new WeakMap,z=new WeakSet,J=function(e){const s=i=>{switch(e.type){case"failed":return{...i,failureCount:e.failureCount,failureReason:e.error};case"pause":return{...i,isPaused:!0};case"continue":return{...i,isPaused:!1};case"pending":return{...i,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:"pending",variables:e.variables,submittedAt:Date.now()};case"success":return{...i,data:e.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...i,data:void 0,error:e.error,failureCount:i.failureCount+1,failureReason:e.error,isPaused:!1,status:"error"}}};this.state=s(this.state),E.batch(()=>{r(this,B).forEach(i=>{i.onMutationUpdate(e)}),r(this,I).notify({mutation:this,type:"updated",action:e})})},Ot);function Jt(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var W,_,Ie,Rt,Xt=(Rt=class extends Ue{constructor(e={}){super();l(this,W);l(this,_);l(this,Ie);this.config=e,u(this,W,new Set),u(this,_,new Map),u(this,Ie,0)}build(e,s,i){const n=new Wt({mutationCache:this,mutationId:++ke(this,Ie)._,options:e.defaultMutationOptions(s),state:i});return this.add(n),n}add(e){r(this,W).add(e);const s=Le(e);if(typeof s=="string"){const i=r(this,_).get(s);i?i.push(e):r(this,_).set(s,[e])}this.notify({type:"added",mutation:e})}remove(e){if(r(this,W).delete(e)){const s=Le(e);if(typeof s=="string"){const i=r(this,_).get(s);if(i)if(i.length>1){const n=i.indexOf(e);n!==-1&&i.splice(n,1)}else i[0]===e&&r(this,_).delete(s)}}this.notify({type:"removed",mutation:e})}canRun(e){const s=Le(e);if(typeof s=="string"){const i=r(this,_).get(s),n=i==null?void 0:i.find(a=>a.state.status==="pending");return!n||n===e}else return!0}runNext(e){var i;const s=Le(e);if(typeof s=="string"){const n=(i=r(this,_).get(s))==null?void 0:i.find(a=>a!==e&&a.state.isPaused);return(n==null?void 0:n.continue())??Promise.resolve()}else return Promise.resolve()}clear(){E.batch(()=>{r(this,W).forEach(e=>{this.notify({type:"removed",mutation:e})}),r(this,W).clear(),r(this,_).clear()})}getAll(){return Array.from(r(this,W))}find(e){const s={exact:!0,...e};return this.getAll().find(i=>ht(s,i))}findAll(e={}){return this.getAll().filter(s=>ht(e,s))}notify(e){E.batch(()=>{this.listeners.forEach(s=>{s(e)})})}resumePausedMutations(){const e=this.getAll().filter(s=>s.state.isPaused);return E.batch(()=>Promise.all(e.map(s=>s.continue().catch(k))))}},W=new WeakMap,_=new WeakMap,Ie=new WeakMap,Rt);function Le(t){var e;return(e=t.options.scope)==null?void 0:e.id}function lt(t){return{onFetch:(e,s)=>{var b,o,C,g,S;const i=e.options,n=(C=(o=(b=e.fetchOptions)==null?void 0:b.meta)==null?void 0:o.fetchMore)==null?void 0:C.direction,a=((g=e.state.data)==null?void 0:g.pages)||[],h=((S=e.state.data)==null?void 0:S.pageParams)||[];let c={pages:[],pageParams:[]},d=0;const w=async()=>{let f=!1;const y=R=>{Object.defineProperty(R,"signal",{enumerable:!0,get:()=>(e.signal.aborted?f=!0:e.signal.addEventListener("abort",()=>{f=!0}),e.signal)})},Q=Et(e.options,e.fetchOptions),T=async(R,D,U)=>{if(f)return Promise.reject();if(D==null&&R.pages.length)return Promise.resolve(R);const K={client:e.client,queryKey:e.queryKey,pageParam:D,direction:U?"backward":"forward",meta:e.options.meta};y(K);const A=await Q(K),{maxPages:F}=e.options,O=U?Ht:Kt;return{pages:O(R.pages,A,F),pageParams:O(R.pageParams,D,F)}};if(n&&a.length){const R=n==="backward",D=R?Yt:dt,U={pages:a,pageParams:h},K=D(i,U);c=await T(U,K,R)}else{const R=t??a.length;do{const D=d===0?h[0]??i.initialPageParam:dt(i,c);if(d>0&&D==null)break;c=await T(c,D),d++}while(d<R)}return c};e.options.persister?e.fetchFn=()=>{var f,y;return(y=(f=e.options).persister)==null?void 0:y.call(f,w,{client:e.client,queryKey:e.queryKey,meta:e.options.meta,signal:e.signal},s)}:e.fetchFn=w}}}function dt(t,{pages:e,pageParams:s}){const i=e.length-1;return e.length>0?t.getNextPageParam(e[i],e,s[i],s):void 0}function Yt(t,{pages:e,pageParams:s}){var i;return e.length>0?(i=t.getPreviousPageParam)==null?void 0:i.call(t,e[0],e,s[0],s):void 0}var P,Z,ee,Ce,Oe,te,Re,Pe,Pt,gs=(Pt=class{constructor(t={}){l(this,P);l(this,Z);l(this,ee);l(this,Ce);l(this,Oe);l(this,te);l(this,Re);l(this,Pe);u(this,P,t.queryCache||new $t),u(this,Z,t.mutationCache||new Xt),u(this,ee,t.defaultOptions||{}),u(this,Ce,new Map),u(this,Oe,new Map),u(this,te,0)}mount(){ke(this,te)._++,r(this,te)===1&&(u(this,Re,rt.subscribe(async t=>{t&&(await this.resumePausedMutations(),r(this,P).onFocus())})),u(this,Pe,Ke.subscribe(async t=>{t&&(await this.resumePausedMutations(),r(this,P).onOnline())})))}unmount(){var t,e;ke(this,te)._--,r(this,te)===0&&((t=r(this,Re))==null||t.call(this),u(this,Re,void 0),(e=r(this,Pe))==null||e.call(this),u(this,Pe,void 0))}isFetching(t){return r(this,P).findAll({...t,fetchStatus:"fetching"}).length}isMutating(t){return r(this,Z).findAll({...t,status:"pending"}).length}getQueryData(t){var s;const e=this.defaultQueryOptions({queryKey:t});return(s=r(this,P).get(e.queryHash))==null?void 0:s.state.data}ensureQueryData(t){const e=this.defaultQueryOptions(t),s=r(this,P).build(this,e),i=s.state.data;return i===void 0?this.fetchQuery(t):(t.revalidateIfStale&&s.isStaleByTime(pe(e.staleTime,s))&&this.prefetchQuery(e),Promise.resolve(i))}getQueriesData(t){return r(this,P).findAll(t).map(({queryKey:e,state:s})=>{const i=s.data;return[e,i]})}setQueryData(t,e,s){const i=this.defaultQueryOptions({queryKey:t}),n=r(this,P).get(i.queryHash),a=n==null?void 0:n.state.data,h=kt(e,a);if(h!==void 0)return r(this,P).build(this,i).setData(h,{...s,manual:!0})}setQueriesData(t,e,s){return E.batch(()=>r(this,P).findAll(t).map(({queryKey:i})=>[i,this.setQueryData(i,e,s)]))}getQueryState(t){var s;const e=this.defaultQueryOptions({queryKey:t});return(s=r(this,P).get(e.queryHash))==null?void 0:s.state}removeQueries(t){const e=r(this,P);E.batch(()=>{e.findAll(t).forEach(s=>{e.remove(s)})})}resetQueries(t,e){const s=r(this,P),i={type:"active",...t};return E.batch(()=>(s.findAll(t).forEach(n=>{n.reset()}),this.refetchQueries(i,e)))}cancelQueries(t,e={}){const s={revert:!0,...e},i=E.batch(()=>r(this,P).findAll(t).map(n=>n.cancel(s)));return Promise.all(i).then(k).catch(k)}invalidateQueries(t,e={}){return E.batch(()=>{if(r(this,P).findAll(t).forEach(i=>{i.invalidate()}),(t==null?void 0:t.refetchType)==="none")return Promise.resolve();const s={...t,type:(t==null?void 0:t.refetchType)??(t==null?void 0:t.type)??"active"};return this.refetchQueries(s,e)})}refetchQueries(t,e={}){const s={...e,cancelRefetch:e.cancelRefetch??!0},i=E.batch(()=>r(this,P).findAll(t).filter(n=>!n.isDisabled()).map(n=>{let a=n.fetch(void 0,s);return s.throwOnError||(a=a.catch(k)),n.state.fetchStatus==="paused"?Promise.resolve():a}));return Promise.all(i).then(k)}fetchQuery(t){const e=this.defaultQueryOptions(t);e.retry===void 0&&(e.retry=!1);const s=r(this,P).build(this,e);return s.isStaleByTime(pe(e.staleTime,s))?s.fetch(e):Promise.resolve(s.state.data)}prefetchQuery(t){return this.fetchQuery(t).then(k).catch(k)}fetchInfiniteQuery(t){return t.behavior=lt(t.pages),this.fetchQuery(t)}prefetchInfiniteQuery(t){return this.fetchInfiniteQuery(t).then(k).catch(k)}ensureInfiniteQueryData(t){return t.behavior=lt(t.pages),this.ensureQueryData(t)}resumePausedMutations(){return Ke.isOnline()?r(this,Z).resumePausedMutations():Promise.resolve()}getQueryCache(){return r(this,P)}getMutationCache(){return r(this,Z)}getDefaultOptions(){return r(this,ee)}setDefaultOptions(t){u(this,ee,t)}setQueryDefaults(t,e){r(this,Ce).set(Me(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){const e=[...r(this,Ce).values()],s={};return e.forEach(i=>{Te(t,i.queryKey)&&Object.assign(s,i.defaultOptions)}),s}setMutationDefaults(t,e){r(this,Oe).set(Me(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){const e=[...r(this,Oe).values()];let s={};return e.forEach(i=>{Te(t,i.mutationKey)&&(s={...s,...i.defaultOptions})}),s}defaultQueryOptions(t){if(t._defaulted)return t;const e={...r(this,ee).queries,...this.getQueryDefaults(t.queryKey),...t,_defaulted:!0};return e.queryHash||(e.queryHash=st(e.queryKey,e)),e.refetchOnReconnect===void 0&&(e.refetchOnReconnect=e.networkMode!=="always"),e.throwOnError===void 0&&(e.throwOnError=!!e.suspense),!e.networkMode&&e.persister&&(e.networkMode="offlineFirst"),e.queryFn===it&&(e.enabled=!1),e}defaultMutationOptions(t){return t!=null&&t._defaulted?t:{...r(this,ee).mutations,...(t==null?void 0:t.mutationKey)&&this.getMutationDefaults(t.mutationKey),...t,_defaulted:!0}}clear(){r(this,P).clear(),r(this,Z).clear()}},P=new WeakMap,Z=new WeakMap,ee=new WeakMap,Ce=new WeakMap,Oe=new WeakMap,te=new WeakMap,Re=new WeakMap,Pe=new WeakMap,Pt),q,m,xe,x,oe,Se,se,V,qe,Fe,Qe,ce,le,ie,Ee,v,De,$e,We,Je,Xe,Ye,Ze,et,xt,St,Zt=(St=class extends Ue{constructor(e,s){super();l(this,v);l(this,q);l(this,m);l(this,xe);l(this,x);l(this,oe);l(this,Se);l(this,se);l(this,V);l(this,qe);l(this,Fe);l(this,Qe);l(this,ce);l(this,le);l(this,ie);l(this,Ee,new Set);this.options=s,u(this,q,e),u(this,V,null),u(this,se,Ve()),this.options.experimental_prefetchInRender||r(this,se).reject(new Error("experimental_prefetchInRender feature flag is not enabled")),this.bindMethods(),this.setOptions(s)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(r(this,m).addObserver(this),ft(r(this,m),this.options)?p(this,v,De).call(this):this.updateResult(),p(this,v,Xe).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return tt(r(this,m),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return tt(r(this,m),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,p(this,v,Ye).call(this),p(this,v,Ze).call(this),r(this,m).removeObserver(this)}setOptions(e,s){const i=this.options,n=r(this,m);if(this.options=r(this,q).defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof G(this.options.enabled,r(this,m))!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");p(this,v,et).call(this),r(this,m).setOptions(this.options),i._defaulted&&!Ne(this.options,i)&&r(this,q).getQueryCache().notify({type:"observerOptionsUpdated",query:r(this,m),observer:this});const a=this.hasListeners();a&&yt(r(this,m),n,this.options,i)&&p(this,v,De).call(this),this.updateResult(s),a&&(r(this,m)!==n||G(this.options.enabled,r(this,m))!==G(i.enabled,r(this,m))||pe(this.options.staleTime,r(this,m))!==pe(i.staleTime,r(this,m)))&&p(this,v,$e).call(this);const h=p(this,v,We).call(this);a&&(r(this,m)!==n||G(this.options.enabled,r(this,m))!==G(i.enabled,r(this,m))||h!==r(this,ie))&&p(this,v,Je).call(this,h)}getOptimisticResult(e){const s=r(this,q).getQueryCache().build(r(this,q),e),i=this.createResult(s,e);return ts(this,i)&&(u(this,x,i),u(this,Se,this.options),u(this,oe,r(this,m).state)),i}getCurrentResult(){return r(this,x)}trackResult(e,s){const i={};return Object.keys(e).forEach(n=>{Object.defineProperty(i,n,{configurable:!1,enumerable:!0,get:()=>(this.trackProp(n),s==null||s(n),e[n])})}),i}trackProp(e){r(this,Ee).add(e)}getCurrentQuery(){return r(this,m)}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){const s=r(this,q).defaultQueryOptions(e),i=r(this,q).getQueryCache().build(r(this,q),s);return i.fetch().then(()=>this.createResult(i,s))}fetch(e){return p(this,v,De).call(this,{...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),r(this,x)))}createResult(e,s){var F;const i=r(this,m),n=this.options,a=r(this,x),h=r(this,oe),c=r(this,Se),w=e!==i?e.state:r(this,xe),{state:b}=e;let o={...b},C=!1,g;if(s._optimisticResults){const O=this.hasListeners(),fe=!O&&ft(e,s),ye=O&&yt(e,i,s,n);(fe||ye)&&(o={...o,...It(b.data,e.options)}),s._optimisticResults==="isRestoring"&&(o.fetchStatus="idle")}let{error:S,errorUpdatedAt:f,status:y}=o;if(s.select&&o.data!==void 0)if(a&&o.data===(h==null?void 0:h.data)&&s.select===r(this,qe))g=r(this,Fe);else try{u(this,qe,s.select),g=s.select(o.data),g=ze(a==null?void 0:a.data,g,s),u(this,Fe,g),u(this,V,null)}catch(O){u(this,V,O)}else g=o.data;if(s.placeholderData!==void 0&&g===void 0&&y==="pending"){let O;if(a!=null&&a.isPlaceholderData&&s.placeholderData===(c==null?void 0:c.placeholderData))O=a.data;else if(O=typeof s.placeholderData=="function"?s.placeholderData((F=r(this,Qe))==null?void 0:F.state.data,r(this,Qe)):s.placeholderData,s.select&&O!==void 0)try{O=s.select(O),u(this,V,null)}catch(fe){u(this,V,fe)}O!==void 0&&(y="success",g=ze(a==null?void 0:a.data,O,s),C=!0)}r(this,V)&&(S=r(this,V),g=r(this,Fe),f=Date.now(),y="error");const Q=o.fetchStatus==="fetching",T=y==="pending",R=y==="error",D=T&&Q,U=g!==void 0,A={status:y,fetchStatus:o.fetchStatus,isPending:T,isSuccess:y==="success",isError:R,isInitialLoading:D,isLoading:D,data:g,dataUpdatedAt:o.dataUpdatedAt,error:S,errorUpdatedAt:f,failureCount:o.fetchFailureCount,failureReason:o.fetchFailureReason,errorUpdateCount:o.errorUpdateCount,isFetched:o.dataUpdateCount>0||o.errorUpdateCount>0,isFetchedAfterMount:o.dataUpdateCount>w.dataUpdateCount||o.errorUpdateCount>w.errorUpdateCount,isFetching:Q,isRefetching:Q&&!T,isLoadingError:R&&!U,isPaused:o.fetchStatus==="paused",isPlaceholderData:C,isRefetchError:R&&U,isStale:nt(e,s),refetch:this.refetch,promise:r(this,se)};if(this.options.experimental_prefetchInRender){const O=je=>{A.status==="error"?je.reject(A.error):A.data!==void 0&&je.resolve(A.data)},fe=()=>{const je=u(this,se,A.promise=Ve());O(je)},ye=r(this,se);switch(ye.status){case"pending":e.queryHash===i.queryHash&&O(ye);break;case"fulfilled":(A.status==="error"||A.data!==ye.value)&&fe();break;case"rejected":(A.status!=="error"||A.error!==ye.reason)&&fe();break}}return A}updateResult(e){const s=r(this,x),i=this.createResult(r(this,m),this.options);if(u(this,oe,r(this,m).state),u(this,Se,this.options),r(this,oe).data!==void 0&&u(this,Qe,r(this,m)),Ne(i,s))return;u(this,x,i);const n={},a=()=>{if(!s)return!0;const{notifyOnChangeProps:h}=this.options,c=typeof h=="function"?h():h;if(c==="all"||!c&&!r(this,Ee).size)return!0;const d=new Set(c??r(this,Ee));return this.options.throwOnError&&d.add("error"),Object.keys(r(this,x)).some(w=>{const b=w;return r(this,x)[b]!==s[b]&&d.has(b)})};(e==null?void 0:e.listeners)!==!1&&a()&&(n.listeners=!0),p(this,v,xt).call(this,{...n,...e})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&p(this,v,Xe).call(this)}},q=new WeakMap,m=new WeakMap,xe=new WeakMap,x=new WeakMap,oe=new WeakMap,Se=new WeakMap,se=new WeakMap,V=new WeakMap,qe=new WeakMap,Fe=new WeakMap,Qe=new WeakMap,ce=new WeakMap,le=new WeakMap,ie=new WeakMap,Ee=new WeakMap,v=new WeakSet,De=function(e){p(this,v,et).call(this);let s=r(this,m).fetch(this.options,e);return e!=null&&e.throwOnError||(s=s.catch(k)),s},$e=function(){p(this,v,Ye).call(this);const e=pe(this.options.staleTime,r(this,m));if(de||r(this,x).isStale||!Ge(e))return;const i=Ft(r(this,x).dataUpdatedAt,e)+1;u(this,ce,setTimeout(()=>{r(this,x).isStale||this.updateResult()},i))},We=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(r(this,m)):this.options.refetchInterval)??!1},Je=function(e){p(this,v,Ze).call(this),u(this,ie,e),!(de||G(this.options.enabled,r(this,m))===!1||!Ge(r(this,ie))||r(this,ie)===0)&&u(this,le,setInterval(()=>{(this.options.refetchIntervalInBackground||rt.isFocused())&&p(this,v,De).call(this)},r(this,ie)))},Xe=function(){p(this,v,$e).call(this),p(this,v,Je).call(this,p(this,v,We).call(this))},Ye=function(){r(this,ce)&&(clearTimeout(r(this,ce)),u(this,ce,void 0))},Ze=function(){r(this,le)&&(clearInterval(r(this,le)),u(this,le,void 0))},et=function(){const e=r(this,q).getQueryCache().build(r(this,q),this.options);if(e===r(this,m))return;const s=r(this,m);u(this,m,e),u(this,xe,e.state),this.hasListeners()&&(s==null||s.removeObserver(this),e.addObserver(this))},xt=function(e){E.batch(()=>{e.listeners&&this.listeners.forEach(s=>{s(r(this,x))}),r(this,q).getQueryCache().notify({query:r(this,m),type:"observerResultsUpdated"})})},St);function es(t,e){return G(e.enabled,t)!==!1&&t.state.data===void 0&&!(t.state.status==="error"&&e.retryOnMount===!1)}function ft(t,e){return es(t,e)||t.state.data!==void 0&&tt(t,e,e.refetchOnMount)}function tt(t,e,s){if(G(e.enabled,t)!==!1){const i=typeof s=="function"?s(t):s;return i==="always"||i!==!1&&nt(t,e)}return!1}function yt(t,e,s,i){return(t!==e||G(i.enabled,t)===!1)&&(!s.suspense||t.state.status!=="error")&&nt(t,s)}function nt(t,e){return G(e.enabled,t)!==!1&&t.isStaleByTime(pe(e.staleTime,t))}function ts(t,e){return!Ne(t.getCurrentResult(),e)}var qt=L.createContext(void 0),ss=t=>{const e=L.useContext(qt);if(!e)throw new Error("No QueryClient set, use QueryClientProvider to set one");return e},vs=({client:t,children:e})=>(L.useEffect(()=>(t.mount(),()=>{t.unmount()}),[t]),jt.jsx(qt.Provider,{value:t,children:e})),Ut=L.createContext(!1),is=()=>L.useContext(Ut);Ut.Provider;function rs(){let t=!1;return{clearReset:()=>{t=!1},reset:()=>{t=!0},isReset:()=>t}}var ns=L.createContext(rs()),as=()=>L.useContext(ns);function us(t,e){return typeof t=="function"?t(...e):!!t}function pt(){}var hs=(t,e)=>{(t.suspense||t.throwOnError||t.experimental_prefetchInRender)&&(e.isReset()||(t.retryOnMount=!1))},os=t=>{L.useEffect(()=>{t.clearReset()},[t])},cs=({result:t,errorResetBoundary:e,throwOnError:s,query:i,suspense:n})=>t.isError&&!e.isReset()&&!t.isFetching&&i&&(n&&t.data===void 0||us(s,[t.error,i])),ls=t=>{const e=t.staleTime;t.suspense&&(t.staleTime=typeof e=="function"?(...s)=>Math.max(e(...s),1e3):Math.max(e??1e3,1e3),typeof t.gcTime=="number"&&(t.gcTime=Math.max(t.gcTime,1e3)))},ds=(t,e)=>t.isLoading&&t.isFetching&&!e,fs=(t,e)=>(t==null?void 0:t.suspense)&&e.isPending,mt=(t,e,s)=>e.fetchOptimistic(t).catch(()=>{s.clearReset()});function ys(t,e,s){var o,C,g,S,f;const i=ss(),n=is(),a=as(),h=i.defaultQueryOptions(t);(C=(o=i.getDefaultOptions().queries)==null?void 0:o._experimental_beforeQuery)==null||C.call(o,h),h._optimisticResults=n?"isRestoring":"optimistic",ls(h),hs(h,a),os(a);const c=!i.getQueryCache().get(h.queryHash),[d]=L.useState(()=>new e(i,h)),w=d.getOptimisticResult(h),b=!n&&t.subscribed!==!1;if(L.useSyncExternalStore(L.useCallback(y=>{const Q=b?d.subscribe(E.batchCalls(y)):pt;return d.updateResult(),Q},[d,b]),()=>d.getCurrentResult(),()=>d.getCurrentResult()),L.useEffect(()=>{d.setOptions(h,{listeners:!1})},[h,d]),fs(h,w))throw mt(h,d,a);if(cs({result:w,errorResetBoundary:a,throwOnError:h.throwOnError,query:i.getQueryCache().get(h.queryHash),suspense:h.suspense}))throw w.error;if((S=(g=i.getDefaultOptions().queries)==null?void 0:g._experimental_afterQuery)==null||S.call(g,h,w),h.experimental_prefetchInRender&&!de&&ds(w,n)){const y=c?mt(h,d,a):(f=i.getQueryCache().get(h.queryHash))==null?void 0:f.promise;y==null||y.catch(pt).finally(()=>{d.updateResult()})}return h.notifyOnChangeProps?w:d.trackResult(w)}function ws(t,e){return ys(t,Zt)}export{gs as Q,ss as a,vs as b,ws as u};