import { Observable , from , EMPTY } from 'rxjs' ; import { map , takeUntil } from 'rxjs/operators' ; import { HttpStart } from 'src/core/public' ; import { GlobalSearchResult , GlobalSearchProviderFindParams } from '../../common/types' ; import { GlobalSearchFindOptions } from './types' ; interface ServerFetchResponse { results : GlobalSearchResult [ ] ; } remarks export const fetchServerResults = ( http , params , { preference , aborted$ } ) : Observable < GlobalSearchResult [ ] > => { let controller ; if ( aborted$ ) { controller = new AbortController ( ) ; aborted$ . subscribe ( ( ) => { controller ! . abort ( ) ; } ) ; } return from ( http . post < ServerFetchResponse > ( '/internal/global_search/find' , { body : JSON . stringify ( { params , options : { preference } } ) , signal : controller ?. signal , } ) ) . pipe ( takeUntil ( aborted$ ?? EMPTY ) , map ( ( response ) => response . results ) ) ; } ;