import type { TransportRequestOptions } from '@elastic/elasticsearch/lib/Transport' ; import { OpenSearchClient } from '../../../opensearch/' ; import { retryCallCluster } from '../../../opensearch/client/retry_call_cluster' ; import { decorateOpenSearchError } from './decorate_opensearch_error' ; const methods = [ 'bulk' , 'create' , 'delete' , 'get' , 'index' , 'mget' , 'search' , 'update' , 'updateByQuery' , ] as const ; type MethodName = typeof methods [ number ] ; export type RepositoryOpenSearchClient = Pick < OpenSearchClient , MethodName > ; export function createRepositoryOpenSearchClient ( client ) { return methods . reduce ( ( acc , key ) => { Object . defineProperty ( acc , key , { value : async ( params ? , options ? ) => { try { return await retryCallCluster ( ( ) => ( client [ key ] as Function ) ( params , { maxRetries : 0 , ... options } ) ) ; } catch ( e ) { throw decorateOpenSearchError ( e ) ; } } , } ) ; return acc ; } , { } as RepositoryOpenSearchClient ) ; }