UNPKG

88.7 kBJavaScriptView Raw
1var __extends = (this && this.__extends) || (function () {
2 var extendStatics = function (d, b) {
3 extendStatics = Object.setPrototypeOf ||
4 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6 return extendStatics(d, b);
7 };
8 return function (d, b) {
9 if (typeof b !== "function" && b !== null)
10 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11 extendStatics(d, b);
12 function __() { this.constructor = d; }
13 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14 };
15})();
16var __generator = (this && this.__generator) || function (thisArg, body) {
17 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
18 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
19 function verb(n) { return function (v) { return step([n, v]); }; }
20 function step(op) {
21 if (f) throw new TypeError("Generator is already executing.");
22 while (_) try {
23 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;
24 if (y = 0, t) op = [op[0] & 2, t.value];
25 switch (op[0]) {
26 case 0: case 1: t = op; break;
27 case 4: _.label++; return { value: op[1], done: false };
28 case 5: _.label++; y = op[1]; op = [0]; continue;
29 case 7: op = _.ops.pop(); _.trys.pop(); continue;
30 default:
31 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
32 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
33 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
34 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
35 if (t[2]) _.ops.pop();
36 _.trys.pop(); continue;
37 }
38 op = body.call(thisArg, _);
39 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
40 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
41 }
42};
43var __spreadArray = (this && this.__spreadArray) || function (to, from) {
44 for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
45 to[j] = from[i];
46 return to;
47};
48var __defProp = Object.defineProperty;
49var __defProps = Object.defineProperties;
50var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
51var __getOwnPropSymbols = Object.getOwnPropertySymbols;
52var __hasOwnProp = Object.prototype.hasOwnProperty;
53var __propIsEnum = Object.prototype.propertyIsEnumerable;
54var __defNormalProp = function (obj, key, value) { return key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value: value }) : obj[key] = value; };
55var __spreadValues = function (a, b) {
56 for (var prop in b || (b = {}))
57 if (__hasOwnProp.call(b, prop))
58 __defNormalProp(a, prop, b[prop]);
59 if (__getOwnPropSymbols)
60 for (var _i = 0, _c = __getOwnPropSymbols(b); _i < _c.length; _i++) {
61 var prop = _c[_i];
62 if (__propIsEnum.call(b, prop))
63 __defNormalProp(a, prop, b[prop]);
64 }
65 return a;
66};
67var __spreadProps = function (a, b) { return __defProps(a, __getOwnPropDescs(b)); };
68var __async = function (__this, __arguments, generator) {
69 return new Promise(function (resolve, reject) {
70 var fulfilled = function (value) {
71 try {
72 step(generator.next(value));
73 }
74 catch (e) {
75 reject(e);
76 }
77 };
78 var rejected = function (value) {
79 try {
80 step(generator.throw(value));
81 }
82 catch (e) {
83 reject(e);
84 }
85 };
86 var step = function (x) { return x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); };
87 step((generator = generator.apply(__this, __arguments)).next());
88 });
89};
90// src/index.ts
91import { enableES5 } from "immer";
92export * from "redux";
93import { default as default2, current as current2, freeze, original, isDraft as isDraft4 } from "immer";
94import { createSelector as createSelector2 } from "reselect";
95// src/createDraftSafeSelector.ts
96import { current, isDraft } from "immer";
97import { createSelector } from "reselect";
98var createDraftSafeSelector = function () {
99 var args = [];
100 for (var _i = 0; _i < arguments.length; _i++) {
101 args[_i] = arguments[_i];
102 }
103 var selector = createSelector.apply(void 0, args);
104 var wrappedSelector = function (value) {
105 var rest = [];
106 for (var _i = 1; _i < arguments.length; _i++) {
107 rest[_i - 1] = arguments[_i];
108 }
109 return selector.apply(void 0, __spreadArray([isDraft(value) ? current(value) : value], rest));
110 };
111 return wrappedSelector;
112};
113// src/configureStore.ts
114import { createStore, compose as compose2, applyMiddleware, combineReducers } from "redux";
115// src/devtoolsExtension.ts
116import { compose } from "redux";
117var composeWithDevTools = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : function () {
118 if (arguments.length === 0)
119 return void 0;
120 if (typeof arguments[0] === "object")
121 return compose;
122 return compose.apply(null, arguments);
123};
124var devToolsEnhancer = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ : function () {
125 return function (noop2) {
126 return noop2;
127 };
128};
129// src/isPlainObject.ts
130function isPlainObject(value) {
131 if (typeof value !== "object" || value === null)
132 return false;
133 var proto = Object.getPrototypeOf(value);
134 if (proto === null)
135 return true;
136 var baseProto = proto;
137 while (Object.getPrototypeOf(baseProto) !== null) {
138 baseProto = Object.getPrototypeOf(baseProto);
139 }
140 return proto === baseProto;
141}
142// src/getDefaultMiddleware.ts
143import thunkMiddleware from "redux-thunk";
144// src/tsHelpers.ts
145var hasMatchFunction = function (v) {
146 return v && typeof v.match === "function";
147};
148// src/createAction.ts
149function createAction(type, prepareAction) {
150 function actionCreator() {
151 var args = [];
152 for (var _i = 0; _i < arguments.length; _i++) {
153 args[_i] = arguments[_i];
154 }
155 if (prepareAction) {
156 var prepared = prepareAction.apply(void 0, args);
157 if (!prepared) {
158 throw new Error("prepareAction did not return an object");
159 }
160 return __spreadValues(__spreadValues({
161 type: type,
162 payload: prepared.payload
163 }, "meta" in prepared && { meta: prepared.meta }), "error" in prepared && { error: prepared.error });
164 }
165 return { type: type, payload: args[0] };
166 }
167 actionCreator.toString = function () { return "" + type; };
168 actionCreator.type = type;
169 actionCreator.match = function (action) { return action.type === type; };
170 return actionCreator;
171}
172function isAction(action) {
173 return isPlainObject(action) && "type" in action;
174}
175function isActionCreator(action) {
176 return typeof action === "function" && "type" in action && hasMatchFunction(action);
177}
178function isFSA(action) {
179 return isAction(action) && typeof action.type === "string" && Object.keys(action).every(isValidKey);
180}
181function isValidKey(key) {
182 return ["type", "payload", "error", "meta"].indexOf(key) > -1;
183}
184function getType(actionCreator) {
185 return "" + actionCreator;
186}
187// src/actionCreatorInvariantMiddleware.ts
188function getMessage(type) {
189 var splitType = type ? ("" + type).split("/") : [];
190 var actionName = splitType[splitType.length - 1] || "actionCreator";
191 return "Detected an action creator with type \"" + (type || "unknown") + "\" being dispatched. \nMake sure you're calling the action creator before dispatching, i.e. `dispatch(" + actionName + "())` instead of `dispatch(" + actionName + ")`. This is necessary even if the action has no payload.";
192}
193function createActionCreatorInvariantMiddleware(options) {
194 if (options === void 0) { options = {}; }
195 if (process.env.NODE_ENV === "production") {
196 return function () { return function (next) { return function (action) { return next(action); }; }; };
197 }
198 var _c = options.isActionCreator, isActionCreator2 = _c === void 0 ? isActionCreator : _c;
199 return function () { return function (next) { return function (action) {
200 if (isActionCreator2(action)) {
201 console.warn(getMessage(action.type));
202 }
203 return next(action);
204 }; }; };
205}
206// src/utils.ts
207import createNextState, { isDraftable } from "immer";
208function getTimeMeasureUtils(maxDelay, fnName) {
209 var elapsed = 0;
210 return {
211 measureTime: function (fn) {
212 var started = Date.now();
213 try {
214 return fn();
215 }
216 finally {
217 var finished = Date.now();
218 elapsed += finished - started;
219 }
220 },
221 warnIfExceeded: function () {
222 if (elapsed > maxDelay) {
223 console.warn(fnName + " took " + elapsed + "ms, which is more than the warning threshold of " + maxDelay + "ms. \nIf your state or actions are very large, you may want to disable the middleware as it might cause too much of a slowdown in development mode. See https://redux-toolkit.js.org/api/getDefaultMiddleware for instructions.\nIt is disabled in production builds, so you don't need to worry about that.");
224 }
225 }
226 };
227}
228var MiddlewareArray = /** @class */ (function (_super) {
229 __extends(MiddlewareArray, _super);
230 function MiddlewareArray() {
231 var args = [];
232 for (var _i = 0; _i < arguments.length; _i++) {
233 args[_i] = arguments[_i];
234 }
235 var _this = _super.apply(this, args) || this;
236 Object.setPrototypeOf(_this, MiddlewareArray.prototype);
237 return _this;
238 }
239 Object.defineProperty(MiddlewareArray, Symbol.species, {
240 get: function () {
241 return MiddlewareArray;
242 },
243 enumerable: false,
244 configurable: true
245 });
246 MiddlewareArray.prototype.concat = function () {
247 var arr = [];
248 for (var _i = 0; _i < arguments.length; _i++) {
249 arr[_i] = arguments[_i];
250 }
251 return _super.prototype.concat.apply(this, arr);
252 };
253 MiddlewareArray.prototype.prepend = function () {
254 var arr = [];
255 for (var _i = 0; _i < arguments.length; _i++) {
256 arr[_i] = arguments[_i];
257 }
258 if (arr.length === 1 && Array.isArray(arr[0])) {
259 return new (MiddlewareArray.bind.apply(MiddlewareArray, __spreadArray([void 0], arr[0].concat(this))))();
260 }
261 return new (MiddlewareArray.bind.apply(MiddlewareArray, __spreadArray([void 0], arr.concat(this))))();
262 };
263 return MiddlewareArray;
264}(Array));
265var EnhancerArray = /** @class */ (function (_super) {
266 __extends(EnhancerArray, _super);
267 function EnhancerArray() {
268 var args = [];
269 for (var _i = 0; _i < arguments.length; _i++) {
270 args[_i] = arguments[_i];
271 }
272 var _this = _super.apply(this, args) || this;
273 Object.setPrototypeOf(_this, EnhancerArray.prototype);
274 return _this;
275 }
276 Object.defineProperty(EnhancerArray, Symbol.species, {
277 get: function () {
278 return EnhancerArray;
279 },
280 enumerable: false,
281 configurable: true
282 });
283 EnhancerArray.prototype.concat = function () {
284 var arr = [];
285 for (var _i = 0; _i < arguments.length; _i++) {
286 arr[_i] = arguments[_i];
287 }
288 return _super.prototype.concat.apply(this, arr);
289 };
290 EnhancerArray.prototype.prepend = function () {
291 var arr = [];
292 for (var _i = 0; _i < arguments.length; _i++) {
293 arr[_i] = arguments[_i];
294 }
295 if (arr.length === 1 && Array.isArray(arr[0])) {
296 return new (EnhancerArray.bind.apply(EnhancerArray, __spreadArray([void 0], arr[0].concat(this))))();
297 }
298 return new (EnhancerArray.bind.apply(EnhancerArray, __spreadArray([void 0], arr.concat(this))))();
299 };
300 return EnhancerArray;
301}(Array));
302function freezeDraftable(val) {
303 return isDraftable(val) ? createNextState(val, function () {
304 }) : val;
305}
306// src/immutableStateInvariantMiddleware.ts
307var isProduction = process.env.NODE_ENV === "production";
308var prefix = "Invariant failed";
309function invariant(condition, message) {
310 if (condition) {
311 return;
312 }
313 if (isProduction) {
314 throw new Error(prefix);
315 }
316 throw new Error(prefix + ": " + (message || ""));
317}
318function stringify(obj, serializer, indent, decycler) {
319 return JSON.stringify(obj, getSerialize(serializer, decycler), indent);
320}
321function getSerialize(serializer, decycler) {
322 var stack = [], keys = [];
323 if (!decycler)
324 decycler = function (_, value) {
325 if (stack[0] === value)
326 return "[Circular ~]";
327 return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
328 };
329 return function (key, value) {
330 if (stack.length > 0) {
331 var thisPos = stack.indexOf(this);
332 ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
333 ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
334 if (~stack.indexOf(value))
335 value = decycler.call(this, key, value);
336 }
337 else
338 stack.push(value);
339 return serializer == null ? value : serializer.call(this, key, value);
340 };
341}
342function isImmutableDefault(value) {
343 return typeof value !== "object" || value == null || Object.isFrozen(value);
344}
345function trackForMutations(isImmutable, ignorePaths, obj) {
346 var trackedProperties = trackProperties(isImmutable, ignorePaths, obj);
347 return {
348 detectMutations: function () {
349 return detectMutations(isImmutable, ignorePaths, trackedProperties, obj);
350 }
351 };
352}
353function trackProperties(isImmutable, ignorePaths, obj, path, checkedObjects) {
354 if (ignorePaths === void 0) { ignorePaths = []; }
355 if (path === void 0) { path = ""; }
356 if (checkedObjects === void 0) { checkedObjects = new Set(); }
357 var tracked = { value: obj };
358 if (!isImmutable(obj) && !checkedObjects.has(obj)) {
359 checkedObjects.add(obj);
360 tracked.children = {};
361 for (var key in obj) {
362 var childPath = path ? path + "." + key : key;
363 if (ignorePaths.length && ignorePaths.indexOf(childPath) !== -1) {
364 continue;
365 }
366 tracked.children[key] = trackProperties(isImmutable, ignorePaths, obj[key], childPath);
367 }
368 }
369 return tracked;
370}
371function detectMutations(isImmutable, ignoredPaths, trackedProperty, obj, sameParentRef, path) {
372 if (ignoredPaths === void 0) { ignoredPaths = []; }
373 if (sameParentRef === void 0) { sameParentRef = false; }
374 if (path === void 0) { path = ""; }
375 var prevObj = trackedProperty ? trackedProperty.value : void 0;
376 var sameRef = prevObj === obj;
377 if (sameParentRef && !sameRef && !Number.isNaN(obj)) {
378 return { wasMutated: true, path: path };
379 }
380 if (isImmutable(prevObj) || isImmutable(obj)) {
381 return { wasMutated: false };
382 }
383 var keysToDetect = {};
384 for (var key in trackedProperty.children) {
385 keysToDetect[key] = true;
386 }
387 for (var key in obj) {
388 keysToDetect[key] = true;
389 }
390 var hasIgnoredPaths = ignoredPaths.length > 0;
391 var _loop_1 = function (key) {
392 var nestedPath = path ? path + "." + key : key;
393 if (hasIgnoredPaths) {
394 var hasMatches = ignoredPaths.some(function (ignored) {
395 if (ignored instanceof RegExp) {
396 return ignored.test(nestedPath);
397 }
398 return nestedPath === ignored;
399 });
400 if (hasMatches) {
401 return "continue";
402 }
403 }
404 var result = detectMutations(isImmutable, ignoredPaths, trackedProperty.children[key], obj[key], sameRef, nestedPath);
405 if (result.wasMutated) {
406 return { value: result };
407 }
408 };
409 for (var key in keysToDetect) {
410 var state_1 = _loop_1(key);
411 if (typeof state_1 === "object")
412 return state_1.value;
413 }
414 return { wasMutated: false };
415}
416function createImmutableStateInvariantMiddleware(options) {
417 if (options === void 0) { options = {}; }
418 if (process.env.NODE_ENV === "production") {
419 return function () { return function (next) { return function (action) { return next(action); }; }; };
420 }
421 var _c = options.isImmutable, isImmutable = _c === void 0 ? isImmutableDefault : _c, ignoredPaths = options.ignoredPaths, _d = options.warnAfter, warnAfter = _d === void 0 ? 32 : _d, ignore = options.ignore;
422 ignoredPaths = ignoredPaths || ignore;
423 var track = trackForMutations.bind(null, isImmutable, ignoredPaths);
424 return function (_c) {
425 var getState = _c.getState;
426 var state = getState();
427 var tracker = track(state);
428 var result;
429 return function (next) { return function (action) {
430 var measureUtils = getTimeMeasureUtils(warnAfter, "ImmutableStateInvariantMiddleware");
431 measureUtils.measureTime(function () {
432 state = getState();
433 result = tracker.detectMutations();
434 tracker = track(state);
435 invariant(!result.wasMutated, "A state mutation was detected between dispatches, in the path '" + (result.path || "") + "'. This may cause incorrect behavior. (https://redux.js.org/style-guide/style-guide#do-not-mutate-state)");
436 });
437 var dispatchedAction = next(action);
438 measureUtils.measureTime(function () {
439 state = getState();
440 result = tracker.detectMutations();
441 tracker = track(state);
442 result.wasMutated && invariant(!result.wasMutated, "A state mutation was detected inside a dispatch, in the path: " + (result.path || "") + ". Take a look at the reducer(s) handling the action " + stringify(action) + ". (https://redux.js.org/style-guide/style-guide#do-not-mutate-state)");
443 });
444 measureUtils.warnIfExceeded();
445 return dispatchedAction;
446 }; };
447 };
448}
449// src/serializableStateInvariantMiddleware.ts
450function isPlain(val) {
451 var type = typeof val;
452 return val == null || type === "string" || type === "boolean" || type === "number" || Array.isArray(val) || isPlainObject(val);
453}
454function findNonSerializableValue(value, path, isSerializable, getEntries, ignoredPaths, cache) {
455 if (path === void 0) { path = ""; }
456 if (isSerializable === void 0) { isSerializable = isPlain; }
457 if (ignoredPaths === void 0) { ignoredPaths = []; }
458 var foundNestedSerializable;
459 if (!isSerializable(value)) {
460 return {
461 keyPath: path || "<root>",
462 value: value
463 };
464 }
465 if (typeof value !== "object" || value === null) {
466 return false;
467 }
468 if (cache == null ? void 0 : cache.has(value))
469 return false;
470 var entries = getEntries != null ? getEntries(value) : Object.entries(value);
471 var hasIgnoredPaths = ignoredPaths.length > 0;
472 var _loop_2 = function (key, nestedValue) {
473 var nestedPath = path ? path + "." + key : key;
474 if (hasIgnoredPaths) {
475 var hasMatches = ignoredPaths.some(function (ignored) {
476 if (ignored instanceof RegExp) {
477 return ignored.test(nestedPath);
478 }
479 return nestedPath === ignored;
480 });
481 if (hasMatches) {
482 return "continue";
483 }
484 }
485 if (!isSerializable(nestedValue)) {
486 return { value: {
487 keyPath: nestedPath,
488 value: nestedValue
489 } };
490 }
491 if (typeof nestedValue === "object") {
492 foundNestedSerializable = findNonSerializableValue(nestedValue, nestedPath, isSerializable, getEntries, ignoredPaths, cache);
493 if (foundNestedSerializable) {
494 return { value: foundNestedSerializable };
495 }
496 }
497 };
498 for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
499 var _c = entries_1[_i], key = _c[0], nestedValue = _c[1];
500 var state_2 = _loop_2(key, nestedValue);
501 if (typeof state_2 === "object")
502 return state_2.value;
503 }
504 if (cache && isNestedFrozen(value))
505 cache.add(value);
506 return false;
507}
508function isNestedFrozen(value) {
509 if (!Object.isFrozen(value))
510 return false;
511 for (var _i = 0, _c = Object.values(value); _i < _c.length; _i++) {
512 var nestedValue = _c[_i];
513 if (typeof nestedValue !== "object" || nestedValue === null)
514 continue;
515 if (!isNestedFrozen(nestedValue))
516 return false;
517 }
518 return true;
519}
520function createSerializableStateInvariantMiddleware(options) {
521 if (options === void 0) { options = {}; }
522 if (process.env.NODE_ENV === "production") {
523 return function () { return function (next) { return function (action) { return next(action); }; }; };
524 }
525 var _c = options.isSerializable, isSerializable = _c === void 0 ? isPlain : _c, getEntries = options.getEntries, _d = options.ignoredActions, ignoredActions = _d === void 0 ? [] : _d, _e = options.ignoredActionPaths, ignoredActionPaths = _e === void 0 ? ["meta.arg", "meta.baseQueryMeta"] : _e, _f = options.ignoredPaths, ignoredPaths = _f === void 0 ? [] : _f, _g = options.warnAfter, warnAfter = _g === void 0 ? 32 : _g, _h = options.ignoreState, ignoreState = _h === void 0 ? false : _h, _j = options.ignoreActions, ignoreActions = _j === void 0 ? false : _j, _k = options.disableCache, disableCache = _k === void 0 ? false : _k;
526 var cache = !disableCache && WeakSet ? new WeakSet() : void 0;
527 return function (storeAPI) { return function (next) { return function (action) {
528 var result = next(action);
529 var measureUtils = getTimeMeasureUtils(warnAfter, "SerializableStateInvariantMiddleware");
530 if (!ignoreActions && !(ignoredActions.length && ignoredActions.indexOf(action.type) !== -1)) {
531 measureUtils.measureTime(function () {
532 var foundActionNonSerializableValue = findNonSerializableValue(action, "", isSerializable, getEntries, ignoredActionPaths, cache);
533 if (foundActionNonSerializableValue) {
534 var keyPath = foundActionNonSerializableValue.keyPath, value = foundActionNonSerializableValue.value;
535 console.error("A non-serializable value was detected in an action, in the path: `" + keyPath + "`. Value:", value, "\nTake a look at the logic that dispatched this action: ", action, "\n(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)", "\n(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)");
536 }
537 });
538 }
539 if (!ignoreState) {
540 measureUtils.measureTime(function () {
541 var state = storeAPI.getState();
542 var foundStateNonSerializableValue = findNonSerializableValue(state, "", isSerializable, getEntries, ignoredPaths, cache);
543 if (foundStateNonSerializableValue) {
544 var keyPath = foundStateNonSerializableValue.keyPath, value = foundStateNonSerializableValue.value;
545 console.error("A non-serializable value was detected in the state, in the path: `" + keyPath + "`. Value:", value, "\nTake a look at the reducer(s) handling this action type: " + action.type + ".\n(See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)");
546 }
547 });
548 measureUtils.warnIfExceeded();
549 }
550 return result;
551 }; }; };
552}
553// src/getDefaultMiddleware.ts
554function isBoolean(x) {
555 return typeof x === "boolean";
556}
557function curryGetDefaultMiddleware() {
558 return function curriedGetDefaultMiddleware(options) {
559 return getDefaultMiddleware(options);
560 };
561}
562function getDefaultMiddleware(options) {
563 if (options === void 0) { options = {}; }
564 var _c = options.thunk, thunk = _c === void 0 ? true : _c, _d = options.immutableCheck, immutableCheck = _d === void 0 ? true : _d, _e = options.serializableCheck, serializableCheck = _e === void 0 ? true : _e, _f = options.actionCreatorCheck, actionCreatorCheck = _f === void 0 ? true : _f;
565 var middlewareArray = new MiddlewareArray();
566 if (thunk) {
567 if (isBoolean(thunk)) {
568 middlewareArray.push(thunkMiddleware);
569 }
570 else {
571 middlewareArray.push(thunkMiddleware.withExtraArgument(thunk.extraArgument));
572 }
573 }
574 if (process.env.NODE_ENV !== "production") {
575 if (immutableCheck) {
576 var immutableOptions = {};
577 if (!isBoolean(immutableCheck)) {
578 immutableOptions = immutableCheck;
579 }
580 middlewareArray.unshift(createImmutableStateInvariantMiddleware(immutableOptions));
581 }
582 if (serializableCheck) {
583 var serializableOptions = {};
584 if (!isBoolean(serializableCheck)) {
585 serializableOptions = serializableCheck;
586 }
587 middlewareArray.push(createSerializableStateInvariantMiddleware(serializableOptions));
588 }
589 if (actionCreatorCheck) {
590 var actionCreatorOptions = {};
591 if (!isBoolean(actionCreatorCheck)) {
592 actionCreatorOptions = actionCreatorCheck;
593 }
594 middlewareArray.unshift(createActionCreatorInvariantMiddleware(actionCreatorOptions));
595 }
596 }
597 return middlewareArray;
598}
599// src/configureStore.ts
600var IS_PRODUCTION = process.env.NODE_ENV === "production";
601function configureStore(options) {
602 var curriedGetDefaultMiddleware = curryGetDefaultMiddleware();
603 var _c = options || {}, _d = _c.reducer, reducer = _d === void 0 ? void 0 : _d, _e = _c.middleware, middleware = _e === void 0 ? curriedGetDefaultMiddleware() : _e, _f = _c.devTools, devTools = _f === void 0 ? true : _f, _g = _c.preloadedState, preloadedState = _g === void 0 ? void 0 : _g, _h = _c.enhancers, enhancers = _h === void 0 ? void 0 : _h;
604 var rootReducer;
605 if (typeof reducer === "function") {
606 rootReducer = reducer;
607 }
608 else if (isPlainObject(reducer)) {
609 rootReducer = combineReducers(reducer);
610 }
611 else {
612 throw new Error('"reducer" is a required argument, and must be a function or an object of functions that can be passed to combineReducers');
613 }
614 var finalMiddleware = middleware;
615 if (typeof finalMiddleware === "function") {
616 finalMiddleware = finalMiddleware(curriedGetDefaultMiddleware);
617 if (!IS_PRODUCTION && !Array.isArray(finalMiddleware)) {
618 throw new Error("when using a middleware builder function, an array of middleware must be returned");
619 }
620 }
621 if (!IS_PRODUCTION && finalMiddleware.some(function (item) { return typeof item !== "function"; })) {
622 throw new Error("each middleware provided to configureStore must be a function");
623 }
624 var middlewareEnhancer = applyMiddleware.apply(void 0, finalMiddleware);
625 var finalCompose = compose2;
626 if (devTools) {
627 finalCompose = composeWithDevTools(__spreadValues({
628 trace: !IS_PRODUCTION
629 }, typeof devTools === "object" && devTools));
630 }
631 var defaultEnhancers = new EnhancerArray(middlewareEnhancer);
632 var storeEnhancers = defaultEnhancers;
633 if (Array.isArray(enhancers)) {
634 storeEnhancers = __spreadArray([middlewareEnhancer], enhancers);
635 }
636 else if (typeof enhancers === "function") {
637 storeEnhancers = enhancers(defaultEnhancers);
638 }
639 var composedEnhancer = finalCompose.apply(void 0, storeEnhancers);
640 return createStore(rootReducer, preloadedState, composedEnhancer);
641}
642// src/createReducer.ts
643import createNextState2, { isDraft as isDraft2, isDraftable as isDraftable2 } from "immer";
644// src/mapBuilders.ts
645function executeReducerBuilderCallback(builderCallback) {
646 var actionsMap = {};
647 var actionMatchers = [];
648 var defaultCaseReducer;
649 var builder = {
650 addCase: function (typeOrActionCreator, reducer) {
651 if (process.env.NODE_ENV !== "production") {
652 if (actionMatchers.length > 0) {
653 throw new Error("`builder.addCase` should only be called before calling `builder.addMatcher`");
654 }
655 if (defaultCaseReducer) {
656 throw new Error("`builder.addCase` should only be called before calling `builder.addDefaultCase`");
657 }
658 }
659 var type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
660 if (!type) {
661 throw new Error("`builder.addCase` cannot be called with an empty action type");
662 }
663 if (type in actionsMap) {
664 throw new Error("`builder.addCase` cannot be called with two reducers for the same action type");
665 }
666 actionsMap[type] = reducer;
667 return builder;
668 },
669 addMatcher: function (matcher, reducer) {
670 if (process.env.NODE_ENV !== "production") {
671 if (defaultCaseReducer) {
672 throw new Error("`builder.addMatcher` should only be called before calling `builder.addDefaultCase`");
673 }
674 }
675 actionMatchers.push({ matcher: matcher, reducer: reducer });
676 return builder;
677 },
678 addDefaultCase: function (reducer) {
679 if (process.env.NODE_ENV !== "production") {
680 if (defaultCaseReducer) {
681 throw new Error("`builder.addDefaultCase` can only be called once");
682 }
683 }
684 defaultCaseReducer = reducer;
685 return builder;
686 }
687 };
688 builderCallback(builder);
689 return [actionsMap, actionMatchers, defaultCaseReducer];
690}
691// src/createReducer.ts
692function isStateFunction(x) {
693 return typeof x === "function";
694}
695var hasWarnedAboutObjectNotation = false;
696function createReducer(initialState, mapOrBuilderCallback, actionMatchers, defaultCaseReducer) {
697 if (actionMatchers === void 0) { actionMatchers = []; }
698 if (process.env.NODE_ENV !== "production") {
699 if (typeof mapOrBuilderCallback === "object") {
700 if (!hasWarnedAboutObjectNotation) {
701 hasWarnedAboutObjectNotation = true;
702 console.warn("The object notation for `createReducer` is deprecated, and will be removed in RTK 2.0. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createReducer");
703 }
704 }
705 }
706 var _c = typeof mapOrBuilderCallback === "function" ? executeReducerBuilderCallback(mapOrBuilderCallback) : [mapOrBuilderCallback, actionMatchers, defaultCaseReducer], actionsMap = _c[0], finalActionMatchers = _c[1], finalDefaultCaseReducer = _c[2];
707 var getInitialState;
708 if (isStateFunction(initialState)) {
709 getInitialState = function () { return freezeDraftable(initialState()); };
710 }
711 else {
712 var frozenInitialState_1 = freezeDraftable(initialState);
713 getInitialState = function () { return frozenInitialState_1; };
714 }
715 function reducer(state, action) {
716 if (state === void 0) { state = getInitialState(); }
717 var caseReducers = __spreadArray([
718 actionsMap[action.type]
719 ], finalActionMatchers.filter(function (_c) {
720 var matcher = _c.matcher;
721 return matcher(action);
722 }).map(function (_c) {
723 var reducer2 = _c.reducer;
724 return reducer2;
725 }));
726 if (caseReducers.filter(function (cr) { return !!cr; }).length === 0) {
727 caseReducers = [finalDefaultCaseReducer];
728 }
729 return caseReducers.reduce(function (previousState, caseReducer) {
730 if (caseReducer) {
731 if (isDraft2(previousState)) {
732 var draft = previousState;
733 var result = caseReducer(draft, action);
734 if (result === void 0) {
735 return previousState;
736 }
737 return result;
738 }
739 else if (!isDraftable2(previousState)) {
740 var result = caseReducer(previousState, action);
741 if (result === void 0) {
742 if (previousState === null) {
743 return previousState;
744 }
745 throw Error("A case reducer on a non-draftable value must not return undefined");
746 }
747 return result;
748 }
749 else {
750 return createNextState2(previousState, function (draft) {
751 return caseReducer(draft, action);
752 });
753 }
754 }
755 return previousState;
756 }, state);
757 }
758 reducer.getInitialState = getInitialState;
759 return reducer;
760}
761// src/createSlice.ts
762var hasWarnedAboutObjectNotation2 = false;
763function getType2(slice, actionKey) {
764 return slice + "/" + actionKey;
765}
766function createSlice(options) {
767 var name = options.name;
768 if (!name) {
769 throw new Error("`name` is a required option for createSlice");
770 }
771 if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
772 if (options.initialState === void 0) {
773 console.error("You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`");
774 }
775 }
776 var initialState = typeof options.initialState == "function" ? options.initialState : freezeDraftable(options.initialState);
777 var reducers = options.reducers || {};
778 var reducerNames = Object.keys(reducers);
779 var sliceCaseReducersByName = {};
780 var sliceCaseReducersByType = {};
781 var actionCreators = {};
782 reducerNames.forEach(function (reducerName) {
783 var maybeReducerWithPrepare = reducers[reducerName];
784 var type = getType2(name, reducerName);
785 var caseReducer;
786 var prepareCallback;
787 if ("reducer" in maybeReducerWithPrepare) {
788 caseReducer = maybeReducerWithPrepare.reducer;
789 prepareCallback = maybeReducerWithPrepare.prepare;
790 }
791 else {
792 caseReducer = maybeReducerWithPrepare;
793 }
794 sliceCaseReducersByName[reducerName] = caseReducer;
795 sliceCaseReducersByType[type] = caseReducer;
796 actionCreators[reducerName] = prepareCallback ? createAction(type, prepareCallback) : createAction(type);
797 });
798 function buildReducer() {
799 if (process.env.NODE_ENV !== "production") {
800 if (typeof options.extraReducers === "object") {
801 if (!hasWarnedAboutObjectNotation2) {
802 hasWarnedAboutObjectNotation2 = true;
803 console.warn("The object notation for `createSlice.extraReducers` is deprecated, and will be removed in RTK 2.0. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createSlice");
804 }
805 }
806 }
807 var _c = typeof options.extraReducers === "function" ? executeReducerBuilderCallback(options.extraReducers) : [options.extraReducers], _d = _c[0], extraReducers = _d === void 0 ? {} : _d, _e = _c[1], actionMatchers = _e === void 0 ? [] : _e, _f = _c[2], defaultCaseReducer = _f === void 0 ? void 0 : _f;
808 var finalCaseReducers = __spreadValues(__spreadValues({}, extraReducers), sliceCaseReducersByType);
809 return createReducer(initialState, function (builder) {
810 for (var key in finalCaseReducers) {
811 builder.addCase(key, finalCaseReducers[key]);
812 }
813 for (var _i = 0, actionMatchers_1 = actionMatchers; _i < actionMatchers_1.length; _i++) {
814 var m = actionMatchers_1[_i];
815 builder.addMatcher(m.matcher, m.reducer);
816 }
817 if (defaultCaseReducer) {
818 builder.addDefaultCase(defaultCaseReducer);
819 }
820 });
821 }
822 var _reducer;
823 return {
824 name: name,
825 reducer: function (state, action) {
826 if (!_reducer)
827 _reducer = buildReducer();
828 return _reducer(state, action);
829 },
830 actions: actionCreators,
831 caseReducers: sliceCaseReducersByName,
832 getInitialState: function () {
833 if (!_reducer)
834 _reducer = buildReducer();
835 return _reducer.getInitialState();
836 }
837 };
838}
839// src/entities/entity_state.ts
840function getInitialEntityState() {
841 return {
842 ids: [],
843 entities: {}
844 };
845}
846function createInitialStateFactory() {
847 function getInitialState(additionalState) {
848 if (additionalState === void 0) { additionalState = {}; }
849 return Object.assign(getInitialEntityState(), additionalState);
850 }
851 return { getInitialState: getInitialState };
852}
853// src/entities/state_selectors.ts
854function createSelectorsFactory() {
855 function getSelectors(selectState) {
856 var selectIds = function (state) { return state.ids; };
857 var selectEntities = function (state) { return state.entities; };
858 var selectAll = createDraftSafeSelector(selectIds, selectEntities, function (ids, entities) { return ids.map(function (id) { return entities[id]; }); });
859 var selectId = function (_, id) { return id; };
860 var selectById = function (entities, id) { return entities[id]; };
861 var selectTotal = createDraftSafeSelector(selectIds, function (ids) { return ids.length; });
862 if (!selectState) {
863 return {
864 selectIds: selectIds,
865 selectEntities: selectEntities,
866 selectAll: selectAll,
867 selectTotal: selectTotal,
868 selectById: createDraftSafeSelector(selectEntities, selectId, selectById)
869 };
870 }
871 var selectGlobalizedEntities = createDraftSafeSelector(selectState, selectEntities);
872 return {
873 selectIds: createDraftSafeSelector(selectState, selectIds),
874 selectEntities: selectGlobalizedEntities,
875 selectAll: createDraftSafeSelector(selectState, selectAll),
876 selectTotal: createDraftSafeSelector(selectState, selectTotal),
877 selectById: createDraftSafeSelector(selectGlobalizedEntities, selectId, selectById)
878 };
879 }
880 return { getSelectors: getSelectors };
881}
882// src/entities/state_adapter.ts
883import createNextState3, { isDraft as isDraft3 } from "immer";
884function createSingleArgumentStateOperator(mutator) {
885 var operator = createStateOperator(function (_, state) { return mutator(state); });
886 return function operation(state) {
887 return operator(state, void 0);
888 };
889}
890function createStateOperator(mutator) {
891 return function operation(state, arg) {
892 function isPayloadActionArgument(arg2) {
893 return isFSA(arg2);
894 }
895 var runMutator = function (draft) {
896 if (isPayloadActionArgument(arg)) {
897 mutator(arg.payload, draft);
898 }
899 else {
900 mutator(arg, draft);
901 }
902 };
903 if (isDraft3(state)) {
904 runMutator(state);
905 return state;
906 }
907 else {
908 return createNextState3(state, runMutator);
909 }
910 };
911}
912// src/entities/utils.ts
913function selectIdValue(entity, selectId) {
914 var key = selectId(entity);
915 if (process.env.NODE_ENV !== "production" && key === void 0) {
916 console.warn("The entity passed to the `selectId` implementation returned undefined.", "You should probably provide your own `selectId` implementation.", "The entity that was passed:", entity, "The `selectId` implementation:", selectId.toString());
917 }
918 return key;
919}
920function ensureEntitiesArray(entities) {
921 if (!Array.isArray(entities)) {
922 entities = Object.values(entities);
923 }
924 return entities;
925}
926function splitAddedUpdatedEntities(newEntities, selectId, state) {
927 newEntities = ensureEntitiesArray(newEntities);
928 var added = [];
929 var updated = [];
930 for (var _i = 0, newEntities_1 = newEntities; _i < newEntities_1.length; _i++) {
931 var entity = newEntities_1[_i];
932 var id = selectIdValue(entity, selectId);
933 if (id in state.entities) {
934 updated.push({ id: id, changes: entity });
935 }
936 else {
937 added.push(entity);
938 }
939 }
940 return [added, updated];
941}
942// src/entities/unsorted_state_adapter.ts
943function createUnsortedStateAdapter(selectId) {
944 function addOneMutably(entity, state) {
945 var key = selectIdValue(entity, selectId);
946 if (key in state.entities) {
947 return;
948 }
949 state.ids.push(key);
950 state.entities[key] = entity;
951 }
952 function addManyMutably(newEntities, state) {
953 newEntities = ensureEntitiesArray(newEntities);
954 for (var _i = 0, newEntities_2 = newEntities; _i < newEntities_2.length; _i++) {
955 var entity = newEntities_2[_i];
956 addOneMutably(entity, state);
957 }
958 }
959 function setOneMutably(entity, state) {
960 var key = selectIdValue(entity, selectId);
961 if (!(key in state.entities)) {
962 state.ids.push(key);
963 }
964 state.entities[key] = entity;
965 }
966 function setManyMutably(newEntities, state) {
967 newEntities = ensureEntitiesArray(newEntities);
968 for (var _i = 0, newEntities_3 = newEntities; _i < newEntities_3.length; _i++) {
969 var entity = newEntities_3[_i];
970 setOneMutably(entity, state);
971 }
972 }
973 function setAllMutably(newEntities, state) {
974 newEntities = ensureEntitiesArray(newEntities);
975 state.ids = [];
976 state.entities = {};
977 addManyMutably(newEntities, state);
978 }
979 function removeOneMutably(key, state) {
980 return removeManyMutably([key], state);
981 }
982 function removeManyMutably(keys, state) {
983 var didMutate = false;
984 keys.forEach(function (key) {
985 if (key in state.entities) {
986 delete state.entities[key];
987 didMutate = true;
988 }
989 });
990 if (didMutate) {
991 state.ids = state.ids.filter(function (id) { return id in state.entities; });
992 }
993 }
994 function removeAllMutably(state) {
995 Object.assign(state, {
996 ids: [],
997 entities: {}
998 });
999 }
1000 function takeNewKey(keys, update, state) {
1001 var original2 = state.entities[update.id];
1002 var updated = Object.assign({}, original2, update.changes);
1003 var newKey = selectIdValue(updated, selectId);
1004 var hasNewKey = newKey !== update.id;
1005 if (hasNewKey) {
1006 keys[update.id] = newKey;
1007 delete state.entities[update.id];
1008 }
1009 state.entities[newKey] = updated;
1010 return hasNewKey;
1011 }
1012 function updateOneMutably(update, state) {
1013 return updateManyMutably([update], state);
1014 }
1015 function updateManyMutably(updates, state) {
1016 var newKeys = {};
1017 var updatesPerEntity = {};
1018 updates.forEach(function (update) {
1019 if (update.id in state.entities) {
1020 updatesPerEntity[update.id] = {
1021 id: update.id,
1022 changes: __spreadValues(__spreadValues({}, updatesPerEntity[update.id] ? updatesPerEntity[update.id].changes : null), update.changes)
1023 };
1024 }
1025 });
1026 updates = Object.values(updatesPerEntity);
1027 var didMutateEntities = updates.length > 0;
1028 if (didMutateEntities) {
1029 var didMutateIds = updates.filter(function (update) { return takeNewKey(newKeys, update, state); }).length > 0;
1030 if (didMutateIds) {
1031 state.ids = Object.keys(state.entities);
1032 }
1033 }
1034 }
1035 function upsertOneMutably(entity, state) {
1036 return upsertManyMutably([entity], state);
1037 }
1038 function upsertManyMutably(newEntities, state) {
1039 var _c = splitAddedUpdatedEntities(newEntities, selectId, state), added = _c[0], updated = _c[1];
1040 updateManyMutably(updated, state);
1041 addManyMutably(added, state);
1042 }
1043 return {
1044 removeAll: createSingleArgumentStateOperator(removeAllMutably),
1045 addOne: createStateOperator(addOneMutably),
1046 addMany: createStateOperator(addManyMutably),
1047 setOne: createStateOperator(setOneMutably),
1048 setMany: createStateOperator(setManyMutably),
1049 setAll: createStateOperator(setAllMutably),
1050 updateOne: createStateOperator(updateOneMutably),
1051 updateMany: createStateOperator(updateManyMutably),
1052 upsertOne: createStateOperator(upsertOneMutably),
1053 upsertMany: createStateOperator(upsertManyMutably),
1054 removeOne: createStateOperator(removeOneMutably),
1055 removeMany: createStateOperator(removeManyMutably)
1056 };
1057}
1058// src/entities/sorted_state_adapter.ts
1059function createSortedStateAdapter(selectId, sort) {
1060 var _c = createUnsortedStateAdapter(selectId), removeOne = _c.removeOne, removeMany = _c.removeMany, removeAll = _c.removeAll;
1061 function addOneMutably(entity, state) {
1062 return addManyMutably([entity], state);
1063 }
1064 function addManyMutably(newEntities, state) {
1065 newEntities = ensureEntitiesArray(newEntities);
1066 var models = newEntities.filter(function (model) { return !(selectIdValue(model, selectId) in state.entities); });
1067 if (models.length !== 0) {
1068 merge(models, state);
1069 }
1070 }
1071 function setOneMutably(entity, state) {
1072 return setManyMutably([entity], state);
1073 }
1074 function setManyMutably(newEntities, state) {
1075 newEntities = ensureEntitiesArray(newEntities);
1076 if (newEntities.length !== 0) {
1077 merge(newEntities, state);
1078 }
1079 }
1080 function setAllMutably(newEntities, state) {
1081 newEntities = ensureEntitiesArray(newEntities);
1082 state.entities = {};
1083 state.ids = [];
1084 addManyMutably(newEntities, state);
1085 }
1086 function updateOneMutably(update, state) {
1087 return updateManyMutably([update], state);
1088 }
1089 function updateManyMutably(updates, state) {
1090 var appliedUpdates = false;
1091 for (var _i = 0, updates_1 = updates; _i < updates_1.length; _i++) {
1092 var update = updates_1[_i];
1093 var entity = state.entities[update.id];
1094 if (!entity) {
1095 continue;
1096 }
1097 appliedUpdates = true;
1098 Object.assign(entity, update.changes);
1099 var newId = selectId(entity);
1100 if (update.id !== newId) {
1101 delete state.entities[update.id];
1102 state.entities[newId] = entity;
1103 }
1104 }
1105 if (appliedUpdates) {
1106 resortEntities(state);
1107 }
1108 }
1109 function upsertOneMutably(entity, state) {
1110 return upsertManyMutably([entity], state);
1111 }
1112 function upsertManyMutably(newEntities, state) {
1113 var _c = splitAddedUpdatedEntities(newEntities, selectId, state), added = _c[0], updated = _c[1];
1114 updateManyMutably(updated, state);
1115 addManyMutably(added, state);
1116 }
1117 function areArraysEqual(a, b) {
1118 if (a.length !== b.length) {
1119 return false;
1120 }
1121 for (var i = 0; i < a.length && i < b.length; i++) {
1122 if (a[i] === b[i]) {
1123 continue;
1124 }
1125 return false;
1126 }
1127 return true;
1128 }
1129 function merge(models, state) {
1130 models.forEach(function (model) {
1131 state.entities[selectId(model)] = model;
1132 });
1133 resortEntities(state);
1134 }
1135 function resortEntities(state) {
1136 var allEntities = Object.values(state.entities);
1137 allEntities.sort(sort);
1138 var newSortedIds = allEntities.map(selectId);
1139 var ids = state.ids;
1140 if (!areArraysEqual(ids, newSortedIds)) {
1141 state.ids = newSortedIds;
1142 }
1143 }
1144 return {
1145 removeOne: removeOne,
1146 removeMany: removeMany,
1147 removeAll: removeAll,
1148 addOne: createStateOperator(addOneMutably),
1149 updateOne: createStateOperator(updateOneMutably),
1150 upsertOne: createStateOperator(upsertOneMutably),
1151 setOne: createStateOperator(setOneMutably),
1152 setMany: createStateOperator(setManyMutably),
1153 setAll: createStateOperator(setAllMutably),
1154 addMany: createStateOperator(addManyMutably),
1155 updateMany: createStateOperator(updateManyMutably),
1156 upsertMany: createStateOperator(upsertManyMutably)
1157 };
1158}
1159// src/entities/create_adapter.ts
1160function createEntityAdapter(options) {
1161 if (options === void 0) { options = {}; }
1162 var _c = __spreadValues({
1163 sortComparer: false,
1164 selectId: function (instance) { return instance.id; }
1165 }, options), selectId = _c.selectId, sortComparer = _c.sortComparer;
1166 var stateFactory = createInitialStateFactory();
1167 var selectorsFactory = createSelectorsFactory();
1168 var stateAdapter = sortComparer ? createSortedStateAdapter(selectId, sortComparer) : createUnsortedStateAdapter(selectId);
1169 return __spreadValues(__spreadValues(__spreadValues({
1170 selectId: selectId,
1171 sortComparer: sortComparer
1172 }, stateFactory), selectorsFactory), stateAdapter);
1173}
1174// src/nanoid.ts
1175var urlAlphabet = "ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW";
1176var nanoid = function (size) {
1177 if (size === void 0) { size = 21; }
1178 var id = "";
1179 var i = size;
1180 while (i--) {
1181 id += urlAlphabet[Math.random() * 64 | 0];
1182 }
1183 return id;
1184};
1185// src/createAsyncThunk.ts
1186var commonProperties = [
1187 "name",
1188 "message",
1189 "stack",
1190 "code"
1191];
1192var RejectWithValue = /** @class */ (function () {
1193 function RejectWithValue(payload, meta) {
1194 this.payload = payload;
1195 this.meta = meta;
1196 }
1197 return RejectWithValue;
1198}());
1199var FulfillWithMeta = /** @class */ (function () {
1200 function FulfillWithMeta(payload, meta) {
1201 this.payload = payload;
1202 this.meta = meta;
1203 }
1204 return FulfillWithMeta;
1205}());
1206var miniSerializeError = function (value) {
1207 if (typeof value === "object" && value !== null) {
1208 var simpleError = {};
1209 for (var _i = 0, commonProperties_1 = commonProperties; _i < commonProperties_1.length; _i++) {
1210 var property = commonProperties_1[_i];
1211 if (typeof value[property] === "string") {
1212 simpleError[property] = value[property];
1213 }
1214 }
1215 return simpleError;
1216 }
1217 return { message: String(value) };
1218};
1219var createAsyncThunk = (function () {
1220 function createAsyncThunk2(typePrefix, payloadCreator, options) {
1221 var fulfilled = createAction(typePrefix + "/fulfilled", function (payload, requestId, arg, meta) { return ({
1222 payload: payload,
1223 meta: __spreadProps(__spreadValues({}, meta || {}), {
1224 arg: arg,
1225 requestId: requestId,
1226 requestStatus: "fulfilled"
1227 })
1228 }); });
1229 var pending = createAction(typePrefix + "/pending", function (requestId, arg, meta) { return ({
1230 payload: void 0,
1231 meta: __spreadProps(__spreadValues({}, meta || {}), {
1232 arg: arg,
1233 requestId: requestId,
1234 requestStatus: "pending"
1235 })
1236 }); });
1237 var rejected = createAction(typePrefix + "/rejected", function (error, requestId, arg, payload, meta) { return ({
1238 payload: payload,
1239 error: (options && options.serializeError || miniSerializeError)(error || "Rejected"),
1240 meta: __spreadProps(__spreadValues({}, meta || {}), {
1241 arg: arg,
1242 requestId: requestId,
1243 rejectedWithValue: !!payload,
1244 requestStatus: "rejected",
1245 aborted: (error == null ? void 0 : error.name) === "AbortError",
1246 condition: (error == null ? void 0 : error.name) === "ConditionError"
1247 })
1248 }); });
1249 var displayedWarning = false;
1250 var AC = typeof AbortController !== "undefined" ? AbortController : /** @class */ (function () {
1251 function class_1() {
1252 this.signal = {
1253 aborted: false,
1254 addEventListener: function () {
1255 },
1256 dispatchEvent: function () {
1257 return false;
1258 },
1259 onabort: function () {
1260 },
1261 removeEventListener: function () {
1262 },
1263 reason: void 0,
1264 throwIfAborted: function () {
1265 }
1266 };
1267 }
1268 class_1.prototype.abort = function () {
1269 if (process.env.NODE_ENV !== "production") {
1270 if (!displayedWarning) {
1271 displayedWarning = true;
1272 console.info("This platform does not implement AbortController. \nIf you want to use the AbortController to react to `abort` events, please consider importing a polyfill like 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'.");
1273 }
1274 }
1275 };
1276 return class_1;
1277 }());
1278 function actionCreator(arg) {
1279 return function (dispatch, getState, extra) {
1280 var requestId = (options == null ? void 0 : options.idGenerator) ? options.idGenerator(arg) : nanoid();
1281 var abortController = new AC();
1282 var abortReason;
1283 var started = false;
1284 function abort(reason) {
1285 abortReason = reason;
1286 abortController.abort();
1287 }
1288 var promise2 = function () {
1289 return __async(this, null, function () {
1290 var _a, _b, finalAction, conditionResult, abortedPromise, err_1, skipDispatch;
1291 return __generator(this, function (_c) {
1292 switch (_c.label) {
1293 case 0:
1294 _c.trys.push([0, 4, , 5]);
1295 conditionResult = (_a = options == null ? void 0 : options.condition) == null ? void 0 : _a.call(options, arg, { getState: getState, extra: extra });
1296 if (!isThenable(conditionResult)) return [3 /*break*/, 2];
1297 return [4 /*yield*/, conditionResult];
1298 case 1:
1299 conditionResult = _c.sent();
1300 _c.label = 2;
1301 case 2:
1302 if (conditionResult === false || abortController.signal.aborted) {
1303 throw {
1304 name: "ConditionError",
1305 message: "Aborted due to condition callback returning false."
1306 };
1307 }
1308 started = true;
1309 abortedPromise = new Promise(function (_, reject) { return abortController.signal.addEventListener("abort", function () { return reject({
1310 name: "AbortError",
1311 message: abortReason || "Aborted"
1312 }); }); });
1313 dispatch(pending(requestId, arg, (_b = options == null ? void 0 : options.getPendingMeta) == null ? void 0 : _b.call(options, { requestId: requestId, arg: arg }, { getState: getState, extra: extra })));
1314 return [4 /*yield*/, Promise.race([
1315 abortedPromise,
1316 Promise.resolve(payloadCreator(arg, {
1317 dispatch: dispatch,
1318 getState: getState,
1319 extra: extra,
1320 requestId: requestId,
1321 signal: abortController.signal,
1322 abort: abort,
1323 rejectWithValue: function (value, meta) {
1324 return new RejectWithValue(value, meta);
1325 },
1326 fulfillWithValue: function (value, meta) {
1327 return new FulfillWithMeta(value, meta);
1328 }
1329 })).then(function (result) {
1330 if (result instanceof RejectWithValue) {
1331 throw result;
1332 }
1333 if (result instanceof FulfillWithMeta) {
1334 return fulfilled(result.payload, requestId, arg, result.meta);
1335 }
1336 return fulfilled(result, requestId, arg);
1337 })
1338 ])];
1339 case 3:
1340 finalAction = _c.sent();
1341 return [3 /*break*/, 5];
1342 case 4:
1343 err_1 = _c.sent();
1344 finalAction = err_1 instanceof RejectWithValue ? rejected(null, requestId, arg, err_1.payload, err_1.meta) : rejected(err_1, requestId, arg);
1345 return [3 /*break*/, 5];
1346 case 5:
1347 skipDispatch = options && !options.dispatchConditionRejection && rejected.match(finalAction) && finalAction.meta.condition;
1348 if (!skipDispatch) {
1349 dispatch(finalAction);
1350 }
1351 return [2 /*return*/, finalAction];
1352 }
1353 });
1354 });
1355 }();
1356 return Object.assign(promise2, {
1357 abort: abort,
1358 requestId: requestId,
1359 arg: arg,
1360 unwrap: function () {
1361 return promise2.then(unwrapResult);
1362 }
1363 });
1364 };
1365 }
1366 return Object.assign(actionCreator, {
1367 pending: pending,
1368 rejected: rejected,
1369 fulfilled: fulfilled,
1370 typePrefix: typePrefix
1371 });
1372 }
1373 createAsyncThunk2.withTypes = function () { return createAsyncThunk2; };
1374 return createAsyncThunk2;
1375})();
1376function unwrapResult(action) {
1377 if (action.meta && action.meta.rejectedWithValue) {
1378 throw action.payload;
1379 }
1380 if (action.error) {
1381 throw action.error;
1382 }
1383 return action.payload;
1384}
1385function isThenable(value) {
1386 return value !== null && typeof value === "object" && typeof value.then === "function";
1387}
1388// src/matchers.ts
1389var matches = function (matcher, action) {
1390 if (hasMatchFunction(matcher)) {
1391 return matcher.match(action);
1392 }
1393 else {
1394 return matcher(action);
1395 }
1396};
1397function isAnyOf() {
1398 var matchers = [];
1399 for (var _i = 0; _i < arguments.length; _i++) {
1400 matchers[_i] = arguments[_i];
1401 }
1402 return function (action) {
1403 return matchers.some(function (matcher) { return matches(matcher, action); });
1404 };
1405}
1406function isAllOf() {
1407 var matchers = [];
1408 for (var _i = 0; _i < arguments.length; _i++) {
1409 matchers[_i] = arguments[_i];
1410 }
1411 return function (action) {
1412 return matchers.every(function (matcher) { return matches(matcher, action); });
1413 };
1414}
1415function hasExpectedRequestMetadata(action, validStatus) {
1416 if (!action || !action.meta)
1417 return false;
1418 var hasValidRequestId = typeof action.meta.requestId === "string";
1419 var hasValidRequestStatus = validStatus.indexOf(action.meta.requestStatus) > -1;
1420 return hasValidRequestId && hasValidRequestStatus;
1421}
1422function isAsyncThunkArray(a) {
1423 return typeof a[0] === "function" && "pending" in a[0] && "fulfilled" in a[0] && "rejected" in a[0];
1424}
1425function isPending() {
1426 var asyncThunks = [];
1427 for (var _i = 0; _i < arguments.length; _i++) {
1428 asyncThunks[_i] = arguments[_i];
1429 }
1430 if (asyncThunks.length === 0) {
1431 return function (action) { return hasExpectedRequestMetadata(action, ["pending"]); };
1432 }
1433 if (!isAsyncThunkArray(asyncThunks)) {
1434 return isPending()(asyncThunks[0]);
1435 }
1436 return function (action) {
1437 var matchers = asyncThunks.map(function (asyncThunk) { return asyncThunk.pending; });
1438 var combinedMatcher = isAnyOf.apply(void 0, matchers);
1439 return combinedMatcher(action);
1440 };
1441}
1442function isRejected() {
1443 var asyncThunks = [];
1444 for (var _i = 0; _i < arguments.length; _i++) {
1445 asyncThunks[_i] = arguments[_i];
1446 }
1447 if (asyncThunks.length === 0) {
1448 return function (action) { return hasExpectedRequestMetadata(action, ["rejected"]); };
1449 }
1450 if (!isAsyncThunkArray(asyncThunks)) {
1451 return isRejected()(asyncThunks[0]);
1452 }
1453 return function (action) {
1454 var matchers = asyncThunks.map(function (asyncThunk) { return asyncThunk.rejected; });
1455 var combinedMatcher = isAnyOf.apply(void 0, matchers);
1456 return combinedMatcher(action);
1457 };
1458}
1459function isRejectedWithValue() {
1460 var asyncThunks = [];
1461 for (var _i = 0; _i < arguments.length; _i++) {
1462 asyncThunks[_i] = arguments[_i];
1463 }
1464 var hasFlag = function (action) {
1465 return action && action.meta && action.meta.rejectedWithValue;
1466 };
1467 if (asyncThunks.length === 0) {
1468 return function (action) {
1469 var combinedMatcher = isAllOf(isRejected.apply(void 0, asyncThunks), hasFlag);
1470 return combinedMatcher(action);
1471 };
1472 }
1473 if (!isAsyncThunkArray(asyncThunks)) {
1474 return isRejectedWithValue()(asyncThunks[0]);
1475 }
1476 return function (action) {
1477 var combinedMatcher = isAllOf(isRejected.apply(void 0, asyncThunks), hasFlag);
1478 return combinedMatcher(action);
1479 };
1480}
1481function isFulfilled() {
1482 var asyncThunks = [];
1483 for (var _i = 0; _i < arguments.length; _i++) {
1484 asyncThunks[_i] = arguments[_i];
1485 }
1486 if (asyncThunks.length === 0) {
1487 return function (action) { return hasExpectedRequestMetadata(action, ["fulfilled"]); };
1488 }
1489 if (!isAsyncThunkArray(asyncThunks)) {
1490 return isFulfilled()(asyncThunks[0]);
1491 }
1492 return function (action) {
1493 var matchers = asyncThunks.map(function (asyncThunk) { return asyncThunk.fulfilled; });
1494 var combinedMatcher = isAnyOf.apply(void 0, matchers);
1495 return combinedMatcher(action);
1496 };
1497}
1498function isAsyncThunkAction() {
1499 var asyncThunks = [];
1500 for (var _i = 0; _i < arguments.length; _i++) {
1501 asyncThunks[_i] = arguments[_i];
1502 }
1503 if (asyncThunks.length === 0) {
1504 return function (action) { return hasExpectedRequestMetadata(action, ["pending", "fulfilled", "rejected"]); };
1505 }
1506 if (!isAsyncThunkArray(asyncThunks)) {
1507 return isAsyncThunkAction()(asyncThunks[0]);
1508 }
1509 return function (action) {
1510 var matchers = [];
1511 for (var _i = 0, asyncThunks_1 = asyncThunks; _i < asyncThunks_1.length; _i++) {
1512 var asyncThunk = asyncThunks_1[_i];
1513 matchers.push(asyncThunk.pending, asyncThunk.rejected, asyncThunk.fulfilled);
1514 }
1515 var combinedMatcher = isAnyOf.apply(void 0, matchers);
1516 return combinedMatcher(action);
1517 };
1518}
1519// src/listenerMiddleware/utils.ts
1520var assertFunction = function (func, expected) {
1521 if (typeof func !== "function") {
1522 throw new TypeError(expected + " is not a function");
1523 }
1524};
1525var noop = function () {
1526};
1527var catchRejection = function (promise2, onError) {
1528 if (onError === void 0) { onError = noop; }
1529 promise2.catch(onError);
1530 return promise2;
1531};
1532var addAbortSignalListener = function (abortSignal, callback) {
1533 abortSignal.addEventListener("abort", callback, { once: true });
1534 return function () { return abortSignal.removeEventListener("abort", callback); };
1535};
1536var abortControllerWithReason = function (abortController, reason) {
1537 var signal = abortController.signal;
1538 if (signal.aborted) {
1539 return;
1540 }
1541 if (!("reason" in signal)) {
1542 Object.defineProperty(signal, "reason", {
1543 enumerable: true,
1544 value: reason,
1545 configurable: true,
1546 writable: true
1547 });
1548 }
1549 ;
1550 abortController.abort(reason);
1551};
1552// src/listenerMiddleware/exceptions.ts
1553var task = "task";
1554var listener = "listener";
1555var completed = "completed";
1556var cancelled = "cancelled";
1557var taskCancelled = "task-" + cancelled;
1558var taskCompleted = "task-" + completed;
1559var listenerCancelled = listener + "-" + cancelled;
1560var listenerCompleted = listener + "-" + completed;
1561var TaskAbortError = /** @class */ (function () {
1562 function TaskAbortError(code) {
1563 this.code = code;
1564 this.name = "TaskAbortError";
1565 this.message = task + " " + cancelled + " (reason: " + code + ")";
1566 }
1567 return TaskAbortError;
1568}());
1569// src/listenerMiddleware/task.ts
1570var validateActive = function (signal) {
1571 if (signal.aborted) {
1572 throw new TaskAbortError(signal.reason);
1573 }
1574};
1575function raceWithSignal(signal, promise2) {
1576 var cleanup = noop;
1577 return new Promise(function (resolve, reject) {
1578 var notifyRejection = function () { return reject(new TaskAbortError(signal.reason)); };
1579 if (signal.aborted) {
1580 notifyRejection();
1581 return;
1582 }
1583 cleanup = addAbortSignalListener(signal, notifyRejection);
1584 promise2.finally(function () { return cleanup(); }).then(resolve, reject);
1585 }).finally(function () {
1586 cleanup = noop;
1587 });
1588}
1589var runTask = function (task2, cleanUp) { return __async(void 0, null, function () {
1590 var value, error_1;
1591 return __generator(this, function (_c) {
1592 switch (_c.label) {
1593 case 0:
1594 _c.trys.push([0, 3, 4, 5]);
1595 return [4 /*yield*/, Promise.resolve()];
1596 case 1:
1597 _c.sent();
1598 return [4 /*yield*/, task2()];
1599 case 2:
1600 value = _c.sent();
1601 return [2 /*return*/, {
1602 status: "ok",
1603 value: value
1604 }];
1605 case 3:
1606 error_1 = _c.sent();
1607 return [2 /*return*/, {
1608 status: error_1 instanceof TaskAbortError ? "cancelled" : "rejected",
1609 error: error_1
1610 }];
1611 case 4:
1612 cleanUp == null ? void 0 : cleanUp();
1613 return [7 /*endfinally*/];
1614 case 5: return [2 /*return*/];
1615 }
1616 });
1617}); };
1618var createPause = function (signal) {
1619 return function (promise2) {
1620 return catchRejection(raceWithSignal(signal, promise2).then(function (output) {
1621 validateActive(signal);
1622 return output;
1623 }));
1624 };
1625};
1626var createDelay = function (signal) {
1627 var pause = createPause(signal);
1628 return function (timeoutMs) {
1629 return pause(new Promise(function (resolve) { return setTimeout(resolve, timeoutMs); }));
1630 };
1631};
1632// src/listenerMiddleware/index.ts
1633var assign = Object.assign;
1634var INTERNAL_NIL_TOKEN = {};
1635var alm = "listenerMiddleware";
1636var createFork = function (parentAbortSignal, parentBlockingPromises) {
1637 var linkControllers = function (controller) { return addAbortSignalListener(parentAbortSignal, function () { return abortControllerWithReason(controller, parentAbortSignal.reason); }); };
1638 return function (taskExecutor, opts) {
1639 assertFunction(taskExecutor, "taskExecutor");
1640 var childAbortController = new AbortController();
1641 linkControllers(childAbortController);
1642 var result = runTask(function () { return __async(void 0, null, function () {
1643 var result2;
1644 return __generator(this, function (_c) {
1645 switch (_c.label) {
1646 case 0:
1647 validateActive(parentAbortSignal);
1648 validateActive(childAbortController.signal);
1649 return [4 /*yield*/, taskExecutor({
1650 pause: createPause(childAbortController.signal),
1651 delay: createDelay(childAbortController.signal),
1652 signal: childAbortController.signal
1653 })];
1654 case 1:
1655 result2 = _c.sent();
1656 validateActive(childAbortController.signal);
1657 return [2 /*return*/, result2];
1658 }
1659 });
1660 }); }, function () { return abortControllerWithReason(childAbortController, taskCompleted); });
1661 if (opts == null ? void 0 : opts.autoJoin) {
1662 parentBlockingPromises.push(result);
1663 }
1664 return {
1665 result: createPause(parentAbortSignal)(result),
1666 cancel: function () {
1667 abortControllerWithReason(childAbortController, taskCancelled);
1668 }
1669 };
1670 };
1671};
1672var createTakePattern = function (startListening, signal) {
1673 var take = function (predicate, timeout) { return __async(void 0, null, function () {
1674 var unsubscribe, tuplePromise, promises, output;
1675 return __generator(this, function (_c) {
1676 switch (_c.label) {
1677 case 0:
1678 validateActive(signal);
1679 unsubscribe = function () {
1680 };
1681 tuplePromise = new Promise(function (resolve, reject) {
1682 var stopListening = startListening({
1683 predicate: predicate,
1684 effect: function (action, listenerApi) {
1685 listenerApi.unsubscribe();
1686 resolve([
1687 action,
1688 listenerApi.getState(),
1689 listenerApi.getOriginalState()
1690 ]);
1691 }
1692 });
1693 unsubscribe = function () {
1694 stopListening();
1695 reject();
1696 };
1697 });
1698 promises = [
1699 tuplePromise
1700 ];
1701 if (timeout != null) {
1702 promises.push(new Promise(function (resolve) { return setTimeout(resolve, timeout, null); }));
1703 }
1704 _c.label = 1;
1705 case 1:
1706 _c.trys.push([1, , 3, 4]);
1707 return [4 /*yield*/, raceWithSignal(signal, Promise.race(promises))];
1708 case 2:
1709 output = _c.sent();
1710 validateActive(signal);
1711 return [2 /*return*/, output];
1712 case 3:
1713 unsubscribe();
1714 return [7 /*endfinally*/];
1715 case 4: return [2 /*return*/];
1716 }
1717 });
1718 }); };
1719 return function (predicate, timeout) { return catchRejection(take(predicate, timeout)); };
1720};
1721var getListenerEntryPropsFrom = function (options) {
1722 var type = options.type, actionCreator = options.actionCreator, matcher = options.matcher, predicate = options.predicate, effect = options.effect;
1723 if (type) {
1724 predicate = createAction(type).match;
1725 }
1726 else if (actionCreator) {
1727 type = actionCreator.type;
1728 predicate = actionCreator.match;
1729 }
1730 else if (matcher) {
1731 predicate = matcher;
1732 }
1733 else if (predicate) {
1734 }
1735 else {
1736 throw new Error("Creating or removing a listener requires one of the known fields for matching an action");
1737 }
1738 assertFunction(effect, "options.listener");
1739 return { predicate: predicate, type: type, effect: effect };
1740};
1741var createListenerEntry = function (options) {
1742 var _c = getListenerEntryPropsFrom(options), type = _c.type, predicate = _c.predicate, effect = _c.effect;
1743 var id = nanoid();
1744 var entry = {
1745 id: id,
1746 effect: effect,
1747 type: type,
1748 predicate: predicate,
1749 pending: new Set(),
1750 unsubscribe: function () {
1751 throw new Error("Unsubscribe not initialized");
1752 }
1753 };
1754 return entry;
1755};
1756var cancelActiveListeners = function (entry) {
1757 entry.pending.forEach(function (controller) {
1758 abortControllerWithReason(controller, listenerCancelled);
1759 });
1760};
1761var createClearListenerMiddleware = function (listenerMap) {
1762 return function () {
1763 listenerMap.forEach(cancelActiveListeners);
1764 listenerMap.clear();
1765 };
1766};
1767var safelyNotifyError = function (errorHandler, errorToNotify, errorInfo) {
1768 try {
1769 errorHandler(errorToNotify, errorInfo);
1770 }
1771 catch (errorHandlerError) {
1772 setTimeout(function () {
1773 throw errorHandlerError;
1774 }, 0);
1775 }
1776};
1777var addListener = createAction(alm + "/add");
1778var clearAllListeners = createAction(alm + "/removeAll");
1779var removeListener = createAction(alm + "/remove");
1780var defaultErrorHandler = function () {
1781 var args = [];
1782 for (var _i = 0; _i < arguments.length; _i++) {
1783 args[_i] = arguments[_i];
1784 }
1785 console.error.apply(console, __spreadArray([alm + "/error"], args));
1786};
1787function createListenerMiddleware(middlewareOptions) {
1788 var _this = this;
1789 if (middlewareOptions === void 0) { middlewareOptions = {}; }
1790 var listenerMap = new Map();
1791 var extra = middlewareOptions.extra, _c = middlewareOptions.onError, onError = _c === void 0 ? defaultErrorHandler : _c;
1792 assertFunction(onError, "onError");
1793 var insertEntry = function (entry) {
1794 entry.unsubscribe = function () { return listenerMap.delete(entry.id); };
1795 listenerMap.set(entry.id, entry);
1796 return function (cancelOptions) {
1797 entry.unsubscribe();
1798 if (cancelOptions == null ? void 0 : cancelOptions.cancelActive) {
1799 cancelActiveListeners(entry);
1800 }
1801 };
1802 };
1803 var findListenerEntry = function (comparator) {
1804 for (var _i = 0, _c = Array.from(listenerMap.values()); _i < _c.length; _i++) {
1805 var entry = _c[_i];
1806 if (comparator(entry)) {
1807 return entry;
1808 }
1809 }
1810 return void 0;
1811 };
1812 var startListening = function (options) {
1813 var entry = findListenerEntry(function (existingEntry) { return existingEntry.effect === options.effect; });
1814 if (!entry) {
1815 entry = createListenerEntry(options);
1816 }
1817 return insertEntry(entry);
1818 };
1819 var stopListening = function (options) {
1820 var _c = getListenerEntryPropsFrom(options), type = _c.type, effect = _c.effect, predicate = _c.predicate;
1821 var entry = findListenerEntry(function (entry2) {
1822 var matchPredicateOrType = typeof type === "string" ? entry2.type === type : entry2.predicate === predicate;
1823 return matchPredicateOrType && entry2.effect === effect;
1824 });
1825 if (entry) {
1826 entry.unsubscribe();
1827 if (options.cancelActive) {
1828 cancelActiveListeners(entry);
1829 }
1830 }
1831 return !!entry;
1832 };
1833 var notifyListener = function (entry, action, api, getOriginalState) { return __async(_this, null, function () {
1834 var internalTaskController, take, autoJoinPromises, listenerError_1;
1835 return __generator(this, function (_c) {
1836 switch (_c.label) {
1837 case 0:
1838 internalTaskController = new AbortController();
1839 take = createTakePattern(startListening, internalTaskController.signal);
1840 autoJoinPromises = [];
1841 _c.label = 1;
1842 case 1:
1843 _c.trys.push([1, 3, 4, 6]);
1844 entry.pending.add(internalTaskController);
1845 return [4 /*yield*/, Promise.resolve(entry.effect(action, assign({}, api, {
1846 getOriginalState: getOriginalState,
1847 condition: function (predicate, timeout) { return take(predicate, timeout).then(Boolean); },
1848 take: take,
1849 delay: createDelay(internalTaskController.signal),
1850 pause: createPause(internalTaskController.signal),
1851 extra: extra,
1852 signal: internalTaskController.signal,
1853 fork: createFork(internalTaskController.signal, autoJoinPromises),
1854 unsubscribe: entry.unsubscribe,
1855 subscribe: function () {
1856 listenerMap.set(entry.id, entry);
1857 },
1858 cancelActiveListeners: function () {
1859 entry.pending.forEach(function (controller, _, set) {
1860 if (controller !== internalTaskController) {
1861 abortControllerWithReason(controller, listenerCancelled);
1862 set.delete(controller);
1863 }
1864 });
1865 }
1866 })))];
1867 case 2:
1868 _c.sent();
1869 return [3 /*break*/, 6];
1870 case 3:
1871 listenerError_1 = _c.sent();
1872 if (!(listenerError_1 instanceof TaskAbortError)) {
1873 safelyNotifyError(onError, listenerError_1, {
1874 raisedBy: "effect"
1875 });
1876 }
1877 return [3 /*break*/, 6];
1878 case 4: return [4 /*yield*/, Promise.allSettled(autoJoinPromises)];
1879 case 5:
1880 _c.sent();
1881 abortControllerWithReason(internalTaskController, listenerCompleted);
1882 entry.pending.delete(internalTaskController);
1883 return [7 /*endfinally*/];
1884 case 6: return [2 /*return*/];
1885 }
1886 });
1887 }); };
1888 var clearListenerMiddleware = createClearListenerMiddleware(listenerMap);
1889 var middleware = function (api) { return function (next) { return function (action) {
1890 if (!isAction(action)) {
1891 return next(action);
1892 }
1893 if (addListener.match(action)) {
1894 return startListening(action.payload);
1895 }
1896 if (clearAllListeners.match(action)) {
1897 clearListenerMiddleware();
1898 return;
1899 }
1900 if (removeListener.match(action)) {
1901 return stopListening(action.payload);
1902 }
1903 var originalState = api.getState();
1904 var getOriginalState = function () {
1905 if (originalState === INTERNAL_NIL_TOKEN) {
1906 throw new Error(alm + ": getOriginalState can only be called synchronously");
1907 }
1908 return originalState;
1909 };
1910 var result;
1911 try {
1912 result = next(action);
1913 if (listenerMap.size > 0) {
1914 var currentState = api.getState();
1915 var listenerEntries = Array.from(listenerMap.values());
1916 for (var _i = 0, listenerEntries_1 = listenerEntries; _i < listenerEntries_1.length; _i++) {
1917 var entry = listenerEntries_1[_i];
1918 var runListener = false;
1919 try {
1920 runListener = entry.predicate(action, currentState, originalState);
1921 }
1922 catch (predicateError) {
1923 runListener = false;
1924 safelyNotifyError(onError, predicateError, {
1925 raisedBy: "predicate"
1926 });
1927 }
1928 if (!runListener) {
1929 continue;
1930 }
1931 notifyListener(entry, action, api, getOriginalState);
1932 }
1933 }
1934 }
1935 finally {
1936 originalState = INTERNAL_NIL_TOKEN;
1937 }
1938 return result;
1939 }; }; };
1940 return {
1941 middleware: middleware,
1942 startListening: startListening,
1943 stopListening: stopListening,
1944 clearListeners: clearListenerMiddleware
1945 };
1946}
1947// src/autoBatchEnhancer.ts
1948var SHOULD_AUTOBATCH = "RTK_autoBatch";
1949var prepareAutoBatched = function () { return function (payload) {
1950 var _c;
1951 return ({
1952 payload: payload,
1953 meta: (_c = {}, _c[SHOULD_AUTOBATCH] = true, _c)
1954 });
1955}; };
1956var promise;
1957var 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 () {
1958 throw err;
1959}, 0); }); };
1960var createQueueWithTimer = function (timeout) {
1961 return function (notify) {
1962 setTimeout(notify, timeout);
1963 };
1964};
1965var rAF = typeof window !== "undefined" && window.requestAnimationFrame ? window.requestAnimationFrame : createQueueWithTimer(10);
1966var autoBatchEnhancer = function (options) {
1967 if (options === void 0) { options = { type: "raf" }; }
1968 return function (next) { return function () {
1969 var args = [];
1970 for (var _i = 0; _i < arguments.length; _i++) {
1971 args[_i] = arguments[_i];
1972 }
1973 var store = next.apply(void 0, args);
1974 var notifying = true;
1975 var shouldNotifyAtEndOfTick = false;
1976 var notificationQueued = false;
1977 var listeners = new Set();
1978 var queueCallback = options.type === "tick" ? queueMicrotaskShim : options.type === "raf" ? rAF : options.type === "callback" ? options.queueNotification : createQueueWithTimer(options.timeout);
1979 var notifyListeners = function () {
1980 notificationQueued = false;
1981 if (shouldNotifyAtEndOfTick) {
1982 shouldNotifyAtEndOfTick = false;
1983 listeners.forEach(function (l) { return l(); });
1984 }
1985 };
1986 return Object.assign({}, store, {
1987 subscribe: function (listener2) {
1988 var wrappedListener = function () { return notifying && listener2(); };
1989 var unsubscribe = store.subscribe(wrappedListener);
1990 listeners.add(listener2);
1991 return function () {
1992 unsubscribe();
1993 listeners.delete(listener2);
1994 };
1995 },
1996 dispatch: function (action) {
1997 var _a;
1998 try {
1999 notifying = !((_a = action == null ? void 0 : action.meta) == null ? void 0 : _a[SHOULD_AUTOBATCH]);
2000 shouldNotifyAtEndOfTick = !notifying;
2001 if (shouldNotifyAtEndOfTick) {
2002 if (!notificationQueued) {
2003 notificationQueued = true;
2004 queueCallback(notifyListeners);
2005 }
2006 }
2007 return store.dispatch(action);
2008 }
2009 finally {
2010 notifying = true;
2011 }
2012 }
2013 });
2014 }; };
2015};
2016// src/index.ts
2017enableES5();
2018export { EnhancerArray, MiddlewareArray, SHOULD_AUTOBATCH, TaskAbortError, addListener, autoBatchEnhancer, clearAllListeners, configureStore, createAction, createActionCreatorInvariantMiddleware, createAsyncThunk, createDraftSafeSelector, createEntityAdapter, createImmutableStateInvariantMiddleware, createListenerMiddleware, default2 as createNextState, createReducer, createSelector2 as createSelector, createSerializableStateInvariantMiddleware, createSlice, current2 as current, findNonSerializableValue, freeze, getDefaultMiddleware, getType, isAction, isActionCreator, isAllOf, isAnyOf, isAsyncThunkAction, isDraft4 as isDraft, isFSA as isFluxStandardAction, isFulfilled, isImmutableDefault, isPending, isPlain, isPlainObject, isRejected, isRejectedWithValue, miniSerializeError, nanoid, original, prepareAutoBatched, removeListener, unwrapResult };
2019//# sourceMappingURL=redux-toolkit.esm.js.map
\No newline at end of file