import { IScopedClusterClient } from 'kibana/server' ; import { wrapError } from '../client/error_wrapper' ; import { RouteInitialization } from '../types' ; import { getCardinalityOfFieldsSchema , getTimeFieldRangeSchema , } from './schemas/fields_service_schema' ; import { fieldsServiceProvider } from '../models/fields_service' ; function getCardinalityOfFields ( client , payload ) { const fs = fieldsServiceProvider ( client ) ; const { index , fieldNames , query , timeFieldName , earliestMs , latestMs } = payload ; return fs . getCardinalityOfFields ( index , fieldNames , query , timeFieldName , earliestMs , latestMs ) ; } function getTimeFieldRange ( client , payload ) { const fs = fieldsServiceProvider ( client ) ; const { index , timeFieldName , query , runtimeMappings , indicesOptions } = payload ; return fs . getTimeFieldRange ( index , timeFieldName , query , runtimeMappings , indicesOptions ) ; } /**
 * Routes for fields service
 */ export function fieldsService ( { router , routeGuard } ) { apiGroup api apiName apiDescription apiSchema apiSuccess router . post ( { path : '/api/ml/fields_service/field_cardinality' , validate : { body : getCardinalityOfFieldsSchema , } , options : { tags : [ 'access:ml:canAccessML' ] , } , } , routeGuard . fullLicenseAPIGuard ( async ( { client , request , response } ) => { try { const resp = await getCardinalityOfFields ( client , request . body ) ; return response . ok ( { body : resp , } ) ; } catch ( e ) { return response . customError ( wrapError ( e ) ) ; } } ) ) ; apiGroup api apiName apiDescription apiSchema apiSuccess apiSuccess router . post ( { path : '/api/ml/fields_service/time_field_range' , validate : { body : getTimeFieldRangeSchema , } , options : { tags : [ 'access:ml:canAccessML' ] , } , } , routeGuard . basicLicenseAPIGuard ( async ( { client , request , response } ) => { try { const resp = await getTimeFieldRange ( client , request . body ) ; return response . ok ( { body : resp , } ) ; } catch ( e ) { return response . customError ( wrapError ( e ) ) ; } } ) ) ; }