@prisma/cli 3.0.0-alpha.2 → 3.0.0-alpha.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.
Files changed (37) hide show
  1. package/dist/adapters/git.js +49 -0
  2. package/dist/adapters/local-state.js +38 -0
  3. package/dist/cli2.js +3 -1
  4. package/dist/commands/app/index.js +31 -20
  5. package/dist/commands/auth/index.js +1 -1
  6. package/dist/commands/env.js +87 -0
  7. package/dist/commands/git/index.js +36 -0
  8. package/dist/commands/project/index.js +10 -13
  9. package/dist/controllers/app-env.js +223 -0
  10. package/dist/controllers/app.js +260 -86
  11. package/dist/controllers/auth.js +2 -2
  12. package/dist/controllers/branch.js +1 -1
  13. package/dist/controllers/project.js +451 -161
  14. package/dist/lib/app/env-config.js +57 -0
  15. package/dist/lib/app/preview-provider.js +15 -2
  16. package/dist/lib/auth/auth-ops.js +8 -10
  17. package/dist/lib/auth/client.js +1 -1
  18. package/dist/lib/project/resolution.js +148 -0
  19. package/dist/output/patterns.js +1 -2
  20. package/dist/presenters/app-env.js +129 -0
  21. package/dist/presenters/app.js +9 -1
  22. package/dist/presenters/auth.js +2 -2
  23. package/dist/presenters/branch.js +6 -6
  24. package/dist/presenters/project.js +84 -44
  25. package/dist/shell/command-meta.js +91 -9
  26. package/dist/shell/command-runner.js +32 -2
  27. package/dist/shell/errors.js +4 -1
  28. package/dist/shell/help.js +1 -1
  29. package/dist/shell/output.js +18 -12
  30. package/dist/shell/runtime.js +1 -1
  31. package/dist/shell/ui.js +19 -1
  32. package/dist/use-cases/auth.js +5 -8
  33. package/dist/use-cases/branch.js +20 -20
  34. package/dist/use-cases/create-cli-gateways.js +3 -13
  35. package/dist/use-cases/project.js +2 -48
  36. package/package.json +2 -2
  37. package/dist/adapters/config.js +0 -74
