import { uniqBy } from 'lodash' ; import { Framework } from '../plugin' ; import { VisTypeTimeseriesFieldsRequest , VisTypeTimeseriesRequestHandlerContext } from '../types' ; import { getCachedIndexPatternFetcher } from './search_strategies/lib/cached_index_pattern_fetcher' ; export async function getFields ( requestContext , request , framework , indexPatternString ) { const indexPatternsService = await framework . getIndexPatternsService ( requestContext ) ; const cachedIndexPatternFetcher = getCachedIndexPatternFetcher ( indexPatternsService ) ; if ( ! indexPatternString ) { const defaultIndexPattern = await indexPatternsService . getDefault ( ) ; indexPatternString = defaultIndexPattern ?. title ?? '' ; } const fetchedIndex = await cachedIndexPatternFetcher ( indexPatternString ) ; const { searchStrategy , capabilities } = ( await framework . searchStrategyRegistry . getViableStrategy ( requestContext , request , fetchedIndex ) ) ! ; const fields = await searchStrategy . getFieldsForWildcard ( fetchedIndex , indexPatternsService , capabilities ) ; return uniqBy ( fields , ( field ) => field . name ) ; }