@prisma/cli-policy
Advanced tools
Comparing version 0.0.0-dev.202502171422 to 0.0.0-dev.202502171907
// @ts-check | ||
export async function resolvePrismaClient(/** @type {string} */ url, /** @type {Record<string, string>} */ env) { | ||
/** @type {any} **/ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore this is injected by the runtime | ||
const { prisma } = await import("./policy-path-to-prisma-client.mjs"); | ||
try { | ||
/** @type {any} **/ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore this is injected by the runtime | ||
let { prisma } = await import("./policy-path-to-prisma-client.mjs"); | ||
const engine = prisma._originalClient._engine; | ||
const dsName = Object.keys(engine.inlineDatasources ?? {})[0] ?? "db"; | ||
engine.config.overrideDatasources = { [dsName]: { url: env.DATABASE_URL } }; | ||
const dbURL = new URL(env.DATABASE_URL ?? "MISSING_DATABASE_URL"); | ||
const apiKey = dbURL.searchParams.get("api_key") ?? "MISSING_API_KEY"; | ||
const itx = new URL(url).searchParams.get("itx"); | ||
const itx = new URL(url).searchParams.get("itx"); | ||
if (itx) return await getItxPrismaClient(prisma, JSON.parse(itx)); | ||
const engine = prisma._originalClient._engine; | ||
const dsName = Object.keys(engine.inlineDatasources ?? {})[0] ?? "db"; | ||
engine.config.overrideDatasources = { [dsName]: { url: dbURL.toString() } }; | ||
return prisma; | ||
prisma = prisma.$withPlatformExtensions({ pulse: [{ apiKey }], accelerate: [] }); | ||
prisma = itx ? await getItxPrismaClient(prisma, JSON.parse(itx)) : prisma; | ||
return [null, prisma]; | ||
} catch (error) { | ||
return [error, null]; | ||
} | ||
} | ||
@@ -18,0 +26,0 @@ |
{ | ||
"name": "@prisma/cli-policy", | ||
"version": "0.0.0-dev.202502171422", | ||
"version": "0.0.0-dev.202502171907", | ||
"sideEffects": false, | ||
@@ -35,4 +35,4 @@ "description": "Policy CLI for Prisma", | ||
"common-cli-utils": "^0.0.0", | ||
"policy-deployer": "^0.0.0-dev.202502171422", | ||
"policy-playground": "^0.0.0-dev.202502171422" | ||
"policy-deployer": "^0.0.0-dev.202502171907", | ||
"policy-playground": "^0.0.0-dev.202502171907" | ||
}, | ||
@@ -39,0 +39,0 @@ "peerDependencies": { |
39028
1058