import { i18n } from '@osd/i18n' ; import { ExpressionFunctionDefinition } from '../types' ; import { ExpressionValueSearchContext } from '../../expression_types' ; const toArray = < T > ( query ) : T [ ] => ! query ? [ ] : Array . isArray ( query ) ? query : [ query ] ; export type ExpressionFunctionOpenSearchDashboards = ExpressionFunctionDefinition < 'opensearchDashboards' , ExpressionValueSearchContext | null , object , ExpressionValueSearchContext > ; export const opensearchDashboards = { name : 'opensearchDashboards' , type : 'opensearch_dashboards_context' , inputTypes : [ 'opensearch_dashboards_context' , 'null' ] , help : i18n . translate ( 'expressions.functions.kibana.help' , { defaultMessage : 'Gets opensearch dashboards global context' , } ) , args : { } , fn ( input , _ , { search = { } } ) { const output = { ... input , type : 'opensearch_dashboards_context' , query : [ ... toArray ( search . query ) , ... toArray ( ( input || { } ) . query ) ] , filters : [ ... ( search . filters || [ ] ) , ... ( ( input || { } ) . filters || [ ] ) ] , timeRange : search . timeRange || ( input ? input . timeRange : undefined ) , } ; return output ; } , } ;