{"version":3,"file":"reducer.cjs","names":["keyedReducer","EquivalentKeyMap","selectorArgsToStateKey"],"sources":["../../../src/redux-store/metadata/reducer.ts"],"sourcesContent":["import EquivalentKeyMap from 'equivalent-key-map';\nimport type { Reducer } from 'redux';\nimport type {\n\tstartResolution,\n\tfinishResolution,\n\tfailResolution,\n\tstartResolutions,\n\tfinishResolutions,\n\tfailResolutions,\n\tinvalidateResolution,\n\tinvalidateResolutionForStore,\n\tinvalidateResolutionForStoreSelector,\n} from './actions';\nimport { keyedReducer } from '../keyed-reducer';\nimport { selectorArgsToStateKey } from './utils';\n\ntype Action =\n\t| ReturnType< typeof startResolution >\n\t| ReturnType< typeof finishResolution >\n\t| ReturnType< typeof failResolution >\n\t| ReturnType< typeof startResolutions >\n\t| ReturnType< typeof finishResolutions >\n\t| ReturnType< typeof failResolutions >\n\t| ReturnType< typeof invalidateResolution >\n\t| ReturnType< typeof invalidateResolutionForStore >\n\t| ReturnType< typeof invalidateResolutionForStoreSelector >;\n\ntype StateKey = unknown[] | unknown;\nexport type StateValue =\n\t| { status: 'resolving' | 'finished' }\n\t| { status: 'error'; error: Error | unknown };\n\nexport type Status = StateValue[ 'status' ];\nexport type State = EquivalentKeyMap< StateKey, StateValue >;\n\n/**\n * Reducer function returning next state for selector resolution of\n * subkeys, object form:\n *\n *  selectorName -> EquivalentKeyMap<Array,boolean>\n */\nconst subKeysIsResolved: Reducer<\n\tRecord< string, State >,\n\tAction\n> = keyedReducer< State, Action >( 'selectorName' )( (\n\tstate = new EquivalentKeyMap(),\n\taction: Action\n) => {\n\tswitch ( action.type ) {\n\t\tcase 'START_RESOLUTION': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.set( selectorArgsToStateKey( action.args ), {\n\t\t\t\tstatus: 'resolving',\n\t\t\t} );\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'FINISH_RESOLUTION': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.set( selectorArgsToStateKey( action.args ), {\n\t\t\t\tstatus: 'finished',\n\t\t\t} );\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'FAIL_RESOLUTION': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.set( selectorArgsToStateKey( action.args ), {\n\t\t\t\tstatus: 'error',\n\t\t\t\terror: action.error,\n\t\t\t} );\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'START_RESOLUTIONS': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tfor ( const resolutionArgs of action.args ) {\n\t\t\t\tnextState.set( selectorArgsToStateKey( resolutionArgs ), {\n\t\t\t\t\tstatus: 'resolving',\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'FINISH_RESOLUTIONS': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tfor ( const resolutionArgs of action.args ) {\n\t\t\t\tnextState.set( selectorArgsToStateKey( resolutionArgs ), {\n\t\t\t\t\tstatus: 'finished',\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'FAIL_RESOLUTIONS': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\taction.args.forEach( ( resolutionArgs, idx ) => {\n\t\t\t\tconst resolutionState: StateValue = {\n\t\t\t\t\tstatus: 'error',\n\t\t\t\t\terror: undefined,\n\t\t\t\t};\n\n\t\t\t\tconst error = action.errors[ idx ];\n\t\t\t\tif ( error ) {\n\t\t\t\t\tresolutionState.error = error;\n\t\t\t\t}\n\n\t\t\t\tnextState.set(\n\t\t\t\t\tselectorArgsToStateKey( resolutionArgs as unknown[] ),\n\t\t\t\t\tresolutionState\n\t\t\t\t);\n\t\t\t} );\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'INVALIDATE_RESOLUTION': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.delete( selectorArgsToStateKey( action.args ) );\n\t\t\treturn nextState;\n\t\t}\n\t}\n\treturn state;\n} );\n\n/**\n * Reducer function returning next state for selector resolution, object form:\n *\n *   selectorName -> EquivalentKeyMap<Array, boolean>\n *\n * @param state  Current state.\n * @param action Dispatched action.\n *\n * @return Next state.\n */\nconst isResolved = ( state: Record< string, State > = {}, action: Action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'INVALIDATE_RESOLUTION_FOR_STORE':\n\t\t\treturn {};\n\t\tcase 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR': {\n\t\t\tif ( action.selectorName in state ) {\n\t\t\t\tconst {\n\t\t\t\t\t[ action.selectorName ]: removedSelector,\n\t\t\t\t\t...restState\n\t\t\t\t} = state;\n\t\t\t\treturn restState;\n\t\t\t}\n\t\t\treturn state;\n\t\t}\n\t\tcase 'START_RESOLUTION':\n\t\tcase 'FINISH_RESOLUTION':\n\t\tcase 'FAIL_RESOLUTION':\n\t\tcase 'START_RESOLUTIONS':\n\t\tcase 'FINISH_RESOLUTIONS':\n\t\tcase 'FAIL_RESOLUTIONS':\n\t\tcase 'INVALIDATE_RESOLUTION':\n\t\t\treturn subKeysIsResolved( state, action );\n\t\tdefault:\n\t\t\treturn state;\n\t}\n};\n\nexport default isResolved;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAM,qBAAA,GAGFA,oBAAAA,aAAAA,CAA+B,cAAe,CAAC,EAClD,QAAQ,IAAIC,mBAAAA,QAAiB,GAC7B,WACI;CACJ,QAAS,OAAO,MAAhB;EACC,KAAK,oBAAoB;GACxB,MAAM,YAAY,IAAIA,mBAAAA,QAAkB,KAAM;GAC9C,UAAU,KAAA,GAAKC,WAAAA,uBAAAA,CAAwB,OAAO,IAAK,GAAG,EACrD,QAAQ,YACT,CAAE;GACF,OAAO;EACR;EACA,KAAK,qBAAqB;GACzB,MAAM,YAAY,IAAID,mBAAAA,QAAkB,KAAM;GAC9C,UAAU,KAAA,GAAKC,WAAAA,uBAAAA,CAAwB,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