import { IndexMapping } from '../../../mappings' ; import { fieldDefined , hasFilterKeyError } from '../filter_utils' ; example export const isRootLevelAttribute = ( attributePath , indexMapping , allowedTypes ) : boolean => { const splits = attributePath . split ( '.' ) ; if ( splits . length <= 1 ) { return false ; } const [ type , firstPath , ... otherPaths ] = splits ; if ( allowedTypes . includes ( firstPath ) ) { return false ; } return ( allowedTypes . includes ( type ) && fieldDefined ( indexMapping , [ firstPath , ... otherPaths ] . join ( '.' ) ) ) ; } ; example export const rewriteRootLevelAttribute = ( attributePath ) => { const [ , ... attributes ] = attributePath . split ( '.' ) ; return attributes . join ( '.' ) ; } ; example export const isObjectTypeAttribute = ( attributePath , indexMapping , allowedTypes ) : boolean => { const error = hasFilterKeyError ( attributePath , allowedTypes , indexMapping ) ; return error == null ; } ; example export const rewriteObjectTypeAttribute = ( attributePath ) => { return attributePath . replace ( '.attributes' , '' ) ; } ;