import{logger as o}from"../../tools/notifiers/logger.js";const r="_redocly_db_preconnect_cache_";class t{static get#t(){const e=globalThis;if(!e[r]){const i={connections:new Map,pendingConnections:new Map,failedConnections:new Set};e[r]=i}return e[r]}static get#c(){return t.#t.connections}static get#e(){return t.#t.failedConnections}static get#i(){return t.#t.pendingConnections}static async getConnection({config:e,strategy:i}){const n=t.#l(e),c=t.#c.get(n);return c||t.#n({config:e,key:n,strategy:i})}static#n=async({config:e,key:i,strategy:n})=>{let c=t.#i.get(i);c||(t.#e.has(i)&&o.warn("There was an error connecting to the database, retrying..."),c=t.#r(e,i,n),t.#i.set(i,c));try{return await c}catch{return t.#e.add(i),null}finally{t.#i.delete(i)}};static#r=async(e,i,n)=>{const c=await n.initialize(e);return t.#c.set(i,c),t.#e.delete(i),c};static#l=e=>`${e.baseDbDir}/${e.additionalFolder}/${e.databaseName}`}export{t as DatabaseConnectionsManager};
