@prisma/cli 8.0.0-rc.1 → 8.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -29
- package/dist/cli.js +14551 -16
- package/dist/{v8/sender.js → sender.js} +1 -1
- package/package.json +17 -18
- package/dist/adapters/git.js +0 -54
- package/dist/adapters/local-state.js +0 -155
- package/dist/auth/client.js +0 -30
- package/dist/auth/errors.js +0 -50
- package/dist/auth/guard.js +0 -39
- package/dist/auth/login.js +0 -471
- package/dist/auth/operations.js +0 -208
- package/dist/auth/recipient.js +0 -42
- package/dist/auth/token-storage.js +0 -439
- package/dist/auth/workspaces.js +0 -171
- package/dist/cli-command.js +0 -14
- package/dist/cli-name.js +0 -12
- package/dist/cli2.js +0 -136
- package/dist/command-arguments.js +0 -12
- package/dist/commands/agent/index.js +0 -60
- package/dist/commands/app/index.js +0 -350
- package/dist/commands/auth/index.js +0 -95
- package/dist/commands/branch/index.js +0 -27
- package/dist/commands/bucket/index.js +0 -123
- package/dist/commands/build/index.js +0 -29
- package/dist/commands/database/index.js +0 -249
- package/dist/commands/env.js +0 -99
- package/dist/commands/feedback/index.js +0 -20
- package/dist/commands/git/index.js +0 -36
- package/dist/commands/init/index.js +0 -33
- package/dist/commands/project/index.js +0 -118
- package/dist/commands/version/index.js +0 -18
- package/dist/controllers/agent-setup.js +0 -52
- package/dist/controllers/agent.js +0 -228
- package/dist/controllers/app-env-api.js +0 -55
- package/dist/controllers/app-env-file.js +0 -181
- package/dist/controllers/app-env.js +0 -502
- package/dist/controllers/app.js +0 -2508
- package/dist/controllers/auth.js +0 -124
- package/dist/controllers/branch.js +0 -92
- package/dist/controllers/bucket.js +0 -184
- package/dist/controllers/build.js +0 -88
- package/dist/controllers/database.js +0 -463
- package/dist/controllers/feedback.js +0 -90
- package/dist/controllers/init.js +0 -814
- package/dist/controllers/project.js +0 -892
- package/dist/controllers/select-prompt-port.js +0 -13
- package/dist/controllers/version.js +0 -12
- package/dist/errors.js +0 -102
- package/dist/lib/agent/cli-command.js +0 -20
- package/dist/lib/agent/constants.js +0 -12
- package/dist/lib/agent/package-manager.js +0 -99
- package/dist/lib/agent/setup-status.js +0 -83
- package/dist/lib/app/app-provider.js +0 -617
- package/dist/lib/app/branch-database-api.js +0 -102
- package/dist/lib/app/branch-database-deploy.js +0 -353
- package/dist/lib/app/branch-database.js +0 -234
- package/dist/lib/app/build-settings.js +0 -98
- package/dist/lib/app/build.js +0 -82
- package/dist/lib/app/bun-project.js +0 -45
- package/dist/lib/app/compute-config.js +0 -145
- package/dist/lib/app/deploy-output.js +0 -24
- package/dist/lib/app/deploy-plan.js +0 -59
- 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 -162
- package/dist/lib/app/read-branch.js +0 -30
- package/dist/lib/bucket/provider.js +0 -139
- package/dist/lib/database/provider.js +0 -385
- package/dist/lib/diagnostics.js +0 -16
- package/dist/lib/feedback.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 -57
- package/dist/lib/project/local-pin.js +0 -200
- package/dist/lib/project/provider.js +0 -93
- package/dist/lib/project/resolution.js +0 -389
- package/dist/lib/project/setup.js +0 -138
- package/dist/lib/version.js +0 -56
- package/dist/lib/workspace-id.js +0 -18
- package/dist/output/patterns.js +0 -90
- package/dist/presenters/agent.js +0 -74
- package/dist/presenters/app-env.js +0 -265
- package/dist/presenters/app.js +0 -672
- package/dist/presenters/auth.js +0 -184
- package/dist/presenters/branch.js +0 -46
- package/dist/presenters/bucket.js +0 -174
- package/dist/presenters/database.js +0 -462
- package/dist/presenters/feedback.js +0 -26
- package/dist/presenters/init.js +0 -30
- package/dist/presenters/project.js +0 -268
- package/dist/presenters/verbose-context.js +0 -64
- package/dist/presenters/version.js +0 -29
- package/dist/shell/cli-command.js +0 -2
- package/dist/shell/command-meta.js +0 -923
- package/dist/shell/command-runner.js +0 -119
- package/dist/shell/diagnostics-output.js +0 -57
- package/dist/shell/global-flags.js +0 -37
- package/dist/shell/help.js +0 -90
- package/dist/shell/output.js +0 -144
- package/dist/shell/prompt.js +0 -48
- package/dist/shell/runtime.js +0 -38
- package/dist/shell/ui.js +0 -116
- package/dist/state-dir.js +0 -12
- package/dist/update-check.js +0 -248
- package/dist/v8/cli.js +0 -14699
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
import { resolvePrismaCliPackageCommandFormatterSync } from "../lib/agent/cli-command.js";
|
|
2
|
-
import { CliError, authRequiredError, usageError, workspaceRequiredError } from "../errors.js";
|
|
3
|
-
import { authenticatedManagementApiClient } from "../auth/guard.js";
|
|
4
|
-
import { projectResolutionErrorToCliError, resolveProjectTarget } from "../lib/project/resolution.js";
|
|
5
|
-
import { requireAuthenticatedAuthState } from "./auth.js";
|
|
6
|
-
import { listRealWorkspaceProjects } from "./project.js";
|
|
7
|
-
import { createManagementDatabaseProvider } from "../lib/database/provider.js";
|
|
8
|
-
import { randomBytes } from "node:crypto";
|
|
9
|
-
//#region src/controllers/database.ts
|
|
10
|
-
async function runDatabaseList(context, flags) {
|
|
11
|
-
const { provider, target } = await requireDatabaseContext(context, flags, "database list");
|
|
12
|
-
const databases = sortDatabases(await provider.listDatabases({
|
|
13
|
-
projectId: target.project.id,
|
|
14
|
-
branchName: flags.branchName,
|
|
15
|
-
signal: context.runtime.signal
|
|
16
|
-
}));
|
|
17
|
-
return {
|
|
18
|
-
command: "database.list",
|
|
19
|
-
result: {
|
|
20
|
-
projectId: target.project.id,
|
|
21
|
-
projectName: target.project.name,
|
|
22
|
-
branchName: flags.branchName ?? null,
|
|
23
|
-
verboseContext: target,
|
|
24
|
-
databases
|
|
25
|
-
},
|
|
26
|
-
warnings: [],
|
|
27
|
-
nextSteps: []
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
async function runDatabaseShow(context, databaseRef, flags) {
|
|
31
|
-
const { provider, target } = await requireDatabaseContext(context, flags, "database show");
|
|
32
|
-
const database = await resolveDatabase(provider, target, databaseRef, flags.branchName, context.runtime.signal);
|
|
33
|
-
const connections = await provider.listConnections(database.id, { signal: context.runtime.signal });
|
|
34
|
-
return {
|
|
35
|
-
command: "database.show",
|
|
36
|
-
result: {
|
|
37
|
-
projectId: target.project.id,
|
|
38
|
-
projectName: target.project.name,
|
|
39
|
-
verboseContext: target,
|
|
40
|
-
database,
|
|
41
|
-
connections
|
|
42
|
-
},
|
|
43
|
-
warnings: [],
|
|
44
|
-
nextSteps: []
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
async function runDatabaseCreate(context, name, flags) {
|
|
48
|
-
const databaseName = name.trim();
|
|
49
|
-
if (!databaseName) throw usageError("Database name required", "Database create needs a non-empty name.", "Pass a database name.", ["prisma-cli database create <name>"], "database");
|
|
50
|
-
const { provider, target } = await requireDatabaseContext(context, flags, "database create");
|
|
51
|
-
const created = await provider.createDatabase({
|
|
52
|
-
projectId: target.project.id,
|
|
53
|
-
name: databaseName,
|
|
54
|
-
branchName: flags.branchName,
|
|
55
|
-
region: flags.region,
|
|
56
|
-
signal: context.runtime.signal
|
|
57
|
-
});
|
|
58
|
-
return {
|
|
59
|
-
command: "database.create",
|
|
60
|
-
result: {
|
|
61
|
-
projectId: target.project.id,
|
|
62
|
-
projectName: target.project.name,
|
|
63
|
-
verboseContext: target,
|
|
64
|
-
database: ensureProjectId(created.database, target.project.id),
|
|
65
|
-
connection: created.connection,
|
|
66
|
-
connectionString: created.connectionString
|
|
67
|
-
},
|
|
68
|
-
warnings: [],
|
|
69
|
-
nextSteps: []
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
async function runDatabaseRemove(context, databaseRef, flags) {
|
|
73
|
-
const { provider, target } = await requireDatabaseContext(context, flags, "database remove");
|
|
74
|
-
const database = await resolveDatabase(provider, target, databaseRef, flags.branchName, context.runtime.signal);
|
|
75
|
-
requireExactConfirmation({
|
|
76
|
-
resourceName: "database",
|
|
77
|
-
commandName: "database remove",
|
|
78
|
-
id: database.id,
|
|
79
|
-
confirm: flags.confirm
|
|
80
|
-
});
|
|
81
|
-
await provider.removeDatabase(database.id, { signal: context.runtime.signal });
|
|
82
|
-
return {
|
|
83
|
-
command: "database.remove",
|
|
84
|
-
result: {
|
|
85
|
-
projectId: target.project.id,
|
|
86
|
-
projectName: target.project.name,
|
|
87
|
-
verboseContext: target,
|
|
88
|
-
database
|
|
89
|
-
},
|
|
90
|
-
warnings: [],
|
|
91
|
-
nextSteps: []
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
async function runDatabaseConnectionList(context, databaseRef, flags) {
|
|
95
|
-
const { provider, target } = await requireDatabaseContext(context, flags, "database connection list");
|
|
96
|
-
const database = await resolveDatabase(provider, target, databaseRef, flags.branchName, context.runtime.signal);
|
|
97
|
-
const connections = await provider.listConnections(database.id, { signal: context.runtime.signal });
|
|
98
|
-
return {
|
|
99
|
-
command: "database.connection.list",
|
|
100
|
-
result: {
|
|
101
|
-
projectId: target.project.id,
|
|
102
|
-
projectName: target.project.name,
|
|
103
|
-
verboseContext: target,
|
|
104
|
-
database,
|
|
105
|
-
connections
|
|
106
|
-
},
|
|
107
|
-
warnings: [],
|
|
108
|
-
nextSteps: []
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
async function runDatabaseConnectionCreate(context, databaseRef, flags) {
|
|
112
|
-
const { provider, target } = await requireDatabaseContext(context, flags, "database connection create");
|
|
113
|
-
const database = await resolveDatabase(provider, target, databaseRef, flags.branchName, context.runtime.signal);
|
|
114
|
-
const created = await provider.createConnection({
|
|
115
|
-
databaseId: database.id,
|
|
116
|
-
name: flags.name?.trim() || defaultConnectionName(),
|
|
117
|
-
signal: context.runtime.signal
|
|
118
|
-
});
|
|
119
|
-
return {
|
|
120
|
-
command: "database.connection.create",
|
|
121
|
-
result: {
|
|
122
|
-
projectId: target.project.id,
|
|
123
|
-
projectName: target.project.name,
|
|
124
|
-
verboseContext: target,
|
|
125
|
-
database,
|
|
126
|
-
connection: created.connection,
|
|
127
|
-
connectionString: created.connectionString
|
|
128
|
-
},
|
|
129
|
-
warnings: [],
|
|
130
|
-
nextSteps: []
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
async function runDatabaseConnectionRemove(context, connectionRef, flags) {
|
|
134
|
-
const connectionId = connectionRef.trim();
|
|
135
|
-
if (!connectionId) throw usageError("Connection id required", "Database connection removal needs a connection id.", "Pass the connection id to remove.", ["prisma-cli database connection remove <connection-id> --confirm <connection-id>"], "database");
|
|
136
|
-
requireExactConfirmation({
|
|
137
|
-
resourceName: "database connection",
|
|
138
|
-
commandName: "database connection remove",
|
|
139
|
-
id: connectionId,
|
|
140
|
-
confirm: flags.confirm
|
|
141
|
-
});
|
|
142
|
-
await (await requireDatabaseProviderOnly(context)).removeConnection(connectionId, { signal: context.runtime.signal });
|
|
143
|
-
return {
|
|
144
|
-
command: "database.connection.remove",
|
|
145
|
-
result: { connection: { id: connectionId } },
|
|
146
|
-
warnings: [],
|
|
147
|
-
nextSteps: []
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
async function runDatabaseUsage(context, databaseRef, flags) {
|
|
151
|
-
const formatCommand = resolvePrismaCliPackageCommandFormatterSync(context.runtime.cwd);
|
|
152
|
-
const from = parseUsageDate(flags.from, "--from", "start", formatCommand);
|
|
153
|
-
const to = parseUsageDate(flags.to, "--to", "end", formatCommand);
|
|
154
|
-
if (from && to && Date.parse(from) > Date.parse(to)) throw usageError("Invalid usage period", "--from must not be later than --to.", "Pass a --from date that is on or before the --to date.", [formatCommand([
|
|
155
|
-
"database",
|
|
156
|
-
"usage",
|
|
157
|
-
"<database>",
|
|
158
|
-
"--from",
|
|
159
|
-
"2026-06-01",
|
|
160
|
-
"--to",
|
|
161
|
-
"2026-06-30"
|
|
162
|
-
])], "database");
|
|
163
|
-
const { provider, target } = await requireDatabaseContext(context, flags, "database usage");
|
|
164
|
-
const database = await resolveDatabase(provider, target, databaseRef, flags.branchName, context.runtime.signal);
|
|
165
|
-
const usage = await provider.getUsage(database.id, {
|
|
166
|
-
from,
|
|
167
|
-
to,
|
|
168
|
-
signal: context.runtime.signal
|
|
169
|
-
});
|
|
170
|
-
return {
|
|
171
|
-
command: "database.usage",
|
|
172
|
-
result: {
|
|
173
|
-
projectId: target.project.id,
|
|
174
|
-
projectName: target.project.name,
|
|
175
|
-
verboseContext: target,
|
|
176
|
-
database,
|
|
177
|
-
period: usage.period,
|
|
178
|
-
metrics: usage.metrics,
|
|
179
|
-
generatedAt: usage.generatedAt
|
|
180
|
-
},
|
|
181
|
-
warnings: [],
|
|
182
|
-
nextSteps: []
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
async function runDatabaseBackupList(context, databaseRef, flags) {
|
|
186
|
-
const limit = parseBackupLimit(flags.limit, resolvePrismaCliPackageCommandFormatterSync(context.runtime.cwd));
|
|
187
|
-
const { provider, target } = await requireDatabaseContext(context, flags, "database backup list");
|
|
188
|
-
const database = await resolveDatabase(provider, target, databaseRef, flags.branchName, context.runtime.signal);
|
|
189
|
-
const backups = await provider.listBackups(database.id, {
|
|
190
|
-
limit,
|
|
191
|
-
signal: context.runtime.signal
|
|
192
|
-
});
|
|
193
|
-
return {
|
|
194
|
-
command: "database.backup.list",
|
|
195
|
-
result: {
|
|
196
|
-
projectId: target.project.id,
|
|
197
|
-
projectName: target.project.name,
|
|
198
|
-
verboseContext: target,
|
|
199
|
-
database,
|
|
200
|
-
backups: backups.backups,
|
|
201
|
-
retentionDays: backups.retentionDays,
|
|
202
|
-
hasMore: backups.hasMore
|
|
203
|
-
},
|
|
204
|
-
warnings: [],
|
|
205
|
-
nextSteps: []
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
async function runDatabaseRestore(context, databaseRef, flags) {
|
|
209
|
-
const formatCommand = resolvePrismaCliPackageCommandFormatterSync(context.runtime.cwd);
|
|
210
|
-
const backupId = flags.backupId?.trim();
|
|
211
|
-
if (!backupId) throw usageError("Backup id required", "Database restore needs the backup to restore from.", `Pass --backup <backup-id> from ${formatCommand([
|
|
212
|
-
"database",
|
|
213
|
-
"backup",
|
|
214
|
-
"list",
|
|
215
|
-
"<database>"
|
|
216
|
-
])}.`, [formatCommand([
|
|
217
|
-
"database",
|
|
218
|
-
"backup",
|
|
219
|
-
"list",
|
|
220
|
-
"<database>"
|
|
221
|
-
])], "database");
|
|
222
|
-
const { provider, target } = await requireDatabaseContext(context, flags, "database restore");
|
|
223
|
-
const database = await resolveDatabase(provider, target, databaseRef, flags.branchName, context.runtime.signal);
|
|
224
|
-
const sourceDatabase = flags.sourceDatabaseRef ? await resolveDatabase(provider, target, flags.sourceDatabaseRef, flags.branchName, context.runtime.signal) : database;
|
|
225
|
-
const sourceDatabaseArg = sourceDatabase.id === database.id ? "" : ` --source-database ${sourceDatabase.id}`;
|
|
226
|
-
requireExactConfirmation({
|
|
227
|
-
resourceName: "database",
|
|
228
|
-
commandName: "database restore",
|
|
229
|
-
id: database.id,
|
|
230
|
-
confirm: flags.confirm,
|
|
231
|
-
summary: "Confirm database restore",
|
|
232
|
-
why: "Restoring immediately and irreversibly overwrites all data in the target database, so it requires the exact target database id.",
|
|
233
|
-
nextStep: `${formatCommand([
|
|
234
|
-
"database",
|
|
235
|
-
"restore",
|
|
236
|
-
database.id,
|
|
237
|
-
"--backup",
|
|
238
|
-
backupId
|
|
239
|
-
])}${sourceDatabaseArg} --confirm ${database.id}`
|
|
240
|
-
});
|
|
241
|
-
const restored = await provider.restoreDatabase({
|
|
242
|
-
targetDatabaseId: database.id,
|
|
243
|
-
sourceDatabaseId: sourceDatabase.id,
|
|
244
|
-
backupId,
|
|
245
|
-
projectId: target.project.id,
|
|
246
|
-
signal: context.runtime.signal
|
|
247
|
-
});
|
|
248
|
-
return {
|
|
249
|
-
command: "database.restore",
|
|
250
|
-
result: {
|
|
251
|
-
projectId: target.project.id,
|
|
252
|
-
projectName: target.project.name,
|
|
253
|
-
verboseContext: target,
|
|
254
|
-
database: ensureProjectId(restored, target.project.id),
|
|
255
|
-
source: {
|
|
256
|
-
databaseId: sourceDatabase.id,
|
|
257
|
-
backupId
|
|
258
|
-
}
|
|
259
|
-
},
|
|
260
|
-
warnings: [],
|
|
261
|
-
nextSteps: [formatCommand([
|
|
262
|
-
"database",
|
|
263
|
-
"show",
|
|
264
|
-
database.id
|
|
265
|
-
])]
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
async function runDatabaseConnectionRotate(context, connectionRef, flags) {
|
|
269
|
-
const formatCommand = resolvePrismaCliPackageCommandFormatterSync(context.runtime.cwd);
|
|
270
|
-
const connectionId = connectionRef.trim();
|
|
271
|
-
if (!connectionId) throw usageError("Connection id required", "Database connection rotation needs a connection id.", "Pass the connection id to rotate.", [formatCommand([
|
|
272
|
-
"database",
|
|
273
|
-
"connection",
|
|
274
|
-
"rotate",
|
|
275
|
-
"<connection-id>",
|
|
276
|
-
"--confirm",
|
|
277
|
-
"<connection-id>"
|
|
278
|
-
])], "database");
|
|
279
|
-
requireExactConfirmation({
|
|
280
|
-
resourceName: "database connection",
|
|
281
|
-
commandName: "database connection rotate",
|
|
282
|
-
id: connectionId,
|
|
283
|
-
confirm: flags.confirm,
|
|
284
|
-
summary: "Confirm database connection rotation",
|
|
285
|
-
why: "Rotating revokes the previous credentials and breaks clients still using them, so it requires the exact connection id.",
|
|
286
|
-
nextStep: formatCommand([
|
|
287
|
-
"database",
|
|
288
|
-
"connection",
|
|
289
|
-
"rotate",
|
|
290
|
-
connectionId,
|
|
291
|
-
"--confirm",
|
|
292
|
-
connectionId
|
|
293
|
-
])
|
|
294
|
-
});
|
|
295
|
-
const rotated = await (await requireDatabaseProviderOnly(context)).rotateConnection(connectionId, { signal: context.runtime.signal });
|
|
296
|
-
return {
|
|
297
|
-
command: "database.connection.rotate",
|
|
298
|
-
result: {
|
|
299
|
-
connection: rotated.connection,
|
|
300
|
-
database: rotated.database,
|
|
301
|
-
connectionString: rotated.connectionString
|
|
302
|
-
},
|
|
303
|
-
warnings: [],
|
|
304
|
-
nextSteps: []
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
const USAGE_DATE_ONLY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
308
|
-
const USAGE_DATETIME_PATTERN = /^\d{4}-\d{2}-\d{2}T/;
|
|
309
|
-
function parseUsageDate(value, flagName, dayBoundary, formatCommand) {
|
|
310
|
-
if (value === void 0) return;
|
|
311
|
-
const trimmed = value.trim();
|
|
312
|
-
if (USAGE_DATE_ONLY_PATTERN.test(trimmed) && isValidCalendarDate(trimmed)) return dayBoundary === "start" ? `${trimmed}T00:00:00.000Z` : `${trimmed}T23:59:59.999Z`;
|
|
313
|
-
if (USAGE_DATETIME_PATTERN.test(trimmed) && !Number.isNaN(Date.parse(trimmed)) && isValidCalendarDate(trimmed.slice(0, 10))) return trimmed;
|
|
314
|
-
throw usageError("Invalid usage period", `${flagName} must be an ISO date such as 2026-06-01 or an ISO datetime such as 2026-06-01T12:00:00Z.`, `Pass an ISO date or datetime to ${flagName}.`, [formatCommand([
|
|
315
|
-
"database",
|
|
316
|
-
"usage",
|
|
317
|
-
"<database>",
|
|
318
|
-
"--from",
|
|
319
|
-
"2026-06-01",
|
|
320
|
-
"--to",
|
|
321
|
-
"2026-06-30"
|
|
322
|
-
])], "database");
|
|
323
|
-
}
|
|
324
|
-
function isValidCalendarDate(datePart) {
|
|
325
|
-
const timestamp = Date.parse(`${datePart}T00:00:00.000Z`);
|
|
326
|
-
return !Number.isNaN(timestamp) && new Date(timestamp).toISOString().startsWith(datePart);
|
|
327
|
-
}
|
|
328
|
-
function parseBackupLimit(value, formatCommand) {
|
|
329
|
-
if (value === void 0) return;
|
|
330
|
-
const limit = Number(value.trim());
|
|
331
|
-
if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw usageError("Invalid backup limit", "--limit must be an integer between 1 and 100.", "Pass a --limit between 1 and 100.", [formatCommand([
|
|
332
|
-
"database",
|
|
333
|
-
"backup",
|
|
334
|
-
"list",
|
|
335
|
-
"<database>",
|
|
336
|
-
"--limit",
|
|
337
|
-
"50"
|
|
338
|
-
])], "database");
|
|
339
|
-
return limit;
|
|
340
|
-
}
|
|
341
|
-
async function requireDatabaseContext(context, flags, commandName) {
|
|
342
|
-
const workspace = (await requireAuthenticatedAuthState(context)).workspace;
|
|
343
|
-
if (!workspace) throw workspaceRequiredError();
|
|
344
|
-
const client = await authenticatedManagementApiClient(context.runtime.env, context.runtime.signal);
|
|
345
|
-
if (!client) throw authRequiredError();
|
|
346
|
-
{
|
|
347
|
-
const targetResult = await resolveProjectTarget({
|
|
348
|
-
context,
|
|
349
|
-
workspace,
|
|
350
|
-
explicitProject: flags.projectRef,
|
|
351
|
-
listProjects: () => listRealWorkspaceProjects(client, context.runtime.signal),
|
|
352
|
-
commandName
|
|
353
|
-
});
|
|
354
|
-
if (targetResult.isErr()) throw projectResolutionErrorToCliError(targetResult.error);
|
|
355
|
-
return {
|
|
356
|
-
provider: createManagementDatabaseProvider(client, {
|
|
357
|
-
formatCommand: resolvePrismaCliPackageCommandFormatterSync(context.runtime.cwd),
|
|
358
|
-
workspaceId: workspace.id
|
|
359
|
-
}),
|
|
360
|
-
target: targetResult.value
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
async function requireDatabaseProviderOnly(context) {
|
|
365
|
-
const authState = await requireAuthenticatedAuthState(context);
|
|
366
|
-
const client = await authenticatedManagementApiClient(context.runtime.env, context.runtime.signal);
|
|
367
|
-
if (!client) throw authRequiredError();
|
|
368
|
-
return createManagementDatabaseProvider(client, {
|
|
369
|
-
formatCommand: resolvePrismaCliPackageCommandFormatterSync(context.runtime.cwd),
|
|
370
|
-
workspaceId: authState.workspace?.id
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
async function resolveDatabase(provider, target, databaseRef, branchName, signal) {
|
|
374
|
-
const ref = databaseRef.trim();
|
|
375
|
-
if (!ref) throw usageError("Database id or name required", "This command needs a database id or name.", "Pass a database id or name.", ["prisma-cli database list"], "database");
|
|
376
|
-
const matches = (await provider.listDatabases({
|
|
377
|
-
projectId: target.project.id,
|
|
378
|
-
branchName,
|
|
379
|
-
signal
|
|
380
|
-
})).filter((database) => database.id === ref || database.name === ref);
|
|
381
|
-
if (matches.length === 0) throw databaseNotFoundError(ref, target.project.name, branchName);
|
|
382
|
-
if (matches.length > 1) throw databaseAmbiguousError(ref, matches, branchName);
|
|
383
|
-
const selected = matches[0];
|
|
384
|
-
const shown = await provider.showDatabase(selected.id, {
|
|
385
|
-
projectId: target.project.id,
|
|
386
|
-
signal
|
|
387
|
-
});
|
|
388
|
-
if (shown === null) throw databaseRemovedDuringResolutionError(selected, target.project.name);
|
|
389
|
-
return ensureProjectId(shown, target.project.id);
|
|
390
|
-
}
|
|
391
|
-
function databaseRemovedDuringResolutionError(database, projectName) {
|
|
392
|
-
return new CliError({
|
|
393
|
-
code: "DATABASE_NOT_FOUND",
|
|
394
|
-
domain: "database",
|
|
395
|
-
summary: "Database not found",
|
|
396
|
-
why: `"${database.name}" (${database.id}) was listed for project "${projectName}", but reading it returned 404. It was most likely removed while this command was running.`,
|
|
397
|
-
fix: "Re-run the command, or list the project's databases to see what is there now.",
|
|
398
|
-
exitCode: 1,
|
|
399
|
-
nextSteps: ["prisma-cli database list"]
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
function ensureProjectId(database, projectId) {
|
|
403
|
-
return database.projectId ? database : {
|
|
404
|
-
...database,
|
|
405
|
-
projectId
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
function sortDatabases(databases) {
|
|
409
|
-
return databases.slice().sort((left, right) => {
|
|
410
|
-
const branchOrder = (left.branchName ?? "").localeCompare(right.branchName ?? "");
|
|
411
|
-
if (branchOrder !== 0) return branchOrder;
|
|
412
|
-
const nameOrder = left.name.localeCompare(right.name);
|
|
413
|
-
return nameOrder !== 0 ? nameOrder : left.id.localeCompare(right.id);
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
function requireExactConfirmation(options) {
|
|
417
|
-
if (options.confirm === options.id) return;
|
|
418
|
-
throw new CliError({
|
|
419
|
-
code: "CONFIRMATION_REQUIRED",
|
|
420
|
-
domain: "database",
|
|
421
|
-
summary: options.summary ?? `Confirm ${options.resourceName} removal`,
|
|
422
|
-
why: options.why ?? `Removing this ${options.resourceName} is destructive and requires the exact id.`,
|
|
423
|
-
fix: `Rerun with --confirm ${options.id}.`,
|
|
424
|
-
exitCode: 2,
|
|
425
|
-
nextSteps: [options.nextStep ?? `prisma-cli ${options.commandName} ${options.id} --confirm ${options.id}`],
|
|
426
|
-
meta: {
|
|
427
|
-
expectedConfirm: options.id,
|
|
428
|
-
receivedConfirm: options.confirm ?? null
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
function defaultConnectionName() {
|
|
433
|
-
return `cli-${(/* @__PURE__ */ new Date()).toISOString().replace(/[-:.TZ]/g, "").slice(0, 17)}-${randomBytes(2).toString("hex")}`;
|
|
434
|
-
}
|
|
435
|
-
function databaseNotFoundError(databaseRef, projectName, branchName) {
|
|
436
|
-
return new CliError({
|
|
437
|
-
code: "DATABASE_NOT_FOUND",
|
|
438
|
-
domain: "database",
|
|
439
|
-
summary: "Database not found",
|
|
440
|
-
why: `No database matched "${databaseRef}"${projectName ? ` in project "${projectName}"${branchName ? ` on branch "${branchName}"` : ""}` : ""}.`,
|
|
441
|
-
fix: "Pass a database id or name from prisma-cli database list.",
|
|
442
|
-
exitCode: 1,
|
|
443
|
-
nextSteps: ["prisma-cli database list"]
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
function databaseAmbiguousError(databaseRef, matches, branchName) {
|
|
447
|
-
return new CliError({
|
|
448
|
-
code: "DATABASE_AMBIGUOUS",
|
|
449
|
-
domain: "database",
|
|
450
|
-
summary: "Database resolution is ambiguous",
|
|
451
|
-
why: branchName ? `Multiple databases matched "${databaseRef}" on branch "${branchName}".` : `Multiple databases matched "${databaseRef}".`,
|
|
452
|
-
fix: "Pass the database id, or pass --branch <git-name> to narrow the match.",
|
|
453
|
-
exitCode: 1,
|
|
454
|
-
nextSteps: ["prisma-cli database list"],
|
|
455
|
-
meta: { matches: matches.map((database) => ({
|
|
456
|
-
id: database.id,
|
|
457
|
-
name: database.name,
|
|
458
|
-
branchName: database.branchName
|
|
459
|
-
})) }
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
//#endregion
|
|
463
|
-
export { runDatabaseBackupList, runDatabaseConnectionCreate, runDatabaseConnectionList, runDatabaseConnectionRemove, runDatabaseConnectionRotate, runDatabaseCreate, runDatabaseList, runDatabaseRemove, runDatabaseRestore, runDatabaseShow, runDatabaseUsage };
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { CliError, usageError } from "../errors.js";
|
|
2
|
-
import { FEEDBACK_TIMEOUT_MS, unreachableDetail, unreadableBodyDetail } from "../lib/feedback.js";
|
|
3
|
-
import { getCliVersion } from "../lib/version.js";
|
|
4
|
-
//#region src/controllers/feedback.ts
|
|
5
|
-
const DEFAULT_FEEDBACK_ENDPOINT = "https://hiieirp2pwqnjvq9axzyg6d0.fra.prisma.build/feedback";
|
|
6
|
-
const MAX_MESSAGE_LENGTH = 4e3;
|
|
7
|
-
const MAX_EMAIL_LENGTH = 320;
|
|
8
|
-
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
9
|
-
async function runFeedback(context, messageArg, flags) {
|
|
10
|
-
const message = messageArg.trim();
|
|
11
|
-
if (!message) throw usageError("Feedback message required", "The message argument is empty.", "Pass a non-empty message.", ["prisma-cli feedback \"the deploy flow is great\""]);
|
|
12
|
-
if (message.length > MAX_MESSAGE_LENGTH) throw usageError("Feedback message too long", `The message is ${message.length} characters; the limit is ${MAX_MESSAGE_LENGTH}.`, "Shorten the message.");
|
|
13
|
-
const email = flags.email?.trim();
|
|
14
|
-
if (email !== void 0 && (email.length > MAX_EMAIL_LENGTH || !EMAIL_PATTERN.test(email))) throw usageError("Invalid email", `"${flags.email}" is not a valid email address of at most ${MAX_EMAIL_LENGTH} characters.`, "Pass a valid address with --email, or drop the flag to stay anonymous.", ["prisma-cli feedback \"please add X\" --email you@example.com"]);
|
|
15
|
-
const feedbackContext = {
|
|
16
|
-
cliVersion: getCliVersion(),
|
|
17
|
-
nodeVersion: process.version,
|
|
18
|
-
platform: process.platform,
|
|
19
|
-
arch: process.arch
|
|
20
|
-
};
|
|
21
|
-
return {
|
|
22
|
-
command: "feedback",
|
|
23
|
-
result: {
|
|
24
|
-
id: await postFeedback(context, context.runtime.env.PRISMA_CLI_FEEDBACK_URL || DEFAULT_FEEDBACK_ENDPOINT, {
|
|
25
|
-
message,
|
|
26
|
-
...email ? { email } : {},
|
|
27
|
-
meta: { ...feedbackContext }
|
|
28
|
-
}),
|
|
29
|
-
email: email ?? null,
|
|
30
|
-
context: feedbackContext
|
|
31
|
-
},
|
|
32
|
-
warnings: [],
|
|
33
|
-
nextSteps: []
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
async function postFeedback(context, endpoint, body) {
|
|
37
|
-
const response = await sendFeedback(context, endpoint, body);
|
|
38
|
-
if (!response.ok) throw feedbackSendFailed(`The feedback service responded with HTTP ${response.status}${await readServiceError(context, response)}.`);
|
|
39
|
-
return readSubmissionId(context, response);
|
|
40
|
-
}
|
|
41
|
-
async function sendFeedback(context, endpoint, body) {
|
|
42
|
-
try {
|
|
43
|
-
return await fetch(endpoint, {
|
|
44
|
-
method: "POST",
|
|
45
|
-
headers: {
|
|
46
|
-
"content-type": "application/json",
|
|
47
|
-
"user-agent": `prisma-cli/${getCliVersion()}`
|
|
48
|
-
},
|
|
49
|
-
body: JSON.stringify(body),
|
|
50
|
-
signal: AbortSignal.any([context.runtime.signal, AbortSignal.timeout(FEEDBACK_TIMEOUT_MS)])
|
|
51
|
-
});
|
|
52
|
-
} catch (error) {
|
|
53
|
-
if (context.runtime.signal.aborted) throw error;
|
|
54
|
-
throw feedbackSendFailed(unreachableDetail(error));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async function readSubmissionId(context, response) {
|
|
58
|
-
let payload;
|
|
59
|
-
try {
|
|
60
|
-
payload = await response.json();
|
|
61
|
-
} catch (error) {
|
|
62
|
-
if (context.runtime.signal.aborted) throw error;
|
|
63
|
-
if (!(error instanceof SyntaxError)) throw feedbackSendFailed(unreadableBodyDetail(error));
|
|
64
|
-
payload = null;
|
|
65
|
-
}
|
|
66
|
-
return typeof payload?.id === "string" ? payload.id : null;
|
|
67
|
-
}
|
|
68
|
-
async function readServiceError(context, response) {
|
|
69
|
-
let payload;
|
|
70
|
-
try {
|
|
71
|
-
payload = await response.json();
|
|
72
|
-
} catch (error) {
|
|
73
|
-
if (context.runtime.signal.aborted) throw error;
|
|
74
|
-
return "";
|
|
75
|
-
}
|
|
76
|
-
return typeof payload?.error?.message === "string" ? ` (${payload.error.message})` : "";
|
|
77
|
-
}
|
|
78
|
-
function feedbackSendFailed(detail) {
|
|
79
|
-
return new CliError({
|
|
80
|
-
code: "FEEDBACK_SEND_FAILED",
|
|
81
|
-
domain: "cli",
|
|
82
|
-
summary: "Feedback could not be delivered",
|
|
83
|
-
why: detail,
|
|
84
|
-
fix: "Check your network and rerun the command.",
|
|
85
|
-
exitCode: 1,
|
|
86
|
-
nextSteps: []
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
//#endregion
|
|
90
|
-
export { runFeedback };
|