import { i18n } from '@osd/i18n' ; import { ExpressionFunctionDefinition } from '../../../../../plugins/expressions/public' ; import { getIndexPatterns } from '../../services' ; import { IndexPatternSpec } from '../../../common/index_patterns' ; const name = 'indexPatternLoad' ; type Input = null ; type Output = Promise < { type : 'index_pattern' ; value : IndexPatternSpec ; } > ; interface Arguments { id : string ; } export const indexPatternLoad = ( ) : ExpressionFunctionDefinition < typeof name , Input , Arguments , Output > => ( { name , type : 'index_pattern' , inputTypes : [ 'null' ] , help : i18n . translate ( 'data.functions.indexPatternLoad.help' , { defaultMessage : 'Loads an index pattern' , } ) , args : { id : { types : [ 'string' ] , required : true , help : i18n . translate ( 'data.functions.indexPatternLoad.id.help' , { defaultMessage : 'index pattern id to load' , } ) , } , } , async fn ( input , args ) { const indexPatterns = getIndexPatterns ( ) ; const indexPattern = await indexPatterns . get ( args . id ) ; return { type : 'index_pattern' , value : indexPattern . toSpec ( ) } ; } , } ) ;