@prisma-next/cli 0.0.1
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 +840 -0
- package/dist/chunk-W5YXBFPY.js +96 -0
- package/dist/chunk-W5YXBFPY.js.map +1 -0
- package/dist/cli.js +1872 -0
- package/dist/cli.js.map +1 -0
- package/dist/config-types.d.ts +1 -0
- package/dist/config-types.js +6 -0
- package/dist/config-types.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +803 -0
- package/dist/index.js.map +1 -0
- package/dist/pack-loading.d.ts +6 -0
- package/dist/pack-loading.js +9 -0
- package/dist/pack-loading.js.map +1 -0
- package/package.json +61 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,1872 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { Command as Command6 } from "commander";
|
|
5
|
+
|
|
6
|
+
// src/commands/contract-emit.ts
|
|
7
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
8
|
+
import { dirname as dirname2, relative as relative2, resolve as resolve2 } from "path";
|
|
9
|
+
import { errorContractConfigMissing as errorContractConfigMissing2 } from "@prisma-next/core-control-plane/errors";
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
|
|
12
|
+
// src/config-loader.ts
|
|
13
|
+
import { dirname, resolve } from "path";
|
|
14
|
+
import { validateConfig } from "@prisma-next/core-control-plane/config-validation";
|
|
15
|
+
import { errorConfigFileNotFound, errorUnexpected } from "@prisma-next/core-control-plane/errors";
|
|
16
|
+
import { loadConfig as loadConfigC12 } from "c12";
|
|
17
|
+
async function loadConfig(configPath) {
|
|
18
|
+
try {
|
|
19
|
+
const cwd = process.cwd();
|
|
20
|
+
const resolvedConfigPath = configPath ? resolve(cwd, configPath) : void 0;
|
|
21
|
+
const configCwd = resolvedConfigPath ? dirname(resolvedConfigPath) : cwd;
|
|
22
|
+
const result = await loadConfigC12({
|
|
23
|
+
name: "prisma-next",
|
|
24
|
+
...resolvedConfigPath ? { configFile: resolvedConfigPath } : {},
|
|
25
|
+
cwd: configCwd
|
|
26
|
+
});
|
|
27
|
+
if (!result.config || Object.keys(result.config).length === 0) {
|
|
28
|
+
const displayPath = result.configFile || resolvedConfigPath || configPath;
|
|
29
|
+
throw errorConfigFileNotFound(displayPath);
|
|
30
|
+
}
|
|
31
|
+
validateConfig(result.config);
|
|
32
|
+
return result.config;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (error instanceof Error && "code" in error && typeof error.code === "string") {
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
if (error instanceof Error) {
|
|
38
|
+
if (error.message.includes("not found") || error.message.includes("Cannot find") || error.message.includes("ENOENT")) {
|
|
39
|
+
const displayPath = configPath ? resolve(process.cwd(), configPath) : void 0;
|
|
40
|
+
throw errorConfigFileNotFound(displayPath, {
|
|
41
|
+
why: error.message
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
throw errorUnexpected(error.message, {
|
|
45
|
+
why: `Failed to load config: ${error.message}`
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
throw errorUnexpected(String(error));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/utils/command-helpers.ts
|
|
53
|
+
function setCommandDescriptions(command, shortDescription, longDescription) {
|
|
54
|
+
command.description(shortDescription);
|
|
55
|
+
if (longDescription) {
|
|
56
|
+
command._longDescription = longDescription;
|
|
57
|
+
}
|
|
58
|
+
return command;
|
|
59
|
+
}
|
|
60
|
+
function getLongDescription(command) {
|
|
61
|
+
return command._longDescription;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/utils/global-flags.ts
|
|
65
|
+
function parseGlobalFlags(options) {
|
|
66
|
+
const flags = {};
|
|
67
|
+
if (options.json === true || options.json === "object") {
|
|
68
|
+
flags.json = "object";
|
|
69
|
+
} else if (options.json === "ndjson") {
|
|
70
|
+
flags.json = "ndjson";
|
|
71
|
+
}
|
|
72
|
+
if (options.quiet || options.q) {
|
|
73
|
+
flags.quiet = true;
|
|
74
|
+
}
|
|
75
|
+
if (options.vv || options.trace) {
|
|
76
|
+
flags.verbose = 2;
|
|
77
|
+
} else if (options.verbose || options.v) {
|
|
78
|
+
flags.verbose = 1;
|
|
79
|
+
} else {
|
|
80
|
+
flags.verbose = 0;
|
|
81
|
+
}
|
|
82
|
+
if (options.timestamps) {
|
|
83
|
+
flags.timestamps = true;
|
|
84
|
+
}
|
|
85
|
+
if (process.env["NO_COLOR"]) {
|
|
86
|
+
flags.color = false;
|
|
87
|
+
} else if (options["no-color"]) {
|
|
88
|
+
flags.color = false;
|
|
89
|
+
} else if (options.color !== void 0) {
|
|
90
|
+
flags.color = options.color;
|
|
91
|
+
} else {
|
|
92
|
+
flags.color = process.stdout.isTTY && !process.env["CI"];
|
|
93
|
+
}
|
|
94
|
+
return flags;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/utils/output.ts
|
|
98
|
+
import { relative } from "path";
|
|
99
|
+
import { bgGreen, blue, bold, cyan, dim, green, magenta, red, yellow } from "colorette";
|
|
100
|
+
import stringWidth from "string-width";
|
|
101
|
+
import stripAnsi from "strip-ansi";
|
|
102
|
+
import wrapAnsi from "wrap-ansi";
|
|
103
|
+
function formatTimestamp() {
|
|
104
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
105
|
+
}
|
|
106
|
+
function createPrefix(flags) {
|
|
107
|
+
return flags.timestamps ? `[${formatTimestamp()}] ` : "";
|
|
108
|
+
}
|
|
109
|
+
function isVerbose(flags, level) {
|
|
110
|
+
return (flags.verbose ?? 0) >= level;
|
|
111
|
+
}
|
|
112
|
+
function createColorFormatter(useColor, colorFn) {
|
|
113
|
+
return useColor ? colorFn : (text) => text;
|
|
114
|
+
}
|
|
115
|
+
function formatDim(useColor, text) {
|
|
116
|
+
return useColor ? dim(text) : text;
|
|
117
|
+
}
|
|
118
|
+
function formatEmitOutput(result, flags) {
|
|
119
|
+
if (flags.quiet) {
|
|
120
|
+
return "";
|
|
121
|
+
}
|
|
122
|
+
const lines = [];
|
|
123
|
+
const prefix = createPrefix(flags);
|
|
124
|
+
const jsonPath = relative(process.cwd(), result.files.json);
|
|
125
|
+
const dtsPath = relative(process.cwd(), result.files.dts);
|
|
126
|
+
lines.push(`${prefix}\u2714 Emitted contract.json \u2192 ${jsonPath}`);
|
|
127
|
+
lines.push(`${prefix}\u2714 Emitted contract.d.ts \u2192 ${dtsPath}`);
|
|
128
|
+
lines.push(`${prefix} coreHash: ${result.coreHash}`);
|
|
129
|
+
if (result.profileHash) {
|
|
130
|
+
lines.push(`${prefix} profileHash: ${result.profileHash}`);
|
|
131
|
+
}
|
|
132
|
+
if (isVerbose(flags, 1)) {
|
|
133
|
+
lines.push(`${prefix} Total time: ${result.timings.total}ms`);
|
|
134
|
+
}
|
|
135
|
+
return lines.join("\n");
|
|
136
|
+
}
|
|
137
|
+
function formatEmitJson(result) {
|
|
138
|
+
const output = {
|
|
139
|
+
ok: true,
|
|
140
|
+
coreHash: result.coreHash,
|
|
141
|
+
...result.profileHash ? { profileHash: result.profileHash } : {},
|
|
142
|
+
outDir: result.outDir,
|
|
143
|
+
files: result.files,
|
|
144
|
+
timings: result.timings
|
|
145
|
+
};
|
|
146
|
+
return JSON.stringify(output, null, 2);
|
|
147
|
+
}
|
|
148
|
+
function formatErrorOutput(error, flags) {
|
|
149
|
+
const lines = [];
|
|
150
|
+
const prefix = createPrefix(flags);
|
|
151
|
+
const useColor = flags.color !== false;
|
|
152
|
+
const formatRed = createColorFormatter(useColor, red);
|
|
153
|
+
const formatDimText = (text) => formatDim(useColor, text);
|
|
154
|
+
lines.push(`${prefix}${formatRed("\u2716")} ${error.summary} (${error.code})`);
|
|
155
|
+
if (error.why) {
|
|
156
|
+
lines.push(`${prefix}${formatDimText(` Why: ${error.why}`)}`);
|
|
157
|
+
}
|
|
158
|
+
if (error.fix) {
|
|
159
|
+
lines.push(`${prefix}${formatDimText(` Fix: ${error.fix}`)}`);
|
|
160
|
+
}
|
|
161
|
+
if (error.where?.path) {
|
|
162
|
+
const whereLine = error.where.line ? `${error.where.path}:${error.where.line}` : error.where.path;
|
|
163
|
+
lines.push(`${prefix}${formatDimText(` Where: ${whereLine}`)}`);
|
|
164
|
+
}
|
|
165
|
+
if (error.docsUrl && isVerbose(flags, 1)) {
|
|
166
|
+
lines.push(formatDimText(error.docsUrl));
|
|
167
|
+
}
|
|
168
|
+
if (isVerbose(flags, 2) && error.meta) {
|
|
169
|
+
lines.push(`${prefix}${formatDimText(` Meta: ${JSON.stringify(error.meta, null, 2)}`)}`);
|
|
170
|
+
}
|
|
171
|
+
return lines.join("\n");
|
|
172
|
+
}
|
|
173
|
+
function formatErrorJson(error) {
|
|
174
|
+
return JSON.stringify(error, null, 2);
|
|
175
|
+
}
|
|
176
|
+
function formatVerifyOutput(result, flags) {
|
|
177
|
+
if (flags.quiet) {
|
|
178
|
+
return "";
|
|
179
|
+
}
|
|
180
|
+
const lines = [];
|
|
181
|
+
const prefix = createPrefix(flags);
|
|
182
|
+
const useColor = flags.color !== false;
|
|
183
|
+
const formatGreen = createColorFormatter(useColor, green);
|
|
184
|
+
const formatRed = createColorFormatter(useColor, red);
|
|
185
|
+
const formatDimText = (text) => formatDim(useColor, text);
|
|
186
|
+
if (result.ok) {
|
|
187
|
+
lines.push(`${prefix}${formatGreen("\u2714")} ${result.summary}`);
|
|
188
|
+
lines.push(`${prefix}${formatDimText(` coreHash: ${result.contract.coreHash}`)}`);
|
|
189
|
+
if (result.contract.profileHash) {
|
|
190
|
+
lines.push(`${prefix}${formatDimText(` profileHash: ${result.contract.profileHash}`)}`);
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
lines.push(`${prefix}${formatRed("\u2716")} ${result.summary} (${result.code})`);
|
|
194
|
+
}
|
|
195
|
+
if (isVerbose(flags, 1)) {
|
|
196
|
+
if (result.codecCoverageSkipped) {
|
|
197
|
+
lines.push(
|
|
198
|
+
`${prefix}${formatDimText(" Codec coverage check skipped (helper returned no supported types)")}`
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
lines.push(`${prefix}${formatDimText(` Total time: ${result.timings.total}ms`)}`);
|
|
202
|
+
}
|
|
203
|
+
return lines.join("\n");
|
|
204
|
+
}
|
|
205
|
+
function formatVerifyJson(result) {
|
|
206
|
+
const output = {
|
|
207
|
+
ok: result.ok,
|
|
208
|
+
...result.code ? { code: result.code } : {},
|
|
209
|
+
summary: result.summary,
|
|
210
|
+
contract: result.contract,
|
|
211
|
+
...result.marker ? { marker: result.marker } : {},
|
|
212
|
+
target: result.target,
|
|
213
|
+
...result.missingCodecs ? { missingCodecs: result.missingCodecs } : {},
|
|
214
|
+
...result.meta ? { meta: result.meta } : {},
|
|
215
|
+
timings: result.timings
|
|
216
|
+
};
|
|
217
|
+
return JSON.stringify(output, null, 2);
|
|
218
|
+
}
|
|
219
|
+
function formatIntrospectJson(result) {
|
|
220
|
+
return JSON.stringify(result, null, 2);
|
|
221
|
+
}
|
|
222
|
+
function renderSchemaTree(node, flags, options) {
|
|
223
|
+
const { isLast, prefix, useColor, formatDimText, isRoot = false } = options;
|
|
224
|
+
const lines = [];
|
|
225
|
+
let formattedLabel = node.label;
|
|
226
|
+
if (useColor) {
|
|
227
|
+
switch (node.kind) {
|
|
228
|
+
case "root":
|
|
229
|
+
formattedLabel = bold(node.label);
|
|
230
|
+
break;
|
|
231
|
+
case "entity": {
|
|
232
|
+
const tableMatch = node.label.match(/^table\s+(.+)$/);
|
|
233
|
+
if (tableMatch?.[1]) {
|
|
234
|
+
const tableName = tableMatch[1];
|
|
235
|
+
formattedLabel = `${dim("table")} ${cyan(tableName)}`;
|
|
236
|
+
} else {
|
|
237
|
+
formattedLabel = cyan(node.label);
|
|
238
|
+
}
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case "collection": {
|
|
242
|
+
formattedLabel = dim(node.label);
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case "field": {
|
|
246
|
+
const columnMatch = node.label.match(/^([^:]+):\s*(.+)$/);
|
|
247
|
+
if (columnMatch?.[1] && columnMatch[2]) {
|
|
248
|
+
const columnName = columnMatch[1];
|
|
249
|
+
const rest = columnMatch[2];
|
|
250
|
+
const typeMatch = rest.match(/^([^\s(]+)\s*(\([^)]+\))$/);
|
|
251
|
+
if (typeMatch?.[1] && typeMatch[2]) {
|
|
252
|
+
const typeDisplay = typeMatch[1];
|
|
253
|
+
const nullability = typeMatch[2];
|
|
254
|
+
formattedLabel = `${cyan(columnName)}: ${typeDisplay} ${dim(nullability)}`;
|
|
255
|
+
} else {
|
|
256
|
+
formattedLabel = `${cyan(columnName)}: ${rest}`;
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
formattedLabel = node.label;
|
|
260
|
+
}
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
case "index": {
|
|
264
|
+
const pkMatch = node.label.match(/^primary key:\s*(.+)$/);
|
|
265
|
+
if (pkMatch?.[1]) {
|
|
266
|
+
const columnNames = pkMatch[1];
|
|
267
|
+
formattedLabel = `${dim("primary key")}: ${cyan(columnNames)}`;
|
|
268
|
+
} else {
|
|
269
|
+
const uniqueMatch = node.label.match(/^unique\s+(.+)$/);
|
|
270
|
+
if (uniqueMatch?.[1]) {
|
|
271
|
+
const name = uniqueMatch[1];
|
|
272
|
+
formattedLabel = `${dim("unique")} ${cyan(name)}`;
|
|
273
|
+
} else {
|
|
274
|
+
const indexMatch = node.label.match(/^(unique\s+)?index\s+(.+)$/);
|
|
275
|
+
if (indexMatch?.[2]) {
|
|
276
|
+
const prefix2 = indexMatch[1] ? `${dim("unique")} ` : "";
|
|
277
|
+
const name = indexMatch[2];
|
|
278
|
+
formattedLabel = `${prefix2}${dim("index")} ${cyan(name)}`;
|
|
279
|
+
} else {
|
|
280
|
+
formattedLabel = dim(node.label);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
case "extension": {
|
|
287
|
+
const extMatch = node.label.match(/^([^\s]+)\s+(extension is enabled)$/);
|
|
288
|
+
if (extMatch?.[1] && extMatch[2]) {
|
|
289
|
+
const extName = extMatch[1];
|
|
290
|
+
const rest = extMatch[2];
|
|
291
|
+
formattedLabel = `${cyan(extName)} ${dim(rest)}`;
|
|
292
|
+
} else {
|
|
293
|
+
formattedLabel = magenta(node.label);
|
|
294
|
+
}
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
default:
|
|
298
|
+
formattedLabel = node.label;
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (isRoot) {
|
|
303
|
+
lines.push(formattedLabel);
|
|
304
|
+
} else {
|
|
305
|
+
const treeChar = isLast ? "\u2514" : "\u251C";
|
|
306
|
+
const treePrefix = `${prefix}${formatDimText(treeChar)}\u2500 `;
|
|
307
|
+
const isRootChild = prefix === "";
|
|
308
|
+
const prefixWithoutAnsi = stripAnsi(prefix);
|
|
309
|
+
const prefixHasVerticalBar = prefixWithoutAnsi.includes("\u2502");
|
|
310
|
+
if (isRootChild) {
|
|
311
|
+
lines.push(`${treePrefix}${formattedLabel}`);
|
|
312
|
+
} else if (prefixHasVerticalBar) {
|
|
313
|
+
lines.push(`${treePrefix}${formattedLabel}`);
|
|
314
|
+
} else {
|
|
315
|
+
lines.push(`${formatDimText("\u2502")} ${treePrefix}${formattedLabel}`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (node.children && node.children.length > 0) {
|
|
319
|
+
const childPrefix = isRoot ? "" : isLast ? `${prefix} ` : `${prefix}${formatDimText("\u2502")} `;
|
|
320
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
321
|
+
const child = node.children[i];
|
|
322
|
+
if (!child) continue;
|
|
323
|
+
const isLastChild = i === node.children.length - 1;
|
|
324
|
+
const childLines = renderSchemaTree(child, flags, {
|
|
325
|
+
isLast: isLastChild,
|
|
326
|
+
prefix: childPrefix,
|
|
327
|
+
useColor,
|
|
328
|
+
formatDimText,
|
|
329
|
+
isRoot: false
|
|
330
|
+
});
|
|
331
|
+
lines.push(...childLines);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return lines;
|
|
335
|
+
}
|
|
336
|
+
function formatIntrospectOutput(result, schemaView, flags) {
|
|
337
|
+
if (flags.quiet) {
|
|
338
|
+
return "";
|
|
339
|
+
}
|
|
340
|
+
const lines = [];
|
|
341
|
+
const prefix = createPrefix(flags);
|
|
342
|
+
const useColor = flags.color !== false;
|
|
343
|
+
const formatDimText = (text) => formatDim(useColor, text);
|
|
344
|
+
if (schemaView) {
|
|
345
|
+
const treeLines = renderSchemaTree(schemaView.root, flags, {
|
|
346
|
+
isLast: true,
|
|
347
|
+
prefix: "",
|
|
348
|
+
useColor,
|
|
349
|
+
formatDimText,
|
|
350
|
+
isRoot: true
|
|
351
|
+
});
|
|
352
|
+
const prefixedTreeLines = treeLines.map((line) => `${prefix}${line}`);
|
|
353
|
+
lines.push(...prefixedTreeLines);
|
|
354
|
+
} else {
|
|
355
|
+
lines.push(`${prefix}\u2714 ${result.summary}`);
|
|
356
|
+
if (isVerbose(flags, 1)) {
|
|
357
|
+
lines.push(`${prefix} Target: ${result.target.familyId}/${result.target.id}`);
|
|
358
|
+
if (result.meta?.dbUrl) {
|
|
359
|
+
lines.push(`${prefix} Database: ${result.meta.dbUrl}`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (isVerbose(flags, 1)) {
|
|
364
|
+
lines.push(`${prefix}${formatDimText(` Total time: ${result.timings.total}ms`)}`);
|
|
365
|
+
}
|
|
366
|
+
return lines.join("\n");
|
|
367
|
+
}
|
|
368
|
+
function renderSchemaVerificationTree(node, flags, options) {
|
|
369
|
+
const { isLast, prefix, useColor, formatDimText, isRoot = false } = options;
|
|
370
|
+
const lines = [];
|
|
371
|
+
let statusGlyph = "";
|
|
372
|
+
let statusColor = (text) => text;
|
|
373
|
+
if (useColor) {
|
|
374
|
+
switch (node.status) {
|
|
375
|
+
case "pass":
|
|
376
|
+
statusGlyph = "\u2714";
|
|
377
|
+
statusColor = green;
|
|
378
|
+
break;
|
|
379
|
+
case "warn":
|
|
380
|
+
statusGlyph = "\u26A0";
|
|
381
|
+
statusColor = (text) => useColor ? yellow(text) : text;
|
|
382
|
+
break;
|
|
383
|
+
case "fail":
|
|
384
|
+
statusGlyph = "\u2716";
|
|
385
|
+
statusColor = red;
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
} else {
|
|
389
|
+
switch (node.status) {
|
|
390
|
+
case "pass":
|
|
391
|
+
statusGlyph = "\u2714";
|
|
392
|
+
break;
|
|
393
|
+
case "warn":
|
|
394
|
+
statusGlyph = "\u26A0";
|
|
395
|
+
break;
|
|
396
|
+
case "fail":
|
|
397
|
+
statusGlyph = "\u2716";
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
let labelColor = (text) => text;
|
|
402
|
+
let formattedLabel = node.name;
|
|
403
|
+
if (useColor) {
|
|
404
|
+
switch (node.kind) {
|
|
405
|
+
case "contract":
|
|
406
|
+
case "schema":
|
|
407
|
+
labelColor = bold;
|
|
408
|
+
formattedLabel = labelColor(node.name);
|
|
409
|
+
break;
|
|
410
|
+
case "table": {
|
|
411
|
+
const tableMatch = node.name.match(/^table\s+(.+)$/);
|
|
412
|
+
if (tableMatch?.[1]) {
|
|
413
|
+
const tableName = tableMatch[1];
|
|
414
|
+
formattedLabel = `${dim("table")} ${cyan(tableName)}`;
|
|
415
|
+
} else {
|
|
416
|
+
formattedLabel = dim(node.name);
|
|
417
|
+
}
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
case "columns":
|
|
421
|
+
labelColor = dim;
|
|
422
|
+
formattedLabel = labelColor(node.name);
|
|
423
|
+
break;
|
|
424
|
+
case "column": {
|
|
425
|
+
const columnMatch = node.name.match(/^([^:]+):\s*(.+)$/);
|
|
426
|
+
if (columnMatch?.[1] && columnMatch[2]) {
|
|
427
|
+
const columnName = columnMatch[1];
|
|
428
|
+
const rest = columnMatch[2];
|
|
429
|
+
const typeMatch = rest.match(/^([^\s→]+)\s*→\s*([^\s(]+)\s*(\([^)]+\))$/);
|
|
430
|
+
if (typeMatch?.[1] && typeMatch[2] && typeMatch[3]) {
|
|
431
|
+
const contractType = typeMatch[1];
|
|
432
|
+
const nativeType = typeMatch[2];
|
|
433
|
+
const nullability = typeMatch[3];
|
|
434
|
+
formattedLabel = `${cyan(columnName)}: ${contractType} \u2192 ${dim(nativeType)} ${dim(nullability)}`;
|
|
435
|
+
} else {
|
|
436
|
+
formattedLabel = `${cyan(columnName)}: ${rest}`;
|
|
437
|
+
}
|
|
438
|
+
} else {
|
|
439
|
+
formattedLabel = node.name;
|
|
440
|
+
}
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
case "type":
|
|
444
|
+
case "nullability":
|
|
445
|
+
labelColor = (text) => text;
|
|
446
|
+
formattedLabel = labelColor(node.name);
|
|
447
|
+
break;
|
|
448
|
+
case "primaryKey": {
|
|
449
|
+
const pkMatch = node.name.match(/^primary key:\s*(.+)$/);
|
|
450
|
+
if (pkMatch?.[1]) {
|
|
451
|
+
const columnNames = pkMatch[1];
|
|
452
|
+
formattedLabel = `${dim("primary key")}: ${cyan(columnNames)}`;
|
|
453
|
+
} else {
|
|
454
|
+
formattedLabel = dim(node.name);
|
|
455
|
+
}
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
case "foreignKey":
|
|
459
|
+
case "unique":
|
|
460
|
+
case "index":
|
|
461
|
+
labelColor = dim;
|
|
462
|
+
formattedLabel = labelColor(node.name);
|
|
463
|
+
break;
|
|
464
|
+
case "extension": {
|
|
465
|
+
const dbMatch = node.name.match(/^database is\s+(.+)$/);
|
|
466
|
+
if (dbMatch?.[1]) {
|
|
467
|
+
const dbName = dbMatch[1];
|
|
468
|
+
formattedLabel = `${dim("database is")} ${cyan(dbName)}`;
|
|
469
|
+
} else {
|
|
470
|
+
const extMatch = node.name.match(/^([^\s]+)\s+(extension is enabled)$/);
|
|
471
|
+
if (extMatch?.[1] && extMatch[2]) {
|
|
472
|
+
const extName = extMatch[1];
|
|
473
|
+
const rest = extMatch[2];
|
|
474
|
+
formattedLabel = `${cyan(extName)} ${dim(rest)}`;
|
|
475
|
+
} else {
|
|
476
|
+
labelColor = magenta;
|
|
477
|
+
formattedLabel = labelColor(node.name);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
default:
|
|
483
|
+
formattedLabel = node.name;
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
486
|
+
} else {
|
|
487
|
+
formattedLabel = node.name;
|
|
488
|
+
}
|
|
489
|
+
const statusGlyphColored = statusColor(statusGlyph);
|
|
490
|
+
let nodeLabel = formattedLabel;
|
|
491
|
+
if ((node.status === "fail" || node.status === "warn") && node.message && node.message.length > 0) {
|
|
492
|
+
const messageText = formatDimText(`(${node.message})`);
|
|
493
|
+
nodeLabel = `${formattedLabel} ${messageText}`;
|
|
494
|
+
}
|
|
495
|
+
if (isRoot) {
|
|
496
|
+
lines.push(`${statusGlyphColored} ${nodeLabel}`);
|
|
497
|
+
} else {
|
|
498
|
+
const treeChar = isLast ? "\u2514" : "\u251C";
|
|
499
|
+
const treePrefix = `${prefix}${formatDimText(treeChar)}\u2500 `;
|
|
500
|
+
const isRootChild = prefix === "";
|
|
501
|
+
const prefixWithoutAnsi = stripAnsi(prefix);
|
|
502
|
+
const prefixHasVerticalBar = prefixWithoutAnsi.includes("\u2502");
|
|
503
|
+
if (isRootChild) {
|
|
504
|
+
lines.push(`${treePrefix}${statusGlyphColored} ${nodeLabel}`);
|
|
505
|
+
} else if (prefixHasVerticalBar) {
|
|
506
|
+
lines.push(`${treePrefix}${statusGlyphColored} ${nodeLabel}`);
|
|
507
|
+
} else {
|
|
508
|
+
lines.push(`${formatDimText("\u2502")} ${treePrefix}${statusGlyphColored} ${nodeLabel}`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
if (node.children && node.children.length > 0) {
|
|
512
|
+
const childPrefix = isRoot ? "" : isLast ? `${prefix} ` : `${prefix}${formatDimText("\u2502")} `;
|
|
513
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
514
|
+
const child = node.children[i];
|
|
515
|
+
if (!child) continue;
|
|
516
|
+
const isLastChild = i === node.children.length - 1;
|
|
517
|
+
const childLines = renderSchemaVerificationTree(child, flags, {
|
|
518
|
+
isLast: isLastChild,
|
|
519
|
+
prefix: childPrefix,
|
|
520
|
+
useColor,
|
|
521
|
+
formatDimText,
|
|
522
|
+
isRoot: false
|
|
523
|
+
});
|
|
524
|
+
lines.push(...childLines);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return lines;
|
|
528
|
+
}
|
|
529
|
+
function formatSchemaVerifyOutput(result, flags) {
|
|
530
|
+
if (flags.quiet) {
|
|
531
|
+
return "";
|
|
532
|
+
}
|
|
533
|
+
const lines = [];
|
|
534
|
+
const prefix = createPrefix(flags);
|
|
535
|
+
const useColor = flags.color !== false;
|
|
536
|
+
const formatGreen = createColorFormatter(useColor, green);
|
|
537
|
+
const formatRed = createColorFormatter(useColor, red);
|
|
538
|
+
const formatDimText = (text) => formatDim(useColor, text);
|
|
539
|
+
const treeLines = renderSchemaVerificationTree(result.schema.root, flags, {
|
|
540
|
+
isLast: true,
|
|
541
|
+
prefix: "",
|
|
542
|
+
useColor,
|
|
543
|
+
formatDimText,
|
|
544
|
+
isRoot: true
|
|
545
|
+
});
|
|
546
|
+
const prefixedTreeLines = treeLines.map((line) => `${prefix}${line}`);
|
|
547
|
+
lines.push(...prefixedTreeLines);
|
|
548
|
+
if (isVerbose(flags, 1)) {
|
|
549
|
+
lines.push(`${prefix}${formatDimText(` Total time: ${result.timings.total}ms`)}`);
|
|
550
|
+
lines.push(
|
|
551
|
+
`${prefix}${formatDimText(` pass=${result.schema.counts.pass} warn=${result.schema.counts.warn} fail=${result.schema.counts.fail}`)}`
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
lines.push("");
|
|
555
|
+
if (result.ok) {
|
|
556
|
+
lines.push(`${prefix}${formatGreen("\u2714")} ${result.summary}`);
|
|
557
|
+
} else {
|
|
558
|
+
const codeText = result.code ? ` (${result.code})` : "";
|
|
559
|
+
lines.push(`${prefix}${formatRed("\u2716")} ${result.summary}${codeText}`);
|
|
560
|
+
}
|
|
561
|
+
return lines.join("\n");
|
|
562
|
+
}
|
|
563
|
+
function formatSchemaVerifyJson(result) {
|
|
564
|
+
return JSON.stringify(result, null, 2);
|
|
565
|
+
}
|
|
566
|
+
function formatSignOutput(result, flags) {
|
|
567
|
+
if (flags.quiet) {
|
|
568
|
+
return "";
|
|
569
|
+
}
|
|
570
|
+
const lines = [];
|
|
571
|
+
const prefix = createPrefix(flags);
|
|
572
|
+
const useColor = flags.color !== false;
|
|
573
|
+
const formatGreen = createColorFormatter(useColor, green);
|
|
574
|
+
const formatDimText = (text) => formatDim(useColor, text);
|
|
575
|
+
if (result.ok) {
|
|
576
|
+
lines.push(`${prefix}${formatGreen("\u2714")} Database signed`);
|
|
577
|
+
const previousHash = result.marker.previous?.coreHash ?? "none";
|
|
578
|
+
const currentHash = result.contract.coreHash;
|
|
579
|
+
lines.push(`${prefix}${formatDimText(` from: ${previousHash}`)}`);
|
|
580
|
+
lines.push(`${prefix}${formatDimText(` to: ${currentHash}`)}`);
|
|
581
|
+
if (isVerbose(flags, 1)) {
|
|
582
|
+
if (result.contract.profileHash) {
|
|
583
|
+
lines.push(`${prefix}${formatDimText(` profileHash: ${result.contract.profileHash}`)}`);
|
|
584
|
+
}
|
|
585
|
+
if (result.marker.previous?.profileHash) {
|
|
586
|
+
lines.push(
|
|
587
|
+
`${prefix}${formatDimText(` previous profileHash: ${result.marker.previous.profileHash}`)}`
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
lines.push(`${prefix}${formatDimText(` Total time: ${result.timings.total}ms`)}`);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return lines.join("\n");
|
|
594
|
+
}
|
|
595
|
+
function formatSignJson(result) {
|
|
596
|
+
return JSON.stringify(result, null, 2);
|
|
597
|
+
}
|
|
598
|
+
var LEFT_COLUMN_WIDTH = 20;
|
|
599
|
+
var RIGHT_COLUMN_MIN_WIDTH = 40;
|
|
600
|
+
var RIGHT_COLUMN_MAX_WIDTH = 90;
|
|
601
|
+
function getTerminalWidth() {
|
|
602
|
+
const terminalWidth = process.stdout.columns;
|
|
603
|
+
const defaultWidth = Number.parseInt(process.env["CLI_WIDTH"] || "80", 10);
|
|
604
|
+
return terminalWidth || defaultWidth;
|
|
605
|
+
}
|
|
606
|
+
function calculateRightColumnWidth() {
|
|
607
|
+
const terminalWidth = getTerminalWidth();
|
|
608
|
+
const availableWidth = terminalWidth - 2 - LEFT_COLUMN_WIDTH - 2;
|
|
609
|
+
return Math.max(RIGHT_COLUMN_MIN_WIDTH, Math.min(availableWidth, RIGHT_COLUMN_MAX_WIDTH));
|
|
610
|
+
}
|
|
611
|
+
function createPrismaNextBadge(useColor) {
|
|
612
|
+
if (!useColor) {
|
|
613
|
+
return "prisma-next";
|
|
614
|
+
}
|
|
615
|
+
const text = " prisma-next ";
|
|
616
|
+
const body = bgGreen(bold(text));
|
|
617
|
+
const separator = "\uE0B0";
|
|
618
|
+
const tip = green(separator);
|
|
619
|
+
return `${body}${tip}`;
|
|
620
|
+
}
|
|
621
|
+
function createPadFunction() {
|
|
622
|
+
return (s, w) => s + " ".repeat(Math.max(0, w - s.length));
|
|
623
|
+
}
|
|
624
|
+
function formatHeaderLine(options) {
|
|
625
|
+
if (options.operation) {
|
|
626
|
+
return `${options.brand} ${options.operation} \u2192 ${options.intent}`;
|
|
627
|
+
}
|
|
628
|
+
return `${options.brand} ${options.intent}`;
|
|
629
|
+
}
|
|
630
|
+
function formatReadMoreLine(options) {
|
|
631
|
+
const pad = createPadFunction();
|
|
632
|
+
const labelPadded = pad("Read more", options.maxLabelWidth);
|
|
633
|
+
const valueColored = options.useColor ? blue(options.url) : options.url;
|
|
634
|
+
return `${options.formatDimText("\u2502")} ${labelPadded} ${valueColored}`;
|
|
635
|
+
}
|
|
636
|
+
function padToFixedWidth(text, width) {
|
|
637
|
+
const actualWidth = stringWidth(text);
|
|
638
|
+
const padding = Math.max(0, width - actualWidth);
|
|
639
|
+
return text + " ".repeat(padding);
|
|
640
|
+
}
|
|
641
|
+
function wrapTextAnsi(text, width) {
|
|
642
|
+
const wrapped = wrapAnsi(text, width, { hard: false, trim: true });
|
|
643
|
+
return wrapped.split("\n");
|
|
644
|
+
}
|
|
645
|
+
function formatDefaultValue(value, useColor) {
|
|
646
|
+
const valueStr = String(value);
|
|
647
|
+
const defaultText = `default: ${valueStr}`;
|
|
648
|
+
return useColor ? dim(defaultText) : defaultText;
|
|
649
|
+
}
|
|
650
|
+
function renderCommandTree(options) {
|
|
651
|
+
const { commands, useColor, formatDimText, hasItemsAfter, continuationPrefix } = options;
|
|
652
|
+
const lines = [];
|
|
653
|
+
if (commands.length === 0) {
|
|
654
|
+
return lines;
|
|
655
|
+
}
|
|
656
|
+
for (let i = 0; i < commands.length; i++) {
|
|
657
|
+
const cmd = commands[i];
|
|
658
|
+
if (!cmd) continue;
|
|
659
|
+
const subcommands = cmd.commands.filter((subcmd) => !subcmd.name().startsWith("_"));
|
|
660
|
+
const isLastCommand = i === commands.length - 1;
|
|
661
|
+
if (subcommands.length > 0) {
|
|
662
|
+
const prefix = isLastCommand && !hasItemsAfter ? formatDimText("\u2514") : formatDimText("\u251C");
|
|
663
|
+
const treePrefix = `${prefix}\u2500 `;
|
|
664
|
+
const treePrefixWidth = stringWidth(stripAnsi(treePrefix));
|
|
665
|
+
const remainingWidth = LEFT_COLUMN_WIDTH - treePrefixWidth;
|
|
666
|
+
const commandNamePadded = padToFixedWidth(cmd.name(), remainingWidth);
|
|
667
|
+
const commandNameColored = useColor ? cyan(commandNamePadded) : commandNamePadded;
|
|
668
|
+
lines.push(`${formatDimText("\u2502")} ${treePrefix}${commandNameColored}`);
|
|
669
|
+
for (let j = 0; j < subcommands.length; j++) {
|
|
670
|
+
const subcmd = subcommands[j];
|
|
671
|
+
if (!subcmd) continue;
|
|
672
|
+
const isLastSubcommand = j === subcommands.length - 1;
|
|
673
|
+
const shortDescription = subcmd.description() || "";
|
|
674
|
+
const treeChar = isLastSubcommand ? "\u2514" : "\u251C";
|
|
675
|
+
const continuation = continuationPrefix ?? (isLastCommand && isLastSubcommand && !hasItemsAfter ? " " : formatDimText("\u2502"));
|
|
676
|
+
const continuationStr = continuation === " " ? " " : continuation;
|
|
677
|
+
const subTreePrefix = `${continuationStr} ${formatDimText(treeChar)}\u2500 `;
|
|
678
|
+
const subTreePrefixWidth = stringWidth(stripAnsi(subTreePrefix));
|
|
679
|
+
const subRemainingWidth = LEFT_COLUMN_WIDTH - subTreePrefixWidth;
|
|
680
|
+
const subcommandNamePadded = padToFixedWidth(subcmd.name(), subRemainingWidth);
|
|
681
|
+
const subcommandNameColored = useColor ? cyan(subcommandNamePadded) : subcommandNamePadded;
|
|
682
|
+
lines.push(
|
|
683
|
+
`${formatDimText("\u2502")} ${subTreePrefix}${subcommandNameColored} ${shortDescription}`
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
} else {
|
|
687
|
+
const prefix = isLastCommand && !hasItemsAfter ? formatDimText("\u2514") : formatDimText("\u251C");
|
|
688
|
+
const treePrefix = `${prefix}\u2500 `;
|
|
689
|
+
const treePrefixWidth = stringWidth(stripAnsi(treePrefix));
|
|
690
|
+
const remainingWidth = LEFT_COLUMN_WIDTH - treePrefixWidth;
|
|
691
|
+
const commandNamePadded = padToFixedWidth(cmd.name(), remainingWidth);
|
|
692
|
+
const commandNameColored = useColor ? cyan(commandNamePadded) : commandNamePadded;
|
|
693
|
+
const shortDescription = cmd.description() || "";
|
|
694
|
+
lines.push(`${formatDimText("\u2502")} ${treePrefix}${commandNameColored} ${shortDescription}`);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
return lines;
|
|
698
|
+
}
|
|
699
|
+
function formatMultilineDescription(options) {
|
|
700
|
+
const lines = [];
|
|
701
|
+
const formatGreen = (text) => options.useColor ? green(text) : text;
|
|
702
|
+
const rightColumnWidth = calculateRightColumnWidth();
|
|
703
|
+
const totalWidth = 2 + LEFT_COLUMN_WIDTH + 2 + rightColumnWidth;
|
|
704
|
+
const wrapWidth = totalWidth - 2;
|
|
705
|
+
for (const descLine of options.descriptionLines) {
|
|
706
|
+
const formattedLine = descLine.replace(/Prisma Next/g, (match) => formatGreen(match));
|
|
707
|
+
const wrappedLines = wrapTextAnsi(formattedLine, wrapWidth);
|
|
708
|
+
for (const wrappedLine of wrappedLines) {
|
|
709
|
+
lines.push(`${options.formatDimText("\u2502")} ${wrappedLine}`);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
return lines;
|
|
713
|
+
}
|
|
714
|
+
function formatStyledHeader(options) {
|
|
715
|
+
const lines = [];
|
|
716
|
+
const useColor = options.flags.color !== false;
|
|
717
|
+
const formatDimText = (text) => formatDim(useColor, text);
|
|
718
|
+
const brand = createPrismaNextBadge(useColor);
|
|
719
|
+
const operation = useColor ? bold(options.command) : options.command;
|
|
720
|
+
const intent = formatDimText(options.description);
|
|
721
|
+
lines.push(formatHeaderLine({ brand, operation, intent }));
|
|
722
|
+
lines.push(formatDimText("\u2502"));
|
|
723
|
+
for (const detail of options.details) {
|
|
724
|
+
const labelWithColon = `${detail.label}:`;
|
|
725
|
+
const labelPadded = padToFixedWidth(labelWithColon, LEFT_COLUMN_WIDTH);
|
|
726
|
+
const labelColored = useColor ? cyan(labelPadded) : labelPadded;
|
|
727
|
+
lines.push(`${formatDimText("\u2502")} ${labelColored} ${detail.value}`);
|
|
728
|
+
}
|
|
729
|
+
if (options.url) {
|
|
730
|
+
lines.push(formatDimText("\u2502"));
|
|
731
|
+
lines.push(
|
|
732
|
+
formatReadMoreLine({
|
|
733
|
+
url: options.url,
|
|
734
|
+
maxLabelWidth: LEFT_COLUMN_WIDTH,
|
|
735
|
+
useColor,
|
|
736
|
+
formatDimText
|
|
737
|
+
})
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
lines.push(formatDimText("\u2514"));
|
|
741
|
+
return `${lines.join("\n")}
|
|
742
|
+
`;
|
|
743
|
+
}
|
|
744
|
+
function formatSuccessMessage(flags) {
|
|
745
|
+
const useColor = flags.color !== false;
|
|
746
|
+
const formatGreen = createColorFormatter(useColor, green);
|
|
747
|
+
return `${formatGreen("\u2714")} Success`;
|
|
748
|
+
}
|
|
749
|
+
function getCommandDocsUrl(commandPath) {
|
|
750
|
+
const docsMap = {
|
|
751
|
+
"contract emit": "https://pris.ly/contract-emit",
|
|
752
|
+
"db verify": "https://pris.ly/db-verify"
|
|
753
|
+
};
|
|
754
|
+
return docsMap[commandPath];
|
|
755
|
+
}
|
|
756
|
+
function buildCommandPath(command) {
|
|
757
|
+
const parts = [];
|
|
758
|
+
let current = command;
|
|
759
|
+
while (current && current.name() !== "prisma-next") {
|
|
760
|
+
parts.unshift(current.name());
|
|
761
|
+
current = current.parent ?? void 0;
|
|
762
|
+
}
|
|
763
|
+
return parts.join(" ");
|
|
764
|
+
}
|
|
765
|
+
function formatCommandHelp(options) {
|
|
766
|
+
const { command, flags } = options;
|
|
767
|
+
const lines = [];
|
|
768
|
+
const useColor = flags.color !== false;
|
|
769
|
+
const formatDimText = (text) => formatDim(useColor, text);
|
|
770
|
+
const commandPath = buildCommandPath(command);
|
|
771
|
+
const shortDescription = command.description() || "";
|
|
772
|
+
const longDescription = getLongDescription(command);
|
|
773
|
+
const brand = createPrismaNextBadge(useColor);
|
|
774
|
+
const operation = useColor ? bold(commandPath) : commandPath;
|
|
775
|
+
const intent = formatDimText(shortDescription);
|
|
776
|
+
lines.push(formatHeaderLine({ brand, operation, intent }));
|
|
777
|
+
lines.push(formatDimText("\u2502"));
|
|
778
|
+
const optionsList = command.options.map((opt) => {
|
|
779
|
+
const flags2 = opt.flags;
|
|
780
|
+
const description = opt.description || "";
|
|
781
|
+
const defaultValue = opt.defaultValue;
|
|
782
|
+
return { flags: flags2, description, defaultValue };
|
|
783
|
+
});
|
|
784
|
+
const subcommands = command.commands.filter((cmd) => !cmd.name().startsWith("_"));
|
|
785
|
+
if (subcommands.length > 0) {
|
|
786
|
+
const hasItemsAfter = optionsList.length > 0;
|
|
787
|
+
const treeLines = renderCommandTree({
|
|
788
|
+
commands: subcommands,
|
|
789
|
+
useColor,
|
|
790
|
+
formatDimText,
|
|
791
|
+
hasItemsAfter
|
|
792
|
+
});
|
|
793
|
+
lines.push(...treeLines);
|
|
794
|
+
}
|
|
795
|
+
if (subcommands.length > 0 && optionsList.length > 0) {
|
|
796
|
+
lines.push(formatDimText("\u2502"));
|
|
797
|
+
}
|
|
798
|
+
if (optionsList.length > 0) {
|
|
799
|
+
for (const opt of optionsList) {
|
|
800
|
+
const flagsPadded = padToFixedWidth(opt.flags, LEFT_COLUMN_WIDTH);
|
|
801
|
+
let flagsColored = flagsPadded;
|
|
802
|
+
if (useColor) {
|
|
803
|
+
flagsColored = flagsPadded.replace(/(<[^>]+>)/g, (match) => magenta(match));
|
|
804
|
+
flagsColored = cyan(flagsColored);
|
|
805
|
+
}
|
|
806
|
+
const rightColumnWidth = calculateRightColumnWidth();
|
|
807
|
+
const wrappedDescription = wrapTextAnsi(opt.description, rightColumnWidth);
|
|
808
|
+
lines.push(`${formatDimText("\u2502")} ${flagsColored} ${wrappedDescription[0] || ""}`);
|
|
809
|
+
for (let i = 1; i < wrappedDescription.length; i++) {
|
|
810
|
+
const emptyLabel = " ".repeat(LEFT_COLUMN_WIDTH);
|
|
811
|
+
lines.push(`${formatDimText("\u2502")} ${emptyLabel} ${wrappedDescription[i] || ""}`);
|
|
812
|
+
}
|
|
813
|
+
if (opt.defaultValue !== void 0) {
|
|
814
|
+
const emptyLabel = " ".repeat(LEFT_COLUMN_WIDTH);
|
|
815
|
+
const defaultText = formatDefaultValue(opt.defaultValue, useColor);
|
|
816
|
+
lines.push(`${formatDimText("\u2502")} ${emptyLabel} ${defaultText}`);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
const docsUrl = getCommandDocsUrl(commandPath);
|
|
821
|
+
if (docsUrl) {
|
|
822
|
+
lines.push(formatDimText("\u2502"));
|
|
823
|
+
lines.push(
|
|
824
|
+
formatReadMoreLine({
|
|
825
|
+
url: docsUrl,
|
|
826
|
+
maxLabelWidth: LEFT_COLUMN_WIDTH,
|
|
827
|
+
useColor,
|
|
828
|
+
formatDimText
|
|
829
|
+
})
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
if (longDescription) {
|
|
833
|
+
lines.push(formatDimText("\u2502"));
|
|
834
|
+
const descriptionLines = longDescription.split("\n").filter((line) => line.trim().length > 0);
|
|
835
|
+
lines.push(...formatMultilineDescription({ descriptionLines, useColor, formatDimText }));
|
|
836
|
+
}
|
|
837
|
+
lines.push(formatDimText("\u2514"));
|
|
838
|
+
return `${lines.join("\n")}
|
|
839
|
+
`;
|
|
840
|
+
}
|
|
841
|
+
function formatRootHelp(options) {
|
|
842
|
+
const { program: program2, flags } = options;
|
|
843
|
+
const lines = [];
|
|
844
|
+
const useColor = flags.color !== false;
|
|
845
|
+
const formatDimText = (text) => formatDim(useColor, text);
|
|
846
|
+
const brand = createPrismaNextBadge(useColor);
|
|
847
|
+
const shortDescription = "Manage your data layer";
|
|
848
|
+
const intent = formatDimText(shortDescription);
|
|
849
|
+
lines.push(formatHeaderLine({ brand, operation: "", intent }));
|
|
850
|
+
lines.push(formatDimText("\u2502"));
|
|
851
|
+
const topLevelCommands = program2.commands.filter(
|
|
852
|
+
(cmd) => !cmd.name().startsWith("_") && cmd.name() !== "help"
|
|
853
|
+
);
|
|
854
|
+
const globalOptions = program2.options.map((opt) => {
|
|
855
|
+
const flags2 = opt.flags;
|
|
856
|
+
const description = opt.description || "";
|
|
857
|
+
const defaultValue = opt.defaultValue;
|
|
858
|
+
return { flags: flags2, description, defaultValue };
|
|
859
|
+
});
|
|
860
|
+
if (topLevelCommands.length > 0) {
|
|
861
|
+
const hasItemsAfter = globalOptions.length > 0;
|
|
862
|
+
const treeLines = renderCommandTree({
|
|
863
|
+
commands: topLevelCommands,
|
|
864
|
+
useColor,
|
|
865
|
+
formatDimText,
|
|
866
|
+
hasItemsAfter
|
|
867
|
+
});
|
|
868
|
+
lines.push(...treeLines);
|
|
869
|
+
}
|
|
870
|
+
if (topLevelCommands.length > 0 && globalOptions.length > 0) {
|
|
871
|
+
lines.push(formatDimText("\u2502"));
|
|
872
|
+
}
|
|
873
|
+
if (globalOptions.length > 0) {
|
|
874
|
+
for (const opt of globalOptions) {
|
|
875
|
+
const flagsPadded = padToFixedWidth(opt.flags, LEFT_COLUMN_WIDTH);
|
|
876
|
+
let flagsColored = flagsPadded;
|
|
877
|
+
if (useColor) {
|
|
878
|
+
flagsColored = flagsPadded.replace(/(<[^>]+>)/g, (match) => magenta(match));
|
|
879
|
+
flagsColored = cyan(flagsColored);
|
|
880
|
+
}
|
|
881
|
+
const rightColumnWidth = calculateRightColumnWidth();
|
|
882
|
+
const wrappedDescription = wrapTextAnsi(opt.description, rightColumnWidth);
|
|
883
|
+
lines.push(`${formatDimText("\u2502")} ${flagsColored} ${wrappedDescription[0] || ""}`);
|
|
884
|
+
for (let i = 1; i < wrappedDescription.length; i++) {
|
|
885
|
+
const emptyLabel = " ".repeat(LEFT_COLUMN_WIDTH);
|
|
886
|
+
lines.push(`${formatDimText("\u2502")} ${emptyLabel} ${wrappedDescription[i] || ""}`);
|
|
887
|
+
}
|
|
888
|
+
if (opt.defaultValue !== void 0) {
|
|
889
|
+
const emptyLabel = " ".repeat(LEFT_COLUMN_WIDTH);
|
|
890
|
+
const defaultText = formatDefaultValue(opt.defaultValue, useColor);
|
|
891
|
+
lines.push(`${formatDimText("\u2502")} ${emptyLabel} ${defaultText}`);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
const formatGreen = (text) => useColor ? green(text) : text;
|
|
896
|
+
const descriptionLines = [
|
|
897
|
+
`Use ${formatGreen("Prisma Next")} to define your data layer as a contract. Sign your database and application with the same contract to guarantee compatibility. Plan and apply migrations to safely evolve your schema.`
|
|
898
|
+
];
|
|
899
|
+
if (descriptionLines.length > 0) {
|
|
900
|
+
lines.push(formatDimText("\u2502"));
|
|
901
|
+
lines.push(...formatMultilineDescription({ descriptionLines, useColor, formatDimText }));
|
|
902
|
+
}
|
|
903
|
+
lines.push(formatDimText("\u2514"));
|
|
904
|
+
return `${lines.join("\n")}
|
|
905
|
+
`;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// src/utils/cli-errors.ts
|
|
909
|
+
import {
|
|
910
|
+
CliStructuredError,
|
|
911
|
+
errorConfigFileNotFound as errorConfigFileNotFound2,
|
|
912
|
+
errorConfigValidation,
|
|
913
|
+
errorContractConfigMissing,
|
|
914
|
+
errorContractValidationFailed,
|
|
915
|
+
errorDatabaseUrlRequired,
|
|
916
|
+
errorDriverRequired,
|
|
917
|
+
errorFamilyReadMarkerSqlRequired,
|
|
918
|
+
errorFileNotFound,
|
|
919
|
+
errorHashMismatch,
|
|
920
|
+
errorMarkerMissing,
|
|
921
|
+
errorQueryRunnerFactoryRequired,
|
|
922
|
+
errorRuntime,
|
|
923
|
+
errorTargetMismatch,
|
|
924
|
+
errorUnexpected as errorUnexpected2
|
|
925
|
+
} from "@prisma-next/core-control-plane/errors";
|
|
926
|
+
|
|
927
|
+
// src/utils/result.ts
|
|
928
|
+
function ok(value) {
|
|
929
|
+
return { ok: true, value };
|
|
930
|
+
}
|
|
931
|
+
function err(error) {
|
|
932
|
+
return { ok: false, error };
|
|
933
|
+
}
|
|
934
|
+
async function performAction(fn) {
|
|
935
|
+
try {
|
|
936
|
+
const value = await fn();
|
|
937
|
+
return ok(value);
|
|
938
|
+
} catch (error) {
|
|
939
|
+
if (error instanceof CliStructuredError) {
|
|
940
|
+
return err(error);
|
|
941
|
+
}
|
|
942
|
+
throw error;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// src/utils/result-handler.ts
|
|
947
|
+
function handleResult(result, flags, onSuccess) {
|
|
948
|
+
if (result.ok) {
|
|
949
|
+
if (onSuccess) {
|
|
950
|
+
onSuccess(result.value);
|
|
951
|
+
}
|
|
952
|
+
return 0;
|
|
953
|
+
}
|
|
954
|
+
const envelope = result.error.toEnvelope();
|
|
955
|
+
if (flags.json === "object") {
|
|
956
|
+
console.error(formatErrorJson(envelope));
|
|
957
|
+
} else {
|
|
958
|
+
console.error(formatErrorOutput(envelope, flags));
|
|
959
|
+
}
|
|
960
|
+
const exitCode = result.error.domain === "CLI" ? 2 : 1;
|
|
961
|
+
return exitCode;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
// src/utils/spinner.ts
|
|
965
|
+
import ora from "ora";
|
|
966
|
+
async function withSpinner(operation, options) {
|
|
967
|
+
const { message, flags, delayThreshold = 100 } = options;
|
|
968
|
+
const shouldShowSpinner = !flags.quiet && flags.json !== "object" && process.stdout.isTTY;
|
|
969
|
+
if (!shouldShowSpinner) {
|
|
970
|
+
return operation();
|
|
971
|
+
}
|
|
972
|
+
const startTime = Date.now();
|
|
973
|
+
let spinner = null;
|
|
974
|
+
let timeoutId = null;
|
|
975
|
+
let operationCompleted = false;
|
|
976
|
+
timeoutId = setTimeout(() => {
|
|
977
|
+
if (!operationCompleted) {
|
|
978
|
+
spinner = ora({
|
|
979
|
+
text: message,
|
|
980
|
+
color: flags.color !== false ? "cyan" : false
|
|
981
|
+
}).start();
|
|
982
|
+
}
|
|
983
|
+
}, delayThreshold);
|
|
984
|
+
try {
|
|
985
|
+
const result = await operation();
|
|
986
|
+
operationCompleted = true;
|
|
987
|
+
if (timeoutId) {
|
|
988
|
+
clearTimeout(timeoutId);
|
|
989
|
+
timeoutId = null;
|
|
990
|
+
}
|
|
991
|
+
if (spinner !== null) {
|
|
992
|
+
const elapsed = Date.now() - startTime;
|
|
993
|
+
spinner.succeed(`${message} (${elapsed}ms)`);
|
|
994
|
+
}
|
|
995
|
+
return result;
|
|
996
|
+
} catch (error) {
|
|
997
|
+
operationCompleted = true;
|
|
998
|
+
if (timeoutId) {
|
|
999
|
+
clearTimeout(timeoutId);
|
|
1000
|
+
timeoutId = null;
|
|
1001
|
+
}
|
|
1002
|
+
if (spinner !== null) {
|
|
1003
|
+
spinner.fail(
|
|
1004
|
+
`${message} failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
throw error;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// src/commands/contract-emit.ts
|
|
1012
|
+
function createContractEmitCommand() {
|
|
1013
|
+
const command = new Command("emit");
|
|
1014
|
+
setCommandDescriptions(
|
|
1015
|
+
command,
|
|
1016
|
+
"Write your contract to JSON and sign it",
|
|
1017
|
+
"Reads your contract source (TypeScript or Prisma schema) and emits contract.json and\ncontract.d.ts. The contract.json contains the canonical contract structure, and\ncontract.d.ts provides TypeScript types for type-safe query building."
|
|
1018
|
+
);
|
|
1019
|
+
command.configureHelp({
|
|
1020
|
+
formatHelp: (cmd) => {
|
|
1021
|
+
const flags = parseGlobalFlags({});
|
|
1022
|
+
return formatCommandHelp({ command: cmd, flags });
|
|
1023
|
+
}
|
|
1024
|
+
}).option("--config <path>", "Path to prisma-next.config.ts").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) => {
|
|
1025
|
+
const flags = parseGlobalFlags(options);
|
|
1026
|
+
const result = await performAction(async () => {
|
|
1027
|
+
const config = await loadConfig(options.config);
|
|
1028
|
+
if (!config.contract) {
|
|
1029
|
+
throw errorContractConfigMissing2({
|
|
1030
|
+
why: "Config.contract is required for emit. Define it in your config: contract: { source: ..., output: ..., types: ... }"
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
const contractConfig = config.contract;
|
|
1034
|
+
if (!contractConfig.output || !contractConfig.types) {
|
|
1035
|
+
throw errorContractConfigMissing2({
|
|
1036
|
+
why: "Contract config must have output and types paths. This should not happen if defineConfig() was used."
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
const outputJsonPath = resolve2(contractConfig.output);
|
|
1040
|
+
const outputDtsPath = resolve2(contractConfig.types);
|
|
1041
|
+
if (flags.json !== "object" && !flags.quiet) {
|
|
1042
|
+
const configPath = options.config ? relative2(process.cwd(), resolve2(options.config)) : "prisma-next.config.ts";
|
|
1043
|
+
const contractPath = relative2(process.cwd(), outputJsonPath);
|
|
1044
|
+
const typesPath = relative2(process.cwd(), outputDtsPath);
|
|
1045
|
+
const header = formatStyledHeader({
|
|
1046
|
+
command: "contract emit",
|
|
1047
|
+
description: "Write your contract to JSON and sign it",
|
|
1048
|
+
url: "https://pris.ly/contract-emit",
|
|
1049
|
+
details: [
|
|
1050
|
+
{ label: "config", value: configPath },
|
|
1051
|
+
{ label: "contract", value: contractPath },
|
|
1052
|
+
{ label: "types", value: typesPath }
|
|
1053
|
+
],
|
|
1054
|
+
flags
|
|
1055
|
+
});
|
|
1056
|
+
console.log(header);
|
|
1057
|
+
}
|
|
1058
|
+
if (!config.driver) {
|
|
1059
|
+
throw errorContractConfigMissing2({
|
|
1060
|
+
why: "Config.driver is required. Even though emit does not use the driver, it is required by ControlFamilyDescriptor.create()"
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
const familyInstance = config.family.create({
|
|
1064
|
+
target: config.target,
|
|
1065
|
+
adapter: config.adapter,
|
|
1066
|
+
driver: config.driver,
|
|
1067
|
+
extensions: config.extensions ?? []
|
|
1068
|
+
});
|
|
1069
|
+
let contractRaw;
|
|
1070
|
+
if (typeof contractConfig.source === "function") {
|
|
1071
|
+
contractRaw = await contractConfig.source();
|
|
1072
|
+
} else {
|
|
1073
|
+
contractRaw = contractConfig.source;
|
|
1074
|
+
}
|
|
1075
|
+
const emitResult = await withSpinner(
|
|
1076
|
+
() => familyInstance.emitContract({ contractIR: contractRaw }),
|
|
1077
|
+
{
|
|
1078
|
+
message: "Emitting contract...",
|
|
1079
|
+
flags
|
|
1080
|
+
}
|
|
1081
|
+
);
|
|
1082
|
+
mkdirSync(dirname2(outputJsonPath), { recursive: true });
|
|
1083
|
+
mkdirSync(dirname2(outputDtsPath), { recursive: true });
|
|
1084
|
+
writeFileSync(outputJsonPath, emitResult.contractJson, "utf-8");
|
|
1085
|
+
writeFileSync(outputDtsPath, emitResult.contractDts, "utf-8");
|
|
1086
|
+
if (!flags.quiet && flags.json !== "object" && process.stdout.isTTY) {
|
|
1087
|
+
console.log("");
|
|
1088
|
+
}
|
|
1089
|
+
return {
|
|
1090
|
+
coreHash: emitResult.coreHash,
|
|
1091
|
+
profileHash: emitResult.profileHash,
|
|
1092
|
+
outDir: dirname2(outputJsonPath),
|
|
1093
|
+
files: {
|
|
1094
|
+
json: outputJsonPath,
|
|
1095
|
+
dts: outputDtsPath
|
|
1096
|
+
},
|
|
1097
|
+
timings: {
|
|
1098
|
+
total: 0
|
|
1099
|
+
// Timing is handled by emitContract internally if needed
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
});
|
|
1103
|
+
const exitCode = handleResult(result, flags, (emitResult) => {
|
|
1104
|
+
if (flags.json === "object") {
|
|
1105
|
+
console.log(formatEmitJson(emitResult));
|
|
1106
|
+
} else {
|
|
1107
|
+
const output = formatEmitOutput(emitResult, flags);
|
|
1108
|
+
if (output) {
|
|
1109
|
+
console.log(output);
|
|
1110
|
+
}
|
|
1111
|
+
if (!flags.quiet) {
|
|
1112
|
+
console.log(formatSuccessMessage(flags));
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
process.exit(exitCode);
|
|
1117
|
+
});
|
|
1118
|
+
return command;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// src/commands/db-introspect.ts
|
|
1122
|
+
import { readFile } from "fs/promises";
|
|
1123
|
+
import { relative as relative3, resolve as resolve3 } from "path";
|
|
1124
|
+
import {
|
|
1125
|
+
errorDatabaseUrlRequired as errorDatabaseUrlRequired2,
|
|
1126
|
+
errorDriverRequired as errorDriverRequired2,
|
|
1127
|
+
errorRuntime as errorRuntime2,
|
|
1128
|
+
errorUnexpected as errorUnexpected3
|
|
1129
|
+
} from "@prisma-next/core-control-plane/errors";
|
|
1130
|
+
import { Command as Command2 } from "commander";
|
|
1131
|
+
function createDbIntrospectCommand() {
|
|
1132
|
+
const command = new Command2("introspect");
|
|
1133
|
+
setCommandDescriptions(
|
|
1134
|
+
command,
|
|
1135
|
+
"Inspect the database schema",
|
|
1136
|
+
"Reads the live database schema and displays it as a tree structure. This command\ndoes not check the schema against your contract - it only shows what exists in\nthe database. Use `db verify` or `db schema-verify` to compare against your contract."
|
|
1137
|
+
);
|
|
1138
|
+
command.configureHelp({
|
|
1139
|
+
formatHelp: (cmd) => {
|
|
1140
|
+
const flags = parseGlobalFlags({});
|
|
1141
|
+
return formatCommandHelp({ command: cmd, flags });
|
|
1142
|
+
}
|
|
1143
|
+
}).option("--db <url>", "Database connection string").option("--config <path>", "Path to prisma-next.config.ts").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) => {
|
|
1144
|
+
const flags = parseGlobalFlags(options);
|
|
1145
|
+
const result = await performAction(async () => {
|
|
1146
|
+
const startTime = Date.now();
|
|
1147
|
+
const config = await loadConfig(options.config);
|
|
1148
|
+
const configPath = options.config ? relative3(process.cwd(), resolve3(options.config)) : "prisma-next.config.ts";
|
|
1149
|
+
let contractIR;
|
|
1150
|
+
if (config.contract?.output) {
|
|
1151
|
+
const contractPath = resolve3(config.contract.output);
|
|
1152
|
+
try {
|
|
1153
|
+
const contractJsonContent = await readFile(contractPath, "utf-8");
|
|
1154
|
+
const contractJson = JSON.parse(contractJsonContent);
|
|
1155
|
+
contractIR = contractJson;
|
|
1156
|
+
} catch (error) {
|
|
1157
|
+
if (error instanceof Error && error.code !== "ENOENT") {
|
|
1158
|
+
throw errorUnexpected3(error.message, {
|
|
1159
|
+
why: `Failed to read contract file: ${error.message}`
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
if (flags.json !== "object" && !flags.quiet) {
|
|
1165
|
+
const details = [
|
|
1166
|
+
{ label: "config", value: configPath }
|
|
1167
|
+
];
|
|
1168
|
+
if (options.db) {
|
|
1169
|
+
const maskedUrl = options.db.replace(/:([^:@]+)@/, ":****@");
|
|
1170
|
+
details.push({ label: "database", value: maskedUrl });
|
|
1171
|
+
} else if (config.db?.url) {
|
|
1172
|
+
const maskedUrl = config.db.url.replace(/:([^:@]+)@/, ":****@");
|
|
1173
|
+
details.push({ label: "database", value: maskedUrl });
|
|
1174
|
+
}
|
|
1175
|
+
const header = formatStyledHeader({
|
|
1176
|
+
command: "db introspect",
|
|
1177
|
+
description: "Inspect the database schema",
|
|
1178
|
+
url: "https://pris.ly/db-introspect",
|
|
1179
|
+
details,
|
|
1180
|
+
flags
|
|
1181
|
+
});
|
|
1182
|
+
console.log(header);
|
|
1183
|
+
}
|
|
1184
|
+
const dbUrl = options.db ?? config.db?.url;
|
|
1185
|
+
if (!dbUrl) {
|
|
1186
|
+
throw errorDatabaseUrlRequired2();
|
|
1187
|
+
}
|
|
1188
|
+
if (!config.driver) {
|
|
1189
|
+
throw errorDriverRequired2();
|
|
1190
|
+
}
|
|
1191
|
+
const driverDescriptor = config.driver;
|
|
1192
|
+
const driver = await withSpinner(() => driverDescriptor.create(dbUrl), {
|
|
1193
|
+
message: "Connecting to database...",
|
|
1194
|
+
flags
|
|
1195
|
+
});
|
|
1196
|
+
try {
|
|
1197
|
+
const familyInstance = config.family.create({
|
|
1198
|
+
target: config.target,
|
|
1199
|
+
adapter: config.adapter,
|
|
1200
|
+
driver: driverDescriptor,
|
|
1201
|
+
extensions: config.extensions ?? []
|
|
1202
|
+
});
|
|
1203
|
+
const typedFamilyInstance = familyInstance;
|
|
1204
|
+
if (contractIR) {
|
|
1205
|
+
contractIR = typedFamilyInstance.validateContractIR(contractIR);
|
|
1206
|
+
}
|
|
1207
|
+
let schemaIR;
|
|
1208
|
+
try {
|
|
1209
|
+
schemaIR = await withSpinner(
|
|
1210
|
+
() => typedFamilyInstance.introspect({
|
|
1211
|
+
driver,
|
|
1212
|
+
contractIR
|
|
1213
|
+
}),
|
|
1214
|
+
{
|
|
1215
|
+
message: "Introspecting database schema...",
|
|
1216
|
+
flags
|
|
1217
|
+
}
|
|
1218
|
+
);
|
|
1219
|
+
} catch (error) {
|
|
1220
|
+
throw errorRuntime2(error instanceof Error ? error.message : String(error), {
|
|
1221
|
+
why: `Failed to introspect database: ${error instanceof Error ? error.message : String(error)}`
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
let schemaView;
|
|
1225
|
+
if (typedFamilyInstance.toSchemaView) {
|
|
1226
|
+
try {
|
|
1227
|
+
schemaView = typedFamilyInstance.toSchemaView(schemaIR);
|
|
1228
|
+
} catch (error) {
|
|
1229
|
+
if (flags.verbose) {
|
|
1230
|
+
console.error(
|
|
1231
|
+
`Warning: Failed to project schema to view: ${error instanceof Error ? error.message : String(error)}`
|
|
1232
|
+
);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
const totalTime = Date.now() - startTime;
|
|
1237
|
+
if (!flags.quiet && flags.json !== "object" && process.stdout.isTTY) {
|
|
1238
|
+
console.log("");
|
|
1239
|
+
}
|
|
1240
|
+
const introspectResult = {
|
|
1241
|
+
ok: true,
|
|
1242
|
+
summary: "Schema introspected successfully",
|
|
1243
|
+
target: {
|
|
1244
|
+
familyId: config.family.familyId,
|
|
1245
|
+
id: config.target.targetId
|
|
1246
|
+
},
|
|
1247
|
+
schema: schemaIR,
|
|
1248
|
+
...configPath || options.db || config.db?.url ? {
|
|
1249
|
+
meta: {
|
|
1250
|
+
...configPath ? { configPath } : {},
|
|
1251
|
+
...options.db || config.db?.url ? {
|
|
1252
|
+
dbUrl: (options.db ?? config.db?.url ?? "").replace(
|
|
1253
|
+
/:([^:@]+)@/,
|
|
1254
|
+
":****@"
|
|
1255
|
+
)
|
|
1256
|
+
} : {}
|
|
1257
|
+
}
|
|
1258
|
+
} : {},
|
|
1259
|
+
timings: {
|
|
1260
|
+
total: totalTime
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1263
|
+
return { introspectResult, schemaView };
|
|
1264
|
+
} finally {
|
|
1265
|
+
await driver.close();
|
|
1266
|
+
}
|
|
1267
|
+
});
|
|
1268
|
+
const exitCode = handleResult(result, flags, (value) => {
|
|
1269
|
+
const { introspectResult, schemaView } = value;
|
|
1270
|
+
if (flags.json === "object") {
|
|
1271
|
+
console.log(formatIntrospectJson(introspectResult));
|
|
1272
|
+
} else {
|
|
1273
|
+
const output = formatIntrospectOutput(introspectResult, schemaView, flags);
|
|
1274
|
+
if (output) {
|
|
1275
|
+
console.log(output);
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
});
|
|
1279
|
+
process.exit(exitCode);
|
|
1280
|
+
});
|
|
1281
|
+
return command;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
// src/commands/db-schema-verify.ts
|
|
1285
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
1286
|
+
import { relative as relative4, resolve as resolve4 } from "path";
|
|
1287
|
+
import {
|
|
1288
|
+
errorDatabaseUrlRequired as errorDatabaseUrlRequired3,
|
|
1289
|
+
errorDriverRequired as errorDriverRequired3,
|
|
1290
|
+
errorFileNotFound as errorFileNotFound2,
|
|
1291
|
+
errorRuntime as errorRuntime3,
|
|
1292
|
+
errorUnexpected as errorUnexpected4
|
|
1293
|
+
} from "@prisma-next/core-control-plane/errors";
|
|
1294
|
+
import { Command as Command3 } from "commander";
|
|
1295
|
+
function createDbSchemaVerifyCommand() {
|
|
1296
|
+
const command = new Command3("schema-verify");
|
|
1297
|
+
setCommandDescriptions(
|
|
1298
|
+
command,
|
|
1299
|
+
"Check whether the database schema satisfies your contract",
|
|
1300
|
+
"Verifies that your database schema satisfies the emitted contract. Compares table structures,\ncolumn types, constraints, and extensions. Reports any mismatches via a contract-shaped\nverification tree. This is a read-only operation that does not modify the database."
|
|
1301
|
+
);
|
|
1302
|
+
command.configureHelp({
|
|
1303
|
+
formatHelp: (cmd) => {
|
|
1304
|
+
const flags = parseGlobalFlags({});
|
|
1305
|
+
return formatCommandHelp({ command: cmd, flags });
|
|
1306
|
+
}
|
|
1307
|
+
}).option("--db <url>", "Database connection string").option("--config <path>", "Path to prisma-next.config.ts").option("--json [format]", "Output as JSON (object or ndjson)", false).option("--strict", "Strict mode: extra schema elements cause failures", 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) => {
|
|
1308
|
+
const flags = parseGlobalFlags(options);
|
|
1309
|
+
const result = await performAction(async () => {
|
|
1310
|
+
const config = await loadConfig(options.config);
|
|
1311
|
+
const configPath = options.config ? relative4(process.cwd(), resolve4(options.config)) : "prisma-next.config.ts";
|
|
1312
|
+
const contractPathAbsolute = config.contract?.output ? resolve4(config.contract.output) : resolve4("src/prisma/contract.json");
|
|
1313
|
+
const contractPath = relative4(process.cwd(), contractPathAbsolute);
|
|
1314
|
+
if (flags.json !== "object" && !flags.quiet) {
|
|
1315
|
+
const details = [
|
|
1316
|
+
{ label: "config", value: configPath },
|
|
1317
|
+
{ label: "contract", value: contractPath }
|
|
1318
|
+
];
|
|
1319
|
+
if (options.db) {
|
|
1320
|
+
details.push({ label: "database", value: options.db });
|
|
1321
|
+
}
|
|
1322
|
+
const header = formatStyledHeader({
|
|
1323
|
+
command: "db schema-verify",
|
|
1324
|
+
description: "Check whether the database schema satisfies your contract",
|
|
1325
|
+
url: "https://pris.ly/db-schema-verify",
|
|
1326
|
+
details,
|
|
1327
|
+
flags
|
|
1328
|
+
});
|
|
1329
|
+
console.log(header);
|
|
1330
|
+
}
|
|
1331
|
+
let contractJsonContent;
|
|
1332
|
+
try {
|
|
1333
|
+
contractJsonContent = await readFile2(contractPathAbsolute, "utf-8");
|
|
1334
|
+
} catch (error) {
|
|
1335
|
+
if (error instanceof Error && error.code === "ENOENT") {
|
|
1336
|
+
throw errorFileNotFound2(contractPathAbsolute, {
|
|
1337
|
+
why: `Contract file not found at ${contractPathAbsolute}`
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
throw errorUnexpected4(error instanceof Error ? error.message : String(error), {
|
|
1341
|
+
why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
const contractJson = JSON.parse(contractJsonContent);
|
|
1345
|
+
const dbUrl = options.db ?? config.db?.url;
|
|
1346
|
+
if (!dbUrl) {
|
|
1347
|
+
throw errorDatabaseUrlRequired3();
|
|
1348
|
+
}
|
|
1349
|
+
if (!config.driver) {
|
|
1350
|
+
throw errorDriverRequired3();
|
|
1351
|
+
}
|
|
1352
|
+
const driverDescriptor = config.driver;
|
|
1353
|
+
const driver = await withSpinner(() => driverDescriptor.create(dbUrl), {
|
|
1354
|
+
message: "Connecting to database...",
|
|
1355
|
+
flags
|
|
1356
|
+
});
|
|
1357
|
+
try {
|
|
1358
|
+
const familyInstance = config.family.create({
|
|
1359
|
+
target: config.target,
|
|
1360
|
+
adapter: config.adapter,
|
|
1361
|
+
driver: driverDescriptor,
|
|
1362
|
+
extensions: config.extensions ?? []
|
|
1363
|
+
});
|
|
1364
|
+
const typedFamilyInstance = familyInstance;
|
|
1365
|
+
const contractIR = typedFamilyInstance.validateContractIR(contractJson);
|
|
1366
|
+
let schemaVerifyResult;
|
|
1367
|
+
try {
|
|
1368
|
+
schemaVerifyResult = await withSpinner(
|
|
1369
|
+
() => typedFamilyInstance.schemaVerify({
|
|
1370
|
+
driver,
|
|
1371
|
+
contractIR,
|
|
1372
|
+
strict: options.strict ?? false,
|
|
1373
|
+
contractPath: contractPathAbsolute,
|
|
1374
|
+
configPath
|
|
1375
|
+
}),
|
|
1376
|
+
{
|
|
1377
|
+
message: "Verifying database schema...",
|
|
1378
|
+
flags
|
|
1379
|
+
}
|
|
1380
|
+
);
|
|
1381
|
+
} catch (error) {
|
|
1382
|
+
throw errorRuntime3(error instanceof Error ? error.message : String(error), {
|
|
1383
|
+
why: `Failed to verify database schema: ${error instanceof Error ? error.message : String(error)}`
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
if (!flags.quiet && flags.json !== "object" && process.stdout.isTTY) {
|
|
1387
|
+
console.log("");
|
|
1388
|
+
}
|
|
1389
|
+
return schemaVerifyResult;
|
|
1390
|
+
} finally {
|
|
1391
|
+
await driver.close();
|
|
1392
|
+
}
|
|
1393
|
+
});
|
|
1394
|
+
const exitCode = handleResult(result, flags, (schemaVerifyResult) => {
|
|
1395
|
+
if (flags.json === "object") {
|
|
1396
|
+
console.log(formatSchemaVerifyJson(schemaVerifyResult));
|
|
1397
|
+
} else {
|
|
1398
|
+
const output = formatSchemaVerifyOutput(schemaVerifyResult, flags);
|
|
1399
|
+
if (output) {
|
|
1400
|
+
console.log(output);
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
if (result.ok && !result.value.ok) {
|
|
1405
|
+
process.exit(1);
|
|
1406
|
+
} else {
|
|
1407
|
+
process.exit(exitCode);
|
|
1408
|
+
}
|
|
1409
|
+
});
|
|
1410
|
+
return command;
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
// src/commands/db-sign.ts
|
|
1414
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
1415
|
+
import { relative as relative5, resolve as resolve5 } from "path";
|
|
1416
|
+
import {
|
|
1417
|
+
errorDatabaseUrlRequired as errorDatabaseUrlRequired4,
|
|
1418
|
+
errorDriverRequired as errorDriverRequired4,
|
|
1419
|
+
errorFileNotFound as errorFileNotFound3,
|
|
1420
|
+
errorRuntime as errorRuntime4,
|
|
1421
|
+
errorUnexpected as errorUnexpected5
|
|
1422
|
+
} from "@prisma-next/core-control-plane/errors";
|
|
1423
|
+
import { Command as Command4 } from "commander";
|
|
1424
|
+
function createDbSignCommand() {
|
|
1425
|
+
const command = new Command4("sign");
|
|
1426
|
+
setCommandDescriptions(
|
|
1427
|
+
command,
|
|
1428
|
+
"Sign the database with your contract so you can safely run queries",
|
|
1429
|
+
"Verifies that your database schema satisfies the emitted contract, and if so, writes or\nupdates the contract marker in the database. This command is idempotent and safe to run\nin CI/deployment pipelines. The marker records that this database instance is aligned\nwith a specific contract version."
|
|
1430
|
+
);
|
|
1431
|
+
command.configureHelp({
|
|
1432
|
+
formatHelp: (cmd) => {
|
|
1433
|
+
const flags = parseGlobalFlags({});
|
|
1434
|
+
return formatCommandHelp({ command: cmd, flags });
|
|
1435
|
+
}
|
|
1436
|
+
}).option("--db <url>", "Database connection string").option("--config <path>", "Path to prisma-next.config.ts").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) => {
|
|
1437
|
+
const flags = parseGlobalFlags(options);
|
|
1438
|
+
const result = await performAction(async () => {
|
|
1439
|
+
const config = await loadConfig(options.config);
|
|
1440
|
+
const configPath = options.config ? relative5(process.cwd(), resolve5(options.config)) : "prisma-next.config.ts";
|
|
1441
|
+
const contractPathAbsolute = config.contract?.output ? resolve5(config.contract.output) : resolve5("src/prisma/contract.json");
|
|
1442
|
+
const contractPath = relative5(process.cwd(), contractPathAbsolute);
|
|
1443
|
+
if (flags.json !== "object" && !flags.quiet) {
|
|
1444
|
+
const details = [
|
|
1445
|
+
{ label: "config", value: configPath },
|
|
1446
|
+
{ label: "contract", value: contractPath }
|
|
1447
|
+
];
|
|
1448
|
+
if (options.db) {
|
|
1449
|
+
details.push({ label: "database", value: options.db });
|
|
1450
|
+
}
|
|
1451
|
+
const header = formatStyledHeader({
|
|
1452
|
+
command: "db sign",
|
|
1453
|
+
description: "Sign the database with your contract so you can safely run queries",
|
|
1454
|
+
url: "https://pris.ly/db-sign",
|
|
1455
|
+
details,
|
|
1456
|
+
flags
|
|
1457
|
+
});
|
|
1458
|
+
console.log(header);
|
|
1459
|
+
}
|
|
1460
|
+
let contractJsonContent;
|
|
1461
|
+
try {
|
|
1462
|
+
contractJsonContent = await readFile3(contractPathAbsolute, "utf-8");
|
|
1463
|
+
} catch (error) {
|
|
1464
|
+
if (error instanceof Error && error.code === "ENOENT") {
|
|
1465
|
+
throw errorFileNotFound3(contractPathAbsolute, {
|
|
1466
|
+
why: `Contract file not found at ${contractPathAbsolute}`
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
throw errorUnexpected5(error instanceof Error ? error.message : String(error), {
|
|
1470
|
+
why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`
|
|
1471
|
+
});
|
|
1472
|
+
}
|
|
1473
|
+
const contractJson = JSON.parse(contractJsonContent);
|
|
1474
|
+
const dbUrl = options.db ?? config.db?.url;
|
|
1475
|
+
if (!dbUrl) {
|
|
1476
|
+
throw errorDatabaseUrlRequired4();
|
|
1477
|
+
}
|
|
1478
|
+
if (!config.driver) {
|
|
1479
|
+
throw errorDriverRequired4();
|
|
1480
|
+
}
|
|
1481
|
+
const driverDescriptor = config.driver;
|
|
1482
|
+
const driver = await driverDescriptor.create(dbUrl);
|
|
1483
|
+
try {
|
|
1484
|
+
const familyInstance = config.family.create({
|
|
1485
|
+
target: config.target,
|
|
1486
|
+
adapter: config.adapter,
|
|
1487
|
+
driver: driverDescriptor,
|
|
1488
|
+
extensions: config.extensions ?? []
|
|
1489
|
+
});
|
|
1490
|
+
const typedFamilyInstance = familyInstance;
|
|
1491
|
+
const contractIR = typedFamilyInstance.validateContractIR(contractJson);
|
|
1492
|
+
let schemaVerifyResult;
|
|
1493
|
+
try {
|
|
1494
|
+
schemaVerifyResult = await withSpinner(
|
|
1495
|
+
async () => {
|
|
1496
|
+
return await typedFamilyInstance.schemaVerify({
|
|
1497
|
+
driver,
|
|
1498
|
+
contractIR,
|
|
1499
|
+
strict: false,
|
|
1500
|
+
contractPath: contractPathAbsolute,
|
|
1501
|
+
configPath
|
|
1502
|
+
});
|
|
1503
|
+
},
|
|
1504
|
+
{
|
|
1505
|
+
message: "Verifying database satisfies contract",
|
|
1506
|
+
flags
|
|
1507
|
+
}
|
|
1508
|
+
);
|
|
1509
|
+
} catch (error) {
|
|
1510
|
+
throw errorRuntime4(error instanceof Error ? error.message : String(error), {
|
|
1511
|
+
why: `Failed to verify database schema: ${error instanceof Error ? error.message : String(error)}`
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
if (!schemaVerifyResult.ok) {
|
|
1515
|
+
return { schemaVerifyResult, signResult: void 0 };
|
|
1516
|
+
}
|
|
1517
|
+
let signResult;
|
|
1518
|
+
try {
|
|
1519
|
+
signResult = await withSpinner(
|
|
1520
|
+
async () => {
|
|
1521
|
+
return await typedFamilyInstance.sign({
|
|
1522
|
+
driver,
|
|
1523
|
+
contractIR,
|
|
1524
|
+
contractPath: contractPathAbsolute,
|
|
1525
|
+
configPath
|
|
1526
|
+
});
|
|
1527
|
+
},
|
|
1528
|
+
{
|
|
1529
|
+
message: "Signing database...",
|
|
1530
|
+
flags
|
|
1531
|
+
}
|
|
1532
|
+
);
|
|
1533
|
+
} catch (error) {
|
|
1534
|
+
throw errorRuntime4(error instanceof Error ? error.message : String(error), {
|
|
1535
|
+
why: `Failed to sign database: ${error instanceof Error ? error.message : String(error)}`
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
if (!flags.quiet && flags.json !== "object" && process.stdout.isTTY) {
|
|
1539
|
+
console.log("");
|
|
1540
|
+
}
|
|
1541
|
+
return { schemaVerifyResult: void 0, signResult };
|
|
1542
|
+
} finally {
|
|
1543
|
+
await driver.close();
|
|
1544
|
+
}
|
|
1545
|
+
});
|
|
1546
|
+
const exitCode = handleResult(result, flags, (value) => {
|
|
1547
|
+
const { schemaVerifyResult, signResult } = value;
|
|
1548
|
+
if (schemaVerifyResult && !schemaVerifyResult.ok) {
|
|
1549
|
+
if (flags.json === "object") {
|
|
1550
|
+
console.log(formatSchemaVerifyJson(schemaVerifyResult));
|
|
1551
|
+
} else {
|
|
1552
|
+
const output = formatSchemaVerifyOutput(schemaVerifyResult, flags);
|
|
1553
|
+
if (output) {
|
|
1554
|
+
console.log(output);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
if (signResult) {
|
|
1560
|
+
if (flags.json === "object") {
|
|
1561
|
+
console.log(formatSignJson(signResult));
|
|
1562
|
+
} else {
|
|
1563
|
+
const output = formatSignOutput(signResult, flags);
|
|
1564
|
+
if (output) {
|
|
1565
|
+
console.log(output);
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
});
|
|
1570
|
+
if (result.ok && result.value.schemaVerifyResult && !result.value.schemaVerifyResult.ok) {
|
|
1571
|
+
process.exit(1);
|
|
1572
|
+
} else {
|
|
1573
|
+
process.exit(exitCode);
|
|
1574
|
+
}
|
|
1575
|
+
});
|
|
1576
|
+
return command;
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
// src/commands/db-verify.ts
|
|
1580
|
+
import { readFile as readFile4 } from "fs/promises";
|
|
1581
|
+
import { relative as relative6, resolve as resolve6 } from "path";
|
|
1582
|
+
import {
|
|
1583
|
+
errorDatabaseUrlRequired as errorDatabaseUrlRequired5,
|
|
1584
|
+
errorDriverRequired as errorDriverRequired5,
|
|
1585
|
+
errorFileNotFound as errorFileNotFound4,
|
|
1586
|
+
errorHashMismatch as errorHashMismatch2,
|
|
1587
|
+
errorMarkerMissing as errorMarkerMissing2,
|
|
1588
|
+
errorRuntime as errorRuntime5,
|
|
1589
|
+
errorTargetMismatch as errorTargetMismatch2,
|
|
1590
|
+
errorUnexpected as errorUnexpected6
|
|
1591
|
+
} from "@prisma-next/core-control-plane/errors";
|
|
1592
|
+
import { Command as Command5 } from "commander";
|
|
1593
|
+
function createDbVerifyCommand() {
|
|
1594
|
+
const command = new Command5("verify");
|
|
1595
|
+
setCommandDescriptions(
|
|
1596
|
+
command,
|
|
1597
|
+
"Check whether the database has been signed with your contract",
|
|
1598
|
+
"Verifies that your database schema matches the emitted contract. Checks table structures,\ncolumn types, constraints, and codec coverage. Reports any mismatches or missing codecs."
|
|
1599
|
+
);
|
|
1600
|
+
command.configureHelp({
|
|
1601
|
+
formatHelp: (cmd) => {
|
|
1602
|
+
const flags = parseGlobalFlags({});
|
|
1603
|
+
return formatCommandHelp({ command: cmd, flags });
|
|
1604
|
+
}
|
|
1605
|
+
}).option("--db <url>", "Database connection string").option("--config <path>", "Path to prisma-next.config.ts").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) => {
|
|
1606
|
+
const flags = parseGlobalFlags(options);
|
|
1607
|
+
const result = await performAction(async () => {
|
|
1608
|
+
const config = await loadConfig(options.config);
|
|
1609
|
+
const configPath = options.config ? relative6(process.cwd(), resolve6(options.config)) : "prisma-next.config.ts";
|
|
1610
|
+
const contractPathAbsolute = config.contract?.output ? resolve6(config.contract.output) : resolve6("src/prisma/contract.json");
|
|
1611
|
+
const contractPath = relative6(process.cwd(), contractPathAbsolute);
|
|
1612
|
+
if (flags.json !== "object" && !flags.quiet) {
|
|
1613
|
+
const details = [
|
|
1614
|
+
{ label: "config", value: configPath },
|
|
1615
|
+
{ label: "contract", value: contractPath }
|
|
1616
|
+
];
|
|
1617
|
+
if (options.db) {
|
|
1618
|
+
details.push({ label: "database", value: options.db });
|
|
1619
|
+
}
|
|
1620
|
+
const header = formatStyledHeader({
|
|
1621
|
+
command: "db verify",
|
|
1622
|
+
description: "Check whether the database has been signed with your contract",
|
|
1623
|
+
url: "https://pris.ly/db-verify",
|
|
1624
|
+
details,
|
|
1625
|
+
flags
|
|
1626
|
+
});
|
|
1627
|
+
console.log(header);
|
|
1628
|
+
}
|
|
1629
|
+
let contractJsonContent;
|
|
1630
|
+
try {
|
|
1631
|
+
contractJsonContent = await readFile4(contractPathAbsolute, "utf-8");
|
|
1632
|
+
} catch (error) {
|
|
1633
|
+
if (error instanceof Error && error.code === "ENOENT") {
|
|
1634
|
+
throw errorFileNotFound4(contractPathAbsolute, {
|
|
1635
|
+
why: `Contract file not found at ${contractPathAbsolute}`
|
|
1636
|
+
});
|
|
1637
|
+
}
|
|
1638
|
+
throw errorUnexpected6(error instanceof Error ? error.message : String(error), {
|
|
1639
|
+
why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
const contractJson = JSON.parse(contractJsonContent);
|
|
1643
|
+
const dbUrl = options.db ?? config.db?.url;
|
|
1644
|
+
if (!dbUrl) {
|
|
1645
|
+
throw errorDatabaseUrlRequired5();
|
|
1646
|
+
}
|
|
1647
|
+
if (!config.driver) {
|
|
1648
|
+
throw errorDriverRequired5();
|
|
1649
|
+
}
|
|
1650
|
+
const driverDescriptor = config.driver;
|
|
1651
|
+
const driver = await withSpinner(() => driverDescriptor.create(dbUrl), {
|
|
1652
|
+
message: "Connecting to database...",
|
|
1653
|
+
flags
|
|
1654
|
+
});
|
|
1655
|
+
try {
|
|
1656
|
+
const familyInstance = config.family.create({
|
|
1657
|
+
target: config.target,
|
|
1658
|
+
adapter: config.adapter,
|
|
1659
|
+
driver: driverDescriptor,
|
|
1660
|
+
extensions: config.extensions ?? []
|
|
1661
|
+
});
|
|
1662
|
+
const typedFamilyInstance = familyInstance;
|
|
1663
|
+
const contractIR = typedFamilyInstance.validateContractIR(contractJson);
|
|
1664
|
+
let verifyResult;
|
|
1665
|
+
try {
|
|
1666
|
+
verifyResult = await withSpinner(
|
|
1667
|
+
() => typedFamilyInstance.verify({
|
|
1668
|
+
driver,
|
|
1669
|
+
contractIR,
|
|
1670
|
+
expectedTargetId: config.target.targetId,
|
|
1671
|
+
contractPath: contractPathAbsolute,
|
|
1672
|
+
configPath
|
|
1673
|
+
}),
|
|
1674
|
+
{
|
|
1675
|
+
message: "Verifying database schema...",
|
|
1676
|
+
flags
|
|
1677
|
+
}
|
|
1678
|
+
);
|
|
1679
|
+
} catch (error) {
|
|
1680
|
+
throw errorUnexpected6(error instanceof Error ? error.message : String(error), {
|
|
1681
|
+
why: `Failed to verify database: ${error instanceof Error ? error.message : String(error)}`
|
|
1682
|
+
});
|
|
1683
|
+
}
|
|
1684
|
+
if (!verifyResult.ok && verifyResult.code) {
|
|
1685
|
+
if (verifyResult.code === "PN-RTM-3001") {
|
|
1686
|
+
throw errorMarkerMissing2();
|
|
1687
|
+
}
|
|
1688
|
+
if (verifyResult.code === "PN-RTM-3002") {
|
|
1689
|
+
throw errorHashMismatch2({
|
|
1690
|
+
expected: verifyResult.contract.coreHash,
|
|
1691
|
+
...verifyResult.marker?.coreHash ? { actual: verifyResult.marker.coreHash } : {}
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
if (verifyResult.code === "PN-RTM-3003") {
|
|
1695
|
+
throw errorTargetMismatch2(
|
|
1696
|
+
verifyResult.target.expected,
|
|
1697
|
+
verifyResult.target.actual ?? "unknown"
|
|
1698
|
+
);
|
|
1699
|
+
}
|
|
1700
|
+
throw errorRuntime5(verifyResult.summary);
|
|
1701
|
+
}
|
|
1702
|
+
if (!flags.quiet && flags.json !== "object" && process.stdout.isTTY) {
|
|
1703
|
+
console.log("");
|
|
1704
|
+
}
|
|
1705
|
+
return verifyResult;
|
|
1706
|
+
} finally {
|
|
1707
|
+
await driver.close();
|
|
1708
|
+
}
|
|
1709
|
+
});
|
|
1710
|
+
const exitCode = handleResult(result, flags, (verifyResult) => {
|
|
1711
|
+
if (flags.json === "object") {
|
|
1712
|
+
console.log(formatVerifyJson(verifyResult));
|
|
1713
|
+
} else {
|
|
1714
|
+
const output = formatVerifyOutput(verifyResult, flags);
|
|
1715
|
+
if (output) {
|
|
1716
|
+
console.log(output);
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
});
|
|
1720
|
+
process.exit(exitCode);
|
|
1721
|
+
});
|
|
1722
|
+
return command;
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
// src/cli.ts
|
|
1726
|
+
var program = new Command6();
|
|
1727
|
+
program.name("prisma-next").description("Prisma Next CLI").version("0.0.1");
|
|
1728
|
+
var versionOption = program.options.find((opt) => opt.flags.includes("--version"));
|
|
1729
|
+
if (versionOption) {
|
|
1730
|
+
versionOption.description = "Output the version number";
|
|
1731
|
+
}
|
|
1732
|
+
program.configureOutput({
|
|
1733
|
+
writeErr: () => {
|
|
1734
|
+
},
|
|
1735
|
+
writeOut: () => {
|
|
1736
|
+
}
|
|
1737
|
+
});
|
|
1738
|
+
var rootHelpFormatter = (cmd) => {
|
|
1739
|
+
const flags = parseGlobalFlags({});
|
|
1740
|
+
return formatRootHelp({ program: cmd, flags });
|
|
1741
|
+
};
|
|
1742
|
+
program.configureHelp({
|
|
1743
|
+
formatHelp: rootHelpFormatter,
|
|
1744
|
+
subcommandDescription: () => ""
|
|
1745
|
+
});
|
|
1746
|
+
program.exitOverride((err2) => {
|
|
1747
|
+
if (err2) {
|
|
1748
|
+
const errorCode = err2.code;
|
|
1749
|
+
const errorMessage = String(err2.message ?? "");
|
|
1750
|
+
const errorName = err2.name ?? "";
|
|
1751
|
+
const isUnknownCommandError = errorCode === "commander.unknownCommand" || errorCode === "commander.unknownArgument" || errorName === "CommanderError" && (errorMessage.includes("unknown command") || errorMessage.includes("unknown argument"));
|
|
1752
|
+
if (isUnknownCommandError) {
|
|
1753
|
+
const flags = parseGlobalFlags({});
|
|
1754
|
+
const match = errorMessage.match(/unknown command ['"]([^'"]+)['"]/);
|
|
1755
|
+
const commandName = match ? match[1] : process.argv[3] || process.argv[2] || "unknown";
|
|
1756
|
+
const firstArg = process.argv[2];
|
|
1757
|
+
const parentCommand = firstArg ? program.commands.find((cmd) => cmd.name() === firstArg) : void 0;
|
|
1758
|
+
if (parentCommand && commandName !== firstArg) {
|
|
1759
|
+
console.error(`Unknown command: ${commandName}`);
|
|
1760
|
+
console.error("");
|
|
1761
|
+
const helpText = formatCommandHelp({ command: parentCommand, flags });
|
|
1762
|
+
console.log(helpText);
|
|
1763
|
+
} else {
|
|
1764
|
+
console.error(`Unknown command: ${commandName}`);
|
|
1765
|
+
console.error("");
|
|
1766
|
+
const helpText = formatRootHelp({ program, flags });
|
|
1767
|
+
console.log(helpText);
|
|
1768
|
+
}
|
|
1769
|
+
process.exit(1);
|
|
1770
|
+
return;
|
|
1771
|
+
}
|
|
1772
|
+
const isHelpError = errorCode === "commander.help" || errorCode === "commander.helpDisplayed" || errorCode === "outputHelp" || errorMessage === "(outputHelp)" || errorMessage.includes("outputHelp") || errorName === "CommanderError" && errorMessage.includes("outputHelp");
|
|
1773
|
+
if (isHelpError) {
|
|
1774
|
+
process.exit(0);
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1777
|
+
const isMissingArgumentError = errorCode === "commander.missingArgument" || errorCode === "commander.missingMandatoryOptionValue" || errorName === "CommanderError" && (errorMessage.includes("missing") || errorMessage.includes("required"));
|
|
1778
|
+
if (isMissingArgumentError) {
|
|
1779
|
+
process.exit(0);
|
|
1780
|
+
return;
|
|
1781
|
+
}
|
|
1782
|
+
console.error(`Unhandled error: ${err2.message}`);
|
|
1783
|
+
if (err2.stack) {
|
|
1784
|
+
console.error(err2.stack);
|
|
1785
|
+
}
|
|
1786
|
+
process.exit(1);
|
|
1787
|
+
}
|
|
1788
|
+
process.exit(0);
|
|
1789
|
+
});
|
|
1790
|
+
var contractCommand = new Command6("contract");
|
|
1791
|
+
setCommandDescriptions(
|
|
1792
|
+
contractCommand,
|
|
1793
|
+
"Contract management commands",
|
|
1794
|
+
"Define and emit your application data contract. The contract describes your schema as a\ndeclarative data structure that can be signed and verified against your database."
|
|
1795
|
+
);
|
|
1796
|
+
contractCommand.configureHelp({
|
|
1797
|
+
formatHelp: (cmd) => {
|
|
1798
|
+
const flags = parseGlobalFlags({});
|
|
1799
|
+
return formatCommandHelp({ command: cmd, flags });
|
|
1800
|
+
},
|
|
1801
|
+
subcommandDescription: () => ""
|
|
1802
|
+
});
|
|
1803
|
+
var contractEmitCommand = createContractEmitCommand();
|
|
1804
|
+
contractCommand.addCommand(contractEmitCommand);
|
|
1805
|
+
program.addCommand(contractCommand);
|
|
1806
|
+
var dbCommand = new Command6("db");
|
|
1807
|
+
setCommandDescriptions(
|
|
1808
|
+
dbCommand,
|
|
1809
|
+
"Database management commands",
|
|
1810
|
+
"Verify and sign your database with your contract. Ensure your database schema matches\nyour contract, and sign it to record the contract hash for future verification."
|
|
1811
|
+
);
|
|
1812
|
+
dbCommand.configureHelp({
|
|
1813
|
+
formatHelp: (cmd) => {
|
|
1814
|
+
const flags = parseGlobalFlags({});
|
|
1815
|
+
return formatCommandHelp({ command: cmd, flags });
|
|
1816
|
+
},
|
|
1817
|
+
subcommandDescription: () => ""
|
|
1818
|
+
});
|
|
1819
|
+
var dbVerifyCommand = createDbVerifyCommand();
|
|
1820
|
+
dbCommand.addCommand(dbVerifyCommand);
|
|
1821
|
+
var dbIntrospectCommand = createDbIntrospectCommand();
|
|
1822
|
+
dbCommand.addCommand(dbIntrospectCommand);
|
|
1823
|
+
var dbSchemaVerifyCommand = createDbSchemaVerifyCommand();
|
|
1824
|
+
dbCommand.addCommand(dbSchemaVerifyCommand);
|
|
1825
|
+
var dbSignCommand = createDbSignCommand();
|
|
1826
|
+
dbCommand.addCommand(dbSignCommand);
|
|
1827
|
+
program.addCommand(dbCommand);
|
|
1828
|
+
var helpCommand = new Command6("help").description("Show usage instructions").configureHelp({
|
|
1829
|
+
formatHelp: (cmd) => {
|
|
1830
|
+
const flags = parseGlobalFlags({});
|
|
1831
|
+
return formatCommandHelp({ command: cmd, flags });
|
|
1832
|
+
}
|
|
1833
|
+
}).action(() => {
|
|
1834
|
+
const flags = parseGlobalFlags({});
|
|
1835
|
+
const helpText = formatRootHelp({ program, flags });
|
|
1836
|
+
console.log(helpText);
|
|
1837
|
+
process.exit(0);
|
|
1838
|
+
});
|
|
1839
|
+
program.addCommand(helpCommand);
|
|
1840
|
+
program.action(() => {
|
|
1841
|
+
const flags = parseGlobalFlags({});
|
|
1842
|
+
const helpText = formatRootHelp({ program, flags });
|
|
1843
|
+
console.log(helpText);
|
|
1844
|
+
process.exit(0);
|
|
1845
|
+
});
|
|
1846
|
+
var args = process.argv.slice(2);
|
|
1847
|
+
if (args.length > 0) {
|
|
1848
|
+
const commandName = args[0];
|
|
1849
|
+
if (commandName === "--version" || commandName === "-V") {
|
|
1850
|
+
console.log(program.version());
|
|
1851
|
+
process.exit(0);
|
|
1852
|
+
}
|
|
1853
|
+
const isGlobalOption = commandName === "--help" || commandName === "-h";
|
|
1854
|
+
if (!isGlobalOption) {
|
|
1855
|
+
const command = program.commands.find((cmd) => cmd.name() === commandName);
|
|
1856
|
+
if (!command) {
|
|
1857
|
+
const flags = parseGlobalFlags({});
|
|
1858
|
+
console.error(`Unknown command: ${commandName}`);
|
|
1859
|
+
console.error("");
|
|
1860
|
+
const helpText = formatRootHelp({ program, flags });
|
|
1861
|
+
console.log(helpText);
|
|
1862
|
+
process.exit(1);
|
|
1863
|
+
} else if (command.commands.length > 0 && args.length === 1) {
|
|
1864
|
+
const flags = parseGlobalFlags({});
|
|
1865
|
+
const helpText = formatCommandHelp({ command, flags });
|
|
1866
|
+
console.log(helpText);
|
|
1867
|
+
process.exit(0);
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
program.parse();
|
|
1872
|
+
//# sourceMappingURL=cli.js.map
|