@@ -47,7 +47,7 @@ const DESCRIPTORS = [
47
47
  {
48
48
  id: "project",
49
49
  path: ["prisma", "project"],
50
- description: "Manage the link between this directory and a Prisma project",
50
+ description: "Manage and inspect your Prisma projects",
51
51
  examples: ["prisma-cli project list", "prisma-cli project show"]
52
52
  },
53
53
  {
@@ -62,6 +62,12 @@ const DESCRIPTORS = [
62
62
  description: "View your active Platform branches",
63
63
  examples: ["prisma-cli branch list", "prisma-cli branch show"]
64
64
  },
65
+ {
66
+ id: "git",
67
+ path: ["prisma", "git"],
68
+ description: "Manage Git repository connections for a project",
69
+ examples: ["prisma-cli git connect", "prisma-cli git disconnect"]
70
+ },
65
71
  {
66
72
  id: "project.list",
67
73
  path: [
@@ -79,18 +85,32 @@ const DESCRIPTORS = [
79
85
  "project",
80
86
  "show"
81
87
  ],
82
- description: "Show the Prisma project linked to this directory",
83
- examples: ["prisma-cli project show", "prisma-cli project show --json"]
88
+ description: "Show which project is active for this directory",
89
+ examples: ["prisma-cli project show", "prisma-cli project show --project proj_123 --json"]
84
90
  },
85
91
  {
86
- id: "project.link",
92
+ id: "git.connect",
87
93
  path: [
88
94
  "prisma",
89
- "project",
90
- "link"
95
+ "git",
96
+ "connect"
97
+ ],
98
+ description: "Connect the resolved project to a GitHub repository",
99
+ examples: [
100
+ "prisma-cli git connect",
101
+ "prisma-cli git connect git@github.com:prisma/prisma-cli.git",
102
+ "prisma-cli git connect --project proj_123"
103
+ ]
104
+ },
105
+ {
106
+ id: "git.disconnect",
107
+ path: [
108
+ "prisma",
109
+ "git",
110
+ "disconnect"
91
111
  ],
92
- description: "Link this directory to a Prisma project",
93
- examples: ["prisma-cli project link", "prisma-cli project link proj_123"]
112
+ description: "Disconnect the GitHub repository from the resolved project",
113
+ examples: ["prisma-cli git disconnect", "prisma-cli git disconnect --project proj_123"]
94
114
  },
95
115
  {
96
116
  id: "branch.list",
@@ -99,7 +119,7 @@ const DESCRIPTORS = [
99
119
  "branch",
100
120
  "list"
101
121
  ],
102
- description: "List active Platform branches linked to this project",
122
+ description: "List active Platform branches for the resolved project",
103
123
  examples: ["prisma-cli branch list", "prisma-cli branch list --json"]
104
124
  },
105
125
  {
@@ -260,6 +280,68 @@ const DESCRIPTORS = [
260
280
  ],
261
281
  description: "Remove the app from the current branch",
262
282
  examples: ["prisma-cli app remove --app hello-world", "prisma-cli app remove --app hello-world --yes"]
283
+ },
284
+ {
285
+ id: "project.env",
286
+ path: [
287
+ "prisma",
288
+ "project",
289
+ "env"
290
+ ],
291
+ description: "Manage environment variables for the active project",
292
+ examples: [
293
+ "prisma-cli project env list --role production",
294
+ "prisma-cli project env add STRIPE_KEY=sk_test_xxx --role production",
295
+ "prisma-cli project env rm STRIPE_KEY --role preview"
296
+ ]
297
+ },
298
+ {
299
+ id: "project.env.add",
300
+ path: [
301
+ "prisma",
302
+ "project",
303
+ "env",
304
+ "add"
305
+ ],
306
+ description: "Create a new environment variable.",
307
+ examples: [
308
+ "prisma-cli project env add STRIPE_KEY=sk_test_xxx --role production",
309
+ "prisma-cli project env add STRIPE_KEY=sk_test_xxx --role preview",
310
+ "API_URL=https://api.example prisma-cli project env add API_URL --project proj_123 --role preview"
311
+ ]
312
+ },
313
+ {
314
+ id: "project.env.update",
315
+ path: [
316
+ "prisma",
317
+ "project",
318
+ "env",
319
+ "update"
320
+ ],
321
+ description: "Replace an existing environment variable's value.",
322
+ examples: ["prisma-cli project env update STRIPE_KEY=sk_new_xxx --role production", "prisma-cli project env update STRIPE_KEY=sk_new_xxx --role preview"]
323
+ },
324
+ {
325
+ id: "project.env.list",
326
+ path: [
327
+ "prisma",
328
+ "project",
329
+ "env",
330
+ "list"
331
+ ],
332
+ description: "List environment variable metadata for a scope (no values).",
333
+ examples: ["prisma-cli project env list --role production", "prisma-cli project env list --role preview"]
334
+ },
335
+ {
336
+ id: "project.env.rm",
337
+ path: [
338
+ "prisma",
339
+ "project",
340
+ "env",
341
+ "rm"
342
+ ],
343
+ description: "Remove an environment variable from a scope.",
344
+ examples: ["prisma-cli project env rm STRIPE_KEY --role production", "prisma-cli project env rm STRIPE_KEY --role preview"]
263
345
  }
264
346
  ];
265
347
  const DESCRIPTORS_BY_ID = new Map(DESCRIPTORS.map((descriptor) => [descriptor.id, descriptor]));
@@ -1,8 +1,8 @@
1
1
  import { CliError } from "./errors.js";
2
+ import { cliErrorToJson, writeHumanError, writeHumanLines, writeJsonError, writeJsonEvent, writeJsonSuccess } from "./output.js";
2
3
  import { getCommandDescriptor } from "./command-meta.js";
3
4
  import { resolveGlobalFlags } from "./global-flags.js";
4
5
  import { createCommandContext } from "./runtime.js";
5
- import { writeHumanError, writeHumanLines, writeJsonError, writeJsonSuccess } from "./output.js";
6
6
  //#region src/shell/command-runner.ts
7
7
  async function runCommand(runtime, commandName, options, handler, presenter) {
8
8
  const flags = resolveGlobalFlags(runtime.argv, options);
@@ -29,5 +29,35 @@ async function runCommand(runtime, commandName, options, handler, presenter) {
29
29
  throw error;
30
30
  }
31
31
  }
32
+ async function runStreamingCommand(runtime, commandName, options, handler) {
33
+ const flags = resolveGlobalFlags(runtime.argv, options);
34
+ const context = await createCommandContext(runtime, flags);
35
+ try {
36
+ await handler(context);
37
+ if (flags.json) writeJsonEvent(context.output, {
38
+ type: "success",
39
+ command: commandName,
40
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
41
+ result: null,
42
+ warnings: [],
43
+ nextSteps: []
44
+ });
45
+ } catch (error) {
46
+ if (error instanceof CliError) {
47
+ if (flags.json) writeJsonEvent(context.output, {
48
+ type: "error",
49
+ command: commandName,
50
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
51
+ error: cliErrorToJson(error),
52
+ warnings: [],
53
+ nextSteps: error.nextSteps
54
+ });
55
+ else writeHumanError(context.output, context.ui, error, { trace: flags.trace });
56
+ process.exitCode = error.exitCode;
57
+ return;
58
+ }
59
+ throw error;
60
+ }
61
+ }
32
62
  //#endregion
33
- export { runCommand };
63
+ export { runCommand, runStreamingCommand };
@@ -51,6 +51,9 @@ function authRequiredError(nextSteps = ["prisma-cli auth login"]) {
51
51
  nextSteps
52
52
  });
53
53
  }
