@prisma-next/cli 0.1.0-dev.15 → 0.1.0-dev.16
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 +325 -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 +232 -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 +14 -9
- 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,224 @@ 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 hasMigrationSupport(target) {
|
|
1180
|
+
return typeof target === "object" && target !== null && Object.hasOwn(target, "createPlanner") && typeof target["createPlanner"] === "function" && Object.hasOwn(target, "createRunner") && typeof target["createRunner"] === "function";
|
|
1181
|
+
}
|
|
1182
|
+
function createDbInitCommand() {
|
|
1183
|
+
const command = new Command2("init");
|
|
1184
|
+
setCommandDescriptions(
|
|
1185
|
+
command,
|
|
1186
|
+
"Bootstrap a database to match the current contract and write the contract marker",
|
|
1187
|
+
"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."
|
|
1188
|
+
);
|
|
1189
|
+
command.configureHelp({
|
|
1190
|
+
formatHelp: (cmd) => {
|
|
1191
|
+
const flags = parseGlobalFlags({});
|
|
1192
|
+
return formatCommandHelp({ command: cmd, flags });
|
|
1193
|
+
}
|
|
1194
|
+
}).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) => {
|
|
1195
|
+
const flags = parseGlobalFlags(options);
|
|
1196
|
+
const startTime = Date.now();
|
|
1197
|
+
const result = await performAction(async () => {
|
|
1198
|
+
const config = await loadConfig(options.config);
|
|
1199
|
+
const configPath = options.config ? relative3(process.cwd(), resolve3(options.config)) : "prisma-next.config.ts";
|
|
1200
|
+
const contractPathAbsolute = config.contract?.output ? resolve3(config.contract.output) : resolve3("src/prisma/contract.json");
|
|
1201
|
+
const contractPath = relative3(process.cwd(), contractPathAbsolute);
|
|
1202
|
+
if (flags.json !== "object" && !flags.quiet) {
|
|
1203
|
+
const details = [
|
|
1204
|
+
{ label: "config", value: configPath },
|
|
1205
|
+
{ label: "contract", value: contractPath }
|
|
1206
|
+
];
|
|
1207
|
+
if (options.db) {
|
|
1208
|
+
details.push({ label: "database", value: options.db });
|
|
1209
|
+
}
|
|
1210
|
+
if (options.plan) {
|
|
1211
|
+
details.push({ label: "mode", value: "plan (dry run)" });
|
|
1212
|
+
}
|
|
1213
|
+
const header = formatStyledHeader({
|
|
1214
|
+
command: "db init",
|
|
1215
|
+
description: "Bootstrap a database to match the current contract",
|
|
1216
|
+
url: "https://pris.ly/db-init",
|
|
1217
|
+
details,
|
|
1218
|
+
flags
|
|
1219
|
+
});
|
|
1220
|
+
console.log(header);
|
|
1221
|
+
}
|
|
1222
|
+
let contractJsonContent;
|
|
1223
|
+
try {
|
|
1224
|
+
contractJsonContent = await readFile(contractPathAbsolute, "utf-8");
|
|
1225
|
+
} catch (error) {
|
|
1226
|
+
if (error instanceof Error && error.code === "ENOENT") {
|
|
1227
|
+
throw errorFileNotFound(contractPathAbsolute, {
|
|
1228
|
+
why: `Contract file not found at ${contractPathAbsolute}`
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
throw errorUnexpected2(error instanceof Error ? error.message : String(error), {
|
|
1232
|
+
why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
let contractJson;
|
|
1236
|
+
try {
|
|
1237
|
+
contractJson = JSON.parse(contractJsonContent);
|
|
1238
|
+
} catch (error) {
|
|
1239
|
+
throw errorUnexpected2(error instanceof Error ? error.message : String(error), {
|
|
1240
|
+
why: `Failed to parse contract JSON at ${contractPathAbsolute}: ${error instanceof Error ? error.message : String(error)}`
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
const dbUrl = options.db ?? config.db?.url;
|
|
1244
|
+
if (!dbUrl) {
|
|
1245
|
+
throw errorDatabaseUrlRequired({ why: "Database URL is required for db init" });
|
|
1246
|
+
}
|
|
1247
|
+
if (!config.driver) {
|
|
1248
|
+
throw errorDriverRequired({ why: "Config.driver is required for db init" });
|
|
1249
|
+
}
|
|
1250
|
+
const driverDescriptor = config.driver;
|
|
1251
|
+
if (!hasMigrationSupport(config.target)) {
|
|
1252
|
+
throw errorTargetMigrationNotSupported({
|
|
1253
|
+
why: `Target "${config.target.id}" does not support migrations (missing createPlanner/createRunner)`
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
const driver = await withSpinner(() => driverDescriptor.create(dbUrl), {
|
|
1257
|
+
message: "Connecting to database...",
|
|
1258
|
+
flags
|
|
1259
|
+
});
|
|
1260
|
+
try {
|
|
1261
|
+
const familyInstance = config.family.create({
|
|
1262
|
+
target: config.target,
|
|
1263
|
+
adapter: config.adapter,
|
|
1264
|
+
driver: driverDescriptor,
|
|
1265
|
+
extensions: config.extensions ?? []
|
|
1266
|
+
});
|
|
1267
|
+
const typedFamilyInstance = familyInstance;
|
|
1268
|
+
const contractIR = typedFamilyInstance.validateContractIR(contractJson);
|
|
1269
|
+
const planner = config.target.createPlanner(familyInstance);
|
|
1270
|
+
const runner = config.target.createRunner(familyInstance);
|
|
1271
|
+
const schemaIR = await withSpinner(() => typedFamilyInstance.introspect({ driver }), {
|
|
1272
|
+
message: "Introspecting database schema...",
|
|
1273
|
+
flags
|
|
1274
|
+
});
|
|
1275
|
+
const policy = { allowedOperationClasses: ["additive"] };
|
|
1276
|
+
const plannerResult = await withSpinner(
|
|
1277
|
+
async () => planner.plan({
|
|
1278
|
+
contract: contractIR,
|
|
1279
|
+
schema: schemaIR,
|
|
1280
|
+
policy
|
|
1281
|
+
}),
|
|
1282
|
+
{
|
|
1283
|
+
message: "Planning migration...",
|
|
1284
|
+
flags
|
|
1285
|
+
}
|
|
1286
|
+
);
|
|
1287
|
+
if (plannerResult.kind === "failure") {
|
|
1288
|
+
throw errorMigrationPlanningFailed({ conflicts: plannerResult.conflicts });
|
|
1289
|
+
}
|
|
1290
|
+
const migrationPlan = plannerResult.plan;
|
|
1291
|
+
if (options.plan) {
|
|
1292
|
+
const dbInitResult2 = {
|
|
1293
|
+
ok: true,
|
|
1294
|
+
mode: "plan",
|
|
1295
|
+
plan: {
|
|
1296
|
+
targetId: migrationPlan.targetId,
|
|
1297
|
+
destination: migrationPlan.destination,
|
|
1298
|
+
operations: migrationPlan.operations.map((op) => ({
|
|
1299
|
+
id: op.id,
|
|
1300
|
+
label: op.label,
|
|
1301
|
+
operationClass: op.operationClass
|
|
1302
|
+
}))
|
|
1303
|
+
},
|
|
1304
|
+
summary: `Planned ${migrationPlan.operations.length} operation(s)`,
|
|
1305
|
+
timings: { total: Date.now() - startTime }
|
|
1306
|
+
};
|
|
1307
|
+
return dbInitResult2;
|
|
1308
|
+
}
|
|
1309
|
+
const callbacks = {
|
|
1310
|
+
onOperationStart: (op) => {
|
|
1311
|
+
if (!flags.quiet && flags.json !== "object") {
|
|
1312
|
+
console.log(` \u2192 ${op.label}...`);
|
|
1313
|
+
}
|
|
1314
|
+
},
|
|
1315
|
+
onOperationComplete: (_op) => {
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
const runnerResult = await withSpinner(
|
|
1319
|
+
() => runner.execute({
|
|
1320
|
+
plan: migrationPlan,
|
|
1321
|
+
driver,
|
|
1322
|
+
destinationContract: contractIR,
|
|
1323
|
+
policy,
|
|
1324
|
+
callbacks
|
|
1325
|
+
}),
|
|
1326
|
+
{
|
|
1327
|
+
message: "Applying migration plan...",
|
|
1328
|
+
flags
|
|
1329
|
+
}
|
|
1330
|
+
);
|
|
1331
|
+
if (!runnerResult.ok) {
|
|
1332
|
+
throw errorRuntime(runnerResult.failure.summary, {
|
|
1333
|
+
why: runnerResult.failure.why ?? `Migration runner failed: ${runnerResult.failure.code}`,
|
|
1334
|
+
meta: { code: runnerResult.failure.code }
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
const execution = runnerResult.value;
|
|
1338
|
+
const dbInitResult = {
|
|
1339
|
+
ok: true,
|
|
1340
|
+
mode: "apply",
|
|
1341
|
+
plan: {
|
|
1342
|
+
targetId: migrationPlan.targetId,
|
|
1343
|
+
destination: migrationPlan.destination,
|
|
1344
|
+
operations: migrationPlan.operations.map((op) => ({
|
|
1345
|
+
id: op.id,
|
|
1346
|
+
label: op.label,
|
|
1347
|
+
operationClass: op.operationClass
|
|
1348
|
+
}))
|
|
1349
|
+
},
|
|
1350
|
+
execution: {
|
|
1351
|
+
operationsPlanned: execution.operationsPlanned,
|
|
1352
|
+
operationsExecuted: execution.operationsExecuted
|
|
1353
|
+
},
|
|
1354
|
+
marker: migrationPlan.destination.profileHash ? {
|
|
1355
|
+
coreHash: migrationPlan.destination.coreHash,
|
|
1356
|
+
profileHash: migrationPlan.destination.profileHash
|
|
1357
|
+
} : { coreHash: migrationPlan.destination.coreHash },
|
|
1358
|
+
summary: `Applied ${execution.operationsExecuted} operation(s), marker written`,
|
|
1359
|
+
timings: { total: Date.now() - startTime }
|
|
1360
|
+
};
|
|
1361
|
+
return dbInitResult;
|
|
1362
|
+
} finally {
|
|
1363
|
+
await driver.close();
|
|
1364
|
+
}
|
|
1365
|
+
});
|
|
1366
|
+
const exitCode = handleResult(result, flags, (dbInitResult) => {
|
|
1367
|
+
if (flags.json === "object") {
|
|
1368
|
+
console.log(formatDbInitJson(dbInitResult));
|
|
1369
|
+
} else {
|
|
1370
|
+
const output = dbInitResult.mode === "plan" ? formatDbInitPlanOutput(dbInitResult, flags) : formatDbInitApplyOutput(dbInitResult, flags);
|
|
1371
|
+
if (output) {
|
|
1372
|
+
console.log(output);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
});
|
|
1376
|
+
process.exit(exitCode);
|
|
1377
|
+
});
|
|
1378
|
+
return command;
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// src/commands/db-introspect.ts
|
|
1382
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
1383
|
+
import { relative as relative4, resolve as resolve4 } from "path";
|
|
1127
1384
|
import {
|
|
1128
1385
|
errorDatabaseUrlRequired as errorDatabaseUrlRequired2,
|
|
1129
1386
|
errorDriverRequired as errorDriverRequired2,
|
|
1130
1387
|
errorRuntime as errorRuntime2,
|
|
1131
1388
|
errorUnexpected as errorUnexpected3
|
|
1132
1389
|
} from "@prisma-next/core-control-plane/errors";
|
|
1133
|
-
import { Command as
|
|
1390
|
+
import { Command as Command3 } from "commander";
|
|
1134
1391
|
function createDbIntrospectCommand() {
|
|
1135
|
-
const command = new
|
|
1392
|
+
const command = new Command3("introspect");
|
|
1136
1393
|
setCommandDescriptions(
|
|
1137
1394
|
command,
|
|
1138
1395
|
"Inspect the database schema",
|
|
@@ -1148,12 +1405,12 @@ function createDbIntrospectCommand() {
|
|
|
1148
1405
|
const result = await performAction(async () => {
|
|
1149
1406
|
const startTime = Date.now();
|
|
1150
1407
|
const config = await loadConfig(options.config);
|
|
1151
|
-
const configPath = options.config ?
|
|
1408
|
+
const configPath = options.config ? relative4(process.cwd(), resolve4(options.config)) : "prisma-next.config.ts";
|
|
1152
1409
|
let contractIR;
|
|
1153
1410
|
if (config.contract?.output) {
|
|
1154
|
-
const contractPath =
|
|
1411
|
+
const contractPath = resolve4(config.contract.output);
|
|
1155
1412
|
try {
|
|
1156
|
-
const contractJsonContent = await
|
|
1413
|
+
const contractJsonContent = await readFile2(contractPath, "utf-8");
|
|
1157
1414
|
const contractJson = JSON.parse(contractJsonContent);
|
|
1158
1415
|
contractIR = contractJson;
|
|
1159
1416
|
} catch (error) {
|
|
@@ -1285,8 +1542,8 @@ function createDbIntrospectCommand() {
|
|
|
1285
1542
|
}
|
|
1286
1543
|
|
|
1287
1544
|
// src/commands/db-schema-verify.ts
|
|
1288
|
-
import { readFile as
|
|
1289
|
-
import { relative as
|
|
1545
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
1546
|
+
import { relative as relative5, resolve as resolve5 } from "path";
|
|
1290
1547
|
import {
|
|
1291
1548
|
errorDatabaseUrlRequired as errorDatabaseUrlRequired3,
|
|
1292
1549
|
errorDriverRequired as errorDriverRequired3,
|
|
@@ -1294,9 +1551,9 @@ import {
|
|
|
1294
1551
|
errorRuntime as errorRuntime3,
|
|
1295
1552
|
errorUnexpected as errorUnexpected4
|
|
1296
1553
|
} from "@prisma-next/core-control-plane/errors";
|
|
1297
|
-
import { Command as
|
|
1554
|
+
import { Command as Command4 } from "commander";
|
|
1298
1555
|
function createDbSchemaVerifyCommand() {
|
|
1299
|
-
const command = new
|
|
1556
|
+
const command = new Command4("schema-verify");
|
|
1300
1557
|
setCommandDescriptions(
|
|
1301
1558
|
command,
|
|
1302
1559
|
"Check whether the database schema satisfies your contract",
|
|
@@ -1311,9 +1568,9 @@ function createDbSchemaVerifyCommand() {
|
|
|
1311
1568
|
const flags = parseGlobalFlags(options);
|
|
1312
1569
|
const result = await performAction(async () => {
|
|
1313
1570
|
const config = await loadConfig(options.config);
|
|
1314
|
-
const configPath = options.config ?
|
|
1315
|
-
const contractPathAbsolute = config.contract?.output ?
|
|
1316
|
-
const contractPath =
|
|
1571
|
+
const configPath = options.config ? relative5(process.cwd(), resolve5(options.config)) : "prisma-next.config.ts";
|
|
1572
|
+
const contractPathAbsolute = config.contract?.output ? resolve5(config.contract.output) : resolve5("src/prisma/contract.json");
|
|
1573
|
+
const contractPath = relative5(process.cwd(), contractPathAbsolute);
|
|
1317
1574
|
if (flags.json !== "object" && !flags.quiet) {
|
|
1318
1575
|
const details = [
|
|
1319
1576
|
{ label: "config", value: configPath },
|
|
@@ -1333,7 +1590,7 @@ function createDbSchemaVerifyCommand() {
|
|
|
1333
1590
|
}
|
|
1334
1591
|
let contractJsonContent;
|
|
1335
1592
|
try {
|
|
1336
|
-
contractJsonContent = await
|
|
1593
|
+
contractJsonContent = await readFile3(contractPathAbsolute, "utf-8");
|
|
1337
1594
|
} catch (error) {
|
|
1338
1595
|
if (error instanceof Error && error.code === "ENOENT") {
|
|
1339
1596
|
throw errorFileNotFound2(contractPathAbsolute, {
|
|
@@ -1414,8 +1671,8 @@ function createDbSchemaVerifyCommand() {
|
|
|
1414
1671
|
}
|
|
1415
1672
|
|
|
1416
1673
|
// src/commands/db-sign.ts
|
|
1417
|
-
import { readFile as
|
|
1418
|
-
import { relative as
|
|
1674
|
+
import { readFile as readFile4 } from "fs/promises";
|
|
1675
|
+
import { relative as relative6, resolve as resolve6 } from "path";
|
|
1419
1676
|
import {
|
|
1420
1677
|
errorDatabaseUrlRequired as errorDatabaseUrlRequired4,
|
|
1421
1678
|
errorDriverRequired as errorDriverRequired4,
|
|
@@ -1423,9 +1680,9 @@ import {
|
|
|
1423
1680
|
errorRuntime as errorRuntime4,
|
|
1424
1681
|
errorUnexpected as errorUnexpected5
|
|
1425
1682
|
} from "@prisma-next/core-control-plane/errors";
|
|
1426
|
-
import { Command as
|
|
1683
|
+
import { Command as Command5 } from "commander";
|
|
1427
1684
|
function createDbSignCommand() {
|
|
1428
|
-
const command = new
|
|
1685
|
+
const command = new Command5("sign");
|
|
1429
1686
|
setCommandDescriptions(
|
|
1430
1687
|
command,
|
|
1431
1688
|
"Sign the database with your contract so you can safely run queries",
|
|
@@ -1440,9 +1697,9 @@ function createDbSignCommand() {
|
|
|
1440
1697
|
const flags = parseGlobalFlags(options);
|
|
1441
1698
|
const result = await performAction(async () => {
|
|
1442
1699
|
const config = await loadConfig(options.config);
|
|
1443
|
-
const configPath = options.config ?
|
|
1444
|
-
const contractPathAbsolute = config.contract?.output ?
|
|
1445
|
-
const contractPath =
|
|
1700
|
+
const configPath = options.config ? relative6(process.cwd(), resolve6(options.config)) : "prisma-next.config.ts";
|
|
1701
|
+
const contractPathAbsolute = config.contract?.output ? resolve6(config.contract.output) : resolve6("src/prisma/contract.json");
|
|
1702
|
+
const contractPath = relative6(process.cwd(), contractPathAbsolute);
|
|
1446
1703
|
if (flags.json !== "object" && !flags.quiet) {
|
|
1447
1704
|
const details = [
|
|
1448
1705
|
{ label: "config", value: configPath },
|
|
@@ -1462,7 +1719,7 @@ function createDbSignCommand() {
|
|
|
1462
1719
|
}
|
|
1463
1720
|
let contractJsonContent;
|
|
1464
1721
|
try {
|
|
1465
|
-
contractJsonContent = await
|
|
1722
|
+
contractJsonContent = await readFile4(contractPathAbsolute, "utf-8");
|
|
1466
1723
|
} catch (error) {
|
|
1467
1724
|
if (error instanceof Error && error.code === "ENOENT") {
|
|
1468
1725
|
throw errorFileNotFound3(contractPathAbsolute, {
|
|
@@ -1580,8 +1837,8 @@ function createDbSignCommand() {
|
|
|
1580
1837
|
}
|
|
1581
1838
|
|
|
1582
1839
|
// src/commands/db-verify.ts
|
|
1583
|
-
import { readFile as
|
|
1584
|
-
import { relative as
|
|
1840
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
1841
|
+
import { relative as relative7, resolve as resolve7 } from "path";
|
|
1585
1842
|
import {
|
|
1586
1843
|
errorDatabaseUrlRequired as errorDatabaseUrlRequired5,
|
|
1587
1844
|
errorDriverRequired as errorDriverRequired5,
|
|
@@ -1592,9 +1849,9 @@ import {
|
|
|
1592
1849
|
errorTargetMismatch as errorTargetMismatch2,
|
|
1593
1850
|
errorUnexpected as errorUnexpected6
|
|
1594
1851
|
} from "@prisma-next/core-control-plane/errors";
|
|
1595
|
-
import { Command as
|
|
1852
|
+
import { Command as Command6 } from "commander";
|
|
1596
1853
|
function createDbVerifyCommand() {
|
|
1597
|
-
const command = new
|
|
1854
|
+
const command = new Command6("verify");
|
|
1598
1855
|
setCommandDescriptions(
|
|
1599
1856
|
command,
|
|
1600
1857
|
"Check whether the database has been signed with your contract",
|
|
@@ -1609,9 +1866,9 @@ function createDbVerifyCommand() {
|
|
|
1609
1866
|
const flags = parseGlobalFlags(options);
|
|
1610
1867
|
const result = await performAction(async () => {
|
|
1611
1868
|
const config = await loadConfig(options.config);
|
|
1612
|
-
const configPath = options.config ?
|
|
1613
|
-
const contractPathAbsolute = config.contract?.output ?
|
|
1614
|
-
const contractPath =
|
|
1869
|
+
const configPath = options.config ? relative7(process.cwd(), resolve7(options.config)) : "prisma-next.config.ts";
|
|
1870
|
+
const contractPathAbsolute = config.contract?.output ? resolve7(config.contract.output) : resolve7("src/prisma/contract.json");
|
|
1871
|
+
const contractPath = relative7(process.cwd(), contractPathAbsolute);
|
|
1615
1872
|
if (flags.json !== "object" && !flags.quiet) {
|
|
1616
1873
|
const details = [
|
|
1617
1874
|
{ label: "config", value: configPath },
|
|
@@ -1631,7 +1888,7 @@ function createDbVerifyCommand() {
|
|
|
1631
1888
|
}
|
|
1632
1889
|
let contractJsonContent;
|
|
1633
1890
|
try {
|
|
1634
|
-
contractJsonContent = await
|
|
1891
|
+
contractJsonContent = await readFile5(contractPathAbsolute, "utf-8");
|
|
1635
1892
|
} catch (error) {
|
|
1636
1893
|
if (error instanceof Error && error.code === "ENOENT") {
|
|
1637
1894
|
throw errorFileNotFound4(contractPathAbsolute, {
|
|
@@ -1726,7 +1983,7 @@ function createDbVerifyCommand() {
|
|
|
1726
1983
|
}
|
|
1727
1984
|
|
|
1728
1985
|
// src/cli.ts
|
|
1729
|
-
var program = new
|
|
1986
|
+
var program = new Command7();
|
|
1730
1987
|
program.name("prisma-next").description("Prisma Next CLI").version("0.0.1");
|
|
1731
1988
|
var versionOption = program.options.find((opt) => opt.flags.includes("--version"));
|
|
1732
1989
|
if (versionOption) {
|
|
@@ -1790,7 +2047,7 @@ program.exitOverride((err2) => {
|
|
|
1790
2047
|
}
|
|
1791
2048
|
process.exit(0);
|
|
1792
2049
|
});
|
|
1793
|
-
var contractCommand = new
|
|
2050
|
+
var contractCommand = new Command7("contract");
|
|
1794
2051
|
setCommandDescriptions(
|
|
1795
2052
|
contractCommand,
|
|
1796
2053
|
"Contract management commands",
|
|
@@ -1806,7 +2063,7 @@ contractCommand.configureHelp({
|
|
|
1806
2063
|
var contractEmitCommand = createContractEmitCommand();
|
|
1807
2064
|
contractCommand.addCommand(contractEmitCommand);
|
|
1808
2065
|
program.addCommand(contractCommand);
|
|
1809
|
-
var dbCommand = new
|
|
2066
|
+
var dbCommand = new Command7("db");
|
|
1810
2067
|
setCommandDescriptions(
|
|
1811
2068
|
dbCommand,
|
|
1812
2069
|
"Database management commands",
|
|
@@ -1821,6 +2078,8 @@ dbCommand.configureHelp({
|
|
|
1821
2078
|
});
|
|
1822
2079
|
var dbVerifyCommand = createDbVerifyCommand();
|
|
1823
2080
|
dbCommand.addCommand(dbVerifyCommand);
|
|
2081
|
+
var dbInitCommand = createDbInitCommand();
|
|
2082
|
+
dbCommand.addCommand(dbInitCommand);
|
|
1824
2083
|
var dbIntrospectCommand = createDbIntrospectCommand();
|
|
1825
2084
|
dbCommand.addCommand(dbIntrospectCommand);
|
|
1826
2085
|
var dbSchemaVerifyCommand = createDbSchemaVerifyCommand();
|
|
@@ -1828,7 +2087,7 @@ dbCommand.addCommand(dbSchemaVerifyCommand);
|
|
|
1828
2087
|
var dbSignCommand = createDbSignCommand();
|
|
1829
2088
|
dbCommand.addCommand(dbSignCommand);
|
|
1830
2089
|
program.addCommand(dbCommand);
|
|
1831
|
-
var helpCommand = new
|
|
2090
|
+
var helpCommand = new Command7("help").description("Show usage instructions").configureHelp({
|
|
1832
2091
|
formatHelp: (cmd) => {
|
|
1833
2092
|
const flags = parseGlobalFlags({});
|
|
1834
2093
|
return formatCommandHelp({ command: cmd, flags });
|