@prisma-next/cli 0.3.0-pr.99.6 → 0.3.0
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/LICENSE +201 -0
- package/README.md +381 -128
- package/dist/agent-skill-mongo.md +106 -0
- package/dist/agent-skill-postgres.md +106 -0
- package/dist/cli-errors-BDCYR5ap.mjs +4 -0
- package/dist/cli-errors-DStABy9d.d.mts +3 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.js +1 -2910
- package/dist/cli.mjs +261 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/client-DiUkJAeN.mjs +987 -0
- package/dist/client-DiUkJAeN.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts +7 -0
- package/dist/commands/contract-emit.d.mts.map +1 -0
- package/dist/commands/contract-emit.mjs +9 -0
- package/dist/commands/contract-infer.d.mts +7 -0
- package/dist/commands/contract-infer.d.mts.map +1 -0
- package/dist/commands/contract-infer.mjs +10 -0
- package/dist/commands/db-init.d.mts +7 -0
- package/dist/commands/db-init.d.mts.map +1 -0
- package/dist/commands/db-init.mjs +126 -0
- package/dist/commands/db-init.mjs.map +1 -0
- package/dist/commands/db-schema.d.mts +7 -0
- package/dist/commands/db-schema.d.mts.map +1 -0
- package/dist/commands/db-schema.mjs +56 -0
- package/dist/commands/db-schema.mjs.map +1 -0
- package/dist/commands/db-sign.d.mts +7 -0
- package/dist/commands/db-sign.d.mts.map +1 -0
- package/dist/commands/db-sign.mjs +137 -0
- package/dist/commands/db-sign.mjs.map +1 -0
- package/dist/commands/db-update.d.mts +7 -0
- package/dist/commands/db-update.d.mts.map +1 -0
- package/dist/commands/db-update.mjs +123 -0
- package/dist/commands/db-update.mjs.map +1 -0
- package/dist/commands/db-verify.d.mts +7 -0
- package/dist/commands/db-verify.d.mts.map +1 -0
- package/dist/commands/db-verify.mjs +323 -0
- package/dist/commands/db-verify.mjs.map +1 -0
- package/dist/commands/migration-apply.d.mts +36 -0
- package/dist/commands/migration-apply.d.mts.map +1 -0
- package/dist/commands/migration-apply.mjs +245 -0
- package/dist/commands/migration-apply.mjs.map +1 -0
- package/dist/commands/migration-new.d.mts +8 -0
- package/dist/commands/migration-new.d.mts.map +1 -0
- package/dist/commands/migration-new.mjs +152 -0
- package/dist/commands/migration-new.mjs.map +1 -0
- package/dist/commands/migration-plan.d.mts +47 -0
- package/dist/commands/migration-plan.d.mts.map +1 -0
- package/dist/commands/migration-plan.mjs +313 -0
- package/dist/commands/migration-plan.mjs.map +1 -0
- package/dist/commands/migration-ref.d.mts +43 -0
- package/dist/commands/migration-ref.d.mts.map +1 -0
- package/dist/commands/migration-ref.mjs +195 -0
- package/dist/commands/migration-ref.mjs.map +1 -0
- package/dist/commands/migration-show.d.mts +28 -0
- package/dist/commands/migration-show.d.mts.map +1 -0
- package/dist/commands/migration-show.mjs +140 -0
- package/dist/commands/migration-show.mjs.map +1 -0
- package/dist/commands/migration-status.d.mts +86 -0
- package/dist/commands/migration-status.d.mts.map +1 -0
- package/dist/commands/migration-status.mjs +9 -0
- package/dist/commands/migration-verify.d.mts +16 -0
- package/dist/commands/migration-verify.d.mts.map +1 -0
- package/dist/commands/migration-verify.mjs +110 -0
- package/dist/commands/migration-verify.mjs.map +1 -0
- package/dist/config-loader-C4VXKl8f.mjs +43 -0
- package/dist/config-loader-C4VXKl8f.mjs.map +1 -0
- package/dist/{config-loader.d.ts → config-loader.d.mts} +8 -3
- package/dist/config-loader.d.mts.map +1 -0
- package/dist/config-loader.mjs +3 -0
- package/dist/contract-emit-D2wDXfyo.mjs +191 -0
- package/dist/contract-emit-D2wDXfyo.mjs.map +1 -0
- package/dist/contract-emit-Zm_sd1wQ.mjs +112 -0
- package/dist/contract-emit-Zm_sd1wQ.mjs.map +1 -0
- package/dist/contract-emit-kN-IkKTE.mjs +6 -0
- package/dist/contract-enrichment-CGW6mm-E.mjs +79 -0
- package/dist/contract-enrichment-CGW6mm-E.mjs.map +1 -0
- package/dist/contract-infer-DozZT511.mjs +90 -0
- package/dist/contract-infer-DozZT511.mjs.map +1 -0
- package/dist/exports/config-types.d.mts +2 -0
- package/dist/exports/config-types.mjs +3 -0
- package/dist/exports/control-api.d.mts +624 -0
- package/dist/exports/control-api.d.mts.map +1 -0
- package/dist/exports/control-api.mjs +8 -0
- package/dist/{load-ts-contract.d.ts → exports/index.d.mts} +12 -7
- package/dist/exports/index.d.mts.map +1 -0
- package/dist/exports/index.mjs +142 -0
- package/dist/exports/index.mjs.map +1 -0
- package/dist/extract-operation-statements-DZUJNmL3.mjs +13 -0
- package/dist/extract-operation-statements-DZUJNmL3.mjs.map +1 -0
- package/dist/extract-sql-ddl-DDMX-9mz.mjs +26 -0
- package/dist/extract-sql-ddl-DDMX-9mz.mjs.map +1 -0
- package/dist/framework-components-BAsliT4V.mjs +59 -0
- package/dist/framework-components-BAsliT4V.mjs.map +1 -0
- package/dist/init-6Pvm_esG.mjs +430 -0
- package/dist/init-6Pvm_esG.mjs.map +1 -0
- package/dist/inspect-live-schema-BYnhztxZ.mjs +91 -0
- package/dist/inspect-live-schema-BYnhztxZ.mjs.map +1 -0
- package/dist/migration-command-scaffold-CntCcntR.mjs +105 -0
- package/dist/migration-command-scaffold-CntCcntR.mjs.map +1 -0
- package/dist/migration-status-CJANY4yr.mjs +1583 -0
- package/dist/migration-status-CJANY4yr.mjs.map +1 -0
- package/dist/migrations-DTZBYXm1.mjs +173 -0
- package/dist/migrations-DTZBYXm1.mjs.map +1 -0
- package/dist/progress-adapter-B-YvmcDu.mjs +43 -0
- package/dist/progress-adapter-B-YvmcDu.mjs.map +1 -0
- package/dist/quick-reference-mongo.md +93 -0
- package/dist/quick-reference-postgres.md +91 -0
- package/dist/result-handler-oK_vA-Fn.mjs +697 -0
- package/dist/result-handler-oK_vA-Fn.mjs.map +1 -0
- package/dist/terminal-ui-C5k88MmW.mjs +274 -0
- package/dist/terminal-ui-C5k88MmW.mjs.map +1 -0
- package/dist/validate-contract-deps-esa-VQ0h.mjs +37 -0
- package/dist/validate-contract-deps-esa-VQ0h.mjs.map +1 -0
- package/dist/verify-DlFQ2FOw.mjs +385 -0
- package/dist/verify-DlFQ2FOw.mjs.map +1 -0
- package/package.json +87 -40
- package/src/cli.ts +118 -58
- package/src/commands/contract-emit.ts +101 -78
- package/src/commands/contract-infer-paths.ts +32 -0
- package/src/commands/contract-infer.ts +143 -0
- package/src/commands/db-init.ts +97 -219
- package/src/commands/db-schema.ts +77 -0
- package/src/commands/db-sign.ts +46 -73
- package/src/commands/db-update.ts +236 -0
- package/src/commands/db-verify.ts +409 -119
- package/src/commands/init/detect-package-manager.ts +47 -0
- package/src/commands/init/index.ts +21 -0
- package/src/commands/init/init.ts +203 -0
- package/src/commands/init/templates/agent-skill-mongo.md +106 -0
- package/src/commands/init/templates/agent-skill-postgres.md +106 -0
- package/src/commands/init/templates/agent-skill.ts +19 -0
- package/src/commands/init/templates/code-templates.ts +168 -0
- package/src/commands/init/templates/quick-reference-mongo.md +93 -0
- package/src/commands/init/templates/quick-reference-postgres.md +91 -0
- package/src/commands/init/templates/quick-reference.ts +19 -0
- package/src/commands/init/templates/render.ts +20 -0
- package/src/commands/init/templates/tsconfig.ts +35 -0
- package/src/commands/inspect-live-schema.ts +170 -0
- package/src/commands/migration-apply.ts +427 -0
- package/src/commands/migration-new.ts +260 -0
- package/src/commands/migration-plan.ts +519 -0
- package/src/commands/migration-ref.ts +305 -0
- package/src/commands/migration-show.ts +246 -0
- package/src/commands/migration-status.ts +864 -0
- package/src/commands/migration-verify.ts +180 -0
- package/src/config-loader.ts +13 -3
- package/src/control-api/client.ts +205 -183
- package/src/control-api/contract-enrichment.ts +119 -0
- package/src/control-api/errors.ts +9 -0
- package/src/control-api/operations/contract-emit.ts +181 -0
- package/src/control-api/operations/db-init.ts +53 -49
- package/src/control-api/operations/db-update.ts +220 -0
- package/src/control-api/operations/extract-operation-statements.ts +14 -0
- package/src/control-api/operations/extract-sql-ddl.ts +47 -0
- package/src/control-api/operations/migration-apply.ts +191 -0
- package/src/control-api/operations/migration-helpers.ts +49 -0
- package/src/control-api/types.ts +274 -52
- package/src/exports/config-types.ts +4 -3
- package/src/exports/control-api.ts +15 -5
- package/src/load-ts-contract.ts +30 -19
- package/src/utils/cli-errors.ts +14 -8
- package/src/utils/command-helpers.ts +302 -3
- package/src/utils/formatters/emit.ts +67 -0
- package/src/utils/formatters/errors.ts +82 -0
- package/src/utils/formatters/graph-migration-mapper.ts +240 -0
- package/src/utils/formatters/graph-render.ts +1323 -0
- package/src/utils/formatters/graph-types.ts +120 -0
- package/src/utils/formatters/help.ts +380 -0
- package/src/utils/formatters/helpers.ts +28 -0
- package/src/utils/formatters/migrations.ts +346 -0
- package/src/utils/formatters/styled.ts +212 -0
- package/src/utils/formatters/verify.ts +621 -0
- package/src/utils/framework-components.ts +13 -10
- package/src/utils/global-flags.ts +41 -23
- package/src/utils/migration-command-scaffold.ts +184 -0
- package/src/utils/migration-types.ts +12 -0
- package/src/utils/progress-adapter.ts +18 -29
- package/src/utils/result-handler.ts +12 -13
- package/src/utils/shutdown.ts +92 -0
- package/src/utils/suggest-command.ts +31 -0
- package/src/utils/terminal-ui.ts +276 -0
- package/src/utils/validate-contract-deps.ts +49 -0
- package/dist/chunk-AGOTG4L3.js +0 -965
- package/dist/chunk-AGOTG4L3.js.map +0 -1
- package/dist/chunk-HLLI4YL7.js +0 -180
- package/dist/chunk-HLLI4YL7.js.map +0 -1
- package/dist/chunk-HWYQOCAJ.js +0 -47
- package/dist/chunk-HWYQOCAJ.js.map +0 -1
- package/dist/chunk-VG2R7DGF.js +0 -735
- package/dist/chunk-VG2R7DGF.js.map +0 -1
- package/dist/cli.d.ts +0 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/contract-emit.d.ts +0 -3
- package/dist/commands/contract-emit.d.ts.map +0 -1
- package/dist/commands/contract-emit.js +0 -10
- package/dist/commands/contract-emit.js.map +0 -1
- package/dist/commands/db-init.d.ts +0 -3
- package/dist/commands/db-init.d.ts.map +0 -1
- package/dist/commands/db-init.js +0 -257
- package/dist/commands/db-init.js.map +0 -1
- package/dist/commands/db-introspect.d.ts +0 -3
- package/dist/commands/db-introspect.d.ts.map +0 -1
- package/dist/commands/db-introspect.js +0 -155
- package/dist/commands/db-introspect.js.map +0 -1
- package/dist/commands/db-schema-verify.d.ts +0 -3
- package/dist/commands/db-schema-verify.d.ts.map +0 -1
- package/dist/commands/db-schema-verify.js +0 -171
- package/dist/commands/db-schema-verify.js.map +0 -1
- package/dist/commands/db-sign.d.ts +0 -3
- package/dist/commands/db-sign.d.ts.map +0 -1
- package/dist/commands/db-sign.js +0 -195
- package/dist/commands/db-sign.js.map +0 -1
- package/dist/commands/db-verify.d.ts +0 -3
- package/dist/commands/db-verify.d.ts.map +0 -1
- package/dist/commands/db-verify.js +0 -193
- package/dist/commands/db-verify.js.map +0 -1
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config-loader.js +0 -7
- package/dist/config-loader.js.map +0 -1
- package/dist/control-api/client.d.ts +0 -13
- package/dist/control-api/client.d.ts.map +0 -1
- package/dist/control-api/operations/db-init.d.ts +0 -29
- package/dist/control-api/operations/db-init.d.ts.map +0 -1
- package/dist/control-api/types.d.ts +0 -387
- package/dist/control-api/types.d.ts.map +0 -1
- package/dist/exports/config-types.d.ts +0 -3
- package/dist/exports/config-types.d.ts.map +0 -1
- package/dist/exports/config-types.js +0 -6
- package/dist/exports/config-types.js.map +0 -1
- package/dist/exports/control-api.d.ts +0 -13
- package/dist/exports/control-api.d.ts.map +0 -1
- package/dist/exports/control-api.js +0 -7
- package/dist/exports/control-api.js.map +0 -1
- package/dist/exports/index.d.ts +0 -4
- package/dist/exports/index.d.ts.map +0 -1
- package/dist/exports/index.js +0 -176
- package/dist/exports/index.js.map +0 -1
- package/dist/load-ts-contract.d.ts.map +0 -1
- package/dist/utils/cli-errors.d.ts +0 -7
- package/dist/utils/cli-errors.d.ts.map +0 -1
- package/dist/utils/command-helpers.d.ts +0 -12
- package/dist/utils/command-helpers.d.ts.map +0 -1
- package/dist/utils/framework-components.d.ts +0 -70
- package/dist/utils/framework-components.d.ts.map +0 -1
- package/dist/utils/global-flags.d.ts +0 -25
- package/dist/utils/global-flags.d.ts.map +0 -1
- package/dist/utils/output.d.ts +0 -142
- package/dist/utils/output.d.ts.map +0 -1
- package/dist/utils/progress-adapter.d.ts +0 -26
- package/dist/utils/progress-adapter.d.ts.map +0 -1
- package/dist/utils/result-handler.d.ts +0 -15
- package/dist/utils/result-handler.d.ts.map +0 -1
- package/src/commands/db-introspect.ts +0 -227
- package/src/commands/db-schema-verify.ts +0 -238
- package/src/utils/output.ts +0 -1471
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CoreSchemaView,
|
|
3
|
+
IntrospectSchemaResult,
|
|
4
|
+
SchemaTreeNode,
|
|
5
|
+
SchemaVerificationNode,
|
|
6
|
+
SignDatabaseResult,
|
|
7
|
+
VerifyDatabaseResult,
|
|
8
|
+
VerifyDatabaseSchemaResult,
|
|
9
|
+
} from '@prisma-next/framework-components/control';
|
|
10
|
+
import { ifDefined } from '@prisma-next/utils/defined';
|
|
11
|
+
import { bold, cyan, dim, green, magenta, red, yellow } from 'colorette';
|
|
12
|
+
import type { GlobalFlags } from '../global-flags';
|
|
13
|
+
import { createColorFormatter, formatDim, isVerbose } from './helpers';
|
|
14
|
+
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Verify Output Formatters
|
|
17
|
+
// ============================================================================
|
|
18
|
+
|
|
19
|
+
export interface DbVerifyCommandSuccessResult {
|
|
20
|
+
readonly ok: true;
|
|
21
|
+
readonly mode: 'full' | 'marker-only';
|
|
22
|
+
readonly summary: string;
|
|
23
|
+
readonly contract: VerifyDatabaseResult['contract'];
|
|
24
|
+
readonly marker?: VerifyDatabaseResult['marker'];
|
|
25
|
+
readonly target: VerifyDatabaseResult['target'];
|
|
26
|
+
readonly missingCodecs?: VerifyDatabaseResult['missingCodecs'];
|
|
27
|
+
readonly codecCoverageSkipped?: VerifyDatabaseResult['codecCoverageSkipped'];
|
|
28
|
+
readonly schema?: {
|
|
29
|
+
readonly summary: string;
|
|
30
|
+
readonly counts: VerifyDatabaseSchemaResult['schema']['counts'];
|
|
31
|
+
readonly strict: boolean;
|
|
32
|
+
};
|
|
33
|
+
readonly warning?: string;
|
|
34
|
+
readonly meta?:
|
|
35
|
+
| (NonNullable<VerifyDatabaseResult['meta']> & {
|
|
36
|
+
readonly schemaVerification: 'performed' | 'skipped';
|
|
37
|
+
})
|
|
38
|
+
| {
|
|
39
|
+
readonly schemaVerification: 'performed' | 'skipped';
|
|
40
|
+
};
|
|
41
|
+
readonly timings: {
|
|
42
|
+
readonly total: number;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Formats human-readable output for database verify.
|
|
48
|
+
*/
|
|
49
|
+
export function formatVerifyOutput(
|
|
50
|
+
result: DbVerifyCommandSuccessResult,
|
|
51
|
+
flags: GlobalFlags,
|
|
52
|
+
): string {
|
|
53
|
+
if (flags.quiet) {
|
|
54
|
+
return '';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const lines: string[] = [];
|
|
58
|
+
|
|
59
|
+
const useColor = flags.color !== false;
|
|
60
|
+
const formatGreen = createColorFormatter(useColor, green);
|
|
61
|
+
const formatYellow = createColorFormatter(useColor, yellow);
|
|
62
|
+
const formatDimText = (text: string) => formatDim(useColor, text);
|
|
63
|
+
const verificationMode =
|
|
64
|
+
result.mode === 'full'
|
|
65
|
+
? `marker + schema${result.schema?.strict ? ' (strict)' : ' (tolerant)'}`
|
|
66
|
+
: 'marker only (--marker-only)';
|
|
67
|
+
|
|
68
|
+
lines.push(`${formatGreen('✔')} ${result.summary}`);
|
|
69
|
+
lines.push(`${formatDimText(` verification: ${verificationMode}`)}`);
|
|
70
|
+
lines.push(`${formatDimText(` storageHash: ${result.contract.storageHash}`)}`);
|
|
71
|
+
if (result.contract.profileHash) {
|
|
72
|
+
lines.push(`${formatDimText(` profileHash: ${result.contract.profileHash}`)}`);
|
|
73
|
+
}
|
|
74
|
+
if (result.mode === 'full' && result.schema && isVerbose(flags, 1)) {
|
|
75
|
+
lines.push(
|
|
76
|
+
`${formatDimText(` schema: pass=${result.schema.counts.pass} warn=${result.schema.counts.warn} fail=${result.schema.counts.fail}`)}`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
if (result.warning) {
|
|
80
|
+
lines.push('');
|
|
81
|
+
lines.push(`${formatYellow('⚠')} ${result.warning}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (isVerbose(flags, 1)) {
|
|
85
|
+
if (result.codecCoverageSkipped) {
|
|
86
|
+
lines.push(
|
|
87
|
+
`${formatDimText(' Codec coverage check skipped (helper returned no supported types)')}`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return lines.join('\n');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Formats JSON output for database verify.
|
|
98
|
+
*/
|
|
99
|
+
export function formatVerifyJson(result: DbVerifyCommandSuccessResult): string {
|
|
100
|
+
const output = {
|
|
101
|
+
ok: result.ok,
|
|
102
|
+
summary: result.summary,
|
|
103
|
+
mode: result.mode,
|
|
104
|
+
contract: result.contract,
|
|
105
|
+
...ifDefined('marker', result.marker),
|
|
106
|
+
target: result.target,
|
|
107
|
+
...ifDefined('missingCodecs', result.missingCodecs),
|
|
108
|
+
...ifDefined('codecCoverageSkipped', result.codecCoverageSkipped),
|
|
109
|
+
...ifDefined('schema', result.schema),
|
|
110
|
+
...ifDefined('warning', result.warning),
|
|
111
|
+
...ifDefined('meta', result.meta),
|
|
112
|
+
timings: result.timings,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
return JSON.stringify(output, null, 2);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Formats JSON output for database introspection.
|
|
120
|
+
*/
|
|
121
|
+
export function formatIntrospectJson(result: IntrospectSchemaResult<unknown>): string {
|
|
122
|
+
return JSON.stringify(result, null, 2);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Renders a schema tree structure from CoreSchemaView.
|
|
127
|
+
* Matches the style of renderSchemaVerificationTree for consistency.
|
|
128
|
+
*/
|
|
129
|
+
function renderSchemaTree(
|
|
130
|
+
node: SchemaTreeNode,
|
|
131
|
+
flags: GlobalFlags,
|
|
132
|
+
options: {
|
|
133
|
+
readonly isLast: boolean;
|
|
134
|
+
readonly prefix: string;
|
|
135
|
+
readonly useColor: boolean;
|
|
136
|
+
readonly formatDimText: (text: string) => string;
|
|
137
|
+
readonly isRoot?: boolean;
|
|
138
|
+
},
|
|
139
|
+
): string[] {
|
|
140
|
+
const { isLast, prefix, useColor, formatDimText, isRoot = false } = options;
|
|
141
|
+
const lines: string[] = [];
|
|
142
|
+
|
|
143
|
+
// Format node label with color based on kind (matching schema-verify style)
|
|
144
|
+
let formattedLabel: string = node.label;
|
|
145
|
+
|
|
146
|
+
if (useColor) {
|
|
147
|
+
switch (node.kind) {
|
|
148
|
+
case 'root':
|
|
149
|
+
formattedLabel = bold(node.label);
|
|
150
|
+
break;
|
|
151
|
+
case 'entity': {
|
|
152
|
+
// Parse "table tableName" format - color "table" dim, tableName cyan
|
|
153
|
+
const tableMatch = node.label.match(/^table\s+(.+)$/);
|
|
154
|
+
if (tableMatch?.[1]) {
|
|
155
|
+
const tableName = tableMatch[1];
|
|
156
|
+
formattedLabel = `${dim('table')} ${cyan(tableName)}`;
|
|
157
|
+
} else {
|
|
158
|
+
// Fallback: color entire label with cyan
|
|
159
|
+
formattedLabel = cyan(node.label);
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
case 'collection': {
|
|
164
|
+
// "columns" grouping node - dim the label
|
|
165
|
+
formattedLabel = dim(node.label);
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
case 'field': {
|
|
169
|
+
// Parse column name format: "columnName: typeDisplay (nullability)"
|
|
170
|
+
// Color code: column name (cyan), type (default), nullability (dim)
|
|
171
|
+
const columnMatch = node.label.match(/^([^:]+):\s*(.+)$/);
|
|
172
|
+
if (columnMatch?.[1] && columnMatch[2]) {
|
|
173
|
+
const columnName = columnMatch[1];
|
|
174
|
+
const rest = columnMatch[2];
|
|
175
|
+
// Parse rest: "typeDisplay (nullability)"
|
|
176
|
+
const typeMatch = rest.match(/^([^\s(]+)\s*(\([^)]+\))$/);
|
|
177
|
+
if (typeMatch?.[1] && typeMatch[2]) {
|
|
178
|
+
const typeDisplay = typeMatch[1];
|
|
179
|
+
const nullability = typeMatch[2];
|
|
180
|
+
formattedLabel = `${cyan(columnName)}: ${typeDisplay} ${dim(nullability)}`;
|
|
181
|
+
} else {
|
|
182
|
+
// Fallback if format doesn't match
|
|
183
|
+
formattedLabel = `${cyan(columnName)}: ${rest}`;
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
formattedLabel = node.label;
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case 'index': {
|
|
191
|
+
// Parse index/unique constraint/primary key formats
|
|
192
|
+
// "primary key: columnName" -> dim "primary key", cyan columnName
|
|
193
|
+
const pkMatch = node.label.match(/^primary key:\s*(.+)$/);
|
|
194
|
+
if (pkMatch?.[1]) {
|
|
195
|
+
const columnNames = pkMatch[1];
|
|
196
|
+
formattedLabel = `${dim('primary key')}: ${cyan(columnNames)}`;
|
|
197
|
+
} else {
|
|
198
|
+
// "unique name" -> dim "unique", cyan "name"
|
|
199
|
+
const uniqueMatch = node.label.match(/^unique\s+(.+)$/);
|
|
200
|
+
if (uniqueMatch?.[1]) {
|
|
201
|
+
const name = uniqueMatch[1];
|
|
202
|
+
formattedLabel = `${dim('unique')} ${cyan(name)}`;
|
|
203
|
+
} else {
|
|
204
|
+
// "index name" or "unique index name" -> dim label prefix, cyan name
|
|
205
|
+
const indexMatch = node.label.match(/^(unique\s+)?index\s+(.+)$/);
|
|
206
|
+
if (indexMatch?.[2]) {
|
|
207
|
+
const indexPrefix = indexMatch[1] ? `${dim('unique')} ` : '';
|
|
208
|
+
const name = indexMatch[2];
|
|
209
|
+
formattedLabel = `${indexPrefix}${dim('index')} ${cyan(name)}`;
|
|
210
|
+
} else {
|
|
211
|
+
formattedLabel = dim(node.label);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case 'dependency': {
|
|
218
|
+
// Parse extension message formats similar to schema-verify
|
|
219
|
+
// "extensionName extension is enabled" -> cyan extensionName, dim rest
|
|
220
|
+
const extMatch = node.label.match(/^([^\s]+)\s+(extension is enabled)$/);
|
|
221
|
+
if (extMatch?.[1] && extMatch[2]) {
|
|
222
|
+
const extName = extMatch[1];
|
|
223
|
+
const rest = extMatch[2];
|
|
224
|
+
formattedLabel = `${cyan(extName)} ${dim(rest)}`;
|
|
225
|
+
} else {
|
|
226
|
+
// Fallback: color entire label with magenta
|
|
227
|
+
formattedLabel = magenta(node.label);
|
|
228
|
+
}
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
default:
|
|
232
|
+
formattedLabel = node.label;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Root node renders without tree characters or prefix
|
|
238
|
+
if (isRoot) {
|
|
239
|
+
lines.push(formattedLabel);
|
|
240
|
+
} else {
|
|
241
|
+
const treeChar = isLast ? '└' : '├';
|
|
242
|
+
const treePrefix = `${formatDimText(treeChar)}─ `;
|
|
243
|
+
lines.push(`${prefix}${treePrefix}${formattedLabel}`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Render children if present
|
|
247
|
+
if (node.children && node.children.length > 0) {
|
|
248
|
+
const childPrefix = isRoot ? '' : `${prefix}${isLast ? ' ' : `${formatDimText('│')} `}`;
|
|
249
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
250
|
+
const child = node.children[i];
|
|
251
|
+
if (!child) continue;
|
|
252
|
+
const isLastChild = i === node.children.length - 1;
|
|
253
|
+
const childLines = renderSchemaTree(child, flags, {
|
|
254
|
+
isLast: isLastChild,
|
|
255
|
+
prefix: childPrefix,
|
|
256
|
+
useColor,
|
|
257
|
+
formatDimText,
|
|
258
|
+
isRoot: false,
|
|
259
|
+
});
|
|
260
|
+
lines.push(...childLines);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return lines;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Formats human-readable output for database introspection.
|
|
269
|
+
*/
|
|
270
|
+
export function formatIntrospectOutput(
|
|
271
|
+
result: IntrospectSchemaResult<unknown>,
|
|
272
|
+
schemaView: CoreSchemaView | undefined,
|
|
273
|
+
flags: GlobalFlags,
|
|
274
|
+
): string {
|
|
275
|
+
if (flags.quiet) {
|
|
276
|
+
return '';
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const lines: string[] = [];
|
|
280
|
+
|
|
281
|
+
const useColor = flags.color !== false;
|
|
282
|
+
const formatDimText = (text: string) => formatDim(useColor, text);
|
|
283
|
+
|
|
284
|
+
if (schemaView) {
|
|
285
|
+
// Render tree structure - root node is special (no tree characters)
|
|
286
|
+
const treeLines = renderSchemaTree(schemaView.root, flags, {
|
|
287
|
+
isLast: true,
|
|
288
|
+
prefix: '',
|
|
289
|
+
useColor,
|
|
290
|
+
formatDimText,
|
|
291
|
+
isRoot: true,
|
|
292
|
+
});
|
|
293
|
+
lines.push(...treeLines);
|
|
294
|
+
} else {
|
|
295
|
+
// Fallback: print summary when toSchemaView is not available
|
|
296
|
+
lines.push(`✔ ${result.summary}`);
|
|
297
|
+
if (isVerbose(flags, 1)) {
|
|
298
|
+
lines.push(` Target: ${result.target.familyId}/${result.target.id}`);
|
|
299
|
+
if (result.meta?.dbUrl) {
|
|
300
|
+
lines.push(` Database: ${result.meta.dbUrl}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Add timings in verbose mode
|
|
306
|
+
if (isVerbose(flags, 1)) {
|
|
307
|
+
lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return lines.join('\n');
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Renders a schema verification tree structure from SchemaVerificationNode.
|
|
315
|
+
* Similar to renderSchemaTree but for verification nodes with status-based colors and glyphs.
|
|
316
|
+
*/
|
|
317
|
+
function renderSchemaVerificationTree(
|
|
318
|
+
node: SchemaVerificationNode,
|
|
319
|
+
flags: GlobalFlags,
|
|
320
|
+
options: {
|
|
321
|
+
readonly isLast: boolean;
|
|
322
|
+
readonly prefix: string;
|
|
323
|
+
readonly useColor: boolean;
|
|
324
|
+
readonly formatDimText: (text: string) => string;
|
|
325
|
+
readonly isRoot?: boolean;
|
|
326
|
+
},
|
|
327
|
+
): string[] {
|
|
328
|
+
const { isLast, prefix, useColor, formatDimText, isRoot = false } = options;
|
|
329
|
+
const lines: string[] = [];
|
|
330
|
+
|
|
331
|
+
// Format status glyph and color based on status
|
|
332
|
+
let statusGlyph = '';
|
|
333
|
+
let statusColor: (text: string) => string = (text) => text;
|
|
334
|
+
if (useColor) {
|
|
335
|
+
switch (node.status) {
|
|
336
|
+
case 'pass':
|
|
337
|
+
statusGlyph = '✔';
|
|
338
|
+
statusColor = green;
|
|
339
|
+
break;
|
|
340
|
+
case 'warn':
|
|
341
|
+
statusGlyph = '⚠';
|
|
342
|
+
statusColor = (text) => (useColor ? yellow(text) : text);
|
|
343
|
+
break;
|
|
344
|
+
case 'fail':
|
|
345
|
+
statusGlyph = '✖';
|
|
346
|
+
statusColor = red;
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
switch (node.status) {
|
|
351
|
+
case 'pass':
|
|
352
|
+
statusGlyph = '✔';
|
|
353
|
+
break;
|
|
354
|
+
case 'warn':
|
|
355
|
+
statusGlyph = '⚠';
|
|
356
|
+
break;
|
|
357
|
+
case 'fail':
|
|
358
|
+
statusGlyph = '✖';
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Format node label with color based on kind
|
|
364
|
+
// For column nodes, we need to parse the name to color code different parts
|
|
365
|
+
let labelColor: (text: string) => string = (text) => text;
|
|
366
|
+
let formattedLabel: string = node.name;
|
|
367
|
+
|
|
368
|
+
if (useColor) {
|
|
369
|
+
switch (node.kind) {
|
|
370
|
+
case 'contract':
|
|
371
|
+
case 'schema':
|
|
372
|
+
labelColor = bold;
|
|
373
|
+
formattedLabel = labelColor(node.name);
|
|
374
|
+
break;
|
|
375
|
+
case 'table': {
|
|
376
|
+
// Parse "table tableName" format - color "table" dim, tableName cyan
|
|
377
|
+
const tableMatch = node.name.match(/^table\s+(.+)$/);
|
|
378
|
+
if (tableMatch?.[1]) {
|
|
379
|
+
const tableName = tableMatch[1];
|
|
380
|
+
formattedLabel = `${dim('table')} ${cyan(tableName)}`;
|
|
381
|
+
} else {
|
|
382
|
+
formattedLabel = dim(node.name);
|
|
383
|
+
}
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
case 'columns':
|
|
387
|
+
labelColor = dim;
|
|
388
|
+
formattedLabel = labelColor(node.name);
|
|
389
|
+
break;
|
|
390
|
+
case 'column': {
|
|
391
|
+
// Parse column name format: "columnName: contractType -> nativeType (nullability)"
|
|
392
|
+
// Color code: column name (cyan), contract type (default), native type (dim), nullability (dim)
|
|
393
|
+
const columnMatch = node.name.match(/^([^:]+):\s*(.+)$/);
|
|
394
|
+
if (columnMatch?.[1] && columnMatch[2]) {
|
|
395
|
+
const columnName = columnMatch[1];
|
|
396
|
+
const rest = columnMatch[2];
|
|
397
|
+
// Parse rest: "contractType -> nativeType (nullability)"
|
|
398
|
+
// Match contract type (can contain /, @, etc.), arrow, native type, then nullability in parentheses
|
|
399
|
+
const typeMatch = rest.match(/^([^\s→]+)\s*→\s*([^\s(]+)\s*(\([^)]+\))$/);
|
|
400
|
+
if (typeMatch?.[1] && typeMatch[2] && typeMatch[3]) {
|
|
401
|
+
const contractType = typeMatch[1];
|
|
402
|
+
const nativeType = typeMatch[2];
|
|
403
|
+
const nullability = typeMatch[3];
|
|
404
|
+
formattedLabel = `${cyan(columnName)}: ${contractType} → ${dim(nativeType)} ${dim(nullability)}`;
|
|
405
|
+
} else {
|
|
406
|
+
// Fallback if format doesn't match (e.g., no native type or no nullability)
|
|
407
|
+
formattedLabel = `${cyan(columnName)}: ${rest}`;
|
|
408
|
+
}
|
|
409
|
+
} else {
|
|
410
|
+
formattedLabel = node.name;
|
|
411
|
+
}
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
case 'type':
|
|
415
|
+
case 'nullability':
|
|
416
|
+
labelColor = (text) => text; // Default color
|
|
417
|
+
formattedLabel = labelColor(node.name);
|
|
418
|
+
break;
|
|
419
|
+
case 'primaryKey': {
|
|
420
|
+
// Parse "primary key: columnName" format - color "primary key" dim, columnName cyan
|
|
421
|
+
const pkMatch = node.name.match(/^primary key:\s*(.+)$/);
|
|
422
|
+
if (pkMatch?.[1]) {
|
|
423
|
+
const columnNames = pkMatch[1];
|
|
424
|
+
formattedLabel = `${dim('primary key')}: ${cyan(columnNames)}`;
|
|
425
|
+
} else {
|
|
426
|
+
formattedLabel = dim(node.name);
|
|
427
|
+
}
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
case 'foreignKey':
|
|
431
|
+
case 'unique':
|
|
432
|
+
case 'index':
|
|
433
|
+
labelColor = dim;
|
|
434
|
+
formattedLabel = labelColor(node.name);
|
|
435
|
+
break;
|
|
436
|
+
case 'dependency': {
|
|
437
|
+
// Parse specific extension message formats
|
|
438
|
+
// "database is postgres" -> dim "database is", cyan "postgres"
|
|
439
|
+
const dbMatch = node.name.match(/^database is\s+(.+)$/);
|
|
440
|
+
if (dbMatch?.[1]) {
|
|
441
|
+
const dbName = dbMatch[1];
|
|
442
|
+
formattedLabel = `${dim('database is')} ${cyan(dbName)}`;
|
|
443
|
+
} else {
|
|
444
|
+
// "vector extension is enabled" -> dim everything except extension name
|
|
445
|
+
// Match pattern: "extensionName extension is enabled"
|
|
446
|
+
const extMatch = node.name.match(/^([^\s]+)\s+(extension is enabled)$/);
|
|
447
|
+
if (extMatch?.[1] && extMatch[2]) {
|
|
448
|
+
const extName = extMatch[1];
|
|
449
|
+
const rest = extMatch[2];
|
|
450
|
+
formattedLabel = `${cyan(extName)} ${dim(rest)}`;
|
|
451
|
+
} else {
|
|
452
|
+
// Fallback: color entire name with magenta
|
|
453
|
+
labelColor = magenta;
|
|
454
|
+
formattedLabel = labelColor(node.name);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
default:
|
|
460
|
+
formattedLabel = node.name;
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
} else {
|
|
464
|
+
formattedLabel = node.name;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const statusGlyphColored = statusColor(statusGlyph);
|
|
468
|
+
|
|
469
|
+
// Build the label with optional message for failure/warn nodes
|
|
470
|
+
let nodeLabel = formattedLabel;
|
|
471
|
+
if (
|
|
472
|
+
(node.status === 'fail' || node.status === 'warn') &&
|
|
473
|
+
node.message &&
|
|
474
|
+
node.message.length > 0
|
|
475
|
+
) {
|
|
476
|
+
// Always show message for failure/warn nodes - it provides crucial context
|
|
477
|
+
// For parent nodes, the message summarizes child failures
|
|
478
|
+
// For leaf nodes, the message explains the specific issue
|
|
479
|
+
const messageText = formatDimText(`(${node.message})`);
|
|
480
|
+
nodeLabel = `${formattedLabel} ${messageText}`;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// Root node renders without tree characters or | prefix
|
|
484
|
+
// Root node renders without tree characters or prefix
|
|
485
|
+
if (isRoot) {
|
|
486
|
+
lines.push(`${statusGlyphColored} ${nodeLabel}`);
|
|
487
|
+
} else {
|
|
488
|
+
const treeChar = isLast ? '└' : '├';
|
|
489
|
+
const treePrefix = `${formatDimText(treeChar)}─ `;
|
|
490
|
+
lines.push(`${prefix}${treePrefix}${statusGlyphColored} ${nodeLabel}`);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// Render children if present
|
|
494
|
+
if (node.children && node.children.length > 0) {
|
|
495
|
+
const childPrefix = isRoot ? '' : `${prefix}${isLast ? ' ' : `${formatDimText('│')} `}`;
|
|
496
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
497
|
+
const child = node.children[i];
|
|
498
|
+
if (!child) continue;
|
|
499
|
+
const isLastChild = i === node.children.length - 1;
|
|
500
|
+
const childLines = renderSchemaVerificationTree(child, flags, {
|
|
501
|
+
isLast: isLastChild,
|
|
502
|
+
prefix: childPrefix,
|
|
503
|
+
useColor,
|
|
504
|
+
formatDimText,
|
|
505
|
+
isRoot: false,
|
|
506
|
+
});
|
|
507
|
+
lines.push(...childLines);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
return lines;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Formats human-readable output for database schema verification.
|
|
516
|
+
*/
|
|
517
|
+
export function formatSchemaVerifyOutput(
|
|
518
|
+
result: VerifyDatabaseSchemaResult,
|
|
519
|
+
flags: GlobalFlags,
|
|
520
|
+
): string {
|
|
521
|
+
if (flags.quiet) {
|
|
522
|
+
return '';
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const lines: string[] = [];
|
|
526
|
+
|
|
527
|
+
const useColor = flags.color !== false;
|
|
528
|
+
const formatGreen = createColorFormatter(useColor, green);
|
|
529
|
+
const formatRed = createColorFormatter(useColor, red);
|
|
530
|
+
const formatDimText = (text: string) => formatDim(useColor, text);
|
|
531
|
+
|
|
532
|
+
// Render verification tree first
|
|
533
|
+
const treeLines = renderSchemaVerificationTree(result.schema.root, flags, {
|
|
534
|
+
isLast: true,
|
|
535
|
+
prefix: '',
|
|
536
|
+
useColor,
|
|
537
|
+
formatDimText,
|
|
538
|
+
isRoot: true,
|
|
539
|
+
});
|
|
540
|
+
lines.push(...treeLines);
|
|
541
|
+
|
|
542
|
+
// Add counts and timings in verbose mode
|
|
543
|
+
if (isVerbose(flags, 1)) {
|
|
544
|
+
lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);
|
|
545
|
+
lines.push(
|
|
546
|
+
`${formatDimText(` pass=${result.schema.counts.pass} warn=${result.schema.counts.warn} fail=${result.schema.counts.fail}`)}`,
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// Blank line before summary
|
|
551
|
+
lines.push('');
|
|
552
|
+
|
|
553
|
+
// Summary line at the end: summary with status glyph
|
|
554
|
+
if (result.ok) {
|
|
555
|
+
lines.push(`${formatGreen('✔')} ${result.summary}`);
|
|
556
|
+
} else {
|
|
557
|
+
const codeText = result.code ? ` (${result.code})` : '';
|
|
558
|
+
lines.push(`${formatRed('✖')} ${result.summary}${codeText}`);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
return lines.join('\n');
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Formats JSON output for database schema verification.
|
|
566
|
+
*/
|
|
567
|
+
export function formatSchemaVerifyJson(result: VerifyDatabaseSchemaResult): string {
|
|
568
|
+
return JSON.stringify(result, null, 2);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// ============================================================================
|
|
572
|
+
// Sign Output Formatters
|
|
573
|
+
// ============================================================================
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Formats human-readable output for database sign.
|
|
577
|
+
*/
|
|
578
|
+
export function formatSignOutput(result: SignDatabaseResult, flags: GlobalFlags): string {
|
|
579
|
+
if (flags.quiet) {
|
|
580
|
+
return '';
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
const lines: string[] = [];
|
|
584
|
+
|
|
585
|
+
const useColor = flags.color !== false;
|
|
586
|
+
const formatGreen = createColorFormatter(useColor, green);
|
|
587
|
+
const formatDimText = (text: string) => formatDim(useColor, text);
|
|
588
|
+
|
|
589
|
+
if (result.ok) {
|
|
590
|
+
// Main success message in white (not dimmed)
|
|
591
|
+
lines.push(`${formatGreen('✔')} Database signed`);
|
|
592
|
+
|
|
593
|
+
// Show from -> to hashes with clear labels
|
|
594
|
+
const previousHash = result.marker.previous?.storageHash ?? 'none';
|
|
595
|
+
const currentHash = result.contract.storageHash;
|
|
596
|
+
|
|
597
|
+
lines.push(`${formatDimText(` from: ${previousHash}`)}`);
|
|
598
|
+
lines.push(`${formatDimText(` to: ${currentHash}`)}`);
|
|
599
|
+
|
|
600
|
+
if (isVerbose(flags, 1)) {
|
|
601
|
+
if (result.contract.profileHash) {
|
|
602
|
+
lines.push(`${formatDimText(` profileHash: ${result.contract.profileHash}`)}`);
|
|
603
|
+
}
|
|
604
|
+
if (result.marker.previous?.profileHash) {
|
|
605
|
+
lines.push(
|
|
606
|
+
`${formatDimText(` previous profileHash: ${result.marker.previous.profileHash}`)}`,
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return lines.join('\n');
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Formats JSON output for database sign.
|
|
618
|
+
*/
|
|
619
|
+
export function formatSignJson(result: SignDatabaseResult): string {
|
|
620
|
+
return JSON.stringify(result, null, 2);
|
|
621
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { Contract } from '@prisma-next/contract/types';
|
|
1
2
|
import {
|
|
2
3
|
checkContractComponentRequirements,
|
|
3
4
|
type TargetBoundComponentDescriptor,
|
|
4
|
-
} from '@prisma-next/
|
|
5
|
-
import type {
|
|
6
|
-
import type { ControlPlaneStack } from '@prisma-next/core-control-plane/types';
|
|
5
|
+
} from '@prisma-next/framework-components/components';
|
|
6
|
+
import type { ControlStack } from '@prisma-next/framework-components/control';
|
|
7
7
|
import { errorConfigValidation, errorContractMissingExtensionPacks } from './cli-errors';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -114,7 +114,7 @@ export function assertFrameworkComponentsCompatible<
|
|
|
114
114
|
* This check ensures the emitted contract matches the CLI config before running
|
|
115
115
|
* commands that depend on the contract (e.g., db verify, db sign).
|
|
116
116
|
*
|
|
117
|
-
* @param contract - The contract
|
|
117
|
+
* @param contract - The contract to validate (must include targetFamily, target, extensionPacks).
|
|
118
118
|
* @param stack - The control plane stack (target, adapter, driver, extensionPacks).
|
|
119
119
|
*
|
|
120
120
|
* @throws {CliStructuredError} errorConfigValidation when contract.targetFamily or contract.target
|
|
@@ -127,11 +127,11 @@ export function assertFrameworkComponentsCompatible<
|
|
|
127
127
|
* import { assertContractRequirementsSatisfied } from './framework-components';
|
|
128
128
|
*
|
|
129
129
|
* const config = await loadConfig();
|
|
130
|
-
* const
|
|
131
|
-
* const stack =
|
|
130
|
+
* const contract = await loadContractJson(config.contract.output);
|
|
131
|
+
* const stack = createControlStack({ family: config.family, target: config.target, adapter: config.adapter, ... });
|
|
132
132
|
*
|
|
133
133
|
* // Throws if contract is incompatible with config
|
|
134
|
-
* assertContractRequirementsSatisfied({ contract
|
|
134
|
+
* assertContractRequirementsSatisfied({ contract, stack });
|
|
135
135
|
* ```
|
|
136
136
|
*/
|
|
137
137
|
export function assertContractRequirementsSatisfied<
|
|
@@ -141,10 +141,13 @@ export function assertContractRequirementsSatisfied<
|
|
|
141
141
|
contract,
|
|
142
142
|
stack,
|
|
143
143
|
}: {
|
|
144
|
-
readonly contract: Pick<
|
|
145
|
-
readonly stack:
|
|
144
|
+
readonly contract: Pick<Contract, 'targetFamily' | 'target' | 'extensionPacks'>;
|
|
145
|
+
readonly stack: ControlStack<TFamilyId, TTargetId>;
|
|
146
146
|
}): void {
|
|
147
|
-
const providedComponentIds = new Set<string>([
|
|
147
|
+
const providedComponentIds = new Set<string>([
|
|
148
|
+
stack.target.id,
|
|
149
|
+
...(stack.adapter ? [stack.adapter.id] : []),
|
|
150
|
+
]);
|
|
148
151
|
for (const extension of stack.extensionPacks) {
|
|
149
152
|
providedComponentIds.add(extension.id);
|
|
150
153
|
}
|