@prisma/cli 8.0.0-rc.1 → 8.0.0-rc.10

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 (110) hide show
  1. package/README.md +25 -29
  2. package/dist/cli.js +14551 -16
  3. package/dist/{v8/sender.js → sender.js} +1 -1
  4. package/package.json +17 -18
  5. package/dist/adapters/git.js +0 -54
  6. package/dist/adapters/local-state.js +0 -155
  7. package/dist/auth/client.js +0 -30
  8. package/dist/auth/errors.js +0 -50
  9. package/dist/auth/guard.js +0 -39
  10. package/dist/auth/login.js +0 -471
  11. package/dist/auth/operations.js +0 -208
  12. package/dist/auth/recipient.js +0 -42
  13. package/dist/auth/token-storage.js +0 -439
  14. package/dist/auth/workspaces.js +0 -171
  15. package/dist/cli-command.js +0 -14
  16. package/dist/cli-name.js +0 -12
  17. package/dist/cli2.js +0 -136
  18. package/dist/command-arguments.js +0 -12
  19. package/dist/commands/agent/index.js +0 -60
  20. package/dist/commands/app/index.js +0 -350
  21. package/dist/commands/auth/index.js +0 -95
  22. package/dist/commands/branch/index.js +0 -27
  23. package/dist/commands/bucket/index.js +0 -123
  24. package/dist/commands/build/index.js +0 -29
  25. package/dist/commands/database/index.js +0 -249
  26. package/dist/commands/env.js +0 -99
  27. package/dist/commands/feedback/index.js +0 -20
  28. package/dist/commands/git/index.js +0 -36
  29. package/dist/commands/init/index.js +0 -33
  30. package/dist/commands/project/index.js +0 -118
  31. package/dist/commands/version/index.js +0 -18
  32. package/dist/controllers/agent-setup.js +0 -52
  33. package/dist/controllers/agent.js +0 -228
  34. package/dist/controllers/app-env-api.js +0 -55
  35. package/dist/controllers/app-env-file.js +0 -181
  36. package/dist/controllers/app-env.js +0 -502
  37. package/dist/controllers/app.js +0 -2508
  38. package/dist/controllers/auth.js +0 -124
  39. package/dist/controllers/branch.js +0 -92
  40. package/dist/controllers/bucket.js +0 -184
  41. package/dist/controllers/build.js +0 -88
  42. package/dist/controllers/database.js +0 -463
  43. package/dist/controllers/feedback.js +0 -90
  44. package/dist/controllers/init.js +0 -814
  45. package/dist/controllers/project.js +0 -892
  46. package/dist/controllers/select-prompt-port.js +0 -13
  47. package/dist/controllers/version.js +0 -12
  48. package/dist/errors.js +0 -102
  49. package/dist/lib/agent/cli-command.js +0 -20
  50. package/dist/lib/agent/constants.js +0 -12
  51. package/dist/lib/agent/package-manager.js +0 -99
  52. package/dist/lib/agent/setup-status.js +0 -83
  53. package/dist/lib/app/app-provider.js +0 -617
  54. package/dist/lib/app/branch-database-api.js +0 -102
  55. package/dist/lib/app/branch-database-deploy.js +0 -353
  56. package/dist/lib/app/branch-database.js +0 -234
  57. package/dist/lib/app/build-settings.js +0 -98
  58. package/dist/lib/app/build.js +0 -82
  59. package/dist/lib/app/bun-project.js +0 -45
  60. package/dist/lib/app/compute-config.js +0 -145
  61. package/dist/lib/app/deploy-output.js +0 -24
  62. package/dist/lib/app/deploy-plan.js +0 -59
  63. package/dist/lib/app/deploy-progress.js +0 -100
  64. package/dist/lib/app/domain-guidance.js +0 -14
  65. package/dist/lib/app/env-config.js +0 -67
  66. package/dist/lib/app/env-file.js +0 -82
  67. package/dist/lib/app/env-vars.js +0 -50
  68. package/dist/lib/app/local-dev.js +0 -109
  69. package/dist/lib/app/production-deploy-gate.js +0 -162
  70. package/dist/lib/app/read-branch.js +0 -30
  71. package/dist/lib/bucket/provider.js +0 -139
  72. package/dist/lib/database/provider.js +0 -385
  73. package/dist/lib/diagnostics.js +0 -16
  74. package/dist/lib/feedback.js +0 -15
  75. package/dist/lib/fs/home-path.js +0 -24
  76. package/dist/lib/git/local-branch.js +0 -53
  77. package/dist/lib/git/local-status.js +0 -57
  78. package/dist/lib/project/interactive-setup.js +0 -57
  79. package/dist/lib/project/local-pin.js +0 -200
  80. package/dist/lib/project/provider.js +0 -93
  81. package/dist/lib/project/resolution.js +0 -389
  82. package/dist/lib/project/setup.js +0 -138
  83. package/dist/lib/version.js +0 -56
  84. package/dist/lib/workspace-id.js +0 -18
  85. package/dist/output/patterns.js +0 -90
  86. package/dist/presenters/agent.js +0 -74
  87. package/dist/presenters/app-env.js +0 -265
  88. package/dist/presenters/app.js +0 -672
  89. package/dist/presenters/auth.js +0 -184
  90. package/dist/presenters/branch.js +0 -46
  91. package/dist/presenters/bucket.js +0 -174
  92. package/dist/presenters/database.js +0 -462
  93. package/dist/presenters/feedback.js +0 -26
  94. package/dist/presenters/init.js +0 -30
  95. package/dist/presenters/project.js +0 -268
  96. package/dist/presenters/verbose-context.js +0 -64
  97. package/dist/presenters/version.js +0 -29
  98. package/dist/shell/cli-command.js +0 -2
  99. package/dist/shell/command-meta.js +0 -923
  100. package/dist/shell/command-runner.js +0 -119
  101. package/dist/shell/diagnostics-output.js +0 -57
  102. package/dist/shell/global-flags.js +0 -37
  103. package/dist/shell/help.js +0 -90
  104. package/dist/shell/output.js +0 -144
  105. package/dist/shell/prompt.js +0 -48
  106. package/dist/shell/runtime.js +0 -38
  107. package/dist/shell/ui.js +0 -116
  108. package/dist/state-dir.js +0 -12
  109. package/dist/update-check.js +0 -248
  110. package/dist/v8/cli.js +0 -14699
