Socket
Socket
Sign inDemoInstall

@tanstack/query-core

Package Overview
Dependencies
Maintainers
1
Versions
266
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tanstack/query-core - npm Package Compare versions

Comparing version 5.0.0-alpha.2 to 5.0.0-alpha.3

3

build/lib/mutation.d.ts

@@ -51,5 +51,6 @@ import type { MutationOptions, MutationStatus, MutationMeta, DefaultError } from './types';

state: MutationState<TData, TError, TVariables, TContext>;
readonly options: MutationOptions<TData, TError, TVariables, TContext>;
options: MutationOptions<TData, TError, TVariables, TContext>;
readonly mutationId: number;
constructor(config: MutationConfig<TData, TError, TVariables, TContext>);
setOptions(options?: MutationOptions<TData, TError, TVariables, TContext>): void;
get meta(): MutationMeta | undefined;

@@ -56,0 +57,0 @@ addObserver(observer: MutationObserver<any, any, any, any>): void;

@@ -11,2 +11,3 @@ import { notifyManager } from './notifyManager.esm.js';

#observers;
#defaultOptions;
#mutationCache;

@@ -16,10 +17,17 @@ #retryer;

super();
this.options = config.options;
this.mutationId = config.mutationId;
this.#defaultOptions = config.defaultOptions;
this.#mutationCache = config.mutationCache;
this.#observers = [];
this.state = config.state || getDefaultState();
this.updateGcTime(this.options.gcTime);
this.setOptions(config.options);
this.scheduleGc();
}
setOptions(options) {
this.options = {
...this.#defaultOptions,
...options
};
this.updateGcTime(this.options.gcTime);
}
get meta() {

@@ -26,0 +34,0 @@ return this.options.meta;

@@ -13,2 +13,3 @@ 'use strict';

#observers;
#defaultOptions;
#mutationCache;

@@ -18,10 +19,17 @@ #retryer;

super();
this.options = config.options;
this.mutationId = config.mutationId;
this.#defaultOptions = config.defaultOptions;
this.#mutationCache = config.mutationCache;
this.#observers = [];
this.state = config.state || getDefaultState();
this.updateGcTime(this.options.gcTime);
this.setOptions(config.options);
this.scheduleGc();
}
setOptions(options) {
this.options = {
...this.#defaultOptions,
...options
};
this.updateGcTime(this.options.gcTime);
}
get meta() {

@@ -28,0 +36,0 @@ return this.options.meta;

@@ -9,6 +9,6 @@ import type { MutationObserver } from './mutationObserver';

interface MutationCacheConfig {
onError?: (error: unknown, variables: unknown, context: unknown, mutation: Mutation<unknown, unknown, unknown>) => Promise<unknown> | unknown;
onError?: (error: DefaultError, variables: unknown, context: unknown, mutation: Mutation<unknown, unknown, unknown>) => Promise<unknown> | unknown;
onSuccess?: (data: unknown, variables: unknown, context: unknown, mutation: Mutation<unknown, unknown, unknown>) => Promise<unknown> | unknown;
onMutate?: (variables: unknown, mutation: Mutation<unknown, unknown, unknown>) => Promise<unknown> | unknown;
onSettled?: (data: unknown | undefined, error: unknown | null, variables: unknown, context: unknown, mutation: Mutation<unknown, unknown, unknown>) => Promise<unknown> | unknown;
onSettled?: (data: unknown | undefined, error: DefaultError | null, variables: unknown, context: unknown, mutation: Mutation<unknown, unknown, unknown>) => Promise<unknown> | unknown;
}

@@ -15,0 +15,0 @@ interface NotifyEventMutationAdded extends NotifyEvent {

@@ -36,2 +36,3 @@ import { getDefaultState } from './mutation.esm.js';

}
this.#currentMutation?.setOptions(this.options);
}

@@ -38,0 +39,0 @@ onUnsubscribe() {

@@ -38,2 +38,3 @@ 'use strict';

}
this.#currentMutation?.setOptions(this.options);
}

