@prisma-next/cli 0.1.0-dev.15 → 0.1.0-dev.17
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 +151 -0
- package/dist/{chunk-4Q3MO4TK.js → chunk-4W62XWA4.js} +2 -2
- package/dist/{chunk-3EODSNGS.js → chunk-JLA4BH74.js} +93 -32
- package/dist/chunk-JLA4BH74.js.map +1 -0
- package/dist/cli.js +323 -66
- package/dist/cli.js.map +1 -1
- package/dist/commands/contract-emit.js +2 -2
- package/dist/commands/db-init.d.ts +5 -0
- package/dist/commands/db-init.js +230 -0
- package/dist/commands/db-init.js.map +1 -0
- package/dist/commands/db-introspect.js +1 -1
- package/dist/commands/db-schema-verify.js +1 -1
- package/dist/commands/db-sign.js +1 -1
- package/dist/commands/db-verify.js +1 -1
- package/dist/index.js +4 -4
- package/package.json +15 -10
- package/dist/chunk-3EODSNGS.js.map +0 -1
- /package/dist/{chunk-4Q3MO4TK.js.map → chunk-4W62XWA4.js.map} +0 -0
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
|
-
import { Command as
|
|
4
|
+
import { Command as Command7 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/commands/contract-emit.ts
|
|
7
7
|
import { mkdirSync, writeFileSync } from "fs";
|
|
@@ -165,6 +165,15 @@ function formatErrorOutput(error, flags) {
|
|
|
165
165
|
const whereLine = error.where.line ? `${error.where.path}:${error.where.line}` : error.where.path;
|
|
166
166
|
lines.push(`${prefix}${formatDimText(` Where: ${whereLine}`)}`);
|
|
167
167
|
}
|
|
168
|
+
if (isVerbose(flags, 1) && error.meta?.["conflicts"]) {
|
|
169
|
+
const conflicts = error.meta["conflicts"];
|
|
170
|
+
if (conflicts.length > 0) {
|
|
171
|
+
lines.push(`${prefix}${formatDimText(" Conflicts:")}`);
|
|
172
|
+
for (const conflict of conflicts) {
|
|
173
|
+
lines.push(`${prefix}${formatDimText(` - [${conflict.kind}] ${conflict.summary}`)}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
168
177
|
if (error.docsUrl && isVerbose(flags, 1)) {
|
|
169
178
|
lines.push(formatDimText(error.docsUrl));
|
|
170
179
|
}
|
|
@@ -598,6 +607,69 @@ function formatSignOutput(result, flags) {
|
|
|
598
607
|
function formatSignJson(result) {
|
|
599
608
|
return JSON.stringify(result, null, 2);
|
|
600
609
|
}
|
|
610
|
+
function formatDbInitPlanOutput(result, flags) {
|
|
611
|
+
if (flags.quiet) {
|
|
612
|
+
return "";
|
|
613
|
+
}
|
|
614
|
+
const lines = [];
|
|
615
|
+
const prefix = createPrefix(flags);
|
|
616
|
+
const useColor = flags.color !== false;
|
|
617
|
+
const formatGreen = createColorFormatter(useColor, green);
|
|
618
|
+
const formatDimText = (text) => formatDim(useColor, text);
|
|
619
|
+
const operationCount = result.plan?.operations.length ?? 0;
|
|
620
|
+
lines.push(`${prefix}${formatGreen("\u2714")} Planned ${operationCount} operation(s)`);
|
|
621
|
+
if (result.plan?.operations && result.plan.operations.length > 0) {
|
|
622
|
+
lines.push(`${prefix}${formatDimText("\u2502")}`);
|
|
623
|
+
for (let i = 0; i < result.plan.operations.length; i++) {
|
|
624
|
+
const op = result.plan.operations[i];
|
|
625
|
+
if (!op) continue;
|
|
626
|
+
const isLast = i === result.plan.operations.length - 1;
|
|
627
|
+
const treeChar = isLast ? "\u2514" : "\u251C";
|
|
628
|
+
const opClass = formatDimText(`[${op.operationClass}]`);
|
|
629
|
+
lines.push(`${prefix}${formatDimText(treeChar)}\u2500 ${op.label} ${opClass}`);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
if (result.plan?.destination) {
|
|
633
|
+
lines.push(`${prefix}`);
|
|
634
|
+
lines.push(
|
|
635
|
+
`${prefix}${formatDimText(`Destination hash: ${result.plan.destination.coreHash}`)}`
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
if (isVerbose(flags, 1)) {
|
|
639
|
+
lines.push(`${prefix}${formatDimText(`Total time: ${result.timings.total}ms`)}`);
|
|
640
|
+
}
|
|
641
|
+
lines.push(`${prefix}`);
|
|
642
|
+
lines.push(`${prefix}${formatDimText("This is a dry run. No changes were applied.")}`);
|
|
643
|
+
lines.push(`${prefix}${formatDimText("Run without --plan to apply changes.")}`);
|
|
644
|
+
return lines.join("\n");
|
|
645
|
+
}
|
|
646
|
+
function formatDbInitApplyOutput(result, flags) {
|
|
647
|
+
if (flags.quiet) {
|
|
648
|
+
return "";
|
|
649
|
+
}
|
|
650
|
+
const lines = [];
|
|
651
|
+
const prefix = createPrefix(flags);
|
|
652
|
+
const useColor = flags.color !== false;
|
|
653
|
+
const formatGreen = createColorFormatter(useColor, green);
|
|
654
|
+
const formatDimText = (text) => formatDim(useColor, text);
|
|
655
|
+
if (result.ok) {
|
|
656
|
+
const executed = result.execution?.operationsExecuted ?? 0;
|
|
657
|
+
lines.push(`${prefix}${formatGreen("\u2714")} Applied ${executed} operation(s)`);
|
|
658
|
+
if (result.marker) {
|
|
659
|
+
lines.push(`${prefix}${formatDimText(` Marker written: ${result.marker.coreHash}`)}`);
|
|
660
|
+
if (result.marker.profileHash) {
|
|
661
|
+
lines.push(`${prefix}${formatDimText(` Profile hash: ${result.marker.profileHash}`)}`);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
if (isVerbose(flags, 1)) {
|
|
665
|
+
lines.push(`${prefix}${formatDimText(` Total time: ${result.timings.total}ms`)}`);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return lines.join("\n");
|
|
669
|
+
}
|
|
670
|
+
function formatDbInitJson(result) {
|
|
671
|
+
return JSON.stringify(result, null, 2);
|
|
672
|
+
}
|
|
601
673
|
var LEFT_COLUMN_WIDTH = 20;
|
|
602
674
|
var RIGHT_COLUMN_MIN_WIDTH = 40;
|
|
603
675
|
var RIGHT_COLUMN_MAX_WIDTH = 90;
|
|
@@ -921,8 +993,10 @@ import {
|
|
|
921
993
|
errorFileNotFound,
|
|
922
994
|
errorHashMismatch,
|
|
923
995
|
errorMarkerMissing,
|
|
996
|
+
errorMigrationPlanningFailed,
|
|
924
997
|
errorQueryRunnerFactoryRequired,
|
|
925
998
|
errorRuntime,
|
|
999
|
+
errorTargetMigrationNotSupported,
|
|
926
1000
|
errorTargetMismatch,
|
|
927
1001
|
errorUnexpected as errorUnexpected2
|
|
928
1002
|
} from "@prisma-next/core-control-plane/errors";
|
|
@@ -967,46 +1041,23 @@ function handleResult(result, flags, onSuccess) {
|
|
|
967
1041
|
// src/utils/spinner.ts
|
|
968
1042
|
import ora from "ora";
|
|
969
1043
|
async function withSpinner(operation, options) {
|
|
970
|
-
const { message, flags
|
|
1044
|
+
const { message, flags } = options;
|
|
971
1045
|
const shouldShowSpinner = !flags.quiet && flags.json !== "object" && process.stdout.isTTY;
|
|
972
1046
|
if (!shouldShowSpinner) {
|
|
973
1047
|
return operation();
|
|
974
1048
|
}
|
|
975
1049
|
const startTime = Date.now();
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
if (!operationCompleted) {
|
|
981
|
-
spinner = ora({
|
|
982
|
-
text: message,
|
|
983
|
-
color: flags.color !== false ? "cyan" : false
|
|
984
|
-
}).start();
|
|
985
|
-
}
|
|
986
|
-
}, delayThreshold);
|
|
1050
|
+
const spinner = ora({
|
|
1051
|
+
text: message,
|
|
1052
|
+
color: flags.color !== false ? "cyan" : false
|
|
1053
|
+
}).start();
|
|
987
1054
|
try {
|
|
988
1055
|
const result = await operation();
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
clearTimeout(timeoutId);
|
|
992
|
-
timeoutId = null;
|
|
993
|
-
}
|
|
994
|
-
if (spinner !== null) {
|
|
995
|
-
const elapsed = Date.now() - startTime;
|
|
996
|
-
spinner.succeed(`${message} (${elapsed}ms)`);
|
|
997
|
-
}
|
|
1056
|
+
const elapsed = Date.now() - startTime;
|
|
1057
|
+
spinner.succeed(`${message} (${elapsed}ms)`);
|
|
998
1058
|
return result;
|
|
999
1059
|
} catch (error) {
|
|
1000
|
-
|
|
1001
|
-
if (timeoutId) {
|
|
1002
|
-
clearTimeout(timeoutId);
|
|
1003
|
-
timeoutId = null;
|
|
1004
|
-
}
|
|
1005
|
-
if (spinner !== null) {
|
|
1006
|
-
spinner.fail(
|
|
1007
|
-
`${message} failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1008
|
-
);
|
|
1009
|
-
}
|
|
1060
|
+
spinner.fail(`${message} failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1010
1061
|
throw error;
|
|
1011
1062
|
}
|
|
1012
1063
|
}
|
|
@@ -1121,18 +1172,222 @@ function createContractEmitCommand() {
|
|
|
1121
1172
|
return command;
|
|
1122
1173
|
}
|
|
1123
1174
|
|
|
1124
|
-
// src/commands/db-
|
|
1175
|
+
// src/commands/db-init.ts
|
|
1125
1176
|
import { readFile } from "fs/promises";
|
|
1126
1177
|
import { relative as relative3, resolve as resolve3 } from "path";
|
|
1178
|
+
import { Command as Command2 } from "commander";
|
|
1179
|
+
function createDbInitCommand() {
|
|
1180
|
+
const command = new Command2("init");
|
|
1181
|
+
setCommandDescriptions(
|
|
1182
|
+
command,
|
|
1183
|
+
"Bootstrap a database to match the current contract and write the contract marker",
|
|
1184
|
+
"Initializes a database to match your emitted contract using additive-only operations.\nCreates tables, columns, indexes, and constraints defined in your contract.\nWrites a contract marker to track the database state. This operation is idempotent.\n\nCurrently supports empty databases only. Use --plan to preview changes without applying."
|
|
1185
|
+
);
|
|
1186
|
+
command.configureHelp({
|
|
1187
|
+
formatHelp: (cmd) => {
|
|
1188
|
+
const flags = parseGlobalFlags({});
|
|
1189
|
+
return formatCommandHelp({ command: cmd, flags });
|
|
1190
|
+
}
|
|
1191
|
+
}).option("--db <url>", "Database connection string").option("--config <path>", "Path to prisma-next.config.ts").option("--plan", "Preview planned operations without applying", false).option("--json [format]", "Output as JSON (object or ndjson)", false).option("-q, --quiet", "Quiet mode: errors only").option("-v, --verbose", "Verbose output: debug info, timings").option("-vv, --trace", "Trace output: deep internals, stack traces").option("--timestamps", "Add timestamps to output").option("--color", "Force color output").option("--no-color", "Disable color output").action(async (options) => {
|
|
1192
|
+
const flags = parseGlobalFlags(options);
|
|
1193
|
+
const startTime = Date.now();
|
|
1194
|
+
const result = await performAction(async () => {
|
|
1195
|
+
const config = await loadConfig(options.config);
|
|
1196
|
+
const configPath = options.config ? relative3(process.cwd(), resolve3(options.config)) : "prisma-next.config.ts";
|
|
1197
|
+
const contractPathAbsolute = config.contract?.output ? resolve3(config.contract.output) : resolve3("src/prisma/contract.json");
|
|
1198
|
+
const contractPath = relative3(process.cwd(), contractPathAbsolute);
|
|
1199
|
+
if (flags.json !== "object" && !flags.quiet) {
|
|
1200
|
+
const details = [
|
|
1201
|
+
{ label: "config", value: configPath },
|
|
1202
|
+
{ label: "contract", value: contractPath }
|
|
1203
|
+
];
|
|
1204
|
+
if (options.db) {
|
|
1205
|
+
details.push({ label: "database", value: options.db });
|
|
1206
|
+
}
|
|
1207
|
+
if (options.plan) {
|
|
1208
|
+
details.push({ label: "mode", value: "plan (dry run)" });
|
|
1209
|
+
}
|
|
1210
|
+
const header = formatStyledHeader({
|
|
1211
|
+
command: "db init",
|
|
1212
|
+
description: "Bootstrap a database to match the current contract",
|
|
1213
|
+
url: "https://pris.ly/db-init",
|
|
1214
|
+
details,
|
|
1215
|
+
flags
|
|
1216
|
+
});
|
|
1217
|
+
console.log(header);
|
|
1218
|
+
}
|
|
1219
|
+
let contractJsonContent;
|
|
1220
|
+
try {
|
|
1221
|
+
contractJsonContent = await readFile(contractPathAbsolute, "utf-8");
|
|
1222
|
+
} catch (error) {
|
|
1223
|
+
if (error instanceof Error && error.code === "ENOENT") {
|
|
1224
|
+
throw errorFileNotFound(contractPathAbsolute, {
|
|
1225
|
+
why: `Contract file not found at ${contractPathAbsolute}`
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
throw errorUnexpected2(error instanceof Error ? error.message : String(error), {
|
|
1229
|
+
why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
let contractJson;
|
|
1233
|
+
try {
|
|
1234
|
+
contractJson = JSON.parse(contractJsonContent);
|
|
1235
|
+
} catch (error) {
|
|
1236
|
+
throw errorUnexpected2(error instanceof Error ? error.message : String(error), {
|
|
1237
|
+
why: `Failed to parse contract JSON at ${contractPathAbsolute}: ${error instanceof Error ? error.message : String(error)}`
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
const dbUrl = options.db ?? config.db?.url;
|
|
1241
|
+
if (!dbUrl) {
|
|
1242
|
+
throw errorDatabaseUrlRequired({ why: "Database URL is required for db init" });
|
|
1243
|
+
}
|
|
1244
|
+
if (!config.driver) {
|
|
1245
|
+
throw errorDriverRequired({ why: "Config.driver is required for db init" });
|
|
1246
|
+
}
|
|
1247
|
+
const driverDescriptor = config.driver;
|
|
1248
|
+
if (!config.target.migrations) {
|
|
1249
|
+
throw errorTargetMigrationNotSupported({
|
|
1250
|
+
why: `Target "${config.target.id}" does not support migrations`
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
const migrations = config.target.migrations;
|
|
1254
|
+
const driver = await withSpinner(() => driverDescriptor.create(dbUrl), {
|
|
1255
|
+
message: "Connecting to database...",
|
|
1256
|
+
flags
|
|
1257
|
+
});
|
|
1258
|
+
try {
|
|
1259
|
+
const familyInstance = config.family.create({
|
|
1260
|
+
target: config.target,
|
|
1261
|
+
adapter: config.adapter,
|
|
1262
|
+
driver: driverDescriptor,
|
|
1263
|
+
extensions: config.extensions ?? []
|
|
1264
|
+
});
|
|
1265
|
+
const typedFamilyInstance = familyInstance;
|
|
1266
|
+
const contractIR = typedFamilyInstance.validateContractIR(contractJson);
|
|
1267
|
+
const planner = migrations.createPlanner(familyInstance);
|
|
1268
|
+
const runner = migrations.createRunner(familyInstance);
|
|
1269
|
+
const schemaIR = await withSpinner(() => typedFamilyInstance.introspect({ driver }), {
|
|
1270
|
+
message: "Introspecting database schema...",
|
|
1271
|
+
flags
|
|
1272
|
+
});
|
|
1273
|
+
const policy = { allowedOperationClasses: ["additive"] };
|
|
1274
|
+
const plannerResult = await withSpinner(
|
|
1275
|
+
async () => planner.plan({
|
|
1276
|
+
contract: contractIR,
|
|
1277
|
+
schema: schemaIR,
|
|
1278
|
+
policy
|
|
1279
|
+
}),
|
|
1280
|
+
{
|
|
1281
|
+
message: "Planning migration...",
|
|
1282
|
+
flags
|
|
1283
|
+
}
|
|
1284
|
+
);
|
|
1285
|
+
if (plannerResult.kind === "failure") {
|
|
1286
|
+
throw errorMigrationPlanningFailed({ conflicts: plannerResult.conflicts });
|
|
1287
|
+
}
|
|
1288
|
+
const migrationPlan = plannerResult.plan;
|
|
1289
|
+
if (options.plan) {
|
|
1290
|
+
const dbInitResult2 = {
|
|
1291
|
+
ok: true,
|
|
1292
|
+
mode: "plan",
|
|
1293
|
+
plan: {
|
|
1294
|
+
targetId: migrationPlan.targetId,
|
|
1295
|
+
destination: migrationPlan.destination,
|
|
1296
|
+
operations: migrationPlan.operations.map((op) => ({
|
|
1297
|
+
id: op.id,
|
|
1298
|
+
label: op.label,
|
|
1299
|
+
operationClass: op.operationClass
|
|
1300
|
+
}))
|
|
1301
|
+
},
|
|
1302
|
+
summary: `Planned ${migrationPlan.operations.length} operation(s)`,
|
|
1303
|
+
timings: { total: Date.now() - startTime }
|
|
1304
|
+
};
|
|
1305
|
+
return dbInitResult2;
|
|
1306
|
+
}
|
|
1307
|
+
const callbacks = {
|
|
1308
|
+
onOperationStart: (op) => {
|
|
1309
|
+
if (!flags.quiet && flags.json !== "object") {
|
|
1310
|
+
console.log(` \u2192 ${op.label}...`);
|
|
1311
|
+
}
|
|
1312
|
+
},
|
|
1313
|
+
onOperationComplete: (_op) => {
|
|
1314
|
+
}
|
|
1315
|
+
};
|
|
1316
|
+
const runnerResult = await withSpinner(
|
|
1317
|
+
() => runner.execute({
|
|
1318
|
+
plan: migrationPlan,
|
|
1319
|
+
driver,
|
|
1320
|
+
destinationContract: contractIR,
|
|
1321
|
+
policy,
|
|
1322
|
+
callbacks
|
|
1323
|
+
}),
|
|
1324
|
+
{
|
|
1325
|
+
message: "Applying migration plan...",
|
|
1326
|
+
flags
|
|
1327
|
+
}
|
|
1328
|
+
);
|
|
1329
|
+
if (!runnerResult.ok) {
|
|
1330
|
+
throw errorRuntime(runnerResult.failure.summary, {
|
|
1331
|
+
why: runnerResult.failure.why ?? `Migration runner failed: ${runnerResult.failure.code}`,
|
|
1332
|
+
meta: { code: runnerResult.failure.code }
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
const execution = runnerResult.value;
|
|
1336
|
+
const dbInitResult = {
|
|
1337
|
+
ok: true,
|
|
1338
|
+
mode: "apply",
|
|
1339
|
+
plan: {
|
|
1340
|
+
targetId: migrationPlan.targetId,
|
|
1341
|
+
destination: migrationPlan.destination,
|
|
1342
|
+
operations: migrationPlan.operations.map((op) => ({
|
|
1343
|
+
id: op.id,
|
|
1344
|
+
label: op.label,
|
|
1345
|
+
operationClass: op.operationClass
|
|
1346
|
+
}))
|
|
1347
|
+
},
|
|
1348
|
+
execution: {
|
|
1349
|
+
operationsPlanned: execution.operationsPlanned,
|
|
1350
|
+
operationsExecuted: execution.operationsExecuted
|
|
1351
|
+
},
|
|
1352
|
+
marker: migrationPlan.destination.profileHash ? {
|
|
1353
|
+
coreHash: migrationPlan.destination.coreHash,
|
|
1354
|
+
profileHash: migrationPlan.destination.profileHash
|
|
1355
|
+
} : { coreHash: migrationPlan.destination.coreHash },
|
|
1356
|
+
summary: `Applied ${execution.operationsExecuted} operation(s), marker written`,
|
|
1357
|
+
timings: { total: Date.now() - startTime }
|
|
1358
|
+
};
|
|
1359
|
+
return dbInitResult;
|
|
1360
|
+
} finally {
|
|
1361
|
+
await driver.close();
|
|
1362
|
+
}
|
|
1363
|
+
});
|
|
1364
|
+
const exitCode = handleResult(result, flags, (dbInitResult) => {
|
|
1365
|
+
if (flags.json === "object") {
|
|
1366
|
+
console.log(formatDbInitJson(dbInitResult));
|
|
1367
|
+
} else {
|
|
1368
|
+
const output = dbInitResult.mode === "plan" ? formatDbInitPlanOutput(dbInitResult, flags) : formatDbInitApplyOutput(dbInitResult, flags);
|
|
1369
|
+
if (output) {
|
|
1370
|
+
console.log(output);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
process.exit(exitCode);
|
|
1375
|
+
});
|
|
1376
|
+
return command;
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
// src/commands/db-introspect.ts
|
|
1380
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
1381
|
+
import { relative as relative4, resolve as resolve4 } from "path";
|
|
1127
1382
|
import {
|
|
1128
1383
|
errorDatabaseUrlRequired as errorDatabaseUrlRequired2,
|
|
1129
1384
|
errorDriverRequired as errorDriverRequired2,
|
|
1130
1385
|
errorRuntime as errorRuntime2,
|
|
1131
1386
|
errorUnexpected as errorUnexpected3
|
|
1132
1387
|
} from "@prisma-next/core-control-plane/errors";
|
|
1133
|
-
import { Command as
|
|
1388
|
+
import { Command as Command3 } from "commander";
|
|
1134
1389
|
function createDbIntrospectCommand() {
|
|
1135
|
-
const command = new
|
|
1390
|
+
const command = new Command3("introspect");
|
|
1136
1391
|
setCommandDescriptions(
|
|
1137
1392
|
command,
|
|
1138
1393
|
"Inspect the database schema",
|
|
@@ -1148,12 +1403,12 @@ function createDbIntrospectCommand() {
|
|
|
1148
1403
|
const result = await performAction(async () => {
|
|
1149
1404
|
const startTime = Date.now();
|
|
1150
1405
|
const config = await loadConfig(options.config);
|
|
1151
|
-
const configPath = options.config ?
|
|
1406
|
+
const configPath = options.config ? relative4(process.cwd(), resolve4(options.config)) : "prisma-next.config.ts";
|
|
1152
1407
|
let contractIR;
|
|
1153
1408
|
if (config.contract?.output) {
|
|
1154
|
-
const contractPath =
|
|
1409
|
+
const contractPath = resolve4(config.contract.output);
|
|
1155
1410
|
try {
|
|
1156
|
-
const contractJsonContent = await
|
|
1411
|
+
const contractJsonContent = await readFile2(contractPath, "utf-8");
|
|
1157
1412
|
const contractJson = JSON.parse(contractJsonContent);
|
|
1158
1413
|
contractIR = contractJson;
|
|
1159
1414
|
} catch (error) {
|
|
@@ -1285,8 +1540,8 @@ function createDbIntrospectCommand() {
|
|
|
1285
1540
|
}
|
|
1286
1541
|
|
|
1287
1542
|
// src/commands/db-schema-verify.ts
|
|
1288
|
-
import { readFile as
|
|
1289
|
-
import { relative as
|
|
1543
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
1544
|
+
import { relative as relative5, resolve as resolve5 } from "path";
|
|
1290
1545
|
import {
|
|
1291
1546
|
errorDatabaseUrlRequired as errorDatabaseUrlRequired3,
|
|
1292
1547
|
errorDriverRequired as errorDriverRequired3,
|
|
@@ -1294,9 +1549,9 @@ import {
|
|
|
1294
1549
|
errorRuntime as errorRuntime3,
|
|
1295
1550
|
errorUnexpected as errorUnexpected4
|
|
1296
1551
|
} from "@prisma-next/core-control-plane/errors";
|
|
1297
|
-
import { Command as
|
|
1552
|
+
import { Command as Command4 } from "commander";
|
|
1298
1553
|
function createDbSchemaVerifyCommand() {
|
|
1299
|
-
const command = new
|
|
1554
|
+
const command = new Command4("schema-verify");
|
|
1300
1555
|
setCommandDescriptions(
|
|
1301
1556
|
command,
|
|
1302
1557
|
"Check whether the database schema satisfies your contract",
|
|
@@ -1311,9 +1566,9 @@ function createDbSchemaVerifyCommand() {
|
|
|
1311
1566
|
const flags = parseGlobalFlags(options);
|
|
1312
1567
|
const result = await performAction(async () => {
|
|
1313
1568
|
const config = await loadConfig(options.config);
|
|
1314
|
-
const configPath = options.config ?
|
|
1315
|
-
const contractPathAbsolute = config.contract?.output ?
|
|
1316
|
-
const contractPath =
|
|
1569
|
+
const configPath = options.config ? relative5(process.cwd(), resolve5(options.config)) : "prisma-next.config.ts";
|
|
1570
|
+
const contractPathAbsolute = config.contract?.output ? resolve5(config.contract.output) : resolve5("src/prisma/contract.json");
|
|
1571
|
+
const contractPath = relative5(process.cwd(), contractPathAbsolute);
|
|
1317
1572
|
if (flags.json !== "object" && !flags.quiet) {
|
|
1318
1573
|
const details = [
|
|
1319
1574
|
{ label: "config", value: configPath },
|
|
@@ -1333,7 +1588,7 @@ function createDbSchemaVerifyCommand() {
|
|
|
1333
1588
|
}
|
|
1334
1589
|
let contractJsonContent;
|
|
1335
1590
|
try {
|
|
1336
|
-
contractJsonContent = await
|
|
1591
|
+
contractJsonContent = await readFile3(contractPathAbsolute, "utf-8");
|
|
1337
1592
|
} catch (error) {
|
|
1338
1593
|
if (error instanceof Error && error.code === "ENOENT") {
|
|
1339
1594
|
throw errorFileNotFound2(contractPathAbsolute, {
|
|
@@ -1414,8 +1669,8 @@ function createDbSchemaVerifyCommand() {
|
|
|
1414
1669
|
}
|
|
1415
1670
|
|
|
1416
1671
|
// src/commands/db-sign.ts
|
|
1417
|
-
import { readFile as
|
|
1418
|
-
import { relative as
|
|
1672
|
+
import { readFile as readFile4 } from "fs/promises";
|
|
1673
|
+
import { relative as relative6, resolve as resolve6 } from "path";
|
|
1419
1674
|
import {
|
|
1420
1675
|
errorDatabaseUrlRequired as errorDatabaseUrlRequired4,
|
|
1421
1676
|
errorDriverRequired as errorDriverRequired4,
|
|
@@ -1423,9 +1678,9 @@ import {
|
|
|
1423
1678
|
errorRuntime as errorRuntime4,
|
|
1424
1679
|
errorUnexpected as errorUnexpected5
|
|
1425
1680
|
} from "@prisma-next/core-control-plane/errors";
|
|
1426
|
-
import { Command as
|
|
1681
|
+
import { Command as Command5 } from "commander";
|
|
1427
1682
|
function createDbSignCommand() {
|
|
1428
|
-
const command = new
|
|
1683
|
+
const command = new Command5("sign");
|
|
1429
1684
|
setCommandDescriptions(
|
|
1430
1685
|
command,
|
|
1431
1686
|
"Sign the database with your contract so you can safely run queries",
|
|
@@ -1440,9 +1695,9 @@ function createDbSignCommand() {
|
|
|
1440
1695
|
const flags = parseGlobalFlags(options);
|
|
1441
1696
|
const result = await performAction(async () => {
|
|
1442
1697
|
const config = await loadConfig(options.config);
|
|
1443
|
-
const configPath = options.config ?
|
|
1444
|
-
const contractPathAbsolute = config.contract?.output ?
|
|
1445
|
-
const contractPath =
|
|
1698
|
+
const configPath = options.config ? relative6(process.cwd(), resolve6(options.config)) : "prisma-next.config.ts";
|
|
1699
|
+
const contractPathAbsolute = config.contract?.output ? resolve6(config.contract.output) : resolve6("src/prisma/contract.json");
|
|
1700
|
+
const contractPath = relative6(process.cwd(), contractPathAbsolute);
|
|
1446
1701
|
if (flags.json !== "object" && !flags.quiet) {
|
|
1447
1702
|
const details = [
|
|
1448
1703
|
{ label: "config", value: configPath },
|
|
@@ -1462,7 +1717,7 @@ function createDbSignCommand() {
|
|
|
1462
1717
|
}
|
|
1463
1718
|
let contractJsonContent;
|
|
1464
1719
|
try {
|
|
1465
|
-
contractJsonContent = await
|
|
1720
|
+
contractJsonContent = await readFile4(contractPathAbsolute, "utf-8");
|
|
1466
1721
|
} catch (error) {
|
|
1467
1722
|
if (error instanceof Error && error.code === "ENOENT") {
|
|
1468
1723
|
throw errorFileNotFound3(contractPathAbsolute, {
|
|
@@ -1580,8 +1835,8 @@ function createDbSignCommand() {
|
|
|
1580
1835
|
}
|
|
1581
1836
|
|
|
1582
1837
|
// src/commands/db-verify.ts
|
|
1583
|
-
import { readFile as
|
|
1584
|
-
import { relative as
|
|
1838
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
1839
|
+
import { relative as relative7, resolve as resolve7 } from "path";
|
|
1585
1840
|
import {
|
|
1586
1841
|
errorDatabaseUrlRequired as errorDatabaseUrlRequired5,
|
|
1587
1842
|
errorDriverRequired as errorDriverRequired5,
|
|
@@ -1592,9 +1847,9 @@ import {
|
|
|
1592
1847
|
errorTargetMismatch as errorTargetMismatch2,
|
|
1593
1848
|
errorUnexpected as errorUnexpected6
|
|
1594
1849
|
} from "@prisma-next/core-control-plane/errors";
|
|
1595
|
-
import { Command as
|
|
1850
|
+
import { Command as Command6 } from "commander";
|
|
1596
1851
|
function createDbVerifyCommand() {
|
|
1597
|
-
const command = new
|
|
1852
|
+
const command = new Command6("verify");
|
|
1598
1853
|
setCommandDescriptions(
|
|
1599
1854
|
command,
|
|
1600
1855
|
"Check whether the database has been signed with your contract",
|
|
@@ -1609,9 +1864,9 @@ function createDbVerifyCommand() {
|
|
|
1609
1864
|
const flags = parseGlobalFlags(options);
|
|
1610
1865
|
const result = await performAction(async () => {
|
|
1611
1866
|
const config = await loadConfig(options.config);
|
|
1612
|
-
const configPath = options.config ?
|
|
1613
|
-
const contractPathAbsolute = config.contract?.output ?
|
|
1614
|
-
const contractPath =
|
|
1867
|
+
const configPath = options.config ? relative7(process.cwd(), resolve7(options.config)) : "prisma-next.config.ts";
|
|
1868
|
+
const contractPathAbsolute = config.contract?.output ? resolve7(config.contract.output) : resolve7("src/prisma/contract.json");
|
|
1869
|
+
const contractPath = relative7(process.cwd(), contractPathAbsolute);
|
|
1615
1870
|
if (flags.json !== "object" && !flags.quiet) {
|
|
1616
1871
|
const details = [
|
|
1617
1872
|
{ label: "config", value: configPath },
|
|
@@ -1631,7 +1886,7 @@ function createDbVerifyCommand() {
|
|
|
1631
1886
|
}
|
|
1632
1887
|
let contractJsonContent;
|
|
1633
1888
|
try {
|
|
1634
|
-
contractJsonContent = await
|
|
1889
|
+
contractJsonContent = await readFile5(contractPathAbsolute, "utf-8");
|
|
1635
1890
|
} catch (error) {
|
|
1636
1891
|
if (error instanceof Error && error.code === "ENOENT") {
|
|
1637
1892
|
throw errorFileNotFound4(contractPathAbsolute, {
|
|
@@ -1726,7 +1981,7 @@ function createDbVerifyCommand() {
|
|
|
1726
1981
|
}
|
|
1727
1982
|
|
|
1728
1983
|
// src/cli.ts
|
|
1729
|
-
var program = new
|
|
1984
|
+
var program = new Command7();
|
|
1730
1985
|
program.name("prisma-next").description("Prisma Next CLI").version("0.0.1");
|
|
1731
1986
|
var versionOption = program.options.find((opt) => opt.flags.includes("--version"));
|
|
1732
1987
|
if (versionOption) {
|
|
@@ -1790,7 +2045,7 @@ program.exitOverride((err2) => {
|
|
|
1790
2045
|
}
|
|
1791
2046
|
process.exit(0);
|
|
1792
2047
|
});
|
|
1793
|
-
var contractCommand = new
|
|
2048
|
+
var contractCommand = new Command7("contract");
|
|
1794
2049
|
setCommandDescriptions(
|
|
1795
2050
|
contractCommand,
|
|
1796
2051
|
"Contract management commands",
|
|
@@ -1806,7 +2061,7 @@ contractCommand.configureHelp({
|
|
|
1806
2061
|
var contractEmitCommand = createContractEmitCommand();
|
|
1807
2062
|
contractCommand.addCommand(contractEmitCommand);
|
|
1808
2063
|
program.addCommand(contractCommand);
|
|
1809
|
-
var dbCommand = new
|
|
2064
|
+
var dbCommand = new Command7("db");
|
|
1810
2065
|
setCommandDescriptions(
|
|
1811
2066
|
dbCommand,
|
|
1812
2067
|
"Database management commands",
|
|
@@ -1821,6 +2076,8 @@ dbCommand.configureHelp({
|
|
|
1821
2076
|
});
|
|
1822
2077
|
var dbVerifyCommand = createDbVerifyCommand();
|
|
1823
2078
|
dbCommand.addCommand(dbVerifyCommand);
|
|
2079
|
+
var dbInitCommand = createDbInitCommand();
|
|
2080
|
+
dbCommand.addCommand(dbInitCommand);
|
|
1824
2081
|
var dbIntrospectCommand = createDbIntrospectCommand();
|
|
1825
2082
|
dbCommand.addCommand(dbIntrospectCommand);
|
|
1826
2083
|
var dbSchemaVerifyCommand = createDbSchemaVerifyCommand();
|
|
@@ -1828,7 +2085,7 @@ dbCommand.addCommand(dbSchemaVerifyCommand);
|
|
|
1828
2085
|
var dbSignCommand = createDbSignCommand();
|
|
1829
2086
|
dbCommand.addCommand(dbSignCommand);
|
|
1830
2087
|
program.addCommand(dbCommand);
|
|
1831
|
-
var helpCommand = new
|
|
2088
|
+
var helpCommand = new Command7("help").description("Show usage instructions").configureHelp({
|
|
1832
2089
|
formatHelp: (cmd) => {
|
|
1833
2090
|
const flags = parseGlobalFlags({});
|
|
1834
2091
|
return formatCommandHelp({ command: cmd, flags });
|