UNPKG

158 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../src/index.ts","../src/createDraftSafeSelector.ts","../src/configureStore.ts","../src/devtoolsExtension.ts","../src/isPlainObject.ts","../src/getDefaultMiddleware.ts","../src/utils.ts","../src/immutableStateInvariantMiddleware.ts","../src/serializableStateInvariantMiddleware.ts","../src/createAction.ts","../src/createReducer.ts","../src/mapBuilders.ts","../src/createSlice.ts","../src/entities/state_adapter.ts","../src/entities/utils.ts","../src/entities/unsorted_state_adapter.ts","../src/entities/create_adapter.ts","../src/entities/entity_state.ts","../src/entities/state_selectors.ts","../src/entities/sorted_state_adapter.ts","../src/nanoid.ts","../src/createAsyncThunk.ts","../src/tsHelpers.ts","../src/matchers.ts"],"names":["__markAsModule","exports","__export","MiddlewareArray","configureStore","createAction","createAsyncThunk","createDraftSafeSelector","createEntityAdapter","createImmutableStateInvariantMiddleware","createNextState","import_immer5","default","createReducer","createSelector","import_reselect2","createSerializableStateInvariantMiddleware","createSlice","current","findNonSerializableValue","freeze","getDefaultMiddleware","getType","isAllOf","isAnyOf","isAsyncThunkAction","isDraft","isFulfilled","isImmutableDefault","isPending","isPlain","isPlainObject","isRejected","isRejectedWithValue","miniSerializeError","nanoid","original","unwrapResult","import_immer4","__toModule","require","__reExport","import_immer","import_reselect","args","_i","arguments","length","selector","apply","wrappedSelector","value","rest","__spreadArray","import_redux2","import_redux","composeWithDevTools","window","__REDUX_DEVTOOLS_EXTENSION_COMPOSE__","compose","proto","Object","getPrototypeOf","__REDUX_DEVTOOLS_EXTENSION__","import_redux_thunk","_super","_this","this","setPrototypeOf","prototype","__extends","defineProperty","Symbol","species","concat","arr","prepend","Array","isArray","bind","isFrozen","options","next","action","val","type","path","isSerializable","getEntries","ignoredPaths","foundNestedSerializable","keyPath","entries","hasIgnoredPaths","entries_1","_b","key","nestedValue","nestedPath","indexOf","thunk","middlewareArray","push","withExtraArgument","extraArgument","rootReducer","curriedGetDefaultMiddleware","_c","reducer","_d","middleware","_e","devTools","_f","preloadedState","_g","enhancers","Error","combineReducers","finalMiddleware","middlewareEnhancer","applyMiddleware","finalCompose","__spreadValues","trace","storeEnhancers","composedEnhancer","createStore","prepareAction","actionCreator","prepared","payload","meta","error","toString","match","isValidKey","import_immer2","executeReducerBuilderCallback","builderCallback","defaultCaseReducer","actionsMap","actionMatchers","builder","addCase","typeOrActionCreator","addMatcher","matcher","addDefaultCase","initialState","mapOrBuilderCallback","finalActionMatchers","finalDefaultCaseReducer","frozenInitialState","state","caseReducers","filter","map","cr","reduce","previousState","caseReducer","result","isDraftable","draft","name","reducers","extraReducers","reducerNames","keys","sliceCaseReducersByName","sliceCaseReducersByType","actionCreators","forEach","reducerName","prepareCallback","maybeReducerWithPrepare","prepare","actions","import_immer3","createStateOperator","mutator","arg","runMutator","every","selectIdValue","entity","selectId","ensureEntitiesArray","entities","values","splitAddedUpdatedEntities","newEntities","added","updated","newEntities_1","id","changes","createUnsortedStateAdapter","addOneMutably","ids","addManyMutably","newEntities_2","setOneMutably","removeManyMutably","didMutate","updateManyMutably","updates","newKeys","updatesPerEntity","update","assign","newKey","hasNewKey","takeNewKey","upsertManyMutably","removeAll","operator","_","addOne","addMany","setOne","setMany","newEntities_3","setAll","updateOne","updateMany","upsertOne","upsertMany","removeOne","removeMany","sortComparer","instance","stateFactory","getInitialState","additionalState","selectorsFactory","getSelectors","selectState","selectIds","selectEntities","selectAll","selectById","selectTotal","selectGlobalizedEntities","stateAdapter","sort","models","model","merge","setManyMutably","takeUpdatedModel","allEntities","newSortedIds","a","b","i","areArraysEqual","createSortedStateAdapter","size","Math","random","commonProperties","RejectWithValue","FulfillWithMeta","simpleError","commonProperties_1","property","message","String","typePrefix","payloadCreator","fulfilled","requestId","__spreadProps","requestStatus","pending","rejected","serializeError","rejectedWithValue","aborted","condition","AC","AbortController","class_1","signal","addEventListener","dispatchEvent","onabort","removeEventListener","abort","dispatch","getState","extra","_a","abortReason","idGenerator","abortController","abortedPromise","Promise","reject","started","promise","_a2","getPendingMeta","call","race","resolve","rejectWithValue","fulfillWithValue","then","finalAction","sent","err_1","dispatchConditionRejection","reason","unwrap","matches","v","matchers","some","hasExpectedRequestMetadata","validStatus","hasValidRequestId","hasValidRequestStatus","isAsyncThunkArray","asyncThunks","asyncThunk","combinedMatcher","hasFlag","asyncThunks_1","enableES5"],"mappings":"qoFAAAA,EAAAC,sEAAAC,CAAAD,QAAA,CAAAE,gBAAA,WAAA,OAAAA,GAAAC,eAAA,WAAA,OAAAA,GAAAC,aAAA,WAAA,OAAAA,GAAAC,iBAAA,WAAA,OAAAA,IAAAC,wBAAA,WAAA,OAAAA,GAAAC,oBAAA,WAAA,OAAAA,GAAAC,wCAAA,WAAA,OAAAA,GAAAC,gBAAA,WAAA,OAAAC,EAAAC,SAAAC,cAAA,WAAA,OAAAA,GAAAC,eAAA,WAAA,OAAAC,EAAAD,gBAAAE,2CAAA,WAAA,OAAAA,GAAAC,YAAA,WAAA,OAAAA,GAAAC,QAAA,WAAA,OAAAP,EAAAO,SAAAC,yBAAA,WAAA,OAAAA,GAAAC,OAAA,WAAA,OAAAT,EAAAS,QAAAC,qBAAA,WAAA,OAAAA,GAAAC,QAAA,WAAA,OAAAA,GAAAC,QAAA,WAAA,OAAAA,IAAAC,QAAA,WAAA,OAAAA,IAAAC,mBAAA,WAAA,OAAAA,IAAAC,QAAA,WAAA,OAAAf,EAAAe,SAAAC,YAAA,WAAA,OAAAA,IAAAC,mBAAA,WAAA,OAAAA,GAAAC,UAAA,WAAA,OAAAA,IAAAC,QAAA,WAAA,OAAAA,GAAAC,cAAA,WAAA,OAAAA,GAAAC,WAAA,WAAA,OAAAA,IAAAC,oBAAA,WAAA,OAAAA,IAAAC,mBAAA,WAAA,OAAAA,IAAAC,OAAA,WAAA,OAAAA,GAAAC,SAAA,WAAA,OAAAzB,EAAAyB,UAAAC,aAAA,WAAA,OAAAA,MAAA,IAAAC,EAA0BC,EAAAC,QAAA,UAC1BC,EAAAxC,QAAcsC,EAAAC,QAAA,WACd,IAA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AAA3S,SAAA,IAAA2S,EAAA,GAAAzR,EAAA,EAAAA,EAAAC,UAAAC,OAAAF,IAAAyR,EAAAzR,GAAAC,UAAAD,GAGL,OAA2B,IAAvByR,EAAYvR,OACP,SAACoC,GAAgB,OAAA8O,GAA2B9O,EAAQ,CAAC,eAGzDkP,GAAkBC,GAIhB,SACLnP,GAGA,IAAM4O,EAA8CO,EAAYzK,KAC9D,SAAC0K,GAAe,OAAAA,EAAWvD,aAK7B,OAFwBxP,GAAAyB,WAAA,EAAW8Q,EAE5BS,CAAgBrP,IAbhBxD,IAAAA,CAAc2S,EAAY,IA8D9B,SAAA7S,SAAA,IAAA6S,EAAA,GAAAzR,EAAA,EAAAA,EAAAC,UAAAC,OAAAF,IAAAyR,EAAAzR,GAAAC,UAAAD,GAGL,OAA2B,IAAvByR,EAAYvR,OACP,SAACoC,GACN,OAAA8O,GAA2B9O,EAAQ,CAAC,UAAW,YAAa,cAG3DkP,GAAkBC,GAIhB,SACLnP,GAKA,IAFA,IAAM4O,EAA8C,GAE3BlR,EAAA,EAAA6R,EAAAJ,EAAAzR,EAAA6R,EAAA3R,OAAAF,IAAa,CAAtC,IAAW0R,EAAAG,EAAA7R,GACTkR,EAASzN,KACPiO,EAAWnD,QACXmD,EAAWlD,SACXkD,EAAWvD,WAMf,OAFwBxP,GAAAyB,WAAA,EAAW8Q,EAE5BS,CAAgBrP,IAnBhB1D,IAAAA,CAAqB6S,EAAY,KvB7X5C,EAAAhS,EAAAqS","sourcesContent":["import { enableES5 } from 'immer'\r\nexport * from 'redux'\r\nexport {\r\n default as createNextState,\r\n current,\r\n freeze,\r\n original,\r\n isDraft,\r\n} from 'immer'\r\nexport type { Draft } from 'immer'\r\nexport { createSelector } from 'reselect'\r\nexport type {\r\n Selector,\r\n OutputParametricSelector,\r\n OutputSelector,\r\n ParametricSelector,\r\n} from 'reselect'\r\nexport { createDraftSafeSelector } from './createDraftSafeSelector'\r\nexport type { ThunkAction, ThunkDispatch } from 'redux-thunk'\r\n\r\n// We deliberately enable Immer's ES5 support, on the grounds that\r\n// we assume RTK will be used with React Native and other Proxy-less\r\n// environments. In addition, that's how Immer 4 behaved, and since\r\n// we want to ship this in an RTK minor, we should keep the same behavior.\r\nenableES5()\r\n\r\nexport {\r\n // js\r\n configureStore,\r\n} from './configureStore'\r\nexport type {\r\n // types\r\n ConfigureEnhancersCallback,\r\n ConfigureStoreOptions,\r\n EnhancedStore,\r\n} from './configureStore'\r\nexport {\r\n // js\r\n createAction,\r\n getType,\r\n} from './createAction'\r\nexport type {\r\n // types\r\n PayloadAction,\r\n PayloadActionCreator,\r\n ActionCreatorWithNonInferrablePayload,\r\n ActionCreatorWithOptionalPayload,\r\n ActionCreatorWithPayload,\r\n ActionCreatorWithoutPayload,\r\n ActionCreatorWithPreparedPayload,\r\n PrepareAction,\r\n} from './createAction'\r\nexport {\r\n // js\r\n createReducer,\r\n} from './createReducer'\r\nexport type {\r\n // types\r\n Actions,\r\n CaseReducer,\r\n CaseReducers,\r\n} from './createReducer'\r\nexport {\r\n // js\r\n createSlice,\r\n} from './createSlice'\r\n\r\nexport type {\r\n // types\r\n CreateSliceOptions,\r\n Slice,\r\n CaseReducerActions,\r\n SliceCaseReducers,\r\n ValidateSliceCaseReducers,\r\n CaseReducerWithPrepare,\r\n SliceActionCreator,\r\n} from './createSlice'\r\nexport {\r\n // js\r\n createImmutableStateInvariantMiddleware,\r\n isImmutableDefault,\r\n} from './immutableStateInvariantMiddleware'\r\nexport type {\r\n // types\r\n ImmutableStateInvariantMiddlewareOptions,\r\n} from './immutableStateInvariantMiddleware'\r\nexport {\r\n // js\r\n createSerializableStateInvariantMiddleware,\r\n findNonSerializableValue,\r\n isPlain,\r\n} from './serializableStateInvariantMiddleware'\r\nexport type {\r\n // types\r\n SerializableStateInvariantMiddlewareOptions,\r\n} from './serializableStateInvariantMiddleware'\r\nexport {\r\n // js\r\n getDefaultMiddleware,\r\n} from './getDefaultMiddleware'\r\nexport type {\r\n // types\r\n ActionReducerMapBuilder,\r\n} from './mapBuilders'\r\nexport { MiddlewareArray } from './utils'\r\n\r\nexport { createEntityAdapter } from './entities/create_adapter'\r\nexport type {\r\n Dictionary,\r\n EntityState,\r\n EntityAdapter,\r\n EntitySelectors,\r\n EntityStateAdapter,\r\n EntityId,\r\n Update,\r\n IdSelector,\r\n Comparer,\r\n} from './entities/models'\r\n\r\nexport {\r\n createAsyncThunk,\r\n unwrapResult,\r\n miniSerializeError,\r\n} from './createAsyncThunk'\r\nexport type {\r\n AsyncThunk,\r\n AsyncThunkOptions,\r\n AsyncThunkAction,\r\n AsyncThunkPayloadCreatorReturnValue,\r\n AsyncThunkPayloadCreator,\r\n SerializedError,\r\n} from './createAsyncThunk'\r\n\r\nexport {\r\n // js\r\n isAllOf,\r\n isAnyOf,\r\n isPending,\r\n isRejected,\r\n isFulfilled,\r\n isAsyncThunkAction,\r\n isRejectedWithValue,\r\n} from './matchers'\r\nexport type {\r\n // types\r\n ActionMatchingAllOf,\r\n ActionMatchingAnyOf,\r\n} from './matchers'\r\n\r\nexport { nanoid } from './nanoid'\r\n\r\nexport { default as isPlainObject } from './isPlainObject'\r\n","import { current, isDraft } from 'immer'\r\nimport { createSelector } from 'reselect'\r\n\r\n/**\r\n * \"Draft-Safe\" version of `reselect`'s `createSelector`:\r\n * If an `immer`-drafted object is passed into the resulting selector's first argument,\r\n * the selector will act on the current draft value, instead of returning a cached value\r\n * that might be possibly outdated if the draft has been modified since.\r\n * @public\r\n */\r\nexport const createDraftSafeSelector: typeof createSelector = (\r\n ...args: unknown[]\r\n) => {\r\n const selector = (createSelector as any)(...args)\r\n const wrappedSelector = (value: unknown, ...rest: unknown[]) =>\r\n selector(isDraft(value) ? current(value) : value, ...rest)\r\n return wrappedSelector as any\r\n}\r\n","import type {\r\n Reducer,\r\n ReducersMapObject,\r\n Middleware,\r\n Action,\r\n AnyAction,\r\n StoreEnhancer,\r\n Store,\r\n Dispatch,\r\n PreloadedState,\r\n CombinedState,\r\n} from 'redux'\r\nimport { createStore, compose, applyMiddleware, combineReducers } from 'redux'\r\nimport type { EnhancerOptions as DevToolsOptions } from './devtoolsExtension'\r\nimport { composeWithDevTools } from './devtoolsExtension'\r\n\r\nimport isPlainObject from './isPlainObject'\r\nimport type {\r\n ThunkMiddlewareFor,\r\n CurriedGetDefaultMiddleware,\r\n} from './getDefaultMiddleware'\r\nimport { curryGetDefaultMiddleware } from './getDefaultMiddleware'\r\nimport type { DispatchForMiddlewares, NoInfer } from './tsHelpers'\r\n\r\nconst IS_PRODUCTION = process.env.NODE_ENV === 'production'\r\n\r\n/**\r\n * Callback function type, to be used in `ConfigureStoreOptions.enhancers`\r\n *\r\n * @public\r\n */\r\nexport type ConfigureEnhancersCallback = (\r\n defaultEnhancers: readonly StoreEnhancer[]\r\n) => StoreEnhancer[]\r\n\r\n/**\r\n * Options for `configureStore()`.\r\n *\r\n * @public\r\n */\r\nexport interface ConfigureStoreOptions<\r\n S = any,\r\n A extends Action = AnyAction,\r\n M extends Middlewares<S> = Middlewares<S>\r\n> {\r\n /**\r\n * A single reducer function that will be used as the root reducer, or an\r\n * object of slice reducers that will be passed to `combineReducers()`.\r\n */\r\n reducer: Reducer<S, A> | ReducersMapObject<S, A>\r\n\r\n /**\r\n * An array of Redux middleware to install. If not supplied, defaults to\r\n * the set of middleware returned by `getDefaultMiddleware()`.\r\n */\r\n middleware?: ((getDefaultMiddleware: CurriedGetDefaultMiddleware<S>) => M) | M\r\n\r\n /**\r\n * Whether to enable Redux DevTools integration. Defaults to `true`.\r\n *\r\n * Additional configuration can be done by passing Redux DevTools options\r\n */\r\n devTools?: boolean | DevToolsOptions\r\n\r\n /**\r\n * The initial state, same as Redux's createStore.\r\n * You may optionally specify it to hydrate the state\r\n * from the server in universal apps, or to restore a previously serialized\r\n * user session. If you use `combineReducers()` to produce the root reducer\r\n * function (either directly or indirectly by passing an object as `reducer`),\r\n * this must be an object with the same shape as the reducer map keys.\r\n */\r\n /* \r\n Not 100% correct but the best approximation we can get:\r\n - if S is a `CombinedState` applying a second `CombinedState` on it does not change anything.\r\n - if it is not, there could be two cases:\r\n - `ReducersMapObject<S, A>` is being passed in. In this case, we will call `combineReducers` on it and `CombinedState<S>` is correct\r\n - `Reducer<S, A>` is being passed in. In this case, actually `CombinedState<S>` is wrong and `S` would be correct.\r\n As we cannot distinguish between those two cases without adding another generic paramter, \r\n we just make the pragmatic assumption that the latter almost never happens.\r\n */\r\n preloadedState?: PreloadedState<CombinedState<NoInfer<S>>>\r\n\r\n /**\r\n * The store enhancers to apply. See Redux's `createStore()`.\r\n * All enhancers will be included before the DevTools Extension enhancer.\r\n * If you need to customize the order of enhancers, supply a callback\r\n * function that will receive the original array (ie, `[applyMiddleware]`),\r\n * and should return a new array (such as `[applyMiddleware, offline]`).\r\n * If you only need to add middleware, you can use the `middleware` parameter instead.\r\n */\r\n enhancers?: StoreEnhancer[] | ConfigureEnhancersCallback\r\n}\r\n\r\ntype Middlewares<S> = ReadonlyArray<Middleware<{}, S>>\r\n\r\n/**\r\n * A Redux store returned by `configureStore()`. Supports dispatching\r\n * side-effectful _thunks_ in addition to plain actions.\r\n *\r\n * @public\r\n */\r\nexport interface EnhancedStore<\r\n S = any,\r\n A extends Action = AnyAction,\r\n M extends Middlewares<S> = Middlewares<S>\r\n> extends Store<S, A> {\r\n /**\r\n * The `dispatch` method of your store, enhanced by all its middlewares.\r\n *\r\n * @inheritdoc\r\n */\r\n dispatch: DispatchForMiddlewares<M> & Dispatch<A>\r\n}\r\n\r\n/**\r\n * A friendly abstraction over the standard Redux `createStore()` function.\r\n *\r\n * @param config The store configuration.\r\n * @returns A configured Redux store.\r\n *\r\n * @public\r\n */\r\nexport function configureStore<\r\n S = any,\r\n A extends Action = AnyAction,\r\n M extends Middlewares<S> = [ThunkMiddlewareFor<S>]\r\n>(options: ConfigureStoreOptions<S, A, M>): EnhancedStore<S, A, M> {\r\n const curriedGetDefaultMiddleware = curryGetDefaultMiddleware<S>()\r\n\r\n const {\r\n reducer = undefined,\r\n middleware = curriedGetDefaultMiddleware(),\r\n devTools = true,\r\n preloadedState = undefined,\r\n enhancers = undefined,\r\n } = options || {}\r\n\r\n let rootReducer: Reducer<S, A>\r\n\r\n if (typeof reducer === 'function') {\r\n rootReducer = reducer\r\n } else if (isPlainObject(reducer)) {\r\n rootReducer = combineReducers(reducer)\r\n } else {\r\n throw new Error(\r\n '\"reducer\" is a required argument, and must be a function or an object of functions that can be passed to combineReducers'\r\n )\r\n }\r\n\r\n let finalMiddleware = middleware\r\n if (typeof finalMiddleware === 'function') {\r\n finalMiddleware = finalMiddleware(curriedGetDefaultMiddleware)\r\n\r\n if (!IS_PRODUCTION && !Array.isArray(finalMiddleware)) {\r\n throw new Error(\r\n 'when using a middleware builder function, an array of middleware must be returned'\r\n )\r\n }\r\n }\r\n if (\r\n !IS_PRODUCTION &&\r\n finalMiddleware.some((item) => typeof item !== 'function')\r\n ) {\r\n throw new Error(\r\n 'each middleware provided to configureStore must be a function'\r\n )\r\n }\r\n\r\n const middlewareEnhancer = applyMiddleware(...finalMiddleware)\r\n\r\n let finalCompose = compose\r\n\r\n if (devTools) {\r\n finalCompose = composeWithDevTools({\r\n // Enable capture of stack traces for dispatched Redux actions\r\n trace: !IS_PRODUCTION,\r\n ...(typeof devTools === 'object' && devTools),\r\n })\r\n }\r\n\r\n let storeEnhancers: StoreEnhancer[] = [middlewareEnhancer]\r\n\r\n if (Array.isArray(enhancers)) {\r\n storeEnhancers = [middlewareEnhancer, ...enhancers]\r\n } else if (typeof enhancers === 'function') {\r\n storeEnhancers = enhancers(storeEnhancers)\r\n }\r\n\r\n const composedEnhancer = finalCompose(...storeEnhancers) as any\r\n\r\n return createStore(rootReducer, preloadedState, composedEnhancer)\r\n}\r\n","import type { Action, ActionCreator, StoreEnhancer } from 'redux'\r\nimport { compose } from 'redux'\r\n\r\n/**\r\n * @public\r\n */\r\nexport interface EnhancerOptions {\r\n /**\r\n * the instance name to be showed on the monitor page. Default value is `document.title`.\r\n * If not specified and there's no document title, it will consist of `tabId` and `instanceId`.\r\n */\r\n name?: string\r\n /**\r\n * action creators functions to be available in the Dispatcher.\r\n */\r\n actionCreators?: ActionCreator<any>[] | { [key: string]: ActionCreator<any> }\r\n /**\r\n * if more than one action is dispatched in the indicated interval, all new actions will be collected and sent at once.\r\n * It is the joint between performance and speed. When set to `0`, all actions will be sent instantly.\r\n * Set it to a higher value when experiencing perf issues (also `maxAge` to a lower value).\r\n *\r\n * @default 500 ms.\r\n */\r\n latency?: number\r\n /**\r\n * (> 1) - maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance.\r\n *\r\n * @default 50\r\n */\r\n maxAge?: number\r\n /**\r\n * See detailed documentation at http://extension.remotedev.io/docs/API/Arguments.html#serialize\r\n */\r\n serialize?:\r\n | boolean\r\n | {\r\n options?:\r\n | boolean\r\n | {\r\n date?: boolean\r\n regex?: boolean\r\n undefined?: boolean\r\n error?: boolean\r\n symbol?: boolean\r\n map?: boolean\r\n set?: boolean\r\n function?: boolean | Function\r\n }\r\n replacer?: (key: string, value: unknown) => unknown\r\n reviver?: (key: string, value: unknown) => unknown\r\n immutable?: unknown\r\n refs?: unknown[]\r\n }\r\n /**\r\n * function which takes `action` object and id number as arguments, and should return `action` object back.\r\n */\r\n actionSanitizer?: <A extends Action>(action: A, id: number) => A\r\n /**\r\n * function which takes `state` object and index as arguments, and should return `state` object back.\r\n */\r\n stateSanitizer?: <S>(state: S, index: number) => S\r\n /**\r\n * *string or array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers).\r\n * If `actionsWhitelist` specified, `actionsBlacklist` is ignored.\r\n */\r\n actionsBlacklist?: string | string[]\r\n /**\r\n * *string or array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers).\r\n * If `actionsWhitelist` specified, `actionsBlacklist` is ignored.\r\n */\r\n actionsWhitelist?: string | string[]\r\n /**\r\n * called for every action before sending, takes `state` and `action` object, and returns `true` in case it allows sending the current data to the monitor.\r\n * Use it as a more advanced version of `actionsBlacklist`/`actionsWhitelist` parameters.\r\n */\r\n predicate?: <S, A extends Action>(state: S, action: A) => boolean\r\n /**\r\n * if specified as `false`, it will not record the changes till clicking on `Start recording` button.\r\n * Available only for Redux enhancer, for others use `autoPause`.\r\n *\r\n * @default true\r\n */\r\n shouldRecordChanges?: boolean\r\n /**\r\n * if specified, whenever clicking on `Pause recording` button and there are actions in the history log, will add this action type.\r\n * If not specified, will commit when paused. Available only for Redux enhancer.\r\n *\r\n * @default \"@@PAUSED\"\"\r\n */\r\n pauseActionType?: string\r\n /**\r\n * auto pauses when the extension’s window is not opened, and so has zero impact on your app when not in use.\r\n * Not available for Redux enhancer (as it already does it but storing the data to be sent).\r\n *\r\n * @default false\r\n */\r\n autoPause?: boolean\r\n /**\r\n * if specified as `true`, it will not allow any non-monitor actions to be dispatched till clicking on `Unlock changes` button.\r\n * Available only for Redux enhancer.\r\n *\r\n * @default false\r\n */\r\n shouldStartLocked?: boolean\r\n /**\r\n * if set to `false`, will not recompute the states on hot reloading (or on replacing the reducers). Available only for Redux enhancer.\r\n *\r\n * @default true\r\n */\r\n shouldHotReload?: boolean\r\n /**\r\n * if specified as `true`, whenever there's an exception in reducers, the monitors will show the error message, and next actions will not be dispatched.\r\n *\r\n * @default false\r\n */\r\n shouldCatchErrors?: boolean\r\n /**\r\n * If you want to restrict the extension, specify the features you allow.\r\n * If not specified, all of the features are enabled. When set as an object, only those included as `true` will be allowed.\r\n * Note that except `true`/`false`, `import` and `export` can be set as `custom` (which is by default for Redux enhancer), meaning that the importing/exporting occurs on the client side.\r\n * Otherwise, you'll get/set the data right from the monitor part.\r\n */\r\n features?: {\r\n /**\r\n * start/pause recording of dispatched actions\r\n */\r\n pause?: boolean\r\n /**\r\n * lock/unlock dispatching actions and side effects\r\n */\r\n lock?: boolean\r\n /**\r\n * persist states on page reloading\r\n */\r\n persist?: boolean\r\n /**\r\n * export history of actions in a file\r\n */\r\n export?: boolean | 'custom'\r\n /**\r\n * import history of actions from a file\r\n */\r\n import?: boolean | 'custom'\r\n /**\r\n * jump back and forth (time travelling)\r\n */\r\n jump?: boolean\r\n /**\r\n * skip (cancel) actions\r\n */\r\n skip?: boolean\r\n /**\r\n * drag and drop actions in the history list\r\n */\r\n reorder?: boolean\r\n /**\r\n * dispatch custom actions or action creators\r\n */\r\n dispatch?: boolean\r\n /**\r\n * generate tests for the selected actions\r\n */\r\n test?: boolean\r\n }\r\n /**\r\n * Set to true or a stacktrace-returning function to record call stack traces for dispatched actions.\r\n * Defaults to false.\r\n */\r\n trace?: boolean | (<A extends Action>(action: A) => string)\r\n /**\r\n * The maximum number of stack trace entries to record per action. Defaults to 10.\r\n */\r\n traceLimit?: number\r\n}\r\n\r\n/**\r\n * @public\r\n */\r\nexport const composeWithDevTools: {\r\n (options: EnhancerOptions): typeof compose\r\n <StoreExt>(...funcs: Array<StoreEnhancer<StoreExt>>): StoreEnhancer<StoreExt>\r\n} =\r\n typeof window !== 'undefined' &&\r\n (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__\r\n ? (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__\r\n : function () {\r\n if (arguments.length === 0) return undefined\r\n if (typeof arguments[0] === 'object') return compose\r\n return compose.apply(null, arguments as any as Function[])\r\n }\r\n\r\n/**\r\n * @public\r\n */\r\nexport const devToolsEnhancer: {\r\n (options: EnhancerOptions): StoreEnhancer<any>\r\n} =\r\n typeof window !== 'undefined' && (window as any).__REDUX_DEVTOOLS_EXTENSION__\r\n ? (window as any).__REDUX_DEVTOOLS_EXTENSION__\r\n : function () {\r\n return function (noop) {\r\n return noop\r\n }\r\n }\r\n","/**\r\n * Returns true if the passed value is \"plain\" object, i.e. an object whose\r\n * prototype is the root `Object.prototype`. This includes objects created\r\n * using object literals, but not for instance for class instances.\r\n *\r\n * @param {any} value The value to inspect.\r\n * @returns {boolean} True if the argument appears to be a plain object.\r\n *\r\n * @public\r\n */\r\nexport default function isPlainObject(value: unknown): value is object {\r\n if (typeof value !== 'object' || value === null) return false\r\n\r\n let proto = value\r\n while (Object.getPrototypeOf(proto) !== null) {\r\n proto = Object.getPrototypeOf(proto)\r\n }\r\n\r\n return Object.getPrototypeOf(value) === proto\r\n}\r\n","import type { Middleware, AnyAction } from 'redux'\r\nimport type { ThunkMiddleware } from 'redux-thunk'\r\nimport thunkMiddleware from 'redux-thunk'\r\nimport type { ImmutableStateInvariantMiddlewareOptions } from './immutableStateInvariantMiddleware'\r\n/* PROD_START_REMOVE_UMD */\r\nimport { createImmutableStateInvariantMiddleware } from './immutableStateInvariantMiddleware'\r\n/* PROD_STOP_REMOVE_UMD */\r\n\r\nimport type { SerializableStateInvariantMiddlewareOptions } from './serializableStateInvariantMiddleware'\r\nimport { createSerializableStateInvariantMiddleware } from './serializableStateInvariantMiddleware'\r\nimport { MiddlewareArray } from './utils'\r\n\r\nfunction isBoolean(x: any): x is boolean {\r\n return typeof x === 'boolean'\r\n}\r\n\r\ninterface ThunkOptions<E = any> {\r\n extraArgument: E\r\n}\r\n\r\ninterface GetDefaultMiddlewareOptions {\r\n thunk?: boolean | ThunkOptions\r\n immutableCheck?: boolean | ImmutableStateInvariantMiddlewareOptions\r\n serializableCheck?: boolean | SerializableStateInvariantMiddlewareOptions\r\n}\r\n\r\nexport type ThunkMiddlewareFor<\r\n S,\r\n O extends GetDefaultMiddlewareOptions = {}\r\n> = O extends {\r\n thunk: false\r\n}\r\n ? never\r\n : O extends { thunk: { extraArgument: infer E } }\r\n ? ThunkMiddleware<S, AnyAction, E>\r\n :\r\n | ThunkMiddleware<S, AnyAction, null> //The ThunkMiddleware with a `null` ExtraArgument is here to provide backwards-compatibility.\r\n | ThunkMiddleware<S, AnyAction>\r\n\r\nexport type CurriedGetDefaultMiddleware<S = any> = <\r\n O extends Partial<GetDefaultMiddlewareOptions> = {\r\n thunk: true\r\n immutableCheck: true\r\n serializableCheck: true\r\n }\r\n>(\r\n options?: O\r\n) => MiddlewareArray<Middleware<{}, S> | ThunkMiddlewareFor<S, O>>\r\n\r\nexport function curryGetDefaultMiddleware<\r\n S = any\r\n>(): CurriedGetDefaultMiddleware<S> {\r\n return function curriedGetDefaultMiddleware(options) {\r\n return getDefaultMiddleware(options)\r\n }\r\n}\r\n\r\n/**\r\n * Returns any array containing the default middleware installed by\r\n * `configureStore()`. Useful if you want to configure your store with a custom\r\n * `middleware` array but still keep the default set.\r\n *\r\n * @return The default middleware used by `configureStore()`.\r\n *\r\n * @public\r\n *\r\n * @deprecated Prefer to use the callback notation for the `middleware` option in `configureStore`\r\n * to access a pre-typed `getDefaultMiddleware` instead.\r\n */\r\nexport function getDefaultMiddleware<\r\n S = any,\r\n O extends Partial<GetDefaultMiddlewareOptions> = {\r\n thunk: true\r\n immutableCheck: true\r\n serializableCheck: true\r\n }\r\n>(\r\n options: O = {} as O\r\n): MiddlewareArray<Middleware<{}, S> | ThunkMiddlewareFor<S, O>> {\r\n const {\r\n thunk = true,\r\n immutableCheck = true,\r\n serializableCheck = true,\r\n } = options\r\n\r\n let middlewareArray: Middleware<{}, S>[] = new MiddlewareArray()\r\n\r\n if (thunk) {\r\n if (isBoolean(thunk)) {\r\n middlewareArray.push(thunkMiddleware)\r\n } else {\r\n middlewareArray.push(\r\n thunkMiddleware.withExtraArgument(thunk.extraArgument)\r\n )\r\n }\r\n }\r\n\r\n if (process.env.NODE_ENV !== 'production') {\r\n if (immutableCheck) {\r\n /* PROD_START_REMOVE_UMD */\r\n let immutableOptions: ImmutableStateInvariantMiddlewareOptions = {}\r\n\r\n if (!isBoolean(immutableCheck)) {\r\n immutableOptions = immutableCheck\r\n }\r\n\r\n middlewareArray.unshift(\r\n createImmutableStateInvariantMiddleware(immutableOptions)\r\n )\r\n /* PROD_STOP_REMOVE_UMD */\r\n }\r\n\r\n if (serializableCheck) {\r\n let serializableOptions: SerializableStateInvariantMiddlewareOptions = {}\r\n\r\n if (!isBoolean(serializableCheck)) {\r\n serializableOptions = serializableCheck\r\n }\r\n\r\n middlewareArray.push(\r\n createSerializableStateInvariantMiddleware(serializableOptions)\r\n )\r\n }\r\n }\r\n\r\n return middlewareArray as any\r\n}\r\n","import type { Middleware } from 'redux'\r\n\r\nexport function getTimeMeasureUtils(maxDelay: number, fnName: string) {\r\n let elapsed = 0\r\n return {\r\n measureTime<T>(fn: () => T): T {\r\n const started = Date.now()\r\n try {\r\n return fn()\r\n } finally {\r\n const finished = Date.now()\r\n elapsed += finished - started\r\n }\r\n },\r\n warnIfExceeded() {\r\n if (elapsed > maxDelay) {\r\n console.warn(`${fnName} took ${elapsed}ms, which is more than the warning threshold of ${maxDelay}ms. \r\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.\r\nIt is disabled in production builds, so you don't need to worry about that.`)\r\n }\r\n },\r\n }\r\n}\r\n\r\n/**\r\n * @public\r\n */\r\nexport class MiddlewareArray<\r\n Middlewares extends Middleware<any, any>\r\n> extends Array<Middlewares> {\r\n constructor(arrayLength?: number)\r\n constructor(...items: Middlewares[])\r\n constructor(...args: any[]) {\r\n super(...args)\r\n Object.setPrototypeOf(this, MiddlewareArray.prototype)\r\n }\r\n\r\n static get [Symbol.species]() {\r\n return MiddlewareArray as any\r\n }\r\n\r\n concat<AdditionalMiddlewares extends ReadonlyArray<Middleware<any, any>>>(\r\n items: AdditionalMiddlewares\r\n ): MiddlewareArray<Middlewares | AdditionalMiddlewares[number]>\r\n\r\n concat<AdditionalMiddlewares extends ReadonlyArray<Middleware<any, any>>>(\r\n ...items: AdditionalMiddlewares\r\n ): MiddlewareArray<Middlewares | AdditionalMiddlewares[number]>\r\n concat(...arr: any[]) {\r\n return super.concat.apply(this, arr)\r\n }\r\n\r\n prepend<AdditionalMiddlewares extends ReadonlyArray<Middleware<any, any>>>(\r\n items: AdditionalMiddlewares\r\n ): MiddlewareArray<AdditionalMiddlewares[number] | Middlewares>\r\n\r\n prepend<AdditionalMiddlewares extends ReadonlyArray<Middleware<any, any>>>(\r\n ...items: AdditionalMiddlewares\r\n ): MiddlewareArray<AdditionalMiddlewares[number] | Middlewares>\r\n\r\n prepend(...arr: any[]) {\r\n if (arr.length === 1 && Array.isArray(arr[0])) {\r\n return new MiddlewareArray(...arr[0].concat(this))\r\n }\r\n return new MiddlewareArray(...arr.concat(this))\r\n }\r\n}\r\n","import type { Middleware } from 'redux'\r\nimport { getTimeMeasureUtils } from './utils'\r\n\r\ntype EntryProcessor = (key: string, value: any) => any\r\n\r\nconst isProduction: boolean = process.env.NODE_ENV === 'production'\r\nconst prefix: string = 'Invariant failed'\r\n\r\n// Throw an error if the condition fails\r\n// Strip out error messages for production\r\n// > Not providing an inline default argument for message as the result is smaller\r\nfunction invariant(condition: any, message?: string) {\r\n if (condition) {\r\n return\r\n }\r\n // Condition not passed\r\n\r\n // In production we strip the message but still throw\r\n if (isProduction) {\r\n throw new Error(prefix)\r\n }\r\n\r\n // When not in production we allow the message to pass through\r\n // *This block will be removed in production builds*\r\n throw new Error(`${prefix}: ${message || ''}`)\r\n}\r\n\r\nfunction stringify(\r\n obj: any,\r\n serializer?: EntryProcessor,\r\n indent?: string | number,\r\n decycler?: EntryProcessor\r\n): string {\r\n return JSON.stringify(obj, getSerialize(serializer, decycler), indent)\r\n}\r\n\r\nfunction getSerialize(\r\n serializer?: EntryProcessor,\r\n decycler?: EntryProcessor\r\n): EntryProcessor {\r\n let stack: any[] = [],\r\n keys: any[] = []\r\n\r\n if (!decycler)\r\n decycler = function (_: string, value: any) {\r\n if (stack[0] === value) return '[Circular ~]'\r\n return (\r\n '[Circular ~.' + keys.slice(0, stack.indexOf(value)).join('.') + ']'\r\n )\r\n }\r\n\r\n return function (this: any, key: string, value: any) {\r\n if (stack.length > 0) {\r\n var thisPos = stack.indexOf(this)\r\n ~thisPos ? stack.splice(thisPos + 1) : stack.push(this)\r\n ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key)\r\n if (~stack.indexOf(value)) value = decycler!.call(this, key, value)\r\n } else stack.push(value)\r\n\r\n return serializer == null ? value : serializer.call(this, key, value)\r\n }\r\n}\r\n\r\n/**\r\n * The default `isImmutable` function.\r\n *\r\n * @public\r\n */\r\nexport function isImmutableDefault(value: unknown): boolean {\r\n return (\r\n typeof value !== 'object' ||\r\n value === null ||\r\n typeof value === 'undefined' ||\r\n Object.isFrozen(value)\r\n )\r\n}\r\n\r\nexport function trackForMutations(\r\n isImmutable: IsImmutableFunc,\r\n ignorePaths: string[] | undefined,\r\n obj: any\r\n) {\r\n const trackedProperties = trackProperties(isImmutable, ignorePaths, obj)\r\n return {\r\n detectMutations() {\r\n return detectMutations(isImmutable, ignorePaths, trackedProperties, obj)\r\n },\r\n }\r\n}\r\n\r\ninterface TrackedProperty {\r\n value: any\r\n children: Record<string, any>\r\n}\r\n\r\nfunction trackProperties(\r\n isImmutable: IsImmutableFunc,\r\n ignorePaths: IgnorePaths = [],\r\n obj: Record<string, any>,\r\n path: string = ''\r\n) {\r\n const tracked: Partial<TrackedProperty> = { value: obj }\r\n\r\n if (!isImmutable(obj)) {\r\n tracked.children = {}\r\n\r\n for (const key in obj) {\r\n const childPath = path ? path + '.' + key : key\r\n if (ignorePaths.length && ignorePaths.indexOf(childPath) !== -1) {\r\n continue\r\n }\r\n\r\n tracked.children[key] = trackProperties(\r\n isImmutable,\r\n ignorePaths,\r\n obj[key],\r\n childPath\r\n )\r\n }\r\n }\r\n return tracked as TrackedProperty\r\n}\r\n\r\ntype IgnorePaths = readonly string[]\r\n\r\nfunction detectMutations(\r\n isImmutable: IsImmutableFunc,\r\n ignorePaths: IgnorePaths = [],\r\n trackedProperty: TrackedProperty,\r\n obj: any,\r\n sameParentRef: boolean = false,\r\n path: string = ''\r\n): { wasMutated: boolean; path?: string } {\r\n const prevObj = trackedProperty ? trackedProperty.value : undefined\r\n\r\n const sameRef = prevObj === obj\r\n\r\n if (sameParentRef && !sameRef && !Number.isNaN(obj)) {\r\n return { wasMutated: true, path }\r\n }\r\n\r\n if (isImmutable(prevObj) || isImmutable(obj)) {\r\n return { wasMutated: false }\r\n }\r\n\r\n // Gather all keys from prev (tracked) and after objs\r\n const keysToDetect: Record<string, boolean> = {}\r\n for (let key in trackedProperty.children) {\r\n keysToDetect[key] = true\r\n }\r\n for (let key in obj) {\r\n keysToDetect[key] = true\r\n }\r\n\r\n for (let key in keysToDetect) {\r\n const childPath = path ? path + '.' + key : key\r\n if (ignorePaths.length && ignorePaths.indexOf(childPath) !== -1) {\r\n continue\r\n }\r\n\r\n const result = detectMutations(\r\n isImmutable,\r\n ignorePaths,\r\n trackedProperty.children[key],\r\n obj[key],\r\n sameRef,\r\n childPath\r\n )\r\n\r\n if (result.wasMutated) {\r\n return result\r\n }\r\n }\r\n return { wasMutated: false }\r\n}\r\n\r\ntype IsImmutableFunc = (value: any) => boolean\r\n\r\n/**\r\n * Options for `createImmutableStateInvariantMiddleware()`.\r\n *\r\n * @public\r\n */\r\nexport interface ImmutableStateInvariantMiddlewareOptions {\r\n /**\r\n Callback function to check if a value is considered to be immutable.\r\n This function is applied recursively to every value contained in the state.\r\n The default implementation will return true for primitive types \r\n (like numbers, strings, booleans, null and undefined).\r\n */\r\n isImmutable?: IsImmutableFunc\r\n /** \r\n An array of dot-separated path strings that match named nodes from \r\n the root state to ignore when checking for immutability.\r\n Defaults to undefined\r\n */\r\n ignoredPaths?: string[]\r\n /** Print a warning if checks take longer than N ms. Default: 32ms */\r\n warnAfter?: number\r\n // @deprecated. Use ignoredPaths\r\n ignore?: string[]\r\n}\r\n\r\n/**\r\n * Creates a middleware that checks whether any state was mutated in between\r\n * dispatches or during a dispatch. If any mutations are detected, an error is\r\n * thrown.\r\n *\r\n * @param options Middleware options.\r\n *\r\n * @public\r\n */\r\nexport function createImmutableStateInvariantMiddleware(\r\n options: ImmutableStateInvariantMiddlewareOptions = {}\r\n): Middleware {\r\n if (process.env.NODE_ENV === 'production') {\r\n return () => (next) => (action) => next(action)\r\n }\r\n\r\n let {\r\n isImmutable = isImmutableDefault,\r\n ignoredPaths,\r\n warnAfter = 32,\r\n ignore,\r\n } = options\r\n\r\n // Alias ignore->ignoredPaths, but prefer ignoredPaths if present\r\n ignoredPaths = ignoredPaths || ignore\r\n\r\n const track = trackForMutations.bind(null, isImmutable, ignoredPaths)\r\n\r\n return ({ getState }) => {\r\n let state = getState()\r\n let tracker = track(state)\r\n\r\n let result\r\n return (next) => (action) => {\r\n const measureUtils = getTimeMeasureUtils(\r\n warnAfter,\r\n 'ImmutableStateInvariantMiddleware'\r\n )\r\n\r\n measureUtils.measureTime(() => {\r\n state = getState()\r\n\r\n result = tracker.detectMutations()\r\n // Track before potentially not meeting the invariant\r\n tracker = track(state)\r\n\r\n invariant(\r\n !result.wasMutated,\r\n `A state mutation was detected between dispatches, in the path '${\r\n result.path || ''\r\n }'. This may cause incorrect behavior. (https://redux.js.org/style-guide/style-guide#do-not-mutate-state)`\r\n )\r\n })\r\n\r\n const dispatchedAction = next(action)\r\n\r\n measureUtils.measureTime(() => {\r\n state = getState()\r\n\r\n result = tracker.detectMutations()\r\n // Track before potentially not meeting the invariant\r\n tracker = track(state)\r\n\r\n result.wasMutated &&\r\n invariant(\r\n !result.wasMutated,\r\n `A state mutation was detected inside a dispatch, in the path: ${\r\n result.path || ''\r\n }. Take a look at the reducer(s) handling the action ${stringify(\r\n action\r\n )}. (https://redux.js.org/style-guide/style-guide#do-not-mutate-state)`\r\n )\r\n })\r\n\r\n measureUtils.warnIfExceeded()\r\n\r\n return dispatchedAction\r\n }\r\n }\r\n}\r\n","import isPlainObject from './isPlainObject'\r\nimport type { Middleware } from 'redux'\r\nimport { getTimeMeasureUtils } from './utils'\r\n\r\n/**\r\n * Returns true if the passed value is \"plain\", i.e. a value that is either\r\n * directly JSON-serializable (boolean, number, string, array, plain object)\r\n * or `undefined`.\r\n *\r\n * @param val The value to check.\r\n *\r\n * @public\r\n */\r\nexport function isPlain(val: any) {\r\n const type = typeof val\r\n return (\r\n type === 'undefined' ||\r\n val === null ||\r\n type === 'string' ||\r\n type === 'boolean' ||\r\n type === 'number' ||\r\n Array.isArray(val) ||\r\n isPlainObject(val)\r\n )\r\n}\r\n\r\ninterface NonSerializableValue {\r\n keyPath: string\r\n value: unknown\r\n}\r\n\r\n/**\r\n * @public\r\n */\r\nexport function findNonSerializableValue(\r\n value: unknown,\r\n path: string = '',\r\n isSerializable: (value: unknown) => boolean = isPlain,\r\n getEntries?: (value: unknown) => [string, any][],\r\n ignoredPaths: readonly string[] = []\r\n): NonSerializableValue | false {\r\n let foundNestedSerializable: NonSerializableValue | false\r\n\r\n if (!isSerializable(value)) {\r\n return {\r\n keyPath: path || '<root>',\r\n value: value,\r\n }\r\n }\r\n\r\n if (typeof value !== 'object' || value === null) {\r\n return false\r\n }\r\n\r\n const entries = getEntries != null ? getEntries(value) : Object.entries(value)\r\n\r\n const hasIgnoredPaths = ignoredPaths.length > 0\r\n\r\n for (const [key, nestedValue] of entries) {\r\n const nestedPath = path ? path + '.' + key : key\r\n\r\n if (hasIgnoredPaths && ignoredPaths.indexOf(nestedPath) >= 0) {\r\n continue\r\n }\r\n\r\n if (!isSerializable(nestedValue)) {\r\n return {\r\n keyPath: nestedPath,\r\n value: nestedValue,\r\n }\r\n }\r\n\r\n if (typeof nestedValue === 'object') {\r\n foundNestedSerializable = findNonSerializableValue(\r\n nestedValue,\r\n nestedPath,\r\n isSerializable,\r\n getEntries,\r\n ignoredPaths\r\n )\r\n\r\n if (foundNestedSerializable) {\r\n return foundNestedSerializable\r\n }\r\n }\r\n }\r\n\r\n return false\r\n}\r\n\r\n/**\r\n * Options for `createSerializableStateInvariantMiddleware()`.\r\n *\r\n * @public\r\n */\r\nexport interface SerializableStateInvariantMiddlewareOptions {\r\n /**\r\n * The function to check if a value is considered serializable. This\r\n * function is applied recursively to every value contained in the\r\n * state. Defaults to `isPlain()`.\r\n */\r\n isSerializable?: (value: any) => boolean\r\n /**\r\n * The function that will be used to retrieve entries from each\r\n * value. If unspecified, `Object.entries` will be used. Defaults\r\n * to `undefined`.\r\n */\r\n getEntries?: (value: any) => [string, any][]\r\n\r\n /**\r\n * An array of action types to ignore when checking for serializability.\r\n * Defaults to []\r\n */\r\n ignoredActions?: string[]\r\n\r\n /**\r\n * An array of dot-separated path strings to ignore when checking\r\n * for serializability, Defaults to ['meta.arg']\r\n */\r\n ignoredActionPaths?: string[]\r\n\r\n /**\r\n * An array of dot-separated path strings to ignore when checking\r\n * for serializability, Defaults to []\r\n */\r\n ignoredPaths?: string[]\r\n /**\r\n * Execution time warning threshold. If the middleware takes longer\r\n * than `warnAfter` ms, a warning will be displayed in the console.\r\n * Defaults to 32ms.\r\n */\r\n warnAfter?: number\r\n\r\n /**\r\n * Opt out of checking state, but continue checking actions\r\n */\r\n ignoreState?: boolean\r\n}\r\n\r\n/**\r\n * Creates a middleware that, after every state change, checks if the new\r\n * state is serializable. If a non-serializable value is found within the\r\n * state, an error is printed to the console.\r\n *\r\n * @param options Middleware options.\r\n *\r\n * @public\r\n */\r\nexport function createSerializableStateInvariantMiddleware(\r\n options: SerializableStateInvariantMiddlewareOptions = {}\r\n): Middleware {\r\n if (process.env.NODE_ENV === 'production') {\r\n return () => (next) => (action) => next(action)\r\n }\r\n const {\r\n isSerializable = isPlain,\r\n getEntries,\r\n ignoredActions = [],\r\n ignoredActionPaths = ['meta.arg', 'meta.baseQueryMeta'],\r\n ignoredPaths = [],\r\n warnAfter = 32,\r\n ignoreState = false,\r\n } = options\r\n\r\n return (storeAPI) => (next) => (action) => {\r\n if (ignoredActions.length && ignoredActions.indexOf(action.type) !== -1) {\r\n return next(action)\r\n }\r\n\r\n const measureUtils = getTimeMeasureUtils(\r\n warnAfter,\r\n 'SerializableStateInvariantMiddleware'\r\n )\r\n measureUtils.measureTime(() => {\r\n const foundActionNonSerializableValue = findNonSerializableValue(\r\n action,\r\n '',\r\n isSerializable,\r\n getEntries,\r\n ignoredActionPaths\r\n )\r\n\r\n if (foundActionNonSerializableValue) {\r\n const { keyPath, value } = foundActionNonSerializableValue\r\n\r\n console.error(\r\n `A non-serializable value was detected in an action, in the path: \\`${keyPath}\\`. Value:`,\r\n value,\r\n '\\nTake a look at the logic that dispatched this action: ',\r\n action,\r\n '\\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)',\r\n '\\n(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)'\r\n )\r\n }\r\n })\r\n\r\n const result = next(action)\r\n\r\n if (!ignoreState) {\r\n measureUtils.measureTime(() => {\r\n const state = storeAPI.getState()\r\n\r\n const foundStateNonSerializableValue = findNonSerializableValue(\r\n state,\r\n '',\r\n isSerializable,\r\n getEntries,\r\n ignoredPaths\r\n )\r\n\r\n if (foundStateNonSerializableValue) {\r\n const { keyPath, value } = foundStateNonSerializableValue\r\n\r\n console.error(\r\n `A non-serializable value was detected in the state, in the path: \\`${keyPath}\\`. Value:`,\r\n value,\r\n `\r\nTake a look at the reducer(s) handling this action type: ${action.type}.\r\n(See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)`\r\n )\r\n }\r\n })\r\n\r\n measureUtils.warnIfExceeded()\r\n }\r\n\r\n return result\r\n }\r\n}\r\n","import type { Action } from 'redux'\r\nimport type {\r\n IsUnknownOrNonInferrable,\r\n IfMaybeUndefined,\r\n IfVoid,\r\n IsAny,\r\n} from './tsHelpers'\r\nimport isPlainObject from './isPlainObject'\r\n\r\n/**\r\n * An action with a string type and an associated payload. This is the\r\n * type of action returned by `createAction()` action creators.\r\n *\r\n * @template P The type of the action's payload.\r\n * @template T the type used for the action type.\r\n * @template M The type of the action's meta (optional)\r\n * @template E The type of the action's error (optional)\r\n *\r\n * @public\r\n */\r\nexport type PayloadAction<\r\n P = void,\r\n T extends string = string,\r\n M = never,\r\n E = never\r\n> = {\r\n payload: P\r\n type: T\r\n} & ([M] extends [never]\r\n ? {}\r\n : {\r\n meta: M\r\n }) &\r\n ([E] extends [never]\r\n ? {}\r\n : {\r\n error: E\r\n })\r\n\r\n/**\r\n * A \"prepare\" method to be used as the second parameter of `createAction`.\r\n * Takes any number of arguments and returns a Flux Standard Action without\r\n * type (will be added later) that *must* contain a payload (might be undefined).\r\n *\r\n * @public\r\n */\r\nexport type PrepareAction<P> =\r\n | ((...args: any[]) => { payload: P })\r\n | ((...args: any[]) => { payload: P; meta: any })\r\n | ((...args: any[]) => { payload: P; error: any })\r\n | ((...args: any[]) => { payload: P; meta: any; error: any })\r\n\r\n/**\r\n * Internal version of `ActionCreatorWithPreparedPayload`. Not to be used externally.\r\n *\r\n * @internal\r\n */\r\nexport type _ActionCreatorWithPreparedPayload<\r\n PA extends PrepareAction<any> | void,\r\n T extends string = string\r\n> = PA extends PrepareAction<infer P>\r\n ? ActionCreatorWithPreparedPayload<\r\n Parameters<PA>,\r\n P,\r\n T,\r\n ReturnType<PA> extends {\r\n error: infer E\r\n }\r\n ? E\r\n : never,\r\n ReturnType<PA> extends {\r\n meta: infer M\r\n }\r\n ? M\r\n : never\r\n >\r\n : void\r\n\r\n/**\r\n * Basic type for all action creators.\r\n *\r\n * @inheritdoc {redux#ActionCreator}\r\n */\r\ninterface BaseActionCreator<P, T extends string, M = never, E = never> {\r\n type: T\r\n match: (action: Action<unknown>) => action is PayloadAction<P, T, M, E>\r\n}\r\n\r\n/**\r\n * An action creator that takes multiple arguments that are passed\r\n * to a `PrepareAction` method to create the final Action.\r\n * @typeParam Args arguments for the action creator function\r\n * @typeParam P `payload` type\r\n * @typeParam T `type` name\r\n * @typeParam E optional `error` type\r\n * @typeParam M optional `meta` type\r\n *\r\n * @inheritdoc {redux#ActionCreator}\r\n *\r\n * @public\r\n */\r\nexport interface ActionCreatorWithPreparedPayload<\r\n Args extends unknown[],\r\n P,\r\n T extends string = string,\r\n E = never,\r\n M = never\r\n> extends BaseActionCreator<P, T, M, E> {\r\n /**\r\n * Calling this {@link redux#ActionCreator} with `Args` will return\r\n * an Action with a payload of type `P` and (depending on the `PrepareAction`\r\n * method used) a `meta`- and `error` property of types `M` and `E` respectively.\r\n */\r\n (...args: Args): PayloadAction<P, T, M, E>\r\n}\r\n\r\n/**\r\n * An action creator of type `T` that takes an optional payload of type `P`.\r\n *\r\n * @inheritdoc {redux#ActionCreator}\r\n *\r\n * @public\r\n */\r\nexport interface ActionCreatorWithOptionalPayload<P, T extends string = string>\r\n extends BaseActionCreator<P, T> {\r\n /**\r\n * Calling this {@link redux#ActionCreator} with an argument will\r\n * return a {@link PayloadAction} of type `T` with a payload of `P`.\r\n * Calling it without an argument will return a PayloadAction with a payload of `undefined`.\r\n */\r\n (payload?: P): PayloadAction<P, T>\r\n}\r\n\r\n/**\r\n * An action creator of type `T` that takes no payload.\r\n *\r\n * @inheritdoc {redux#ActionCreator}\r\n *\r\n * @public\r\n */\r\nexport interface ActionCreatorWithoutPayload<T extends string = string>\r\n extends BaseActionCreator<undefined, T> {\r\n /**\r\n * Calling this {@link redux#ActionCreator} will\r\n * return a {@link PayloadAction} of type `T` with a payload of `undefined`\r\n */\r\n (): PayloadAction<undefined, T>\r\n}\r\n\r\n/**\r\n * An action creator of type `T` that requires a payload of type P.\r\n *\r\n * @inheritdoc {redux#ActionCreator}\r\n *\r\n * @public\r\n */\r\nexport interface ActionCreatorWithPayload<P, T extends string = string>\r\n extends BaseActionCreator<P, T> {\r\n /**\r\n * Calling this {@link redux#ActionCreator} with an argument will\r\n * return a {@link PayloadAction} of type `T` with a payload of `P`\r\n */\r\n (payload: P): PayloadAction<P, T>\r\n}\r\n\r\n/**\r\n * An action creator of type `T` whose `payload` type could not be inferred. Accepts everything as `payload`.\r\n *\r\n * @inheritdoc {redux#ActionCreator}\r\n *\r\n * @public\r\n */\r\nexport interface ActionCreatorWithNonInferrablePayload<\r\n T extends string = string\r\n> extends BaseActionCreator<unknown, T> {\r\n /**\r\n * Calling this {@link redux#ActionCreator} with an argument will\r\n * return a {@link PayloadAction} of type `T` with a payload\r\n * of exactly the type of the argument.\r\n */\r\n <PT extends unknown>(payload: PT): PayloadAction<PT, T>\r\n}\r\n\r\n/**\r\n * An action creator that produces actions with a `payload` attribute.\r\n *\r\n * @typeParam P the `payload` type\r\n * @typeParam T the `type` of the resulting action\r\n * @typeParam PA if the resulting action is preprocessed by a `prepare` method, the signature of said method.\r\n *\r\n * @public\r\n */\r\nexport type PayloadActionCreator<\r\n P = void,\r\n T extends string = string,\r\n PA extends PrepareAction<P> | void = void\r\n> = IfPrepareActionMethodProvided<\r\n PA,\r\n _ActionCreatorWithPreparedPayload<PA, T>,\r\n // else\r\n IsAny<\r\n P,\r\n ActionCreatorWithPayload<any, T>,\r\n IsUnknownOrNonInferrable<\r\n P,\r\n ActionCreatorWithNonInferrablePayload<T>,\r\n // else\r\n IfVoid<\r\n P,\r\n ActionCreatorWithoutPayload<T>,\r\n // else\r\n IfMaybeUndefined<\r\n P,\r\n ActionCreatorWithOptionalPayload<P, T>,\r\n // else\r\n ActionCreatorWithPayload<P, T>\r\n >\r\n >\r\n >\r\n >\r\n>\r\n\r\n/**\r\n * A utility function to create an action creator for the given action type\r\n * string. The action creator accepts a single argument, which will be included\r\n * in the action object as a field called payload. The action creator function\r\n * will also have its toString() overriden so that it returns the action type,\r\n * allowing it to be used in reducer logic that is looking for that action type.\r\n *\r\n * @param type The action type to use for created actions.\r\n * @param prepare (optional) a method that takes any number of arguments and returns { payload } or { payload, meta }.\r\n * If this is given, the resulting action creator will pass its arguments to this method to calculate payload & meta.\r\n *\r\n * @public\r\n */\r\nexport function createAction<P = void, T extends string = string>(\r\n type: T\r\n): PayloadActionCreator<P, T>\r\n\r\n/**\r\n * A utility function to create an action creator for the given action type\r\n * string. The action creator accepts a single argument, which will be included\r\n * in the action object as a field called payload. The action creator function\r\n * will also have its toString() overriden so that it returns the action type,\r\n * allowing it to be used in reducer logic that is looking for that action type.\r\n *\r\n * @param type The action type to use for created actions.\r\n * @param prepare (optional) a method that takes any number of arguments and returns { payload } or { payload, meta }.\r\n * If this is given, the resulting action creator will pass its arguments to this method to calculate payload & meta.\r\n *\r\n * @public\r\n */\r\nexport function createAction<\r\n PA extends PrepareAction<any>,\r\n T extends string = string\r\n>(\r\n type: T,\r\n prepareAction: PA\r\n): PayloadActionCreator<ReturnType<PA>['payload'], T, PA>\r\n\r\nexport function createAction(type: string, prepareAction?: Function): any {\r\n function actionCreator(...args: any[]) {\r\n if (prepareAction) {\r\n let prepared = prepareAction(...args)\r\n if (!prepared) {\r\n throw new Error('prepareAction did not return an object')\r\n }\r\n\r\n return {\r\n type,\r\n payload: prepared.payload,\r\n ...('meta' in prepared && { meta: prepared.meta }),\r\n ...('error' in prepared && { error: prepared.error }),\r\n }\r\n }\r\n return { type, payload: args[0] }\r\n }\r\n\r\n actionCreator.toString = () => `${type}`\r\n\r\n actionCreator.type = type\r\n\r\n actionCreator.match = (action: Action<unknown>): action is PayloadAction =>\r\n action.type === type\r\n\r\n return actionCreator\r\n}\r\n\r\nexport function isFSA(action: unknown): action is {\r\n type: string\r\n payload?: unknown\r\n error?: unknown\r\n meta?: unknown\r\n} {\r\n return (\r\n isPlainObject(action) &&\r\n typeof (action as any).type === 'string' &&\r\n Object.keys(action).every(isValidKey)\r\n )\r\n}\r\n\r\nfunction isValidKey(key: string) {\r\n return ['type', 'payload', 'error', 'meta'].indexOf(key) > -1\r\n}\r\n\r\n/**\r\n * Returns the action type of the actions created by the passed\r\n * `createAction()`-generated action creator (arbitrary action creators\r\n * are not supported).\r\n *\r\n * @param action The action creator whose action type to get.\r\n * @returns The action type used by the action creator.\r\n *\r\n * @public\r\n */\r\nexport function getType<T extends string>(\r\n actionCreator: PayloadActionCreator<any, T>\r\n): T {\r\n return `${actionCreator}` as T\r\n}\r\n\r\n// helper types for more readable typings\r\n\r\ntype IfPrepareActionMethodProvided<\r\n PA extends PrepareAction<any> | void,\r\n True,\r\n False\r\n> = PA extends (...args: any[]) => any ? True : False\r\n","import type { Draft } from 'immer'\r\nimport createNextState, { isDraft, isDraftable } from 'immer'\r\nimport type { AnyAction, Action, Reducer } from 'redux'\r\nimport type { ActionReducerMapBuilder } from './mapBuilders'\r\nimport { executeReducerBuilderCallback } from './mapBuilders'\r\nimport type { NoInfer } from './tsHelpers'\r\n\r\n/**\r\n * Defines a mapping from action types to corresponding action object shapes.\r\n *\r\n * @deprecated This should not be used manually - it is only used for internal\r\n * inference purposes and should not have any further value.\r\n * It might be removed in the future.\r\n * @public\r\n */\r\nexport type Actions<T extends keyof any = string> = Record<T, Action>\r\n\r\nexport interface ActionMatcher<A extends AnyAction> {\r\n (action: AnyAction): action is A\r\n}\r\n\r\nexport type ActionMatcherDescription<S, A extends AnyAction> = {\r\n matcher: ActionMatcher<A>\r\n reducer: CaseReducer<S, NoInfer<A>>\r\n}\r\n\r\nexport type ReadonlyActionMatcherDescriptionCollection<S> = ReadonlyArray<\r\n ActionMatcherDescription<S, any>\r\n>\r\n\r\nexport type ActionMatcherDescriptionCollection<S> = Array<\r\n ActionMatcherDescription<S, any>\r\n>\r\n\r\n/**\r\n * An *case reducer* is a reducer function for a specific action type. Case\r\n * reducers can be composed to full reducers using `createReducer()`.\r\n *\r\n * Unlike a normal Redux reducer, a case reducer is never called with an\r\n * `undefined` state to determine the initial state. Instead, the initial\r\n * state is explicitly specified as an argument to `createReducer()`.\r\n *\r\n * In addition, a case reducer can choose to mutate the passed-in `state`\r\n * value directly instead of returning a new state. This does not actually\r\n * cause the store state to be mutated directly; instead, thanks to\r\n * [immer](https://github.com/mweststrate/immer), the mutations are\r\n * translated to copy operations that result in a new state.\r\n *\r\n * @public\r\n */\r\nexport type CaseReducer<S = any, A extends Action = AnyAction> = (\r\n state: Draft<S>,\r\n action: A\r\n) => S | void | Draft<S>\r\n\r\n/**\r\n * A mapping from action types to case reducers for `createReducer()`.\r\n *\r\n * @deprecated This should not be used manually - it is only used\r\n * for internal inference purposes and using it manually\r\n * would lead to type erasure.\r\n * It might be removed in the future.\r\n * @public\r\n */\r\nexport type CaseReducers<S, AS extends Actions> = {\r\n [T in keyof AS]: AS[T] extends Action ? CaseReducer<S, AS[T]> : void\r\n}\r\n\r\n/**\r\n * A utility function that allows defining a reducer as a mapping from action\r\n * type to *case reducer* functions that handle these action types. The\r\n * reducer's initial state is passed as the first argument.\r\n *\r\n * @remarks\r\n * The body of every case reducer is implicitly wrapped with a call to\r\n * `produce()` from the [immer](https://github.com/mweststrate/immer) library.\r\n * This means that rather than returning a new state object, you can also\r\n * mutate the passed-in state object directly; these mutations will then be\r\n * automatically and efficiently translated into copies, giving you both\r\n * convenience and immutability.\r\n *\r\n * @overloadSummary\r\n * This overload accepts a callback function that receives a `builder` object as its argument.\r\n * That builder provides `addCase`, `addMatcher` and `addDefaultCase` functions that may be\r\n * called to define what actions this reducer will handle.\r\n *\r\n * @param initialState - The initial state that should be used when the reducer is called the first time.\r\n * @param builderCallback - A callback that receives a *builder* object to define\r\n * case reducers via calls to `builder.addCase(actionCreatorOrType, reducer)`.\r\n * @example\r\n```ts\r\nimport {\r\n createAction,\r\n createReducer,\r\n AnyAction,\r\n PayloadAction,\r\n} from \"@reduxjs/toolkit\";\r\n\r\nconst increment = createAction<number>(\"increment\");\r\nconst decrement = createAction<number>(\"decrement\");\r\n\r\nfunction isActionWithNumberPayload(\r\n action: AnyAction\r\n): action is PayloadAction<number> {\r\n return typeof action.payload === \"number\";\r\n}\r\n\r\ncreateReducer(\r\n {\r\n counter: 0,\r\n sumOfNumberPayloads: 0,\r\n unhandledActions: 0,\r\n },\r\n (builder) => {\r\n builder\r\n .addCase(increment, (state, action) => {\r\n // action is inferred correctly here\r\n state.counter += action.payload;\r\n })\r\n // You can chain calls, or have separate `builder.addCase()` lines each time\r\n .addCase(decrement, (state, action) => {\r\n state.counter -= action.payload;\r\n })\r\n // You can apply a \"matcher function\" to incoming actions\r\n .addMatcher(isActionWithNumberPayload, (state, action) => {})\r\n // and provide a default case if no other handlers matched\r\n .addDefaultCase((state, action) => {});\r\n }\r\n);\r\n```\r\n * @public\r\n */\r\nexport function createReducer<S>(\r\n initialState: S,\r\n builderCallback: (builder: ActionReducerMapBuilder<S>) => void\r\n): Reducer<S>\r\n\r\n/**\r\n * A utility function that allows defining a reducer as a mapping from action\r\n * type to *case reducer* functions that handle these action types. The\r\n * reducer's initial state is passed as the first argument.\r\n *\r\n * The body of every case reducer is implicitly wrapped with a call to\r\n * `produce()` from the [immer](https://github.com/mweststrate/immer) library.\r\n * This means that rather than returning a new state object, you can also\r\n * mutate the passed-in state object directly; these mutations will then be\r\n * automatically and efficiently translated into copies, giving you both\r\n * convenience and immutability.\r\n * \r\n * @overloadSummary\r\n * This overload accepts an object where the keys are string action types, and the values\r\n * are case reducer functions to handle those action types.\r\n *\r\n * @param initialState - The initial state that should be used when the reducer is called the first time.\r\n * @param actionsMap - An object mapping from action types to _case reducers_, each of which handles one specific action type.\r\n * @param actionMatchers - An array of matcher definitions in the form `{matcher, reducer}`.\r\n * All matching reducers will be executed in order, independently if a case reducer matched or not.\r\n * @param defaultCaseReducer - A \"default case\" reducer that is executed if no case reducer and no matcher\r\n * reducer was executed for this action.\r\n *\r\n * @example\r\n```js\r\nconst counterReducer = createReducer(0, {\r\n increment: (state, action) => state + action.payload,\r\n decrement: (state, action) => state - action.payload\r\n})\r\n```\r\n \r\n * Action creators that were generated using [`createAction`](./createAction) may be used directly as the keys here, using computed property syntax:\r\n\r\n```js\r\nconst increment = createAction('increment')\r\nconst decrement = createAction('decrement')\r\n\r\nconst counterReducer = createReducer(0, {\r\n [increment]: (state, action) => state + action.payload,\r\n [decrement.type]: (state, action) => state - action.payload\r\n})\r\n```\r\n * @public\r\n */\r\nexport function createReducer<\r\n S,\r\n CR extends CaseReducers<S, any> = CaseReducers<S, any>\r\n>(\r\n initialState: S,\r\n actionsMap: CR,\r\n actionMatchers?: ActionMatcherDescriptionCollection<S>,\r\n defaultCaseReducer?: CaseReducer<S>\r\n): Reducer<S>\r\n\r\nexport function createReducer<S>(\r\n initialState: S,\r\n mapOrBuilderCallback:\r\n | CaseReducers<S, any>\r\n | ((builder: ActionReducerMapBuilder<S>) => void),\r\n actionMatchers: ReadonlyActionMatcherDescriptionCollection<S> = [],\r\n defaultCaseReducer?: CaseReducer<S>\r\n): Reducer<S> {\r\n let [actionsMap, finalActionMatchers, finalDefaultCaseReducer] =\r\n typeof mapOrBuilderCallback === 'function'\r\n ? executeReducerBuilderCallback(mapOrBuilderCallback)\r\n : [mapOrBuilderCallback, actionMatchers, defaultCaseReducer]\r\n\r\n const frozenInitialState = createNextState(initialState, () => {})\r\n\r\n return function (state = frozenInitialState, action): S {\r\n let caseReducers = [\r\n actionsMap[action.type],\r\n ...finalActionMatchers\r\n .filter(({ matcher }) => matcher(action))\r\n .map(({ reducer }) => reducer),\r\n ]\r\n if (caseReducers.filter((cr) => !!cr).length === 0) {\r\n caseReducers = [finalDefaultCaseReducer]\r\n }\r\n\r\n return caseReducers.reduce((previousState, caseReducer): S => {\r\n if (caseReducer) {\r\n if (isDraft(previousState)) {\r\n // If it's already a draft, we must already be inside a `createNextState` call,\r\n // likely because this is being wrapped in `createReducer`, `createSlice`, or nested\r\n // inside an existing draft. It's safe to just pass the draft to the mutator.\r\n const draft = previousState as Draft<S> // We can assume this is already a draft\r\n const result = caseReducer(draft, action)\r\n\r\n if (typeof result === 'undefined') {\r\n return previousState\r\n }\r\n\r\n return result as S\r\n } else if (!isDraftable(previousState)) {\r\n // If state is not draftable (ex: a primitive, such as 0), we want to directly\r\n // return the caseReducer func and not wrap it with produce.\r\n const result = caseReducer(previousState as any, action)\r\n\r\n if (typeof result === 'undefined') {\r\n if (previousState === null) {\r\n return previousState\r\n }\r\n throw Error(\r\n 'A case reducer on a non-draftable value must not return undefined'\r\n )\r\n }\r\n\r\n return result as S\r\n } else {\r\n // @ts-ignore createNextState() produces an Immutable<Draft<S>> rather\r\n // than an Immutable<S>, and TypeScript cannot find out how to reconcile\r\n // these two types.\r\n return createNextState(previousState, (draft: Draft<S>) => {\r\n return caseReducer(draft, action)\r\n })\r\n }\r\n }\r\n\r\n return previousState\r\n }, state)\r\n }\r\n}\r\n","import type { Action, AnyAction } from 'redux'\r\nimport type {\r\n CaseReducer,\r\n CaseReducers,\r\n ActionMatcher,\r\n ActionMatcherDescriptionCollection,\r\n} from './createReducer'\r\n\r\nexport interface TypedActionCreator<Type extends string> {\r\n (...args: any[]): Action<Type>\r\n type: Type\r\n}\r\n\r\n/**\r\n * A builder for an action <-> reducer map.\r\n *\r\n * @public\r\n */\r\nexport interface ActionReducerMapBuilder<State> {\r\n /**\r\n * Adds a case reducer to handle a single exact action type.\r\n * @remarks\r\n * All calls to `builder.addCase` must come before any calls to `builder.addMatcher` or `builder.addDefaultCase`.\r\n * @param actionCreator - Either a plain action type string, or an action creator generated by [`createAction`](./createAction) that can be used to determine the action type.\r\n * @param reducer - The actual case reducer function.\r\n */\r\n addCase<ActionCreator extends TypedActionCreator<string>>(\r\n actionCreator: ActionCreator,\r\n reducer: CaseReducer<State, ReturnType<ActionCreator>>\r\n ): ActionReducerMapBuilder<State>\r\n /**\r\n * Adds a case reducer to handle a single exact action type.\r\n * @remarks\r\n * All calls to `builder.addCase` must come before any calls to `builder.addMatcher` or `builder.addDefaultCase`.\r\n * @param actionCreator - Either a plain action type string, or an action creator generated by [`createAction`](./createAction) that can be used to determine the action type.\r\n * @param reducer - The actual case reducer function.\r\n */\r\n addCase<Type extends string, A extends Action<Type>>(\r\n type: Type,\r\n reducer: CaseReducer<State, A>\r\n ): ActionReducerMapBuilder<State>\r\n\r\n /**\r\n * Allows you to match your incoming actions against your own filter function instead of only the `action.type` property.\r\n * @remarks\r\n * If multiple matcher reducers match, all of them will be executed in the order\r\n * they were defined in - even if a case reducer already matched.\r\n * All calls to `builder.addMatcher` must come after any calls to `builder.addCase` and before any calls to `builder.addDefaultCase`.\r\n * @param matcher - A matcher function. In TypeScript, this should be a [type predicate](https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates)\r\n * function\r\n * @param reducer - The actual case reducer function.\r\n *\r\n * @example\r\n```ts\r\nimport {\r\n createAction,\r\n createReducer,\r\n AsyncThunk,\r\n AnyAction,\r\n} from \"@reduxjs/toolkit\";\r\n\r\ntype GenericAsyncThunk = AsyncThunk<unknown, unknown, any>;\r\n\r\ntype PendingAction = ReturnType<GenericAsyncThunk[\"pending\"]>;\r\ntype RejectedAction = ReturnType<GenericAsyncThunk[\"rejected\"]>;\r\ntype FulfilledAction = ReturnType<GenericAsyncThunk[\"fulfilled\"]>;\r\n\r\nconst initialState: Record<string, string> = {};\r\nconst resetAction = createAction(\"reset-tracked-loading-state\");\r\n\r\nfunction isPendingAction(action: AnyAction): action is PendingAction {\r\n return action.type.endsWith(\"/pending\");\r\n}\r\n\r\nconst reducer = createReducer(initialState, (builder) => {\r\n builder\r\n .addCase(resetAction, () => initialState)\r\n // matcher can be defined outside as a type predicate function\r\n .addMatcher(isPendingAction, (state, action) => {\r\n state[action.meta.requestId] = \"pending\";\r\n })\r\n .addMatcher(\r\n // matcher can be defined inline as a type predicate function\r\n (action): action is RejectedAction => action.type.endsWith(\"/rejected\"),\r\n (state, action) => {\r\n state[action.meta.requestId] = \"rejected\";\r\n }\r\n )\r\n // matcher can just return boolean and the matcher can receive a generic argument\r\n .addMatcher<FulfilledAction>(\r\n (action) => action.type.endsWith(\"/fulfilled\"),\r\n (state, action) => {\r\n state[action.meta.requestId] = \"fulfilled\";\r\n }\r\n );\r\n});\r\n```\r\n */\r\n addMatcher<A extends AnyAction>(\r\n matcher: ActionMatcher<A> | ((action: AnyAction) => boolean),\r\n reducer: CaseReducer<State, A>\r\n ): Omit<ActionReducerMapBuilder<State>, 'addCase'>\r\n\r\n /**\r\n * Adds a \"default case\" reducer that is executed if no case reducer and no matcher\r\n * reducer was executed for this action.\r\n * @param reducer - The fallback \"default case\" reducer function.\r\n *\r\n * @example\r\n```ts\r\nimport { createReducer } from '@reduxjs/toolkit'\r\nconst initialState = { otherActions: 0 }\r\nconst reducer = createReducer(initialState, builder => {\r\n builder\r\n // .addCase(...)\r\n // .addMatcher(...)\r\n .addDefaultCase((state, action) => {\r\n state.otherActions++\r\n })\r\n})\r\n```\r\n */\r\n addDefaultCase(reducer: CaseReducer<State, AnyAction>): {}\r\n}\r\n\r\nexport function executeReducerBuilderCallback<S>(\r\n builderCallback: (builder: ActionReducerMapBuilder<S>) => void\r\n): [\r\n CaseReducers<S, any>,\r\n ActionMatcherDescriptionCollection<S>,\r\n CaseReducer<S, AnyAction> | undefined\r\n] {\r\n const actionsMap: CaseReducers<S, any> = {}\r\n const actionMatchers: ActionMatcherDescriptionCollection<S> = []\r\n let defaultCaseReducer: CaseReducer<S, AnyAction> | undefined\r\n const builder = {\r\n addCase(\r\n typeOrActionCreator: string | TypedActionCreator<any>,\r\n reducer: CaseReducer<S>\r\n ) {\r\n if (process.env.NODE_ENV !== 'production') {\r\n /*\r\n to keep the definition by the user in line with actual behavior, \r\n we enforce `addCase` to always be called before calling `addMatcher`\r\n as matching cases take precedence over matchers\r\n */\r\n if (actionMatchers.length > 0) {\r\n throw new Error(\r\n '`builder.addCase` should only be called before calling `builder.addMatcher`'\r\n )\r\n }\r\n if (defaultCaseReducer) {\r\n throw new Error(\r\n '`builder.addCase` should only be called before calling `builder.addDefaultCase`'\r\n )\r\n }\r\n }\r\n const type =\r\n typeof typeOrActionCreator === 'string'\r\n ? typeOrActionCreator\r\n : typeOrActionCreator.type\r\n if (type in actionsMap) {\r\n throw new Error(\r\n 'addCase cannot be called with two reducers for the same action type'\r\n )\r\n }\r\n actionsMap[type] = reducer\r\n return builder\r\n },\r\n addMatcher<A extends AnyAction>(\r\n matcher: ActionMatcher<A>,\r\n reducer: CaseReducer<S, A>\r\n ) {\r\n if (process.env.NODE_ENV !== 'production') {\r\n if (defaultCaseReducer) {\r\n throw new Error(\r\n '`builder.addMatcher` should only be called before calling `builder.addDefaultCase`'\r\n )\r\n }\r\n }\r\n actionMatchers.push({ matcher, reducer })\r\n return builder\r\n },\r\n addDefaultCase(reducer: CaseReducer<S, AnyAction>) {\r\n if (process.env.NODE_ENV !== 'production') {\r\n if (defaultCaseReducer) {\r\n throw new Error('`builder.addDefaultCase` can only be called once')\r\n }\r\n }\r\n defaultCaseReducer = reducer\r\n return builder\r\n },\r\n }\r\n builderCallback(builder)\r\n return [actionsMap, actionMatchers, defaultCaseReducer]\r\n}\r\n","import type { Reducer } from 'redux'\r\nimport type {\r\n ActionCreatorWithoutPayload,\r\n PayloadAction,\r\n PayloadActionCreator,\r\n PrepareAction,\r\n _ActionCreatorWithPreparedPayload,\r\n} from './createAction'\r\nimport { createAction } from './createAction'\r\nimport type { CaseReducer, CaseReducers } from './createReducer'\r\nimport { createReducer } from './createReducer'\r\nimport type { ActionReducerMapBuilder } from './mapBuilders'\r\nimport { executeReducerBuilderCallback } from './mapBuilders'\r\nimport type { NoInfer } from './tsHelpers'\r\n\r\n/**\r\n * An action creator attached to a slice.\r\n *\r\n * @deprecated please use PayloadActionCreator directly\r\n *\r\n * @public\r\n */\r\nexport type SliceActionCreator<P> = PayloadActionCreator<P>\r\n\r\n/**\r\n * The return value of `createSlice`\r\n *\r\n * @public\r\n */\r\nexport interface Slice<\r\n State = any,\r\n CaseReducers extends SliceCaseReducers<State> = SliceCaseReducers<State>,\r\n Name extends string = string\r\n> {\r\n /**\r\n * The slice name.\r\n */\r\n name: Name\r\n\r\n /**\r\n * The slice's reducer.\r\n */\r\n reducer: Reducer<State>\r\n\r\n /**\r\n * Action creators for the types of actions that are handled by the slice\r\n * reducer.\r\n */\r\n actions: CaseReducerActions<CaseReducers>\r\n\r\n /**\r\n * The individual case reducer functions that were passed in the `reducers` parameter.\r\n * This enables reuse and testing if they were defined inline when calling `createSlice`.\r\n */\r\n caseReducers: SliceDefinedCaseReducers<CaseReducers>\r\n}\r\n\r\n/**\r\n * Options for `createSlice()`.\r\n *\r\n * @public\r\n */\r\nexport interface CreateSliceOptions<\r\n State = any,\r\n CR extends SliceCaseReducers<State> = SliceCaseReducers<State>,\r\n Name extends string = string\r\n> {\r\n /**\r\n * The slice's name. Used to namespace the generated action types.\r\n */\r\n name: Name\r\n\r\n /**\r\n * The initial state to be returned by the slice reducer.\r\n */\r\n initialState: State\r\n\r\n /**\r\n * A mapping from action types to action-type-specific *case reducer*\r\n * functions. For every action type, a matching action creator will be\r\n * generated using `createAction()`.\r\n */\r\n reducers: ValidateSliceCaseReducers<State, CR>\r\n\r\n /**\r\n * A callback that receives a *builder* object to define\r\n * case reducers via calls to `builder.addCase(actionCreatorOrType, reducer)`.\r\n * \r\n * Alternatively, a mapping from action types to action-type-specific *case reducer*\r\n * functions. These reducers should have existing action types used\r\n * as the keys, and action creators will _not_ be generated.\r\n * \r\n * @example\r\n```ts\r\nimport { createAction, createSlice, Action, AnyAction } from '@reduxjs/toolkit'\r\nconst incrementBy = createAction<number>('incrementBy')\r\nconst decrement = createAction('decrement')\r\n\r\ninterface RejectedAction extends Action {\r\n error: Error\r\n}\r\n\r\nfunction isRejectedAction(action: AnyAction): action is RejectedAction {\r\n return action.type.endsWith('rejected')\r\n}\r\n\r\ncreateSlice({\r\n name: 'counter',\r\n initialState: 0,\r\n reducers: {},\r\n extraReducers: builder => {\r\n builder\r\n .addCase(incrementBy, (state, action) => {\r\n // action is inferred correctly here if using TS\r\n })\r\n // You can chain calls, or have separate `builder.addCase()` lines each time\r\n .addCase(decrement, (state, action) => {})\r\n // You can match a range of action types\r\n .addMatcher(\r\n isRejectedAction,\r\n // `action` will be inferred as a RejectedAction due to isRejectedAction being defined as a type guard\r\n (state, action) => {}\r\n )\r\n // and provide a default case if no other handlers matched\r\n .addDefaultCase((state, action) => {})\r\n }\r\n})\r\n```\r\n */\r\n extraReducers?:\r\n | CaseReducers<NoInfer<State>, any>\r\n | ((builder: ActionReducerMapBuilder<NoInfer<State>>) => void)\r\n}\r\n\r\n/**\r\n * A CaseReducer with a `prepare` method.\r\n *\r\n * @public\r\n */\r\nexport type CaseReducerWithPrepare<State, Action extends PayloadAction> = {\r\n reducer: CaseReducer<State, Action>\r\n prepare: PrepareAction<Action['payload']>\r\n}\r\n\r\n/**\r\n * The type describing a slice's `reducers` option.\r\n *\r\n * @public\r\n */\r\nexport type SliceCaseReducers<State> = {\r\n [K: string]:\r\n | CaseReducer<State, PayloadAction<any>>\r\n | CaseReducerWithPrepare<State, PayloadAction<any, string, any, any>>\r\n}\r\n\r\n/**\r\n * Derives the slice's `actions` property from the `reducers` options\r\n *\r\n * @public\r\n */\r\nexport type CaseReducerActions<CaseReducers extends SliceCaseReducers<any>> = {\r\n [Type in keyof CaseReducers]: CaseReducers[Type] extends { prepare: any }\r\n ? ActionCreatorForCaseReducerWithPrepare<CaseReducers[Type]>\r\n : ActionCreatorForCaseReducer<CaseReducers[Type]>\r\n}\r\n\r\n/**\r\n * Get a `PayloadActionCreator` type for a passed `CaseReducerWithPrepare`\r\n *\r\n * @internal\r\n */\r\ntype ActionCreatorForCaseReducerWithPrepare<CR extends { prepare: any }> =\r\n _ActionCreatorWithPreparedPayload<CR['prepare'], string>\r\n\r\n/**\r\n * Get a `PayloadActionCreator` type for a passed `CaseReducer`\r\n *\r\n * @internal\r\n */\r\ntype ActionCreatorForCaseReducer<CR> = CR extends (\r\n state: any,\r\n action: infer Action\r\n) => any\r\n ? Action extends { payload: infer P }\r\n ? PayloadActionCreator<P>\r\n : ActionCreatorWithoutPayload\r\n : ActionCreatorWithoutPayload\r\n\r\n/**\r\n * Extracts the CaseReducers out of a `reducers` object, even if they are\r\n * tested into a `CaseReducerWithPrepare`.\r\n *\r\n * @internal\r\n */\r\ntype SliceDefinedCaseReducers<CaseReducers extends SliceCaseReducers<any>> = {\r\n [Type in keyof CaseReducers]: CaseReducers[Type] extends {\r\n reducer: infer Reducer\r\n }\r\n ? Reducer\r\n : CaseReducers[Type]\r\n}\r\n\r\n/**\r\n * Used on a SliceCaseReducers object.\r\n * Ensures that if a CaseReducer is a `CaseReducerWithPrepare`, that\r\n * the `reducer` and the `prepare` function use the same type of `payload`.\r\n *\r\n * Might do additional such checks in the future.\r\n *\r\n * This type is only ever useful if you want to write your own wrapper around\r\n * `createSlice`. Please don't use it otherwise!\r\n *\r\n * @public\r\n */\r\nexport type ValidateSliceCaseReducers<\r\n S,\r\n ACR extends SliceCaseReducers<S>\r\n> = ACR &\r\n {\r\n [T in keyof ACR]: ACR[T] extends {\r\n reducer(s: S, action?: infer A): any\r\n }\r\n ? {\r\n prepare(...a: never[]): Omit<A, 'type'>\r\n }\r\n : {}\r\n }\r\n\r\nfunction getType(slice: string, actionKey: string): string {\r\n return `${slice}/${actionKey}`\r\n}\r\n\r\n/**\r\n * A function that accepts an initial state, an object full of reducer\r\n * functions, and a \"slice name\", and automatically generates\r\n * action creators and action types that correspond to the\r\n * reducers and state.\r\n *\r\n * The `reducer` argument is passed to `createReducer()`.\r\n *\r\n * @public\r\n */\r\nexport function createSlice<\r\n State,\r\n CaseReducers extends SliceCaseReducers<State>,\r\n Name extends string = string\r\n>(\r\n options: CreateSliceOptions<State, CaseReducers, Name>\r\n): Slice<State, CaseReducers, Name> {\r\n const { name, initialState } = options\r\n if (!name) {\r\n throw new Error('`name` is a required option for createSlice')\r\n }\r\n const reducers = options.reducers || {}\r\n const [\r\n extraReducers = {},\r\n actionMatchers = [],\r\n defaultCaseReducer = undefined,\r\n ] =\r\n typeof options.extraReducers === 'function'\r\n ? executeReducerBuilderCallback(options.extraReducers)\r\n : [options.extraReducers]\r\n\r\n const reducerNames = Object.keys(reducers)\r\n\r\n const sliceCaseReducersByName: Record<string, CaseReducer> = {}\r\n const sliceCaseReducersByType: Record<string, CaseReducer> = {}\r\n const actionCreators: Record<string, Function> = {}\r\n\r\n reducerNames.forEach((reducerName) => {\r\n const maybeReducerWithPrepare = reducers[reducerName]\r\n const type = getType(name, reducerName)\r\n\r\n let caseReducer: CaseReducer<State, any>\r\n let prepareCallback: PrepareAction<any> | undefined\r\n\r\n if ('reducer' in maybeReducerWithPrepare) {\r\n caseReducer = maybeReducerWithPrepare.reducer\r\n prepareCallback = maybeReducerWithPrepare.prepare\r\n } else {\r\n caseReducer = maybeReducerWithPrepare\r\n }\r\n\r\n sliceCaseReducersByName[reducerName] = caseReducer\r\n sliceCaseReducersByType[type] = caseReducer\r\n actionCreators[reducerName] = prepareCallback\r\n ? createAction(type, prepareCallback)\r\n : createAction(type)\r\n })\r\n\r\n const finalCaseReducers = { ...extraReducers, ...sliceCaseReducersByType }\r\n const reducer = createReducer(\r\n initialState,\r\n finalCaseReducers as any,\r\n actionMatchers,\r\n defaultCaseReducer\r\n )\r\n\r\n return {\r\n name,\r\n reducer,\r\n actions: actionCreators as any,\r\n caseReducers: sliceCaseReducersByName as any,\r\n }\r\n}\r\n","import createNextState, { isDraft } from 'immer'\r\nimport type { EntityState, PreventAny } from './models'\r\nimport type { PayloadAction } from '../createAction'\r\nimport { isFSA } from '../createAction'\r\nimport { IsAny } from '../tsHelpers'\r\n\r\nexport function createSingleArgumentStateOperator<V>(\r\n mutator: (state: EntityState<V>) => void\r\n) {\r\n const operator = createStateOperator((_: undefined, state: EntityState<V>) =>\r\n mutator(state)\r\n )\r\n\r\n return function operation<S extends EntityState<V>>(\r\n state: PreventAny<S, V>\r\n ): S {\r\n return operator(state as S, undefined)\r\n }\r\n}\r\n\r\nexport function createStateOperator<V, R>(\r\n mutator: (arg: R, state: EntityState<V>) => void\r\n) {\r\n return function operation<S extends EntityState<V>>(\r\n state: S,\r\n arg: R | PayloadAction<R>\r\n ): S {\r\n function isPayloadActionArgument(\r\n arg: R | PayloadAction<R>\r\n ): arg is PayloadAction<R> {\r\n return isFSA(arg)\r\n }\r\n\r\n const runMutator = (draft: EntityState<V>) => {\r\n if (isPayloadActionArgument(arg)) {\r\n mutator(arg.payload, draft)\r\n } else {\r\n mutator(arg, draft)\r\n }\r\n }\r\n\r\n if (isDraft(state)) {\r\n // we must already be inside a `createNextState` call, likely because\r\n // this is being wrapped in `createReducer` or `createSlice`.\r\n // It's safe to just pass the draft to the mutator.\r\n runMutator(state)\r\n\r\n // since it's a draft, we'll just return it\r\n return state\r\n } else {\r\n // @ts-ignore createNextState() produces an Immutable<Draft<S>> rather\r\n // than an Immutable<S>, and TypeScript cannot find out how to reconcile\r\n // these two types.\r\n return createNextState(state, runMutator)\r\n }\r\n }\r\n}\r\n","import type { EntityState, IdSelector, Update, EntityId } from './models'\r\n\r\nexport function selectIdValue<T>(entity: T, selectId: IdSelector<T>) {\r\n const key = selectId(entity)\r\n\r\n if (process.env.NODE_ENV !== 'production' && key === undefined) {\r\n console.warn(\r\n 'The entity passed to the `selectId` implementation returned undefined.',\r\n 'You should probably provide your own `selectId` implementation.',\r\n 'The entity that was passed:',\r\n entity,\r\n 'The `selectId` implementation:',\r\n selectId.toString()\r\n )\r\n }\r\n\r\n return key\r\n}\r\n\r\nexport function ensureEntitiesArray<T>(\r\n entities: readonly T[] | Record<EntityId, T>\r\n): readonly T[] {\r\n if (!Array.isArray(entities)) {\r\n entities = Object.values(entities)\r\n }\r\n\r\n return entities\r\n}\r\n\r\nexport function splitAddedUpdatedEntities<T>(\r\n newEntities: readonly T[] | Record<EntityId, T>,\r\n selectId: IdSelector<T>,\r\n state: EntityState<T>\r\n): [T[], Update<T>[]] {\r\n newEntities = ensureEntitiesArray(newEntities)\r\n\r\n const added: T[] = []\r\n const updated: Update<T>[] = []\r\n\r\n for (const entity of newEntities) {\r\n const id = selectIdValue(entity, selectId)\r\n if (id in state.entities) {\r\n updated.push({ id, changes: entity })\r\n } else {\r\n added.push(entity)\r\n }\r\n }\r\n return [added, updated]\r\n}\r\n","import type {\r\n EntityState,\r\n EntityStateAdapter,\r\n IdSelector,\r\n Update,\r\n EntityId,\r\n} from './models'\r\nimport {\r\n createStateOperator,\r\n createSingleArgumentStateOperator,\r\n} from './state_adapter'\r\nimport {\r\n selectIdValue,\r\n ensureEntitiesArray,\r\n splitAddedUpdatedEntities,\r\n} from './utils'\r\n\r\nexport function createUnsortedStateAdapter<T>(\r\n selectId: IdSelector<T>\r\n): EntityStateAdapter<T> {\r\n type R = EntityState<T>\r\n\r\n function addOneMutably(entity: T, state: R): void {\r\n const key = selectIdValue(entity, selectId)\r\n\r\n if (key in state.entities) {\r\n return\r\n }\r\n\r\n state.ids.push(key)\r\n state.entities[key] = entity\r\n }\r\n\r\n function addManyMutably(\r\n newEntities: readonly T[] | Record<EntityId, T>,\r\n state: R\r\n ): void {\r\n newEntities = ensureEntitiesArray(newEntities)\r\n\r\n for (const entity of newEntities) {\r\n addOneMutably(entity, state)\r\n }\r\n }\r\n\r\n function setOneMutably(entity: T, state: R): void {\r\n const key = selectIdValue(entity, selectId)\r\n if (!(key in state.entities)) {\r\n state.ids.push(key)\r\n }\r\n state.entities[key] = entity\r\n }\r\n\r\n function setManyMutably(\r\n newEntities: readonly T[] | Record<EntityId, T>,\r\n state: R\r\n ): void {\r\n newEntities = ensureEntitiesArray(newEntities)\r\n for (const entity of newEntities) {\r\n setOneMutably(entity, state)\r\n }\r\n }\r\n\r\n function setAllMutably(\r\n newEntities: readonly T[] | Record<EntityId, T>,\r\n state: R\r\n ): void {\r\n newEntities = ensureEntitiesArray(newEntities)\r\n\r\n state.ids = []\r\n state.entities = {}\r\n\r\n addManyMutably(newEntities, state)\r\n }\r\n\r\n function removeOneMutably(key: EntityId, state: R): void {\r\n return removeManyMutably([key], state)\r\n }\r\n\r\n function removeManyMutably(keys: readonly EntityId[], state: R): void {\r\n let didMutate = false\r\n\r\n keys.forEach((key) => {\r\n if (key in state.entities) {\r\n delete state.entities[key]\r\n didMutate = true\r\n }\r\n })\r\n\r\n if (didMutate) {\r\n state.ids = state.ids.filter((id) => id in state.entities)\r\n }\r\n }\r\n\r\n function removeAllMutably(state: R): void {\r\n Object.assign(state, {\r\n ids: [],\r\n entities: {},\r\n })\r\n }\r\n\r\n function takeNewKey(\r\n keys: { [id: string]: EntityId },\r\n update: Update<T>,\r\n state: R\r\n ): boolean {\r\n const original = state.entities[update.id]\r\n const updated: T = Object.assign({}, original, update.changes)\r\n const newKey = selectIdValue(updated, selectId)\r\n const hasNewKey = newKey !== update.id\r\n\r\n if (hasNewKey) {\r\n keys[update.id] = newKey\r\n delete state.entities[update.id]\r\n }\r\n\r\n state.entities[newKey] = updated\r\n\r\n return hasNewKey\r\n }\r\n\r\n function updateOneMutably(update: Update<T>, state: R): void {\r\n return updateManyMutably([update], state)\r\n }\r\n\r\n function updateManyMutably(\r\n updates: ReadonlyArray<Update<T>>,\r\n state: R\r\n ): void {\r\n const newKeys: { [id: string]: EntityId } = {}\r\n\r\n const updatesPerEntity: { [id: string]: Update<T> } = {}\r\n\r\n updates.forEach((update) => {\r\n // Only apply updates to entities that currently exist\r\n if (update.id in state.entities) {\r\n // If there are multiple updates to one entity, merge them together\r\n updatesPerEntity[update.id] = {\r\n id: update.id,\r\n // Spreads ignore falsy values, so this works even if there isn't\r\n // an existing update already at this key\r\n changes: {\r\n ...(updatesPerEntity[update.id]\r\n ? updatesPerEntity[update.id].changes\r\n : null),\r\n ...update.changes,\r\n },\r\n }\r\n }\r\n })\r\n\r\n updates = Object.values(updatesPerEntity)\r\n\r\n const didMutateEntities = updates.length > 0\r\n\r\n if (didMutateEntities) {\r\n const didMutateIds =\r\n updates.filter((update) => takeNewKey(newKeys, update, state)).length >\r\n 0\r\n\r\n if (didMutateIds) {\r\n state.ids = state.ids.map((id) => newKeys[id] || id)\r\n }\r\n }\r\n }\r\n\r\n function upsertOneMutably(entity: T, state: R): void {\r\n return upsertManyMutably([entity], state)\r\n }\r\n\r\n function upsertManyMutably(\r\n newEntities: readonly T[] | Record<EntityId, T>,\r\n state: R\r\n ): void {\r\n const [added, updated] = splitAddedUpdatedEntities<T>(\r\n newEntities,\r\n selectId,\r\n state\r\n )\r\n\r\n updateManyMutably(updated, state)\r\n addManyMutably(added, state)\r\n }\r\n\r\n return {\r\n removeAll: createSingleArgumentStateOperator(removeAllMutably),\r\n addOne: createStateOperator(addOneMutably),\r\n addMany: createStateOperator(addManyMutably),\r\n setOne: createStateOperator(setOneMutably),\r\n setMany: createStateOperator(setManyMutably),\r\n setAll: createStateOperator(setAllMutably),\r\n updateOne: createStateOperator(updateOneMutably),\r\n updateMany: createStateOperator(updateManyMutably),\r\n upsertOne: createStateOperator(upsertOneMutably),\r\n upsertMany: createStateOperator(upsertManyMutably),\r\n removeOne: createStateOperator(removeOneMutably),\r\n removeMany: createStateOperator(removeManyMutably),\r\n }\r\n}\r\n","import type {\r\n EntityDefinition,\r\n Comparer,\r\n IdSelector,\r\n EntityAdapter,\r\n} from './models'\r\nimport { createInitialStateFactory } from './entity_state'\r\nimport { createSelectorsFactory } from './state_selectors'\r\nimport { createSortedStateAdapter } from './sorted_state_adapter'\r\nimport { createUnsortedStateAdapter } from './unsorted_state_adapter'\r\n\r\n/**\r\n *\r\n * @param options\r\n *\r\n * @public\r\n */\r\nexport function createEntityAdapter<T>(\r\n options: {\r\n selectId?: IdSelector<T>\r\n sortComparer?: false | Comparer<T>\r\n } = {}\r\n): EntityAdapter<T> {\r\n const { selectId, sortComparer }: EntityDefinition<T> = {\r\n sortComparer: false,\r\n selectId: (instance: any) => instance.id,\r\n ...options,\r\n }\r\n\r\n const stateFactory = createInitialStateFactory<T>()\r\n const selectorsFactory = createSelectorsFactory<T>()\r\n const stateAdapter = sortComparer\r\n ? createSortedStateAdapter(selectId, sortComparer)\r\n : createUnsortedStateAdapter(selectId)\r\n\r\n return {\r\n selectId,\r\n sortComparer,\r\n ...stateFactory,\r\n ...selectorsFactory,\r\n ...stateAdapter,\r\n }\r\n}\r\n","import type { EntityState } from './models'\r\n\r\nexport function getInitialEntityState<V>(): EntityState<V> {\r\n return {\r\n ids: [],\r\n entities: {},\r\n }\r\n}\r\n\r\nexport function createInitialStateFactory<V>() {\r\n function getInitialState(): EntityState<V>\r\n function getInitialState<S extends object>(\r\n additionalState: S\r\n ): EntityState<V> & S\r\n function getInitialState(additionalState: any = {}): any {\r\n return Object.assign(getInitialEntityState(), additionalState)\r\n }\r\n\r\n return { getInitialState }\r\n}\r\n","import { createDraftSafeSelector } from '../createDraftSafeSelector'\r\nimport type {\r\n EntityState,\r\n EntitySelectors,\r\n Dictionary,\r\n EntityId,\r\n} from './models'\r\n\r\nexport function createSelectorsFactory<T>() {\r\n function getSelectors(): EntitySelectors<T, EntityState<T>>\r\n function getSelectors<V>(\r\n selectState: (state: V) => EntityState<T>\r\n ): EntitySelectors<T, V>\r\n function getSelectors(\r\n selectState?: (state: any) => EntityState<T>\r\n ): EntitySelectors<T, any> {\r\n const selectIds = (state: any) => state.ids\r\n\r\n const selectEntities = (state: EntityState<T>) => state.entities\r\n\r\n const selectAll = createDraftSafeSelector(\r\n selectIds,\r\n selectEntities,\r\n (ids: readonly T[], entities: Dictionary<T>): any =>\r\n ids.map((id: any) => (entities as any)[id])\r\n )\r\n\r\n const selectId = (_: any, id: EntityId) => id\r\n\r\n const selectById = (entities: Dictionary<T>, id: EntityId) => entities[id]\r\n\r\n const selectTotal = createDraftSafeSelector(selectIds, (ids) => ids.length)\r\n\r\n if (!selectState) {\r\n return {\r\n selectIds,\r\n selectEntities,\r\n selectAll,\r\n selectTotal,\r\n selectById: createDraftSafeSelector(\r\n selectEntities,\r\n selectId,\r\n selectById\r\n ),\r\n }\r\n }\r\n\r\n const selectGlobalizedEntities = createDraftSafeSelector(\r\n selectState,\r\n selectEntities\r\n )\r\n\r\n return {\r\n selectIds: createDraftSafeSelector(selectState, selectIds),\r\n selectEntities: selectGlobalizedEntities,\r\n selectAll: createDraftSafeSelector(selectState, selectAll),\r\n selectTotal: createDraftSafeSelector(selectState, selectTotal),\r\n selectById: createDraftSafeSelector(\r\n selectGlobalizedEntities,\r\n selectId,\r\n selectById\r\n ),\r\n }\r\n }\r\n\r\n return { getSelectors }\r\n}\r\n","import type {\r\n EntityState,\r\n IdSelector,\r\n Comparer,\r\n EntityStateAdapter,\r\n Update,\r\n EntityId,\r\n} from './models'\r\nimport { createStateOperator } from './state_adapter'\r\nimport { createUnsortedStateAdapter } from './unsorted_state_adapter'\r\nimport {\r\n selectIdValue,\r\n ensureEntitiesArray,\r\n splitAddedUpdatedEntities,\r\n} from './utils'\r\n\r\nexport function createSortedStateAdapter<T>(\r\n selectId: IdSelector<T>,\r\n sort: Comparer<T>\r\n): EntityStateAdapter<T> {\r\n type R = EntityState<T>\r\n\r\n const { removeOne, removeMany, removeAll } =\r\n createUnsortedStateAdapter(selectId)\r\n\r\n function addOneMutably(entity: T, state: R): void {\r\n return addManyMutably([entity], state)\r\n }\r\n\r\n function addManyMutably(\r\n newEntities: readonly T[] | Record<EntityId, T>,\r\n state: R\r\n ): void {\r\n newEntities = ensureEntitiesArray(newEntities)\r\n\r\n const models = newEntities.filter(\r\n (model) => !(selectIdValue(model, selectId) in state.entities)\r\n )\r\n\r\n if (models.length !== 0) {\r\n merge(models, state)\r\n }\r\n }\r\n\r\n function setOneMutably(entity: T, state: R): void {\r\n return setManyMutably([entity], state)\r\n }\r\n\r\n function setManyMutably(\r\n newEntities: readonly T[] | Record<EntityId, T>,\r\n state: R\r\n ): void {\r\n newEntities = ensureEntitiesArray(newEntities)\r\n if (newEntities.length !== 0) {\r\n merge(newEntities, state)\r\n }\r\n }\r\n\r\n function setAllMutably(\r\n newEntities: readonly T[] | Record<EntityId, T>,\r\n state: R\r\n ): void {\r\n newEntities = ensureEntitiesArray(newEntities)\r\n state.entities = {}\r\n state.ids = []\r\n\r\n addManyMutably(newEntities, state)\r\n }\r\n\r\n function updateOneMutably(update: Update<T>, state: R): void {\r\n return updateManyMutably([update], state)\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types\r\n function takeUpdatedModel(models: T[], update: Update<T>, state: R): boolean {\r\n if (!(update.id in state.entities)) {\r\n return false\r\n }\r\n\r\n const original = state.entities[update.id]\r\n const updated = Object.assign({}, original, update.changes)\r\n const newKey = selectIdValue(updated, selectId)\r\n\r\n delete state.entities[update.id]\r\n\r\n models.push(updated)\r\n\r\n return newKey !== update.id\r\n }\r\n\r\n function updateManyMutably(\r\n updates: ReadonlyArray<Update<T>>,\r\n state: R\r\n ): void {\r\n const models: T[] = []\r\n\r\n updates.forEach((update) => takeUpdatedModel(models, update, state))\r\n\r\n if (models.length !== 0) {\r\n merge(models, state)\r\n }\r\n }\r\n\r\n function upsertOneMutably(entity: T, state: R): void {\r\n return upsertManyMutably([entity], state)\r\n }\r\n\r\n function upsertManyMutably(\r\n newEntities: readonly T[] | Record<EntityId, T>,\r\n state: R\r\n ): void {\r\n const [added, updated] = splitAddedUpdatedEntities<T>(\r\n newEntities,\r\n selectId,\r\n state\r\n )\r\n\r\n updateManyMutably(updated, state)\r\n addManyMutably(added, state)\r\n }\r\n\r\n function areArraysEqual(a: readonly unknown[], b: readonly unknown[]) {\r\n if (a.length !== b.length) {\r\n return false\r\n }\r\n\r\n for (let i = 0; i < a.length && i < b.length; i++) {\r\n if (a[i] === b[i]) {\r\n continue\r\n }\r\n return false\r\n }\r\n return true\r\n }\r\n\r\n function merge(models: readonly T[], state: R): void {\r\n // Insert/overwrite all new/updated\r\n models.forEach((model) => {\r\n state.entities[selectId(model)] = model\r\n })\r\n\r\n const allEntities = Object.values(state.entities) as T[]\r\n allEntities.sort(sort)\r\n\r\n const newSortedIds = allEntities.map(selectId)\r\n const { ids } = state\r\n\r\n if (!areArraysEqual(ids, newSortedIds)) {\r\n state.ids = newSortedIds\r\n }\r\n }\r\n\r\n return {\r\n removeOne,\r\n removeMany,\r\n removeAll,\r\n addOne: createStateOperator(addOneMutably),\r\n updateOne: createStateOperator(updateOneMutably),\r\n upsertOne: createStateOperator(upsertOneMutably),\r\n setOne: createStateOperator(setOneMutably),\r\n setMany: createStateOperator(setManyMutably),\r\n setAll: createStateOperator(setAllMutably),\r\n addMany: createStateOperator(addManyMutably),\r\n updateMany: createStateOperator(updateManyMutably),\r\n upsertMany: createStateOperator(upsertManyMutably),\r\n }\r\n}\r\n","// Borrowed from https://github.com/ai/nanoid/blob/3.0.2/non-secure/index.js\r\n// This alphabet uses `A-Za-z0-9_-` symbols. A genetic algorithm helped\r\n// optimize the gzip compression for this alphabet.\r\nlet urlAlphabet =\r\n 'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW'\r\n\r\n/**\r\n *\r\n * @public\r\n */\r\nexport let nanoid = (size = 21) => {\r\n let id = ''\r\n // A compact alternative for `for (var i = 0; i < step; i++)`.\r\n let i = size\r\n while (i--) {\r\n // `| 0` is more compact and faster than `Math.floor()`.\r\n id += urlAlphabet[(Math.random() * 64) | 0]\r\n }\r\n return id\r\n}\r\n","import type { Dispatch, AnyAction } from 'redux'\r\nimport type {\r\n PayloadAction,\r\n ActionCreatorWithPreparedPayload,\r\n} from './createAction'\r\nimport { createAction } from './createAction'\r\nimport type { ThunkDispatch } from 'redux-thunk'\r\nimport type { FallbackIfUnknown, IsAny, IsUnknown } from './tsHelpers'\r\nimport { nanoid } from './nanoid'\r\n\r\n// @ts-ignore we need the import of these types due to a bundling issue.\r\ntype _Keep = PayloadAction | ActionCreatorWithPreparedPayload<any, unknown>\r\n\r\nexport type BaseThunkAPI<\r\n S,\r\n E,\r\n D extends Dispatch = Dispatch,\r\n RejectedValue = undefined,\r\n RejectedMeta = unknown,\r\n FulfilledMeta = unknown\r\n> = {\r\n dispatch: D\r\n getState: () => S\r\n extra: E\r\n requestId: string\r\n signal: AbortSignal\r\n rejectWithValue: IsUnknown<\r\n RejectedMeta,\r\n (value: RejectedValue) => RejectWithValue<RejectedValue, RejectedMeta>,\r\n (\r\n value: RejectedValue,\r\n meta: RejectedMeta\r\n ) => RejectWithValue<RejectedValue, RejectedMeta>\r\n >\r\n fulfillWithValue: IsUnknown<\r\n FulfilledMeta,\r\n <FulfilledValue>(\r\n value: FulfilledValue\r\n ) => FulfillWithMeta<FulfilledValue, FulfilledMeta>,\r\n <FulfilledValue>(\r\n value: FulfilledValue,\r\n meta: FulfilledMeta\r\n ) => FulfillWithMeta<FulfilledValue, FulfilledMeta>\r\n >\r\n}\r\n\r\n/**\r\n * @public\r\n */\r\nexport interface SerializedError {\r\n name?: string\r\n message?: string\r\n stack?: string\r\n code?: string\r\n}\r\n\r\nconst commonProperties: Array<keyof SerializedError> = [\r\n 'name',\r\n 'message',\r\n 'stack',\r\n 'code',\r\n]\r\n\r\nclass RejectWithValue<Payload, RejectedMeta> {\r\n /*\r\n type-only property to distinguish between RejectWithValue and FulfillWithMeta\r\n does not exist at runtime\r\n */\r\n private readonly _type!: 'RejectWithValue'\r\n constructor(\r\n public readonly payload: Payload,\r\n public readonly meta: RejectedMeta\r\n ) {}\r\n}\r\n\r\nclass FulfillWithMeta<Payload, FulfilledMeta> {\r\n /*\r\n type-only property to distinguish between RejectWithValue and FulfillWithMeta\r\n does not exist at runtime\r\n */\r\n private readonly _type!: 'FulfillWithMeta'\r\n constructor(\r\n public readonly payload: Payload,\r\n public readonly meta: FulfilledMeta\r\n ) {}\r\n}\r\n\r\n/**\r\n * Serializes an error into a plain object.\r\n * Reworked from https://github.com/sindresorhus/serialize-error\r\n *\r\n * @public\r\n */\r\nexport const miniSerializeError = (value: any): SerializedError => {\r\n if (typeof value === 'object' && value !== null) {\r\n const simpleError: SerializedError = {}\r\n for (const property of commonProperties) {\r\n if (typeof value[property] === 'string') {\r\n simpleError[property] = value[property]\r\n }\r\n }\r\n\r\n return simpleError\r\n }\r\n\r\n return { message: String(value) }\r\n}\r\n\r\ntype AsyncThunkConfig = {\r\n state?: unknown\r\n dispatch?: Dispatch\r\n extra?: unknown\r\n rejectValue?: unknown\r\n serializedErrorType?: unknown\r\n pendingMeta?: unknown\r\n fulfilledMeta?: unknown\r\n rejectedMeta?: unknown\r\n}\r\n\r\ntype GetState<ThunkApiConfig> = ThunkApiConfig extends {\r\n state: infer State\r\n}\r\n ? State\r\n : unknown\r\ntype GetExtra<ThunkApiConfig> = ThunkApiConfig extends { extra: infer Extra }\r\n ? Extra\r\n : unknown\r\ntype GetDispatch<ThunkApiConfig> = ThunkApiConfig extends {\r\n dispatch: infer Dispatch\r\n}\r\n ? FallbackIfUnknown<\r\n Dispatch,\r\n ThunkDispatch<\r\n GetState<ThunkApiConfig>,\r\n GetExtra<ThunkApiConfig>,\r\n AnyAction\r\n >\r\n >\r\n : ThunkDispatch<GetState<ThunkApiConfig>, GetExtra<ThunkApiConfig>, AnyAction>\r\n\r\ntype GetThunkAPI<ThunkApiConfig> = BaseThunkAPI<\r\n GetState<ThunkApiConfig>,\r\n GetExtra<ThunkApiConfig>,\r\n GetDispatch<ThunkApiConfig>,\r\n GetRejectValue<ThunkApiConfig>,\r\n GetRejectedMeta<ThunkApiConfig>,\r\n GetFulfilledMeta<ThunkApiConfig>\r\n>\r\n\r\ntype GetRejectValue<ThunkApiConfig> = ThunkApiConfig extends {\r\n rejectValue: infer RejectValue\r\n}\r\n ? RejectValue\r\n : unknown\r\n\r\ntype GetPendingMeta<ThunkApiConfig> = ThunkApiConfig extends {\r\n pendingMeta: infer PendingMeta\r\n}\r\n ? PendingMeta\r\n : unknown\r\n\r\ntype GetFulfilledMeta<ThunkApiConfig> = ThunkApiConfig extends {\r\n fulfilledMeta: infer FulfilledMeta\r\n}\r\n ? FulfilledMeta\r\n : unknown\r\n\r\ntype GetRejectedMeta<ThunkApiConfig> = ThunkApiConfig extends {\r\n rejectedMeta: infer RejectedMeta\r\n}\r\n ? RejectedMeta\r\n : unknown\r\n\r\ntype GetSerializedErrorType<ThunkApiConfig> = ThunkApiConfig extends {\r\n serializedErrorType: infer GetSerializedErrorType\r\n}\r\n ? GetSerializedErrorType\r\n : SerializedError\r\n\r\ntype MaybePromise<T> = T | Promise<T> | (T extends any ? Promise<T> : never)\r\n\r\n/**\r\n * A type describing the return value of the `payloadCreator` argument to `createAsyncThunk`.\r\n * Might be useful for wrapping `createAsyncThunk` in custom abstractions.\r\n *\r\n * @public\r\n */\r\nexport type AsyncThunkPayloadCreatorReturnValue<\r\n Returned,\r\n ThunkApiConfig extends AsyncThunkConfig\r\n> = MaybePromise<\r\n | IsUnknown<\r\n GetFulfilledMeta<ThunkApiConfig>,\r\n Returned,\r\n FulfillWithMeta<Returned, GetFulfilledMeta<ThunkApiConfig>>\r\n >\r\n | RejectWithValue<\r\n GetRejectValue<ThunkApiConfig>,\r\n GetRejectedMeta<ThunkApiConfig>\r\n >\r\n>\r\n/**\r\n * A type describing the `payloadCreator` argument to `createAsyncThunk`.\r\n * Might be useful for wrapping `createAsyncThunk` in custom abstractions.\r\n *\r\n * @public\r\n */\r\nexport type AsyncThunkPayloadCreator<\r\n Returned,\r\n ThunkArg = void,\r\n ThunkApiConfig extends AsyncThunkConfig = {}\r\n> = (\r\n arg: ThunkArg,\r\n thunkAPI: GetThunkAPI<ThunkApiConfig>\r\n) => AsyncThunkPayloadCreatorReturnValue<Returned, ThunkApiConfig>\r\n\r\n/**\r\n * A ThunkAction created by `createAsyncThunk`.\r\n * Dispatching it returns a Promise for either a\r\n * fulfilled or rejected action.\r\n * Also, the returned value contains an `abort()` method\r\n * that allows the asyncAction to be cancelled from the outside.\r\n *\r\n * @public\r\n */\r\nexport type AsyncThunkAction<\r\n Returned,\r\n ThunkArg,\r\n ThunkApiConfig extends AsyncThunkConfig\r\n> = (\r\n dispatch: GetDispatch<ThunkApiConfig>,\r\n getState: () => GetState<ThunkApiConfig>,\r\n extra: GetExtra<ThunkApiConfig>\r\n) => Promise<\r\n | ReturnType<AsyncThunkFulfilledActionCreator<Returned, ThunkArg>>\r\n | ReturnType<AsyncThunkRejectedActionCreator<ThunkArg, ThunkApiConfig>>\r\n> & {\r\n abort: (reason?: string) => void\r\n requestId: string\r\n arg: ThunkArg\r\n unwrap: () => Promise<Returned>\r\n}\r\n\r\ntype AsyncThunkActionCreator<\r\n Returned,\r\n ThunkArg,\r\n ThunkApiConfig extends AsyncThunkConfig\r\n> = IsAny<\r\n ThunkArg,\r\n // any handling\r\n (arg: ThunkArg) => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig>,\r\n // unknown handling\r\n unknown extends ThunkArg\r\n ? (arg: ThunkArg) => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig> // argument not specified or specified as void or undefined\r\n : [ThunkArg] extends [void] | [undefined]\r\n ? () => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig> // argument contains void\r\n : [void] extends [ThunkArg] // make optional\r\n ? (arg?: ThunkArg) => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig> // argument contains undefined\r\n : [undefined] extends [ThunkArg]\r\n ? WithStrictNullChecks<\r\n // with strict nullChecks: make optional\r\n (\r\n arg?: ThunkArg\r\n ) => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig>,\r\n // without strict null checks this will match everything, so don't make it optional\r\n (arg: ThunkArg) => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig>\r\n > // default case: normal argument\r\n : (arg: ThunkArg) => AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig>\r\n>\r\n\r\n/**\r\n * Options object for `createAsyncThunk`.\r\n *\r\n * @public\r\n */\r\nexport type AsyncThunkOptions<\r\n ThunkArg = void,\r\n ThunkApiConfig extends AsyncThunkConfig = {}\r\n> = {\r\n /**\r\n * A method to control whether the asyncThunk should be executed. Has access to the\r\n * `arg`, `api.getState()` and `api.extra` arguments.\r\n *\r\n * @returns `false` if it should be skipped\r\n */\r\n condition?(\r\n arg: ThunkArg,\r\n api: Pick<GetThunkAPI<ThunkApiConfig>, 'getState' | 'extra'>\r\n ): boolean | undefined\r\n /**\r\n * If `condition` returns `false`, the asyncThunk will be skipped.\r\n * This option allows you to control whether a `rejected` action with `meta.condition == false`\r\n * will be dispatched or not.\r\n *\r\n * @default `false`\r\n */\r\n dispatchConditionRejection?: boolean\r\n\r\n serializeError?: (x: unknown) => GetSerializedErrorType<ThunkApiConfig>\r\n\r\n /**\r\n * A function to use when generating the `requestId` for the request sequence.\r\n *\r\n * @default `nanoid`\r\n */\r\n idGenerator?: () => string\r\n} & IsUnknown<\r\n GetPendingMeta<ThunkApiConfig>,\r\n {\r\n /**\r\n * A method to generate additional properties to be added to `meta` of the pending action.\r\n *\r\n * Using this optional overload will not modify the types correctly, this overload is only in place to support JavaScript users.\r\n * Please use the `ThunkApiConfig` parameter `pendingMeta` to get access to a correctly typed overload\r\n */\r\n getPendingMeta?(\r\n base: {\r\n arg: ThunkArg\r\n requestId: string\r\n },\r\n api: Pick<GetThunkAPI<ThunkApiConfig>, 'getState' | 'extra'>\r\n ): GetPendingMeta<ThunkApiConfig>\r\n },\r\n {\r\n /**\r\n * A method to generate additional properties to be added to `meta` of the pending action.\r\n */\r\n getPendingMeta(\r\n base: {\r\n arg: ThunkArg\r\n requestId: string\r\n },\r\n api: Pick<GetThunkAPI<ThunkApiConfig>, 'getState' | 'extra'>\r\n ): GetPendingMeta<ThunkApiConfig>\r\n }\r\n>\r\n\r\nexport type AsyncThunkPendingActionCreator<\r\n ThunkArg,\r\n ThunkApiConfig = {}\r\n> = ActionCreatorWithPreparedPayload<\r\n [string, ThunkArg, GetPendingMeta<ThunkApiConfig>?],\r\n undefined,\r\n string,\r\n never,\r\n {\r\n arg: ThunkArg\r\n requestId: string\r\n requestStatus: 'pending'\r\n } & GetPendingMeta<ThunkApiConfig>\r\n>\r\n\r\nexport type AsyncThunkRejectedActionCreator<\r\n ThunkArg,\r\n ThunkApiConfig = {}\r\n> = ActionCreatorWithPreparedPayload<\r\n [\r\n Error | null,\r\n string,\r\n ThunkArg,\r\n GetRejectValue<ThunkApiConfig>?,\r\n GetRejectedMeta<ThunkApiConfig>?\r\n ],\r\n GetRejectValue<ThunkApiConfig> | undefined,\r\n string,\r\n GetSerializedErrorType<ThunkApiConfig>,\r\n {\r\n arg: ThunkArg\r\n requestId: string\r\n requestStatus: 'rejected'\r\n aborted: boolean\r\n condition: boolean\r\n } & (\r\n | ({ rejectedWithValue: false } & {\r\n [K in keyof GetRejectedMeta<ThunkApiConfig>]?: undefined\r\n })\r\n | ({ rejectedWithValue: true } & GetRejectedMeta<ThunkApiConfig>)\r\n )\r\n>\r\n\r\nexport type AsyncThunkFulfilledActionCreator<\r\n Returned,\r\n ThunkArg,\r\n ThunkApiConfig = {}\r\n> = ActionCreatorWithPreparedPayload<\r\n [Returned, string, ThunkArg, GetFulfilledMeta<ThunkApiConfig>?],\r\n Returned,\r\n string,\r\n never,\r\n {\r\n arg: ThunkArg\r\n requestId: string\r\n requestStatus: 'fulfilled'\r\n } & GetFulfilledMeta<ThunkApiConfig>\r\n>\r\n\r\n/**\r\n * A type describing the return value of `createAsyncThunk`.\r\n * Might be useful for wrapping `createAsyncThunk` in custom abstractions.\r\n *\r\n * @public\r\n */\r\nexport type AsyncThunk<\r\n Returned,\r\n ThunkArg,\r\n ThunkApiConfig extends AsyncThunkConfig\r\n> = AsyncThunkActionCreator<Returned, ThunkArg, ThunkApiConfig> & {\r\n pending: AsyncThunkPendingActionCreator<ThunkArg, ThunkApiConfig>\r\n rejected: AsyncThunkRejectedActionCreator<ThunkArg, ThunkApiConfig>\r\n fulfilled: AsyncThunkFulfilledActionCreator<\r\n Returned,\r\n ThunkArg,\r\n ThunkApiConfig\r\n >\r\n typePrefix: string\r\n}\r\n\r\n/**\r\n *\r\n * @param typePrefix\r\n * @param payloadCreator\r\n * @param options\r\n *\r\n * @public\r\n */\r\nexport function createAsyncThunk<\r\n Returned,\r\n ThunkArg = void,\r\n ThunkApiConfig extends AsyncThunkConfig = {}\r\n>(\r\n typePrefix: string,\r\n payloadCreator: AsyncThunkPayloadCreator<Returned, ThunkArg, ThunkApiConfig>,\r\n options?: AsyncThunkOptions<ThunkArg, ThunkApiConfig>\r\n): AsyncThunk<Returned, ThunkArg, ThunkApiConfig> {\r\n type RejectedValue = GetRejectValue<ThunkApiConfig>\r\n type PendingMeta = GetPendingMeta<ThunkApiConfig>\r\n type FulfilledMeta = GetFulfilledMeta<ThunkApiConfig>\r\n type RejectedMeta = GetRejectedMeta<ThunkApiConfig>\r\n\r\n const fulfilled: AsyncThunkFulfilledActionCreator<\r\n Returned,\r\n ThunkArg,\r\n ThunkApiConfig\r\n > = createAction(\r\n typePrefix + '/fulfilled',\r\n (\r\n payload: Returned,\r\n requestId: string,\r\n arg: ThunkArg,\r\n meta?: FulfilledMeta\r\n ) => ({\r\n payload,\r\n meta: {\r\n ...((meta as any) || {}),\r\n arg,\r\n requestId,\r\n requestStatus: 'fulfilled' as const,\r\n },\r\n })\r\n )\r\n\r\n const pending: AsyncThunkPendingActionCreator<ThunkArg, ThunkApiConfig> =\r\n createAction(\r\n typePrefix + '/pending',\r\n (requestId: string, arg: ThunkArg, meta?: PendingMeta) => ({\r\n payload: undefined,\r\n meta: {\r\n ...((meta as any) || {}),\r\n arg,\r\n requestId,\r\n requestStatus: 'pending' as const,\r\n },\r\n })\r\n )\r\n\r\n const rejected: AsyncThunkRejectedActionCreator<ThunkArg, ThunkApiConfig> =\r\n createAction(\r\n typePrefix + '/rejected',\r\n (\r\n error: Error | null,\r\n requestId: string,\r\n arg: ThunkArg,\r\n payload?: RejectedValue,\r\n meta?: RejectedMeta\r\n ) => ({\r\n payload,\r\n error: ((options && options.serializeError) || miniSerializeError)(\r\n error || 'Rejected'\r\n ) as GetSerializedErrorType<ThunkApiConfig>,\r\n meta: {\r\n ...((meta as any) || {}),\r\n arg,\r\n requestId,\r\n rejectedWithValue: !!payload,\r\n requestStatus: 'rejected' as const,\r\n aborted: error?.name === 'AbortError',\r\n condition: error?.name === 'ConditionError',\r\n },\r\n })\r\n )\r\n\r\n let displayedWarning = false\r\n\r\n const AC =\r\n typeof AbortController !== 'undefined'\r\n ? AbortController\r\n : class implements AbortController {\r\n signal: AbortSignal = {\r\n aborted: false,\r\n addEventListener() {},\r\n dispatchEvent() {\r\n return false\r\n },\r\n onabort() {},\r\n removeEventListener() {},\r\n }\r\n abort() {\r\n if (process.env.NODE_ENV !== 'production') {\r\n if (!displayedWarning) {\r\n displayedWarning = true\r\n console.info(\r\n `This platform does not implement AbortController. \r\nIf you want to use the AbortController to react to \\`abort\\` events, please consider importing a polyfill like 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'.`\r\n )\r\n }\r\n }\r\n }\r\n }\r\n\r\n function actionCreator(\r\n arg: ThunkArg\r\n ): AsyncThunkAction<Returned, ThunkArg, ThunkApiConfig> {\r\n return (dispatch, getState, extra) => {\r\n const requestId = (options?.idGenerator ?? nanoid)()\r\n\r\n const abortController = new AC()\r\n let abortReason: string | undefined\r\n\r\n const abortedPromise = new Promise<never>((_, reject) =>\r\n abortController.signal.addEventListener('abort', () =>\r\n reject({ name: 'AbortError', message: abortReason || 'Aborted' })\r\n )\r\n )\r\n\r\n let started = false\r\n function abort(reason?: string) {\r\n if (started) {\r\n abortReason = reason\r\n abortController.abort()\r\n }\r\n }\r\n\r\n const promise = (async function () {\r\n let finalAction: ReturnType<typeof fulfilled | typeof rejected>\r\n try {\r\n if (\r\n options &&\r\n options.condition &&\r\n options.condition(arg, { getState, extra }) === false\r\n ) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw {\r\n name: 'ConditionError',\r\n message: 'Aborted due to condition callback returning false.',\r\n }\r\n }\r\n started = true\r\n dispatch(\r\n pending(\r\n requestId,\r\n arg,\r\n options?.getPendingMeta?.({ requestId, arg }, { getState, extra })\r\n )\r\n )\r\n finalAction = await Promise.race([\r\n abortedPromise,\r\n Promise.resolve(\r\n payloadCreator(arg, {\r\n dispatch,\r\n getState,\r\n extra,\r\n requestId,\r\n signal: abortController.signal,\r\n rejectWithValue: ((\r\n value: RejectedValue,\r\n meta?: RejectedMeta\r\n ) => {\r\n return new RejectWithValue(value, meta)\r\n }) as any,\r\n fulfillWithValue: ((value: unknown, meta?: FulfilledMeta) => {\r\n return new FulfillWithMeta(value, meta)\r\n }) as any,\r\n })\r\n ).then((result) => {\r\n if (result instanceof RejectWithValue) {\r\n throw result\r\n }\r\n if (result instanceof FulfillWithMeta) {\r\n return fulfilled(result.payload, requestId, arg, result.meta)\r\n }\r\n return fulfilled(result as any, requestId, arg)\r\n }),\r\n ])\r\n } catch (err) {\r\n finalAction =\r\n err instanceof RejectWithValue\r\n ? rejected(null, requestId, arg, err.payload, err.meta)\r\n : rejected(err as any, requestId, arg)\r\n }\r\n // We dispatch the result action _after_ the catch, to avoid having any errors\r\n // here get swallowed by the try/catch block,\r\n // per https://twitter.com/dan_abramov/status/770914221638942720\r\n // and https://github.com/reduxjs/redux-toolkit/blob/e85eb17b39a2118d859f7b7746e0f3fee523e089/docs/tutorials/advanced-tutorial.md#async-error-handling-logic-in-thunks\r\n\r\n const skipDispatch =\r\n options &&\r\n !options.dispatchConditionRejection &&\r\n rejected.match(finalAction) &&\r\n (finalAction as any).meta.condition\r\n\r\n if (!skipDispatch) {\r\n dispatch(finalAction)\r\n }\r\n return finalAction\r\n })()\r\n return Object.assign(promise as Promise<any>, {\r\n abort,\r\n requestId,\r\n arg,\r\n unwrap() {\r\n return promise.then<any>(unwrapResult)\r\n },\r\n })\r\n }\r\n }\r\n\r\n return Object.assign(\r\n actionCreator as AsyncThunkActionCreator<\r\n Returned,\r\n ThunkArg,\r\n ThunkApiConfig\r\n >,\r\n {\r\n pending,\r\n rejected,\r\n fulfilled,\r\n typePrefix,\r\n }\r\n )\r\n}\r\n\r\ninterface UnwrappableAction {\r\n payload: any\r\n meta?: any\r\n error?: any\r\n}\r\n\r\ntype UnwrappedActionPayload<T extends UnwrappableAction> = Exclude<\r\n T,\r\n { error: any }\r\n>['payload']\r\n\r\n/**\r\n * @public\r\n */\r\nexport function unwrapResult<R extends UnwrappableAction>(\r\n action: R\r\n): UnwrappedActionPayload<R> {\r\n if (action.meta && action.meta.rejectedWithValue) {\r\n throw action.payload\r\n }\r\n if (action.error) {\r\n throw action.error\r\n }\r\n return action.payload\r\n}\r\n\r\ntype WithStrictNullChecks<True, False> = undefined extends boolean\r\n ? False\r\n : True\r\n","import type { Middleware } from 'redux'\r\n\r\n/**\r\n * return True if T is `any`, otherwise return False\r\n * taken from https://github.com/joonhocho/tsdef\r\n *\r\n * @internal\r\n */\r\nexport type IsAny<T, True, False = never> =\r\n // test if we are going the left AND right path in the condition\r\n true | false extends (T extends never ? true : false) ? True : False\r\n\r\n/**\r\n * return True if T is `unknown`, otherwise return False\r\n * taken from https://github.com/joonhocho/tsdef\r\n *\r\n * @internal\r\n */\r\nexport type IsUnknown<T, True, False = never> = unknown extends T\r\n ? IsAny<T, False, True>\r\n : False\r\n\r\nexport type FallbackIfUnknown<T, Fallback> = IsUnknown<T, Fallback, T>\r\n\r\n/**\r\n * @internal\r\n */\r\nexport type IfMaybeUndefined<P, True, False> = [undefined] extends [P]\r\n ? True\r\n : False\r\n\r\n/**\r\n * @internal\r\n */\r\nexport type IfVoid<P, True, False> = [void] extends [P] ? True : False\r\n\r\n/**\r\n * @internal\r\n */\r\nexport type IsEmptyObj<T, True, False = never> = T extends any\r\n ? keyof T extends never\r\n ? IsUnknown<T, False, IfMaybeUndefined<T, False, IfVoid<T, False, True>>>\r\n : False\r\n : never\r\n\r\n/**\r\n * returns True if TS version is above 3.5, False if below.\r\n * uses feature detection to detect TS version >= 3.5\r\n * * versions below 3.5 will return `{}` for unresolvable interference\r\n * * versions above will return `unknown`\r\n *\r\n * @internal\r\n */\r\nexport type AtLeastTS35<True, False> = [True, False][IsUnknown<\r\n ReturnType<<T>() => T>,\r\n 0,\r\n 1\r\n>]\r\n\r\n/**\r\n * @internal\r\n */\r\nexport type IsUnknownOrNonInferrable<T, True, False> = AtLeastTS35<\r\n IsUnknown<T, True, False>,\r\n IsEmptyObj<T, True, IsUnknown<T, True, False>>\r\n>\r\n\r\n/**\r\n * Combines all dispatch signatures of all middlewares in the array `M` into\r\n * one intersected dispatch signature.\r\n */\r\nexport type DispatchForMiddlewares<M> = M extends ReadonlyArray<any>\r\n ? UnionToIntersection<\r\n M[number] extends infer MiddlewareValues\r\n ? MiddlewareValues extends Middleware<infer DispatchExt, any, any>\r\n ? DispatchExt extends Function\r\n ? IsAny<DispatchExt, never, DispatchExt>\r\n : never\r\n : never\r\n : never\r\n >\r\n : never\r\n\r\n/**\r\n * Convert a Union type `(A|B)` to an intersection type `(A&B)`\r\n */\r\nexport type UnionToIntersection<U> = (\r\n U extends any ? (k: U) => void : never\r\n) extends (k: infer I) => void\r\n ? I\r\n : never\r\n\r\n/**\r\n * Helper type. Passes T out again, but boxes it in a way that it cannot\r\n * \"widen\" the type by accident if it is a generic that should be inferred\r\n * from elsewhere.\r\n *\r\n * @internal\r\n */\r\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\r\n\r\nexport type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>\r\n\r\nexport interface HasMatchFunction<T> {\r\n match: (v: any) => v is T\r\n}\r\n\r\nexport const hasMatchFunction = <T>(\r\n v: Matcher<T>\r\n): v is HasMatchFunction<T> => {\r\n return v && typeof (v as HasMatchFunction<T>).match === 'function'\r\n}\r\n\r\n/** @public */\r\nexport type Matcher<T> = HasMatchFunction<T> | ((v: any) => v is T)\r\n\r\n/** @public */\r\nexport type ActionFromMatcher<M extends Matcher<any>> = M extends Matcher<\r\n infer T\r\n>\r\n ? T\r\n : never\r\n","import type {\r\n ActionFromMatcher,\r\n Matcher,\r\n UnionToIntersection,\r\n} from './tsHelpers'\r\nimport { hasMatchFunction } from './tsHelpers'\r\nimport type {\r\n AsyncThunk,\r\n AsyncThunkFulfilledActionCreator,\r\n AsyncThunkPendingActionCreator,\r\n AsyncThunkRejectedActionCreator,\r\n} from './createAsyncThunk'\r\n\r\n/** @public */\r\nexport type ActionMatchingAnyOf<\r\n Matchers extends [Matcher<any>, ...Matcher<any>[]]\r\n> = ActionFromMatcher<Matchers[number]>\r\n\r\n/** @public */\r\nexport type ActionMatchingAllOf<\r\n Matchers extends [Matcher<any>, ...Matcher<any>[]]\r\n> = UnionToIntersection<ActionMatchingAnyOf<Matchers>>\r\n\r\nconst matches = (matcher: Matcher<any>, action: any) => {\r\n if (hasMatchFunction(matcher)) {\r\n return matcher.match(action)\r\n } else {\r\n return matcher(action)\r\n }\r\n}\r\n\r\n/**\r\n * A higher-order function that returns a function that may be used to check\r\n * whether an action matches any one of the supplied type guards or action\r\n * creators.\r\n *\r\n * @param matchers The type guards or action creators to match against.\r\n *\r\n * @public\r\n */\r\nexport function isAnyOf<Matchers extends [Matcher<any>, ...Matcher<any>[]]>(\r\n ...matchers: Matchers\r\n) {\r\n return (action: any): action is ActionMatchingAnyOf<Matchers> => {\r\n return matchers.some((matcher) => matches(matcher, action))\r\n }\r\n}\r\n\r\n/**\r\n * A higher-order function that returns a function that may be used to check\r\n * whether an action matches all of the supplied type guards or action\r\n * creators.\r\n *\r\n * @param matchers The type guards or action creators to match against.\r\n *\r\n * @public\r\n */\r\nexport function isAllOf<Matchers extends [Matcher<any>, ...Matcher<any>[]]>(\r\n ...matchers: Matchers\r\n) {\r\n return (action: any): action is ActionMatchingAllOf<Matchers> => {\r\n return matchers.every((matcher) => matches(matcher, action))\r\n }\r\n}\r\n\r\n/**\r\n * @param action A redux action\r\n * @param validStatus An array of valid meta.requestStatus values\r\n *\r\n * @internal\r\n */\r\nexport function hasExpectedRequestMetadata(\r\n action: any,\r\n validStatus: readonly string[]\r\n) {\r\n if (!action || !action.meta) return false\r\n\r\n const hasValidRequestId = typeof action.meta.requestId === 'string'\r\n const hasValidRequestStatus =\r\n validStatus.indexOf(action.meta.requestStatus) > -1\r\n\r\n return hasValidRequestId && hasValidRequestStatus\r\n}\r\n\r\nfunction isAsyncThunkArray(a: [any] | AnyAsyncThunk[]): a is AnyAsyncThunk[] {\r\n return (\r\n typeof a[0] === 'function' &&\r\n 'pending' in a[0] &&\r\n 'fulfilled' in a[0] &&\r\n 'rejected' in a[0]\r\n )\r\n}\r\n\r\nexport type UnknownAsyncThunkPendingAction = ReturnType<\r\n AsyncThunkPendingActionCreator<unknown>\r\n>\r\n\r\nexport type PendingActionFromAsyncThunk<T extends AnyAsyncThunk> =\r\n ActionFromMatcher<T['pending']>\r\n\r\n/**\r\n * A higher-order function that returns a function that may be used to check\r\n * whether an action was created by an async thunk action creator, and that\r\n * the action is pending.\r\n *\r\n * @public\r\n */\r\nexport function isPending(): (\r\n action: any\r\n) => action is UnknownAsyncThunkPendingAction\r\n/**\r\n * A higher-order function that returns a function that may be used to check\r\n * whether an action belongs to one of the provided async thunk action creators,\r\n * and that the action is pending.\r\n *\r\n * @param asyncThunks (optional) The async thunk action creators to match against.\r\n *\r\n * @public\r\n */\r\nexport function isPending<\r\n AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]\r\n>(\r\n ...asyncThunks: AsyncThunks\r\n): (action: any) => action is PendingActionFromAsyncThunk<AsyncThunks[number]>\r\n/**\r\n * Tests if `action` is a pending thunk action\r\n * @public\r\n */\r\nexport function isPending(action: any): action is UnknownAsyncThunkPendingAction\r\nexport function isPending<\r\n AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]\r\n>(...asyncThunks: AsyncThunks | [any]) {\r\n if (asyncThunks.length === 0) {\r\n return (action: any) => hasExpectedRequestMetadata(action, ['pending'])\r\n }\r\n\r\n if (!isAsyncThunkArray(asyncThunks)) {\r\n return isPending()(asyncThunks[0])\r\n }\r\n\r\n return (\r\n action: any\r\n ): action is PendingActionFromAsyncThunk<AsyncThunks[number]> => {\r\n // note: this type will be correct because we have at least 1 asyncThunk\r\n const matchers: [Matcher<any>, ...Matcher<any>[]] = asyncThunks.map(\r\n (asyncThunk) => asyncThunk.pending\r\n ) as any\r\n\r\n const combinedMatcher = isAnyOf(...matchers)\r\n\r\n return combinedMatcher(action)\r\n }\r\n}\r\n\r\nexport type UnknownAsyncThunkRejectedAction = ReturnType<\r\n AsyncThunkRejectedActionCreator<unknown, unknown>\r\n>\r\n\r\nexport type RejectedActionFromAsyncThunk<T extends AnyAsyncThunk> =\r\n ActionFromMatcher<T['rejected']>\r\n\r\n/**\r\n * A higher-order function that returns a function that may be used to check\r\n * whether an action was created by an async thunk action creator, and that\r\n * the action is rejected.\r\n *\r\n * @public\r\n */\r\nexport function isRejected(): (\r\n action: any\r\n) => action is UnknownAsyncThunkRejectedAction\r\n/**\r\n * A higher-order function that returns a function that may be used to check\r\n * whether an action belongs to one of the provided async thunk action creators,\r\n * and that the action is rejected.\r\n *\r\n * @param asyncThunks (optional) The async thunk action creators to match against.\r\n *\r\n * @public\r\n */\r\nexport function isRejected<\r\n AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]\r\n>(\r\n ...asyncThunks: AsyncThunks\r\n): (action: any) => action is RejectedActionFromAsyncThunk<AsyncThunks[number]>\r\n/**\r\n * Tests if `action` is a rejected thunk action\r\n * @public\r\n */\r\nexport function isRejected(\r\n action: any\r\n): action is UnknownAsyncThunkRejectedAction\r\nexport function isRejected<\r\n AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]\r\n>(...asyncThunks: AsyncThunks | [any]) {\r\n if (asyncThunks.length === 0) {\r\n return (action: any) => hasExpectedRequestMetadata(action, ['rejected'])\r\n }\r\n\r\n if (!isAsyncThunkArray(asyncThunks)) {\r\n return isRejected()(asyncThunks[0])\r\n }\r\n\r\n return (\r\n action: any\r\n ): action is RejectedActionFromAsyncThunk<AsyncThunks[number]> => {\r\n // note: this type will be correct because we have at least 1 asyncThunk\r\n const matchers: [Matcher<any>, ...Matcher<any>[]] = asyncThunks.map(\r\n (asyncThunk) => asyncThunk.rejected\r\n ) as any\r\n\r\n const combinedMatcher = isAnyOf(...matchers)\r\n\r\n return combinedMatcher(action)\r\n }\r\n}\r\n\r\nexport type UnknownAsyncThunkRejectedWithValueAction = ReturnType<\r\n AsyncThunkRejectedActionCreator<unknown, unknown>\r\n>\r\n\r\nexport type RejectedWithValueActionFromAsyncThunk<T extends AnyAsyncThunk> =\r\n ActionFromMatcher<T['rejected']> &\r\n (T extends AsyncThunk<any, any, { rejectValue: infer RejectedValue }>\r\n ? { payload: RejectedValue }\r\n : unknown)\r\n\r\n/**\r\n * A higher-order function that returns a function that may be used to check\r\n * whether an action was created by an async thunk action creator, and that\r\n * the action is rejected with value.\r\n *\r\n * @public\r\n */\r\nexport function isRejectedWithValue(): (\r\n action: any\r\n) => action is UnknownAsyncThunkRejectedAction\r\n/**\r\n * A higher-order function that returns a function that may be used to check\r\n * whether an action belongs to one of the provided async thunk action creators,\r\n * and that the action is rejected with value.\r\n *\r\n * @param asyncThunks (optional) The async thunk action creators to match against.\r\n *\r\n * @public\r\n */\r\nexport function isRejectedWithValue<\r\n AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]\r\n>(\r\n ...asyncThunks: AsyncThunks\r\n): (\r\n action: any\r\n) => action is RejectedWithValueActionFromAsyncThunk<AsyncThunks[number]>\r\n/**\r\n * Tests if `action` is a rejected thunk action with value\r\n * @public\r\n */\r\nexport function isRejectedWithValue(\r\n action: any\r\n): action is UnknownAsyncThunkRejectedAction\r\nexport function isRejectedWithValue<\r\n AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]\r\n>(...asyncThunks: AsyncThunks | [any]) {\r\n const hasFlag = (action: any): action is any => {\r\n return action && action.meta && action.meta.rejectedWithValue\r\n }\r\n\r\n if (asyncThunks.length === 0) {\r\n return (action: any) => {\r\n const combinedMatcher = isAllOf(isRejected(...asyncThunks), hasFlag)\r\n\r\n return combinedMatcher(action)\r\n }\r\n }\r\n\r\n if (!isAsyncThunkArray(asyncThunks)) {\r\n return isRejectedWithValue()(asyncThunks[0])\r\n }\r\n\r\n return (\r\n action: any\r\n ): action is RejectedActionFromAsyncThunk<AsyncThunks[number]> => {\r\n const combinedMatcher = isAllOf(isRejected(...asyncThunks), hasFlag)\r\n\r\n return combinedMatcher(action)\r\n }\r\n}\r\n\r\nexport type UnknownAsyncThunkFulfilledAction = ReturnType<\r\n AsyncThunkFulfilledActionCreator<unknown, unknown>\r\n>\r\n\r\nexport type FulfilledActionFromAsyncThunk<T extends AnyAsyncThunk> =\r\n ActionFromMatcher<T['fulfilled']>\r\n\r\n/**\r\n * A higher-order function that returns a function that may be used to check\r\n * whether an action was created by an async thunk action creator, and that\r\n * the action is fulfilled.\r\n *\r\n * @public\r\n */\r\nexport function isFulfilled(): (\r\n action: any\r\n) => action is UnknownAsyncThunkFulfilledAction\r\n/**\r\n * A higher-order function that returns a function that may be used to check\r\n * whether an action belongs to one of the provided async thunk action creators,\r\n * and that the action is fulfilled.\r\n *\r\n * @param asyncThunks (optional) The async thunk action creators to match against.\r\n *\r\n * @public\r\n */\r\nexport function isFulfilled<\r\n AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]\r\n>(\r\n ...asyncThunks: AsyncThunks\r\n): (action: any) => action is FulfilledActionFromAsyncThunk<AsyncThunks[number]>\r\n/**\r\n * Tests if `action` is a fulfilled thunk action\r\n * @public\r\n */\r\nexport function isFulfilled(\r\n action: any\r\n): action is UnknownAsyncThunkFulfilledAction\r\nexport function isFulfilled<\r\n AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]\r\n>(...asyncThunks: AsyncThunks | [any]) {\r\n if (asyncThunks.length === 0) {\r\n return (action: any) => hasExpectedRequestMetadata(action, ['fulfilled'])\r\n }\r\n\r\n if (!isAsyncThunkArray(asyncThunks)) {\r\n return isFulfilled()(asyncThunks[0])\r\n }\r\n\r\n return (\r\n action: any\r\n ): action is FulfilledActionFromAsyncThunk<AsyncThunks[number]> => {\r\n // note: this type will be correct because we have at least 1 asyncThunk\r\n const matchers: [Matcher<any>, ...Matcher<any>[]] = asyncThunks.map(\r\n (asyncThunk) => asyncThunk.fulfilled\r\n ) as any\r\n\r\n const combinedMatcher = isAnyOf(...matchers)\r\n\r\n return combinedMatcher(action)\r\n }\r\n}\r\n\r\nexport type UnknownAsyncThunkAction =\r\n | UnknownAsyncThunkPendingAction\r\n | UnknownAsyncThunkRejectedAction\r\n | UnknownAsyncThunkFulfilledAction\r\n\r\nexport type AnyAsyncThunk = {\r\n pending: { match: (action: any) => action is any }\r\n fulfilled: { match: (action: any) => action is any }\r\n rejected: { match: (action: any) => action is any }\r\n}\r\n\r\nexport type ActionsFromAsyncThunk<T extends AnyAsyncThunk> =\r\n | ActionFromMatcher<T['pending']>\r\n | ActionFromMatcher<T['fulfilled']>\r\n | ActionFromMatcher<T['rejected']>\r\n\r\n/**\r\n * A higher-order function that returns a function that may be used to check\r\n * whether an action was created by an async thunk action creator.\r\n *\r\n * @public\r\n */\r\nexport function isAsyncThunkAction(): (\r\n action: any\r\n) => action is UnknownAsyncThunkAction\r\n/**\r\n * A higher-order function that returns a function that may be used to check\r\n * whether an action belongs to one of the provided async thunk action creators.\r\n *\r\n * @param asyncThunks (optional) The async thunk action creators to match against.\r\n *\r\n * @public\r\n */\r\nexport function isAsyncThunkAction<\r\n AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]\r\n>(\r\n ...asyncThunks: AsyncThunks\r\n): (action: any) => action is ActionsFromAsyncThunk<AsyncThunks[number]>\r\n/**\r\n * Tests if `action` is a thunk action\r\n * @public\r\n */\r\nexport function isAsyncThunkAction(\r\n action: any\r\n): action is UnknownAsyncThunkAction\r\nexport function isAsyncThunkAction<\r\n AsyncThunks extends [AnyAsyncThunk, ...AnyAsyncThunk[]]\r\n>(...asyncThunks: AsyncThunks | [any]) {\r\n if (asyncThunks.length === 0) {\r\n return (action: any) =>\r\n hasExpectedRequestMetadata(action, ['pending', 'fulfilled', 'rejected'])\r\n }\r\n\r\n if (!isAsyncThunkArray(asyncThunks)) {\r\n return isAsyncThunkAction()(asyncThunks[0])\r\n }\r\n\r\n return (\r\n action: any\r\n ): action is ActionsFromAsyncThunk<AsyncThunks[number]> => {\r\n // note: this type will be correct because we have at least 1 asyncThunk\r\n const matchers: [Matcher<any>, ...Matcher<any>[]] = [] as any\r\n\r\n for (const asyncThunk of asyncThunks) {\r\n matchers.push(\r\n asyncThunk.pending,\r\n asyncThunk.rejected,\r\n asyncThunk.fulfilled\r\n )\r\n }\r\n\r\n const combinedMatcher = isAnyOf(...matchers)\r\n\r\n return combinedMatcher(action)\r\n }\r\n}\r\n"]}