import { getIndexPatternKey } from '../../../../common/index_patterns_utils' ; import type { VisTypeTimeseriesVisDataRequest } from '../../../types' ; import type { SearchStrategy , SearchCapabilities } from '../index' ; import type { IndexPatternsService } from '../../../../../../data/common' ; import type { CachedIndexPatternFetcher } from './cached_index_pattern_fetcher' ; import type { IndexPatternValue } from '../../../../common/types' ; export interface FieldsFetcherServices { indexPatternsService : IndexPatternsService ; cachedIndexPatternFetcher : CachedIndexPatternFetcher ; searchStrategy : SearchStrategy ; capabilities : SearchCapabilities ; } export const createFieldsFetcher = ( req , { capabilities , indexPatternsService , searchStrategy , cachedIndexPatternFetcher , } ) => { const fieldsCacheMap = new Map ( ) ; return async ( indexPatternValue ) => { const key = getIndexPatternKey ( indexPatternValue ) ; if ( fieldsCacheMap . has ( key ) ) { return fieldsCacheMap . get ( key ) ; } const fetchedIndex = await cachedIndexPatternFetcher ( indexPatternValue ) ; const fields = await searchStrategy . getFieldsForWildcard ( fetchedIndex , indexPatternsService , capabilities ) ; fieldsCacheMap . set ( key , fields ) ; return fields ; } ; } ;