import { CoreSetup , CoreStart } from 'kibana/public' ; import * as t from 'io-ts' ; import type { ClientRequestParamsOf , formatRequest as formatRequestType , ReturnOf , RouteRepositoryClient , ServerRouteRepository , ServerRoute , } from '@kbn/server-route-repository' ; import { formatRequest } from '@kbn/server-route-repository/target_node/format_request' ; import { FetchOptions } from '../../../common/fetch_options' ; import { callApi } from './callApi' ; import type { APMServerRouteRepository , APMRouteHandlerResources , APIEndpoint , } from '../../../server' ; import { InspectResponse } from '../../../../observability/typings/common' ; export type APMClientOptions = Omit < FetchOptions , 'query' | 'body' | 'pathname' | 'signal' > & { signal : AbortSignal | null ; } ; export type APMClient = RouteRepositoryClient < APMServerRouteRepository , APMClientOptions > ; export type AutoAbortedAPMClient = RouteRepositoryClient < APMServerRouteRepository , Omit < APMClientOptions , 'signal' > > ; export type APIReturnType < TEndpoint extends APIEndpoint > = ReturnOf < APMServerRouteRepository , TEndpoint > & { _inspect ? : InspectResponse ; } ; export type APIClientRequestParamsOf < TEndpoint extends APIEndpoint > = ClientRequestParamsOf < APMServerRouteRepository , TEndpoint > ; export type AbstractAPMRepository = ServerRouteRepository < APMRouteHandlerResources , { } , Record < string , ServerRoute < string , t . Mixed | undefined , APMRouteHandlerResources , any , { } > > > ; export type AbstractAPMClient = RouteRepositoryClient < AbstractAPMRepository , APMClientOptions > ; export let callApmApi = ( ) => { throw new Error ( 'callApmApi has to be initialized before used. Call createCallApmApi first.' ) ; } ; export function createCallApmApi ( core ) { callApmApi = ( ( options ) => { const { endpoint , ... opts } = options ; const { params } = options as unknown as { params ? : Partial < Record < string , any > > ; } ; const { method , pathname } = formatRequest ( endpoint , params ?. path ) as ReturnType < typeof formatRequestType > ; return callApi ( core , { ... opts , method , pathname , body : params ?. body , query : params ?. query , } ) ; } ) as APMClient ; }