import { ExpressionsServiceSetup } from 'src/plugins/expressions/common' ; import { UI_SETTINGS } from '../../../common' ; import { GetConfigFn } from '../../types' ; import { AggConfigs , AggTypesRegistry , getAggTypes , getAggTypesFunctions , getCalculateAutoTimeExpression , } from './' ; import { AggsCommonSetup , AggsCommonStart } from './types' ; internal export const aggsRequiredUiSettings = [ 'dateFormat' , 'dateFormat:scaled' , 'dateFormat:tz' , UI_SETTINGS . HISTOGRAM_BAR_TARGET , UI_SETTINGS . HISTOGRAM_MAX_BARS , UI_SETTINGS . SEARCH_QUERY_LANGUAGE , UI_SETTINGS . QUERY_ALLOW_LEADING_WILDCARDS , UI_SETTINGS . QUERY_STRING_OPTIONS , UI_SETTINGS . COURIER_IGNORE_FILTER_IF_FIELD_NOT_IN_INDEX , ] ; internal export interface AggsCommonSetupDependencies { registerFunction : ExpressionsServiceSetup [ 'registerFunction' ] ; } internal export interface AggsCommonStartDependencies { getConfig : GetConfigFn ; } /**
 * The aggs service provides a means of modeling and manipulating the various
 * OpenSearch aggregations supported by OpenSearch Dashboards, providing the ability to
 * output the correct DSL when you are ready to send your request to OpenSearch.
 */ export class AggsCommonService { private readonly aggTypesRegistry = new AggTypesRegistry ( ) ; public setup ( { registerFunction } ) { const aggTypesSetup = this . aggTypesRegistry . setup ( ) ; const aggTypes = getAggTypes ( ) ; aggTypes . buckets . forEach ( ( { name , fn } ) => aggTypesSetup . registerBucket ( name , fn ) ) ; aggTypes . metrics . forEach ( ( { name , fn } ) => aggTypesSetup . registerMetric ( name , fn ) ) ; const aggFunctions = getAggTypesFunctions ( ) ; aggFunctions . forEach ( ( fn ) => registerFunction ( fn ) ) ; return { types : aggTypesSetup , } ; } public start ( { getConfig } ) { const aggTypesStart = this . aggTypesRegistry . start ( ) ; return { calculateAutoTimeExpression : getCalculateAutoTimeExpression ( getConfig ) , createAggConfigs : ( indexPattern , configStates = [ ] , schemas ) => { return new AggConfigs ( indexPattern , configStates , { typesRegistry : aggTypesStart , } ) ; } , types : aggTypesStart , } ; } }