rtk-query.cjs.development.js 113 KB

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