@tanstack/query-core
Advanced tools
Comparing version 5.0.0-alpha.32 to 5.0.0-alpha.33
@@ -20,2 +20,3 @@ export { CancelledError } from './retryer'; | ||
export type { DehydrateOptions, DehydratedState, HydrateOptions, } from './hydration'; | ||
export type { QueriesObserverOptions } from './queriesObserver'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -7,15 +7,22 @@ import type { QueryObserverOptions, QueryObserverResult } from './types'; | ||
declare type QueriesObserverListener = (result: QueryObserverResult[]) => void; | ||
export declare class QueriesObserver extends Subscribable<QueriesObserverListener> { | ||
export interface QueriesObserverOptions<TCombinedResult = QueryObserverResult[]> { | ||
combine?: (result: QueryObserverResult[]) => TCombinedResult; | ||
} | ||
export declare class QueriesObserver<TCombinedResult = QueryObserverResult[]> extends Subscribable<QueriesObserverListener> { | ||
#private; | ||
constructor(client: QueryClient, queries?: QueryObserverOptions[]); | ||
constructor(client: QueryClient, queries: QueryObserverOptions[], options?: QueriesObserverOptions<TCombinedResult>); | ||
protected onSubscribe(): void; | ||
protected onUnsubscribe(): void; | ||
destroy(): void; | ||
setQueries(queries: QueryObserverOptions[], notifyOptions?: NotifyOptions): void; | ||
getCurrentResult(): QueryObserverResult[]; | ||
setQueries(queries: QueryObserverOptions[], options?: QueriesObserverOptions<TCombinedResult>, notifyOptions?: NotifyOptions): void; | ||
getCurrentResult(): TCombinedResult; | ||
getQueries(): import("./query").Query<unknown, Error, unknown, import("./types").QueryKey>[]; | ||
getObservers(): QueryObserver<unknown, Error, unknown, unknown, import("./types").QueryKey>[]; | ||
getOptimisticResult(queries: QueryObserverOptions[]): QueryObserverResult[]; | ||
getOptimisticResult(queries: QueryObserverOptions[]): [ | ||
rawResult: QueryObserverResult[], | ||
combineResult: (r?: QueryObserverResult[]) => TCombinedResult, | ||
trackResult: () => QueryObserverResult[] | ||
]; | ||
} | ||
export {}; | ||
//# sourceMappingURL=queriesObserver.d.ts.map |
@@ -5,2 +5,3 @@ import { classPrivateFieldLooseBase as _classPrivateFieldLooseBase, classPrivateFieldLooseKey as _classPrivateFieldLooseKey } from './_virtual/_rollupPluginBabelHelpers.esm.js'; | ||
import { Subscribable } from './subscribable.esm.js'; | ||
import { replaceEqualDeep } from './utils.esm.js'; | ||
@@ -19,2 +20,6 @@ function difference(array1, array2) { | ||
var _observers = /*#__PURE__*/_classPrivateFieldLooseKey("observers"); | ||
var _options = /*#__PURE__*/_classPrivateFieldLooseKey("options"); | ||
var _combinedResult = /*#__PURE__*/_classPrivateFieldLooseKey("combinedResult"); | ||
var _setResult = /*#__PURE__*/_classPrivateFieldLooseKey("setResult"); | ||
var _combineResult = /*#__PURE__*/_classPrivateFieldLooseKey("combineResult"); | ||
var _findMatchingObservers = /*#__PURE__*/_classPrivateFieldLooseKey("findMatchingObservers"); | ||
@@ -24,3 +29,3 @@ var _onUpdate = /*#__PURE__*/_classPrivateFieldLooseKey("onUpdate"); | ||
class QueriesObserver extends Subscribable { | ||
constructor(client, _queries2) { | ||
constructor(client, _queries2, _options2) { | ||
super(); | ||
@@ -36,2 +41,8 @@ Object.defineProperty(this, _notify, { | ||
}); | ||
Object.defineProperty(this, _combineResult, { | ||
value: _combineResult2 | ||
}); | ||
Object.defineProperty(this, _setResult, { | ||
value: _setResult2 | ||
}); | ||
Object.defineProperty(this, _client, { | ||
@@ -53,9 +64,15 @@ writable: true, | ||
}); | ||
Object.defineProperty(this, _options, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, _combinedResult, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_classPrivateFieldLooseBase(this, _client)[_client] = client; | ||
_classPrivateFieldLooseBase(this, _queries)[_queries] = []; | ||
_classPrivateFieldLooseBase(this, _result)[_result] = []; | ||
_classPrivateFieldLooseBase(this, _observers)[_observers] = []; | ||
if (_queries2) { | ||
this.setQueries(_queries2); | ||
} | ||
_classPrivateFieldLooseBase(this, _setResult)[_setResult]([]); | ||
this.setQueries(_queries2, _options2); | ||
} | ||
@@ -82,4 +99,5 @@ onSubscribe() { | ||
} | ||
setQueries(queries, notifyOptions) { | ||
setQueries(queries, options, notifyOptions) { | ||
_classPrivateFieldLooseBase(this, _queries)[_queries] = queries; | ||
_classPrivateFieldLooseBase(this, _options)[_options] = options; | ||
notifyManager.batch(() => { | ||
@@ -98,3 +116,3 @@ const prevObservers = _classPrivateFieldLooseBase(this, _observers)[_observers]; | ||
_classPrivateFieldLooseBase(this, _observers)[_observers] = newObservers; | ||
_classPrivateFieldLooseBase(this, _result)[_result] = newResult; | ||
_classPrivateFieldLooseBase(this, _setResult)[_setResult](newResult); | ||
if (!this.hasListeners()) { | ||
@@ -115,3 +133,3 @@ return; | ||
getCurrentResult() { | ||
return _classPrivateFieldLooseBase(this, _result)[_result]; | ||
return _classPrivateFieldLooseBase(this, _combinedResult)[_combinedResult]; | ||
} | ||
@@ -125,5 +143,26 @@ getQueries() { | ||
getOptimisticResult(queries) { | ||
return _classPrivateFieldLooseBase(this, _findMatchingObservers)[_findMatchingObservers](queries).map(match => match.observer.getOptimisticResult(match.defaultedQueryOptions)); | ||
const matches = _classPrivateFieldLooseBase(this, _findMatchingObservers)[_findMatchingObservers](queries); | ||
const result = matches.map(match => match.observer.getOptimisticResult(match.defaultedQueryOptions)); | ||
return [result, r => { | ||
return _classPrivateFieldLooseBase(this, _combineResult)[_combineResult](r != null ? r : result); | ||
}, () => { | ||
return matches.map((match, index) => { | ||
const observerResult = result[index]; | ||
return !match.defaultedQueryOptions.notifyOnChangeProps ? match.observer.trackResult(observerResult) : observerResult; | ||
}); | ||
}]; | ||
} | ||
} | ||
function _setResult2(value) { | ||
_classPrivateFieldLooseBase(this, _result)[_result] = value; | ||
_classPrivateFieldLooseBase(this, _combinedResult)[_combinedResult] = _classPrivateFieldLooseBase(this, _combineResult)[_combineResult](value); | ||
} | ||
function _combineResult2(input) { | ||
var _classPrivateFieldLoo; | ||
const combine = (_classPrivateFieldLoo = _classPrivateFieldLooseBase(this, _options)[_options]) == null ? void 0 : _classPrivateFieldLoo.combine; | ||
if (combine) { | ||
return replaceEqualDeep(_classPrivateFieldLooseBase(this, _combinedResult)[_combinedResult], combine(input)); | ||
} | ||
return input; | ||
} | ||
function _findMatchingObservers2(queries) { | ||
@@ -162,3 +201,3 @@ const prevObservers = _classPrivateFieldLooseBase(this, _observers)[_observers]; | ||
if (index !== -1) { | ||
_classPrivateFieldLooseBase(this, _result)[_result] = replaceAt(_classPrivateFieldLooseBase(this, _result)[_result], index, result); | ||
_classPrivateFieldLooseBase(this, _setResult)[_setResult](replaceAt(_classPrivateFieldLooseBase(this, _result)[_result], index, result)); | ||
_classPrivateFieldLooseBase(this, _notify)[_notify](); | ||
@@ -165,0 +204,0 @@ } |
@@ -7,2 +7,3 @@ 'use strict'; | ||
var subscribable = require('./subscribable.js'); | ||
var utils = require('./utils.js'); | ||
@@ -21,2 +22,6 @@ function difference(array1, array2) { | ||
var _observers = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("observers"); | ||
var _options = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("options"); | ||
var _combinedResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("combinedResult"); | ||
var _setResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("setResult"); | ||
var _combineResult = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("combineResult"); | ||
var _findMatchingObservers = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("findMatchingObservers"); | ||
@@ -26,3 +31,3 @@ var _onUpdate = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("onUpdate"); | ||
class QueriesObserver extends subscribable.Subscribable { | ||
constructor(client, _queries2) { | ||
constructor(client, _queries2, _options2) { | ||
super(); | ||
@@ -38,2 +43,8 @@ Object.defineProperty(this, _notify, { | ||
}); | ||
Object.defineProperty(this, _combineResult, { | ||
value: _combineResult2 | ||
}); | ||
Object.defineProperty(this, _setResult, { | ||
value: _setResult2 | ||
}); | ||
Object.defineProperty(this, _client, { | ||
@@ -55,9 +66,15 @@ writable: true, | ||
}); | ||
Object.defineProperty(this, _options, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, _combinedResult, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _client)[_client] = client; | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queries)[_queries] = []; | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _result)[_result] = []; | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers] = []; | ||
if (_queries2) { | ||
this.setQueries(_queries2); | ||
} | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setResult)[_setResult]([]); | ||
this.setQueries(_queries2, _options2); | ||
} | ||
@@ -84,4 +101,5 @@ onSubscribe() { | ||
} | ||
setQueries(queries, notifyOptions) { | ||
setQueries(queries, options, notifyOptions) { | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _queries)[_queries] = queries; | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _options)[_options] = options; | ||
notifyManager.notifyManager.batch(() => { | ||
@@ -100,3 +118,3 @@ const prevObservers = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers]; | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers] = newObservers; | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _result)[_result] = newResult; | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setResult)[_setResult](newResult); | ||
if (!this.hasListeners()) { | ||
@@ -117,3 +135,3 @@ return; | ||
getCurrentResult() { | ||
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _result)[_result]; | ||
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _combinedResult)[_combinedResult]; | ||
} | ||
@@ -127,5 +145,26 @@ getQueries() { | ||
getOptimisticResult(queries) { | ||
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _findMatchingObservers)[_findMatchingObservers](queries).map(match => match.observer.getOptimisticResult(match.defaultedQueryOptions)); | ||
const matches = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _findMatchingObservers)[_findMatchingObservers](queries); | ||
const result = matches.map(match => match.observer.getOptimisticResult(match.defaultedQueryOptions)); | ||
return [result, r => { | ||
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _combineResult)[_combineResult](r != null ? r : result); | ||
}, () => { | ||
return matches.map((match, index) => { | ||
const observerResult = result[index]; | ||
return !match.defaultedQueryOptions.notifyOnChangeProps ? match.observer.trackResult(observerResult) : observerResult; | ||
}); | ||
}]; | ||
} | ||
} | ||
function _setResult2(value) { | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _result)[_result] = value; | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _combinedResult)[_combinedResult] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _combineResult)[_combineResult](value); | ||
} | ||
function _combineResult2(input) { | ||
var _classPrivateFieldLoo; | ||
const combine = (_classPrivateFieldLoo = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _options)[_options]) == null ? void 0 : _classPrivateFieldLoo.combine; | ||
if (combine) { | ||
return utils.replaceEqualDeep(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _combinedResult)[_combinedResult], combine(input)); | ||
} | ||
return input; | ||
} | ||
function _findMatchingObservers2(queries) { | ||
@@ -164,3 +203,3 @@ const prevObservers = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers]; | ||
if (index !== -1) { | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _result)[_result] = replaceAt(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _result)[_result], index, result); | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setResult)[_setResult](replaceAt(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _result)[_result], index, result)); | ||
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _notify)[_notify](); | ||
@@ -167,0 +206,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=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(t){return this.listeners.add(t),this.onSubscribe(),()=>{this.listeners.delete(t),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}}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=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.size&&(this.#R.addObserver(this),j(this.#R,this.options)&&this.#I(),this.#U())}onUnsubscribe(){this.hasListeners()||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=new Set,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?.state.data,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:W(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.#R),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&&W(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)&&W(t,s)}function W(t,e){return t.isStaleByTime(e.staleTime)}function _(t,e){return t.filter((t=>-1===e.indexOf(t)))}function z(t){return{mutationKey:t.options.mutationKey,state:t.state}}function B(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;#W;#_;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.#W,observer:this}),this.#W?.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#W?.removeObserver(this)}onMutationUpdate(t){this.#L(),this.#N(t)}getCurrentResult(){return this.#q}reset(){this.#W=void 0,this.#L(),this.#N()}mutate(t,e){return this.#_=e,this.#W?.removeObserver(this),this.#W=this.#O.getMutationCache().build(this.#O,this.options),this.#W.addObserver(this),this.#W.execute(t)}#L(){const t=this.#W?.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.#_&&this.hasListeners()&&("success"===t?.type?(this.#_.onSuccess?.(t.data,this.#q.variables,this.#q.context),this.#_.onSettled?.(t.data,null,this.#q.variables,this.#q.context)):"error"===t?.type&&(this.#_.onError?.(t.error,this.#q.variables,this.#q.context),this.#_.onSettled?.(void 0,t.error,this.#q.variables,this.#q.context))),this.listeners.forEach((t=>{t(this.#q)}))}))}},t.QueriesObserver=class extends e{#O;#z;#y;#c;constructor(t,e){super(),this.#O=t,this.#y=[],this.#z=[],this.#c=[],e&&this.setQueries(e)}onSubscribe(){1===this.listeners.size&&this.#c.forEach((t=>{t.subscribe((e=>{this.#B(t,e)}))}))}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,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.#z=r,this.hasListeners()&&(_(t,i).forEach((t=>{t.destroy()})),_(i,t).forEach((t=>{t.subscribe((e=>{this.#B(t,e)}))})),this.#N()))}))}getCurrentResult(){return this.#z}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)))}#B(t,e){const s=this.#c.indexOf(t);-1!==s&&(this.#z=function(t,e,s){const i=t.slice(0);return i[e]=s,i}(this.#z,s,e),this.#N())}#N(){M.batch((()=>{this.listeners.forEach((t=>{t(this.#z)}))}))}},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={...e,cancelRefetch:e?.cancelRefetch??!0},r=M.batch((()=>this.#$.findAll(t).filter((t=>!t.isDisabled())).map((t=>{let e=t.fetch(void 0,s);return s.throwOnError||(e=e.catch(i)),"paused"===t.state.fetchStatus?Promise.resolve():e}))));return Promise.all(r).then(i)}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)?[z(t)]:[])),r=e.shouldDehydrateQuery??$;return{mutations:i,queries:t.getQueryCache().getAll().flatMap((t=>r(t)?[B(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=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(t){return this.listeners.add(t),this.onSubscribe(),()=>{this.listeners.delete(t),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}}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=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.size&&(this.#R.addObserver(this),j(this.#R,this.options)&&this.#I(),this.#U())}onUnsubscribe(){this.hasListeners()||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=new Set,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?.state.data,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:W(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.#R),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&&W(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)&&W(t,s)}function W(t,e){return t.isStaleByTime(e.staleTime)}function _(t,e){return t.filter((t=>-1===e.indexOf(t)))}function z(t){return{mutationKey:t.options.mutationKey,state:t.state}}function B(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;#W;#_;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.#W,observer:this}),this.#W?.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#W?.removeObserver(this)}onMutationUpdate(t){this.#L(),this.#N(t)}getCurrentResult(){return this.#q}reset(){this.#W=void 0,this.#L(),this.#N()}mutate(t,e){return this.#_=e,this.#W?.removeObserver(this),this.#W=this.#O.getMutationCache().build(this.#O,this.options),this.#W.addObserver(this),this.#W.execute(t)}#L(){const t=this.#W?.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.#_&&this.hasListeners()&&("success"===t?.type?(this.#_.onSuccess?.(t.data,this.#q.variables,this.#q.context),this.#_.onSettled?.(t.data,null,this.#q.variables,this.#q.context)):"error"===t?.type&&(this.#_.onError?.(t.error,this.#q.variables,this.#q.context),this.#_.onSettled?.(void 0,t.error,this.#q.variables,this.#q.context))),this.listeners.forEach((t=>{t(this.#q)}))}))}},t.QueriesObserver=class extends e{#O;#z;#y;#c;#B;#J;constructor(t,e,s){super(),this.#O=t,this.#y=[],this.#c=[],this.#$([]),this.setQueries(e,s)}#$(t){this.#z=t,this.#J=this.#V(t)}onSubscribe(){1===this.listeners.size&&this.#c.forEach((t=>{t.subscribe((e=>{this.#X(t,e)}))}))}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#c.forEach((t=>{t.destroy()}))}setQueries(t,e,s){this.#y=t,this.#B=e,M.batch((()=>{const t=this.#c,e=this.#Y(this.#y);e.forEach((t=>t.observer.setOptions(t.defaultedQueryOptions,s)));const i=e.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.#$(r),this.hasListeners()&&(_(t,i).forEach((t=>{t.destroy()})),_(i,t).forEach((t=>{t.subscribe((e=>{this.#X(t,e)}))})),this.#N()))}))}getCurrentResult(){return this.#J}getQueries(){return this.#c.map((t=>t.getCurrentQuery()))}getObservers(){return this.#c}getOptimisticResult(t){const e=this.#Y(t),s=e.map((t=>t.observer.getOptimisticResult(t.defaultedQueryOptions)));return[s,t=>this.#V(t??s),()=>e.map(((t,e)=>{const i=s[e];return t.defaultedQueryOptions.notifyOnChangeProps?i:t.observer.trackResult(i)}))]}#V(t){const e=this.#B?.combine;return e?l(this.#J,e(t)):t}#Y(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)))}#X(t,e){const s=this.#c.indexOf(t);-1!==s&&(this.#$(function(t,e,s){const i=t.slice(0);return i[e]=s,i}(this.#z,s,e)),this.#N())}#N(){M.batch((()=>{this.listeners.forEach((t=>{t(this.#z)}))}))}},t.QueryCache=D,t.QueryClient=class{#Z;#m;#l;#tt;#et;#st;#it;#rt;constructor(t={}){this.#Z=t.queryCache||new D,this.#m=t.mutationCache||new I,this.#l=t.defaultOptions||{},this.#tt=new Map,this.#et=new Map,this.#st=0}mount(){this.#st++,1===this.#st&&(this.#it=R.subscribe((()=>{R.isFocused()&&(this.resumePausedMutations(),this.#Z.onFocus())})),this.#rt=C.subscribe((()=>{C.isOnline()&&(this.resumePausedMutations(),this.#Z.onOnline())})))}unmount(){this.#st--,0===this.#st&&(this.#it?.(),this.#it=void 0,this.#rt?.(),this.#rt=void 0)}isFetching(t){return this.#Z.findAll({...t,fetchStatus:"fetching"}).length}isMutating(t){return this.#m.findAll({...t,status:"pending"}).length}getQueryData(t){return this.#Z.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.#Z.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.#Z.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.#Z.find({queryKey:t})?.state}removeQueries(t){const e=this.#Z;M.batch((()=>{e.findAll(t).forEach((t=>{e.remove(t)}))}))}resetQueries(t,e){const s=this.#Z,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.#Z.findAll(t).map((t=>t.cancel(s)))));return Promise.all(r).then(i).catch(i)}invalidateQueries(t={},e={}){return M.batch((()=>{if(this.#Z.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={...e,cancelRefetch:e?.cancelRefetch??!0},r=M.batch((()=>this.#Z.findAll(t).filter((t=>!t.isDisabled())).map((t=>{let e=t.fetch(void 0,s);return s.throwOnError||(e=e.catch(i)),"paused"===t.state.fetchStatus?Promise.resolve():e}))));return Promise.all(r).then(i)}fetchQuery(t){const e=this.defaultQueryOptions(t);void 0===e.retry&&(e.retry=!1);const s=this.#Z.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.#Z}getMutationCache(){return this.#m}getDefaultOptions(){return this.#l}setDefaultOptions(t){this.#l=t}setQueryDefaults(t,e){this.#tt.set(h(t),{queryKey:t,defaultOptions:e})}getQueryDefaults(t){const e=[...this.#tt.values()];let s={};return e.forEach((e=>{c(t,e.queryKey)&&(s={...s,...e.defaultOptions})})),s}setMutationDefaults(t,e){this.#et.set(h(t),{mutationKey:t,defaultOptions:e})}getMutationDefaults(t){const e=[...this.#et.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.#Z.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)?[z(t)]:[])),r=e.shouldDehydrateQuery??$;return{mutations:i,queries:t.getQueryCache().getAll().flatMap((t=>r(t)?[B(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.32", | ||
"version": "5.0.0-alpha.33", | ||
"description": "The framework agnostic core that powers TanStack Query", | ||
@@ -5,0 +5,0 @@ "author": "tannerlinsley", |
@@ -39,1 +39,2 @@ /* istanbul ignore file */ | ||
} from './hydration' | ||
export type { QueriesObserverOptions } from './queriesObserver' |
@@ -11,2 +11,3 @@ import { notifyManager } from './notifyManager' | ||
import { Subscribable } from './subscribable' | ||
import { replaceEqualDeep } from './utils' | ||
@@ -25,9 +26,23 @@ function difference<T>(array1: T[], array2: T[]): T[] { | ||
export class QueriesObserver extends Subscribable<QueriesObserverListener> { | ||
export interface QueriesObserverOptions< | ||
TCombinedResult = QueryObserverResult[], | ||
> { | ||
combine?: (result: QueryObserverResult[]) => TCombinedResult | ||
} | ||
export class QueriesObserver< | ||
TCombinedResult = QueryObserverResult[], | ||
> extends Subscribable<QueriesObserverListener> { | ||
#client: QueryClient | ||
#result: QueryObserverResult[] | ||
#result!: QueryObserverResult[] | ||
#queries: QueryObserverOptions[] | ||
#observers: QueryObserver[] | ||
#options?: QueriesObserverOptions<TCombinedResult> | ||
#combinedResult!: TCombinedResult | ||
constructor(client: QueryClient, queries?: QueryObserverOptions[]) { | ||
constructor( | ||
client: QueryClient, | ||
queries: QueryObserverOptions[], | ||
options?: QueriesObserverOptions<TCombinedResult>, | ||
) { | ||
super() | ||
@@ -37,10 +52,13 @@ | ||
this.#queries = [] | ||
this.#result = [] | ||
this.#observers = [] | ||
if (queries) { | ||
this.setQueries(queries) | ||
} | ||
this.#setResult([]) | ||
this.setQueries(queries, options) | ||
} | ||
#setResult(value: QueryObserverResult[]) { | ||
this.#result = value | ||
this.#combinedResult = this.#combineResult(value) | ||
} | ||
protected onSubscribe(): void { | ||
@@ -71,5 +89,7 @@ if (this.listeners.size === 1) { | ||
queries: QueryObserverOptions[], | ||
options?: QueriesObserverOptions<TCombinedResult>, | ||
notifyOptions?: NotifyOptions, | ||
): void { | ||
this.#queries = queries | ||
this.#options = options | ||
@@ -99,3 +119,3 @@ notifyManager.batch(() => { | ||
this.#observers = newObservers | ||
this.#result = newResult | ||
this.#setResult(newResult) | ||
@@ -120,4 +140,4 @@ if (!this.hasListeners()) { | ||
getCurrentResult(): QueryObserverResult[] { | ||
return this.#result | ||
getCurrentResult(): TCombinedResult { | ||
return this.#combinedResult | ||
} | ||
@@ -133,8 +153,38 @@ | ||
getOptimisticResult(queries: QueryObserverOptions[]): QueryObserverResult[] { | ||
return this.#findMatchingObservers(queries).map((match) => | ||
getOptimisticResult( | ||
queries: QueryObserverOptions[], | ||
): [ | ||
rawResult: QueryObserverResult[], | ||
combineResult: (r?: QueryObserverResult[]) => TCombinedResult, | ||
trackResult: () => QueryObserverResult[], | ||
] { | ||
const matches = this.#findMatchingObservers(queries) | ||
const result = matches.map((match) => | ||
match.observer.getOptimisticResult(match.defaultedQueryOptions), | ||
) | ||
return [ | ||
result, | ||
(r?: QueryObserverResult[]) => { | ||
return this.#combineResult(r ?? result) | ||
}, | ||
() => { | ||
return matches.map((match, index) => { | ||
const observerResult = result[index]! | ||
return !match.defaultedQueryOptions.notifyOnChangeProps | ||
? match.observer.trackResult(observerResult) | ||
: observerResult | ||
}) | ||
}, | ||
] | ||
} | ||
#combineResult(input: QueryObserverResult[]): TCombinedResult { | ||
const combine = this.#options?.combine | ||
if (combine) { | ||
return replaceEqualDeep(this.#combinedResult, combine(input)) | ||
} | ||
return input as any | ||
} | ||
#findMatchingObservers( | ||
@@ -202,3 +252,3 @@ queries: QueryObserverOptions[], | ||
if (index !== -1) { | ||
this.#result = replaceAt(this.#result, index, result) | ||
this.#setResult(replaceAt(this.#result, index, result)) | ||
this.#notify() | ||
@@ -205,0 +255,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
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
22795
1936087
196