import{sql as a}from"drizzle-orm";import{getFirstRunRow as o}from"../../providers/database/utils/get-first-row.js";import{envConfig as i}from"../../config/env-config.js";import{SQLD_REMOTE_DATABASE_URL_NO_DEPLOYMENT_YET_VAR as E}from"../../constants/plugins/catalog-entities.js";class n{static#t="ORGANIZATION_ID";static#e="PROJECT_ID";organizationId;projectId;databaseClient;path;constructor(e){const t=this.isNonRemoteDatabaseMode();this.organizationId=this.#i(t),this.projectId=this.#n(t),this.databaseClient=e.client,this.path=e.path}async close(){await this.databaseClient.close()}async sync(){await this.databaseClient.sync()}async getTableSizeInBytes(e){const t=await this.databaseClient.client.run(a`
      SELECT COALESCE(SUM(pgsize), 0) AS bytes
      FROM dbstat
      WHERE name = ${e}
    `),s=o(t)?.bytes,r=Number(s??0);return Number.isFinite(r)?r:0}#i=e=>{const t=i.ORGANIZATION_ID;if(t)return t;if(e)return n.#t;throw new Error("ORGANIZATION_ID environment variable is required. Ensure it is set in your environment configuration.")};#n=e=>{const t=i.PROJECT_ID;if(t)return t;if(e)return n.#e;throw new Error("PROJECT_ID environment variable is required. Ensure it is set in your environment configuration.")};isNonRemoteDatabaseMode=()=>i.SQLD_REMOTE_DATABASE_URL===E||!i.SQLD_REMOTE_DATABASE_AUTH_TOKEN}export{n as BaseRepository};
