import { isPlainObject } from 'lodash' ; import { RuleType , RuleTypeId , ruleTypeMappings } from './rule_type_mappings' ; export const isRuleType = ( ruleType ) : ruleType is RuleType => { return Object . keys ( ruleTypeMappings ) . includes ( ruleType as string ) ; } ; export const isRuleTypeId = ( ruleTypeId ) : ruleTypeId is RuleTypeId => { return Object . values ( ruleTypeMappings ) . includes ( ruleTypeId as RuleTypeId ) ; } ; type SearchTypes = string | number | boolean | object | SearchTypes [ ] | undefined ; export const flattenWithPrefix = ( prefix , maybeObj ) : Record < string , SearchTypes > => { if ( maybeObj != null && isPlainObject ( maybeObj ) ) { return Object . keys ( maybeObj as Record < string , SearchTypes > ) . reduce ( ( acc , key ) => { return { ... acc , ... flattenWithPrefix ( `${ prefix }.${ key }` , ( maybeObj as Record < string , SearchTypes > ) [ key ] ) , } ; } , { } ) ; } else { return { [ prefix ] : maybeObj as SearchTypes , } ; } } ;