import { Client } from 'elasticsearch' ; import { ToolingLog , OsdClient } from '@osd/dev-utils' ; import { saveAction , loadAction , unloadAction , rebuildAllAction , emptyOpenSearchDashboardsIndexAction , editAction , } from './actions' ; export class OpenSearchArchiver { private readonly client : Client ; private readonly dataDir : string ; private readonly log : ToolingLog ; private readonly osdClient : OsdClient ; constructor ( { client , dataDir , log , opensearchDashboardsUrl , } ) { this . client = client ; this . dataDir = dataDir ; this . log = log ; this . osdClient = new OsdClient ( { log , url : opensearchDashboardsUrl } ) ; } param { String } name param { String | Array < String > } indices param { Object } options property return async save ( name , indices , { raw = false , query } = { } ) { return await saveAction ( { name , indices , raw , client : this . client , dataDir : this . dataDir , log : this . log , query , } ) ; } param { String } name param { Object } options property property return async load ( name , { skipExisting = false , useCreate = false , } = { } ) { return await loadAction ( { name , skipExisting : ! ! skipExisting , useCreate : ! ! useCreate , client : this . client , dataDir : this . dataDir , log : this . log , osdClient : this . osdClient , } ) ; } param { String } name return async unload ( name ) { return await unloadAction ( { name , client : this . client , dataDir : this . dataDir , log : this . log , osdClient : this . osdClient , } ) ; } return async rebuildAll ( ) { return await rebuildAllAction ( { dataDir : this . dataDir , log : this . log , } ) ; } param { String } prefix param { ( ) => Promise < any > } handler return async edit ( prefix , handler ) { return await editAction ( { prefix , log : this . log , dataDir : this . dataDir , handler , } ) ; } param { String } name return async loadIfNeeded ( name ) { return await this . load ( name , { skipExisting : true } ) ; } return async emptyOpenSearchDashboardsIndex ( ) { await emptyOpenSearchDashboardsIndexAction ( { client : this . client , log : this . log , osdClient : this . osdClient , } ) ; } }