@tanstack/query-core
Advanced tools
Comparing version 5.0.0-alpha.23 to 5.0.0-alpha.24
@@ -15,1 +15,2 @@ import { Subscribable } from './subscribable'; | ||
export {}; | ||
//# sourceMappingURL=focusManager.d.ts.map |
@@ -33,1 +33,2 @@ import type { QueryClient } from './queryClient'; | ||
export {}; | ||
//# sourceMappingURL=hydration.d.ts.map |
@@ -20,1 +20,2 @@ export { CancelledError } from './retryer'; | ||
export type { DehydrateOptions, DehydratedState, HydrateOptions, } from './hydration'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -12,1 +12,2 @@ import type { QueryBehavior } from './query'; | ||
export declare function hasPreviousPage(options: InfiniteQueryPageParamsOptions<any, any>, data?: InfiniteData<unknown>): boolean; | ||
//# sourceMappingURL=infiniteQueryBehavior.d.ts.map |
@@ -20,1 +20,2 @@ import type { DefaultedInfiniteQueryObserverOptions, FetchNextPageOptions, FetchPreviousPageOptions, InfiniteData, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, QueryKey, DefaultError } from './types'; | ||
export {}; | ||
//# sourceMappingURL=infiniteQueryObserver.d.ts.map |
@@ -64,1 +64,2 @@ import type { MutationOptions, MutationStatus, MutationMeta, DefaultError } from './types'; | ||
export {}; | ||
//# sourceMappingURL=mutation.d.ts.map |
@@ -59,1 +59,2 @@ import type { MutationObserver } from './mutationObserver'; | ||
export {}; | ||
//# sourceMappingURL=mutationCache.d.ts.map |
@@ -19,1 +19,2 @@ import type { Action } from './mutation'; | ||
export {}; | ||
//# sourceMappingURL=mutationObserver.d.ts.map |
@@ -19,1 +19,2 @@ declare type NotifyCallback = () => void; | ||
export {}; | ||
//# sourceMappingURL=notifyManager.d.ts.map |
@@ -15,1 +15,2 @@ import { Subscribable } from './subscribable'; | ||
export {}; | ||
//# sourceMappingURL=onlineManager.d.ts.map |
@@ -20,1 +20,2 @@ import type { QueryObserverOptions, QueryObserverResult } from './types'; | ||
export {}; | ||
//# sourceMappingURL=queriesObserver.d.ts.map |
@@ -115,1 +115,2 @@ import type { QueryKey, QueryOptions, QueryStatus, QueryMeta, CancelOptions, SetDataOptions, FetchStatus, DefaultError } from './types'; | ||
export {}; | ||
//# sourceMappingURL=query.d.ts.map |
@@ -313,3 +313,3 @@ import { classPrivateFieldLooseBase as _classPrivateFieldLooseBase, classPrivateFieldLooseKey as _classPrivateFieldLooseKey } from './_virtual/_rollupPluginBabelHelpers.esm.js'; | ||
} | ||
onError(new Error('undefined')); | ||
onError(new Error(`${this.queryHash} data is undefined`)); | ||
return; | ||
@@ -316,0 +316,0 @@ } |
@@ -315,3 +315,3 @@ 'use strict'; | ||
} | ||
onError(new Error('undefined')); | ||
onError(new Error(`${this.queryHash} data is undefined`)); | ||
return; | ||
@@ -318,0 +318,0 @@ } |
@@ -72,1 +72,2 @@ import type { QueryFilters } from './utils'; | ||
export {}; | ||
//# sourceMappingURL=queryCache.d.ts.map |
@@ -42,1 +42,2 @@ import type { QueryFilters, Updater, MutationFilters } from './utils'; | ||
} | ||
//# sourceMappingURL=queryClient.d.ts.map |
@@ -35,1 +35,2 @@ import type { DefaultedQueryObserverOptions, DefaultError } from './types'; | ||
export {}; | ||
//# sourceMappingURL=queryObserver.d.ts.map |
@@ -10,1 +10,2 @@ export declare abstract class Removable { | ||
} | ||
//# sourceMappingURL=removable.d.ts.map |
@@ -34,1 +34,2 @@ import type { CancelOptions, NetworkMode, DefaultError } from './types'; | ||
export {}; | ||
//# sourceMappingURL=retryer.d.ts.map |
@@ -11,1 +11,2 @@ declare type Listener = () => void; | ||
export {}; | ||
//# sourceMappingURL=subscribable.d.ts.map |
export {}; | ||
//# sourceMappingURL=focusManager.test.d.ts.map |
export {}; | ||
//# sourceMappingURL=hydration.test.d.ts.map |
export {}; | ||
//# sourceMappingURL=infiniteQueryBehavior.test.d.ts.map |
export {}; | ||
//# sourceMappingURL=infiniteQueryObserver.test.d.ts.map |
export {}; | ||
//# sourceMappingURL=mutationCache.test.d.ts.map |
export {}; | ||
//# sourceMappingURL=mutationObserver.test.d.ts.map |
export {}; | ||
//# sourceMappingURL=mutations.test.d.ts.map |
export {}; | ||
//# sourceMappingURL=notifyManager.test.d.ts.map |
export {}; | ||
//# sourceMappingURL=onlineManager.test.d.ts.map |
export {}; | ||
//# sourceMappingURL=queriesObserver.test.d.ts.map |
export {}; | ||
//# sourceMappingURL=query.test.d.ts.map |
export {}; | ||
//# sourceMappingURL=queryCache.test.d.ts.map |
import '@testing-library/jest-dom'; | ||
//# sourceMappingURL=queryClient.test.d.ts.map |
export {}; | ||
//# sourceMappingURL=queryObserver.test.d.ts.map |
@@ -16,1 +16,2 @@ /// <reference types="node" /> | ||
export declare function setIsServer(isServer: boolean): () => void; | ||
//# sourceMappingURL=utils.d.ts.map |
export {}; | ||
//# sourceMappingURL=utils.test.d.ts.map |
@@ -432,1 +432,2 @@ import type { MutationState } from './mutation'; | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -90,1 +90,2 @@ import type { Mutation } from './mutation'; | ||
export declare function addToStart<T>(items: T[], item: T, max?: number): T[]; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -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 b(t){m(0).then(t)}function v(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 w(t){return"online"!==(t??"online")||C.isOnline()}class Q{constructor(t){this.revert=t?.revert,this.silent=t?.silent}}function S(t){return t instanceof Q}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 w(t.networkMode)?d():l().then(d),{promise:o,cancel:e=>{a||(c(new Q(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):b((()=>{s(i)}))},n=()=>{const e=t;t=[],e.length&&b((()=>{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=v(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=>{S(t)&&t.silent||this.#p({type:"error",error:t}),S(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:w(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 S(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((t=>{t.onQueryUpdate()})),this.#o.notify({query:this,type:"updated",action:t})}))}}class D 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){const e={exact:!0,...t};return this.getAll().find((t=>a(e,t)))}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 x 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:!w(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{#b;#v;#g;constructor(t={}){super(),this.config=t,this.#b=[],this.#v=0}build(t,e,s){const i=new x({mutationCache:this,mutationId:++this.#v,options:t.defaultMutationOptions(e),state:s});return this.add(i),i}add(t){this.#b.push(t),this.notify({type:"added",mutation:t})}remove(t){this.#b=this.#b.filter((e=>e!==t)),this.notify({type:"removed",mutation:t})}clear(){M.batch((()=>{this.#b.forEach((t=>{this.remove(t)}))}))}getAll(){return this.#b}find(t){const e={exact:!0,...t};return this.#b.find((t=>o(e,t)))}findAll(t={}){return this.#b.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.#b.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=async()=>{const e=t.options,s=t.fetchOptions?.meta?.fetchMore?.direction,i=t.state.data?.pages||[],r=t.state.data?.pageParams||[],n={pages:[],pageParams:[]};let a=!1;const o=t.options.queryFn||(()=>Promise.reject(new Error("Missing queryFn"))),u=async(e,s,i)=>{if(a)return Promise.reject();if(void 0===s&&e.pages.length)return Promise.resolve(e);const r={queryKey:t.queryKey,pageParam:s,direction:i?"backward":"forward",meta:t.options.meta};var n;n=r,Object.defineProperty(n,"signal",{enumerable:!0,get:()=>(t.signal.aborted?a=!0:t.signal.addEventListener("abort",(()=>{a=!0})),t.signal)});const u=await o(r),{maxPages:h}=t.options,c=i?O:g;return{pages:c(e.pages,u,h),pageParams:c(e.pageParams,s,h)}};let h;if(i.length)if(s){const t="backward"===s,n={pages:i,pageParams:r},a=(t?K:T)(e,n);h=await u(n,a,t)}else{h=await u(n,r[0]);for(let t=1;t<i.length;t++){const t=T(e,h);h=await u(h,t)}}else h=await u(n,e.defaultPageParam);return h}}}}function T(t,{pages:e,pageParams:s}){const i=e.length-1;return t.getNextPageParam(e[i],e,s[i],s)}function K(t,{pages:e,pageParams:s}){return t.getPreviousPageParam?.(e[0],e,s[0],s)}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;#w;#Q;#S;#P;#M;#F;#E;#D;#x;#A=new Set;constructor(t,e){super(),this.#O=t,this.options=e,this.#S=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.#x||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.#x=t,!s&&!1!==this.options.enabled&&r(this.#x)&&0!==this.#x&&(this.#D=setInterval((()=>{(this.options.refetchIntervalInBackground||R.isFocused())&&this.#I()}),this.#x))}#U(){this.#j(),this.#G(this.#H())}#T(){this.#E&&(clearTimeout(this.#E),this.#E=void 0)}#K(){this.#D&&(clearInterval(this.#D),this.#D=void 0)}createResult(t,e){const s=this.#R,i=this.options,r=this.#q,n=this.#w,a=this.#Q,o=t!==s?t.state:this.#C,{state:u}=t;let h,{error:c,errorUpdatedAt:l,fetchStatus:d,status:f}=u,p=!1;if(e._optimisticResults){const r=this.hasListeners(),n=!r&&H(t,e),a=r&&N(t,s,e,i);(n||a)&&(d=w(t.options.networkMode)?"fetching":"paused",u.dataUpdatedAt||(f="pending")),"isRestoring"===e._optimisticResults&&(d="idle")}if(e.select&&void 0!==u.data)if(r&&u.data===n?.data&&e.select===this.#P)h=this.#M;else try{this.#P=e.select,h=e.select(u.data),h=v(r?.data,h,e),this.#M=h,this.#S=null}catch(t){this.#S=t}else h=u.data;if(void 0!==e.placeholderData&&void 0===h&&"pending"===f){let t;if(r?.isPlaceholderData&&e.placeholderData===a?.placeholderData)t=r.data;else if(t="function"==typeof e.placeholderData?e.placeholderData(this.#F):e.placeholderData,e.select&&void 0!==t)try{t=e.select(t),this.#S=null}catch(t){this.#S=t}void 0!==t&&(f="success",h=v(r?.data,t,e),p=!0)}this.#S&&(c=this.#S,h=this.#M,l=Date.now(),f="error");const y="fetching"===d,m="pending"===f,b="error"===f,g=m&&y;return{status:f,fetchStatus:d,isPending:m,isSuccess:"success"===f,isError:b,isInitialLoading:g,isLoading:g,data:h,dataUpdatedAt:u.dataUpdatedAt,error:c,errorUpdatedAt:l,failureCount:u.fetchFailureCount,failureReason:u.fetchFailureReason,errorUpdateCount:u.errorUpdateCount,isFetched:u.dataUpdateCount>0||u.errorUpdateCount>0,isFetchedAfterMount:u.dataUpdateCount>o.dataUpdateCount||u.errorUpdateCount>o.errorUpdateCount,isFetching:y,isRefetching:y&&!m,isLoadingError:b&&0===u.dataUpdatedAt,isPaused:"paused"===d,isPlaceholderData:p,isRefetchError:b&&0!==u.dataUpdatedAt,isStale:_(t,e),refetch:this.refetch}}#L(t){const e=this.#q,s=this.createResult(this.#R,this.options);if(this.#w=this.#R.state,this.#Q=this.options,d(s,e))return;void 0!==this.#w.data&&(this.#F=this.#w.data),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.throwOnError&&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.hasListeners()&&(e?.removeObserver(this),t.addObserver(this))}onQueryUpdate(){this.#L(),this.hasListeners()&&this.#U()}#N(t){M.batch((()=>{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{mutationKey:t.options.mutationKey,state:t.state}}function z(t){return{state:t.state,queryKey:t.queryKey,queryHash:t.queryHash}}function J(t){return t.state.isPaused}function V(t){return"success"===t.state.status}t.CancelledError=Q,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),hasPreviousPage:L(e,s.data),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}),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=new Map(e.map((t=>[t.options.queryHash,t]))),i=t.map((t=>this.#O.defaultQueryOptions(t))),r=i.flatMap((t=>{const e=s.get(t.queryHash);return null!=e?[{defaultedQueryOptions:t,observer:e}]:[]})),n=new Set(r.map((t=>t.defaultedQueryOptions.queryHash))),a=i.filter((t=>!n.has(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)},u=a.map((t=>({defaultedQueryOptions:t,observer:o(t)})));return r.concat(u).sort(((t,e)=>i.indexOf(t.defaultedQueryOptions)-i.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=D,t.QueryClient=class{#V;#m;#l;#X;#Y;#Z;#$;#tt;constructor(t={}){this.#V=t.queryCache||new D,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={}){const s={revert:!0,...e},r=M.batch((()=>this.#V.findAll(t).map((t=>t.cancel(s)))));return Promise.all(r).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.throwOnError&&(e.throwOnError=!!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=J,t.defaultShouldDehydrateQuery=V,t.dehydrate=function(t,e={}){const s=e.shouldDehydrateMutation??J,i=t.getMutationCache().getAll().flatMap((t=>s(t)?[W(t)]:[])),r=e.shouldDehydrateQuery??V;return{mutations:i,queries:t.getQueryCache().getAll().flatMap((t=>r(t)?[z(t)]:[]))}},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=S,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 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 b(t){m(0).then(t)}function v(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 w(t){return"online"!==(t??"online")||C.isOnline()}class Q{constructor(t){this.revert=t?.revert,this.silent=t?.silent}}function S(t){return t instanceof Q}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 w(t.networkMode)?d():l().then(d),{promise:o,cancel:e=>{a||(c(new Q(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):b((()=>{s(i)}))},n=()=>{const e=t;t=[],e.length&&b((()=>{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=v(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=>{S(t)&&t.silent||this.#p({type:"error",error:t}),S(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(`${this.queryHash} data is 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:w(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 S(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((t=>{t.onQueryUpdate()})),this.#o.notify({query:this,type:"updated",action:t})}))}}class D 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){const e={exact:!0,...t};return this.getAll().find((t=>a(e,t)))}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 x 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:!w(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{#b;#v;#g;constructor(t={}){super(),this.config=t,this.#b=[],this.#v=0}build(t,e,s){const i=new x({mutationCache:this,mutationId:++this.#v,options:t.defaultMutationOptions(e),state:s});return this.add(i),i}add(t){this.#b.push(t),this.notify({type:"added",mutation:t})}remove(t){this.#b=this.#b.filter((e=>e!==t)),this.notify({type:"removed",mutation:t})}clear(){M.batch((()=>{this.#b.forEach((t=>{this.remove(t)}))}))}getAll(){return this.#b}find(t){const e={exact:!0,...t};return this.#b.find((t=>o(e,t)))}findAll(t={}){return this.#b.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.#b.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=async()=>{const e=t.options,s=t.fetchOptions?.meta?.fetchMore?.direction,i=t.state.data?.pages||[],r=t.state.data?.pageParams||[],n={pages:[],pageParams:[]};let a=!1;const o=t.options.queryFn||(()=>Promise.reject(new Error("Missing queryFn"))),u=async(e,s,i)=>{if(a)return Promise.reject();if(void 0===s&&e.pages.length)return Promise.resolve(e);const r={queryKey:t.queryKey,pageParam:s,direction:i?"backward":"forward",meta:t.options.meta};var n;n=r,Object.defineProperty(n,"signal",{enumerable:!0,get:()=>(t.signal.aborted?a=!0:t.signal.addEventListener("abort",(()=>{a=!0})),t.signal)});const u=await o(r),{maxPages:h}=t.options,c=i?O:g;return{pages:c(e.pages,u,h),pageParams:c(e.pageParams,s,h)}};let h;if(i.length)if(s){const t="backward"===s,n={pages:i,pageParams:r},a=(t?K:T)(e,n);h=await u(n,a,t)}else{h=await u(n,r[0]);for(let t=1;t<i.length;t++){const t=T(e,h);h=await u(h,t)}}else h=await u(n,e.defaultPageParam);return h}}}}function T(t,{pages:e,pageParams:s}){const i=e.length-1;return t.getNextPageParam(e[i],e,s[i],s)}function K(t,{pages:e,pageParams:s}){return t.getPreviousPageParam?.(e[0],e,s[0],s)}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 H extends e{#O;#R=void 0;#C=void 0;#q=void 0;#w;#Q;#S;#P;#M;#F;#E;#D;#x;#A=new Set;constructor(t,e){super(),this.#O=t,this.options=e,this.#S=null,this.bindMethods(),this.setOptions(e)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){1===this.listeners.length&&(this.#R.addObserver(this),j(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.#H();const n=this.#j();!r||this.#R===i&&this.options.enabled===s.enabled&&n===this.#x||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}#H(){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)}#j(){return("function"==typeof this.options.refetchInterval?this.options.refetchInterval(this.#q.data,this.#R):this.options.refetchInterval)??!1}#G(t){this.#K(),this.#x=t,!s&&!1!==this.options.enabled&&r(this.#x)&&0!==this.#x&&(this.#D=setInterval((()=>{(this.options.refetchIntervalInBackground||R.isFocused())&&this.#I()}),this.#x))}#U(){this.#H(),this.#G(this.#j())}#T(){this.#E&&(clearTimeout(this.#E),this.#E=void 0)}#K(){this.#D&&(clearInterval(this.#D),this.#D=void 0)}createResult(t,e){const s=this.#R,i=this.options,r=this.#q,n=this.#w,a=this.#Q,o=t!==s?t.state:this.#C,{state:u}=t;let h,{error:c,errorUpdatedAt:l,fetchStatus:d,status:f}=u,p=!1;if(e._optimisticResults){const r=this.hasListeners(),n=!r&&j(t,e),a=r&&N(t,s,e,i);(n||a)&&(d=w(t.options.networkMode)?"fetching":"paused",u.dataUpdatedAt||(f="pending")),"isRestoring"===e._optimisticResults&&(d="idle")}if(e.select&&void 0!==u.data)if(r&&u.data===n?.data&&e.select===this.#P)h=this.#M;else try{this.#P=e.select,h=e.select(u.data),h=v(r?.data,h,e),this.#M=h,this.#S=null}catch(t){this.#S=t}else h=u.data;if(void 0!==e.placeholderData&&void 0===h&&"pending"===f){let t;if(r?.isPlaceholderData&&e.placeholderData===a?.placeholderData)t=r.data;else if(t="function"==typeof e.placeholderData?e.placeholderData(this.#F):e.placeholderData,e.select&&void 0!==t)try{t=e.select(t),this.#S=null}catch(t){this.#S=t}void 0!==t&&(f="success",h=v(r?.data,t,e),p=!0)}this.#S&&(c=this.#S,h=this.#M,l=Date.now(),f="error");const y="fetching"===d,m="pending"===f,b="error"===f,g=m&&y;return{status:f,fetchStatus:d,isPending:m,isSuccess:"success"===f,isError:b,isInitialLoading:g,isLoading:g,data:h,dataUpdatedAt:u.dataUpdatedAt,error:c,errorUpdatedAt:l,failureCount:u.fetchFailureCount,failureReason:u.fetchFailureReason,errorUpdateCount:u.errorUpdateCount,isFetched:u.dataUpdateCount>0||u.errorUpdateCount>0,isFetchedAfterMount:u.dataUpdateCount>o.dataUpdateCount||u.errorUpdateCount>o.errorUpdateCount,isFetching:y,isRefetching:y&&!m,isLoadingError:b&&0===u.dataUpdatedAt,isPaused:"paused"===d,isPlaceholderData:p,isRefetchError:b&&0!==u.dataUpdatedAt,isStale:_(t,e),refetch:this.refetch}}#L(t){const e=this.#q,s=this.createResult(this.#R,this.options);if(this.#w=this.#R.state,this.#Q=this.options,d(s,e))return;void 0!==this.#w.data&&(this.#F=this.#w.data),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.throwOnError&&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.hasListeners()&&(e?.removeObserver(this),t.addObserver(this))}onQueryUpdate(){this.#L(),this.hasListeners()&&this.#U()}#N(t){M.batch((()=>{t.listeners&&this.listeners.forEach((t=>{t(this.#q)})),this.#O.getQueryCache().notify({query:this.#R,type:"observerResultsUpdated"})}))}}function j(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{mutationKey:t.options.mutationKey,state:t.state}}function z(t){return{state:t.state,queryKey:t.queryKey,queryHash:t.queryHash}}function J(t){return t.state.isPaused}function $(t){return"success"===t.state.status}t.CancelledError=Q,t.InfiniteQueryObserver=class extends H{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),hasPreviousPage:L(e,s.data),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}),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=new Map(e.map((t=>[t.options.queryHash,t]))),i=t.map((t=>this.#O.defaultQueryOptions(t))),r=i.flatMap((t=>{const e=s.get(t.queryHash);return null!=e?[{defaultedQueryOptions:t,observer:e}]:[]})),n=new Set(r.map((t=>t.defaultedQueryOptions.queryHash))),a=i.filter((t=>!n.has(t.queryHash))),o=t=>{const e=this.#O.defaultQueryOptions(t);return this.#c.find((t=>t.options.queryHash===e.queryHash))??new H(this.#O,e)},u=a.map((t=>({defaultedQueryOptions:t,observer:o(t)})));return r.concat(u).sort(((t,e)=>i.indexOf(t.defaultedQueryOptions)-i.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=D,t.QueryClient=class{#$;#m;#l;#V;#X;#Y;#Z;#tt;constructor(t={}){this.#$=t.queryCache||new D,this.#m=t.mutationCache||new I,this.#l=t.defaultOptions||{},this.#V=new Map,this.#X=new Map,this.#Y=0}mount(){this.#Y++,1===this.#Y&&(this.#Z=R.subscribe((()=>{R.isFocused()&&(this.resumePausedMutations(),this.#$.onFocus())})),this.#tt=C.subscribe((()=>{C.isOnline()&&(this.resumePausedMutations(),this.#$.onOnline())})))}unmount(){this.#Y--,0===this.#Y&&(this.#Z?.(),this.#Z=void 0,this.#tt?.(),this.#tt=void 0)}isFetching(t){return this.#$.findAll({...t,fetchStatus:"fetching"}).length}isMutating(t){return this.#m.findAll({...t,status:"pending"}).length}getQueryData(t){return this.#$.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.#$.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.#$.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.#$.find({queryKey:t})?.state}removeQueries(t){const e=this.#$;M.batch((()=>{e.findAll(t).forEach((t=>{e.remove(t)}))}))}resetQueries(t,e){const s=this.#$,i={type:"active",...t};return M.batch((()=>(s.findAll(t).forEach((t=>{t.reset()})),this.refetchQueries(i,e))))}cancelQueries(t={},e={}){const s={revert:!0,...e},r=M.batch((()=>this.#$.findAll(t).map((t=>t.cancel(s)))));return Promise.all(r).then(i).catch(i)}invalidateQueries(t={},e={}){return M.batch((()=>{if(this.#$.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.#$.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.#$.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.#$}getMutationCache(){return this.#m}getDefaultOptions(){return this.#l}setDefaultOptions(t){this.#l=t}setQueryDefaults(t,e){this.#V.set(h(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){const e=[...this.#V.values()];let s={};return e.forEach((e=>{c(t,e.queryKey)&&(s={...s,...e.defaultOptions})})),s}setMutationDefaults(t,e){this.#X.set(h(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){const e=[...this.#X.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.throwOnError&&(e.throwOnError=!!e.suspense),e}defaultMutationOptions(t){return t?._defaulted?t:{...this.#l.mutations,...t?.mutationKey&&this.getMutationDefaults(t.mutationKey),...t,_defaulted:!0}}clear(){this.#$.clear(),this.#m.clear()}},t.QueryObserver=H,t.defaultShouldDehydrateMutation=J,t.defaultShouldDehydrateQuery=$,t.dehydrate=function(t,e={}){const s=e.shouldDehydrateMutation??J,i=t.getMutationCache().getAll().flatMap((t=>s(t)?[W(t)]:[])),r=e.shouldDehydrateQuery??$;return{mutations:i,queries:t.getQueryCache().getAll().flatMap((t=>r(t)?[z(t)]:[]))}},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=S,t.isServer=s,t.keepPreviousData=function(t){return t},t.matchQuery=a,t.notifyManager=M,t.onlineManager=C,t.replaceEqualDeep=l})); | ||
//# sourceMappingURL=index.production.js.map |
{ | ||
"name": "@tanstack/query-core", | ||
"version": "5.0.0-alpha.23", | ||
"version": "5.0.0-alpha.24", | ||
"description": "The framework agnostic core that powers TanStack Query", | ||
@@ -5,0 +5,0 @@ "author": "tannerlinsley", |
@@ -467,3 +467,3 @@ import { noop, replaceData, timeUntilStale } from './utils' | ||
} | ||
onError(new Error('undefined') as any) | ||
onError(new Error(`${this.queryHash} data is undefined`) as any) | ||
return | ||
@@ -470,0 +470,0 @@ } |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1909094