UNPKG

60.8 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 __create = Object.create;
49var __defProp = Object.defineProperty;
50var __defProps = Object.defineProperties;
51var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
52var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
53var __getOwnPropNames = Object.getOwnPropertyNames;
54var __getOwnPropSymbols = Object.getOwnPropertySymbols;
55var __getProtoOf = Object.getPrototypeOf;
56var __hasOwnProp = Object.prototype.hasOwnProperty;
57var __propIsEnum = Object.prototype.propertyIsEnumerable;
58var __defNormalProp = function (obj, key, value) { return key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value: value }) : obj[key] = value; };
59var __spreadValues = function (a, b) {
60 for (var prop in b || (b = {}))
61 if (__hasOwnProp.call(b, prop))
62 __defNormalProp(a, prop, b[prop]);
63 if (__getOwnPropSymbols)
64 for (var _i = 0, _b = __getOwnPropSymbols(b); _i < _b.length; _i++) {
65 var prop = _b[_i];
66 if (__propIsEnum.call(b, prop))
67 __defNormalProp(a, prop, b[prop]);
68 }
69 return a;
70};
71var __spreadProps = function (a, b) { return __defProps(a, __getOwnPropDescs(b)); };
72var __markAsModule = function (target) { return __defProp(target, "__esModule", { value: true }); };
73var __export = function (target, all) {
74 for (var name in all)
75 __defProp(target, name, { get: all[name], enumerable: true });
76};
77var __reExport = function (target, module2, desc) {
78 if (module2 && typeof module2 === "object" || typeof module2 === "function") {
79 var _loop_1 = function (key) {
80 if (!__hasOwnProp.call(target, key) && key !== "default")
81 __defProp(target, key, { get: function () { return module2[key]; }, enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
82 };
83 for (var _i = 0, _b = __getOwnPropNames(module2); _i < _b.length; _i++) {
84 var key = _b[_i];
85 _loop_1(key);
86 }
87 }
88 return target;
89};
90var __toModule = function (module2) {
91 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);
92};
93var __async = function (__this, __arguments, generator) {
94 return new Promise(function (resolve, reject) {
95 var fulfilled = function (value) {
96 try {
97 step(generator.next(value));
98 }
99 catch (e) {
100 reject(e);
101 }
102 };
103 var rejected = function (value) {
104 try {
105 step(generator.throw(value));
106 }
107 catch (e) {
108 reject(e);
109 }
110 };
111 var step = function (x) { return x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); };
112 step((generator = generator.apply(__this, __arguments)).next());
113 });
114};
115// src/index.ts
116__markAsModule(exports);
117__export(exports, {
118 MiddlewareArray: function () { return MiddlewareArray; },
119 configureStore: function () { return configureStore; },
120 createAction: function () { return createAction; },
121 createAsyncThunk: function () { return createAsyncThunk; },
122 createDraftSafeSelector: function () { return createDraftSafeSelector; },
123 createEntityAdapter: function () { return createEntityAdapter; },
124 createImmutableStateInvariantMiddleware: function () { return createImmutableStateInvariantMiddleware; },
125 createNextState: function () { return import_immer5.default; },
126 createReducer: function () { return createReducer; },
127 createSelector: function () { return import_reselect2.createSelector; },
128 createSerializableStateInvariantMiddleware: function () { return createSerializableStateInvariantMiddleware; },
129 createSlice: function () { return createSlice; },
130 current: function () { return import_immer5.current; },
131 findNonSerializableValue: function () { return findNonSerializableValue; },
132 freeze: function () { return import_immer5.freeze; },
133 getDefaultMiddleware: function () { return getDefaultMiddleware; },
134 getType: function () { return getType; },
135 isAllOf: function () { return isAllOf; },
136 isAnyOf: function () { return isAnyOf; },
137 isAsyncThunkAction: function () { return isAsyncThunkAction; },
138 isDraft: function () { return import_immer5.isDraft; },
139 isFulfilled: function () { return isFulfilled; },
140 isImmutableDefault: function () { return isImmutableDefault; },
141 isPending: function () { return isPending; },
142 isPlain: function () { return isPlain; },
143 isPlainObject: function () { return isPlainObject; },
144 isRejected: function () { return isRejected; },
145 isRejectedWithValue: function () { return isRejectedWithValue; },
146 miniSerializeError: function () { return miniSerializeError; },
147 nanoid: function () { return nanoid; },
148 original: function () { return import_immer5.original; },
149 unwrapResult: function () { return unwrapResult; }
150});
151var import_immer4 = __toModule(require("immer"));
152__reExport(exports, __toModule(require("redux")));
153var import_immer5 = __toModule(require("immer"));
154var import_reselect2 = __toModule(require("reselect"));
155// src/createDraftSafeSelector.ts
156var import_immer = __toModule(require("immer"));
157var import_reselect = __toModule(require("reselect"));
158var createDraftSafeSelector = function () {
159 var args = [];
160 for (var _i = 0; _i < arguments.length; _i++) {
161 args[_i] = arguments[_i];
162 }
163 var selector = (0, import_reselect.createSelector).apply(void 0, args);
164 var wrappedSelector = function (value) {
165 var rest = [];
166 for (var _i = 1; _i < arguments.length; _i++) {
167 rest[_i - 1] = arguments[_i];
168 }
169 return selector.apply(void 0, __spreadArray([(0, import_immer.isDraft)(value) ? (0, import_immer.current)(value) : value], rest));
170 };
171 return wrappedSelector;
172};
173// src/configureStore.ts
174var import_redux2 = __toModule(require("redux"));
175// src/devtoolsExtension.ts
176var import_redux = __toModule(require("redux"));
177var composeWithDevTools = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : function () {
178 if (arguments.length === 0)
179 return void 0;
180 if (typeof arguments[0] === "object")
181 return import_redux.compose;
182 return import_redux.compose.apply(null, arguments);
183};
184var devToolsEnhancer = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ : function () {
185 return function (noop) {
186 return noop;
187 };
188};
189// src/isPlainObject.ts
190function isPlainObject(value) {
191 if (typeof value !== "object" || value === null)
192 return false;
193 var proto = value;
194 while (Object.getPrototypeOf(proto) !== null) {
195 proto = Object.getPrototypeOf(proto);
196 }
197 return Object.getPrototypeOf(value) === proto;
198}
199// src/getDefaultMiddleware.ts
200var import_redux_thunk = __toModule(require("redux-thunk"));
201// src/utils.ts
202function getTimeMeasureUtils(maxDelay, fnName) {
203 var elapsed = 0;
204 return {
205 measureTime: function (fn) {
206 var started = Date.now();
207 try {
208 return fn();
209 }
210 finally {
211 var finished = Date.now();
212 elapsed += finished - started;
213 }
214 },
215 warnIfExceeded: function () {
216 if (elapsed > maxDelay) {
217 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.");
218 }
219 }
220 };
221}
222var MiddlewareArray = /** @class */ (function (_super) {
223 __extends(MiddlewareArray, _super);
224 function MiddlewareArray() {
225 var args = [];
226 for (var _i = 0; _i < arguments.length; _i++) {
227 args[_i] = arguments[_i];
228 }
229 var _this = _super.apply(this, args) || this;
230 Object.setPrototypeOf(_this, MiddlewareArray.prototype);
231 return _this;
232 }
233 Object.defineProperty(MiddlewareArray, Symbol.species, {
234 get: function () {
235 return MiddlewareArray;
236 },
237 enumerable: false,
238 configurable: true
239 });
240 MiddlewareArray.prototype.concat = function () {
241 var arr = [];
242 for (var _i = 0; _i < arguments.length; _i++) {
243 arr[_i] = arguments[_i];
244 }
245 return _super.prototype.concat.apply(this, arr);
246 };
247 MiddlewareArray.prototype.prepend = function () {
248 var arr = [];
249 for (var _i = 0; _i < arguments.length; _i++) {
250 arr[_i] = arguments[_i];
251 }
252 if (arr.length === 1 && Array.isArray(arr[0])) {
253 return new (MiddlewareArray.bind.apply(MiddlewareArray, __spreadArray([void 0], arr[0].concat(this))))();
254 }
255 return new (MiddlewareArray.bind.apply(MiddlewareArray, __spreadArray([void 0], arr.concat(this))))();
256 };
257 return MiddlewareArray;
258}(Array));
259// src/immutableStateInvariantMiddleware.ts
260var isProduction = false;
261var prefix = "Invariant failed";
262function invariant(condition, message) {
263 if (condition) {
264 return;
265 }
266 if (isProduction) {
267 throw new Error(prefix);
268 }
269 throw new Error(prefix + ": " + (message || ""));
270}
271function stringify(obj, serializer, indent, decycler) {
272 return JSON.stringify(obj, getSerialize(serializer, decycler), indent);
273}
274function getSerialize(serializer, decycler) {
275 var stack = [], keys = [];
276 if (!decycler)
277 decycler = function (_, value) {
278 if (stack[0] === value)
279 return "[Circular ~]";
280 return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
281 };
282 return function (key, value) {
283 if (stack.length > 0) {
284 var thisPos = stack.indexOf(this);
285 ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
286 ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
287 if (~stack.indexOf(value))
288 value = decycler.call(this, key, value);
289 }
290 else
291 stack.push(value);
292 return serializer == null ? value : serializer.call(this, key, value);
293 };
294}
295function isImmutableDefault(value) {
296 return typeof value !== "object" || value === null || typeof value === "undefined" || Object.isFrozen(value);
297}
298function trackForMutations(isImmutable, ignorePaths, obj) {
299 var trackedProperties = trackProperties(isImmutable, ignorePaths, obj);
300 return {
301 detectMutations: function () {
302 return detectMutations(isImmutable, ignorePaths, trackedProperties, obj);
303 }
304 };
305}
306function trackProperties(isImmutable, ignorePaths, obj, path) {
307 if (ignorePaths === void 0) { ignorePaths = []; }
308 if (path === void 0) { path = ""; }
309 var tracked = { value: obj };
310 if (!isImmutable(obj)) {
311 tracked.children = {};
312 for (var key in obj) {
313 var childPath = path ? path + "." + key : key;
314 if (ignorePaths.length && ignorePaths.indexOf(childPath) !== -1) {
315 continue;
316 }
317 tracked.children[key] = trackProperties(isImmutable, ignorePaths, obj[key], childPath);
318 }
319 }
320 return tracked;
321}
322function detectMutations(isImmutable, ignorePaths, trackedProperty, obj, sameParentRef, path) {
323 if (ignorePaths === void 0) { ignorePaths = []; }
324 if (sameParentRef === void 0) { sameParentRef = false; }
325 if (path === void 0) { path = ""; }
326 var prevObj = trackedProperty ? trackedProperty.value : void 0;
327 var sameRef = prevObj === obj;
328 if (sameParentRef && !sameRef && !Number.isNaN(obj)) {
329 return { wasMutated: true, path: path };
330 }
331 if (isImmutable(prevObj) || isImmutable(obj)) {
332 return { wasMutated: false };
333 }
334 var keysToDetect = {};
335 for (var key in trackedProperty.children) {
336 keysToDetect[key] = true;
337 }
338 for (var key in obj) {
339 keysToDetect[key] = true;
340 }
341 for (var key in keysToDetect) {
342 var childPath = path ? path + "." + key : key;
343 if (ignorePaths.length && ignorePaths.indexOf(childPath) !== -1) {
344 continue;
345 }
346 var result = detectMutations(isImmutable, ignorePaths, trackedProperty.children[key], obj[key], sameRef, childPath);
347 if (result.wasMutated) {
348 return result;
349 }
350 }
351 return { wasMutated: false };
352}
353function createImmutableStateInvariantMiddleware(options) {
354 if (options === void 0) { options = {}; }
355 if (false) {
356 return function () { return function (next) { return function (action) { return next(action); }; }; };
357 }
358 var _b = options.isImmutable, isImmutable = _b === void 0 ? isImmutableDefault : _b, ignoredPaths = options.ignoredPaths, _c = options.warnAfter, warnAfter = _c === void 0 ? 32 : _c, ignore = options.ignore;
359 ignoredPaths = ignoredPaths || ignore;
360 var track = trackForMutations.bind(null, isImmutable, ignoredPaths);
361 return function (_b) {
362 var getState = _b.getState;
363 var state = getState();
364 var tracker = track(state);
365 var result;
366 return function (next) { return function (action) {
367 var measureUtils = getTimeMeasureUtils(warnAfter, "ImmutableStateInvariantMiddleware");
368 measureUtils.measureTime(function () {
369 state = getState();
370 result = tracker.detectMutations();
371 tracker = track(state);
372 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)");
373 });
374 var dispatchedAction = next(action);
375 measureUtils.measureTime(function () {
376 state = getState();
377 result = tracker.detectMutations();
378 tracker = track(state);
379 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)");
380 });
381 measureUtils.warnIfExceeded();
382 return dispatchedAction;
383 }; };
384 };
385}
386// src/serializableStateInvariantMiddleware.ts
387function isPlain(val) {
388 var type = typeof val;
389 return type === "undefined" || val === null || type === "string" || type === "boolean" || type === "number" || Array.isArray(val) || isPlainObject(val);
390}
391function findNonSerializableValue(value, path, isSerializable, getEntries, ignoredPaths) {
392 if (path === void 0) { path = ""; }
393 if (isSerializable === void 0) { isSerializable = isPlain; }
394 if (ignoredPaths === void 0) { ignoredPaths = []; }
395 var foundNestedSerializable;
396 if (!isSerializable(value)) {
397 return {
398 keyPath: path || "<root>",
399 value: value
400 };
401 }
402 if (typeof value !== "object" || value === null) {
403 return false;
404 }
405 var entries = getEntries != null ? getEntries(value) : Object.entries(value);
406 var hasIgnoredPaths = ignoredPaths.length > 0;
407 for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
408 var _b = entries_1[_i], key = _b[0], nestedValue = _b[1];
409 var nestedPath = path ? path + "." + key : key;
410 if (hasIgnoredPaths && ignoredPaths.indexOf(nestedPath) >= 0) {
411 continue;
412 }
413 if (!isSerializable(nestedValue)) {
414 return {
415 keyPath: nestedPath,
416 value: nestedValue
417 };
418 }
419 if (typeof nestedValue === "object") {
420 foundNestedSerializable = findNonSerializableValue(nestedValue, nestedPath, isSerializable, getEntries, ignoredPaths);
421 if (foundNestedSerializable) {
422 return foundNestedSerializable;
423 }
424 }
425 }
426 return false;
427}
428function createSerializableStateInvariantMiddleware(options) {
429 if (options === void 0) { options = {}; }
430 if (false) {
431 return function () { return function (next) { return function (action) { return next(action); }; }; };
432 }
433 var _b = options.isSerializable, isSerializable = _b === void 0 ? isPlain : _b, getEntries = options.getEntries, _c = options.ignoredActions, ignoredActions = _c === void 0 ? [] : _c, _d = options.ignoredActionPaths, ignoredActionPaths = _d === void 0 ? ["meta.arg", "meta.baseQueryMeta"] : _d, _e = options.ignoredPaths, ignoredPaths = _e === void 0 ? [] : _e, _f = options.warnAfter, warnAfter = _f === void 0 ? 32 : _f, _g = options.ignoreState, ignoreState = _g === void 0 ? false : _g;
434 return function (storeAPI) { return function (next) { return function (action) {
435 if (ignoredActions.length && ignoredActions.indexOf(action.type) !== -1) {
436 return next(action);
437 }
438 var measureUtils = getTimeMeasureUtils(warnAfter, "SerializableStateInvariantMiddleware");
439 measureUtils.measureTime(function () {
440 var foundActionNonSerializableValue = findNonSerializableValue(action, "", isSerializable, getEntries, ignoredActionPaths);
441 if (foundActionNonSerializableValue) {
442 var keyPath = foundActionNonSerializableValue.keyPath, value = foundActionNonSerializableValue.value;
443 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)");
444 }
445 });
446 var result = next(action);
447 if (!ignoreState) {
448 measureUtils.measureTime(function () {
449 var state = storeAPI.getState();
450 var foundStateNonSerializableValue = findNonSerializableValue(state, "", isSerializable, getEntries, ignoredPaths);
451 if (foundStateNonSerializableValue) {
452 var keyPath = foundStateNonSerializableValue.keyPath, value = foundStateNonSerializableValue.value;
453 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)");
454 }
455 });
456 measureUtils.warnIfExceeded();
457 }
458 return result;
459 }; }; };
460}
461// src/getDefaultMiddleware.ts
462function isBoolean(x) {
463 return typeof x === "boolean";
464}
465function curryGetDefaultMiddleware() {
466 return function curriedGetDefaultMiddleware(options) {
467 return getDefaultMiddleware(options);
468 };
469}
470function getDefaultMiddleware(options) {
471 if (options === void 0) { options = {}; }
472 var _b = options.thunk, thunk = _b === void 0 ? true : _b, _c = options.immutableCheck, immutableCheck = _c === void 0 ? true : _c, _d = options.serializableCheck, serializableCheck = _d === void 0 ? true : _d;
473 var middlewareArray = new MiddlewareArray();
474 if (thunk) {
475 if (isBoolean(thunk)) {
476 middlewareArray.push(import_redux_thunk.default);
477 }
478 else {
479 middlewareArray.push(import_redux_thunk.default.withExtraArgument(thunk.extraArgument));
480 }
481 }
482 if (true) {
483 if (immutableCheck) {
484 var immutableOptions = {};
485 if (!isBoolean(immutableCheck)) {
486 immutableOptions = immutableCheck;
487 }
488 middlewareArray.unshift(createImmutableStateInvariantMiddleware(immutableOptions));
489 }
490 if (serializableCheck) {
491 var serializableOptions = {};
492 if (!isBoolean(serializableCheck)) {
493 serializableOptions = serializableCheck;
494 }
495 middlewareArray.push(createSerializableStateInvariantMiddleware(serializableOptions));
496 }
497 }
498 return middlewareArray;
499}
500// src/configureStore.ts
501var IS_PRODUCTION = false;
502function configureStore(options) {
503 var curriedGetDefaultMiddleware = curryGetDefaultMiddleware();
504 var _b = options || {}, _c = _b.reducer, reducer = _c === void 0 ? void 0 : _c, _d = _b.middleware, middleware = _d === void 0 ? curriedGetDefaultMiddleware() : _d, _e = _b.devTools, devTools = _e === void 0 ? true : _e, _f = _b.preloadedState, preloadedState = _f === void 0 ? void 0 : _f, _g = _b.enhancers, enhancers = _g === void 0 ? void 0 : _g;
505 var rootReducer;
506 if (typeof reducer === "function") {
507 rootReducer = reducer;
508 }
509 else if (isPlainObject(reducer)) {
510 rootReducer = (0, import_redux2.combineReducers)(reducer);
511 }
512 else {
513 throw new Error('"reducer" is a required argument, and must be a function or an object of functions that can be passed to combineReducers');
514 }
515 var finalMiddleware = middleware;
516 if (typeof finalMiddleware === "function") {
517 finalMiddleware = finalMiddleware(curriedGetDefaultMiddleware);
518 if (!IS_PRODUCTION && !Array.isArray(finalMiddleware)) {
519 throw new Error("when using a middleware builder function, an array of middleware must be returned");
520 }
521 }
522 if (!IS_PRODUCTION && finalMiddleware.some(function (item) { return typeof item !== "function"; })) {
523 throw new Error("each middleware provided to configureStore must be a function");
524 }
525 var middlewareEnhancer = (0, import_redux2.applyMiddleware).apply(void 0, finalMiddleware);
526 var finalCompose = import_redux2.compose;
527 if (devTools) {
528 finalCompose = composeWithDevTools(__spreadValues({
529 trace: !IS_PRODUCTION
530 }, typeof devTools === "object" && devTools));
531 }
532 var storeEnhancers = [middlewareEnhancer];
533 if (Array.isArray(enhancers)) {
534 storeEnhancers = __spreadArray([middlewareEnhancer], enhancers);
535 }
536 else if (typeof enhancers === "function") {
537 storeEnhancers = enhancers(storeEnhancers);
538 }
539 var composedEnhancer = finalCompose.apply(void 0, storeEnhancers);
540 return (0, import_redux2.createStore)(rootReducer, preloadedState, composedEnhancer);
541}
542// src/createAction.ts
543function createAction(type, prepareAction) {
544 function actionCreator() {
545 var args = [];
546 for (var _i = 0; _i < arguments.length; _i++) {
547 args[_i] = arguments[_i];
548 }
549 if (prepareAction) {
550 var prepared = prepareAction.apply(void 0, args);
551 if (!prepared) {
552 throw new Error("prepareAction did not return an object");
553 }
554 return __spreadValues(__spreadValues({
555 type: type,
556 payload: prepared.payload
557 }, "meta" in prepared && { meta: prepared.meta }), "error" in prepared && { error: prepared.error });
558 }
559 return { type: type, payload: args[0] };
560 }
561 actionCreator.toString = function () { return "" + type; };
562 actionCreator.type = type;
563 actionCreator.match = function (action) { return action.type === type; };
564 return actionCreator;
565}
566function isFSA(action) {
567 return isPlainObject(action) && typeof action.type === "string" && Object.keys(action).every(isValidKey);
568}
569function isValidKey(key) {
570 return ["type", "payload", "error", "meta"].indexOf(key) > -1;
571}
572function getType(actionCreator) {
573 return "" + actionCreator;
574}
575// src/createReducer.ts
576var import_immer2 = __toModule(require("immer"));
577// src/mapBuilders.ts
578function executeReducerBuilderCallback(builderCallback) {
579 var actionsMap = {};
580 var actionMatchers = [];
581 var defaultCaseReducer;
582 var builder = {
583 addCase: function (typeOrActionCreator, reducer) {
584 if (true) {
585 if (actionMatchers.length > 0) {
586 throw new Error("`builder.addCase` should only be called before calling `builder.addMatcher`");
587 }
588 if (defaultCaseReducer) {
589 throw new Error("`builder.addCase` should only be called before calling `builder.addDefaultCase`");
590 }
591 }
592 var type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
593 if (type in actionsMap) {
594 throw new Error("addCase cannot be called with two reducers for the same action type");
595 }
596 actionsMap[type] = reducer;
597 return builder;
598 },
599 addMatcher: function (matcher, reducer) {
600 if (true) {
601 if (defaultCaseReducer) {
602 throw new Error("`builder.addMatcher` should only be called before calling `builder.addDefaultCase`");
603 }
604 }
605 actionMatchers.push({ matcher: matcher, reducer: reducer });
606 return builder;
607 },
608 addDefaultCase: function (reducer) {
609 if (true) {
610 if (defaultCaseReducer) {
611 throw new Error("`builder.addDefaultCase` can only be called once");
612 }
613 }
614 defaultCaseReducer = reducer;
615 return builder;
616 }
617 };
618 builderCallback(builder);
619 return [actionsMap, actionMatchers, defaultCaseReducer];
620}
621// src/createReducer.ts
622function createReducer(initialState, mapOrBuilderCallback, actionMatchers, defaultCaseReducer) {
623 if (actionMatchers === void 0) { actionMatchers = []; }
624 var _b = typeof mapOrBuilderCallback === "function" ? executeReducerBuilderCallback(mapOrBuilderCallback) : [mapOrBuilderCallback, actionMatchers, defaultCaseReducer], actionsMap = _b[0], finalActionMatchers = _b[1], finalDefaultCaseReducer = _b[2];
625 var frozenInitialState = (0, import_immer2.default)(initialState, function () {
626 });
627 return function (state, action) {
628 if (state === void 0) { state = frozenInitialState; }
629 var caseReducers = __spreadArray([
630 actionsMap[action.type]
631 ], finalActionMatchers.filter(function (_b) {
632 var matcher = _b.matcher;
633 return matcher(action);
634 }).map(function (_b) {
635 var reducer = _b.reducer;
636 return reducer;
637 }));
638 if (caseReducers.filter(function (cr) { return !!cr; }).length === 0) {
639 caseReducers = [finalDefaultCaseReducer];
640 }
641 return caseReducers.reduce(function (previousState, caseReducer) {
642 if (caseReducer) {
643 if ((0, import_immer2.isDraft)(previousState)) {
644 var draft = previousState;
645 var result = caseReducer(draft, action);
646 if (typeof result === "undefined") {
647 return previousState;
648 }
649 return result;
650 }
651 else if (!(0, import_immer2.isDraftable)(previousState)) {
652 var result = caseReducer(previousState, action);
653 if (typeof result === "undefined") {
654 if (previousState === null) {
655 return previousState;
656 }
657 throw Error("A case reducer on a non-draftable value must not return undefined");
658 }
659 return result;
660 }
661 else {
662 return (0, import_immer2.default)(previousState, function (draft) {
663 return caseReducer(draft, action);
664 });
665 }
666 }
667 return previousState;
668 }, state);
669 };
670}
671// src/createSlice.ts
672function getType2(slice, actionKey) {
673 return slice + "/" + actionKey;
674}
675function createSlice(options) {
676 var name = options.name, initialState = options.initialState;
677 if (!name) {
678 throw new Error("`name` is a required option for createSlice");
679 }
680 var reducers = options.reducers || {};
681 var _b = typeof options.extraReducers === "function" ? executeReducerBuilderCallback(options.extraReducers) : [options.extraReducers], _c = _b[0], extraReducers = _c === void 0 ? {} : _c, _d = _b[1], actionMatchers = _d === void 0 ? [] : _d, _e = _b[2], defaultCaseReducer = _e === void 0 ? void 0 : _e;
682 var reducerNames = Object.keys(reducers);
683 var sliceCaseReducersByName = {};
684 var sliceCaseReducersByType = {};
685 var actionCreators = {};
686 reducerNames.forEach(function (reducerName) {
687 var maybeReducerWithPrepare = reducers[reducerName];
688 var type = getType2(name, reducerName);
689 var caseReducer;
690 var prepareCallback;
691 if ("reducer" in maybeReducerWithPrepare) {
692 caseReducer = maybeReducerWithPrepare.reducer;
693 prepareCallback = maybeReducerWithPrepare.prepare;
694 }
695 else {
696 caseReducer = maybeReducerWithPrepare;
697 }
698 sliceCaseReducersByName[reducerName] = caseReducer;
699 sliceCaseReducersByType[type] = caseReducer;
700 actionCreators[reducerName] = prepareCallback ? createAction(type, prepareCallback) : createAction(type);
701 });
702 var finalCaseReducers = __spreadValues(__spreadValues({}, extraReducers), sliceCaseReducersByType);
703 var reducer = createReducer(initialState, finalCaseReducers, actionMatchers, defaultCaseReducer);
704 return {
705 name: name,
706 reducer: reducer,
707 actions: actionCreators,
708 caseReducers: sliceCaseReducersByName
709 };
710}
711// src/entities/entity_state.ts
712function getInitialEntityState() {
713 return {
714 ids: [],
715 entities: {}
716 };
717}
718function createInitialStateFactory() {
719 function getInitialState(additionalState) {
720 if (additionalState === void 0) { additionalState = {}; }
721 return Object.assign(getInitialEntityState(), additionalState);
722 }
723 return { getInitialState: getInitialState };
724}
725// src/entities/state_selectors.ts
726function createSelectorsFactory() {
727 function getSelectors(selectState) {
728 var selectIds = function (state) { return state.ids; };
729 var selectEntities = function (state) { return state.entities; };
730 var selectAll = createDraftSafeSelector(selectIds, selectEntities, function (ids, entities) { return ids.map(function (id) { return entities[id]; }); });
731 var selectId = function (_, id) { return id; };
732 var selectById = function (entities, id) { return entities[id]; };
733 var selectTotal = createDraftSafeSelector(selectIds, function (ids) { return ids.length; });
734 if (!selectState) {
735 return {
736 selectIds: selectIds,
737 selectEntities: selectEntities,
738 selectAll: selectAll,
739 selectTotal: selectTotal,
740 selectById: createDraftSafeSelector(selectEntities, selectId, selectById)
741 };
742 }
743 var selectGlobalizedEntities = createDraftSafeSelector(selectState, selectEntities);
744 return {
745 selectIds: createDraftSafeSelector(selectState, selectIds),
746 selectEntities: selectGlobalizedEntities,
747 selectAll: createDraftSafeSelector(selectState, selectAll),
748 selectTotal: createDraftSafeSelector(selectState, selectTotal),
749 selectById: createDraftSafeSelector(selectGlobalizedEntities, selectId, selectById)
750 };
751 }
752 return { getSelectors: getSelectors };
753}
754// src/entities/state_adapter.ts
755var import_immer3 = __toModule(require("immer"));
756function createSingleArgumentStateOperator(mutator) {
757 var operator = createStateOperator(function (_, state) { return mutator(state); });
758 return function operation(state) {
759 return operator(state, void 0);
760 };
761}
762function createStateOperator(mutator) {
763 return function operation(state, arg) {
764 function isPayloadActionArgument(arg2) {
765 return isFSA(arg2);
766 }
767 var runMutator = function (draft) {
768 if (isPayloadActionArgument(arg)) {
769 mutator(arg.payload, draft);
770 }
771 else {
772 mutator(arg, draft);
773 }
774 };
775 if ((0, import_immer3.isDraft)(state)) {
776 runMutator(state);
777 return state;
778 }
779 else {
780 return (0, import_immer3.default)(state, runMutator);
781 }
782 };
783}
784// src/entities/utils.ts
785function selectIdValue(entity, selectId) {
786 var key = selectId(entity);
787 if (key === void 0) {
788 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());
789 }
790 return key;
791}
792function ensureEntitiesArray(entities) {
793 if (!Array.isArray(entities)) {
794 entities = Object.values(entities);
795 }
796 return entities;
797}
798function splitAddedUpdatedEntities(newEntities, selectId, state) {
799 newEntities = ensureEntitiesArray(newEntities);
800 var added = [];
801 var updated = [];
802 for (var _i = 0, newEntities_1 = newEntities; _i < newEntities_1.length; _i++) {
803 var entity = newEntities_1[_i];
804 var id = selectIdValue(entity, selectId);
805 if (id in state.entities) {
806 updated.push({ id: id, changes: entity });
807 }
808 else {
809 added.push(entity);
810 }
811 }
812 return [added, updated];
813}
814// src/entities/unsorted_state_adapter.ts
815function createUnsortedStateAdapter(selectId) {
816 function addOneMutably(entity, state) {
817 var key = selectIdValue(entity, selectId);
818 if (key in state.entities) {
819 return;
820 }
821 state.ids.push(key);
822 state.entities[key] = entity;
823 }
824 function addManyMutably(newEntities, state) {
825 newEntities = ensureEntitiesArray(newEntities);
826 for (var _i = 0, newEntities_2 = newEntities; _i < newEntities_2.length; _i++) {
827 var entity = newEntities_2[_i];
828 addOneMutably(entity, state);
829 }
830 }
831 function setOneMutably(entity, state) {
832 var key = selectIdValue(entity, selectId);
833 if (!(key in state.entities)) {
834 state.ids.push(key);
835 }
836 state.entities[key] = entity;
837 }
838 function setManyMutably(newEntities, state) {
839 newEntities = ensureEntitiesArray(newEntities);
840 for (var _i = 0, newEntities_3 = newEntities; _i < newEntities_3.length; _i++) {
841 var entity = newEntities_3[_i];
842 setOneMutably(entity, state);
843 }
844 }
845 function setAllMutably(newEntities, state) {
846 newEntities = ensureEntitiesArray(newEntities);
847 state.ids = [];
848 state.entities = {};
849 addManyMutably(newEntities, state);
850 }
851 function removeOneMutably(key, state) {
852 return removeManyMutably([key], state);
853 }
854 function removeManyMutably(keys, state) {
855 var didMutate = false;
856 keys.forEach(function (key) {
857 if (key in state.entities) {
858 delete state.entities[key];
859 didMutate = true;
860 }
861 });
862 if (didMutate) {
863 state.ids = state.ids.filter(function (id) { return id in state.entities; });
864 }
865 }
866 function removeAllMutably(state) {
867 Object.assign(state, {
868 ids: [],
869 entities: {}
870 });
871 }
872 function takeNewKey(keys, update, state) {
873 var original2 = state.entities[update.id];
874 var updated = Object.assign({}, original2, update.changes);
875 var newKey = selectIdValue(updated, selectId);
876 var hasNewKey = newKey !== update.id;
877 if (hasNewKey) {
878 keys[update.id] = newKey;
879 delete state.entities[update.id];
880 }
881 state.entities[newKey] = updated;
882 return hasNewKey;
883 }
884 function updateOneMutably(update, state) {
885 return updateManyMutably([update], state);
886 }
887 function updateManyMutably(updates, state) {
888 var newKeys = {};
889 var updatesPerEntity = {};
890 updates.forEach(function (update) {
891 if (update.id in state.entities) {
892 updatesPerEntity[update.id] = {
893 id: update.id,
894 changes: __spreadValues(__spreadValues({}, updatesPerEntity[update.id] ? updatesPerEntity[update.id].changes : null), update.changes)
895 };
896 }
897 });
898 updates = Object.values(updatesPerEntity);
899 var didMutateEntities = updates.length > 0;
900 if (didMutateEntities) {
901 var didMutateIds = updates.filter(function (update) { return takeNewKey(newKeys, update, state); }).length > 0;
902 if (didMutateIds) {
903 state.ids = state.ids.map(function (id) { return newKeys[id] || id; });
904 }
905 }
906 }
907 function upsertOneMutably(entity, state) {
908 return upsertManyMutably([entity], state);
909 }
910 function upsertManyMutably(newEntities, state) {
911 var _b = splitAddedUpdatedEntities(newEntities, selectId, state), added = _b[0], updated = _b[1];
912 updateManyMutably(updated, state);
913 addManyMutably(added, state);
914 }
915 return {
916 removeAll: createSingleArgumentStateOperator(removeAllMutably),
917 addOne: createStateOperator(addOneMutably),
918 addMany: createStateOperator(addManyMutably),
919 setOne: createStateOperator(setOneMutably),
920 setMany: createStateOperator(setManyMutably),
921 setAll: createStateOperator(setAllMutably),
922 updateOne: createStateOperator(updateOneMutably),
923 updateMany: createStateOperator(updateManyMutably),
924 upsertOne: createStateOperator(upsertOneMutably),
925 upsertMany: createStateOperator(upsertManyMutably),
926 removeOne: createStateOperator(removeOneMutably),
927 removeMany: createStateOperator(removeManyMutably)
928 };
929}
930// src/entities/sorted_state_adapter.ts
931function createSortedStateAdapter(selectId, sort) {
932 var _b = createUnsortedStateAdapter(selectId), removeOne = _b.removeOne, removeMany = _b.removeMany, removeAll = _b.removeAll;
933 function addOneMutably(entity, state) {
934 return addManyMutably([entity], state);
935 }
936 function addManyMutably(newEntities, state) {
937 newEntities = ensureEntitiesArray(newEntities);
938 var models = newEntities.filter(function (model) { return !(selectIdValue(model, selectId) in state.entities); });
939 if (models.length !== 0) {
940 merge(models, state);
941 }
942 }
943 function setOneMutably(entity, state) {
944 return setManyMutably([entity], state);
945 }
946 function setManyMutably(newEntities, state) {
947 newEntities = ensureEntitiesArray(newEntities);
948 if (newEntities.length !== 0) {
949 merge(newEntities, state);
950 }
951 }
952 function setAllMutably(newEntities, state) {
953 newEntities = ensureEntitiesArray(newEntities);
954 state.entities = {};
955 state.ids = [];
956 addManyMutably(newEntities, state);
957 }
958 function updateOneMutably(update, state) {
959 return updateManyMutably([update], state);
960 }
961 function takeUpdatedModel(models, update, state) {
962 if (!(update.id in state.entities)) {
963 return false;
964 }
965 var original2 = state.entities[update.id];
966 var updated = Object.assign({}, original2, update.changes);
967 var newKey = selectIdValue(updated, selectId);
968 delete state.entities[update.id];
969 models.push(updated);
970 return newKey !== update.id;
971 }
972 function updateManyMutably(updates, state) {
973 var models = [];
974 updates.forEach(function (update) { return takeUpdatedModel(models, update, state); });
975 if (models.length !== 0) {
976 merge(models, state);
977 }
978 }
979 function upsertOneMutably(entity, state) {
980 return upsertManyMutably([entity], state);
981 }
982 function upsertManyMutably(newEntities, state) {
983 var _b = splitAddedUpdatedEntities(newEntities, selectId, state), added = _b[0], updated = _b[1];
984 updateManyMutably(updated, state);
985 addManyMutably(added, state);
986 }
987 function areArraysEqual(a, b) {
988 if (a.length !== b.length) {
989 return false;
990 }
991 for (var i = 0; i < a.length && i < b.length; i++) {
992 if (a[i] === b[i]) {
993 continue;
994 }
995 return false;
996 }
997 return true;
998 }
999 function merge(models, state) {
1000 models.forEach(function (model) {
1001 state.entities[selectId(model)] = model;
1002 });
1003 var allEntities = Object.values(state.entities);
1004 allEntities.sort(sort);
1005 var newSortedIds = allEntities.map(selectId);
1006 var ids = state.ids;
1007 if (!areArraysEqual(ids, newSortedIds)) {
1008 state.ids = newSortedIds;
1009 }
1010 }
1011 return {
1012 removeOne: removeOne,
1013 removeMany: removeMany,
1014 removeAll: removeAll,
1015 addOne: createStateOperator(addOneMutably),
1016 updateOne: createStateOperator(updateOneMutably),
1017 upsertOne: createStateOperator(upsertOneMutably),
1018 setOne: createStateOperator(setOneMutably),
1019 setMany: createStateOperator(setManyMutably),
1020 setAll: createStateOperator(setAllMutably),
1021 addMany: createStateOperator(addManyMutably),
1022 updateMany: createStateOperator(updateManyMutably),
1023 upsertMany: createStateOperator(upsertManyMutably)
1024 };
1025}
1026// src/entities/create_adapter.ts
1027function createEntityAdapter(options) {
1028 if (options === void 0) { options = {}; }
1029 var _b = __spreadValues({
1030 sortComparer: false,
1031 selectId: function (instance) { return instance.id; }
1032 }, options), selectId = _b.selectId, sortComparer = _b.sortComparer;
1033 var stateFactory = createInitialStateFactory();
1034 var selectorsFactory = createSelectorsFactory();
1035 var stateAdapter = sortComparer ? createSortedStateAdapter(selectId, sortComparer) : createUnsortedStateAdapter(selectId);
1036 return __spreadValues(__spreadValues(__spreadValues({
1037 selectId: selectId,
1038 sortComparer: sortComparer
1039 }, stateFactory), selectorsFactory), stateAdapter);
1040}
1041// src/nanoid.ts
1042var urlAlphabet = "ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW";
1043var nanoid = function (size) {
1044 if (size === void 0) { size = 21; }
1045 var id = "";
1046 var i = size;
1047 while (i--) {
1048 id += urlAlphabet[Math.random() * 64 | 0];
1049 }
1050 return id;
1051};
1052// src/createAsyncThunk.ts
1053var commonProperties = [
1054 "name",
1055 "message",
1056 "stack",
1057 "code"
1058];
1059var RejectWithValue = /** @class */ (function () {
1060 function RejectWithValue(payload, meta) {
1061 this.payload = payload;
1062 this.meta = meta;
1063 }
1064 return RejectWithValue;
1065}());
1066var FulfillWithMeta = /** @class */ (function () {
1067 function FulfillWithMeta(payload, meta) {
1068 this.payload = payload;
1069 this.meta = meta;
1070 }
1071 return FulfillWithMeta;
1072}());
1073var miniSerializeError = function (value) {
1074 if (typeof value === "object" && value !== null) {
1075 var simpleError = {};
1076 for (var _i = 0, commonProperties_1 = commonProperties; _i < commonProperties_1.length; _i++) {
1077 var property = commonProperties_1[_i];
1078 if (typeof value[property] === "string") {
1079 simpleError[property] = value[property];
1080 }
1081 }
1082 return simpleError;
1083 }
1084 return { message: String(value) };
1085};
1086function createAsyncThunk(typePrefix, payloadCreator, options) {
1087 var fulfilled = createAction(typePrefix + "/fulfilled", function (payload, requestId, arg, meta) { return ({
1088 payload: payload,
1089 meta: __spreadProps(__spreadValues({}, meta || {}), {
1090 arg: arg,
1091 requestId: requestId,
1092 requestStatus: "fulfilled"
1093 })
1094 }); });
1095 var pending = createAction(typePrefix + "/pending", function (requestId, arg, meta) { return ({
1096 payload: void 0,
1097 meta: __spreadProps(__spreadValues({}, meta || {}), {
1098 arg: arg,
1099 requestId: requestId,
1100 requestStatus: "pending"
1101 })
1102 }); });
1103 var rejected = createAction(typePrefix + "/rejected", function (error, requestId, arg, payload, meta) { return ({
1104 payload: payload,
1105 error: (options && options.serializeError || miniSerializeError)(error || "Rejected"),
1106 meta: __spreadProps(__spreadValues({}, meta || {}), {
1107 arg: arg,
1108 requestId: requestId,
1109 rejectedWithValue: !!payload,
1110 requestStatus: "rejected",
1111 aborted: (error == null ? void 0 : error.name) === "AbortError",
1112 condition: (error == null ? void 0 : error.name) === "ConditionError"
1113 })
1114 }); });
1115 var displayedWarning = false;
1116 var AC = typeof AbortController !== "undefined" ? AbortController : /** @class */ (function () {
1117 function class_1() {
1118 this.signal = {
1119 aborted: false,
1120 addEventListener: function () {
1121 },
1122 dispatchEvent: function () {
1123 return false;
1124 },
1125 onabort: function () {
1126 },
1127 removeEventListener: function () {
1128 }
1129 };
1130 }
1131 class_1.prototype.abort = function () {
1132 if (true) {
1133 if (!displayedWarning) {
1134 displayedWarning = true;
1135 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'.");
1136 }
1137 }
1138 };
1139 return class_1;
1140 }());
1141 function actionCreator(arg) {
1142 return function (dispatch, getState, extra) {
1143 var _a;
1144 var requestId = ((_a = options == null ? void 0 : options.idGenerator) != null ? _a : nanoid)();
1145 var abortController = new AC();
1146 var abortReason;
1147 var abortedPromise = new Promise(function (_, reject) { return abortController.signal.addEventListener("abort", function () { return reject({ name: "AbortError", message: abortReason || "Aborted" }); }); });
1148 var started = false;
1149 function abort(reason) {
1150 if (started) {
1151 abortReason = reason;
1152 abortController.abort();
1153 }
1154 }
1155 var promise = function () {
1156 return __async(this, null, function () {
1157 var _a2, finalAction, err_1, skipDispatch;
1158 return __generator(this, function (_b) {
1159 switch (_b.label) {
1160 case 0:
1161 _b.trys.push([0, 2, , 3]);
1162 if (options && options.condition && options.condition(arg, { getState: getState, extra: extra }) === false) {
1163 throw {
1164 name: "ConditionError",
1165 message: "Aborted due to condition callback returning false."
1166 };
1167 }
1168 started = true;
1169 dispatch(pending(requestId, arg, (_a2 = options == null ? void 0 : options.getPendingMeta) == null ? void 0 : _a2.call(options, { requestId: requestId, arg: arg }, { getState: getState, extra: extra })));
1170 return [4 /*yield*/, Promise.race([
1171 abortedPromise,
1172 Promise.resolve(payloadCreator(arg, {
1173 dispatch: dispatch,
1174 getState: getState,
1175 extra: extra,
1176 requestId: requestId,
1177 signal: abortController.signal,
1178 rejectWithValue: function (value, meta) {
1179 return new RejectWithValue(value, meta);
1180 },
1181 fulfillWithValue: function (value, meta) {
1182 return new FulfillWithMeta(value, meta);
1183 }
1184 })).then(function (result) {
1185 if (result instanceof RejectWithValue) {
1186 throw result;
1187 }
1188 if (result instanceof FulfillWithMeta) {
1189 return fulfilled(result.payload, requestId, arg, result.meta);
1190 }
1191 return fulfilled(result, requestId, arg);
1192 })
1193 ])];
1194 case 1:
1195 finalAction = _b.sent();
1196 return [3 /*break*/, 3];
1197 case 2:
1198 err_1 = _b.sent();
1199 finalAction = err_1 instanceof RejectWithValue ? rejected(null, requestId, arg, err_1.payload, err_1.meta) : rejected(err_1, requestId, arg);
1200 return [3 /*break*/, 3];
1201 case 3:
1202 skipDispatch = options && !options.dispatchConditionRejection && rejected.match(finalAction) && finalAction.meta.condition;
1203 if (!skipDispatch) {
1204 dispatch(finalAction);
1205 }
1206 return [2 /*return*/, finalAction];
1207 }
1208 });
1209 });
1210 }();
1211 return Object.assign(promise, {
1212 abort: abort,
1213 requestId: requestId,
1214 arg: arg,
1215 unwrap: function () {
1216 return promise.then(unwrapResult);
1217 }
1218 });
1219 };
1220 }
1221 return Object.assign(actionCreator, {
1222 pending: pending,
1223 rejected: rejected,
1224 fulfilled: fulfilled,
1225 typePrefix: typePrefix
1226 });
1227}
1228function unwrapResult(action) {
1229 if (action.meta && action.meta.rejectedWithValue) {
1230 throw action.payload;
1231 }
1232 if (action.error) {
1233 throw action.error;
1234 }
1235 return action.payload;
1236}
1237// src/tsHelpers.ts
1238var hasMatchFunction = function (v) {
1239 return v && typeof v.match === "function";
1240};
1241// src/matchers.ts
1242var matches = function (matcher, action) {
1243 if (hasMatchFunction(matcher)) {
1244 return matcher.match(action);
1245 }
1246 else {
1247 return matcher(action);
1248 }
1249};
1250function isAnyOf() {
1251 var matchers = [];
1252 for (var _i = 0; _i < arguments.length; _i++) {
1253 matchers[_i] = arguments[_i];
1254 }
1255 return function (action) {
1256 return matchers.some(function (matcher) { return matches(matcher, action); });
1257 };
1258}
1259function isAllOf() {
1260 var matchers = [];
1261 for (var _i = 0; _i < arguments.length; _i++) {
1262 matchers[_i] = arguments[_i];
1263 }
1264 return function (action) {
1265 return matchers.every(function (matcher) { return matches(matcher, action); });
1266 };
1267}
1268function hasExpectedRequestMetadata(action, validStatus) {
1269 if (!action || !action.meta)
1270 return false;
1271 var hasValidRequestId = typeof action.meta.requestId === "string";
1272 var hasValidRequestStatus = validStatus.indexOf(action.meta.requestStatus) > -1;
1273 return hasValidRequestId && hasValidRequestStatus;
1274}
1275function isAsyncThunkArray(a) {
1276 return typeof a[0] === "function" && "pending" in a[0] && "fulfilled" in a[0] && "rejected" in a[0];
1277}
1278function isPending() {
1279 var asyncThunks = [];
1280 for (var _i = 0; _i < arguments.length; _i++) {
1281 asyncThunks[_i] = arguments[_i];
1282 }
1283 if (asyncThunks.length === 0) {
1284 return function (action) { return hasExpectedRequestMetadata(action, ["pending"]); };
1285 }
1286 if (!isAsyncThunkArray(asyncThunks)) {
1287 return isPending()(asyncThunks[0]);
1288 }
1289 return function (action) {
1290 var matchers = asyncThunks.map(function (asyncThunk) { return asyncThunk.pending; });
1291 var combinedMatcher = isAnyOf.apply(void 0, matchers);
1292 return combinedMatcher(action);
1293 };
1294}
1295function isRejected() {
1296 var asyncThunks = [];
1297 for (var _i = 0; _i < arguments.length; _i++) {
1298 asyncThunks[_i] = arguments[_i];
1299 }
1300 if (asyncThunks.length === 0) {
1301 return function (action) { return hasExpectedRequestMetadata(action, ["rejected"]); };
1302 }
1303 if (!isAsyncThunkArray(asyncThunks)) {
1304 return isRejected()(asyncThunks[0]);
1305 }
1306 return function (action) {
1307 var matchers = asyncThunks.map(function (asyncThunk) { return asyncThunk.rejected; });
1308 var combinedMatcher = isAnyOf.apply(void 0, matchers);
1309 return combinedMatcher(action);
1310 };
1311}
1312function isRejectedWithValue() {
1313 var asyncThunks = [];
1314 for (var _i = 0; _i < arguments.length; _i++) {
1315 asyncThunks[_i] = arguments[_i];
1316 }
1317 var hasFlag = function (action) {
1318 return action && action.meta && action.meta.rejectedWithValue;
1319 };
1320 if (asyncThunks.length === 0) {
1321 return function (action) {
1322 var combinedMatcher = isAllOf(isRejected.apply(void 0, asyncThunks), hasFlag);
1323 return combinedMatcher(action);
1324 };
1325 }
1326 if (!isAsyncThunkArray(asyncThunks)) {
1327 return isRejectedWithValue()(asyncThunks[0]);
1328 }
1329 return function (action) {
1330 var combinedMatcher = isAllOf(isRejected.apply(void 0, asyncThunks), hasFlag);
1331 return combinedMatcher(action);
1332 };
1333}
1334function isFulfilled() {
1335 var asyncThunks = [];
1336 for (var _i = 0; _i < arguments.length; _i++) {
1337 asyncThunks[_i] = arguments[_i];
1338 }
1339 if (asyncThunks.length === 0) {
1340 return function (action) { return hasExpectedRequestMetadata(action, ["fulfilled"]); };
1341 }
1342 if (!isAsyncThunkArray(asyncThunks)) {
1343 return isFulfilled()(asyncThunks[0]);
1344 }
1345 return function (action) {
1346 var matchers = asyncThunks.map(function (asyncThunk) { return asyncThunk.fulfilled; });
1347 var combinedMatcher = isAnyOf.apply(void 0, matchers);
1348 return combinedMatcher(action);
1349 };
1350}
1351function isAsyncThunkAction() {
1352 var asyncThunks = [];
1353 for (var _i = 0; _i < arguments.length; _i++) {
1354 asyncThunks[_i] = arguments[_i];
1355 }
1356 if (asyncThunks.length === 0) {
1357 return function (action) { return hasExpectedRequestMetadata(action, ["pending", "fulfilled", "rejected"]); };
1358 }
1359 if (!isAsyncThunkArray(asyncThunks)) {
1360 return isAsyncThunkAction()(asyncThunks[0]);
1361 }
1362 return function (action) {
1363 var matchers = [];
1364 for (var _i = 0, asyncThunks_1 = asyncThunks; _i < asyncThunks_1.length; _i++) {
1365 var asyncThunk = asyncThunks_1[_i];
1366 matchers.push(asyncThunk.pending, asyncThunk.rejected, asyncThunk.fulfilled);
1367 }
1368 var combinedMatcher = isAnyOf.apply(void 0, matchers);
1369 return combinedMatcher(action);
1370 };
1371}
1372// src/index.ts
1373(0, import_immer4.enableES5)();
1374//# sourceMappingURL=module.js.map
\No newline at end of file