import * as t from 'io-ts' ; import { maxSuggestions } from '../../../../observability/common' ; import { getSuggestions } from '../suggestions/get_suggestions' ; import { getSearchAggregatedTransactions } from '../../lib/helpers/transactions' ; import { setupRequest } from '../../lib/helpers/setup_request' ; import { createApmServerRoute } from '../apm_routes/create_apm_server_route' ; import { createApmServerRouteRepository } from '../apm_routes/create_apm_server_route_repository' ; const suggestionsRoute = createApmServerRoute ( { endpoint : 'GET /internal/apm/suggestions' , params : t . partial ( { query : t . type ( { field : t . string , string : t . string } ) , } ) , options : { tags : [ 'access:apm' ] } , handler : async ( resources ) => { const setup = await setupRequest ( resources ) ; const { context , params } = resources ; const { field , string } = params . query ; const searchAggregatedTransactions = await getSearchAggregatedTransactions ( { apmEventClient : setup . apmEventClient , config : setup . config , kuery : '' , } ) ; const size = await context . core . uiSettings . client . get < number > ( maxSuggestions ) ; const suggestions = await getSuggestions ( { field , searchAggregatedTransactions , setup , size , string , } ) ; return suggestions ; } , } ) ; export const suggestionsRouteRepository = createApmServerRouteRepository ( ) . add ( suggestionsRoute ) ;