import { BucketAggType } from './buckets/bucket_agg_type' ; import { MetricAggType } from './metrics/metric_agg_type' ; import { AggTypesDependencies } from './agg_types' ; export type AggTypesRegistrySetup = ReturnType < AggTypesRegistry [ 'setup' ] > ; internal export interface AggTypesRegistryStart { get : ( id : string ) => BucketAggType < any > | MetricAggType < any > ; getAll : ( ) => { buckets : Array < BucketAggType < any > > ; metrics : Array < MetricAggType < any > > ; } ; } export class AggTypesRegistry { private readonly bucketAggs = new Map ( ) ; private readonly metricAggs = new Map ( ) ; setup = ( ) => { return { registerBucket : < N extends string , T extends ( deps : AggTypesDependencies ) => BucketAggType < any > > ( name , type ) : void => { if ( this . bucketAggs . get ( name ) || this . metricAggs . get ( name ) ) { throw new Error ( `Agg has already been registered with name: ${ name }` ) ; } this . bucketAggs . set ( name , type ) ; } , registerMetric : < N extends string , T extends ( deps : AggTypesDependencies ) => MetricAggType < any > > ( name , type ) : void => { if ( this . bucketAggs . get ( name ) || this . metricAggs . get ( name ) ) { throw new Error ( `Agg has already been registered with name: ${ name }` ) ; } this . metricAggs . set ( name , type ) ; } , } ; } ; start = ( ) => { return { get : ( name ) => { return this . bucketAggs . get ( name ) || this . metricAggs . get ( name ) ; } , getAll : ( ) => { return { buckets : Array . from ( this . bucketAggs . values ( ) ) , metrics : Array . from ( this . metricAggs . values ( ) ) , } ; } , } ; } ; }