@prisma/cli 3.0.0-dev.99.1 → 8.0.0-rc.10-dev.80

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 (86) hide show
  1. package/README.md +26 -28
  2. package/dist/cli.js +14551 -16
  3. package/dist/payload-B88Qvzxk-CrtTXSOe.js +34 -0
  4. package/dist/sender.js +192 -0
  5. package/package.json +26 -19
  6. package/dist/adapters/git.js +0 -54
  7. package/dist/adapters/local-state.js +0 -144
  8. package/dist/adapters/mock-api.js +0 -136
  9. package/dist/adapters/token-storage.js +0 -418
  10. package/dist/cli2.js +0 -119
  11. package/dist/commands/app/index.js +0 -345
  12. package/dist/commands/auth/index.js +0 -96
  13. package/dist/commands/branch/index.js +0 -27
  14. package/dist/commands/database/index.js +0 -159
  15. package/dist/commands/env.js +0 -99
  16. package/dist/commands/git/index.js +0 -36
  17. package/dist/commands/project/index.js +0 -69
  18. package/dist/commands/version/index.js +0 -18
  19. package/dist/controllers/app-env-api.js +0 -54
  20. package/dist/controllers/app-env-file.js +0 -181
  21. package/dist/controllers/app-env.js +0 -502
  22. package/dist/controllers/app.js +0 -2443
  23. package/dist/controllers/auth.js +0 -316
  24. package/dist/controllers/branch.js +0 -103
  25. package/dist/controllers/database.js +0 -318
  26. package/dist/controllers/project.js +0 -731
  27. package/dist/controllers/select-prompt-port.js +0 -12
  28. package/dist/controllers/version.js +0 -12
  29. package/dist/lib/app/app-interaction.js +0 -5
  30. package/dist/lib/app/app-provider.js +0 -544
  31. package/dist/lib/app/branch-database-api.js +0 -102
  32. package/dist/lib/app/branch-database-deploy.js +0 -325
  33. package/dist/lib/app/branch-database.js +0 -215
  34. package/dist/lib/app/build-settings.js +0 -93
  35. package/dist/lib/app/build.js +0 -80
  36. package/dist/lib/app/bun-project.js +0 -45
  37. package/dist/lib/app/compute-config.js +0 -147
  38. package/dist/lib/app/deploy-output.js +0 -24
  39. package/dist/lib/app/deploy-plan.js +0 -58
  40. package/dist/lib/app/deploy-progress.js +0 -100
  41. package/dist/lib/app/domain-guidance.js +0 -14
  42. package/dist/lib/app/env-config.js +0 -67
  43. package/dist/lib/app/env-file.js +0 -82
  44. package/dist/lib/app/env-vars.js +0 -50
  45. package/dist/lib/app/local-dev.js +0 -109
  46. package/dist/lib/app/production-deploy-gate.js +0 -161
  47. package/dist/lib/app/read-branch.js +0 -30
  48. package/dist/lib/auth/auth-ops.js +0 -158
  49. package/dist/lib/auth/client.js +0 -22
  50. package/dist/lib/auth/guard.js +0 -38
  51. package/dist/lib/auth/login.js +0 -330
  52. package/dist/lib/database/provider.js +0 -167
  53. package/dist/lib/diagnostics.js +0 -15
  54. package/dist/lib/fs/home-path.js +0 -24
  55. package/dist/lib/git/local-branch.js +0 -53
  56. package/dist/lib/git/local-status.js +0 -57
  57. package/dist/lib/project/interactive-setup.js +0 -56
  58. package/dist/lib/project/local-pin.js +0 -200
  59. package/dist/lib/project/resolution.js +0 -386
  60. package/dist/lib/project/setup.js +0 -135
  61. package/dist/lib/version.js +0 -55
  62. package/dist/output/patterns.js +0 -90
  63. package/dist/presenters/app-env.js +0 -265
  64. package/dist/presenters/app.js +0 -646
  65. package/dist/presenters/auth.js +0 -183
  66. package/dist/presenters/branch.js +0 -46
  67. package/dist/presenters/database.js +0 -274
  68. package/dist/presenters/project.js +0 -174
  69. package/dist/presenters/verbose-context.js +0 -64
  70. package/dist/presenters/version.js +0 -29
  71. package/dist/shell/command-arguments.js +0 -6
  72. package/dist/shell/command-meta.js +0 -622
  73. package/dist/shell/command-runner.js +0 -112
  74. package/dist/shell/diagnostics-output.js +0 -57
  75. package/dist/shell/errors.js +0 -134
  76. package/dist/shell/global-flags.js +0 -37
  77. package/dist/shell/help.js +0 -89
  78. package/dist/shell/output.js +0 -82
  79. package/dist/shell/prompt.js +0 -41
  80. package/dist/shell/runtime.js +0 -55
  81. package/dist/shell/ui.js +0 -116
  82. package/dist/shell/update-check.js +0 -247
  83. package/dist/use-cases/auth.js +0 -145
  84. package/dist/use-cases/branch.js +0 -47
  85. package/dist/use-cases/create-cli-gateways.js +0 -68
  86. package/dist/use-cases/project.js +0 -30
