PHP 7.4.33
Preview: query.js Size: 11.55 KB
/var/www/gtechmarathon2026.bitkit.dk/httpdocs/node_modules/@tanstack/query-core/build/modern/query.js
// src/query.ts
import {
  ensureQueryFn,
  noop,
  replaceData,
  resolveEnabled,
  resolveStaleTime,
  skipToken,
  timeUntilStale
} from "./utils.js";
import { notifyManager } from "./notifyManager.js";
import { canFetch, createRetryer, isCancelledError } from "./retryer.js";
import { Removable } from "./removable.js";
var Query = class extends Removable {
  #initialState;
  #revertState;
  #cache;
  #client;
  #retryer;
  #defaultOptions;
  #abortSignalConsumed;
  constructor(config) {
    super();
    this.#abortSignalConsumed = false;
    this.#defaultOptions = config.defaultOptions;
    this.setOptions(config.options);
    this.observers = [];
    this.#client = config.client;
    this.#cache = this.#client.getQueryCache();
    this.queryKey = config.queryKey;
    this.queryHash = config.queryHash;
    this.#initialState = getDefaultState(this.options);
    this.state = config.state ?? this.#initialState;
    this.scheduleGc();
  }
  get meta() {
    return this.options.meta;
  }
  get promise() {
    return this.#retryer?.promise;
  }
  setOptions(options) {
    this.options = { ...this.#defaultOptions, ...options };
    this.updateGcTime(this.options.gcTime);
  }
  optionalRemove() {
    if (!this.observers.length && this.state.fetchStatus === "idle") {
      this.#cache.remove(this);
    }
  }
  setData(newData, options) {
    const data = replaceData(this.state.data, newData, this.options);
    this.#dispatch({
      data,
      type: "success",
      dataUpdatedAt: options?.updatedAt,
      manual: options?.manual
    });
    return data;
  }
  setState(state, setStateOptions) {
    this.#dispatch({ type: "setState", state, setStateOptions });
  }
  cancel(options) {
    const promise = this.#retryer?.promise;
    this.#retryer?.cancel(options);
    return promise ? promise.then(noop).catch(noop) : Promise.resolve();
  }
  destroy() {
    super.destroy();
    this.cancel({ silent: true });
  }
  reset() {
    this.destroy();
    this.setState(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;
  }
  isStatic() {
    if (this.getObserversCount() > 0) {
      return this.observers.some(
        (observer) => resolveStaleTime(observer.options.staleTime, this) === "static"
      );
    }
    return false;
  }
  isStale() {
    if (this.getObserversCount() > 0) {
      return this.observers.some(
        (observer) => observer.getCurrentResult().isStale
      );
    }
    return this.state.data === void 0 || this.state.isInvalidated;
  }
  isStaleByTime(staleTime = 0) {
    if (this.state.data === void 0) {
      return true;
    }
    if (staleTime === "static") {
      return false;
    }
    if (this.state.isInvalidated) {
      return true;
    }
    return !timeUntilStale(this.state.dataUpdatedAt, staleTime);
  }
  onFocus() {
    const observer = this.observers.find((x) => x.shouldFetchOnWindowFocus());
    observer?.refetch({ cancelRefetch: false });
    this.#retryer?.continue();
  }
  onOnline() {
    const observer = this.observers.find((x) => x.shouldFetchOnReconnect());
    observer?.refetch({ cancelRefetch: false });
    this.#retryer?.continue();
  }
  addObserver(observer) {
    if (!this.observers.includes(observer)) {
      this.observers.push(observer);
      this.clearGcTimeout();
      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 (this.#retryer) {
          if (this.#abortSignalConsumed) {
            this.#retryer.cancel({ revert: true });
          } else {
            this.#retryer.cancelRetry();
          }
        }
        this.scheduleGc();
      }
      this.#cache.notify({ type: "observerRemoved", query: this, observer });
    }
  }
  getObserversCount() {
    return this.observers.length;
  }
  invalidate() {
    if (!this.state.isInvalidated) {
      this.#dispatch({ type: "invalidate" });
    }
  }
  fetch(options, fetchOptions) {
    if (this.state.fetchStatus !== "idle") {
      if (this.state.data !== void 0 && fetchOptions?.cancelRefetch) {
        this.cancel({ silent: true });
      } else if (this.#retryer) {
        this.#retryer.continueRetry();
        return 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: () => {
          this.#abortSignalConsumed = true;
          return abortController.signal;
        }
      });
    };
    const fetchFn = () => {
      const queryFn = ensureQueryFn(this.options, fetchOptions);
      const createQueryFnContext = () => {
        const queryFnContext2 = {
          client: this.#client,
          queryKey: this.queryKey,
          meta: this.meta
        };
        addSignalProperty(queryFnContext2);
        return queryFnContext2;
      };
      const queryFnContext = createQueryFnContext();
      this.#abortSignalConsumed = false;
      if (this.options.persister) {
        return this.options.persister(
          queryFn,
          queryFnContext,
          this
        );
      }
      return queryFn(queryFnContext);
    };
    const createFetchContext = () => {
      const context2 = {
        fetchOptions,
        options: this.options,
        queryKey: this.queryKey,
        client: this.#client,
        state: this.state,
        fetchFn
      };
      addSignalProperty(context2);
      return context2;
    };
    const context = createFetchContext();
    this.options.behavior?.onFetch(context, this);
    this.#revertState = this.state;
    if (this.state.fetchStatus === "idle" || this.state.fetchMeta !== context.fetchOptions?.meta) {
      this.#dispatch({ type: "fetch", meta: context.fetchOptions?.meta });
    }
    const onError = (error) => {
      if (!(isCancelledError(error) && error.silent)) {
        this.#dispatch({
          type: "error",
          error
        });
      }
      if (!isCancelledError(error)) {
        this.#cache.config.onError?.(
          error,
          this
        );
        this.#cache.config.onSettled?.(
          this.state.data,
          error,
          this
        );
      }
      this.scheduleGc();
    };
    this.#retryer = createRetryer({
      initialPromise: fetchOptions?.initialPromise,
      fn: context.fetchFn,
      abort: abortController.abort.bind(abortController),
      onSuccess: (data) => {
        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;
        }
        this.#cache.config.onSuccess?.(data, this);
        this.#cache.config.onSettled?.(
          data,
          this.state.error,
          this
        );
        this.scheduleGc();
      },
      onError,
      onFail: (failureCount, error) => {
        this.#dispatch({ type: "failed", failureCount, error });
      },
      onPause: () => {
        this.#dispatch({ type: "pause" });
      },
      onContinue: () => {
        this.#dispatch({ type: "continue" });
      },
      retry: context.options.retry,
      retryDelay: context.options.retryDelay,
      networkMode: context.options.networkMode,
      canRun: () => true
    });
    return this.#retryer.start();
  }
  #dispatch(action) {
    const reducer = (state) => {
      switch (action.type) {
        case "failed":
          return {
            ...state,
            fetchFailureCount: action.failureCount,
            fetchFailureReason: action.error
          };
        case "pause":
          return {
            ...state,
            fetchStatus: "paused"
          };
        case "continue":
          return {
            ...state,
            fetchStatus: "fetching"
          };
        case "fetch":
          return {
            ...state,
            ...fetchState(state.data, this.options),
            fetchMeta: action.meta ?? null
          };
        case "success":
          this.#revertState = void 0;
          return {
            ...state,
            data: action.data,
            dataUpdateCount: state.dataUpdateCount + 1,
            dataUpdatedAt: action.dataUpdatedAt ?? 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 && this.#revertState) {
            return { ...this.#revertState, fetchStatus: "idle" };
          }
          return {
            ...state,
            error,
            errorUpdateCount: state.errorUpdateCount + 1,
            errorUpdatedAt: Date.now(),
            fetchFailureCount: state.fetchFailureCount + 1,
            fetchFailureReason: error,
            fetchStatus: "idle",
            status: "error"
          };
        case "invalidate":
          return {
            ...state,
            isInvalidated: true
          };
        case "setState":
          return {
            ...state,
            ...action.state
          };
      }
    };
    this.state = reducer(this.state);
    notifyManager.batch(() => {
      this.observers.forEach((observer) => {
        observer.onQueryUpdate();
      });
      this.#cache.notify({ query: this, type: "updated", action });
    });
  }
};
function fetchState(data, options) {
  return {
    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 ?? Date.now() : 0,
    error: null,
    errorUpdateCount: 0,
    errorUpdatedAt: 0,
    fetchFailureCount: 0,
    fetchFailureReason: null,
    fetchMeta: null,
    isInvalidated: false,
    status: hasData ? "success" : "pending",
    fetchStatus: "idle"
  };
}
export {
  Query,
  fetchState
};
//# sourceMappingURL=query.js.map

Directory Contents

Dirs: 0 × Files: 134
Name Size Perms Modified Actions
2.65 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.35 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
563 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
562 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.56 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.31 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
70.04 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
70.04 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
6.44 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
11.47 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
265 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
262 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
5.26 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
11.42 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
4.33 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.10 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.67 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.67 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.68 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.11 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
5.33 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
8.04 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
744 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
741 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
4.18 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
8.00 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.39 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
6.28 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.31 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.31 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.21 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
6.27 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
7.19 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
13.51 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
170 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
167 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
6.09 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
13.48 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
4.66 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
9.78 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
149 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
146 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.48 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
9.75 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
4.30 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
7.07 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
121 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
118 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.16 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
7.05 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.04 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.70 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.15 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.15 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.93 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.65 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.54 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.93 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
522 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
521 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.45 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.89 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
6.83 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
11.77 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.55 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.55 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
5.69 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
11.75 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
12.71 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
27.12 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
282 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
279 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
11.55 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
27.16 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.53 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
7.75 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
161 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
158 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.36 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
7.73 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
10.82 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
23.29 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
116 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
113 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
9.33 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
23.33 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
17.24 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
33.24 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
118 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
115 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
15.74 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
33.28 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.69 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.46 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
299 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
299 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
686 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.42 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
4.79 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
8.18 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
235 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
232 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.56 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
8.14 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.28 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.72 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.54 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.53 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.22 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.68 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.52 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.07 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
294 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
294 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
522 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.03 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.02 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.77 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.79 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.79 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
961 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
3.72 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
1.32 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
40.32 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.61 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
2.60 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
255 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
40.26 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
8.54 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
16.51 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
674 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
671 B lrw-r--r-- 2025-07-14 06:33:17
Edit Download
6.71 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
16.35 KB lrw-r--r-- 2025-07-14 06:33:17
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).