@@ -1,119 +0,0 @@
1
- import { CliError, authConfigInvalidError, authRequiredError, commandCanceledError } from "../errors.js";
2
- import { getCommandDescriptor } from "./command-meta.js";
3
- import { renderSummaryLine } from "./ui.js";
4
- import { isEmptyServiceTokenError } from "../auth/operations.js";
5
- import { resolveGlobalFlags } from "./global-flags.js";
6
- import { createCommandContext } from "./runtime.js";
7
- import { collectCommandDiagnostics } from "../lib/diagnostics.js";
8
- import { renderCommandDiagnostics } from "./diagnostics-output.js";
9
- import { cliErrorToJson, writeHumanError, writeHumanLines, writeJsonError, writeJsonEvent, writeJsonSuccess } from "./output.js";
10
- import { AuthError } from "@prisma/management-api-sdk";
11
- //#region src/shell/command-runner.ts
12
- function toCliError(error, runtime) {
13
- if (isCancellationError(error) || runtime.signal.aborted) return commandCanceledError();
14
- if (error instanceof CliError) return error;
15
- if (error instanceof AuthError) return authRequiredError(["prisma-cli auth login"], { debug: error.message });
16
- if (isEmptyServiceTokenError(error)) return authConfigInvalidError(error.message);
17
- return null;
18
- }
19
- function isCancellationError(error) {
20
- if (!(error instanceof Error)) return false;
21
- return error.name === "AbortError" || error.name === "CancelledError";
22
- }
23
- async function runCommand(runtime, commandName, options, handler, presenter) {
24
- const context = await createCommandContext(runtime, resolveGlobalFlags(runtime.argv, options));
25
- const descriptor = getCommandDescriptor(commandName);
26
- const startedAt = Date.now();
27
- try {
28
- await writeCommandSuccess(context, descriptor, await handler(context), presenter, Date.now() - startedAt);
29
- } catch (error) {
30
- const cliError = toCliError(error, runtime);
31
- if (cliError) {
32
- writeCommandError(context, commandName, cliError);
33
- process.exitCode = cliError.exitCode;
34
- return;
35
- }
36
- throw error;
37
- }
38
- }
39
- async function writeCommandSuccess(context, descriptor, success, presenter, durationMs) {
40
- if (context.flags.json) {
41
- writeJsonSuccess(context.output, {
42
- ...success,
43
- result: presenter.renderJson ? presenter.renderJson(success.result) : success.result
44
- });
45
- return;
46
- }
47
- const stdout = presenter.renderStdout?.(context, descriptor, success.result) ?? [];
48
- if (context.flags.quiet) {
49
- writeStdoutLines(context, stdout);
50
- return;
51
- }
52
- const rendered = presenter.renderHuman(context, descriptor, success.result);
53
- const warningLines = success.warnings.map((warning) => renderSummaryLine(context.ui, "warning", warning));
54
- const diagnostics = await renderBestEffortCommandDiagnostics(context, {
55
- enabled: context.flags.verbose && rendered.length > 0,
56
- durationMs
57
- });
58
- const humanLines = [
59
- ...rendered,
60
- ...warningLines,
61
- ...diagnostics
62
- ];
63
- if (stdout.length > 0 && humanLines.length > 0) humanLines.push("");
64
- writeHumanLines(context.output, humanLines);
65
- writeStdoutLines(context, stdout);
66
- }
67
- function writeCommandError(context, commandName, cliError) {
68
- if (context.flags.json) {
69
- writeJsonError(context.output, commandName, cliError);
70
- return;
71
- }
72
- writeHumanError(context.output, context.ui, cliError, { trace: context.flags.trace });
73
- }
74
- function writeStdoutLines(context, lines) {
75
- if (lines.length > 0) context.output.stdout.write(`${lines.join("\n")}\n`);
76
- }
77
- async function renderBestEffortCommandDiagnostics(context, options) {
78
- if (!options.enabled) return [];
79
- try {
80
- return renderCommandDiagnostics(context, await collectCommandDiagnostics(context, { durationMs: options.durationMs }));
81
- } catch {
82
- return [];
83
- }
84
- }
85
- async function runStreamingCommand(runtime, commandName, options, handler, streamOptions) {
86
- const flags = resolveGlobalFlags(runtime.argv, options);
87
- const context = await createCommandContext(runtime, flags);
88
- try {
89
- await handler(context);
90
- if (flags.json && (streamOptions?.emitJsonSuccessEvent ?? true)) writeJsonEvent(context.output, {
91
- type: "success",
92
- command: commandName,
93
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
94
- result: null,
95
- warnings: [],
96
- nextSteps: [],
97
- nextActions: []
98
- });
99
- } catch (error) {
100
- const cliError = toCliError(error, runtime);
101
- if (cliError) {
102
- if (flags.json) writeJsonEvent(context.output, {
103
- type: "error",
104
- command: commandName,
105
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
106
- error: cliErrorToJson(cliError),
107
- warnings: [],
108
- nextSteps: cliError.nextSteps,
109
- nextActions: cliError.nextActions
110
- });
111
- else writeHumanError(context.output, context.ui, cliError, { trace: flags.trace });
112
- process.exitCode = cliError.exitCode;
113
- return;
114
- }
115
- throw error;
116
- }
117
- }
118
- //#endregion
119
- export { runCommand, runStreamingCommand };
@@ -1,57 +0,0 @@
1
- import { renderVerboseBlock } from "./ui.js";
2
- import { shortenHomePath } from "../lib/fs/home-path.js";
3
- //#region src/shell/diagnostics-output.ts
4
- function renderCommandDiagnostics(context, diagnostics, rows = [], options = {}) {
5
- if (!diagnostics) return [];
6
- const { env } = context.runtime;
7
- const git = diagnostics.git;
8
- return renderVerboseBlock(context.ui, [
9
- ...rows,
10
- ...diagnostics.durationMs === void 0 ? [] : [{
11
- key: "duration",
12
- value: formatDuration(diagnostics.durationMs)
13
- }],
14
- {
15
- key: "cwd",
16
- value: formatLocalPath(diagnostics.cwd, env)
17
- },
18
- {
19
- key: "state file",
20
- value: formatLocalPath(diagnostics.stateFilePath, env)
21
- },
22
- ...git ? [
23
- {
24
- key: "git ref",
25
- value: git.ref ?? "detached",
26
- tone: git.ref ? "default" : "dim"
27
- },
28
- {
29
- key: "git sha",
30
- value: git.sha ?? "unknown",
31
- tone: git.sha ? "default" : "dim"
32
- },
33
- {
34
- key: "git dirty",
35
- value: formatDirtyState(git.dirty),
36
- tone: git.dirty ? "warning" : "dim"
37
- }
38
- ] : [{
39
- key: "git",
40
- value: "not detected",
41
- tone: "dim"
42
- }]
43
- ], { title: options.title ?? "Local context" });
44
- }
45
- function formatLocalPath(value, env) {
46
- return shortenHomePath(value, env);
47
- }
48
- function formatDirtyState(dirty) {
49
- if (dirty === null) return "unknown";
50
- return dirty ? "yes" : "no";
51
- }
52
- function formatDuration(durationMs) {
53
- if (durationMs < 1e3) return `${durationMs}ms`;
54
- return `${(durationMs / 1e3).toFixed(1)}s`;
55
- }
56
- //#endregion
57
- export { renderCommandDiagnostics };
@@ -1,37 +0,0 @@
1
- import { Option } from "commander";
2
- //#region src/shell/global-flags.ts
3
- const COMPACT_GLOBAL_OPTION_FLAGS = [
4
- "--json",
5
- "-q, --quiet",
6
- "-v, --verbose",
7
- "--trace",
8
- "--no-interactive",
9
- "-y, --yes",
10
- "--version"
11
- ];
12
- function addGlobalFlags(command) {
13
- return command.option("--json", "Emit structured JSON output.").option("-q, --quiet", "Reduce human-oriented output.").option("-v, --verbose", "Increase human-oriented output detail.").option("--trace", "Show deeper diagnostics for failures.").option("-y, --yes", "Accept supported confirmation prompts.").addOption(new Option("--interactive", "Force interactive behavior when prompts are supported.")).addOption(new Option("--no-interactive", "Disable interactive behavior and prompts.")).addOption(new Option("--color", "Force color output in supported terminals.")).addOption(new Option("--no-color", "Disable color output."));
14
- }
15
- function addCompactGlobalFlags(command) {
16
- return command.option("--json", "Emit structured JSON output.").option("-q, --quiet", "Reduce human-oriented output.").option("-v, --verbose", "Increase human-oriented output detail.").option("--trace", "Show deeper diagnostics for failures.").addOption(new Option("--no-interactive", "Disable interactive behavior and prompts.")).option("-y, --yes", "Accept supported confirmation prompts.");
17
- }
18
- function getExplicitBoolean(argv, positive, negative) {
19
- for (let index = argv.length - 1; index >= 0; index -= 1) {
20
- const value = argv[index];
21
- if (value === positive) return true;
22
- if (value === negative) return false;
23
- }
24
- }
25
- function resolveGlobalFlags(argv, options) {
26
- return {
27
- json: options.json === true || argv.includes("--json"),
28
- quiet: options.quiet === true || argv.includes("--quiet") || argv.includes("-q"),
29
- verbose: options.verbose === true || argv.includes("--verbose") || argv.includes("-v"),
30
- trace: options.trace === true || argv.includes("--trace"),
31
- yes: options.yes === true || argv.includes("--yes") || argv.includes("-y"),
32
- interactive: getExplicitBoolean(argv, "--interactive", "--no-interactive"),
33
- color: getExplicitBoolean(argv, "--color", "--no-color")
34
- };
35
- }
36
- //#endregion
37
- export { COMPACT_GLOBAL_OPTION_FLAGS, addCompactGlobalFlags, addGlobalFlags, resolveGlobalFlags };
@@ -1,90 +0,0 @@
1
- import { formatDescriptorLabel, getDescriptorForCommand } from "./command-meta.js";
2
- import { createShellUi, padDisplay, wrapText } from "./ui.js";
3
- import { COMPACT_GLOBAL_OPTION_FLAGS, resolveGlobalFlags } from "./global-flags.js";
4
- //#region src/shell/help.ts
5
- function renderHelp(command, runtime) {
6
- const descriptor = getDescriptorForCommand(command);
7
- const ui = createShellUi(runtime, resolveGlobalFlags(runtime.argv, {}));
8
- const rail = ui.isTTY ? ui.dim("│") : "│";
9
- const lines = [`${formatDescriptorLabel(descriptor)} ${ui.dim("→")} ${ui.dim(descriptor.description)}`, ""];
10
- const visibleCommands = command.commands.filter((candidate) => candidate.name() !== "help" && !candidate.hidden);
11
- const visibleOptions = command.options.filter((candidate) => !candidate.hidden);
12
- if (visibleCommands.length > 0) lines.push(...renderCommandRows(rail, ui, visibleCommands));
13
- lines.push(...renderLongDescription(rail, ui, descriptor.longDescription));
14
- lines.push(...renderVisibleOptions(rail, ui, visibleCommands, visibleOptions));
15
- lines.push(...renderExamples(rail, runtime, descriptor.examples));
16
- lines.push(...renderDocsPath(rail, ui, descriptor.docsPath));
17
- lines.push("");
18
- return `${lines.join("\n")}`;
19
- }
20
- function renderLongDescription(rail, ui, longDescription) {
21
- if (!longDescription) return [];
22
- return [`${rail}`, ...wrapText(longDescription, Math.max(ui.width - 3, 40)).map((line) => `${rail} ${line}`)];
23
- }
24
- function renderVisibleOptions(rail, ui, visibleCommands, visibleOptions) {
25
- if (visibleOptions.length === 0) return [];
26
- const lines = visibleCommands.length > 0 ? [`${rail}`] : [];
27
- if (shouldLabelGlobalOptions(visibleCommands, visibleOptions)) lines.push(`${rail} Global options:`);
28
- return [...lines, ...renderOptionRows(rail, ui, visibleOptions)];
29
- }
30
- function shouldLabelGlobalOptions(visibleCommands, visibleOptions) {
31
- return visibleCommands.length > 0 && visibleOptions.every((option) => COMPACT_GLOBAL_OPTION_FLAGS.includes(option.flags));
32
- }
33
- function renderExamples(rail, runtime, examples) {
34
- const resolvedExamples = typeof examples === "function" ? examples(runtime) : examples;
35
- if (!resolvedExamples || resolvedExamples.length === 0) return [];
36
- return [
37
- `${rail}`,
38
- `${rail} Examples:`,
39
- ...resolvedExamples.map((example) => `${rail} $ ${example}`)
40
- ];
41
- }
42
- function renderDocsPath(rail, ui, docsPath) {
43
- if (!docsPath) return [];
44
- return [`${rail}`, `${rail} ${ui.accent(padDisplay("Read more", 16))} ${ui.link(docsPath)}`];
45
- }
46
- function renderCommandRows(rail, ui, commands) {
47
- return renderAlignedRows(rail, ui, commands.map((command) => {
48
- const descriptor = getDescriptorForCommand(command);
49
- return {
50
- term: renderCommandTerm(command),
51
- description: descriptor.description
52
- };
53
- }));
54
- }
55
- function renderOptionRows(rail, ui, options) {
56
- return renderAlignedRows(rail, ui, options.map((option) => ({
57
- term: option.flags,
58
- description: option.description || "",
59
- defaultValue: option.defaultValueDescription ?? formatDefaultValue(option.defaultValue)
60
- })));
61
- }
62
- function renderAlignedRows(rail, ui, rows) {
63
- const termWidth = rows.reduce((width, row) => Math.max(width, row.term.length), 0);
64
- const descriptionWidth = Math.max(ui.width - 3 - termWidth - 4, 30);
65
- const lines = [];
66
- for (const row of rows) {
67
- const [firstLine, ...rest] = wrapText(row.description, descriptionWidth, " ".repeat(termWidth + 2));
68
- lines.push(`${rail} ${ui.accent(padDisplay(row.term, termWidth))} ${firstLine}`);
69
- for (const line of rest) lines.push(`${rail} ${" ".repeat(termWidth)} ${line.trimStart()}`);
70
- if (row.defaultValue) lines.push(`${rail} ${" ".repeat(termWidth)} ${ui.dim(`default: ${row.defaultValue}`)}`);
71
- }
72
- return lines;
73
- }
74
- function renderCommandTerm(command) {
75
- const argumentsList = command.registeredArguments.map(renderArgumentLabel).join(" ");
76
- return `${command.name()}${argumentsList ? ` ${argumentsList}` : ""}`;
77
- }
78
- function renderArgumentLabel(argument) {
79
- const name = argument.name();
80
- return argument.required ? `<${name}>` : `[${name}]`;
81
- }
82
- function formatDefaultValue(value) {
83
- if (value === void 0) return null;
84
- if (Array.isArray(value)) return value.join(", ");
85
- if (typeof value === "boolean" || typeof value === "number") return String(value);
86
- if (typeof value === "string" && value.length > 0) return value;
87
- return null;
88
- }
89
- //#endregion
90
- export { renderHelp };
@@ -1,144 +0,0 @@
1
- import { formatCommandArgument } from "../command-arguments.js";
2
- import { renderNextSteps, renderSummaryLine } from "./ui.js";
3
- //#region src/shell/output.ts
4
- function writeJsonSuccess(output, success) {
5
- output.stdout.write(`${JSON.stringify({
6
- ok: true,
7
- nextActions: [],
8
- ...success
9
- }, null, 2)}\n`);
10
- }
11
- function writeJsonEvent(output, event) {
12
- output.stdout.write(`${JSON.stringify(event)}\n`);
13
- }
14
- function cliErrorToJson(error) {
15
- return {
16
- code: error.code,
17
- domain: error.domain,
18
- severity: error.severity,
19
- summary: error.summary,
20
- why: error.why,
21
- fix: error.fix,
22
- where: error.where,
23
- meta: error.meta,
24
- docsUrl: error.docsUrl
25
- };
26
- }
27
- function formatUnexpectedError(error, trace, feedbackCommand) {
28
- const feedbackLine = feedbackCommand ? `Tell us what happened: ${feedbackCommand}` : null;
29
- const debug = error instanceof Error ? error.stack ?? error.message : String(error);
30
- if (trace) return [
31
- debug,
32
- ...feedbackLine ? [feedbackLine] : [],
33
- ""
34
- ].join("\n");
35
- return [
36
- `Unexpected CLI error: ${error instanceof Error && error.message ? error.message : String(error)}`,
37
- "More: Re-run with --trace for deeper diagnostics",
38
- ...feedbackLine ? [feedbackLine] : [],
39
- ""
40
- ].join("\n");
41
- }
42
- /** Command groups whose second argv token names the subcommand. */
43
- const COMMAND_GROUPS = new Set([
44
- "agent",
45
- "auth",
46
- "project",
47
- "git",
48
- "branch",
49
- "build",
50
- "database",
51
- "app"
52
- ]);
53
- /** Best-effort `command` label for a crash that predates envelope assembly. */
54
- function unexpectedErrorCommandLabel(argv) {
55
- const [group, action] = argv.filter((arg) => !arg.startsWith("-"));
56
- if (!group) return "unknown";
57
- return action && COMMAND_GROUPS.has(group) ? `${group}.${action}` : group;
58
- }
59
- /**
60
- * Pre-filled feedback command for a crash, so the report arrives carrying the
61
- * failing command and the error's first line.
62
- */
63
- function unexpectedErrorFeedbackCommand(argv, error) {
64
- return `prisma-cli feedback ${formatCommandArgument(`${unexpectedErrorCommandLabel(argv).replace(".", " ")} crashed: ${(error instanceof Error && error.message ? error.message : String(error)).split("\n")[0]}`.slice(0, 200))}`;
65
- }
66
- /**
67
- * A crash must not break the `--json` contract: agents still get a structured
68
- * envelope, with a recover action pointing at the feedback command.
69
- */
70
- function writeJsonUnexpectedError(output, argv, error) {
71
- const feedbackCommand = unexpectedErrorFeedbackCommand(argv, error);
72
- output.stdout.write(`${JSON.stringify({
73
- ok: false,
74
- command: unexpectedErrorCommandLabel(argv),
75
- error: {
76
- code: "UNEXPECTED_ERROR",
77
- domain: "cli",
78
- severity: "error",
79
- summary: "Unexpected CLI error",
80
- why: error instanceof Error && error.message ? error.message : String(error),
81
- fix: "Re-run with --trace for deeper diagnostics, and report the crash.",
82
- where: null,
83
- meta: {},
84
- docsUrl: null
85
- },
86
- warnings: [],
87
- nextSteps: [feedbackCommand],
88
- nextActions: [{
89
- kind: "run-command",
90
- journey: "recover",
91
- label: "Report this crash to the Prisma team",
92
- command: feedbackCommand,
93
- reason: "This looks like a CLI bug; the pre-filled report carries the failing command and error."
94
- }]
95
- }, null, 2)}\n`);
96
- }
97
- function writeJsonError(output, command, error) {
98
- output.stdout.write(`${JSON.stringify({
99
- ok: false,
100
- command,
101
- error: cliErrorToJson(error),
102
- warnings: [],
103
- nextSteps: error.nextSteps,
104
- nextActions: error.nextActions
105
- }, null, 2)}\n`);
106
- }
107
- function writeHumanLines(output, lines) {
108
- if (lines.length === 0) return;
109
- output.stderr.write(`${lines.join("\n")}\n`);
110
- }
111
- function writeHumanError(output, ui, error, options) {
112
- if (error.humanLines && error.humanLines.length > 0) {
113
- const lines = [...error.humanLines];
114
- if (options.trace && error.debug) {
115
- lines.push("");
116
- lines.push("Trace:");
117
- lines.push(...error.debug.trimEnd().split("\n"));
118
- }
119
- lines.push(...renderNextSteps(error.nextSteps));
120
- writeHumanLines(output, lines);
121
- return;
122
- }
123
- const lines = [renderSummaryLine(ui, "error", `${error.summary} [${error.code}]`)];
124
- if (error.where) lines.push(...["", `Where: ${error.where}`]);
125
- if (error.why) {
126
- if (!error.where) lines.push("");
127
- lines.push(`Why: ${error.why}`);
128
- }
129
- if (error.fix) lines.push(`Fix: ${error.fix}`);
130
- if (options.trace) {
131
- if (error.debug) {
132
- lines.push("");
133
- lines.push("Trace:");
134
- lines.push(...error.debug.trimEnd().split("\n"));
135
- }
136
- } else {
137
- lines.push("");
138
- lines.push("More: Re-run with --trace for deeper diagnostics");
139
- }
140
- lines.push(...renderNextSteps(error.nextSteps));
141
- writeHumanLines(output, lines);
142
- }
143
- //#endregion
144
- export { cliErrorToJson, formatUnexpectedError, unexpectedErrorFeedbackCommand, writeHumanError, writeHumanLines, writeJsonError, writeJsonEvent, writeJsonSuccess, writeJsonUnexpectedError };
@@ -1,48 +0,0 @@
1
- import { isUsageError, usageError } from "../errors.js";
2
- import { confirm, isCancel, select, text } from "@clack/prompts";
3
- //#region src/shell/prompt.ts
4
- const PROMPT_CANCELED_SUMMARY = "Interactive prompt canceled";
5
- async function selectPrompt(options) {
6
- const promptOptions = options.choices.map((choice) => ({
7
- label: choice.label,
8
- value: choice.value
9
- }));
10
- const response = await select({
11
- input: options.input,
12
- output: options.output,
13
- signal: options.signal,
14
- message: options.message,
15
- options: promptOptions
16
- });
17
- if (isCancel(response)) throw usageError(PROMPT_CANCELED_SUMMARY, "The command was canceled before a selection was made.", "Re-run the command and choose an option to continue.");
18
- return response;
19
- }
20
- async function textPrompt(options) {
21
- const response = await text({
22
- input: options.input,
23
- output: options.output,
24
- signal: options.signal,
25
- message: options.message,
26
- placeholder: options.placeholder,
27
- validate: options.validate
28
- });
29
- if (isCancel(response)) throw usageError(PROMPT_CANCELED_SUMMARY, "The command was canceled before a value was entered.", "Re-run the command and provide a value to continue.");
30
- return response;
31
- }
32
- async function confirmPrompt(options) {
33
- const response = await confirm({
34
- input: options.input,
35
- output: options.output,
36
- signal: options.signal,
37
- message: options.message,
38
- initialValue: options.initialValue ?? false
39
- });
40
- if (isCancel(response)) throw usageError(PROMPT_CANCELED_SUMMARY, "The command was canceled before a confirmation was made.", "Re-run the command and choose an option to continue.");
41
- return response;
42
- }
43
- function isPromptCancelError(error) {
44
- return isUsageError(error, PROMPT_CANCELED_SUMMARY);
45
- }
46
- function disposePromptState(_input) {}
47
- //#endregion
48
- export { confirmPrompt, disposePromptState, isPromptCancelError, selectPrompt, textPrompt };
@@ -1,38 +0,0 @@
1
- import { createShellUi } from "./ui.js";
2
- import { LocalStateStore } from "../adapters/local-state.js";
3
- import { resolveStateDir } from "../state-dir.js";
4
- import { renderHelp } from "./help.js";
5
- //#region src/shell/runtime.ts
6
- function configureRuntimeCommand(command, runtime) {
7
- return command.helpCommand(false).configureHelp({ formatHelp: (configuredCommand) => renderHelp(configuredCommand, runtime) }).configureOutput({
8
- writeOut: (text) => {
9
- runtime.stderr.write(text);
10
- },
11
- writeErr: (text) => {
12
- runtime.stderr.write(text);
13
- },
14
- outputError: (text, write) => {
15
- write(text);
16
- }
17
- }).exitOverride();
18
- }
19
- async function createCommandContext(runtime, flags) {
20
- return {
21
- stateStore: new LocalStateStore(await resolveStateDir(runtime), runtime.signal),
22
- output: {
23
- stdout: runtime.stdout,
24
- stderr: runtime.stderr
25
- },
26
- flags,
27
- runtime,
28
- ui: createShellUi(runtime, flags)
29
- };
30
- }
31
- function canPrompt(context) {
32
- if (context.flags.json) return false;
33
- if (context.flags.interactive === false) return false;
34
- if (context.runtime.env.CI && context.flags.interactive !== true) return false;
35
- return Boolean(context.runtime.stdin.isTTY && context.runtime.stderr.isTTY);
36
- }
37
- //#endregion
38
- export { canPrompt, configureRuntimeCommand, createCommandContext };
package/dist/shell/ui.js DELETED
@@ -1,116 +0,0 @@
1
- import { createColors } from "colorette";
2
- import stringWidth from "string-width";
3
- import stripAnsi from "strip-ansi";
4
- import wrapAnsi from "wrap-ansi";
5
- //#region src/shell/ui.ts
6
- const URL_CREDENTIALS_PATTERN = /:\/\/[^:@/\s]+:[^@/\s]+@/g;
7
- const DEFAULT_WIDTH = 80;
8
- function createShellUi(runtime, flags) {
9
- const isTTY = Boolean(runtime.stderr.isTTY);
10
- const colorEnabled = resolveColorEnabled(runtime, flags, isTTY);
11
- const colors = createColors({ useColor: colorEnabled });
12
- return {
13
- isTTY,
14
- colorEnabled,
15
- width: runtime.stderr.columns && runtime.stderr.columns > 0 ? runtime.stderr.columns : DEFAULT_WIDTH,
16
- quiet: flags.quiet,
17
- verbose: flags.verbose,
18
- trace: flags.trace,
19
- accent: (text) => colors.cyan(text),
20
- success: (text) => colors.greenBright(text),
21
- error: (text) => colors.redBright(text),
22
- warning: (text) => colors.yellow(text),
23
- info: (text) => colors.blue(text),
24
- link: (text) => colors.blue(text),
25
- dim: (text) => colors.dim(text),
26
- strong: (text) => colors.bold(text)
27
- };
28
- }
29
- function renderCommandHeader(ui, options) {
30
- if (!ui.isTTY) return [];
31
- const rows = options.rows ?? [];
32
- const lines = [`${ui.strong(options.commandLabel)} ${ui.dim("→")} ${ui.dim(options.description)}`, ""];
33
- const rail = ui.dim("│");
34
- const keyWidth = rows.length > 0 ? Math.max(...rows.map((row) => stringWidth(`${row.key}:`)), stringWidth("Read more")) : stringWidth("Read more");
35
- for (const row of rows) lines.push(`${rail} ${ui.accent(padDisplay(`${row.key}:`, keyWidth))} ${formatHeaderValue(ui, row)}`);
36
- if (rows.length > 0 || options.docsPath) lines.push(rail);
37
- if (options.docsPath) lines.push(`${rail} ${ui.accent(padDisplay("Read more", keyWidth))} ${ui.link(options.docsPath)}`);
38
- lines.push("");
39
- return lines;
40
- }
41
- function renderSummaryLine(ui, status, text) {
42
- return `${status === "success" ? ui.success("✔") : status === "error" ? ui.error("✘") : status === "warning" ? ui.warning("⚠") : ui.info("ℹ")} ${text}`;
43
- }
44
- function renderNextSteps(steps) {
45
- if (steps.length === 0) return [];
46
- return [
47
- "",
48
- steps.length === 1 ? "Next step:" : "Next steps:",
49
- ...steps.map((step) => `- ${step}`)
50
- ];
51
- }
52
- function renderVerboseBlock(ui, rows, options = {}) {
53
- if (!ui.verbose || rows.length === 0) return [];
54
- const title = options.title ?? "Details";
55
- const keyWidth = Math.max(...rows.map((row) => stringWidth(`${row.key}:`)));
56
- const rail = ui.dim("│");
57
- return [
58
- "",
59
- `${ui.dim(title)}:`,
60
- ...rows.map((row) => `${rail} ${ui.accent(padDisplay(`${row.key}:`, keyWidth))} ${formatVerboseValue(ui, row)}`)
61
- ];
62
- }
63
- function formatColumns(columns, widths) {
64
- return columns.map((value, index) => padDisplay(value, widths[index])).join(" ").trimEnd();
65
- }
66
- function wrapText(text, width, indent = "") {
67
- return wrapAnsi(text, width, {
68
- hard: false,
69
- trim: false
70
- }).split("\n").map((line, index) => index === 0 ? line : `${indent}${line}`);
71
- }
72
- function padDisplay(text, width) {
73
- const padding = Math.max(width - stringWidth(stripAnsi(text)), 0);
74
- return `${text}${" ".repeat(padding)}`;
75
- }
76
- function maskValue(value) {
77
- return maskEmailLocalParts(value).replace(URL_CREDENTIALS_PATTERN, "://****:****@");
78
- }
79
- function maskEmailLocalParts(value) {
80
- let masked = "";
81
- let segmentStart = 0;
82
- for (let index = 0; index < value.length; index += 1) {
83
- if (value[index] !== "@") continue;
84
- let localStart = index;
85
- while (localStart > segmentStart && isEmailLocalPartChar(value[localStart - 1])) localStart -= 1;
86
- if (localStart === index) continue;
87
- masked += `${value.slice(segmentStart, localStart)}****@`;
88
- segmentStart = index + 1;
89
- }
90
- return masked + value.slice(segmentStart);
91
- }
92
- function isEmailLocalPartChar(char) {
93
- return char >= "A" && char <= "Z" || char >= "a" && char <= "z" || char >= "0" && char <= "9" || char === "!" || char === "#" || char === "$" || char === "." || char === "&" || char === "'" || char === "*" || char === "%" || char === "+" || char === "-" || char === "/" || char === "=" || char === "?" || char === "^" || char === "_" || char === "`" || char === "{" || char === "|" || char === "}" || char === "~";
94
- }
95
- function resolveColorEnabled(runtime, flags, isTTY) {
96
- if (flags.color === true) return true;
97
- if (flags.color === false) return false;
98
- if (runtime.env.NO_COLOR !== void 0) return false;
99
- return isTTY;
100
- }
101
- function formatHeaderValue(ui, row) {
102
- const value = row.sensitive ? maskValue(row.value) : row.value;
103
- if (row.tone === "dim") return ui.dim(value);
104
- if (row.tone === "link") return ui.link(value);
105
- return value;
106
- }
107
- function formatVerboseValue(ui, row) {
108
- const value = row.sensitive ? maskValue(row.value) : row.value;
109
- if (row.tone === "dim") return ui.dim(value);
110
- if (row.tone === "success") return ui.success(value);
111
- if (row.tone === "warning") return ui.warning(value);
112
- if (row.tone === "link") return ui.link(value);
113
- return value;
114
- }
115
- //#endregion
116
- export { createShellUi, formatColumns, maskValue, padDisplay, renderCommandHeader, renderNextSteps, renderSummaryLine, renderVerboseBlock, wrapText };
package/dist/state-dir.js DELETED
@@ -1,12 +0,0 @@
1
- import path from "node:path";
2
- import { findComputeConfigDir } from "@prisma/compute-sdk/config";
3
- //#region src/state-dir.ts
4
- const DEFAULT_STATE_DIR_NAME = path.join(".prisma", "cli");
5
- async function resolveStateDir(inputs) {
6
- const explicitStateDir = inputs.stateDir ?? inputs.env.PRISMA_CLI_STATE_DIR;
7
- if (explicitStateDir) return explicitStateDir;
8
- const projectDir = await findComputeConfigDir(inputs.cwd, inputs.signal);
9
- return path.join(projectDir ?? inputs.cwd, DEFAULT_STATE_DIR_NAME);
10
- }
11
- //#endregion
12
- export { DEFAULT_STATE_DIR_NAME, resolveStateDir };