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 _i = 0, _e = __getOwnPropSymbols(b); _i < _e.length; _i++) {
|
46 | var prop = _e[_i];
|
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 _i = 0, _e = __getOwnPropSymbols(source); _i < _e.length; _i++) {
|
60 | var prop = _e[_i];
|
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 | base = withoutTrailingSlash(base);
|
123 | url = withoutLeadingSlash(url);
|
124 | return base + "/" + url;
|
125 | }
|
126 |
|
127 | var flatten = function (arr) { return [].concat.apply([], arr); };
|
128 |
|
129 | function isOnline() {
|
130 | return typeof navigator === "undefined" ? true : navigator.onLine === void 0 ? true : navigator.onLine;
|
131 | }
|
132 |
|
133 | function isDocumentVisible() {
|
134 | if (typeof document === "undefined") {
|
135 | return true;
|
136 | }
|
137 | return document.visibilityState !== "hidden";
|
138 | }
|
139 |
|
140 | import { isPlainObject as _iPO } from "@reduxjs/toolkit";
|
141 | var isPlainObject = _iPO;
|
142 | function copyWithStructuralSharing(oldObj, newObj) {
|
143 | if (oldObj === newObj || !(isPlainObject(oldObj) && isPlainObject(newObj) || Array.isArray(oldObj) && Array.isArray(newObj))) {
|
144 | return newObj;
|
145 | }
|
146 | var newKeys = Object.keys(newObj);
|
147 | var oldKeys = Object.keys(oldObj);
|
148 | var isSameObject = newKeys.length === oldKeys.length;
|
149 | var mergeObj = Array.isArray(newObj) ? [] : {};
|
150 | for (var _i = 0, newKeys_1 = newKeys; _i < newKeys_1.length; _i++) {
|
151 | var key = newKeys_1[_i];
|
152 | mergeObj[key] = copyWithStructuralSharing(oldObj[key], newObj[key]);
|
153 | if (isSameObject)
|
154 | isSameObject = oldObj[key] === mergeObj[key];
|
155 | }
|
156 | return isSameObject ? oldObj : mergeObj;
|
157 | }
|
158 |
|
159 | import { isPlainObject as isPlainObject2 } from "@reduxjs/toolkit";
|
160 | var defaultFetchFn = function () {
|
161 | var args = [];
|
162 | for (var _i = 0; _i < arguments.length; _i++) {
|
163 | args[_i] = arguments[_i];
|
164 | }
|
165 | return fetch.apply(void 0, args);
|
166 | };
|
167 | var defaultValidateStatus = function (response) { return response.status >= 200 && response.status <= 299; };
|
168 | var isJsonContentType = function (headers) {
|
169 | var _a, _b;
|
170 | return (_b = (_a = headers.get("content-type")) == null ? void 0 : _a.trim()) == null ? void 0 : _b.startsWith("application/json");
|
171 | };
|
172 | var handleResponse = function (response, responseHandler) { return __async(void 0, null, function () {
|
173 | var text;
|
174 | return __generator(this, function (_e) {
|
175 | switch (_e.label) {
|
176 | case 0:
|
177 | if (typeof responseHandler === "function") {
|
178 | return [2 , responseHandler(response)];
|
179 | }
|
180 | if (responseHandler === "text") {
|
181 | return [2 , response.text()];
|
182 | }
|
183 | if (!(responseHandler === "json")) return [3 , 2];
|
184 | return [4 , response.text()];
|
185 | case 1:
|
186 | text = _e.sent();
|
187 | return [2 , text.length ? JSON.parse(text) : void 0];
|
188 | case 2: return [2 ];
|
189 | }
|
190 | });
|
191 | }); };
|
192 | function stripUndefined(obj) {
|
193 | if (!isPlainObject2(obj)) {
|
194 | return obj;
|
195 | }
|
196 | var copy = __spreadValues({}, obj);
|
197 | for (var _i = 0, _e = Object.entries(copy); _i < _e.length; _i++) {
|
198 | var _f = _e[_i], k = _f[0], v = _f[1];
|
199 | if (typeof v === "undefined")
|
200 | delete copy[k];
|
201 | }
|
202 | return copy;
|
203 | }
|
204 | function fetchBaseQuery(_a) {
|
205 | var _this = this;
|
206 | if (_a === void 0) { _a = {}; }
|
207 | var _b = _a, baseUrl = _b.baseUrl, _e = _b.prepareHeaders, prepareHeaders = _e === void 0 ? function (x) { return x; } : _e, _f = _b.fetchFn, fetchFn = _f === void 0 ? defaultFetchFn : _f, baseFetchOptions = __objRest(_b, [
|
208 | "baseUrl",
|
209 | "prepareHeaders",
|
210 | "fetchFn"
|
211 | ]);
|
212 | if (typeof fetch === "undefined" && fetchFn === defaultFetchFn) {
|
213 | console.warn("Warning: `fetch` is not available. Please supply a custom `fetchFn` property to use `fetchBaseQuery` on SSR environments.");
|
214 | }
|
215 | return function (_0, _1) { return __async(_this, [_0, _1], function (arg, _e) {
|
216 | var meta, _a2, url, _f, method, _g, headers, _h, body, _j, params, _k, responseHandler, _l, validateStatus, rest, config, _m, isJsonifiable, divider, query, request, requestClone, response, e_1, responseClone, resultData, responseText, handleResponseError_1, e_2;
|
217 | var signal = _e.signal, getState = _e.getState;
|
218 | return __generator(this, function (_o) {
|
219 | switch (_o.label) {
|
220 | case 0:
|
221 | _a2 = typeof arg == "string" ? { url: arg } : arg, url = _a2.url, _f = _a2.method, method = _f === void 0 ? "GET" : _f, _g = _a2.headers, headers = _g === void 0 ? new Headers({}) : _g, _h = _a2.body, body = _h === void 0 ? void 0 : _h, _j = _a2.params, params = _j === void 0 ? void 0 : _j, _k = _a2.responseHandler, responseHandler = _k === void 0 ? "json" : _k, _l = _a2.validateStatus, validateStatus = _l === void 0 ? defaultValidateStatus : _l, rest = __objRest(_a2, [
|
222 | "url",
|
223 | "method",
|
224 | "headers",
|
225 | "body",
|
226 | "params",
|
227 | "responseHandler",
|
228 | "validateStatus"
|
229 | ]);
|
230 | config = __spreadValues(__spreadProps(__spreadValues({}, baseFetchOptions), {
|
231 | method: method,
|
232 | signal: signal,
|
233 | body: body
|
234 | }), rest);
|
235 | _m = config;
|
236 | return [4 , prepareHeaders(new Headers(stripUndefined(headers)), { getState: getState })];
|
237 | case 1:
|
238 | _m.headers = _o.sent();
|
239 | isJsonifiable = function (body2) { return typeof body2 === "object" && (isPlainObject2(body2) || Array.isArray(body2) || typeof body2.toJSON === "function"); };
|
240 | if (!config.headers.has("content-type") && isJsonifiable(body)) {
|
241 | config.headers.set("content-type", "application/json");
|
242 | }
|
243 | if (body && isJsonContentType(config.headers)) {
|
244 | config.body = JSON.stringify(body);
|
245 | }
|
246 | if (params) {
|
247 | divider = ~url.indexOf("?") ? "&" : "?";
|
248 | query = new URLSearchParams(stripUndefined(params));
|
249 | url += divider + query;
|
250 | }
|
251 | url = joinUrls(baseUrl, url);
|
252 | request = new Request(url, config);
|
253 | requestClone = request.clone();
|
254 | meta = { request: requestClone };
|
255 | _o.label = 2;
|
256 | case 2:
|
257 | _o.trys.push([2, 4, , 5]);
|
258 | return [4 , fetchFn(request)];
|
259 | case 3:
|
260 | response = _o.sent();
|
261 | return [3 , 5];
|
262 | case 4:
|
263 | e_1 = _o.sent();
|
264 | return [2 , { error: { status: "FETCH_ERROR", error: String(e_1) }, meta: meta }];
|
265 | case 5:
|
266 | responseClone = response.clone();
|
267 | meta.response = responseClone;
|
268 | responseText = "";
|
269 | _o.label = 6;
|
270 | case 6:
|
271 | _o.trys.push([6, 8, , 9]);
|
272 | return [4 , Promise.all([
|
273 | handleResponse(response, responseHandler).then(function (r) { return resultData = r; }, function (e) { return handleResponseError_1 = e; }),
|
274 | responseClone.text().then(function (r) { return responseText = r; }, function () {
|
275 | })
|
276 | ])];
|
277 | case 7:
|
278 | _o.sent();
|
279 | if (handleResponseError_1)
|
280 | throw handleResponseError_1;
|
281 | return [3 , 9];
|
282 | case 8:
|
283 | e_2 = _o.sent();
|
284 | return [2 , {
|
285 | error: {
|
286 | status: "PARSING_ERROR",
|
287 | originalStatus: response.status,
|
288 | data: responseText,
|
289 | error: String(e_2)
|
290 | },
|
291 | meta: meta
|
292 | }];
|
293 | case 9: return [2 , validateStatus(response, resultData) ? {
|
294 | data: resultData,
|
295 | meta: meta
|
296 | } : {
|
297 | error: {
|
298 | status: response.status,
|
299 | data: resultData
|
300 | },
|
301 | meta: meta
|
302 | }];
|
303 | }
|
304 | });
|
305 | }); };
|
306 | }
|
307 |
|
308 | var HandledError = (function () {
|
309 | function HandledError(value, meta) {
|
310 | if (meta === void 0) { meta = void 0; }
|
311 | this.value = value;
|
312 | this.meta = meta;
|
313 | }
|
314 | return HandledError;
|
315 | }());
|
316 |
|
317 | function defaultBackoff(attempt, maxRetries) {
|
318 | if (attempt === void 0) { attempt = 0; }
|
319 | if (maxRetries === void 0) { maxRetries = 5; }
|
320 | return __async(this, null, function () {
|
321 | var attempts, timeout;
|
322 | return __generator(this, function (_e) {
|
323 | switch (_e.label) {
|
324 | case 0:
|
325 | attempts = Math.min(attempt, maxRetries);
|
326 | timeout = ~~((Math.random() + 0.4) * (300 << attempts));
|
327 | return [4 , new Promise(function (resolve) { return setTimeout(function (res) { return resolve(res); }, timeout); })];
|
328 | case 1:
|
329 | _e.sent();
|
330 | return [2 ];
|
331 | }
|
332 | });
|
333 | });
|
334 | }
|
335 | function fail(e) {
|
336 | throw Object.assign(new HandledError({ error: e }), {
|
337 | throwImmediately: true
|
338 | });
|
339 | }
|
340 | var retryWithBackoff = function (baseQuery, defaultOptions) { return function (args, api, extraOptions) { return __async(void 0, null, function () {
|
341 | var options, retry2, result, e_3;
|
342 | return __generator(this, function (_e) {
|
343 | switch (_e.label) {
|
344 | case 0:
|
345 | options = __spreadValues(__spreadValues({
|
346 | maxRetries: 5,
|
347 | backoff: defaultBackoff
|
348 | }, defaultOptions), extraOptions);
|
349 | retry2 = 0;
|
350 | _e.label = 1;
|
351 | case 1:
|
352 | if (!true) return [3 , 7];
|
353 | _e.label = 2;
|
354 | case 2:
|
355 | _e.trys.push([2, 4, , 6]);
|
356 | return [4 , baseQuery(args, api, extraOptions)];
|
357 | case 3:
|
358 | result = _e.sent();
|
359 | if (result.error) {
|
360 | throw new HandledError(result);
|
361 | }
|
362 | return [2 , result];
|
363 | case 4:
|
364 | e_3 = _e.sent();
|
365 | retry2++;
|
366 | if (e_3.throwImmediately || retry2 > options.maxRetries) {
|
367 | if (e_3 instanceof HandledError) {
|
368 | return [2 , e_3.value];
|
369 | }
|
370 | throw e_3;
|
371 | }
|
372 | return [4 , options.backoff(retry2, options.maxRetries)];
|
373 | case 5:
|
374 | _e.sent();
|
375 | return [3 , 6];
|
376 | case 6: return [3 , 1];
|
377 | case 7: return [2 ];
|
378 | }
|
379 | });
|
380 | }); }; };
|
381 | var retry = Object.assign(retryWithBackoff, { fail: fail });
|
382 |
|
383 | import { createAction } from "@reduxjs/toolkit";
|
384 | var onFocus = createAction("__rtkq/focused");
|
385 | var onFocusLost = createAction("__rtkq/unfocused");
|
386 | var onOnline = createAction("__rtkq/online");
|
387 | var onOffline = createAction("__rtkq/offline");
|
388 | var initialized = false;
|
389 | function setupListeners(dispatch, customHandler) {
|
390 | function defaultHandler() {
|
391 | var handleFocus = function () { return dispatch(onFocus()); };
|
392 | var handleFocusLost = function () { return dispatch(onFocusLost()); };
|
393 | var handleOnline = function () { return dispatch(onOnline()); };
|
394 | var handleOffline = function () { return dispatch(onOffline()); };
|
395 | var handleVisibilityChange = function () {
|
396 | if (window.document.visibilityState === "visible") {
|
397 | handleFocus();
|
398 | }
|
399 | else {
|
400 | handleFocusLost();
|
401 | }
|
402 | };
|
403 | if (!initialized) {
|
404 | if (typeof window !== "undefined" && window.addEventListener) {
|
405 | window.addEventListener("visibilitychange", handleVisibilityChange, false);
|
406 | window.addEventListener("focus", handleFocus, false);
|
407 | window.addEventListener("online", handleOnline, false);
|
408 | window.addEventListener("offline", handleOffline, false);
|
409 | initialized = true;
|
410 | }
|
411 | }
|
412 | var unsubscribe = function () {
|
413 | window.removeEventListener("focus", handleFocus);
|
414 | window.removeEventListener("visibilitychange", handleVisibilityChange);
|
415 | window.removeEventListener("online", handleOnline);
|
416 | window.removeEventListener("offline", handleOffline);
|
417 | initialized = false;
|
418 | };
|
419 | return unsubscribe;
|
420 | }
|
421 | return customHandler ? customHandler(dispatch, { onFocus: onFocus, onFocusLost: onFocusLost, onOffline: onOffline, onOnline: onOnline }) : defaultHandler();
|
422 | }
|
423 |
|
424 | import { createNextState, createSelector } from "@reduxjs/toolkit";
|
425 | var skipToken = Symbol.for("RTKQ/skipToken");
|
426 | var skipSelector = skipToken;
|
427 | var initialSubState = {
|
428 | status: QueryStatus.uninitialized
|
429 | };
|
430 | var defaultQuerySubState = createNextState(initialSubState, function () {
|
431 | });
|
432 | var defaultMutationSubState = createNextState(initialSubState, function () {
|
433 | });
|
434 | function buildSelectors(_e) {
|
435 | var serializeQueryArgs = _e.serializeQueryArgs, reducerPath = _e.reducerPath;
|
436 | return { buildQuerySelector: buildQuerySelector, buildMutationSelector: buildMutationSelector };
|
437 | function withRequestFlags(substate) {
|
438 | return __spreadValues(__spreadValues({}, substate), getRequestStatusFlags(substate.status));
|
439 | }
|
440 | function selectInternalState(rootState) {
|
441 | var state = rootState[reducerPath];
|
442 | if (process.env.NODE_ENV !== "production") {
|
443 | if (!state) {
|
444 | if (selectInternalState.triggered)
|
445 | return state;
|
446 | selectInternalState.triggered = true;
|
447 | console.error("Error: No data found at `state." + reducerPath + "`. Did you forget to add the reducer to the store?");
|
448 | }
|
449 | }
|
450 | return state;
|
451 | }
|
452 | function buildQuerySelector(endpointName, endpointDefinition) {
|
453 | return function (queryArgs) {
|
454 | var selectQuerySubState = createSelector(selectInternalState, function (internalState) {
|
455 | var _a, _b;
|
456 | return (_b = queryArgs === skipToken ? void 0 : (_a = internalState == null ? void 0 : internalState.queries) == null ? void 0 : _a[serializeQueryArgs({
|
457 | queryArgs: queryArgs,
|
458 | endpointDefinition: endpointDefinition,
|
459 | endpointName: endpointName
|
460 | })]) != null ? _b : defaultQuerySubState;
|
461 | });
|
462 | return createSelector(selectQuerySubState, withRequestFlags);
|
463 | };
|
464 | }
|
465 | function buildMutationSelector() {
|
466 | return function (mutationId) {
|
467 | var selectMutationSubstate = createSelector(selectInternalState, function (internalState) {
|
468 | var _a, _b;
|
469 | return (_b = mutationId === skipToken ? void 0 : (_a = internalState == null ? void 0 : internalState.mutations) == null ? void 0 : _a[mutationId]) != null ? _b : defaultMutationSubState;
|
470 | });
|
471 | return createSelector(selectMutationSubstate, withRequestFlags);
|
472 | };
|
473 | }
|
474 | }
|
475 |
|
476 | import { isPlainObject as isPlainObject3 } from "@reduxjs/toolkit";
|
477 | var defaultSerializeQueryArgs = function (_e) {
|
478 | var endpointName = _e.endpointName, queryArgs = _e.queryArgs;
|
479 | return endpointName + "(" + JSON.stringify(queryArgs, function (key, value) { return isPlainObject3(value) ? Object.keys(value).sort().reduce(function (acc, key2) {
|
480 | acc[key2] = value[key2];
|
481 | return acc;
|
482 | }, {}) : value; }) + ")";
|
483 | };
|
484 |
|
485 | var DefinitionType;
|
486 | (function (DefinitionType2) {
|
487 | DefinitionType2["query"] = "query";
|
488 | DefinitionType2["mutation"] = "mutation";
|
489 | })(DefinitionType || (DefinitionType = {}));
|
490 | function isQueryDefinition(e) {
|
491 | return e.type === DefinitionType.query;
|
492 | }
|
493 | function isMutationDefinition(e) {
|
494 | return e.type === DefinitionType.mutation;
|
495 | }
|
496 | function calculateProvidedBy(description, result, error, queryArg, assertTagTypes) {
|
497 | if (isFunction(description)) {
|
498 | return description(result, error, queryArg).map(expandTagDescription).map(assertTagTypes);
|
499 | }
|
500 | if (Array.isArray(description)) {
|
501 | return description.map(expandTagDescription).map(assertTagTypes);
|
502 | }
|
503 | return [];
|
504 | }
|
505 | function isFunction(t) {
|
506 | return typeof t === "function";
|
507 | }
|
508 | function expandTagDescription(description) {
|
509 | return typeof description === "string" ? { type: description } : description;
|
510 | }
|
511 |
|
512 | import { nanoid } from "@reduxjs/toolkit";
|
513 | function buildCreateApi() {
|
514 | var modules = [];
|
515 | for (var _i = 0; _i < arguments.length; _i++) {
|
516 | modules[_i] = arguments[_i];
|
517 | }
|
518 | return function baseCreateApi(options) {
|
519 | var optionsWithDefaults = __spreadProps(__spreadValues({
|
520 | reducerPath: "api",
|
521 | serializeQueryArgs: defaultSerializeQueryArgs,
|
522 | keepUnusedDataFor: 60,
|
523 | refetchOnMountOrArgChange: false,
|
524 | refetchOnFocus: false,
|
525 | refetchOnReconnect: false
|
526 | }, options), {
|
527 | tagTypes: __spreadArray([], options.tagTypes || [])
|
528 | });
|
529 | var context = {
|
530 | endpointDefinitions: {},
|
531 | batch: function (fn) {
|
532 | fn();
|
533 | },
|
534 | apiUid: nanoid()
|
535 | };
|
536 | var api = {
|
537 | injectEndpoints: injectEndpoints,
|
538 | enhanceEndpoints: function (_e) {
|
539 | var addTagTypes = _e.addTagTypes, endpoints = _e.endpoints;
|
540 | if (addTagTypes) {
|
541 | for (var _i = 0, addTagTypes_1 = addTagTypes; _i < addTagTypes_1.length; _i++) {
|
542 | var eT = addTagTypes_1[_i];
|
543 | if (!optionsWithDefaults.tagTypes.includes(eT)) {
|
544 | optionsWithDefaults.tagTypes.push(eT);
|
545 | }
|
546 | }
|
547 | }
|
548 | if (endpoints) {
|
549 | for (var _f = 0, _g = Object.entries(endpoints); _f < _g.length; _f++) {
|
550 | var _h = _g[_f], endpointName = _h[0], partialDefinition = _h[1];
|
551 | if (typeof partialDefinition === "function") {
|
552 | partialDefinition(context.endpointDefinitions[endpointName]);
|
553 | }
|
554 | Object.assign(context.endpointDefinitions[endpointName] || {}, partialDefinition);
|
555 | }
|
556 | }
|
557 | return api;
|
558 | }
|
559 | };
|
560 | var initializedModules = modules.map(function (m) { return m.init(api, optionsWithDefaults, context); });
|
561 | function injectEndpoints(inject) {
|
562 | var evaluatedEndpoints = inject.endpoints({
|
563 | query: function (x) { return __spreadProps(__spreadValues({}, x), { type: DefinitionType.query }); },
|
564 | mutation: function (x) { return __spreadProps(__spreadValues({}, x), { type: DefinitionType.mutation }); }
|
565 | });
|
566 | for (var _i = 0, _e = Object.entries(evaluatedEndpoints); _i < _e.length; _i++) {
|
567 | var _f = _e[_i], endpointName = _f[0], definition = _f[1];
|
568 | if (!inject.overrideExisting && endpointName in context.endpointDefinitions) {
|
569 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
570 | console.error("called `injectEndpoints` to override already-existing endpointName " + endpointName + " without specifying `overrideExisting: true`");
|
571 | }
|
572 | continue;
|
573 | }
|
574 | context.endpointDefinitions[endpointName] = definition;
|
575 | for (var _g = 0, initializedModules_1 = initializedModules; _g < initializedModules_1.length; _g++) {
|
576 | var m = initializedModules_1[_g];
|
577 | m.injectEndpoint(endpointName, definition);
|
578 | }
|
579 | }
|
580 | return api;
|
581 | }
|
582 | return api.injectEndpoints({ endpoints: options.endpoints });
|
583 | };
|
584 | }
|
585 |
|
586 | function fakeBaseQuery() {
|
587 | return function () {
|
588 | throw new Error("When using `fakeBaseQuery`, all queries & mutations must use the `queryFn` definition syntax.");
|
589 | };
|
590 | }
|
591 |
|
592 | import { isAllOf, isFulfilled, isPending, isRejected, isRejectedWithValue } from "@reduxjs/toolkit";
|
593 | import { isDraftable, produceWithPatches } from "immer";
|
594 | import { createAsyncThunk } from "@reduxjs/toolkit";
|
595 | function defaultTransformResponse(baseQueryReturnValue) {
|
596 | return baseQueryReturnValue;
|
597 | }
|
598 | function buildThunks(_e) {
|
599 | var _this = this;
|
600 | var reducerPath = _e.reducerPath, baseQuery = _e.baseQuery, endpointDefinitions = _e.context.endpointDefinitions, serializeQueryArgs = _e.serializeQueryArgs, api = _e.api;
|
601 | var patchQueryData = function (endpointName, args, patches) { return function (dispatch) {
|
602 | var endpointDefinition = endpointDefinitions[endpointName];
|
603 | dispatch(api.internalActions.queryResultPatched({
|
604 | queryCacheKey: serializeQueryArgs({
|
605 | queryArgs: args,
|
606 | endpointDefinition: endpointDefinition,
|
607 | endpointName: endpointName
|
608 | }),
|
609 | patches: patches
|
610 | }));
|
611 | }; };
|
612 | var updateQueryData = function (endpointName, args, updateRecipe) { return function (dispatch, getState) {
|
613 | var _e, _f;
|
614 | var currentState = api.endpoints[endpointName].select(args)(getState());
|
615 | var ret = {
|
616 | patches: [],
|
617 | inversePatches: [],
|
618 | undo: function () { return dispatch(api.util.patchQueryData(endpointName, args, ret.inversePatches)); }
|
619 | };
|
620 | if (currentState.status === QueryStatus.uninitialized) {
|
621 | return ret;
|
622 | }
|
623 | if ("data" in currentState) {
|
624 | if (isDraftable(currentState.data)) {
|
625 | var _g = produceWithPatches(currentState.data, updateRecipe), patches = _g[1], inversePatches = _g[2];
|
626 | (_e = ret.patches).push.apply(_e, patches);
|
627 | (_f = ret.inversePatches).push.apply(_f, inversePatches);
|
628 | }
|
629 | else {
|
630 | var value = updateRecipe(currentState.data);
|
631 | ret.patches.push({ op: "replace", path: [], value: value });
|
632 | ret.inversePatches.push({
|
633 | op: "replace",
|
634 | path: [],
|
635 | value: currentState.data
|
636 | });
|
637 | }
|
638 | }
|
639 | dispatch(api.util.patchQueryData(endpointName, args, ret.patches));
|
640 | return ret;
|
641 | }; };
|
642 | var executeEndpoint = function (_0, _1) { return __async(_this, [_0, _1], function (arg, _e) {
|
643 | var endpointDefinition, transformResponse, result, baseQueryApi_1, _f, error_1;
|
644 | var signal = _e.signal, rejectWithValue = _e.rejectWithValue, fulfillWithValue = _e.fulfillWithValue, dispatch = _e.dispatch, getState = _e.getState, extra = _e.extra;
|
645 | return __generator(this, function (_g) {
|
646 | switch (_g.label) {
|
647 | case 0:
|
648 | endpointDefinition = endpointDefinitions[arg.endpointName];
|
649 | _g.label = 1;
|
650 | case 1:
|
651 | _g.trys.push([1, 7, , 8]);
|
652 | transformResponse = defaultTransformResponse;
|
653 | result = void 0;
|
654 | baseQueryApi_1 = {
|
655 | signal: signal,
|
656 | dispatch: dispatch,
|
657 | getState: getState,
|
658 | extra: extra
|
659 | };
|
660 | if (!endpointDefinition.query) return [3 , 3];
|
661 | return [4 , baseQuery(endpointDefinition.query(arg.originalArgs), baseQueryApi_1, endpointDefinition.extraOptions)];
|
662 | case 2:
|
663 | result = _g.sent();
|
664 | if (endpointDefinition.transformResponse) {
|
665 | transformResponse = endpointDefinition.transformResponse;
|
666 | }
|
667 | return [3 , 5];
|
668 | case 3: return [4 , endpointDefinition.queryFn(arg.originalArgs, baseQueryApi_1, endpointDefinition.extraOptions, function (arg2) { return baseQuery(arg2, baseQueryApi_1, endpointDefinition.extraOptions); })];
|
669 | case 4:
|
670 | result = _g.sent();
|
671 | _g.label = 5;
|
672 | case 5:
|
673 | if (result.error)
|
674 | throw new HandledError(result.error, result.meta);
|
675 | _f = fulfillWithValue;
|
676 | return [4 , transformResponse(result.data, result.meta)];
|
677 | case 6: return [2 , _f.apply(void 0, [_g.sent(), {
|
678 | fulfilledTimeStamp: Date.now(),
|
679 | baseQueryMeta: result.meta
|
680 | }])];
|
681 | case 7:
|
682 | error_1 = _g.sent();
|
683 | if (error_1 instanceof HandledError) {
|
684 | return [2 , rejectWithValue(error_1.value, { baseQueryMeta: error_1.meta })];
|
685 | }
|
686 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
687 | console.error("An unhandled error occured processing a request for the endpoint \"" + arg.endpointName + "\".\nIn the case of an unhandled error, no tags will be \"provided\" or \"invalidated\".", error_1);
|
688 | }
|
689 | else {
|
690 | console.error(error_1);
|
691 | }
|
692 | throw error_1;
|
693 | case 8: return [2 ];
|
694 | }
|
695 | });
|
696 | }); };
|
697 | var queryThunk = createAsyncThunk(reducerPath + "/executeQuery", executeEndpoint, {
|
698 | getPendingMeta: function () {
|
699 | return { startedTimeStamp: Date.now() };
|
700 | },
|
701 | condition: function (arg, _e) {
|
702 | var getState = _e.getState;
|
703 | var _a, _b;
|
704 | var state = getState()[reducerPath];
|
705 | var requestState = (_a = state == null ? void 0 : state.queries) == null ? void 0 : _a[arg.queryCacheKey];
|
706 | var baseFetchOnMountOrArgChange = state.config.refetchOnMountOrArgChange;
|
707 | var fulfilledVal = requestState == null ? void 0 : requestState.fulfilledTimeStamp;
|
708 | var refetchVal = (_b = arg.forceRefetch) != null ? _b : arg.subscribe && baseFetchOnMountOrArgChange;
|
709 | if ((requestState == null ? void 0 : requestState.status) === "pending")
|
710 | return false;
|
711 | if (fulfilledVal) {
|
712 | if (refetchVal) {
|
713 | return refetchVal === true || (Number(new Date()) - Number(fulfilledVal)) / 1e3 >= refetchVal;
|
714 | }
|
715 | return false;
|
716 | }
|
717 | return true;
|
718 | },
|
719 | dispatchConditionRejection: true
|
720 | });
|
721 | var mutationThunk = createAsyncThunk(reducerPath + "/executeMutation", executeEndpoint, {
|
722 | getPendingMeta: function () {
|
723 | return { startedTimeStamp: Date.now() };
|
724 | }
|
725 | });
|
726 | var hasTheForce = function (options) { return "force" in options; };
|
727 | var hasMaxAge = function (options) { return "ifOlderThan" in options; };
|
728 | var prefetch = function (endpointName, arg, options) { return function (dispatch, getState) {
|
729 | var force = hasTheForce(options) && options.force;
|
730 | var maxAge = hasMaxAge(options) && options.ifOlderThan;
|
731 | var queryAction = function (force2) {
|
732 | if (force2 === void 0) { force2 = true; }
|
733 | return api.endpoints[endpointName].initiate(arg, { forceRefetch: force2 });
|
734 | };
|
735 | var latestStateValue = api.endpoints[endpointName].select(arg)(getState());
|
736 | if (force) {
|
737 | dispatch(queryAction());
|
738 | }
|
739 | else if (maxAge) {
|
740 | var lastFulfilledTs = latestStateValue == null ? void 0 : latestStateValue.fulfilledTimeStamp;
|
741 | if (!lastFulfilledTs) {
|
742 | dispatch(queryAction());
|
743 | return;
|
744 | }
|
745 | var shouldRetrigger = (Number(new Date()) - Number(new Date(lastFulfilledTs))) / 1e3 >= maxAge;
|
746 | if (shouldRetrigger) {
|
747 | dispatch(queryAction());
|
748 | }
|
749 | }
|
750 | else {
|
751 | dispatch(queryAction(false));
|
752 | }
|
753 | }; };
|
754 | function matchesEndpoint(endpointName) {
|
755 | return function (action) {
|
756 | var _a, _b;
|
757 | return ((_b = (_a = action == null ? void 0 : action.meta) == null ? void 0 : _a.arg) == null ? void 0 : _b.endpointName) === endpointName;
|
758 | };
|
759 | }
|
760 | function buildMatchThunkActions(thunk, endpointName) {
|
761 | return {
|
762 | matchPending: isAllOf(isPending(thunk), matchesEndpoint(endpointName)),
|
763 | matchFulfilled: isAllOf(isFulfilled(thunk), matchesEndpoint(endpointName)),
|
764 | matchRejected: isAllOf(isRejected(thunk), matchesEndpoint(endpointName))
|
765 | };
|
766 | }
|
767 | return {
|
768 | queryThunk: queryThunk,
|
769 | mutationThunk: mutationThunk,
|
770 | prefetch: prefetch,
|
771 | updateQueryData: updateQueryData,
|
772 | patchQueryData: patchQueryData,
|
773 | buildMatchThunkActions: buildMatchThunkActions
|
774 | };
|
775 | }
|
776 | function calculateProvidedByThunk(action, type, endpointDefinitions, assertTagType) {
|
777 | return calculateProvidedBy(endpointDefinitions[action.meta.arg.endpointName][type], isFulfilled(action) ? action.payload : void 0, isRejectedWithValue(action) ? action.payload : void 0, action.meta.arg.originalArgs, assertTagType);
|
778 | }
|
779 |
|
780 | import { combineReducers, createAction as createAction2, createSlice, isAnyOf, isFulfilled as isFulfilled2, isRejectedWithValue as isRejectedWithValue2 } from "@reduxjs/toolkit";
|
781 | import { applyPatches } from "immer";
|
782 | function updateQuerySubstateIfExists(state, queryCacheKey, update) {
|
783 | var substate = state[queryCacheKey];
|
784 | if (substate) {
|
785 | update(substate);
|
786 | }
|
787 | }
|
788 | function updateMutationSubstateIfExists(state, _e, update) {
|
789 | var requestId = _e.requestId;
|
790 | var substate = state[requestId];
|
791 | if (substate) {
|
792 | update(substate);
|
793 | }
|
794 | }
|
795 | var initialState = {};
|
796 | function buildSlice(_e) {
|
797 | var reducerPath = _e.reducerPath, queryThunk = _e.queryThunk, mutationThunk = _e.mutationThunk, _f = _e.context, definitions = _f.endpointDefinitions, apiUid = _f.apiUid, assertTagType = _e.assertTagType, config = _e.config;
|
798 | var resetApiState = createAction2(reducerPath + "/resetApiState");
|
799 | var querySlice = createSlice({
|
800 | name: reducerPath + "/queries",
|
801 | initialState: initialState,
|
802 | reducers: {
|
803 | removeQueryResult: function (draft, _e) {
|
804 | var queryCacheKey = _e.payload.queryCacheKey;
|
805 | delete draft[queryCacheKey];
|
806 | },
|
807 | queryResultPatched: function (draft, _e) {
|
808 | var _f = _e.payload, queryCacheKey = _f.queryCacheKey, patches = _f.patches;
|
809 | updateQuerySubstateIfExists(draft, queryCacheKey, function (substate) {
|
810 | substate.data = applyPatches(substate.data, patches.concat());
|
811 | });
|
812 | }
|
813 | },
|
814 | extraReducers: function (builder) {
|
815 | builder.addCase(queryThunk.pending, function (draft, _e) {
|
816 | var meta = _e.meta, arg = _e.meta.arg;
|
817 | var _a, _b;
|
818 | if (arg.subscribe) {
|
819 | (_b = draft[_a = arg.queryCacheKey]) != null ? _b : draft[_a] = {
|
820 | status: QueryStatus.uninitialized,
|
821 | endpointName: arg.endpointName
|
822 | };
|
823 | }
|
824 | updateQuerySubstateIfExists(draft, arg.queryCacheKey, function (substate) {
|
825 | substate.status = QueryStatus.pending;
|
826 | substate.requestId = meta.requestId;
|
827 | substate.originalArgs = arg.originalArgs;
|
828 | substate.startedTimeStamp = meta.startedTimeStamp;
|
829 | });
|
830 | }).addCase(queryThunk.fulfilled, function (draft, _e) {
|
831 | var meta = _e.meta, payload = _e.payload;
|
832 | updateQuerySubstateIfExists(draft, meta.arg.queryCacheKey, function (substate) {
|
833 | if (substate.requestId !== meta.requestId)
|
834 | return;
|
835 | substate.status = QueryStatus.fulfilled;
|
836 | substate.data = copyWithStructuralSharing(substate.data, payload);
|
837 | delete substate.error;
|
838 | substate.fulfilledTimeStamp = meta.fulfilledTimeStamp;
|
839 | });
|
840 | }).addCase(queryThunk.rejected, function (draft, _e) {
|
841 | var _f = _e.meta, condition = _f.condition, arg = _f.arg, requestId = _f.requestId, error = _e.error, payload = _e.payload;
|
842 | updateQuerySubstateIfExists(draft, arg.queryCacheKey, function (substate) {
|
843 | if (condition) {
|
844 | }
|
845 | else {
|
846 | if (substate.requestId !== requestId)
|
847 | return;
|
848 | substate.status = QueryStatus.rejected;
|
849 | substate.error = payload != null ? payload : error;
|
850 | }
|
851 | });
|
852 | });
|
853 | }
|
854 | });
|
855 | var mutationSlice = createSlice({
|
856 | name: reducerPath + "/mutations",
|
857 | initialState: initialState,
|
858 | reducers: {
|
859 | unsubscribeMutationResult: function (draft, action) {
|
860 | if (action.payload.requestId in draft) {
|
861 | delete draft[action.payload.requestId];
|
862 | }
|
863 | }
|
864 | },
|
865 | extraReducers: function (builder) {
|
866 | builder.addCase(mutationThunk.pending, function (draft, _e) {
|
867 | var _f = _e.meta, arg = _f.arg, requestId = _f.requestId, startedTimeStamp = _f.startedTimeStamp;
|
868 | if (!arg.track)
|
869 | return;
|
870 | draft[requestId] = {
|
871 | status: QueryStatus.pending,
|
872 | endpointName: arg.endpointName,
|
873 | startedTimeStamp: startedTimeStamp
|
874 | };
|
875 | }).addCase(mutationThunk.fulfilled, function (draft, _e) {
|
876 | var payload = _e.payload, meta = _e.meta, requestId = _e.meta.requestId;
|
877 | if (!meta.arg.track)
|
878 | return;
|
879 | updateMutationSubstateIfExists(draft, { requestId: requestId }, function (substate) {
|
880 | substate.status = QueryStatus.fulfilled;
|
881 | substate.data = payload;
|
882 | substate.fulfilledTimeStamp = meta.fulfilledTimeStamp;
|
883 | });
|
884 | }).addCase(mutationThunk.rejected, function (draft, _e) {
|
885 | var payload = _e.payload, error = _e.error, _f = _e.meta, requestId = _f.requestId, arg = _f.arg;
|
886 | if (!arg.track)
|
887 | return;
|
888 | updateMutationSubstateIfExists(draft, { requestId: requestId }, function (substate) {
|
889 | substate.status = QueryStatus.rejected;
|
890 | substate.error = payload != null ? payload : error;
|
891 | });
|
892 | });
|
893 | }
|
894 | });
|
895 | var invalidationSlice = createSlice({
|
896 | name: reducerPath + "/invalidation",
|
897 | initialState: initialState,
|
898 | reducers: {},
|
899 | extraReducers: function (builder) {
|
900 | builder.addCase(querySlice.actions.removeQueryResult, function (draft, _e) {
|
901 | var queryCacheKey = _e.payload.queryCacheKey;
|
902 | for (var _i = 0, _f = Object.values(draft); _i < _f.length; _i++) {
|
903 | var tagTypeSubscriptions = _f[_i];
|
904 | for (var _g = 0, _h = Object.values(tagTypeSubscriptions); _g < _h.length; _g++) {
|
905 | var idSubscriptions = _h[_g];
|
906 | var foundAt = idSubscriptions.indexOf(queryCacheKey);
|
907 | if (foundAt !== -1) {
|
908 | idSubscriptions.splice(foundAt, 1);
|
909 | }
|
910 | }
|
911 | }
|
912 | }).addMatcher(isAnyOf(isFulfilled2(queryThunk), isRejectedWithValue2(queryThunk)), function (draft, action) {
|
913 | var _a, _b, _c, _d;
|
914 | var providedTags = calculateProvidedByThunk(action, "providesTags", definitions, assertTagType);
|
915 | var queryCacheKey = action.meta.arg.queryCacheKey;
|
916 | for (var _i = 0, providedTags_1 = providedTags; _i < providedTags_1.length; _i++) {
|
917 | var _e = providedTags_1[_i], type = _e.type, id = _e.id;
|
918 | var subscribedQueries = (_d = (_b = (_a = draft[type]) != null ? _a : draft[type] = {})[_c = id || "__internal_without_id"]) != null ? _d : _b[_c] = [];
|
919 | var alreadySubscribed = subscribedQueries.includes(queryCacheKey);
|
920 | if (!alreadySubscribed) {
|
921 | subscribedQueries.push(queryCacheKey);
|
922 | }
|
923 | }
|
924 | });
|
925 | }
|
926 | });
|
927 | var subscriptionSlice = createSlice({
|
928 | name: reducerPath + "/subscriptions",
|
929 | initialState: initialState,
|
930 | reducers: {
|
931 | updateSubscriptionOptions: function (draft, _e) {
|
932 | var _f = _e.payload, queryCacheKey = _f.queryCacheKey, requestId = _f.requestId, options = _f.options;
|
933 | var _a;
|
934 | if ((_a = draft == null ? void 0 : draft[queryCacheKey]) == null ? void 0 : _a[requestId]) {
|
935 | draft[queryCacheKey][requestId] = options;
|
936 | }
|
937 | },
|
938 | unsubscribeQueryResult: function (draft, _e) {
|
939 | var _f = _e.payload, queryCacheKey = _f.queryCacheKey, requestId = _f.requestId;
|
940 | if (draft[queryCacheKey]) {
|
941 | delete draft[queryCacheKey][requestId];
|
942 | }
|
943 | }
|
944 | },
|
945 | extraReducers: function (builder) {
|
946 | builder.addCase(querySlice.actions.removeQueryResult, function (draft, _e) {
|
947 | var queryCacheKey = _e.payload.queryCacheKey;
|
948 | delete draft[queryCacheKey];
|
949 | }).addCase(queryThunk.pending, function (draft, _e) {
|
950 | var _f = _e.meta, arg = _f.arg, requestId = _f.requestId;
|
951 | var _a, _b, _c, _d;
|
952 | if (arg.subscribe) {
|
953 | var substate = (_b = draft[_a = arg.queryCacheKey]) != null ? _b : draft[_a] = {};
|
954 | substate[requestId] = (_d = (_c = arg.subscriptionOptions) != null ? _c : substate[requestId]) != null ? _d : {};
|
955 | }
|
956 | }).addCase(queryThunk.rejected, function (draft, _e) {
|
957 | var _f = _e.meta, condition = _f.condition, arg = _f.arg, requestId = _f.requestId, error = _e.error, payload = _e.payload;
|
958 | var _a, _b;
|
959 | var substate = draft[arg.queryCacheKey];
|
960 | if (condition && arg.subscribe && substate) {
|
961 | substate[requestId] = (_b = (_a = arg.subscriptionOptions) != null ? _a : substate[requestId]) != null ? _b : {};
|
962 | }
|
963 | });
|
964 | }
|
965 | });
|
966 | var configSlice = createSlice({
|
967 | name: reducerPath + "/config",
|
968 | initialState: __spreadValues({
|
969 | online: isOnline(),
|
970 | focused: isDocumentVisible(),
|
971 | middlewareRegistered: false
|
972 | }, config),
|
973 | reducers: {
|
974 | middlewareRegistered: function (state, _e) {
|
975 | var payload = _e.payload;
|
976 | state.middlewareRegistered = state.middlewareRegistered === "conflict" || apiUid !== payload ? "conflict" : true;
|
977 | }
|
978 | },
|
979 | extraReducers: function (builder) {
|
980 | builder.addCase(onOnline, function (state) {
|
981 | state.online = true;
|
982 | }).addCase(onOffline, function (state) {
|
983 | state.online = false;
|
984 | }).addCase(onFocus, function (state) {
|
985 | state.focused = true;
|
986 | }).addCase(onFocusLost, function (state) {
|
987 | state.focused = false;
|
988 | });
|
989 | }
|
990 | });
|
991 | var combinedReducer = combineReducers({
|
992 | queries: querySlice.reducer,
|
993 | mutations: mutationSlice.reducer,
|
994 | provided: invalidationSlice.reducer,
|
995 | subscriptions: subscriptionSlice.reducer,
|
996 | config: configSlice.reducer
|
997 | });
|
998 | var reducer = function (state, action) { return combinedReducer(resetApiState.match(action) ? void 0 : state, action); };
|
999 | var actions = __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, configSlice.actions), querySlice.actions), subscriptionSlice.actions), mutationSlice.actions), {
|
1000 | resetApiState: resetApiState
|
1001 | });
|
1002 | return { reducer: reducer, actions: actions };
|
1003 | }
|
1004 |
|
1005 | import { compose } from "redux";
|
1006 | import { createAction as createAction3 } from "@reduxjs/toolkit";
|
1007 |
|
1008 | var build = function (_e) {
|
1009 | var reducerPath = _e.reducerPath, api = _e.api, context = _e.context;
|
1010 | var _f = api.internalActions, removeQueryResult = _f.removeQueryResult, unsubscribeQueryResult = _f.unsubscribeQueryResult;
|
1011 | return function (mwApi) {
|
1012 | var currentRemovalTimeouts = {};
|
1013 | return function (next) { return function (action) {
|
1014 | var _a, _b;
|
1015 | var result = next(action);
|
1016 | if (unsubscribeQueryResult.match(action)) {
|
1017 | var state = mwApi.getState()[reducerPath];
|
1018 | var queryCacheKey = action.payload.queryCacheKey;
|
1019 | var endpointDefinition = context.endpointDefinitions[(_a = state.queries[queryCacheKey]) == null ? void 0 : _a.endpointName];
|
1020 | handleUnsubscribe(queryCacheKey, mwApi, (_b = endpointDefinition == null ? void 0 : endpointDefinition.keepUnusedDataFor) != null ? _b : state.config.keepUnusedDataFor);
|
1021 | }
|
1022 | if (api.util.resetApiState.match(action)) {
|
1023 | for (var _i = 0, _e = Object.entries(currentRemovalTimeouts); _i < _e.length; _i++) {
|
1024 | var _f = _e[_i], key = _f[0], timeout = _f[1];
|
1025 | if (timeout)
|
1026 | clearTimeout(timeout);
|
1027 | delete currentRemovalTimeouts[key];
|
1028 | }
|
1029 | }
|
1030 | return result;
|
1031 | }; };
|
1032 | function handleUnsubscribe(queryCacheKey, api2, keepUnusedDataFor) {
|
1033 | var currentTimeout = currentRemovalTimeouts[queryCacheKey];
|
1034 | if (currentTimeout) {
|
1035 | clearTimeout(currentTimeout);
|
1036 | }
|
1037 | currentRemovalTimeouts[queryCacheKey] = setTimeout(function () {
|
1038 | var subscriptions = api2.getState()[reducerPath].subscriptions[queryCacheKey];
|
1039 | if (!subscriptions || Object.keys(subscriptions).length === 0) {
|
1040 | api2.dispatch(removeQueryResult({ queryCacheKey: queryCacheKey }));
|
1041 | }
|
1042 | delete currentRemovalTimeouts[queryCacheKey];
|
1043 | }, keepUnusedDataFor * 1e3);
|
1044 | }
|
1045 | };
|
1046 | };
|
1047 |
|
1048 | import { isAnyOf as isAnyOf2, isFulfilled as isFulfilled3, isRejectedWithValue as isRejectedWithValue3 } from "@reduxjs/toolkit";
|
1049 | var build2 = function (_e) {
|
1050 | var reducerPath = _e.reducerPath, context = _e.context, endpointDefinitions = _e.context.endpointDefinitions, mutationThunk = _e.mutationThunk, api = _e.api, assertTagType = _e.assertTagType, refetchQuery = _e.refetchQuery;
|
1051 | var removeQueryResult = api.internalActions.removeQueryResult;
|
1052 | return function (mwApi) { return function (next) { return function (action) {
|
1053 | var result = next(action);
|
1054 | if (isAnyOf2(isFulfilled3(mutationThunk), isRejectedWithValue3(mutationThunk))(action)) {
|
1055 | invalidateTags(calculateProvidedByThunk(action, "invalidatesTags", endpointDefinitions, assertTagType), mwApi);
|
1056 | }
|
1057 | if (api.util.invalidateTags.match(action)) {
|
1058 | invalidateTags(calculateProvidedBy(action.payload, void 0, void 0, void 0, assertTagType), mwApi);
|
1059 | }
|
1060 | return result;
|
1061 | }; }; };
|
1062 | function invalidateTags(tags, api2) {
|
1063 | var _a;
|
1064 | var state = api2.getState()[reducerPath];
|
1065 | var toInvalidate = new Set();
|
1066 | for (var _i = 0, tags_1 = tags; _i < tags_1.length; _i++) {
|
1067 | var tag = tags_1[_i];
|
1068 | var provided = state.provided[tag.type];
|
1069 | if (!provided) {
|
1070 | continue;
|
1071 | }
|
1072 | var invalidateSubscriptions = (_a = tag.id !== void 0 ? provided[tag.id] : flatten(Object.values(provided))) != null ? _a : [];
|
1073 | for (var _e = 0, invalidateSubscriptions_1 = invalidateSubscriptions; _e < invalidateSubscriptions_1.length; _e++) {
|
1074 | var invalidate = invalidateSubscriptions_1[_e];
|
1075 | toInvalidate.add(invalidate);
|
1076 | }
|
1077 | }
|
1078 | context.batch(function () {
|
1079 | var valuesArray = Array.from(toInvalidate.values());
|
1080 | for (var _i = 0, valuesArray_1 = valuesArray; _i < valuesArray_1.length; _i++) {
|
1081 | var queryCacheKey = valuesArray_1[_i];
|
1082 | var querySubState = state.queries[queryCacheKey];
|
1083 | var subscriptionSubState = state.subscriptions[queryCacheKey];
|
1084 | if (querySubState && subscriptionSubState) {
|
1085 | if (Object.keys(subscriptionSubState).length === 0) {
|
1086 | api2.dispatch(removeQueryResult({ queryCacheKey: queryCacheKey }));
|
1087 | }
|
1088 | else if (querySubState.status !== QueryStatus.uninitialized) {
|
1089 | api2.dispatch(refetchQuery(querySubState, queryCacheKey));
|
1090 | }
|
1091 | else {
|
1092 | }
|
1093 | }
|
1094 | }
|
1095 | });
|
1096 | }
|
1097 | };
|
1098 |
|
1099 | var build3 = function (_e) {
|
1100 | var reducerPath = _e.reducerPath, queryThunk = _e.queryThunk, api = _e.api, refetchQuery = _e.refetchQuery;
|
1101 | return function (mwApi) {
|
1102 | var currentPolls = {};
|
1103 | return function (next) { return function (action) {
|
1104 | var result = next(action);
|
1105 | if (api.internalActions.updateSubscriptionOptions.match(action)) {
|
1106 | updatePollingInterval(action.payload, mwApi);
|
1107 | }
|
1108 | if (queryThunk.pending.match(action) || queryThunk.rejected.match(action) && action.meta.condition) {
|
1109 | updatePollingInterval(action.meta.arg, mwApi);
|
1110 | }
|
1111 | if (queryThunk.fulfilled.match(action) || queryThunk.rejected.match(action) && !action.meta.condition) {
|
1112 | startNextPoll(action.meta.arg, mwApi);
|
1113 | }
|
1114 | if (api.util.resetApiState.match(action)) {
|
1115 | clearPolls();
|
1116 | }
|
1117 | return result;
|
1118 | }; };
|
1119 | function startNextPoll(_e, api2) {
|
1120 | var queryCacheKey = _e.queryCacheKey;
|
1121 | var state = api2.getState()[reducerPath];
|
1122 | var querySubState = state.queries[queryCacheKey];
|
1123 | var subscriptions = state.subscriptions[queryCacheKey];
|
1124 | if (!querySubState || querySubState.status === QueryStatus.uninitialized)
|
1125 | return;
|
1126 | var lowestPollingInterval = findLowestPollingInterval(subscriptions);
|
1127 | if (!Number.isFinite(lowestPollingInterval))
|
1128 | return;
|
1129 | var currentPoll = currentPolls[queryCacheKey];
|
1130 | if (currentPoll == null ? void 0 : currentPoll.timeout) {
|
1131 | clearTimeout(currentPoll.timeout);
|
1132 | currentPoll.timeout = void 0;
|
1133 | }
|
1134 | var nextPollTimestamp = Date.now() + lowestPollingInterval;
|
1135 | var currentInterval = currentPolls[queryCacheKey] = {
|
1136 | nextPollTimestamp: nextPollTimestamp,
|
1137 | pollingInterval: lowestPollingInterval,
|
1138 | timeout: setTimeout(function () {
|
1139 | currentInterval.timeout = void 0;
|
1140 | api2.dispatch(refetchQuery(querySubState, queryCacheKey));
|
1141 | }, lowestPollingInterval)
|
1142 | };
|
1143 | }
|
1144 | function updatePollingInterval(_e, api2) {
|
1145 | var queryCacheKey = _e.queryCacheKey;
|
1146 | var state = api2.getState()[reducerPath];
|
1147 | var querySubState = state.queries[queryCacheKey];
|
1148 | var subscriptions = state.subscriptions[queryCacheKey];
|
1149 | if (!querySubState || querySubState.status === QueryStatus.uninitialized) {
|
1150 | return;
|
1151 | }
|
1152 | var lowestPollingInterval = findLowestPollingInterval(subscriptions);
|
1153 | var currentPoll = currentPolls[queryCacheKey];
|
1154 | if (!Number.isFinite(lowestPollingInterval)) {
|
1155 | if (currentPoll == null ? void 0 : currentPoll.timeout) {
|
1156 | clearTimeout(currentPoll.timeout);
|
1157 | }
|
1158 | delete currentPolls[queryCacheKey];
|
1159 | return;
|
1160 | }
|
1161 | var nextPollTimestamp = Date.now() + lowestPollingInterval;
|
1162 | if (!currentPoll || nextPollTimestamp < currentPoll.nextPollTimestamp) {
|
1163 | startNextPoll({ queryCacheKey: queryCacheKey }, api2);
|
1164 | }
|
1165 | }
|
1166 | function clearPolls() {
|
1167 | for (var _i = 0, _e = Object.entries(currentPolls); _i < _e.length; _i++) {
|
1168 | var _f = _e[_i], key = _f[0], poll = _f[1];
|
1169 | if (poll == null ? void 0 : poll.timeout)
|
1170 | clearTimeout(poll.timeout);
|
1171 | delete currentPolls[key];
|
1172 | }
|
1173 | }
|
1174 | };
|
1175 | function findLowestPollingInterval(subscribers) {
|
1176 | if (subscribers === void 0) { subscribers = {}; }
|
1177 | var lowestPollingInterval = Number.POSITIVE_INFINITY;
|
1178 | for (var _i = 0, _e = Object.values(subscribers); _i < _e.length; _i++) {
|
1179 | var subscription = _e[_i];
|
1180 | if (!!subscription.pollingInterval)
|
1181 | lowestPollingInterval = Math.min(subscription.pollingInterval, lowestPollingInterval);
|
1182 | }
|
1183 | return lowestPollingInterval;
|
1184 | }
|
1185 | };
|
1186 |
|
1187 | var build4 = function (_e) {
|
1188 | var reducerPath = _e.reducerPath, context = _e.context, refetchQuery = _e.refetchQuery;
|
1189 | return function (mwApi) { return function (next) { return function (action) {
|
1190 | var result = next(action);
|
1191 | if (onFocus.match(action)) {
|
1192 | refetchValidQueries(mwApi, "refetchOnFocus");
|
1193 | }
|
1194 | if (onOnline.match(action)) {
|
1195 | refetchValidQueries(mwApi, "refetchOnReconnect");
|
1196 | }
|
1197 | return result;
|
1198 | }; }; };
|
1199 | function refetchValidQueries(api, type) {
|
1200 | var state = api.getState()[reducerPath];
|
1201 | var queries = state.queries;
|
1202 | var subscriptions = state.subscriptions;
|
1203 | context.batch(function () {
|
1204 | for (var _i = 0, _e = Object.keys(subscriptions); _i < _e.length; _i++) {
|
1205 | var queryCacheKey = _e[_i];
|
1206 | var querySubState = queries[queryCacheKey];
|
1207 | var subscriptionSubState = subscriptions[queryCacheKey];
|
1208 | if (!subscriptionSubState || !querySubState || querySubState.status === QueryStatus.uninitialized)
|
1209 | return;
|
1210 | 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];
|
1211 | if (shouldRefetch) {
|
1212 | api.dispatch(refetchQuery(querySubState, queryCacheKey));
|
1213 | }
|
1214 | }
|
1215 | });
|
1216 | }
|
1217 | };
|
1218 |
|
1219 | import { isAsyncThunkAction, isFulfilled as isFulfilled4 } from "@reduxjs/toolkit";
|
1220 | var neverResolvedError = new Error("Promise never resolved before cacheEntryRemoved.");
|
1221 | var build5 = function (_e) {
|
1222 | var api = _e.api, reducerPath = _e.reducerPath, context = _e.context, queryThunk = _e.queryThunk, mutationThunk = _e.mutationThunk;
|
1223 | var isQueryThunk = isAsyncThunkAction(queryThunk);
|
1224 | var isMutationThunk = isAsyncThunkAction(mutationThunk);
|
1225 | var isFullfilledThunk = isFulfilled4(queryThunk, mutationThunk);
|
1226 | return function (mwApi) {
|
1227 | var lifecycleMap = {};
|
1228 | return function (next) { return function (action) {
|
1229 | var stateBefore = mwApi.getState();
|
1230 | var result = next(action);
|
1231 | var cacheKey = getCacheKey(action);
|
1232 | if (queryThunk.pending.match(action)) {
|
1233 | var oldState = stateBefore[reducerPath].queries[cacheKey];
|
1234 | var state = mwApi.getState()[reducerPath].queries[cacheKey];
|
1235 | if (!oldState && state) {
|
1236 | handleNewKey(action.meta.arg.endpointName, action.meta.arg.originalArgs, cacheKey, mwApi, action.meta.requestId);
|
1237 | }
|
1238 | }
|
1239 | else if (mutationThunk.pending.match(action)) {
|
1240 | var state = mwApi.getState()[reducerPath].mutations[cacheKey];
|
1241 | if (state) {
|
1242 | handleNewKey(action.meta.arg.endpointName, action.meta.arg.originalArgs, cacheKey, mwApi, action.meta.requestId);
|
1243 | }
|
1244 | }
|
1245 | else if (isFullfilledThunk(action)) {
|
1246 | var lifecycle = lifecycleMap[cacheKey];
|
1247 | if (lifecycle == null ? void 0 : lifecycle.valueResolved) {
|
1248 | lifecycle.valueResolved({
|
1249 | data: action.payload,
|
1250 | meta: action.meta.baseQueryMeta
|
1251 | });
|
1252 | delete lifecycle.valueResolved;
|
1253 | }
|
1254 | }
|
1255 | else if (api.internalActions.removeQueryResult.match(action) || api.internalActions.unsubscribeMutationResult.match(action)) {
|
1256 | var lifecycle = lifecycleMap[cacheKey];
|
1257 | if (lifecycle) {
|
1258 | delete lifecycleMap[cacheKey];
|
1259 | lifecycle.cacheEntryRemoved();
|
1260 | }
|
1261 | }
|
1262 | else if (api.util.resetApiState.match(action)) {
|
1263 | for (var _i = 0, _e = Object.entries(lifecycleMap); _i < _e.length; _i++) {
|
1264 | var _f = _e[_i], cacheKey2 = _f[0], lifecycle = _f[1];
|
1265 | delete lifecycleMap[cacheKey2];
|
1266 | lifecycle.cacheEntryRemoved();
|
1267 | }
|
1268 | }
|
1269 | return result;
|
1270 | }; };
|
1271 | function getCacheKey(action) {
|
1272 | if (isQueryThunk(action))
|
1273 | return action.meta.arg.queryCacheKey;
|
1274 | if (isMutationThunk(action))
|
1275 | return action.meta.requestId;
|
1276 | if (api.internalActions.removeQueryResult.match(action))
|
1277 | return action.payload.queryCacheKey;
|
1278 | if (api.internalActions.unsubscribeMutationResult.match(action))
|
1279 | return action.payload.requestId;
|
1280 | return "";
|
1281 | }
|
1282 | function handleNewKey(endpointName, originalArgs, queryCacheKey, mwApi2, requestId) {
|
1283 | var endpointDefinition = context.endpointDefinitions[endpointName];
|
1284 | var onCacheEntryAdded = endpointDefinition == null ? void 0 : endpointDefinition.onCacheEntryAdded;
|
1285 | if (!onCacheEntryAdded)
|
1286 | return;
|
1287 | var lifecycle = {};
|
1288 | var cacheEntryRemoved = new Promise(function (resolve) {
|
1289 | lifecycle.cacheEntryRemoved = resolve;
|
1290 | });
|
1291 | var cacheDataLoaded = Promise.race([
|
1292 | new Promise(function (resolve) {
|
1293 | lifecycle.valueResolved = resolve;
|
1294 | }),
|
1295 | cacheEntryRemoved.then(function () {
|
1296 | throw neverResolvedError;
|
1297 | })
|
1298 | ]);
|
1299 | cacheDataLoaded.catch(function () {
|
1300 | });
|
1301 | lifecycleMap[queryCacheKey] = lifecycle;
|
1302 | var selector = api.endpoints[endpointName].select(endpointDefinition.type === DefinitionType.query ? originalArgs : queryCacheKey);
|
1303 | var extra = mwApi2.dispatch(function (_, __, extra2) { return extra2; });
|
1304 | var lifecycleApi = __spreadProps(__spreadValues({}, mwApi2), {
|
1305 | getCacheEntry: function () { return selector(mwApi2.getState()); },
|
1306 | requestId: requestId,
|
1307 | extra: extra,
|
1308 | updateCachedData: endpointDefinition.type === DefinitionType.query ? function (updateRecipe) { return mwApi2.dispatch(api.util.updateQueryData(endpointName, originalArgs, updateRecipe)); } : void 0,
|
1309 | cacheDataLoaded: cacheDataLoaded,
|
1310 | cacheEntryRemoved: cacheEntryRemoved
|
1311 | });
|
1312 | var runningHandler = onCacheEntryAdded(originalArgs, lifecycleApi);
|
1313 | Promise.resolve(runningHandler).catch(function (e) {
|
1314 | if (e === neverResolvedError)
|
1315 | return;
|
1316 | throw e;
|
1317 | });
|
1318 | }
|
1319 | };
|
1320 | };
|
1321 |
|
1322 | import { isPending as isPending2, isRejected as isRejected2, isFulfilled as isFulfilled5 } from "@reduxjs/toolkit";
|
1323 | var build6 = function (_e) {
|
1324 | var api = _e.api, context = _e.context, queryThunk = _e.queryThunk, mutationThunk = _e.mutationThunk;
|
1325 | var isPendingThunk = isPending2(queryThunk, mutationThunk);
|
1326 | var isRejectedThunk = isRejected2(queryThunk, mutationThunk);
|
1327 | var isFullfilledThunk = isFulfilled5(queryThunk, mutationThunk);
|
1328 | return function (mwApi) {
|
1329 | var lifecycleMap = {};
|
1330 | return function (next) { return function (action) {
|
1331 | var _a, _b, _c;
|
1332 | var result = next(action);
|
1333 | if (isPendingThunk(action)) {
|
1334 | var _e = action.meta, requestId = _e.requestId, _f = _e.arg, endpointName_1 = _f.endpointName, originalArgs_1 = _f.originalArgs;
|
1335 | var endpointDefinition = context.endpointDefinitions[endpointName_1];
|
1336 | var onQueryStarted = endpointDefinition == null ? void 0 : endpointDefinition.onQueryStarted;
|
1337 | if (onQueryStarted) {
|
1338 | var lifecycle_1 = {};
|
1339 | var queryFulfilled = new Promise(function (resolve, reject) {
|
1340 | lifecycle_1.resolve = resolve;
|
1341 | lifecycle_1.reject = reject;
|
1342 | });
|
1343 | queryFulfilled.catch(function () {
|
1344 | });
|
1345 | lifecycleMap[requestId] = lifecycle_1;
|
1346 | var selector_1 = api.endpoints[endpointName_1].select(endpointDefinition.type === DefinitionType.query ? originalArgs_1 : requestId);
|
1347 | var extra = mwApi.dispatch(function (_, __, extra2) { return extra2; });
|
1348 | var lifecycleApi = __spreadProps(__spreadValues({}, mwApi), {
|
1349 | getCacheEntry: function () { return selector_1(mwApi.getState()); },
|
1350 | requestId: requestId,
|
1351 | extra: extra,
|
1352 | updateCachedData: endpointDefinition.type === DefinitionType.query ? function (updateRecipe) { return mwApi.dispatch(api.util.updateQueryData(endpointName_1, originalArgs_1, updateRecipe)); } : void 0,
|
1353 | queryFulfilled: queryFulfilled
|
1354 | });
|
1355 | onQueryStarted(originalArgs_1, lifecycleApi);
|
1356 | }
|
1357 | }
|
1358 | else if (isFullfilledThunk(action)) {
|
1359 | var _g = action.meta, requestId = _g.requestId, baseQueryMeta = _g.baseQueryMeta;
|
1360 | (_a = lifecycleMap[requestId]) == null ? void 0 : _a.resolve({
|
1361 | data: action.payload,
|
1362 | meta: baseQueryMeta
|
1363 | });
|
1364 | delete lifecycleMap[requestId];
|
1365 | }
|
1366 | else if (isRejectedThunk(action)) {
|
1367 | var _h = action.meta, requestId = _h.requestId, rejectedWithValue = _h.rejectedWithValue, baseQueryMeta = _h.baseQueryMeta;
|
1368 | (_c = lifecycleMap[requestId]) == null ? void 0 : _c.reject({
|
1369 | error: (_b = action.payload) != null ? _b : action.error,
|
1370 | isUnhandledError: !rejectedWithValue,
|
1371 | meta: baseQueryMeta
|
1372 | });
|
1373 | delete lifecycleMap[requestId];
|
1374 | }
|
1375 | return result;
|
1376 | }; };
|
1377 | };
|
1378 | };
|
1379 |
|
1380 | var build7 = function (_e) {
|
1381 | var api = _e.api, apiUid = _e.context.apiUid, reducerPath = _e.reducerPath;
|
1382 | return function (mwApi) {
|
1383 | var initialized2 = false;
|
1384 | return function (next) { return function (action) {
|
1385 | var _a, _b;
|
1386 | if (!initialized2) {
|
1387 | initialized2 = true;
|
1388 | mwApi.dispatch(api.internalActions.middlewareRegistered(apiUid));
|
1389 | }
|
1390 | var result = next(action);
|
1391 | if (api.util.resetApiState.match(action)) {
|
1392 | mwApi.dispatch(api.internalActions.middlewareRegistered(apiUid));
|
1393 | }
|
1394 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
1395 | 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") {
|
1396 | 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!" : ""));
|
1397 | }
|
1398 | }
|
1399 | return result;
|
1400 | }; };
|
1401 | };
|
1402 | };
|
1403 |
|
1404 | function buildMiddleware(input) {
|
1405 | var reducerPath = input.reducerPath, queryThunk = input.queryThunk;
|
1406 | var actions = {
|
1407 | invalidateTags: createAction3(reducerPath + "/invalidateTags")
|
1408 | };
|
1409 | var middlewares = [
|
1410 | build7,
|
1411 | build,
|
1412 | build2,
|
1413 | build3,
|
1414 | build4,
|
1415 | build5,
|
1416 | build6
|
1417 | ].map(function (build8) { return build8(__spreadProps(__spreadValues({}, input), {
|
1418 | refetchQuery: refetchQuery
|
1419 | })); });
|
1420 | var middleware = function (mwApi) { return function (next) {
|
1421 | var applied = compose.apply(void 0, middlewares.map(function (middleware2) { return middleware2(mwApi); }))(next);
|
1422 | return function (action) {
|
1423 | if (mwApi.getState()[reducerPath]) {
|
1424 | return applied(action);
|
1425 | }
|
1426 | return next(action);
|
1427 | };
|
1428 | }; };
|
1429 | return { middleware: middleware, actions: actions };
|
1430 | function refetchQuery(querySubState, queryCacheKey, override) {
|
1431 | if (override === void 0) { override = {}; }
|
1432 | return queryThunk(__spreadValues({
|
1433 | endpointName: querySubState.endpointName,
|
1434 | originalArgs: querySubState.originalArgs,
|
1435 | subscribe: false,
|
1436 | forceRefetch: true,
|
1437 | queryCacheKey: queryCacheKey
|
1438 | }, override));
|
1439 | }
|
1440 | }
|
1441 |
|
1442 | function buildInitiate(_e) {
|
1443 | var serializeQueryArgs = _e.serializeQueryArgs, queryThunk = _e.queryThunk, mutationThunk = _e.mutationThunk, api = _e.api;
|
1444 | var _f = api.internalActions, unsubscribeQueryResult = _f.unsubscribeQueryResult, unsubscribeMutationResult = _f.unsubscribeMutationResult, updateSubscriptionOptions = _f.updateSubscriptionOptions;
|
1445 | return { buildInitiateQuery: buildInitiateQuery, buildInitiateMutation: buildInitiateMutation };
|
1446 | function middlewareWarning(getState) {
|
1447 | var _a, _b;
|
1448 | if (process.env.NODE_ENV !== "production") {
|
1449 | if (middlewareWarning.triggered)
|
1450 | return;
|
1451 | var registered = (_b = (_a = getState()[api.reducerPath]) == null ? void 0 : _a.config) == null ? void 0 : _b.middlewareRegistered;
|
1452 | if (registered !== void 0) {
|
1453 | ;
|
1454 | middlewareWarning.triggered = true;
|
1455 | }
|
1456 | if (registered === false) {
|
1457 | console.warn("Warning: Middleware for RTK-Query API at reducerPath \"" + api.reducerPath + "\" has not been added to the store.\nFeatures like automatic cache collection, automatic refetching etc. will not be available.");
|
1458 | }
|
1459 | }
|
1460 | }
|
1461 | function buildInitiateQuery(endpointName, endpointDefinition) {
|
1462 | var queryAction = function (arg, _e) {
|
1463 | var _f = _e === void 0 ? {} : _e, _g = _f.subscribe, subscribe = _g === void 0 ? true : _g, forceRefetch = _f.forceRefetch, subscriptionOptions = _f.subscriptionOptions;
|
1464 | return function (dispatch, getState) {
|
1465 | var queryCacheKey = serializeQueryArgs({
|
1466 | queryArgs: arg,
|
1467 | endpointDefinition: endpointDefinition,
|
1468 | endpointName: endpointName
|
1469 | });
|
1470 | var thunk = queryThunk({
|
1471 | subscribe: subscribe,
|
1472 | forceRefetch: forceRefetch,
|
1473 | subscriptionOptions: subscriptionOptions,
|
1474 | endpointName: endpointName,
|
1475 | originalArgs: arg,
|
1476 | queryCacheKey: queryCacheKey
|
1477 | });
|
1478 | var thunkResult = dispatch(thunk);
|
1479 | middlewareWarning(getState);
|
1480 | var requestId = thunkResult.requestId, abort = thunkResult.abort;
|
1481 | var statePromise = Object.assign(thunkResult.then(function () { return api.endpoints[endpointName].select(arg)(getState()); }), {
|
1482 | arg: arg,
|
1483 | requestId: requestId,
|
1484 | subscriptionOptions: subscriptionOptions,
|
1485 | abort: abort,
|
1486 | refetch: function () {
|
1487 | dispatch(queryAction(arg, { subscribe: false, forceRefetch: true }));
|
1488 | },
|
1489 | unsubscribe: function () {
|
1490 | if (subscribe)
|
1491 | dispatch(unsubscribeQueryResult({
|
1492 | queryCacheKey: queryCacheKey,
|
1493 | requestId: requestId
|
1494 | }));
|
1495 | },
|
1496 | updateSubscriptionOptions: function (options) {
|
1497 | statePromise.subscriptionOptions = options;
|
1498 | dispatch(updateSubscriptionOptions({
|
1499 | endpointName: endpointName,
|
1500 | requestId: requestId,
|
1501 | queryCacheKey: queryCacheKey,
|
1502 | options: options
|
1503 | }));
|
1504 | }
|
1505 | });
|
1506 | return statePromise;
|
1507 | };
|
1508 | };
|
1509 | return queryAction;
|
1510 | }
|
1511 | function buildInitiateMutation(endpointName, definition) {
|
1512 | return function (arg, _e) {
|
1513 | var _f = _e === void 0 ? {} : _e, _g = _f.track, track = _g === void 0 ? true : _g;
|
1514 | return function (dispatch, getState) {
|
1515 | var thunk = mutationThunk({
|
1516 | endpointName: endpointName,
|
1517 | originalArgs: arg,
|
1518 | track: track
|
1519 | });
|
1520 | var thunkResult = dispatch(thunk);
|
1521 | middlewareWarning(getState);
|
1522 | var requestId = thunkResult.requestId, abort = thunkResult.abort;
|
1523 | var returnValuePromise = thunkResult.unwrap().then(function (data) { return ({ data: data }); }).catch(function (error) { return ({ error: error }); });
|
1524 | return Object.assign(returnValuePromise, {
|
1525 | arg: thunkResult.arg,
|
1526 | requestId: requestId,
|
1527 | abort: abort,
|
1528 | unwrap: thunkResult.unwrap,
|
1529 | unsubscribe: function () {
|
1530 | if (track)
|
1531 | dispatch(unsubscribeMutationResult({ requestId: requestId }));
|
1532 | }
|
1533 | });
|
1534 | };
|
1535 | };
|
1536 | }
|
1537 | }
|
1538 |
|
1539 | function assertCast(v) {
|
1540 | }
|
1541 | function safeAssign(target) {
|
1542 | var args = [];
|
1543 | for (var _i = 1; _i < arguments.length; _i++) {
|
1544 | args[_i - 1] = arguments[_i];
|
1545 | }
|
1546 | Object.assign.apply(Object, __spreadArray([target], args));
|
1547 | }
|
1548 |
|
1549 | import { enablePatches } from "immer";
|
1550 | var coreModuleName = Symbol();
|
1551 | var coreModule = function () { return ({
|
1552 | name: coreModuleName,
|
1553 | init: function (api, _e, context) {
|
1554 | var baseQuery = _e.baseQuery, tagTypes = _e.tagTypes, reducerPath = _e.reducerPath, serializeQueryArgs = _e.serializeQueryArgs, keepUnusedDataFor = _e.keepUnusedDataFor, refetchOnMountOrArgChange = _e.refetchOnMountOrArgChange, refetchOnFocus = _e.refetchOnFocus, refetchOnReconnect = _e.refetchOnReconnect;
|
1555 | enablePatches();
|
1556 | assertCast(serializeQueryArgs);
|
1557 | var assertTagType = function (tag) {
|
1558 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
1559 | if (!tagTypes.includes(tag.type)) {
|
1560 | console.error("Tag type '" + tag.type + "' was used, but not specified in `tagTypes`!");
|
1561 | }
|
1562 | }
|
1563 | return tag;
|
1564 | };
|
1565 | Object.assign(api, {
|
1566 | reducerPath: reducerPath,
|
1567 | endpoints: {},
|
1568 | internalActions: {
|
1569 | onOnline: onOnline,
|
1570 | onOffline: onOffline,
|
1571 | onFocus: onFocus,
|
1572 | onFocusLost: onFocusLost
|
1573 | },
|
1574 | util: {}
|
1575 | });
|
1576 | var _f = buildThunks({
|
1577 | baseQuery: baseQuery,
|
1578 | reducerPath: reducerPath,
|
1579 | context: context,
|
1580 | api: api,
|
1581 | serializeQueryArgs: serializeQueryArgs
|
1582 | }), queryThunk = _f.queryThunk, mutationThunk = _f.mutationThunk, patchQueryData = _f.patchQueryData, updateQueryData = _f.updateQueryData, prefetch = _f.prefetch, buildMatchThunkActions = _f.buildMatchThunkActions;
|
1583 | var _g = buildSlice({
|
1584 | context: context,
|
1585 | queryThunk: queryThunk,
|
1586 | mutationThunk: mutationThunk,
|
1587 | reducerPath: reducerPath,
|
1588 | assertTagType: assertTagType,
|
1589 | config: {
|
1590 | refetchOnFocus: refetchOnFocus,
|
1591 | refetchOnReconnect: refetchOnReconnect,
|
1592 | refetchOnMountOrArgChange: refetchOnMountOrArgChange,
|
1593 | keepUnusedDataFor: keepUnusedDataFor,
|
1594 | reducerPath: reducerPath
|
1595 | }
|
1596 | }), reducer = _g.reducer, sliceActions = _g.actions;
|
1597 | safeAssign(api.util, {
|
1598 | patchQueryData: patchQueryData,
|
1599 | updateQueryData: updateQueryData,
|
1600 | prefetch: prefetch,
|
1601 | resetApiState: sliceActions.resetApiState
|
1602 | });
|
1603 | safeAssign(api.internalActions, sliceActions);
|
1604 | Object.defineProperty(api.util, "updateQueryResult", {
|
1605 | get: function () {
|
1606 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
1607 | console.warn("`api.util.updateQueryResult` has been renamed to `api.util.updateQueryData`, please change your code accordingly");
|
1608 | }
|
1609 | return api.util.updateQueryData;
|
1610 | }
|
1611 | });
|
1612 | Object.defineProperty(api.util, "patchQueryResult", {
|
1613 | get: function () {
|
1614 | if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
1615 | console.warn("`api.util.patchQueryResult` has been renamed to `api.util.patchQueryData`, please change your code accordingly");
|
1616 | }
|
1617 | return api.util.patchQueryData;
|
1618 | }
|
1619 | });
|
1620 | var _h = buildMiddleware({
|
1621 | reducerPath: reducerPath,
|
1622 | context: context,
|
1623 | queryThunk: queryThunk,
|
1624 | mutationThunk: mutationThunk,
|
1625 | api: api,
|
1626 | assertTagType: assertTagType
|
1627 | }), middleware = _h.middleware, middlewareActions = _h.actions;
|
1628 | safeAssign(api.util, middlewareActions);
|
1629 | safeAssign(api, { reducer: reducer, middleware: middleware });
|
1630 | var _j = buildSelectors({
|
1631 | serializeQueryArgs: serializeQueryArgs,
|
1632 | reducerPath: reducerPath
|
1633 | }), buildQuerySelector = _j.buildQuerySelector, buildMutationSelector = _j.buildMutationSelector;
|
1634 | var _k = buildInitiate({
|
1635 | queryThunk: queryThunk,
|
1636 | mutationThunk: mutationThunk,
|
1637 | api: api,
|
1638 | serializeQueryArgs: serializeQueryArgs
|
1639 | }), buildInitiateQuery = _k.buildInitiateQuery, buildInitiateMutation = _k.buildInitiateMutation;
|
1640 | return {
|
1641 | name: coreModuleName,
|
1642 | injectEndpoint: function (endpointName, definition) {
|
1643 | var _a, _b;
|
1644 | var anyApi = api;
|
1645 | (_b = (_a = anyApi.endpoints)[endpointName]) != null ? _b : _a[endpointName] = {};
|
1646 | if (isQueryDefinition(definition)) {
|
1647 | safeAssign(anyApi.endpoints[endpointName], {
|
1648 | select: buildQuerySelector(endpointName, definition),
|
1649 | initiate: buildInitiateQuery(endpointName, definition)
|
1650 | }, buildMatchThunkActions(queryThunk, endpointName));
|
1651 | }
|
1652 | else if (isMutationDefinition(definition)) {
|
1653 | safeAssign(anyApi.endpoints[endpointName], {
|
1654 | select: buildMutationSelector(),
|
1655 | initiate: buildInitiateMutation(endpointName, definition)
|
1656 | }, buildMatchThunkActions(mutationThunk, endpointName));
|
1657 | }
|
1658 | }
|
1659 | };
|
1660 | }
|
1661 | }); };
|
1662 |
|
1663 | var createApi = buildCreateApi(coreModule());
|
1664 | export { QueryStatus, buildCreateApi, copyWithStructuralSharing, coreModule, createApi, fakeBaseQuery, fetchBaseQuery, retry, setupListeners, skipSelector, skipToken };
|
1665 |
|
\ | No newline at end of file |