@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
package/dist/presenters/auth.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { formatDescriptorLabel } from "../shell/command-meta.js";
|
|
2
|
-
import { padDisplay } from "../shell/ui.js";
|
|
3
|
-
import { renderMutate, renderShow } from "../output/patterns.js";
|
|
4
|
-
import stringWidth from "string-width";
|
|
5
|
-
//#region src/presenters/auth.ts
|
|
6
|
-
function renderAuthSuccess(context, descriptor, command, result) {
|
|
7
|
-
if (command === "auth.login") {
|
|
8
|
-
const rows = [];
|
|
9
|
-
if (result.provider) rows.push({
|
|
10
|
-
key: "provider",
|
|
11
|
-
value: providerLabel(result.provider)
|
|
12
|
-
});
|
|
13
|
-
const userLabel = authUserLabel(result);
|
|
14
|
-
if (userLabel) rows.push({
|
|
15
|
-
key: "user",
|
|
16
|
-
value: userLabel
|
|
17
|
-
});
|
|
18
|
-
if (result.workspace?.name) rows.push({
|
|
19
|
-
key: "workspace",
|
|
20
|
-
value: result.workspace.name
|
|
21
|
-
});
|
|
22
|
-
return renderMutate({
|
|
23
|
-
title: "Starting an authenticated CLI session.",
|
|
24
|
-
descriptor,
|
|
25
|
-
context: rows,
|
|
26
|
-
operationDescription: "Applying authentication session changes",
|
|
27
|
-
operationCount: 1,
|
|
28
|
-
details: ["Session stored in local CLI state."]
|
|
29
|
-
}, context.ui);
|
|
30
|
-
}
|
|
31
|
-
if (command === "auth.logout") return renderMutate({
|
|
32
|
-
title: "Clearing the current CLI session.",
|
|
33
|
-
descriptor,
|
|
34
|
-
context: [{
|
|
35
|
-
key: "session",
|
|
36
|
-
value: "local CLI state",
|
|
37
|
-
tone: "dim"
|
|
38
|
-
}],
|
|
39
|
-
operationDescription: "Applying authentication session changes",
|
|
40
|
-
operationCount: 1,
|
|
41
|
-
details: ["Session removed from local CLI state."]
|
|
42
|
-
}, context.ui);
|
|
43
|
-
return renderShow({
|
|
44
|
-
title: "Showing the current authenticated identity.",
|
|
45
|
-
descriptor,
|
|
46
|
-
fields: result.authenticated ? [
|
|
47
|
-
{
|
|
48
|
-
key: "status",
|
|
49
|
-
value: "signed in",
|
|
50
|
-
tone: "success"
|
|
51
|
-
},
|
|
52
|
-
...authUserRows(result),
|
|
53
|
-
...result.provider ? [{
|
|
54
|
-
key: "provider",
|
|
55
|
-
value: providerLabel(result.provider)
|
|
56
|
-
}] : [],
|
|
57
|
-
...result.workspace?.name ? [{
|
|
58
|
-
key: "workspace",
|
|
59
|
-
value: result.workspace.name
|
|
60
|
-
}] : []
|
|
61
|
-
] : [{
|
|
62
|
-
key: "status",
|
|
63
|
-
value: "signed out",
|
|
64
|
-
tone: "dim"
|
|
65
|
-
}]
|
|
66
|
-
}, context.ui);
|
|
67
|
-
}
|
|
68
|
-
function renderAuthWorkspaceList(context, descriptor, result) {
|
|
69
|
-
const ui = context.ui;
|
|
70
|
-
const rail = ui.dim("│");
|
|
71
|
-
const lines = [
|
|
72
|
-
`${ui.strong(formatDescriptorLabel(descriptor))} ${ui.dim("→")} ${ui.dim("Listing authenticated workspaces on this machine.")}`,
|
|
73
|
-
"",
|
|
74
|
-
`${rail} ${ui.accent("auth source:")} ${authSourceLabel(result.authSource)}`
|
|
75
|
-
];
|
|
76
|
-
const hasMixedSources = new Set(result.workspaces.map((workspace) => workspace.source)).size > 1;
|
|
77
|
-
if (result.workspaces.length === 0) {
|
|
78
|
-
lines.push(`${rail} ${ui.dim("No local OAuth workspaces found.")}`);
|
|
79
|
-
return lines;
|
|
80
|
-
}
|
|
81
|
-
const nameWidth = Math.max(4, ...result.workspaces.map((workspace) => stringWidth(workspace.name)));
|
|
82
|
-
const idWidth = Math.max(2, ...result.workspaces.map((workspace) => stringWidth(workspace.id)));
|
|
83
|
-
const sourceWidth = hasMixedSources ? Math.max(6, ...result.workspaces.map((workspace) => stringWidth(workspaceSourceLabel(workspace.source)))) : 0;
|
|
84
|
-
lines.push(rail);
|
|
85
|
-
lines.push(hasMixedSources ? `${rail} ${ui.accent(padDisplay("name", nameWidth))} ${ui.accent(padDisplay("id", idWidth))} ${ui.accent(padDisplay("source", sourceWidth))} ${ui.accent("status")}` : `${rail} ${ui.accent(padDisplay("name", nameWidth))} ${ui.accent(padDisplay("id", idWidth))} ${ui.accent("status")}`);
|
|
86
|
-
for (const workspace of result.workspaces) {
|
|
87
|
-
const status = workspace.active ? "active" : "";
|
|
88
|
-
const source = workspaceSourceLabel(workspace.source);
|
|
89
|
-
lines.push(hasMixedSources ? `${rail} ${padDisplay(workspace.name, nameWidth)} ${padDisplay(workspace.id, idWidth)} ${padDisplay(source, sourceWidth)} ${status}` : `${rail} ${padDisplay(workspace.name, nameWidth)} ${padDisplay(workspace.id, idWidth)} ${status}`);
|
|
90
|
-
}
|
|
91
|
-
return lines;
|
|
92
|
-
}
|
|
93
|
-
function serializeAuthWorkspaceList(result) {
|
|
94
|
-
return {
|
|
95
|
-
context: {
|
|
96
|
-
authSource: result.authSource,
|
|
97
|
-
activeWorkspaceId: result.activeWorkspace?.id ?? null,
|
|
98
|
-
activeWorkspaceName: result.activeWorkspace?.name ?? null
|
|
99
|
-
},
|
|
100
|
-
items: result.workspaces.map((workspace) => ({
|
|
101
|
-
id: workspace.id,
|
|
102
|
-
name: workspace.name,
|
|
103
|
-
status: workspace.active ? "active" : null,
|
|
104
|
-
source: workspace.source,
|
|
105
|
-
switchable: workspace.switchable,
|
|
106
|
-
credentialWorkspaceId: workspace.credentialWorkspaceId,
|
|
107
|
-
lastSeenAt: workspace.lastSeenAt
|
|
108
|
-
})),
|
|
109
|
-
count: result.workspaces.length
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function renderAuthWorkspaceUse(context, descriptor, result) {
|
|
113
|
-
return renderMutate({
|
|
114
|
-
title: "Switching the local CLI workspace.",
|
|
115
|
-
descriptor,
|
|
116
|
-
context: [...result.previousWorkspace ? [{
|
|
117
|
-
key: "previous",
|
|
118
|
-
value: result.previousWorkspace.name
|
|
119
|
-
}] : [], {
|
|
120
|
-
key: "workspace",
|
|
121
|
-
value: result.workspace.name
|
|
122
|
-
}],
|
|
123
|
-
operationDescription: "Applying workspace selection",
|
|
124
|
-
operationCount: 1,
|
|
125
|
-
details: ["Local OAuth workspace selection updated."]
|
|
126
|
-
}, context.ui);
|
|
127
|
-
}
|
|
128
|
-
function serializeAuthWorkspaceUse(result) {
|
|
129
|
-
return result;
|
|
130
|
-
}
|
|
131
|
-
function renderAuthWorkspaceLogout(context, descriptor, result) {
|
|
132
|
-
return renderMutate({
|
|
133
|
-
title: "Removing a local OAuth workspace session.",
|
|
134
|
-
descriptor,
|
|
135
|
-
context: [{
|
|
136
|
-
key: "workspace",
|
|
137
|
-
value: result.workspace.name
|
|
138
|
-
}, ...result.activeWorkspace ? [{
|
|
139
|
-
key: "active",
|
|
140
|
-
value: result.activeWorkspace.name
|
|
141
|
-
}] : [{
|
|
142
|
-
key: "active",
|
|
143
|
-
value: "none",
|
|
144
|
-
tone: "dim"
|
|
145
|
-
}]],
|
|
146
|
-
operationDescription: "Removing workspace session",
|
|
147
|
-
operationCount: 1,
|
|
148
|
-
details: [result.wasActive ? "Removed active workspace session; no replacement workspace was selected." : "Removed workspace session."]
|
|
149
|
-
}, context.ui);
|
|
150
|
-
}
|
|
151
|
-
function serializeAuthWorkspaceLogout(result) {
|
|
152
|
-
return result;
|
|
153
|
-
}
|
|
154
|
-
function providerLabel(provider) {
|
|
155
|
-
if (provider === "github") return "GitHub";
|
|
156
|
-
if (provider === "google") return "Google";
|
|
157
|
-
return "";
|
|
158
|
-
}
|
|
159
|
-
function authSourceLabel(source) {
|
|
160
|
-
if (source === "oauth") return "local OAuth";
|
|
161
|
-
if (source === "service_token") return "PRISMA_SERVICE_TOKEN";
|
|
162
|
-
return "none";
|
|
163
|
-
}
|
|
164
|
-
function workspaceSourceLabel(source) {
|
|
165
|
-
return source === "service_token" ? "service token" : "OAuth";
|
|
166
|
-
}
|
|
167
|
-
function authUserLabel(result) {
|
|
168
|
-
return result.user?.email ?? credentialUserLabel(result);
|
|
169
|
-
}
|
|
170
|
-
function authUserRows(result) {
|
|
171
|
-
const userLabel = authUserLabel(result);
|
|
172
|
-
return userLabel ? [{
|
|
173
|
-
key: "user",
|
|
174
|
-
value: userLabel
|
|
175
|
-
}] : [];
|
|
176
|
-
}
|
|
177
|
-
function credentialUserLabel(result) {
|
|
178
|
-
if (result.credential?.type === "service_token") return result.credential.name ? `<service token: ${result.credential.name}>` : "<service token>";
|
|
179
|
-
if (result.credential?.type === "management_token") return result.credential.name ? `<management token: ${result.credential.name}>` : "<management token>";
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
//#endregion
|
|
183
|
-
export { renderAuthSuccess, renderAuthWorkspaceList, renderAuthWorkspaceLogout, renderAuthWorkspaceUse, serializeAuthWorkspaceList, serializeAuthWorkspaceLogout, serializeAuthWorkspaceUse };
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { formatDescriptorLabel } from "../shell/command-meta.js";
|
|
2
|
-
import { formatColumns } from "../shell/ui.js";
|
|
3
|
-
import { renderResolvedProjectContextBlock } from "./verbose-context.js";
|
|
4
|
-
//#region src/presenters/branch.ts
|
|
5
|
-
function renderBranchList(context, descriptor, result) {
|
|
6
|
-
const ui = context.ui;
|
|
7
|
-
const lines = [`${ui.strong(formatDescriptorLabel(descriptor))} ${ui.dim("→")} ${ui.dim("Listing branches for the resolved project.")}`, ""];
|
|
8
|
-
const rail = ui.dim("│");
|
|
9
|
-
lines.push(`${rail} ${ui.accent("project:")} ${result.projectName}`);
|
|
10
|
-
lines.push(rail);
|
|
11
|
-
if (result.branches.length === 0) {
|
|
12
|
-
lines.push(`${rail} ${ui.dim("No branches found.")}`);
|
|
13
|
-
lines.push(...renderBranchResolvedContextBlock(context, result));
|
|
14
|
-
return lines;
|
|
15
|
-
}
|
|
16
|
-
const widths = [
|
|
17
|
-
Math.max(4, ...result.branches.map((branch) => branch.name.length)),
|
|
18
|
-
Math.max(4, ...result.branches.map((branch) => branch.role.length)),
|
|
19
|
-
Math.max(7, ...result.branches.map((branch) => branch.envMap.length))
|
|
20
|
-
];
|
|
21
|
-
lines.push(`${rail} ${ui.accent(formatColumns([
|
|
22
|
-
"Name",
|
|
23
|
-
"Role",
|
|
24
|
-
"Env map"
|
|
25
|
-
], widths))}`);
|
|
26
|
-
for (const branch of result.branches) lines.push(`${rail} ${formatColumns([
|
|
27
|
-
branch.name,
|
|
28
|
-
branch.role,
|
|
29
|
-
branch.envMap
|
|
30
|
-
], widths)}`);
|
|
31
|
-
lines.push(...renderBranchResolvedContextBlock(context, result));
|
|
32
|
-
return lines;
|
|
33
|
-
}
|
|
34
|
-
function serializeBranchList(result) {
|
|
35
|
-
const { verboseContext: _verboseContext, ...serializable } = result;
|
|
36
|
-
return {
|
|
37
|
-
projectId: serializable.projectId,
|
|
38
|
-
projectName: serializable.projectName,
|
|
39
|
-
branches: serializable.branches
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function renderBranchResolvedContextBlock(context, result) {
|
|
43
|
-
return renderResolvedProjectContextBlock(context.ui, result.verboseContext);
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
|
-
export { renderBranchList, serializeBranchList };
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
import { formatDescriptorLabel } from "../shell/command-meta.js";
|
|
2
|
-
import { formatColumns, renderSummaryLine } from "../shell/ui.js";
|
|
3
|
-
import { renderMutate, renderShow, serializeList } from "../output/patterns.js";
|
|
4
|
-
import { renderResolvedProjectContextBlock, stripVerboseContext } from "./verbose-context.js";
|
|
5
|
-
//#region src/presenters/database.ts
|
|
6
|
-
function renderDatabaseList(context, descriptor, result) {
|
|
7
|
-
const ui = context.ui;
|
|
8
|
-
const lines = [`${ui.strong(formatDescriptorLabel(descriptor))} ${ui.dim("→")} ${ui.dim("Listing databases for the resolved project.")}`, ""];
|
|
9
|
-
const rail = ui.dim("│");
|
|
10
|
-
lines.push(`${rail} ${ui.accent("project:")} ${result.projectName}`);
|
|
11
|
-
if (result.branchName) lines.push(`${rail} ${ui.accent("branch:")} ${result.branchName}`);
|
|
12
|
-
lines.push(rail);
|
|
13
|
-
if (result.databases.length === 0) {
|
|
14
|
-
lines.push(`${rail} ${ui.dim("No databases found.")}`);
|
|
15
|
-
lines.push(...renderResolvedProjectContextBlock(context.ui, result.verboseContext));
|
|
16
|
-
return lines;
|
|
17
|
-
}
|
|
18
|
-
const rows = result.databases.map((database) => [
|
|
19
|
-
database.name,
|
|
20
|
-
database.branchName ?? "unscoped",
|
|
21
|
-
database.region ?? "unknown",
|
|
22
|
-
formatStatus(database),
|
|
23
|
-
database.id
|
|
24
|
-
]);
|
|
25
|
-
const widths = [
|
|
26
|
-
Math.max(4, ...rows.map((row) => row[0].length)),
|
|
27
|
-
Math.max(6, ...rows.map((row) => row[1].length)),
|
|
28
|
-
Math.max(6, ...rows.map((row) => row[2].length)),
|
|
29
|
-
Math.max(6, ...rows.map((row) => row[3].length)),
|
|
30
|
-
Math.max(2, ...rows.map((row) => row[4].length))
|
|
31
|
-
];
|
|
32
|
-
lines.push(`${rail} ${ui.accent(formatColumns([
|
|
33
|
-
"Name",
|
|
34
|
-
"Branch",
|
|
35
|
-
"Region",
|
|
36
|
-
"Status",
|
|
37
|
-
"Id"
|
|
38
|
-
], widths))}`);
|
|
39
|
-
for (const row of rows) lines.push(`${rail} ${formatColumns(row, widths)}`);
|
|
40
|
-
lines.push(...renderResolvedProjectContextBlock(context.ui, result.verboseContext));
|
|
41
|
-
return lines;
|
|
42
|
-
}
|
|
43
|
-
function serializeDatabaseList(result) {
|
|
44
|
-
return {
|
|
45
|
-
...serializeList({
|
|
46
|
-
context: {
|
|
47
|
-
project: result.projectName,
|
|
48
|
-
...result.branchName ? { branch: result.branchName } : {}
|
|
49
|
-
},
|
|
50
|
-
items: result.databases.map((database) => ({
|
|
51
|
-
noun: "database",
|
|
52
|
-
label: database.name,
|
|
53
|
-
id: database.id,
|
|
54
|
-
status: database.isDefault ? "default" : null
|
|
55
|
-
}))
|
|
56
|
-
}),
|
|
57
|
-
projectId: result.projectId,
|
|
58
|
-
branchName: result.branchName,
|
|
59
|
-
databases: result.databases
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
function renderDatabaseShow(context, descriptor, result) {
|
|
63
|
-
const lines = renderShow({
|
|
64
|
-
title: "Showing database metadata.",
|
|
65
|
-
descriptor,
|
|
66
|
-
fields: [
|
|
67
|
-
{
|
|
68
|
-
key: "project",
|
|
69
|
-
value: result.projectName
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
key: "database",
|
|
73
|
-
value: result.database.name
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
key: "id",
|
|
77
|
-
value: result.database.id,
|
|
78
|
-
tone: "dim"
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
key: "branch",
|
|
82
|
-
value: result.database.branchName ?? "unscoped",
|
|
83
|
-
tone: result.database.branchName ? "default" : "dim"
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
key: "region",
|
|
87
|
-
value: result.database.region ?? "unknown",
|
|
88
|
-
tone: result.database.region ? "default" : "dim"
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
key: "status",
|
|
92
|
-
value: formatStatus(result.database)
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
key: "connections",
|
|
96
|
-
value: String(result.connections.length)
|
|
97
|
-
}
|
|
98
|
-
]
|
|
99
|
-
}, context.ui);
|
|
100
|
-
lines.push(...renderResolvedProjectContextBlock(context.ui, result.verboseContext));
|
|
101
|
-
return lines;
|
|
102
|
-
}
|
|
103
|
-
function serializeDatabaseShow(result) {
|
|
104
|
-
return stripVerboseContext(result);
|
|
105
|
-
}
|
|
106
|
-
function renderDatabaseCreateStdout(_context, _descriptor, result) {
|
|
107
|
-
return [result.connectionString];
|
|
108
|
-
}
|
|
109
|
-
function renderDatabaseCreate(context, _descriptor, result) {
|
|
110
|
-
const ui = context.ui;
|
|
111
|
-
const lines = [
|
|
112
|
-
"Creating database...",
|
|
113
|
-
renderSummaryLine(ui, "success", `Created database "${result.database.name}" in ${formatDatabaseTarget(result.projectName, result.database.branchName)}.`),
|
|
114
|
-
" The connection URL below is shown once, so save it now."
|
|
115
|
-
];
|
|
116
|
-
if (ui.verbose) {
|
|
117
|
-
lines.push("");
|
|
118
|
-
lines.push(...renderDatabaseCreateVerboseRows(context, result));
|
|
119
|
-
}
|
|
120
|
-
return lines;
|
|
121
|
-
}
|
|
122
|
-
function serializeDatabaseCreate(result) {
|
|
123
|
-
return stripVerboseContext(result);
|
|
124
|
-
}
|
|
125
|
-
function renderDatabaseRemove(context, descriptor, result) {
|
|
126
|
-
const lines = renderMutate({
|
|
127
|
-
title: "Removing database.",
|
|
128
|
-
descriptor,
|
|
129
|
-
context: [
|
|
130
|
-
{
|
|
131
|
-
key: "project",
|
|
132
|
-
value: result.projectName
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
key: "database",
|
|
136
|
-
value: result.database.name
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
key: "id",
|
|
140
|
-
value: result.database.id,
|
|
141
|
-
tone: "dim"
|
|
142
|
-
}
|
|
143
|
-
],
|
|
144
|
-
operationDescription: "Removing database",
|
|
145
|
-
operationCount: 1,
|
|
146
|
-
details: ["Database and its connection metadata were removed."]
|
|
147
|
-
}, context.ui);
|
|
148
|
-
lines.push(...renderResolvedProjectContextBlock(context.ui, result.verboseContext));
|
|
149
|
-
return lines;
|
|
150
|
-
}
|
|
151
|
-
function serializeDatabaseRemove(result) {
|
|
152
|
-
return stripVerboseContext(result);
|
|
153
|
-
}
|
|
154
|
-
function renderDatabaseConnectionList(context, descriptor, result) {
|
|
155
|
-
const ui = context.ui;
|
|
156
|
-
const lines = [`${ui.strong(formatDescriptorLabel(descriptor))} ${ui.dim("→")} ${ui.dim("Listing database connection metadata.")}`, ""];
|
|
157
|
-
const rail = ui.dim("│");
|
|
158
|
-
lines.push(`${rail} ${ui.accent("database:")} ${result.database.name}`);
|
|
159
|
-
lines.push(rail);
|
|
160
|
-
if (result.connections.length === 0) {
|
|
161
|
-
lines.push(`${rail} ${ui.dim("No database connections found.")}`);
|
|
162
|
-
lines.push(...renderResolvedProjectContextBlock(context.ui, result.verboseContext));
|
|
163
|
-
return lines;
|
|
164
|
-
}
|
|
165
|
-
const rows = result.connections.map((connection) => [
|
|
166
|
-
connection.name,
|
|
167
|
-
connection.id,
|
|
168
|
-
connection.createdAt ?? "unknown"
|
|
169
|
-
]);
|
|
170
|
-
const widths = [
|
|
171
|
-
Math.max(4, ...rows.map((row) => row[0].length)),
|
|
172
|
-
Math.max(2, ...rows.map((row) => row[1].length)),
|
|
173
|
-
Math.max(7, ...rows.map((row) => row[2].length))
|
|
174
|
-
];
|
|
175
|
-
lines.push(`${rail} ${ui.accent(formatColumns([
|
|
176
|
-
"Name",
|
|
177
|
-
"Id",
|
|
178
|
-
"Created"
|
|
179
|
-
], widths))}`);
|
|
180
|
-
for (const row of rows) lines.push(`${rail} ${formatColumns(row, widths)}`);
|
|
181
|
-
lines.push(...renderResolvedProjectContextBlock(context.ui, result.verboseContext));
|
|
182
|
-
return lines;
|
|
183
|
-
}
|
|
184
|
-
function serializeDatabaseConnectionList(result) {
|
|
185
|
-
return {
|
|
186
|
-
...serializeList({
|
|
187
|
-
context: {
|
|
188
|
-
project: result.projectName,
|
|
189
|
-
database: result.database.name
|
|
190
|
-
},
|
|
191
|
-
items: result.connections.map((connection) => ({
|
|
192
|
-
noun: "connection",
|
|
193
|
-
label: connection.name,
|
|
194
|
-
id: connection.id,
|
|
195
|
-
status: null
|
|
196
|
-
}))
|
|
197
|
-
}),
|
|
198
|
-
projectId: result.projectId,
|
|
199
|
-
database: result.database,
|
|
200
|
-
connections: result.connections
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
function renderDatabaseConnectionCreateStdout(_context, _descriptor, result) {
|
|
204
|
-
return [result.connectionString];
|
|
205
|
-
}
|
|
206
|
-
function renderDatabaseConnectionCreate(context, _descriptor, result) {
|
|
207
|
-
const ui = context.ui;
|
|
208
|
-
const lines = [
|
|
209
|
-
"Creating connection...",
|
|
210
|
-
renderSummaryLine(ui, "success", `Added a connection to "${result.database.name}" in ${formatDatabaseTarget(result.projectName, result.database.branchName)}.`),
|
|
211
|
-
" The connection URL below is shown once, so save it now."
|
|
212
|
-
];
|
|
213
|
-
if (ui.verbose) {
|
|
214
|
-
lines.push("");
|
|
215
|
-
lines.push(...renderDatabaseConnectionCreateVerboseRows(context, result));
|
|
216
|
-
}
|
|
217
|
-
return lines;
|
|
218
|
-
}
|
|
219
|
-
function serializeDatabaseConnectionCreate(result) {
|
|
220
|
-
return stripVerboseContext(result);
|
|
221
|
-
}
|
|
222
|
-
function renderDatabaseConnectionRemove(context, descriptor, result) {
|
|
223
|
-
return renderMutate({
|
|
224
|
-
title: "Removing database connection.",
|
|
225
|
-
descriptor,
|
|
226
|
-
context: [{
|
|
227
|
-
key: "connection",
|
|
228
|
-
value: result.connection.id,
|
|
229
|
-
tone: "dim"
|
|
230
|
-
}],
|
|
231
|
-
operationDescription: "Removing database connection",
|
|
232
|
-
operationCount: 1,
|
|
233
|
-
details: ["The connection metadata was removed. Existing one-time secrets were not shown."]
|
|
234
|
-
}, context.ui);
|
|
235
|
-
}
|
|
236
|
-
function serializeDatabaseConnectionRemove(result) {
|
|
237
|
-
return { connection: result.connection };
|
|
238
|
-
}
|
|
239
|
-
function formatStatus(database) {
|
|
240
|
-
return database.status ?? (database.isDefault ? "default" : "unknown");
|
|
241
|
-
}
|
|
242
|
-
function formatDatabaseTarget(projectName, branchName) {
|
|
243
|
-
return branchName ? `${projectName} / ${branchName}` : projectName;
|
|
244
|
-
}
|
|
245
|
-
function renderDatabaseCreateVerboseRows(context, result) {
|
|
246
|
-
return renderMetadataRows([
|
|
247
|
-
...renderWorkspaceProjectRows(result),
|
|
248
|
-
["branch", result.database.branchName ?? "unscoped"],
|
|
249
|
-
["database", formatResourceWithId(context, result.database.name, result.database.id)],
|
|
250
|
-
["region", result.database.region ?? "unknown"],
|
|
251
|
-
["status", formatStatus(result.database)],
|
|
252
|
-
["connection", formatResourceWithId(context, result.connection.name, result.connection.id)]
|
|
253
|
-
]);
|
|
254
|
-
}
|
|
255
|
-
function renderDatabaseConnectionCreateVerboseRows(context, result) {
|
|
256
|
-
return renderMetadataRows([
|
|
257
|
-
...renderWorkspaceProjectRows(result),
|
|
258
|
-
["branch", result.database.branchName ?? "unscoped"],
|
|
259
|
-
["database", formatResourceWithId(context, result.database.name, result.database.id)],
|
|
260
|
-
["connection", formatResourceWithId(context, result.connection.name, result.connection.id)]
|
|
261
|
-
]);
|
|
262
|
-
}
|
|
263
|
-
function renderWorkspaceProjectRows(result) {
|
|
264
|
-
return [...result.verboseContext ? [["workspace", result.verboseContext.workspace.name]] : [], ["project", result.projectName]];
|
|
265
|
-
}
|
|
266
|
-
function formatResourceWithId(context, name, id) {
|
|
267
|
-
return `${name} ${context.ui.dim(`(${id})`)}`;
|
|
268
|
-
}
|
|
269
|
-
function renderMetadataRows(rows) {
|
|
270
|
-
const widths = [Math.max(...rows.map((row) => row[0].length)), 0];
|
|
271
|
-
return rows.map(([key, value]) => ` ${formatColumns([key, value], widths)}`);
|
|
272
|
-
}
|
|
273
|
-
//#endregion
|
|
274
|
-
export { renderDatabaseConnectionCreate, renderDatabaseConnectionCreateStdout, renderDatabaseConnectionList, renderDatabaseConnectionRemove, renderDatabaseCreate, renderDatabaseCreateStdout, renderDatabaseList, renderDatabaseRemove, renderDatabaseShow, serializeDatabaseConnectionCreate, serializeDatabaseConnectionList, serializeDatabaseConnectionRemove, serializeDatabaseCreate, serializeDatabaseList, serializeDatabaseRemove, serializeDatabaseShow };
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { formatDescriptorLabel } from "../shell/command-meta.js";
|
|
2
|
-
import { padDisplay, renderNextSteps, renderSummaryLine, renderVerboseBlock } from "../shell/ui.js";
|
|
3
|
-
import { shortenHomePath } from "../lib/fs/home-path.js";
|
|
4
|
-
import { formatCommandArgument } from "../shell/command-arguments.js";
|
|
5
|
-
import { renderMutate, renderShow, serializeList } from "../output/patterns.js";
|
|
6
|
-
import { renderResolvedProjectContextBlock } from "./verbose-context.js";
|
|
7
|
-
import stringWidth from "string-width";
|
|
8
|
-
//#region src/presenters/project.ts
|
|
9
|
-
function renderProjectList(context, descriptor, result) {
|
|
10
|
-
const ui = context.ui;
|
|
11
|
-
const rail = ui.dim("│");
|
|
12
|
-
const lines = [`${ui.strong(formatDescriptorLabel(descriptor))} ${ui.dim("→")} ${ui.dim("Listing projects for the authenticated workspace.")}`, ""];
|
|
13
|
-
lines.push(`${rail} ${ui.accent("workspace:")} ${result.workspace.name}`);
|
|
14
|
-
if (result.projects.length === 0) {
|
|
15
|
-
lines.push(`${rail} ${ui.dim("No projects found.")}`);
|
|
16
|
-
if (result.localBinding?.status === "not-linked" || result.localBinding?.status === "invalid") lines.push(...renderNextSteps(["Link an existing Project you choose: prisma-cli project link <id-or-name>", "Create a new Project: prisma-cli project create <name>"]));
|
|
17
|
-
return lines;
|
|
18
|
-
}
|
|
19
|
-
const nameWidth = Math.max(4, ...result.projects.map((project) => stringWidth(project.name)));
|
|
20
|
-
lines.push(rail);
|
|
21
|
-
lines.push(`${rail} ${ui.accent(padDisplay("name", nameWidth))} ${ui.accent("id")}`);
|
|
22
|
-
for (const project of result.projects) lines.push(`${rail} ${padDisplay(project.name, nameWidth)} ${project.id}`);
|
|
23
|
-
if (result.localBinding?.status === "not-linked" || result.localBinding?.status === "invalid") lines.push(...renderNextSteps(["Link an existing Project you choose: prisma-cli project link <id-or-name>", "Create a new Project: prisma-cli project create <name>"]));
|
|
24
|
-
return lines;
|
|
25
|
-
}
|
|
26
|
-
function serializeProjectList(result) {
|
|
27
|
-
return {
|
|
28
|
-
...serializeList({
|
|
29
|
-
context: { workspace: result.workspace.name },
|
|
30
|
-
items: result.projects.map((project) => ({
|
|
31
|
-
noun: "project",
|
|
32
|
-
label: project.name,
|
|
33
|
-
id: project.id,
|
|
34
|
-
status: null
|
|
35
|
-
}))
|
|
36
|
-
}),
|
|
37
|
-
localBinding: result.localBinding ?? null
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function renderProjectShow(context, descriptor, result) {
|
|
41
|
-
if (result.project === null) {
|
|
42
|
-
const lines = renderShow({
|
|
43
|
-
title: "This directory is not linked to a Prisma Project.",
|
|
44
|
-
descriptor,
|
|
45
|
-
fields: [{
|
|
46
|
-
key: "workspace",
|
|
47
|
-
value: result.workspace.name
|
|
48
|
-
}, {
|
|
49
|
-
key: "project",
|
|
50
|
-
value: "Not linked",
|
|
51
|
-
tone: "warning"
|
|
52
|
-
}]
|
|
53
|
-
}, context.ui);
|
|
54
|
-
lines.push(...renderVerboseBlock(context.ui, [
|
|
55
|
-
{
|
|
56
|
-
key: "workspace",
|
|
57
|
-
value: result.workspace.name
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
key: "workspace id",
|
|
61
|
-
value: result.workspace.id,
|
|
62
|
-
tone: "dim"
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
key: "project source",
|
|
66
|
-
value: "unbound"
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
key: "suggested name",
|
|
70
|
-
value: `${result.suggestedProjectName} (${result.suggestedProjectNameSource})`
|
|
71
|
-
}
|
|
72
|
-
], { title: "Resolved context" }));
|
|
73
|
-
lines.push(...renderNextSteps(["Link an existing Project you choose: prisma-cli project link <id-or-name>", `Create a new Project: prisma-cli project create ${formatCommandArgument(result.suggestedProjectName)}`]));
|
|
74
|
-
return lines;
|
|
75
|
-
}
|
|
76
|
-
return renderBoundProjectShow(context, descriptor, result);
|
|
77
|
-
}
|
|
78
|
-
function serializeProjectShow(result) {
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
function renderProjectSetup(context, _descriptor, result) {
|
|
82
|
-
const lines = result.action === "created" ? [renderSummaryLine(context.ui, "success", `Created Project "${result.project.name}"`)] : [];
|
|
83
|
-
lines.push(renderSummaryLine(context.ui, "success", `Linked "${result.directory}" to Project "${result.project.name}"`), `Saved ${result.localPin.path}`);
|
|
84
|
-
return lines;
|
|
85
|
-
}
|
|
86
|
-
function serializeProjectSetup(result) {
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
function renderGitConnect(context, descriptor, result) {
|
|
90
|
-
const connection = result.repositoryConnection;
|
|
91
|
-
return renderMutate({
|
|
92
|
-
title: "Connecting Git to the resolved project.",
|
|
93
|
-
descriptor,
|
|
94
|
-
context: [
|
|
95
|
-
{
|
|
96
|
-
key: "project",
|
|
97
|
-
value: result.project.name
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
key: "workspace",
|
|
101
|
-
value: result.workspace.name
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
key: "repository",
|
|
105
|
-
value: connection.repository.fullName
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
key: "status",
|
|
109
|
-
value: connection.status
|
|
110
|
-
}
|
|
111
|
-
],
|
|
112
|
-
operationDescription: "Applying repository connection",
|
|
113
|
-
operationCount: 1,
|
|
114
|
-
details: [formatGitConnectionDetail(connection.status)]
|
|
115
|
-
}, context.ui);
|
|
116
|
-
}
|
|
117
|
-
function renderGitDisconnect(context, descriptor, result) {
|
|
118
|
-
return renderMutate({
|
|
119
|
-
title: "Disconnecting Git from the resolved project.",
|
|
120
|
-
descriptor,
|
|
121
|
-
context: [
|
|
122
|
-
{
|
|
123
|
-
key: "project",
|
|
124
|
-
value: result.project.name
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
key: "workspace",
|
|
128
|
-
value: result.workspace.name
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
key: "repository",
|
|
132
|
-
value: result.repositoryConnection.repository.fullName
|
|
133
|
-
}
|
|
134
|
-
],
|
|
135
|
-
operationDescription: "Applying repository disconnection",
|
|
136
|
-
operationCount: 1,
|
|
137
|
-
details: ["GitHub branch automation is no longer active for this project."]
|
|
138
|
-
}, context.ui);
|
|
139
|
-
}
|
|
140
|
-
function renderBoundProjectShow(context, descriptor, result) {
|
|
141
|
-
const { ui } = context;
|
|
142
|
-
const rail = ui.dim("│");
|
|
143
|
-
const keyWidth = 10;
|
|
144
|
-
const platform = `${result.workspace.name} / ${result.project.name}`;
|
|
145
|
-
const lines = [
|
|
146
|
-
`${ui.strong(formatDescriptorLabel(descriptor))} ${ui.dim("→")} ${ui.dim("This directory is linked to the following platform project.")}`,
|
|
147
|
-
"",
|
|
148
|
-
`${rail} ${ui.accent(padDisplay("local repo", keyWidth))} ${formatLocalRepoPath(context.runtime.cwd, context.runtime.env)}`,
|
|
149
|
-
`${rail} ${ui.accent(padDisplay("platform", keyWidth))} ${ui.strong(platform)}`
|
|
150
|
-
];
|
|
151
|
-
if (result.project.url) {
|
|
152
|
-
lines.push(rail);
|
|
153
|
-
lines.push(`${rail} ${ui.dim("→")} ${ui.link(result.project.url)}`);
|
|
154
|
-
}
|
|
155
|
-
lines.push(...renderResolvedProjectContextBlock(context.ui, {
|
|
156
|
-
workspace: result.workspace,
|
|
157
|
-
project: result.project,
|
|
158
|
-
resolution: result.resolution
|
|
159
|
-
}));
|
|
160
|
-
return lines;
|
|
161
|
-
}
|
|
162
|
-
function formatLocalRepoPath(cwd, env) {
|
|
163
|
-
return shortenHomePath(cwd, env);
|
|
164
|
-
}
|
|
165
|
-
function formatGitConnectionDetail(status) {
|
|
166
|
-
switch (status) {
|
|
167
|
-
case "active": return "GitHub branch automation is active for this project.";
|
|
168
|
-
case "pending": return "GitHub branch automation is pending GitHub App installation.";
|
|
169
|
-
case "archived": return "GitHub branch automation has been archived for this project.";
|
|
170
|
-
default: return "GitHub repository is connected, but branch automation is not active.";
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
//#endregion
|
|
174
|
-
export { renderGitConnect, renderGitDisconnect, renderProjectList, renderProjectSetup, renderProjectShow, serializeProjectList, serializeProjectSetup, serializeProjectShow };
|