import { IAggConfig , IndexPatternField } from '../../../data/public' ; type AggTypeFieldFilter = ( field : IndexPatternField , aggConfig : IAggConfig ) => boolean ; const filters = [ /**
     * Check index pattern aggregation restrictions
     * and limit available fields for a given aggType based on that.
     */ ( field , aggConfig ) => { const indexPattern = aggConfig . getIndexPattern ( ) ; const aggRestrictions = indexPattern . getAggregationRestrictions ( ) ; if ( ! aggRestrictions ) { return true ; } const aggName = aggConfig . type && aggConfig . type . name ; const aggFields = aggRestrictions [ aggName ] ; return ! ! aggFields && ! ! aggFields [ field . name ] ; } , ] ; export function filterAggTypeFields ( fields , aggConfig ) { const allowedAggTypeFields = fields . filter ( ( field ) => { const isAggTypeFieldAllowed = filters . every ( ( filter ) => filter ( field , aggConfig ) ) ; return isAggTypeFieldAllowed ; } ) ; return allowedAggTypeFields ; }