@prisma/composer-prisma-cloud 0.30.0-dev.3 → 0.30.0-dev.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/pack.mjs +1 -1
- package/dist/auth/pack.mjs.map +1 -1
- package/dist/auth/testing.mjs +1 -1
- package/dist/auth/testing.mjs.map +1 -1
- package/dist/buckets-main.mjs +101 -82
- package/dist/buckets-main.mjs.map +1 -1
- package/dist/control.mjs +3 -3
- package/dist/control.mjs.map +1 -1
- package/dist/local-target.mjs +614 -412
- package/dist/local-target.mjs.map +1 -1
- package/dist/postgres-main.mjs +324 -193
- package/dist/postgres-main.mjs.map +1 -1
- package/dist/{s3-credentials-resource-BZjtuopJ-azxxffwQ.mjs → s3-credentials-resource-D4jcpAZp-6qCQY8BD.mjs} +50 -10
- package/dist/{s3-credentials-resource-BZjtuopJ-azxxffwQ.mjs.map → s3-credentials-resource-D4jcpAZp-6qCQY8BD.mjs.map} +1 -1
- package/package.json +18 -18
- package/dist/segments-CA7TOJ1U-CoICbb95.mjs +0 -14
- package/dist/segments-CA7TOJ1U-CoICbb95.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-main.mjs","names":["getPort"],"sources":["../../../1-prisma-cloud/0-lowering/dev-emulators/dist/instance-name-BF6J_weL.mjs","../../../1-prisma-cloud/0-lowering/dev-emulators/dist/postgres-main.mjs"],"sourcesContent":["//#region src/instance-name.ts\n/**\n* `pcdev-<app>-<database-id>` instance-name derivation (local-dev spec § 2\n* `postgres-main.ts`): each half lowercased, every char outside `[a-z0-9]`\n* replaced by `-`, runs collapsed, the combined name trimmed to 63 chars.\n*\n* A separate, side-effect-free module (not defined inline in\n* `postgres-main.ts`) so it can be imported directly by tests without also\n* running that file's own `main()` — `postgres-main.ts` is a daemon\n* entrypoint script, always invoked as a subprocess, and calls `main()`\n* unconditionally at module load.\n*/\n/**\n* Deliberately linear, no ambiguous quantifiers: a per-character replace\n* (no `+`, so no run-length backtracking surface), a bounded-quantifier\n* collapse (`{2,}`, not alternation-with-quantifiers), and plain\n* index-walking for the leading/trailing trim instead of a regex — a\n* combined `+`-plus-alternation trim (`/^-+|-+$/g`) is exactly the shape\n* CodeQL's polynomial-ReDoS check flags, whether or not this particular\n* instance is provably safe.\n*/\nfunction slug(segment) {\n\tconst collapsed = segment.toLowerCase().replace(/[^a-z0-9]/g, \"-\").replace(/-{2,}/g, \"-\");\n\tlet start = 0;\n\tlet end = collapsed.length;\n\twhile (start < end && collapsed[start] === \"-\") start++;\n\twhile (end > start && collapsed[end - 1] === \"-\") end--;\n\treturn collapsed.slice(start, end);\n}\nfunction instanceNameFor(app, id) {\n\treturn `pcdev-${slug(app)}-${slug(id)}`.slice(0, 63);\n}\n//#endregion\nexport { slug as n, instanceNameFor as t };\n\n//# sourceMappingURL=instance-name-BF6J_weL.mjs.map","import { c as isPidAlive, l as readOwnVersion, m as readJsonFile, p as StateFile } from \"./daemon-D9BV062Q.mjs\";\nimport { t as isValidSegment } from \"./segments-CA7TOJ1U.mjs\";\nimport { t as instanceNameFor } from \"./instance-name-BF6J_weL.mjs\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport getPort, { portNumbers } from \"get-port\";\nimport * as http from \"node:http\";\n//#region src/prisma-dev-registry.ts\nfunction isStringKeyedRecord(value) {\n\treturn typeof value === \"object\" && value !== null;\n}\n/**\n* `ServerState` is exported by `@prisma/dev` as a class constructor, so its\n* static `scan` method lives on a function at runtime. Accept both that real\n* shape and an object-shaped compatible implementation.\n*/\nfunction isServerStateScanner(value) {\n\treturn (typeof value === \"object\" && value !== null || typeof value === \"function\") && \"scan\" in value && typeof value.scan === \"function\";\n}\n/** The port of a URL, when it names one explicitly. */\nfunction portOfUrl(value) {\n\ttry {\n\t\tconst port = Number(new URL(value).port);\n\t\treturn Number.isInteger(port) && port > 0 ? port : void 0;\n\t} catch {\n\t\treturn;\n\t}\n}\nlet scanUnavailableLogged = false;\n/**\n* Every port a FOREIGN persisted `@prisma/dev` server record claims. The\n* record named `ownInstanceName` is skipped — `@prisma/dev` exempts a\n* server's own record from port validation and prefers to reuse its ports,\n* so excluding them would move a persisted database off its recorded port.\n* Best-effort: when the internal surface is absent or unreadable this\n* degrades to an empty set (logged, so the degradation is visible), and\n* port picks fall back to the OS probe alone.\n*/\nasync function registryClaimedPorts(internalState, ownInstanceName) {\n\tconst ports = /* @__PURE__ */ new Set();\n\tconst scanHost = internalState.ServerState;\n\tif (!isServerStateScanner(scanHost)) {\n\t\tif (!scanUnavailableLogged) {\n\t\t\tscanUnavailableLogged = true;\n\t\t\tconsole.error(\"prisma-dev-registry: @prisma/dev exposes no usable ServerState.scan — port picks fall back to the OS probe alone\");\n\t\t}\n\t\treturn ports;\n\t}\n\ttry {\n\t\tconst records = await scanHost.scan({ onlyMetadata: true });\n\t\tif (!Array.isArray(records)) return ports;\n\t\tfor (const record of records) {\n\t\t\tif (!isStringKeyedRecord(record)) continue;\n\t\t\tif (record[\"name\"] === ownInstanceName) continue;\n\t\t\tfor (const key of [\n\t\t\t\t\"databasePort\",\n\t\t\t\t\"port\",\n\t\t\t\t\"shadowDatabasePort\"\n\t\t\t]) {\n\t\t\t\tconst port = record[key];\n\t\t\t\tif (typeof port === \"number\" && Number.isInteger(port) && port > 0) ports.add(port);\n\t\t\t}\n\t\t\tconst experimental = record[\"experimental\"];\n\t\t\tconst streams = isStringKeyedRecord(experimental) ? experimental[\"streams\"] : void 0;\n\t\t\tconst streamsUrl = isStringKeyedRecord(streams) ? streams[\"serverUrl\"] : void 0;\n\t\t\tif (typeof streamsUrl === \"string\") {\n\t\t\t\tconst port = portOfUrl(streamsUrl);\n\t\t\t\tif (port !== void 0) ports.add(port);\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tconsole.error(`prisma-dev-registry: failed to read the @prisma/dev server registry — port picks fall back to the OS probe alone (${error instanceof Error ? error.message : String(error)})`);\n\t}\n\treturn ports;\n}\n//#endregion\n//#region src/postgres-main.ts\n/**\n* The Postgres emulator daemon (local-dev spec § 2 `postgres-main.ts`): a\n* small local counterpart of hosted Postgres, hosting `@prisma/dev`'s\n* `startPrismaDevServer()` — one named, persistent server per `Database`\n* resource, several servers in this one daemon process. Loopback\n* `node:http` JSON admin API; state under its `--state-dir`.\n*\n* `@prisma/dev` is imported dynamically from a CALLER-RESOLVED path (each\n* admin request that needs it carries `prismaDevModulePath`): the local\n* target resolves it from Composer's own `@prisma/composer-prisma-cloud`\n* installation, which declares the version — this daemon has no\n* `@prisma/dev` dependency of its own.\n*\n* Runs as its own OS process, started by `daemon.ts`'s `ensureDaemon` via\n* `process.execPath <this file> --port <n> --state-dir <dir>`.\n*/\nconst MIN_DATABASE_PORT = 51300;\nconst MAX_DATABASE_PORT = 65535;\nconst APPS_STATE_MODE = 384;\n/** Spec § 2 step 5's pattern, applied to a fresh database-port allocation. */\nconst MAX_FRESH_PORT_CANDIDATES = 5;\n/**\n* A name refused as \"already running\" is retried a few times, each attempt\n* first waiting out the holder: a cold server boot takes seconds, and a\n* crashed holder's lock is only released once proper-lockfile's ~10s stale\n* threshold passes. Bounded so a genuinely stuck name still fails visibly\n* inside the dev command's own startup budget.\n*/\nconst MAX_ALREADY_RUNNING_RETRIES = 2;\nconst ALREADY_RUNNING_POLLS = 24;\nconst ALREADY_RUNNING_POLL_MS = 500;\nconst NOT_INSTALLED_MESSAGE = \"local dev needs @prisma/dev for its local Postgres emulator — @prisma/composer-prisma-cloud declares it as a dependency, but the given module path did not load; reinstall your dependencies.\";\nfunction maskCredentials(text) {\n\treturn text.replace(/:\\/\\/([^:@/\\s]+):[^@/\\s]+@/g, \"://$1:***@\");\n}\nfunction firstLine(text) {\n\treturn (text.split(\"\\n\")[0] ?? text).trim();\n}\nfunction isDatabaseRecord(value) {\n\treturn typeof value === \"object\" && value !== null && \"id\" in value && typeof value.id === \"string\" && \"instanceName\" in value && typeof value.instanceName === \"string\" && \"databasePort\" in value && typeof value.databasePort === \"number\" && \"url\" in value && typeof value.url === \"string\";\n}\nfunction isAppRecord(value) {\n\treturn typeof value === \"object\" && value !== null && \"databases\" in value && typeof value.databases === \"object\" && value.databases !== null && Object.values(value.databases).every(isDatabaseRecord);\n}\nfunction isAppsState(value) {\n\treturn typeof value === \"object\" && value !== null && Object.values(value).every(isAppRecord);\n}\nfunction isDatabaseBody(value) {\n\treturn typeof value === \"object\" && value !== null && \"prismaDevModulePath\" in value && typeof value.prismaDevModulePath === \"string\";\n}\nfunction isPrismaDevModule(value) {\n\treturn typeof value === \"object\" && value !== null && \"startPrismaDevServer\" in value && typeof value.startPrismaDevServer === \"function\";\n}\n/**\n* `@prisma/dev` exports a `PortNotAvailableError` class with a `readonly\n* port: number`, but the daemon dynamically imports the module from a\n* caller-given path while the class identity checked here would come from\n* whatever module graph THIS file's own bundle produced — two separate\n* instantiations of the same logical class, so `instanceof` doesn't match\n* across them (confirmed empirically: a real port conflict's `err\n* instanceof mod.PortNotAvailableError` is `false` even though the error IS\n* the port-conflict one). Duck-typing the documented shape — a `port`\n* number matching the candidate we just tried — is what actually survives\n* that boundary.\n*/\n/**\n* The port a start refusal is about, when it is one of THIS attempt's ports.\n* Duck-typed (`instanceof` fails across the dynamic-import boundary): every\n* `@prisma/dev` port refusal — not-available, requested-twice, and\n* belongs-to-another-server (its registry can claim a port no bind probe\n* sees) — carries the offending port as `.port`, and any of the four ports\n* we requested (database + the three aux listeners) can be the one refused.\n*/\nfunction portConflictOf(err, ports) {\n\tif (typeof err !== \"object\" || err === null || !(\"port\" in err)) return void 0;\n\tconst port = err.port;\n\treturn typeof port === \"number\" && ports.includes(port) ? port : void 0;\n}\nfunction isNameAlreadyTaken(err) {\n\treturn isStringKeyedRecord(err) && (err[\"name\"] === \"ServerAlreadyRunningError\" || err[\"name\"] === \"ServerStateAlreadyExistsError\");\n}\n/**\n* A dynamic `import()` failure's own message routinely names a SECOND path\n* (e.g. bun's \"Cannot find module '<target>' from '<importer>'\") — the\n* importer half is this daemon's own internal location, not anything the\n* caller gave us, and has no business in a response body. Rather than try\n* to scrub an arbitrary underlying message for every runtime's own error\n* phrasing, the resolution-failure case names only what the caller\n* supplied — the pinned message plus the given `prismaDevModulePath`, and\n* nothing else. (A DIFFERENT case — a module that resolves fine but whose\n* `startPrismaDevServer()` call itself fails — still surfaces its\n* underlying text verbatim, credential-masked, per spec § 2.)\n*/\nasync function importPrismaDev(prismaDevModulePath) {\n\tlet mod;\n\ttry {\n\t\tmod = await import(pathToFileURL(prismaDevModulePath).href);\n\t} catch {\n\t\tthrow new Error(`${NOT_INSTALLED_MESSAGE} (could not resolve \"${prismaDevModulePath}\")`);\n\t}\n\tif (!isPrismaDevModule(mod)) throw new Error(`${NOT_INSTALLED_MESSAGE} (\"${prismaDevModulePath}\" is not a @prisma/dev module)`);\n\treturn mod;\n}\nfunction isPrismaDevInternalStateModule(value) {\n\treturn isStringKeyedRecord(value) && typeof value[\"deleteServer\"] === \"function\" && typeof value[\"killServer\"] === \"function\" && typeof value[\"getServerStatus\"] === \"function\";\n}\nfunction readServerStatus(status) {\n\tif (!isStringKeyedRecord(status)) return {\n\t\tlive: false,\n\t\trecordExists: true,\n\t\tpid: void 0,\n\t\turl: void 0,\n\t\tdatabasePort: void 0\n\t};\n\tconst exports = status[\"exports\"];\n\tconst database = isStringKeyedRecord(exports) ? exports[\"database\"] : void 0;\n\tconst url = isStringKeyedRecord(database) ? database[\"connectionString\"] : void 0;\n\tconst pid = status[\"pid\"];\n\tconst databasePort = status[\"databasePort\"];\n\treturn {\n\t\tlive: status[\"status\"] === \"running\" || status[\"status\"] === \"starting_up\",\n\t\trecordExists: status[\"status\"] !== \"no_such_server\",\n\t\tpid: typeof pid === \"number\" ? pid : void 0,\n\t\turl: typeof url === \"string\" ? url : void 0,\n\t\tdatabasePort: typeof databasePort === \"number\" ? databasePort : void 0\n\t};\n}\nasync function serverStatusOf(internalState, instanceName) {\n\ttry {\n\t\treturn readServerStatus(await internalState.getServerStatus(instanceName));\n\t} catch {\n\t\treturn {\n\t\t\tlive: false,\n\t\t\trecordExists: true,\n\t\t\tpid: void 0,\n\t\t\turl: void 0,\n\t\t\tdatabasePort: void 0\n\t\t};\n\t}\n}\nconst CLOSE_SETTLE_ATTEMPTS = 40;\nconst CLOSE_SETTLE_DELAY_MS = 250;\n/** True once the named server's persisted state no longer claims it is live — the precondition for `deleteServer`, whose kill path targets the pid in that state, which for an in-daemon server is THIS DAEMON's own pid. */\nasync function settledAfterClose(internalState, instanceName) {\n\tfor (let attempt = 1; attempt <= CLOSE_SETTLE_ATTEMPTS; attempt += 1) {\n\t\tif (!(await serverStatusOf(internalState, instanceName)).live) return true;\n\t\tif (attempt < CLOSE_SETTLE_ATTEMPTS) await new Promise((resolve) => setTimeout(resolve, CLOSE_SETTLE_DELAY_MS));\n\t}\n\treturn false;\n}\n/**\n* `@prisma/dev`'s own package.json declares `./internal/state`, whose\n* `deleteServer(name)` actually removes a stateful server's persisted PGlite\n* data — `startPrismaDevServer`'s public surface only starts/closes a live\n* server, never deletes what a closed one left on disk. Resolved by reading\n* the SAME package's own `exports` map (walked up from the caller-given\n* entry path to find `@prisma/dev`'s `package.json`), never by guessing at\n* `dist/` file layout.\n*/\nasync function importPrismaDevInternalState(prismaDevModulePath) {\n\tlet dir = path.dirname(prismaDevModulePath);\n\tfor (;;) {\n\t\tconst pkgPath = path.join(dir, \"package.json\");\n\t\tif (fs.existsSync(pkgPath)) {\n\t\t\tconst pkg = JSON.parse(fs.readFileSync(pkgPath, \"utf8\"));\n\t\t\tif (isStringKeyedRecord(pkg) && pkg[\"name\"] === \"@prisma/dev\" && isStringKeyedRecord(pkg[\"exports\"])) {\n\t\t\t\tconst entry = pkg[\"exports\"][\"./internal/state\"];\n\t\t\t\tconst target = resolveExportTarget(entry);\n\t\t\t\tif (target === void 0) throw new Error(`\"@prisma/dev\" at \"${dir}\" does not declare an \"./internal/state\" export — cannot delete its persisted database data.`);\n\t\t\t\tconst mod = await import(pathToFileURL(path.join(dir, target)).href);\n\t\t\t\tif (isPrismaDevInternalStateModule(mod)) return mod;\n\t\t\t\tthrow new Error(`\"@prisma/dev\"'s \"./internal/state\" export at \"${dir}\" has no deleteServer.`);\n\t\t\t}\n\t\t}\n\t\tconst parent = path.dirname(dir);\n\t\tif (parent === dir) throw new Error(`could not find \"@prisma/dev\"'s package.json above \"${prismaDevModulePath}\".`);\n\t\tdir = parent;\n\t}\n}\nfunction resolveExportTarget(entry) {\n\tif (typeof entry === \"string\") return entry;\n\tif (!isStringKeyedRecord(entry)) return void 0;\n\tconst nested = entry[\"import\"] ?? entry[\"require\"] ?? entry[\"default\"];\n\tif (typeof nested === \"string\") return nested;\n\tif (isStringKeyedRecord(nested)) {\n\t\tconst def = nested[\"default\"];\n\t\tif (typeof def === \"string\") return def;\n\t}\n}\nfunction parseArgs(argv) {\n\tlet port;\n\tlet stateDir;\n\tfor (let i = 0; i < argv.length; i++) if (argv[i] === \"--port\") port = Number(argv[i + 1]);\n\telse if (argv[i] === \"--state-dir\") stateDir = argv[i + 1];\n\tif (port === void 0 || Number.isNaN(port)) throw new Error(\"postgres-main: --port <n> is required\");\n\tif (stateDir === void 0) throw new Error(\"postgres-main: --state-dir <dir> is required\");\n\treturn {\n\t\tport,\n\t\tstateDir\n\t};\n}\nfunction readBody(req) {\n\treturn new Promise((resolve, reject) => {\n\t\tconst chunks = [];\n\t\treq.on(\"data\", (chunk) => chunks.push(chunk));\n\t\treq.on(\"end\", () => resolve(Buffer.concat(chunks)));\n\t\treq.on(\"error\", reject);\n\t});\n}\nfunction main() {\n\tconst { port, stateDir } = parseArgs(process.argv.slice(2));\n\tconst ownVersion = readOwnVersion();\n\tconst appsJsonPath = path.join(stateDir, \"apps.json\");\n\tconst stateFile = new StateFile(appsJsonPath, APPS_STATE_MODE);\n\tlet state = {};\n\tconst runtimes = /* @__PURE__ */ new Map();\n\t/**\n\t* Server starts run ONE AT A TIME. `@prisma/dev`'s start is not\n\t* concurrency-safe within a process: two simultaneous calls pick their\n\t* ports without seeing each other and one fails with a port refusal\n\t* (verified directly — two concurrent starts with distinct, pinned\n\t* database ports fail; the same two started in sequence both succeed).\n\t* The daemon issues concurrent starts whenever an app converges more than\n\t* one database, which is what produced the port refusals, the retries\n\t* whose half-started servers held their own name's lock, and every\n\t* \"already running\" failure downstream of that.\n\t*/\n\tlet startQueue = Promise.resolve();\n\tfunction serializeStart(run) {\n\t\tconst next = startQueue.then(run, run);\n\t\tstartQueue = next.then(() => void 0, () => void 0);\n\t\treturn next;\n\t}\n\tfunction schedulePersist() {\n\t\tstateFile.write(state);\n\t}\n\tfunction getOrCreateApp(app) {\n\t\tlet appRec = state[app];\n\t\tif (!appRec) {\n\t\t\tappRec = { databases: {} };\n\t\t\tstate[app] = appRec;\n\t\t}\n\t\treturn appRec;\n\t}\n\tfunction usedDatabasePorts() {\n\t\tconst ports = /* @__PURE__ */ new Set();\n\t\tfor (const appRec of Object.values(state)) for (const db of Object.values(appRec.databases)) ports.add(db.databasePort);\n\t\treturn ports;\n\t}\n\tasync function smallestUnusedDatabasePort(min, alsoExclude = /* @__PURE__ */ new Set()) {\n\t\treturn getPort({\n\t\t\tport: portNumbers(min, MAX_DATABASE_PORT),\n\t\t\texclude: [...usedDatabasePorts(), ...alsoExclude]\n\t\t});\n\t}\n\tconst inflightEnsures = /* @__PURE__ */ new Map();\n\t/**\n\t* Names whose `startPrismaDevServer` call failed in THIS process for any\n\t* reason other than \"already running\". `@prisma/dev` acquires the name's\n\t* lock before it validates the requested ports, and a failure after that\n\t* point (a port refusal) propagates WITHOUT releasing the lock — so the\n\t* very next start of the same name in this process is refused as \"already\n\t* running\" by a holder that is this daemon's own dead attempt, and no\n\t* amount of waiting frees it. Membership here is what makes deleting that\n\t* lock provably safe: a name this process leaked cannot have been\n\t* acquired by anyone else since (the leak never releases).\n\t*/\n\tconst leakedStartNames = /* @__PURE__ */ new Set();\n\t/** Concurrent PUTs for the same database coalesce onto one start — a second `startPrismaDevServer` for a name whose first start is still booting fails as \"already running\". */\n\tfunction ensureDatabase(app, id, prismaDevModulePath) {\n\t\tconst instanceName = instanceNameFor(app, id);\n\t\tconst inflight = inflightEnsures.get(instanceName);\n\t\tif (inflight) return inflight;\n\t\tconst run = ensureDatabaseSerialized(app, id, prismaDevModulePath, instanceName).finally(() => {\n\t\t\tinflightEnsures.delete(instanceName);\n\t\t});\n\t\tinflightEnsures.set(instanceName, run);\n\t\treturn run;\n\t}\n\tasync function ensureDatabaseSerialized(app, id, prismaDevModulePath, instanceName) {\n\t\tconst appRec = getOrCreateApp(app);\n\t\tconst existingRecord = appRec.databases[id];\n\t\tconst runningServer = runtimes.get(instanceName);\n\t\tif (existingRecord && runningServer) return { url: existingRecord.url };\n\t\tconst prismaDev = await importPrismaDev(prismaDevModulePath);\n\t\tconst internalState = await importPrismaDevInternalState(prismaDevModulePath);\n\t\tconst recorded = await serverStatusOf(internalState, instanceName);\n\t\tif (recorded.live && recorded.pid !== void 0 && isPidAlive(recorded.pid)) {\n\t\t\tif (recorded.url !== void 0) {\n\t\t\t\tappRec.databases[id] = {\n\t\t\t\t\tid,\n\t\t\t\t\tinstanceName,\n\t\t\t\t\tdatabasePort: recorded.databasePort ?? portOfUrl(recorded.url) ?? MIN_DATABASE_PORT,\n\t\t\t\t\turl: recorded.url\n\t\t\t\t};\n\t\t\t\tschedulePersist();\n\t\t\t\treturn { url: recorded.url };\n\t\t\t}\n\t\t} else if (recorded.live) await internalState.killServer(instanceName).catch(() => void 0);\n\t\tconst isFreshAllocation = existingRecord === void 0;\n\t\tlet dbPort = existingRecord?.databasePort ?? 0;\n\t\tconst conflicted = /* @__PURE__ */ new Set();\n\t\tlet alreadyRunningRetries = 0;\n\t\tlet blindRetries = 0;\n\t\tfor (let attempt = 1;; attempt++) {\n\t\t\tconst auxPorts = [];\n\t\t\ttry {\n\t\t\t\tconst server = await serializeStart(async () => {\n\t\t\t\t\tconst registryPorts = await registryClaimedPorts(internalState, instanceName);\n\t\t\t\t\tif (isFreshAllocation) dbPort = await smallestUnusedDatabasePort(MIN_DATABASE_PORT, /* @__PURE__ */ new Set([...registryPorts, ...conflicted]));\n\t\t\t\t\tconst auxExclude = /* @__PURE__ */ new Set([\n\t\t\t\t\t\t...registryPorts,\n\t\t\t\t\t\t...conflicted,\n\t\t\t\t\t\tdbPort\n\t\t\t\t\t]);\n\t\t\t\t\tconst pickAux = async () => {\n\t\t\t\t\t\tconst port = await smallestUnusedDatabasePort(MIN_DATABASE_PORT, auxExclude);\n\t\t\t\t\t\tauxExclude.add(port);\n\t\t\t\t\t\tauxPorts.push(port);\n\t\t\t\t\t\treturn port;\n\t\t\t\t\t};\n\t\t\t\t\tconst httpPort = await pickAux();\n\t\t\t\t\tconst shadowPort = await pickAux();\n\t\t\t\t\tconst streamsPort = await pickAux();\n\t\t\t\t\treturn prismaDev.startPrismaDevServer({\n\t\t\t\t\t\tname: instanceName,\n\t\t\t\t\t\tdatabasePort: dbPort,\n\t\t\t\t\t\tport: httpPort,\n\t\t\t\t\t\tshadowDatabasePort: shadowPort,\n\t\t\t\t\t\tstreamsPort,\n\t\t\t\t\t\tpersistenceMode: \"stateful\"\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\tconst url = server.database.connectionString;\n\t\t\t\tleakedStartNames.delete(instanceName);\n\t\t\t\truntimes.set(instanceName, server);\n\t\t\t\tappRec.databases[id] = {\n\t\t\t\t\tid,\n\t\t\t\t\tinstanceName,\n\t\t\t\t\tdatabasePort: dbPort,\n\t\t\t\t\turl\n\t\t\t\t};\n\t\t\t\tschedulePersist();\n\t\t\t\treturn { url };\n\t\t\t} catch (err) {\n\t\t\t\tif (isNameAlreadyTaken(err) && alreadyRunningRetries < MAX_ALREADY_RUNNING_RETRIES) {\n\t\t\t\t\talreadyRunningRetries += 1;\n\t\t\t\t\tif (leakedStartNames.has(instanceName)) {\n\t\t\t\t\t\tif (!(await serverStatusOf(internalState, instanceName)).recordExists) {\n\t\t\t\t\t\t\tawait internalState.deleteServer(instanceName).catch(() => void 0);\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (let poll = 1; poll <= ALREADY_RUNNING_POLLS; poll += 1) {\n\t\t\t\t\t\tconst now = await serverStatusOf(internalState, instanceName);\n\t\t\t\t\t\tif (now.live && now.pid !== void 0 && isPidAlive(now.pid) && now.url !== void 0) {\n\t\t\t\t\t\t\tappRec.databases[id] = {\n\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\tinstanceName,\n\t\t\t\t\t\t\t\tdatabasePort: now.databasePort ?? portOfUrl(now.url) ?? dbPort,\n\t\t\t\t\t\t\t\turl: now.url\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tschedulePersist();\n\t\t\t\t\t\t\treturn { url: now.url };\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (now.live && (now.pid === void 0 || !isPidAlive(now.pid))) {\n\t\t\t\t\t\t\tawait internalState.killServer(instanceName).catch(() => void 0);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, ALREADY_RUNNING_POLL_MS));\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!isNameAlreadyTaken(err)) leakedStartNames.add(instanceName);\n\t\t\t\tconst conflictPort = portConflictOf(err, [dbPort, ...auxPorts]);\n\t\t\t\tif (!(conflictPort !== void 0 && attempt < MAX_FRESH_PORT_CANDIDATES && (conflictPort !== dbPort || isFreshAllocation))) {\n\t\t\t\t\tif (conflictPort === void 0 && !isNameAlreadyTaken(err) && blindRetries < 2) {\n\t\t\t\t\t\tblindRetries += 1;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst reason = err instanceof Error ? err.message : String(err);\n\t\t\t\t\tthrow new Error(`postgres emulator failed to start database \"${instanceName}\" on port ${String(dbPort)}: ${maskCredentials(firstLine(reason))}`);\n\t\t\t\t}\n\t\t\t\tconflicted.add(conflictPort);\n\t\t\t}\n\t\t}\n\t}\n\tasync function deleteApp(app, prismaDevModulePathHint) {\n\t\tconst appRec = state[app];\n\t\tif (!appRec) return;\n\t\tconst entries = Object.values(appRec.databases);\n\t\tfor (const db of entries) {\n\t\t\tconst server = runtimes.get(db.instanceName);\n\t\t\tif (server) {\n\t\t\t\tawait server.close().catch(() => void 0);\n\t\t\t\truntimes.delete(db.instanceName);\n\t\t\t}\n\t\t}\n\t\tif (entries.length > 0 && prismaDevModulePathHint) {\n\t\t\tconst internalState = await importPrismaDevInternalState(prismaDevModulePathHint);\n\t\t\tfor (const db of entries) {\n\t\t\t\tif (!runtimes.has(db.instanceName)) {\n\t\t\t\t\tif ((await serverStatusOf(internalState, db.instanceName)).pid !== process.pid) await internalState.killServer(db.instanceName).catch(() => void 0);\n\t\t\t\t}\n\t\t\t\tif (!await settledAfterClose(internalState, db.instanceName)) {\n\t\t\t\t\tconsole.error(`postgres-main: server \"${db.instanceName}\" still reports running after close — leaving its persisted data in place instead of risking a self-kill.`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tawait internalState.deleteServer(db.instanceName);\n\t\t\t}\n\t\t}\n\t\tdelete state[app];\n\t\tschedulePersist();\n\t}\n\tfunction json(res, status, body) {\n\t\tres.writeHead(status, { \"content-type\": \"application/json\" });\n\t\tres.end(JSON.stringify(body));\n\t}\n\tfunction text(res, status, body) {\n\t\tres.writeHead(status, { \"content-type\": \"text/plain; charset=utf-8\" });\n\t\tres.end(body);\n\t}\n\tfunction badSegment(res, segment) {\n\t\ttext(res, 400, `invalid path segment \"${segment}\": must match /^[a-z0-9][a-z0-9-]*$/ and be at most 63 characters`);\n\t}\n\tfunction databaseView(db) {\n\t\treturn {\n\t\t\tid: db.id,\n\t\t\turl: db.url,\n\t\t\tinstanceName: db.instanceName,\n\t\t\tdatabasePort: db.databasePort\n\t\t};\n\t}\n\t/** The most recently observed `prismaDevModulePath` for any database of `app` — DELETE has no body of its own to carry one. */\n\tconst recentPrismaDevModulePath = /* @__PURE__ */ new Map();\n\tfunction lastKnownPrismaDevModulePath(app) {\n\t\treturn recentPrismaDevModulePath.get(app);\n\t}\n\tasync function handleRequest(req, res) {\n\t\tconst url = new URL(req.url ?? \"/\", `http://127.0.0.1:${String(port)}`);\n\t\tconst method = req.method ?? \"GET\";\n\t\tconst segments = url.pathname.split(\"/\").filter((s) => s.length > 0).map((s) => decodeURIComponent(s));\n\t\tif (method === \"GET\" && segments.length === 1 && segments[0] === \"health\") return json(res, 200, { version: ownVersion });\n\t\tif (segments[0] === \"apps\" && segments.length >= 2) {\n\t\t\tconst app = segments[1];\n\t\t\tif (app === void 0 || !isValidSegment(app)) return badSegment(res, app ?? \"\");\n\t\t\tif (method === \"PUT\" && segments.length === 4 && segments[2] === \"databases\") {\n\t\t\t\tconst id = segments[3];\n\t\t\t\tif (id === void 0 || !isValidSegment(id)) return badSegment(res, id ?? \"\");\n\t\t\t\tconst raw = await readBody(req);\n\t\t\t\tlet parsed;\n\t\t\t\ttry {\n\t\t\t\t\tparsed = JSON.parse(raw.toString(\"utf8\"));\n\t\t\t\t} catch {\n\t\t\t\t\treturn text(res, 400, \"malformed JSON body\");\n\t\t\t\t}\n\t\t\t\tif (!isDatabaseBody(parsed)) return text(res, 400, \"malformed database body: expected { \\\"prismaDevModulePath\\\": string }\");\n\t\t\t\trecentPrismaDevModulePath.set(app, parsed.prismaDevModulePath);\n\t\t\t\treturn json(res, 200, await ensureDatabase(app, id, parsed.prismaDevModulePath));\n\t\t\t}\n\t\t\tif (method === \"GET\" && segments.length === 3 && segments[2] === \"databases\") {\n\t\t\t\tconst appRec = state[app];\n\t\t\t\treturn json(res, 200, appRec ? Object.values(appRec.databases).map(databaseView) : []);\n\t\t\t}\n\t\t\tif (method === \"DELETE\" && segments.length === 2) {\n\t\t\t\tawait deleteApp(app, lastKnownPrismaDevModulePath(app));\n\t\t\t\tres.writeHead(204);\n\t\t\t\tres.end();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tres.writeHead(404);\n\t\tres.end();\n\t}\n\tconst server = http.createServer((req, res) => {\n\t\thandleRequest(req, res).catch((err) => {\n\t\t\tif (!res.headersSent) res.writeHead(500, { \"content-type\": \"text/plain\" });\n\t\t\tres.end(err instanceof Error ? maskCredentials(err.message) : String(err));\n\t\t});\n\t});\n\tasync function shutdown() {\n\t\tfor (const server of runtimes.values()) await server.close().catch(() => void 0);\n\t\tawait stateFile.flush();\n\t\tserver.close();\n\t\tprocess.exit(0);\n\t}\n\tprocess.on(\"SIGTERM\", () => void shutdown());\n\tprocess.on(\"SIGINT\", () => void shutdown());\n\tprocess.on(\"unhandledRejection\", (reason) => {\n\t\tconsole.error(\"postgres-main: unhandled rejection from background work:\", reason instanceof Error ? maskCredentials(reason.stack ?? reason.message) : reason);\n\t});\n\tprocess.on(\"uncaughtException\", (err) => {\n\t\tconsole.error(\"postgres-main: uncaught exception from background work:\", err instanceof Error ? maskCredentials(err.stack ?? err.message) : err);\n\t});\n\treadJsonFile(appsJsonPath, isAppsState).then((loaded) => {\n\t\tif (loaded) state = loaded;\n\t\tserver.listen(port, \"127.0.0.1\", () => {\n\t\t\tconsole.log(`[dev-emulators] postgres-main listening on 127.0.0.1:${String(port)}`);\n\t\t});\n\t}).catch((err) => {\n\t\tconsole.error(\"postgres-main: failed to load state\", err);\n\t\tprocess.exit(1);\n\t});\n}\nmain();\n//#endregion\nexport {};\n\n//# sourceMappingURL=postgres-main.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAS,KAAK,SAAS;CACtB,MAAM,YAAY,QAAQ,YAAY,CAAC,CAAC,QAAQ,cAAc,GAAG,CAAC,CAAC,QAAQ,UAAU,GAAG;CACxF,IAAI,QAAQ;CACZ,IAAI,MAAM,UAAU;CACpB,OAAO,QAAQ,OAAO,UAAU,WAAW,KAAK;CAChD,OAAO,MAAM,SAAS,UAAU,MAAM,OAAO,KAAK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ACzE,IAAI,IAAI,eAAe,QAAQ,gBAAgB,IAAI,OAAO,IAAI,OAAO,GAAG,CAAC;EAC1E,CAAC;CACF,CAAC;CACD,eAAe,WAAW;EACzB,KAAK,MAAM,UAAU,SAAS,OAAO,GAAG,MAAM,OAAO,MAAM,CAAC,CAAC,YAAY,KAAK,CAAC;EAC/E,MAAM,UAAU,MAAM;EACtB,OAAO,MAAM;EACb,QAAQ,KAAK,CAAC;CACf;CACA,QAAQ,GAAG,iBAAiB,KAAK,SAAS,CAAC;CAC3C,QAAQ,GAAG,gBAAgB,KAAK,SAAS,CAAC;CAC1C,QAAQ,GAAG,uBAAuB,WAAW;EAC5C,QAAQ,MAAM,4DAA4D,kBAAkB,QAAQ,gBAAgB,OAAO,SAAS,OAAO,OAAO,IAAI,MAAM;CAC7J,CAAC;CACD,QAAQ,GAAG,sBAAsB,QAAQ;EACxC,QAAQ,MAAM,2DAA2D,eAAe,QAAQ,gBAAgB,IAAI,SAAS,IAAI,OAAO,IAAI,GAAG;CAChJ,CAAC;CACD,aAAa,cAAc,WAAW,CAAC,CAAC,MAAM,WAAW;EACxD,IAAI,QAAQ,QAAQ;EACpB,OAAO,OAAO,MAAM,mBAAmB;GACtC,QAAQ,IAAI,wDAAwD,OAAO,IAAI,GAAG;EACnF,CAAC;CACF,CAAC,CAAC,CAAC,OAAO,QAAQ;EACjB,QAAQ,MAAM,uCAAuC,GAAG;EACxD,QAAQ,KAAK,CAAC;CACf,CAAC;AACF;AACA,KAAK"}
|
|
1
|
+
{"version":3,"file":"postgres-main.mjs","names":["getPort"],"sources":["../../../1-prisma-cloud/0-lowering/dev-emulators/dist/postgres-main.mjs"],"sourcesContent":["import { c as isPidAlive, l as readOwnVersion, m as readJsonFile, p as StateFile } from \"./daemon-D9BV062Q.mjs\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport getPort, { clearLockedPorts, portNumbers } from \"get-port\";\nimport { randomBytes } from \"node:crypto\";\nimport * as http from \"node:http\";\n//#region src/prisma-dev-registry.ts\nfunction isStringKeyedRecord(value) {\n\treturn typeof value === \"object\" && value !== null;\n}\n/**\n* `ServerState` is exported by `@prisma/dev` as a class constructor, so its\n* static `scan` method lives on a function at runtime. Accept both that real\n* shape and an object-shaped compatible implementation.\n*/\nfunction isServerStateScanner(value) {\n\treturn (typeof value === \"object\" && value !== null || typeof value === \"function\") && \"scan\" in value && typeof value.scan === \"function\";\n}\n/** The port of a URL, when it names one explicitly. */\nfunction portOfUrl(value) {\n\ttry {\n\t\tconst port = Number(new URL(value).port);\n\t\treturn Number.isInteger(port) && port > 0 ? port : void 0;\n\t} catch {\n\t\treturn;\n\t}\n}\nlet scanUnavailableLogged = false;\n/**\n* Every port a FOREIGN persisted `@prisma/dev` server record claims. The\n* record named `ownInstanceName` is skipped — `@prisma/dev` exempts a\n* server's own record from port validation and prefers to reuse its ports,\n* so excluding them would move a persisted database off its recorded port.\n* Best-effort: when the internal surface is absent or unreadable this\n* degrades to an empty set (logged, so the degradation is visible), and\n* port picks fall back to the OS probe alone.\n*/\nasync function registryClaimedPorts(internalState, ownInstanceName) {\n\tconst ports = /* @__PURE__ */ new Set();\n\tconst scanHost = internalState.ServerState;\n\tif (!isServerStateScanner(scanHost)) {\n\t\tif (!scanUnavailableLogged) {\n\t\t\tscanUnavailableLogged = true;\n\t\t\tconsole.error(\"prisma-dev-registry: @prisma/dev exposes no usable ServerState.scan — port picks fall back to the OS probe alone\");\n\t\t}\n\t\treturn ports;\n\t}\n\ttry {\n\t\tconst records = await scanHost.scan({ onlyMetadata: true });\n\t\tif (!Array.isArray(records)) return ports;\n\t\tfor (const record of records) {\n\t\t\tif (!isStringKeyedRecord(record)) continue;\n\t\t\tif (record[\"name\"] === ownInstanceName) continue;\n\t\t\tfor (const key of [\n\t\t\t\t\"databasePort\",\n\t\t\t\t\"port\",\n\t\t\t\t\"shadowDatabasePort\"\n\t\t\t]) {\n\t\t\t\tconst port = record[key];\n\t\t\t\tif (typeof port === \"number\" && Number.isInteger(port) && port > 0) ports.add(port);\n\t\t\t}\n\t\t\tconst experimental = record[\"experimental\"];\n\t\t\tconst streams = isStringKeyedRecord(experimental) ? experimental[\"streams\"] : void 0;\n\t\t\tconst streamsUrl = isStringKeyedRecord(streams) ? streams[\"serverUrl\"] : void 0;\n\t\t\tif (typeof streamsUrl === \"string\") {\n\t\t\t\tconst port = portOfUrl(streamsUrl);\n\t\t\t\tif (port !== void 0) ports.add(port);\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tconsole.error(`prisma-dev-registry: failed to read the @prisma/dev server registry — port picks fall back to the OS probe alone (${error instanceof Error ? error.message : String(error)})`);\n\t}\n\treturn ports;\n}\n//#endregion\n//#region src/postgres-main.ts\n/**\n* The Postgres emulator daemon (local-dev spec § 2 `postgres-main.ts`): a\n* small local counterpart of hosted Postgres, hosting `@prisma/dev`'s\n* `startPrismaDevServer()` — one named, persistent server per database\n* instance, several servers in this one daemon process. Instances are keyed\n* by ids this daemon generates; a server is named after its instance's id,\n* and `@prisma/dev` keeps its data under that name in its own data\n* directory. Labels are stored and returned verbatim, never interpreted.\n* Stopping an instance shuts its server down and keeps its data and port.\n* Loopback `node:http` JSON admin API; state under its `--state-dir`.\n*\n* `@prisma/dev` is imported dynamically from a CALLER-RESOLVED path (each\n* admin request that needs it carries `prismaDevModulePath`): the local\n* target resolves it from Composer's own `@prisma/composer-prisma-cloud`\n* installation, which declares the version — this daemon has no\n* `@prisma/dev` dependency of its own.\n*\n* Runs as its own OS process, started by `daemon.ts`'s `ensureDaemon` via\n* `process.execPath <this file> --port <n> --state-dir <dir>`.\n*/\nconst MIN_DATABASE_PORT = 51300;\nconst MAX_DATABASE_PORT = 65535;\nconst STATE_MODE = 384;\n/** Spec § 2 step 5's pattern, applied to a fresh database-port allocation. */\nconst MAX_FRESH_PORT_CANDIDATES = 5;\n/**\n* A name refused as \"already running\" is retried a few times, each attempt\n* first waiting out the holder: a cold server boot takes seconds, and a\n* crashed holder's lock is only released once proper-lockfile's ~10s stale\n* threshold passes. Bounded so a genuinely stuck name still fails visibly\n* inside the dev command's own startup budget.\n*/\nconst MAX_ALREADY_RUNNING_RETRIES = 2;\nconst ALREADY_RUNNING_POLLS = 24;\nconst ALREADY_RUNNING_POLL_MS = 500;\nconst NOT_INSTALLED_MESSAGE = \"local dev needs @prisma/dev for its local Postgres emulator, and the given module path did not load; reinstall your dependencies.\";\nfunction maskCredentials(text) {\n\treturn text.replace(/:\\/\\/([^:@/\\s]+):[^@/\\s]+@/g, \"://$1:***@\");\n}\nfunction firstLine(text) {\n\treturn (text.split(\"\\n\")[0] ?? text).trim();\n}\nconst INSTANCE_ID_RE = /^db_[0-9a-f]{16}$/;\nfunction newInstanceId() {\n\treturn `db_${randomBytes(8).toString(\"hex\")}`;\n}\nfunction serverNameFor(id) {\n\treturn `pcdev-${id}`;\n}\nfunction isStringRecord(value) {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value) && Object.values(value).every((v) => typeof v === \"string\");\n}\nfunction isPort(value) {\n\treturn typeof value === \"number\" && Number.isInteger(value) && value >= 1 && value <= MAX_DATABASE_PORT;\n}\nfunction isDatabaseRecord(value) {\n\treturn typeof value === \"object\" && value !== null && \"id\" in value && typeof value.id === \"string\" && \"labels\" in value && isStringRecord(value.labels) && \"serverName\" in value && typeof value.serverName === \"string\" && \"port\" in value && isPort(value.port) && \"url\" in value && typeof value.url === \"string\" && \"prismaDevModulePath\" in value && typeof value.prismaDevModulePath === \"string\";\n}\nfunction isInstancesState(value) {\n\treturn typeof value === \"object\" && value !== null && \"instances\" in value && typeof value.instances === \"object\" && value.instances !== null && Object.values(value.instances).every(isDatabaseRecord) && \"discardedServers\" in value && Array.isArray(value.discardedServers) && value.discardedServers.every((name) => typeof name === \"string\");\n}\nfunction isCreateBody(value) {\n\treturn typeof value === \"object\" && value !== null && \"labels\" in value && isStringRecord(value.labels) && (!(\"port\" in value) || value.port === void 0 || isPort(value.port)) && \"prismaDevModulePath\" in value && typeof value.prismaDevModulePath === \"string\";\n}\nfunction isStartBody(value) {\n\treturn isIdsBody(value) && \"prismaDevModulePath\" in value && typeof value.prismaDevModulePath === \"string\";\n}\nfunction isIdsBody(value) {\n\treturn typeof value === \"object\" && value !== null && \"ids\" in value && Array.isArray(value.ids) && value.ids.every((id) => typeof id === \"string\");\n}\n/** Every `@prisma/dev` server name an earlier version's state file lists; an unreadable file lists none. */\nfunction serverNamesInEarlierState(raw) {\n\tlet parsed;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch {\n\t\treturn [];\n\t}\n\tif (!isStringKeyedRecord(parsed)) return [];\n\treturn Object.values(parsed).flatMap((group) => {\n\t\tconst databases = isStringKeyedRecord(group) ? group[\"databases\"] : void 0;\n\t\tif (!isStringKeyedRecord(databases)) return [];\n\t\treturn Object.values(databases).flatMap((db) => {\n\t\t\tconst name = isStringKeyedRecord(db) ? db[\"instanceName\"] : void 0;\n\t\t\treturn typeof name === \"string\" ? [name] : [];\n\t\t});\n\t});\n}\nfunction isPrismaDevModule(value) {\n\treturn typeof value === \"object\" && value !== null && \"startPrismaDevServer\" in value && typeof value.startPrismaDevServer === \"function\";\n}\n/**\n* `@prisma/dev` exports a `PortNotAvailableError` class with a `readonly\n* port: number`, but the daemon dynamically imports the module from a\n* caller-given path while the class identity checked here would come from\n* whatever module graph THIS file's own bundle produced — two separate\n* instantiations of the same logical class, so `instanceof` doesn't match\n* across them (confirmed empirically: a real port conflict's `err\n* instanceof mod.PortNotAvailableError` is `false` even though the error IS\n* the port-conflict one). Duck-typing the documented shape — a `port`\n* number matching the candidate we just tried — is what actually survives\n* that boundary.\n*/\n/**\n* The port a start refusal is about, when it is one of THIS attempt's ports.\n* Duck-typed (`instanceof` fails across the dynamic-import boundary): every\n* `@prisma/dev` port refusal — not-available, requested-twice, and\n* belongs-to-another-server (its registry can claim a port no bind probe\n* sees) — carries the offending port as `.port`, and any of the four ports\n* we requested (database + the three aux listeners) can be the one refused.\n*/\nfunction portConflictOf(err, ports) {\n\tif (typeof err !== \"object\" || err === null || !(\"port\" in err)) return void 0;\n\tconst port = err.port;\n\treturn typeof port === \"number\" && ports.includes(port) ? port : void 0;\n}\nfunction isNameAlreadyTaken(err) {\n\treturn isStringKeyedRecord(err) && (err[\"name\"] === \"ServerAlreadyRunningError\" || err[\"name\"] === \"ServerStateAlreadyExistsError\");\n}\n/**\n* A dynamic `import()` failure's own message routinely names a SECOND path\n* (e.g. bun's \"Cannot find module '<target>' from '<importer>'\") — the\n* importer half is this daemon's own internal location, not anything the\n* caller gave us, and has no business in a response body. Rather than try\n* to scrub an arbitrary underlying message for every runtime's own error\n* phrasing, the resolution-failure case names only what the caller\n* supplied — the pinned message plus the given `prismaDevModulePath`, and\n* nothing else. (A DIFFERENT case — a module that resolves fine but whose\n* `startPrismaDevServer()` call itself fails — still surfaces its\n* underlying text verbatim, credential-masked, per spec § 2.)\n*/\nasync function importPrismaDev(prismaDevModulePath) {\n\tlet mod;\n\ttry {\n\t\tmod = await import(pathToFileURL(prismaDevModulePath).href);\n\t} catch {\n\t\tthrow new Error(`${NOT_INSTALLED_MESSAGE} (could not resolve \"${prismaDevModulePath}\")`);\n\t}\n\tif (!isPrismaDevModule(mod)) throw new Error(`${NOT_INSTALLED_MESSAGE} (\"${prismaDevModulePath}\" is not a @prisma/dev module)`);\n\treturn mod;\n}\nfunction isPrismaDevInternalStateModule(value) {\n\treturn isStringKeyedRecord(value) && typeof value[\"deleteServer\"] === \"function\" && typeof value[\"killServer\"] === \"function\" && typeof value[\"getServerStatus\"] === \"function\";\n}\nfunction readServerStatus(status) {\n\tif (!isStringKeyedRecord(status)) return {\n\t\tlive: false,\n\t\trecordExists: true,\n\t\tpid: void 0,\n\t\turl: void 0,\n\t\tdatabasePort: void 0\n\t};\n\tconst exports = status[\"exports\"];\n\tconst database = isStringKeyedRecord(exports) ? exports[\"database\"] : void 0;\n\tconst url = isStringKeyedRecord(database) ? database[\"connectionString\"] : void 0;\n\tconst pid = status[\"pid\"];\n\tconst databasePort = status[\"databasePort\"];\n\treturn {\n\t\tlive: status[\"status\"] === \"running\" || status[\"status\"] === \"starting_up\",\n\t\trecordExists: status[\"status\"] !== \"no_such_server\",\n\t\tpid: typeof pid === \"number\" ? pid : void 0,\n\t\turl: typeof url === \"string\" ? url : void 0,\n\t\tdatabasePort: typeof databasePort === \"number\" ? databasePort : void 0\n\t};\n}\nasync function serverStatusOf(internalState, instanceName) {\n\ttry {\n\t\treturn readServerStatus(await internalState.getServerStatus(instanceName));\n\t} catch {\n\t\treturn {\n\t\t\tlive: false,\n\t\t\trecordExists: true,\n\t\t\tpid: void 0,\n\t\t\turl: void 0,\n\t\t\tdatabasePort: void 0\n\t\t};\n\t}\n}\nconst CLOSE_SETTLE_ATTEMPTS = 40;\nconst CLOSE_SETTLE_DELAY_MS = 250;\n/** True once the named server's persisted state no longer claims it is live — the precondition for `deleteServer`, whose kill path targets the pid in that state, which for an in-daemon server is THIS DAEMON's own pid. */\nasync function settledAfterClose(internalState, instanceName) {\n\tfor (let attempt = 1; attempt <= CLOSE_SETTLE_ATTEMPTS; attempt += 1) {\n\t\tif (!(await serverStatusOf(internalState, instanceName)).live) return true;\n\t\tif (attempt < CLOSE_SETTLE_ATTEMPTS) await new Promise((resolve) => setTimeout(resolve, CLOSE_SETTLE_DELAY_MS));\n\t}\n\treturn false;\n}\n/**\n* `@prisma/dev`'s own package.json declares `./internal/state`, whose\n* `deleteServer(name)` actually removes a stateful server's persisted PGlite\n* data — `startPrismaDevServer`'s public surface only starts/closes a live\n* server, never deletes what a closed one left on disk. Resolved by reading\n* the SAME package's own `exports` map (walked up from the caller-given\n* entry path to find `@prisma/dev`'s `package.json`), never by guessing at\n* `dist/` file layout.\n*/\nasync function importPrismaDevInternalState(prismaDevModulePath) {\n\tlet dir = path.dirname(prismaDevModulePath);\n\tfor (;;) {\n\t\tconst pkgPath = path.join(dir, \"package.json\");\n\t\tif (fs.existsSync(pkgPath)) {\n\t\t\tconst pkg = JSON.parse(fs.readFileSync(pkgPath, \"utf8\"));\n\t\t\tif (isStringKeyedRecord(pkg) && pkg[\"name\"] === \"@prisma/dev\" && isStringKeyedRecord(pkg[\"exports\"])) {\n\t\t\t\tconst entry = pkg[\"exports\"][\"./internal/state\"];\n\t\t\t\tconst target = resolveExportTarget(entry);\n\t\t\t\tif (target === void 0) throw new Error(`\"@prisma/dev\" at \"${dir}\" does not declare an \"./internal/state\" export — cannot delete its persisted database data.`);\n\t\t\t\tconst mod = await import(pathToFileURL(path.join(dir, target)).href);\n\t\t\t\tif (isPrismaDevInternalStateModule(mod)) return mod;\n\t\t\t\tthrow new Error(`\"@prisma/dev\"'s \"./internal/state\" export at \"${dir}\" has no deleteServer.`);\n\t\t\t}\n\t\t}\n\t\tconst parent = path.dirname(dir);\n\t\tif (parent === dir) throw new Error(`could not find \"@prisma/dev\"'s package.json above \"${prismaDevModulePath}\".`);\n\t\tdir = parent;\n\t}\n}\nfunction resolveExportTarget(entry) {\n\tif (typeof entry === \"string\") return entry;\n\tif (!isStringKeyedRecord(entry)) return void 0;\n\tconst nested = entry[\"import\"] ?? entry[\"require\"] ?? entry[\"default\"];\n\tif (typeof nested === \"string\") return nested;\n\tif (isStringKeyedRecord(nested)) {\n\t\tconst def = nested[\"default\"];\n\t\tif (typeof def === \"string\") return def;\n\t}\n}\nfunction parseArgs(argv) {\n\tlet port;\n\tlet stateDir;\n\tfor (let i = 0; i < argv.length; i++) if (argv[i] === \"--port\") port = Number(argv[i + 1]);\n\telse if (argv[i] === \"--state-dir\") stateDir = argv[i + 1];\n\tif (port === void 0 || Number.isNaN(port)) throw new Error(\"postgres-main: --port <n> is required\");\n\tif (stateDir === void 0) throw new Error(\"postgres-main: --state-dir <dir> is required\");\n\treturn {\n\t\tport,\n\t\tstateDir\n\t};\n}\nfunction readBody(req) {\n\treturn new Promise((resolve, reject) => {\n\t\tconst chunks = [];\n\t\treq.on(\"data\", (chunk) => chunks.push(chunk));\n\t\treq.on(\"end\", () => resolve(Buffer.concat(chunks)));\n\t\treq.on(\"error\", reject);\n\t});\n}\nfunction main() {\n\tconst { port, stateDir } = parseArgs(process.argv.slice(2));\n\tconst ownVersion = readOwnVersion();\n\tconst statePath = path.join(stateDir, \"instances.json\");\n\tconst stateFile = new StateFile(statePath, STATE_MODE);\n\tlet state = {\n\t\tinstances: {},\n\t\tdiscardedServers: []\n\t};\n\tconst runtimes = /* @__PURE__ */ new Map();\n\t/** Instances whose server another live process holds: running, but with no handle in this one. */\n\tconst adopted = /* @__PURE__ */ new Set();\n\t/**\n\t* Server starts run ONE AT A TIME. `@prisma/dev`'s start is not\n\t* concurrency-safe within a process: two simultaneous calls pick their\n\t* ports without seeing each other and one fails with a port refusal\n\t* (verified directly — two concurrent starts with distinct, pinned\n\t* database ports fail; the same two started in sequence both succeed).\n\t*/\n\tlet startQueue = Promise.resolve();\n\tfunction serializeStart(run) {\n\t\tconst next = startQueue.then(run, run);\n\t\tstartQueue = next.then(() => void 0, () => void 0);\n\t\treturn next;\n\t}\n\tfunction schedulePersist() {\n\t\tstateFile.write(state);\n\t}\n\tfunction heldPorts() {\n\t\treturn new Set(Object.values(state.instances).map((db) => db.port));\n\t}\n\tasync function smallestUnusedPort(exclude) {\n\t\treturn getPort({\n\t\t\tport: portNumbers(MIN_DATABASE_PORT, MAX_DATABASE_PORT),\n\t\t\texclude: [...heldPorts(), ...exclude]\n\t\t});\n\t}\n\t/** The requested port when no instance or record holds it and it is bindable; otherwise the smallest such port in the database range. */\n\tasync function allocatePort(requested, exclude) {\n\t\tconst held = heldPorts();\n\t\tif (requested !== void 0 && !held.has(requested) && !exclude.has(requested)) {\n\t\t\tconst given = await getPort({\n\t\t\t\tport: requested,\n\t\t\t\texclude: [...held, ...exclude]\n\t\t\t});\n\t\t\tif (given === requested) return given;\n\t\t}\n\t\treturn smallestUnusedPort(exclude);\n\t}\n\t/** In-flight starts and stops per instance, so a stop, a start or a delete never overlaps another on the same server. */\n\tconst inflight = /* @__PURE__ */ new Map();\n\tfunction exclusive(id, run) {\n\t\tconst next = (inflight.get(id) ?? Promise.resolve()).then(run, run);\n\t\tconst settled = next.then(() => void 0, () => void 0);\n\t\tinflight.set(id, settled);\n\t\tsettled.then(() => {\n\t\t\tif (inflight.get(id) === settled) inflight.delete(id);\n\t\t});\n\t\treturn next;\n\t}\n\t/**\n\t* Names whose `startPrismaDevServer` call failed in THIS process for any\n\t* reason other than \"already running\". `@prisma/dev` acquires the name's\n\t* lock before it validates the requested ports, and a failure after that\n\t* point (a port refusal) propagates WITHOUT releasing the lock — so the\n\t* very next start of the same name in this process is refused as \"already\n\t* running\" by a holder that is this daemon's own dead attempt, and no\n\t* amount of waiting frees it. Membership here is what makes deleting that\n\t* lock provably safe: a name this process leaked cannot have been\n\t* acquired by anyone else since (the leak never releases).\n\t*/\n\tconst leakedStartNames = /* @__PURE__ */ new Set();\n\t/**\n\t* Starts the server for `serverName`. A fresh allocation picks its port\n\t* (preferring `requestedPort`) inside the serialized section and may move\n\t* to another port on a refusal; a start of an existing instance is pinned\n\t* to its port, because dependents' environments carry its URL.\n\t*/\n\tasync function startServer(opts) {\n\t\tconst { serverName, prismaDevModulePath } = opts;\n\t\tconst prismaDev = await importPrismaDev(prismaDevModulePath);\n\t\tconst internalState = await importPrismaDevInternalState(prismaDevModulePath);\n\t\tawait discardEarlierServers(internalState);\n\t\tconst recorded = await serverStatusOf(internalState, serverName);\n\t\tif (recorded.live && recorded.pid !== void 0 && isPidAlive(recorded.pid)) {\n\t\t\tif (recorded.url !== void 0) return {\n\t\t\t\turl: recorded.url,\n\t\t\t\tport: recorded.databasePort ?? portOfUrl(recorded.url) ?? opts.pinnedPort ?? 0\n\t\t\t};\n\t\t} else if (recorded.live) await internalState.killServer(serverName).catch(() => void 0);\n\t\tconst isFreshAllocation = opts.pinnedPort === void 0;\n\t\tlet dbPort = opts.pinnedPort ?? 0;\n\t\tconst conflicted = /* @__PURE__ */ new Set();\n\t\tlet alreadyRunningRetries = 0;\n\t\tlet blindRetries = 0;\n\t\tfor (let attempt = 1;; attempt++) {\n\t\t\tconst auxPorts = [];\n\t\t\ttry {\n\t\t\t\tconst server = await serializeStart(async () => {\n\t\t\t\t\tconst registryPorts = await registryClaimedPorts(internalState, serverName);\n\t\t\t\t\tif (isFreshAllocation) dbPort = await allocatePort(attempt === 1 ? opts.requestedPort : void 0, /* @__PURE__ */ new Set([...registryPorts, ...conflicted]));\n\t\t\t\t\tconst auxExclude = /* @__PURE__ */ new Set([\n\t\t\t\t\t\t...registryPorts,\n\t\t\t\t\t\t...conflicted,\n\t\t\t\t\t\tdbPort\n\t\t\t\t\t]);\n\t\t\t\t\tconst pickAux = async () => {\n\t\t\t\t\t\tconst picked = await smallestUnusedPort(auxExclude);\n\t\t\t\t\t\tauxExclude.add(picked);\n\t\t\t\t\t\tauxPorts.push(picked);\n\t\t\t\t\t\treturn picked;\n\t\t\t\t\t};\n\t\t\t\t\tconst httpPort = await pickAux();\n\t\t\t\t\tconst shadowPort = await pickAux();\n\t\t\t\t\tconst streamsPort = await pickAux();\n\t\t\t\t\treturn prismaDev.startPrismaDevServer({\n\t\t\t\t\t\tname: serverName,\n\t\t\t\t\t\tdatabasePort: dbPort,\n\t\t\t\t\t\tport: httpPort,\n\t\t\t\t\t\tshadowDatabasePort: shadowPort,\n\t\t\t\t\t\tstreamsPort,\n\t\t\t\t\t\tpersistenceMode: \"stateful\"\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\tleakedStartNames.delete(serverName);\n\t\t\t\treturn {\n\t\t\t\t\turl: server.database.connectionString,\n\t\t\t\t\tport: dbPort,\n\t\t\t\t\tserver\n\t\t\t\t};\n\t\t\t} catch (err) {\n\t\t\t\tif (isNameAlreadyTaken(err) && alreadyRunningRetries < MAX_ALREADY_RUNNING_RETRIES) {\n\t\t\t\t\talreadyRunningRetries += 1;\n\t\t\t\t\tif (leakedStartNames.has(serverName)) {\n\t\t\t\t\t\tif (!(await serverStatusOf(internalState, serverName)).recordExists) {\n\t\t\t\t\t\t\tawait internalState.deleteServer(serverName).catch(() => void 0);\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (let poll = 1; poll <= ALREADY_RUNNING_POLLS; poll += 1) {\n\t\t\t\t\t\tconst now = await serverStatusOf(internalState, serverName);\n\t\t\t\t\t\tif (now.live && now.pid !== void 0 && isPidAlive(now.pid) && now.url !== void 0) return {\n\t\t\t\t\t\t\turl: now.url,\n\t\t\t\t\t\t\tport: now.databasePort ?? portOfUrl(now.url) ?? dbPort\n\t\t\t\t\t\t};\n\t\t\t\t\t\tif (now.live && (now.pid === void 0 || !isPidAlive(now.pid))) {\n\t\t\t\t\t\t\tawait internalState.killServer(serverName).catch(() => void 0);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, ALREADY_RUNNING_POLL_MS));\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!isNameAlreadyTaken(err)) leakedStartNames.add(serverName);\n\t\t\t\tconst conflictPort = portConflictOf(err, [dbPort, ...auxPorts]);\n\t\t\t\tif (!(conflictPort !== void 0 && attempt < MAX_FRESH_PORT_CANDIDATES && (conflictPort !== dbPort || isFreshAllocation))) {\n\t\t\t\t\tif (conflictPort === void 0 && !isNameAlreadyTaken(err) && blindRetries < 2) {\n\t\t\t\t\t\tblindRetries += 1;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst reason = err instanceof Error ? err.message : String(err);\n\t\t\t\t\tthrow new Error(`postgres emulator failed to start database \"${serverName}\" on port ${String(dbPort)}: ${maskCredentials(firstLine(reason))}`);\n\t\t\t\t}\n\t\t\t\tconflicted.add(conflictPort);\n\t\t\t}\n\t\t}\n\t}\n\t/**\n\t* Deletes the data of servers an earlier version of this emulator created,\n\t* once a request brings a `@prisma/dev` module to do it with. Best effort:\n\t* a server another live process still serves, or one whose delete fails,\n\t* is tried again on the next request.\n\t*/\n\tlet discarding;\n\tfunction discardEarlierServers(internalState) {\n\t\tif (state.discardedServers.length === 0) return Promise.resolve();\n\t\tdiscarding ??= deleteEarlierServers(internalState).finally(() => {\n\t\t\tdiscarding = void 0;\n\t\t});\n\t\treturn discarding;\n\t}\n\tasync function deleteEarlierServers(internalState) {\n\t\tconst remaining = [];\n\t\tfor (const name of state.discardedServers) try {\n\t\t\tconst owner = await serverStatusOf(internalState, name);\n\t\t\tif (owner.live && owner.pid !== void 0 && isPidAlive(owner.pid)) {\n\t\t\t\tremaining.push(name);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (owner.live) await internalState.killServer(name).catch(() => void 0);\n\t\t\tawait internalState.deleteServer(name);\n\t\t} catch (err) {\n\t\t\tconsole.error(`postgres-main: could not delete the data of \"${name}\", left by an earlier version: ${err instanceof Error ? err.message : String(err)}`);\n\t\t\tremaining.push(name);\n\t\t}\n\t\tstate.discardedServers = remaining;\n\t\tschedulePersist();\n\t}\n\tasync function createInstance(body) {\n\t\tconst id = newInstanceId();\n\t\tconst serverName = serverNameFor(id);\n\t\tlet started;\n\t\ttry {\n\t\t\tstarted = await startServer({\n\t\t\t\tserverName,\n\t\t\t\tprismaDevModulePath: body.prismaDevModulePath,\n\t\t\t\t...body.port !== void 0 ? { requestedPort: body.port } : {}\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tawait discardFailedServer(serverName, body.prismaDevModulePath);\n\t\t\tthrow err;\n\t\t}\n\t\tconst record = {\n\t\t\tid,\n\t\t\tlabels: { ...body.labels },\n\t\t\tserverName,\n\t\t\tport: started.port,\n\t\t\turl: started.url,\n\t\t\tprismaDevModulePath: body.prismaDevModulePath\n\t\t};\n\t\tif (started.server) runtimes.set(id, started.server);\n\t\telse adopted.add(id);\n\t\tstate.instances[id] = record;\n\t\tawait stateFile.write(state);\n\t\treturn record;\n\t}\n\t/**\n\t* A failed create records no instance, so nothing will use its server name\n\t* again. A start that failed after `@prisma/dev` took the name's lock leaves\n\t* the name's directory behind with no record; remove it.\n\t*/\n\tasync function discardFailedServer(serverName, prismaDevModulePath) {\n\t\tif (!leakedStartNames.has(serverName)) return;\n\t\ttry {\n\t\t\tconst internalState = await importPrismaDevInternalState(prismaDevModulePath);\n\t\t\tif (!(await serverStatusOf(internalState, serverName)).recordExists) await internalState.deleteServer(serverName);\n\t\t\tleakedStartNames.delete(serverName);\n\t\t} catch {}\n\t}\n\tfunction isRunning(id) {\n\t\treturn runtimes.has(id) || adopted.has(id);\n\t}\n\tfunction startInstance(db, prismaDevModulePath) {\n\t\treturn exclusive(db.id, async () => {\n\t\t\tdb.prismaDevModulePath = prismaDevModulePath;\n\t\t\tif (isRunning(db.id)) return;\n\t\t\tconst started = await startServer({\n\t\t\t\tserverName: db.serverName,\n\t\t\t\tprismaDevModulePath,\n\t\t\t\tpinnedPort: db.port\n\t\t\t});\n\t\t\tdb.url = started.url;\n\t\t\tif (started.server) runtimes.set(db.id, started.server);\n\t\t\telse adopted.add(db.id);\n\t\t\tschedulePersist();\n\t\t});\n\t}\n\t/** Shuts the server down and keeps its data. */\n\tasync function closeServer(db) {\n\t\tconst server = runtimes.get(db.id);\n\t\tif (server) {\n\t\t\tawait server.close().catch(() => void 0);\n\t\t\truntimes.delete(db.id);\n\t\t\treturn;\n\t\t}\n\t\tif (!adopted.has(db.id)) return;\n\t\tconst internalState = await importPrismaDevInternalState(db.prismaDevModulePath);\n\t\tif ((await serverStatusOf(internalState, db.serverName)).pid !== process.pid) await internalState.killServer(db.serverName).catch(() => void 0);\n\t\tadopted.delete(db.id);\n\t}\n\tfunction stopInstance(db) {\n\t\treturn exclusive(db.id, () => closeServer(db));\n\t}\n\t/** `prismaDevModulePath` is the caller's: the one the database was last started with may since have been removed. */\n\tfunction deleteInstance(db, prismaDevModulePath) {\n\t\treturn exclusive(db.id, async () => {\n\t\t\tif (prismaDevModulePath !== void 0) db.prismaDevModulePath = prismaDevModulePath;\n\t\t\tawait closeServer(db);\n\t\t\tconst internalState = await importPrismaDevInternalState(db.prismaDevModulePath);\n\t\t\tif (await settledAfterClose(internalState, db.serverName)) await internalState.deleteServer(db.serverName);\n\t\t\telse console.error(`postgres-main: server \"${db.serverName}\" still reports running after close — leaving its persisted data in place instead of risking a self-kill.`);\n\t\t\tdelete state.instances[db.id];\n\t\t\tawait stateFile.write(state);\n\t\t\tclearLockedPorts();\n\t\t});\n\t}\n\tfunction json(res, status, body) {\n\t\tres.writeHead(status, { \"content-type\": \"application/json\" });\n\t\tres.end(JSON.stringify(body));\n\t}\n\tfunction text(res, status, body) {\n\t\tres.writeHead(status, { \"content-type\": \"text/plain; charset=utf-8\" });\n\t\tres.end(body);\n\t}\n\tfunction noContent(res) {\n\t\tres.writeHead(204);\n\t\tres.end();\n\t}\n\tasync function readJsonBody(req) {\n\t\tconst raw = await readBody(req);\n\t\ttry {\n\t\t\treturn JSON.parse(raw.toString(\"utf8\"));\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t}\n\tfunction instanceView(db) {\n\t\treturn {\n\t\t\tid: db.id,\n\t\t\tlabels: db.labels,\n\t\t\tport: db.port,\n\t\t\turl: db.url,\n\t\t\tstatus: isRunning(db.id) ? \"running\" : \"stopped\"\n\t\t};\n\t}\n\tfunction unknownInstances(res, ids) {\n\t\ttext(res, 404, `no such instance: ${ids.map((id) => `\"${id}\"`).join(\", \")}`);\n\t}\n\tasync function handleRequest(req, res) {\n\t\tconst url = new URL(req.url ?? \"/\", `http://127.0.0.1:${String(port)}`);\n\t\tconst method = req.method ?? \"GET\";\n\t\tconst segments = url.pathname.split(\"/\").filter((s) => s.length > 0).map((s) => decodeURIComponent(s));\n\t\tif (method === \"GET\" && segments.length === 1 && segments[0] === \"health\") return json(res, 200, { version: ownVersion });\n\t\tif (segments[0] !== \"instances\") {\n\t\t\tres.writeHead(404);\n\t\t\tres.end();\n\t\t\treturn;\n\t\t}\n\t\tif (segments.length === 1) {\n\t\t\tif (method === \"GET\") return json(res, 200, Object.values(state.instances).map(instanceView));\n\t\t\tif (method === \"POST\") {\n\t\t\t\tconst body = await readJsonBody(req);\n\t\t\t\tif (!isCreateBody(body)) return text(res, 400, \"malformed body: expected { \\\"labels\\\": Record<string, string>, \\\"port\\\"?: number, \\\"prismaDevModulePath\\\": string }\");\n\t\t\t\treturn json(res, 201, instanceView(await createInstance(body)));\n\t\t\t}\n\t\t}\n\t\tif (method === \"POST\" && segments.length === 2 && segments[1] === \"start\") {\n\t\t\tconst body = await readJsonBody(req);\n\t\t\tif (!isStartBody(body)) return text(res, 400, \"malformed body: expected { \\\"ids\\\": string[], \\\"prismaDevModulePath\\\": string }\");\n\t\t\tconst unknown = body.ids.filter((id) => state.instances[id] === void 0);\n\t\t\tif (unknown.length > 0) return unknownInstances(res, unknown);\n\t\t\tfor (const id of body.ids) {\n\t\t\t\tconst db = state.instances[id];\n\t\t\t\tif (db) await startInstance(db, body.prismaDevModulePath);\n\t\t\t}\n\t\t\treturn noContent(res);\n\t\t}\n\t\tif (method === \"POST\" && segments.length === 2 && segments[1] === \"stop\") {\n\t\t\tconst body = await readJsonBody(req);\n\t\t\tif (!isIdsBody(body)) return text(res, 400, \"malformed body: expected { \\\"ids\\\": string[] }\");\n\t\t\tfor (const id of body.ids) {\n\t\t\t\tconst db = state.instances[id];\n\t\t\t\tif (db) await stopInstance(db);\n\t\t\t}\n\t\t\treturn noContent(res);\n\t\t}\n\t\tconst id = segments[1];\n\t\tif (id !== void 0 && !INSTANCE_ID_RE.test(id)) return text(res, 400, `invalid instance id \"${id}\"`);\n\t\tconst db = id === void 0 ? void 0 : state.instances[id];\n\t\tif (method === \"DELETE\" && segments.length === 2) {\n\t\t\tconst body = await readJsonBody(req);\n\t\t\tconst modulePath = isStringKeyedRecord(body) ? body[\"prismaDevModulePath\"] : void 0;\n\t\t\tif (db) await deleteInstance(db, typeof modulePath === \"string\" ? modulePath : void 0);\n\t\t\treturn noContent(res);\n\t\t}\n\t\tif (!db) return unknownInstances(res, id === void 0 ? [] : [id]);\n\t\tif (method === \"GET\" && segments.length === 2) return json(res, 200, instanceView(db));\n\t\tres.writeHead(404);\n\t\tres.end();\n\t}\n\tconst server = http.createServer((req, res) => {\n\t\thandleRequest(req, res).catch((err) => {\n\t\t\tif (!res.headersSent) res.writeHead(500, { \"content-type\": \"text/plain\" });\n\t\t\tres.end(err instanceof Error ? maskCredentials(err.message) : String(err));\n\t\t});\n\t});\n\tasync function shutdown() {\n\t\tfor (const live of runtimes.values()) await live.close().catch(() => void 0);\n\t\tawait stateFile.flush();\n\t\tserver.close();\n\t\tprocess.exit(0);\n\t}\n\tprocess.on(\"SIGTERM\", () => void shutdown());\n\tprocess.on(\"SIGINT\", () => void shutdown());\n\tprocess.on(\"unhandledRejection\", (reason) => {\n\t\tconsole.error(\"postgres-main: unhandled rejection from background work:\", reason instanceof Error ? maskCredentials(reason.stack ?? reason.message) : reason);\n\t});\n\tprocess.on(\"uncaughtException\", (err) => {\n\t\tconsole.error(\"postgres-main: uncaught exception from background work:\", err instanceof Error ? maskCredentials(err.stack ?? err.message) : err);\n\t});\n\tloadState(stateDir, statePath).then((loaded) => {\n\t\tstate = loaded;\n\t\tschedulePersist();\n\t\tserver.listen(port, \"127.0.0.1\", () => {\n\t\t\tconsole.log(`[dev-emulators] postgres-main listening on 127.0.0.1:${String(port)}`);\n\t\t});\n\t}).catch((err) => {\n\t\tconsole.error(\"postgres-main: failed to load state\", err);\n\t\tprocess.exit(1);\n\t});\n}\n/**\n* This version's state, plus the servers named in any other JSON state file\n* in the state directory, which an earlier version wrote; those files are\n* removed. Local dev state is never migrated; the servers' data is deleted\n* on the first request that can (see `discardEarlierServers`).\n*/\nasync function loadState(stateDir, statePath) {\n\tconst loaded = await readJsonFile(statePath, isInstancesState) ?? {\n\t\tinstances: {},\n\t\tdiscardedServers: []\n\t};\n\tconst files = await fs.promises.readdir(stateDir).catch(() => []);\n\tfor (const file of files.map((name) => path.join(stateDir, name))) {\n\t\tif (!file.endsWith(\".json\") || file === statePath) continue;\n\t\tconst names = serverNamesInEarlierState(await fs.promises.readFile(file, \"utf8\").catch(() => \"\"));\n\t\tloaded.discardedServers = [.../* @__PURE__ */ new Set([...loaded.discardedServers, ...names])];\n\t\tawait fs.promises.rm(file, { force: true });\n\t}\n\treturn loaded;\n}\nmain();\n//#endregion\nexport {};\n\n//# sourceMappingURL=postgres-main.mjs.map"],"mappings":";;;;;;;;AAQA,SAAS,oBAAoB,OAAO;CACnC,OAAO,OAAO,UAAU,YAAY,UAAU;AAC/C;;;;;;AAMA,SAAS,qBAAqB,OAAO;CACpC,QAAQ,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAO,UAAU,eAAe,UAAU,SAAS,OAAO,MAAM,SAAS;AACjI;;AAEA,SAAS,UAAU,OAAO;CACzB,IAAI;EACH,MAAM,OAAO,OAAO,IAAI,IAAI,KAAK,CAAC,CAAC,IAAI;EACvC,OAAO,OAAO,UAAU,IAAI,KAAK,OAAO,IAAI,OAAO,KAAK;CACzD,QAAQ;EACP;CACD;AACD;AACA,IAAI,wBAAwB;;;;;;;;;;AAU5B,eAAe,qBAAqB,eAAe,iBAAiB;CACnE,MAAM,wBAAwB,IAAI,IAAI;CACtC,MAAM,WAAW,cAAc;CAC/B,IAAI,CAAC,qBAAqB,QAAQ,GAAG;EACpC,IAAI,CAAC,uBAAuB;GAC3B,wBAAwB;GACxB,QAAQ,MAAM,kHAAkH;EACjI;EACA,OAAO;CACR;CACA,IAAI;EACH,MAAM,UAAU,MAAM,SAAS,KAAK,EAAE,cAAc,KAAK,CAAC;EAC1D,IAAI,CAAC,MAAM,QAAQ,OAAO,GAAG,OAAO;EACpC,KAAK,MAAM,UAAU,SAAS;GAC7B,IAAI,CAAC,oBAAoB,MAAM,GAAG;GAClC,IAAI,OAAO,YAAY,iBAAiB;GACxC,KAAK,MAAM,OAAO;IACjB;IACA;IACA;GACD,GAAG;IACF,MAAM,OAAO,OAAO;IACpB,IAAI,OAAO,SAAS,YAAY,OAAO,UAAU,IAAI,KA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AAG,sBAAsB,QAAQ;EACxC,QAAQ,MAAM,2DAA2D,eAAe,QAAQ,gBAAgB,IAAI,SAAS,IAAI,OAAO,IAAI,GAAG;CAChJ,CAAC;CACD,UAAU,UAAU,SAAS,CAAC,CAAC,MAAM,WAAW;EAC/C,QAAQ;EACR,gBAAgB;EAChB,OAAO,OAAO,MAAM,mBAAmB;GACtC,QAAQ,IAAI,wDAAwD,OAAO,IAAI,GAAG;EACnF,CAAC;CACF,CAAC,CAAC,CAAC,OAAO,QAAQ;EACjB,QAAQ,MAAM,uCAAuC,GAAG;EACxD,QAAQ,KAAK,CAAC;CACf,CAAC;AACF;;;;;;;AAOA,eAAe,UAAU,UAAU,WAAW;CAC7C,MAAM,SAAS,MAAM,aAAa,WAAW,gBAAgB,KAAK;EACjE,WAAW,CAAC;EACZ,kBAAkB,CAAC;CACpB;CACA,MAAM,QAAQ,MAAM,GAAG,SAAS,QAAQ,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC;CAChE,KAAK,MAAM,QAAQ,MAAM,KAAK,SAAS,KAAK,KAAK,UAAU,IAAI,CAAC,GAAG;EAClE,IAAI,CAAC,KAAK,SAAS,OAAO,KAAK,SAAS,WAAW;EACnD,MAAM,QAAQ,0BAA0B,MAAM,GAAG,SAAS,SAAS,MAAM,MAAM,CAAC,CAAC,YAAY,EAAE,CAAC;EAChG,OAAO,mBAAmB,CAAC,mBAAmB,IAAI,IAAI,CAAC,GAAG,OAAO,kBAAkB,GAAG,KAAK,CAAC,CAAC;EAC7F,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,OAAO,KAAK,CAAC;CAC3C;CACA,OAAO;AACR;AACA,KAAK"}
|
|
@@ -27,8 +27,8 @@ import { createPostgresControlClient } from "@prisma/orm-postgres/control";
|
|
|
27
27
|
import { readRef } from "@prisma/orm-toolchain/migration-tools/refs";
|
|
28
28
|
import { APP_SPACE_ID, readContractSpaceHeadRef, spaceMigrationDirectory, spaceRefsDirectory } from "@prisma/orm-toolchain/migration-tools/spaces";
|
|
29
29
|
import pg from "pg";
|
|
30
|
-
//#region ../../1-prisma-cloud/0-lowering/lowering/dist/credentials-
|
|
31
|
-
var version = "0.30.0-dev.
|
|
30
|
+
//#region ../../1-prisma-cloud/0-lowering/lowering/dist/credentials-Cy9vBvgt.mjs
|
|
31
|
+
var version = "0.30.0-dev.4";
|
|
32
32
|
/**
|
|
33
33
|
* The Prisma service token used to authenticate Management API calls. Kept
|
|
34
34
|
* as a Redacted value so it never lands in logs or error output.
|
|
@@ -72,7 +72,7 @@ const deploySourceHeaders = () => ({
|
|
|
72
72
|
*/
|
|
73
73
|
const managementApiBaseUrl = (env) => env !== void 0 ? normalizeBaseUrl(env["PRISMA_API_URL"] || env["PRISMA_MANAGEMENT_API_URL"] || DEFAULT_BASE_URL) : Config$1.String("PRISMA_API_URL").pipe(Config$1.orElse(() => Config$1.String("PRISMA_MANAGEMENT_API_URL")), Config$1.withDefault(DEFAULT_BASE_URL), Effect.flatMap(normalizeBaseUrl));
|
|
74
74
|
//#endregion
|
|
75
|
-
//#region ../../1-prisma-cloud/0-lowering/lowering/dist/database-url-claim-
|
|
75
|
+
//#region ../../1-prisma-cloud/0-lowering/lowering/dist/database-url-claim-BDsci7kB.mjs
|
|
76
76
|
/**
|
|
77
77
|
* The typed Prisma Management API client, built once from the resolved
|
|
78
78
|
* credentials. Providers yield this in their outer Effect and call it inside
|
|
@@ -501,7 +501,7 @@ function mintKeyPair() {
|
|
|
501
501
|
};
|
|
502
502
|
}
|
|
503
503
|
//#endregion
|
|
504
|
-
//#region ../../1-prisma-cloud/1-extensions/target/dist/s3-credentials-resource-
|
|
504
|
+
//#region ../../1-prisma-cloud/1-extensions/target/dist/s3-credentials-resource-D4jcpAZp.mjs
|
|
505
505
|
const PRISMA_CLOUD_EXTENSION_ID = "@prisma/composer-prisma-cloud";
|
|
506
506
|
/** Accepts exactly what Alchemy's own `--stage` validation accepts (pinned 2.0.0-beta.59, `Cli/commands/_shared.ts`), rewritten without overlapping quantifiers so it cannot backtrack catastrophically. Asserted before a Branch id is exposed as a stage. */
|
|
507
507
|
const ALCHEMY_STAGE_PATTERN = /^[a-z0-9][-_a-z0-9]*$/i;
|
|
@@ -697,6 +697,14 @@ function containerDescriptor(deps) {
|
|
|
697
697
|
function missingBranchId(instance) {
|
|
698
698
|
throw new Error(`${PRISMA_CLOUD_EXTENSION_ID}: a named-stage ("${instance.input.stage}") container instance is missing its branchId — this is a bug in ensure/locate/deserialize.`);
|
|
699
699
|
}
|
|
700
|
+
/** The `displayName` of a service's `Prisma.App`. Local dev reserves each service's emulator port under this name before converge, so both must come from here. */
|
|
701
|
+
function serviceAppName(address) {
|
|
702
|
+
return address;
|
|
703
|
+
}
|
|
704
|
+
/** The `name` of a database's `Prisma.Database` and a bucket's `Prisma.Bucket`. Local dev records each one's emulator instance under this name before converge, and the local providers look it up by it, so both must come from here. */
|
|
705
|
+
function resourceName(nodeId) {
|
|
706
|
+
return nodeId;
|
|
707
|
+
}
|
|
700
708
|
/**
|
|
701
709
|
* The `GeneratedParam` Alchemy resource — generates a random value ONCE at
|
|
702
710
|
* create and keeps it STABLE across deploys, so an unchanged service no-ops on
|
|
@@ -738,10 +746,6 @@ const generatedParamProviderService = {
|
|
|
738
746
|
};
|
|
739
747
|
/** The `GeneratedParam` provider layer — merged into the extension descriptor's `providers()`. */
|
|
740
748
|
const GeneratedParamProvider = () => Provider.effect(GeneratedParam, Effect.succeed(generatedParamProviderService));
|
|
741
|
-
/** The `displayName` of a service's `Prisma.App`. Local dev reserves each service's emulator port under this name before converge, so both must come from here. */
|
|
742
|
-
function serviceAppName(address) {
|
|
743
|
-
return address;
|
|
744
|
-
}
|
|
745
749
|
/**
|
|
746
750
|
* Resolves a `postgres` resource's `prisma.config.ts` path to the
|
|
747
751
|
* project facts the deploy needs (ADR-0022, slice 2): the emitted
|
|
@@ -921,6 +925,23 @@ function decideMigrationAction(marker, ref) {
|
|
|
921
925
|
return "migrate";
|
|
922
926
|
}
|
|
923
927
|
/**
|
|
928
|
+
* Whether the database at `url` is already at `ref` by its marker, read
|
|
929
|
+
* without applying anything. A database with no marker, such as one created
|
|
930
|
+
* empty, is not.
|
|
931
|
+
*/
|
|
932
|
+
async function isAtTargetRef(url, ref) {
|
|
933
|
+
const client = createPostgresControlClient({
|
|
934
|
+
connection: normalizeSslMode(url),
|
|
935
|
+
extensions: []
|
|
936
|
+
});
|
|
937
|
+
await client.connect();
|
|
938
|
+
try {
|
|
939
|
+
return decideMigrationAction(await client.readMarker(), ref) === "noop";
|
|
940
|
+
} finally {
|
|
941
|
+
await client.close();
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
924
945
|
* Bring the database at `url` to the target ref via PN's authored migrations.
|
|
925
946
|
* Reads the live marker, decides no-op / migrate
|
|
926
947
|
* ({@link decideMigrationAction}), applies, and throws a typed
|
|
@@ -1042,6 +1063,25 @@ const ormMigrationProviderService = {
|
|
|
1042
1063
|
/** The `OrmMigration` provider layer — merged into the extension descriptor's `providers()`. */
|
|
1043
1064
|
const OrmMigrationProvider = () => Provider.effect(OrmMigration, Effect.succeed(ormMigrationProviderService));
|
|
1044
1065
|
/**
|
|
1066
|
+
* Local dev's `OrmMigration` provider: the same service, plus a diff that
|
|
1067
|
+
* asks for an update when the database is not at the target by its marker.
|
|
1068
|
+
* A local database the emulator had to create again starts empty on the
|
|
1069
|
+
* same URL, so nothing in the props changes and Alchemy would otherwise skip
|
|
1070
|
+
* the migration. Reading the marker is one connection per converge.
|
|
1071
|
+
*/
|
|
1072
|
+
const LocalOrmMigrationProvider = () => Provider.effect(OrmMigration, Effect.succeed({
|
|
1073
|
+
...ormMigrationProviderService,
|
|
1074
|
+
diff: ({ olds }) => Effect.tryPromise({
|
|
1075
|
+
try: async () => {
|
|
1076
|
+
return await isAtTargetRef(olds.url, {
|
|
1077
|
+
hash: olds.targetHash,
|
|
1078
|
+
invariants: olds.invariants
|
|
1079
|
+
}).catch(() => false) ? void 0 : { action: "update" };
|
|
1080
|
+
},
|
|
1081
|
+
catch: (cause) => cause
|
|
1082
|
+
})
|
|
1083
|
+
}));
|
|
1084
|
+
/**
|
|
1045
1085
|
* The `PgWarm` Alchemy resource (slice 3, FT-5226) — warm a freshly-provisioned
|
|
1046
1086
|
* Prisma Postgres database at apply-time so it is ready by deploy-end, and the
|
|
1047
1087
|
* first real connection (a service's runtime client, or the migration) doesn't
|
|
@@ -1161,6 +1201,6 @@ const s3CredentialsProviderService = {
|
|
|
1161
1201
|
/** The `S3Credentials` provider layer — merged into the extension descriptor's `providers()`. */
|
|
1162
1202
|
const S3CredentialsProvider = () => Provider.effect(S3Credentials, Effect.succeed(s3CredentialsProviderService));
|
|
1163
1203
|
//#endregion
|
|
1164
|
-
export {
|
|
1204
|
+
export { PrismaApiError as A, managementApiBaseUrl as B, Providers as C, appAfterEnvironment as D, ServiceKeyProvider as E, drivePagesAsync as F, layer as I, resolveDefaultBranchId as L, call as M, claimDatabaseUrlKeys as N, isWithin as O, collectPages as P, PrismaCredentials as R, mintKeyPair as S, ServiceKey as T, resolveOrmConfig as _, OrmMigrationProvider as a, serviceAppName as b, PgWarmProvider as c, S3CredentialsProvider as d, collectPreflightNames as f, prismaCloudContainerOf as g, packHeadRefHashes as h, OrmMigration as i, RESERVED_DATABASE_URL_KEYS as j, ManagementClient as k, PrismaCloudContainer as l, deserialize as m, GeneratedParamProvider as n, PRISMA_CLOUD_EXTENSION_ID as o, containerDescriptor as p, LocalOrmMigrationProvider as r, PgWarm as s, GeneratedParam as t, S3Credentials as u, resolveTargetRef as v, providers as w, targetStorageHash as x, resourceName as y, fromEnv as z };
|
|
1165
1205
|
|
|
1166
|
-
//# sourceMappingURL=s3-credentials-resource-
|
|
1206
|
+
//# sourceMappingURL=s3-credentials-resource-D4jcpAZp-6qCQY8BD.mjs.map
|