@prisma/cli 8.0.0-rc.1 → 8.0.0-rc.2-dev.49

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/dist/cli.js +15410 -16
  2. package/dist/deploy-framework-C7bQM00A.js +23 -0
  3. package/dist/{v8/sender.js → sender.js} +2 -2
  4. package/package.json +11 -15
  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,138 +0,0 @@
1
- import { CliError, usageError } from "../../errors.js";
2
- import { shortenHomePath } from "../fs/home-path.js";
3
- import { LOCAL_RESOLUTION_PIN_RELATIVE_PATH, ensureLocalResolutionPinGitignore, writeLocalResolutionPin } from "./local-pin.js";
4
- import { projectAmbiguousError, projectNotFoundError } from "./resolution.js";
5
- import path from "node:path";
6
- import { Result, matchError } from "better-result";
7
- //#region src/lib/project/setup.ts
8
- function isValidProjectSetupName(projectName) {
9
- return projectName.trim().length > 0;
10
- }
11
- function validateProjectSetupNameText(value, fallback) {
12
- if ((value?.trim() || fallback).trim().length > 0) return;
13
- return "Enter a Project name.";
14
- }
15
- function resolveProjectForSetup(projectRef, projects, workspace) {
16
- const matches = projects.filter((project) => project.id === projectRef || project.name === projectRef);
17
- if (matches.length > 1) throw projectAmbiguousError(projectRef, matches);
18
- const match = matches[0];
19
- if (match !== void 0) return match;
20
- throw projectNotFoundError(projectRef, workspace);
21
- }
22
- async function bindProjectToDirectory(context, workspace, project, action, directory = context.runtime.cwd) {
23
- return Result.gen(async function* () {
24
- yield* Result.await(writeLocalResolutionPin(directory, {
25
- workspaceId: workspace.id,
26
- projectId: project.id
27
- }, context.runtime.signal));
28
- yield* Result.await(ensureLocalResolutionPinGitignore(directory, context.runtime.signal));
29
- return Result.ok({
30
- workspace,
31
- project,
32
- directory: formatSetupDirectory(directory, context),
33
- localPin: {
34
- path: LOCAL_RESOLUTION_PIN_RELATIVE_PATH,
35
- written: true
36
- },
37
- action
38
- });
39
- });
40
- }
41
- function projectDirectoryBindingErrorToCliError(error) {
42
- return matchError(error, {
43
- LocalResolutionPinSerializationError: (error) => {
44
- throw error;
45
- },
46
- LocalResolutionPinWriteAbortedError: (error) => {
47
- throw error;
48
- },
49
- LocalResolutionPinWriteFailedError: (error) => localStateWriteFailedError(error, {
50
- why: `The CLI could not write ${LOCAL_RESOLUTION_PIN_RELATIVE_PATH}.`,
51
- meta: {
52
- pinPath: error.pinPath,
53
- operation: error.operation
54
- }
55
- }),
56
- LocalResolutionPinGitignoreUpdateAbortedError: (error) => {
57
- throw error;
58
- },
59
- LocalResolutionPinGitignoreUpdateFailedError: (error) => localStateWriteFailedError(error, {
60
- why: "The CLI could not update .gitignore to keep local Project binding state out of git.",
61
- meta: {
62
- gitignorePath: error.gitignorePath,
63
- operation: error.operation
64
- }
65
- })
66
- });
67
- }
68
- function localStateWriteFailedError(error, options) {
69
- return new CliError({
70
- code: "LOCAL_STATE_WRITE_FAILED",
71
- domain: "project",
72
- summary: "Could not save local Project binding",
73
- why: options.why,
74
- fix: "Check that this directory is writable and that .prisma/local.json and .gitignore are not blocked by directories or permissions, then retry.",
75
- debug: formatDebugDetails(error.cause),
76
- meta: options.meta,
77
- exitCode: 1,
78
- nextSteps: ["prisma-cli project link <id-or-name>", "prisma-cli app deploy --project <id-or-name>"]
79
- });
80
- }
81
- function toProjectSummary(project) {
82
- return {
83
- id: project.id,
84
- name: project.name,
85
- ...project.url ? { url: project.url } : {},
86
- ...project.defaultRegion != null ? { defaultRegion: project.defaultRegion } : {}
87
- };
88
- }
89
- function projectSetupNameRequiredError(command) {
90
- return usageError("Project create requires a name", "The project name must be a non-empty value.", "Pass a Project name explicitly.", [`prisma-cli ${command} my-app`], "project");
91
- }
92
- function projectCreateFailedError(error, projectName, workspace, options) {
93
- const status = extractHttpStatus(error);
94
- if (status === 401 || status === 403) return new CliError({
95
- code: "PROJECT_CREATE_FAILED",
96
- domain: "project",
97
- summary: `Could not create Project "${projectName}"`,
98
- why: `The platform rejected the Project create in workspace "${workspace.name}" (HTTP ${status}).`,
99
- fix: options.permissionFix,
100
- debug: formatDebugDetails(error),
101
- exitCode: 1,
102
- nextSteps: options.nextSteps
103
- });
104
- return new CliError({
105
- code: "PROJECT_CREATE_FAILED",
106
- domain: "project",
107
- summary: `Could not create Project "${projectName}"`,
108
- why: error instanceof Error ? error.message : String(error),
109
- fix: options.fallbackFix,
110
- debug: formatDebugDetails(error),
111
- exitCode: 1,
112
- nextSteps: options.nextSteps
113
- });
114
- }
115
- const PATH_SEPARATORS = /[\\/]/;
116
- function formatSetupDirectory(directory, context) {
117
- if (path.resolve(directory) !== path.resolve(context.runtime.cwd)) return shortenHomePath(directory, context.runtime.env);
118
- const basename = directory.split(PATH_SEPARATORS).filter(Boolean).pop();
119
- return basename ? `./${basename}` : ".";
120
- }
121
- const HTTP_STATUS_IN_MESSAGE = /\(HTTP (\d{3})\)/;
122
- function extractHttpStatus(error) {
123
- if (!error || typeof error !== "object") return null;
124
- const candidate = error;
125
- if (typeof candidate.statusCode === "number") return candidate.statusCode;
126
- if (typeof candidate.status === "number") return candidate.status;
127
- if (typeof candidate.message === "string") {
128
- const match = HTTP_STATUS_IN_MESSAGE.exec(candidate.message);
129
- if (match) return Number.parseInt(match[1], 10);
130
- }
131
- return null;
132
- }
133
- function formatDebugDetails(error) {
134
- if (error instanceof Error) return error.stack ?? error.message;
135
- return typeof error === "string" ? error : null;
136
- }
137
- //#endregion
138
- export { bindProjectToDirectory, isValidProjectSetupName, projectCreateFailedError, projectDirectoryBindingErrorToCliError, projectSetupNameRequiredError, resolveProjectForSetup, toProjectSummary, validateProjectSetupNameText };
@@ -1,56 +0,0 @@
1
- import { CliError } from "../errors.js";
2
- import { CLI_NAME } from "../cli-name.js";
3
- import { createRequire } from "node:module";
4
- import process from "node:process";
5
- //#region src/lib/version.ts
6
- const requireFromHere = createRequire(import.meta.url);
7
- function readPackageMetadata() {
8
- try {
9
- return requireFromHere("../../package.json");
10
- } catch {
11
- return {};
12
- }
13
- }
14
- function getCliVersion() {
15
- const pkg = readPackageMetadata();
16
- if (!pkg.version) throw new CliError({
17
- code: "VERSION_UNAVAILABLE",
18
- domain: "cli",
19
- summary: "CLI version metadata is missing from the installed package",
20
- why: "The bundled package.json could not be read or did not contain a version field.",
21
- fix: "Reinstall the CLI from the npm registry, or check your install path is intact.",
22
- exitCode: 1
23
- });
24
- return pkg.version;
25
- }
26
- function getCliName() {
27
- return CLI_NAME;
28
- }
29
- function detectInvocation(env, argv) {
30
- if (env.npm_config_user_agent?.startsWith("bun")) return "bunx";
31
- const normalizedExecPath = env.npm_execpath?.replace(/\\/g, "/").toLowerCase();
32
- const normalizedUserAgent = env.npm_config_user_agent?.toLowerCase();
33
- if (env.npm_lifecycle_event === "npx" || normalizedExecPath?.includes("/_npx/") || normalizedUserAgent?.includes("npx")) return "npx";
34
- const entry = (argv[1] ?? "").replace(/\\/g, "/").toLowerCase();
35
- if (entry.endsWith(".ts") || entry.includes("/tsx/")) return "dev";
36
- if (entry.includes("/_npx/")) return "npx";
37
- if (entry.includes("/.bun/")) return "bunx";
38
- if (entry.includes("/node_modules/.bin/") || /\/prisma-cli(\.cmd|\.exe)?$/.test(entry)) return "global";
39
- return "unknown";
40
- }
41
- function buildVersionResult(env, argv) {
42
- return {
43
- cli: {
44
- name: getCliName(),
45
- version: getCliVersion()
46
- },
47
- node: { version: process.version },
48
- os: {
49
- platform: process.platform,
50
- arch: process.arch
51
- },
52
- invocation: detectInvocation(env, argv)
53
- };
54
- }
55
- //#endregion
56
- export { buildVersionResult, getCliName, getCliVersion };
@@ -1,18 +0,0 @@
1
- //#region src/lib/workspace-id.ts
2
- /**
3
- * A workspace reaches the CLI under two ids for the same workspace: a
4
- * credential's `workspace_id` claim carries the bare id, while the
5
- * management API and anything derived from it carry the same id behind
6
- * a `wksp_` prefix. Comparing the two forms directly silently matches
7
- * nothing, so every comparison between workspace ids of different
8
- * origin goes through here.
9
- */
10
- const WORKSPACE_ID_PREFIX = "wksp_";
11
- function stripWorkspacePrefix(value) {
12
- return value.startsWith(WORKSPACE_ID_PREFIX) ? value.slice(5) : value;
13
- }
14
- function sameWorkspaceId(left, right) {
15
- return stripWorkspacePrefix(left) === stripWorkspacePrefix(right);
16
- }
17
- //#endregion
18
- export { sameWorkspaceId };
@@ -1,90 +0,0 @@
1
- import { formatDescriptorLabel } from "../shell/command-meta.js";
2
- import { maskValue, padDisplay, renderSummaryLine } from "../shell/ui.js";
3
- import stringWidth from "string-width";
4
- //#region src/output/patterns.ts
5
- function renderList(input, ui) {
6
- const keyWidth = Math.max(stringWidth(`${input.parentContext.key}:`), ...input.items.map((item) => stringWidth(`⚬ ${item.noun}:`)), ...readMoreWidth(input.descriptor));
7
- const lines = renderCardTitle(input.descriptor, input.title, ui);
8
- lines.push(renderCardRow(ui, keyWidth, input.parentContext.key, input.parentContext.value));
9
- if (input.items.length === 0) lines.push(renderPlainCardLine(ui, ui.dim(input.emptyMessage)));
10
- else for (const item of input.items) lines.push(renderCardRow(ui, keyWidth, `⚬ ${item.noun}`, formatListItemValue(ui, item)));
11
- pushReadMore(lines, ui, keyWidth, input.descriptor);
12
- return lines;
13
- }
14
- function serializeList(input) {
15
- return {
16
- context: input.context,
17
- items: input.items.map((item) => ({
18
- name: item.label,
19
- id: item.id,
20
- status: item.status
21
- })),
22
- count: input.items.length
23
- };
24
- }
25
- function renderShow(input, ui) {
26
- const keyWidth = Math.max(0, ...input.fields.map((field) => stringWidth(`${field.key}:`)), ...readMoreWidth(input.descriptor));
27
- const lines = renderCardTitle(input.descriptor, input.title, ui);
28
- for (const field of input.fields) lines.push(renderCardRow(ui, keyWidth, field.key, formatValue(ui, field.value, field.tone, field.sensitive)));
29
- pushReadMore(lines, ui, keyWidth, input.descriptor);
30
- return lines;
31
- }
32
- function renderMutate(input, ui) {
33
- const rows = input.context;
34
- const keyWidth = Math.max(0, ...rows.map((row) => stringWidth(`${row.key}:`)), ...readMoreWidth(input.descriptor));
35
- const lines = renderCardTitle(input.descriptor, input.title, ui);
36
- for (const row of rows) lines.push(renderCardRow(ui, keyWidth, row.key, formatValue(ui, row.value, row.tone, row.sensitive)));
37
- pushReadMore(lines, ui, keyWidth, input.descriptor);
38
- lines.push("");
39
- lines.push(`${ui.warning("◇")} ${input.operationDescription}...`);
40
- lines.push(renderSummaryLine(ui, "success", `Applied ${input.operationCount} operation(s)`));
41
- for (const detail of input.details) lines.push(` ${detail}`);
42
- for (const alert of input.alerts ?? []) {
43
- lines.push("");
44
- lines.push(renderSummaryLine(ui, alert.tone, alert.text));
45
- }
46
- return lines;
47
- }
48
- function renderCardTitle(descriptor, title, ui) {
49
- return [`${ui.strong(formatDescriptorLabel(descriptor))} ${ui.dim("→")} ${ui.dim(title)}`, ""];
50
- }
51
- function renderCardRow(ui, keyWidth, key, value) {
52
- return `${renderCardRail(ui)} ${ui.accent(padDisplay(`${key}:`, keyWidth))} ${value}`;
53
- }
54
- function renderPlainCardLine(ui, text) {
55
- return `${renderCardRail(ui)} ${text}`;
56
- }
57
- function renderCardDivider(ui) {
58
- return renderCardRail(ui);
59
- }
60
- function readMoreWidth(descriptor) {
61
- return descriptor.docsPath ? [stringWidth("Read more")] : [];
62
- }
63
- function pushReadMore(lines, ui, keyWidth, descriptor) {
64
- if (!descriptor.docsPath) return;
65
- lines.push(renderCardDivider(ui));
66
- lines.push(`${renderCardRail(ui)} ${ui.accent(padDisplay("Read more", keyWidth))} ${ui.link(descriptor.docsPath)}`);
67
- }
68
- function renderCardRail(ui) {
69
- return ui.dim("│");
70
- }
71
- function formatListItemValue(ui, item) {
72
- const annotation = renderAnnotation(ui, item.status);
73
- return annotation ? `${item.label} ${annotation}` : item.label;
74
- }
75
- function renderAnnotation(ui, status) {
76
- if (status === "active") return ui.success("(active)");
77
- if (status === "default") return ui.dim("(default)");
78
- return "";
79
- }
80
- function formatValue(ui, value, tone = "default", sensitive = false) {
81
- const resolvedValue = sensitive ? maskValue(value) : value;
82
- if (tone === "success") return ui.success(resolvedValue);
83
- if (tone === "warning") return ui.warning(resolvedValue);
84
- if (tone === "error") return ui.error(resolvedValue);
85
- if (tone === "link") return ui.link(resolvedValue);
86
- if (tone === "dim") return ui.dim(resolvedValue);
87
- return resolvedValue;
88
- }
89
- //#endregion
90
- export { renderList, renderMutate, renderShow, serializeList };
@@ -1,74 +0,0 @@
1
- import { formatShellCommand } from "../command-arguments.js";
2
- import { formatDescriptorLabel } from "../shell/command-meta.js";
3
- import { renderSummaryLine } from "../shell/ui.js";
4
- //#region src/presenters/agent.ts
5
- function renderAgentInstall(context, descriptor, result) {
6
- const ui = context.ui;
7
- const rail = ui.dim("│");
8
- return [
9
- renderSummaryLine(ui, "success", `${formatDescriptorLabel(descriptor)} → ${operationSummary(result)} Prisma skills.`),
10
- "",
11
- `${rail} ${ui.accent("skills:")} ${result.skills.status.replace("-", " ")}`,
12
- `${rail} ${ui.dim(formatShellCommand(result.skills.command))}`
13
- ];
14
- }
15
- function renderAgentStatus(context, descriptor, result) {
16
- const ui = context.ui;
17
- const rail = ui.dim("│");
18
- return [
19
- `${ui.strong(formatDescriptorLabel(descriptor))} ${ui.dim("→")} ${ui.dim(`Checking ${result.statusScope} Prisma skills.`)}`,
20
- "",
21
- `${rail} ${ui.accent("skills:")} ${result.skillsInstalled ? "installed" : "not found"}`,
22
- ...renderInstalledSkills(context, result.skills),
23
- `${rail}`,
24
- `${rail} ${ui.accent("source:")} ${formatStatusSource(result)}`,
25
- `${rail} ${ui.dim(formatShellCommand(result.skillsListCommand))}`,
26
- ...renderProjectStatusDetails(context, result)
27
- ];
28
- }
29
- function serializeAgentInstall(result) {
30
- return result;
31
- }
32
- function serializeAgentStatus(result) {
33
- return result;
34
- }
35
- function formatSetupPromptStatus(result) {
36
- if (result.skillsInstalled) return "not needed";
37
- if (result.promptDismissedAt) return `dismissed ${result.promptDismissedAt}`;
38
- return "active";
39
- }
40
- function formatStatusSource(result) {
41
- if (result.statusSource === "skills-cli") return result.statusScope === "global" ? "skills list -g --json" : "skills list --json";
42
- if (result.statusSource === "skills-lock") return result.skillsLockPath;
43
- return "unavailable";
44
- }
45
- function renderProjectStatusDetails(context, result) {
46
- if (result.statusScope !== "project") return [];
47
- const ui = context.ui;
48
- const rail = ui.dim("│");
49
- return [
50
- `${rail}`,
51
- `${rail} ${ui.accent("skills lock:")} ${result.skillsLockInstalled ? "installed" : "not found"}`,
52
- `${rail} ${ui.dim(result.skillsLockPath)}`,
53
- `${rail}`,
54
- `${rail} ${ui.accent("setup prompt:")} ${formatSetupPromptStatus(result)}`
55
- ];
56
- }
57
- function renderInstalledSkills(context, skills) {
58
- const ui = context.ui;
59
- const rail = ui.dim("│");
60
- if (skills.length === 0) return [`${rail} ${ui.dim("No Prisma skills reported.")}`];
61
- return skills.map((skill) => {
62
- const agents = skill.agents.length > 0 ? skill.agents.join(", ") : "no agents reported";
63
- return `${rail} ${skill.name} ${ui.dim(`${skill.scope}; ${agents}`)}`;
64
- });
65
- }
66
- function operationSummary(result) {
67
- if (result.skills.status === "would-install") return "Would install";
68
- return operationLabel(result.operation);
69
- }
70
- function operationLabel(operation) {
71
- return operation === "update" ? "Updated" : "Installed";
72
- }
73
- //#endregion
74
- export { renderAgentInstall, renderAgentStatus, serializeAgentInstall, serializeAgentStatus };
@@ -1,265 +0,0 @@
1
- import { renderVerboseBlock } from "../shell/ui.js";
2
- import { renderList, renderShow, serializeList } from "../output/patterns.js";
3
- import { renderResolvedProjectContextBlock, stripVerboseContext } from "./verbose-context.js";
4
- //#region src/presenters/app-env.ts
5
- function scopeLabel(scope) {
6
- if (scope.kind === "role") return scope.role ?? "unknown";
7
- if (scope.kind === "overview") return "overview";
8
- return `branch:${scope.branchName ?? scope.branchId ?? "unknown"}`;
9
- }
10
- function listTargetLabel(result) {
11
- const target = result.target;
12
- if (target.source === "overview") return "overview";
13
- if (target.branchName) {
14
- const suffix = target.branchExists === false ? " (not created yet)" : "";
15
- return `branch:${target.branchName} -> ${target.envMap}${suffix}`;
16
- }
17
- return scopeLabel(result.scope);
18
- }
19
- function renderEnvVerboseBlocks(context, result) {
20
- return [...renderEnvResolvedContextBlock(context, result.verboseContext), ...renderEnvTargetBlock(context, result)];
21
- }
22
- function renderEnvResolvedContextBlock(context, verboseContext) {
23
- return renderResolvedProjectContextBlock(context.ui, verboseContext);
24
- }
25
- function renderEnvTargetBlock(context, result) {
26
- return renderVerboseBlock(context.ui, envTargetRows(result), { title: "Env target" });
27
- }
28
- function envTargetRows(result) {
29
- return [
30
- {
31
- key: "project id",
32
- value: result.projectId,
33
- tone: "dim"
34
- },
35
- {
36
- key: "scope",
37
- value: scopeLabel(result.scope)
38
- },
39
- ...envListTargetRows(result),
40
- ...envFileRows(result),
41
- {
42
- key: "keys",
43
- value: formatKeyNames(envResultKeys(result)),
44
- tone: envResultKeys(result).length > 0 ? "default" : "dim"
45
- }
46
- ];
47
- }
48
- function envListTargetRows(result) {
49
- if (!("target" in result)) return [];
50
- return [
51
- {
52
- key: "target source",
53
- value: result.target.source
54
- },
55
- {
56
- key: "env map",
57
- value: result.target.envMap
58
- },
59
- ...result.target.branchName ? [{
60
- key: "branch",
61
- value: result.target.branchName
62
- }] : [],
63
- ...result.target.branchId ? [{
64
- key: "branch id",
65
- value: result.target.branchId,
66
- tone: "dim"
67
- }] : [],
68
- ...result.target.branchExists === false ? [{
69
- key: "branch state",
70
- value: "not created yet",
71
- tone: "warning"
72
- }] : []
73
- ];
74
- }
75
- function envFileRows(result) {
76
- if (!("file" in result) || !result.file) return [];
77
- return [{
78
- key: "file",
79
- value: result.file.path
80
- }, {
81
- key: "file count",
82
- value: String(result.file.count)
83
- }];
84
- }
85
- function envResultKeys(result) {
86
- if ("variables" in result && result.variables) return result.variables.map((variable) => variable.key).sort((left, right) => left.localeCompare(right));
87
- if ("variable" in result && result.variable) return [result.variable.key];
88
- if ("key" in result) return [result.key];
89
- return [];
90
- }
91
- function formatKeyNames(keys) {
92
- return keys.length > 0 ? keys.join(", ") : "none";
93
- }
94
- function renderEnvAdd(context, descriptor, result) {
95
- if (result.variables !== void 0) {
96
- const lines = renderList({
97
- title: "Setting new environment variables from file.",
98
- descriptor,
99
- parentContext: {
100
- key: "target",
101
- value: `${scopeLabel(result.scope)} from ${result.file.path}`
102
- },
103
- items: result.variables.map((variable) => ({
104
- noun: "variable",
105
- label: `${variable.key} (${variable.source})`,
106
- id: variable.id,
107
- status: variable.isManagedBySystem ? "default" : null
108
- })),
109
- emptyMessage: "No environment variables imported."
110
- }, context.ui);
111
- lines.push(...renderEnvVerboseBlocks(context, result));
112
- return lines;
113
- }
114
- const lines = renderShow({
115
- title: "Setting a new environment variable.",
116
- descriptor,
117
- fields: [
118
- {
119
- key: "project",
120
- value: result.projectId
121
- },
122
- {
123
- key: "scope",
124
- value: scopeLabel(result.scope)
125
- },
126
- {
127
- key: "key",
128
- value: result.variable.key
129
- },
130
- {
131
- key: "id",
132
- value: result.variable.id,
133
- tone: "dim"
134
- },
135
- {
136
- key: "last updated",
137
- value: result.variable.updatedAt,
138
- tone: "dim"
139
- }
140
- ]
141
- }, context.ui);
142
- lines.push(...renderEnvVerboseBlocks(context, result));
143
- return lines;
144
- }
145
- function serializeEnvAdd(result) {
146
- return stripVerboseContext(result);
147
- }
148
- function renderEnvUpdate(context, descriptor, result) {
149
- if (result.variables !== void 0) {
150
- const lines = renderList({
151
- title: "Replacing environment variable values from file.",
152
- descriptor,
153
- parentContext: {
154
- key: "target",
155
- value: `${scopeLabel(result.scope)} from ${result.file.path}`
156
- },
157
- items: result.variables.map((variable) => ({
158
- noun: "variable",
159
- label: `${variable.key} (${variable.source})`,
160
- id: variable.id,
161
- status: variable.isManagedBySystem ? "default" : null
162
- })),
163
- emptyMessage: "No environment variables updated."
164
- }, context.ui);
165
- lines.push(...renderEnvVerboseBlocks(context, result));
166
- return lines;
167
- }
168
- const lines = renderShow({
169
- title: "Replacing the environment variable's value.",
170
- descriptor,
171
- fields: [
172
- {
173
- key: "project",
174
- value: result.projectId
175
- },
176
- {
177
- key: "scope",
178
- value: scopeLabel(result.scope)
179
- },
180
- {
181
- key: "key",
182
- value: result.variable.key
183
- },
184
- {
185
- key: "id",
186
- value: result.variable.id,
187
- tone: "dim"
188
- },
189
- {
190
- key: "last updated",
191
- value: result.variable.updatedAt,
192
- tone: "dim"
193
- }
194
- ]
195
- }, context.ui);
196
- lines.push(...renderEnvVerboseBlocks(context, result));
197
- return lines;
198
- }
199
- function serializeEnvUpdate(result) {
200
- return stripVerboseContext(result);
201
- }
202
- function renderEnvList(context, descriptor, result) {
203
- const lines = renderList({
204
- title: "Listing environment variables for the selected scope.",
205
- descriptor,
206
- parentContext: {
207
- key: "target",
208
- value: listTargetLabel(result)
209
- },
210
- items: result.variables.map((variable) => ({
211
- noun: "variable",
212
- label: `${variable.key} (${variable.source})`,
213
- id: variable.id,
214
- status: variable.isManagedBySystem ? "default" : null
215
- })),
216
- emptyMessage: "No environment variables defined in this scope."
217
- }, context.ui);
218
- lines.push(...renderEnvVerboseBlocks(context, result));
219
- return lines;
220
- }
221
- function serializeEnvList(result) {
222
- const serializable = stripVerboseContext(result);
223
- return {
224
- projectId: serializable.projectId,
225
- scope: serializable.scope,
226
- target: serializable.target,
227
- ...serializeList({
228
- context: { target: listTargetLabel(serializable) },
229
- items: serializable.variables.map((variable) => ({
230
- noun: "variable",
231
- label: `${variable.key} (${variable.source})`,
232
- id: variable.id,
233
- status: variable.isManagedBySystem ? "default" : null
234
- }))
235
- }),
236
- variables: serializable.variables
237
- };
238
- }
239
- function renderEnvRm(context, descriptor, result) {
240
- const lines = renderShow({
241
- title: "Removing the environment variable from the scope.",
242
- descriptor,
243
- fields: [
244
- {
245
- key: "project",
246
- value: result.projectId
247
- },
248
- {
249
- key: "scope",
250
- value: scopeLabel(result.scope)
251
- },
252
- {
253
- key: "key",
254
- value: result.key
255
- }
256
- ]
257
- }, context.ui);
258
- lines.push(...renderEnvVerboseBlocks(context, result));
259
- return lines;
260
- }
261
- function serializeEnvRm(result) {
262
- return stripVerboseContext(result);
263
- }
264
- //#endregion
265
- export { renderEnvAdd, renderEnvList, renderEnvRm, renderEnvUpdate, serializeEnvAdd, serializeEnvList, serializeEnvRm, serializeEnvUpdate };