@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.
- package/README.md +26 -28
- package/dist/cli.js +14551 -16
- package/dist/payload-B88Qvzxk-CrtTXSOe.js +34 -0
- package/dist/sender.js +192 -0
- package/package.json +26 -19
- package/dist/adapters/git.js +0 -54
- package/dist/adapters/local-state.js +0 -144
- package/dist/adapters/mock-api.js +0 -136
- package/dist/adapters/token-storage.js +0 -418
- package/dist/cli2.js +0 -119
- package/dist/commands/app/index.js +0 -345
- package/dist/commands/auth/index.js +0 -96
- package/dist/commands/branch/index.js +0 -27
- package/dist/commands/database/index.js +0 -159
- package/dist/commands/env.js +0 -99
- package/dist/commands/git/index.js +0 -36
- package/dist/commands/project/index.js +0 -69
- package/dist/commands/version/index.js +0 -18
- package/dist/controllers/app-env-api.js +0 -54
- package/dist/controllers/app-env-file.js +0 -181
- package/dist/controllers/app-env.js +0 -502
- package/dist/controllers/app.js +0 -2443
- package/dist/controllers/auth.js +0 -316
- package/dist/controllers/branch.js +0 -103
- package/dist/controllers/database.js +0 -318
- package/dist/controllers/project.js +0 -731
- package/dist/controllers/select-prompt-port.js +0 -12
- package/dist/controllers/version.js +0 -12
- package/dist/lib/app/app-interaction.js +0 -5
- package/dist/lib/app/app-provider.js +0 -544
- package/dist/lib/app/branch-database-api.js +0 -102
- package/dist/lib/app/branch-database-deploy.js +0 -325
- package/dist/lib/app/branch-database.js +0 -215
- package/dist/lib/app/build-settings.js +0 -93
- package/dist/lib/app/build.js +0 -80
- package/dist/lib/app/bun-project.js +0 -45
- package/dist/lib/app/compute-config.js +0 -147
- package/dist/lib/app/deploy-output.js +0 -24
- package/dist/lib/app/deploy-plan.js +0 -58
- package/dist/lib/app/deploy-progress.js +0 -100
- package/dist/lib/app/domain-guidance.js +0 -14
- package/dist/lib/app/env-config.js +0 -67
- package/dist/lib/app/env-file.js +0 -82
- package/dist/lib/app/env-vars.js +0 -50
- package/dist/lib/app/local-dev.js +0 -109
- package/dist/lib/app/production-deploy-gate.js +0 -161
- package/dist/lib/app/read-branch.js +0 -30
- package/dist/lib/auth/auth-ops.js +0 -158
- package/dist/lib/auth/client.js +0 -22
- package/dist/lib/auth/guard.js +0 -38
- package/dist/lib/auth/login.js +0 -330
- package/dist/lib/database/provider.js +0 -167
- package/dist/lib/diagnostics.js +0 -15
- package/dist/lib/fs/home-path.js +0 -24
- package/dist/lib/git/local-branch.js +0 -53
- package/dist/lib/git/local-status.js +0 -57
- package/dist/lib/project/interactive-setup.js +0 -56
- package/dist/lib/project/local-pin.js +0 -200
- package/dist/lib/project/resolution.js +0 -386
- package/dist/lib/project/setup.js +0 -135
- package/dist/lib/version.js +0 -55
- package/dist/output/patterns.js +0 -90
- package/dist/presenters/app-env.js +0 -265
- package/dist/presenters/app.js +0 -646
- package/dist/presenters/auth.js +0 -183
- package/dist/presenters/branch.js +0 -46
- package/dist/presenters/database.js +0 -274
- package/dist/presenters/project.js +0 -174
- package/dist/presenters/verbose-context.js +0 -64
- package/dist/presenters/version.js +0 -29
- package/dist/shell/command-arguments.js +0 -6
- package/dist/shell/command-meta.js +0 -622
- package/dist/shell/command-runner.js +0 -112
- package/dist/shell/diagnostics-output.js +0 -57
- package/dist/shell/errors.js +0 -134
- package/dist/shell/global-flags.js +0 -37
- package/dist/shell/help.js +0 -89
- package/dist/shell/output.js +0 -82
- package/dist/shell/prompt.js +0 -41
- package/dist/shell/runtime.js +0 -55
- package/dist/shell/ui.js +0 -116
- package/dist/shell/update-check.js +0 -247
- package/dist/use-cases/auth.js +0 -145
- package/dist/use-cases/branch.js +0 -47
- package/dist/use-cases/create-cli-gateways.js +0 -68
- package/dist/use-cases/project.js +0 -30
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { CliError, authConfigInvalidError, authRequiredError, commandCanceledError } from "./errors.js";
|
|
2
|
-
import { getCommandDescriptor } from "./command-meta.js";
|
|
3
|
-
import { resolveGlobalFlags } from "./global-flags.js";
|
|
4
|
-
import { createCommandContext } from "./runtime.js";
|
|
5
|
-
import { cliErrorToJson, writeHumanError, writeHumanLines, writeJsonError, writeJsonEvent, writeJsonSuccess } from "./output.js";
|
|
6
|
-
import { collectCommandDiagnostics } from "../lib/diagnostics.js";
|
|
7
|
-
import { renderCommandDiagnostics } from "./diagnostics-output.js";
|
|
8
|
-
import { AuthError } from "@prisma/management-api-sdk";
|
|
9
|
-
//#region src/shell/command-runner.ts
|
|
10
|
-
function toCliError(error, runtime) {
|
|
11
|
-
if (isCancellationError(error) || runtime.signal.aborted) return commandCanceledError();
|
|
12
|
-
if (error instanceof CliError) return error;
|
|
13
|
-
if (error instanceof AuthError) return authRequiredError(["prisma-cli auth login"], { debug: error.message });
|
|
14
|
-
if (error instanceof Error && error.message.startsWith("PRISMA_SERVICE_TOKEN is set but empty")) return authConfigInvalidError(error.message);
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
function isCancellationError(error) {
|
|
18
|
-
if (!(error instanceof Error)) return false;
|
|
19
|
-
return error.name === "AbortError" || error.name === "CancelledError";
|
|
20
|
-
}
|
|
21
|
-
async function runCommand(runtime, commandName, options, handler, presenter) {
|
|
22
|
-
const context = await createCommandContext(runtime, resolveGlobalFlags(runtime.argv, options));
|
|
23
|
-
const descriptor = getCommandDescriptor(commandName);
|
|
24
|
-
const startedAt = Date.now();
|
|
25
|
-
try {
|
|
26
|
-
await writeCommandSuccess(context, descriptor, await handler(context), presenter, Date.now() - startedAt);
|
|
27
|
-
} catch (error) {
|
|
28
|
-
const cliError = toCliError(error, runtime);
|
|
29
|
-
if (cliError) {
|
|
30
|
-
writeCommandError(context, commandName, cliError);
|
|
31
|
-
process.exitCode = cliError.exitCode;
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
async function writeCommandSuccess(context, descriptor, success, presenter, durationMs) {
|
|
38
|
-
if (context.flags.json) {
|
|
39
|
-
writeJsonSuccess(context.output, {
|
|
40
|
-
...success,
|
|
41
|
-
result: presenter.renderJson ? presenter.renderJson(success.result) : success.result
|
|
42
|
-
});
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const stdout = presenter.renderStdout?.(context, descriptor, success.result) ?? [];
|
|
46
|
-
if (context.flags.quiet) {
|
|
47
|
-
writeStdoutLines(context, stdout);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const rendered = presenter.renderHuman(context, descriptor, success.result);
|
|
51
|
-
const diagnostics = await renderBestEffortCommandDiagnostics(context, {
|
|
52
|
-
enabled: context.flags.verbose && rendered.length > 0,
|
|
53
|
-
durationMs
|
|
54
|
-
});
|
|
55
|
-
const humanLines = [...rendered, ...diagnostics];
|
|
56
|
-
if (stdout.length > 0 && humanLines.length > 0) humanLines.push("");
|
|
57
|
-
writeHumanLines(context.output, humanLines);
|
|
58
|
-
writeStdoutLines(context, stdout);
|
|
59
|
-
}
|
|
60
|
-
function writeCommandError(context, commandName, cliError) {
|
|
61
|
-
if (context.flags.json) {
|
|
62
|
-
writeJsonError(context.output, commandName, cliError);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
writeHumanError(context.output, context.ui, cliError, { trace: context.flags.trace });
|
|
66
|
-
}
|
|
67
|
-
function writeStdoutLines(context, lines) {
|
|
68
|
-
if (lines.length > 0) context.output.stdout.write(`${lines.join("\n")}\n`);
|
|
69
|
-
}
|
|
70
|
-
async function renderBestEffortCommandDiagnostics(context, options) {
|
|
71
|
-
if (!options.enabled) return [];
|
|
72
|
-
try {
|
|
73
|
-
return renderCommandDiagnostics(context, await collectCommandDiagnostics(context, { durationMs: options.durationMs }));
|
|
74
|
-
} catch {
|
|
75
|
-
return [];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
async function runStreamingCommand(runtime, commandName, options, handler) {
|
|
79
|
-
const flags = resolveGlobalFlags(runtime.argv, options);
|
|
80
|
-
const context = await createCommandContext(runtime, flags);
|
|
81
|
-
try {
|
|
82
|
-
await handler(context);
|
|
83
|
-
if (flags.json) writeJsonEvent(context.output, {
|
|
84
|
-
type: "success",
|
|
85
|
-
command: commandName,
|
|
86
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
87
|
-
result: null,
|
|
88
|
-
warnings: [],
|
|
89
|
-
nextSteps: [],
|
|
90
|
-
nextActions: []
|
|
91
|
-
});
|
|
92
|
-
} catch (error) {
|
|
93
|
-
const cliError = toCliError(error, runtime);
|
|
94
|
-
if (cliError) {
|
|
95
|
-
if (flags.json) writeJsonEvent(context.output, {
|
|
96
|
-
type: "error",
|
|
97
|
-
command: commandName,
|
|
98
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
99
|
-
error: cliErrorToJson(cliError),
|
|
100
|
-
warnings: [],
|
|
101
|
-
nextSteps: cliError.nextSteps,
|
|
102
|
-
nextActions: cliError.nextActions
|
|
103
|
-
});
|
|
104
|
-
else writeHumanError(context.output, context.ui, cliError, { trace: flags.trace });
|
|
105
|
-
process.exitCode = cliError.exitCode;
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
throw error;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
//#endregion
|
|
112
|
-
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 };
|
package/dist/shell/errors.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
//#region src/shell/errors.ts
|
|
2
|
-
var CliError = class extends Error {
|
|
3
|
-
code;
|
|
4
|
-
domain;
|
|
5
|
-
severity;
|
|
6
|
-
summary;
|
|
7
|
-
why;
|
|
8
|
-
fix;
|
|
9
|
-
debug;
|
|
10
|
-
where;
|
|
11
|
-
meta;
|
|
12
|
-
docsUrl;
|
|
13
|
-
exitCode;
|
|
14
|
-
nextSteps;
|
|
15
|
-
nextActions;
|
|
16
|
-
humanLines;
|
|
17
|
-
constructor(options) {
|
|
18
|
-
super(options.summary);
|
|
19
|
-
this.name = "CliError";
|
|
20
|
-
this.code = options.code;
|
|
21
|
-
this.domain = options.domain;
|
|
22
|
-
this.severity = "error";
|
|
23
|
-
this.summary = options.summary;
|
|
24
|
-
this.why = options.why;
|
|
25
|
-
this.fix = options.fix;
|
|
26
|
-
this.debug = options.debug ?? null;
|
|
27
|
-
this.where = options.where ?? null;
|
|
28
|
-
this.meta = options.meta ?? {};
|
|
29
|
-
this.docsUrl = options.docsUrl ?? null;
|
|
30
|
-
this.exitCode = options.exitCode ?? 1;
|
|
31
|
-
this.nextSteps = options.nextSteps ?? [];
|
|
32
|
-
this.nextActions = options.nextActions ?? [];
|
|
33
|
-
this.humanLines = options.humanLines && options.humanLines.length > 0 ? [...options.humanLines] : null;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
function usageError(summary, why, fix, nextSteps = [], domain = "cli") {
|
|
37
|
-
return new CliError({
|
|
38
|
-
code: "USAGE_ERROR",
|
|
39
|
-
domain,
|
|
40
|
-
summary,
|
|
41
|
-
why,
|
|
42
|
-
fix,
|
|
43
|
-
exitCode: 2,
|
|
44
|
-
nextSteps
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
function authRequiredError(nextSteps = ["prisma-cli auth login"], options = {}) {
|
|
48
|
-
return new CliError({
|
|
49
|
-
code: "AUTH_REQUIRED",
|
|
50
|
-
domain: "auth",
|
|
51
|
-
summary: "Authentication required",
|
|
52
|
-
why: "This command needs an authenticated session.",
|
|
53
|
-
fix: "Run prisma-cli auth login, or rerun the command in a TTY to sign in interactively.",
|
|
54
|
-
debug: options.debug,
|
|
55
|
-
exitCode: 1,
|
|
56
|
-
nextSteps
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function authConfigInvalidError(message) {
|
|
60
|
-
return new CliError({
|
|
61
|
-
code: "AUTH_CONFIG_INVALID",
|
|
62
|
-
domain: "auth",
|
|
63
|
-
summary: "Authentication configuration is invalid",
|
|
64
|
-
why: message,
|
|
65
|
-
fix: "Provide a valid PRISMA_SERVICE_TOKEN value, or unset the variable to use local OAuth login.",
|
|
66
|
-
exitCode: 1,
|
|
67
|
-
nextSteps: ["prisma-cli auth login"]
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function commandCanceledError() {
|
|
71
|
-
return new CliError({
|
|
72
|
-
code: "COMMAND_CANCELED",
|
|
73
|
-
domain: "cli",
|
|
74
|
-
summary: "Command canceled",
|
|
75
|
-
why: null,
|
|
76
|
-
fix: null,
|
|
77
|
-
exitCode: 130,
|
|
78
|
-
humanLines: ["Command canceled [COMMAND_CANCELED]"]
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
function workspaceRequiredError() {
|
|
82
|
-
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");
|
|
83
|
-
}
|
|
84
|
-
function workspaceSwitchUnavailableError() {
|
|
85
|
-
return new CliError({
|
|
86
|
-
code: "WORKSPACE_SWITCH_UNAVAILABLE",
|
|
87
|
-
domain: "auth",
|
|
88
|
-
summary: "Workspace switching is unavailable",
|
|
89
|
-
why: "PRISMA_SERVICE_TOKEN is set, so authenticated commands use that token instead of local OAuth workspaces.",
|
|
90
|
-
fix: "Unset PRISMA_SERVICE_TOKEN to switch between local OAuth workspaces, or use a token for the workspace you want.",
|
|
91
|
-
exitCode: 1,
|
|
92
|
-
nextSteps: ["unset PRISMA_SERVICE_TOKEN", "prisma-cli auth workspace list"]
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
function workspaceNotAuthenticatedError(workspaceRef) {
|
|
96
|
-
return new CliError({
|
|
97
|
-
code: "WORKSPACE_NOT_AUTHENTICATED",
|
|
98
|
-
domain: "auth",
|
|
99
|
-
summary: "Workspace is not authenticated",
|
|
100
|
-
why: `No stored OAuth session matched "${workspaceRef}".`,
|
|
101
|
-
fix: "Run prisma-cli auth login and authorize that workspace, then switch to it.",
|
|
102
|
-
meta: { workspaceRef },
|
|
103
|
-
exitCode: 1,
|
|
104
|
-
nextSteps: ["prisma-cli auth workspace list", "prisma-cli auth login"]
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
function workspaceAmbiguousError(workspaceRef, matches) {
|
|
108
|
-
return new CliError({
|
|
109
|
-
code: "WORKSPACE_AMBIGUOUS",
|
|
110
|
-
domain: "auth",
|
|
111
|
-
summary: "Workspace name is ambiguous",
|
|
112
|
-
why: `Multiple authenticated workspaces matched "${workspaceRef}".`,
|
|
113
|
-
fix: "Run prisma-cli auth workspace list and switch by workspace id.",
|
|
114
|
-
meta: {
|
|
115
|
-
workspaceRef,
|
|
116
|
-
matches
|
|
117
|
-
},
|
|
118
|
-
exitCode: 2,
|
|
119
|
-
nextSteps: ["prisma-cli auth workspace list"]
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
function featureUnavailableError(summary, why, fix, nextSteps = [], domain = "cli") {
|
|
123
|
-
return new CliError({
|
|
124
|
-
code: "FEATURE_UNAVAILABLE",
|
|
125
|
-
domain,
|
|
126
|
-
summary,
|
|
127
|
-
why,
|
|
128
|
-
fix,
|
|
129
|
-
exitCode: 1,
|
|
130
|
-
nextSteps
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
//#endregion
|
|
134
|
-
export { CliError, authConfigInvalidError, authRequiredError, commandCanceledError, featureUnavailableError, usageError, workspaceAmbiguousError, workspaceNotAuthenticatedError, workspaceRequiredError, workspaceSwitchUnavailableError };
|
|
@@ -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 };
|
package/dist/shell/help.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { formatDescriptorLabel, getDescriptorForCommand } from "./command-meta.js";
|
|
2
|
-
import { COMPACT_GLOBAL_OPTION_FLAGS, resolveGlobalFlags } from "./global-flags.js";
|
|
3
|
-
import { createShellUi, padDisplay, wrapText } from "./ui.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, 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, examples) {
|
|
34
|
-
if (!examples || examples.length === 0) return [];
|
|
35
|
-
return [
|
|
36
|
-
`${rail}`,
|
|
37
|
-
`${rail} Examples:`,
|
|
38
|
-
...examples.map((example) => `${rail} $ ${example}`)
|
|
39
|
-
];
|
|
40
|
-
}
|
|
41
|
-
function renderDocsPath(rail, ui, docsPath) {
|
|
42
|
-
if (!docsPath) return [];
|
|
43
|
-
return [`${rail}`, `${rail} ${ui.accent(padDisplay("Read more", 16))} ${ui.link(docsPath)}`];
|
|
44
|
-
}
|
|
45
|
-
function renderCommandRows(rail, ui, commands) {
|
|
46
|
-
return renderAlignedRows(rail, ui, commands.map((command) => {
|
|
47
|
-
const descriptor = getDescriptorForCommand(command);
|
|
48
|
-
return {
|
|
49
|
-
term: renderCommandTerm(command),
|
|
50
|
-
description: descriptor.description
|
|
51
|
-
};
|
|
52
|
-
}));
|
|
53
|
-
}
|
|
54
|
-
function renderOptionRows(rail, ui, options) {
|
|
55
|
-
return renderAlignedRows(rail, ui, options.map((option) => ({
|
|
56
|
-
term: option.flags,
|
|
57
|
-
description: option.description || "",
|
|
58
|
-
defaultValue: option.defaultValueDescription ?? formatDefaultValue(option.defaultValue)
|
|
59
|
-
})));
|
|
60
|
-
}
|
|
61
|
-
function renderAlignedRows(rail, ui, rows) {
|
|
62
|
-
const termWidth = rows.reduce((width, row) => Math.max(width, row.term.length), 0);
|
|
63
|
-
const descriptionWidth = Math.max(ui.width - 3 - termWidth - 4, 30);
|
|
64
|
-
const lines = [];
|
|
65
|
-
for (const row of rows) {
|
|
66
|
-
const [firstLine, ...rest] = wrapText(row.description, descriptionWidth, " ".repeat(termWidth + 2));
|
|
67
|
-
lines.push(`${rail} ${ui.accent(padDisplay(row.term, termWidth))} ${firstLine}`);
|
|
68
|
-
for (const line of rest) lines.push(`${rail} ${" ".repeat(termWidth)} ${line.trimStart()}`);
|
|
69
|
-
if (row.defaultValue) lines.push(`${rail} ${" ".repeat(termWidth)} ${ui.dim(`default: ${row.defaultValue}`)}`);
|
|
70
|
-
}
|
|
71
|
-
return lines;
|
|
72
|
-
}
|
|
73
|
-
function renderCommandTerm(command) {
|
|
74
|
-
const argumentsList = command.registeredArguments.map(renderArgumentLabel).join(" ");
|
|
75
|
-
return `${command.name()}${argumentsList ? ` ${argumentsList}` : ""}`;
|
|
76
|
-
}
|
|
77
|
-
function renderArgumentLabel(argument) {
|
|
78
|
-
const name = argument.name();
|
|
79
|
-
return argument.required ? `<${name}>` : `[${name}]`;
|
|
80
|
-
}
|
|
81
|
-
function formatDefaultValue(value) {
|
|
82
|
-
if (value === void 0) return null;
|
|
83
|
-
if (Array.isArray(value)) return value.join(", ");
|
|
84
|
-
if (typeof value === "boolean" || typeof value === "number") return String(value);
|
|
85
|
-
if (typeof value === "string" && value.length > 0) return value;
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
//#endregion
|
|
89
|
-
export { renderHelp };
|
package/dist/shell/output.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { renderNextSteps, renderSummaryLine } from "./ui.js";
|
|
2
|
-
//#region src/shell/output.ts
|
|
3
|
-
function writeJsonSuccess(output, success) {
|
|
4
|
-
output.stdout.write(`${JSON.stringify({
|
|
5
|
-
ok: true,
|
|
6
|
-
nextActions: [],
|
|
7
|
-
...success
|
|
8
|
-
}, null, 2)}\n`);
|
|
9
|
-
}
|
|
10
|
-
function writeJsonEvent(output, event) {
|
|
11
|
-
output.stdout.write(`${JSON.stringify(event)}\n`);
|
|
12
|
-
}
|
|
13
|
-
function cliErrorToJson(error) {
|
|
14
|
-
return {
|
|
15
|
-
code: error.code,
|
|
16
|
-
domain: error.domain,
|
|
17
|
-
severity: error.severity,
|
|
18
|
-
summary: error.summary,
|
|
19
|
-
why: error.why,
|
|
20
|
-
fix: error.fix,
|
|
21
|
-
where: error.where,
|
|
22
|
-
meta: error.meta,
|
|
23
|
-
docsUrl: error.docsUrl
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function formatUnexpectedError(error, trace) {
|
|
27
|
-
const debug = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
28
|
-
if (trace) return `${debug}\n`;
|
|
29
|
-
return [
|
|
30
|
-
`Unexpected CLI error: ${error instanceof Error && error.message ? error.message : String(error)}`,
|
|
31
|
-
"More: Re-run with --trace for deeper diagnostics",
|
|
32
|
-
""
|
|
33
|
-
].join("\n");
|
|
34
|
-
}
|
|
35
|
-
function writeJsonError(output, command, error) {
|
|
36
|
-
output.stdout.write(`${JSON.stringify({
|
|
37
|
-
ok: false,
|
|
38
|
-
command,
|
|
39
|
-
error: cliErrorToJson(error),
|
|
40
|
-
warnings: [],
|
|
41
|
-
nextSteps: error.nextSteps,
|
|
42
|
-
nextActions: error.nextActions
|
|
43
|
-
}, null, 2)}\n`);
|
|
44
|
-
}
|
|
45
|
-
function writeHumanLines(output, lines) {
|
|
46
|
-
if (lines.length === 0) return;
|
|
47
|
-
output.stderr.write(`${lines.join("\n")}\n`);
|
|
48
|
-
}
|
|
49
|
-
function writeHumanError(output, ui, error, options) {
|
|
50
|
-
if (error.humanLines && error.humanLines.length > 0) {
|
|
51
|
-
const lines = [...error.humanLines];
|
|
52
|
-
if (options.trace && error.debug) {
|
|
53
|
-
lines.push("");
|
|
54
|
-
lines.push("Trace:");
|
|
55
|
-
lines.push(...error.debug.trimEnd().split("\n"));
|
|
56
|
-
}
|
|
57
|
-
lines.push(...renderNextSteps(error.nextSteps));
|
|
58
|
-
writeHumanLines(output, lines);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const lines = [renderSummaryLine(ui, "error", `${error.summary} [${error.code}]`)];
|
|
62
|
-
if (error.where) lines.push(...["", `Where: ${error.where}`]);
|
|
63
|
-
if (error.why) {
|
|
64
|
-
if (!error.where) lines.push("");
|
|
65
|
-
lines.push(`Why: ${error.why}`);
|
|
66
|
-
}
|
|
67
|
-
if (error.fix) lines.push(`Fix: ${error.fix}`);
|
|
68
|
-
if (options.trace) {
|
|
69
|
-
if (error.debug) {
|
|
70
|
-
lines.push("");
|
|
71
|
-
lines.push("Trace:");
|
|
72
|
-
lines.push(...error.debug.trimEnd().split("\n"));
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
lines.push("");
|
|
76
|
-
lines.push("More: Re-run with --trace for deeper diagnostics");
|
|
77
|
-
}
|
|
78
|
-
lines.push(...renderNextSteps(error.nextSteps));
|
|
79
|
-
writeHumanLines(output, lines);
|
|
80
|
-
}
|
|
81
|
-
//#endregion
|
|
82
|
-
export { cliErrorToJson, formatUnexpectedError, writeHumanError, writeHumanLines, writeJsonError, writeJsonEvent, writeJsonSuccess };
|
package/dist/shell/prompt.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { usageError } from "./errors.js";
|
|
2
|
-
import { confirm, isCancel, select, text } from "@clack/prompts";
|
|
3
|
-
//#region src/shell/prompt.ts
|
|
4
|
-
async function selectPrompt(options) {
|
|
5
|
-
const promptOptions = options.choices.map((choice) => ({
|
|
6
|
-
label: choice.label,
|
|
7
|
-
value: choice.value
|
|
8
|
-
}));
|
|
9
|
-
const response = await select({
|
|
10
|
-
input: options.input,
|
|
11
|
-
output: options.output,
|
|
12
|
-
message: options.message,
|
|
13
|
-
options: promptOptions
|
|
14
|
-
});
|
|
15
|
-
if (isCancel(response)) throw usageError("Interactive prompt canceled", "The command was canceled before a selection was made.", "Re-run the command and choose an option to continue.");
|
|
16
|
-
return response;
|
|
17
|
-
}
|
|
18
|
-
async function textPrompt(options) {
|
|
19
|
-
const response = await text({
|
|
20
|
-
input: options.input,
|
|
21
|
-
output: options.output,
|
|
22
|
-
message: options.message,
|
|
23
|
-
placeholder: options.placeholder,
|
|
24
|
-
validate: options.validate
|
|
25
|
-
});
|
|
26
|
-
if (isCancel(response)) throw usageError("Interactive prompt canceled", "The command was canceled before a value was entered.", "Re-run the command and provide a value to continue.");
|
|
27
|
-
return response;
|
|
28
|
-
}
|
|
29
|
-
async function confirmPrompt(options) {
|
|
30
|
-
const response = await confirm({
|
|
31
|
-
input: options.input,
|
|
32
|
-
output: options.output,
|
|
33
|
-
message: options.message,
|
|
34
|
-
initialValue: options.initialValue ?? false
|
|
35
|
-
});
|
|
36
|
-
if (isCancel(response)) throw usageError("Interactive prompt canceled", "The command was canceled before a confirmation was made.", "Re-run the command and choose an option to continue.");
|
|
37
|
-
return response;
|
|
38
|
-
}
|
|
39
|
-
function disposePromptState(_input) {}
|
|
40
|
-
//#endregion
|
|
41
|
-
export { confirmPrompt, disposePromptState, selectPrompt, textPrompt };
|
package/dist/shell/runtime.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { LocalStateStore } from "../adapters/local-state.js";
|
|
2
|
-
import { MockApi } from "../adapters/mock-api.js";
|
|
3
|
-
import { createShellUi } from "./ui.js";
|
|
4
|
-
import { renderHelp } from "./help.js";
|
|
5
|
-
import { findComputeConfigDir } from "@prisma/compute-sdk/config";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
//#region src/shell/runtime.ts
|
|
8
|
-
const DEFAULT_STATE_DIR_NAME = path.join(".prisma", "cli");
|
|
9
|
-
function configureRuntimeCommand(command, runtime) {
|
|
10
|
-
return command.helpCommand(false).configureHelp({ formatHelp: (configuredCommand) => renderHelp(configuredCommand, runtime) }).configureOutput({
|
|
11
|
-
writeOut: (text) => {
|
|
12
|
-
runtime.stderr.write(text);
|
|
13
|
-
},
|
|
14
|
-
writeErr: (text) => {
|
|
15
|
-
runtime.stderr.write(text);
|
|
16
|
-
},
|
|
17
|
-
outputError: (text, write) => {
|
|
18
|
-
write(text);
|
|
19
|
-
}
|
|
20
|
-
}).exitOverride();
|
|
21
|
-
}
|
|
22
|
-
async function createCommandContext(runtime, flags) {
|
|
23
|
-
const fixturePath = runtime.fixturePath ?? runtime.env.PRISMA_CLI_MOCK_FIXTURE_PATH;
|
|
24
|
-
const stateDir = await resolveStateDir(runtime);
|
|
25
|
-
let loadedApi;
|
|
26
|
-
if (fixturePath) loadedApi = await MockApi.load(fixturePath, runtime.signal);
|
|
27
|
-
return {
|
|
28
|
-
get api() {
|
|
29
|
-
if (!loadedApi) throw new Error("context.api accessed in real mode. Set runtime.fixturePath or PRISMA_CLI_MOCK_FIXTURE_PATH to use fixture mode.");
|
|
30
|
-
return loadedApi;
|
|
31
|
-
},
|
|
32
|
-
stateStore: new LocalStateStore(stateDir, runtime.signal),
|
|
33
|
-
output: {
|
|
34
|
-
stdout: runtime.stdout,
|
|
35
|
-
stderr: runtime.stderr
|
|
36
|
-
},
|
|
37
|
-
flags,
|
|
38
|
-
runtime,
|
|
39
|
-
ui: createShellUi(runtime, flags)
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
async function resolveStateDir(runtime) {
|
|
43
|
-
const explicitStateDir = runtime.stateDir ?? runtime.env.PRISMA_CLI_STATE_DIR;
|
|
44
|
-
if (explicitStateDir) return explicitStateDir;
|
|
45
|
-
const projectDir = await findComputeConfigDir(runtime.cwd, runtime.signal);
|
|
46
|
-
return path.join(projectDir ?? runtime.cwd, DEFAULT_STATE_DIR_NAME);
|
|
47
|
-
}
|
|
48
|
-
function canPrompt(context) {
|
|
49
|
-
if (context.flags.json) return false;
|
|
50
|
-
if (context.flags.interactive === false) return false;
|
|
51
|
-
if (context.runtime.env.CI && context.flags.interactive !== true) return false;
|
|
52
|
-
return Boolean(context.runtime.stdin.isTTY && context.runtime.stderr.isTTY);
|
|
53
|
-
}
|
|
54
|
-
//#endregion
|
|
55
|
-
export { canPrompt, configureRuntimeCommand, createCommandContext, resolveStateDir };
|