@@ -1,99 +0,0 @@
1
- import { attachCommandDescriptor } from "../shell/command-meta.js";
2
- import { addGlobalFlags } from "../shell/global-flags.js";
3
- import { configureRuntimeCommand } from "../shell/runtime.js";
4
- import { runCommand } from "../shell/command-runner.js";
5
- import { runEnvAdd, runEnvList, runEnvRemove, runEnvUpdate } from "../controllers/app-env.js";
6
- import { renderEnvAdd, renderEnvList, renderEnvRm, renderEnvUpdate, serializeEnvAdd, serializeEnvList, serializeEnvRm, serializeEnvUpdate } from "../presenters/app-env.js";
7
- import { Command, Option } from "commander";
8
- //#region src/commands/env.ts
9
- function createEnvCommand(runtime) {
10
- const env = attachCommandDescriptor(configureRuntimeCommand(new Command("env"), runtime), "project.env");
11
- env.description("Manage environment variables for the active project");
12
- env.addCommand(createEnvAddCommand(runtime));
13
- env.addCommand(createEnvUpdateCommand(runtime));
14
- env.addCommand(createEnvListCommand(runtime));
15
- env.addCommand(createEnvRemoveCommand(runtime));
16
- return env;
17
- }
18
- function createEnvAddCommand(runtime) {
19
- const command = attachCommandDescriptor(configureRuntimeCommand(new Command("add"), runtime), "project.env.add");
20
- command.argument("[assignment]", "Variable assignment as KEY=VALUE or KEY from the current environment").addOption(new Option("--file <path>", "Read KEY=VALUE assignments from a dotenv file")).addOption(new Option("--role <role>", "Project template scope (production or preview)").choices(["production", "preview"])).addOption(new Option("--branch <git-name>", "Preview branch override scope")).addOption(new Option("--project <id-or-name>", "Project id or name"));
21
- addGlobalFlags(command);
22
- command.action(async (assignment, options) => {
23
- const roleName = options.role;
24
- const branchName = options.branch;
25
- const projectRef = options.project;
26
- const filePath = options.file;
27
- await runCommand(runtime, "project.env.add", options, (context) => runEnvAdd(context, assignment, {
28
- roleName,
29
- branchName,
30
- projectRef,
31
- filePath
32
- }), {
33
- renderHuman: (context, descriptor, result) => renderEnvAdd(context, descriptor, result),
34
- renderJson: (result) => serializeEnvAdd(result)
35
- });
36
- });
37
- return command;
38
- }
39
- function createEnvUpdateCommand(runtime) {
40
- const command = attachCommandDescriptor(configureRuntimeCommand(new Command("update"), runtime), "project.env.update");
41
- command.argument("[assignment]", "Variable assignment as KEY=VALUE or KEY from the current environment").addOption(new Option("--file <path>", "Read KEY=VALUE assignments from a dotenv file")).addOption(new Option("--role <role>", "Project template scope (production or preview)").choices(["production", "preview"])).addOption(new Option("--branch <git-name>", "Preview branch override scope")).addOption(new Option("--project <id-or-name>", "Project id or name"));
42
- addGlobalFlags(command);
43
- command.action(async (assignment, options) => {
44
- const roleName = options.role;
45
- const branchName = options.branch;
46
- const projectRef = options.project;
47
- const filePath = options.file;
48
- await runCommand(runtime, "project.env.update", options, (context) => runEnvUpdate(context, assignment, {
49
- roleName,
50
- branchName,
51
- projectRef,
52
- filePath
53
- }), {
54
- renderHuman: (context, descriptor, result) => renderEnvUpdate(context, descriptor, result),
55
- renderJson: (result) => serializeEnvUpdate(result)
56
- });
57
- });
58
- return command;
59
- }
60
- function createEnvListCommand(runtime) {
61
- const command = attachCommandDescriptor(configureRuntimeCommand(new Command("list"), runtime), "project.env.list");
62
- command.addOption(new Option("--role <role>", "Project template scope").choices(["production", "preview"])).addOption(new Option("--branch <git-name>", "Preview branch resolved scope")).addOption(new Option("--project <id-or-name>", "Project id or name"));
63
- addGlobalFlags(command);
64
- command.action(async (options) => {
65
- const roleName = options.role;
66
- const branchName = options.branch;
67
- const projectRef = options.project;
68
- await runCommand(runtime, "project.env.list", options, (context) => runEnvList(context, {
69
- roleName,
70
- branchName,
71
- projectRef
72
- }), {
73
- renderHuman: (context, descriptor, result) => renderEnvList(context, descriptor, result),
74
- renderJson: (result) => serializeEnvList(result)
75
- });
76
- });
77
- return command;
78
- }
79
- function createEnvRemoveCommand(runtime) {
80
- const command = attachCommandDescriptor(configureRuntimeCommand(new Command("remove"), runtime), "project.env.remove");
81
- command.alias("rm").argument("<key>", "Variable key to remove").addOption(new Option("--role <role>", "Project template scope (production or preview)").choices(["production", "preview"])).addOption(new Option("--branch <git-name>", "Preview branch override scope")).addOption(new Option("--project <id-or-name>", "Project id or name"));
82
- addGlobalFlags(command);
83
- command.action(async (key, options) => {
84
- const roleName = options.role;
85
- const branchName = options.branch;
86
- const projectRef = options.project;
87
- await runCommand(runtime, "project.env.remove", options, (context) => runEnvRemove(context, key, {
88
- roleName,
89
- branchName,
90
- projectRef
91
- }), {
92
- renderHuman: (context, descriptor, result) => renderEnvRm(context, descriptor, result),
93
- renderJson: (result) => serializeEnvRm(result)
94
- });
95
- });
96
- return command;
97
- }
98
- //#endregion
99
- export { createEnvCommand };
@@ -1,36 +0,0 @@
1
- import { attachCommandDescriptor } from "../../shell/command-meta.js";
2
- import { addCompactGlobalFlags, addGlobalFlags } from "../../shell/global-flags.js";
3
- import { configureRuntimeCommand } from "../../shell/runtime.js";
4
- import { runGitConnect, runGitDisconnect } from "../../controllers/project.js";
5
- import { runCommand } from "../../shell/command-runner.js";
6
- import { renderGitConnect, renderGitDisconnect } from "../../presenters/project.js";
7
- import { Command } from "commander";
8
- //#region src/commands/git/index.ts
9
- function createGitCommand(runtime) {
10
- const git = attachCommandDescriptor(configureRuntimeCommand(new Command("git"), runtime), "git");
11
- addCompactGlobalFlags(git);
12
- git.addCommand(createGitConnectCommand(runtime));
13
- git.addCommand(createGitDisconnectCommand(runtime));
14
- return git;
15
- }
16
- function createGitConnectCommand(runtime) {
17
- const command = attachCommandDescriptor(configureRuntimeCommand(new Command("connect"), runtime), "git.connect");
18
- command.argument("[git-url]", "GitHub repository URL");
19
- command.option("--project <id-or-name>", "Project id or name");
20
- addGlobalFlags(command);
21
- command.action(async (gitUrl, options) => {
22
- await runCommand(runtime, "git.connect", options, (context) => runGitConnect(context, gitUrl, { project: typeof options.project === "string" ? options.project : void 0 }), { renderHuman: (context, descriptor, result) => renderGitConnect(context, descriptor, result) });
23
- });
24
- return command;
25
- }
26
- function createGitDisconnectCommand(runtime) {
27
- const command = attachCommandDescriptor(configureRuntimeCommand(new Command("disconnect"), runtime), "git.disconnect");
28
- command.option("--project <id-or-name>", "Project id or name");
29
- addGlobalFlags(command);
30
- command.action(async (options) => {
31
- await runCommand(runtime, "git.disconnect", options, (context) => runGitDisconnect(context, { project: typeof options.project === "string" ? options.project : void 0 }), { renderHuman: (context, descriptor, result) => renderGitDisconnect(context, descriptor, result) });
32
- });
33
- return command;
34
- }
35
- //#endregion
36
- export { createGitCommand };
@@ -1,69 +0,0 @@
1
- import { attachCommandDescriptor } from "../../shell/command-meta.js";
2
- import { addCompactGlobalFlags, addGlobalFlags } from "../../shell/global-flags.js";
3
- import { configureRuntimeCommand } from "../../shell/runtime.js";
4
- import { runProjectCreate, runProjectLink, runProjectList, runProjectShow } from "../../controllers/project.js";
5
- import { runCommand } from "../../shell/command-runner.js";
6
- import { renderProjectList, renderProjectSetup, renderProjectShow, serializeProjectList, serializeProjectSetup, serializeProjectShow } from "../../presenters/project.js";
7
- import { createEnvCommand } from "../env.js";
8
- import { Command } from "commander";
9
- //#region src/commands/project/index.ts
10
- function createProjectCommand(runtime) {
11
- const project = attachCommandDescriptor(configureRuntimeCommand(new Command("project"), runtime), "project");
12
- addCompactGlobalFlags(project);
13
- project.addCommand(createProjectListCommand(runtime));
14
- project.addCommand(createProjectShowCommand(runtime));
15
- project.addCommand(createProjectCreateCommand(runtime));
16
- project.addCommand(createProjectLinkCommand(runtime));
17
- project.addCommand(createEnvCommand(runtime));
18
- return project;
19
- }
20
- function createProjectCreateCommand(runtime) {
21
- const command = attachCommandDescriptor(configureRuntimeCommand(new Command("create"), runtime), "project.create");
22
- command.argument("<name>", "Project name");
23
- addGlobalFlags(command);
24
- command.action(async (name, options) => {
25
- await runCommand(runtime, "project.create", options, (context) => runProjectCreate(context, String(name)), {
26
- renderHuman: (context, descriptor, result) => renderProjectSetup(context, descriptor, result),
27
- renderJson: (result) => serializeProjectSetup(result)
28
- });
29
- });
30
- return command;
31
- }
32
- function createProjectLinkCommand(runtime) {
33
- const command = attachCommandDescriptor(configureRuntimeCommand(new Command("link"), runtime), "project.link");
34
- command.argument("[id-or-name]", "Project id or name");
35
- addGlobalFlags(command);
36
- command.action(async (projectRef, options) => {
37
- await runCommand(runtime, "project.link", options, (context) => runProjectLink(context, typeof projectRef === "string" ? projectRef : void 0), {
38
- renderHuman: (context, descriptor, result) => renderProjectSetup(context, descriptor, result),
39
- renderJson: (result) => serializeProjectSetup(result)
40
- });
41
- });
42
- return command;
43
- }
44
- function createProjectListCommand(runtime) {
45
- const command = attachCommandDescriptor(configureRuntimeCommand(new Command("list"), runtime), "project.list");
46
- addGlobalFlags(command);
47
- command.action(async (options) => {
48
- await runCommand(runtime, "project.list", options, (context) => runProjectList(context), {
49
- renderHuman: (context, descriptor, result) => renderProjectList(context, descriptor, result),
50
- renderJson: (result) => serializeProjectList(result)
51
- });
52
- });
53
- return command;
54
- }
55
- function createProjectShowCommand(runtime) {
56
- const command = attachCommandDescriptor(configureRuntimeCommand(new Command("show"), runtime), "project.show");
57
- command.option("--project <id-or-name>", "Project id or name");
58
- addGlobalFlags(command);
59
- command.action(async (options) => {
60
- const projectRef = options.project;
61
- await runCommand(runtime, "project.show", options, (context) => runProjectShow(context, projectRef), {
62
- renderHuman: (context, descriptor, result) => renderProjectShow(context, descriptor, result),
63
- renderJson: (result) => serializeProjectShow(result)
64
- });
65
- });
66
- return command;
67
- }
68
- //#endregion
69
- export { createProjectCommand };
@@ -1,18 +0,0 @@
1
- import { attachCommandDescriptor } from "../../shell/command-meta.js";
2
- import { addGlobalFlags } from "../../shell/global-flags.js";
3
- import { configureRuntimeCommand } from "../../shell/runtime.js";
4
- import { runCommand } from "../../shell/command-runner.js";
5
- import { runVersion } from "../../controllers/version.js";
6
- import { renderVersionSuccess } from "../../presenters/version.js";
7
- import { Command } from "commander";
8
- //#region src/commands/version/index.ts
9
- function createVersionCommand(runtime) {
10
- const command = attachCommandDescriptor(configureRuntimeCommand(new Command("version"), runtime), "version");
11
- addGlobalFlags(command);
12
- command.action(async (options) => {
13
- await runCommand(runtime, "version", options, (context) => runVersion(context), { renderHuman: (context, descriptor, result) => renderVersionSuccess(context, descriptor, result) });
14
- });
15
- return command;
16
- }
17
- //#endregion
18
- export { createVersionCommand };
@@ -1,54 +0,0 @@
1
- import { CliError, authRequiredError } from "../shell/errors.js";
2
- //#region src/controllers/app-env-api.ts
3
- async function findVariableByNaturalKey(client, projectId, key, resolved, signal) {
4
- const { data, error, response } = await client.GET("/v1/environment-variables", {
5
- params: { query: {
6
- projectId,
7
- class: resolved.apiTarget.class,
8
- key
9
- } },
10
- signal
11
- });
12
- if (error || !data) throw apiCallError(`Failed to look up ${key}`, response, error);
13
- return data.data.filter((row) => rowMatchesExactScope(row, resolved))[0] ?? null;
14
- }
15
- function toMetadata(row, requestedScope) {
16
- const rowScope = row.branchId === null ? {
17
- kind: "role",
18
- role: row.class
19
- } : requestedScope;
20
- return {
21
- id: row.id,
22
- key: row.key,
23
- scope: rowScope,
24
- source: formatDescriptorLabel(rowScope),
25
- isManagedBySystem: row.isManagedBySystem,
26
- updatedAt: row.updatedAt
27
- };
28
- }
29
- function rowMatchesExactScope(row, resolved) {
30
- return row.class === resolved.apiTarget.class && row.branchId === resolved.apiTarget.branchId;
31
- }
32
- function apiCallError(summary, response, error) {
33
- const status = response?.status ?? 0;
34
- const apiCode = error?.error?.code;
35
- const apiMessage = error?.error?.message;
36
- const apiHint = error?.error?.hint;
37
- if (status === 401 || status === 403) return authRequiredError(["prisma auth login"]);
38
- return new CliError({
39
- code: apiCode ?? "ENV_API_ERROR",
40
- domain: "app",
41
- summary,
42
- why: apiMessage ?? `The Management API returned status ${status || "unknown"}.`,
43
- fix: apiHint ?? "Re-run with --trace for the underlying API response details.",
44
- exitCode: 1,
45
- nextSteps: []
46
- });
47
- }
48
- function formatDescriptorLabel(scope) {
49
- if (scope.kind === "role") return scope.role ?? "unknown";
50
- if (scope.kind === "overview") return "overview";
51
- return `branch:${scope.branchName ?? scope.branchId ?? "unknown"}`;
52
- }
53
- //#endregion
54
- export { apiCallError, findVariableByNaturalKey, toMetadata };
@@ -1,181 +0,0 @@
1
- import { CliError } from "../shell/errors.js";
2
- import { formatScopeLabel } from "../lib/app/env-config.js";
3
- import { apiCallError, findVariableByNaturalKey, toMetadata } from "./app-env-api.js";
4
- //#region src/controllers/app-env-file.ts
5
- async function runEnvAddFile(context, client, projectId, resolved, filePath, assignments, verboseContext) {
6
- const existing = await findVariablesByNaturalKey(client, projectId, assignments.map((assignment) => assignment.key), resolved, context.runtime.signal);
7
- const existingKeys = assignments.map((assignment) => assignment.key).filter((key) => existing.has(key));
8
- if (existingKeys.length > 0) throw new CliError({
9
- code: "ENV_VARIABLE_ALREADY_EXISTS",
10
- domain: "app",
11
- summary: `${existingKeys.length} environment variable(s) already exist in ${formatScopeLabel(resolved.scope)}`,
12
- why: `Existing keys: ${formatKeyList(existingKeys)}.`,
13
- fix: "Split the input file by key state: update existing keys and add new keys separately.",
14
- exitCode: 1,
15
- nextSteps: splitFileNextSteps(filePath, resolved.scope, {
16
- existingKeys,
17
- first: "update-existing"
18
- }),
19
- meta: { keys: existingKeys }
20
- });
21
- const warnings = await missingPreviewDefaultWarnings(client, projectId, resolved.scope, assignments.map((assignment) => assignment.key), context.runtime.signal);
22
- const variables = [];
23
- for (const assignment of assignments) try {
24
- const { data, error, response } = await client.POST("/v1/environment-variables", {
25
- body: {
26
- projectId,
27
- class: resolved.apiTarget.class,
28
- ...resolved.apiTarget.branchId !== null ? { branchId: resolved.apiTarget.branchId } : {},
29
- key: assignment.key,
30
- value: assignment.value
31
- },
32
- signal: context.runtime.signal
33
- });
34
- if (error || !data) throw apiCallError(`Failed to add ${assignment.key}`, response, error);
35
- variables.push(toMetadata(data.data, resolved.descriptor));
36
- } catch (error) {
37
- throw envFileApplyFailedError("add", filePath, resolved.scope, assignment.key, variables, error);
38
- }
39
- return {
40
- command: "project.env.add",
41
- result: {
42
- projectId,
43
- verboseContext,
44
- scope: resolved.descriptor,
45
- variables,
46
- file: {
47
- path: filePath,
48
- count: variables.length
49
- }
50
- },
51
- warnings,
52
- nextSteps: []
53
- };
54
- }
55
- async function runEnvUpdateFile(context, client, projectId, resolved, filePath, assignments, verboseContext) {
56
- const existing = await findVariablesByNaturalKey(client, projectId, assignments.map((assignment) => assignment.key), resolved, context.runtime.signal);
57
- const missingKeys = assignments.map((assignment) => assignment.key).filter((key) => !existing.has(key));
58
- if (missingKeys.length > 0) throw new CliError({
59
- code: "ENV_VARIABLE_NOT_FOUND",
60
- domain: "app",
61
- summary: `${missingKeys.length} environment variable(s) not found in ${formatScopeLabel(resolved.scope)}`,
62
- why: `Missing keys: ${formatKeyList(missingKeys)}.`,
63
- fix: "Split the input file by key state: add missing keys and update existing keys separately.",
64
- exitCode: 1,
65
- nextSteps: splitFileNextSteps(filePath, resolved.scope, {
66
- missingKeys,
67
- first: "add-missing"
68
- }),
69
- meta: { keys: missingKeys }
70
- });
71
- const variables = [];
72
- for (const assignment of assignments) {
73
- const existingVariable = existing.get(assignment.key);
74
- if (!existingVariable) continue;
75
- try {
76
- const { data, error, response } = await client.PATCH("/v1/environment-variables/{envVarId}", {
77
- params: { path: { envVarId: existingVariable.id } },
78
- body: { value: assignment.value },
79
- signal: context.runtime.signal
80
- });
81
- if (error || !data) throw apiCallError(`Failed to update value for ${assignment.key}`, response, error);
82
- variables.push(toMetadata(data.data, resolved.descriptor));
83
- } catch (error) {
84
- throw envFileApplyFailedError("update", filePath, resolved.scope, assignment.key, variables, error);
85
- }
86
- }
87
- return {
88
- command: "project.env.update",
89
- result: {
90
- projectId,
91
- verboseContext,
92
- scope: resolved.descriptor,
93
- variables,
94
- file: {
95
- path: filePath,
96
- count: variables.length
97
- }
98
- },
99
- warnings: [],
100
- nextSteps: []
101
- };
102
- }
103
- async function findVariablesByNaturalKey(client, projectId, keys, resolved, signal) {
104
- const found = /* @__PURE__ */ new Map();
105
- for (const key of keys) {
106
- const row = await findVariableByNaturalKey(client, projectId, key, resolved, signal);
107
- if (row) found.set(key, row);
108
- }
109
- return found;
110
- }
111
- async function missingPreviewDefaultWarnings(client, projectId, scope, keys, signal) {
112
- if (scope.kind !== "branch") return [];
113
- const previewScope = {
114
- scope: {
115
- kind: "role",
116
- role: "preview"
117
- },
118
- descriptor: {
119
- kind: "role",
120
- role: "preview"
121
- },
122
- apiTarget: {
123
- class: "preview",
124
- branchId: null
125
- }
126
- };
127
- const missing = [];
128
- for (const key of keys) if (!await findVariableByNaturalKey(client, projectId, key, previewScope, signal)) missing.push(key);
129
- if (missing.length === 0) return [];
130
- if (missing.length === 1) return [`Variable "${missing[0]}" does not exist in preview. It will only exist on ${formatScopeLabel(scope)}.`];
131
- return [`Variables ${formatKeyList(missing)} do not exist in preview. They will only exist on ${formatScopeLabel(scope)}.`];
132
- }
133
- function envFileApplyFailedError(command, filePath, scope, failedKey, writtenVariables, error) {
134
- const writtenKeys = writtenVariables.map((variable) => variable.key);
135
- const cause = error instanceof CliError ? error.summary : error instanceof Error ? error.message : "Unknown error.";
136
- return new CliError({
137
- code: "ENV_FILE_APPLY_FAILED",
138
- domain: "app",
139
- summary: `Failed to ${command} "${failedKey}" from "${filePath}"`,
140
- why: writtenKeys.length === 0 ? `No variables were written before ${failedKey} failed. Cause: ${cause}` : `Written keys before failure: ${formatKeyList(writtenKeys)}. Cause: ${cause}`,
141
- fix: "Inspect the target scope, then retry the remaining keys once the API issue is resolved.",
142
- exitCode: 1,
143
- nextSteps: [`prisma-cli project env list ${formatScopeFlag(scope)}`, retryStepForApplyFailure(command, filePath, scope, writtenKeys)],
144
- meta: {
145
- file: filePath,
146
- failedKey,
147
- writtenKeys
148
- }
149
- });
150
- }
151
- function retryStepForApplyFailure(command, filePath, scope, writtenKeys) {
152
- if (command === "update") return `prisma-cli project env update --file ${filePath} ${formatScopeFlag(scope)}`;
153
- if (writtenKeys.length === 0) return `prisma-cli project env add --file ${filePath} ${formatScopeFlag(scope)}`;
154
- return `prisma-cli project env add --file <remaining.env> ${formatScopeFlag(scope)}`;
155
- }
156
- function splitFileNextSteps(filePath, scope, options) {
157
- const scopeFlag = formatScopeFlag(scope);
158
- const existingFile = `${filePath}.existing`;
159
- const newFile = `${filePath}.new`;
160
- if (options.first === "update-existing") return [
161
- `# existing keys: ${formatKeyList(options.existingKeys)}`,
162
- `prisma-cli project env update --file ${existingFile} ${scopeFlag}`,
163
- "# new keys only",
164
- `prisma-cli project env add --file ${newFile} ${scopeFlag}`
165
- ];
166
- return [
167
- `# missing keys: ${formatKeyList(options.missingKeys)}`,
168
- `prisma-cli project env add --file ${newFile} ${scopeFlag}`,
169
- "# existing keys only",
170
- `prisma-cli project env update --file ${existingFile} ${scopeFlag}`
171
- ];
172
- }
173
- function formatKeyList(keys) {
174
- return keys.map((key) => `"${key}"`).join(", ");
175
- }
176
- function formatScopeFlag(scope) {
177
- if (scope.kind === "role") return `--role ${scope.role}`;
178
- return `--branch ${scope.branchName}`;
179
- }
180
- //#endregion
181
- export { runEnvAddFile, runEnvUpdateFile };