1 | var __generator = (this && this.__generator) || function (thisArg, body) {
|
2 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
3 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
4 | function verb(n) { return function (v) { return step([n, v]); }; }
|
5 | function step(op) {
|
6 | if (f) throw new TypeError("Generator is already executing.");
|
7 | while (_) try {
|
8 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
9 | if (y = 0, t) op = [op[0] & 2, t.value];
|
10 | switch (op[0]) {
|
11 | case 0: case 1: t = op; break;
|
12 | case 4: _.label++; return { value: op[1], done: false };
|
13 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
14 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
15 | default:
|
16 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
17 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
18 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
19 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
20 | if (t[2]) _.ops.pop();
|
21 | _.trys.pop(); continue;
|
22 | }
|
23 | op = body.call(thisArg, _);
|
24 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
25 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
26 | }
|
27 | };
|
28 | var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
29 | for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
30 | to[j] = from[i];
|
31 | return to;
|
32 | };
|
33 | var __defProp = Object.defineProperty;
|
34 | var __defProps = Object.defineProperties;
|
35 | var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
36 | var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
37 | var __hasOwnProp = Object.prototype.hasOwnProperty;
|
38 | var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
39 | var __defNormalProp = function (obj, key, value) { return key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value: value }) : obj[key] = value; };
|
40 | var __spreadValues = function (a, b) {
|
41 | for (var prop in b || (b = {}))
|
42 | if (__hasOwnProp.call(b, prop))
|
43 | __defNormalProp(a, prop, b[prop]);
|
44 | if (__getOwnPropSymbols)
|
45 | for (var _j = 0, _k = __getOwnPropSymbols(b); _j < _k.length; _j++) {
|
46 | var prop = _k[_j];
|
47 | if (__propIsEnum.call(b, prop))
|
48 | __defNormalProp(a, prop, b[prop]);
|
49 | }
|
50 | return a;
|
51 | };
|
52 | var __spreadProps = function (a, b) { return __defProps(a, __getOwnPropDescs(b)); };
|
53 | var __objRest = function (source, exclude) {
|
54 | var target = {};
|
55 | for (var prop in source)
|
56 | if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
57 | target[prop] = source[prop];
|
58 | if (source != null && __getOwnPropSymbols)
|
59 | for (var _j = 0, _k = __getOwnPropSymbols(source); _j < _k.length; _j++) {
|
60 | var prop = _k[_j];
|
61 | if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
62 | target[prop] = source[prop];
|
63 | }
|
64 | return target;
|
65 | };
|
66 | var __async = function (__this, __arguments, generator) {
|
67 | return new Promise(function (resolve, reject) {
|
68 | var fulfilled = function (value) {
|
69 | try {
|
70 | step(generator.next(value));
|
71 | }
|
72 | catch (e) {
|
73 | reject(e);
|
74 | }
|
75 | };
|
76 | var rejected = function (value) {
|
77 | try {
|
78 | step(generator.throw(value));
|
79 | }
|
80 | catch (e) {
|
81 | reject(e);
|
82 | }
|
83 | };
|
84 | var step = function (x) { return x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); };
|
85 | step((generator = generator.apply(__this, __arguments)).next());
|
86 | });
|
87 | };
|
88 |
|
89 | var QueryStatus;
|
90 | (function (QueryStatus2) {
|
91 | QueryStatus2["uninitialized"] = "uninitialized";
|
92 | QueryStatus2["pending"] = "pending";
|
93 | QueryStatus2["fulfilled"] = "fulfilled";
|
94 | QueryStatus2["rejected"] = "rejected";
|
95 | })(QueryStatus || (QueryStatus = {}));
|
96 | function getRequestStatusFlags(status) {
|
97 | return {
|
98 | status: status,
|
99 | isUninitialized: status === QueryStatus.uninitialized,
|
100 | isLoading: status === QueryStatus.pending,
|
101 | isSuccess: status === QueryStatus.fulfilled,
|
102 | isError: status === QueryStatus.rejected
|
103 | };
|
104 | }
|
105 |
|
106 | function isAbsoluteUrl(url) {
|
107 | return new RegExp("(^|:)//").test(url);
|
108 | }
|
109 |
|
110 | var withoutTrailingSlash = function (url) { return url.replace(/\/$/, ""); };
|
111 | var withoutLeadingSlash = function (url) { return url.replace(/^\//, ""); };
|
112 | function joinUrls(base, url) {
|
113 | if (!base) {
|
114 | return url;
|
115 | }
|
116 | if (!url) {
|
117 | return base;
|
118 | }
|
119 | if (isAbsoluteUrl(url)) {
|
120 | return url;
|
121 | }
|
122 | var delimiter = base.endsWith("/") || !url.startsWith("?") ? "/" : "";
|
123 | base = withoutTrailingSlash(base);
|
124 | url = withoutLeadingSlash(url);
|
125 | return "" + base + delimiter + url;
|
126 | }
|
127 |
|
128 | var flatten = function (arr) { return [].concat.apply([], arr); };
|
129 |
|
130 | function isOnline() {
|
131 | return typeof navigator === "undefined" ? true : navigator.onLine === void 0 ? true : navigator.onLine;
|
132 | }
|
133 |
|
134 | function isDocumentVisible() {
|
135 | if (typeof document === "undefined") {
|
136 | return true;
|
137 | }
|
138 | return document.visibilityState !== "hidden";
|
139 | }
|
140 |
|
141 | import { isPlainObject as _iPO } from "@reduxjs/toolkit";
|
142 | var isPlainObject = _iPO;
|
143 | function copyWithStructuralSharing(oldObj, newObj) {
|
144 | if (oldObj === newObj || !(isPlainObject(oldObj) && isPlainObject(newObj) || Array.isArray(oldObj) && Array.isArray(newObj))) {
|
145 | return newObj;
|
146 | }
|
147 | var newKeys = Object.keys(newObj);
|
148 | var oldKeys = Object.keys(oldObj);
|
149 | var isSameObject = newKeys.length === oldKeys.length;
|
150 | var mergeObj = Array.isArray(newObj) ? [] : {};
|
151 | for (var _j = 0, newKeys_1 = newKeys; _j < newKeys_1.length; _j++) {
|
152 | var key = newKeys_1[_j];
|
153 | mergeObj[key] = copyWithStructuralSharing(oldObj[key], newObj[key]);
|
154 | if (isSameObject)
|
155 | isSameObject = oldObj[key] === mergeObj[key];
|
156 | }
|
157 | return isSameObject ? oldObj : mergeObj;
|
158 | }
|
159 |
|
160 | import { isPlainObject as isPlainObject2 } from "@reduxjs/toolkit";
|
161 | var defaultFetchFn = function () {
|
162 | var args = [];
|
163 | for (var _j = 0; _j < arguments.length; _j++) {
|
164 | args[_j] = arguments[_j];
|
165 | }
|
166 | return fetch.apply(void 0, args);
|
167 | };
|
168 | var defaultValidateStatus = function (response) { return response.status >= 200 && response.status <= 299; };
|
169 | var defaultIsJsonContentType = function (headers) { return /ion\/(vnd\.api\+)?json/.test(headers.get("content-type") || ""); };
|
170 | function stripUndefined(obj) {
|
171 | if (!isPlainObject2(obj)) {
|
172 | return obj;
|
173 | }
|
174 | var copy = __spreadValues({}, obj);
|
175 | for (var _j = 0, _k = Object.entries(copy); _j < _k.length; _j++) {
|
176 | var _l = _k[_j], k = _l[0], v = _l[1];
|
177 | if (v === void 0)
|
178 | delete copy[k];
|
179 | }
|
180 | return copy;
|
181 | }
|
182 | function fetchBaseQuery(_a) {
|
183 | var _this = this;
|
184 | if (_a === void 0) { _a = {}; }
|
185 | var _b = _a, baseUrl = _b.baseUrl, _j = _b.prepareHeaders, prepareHeaders = _j === void 0 ? function (x) { return x; } : _j, _k = _b.fetchFn, fetchFn = _k === void 0 ? defaultFetchFn : _k, paramsSerializer = _b.paramsSerializer, _l = _b.isJsonContentType, isJsonContentType = _l === void 0 ? defaultIsJsonContentType : _l, _m = _b.jsonContentType, jsonContentType = _m === void 0 ? "application/json" : _m, jsonReplacer = _b.jsonReplacer, defaultTimeout = _b.timeout, globalValidateStatus = _b.validateStatus, baseFetchOptions = __objRest(_b, [
|
186 | "baseUrl",
|
187 | "prepareHeaders",
|
188 | "fetchFn",
|
189 | "paramsSerializer",
|
190 | "isJsonContentType",
|
191 | "jsonContentType",
|
192 | "jsonReplacer",
|
193 | "timeout",
|
194 | "validateStatus"
|
195 | ]);
|
196 | if (typeof fetch === "undefined" && fetchFn === defaultFetchFn) {
|
197 | console.warn("Warning: `fetch` is not available. Please supply a custom `fetchFn` property to use `fetchBaseQuery` on SSR environments.");
|
198 | }
|
199 | return function (arg, api) { return __async(_this, null, function () {
|
200 | var signal, getState, extra, endpoint, forced, type, meta, _a2, url, _j, headers, _k, params, _l, responseHandler, _m, validateStatus, _o, timeout, rest, config, _p, isJsonifiable, divider, query, request, requestClone, response, timedOut, timeoutId, e_1, responseClone, resultData, responseText, handleResponseError_1, e_2;
|
201 | return __generator(this, function (_q) {
|
202 | switch (_q.label) {
|
203 | case 0:
|
204 | signal = api.signal, getState = api.getState, extra = api.extra, endpoint = api.endpoint, forced = api.forced, type = api.type;
|
205 | _a2 = typeof arg == "string" ? { url: arg } : arg, url = _a2.url, _j = _a2.headers, headers = _j === void 0 ? new Headers(baseFetchOptions.headers) : _j, _k = _a2.params, params = _k === void 0 ? void 0 : _k, _l = _a2.responseHandler, responseHandler = _l === void 0 ? "json" : _l, _m = _a2.validateStatus, validateStatus = _m === void 0 ? globalValidateStatus != null ? globalValidateStatus : defaultValidateStatus : _m, _o = _a2.timeout, timeout = _o === void 0 ? defaultTimeout : _o, rest = __objRest(_a2, [
|
206 | "url",
|
207 | "headers",
|
208 | "params",
|
209 | "responseHandler",
|
210 | "validateStatus",
|
211 | "timeout"
|
212 | ]);
|
213 | config = __spreadValues(__spreadProps(__spreadValues({}, baseFetchOptions), {
|
214 | signal: signal
|
215 | }), rest);
|
216 | headers = new Headers(stripUndefined(headers));
|
217 | _p = config;
|
218 | return [4 , prepareHeaders(headers, {
|
219 | getState: getState,
|
220 | extra: extra,
|
221 | endpoint: endpoint,
|
222 | forced: forced,
|
223 | type: type
|
224 | })];
|
225 | case 1:
|
226 | _p.headers = (_q.sent()) || headers;
|
227 | isJsonifiable = function (body) { return typeof body === "object" && (isPlainObject2(body) || Array.isArray(body) || typeof body.toJSON === "function"); };
|
228 | if (!config.headers.has("content-type") && isJsonifiable(config.body)) {
|
229 | config.headers.set("content-type", jsonContentType);
|
230 | }
|
231 | if (isJsonifiable(config.body) && isJsonContentType(config.headers)) {
|
232 | config.body = JSON.stringify(config.body, jsonReplacer);
|
233 | }
|
234 | if (params) {
|
235 | divider = ~url.indexOf("?") ? "&" : "?";
|
236 | query = paramsSerializer ? paramsSerializer(params) : new URLSearchParams(stripUndefined(params));
|
237 | url += divider + query;
|
238 | }
|
239 | url = joinUrls(baseUrl, url);
|
240 | request = new Request(url, config);
|
241 | requestClone = request.clone();
|
242 | meta = { request: requestClone };
|
243 | timedOut = false, timeoutId = timeout && setTimeout(function () {
|
244 | timedOut = true;
|
245 | api.abort();
|
246 | }, timeout);
|
247 | _q.label = 2;
|
248 | case 2:
|
249 | _q.trys.push([2, 4, 5, 6]);
|
250 | return [4 , fetchFn(request)];
|
251 | case 3:
|
252 | response = _q.sent();
|
253 | return [3 , 6];
|
254 | case 4:
|
255 | e_1 = _q.sent();
|
256 | return [2 , {
|
257 | error: {
|
258 | status: timedOut ? "TIMEOUT_ERROR" : "FETCH_ERROR",
|
259 | error: String(e_1)
|
260 | },
|
261 | meta: meta
|
262 | }];
|
263 | case 5:
|
264 | if (timeoutId)
|
265 | clearTimeout(timeoutId);
|
266 | return [7 ];
|
267 | case 6:
|
268 | responseClone = response.clone();
|
269 | meta.response = responseClone;
|
270 | responseText = "";
|
271 | _q.label = 7;
|
272 | case 7:
|
273 | _q.trys.push([7, 9, , 10]);
|
274 | return [4 , Promise.all([
|
275 | handleResponse(response, responseHandler).then(function (r) { return resultData = r; }, function (e) { return handleResponseError_1 = e; }),
|
276 | responseClone.text().then(function (r) { return responseText = r; }, function () {
|
277 | })
|
278 | ])];
|
279 | case 8:
|
280 | _q.sent();
|
281 | if (handleResponseError_1)
|
282 | throw handleResponseError_1;
|
283 | return [3 , 10];
|
284 | case 9:
|
285 | e_2 = _q.sent();
|
286 | return [2 , {
|
287 | error: {
|
288 | status: "PARSING_ERROR",
|
289 | originalStatus: response.status,
|
290 | data: responseText,
|
291 | error: String(e_2)
|
292 | },
|
293 | meta: meta
|
294 | }];
|
295 | case 10: return [2 , validateStatus(response, resultData) ? {
|
296 | data: resultData,
|
297 | meta: meta
|
298 | } : {
|
299 | error: {
|
300 | status: response.status,
|
301 | data: resultData
|
302 | },
|
303 | meta: meta
|
304 | }];
|
305 | }
|
306 | });
|
307 | }); };
|
308 | function handleResponse(response, responseHandler) {
|
309 | return __async(this, null, function () {
|
310 | var text;
|
311 | return __generator(this, function (_j) {
|
312 | switch (_j.label) {
|
313 | case 0:
|
314 | if (typeof responseHandler === "function") {
|
315 | return [2 , responseHandler(response)];
|
316 | }
|
317 | if (responseHandler === "content-type") {
|
318 | responseHandler = isJsonContentType(response.headers) ? "json" : "text";
|
319 | }
|
320 | if (!(responseHandler === "json")) return [3 , 2];
|
321 | return [4 , response.text()];
|
322 | case 1:
|
323 | text = _j.sent();
|
324 | return [2 , text.length ? JSON.parse(text) : null];
|
325 | case 2: return [2 , response.text()];
|
326 | }
|
327 | });
|
328 | });
|
329 | }
|
330 | }
|
331 |
|
332 | var HandledError = (function () {
|
333 | function HandledError(value, meta) {
|
334 | if (meta === void 0) { meta = void 0; }
|
335 | this.value = value;
|
336 | this.meta = meta;
|
337 | }
|
338 | return HandledError;
|
339 | }());
|
340 |
|
341 | function defaultBackoff(attempt, maxRetries) {
|
342 | if (attempt === void 0) { attempt = 0; }
|
343 | if (maxRetries === void 0) { maxRetries = 5; }
|
344 | return __async(this, null, function () {
|
345 | var attempts, timeout;
|
346 | return __generator(this, function (_j) {
|
347 | switch (_j.label) {
|
348 | case 0:
|
349 | attempts = Math.min(attempt, maxRetries);
|
350 | timeout = ~~((Math.random() + 0.4) * (300 << attempts));
|
351 | return [4 , new Promise(function (resolve) { return setTimeout(function (res) { return resolve(res); }, timeout); })];
|
352 | case 1:
|
353 | _j.sent();
|
354 | return [2 ];
|
355 | }
|
356 | });
|
357 | });
|
358 | }
|
359 | function fail(e) {
|
360 | throw Object.assign(new HandledError({ error: e }), {
|
361 | throwImmediately: true
|
362 | });
|
363 | }
|
364 | var EMPTY_OPTIONS = {};
|
365 | var retryWithBackoff = function (baseQuery, defaultOptions) { return function (args, api, extraOptions) { return __async(void 0, null, function () {
|
366 | var possibleMaxRetries, maxRetries, defaultRetryCondition, options, retry2, result, e_3;
|
367 | return __generator(this, function (_j) {
|
368 | switch (_j.label) {
|
369 | case 0:
|
370 | possibleMaxRetries = [
|
371 | 5,
|
372 | (defaultOptions || EMPTY_OPTIONS).maxRetries,
|
373 | (extraOptions || EMPTY_OPTIONS).maxRetries
|
374 | ].filter(function (x) { return x !== void 0; });
|
375 | maxRetries = possibleMaxRetries.slice(-1)[0];
|
376 | defaultRetryCondition = function (_, __, _j) {
|
377 | var attempt = _j.attempt;
|
378 | return attempt <= maxRetries;
|
379 | };
|
380 | options = __spreadValues(__spreadValues({
|
381 | maxRetries: maxRetries,
|
382 | backoff: defaultBackoff,
|
383 | retryCondition: defaultRetryCondition
|
384 | }, defaultOptions), extraOptions);
|
385 | retry2 = 0;
|
386 | _j.label = 1;
|
387 | case 1:
|
388 | if (!true) return [3 , 7];
|
389 | _j.label = 2;
|
390 | case 2:
|
391 | _j.trys.push([2, 4, , 6]);
|
392 | return [4 , baseQuery(args, api, extraOptions)];
|
393 | case 3:
|
394 | result = _j.sent();
|
395 | if (result.error) {
|
396 | throw new HandledError(result);
|
397 | }
|
398 | return [2 , result];
|
399 | case 4:
|
400 | e_3 = _j.sent();
|
401 | retry2++;
|
402 | if (e_3.throwImmediately) {
|
403 | if (e_3 instanceof HandledError) {
|
404 | return [2 , e_3.value];
|
405 | }
|
406 | throw e_3;
|
407 | }
|
408 | if (e_3 instanceof HandledError && !options.retryCondition(e_3.value.error, args, {
|
409 | attempt: retry2,
|
410 | baseQueryApi: api,
|
411 | extraOptions: extraOptions
|
412 | })) {
|
413 | return [2 , e_3.value];
|
414 | }
|
415 | return [4 , options.backoff(retry2, options.maxRetries)];
|
416 | case 5:
|
417 | _j.sent();
|
418 | return [3 , 6];
|
419 | case 6: return [3 , 1];
|
420 | case 7: return [2 ];
|
421 | }
|
422 | });
|
423 | }); }; };
|
424 | var retry = Object.assign(retryWithBackoff, { fail: fail });
|
425 |
|
426 | import { createAction } from "@reduxjs/toolkit";
|
427 | var onFocus = createAction("__rtkq/focused");
|
428 | var onFocusLost = createAction("__rtkq/unfocused");
|
429 | var onOnline = createAction("__rtkq/online");
|
430 | var onOffline = createAction("__rtkq/offline");
|
431 | var initialized = false;
|
432 | function setupListeners(dispatch, customHandler) {
|
433 | function defaultHandler() {
|
434 | var handleFocus = function () { return dispatch(onFocus()); };
|
435 | var handleFocusLost = function () { return dispatch(onFocusLost()); };
|
436 | var handleOnline = function () { return dispatch(onOnline()); };
|
437 | var handleOffline = function () { return dispatch(onOffline()); };
|
438 | var handleVisibilityChange = function () {
|
439 | if (window.document.visibilityState === "visible") {
|
440 | handleFocus();
|
441 | }
|
442 | else {
|
443 | handleFocusLost();
|
444 | }
|
445 | };
|
446 | if (!initialized) {
|
447 | if (typeof window !== "undefined" && window.addEventListener) {
|
448 | window.addEventListener("visibilitychange", handleVisibilityChange, false);
|
449 | window.addEventListener("focus", handleFocus, false);
|
450 | window.addEventListener("online", handleOnline, false);
|
451 | window.addEventListener("offline", handleOffline, false);
|
452 | initialized = true;
|
453 | }
|
454 | }
|
455 | var unsubscribe = function () {
|
456 | window.removeEventListener("focus", handleFocus);
|
457 | window.removeEventListener("visibilitychange", handleVisibilityChange);
|
458 | window.removeEventListener("online", handleOnline);
|
459 | window.removeEventListener("offline", handleOffline);
|
460 | initialized = false;
|
461 | };
|
462 | return unsubscribe;
|
463 | }
|
464 | return customHandler ? customHandler(dispatch, { onFocus: onFocus, onFocusLost: onFocusLost, onOffline: onOffline, onOnline: onOnline }) : defaultHandler();
|
465 | }
|
466 |
|
467 | import { createNextState as createNextState2, createSelector } from "@reduxjs/toolkit";
|
468 |
|
469 | var DefinitionType;
|
470 | (function (DefinitionType2) {
|
471 | DefinitionType2["query"] = "query";
|
472 | DefinitionType2["mutation"] = "mutation";
|
473 | })(DefinitionType || (DefinitionType = {}));
|
474 | function isQueryDefinition(e) {
|
475 | return e.type === DefinitionType.query;
|
476 | }
|
477 | function isMutationDefinition(e) {
|
478 | return e.type === DefinitionType.mutation;
|
479 | }
|
480 | function calculateProvidedBy(description, result, error, queryArg, meta, assertTagTypes) {
|
481 | if (isFunction(description)) {
|
482 | return description(result, error, queryArg, meta).map(expandTagDescription).map(assertTagTypes);
|
483 | }
|
484 | if (Array.isArray(description)) {
|
485 | return description.map(expandTagDescription).map(assertTagTypes);
|
486 | }
|
487 | return [];
|
488 | }
|
489 | function isFunction(t) {
|
490 | return typeof t === "function";
|
491 | }
|
492 | function expandTagDescription(description) {
|
493 | return typeof description === "string" ? { type: description } : description;
|
494 | }
|
495 |
|
496 | import { combineReducers, createAction as createAction2, createSlice, isAnyOf, isFulfilled as isFulfilled2, isRejectedWithValue as isRejectedWithValue2, createNextState, prepareAutoBatched } from "@reduxjs/toolkit";
|
497 |
|
498 | function isNotNullish(v) {
|
499 | return v != null;
|
500 | }
|
501 |
|
502 | var forceQueryFnSymbol = Symbol("forceQueryFn");
|
503 | var isUpsertQuery = function (arg) { return typeof arg[forceQueryFnSymbol] === "function"; };
|
504 | function buildInitiate(_j) {
|
505 | var serializeQueryArgs = _j.serializeQueryArgs, queryThunk = _j.queryThunk, mutationThunk = _j.mutationThunk, api = _j.api, context = _j.context;
|
506 | var runningQueries = new Map();
|
507 | var runningMutations = new Map();
|
508 | var _k = api.internalActions, unsubscribeQueryResult = _k.unsubscribeQueryResult, removeMutationResult = _k.removeMutationResult, updateSubscriptionOptions = _k.updateSubscriptionOptions;
|
509 | return {
|
510 | buildInitiateQuery: buildInitiateQuery,
|
511 | buildInitiateMutation: buildInitiateMutation,
|
512 | getRunningQueryThunk: getRunningQueryThunk,
|
513 | getRunningMutationThunk: getRunningMutationThunk,
|
514 | getRunningQueriesThunk: getRunningQueriesThunk,
|
515 | getRunningMutationsThunk: getRunningMutationsThunk,
|
516 | getRunningOperationPromises: getRunningOperationPromises,
|
517 | removalWarning: removalWarning
|
518 | };
|
519 | function removalWarning() {
|
520 | throw new Error("This method had to be removed due to a conceptual bug in RTK.\n Please see https://github.com/reduxjs/redux-toolkit/pull/2481 for details.\n See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for new guidance on SSR.");
|
521 | }
|
522 | function getRunningOperationPromises() {
|
523 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
524 | removalWarning();
|
525 | }
|
526 | else {
|
527 | var extract = function (v) { return Array.from(v.values()).flatMap(function (queriesForStore) { return queriesForStore ? Object.values(queriesForStore) : []; }); };
|
528 | return __spreadArray(__spreadArray([], extract(runningQueries)), extract(runningMutations)).filter(isNotNullish);
|
529 | }
|
530 | }
|
531 | function getRunningQueryThunk(endpointName, queryArgs) {
|
532 | return function (dispatch) {
|
533 | var _a;
|
534 | var endpointDefinition = context.endpointDefinitions[endpointName];
|
535 | var queryCacheKey = serializeQueryArgs({
|
536 | queryArgs: queryArgs,
|
537 | endpointDefinition: endpointDefinition,
|
538 | endpointName: endpointName
|
539 | });
|
540 | return (_a = runningQueries.get(dispatch)) == null ? void 0 : _a[queryCacheKey];
|
541 | };
|
542 | }
|
543 | function getRunningMutationThunk(_endpointName, fixedCacheKeyOrRequestId) {
|
544 | return function (dispatch) {
|
545 | var _a;
|
546 | return (_a = runningMutations.get(dispatch)) == null ? void 0 : _a[fixedCacheKeyOrRequestId];
|
547 | };
|
548 | }
|
549 | function getRunningQueriesThunk() {
|
550 | return function (dispatch) { return Object.values(runningQueries.get(dispatch) || {}).filter(isNotNullish); };
|
551 | }
|
552 | function getRunningMutationsThunk() {
|
553 | return function (dispatch) { return Object.values(runningMutations.get(dispatch) || {}).filter(isNotNullish); };
|
554 | }
|
555 | function middlewareWarning(dispatch) {
|
556 | if (process.env.NODE_ENV !== "production") {
|
557 | if (middlewareWarning.triggered)
|
558 | return;
|
559 | var registered = dispatch(api.internalActions.internal_probeSubscription({
|
560 | queryCacheKey: "DOES_NOT_EXIST",
|
561 | requestId: "DUMMY_REQUEST_ID"
|
562 | }));
|
563 | middlewareWarning.triggered = true;
|
564 | if (typeof registered !== "boolean") {
|
565 | throw new Error("Warning: Middleware for RTK-Query API at reducerPath \"" + api.reducerPath + "\" has not been added to the store.\nYou must add the middleware for RTK-Query to function correctly!");
|
566 | }
|
567 | }
|
568 | }
|
569 | function buildInitiateQuery(endpointName, endpointDefinition) {
|
570 | var queryAction = function (arg, _j) {
|
571 | var _k = _j === void 0 ? {} : _j, _l = _k.subscribe, subscribe = _l === void 0 ? true : _l, forceRefetch = _k.forceRefetch, subscriptionOptions = _k.subscriptionOptions, _m = forceQueryFnSymbol, forceQueryFn = _k[_m];
|
572 | return function (dispatch, getState) {
|
573 | var _j;
|
574 | var _a;
|
575 | var queryCacheKey = serializeQueryArgs({
|
576 | queryArgs: arg,
|
577 | endpointDefinition: endpointDefinition,
|
578 | endpointName: endpointName
|
579 | });
|
580 | var thunk = queryThunk((_j = {
|
581 | type: "query",
|
582 | subscribe: subscribe,
|
583 | forceRefetch: forceRefetch,
|
584 | subscriptionOptions: subscriptionOptions,
|
585 | endpointName: endpointName,
|
586 | originalArgs: arg,
|
587 | queryCacheKey: queryCacheKey
|
588 | },
|
589 | _j[forceQueryFnSymbol] = forceQueryFn,
|
590 | _j));
|
591 | var selector = api.endpoints[endpointName].select(arg);
|
592 | var thunkResult = dispatch(thunk);
|
593 | var stateAfter = selector(getState());
|
594 | middlewareWarning(dispatch);
|
595 | var requestId = thunkResult.requestId, abort = thunkResult.abort;
|
596 | var skippedSynchronously = stateAfter.requestId !== requestId;
|
597 | var runningQuery = (_a = runningQueries.get(dispatch)) == null ? void 0 : _a[queryCacheKey];
|
598 | var selectFromState = function () { return selector(getState()); };
|
599 | var statePromise = Object.assign(forceQueryFn ? thunkResult.then(selectFromState) : skippedSynchronously && !runningQuery ? Promise.resolve(stateAfter) : Promise.all([runningQuery, thunkResult]).then(selectFromState), {
|
600 | arg: arg,
|
601 | requestId: requestId,
|
602 | subscriptionOptions: subscriptionOptions,
|
603 | queryCacheKey: queryCacheKey,
|
604 | abort: abort,
|
605 | unwrap: function () {
|
606 | return __async(this, null, function () {
|
607 | var result;
|
608 | return __generator(this, function (_j) {
|
609 | switch (_j.label) {
|
610 | case 0: return [4 , statePromise];
|
611 | case 1:
|
612 | result = _j.sent();
|
613 | if (result.isError) {
|
614 | throw result.error;
|
615 | }
|
616 | return [2 , result.data];
|
617 | }
|
618 | });
|
619 | });
|
620 | },
|
621 | refetch: function () { return dispatch(queryAction(arg, { subscribe: false, forceRefetch: true })); },
|
622 | unsubscribe: function () {
|
623 | if (subscribe)
|
624 | dispatch(unsubscribeQueryResult({
|
625 | queryCacheKey: queryCacheKey,
|
626 | requestId: requestId
|
627 | }));
|
628 | },
|
629 | updateSubscriptionOptions: function (options) {
|
630 | statePromise.subscriptionOptions = options;
|
631 | dispatch(updateSubscriptionOptions({
|
632 | endpointName: endpointName,
|
633 | requestId: requestId,
|
634 | queryCacheKey: queryCacheKey,
|
635 | options: options
|
636 | }));
|
637 | }
|
638 | });
|
639 | if (!runningQuery && !skippedSynchronously && !forceQueryFn) {
|
640 | var running_1 = runningQueries.get(dispatch) || {};
|
641 | running_1[queryCacheKey] = statePromise;
|
642 | runningQueries.set(dispatch, running_1);
|
643 | statePromise.then(function () {
|
644 | delete running_1[queryCacheKey];
|
645 | if (!Object.keys(running_1).length) {
|
646 | runningQueries.delete(dispatch);
|
647 | }
|
648 | });
|
649 | }
|
650 | return statePromise;
|
651 | };
|
652 | };
|
653 | return queryAction;
|
654 | }
|
655 | function buildInitiateMutation(endpointName) {
|
656 | return function (arg, _j) {
|
657 | var _k = _j === void 0 ? {} : _j, _l = _k.track, track = _l === void 0 ? true : _l, fixedCacheKey = _k.fixedCacheKey;
|
658 | return function (dispatch, getState) {
|
659 | var thunk = mutationThunk({
|
660 | type: "mutation",
|
661 | endpointName: endpointName,
|
662 | originalArgs: arg,
|
663 | track: track,
|
664 | fixedCacheKey: fixedCacheKey
|
665 | });
|
666 | var thunkResult = dispatch(thunk);
|
667 | middlewareWarning(dispatch);
|
668 | var requestId = thunkResult.requestId, abort = thunkResult.abort, unwrap = thunkResult.unwrap;
|
669 | var returnValuePromise = thunkResult.unwrap().then(function (data) { return ({ data: data }); }).catch(function (error) { return ({ error: error }); });
|
670 | var reset = function () {
|
671 | dispatch(removeMutationResult({ requestId: requestId, fixedCacheKey: fixedCacheKey }));
|
672 | };
|
673 | var ret = Object.assign(returnValuePromise, {
|
674 | arg: thunkResult.arg,
|
675 | requestId: requestId,
|
676 | abort: abort,
|
677 | unwrap: unwrap,
|
678 | unsubscribe: reset,
|
679 | reset: reset
|
680 | });
|
681 | var running = runningMutations.get(dispatch) || {};
|
682 | runningMutations.set(dispatch, running);
|
683 | running[requestId] = ret;
|
684 | ret.then(function () {
|
685 | delete running[requestId];
|
686 | if (!Object.keys(running).length) {
|
687 | runningMutations.delete(dispatch);
|
688 | }
|
689 | });
|
690 | if (fixedCacheKey) {
|
691 | running[fixedCacheKey] = ret;
|
692 | ret.then(function () {
|
693 | if (running[fixedCacheKey] === ret) {
|
694 | delete running[fixedCacheKey];
|
695 | if (!Object.keys(running).length) {
|
696 | runningMutations.delete(dispatch);
|
697 | }
|
698 | }
|
699 | });
|
700 | }
|
701 | return ret;
|
702 | };
|
703 | };
|
704 | }
|
705 | }
|
706 |
|
707 | import { isAllOf, isFulfilled, isPending, isRejected, isRejectedWithValue } from "@reduxjs/toolkit";
|
708 | import { isDraftable, produceWithPatches } from "immer";
|
709 | import { createAsyncThunk, SHOULD_AUTOBATCH } from "@reduxjs/toolkit";
|
710 | function defaultTransformResponse(baseQueryReturnValue) {
|
711 | return baseQueryReturnValue;
|
712 | }
|
713 | function buildThunks(_j) {
|
714 | var _this = this;
|
715 | var reducerPath = _j.reducerPath, baseQuery = _j.baseQuery, endpointDefinitions = _j.context.endpointDefinitions, serializeQueryArgs = _j.serializeQueryArgs, api = _j.api;
|
716 | var patchQueryData = function (endpointName, args, patches) { return function (dispatch) {
|
717 | var endpointDefinition = endpointDefinitions[endpointName];
|
718 | dispatch(api.internalActions.queryResultPatched({
|
719 | queryCacheKey: serializeQueryArgs({
|
720 | queryArgs: args,
|
721 | endpointDefinition: endpointDefinition,
|
722 | endpointName: endpointName
|
723 | }),
|
724 | patches: patches
|
725 | }));
|
726 | }; };
|
727 | var updateQueryData = function (endpointName, args, updateRecipe) { return function (dispatch, getState) {
|
728 | var _j, _k;
|
729 | var currentState = api.endpoints[endpointName].select(args)(getState());
|
730 | var ret = {
|
731 | patches: [],
|
732 | inversePatches: [],
|
733 | undo: function () { return dispatch(api.util.patchQueryData(endpointName, args, ret.inversePatches)); }
|
734 | };
|
735 | if (currentState.status === QueryStatus.uninitialized) {
|
736 | return ret;
|
737 | }
|
738 | if ("data" in currentState) {
|
739 | if (isDraftable(currentState.data)) {
|
740 | var _l = produceWithPatches(currentState.data, updateRecipe), patches = _l[1], inversePatches = _l[2];
|
741 | (_j = ret.patches).push.apply(_j, patches);
|
742 | (_k = ret.inversePatches).push.apply(_k, inversePatches);
|
743 | }
|
744 | else {
|
745 | var value = updateRecipe(currentState.data);
|
746 | ret.patches.push({ op: "replace", path: [], value: value });
|
747 | ret.inversePatches.push({
|
748 | op: "replace",
|
749 | path: [],
|
750 | value: currentState.data
|
751 | });
|
752 | }
|
753 | }
|
754 | dispatch(api.util.patchQueryData(endpointName, args, ret.patches));
|
755 | return ret;
|
756 | }; };
|
757 | var upsertQueryData = function (endpointName, args, value) { return function (dispatch) {
|
758 | var _j;
|
759 | return dispatch(api.endpoints[endpointName].initiate(args, (_j = {
|
760 | subscribe: false,
|
761 | forceRefetch: true
|
762 | },
|
763 | _j[forceQueryFnSymbol] = function () { return ({
|
764 | data: value
|
765 | }); },
|
766 | _j)));
|
767 | }; };
|
768 | var executeEndpoint = function (_0, _1) { return __async(_this, [_0, _1], function (arg, _j) {
|
769 | var endpointDefinition, transformResponse, result, baseQueryApi_1, forceQueryFn, what, err, _k, _l, key, _m, error_1, catchedError, transformErrorResponse, _o, e_4;
|
770 | var _p, _q;
|
771 | var signal = _j.signal, abort = _j.abort, rejectWithValue = _j.rejectWithValue, fulfillWithValue = _j.fulfillWithValue, dispatch = _j.dispatch, getState = _j.getState, extra = _j.extra;
|
772 | return __generator(this, function (_r) {
|
773 | switch (_r.label) {
|
774 | case 0:
|
775 | endpointDefinition = endpointDefinitions[arg.endpointName];
|
776 | _r.label = 1;
|
777 | case 1:
|
778 | _r.trys.push([1, 8, , 13]);
|
779 | transformResponse = defaultTransformResponse;
|
780 | result = void 0;
|
781 | baseQueryApi_1 = {
|
782 | signal: signal,
|
783 | abort: abort,
|
784 | dispatch: dispatch,
|
785 | getState: getState,
|
786 | extra: extra,
|
787 | endpoint: arg.endpointName,
|
788 | type: arg.type,
|
789 | forced: arg.type === "query" ? isForcedQuery(arg, getState()) : void 0
|
790 | };
|
791 | forceQueryFn = arg.type === "query" ? arg[forceQueryFnSymbol] : void 0;
|
792 | if (!forceQueryFn) return [3 , 2];
|
793 | result = forceQueryFn();
|
794 | return [3 , 6];
|
795 | case 2:
|
796 | if (!endpointDefinition.query) return [3 , 4];
|
797 | return [4 , baseQuery(endpointDefinition.query(arg.originalArgs), baseQueryApi_1, endpointDefinition.extraOptions)];
|
798 | case 3:
|
799 | result = _r.sent();
|
800 | if (endpointDefinition.transformResponse) {
|
801 | transformResponse = endpointDefinition.transformResponse;
|
802 | }
|
803 | return [3 , 6];
|
804 | case 4: return [4 , endpointDefinition.queryFn(arg.originalArgs, baseQueryApi_1, endpointDefinition.extraOptions, function (arg2) { return baseQuery(arg2, baseQueryApi_1, endpointDefinition.extraOptions); })];
|
805 | case 5:
|
806 | result = _r.sent();
|
807 | _r.label = 6;
|
808 | case 6:
|
809 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
810 | what = endpointDefinition.query ? "`baseQuery`" : "`queryFn`";
|
811 | err = void 0;
|
812 | if (!result) {
|
813 | err = what + " did not return anything.";
|
814 | }
|
815 | else if (typeof result !== "object") {
|
816 | err = what + " did not return an object.";
|
817 | }
|
818 | else if (result.error && result.data) {
|
819 | err = what + " returned an object containing both `error` and `result`.";
|
820 | }
|
821 | else if (result.error === void 0 && result.data === void 0) {
|
822 | err = what + " returned an object containing neither a valid `error` and `result`. At least one of them should not be `undefined`";
|
823 | }
|
824 | else {
|
825 | for (_k = 0, _l = Object.keys(result); _k < _l.length; _k++) {
|
826 | key = _l[_k];
|
827 | if (key !== "error" && key !== "data" && key !== "meta") {
|
828 | err = "The object returned by " + what + " has the unknown property " + key + ".";
|
829 | break;
|
830 | }
|
831 | }
|
832 | }
|
833 | if (err) {
|
834 | console.error("Error encountered handling the endpoint " + arg.endpointName + ".\n " + err + "\n It needs to return an object with either the shape `{ data: <value> }` or `{ error: <value> }` that may contain an optional `meta` property.\n Object returned was:", result);
|
835 | }
|
836 | }
|
837 | if (result.error)
|
838 | throw new HandledError(result.error, result.meta);
|
839 | _m = fulfillWithValue;
|
840 | return [4 , transformResponse(result.data, result.meta, arg.originalArgs)];
|
841 | case 7: return [2 , _m.apply(void 0, [_r.sent(), (_p = {
|
842 | fulfilledTimeStamp: Date.now(),
|
843 | baseQueryMeta: result.meta
|
844 | },
|
845 | _p[SHOULD_AUTOBATCH] = true,
|
846 | _p)])];
|
847 | case 8:
|
848 | error_1 = _r.sent();
|
849 | catchedError = error_1;
|
850 | if (!(catchedError instanceof HandledError)) return [3 , 12];
|
851 | transformErrorResponse = defaultTransformResponse;
|
852 | if (endpointDefinition.query && endpointDefinition.transformErrorResponse) {
|
853 | transformErrorResponse = endpointDefinition.transformErrorResponse;
|
854 | }
|
855 | _r.label = 9;
|
856 | case 9:
|
857 | _r.trys.push([9, 11, , 12]);
|
858 | _o = rejectWithValue;
|
859 | return [4 , transformErrorResponse(catchedError.value, catchedError.meta, arg.originalArgs)];
|
860 | case 10: return [2 , _o.apply(void 0, [_r.sent(), (_q = { baseQueryMeta: catchedError.meta }, _q[SHOULD_AUTOBATCH] = true, _q)])];
|
861 | case 11:
|
862 | e_4 = _r.sent();
|
863 | catchedError = e_4;
|
864 | return [3 , 12];
|
865 | case 12:
|
866 | if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
|
867 | console.error("An unhandled error occurred processing a request for the endpoint \"" + arg.endpointName + "\".\nIn the case of an unhandled error, no tags will be \"provided\" or \"invalidated\".", catchedError);
|
868 | }
|
869 | else {
|
870 | console.error(catchedError);
|
871 | }
|
872 | throw catchedError;
|
873 | case 13: return [2 ];
|
874 | }
|
875 | });
|
876 | }); };
|
877 | function isForcedQuery(arg, state) {
|
878 | var _a, _b, _c, _d;
|
879 | var requestState = (_b = (_a = state[reducerPath]) == null ? void 0 : _a.queries) == null ? void 0 : _b[arg.queryCacheKey];
|
880 | var baseFetchOnMountOrArgChange = (_c = state[reducerPath]) == null ? void 0 : _c.config.refetchOnMountOrArgChange;
|
881 | var fulfilledVal = requestState == null ? void 0 : requestState.fulfilledTimeStamp;
|
882 | var refetchVal = (_d = arg.forceRefetch) != null ? _d : arg.subscribe && baseFetchOnMountOrArgChange;
|
883 | if (refetchVal) {
|
884 | return refetchVal === true || (Number(new Date()) - Number(fulfilledVal)) / 1e3 >= refetchVal;
|
885 | }
|
886 | return false;
|
887 | }
|
888 | var queryThunk = createAsyncThunk(reducerPath + "/executeQuery", executeEndpoint, {
|
889 | getPendingMeta: function () {
|
890 | var _j;
|
891 | return _j = { startedTimeStamp: Date.now() }, _j[SHOULD_AUTOBATCH] = true, _j;
|
892 | },
|
893 | condition: function (queryThunkArgs, _j) {
|
894 | var getState = _j.getState;
|
895 | var _a, _b, _c;
|
896 | var state = getState();
|
897 | var requestState = (_b = (_a = state[reducerPath]) == null ? void 0 : _a.queries) == null ? void 0 : _b[queryThunkArgs.queryCacheKey];
|
898 | var fulfilledVal = requestState == null ? void 0 : requestState.fulfilledTimeStamp;
|
899 | var currentArg = queryThunkArgs.originalArgs;
|
900 | var previousArg = requestState == null ? void 0 : requestState.originalArgs;
|
901 | var endpointDefinition = endpointDefinitions[queryThunkArgs.endpointName];
|
902 | if (isUpsertQuery(queryThunkArgs)) {
|
903 | return true;
|
904 | }
|
905 | if ((requestState == null ? void 0 : requestState.status) === "pending") {
|
906 | return false;
|
907 | }
|
908 | if (isForcedQuery(queryThunkArgs, state)) {
|
909 | return true;
|
910 | }
|
911 | if (isQueryDefinition(endpointDefinition) && ((_c = endpointDefinition == null ? void 0 : endpointDefinition.forceRefetch) == null ? void 0 : _c.call(endpointDefinition, {
|
912 | currentArg: currentArg,
|
913 | previousArg: previousArg,
|
914 | endpointState: requestState,
|
915 | state: state
|
916 | }))) {
|
917 | return true;
|
918 | }
|
919 | if (fulfilledVal) {
|
920 | return false;
|
921 | }
|
922 | return true;
|
923 | },
|
924 | dispatchConditionRejection: true
|
925 | });
|
926 | var mutationThunk = createAsyncThunk(reducerPath + "/executeMutation", executeEndpoint, {
|
927 | getPendingMeta: function () {
|
928 | var _j;
|
929 | return _j = { startedTimeStamp: Date.now() }, _j[SHOULD_AUTOBATCH] = true, _j;
|
930 | }
|
931 | });
|
932 | var hasTheForce = function (options) { return "force" in options; };
|
933 | var hasMaxAge = function (options) { return "ifOlderThan" in options; };
|
934 | var prefetch = function (endpointName, arg, options) { return function (dispatch, getState) {
|
935 | var force = hasTheForce(options) && options.force;
|
936 | var maxAge = hasMaxAge(options) && options.ifOlderThan;
|
937 | var queryAction = function (force2) {
|
938 | if (force2 === void 0) { force2 = true; }
|
939 | return api.endpoints[endpointName].initiate(arg, { forceRefetch: force2 });
|
940 | };
|
941 | var latestStateValue = api.endpoints[endpointName].select(arg)(getState());
|
942 | if (force) {
|
943 | dispatch(queryAction());
|
944 | }
|
945 | else if (maxAge) {
|
946 | var lastFulfilledTs = latestStateValue == null ? void 0 : latestStateValue.fulfilledTimeStamp;
|
947 | if (!lastFulfilledTs) {
|
948 | dispatch(queryAction());
|
949 | return;
|
950 | }
|
951 | var shouldRetrigger = (Number(new Date()) - Number(new Date(lastFulfilledTs))) / 1e3 >= maxAge;
|
952 | if (shouldRetrigger) {
|
953 | dispatch(queryAction());
|
954 | }
|
955 | }
|
956 | else {
|
957 | dispatch(queryAction(false));
|
958 | }
|
959 | }; };
|
960 | function matchesEndpoint(endpointName) {
|
961 | return function (action) {
|
962 | var _a, _b;
|
963 | return ((_b = (_a = action == null ? void 0 : action.meta) == null ? void 0 : _a.arg) == null ? void 0 : _b.endpointName) === endpointName;
|
964 | };
|
965 | }
|
966 | function buildMatchThunkActions(thunk, endpointName) {
|
967 | return {
|
968 | matchPending: isAllOf(isPending(thunk), matchesEndpoint(endpointName)),
|
969 | matchFulfilled: isAllOf(isFulfilled(thunk), matchesEndpoint(endpointName)),
|
970 | matchRejected: isAllOf(isRejected(thunk), matchesEndpoint(endpointName))
|
971 | };
|
972 | }
|
973 | return {
|
974 | queryThunk: queryThunk,
|
975 | mutationThunk: mutationThunk,
|
976 | prefetch: prefetch,
|
977 | updateQueryData: updateQueryData,
|
978 | upsertQueryData: upsertQueryData,
|
979 | patchQueryData: patchQueryData,
|
980 | buildMatchThunkActions: buildMatchThunkActions
|
981 | };
|
982 | }
|
983 | function calculateProvidedByThunk(action, type, endpointDefinitions, assertTagType) {
|
984 | 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);
|
985 | }
|
986 |
|
987 | import { applyPatches } from "immer";
|
988 | function updateQuerySubstateIfExists(state, queryCacheKey, update) {
|
989 | var substate = state[queryCacheKey];
|
990 | if (substate) {
|
991 | update(substate);
|
992 | }
|
993 | }
|
994 | function getMutationCacheKey(id) {
|
995 | var _a;
|
996 | return (_a = "arg" in id ? id.arg.fixedCacheKey : id.fixedCacheKey) != null ? _a : id.requestId;
|
997 | }
|
998 | function updateMutationSubstateIfExists(state, id, update) {
|
999 | var substate = state[getMutationCacheKey(id)];
|
1000 | if (substate) {
|
1001 | update(substate);
|
1002 | }
|
1003 | }
|
1004 | var initialState = {};
|
1005 | function buildSlice(_j) {
|
1006 | var reducerPath = _j.reducerPath, queryThunk = _j.queryThunk, mutationThunk = _j.mutationThunk, _k = _j.context, definitions = _k.endpointDefinitions, apiUid = _k.apiUid, extractRehydrationInfo = _k.extractRehydrationInfo, hasRehydrationInfo = _k.hasRehydrationInfo, assertTagType = _j.assertTagType, config = _j.config;
|
1007 | var resetApiState = createAction2(reducerPath + "/resetApiState");
|
1008 | var querySlice = createSlice({
|
1009 | name: reducerPath + "/queries",
|
1010 | initialState: initialState,
|
1011 | reducers: {
|
1012 | removeQueryResult: {
|
1013 | reducer: function (draft, _j) {
|
1014 | var queryCacheKey = _j.payload.queryCacheKey;
|
1015 | delete draft[queryCacheKey];
|
1016 | },
|
1017 | prepare: prepareAutoBatched()
|
1018 | },
|
1019 | queryResultPatched: function (draft, _j) {
|
1020 | var _k = _j.payload, queryCacheKey = _k.queryCacheKey, patches = _k.patches;
|
1021 | updateQuerySubstateIfExists(draft, queryCacheKey, function (substate) {
|
1022 | substate.data = applyPatches(substate.data, patches.concat());
|
1023 | });
|
1024 | }
|
1025 | },
|
1026 | extraReducers: function (builder) {
|
1027 | builder.addCase(queryThunk.pending, function (draft, _j) {
|
1028 | var meta = _j.meta, arg = _j.meta.arg;
|
1029 | var _a, _b;
|
1030 | var upserting = isUpsertQuery(arg);
|
1031 | if (arg.subscribe || upserting) {
|
1032 | (_b = draft[_a = arg.queryCacheKey]) != null ? _b : draft[_a] = {
|
1033 | status: QueryStatus.uninitialized,
|
1034 | endpointName: arg.endpointName
|
1035 | };
|
1036 | }
|
1037 | updateQuerySubstateIfExists(draft, arg.queryCacheKey, function (substate) {
|
1038 | substate.status = QueryStatus.pending;
|
1039 | substate.requestId = upserting && substate.requestId ? substate.requestId : meta.requestId;
|
1040 | if (arg.originalArgs !== void 0) {
|
1041 | substate.originalArgs = arg.originalArgs;
|
1042 | }
|
1043 | substate.startedTimeStamp = meta.startedTimeStamp;
|
1044 | });
|
1045 | }).addCase(queryThunk.fulfilled, function (draft, _j) {
|
1046 | var meta = _j.meta, payload = _j.payload;
|
1047 | updateQuerySubstateIfExists(draft, meta.arg.queryCacheKey, function (substate) {
|
1048 | var _a;
|
1049 | if (substate.requestId !== meta.requestId && !isUpsertQuery(meta.arg))
|
1050 | return;
|
1051 | var merge = definitions[meta.arg.endpointName].merge;
|
1052 | substate.status = QueryStatus.fulfilled;
|
1053 | if (merge) {
|
1054 | if (substate.data !== void 0) {
|
1055 | var fulfilledTimeStamp_1 = meta.fulfilledTimeStamp, arg_1 = meta.arg, baseQueryMeta_1 = meta.baseQueryMeta, requestId_1 = meta.requestId;
|
1056 | var newData = createNextState(substate.data, function (draftSubstateData) {
|
1057 | return merge(draftSubstateData, payload, {
|
1058 | arg: arg_1.originalArgs,
|
1059 | baseQueryMeta: baseQueryMeta_1,
|
1060 | fulfilledTimeStamp: fulfilledTimeStamp_1,
|
1061 | requestId: requestId_1
|
1062 | });
|
1063 | });
|
1064 | substate.data = newData;
|
1065 | }
|
1066 | else {
|
1067 | substate.data = payload;
|
1068 | }
|
1069 | }
|
1070 | else {
|
1071 | substate.data = ((_a = definitions[meta.arg.endpointName].structuralSharing) != null ? _a : true) ? copyWithStructuralSharing(substate.data, payload) : payload;
|
1072 | }
|
1073 | delete substate.error;
|
1074 | substate.fulfilledTimeStamp = meta.fulfilledTimeStamp;
|
1075 | });
|
1076 | }).addCase(queryThunk.rejected, function (draft, _j) {
|
1077 | var _k = _j.meta, condition = _k.condition, arg = _k.arg, requestId = _k.requestId, error = _j.error, payload = _j.payload;
|
1078 | updateQuerySubstateIfExists(draft, arg.queryCacheKey, function (substate) {
|
1079 | if (condition) {
|
1080 | }
|
1081 | else {
|
1082 | if (substate.requestId !== requestId)
|
1083 | return;
|
1084 | substate.status = QueryStatus.rejected;
|
1085 | substate.error = payload != null ? payload : error;
|
1086 | }
|
1087 | });
|
1088 | }).addMatcher(hasRehydrationInfo, function (draft, action) {
|
1089 | var queries = extractRehydrationInfo(action).queries;
|
1090 | for (var _j = 0, _k = Object.entries(queries); _j < _k.length; _j++) {
|
1091 | var _l = _k[_j], key = _l[0], entry = _l[1];
|
1092 | if ((entry == null ? void 0 : entry.status) === QueryStatus.fulfilled || (entry == null ? void 0 : entry.status) === QueryStatus.rejected) {
|
1093 | draft[key] = entry;
|
1094 | }
|
1095 | }
|
1096 | });
|
1097 | }
|
1098 | });
|
1099 | var mutationSlice = createSlice({
|
1100 | name: reducerPath + "/mutations",
|
1101 | initialState: initialState,
|
1102 | reducers: {
|
1103 | removeMutationResult: {
|
1104 | reducer: function (draft, _j) {
|
1105 | var payload = _j.payload;
|
1106 | var cacheKey = getMutationCacheKey(payload);
|
1107 | if (cacheKey in draft) {
|
1108 | delete draft[cacheKey];
|
1109 | }
|
1110 | },
|
1111 | prepare: prepareAutoBatched()
|
1112 | }
|
1113 | },
|
1114 | extraReducers: function (builder) {
|
1115 | builder.addCase(mutationThunk.pending, function (draft, _j) {
|
1116 | var meta = _j.meta, _k = _j.meta, requestId = _k.requestId, arg = _k.arg, startedTimeStamp = _k.startedTimeStamp;
|
1117 | if (!arg.track)
|
1118 | return;
|
1119 | draft[getMutationCacheKey(meta)] = {
|
1120 | requestId: requestId,
|
1121 | status: QueryStatus.pending,
|
1122 | endpointName: arg.endpointName,
|
1123 | startedTimeStamp: startedTimeStamp
|
1124 | };
|
1125 | }).addCase(mutationThunk.fulfilled, function (draft, _j) {
|
1126 | var payload = _j.payload, meta = _j.meta;
|
1127 | if (!meta.arg.track)
|
1128 | return;
|
1129 | updateMutationSubstateIfExists(draft, meta, function (substate) {
|
1130 | if (substate.requestId !== meta.requestId)
|
1131 | return;
|
1132 | substate.status = QueryStatus.fulfilled;
|
1133 | substate.data = payload;
|
1134 | substate.fulfilledTimeStamp = meta.fulfilledTimeStamp;
|
1135 | });
|
1136 | }).addCase(mutationThunk.rejected, function (draft, _j) {
|
1137 | var payload = _j.payload, error = _j.error, meta = _j.meta;
|
1138 | if (!meta.arg.track)
|
1139 | return;
|
1140 | updateMutationSubstateIfExists(draft, meta, function (substate) {
|
1141 | if (substate.requestId !== meta.requestId)
|
1142 | return;
|
1143 | substate.status = QueryStatus.rejected;
|
1144 | substate.error = payload != null ? payload : error;
|
1145 | });
|
1146 | }).addMatcher(hasRehydrationInfo, function (draft, action) {
|
1147 | var mutations = extractRehydrationInfo(action).mutations;
|
1148 | for (var _j = 0, _k = Object.entries(mutations); _j < _k.length; _j++) {
|
1149 | var _l = _k[_j], key = _l[0], entry = _l[1];
|
1150 | if (((entry == null ? void 0 : entry.status) === QueryStatus.fulfilled || (entry == null ? void 0 : entry.status) === QueryStatus.rejected) && key !== (entry == null ? void 0 : entry.requestId)) {
|
1151 | draft[key] = entry;
|
1152 | }
|
1153 | }
|
1154 | });
|
1155 | }
|
1156 | });
|
1157 | var invalidationSlice = createSlice({
|
1158 | name: reducerPath + "/invalidation",
|
1159 | initialState: initialState,
|
1160 | reducers: {},
|
1161 | extraReducers: function (builder) {
|
1162 | builder.addCase(querySlice.actions.removeQueryResult, function (draft, _j) {
|
1163 | var queryCacheKey = _j.payload.queryCacheKey;
|
1164 | for (var _k = 0, _l = Object.values(draft); _k < _l.length; _k++) {
|
1165 | var tagTypeSubscriptions = _l[_k];
|
1166 | for (var _m = 0, _o = Object.values(tagTypeSubscriptions); _m < _o.length; _m++) {
|
1167 | var idSubscriptions = _o[_m];
|
1168 | var foundAt = idSubscriptions.indexOf(queryCacheKey);
|
1169 | if (foundAt !== -1) {
|
1170 | idSubscriptions.splice(foundAt, 1);
|
1171 | }
|
1172 | }
|
1173 | }
|
1174 | }).addMatcher(hasRehydrationInfo, function (draft, action) {
|
1175 | var _a, _b, _c, _d;
|
1176 | var provided = extractRehydrationInfo(action).provided;
|
1177 | for (var _j = 0, _k = Object.entries(provided); _j < _k.length; _j++) {
|
1178 | var _l = _k[_j], type = _l[0], incomingTags = _l[1];
|
1179 | for (var _m = 0, _o = Object.entries(incomingTags); _m < _o.length; _m++) {
|
1180 | var _p = _o[_m], id = _p[0], cacheKeys = _p[1];
|
1181 | var subscribedQueries = (_d = (_b = (_a = draft[type]) != null ? _a : draft[type] = {})[_c = id || "__internal_without_id"]) != null ? _d : _b[_c] = [];
|
1182 | for (var _q = 0, cacheKeys_1 = cacheKeys; _q < cacheKeys_1.length; _q++) {
|
1183 | var queryCacheKey = cacheKeys_1[_q];
|
1184 | var alreadySubscribed = subscribedQueries.includes(queryCacheKey);
|
1185 | if (!alreadySubscribed) {
|
1186 | subscribedQueries.push(queryCacheKey);
|
1187 | }
|
1188 | }
|
1189 | }
|
1190 | }
|
1191 | }).addMatcher(isAnyOf(isFulfilled2(queryThunk), isRejectedWithValue2(queryThunk)), function (draft, action) {
|
1192 | var _a, _b, _c, _d;
|
1193 | var providedTags = calculateProvidedByThunk(action, "providesTags", definitions, assertTagType);
|
1194 | var queryCacheKey = action.meta.arg.queryCacheKey;
|
1195 | for (var _j = 0, _k = Object.values(draft); _j < _k.length; _j++) {
|
1196 | var tagTypeSubscriptions = _k[_j];
|
1197 | for (var _l = 0, _m = Object.values(tagTypeSubscriptions); _l < _m.length; _l++) {
|
1198 | var idSubscriptions = _m[_l];
|
1199 | var foundAt = idSubscriptions.indexOf(queryCacheKey);
|
1200 | if (foundAt !== -1) {
|
1201 | idSubscriptions.splice(foundAt, 1);
|
1202 | }
|
1203 | }
|
1204 | }
|
1205 | for (var _o = 0, providedTags_1 = providedTags; _o < providedTags_1.length; _o++) {
|
1206 | var _p = providedTags_1[_o], type = _p.type, id = _p.id;
|
1207 | var subscribedQueries = (_d = (_b = (_a = draft[type]) != null ? _a : draft[type] = {})[_c = id || "__internal_without_id"]) != null ? _d : _b[_c] = [];
|
1208 | var alreadySubscribed = subscribedQueries.includes(queryCacheKey);
|
1209 | if (!alreadySubscribed) {
|
1210 | subscribedQueries.push(queryCacheKey);
|
1211 | }
|
1212 | }
|
1213 | });
|
1214 | }
|
1215 | });
|
1216 | var subscriptionSlice = createSlice({
|
1217 | name: reducerPath + "/subscriptions",
|
1218 | initialState: initialState,
|
1219 | reducers: {
|
1220 | updateSubscriptionOptions: function (d, a) {
|
1221 | },
|
1222 | unsubscribeQueryResult: function (d, a) {
|
1223 | },
|
1224 | internal_probeSubscription: function (d, a) {
|
1225 | }
|
1226 | }
|
1227 | });
|
1228 | var internalSubscriptionsSlice = createSlice({
|
1229 | name: reducerPath + "/internalSubscriptions",
|
1230 | initialState: initialState,
|
1231 | reducers: {
|
1232 | subscriptionsUpdated: function (state, action) {
|
1233 | return applyPatches(state, action.payload);
|
1234 | }
|
1235 | }
|
1236 | });
|
1237 | var configSlice = createSlice({
|
1238 | name: reducerPath + "/config",
|
1239 | initialState: __spreadValues({
|
1240 | online: isOnline(),
|
1241 | focused: isDocumentVisible(),
|
1242 | middlewareRegistered: false
|
1243 | }, config),
|
1244 | reducers: {
|
1245 | middlewareRegistered: function (state, _j) {
|
1246 | var payload = _j.payload;
|
1247 | state.middlewareRegistered = state.middlewareRegistered === "conflict" || apiUid !== payload ? "conflict" : true;
|
1248 | }
|
1249 | },
|
1250 | extraReducers: function (builder) {
|
1251 | builder.addCase(onOnline, function (state) {
|
1252 | state.online = true;
|
1253 | }).addCase(onOffline, function (state) {
|
1254 | state.online = false;
|
1255 | }).addCase(onFocus, function (state) {
|
1256 | state.focused = true;
|
1257 | }).addCase(onFocusLost, function (state) {
|
1258 | state.focused = false;
|
1259 | }).addMatcher(hasRehydrationInfo, function (draft) { return __spreadValues({}, draft); });
|
1260 | }
|
1261 | });
|
1262 | var combinedReducer = combineReducers({
|
1263 | queries: querySlice.reducer,
|
1264 | mutations: mutationSlice.reducer,
|
1265 | provided: invalidationSlice.reducer,
|
1266 | subscriptions: internalSubscriptionsSlice.reducer,
|
1267 | config: configSlice.reducer
|
1268 | });
|
1269 | var reducer = function (state, action) { return combinedReducer(resetApiState.match(action) ? void 0 : state, action); };
|
1270 | var actions = __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, configSlice.actions), querySlice.actions), subscriptionSlice.actions), internalSubscriptionsSlice.actions), mutationSlice.actions), {
|
1271 | unsubscribeMutationResult: mutationSlice.actions.removeMutationResult,
|
1272 | resetApiState: resetApiState
|
1273 | });
|
1274 | return { reducer: reducer, actions: actions };
|
1275 | }
|
1276 |
|
1277 | var skipToken = Symbol.for("RTKQ/skipToken");
|
1278 | var skipSelector = skipToken;
|
1279 | var initialSubState = {
|
1280 | status: QueryStatus.uninitialized
|
1281 | };
|
1282 | var defaultQuerySubState = createNextState2(initialSubState, function () {
|
1283 | });
|
1284 | var defaultMutationSubState = createNextState2(initialSubState, function () {
|
1285 | });
|
1286 | function buildSelectors(_j) {
|
1287 | var serializeQueryArgs = _j.serializeQueryArgs, reducerPath = _j.reducerPath;
|
1288 | var selectSkippedQuery = function (state) { return defaultQuerySubState; };
|
1289 | var selectSkippedMutation = function (state) { return defaultMutationSubState; };
|
1290 | return { buildQuerySelector: buildQuerySelector, buildMutationSelector: buildMutationSelector, selectInvalidatedBy: selectInvalidatedBy };
|
1291 | function withRequestFlags(substate) {
|
1292 | return __spreadValues(__spreadValues({}, substate), getRequestStatusFlags(substate.status));
|
1293 | }
|
1294 | function selectInternalState(rootState) {
|
1295 | var state = rootState[reducerPath];
|
1296 | if (process.env.NODE_ENV !== "production") {
|
1297 | if (!state) {
|
1298 | if (selectInternalState.triggered)
|
1299 | return state;
|
1300 | selectInternalState.triggered = true;
|
1301 | console.error("Error: No data found at `state." + reducerPath + "`. Did you forget to add the reducer to the store?");
|
1302 | }
|
1303 | }
|
1304 | return state;
|
1305 | }
|
1306 | function buildQuerySelector(endpointName, endpointDefinition) {
|
1307 | return function (queryArgs) {
|
1308 | var serializedArgs = serializeQueryArgs({
|
1309 | queryArgs: queryArgs,
|
1310 | endpointDefinition: endpointDefinition,
|
1311 | endpointName: endpointName
|
1312 | });
|
1313 | var selectQuerySubstate = function (state) {
|
1314 | var _a, _b, _c;
|
1315 | return (_c = (_b = (_a = selectInternalState(state)) == null ? void 0 : _a.queries) == null ? void 0 : _b[serializedArgs]) != null ? _c : defaultQuerySubState;
|
1316 | };
|
1317 | var finalSelectQuerySubState = queryArgs === skipToken ? selectSkippedQuery : selectQuerySubstate;
|
1318 | return createSelector(finalSelectQuerySubState, withRequestFlags);
|
1319 | };
|
1320 | }
|
1321 | function buildMutationSelector() {
|
1322 | return function (id) {
|
1323 | var _a;
|
1324 | var mutationId;
|
1325 | if (typeof id === "object") {
|
1326 | mutationId = (_a = getMutationCacheKey(id)) != null ? _a : skipToken;
|
1327 | }
|
1328 | else {
|
1329 | mutationId = id;
|
1330 | }
|
1331 | var selectMutationSubstate = function (state) {
|
1332 | var _a2, _b, _c;
|
1333 | return (_c = (_b = (_a2 = selectInternalState(state)) == null ? void 0 : _a2.mutations) == null ? void 0 : _b[mutationId]) != null ? _c : defaultMutationSubState;
|
1334 | };
|
1335 | var finalSelectMutationSubstate = mutationId === skipToken ? selectSkippedMutation : selectMutationSubstate;
|
1336 | return createSelector(finalSelectMutationSubstate, withRequestFlags);
|
1337 | };
|
1338 | }
|
1339 | function selectInvalidatedBy(state, tags) {
|
1340 | var _a;
|
1341 | var apiState = state[reducerPath];
|
1342 | var toInvalidate = new Set();
|
1343 | for (var _j = 0, _k = tags.map(expandTagDescription); _j < _k.length; _j++) {
|
1344 | var tag = _k[_j];
|
1345 | var provided = apiState.provided[tag.type];
|
1346 | if (!provided) {
|
1347 | continue;
|
1348 | }
|
1349 | var invalidateSubscriptions = (_a = tag.id !== void 0 ? provided[tag.id] : flatten(Object.values(provided))) != null ? _a : [];
|
1350 | for (var _l = 0, invalidateSubscriptions_1 = invalidateSubscriptions; _l < invalidateSubscriptions_1.length; _l++) {
|
1351 | var invalidate = invalidateSubscriptions_1[_l];
|
1352 | toInvalidate.add(invalidate);
|
1353 | }
|
1354 | }
|
1355 | return flatten(Array.from(toInvalidate.values()).map(function (queryCacheKey) {
|
1356 | var querySubState = apiState.queries[queryCacheKey];
|
1357 | return querySubState ? [
|
1358 | {
|
1359 | queryCacheKey: queryCacheKey,
|
1360 | endpointName: querySubState.endpointName,
|
1361 | originalArgs: querySubState.originalArgs
|
1362 | }
|
1363 | ] : [];
|
1364 | }));
|
1365 | }
|
1366 | }
|
1367 |
|
1368 | import { isPlainObject as isPlainObject3 } from "@reduxjs/toolkit";
|
1369 | var defaultSerializeQueryArgs = function (_j) {
|
1370 | var endpointName = _j.endpointName, queryArgs = _j.queryArgs;
|
1371 | return endpointName + "(" + JSON.stringify(queryArgs, function (key, value) { return isPlainObject3(value) ? Object.keys(value).sort().reduce(function (acc, key2) {
|
1372 | acc[key2] = value[key2];
|
1373 | return acc;
|
1374 | }, {}) : value; }) + ")";
|
1375 | };
|
1376 |
|
1377 | import { nanoid } from "@reduxjs/toolkit";
|
1378 | import { defaultMemoize } from "reselect";
|
1379 | function buildCreateApi() {
|
1380 | var modules = [];
|
1381 | for (var _j = 0; _j < arguments.length; _j++) {
|
1382 | modules[_j] = arguments[_j];
|
1383 | }
|
1384 | return function baseCreateApi(options) {
|
1385 | var extractRehydrationInfo = defaultMemoize(function (action) {
|
1386 | var _a, _b;
|
1387 | return (_b = options.extractRehydrationInfo) == null ? void 0 : _b.call(options, action, {
|
1388 | reducerPath: (_a = options.reducerPath) != null ? _a : "api"
|
1389 | });
|
1390 | });
|
1391 | var optionsWithDefaults = __spreadProps(__spreadValues({
|
1392 | reducerPath: "api",
|
1393 | keepUnusedDataFor: 60,
|
1394 | refetchOnMountOrArgChange: false,
|
1395 | refetchOnFocus: false,
|
1396 | refetchOnReconnect: false
|
1397 | }, options), {
|
1398 | extractRehydrationInfo: extractRehydrationInfo,
|
1399 | serializeQueryArgs: function (queryArgsApi) {
|
1400 | var finalSerializeQueryArgs = defaultSerializeQueryArgs;
|
1401 | if ("serializeQueryArgs" in queryArgsApi.endpointDefinition) {
|
1402 | var endpointSQA_1 = queryArgsApi.endpointDefinition.serializeQueryArgs;
|
1403 | finalSerializeQueryArgs = function (queryArgsApi2) {
|
1404 | var initialResult = endpointSQA_1(queryArgsApi2);
|
1405 | if (typeof initialResult === "string") {
|
1406 | return initialResult;
|
1407 | }
|
1408 | else {
|
1409 | return defaultSerializeQueryArgs(__spreadProps(__spreadValues({}, queryArgsApi2), {
|
1410 | queryArgs: initialResult
|
1411 | }));
|
1412 | }
|
1413 | };
|
1414 | }
|
1415 | else if (options.serializeQueryArgs) {
|
1416 | finalSerializeQueryArgs = options.serializeQueryArgs;
|
1417 | }
|
1418 | return finalSerializeQueryArgs(queryArgsApi);
|
1419 | },
|
1420 | tagTypes: __spreadArray([], options.tagTypes || [])
|
1421 | });
|
1422 | var context = {
|
1423 | endpointDefinitions: {},
|
1424 | batch: function (fn) {
|
1425 | fn();
|
1426 | },
|
1427 | apiUid: nanoid(),
|
1428 | extractRehydrationInfo: extractRehydrationInfo,
|
1429 | hasRehydrationInfo: defaultMemoize(function (action) { return extractRehydrationInfo(action) != null; })
|
1430 | };
|
1431 | var api = {
|
1432 | injectEndpoints: injectEndpoints,
|
1433 | enhanceEndpoints: function (_j) {
|
1434 | var addTagTypes = _j.addTagTypes, endpoints = _j.endpoints;
|
1435 | if (addTagTypes) {
|
1436 | for (var _k = 0, addTagTypes_1 = addTagTypes; _k < addTagTypes_1.length; _k++) {
|
1437 | var eT = addTagTypes_1[_k];
|
1438 | if (!optionsWithDefaults.tagTypes.includes(eT)) {
|
1439 | ;
|
1440 | optionsWithDefaults.tagTypes.push(eT);
|
1441 | }
|
1442 | }
|
1443 | }
|
1444 | if (endpoints) {
|
1445 | for (var _l = 0, _m = Object.entries(endpoints); _l < _m.length; _l++) {
|
1446 | var _o = _m[_l], endpointName = _o[0], partialDefinition = _o[1];
|
1447 | if (typeof partialDefinition === "function") {
|
1448 | partialDefinition(context.endpointDefinitions[endpointName]);
|
1449 | }
|
1450 | else {
|
1451 | Object.assign(context.endpointDefinitions[endpointName] || {}, partialDefinition);
|
1452 | }
|
1453 | }
|
1454 | }
|
1455 | return api;
|
1456 | }
|
1457 | };
|
1458 | var initializedModules = modules.map(function (m) { return m.init(api, optionsWithDefaults, context); });
|
1459 | function injectEndpoints(inject) {
|
1460 | var evaluatedEndpoints = inject.endpoints({
|
1461 | query: function (x) { return __spreadProps(__spreadValues({}, x), { type: DefinitionType.query }); },
|
1462 | mutation: function (x) { return __spreadProps(__spreadValues({}, x), { type: DefinitionType.mutation }); }
|
1463 | });
|
1464 | for (var _j = 0, _k = Object.entries(evaluatedEndpoints); _j < _k.length; _j++) {
|
1465 | var _l = _k[_j], endpointName = _l[0], definition = _l[1];
|
1466 | if (!inject.overrideExisting && endpointName in context.endpointDefinitions) {
|
1467 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
1468 | console.error("called `injectEndpoints` to override already-existing endpointName " + endpointName + " without specifying `overrideExisting: true`");
|
1469 | }
|
1470 | continue;
|
1471 | }
|
1472 | context.endpointDefinitions[endpointName] = definition;
|
1473 | for (var _m = 0, initializedModules_1 = initializedModules; _m < initializedModules_1.length; _m++) {
|
1474 | var m = initializedModules_1[_m];
|
1475 | m.injectEndpoint(endpointName, definition);
|
1476 | }
|
1477 | }
|
1478 | return api;
|
1479 | }
|
1480 | return api.injectEndpoints({ endpoints: options.endpoints });
|
1481 | };
|
1482 | }
|
1483 |
|
1484 | function fakeBaseQuery() {
|
1485 | return function () {
|
1486 | throw new Error("When using `fakeBaseQuery`, all queries & mutations must use the `queryFn` definition syntax.");
|
1487 | };
|
1488 | }
|
1489 |
|
1490 | import { createAction as createAction3 } from "@reduxjs/toolkit";
|
1491 |
|
1492 | function isObjectEmpty(obj) {
|
1493 | for (var k in obj) {
|
1494 | return false;
|
1495 | }
|
1496 | return true;
|
1497 | }
|
1498 | var THIRTY_TWO_BIT_MAX_TIMER_SECONDS = 2147483647 / 1e3 - 1;
|
1499 | var buildCacheCollectionHandler = function (_j) {
|
1500 | var reducerPath = _j.reducerPath, api = _j.api, context = _j.context, internalState = _j.internalState;
|
1501 | var _k = api.internalActions, removeQueryResult = _k.removeQueryResult, unsubscribeQueryResult = _k.unsubscribeQueryResult;
|
1502 | function anySubscriptionsRemainingForKey(queryCacheKey) {
|
1503 | var subscriptions = internalState.currentSubscriptions[queryCacheKey];
|
1504 | return !!subscriptions && !isObjectEmpty(subscriptions);
|
1505 | }
|
1506 | var currentRemovalTimeouts = {};
|
1507 | var handler = function (action, mwApi, internalState2) {
|
1508 | var _a;
|
1509 | if (unsubscribeQueryResult.match(action)) {
|
1510 | var state = mwApi.getState()[reducerPath];
|
1511 | var queryCacheKey = action.payload.queryCacheKey;
|
1512 | handleUnsubscribe(queryCacheKey, (_a = state.queries[queryCacheKey]) == null ? void 0 : _a.endpointName, mwApi, state.config);
|
1513 | }
|
1514 | if (api.util.resetApiState.match(action)) {
|
1515 | for (var _j = 0, _k = Object.entries(currentRemovalTimeouts); _j < _k.length; _j++) {
|
1516 | var _l = _k[_j], key = _l[0], timeout = _l[1];
|
1517 | if (timeout)
|
1518 | clearTimeout(timeout);
|
1519 | delete currentRemovalTimeouts[key];
|
1520 | }
|
1521 | }
|
1522 | if (context.hasRehydrationInfo(action)) {
|
1523 | var state = mwApi.getState()[reducerPath];
|
1524 | var queries = context.extractRehydrationInfo(action).queries;
|
1525 | for (var _m = 0, _o = Object.entries(queries); _m < _o.length; _m++) {
|
1526 | var _p = _o[_m], queryCacheKey = _p[0], queryState = _p[1];
|
1527 | handleUnsubscribe(queryCacheKey, queryState == null ? void 0 : queryState.endpointName, mwApi, state.config);
|
1528 | }
|
1529 | }
|
1530 | };
|
1531 | function handleUnsubscribe(queryCacheKey, endpointName, api2, config) {
|
1532 | var _a;
|
1533 | var endpointDefinition = context.endpointDefinitions[endpointName];
|
1534 | var keepUnusedDataFor = (_a = endpointDefinition == null ? void 0 : endpointDefinition.keepUnusedDataFor) != null ? _a : config.keepUnusedDataFor;
|
1535 | if (keepUnusedDataFor === Infinity) {
|
1536 | return;
|
1537 | }
|
1538 | var finalKeepUnusedDataFor = Math.max(0, Math.min(keepUnusedDataFor, THIRTY_TWO_BIT_MAX_TIMER_SECONDS));
|
1539 | if (!anySubscriptionsRemainingForKey(queryCacheKey)) {
|
1540 | var currentTimeout = currentRemovalTimeouts[queryCacheKey];
|
1541 | if (currentTimeout) {
|
1542 | clearTimeout(currentTimeout);
|
1543 | }
|
1544 | currentRemovalTimeouts[queryCacheKey] = setTimeout(function () {
|
1545 | if (!anySubscriptionsRemainingForKey(queryCacheKey)) {
|
1546 | api2.dispatch(removeQueryResult({ queryCacheKey: queryCacheKey }));
|
1547 | }
|
1548 | delete currentRemovalTimeouts[queryCacheKey];
|
1549 | }, finalKeepUnusedDataFor * 1e3);
|
1550 | }
|
1551 | }
|
1552 | return handler;
|
1553 | };
|
1554 |
|
1555 | import { isAnyOf as isAnyOf2, isFulfilled as isFulfilled3, isRejectedWithValue as isRejectedWithValue3 } from "@reduxjs/toolkit";
|
1556 | var buildInvalidationByTagsHandler = function (_j) {
|
1557 | var reducerPath = _j.reducerPath, context = _j.context, endpointDefinitions = _j.context.endpointDefinitions, mutationThunk = _j.mutationThunk, api = _j.api, assertTagType = _j.assertTagType, refetchQuery = _j.refetchQuery;
|
1558 | var removeQueryResult = api.internalActions.removeQueryResult;
|
1559 | var isThunkActionWithTags = isAnyOf2(isFulfilled3(mutationThunk), isRejectedWithValue3(mutationThunk));
|
1560 | var handler = function (action, mwApi) {
|
1561 | if (isThunkActionWithTags(action)) {
|
1562 | invalidateTags(calculateProvidedByThunk(action, "invalidatesTags", endpointDefinitions, assertTagType), mwApi);
|
1563 | }
|
1564 | if (api.util.invalidateTags.match(action)) {
|
1565 | invalidateTags(calculateProvidedBy(action.payload, void 0, void 0, void 0, void 0, assertTagType), mwApi);
|
1566 | }
|
1567 | };
|
1568 | function invalidateTags(tags, mwApi) {
|
1569 | var rootState = mwApi.getState();
|
1570 | var state = rootState[reducerPath];
|
1571 | var toInvalidate = api.util.selectInvalidatedBy(rootState, tags);
|
1572 | context.batch(function () {
|
1573 | var _a;
|
1574 | var valuesArray = Array.from(toInvalidate.values());
|
1575 | for (var _j = 0, valuesArray_1 = valuesArray; _j < valuesArray_1.length; _j++) {
|
1576 | var queryCacheKey = valuesArray_1[_j].queryCacheKey;
|
1577 | var querySubState = state.queries[queryCacheKey];
|
1578 | var subscriptionSubState = (_a = state.subscriptions[queryCacheKey]) != null ? _a : {};
|
1579 | if (querySubState) {
|
1580 | if (Object.keys(subscriptionSubState).length === 0) {
|
1581 | mwApi.dispatch(removeQueryResult({
|
1582 | queryCacheKey: queryCacheKey
|
1583 | }));
|
1584 | }
|
1585 | else if (querySubState.status !== QueryStatus.uninitialized) {
|
1586 | mwApi.dispatch(refetchQuery(querySubState, queryCacheKey));
|
1587 | }
|
1588 | }
|
1589 | }
|
1590 | });
|
1591 | }
|
1592 | return handler;
|
1593 | };
|
1594 |
|
1595 | var buildPollingHandler = function (_j) {
|
1596 | var reducerPath = _j.reducerPath, queryThunk = _j.queryThunk, api = _j.api, refetchQuery = _j.refetchQuery, internalState = _j.internalState;
|
1597 | var currentPolls = {};
|
1598 | var handler = function (action, mwApi) {
|
1599 | if (api.internalActions.updateSubscriptionOptions.match(action) || api.internalActions.unsubscribeQueryResult.match(action)) {
|
1600 | updatePollingInterval(action.payload, mwApi);
|
1601 | }
|
1602 | if (queryThunk.pending.match(action) || queryThunk.rejected.match(action) && action.meta.condition) {
|
1603 | updatePollingInterval(action.meta.arg, mwApi);
|
1604 | }
|
1605 | if (queryThunk.fulfilled.match(action) || queryThunk.rejected.match(action) && !action.meta.condition) {
|
1606 | startNextPoll(action.meta.arg, mwApi);
|
1607 | }
|
1608 | if (api.util.resetApiState.match(action)) {
|
1609 | clearPolls();
|
1610 | }
|
1611 | };
|
1612 | function startNextPoll(_j, api2) {
|
1613 | var queryCacheKey = _j.queryCacheKey;
|
1614 | var state = api2.getState()[reducerPath];
|
1615 | var querySubState = state.queries[queryCacheKey];
|
1616 | var subscriptions = internalState.currentSubscriptions[queryCacheKey];
|
1617 | if (!querySubState || querySubState.status === QueryStatus.uninitialized)
|
1618 | return;
|
1619 | var lowestPollingInterval = findLowestPollingInterval(subscriptions);
|
1620 | if (!Number.isFinite(lowestPollingInterval))
|
1621 | return;
|
1622 | var currentPoll = currentPolls[queryCacheKey];
|
1623 | if (currentPoll == null ? void 0 : currentPoll.timeout) {
|
1624 | clearTimeout(currentPoll.timeout);
|
1625 | currentPoll.timeout = void 0;
|
1626 | }
|
1627 | var nextPollTimestamp = Date.now() + lowestPollingInterval;
|
1628 | var currentInterval = currentPolls[queryCacheKey] = {
|
1629 | nextPollTimestamp: nextPollTimestamp,
|
1630 | pollingInterval: lowestPollingInterval,
|
1631 | timeout: setTimeout(function () {
|
1632 | currentInterval.timeout = void 0;
|
1633 | api2.dispatch(refetchQuery(querySubState, queryCacheKey));
|
1634 | }, lowestPollingInterval)
|
1635 | };
|
1636 | }
|
1637 | function updatePollingInterval(_j, api2) {
|
1638 | var queryCacheKey = _j.queryCacheKey;
|
1639 | var state = api2.getState()[reducerPath];
|
1640 | var querySubState = state.queries[queryCacheKey];
|
1641 | var subscriptions = internalState.currentSubscriptions[queryCacheKey];
|
1642 | if (!querySubState || querySubState.status === QueryStatus.uninitialized) {
|
1643 | return;
|
1644 | }
|
1645 | var lowestPollingInterval = findLowestPollingInterval(subscriptions);
|
1646 | if (!Number.isFinite(lowestPollingInterval)) {
|
1647 | cleanupPollForKey(queryCacheKey);
|
1648 | return;
|
1649 | }
|
1650 | var currentPoll = currentPolls[queryCacheKey];
|
1651 | var nextPollTimestamp = Date.now() + lowestPollingInterval;
|
1652 | if (!currentPoll || nextPollTimestamp < currentPoll.nextPollTimestamp) {
|
1653 | startNextPoll({ queryCacheKey: queryCacheKey }, api2);
|
1654 | }
|
1655 | }
|
1656 | function cleanupPollForKey(key) {
|
1657 | var existingPoll = currentPolls[key];
|
1658 | if (existingPoll == null ? void 0 : existingPoll.timeout) {
|
1659 | clearTimeout(existingPoll.timeout);
|
1660 | }
|
1661 | delete currentPolls[key];
|
1662 | }
|
1663 | function clearPolls() {
|
1664 | for (var _j = 0, _k = Object.keys(currentPolls); _j < _k.length; _j++) {
|
1665 | var key = _k[_j];
|
1666 | cleanupPollForKey(key);
|
1667 | }
|
1668 | }
|
1669 | function findLowestPollingInterval(subscribers) {
|
1670 | if (subscribers === void 0) { subscribers = {}; }
|
1671 | var lowestPollingInterval = Number.POSITIVE_INFINITY;
|
1672 | for (var key in subscribers) {
|
1673 | if (!!subscribers[key].pollingInterval) {
|
1674 | lowestPollingInterval = Math.min(subscribers[key].pollingInterval, lowestPollingInterval);
|
1675 | }
|
1676 | }
|
1677 | return lowestPollingInterval;
|
1678 | }
|
1679 | return handler;
|
1680 | };
|
1681 |
|
1682 | var buildWindowEventHandler = function (_j) {
|
1683 | var reducerPath = _j.reducerPath, context = _j.context, api = _j.api, refetchQuery = _j.refetchQuery, internalState = _j.internalState;
|
1684 | var removeQueryResult = api.internalActions.removeQueryResult;
|
1685 | var handler = function (action, mwApi) {
|
1686 | if (onFocus.match(action)) {
|
1687 | refetchValidQueries(mwApi, "refetchOnFocus");
|
1688 | }
|
1689 | if (onOnline.match(action)) {
|
1690 | refetchValidQueries(mwApi, "refetchOnReconnect");
|
1691 | }
|
1692 | };
|
1693 | function refetchValidQueries(api2, type) {
|
1694 | var state = api2.getState()[reducerPath];
|
1695 | var queries = state.queries;
|
1696 | var subscriptions = internalState.currentSubscriptions;
|
1697 | context.batch(function () {
|
1698 | for (var _j = 0, _k = Object.keys(subscriptions); _j < _k.length; _j++) {
|
1699 | var queryCacheKey = _k[_j];
|
1700 | var querySubState = queries[queryCacheKey];
|
1701 | var subscriptionSubState = subscriptions[queryCacheKey];
|
1702 | if (!subscriptionSubState || !querySubState)
|
1703 | continue;
|
1704 | var shouldRefetch = Object.values(subscriptionSubState).some(function (sub) { return sub[type] === true; }) || Object.values(subscriptionSubState).every(function (sub) { return sub[type] === void 0; }) && state.config[type];
|
1705 | if (shouldRefetch) {
|
1706 | if (Object.keys(subscriptionSubState).length === 0) {
|
1707 | api2.dispatch(removeQueryResult({
|
1708 | queryCacheKey: queryCacheKey
|
1709 | }));
|
1710 | }
|
1711 | else if (querySubState.status !== QueryStatus.uninitialized) {
|
1712 | api2.dispatch(refetchQuery(querySubState, queryCacheKey));
|
1713 | }
|
1714 | }
|
1715 | }
|
1716 | });
|
1717 | }
|
1718 | return handler;
|
1719 | };
|
1720 |
|
1721 | import { isAsyncThunkAction, isFulfilled as isFulfilled4 } from "@reduxjs/toolkit";
|
1722 | var neverResolvedError = new Error("Promise never resolved before cacheEntryRemoved.");
|
1723 | var buildCacheLifecycleHandler = function (_j) {
|
1724 | var api = _j.api, reducerPath = _j.reducerPath, context = _j.context, queryThunk = _j.queryThunk, mutationThunk = _j.mutationThunk, internalState = _j.internalState;
|
1725 | var isQueryThunk = isAsyncThunkAction(queryThunk);
|
1726 | var isMutationThunk = isAsyncThunkAction(mutationThunk);
|
1727 | var isFulfilledThunk = isFulfilled4(queryThunk, mutationThunk);
|
1728 | var lifecycleMap = {};
|
1729 | var handler = function (action, mwApi, stateBefore) {
|
1730 | var cacheKey = getCacheKey(action);
|
1731 | if (queryThunk.pending.match(action)) {
|
1732 | var oldState = stateBefore[reducerPath].queries[cacheKey];
|
1733 | var state = mwApi.getState()[reducerPath].queries[cacheKey];
|
1734 | if (!oldState && state) {
|
1735 | handleNewKey(action.meta.arg.endpointName, action.meta.arg.originalArgs, cacheKey, mwApi, action.meta.requestId);
|
1736 | }
|
1737 | }
|
1738 | else if (mutationThunk.pending.match(action)) {
|
1739 | var state = mwApi.getState()[reducerPath].mutations[cacheKey];
|
1740 | if (state) {
|
1741 | handleNewKey(action.meta.arg.endpointName, action.meta.arg.originalArgs, cacheKey, mwApi, action.meta.requestId);
|
1742 | }
|
1743 | }
|
1744 | else if (isFulfilledThunk(action)) {
|
1745 | var lifecycle = lifecycleMap[cacheKey];
|
1746 | if (lifecycle == null ? void 0 : lifecycle.valueResolved) {
|
1747 | lifecycle.valueResolved({
|
1748 | data: action.payload,
|
1749 | meta: action.meta.baseQueryMeta
|
1750 | });
|
1751 | delete lifecycle.valueResolved;
|
1752 | }
|
1753 | }
|
1754 | else if (api.internalActions.removeQueryResult.match(action) || api.internalActions.removeMutationResult.match(action)) {
|
1755 | var lifecycle = lifecycleMap[cacheKey];
|
1756 | if (lifecycle) {
|
1757 | delete lifecycleMap[cacheKey];
|
1758 | lifecycle.cacheEntryRemoved();
|
1759 | }
|
1760 | }
|
1761 | else if (api.util.resetApiState.match(action)) {
|
1762 | for (var _j = 0, _k = Object.entries(lifecycleMap); _j < _k.length; _j++) {
|
1763 | var _l = _k[_j], cacheKey2 = _l[0], lifecycle = _l[1];
|
1764 | delete lifecycleMap[cacheKey2];
|
1765 | lifecycle.cacheEntryRemoved();
|
1766 | }
|
1767 | }
|
1768 | };
|
1769 | function getCacheKey(action) {
|
1770 | if (isQueryThunk(action))
|
1771 | return action.meta.arg.queryCacheKey;
|
1772 | if (isMutationThunk(action))
|
1773 | return action.meta.requestId;
|
1774 | if (api.internalActions.removeQueryResult.match(action))
|
1775 | return action.payload.queryCacheKey;
|
1776 | if (api.internalActions.removeMutationResult.match(action))
|
1777 | return getMutationCacheKey(action.payload);
|
1778 | return "";
|
1779 | }
|
1780 | function handleNewKey(endpointName, originalArgs, queryCacheKey, mwApi, requestId) {
|
1781 | var endpointDefinition = context.endpointDefinitions[endpointName];
|
1782 | var onCacheEntryAdded = endpointDefinition == null ? void 0 : endpointDefinition.onCacheEntryAdded;
|
1783 | if (!onCacheEntryAdded)
|
1784 | return;
|
1785 | var lifecycle = {};
|
1786 | var cacheEntryRemoved = new Promise(function (resolve) {
|
1787 | lifecycle.cacheEntryRemoved = resolve;
|
1788 | });
|
1789 | var cacheDataLoaded = Promise.race([
|
1790 | new Promise(function (resolve) {
|
1791 | lifecycle.valueResolved = resolve;
|
1792 | }),
|
1793 | cacheEntryRemoved.then(function () {
|
1794 | throw neverResolvedError;
|
1795 | })
|
1796 | ]);
|
1797 | cacheDataLoaded.catch(function () {
|
1798 | });
|
1799 | lifecycleMap[queryCacheKey] = lifecycle;
|
1800 | var selector = api.endpoints[endpointName].select(endpointDefinition.type === DefinitionType.query ? originalArgs : queryCacheKey);
|
1801 | var extra = mwApi.dispatch(function (_, __, extra2) { return extra2; });
|
1802 | var lifecycleApi = __spreadProps(__spreadValues({}, mwApi), {
|
1803 | getCacheEntry: function () { return selector(mwApi.getState()); },
|
1804 | requestId: requestId,
|
1805 | extra: extra,
|
1806 | updateCachedData: endpointDefinition.type === DefinitionType.query ? function (updateRecipe) { return mwApi.dispatch(api.util.updateQueryData(endpointName, originalArgs, updateRecipe)); } : void 0,
|
1807 | cacheDataLoaded: cacheDataLoaded,
|
1808 | cacheEntryRemoved: cacheEntryRemoved
|
1809 | });
|
1810 | var runningHandler = onCacheEntryAdded(originalArgs, lifecycleApi);
|
1811 | Promise.resolve(runningHandler).catch(function (e) {
|
1812 | if (e === neverResolvedError)
|
1813 | return;
|
1814 | throw e;
|
1815 | });
|
1816 | }
|
1817 | return handler;
|
1818 | };
|
1819 |
|
1820 | import { isPending as isPending2, isRejected as isRejected2, isFulfilled as isFulfilled5 } from "@reduxjs/toolkit";
|
1821 | var buildQueryLifecycleHandler = function (_j) {
|
1822 | var api = _j.api, context = _j.context, queryThunk = _j.queryThunk, mutationThunk = _j.mutationThunk;
|
1823 | var isPendingThunk = isPending2(queryThunk, mutationThunk);
|
1824 | var isRejectedThunk = isRejected2(queryThunk, mutationThunk);
|
1825 | var isFullfilledThunk = isFulfilled5(queryThunk, mutationThunk);
|
1826 | var lifecycleMap = {};
|
1827 | var handler = function (action, mwApi) {
|
1828 | var _a, _b, _c;
|
1829 | if (isPendingThunk(action)) {
|
1830 | var _j = action.meta, requestId = _j.requestId, _k = _j.arg, endpointName_1 = _k.endpointName, originalArgs_1 = _k.originalArgs;
|
1831 | var endpointDefinition = context.endpointDefinitions[endpointName_1];
|
1832 | var onQueryStarted = endpointDefinition == null ? void 0 : endpointDefinition.onQueryStarted;
|
1833 | if (onQueryStarted) {
|
1834 | var lifecycle_1 = {};
|
1835 | var queryFulfilled = new Promise(function (resolve, reject) {
|
1836 | lifecycle_1.resolve = resolve;
|
1837 | lifecycle_1.reject = reject;
|
1838 | });
|
1839 | queryFulfilled.catch(function () {
|
1840 | });
|
1841 | lifecycleMap[requestId] = lifecycle_1;
|
1842 | var selector_1 = api.endpoints[endpointName_1].select(endpointDefinition.type === DefinitionType.query ? originalArgs_1 : requestId);
|
1843 | var extra = mwApi.dispatch(function (_, __, extra2) { return extra2; });
|
1844 | var lifecycleApi = __spreadProps(__spreadValues({}, mwApi), {
|
1845 | getCacheEntry: function () { return selector_1(mwApi.getState()); },
|
1846 | requestId: requestId,
|
1847 | extra: extra,
|
1848 | updateCachedData: endpointDefinition.type === DefinitionType.query ? function (updateRecipe) { return mwApi.dispatch(api.util.updateQueryData(endpointName_1, originalArgs_1, updateRecipe)); } : void 0,
|
1849 | queryFulfilled: queryFulfilled
|
1850 | });
|
1851 | onQueryStarted(originalArgs_1, lifecycleApi);
|
1852 | }
|
1853 | }
|
1854 | else if (isFullfilledThunk(action)) {
|
1855 | var _l = action.meta, requestId = _l.requestId, baseQueryMeta = _l.baseQueryMeta;
|
1856 | (_a = lifecycleMap[requestId]) == null ? void 0 : _a.resolve({
|
1857 | data: action.payload,
|
1858 | meta: baseQueryMeta
|
1859 | });
|
1860 | delete lifecycleMap[requestId];
|
1861 | }
|
1862 | else if (isRejectedThunk(action)) {
|
1863 | var _m = action.meta, requestId = _m.requestId, rejectedWithValue = _m.rejectedWithValue, baseQueryMeta = _m.baseQueryMeta;
|
1864 | (_c = lifecycleMap[requestId]) == null ? void 0 : _c.reject({
|
1865 | error: (_b = action.payload) != null ? _b : action.error,
|
1866 | isUnhandledError: !rejectedWithValue,
|
1867 | meta: baseQueryMeta
|
1868 | });
|
1869 | delete lifecycleMap[requestId];
|
1870 | }
|
1871 | };
|
1872 | return handler;
|
1873 | };
|
1874 |
|
1875 | var buildDevCheckHandler = function (_j) {
|
1876 | var api = _j.api, apiUid = _j.context.apiUid, reducerPath = _j.reducerPath;
|
1877 | return function (action, mwApi) {
|
1878 | var _a, _b;
|
1879 | if (api.util.resetApiState.match(action)) {
|
1880 | mwApi.dispatch(api.internalActions.middlewareRegistered(apiUid));
|
1881 | }
|
1882 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
1883 | 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") {
|
1884 | console.warn("There is a mismatch between slice and middleware for the reducerPath \"" + reducerPath + "\".\nYou can only have one api per reducer path, this will lead to crashes in various situations!" + (reducerPath === "api" ? "\nIf you have multiple apis, you *have* to specify the reducerPath option when using createApi!" : ""));
|
1885 | }
|
1886 | }
|
1887 | };
|
1888 | };
|
1889 |
|
1890 | import { produceWithPatches as produceWithPatches2 } from "immer";
|
1891 | var promise;
|
1892 | var queueMicrotaskShim = typeof queueMicrotask === "function" ? queueMicrotask.bind(typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : globalThis) : function (cb) { return (promise || (promise = Promise.resolve())).then(cb).catch(function (err) { return setTimeout(function () {
|
1893 | throw err;
|
1894 | }, 0); }); };
|
1895 | var buildBatchedActionsHandler = function (_j) {
|
1896 | var api = _j.api, queryThunk = _j.queryThunk, internalState = _j.internalState;
|
1897 | var subscriptionsPrefix = api.reducerPath + "/subscriptions";
|
1898 | var previousSubscriptions = null;
|
1899 | var dispatchQueued = false;
|
1900 | var _k = api.internalActions, updateSubscriptionOptions = _k.updateSubscriptionOptions, unsubscribeQueryResult = _k.unsubscribeQueryResult;
|
1901 | var actuallyMutateSubscriptions = function (mutableState, action) {
|
1902 | var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
1903 | if (updateSubscriptionOptions.match(action)) {
|
1904 | var _j = action.payload, queryCacheKey = _j.queryCacheKey, requestId = _j.requestId, options = _j.options;
|
1905 | if ((_a = mutableState == null ? void 0 : mutableState[queryCacheKey]) == null ? void 0 : _a[requestId]) {
|
1906 | mutableState[queryCacheKey][requestId] = options;
|
1907 | }
|
1908 | return true;
|
1909 | }
|
1910 | if (unsubscribeQueryResult.match(action)) {
|
1911 | var _k = action.payload, queryCacheKey = _k.queryCacheKey, requestId = _k.requestId;
|
1912 | if (mutableState[queryCacheKey]) {
|
1913 | delete mutableState[queryCacheKey][requestId];
|
1914 | }
|
1915 | return true;
|
1916 | }
|
1917 | if (api.internalActions.removeQueryResult.match(action)) {
|
1918 | delete mutableState[action.payload.queryCacheKey];
|
1919 | return true;
|
1920 | }
|
1921 | if (queryThunk.pending.match(action)) {
|
1922 | var _l = action.meta, arg = _l.arg, requestId = _l.requestId;
|
1923 | if (arg.subscribe) {
|
1924 | var substate = (_c = mutableState[_b = arg.queryCacheKey]) != null ? _c : mutableState[_b] = {};
|
1925 | substate[requestId] = (_e = (_d = arg.subscriptionOptions) != null ? _d : substate[requestId]) != null ? _e : {};
|
1926 | return true;
|
1927 | }
|
1928 | }
|
1929 | if (queryThunk.rejected.match(action)) {
|
1930 | var _m = action.meta, condition = _m.condition, arg = _m.arg, requestId = _m.requestId;
|
1931 | if (condition && arg.subscribe) {
|
1932 | var substate = (_g = mutableState[_f = arg.queryCacheKey]) != null ? _g : mutableState[_f] = {};
|
1933 | substate[requestId] = (_i = (_h = arg.subscriptionOptions) != null ? _h : substate[requestId]) != null ? _i : {};
|
1934 | return true;
|
1935 | }
|
1936 | }
|
1937 | return false;
|
1938 | };
|
1939 | return function (action, mwApi) {
|
1940 | var _a, _b;
|
1941 | if (!previousSubscriptions) {
|
1942 | previousSubscriptions = JSON.parse(JSON.stringify(internalState.currentSubscriptions));
|
1943 | }
|
1944 | if (api.internalActions.internal_probeSubscription.match(action)) {
|
1945 | var _j = action.payload, queryCacheKey = _j.queryCacheKey, requestId = _j.requestId;
|
1946 | var hasSubscription = !!((_a = internalState.currentSubscriptions[queryCacheKey]) == null ? void 0 : _a[requestId]);
|
1947 | return [false, hasSubscription];
|
1948 | }
|
1949 | var didMutate = actuallyMutateSubscriptions(internalState.currentSubscriptions, action);
|
1950 | if (didMutate) {
|
1951 | if (!dispatchQueued) {
|
1952 | queueMicrotaskShim(function () {
|
1953 | var newSubscriptions = JSON.parse(JSON.stringify(internalState.currentSubscriptions));
|
1954 | var _j = produceWithPatches2(previousSubscriptions, function () { return newSubscriptions; }), patches = _j[1];
|
1955 | mwApi.next(api.internalActions.subscriptionsUpdated(patches));
|
1956 | previousSubscriptions = newSubscriptions;
|
1957 | dispatchQueued = false;
|
1958 | });
|
1959 | dispatchQueued = true;
|
1960 | }
|
1961 | var isSubscriptionSliceAction = !!((_b = action.type) == null ? void 0 : _b.startsWith(subscriptionsPrefix));
|
1962 | var isAdditionalSubscriptionAction = queryThunk.rejected.match(action) && action.meta.condition && !!action.meta.arg.subscribe;
|
1963 | var actionShouldContinue = !isSubscriptionSliceAction && !isAdditionalSubscriptionAction;
|
1964 | return [actionShouldContinue, false];
|
1965 | }
|
1966 | return [true, false];
|
1967 | };
|
1968 | };
|
1969 |
|
1970 | function buildMiddleware(input) {
|
1971 | var reducerPath = input.reducerPath, queryThunk = input.queryThunk, api = input.api, context = input.context;
|
1972 | var apiUid = context.apiUid;
|
1973 | var actions = {
|
1974 | invalidateTags: createAction3(reducerPath + "/invalidateTags")
|
1975 | };
|
1976 | var isThisApiSliceAction = function (action) {
|
1977 | return !!action && typeof action.type === "string" && action.type.startsWith(reducerPath + "/");
|
1978 | };
|
1979 | var handlerBuilders = [
|
1980 | buildDevCheckHandler,
|
1981 | buildCacheCollectionHandler,
|
1982 | buildInvalidationByTagsHandler,
|
1983 | buildPollingHandler,
|
1984 | buildCacheLifecycleHandler,
|
1985 | buildQueryLifecycleHandler
|
1986 | ];
|
1987 | var middleware = function (mwApi) {
|
1988 | var initialized2 = false;
|
1989 | var internalState = {
|
1990 | currentSubscriptions: {}
|
1991 | };
|
1992 | var builderArgs = __spreadProps(__spreadValues({}, input), {
|
1993 | internalState: internalState,
|
1994 | refetchQuery: refetchQuery
|
1995 | });
|
1996 | var handlers = handlerBuilders.map(function (build) { return build(builderArgs); });
|
1997 | var batchedActionsHandler = buildBatchedActionsHandler(builderArgs);
|
1998 | var windowEventsHandler = buildWindowEventHandler(builderArgs);
|
1999 | return function (next) {
|
2000 | return function (action) {
|
2001 | if (!initialized2) {
|
2002 | initialized2 = true;
|
2003 | mwApi.dispatch(api.internalActions.middlewareRegistered(apiUid));
|
2004 | }
|
2005 | var mwApiWithNext = __spreadProps(__spreadValues({}, mwApi), { next: next });
|
2006 | var stateBefore = mwApi.getState();
|
2007 | var _j = batchedActionsHandler(action, mwApiWithNext, stateBefore), actionShouldContinue = _j[0], hasSubscription = _j[1];
|
2008 | var res;
|
2009 | if (actionShouldContinue) {
|
2010 | res = next(action);
|
2011 | }
|
2012 | else {
|
2013 | res = hasSubscription;
|
2014 | }
|
2015 | if (!!mwApi.getState()[reducerPath]) {
|
2016 | windowEventsHandler(action, mwApiWithNext, stateBefore);
|
2017 | if (isThisApiSliceAction(action) || context.hasRehydrationInfo(action)) {
|
2018 | for (var _k = 0, handlers_1 = handlers; _k < handlers_1.length; _k++) {
|
2019 | var handler = handlers_1[_k];
|
2020 | handler(action, mwApiWithNext, stateBefore);
|
2021 | }
|
2022 | }
|
2023 | }
|
2024 | return res;
|
2025 | };
|
2026 | };
|
2027 | };
|
2028 | return { middleware: middleware, actions: actions };
|
2029 | function refetchQuery(querySubState, queryCacheKey, override) {
|
2030 | if (override === void 0) { override = {}; }
|
2031 | return queryThunk(__spreadValues({
|
2032 | type: "query",
|
2033 | endpointName: querySubState.endpointName,
|
2034 | originalArgs: querySubState.originalArgs,
|
2035 | subscribe: false,
|
2036 | forceRefetch: true,
|
2037 | queryCacheKey: queryCacheKey
|
2038 | }, override));
|
2039 | }
|
2040 | }
|
2041 |
|
2042 | function assertCast(v) {
|
2043 | }
|
2044 | function safeAssign(target) {
|
2045 | var args = [];
|
2046 | for (var _j = 1; _j < arguments.length; _j++) {
|
2047 | args[_j - 1] = arguments[_j];
|
2048 | }
|
2049 | Object.assign.apply(Object, __spreadArray([target], args));
|
2050 | }
|
2051 |
|
2052 | import { enablePatches } from "immer";
|
2053 | var coreModuleName = Symbol();
|
2054 | var coreModule = function () { return ({
|
2055 | name: coreModuleName,
|
2056 | init: function (api, _j, context) {
|
2057 | var baseQuery = _j.baseQuery, tagTypes = _j.tagTypes, reducerPath = _j.reducerPath, serializeQueryArgs = _j.serializeQueryArgs, keepUnusedDataFor = _j.keepUnusedDataFor, refetchOnMountOrArgChange = _j.refetchOnMountOrArgChange, refetchOnFocus = _j.refetchOnFocus, refetchOnReconnect = _j.refetchOnReconnect;
|
2058 | enablePatches();
|
2059 | assertCast(serializeQueryArgs);
|
2060 | var assertTagType = function (tag) {
|
2061 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
2062 | if (!tagTypes.includes(tag.type)) {
|
2063 | console.error("Tag type '" + tag.type + "' was used, but not specified in `tagTypes`!");
|
2064 | }
|
2065 | }
|
2066 | return tag;
|
2067 | };
|
2068 | Object.assign(api, {
|
2069 | reducerPath: reducerPath,
|
2070 | endpoints: {},
|
2071 | internalActions: {
|
2072 | onOnline: onOnline,
|
2073 | onOffline: onOffline,
|
2074 | onFocus: onFocus,
|
2075 | onFocusLost: onFocusLost
|
2076 | },
|
2077 | util: {}
|
2078 | });
|
2079 | var _k = buildThunks({
|
2080 | baseQuery: baseQuery,
|
2081 | reducerPath: reducerPath,
|
2082 | context: context,
|
2083 | api: api,
|
2084 | serializeQueryArgs: serializeQueryArgs
|
2085 | }), queryThunk = _k.queryThunk, mutationThunk = _k.mutationThunk, patchQueryData = _k.patchQueryData, updateQueryData = _k.updateQueryData, upsertQueryData = _k.upsertQueryData, prefetch = _k.prefetch, buildMatchThunkActions = _k.buildMatchThunkActions;
|
2086 | var _l = buildSlice({
|
2087 | context: context,
|
2088 | queryThunk: queryThunk,
|
2089 | mutationThunk: mutationThunk,
|
2090 | reducerPath: reducerPath,
|
2091 | assertTagType: assertTagType,
|
2092 | config: {
|
2093 | refetchOnFocus: refetchOnFocus,
|
2094 | refetchOnReconnect: refetchOnReconnect,
|
2095 | refetchOnMountOrArgChange: refetchOnMountOrArgChange,
|
2096 | keepUnusedDataFor: keepUnusedDataFor,
|
2097 | reducerPath: reducerPath
|
2098 | }
|
2099 | }), reducer = _l.reducer, sliceActions = _l.actions;
|
2100 | safeAssign(api.util, {
|
2101 | patchQueryData: patchQueryData,
|
2102 | updateQueryData: updateQueryData,
|
2103 | upsertQueryData: upsertQueryData,
|
2104 | prefetch: prefetch,
|
2105 | resetApiState: sliceActions.resetApiState
|
2106 | });
|
2107 | safeAssign(api.internalActions, sliceActions);
|
2108 | var _m = buildMiddleware({
|
2109 | reducerPath: reducerPath,
|
2110 | context: context,
|
2111 | queryThunk: queryThunk,
|
2112 | mutationThunk: mutationThunk,
|
2113 | api: api,
|
2114 | assertTagType: assertTagType
|
2115 | }), middleware = _m.middleware, middlewareActions = _m.actions;
|
2116 | safeAssign(api.util, middlewareActions);
|
2117 | safeAssign(api, { reducer: reducer, middleware: middleware });
|
2118 | var _o = buildSelectors({
|
2119 | serializeQueryArgs: serializeQueryArgs,
|
2120 | reducerPath: reducerPath
|
2121 | }), buildQuerySelector = _o.buildQuerySelector, buildMutationSelector = _o.buildMutationSelector, selectInvalidatedBy = _o.selectInvalidatedBy;
|
2122 | safeAssign(api.util, { selectInvalidatedBy: selectInvalidatedBy });
|
2123 | var _p = buildInitiate({
|
2124 | queryThunk: queryThunk,
|
2125 | mutationThunk: mutationThunk,
|
2126 | api: api,
|
2127 | serializeQueryArgs: serializeQueryArgs,
|
2128 | context: context
|
2129 | }), buildInitiateQuery = _p.buildInitiateQuery, buildInitiateMutation = _p.buildInitiateMutation, getRunningMutationThunk = _p.getRunningMutationThunk, getRunningMutationsThunk = _p.getRunningMutationsThunk, getRunningQueriesThunk = _p.getRunningQueriesThunk, getRunningQueryThunk = _p.getRunningQueryThunk, getRunningOperationPromises = _p.getRunningOperationPromises, removalWarning = _p.removalWarning;
|
2130 | safeAssign(api.util, {
|
2131 | getRunningOperationPromises: getRunningOperationPromises,
|
2132 | getRunningOperationPromise: removalWarning,
|
2133 | getRunningMutationThunk: getRunningMutationThunk,
|
2134 | getRunningMutationsThunk: getRunningMutationsThunk,
|
2135 | getRunningQueryThunk: getRunningQueryThunk,
|
2136 | getRunningQueriesThunk: getRunningQueriesThunk
|
2137 | });
|
2138 | return {
|
2139 | name: coreModuleName,
|
2140 | injectEndpoint: function (endpointName, definition) {
|
2141 | var _a, _b;
|
2142 | var anyApi = api;
|
2143 | (_b = (_a = anyApi.endpoints)[endpointName]) != null ? _b : _a[endpointName] = {};
|
2144 | if (isQueryDefinition(definition)) {
|
2145 | safeAssign(anyApi.endpoints[endpointName], {
|
2146 | name: endpointName,
|
2147 | select: buildQuerySelector(endpointName, definition),
|
2148 | initiate: buildInitiateQuery(endpointName, definition)
|
2149 | }, buildMatchThunkActions(queryThunk, endpointName));
|
2150 | }
|
2151 | else if (isMutationDefinition(definition)) {
|
2152 | safeAssign(anyApi.endpoints[endpointName], {
|
2153 | name: endpointName,
|
2154 | select: buildMutationSelector(),
|
2155 | initiate: buildInitiateMutation(endpointName)
|
2156 | }, buildMatchThunkActions(mutationThunk, endpointName));
|
2157 | }
|
2158 | }
|
2159 | };
|
2160 | }
|
2161 | }); };
|
2162 |
|
2163 | var createApi = buildCreateApi(coreModule());
|
2164 | export { QueryStatus, buildCreateApi, copyWithStructuralSharing, coreModule, createApi, defaultSerializeQueryArgs, fakeBaseQuery, fetchBaseQuery, retry, setupListeners, skipSelector, skipToken };
|
2165 |
|
\ | No newline at end of file |