@prisma/cli 3.0.0-beta.3 → 3.0.0-beta.30

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 (99) hide show
  1. package/README.md +6 -15
  2. package/dist/adapters/local-state.js +15 -4
  3. package/dist/adapters/mock-api.js +244 -0
  4. package/dist/adapters/token-storage.js +335 -34
  5. package/dist/cli.js +7 -7
  6. package/dist/cli2.js +24 -5
  7. package/dist/commands/agent/index.js +60 -0
  8. package/dist/commands/app/index.js +91 -61
  9. package/dist/commands/auth/index.js +55 -2
  10. package/dist/commands/branch/index.js +2 -27
  11. package/dist/commands/bucket/index.js +123 -0
  12. package/dist/commands/build/index.js +29 -0
  13. package/dist/commands/database/index.js +249 -0
  14. package/dist/commands/env.js +8 -4
  15. package/dist/commands/feedback/index.js +20 -0
  16. package/dist/commands/git/index.js +1 -1
  17. package/dist/commands/init/index.js +33 -0
  18. package/dist/commands/project/index.js +54 -5
  19. package/dist/controllers/agent-setup.js +52 -0
  20. package/dist/controllers/agent.js +228 -0
  21. package/dist/controllers/app-env-api.js +55 -0
  22. package/dist/controllers/app-env-file.js +181 -0
  23. package/dist/controllers/app-env.js +227 -104
  24. package/dist/controllers/app.js +746 -306
  25. package/dist/controllers/auth.js +247 -3
  26. package/dist/controllers/branch.js +78 -48
  27. package/dist/controllers/bucket.js +278 -0
  28. package/dist/controllers/build.js +88 -0
  29. package/dist/controllers/database.js +567 -0
  30. package/dist/controllers/feedback.js +86 -0
  31. package/dist/controllers/init.js +753 -0
  32. package/dist/controllers/project.js +377 -22
  33. package/dist/controllers/select-prompt-port.js +1 -0
  34. package/dist/lib/agent/cli-command.js +20 -0
  35. package/dist/lib/agent/constants.js +12 -0
  36. package/dist/lib/agent/package-manager.js +99 -0
  37. package/dist/lib/agent/setup-status.js +83 -0
  38. package/dist/lib/app/{preview-provider.js → app-provider.js} +137 -88
  39. package/dist/lib/app/branch-database-api.js +102 -0
  40. package/dist/lib/app/branch-database-deploy.js +326 -0
  41. package/dist/lib/app/branch-database.js +216 -0
  42. package/dist/lib/app/build-settings.js +93 -0
  43. package/dist/lib/app/build.js +83 -0
  44. package/dist/lib/app/bun-project.js +3 -4
  45. package/dist/lib/app/compute-config.js +145 -0
  46. package/dist/lib/app/deploy-plan.js +59 -0
  47. package/dist/lib/app/{preview-progress.js → deploy-progress.js} +12 -12
  48. package/dist/lib/app/env-config.js +1 -1
  49. package/dist/lib/app/env-file.js +82 -0
  50. package/dist/lib/app/env-vars.js +28 -2
  51. package/dist/lib/app/local-dev.js +3 -60
  52. package/dist/lib/app/production-deploy-gate.js +162 -0
  53. package/dist/lib/app/read-branch.js +30 -0
  54. package/dist/lib/auth/auth-ops.js +10 -4
  55. package/dist/lib/auth/guard.js +4 -1
  56. package/dist/lib/auth/login.js +33 -26
  57. package/dist/lib/auth/recipient.js +42 -0
  58. package/dist/lib/bucket/provider.js +139 -0
  59. package/dist/lib/database/provider.js +378 -0
  60. package/dist/lib/diagnostics.js +15 -0
  61. package/dist/lib/fs/home-path.js +24 -0
  62. package/dist/lib/git/local-branch.js +53 -0
  63. package/dist/lib/git/local-status.js +57 -0
  64. package/dist/lib/project/interactive-setup.js +5 -4
  65. package/dist/lib/project/local-pin.js +171 -41
  66. package/dist/lib/project/provider.js +92 -0
  67. package/dist/lib/project/resolution.js +199 -48
  68. package/dist/lib/project/setup.js +67 -20
  69. package/dist/output/patterns.js +1 -1
  70. package/dist/presenters/agent.js +74 -0
  71. package/dist/presenters/app-env.js +149 -14
  72. package/dist/presenters/app.js +208 -27
  73. package/dist/presenters/auth.js +99 -2
  74. package/dist/presenters/branch.js +37 -102
  75. package/dist/presenters/bucket.js +174 -0
  76. package/dist/presenters/database.js +448 -0
  77. package/dist/presenters/feedback.js +26 -0
  78. package/dist/presenters/init.js +30 -0
  79. package/dist/presenters/project.js +139 -27
  80. package/dist/presenters/verbose-context.js +64 -0
  81. package/dist/shell/cli-command.js +12 -0
  82. package/dist/shell/command-arguments.js +7 -1
  83. package/dist/shell/command-meta.js +458 -17
  84. package/dist/shell/command-runner.js +58 -18
  85. package/dist/shell/diagnostics-output.js +57 -0
  86. package/dist/shell/errors.js +56 -1
  87. package/dist/shell/help.js +31 -20
  88. package/dist/shell/output.js +72 -1
  89. package/dist/shell/prompt.js +12 -5
  90. package/dist/shell/runtime.js +8 -4
  91. package/dist/shell/ui.js +42 -3
  92. package/dist/shell/update-check.js +2 -2
  93. package/dist/use-cases/auth.js +68 -1
  94. package/dist/use-cases/branch.js +20 -68
  95. package/dist/use-cases/create-cli-gateways.js +2 -17
  96. package/dist/use-cases/project.js +2 -1
  97. package/package.json +21 -4
  98. package/dist/lib/app/preview-build.js +0 -312
  99. package/dist/lib/app/preview-interaction.js +0 -5
