import rison , { RisonValue } from 'rison-node' ; import { isStateHash , retrieveState , persistState } from '../state_hash' ; export function decodeState < State > ( expandedOrHashedState ) { if ( isStateHash ( expandedOrHashedState ) ) { return retrieveState ( expandedOrHashedState ) ; } else { return ( rison . decode ( expandedOrHashedState ) as unknown ) as State ; } } export function encodeState < State > ( state , useHash ) { if ( useHash ) { return persistState ( state ) ; } else { return rison . encode ( ( state as unknown ) as RisonValue ) ; } } export function hashedStateToExpandedState ( expandedOrHashedState ) { if ( isStateHash ( expandedOrHashedState ) ) { return encodeState ( retrieveState ( expandedOrHashedState ) , false ) ; } return expandedOrHashedState ; } export function expandedStateToHashedState ( expandedOrHashedState ) { if ( isStateHash ( expandedOrHashedState ) ) { return expandedOrHashedState ; } return persistState ( decodeState ( expandedOrHashedState ) ) ; }