"use strict";exports.ids=["214"],exports.modules={32732:function(e,t,n){var r=n(15755).default;Object.defineProperty(t,"__esModule",{value:!0}),t.IndexSettingsGetError=void 0;var s=r(n(96861));class i extends s.default{constructor(e,t){super(e.message,"GET_INDEX_SETTINGS_ERROR",{...e.data,index:t}),this.index=t}}t.IndexSettingsGetError=i},82207:function(e,t,n){var r=n(15755).default;Object.defineProperty(t,"__esModule",{value:!0}),t.IndexSettingsSetError=void 0;var s=r(n(96861));class i extends s.default{constructor(e,t){super(e.message,"SET_INDEX_SETTINGS_ERROR",{...e.data,index:t}),this.index=t}}t.IndexSettingsSetError=i},16388:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.IndexingDisableError=void 0,t.IndexingDisableError=class extends Error{}},23386:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.IndexingEnableError=void 0,t.IndexingEnableError=class extends Error{}},35158:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(16388);Object.keys(r).forEach(function(e){"default"!==e&&"__esModule"!==e&&(e in t&&t[e]===r[e]||Object.defineProperty(t,e,{enumerable:!0,get:function(){return r[e]}}))});var s=n(23386);Object.keys(s).forEach(function(e){"default"!==e&&"__esModule"!==e&&(e in t&&t[e]===s[e]||Object.defineProperty(t,e,{enumerable:!0,get:function(){return s[e]}}))});var i=n(32732);Object.keys(i).forEach(function(e){"default"!==e&&"__esModule"!==e&&(e in t&&t[e]===i[e]||Object.defineProperty(t,e,{enumerable:!0,get:function(){return i[e]}}))});var a=n(82207);Object.keys(a).forEach(function(e){"default"!==e&&"__esModule"!==e&&(e in t&&t[e]===a[e]||Object.defineProperty(t,e,{enumerable:!0,get:function(){return a[e]}}))})},37248:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.DisableIndexing=void 0;var r=n(35158);t.DisableIndexing=class{constructor(e){this.settings=e}async exec(e){let t=await this.settings.getSettings(e);try{await this.settings.setSettings(e,{numberOfReplicas:0,refreshInterval:"-1"})}catch(e){throw new r.IndexingDisableError(e)}return t}}},19918:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.EnableIndexing=void 0;var r=n(35158);t.EnableIndexing=class{constructor(e){this.settings=e}async exec(e,t){try{let n=parseInt(t.refreshInterval||"",10)||0;await this.settings.setSettings(e,{...t,numberOfReplicas:t.numberOfReplicas<1?1:t.numberOfReplicas,refreshInterval:n<=0?"1s":t.refreshInterval})}catch(e){throw new r.IndexingEnableError(e)}}}},18975:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.IndexManager=void 0;var r=n(71981),s=n(37248),i=n(19918),a=n(40468);let c={numberOfReplicas:1,refreshInterval:"1s"},l=process.env.ELASTIC_SEARCH_INDEX_PREFIX||"",o=e=>!(!e||e.startsWith("."))&&(!l||e.startsWith(l));t.IndexManager=class{get settings(){return this._settings}constructor(e,t,n){let a=new r.IndexSettingsManager(e);this.client=e,this.disable=new s.DisableIndexing(a),this.enable=new i.EnableIndexing(a),this._settings=t,this.defaults={refreshInterval:n?.refreshInterval||c.refreshInterval,numberOfReplicas:n?.numberOfReplicas||c.numberOfReplicas}}async list(){try{let e=await this.client.cat.indices({format:"json"});if(!Array.isArray(e.body))return[];return e.body.map(e=>e.index).filter(o)}catch(e){return console.error(JSON.stringify({message:"Failed to list indices.",error:(0,a.getObjectProperties)(e)})),[]}}async disableIndexing(e){if(this._settings[e])return this._settings[e];let t=await this.disable.exec(e);return this._settings[e]=t,t}async enableIndexing(e){if(!e){for(let e of Object.keys(this._settings))await this.enableIndexing(e);return}let t=this._settings[e]||this.defaults;await this.enable.exec(e,t)}async createIndex(e,t){await this.client.indices.create({index:e,body:t})}async indexExists(e){return!!(await this.client.indices.exists({index:e,ignore_unavailable:!1,allow_no_indices:!0,include_defaults:!0,flat_settings:!1,local:!1})).body}}},71981:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.IndexSettingsManager=void 0;var r=n(35158);t.IndexSettingsManager=class{constructor(e){this.elasticsearch=e}async getSettings(e){try{let t=(await this.elasticsearch.indices.getSettings({index:e})).body[e].settings.index;return{numberOfReplicas:t.number_of_replicas,refreshInterval:t.refresh_interval}}catch(t){throw new r.IndexSettingsGetError(t,e)}}async setSettings(e,t){try{await this.elasticsearch.indices.putSettings({index:e,body:{index:{number_of_replicas:t.numberOfReplicas,refresh_interval:t.refreshInterval}}})}catch(t){throw new r.IndexSettingsSetError(t,e)}}}},90192:function(e,t,n){Object.defineProperty(t,"__esModule",{value:!0});var r=n(18975);Object.keys(r).forEach(function(e){"default"!==e&&"__esModule"!==e&&(e in t&&t[e]===r[e]||Object.defineProperty(t,e,{enumerable:!0,get:function(){return r[e]}}))})}};
//# sourceMappingURL=IndexManager.9bd863b2.chunk.js.map