@@ -40,0 +41,0 @@ onUnsubscribe() {

@@ -9,5 +9,5 @@ import type { QueryFilters } from './utils';

interface QueryCacheConfig {
onError?: (error: unknown, query: Query<unknown, unknown, unknown>) => void;
onError?: (error: DefaultError, query: Query<unknown, unknown, unknown>) => void;
onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void;
onSettled?: (data: unknown | undefined, error: unknown | null, query: Query<unknown, unknown, unknown>) => void;
onSettled?: (data: unknown | undefined, error: DefaultError | null, query: Query<unknown, unknown, unknown>) => void;
createStore?: () => QueryStore;

@@ -14,0 +14,0 @@ }

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).QueryCore={})}(this,(function(t){"use strict";class e{constructor(){this.listeners=[],this.subscribe=this.subscribe.bind(this)}subscribe(t){return this.listeners.push(t),this.onSubscribe(),()=>{this.listeners=this.listeners.filter((e=>e!==t)),this.onUnsubscribe()}}hasListeners(){return this.listeners.length>0}onSubscribe(){}onUnsubscribe(){}}const s="undefined"==typeof window||"Deno"in window;function i(){}function r(t){return"number"==typeof t&&t>=0&&t!==1/0}function n(t,e){return Math.max(t+(e||0)-Date.now(),0)}function a(t,e){const{type:s="all",exact:i,fetchStatus:r,predicate:n,queryKey:a,stale:o}=t;if(a)if(i){if(e.queryHash!==u(a,e.options))return!1}else if(!c(e.queryKey,a))return!1;if("all"!==s){const t=e.isActive();if("active"===s&&!t)return!1;if("inactive"===s&&t)return!1}return("boolean"!=typeof o||e.isStale()===o)&&((void 0===r||r===e.state.fetchStatus)&&!(n&&!n(e)))}function o(t,e){const{exact:s,status:i,predicate:r,mutationKey:n}=t;if(n){if(!e.options.mutationKey)return!1;if(s){if(h(e.options.mutationKey)!==h(n))return!1}else if(!c(e.options.mutationKey,n))return!1}return(!i||e.state.status===i)&&!(r&&!r(e))}function u(t,e){return(e?.queryKeyHashFn||h)(t)}function h(t){return JSON.stringify(t,((t,e)=>p(e)?Object.keys(e).sort().reduce(((t,s)=>(t[s]=e[s],t)),{}):e))}function c(t,e){return t===e||typeof t==typeof e&&(!(!t||!e||"object"!=typeof t||"object"!=typeof e)&&!Object.keys(e).some((s=>!c(t[s],e[s]))))}function l(t,e){if(t===e)return t;const s=f(t)&&f(e);if(s||p(t)&&p(e)){const i=s?t.length:Object.keys(t).length,r=s?e:Object.keys(e),n=r.length,a=s?[]:{};let o=0;for(let i=0;i<n;i++){const n=s?i:r[i];a[n]=l(t[n],e[n]),a[n]===t[n]&&o++}return i===n&&o===i?t:a}return e}function d(t,e){if(t&&!e||e&&!t)return!1;for(const s in t)if(t[s]!==e[s])return!1;return!0}function f(t){return Array.isArray(t)&&t.length===Object.keys(t).length}function p(t){if(!y(t))return!1;const e=t.constructor;if(void 0===e)return!0;const s=e.prototype;return!!y(s)&&!!s.hasOwnProperty("isPrototypeOf")}function y(t){return"[object Object]"===Object.prototype.toString.call(t)}function m(t){return new Promise((e=>{setTimeout(e,t)}))}function v(t){m(0).then(t)}function b(t,e,s){return"function"==typeof s.structuralSharing?s.structuralSharing(t,e):!1!==s.structuralSharing?l(t,e):e}function g(t,e,s=0){const i=[...t,e];return s&&i.length>s?i.slice(1):i}function O(t,e,s=0){const i=[e,...t];return s&&i.length>s?i.slice(0,-1):i}const R=new class extends e{#t;#e;#s;constructor(){super(),this.#s=t=>{if(!s&&window.addEventListener){const e=()=>t();return window.addEventListener("visibilitychange",e,!1),()=>{window.removeEventListener("visibilitychange",e)}}}}onSubscribe(){this.#e||this.setEventListener(this.#s)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(t){this.#s=t,this.#e?.(),this.#e=t((t=>{"boolean"==typeof t?this.setFocused(t):this.onFocus()}))}setFocused(t){this.#t=t,t&&this.onFocus()}onFocus(){this.listeners.forEach((t=>{t()}))}isFocused(){return"boolean"==typeof this.#t?this.#t:"hidden"!==globalThis.document?.visibilityState}};const C=new class extends e{#i;#e;#s;constructor(){super(),this.#s=t=>{if(!s&&window.addEventListener){const e=()=>t();return window.addEventListener("online",e,!1),window.addEventListener("offline",e,!1),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",e)}}}}onSubscribe(){this.#e||this.setEventListener(this.#s)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(t){this.#s=t,this.#e?.(),this.#e=t((t=>{"boolean"==typeof t?this.setOnline(t):this.onOnline()}))}setOnline(t){this.#i=t,t&&this.onOnline()}onOnline(){this.listeners.forEach((t=>{t()}))}isOnline(){return"boolean"==typeof this.#i?this.#i:"undefined"==typeof navigator||void 0===navigator.onLine||navigator.onLine}};function q(t){return Math.min(1e3*2**t,3e4)}function Q(t){return"online"!==(t??"online")||C.isOnline()}class S{constructor(t){this.revert=t?.revert,this.silent=t?.silent}}function w(t){return t instanceof S}function P(t){let e,s,i,r=!1,n=0,a=!1;const o=new Promise(((t,e)=>{s=t,i=e})),u=()=>!R.isFocused()||"always"!==t.networkMode&&!C.isOnline(),h=i=>{a||(a=!0,t.onSuccess?.(i),e?.(),s(i))},c=s=>{a||(a=!0,t.onError?.(s),e?.(),i(s))},l=()=>new Promise((s=>{e=t=>{const e=a||!u();return e&&s(t),e},t.onPause?.()})).then((()=>{e=void 0,a||t.onContinue?.()})),d=()=>{if(a)return;let e;try{e=t.fn()}catch(t){e=Promise.reject(t)}Promise.resolve(e).then(h).catch((e=>{if(a)return;const s=t.retry??3,i=t.retryDelay??q,o="function"==typeof i?i(n,e):i,h=!0===s||"number"==typeof s&&n<s||"function"==typeof s&&s(n,e);!r&&h?(n++,t.onFail?.(n,e),m(o).then((()=>{if(u())return l()})).then((()=>{r?c(e):d()}))):c(e)}))};return Q(t.networkMode)?d():l().then(d),{promise:o,cancel:e=>{a||(c(new S(e)),t.abort?.())},continue:()=>{const t=e?.();return t?o:Promise.resolve()},cancelRetry:()=>{r=!0},continueRetry:()=>{r=!1}}}const M=function(){let t=[],e=0,s=t=>{t()},i=t=>{t()};const r=i=>{e?t.push(i):v((()=>{s(i)}))},n=()=>{const e=t;t=[],e.length&&v((()=>{i((()=>{e.forEach((t=>{s(t)}))}))}))};return{batch:t=>{let s;e++;try{s=t()}finally{e--,e||n()}return s},batchCalls:t=>(...e)=>{r((()=>{t(...e)}))},schedule:r,setNotifyFunction:t=>{s=t},setBatchNotifyFunction:t=>{i=t}}}();class F{#r;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),r(this.gcTime)&&(this.#r=setTimeout((()=>{this.optionalRemove()}),this.gcTime))}updateGcTime(t){this.gcTime=Math.max(this.gcTime||0,t??(s?1/0:3e5))}clearGcTimeout(){this.#r&&(clearTimeout(this.#r),this.#r=void 0)}}class E extends F{#n;#a;#o;#u;#h;#c;#l;#d;constructor(t){super(),this.#d=!1,this.#l=t.defaultOptions,this.#f(t.options),this.#c=[],this.#o=t.cache,this.queryKey=t.queryKey,this.queryHash=t.queryHash,this.#n=t.state||function(t){const e="function"==typeof t.initialData?t.initialData():t.initialData,s=void 0!==e,i=s?"function"==typeof t.initialDataUpdatedAt?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"}}(this.options),this.state=this.#n,this.scheduleGc()}get meta(){return this.options.meta}#f(t){this.options={...this.#l,...t},this.updateGcTime(this.options.gcTime)}optionalRemove(){this.#c.length||"idle"!==this.state.fetchStatus||this.#o.remove(this)}setData(t,e){const s=b(this.state.data,t,this.options);return this.#p({data:s,type:"success",dataUpdatedAt:e?.updatedAt,manual:e?.manual}),s}setState(t,e){this.#p({type:"setState",state:t,setStateOptions:e})}cancel(t){const e=this.#u;return this.#h?.cancel(t),e?e.then(i).catch(i):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#n)}isActive(){return this.#c.some((t=>!1!==t.options.enabled))}isDisabled(){return this.getObserversCount()>0&&!this.isActive()}isStale(){return this.state.isInvalidated||!this.state.dataUpdatedAt||this.#c.some((t=>t.getCurrentResult().isStale))}isStaleByTime(t=0){return this.state.isInvalidated||!this.state.dataUpdatedAt||!n(this.state.dataUpdatedAt,t)}onFocus(){this.#c.find((t=>t.shouldFetchOnWindowFocus()))?.refetch({cancelRefetch:!1}),this.#h?.continue()}onOnline(){this.#c.find((t=>t.shouldFetchOnReconnect()))?.refetch({cancelRefetch:!1}),this.#h?.continue()}addObserver(t){-1===this.#c.indexOf(t)&&(this.#c.push(t),this.clearGcTimeout(),this.#o.notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){-1!==this.#c.indexOf(t)&&(this.#c=this.#c.filter((e=>e!==t)),this.#c.length||(this.#h&&(this.#d?this.#h.cancel({revert:!0}):this.#h.cancelRetry()),this.scheduleGc()),this.#o.notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.#c.length}invalidate(){this.state.isInvalidated||this.#p({type:"invalidate"})}fetch(t,e){if("idle"!==this.state.fetchStatus)if(this.state.dataUpdatedAt&&e?.cancelRefetch)this.cancel({silent:!0});else if(this.#u)return this.#h?.continueRetry(),this.#u;if(t&&this.#f(t),!this.options.queryFn){const t=this.#c.find((t=>t.options.queryFn));t&&this.#f(t.options)}const s=new AbortController,i={queryKey:this.queryKey,meta:this.meta},r=t=>{Object.defineProperty(t,"signal",{enumerable:!0,get:()=>(this.#d=!0,s.signal)})};r(i);const n={fetchOptions:e,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:()=>this.options.queryFn?(this.#d=!1,this.options.queryFn(i)):Promise.reject(new Error("Missing queryFn"))};r(n),this.options.behavior?.onFetch(n),this.#a=this.state,"idle"!==this.state.fetchStatus&&this.state.fetchMeta===n.fetchOptions?.meta||this.#p({type:"fetch",meta:n.fetchOptions?.meta});const a=t=>{w(t)&&t.silent||this.#p({type:"error",error:t}),w(t)||(this.#o.config.onError?.(t,this),this.#o.config.onSettled?.(this.state.data,t,this)),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1};return this.#h=P({fn:n.fetchFn,abort:s.abort.bind(s),onSuccess:t=>{void 0!==t?(this.setData(t),this.#o.config.onSuccess?.(t,this),this.#o.config.onSettled?.(t,this.state.error,this),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1):a(new Error("undefined"))},onError:a,onFail:(t,e)=>{this.#p({type:"failed",failureCount:t,error:e})},onPause:()=>{this.#p({type:"pause"})},onContinue:()=>{this.#p({type:"continue"})},retry:n.options.retry,retryDelay:n.options.retryDelay,networkMode:n.options.networkMode}),this.#u=this.#h.promise,this.#u}#p(t){this.state=(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":return{...e,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:t.meta??null,fetchStatus:Q(this.options.networkMode)?"fetching":"paused",...!e.dataUpdatedAt&&{error:null,status:"pending"}};case"success":return{...e,data:t.data,dataUpdateCount:e.dataUpdateCount+1,dataUpdatedAt:t.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":const s=t.error;return w(s)&&s.revert&&this.#a?{...this.#a}:{...e,error:s,errorUpdateCount:e.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:e.fetchFailureCount+1,fetchFailureReason:s,fetchStatus:"idle",status:"error"};case"invalidate":return{...e,isInvalidated:!0};case"setState":return{...e,...t.state}}})(this.state),M.batch((()=>{this.#c.forEach((e=>{e.onQueryUpdate(t)})),this.#o.notify({query:this,type:"updated",action:t})}))}}class x extends e{#y;constructor(t={}){super(),this.config=t,this.#y=t.createStore?.()??new Map}build(t,e,s){const i=e.queryKey,r=e.queryHash??u(i,e);let n=this.get(r);return n||(n=new E({cache:this,queryKey:i,queryHash:r,options:t.defaultQueryOptions(e),state:s,defaultOptions:t.getQueryDefaults(i)}),this.add(n)),n}add(t){this.#y.has(t.queryHash)||(this.#y.set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const e=this.#y.get(t.queryHash);e&&(t.destroy(),e===t&&this.#y.delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){M.batch((()=>{this.getAll().forEach((t=>{this.remove(t)}))}))}get(t){return this.#y.get(t)}getAll(){return[...this.#y.values()]}find(t){return void 0===t.exact&&(t.exact=!0),this.getAll().find((e=>a(t,e)))}findAll(t={}){const e=this.getAll();return Object.keys(t).length>0?e.filter((e=>a(t,e))):e}notify(t){M.batch((()=>{this.listeners.forEach((e=>{e(t)}))}))}onFocus(){M.batch((()=>{this.getAll().forEach((t=>{t.onFocus()}))}))}onOnline(){M.batch((()=>{this.getAll().forEach((t=>{t.onOnline()}))}))}}class D extends F{#c;#m;#h;constructor(t){super(),this.options=t.options,this.mutationId=t.mutationId,this.#m=t.mutationCache,this.#c=[],this.state=t.state||A(),this.updateGcTime(this.options.gcTime),this.scheduleGc()}get meta(){return this.options.meta}addObserver(t){-1===this.#c.indexOf(t)&&(this.#c.push(t),this.clearGcTimeout(),this.#m.notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){this.#c=this.#c.filter((e=>e!==t)),this.scheduleGc(),this.#m.notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){this.#c.length||("pending"===this.state.status?this.scheduleGc():this.#m.remove(this))}continue(){return this.#h?.continue()??this.execute(this.state.variables)}async execute(t){const e=()=>(this.#h=P({fn:()=>this.options.mutationFn?this.options.mutationFn(t):Promise.reject(new Error("No mutationFn found")),onFail:(t,e)=>{this.#p({type:"failed",failureCount:t,error:e})},onPause:()=>{this.#p({type:"pause"})},onContinue:()=>{this.#p({type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode}),this.#h.promise),s="pending"===this.state.status;try{if(!s){this.#p({type:"pending",variables:t}),await(this.#m.config.onMutate?.(t,this));const e=await(this.options.onMutate?.(t));e!==this.state.context&&this.#p({type:"pending",context:e,variables:t})}const i=await e();return await(this.#m.config.onSuccess?.(i,t,this.state.context,this)),await(this.options.onSuccess?.(i,t,this.state.context)),await(this.#m.config.onSettled?.(i,null,this.state.variables,this.state.context,this)),await(this.options.onSettled?.(i,null,t,this.state.context)),this.#p({type:"success",data:i}),i}catch(e){try{throw await(this.#m.config.onError?.(e,t,this.state.context,this)),await(this.options.onError?.(e,t,this.state.context)),await(this.#m.config.onSettled?.(void 0,e,this.state.variables,this.state.context,this)),await(this.options.onSettled?.(void 0,e,t,this.state.context)),e}finally{this.#p({type:"error",error:e})}}}#p(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:!Q(this.options.networkMode),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),M.batch((()=>{this.#c.forEach((e=>{e.onMutationUpdate(t)})),this.#m.notify({mutation:this,type:"updated",action:t})}))}}function A(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}class I extends e{#v;#b;#g;constructor(t={}){super(),this.config=t,this.#v=[],this.#b=0}build(t,e,s){const i=new D({mutationCache:this,mutationId:++this.#b,options:t.defaultMutationOptions(e),state:s});return this.add(i),i}add(t){this.#v.push(t),this.notify({type:"added",mutation:t})}remove(t){this.#v=this.#v.filter((e=>e!==t)),this.notify({type:"removed",mutation:t})}clear(){M.batch((()=>{this.#v.forEach((t=>{this.remove(t)}))}))}getAll(){return this.#v}find(t){return void 0===t.exact&&(t.exact=!0),this.#v.find((e=>o(t,e)))}findAll(t={}){return this.#v.filter((e=>o(t,e)))}notify(t){M.batch((()=>{this.listeners.forEach((e=>{e(t)}))}))}resumePausedMutations(){return this.#g=(this.#g??Promise.resolve()).then((()=>{const t=this.#v.filter((t=>t.state.isPaused));return M.batch((()=>t.reduce(((t,e)=>t.then((()=>e.continue().catch(i)))),Promise.resolve())))})).then((()=>{this.#g=void 0})),this.#g}}function U(){return{onFetch:t=>{t.fetchFn=()=>{const e=t.options,s=t.fetchOptions?.meta?.fetchMore?.direction,i=t.state.data?.pages||[],r=t.state.data?.pageParams||[];let n=r,a=!1;const o=t.options.queryFn||(()=>Promise.reject(new Error("Missing queryFn"))),u=(e,s,i)=>{if(a)return Promise.reject();if(void 0===s&&e.length)return Promise.resolve(e);const r={queryKey:t.queryKey,pageParam:s,meta:t.options.meta};var u;u=r,Object.defineProperty(u,"signal",{enumerable:!0,get:()=>(t.signal.aborted?a=!0:t.signal.addEventListener("abort",(()=>{a=!0})),t.signal)});const h=o(r),c=Promise.resolve(h).then((r=>((e,s,i,r)=>{const{maxPages:a}=t.options;return r?(n=O(n,s,a),O(e,i,a)):(n=g(n,s,a),g(e,i,a))})(e,s,r,i)));return c};let h;if(i.length)if(s){const t="backward"===s,r=t?K(e,i):T(e,i);h=u(i,r,t)}else{n=[],h=u([],r[0]);for(let t=1;t<i.length;t++)h=h.then((t=>{const s=T(e,t);return u(t,s)}))}else h=u([],e.defaultPageParam);return h.then((t=>({pages:t,pageParams:n})))}}}}function T(t,e){return t.getNextPageParam(e[e.length-1],e)}function K(t,e){return t.getPreviousPageParam?.(e[0],e)}function k(t,e){return!!e&&void 0!==T(t,e)}function L(t,e){return!(!e||!t.getPreviousPageParam)&&void 0!==K(t,e)}class j extends e{#O;#R=void 0;#C=void 0;#q=void 0;#Q;#S;#w;#P;#M;#F;#E;#x;#D;#A=new Set;constructor(t,e){super(),this.#O=t,this.options=e,this.#P=null,this.bindMethods(),this.setOptions(e)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){1===this.listeners.length&&(this.#R.addObserver(this),H(this.#R,this.options)&&this.#I(),this.#U())}onUnsubscribe(){this.listeners.length||this.destroy()}shouldFetchOnReconnect(){return G(this.#R,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return G(this.#R,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=[],this.#T(),this.#K(),this.#R.removeObserver(this)}setOptions(t,e){const s=this.options,i=this.#R;if(this.options=this.#O.defaultQueryOptions(t),d(s,this.options)||this.#O.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#R,observer:this}),void 0!==this.options.enabled&&"boolean"!=typeof this.options.enabled)throw new Error("Expected enabled to be a boolean");this.options.queryKey||(this.options.queryKey=s.queryKey),this.#k();const r=this.hasListeners();r&&N(this.#R,i,this.options,s)&&this.#I(),this.#L(e),!r||this.#R===i&&this.options.enabled===s.enabled&&this.options.staleTime===s.staleTime||this.#j();const n=this.#H();!r||this.#R===i&&this.options.enabled===s.enabled&&n===this.#D||this.#G(n)}getOptimisticResult(t){const e=this.#O.getQueryCache().build(this.#O,t);return this.createResult(e,t)}getCurrentResult(){return this.#q}trackResult(t){const e={};return Object.keys(t).forEach((s=>{Object.defineProperty(e,s,{configurable:!1,enumerable:!0,get:()=>(this.#A.add(s),t[s])})})),e}getCurrentQuery(){return this.#R}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const e=this.#O.defaultQueryOptions(t),s=this.#O.getQueryCache().build(this.#O,e);return s.isFetchingOptimistic=!0,s.fetch().then((()=>this.createResult(s,e)))}fetch(t){return this.#I({...t,cancelRefetch:t.cancelRefetch??!0}).then((()=>(this.#L(),this.#q)))}#I(t){this.#k();let e=this.#R.fetch(this.options,t);return t?.throwOnError||(e=e.catch(i)),e}#j(){if(this.#T(),s||this.#q.isStale||!r(this.options.staleTime))return;const t=n(this.#q.dataUpdatedAt,this.options.staleTime)+1;this.#E=setTimeout((()=>{this.#q.isStale||this.#L()}),t)}#H(){return"function"==typeof this.options.refetchInterval?this.options.refetchInterval(this.#q.data,this.#R):this.options.refetchInterval??!1}#G(t){this.#K(),this.#D=t,!s&&!1!==this.options.enabled&&r(this.#D)&&0!==this.#D&&(this.#x=setInterval((()=>{(this.options.refetchIntervalInBackground||R.isFocused())&&this.#I()}),this.#D))}#U(){this.#j(),this.#G(this.#H())}#T(){this.#E&&(clearTimeout(this.#E),this.#E=void 0)}#K(){this.#x&&(clearInterval(this.#x),this.#x=void 0)}createResult(t,e){const s=this.#R,i=this.options,r=this.#q,n=this.#Q,a=this.#S,o=t!==s,u=o?t.state:this.#C,h=o?this.#q:this.#w,{state:c}=t;let l,{error:d,errorUpdatedAt:f,fetchStatus:p,status:y}=c,m=!1;if(e._optimisticResults){const r=this.hasListeners(),n=!r&&H(t,e),a=r&&N(t,s,e,i);(n||a)&&(p=Q(t.options.networkMode)?"fetching":"paused",c.dataUpdatedAt||(y="pending")),"isRestoring"===e._optimisticResults&&(p="idle")}if(e.select&&void 0!==c.data)if(r&&c.data===n?.data&&e.select===this.#M)l=this.#F;else try{this.#M=e.select,l=e.select(c.data),l=b(r?.data,l,e),this.#F=l,this.#P=null}catch(t){this.#P=t}else l=c.data;if(void 0!==e.placeholderData&&void 0===l&&"pending"===y){let t;if(r?.isPlaceholderData&&e.placeholderData===a?.placeholderData)t=r.data;else if(t="function"==typeof e.placeholderData?e.placeholderData(h?.data):e.placeholderData,e.select&&void 0!==t)try{t=e.select(t),this.#P=null}catch(t){this.#P=t}void 0!==t&&(y="success",l=b(r?.data,t,e),m=!0)}this.#P&&(d=this.#P,l=this.#F,f=Date.now(),y="error");const v="fetching"===p,g="pending"===y,O="error"===y,R=g&&v;return{status:y,fetchStatus:p,isPending:g,isSuccess:"success"===y,isError:O,isInitialLoading:R,isLoading:R,data:l,dataUpdatedAt:c.dataUpdatedAt,error:d,errorUpdatedAt:f,failureCount:c.fetchFailureCount,failureReason:c.fetchFailureReason,errorUpdateCount:c.errorUpdateCount,isFetched:c.dataUpdateCount>0||c.errorUpdateCount>0,isFetchedAfterMount:c.dataUpdateCount>u.dataUpdateCount||c.errorUpdateCount>u.errorUpdateCount,isFetching:v,isRefetching:v&&!g,isLoadingError:O&&0===c.dataUpdatedAt,isPaused:"paused"===p,isPlaceholderData:m,isRefetchError:O&&0!==c.dataUpdatedAt,isStale:_(t,e),refetch:this.refetch}}#L(t){const e=this.#q,s=this.createResult(this.#R,this.options);if(this.#Q=this.#R.state,this.#S=this.options,d(s,e))return;this.#q=s;const i={};!1!==t?.listeners&&(()=>{if(!e)return!0;const{notifyOnChangeProps:t}=this.options;if("all"===t||!t&&!this.#A.size)return!0;const s=new Set(t??this.#A);return this.options.throwErrors&&s.add("error"),Object.keys(this.#q).some((t=>{const i=t;return this.#q[i]!==e[i]&&s.has(i)}))})()&&(i.listeners=!0),this.#N({...i,...t})}#k(){const t=this.#O.getQueryCache().build(this.#O,this.options);if(t===this.#R)return;const e=this.#R;this.#R=t,this.#C=t.state,this.#w=this.#q,this.hasListeners()&&(e?.removeObserver(this),t.addObserver(this))}onQueryUpdate(t){const e={};"success"===t.type?e.onSuccess=!t.manual:"error"!==t.type||w(t.error)||(e.onError=!0),this.#L(e),this.hasListeners()&&this.#U()}#N(t){M.batch((()=>{t.onSuccess?(this.options.onSuccess?.(this.#q.data),this.options.onSettled?.(this.#q.data,null)):t.onError&&(this.options.onError?.(this.#q.error),this.options.onSettled?.(void 0,this.#q.error)),t.listeners&&this.listeners.forEach((t=>{t(this.#q)})),this.#O.getQueryCache().notify({query:this.#R,type:"observerResultsUpdated"})}))}}function H(t,e){return function(t,e){return!(!1===e.enabled||t.state.dataUpdatedAt||"error"===t.state.status&&!1===e.retryOnMount)}(t,e)||t.state.dataUpdatedAt>0&&G(t,e,e.refetchOnMount)}function G(t,e,s){if(!1!==e.enabled){const i="function"==typeof s?s(t):s;return"always"===i||!1!==i&&_(t,e)}return!1}function N(t,e,s,i){return!1!==s.enabled&&(t!==e||!1===i.enabled)&&(!s.suspense||"error"!==t.state.status)&&_(t,s)}function _(t,e){return t.isStaleByTime(e.staleTime)}function B(t,e){return t.filter((t=>-1===e.indexOf(t)))}function W(t){return t.state.isPaused}function z(t){return"success"===t.state.status}t.CancelledError=S,t.InfiniteQueryObserver=class extends j{constructor(t,e){super(t,e)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(t,e){super.setOptions({...t,behavior:U()},e)}getOptimisticResult(t){return t.behavior=U(),super.getOptimisticResult(t)}fetchNextPage(t={}){return this.fetch({...t,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage({...t}={}){return this.fetch({...t,meta:{fetchMore:{direction:"backward"}}})}createResult(t,e){const{state:s}=t,i=super.createResult(t,e),{isFetching:r,isRefetching:n}=i,a=r&&"forward"===s.fetchMeta?.fetchMore?.direction,o=r&&"backward"===s.fetchMeta?.fetchMore?.direction;return{...i,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:k(e,s.data?.pages),hasPreviousPage:L(e,s.data?.pages),isFetchingNextPage:a,isFetchingPreviousPage:o,isRefetching:n&&!a&&!o}}},t.MutationCache=I,t.MutationObserver=class extends e{#O;#q=void 0;#_;#B;constructor(t,e){super(),this.#O=t,this.setOptions(e),this.bindMethods(),this.#L()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){const e=this.options;this.options=this.#O.defaultMutationOptions(t),d(e,this.options)||this.#O.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#_,observer:this})}onUnsubscribe(){this.listeners.length||this.#_?.removeObserver(this)}onMutationUpdate(t){this.#L(),this.#N(t)}getCurrentResult(){return this.#q}reset(){this.#_=void 0,this.#L(),this.#N()}mutate(t,e){return this.#B=e,this.#_?.removeObserver(this),this.#_=this.#O.getMutationCache().build(this.#O,this.options),this.#_.addObserver(this),this.#_.execute(t)}#L(){const t=this.#_?.state??{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0};this.#q={...t,isPending:"pending"===t.status,isSuccess:"success"===t.status,isError:"error"===t.status,isIdle:"idle"===t.status,mutate:this.mutate,reset:this.reset}}#N(t){M.batch((()=>{this.#B&&this.hasListeners()&&("success"===t?.type?(this.#B.onSuccess?.(t.data,this.#q.variables,this.#q.context),this.#B.onSettled?.(t.data,null,this.#q.variables,this.#q.context)):"error"===t?.type&&(this.#B.onError?.(t.error,this.#q.variables,this.#q.context),this.#B.onSettled?.(void 0,t.error,this.#q.variables,this.#q.context))),this.listeners.forEach((t=>{t(this.#q)}))}))}},t.QueriesObserver=class extends e{#O;#W;#y;#c;constructor(t,e){super(),this.#O=t,this.#y=[],this.#W=[],this.#c=[],e&&this.setQueries(e)}onSubscribe(){1===this.listeners.length&&this.#c.forEach((t=>{t.subscribe((e=>{this.#z(t,e)}))}))}onUnsubscribe(){this.listeners.length||this.destroy()}destroy(){this.listeners=[],this.#c.forEach((t=>{t.destroy()}))}setQueries(t,e){this.#y=t,M.batch((()=>{const t=this.#c,s=this.#J(this.#y);s.forEach((t=>t.observer.setOptions(t.defaultedQueryOptions,e)));const i=s.map((t=>t.observer)),r=i.map((t=>t.getCurrentResult())),n=i.some(((e,s)=>e!==t[s]));(t.length!==i.length||n)&&(this.#c=i,this.#W=r,this.hasListeners()&&(B(t,i).forEach((t=>{t.destroy()})),B(i,t).forEach((t=>{t.subscribe((e=>{this.#z(t,e)}))})),this.#N()))}))}getCurrentResult(){return this.#W}getQueries(){return this.#c.map((t=>t.getCurrentQuery()))}getObservers(){return this.#c}getOptimisticResult(t){return this.#J(t).map((t=>t.observer.getOptimisticResult(t.defaultedQueryOptions)))}#J(t){const e=this.#c,s=t.map((t=>this.#O.defaultQueryOptions(t))),i=s.flatMap((t=>{const s=e.find((e=>e.options.queryHash===t.queryHash));return null!=s?[{defaultedQueryOptions:t,observer:s}]:[]})),r=i.map((t=>t.defaultedQueryOptions.queryHash)),n=s.filter((t=>!r.includes(t.queryHash))),a=t=>{const e=this.#O.defaultQueryOptions(t);return this.#c.find((t=>t.options.queryHash===e.queryHash))??new j(this.#O,e)},o=n.map((t=>({defaultedQueryOptions:t,observer:a(t)})));return i.concat(o).sort(((t,e)=>s.indexOf(t.defaultedQueryOptions)-s.indexOf(e.defaultedQueryOptions)))}#z(t,e){const s=this.#c.indexOf(t);-1!==s&&(this.#W=function(t,e,s){const i=t.slice(0);return i[e]=s,i}(this.#W,s,e),this.#N())}#N(){M.batch((()=>{this.listeners.forEach((t=>{t(this.#W)}))}))}},t.QueryCache=x,t.QueryClient=class{#V;#m;#l;#X;#Y;#Z;#$;#tt;constructor(t={}){this.#V=t.queryCache||new x,this.#m=t.mutationCache||new I,this.#l=t.defaultOptions||{},this.#X=new Map,this.#Y=new Map,this.#Z=0}mount(){this.#Z++,1===this.#Z&&(this.#$=R.subscribe((()=>{R.isFocused()&&(this.resumePausedMutations(),this.#V.onFocus())})),this.#tt=C.subscribe((()=>{C.isOnline()&&(this.resumePausedMutations(),this.#V.onOnline())})))}unmount(){this.#Z--,0===this.#Z&&(this.#$?.(),this.#$=void 0,this.#tt?.(),this.#tt=void 0)}isFetching(t){return this.#V.findAll({...t,fetchStatus:"fetching"}).length}isMutating(t){return this.#m.findAll({...t,status:"pending"}).length}getQueryData(t){return this.#V.find({queryKey:t})?.state.data}ensureQueryData(t){const e=this.getQueryData(t.queryKey);return e?Promise.resolve(e):this.fetchQuery(t)}getQueriesData(t){return this.getQueryCache().findAll(t).map((({queryKey:t,state:e})=>[t,e.data]))}setQueryData(t,e,s){const i=this.#V.find({queryKey:t})?.state.data,r=function(t,e){return"function"==typeof t?t(e):t}(e,i);if(void 0===r)return;const n=this.defaultQueryOptions({queryKey:t});return this.#V.build(this,n).setData(r,{...s,manual:!0})}setQueriesData(t,e,s){return M.batch((()=>this.getQueryCache().findAll(t).map((({queryKey:t})=>[t,this.setQueryData(t,e,s)]))))}getQueryState(t){return this.#V.find({queryKey:t})?.state}removeQueries(t){const e=this.#V;M.batch((()=>{e.findAll(t).forEach((t=>{e.remove(t)}))}))}resetQueries(t,e){const s=this.#V,i={type:"active",...t};return M.batch((()=>(s.findAll(t).forEach((t=>{t.reset()})),this.refetchQueries(i,e))))}cancelQueries(t={},e={}){void 0===e.revert&&(e.revert=!0);const s=M.batch((()=>this.#V.findAll(t).map((t=>t.cancel(e)))));return Promise.all(s).then(i).catch(i)}invalidateQueries(t={},e={}){return M.batch((()=>{if(this.#V.findAll(t).forEach((t=>{t.invalidate()})),"none"===t.refetchType)return Promise.resolve();const s={...t,type:t.refetchType??t.type??"active"};return this.refetchQueries(s,e)}))}refetchQueries(t={},e){const s=M.batch((()=>this.#V.findAll(t).filter((t=>!t.isDisabled())).map((t=>t.fetch(void 0,{...e,cancelRefetch:e?.cancelRefetch??!0})))));let r=Promise.all(s).then(i);return e?.throwOnError||(r=r.catch(i)),r}fetchQuery(t){const e=this.defaultQueryOptions(t);void 0===e.retry&&(e.retry=!1);const s=this.#V.build(this,e);return s.isStaleByTime(e.staleTime)?s.fetch(e):Promise.resolve(s.state.data)}prefetchQuery(t){return this.fetchQuery(t).then(i).catch(i)}fetchInfiniteQuery(t){return t.behavior=U(),this.fetchQuery(t)}prefetchInfiniteQuery(t){return this.fetchInfiniteQuery(t).then(i).catch(i)}resumePausedMutations(){return this.#m.resumePausedMutations()}getQueryCache(){return this.#V}getMutationCache(){return this.#m}getDefaultOptions(){return this.#l}setDefaultOptions(t){this.#l=t}setQueryDefaults(t,e){this.#X.set(h(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){const e=[...this.#X.values()];let s={};return e.forEach((e=>{c(t,e.queryKey)&&(s={...s,...e.defaultOptions})})),s}setMutationDefaults(t,e){this.#Y.set(h(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){const e=[...this.#Y.values()];let s={};return e.forEach((e=>{c(t,e.mutationKey)&&(s={...s,...e.defaultOptions})})),s}defaultQueryOptions(t){if(t?._defaulted)return t;const e={...this.#l.queries,...t?.queryKey&&this.getQueryDefaults(t.queryKey),...t,_defaulted:!0};return e.queryHash||(e.queryHash=u(e.queryKey,e)),void 0===e.refetchOnReconnect&&(e.refetchOnReconnect="always"!==e.networkMode),void 0===e.throwErrors&&(e.throwErrors=!!e.suspense),e}defaultMutationOptions(t){return t?._defaulted?t:{...this.#l.mutations,...t?.mutationKey&&this.getMutationDefaults(t.mutationKey),...t,_defaulted:!0}}clear(){this.#V.clear(),this.#m.clear()}},t.QueryObserver=j,t.defaultShouldDehydrateMutation=W,t.defaultShouldDehydrateQuery=z,t.dehydrate=function(t,e={}){const s=[],i=[];if(!1!==e.dehydrateMutations){const i=e.shouldDehydrateMutation||W;t.getMutationCache().getAll().forEach((t=>{i(t)&&s.push(function(t){return{mutationKey:t.options.mutationKey,state:t.state}}(t))}))}if(!1!==e.dehydrateQueries){const s=e.shouldDehydrateQuery||z;t.getQueryCache().getAll().forEach((t=>{s(t)&&i.push(function(t){return{state:t.state,queryKey:t.queryKey,queryHash:t.queryHash}}(t))}))}return{mutations:s,queries:i}},t.focusManager=R,t.hashKey=h,t.hydrate=function(t,e,s){if("object"!=typeof e||null===e)return;const i=t.getMutationCache(),r=t.getQueryCache(),n=e.mutations||[],a=e.queries||[];n.forEach((e=>{i.build(t,{...s?.defaultOptions?.mutations,mutationKey:e.mutationKey},e.state)})),a.forEach((e=>{const i=r.get(e.queryHash),n={...e.state,fetchStatus:"idle"};i?i.state.dataUpdatedAt<n.dataUpdatedAt&&i.setState(n):r.build(t,{...s?.defaultOptions?.queries,queryKey:e.queryKey,queryHash:e.queryHash},n)}))},t.isCancelledError=w,t.isServer=s,t.keepPreviousData=function(t){return t},t.matchQuery=a,t.notifyManager=M,t.onlineManager=C,t.replaceEqualDeep=l}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).QueryCore={})}(this,(function(t){"use strict";class e{constructor(){this.listeners=[],this.subscribe=this.subscribe.bind(this)}subscribe(t){return this.listeners.push(t),this.onSubscribe(),()=>{this.listeners=this.listeners.filter((e=>e!==t)),this.onUnsubscribe()}}hasListeners(){return this.listeners.length>0}onSubscribe(){}onUnsubscribe(){}}const s="undefined"==typeof window||"Deno"in window;function i(){}function r(t){return"number"==typeof t&&t>=0&&t!==1/0}function n(t,e){return Math.max(t+(e||0)-Date.now(),0)}function o(t,e){const{type:s="all",exact:i,fetchStatus:r,predicate:n,queryKey:o,stale:a}=t;if(o)if(i){if(e.queryHash!==u(o,e.options))return!1}else if(!c(e.queryKey,o))return!1;if("all"!==s){const t=e.isActive();if("active"===s&&!t)return!1;if("inactive"===s&&t)return!1}return("boolean"!=typeof a||e.isStale()===a)&&((void 0===r||r===e.state.fetchStatus)&&!(n&&!n(e)))}function a(t,e){const{exact:s,status:i,predicate:r,mutationKey:n}=t;if(n){if(!e.options.mutationKey)return!1;if(s){if(h(e.options.mutationKey)!==h(n))return!1}else if(!c(e.options.mutationKey,n))return!1}return(!i||e.state.status===i)&&!(r&&!r(e))}function u(t,e){return(e?.queryKeyHashFn||h)(t)}function h(t){return JSON.stringify(t,((t,e)=>p(e)?Object.keys(e).sort().reduce(((t,s)=>(t[s]=e[s],t)),{}):e))}function c(t,e){return t===e||typeof t==typeof e&&(!(!t||!e||"object"!=typeof t||"object"!=typeof e)&&!Object.keys(e).some((s=>!c(t[s],e[s]))))}function l(t,e){if(t===e)return t;const s=f(t)&&f(e);if(s||p(t)&&p(e)){const i=s?t.length:Object.keys(t).length,r=s?e:Object.keys(e),n=r.length,o=s?[]:{};let a=0;for(let i=0;i<n;i++){const n=s?i:r[i];o[n]=l(t[n],e[n]),o[n]===t[n]&&a++}return i===n&&a===i?t:o}return e}function d(t,e){if(t&&!e||e&&!t)return!1;for(const s in t)if(t[s]!==e[s])return!1;return!0}function f(t){return Array.isArray(t)&&t.length===Object.keys(t).length}function p(t){if(!y(t))return!1;const e=t.constructor;if(void 0===e)return!0;const s=e.prototype;return!!y(s)&&!!s.hasOwnProperty("isPrototypeOf")}function y(t){return"[object Object]"===Object.prototype.toString.call(t)}function m(t){return new Promise((e=>{setTimeout(e,t)}))}function v(t){m(0).then(t)}function b(t,e,s){return"function"==typeof s.structuralSharing?s.structuralSharing(t,e):!1!==s.structuralSharing?l(t,e):e}function g(t,e,s=0){const i=[...t,e];return s&&i.length>s?i.slice(1):i}function O(t,e,s=0){const i=[e,...t];return s&&i.length>s?i.slice(0,-1):i}const R=new class extends e{#t;#e;#s;constructor(){super(),this.#s=t=>{if(!s&&window.addEventListener){const e=()=>t();return window.addEventListener("visibilitychange",e,!1),()=>{window.removeEventListener("visibilitychange",e)}}}}onSubscribe(){this.#e||this.setEventListener(this.#s)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(t){this.#s=t,this.#e?.(),this.#e=t((t=>{"boolean"==typeof t?this.setFocused(t):this.onFocus()}))}setFocused(t){this.#t=t,t&&this.onFocus()}onFocus(){this.listeners.forEach((t=>{t()}))}isFocused(){return"boolean"==typeof this.#t?this.#t:"hidden"!==globalThis.document?.visibilityState}};const C=new class extends e{#i;#e;#s;constructor(){super(),this.#s=t=>{if(!s&&window.addEventListener){const e=()=>t();return window.addEventListener("online",e,!1),window.addEventListener("offline",e,!1),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",e)}}}}onSubscribe(){this.#e||this.setEventListener(this.#s)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(t){this.#s=t,this.#e?.(),this.#e=t((t=>{"boolean"==typeof t?this.setOnline(t):this.onOnline()}))}setOnline(t){this.#i=t,t&&this.onOnline()}onOnline(){this.listeners.forEach((t=>{t()}))}isOnline(){return"boolean"==typeof this.#i?this.#i:"undefined"==typeof navigator||void 0===navigator.onLine||navigator.onLine}};function q(t){return Math.min(1e3*2**t,3e4)}function Q(t){return"online"!==(t??"online")||C.isOnline()}class S{constructor(t){this.revert=t?.revert,this.silent=t?.silent}}function w(t){return t instanceof S}function P(t){let e,s,i,r=!1,n=0,o=!1;const a=new Promise(((t,e)=>{s=t,i=e})),u=()=>!R.isFocused()||"always"!==t.networkMode&&!C.isOnline(),h=i=>{o||(o=!0,t.onSuccess?.(i),e?.(),s(i))},c=s=>{o||(o=!0,t.onError?.(s),e?.(),i(s))},l=()=>new Promise((s=>{e=t=>{const e=o||!u();return e&&s(t),e},t.onPause?.()})).then((()=>{e=void 0,o||t.onContinue?.()})),d=()=>{if(o)return;let e;try{e=t.fn()}catch(t){e=Promise.reject(t)}Promise.resolve(e).then(h).catch((e=>{if(o)return;const s=t.retry??3,i=t.retryDelay??q,a="function"==typeof i?i(n,e):i,h=!0===s||"number"==typeof s&&n<s||"function"==typeof s&&s(n,e);!r&&h?(n++,t.onFail?.(n,e),m(a).then((()=>{if(u())return l()})).then((()=>{r?c(e):d()}))):c(e)}))};return Q(t.networkMode)?d():l().then(d),{promise:a,cancel:e=>{o||(c(new S(e)),t.abort?.())},continue:()=>{const t=e?.();return t?a:Promise.resolve()},cancelRetry:()=>{r=!0},continueRetry:()=>{r=!1}}}const M=function(){let t=[],e=0,s=t=>{t()},i=t=>{t()};const r=i=>{e?t.push(i):v((()=>{s(i)}))},n=()=>{const e=t;t=[],e.length&&v((()=>{i((()=>{e.forEach((t=>{s(t)}))}))}))};return{batch:t=>{let s;e++;try{s=t()}finally{e--,e||n()}return s},batchCalls:t=>(...e)=>{r((()=>{t(...e)}))},schedule:r,setNotifyFunction:t=>{s=t},setBatchNotifyFunction:t=>{i=t}}}();class F{#r;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),r(this.gcTime)&&(this.#r=setTimeout((()=>{this.optionalRemove()}),this.gcTime))}updateGcTime(t){this.gcTime=Math.max(this.gcTime||0,t??(s?1/0:3e5))}clearGcTimeout(){this.#r&&(clearTimeout(this.#r),this.#r=void 0)}}class E extends F{#n;#o;#a;#u;#h;#c;#l;#d;constructor(t){super(),this.#d=!1,this.#l=t.defaultOptions,this.#f(t.options),this.#c=[],this.#a=t.cache,this.queryKey=t.queryKey,this.queryHash=t.queryHash,this.#n=t.state||function(t){const e="function"==typeof t.initialData?t.initialData():t.initialData,s=void 0!==e,i=s?"function"==typeof t.initialDataUpdatedAt?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"}}(this.options),this.state=this.#n,this.scheduleGc()}get meta(){return this.options.meta}#f(t){this.options={...this.#l,...t},this.updateGcTime(this.options.gcTime)}optionalRemove(){this.#c.length||"idle"!==this.state.fetchStatus||this.#a.remove(this)}setData(t,e){const s=b(this.state.data,t,this.options);return this.#p({data:s,type:"success",dataUpdatedAt:e?.updatedAt,manual:e?.manual}),s}setState(t,e){this.#p({type:"setState",state:t,setStateOptions:e})}cancel(t){const e=this.#u;return this.#h?.cancel(t),e?e.then(i).catch(i):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(this.#n)}isActive(){return this.#c.some((t=>!1!==t.options.enabled))}isDisabled(){return this.getObserversCount()>0&&!this.isActive()}isStale(){return this.state.isInvalidated||!this.state.dataUpdatedAt||this.#c.some((t=>t.getCurrentResult().isStale))}isStaleByTime(t=0){return this.state.isInvalidated||!this.state.dataUpdatedAt||!n(this.state.dataUpdatedAt,t)}onFocus(){this.#c.find((t=>t.shouldFetchOnWindowFocus()))?.refetch({cancelRefetch:!1}),this.#h?.continue()}onOnline(){this.#c.find((t=>t.shouldFetchOnReconnect()))?.refetch({cancelRefetch:!1}),this.#h?.continue()}addObserver(t){-1===this.#c.indexOf(t)&&(this.#c.push(t),this.clearGcTimeout(),this.#a.notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){-1!==this.#c.indexOf(t)&&(this.#c=this.#c.filter((e=>e!==t)),this.#c.length||(this.#h&&(this.#d?this.#h.cancel({revert:!0}):this.#h.cancelRetry()),this.scheduleGc()),this.#a.notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.#c.length}invalidate(){this.state.isInvalidated||this.#p({type:"invalidate"})}fetch(t,e){if("idle"!==this.state.fetchStatus)if(this.state.dataUpdatedAt&&e?.cancelRefetch)this.cancel({silent:!0});else if(this.#u)return this.#h?.continueRetry(),this.#u;if(t&&this.#f(t),!this.options.queryFn){const t=this.#c.find((t=>t.options.queryFn));t&&this.#f(t.options)}const s=new AbortController,i={queryKey:this.queryKey,meta:this.meta},r=t=>{Object.defineProperty(t,"signal",{enumerable:!0,get:()=>(this.#d=!0,s.signal)})};r(i);const n={fetchOptions:e,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:()=>this.options.queryFn?(this.#d=!1,this.options.queryFn(i)):Promise.reject(new Error("Missing queryFn"))};r(n),this.options.behavior?.onFetch(n),this.#o=this.state,"idle"!==this.state.fetchStatus&&this.state.fetchMeta===n.fetchOptions?.meta||this.#p({type:"fetch",meta:n.fetchOptions?.meta});const o=t=>{w(t)&&t.silent||this.#p({type:"error",error:t}),w(t)||(this.#a.config.onError?.(t,this),this.#a.config.onSettled?.(this.state.data,t,this)),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1};return this.#h=P({fn:n.fetchFn,abort:s.abort.bind(s),onSuccess:t=>{void 0!==t?(this.setData(t),this.#a.config.onSuccess?.(t,this),this.#a.config.onSettled?.(t,this.state.error,this),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1):o(new Error("undefined"))},onError:o,onFail:(t,e)=>{this.#p({type:"failed",failureCount:t,error:e})},onPause:()=>{this.#p({type:"pause"})},onContinue:()=>{this.#p({type:"continue"})},retry:n.options.retry,retryDelay:n.options.retryDelay,networkMode:n.options.networkMode}),this.#u=this.#h.promise,this.#u}#p(t){this.state=(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":return{...e,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:t.meta??null,fetchStatus:Q(this.options.networkMode)?"fetching":"paused",...!e.dataUpdatedAt&&{error:null,status:"pending"}};case"success":return{...e,data:t.data,dataUpdateCount:e.dataUpdateCount+1,dataUpdatedAt:t.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":const s=t.error;return w(s)&&s.revert&&this.#o?{...this.#o}:{...e,error:s,errorUpdateCount:e.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:e.fetchFailureCount+1,fetchFailureReason:s,fetchStatus:"idle",status:"error"};case"invalidate":return{...e,isInvalidated:!0};case"setState":return{...e,...t.state}}})(this.state),M.batch((()=>{this.#c.forEach((e=>{e.onQueryUpdate(t)})),this.#a.notify({query:this,type:"updated",action:t})}))}}class x extends e{#y;constructor(t={}){super(),this.config=t,this.#y=t.createStore?.()??new Map}build(t,e,s){const i=e.queryKey,r=e.queryHash??u(i,e);let n=this.get(r);return n||(n=new E({cache:this,queryKey:i,queryHash:r,options:t.defaultQueryOptions(e),state:s,defaultOptions:t.getQueryDefaults(i)}),this.add(n)),n}add(t){this.#y.has(t.queryHash)||(this.#y.set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const e=this.#y.get(t.queryHash);e&&(t.destroy(),e===t&&this.#y.delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){M.batch((()=>{this.getAll().forEach((t=>{this.remove(t)}))}))}get(t){return this.#y.get(t)}getAll(){return[...this.#y.values()]}find(t){return void 0===t.exact&&(t.exact=!0),this.getAll().find((e=>o(t,e)))}findAll(t={}){const e=this.getAll();return Object.keys(t).length>0?e.filter((e=>o(t,e))):e}notify(t){M.batch((()=>{this.listeners.forEach((e=>{e(t)}))}))}onFocus(){M.batch((()=>{this.getAll().forEach((t=>{t.onFocus()}))}))}onOnline(){M.batch((()=>{this.getAll().forEach((t=>{t.onOnline()}))}))}}class D extends F{#c;#l;#m;#h;constructor(t){super(),this.mutationId=t.mutationId,this.#l=t.defaultOptions,this.#m=t.mutationCache,this.#c=[],this.state=t.state||A(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options={...this.#l,...t},this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){-1===this.#c.indexOf(t)&&(this.#c.push(t),this.clearGcTimeout(),this.#m.notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){this.#c=this.#c.filter((e=>e!==t)),this.scheduleGc(),this.#m.notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){this.#c.length||("pending"===this.state.status?this.scheduleGc():this.#m.remove(this))}continue(){return this.#h?.continue()??this.execute(this.state.variables)}async execute(t){const e=()=>(this.#h=P({fn:()=>this.options.mutationFn?this.options.mutationFn(t):Promise.reject(new Error("No mutationFn found")),onFail:(t,e)=>{this.#p({type:"failed",failureCount:t,error:e})},onPause:()=>{this.#p({type:"pause"})},onContinue:()=>{this.#p({type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode}),this.#h.promise),s="pending"===this.state.status;try{if(!s){this.#p({type:"pending",variables:t}),await(this.#m.config.onMutate?.(t,this));const e=await(this.options.onMutate?.(t));e!==this.state.context&&this.#p({type:"pending",context:e,variables:t})}const i=await e();return await(this.#m.config.onSuccess?.(i,t,this.state.context,this)),await(this.options.onSuccess?.(i,t,this.state.context)),await(this.#m.config.onSettled?.(i,null,this.state.variables,this.state.context,this)),await(this.options.onSettled?.(i,null,t,this.state.context)),this.#p({type:"success",data:i}),i}catch(e){try{throw await(this.#m.config.onError?.(e,t,this.state.context,this)),await(this.options.onError?.(e,t,this.state.context)),await(this.#m.config.onSettled?.(void 0,e,this.state.variables,this.state.context,this)),await(this.options.onSettled?.(void 0,e,t,this.state.context)),e}finally{this.#p({type:"error",error:e})}}}#p(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:!Q(this.options.networkMode),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),M.batch((()=>{this.#c.forEach((e=>{e.onMutationUpdate(t)})),this.#m.notify({mutation:this,type:"updated",action:t})}))}}function A(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}class I extends e{#v;#b;#g;constructor(t={}){super(),this.config=t,this.#v=[],this.#b=0}build(t,e,s){const i=new D({mutationCache:this,mutationId:++this.#b,options:t.defaultMutationOptions(e),state:s});return this.add(i),i}add(t){this.#v.push(t),this.notify({type:"added",mutation:t})}remove(t){this.#v=this.#v.filter((e=>e!==t)),this.notify({type:"removed",mutation:t})}clear(){M.batch((()=>{this.#v.forEach((t=>{this.remove(t)}))}))}getAll(){return this.#v}find(t){return void 0===t.exact&&(t.exact=!0),this.#v.find((e=>a(t,e)))}findAll(t={}){return this.#v.filter((e=>a(t,e)))}notify(t){M.batch((()=>{this.listeners.forEach((e=>{e(t)}))}))}resumePausedMutations(){return this.#g=(this.#g??Promise.resolve()).then((()=>{const t=this.#v.filter((t=>t.state.isPaused));return M.batch((()=>t.reduce(((t,e)=>t.then((()=>e.continue().catch(i)))),Promise.resolve())))})).then((()=>{this.#g=void 0})),this.#g}}function U(){return{onFetch:t=>{t.fetchFn=()=>{const e=t.options,s=t.fetchOptions?.meta?.fetchMore?.direction,i=t.state.data?.pages||[],r=t.state.data?.pageParams||[];let n=r,o=!1;const a=t.options.queryFn||(()=>Promise.reject(new Error("Missing queryFn"))),u=(e,s,i)=>{if(o)return Promise.reject();if(void 0===s&&e.length)return Promise.resolve(e);const r={queryKey:t.queryKey,pageParam:s,meta:t.options.meta};var u;u=r,Object.defineProperty(u,"signal",{enumerable:!0,get:()=>(t.signal.aborted?o=!0:t.signal.addEventListener("abort",(()=>{o=!0})),t.signal)});const h=a(r),c=Promise.resolve(h).then((r=>((e,s,i,r)=>{const{maxPages:o}=t.options;return r?(n=O(n,s,o),O(e,i,o)):(n=g(n,s,o),g(e,i,o))})(e,s,r,i)));return c};let h;if(i.length)if(s){const t="backward"===s,r=t?K(e,i):T(e,i);h=u(i,r,t)}else{n=[],h=u([],r[0]);for(let t=1;t<i.length;t++)h=h.then((t=>{const s=T(e,t);return u(t,s)}))}else h=u([],e.defaultPageParam);return h.then((t=>({pages:t,pageParams:n})))}}}}function T(t,e){return t.getNextPageParam(e[e.length-1],e)}function K(t,e){return t.getPreviousPageParam?.(e[0],e)}function k(t,e){return!!e&&void 0!==T(t,e)}function L(t,e){return!(!e||!t.getPreviousPageParam)&&void 0!==K(t,e)}class j extends e{#O;#R=void 0;#C=void 0;#q=void 0;#Q;#S;#w;#P;#M;#F;#E;#x;#D;#A=new Set;constructor(t,e){super(),this.#O=t,this.options=e,this.#P=null,this.bindMethods(),this.setOptions(e)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){1===this.listeners.length&&(this.#R.addObserver(this),H(this.#R,this.options)&&this.#I(),this.#U())}onUnsubscribe(){this.listeners.length||this.destroy()}shouldFetchOnReconnect(){return G(this.#R,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return G(this.#R,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=[],this.#T(),this.#K(),this.#R.removeObserver(this)}setOptions(t,e){const s=this.options,i=this.#R;if(this.options=this.#O.defaultQueryOptions(t),d(s,this.options)||this.#O.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#R,observer:this}),void 0!==this.options.enabled&&"boolean"!=typeof this.options.enabled)throw new Error("Expected enabled to be a boolean");this.options.queryKey||(this.options.queryKey=s.queryKey),this.#k();const r=this.hasListeners();r&&N(this.#R,i,this.options,s)&&this.#I(),this.#L(e),!r||this.#R===i&&this.options.enabled===s.enabled&&this.options.staleTime===s.staleTime||this.#j();const n=this.#H();!r||this.#R===i&&this.options.enabled===s.enabled&&n===this.#D||this.#G(n)}getOptimisticResult(t){const e=this.#O.getQueryCache().build(this.#O,t);return this.createResult(e,t)}getCurrentResult(){return this.#q}trackResult(t){const e={};return Object.keys(t).forEach((s=>{Object.defineProperty(e,s,{configurable:!1,enumerable:!0,get:()=>(this.#A.add(s),t[s])})})),e}getCurrentQuery(){return this.#R}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const e=this.#O.defaultQueryOptions(t),s=this.#O.getQueryCache().build(this.#O,e);return s.isFetchingOptimistic=!0,s.fetch().then((()=>this.createResult(s,e)))}fetch(t){return this.#I({...t,cancelRefetch:t.cancelRefetch??!0}).then((()=>(this.#L(),this.#q)))}#I(t){this.#k();let e=this.#R.fetch(this.options,t);return t?.throwOnError||(e=e.catch(i)),e}#j(){if(this.#T(),s||this.#q.isStale||!r(this.options.staleTime))return;const t=n(this.#q.dataUpdatedAt,this.options.staleTime)+1;this.#E=setTimeout((()=>{this.#q.isStale||this.#L()}),t)}#H(){return"function"==typeof this.options.refetchInterval?this.options.refetchInterval(this.#q.data,this.#R):this.options.refetchInterval??!1}#G(t){this.#K(),this.#D=t,!s&&!1!==this.options.enabled&&r(this.#D)&&0!==this.#D&&(this.#x=setInterval((()=>{(this.options.refetchIntervalInBackground||R.isFocused())&&this.#I()}),this.#D))}#U(){this.#j(),this.#G(this.#H())}#T(){this.#E&&(clearTimeout(this.#E),this.#E=void 0)}#K(){this.#x&&(clearInterval(this.#x),this.#x=void 0)}createResult(t,e){const s=this.#R,i=this.options,r=this.#q,n=this.#Q,o=this.#S,a=t!==s,u=a?t.state:this.#C,h=a?this.#q:this.#w,{state:c}=t;let l,{error:d,errorUpdatedAt:f,fetchStatus:p,status:y}=c,m=!1;if(e._optimisticResults){const r=this.hasListeners(),n=!r&&H(t,e),o=r&&N(t,s,e,i);(n||o)&&(p=Q(t.options.networkMode)?"fetching":"paused",c.dataUpdatedAt||(y="pending")),"isRestoring"===e._optimisticResults&&(p="idle")}if(e.select&&void 0!==c.data)if(r&&c.data===n?.data&&e.select===this.#M)l=this.#F;else try{this.#M=e.select,l=e.select(c.data),l=b(r?.data,l,e),this.#F=l,this.#P=null}catch(t){this.#P=t}else l=c.data;if(void 0!==e.placeholderData&&void 0===l&&"pending"===y){let t;if(r?.isPlaceholderData&&e.placeholderData===o?.placeholderData)t=r.data;else if(t="function"==typeof e.placeholderData?e.placeholderData(h?.data):e.placeholderData,e.select&&void 0!==t)try{t=e.select(t),this.#P=null}catch(t){this.#P=t}void 0!==t&&(y="success",l=b(r?.data,t,e),m=!0)}this.#P&&(d=this.#P,l=this.#F,f=Date.now(),y="error");const v="fetching"===p,g="pending"===y,O="error"===y,R=g&&v;return{status:y,fetchStatus:p,isPending:g,isSuccess:"success"===y,isError:O,isInitialLoading:R,isLoading:R,data:l,dataUpdatedAt:c.dataUpdatedAt,error:d,errorUpdatedAt:f,failureCount:c.fetchFailureCount,failureReason:c.fetchFailureReason,errorUpdateCount:c.errorUpdateCount,isFetched:c.dataUpdateCount>0||c.errorUpdateCount>0,isFetchedAfterMount:c.dataUpdateCount>u.dataUpdateCount||c.errorUpdateCount>u.errorUpdateCount,isFetching:v,isRefetching:v&&!g,isLoadingError:O&&0===c.dataUpdatedAt,isPaused:"paused"===p,isPlaceholderData:m,isRefetchError:O&&0!==c.dataUpdatedAt,isStale:_(t,e),refetch:this.refetch}}#L(t){const e=this.#q,s=this.createResult(this.#R,this.options);if(this.#Q=this.#R.state,this.#S=this.options,d(s,e))return;this.#q=s;const i={};!1!==t?.listeners&&(()=>{if(!e)return!0;const{notifyOnChangeProps:t}=this.options;if("all"===t||!t&&!this.#A.size)return!0;const s=new Set(t??this.#A);return this.options.throwErrors&&s.add("error"),Object.keys(this.#q).some((t=>{const i=t;return this.#q[i]!==e[i]&&s.has(i)}))})()&&(i.listeners=!0),this.#N({...i,...t})}#k(){const t=this.#O.getQueryCache().build(this.#O,this.options);if(t===this.#R)return;const e=this.#R;this.#R=t,this.#C=t.state,this.#w=this.#q,this.hasListeners()&&(e?.removeObserver(this),t.addObserver(this))}onQueryUpdate(t){const e={};"success"===t.type?e.onSuccess=!t.manual:"error"!==t.type||w(t.error)||(e.onError=!0),this.#L(e),this.hasListeners()&&this.#U()}#N(t){M.batch((()=>{t.onSuccess?(this.options.onSuccess?.(this.#q.data),this.options.onSettled?.(this.#q.data,null)):t.onError&&(this.options.onError?.(this.#q.error),this.options.onSettled?.(void 0,this.#q.error)),t.listeners&&this.listeners.forEach((t=>{t(this.#q)})),this.#O.getQueryCache().notify({query:this.#R,type:"observerResultsUpdated"})}))}}function H(t,e){return function(t,e){return!(!1===e.enabled||t.state.dataUpdatedAt||"error"===t.state.status&&!1===e.retryOnMount)}(t,e)||t.state.dataUpdatedAt>0&&G(t,e,e.refetchOnMount)}function G(t,e,s){if(!1!==e.enabled){const i="function"==typeof s?s(t):s;return"always"===i||!1!==i&&_(t,e)}return!1}function N(t,e,s,i){return!1!==s.enabled&&(t!==e||!1===i.enabled)&&(!s.suspense||"error"!==t.state.status)&&_(t,s)}function _(t,e){return t.isStaleByTime(e.staleTime)}function B(t,e){return t.filter((t=>-1===e.indexOf(t)))}function W(t){return t.state.isPaused}function z(t){return"success"===t.state.status}t.CancelledError=S,t.InfiniteQueryObserver=class extends j{constructor(t,e){super(t,e)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(t,e){super.setOptions({...t,behavior:U()},e)}getOptimisticResult(t){return t.behavior=U(),super.getOptimisticResult(t)}fetchNextPage(t={}){return this.fetch({...t,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage({...t}={}){return this.fetch({...t,meta:{fetchMore:{direction:"backward"}}})}createResult(t,e){const{state:s}=t,i=super.createResult(t,e),{isFetching:r,isRefetching:n}=i,o=r&&"forward"===s.fetchMeta?.fetchMore?.direction,a=r&&"backward"===s.fetchMeta?.fetchMore?.direction;return{...i,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:k(e,s.data?.pages),hasPreviousPage:L(e,s.data?.pages),isFetchingNextPage:o,isFetchingPreviousPage:a,isRefetching:n&&!o&&!a}}},t.MutationCache=I,t.MutationObserver=class extends e{#O;#q=void 0;#_;#B;constructor(t,e){super(),this.#O=t,this.setOptions(e),this.bindMethods(),this.#L()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){const e=this.options;this.options=this.#O.defaultMutationOptions(t),d(e,this.options)||this.#O.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#_,observer:this}),this.#_?.setOptions(this.options)}onUnsubscribe(){this.listeners.length||this.#_?.removeObserver(this)}onMutationUpdate(t){this.#L(),this.#N(t)}getCurrentResult(){return this.#q}reset(){this.#_=void 0,this.#L(),this.#N()}mutate(t,e){return this.#B=e,this.#_?.removeObserver(this),this.#_=this.#O.getMutationCache().build(this.#O,this.options),this.#_.addObserver(this),this.#_.execute(t)}#L(){const t=this.#_?.state??{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0};this.#q={...t,isPending:"pending"===t.status,isSuccess:"success"===t.status,isError:"error"===t.status,isIdle:"idle"===t.status,mutate:this.mutate,reset:this.reset}}#N(t){M.batch((()=>{this.#B&&this.hasListeners()&&("success"===t?.type?(this.#B.onSuccess?.(t.data,this.#q.variables,this.#q.context),this.#B.onSettled?.(t.data,null,this.#q.variables,this.#q.context)):"error"===t?.type&&(this.#B.onError?.(t.error,this.#q.variables,this.#q.context),this.#B.onSettled?.(void 0,t.error,this.#q.variables,this.#q.context))),this.listeners.forEach((t=>{t(this.#q)}))}))}},t.QueriesObserver=class extends e{#O;#W;#y;#c;constructor(t,e){super(),this.#O=t,this.#y=[],this.#W=[],this.#c=[],e&&this.setQueries(e)}onSubscribe(){1===this.listeners.length&&this.#c.forEach((t=>{t.subscribe((e=>{this.#z(t,e)}))}))}onUnsubscribe(){this.listeners.length||this.destroy()}destroy(){this.listeners=[],this.#c.forEach((t=>{t.destroy()}))}setQueries(t,e){this.#y=t,M.batch((()=>{const t=this.#c,s=this.#J(this.#y);s.forEach((t=>t.observer.setOptions(t.defaultedQueryOptions,e)));const i=s.map((t=>t.observer)),r=i.map((t=>t.getCurrentResult())),n=i.some(((e,s)=>e!==t[s]));(t.length!==i.length||n)&&(this.#c=i,this.#W=r,this.hasListeners()&&(B(t,i).forEach((t=>{t.destroy()})),B(i,t).forEach((t=>{t.subscribe((e=>{this.#z(t,e)}))})),this.#N()))}))}getCurrentResult(){return this.#W}getQueries(){return this.#c.map((t=>t.getCurrentQuery()))}getObservers(){return this.#c}getOptimisticResult(t){return this.#J(t).map((t=>t.observer.getOptimisticResult(t.defaultedQueryOptions)))}#J(t){const e=this.#c,s=t.map((t=>this.#O.defaultQueryOptions(t))),i=s.flatMap((t=>{const s=e.find((e=>e.options.queryHash===t.queryHash));return null!=s?[{defaultedQueryOptions:t,observer:s}]:[]})),r=i.map((t=>t.defaultedQueryOptions.queryHash)),n=s.filter((t=>!r.includes(t.queryHash))),o=t=>{const e=this.#O.defaultQueryOptions(t);return this.#c.find((t=>t.options.queryHash===e.queryHash))??new j(this.#O,e)},a=n.map((t=>({defaultedQueryOptions:t,observer:o(t)})));return i.concat(a).sort(((t,e)=>s.indexOf(t.defaultedQueryOptions)-s.indexOf(e.defaultedQueryOptions)))}#z(t,e){const s=this.#c.indexOf(t);-1!==s&&(this.#W=function(t,e,s){const i=t.slice(0);return i[e]=s,i}(this.#W,s,e),this.#N())}#N(){M.batch((()=>{this.listeners.forEach((t=>{t(this.#W)}))}))}},t.QueryCache=x,t.QueryClient=class{#V;#m;#l;#X;#Y;#Z;#$;#tt;constructor(t={}){this.#V=t.queryCache||new x,this.#m=t.mutationCache||new I,this.#l=t.defaultOptions||{},this.#X=new Map,this.#Y=new Map,this.#Z=0}mount(){this.#Z++,1===this.#Z&&(this.#$=R.subscribe((()=>{R.isFocused()&&(this.resumePausedMutations(),this.#V.onFocus())})),this.#tt=C.subscribe((()=>{C.isOnline()&&(this.resumePausedMutations(),this.#V.onOnline())})))}unmount(){this.#Z--,0===this.#Z&&(this.#$?.(),this.#$=void 0,this.#tt?.(),this.#tt=void 0)}isFetching(t){return this.#V.findAll({...t,fetchStatus:"fetching"}).length}isMutating(t){return this.#m.findAll({...t,status:"pending"}).length}getQueryData(t){return this.#V.find({queryKey:t})?.state.data}ensureQueryData(t){const e=this.getQueryData(t.queryKey);return e?Promise.resolve(e):this.fetchQuery(t)}getQueriesData(t){return this.getQueryCache().findAll(t).map((({queryKey:t,state:e})=>[t,e.data]))}setQueryData(t,e,s){const i=this.#V.find({queryKey:t})?.state.data,r=function(t,e){return"function"==typeof t?t(e):t}(e,i);if(void 0===r)return;const n=this.defaultQueryOptions({queryKey:t});return this.#V.build(this,n).setData(r,{...s,manual:!0})}setQueriesData(t,e,s){return M.batch((()=>this.getQueryCache().findAll(t).map((({queryKey:t})=>[t,this.setQueryData(t,e,s)]))))}getQueryState(t){return this.#V.find({queryKey:t})?.state}removeQueries(t){const e=this.#V;M.batch((()=>{e.findAll(t).forEach((t=>{e.remove(t)}))}))}resetQueries(t,e){const s=this.#V,i={type:"active",...t};return M.batch((()=>(s.findAll(t).forEach((t=>{t.reset()})),this.refetchQueries(i,e))))}cancelQueries(t={},e={}){void 0===e.revert&&(e.revert=!0);const s=M.batch((()=>this.#V.findAll(t).map((t=>t.cancel(e)))));return Promise.all(s).then(i).catch(i)}invalidateQueries(t={},e={}){return M.batch((()=>{if(this.#V.findAll(t).forEach((t=>{t.invalidate()})),"none"===t.refetchType)return Promise.resolve();const s={...t,type:t.refetchType??t.type??"active"};return this.refetchQueries(s,e)}))}refetchQueries(t={},e){const s=M.batch((()=>this.#V.findAll(t).filter((t=>!t.isDisabled())).map((t=>t.fetch(void 0,{...e,cancelRefetch:e?.cancelRefetch??!0})))));let r=Promise.all(s).then(i);return e?.throwOnError||(r=r.catch(i)),r}fetchQuery(t){const e=this.defaultQueryOptions(t);void 0===e.retry&&(e.retry=!1);const s=this.#V.build(this,e);return s.isStaleByTime(e.staleTime)?s.fetch(e):Promise.resolve(s.state.data)}prefetchQuery(t){return this.fetchQuery(t).then(i).catch(i)}fetchInfiniteQuery(t){return t.behavior=U(),this.fetchQuery(t)}prefetchInfiniteQuery(t){return this.fetchInfiniteQuery(t).then(i).catch(i)}resumePausedMutations(){return this.#m.resumePausedMutations()}getQueryCache(){return this.#V}getMutationCache(){return this.#m}getDefaultOptions(){return this.#l}setDefaultOptions(t){this.#l=t}setQueryDefaults(t,e){this.#X.set(h(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){const e=[...this.#X.values()];let s={};return e.forEach((e=>{c(t,e.queryKey)&&(s={...s,...e.defaultOptions})})),s}setMutationDefaults(t,e){this.#Y.set(h(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){const e=[...this.#Y.values()];let s={};return e.forEach((e=>{c(t,e.mutationKey)&&(s={...s,...e.defaultOptions})})),s}defaultQueryOptions(t){if(t?._defaulted)return t;const e={...this.#l.queries,...t?.queryKey&&this.getQueryDefaults(t.queryKey),...t,_defaulted:!0};return e.queryHash||(e.queryHash=u(e.queryKey,e)),void 0===e.refetchOnReconnect&&(e.refetchOnReconnect="always"!==e.networkMode),void 0===e.throwErrors&&(e.throwErrors=!!e.suspense),e}defaultMutationOptions(t){return t?._defaulted?t:{...this.#l.mutations,...t?.mutationKey&&this.getMutationDefaults(t.mutationKey),...t,_defaulted:!0}}clear(){this.#V.clear(),this.#m.clear()}},t.QueryObserver=j,t.defaultShouldDehydrateMutation=W,t.defaultShouldDehydrateQuery=z,t.dehydrate=function(t,e={}){const s=[],i=[];if(!1!==e.dehydrateMutations){const i=e.shouldDehydrateMutation||W;t.getMutationCache().getAll().forEach((t=>{i(t)&&s.push(function(t){return{mutationKey:t.options.mutationKey,state:t.state}}(t))}))}if(!1!==e.dehydrateQueries){const s=e.shouldDehydrateQuery||z;t.getQueryCache().getAll().forEach((t=>{s(t)&&i.push(function(t){return{state:t.state,queryKey:t.queryKey,queryHash:t.queryHash}}(t))}))}return{mutations:s,queries:i}},t.focusManager=R,t.hashKey=h,t.hydrate=function(t,e,s){if("object"!=typeof e||null===e)return;const i=t.getMutationCache(),r=t.getQueryCache(),n=e.mutations||[],o=e.queries||[];n.forEach((e=>{i.build(t,{...s?.defaultOptions?.mutations,mutationKey:e.mutationKey},e.state)})),o.forEach((e=>{const i=r.get(e.queryHash),n={...e.state,fetchStatus:"idle"};i?i.state.dataUpdatedAt<n.dataUpdatedAt&&i.setState(n):r.build(t,{...s?.defaultOptions?.queries,queryKey:e.queryKey,queryHash:e.queryHash},n)}))},t.isCancelledError=w,t.isServer=s,t.keepPreviousData=function(t){return t},t.matchQuery=o,t.notifyManager=M,t.onlineManager=C,t.replaceEqualDeep=l}));
//# sourceMappingURL=index.production.js.map
{
"name": "@tanstack/query-core",
"version": "5.0.0-alpha.2",
"version": "5.0.0-alpha.3",
"description": "The framework agnostic core that powers TanStack Query",

@@ -5,0 +5,0 @@ "author": "tannerlinsley",

@@ -88,6 +88,7 @@ import type {

state: MutationState<TData, TError, TVariables, TContext>
readonly options: MutationOptions<TData, TError, TVariables, TContext>
options!: MutationOptions<TData, TError, TVariables, TContext>
readonly mutationId: number
#observers: MutationObserver<TData, TError, TVariables, TContext>[]
#defaultOptions?: MutationOptions<TData, TError, TVariables, TContext>
#mutationCache: MutationCache

@@ -99,4 +100,4 @@ #retryer?: Retryer<TData>

this.options = config.options
this.mutationId = config.mutationId
this.#defaultOptions = config.defaultOptions
this.#mutationCache = config.mutationCache

@@ -106,6 +107,14 @@ this.#observers = []

this.updateGcTime(this.options.gcTime)
this.setOptions(config.options)
this.scheduleGc()
}
setOptions(
options?: MutationOptions<TData, TError, TVariables, TContext>,
): void {
this.options = { ...this.#defaultOptions, ...options }
this.updateGcTime(this.options.gcTime)
}
get meta(): MutationMeta | undefined {

@@ -234,3 +243,3 @@ return this.options.meta

await this.#mutationCache.config.onError?.(
error,
error as any,
variables,

@@ -250,3 +259,3 @@ this.state.context,

undefined,
error,
error as any,
this.state.variables,

@@ -253,0 +262,0 @@ this.state.context,

@@ -15,3 +15,3 @@ import type { MutationObserver } from './mutationObserver'

onError?: (
error: unknown,
error: DefaultError,
variables: unknown,

@@ -33,3 +33,3 @@ context: unknown,

data: unknown | undefined,
error: unknown | null,
error: DefaultError | null,
variables: unknown,

@@ -36,0 +36,0 @@ context: unknown,

@@ -67,2 +67,3 @@ import type { Action, Mutation } from './mutation'

}
this.#currentMutation?.setOptions(this.options)
}

@@ -69,0 +70,0 @@

@@ -436,6 +436,9 @@ import { noop, replaceData, timeUntilStale } from './utils'

// Notify cache callback
this.#cache.config.onError?.(error, this as Query<any, any, any, any>)
this.#cache.config.onError?.(
error as any,
this as Query<any, any, any, any>,
)
this.#cache.config.onSettled?.(
this.state.data,
error,
error as any,
this as Query<any, any, any, any>,

@@ -473,3 +476,3 @@ )

data,
this.state.error,
this.state.error as any,
this as Query<any, any, any, any>,

@@ -476,0 +479,0 @@ )

@@ -20,7 +20,10 @@ import type { QueryFilters } from './utils'

interface QueryCacheConfig {
onError?: (error: unknown, query: Query<unknown, unknown, unknown>) => void
onError?: (
error: DefaultError,
query: Query<unknown, unknown, unknown>,
) => void
onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void
onSettled?: (
data: unknown | undefined,
error: unknown | null,
error: DefaultError | null,
query: Query<unknown, unknown, unknown>,

@@ -27,0 +30,0 @@ ) => void

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc