| [a762898] | 1 | var __defProp = Object.defineProperty;
|
|---|
| 2 | var __defProps = Object.defineProperties;
|
|---|
| 3 | var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|---|
| 4 | var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|---|
| 5 | var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|---|
| 6 | var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|---|
| 7 | var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|---|
| 8 | var __spreadValues = (a, b) => {
|
|---|
| 9 | for (var prop in b || (b = {}))
|
|---|
| 10 | if (__hasOwnProp.call(b, prop))
|
|---|
| 11 | __defNormalProp(a, prop, b[prop]);
|
|---|
| 12 | if (__getOwnPropSymbols)
|
|---|
| 13 | for (var prop of __getOwnPropSymbols(b)) {
|
|---|
| 14 | if (__propIsEnum.call(b, prop))
|
|---|
| 15 | __defNormalProp(a, prop, b[prop]);
|
|---|
| 16 | }
|
|---|
| 17 | return a;
|
|---|
| 18 | };
|
|---|
| 19 | var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|---|
| 20 | var __restKey = (key) => typeof key === "symbol" ? key : key + "";
|
|---|
| 21 | var __objRest = (source, exclude) => {
|
|---|
| 22 | var target = {};
|
|---|
| 23 | for (var prop in source)
|
|---|
| 24 | if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|---|
| 25 | target[prop] = source[prop];
|
|---|
| 26 | if (source != null && __getOwnPropSymbols)
|
|---|
| 27 | for (var prop of __getOwnPropSymbols(source)) {
|
|---|
| 28 | if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|---|
| 29 | target[prop] = source[prop];
|
|---|
| 30 | }
|
|---|
| 31 | return target;
|
|---|
| 32 | };
|
|---|
| 33 |
|
|---|
| 34 | // src/query/core/apiState.ts
|
|---|
| 35 | var QueryStatus = /* @__PURE__ */ ((QueryStatus7) => {
|
|---|
| 36 | QueryStatus7["uninitialized"] = "uninitialized";
|
|---|
| 37 | QueryStatus7["pending"] = "pending";
|
|---|
| 38 | QueryStatus7["fulfilled"] = "fulfilled";
|
|---|
| 39 | QueryStatus7["rejected"] = "rejected";
|
|---|
| 40 | return QueryStatus7;
|
|---|
| 41 | })(QueryStatus || {});
|
|---|
| 42 | var STATUS_UNINITIALIZED = "uninitialized" /* uninitialized */;
|
|---|
| 43 | var STATUS_PENDING = "pending" /* pending */;
|
|---|
| 44 | var STATUS_FULFILLED = "fulfilled" /* fulfilled */;
|
|---|
| 45 | var STATUS_REJECTED = "rejected" /* rejected */;
|
|---|
| 46 | function getRequestStatusFlags(status) {
|
|---|
| 47 | return {
|
|---|
| 48 | status,
|
|---|
| 49 | isUninitialized: status === STATUS_UNINITIALIZED,
|
|---|
| 50 | isLoading: status === STATUS_PENDING,
|
|---|
| 51 | isSuccess: status === STATUS_FULFILLED,
|
|---|
| 52 | isError: status === STATUS_REJECTED
|
|---|
| 53 | };
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | // src/query/core/rtkImports.ts
|
|---|
| 57 | import { createAction, createSlice, createSelector, createAsyncThunk, combineReducers, createNextState, isAnyOf, isAllOf, isAction, isPending, isRejected, isFulfilled, isRejectedWithValue, isAsyncThunkAction, prepareAutoBatched, SHOULD_AUTOBATCH, isPlainObject, nanoid } from "@reduxjs/toolkit";
|
|---|
| 58 |
|
|---|
| 59 | // src/query/utils/copyWithStructuralSharing.ts
|
|---|
| 60 | var isPlainObject2 = isPlainObject;
|
|---|
| 61 | function copyWithStructuralSharing(oldObj, newObj) {
|
|---|
| 62 | if (oldObj === newObj || !(isPlainObject2(oldObj) && isPlainObject2(newObj) || Array.isArray(oldObj) && Array.isArray(newObj))) {
|
|---|
| 63 | return newObj;
|
|---|
| 64 | }
|
|---|
| 65 | const newKeys = Object.keys(newObj);
|
|---|
| 66 | const oldKeys = Object.keys(oldObj);
|
|---|
| 67 | let isSameObject = newKeys.length === oldKeys.length;
|
|---|
| 68 | const mergeObj = Array.isArray(newObj) ? [] : {};
|
|---|
| 69 | for (const key of newKeys) {
|
|---|
| 70 | mergeObj[key] = copyWithStructuralSharing(oldObj[key], newObj[key]);
|
|---|
| 71 | if (isSameObject) isSameObject = oldObj[key] === mergeObj[key];
|
|---|
| 72 | }
|
|---|
| 73 | return isSameObject ? oldObj : mergeObj;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | // src/query/utils/filterMap.ts
|
|---|
| 77 | function filterMap(array, predicate, mapper) {
|
|---|
| 78 | return array.reduce((acc, item, i) => {
|
|---|
| 79 | if (predicate(item, i)) {
|
|---|
| 80 | acc.push(mapper(item, i));
|
|---|
| 81 | }
|
|---|
| 82 | return acc;
|
|---|
| 83 | }, []).flat();
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | // src/query/utils/isAbsoluteUrl.ts
|
|---|
| 87 | function isAbsoluteUrl(url) {
|
|---|
| 88 | return new RegExp(`(^|:)//`).test(url);
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | // src/query/utils/isDocumentVisible.ts
|
|---|
| 92 | function isDocumentVisible() {
|
|---|
| 93 | if (typeof document === "undefined") {
|
|---|
| 94 | return true;
|
|---|
| 95 | }
|
|---|
| 96 | return document.visibilityState !== "hidden";
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | // src/query/utils/isNotNullish.ts
|
|---|
| 100 | function isNotNullish(v) {
|
|---|
| 101 | return v != null;
|
|---|
| 102 | }
|
|---|
| 103 | function filterNullishValues(map) {
|
|---|
| 104 | var _a;
|
|---|
| 105 | return [...(_a = map == null ? void 0 : map.values()) != null ? _a : []].filter(isNotNullish);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | // src/query/utils/isOnline.ts
|
|---|
| 109 | function isOnline() {
|
|---|
| 110 | return typeof navigator === "undefined" ? true : navigator.onLine === void 0 ? true : navigator.onLine;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | // src/query/utils/joinUrls.ts
|
|---|
| 114 | var withoutTrailingSlash = (url) => url.replace(/\/$/, "");
|
|---|
| 115 | var withoutLeadingSlash = (url) => url.replace(/^\//, "");
|
|---|
| 116 | function joinUrls(base, url) {
|
|---|
| 117 | if (!base) {
|
|---|
| 118 | return url;
|
|---|
| 119 | }
|
|---|
| 120 | if (!url) {
|
|---|
| 121 | return base;
|
|---|
| 122 | }
|
|---|
| 123 | if (isAbsoluteUrl(url)) {
|
|---|
| 124 | return url;
|
|---|
| 125 | }
|
|---|
| 126 | const delimiter = base.endsWith("/") || !url.startsWith("?") ? "/" : "";
|
|---|
| 127 | base = withoutTrailingSlash(base);
|
|---|
| 128 | url = withoutLeadingSlash(url);
|
|---|
| 129 | return `${base}${delimiter}${url}`;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | // src/query/utils/getOrInsert.ts
|
|---|
| 133 | function getOrInsertComputed(map, key, compute) {
|
|---|
| 134 | if (map.has(key)) return map.get(key);
|
|---|
| 135 | return map.set(key, compute(key)).get(key);
|
|---|
| 136 | }
|
|---|
| 137 | var createNewMap = () => /* @__PURE__ */ new Map();
|
|---|
| 138 |
|
|---|
| 139 | // src/query/utils/signals.ts
|
|---|
| 140 | var timeoutSignal = (milliseconds) => {
|
|---|
| 141 | const abortController = new AbortController();
|
|---|
| 142 | setTimeout(() => {
|
|---|
| 143 | const message = "signal timed out";
|
|---|
| 144 | const name = "TimeoutError";
|
|---|
| 145 | abortController.abort(
|
|---|
| 146 | // some environments (React Native, Node) don't have DOMException
|
|---|
| 147 | typeof DOMException !== "undefined" ? new DOMException(message, name) : Object.assign(new Error(message), {
|
|---|
| 148 | name
|
|---|
| 149 | })
|
|---|
| 150 | );
|
|---|
| 151 | }, milliseconds);
|
|---|
| 152 | return abortController.signal;
|
|---|
| 153 | };
|
|---|
| 154 | var anySignal = (...signals) => {
|
|---|
| 155 | for (const signal of signals) if (signal.aborted) return AbortSignal.abort(signal.reason);
|
|---|
| 156 | const abortController = new AbortController();
|
|---|
| 157 | for (const signal of signals) {
|
|---|
| 158 | signal.addEventListener("abort", () => abortController.abort(signal.reason), {
|
|---|
| 159 | signal: abortController.signal,
|
|---|
| 160 | once: true
|
|---|
| 161 | });
|
|---|
| 162 | }
|
|---|
| 163 | return abortController.signal;
|
|---|
| 164 | };
|
|---|
| 165 |
|
|---|
| 166 | // src/query/fetchBaseQuery.ts
|
|---|
| 167 | var defaultFetchFn = (...args) => fetch(...args);
|
|---|
| 168 | var defaultValidateStatus = (response) => response.status >= 200 && response.status <= 299;
|
|---|
| 169 | var defaultIsJsonContentType = (headers) => (
|
|---|
| 170 | /*applicat*/
|
|---|
| 171 | /ion\/(vnd\.api\+)?json/.test(headers.get("content-type") || "")
|
|---|
| 172 | );
|
|---|
| 173 | function stripUndefined(obj) {
|
|---|
| 174 | if (!isPlainObject(obj)) {
|
|---|
| 175 | return obj;
|
|---|
| 176 | }
|
|---|
| 177 | const copy = __spreadValues({}, obj);
|
|---|
| 178 | for (const [k, v] of Object.entries(copy)) {
|
|---|
| 179 | if (v === void 0) delete copy[k];
|
|---|
| 180 | }
|
|---|
| 181 | return copy;
|
|---|
| 182 | }
|
|---|
| 183 | var isJsonifiable = (body) => typeof body === "object" && (isPlainObject(body) || Array.isArray(body) || typeof body.toJSON === "function");
|
|---|
| 184 | function fetchBaseQuery(_a = {}) {
|
|---|
| 185 | var _b = _a, {
|
|---|
| 186 | baseUrl,
|
|---|
| 187 | prepareHeaders = (x) => x,
|
|---|
| 188 | fetchFn = defaultFetchFn,
|
|---|
| 189 | paramsSerializer,
|
|---|
| 190 | isJsonContentType = defaultIsJsonContentType,
|
|---|
| 191 | jsonContentType = "application/json",
|
|---|
| 192 | jsonReplacer,
|
|---|
| 193 | timeout: defaultTimeout,
|
|---|
| 194 | responseHandler: globalResponseHandler,
|
|---|
| 195 | validateStatus: globalValidateStatus
|
|---|
| 196 | } = _b, baseFetchOptions = __objRest(_b, [
|
|---|
| 197 | "baseUrl",
|
|---|
| 198 | "prepareHeaders",
|
|---|
| 199 | "fetchFn",
|
|---|
| 200 | "paramsSerializer",
|
|---|
| 201 | "isJsonContentType",
|
|---|
| 202 | "jsonContentType",
|
|---|
| 203 | "jsonReplacer",
|
|---|
| 204 | "timeout",
|
|---|
| 205 | "responseHandler",
|
|---|
| 206 | "validateStatus"
|
|---|
| 207 | ]);
|
|---|
| 208 | if (typeof fetch === "undefined" && fetchFn === defaultFetchFn) {
|
|---|
| 209 | console.warn("Warning: `fetch` is not available. Please supply a custom `fetchFn` property to use `fetchBaseQuery` on SSR environments.");
|
|---|
| 210 | }
|
|---|
| 211 | return async (arg, api, extraOptions) => {
|
|---|
| 212 | const {
|
|---|
| 213 | getState,
|
|---|
| 214 | extra,
|
|---|
| 215 | endpoint,
|
|---|
| 216 | forced,
|
|---|
| 217 | type
|
|---|
| 218 | } = api;
|
|---|
| 219 | let meta;
|
|---|
| 220 | let _a2 = typeof arg == "string" ? {
|
|---|
| 221 | url: arg
|
|---|
| 222 | } : arg, {
|
|---|
| 223 | url,
|
|---|
| 224 | headers = new Headers(baseFetchOptions.headers),
|
|---|
| 225 | params = void 0,
|
|---|
| 226 | responseHandler = globalResponseHandler != null ? globalResponseHandler : "json",
|
|---|
| 227 | validateStatus = globalValidateStatus != null ? globalValidateStatus : defaultValidateStatus,
|
|---|
| 228 | timeout = defaultTimeout
|
|---|
| 229 | } = _a2, rest = __objRest(_a2, [
|
|---|
| 230 | "url",
|
|---|
| 231 | "headers",
|
|---|
| 232 | "params",
|
|---|
| 233 | "responseHandler",
|
|---|
| 234 | "validateStatus",
|
|---|
| 235 | "timeout"
|
|---|
| 236 | ]);
|
|---|
| 237 | let config = __spreadValues(__spreadProps(__spreadValues({}, baseFetchOptions), {
|
|---|
| 238 | signal: timeout ? anySignal(api.signal, timeoutSignal(timeout)) : api.signal
|
|---|
| 239 | }), rest);
|
|---|
| 240 | headers = new Headers(stripUndefined(headers));
|
|---|
| 241 | config.headers = await prepareHeaders(headers, {
|
|---|
| 242 | getState,
|
|---|
| 243 | arg,
|
|---|
| 244 | extra,
|
|---|
| 245 | endpoint,
|
|---|
| 246 | forced,
|
|---|
| 247 | type,
|
|---|
| 248 | extraOptions
|
|---|
| 249 | }) || headers;
|
|---|
| 250 | const bodyIsJsonifiable = isJsonifiable(config.body);
|
|---|
| 251 | if (config.body != null && !bodyIsJsonifiable && typeof config.body !== "string") {
|
|---|
| 252 | config.headers.delete("content-type");
|
|---|
| 253 | }
|
|---|
| 254 | if (!config.headers.has("content-type") && bodyIsJsonifiable) {
|
|---|
| 255 | config.headers.set("content-type", jsonContentType);
|
|---|
| 256 | }
|
|---|
| 257 | if (bodyIsJsonifiable && isJsonContentType(config.headers)) {
|
|---|
| 258 | config.body = JSON.stringify(config.body, jsonReplacer);
|
|---|
| 259 | }
|
|---|
| 260 | if (!config.headers.has("accept")) {
|
|---|
| 261 | if (responseHandler === "json") {
|
|---|
| 262 | config.headers.set("accept", "application/json");
|
|---|
| 263 | } else if (responseHandler === "text") {
|
|---|
| 264 | config.headers.set("accept", "text/plain, text/html, */*");
|
|---|
| 265 | }
|
|---|
| 266 | }
|
|---|
| 267 | if (params) {
|
|---|
| 268 | const divider = ~url.indexOf("?") ? "&" : "?";
|
|---|
| 269 | const query = paramsSerializer ? paramsSerializer(params) : new URLSearchParams(stripUndefined(params));
|
|---|
| 270 | url += divider + query;
|
|---|
| 271 | }
|
|---|
| 272 | url = joinUrls(baseUrl, url);
|
|---|
| 273 | const request = new Request(url, config);
|
|---|
| 274 | const requestClone = new Request(url, config);
|
|---|
| 275 | meta = {
|
|---|
| 276 | request: requestClone
|
|---|
| 277 | };
|
|---|
| 278 | let response;
|
|---|
| 279 | try {
|
|---|
| 280 | response = await fetchFn(request);
|
|---|
| 281 | } catch (e) {
|
|---|
| 282 | return {
|
|---|
| 283 | error: {
|
|---|
| 284 | status: (e instanceof Error || typeof DOMException !== "undefined" && e instanceof DOMException) && e.name === "TimeoutError" ? "TIMEOUT_ERROR" : "FETCH_ERROR",
|
|---|
| 285 | error: String(e)
|
|---|
| 286 | },
|
|---|
| 287 | meta
|
|---|
| 288 | };
|
|---|
| 289 | }
|
|---|
| 290 | const responseClone = response.clone();
|
|---|
| 291 | meta.response = responseClone;
|
|---|
| 292 | let resultData;
|
|---|
| 293 | let responseText = "";
|
|---|
| 294 | try {
|
|---|
| 295 | let handleResponseError;
|
|---|
| 296 | await Promise.all([
|
|---|
| 297 | handleResponse(response, responseHandler).then((r) => resultData = r, (e) => handleResponseError = e),
|
|---|
| 298 | // see https://github.com/node-fetch/node-fetch/issues/665#issuecomment-538995182
|
|---|
| 299 | // we *have* to "use up" both streams at the same time or they will stop running in node-fetch scenarios
|
|---|
| 300 | responseClone.text().then((r) => responseText = r, () => {
|
|---|
| 301 | })
|
|---|
| 302 | ]);
|
|---|
| 303 | if (handleResponseError) throw handleResponseError;
|
|---|
| 304 | } catch (e) {
|
|---|
| 305 | return {
|
|---|
| 306 | error: {
|
|---|
| 307 | status: "PARSING_ERROR",
|
|---|
| 308 | originalStatus: response.status,
|
|---|
| 309 | data: responseText,
|
|---|
| 310 | error: String(e)
|
|---|
| 311 | },
|
|---|
| 312 | meta
|
|---|
| 313 | };
|
|---|
| 314 | }
|
|---|
| 315 | return validateStatus(response, resultData) ? {
|
|---|
| 316 | data: resultData,
|
|---|
| 317 | meta
|
|---|
| 318 | } : {
|
|---|
| 319 | error: {
|
|---|
| 320 | status: response.status,
|
|---|
| 321 | data: resultData
|
|---|
| 322 | },
|
|---|
| 323 | meta
|
|---|
| 324 | };
|
|---|
| 325 | };
|
|---|
| 326 | async function handleResponse(response, responseHandler) {
|
|---|
| 327 | if (typeof responseHandler === "function") {
|
|---|
| 328 | return responseHandler(response);
|
|---|
| 329 | }
|
|---|
| 330 | if (responseHandler === "content-type") {
|
|---|
| 331 | responseHandler = isJsonContentType(response.headers) ? "json" : "text";
|
|---|
| 332 | }
|
|---|
| 333 | if (responseHandler === "json") {
|
|---|
| 334 | const text = await response.text();
|
|---|
| 335 | return text.length ? JSON.parse(text) : null;
|
|---|
| 336 | }
|
|---|
| 337 | return response.text();
|
|---|
| 338 | }
|
|---|
| 339 | }
|
|---|
| 340 |
|
|---|
| 341 | // src/query/HandledError.ts
|
|---|
| 342 | var HandledError = class {
|
|---|
| 343 | constructor(value, meta = void 0) {
|
|---|
| 344 | this.value = value;
|
|---|
| 345 | this.meta = meta;
|
|---|
| 346 | }
|
|---|
| 347 | };
|
|---|
| 348 |
|
|---|
| 349 | // src/query/retry.ts
|
|---|
| 350 | async function defaultBackoff(attempt = 0, maxRetries = 5, signal) {
|
|---|
| 351 | const attempts = Math.min(attempt, maxRetries);
|
|---|
| 352 | const timeout = ~~((Math.random() + 0.4) * (300 << attempts));
|
|---|
| 353 | await new Promise((resolve, reject) => {
|
|---|
| 354 | const timeoutId = setTimeout(() => resolve(), timeout);
|
|---|
| 355 | if (signal) {
|
|---|
| 356 | const abortHandler = () => {
|
|---|
| 357 | clearTimeout(timeoutId);
|
|---|
| 358 | reject(new Error("Aborted"));
|
|---|
| 359 | };
|
|---|
| 360 | if (signal.aborted) {
|
|---|
| 361 | clearTimeout(timeoutId);
|
|---|
| 362 | reject(new Error("Aborted"));
|
|---|
| 363 | } else {
|
|---|
| 364 | signal.addEventListener("abort", abortHandler, {
|
|---|
| 365 | once: true
|
|---|
| 366 | });
|
|---|
| 367 | }
|
|---|
| 368 | }
|
|---|
| 369 | });
|
|---|
| 370 | }
|
|---|
| 371 | function fail(error, meta) {
|
|---|
| 372 | throw Object.assign(new HandledError({
|
|---|
| 373 | error,
|
|---|
| 374 | meta
|
|---|
| 375 | }), {
|
|---|
| 376 | throwImmediately: true
|
|---|
| 377 | });
|
|---|
| 378 | }
|
|---|
| 379 | function failIfAborted(signal) {
|
|---|
| 380 | if (signal.aborted) {
|
|---|
| 381 | fail({
|
|---|
| 382 | status: "CUSTOM_ERROR",
|
|---|
| 383 | error: "Aborted"
|
|---|
| 384 | });
|
|---|
| 385 | }
|
|---|
| 386 | }
|
|---|
| 387 | var EMPTY_OPTIONS = {};
|
|---|
| 388 | var retryWithBackoff = (baseQuery, defaultOptions) => async (args, api, extraOptions) => {
|
|---|
| 389 | const possibleMaxRetries = [5, (defaultOptions || EMPTY_OPTIONS).maxRetries, (extraOptions || EMPTY_OPTIONS).maxRetries].filter((x) => x !== void 0);
|
|---|
| 390 | const [maxRetries] = possibleMaxRetries.slice(-1);
|
|---|
| 391 | const defaultRetryCondition = (_, __, {
|
|---|
| 392 | attempt
|
|---|
| 393 | }) => attempt <= maxRetries;
|
|---|
| 394 | const options = __spreadValues(__spreadValues({
|
|---|
| 395 | maxRetries,
|
|---|
| 396 | backoff: defaultBackoff,
|
|---|
| 397 | retryCondition: defaultRetryCondition
|
|---|
| 398 | }, defaultOptions), extraOptions);
|
|---|
| 399 | let retry2 = 0;
|
|---|
| 400 | while (true) {
|
|---|
| 401 | failIfAborted(api.signal);
|
|---|
| 402 | try {
|
|---|
| 403 | const result = await baseQuery(args, api, extraOptions);
|
|---|
| 404 | if (result.error) {
|
|---|
| 405 | throw new HandledError(result);
|
|---|
| 406 | }
|
|---|
| 407 | return result;
|
|---|
| 408 | } catch (e) {
|
|---|
| 409 | retry2++;
|
|---|
| 410 | if (e.throwImmediately) {
|
|---|
| 411 | if (e instanceof HandledError) {
|
|---|
| 412 | return e.value;
|
|---|
| 413 | }
|
|---|
| 414 | throw e;
|
|---|
| 415 | }
|
|---|
| 416 | if (e instanceof HandledError) {
|
|---|
| 417 | if (!options.retryCondition(e.value.error, args, {
|
|---|
| 418 | attempt: retry2,
|
|---|
| 419 | baseQueryApi: api,
|
|---|
| 420 | extraOptions
|
|---|
| 421 | })) {
|
|---|
| 422 | return e.value;
|
|---|
| 423 | }
|
|---|
| 424 | } else {
|
|---|
| 425 | if (retry2 > options.maxRetries) {
|
|---|
| 426 | return {
|
|---|
| 427 | error: e
|
|---|
| 428 | };
|
|---|
| 429 | }
|
|---|
| 430 | }
|
|---|
| 431 | failIfAborted(api.signal);
|
|---|
| 432 | try {
|
|---|
| 433 | await options.backoff(retry2, options.maxRetries, api.signal);
|
|---|
| 434 | } catch (backoffError) {
|
|---|
| 435 | failIfAborted(api.signal);
|
|---|
| 436 | throw backoffError;
|
|---|
| 437 | }
|
|---|
| 438 | }
|
|---|
| 439 | }
|
|---|
| 440 | };
|
|---|
| 441 | var retry = /* @__PURE__ */ Object.assign(retryWithBackoff, {
|
|---|
| 442 | fail
|
|---|
| 443 | });
|
|---|
| 444 |
|
|---|
| 445 | // src/query/core/setupListeners.ts
|
|---|
| 446 | var INTERNAL_PREFIX = "__rtkq/";
|
|---|
| 447 | var ONLINE = "online";
|
|---|
| 448 | var OFFLINE = "offline";
|
|---|
| 449 | var FOCUS = "focus";
|
|---|
| 450 | var FOCUSED = "focused";
|
|---|
| 451 | var VISIBILITYCHANGE = "visibilitychange";
|
|---|
| 452 | var onFocus = /* @__PURE__ */ createAction(`${INTERNAL_PREFIX}${FOCUSED}`);
|
|---|
| 453 | var onFocusLost = /* @__PURE__ */ createAction(`${INTERNAL_PREFIX}un${FOCUSED}`);
|
|---|
| 454 | var onOnline = /* @__PURE__ */ createAction(`${INTERNAL_PREFIX}${ONLINE}`);
|
|---|
| 455 | var onOffline = /* @__PURE__ */ createAction(`${INTERNAL_PREFIX}${OFFLINE}`);
|
|---|
| 456 | var actions = {
|
|---|
| 457 | onFocus,
|
|---|
| 458 | onFocusLost,
|
|---|
| 459 | onOnline,
|
|---|
| 460 | onOffline
|
|---|
| 461 | };
|
|---|
| 462 | var initialized = false;
|
|---|
| 463 | function setupListeners(dispatch, customHandler) {
|
|---|
| 464 | function defaultHandler() {
|
|---|
| 465 | const [handleFocus, handleFocusLost, handleOnline, handleOffline] = [onFocus, onFocusLost, onOnline, onOffline].map((action) => () => dispatch(action()));
|
|---|
| 466 | const handleVisibilityChange = () => {
|
|---|
| 467 | if (window.document.visibilityState === "visible") {
|
|---|
| 468 | handleFocus();
|
|---|
| 469 | } else {
|
|---|
| 470 | handleFocusLost();
|
|---|
| 471 | }
|
|---|
| 472 | };
|
|---|
| 473 | let unsubscribe = () => {
|
|---|
| 474 | initialized = false;
|
|---|
| 475 | };
|
|---|
| 476 | if (!initialized) {
|
|---|
| 477 | if (typeof window !== "undefined" && window.addEventListener) {
|
|---|
| 478 | let updateListeners2 = function(add) {
|
|---|
| 479 | Object.entries(handlers).forEach(([event, handler]) => {
|
|---|
| 480 | if (add) {
|
|---|
| 481 | window.addEventListener(event, handler, false);
|
|---|
| 482 | } else {
|
|---|
| 483 | window.removeEventListener(event, handler);
|
|---|
| 484 | }
|
|---|
| 485 | });
|
|---|
| 486 | };
|
|---|
| 487 | var updateListeners = updateListeners2;
|
|---|
| 488 | const handlers = {
|
|---|
| 489 | [FOCUS]: handleFocus,
|
|---|
| 490 | [VISIBILITYCHANGE]: handleVisibilityChange,
|
|---|
| 491 | [ONLINE]: handleOnline,
|
|---|
| 492 | [OFFLINE]: handleOffline
|
|---|
| 493 | };
|
|---|
| 494 | updateListeners2(true);
|
|---|
| 495 | initialized = true;
|
|---|
| 496 | unsubscribe = () => {
|
|---|
| 497 | updateListeners2(false);
|
|---|
| 498 | initialized = false;
|
|---|
| 499 | };
|
|---|
| 500 | }
|
|---|
| 501 | }
|
|---|
| 502 | return unsubscribe;
|
|---|
| 503 | }
|
|---|
| 504 | return customHandler ? customHandler(dispatch, actions) : defaultHandler();
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 | // src/query/endpointDefinitions.ts
|
|---|
| 508 | var ENDPOINT_QUERY = "query" /* query */;
|
|---|
| 509 | var ENDPOINT_MUTATION = "mutation" /* mutation */;
|
|---|
| 510 | var ENDPOINT_INFINITEQUERY = "infinitequery" /* infinitequery */;
|
|---|
| 511 | function isQueryDefinition(e) {
|
|---|
| 512 | return e.type === ENDPOINT_QUERY;
|
|---|
| 513 | }
|
|---|
| 514 | function isMutationDefinition(e) {
|
|---|
| 515 | return e.type === ENDPOINT_MUTATION;
|
|---|
| 516 | }
|
|---|
| 517 | function isInfiniteQueryDefinition(e) {
|
|---|
| 518 | return e.type === ENDPOINT_INFINITEQUERY;
|
|---|
| 519 | }
|
|---|
| 520 | function isAnyQueryDefinition(e) {
|
|---|
| 521 | return isQueryDefinition(e) || isInfiniteQueryDefinition(e);
|
|---|
| 522 | }
|
|---|
| 523 | function calculateProvidedBy(description, result, error, queryArg, meta, assertTagTypes) {
|
|---|
| 524 | const finalDescription = isFunction(description) ? description(result, error, queryArg, meta) : description;
|
|---|
| 525 | if (finalDescription) {
|
|---|
| 526 | return filterMap(finalDescription, isNotNullish, (tag) => assertTagTypes(expandTagDescription(tag)));
|
|---|
| 527 | }
|
|---|
| 528 | return [];
|
|---|
| 529 | }
|
|---|
| 530 | function isFunction(t) {
|
|---|
| 531 | return typeof t === "function";
|
|---|
| 532 | }
|
|---|
| 533 | function expandTagDescription(description) {
|
|---|
| 534 | return typeof description === "string" ? {
|
|---|
| 535 | type: description
|
|---|
| 536 | } : description;
|
|---|
| 537 | }
|
|---|
| 538 |
|
|---|
| 539 | // src/query/utils/immerImports.ts
|
|---|
| 540 | import { current, isDraft, applyPatches, original, isDraftable, produceWithPatches, enablePatches } from "immer";
|
|---|
| 541 |
|
|---|
| 542 | // src/query/core/buildInitiate.ts
|
|---|
| 543 | import { formatProdErrorMessage as _formatProdErrorMessage } from "@reduxjs/toolkit";
|
|---|
| 544 |
|
|---|
| 545 | // src/tsHelpers.ts
|
|---|
| 546 | function asSafePromise(promise, fallback) {
|
|---|
| 547 | return promise.catch(fallback);
|
|---|
| 548 | }
|
|---|
| 549 |
|
|---|
| 550 | // src/query/apiTypes.ts
|
|---|
| 551 | var getEndpointDefinition = (context, endpointName) => context.endpointDefinitions[endpointName];
|
|---|
| 552 |
|
|---|
| 553 | // src/query/core/buildInitiate.ts
|
|---|
| 554 | var forceQueryFnSymbol = Symbol("forceQueryFn");
|
|---|
| 555 | var isUpsertQuery = (arg) => typeof arg[forceQueryFnSymbol] === "function";
|
|---|
| 556 | function buildInitiate({
|
|---|
| 557 | serializeQueryArgs,
|
|---|
| 558 | queryThunk,
|
|---|
| 559 | infiniteQueryThunk,
|
|---|
| 560 | mutationThunk,
|
|---|
| 561 | api,
|
|---|
| 562 | context,
|
|---|
| 563 | getInternalState
|
|---|
| 564 | }) {
|
|---|
| 565 | const getRunningQueries = (dispatch) => {
|
|---|
| 566 | var _a;
|
|---|
| 567 | return (_a = getInternalState(dispatch)) == null ? void 0 : _a.runningQueries;
|
|---|
| 568 | };
|
|---|
| 569 | const getRunningMutations = (dispatch) => {
|
|---|
| 570 | var _a;
|
|---|
| 571 | return (_a = getInternalState(dispatch)) == null ? void 0 : _a.runningMutations;
|
|---|
| 572 | };
|
|---|
| 573 | const {
|
|---|
| 574 | unsubscribeQueryResult,
|
|---|
| 575 | removeMutationResult,
|
|---|
| 576 | updateSubscriptionOptions
|
|---|
| 577 | } = api.internalActions;
|
|---|
| 578 | return {
|
|---|
| 579 | buildInitiateQuery,
|
|---|
| 580 | buildInitiateInfiniteQuery,
|
|---|
| 581 | buildInitiateMutation,
|
|---|
| 582 | getRunningQueryThunk,
|
|---|
| 583 | getRunningMutationThunk,
|
|---|
| 584 | getRunningQueriesThunk,
|
|---|
| 585 | getRunningMutationsThunk
|
|---|
| 586 | };
|
|---|
| 587 | function getRunningQueryThunk(endpointName, queryArgs) {
|
|---|
| 588 | return (dispatch) => {
|
|---|
| 589 | var _a;
|
|---|
| 590 | const endpointDefinition = getEndpointDefinition(context, endpointName);
|
|---|
| 591 | const queryCacheKey = serializeQueryArgs({
|
|---|
| 592 | queryArgs,
|
|---|
| 593 | endpointDefinition,
|
|---|
| 594 | endpointName
|
|---|
| 595 | });
|
|---|
| 596 | return (_a = getRunningQueries(dispatch)) == null ? void 0 : _a.get(queryCacheKey);
|
|---|
| 597 | };
|
|---|
| 598 | }
|
|---|
| 599 | function getRunningMutationThunk(_endpointName, fixedCacheKeyOrRequestId) {
|
|---|
| 600 | return (dispatch) => {
|
|---|
| 601 | var _a;
|
|---|
| 602 | return (_a = getRunningMutations(dispatch)) == null ? void 0 : _a.get(fixedCacheKeyOrRequestId);
|
|---|
| 603 | };
|
|---|
| 604 | }
|
|---|
| 605 | function getRunningQueriesThunk() {
|
|---|
| 606 | return (dispatch) => filterNullishValues(getRunningQueries(dispatch));
|
|---|
| 607 | }
|
|---|
| 608 | function getRunningMutationsThunk() {
|
|---|
| 609 | return (dispatch) => filterNullishValues(getRunningMutations(dispatch));
|
|---|
| 610 | }
|
|---|
| 611 | function middlewareWarning(dispatch) {
|
|---|
| 612 | if (process.env.NODE_ENV !== "production") {
|
|---|
| 613 | if (middlewareWarning.triggered) return;
|
|---|
| 614 | const returnedValue = dispatch(api.internalActions.internal_getRTKQSubscriptions());
|
|---|
| 615 | middlewareWarning.triggered = true;
|
|---|
| 616 | if (typeof returnedValue !== "object" || typeof (returnedValue == null ? void 0 : returnedValue.type) === "string") {
|
|---|
| 617 | throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage(34) : `Warning: Middleware for RTK-Query API at reducerPath "${api.reducerPath}" has not been added to the store.
|
|---|
| 618 | You must add the middleware for RTK-Query to function correctly!`);
|
|---|
| 619 | }
|
|---|
| 620 | }
|
|---|
| 621 | }
|
|---|
| 622 | function buildInitiateAnyQuery(endpointName, endpointDefinition) {
|
|---|
| 623 | const queryAction = (arg, _a = {}) => {
|
|---|
| 624 | var _b = _a, {
|
|---|
| 625 | subscribe = true,
|
|---|
| 626 | forceRefetch,
|
|---|
| 627 | subscriptionOptions,
|
|---|
| 628 | [forceQueryFnSymbol]: forceQueryFn
|
|---|
| 629 | } = _b, rest = __objRest(_b, [
|
|---|
| 630 | "subscribe",
|
|---|
| 631 | "forceRefetch",
|
|---|
| 632 | "subscriptionOptions",
|
|---|
| 633 | __restKey(forceQueryFnSymbol)
|
|---|
| 634 | ]);
|
|---|
| 635 | return (dispatch, getState) => {
|
|---|
| 636 | var _a2;
|
|---|
| 637 | const queryCacheKey = serializeQueryArgs({
|
|---|
| 638 | queryArgs: arg,
|
|---|
| 639 | endpointDefinition,
|
|---|
| 640 | endpointName
|
|---|
| 641 | });
|
|---|
| 642 | let thunk;
|
|---|
| 643 | const commonThunkArgs = __spreadProps(__spreadValues({}, rest), {
|
|---|
| 644 | type: ENDPOINT_QUERY,
|
|---|
| 645 | subscribe,
|
|---|
| 646 | forceRefetch,
|
|---|
| 647 | subscriptionOptions,
|
|---|
| 648 | endpointName,
|
|---|
| 649 | originalArgs: arg,
|
|---|
| 650 | queryCacheKey,
|
|---|
| 651 | [forceQueryFnSymbol]: forceQueryFn
|
|---|
| 652 | });
|
|---|
| 653 | if (isQueryDefinition(endpointDefinition)) {
|
|---|
| 654 | thunk = queryThunk(commonThunkArgs);
|
|---|
| 655 | } else {
|
|---|
| 656 | const {
|
|---|
| 657 | direction,
|
|---|
| 658 | initialPageParam,
|
|---|
| 659 | refetchCachedPages
|
|---|
| 660 | } = rest;
|
|---|
| 661 | thunk = infiniteQueryThunk(__spreadProps(__spreadValues({}, commonThunkArgs), {
|
|---|
| 662 | // Supply these even if undefined. This helps with a field existence
|
|---|
| 663 | // check over in `buildSlice.ts`
|
|---|
| 664 | direction,
|
|---|
| 665 | initialPageParam,
|
|---|
| 666 | refetchCachedPages
|
|---|
| 667 | }));
|
|---|
| 668 | }
|
|---|
| 669 | const selector = api.endpoints[endpointName].select(arg);
|
|---|
| 670 | const thunkResult = dispatch(thunk);
|
|---|
| 671 | const stateAfter = selector(getState());
|
|---|
| 672 | middlewareWarning(dispatch);
|
|---|
| 673 | const {
|
|---|
| 674 | requestId,
|
|---|
| 675 | abort
|
|---|
| 676 | } = thunkResult;
|
|---|
| 677 | const skippedSynchronously = stateAfter.requestId !== requestId;
|
|---|
| 678 | const runningQuery = (_a2 = getRunningQueries(dispatch)) == null ? void 0 : _a2.get(queryCacheKey);
|
|---|
| 679 | const selectFromState = () => selector(getState());
|
|---|
| 680 | const statePromise = Object.assign(forceQueryFn ? (
|
|---|
| 681 | // a query has been forced (upsertQueryData)
|
|---|
| 682 | // -> we want to resolve it once data has been written with the data that will be written
|
|---|
| 683 | thunkResult.then(selectFromState)
|
|---|
| 684 | ) : skippedSynchronously && !runningQuery ? (
|
|---|
| 685 | // a query has been skipped due to a condition and we do not have any currently running query
|
|---|
| 686 | // -> we want to resolve it immediately with the current data
|
|---|
| 687 | Promise.resolve(stateAfter)
|
|---|
| 688 | ) : (
|
|---|
| 689 | // query just started or one is already in flight
|
|---|
| 690 | // -> wait for the running query, then resolve with data from after that
|
|---|
| 691 | Promise.all([runningQuery, thunkResult]).then(selectFromState)
|
|---|
| 692 | ), {
|
|---|
| 693 | arg,
|
|---|
| 694 | requestId,
|
|---|
| 695 | subscriptionOptions,
|
|---|
| 696 | queryCacheKey,
|
|---|
| 697 | abort,
|
|---|
| 698 | async unwrap() {
|
|---|
| 699 | const result = await statePromise;
|
|---|
| 700 | if (result.isError) {
|
|---|
| 701 | throw result.error;
|
|---|
| 702 | }
|
|---|
| 703 | return result.data;
|
|---|
| 704 | },
|
|---|
| 705 | refetch: (options) => dispatch(queryAction(arg, __spreadValues({
|
|---|
| 706 | subscribe: false,
|
|---|
| 707 | forceRefetch: true
|
|---|
| 708 | }, options))),
|
|---|
| 709 | unsubscribe() {
|
|---|
| 710 | if (subscribe) dispatch(unsubscribeQueryResult({
|
|---|
| 711 | queryCacheKey,
|
|---|
| 712 | requestId
|
|---|
| 713 | }));
|
|---|
| 714 | },
|
|---|
| 715 | updateSubscriptionOptions(options) {
|
|---|
| 716 | statePromise.subscriptionOptions = options;
|
|---|
| 717 | dispatch(updateSubscriptionOptions({
|
|---|
| 718 | endpointName,
|
|---|
| 719 | requestId,
|
|---|
| 720 | queryCacheKey,
|
|---|
| 721 | options
|
|---|
| 722 | }));
|
|---|
| 723 | }
|
|---|
| 724 | });
|
|---|
| 725 | if (!runningQuery && !skippedSynchronously && !forceQueryFn) {
|
|---|
| 726 | const runningQueries = getRunningQueries(dispatch);
|
|---|
| 727 | runningQueries.set(queryCacheKey, statePromise);
|
|---|
| 728 | statePromise.then(() => {
|
|---|
| 729 | runningQueries.delete(queryCacheKey);
|
|---|
| 730 | });
|
|---|
| 731 | }
|
|---|
| 732 | return statePromise;
|
|---|
| 733 | };
|
|---|
| 734 | };
|
|---|
| 735 | return queryAction;
|
|---|
| 736 | }
|
|---|
| 737 | function buildInitiateQuery(endpointName, endpointDefinition) {
|
|---|
| 738 | const queryAction = buildInitiateAnyQuery(endpointName, endpointDefinition);
|
|---|
| 739 | return queryAction;
|
|---|
| 740 | }
|
|---|
| 741 | function buildInitiateInfiniteQuery(endpointName, endpointDefinition) {
|
|---|
| 742 | const infiniteQueryAction = buildInitiateAnyQuery(endpointName, endpointDefinition);
|
|---|
| 743 | return infiniteQueryAction;
|
|---|
| 744 | }
|
|---|
| 745 | function buildInitiateMutation(endpointName) {
|
|---|
| 746 | return (arg, {
|
|---|
| 747 | track = true,
|
|---|
| 748 | fixedCacheKey
|
|---|
| 749 | } = {}) => (dispatch, getState) => {
|
|---|
| 750 | const thunk = mutationThunk({
|
|---|
| 751 | type: "mutation",
|
|---|
| 752 | endpointName,
|
|---|
| 753 | originalArgs: arg,
|
|---|
| 754 | track,
|
|---|
| 755 | fixedCacheKey
|
|---|
| 756 | });
|
|---|
| 757 | const thunkResult = dispatch(thunk);
|
|---|
| 758 | middlewareWarning(dispatch);
|
|---|
| 759 | const {
|
|---|
| 760 | requestId,
|
|---|
| 761 | abort,
|
|---|
| 762 | unwrap
|
|---|
| 763 | } = thunkResult;
|
|---|
| 764 | const returnValuePromise = asSafePromise(thunkResult.unwrap().then((data) => ({
|
|---|
| 765 | data
|
|---|
| 766 | })), (error) => ({
|
|---|
| 767 | error
|
|---|
| 768 | }));
|
|---|
| 769 | const reset = () => {
|
|---|
| 770 | dispatch(removeMutationResult({
|
|---|
| 771 | requestId,
|
|---|
| 772 | fixedCacheKey
|
|---|
| 773 | }));
|
|---|
| 774 | };
|
|---|
| 775 | const ret = Object.assign(returnValuePromise, {
|
|---|
| 776 | arg: thunkResult.arg,
|
|---|
| 777 | requestId,
|
|---|
| 778 | abort,
|
|---|
| 779 | unwrap,
|
|---|
| 780 | reset
|
|---|
| 781 | });
|
|---|
| 782 | const runningMutations = getRunningMutations(dispatch);
|
|---|
| 783 | runningMutations.set(requestId, ret);
|
|---|
| 784 | ret.then(() => {
|
|---|
| 785 | runningMutations.delete(requestId);
|
|---|
| 786 | });
|
|---|
| 787 | if (fixedCacheKey) {
|
|---|
| 788 | runningMutations.set(fixedCacheKey, ret);
|
|---|
| 789 | ret.then(() => {
|
|---|
| 790 | if (runningMutations.get(fixedCacheKey) === ret) {
|
|---|
| 791 | runningMutations.delete(fixedCacheKey);
|
|---|
| 792 | }
|
|---|
| 793 | });
|
|---|
| 794 | }
|
|---|
| 795 | return ret;
|
|---|
| 796 | };
|
|---|
| 797 | }
|
|---|
| 798 | }
|
|---|
| 799 |
|
|---|
| 800 | // src/query/standardSchema.ts
|
|---|
| 801 | import { SchemaError } from "@standard-schema/utils";
|
|---|
| 802 | var NamedSchemaError = class extends SchemaError {
|
|---|
| 803 | constructor(issues, value, schemaName, _bqMeta) {
|
|---|
| 804 | super(issues);
|
|---|
| 805 | this.value = value;
|
|---|
| 806 | this.schemaName = schemaName;
|
|---|
| 807 | this._bqMeta = _bqMeta;
|
|---|
| 808 | }
|
|---|
| 809 | };
|
|---|
| 810 | var shouldSkip = (skipSchemaValidation, schemaName) => Array.isArray(skipSchemaValidation) ? skipSchemaValidation.includes(schemaName) : !!skipSchemaValidation;
|
|---|
| 811 | async function parseWithSchema(schema, data, schemaName, bqMeta) {
|
|---|
| 812 | const result = await schema["~standard"].validate(data);
|
|---|
| 813 | if (result.issues) {
|
|---|
| 814 | throw new NamedSchemaError(result.issues, data, schemaName, bqMeta);
|
|---|
| 815 | }
|
|---|
| 816 | return result.value;
|
|---|
| 817 | }
|
|---|
| 818 |
|
|---|
| 819 | // src/query/core/buildThunks.ts
|
|---|
| 820 | function defaultTransformResponse(baseQueryReturnValue) {
|
|---|
| 821 | return baseQueryReturnValue;
|
|---|
| 822 | }
|
|---|
| 823 | var addShouldAutoBatch = (arg = {}) => {
|
|---|
| 824 | return __spreadProps(__spreadValues({}, arg), {
|
|---|
| 825 | [SHOULD_AUTOBATCH]: true
|
|---|
| 826 | });
|
|---|
| 827 | };
|
|---|
| 828 | function buildThunks({
|
|---|
| 829 | reducerPath,
|
|---|
| 830 | baseQuery,
|
|---|
| 831 | context: {
|
|---|
| 832 | endpointDefinitions
|
|---|
| 833 | },
|
|---|
| 834 | serializeQueryArgs,
|
|---|
| 835 | api,
|
|---|
| 836 | assertTagType,
|
|---|
| 837 | selectors,
|
|---|
| 838 | onSchemaFailure,
|
|---|
| 839 | catchSchemaFailure: globalCatchSchemaFailure,
|
|---|
| 840 | skipSchemaValidation: globalSkipSchemaValidation
|
|---|
| 841 | }) {
|
|---|
| 842 | const patchQueryData = (endpointName, arg, patches, updateProvided) => (dispatch, getState) => {
|
|---|
| 843 | const endpointDefinition = endpointDefinitions[endpointName];
|
|---|
| 844 | const queryCacheKey = serializeQueryArgs({
|
|---|
| 845 | queryArgs: arg,
|
|---|
| 846 | endpointDefinition,
|
|---|
| 847 | endpointName
|
|---|
| 848 | });
|
|---|
| 849 | dispatch(api.internalActions.queryResultPatched({
|
|---|
| 850 | queryCacheKey,
|
|---|
| 851 | patches
|
|---|
| 852 | }));
|
|---|
| 853 | if (!updateProvided) {
|
|---|
| 854 | return;
|
|---|
| 855 | }
|
|---|
| 856 | const newValue = api.endpoints[endpointName].select(arg)(
|
|---|
| 857 | // Work around TS 4.1 mismatch
|
|---|
| 858 | getState()
|
|---|
| 859 | );
|
|---|
| 860 | const providedTags = calculateProvidedBy(endpointDefinition.providesTags, newValue.data, void 0, arg, {}, assertTagType);
|
|---|
| 861 | dispatch(api.internalActions.updateProvidedBy([{
|
|---|
| 862 | queryCacheKey,
|
|---|
| 863 | providedTags
|
|---|
| 864 | }]));
|
|---|
| 865 | };
|
|---|
| 866 | function addToStart(items, item, max = 0) {
|
|---|
| 867 | const newItems = [item, ...items];
|
|---|
| 868 | return max && newItems.length > max ? newItems.slice(0, -1) : newItems;
|
|---|
| 869 | }
|
|---|
| 870 | function addToEnd(items, item, max = 0) {
|
|---|
| 871 | const newItems = [...items, item];
|
|---|
| 872 | return max && newItems.length > max ? newItems.slice(1) : newItems;
|
|---|
| 873 | }
|
|---|
| 874 | const updateQueryData = (endpointName, arg, updateRecipe, updateProvided = true) => (dispatch, getState) => {
|
|---|
| 875 | const endpointDefinition = api.endpoints[endpointName];
|
|---|
| 876 | const currentState = endpointDefinition.select(arg)(
|
|---|
| 877 | // Work around TS 4.1 mismatch
|
|---|
| 878 | getState()
|
|---|
| 879 | );
|
|---|
| 880 | const ret = {
|
|---|
| 881 | patches: [],
|
|---|
| 882 | inversePatches: [],
|
|---|
| 883 | undo: () => dispatch(api.util.patchQueryData(endpointName, arg, ret.inversePatches, updateProvided))
|
|---|
| 884 | };
|
|---|
| 885 | if (currentState.status === STATUS_UNINITIALIZED) {
|
|---|
| 886 | return ret;
|
|---|
| 887 | }
|
|---|
| 888 | let newValue;
|
|---|
| 889 | if ("data" in currentState) {
|
|---|
| 890 | if (isDraftable(currentState.data)) {
|
|---|
| 891 | const [value, patches, inversePatches] = produceWithPatches(currentState.data, updateRecipe);
|
|---|
| 892 | ret.patches.push(...patches);
|
|---|
| 893 | ret.inversePatches.push(...inversePatches);
|
|---|
| 894 | newValue = value;
|
|---|
| 895 | } else {
|
|---|
| 896 | newValue = updateRecipe(currentState.data);
|
|---|
| 897 | ret.patches.push({
|
|---|
| 898 | op: "replace",
|
|---|
| 899 | path: [],
|
|---|
| 900 | value: newValue
|
|---|
| 901 | });
|
|---|
| 902 | ret.inversePatches.push({
|
|---|
| 903 | op: "replace",
|
|---|
| 904 | path: [],
|
|---|
| 905 | value: currentState.data
|
|---|
| 906 | });
|
|---|
| 907 | }
|
|---|
| 908 | }
|
|---|
| 909 | if (ret.patches.length === 0) {
|
|---|
| 910 | return ret;
|
|---|
| 911 | }
|
|---|
| 912 | dispatch(api.util.patchQueryData(endpointName, arg, ret.patches, updateProvided));
|
|---|
| 913 | return ret;
|
|---|
| 914 | };
|
|---|
| 915 | const upsertQueryData = (endpointName, arg, value) => (dispatch) => {
|
|---|
| 916 | const res = dispatch(api.endpoints[endpointName].initiate(arg, {
|
|---|
| 917 | subscribe: false,
|
|---|
| 918 | forceRefetch: true,
|
|---|
| 919 | [forceQueryFnSymbol]: () => ({
|
|---|
| 920 | data: value
|
|---|
| 921 | })
|
|---|
| 922 | }));
|
|---|
| 923 | return res;
|
|---|
| 924 | };
|
|---|
| 925 | const getTransformCallbackForEndpoint = (endpointDefinition, transformFieldName) => {
|
|---|
| 926 | return endpointDefinition.query && endpointDefinition[transformFieldName] ? endpointDefinition[transformFieldName] : defaultTransformResponse;
|
|---|
| 927 | };
|
|---|
| 928 | const executeEndpoint = async (arg, {
|
|---|
| 929 | signal,
|
|---|
| 930 | abort,
|
|---|
| 931 | rejectWithValue,
|
|---|
| 932 | fulfillWithValue,
|
|---|
| 933 | dispatch,
|
|---|
| 934 | getState,
|
|---|
| 935 | extra
|
|---|
| 936 | }) => {
|
|---|
| 937 | var _a, _b, _c, _d, _e, _f;
|
|---|
| 938 | const endpointDefinition = endpointDefinitions[arg.endpointName];
|
|---|
| 939 | const {
|
|---|
| 940 | metaSchema,
|
|---|
| 941 | skipSchemaValidation = globalSkipSchemaValidation
|
|---|
| 942 | } = endpointDefinition;
|
|---|
| 943 | const isQuery = arg.type === ENDPOINT_QUERY;
|
|---|
| 944 | try {
|
|---|
| 945 | let transformResponse = defaultTransformResponse;
|
|---|
| 946 | const baseQueryApi = {
|
|---|
| 947 | signal,
|
|---|
| 948 | abort,
|
|---|
| 949 | dispatch,
|
|---|
| 950 | getState,
|
|---|
| 951 | extra,
|
|---|
| 952 | endpoint: arg.endpointName,
|
|---|
| 953 | type: arg.type,
|
|---|
| 954 | forced: isQuery ? isForcedQuery(arg, getState()) : void 0,
|
|---|
| 955 | queryCacheKey: isQuery ? arg.queryCacheKey : void 0
|
|---|
| 956 | };
|
|---|
| 957 | const forceQueryFn = isQuery ? arg[forceQueryFnSymbol] : void 0;
|
|---|
| 958 | let finalQueryReturnValue;
|
|---|
| 959 | const fetchPage = async (data, param, maxPages, previous) => {
|
|---|
| 960 | if (param == null && data.pages.length) {
|
|---|
| 961 | return Promise.resolve({
|
|---|
| 962 | data
|
|---|
| 963 | });
|
|---|
| 964 | }
|
|---|
| 965 | const finalQueryArg = {
|
|---|
| 966 | queryArg: arg.originalArgs,
|
|---|
| 967 | pageParam: param
|
|---|
| 968 | };
|
|---|
| 969 | const pageResponse = await executeRequest(finalQueryArg);
|
|---|
| 970 | const addTo = previous ? addToStart : addToEnd;
|
|---|
| 971 | return {
|
|---|
| 972 | data: {
|
|---|
| 973 | pages: addTo(data.pages, pageResponse.data, maxPages),
|
|---|
| 974 | pageParams: addTo(data.pageParams, param, maxPages)
|
|---|
| 975 | },
|
|---|
| 976 | meta: pageResponse.meta
|
|---|
| 977 | };
|
|---|
| 978 | };
|
|---|
| 979 | async function executeRequest(finalQueryArg) {
|
|---|
| 980 | let result;
|
|---|
| 981 | const {
|
|---|
| 982 | extraOptions,
|
|---|
| 983 | argSchema,
|
|---|
| 984 | rawResponseSchema,
|
|---|
| 985 | responseSchema
|
|---|
| 986 | } = endpointDefinition;
|
|---|
| 987 | if (argSchema && !shouldSkip(skipSchemaValidation, "arg")) {
|
|---|
| 988 | finalQueryArg = await parseWithSchema(
|
|---|
| 989 | argSchema,
|
|---|
| 990 | finalQueryArg,
|
|---|
| 991 | "argSchema",
|
|---|
| 992 | {}
|
|---|
| 993 | // we don't have a meta yet, so we can't pass it
|
|---|
| 994 | );
|
|---|
| 995 | }
|
|---|
| 996 | if (forceQueryFn) {
|
|---|
| 997 | result = forceQueryFn();
|
|---|
| 998 | } else if (endpointDefinition.query) {
|
|---|
| 999 | transformResponse = getTransformCallbackForEndpoint(endpointDefinition, "transformResponse");
|
|---|
| 1000 | result = await baseQuery(endpointDefinition.query(finalQueryArg), baseQueryApi, extraOptions);
|
|---|
| 1001 | } else {
|
|---|
| 1002 | result = await endpointDefinition.queryFn(finalQueryArg, baseQueryApi, extraOptions, (arg2) => baseQuery(arg2, baseQueryApi, extraOptions));
|
|---|
| 1003 | }
|
|---|
| 1004 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|---|
| 1005 | const what = endpointDefinition.query ? "`baseQuery`" : "`queryFn`";
|
|---|
| 1006 | let err;
|
|---|
| 1007 | if (!result) {
|
|---|
| 1008 | err = `${what} did not return anything.`;
|
|---|
| 1009 | } else if (typeof result !== "object") {
|
|---|
| 1010 | err = `${what} did not return an object.`;
|
|---|
| 1011 | } else if (result.error && result.data) {
|
|---|
| 1012 | err = `${what} returned an object containing both \`error\` and \`result\`.`;
|
|---|
| 1013 | } else if (result.error === void 0 && result.data === void 0) {
|
|---|
| 1014 | err = `${what} returned an object containing neither a valid \`error\` and \`result\`. At least one of them should not be \`undefined\``;
|
|---|
| 1015 | } else {
|
|---|
| 1016 | for (const key of Object.keys(result)) {
|
|---|
| 1017 | if (key !== "error" && key !== "data" && key !== "meta") {
|
|---|
| 1018 | err = `The object returned by ${what} has the unknown property ${key}.`;
|
|---|
| 1019 | break;
|
|---|
| 1020 | }
|
|---|
| 1021 | }
|
|---|
| 1022 | }
|
|---|
| 1023 | if (err) {
|
|---|
| 1024 | console.error(`Error encountered handling the endpoint ${arg.endpointName}.
|
|---|
| 1025 | ${err}
|
|---|
| 1026 | It needs to return an object with either the shape \`{ data: <value> }\` or \`{ error: <value> }\` that may contain an optional \`meta\` property.
|
|---|
| 1027 | Object returned was:`, result);
|
|---|
| 1028 | }
|
|---|
| 1029 | }
|
|---|
| 1030 | if (result.error) throw new HandledError(result.error, result.meta);
|
|---|
| 1031 | let {
|
|---|
| 1032 | data
|
|---|
| 1033 | } = result;
|
|---|
| 1034 | if (rawResponseSchema && !shouldSkip(skipSchemaValidation, "rawResponse")) {
|
|---|
| 1035 | data = await parseWithSchema(rawResponseSchema, result.data, "rawResponseSchema", result.meta);
|
|---|
| 1036 | }
|
|---|
| 1037 | let transformedResponse = await transformResponse(data, result.meta, finalQueryArg);
|
|---|
| 1038 | if (responseSchema && !shouldSkip(skipSchemaValidation, "response")) {
|
|---|
| 1039 | transformedResponse = await parseWithSchema(responseSchema, transformedResponse, "responseSchema", result.meta);
|
|---|
| 1040 | }
|
|---|
| 1041 | return __spreadProps(__spreadValues({}, result), {
|
|---|
| 1042 | data: transformedResponse
|
|---|
| 1043 | });
|
|---|
| 1044 | }
|
|---|
| 1045 | if (isQuery && "infiniteQueryOptions" in endpointDefinition) {
|
|---|
| 1046 | const {
|
|---|
| 1047 | infiniteQueryOptions
|
|---|
| 1048 | } = endpointDefinition;
|
|---|
| 1049 | const {
|
|---|
| 1050 | maxPages = Infinity
|
|---|
| 1051 | } = infiniteQueryOptions;
|
|---|
| 1052 | const refetchCachedPages = (_b = (_a = arg.refetchCachedPages) != null ? _a : infiniteQueryOptions.refetchCachedPages) != null ? _b : true;
|
|---|
| 1053 | let result;
|
|---|
| 1054 | const blankData = {
|
|---|
| 1055 | pages: [],
|
|---|
| 1056 | pageParams: []
|
|---|
| 1057 | };
|
|---|
| 1058 | const cachedData = (_c = selectors.selectQueryEntry(getState(), arg.queryCacheKey)) == null ? void 0 : _c.data;
|
|---|
| 1059 | const isForcedQueryNeedingRefetch = (
|
|---|
| 1060 | // arg.forceRefetch
|
|---|
| 1061 | isForcedQuery(arg, getState()) && !arg.direction
|
|---|
| 1062 | );
|
|---|
| 1063 | const existingData = isForcedQueryNeedingRefetch || !cachedData ? blankData : cachedData;
|
|---|
| 1064 | if ("direction" in arg && arg.direction && existingData.pages.length) {
|
|---|
| 1065 | const previous = arg.direction === "backward";
|
|---|
| 1066 | const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
|
|---|
| 1067 | const param = pageParamFn(infiniteQueryOptions, existingData, arg.originalArgs);
|
|---|
| 1068 | result = await fetchPage(existingData, param, maxPages, previous);
|
|---|
| 1069 | } else {
|
|---|
| 1070 | const {
|
|---|
| 1071 | initialPageParam = infiniteQueryOptions.initialPageParam
|
|---|
| 1072 | } = arg;
|
|---|
| 1073 | const cachedPageParams = (_d = cachedData == null ? void 0 : cachedData.pageParams) != null ? _d : [];
|
|---|
| 1074 | const firstPageParam = (_e = cachedPageParams[0]) != null ? _e : initialPageParam;
|
|---|
| 1075 | const totalPages = cachedPageParams.length;
|
|---|
| 1076 | result = await fetchPage(existingData, firstPageParam, maxPages);
|
|---|
| 1077 | if (forceQueryFn) {
|
|---|
| 1078 | result = {
|
|---|
| 1079 | data: result.data.pages[0]
|
|---|
| 1080 | };
|
|---|
| 1081 | }
|
|---|
| 1082 | if (refetchCachedPages) {
|
|---|
| 1083 | for (let i = 1; i < totalPages; i++) {
|
|---|
| 1084 | const param = getNextPageParam(infiniteQueryOptions, result.data, arg.originalArgs);
|
|---|
| 1085 | result = await fetchPage(result.data, param, maxPages);
|
|---|
| 1086 | }
|
|---|
| 1087 | }
|
|---|
| 1088 | }
|
|---|
| 1089 | finalQueryReturnValue = result;
|
|---|
| 1090 | } else {
|
|---|
| 1091 | finalQueryReturnValue = await executeRequest(arg.originalArgs);
|
|---|
| 1092 | }
|
|---|
| 1093 | if (metaSchema && !shouldSkip(skipSchemaValidation, "meta") && finalQueryReturnValue.meta) {
|
|---|
| 1094 | finalQueryReturnValue.meta = await parseWithSchema(metaSchema, finalQueryReturnValue.meta, "metaSchema", finalQueryReturnValue.meta);
|
|---|
| 1095 | }
|
|---|
| 1096 | return fulfillWithValue(finalQueryReturnValue.data, addShouldAutoBatch({
|
|---|
| 1097 | fulfilledTimeStamp: Date.now(),
|
|---|
| 1098 | baseQueryMeta: finalQueryReturnValue.meta
|
|---|
| 1099 | }));
|
|---|
| 1100 | } catch (error) {
|
|---|
| 1101 | let caughtError = error;
|
|---|
| 1102 | if (caughtError instanceof HandledError) {
|
|---|
| 1103 | let transformErrorResponse = getTransformCallbackForEndpoint(endpointDefinition, "transformErrorResponse");
|
|---|
| 1104 | const {
|
|---|
| 1105 | rawErrorResponseSchema,
|
|---|
| 1106 | errorResponseSchema
|
|---|
| 1107 | } = endpointDefinition;
|
|---|
| 1108 | let {
|
|---|
| 1109 | value,
|
|---|
| 1110 | meta
|
|---|
| 1111 | } = caughtError;
|
|---|
| 1112 | try {
|
|---|
| 1113 | if (rawErrorResponseSchema && !shouldSkip(skipSchemaValidation, "rawErrorResponse")) {
|
|---|
| 1114 | value = await parseWithSchema(rawErrorResponseSchema, value, "rawErrorResponseSchema", meta);
|
|---|
| 1115 | }
|
|---|
| 1116 | if (metaSchema && !shouldSkip(skipSchemaValidation, "meta")) {
|
|---|
| 1117 | meta = await parseWithSchema(metaSchema, meta, "metaSchema", meta);
|
|---|
| 1118 | }
|
|---|
| 1119 | let transformedErrorResponse = await transformErrorResponse(value, meta, arg.originalArgs);
|
|---|
| 1120 | if (errorResponseSchema && !shouldSkip(skipSchemaValidation, "errorResponse")) {
|
|---|
| 1121 | transformedErrorResponse = await parseWithSchema(errorResponseSchema, transformedErrorResponse, "errorResponseSchema", meta);
|
|---|
| 1122 | }
|
|---|
| 1123 | return rejectWithValue(transformedErrorResponse, addShouldAutoBatch({
|
|---|
| 1124 | baseQueryMeta: meta
|
|---|
| 1125 | }));
|
|---|
| 1126 | } catch (e) {
|
|---|
| 1127 | caughtError = e;
|
|---|
| 1128 | }
|
|---|
| 1129 | }
|
|---|
| 1130 | try {
|
|---|
| 1131 | if (caughtError instanceof NamedSchemaError) {
|
|---|
| 1132 | const info = {
|
|---|
| 1133 | endpoint: arg.endpointName,
|
|---|
| 1134 | arg: arg.originalArgs,
|
|---|
| 1135 | type: arg.type,
|
|---|
| 1136 | queryCacheKey: isQuery ? arg.queryCacheKey : void 0
|
|---|
| 1137 | };
|
|---|
| 1138 | (_f = endpointDefinition.onSchemaFailure) == null ? void 0 : _f.call(endpointDefinition, caughtError, info);
|
|---|
| 1139 | onSchemaFailure == null ? void 0 : onSchemaFailure(caughtError, info);
|
|---|
| 1140 | const {
|
|---|
| 1141 | catchSchemaFailure = globalCatchSchemaFailure
|
|---|
| 1142 | } = endpointDefinition;
|
|---|
| 1143 | if (catchSchemaFailure) {
|
|---|
| 1144 | return rejectWithValue(catchSchemaFailure(caughtError, info), addShouldAutoBatch({
|
|---|
| 1145 | baseQueryMeta: caughtError._bqMeta
|
|---|
| 1146 | }));
|
|---|
| 1147 | }
|
|---|
| 1148 | }
|
|---|
| 1149 | } catch (e) {
|
|---|
| 1150 | caughtError = e;
|
|---|
| 1151 | }
|
|---|
| 1152 | if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
|
|---|
| 1153 | console.error(`An unhandled error occurred processing a request for the endpoint "${arg.endpointName}".
|
|---|
| 1154 | In the case of an unhandled error, no tags will be "provided" or "invalidated".`, caughtError);
|
|---|
| 1155 | } else {
|
|---|
| 1156 | console.error(caughtError);
|
|---|
| 1157 | }
|
|---|
| 1158 | throw caughtError;
|
|---|
| 1159 | }
|
|---|
| 1160 | };
|
|---|
| 1161 | function isForcedQuery(arg, state) {
|
|---|
| 1162 | var _a;
|
|---|
| 1163 | const requestState = selectors.selectQueryEntry(state, arg.queryCacheKey);
|
|---|
| 1164 | const baseFetchOnMountOrArgChange = selectors.selectConfig(state).refetchOnMountOrArgChange;
|
|---|
| 1165 | const fulfilledVal = requestState == null ? void 0 : requestState.fulfilledTimeStamp;
|
|---|
| 1166 | const refetchVal = (_a = arg.forceRefetch) != null ? _a : arg.subscribe && baseFetchOnMountOrArgChange;
|
|---|
| 1167 | if (refetchVal) {
|
|---|
| 1168 | return refetchVal === true || (Number(/* @__PURE__ */ new Date()) - Number(fulfilledVal)) / 1e3 >= refetchVal;
|
|---|
| 1169 | }
|
|---|
| 1170 | return false;
|
|---|
| 1171 | }
|
|---|
| 1172 | const createQueryThunk = () => {
|
|---|
| 1173 | const generatedQueryThunk = createAsyncThunk(`${reducerPath}/executeQuery`, executeEndpoint, {
|
|---|
| 1174 | getPendingMeta({
|
|---|
| 1175 | arg
|
|---|
| 1176 | }) {
|
|---|
| 1177 | const endpointDefinition = endpointDefinitions[arg.endpointName];
|
|---|
| 1178 | return addShouldAutoBatch(__spreadValues({
|
|---|
| 1179 | startedTimeStamp: Date.now()
|
|---|
| 1180 | }, isInfiniteQueryDefinition(endpointDefinition) ? {
|
|---|
| 1181 | direction: arg.direction
|
|---|
| 1182 | } : {}));
|
|---|
| 1183 | },
|
|---|
| 1184 | condition(queryThunkArg, {
|
|---|
| 1185 | getState
|
|---|
| 1186 | }) {
|
|---|
| 1187 | var _a;
|
|---|
| 1188 | const state = getState();
|
|---|
| 1189 | const requestState = selectors.selectQueryEntry(state, queryThunkArg.queryCacheKey);
|
|---|
| 1190 | const fulfilledVal = requestState == null ? void 0 : requestState.fulfilledTimeStamp;
|
|---|
| 1191 | const currentArg = queryThunkArg.originalArgs;
|
|---|
| 1192 | const previousArg = requestState == null ? void 0 : requestState.originalArgs;
|
|---|
| 1193 | const endpointDefinition = endpointDefinitions[queryThunkArg.endpointName];
|
|---|
| 1194 | const direction = queryThunkArg.direction;
|
|---|
| 1195 | if (isUpsertQuery(queryThunkArg)) {
|
|---|
| 1196 | return true;
|
|---|
| 1197 | }
|
|---|
| 1198 | if ((requestState == null ? void 0 : requestState.status) === "pending") {
|
|---|
| 1199 | return false;
|
|---|
| 1200 | }
|
|---|
| 1201 | if (isForcedQuery(queryThunkArg, state)) {
|
|---|
| 1202 | return true;
|
|---|
| 1203 | }
|
|---|
| 1204 | if (isQueryDefinition(endpointDefinition) && ((_a = endpointDefinition == null ? void 0 : endpointDefinition.forceRefetch) == null ? void 0 : _a.call(endpointDefinition, {
|
|---|
| 1205 | currentArg,
|
|---|
| 1206 | previousArg,
|
|---|
| 1207 | endpointState: requestState,
|
|---|
| 1208 | state
|
|---|
| 1209 | }))) {
|
|---|
| 1210 | return true;
|
|---|
| 1211 | }
|
|---|
| 1212 | if (fulfilledVal && !direction) {
|
|---|
| 1213 | return false;
|
|---|
| 1214 | }
|
|---|
| 1215 | return true;
|
|---|
| 1216 | },
|
|---|
| 1217 | dispatchConditionRejection: true
|
|---|
| 1218 | });
|
|---|
| 1219 | return generatedQueryThunk;
|
|---|
| 1220 | };
|
|---|
| 1221 | const queryThunk = createQueryThunk();
|
|---|
| 1222 | const infiniteQueryThunk = createQueryThunk();
|
|---|
| 1223 | const mutationThunk = createAsyncThunk(`${reducerPath}/executeMutation`, executeEndpoint, {
|
|---|
| 1224 | getPendingMeta() {
|
|---|
| 1225 | return addShouldAutoBatch({
|
|---|
| 1226 | startedTimeStamp: Date.now()
|
|---|
| 1227 | });
|
|---|
| 1228 | }
|
|---|
| 1229 | });
|
|---|
| 1230 | const hasTheForce = (options) => "force" in options;
|
|---|
| 1231 | const hasMaxAge = (options) => "ifOlderThan" in options;
|
|---|
| 1232 | const prefetch = (endpointName, arg, options = {}) => (dispatch, getState) => {
|
|---|
| 1233 | const force = hasTheForce(options) && options.force;
|
|---|
| 1234 | const maxAge = hasMaxAge(options) && options.ifOlderThan;
|
|---|
| 1235 | const queryAction = (force2 = true) => {
|
|---|
| 1236 | const options2 = {
|
|---|
| 1237 | forceRefetch: force2,
|
|---|
| 1238 | subscribe: false
|
|---|
| 1239 | };
|
|---|
| 1240 | return api.endpoints[endpointName].initiate(arg, options2);
|
|---|
| 1241 | };
|
|---|
| 1242 | const latestStateValue = api.endpoints[endpointName].select(arg)(getState());
|
|---|
| 1243 | if (force) {
|
|---|
| 1244 | dispatch(queryAction());
|
|---|
| 1245 | } else if (maxAge) {
|
|---|
| 1246 | const lastFulfilledTs = latestStateValue == null ? void 0 : latestStateValue.fulfilledTimeStamp;
|
|---|
| 1247 | if (!lastFulfilledTs) {
|
|---|
| 1248 | dispatch(queryAction());
|
|---|
| 1249 | return;
|
|---|
| 1250 | }
|
|---|
| 1251 | const shouldRetrigger = (Number(/* @__PURE__ */ new Date()) - Number(new Date(lastFulfilledTs))) / 1e3 >= maxAge;
|
|---|
| 1252 | if (shouldRetrigger) {
|
|---|
| 1253 | dispatch(queryAction());
|
|---|
| 1254 | }
|
|---|
| 1255 | } else {
|
|---|
| 1256 | dispatch(queryAction(false));
|
|---|
| 1257 | }
|
|---|
| 1258 | };
|
|---|
| 1259 | function matchesEndpoint(endpointName) {
|
|---|
| 1260 | return (action) => {
|
|---|
| 1261 | var _a, _b;
|
|---|
| 1262 | return ((_b = (_a = action == null ? void 0 : action.meta) == null ? void 0 : _a.arg) == null ? void 0 : _b.endpointName) === endpointName;
|
|---|
| 1263 | };
|
|---|
| 1264 | }
|
|---|
| 1265 | function buildMatchThunkActions(thunk, endpointName) {
|
|---|
| 1266 | return {
|
|---|
| 1267 | matchPending: isAllOf(isPending(thunk), matchesEndpoint(endpointName)),
|
|---|
| 1268 | matchFulfilled: isAllOf(isFulfilled(thunk), matchesEndpoint(endpointName)),
|
|---|
| 1269 | matchRejected: isAllOf(isRejected(thunk), matchesEndpoint(endpointName))
|
|---|
| 1270 | };
|
|---|
| 1271 | }
|
|---|
| 1272 | return {
|
|---|
| 1273 | queryThunk,
|
|---|
| 1274 | mutationThunk,
|
|---|
| 1275 | infiniteQueryThunk,
|
|---|
| 1276 | prefetch,
|
|---|
| 1277 | updateQueryData,
|
|---|
| 1278 | upsertQueryData,
|
|---|
| 1279 | patchQueryData,
|
|---|
| 1280 | buildMatchThunkActions
|
|---|
| 1281 | };
|
|---|
| 1282 | }
|
|---|
| 1283 | function getNextPageParam(options, {
|
|---|
| 1284 | pages,
|
|---|
| 1285 | pageParams
|
|---|
| 1286 | }, queryArg) {
|
|---|
| 1287 | const lastIndex = pages.length - 1;
|
|---|
| 1288 | return options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams, queryArg);
|
|---|
| 1289 | }
|
|---|
| 1290 | function getPreviousPageParam(options, {
|
|---|
| 1291 | pages,
|
|---|
| 1292 | pageParams
|
|---|
| 1293 | }, queryArg) {
|
|---|
| 1294 | var _a;
|
|---|
| 1295 | return (_a = options.getPreviousPageParam) == null ? void 0 : _a.call(options, pages[0], pages, pageParams[0], pageParams, queryArg);
|
|---|
| 1296 | }
|
|---|
| 1297 | function calculateProvidedByThunk(action, type, endpointDefinitions, assertTagType) {
|
|---|
| 1298 | return calculateProvidedBy(endpointDefinitions[action.meta.arg.endpointName][type], isFulfilled(action) ? action.payload : void 0, isRejectedWithValue(action) ? action.payload : void 0, action.meta.arg.originalArgs, "baseQueryMeta" in action.meta ? action.meta.baseQueryMeta : void 0, assertTagType);
|
|---|
| 1299 | }
|
|---|
| 1300 |
|
|---|
| 1301 | // src/query/utils/getCurrent.ts
|
|---|
| 1302 | function getCurrent(value) {
|
|---|
| 1303 | return isDraft(value) ? current(value) : value;
|
|---|
| 1304 | }
|
|---|
| 1305 |
|
|---|
| 1306 | // src/query/core/buildSlice.ts
|
|---|
| 1307 | function updateQuerySubstateIfExists(state, queryCacheKey, update) {
|
|---|
| 1308 | const substate = state[queryCacheKey];
|
|---|
| 1309 | if (substate) {
|
|---|
| 1310 | update(substate);
|
|---|
| 1311 | }
|
|---|
| 1312 | }
|
|---|
| 1313 | function getMutationCacheKey(id) {
|
|---|
| 1314 | var _a;
|
|---|
| 1315 | return (_a = "arg" in id ? id.arg.fixedCacheKey : id.fixedCacheKey) != null ? _a : id.requestId;
|
|---|
| 1316 | }
|
|---|
| 1317 | function updateMutationSubstateIfExists(state, id, update) {
|
|---|
| 1318 | const substate = state[getMutationCacheKey(id)];
|
|---|
| 1319 | if (substate) {
|
|---|
| 1320 | update(substate);
|
|---|
| 1321 | }
|
|---|
| 1322 | }
|
|---|
| 1323 | var initialState = {};
|
|---|
| 1324 | function buildSlice({
|
|---|
| 1325 | reducerPath,
|
|---|
| 1326 | queryThunk,
|
|---|
| 1327 | mutationThunk,
|
|---|
| 1328 | serializeQueryArgs,
|
|---|
| 1329 | context: {
|
|---|
| 1330 | endpointDefinitions: definitions,
|
|---|
| 1331 | apiUid,
|
|---|
| 1332 | extractRehydrationInfo,
|
|---|
| 1333 | hasRehydrationInfo
|
|---|
| 1334 | },
|
|---|
| 1335 | assertTagType,
|
|---|
| 1336 | config
|
|---|
| 1337 | }) {
|
|---|
| 1338 | const resetApiState = createAction(`${reducerPath}/resetApiState`);
|
|---|
| 1339 | function writePendingCacheEntry(draft, arg, upserting, meta) {
|
|---|
| 1340 | var _a, _b;
|
|---|
| 1341 | (_b = draft[_a = arg.queryCacheKey]) != null ? _b : draft[_a] = {
|
|---|
| 1342 | status: STATUS_UNINITIALIZED,
|
|---|
| 1343 | endpointName: arg.endpointName
|
|---|
| 1344 | };
|
|---|
| 1345 | updateQuerySubstateIfExists(draft, arg.queryCacheKey, (substate) => {
|
|---|
| 1346 | substate.status = STATUS_PENDING;
|
|---|
| 1347 | substate.requestId = upserting && substate.requestId ? (
|
|---|
| 1348 | // for `upsertQuery` **updates**, keep the current `requestId`
|
|---|
| 1349 | substate.requestId
|
|---|
| 1350 | ) : (
|
|---|
| 1351 | // for normal queries or `upsertQuery` **inserts** always update the `requestId`
|
|---|
| 1352 | meta.requestId
|
|---|
| 1353 | );
|
|---|
| 1354 | if (arg.originalArgs !== void 0) {
|
|---|
| 1355 | substate.originalArgs = arg.originalArgs;
|
|---|
| 1356 | }
|
|---|
| 1357 | substate.startedTimeStamp = meta.startedTimeStamp;
|
|---|
| 1358 | const endpointDefinition = definitions[meta.arg.endpointName];
|
|---|
| 1359 | if (isInfiniteQueryDefinition(endpointDefinition) && "direction" in arg) {
|
|---|
| 1360 | ;
|
|---|
| 1361 | substate.direction = arg.direction;
|
|---|
| 1362 | }
|
|---|
| 1363 | });
|
|---|
| 1364 | }
|
|---|
| 1365 | function writeFulfilledCacheEntry(draft, meta, payload, upserting) {
|
|---|
| 1366 | updateQuerySubstateIfExists(draft, meta.arg.queryCacheKey, (substate) => {
|
|---|
| 1367 | var _a;
|
|---|
| 1368 | if (substate.requestId !== meta.requestId && !upserting) return;
|
|---|
| 1369 | const {
|
|---|
| 1370 | merge
|
|---|
| 1371 | } = definitions[meta.arg.endpointName];
|
|---|
| 1372 | substate.status = STATUS_FULFILLED;
|
|---|
| 1373 | if (merge) {
|
|---|
| 1374 | if (substate.data !== void 0) {
|
|---|
| 1375 | const {
|
|---|
| 1376 | fulfilledTimeStamp,
|
|---|
| 1377 | arg,
|
|---|
| 1378 | baseQueryMeta,
|
|---|
| 1379 | requestId
|
|---|
| 1380 | } = meta;
|
|---|
| 1381 | let newData = createNextState(substate.data, (draftSubstateData) => {
|
|---|
| 1382 | return merge(draftSubstateData, payload, {
|
|---|
| 1383 | arg: arg.originalArgs,
|
|---|
| 1384 | baseQueryMeta,
|
|---|
| 1385 | fulfilledTimeStamp,
|
|---|
| 1386 | requestId
|
|---|
| 1387 | });
|
|---|
| 1388 | });
|
|---|
| 1389 | substate.data = newData;
|
|---|
| 1390 | } else {
|
|---|
| 1391 | substate.data = payload;
|
|---|
| 1392 | }
|
|---|
| 1393 | } else {
|
|---|
| 1394 | substate.data = ((_a = definitions[meta.arg.endpointName].structuralSharing) != null ? _a : true) ? copyWithStructuralSharing(isDraft(substate.data) ? original(substate.data) : substate.data, payload) : payload;
|
|---|
| 1395 | }
|
|---|
| 1396 | delete substate.error;
|
|---|
| 1397 | substate.fulfilledTimeStamp = meta.fulfilledTimeStamp;
|
|---|
| 1398 | });
|
|---|
| 1399 | }
|
|---|
| 1400 | const querySlice = createSlice({
|
|---|
| 1401 | name: `${reducerPath}/queries`,
|
|---|
| 1402 | initialState,
|
|---|
| 1403 | reducers: {
|
|---|
| 1404 | removeQueryResult: {
|
|---|
| 1405 | reducer(draft, {
|
|---|
| 1406 | payload: {
|
|---|
| 1407 | queryCacheKey
|
|---|
| 1408 | }
|
|---|
| 1409 | }) {
|
|---|
| 1410 | delete draft[queryCacheKey];
|
|---|
| 1411 | },
|
|---|
| 1412 | prepare: prepareAutoBatched()
|
|---|
| 1413 | },
|
|---|
| 1414 | cacheEntriesUpserted: {
|
|---|
| 1415 | reducer(draft, action) {
|
|---|
| 1416 | for (const entry of action.payload) {
|
|---|
| 1417 | const {
|
|---|
| 1418 | queryDescription: arg,
|
|---|
| 1419 | value
|
|---|
| 1420 | } = entry;
|
|---|
| 1421 | writePendingCacheEntry(draft, arg, true, {
|
|---|
| 1422 | arg,
|
|---|
| 1423 | requestId: action.meta.requestId,
|
|---|
| 1424 | startedTimeStamp: action.meta.timestamp
|
|---|
| 1425 | });
|
|---|
| 1426 | writeFulfilledCacheEntry(
|
|---|
| 1427 | draft,
|
|---|
| 1428 | {
|
|---|
| 1429 | arg,
|
|---|
| 1430 | requestId: action.meta.requestId,
|
|---|
| 1431 | fulfilledTimeStamp: action.meta.timestamp,
|
|---|
| 1432 | baseQueryMeta: {}
|
|---|
| 1433 | },
|
|---|
| 1434 | value,
|
|---|
| 1435 | // We know we're upserting here
|
|---|
| 1436 | true
|
|---|
| 1437 | );
|
|---|
| 1438 | }
|
|---|
| 1439 | },
|
|---|
| 1440 | prepare: (payload) => {
|
|---|
| 1441 | const queryDescriptions = payload.map((entry) => {
|
|---|
| 1442 | const {
|
|---|
| 1443 | endpointName,
|
|---|
| 1444 | arg,
|
|---|
| 1445 | value
|
|---|
| 1446 | } = entry;
|
|---|
| 1447 | const endpointDefinition = definitions[endpointName];
|
|---|
| 1448 | const queryDescription = {
|
|---|
| 1449 | type: ENDPOINT_QUERY,
|
|---|
| 1450 | endpointName,
|
|---|
| 1451 | originalArgs: entry.arg,
|
|---|
| 1452 | queryCacheKey: serializeQueryArgs({
|
|---|
| 1453 | queryArgs: arg,
|
|---|
| 1454 | endpointDefinition,
|
|---|
| 1455 | endpointName
|
|---|
| 1456 | })
|
|---|
| 1457 | };
|
|---|
| 1458 | return {
|
|---|
| 1459 | queryDescription,
|
|---|
| 1460 | value
|
|---|
| 1461 | };
|
|---|
| 1462 | });
|
|---|
| 1463 | const result = {
|
|---|
| 1464 | payload: queryDescriptions,
|
|---|
| 1465 | meta: {
|
|---|
| 1466 | [SHOULD_AUTOBATCH]: true,
|
|---|
| 1467 | requestId: nanoid(),
|
|---|
| 1468 | timestamp: Date.now()
|
|---|
| 1469 | }
|
|---|
| 1470 | };
|
|---|
| 1471 | return result;
|
|---|
| 1472 | }
|
|---|
| 1473 | },
|
|---|
| 1474 | queryResultPatched: {
|
|---|
| 1475 | reducer(draft, {
|
|---|
| 1476 | payload: {
|
|---|
| 1477 | queryCacheKey,
|
|---|
| 1478 | patches
|
|---|
| 1479 | }
|
|---|
| 1480 | }) {
|
|---|
| 1481 | updateQuerySubstateIfExists(draft, queryCacheKey, (substate) => {
|
|---|
| 1482 | substate.data = applyPatches(substate.data, patches.concat());
|
|---|
| 1483 | });
|
|---|
| 1484 | },
|
|---|
| 1485 | prepare: prepareAutoBatched()
|
|---|
| 1486 | }
|
|---|
| 1487 | },
|
|---|
| 1488 | extraReducers(builder) {
|
|---|
| 1489 | builder.addCase(queryThunk.pending, (draft, {
|
|---|
| 1490 | meta,
|
|---|
| 1491 | meta: {
|
|---|
| 1492 | arg
|
|---|
| 1493 | }
|
|---|
| 1494 | }) => {
|
|---|
| 1495 | const upserting = isUpsertQuery(arg);
|
|---|
| 1496 | writePendingCacheEntry(draft, arg, upserting, meta);
|
|---|
| 1497 | }).addCase(queryThunk.fulfilled, (draft, {
|
|---|
| 1498 | meta,
|
|---|
| 1499 | payload
|
|---|
| 1500 | }) => {
|
|---|
| 1501 | const upserting = isUpsertQuery(meta.arg);
|
|---|
| 1502 | writeFulfilledCacheEntry(draft, meta, payload, upserting);
|
|---|
| 1503 | }).addCase(queryThunk.rejected, (draft, {
|
|---|
| 1504 | meta: {
|
|---|
| 1505 | condition,
|
|---|
| 1506 | arg,
|
|---|
| 1507 | requestId
|
|---|
| 1508 | },
|
|---|
| 1509 | error,
|
|---|
| 1510 | payload
|
|---|
| 1511 | }) => {
|
|---|
| 1512 | updateQuerySubstateIfExists(draft, arg.queryCacheKey, (substate) => {
|
|---|
| 1513 | if (condition) {
|
|---|
| 1514 | } else {
|
|---|
| 1515 | if (substate.requestId !== requestId) return;
|
|---|
| 1516 | substate.status = STATUS_REJECTED;
|
|---|
| 1517 | substate.error = payload != null ? payload : error;
|
|---|
| 1518 | }
|
|---|
| 1519 | });
|
|---|
| 1520 | }).addMatcher(hasRehydrationInfo, (draft, action) => {
|
|---|
| 1521 | const {
|
|---|
| 1522 | queries
|
|---|
| 1523 | } = extractRehydrationInfo(action);
|
|---|
| 1524 | for (const [key, entry] of Object.entries(queries)) {
|
|---|
| 1525 | if (
|
|---|
| 1526 | // do not rehydrate entries that were currently in flight.
|
|---|
| 1527 | (entry == null ? void 0 : entry.status) === STATUS_FULFILLED || (entry == null ? void 0 : entry.status) === STATUS_REJECTED
|
|---|
| 1528 | ) {
|
|---|
| 1529 | draft[key] = entry;
|
|---|
| 1530 | }
|
|---|
| 1531 | }
|
|---|
| 1532 | });
|
|---|
| 1533 | }
|
|---|
| 1534 | });
|
|---|
| 1535 | const mutationSlice = createSlice({
|
|---|
| 1536 | name: `${reducerPath}/mutations`,
|
|---|
| 1537 | initialState,
|
|---|
| 1538 | reducers: {
|
|---|
| 1539 | removeMutationResult: {
|
|---|
| 1540 | reducer(draft, {
|
|---|
| 1541 | payload
|
|---|
| 1542 | }) {
|
|---|
| 1543 | const cacheKey = getMutationCacheKey(payload);
|
|---|
| 1544 | if (cacheKey in draft) {
|
|---|
| 1545 | delete draft[cacheKey];
|
|---|
| 1546 | }
|
|---|
| 1547 | },
|
|---|
| 1548 | prepare: prepareAutoBatched()
|
|---|
| 1549 | }
|
|---|
| 1550 | },
|
|---|
| 1551 | extraReducers(builder) {
|
|---|
| 1552 | builder.addCase(mutationThunk.pending, (draft, {
|
|---|
| 1553 | meta,
|
|---|
| 1554 | meta: {
|
|---|
| 1555 | requestId,
|
|---|
| 1556 | arg,
|
|---|
| 1557 | startedTimeStamp
|
|---|
| 1558 | }
|
|---|
| 1559 | }) => {
|
|---|
| 1560 | if (!arg.track) return;
|
|---|
| 1561 | draft[getMutationCacheKey(meta)] = {
|
|---|
| 1562 | requestId,
|
|---|
| 1563 | status: STATUS_PENDING,
|
|---|
| 1564 | endpointName: arg.endpointName,
|
|---|
| 1565 | startedTimeStamp
|
|---|
| 1566 | };
|
|---|
| 1567 | }).addCase(mutationThunk.fulfilled, (draft, {
|
|---|
| 1568 | payload,
|
|---|
| 1569 | meta
|
|---|
| 1570 | }) => {
|
|---|
| 1571 | if (!meta.arg.track) return;
|
|---|
| 1572 | updateMutationSubstateIfExists(draft, meta, (substate) => {
|
|---|
| 1573 | if (substate.requestId !== meta.requestId) return;
|
|---|
| 1574 | substate.status = STATUS_FULFILLED;
|
|---|
| 1575 | substate.data = payload;
|
|---|
| 1576 | substate.fulfilledTimeStamp = meta.fulfilledTimeStamp;
|
|---|
| 1577 | });
|
|---|
| 1578 | }).addCase(mutationThunk.rejected, (draft, {
|
|---|
| 1579 | payload,
|
|---|
| 1580 | error,
|
|---|
| 1581 | meta
|
|---|
| 1582 | }) => {
|
|---|
| 1583 | if (!meta.arg.track) return;
|
|---|
| 1584 | updateMutationSubstateIfExists(draft, meta, (substate) => {
|
|---|
| 1585 | if (substate.requestId !== meta.requestId) return;
|
|---|
| 1586 | substate.status = STATUS_REJECTED;
|
|---|
| 1587 | substate.error = payload != null ? payload : error;
|
|---|
| 1588 | });
|
|---|
| 1589 | }).addMatcher(hasRehydrationInfo, (draft, action) => {
|
|---|
| 1590 | const {
|
|---|
| 1591 | mutations
|
|---|
| 1592 | } = extractRehydrationInfo(action);
|
|---|
| 1593 | for (const [key, entry] of Object.entries(mutations)) {
|
|---|
| 1594 | if (
|
|---|
| 1595 | // do not rehydrate entries that were currently in flight.
|
|---|
| 1596 | ((entry == null ? void 0 : entry.status) === STATUS_FULFILLED || (entry == null ? void 0 : entry.status) === STATUS_REJECTED) && // only rehydrate endpoints that were persisted using a `fixedCacheKey`
|
|---|
| 1597 | key !== (entry == null ? void 0 : entry.requestId)
|
|---|
| 1598 | ) {
|
|---|
| 1599 | draft[key] = entry;
|
|---|
| 1600 | }
|
|---|
| 1601 | }
|
|---|
| 1602 | });
|
|---|
| 1603 | }
|
|---|
| 1604 | });
|
|---|
| 1605 | const initialInvalidationState = {
|
|---|
| 1606 | tags: {},
|
|---|
| 1607 | keys: {}
|
|---|
| 1608 | };
|
|---|
| 1609 | const invalidationSlice = createSlice({
|
|---|
| 1610 | name: `${reducerPath}/invalidation`,
|
|---|
| 1611 | initialState: initialInvalidationState,
|
|---|
| 1612 | reducers: {
|
|---|
| 1613 | updateProvidedBy: {
|
|---|
| 1614 | reducer(draft, action) {
|
|---|
| 1615 | var _a, _b, _c, _d, _e;
|
|---|
| 1616 | for (const {
|
|---|
| 1617 | queryCacheKey,
|
|---|
| 1618 | providedTags
|
|---|
| 1619 | } of action.payload) {
|
|---|
| 1620 | removeCacheKeyFromTags(draft, queryCacheKey);
|
|---|
| 1621 | for (const {
|
|---|
| 1622 | type,
|
|---|
| 1623 | id
|
|---|
| 1624 | } of providedTags) {
|
|---|
| 1625 | const subscribedQueries = (_e = (_c = (_b = (_a = draft.tags)[type]) != null ? _b : _a[type] = {})[_d = id || "__internal_without_id"]) != null ? _e : _c[_d] = [];
|
|---|
| 1626 | const alreadySubscribed = subscribedQueries.includes(queryCacheKey);
|
|---|
| 1627 | if (!alreadySubscribed) {
|
|---|
| 1628 | subscribedQueries.push(queryCacheKey);
|
|---|
| 1629 | }
|
|---|
| 1630 | }
|
|---|
| 1631 | draft.keys[queryCacheKey] = providedTags;
|
|---|
| 1632 | }
|
|---|
| 1633 | },
|
|---|
| 1634 | prepare: prepareAutoBatched()
|
|---|
| 1635 | }
|
|---|
| 1636 | },
|
|---|
| 1637 | extraReducers(builder) {
|
|---|
| 1638 | builder.addCase(querySlice.actions.removeQueryResult, (draft, {
|
|---|
| 1639 | payload: {
|
|---|
| 1640 | queryCacheKey
|
|---|
| 1641 | }
|
|---|
| 1642 | }) => {
|
|---|
| 1643 | removeCacheKeyFromTags(draft, queryCacheKey);
|
|---|
| 1644 | }).addMatcher(hasRehydrationInfo, (draft, action) => {
|
|---|
| 1645 | var _a, _b, _c, _d, _e, _f;
|
|---|
| 1646 | const {
|
|---|
| 1647 | provided
|
|---|
| 1648 | } = extractRehydrationInfo(action);
|
|---|
| 1649 | for (const [type, incomingTags] of Object.entries((_a = provided.tags) != null ? _a : {})) {
|
|---|
| 1650 | for (const [id, cacheKeys] of Object.entries(incomingTags)) {
|
|---|
| 1651 | const subscribedQueries = (_f = (_d = (_c = (_b = draft.tags)[type]) != null ? _c : _b[type] = {})[_e = id || "__internal_without_id"]) != null ? _f : _d[_e] = [];
|
|---|
| 1652 | for (const queryCacheKey of cacheKeys) {
|
|---|
| 1653 | const alreadySubscribed = subscribedQueries.includes(queryCacheKey);
|
|---|
| 1654 | if (!alreadySubscribed) {
|
|---|
| 1655 | subscribedQueries.push(queryCacheKey);
|
|---|
| 1656 | }
|
|---|
| 1657 | draft.keys[queryCacheKey] = provided.keys[queryCacheKey];
|
|---|
| 1658 | }
|
|---|
| 1659 | }
|
|---|
| 1660 | }
|
|---|
| 1661 | }).addMatcher(isAnyOf(isFulfilled(queryThunk), isRejectedWithValue(queryThunk)), (draft, action) => {
|
|---|
| 1662 | writeProvidedTagsForQueries(draft, [action]);
|
|---|
| 1663 | }).addMatcher(querySlice.actions.cacheEntriesUpserted.match, (draft, action) => {
|
|---|
| 1664 | const mockActions = action.payload.map(({
|
|---|
| 1665 | queryDescription,
|
|---|
| 1666 | value
|
|---|
| 1667 | }) => {
|
|---|
| 1668 | return {
|
|---|
| 1669 | type: "UNKNOWN",
|
|---|
| 1670 | payload: value,
|
|---|
| 1671 | meta: {
|
|---|
| 1672 | requestStatus: "fulfilled",
|
|---|
| 1673 | requestId: "UNKNOWN",
|
|---|
| 1674 | arg: queryDescription
|
|---|
| 1675 | }
|
|---|
| 1676 | };
|
|---|
| 1677 | });
|
|---|
| 1678 | writeProvidedTagsForQueries(draft, mockActions);
|
|---|
| 1679 | });
|
|---|
| 1680 | }
|
|---|
| 1681 | });
|
|---|
| 1682 | function removeCacheKeyFromTags(draft, queryCacheKey) {
|
|---|
| 1683 | var _a, _b, _c;
|
|---|
| 1684 | const existingTags = getCurrent((_a = draft.keys[queryCacheKey]) != null ? _a : []);
|
|---|
| 1685 | for (const tag of existingTags) {
|
|---|
| 1686 | const tagType = tag.type;
|
|---|
| 1687 | const tagId = (_b = tag.id) != null ? _b : "__internal_without_id";
|
|---|
| 1688 | const tagSubscriptions = (_c = draft.tags[tagType]) == null ? void 0 : _c[tagId];
|
|---|
| 1689 | if (tagSubscriptions) {
|
|---|
| 1690 | draft.tags[tagType][tagId] = getCurrent(tagSubscriptions).filter((qc) => qc !== queryCacheKey);
|
|---|
| 1691 | }
|
|---|
| 1692 | }
|
|---|
| 1693 | delete draft.keys[queryCacheKey];
|
|---|
| 1694 | }
|
|---|
| 1695 | function writeProvidedTagsForQueries(draft, actions3) {
|
|---|
| 1696 | const providedByEntries = actions3.map((action) => {
|
|---|
| 1697 | const providedTags = calculateProvidedByThunk(action, "providesTags", definitions, assertTagType);
|
|---|
| 1698 | const {
|
|---|
| 1699 | queryCacheKey
|
|---|
| 1700 | } = action.meta.arg;
|
|---|
| 1701 | return {
|
|---|
| 1702 | queryCacheKey,
|
|---|
| 1703 | providedTags
|
|---|
| 1704 | };
|
|---|
| 1705 | });
|
|---|
| 1706 | invalidationSlice.caseReducers.updateProvidedBy(draft, invalidationSlice.actions.updateProvidedBy(providedByEntries));
|
|---|
| 1707 | }
|
|---|
| 1708 | const subscriptionSlice = createSlice({
|
|---|
| 1709 | name: `${reducerPath}/subscriptions`,
|
|---|
| 1710 | initialState,
|
|---|
| 1711 | reducers: {
|
|---|
| 1712 | updateSubscriptionOptions(d, a) {
|
|---|
| 1713 | },
|
|---|
| 1714 | unsubscribeQueryResult(d, a) {
|
|---|
| 1715 | },
|
|---|
| 1716 | internal_getRTKQSubscriptions() {
|
|---|
| 1717 | }
|
|---|
| 1718 | }
|
|---|
| 1719 | });
|
|---|
| 1720 | const internalSubscriptionsSlice = createSlice({
|
|---|
| 1721 | name: `${reducerPath}/internalSubscriptions`,
|
|---|
| 1722 | initialState,
|
|---|
| 1723 | reducers: {
|
|---|
| 1724 | subscriptionsUpdated: {
|
|---|
| 1725 | reducer(state, action) {
|
|---|
| 1726 | return applyPatches(state, action.payload);
|
|---|
| 1727 | },
|
|---|
| 1728 | prepare: prepareAutoBatched()
|
|---|
| 1729 | }
|
|---|
| 1730 | }
|
|---|
| 1731 | });
|
|---|
| 1732 | const configSlice = createSlice({
|
|---|
| 1733 | name: `${reducerPath}/config`,
|
|---|
| 1734 | initialState: __spreadValues({
|
|---|
| 1735 | online: isOnline(),
|
|---|
| 1736 | focused: isDocumentVisible(),
|
|---|
| 1737 | middlewareRegistered: false
|
|---|
| 1738 | }, config),
|
|---|
| 1739 | reducers: {
|
|---|
| 1740 | middlewareRegistered(state, {
|
|---|
| 1741 | payload
|
|---|
| 1742 | }) {
|
|---|
| 1743 | state.middlewareRegistered = state.middlewareRegistered === "conflict" || apiUid !== payload ? "conflict" : true;
|
|---|
| 1744 | }
|
|---|
| 1745 | },
|
|---|
| 1746 | extraReducers: (builder) => {
|
|---|
| 1747 | builder.addCase(onOnline, (state) => {
|
|---|
| 1748 | state.online = true;
|
|---|
| 1749 | }).addCase(onOffline, (state) => {
|
|---|
| 1750 | state.online = false;
|
|---|
| 1751 | }).addCase(onFocus, (state) => {
|
|---|
| 1752 | state.focused = true;
|
|---|
| 1753 | }).addCase(onFocusLost, (state) => {
|
|---|
| 1754 | state.focused = false;
|
|---|
| 1755 | }).addMatcher(hasRehydrationInfo, (draft) => __spreadValues({}, draft));
|
|---|
| 1756 | }
|
|---|
| 1757 | });
|
|---|
| 1758 | const combinedReducer = combineReducers({
|
|---|
| 1759 | queries: querySlice.reducer,
|
|---|
| 1760 | mutations: mutationSlice.reducer,
|
|---|
| 1761 | provided: invalidationSlice.reducer,
|
|---|
| 1762 | subscriptions: internalSubscriptionsSlice.reducer,
|
|---|
| 1763 | config: configSlice.reducer
|
|---|
| 1764 | });
|
|---|
| 1765 | const reducer = (state, action) => combinedReducer(resetApiState.match(action) ? void 0 : state, action);
|
|---|
| 1766 | const actions2 = __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, configSlice.actions), querySlice.actions), subscriptionSlice.actions), internalSubscriptionsSlice.actions), mutationSlice.actions), invalidationSlice.actions), {
|
|---|
| 1767 | resetApiState
|
|---|
| 1768 | });
|
|---|
| 1769 | return {
|
|---|
| 1770 | reducer,
|
|---|
| 1771 | actions: actions2
|
|---|
| 1772 | };
|
|---|
| 1773 | }
|
|---|
| 1774 |
|
|---|
| 1775 | // src/query/core/buildSelectors.ts
|
|---|
| 1776 | var skipToken = /* @__PURE__ */ Symbol.for("RTKQ/skipToken");
|
|---|
| 1777 | var initialSubState = {
|
|---|
| 1778 | status: STATUS_UNINITIALIZED
|
|---|
| 1779 | };
|
|---|
| 1780 | var defaultQuerySubState = /* @__PURE__ */ createNextState(initialSubState, () => {
|
|---|
| 1781 | });
|
|---|
| 1782 | var defaultMutationSubState = /* @__PURE__ */ createNextState(initialSubState, () => {
|
|---|
| 1783 | });
|
|---|
| 1784 | function buildSelectors({
|
|---|
| 1785 | serializeQueryArgs,
|
|---|
| 1786 | reducerPath,
|
|---|
| 1787 | createSelector: createSelector2
|
|---|
| 1788 | }) {
|
|---|
| 1789 | const selectSkippedQuery = (state) => defaultQuerySubState;
|
|---|
| 1790 | const selectSkippedMutation = (state) => defaultMutationSubState;
|
|---|
| 1791 | return {
|
|---|
| 1792 | buildQuerySelector,
|
|---|
| 1793 | buildInfiniteQuerySelector,
|
|---|
| 1794 | buildMutationSelector,
|
|---|
| 1795 | selectInvalidatedBy,
|
|---|
| 1796 | selectCachedArgsForQuery,
|
|---|
| 1797 | selectApiState,
|
|---|
| 1798 | selectQueries,
|
|---|
| 1799 | selectMutations,
|
|---|
| 1800 | selectQueryEntry,
|
|---|
| 1801 | selectConfig
|
|---|
| 1802 | };
|
|---|
| 1803 | function withRequestFlags(substate) {
|
|---|
| 1804 | return __spreadValues(__spreadValues({}, substate), getRequestStatusFlags(substate.status));
|
|---|
| 1805 | }
|
|---|
| 1806 | function selectApiState(rootState) {
|
|---|
| 1807 | const state = rootState[reducerPath];
|
|---|
| 1808 | if (process.env.NODE_ENV !== "production") {
|
|---|
| 1809 | if (!state) {
|
|---|
| 1810 | if (selectApiState.triggered) return state;
|
|---|
| 1811 | selectApiState.triggered = true;
|
|---|
| 1812 | console.error(`Error: No data found at \`state.${reducerPath}\`. Did you forget to add the reducer to the store?`);
|
|---|
| 1813 | }
|
|---|
| 1814 | }
|
|---|
| 1815 | return state;
|
|---|
| 1816 | }
|
|---|
| 1817 | function selectQueries(rootState) {
|
|---|
| 1818 | var _a;
|
|---|
| 1819 | return (_a = selectApiState(rootState)) == null ? void 0 : _a.queries;
|
|---|
| 1820 | }
|
|---|
| 1821 | function selectQueryEntry(rootState, cacheKey) {
|
|---|
| 1822 | var _a;
|
|---|
| 1823 | return (_a = selectQueries(rootState)) == null ? void 0 : _a[cacheKey];
|
|---|
| 1824 | }
|
|---|
| 1825 | function selectMutations(rootState) {
|
|---|
| 1826 | var _a;
|
|---|
| 1827 | return (_a = selectApiState(rootState)) == null ? void 0 : _a.mutations;
|
|---|
| 1828 | }
|
|---|
| 1829 | function selectConfig(rootState) {
|
|---|
| 1830 | var _a;
|
|---|
| 1831 | return (_a = selectApiState(rootState)) == null ? void 0 : _a.config;
|
|---|
| 1832 | }
|
|---|
| 1833 | function buildAnyQuerySelector(endpointName, endpointDefinition, combiner) {
|
|---|
| 1834 | return (queryArgs) => {
|
|---|
| 1835 | if (queryArgs === skipToken) {
|
|---|
| 1836 | return createSelector2(selectSkippedQuery, combiner);
|
|---|
| 1837 | }
|
|---|
| 1838 | const serializedArgs = serializeQueryArgs({
|
|---|
| 1839 | queryArgs,
|
|---|
| 1840 | endpointDefinition,
|
|---|
| 1841 | endpointName
|
|---|
| 1842 | });
|
|---|
| 1843 | const selectQuerySubstate = (state) => {
|
|---|
| 1844 | var _a;
|
|---|
| 1845 | return (_a = selectQueryEntry(state, serializedArgs)) != null ? _a : defaultQuerySubState;
|
|---|
| 1846 | };
|
|---|
| 1847 | return createSelector2(selectQuerySubstate, combiner);
|
|---|
| 1848 | };
|
|---|
| 1849 | }
|
|---|
| 1850 | function buildQuerySelector(endpointName, endpointDefinition) {
|
|---|
| 1851 | return buildAnyQuerySelector(endpointName, endpointDefinition, withRequestFlags);
|
|---|
| 1852 | }
|
|---|
| 1853 | function buildInfiniteQuerySelector(endpointName, endpointDefinition) {
|
|---|
| 1854 | const {
|
|---|
| 1855 | infiniteQueryOptions
|
|---|
| 1856 | } = endpointDefinition;
|
|---|
| 1857 | function withInfiniteQueryResultFlags(substate) {
|
|---|
| 1858 | const stateWithRequestFlags = __spreadValues(__spreadValues({}, substate), getRequestStatusFlags(substate.status));
|
|---|
| 1859 | const {
|
|---|
| 1860 | isLoading,
|
|---|
| 1861 | isError,
|
|---|
| 1862 | direction
|
|---|
| 1863 | } = stateWithRequestFlags;
|
|---|
| 1864 | const isForward = direction === "forward";
|
|---|
| 1865 | const isBackward = direction === "backward";
|
|---|
| 1866 | return __spreadProps(__spreadValues({}, stateWithRequestFlags), {
|
|---|
| 1867 | hasNextPage: getHasNextPage(infiniteQueryOptions, stateWithRequestFlags.data, stateWithRequestFlags.originalArgs),
|
|---|
| 1868 | hasPreviousPage: getHasPreviousPage(infiniteQueryOptions, stateWithRequestFlags.data, stateWithRequestFlags.originalArgs),
|
|---|
| 1869 | isFetchingNextPage: isLoading && isForward,
|
|---|
| 1870 | isFetchingPreviousPage: isLoading && isBackward,
|
|---|
| 1871 | isFetchNextPageError: isError && isForward,
|
|---|
| 1872 | isFetchPreviousPageError: isError && isBackward
|
|---|
| 1873 | });
|
|---|
| 1874 | }
|
|---|
| 1875 | return buildAnyQuerySelector(endpointName, endpointDefinition, withInfiniteQueryResultFlags);
|
|---|
| 1876 | }
|
|---|
| 1877 | function buildMutationSelector() {
|
|---|
| 1878 | return (id) => {
|
|---|
| 1879 | var _a;
|
|---|
| 1880 | let mutationId;
|
|---|
| 1881 | if (typeof id === "object") {
|
|---|
| 1882 | mutationId = (_a = getMutationCacheKey(id)) != null ? _a : skipToken;
|
|---|
| 1883 | } else {
|
|---|
| 1884 | mutationId = id;
|
|---|
| 1885 | }
|
|---|
| 1886 | const selectMutationSubstate = (state) => {
|
|---|
| 1887 | var _a2, _b, _c;
|
|---|
| 1888 | return (_c = (_b = (_a2 = selectApiState(state)) == null ? void 0 : _a2.mutations) == null ? void 0 : _b[mutationId]) != null ? _c : defaultMutationSubState;
|
|---|
| 1889 | };
|
|---|
| 1890 | const finalSelectMutationSubstate = mutationId === skipToken ? selectSkippedMutation : selectMutationSubstate;
|
|---|
| 1891 | return createSelector2(finalSelectMutationSubstate, withRequestFlags);
|
|---|
| 1892 | };
|
|---|
| 1893 | }
|
|---|
| 1894 | function selectInvalidatedBy(state, tags) {
|
|---|
| 1895 | var _a;
|
|---|
| 1896 | const apiState = state[reducerPath];
|
|---|
| 1897 | const toInvalidate = /* @__PURE__ */ new Set();
|
|---|
| 1898 | const finalTags = filterMap(tags, isNotNullish, expandTagDescription);
|
|---|
| 1899 | for (const tag of finalTags) {
|
|---|
| 1900 | const provided = apiState.provided.tags[tag.type];
|
|---|
| 1901 | if (!provided) {
|
|---|
| 1902 | continue;
|
|---|
| 1903 | }
|
|---|
| 1904 | let invalidateSubscriptions = (_a = tag.id !== void 0 ? (
|
|---|
| 1905 | // id given: invalidate all queries that provide this type & id
|
|---|
| 1906 | provided[tag.id]
|
|---|
| 1907 | ) : (
|
|---|
| 1908 | // no id: invalidate all queries that provide this type
|
|---|
| 1909 | Object.values(provided).flat()
|
|---|
| 1910 | )) != null ? _a : [];
|
|---|
| 1911 | for (const invalidate of invalidateSubscriptions) {
|
|---|
| 1912 | toInvalidate.add(invalidate);
|
|---|
| 1913 | }
|
|---|
| 1914 | }
|
|---|
| 1915 | return Array.from(toInvalidate.values()).flatMap((queryCacheKey) => {
|
|---|
| 1916 | const querySubState = apiState.queries[queryCacheKey];
|
|---|
| 1917 | return querySubState ? {
|
|---|
| 1918 | queryCacheKey,
|
|---|
| 1919 | endpointName: querySubState.endpointName,
|
|---|
| 1920 | originalArgs: querySubState.originalArgs
|
|---|
| 1921 | } : [];
|
|---|
| 1922 | });
|
|---|
| 1923 | }
|
|---|
| 1924 | function selectCachedArgsForQuery(state, queryName) {
|
|---|
| 1925 | return filterMap(Object.values(selectQueries(state)), (entry) => (entry == null ? void 0 : entry.endpointName) === queryName && entry.status !== STATUS_UNINITIALIZED, (entry) => entry.originalArgs);
|
|---|
| 1926 | }
|
|---|
| 1927 | function getHasNextPage(options, data, queryArg) {
|
|---|
| 1928 | if (!data) return false;
|
|---|
| 1929 | return getNextPageParam(options, data, queryArg) != null;
|
|---|
| 1930 | }
|
|---|
| 1931 | function getHasPreviousPage(options, data, queryArg) {
|
|---|
| 1932 | if (!data || !options.getPreviousPageParam) return false;
|
|---|
| 1933 | return getPreviousPageParam(options, data, queryArg) != null;
|
|---|
| 1934 | }
|
|---|
| 1935 | }
|
|---|
| 1936 |
|
|---|
| 1937 | // src/query/createApi.ts
|
|---|
| 1938 | import { formatProdErrorMessage as _formatProdErrorMessage2, formatProdErrorMessage as _formatProdErrorMessage22, formatProdErrorMessage as _formatProdErrorMessage3 } from "@reduxjs/toolkit";
|
|---|
| 1939 |
|
|---|
| 1940 | // src/query/defaultSerializeQueryArgs.ts
|
|---|
| 1941 | var cache = WeakMap ? /* @__PURE__ */ new WeakMap() : void 0;
|
|---|
| 1942 | var defaultSerializeQueryArgs = ({
|
|---|
| 1943 | endpointName,
|
|---|
| 1944 | queryArgs
|
|---|
| 1945 | }) => {
|
|---|
| 1946 | let serialized = "";
|
|---|
| 1947 | const cached = cache == null ? void 0 : cache.get(queryArgs);
|
|---|
| 1948 | if (typeof cached === "string") {
|
|---|
| 1949 | serialized = cached;
|
|---|
| 1950 | } else {
|
|---|
| 1951 | const stringified = JSON.stringify(queryArgs, (key, value) => {
|
|---|
| 1952 | value = typeof value === "bigint" ? {
|
|---|
| 1953 | $bigint: value.toString()
|
|---|
| 1954 | } : value;
|
|---|
| 1955 | value = isPlainObject(value) ? Object.keys(value).sort().reduce((acc, key2) => {
|
|---|
| 1956 | acc[key2] = value[key2];
|
|---|
| 1957 | return acc;
|
|---|
| 1958 | }, {}) : value;
|
|---|
| 1959 | return value;
|
|---|
| 1960 | });
|
|---|
| 1961 | if (isPlainObject(queryArgs)) {
|
|---|
| 1962 | cache == null ? void 0 : cache.set(queryArgs, stringified);
|
|---|
| 1963 | }
|
|---|
| 1964 | serialized = stringified;
|
|---|
| 1965 | }
|
|---|
| 1966 | return `${endpointName}(${serialized})`;
|
|---|
| 1967 | };
|
|---|
| 1968 |
|
|---|
| 1969 | // src/query/createApi.ts
|
|---|
| 1970 | import { weakMapMemoize } from "reselect";
|
|---|
| 1971 | function buildCreateApi(...modules) {
|
|---|
| 1972 | return function baseCreateApi(options) {
|
|---|
| 1973 | const extractRehydrationInfo = weakMapMemoize((action) => {
|
|---|
| 1974 | var _a, _b;
|
|---|
| 1975 | return (_b = options.extractRehydrationInfo) == null ? void 0 : _b.call(options, action, {
|
|---|
| 1976 | reducerPath: (_a = options.reducerPath) != null ? _a : "api"
|
|---|
| 1977 | });
|
|---|
| 1978 | });
|
|---|
| 1979 | const optionsWithDefaults = __spreadProps(__spreadValues({
|
|---|
| 1980 | reducerPath: "api",
|
|---|
| 1981 | keepUnusedDataFor: 60,
|
|---|
| 1982 | refetchOnMountOrArgChange: false,
|
|---|
| 1983 | refetchOnFocus: false,
|
|---|
| 1984 | refetchOnReconnect: false,
|
|---|
| 1985 | invalidationBehavior: "delayed"
|
|---|
| 1986 | }, options), {
|
|---|
| 1987 | extractRehydrationInfo,
|
|---|
| 1988 | serializeQueryArgs(queryArgsApi) {
|
|---|
| 1989 | let finalSerializeQueryArgs = defaultSerializeQueryArgs;
|
|---|
| 1990 | if ("serializeQueryArgs" in queryArgsApi.endpointDefinition) {
|
|---|
| 1991 | const endpointSQA = queryArgsApi.endpointDefinition.serializeQueryArgs;
|
|---|
| 1992 | finalSerializeQueryArgs = (queryArgsApi2) => {
|
|---|
| 1993 | const initialResult = endpointSQA(queryArgsApi2);
|
|---|
| 1994 | if (typeof initialResult === "string") {
|
|---|
| 1995 | return initialResult;
|
|---|
| 1996 | } else {
|
|---|
| 1997 | return defaultSerializeQueryArgs(__spreadProps(__spreadValues({}, queryArgsApi2), {
|
|---|
| 1998 | queryArgs: initialResult
|
|---|
| 1999 | }));
|
|---|
| 2000 | }
|
|---|
| 2001 | };
|
|---|
| 2002 | } else if (options.serializeQueryArgs) {
|
|---|
| 2003 | finalSerializeQueryArgs = options.serializeQueryArgs;
|
|---|
| 2004 | }
|
|---|
| 2005 | return finalSerializeQueryArgs(queryArgsApi);
|
|---|
| 2006 | },
|
|---|
| 2007 | tagTypes: [...options.tagTypes || []]
|
|---|
| 2008 | });
|
|---|
| 2009 | const context = {
|
|---|
| 2010 | endpointDefinitions: {},
|
|---|
| 2011 | batch(fn) {
|
|---|
| 2012 | fn();
|
|---|
| 2013 | },
|
|---|
| 2014 | apiUid: nanoid(),
|
|---|
| 2015 | extractRehydrationInfo,
|
|---|
| 2016 | hasRehydrationInfo: weakMapMemoize((action) => extractRehydrationInfo(action) != null)
|
|---|
| 2017 | };
|
|---|
| 2018 | const api = {
|
|---|
| 2019 | injectEndpoints,
|
|---|
| 2020 | enhanceEndpoints({
|
|---|
| 2021 | addTagTypes,
|
|---|
| 2022 | endpoints
|
|---|
| 2023 | }) {
|
|---|
| 2024 | if (addTagTypes) {
|
|---|
| 2025 | for (const eT of addTagTypes) {
|
|---|
| 2026 | if (!optionsWithDefaults.tagTypes.includes(eT)) {
|
|---|
| 2027 | ;
|
|---|
| 2028 | optionsWithDefaults.tagTypes.push(eT);
|
|---|
| 2029 | }
|
|---|
| 2030 | }
|
|---|
| 2031 | }
|
|---|
| 2032 | if (endpoints) {
|
|---|
| 2033 | for (const [endpointName, partialDefinition] of Object.entries(endpoints)) {
|
|---|
| 2034 | if (typeof partialDefinition === "function") {
|
|---|
| 2035 | partialDefinition(getEndpointDefinition(context, endpointName));
|
|---|
| 2036 | } else {
|
|---|
| 2037 | Object.assign(getEndpointDefinition(context, endpointName) || {}, partialDefinition);
|
|---|
| 2038 | }
|
|---|
| 2039 | }
|
|---|
| 2040 | }
|
|---|
| 2041 | return api;
|
|---|
| 2042 | }
|
|---|
| 2043 | };
|
|---|
| 2044 | const initializedModules = modules.map((m) => m.init(api, optionsWithDefaults, context));
|
|---|
| 2045 | function injectEndpoints(inject) {
|
|---|
| 2046 | const evaluatedEndpoints = inject.endpoints({
|
|---|
| 2047 | query: (x) => __spreadProps(__spreadValues({}, x), {
|
|---|
| 2048 | type: ENDPOINT_QUERY
|
|---|
| 2049 | }),
|
|---|
| 2050 | mutation: (x) => __spreadProps(__spreadValues({}, x), {
|
|---|
| 2051 | type: ENDPOINT_MUTATION
|
|---|
| 2052 | }),
|
|---|
| 2053 | infiniteQuery: (x) => __spreadProps(__spreadValues({}, x), {
|
|---|
| 2054 | type: ENDPOINT_INFINITEQUERY
|
|---|
| 2055 | })
|
|---|
| 2056 | });
|
|---|
| 2057 | for (const [endpointName, definition] of Object.entries(evaluatedEndpoints)) {
|
|---|
| 2058 | if (inject.overrideExisting !== true && endpointName in context.endpointDefinitions) {
|
|---|
| 2059 | if (inject.overrideExisting === "throw") {
|
|---|
| 2060 | throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage2(39) : `called \`injectEndpoints\` to override already-existing endpointName ${endpointName} without specifying \`overrideExisting: true\``);
|
|---|
| 2061 | } else if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|---|
| 2062 | console.error(`called \`injectEndpoints\` to override already-existing endpointName ${endpointName} without specifying \`overrideExisting: true\``);
|
|---|
| 2063 | }
|
|---|
| 2064 | continue;
|
|---|
| 2065 | }
|
|---|
| 2066 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|---|
| 2067 | if (isInfiniteQueryDefinition(definition)) {
|
|---|
| 2068 | const {
|
|---|
| 2069 | infiniteQueryOptions
|
|---|
| 2070 | } = definition;
|
|---|
| 2071 | const {
|
|---|
| 2072 | maxPages,
|
|---|
| 2073 | getPreviousPageParam: getPreviousPageParam2
|
|---|
| 2074 | } = infiniteQueryOptions;
|
|---|
| 2075 | if (typeof maxPages === "number") {
|
|---|
| 2076 | if (maxPages < 1) {
|
|---|
| 2077 | throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage22(40) : `maxPages for endpoint '${endpointName}' must be a number greater than 0`);
|
|---|
| 2078 | }
|
|---|
| 2079 | if (typeof getPreviousPageParam2 !== "function") {
|
|---|
| 2080 | throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage3(41) : `getPreviousPageParam for endpoint '${endpointName}' must be a function if maxPages is used`);
|
|---|
| 2081 | }
|
|---|
| 2082 | }
|
|---|
| 2083 | }
|
|---|
| 2084 | }
|
|---|
| 2085 | context.endpointDefinitions[endpointName] = definition;
|
|---|
| 2086 | for (const m of initializedModules) {
|
|---|
| 2087 | m.injectEndpoint(endpointName, definition);
|
|---|
| 2088 | }
|
|---|
| 2089 | }
|
|---|
| 2090 | return api;
|
|---|
| 2091 | }
|
|---|
| 2092 | return api.injectEndpoints({
|
|---|
| 2093 | endpoints: options.endpoints
|
|---|
| 2094 | });
|
|---|
| 2095 | };
|
|---|
| 2096 | }
|
|---|
| 2097 |
|
|---|
| 2098 | // src/query/fakeBaseQuery.ts
|
|---|
| 2099 | import { formatProdErrorMessage as _formatProdErrorMessage4 } from "@reduxjs/toolkit";
|
|---|
| 2100 | var _NEVER = /* @__PURE__ */ Symbol();
|
|---|
| 2101 | function fakeBaseQuery() {
|
|---|
| 2102 | return function() {
|
|---|
| 2103 | throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage4(33) : "When using `fakeBaseQuery`, all queries & mutations must use the `queryFn` definition syntax.");
|
|---|
| 2104 | };
|
|---|
| 2105 | }
|
|---|
| 2106 |
|
|---|
| 2107 | // src/query/tsHelpers.ts
|
|---|
| 2108 | function assertCast(v) {
|
|---|
| 2109 | }
|
|---|
| 2110 | function safeAssign(target, ...args) {
|
|---|
| 2111 | return Object.assign(target, ...args);
|
|---|
| 2112 | }
|
|---|
| 2113 |
|
|---|
| 2114 | // src/query/core/buildMiddleware/batchActions.ts
|
|---|
| 2115 | var buildBatchedActionsHandler = ({
|
|---|
| 2116 | api,
|
|---|
| 2117 | queryThunk,
|
|---|
| 2118 | internalState,
|
|---|
| 2119 | mwApi
|
|---|
| 2120 | }) => {
|
|---|
| 2121 | const subscriptionsPrefix = `${api.reducerPath}/subscriptions`;
|
|---|
| 2122 | let previousSubscriptions = null;
|
|---|
| 2123 | let updateSyncTimer = null;
|
|---|
| 2124 | const {
|
|---|
| 2125 | updateSubscriptionOptions,
|
|---|
| 2126 | unsubscribeQueryResult
|
|---|
| 2127 | } = api.internalActions;
|
|---|
| 2128 | const actuallyMutateSubscriptions = (currentSubscriptions, action) => {
|
|---|
| 2129 | var _a, _b, _c, _d;
|
|---|
| 2130 | if (updateSubscriptionOptions.match(action)) {
|
|---|
| 2131 | const {
|
|---|
| 2132 | queryCacheKey,
|
|---|
| 2133 | requestId,
|
|---|
| 2134 | options
|
|---|
| 2135 | } = action.payload;
|
|---|
| 2136 | const sub = currentSubscriptions.get(queryCacheKey);
|
|---|
| 2137 | if (sub == null ? void 0 : sub.has(requestId)) {
|
|---|
| 2138 | sub.set(requestId, options);
|
|---|
| 2139 | }
|
|---|
| 2140 | return true;
|
|---|
| 2141 | }
|
|---|
| 2142 | if (unsubscribeQueryResult.match(action)) {
|
|---|
| 2143 | const {
|
|---|
| 2144 | queryCacheKey,
|
|---|
| 2145 | requestId
|
|---|
| 2146 | } = action.payload;
|
|---|
| 2147 | const sub = currentSubscriptions.get(queryCacheKey);
|
|---|
| 2148 | if (sub) {
|
|---|
| 2149 | sub.delete(requestId);
|
|---|
| 2150 | }
|
|---|
| 2151 | return true;
|
|---|
| 2152 | }
|
|---|
| 2153 | if (api.internalActions.removeQueryResult.match(action)) {
|
|---|
| 2154 | currentSubscriptions.delete(action.payload.queryCacheKey);
|
|---|
| 2155 | return true;
|
|---|
| 2156 | }
|
|---|
| 2157 | if (queryThunk.pending.match(action)) {
|
|---|
| 2158 | const {
|
|---|
| 2159 | meta: {
|
|---|
| 2160 | arg,
|
|---|
| 2161 | requestId
|
|---|
| 2162 | }
|
|---|
| 2163 | } = action;
|
|---|
| 2164 | const substate = getOrInsertComputed(currentSubscriptions, arg.queryCacheKey, createNewMap);
|
|---|
| 2165 | if (arg.subscribe) {
|
|---|
| 2166 | substate.set(requestId, (_b = (_a = arg.subscriptionOptions) != null ? _a : substate.get(requestId)) != null ? _b : {});
|
|---|
| 2167 | }
|
|---|
| 2168 | return true;
|
|---|
| 2169 | }
|
|---|
| 2170 | let mutated = false;
|
|---|
| 2171 | if (queryThunk.rejected.match(action)) {
|
|---|
| 2172 | const {
|
|---|
| 2173 | meta: {
|
|---|
| 2174 | condition,
|
|---|
| 2175 | arg,
|
|---|
| 2176 | requestId
|
|---|
| 2177 | }
|
|---|
| 2178 | } = action;
|
|---|
| 2179 | if (condition && arg.subscribe) {
|
|---|
| 2180 | const substate = getOrInsertComputed(currentSubscriptions, arg.queryCacheKey, createNewMap);
|
|---|
| 2181 | substate.set(requestId, (_d = (_c = arg.subscriptionOptions) != null ? _c : substate.get(requestId)) != null ? _d : {});
|
|---|
| 2182 | mutated = true;
|
|---|
| 2183 | }
|
|---|
| 2184 | }
|
|---|
| 2185 | return mutated;
|
|---|
| 2186 | };
|
|---|
| 2187 | const getSubscriptions = () => internalState.currentSubscriptions;
|
|---|
| 2188 | const getSubscriptionCount = (queryCacheKey) => {
|
|---|
| 2189 | var _a;
|
|---|
| 2190 | const subscriptions = getSubscriptions();
|
|---|
| 2191 | const subscriptionsForQueryArg = subscriptions.get(queryCacheKey);
|
|---|
| 2192 | return (_a = subscriptionsForQueryArg == null ? void 0 : subscriptionsForQueryArg.size) != null ? _a : 0;
|
|---|
| 2193 | };
|
|---|
| 2194 | const isRequestSubscribed = (queryCacheKey, requestId) => {
|
|---|
| 2195 | var _a;
|
|---|
| 2196 | const subscriptions = getSubscriptions();
|
|---|
| 2197 | return !!((_a = subscriptions == null ? void 0 : subscriptions.get(queryCacheKey)) == null ? void 0 : _a.get(requestId));
|
|---|
| 2198 | };
|
|---|
| 2199 | const subscriptionSelectors = {
|
|---|
| 2200 | getSubscriptions,
|
|---|
| 2201 | getSubscriptionCount,
|
|---|
| 2202 | isRequestSubscribed
|
|---|
| 2203 | };
|
|---|
| 2204 | function serializeSubscriptions(currentSubscriptions) {
|
|---|
| 2205 | return JSON.parse(JSON.stringify(Object.fromEntries([...currentSubscriptions].map(([k, v]) => [k, Object.fromEntries(v)]))));
|
|---|
| 2206 | }
|
|---|
| 2207 | return (action, mwApi2) => {
|
|---|
| 2208 | if (!previousSubscriptions) {
|
|---|
| 2209 | previousSubscriptions = serializeSubscriptions(internalState.currentSubscriptions);
|
|---|
| 2210 | }
|
|---|
| 2211 | if (api.util.resetApiState.match(action)) {
|
|---|
| 2212 | previousSubscriptions = {};
|
|---|
| 2213 | internalState.currentSubscriptions.clear();
|
|---|
| 2214 | updateSyncTimer = null;
|
|---|
| 2215 | return [true, false];
|
|---|
| 2216 | }
|
|---|
| 2217 | if (api.internalActions.internal_getRTKQSubscriptions.match(action)) {
|
|---|
| 2218 | return [false, subscriptionSelectors];
|
|---|
| 2219 | }
|
|---|
| 2220 | const didMutate = actuallyMutateSubscriptions(internalState.currentSubscriptions, action);
|
|---|
| 2221 | let actionShouldContinue = true;
|
|---|
| 2222 | if (process.env.NODE_ENV === "test" && typeof action.type === "string" && action.type === `${api.reducerPath}/getPolling`) {
|
|---|
| 2223 | return [false, internalState.currentPolls];
|
|---|
| 2224 | }
|
|---|
| 2225 | if (didMutate) {
|
|---|
| 2226 | if (!updateSyncTimer) {
|
|---|
| 2227 | updateSyncTimer = setTimeout(() => {
|
|---|
| 2228 | const newSubscriptions = serializeSubscriptions(internalState.currentSubscriptions);
|
|---|
| 2229 | const [, patches] = produceWithPatches(previousSubscriptions, () => newSubscriptions);
|
|---|
| 2230 | mwApi2.next(api.internalActions.subscriptionsUpdated(patches));
|
|---|
| 2231 | previousSubscriptions = newSubscriptions;
|
|---|
| 2232 | updateSyncTimer = null;
|
|---|
| 2233 | }, 500);
|
|---|
| 2234 | }
|
|---|
| 2235 | const isSubscriptionSliceAction = typeof action.type == "string" && !!action.type.startsWith(subscriptionsPrefix);
|
|---|
| 2236 | const isAdditionalSubscriptionAction = queryThunk.rejected.match(action) && action.meta.condition && !!action.meta.arg.subscribe;
|
|---|
| 2237 | actionShouldContinue = !isSubscriptionSliceAction && !isAdditionalSubscriptionAction;
|
|---|
| 2238 | }
|
|---|
| 2239 | return [actionShouldContinue, false];
|
|---|
| 2240 | };
|
|---|
| 2241 | };
|
|---|
| 2242 |
|
|---|
| 2243 | // src/query/core/buildMiddleware/cacheCollection.ts
|
|---|
| 2244 | var THIRTY_TWO_BIT_MAX_TIMER_SECONDS = 2147483647 / 1e3 - 1;
|
|---|
| 2245 | var buildCacheCollectionHandler = ({
|
|---|
| 2246 | reducerPath,
|
|---|
| 2247 | api,
|
|---|
| 2248 | queryThunk,
|
|---|
| 2249 | context,
|
|---|
| 2250 | internalState,
|
|---|
| 2251 | selectors: {
|
|---|
| 2252 | selectQueryEntry,
|
|---|
| 2253 | selectConfig
|
|---|
| 2254 | },
|
|---|
| 2255 | getRunningQueryThunk,
|
|---|
| 2256 | mwApi
|
|---|
| 2257 | }) => {
|
|---|
| 2258 | const {
|
|---|
| 2259 | removeQueryResult,
|
|---|
| 2260 | unsubscribeQueryResult,
|
|---|
| 2261 | cacheEntriesUpserted
|
|---|
| 2262 | } = api.internalActions;
|
|---|
| 2263 | const canTriggerUnsubscribe = isAnyOf(unsubscribeQueryResult.match, queryThunk.fulfilled, queryThunk.rejected, cacheEntriesUpserted.match);
|
|---|
| 2264 | function anySubscriptionsRemainingForKey(queryCacheKey) {
|
|---|
| 2265 | const subscriptions = internalState.currentSubscriptions.get(queryCacheKey);
|
|---|
| 2266 | if (!subscriptions) {
|
|---|
| 2267 | return false;
|
|---|
| 2268 | }
|
|---|
| 2269 | const hasSubscriptions = subscriptions.size > 0;
|
|---|
| 2270 | return hasSubscriptions;
|
|---|
| 2271 | }
|
|---|
| 2272 | const currentRemovalTimeouts = {};
|
|---|
| 2273 | function abortAllPromises(promiseMap) {
|
|---|
| 2274 | var _a;
|
|---|
| 2275 | for (const promise of promiseMap.values()) {
|
|---|
| 2276 | (_a = promise == null ? void 0 : promise.abort) == null ? void 0 : _a.call(promise);
|
|---|
| 2277 | }
|
|---|
| 2278 | }
|
|---|
| 2279 | const handler = (action, mwApi2) => {
|
|---|
| 2280 | const state = mwApi2.getState();
|
|---|
| 2281 | const config = selectConfig(state);
|
|---|
| 2282 | if (canTriggerUnsubscribe(action)) {
|
|---|
| 2283 | let queryCacheKeys;
|
|---|
| 2284 | if (cacheEntriesUpserted.match(action)) {
|
|---|
| 2285 | queryCacheKeys = action.payload.map((entry) => entry.queryDescription.queryCacheKey);
|
|---|
| 2286 | } else {
|
|---|
| 2287 | const {
|
|---|
| 2288 | queryCacheKey
|
|---|
| 2289 | } = unsubscribeQueryResult.match(action) ? action.payload : action.meta.arg;
|
|---|
| 2290 | queryCacheKeys = [queryCacheKey];
|
|---|
| 2291 | }
|
|---|
| 2292 | handleUnsubscribeMany(queryCacheKeys, mwApi2, config);
|
|---|
| 2293 | }
|
|---|
| 2294 | if (api.util.resetApiState.match(action)) {
|
|---|
| 2295 | for (const [key, timeout] of Object.entries(currentRemovalTimeouts)) {
|
|---|
| 2296 | if (timeout) clearTimeout(timeout);
|
|---|
| 2297 | delete currentRemovalTimeouts[key];
|
|---|
| 2298 | }
|
|---|
| 2299 | abortAllPromises(internalState.runningQueries);
|
|---|
| 2300 | abortAllPromises(internalState.runningMutations);
|
|---|
| 2301 | }
|
|---|
| 2302 | if (context.hasRehydrationInfo(action)) {
|
|---|
| 2303 | const {
|
|---|
| 2304 | queries
|
|---|
| 2305 | } = context.extractRehydrationInfo(action);
|
|---|
| 2306 | handleUnsubscribeMany(Object.keys(queries), mwApi2, config);
|
|---|
| 2307 | }
|
|---|
| 2308 | };
|
|---|
| 2309 | function handleUnsubscribeMany(cacheKeys, api2, config) {
|
|---|
| 2310 | const state = api2.getState();
|
|---|
| 2311 | for (const queryCacheKey of cacheKeys) {
|
|---|
| 2312 | const entry = selectQueryEntry(state, queryCacheKey);
|
|---|
| 2313 | if (entry == null ? void 0 : entry.endpointName) {
|
|---|
| 2314 | handleUnsubscribe(queryCacheKey, entry.endpointName, api2, config);
|
|---|
| 2315 | }
|
|---|
| 2316 | }
|
|---|
| 2317 | }
|
|---|
| 2318 | function handleUnsubscribe(queryCacheKey, endpointName, api2, config) {
|
|---|
| 2319 | var _a;
|
|---|
| 2320 | const endpointDefinition = getEndpointDefinition(context, endpointName);
|
|---|
| 2321 | const keepUnusedDataFor = (_a = endpointDefinition == null ? void 0 : endpointDefinition.keepUnusedDataFor) != null ? _a : config.keepUnusedDataFor;
|
|---|
| 2322 | if (keepUnusedDataFor === Infinity) {
|
|---|
| 2323 | return;
|
|---|
| 2324 | }
|
|---|
| 2325 | const finalKeepUnusedDataFor = Math.max(0, Math.min(keepUnusedDataFor, THIRTY_TWO_BIT_MAX_TIMER_SECONDS));
|
|---|
| 2326 | if (!anySubscriptionsRemainingForKey(queryCacheKey)) {
|
|---|
| 2327 | const currentTimeout = currentRemovalTimeouts[queryCacheKey];
|
|---|
| 2328 | if (currentTimeout) {
|
|---|
| 2329 | clearTimeout(currentTimeout);
|
|---|
| 2330 | }
|
|---|
| 2331 | currentRemovalTimeouts[queryCacheKey] = setTimeout(() => {
|
|---|
| 2332 | if (!anySubscriptionsRemainingForKey(queryCacheKey)) {
|
|---|
| 2333 | const entry = selectQueryEntry(api2.getState(), queryCacheKey);
|
|---|
| 2334 | if (entry == null ? void 0 : entry.endpointName) {
|
|---|
| 2335 | const runningQuery = api2.dispatch(getRunningQueryThunk(entry.endpointName, entry.originalArgs));
|
|---|
| 2336 | runningQuery == null ? void 0 : runningQuery.abort();
|
|---|
| 2337 | }
|
|---|
| 2338 | api2.dispatch(removeQueryResult({
|
|---|
| 2339 | queryCacheKey
|
|---|
| 2340 | }));
|
|---|
| 2341 | }
|
|---|
| 2342 | delete currentRemovalTimeouts[queryCacheKey];
|
|---|
| 2343 | }, finalKeepUnusedDataFor * 1e3);
|
|---|
| 2344 | }
|
|---|
| 2345 | }
|
|---|
| 2346 | return handler;
|
|---|
| 2347 | };
|
|---|
| 2348 |
|
|---|
| 2349 | // src/query/core/buildMiddleware/cacheLifecycle.ts
|
|---|
| 2350 | var neverResolvedError = new Error("Promise never resolved before cacheEntryRemoved.");
|
|---|
| 2351 | var buildCacheLifecycleHandler = ({
|
|---|
| 2352 | api,
|
|---|
| 2353 | reducerPath,
|
|---|
| 2354 | context,
|
|---|
| 2355 | queryThunk,
|
|---|
| 2356 | mutationThunk,
|
|---|
| 2357 | internalState,
|
|---|
| 2358 | selectors: {
|
|---|
| 2359 | selectQueryEntry,
|
|---|
| 2360 | selectApiState
|
|---|
| 2361 | }
|
|---|
| 2362 | }) => {
|
|---|
| 2363 | const isQueryThunk = isAsyncThunkAction(queryThunk);
|
|---|
| 2364 | const isMutationThunk = isAsyncThunkAction(mutationThunk);
|
|---|
| 2365 | const isFulfilledThunk = isFulfilled(queryThunk, mutationThunk);
|
|---|
| 2366 | const lifecycleMap = {};
|
|---|
| 2367 | const {
|
|---|
| 2368 | removeQueryResult,
|
|---|
| 2369 | removeMutationResult,
|
|---|
| 2370 | cacheEntriesUpserted
|
|---|
| 2371 | } = api.internalActions;
|
|---|
| 2372 | function resolveLifecycleEntry(cacheKey, data, meta) {
|
|---|
| 2373 | const lifecycle = lifecycleMap[cacheKey];
|
|---|
| 2374 | if (lifecycle == null ? void 0 : lifecycle.valueResolved) {
|
|---|
| 2375 | lifecycle.valueResolved({
|
|---|
| 2376 | data,
|
|---|
| 2377 | meta
|
|---|
| 2378 | });
|
|---|
| 2379 | delete lifecycle.valueResolved;
|
|---|
| 2380 | }
|
|---|
| 2381 | }
|
|---|
| 2382 | function removeLifecycleEntry(cacheKey) {
|
|---|
| 2383 | const lifecycle = lifecycleMap[cacheKey];
|
|---|
| 2384 | if (lifecycle) {
|
|---|
| 2385 | delete lifecycleMap[cacheKey];
|
|---|
| 2386 | lifecycle.cacheEntryRemoved();
|
|---|
| 2387 | }
|
|---|
| 2388 | }
|
|---|
| 2389 | function getActionMetaFields(action) {
|
|---|
| 2390 | const {
|
|---|
| 2391 | arg,
|
|---|
| 2392 | requestId
|
|---|
| 2393 | } = action.meta;
|
|---|
| 2394 | const {
|
|---|
| 2395 | endpointName,
|
|---|
| 2396 | originalArgs
|
|---|
| 2397 | } = arg;
|
|---|
| 2398 | return [endpointName, originalArgs, requestId];
|
|---|
| 2399 | }
|
|---|
| 2400 | const handler = (action, mwApi, stateBefore) => {
|
|---|
| 2401 | const cacheKey = getCacheKey(action);
|
|---|
| 2402 | function checkForNewCacheKey(endpointName, cacheKey2, requestId, originalArgs) {
|
|---|
| 2403 | const oldEntry = selectQueryEntry(stateBefore, cacheKey2);
|
|---|
| 2404 | const newEntry = selectQueryEntry(mwApi.getState(), cacheKey2);
|
|---|
| 2405 | if (!oldEntry && newEntry) {
|
|---|
| 2406 | handleNewKey(endpointName, originalArgs, cacheKey2, mwApi, requestId);
|
|---|
| 2407 | }
|
|---|
| 2408 | }
|
|---|
| 2409 | if (queryThunk.pending.match(action)) {
|
|---|
| 2410 | const [endpointName, originalArgs, requestId] = getActionMetaFields(action);
|
|---|
| 2411 | checkForNewCacheKey(endpointName, cacheKey, requestId, originalArgs);
|
|---|
| 2412 | } else if (cacheEntriesUpserted.match(action)) {
|
|---|
| 2413 | for (const {
|
|---|
| 2414 | queryDescription,
|
|---|
| 2415 | value
|
|---|
| 2416 | } of action.payload) {
|
|---|
| 2417 | const {
|
|---|
| 2418 | endpointName,
|
|---|
| 2419 | originalArgs,
|
|---|
| 2420 | queryCacheKey
|
|---|
| 2421 | } = queryDescription;
|
|---|
| 2422 | checkForNewCacheKey(endpointName, queryCacheKey, action.meta.requestId, originalArgs);
|
|---|
| 2423 | resolveLifecycleEntry(queryCacheKey, value, {});
|
|---|
| 2424 | }
|
|---|
| 2425 | } else if (mutationThunk.pending.match(action)) {
|
|---|
| 2426 | const state = mwApi.getState()[reducerPath].mutations[cacheKey];
|
|---|
| 2427 | if (state) {
|
|---|
| 2428 | const [endpointName, originalArgs, requestId] = getActionMetaFields(action);
|
|---|
| 2429 | handleNewKey(endpointName, originalArgs, cacheKey, mwApi, requestId);
|
|---|
| 2430 | }
|
|---|
| 2431 | } else if (isFulfilledThunk(action)) {
|
|---|
| 2432 | resolveLifecycleEntry(cacheKey, action.payload, action.meta.baseQueryMeta);
|
|---|
| 2433 | } else if (removeQueryResult.match(action) || removeMutationResult.match(action)) {
|
|---|
| 2434 | removeLifecycleEntry(cacheKey);
|
|---|
| 2435 | } else if (api.util.resetApiState.match(action)) {
|
|---|
| 2436 | for (const cacheKey2 of Object.keys(lifecycleMap)) {
|
|---|
| 2437 | removeLifecycleEntry(cacheKey2);
|
|---|
| 2438 | }
|
|---|
| 2439 | }
|
|---|
| 2440 | };
|
|---|
| 2441 | function getCacheKey(action) {
|
|---|
| 2442 | var _a;
|
|---|
| 2443 | if (isQueryThunk(action)) return action.meta.arg.queryCacheKey;
|
|---|
| 2444 | if (isMutationThunk(action)) {
|
|---|
| 2445 | return (_a = action.meta.arg.fixedCacheKey) != null ? _a : action.meta.requestId;
|
|---|
| 2446 | }
|
|---|
| 2447 | if (removeQueryResult.match(action)) return action.payload.queryCacheKey;
|
|---|
| 2448 | if (removeMutationResult.match(action)) return getMutationCacheKey(action.payload);
|
|---|
| 2449 | return "";
|
|---|
| 2450 | }
|
|---|
| 2451 | function handleNewKey(endpointName, originalArgs, queryCacheKey, mwApi, requestId) {
|
|---|
| 2452 | const endpointDefinition = getEndpointDefinition(context, endpointName);
|
|---|
| 2453 | const onCacheEntryAdded = endpointDefinition == null ? void 0 : endpointDefinition.onCacheEntryAdded;
|
|---|
| 2454 | if (!onCacheEntryAdded) return;
|
|---|
| 2455 | const lifecycle = {};
|
|---|
| 2456 | const cacheEntryRemoved = new Promise((resolve) => {
|
|---|
| 2457 | lifecycle.cacheEntryRemoved = resolve;
|
|---|
| 2458 | });
|
|---|
| 2459 | const cacheDataLoaded = Promise.race([new Promise((resolve) => {
|
|---|
| 2460 | lifecycle.valueResolved = resolve;
|
|---|
| 2461 | }), cacheEntryRemoved.then(() => {
|
|---|
| 2462 | throw neverResolvedError;
|
|---|
| 2463 | })]);
|
|---|
| 2464 | cacheDataLoaded.catch(() => {
|
|---|
| 2465 | });
|
|---|
| 2466 | lifecycleMap[queryCacheKey] = lifecycle;
|
|---|
| 2467 | const selector = api.endpoints[endpointName].select(isAnyQueryDefinition(endpointDefinition) ? originalArgs : queryCacheKey);
|
|---|
| 2468 | const extra = mwApi.dispatch((_, __, extra2) => extra2);
|
|---|
| 2469 | const lifecycleApi = __spreadProps(__spreadValues({}, mwApi), {
|
|---|
| 2470 | getCacheEntry: () => selector(mwApi.getState()),
|
|---|
| 2471 | requestId,
|
|---|
| 2472 | extra,
|
|---|
| 2473 | updateCachedData: isAnyQueryDefinition(endpointDefinition) ? (updateRecipe) => mwApi.dispatch(api.util.updateQueryData(endpointName, originalArgs, updateRecipe)) : void 0,
|
|---|
| 2474 | cacheDataLoaded,
|
|---|
| 2475 | cacheEntryRemoved
|
|---|
| 2476 | });
|
|---|
| 2477 | const runningHandler = onCacheEntryAdded(originalArgs, lifecycleApi);
|
|---|
| 2478 | Promise.resolve(runningHandler).catch((e) => {
|
|---|
| 2479 | if (e === neverResolvedError) return;
|
|---|
| 2480 | throw e;
|
|---|
| 2481 | });
|
|---|
| 2482 | }
|
|---|
| 2483 | return handler;
|
|---|
| 2484 | };
|
|---|
| 2485 |
|
|---|
| 2486 | // src/query/core/buildMiddleware/devMiddleware.ts
|
|---|
| 2487 | var buildDevCheckHandler = ({
|
|---|
| 2488 | api,
|
|---|
| 2489 | context: {
|
|---|
| 2490 | apiUid
|
|---|
| 2491 | },
|
|---|
| 2492 | reducerPath
|
|---|
| 2493 | }) => {
|
|---|
| 2494 | return (action, mwApi) => {
|
|---|
| 2495 | var _a, _b;
|
|---|
| 2496 | if (api.util.resetApiState.match(action)) {
|
|---|
| 2497 | mwApi.dispatch(api.internalActions.middlewareRegistered(apiUid));
|
|---|
| 2498 | }
|
|---|
| 2499 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|---|
| 2500 | if (api.internalActions.middlewareRegistered.match(action) && action.payload === apiUid && ((_b = (_a = mwApi.getState()[reducerPath]) == null ? void 0 : _a.config) == null ? void 0 : _b.middlewareRegistered) === "conflict") {
|
|---|
| 2501 | console.warn(`There is a mismatch between slice and middleware for the reducerPath "${reducerPath}".
|
|---|
| 2502 | You can only have one api per reducer path, this will lead to crashes in various situations!${reducerPath === "api" ? `
|
|---|
| 2503 | If you have multiple apis, you *have* to specify the reducerPath option when using createApi!` : ""}`);
|
|---|
| 2504 | }
|
|---|
| 2505 | }
|
|---|
| 2506 | };
|
|---|
| 2507 | };
|
|---|
| 2508 |
|
|---|
| 2509 | // src/query/core/buildMiddleware/invalidationByTags.ts
|
|---|
| 2510 | var buildInvalidationByTagsHandler = ({
|
|---|
| 2511 | reducerPath,
|
|---|
| 2512 | context,
|
|---|
| 2513 | context: {
|
|---|
| 2514 | endpointDefinitions
|
|---|
| 2515 | },
|
|---|
| 2516 | mutationThunk,
|
|---|
| 2517 | queryThunk,
|
|---|
| 2518 | api,
|
|---|
| 2519 | assertTagType,
|
|---|
| 2520 | refetchQuery,
|
|---|
| 2521 | internalState
|
|---|
| 2522 | }) => {
|
|---|
| 2523 | const {
|
|---|
| 2524 | removeQueryResult
|
|---|
| 2525 | } = api.internalActions;
|
|---|
| 2526 | const isThunkActionWithTags = isAnyOf(isFulfilled(mutationThunk), isRejectedWithValue(mutationThunk));
|
|---|
| 2527 | const isQueryEnd = isAnyOf(isFulfilled(queryThunk, mutationThunk), isRejected(queryThunk, mutationThunk));
|
|---|
| 2528 | let pendingTagInvalidations = [];
|
|---|
| 2529 | let pendingRequestCount = 0;
|
|---|
| 2530 | const handler = (action, mwApi) => {
|
|---|
| 2531 | if (queryThunk.pending.match(action) || mutationThunk.pending.match(action)) {
|
|---|
| 2532 | pendingRequestCount++;
|
|---|
| 2533 | }
|
|---|
| 2534 | if (isQueryEnd(action)) {
|
|---|
| 2535 | pendingRequestCount = Math.max(0, pendingRequestCount - 1);
|
|---|
| 2536 | }
|
|---|
| 2537 | if (isThunkActionWithTags(action)) {
|
|---|
| 2538 | invalidateTags(calculateProvidedByThunk(action, "invalidatesTags", endpointDefinitions, assertTagType), mwApi);
|
|---|
| 2539 | } else if (isQueryEnd(action)) {
|
|---|
| 2540 | invalidateTags([], mwApi);
|
|---|
| 2541 | } else if (api.util.invalidateTags.match(action)) {
|
|---|
| 2542 | invalidateTags(calculateProvidedBy(action.payload, void 0, void 0, void 0, void 0, assertTagType), mwApi);
|
|---|
| 2543 | }
|
|---|
| 2544 | };
|
|---|
| 2545 | function hasPendingRequests() {
|
|---|
| 2546 | return pendingRequestCount > 0;
|
|---|
| 2547 | }
|
|---|
| 2548 | function invalidateTags(newTags, mwApi) {
|
|---|
| 2549 | const rootState = mwApi.getState();
|
|---|
| 2550 | const state = rootState[reducerPath];
|
|---|
| 2551 | pendingTagInvalidations.push(...newTags);
|
|---|
| 2552 | if (state.config.invalidationBehavior === "delayed" && hasPendingRequests()) {
|
|---|
| 2553 | return;
|
|---|
| 2554 | }
|
|---|
| 2555 | const tags = pendingTagInvalidations;
|
|---|
| 2556 | pendingTagInvalidations = [];
|
|---|
| 2557 | if (tags.length === 0) return;
|
|---|
| 2558 | const toInvalidate = api.util.selectInvalidatedBy(rootState, tags);
|
|---|
| 2559 | context.batch(() => {
|
|---|
| 2560 | const valuesArray = Array.from(toInvalidate.values());
|
|---|
| 2561 | for (const {
|
|---|
| 2562 | queryCacheKey
|
|---|
| 2563 | } of valuesArray) {
|
|---|
| 2564 | const querySubState = state.queries[queryCacheKey];
|
|---|
| 2565 | const subscriptionSubState = getOrInsertComputed(internalState.currentSubscriptions, queryCacheKey, createNewMap);
|
|---|
| 2566 | if (querySubState) {
|
|---|
| 2567 | if (subscriptionSubState.size === 0) {
|
|---|
| 2568 | mwApi.dispatch(removeQueryResult({
|
|---|
| 2569 | queryCacheKey
|
|---|
| 2570 | }));
|
|---|
| 2571 | } else if (querySubState.status !== STATUS_UNINITIALIZED) {
|
|---|
| 2572 | mwApi.dispatch(refetchQuery(querySubState));
|
|---|
| 2573 | }
|
|---|
| 2574 | }
|
|---|
| 2575 | }
|
|---|
| 2576 | });
|
|---|
| 2577 | }
|
|---|
| 2578 | return handler;
|
|---|
| 2579 | };
|
|---|
| 2580 |
|
|---|
| 2581 | // src/query/core/buildMiddleware/polling.ts
|
|---|
| 2582 | var buildPollingHandler = ({
|
|---|
| 2583 | reducerPath,
|
|---|
| 2584 | queryThunk,
|
|---|
| 2585 | api,
|
|---|
| 2586 | refetchQuery,
|
|---|
| 2587 | internalState
|
|---|
| 2588 | }) => {
|
|---|
| 2589 | const {
|
|---|
| 2590 | currentPolls,
|
|---|
| 2591 | currentSubscriptions
|
|---|
| 2592 | } = internalState;
|
|---|
| 2593 | const pendingPollingUpdates = /* @__PURE__ */ new Set();
|
|---|
| 2594 | let pollingUpdateTimer = null;
|
|---|
| 2595 | const handler = (action, mwApi) => {
|
|---|
| 2596 | if (api.internalActions.updateSubscriptionOptions.match(action) || api.internalActions.unsubscribeQueryResult.match(action)) {
|
|---|
| 2597 | schedulePollingUpdate(action.payload.queryCacheKey, mwApi);
|
|---|
| 2598 | }
|
|---|
| 2599 | if (queryThunk.pending.match(action) || queryThunk.rejected.match(action) && action.meta.condition) {
|
|---|
| 2600 | schedulePollingUpdate(action.meta.arg.queryCacheKey, mwApi);
|
|---|
| 2601 | }
|
|---|
| 2602 | if (queryThunk.fulfilled.match(action) || queryThunk.rejected.match(action) && !action.meta.condition) {
|
|---|
| 2603 | startNextPoll(action.meta.arg, mwApi);
|
|---|
| 2604 | }
|
|---|
| 2605 | if (api.util.resetApiState.match(action)) {
|
|---|
| 2606 | clearPolls();
|
|---|
| 2607 | if (pollingUpdateTimer) {
|
|---|
| 2608 | clearTimeout(pollingUpdateTimer);
|
|---|
| 2609 | pollingUpdateTimer = null;
|
|---|
| 2610 | }
|
|---|
| 2611 | pendingPollingUpdates.clear();
|
|---|
| 2612 | }
|
|---|
| 2613 | };
|
|---|
| 2614 | function schedulePollingUpdate(queryCacheKey, api2) {
|
|---|
| 2615 | pendingPollingUpdates.add(queryCacheKey);
|
|---|
| 2616 | if (!pollingUpdateTimer) {
|
|---|
| 2617 | pollingUpdateTimer = setTimeout(() => {
|
|---|
| 2618 | for (const key of pendingPollingUpdates) {
|
|---|
| 2619 | updatePollingInterval({
|
|---|
| 2620 | queryCacheKey: key
|
|---|
| 2621 | }, api2);
|
|---|
| 2622 | }
|
|---|
| 2623 | pendingPollingUpdates.clear();
|
|---|
| 2624 | pollingUpdateTimer = null;
|
|---|
| 2625 | }, 0);
|
|---|
| 2626 | }
|
|---|
| 2627 | }
|
|---|
| 2628 | function startNextPoll({
|
|---|
| 2629 | queryCacheKey
|
|---|
| 2630 | }, api2) {
|
|---|
| 2631 | const state = api2.getState()[reducerPath];
|
|---|
| 2632 | const querySubState = state.queries[queryCacheKey];
|
|---|
| 2633 | const subscriptions = currentSubscriptions.get(queryCacheKey);
|
|---|
| 2634 | if (!querySubState || querySubState.status === STATUS_UNINITIALIZED) return;
|
|---|
| 2635 | const {
|
|---|
| 2636 | lowestPollingInterval,
|
|---|
| 2637 | skipPollingIfUnfocused
|
|---|
| 2638 | } = findLowestPollingInterval(subscriptions);
|
|---|
| 2639 | if (!Number.isFinite(lowestPollingInterval)) return;
|
|---|
| 2640 | const currentPoll = currentPolls.get(queryCacheKey);
|
|---|
| 2641 | if (currentPoll == null ? void 0 : currentPoll.timeout) {
|
|---|
| 2642 | clearTimeout(currentPoll.timeout);
|
|---|
| 2643 | currentPoll.timeout = void 0;
|
|---|
| 2644 | }
|
|---|
| 2645 | const nextPollTimestamp = Date.now() + lowestPollingInterval;
|
|---|
| 2646 | currentPolls.set(queryCacheKey, {
|
|---|
| 2647 | nextPollTimestamp,
|
|---|
| 2648 | pollingInterval: lowestPollingInterval,
|
|---|
| 2649 | timeout: setTimeout(() => {
|
|---|
| 2650 | if (state.config.focused || !skipPollingIfUnfocused) {
|
|---|
| 2651 | api2.dispatch(refetchQuery(querySubState));
|
|---|
| 2652 | }
|
|---|
| 2653 | startNextPoll({
|
|---|
| 2654 | queryCacheKey
|
|---|
| 2655 | }, api2);
|
|---|
| 2656 | }, lowestPollingInterval)
|
|---|
| 2657 | });
|
|---|
| 2658 | }
|
|---|
| 2659 | function updatePollingInterval({
|
|---|
| 2660 | queryCacheKey
|
|---|
| 2661 | }, api2) {
|
|---|
| 2662 | var _a, _b;
|
|---|
| 2663 | const state = api2.getState()[reducerPath];
|
|---|
| 2664 | const querySubState = state.queries[queryCacheKey];
|
|---|
| 2665 | const subscriptions = currentSubscriptions.get(queryCacheKey);
|
|---|
| 2666 | if (!querySubState || querySubState.status === STATUS_UNINITIALIZED) {
|
|---|
| 2667 | return;
|
|---|
| 2668 | }
|
|---|
| 2669 | const {
|
|---|
| 2670 | lowestPollingInterval
|
|---|
| 2671 | } = findLowestPollingInterval(subscriptions);
|
|---|
| 2672 | if (process.env.NODE_ENV === "test") {
|
|---|
| 2673 | const updateCounters = (_a = currentPolls.pollUpdateCounters) != null ? _a : currentPolls.pollUpdateCounters = {};
|
|---|
| 2674 | (_b = updateCounters[queryCacheKey]) != null ? _b : updateCounters[queryCacheKey] = 0;
|
|---|
| 2675 | updateCounters[queryCacheKey]++;
|
|---|
| 2676 | }
|
|---|
| 2677 | if (!Number.isFinite(lowestPollingInterval)) {
|
|---|
| 2678 | cleanupPollForKey(queryCacheKey);
|
|---|
| 2679 | return;
|
|---|
| 2680 | }
|
|---|
| 2681 | const currentPoll = currentPolls.get(queryCacheKey);
|
|---|
| 2682 | const nextPollTimestamp = Date.now() + lowestPollingInterval;
|
|---|
| 2683 | if (!currentPoll || nextPollTimestamp < currentPoll.nextPollTimestamp) {
|
|---|
| 2684 | startNextPoll({
|
|---|
| 2685 | queryCacheKey
|
|---|
| 2686 | }, api2);
|
|---|
| 2687 | }
|
|---|
| 2688 | }
|
|---|
| 2689 | function cleanupPollForKey(key) {
|
|---|
| 2690 | const existingPoll = currentPolls.get(key);
|
|---|
| 2691 | if (existingPoll == null ? void 0 : existingPoll.timeout) {
|
|---|
| 2692 | clearTimeout(existingPoll.timeout);
|
|---|
| 2693 | }
|
|---|
| 2694 | currentPolls.delete(key);
|
|---|
| 2695 | }
|
|---|
| 2696 | function clearPolls() {
|
|---|
| 2697 | for (const key of currentPolls.keys()) {
|
|---|
| 2698 | cleanupPollForKey(key);
|
|---|
| 2699 | }
|
|---|
| 2700 | }
|
|---|
| 2701 | function findLowestPollingInterval(subscribers = /* @__PURE__ */ new Map()) {
|
|---|
| 2702 | let skipPollingIfUnfocused = false;
|
|---|
| 2703 | let lowestPollingInterval = Number.POSITIVE_INFINITY;
|
|---|
| 2704 | for (const entry of subscribers.values()) {
|
|---|
| 2705 | if (!!entry.pollingInterval) {
|
|---|
| 2706 | lowestPollingInterval = Math.min(entry.pollingInterval, lowestPollingInterval);
|
|---|
| 2707 | skipPollingIfUnfocused = entry.skipPollingIfUnfocused || skipPollingIfUnfocused;
|
|---|
| 2708 | }
|
|---|
| 2709 | }
|
|---|
| 2710 | return {
|
|---|
| 2711 | lowestPollingInterval,
|
|---|
| 2712 | skipPollingIfUnfocused
|
|---|
| 2713 | };
|
|---|
| 2714 | }
|
|---|
| 2715 | return handler;
|
|---|
| 2716 | };
|
|---|
| 2717 |
|
|---|
| 2718 | // src/query/core/buildMiddleware/queryLifecycle.ts
|
|---|
| 2719 | var buildQueryLifecycleHandler = ({
|
|---|
| 2720 | api,
|
|---|
| 2721 | context,
|
|---|
| 2722 | queryThunk,
|
|---|
| 2723 | mutationThunk
|
|---|
| 2724 | }) => {
|
|---|
| 2725 | const isPendingThunk = isPending(queryThunk, mutationThunk);
|
|---|
| 2726 | const isRejectedThunk = isRejected(queryThunk, mutationThunk);
|
|---|
| 2727 | const isFullfilledThunk = isFulfilled(queryThunk, mutationThunk);
|
|---|
| 2728 | const lifecycleMap = {};
|
|---|
| 2729 | const handler = (action, mwApi) => {
|
|---|
| 2730 | var _a, _b, _c;
|
|---|
| 2731 | if (isPendingThunk(action)) {
|
|---|
| 2732 | const {
|
|---|
| 2733 | requestId,
|
|---|
| 2734 | arg: {
|
|---|
| 2735 | endpointName,
|
|---|
| 2736 | originalArgs
|
|---|
| 2737 | }
|
|---|
| 2738 | } = action.meta;
|
|---|
| 2739 | const endpointDefinition = getEndpointDefinition(context, endpointName);
|
|---|
| 2740 | const onQueryStarted = endpointDefinition == null ? void 0 : endpointDefinition.onQueryStarted;
|
|---|
| 2741 | if (onQueryStarted) {
|
|---|
| 2742 | const lifecycle = {};
|
|---|
| 2743 | const queryFulfilled = new Promise((resolve, reject) => {
|
|---|
| 2744 | lifecycle.resolve = resolve;
|
|---|
| 2745 | lifecycle.reject = reject;
|
|---|
| 2746 | });
|
|---|
| 2747 | queryFulfilled.catch(() => {
|
|---|
| 2748 | });
|
|---|
| 2749 | lifecycleMap[requestId] = lifecycle;
|
|---|
| 2750 | const selector = api.endpoints[endpointName].select(isAnyQueryDefinition(endpointDefinition) ? originalArgs : requestId);
|
|---|
| 2751 | const extra = mwApi.dispatch((_, __, extra2) => extra2);
|
|---|
| 2752 | const lifecycleApi = __spreadProps(__spreadValues({}, mwApi), {
|
|---|
| 2753 | getCacheEntry: () => selector(mwApi.getState()),
|
|---|
| 2754 | requestId,
|
|---|
| 2755 | extra,
|
|---|
| 2756 | updateCachedData: isAnyQueryDefinition(endpointDefinition) ? (updateRecipe) => mwApi.dispatch(api.util.updateQueryData(endpointName, originalArgs, updateRecipe)) : void 0,
|
|---|
| 2757 | queryFulfilled
|
|---|
| 2758 | });
|
|---|
| 2759 | onQueryStarted(originalArgs, lifecycleApi);
|
|---|
| 2760 | }
|
|---|
| 2761 | } else if (isFullfilledThunk(action)) {
|
|---|
| 2762 | const {
|
|---|
| 2763 | requestId,
|
|---|
| 2764 | baseQueryMeta
|
|---|
| 2765 | } = action.meta;
|
|---|
| 2766 | (_a = lifecycleMap[requestId]) == null ? void 0 : _a.resolve({
|
|---|
| 2767 | data: action.payload,
|
|---|
| 2768 | meta: baseQueryMeta
|
|---|
| 2769 | });
|
|---|
| 2770 | delete lifecycleMap[requestId];
|
|---|
| 2771 | } else if (isRejectedThunk(action)) {
|
|---|
| 2772 | const {
|
|---|
| 2773 | requestId,
|
|---|
| 2774 | rejectedWithValue,
|
|---|
| 2775 | baseQueryMeta
|
|---|
| 2776 | } = action.meta;
|
|---|
| 2777 | (_c = lifecycleMap[requestId]) == null ? void 0 : _c.reject({
|
|---|
| 2778 | error: (_b = action.payload) != null ? _b : action.error,
|
|---|
| 2779 | isUnhandledError: !rejectedWithValue,
|
|---|
| 2780 | meta: baseQueryMeta
|
|---|
| 2781 | });
|
|---|
| 2782 | delete lifecycleMap[requestId];
|
|---|
| 2783 | }
|
|---|
| 2784 | };
|
|---|
| 2785 | return handler;
|
|---|
| 2786 | };
|
|---|
| 2787 |
|
|---|
| 2788 | // src/query/core/buildMiddleware/windowEventHandling.ts
|
|---|
| 2789 | var buildWindowEventHandler = ({
|
|---|
| 2790 | reducerPath,
|
|---|
| 2791 | context,
|
|---|
| 2792 | api,
|
|---|
| 2793 | refetchQuery,
|
|---|
| 2794 | internalState
|
|---|
| 2795 | }) => {
|
|---|
| 2796 | const {
|
|---|
| 2797 | removeQueryResult
|
|---|
| 2798 | } = api.internalActions;
|
|---|
| 2799 | const handler = (action, mwApi) => {
|
|---|
| 2800 | if (onFocus.match(action)) {
|
|---|
| 2801 | refetchValidQueries(mwApi, "refetchOnFocus");
|
|---|
| 2802 | }
|
|---|
| 2803 | if (onOnline.match(action)) {
|
|---|
| 2804 | refetchValidQueries(mwApi, "refetchOnReconnect");
|
|---|
| 2805 | }
|
|---|
| 2806 | };
|
|---|
| 2807 | function refetchValidQueries(api2, type) {
|
|---|
| 2808 | const state = api2.getState()[reducerPath];
|
|---|
| 2809 | const queries = state.queries;
|
|---|
| 2810 | const subscriptions = internalState.currentSubscriptions;
|
|---|
| 2811 | context.batch(() => {
|
|---|
| 2812 | for (const queryCacheKey of subscriptions.keys()) {
|
|---|
| 2813 | const querySubState = queries[queryCacheKey];
|
|---|
| 2814 | const subscriptionSubState = subscriptions.get(queryCacheKey);
|
|---|
| 2815 | if (!subscriptionSubState || !querySubState) continue;
|
|---|
| 2816 | const values = [...subscriptionSubState.values()];
|
|---|
| 2817 | const shouldRefetch = values.some((sub) => sub[type] === true) || values.every((sub) => sub[type] === void 0) && state.config[type];
|
|---|
| 2818 | if (shouldRefetch) {
|
|---|
| 2819 | if (subscriptionSubState.size === 0) {
|
|---|
| 2820 | api2.dispatch(removeQueryResult({
|
|---|
| 2821 | queryCacheKey
|
|---|
| 2822 | }));
|
|---|
| 2823 | } else if (querySubState.status !== STATUS_UNINITIALIZED) {
|
|---|
| 2824 | api2.dispatch(refetchQuery(querySubState));
|
|---|
| 2825 | }
|
|---|
| 2826 | }
|
|---|
| 2827 | }
|
|---|
| 2828 | });
|
|---|
| 2829 | }
|
|---|
| 2830 | return handler;
|
|---|
| 2831 | };
|
|---|
| 2832 |
|
|---|
| 2833 | // src/query/core/buildMiddleware/index.ts
|
|---|
| 2834 | function buildMiddleware(input) {
|
|---|
| 2835 | const {
|
|---|
| 2836 | reducerPath,
|
|---|
| 2837 | queryThunk,
|
|---|
| 2838 | api,
|
|---|
| 2839 | context,
|
|---|
| 2840 | getInternalState
|
|---|
| 2841 | } = input;
|
|---|
| 2842 | const {
|
|---|
| 2843 | apiUid
|
|---|
| 2844 | } = context;
|
|---|
| 2845 | const actions2 = {
|
|---|
| 2846 | invalidateTags: createAction(`${reducerPath}/invalidateTags`)
|
|---|
| 2847 | };
|
|---|
| 2848 | const isThisApiSliceAction = (action) => action.type.startsWith(`${reducerPath}/`);
|
|---|
| 2849 | const handlerBuilders = [buildDevCheckHandler, buildCacheCollectionHandler, buildInvalidationByTagsHandler, buildPollingHandler, buildCacheLifecycleHandler, buildQueryLifecycleHandler];
|
|---|
| 2850 | const middleware = (mwApi) => {
|
|---|
| 2851 | let initialized2 = false;
|
|---|
| 2852 | const internalState = getInternalState(mwApi.dispatch);
|
|---|
| 2853 | const builderArgs = __spreadProps(__spreadValues({}, input), {
|
|---|
| 2854 | internalState,
|
|---|
| 2855 | refetchQuery,
|
|---|
| 2856 | isThisApiSliceAction,
|
|---|
| 2857 | mwApi
|
|---|
| 2858 | });
|
|---|
| 2859 | const handlers = handlerBuilders.map((build) => build(builderArgs));
|
|---|
| 2860 | const batchedActionsHandler = buildBatchedActionsHandler(builderArgs);
|
|---|
| 2861 | const windowEventsHandler = buildWindowEventHandler(builderArgs);
|
|---|
| 2862 | return (next) => {
|
|---|
| 2863 | return (action) => {
|
|---|
| 2864 | if (!isAction(action)) {
|
|---|
| 2865 | return next(action);
|
|---|
| 2866 | }
|
|---|
| 2867 | if (!initialized2) {
|
|---|
| 2868 | initialized2 = true;
|
|---|
| 2869 | mwApi.dispatch(api.internalActions.middlewareRegistered(apiUid));
|
|---|
| 2870 | }
|
|---|
| 2871 | const mwApiWithNext = __spreadProps(__spreadValues({}, mwApi), {
|
|---|
| 2872 | next
|
|---|
| 2873 | });
|
|---|
| 2874 | const stateBefore = mwApi.getState();
|
|---|
| 2875 | const [actionShouldContinue, internalProbeResult] = batchedActionsHandler(action, mwApiWithNext, stateBefore);
|
|---|
| 2876 | let res;
|
|---|
| 2877 | if (actionShouldContinue) {
|
|---|
| 2878 | res = next(action);
|
|---|
| 2879 | } else {
|
|---|
| 2880 | res = internalProbeResult;
|
|---|
| 2881 | }
|
|---|
| 2882 | if (!!mwApi.getState()[reducerPath]) {
|
|---|
| 2883 | windowEventsHandler(action, mwApiWithNext, stateBefore);
|
|---|
| 2884 | if (isThisApiSliceAction(action) || context.hasRehydrationInfo(action)) {
|
|---|
| 2885 | for (const handler of handlers) {
|
|---|
| 2886 | handler(action, mwApiWithNext, stateBefore);
|
|---|
| 2887 | }
|
|---|
| 2888 | }
|
|---|
| 2889 | }
|
|---|
| 2890 | return res;
|
|---|
| 2891 | };
|
|---|
| 2892 | };
|
|---|
| 2893 | };
|
|---|
| 2894 | return {
|
|---|
| 2895 | middleware,
|
|---|
| 2896 | actions: actions2
|
|---|
| 2897 | };
|
|---|
| 2898 | function refetchQuery(querySubState) {
|
|---|
| 2899 | return input.api.endpoints[querySubState.endpointName].initiate(querySubState.originalArgs, {
|
|---|
| 2900 | subscribe: false,
|
|---|
| 2901 | forceRefetch: true
|
|---|
| 2902 | });
|
|---|
| 2903 | }
|
|---|
| 2904 | }
|
|---|
| 2905 |
|
|---|
| 2906 | // src/query/core/module.ts
|
|---|
| 2907 | var coreModuleName = /* @__PURE__ */ Symbol();
|
|---|
| 2908 | var coreModule = ({
|
|---|
| 2909 | createSelector: createSelector2 = createSelector
|
|---|
| 2910 | } = {}) => ({
|
|---|
| 2911 | name: coreModuleName,
|
|---|
| 2912 | init(api, {
|
|---|
| 2913 | baseQuery,
|
|---|
| 2914 | tagTypes,
|
|---|
| 2915 | reducerPath,
|
|---|
| 2916 | serializeQueryArgs,
|
|---|
| 2917 | keepUnusedDataFor,
|
|---|
| 2918 | refetchOnMountOrArgChange,
|
|---|
| 2919 | refetchOnFocus,
|
|---|
| 2920 | refetchOnReconnect,
|
|---|
| 2921 | invalidationBehavior,
|
|---|
| 2922 | onSchemaFailure,
|
|---|
| 2923 | catchSchemaFailure,
|
|---|
| 2924 | skipSchemaValidation
|
|---|
| 2925 | }, context) {
|
|---|
| 2926 | enablePatches();
|
|---|
| 2927 | assertCast(serializeQueryArgs);
|
|---|
| 2928 | const assertTagType = (tag) => {
|
|---|
| 2929 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|---|
| 2930 | if (!tagTypes.includes(tag.type)) {
|
|---|
| 2931 | console.error(`Tag type '${tag.type}' was used, but not specified in \`tagTypes\`!`);
|
|---|
| 2932 | }
|
|---|
| 2933 | }
|
|---|
| 2934 | return tag;
|
|---|
| 2935 | };
|
|---|
| 2936 | Object.assign(api, {
|
|---|
| 2937 | reducerPath,
|
|---|
| 2938 | endpoints: {},
|
|---|
| 2939 | internalActions: {
|
|---|
| 2940 | onOnline,
|
|---|
| 2941 | onOffline,
|
|---|
| 2942 | onFocus,
|
|---|
| 2943 | onFocusLost
|
|---|
| 2944 | },
|
|---|
| 2945 | util: {}
|
|---|
| 2946 | });
|
|---|
| 2947 | const selectors = buildSelectors({
|
|---|
| 2948 | serializeQueryArgs,
|
|---|
| 2949 | reducerPath,
|
|---|
| 2950 | createSelector: createSelector2
|
|---|
| 2951 | });
|
|---|
| 2952 | const {
|
|---|
| 2953 | selectInvalidatedBy,
|
|---|
| 2954 | selectCachedArgsForQuery,
|
|---|
| 2955 | buildQuerySelector,
|
|---|
| 2956 | buildInfiniteQuerySelector,
|
|---|
| 2957 | buildMutationSelector
|
|---|
| 2958 | } = selectors;
|
|---|
| 2959 | safeAssign(api.util, {
|
|---|
| 2960 | selectInvalidatedBy,
|
|---|
| 2961 | selectCachedArgsForQuery
|
|---|
| 2962 | });
|
|---|
| 2963 | const {
|
|---|
| 2964 | queryThunk,
|
|---|
| 2965 | infiniteQueryThunk,
|
|---|
| 2966 | mutationThunk,
|
|---|
| 2967 | patchQueryData,
|
|---|
| 2968 | updateQueryData,
|
|---|
| 2969 | upsertQueryData,
|
|---|
| 2970 | prefetch,
|
|---|
| 2971 | buildMatchThunkActions
|
|---|
| 2972 | } = buildThunks({
|
|---|
| 2973 | baseQuery,
|
|---|
| 2974 | reducerPath,
|
|---|
| 2975 | context,
|
|---|
| 2976 | api,
|
|---|
| 2977 | serializeQueryArgs,
|
|---|
| 2978 | assertTagType,
|
|---|
| 2979 | selectors,
|
|---|
| 2980 | onSchemaFailure,
|
|---|
| 2981 | catchSchemaFailure,
|
|---|
| 2982 | skipSchemaValidation
|
|---|
| 2983 | });
|
|---|
| 2984 | const {
|
|---|
| 2985 | reducer,
|
|---|
| 2986 | actions: sliceActions
|
|---|
| 2987 | } = buildSlice({
|
|---|
| 2988 | context,
|
|---|
| 2989 | queryThunk,
|
|---|
| 2990 | infiniteQueryThunk,
|
|---|
| 2991 | mutationThunk,
|
|---|
| 2992 | serializeQueryArgs,
|
|---|
| 2993 | reducerPath,
|
|---|
| 2994 | assertTagType,
|
|---|
| 2995 | config: {
|
|---|
| 2996 | refetchOnFocus,
|
|---|
| 2997 | refetchOnReconnect,
|
|---|
| 2998 | refetchOnMountOrArgChange,
|
|---|
| 2999 | keepUnusedDataFor,
|
|---|
| 3000 | reducerPath,
|
|---|
| 3001 | invalidationBehavior
|
|---|
| 3002 | }
|
|---|
| 3003 | });
|
|---|
| 3004 | safeAssign(api.util, {
|
|---|
| 3005 | patchQueryData,
|
|---|
| 3006 | updateQueryData,
|
|---|
| 3007 | upsertQueryData,
|
|---|
| 3008 | prefetch,
|
|---|
| 3009 | resetApiState: sliceActions.resetApiState,
|
|---|
| 3010 | upsertQueryEntries: sliceActions.cacheEntriesUpserted
|
|---|
| 3011 | });
|
|---|
| 3012 | safeAssign(api.internalActions, sliceActions);
|
|---|
| 3013 | const internalStateMap = /* @__PURE__ */ new WeakMap();
|
|---|
| 3014 | const getInternalState = (dispatch) => {
|
|---|
| 3015 | const state = getOrInsertComputed(internalStateMap, dispatch, () => ({
|
|---|
| 3016 | currentSubscriptions: /* @__PURE__ */ new Map(),
|
|---|
| 3017 | currentPolls: /* @__PURE__ */ new Map(),
|
|---|
| 3018 | runningQueries: /* @__PURE__ */ new Map(),
|
|---|
| 3019 | runningMutations: /* @__PURE__ */ new Map()
|
|---|
| 3020 | }));
|
|---|
| 3021 | return state;
|
|---|
| 3022 | };
|
|---|
| 3023 | const {
|
|---|
| 3024 | buildInitiateQuery,
|
|---|
| 3025 | buildInitiateInfiniteQuery,
|
|---|
| 3026 | buildInitiateMutation,
|
|---|
| 3027 | getRunningMutationThunk,
|
|---|
| 3028 | getRunningMutationsThunk,
|
|---|
| 3029 | getRunningQueriesThunk,
|
|---|
| 3030 | getRunningQueryThunk
|
|---|
| 3031 | } = buildInitiate({
|
|---|
| 3032 | queryThunk,
|
|---|
| 3033 | mutationThunk,
|
|---|
| 3034 | infiniteQueryThunk,
|
|---|
| 3035 | api,
|
|---|
| 3036 | serializeQueryArgs,
|
|---|
| 3037 | context,
|
|---|
| 3038 | getInternalState
|
|---|
| 3039 | });
|
|---|
| 3040 | safeAssign(api.util, {
|
|---|
| 3041 | getRunningMutationThunk,
|
|---|
| 3042 | getRunningMutationsThunk,
|
|---|
| 3043 | getRunningQueryThunk,
|
|---|
| 3044 | getRunningQueriesThunk
|
|---|
| 3045 | });
|
|---|
| 3046 | const {
|
|---|
| 3047 | middleware,
|
|---|
| 3048 | actions: middlewareActions
|
|---|
| 3049 | } = buildMiddleware({
|
|---|
| 3050 | reducerPath,
|
|---|
| 3051 | context,
|
|---|
| 3052 | queryThunk,
|
|---|
| 3053 | mutationThunk,
|
|---|
| 3054 | infiniteQueryThunk,
|
|---|
| 3055 | api,
|
|---|
| 3056 | assertTagType,
|
|---|
| 3057 | selectors,
|
|---|
| 3058 | getRunningQueryThunk,
|
|---|
| 3059 | getInternalState
|
|---|
| 3060 | });
|
|---|
| 3061 | safeAssign(api.util, middlewareActions);
|
|---|
| 3062 | safeAssign(api, {
|
|---|
| 3063 | reducer,
|
|---|
| 3064 | middleware
|
|---|
| 3065 | });
|
|---|
| 3066 | return {
|
|---|
| 3067 | name: coreModuleName,
|
|---|
| 3068 | injectEndpoint(endpointName, definition) {
|
|---|
| 3069 | var _a, _b;
|
|---|
| 3070 | const anyApi = api;
|
|---|
| 3071 | const endpoint = (_b = (_a = anyApi.endpoints)[endpointName]) != null ? _b : _a[endpointName] = {};
|
|---|
| 3072 | if (isQueryDefinition(definition)) {
|
|---|
| 3073 | safeAssign(endpoint, {
|
|---|
| 3074 | name: endpointName,
|
|---|
| 3075 | select: buildQuerySelector(endpointName, definition),
|
|---|
| 3076 | initiate: buildInitiateQuery(endpointName, definition)
|
|---|
| 3077 | }, buildMatchThunkActions(queryThunk, endpointName));
|
|---|
| 3078 | }
|
|---|
| 3079 | if (isMutationDefinition(definition)) {
|
|---|
| 3080 | safeAssign(endpoint, {
|
|---|
| 3081 | name: endpointName,
|
|---|
| 3082 | select: buildMutationSelector(),
|
|---|
| 3083 | initiate: buildInitiateMutation(endpointName)
|
|---|
| 3084 | }, buildMatchThunkActions(mutationThunk, endpointName));
|
|---|
| 3085 | }
|
|---|
| 3086 | if (isInfiniteQueryDefinition(definition)) {
|
|---|
| 3087 | safeAssign(endpoint, {
|
|---|
| 3088 | name: endpointName,
|
|---|
| 3089 | select: buildInfiniteQuerySelector(endpointName, definition),
|
|---|
| 3090 | initiate: buildInitiateInfiniteQuery(endpointName, definition)
|
|---|
| 3091 | }, buildMatchThunkActions(queryThunk, endpointName));
|
|---|
| 3092 | }
|
|---|
| 3093 | }
|
|---|
| 3094 | };
|
|---|
| 3095 | }
|
|---|
| 3096 | });
|
|---|
| 3097 |
|
|---|
| 3098 | // src/query/core/index.ts
|
|---|
| 3099 | var createApi = /* @__PURE__ */ buildCreateApi(coreModule());
|
|---|
| 3100 | export {
|
|---|
| 3101 | NamedSchemaError,
|
|---|
| 3102 | QueryStatus,
|
|---|
| 3103 | _NEVER,
|
|---|
| 3104 | buildCreateApi,
|
|---|
| 3105 | copyWithStructuralSharing,
|
|---|
| 3106 | coreModule,
|
|---|
| 3107 | coreModuleName,
|
|---|
| 3108 | createApi,
|
|---|
| 3109 | defaultSerializeQueryArgs,
|
|---|
| 3110 | fakeBaseQuery,
|
|---|
| 3111 | fetchBaseQuery,
|
|---|
| 3112 | retry,
|
|---|
| 3113 | setupListeners,
|
|---|
| 3114 | skipToken
|
|---|
| 3115 | };
|
|---|
| 3116 | //# sourceMappingURL=rtk-query.legacy-esm.js.map |
|---|