@elevora/react
Version:
Official SDK for Elevora's public API
1,542 lines (1,527 loc) • 143 kB
JavaScript
"use client";
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __typeError = (msg) => {
throw TypeError(msg);
};
var __pow = Math.pow;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
var __privateWrapper = (obj, member, setter, getter) => ({
set _(value) {
__privateSet(obj, member, value, setter);
},
get _() {
return __privateGet(obj, member, getter);
}
});
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// src/ElevoraProvider.tsx
import React7, { createContext as createContext4, useContext as useContext4, useCallback as useCallback3, useMemo } from "react";
// src/elevora-axios-instance.ts
import Axios from "axios";
import { useEffect } from "react";
import { useLocalStorageState } from "@thibault.sh/hooks";
var baseURL = process.env.NEXT_PUBLIC_ELEVORA || "https://api.dev.elevora.app";
var elevoraClient = Axios.create({
baseURL
});
var customInstance = (config, options) => __async(void 0, null, function* () {
const response = yield elevoraClient(__spreadValues(__spreadValues({}, config), options));
return response.data;
});
function setAxiosToken(token) {
if (token) {
elevoraClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
} else {
elevoraClient.defaults.headers.common["Authorization"] = void 0;
}
}
function useSetElevoraToken() {
const [token, _setToken] = useLocalStorageState("elevoraToken", "");
useEffect(() => {
setAxiosToken(token);
}, [token]);
const logout = () => {
_setToken("");
setAxiosToken("");
};
const setToken = (token2) => {
_setToken(token2);
setAxiosToken(token2);
};
return { setToken, logout };
}
// ../../node_modules/.pnpm/@tanstack+query-core@5.62.7/node_modules/@tanstack/query-core/build/modern/subscribable.js
var Subscribable = class {
constructor() {
this.listeners = /* @__PURE__ */ new Set();
this.subscribe = this.subscribe.bind(this);
}
subscribe(listener) {
this.listeners.add(listener);
this.onSubscribe();
return () => {
this.listeners.delete(listener);
this.onUnsubscribe();
};
}
hasListeners() {
return this.listeners.size > 0;
}
onSubscribe() {
}
onUnsubscribe() {
}
};
// ../../node_modules/.pnpm/@tanstack+query-core@5.62.7/node_modules/@tanstack/query-core/build/modern/utils.js
var isServer = typeof window === "undefined" || "Deno" in globalThis;
function noop() {
}
function functionalUpdate(updater, input) {
return typeof updater === "function" ? updater(input) : updater;
}
function isValidTimeout(value) {
return typeof value === "number" && value >= 0 && value !== Infinity;
}
function timeUntilStale(updatedAt, staleTime) {
return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
}
function resolveStaleTime(staleTime, query) {
return typeof staleTime === "function" ? staleTime(query) : staleTime;
}
function resolveEnabled(enabled, query) {
return typeof enabled === "function" ? enabled(query) : enabled;
}
function matchQuery(filters, query) {
const {
type = "all",
exact,
fetchStatus,
predicate,
queryKey,
stale
} = filters;
if (queryKey) {
if (exact) {
if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {
return false;
}
} else if (!partialMatchKey(query.queryKey, queryKey)) {
return false;
}
}
if (type !== "all") {
const isActive = query.isActive();
if (type === "active" && !isActive) {
return false;
}
if (type === "inactive" && isActive) {
return false;
}
}
if (typeof stale === "boolean" && query.isStale() !== stale) {
return false;
}
if (fetchStatus && fetchStatus !== query.state.fetchStatus) {
return false;
}
if (predicate && !predicate(query)) {
return false;
}
return true;
}
function matchMutation(filters, mutation) {
const { exact, status, predicate, mutationKey } = filters;
if (mutationKey) {
if (!mutation.options.mutationKey) {
return false;
}
if (exact) {
if (hashKey(mutation.options.mutationKey) !== hashKey(mutationKey)) {
return false;
}
} else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {
return false;
}
}
if (status && mutation.state.status !== status) {
return false;
}
if (predicate && !predicate(mutation)) {
return false;
}
return true;
}
function hashQueryKeyByOptions(queryKey, options) {
const hashFn = (options == null ? void 0 : options.queryKeyHashFn) || hashKey;
return hashFn(queryKey);
}
function hashKey(queryKey) {
return JSON.stringify(
queryKey,
(_, val) => isPlainObject(val) ? Object.keys(val).sort().reduce((result, key) => {
result[key] = val[key];
return result;
}, {}) : val
);
}
function partialMatchKey(a, b) {
if (a === b) {
return true;
}
if (typeof a !== typeof b) {
return false;
}
if (a && b && typeof a === "object" && typeof b === "object") {
return !Object.keys(b).some((key) => !partialMatchKey(a[key], b[key]));
}
return false;
}
function replaceEqualDeep(a, b) {
if (a === b) {
return a;
}
const array = isPlainArray(a) && isPlainArray(b);
if (array || isPlainObject(a) && isPlainObject(b)) {
const aItems = array ? a : Object.keys(a);
const aSize = aItems.length;
const bItems = array ? b : Object.keys(b);
const bSize = bItems.length;
const copy = array ? [] : {};
let equalItems = 0;
for (let i = 0; i < bSize; i++) {
const key = array ? i : bItems[i];
if ((!array && aItems.includes(key) || array) && a[key] === void 0 && b[key] === void 0) {
copy[key] = void 0;
equalItems++;
} else {
copy[key] = replaceEqualDeep(a[key], b[key]);
if (copy[key] === a[key] && a[key] !== void 0) {
equalItems++;
}
}
}
return aSize === bSize && equalItems === aSize ? a : copy;
}
return b;
}
function shallowEqualObjects(a, b) {
if (!b || Object.keys(a).length !== Object.keys(b).length) {
return false;
}
for (const key in a) {
if (a[key] !== b[key]) {
return false;
}
}
return true;
}
function isPlainArray(value) {
return Array.isArray(value) && value.length === Object.keys(value).length;
}
function isPlainObject(o) {
if (!hasObjectPrototype(o)) {
return false;
}
const ctor = o.constructor;
if (ctor === void 0) {
return true;
}
const prot = ctor.prototype;
if (!hasObjectPrototype(prot)) {
return false;
}
if (!prot.hasOwnProperty("isPrototypeOf")) {
return false;
}
if (Object.getPrototypeOf(o) !== Object.prototype) {
return false;
}
return true;
}
function hasObjectPrototype(o) {
return Object.prototype.toString.call(o) === "[object Object]";
}
function sleep(timeout) {
return new Promise((resolve) => {
setTimeout(resolve, timeout);
});
}
function replaceData(prevData, data, options) {
if (typeof options.structuralSharing === "function") {
return options.structuralSharing(prevData, data);
} else if (options.structuralSharing !== false) {
if (process.env.NODE_ENV !== "production") {
try {
return replaceEqualDeep(prevData, data);
} catch (error) {
console.error(
`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${options.queryHash}]: ${error}`
);
}
}
return replaceEqualDeep(prevData, data);
}
return data;
}
function addToEnd(items, item, max = 0) {
const newItems = [...items, item];
return max && newItems.length > max ? newItems.slice(1) : newItems;
}
function addToStart(items, item, max = 0) {
const newItems = [item, ...items];
return max && newItems.length > max ? newItems.slice(0, -1) : newItems;
}
var skipToken = Symbol();
function ensureQueryFn(options, fetchOptions) {
if (process.env.NODE_ENV !== "production") {
if (options.queryFn === skipToken) {
console.error(
`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${options.queryHash}'`
);
}
}
if (!options.queryFn && (fetchOptions == null ? void 0 : fetchOptions.initialPromise)) {
return () => fetchOptions.initialPromise;
}
if (!options.queryFn || options.queryFn === skipToken) {
return () => Promise.reject(new Error(`Missing queryFn: '${options.queryHash}'`));
}
return options.queryFn;
}
// ../../node_modules/.pnpm/@tanstack+query-core@5.62.7/node_modules/@tanstack/query-core/build/modern/focusManager.js
var _focused, _cleanup, _setup, _a;
var FocusManager = (_a = class extends Subscribable {
constructor() {
super();
__privateAdd(this, _focused);
__privateAdd(this, _cleanup);
__privateAdd(this, _setup);
__privateSet(this, _setup, (onFocus) => {
if (!isServer && window.addEventListener) {
const listener = () => onFocus();
window.addEventListener("visibilitychange", listener, false);
return () => {
window.removeEventListener("visibilitychange", listener);
};
}
return;
});
}
onSubscribe() {
if (!__privateGet(this, _cleanup)) {
this.setEventListener(__privateGet(this, _setup));
}
}
onUnsubscribe() {
var _a10;
if (!this.hasListeners()) {
(_a10 = __privateGet(this, _cleanup)) == null ? void 0 : _a10.call(this);
__privateSet(this, _cleanup, void 0);
}
}
setEventListener(setup) {
var _a10;
__privateSet(this, _setup, setup);
(_a10 = __privateGet(this, _cleanup)) == null ? void 0 : _a10.call(this);
__privateSet(this, _cleanup, setup((focused) => {
if (typeof focused === "boolean") {
this.setFocused(focused);
} else {
this.onFocus();
}
}));
}
setFocused(focused) {
const changed = __privateGet(this, _focused) !== focused;
if (changed) {
__privateSet(this, _focused, focused);
this.onFocus();
}
}
onFocus() {
const isFocused = this.isFocused();
this.listeners.forEach((listener) => {
listener(isFocused);
});
}
isFocused() {
var _a10;
if (typeof __privateGet(this, _focused) === "boolean") {
return __privateGet(this, _focused);
}
return ((_a10 = globalThis.document) == null ? void 0 : _a10.visibilityState) !== "hidden";
}
}, _focused = new WeakMap(), _cleanup = new WeakMap(), _setup = new WeakMap(), _a);
var focusManager = new FocusManager();
// ../../node_modules/.pnpm/@tanstack+query-core@5.62.7/node_modules/@tanstack/query-core/build/modern/onlineManager.js
var _online, _cleanup2, _setup2, _a2;
var OnlineManager = (_a2 = class extends Subscribable {
constructor() {
super();
__privateAdd(this, _online, true);
__privateAdd(this, _cleanup2);
__privateAdd(this, _setup2);
__privateSet(this, _setup2, (onOnline) => {
if (!isServer && window.addEventListener) {
const onlineListener = () => onOnline(true);
const offlineListener = () => onOnline(false);
window.addEventListener("online", onlineListener, false);
window.addEventListener("offline", offlineListener, false);
return () => {
window.removeEventListener("online", onlineListener);
window.removeEventListener("offline", offlineListener);
};
}
return;
});
}
onSubscribe() {
if (!__privateGet(this, _cleanup2)) {
this.setEventListener(__privateGet(this, _setup2));
}
}
onUnsubscribe() {
var _a10;
if (!this.hasListeners()) {
(_a10 = __privateGet(this, _cleanup2)) == null ? void 0 : _a10.call(this);
__privateSet(this, _cleanup2, void 0);
}
}
setEventListener(setup) {
var _a10;
__privateSet(this, _setup2, setup);
(_a10 = __privateGet(this, _cleanup2)) == null ? void 0 : _a10.call(this);
__privateSet(this, _cleanup2, setup(this.setOnline.bind(this)));
}
setOnline(online) {
const changed = __privateGet(this, _online) !== online;
if (changed) {
__privateSet(this, _online, online);
this.listeners.forEach((listener) => {
listener(online);
});
}
}
isOnline() {
return __privateGet(this, _online);
}
}, _online = new WeakMap(), _cleanup2 = new WeakMap(), _setup2 = new WeakMap(), _a2);
var onlineManager = new OnlineManager();
// ../../node_modules/.pnpm/@tanstack+query-core@5.62.7/node_modules/@tanstack/query-core/build/modern/thenable.js
function pendingThenable() {
let resolve;
let reject;
const thenable = new Promise((_resolve, _reject) => {
resolve = _resolve;
reject = _reject;
});
thenable.status = "pending";
thenable.catch(() => {
});
function finalize(data) {
Object.assign(thenable, data);
delete thenable.resolve;
delete thenable.reject;
}
thenable.resolve = (value) => {
finalize({
status: "fulfilled",
value
});
resolve(value);
};
thenable.reject = (reason) => {
finalize({
status: "rejected",
reason
});
reject(reason);
};
return thenable;
}
// ../../node_modules/.pnpm/@tanstack+query-core@5.62.7/node_modules/@tanstack/query-core/build/modern/retryer.js
function defaultRetryDelay(failureCount) {
return Math.min(1e3 * __pow(2, failureCount), 3e4);
}
function canFetch(networkMode) {
return (networkMode != null ? networkMode : "online") === "online" ? onlineManager.isOnline() : true;
}
var CancelledError = class extends Error {
constructor(options) {
super("CancelledError");
this.revert = options == null ? void 0 : options.revert;
this.silent = options == null ? void 0 : options.silent;
}
};
function isCancelledError(value) {
return value instanceof CancelledError;
}
function createRetryer(config) {
let isRetryCancelled = false;
let failureCount = 0;
let isResolved = false;
let continueFn;
const thenable = pendingThenable();
const cancel = (cancelOptions) => {
var _a10;
if (!isResolved) {
reject(new CancelledError(cancelOptions));
(_a10 = config.abort) == null ? void 0 : _a10.call(config);
}
};
const cancelRetry = () => {
isRetryCancelled = true;
};
const continueRetry = () => {
isRetryCancelled = false;
};
const canContinue = () => focusManager.isFocused() && (config.networkMode === "always" || onlineManager.isOnline()) && config.canRun();
const canStart = () => canFetch(config.networkMode) && config.canRun();
const resolve = (value) => {
var _a10;
if (!isResolved) {
isResolved = true;
(_a10 = config.onSuccess) == null ? void 0 : _a10.call(config, value);
continueFn == null ? void 0 : continueFn();
thenable.resolve(value);
}
};
const reject = (value) => {
var _a10;
if (!isResolved) {
isResolved = true;
(_a10 = config.onError) == null ? void 0 : _a10.call(config, value);
continueFn == null ? void 0 : continueFn();
thenable.reject(value);
}
};
const pause = () => {
return new Promise((continueResolve) => {
var _a10;
continueFn = (value) => {
if (isResolved || canContinue()) {
continueResolve(value);
}
};
(_a10 = config.onPause) == null ? void 0 : _a10.call(config);
}).then(() => {
var _a10;
continueFn = void 0;
if (!isResolved) {
(_a10 = config.onContinue) == null ? void 0 : _a10.call(config);
}
});
};
const run = () => {
if (isResolved) {
return;
}
let promiseOrValue;
const initialPromise = failureCount === 0 ? config.initialPromise : void 0;
try {
promiseOrValue = initialPromise != null ? initialPromise : config.fn();
} catch (error) {
promiseOrValue = Promise.reject(error);
}
Promise.resolve(promiseOrValue).then(resolve).catch((error) => {
var _a10, _b2, _c;
if (isResolved) {
return;
}
const retry = (_a10 = config.retry) != null ? _a10 : isServer ? 0 : 3;
const retryDelay = (_b2 = config.retryDelay) != null ? _b2 : defaultRetryDelay;
const delay = typeof retryDelay === "function" ? retryDelay(failureCount, error) : retryDelay;
const shouldRetry = retry === true || typeof retry === "number" && failureCount < retry || typeof retry === "function" && retry(failureCount, error);
if (isRetryCancelled || !shouldRetry) {
reject(error);
return;
}
failureCount++;
(_c = config.onFail) == null ? void 0 : _c.call(config, failureCount, error);
sleep(delay).then(() => {
return canContinue() ? void 0 : pause();
}).then(() => {
if (isRetryCancelled) {
reject(error);
} else {
run();
}
});
});
};
return {
promise: thenable,
cancel,
continue: () => {
continueFn == null ? void 0 : continueFn();
return thenable;
},
cancelRetry,
continueRetry,
canStart,
start: () => {
if (canStart()) {
run();
} else {
pause().then(run);
}
return thenable;
}
};
}
// ../../node_modules/.pnpm/@tanstack+query-core@5.62.7/node_modules/@tanstack/query-core/build/modern/notifyManager.js
function createNotifyManager() {
let queue = [];
let transactions = 0;
let notifyFn = (callback) => {
callback();
};
let batchNotifyFn = (callback) => {
callback();
};
let scheduleFn = (cb) => setTimeout(cb, 0);
const schedule = (callback) => {
if (transactions) {
queue.push(callback);
} else {
scheduleFn(() => {
notifyFn(callback);
});
}
};
const flush = () => {
const originalQueue = queue;
queue = [];
if (originalQueue.length) {
scheduleFn(() => {
batchNotifyFn(() => {
originalQueue.forEach((callback) => {
notifyFn(callback);
});
});
});
}
};
return {
batch: (callback) => {
let result;
transactions++;
try {
result = callback();
} finally {
transactions--;
if (!transactions) {
flush();
}
}
return result;
},
/**
* All calls to the wrapped function will be batched.
*/
batchCalls: (callback) => {
return (...args) => {
schedule(() => {
callback(...args);
});
};
},
schedule,
/**
* Use this method to set a custom notify function.
* This can be used to for example wrap notifications with `React.act` while running tests.
*/
setNotifyFunction: (fn) => {
notifyFn = fn;
},
/**
* Use this method to set a custom function to batch notifications together into a single tick.
* By default React Query will use the batch function provided by ReactDOM or React Native.
*/
setBatchNotifyFunction: (fn) => {
batchNotifyFn = fn;
},
setScheduler: (fn) => {
scheduleFn = fn;
}
};
}
var notifyManager = createNotifyManager();
// ../../node_modules/.pnpm/@tanstack+query-core@5.62.7/node_modules/@tanstack/query-core/build/modern/removable.js
var _gcTimeout, _a3;
var Removable = (_a3 = class {
constructor() {
__privateAdd(this, _gcTimeout);
}
destroy() {
this.clearGcTimeout();
}
scheduleGc() {
this.clearGcTimeout();
if (isValidTimeout(this.gcTime)) {
__privateSet(this, _gcTimeout, setTimeout(() => {
this.optionalRemove();
}, this.gcTime));
}
}
updateGcTime(newGcTime) {
this.gcTime = Math.max(
this.gcTime || 0,
newGcTime != null ? newGcTime : isServer ? Infinity : 5 * 60 * 1e3
);
}
clearGcTimeout() {
if (__privateGet(this, _gcTimeout)) {
clearTimeout(__privateGet(this, _gcTimeout));
__privateSet(this, _gcTimeout, void 0);
}
}
}, _gcTimeout = new WeakMap(), _a3);
// ../../node_modules/.pnpm/@tanstack+query-core@5.62.7/node_modules/@tanstack/query-core/build/modern/query.js
var _initialState, _revertState, _cache, _retryer, _defaultOptions, _abortSignalConsumed, _Query_instances, dispatch_fn, _a4;
var Query = (_a4 = class extends Removable {
constructor(config) {
var _a10;
super();
__privateAdd(this, _Query_instances);
__privateAdd(this, _initialState);
__privateAdd(this, _revertState);
__privateAdd(this, _cache);
__privateAdd(this, _retryer);
__privateAdd(this, _defaultOptions);
__privateAdd(this, _abortSignalConsumed);
__privateSet(this, _abortSignalConsumed, false);
__privateSet(this, _defaultOptions, config.defaultOptions);
this.setOptions(config.options);
this.observers = [];
__privateSet(this, _cache, config.cache);
this.queryKey = config.queryKey;
this.queryHash = config.queryHash;
__privateSet(this, _initialState, getDefaultState(this.options));
this.state = (_a10 = config.state) != null ? _a10 : __privateGet(this, _initialState);
this.scheduleGc();
}
get meta() {
return this.options.meta;
}
get promise() {
var _a10;
return (_a10 = __privateGet(this, _retryer)) == null ? void 0 : _a10.promise;
}
setOptions(options) {
this.options = __spreadValues(__spreadValues({}, __privateGet(this, _defaultOptions)), options);
this.updateGcTime(this.options.gcTime);
}
optionalRemove() {
if (!this.observers.length && this.state.fetchStatus === "idle") {
__privateGet(this, _cache).remove(this);
}
}
setData(newData, options) {
const data = replaceData(this.state.data, newData, this.options);
__privateMethod(this, _Query_instances, dispatch_fn).call(this, {
data,
type: "success",
dataUpdatedAt: options == null ? void 0 : options.updatedAt,
manual: options == null ? void 0 : options.manual
});
return data;
}
setState(state, setStateOptions) {
__privateMethod(this, _Query_instances, dispatch_fn).call(this, { type: "setState", state, setStateOptions });
}
cancel(options) {
var _a10, _b2;
const promise = (_a10 = __privateGet(this, _retryer)) == null ? void 0 : _a10.promise;
(_b2 = __privateGet(this, _retryer)) == null ? void 0 : _b2.cancel(options);
return promise ? promise.then(noop).catch(noop) : Promise.resolve();
}
destroy() {
super.destroy();
this.cancel({ silent: true });
}
reset() {
this.destroy();
this.setState(__privateGet(this, _initialState));
}
isActive() {
return this.observers.some(
(observer) => resolveEnabled(observer.options.enabled, this) !== false
);
}
isDisabled() {
if (this.getObserversCount() > 0) {
return !this.isActive();
}
return this.options.queryFn === skipToken || this.state.dataUpdateCount + this.state.errorUpdateCount === 0;
}
isStale() {
if (this.state.isInvalidated) {
return true;
}
if (this.getObserversCount() > 0) {
return this.observers.some(
(observer) => observer.getCurrentResult().isStale
);
}
return this.state.data === void 0;
}
isStaleByTime(staleTime = 0) {
return this.state.isInvalidated || this.state.data === void 0 || !timeUntilStale(this.state.dataUpdatedAt, staleTime);
}
onFocus() {
var _a10;
const observer = this.observers.find((x) => x.shouldFetchOnWindowFocus());
observer == null ? void 0 : observer.refetch({ cancelRefetch: false });
(_a10 = __privateGet(this, _retryer)) == null ? void 0 : _a10.continue();
}
onOnline() {
var _a10;
const observer = this.observers.find((x) => x.shouldFetchOnReconnect());
observer == null ? void 0 : observer.refetch({ cancelRefetch: false });
(_a10 = __privateGet(this, _retryer)) == null ? void 0 : _a10.continue();
}
addObserver(observer) {
if (!this.observers.includes(observer)) {
this.observers.push(observer);
this.clearGcTimeout();
__privateGet(this, _cache).notify({ type: "observerAdded", query: this, observer });
}
}
removeObserver(observer) {
if (this.observers.includes(observer)) {
this.observers = this.observers.filter((x) => x !== observer);
if (!this.observers.length) {
if (__privateGet(this, _retryer)) {
if (__privateGet(this, _abortSignalConsumed)) {
__privateGet(this, _retryer).cancel({ revert: true });
} else {
__privateGet(this, _retryer).cancelRetry();
}
}
this.scheduleGc();
}
__privateGet(this, _cache).notify({ type: "observerRemoved", query: this, observer });
}
}
getObserversCount() {
return this.observers.length;
}
invalidate() {
if (!this.state.isInvalidated) {
__privateMethod(this, _Query_instances, dispatch_fn).call(this, { type: "invalidate" });
}
}
fetch(options, fetchOptions) {
var _a10, _b2, _c;
if (this.state.fetchStatus !== "idle") {
if (this.state.data !== void 0 && (fetchOptions == null ? void 0 : fetchOptions.cancelRefetch)) {
this.cancel({ silent: true });
} else if (__privateGet(this, _retryer)) {
__privateGet(this, _retryer).continueRetry();
return __privateGet(this, _retryer).promise;
}
}
if (options) {
this.setOptions(options);
}
if (!this.options.queryFn) {
const observer = this.observers.find((x) => x.options.queryFn);
if (observer) {
this.setOptions(observer.options);
}
}
if (process.env.NODE_ENV !== "production") {
if (!Array.isArray(this.options.queryKey)) {
console.error(
`As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']`
);
}
}
const abortController = new AbortController();
const addSignalProperty = (object) => {
Object.defineProperty(object, "signal", {
enumerable: true,
get: () => {
__privateSet(this, _abortSignalConsumed, true);
return abortController.signal;
}
});
};
const fetchFn = () => {
const queryFn = ensureQueryFn(this.options, fetchOptions);
const queryFnContext = {
queryKey: this.queryKey,
meta: this.meta
};
addSignalProperty(queryFnContext);
__privateSet(this, _abortSignalConsumed, false);
if (this.options.persister) {
return this.options.persister(
queryFn,
queryFnContext,
this
);
}
return queryFn(queryFnContext);
};
const context = {
fetchOptions,
options: this.options,
queryKey: this.queryKey,
state: this.state,
fetchFn
};
addSignalProperty(context);
(_a10 = this.options.behavior) == null ? void 0 : _a10.onFetch(
context,
this
);
__privateSet(this, _revertState, this.state);
if (this.state.fetchStatus === "idle" || this.state.fetchMeta !== ((_b2 = context.fetchOptions) == null ? void 0 : _b2.meta)) {
__privateMethod(this, _Query_instances, dispatch_fn).call(this, { type: "fetch", meta: (_c = context.fetchOptions) == null ? void 0 : _c.meta });
}
const onError = (error) => {
var _a11, _b3, _c2, _d;
if (!(isCancelledError(error) && error.silent)) {
__privateMethod(this, _Query_instances, dispatch_fn).call(this, {
type: "error",
error
});
}
if (!isCancelledError(error)) {
(_b3 = (_a11 = __privateGet(this, _cache).config).onError) == null ? void 0 : _b3.call(
_a11,
error,
this
);
(_d = (_c2 = __privateGet(this, _cache).config).onSettled) == null ? void 0 : _d.call(
_c2,
this.state.data,
error,
this
);
}
this.scheduleGc();
};
__privateSet(this, _retryer, createRetryer({
initialPromise: fetchOptions == null ? void 0 : fetchOptions.initialPromise,
fn: context.fetchFn,
abort: abortController.abort.bind(abortController),
onSuccess: (data) => {
var _a11, _b3, _c2, _d;
if (data === void 0) {
if (process.env.NODE_ENV !== "production") {
console.error(
`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`
);
}
onError(new Error(`${this.queryHash} data is undefined`));
return;
}
try {
this.setData(data);
} catch (error) {
onError(error);
return;
}
(_b3 = (_a11 = __privateGet(this, _cache).config).onSuccess) == null ? void 0 : _b3.call(_a11, data, this);
(_d = (_c2 = __privateGet(this, _cache).config).onSettled) == null ? void 0 : _d.call(
_c2,
data,
this.state.error,
this
);
this.scheduleGc();
},
onError,
onFail: (failureCount, error) => {
__privateMethod(this, _Query_instances, dispatch_fn).call(this, { type: "failed", failureCount, error });
},
onPause: () => {
__privateMethod(this, _Query_instances, dispatch_fn).call(this, { type: "pause" });
},
onContinue: () => {
__privateMethod(this, _Query_instances, dispatch_fn).call(this, { type: "continue" });
},
retry: context.options.retry,
retryDelay: context.options.retryDelay,
networkMode: context.options.networkMode,
canRun: () => true
}));
return __privateGet(this, _retryer).start();
}
}, _initialState = new WeakMap(), _revertState = new WeakMap(), _cache = new WeakMap(), _retryer = new WeakMap(), _defaultOptions = new WeakMap(), _abortSignalConsumed = new WeakMap(), _Query_instances = new WeakSet(), dispatch_fn = function(action) {
const reducer = (state) => {
var _a10, _b2;
switch (action.type) {
case "failed":
return __spreadProps(__spreadValues({}, state), {
fetchFailureCount: action.failureCount,
fetchFailureReason: action.error
});
case "pause":
return __spreadProps(__spreadValues({}, state), {
fetchStatus: "paused"
});
case "continue":
return __spreadProps(__spreadValues({}, state), {
fetchStatus: "fetching"
});
case "fetch":
return __spreadProps(__spreadValues(__spreadValues({}, state), fetchState(state.data, this.options)), {
fetchMeta: (_a10 = action.meta) != null ? _a10 : null
});
case "success":
return __spreadValues(__spreadProps(__spreadValues({}, state), {
data: action.data,
dataUpdateCount: state.dataUpdateCount + 1,
dataUpdatedAt: (_b2 = action.dataUpdatedAt) != null ? _b2 : Date.now(),
error: null,
isInvalidated: false,
status: "success"
}), !action.manual && {
fetchStatus: "idle",
fetchFailureCount: 0,
fetchFailureReason: null
});
case "error":
const error = action.error;
if (isCancelledError(error) && error.revert && __privateGet(this, _revertState)) {
return __spreadProps(__spreadValues({}, __privateGet(this, _revertState)), { fetchStatus: "idle" });
}
return __spreadProps(__spreadValues({}, state), {
error,
errorUpdateCount: state.errorUpdateCount + 1,
errorUpdatedAt: Date.now(),
fetchFailureCount: state.fetchFailureCount + 1,
fetchFailureReason: error,
fetchStatus: "idle",
status: "error"
});
case "invalidate":
return __spreadProps(__spreadValues({}, state), {
isInvalidated: true
});
case "setState":
return __spreadValues(__spreadValues({}, state), action.state);
}
};
this.state = reducer(this.state);
notifyManager.batch(() => {
this.observers.forEach((observer) => {
observer.onQueryUpdate();
});
__privateGet(this, _cache).notify({ query: this, type: "updated", action });
});
}, _a4);
function fetchState(data, options) {
return __spreadValues({
fetchFailureCount: 0,
fetchFailureReason: null,
fetchStatus: canFetch(options.networkMode) ? "fetching" : "paused"
}, data === void 0 && {
error: null,
status: "pending"
});
}
function getDefaultState(options) {
const data = typeof options.initialData === "function" ? options.initialData() : options.initialData;
const hasData = data !== void 0;
const initialDataUpdatedAt = hasData ? typeof options.initialDataUpdatedAt === "function" ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
return {
data,
dataUpdateCount: 0,
dataUpdatedAt: hasData ? initialDataUpdatedAt != null ? initialDataUpdatedAt : Date.now() : 0,
error: null,
errorUpdateCount: 0,
errorUpdatedAt: 0,
fetchFailureCount: 0,
fetchFailureReason: null,
fetchMeta: null,
isInvalidated: false,
status: hasData ? "success" : "pending",
fetchStatus: "idle"
};
}
// ../../node_modules/.pnpm/@tanstack+query-core@5.62.7/node_modules/@tanstack/query-core/build/modern/queryCache.js
var _queries, _a5;
var QueryCache = (_a5 = class extends Subscribable {
constructor(config = {}) {
super();
__privateAdd(this, _queries);
this.config = config;
__privateSet(this, _queries, /* @__PURE__ */ new Map());
}
build(client, options, state) {
var _a10;
const queryKey = options.queryKey;
const queryHash = (_a10 = options.queryHash) != null ? _a10 : hashQueryKeyByOptions(queryKey, options);
let query = this.get(queryHash);
if (!query) {
query = new Query({
cache: this,
queryKey,
queryHash,
options: client.defaultQueryOptions(options),
state,
defaultOptions: client.getQueryDefaults(queryKey)
});
this.add(query);
}
return query;
}
add(query) {
if (!__privateGet(this, _queries).has(query.queryHash)) {
__privateGet(this, _queries).set(query.queryHash, query);
this.notify({
type: "added",
query
});
}
}
remove(query) {
const queryInMap = __privateGet(this, _queries).get(query.queryHash);
if (queryInMap) {
query.destroy();
if (queryInMap === query) {
__privateGet(this, _queries).delete(query.queryHash);
}
this.notify({ type: "removed", query });
}
}
clear() {
notifyManager.batch(() => {
this.getAll().forEach((query) => {
this.remove(query);
});
});
}
get(queryHash) {
return __privateGet(this, _queries).get(queryHash);
}
getAll() {
return [...__privateGet(this, _queries).values()];
}
find(filters) {
const defaultedFilters = __spreadValues({ exact: true }, filters);
return this.getAll().find(
(query) => matchQuery(defaultedFilters, query)
);
}
findAll(filters = {}) {
const queries = this.getAll();
return Object.keys(filters).length > 0 ? queries.filter((query) => matchQuery(filters, query)) : queries;
}
notify(event) {
notifyManager.batch(() => {
this.listeners.forEach((listener) => {
listener(event);
});
});
}
onFocus() {
notifyManager.batch(() => {
this.getAll().forEach((query) => {
query.onFocus();
});
});
}
onOnline() {
notifyManager.batch(() => {
this.getAll().forEach((query) => {
query.onOnline();
});
});
}
}, _queries = new WeakMap(), _a5);
// ../../node_modules/.pnpm/@tanstack+query-core@5.62.7/node_modules/@tanstack/query-core/build/modern/mutation.js
var _observers, _mutationCache, _retryer2, _Mutation_instances, dispatch_fn2, _a6;
var Mutation = (_a6 = class extends Removable {
constructor(config) {
super();
__privateAdd(this, _Mutation_instances);
__privateAdd(this, _observers);
__privateAdd(this, _mutationCache);
__privateAdd(this, _retryer2);
this.mutationId = config.mutationId;
__privateSet(this, _mutationCache, config.mutationCache);
__privateSet(this, _observers, []);
this.state = config.state || getDefaultState2();
this.setOptions(config.options);
this.scheduleGc();
}
setOptions(options) {
this.options = options;
this.updateGcTime(this.options.gcTime);
}
get meta() {
return this.options.meta;
}
addObserver(observer) {
if (!__privateGet(this, _observers).includes(observer)) {
__privateGet(this, _observers).push(observer);
this.clearGcTimeout();
__privateGet(this, _mutationCache).notify({
type: "observerAdded",
mutation: this,
observer
});
}
}
removeObserver(observer) {
__privateSet(this, _observers, __privateGet(this, _observers).filter((x) => x !== observer));
this.scheduleGc();
__privateGet(this, _mutationCache).notify({
type: "observerRemoved",
mutation: this,
observer
});
}
optionalRemove() {
if (!__privateGet(this, _observers).length) {
if (this.state.status === "pending") {
this.scheduleGc();
} else {
__privateGet(this, _mutationCache).remove(this);
}
}
}
continue() {
var _a10, _b2;
return (_b2 = (_a10 = __privateGet(this, _retryer2)) == null ? void 0 : _a10.continue()) != null ? _b2 : (
// continuing a mutation assumes that variables are set, mutation must have been dehydrated before
this.execute(this.state.variables)
);
}
execute(variables) {
return __async(this, null, function* () {
var _a10, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
__privateSet(this, _retryer2, createRetryer({
fn: () => {
if (!this.options.mutationFn) {
return Promise.reject(new Error("No mutationFn found"));
}
return this.options.mutationFn(variables);
},
onFail: (failureCount, error) => {
__privateMethod(this, _Mutation_instances, dispatch_fn2).call(this, { type: "failed", failureCount, error });
},
onPause: () => {
__privateMethod(this, _Mutation_instances, dispatch_fn2).call(this, { type: "pause" });
},
onContinue: () => {
__privateMethod(this, _Mutation_instances, dispatch_fn2).call(this, { type: "continue" });
},
retry: (_a10 = this.options.retry) != null ? _a10 : 0,
retryDelay: this.options.retryDelay,
networkMode: this.options.networkMode,
canRun: () => __privateGet(this, _mutationCache).canRun(this)
}));
const restored = this.state.status === "pending";
const isPaused = !__privateGet(this, _retryer2).canStart();
try {
if (!restored) {
__privateMethod(this, _Mutation_instances, dispatch_fn2).call(this, { type: "pending", variables, isPaused });
yield (_c = (_b2 = __privateGet(this, _mutationCache).config).onMutate) == null ? void 0 : _c.call(
_b2,
variables,
this
);
const context = yield (_e = (_d = this.options).onMutate) == null ? void 0 : _e.call(_d, variables);
if (context !== this.state.context) {
__privateMethod(this, _Mutation_instances, dispatch_fn2).call(this, {
type: "pending",
context,
variables,
isPaused
});
}
}
const data = yield __privateGet(this, _retryer2).start();
yield (_g = (_f = __privateGet(this, _mutationCache).config).onSuccess) == null ? void 0 : _g.call(
_f,
data,
variables,
this.state.context,
this
);
yield (_i = (_h = this.options).onSuccess) == null ? void 0 : _i.call(_h, data, variables, this.state.context);
yield (_k = (_j = __privateGet(this, _mutationCache).config).onSettled) == null ? void 0 : _k.call(
_j,
data,
null,
this.state.variables,
this.state.context,
this
);
yield (_m = (_l = this.options).onSettled) == null ? void 0 : _m.call(_l, data, null, variables, this.state.context);
__privateMethod(this, _Mutation_instances, dispatch_fn2).call(this, { type: "success", data });
return data;
} catch (error) {
try {
yield (_o = (_n = __privateGet(this, _mutationCache).config).onError) == null ? void 0 : _o.call(
_n,
error,
variables,
this.state.context,
this
);
yield (_q = (_p = this.options).onError) == null ? void 0 : _q.call(
_p,
error,
variables,
this.state.context
);
yield (_s = (_r = __privateGet(this, _mutationCache).config).onSettled) == null ? void 0 : _s.call(
_r,
void 0,
error,
this.state.variables,
this.state.context,
this
);
yield (_u = (_t = this.options).onSettled) == null ? void 0 : _u.call(
_t,
void 0,
error,
variables,
this.state.context
);
throw error;
} finally {
__privateMethod(this, _Mutation_instances, dispatch_fn2).call(this, { type: "error", error });
}
} finally {
__privateGet(this, _mutationCache).runNext(this);
}
});
}
}, _observers = new WeakMap(), _mutationCache = new WeakMap(), _retryer2 = new WeakMap(), _Mutation_instances = new WeakSet(), dispatch_fn2 = function(action) {
const reducer = (state) => {
switch (action.type) {
case "failed":
return __spreadProps(__spreadValues({}, state), {
failureCount: action.failureCount,
failureReason: action.error
});
case "pause":
return __spreadProps(__spreadValues({}, state), {
isPaused: true
});
case "continue":
return __spreadProps(__spreadValues({}, state), {
isPaused: false
});
case "pending":
return __spreadProps(__spreadValues({}, state), {
context: action.context,
data: void 0,
failureCount: 0,
failureReason: null,
error: null,
isPaused: action.isPaused,
status: "pending",
variables: action.variables,
submittedAt: Date.now()
});
case "success":
return __spreadProps(__spreadValues({}, state), {
data: action.data,
failureCount: 0,
failureReason: null,
error: null,
status: "success",
isPaused: false
});
case "error":
return __spreadProps(__spreadValues({}, state), {
data: void 0,
error: action.error,
failureCount: state.failureCount + 1,
failureReason: action.error,
isPaused: false,
status: "error"
});
}
};
this.state = reducer(this.state);
notifyManager.batch(() => {
__privateGet(this, _observers).forEach((observer) => {
observer.onMutationUpdate(action);
});
__privateGet(this, _mutationCache).notify({
mutation: this,
type: "updated",
action
});
});
}, _a6);
function getDefaultState2() {
return {
context: void 0,
data: void 0,
error: null,
failureCount: 0,
failureReason: null,
isPaused: false,
status: "idle",
variables: void 0,
submittedAt: 0
};
}
// ../../node_modules/.pnpm/@tanstack+query-core@5.62.7/node_modules/@tanstack/query-core/build/modern/mutationCache.js
var _mutations, _mutationId, _a7;
var MutationCache = (_a7 = class extends Subscribable {
constructor(config = {}) {
super();
__privateAdd(this, _mutations);
__privateAdd(this, _mutationId);
this.config = config;
__privateSet(this, _mutations, /* @__PURE__ */ new Map());
__privateSet(this, _mutationId, Date.now());
}
build(client, options, state) {
const mutation = new Mutation({
mutationCache: this,
mutationId: ++__privateWrapper(this, _mutationId)._,
options: client.defaultMutationOptions(options),
state
});
this.add(mutation);
return mutation;
}
add(mutation) {
var _a10;
const scope = scopeFor(mutation);
const mutations = (_a10 = __privateGet(this, _mutations).get(scope)) != null ? _a10 : [];
mutations.push(mutation);
__privateGet(this, _mutations).set(scope, mutations);
this.notify({ type: "added", mutation });
}
remove(mutation) {
var _a10;
const scope = scopeFor(mutation);
if (__privateGet(this, _mutations).has(scope)) {
const mutations = (_a10 = __privateGet(this, _mutations).get(scope)) == null ? void 0 : _a10.filter((x) => x !== mutation);
if (mutations) {
if (mutations.length === 0) {
__privateGet(this, _mutations).delete(scope);
} else {
__privateGet(this, _mutations).set(scope, mutations);
}
}
}
this.notify({ type: "removed", mutation });
}
canRun(mutation) {
var _a10;
const firstPendingMutation = (_a10 = __privateGet(this, _mutations).get(scopeFor(mutation))) == null ? void 0 : _a10.find((m) => m.state.status === "pending");
return !firstPendingMutation || firstPendingMutation === mutation;
}
runNext(mutation) {
var _a10, _b2;
const foundMutation = (_a10 = __privateGet(this, _mutations).get(scopeFor(mutation))) == null ? void 0 : _a10.find((m) => m !== mutation && m.state.isPaused);
return (_b2 = foundMutation == null ? void 0 : foundMutation.continue()) != null ? _b2 : Promise.resolve();
}
clear() {
notifyManager.batch(() => {
this.getAll().forEach((mutation) => {
this.remove(mutation);
});
});
}
getAll() {
return [...__privateGet(this, _mutations).values()].flat();
}
find(filters) {
const defaultedFilters = __spreadValues({ exact: true }, filters);
return this.getAll().find(
(mutation) => matchMutation(defaultedFilters, mutation)
);
}
findAll(filters = {}) {
return this.getAll().filter((mutation) => matchMutation(filters, mutation));
}
notify(event) {
notifyManager.batch(() => {
this.listeners.forEach((listener) => {
listener(event);
});
});
}
resumePausedMutations() {
const pausedMutations = this.getAll().filter((x) => x.state.isPaused);
return notifyManager.batch(
() => Promise.all(
pausedMutations.map((mutation) => mutation.continue().catch(noop))
)
);
}
}, _mutations = new WeakMap(), _mutationId = new WeakMap(), _a7);
function scopeFor(mutation) {
var _a10, _b2;
return (_b2 = (_a10 = mutation.options.scope) == null ? void 0 : _a10.id) != null ? _b2 : String(mutation.mutationId);
}
// ../../node_modules/.pnpm/@tanstack+query-core@5.62.7/node_modules/@tanstack/query-core/build/modern/infiniteQueryBehavior.js
function infiniteQueryBehavior(pages) {
return {
onFetch: (context, query) => {
var _a10, _b2, _c, _d, _e;
const options = context.options;
const direction = (_c = (_b2 = (_a10 = context.fetchOptions) == null ? void 0 : _a10.meta) == null ? void 0 : _b2.fetchMore) == null ? void 0 : _c.direction;
const oldPages = ((_d = context.state.data) == null ? void 0 : _d.pages) || [];
c