export const pgProtocols = ["postgres:", "postgresql:"]; export function isPgUrl(url: string): boolean { try { const urlObj = new URL(url); return pgProtocols.includes(urlObj.protocol); } catch { return false; } } export function parsePgUrl(url: string): { connectionString: string; readonly: boolean } { if (!isPgUrl(url)) throw new Error("Not a postgres: URL"); const urlObj = new URL(url); const readonly = (urlObj.searchParams.get("readonly") ?? "0") !== "0"; urlObj.searchParams.delete("readonly"); return { connectionString: urlObj.toString(), readonly }; }