"use strict";exports.id=102,exports.ids=[102],exports.modules={60232:(e,t,n)=>{var r=n(92120).default;Object.defineProperty(t,"__esModule",{value:!0}),t.IndexSettingsGetError=void 0;var s=r(n(32126));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},48164:(e,t,n)=>{var r=n(92120).default;Object.defineProperty(t,"__esModule",{value:!0}),t.IndexSettingsSetError=void 0;var s=r(n(32126));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},71569:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.IndexingDisableError=void 0;class n extends Error{}t.IndexingDisableError=n},5664:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.IndexingEnableError=void 0;class n extends Error{}t.IndexingEnableError=n},19963:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(71569);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(5664);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(60232);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(48164);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]}}))}))},21233:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DisableIndexing=void 0;var r=n(19963);t.DisableIndexing=class{constructor(e){this.settings=e}async exec(e){const 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}}},60566:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EnableIndexing=void 0;var r=n(19963);t.EnableIndexing=class{constructor(e){this.settings=e}async exec(e,t){try{const 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)}}}},46050:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.IndexManager=void 0;var r=n(25313),s=n(21233),i=n(60566),a=n(27179);const c=process.env.ELASTIC_SEARCH_INDEX_PREFIX||"",o=e=>!!e&&!e.startsWith(".")&&(!c||e.startsWith(c));t.IndexManager=class{get settings(){return this._settings}constructor(e,t,n){const 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||"1s",numberOfReplicas:n?.numberOfReplicas||1}}async list(){try{const e=await this.client.cat.indices({format:"json"});return Array.isArray(e.body)?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];const t=await this.disable.exec(e);return this._settings[e]=t,t}async enableIndexing(e){if(!e){const e=Object.keys(this._settings);for(const t of e)await this.enableIndexing(t);return}const 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}}},25313:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.IndexSettingsManager=void 0;var r=n(19963);t.IndexSettingsManager=class{constructor(e){this.elasticsearch=e}async getSettings(e){try{const 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)}}}},77357:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(46050);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.15a61dc7.chunk.js.map