@@ -1,25 +1,29 @@
1
- import { padDisplay, renderNextSteps, renderSummaryLine } from "../shell/ui.js";
2
- import { formatDescriptorLabel } from "../shell/command-meta.js";
3
1
  import { formatCommandArgument } from "../shell/command-arguments.js";
4
- import { renderList, renderMutate, renderShow, serializeList } from "../output/patterns.js";
5
- import path from "node:path";
2
+ import { formatDescriptorLabel } from "../shell/command-meta.js";
3
+ import { padDisplay, renderNextSteps, renderSummaryLine, renderVerboseBlock } from "../shell/ui.js";
4
+ import { shortenHomePath } from "../lib/fs/home-path.js";
5
+ import { renderMutate, renderShow, serializeList } from "../output/patterns.js";
6
+ import { renderResolvedProjectContextBlock } from "./verbose-context.js";
7
+ import stringWidth from "string-width";
6
8
  //#region src/presenters/project.ts
7
9
  function renderProjectList(context, descriptor, result) {
8
- const lines = renderList({
9
- title: "Listing projects for the authenticated workspace.",
10
- descriptor,
11
- parentContext: {
12
- key: "workspace",
13
- value: result.workspace.name
14
- },
15
- items: result.projects.map((project) => ({
16
- noun: "project",
17
- label: project.name,
18
- id: project.id,
19
- status: null
20
- })),
21
- emptyMessage: "No projects found."
22
- }, context.ui);
10
+ const ui = context.ui;
11
+ const rail = ui.dim("│");
12
+ const lines = [`${ui.strong(formatDescriptorLabel(descriptor))} ${ui.dim("→")} ${ui.dim("Listing projects for the authenticated workspace.")}`, ""];
13
+ lines.push(`${rail} ${ui.accent("workspace:")} ${result.workspace.name}`);
14
+ if (result.projects.length === 0) {
15
+ lines.push(`${rail} ${ui.dim("No projects found.")}`);
16
+ if (result.localBinding?.status === "not-linked" || result.localBinding?.status === "invalid") lines.push(...renderNextSteps(["Link an existing Project you choose: prisma-cli project link <id-or-name>", "Create a new Project: prisma-cli project create <name>"]));
17
+ return lines;
18
+ }
19
+ const nameWidth = Math.max(4, ...result.projects.map((project) => stringWidth(project.name)));
20
+ const idWidth = Math.max(2, ...result.projects.map((project) => project.id.length));
21
+ lines.push(rail);
22
+ lines.push(`${rail} ${ui.accent(padDisplay("name", nameWidth))} ${ui.accent(padDisplay("id", idWidth))} ${ui.accent("region")}`);
23
+ for (const project of result.projects) {
24
+ const region = project.defaultRegion ? project.defaultRegion : ui.dim("none");
25
+ lines.push(`${rail} ${padDisplay(project.name, nameWidth)} ${padDisplay(project.id, idWidth)} ${region}`);
26
+ }
23
27
  if (result.localBinding?.status === "not-linked" || result.localBinding?.status === "invalid") lines.push(...renderNextSteps(["Link an existing Project you choose: prisma-cli project link <id-or-name>", "Create a new Project: prisma-cli project create <name>"]));
24
28
  return lines;
25
29
  }
