{"version":3,"sources":["/../../src/useSyncExternalStore.ts","/../../node_modules/core-js/modules/es.promise.catch.js","/../../src/QueryErrorResetBoundary.tsx","/../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js","/../../src/focusManager.ts","/../../node_modules/core-js/modules/es.promise.js","/../../src/removable.ts","/../../node_modules/core-js/internals/perform.js","/../../node_modules/core-js/internals/promise-resolve.js","/../../node_modules/core-js/internals/set-species.js","/../../node_modules/@tanstack/query-core/build/lib/index.mjs","/../../node_modules/core-js/internals/validate-arguments-length.js","/../../node_modules/core-js/internals/new-promise-capability.js","/../../src/logger.ts","/../../src/useQuery.ts","/../../node_modules/core-js/internals/iterate.js","/../../src/retryer.ts","/../../src/errorBoundaryUtils.ts","/../../src/mutation.ts","/../../src/suspense.ts","/../../node_modules/core-js/internals/safe-get-built-in.js","/../../node_modules/core-js/internals/queue.js","/../../src/utils.ts","/../../node_modules/core-js/modules/es.promise.reject.js","/../../node_modules/core-js/internals/promise-native-constructor.js","/../../node_modules/core-js/internals/is-possible-prototype.js","/../../node_modules/core-js/internals/a-possible-prototype.js","/../../src/queryObserver.ts","/../../src/subscribable.ts","/../../node_modules/core-js/internals/check-correctness-of-iteration.js","/../../src/queryClient.ts","/../../node_modules/core-js/internals/promise-constructor-detection.js","/../../src/notifyManager.ts","/../../src/infiniteQueryBehavior.ts","/../../src/queryCache.ts","/../../src/useBaseQuery.ts","/../../src/useInfiniteQuery.ts","/../../node_modules/core-js/internals/get-iterator.js","/../../node_modules/core-js/internals/get-iterator-method.js","/../../node_modules/core-js/modules/es.promise.race.js","/../../node_modules/core-js/modules/es.promise.constructor.js","/../../node_modules/core-js/internals/array-slice.js","/../../node_modules/core-js/modules/es.promise.resolve.js","/../../node_modules/core-js/internals/task.js","/../../node_modules/core-js/internals/iterator-close.js","/../../node_modules/core-js/internals/is-array-iterator-method.js","/../../src/useMutation.ts","/../../node_modules/@tanstack/react-query/build/lib/index.mjs","/../../node_modules/core-js/internals/function-apply.js","/../../node_modules/core-js/internals/microtask.js","/../../src/queriesObserver.ts","/../../src/infiniteQueryObserver.ts","/../../node_modules/core-js/internals/an-instance.js","/../../node_modules/core-js/internals/object-set-prototype-of.js","/../../node_modules/core-js/internals/iterators.js","/../../src/useQueries.ts","/../../node_modules/core-js/internals/function-bind-context.js","/../../node_modules/core-js/internals/set-to-string-tag.js","/../../src/isRestoring.tsx","/../../src/onlineManager.ts","/../../src/mutationObserver.ts","/../../src/mutationCache.ts","/../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js","/../../node_modules/use-sync-external-store/shim/index.js","/../../node_modules/core-js/internals/environment-is-ios-pebble.js","/../../node_modules/core-js/internals/host-report-errors.js","/../../node_modules/core-js/internals/environment-is-ios.js","/../../node_modules/core-js/internals/environment.js","/../../node_modules/core-js/internals/define-built-in-accessor.js","/../../src/query.ts","/../../node_modules/core-js/modules/es.promise.all.js","/../../node_modules/core-js/internals/function-uncurry-this-clause.js","/../../node_modules/core-js/internals/environment-is-webos-webkit.js","/../../node_modules/core-js/internals/promise-statics-incorrect-iteration.js","/../../node_modules/core-js/internals/environment-is-node.js","/../../node_modules/core-js/internals/function-uncurry-this-accessor.js","/../../src/QueryClientProvider.tsx"],"sourcesContent":["'use client'\n// Temporary workaround due to an issue with react-native uSES - https://github.com/TanStack/query/pull/3601\nimport { useSyncExternalStore as uSES } from 'use-sync-external-store/shim/index.js'\n\nexport const useSyncExternalStore = uSES\n","'use strict';\nvar $ = require('../internals/export');\nvar IS_PURE = require('../internals/is-pure');\nvar FORCED_PROMISE_CONSTRUCTOR = require('../internals/promise-constructor-detection').CONSTRUCTOR;\nvar NativePromiseConstructor = require('../internals/promise-native-constructor');\nvar getBuiltIn = require('../internals/get-built-in');\nvar isCallable = require('../internals/is-callable');\nvar defineBuiltIn = require('../internals/define-built-in');\n\nvar NativePromisePrototype = NativePromiseConstructor && NativePromiseConstructor.prototype;\n\n// `Promise.prototype.catch` method\n// https://tc39.es/ecma262/#sec-promise.prototype.catch\n$({ target: 'Promise', proto: true, forced: FORCED_PROMISE_CONSTRUCTOR, real: true }, {\n 'catch': function (onRejected) {\n return this.then(undefined, onRejected);\n }\n});\n\n// makes sure that native promise-based APIs `Promise#catch` properly works with patched `Promise#then`\nif (!IS_PURE && isCallable(NativePromiseConstructor)) {\n var method = getBuiltIn('Promise').prototype['catch'];\n if (NativePromisePrototype['catch'] !== method) {\n defineBuiltIn(NativePromisePrototype, 'catch', method, { unsafe: true });\n }\n}\n","'use client'\nimport * as React from 'react'\n\n// CONTEXT\n\nexport interface QueryErrorResetBoundaryValue {\n clearReset: () => void\n isReset: () => boolean\n reset: () => void\n}\n\nfunction createValue(): QueryErrorResetBoundaryValue {\n let isReset = false\n return {\n clearReset: () => {\n isReset = false\n },\n reset: () => {\n isReset = true\n },\n isReset: () => {\n return isReset\n },\n }\n}\n\nconst QueryErrorResetBoundaryContext = React.createContext(createValue())\n\n// HOOK\n\nexport const useQueryErrorResetBoundary = () =>\n React.useContext(QueryErrorResetBoundaryContext)\n\n// COMPONENT\n\nexport interface QueryErrorResetBoundaryProps {\n children:\n | ((value: QueryErrorResetBoundaryValue) => React.ReactNode)\n | React.ReactNode\n}\n\nexport const QueryErrorResetBoundary = ({\n children,\n}: QueryErrorResetBoundaryProps) => {\n const [value] = React.useState(() => createValue())\n return (\n \n {typeof children === 'function'\n ? (children as Function)(value)\n : children}\n \n )\n}\n","/**\n * @license React\n * use-sync-external-store-shim.development.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n'use strict';\n\nif (\"production\" !== \"production\") {\n (function() {\n\n 'use strict';\n\n/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */\nif (\n typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&\n typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===\n 'function'\n) {\n __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());\n}\n var React = require('react');\n\nvar ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;\n\nfunction error(format) {\n {\n {\n for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {\n args[_key2 - 1] = arguments[_key2];\n }\n\n printWarning('error', format, args);\n }\n }\n}\n\nfunction printWarning(level, format, args) {\n // When changing this logic, you might want to also\n // update consoleWithStackDev.www.js as well.\n {\n var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;\n var stack = ReactDebugCurrentFrame.getStackAddendum();\n\n if (stack !== '') {\n format += '%s';\n args = args.concat([stack]);\n } // eslint-disable-next-line react-internal/safe-string-coercion\n\n\n var argsWithFormat = args.map(function (item) {\n return String(item);\n }); // Careful: RN currently depends on this prefix\n\n argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it\n // breaks IE9: https://github.com/facebook/react/issues/13610\n // eslint-disable-next-line react-internal/no-production-logging\n\n Function.prototype.apply.call(console[level], console, argsWithFormat);\n }\n}\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\nfunction is(x, y) {\n return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare\n ;\n}\n\nvar objectIs = typeof Object.is === 'function' ? Object.is : is;\n\n// dispatch for CommonJS interop named imports.\n\nvar useState = React.useState,\n useEffect = React.useEffect,\n useLayoutEffect = React.useLayoutEffect,\n useDebugValue = React.useDebugValue;\nvar didWarnOld18Alpha = false;\nvar didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works\n// because of a very particular set of implementation details and assumptions\n// -- change any one of them and it will break. The most important assumption\n// is that updates are always synchronous, because concurrent rendering is\n// only available in versions of React that also have a built-in\n// useSyncExternalStore API. And we only use this shim when the built-in API\n// does not exist.\n//\n// Do not assume that the clever hacks used by this hook also work in general.\n// The point of this shim is to replace the need for hacks by other libraries.\n\nfunction useSyncExternalStore(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of\n// React do not expose a way to check if we're hydrating. So users of the shim\n// will need to track that themselves and return the correct value\n// from `getSnapshot`.\ngetServerSnapshot) {\n {\n if (!didWarnOld18Alpha) {\n if (React.startTransition !== undefined) {\n didWarnOld18Alpha = true;\n\n error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.');\n }\n }\n } // Read the current snapshot from the store on every render. Again, this\n // breaks the rules of React, and only works here because of specific\n // implementation details, most importantly that updates are\n // always synchronous.\n\n\n var value = getSnapshot();\n\n {\n if (!didWarnUncachedGetSnapshot) {\n var cachedValue = getSnapshot();\n\n if (!objectIs(value, cachedValue)) {\n error('The result of getSnapshot should be cached to avoid an infinite loop');\n\n didWarnUncachedGetSnapshot = true;\n }\n }\n } // Because updates are synchronous, we don't queue them. Instead we force a\n // re-render whenever the subscribed state changes by updating an some\n // arbitrary useState hook. Then, during render, we call getSnapshot to read\n // the current value.\n //\n // Because we don't actually use the state returned by the useState hook, we\n // can save a bit of memory by storing other stuff in that slot.\n //\n // To implement the early bailout, we need to track some things on a mutable\n // object. Usually, we would put that in a useRef hook, but we can stash it in\n // our useState hook instead.\n //\n // To force a re-render, we call forceUpdate({inst}). That works because the\n // new object always fails an equality check.\n\n\n var _useState = useState({\n inst: {\n value: value,\n getSnapshot: getSnapshot\n }\n }),\n inst = _useState[0].inst,\n forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated\n // in the layout phase so we can access it during the tearing check that\n // happens on subscribe.\n\n\n useLayoutEffect(function () {\n inst.value = value;\n inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the\n // commit phase if there was an interleaved mutation. In concurrent mode\n // this can happen all the time, but even in synchronous mode, an earlier\n // effect may have mutated the store.\n\n if (checkIfSnapshotChanged(inst)) {\n // Force a re-render.\n forceUpdate({\n inst: inst\n });\n }\n }, [subscribe, value, getSnapshot]);\n useEffect(function () {\n // Check for changes right before subscribing. Subsequent changes will be\n // detected in the subscription handler.\n if (checkIfSnapshotChanged(inst)) {\n // Force a re-render.\n forceUpdate({\n inst: inst\n });\n }\n\n var handleStoreChange = function () {\n // TODO: Because there is no cross-renderer API for batching updates, it's\n // up to the consumer of this library to wrap their subscription event\n // with unstable_batchedUpdates. Should we try to detect when this isn't\n // the case and print a warning in development?\n // The store changed. Check if the snapshot changed since the last time we\n // read from the store.\n if (checkIfSnapshotChanged(inst)) {\n // Force a re-render.\n forceUpdate({\n inst: inst\n });\n }\n }; // Subscribe to the store and return a clean-up function.\n\n\n return subscribe(handleStoreChange);\n }, [subscribe]);\n useDebugValue(value);\n return value;\n}\n\nfunction checkIfSnapshotChanged(inst) {\n var latestGetSnapshot = inst.getSnapshot;\n var prevValue = inst.value;\n\n try {\n var nextValue = latestGetSnapshot();\n return !objectIs(prevValue, nextValue);\n } catch (error) {\n return true;\n }\n}\n\nfunction useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {\n // Note: The shim does not use getServerSnapshot, because pre-18 versions of\n // React do not expose a way to check if we're hydrating. So users of the shim\n // will need to track that themselves and return the correct value\n // from `getSnapshot`.\n return getSnapshot();\n}\n\nvar canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');\n\nvar isServerEnvironment = !canUseDOM;\n\nvar shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;\nvar useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;\n\nexports.useSyncExternalStore = useSyncExternalStore$2;\n /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */\nif (\n typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&\n typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===\n 'function'\n) {\n __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());\n}\n \n })();\n}\n","import { Subscribable } from './subscribable'\nimport { isServer } from './utils'\n\ntype SetupFn = (\n setFocused: (focused?: boolean) => void,\n) => (() => void) | undefined\n\nexport class FocusManager extends Subscribable {\n private focused?: boolean\n private cleanup?: () => void\n\n private setup: SetupFn\n\n constructor() {\n super()\n this.setup = (onFocus) => {\n // addEventListener does not exist in React Native, but window does\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isServer && window.addEventListener) {\n const listener = () => onFocus()\n // Listen to visibillitychange and focus\n window.addEventListener('visibilitychange', listener, false)\n window.addEventListener('focus', listener, false)\n\n return () => {\n // Be sure to unsubscribe if a new handler is set\n window.removeEventListener('visibilitychange', listener)\n window.removeEventListener('focus', listener)\n }\n }\n return\n }\n }\n\n protected onSubscribe(): void {\n if (!this.cleanup) {\n this.setEventListener(this.setup)\n }\n }\n\n protected onUnsubscribe() {\n if (!this.hasListeners()) {\n this.cleanup?.()\n this.cleanup = undefined\n }\n }\n\n setEventListener(setup: SetupFn): void {\n this.setup = setup\n this.cleanup?.()\n this.cleanup = setup((focused) => {\n if (typeof focused === 'boolean') {\n this.setFocused(focused)\n } else {\n this.onFocus()\n }\n })\n }\n\n setFocused(focused?: boolean): void {\n const changed = this.focused !== focused\n if (changed) {\n this.focused = focused\n this.onFocus()\n }\n }\n\n onFocus(): void {\n this.listeners.forEach(({ listener }) => {\n listener()\n })\n }\n\n isFocused(): boolean {\n if (typeof this.focused === 'boolean') {\n return this.focused\n }\n\n // document global can be unavailable in react native\n if (typeof document === 'undefined') {\n return true\n }\n\n return [undefined, 'visible', 'prerender'].includes(\n document.visibilityState,\n )\n }\n}\n\nexport const focusManager = new FocusManager()\n","'use strict';\n// TODO: Remove this module from `core-js@4` since it's split to modules listed below\nrequire('../modules/es.promise.constructor');\nrequire('../modules/es.promise.all');\nrequire('../modules/es.promise.catch');\nrequire('../modules/es.promise.race');\nrequire('../modules/es.promise.reject');\nrequire('../modules/es.promise.resolve');\n","import { isServer, isValidTimeout } from './utils'\n\nexport abstract class Removable {\n cacheTime!: number\n private gcTimeout?: ReturnType\n\n destroy(): void {\n this.clearGcTimeout()\n }\n\n protected scheduleGc(): void {\n this.clearGcTimeout()\n\n if (isValidTimeout(this.cacheTime)) {\n this.gcTimeout = setTimeout(() => {\n this.optionalRemove()\n }, this.cacheTime)\n }\n }\n\n protected updateCacheTime(newCacheTime: number | undefined): void {\n // Default to 5 minutes (Infinity for server-side) if no cache time is set\n this.cacheTime = Math.max(\n this.cacheTime || 0,\n newCacheTime ?? (isServer ? Infinity : 5 * 60 * 1000),\n )\n }\n\n protected clearGcTimeout() {\n if (this.gcTimeout) {\n clearTimeout(this.gcTimeout)\n this.gcTimeout = undefined\n }\n }\n\n protected abstract optionalRemove(): void\n}\n","'use strict';\nmodule.exports = function (exec) {\n try {\n return { error: false, value: exec() };\n } catch (error) {\n return { error: true, value: error };\n }\n};\n","'use strict';\nvar anObject = require('../internals/an-object');\nvar isObject = require('../internals/is-object');\nvar newPromiseCapability = require('../internals/new-promise-capability');\n\nmodule.exports = function (C, x) {\n anObject(C);\n if (isObject(x) && x.constructor === C) return x;\n var promiseCapability = newPromiseCapability.f(C);\n var resolve = promiseCapability.resolve;\n resolve(x);\n return promiseCapability.promise;\n};\n","'use strict';\nvar getBuiltIn = require('../internals/get-built-in');\nvar defineBuiltInAccessor = require('../internals/define-built-in-accessor');\nvar wellKnownSymbol = require('../internals/well-known-symbol');\nvar DESCRIPTORS = require('../internals/descriptors');\n\nvar SPECIES = wellKnownSymbol('species');\n\nmodule.exports = function (CONSTRUCTOR_NAME) {\n var Constructor = getBuiltIn(CONSTRUCTOR_NAME);\n\n if (DESCRIPTORS && Constructor && !Constructor[SPECIES]) {\n defineBuiltInAccessor(Constructor, SPECIES, {\n configurable: true,\n get: function () { return this; }\n });\n }\n};\n","function e(e,r,a,v){e._m(r);var _=a(\"6ef6d243\");e._(r,\"QueryCache\",_);var s=a(\"6c48cc4b\");e._(r,\"QueryClient\",s);var u=a(\"5e1710d5\");e._(r,\"QueryObserver\",u);var n=a(\"a1e10b1a\");e._(r,\"QueriesObserver\",n);var i=a(\"a65f3fed\");e._(r,\"InfiniteQueryObserver\",i);var t=a(\"d11e52d9\");e._(r,\"MutationObserver\",t);var y=a(\"6d7b4c1d\");e._(r,\"notifyManager\",y);var b=a(\"43ae377f\");e._(r,\"hashQueryKey\",b),e._(r,\"parseMutationArgs\",b),e._(r,\"parseQueryArgs\",b);}","'use strict';\nvar $TypeError = TypeError;\n\nmodule.exports = function (passed, required) {\n if (passed < required) throw new $TypeError('Not enough arguments');\n return passed;\n};\n","'use strict';\nvar aCallable = require('../internals/a-callable');\n\nvar $TypeError = TypeError;\n\nvar PromiseCapability = function (C) {\n var resolve, reject;\n this.promise = new C(function ($$resolve, $$reject) {\n if (resolve !== undefined || reject !== undefined) throw new $TypeError('Bad Promise constructor');\n resolve = $$resolve;\n reject = $$reject;\n });\n this.resolve = aCallable(resolve);\n this.reject = aCallable(reject);\n};\n\n// `NewPromiseCapability` abstract operation\n// https://tc39.es/ecma262/#sec-newpromisecapability\nmodule.exports.f = function (C) {\n return new PromiseCapability(C);\n};\n","export interface Logger {\n log: LogFunction\n warn: LogFunction\n error: LogFunction\n}\n\ntype LogFunction = (...args: any[]) => void\n\nexport const defaultLogger: Logger = console\n","'use client'\nimport { QueryObserver, parseQueryArgs } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type { QueryFunction, QueryKey } from '@tanstack/query-core'\nimport type {\n DefinedUseQueryResult,\n UseQueryOptions,\n UseQueryResult,\n} from './types'\n\n// HOOK\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: Omit<\n UseQueryOptions,\n 'initialData'\n > & { initialData?: () => undefined },\n): UseQueryResult\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: Omit<\n UseQueryOptions,\n 'initialData'\n > & { initialData: TQueryFnData | (() => TQueryFnData) },\n): DefinedUseQueryResult\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions,\n): UseQueryResult\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n options?: Omit<\n UseQueryOptions,\n 'queryKey' | 'initialData'\n > & { initialData?: () => undefined },\n): UseQueryResult\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n options?: Omit<\n UseQueryOptions,\n 'queryKey' | 'initialData'\n > & { initialData: TQueryFnData | (() => TQueryFnData) },\n): DefinedUseQueryResult\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n options?: Omit<\n UseQueryOptions,\n 'queryKey'\n >,\n): UseQueryResult\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n queryFn: QueryFunction,\n options?: Omit<\n UseQueryOptions,\n 'queryKey' | 'queryFn' | 'initialData'\n > & { initialData?: () => undefined },\n): UseQueryResult\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n queryFn: QueryFunction,\n options?: Omit<\n UseQueryOptions,\n 'queryKey' | 'queryFn' | 'initialData'\n > & { initialData: TQueryFnData | (() => TQueryFnData) },\n): DefinedUseQueryResult\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n queryFn: QueryFunction,\n options?: Omit<\n UseQueryOptions,\n 'queryKey' | 'queryFn'\n >,\n): UseQueryResult\n\nexport function useQuery<\n TQueryFnData,\n TError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n arg1: TQueryKey | UseQueryOptions,\n arg2?:\n | QueryFunction\n | UseQueryOptions,\n arg3?: UseQueryOptions,\n): UseQueryResult {\n const parsedOptions = parseQueryArgs(arg1, arg2, arg3)\n return useBaseQuery(parsedOptions, QueryObserver)\n}\n","'use strict';\nvar bind = require('../internals/function-bind-context');\nvar call = require('../internals/function-call');\nvar anObject = require('../internals/an-object');\nvar tryToString = require('../internals/try-to-string');\nvar isArrayIteratorMethod = require('../internals/is-array-iterator-method');\nvar lengthOfArrayLike = require('../internals/length-of-array-like');\nvar isPrototypeOf = require('../internals/object-is-prototype-of');\nvar getIterator = require('../internals/get-iterator');\nvar getIteratorMethod = require('../internals/get-iterator-method');\nvar iteratorClose = require('../internals/iterator-close');\n\nvar $TypeError = TypeError;\n\nvar Result = function (stopped, result) {\n this.stopped = stopped;\n this.result = result;\n};\n\nvar ResultPrototype = Result.prototype;\n\nmodule.exports = function (iterable, unboundFunction, options) {\n var that = options && options.that;\n var AS_ENTRIES = !!(options && options.AS_ENTRIES);\n var IS_RECORD = !!(options && options.IS_RECORD);\n var IS_ITERATOR = !!(options && options.IS_ITERATOR);\n var INTERRUPTED = !!(options && options.INTERRUPTED);\n var fn = bind(unboundFunction, that);\n var iterator, iterFn, index, length, result, next, step;\n\n var stop = function (condition) {\n if (iterator) iteratorClose(iterator, 'normal', condition);\n return new Result(true, condition);\n };\n\n var callFn = function (value) {\n if (AS_ENTRIES) {\n anObject(value);\n return INTERRUPTED ? fn(value[0], value[1], stop) : fn(value[0], value[1]);\n } return INTERRUPTED ? fn(value, stop) : fn(value);\n };\n\n if (IS_RECORD) {\n iterator = iterable.iterator;\n } else if (IS_ITERATOR) {\n iterator = iterable;\n } else {\n iterFn = getIteratorMethod(iterable);\n if (!iterFn) throw new $TypeError(tryToString(iterable) + ' is not iterable');\n // optimisation for array iterators\n if (isArrayIteratorMethod(iterFn)) {\n for (index = 0, length = lengthOfArrayLike(iterable); length > index; index++) {\n result = callFn(iterable[index]);\n if (result && isPrototypeOf(ResultPrototype, result)) return result;\n } return new Result(false);\n }\n iterator = getIterator(iterable, iterFn);\n }\n\n next = IS_RECORD ? iterable.next : iterator.next;\n while (!(step = call(next, iterator)).done) {\n try {\n result = callFn(step.value);\n } catch (error) {\n iteratorClose(iterator, 'throw', error);\n }\n if (typeof result == 'object' && result && isPrototypeOf(ResultPrototype, result)) return result;\n } return new Result(false);\n};\n","import { focusManager } from './focusManager'\nimport { onlineManager } from './onlineManager'\nimport { sleep } from './utils'\nimport type { CancelOptions, NetworkMode } from './types'\n\n// TYPES\n\ninterface RetryerConfig {\n fn: () => TData | Promise\n abort?: () => void\n onError?: (error: TError) => void\n onSuccess?: (data: TData) => void\n onFail?: (failureCount: number, error: TError) => void\n onPause?: () => void\n onContinue?: () => void\n retry?: RetryValue\n retryDelay?: RetryDelayValue\n networkMode: NetworkMode | undefined\n}\n\nexport interface Retryer {\n promise: Promise\n cancel: (cancelOptions?: CancelOptions) => void\n continue: () => Promise\n cancelRetry: () => void\n continueRetry: () => void\n}\n\nexport type RetryValue = boolean | number | ShouldRetryFunction\n\ntype ShouldRetryFunction = (\n failureCount: number,\n error: TError,\n) => boolean\n\nexport type RetryDelayValue = number | RetryDelayFunction\n\ntype RetryDelayFunction = (\n failureCount: number,\n error: TError,\n) => number\n\nfunction defaultRetryDelay(failureCount: number) {\n return Math.min(1000 * 2 ** failureCount, 30000)\n}\n\nexport function canFetch(networkMode: NetworkMode | undefined): boolean {\n return (networkMode ?? 'online') === 'online'\n ? onlineManager.isOnline()\n : true\n}\n\nexport class CancelledError {\n revert?: boolean\n silent?: boolean\n constructor(options?: CancelOptions) {\n this.revert = options?.revert\n this.silent = options?.silent\n }\n}\n\nexport function isCancelledError(value: any): value is CancelledError {\n return value instanceof CancelledError\n}\n\nexport function createRetryer(\n config: RetryerConfig,\n): Retryer {\n let isRetryCancelled = false\n let failureCount = 0\n let isResolved = false\n let continueFn: ((value?: unknown) => boolean) | undefined\n let promiseResolve: (data: TData) => void\n let promiseReject: (error: TError) => void\n\n const promise = new Promise((outerResolve, outerReject) => {\n promiseResolve = outerResolve\n promiseReject = outerReject\n })\n\n const cancel = (cancelOptions?: CancelOptions): void => {\n if (!isResolved) {\n reject(new CancelledError(cancelOptions))\n\n config.abort?.()\n }\n }\n const cancelRetry = () => {\n isRetryCancelled = true\n }\n\n const continueRetry = () => {\n isRetryCancelled = false\n }\n\n const shouldPause = () =>\n !focusManager.isFocused() ||\n (config.networkMode !== 'always' && !onlineManager.isOnline())\n\n const resolve = (value: any) => {\n if (!isResolved) {\n isResolved = true\n config.onSuccess?.(value)\n continueFn?.()\n promiseResolve(value)\n }\n }\n\n const reject = (value: any) => {\n if (!isResolved) {\n isResolved = true\n config.onError?.(value)\n continueFn?.()\n promiseReject(value)\n }\n }\n\n const pause = () => {\n return new Promise((continueResolve) => {\n continueFn = (value) => {\n const canContinue = isResolved || !shouldPause()\n if (canContinue) {\n continueResolve(value)\n }\n return canContinue\n }\n config.onPause?.()\n }).then(() => {\n continueFn = undefined\n if (!isResolved) {\n config.onContinue?.()\n }\n })\n }\n\n // Create loop function\n const run = () => {\n // Do nothing if already resolved\n if (isResolved) {\n return\n }\n\n let promiseOrValue: any\n\n // Execute query\n try {\n promiseOrValue = config.fn()\n } catch (error) {\n promiseOrValue = Promise.reject(error)\n }\n\n Promise.resolve(promiseOrValue)\n .then(resolve)\n .catch((error) => {\n // Stop if the fetch is already resolved\n if (isResolved) {\n return\n }\n\n // Do we need to retry the request?\n const retry = config.retry ?? 3\n const retryDelay = config.retryDelay ?? defaultRetryDelay\n const delay =\n typeof retryDelay === 'function'\n ? retryDelay(failureCount, error)\n : retryDelay\n const shouldRetry =\n retry === true ||\n (typeof retry === 'number' && failureCount < retry) ||\n (typeof retry === 'function' && retry(failureCount, error))\n\n if (isRetryCancelled || !shouldRetry) {\n // We are done if the query does not need to be retried\n reject(error)\n return\n }\n\n failureCount++\n\n // Notify on fail\n config.onFail?.(failureCount, error)\n\n // Delay\n sleep(delay)\n // Pause if the document is not visible or when the device is offline\n .then(() => {\n if (shouldPause()) {\n return pause()\n }\n return\n })\n .then(() => {\n if (isRetryCancelled) {\n reject(error)\n } else {\n run()\n }\n })\n })\n }\n\n // Start loop\n if (canFetch(config.networkMode)) {\n run()\n } else {\n pause().then(run)\n }\n\n return {\n promise,\n cancel,\n continue: () => {\n const didContinue = continueFn?.()\n return didContinue ? promise : Promise.resolve()\n },\n cancelRetry,\n continueRetry,\n }\n}\n","'use client'\nimport * as React from 'react'\nimport { shouldThrowError } from './utils'\nimport type {\n DefaultedQueryObserverOptions,\n Query,\n QueryKey,\n QueryObserverResult,\n UseErrorBoundary,\n} from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\n\nexport const ensurePreventErrorBoundaryRetry = <\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n if (options.suspense || options.useErrorBoundary) {\n // Prevent retrying failed query if the error boundary has not been reset yet\n if (!errorResetBoundary.isReset()) {\n options.retryOnMount = false\n }\n }\n}\n\nexport const useClearResetErrorBoundary = (\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n React.useEffect(() => {\n errorResetBoundary.clearReset()\n }, [errorResetBoundary])\n}\n\nexport const getHasError = <\n TData,\n TError,\n TQueryFnData,\n TQueryData,\n TQueryKey extends QueryKey,\n>({\n result,\n errorResetBoundary,\n useErrorBoundary,\n query,\n}: {\n result: QueryObserverResult\n errorResetBoundary: QueryErrorResetBoundaryValue\n useErrorBoundary: UseErrorBoundary<\n TQueryFnData,\n TError,\n TQueryData,\n TQueryKey\n >\n query: Query\n}) => {\n return (\n result.isError &&\n !errorResetBoundary.isReset() &&\n !result.isFetching &&\n shouldThrowError(useErrorBoundary, [result.error, query])\n )\n}\n","import { defaultLogger } from './logger'\nimport { notifyManager } from './notifyManager'\nimport { Removable } from './removable'\nimport { canFetch, createRetryer } from './retryer'\nimport type { MutationMeta, MutationOptions, MutationStatus } from './types'\nimport type { MutationCache } from './mutationCache'\nimport type { MutationObserver } from './mutationObserver'\nimport type { Logger } from './logger'\nimport type { Retryer } from './retryer'\n\n// TYPES\n\ninterface MutationConfig {\n mutationId: number\n mutationCache: MutationCache\n options: MutationOptions\n logger?: Logger\n defaultOptions?: MutationOptions\n state?: MutationState\n meta?: MutationMeta\n}\n\nexport interface MutationState<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n> {\n context: TContext | undefined\n data: TData | undefined\n error: TError | null\n failureCount: number\n failureReason: TError | null\n isPaused: boolean\n status: MutationStatus\n variables: TVariables | undefined\n}\n\ninterface FailedAction {\n type: 'failed'\n failureCount: number\n error: TError | null\n}\n\ninterface LoadingAction {\n type: 'loading'\n variables?: TVariables\n context?: TContext\n}\n\ninterface SuccessAction {\n type: 'success'\n data: TData\n}\n\ninterface ErrorAction {\n type: 'error'\n error: TError\n}\n\ninterface PauseAction {\n type: 'pause'\n}\n\ninterface ContinueAction {\n type: 'continue'\n}\n\ninterface SetStateAction {\n type: 'setState'\n state: MutationState\n}\n\nexport type Action =\n | ContinueAction\n | ErrorAction\n | FailedAction\n | LoadingAction\n | PauseAction\n | SetStateAction\n | SuccessAction\n\n// CLASS\n\nexport class Mutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n> extends Removable {\n state: MutationState\n options!: MutationOptions\n mutationId: number\n\n private observers: MutationObserver[]\n private defaultOptions?: MutationOptions\n private mutationCache: MutationCache\n private logger: Logger\n private retryer?: Retryer\n\n constructor(config: MutationConfig) {\n super()\n\n this.defaultOptions = config.defaultOptions\n this.mutationId = config.mutationId\n this.mutationCache = config.mutationCache\n this.logger = config.logger || defaultLogger\n this.observers = []\n this.state = config.state || getDefaultState()\n\n this.setOptions(config.options)\n this.scheduleGc()\n }\n\n setOptions(\n options?: MutationOptions,\n ): void {\n this.options = { ...this.defaultOptions, ...options }\n\n this.updateCacheTime(this.options.cacheTime)\n }\n\n get meta(): MutationMeta | undefined {\n return this.options.meta\n }\n\n setState(state: MutationState): void {\n this.dispatch({ type: 'setState', state })\n }\n\n addObserver(observer: MutationObserver): void {\n if (!this.observers.includes(observer)) {\n this.observers.push(observer)\n\n // Stop the mutation from being garbage collected\n this.clearGcTimeout()\n\n this.mutationCache.notify({\n type: 'observerAdded',\n mutation: this,\n observer,\n })\n }\n }\n\n removeObserver(observer: MutationObserver): void {\n this.observers = this.observers.filter((x) => x !== observer)\n\n this.scheduleGc()\n\n this.mutationCache.notify({\n type: 'observerRemoved',\n mutation: this,\n observer,\n })\n }\n\n protected optionalRemove() {\n if (!this.observers.length) {\n if (this.state.status === 'loading') {\n this.scheduleGc()\n } else {\n this.mutationCache.remove(this)\n }\n }\n }\n\n continue(): Promise {\n return this.retryer?.continue() ?? this.execute()\n }\n\n async execute(): Promise {\n const executeMutation = () => {\n this.retryer = createRetryer({\n fn: () => {\n if (!this.options.mutationFn) {\n return Promise.reject('No mutationFn found')\n }\n return this.options.mutationFn(this.state.variables!)\n },\n onFail: (failureCount, error) => {\n this.dispatch({ type: 'failed', failureCount, error })\n },\n onPause: () => {\n this.dispatch({ type: 'pause' })\n },\n onContinue: () => {\n this.dispatch({ type: 'continue' })\n },\n retry: this.options.retry ?? 0,\n retryDelay: this.options.retryDelay,\n networkMode: this.options.networkMode,\n })\n\n return this.retryer.promise\n }\n\n const restored = this.state.status === 'loading'\n try {\n if (!restored) {\n this.dispatch({ type: 'loading', variables: this.options.variables! })\n // Notify cache callback\n await this.mutationCache.config.onMutate?.(\n this.state.variables,\n this as Mutation,\n )\n const context = await this.options.onMutate?.(this.state.variables!)\n if (context !== this.state.context) {\n this.dispatch({\n type: 'loading',\n context,\n variables: this.state.variables,\n })\n }\n }\n const data = await executeMutation()\n\n // Notify cache callback\n await this.mutationCache.config.onSuccess?.(\n data,\n this.state.variables,\n this.state.context,\n this as Mutation,\n )\n\n await this.options.onSuccess?.(\n data,\n this.state.variables!,\n this.state.context!,\n )\n\n // Notify cache callback\n await this.mutationCache.config.onSettled?.(\n data,\n null,\n this.state.variables,\n this.state.context,\n this as Mutation,\n )\n\n await this.options.onSettled?.(\n data,\n null,\n this.state.variables!,\n this.state.context,\n )\n\n this.dispatch({ type: 'success', data })\n return data\n } catch (error) {\n try {\n // Notify cache callback\n await this.mutationCache.config.onError?.(\n error,\n this.state.variables,\n this.state.context,\n this as Mutation,\n )\n\n if (process.env.NODE_ENV !== 'production') {\n this.logger.error(error)\n }\n\n await this.options.onError?.(\n error as TError,\n this.state.variables!,\n this.state.context,\n )\n\n // Notify cache callback\n await this.mutationCache.config.onSettled?.(\n undefined,\n error,\n this.state.variables,\n this.state.context,\n this as Mutation,\n )\n\n await this.options.onSettled?.(\n undefined,\n error as TError,\n this.state.variables!,\n this.state.context,\n )\n throw error\n } finally {\n this.dispatch({ type: 'error', error: error as TError })\n }\n }\n }\n\n private dispatch(action: Action): void {\n const reducer = (\n state: MutationState,\n ): MutationState => {\n switch (action.type) {\n case 'failed':\n return {\n ...state,\n failureCount: action.failureCount,\n failureReason: action.error,\n }\n case 'pause':\n return {\n ...state,\n isPaused: true,\n }\n case 'continue':\n return {\n ...state,\n isPaused: false,\n }\n case 'loading':\n return {\n ...state,\n context: action.context,\n data: undefined,\n failureCount: 0,\n failureReason: null,\n error: null,\n isPaused: !canFetch(this.options.networkMode),\n status: 'loading',\n variables: action.variables,\n }\n case 'success':\n return {\n ...state,\n data: action.data,\n failureCount: 0,\n failureReason: null,\n error: null,\n status: 'success',\n isPaused: false,\n }\n case 'error':\n return {\n ...state,\n data: undefined,\n error: action.error,\n failureCount: state.failureCount + 1,\n failureReason: action.error,\n isPaused: false,\n status: 'error',\n }\n case 'setState':\n return {\n ...state,\n ...action.state,\n }\n }\n }\n this.state = reducer(this.state)\n\n notifyManager.batch(() => {\n this.observers.forEach((observer) => {\n observer.onMutationUpdate(action)\n })\n this.mutationCache.notify({\n mutation: this,\n type: 'updated',\n action,\n })\n })\n }\n}\n\nexport function getDefaultState<\n TData,\n TError,\n TVariables,\n TContext,\n>(): MutationState {\n return {\n context: undefined,\n data: undefined,\n error: null,\n failureCount: 0,\n failureReason: null,\n isPaused: false,\n status: 'idle',\n variables: undefined,\n }\n}\n","import type { DefaultedQueryObserverOptions } from '@tanstack/query-core'\nimport type { QueryObserver } from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\nimport type { QueryObserverResult } from '@tanstack/query-core'\nimport type { QueryKey } from '@tanstack/query-core'\n\nexport const ensureStaleTime = (\n defaultedOptions: DefaultedQueryObserverOptions,\n) => {\n if (defaultedOptions.suspense) {\n // Always set stale time when using suspense to prevent\n // fetching again when directly mounting after suspending\n if (typeof defaultedOptions.staleTime !== 'number') {\n defaultedOptions.staleTime = 1000\n }\n }\n}\n\nexport const willFetch = (\n result: QueryObserverResult,\n isRestoring: boolean,\n) => result.isLoading && result.isFetching && !isRestoring\n\nexport const shouldSuspend = (\n defaultedOptions:\n | DefaultedQueryObserverOptions\n | undefined,\n result: QueryObserverResult,\n isRestoring: boolean,\n) => defaultedOptions?.suspense && willFetch(result, isRestoring)\n\nexport const fetchOptimistic = <\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n defaultedOptions: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n observer: QueryObserver,\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) =>\n observer\n .fetchOptimistic(defaultedOptions)\n .then(({ data }) => {\n defaultedOptions.onSuccess?.(data as TData)\n defaultedOptions.onSettled?.(data, null)\n })\n .catch((error) => {\n errorResetBoundary.clearReset()\n defaultedOptions.onError?.(error)\n defaultedOptions.onSettled?.(undefined, error)\n })\n","'use strict';\nvar globalThis = require('../internals/global-this');\nvar DESCRIPTORS = require('../internals/descriptors');\n\n// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe\nvar getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;\n\n// Avoid NodeJS experimental warning\nmodule.exports = function (name) {\n if (!DESCRIPTORS) return globalThis[name];\n var descriptor = getOwnPropertyDescriptor(globalThis, name);\n return descriptor && descriptor.value;\n};\n","'use strict';\nvar Queue = function () {\n this.head = null;\n this.tail = null;\n};\n\nQueue.prototype = {\n add: function (item) {\n var entry = { item: item, next: null };\n var tail = this.tail;\n if (tail) tail.next = entry;\n else this.head = entry;\n this.tail = entry;\n },\n get: function () {\n var entry = this.head;\n if (entry) {\n var next = this.head = entry.next;\n if (next === null) this.tail = null;\n return entry.item;\n }\n }\n};\n\nmodule.exports = Queue;\n","import type { Mutation } from './mutation'\nimport type { Query } from './query'\nimport type {\n FetchStatus,\n MutationFunction,\n MutationKey,\n MutationOptions,\n QueryFunction,\n QueryKey,\n QueryOptions,\n} from './types'\n\n// TYPES\n\nexport interface QueryFilters {\n /**\n * Filter to active queries, inactive queries or all queries\n */\n type?: QueryTypeFilter\n /**\n * Match query key exactly\n */\n exact?: boolean\n /**\n * Include queries matching this predicate function\n */\n predicate?: (query: Query) => boolean\n /**\n * Include queries matching this query key\n */\n queryKey?: QueryKey\n /**\n * Include or exclude stale queries\n */\n stale?: boolean\n /**\n * Include queries matching their fetchStatus\n */\n fetchStatus?: FetchStatus\n}\n\nexport interface MutationFilters {\n /**\n * Match mutation key exactly\n */\n exact?: boolean\n /**\n * Include mutations matching this predicate function\n */\n predicate?: (mutation: Mutation) => boolean\n /**\n * Include mutations matching this mutation key\n */\n mutationKey?: MutationKey\n /**\n * Include or exclude fetching mutations\n */\n fetching?: boolean\n}\n\nexport type DataUpdateFunction = (input: TInput) => TOutput\n\nexport type Updater =\n | TOutput\n | DataUpdateFunction\n\nexport type QueryTypeFilter = 'all' | 'active' | 'inactive'\n\n// UTILS\n\nexport const isServer = typeof window === 'undefined' || 'Deno' in window\n\nexport function noop(): undefined {\n return undefined\n}\n\nexport function functionalUpdate(\n updater: Updater,\n input: TInput,\n): TOutput {\n return typeof updater === 'function'\n ? (updater as DataUpdateFunction)(input)\n : updater\n}\n\nexport function isValidTimeout(value: unknown): value is number {\n return typeof value === 'number' && value >= 0 && value !== Infinity\n}\n\nexport function difference(array1: T[], array2: T[]): T[] {\n return array1.filter((x) => !array2.includes(x))\n}\n\nexport function replaceAt(array: T[], index: number, value: T): T[] {\n const copy = array.slice(0)\n copy[index] = value\n return copy\n}\n\nexport function timeUntilStale(updatedAt: number, staleTime?: number): number {\n return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0)\n}\n\nexport function parseQueryArgs<\n TOptions extends QueryOptions,\n TQueryKey extends QueryKey = QueryKey,\n>(\n arg1: TQueryKey | TOptions,\n arg2?: QueryFunction | TOptions,\n arg3?: TOptions,\n): TOptions {\n if (!isQueryKey(arg1)) {\n return arg1 as TOptions\n }\n\n if (typeof arg2 === 'function') {\n return { ...arg3, queryKey: arg1, queryFn: arg2 } as TOptions\n }\n\n return { ...arg2, queryKey: arg1 } as TOptions\n}\n\nexport function parseMutationArgs<\n TOptions extends MutationOptions,\n>(\n arg1: MutationKey | MutationFunction | TOptions,\n arg2?: MutationFunction | TOptions,\n arg3?: TOptions,\n): TOptions {\n if (isQueryKey(arg1)) {\n if (typeof arg2 === 'function') {\n return { ...arg3, mutationKey: arg1, mutationFn: arg2 } as TOptions\n }\n return { ...arg2, mutationKey: arg1 } as TOptions\n }\n\n if (typeof arg1 === 'function') {\n return { ...arg2, mutationFn: arg1 } as TOptions\n }\n\n return { ...arg1 } as TOptions\n}\n\nexport function parseFilterArgs<\n TFilters extends QueryFilters,\n TOptions = unknown,\n>(\n arg1?: QueryKey | TFilters,\n arg2?: TFilters | TOptions,\n arg3?: TOptions,\n): [TFilters, TOptions | undefined] {\n return (\n isQueryKey(arg1) ? [{ ...arg2, queryKey: arg1 }, arg3] : [arg1 || {}, arg2]\n ) as [TFilters, TOptions]\n}\n\nexport function parseMutationFilterArgs<\n TFilters extends MutationFilters,\n TOptions = unknown,\n>(\n arg1?: QueryKey | TFilters,\n arg2?: TFilters | TOptions,\n arg3?: TOptions,\n): [TFilters, TOptions | undefined] {\n return (\n isQueryKey(arg1)\n ? [{ ...arg2, mutationKey: arg1 }, arg3]\n : [arg1 || {}, arg2]\n ) as [TFilters, TOptions]\n}\n\nexport function matchQuery(\n filters: QueryFilters,\n query: Query,\n): boolean {\n const {\n type = 'all',\n exact,\n fetchStatus,\n predicate,\n queryKey,\n stale,\n } = filters\n\n if (isQueryKey(queryKey)) {\n if (exact) {\n if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {\n return false\n }\n } else if (!partialMatchKey(query.queryKey, queryKey)) {\n return false\n }\n }\n\n if (type !== 'all') {\n const isActive = query.isActive()\n if (type === 'active' && !isActive) {\n return false\n }\n if (type === 'inactive' && isActive) {\n return false\n }\n }\n\n if (typeof stale === 'boolean' && query.isStale() !== stale) {\n return false\n }\n\n if (\n typeof fetchStatus !== 'undefined' &&\n fetchStatus !== query.state.fetchStatus\n ) {\n return false\n }\n\n if (predicate && !predicate(query)) {\n return false\n }\n\n return true\n}\n\nexport function matchMutation(\n filters: MutationFilters,\n mutation: Mutation,\n): boolean {\n const { exact, fetching, predicate, mutationKey } = filters\n if (isQueryKey(mutationKey)) {\n if (!mutation.options.mutationKey) {\n return false\n }\n if (exact) {\n if (\n hashQueryKey(mutation.options.mutationKey) !== hashQueryKey(mutationKey)\n ) {\n return false\n }\n } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {\n return false\n }\n }\n\n if (\n typeof fetching === 'boolean' &&\n (mutation.state.status === 'loading') !== fetching\n ) {\n return false\n }\n\n if (predicate && !predicate(mutation)) {\n return false\n }\n\n return true\n}\n\nexport function hashQueryKeyByOptions(\n queryKey: TQueryKey,\n options?: QueryOptions,\n): string {\n const hashFn = options?.queryKeyHashFn || hashQueryKey\n return hashFn(queryKey)\n}\n\n/**\n * Default query keys hash function.\n * Hashes the value into a stable hash.\n */\nexport function hashQueryKey(queryKey: QueryKey): string {\n return JSON.stringify(queryKey, (_, val) =>\n isPlainObject(val)\n ? Object.keys(val)\n .sort()\n .reduce((result, key) => {\n result[key] = val[key]\n return result\n }, {} as any)\n : val,\n )\n}\n\n/**\n * Checks if key `b` partially matches with key `a`.\n */\nexport function partialMatchKey(a: QueryKey, b: QueryKey): boolean {\n return partialDeepEqual(a, b)\n}\n\n/**\n * Checks if `b` partially matches with `a`.\n */\nexport function partialDeepEqual(a: any, b: any): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (a && b && typeof a === 'object' && typeof b === 'object') {\n return !Object.keys(b).some((key) => !partialDeepEqual(a[key], b[key]))\n }\n\n return false\n}\n\n/**\n * This function returns `a` if `b` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between JSON values for example.\n */\nexport function replaceEqualDeep(a: unknown, b: T): T\nexport function replaceEqualDeep(a: any, b: any): any {\n if (a === b) {\n return a\n }\n\n const array = isPlainArray(a) && isPlainArray(b)\n\n if (array || (isPlainObject(a) && isPlainObject(b))) {\n const aSize = array ? a.length : Object.keys(a).length\n const bItems = array ? b : Object.keys(b)\n const bSize = bItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < bSize; i++) {\n const key = array ? i : bItems[i]\n copy[key] = replaceEqualDeep(a[key], b[key])\n if (copy[key] === a[key]) {\n equalItems++\n }\n }\n\n return aSize === bSize && equalItems === aSize ? a : copy\n }\n\n return b\n}\n\n/**\n * Shallow compare objects. Only works with objects that always have the same properties.\n */\nexport function shallowEqualObjects(a: T, b: T): boolean {\n if ((a && !b) || (b && !a)) {\n return false\n }\n\n for (const key in a) {\n if (a[key] !== b[key]) {\n return false\n }\n }\n\n return true\n}\n\nexport function isPlainArray(value: unknown) {\n return Array.isArray(value) && value.length === Object.keys(value).length\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function isPlainObject(o: any): o is Object {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any): boolean {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n\nexport function isQueryKey(value: unknown): value is QueryKey {\n return Array.isArray(value)\n}\n\nexport function isError(value: any): value is Error {\n return value instanceof Error\n}\n\nexport function sleep(timeout: number): Promise {\n return new Promise((resolve) => {\n setTimeout(resolve, timeout)\n })\n}\n\n/**\n * Schedules a microtask.\n * This can be useful to schedule state updates after rendering.\n */\nexport function scheduleMicrotask(callback: () => void) {\n sleep(0).then(callback)\n}\n\nexport function getAbortController(): AbortController | undefined {\n if (typeof AbortController === 'function') {\n return new AbortController()\n }\n return\n}\n\nexport function replaceData<\n TData,\n TOptions extends QueryOptions,\n>(prevData: TData | undefined, data: TData, options: TOptions): TData {\n // Use prev data if an isDataEqual function is defined and returns `true`\n if (options.isDataEqual?.(prevData, data)) {\n return prevData as TData\n } else if (typeof options.structuralSharing === 'function') {\n return options.structuralSharing(prevData, data)\n } else if (options.structuralSharing !== false) {\n // Structurally share data between prev and new data if needed\n return replaceEqualDeep(prevData, data)\n }\n return data\n}\n","'use strict';\nvar $ = require('../internals/export');\nvar newPromiseCapabilityModule = require('../internals/new-promise-capability');\nvar FORCED_PROMISE_CONSTRUCTOR = require('../internals/promise-constructor-detection').CONSTRUCTOR;\n\n// `Promise.reject` method\n// https://tc39.es/ecma262/#sec-promise.reject\n$({ target: 'Promise', stat: true, forced: FORCED_PROMISE_CONSTRUCTOR }, {\n reject: function reject(r) {\n var capability = newPromiseCapabilityModule.f(this);\n var capabilityReject = capability.reject;\n capabilityReject(r);\n return capability.promise;\n }\n});\n","'use strict';\nvar globalThis = require('../internals/global-this');\n\nmodule.exports = globalThis.Promise;\n","'use strict';\nvar isObject = require('../internals/is-object');\n\nmodule.exports = function (argument) {\n return isObject(argument) || argument === null;\n};\n","'use strict';\nvar isPossiblePrototype = require('../internals/is-possible-prototype');\n\nvar $String = String;\nvar $TypeError = TypeError;\n\nmodule.exports = function (argument) {\n if (isPossiblePrototype(argument)) return argument;\n throw new $TypeError(\"Can't set \" + $String(argument) + ' as a prototype');\n};\n","import {\n isServer,\n isValidTimeout,\n noop,\n replaceData,\n shallowEqualObjects,\n timeUntilStale,\n} from './utils'\nimport { notifyManager } from './notifyManager'\nimport { focusManager } from './focusManager'\nimport { Subscribable } from './subscribable'\nimport { canFetch, isCancelledError } from './retryer'\nimport type {\n PlaceholderDataFunction,\n QueryKey,\n QueryObserverBaseResult,\n QueryObserverOptions,\n QueryObserverResult,\n QueryOptions,\n RefetchOptions,\n} from './types'\nimport type { Action, FetchOptions, Query, QueryState } from './query'\nimport type { QueryClient } from './queryClient'\nimport type { DefaultedQueryObserverOptions, RefetchPageFilters } from './types'\n\ntype QueryObserverListener = (\n result: QueryObserverResult,\n) => void\n\nexport interface NotifyOptions {\n cache?: boolean\n listeners?: boolean\n onError?: boolean\n onSuccess?: boolean\n}\n\nexport interface ObserverFetchOptions extends FetchOptions {\n throwOnError?: boolean\n}\n\nexport class QueryObserver<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends Subscribable> {\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n\n private client: QueryClient\n private currentQuery!: Query\n private currentQueryInitialState!: QueryState\n private currentResult!: QueryObserverResult\n private currentResultState?: QueryState\n private currentResultOptions?: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n private previousQueryResult?: QueryObserverResult\n private selectError: TError | null\n private selectFn?: (data: TQueryData) => TData\n private selectResult?: TData\n private staleTimeoutId?: ReturnType\n private refetchIntervalId?: ReturnType\n private currentRefetchInterval?: number | false\n private trackedProps!: Set\n\n constructor(\n client: QueryClient,\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ) {\n super()\n\n this.client = client\n this.options = options\n this.trackedProps = new Set()\n this.selectError = null\n this.bindMethods()\n this.setOptions(options)\n }\n\n protected bindMethods(): void {\n this.remove = this.remove.bind(this)\n this.refetch = this.refetch.bind(this)\n }\n\n protected onSubscribe(): void {\n if (this.listeners.size === 1) {\n this.currentQuery.addObserver(this)\n\n if (shouldFetchOnMount(this.currentQuery, this.options)) {\n this.executeFetch()\n }\n\n this.updateTimers()\n }\n }\n\n protected onUnsubscribe(): void {\n if (!this.hasListeners()) {\n this.destroy()\n }\n }\n\n shouldFetchOnReconnect(): boolean {\n return shouldFetchOn(\n this.currentQuery,\n this.options,\n this.options.refetchOnReconnect,\n )\n }\n\n shouldFetchOnWindowFocus(): boolean {\n return shouldFetchOn(\n this.currentQuery,\n this.options,\n this.options.refetchOnWindowFocus,\n )\n }\n\n destroy(): void {\n this.listeners = new Set()\n this.clearStaleTimeout()\n this.clearRefetchInterval()\n this.currentQuery.removeObserver(this)\n }\n\n setOptions(\n options?: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n notifyOptions?: NotifyOptions,\n ): void {\n const prevOptions = this.options\n const prevQuery = this.currentQuery\n\n this.options = this.client.defaultQueryOptions(options)\n\n if (\n process.env.NODE_ENV !== 'production' &&\n typeof options?.isDataEqual !== 'undefined'\n ) {\n this.client\n .getLogger()\n .error(\n `The isDataEqual option has been deprecated and will be removed in the next major version. You can achieve the same functionality by passing a function as the structuralSharing option`,\n )\n }\n\n if (!shallowEqualObjects(prevOptions, this.options)) {\n this.client.getQueryCache().notify({\n type: 'observerOptionsUpdated',\n query: this.currentQuery,\n observer: this,\n })\n }\n\n if (\n typeof this.options.enabled !== 'undefined' &&\n typeof this.options.enabled !== 'boolean'\n ) {\n throw new Error('Expected enabled to be a boolean')\n }\n\n // Keep previous query key if the user does not supply one\n if (!this.options.queryKey) {\n this.options.queryKey = prevOptions.queryKey\n }\n\n this.updateQuery()\n\n const mounted = this.hasListeners()\n\n // Fetch if there are subscribers\n if (\n mounted &&\n shouldFetchOptionally(\n this.currentQuery,\n prevQuery,\n this.options,\n prevOptions,\n )\n ) {\n this.executeFetch()\n }\n\n // Update result\n this.updateResult(notifyOptions)\n\n // Update stale interval if needed\n if (\n mounted &&\n (this.currentQuery !== prevQuery ||\n this.options.enabled !== prevOptions.enabled ||\n this.options.staleTime !== prevOptions.staleTime)\n ) {\n this.updateStaleTimeout()\n }\n\n const nextRefetchInterval = this.computeRefetchInterval()\n\n // Update refetch interval if needed\n if (\n mounted &&\n (this.currentQuery !== prevQuery ||\n this.options.enabled !== prevOptions.enabled ||\n nextRefetchInterval !== this.currentRefetchInterval)\n ) {\n this.updateRefetchInterval(nextRefetchInterval)\n }\n }\n\n getOptimisticResult(\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): QueryObserverResult {\n const query = this.client.getQueryCache().build(this.client, options)\n\n const result = this.createResult(query, options)\n\n if (shouldAssignObserverCurrentProperties(this, result, options)) {\n // this assigns the optimistic result to the current Observer\n // because if the query function changes, useQuery will be performing\n // an effect where it would fetch again.\n // When the fetch finishes, we perform a deep data cloning in order\n // to reuse objects references. This deep data clone is performed against\n // the `observer.currentResult.data` property\n // When QueryKey changes, we refresh the query and get new `optimistic`\n // result, while we leave the `observer.currentResult`, so when new data\n // arrives, it finds the old `observer.currentResult` which is related\n // to the old QueryKey. Which means that currentResult and selectData are\n // out of sync already.\n // To solve this, we move the cursor of the currentResult everytime\n // an observer reads an optimistic value.\n\n // When keeping the previous data, the result doesn't change until new\n // data arrives.\n this.currentResult = result\n this.currentResultOptions = this.options\n this.currentResultState = this.currentQuery.state\n }\n return result\n }\n\n getCurrentResult(): QueryObserverResult {\n return this.currentResult\n }\n\n trackResult(\n result: QueryObserverResult,\n ): QueryObserverResult {\n const trackedResult = {} as QueryObserverResult\n\n Object.keys(result).forEach((key) => {\n Object.defineProperty(trackedResult, key, {\n configurable: false,\n enumerable: true,\n get: () => {\n this.trackedProps.add(key as keyof QueryObserverResult)\n return result[key as keyof QueryObserverResult]\n },\n })\n })\n\n return trackedResult\n }\n\n getCurrentQuery(): Query {\n return this.currentQuery\n }\n\n remove(): void {\n this.client.getQueryCache().remove(this.currentQuery)\n }\n\n refetch({\n refetchPage,\n ...options\n }: RefetchOptions & RefetchPageFilters = {}): Promise<\n QueryObserverResult\n > {\n return this.fetch({\n ...options,\n meta: { refetchPage },\n })\n }\n\n fetchOptimistic(\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): Promise> {\n const defaultedOptions = this.client.defaultQueryOptions(options)\n\n const query = this.client\n .getQueryCache()\n .build(this.client, defaultedOptions)\n query.isFetchingOptimistic = true\n\n return query.fetch().then(() => this.createResult(query, defaultedOptions))\n }\n\n protected fetch(\n fetchOptions: ObserverFetchOptions,\n ): Promise> {\n return this.executeFetch({\n ...fetchOptions,\n cancelRefetch: fetchOptions.cancelRefetch ?? true,\n }).then(() => {\n this.updateResult()\n return this.currentResult\n })\n }\n\n private executeFetch(\n fetchOptions?: ObserverFetchOptions,\n ): Promise {\n // Make sure we reference the latest query as the current one might have been removed\n this.updateQuery()\n\n // Fetch\n let promise: Promise = this.currentQuery.fetch(\n this.options as QueryOptions,\n fetchOptions,\n )\n\n if (!fetchOptions?.throwOnError) {\n promise = promise.catch(noop)\n }\n\n return promise\n }\n\n private updateStaleTimeout(): void {\n this.clearStaleTimeout()\n\n if (\n isServer ||\n this.currentResult.isStale ||\n !isValidTimeout(this.options.staleTime)\n ) {\n return\n }\n\n const time = timeUntilStale(\n this.currentResult.dataUpdatedAt,\n this.options.staleTime,\n )\n\n // The timeout is sometimes triggered 1 ms before the stale time expiration.\n // To mitigate this issue we always add 1 ms to the timeout.\n const timeout = time + 1\n\n this.staleTimeoutId = setTimeout(() => {\n if (!this.currentResult.isStale) {\n this.updateResult()\n }\n }, timeout)\n }\n\n private computeRefetchInterval() {\n return typeof this.options.refetchInterval === 'function'\n ? this.options.refetchInterval(this.currentResult.data, this.currentQuery)\n : this.options.refetchInterval ?? false\n }\n\n private updateRefetchInterval(nextInterval: number | false): void {\n this.clearRefetchInterval()\n\n this.currentRefetchInterval = nextInterval\n\n if (\n isServer ||\n this.options.enabled === false ||\n !isValidTimeout(this.currentRefetchInterval) ||\n this.currentRefetchInterval === 0\n ) {\n return\n }\n\n this.refetchIntervalId = setInterval(() => {\n if (\n this.options.refetchIntervalInBackground ||\n focusManager.isFocused()\n ) {\n this.executeFetch()\n }\n }, this.currentRefetchInterval)\n }\n\n private updateTimers(): void {\n this.updateStaleTimeout()\n this.updateRefetchInterval(this.computeRefetchInterval())\n }\n\n private clearStaleTimeout(): void {\n if (this.staleTimeoutId) {\n clearTimeout(this.staleTimeoutId)\n this.staleTimeoutId = undefined\n }\n }\n\n private clearRefetchInterval(): void {\n if (this.refetchIntervalId) {\n clearInterval(this.refetchIntervalId)\n this.refetchIntervalId = undefined\n }\n }\n\n protected createResult(\n query: Query,\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): QueryObserverResult {\n const prevQuery = this.currentQuery\n const prevOptions = this.options\n const prevResult = this.currentResult as\n | QueryObserverResult\n | undefined\n const prevResultState = this.currentResultState\n const prevResultOptions = this.currentResultOptions\n const queryChange = query !== prevQuery\n const queryInitialState = queryChange\n ? query.state\n : this.currentQueryInitialState\n const prevQueryResult = queryChange\n ? this.currentResult\n : this.previousQueryResult\n\n const { state } = query\n let { dataUpdatedAt, error, errorUpdatedAt, fetchStatus, status } = state\n let isPreviousData = false\n let isPlaceholderData = false\n let data: TData | undefined\n\n // Optimistically set result in fetching state if needed\n if (options._optimisticResults) {\n const mounted = this.hasListeners()\n\n const fetchOnMount = !mounted && shouldFetchOnMount(query, options)\n\n const fetchOptionally =\n mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions)\n\n if (fetchOnMount || fetchOptionally) {\n fetchStatus = canFetch(query.options.networkMode)\n ? 'fetching'\n : 'paused'\n if (!dataUpdatedAt) {\n status = 'loading'\n }\n }\n if (options._optimisticResults === 'isRestoring') {\n fetchStatus = 'idle'\n }\n }\n\n // Keep previous data if needed\n if (\n options.keepPreviousData &&\n !state.dataUpdatedAt &&\n prevQueryResult?.isSuccess &&\n status !== 'error'\n ) {\n data = prevQueryResult.data\n dataUpdatedAt = prevQueryResult.dataUpdatedAt\n status = prevQueryResult.status\n isPreviousData = true\n }\n // Select data if needed\n else if (options.select && typeof state.data !== 'undefined') {\n // Memoize select result\n if (\n prevResult &&\n state.data === prevResultState?.data &&\n options.select === this.selectFn\n ) {\n data = this.selectResult\n } else {\n try {\n this.selectFn = options.select\n data = options.select(state.data)\n data = replaceData(prevResult?.data, data, options)\n this.selectResult = data\n this.selectError = null\n } catch (selectError) {\n if (process.env.NODE_ENV !== 'production') {\n this.client.getLogger().error(selectError)\n }\n this.selectError = selectError as TError\n }\n }\n }\n // Use query data\n else {\n data = state.data as unknown as TData\n }\n\n // Show placeholder data if needed\n if (\n typeof options.placeholderData !== 'undefined' &&\n typeof data === 'undefined' &&\n status === 'loading'\n ) {\n let placeholderData\n\n // Memoize placeholder data\n if (\n prevResult?.isPlaceholderData &&\n options.placeholderData === prevResultOptions?.placeholderData\n ) {\n placeholderData = prevResult.data\n } else {\n placeholderData =\n typeof options.placeholderData === 'function'\n ? (options.placeholderData as PlaceholderDataFunction)()\n : options.placeholderData\n if (options.select && typeof placeholderData !== 'undefined') {\n try {\n placeholderData = options.select(placeholderData)\n this.selectError = null\n } catch (selectError) {\n if (process.env.NODE_ENV !== 'production') {\n this.client.getLogger().error(selectError)\n }\n this.selectError = selectError as TError\n }\n }\n }\n\n if (typeof placeholderData !== 'undefined') {\n status = 'success'\n data = replaceData(prevResult?.data, placeholderData, options) as TData\n isPlaceholderData = true\n }\n }\n\n if (this.selectError) {\n error = this.selectError as any\n data = this.selectResult\n errorUpdatedAt = Date.now()\n status = 'error'\n }\n\n const isFetching = fetchStatus === 'fetching'\n const isLoading = status === 'loading'\n const isError = status === 'error'\n\n const result: QueryObserverBaseResult = {\n status,\n fetchStatus,\n isLoading,\n isSuccess: status === 'success',\n isError,\n isInitialLoading: isLoading && isFetching,\n data,\n dataUpdatedAt,\n error,\n errorUpdatedAt,\n failureCount: state.fetchFailureCount,\n failureReason: state.fetchFailureReason,\n errorUpdateCount: state.errorUpdateCount,\n isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,\n isFetchedAfterMount:\n state.dataUpdateCount > queryInitialState.dataUpdateCount ||\n state.errorUpdateCount > queryInitialState.errorUpdateCount,\n isFetching,\n isRefetching: isFetching && !isLoading,\n isLoadingError: isError && state.dataUpdatedAt === 0,\n isPaused: fetchStatus === 'paused',\n isPlaceholderData,\n isPreviousData,\n isRefetchError: isError && state.dataUpdatedAt !== 0,\n isStale: isStale(query, options),\n refetch: this.refetch,\n remove: this.remove,\n }\n\n return result as QueryObserverResult\n }\n\n updateResult(notifyOptions?: NotifyOptions): void {\n const prevResult = this.currentResult as\n | QueryObserverResult\n | undefined\n\n const nextResult = this.createResult(this.currentQuery, this.options)\n this.currentResultState = this.currentQuery.state\n this.currentResultOptions = this.options\n\n // Only notify and update result if something has changed\n if (shallowEqualObjects(nextResult, prevResult)) {\n return\n }\n\n this.currentResult = nextResult\n\n // Determine which callbacks to trigger\n const defaultNotifyOptions: NotifyOptions = { cache: true }\n\n const shouldNotifyListeners = (): boolean => {\n if (!prevResult) {\n return true\n }\n\n const { notifyOnChangeProps } = this.options\n const notifyOnChangePropsValue =\n typeof notifyOnChangeProps === 'function'\n ? notifyOnChangeProps()\n : notifyOnChangeProps\n\n if (\n notifyOnChangePropsValue === 'all' ||\n (!notifyOnChangePropsValue && !this.trackedProps.size)\n ) {\n return true\n }\n\n const includedProps = new Set(\n notifyOnChangePropsValue ?? this.trackedProps,\n )\n\n if (this.options.useErrorBoundary) {\n includedProps.add('error')\n }\n\n return Object.keys(this.currentResult).some((key) => {\n const typedKey = key as keyof QueryObserverResult\n const changed = this.currentResult[typedKey] !== prevResult[typedKey]\n return changed && includedProps.has(typedKey)\n })\n }\n\n if (notifyOptions?.listeners !== false && shouldNotifyListeners()) {\n defaultNotifyOptions.listeners = true\n }\n\n this.notify({ ...defaultNotifyOptions, ...notifyOptions })\n }\n\n private updateQuery(): void {\n const query = this.client.getQueryCache().build(this.client, this.options)\n\n if (query === this.currentQuery) {\n return\n }\n\n const prevQuery = this.currentQuery as\n | Query\n | undefined\n this.currentQuery = query\n this.currentQueryInitialState = query.state\n this.previousQueryResult = this.currentResult\n\n if (this.hasListeners()) {\n prevQuery?.removeObserver(this)\n query.addObserver(this)\n }\n }\n\n onQueryUpdate(action: Action): void {\n const notifyOptions: NotifyOptions = {}\n\n if (action.type === 'success') {\n notifyOptions.onSuccess = !action.manual\n } else if (action.type === 'error' && !isCancelledError(action.error)) {\n notifyOptions.onError = true\n }\n\n this.updateResult(notifyOptions)\n\n if (this.hasListeners()) {\n this.updateTimers()\n }\n }\n\n private notify(notifyOptions: NotifyOptions): void {\n notifyManager.batch(() => {\n // First trigger the configuration callbacks\n if (notifyOptions.onSuccess) {\n this.options.onSuccess?.(this.currentResult.data!)\n this.options.onSettled?.(this.currentResult.data!, null)\n } else if (notifyOptions.onError) {\n this.options.onError?.(this.currentResult.error!)\n this.options.onSettled?.(undefined, this.currentResult.error!)\n }\n\n // Then trigger the listeners\n if (notifyOptions.listeners) {\n this.listeners.forEach(({ listener }) => {\n listener(this.currentResult)\n })\n }\n\n // Then the cache listeners\n if (notifyOptions.cache) {\n this.client.getQueryCache().notify({\n query: this.currentQuery,\n type: 'observerResultsUpdated',\n })\n }\n })\n }\n}\n\nfunction shouldLoadOnMount(\n query: Query,\n options: QueryObserverOptions,\n): boolean {\n return (\n options.enabled !== false &&\n !query.state.dataUpdatedAt &&\n !(query.state.status === 'error' && options.retryOnMount === false)\n )\n}\n\nfunction shouldFetchOnMount(\n query: Query,\n options: QueryObserverOptions,\n): boolean {\n return (\n shouldLoadOnMount(query, options) ||\n (query.state.dataUpdatedAt > 0 &&\n shouldFetchOn(query, options, options.refetchOnMount))\n )\n}\n\nfunction shouldFetchOn(\n query: Query,\n options: QueryObserverOptions,\n field: typeof options['refetchOnMount'] &\n typeof options['refetchOnWindowFocus'] &\n typeof options['refetchOnReconnect'],\n) {\n if (options.enabled !== false) {\n const value = typeof field === 'function' ? field(query) : field\n\n return value === 'always' || (value !== false && isStale(query, options))\n }\n return false\n}\n\nfunction shouldFetchOptionally(\n query: Query,\n prevQuery: Query,\n options: QueryObserverOptions,\n prevOptions: QueryObserverOptions,\n): boolean {\n return (\n options.enabled !== false &&\n (query !== prevQuery || prevOptions.enabled === false) &&\n (!options.suspense || query.state.status !== 'error') &&\n isStale(query, options)\n )\n}\n\nfunction isStale(\n query: Query,\n options: QueryObserverOptions,\n): boolean {\n return query.isStaleByTime(options.staleTime)\n}\n\n// this function would decide if we will update the observer's 'current'\n// properties after an optimistic reading via getOptimisticResult\nfunction shouldAssignObserverCurrentProperties<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n observer: QueryObserver,\n optimisticResult: QueryObserverResult,\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n) {\n // it is important to keep this condition like this for three reasons:\n // 1. It will get removed in the v5\n // 2. it reads: don't update the properties if we want to keep the previous\n // data.\n // 3. The opposite condition (!options.keepPreviousData) would fallthrough\n // and will result in a bad decision\n if (options.keepPreviousData) {\n return false\n }\n\n // this means we want to put some placeholder data when pending and queryKey\n // changed.\n if (options.placeholderData !== undefined) {\n // re-assign properties only if current data is placeholder data\n // which means that data did not arrive yet, so, if there is some cached data\n // we need to \"prepare\" to receive it\n return optimisticResult.isPlaceholderData\n }\n\n // if the newly created result isn't what the observer is holding as current,\n // then we'll need to update the properties as well\n if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) {\n return true\n }\n\n // basically, just keep previous properties if nothing changed\n return false\n}\n","type Listener = () => void\n\nexport class Subscribable {\n protected listeners: Set<{ listener: TListener }>\n\n constructor() {\n this.listeners = new Set()\n this.subscribe = this.subscribe.bind(this)\n }\n\n subscribe(listener: TListener): () => void {\n const identity = { listener }\n this.listeners.add(identity)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(identity)\n this.onUnsubscribe()\n }\n }\n\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n protected onSubscribe(): void {\n // Do nothing\n }\n\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n","'use strict';\nvar wellKnownSymbol = require('../internals/well-known-symbol');\n\nvar ITERATOR = wellKnownSymbol('iterator');\nvar SAFE_CLOSING = false;\n\ntry {\n var called = 0;\n var iteratorWithReturn = {\n next: function () {\n return { done: !!called++ };\n },\n 'return': function () {\n SAFE_CLOSING = true;\n }\n };\n iteratorWithReturn[ITERATOR] = function () {\n return this;\n };\n // eslint-disable-next-line es/no-array-from, no-throw-literal -- required for testing\n Array.from(iteratorWithReturn, function () { throw 2; });\n} catch (error) { /* empty */ }\n\nmodule.exports = function (exec, SKIP_CLOSING) {\n try {\n if (!SKIP_CLOSING && !SAFE_CLOSING) return false;\n } catch (error) { return false; } // workaround of old WebKit + `eval` bug\n var ITERATION_SUPPORT = false;\n try {\n var object = {};\n object[ITERATOR] = function () {\n return {\n next: function () {\n return { done: ITERATION_SUPPORT = true };\n }\n };\n };\n exec(object);\n } catch (error) { /* empty */ }\n return ITERATION_SUPPORT;\n};\n","import {\n functionalUpdate,\n hashQueryKey,\n hashQueryKeyByOptions,\n noop,\n parseFilterArgs,\n parseQueryArgs,\n partialMatchKey,\n} from './utils'\nimport { QueryCache } from './queryCache'\nimport { MutationCache } from './mutationCache'\nimport { focusManager } from './focusManager'\nimport { onlineManager } from './onlineManager'\nimport { notifyManager } from './notifyManager'\nimport { infiniteQueryBehavior } from './infiniteQueryBehavior'\nimport { defaultLogger } from './logger'\nimport type { CancelOptions, DefaultedQueryObserverOptions } from './types'\nimport type { Logger } from './logger'\nimport type { QueryState } from './query'\nimport type {\n DefaultOptions,\n FetchInfiniteQueryOptions,\n FetchQueryOptions,\n InfiniteData,\n InvalidateOptions,\n InvalidateQueryFilters,\n MutationKey,\n MutationObserverOptions,\n MutationOptions,\n QueryClientConfig,\n QueryFunction,\n QueryKey,\n QueryObserverOptions,\n QueryOptions,\n RefetchOptions,\n RefetchQueryFilters,\n ResetOptions,\n ResetQueryFilters,\n SetDataOptions,\n WithRequired,\n} from './types'\nimport type { MutationFilters, QueryFilters, Updater } from './utils'\n\n// TYPES\n\ninterface QueryDefaults {\n queryKey: QueryKey\n defaultOptions: QueryOptions\n}\n\ninterface MutationDefaults {\n mutationKey: MutationKey\n defaultOptions: MutationOptions\n}\n\n// CLASS\n\nexport class QueryClient {\n private queryCache: QueryCache\n private mutationCache: MutationCache\n private logger: Logger\n private defaultOptions: DefaultOptions\n private queryDefaults: QueryDefaults[]\n private mutationDefaults: MutationDefaults[]\n private mountCount: number\n private unsubscribeFocus?: () => void\n private unsubscribeOnline?: () => void\n\n constructor(config: QueryClientConfig = {}) {\n this.queryCache = config.queryCache || new QueryCache()\n this.mutationCache = config.mutationCache || new MutationCache()\n this.logger = config.logger || defaultLogger\n this.defaultOptions = config.defaultOptions || {}\n this.queryDefaults = []\n this.mutationDefaults = []\n this.mountCount = 0\n\n if (process.env.NODE_ENV !== 'production' && config.logger) {\n this.logger.error(\n `Passing a custom logger has been deprecated and will be removed in the next major version.`,\n )\n }\n }\n\n mount(): void {\n this.mountCount++\n if (this.mountCount !== 1) return\n\n this.unsubscribeFocus = focusManager.subscribe(() => {\n if (focusManager.isFocused()) {\n this.resumePausedMutations()\n this.queryCache.onFocus()\n }\n })\n this.unsubscribeOnline = onlineManager.subscribe(() => {\n if (onlineManager.isOnline()) {\n this.resumePausedMutations()\n this.queryCache.onOnline()\n }\n })\n }\n\n unmount(): void {\n this.mountCount--\n if (this.mountCount !== 0) return\n\n this.unsubscribeFocus?.()\n this.unsubscribeFocus = undefined\n\n this.unsubscribeOnline?.()\n this.unsubscribeOnline = undefined\n }\n\n isFetching(filters?: QueryFilters): number\n isFetching(queryKey?: QueryKey, filters?: QueryFilters): number\n isFetching(arg1?: QueryKey | QueryFilters, arg2?: QueryFilters): number {\n const [filters] = parseFilterArgs(arg1, arg2)\n filters.fetchStatus = 'fetching'\n return this.queryCache.findAll(filters).length\n }\n\n isMutating(filters?: MutationFilters): number {\n return this.mutationCache.findAll({ ...filters, fetching: true }).length\n }\n\n getQueryData(\n queryKey: QueryKey,\n filters?: QueryFilters,\n ): TQueryFnData | undefined {\n return this.queryCache.find(queryKey, filters)?.state.data\n }\n\n ensureQueryData<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: WithRequired<\n FetchQueryOptions,\n 'queryKey'\n >,\n ): Promise\n ensureQueryData<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryKey: TQueryKey,\n options?: Omit<\n FetchQueryOptions,\n 'queryKey'\n >,\n ): Promise\n ensureQueryData<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryKey: TQueryKey,\n queryFn: QueryFunction,\n options?: Omit<\n FetchQueryOptions,\n 'queryKey' | 'queryFn'\n >,\n ): Promise\n ensureQueryData<\n TQueryFnData,\n TError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n arg1:\n | TQueryKey\n | WithRequired<\n FetchQueryOptions,\n 'queryKey'\n >,\n arg2?:\n | QueryFunction\n | FetchQueryOptions,\n arg3?: FetchQueryOptions,\n ): Promise {\n const parsedOptions = parseQueryArgs(arg1, arg2, arg3)\n const cachedData = this.getQueryData(parsedOptions.queryKey!)\n\n return cachedData\n ? Promise.resolve(cachedData)\n : this.fetchQuery(parsedOptions)\n }\n\n getQueriesData(\n queryKey: QueryKey,\n ): [QueryKey, TQueryFnData | undefined][]\n getQueriesData(\n filters: QueryFilters,\n ): [QueryKey, TQueryFnData | undefined][]\n getQueriesData(\n queryKeyOrFilters: QueryKey | QueryFilters,\n ): [QueryKey, TQueryFnData | undefined][] {\n return this.getQueryCache()\n .findAll(queryKeyOrFilters)\n .map(({ queryKey, state }) => {\n const data = state.data as TQueryFnData | undefined\n return [queryKey, data]\n })\n }\n\n setQueryData(\n queryKey: QueryKey,\n updater: Updater,\n options?: SetDataOptions,\n ): TQueryFnData | undefined {\n const query = this.queryCache.find(queryKey)\n const prevData = query?.state.data\n const data = functionalUpdate(updater, prevData)\n\n if (typeof data === 'undefined') {\n return undefined\n }\n\n const parsedOptions = parseQueryArgs(queryKey)\n const defaultedOptions = this.defaultQueryOptions(parsedOptions)\n return this.queryCache\n .build(this, defaultedOptions)\n .setData(data, { ...options, manual: true })\n }\n\n setQueriesData(\n queryKey: QueryKey,\n updater: Updater,\n options?: SetDataOptions,\n ): [QueryKey, TQueryFnData | undefined][]\n\n setQueriesData(\n filters: QueryFilters,\n updater: Updater,\n options?: SetDataOptions,\n ): [QueryKey, TQueryFnData | undefined][]\n\n setQueriesData(\n queryKeyOrFilters: QueryKey | QueryFilters,\n updater: Updater,\n options?: SetDataOptions,\n ): [QueryKey, TQueryFnData | undefined][] {\n return notifyManager.batch(() =>\n this.getQueryCache()\n .findAll(queryKeyOrFilters)\n .map(({ queryKey }) => [\n queryKey,\n this.setQueryData(queryKey, updater, options),\n ]),\n )\n }\n\n getQueryState(\n queryKey: QueryKey,\n filters?: QueryFilters,\n ): QueryState | undefined {\n return this.queryCache.find(queryKey, filters)?.state\n }\n\n removeQueries(filters?: QueryFilters): void\n removeQueries(queryKey?: QueryKey, filters?: QueryFilters): void\n removeQueries(arg1?: QueryKey | QueryFilters, arg2?: QueryFilters): void {\n const [filters] = parseFilterArgs(arg1, arg2)\n const queryCache = this.queryCache\n notifyManager.batch(() => {\n queryCache.findAll(filters).forEach((query) => {\n queryCache.remove(query)\n })\n })\n }\n\n resetQueries(\n filters?: ResetQueryFilters,\n options?: ResetOptions,\n ): Promise\n resetQueries(\n queryKey?: QueryKey,\n filters?: ResetQueryFilters,\n options?: ResetOptions,\n ): Promise\n resetQueries(\n arg1?: QueryKey | ResetQueryFilters,\n arg2?: ResetQueryFilters | ResetOptions,\n arg3?: ResetOptions,\n ): Promise {\n const [filters, options] = parseFilterArgs(arg1, arg2, arg3)\n const queryCache = this.queryCache\n\n const refetchFilters: RefetchQueryFilters = {\n type: 'active',\n ...filters,\n }\n\n return notifyManager.batch(() => {\n queryCache.findAll(filters).forEach((query) => {\n query.reset()\n })\n return this.refetchQueries(refetchFilters, options)\n })\n }\n\n cancelQueries(filters?: QueryFilters, options?: CancelOptions): Promise\n cancelQueries(\n queryKey?: QueryKey,\n filters?: QueryFilters,\n options?: CancelOptions,\n ): Promise\n cancelQueries(\n arg1?: QueryKey | QueryFilters,\n arg2?: QueryFilters | CancelOptions,\n arg3?: CancelOptions,\n ): Promise {\n const [filters, cancelOptions = {}] = parseFilterArgs(arg1, arg2, arg3)\n\n if (typeof cancelOptions.revert === 'undefined') {\n cancelOptions.revert = true\n }\n\n const promises = notifyManager.batch(() =>\n this.queryCache\n .findAll(filters)\n .map((query) => query.cancel(cancelOptions)),\n )\n\n return Promise.all(promises).then(noop).catch(noop)\n }\n\n invalidateQueries(\n filters?: InvalidateQueryFilters,\n options?: InvalidateOptions,\n ): Promise\n invalidateQueries(\n queryKey?: QueryKey,\n filters?: InvalidateQueryFilters,\n options?: InvalidateOptions,\n ): Promise\n invalidateQueries(\n arg1?: QueryKey | InvalidateQueryFilters,\n arg2?: InvalidateQueryFilters | InvalidateOptions,\n arg3?: InvalidateOptions,\n ): Promise {\n const [filters, options] = parseFilterArgs(arg1, arg2, arg3)\n\n return notifyManager.batch(() => {\n this.queryCache.findAll(filters).forEach((query) => {\n query.invalidate()\n })\n\n if (filters.refetchType === 'none') {\n return Promise.resolve()\n }\n const refetchFilters: RefetchQueryFilters = {\n ...filters,\n type: filters.refetchType ?? filters.type ?? 'active',\n }\n return this.refetchQueries(refetchFilters, options)\n })\n }\n\n refetchQueries(\n filters?: RefetchQueryFilters,\n options?: RefetchOptions,\n ): Promise\n refetchQueries(\n queryKey?: QueryKey,\n filters?: RefetchQueryFilters,\n options?: RefetchOptions,\n ): Promise\n refetchQueries(\n arg1?: QueryKey | RefetchQueryFilters,\n arg2?: RefetchQueryFilters | RefetchOptions,\n arg3?: RefetchOptions,\n ): Promise {\n const [filters, options] = parseFilterArgs(arg1, arg2, arg3)\n\n const promises = notifyManager.batch(() =>\n this.queryCache\n .findAll(filters)\n .filter((query) => !query.isDisabled())\n .map((query) =>\n query.fetch(undefined, {\n ...options,\n cancelRefetch: options?.cancelRefetch ?? true,\n meta: { refetchPage: filters.refetchPage },\n }),\n ),\n )\n\n let promise = Promise.all(promises).then(noop)\n\n if (!options?.throwOnError) {\n promise = promise.catch(noop)\n }\n\n return promise\n }\n\n fetchQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: FetchQueryOptions,\n ): Promise\n fetchQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryKey: TQueryKey,\n options?: FetchQueryOptions,\n ): Promise\n fetchQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryKey: TQueryKey,\n queryFn: QueryFunction,\n options?: FetchQueryOptions,\n ): Promise\n fetchQuery<\n TQueryFnData,\n TError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n arg1: TQueryKey | FetchQueryOptions,\n arg2?:\n | QueryFunction\n | FetchQueryOptions,\n arg3?: FetchQueryOptions,\n ): Promise {\n const parsedOptions = parseQueryArgs(arg1, arg2, arg3)\n const defaultedOptions = this.defaultQueryOptions(parsedOptions)\n\n // https://github.com/tannerlinsley/react-query/issues/652\n if (typeof defaultedOptions.retry === 'undefined') {\n defaultedOptions.retry = false\n }\n\n const query = this.queryCache.build(this, defaultedOptions)\n\n return query.isStaleByTime(defaultedOptions.staleTime)\n ? query.fetch(defaultedOptions)\n : Promise.resolve(query.state.data as TData)\n }\n\n prefetchQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: FetchQueryOptions,\n ): Promise\n prefetchQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryKey: TQueryKey,\n options?: FetchQueryOptions,\n ): Promise\n prefetchQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryKey: TQueryKey,\n queryFn: QueryFunction,\n options?: FetchQueryOptions,\n ): Promise\n prefetchQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n arg1: TQueryKey | FetchQueryOptions,\n arg2?:\n | QueryFunction\n | FetchQueryOptions,\n arg3?: FetchQueryOptions,\n ): Promise {\n return this.fetchQuery(arg1 as any, arg2 as any, arg3)\n .then(noop)\n .catch(noop)\n }\n\n fetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: FetchInfiniteQueryOptions,\n ): Promise>\n fetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryKey: TQueryKey,\n options?: FetchInfiniteQueryOptions,\n ): Promise>\n fetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryKey: TQueryKey,\n queryFn: QueryFunction,\n options?: FetchInfiniteQueryOptions,\n ): Promise>\n fetchInfiniteQuery<\n TQueryFnData,\n TError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n arg1:\n | TQueryKey\n | FetchInfiniteQueryOptions,\n arg2?:\n | QueryFunction\n | FetchInfiniteQueryOptions,\n arg3?: FetchInfiniteQueryOptions,\n ): Promise> {\n const parsedOptions = parseQueryArgs(arg1, arg2, arg3)\n parsedOptions.behavior = infiniteQueryBehavior<\n TQueryFnData,\n TError,\n TData\n >()\n return this.fetchQuery(parsedOptions)\n }\n\n prefetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n options: FetchInfiniteQueryOptions,\n ): Promise\n prefetchInfiniteQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryKey: TQueryKey,\n options?: FetchInfiniteQueryOptions