import type { IScopedClusterClient } from 'kibana/server' ; import type { DataViewsService } from '../../../../../../../src/plugins/data_views/common' ; import type { Aggregation , Field , NewJobCapsResponse } from '../../../../common/types/fields' ; import { _DOC_COUNT } from '../../../../common/constants/field_types' ; import { fieldServiceProvider } from './field_service' ; export function newJobCapsProvider ( client ) { async function newJobCaps ( indexPattern , isRollup = false , dataViewsService ) { const fieldService = fieldServiceProvider ( indexPattern , isRollup , client , dataViewsService ) ; const { aggs , fields } = await fieldService . getData ( ) ; convertForStringify ( aggs , fields ) ; const fieldsWithoutDocCount = fields . filter ( ( { id } ) => id !== _DOC_COUNT ) ; return { [ indexPattern ] : { aggs , fields : fieldsWithoutDocCount , } , } ; } return { newJobCaps , } ; } function convertForStringify ( aggs , fields ) { fields . forEach ( ( f ) => { f . aggIds = f . aggs ? f . aggs . map ( ( a ) => a . id ) : [ ] ; delete f . aggs ; } ) ; aggs . forEach ( ( a ) => { if ( a . fields !== undefined ) { a . fieldIds = a . fields . map ( ( f ) => f . id ) ; } delete a . fields ; } ) ; }