import { IAggConfig } from '../agg_config' ; import { OSD_FIELD_TYPES } from '../../../../common' ; import { AggType , AggTypeConfig } from '../agg_type' ; import { AggParamType } from '../param_types/agg' ; export interface IBucketAggConfig extends IAggConfig { type : InstanceType < typeof BucketAggType > ; } export interface BucketAggParam < TBucketAggConfig extends IAggConfig > extends AggParamType < TBucketAggConfig > { scriptable ? : boolean ; filterFieldTypes ? : OSD_FIELD_TYPES | OSD_FIELD_TYPES [ ] | '*' ; } const bucketType = 'buckets' ; interface BucketAggTypeConfig < TBucketAggConfig extends IAggConfig > extends AggTypeConfig < TBucketAggConfig , BucketAggParam < TBucketAggConfig > > { getKey ? : ( bucket : any , key : any , agg : IAggConfig ) => any ; } export class BucketAggType < TBucketAggConfig extends IAggConfig = IBucketAggConfig > extends AggType < TBucketAggConfig , BucketAggParam < TBucketAggConfig > > { getKey : ( bucket : any , key : any , agg : TBucketAggConfig ) => any ; type = bucketType ; constructor ( config ) { super ( config ) ; this . getKey = config . getKey || ( ( bucket , key ) => { return key || bucket . key ; } ) ; } } export function isBucketAggType ( aggConfig ) { return aggConfig && aggConfig . type === bucketType ; }