import{logger as e}from"../../tools/notifiers/logger.js";import{DatabaseConnectionsManager as r}from"./database-connections-manager.js";import{CATALOG_DATABASE_MIGRATIONS_FOLDER as n,CATALOG_REMOTE_DATABASE_FOLDER as i,CATALOG_REMOTE_DATABASE_NAME as E}from"../../plugins/catalog-entities/database/consts.js";import{RemoteDatabaseInitializationStrategy as A}from"./database-initialization-strategy.js";class a{static#t=!1;static async init(s){if(!(process.env.REDOCLY_LOCAL_DEV==="true"||process.env.CI==="true")&&!a.#t)try{await a.#e(s)==="PRECONNECTED"&&(a.#t=!0)}catch(t){e.error("Failed to preconnect to databases",t)}}static#e=async s=>{const o=process.env.SQLD_REMOTE_DATABASE_URL,t=process.env.SQLD_REMOTE_DATABASE_AUTH_TOKEN;return!o||!t?(e.warn("SQLD_REMOTE_DATABASE_URL or SQLD_REMOTE_DATABASE_AUTH_TOKEN is not set yet"),"NOT_PRECONNECTED"):await r.getConnection({config:{baseDbDir:s,syncUrl:o,authToken:t,databaseName:E,additionalFolder:i,migrationsFolder:n},strategy:new A({skipLogs:!1})})?(e.info("Catalog entities database preconnected"),"PRECONNECTED"):(e.warn("Catalog entities database preconnect failed"),"NOT_PRECONNECTED")}}export{a as DatabasePreconnectService};
