import { getFields } from './get_fields' ; import { IIndexPattern , IFieldType , KueryNode } from '../../../..' ; export function getFullFieldNameNode ( rootNameNode , indexPattern ? , nestedPath ? ) { const fullFieldNameNode = { ... rootNameNode , value : nestedPath ? `${ nestedPath }.${ rootNameNode . value }` : rootNameNode . value , } ; if ( ! indexPattern || ( fullFieldNameNode . type === 'wildcard' && ! nestedPath ) ) { return fullFieldNameNode ; } const fields = getFields ( fullFieldNameNode , indexPattern ) ; const errors = fields ! . reduce ( ( acc , field ) => { const nestedPathFromField = field . subType && field . subType . nested ? field . subType . nested . path : undefined ; if ( nestedPath && ! nestedPathFromField ) { return [ ... acc , `${ field . name } is not a nested field but is in nested group "${ nestedPath }" in the DQL expression.` , ] ; } if ( nestedPathFromField && ! nestedPath ) { return [ ... acc , `${ field . name } is a nested field, but is not in a nested group in the DQL expression.` , ] ; } if ( nestedPathFromField !== nestedPath ) { return [ ... acc , `Nested field ${ field . name } is being queried with the incorrect nested path. The correct path is ${ field . subType ! . nested ! . path }.` , ] ; } return acc ; } , [ ] ) ; if ( errors . length > 0 ) { throw new Error ( errors . join ( '\n' ) ) ; } return fullFieldNameNode ; }