@prisma-next/cli 0.3.0-dev.17 → 0.3.0-dev.18
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/dist/chunk-BO73VO4I.js +45 -0
- package/dist/chunk-BO73VO4I.js.map +1 -0
- package/dist/{chunk-VI2YETW7.js → chunk-MPSJAVF6.js} +4 -2
- package/dist/{chunk-U6QI3AZ3.js → chunk-RIONCN4I.js} +45 -6
- package/dist/chunk-RIONCN4I.js.map +1 -0
- package/dist/{chunk-74IELXRA.js → chunk-RPYY5SM7.js} +273 -19
- package/dist/chunk-RPYY5SM7.js.map +1 -0
- package/dist/cli.js +708 -551
- package/dist/cli.js.map +1 -1
- package/dist/commands/contract-emit.js +2 -3
- package/dist/commands/db-init.js +5 -46
- package/dist/commands/db-init.js.map +1 -1
- package/dist/commands/db-introspect.d.ts.map +1 -1
- package/dist/commands/db-introspect.js +107 -133
- package/dist/commands/db-introspect.js.map +1 -1
- package/dist/commands/db-schema-verify.d.ts.map +1 -1
- package/dist/commands/db-schema-verify.js +119 -107
- package/dist/commands/db-schema-verify.js.map +1 -1
- package/dist/commands/db-sign.d.ts.map +1 -1
- package/dist/commands/db-sign.js +151 -150
- package/dist/commands/db-sign.js.map +1 -1
- package/dist/commands/db-verify.d.ts.map +1 -1
- package/dist/commands/db-verify.js +141 -116
- package/dist/commands/db-verify.js.map +1 -1
- package/dist/control-api/client.d.ts.map +1 -1
- package/dist/control-api/types.d.ts +41 -0
- package/dist/control-api/types.d.ts.map +1 -1
- package/dist/exports/control-api.js +2 -3
- package/dist/exports/index.js +2 -3
- package/dist/exports/index.js.map +1 -1
- package/package.json +10 -10
- package/src/commands/contract-emit.ts +1 -1
- package/src/commands/db-introspect.ts +151 -178
- package/src/commands/db-schema-verify.ts +150 -143
- package/src/commands/db-sign.ts +202 -196
- package/src/commands/db-verify.ts +179 -149
- package/src/control-api/client.ts +256 -22
- package/src/control-api/types.ts +42 -0
- package/dist/chunk-5MPKZYVI.js +0 -47
- package/dist/chunk-5MPKZYVI.js.map +0 -1
- package/dist/chunk-6EPKRATC.js +0 -91
- package/dist/chunk-6EPKRATC.js.map +0 -1
- package/dist/chunk-74IELXRA.js.map +0 -1
- package/dist/chunk-U6QI3AZ3.js.map +0 -1
- /package/dist/{chunk-VI2YETW7.js.map → chunk-MPSJAVF6.js.map} +0 -0
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { relative, resolve } from 'node:path';
|
|
3
|
-
import type {
|
|
3
|
+
import type { VerifyDatabaseResult } from '@prisma-next/core-control-plane/types';
|
|
4
|
+
import { notOk, ok, type Result } from '@prisma-next/utils/result';
|
|
5
|
+
import { Command } from 'commander';
|
|
6
|
+
import { loadConfig } from '../config-loader';
|
|
7
|
+
import { createControlClient } from '../control-api/client';
|
|
4
8
|
import {
|
|
9
|
+
CliStructuredError,
|
|
10
|
+
errorContractValidationFailed,
|
|
5
11
|
errorDatabaseConnectionRequired,
|
|
6
12
|
errorDriverRequired,
|
|
7
13
|
errorFileNotFound,
|
|
8
14
|
errorHashMismatch,
|
|
15
|
+
errorJsonFormatNotSupported,
|
|
9
16
|
errorMarkerMissing,
|
|
10
17
|
errorRuntime,
|
|
11
18
|
errorTargetMismatch,
|
|
12
19
|
errorUnexpected,
|
|
13
|
-
} from '
|
|
14
|
-
import type { VerifyDatabaseResult } from '@prisma-next/core-control-plane/types';
|
|
15
|
-
import { createControlPlaneStack } from '@prisma-next/core-control-plane/types';
|
|
16
|
-
import { Command } from 'commander';
|
|
17
|
-
import { loadConfig } from '../config-loader';
|
|
18
|
-
import { performAction } from '../utils/action';
|
|
20
|
+
} from '../utils/cli-errors';
|
|
19
21
|
import { setCommandDescriptions } from '../utils/command-helpers';
|
|
20
|
-
import {
|
|
21
|
-
import { parseGlobalFlags } from '../utils/global-flags';
|
|
22
|
+
import { type GlobalFlags, parseGlobalFlags } from '../utils/global-flags';
|
|
22
23
|
import {
|
|
23
24
|
formatCommandHelp,
|
|
24
25
|
formatStyledHeader,
|
|
25
26
|
formatVerifyJson,
|
|
26
27
|
formatVerifyOutput,
|
|
27
28
|
} from '../utils/output';
|
|
29
|
+
import { createProgressAdapter } from '../utils/progress-adapter';
|
|
28
30
|
import { handleResult } from '../utils/result-handler';
|
|
29
|
-
import { withSpinner } from '../utils/spinner';
|
|
30
31
|
|
|
31
32
|
interface DbVerifyOptions {
|
|
32
33
|
readonly db?: string;
|
|
@@ -43,6 +44,161 @@ interface DbVerifyOptions {
|
|
|
43
44
|
readonly 'no-color'?: boolean;
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Maps a VerifyDatabaseResult failure to a CliStructuredError.
|
|
49
|
+
*/
|
|
50
|
+
function mapVerifyFailure(verifyResult: VerifyDatabaseResult): CliStructuredError {
|
|
51
|
+
if (!verifyResult.ok && verifyResult.code) {
|
|
52
|
+
if (verifyResult.code === 'PN-RTM-3001') {
|
|
53
|
+
return errorMarkerMissing();
|
|
54
|
+
}
|
|
55
|
+
if (verifyResult.code === 'PN-RTM-3002') {
|
|
56
|
+
return errorHashMismatch({
|
|
57
|
+
expected: verifyResult.contract.coreHash,
|
|
58
|
+
...(verifyResult.marker?.coreHash ? { actual: verifyResult.marker.coreHash } : {}),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (verifyResult.code === 'PN-RTM-3003') {
|
|
62
|
+
return errorTargetMismatch(
|
|
63
|
+
verifyResult.target.expected,
|
|
64
|
+
verifyResult.target.actual ?? 'unknown',
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
// Unknown code - fall through to runtime error
|
|
68
|
+
}
|
|
69
|
+
return errorRuntime(verifyResult.summary);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Executes the db verify command and returns a structured Result.
|
|
74
|
+
*/
|
|
75
|
+
async function executeDbVerifyCommand(
|
|
76
|
+
options: DbVerifyOptions,
|
|
77
|
+
flags: GlobalFlags,
|
|
78
|
+
): Promise<Result<VerifyDatabaseResult, CliStructuredError>> {
|
|
79
|
+
// Load config
|
|
80
|
+
const config = await loadConfig(options.config);
|
|
81
|
+
const configPath = options.config
|
|
82
|
+
? relative(process.cwd(), resolve(options.config))
|
|
83
|
+
: 'prisma-next.config.ts';
|
|
84
|
+
const contractPathAbsolute = config.contract?.output
|
|
85
|
+
? resolve(config.contract.output)
|
|
86
|
+
: resolve('src/prisma/contract.json');
|
|
87
|
+
const contractPath = relative(process.cwd(), contractPathAbsolute);
|
|
88
|
+
|
|
89
|
+
// Output header
|
|
90
|
+
if (flags.json !== 'object' && !flags.quiet) {
|
|
91
|
+
const details: Array<{ label: string; value: string }> = [
|
|
92
|
+
{ label: 'config', value: configPath },
|
|
93
|
+
{ label: 'contract', value: contractPath },
|
|
94
|
+
];
|
|
95
|
+
if (options.db) {
|
|
96
|
+
details.push({ label: 'database', value: options.db });
|
|
97
|
+
}
|
|
98
|
+
const header = formatStyledHeader({
|
|
99
|
+
command: 'db verify',
|
|
100
|
+
description: 'Check whether the database has been signed with your contract',
|
|
101
|
+
url: 'https://pris.ly/db-verify',
|
|
102
|
+
details,
|
|
103
|
+
flags,
|
|
104
|
+
});
|
|
105
|
+
console.log(header);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Load contract file
|
|
109
|
+
let contractJsonContent: string;
|
|
110
|
+
try {
|
|
111
|
+
contractJsonContent = await readFile(contractPathAbsolute, 'utf-8');
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (error instanceof Error && (error as { code?: string }).code === 'ENOENT') {
|
|
114
|
+
return notOk(
|
|
115
|
+
errorFileNotFound(contractPathAbsolute, {
|
|
116
|
+
why: `Contract file not found at ${contractPathAbsolute}`,
|
|
117
|
+
fix: `Run \`prisma-next contract emit\` to generate ${contractPath}, or update \`config.contract.output\` in ${configPath}`,
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return notOk(
|
|
122
|
+
errorUnexpected(error instanceof Error ? error.message : String(error), {
|
|
123
|
+
why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`,
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let contractJson: Record<string, unknown>;
|
|
129
|
+
try {
|
|
130
|
+
contractJson = JSON.parse(contractJsonContent) as Record<string, unknown>;
|
|
131
|
+
} catch (error) {
|
|
132
|
+
return notOk(
|
|
133
|
+
errorContractValidationFailed(
|
|
134
|
+
`Contract JSON is invalid: ${error instanceof Error ? error.message : String(error)}`,
|
|
135
|
+
{ where: { path: contractPathAbsolute } },
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Resolve database connection (--db flag or config.db.connection)
|
|
141
|
+
const dbConnection = options.db ?? config.db?.connection;
|
|
142
|
+
if (!dbConnection) {
|
|
143
|
+
return notOk(
|
|
144
|
+
errorDatabaseConnectionRequired({
|
|
145
|
+
why: `Database connection is required for db verify (set db.connection in ${configPath}, or pass --db <url>)`,
|
|
146
|
+
}),
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Check for driver
|
|
151
|
+
if (!config.driver) {
|
|
152
|
+
return notOk(errorDriverRequired({ why: 'Config.driver is required for db verify' }));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Create control client
|
|
156
|
+
const client = createControlClient({
|
|
157
|
+
family: config.family,
|
|
158
|
+
target: config.target,
|
|
159
|
+
adapter: config.adapter,
|
|
160
|
+
driver: config.driver,
|
|
161
|
+
extensionPacks: config.extensionPacks ?? [],
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Create progress adapter
|
|
165
|
+
const onProgress = createProgressAdapter({ flags });
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
const verifyResult = await client.verify({
|
|
169
|
+
contractIR: contractJson,
|
|
170
|
+
connection: dbConnection,
|
|
171
|
+
onProgress,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// Add blank line after all async operations if spinners were shown
|
|
175
|
+
if (!flags.quiet && flags.json !== 'object' && process.stdout.isTTY) {
|
|
176
|
+
console.log('');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// If verification failed, map to CLI structured error
|
|
180
|
+
if (!verifyResult.ok) {
|
|
181
|
+
return notOk(mapVerifyFailure(verifyResult));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return ok(verifyResult);
|
|
185
|
+
} catch (error) {
|
|
186
|
+
// Driver already throws CliStructuredError for connection failures
|
|
187
|
+
if (error instanceof CliStructuredError) {
|
|
188
|
+
return notOk(error);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Wrap unexpected errors
|
|
192
|
+
return notOk(
|
|
193
|
+
errorUnexpected(error instanceof Error ? error.message : String(error), {
|
|
194
|
+
why: `Unexpected error during db verify: ${error instanceof Error ? error.message : String(error)}`,
|
|
195
|
+
}),
|
|
196
|
+
);
|
|
197
|
+
} finally {
|
|
198
|
+
await client.close();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
46
202
|
export function createDbVerifyCommand(): Command {
|
|
47
203
|
const command = new Command('verify');
|
|
48
204
|
setCommandDescriptions(
|
|
@@ -60,7 +216,7 @@ export function createDbVerifyCommand(): Command {
|
|
|
60
216
|
})
|
|
61
217
|
.option('--db <url>', 'Database connection string')
|
|
62
218
|
.option('--config <path>', 'Path to prisma-next.config.ts')
|
|
63
|
-
.option('--json [format]', 'Output as JSON (object
|
|
219
|
+
.option('--json [format]', 'Output as JSON (object)', false)
|
|
64
220
|
.option('-q, --quiet', 'Quiet mode: errors only')
|
|
65
221
|
.option('-v, --verbose', 'Verbose output: debug info, timings')
|
|
66
222
|
.option('-vv, --trace', 'Trace output: deep internals, stack traces')
|
|
@@ -70,151 +226,25 @@ export function createDbVerifyCommand(): Command {
|
|
|
70
226
|
.action(async (options: DbVerifyOptions) => {
|
|
71
227
|
const flags = parseGlobalFlags(options);
|
|
72
228
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
const configPath = options.config
|
|
78
|
-
? relative(process.cwd(), resolve(options.config))
|
|
79
|
-
: 'prisma-next.config.ts';
|
|
80
|
-
const contractPathAbsolute = config.contract?.output
|
|
81
|
-
? resolve(config.contract.output)
|
|
82
|
-
: resolve('src/prisma/contract.json');
|
|
83
|
-
// Convert to relative path for display
|
|
84
|
-
const contractPath = relative(process.cwd(), contractPathAbsolute);
|
|
85
|
-
|
|
86
|
-
// Output header (only for human-readable output)
|
|
87
|
-
if (flags.json !== 'object' && !flags.quiet) {
|
|
88
|
-
const details: Array<{ label: string; value: string }> = [
|
|
89
|
-
{ label: 'config', value: configPath },
|
|
90
|
-
{ label: 'contract', value: contractPath },
|
|
91
|
-
];
|
|
92
|
-
if (options.db) {
|
|
93
|
-
details.push({ label: 'database', value: options.db });
|
|
94
|
-
}
|
|
95
|
-
const header = formatStyledHeader({
|
|
229
|
+
// Validate JSON format option
|
|
230
|
+
if (flags.json === 'ndjson') {
|
|
231
|
+
const result = notOk(
|
|
232
|
+
errorJsonFormatNotSupported({
|
|
96
233
|
command: 'db verify',
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// Load contract file (file I/O)
|
|
106
|
-
let contractJsonContent: string;
|
|
107
|
-
try {
|
|
108
|
-
contractJsonContent = await readFile(contractPathAbsolute, 'utf-8');
|
|
109
|
-
} catch (error) {
|
|
110
|
-
if (error instanceof Error && (error as { code?: string }).code === 'ENOENT') {
|
|
111
|
-
throw errorFileNotFound(contractPathAbsolute, {
|
|
112
|
-
why: `Contract file not found at ${contractPathAbsolute}`,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
throw errorUnexpected(error instanceof Error ? error.message : String(error), {
|
|
116
|
-
why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
const contractJson = JSON.parse(contractJsonContent) as Record<string, unknown>;
|
|
120
|
-
|
|
121
|
-
// Resolve database connection (--db flag or config.db.connection)
|
|
122
|
-
const dbConnection = options.db ?? config.db?.connection;
|
|
123
|
-
if (!dbConnection) {
|
|
124
|
-
throw errorDatabaseConnectionRequired();
|
|
125
|
-
}
|
|
234
|
+
format: 'ndjson',
|
|
235
|
+
supportedFormats: ['object'],
|
|
236
|
+
}),
|
|
237
|
+
);
|
|
238
|
+
const exitCode = handleResult(result, flags);
|
|
239
|
+
process.exit(exitCode);
|
|
240
|
+
}
|
|
126
241
|
|
|
127
|
-
|
|
128
|
-
if (!config.driver) {
|
|
129
|
-
throw errorDriverRequired();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Store driver descriptor after null check
|
|
133
|
-
const driverDescriptor = config.driver;
|
|
134
|
-
|
|
135
|
-
const driver = await withSpinner(() => driverDescriptor.create(dbConnection), {
|
|
136
|
-
message: 'Connecting to database...',
|
|
137
|
-
flags,
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
try {
|
|
141
|
-
// Create family instance
|
|
142
|
-
const stack = createControlPlaneStack({
|
|
143
|
-
target: config.target,
|
|
144
|
-
adapter: config.adapter,
|
|
145
|
-
driver: driverDescriptor,
|
|
146
|
-
extensionPacks: config.extensionPacks,
|
|
147
|
-
});
|
|
148
|
-
const familyInstance = config.family.create(stack);
|
|
149
|
-
|
|
150
|
-
// Validate contract using instance validator
|
|
151
|
-
const contractIR = familyInstance.validateContractIR(contractJson) as ContractIR;
|
|
152
|
-
assertContractRequirementsSatisfied({ contract: contractIR, stack });
|
|
153
|
-
|
|
154
|
-
// Call family instance verify method
|
|
155
|
-
let verifyResult: VerifyDatabaseResult;
|
|
156
|
-
try {
|
|
157
|
-
verifyResult = await withSpinner(
|
|
158
|
-
() =>
|
|
159
|
-
familyInstance.verify({
|
|
160
|
-
driver,
|
|
161
|
-
contractIR,
|
|
162
|
-
expectedTargetId: config.target.targetId,
|
|
163
|
-
contractPath: contractPathAbsolute,
|
|
164
|
-
configPath,
|
|
165
|
-
}),
|
|
166
|
-
{
|
|
167
|
-
message: 'Verifying database schema...',
|
|
168
|
-
flags,
|
|
169
|
-
},
|
|
170
|
-
);
|
|
171
|
-
} catch (error) {
|
|
172
|
-
// Wrap errors from verify() in structured error
|
|
173
|
-
throw errorUnexpected(error instanceof Error ? error.message : String(error), {
|
|
174
|
-
why: `Failed to verify database: ${error instanceof Error ? error.message : String(error)}`,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// If verification failed, throw structured error
|
|
179
|
-
if (!verifyResult.ok && verifyResult.code) {
|
|
180
|
-
if (verifyResult.code === 'PN-RTM-3001') {
|
|
181
|
-
throw errorMarkerMissing();
|
|
182
|
-
}
|
|
183
|
-
if (verifyResult.code === 'PN-RTM-3002') {
|
|
184
|
-
throw errorHashMismatch({
|
|
185
|
-
expected: verifyResult.contract.coreHash,
|
|
186
|
-
...(verifyResult.marker?.coreHash ? { actual: verifyResult.marker.coreHash } : {}),
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
if (verifyResult.code === 'PN-RTM-3003') {
|
|
190
|
-
throw errorTargetMismatch(
|
|
191
|
-
verifyResult.target.expected,
|
|
192
|
-
verifyResult.target.actual ?? 'unknown',
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
throw errorRuntime(verifyResult.summary);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Add blank line after all async operations if spinners were shown
|
|
199
|
-
if (!flags.quiet && flags.json !== 'object' && process.stdout.isTTY) {
|
|
200
|
-
console.log('');
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return verifyResult;
|
|
204
|
-
} finally {
|
|
205
|
-
// Ensure driver connection is closed
|
|
206
|
-
await driver.close();
|
|
207
|
-
}
|
|
208
|
-
});
|
|
242
|
+
const result = await executeDbVerifyCommand(options, flags);
|
|
209
243
|
|
|
210
|
-
// Handle result - formats output and returns exit code
|
|
211
244
|
const exitCode = handleResult(result, flags, (verifyResult) => {
|
|
212
|
-
// Output based on flags
|
|
213
245
|
if (flags.json === 'object') {
|
|
214
|
-
// JSON output to stdout
|
|
215
246
|
console.log(formatVerifyJson(verifyResult));
|
|
216
247
|
} else {
|
|
217
|
-
// Human-readable output to stdout
|
|
218
248
|
const output = formatVerifyOutput(verifyResult, flags);
|
|
219
249
|
if (output) {
|
|
220
250
|
console.log(output);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TargetBoundComponentDescriptor } from '@prisma-next/contract/framework-components';
|
|
2
|
+
import type { CoreSchemaView } from '@prisma-next/core-control-plane/schema-view';
|
|
2
3
|
import { createControlPlaneStack } from '@prisma-next/core-control-plane/stack';
|
|
3
4
|
import type {
|
|
4
5
|
ControlDriverInstance,
|
|
@@ -148,51 +149,220 @@ class ControlClientImpl implements ControlClient {
|
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
async verify(options: VerifyOptions): Promise<VerifyDatabaseResult> {
|
|
152
|
+
const { onProgress } = options;
|
|
153
|
+
|
|
154
|
+
// Connect with progress span if connection provided
|
|
155
|
+
if (options.connection !== undefined) {
|
|
156
|
+
onProgress?.({
|
|
157
|
+
action: 'verify',
|
|
158
|
+
kind: 'spanStart',
|
|
159
|
+
spanId: 'connect',
|
|
160
|
+
label: 'Connecting to database...',
|
|
161
|
+
});
|
|
162
|
+
try {
|
|
163
|
+
await this.connect(options.connection);
|
|
164
|
+
onProgress?.({
|
|
165
|
+
action: 'verify',
|
|
166
|
+
kind: 'spanEnd',
|
|
167
|
+
spanId: 'connect',
|
|
168
|
+
outcome: 'ok',
|
|
169
|
+
});
|
|
170
|
+
} catch (error) {
|
|
171
|
+
onProgress?.({
|
|
172
|
+
action: 'verify',
|
|
173
|
+
kind: 'spanEnd',
|
|
174
|
+
spanId: 'connect',
|
|
175
|
+
outcome: 'error',
|
|
176
|
+
});
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
151
181
|
const { driver, familyInstance } = await this.ensureConnected();
|
|
152
182
|
|
|
153
183
|
// Validate contract using family instance
|
|
154
184
|
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
155
185
|
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
contractIR,
|
|
163
|
-
expectedTargetId: this.options.target.targetId,
|
|
164
|
-
contractPath: '',
|
|
186
|
+
// Emit verify span
|
|
187
|
+
onProgress?.({
|
|
188
|
+
action: 'verify',
|
|
189
|
+
kind: 'spanStart',
|
|
190
|
+
spanId: 'verify',
|
|
191
|
+
label: 'Verifying contract marker...',
|
|
165
192
|
});
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
// Delegate to family instance verify method
|
|
196
|
+
// Note: We pass empty strings for contractPath/configPath since the programmatic
|
|
197
|
+
// API doesn't deal with file paths. The family instance accepts these as optional
|
|
198
|
+
// metadata for error reporting.
|
|
199
|
+
const result = await familyInstance.verify({
|
|
200
|
+
driver,
|
|
201
|
+
contractIR,
|
|
202
|
+
expectedTargetId: this.options.target.targetId,
|
|
203
|
+
contractPath: '',
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
onProgress?.({
|
|
207
|
+
action: 'verify',
|
|
208
|
+
kind: 'spanEnd',
|
|
209
|
+
spanId: 'verify',
|
|
210
|
+
outcome: result.ok ? 'ok' : 'error',
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
return result;
|
|
214
|
+
} catch (error) {
|
|
215
|
+
onProgress?.({
|
|
216
|
+
action: 'verify',
|
|
217
|
+
kind: 'spanEnd',
|
|
218
|
+
spanId: 'verify',
|
|
219
|
+
outcome: 'error',
|
|
220
|
+
});
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
166
223
|
}
|
|
167
224
|
|
|
168
225
|
async schemaVerify(options: SchemaVerifyOptions): Promise<VerifyDatabaseSchemaResult> {
|
|
226
|
+
const { onProgress } = options;
|
|
227
|
+
|
|
228
|
+
// Connect with progress span if connection provided
|
|
229
|
+
if (options.connection !== undefined) {
|
|
230
|
+
onProgress?.({
|
|
231
|
+
action: 'schemaVerify',
|
|
232
|
+
kind: 'spanStart',
|
|
233
|
+
spanId: 'connect',
|
|
234
|
+
label: 'Connecting to database...',
|
|
235
|
+
});
|
|
236
|
+
try {
|
|
237
|
+
await this.connect(options.connection);
|
|
238
|
+
onProgress?.({
|
|
239
|
+
action: 'schemaVerify',
|
|
240
|
+
kind: 'spanEnd',
|
|
241
|
+
spanId: 'connect',
|
|
242
|
+
outcome: 'ok',
|
|
243
|
+
});
|
|
244
|
+
} catch (error) {
|
|
245
|
+
onProgress?.({
|
|
246
|
+
action: 'schemaVerify',
|
|
247
|
+
kind: 'spanEnd',
|
|
248
|
+
spanId: 'connect',
|
|
249
|
+
outcome: 'error',
|
|
250
|
+
});
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
169
255
|
const { driver, familyInstance, frameworkComponents } = await this.ensureConnected();
|
|
170
256
|
|
|
171
257
|
// Validate contract using family instance
|
|
172
258
|
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
173
259
|
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
frameworkComponents,
|
|
260
|
+
// Emit schemaVerify span
|
|
261
|
+
onProgress?.({
|
|
262
|
+
action: 'schemaVerify',
|
|
263
|
+
kind: 'spanStart',
|
|
264
|
+
spanId: 'schemaVerify',
|
|
265
|
+
label: 'Verifying database schema...',
|
|
181
266
|
});
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
// Delegate to family instance schemaVerify method
|
|
270
|
+
const result = await familyInstance.schemaVerify({
|
|
271
|
+
driver,
|
|
272
|
+
contractIR,
|
|
273
|
+
strict: options.strict ?? false,
|
|
274
|
+
contractPath: '',
|
|
275
|
+
frameworkComponents,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
onProgress?.({
|
|
279
|
+
action: 'schemaVerify',
|
|
280
|
+
kind: 'spanEnd',
|
|
281
|
+
spanId: 'schemaVerify',
|
|
282
|
+
outcome: result.ok ? 'ok' : 'error',
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
return result;
|
|
286
|
+
} catch (error) {
|
|
287
|
+
onProgress?.({
|
|
288
|
+
action: 'schemaVerify',
|
|
289
|
+
kind: 'spanEnd',
|
|
290
|
+
spanId: 'schemaVerify',
|
|
291
|
+
outcome: 'error',
|
|
292
|
+
});
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
182
295
|
}
|
|
183
296
|
|
|
184
297
|
async sign(options: SignOptions): Promise<SignDatabaseResult> {
|
|
298
|
+
const { onProgress } = options;
|
|
299
|
+
|
|
300
|
+
// Connect with progress span if connection provided
|
|
301
|
+
if (options.connection !== undefined) {
|
|
302
|
+
onProgress?.({
|
|
303
|
+
action: 'sign',
|
|
304
|
+
kind: 'spanStart',
|
|
305
|
+
spanId: 'connect',
|
|
306
|
+
label: 'Connecting to database...',
|
|
307
|
+
});
|
|
308
|
+
try {
|
|
309
|
+
await this.connect(options.connection);
|
|
310
|
+
onProgress?.({
|
|
311
|
+
action: 'sign',
|
|
312
|
+
kind: 'spanEnd',
|
|
313
|
+
spanId: 'connect',
|
|
314
|
+
outcome: 'ok',
|
|
315
|
+
});
|
|
316
|
+
} catch (error) {
|
|
317
|
+
onProgress?.({
|
|
318
|
+
action: 'sign',
|
|
319
|
+
kind: 'spanEnd',
|
|
320
|
+
spanId: 'connect',
|
|
321
|
+
outcome: 'error',
|
|
322
|
+
});
|
|
323
|
+
throw error;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
185
327
|
const { driver, familyInstance } = await this.ensureConnected();
|
|
186
328
|
|
|
187
329
|
// Validate contract using family instance
|
|
188
330
|
const contractIR = familyInstance.validateContractIR(options.contractIR);
|
|
189
331
|
|
|
190
|
-
//
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
332
|
+
// Emit sign span
|
|
333
|
+
onProgress?.({
|
|
334
|
+
action: 'sign',
|
|
335
|
+
kind: 'spanStart',
|
|
336
|
+
spanId: 'sign',
|
|
337
|
+
label: 'Signing database...',
|
|
195
338
|
});
|
|
339
|
+
|
|
340
|
+
try {
|
|
341
|
+
// Delegate to family instance sign method
|
|
342
|
+
const result = await familyInstance.sign({
|
|
343
|
+
driver,
|
|
344
|
+
contractIR,
|
|
345
|
+
contractPath: options.contractPath ?? '',
|
|
346
|
+
...(options.configPath ? { configPath: options.configPath } : {}),
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
onProgress?.({
|
|
350
|
+
action: 'sign',
|
|
351
|
+
kind: 'spanEnd',
|
|
352
|
+
spanId: 'sign',
|
|
353
|
+
outcome: 'ok',
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
return result;
|
|
357
|
+
} catch (error) {
|
|
358
|
+
onProgress?.({
|
|
359
|
+
action: 'sign',
|
|
360
|
+
kind: 'spanEnd',
|
|
361
|
+
spanId: 'sign',
|
|
362
|
+
outcome: 'error',
|
|
363
|
+
});
|
|
364
|
+
throw error;
|
|
365
|
+
}
|
|
196
366
|
}
|
|
197
367
|
|
|
198
368
|
async dbInit(options: DbInitOptions): Promise<DbInitResult> {
|
|
@@ -248,12 +418,76 @@ class ControlClientImpl implements ControlClient {
|
|
|
248
418
|
}
|
|
249
419
|
|
|
250
420
|
async introspect(options?: IntrospectOptions): Promise<unknown> {
|
|
421
|
+
const onProgress = options?.onProgress;
|
|
422
|
+
|
|
423
|
+
// Connect with progress span if connection provided
|
|
424
|
+
if (options?.connection !== undefined) {
|
|
425
|
+
onProgress?.({
|
|
426
|
+
action: 'introspect',
|
|
427
|
+
kind: 'spanStart',
|
|
428
|
+
spanId: 'connect',
|
|
429
|
+
label: 'Connecting to database...',
|
|
430
|
+
});
|
|
431
|
+
try {
|
|
432
|
+
await this.connect(options.connection);
|
|
433
|
+
onProgress?.({
|
|
434
|
+
action: 'introspect',
|
|
435
|
+
kind: 'spanEnd',
|
|
436
|
+
spanId: 'connect',
|
|
437
|
+
outcome: 'ok',
|
|
438
|
+
});
|
|
439
|
+
} catch (error) {
|
|
440
|
+
onProgress?.({
|
|
441
|
+
action: 'introspect',
|
|
442
|
+
kind: 'spanEnd',
|
|
443
|
+
spanId: 'connect',
|
|
444
|
+
outcome: 'error',
|
|
445
|
+
});
|
|
446
|
+
throw error;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
251
450
|
const { driver, familyInstance } = await this.ensureConnected();
|
|
252
451
|
|
|
253
452
|
// TODO: Pass schema option to familyInstance.introspect when schema filtering is implemented
|
|
254
453
|
const _schema = options?.schema;
|
|
255
454
|
void _schema;
|
|
256
455
|
|
|
257
|
-
|
|
456
|
+
// Emit introspect span
|
|
457
|
+
onProgress?.({
|
|
458
|
+
action: 'introspect',
|
|
459
|
+
kind: 'spanStart',
|
|
460
|
+
spanId: 'introspect',
|
|
461
|
+
label: 'Introspecting database schema...',
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
try {
|
|
465
|
+
const result = await familyInstance.introspect({ driver });
|
|
466
|
+
|
|
467
|
+
onProgress?.({
|
|
468
|
+
action: 'introspect',
|
|
469
|
+
kind: 'spanEnd',
|
|
470
|
+
spanId: 'introspect',
|
|
471
|
+
outcome: 'ok',
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
return result;
|
|
475
|
+
} catch (error) {
|
|
476
|
+
onProgress?.({
|
|
477
|
+
action: 'introspect',
|
|
478
|
+
kind: 'spanEnd',
|
|
479
|
+
spanId: 'introspect',
|
|
480
|
+
outcome: 'error',
|
|
481
|
+
});
|
|
482
|
+
throw error;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
toSchemaView(schemaIR: unknown): CoreSchemaView | undefined {
|
|
487
|
+
this.init();
|
|
488
|
+
if (this.familyInstance?.toSchemaView) {
|
|
489
|
+
return this.familyInstance.toSchemaView(schemaIR);
|
|
490
|
+
}
|
|
491
|
+
return undefined;
|
|
258
492
|
}
|
|
259
493
|
}
|