@prisma/cli 8.0.0-rc.5-dev.63 → 8.0.0-rc.5-dev.64

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.
Files changed (2) hide show
  1. package/dist/cli.js +57 -2
  2. package/package.json +7 -7
package/dist/cli.js CHANGED
@@ -14226,6 +14226,52 @@ function runTelemetry(inputs) {
14226
14226
  //#region src/auth/legacy-state.ts
14227
14227
  const LEGACY_PLACEHOLDER_NAME = "Unknown workspace";
14228
14228
  /**
14229
+ * The sessions re-serialized in the legacy store's record shape. The
14230
+ * 3.x CLI reads `tokens` from auth.json (`data.tokens || []`, silently
14231
+ * empty for any other shape), so a write that dropped the key made
14232
+ * every session invisible to `@prisma/cli@latest` on the same machine
14233
+ * the moment this CLI first mutated the file (#204). Sessions without
14234
+ * a refresh token still mirror; the legacy reader skips them, exactly
14235
+ * as it skips its own unrefreshable records.
14236
+ */
14237
+ function legacyTokensMirror(sessions) {
14238
+ return sessions.map((session) => ({
14239
+ workspaceId: session.workspaceId,
14240
+ token: session.token,
14241
+ ...session.refreshToken === void 0 ? {} : { refreshToken: session.refreshToken }
14242
+ }));
14243
+ }
14244
+ /**
14245
+ * Keeps auth.context.json's `activeWorkspaceId` — the pointer the 3.x
14246
+ * CLI selects its session with — in step with `currentWorkspaceId`.
14247
+ * The rest of the context file (the remembered-workspace name map) is
14248
+ * preserved verbatim; only the pointer moves.
14249
+ */
14250
+ async function syncLegacyContext(authFilePath, currentWorkspaceId) {
14251
+ const contextFilePath = getAuthContextFilePath(authFilePath);
14252
+ const context = await readLegacyContext(contextFilePath);
14253
+ if (context.exists && context.activeWorkspaceId === currentWorkspaceId) return;
14254
+ if (!context.exists && currentWorkspaceId === null) return;
14255
+ const raw = await fs.readFile(contextFilePath, "utf8").catch(() => null);
14256
+ let workspaces = {};
14257
+ if (raw !== null) try {
14258
+ const parsed = JSON.parse(raw);
14259
+ if (typeof parsed.workspaces === "object" && parsed.workspaces !== null && !Array.isArray(parsed.workspaces)) workspaces = parsed.workspaces;
14260
+ } catch {}
14261
+ const tempPath = `${contextFilePath}.${randomUUID()}.tmp`;
14262
+ const payload = `${JSON.stringify({
14263
+ activeWorkspaceId: currentWorkspaceId,
14264
+ workspaces
14265
+ }, null, 2)}\n`;
14266
+ try {
14267
+ await fs.writeFile(tempPath, payload, "utf8");
14268
+ await fs.rename(tempPath, contextFilePath);
14269
+ } catch (error) {
14270
+ await fs.unlink(tempPath).catch(() => {});
14271
+ throw error;
14272
+ }
14273
+ }
14274
+ /**
14229
14275
  * The legacy store read as sessions. Pure: adoption never writes, and
14230
14276
  * the legacy files stay untouched until a mutation materializes the
14231
14277
  * adopted set in the new format.
@@ -14412,14 +14458,22 @@ function normalizeSession(session) {
14412
14458
  };
14413
14459
  }
14414
14460
  /** Temp file in the same directory, fsync, rename, mode 0600 — a reader
14415
- * only ever sees a complete state. */
14461
+ * only ever sees a complete state. The written file also carries the
14462
+ * legacy `tokens` mirror and the auth.context.json pointer stays in
14463
+ * step, so the 3.x CLI sharing this store keeps seeing the sessions
14464
+ * (#204). Our own reader branches on `sessions` before it ever looks
14465
+ * at `tokens`, so the mirror is invisible to this CLI. */
14416
14466
  async function writeCredentialState(filePath, state) {
14417
14467
  await fs.mkdir(path.dirname(filePath), { recursive: true });
14418
14468
  const tempPath = `${filePath}.${randomUUID()}.tmp`;
14469
+ const payload = {
14470
+ ...state,
14471
+ tokens: legacyTokensMirror(state.sessions)
14472
+ };
14419
14473
  try {
14420
14474
  const handle = await fs.open(tempPath, "wx", FILE_MODE);
14421
14475
  try {
14422
- await handle.writeFile(`${JSON.stringify(state, null, 2)}\n`, "utf8");
14476
+ await handle.writeFile(`${JSON.stringify(payload, null, 2)}\n`, "utf8");
14423
14477
  await handle.sync();
14424
14478
  } finally {
14425
14479
  await handle.close();
@@ -14430,6 +14484,7 @@ async function writeCredentialState(filePath, state) {
14430
14484
  throw error;
14431
14485
  }
14432
14486
  await fs.chmod(filePath, FILE_MODE).catch(() => {});
14487
+ await syncLegacyContext(filePath, state.currentWorkspaceId);
14433
14488
  }
14434
14489
  var StateLockTimeoutError = class extends CliStructuredError {
14435
14490
  constructor(lockPath, waitTimeoutMs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/cli",
3
- "version": "8.0.0-rc.5-dev.63",
3
+ "version": "8.0.0-rc.5-dev.64",
4
4
  "description": "Command-line interface for the Prisma Developer Platform.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -40,11 +40,11 @@
40
40
  "license": "Apache-2.0",
41
41
  "dependencies": {
42
42
  "@prisma/cli-engine": "0.2.0",
43
- "@prisma/composer-cli": "0.8.0-dev.1",
43
+ "@prisma/composer-cli": "0.9.0-dev.1",
44
44
  "@prisma/compute-sdk": "0.39.0",
45
45
  "@prisma/credentials-store": "^7.8.0",
46
46
  "@prisma/management-api-sdk": "1.55.0",
47
- "@prisma/orm-toolchain": "8.0.0-rc.3-dev.1",
47
+ "@prisma/orm-toolchain": "8.0.0-rc.3-dev.3",
48
48
  "@vercel/detect-agent": "^1.2.3",
49
49
  "better-result": "^2.9.2",
50
50
  "dotenv": "^17.4.2",
@@ -52,10 +52,10 @@
52
52
  "open": "^11.0.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@prisma/composer": "0.8.0-dev.1",
56
- "@repo/cli-conformance": "8.0.0-rc.5-dev.63",
57
- "@repo/cli-telemetry": "8.0.0-rc.5-dev.63",
58
- "@repo/tsconfig": "8.0.0-rc.5-dev.63",
55
+ "@prisma/composer": "0.9.0-dev.1",
56
+ "@repo/cli-conformance": "8.0.0-rc.5-dev.64",
57
+ "@repo/cli-telemetry": "8.0.0-rc.5-dev.64",
58
+ "@repo/tsconfig": "8.0.0-rc.5-dev.64",
59
59
  "@types/node": "^22.19.19",
60
60
  "tsdown": "^0.21.10",
61
61
  "tsx": "^4.22.4",