@prisma-next/cli 0.3.0-dev.3 → 0.3.0-dev.30
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 +111 -27
- package/dist/{chunk-BZMBKEEQ.js → chunk-AGOTG4L3.js} +44 -76
- package/dist/chunk-AGOTG4L3.js.map +1 -0
- package/dist/chunk-HLLI4YL7.js +180 -0
- package/dist/chunk-HLLI4YL7.js.map +1 -0
- package/dist/chunk-VG2R7DGF.js +735 -0
- package/dist/chunk-VG2R7DGF.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +1502 -968
- package/dist/cli.js.map +1 -1
- package/dist/commands/contract-emit.d.ts +2 -4
- package/dist/commands/contract-emit.d.ts.map +1 -0
- package/dist/commands/contract-emit.js +3 -2
- package/dist/commands/db-init.d.ts +2 -4
- package/dist/commands/db-init.d.ts.map +1 -0
- package/dist/commands/db-init.js +205 -289
- package/dist/commands/db-init.js.map +1 -1
- package/dist/commands/db-introspect.d.ts +2 -4
- package/dist/commands/db-introspect.d.ts.map +1 -0
- package/dist/commands/db-introspect.js +108 -143
- package/dist/commands/db-introspect.js.map +1 -1
- package/dist/commands/db-schema-verify.d.ts +2 -4
- package/dist/commands/db-schema-verify.d.ts.map +1 -0
- package/dist/commands/db-schema-verify.js +120 -113
- package/dist/commands/db-schema-verify.js.map +1 -1
- package/dist/commands/db-sign.d.ts +2 -4
- package/dist/commands/db-sign.d.ts.map +1 -0
- package/dist/commands/db-sign.js +152 -156
- package/dist/commands/db-sign.js.map +1 -1
- package/dist/commands/db-verify.d.ts +2 -4
- package/dist/commands/db-verify.d.ts.map +1 -0
- package/dist/commands/db-verify.js +142 -122
- package/dist/commands/db-verify.js.map +1 -1
- package/dist/config-loader.d.ts +3 -5
- package/dist/config-loader.d.ts.map +1 -0
- package/dist/control-api/client.d.ts +13 -0
- package/dist/control-api/client.d.ts.map +1 -0
- package/dist/control-api/operations/db-init.d.ts +29 -0
- package/dist/control-api/operations/db-init.d.ts.map +1 -0
- package/dist/control-api/types.d.ts +387 -0
- package/dist/control-api/types.d.ts.map +1 -0
- package/dist/exports/config-types.d.ts +3 -0
- package/dist/exports/config-types.d.ts.map +1 -0
- package/dist/exports/config-types.js.map +1 -0
- package/dist/exports/control-api.d.ts +13 -0
- package/dist/exports/control-api.d.ts.map +1 -0
- package/dist/exports/control-api.js +7 -0
- package/dist/exports/control-api.js.map +1 -0
- package/dist/exports/index.d.ts +4 -0
- package/dist/exports/index.d.ts.map +1 -0
- package/dist/{index.js → exports/index.js} +4 -3
- package/dist/exports/index.js.map +1 -0
- package/dist/{index.d.ts → load-ts-contract.d.ts} +4 -8
- package/dist/load-ts-contract.d.ts.map +1 -0
- package/dist/utils/cli-errors.d.ts +7 -0
- package/dist/utils/cli-errors.d.ts.map +1 -0
- package/dist/utils/command-helpers.d.ts +12 -0
- package/dist/utils/command-helpers.d.ts.map +1 -0
- package/dist/utils/framework-components.d.ts +70 -0
- package/dist/utils/framework-components.d.ts.map +1 -0
- package/dist/utils/global-flags.d.ts +25 -0
- package/dist/utils/global-flags.d.ts.map +1 -0
- package/dist/utils/output.d.ts +142 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/progress-adapter.d.ts +26 -0
- package/dist/utils/progress-adapter.d.ts.map +1 -0
- package/dist/utils/result-handler.d.ts +15 -0
- package/dist/utils/result-handler.d.ts.map +1 -0
- package/package.json +30 -26
- package/src/cli.ts +260 -0
- package/src/commands/contract-emit.ts +259 -0
- package/src/commands/db-init.ts +360 -0
- package/src/commands/db-introspect.ts +227 -0
- package/src/commands/db-schema-verify.ts +238 -0
- package/src/commands/db-sign.ts +279 -0
- package/src/commands/db-verify.ts +258 -0
- package/src/config-loader.ts +76 -0
- package/src/control-api/client.ts +589 -0
- package/src/control-api/operations/db-init.ts +281 -0
- package/src/control-api/types.ts +461 -0
- package/src/exports/config-types.ts +6 -0
- package/src/exports/control-api.ts +46 -0
- package/src/exports/index.ts +4 -0
- package/src/load-ts-contract.ts +217 -0
- package/src/utils/cli-errors.ts +26 -0
- package/src/utils/command-helpers.ts +26 -0
- package/src/utils/framework-components.ts +177 -0
- package/src/utils/global-flags.ts +75 -0
- package/src/utils/output.ts +1471 -0
- package/src/utils/progress-adapter.ts +86 -0
- package/src/utils/result-handler.ts +44 -0
- package/dist/chunk-464LNZCE.js +0 -134
- package/dist/chunk-464LNZCE.js.map +0 -1
- package/dist/chunk-BZMBKEEQ.js.map +0 -1
- package/dist/chunk-ZKYEJROM.js +0 -94
- package/dist/chunk-ZKYEJROM.js.map +0 -1
- package/dist/config-types.d.ts +0 -1
- package/dist/config-types.js.map +0 -1
- package/dist/index.js.map +0 -1
- /package/dist/{config-types.js → exports/config-types.js} +0 -0
|
@@ -1,35 +1,152 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "../chunk-ZKYEJROM.js";
|
|
4
|
-
import {
|
|
2
|
+
createProgressAdapter,
|
|
5
3
|
formatCommandHelp,
|
|
6
4
|
formatStyledHeader,
|
|
7
5
|
formatVerifyJson,
|
|
8
6
|
formatVerifyOutput,
|
|
9
7
|
handleResult,
|
|
10
8
|
parseGlobalFlags,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
withSpinner
|
|
14
|
-
} from "../chunk-BZMBKEEQ.js";
|
|
9
|
+
setCommandDescriptions
|
|
10
|
+
} from "../chunk-AGOTG4L3.js";
|
|
15
11
|
import {
|
|
16
12
|
loadConfig
|
|
17
13
|
} from "../chunk-HWYQOCAJ.js";
|
|
18
|
-
|
|
19
|
-
// src/commands/db-verify.ts
|
|
20
|
-
import { readFile } from "fs/promises";
|
|
21
|
-
import { relative, resolve } from "path";
|
|
22
14
|
import {
|
|
23
|
-
|
|
15
|
+
CliStructuredError,
|
|
16
|
+
createControlClient,
|
|
17
|
+
errorContractValidationFailed,
|
|
18
|
+
errorDatabaseConnectionRequired,
|
|
24
19
|
errorDriverRequired,
|
|
25
20
|
errorFileNotFound,
|
|
26
21
|
errorHashMismatch,
|
|
22
|
+
errorJsonFormatNotSupported,
|
|
27
23
|
errorMarkerMissing,
|
|
28
24
|
errorRuntime,
|
|
29
25
|
errorTargetMismatch,
|
|
30
26
|
errorUnexpected
|
|
31
|
-
} from "
|
|
27
|
+
} from "../chunk-VG2R7DGF.js";
|
|
28
|
+
|
|
29
|
+
// src/commands/db-verify.ts
|
|
30
|
+
import { readFile } from "fs/promises";
|
|
31
|
+
import { relative, resolve } from "path";
|
|
32
|
+
import { notOk, ok } from "@prisma-next/utils/result";
|
|
32
33
|
import { Command } from "commander";
|
|
34
|
+
function mapVerifyFailure(verifyResult) {
|
|
35
|
+
if (!verifyResult.ok && verifyResult.code) {
|
|
36
|
+
if (verifyResult.code === "PN-RTM-3001") {
|
|
37
|
+
return errorMarkerMissing();
|
|
38
|
+
}
|
|
39
|
+
if (verifyResult.code === "PN-RTM-3002") {
|
|
40
|
+
return errorHashMismatch({
|
|
41
|
+
expected: verifyResult.contract.coreHash,
|
|
42
|
+
...verifyResult.marker?.coreHash ? { actual: verifyResult.marker.coreHash } : {}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (verifyResult.code === "PN-RTM-3003") {
|
|
46
|
+
return errorTargetMismatch(
|
|
47
|
+
verifyResult.target.expected,
|
|
48
|
+
verifyResult.target.actual ?? "unknown"
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return errorRuntime(verifyResult.summary);
|
|
53
|
+
}
|
|
54
|
+
async function executeDbVerifyCommand(options, flags) {
|
|
55
|
+
const config = await loadConfig(options.config);
|
|
56
|
+
const configPath = options.config ? relative(process.cwd(), resolve(options.config)) : "prisma-next.config.ts";
|
|
57
|
+
const contractPathAbsolute = config.contract?.output ? resolve(config.contract.output) : resolve("src/prisma/contract.json");
|
|
58
|
+
const contractPath = relative(process.cwd(), contractPathAbsolute);
|
|
59
|
+
if (flags.json !== "object" && !flags.quiet) {
|
|
60
|
+
const details = [
|
|
61
|
+
{ label: "config", value: configPath },
|
|
62
|
+
{ label: "contract", value: contractPath }
|
|
63
|
+
];
|
|
64
|
+
if (options.db) {
|
|
65
|
+
details.push({ label: "database", value: options.db });
|
|
66
|
+
}
|
|
67
|
+
const header = formatStyledHeader({
|
|
68
|
+
command: "db verify",
|
|
69
|
+
description: "Check whether the database has been signed with your contract",
|
|
70
|
+
url: "https://pris.ly/db-verify",
|
|
71
|
+
details,
|
|
72
|
+
flags
|
|
73
|
+
});
|
|
74
|
+
console.log(header);
|
|
75
|
+
}
|
|
76
|
+
let contractJsonContent;
|
|
77
|
+
try {
|
|
78
|
+
contractJsonContent = await readFile(contractPathAbsolute, "utf-8");
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error instanceof Error && error.code === "ENOENT") {
|
|
81
|
+
return notOk(
|
|
82
|
+
errorFileNotFound(contractPathAbsolute, {
|
|
83
|
+
why: `Contract file not found at ${contractPathAbsolute}`,
|
|
84
|
+
fix: `Run \`prisma-next contract emit\` to generate ${contractPath}, or update \`config.contract.output\` in ${configPath}`
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return notOk(
|
|
89
|
+
errorUnexpected(error instanceof Error ? error.message : String(error), {
|
|
90
|
+
why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
let contractJson;
|
|
95
|
+
try {
|
|
96
|
+
contractJson = JSON.parse(contractJsonContent);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
return notOk(
|
|
99
|
+
errorContractValidationFailed(
|
|
100
|
+
`Contract JSON is invalid: ${error instanceof Error ? error.message : String(error)}`,
|
|
101
|
+
{ where: { path: contractPathAbsolute } }
|
|
102
|
+
)
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
const dbConnection = options.db ?? config.db?.connection;
|
|
106
|
+
if (!dbConnection) {
|
|
107
|
+
return notOk(
|
|
108
|
+
errorDatabaseConnectionRequired({
|
|
109
|
+
why: `Database connection is required for db verify (set db.connection in ${configPath}, or pass --db <url>)`
|
|
110
|
+
})
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
if (!config.driver) {
|
|
114
|
+
return notOk(errorDriverRequired({ why: "Config.driver is required for db verify" }));
|
|
115
|
+
}
|
|
116
|
+
const client = createControlClient({
|
|
117
|
+
family: config.family,
|
|
118
|
+
target: config.target,
|
|
119
|
+
adapter: config.adapter,
|
|
120
|
+
driver: config.driver,
|
|
121
|
+
extensionPacks: config.extensionPacks ?? []
|
|
122
|
+
});
|
|
123
|
+
const onProgress = createProgressAdapter({ flags });
|
|
124
|
+
try {
|
|
125
|
+
const verifyResult = await client.verify({
|
|
126
|
+
contractIR: contractJson,
|
|
127
|
+
connection: dbConnection,
|
|
128
|
+
onProgress
|
|
129
|
+
});
|
|
130
|
+
if (!flags.quiet && flags.json !== "object" && process.stdout.isTTY) {
|
|
131
|
+
console.log("");
|
|
132
|
+
}
|
|
133
|
+
if (!verifyResult.ok) {
|
|
134
|
+
return notOk(mapVerifyFailure(verifyResult));
|
|
135
|
+
}
|
|
136
|
+
return ok(verifyResult);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (error instanceof CliStructuredError) {
|
|
139
|
+
return notOk(error);
|
|
140
|
+
}
|
|
141
|
+
return notOk(
|
|
142
|
+
errorUnexpected(error instanceof Error ? error.message : String(error), {
|
|
143
|
+
why: `Unexpected error during db verify: ${error instanceof Error ? error.message : String(error)}`
|
|
144
|
+
})
|
|
145
|
+
);
|
|
146
|
+
} finally {
|
|
147
|
+
await client.close();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
33
150
|
function createDbVerifyCommand() {
|
|
34
151
|
const command = new Command("verify");
|
|
35
152
|
setCommandDescriptions(
|
|
@@ -42,117 +159,20 @@ function createDbVerifyCommand() {
|
|
|
42
159
|
const flags = parseGlobalFlags({});
|
|
43
160
|
return formatCommandHelp({ command: cmd, flags });
|
|
44
161
|
}
|
|
45
|
-
}).option("--db <url>", "Database connection string").option("--config <path>", "Path to prisma-next.config.ts").option("--json [format]", "Output as JSON (object
|
|
162
|
+
}).option("--db <url>", "Database connection string").option("--config <path>", "Path to prisma-next.config.ts").option("--json [format]", "Output as JSON (object)", 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) => {
|
|
46
163
|
const flags = parseGlobalFlags(options);
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
const contractPathAbsolute = config.contract?.output ? resolve(config.contract.output) : resolve("src/prisma/contract.json");
|
|
51
|
-
const contractPath = relative(process.cwd(), contractPathAbsolute);
|
|
52
|
-
if (flags.json !== "object" && !flags.quiet) {
|
|
53
|
-
const details = [
|
|
54
|
-
{ label: "config", value: configPath },
|
|
55
|
-
{ label: "contract", value: contractPath }
|
|
56
|
-
];
|
|
57
|
-
if (options.db) {
|
|
58
|
-
details.push({ label: "database", value: options.db });
|
|
59
|
-
}
|
|
60
|
-
const header = formatStyledHeader({
|
|
164
|
+
if (flags.json === "ndjson") {
|
|
165
|
+
const result2 = notOk(
|
|
166
|
+
errorJsonFormatNotSupported({
|
|
61
167
|
command: "db verify",
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
contractJsonContent = await readFile(contractPathAbsolute, "utf-8");
|
|
72
|
-
} catch (error) {
|
|
73
|
-
if (error instanceof Error && error.code === "ENOENT") {
|
|
74
|
-
throw errorFileNotFound(contractPathAbsolute, {
|
|
75
|
-
why: `Contract file not found at ${contractPathAbsolute}`
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
throw errorUnexpected(error instanceof Error ? error.message : String(error), {
|
|
79
|
-
why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
const contractJson = JSON.parse(contractJsonContent);
|
|
83
|
-
const dbUrl = options.db ?? config.db?.url;
|
|
84
|
-
if (!dbUrl) {
|
|
85
|
-
throw errorDatabaseUrlRequired();
|
|
86
|
-
}
|
|
87
|
-
if (!config.driver) {
|
|
88
|
-
throw errorDriverRequired();
|
|
89
|
-
}
|
|
90
|
-
const driverDescriptor = config.driver;
|
|
91
|
-
const driver = await withSpinner(() => driverDescriptor.create(dbUrl), {
|
|
92
|
-
message: "Connecting to database...",
|
|
93
|
-
flags
|
|
94
|
-
});
|
|
95
|
-
try {
|
|
96
|
-
const familyInstance = config.family.create({
|
|
97
|
-
target: config.target,
|
|
98
|
-
adapter: config.adapter,
|
|
99
|
-
driver: driverDescriptor,
|
|
100
|
-
extensionPacks: config.extensionPacks ?? []
|
|
101
|
-
});
|
|
102
|
-
const contractIR = familyInstance.validateContractIR(contractJson);
|
|
103
|
-
assertContractRequirementsSatisfied({
|
|
104
|
-
contract: contractIR,
|
|
105
|
-
family: config.family,
|
|
106
|
-
target: config.target,
|
|
107
|
-
adapter: config.adapter,
|
|
108
|
-
extensionPacks: config.extensionPacks
|
|
109
|
-
});
|
|
110
|
-
let verifyResult;
|
|
111
|
-
try {
|
|
112
|
-
verifyResult = await withSpinner(
|
|
113
|
-
() => familyInstance.verify({
|
|
114
|
-
driver,
|
|
115
|
-
contractIR,
|
|
116
|
-
expectedTargetId: config.target.targetId,
|
|
117
|
-
contractPath: contractPathAbsolute,
|
|
118
|
-
configPath
|
|
119
|
-
}),
|
|
120
|
-
{
|
|
121
|
-
message: "Verifying database schema...",
|
|
122
|
-
flags
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
} catch (error) {
|
|
126
|
-
throw errorUnexpected(error instanceof Error ? error.message : String(error), {
|
|
127
|
-
why: `Failed to verify database: ${error instanceof Error ? error.message : String(error)}`
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
if (!verifyResult.ok && verifyResult.code) {
|
|
131
|
-
if (verifyResult.code === "PN-RTM-3001") {
|
|
132
|
-
throw errorMarkerMissing();
|
|
133
|
-
}
|
|
134
|
-
if (verifyResult.code === "PN-RTM-3002") {
|
|
135
|
-
throw errorHashMismatch({
|
|
136
|
-
expected: verifyResult.contract.coreHash,
|
|
137
|
-
...verifyResult.marker?.coreHash ? { actual: verifyResult.marker.coreHash } : {}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
if (verifyResult.code === "PN-RTM-3003") {
|
|
141
|
-
throw errorTargetMismatch(
|
|
142
|
-
verifyResult.target.expected,
|
|
143
|
-
verifyResult.target.actual ?? "unknown"
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
throw errorRuntime(verifyResult.summary);
|
|
147
|
-
}
|
|
148
|
-
if (!flags.quiet && flags.json !== "object" && process.stdout.isTTY) {
|
|
149
|
-
console.log("");
|
|
150
|
-
}
|
|
151
|
-
return verifyResult;
|
|
152
|
-
} finally {
|
|
153
|
-
await driver.close();
|
|
154
|
-
}
|
|
155
|
-
});
|
|
168
|
+
format: "ndjson",
|
|
169
|
+
supportedFormats: ["object"]
|
|
170
|
+
})
|
|
171
|
+
);
|
|
172
|
+
const exitCode2 = handleResult(result2, flags);
|
|
173
|
+
process.exit(exitCode2);
|
|
174
|
+
}
|
|
175
|
+
const result = await executeDbVerifyCommand(options, flags);
|
|
156
176
|
const exitCode = handleResult(result, flags, (verifyResult) => {
|
|
157
177
|
if (flags.json === "object") {
|
|
158
178
|
console.log(formatVerifyJson(verifyResult));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/db-verify.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { relative, resolve } from 'node:path';\nimport type { ContractIR } from '@prisma-next/contract/ir';\nimport {\n errorDatabaseUrlRequired,\n errorDriverRequired,\n errorFileNotFound,\n errorHashMismatch,\n errorMarkerMissing,\n errorRuntime,\n errorTargetMismatch,\n errorUnexpected,\n} from '@prisma-next/core-control-plane/errors';\nimport type { VerifyDatabaseResult } from '@prisma-next/core-control-plane/types';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport { performAction } from '../utils/action';\nimport { setCommandDescriptions } from '../utils/command-helpers';\nimport { assertContractRequirementsSatisfied } from '../utils/framework-components';\nimport { parseGlobalFlags } from '../utils/global-flags';\nimport {\n formatCommandHelp,\n formatStyledHeader,\n formatVerifyJson,\n formatVerifyOutput,\n} from '../utils/output';\nimport { handleResult } from '../utils/result-handler';\nimport { withSpinner } from '../utils/spinner';\n\ninterface DbVerifyOptions {\n readonly db?: string;\n readonly config?: string;\n readonly json?: string | boolean;\n readonly quiet?: boolean;\n readonly q?: boolean;\n readonly verbose?: boolean;\n readonly v?: boolean;\n readonly vv?: boolean;\n readonly trace?: boolean;\n readonly timestamps?: boolean;\n readonly color?: boolean;\n readonly 'no-color'?: boolean;\n}\n\nexport function createDbVerifyCommand(): Command {\n const command = new Command('verify');\n setCommandDescriptions(\n command,\n 'Check whether the database has been signed with your contract',\n 'Verifies that your database schema matches the emitted contract. Checks table structures,\\n' +\n 'column types, constraints, and codec coverage. Reports any mismatches or missing codecs.',\n );\n command\n .configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n })\n .option('--db <url>', 'Database connection string')\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option('--json [format]', 'Output as JSON (object or ndjson)', false)\n .option('-q, --quiet', 'Quiet mode: errors only')\n .option('-v, --verbose', 'Verbose output: debug info, timings')\n .option('-vv, --trace', 'Trace output: deep internals, stack traces')\n .option('--timestamps', 'Add timestamps to output')\n .option('--color', 'Force color output')\n .option('--no-color', 'Disable color output')\n .action(async (options: DbVerifyOptions) => {\n const flags = parseGlobalFlags(options);\n\n const result = await performAction(async () => {\n // Load config (file I/O)\n const config = await loadConfig(options.config);\n // Normalize config path for display (match contract path format - no ./ prefix)\n const configPath = options.config\n ? relative(process.cwd(), resolve(options.config))\n : 'prisma-next.config.ts';\n const contractPathAbsolute = config.contract?.output\n ? resolve(config.contract.output)\n : resolve('src/prisma/contract.json');\n // Convert to relative path for display\n const contractPath = relative(process.cwd(), contractPathAbsolute);\n\n // Output header (only for human-readable output)\n if (flags.json !== 'object' && !flags.quiet) {\n const details: Array<{ label: string; value: string }> = [\n { label: 'config', value: configPath },\n { label: 'contract', value: contractPath },\n ];\n if (options.db) {\n details.push({ label: 'database', value: options.db });\n }\n const header = formatStyledHeader({\n command: 'db verify',\n description: 'Check whether the database has been signed with your contract',\n url: 'https://pris.ly/db-verify',\n details,\n flags,\n });\n console.log(header);\n }\n\n // Load contract file (file I/O)\n let contractJsonContent: string;\n try {\n contractJsonContent = await readFile(contractPathAbsolute, 'utf-8');\n } catch (error) {\n if (error instanceof Error && (error as { code?: string }).code === 'ENOENT') {\n throw errorFileNotFound(contractPathAbsolute, {\n why: `Contract file not found at ${contractPathAbsolute}`,\n });\n }\n throw errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n const contractJson = JSON.parse(contractJsonContent) as Record<string, unknown>;\n\n // Resolve database URL\n const dbUrl = options.db ?? config.db?.url;\n if (!dbUrl) {\n throw errorDatabaseUrlRequired();\n }\n\n // Check for driver\n if (!config.driver) {\n throw errorDriverRequired();\n }\n\n // Store driver descriptor after null check\n const driverDescriptor = config.driver;\n\n // Create driver\n const driver = await withSpinner(() => driverDescriptor.create(dbUrl), {\n message: 'Connecting to database...',\n flags,\n });\n\n try {\n // Create family instance\n const familyInstance = config.family.create({\n target: config.target,\n adapter: config.adapter,\n driver: driverDescriptor,\n extensionPacks: config.extensionPacks ?? [],\n });\n\n // Validate contract using instance validator\n const contractIR = familyInstance.validateContractIR(contractJson) as ContractIR;\n assertContractRequirementsSatisfied({\n contract: contractIR,\n family: config.family,\n target: config.target,\n adapter: config.adapter,\n extensionPacks: config.extensionPacks,\n });\n\n // Call family instance verify method\n let verifyResult: VerifyDatabaseResult;\n try {\n verifyResult = await withSpinner(\n () =>\n familyInstance.verify({\n driver,\n contractIR,\n expectedTargetId: config.target.targetId,\n contractPath: contractPathAbsolute,\n configPath,\n }),\n {\n message: 'Verifying database schema...',\n flags,\n },\n );\n } catch (error) {\n // Wrap errors from verify() in structured error\n throw errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to verify database: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n\n // If verification failed, throw structured error\n if (!verifyResult.ok && verifyResult.code) {\n if (verifyResult.code === 'PN-RTM-3001') {\n throw errorMarkerMissing();\n }\n if (verifyResult.code === 'PN-RTM-3002') {\n throw errorHashMismatch({\n expected: verifyResult.contract.coreHash,\n ...(verifyResult.marker?.coreHash ? { actual: verifyResult.marker.coreHash } : {}),\n });\n }\n if (verifyResult.code === 'PN-RTM-3003') {\n throw errorTargetMismatch(\n verifyResult.target.expected,\n verifyResult.target.actual ?? 'unknown',\n );\n }\n throw errorRuntime(verifyResult.summary);\n }\n\n // Add blank line after all async operations if spinners were shown\n if (!flags.quiet && flags.json !== 'object' && process.stdout.isTTY) {\n console.log('');\n }\n\n return verifyResult;\n } finally {\n // Ensure driver connection is closed\n await driver.close();\n }\n });\n\n // Handle result - formats output and returns exit code\n const exitCode = handleResult(result, flags, (verifyResult) => {\n // Output based on flags\n if (flags.json === 'object') {\n // JSON output to stdout\n console.log(formatVerifyJson(verifyResult));\n } else {\n // Human-readable output to stdout\n const output = formatVerifyOutput(verifyResult, flags);\n if (output) {\n console.log(output);\n }\n }\n });\n process.exit(exitCode);\n });\n\n return command;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,UAAU,eAAe;AAElC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;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AEL,cAAM,SAAS,mBAAmB,cAAc,KAAK;AACrD,YAAI,QAAQ;AACV,kBAAQ,IAAI,MAAM;AAAA,QACpB;AAAA,MACF;AAAA,IACF,CAAC;AACD,YAAQ,KAAK,QAAQ;AAAA,EACvB,CAAC;AAEH,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/commands/db-verify.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { relative, resolve } from 'node:path';\nimport type { VerifyDatabaseResult } from '@prisma-next/core-control-plane/types';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport { createControlClient } from '../control-api/client';\nimport {\n CliStructuredError,\n errorContractValidationFailed,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorFileNotFound,\n errorHashMismatch,\n errorJsonFormatNotSupported,\n errorMarkerMissing,\n errorRuntime,\n errorTargetMismatch,\n errorUnexpected,\n} from '../utils/cli-errors';\nimport { setCommandDescriptions } from '../utils/command-helpers';\nimport { type GlobalFlags, parseGlobalFlags } from '../utils/global-flags';\nimport {\n formatCommandHelp,\n formatStyledHeader,\n formatVerifyJson,\n formatVerifyOutput,\n} from '../utils/output';\nimport { createProgressAdapter } from '../utils/progress-adapter';\nimport { handleResult } from '../utils/result-handler';\n\ninterface DbVerifyOptions {\n readonly db?: string;\n readonly config?: string;\n readonly json?: string | boolean;\n readonly quiet?: boolean;\n readonly q?: boolean;\n readonly verbose?: boolean;\n readonly v?: boolean;\n readonly vv?: boolean;\n readonly trace?: boolean;\n readonly timestamps?: boolean;\n readonly color?: boolean;\n readonly 'no-color'?: boolean;\n}\n\n/**\n * Maps a VerifyDatabaseResult failure to a CliStructuredError.\n */\nfunction mapVerifyFailure(verifyResult: VerifyDatabaseResult): CliStructuredError {\n if (!verifyResult.ok && verifyResult.code) {\n if (verifyResult.code === 'PN-RTM-3001') {\n return errorMarkerMissing();\n }\n if (verifyResult.code === 'PN-RTM-3002') {\n return errorHashMismatch({\n expected: verifyResult.contract.coreHash,\n ...(verifyResult.marker?.coreHash ? { actual: verifyResult.marker.coreHash } : {}),\n });\n }\n if (verifyResult.code === 'PN-RTM-3003') {\n return errorTargetMismatch(\n verifyResult.target.expected,\n verifyResult.target.actual ?? 'unknown',\n );\n }\n // Unknown code - fall through to runtime error\n }\n return errorRuntime(verifyResult.summary);\n}\n\n/**\n * Executes the db verify command and returns a structured Result.\n */\nasync function executeDbVerifyCommand(\n options: DbVerifyOptions,\n flags: GlobalFlags,\n): Promise<Result<VerifyDatabaseResult, CliStructuredError>> {\n // Load config\n const config = await loadConfig(options.config);\n const configPath = options.config\n ? relative(process.cwd(), resolve(options.config))\n : 'prisma-next.config.ts';\n const contractPathAbsolute = config.contract?.output\n ? resolve(config.contract.output)\n : resolve('src/prisma/contract.json');\n const contractPath = relative(process.cwd(), contractPathAbsolute);\n\n // Output header\n if (flags.json !== 'object' && !flags.quiet) {\n const details: Array<{ label: string; value: string }> = [\n { label: 'config', value: configPath },\n { label: 'contract', value: contractPath },\n ];\n if (options.db) {\n details.push({ label: 'database', value: options.db });\n }\n const header = formatStyledHeader({\n command: 'db verify',\n description: 'Check whether the database has been signed with your contract',\n url: 'https://pris.ly/db-verify',\n details,\n flags,\n });\n console.log(header);\n }\n\n // Load contract file\n let contractJsonContent: string;\n try {\n contractJsonContent = await readFile(contractPathAbsolute, 'utf-8');\n } catch (error) {\n if (error instanceof Error && (error as { code?: string }).code === 'ENOENT') {\n return notOk(\n errorFileNotFound(contractPathAbsolute, {\n why: `Contract file not found at ${contractPathAbsolute}`,\n fix: `Run \\`prisma-next contract emit\\` to generate ${contractPath}, or update \\`config.contract.output\\` in ${configPath}`,\n }),\n );\n }\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n }\n\n let contractJson: Record<string, unknown>;\n try {\n contractJson = JSON.parse(contractJsonContent) as Record<string, unknown>;\n } catch (error) {\n return notOk(\n errorContractValidationFailed(\n `Contract JSON is invalid: ${error instanceof Error ? error.message : String(error)}`,\n { where: { path: contractPathAbsolute } },\n ),\n );\n }\n\n // Resolve database connection (--db flag or config.db.connection)\n const dbConnection = options.db ?? config.db?.connection;\n if (!dbConnection) {\n return notOk(\n errorDatabaseConnectionRequired({\n why: `Database connection is required for db verify (set db.connection in ${configPath}, or pass --db <url>)`,\n }),\n );\n }\n\n // Check for driver\n if (!config.driver) {\n return notOk(errorDriverRequired({ why: 'Config.driver is required for db verify' }));\n }\n\n // Create control client\n const client = createControlClient({\n family: config.family,\n target: config.target,\n adapter: config.adapter,\n driver: config.driver,\n extensionPacks: config.extensionPacks ?? [],\n });\n\n // Create progress adapter\n const onProgress = createProgressAdapter({ flags });\n\n try {\n const verifyResult = await client.verify({\n contractIR: contractJson,\n connection: dbConnection,\n onProgress,\n });\n\n // Add blank line after all async operations if spinners were shown\n if (!flags.quiet && flags.json !== 'object' && process.stdout.isTTY) {\n console.log('');\n }\n\n // If verification failed, map to CLI structured error\n if (!verifyResult.ok) {\n return notOk(mapVerifyFailure(verifyResult));\n }\n\n return ok(verifyResult);\n } catch (error) {\n // Driver already throws CliStructuredError for connection failures\n if (error instanceof CliStructuredError) {\n return notOk(error);\n }\n\n // Wrap unexpected errors\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Unexpected error during db verify: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n } finally {\n await client.close();\n }\n}\n\nexport function createDbVerifyCommand(): Command {\n const command = new Command('verify');\n setCommandDescriptions(\n command,\n 'Check whether the database has been signed with your contract',\n 'Verifies that your database schema matches the emitted contract. Checks table structures,\\n' +\n 'column types, constraints, and codec coverage. Reports any mismatches or missing codecs.',\n );\n command\n .configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n })\n .option('--db <url>', 'Database connection string')\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option('--json [format]', 'Output as JSON (object)', false)\n .option('-q, --quiet', 'Quiet mode: errors only')\n .option('-v, --verbose', 'Verbose output: debug info, timings')\n .option('-vv, --trace', 'Trace output: deep internals, stack traces')\n .option('--timestamps', 'Add timestamps to output')\n .option('--color', 'Force color output')\n .option('--no-color', 'Disable color output')\n .action(async (options: DbVerifyOptions) => {\n const flags = parseGlobalFlags(options);\n\n // Validate JSON format option\n if (flags.json === 'ndjson') {\n const result = notOk(\n errorJsonFormatNotSupported({\n command: 'db verify',\n format: 'ndjson',\n supportedFormats: ['object'],\n }),\n );\n const exitCode = handleResult(result, flags);\n process.exit(exitCode);\n }\n\n const result = await executeDbVerifyCommand(options, flags);\n\n const exitCode = handleResult(result, flags, (verifyResult) => {\n if (flags.json === 'object') {\n console.log(formatVerifyJson(verifyResult));\n } else {\n const output = formatVerifyOutput(verifyResult, flags);\n if (output) {\n console.log(output);\n }\n }\n });\n process.exit(exitCode);\n });\n\n return command;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,UAAU,eAAe;AAElC,SAAS,OAAO,UAAuB;AACvC,SAAS,eAAe;AA6CxB,SAAS,iBAAiB,cAAwD;AAChF,MAAI,CAAC,aAAa,MAAM,aAAa,MAAM;AACzC,QAAI,aAAa,SAAS,eAAe;AACvC,aAAO,mBAAmB;AAAA,IAC5B;AACA,QAAI,aAAa,SAAS,eAAe;AACvC,aAAO,kBAAkB;AAAA,QACvB,UAAU,aAAa,SAAS;AAAA,QAChC,GAAI,aAAa,QAAQ,WAAW,EAAE,QAAQ,aAAa,OAAO,SAAS,IAAI,CAAC;AAAA,MAClF,CAAC;AAAA,IACH;AACA,QAAI,aAAa,SAAS,eAAe;AACvC,aAAO;AAAA,QACL,aAAa,OAAO;AAAA,QACpB,aAAa,OAAO,UAAU;AAAA,MAChC;AAAA,IACF;AAAA,EAEF;AACA,SAAO,aAAa,aAAa,OAAO;AAC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I,QAAQ;AACV,kBAAQ,IAAI,MAAM;AAAA,QACpB;AAAA,MACF;AAAA,IACF,CAAC;AACD,YAAQ,KAAK,QAAQ;AAAA,EACvB,CAAC;AAEH,SAAO;AACT;","names":["result","exitCode"]}
|
package/dist/config-loader.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { PrismaNextConfig } from '@prisma-next/core-control-plane/config-types';
|
|
2
|
-
|
|
1
|
+
import type { PrismaNextConfig } from '@prisma-next/core-control-plane/config-types';
|
|
3
2
|
/**
|
|
4
3
|
* Loads the Prisma Next config from a TypeScript file.
|
|
5
4
|
* Supports both default export and named export.
|
|
@@ -9,6 +8,5 @@ import { PrismaNextConfig } from '@prisma-next/core-control-plane/config-types';
|
|
|
9
8
|
* @returns The loaded config object.
|
|
10
9
|
* @throws Error if config file doesn't exist or is invalid.
|
|
11
10
|
*/
|
|
12
|
-
declare function loadConfig(configPath?: string): Promise<PrismaNextConfig>;
|
|
13
|
-
|
|
14
|
-
export { loadConfig };
|
|
11
|
+
export declare function loadConfig(configPath?: string): Promise<PrismaNextConfig>;
|
|
12
|
+
//# sourceMappingURL=config-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../src/config-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AAKrF;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA4D/E"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ControlClient, ControlClientOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a programmatic control client for Prisma Next operations.
|
|
4
|
+
*
|
|
5
|
+
* The client accepts framework component descriptors at creation time,
|
|
6
|
+
* manages driver lifecycle via connect()/close(), and exposes domain
|
|
7
|
+
* operations that delegate to the existing family instance methods.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link ControlClient} for the client interface
|
|
10
|
+
* @see README.md "Programmatic Control API" section for usage examples
|
|
11
|
+
*/
|
|
12
|
+
export declare function createControlClient(options: ControlClientOptions): ControlClient;
|
|
13
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/control-api/client.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EASrB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAEhF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { TargetBoundComponentDescriptor } from '@prisma-next/contract/framework-components';
|
|
2
|
+
import type { ContractIR } from '@prisma-next/contract/ir';
|
|
3
|
+
import type { ControlDriverInstance, ControlFamilyInstance, TargetMigrationsCapability } from '@prisma-next/core-control-plane/types';
|
|
4
|
+
import type { DbInitResult, OnControlProgress } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* Options for executing dbInit operation.
|
|
7
|
+
*/
|
|
8
|
+
export interface ExecuteDbInitOptions<TFamilyId extends string, TTargetId extends string> {
|
|
9
|
+
readonly driver: ControlDriverInstance<TFamilyId, TTargetId>;
|
|
10
|
+
readonly familyInstance: ControlFamilyInstance<TFamilyId>;
|
|
11
|
+
readonly contractIR: ContractIR;
|
|
12
|
+
readonly mode: 'plan' | 'apply';
|
|
13
|
+
readonly migrations: TargetMigrationsCapability<TFamilyId, TTargetId, ControlFamilyInstance<TFamilyId>>;
|
|
14
|
+
readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, TTargetId>>;
|
|
15
|
+
/** Optional progress callback for observing operation progress */
|
|
16
|
+
readonly onProgress?: OnControlProgress;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Executes the dbInit operation.
|
|
20
|
+
*
|
|
21
|
+
* This is the core logic extracted from the CLI command, without any file I/O,
|
|
22
|
+
* process.exit(), or console output. It uses the Result pattern to return
|
|
23
|
+
* success or failure details.
|
|
24
|
+
*
|
|
25
|
+
* @param options - The options for executing dbInit
|
|
26
|
+
* @returns Result with DbInitSuccess on success, DbInitFailure on failure
|
|
27
|
+
*/
|
|
28
|
+
export declare function executeDbInit<TFamilyId extends string, TTargetId extends string>(options: ExecuteDbInitOptions<TFamilyId, TTargetId>): Promise<DbInitResult>;
|
|
29
|
+
//# sourceMappingURL=db-init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-init.d.ts","sourceRoot":"","sources":["../../../src/control-api/operations/db-init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AACjG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EAKrB,0BAA0B,EAC3B,MAAM,uCAAuC,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAiB,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,SAAS,SAAS,MAAM,EAAE,SAAS,SAAS,MAAM;IACtF,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC7D,QAAQ,CAAC,cAAc,EAAE,qBAAqB,CAAC,SAAS,CAAC,CAAC;IAC1D,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,0BAA0B,CAC7C,SAAS,EACT,SAAS,EACT,qBAAqB,CAAC,SAAS,CAAC,CACjC,CAAC;IACF,QAAQ,CAAC,mBAAmB,EAAE,aAAa,CAAC,8BAA8B,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;IAClG,kEAAkE;IAClE,QAAQ,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAC;CACzC;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,SAAS,SAAS,MAAM,EAAE,SAAS,SAAS,MAAM,EACpF,OAAO,EAAE,oBAAoB,CAAC,SAAS,EAAE,SAAS,CAAC,GAClD,OAAO,CAAC,YAAY,CAAC,CA4OvB"}
|