54
+ function workspaceRequiredError() {
55
+ return usageError("Workspace required", "This command needs an active workspace, but the authenticated session does not have one.", "Run prisma-cli auth login and choose a workspace.", ["prisma-cli auth login"], "auth");
56
+ }
54
57
  function featureUnavailableError(summary, why, fix, nextSteps = [], domain = "cli") {
55
58
  return new CliError({
56
59
  code: "FEATURE_UNAVAILABLE",
@@ -63,4 +66,4 @@ function featureUnavailableError(summary, why, fix, nextSteps = [], domain = "cl
63
66
  });
64
67
  }
65
68
  //#endregion
66
- export { CliError, authRequiredError, featureUnavailableError, usageError };
69
+ export { CliError, authRequiredError, featureUnavailableError, usageError, workspaceRequiredError };
@@ -1,6 +1,6 @@
1
+ import { createShellUi, padDisplay, wrapText } from "./ui.js";
1
2
  import { formatDescriptorLabel, getDescriptorForCommand } from "./command-meta.js";
2
3
  import { COMPACT_GLOBAL_OPTION_FLAGS, resolveGlobalFlags } from "./global-flags.js";
3
- import { createShellUi, padDisplay, wrapText } from "./ui.js";
4
4
  //#region src/shell/help.ts
5
5
  function renderHelp(command, runtime) {
6
6
  const descriptor = getDescriptorForCommand(command);
@@ -6,21 +6,27 @@ function writeJsonSuccess(output, success) {
6
6
  ...success
7
7
  }, null, 2)}\n`);
8
8
  }
9
+ function writeJsonEvent(output, event) {
10
+ output.stdout.write(`${JSON.stringify(event)}\n`);
11
+ }
12
+ function cliErrorToJson(error) {
13
+ return {
14
+ code: error.code,
15
+ domain: error.domain,
16
+ severity: error.severity,
17
+ summary: error.summary,
18
+ why: error.why,
19
+ fix: error.fix,
20
+ where: error.where,
21
+ meta: error.meta,
22
+ docsUrl: error.docsUrl
23
+ };
24
+ }
9
25
  function writeJsonError(output, command, error) {
10
26
  output.stdout.write(`${JSON.stringify({
11
27
  ok: false,
12
28
  command,
13
- error: {
14
- code: error.code,
15
- domain: error.domain,
16
- severity: error.severity,
17
- summary: error.summary,
18
- why: error.why,
19
- fix: error.fix,
20
- where: error.where,
21
- meta: error.meta,
22
- docsUrl: error.docsUrl
23
- },
29
+ error: cliErrorToJson(error),
24
30
  warnings: [],
25
31
  nextSteps: error.nextSteps
26
32
  }, null, 2)}\n`);
@@ -51,4 +57,4 @@ function writeHumanError(output, ui, error, options) {
51
57
  writeHumanLines(output, lines);
52
58
  }
53
59
  //#endregion
54
- export { writeHumanError, writeHumanLines, writeJsonError, writeJsonSuccess };
60
+ export { cliErrorToJson, writeHumanError, writeHumanLines, writeJsonError, writeJsonEvent, writeJsonSuccess };
@@ -1,6 +1,6 @@
1
+ import { createShellUi } from "./ui.js";
1
2
  import { LocalStateStore } from "../adapters/local-state.js";
2
3
  import { MockApi } from "../adapters/mock-api.js";
3
- import { createShellUi } from "./ui.js";
4
4
  import { renderHelp } from "./help.js";
5
5
  import path from "node:path";
6
6
  //#region src/shell/runtime.ts
package/dist/shell/ui.js CHANGED
@@ -25,6 +25,18 @@ function createShellUi(runtime, flags) {
25
25
  strong: (text) => colors.bold(text)
26
26
  };
27
27
  }
28
+ function renderCommandHeader(ui, options) {
29
+ if (!ui.isTTY) return [];
30
+ const rows = options.rows ?? [];
31
+ const lines = [`${ui.strong(options.commandLabel)} ${ui.dim("→")} ${ui.dim(options.description)}`, ""];
32
+ const rail = ui.dim("│");
33
+ const keyWidth = rows.length > 0 ? Math.max(...rows.map((row) => stringWidth(`${row.key}:`)), stringWidth("Read more")) : stringWidth("Read more");
34
+ for (const row of rows) lines.push(`${rail} ${ui.accent(padDisplay(`${row.key}:`, keyWidth))} ${formatHeaderValue(ui, row)}`);
35
+ if (rows.length > 0 || options.docsPath) lines.push(rail);
36
+ if (options.docsPath) lines.push(`${rail} ${ui.accent(padDisplay("Read more", keyWidth))} ${ui.link(options.docsPath)}`);
37
+ lines.push("");
38
+ return lines;
39
+ }
28
40
  function renderSummaryLine(ui, status, text) {
29
41
  return `${status === "success" ? ui.success("✔") : status === "error" ? ui.error("✘") : status === "warning" ? ui.warning("⚠") : ui.info("ℹ")} ${text}`;
30
42
  }
@@ -55,5 +67,11 @@ function resolveColorEnabled(runtime, flags, isTTY) {
55
67
  if (runtime.env.NO_COLOR !== void 0) return false;
56
68
  return isTTY;
57
69
  }
70
+ function formatHeaderValue(ui, row) {
71
+ const value = row.sensitive ? maskValue(row.value) : row.value;
72
+ if (row.tone === "dim") return ui.dim(value);
73
+ if (row.tone === "link") return ui.link(value);
74
+ return value;
75
+ }
58
76
  //#endregion
59
- export { createShellUi, maskValue, padDisplay, renderNextSteps, renderSummaryLine, wrapText };
77
+ export { createShellUi, maskValue, padDisplay, renderCommandHeader, renderNextSteps, renderSummaryLine, wrapText };
@@ -40,13 +40,12 @@ function createAuthUseCases(dependencies) {
40
40
  };
41
41
  }
42
42
  async function resolveCurrentAuthState(dependencies) {
43
- const [session, linkedProjectId] = await Promise.all([dependencies.sessionGateway.readAuthSession(), dependencies.projectConfigGateway.readLinkedProjectId()]);
43
+ const session = await dependencies.sessionGateway.readAuthSession();
44
44
  if (!session) return {
45
45
  authenticated: false,
46
46
  provider: null,
47
47
  user: null,
48
- workspace: null,
49
- linkedProjectId
48
+ workspace: null
50
49
  };
51
50
  const provider = dependencies.identityGateway.getProvider(session.provider);
52
51
  const user = dependencies.identityGateway.getUser(session.userId);
@@ -55,15 +54,13 @@ async function resolveCurrentAuthState(dependencies) {
55
54
  authenticated: false,
56
55
  provider: null,
57
56
  user: null,
58
- workspace: null,
59
- linkedProjectId
57
+ workspace: null
60
58
  };
61
59
  return {
62
60
  authenticated: true,
63
61
  provider: provider.id,
64
- user,
65
- workspace,
66
- linkedProjectId
62
+ user: { email: user.email },
63
+ workspace
67
64
  };
68
65
  }
69
66
  //#endregion
@@ -2,41 +2,41 @@
2
2
  function createBranchUseCases(dependencies) {
3
3
  return {
4
4
  list: async () => {
5
- const [linkedProjectId, activeBranch] = await Promise.all([dependencies.projectConfigGateway.readLinkedProjectId(), dependencies.branchStateGateway.readActiveBranch()]);
6
- const remoteBranches = await listRemoteBranches(dependencies.branchGateway, linkedProjectId);
5
+ const [projectId, activeBranch] = await Promise.all([dependencies.projectStateGateway.readRememberedProjectId(), dependencies.branchStateGateway.readActiveBranch()]);
6
+ const remoteBranches = await listRemoteBranches(dependencies.branchGateway, projectId);
7
7
  return {
8
- linkedProjectId,
9
- projectName: resolveProjectName(dependencies.projectGateway, linkedProjectId),
8
+ projectId,
9
+ projectName: resolveProjectName(dependencies.projectGateway, projectId),
10
10
  activeBranch,
11
11
  branches: buildBranchSummaries(activeBranch, remoteBranches)
12
12
  };
13
13
  },
14
14
  show: async () => {
15
- const [linkedProjectId, activeBranch] = await Promise.all([dependencies.projectConfigGateway.readLinkedProjectId(), dependencies.branchStateGateway.readActiveBranch()]);
15
+ const [projectId, activeBranch] = await Promise.all([dependencies.projectStateGateway.readRememberedProjectId(), dependencies.branchStateGateway.readActiveBranch()]);
16
16
  return {
17
- linkedProjectId,
18
- projectName: resolveProjectName(dependencies.projectGateway, linkedProjectId),
19
- branch: buildBranchDetail(dependencies.branchGateway, linkedProjectId, activeBranch)
17
+ projectId,
18
+ projectName: resolveProjectName(dependencies.projectGateway, projectId),
19
+ branch: buildBranchDetail(dependencies.branchGateway, projectId, activeBranch)
20
20
  };
21
21
  },
22
22
  use: async (branchName) => {
23
23
  await dependencies.branchStateGateway.writeActiveBranch(branchName);
24
- const linkedProjectId = await dependencies.projectConfigGateway.readLinkedProjectId();
24
+ const projectId = await dependencies.projectStateGateway.readRememberedProjectId();
25
25
  return {
26
- linkedProjectId,
27
- projectName: resolveProjectName(dependencies.projectGateway, linkedProjectId),
28
- branch: buildBranchDetail(dependencies.branchGateway, linkedProjectId, branchName)
26
+ projectId,
27
+ projectName: resolveProjectName(dependencies.projectGateway, projectId),
28
+ branch: buildBranchDetail(dependencies.branchGateway, projectId, branchName)
29
29
  };
30
30
  }
31
31
  };
32
32
  }
33
- function resolveProjectName(projectGateway, linkedProjectId) {
34
- if (!linkedProjectId) return null;
35
- return projectGateway.getProject(linkedProjectId)?.name ?? null;
33
+ function resolveProjectName(projectGateway, projectId) {
34
+ if (!projectId) return null;
35
+ return projectGateway.getProject(projectId)?.name ?? null;
36
36
  }
37
- async function listRemoteBranches(branchGateway, linkedProjectId) {
38
- if (!linkedProjectId) return [];
39
- return branchGateway.listBranchesForProject(linkedProjectId);
37
+ async function listRemoteBranches(branchGateway, projectId) {
38
+ if (!projectId) return [];
39
+ return branchGateway.listBranchesForProject(projectId);
40
40
  }
41
41
  function buildBranchSummaries(activeBranch, remoteBranches) {
42
42
  const byName = /* @__PURE__ */ new Map();
@@ -56,9 +56,9 @@ function buildBranchSummaries(activeBranch, remoteBranches) {
56
56
  });
57
57
  return sortBranches([...byName.values()]);
58
58
  }
59
- function buildBranchDetail(branchGateway, linkedProjectId, branchName) {
59
+ function buildBranchDetail(branchGateway, projectId, branchName) {
60
60
  const kind = toBranchKind(branchName);
61
- const remoteBranch = linkedProjectId ? branchGateway.getBranchForProject(linkedProjectId, branchName) : void 0;
61
+ const remoteBranch = projectId ? branchGateway.getBranchForProject(projectId, branchName) : void 0;
62
62
  return {
63
63
  name: branchName,
64
64
  kind,
@@ -1,5 +1,3 @@
1
- import { UnsafeConfigWriteError, readLinkedProjectId, writeLinkedProjectId } from "../adapters/config.js";
2
- import { usageError } from "../shell/errors.js";
3
1
  //#region src/use-cases/create-cli-gateways.ts
4
2
  function createCliUseCaseGateways(context) {
5
3
  return {
@@ -44,17 +42,9 @@ function createCliUseCaseGateways(context) {
44
42
  },
45
43
  getDeployment: (deploymentId) => context.api.getDeployment(deploymentId)
46
44
  },
47
- projectConfigGateway: {
48
- readLinkedProjectId: () => readLinkedProjectId(context.runtime.cwd),
49
- writeLinkedProjectId: async (projectId) => {
50
- try {
51
- await writeLinkedProjectId(context.runtime.cwd, projectId);
52
- } catch (error) {
53
- if (error instanceof UnsafeConfigWriteError) throw usageError("Project link requires a writable Prisma config", error.message, "Update prisma.config.ts to use a recognizable project field, or remove it and rerun prisma-cli project link.", ["prisma-cli project link proj_123"], "project");
54
- throw error;
55
- }
56
- }
57
- },
45
+ projectStateGateway: { readRememberedProjectId: async () => {
46
+ return (await context.stateStore.readLastResolvedProject())?.id ?? null;
47
+ } },
58
48
  sessionGateway: {
59
49
  readAuthSession: async () => {
60
50
  return (await context.stateStore.read()).auth;
@@ -1,4 +1,4 @@
1
- import { CliError, authRequiredError } from "../shell/errors.js";
1
+ import { authRequiredError } from "../shell/errors.js";
2
2
  //#region src/use-cases/project.ts
3
3
  function createProjectUseCases(dependencies) {
4
4
  return {
@@ -6,44 +6,9 @@ function createProjectUseCases(dependencies) {
6
6
  const workspace = requireWorkspace(authState);
7
7
  return {
8
8
  workspace,
9
- linkedProjectId: authState.linkedProjectId,
10
9
  projects: listSortedWorkspaceProjects(dependencies.projectGateway, workspace.id).map(toProjectSummary)
11
10
  };
12
11
  },
13
- show: async (authState) => {
14
- if (!authState.linkedProjectId) return {
15
- linkedProjectId: null,
16
- workspace: null,
17
- project: null
18
- };
19
- if (!authState.authenticated || !authState.workspace) return {
20
- linkedProjectId: authState.linkedProjectId,
21
- workspace: null,
22
- project: null
23
- };
24
- const project = dependencies.projectGateway.getProjectForWorkspace(authState.workspace.id, authState.linkedProjectId);
25
- if (!project) return {
26
- linkedProjectId: authState.linkedProjectId,
27
- workspace: null,
28
- project: null
29
- };
30
- return {
31
- linkedProjectId: authState.linkedProjectId,
32
- workspace: authState.workspace,
33
- project: toProjectSummary(project)
34
- };
35
- },
36
- link: async (authState, projectId) => {
37
- const workspace = requireWorkspace(authState);
38
- const project = dependencies.projectGateway.getProjectForWorkspace(workspace.id, projectId);
39
- if (!project) throw projectNotFoundError(`The project "${projectId}" does not exist in workspace "${workspace.name}".`, "Run prisma-cli project list and choose a project id from the active workspace.");
40
- await dependencies.projectConfigGateway.writeLinkedProjectId(project.id);
41
- return {
42
- linkedProjectId: project.id,
43
- workspace,
44
- project: toProjectSummary(project)
45
- };
46
- },
47
12
  listProjectsForWorkspace: async (workspaceId) => listSortedWorkspaceProjects(dependencies.projectGateway, workspaceId).map(toProjectSummary)
48
13
  };
49
14
  }
@@ -60,16 +25,5 @@ function toProjectSummary(project) {
60
25
  name: project.name
61
26
  };
62
27
  }
63
- function projectNotFoundError(why, fix, nextSteps = ["prisma-cli project list"]) {
64
- return new CliError({
65
- code: "PROJECT_NOT_FOUND",
66
- domain: "project",
67
- summary: "Project not found",
68
- why,
69
- fix,
70
- exitCode: 1,
71
- nextSteps
72
- });
73
- }
74
28
  //#endregion
75
- export { createProjectUseCases, projectNotFoundError };
29
+ export { createProjectUseCases };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/cli",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.4",
4
4
  "description": "Preview of the unified Prisma CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -39,7 +39,7 @@
39
39
  "@prisma/compute-sdk": "^0.17.0",
40
40
  "c12": "4.0.0-beta.4",
41
41
  "@prisma/credentials-store": "^7.7.0",
42
- "@prisma/management-api-sdk": "^1.24.0",
42
+ "@prisma/management-api-sdk": "^1.27.0",
43
43
  "colorette": "^2.0.20",
44
44
  "commander": "^12.1.0",
45
45
  "magicast": "^0.3.5",
@@ -1,74 +0,0 @@
1
- import path from "node:path";
2
- import { copyFile, mkdir, mkdtemp, readFile, rm } from "node:fs/promises";
3
- import os from "node:os";
4
- import { updateConfig } from "c12/update";
5
- //#region src/adapters/config.ts
6
- const PROJECT_FIELD_PATTERN = /project\s*:\s*["']([^"']+)["']/;
7
- async function readLinkedProjectId(cwd) {
8
- const configPath = path.join(cwd, "prisma.config.ts");
9
- try {
10
- return (await readFile(configPath, "utf8")).match(PROJECT_FIELD_PATTERN)?.[1] ?? null;
11
- } catch (error) {
12
- if (error.code === "ENOENT") return null;
13
- throw error;
14
- }
15
- }
16
- var UnsafeConfigWriteError = class extends Error {
17
- constructor(message) {
18
- super(message);
19
- this.name = "UnsafeConfigWriteError";
20
- }
21
- };
22
- async function assertLinkedProjectIdWritable(cwd) {
23
- const tempDir = await mkdtemp(path.join(os.tmpdir(), "prisma-cli-config-"));
24
- const sourceConfigPath = path.join(cwd, "prisma.config.ts");
25
- const tempConfigPath = path.join(tempDir, "prisma.config.ts");
26
- try {
27
- try {
28
- await copyFile(sourceConfigPath, tempConfigPath);
29
- } catch (error) {
30
- if (error.code !== "ENOENT") throw error;
31
- }
32
- await applyLinkedProjectIdUpdate(tempDir, "proj_preflight");
33
- } catch (error) {
34
- throw toUnsafeConfigWriteError(error);
35
- } finally {
36
- await rm(tempDir, {
37
- recursive: true,
38
- force: true
39
- });
40
- }
41
- }
42
- async function writeLinkedProjectId(cwd, projectId) {
43
- try {
44
- await applyLinkedProjectIdUpdate(cwd, projectId);
45
- } catch (error) {
46
- if (error.code === "ENOENT") {
47
- await mkdir(cwd, { recursive: true });
48
- await applyLinkedProjectIdUpdate(cwd, projectId);
49
- return;
50
- }
51
- throw toUnsafeConfigWriteError(error);
52
- }
53
- }
54
- async function applyLinkedProjectIdUpdate(cwd, projectId) {
55
- await updateConfig({
56
- cwd,
57
- configFile: "prisma.config",
58
- onUpdate(config) {
59
- config.project = projectId;
60
- },
61
- onCreate() {
62
- return renderProjectConfig(projectId);
63
- }
64
- });
65
- }
66
- function renderProjectConfig(projectId) {
67
- return `export default {\n project: "${projectId}",\n};\n`;
68
- }
69
- function toUnsafeConfigWriteError(error) {
70
- if (error instanceof UnsafeConfigWriteError) return error;
71
- return new UnsafeConfigWriteError("The existing prisma.config.ts file could not be updated safely.");
72
- }
73
- //#endregion
74
- export { UnsafeConfigWriteError, assertLinkedProjectIdWritable, readLinkedProjectId, writeLinkedProjectId };