UNPKG

@renegade-fi/core

Version:
49 lines 2.08 kB
import { replaceEqualDeep } from "@tanstack/query-core"; import { deepEqual } from "../utils/deepEqual.js"; export function structuralSharing(oldData, newData) { if (deepEqual(oldData, newData)) return oldData; return replaceEqualDeep(oldData, newData); } export function hashFn(queryKey) { return JSON.stringify(queryKey, (_, value) => { if (isPlainObject(value)) return Object.keys(value) .sort() .reduce((result, key) => { result[key] = value[key]; return result; }, {}); if (typeof value === "bigint") return value.toString(); return value; }); } // biome-ignore lint/complexity/noBannedTypes: <explanation> function isPlainObject(o) { if (!hasObjectPrototype(o)) { return false; } // If has modified constructor const ctor = o.constructor; if (typeof ctor === "undefined") return true; // If has modified prototype const prot = ctor.prototype; if (!hasObjectPrototype(prot)) return false; // If constructor does not have an Object-specific method // biome-ignore lint/suspicious/noPrototypeBuiltins: <explanation> if (!prot.hasOwnProperty("isPrototypeOf")) return false; // Most likely a plain Object return true; } function hasObjectPrototype(o) { return Object.prototype.toString.call(o) === "[object Object]"; } export function filterQueryOptions(options) { const { _defaulted, behavior, gcTime, initialData, initialDataUpdatedAt, maxPages, meta, networkMode, queryFn, queryHash, queryKey, queryKeyHashFn, retry, retryDelay, structuralSharing, getPreviousPageParam, getNextPageParam, initialPageParam, _optimisticResults, enabled, notifyOnChangeProps, placeholderData, refetchInterval, refetchIntervalInBackground, refetchOnMount, refetchOnReconnect, refetchOnWindowFocus, retryOnMount, select, staleTime, suspense, throwOnError, config, connector, query, ...rest } = options; return rest; } //# sourceMappingURL=utils.js.map