mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-09 16:02:36 +01:00
Reviewed and verified at 69792ccbcf.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
12 lines
601 B
TypeScript
12 lines
601 B
TypeScript
export function resolveExternalTestDatabaseUrl(name: string, value = process.env[name]): string | undefined {
|
|
if (!value?.trim()) return undefined;
|
|
try {
|
|
const url = new URL(value);
|
|
const database = decodeURIComponent(url.pathname.slice(1));
|
|
if (['postgres:', 'postgresql:'].includes(url.protocol)
|
|
&& /^[a-zA-Z0-9_]+_test$/.test(database)
|
|
&& !['database', 'dbname', 'options'].some(key => url.searchParams.has(key))) return value;
|
|
} catch {}
|
|
throw new Error(`${name} must name a dedicated PostgreSQL database ending in _test, without database or options overrides`);
|
|
}
|