UNPKG

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