@@ -51,6 +55,25 @@ function renderProjectShow(context, descriptor, result) {
51
55
  tone: "warning"
52
56
  }]
53
57
  }, context.ui);
58
+ lines.push(...renderVerboseBlock(context.ui, [
59
+ {
60
+ key: "workspace",
61
+ value: result.workspace.name
62
+ },
63
+ {
64
+ key: "workspace id",
65
+ value: result.workspace.id,
66
+ tone: "dim"
67
+ },
68
+ {
69
+ key: "project source",
70
+ value: "unbound"
71
+ },
72
+ {
73
+ key: "suggested name",
74
+ value: `${result.suggestedProjectName} (${result.suggestedProjectNameSource})`
75
+ }
76
+ ], { title: "Resolved context" }));
54
77
  lines.push(...renderNextSteps(["Link an existing Project you choose: prisma-cli project link <id-or-name>", `Create a new Project: prisma-cli project create ${formatCommandArgument(result.suggestedProjectName)}`]));
55
78
  return lines;
56
79
  }
@@ -67,6 +90,95 @@ function renderProjectSetup(context, _descriptor, result) {
67
90
  function serializeProjectSetup(result) {
68
91
  return result;
69
92
  }
93
+ function renderProjectRename(context, descriptor, result) {
94
+ return renderMutate({
95
+ title: "Renaming project.",
96
+ descriptor,
97
+ context: [
98
+ {
99
+ key: "workspace",
100
+ value: result.workspace.name
101
+ },
102
+ {
103
+ key: "project",
104
+ value: result.previousName
105
+ },
106
+ {
107
+ key: "id",
108
+ value: result.project.id,
109
+ tone: "dim"
110
+ }
111
+ ],
112
+ operationDescription: "Renaming project",
113
+ operationCount: 1,
114
+ details: [`The project is now named "${result.project.name}". Directory bindings pin the project id, so they stay valid.`]
115
+ }, context.ui);
116
+ }
117
+ function serializeProjectRename(result) {
118
+ return result;
119
+ }
120
+ function renderProjectRemove(context, descriptor, result) {
121
+ return renderMutate({
122
+ title: "Removing project.",
123
+ descriptor,
124
+ context: [
125
+ {
126
+ key: "workspace",
127
+ value: result.workspace.name
128
+ },
129
+ {
130
+ key: "project",
131
+ value: result.project.name
132
+ },
133
+ {
134
+ key: "id",
135
+ value: result.project.id,
136
+ tone: "dim"
137
+ }
138
+ ],
139
+ operationDescription: "Removing project",
140
+ operationCount: 1,
141
+ details: ["The project, its databases, and its apps were removed.", ...result.localPin.cleared ? ["This directory's local project binding was cleared."] : []]
142
+ }, context.ui);
143
+ }
144
+ function serializeProjectRemove(result) {
145
+ return result;
146
+ }
147
+ function renderProjectTransfer(context, descriptor, result) {
148
+ return renderMutate({
149
+ title: "Transferring project.",
150
+ descriptor,
151
+ context: [
152
+ {
153
+ key: "workspace",
154
+ value: result.workspace.name
155
+ },
156
+ {
157
+ key: "project",
158
+ value: result.project.name
159
+ },
160
+ {
161
+ key: "id",
162
+ value: result.project.id,
163
+ tone: "dim"
164
+ },
165
+ {
166
+ key: "recipient",
167
+ value: result.recipient.workspaceName ?? result.recipient.workspaceId ?? "workspace of the provided recipient token"
168
+ }
169
+ ],
170
+ operationDescription: "Transferring project",
171
+ operationCount: 1,
172
+ details: [
173
+ "The project now belongs to the recipient workspace; this workspace no longer has access.",
174
+ ...result.localPin.action === "rewritten" ? ["This directory's local project binding now points at the recipient workspace."] : [],
175
+ ...result.localPin.action === "cleared" ? ["This directory's local project binding was cleared."] : []
176
+ ]
177
+ }, context.ui);
178
+ }
179
+ function serializeProjectTransfer(result) {
180
+ return result;
181
+ }
70
182
  function renderGitConnect(context, descriptor, result) {
71
183
  const connection = result.repositoryConnection;
72
184
  return renderMutate({
@@ -133,16 +245,16 @@ function renderBoundProjectShow(context, descriptor, result) {
133
245
  lines.push(rail);
134
246
  lines.push(`${rail} ${ui.dim("→")} ${ui.link(result.project.url)}`);
135
247
  }
248
+ if (result.project.defaultRegion) lines.push(`${rail} ${ui.accent(padDisplay("region", keyWidth))} ${ui.dim(result.project.defaultRegion)}`);
249
+ lines.push(...renderResolvedProjectContextBlock(context.ui, {
250
+ workspace: result.workspace,
251
+ project: result.project,
252
+ resolution: result.resolution
253
+ }));
136
254
  return lines;
137
255
  }
138
256
  function formatLocalRepoPath(cwd, env) {
139
- const resolved = path.resolve(cwd);
140
- const home = env.HOME ? path.resolve(env.HOME) : null;
141
- if (home && (resolved === home || resolved.startsWith(`${home}${path.sep}`))) {
142
- const relative = path.relative(home, resolved);
143
- return relative ? `~/${relative}` : "~";
144
- }
145
- return resolved;
257
+ return shortenHomePath(cwd, env);
146
258
  }
147
259
  function formatGitConnectionDetail(status) {
148
260
  switch (status) {
@@ -153,4 +265,4 @@ function formatGitConnectionDetail(status) {
153
265
  }
154
266
  }
155
267
  //#endregion
156
- export { renderGitConnect, renderGitDisconnect, renderProjectList, renderProjectSetup, renderProjectShow, serializeProjectList, serializeProjectSetup, serializeProjectShow };
268
+ export { renderGitConnect, renderGitDisconnect, renderProjectList, renderProjectRemove, renderProjectRename, renderProjectSetup, renderProjectShow, renderProjectTransfer, serializeProjectList, serializeProjectRemove, serializeProjectRename, serializeProjectSetup, serializeProjectShow, serializeProjectTransfer };
@@ -0,0 +1,64 @@
1
+ import { renderVerboseBlock } from "../shell/ui.js";
2
+ //#region src/presenters/verbose-context.ts
3
+ function renderResolvedProjectContextBlock(ui, context, options = {}) {
4
+ if (!context) return [];
5
+ return renderVerboseBlock(ui, [...projectResolutionRows(context), ...options.extraRows ?? []], { title: options.title ?? "Resolved context" });
6
+ }
7
+ function projectResolutionRows(context) {
8
+ return [
9
+ {
10
+ key: "workspace",
11
+ value: context.workspace.name
12
+ },
13
+ {
14
+ key: "workspace id",
15
+ value: context.workspace.id,
16
+ tone: "dim"
17
+ },
18
+ {
19
+ key: "project",
20
+ value: context.project.name
21
+ },
22
+ {
23
+ key: "project id",
24
+ value: context.project.id,
25
+ tone: "dim"
26
+ },
27
+ {
28
+ key: "project source",
29
+ value: formatProjectSource(context.resolution.projectSource)
30
+ },
31
+ ...context.resolution.targetName ? [{
32
+ key: "target name",
33
+ value: formatTargetName(context.resolution)
34
+ }] : [],
35
+ ...context.branch ? [{
36
+ key: "branch",
37
+ value: `${context.branch.name} (${context.branch.kind})`
38
+ }, ...context.branch.id ? [{
39
+ key: "branch id",
40
+ value: context.branch.id,
41
+ tone: "dim"
42
+ }] : []] : []
43
+ ];
44
+ }
45
+ function stripVerboseContext(result) {
46
+ const { verboseContext: _verboseContext, ...serialized } = result;
47
+ return serialized;
48
+ }
49
+ function formatProjectSource(source) {
50
+ switch (source) {
51
+ case "explicit": return "--project";
52
+ case "env": return "environment";
53
+ case "local-pin": return ".prisma/local.json";
54
+ case "platform-mapping": return "platform mapping";
55
+ case "created": return "created";
56
+ case "prompt": return "prompt";
57
+ case "unbound": return "unbound";
58
+ }
59
+ }
60
+ function formatTargetName(resolution) {
61
+ return resolution.targetNameSource ? `${resolution.targetName} (${resolution.targetNameSource})` : String(resolution.targetName);
62
+ }
63
+ //#endregion
64
+ export { renderResolvedProjectContextBlock, stripVerboseContext };
@@ -0,0 +1,12 @@
1
+ const PRISMA_CLI_PACKAGE_SPEC = `@prisma/cli@latest`;
2
+ const DEFAULT_PRISMA_CLI_PACKAGE_RUNNER = ["npx", "-y"];
3
+ const PRISMA_CLI_BINARY = "prisma-cli";
4
+ function formatPrismaCliCommand(args, options = {}) {
5
+ return [...getPrismaCliCommandPrefix(options), ...args].join(" ");
6
+ }
7
+ function getPrismaCliCommandPrefix({ invocation = "package", packageRunner = DEFAULT_PRISMA_CLI_PACKAGE_RUNNER }) {
8
+ if (invocation === "binary") return [PRISMA_CLI_BINARY];
9
+ return [...packageRunner, PRISMA_CLI_PACKAGE_SPEC];
10
+ }
11
+ //#endregion
12
+ export { formatPrismaCliCommand };
@@ -2,5 +2,11 @@
2
2
  function formatCommandArgument(value) {
3
3
  return /^[A-Za-z0-9._/-]+$/.test(value) && !value.startsWith("-") ? value : `'${value.replace(/'/g, "'\\''")}'`;
4
4
  }
5
+ function formatShellCommand(command) {
6
+ return command.map(formatShellCommandWord).join(" ");
7
+ }
8
+ function formatShellCommandWord(value) {
9
+ return /^[A-Za-z0-9_./:@=-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
10
+ }
5
11
  //#endregion
6
- export { formatCommandArgument };
12
+ export { formatCommandArgument, formatShellCommand };