@prisma-next/cli 0.14.0-dev.4 → 0.14.0-dev.41
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 +2 -2
- package/dist/cli.mjs +27 -13
- package/dist/cli.mjs.map +1 -1
- package/dist/{client-CJzuo5wX.mjs → client-CWTNqJdj.mjs} +76 -72
- package/dist/client-CWTNqJdj.mjs.map +1 -0
- package/dist/{command-helpers-DGMvGBeX.mjs → command-helpers-6cNJZ863.mjs} +3 -3
- package/dist/{command-helpers-DGMvGBeX.mjs.map → command-helpers-6cNJZ863.mjs.map} +1 -1
- package/dist/commands/contract-emit.mjs +1 -1
- package/dist/commands/contract-infer.mjs +1 -1
- package/dist/commands/db-init.mjs +3 -3
- package/dist/commands/db-schema.mjs +3 -3
- package/dist/commands/db-sign.mjs +5 -5
- package/dist/commands/db-sign.mjs.map +1 -1
- package/dist/commands/db-update.mjs +4 -4
- package/dist/commands/db-verify.mjs +1 -1
- package/dist/commands/migrate.d.mts +1 -1
- package/dist/commands/migrate.d.mts.map +1 -1
- package/dist/commands/migrate.mjs +35 -35
- package/dist/commands/migrate.mjs.map +1 -1
- package/dist/commands/migration-check.d.mts +1 -1
- package/dist/commands/migration-check.mjs +1 -1
- package/dist/commands/migration-graph.d.mts +1 -1
- package/dist/commands/migration-graph.mjs +8 -8
- package/dist/commands/migration-graph.mjs.map +1 -1
- package/dist/commands/migration-list.d.mts +6 -6
- package/dist/commands/migration-list.d.mts.map +1 -1
- package/dist/commands/migration-list.mjs +1 -1
- package/dist/commands/migration-log.d.mts +1 -1
- package/dist/commands/migration-log.mjs +1 -1
- package/dist/commands/migration-new.mjs +4 -4
- package/dist/commands/migration-new.mjs.map +1 -1
- package/dist/commands/migration-plan.mjs +1 -1
- package/dist/commands/migration-show.mjs +4 -4
- package/dist/commands/migration-show.mjs.map +1 -1
- package/dist/commands/migration-status.d.mts +1 -1
- package/dist/commands/migration-status.mjs +1 -1
- package/dist/commands/ref.d.mts +1 -1
- package/dist/commands/ref.mjs +3 -3
- package/dist/commands/ref.mjs.map +1 -1
- package/dist/commands/telemetry/index.mjs +1 -1
- package/dist/{contract-at-errors-CFXsstzm.mjs → contract-at-errors-DdxWRjMc.mjs} +2 -2
- package/dist/{contract-at-errors-CFXsstzm.mjs.map → contract-at-errors-DdxWRjMc.mjs.map} +1 -1
- package/dist/{contract-emit-C8HmtboH.mjs → contract-emit-CMwCj7_m.mjs} +8 -6
- package/dist/contract-emit-CMwCj7_m.mjs.map +1 -0
- package/dist/{contract-emit-B_qriF8B.mjs → contract-emit-klH7zzaV.mjs} +6 -6
- package/dist/contract-emit-klH7zzaV.mjs.map +1 -0
- package/dist/{contract-infer-BYT_ra_U.mjs → contract-infer-B__56PGb.mjs} +3 -3
- package/dist/{contract-infer-BYT_ra_U.mjs.map → contract-infer-B__56PGb.mjs.map} +1 -1
- package/dist/{contract-space-aggregate-loader-ClI1KN6d.mjs → contract-space-aggregate-loader-Bu2fjSWV.mjs} +2 -2
- package/dist/{contract-space-aggregate-loader-ClI1KN6d.mjs.map → contract-space-aggregate-loader-Bu2fjSWV.mjs.map} +1 -1
- package/dist/{db-verify-C24FKhb7.mjs → db-verify-DlqHvkkA.mjs} +69 -49
- package/dist/db-verify-DlqHvkkA.mjs.map +1 -0
- package/dist/exports/control-api.d.mts +3 -3
- package/dist/exports/control-api.mjs +2 -2
- package/dist/exports/index.mjs +2 -2
- package/dist/extension-pack-inputs-1ySHqxKG.mjs.map +1 -1
- package/dist/{format-C8yv6mXH.mjs → format-C3XdaDuA.mjs} +3 -3
- package/dist/format-C3XdaDuA.mjs.map +1 -0
- package/dist/{framework-components-YVQHhPH7.mjs → framework-components-5RljWT7Q.mjs} +2 -2
- package/dist/{framework-components-YVQHhPH7.mjs.map → framework-components-5RljWT7Q.mjs.map} +1 -1
- package/dist/{init-a3-ljrL3.mjs → init-BF3s9NcB.mjs} +3 -3
- package/dist/{init-a3-ljrL3.mjs.map → init-BF3s9NcB.mjs.map} +1 -1
- package/dist/{inspect-live-schema-DF6IwcDl.mjs → inspect-live-schema-Dd1Ft0dw.mjs} +4 -4
- package/dist/inspect-live-schema-Dd1Ft0dw.mjs.map +1 -0
- package/dist/{migration-check-VwM8xCZV.mjs → migration-check-C9F4RopI.mjs} +10 -10
- package/dist/migration-check-C9F4RopI.mjs.map +1 -0
- package/dist/migration-cli.mjs +1 -1
- package/dist/migration-cli.mjs.map +1 -1
- package/dist/{migration-command-scaffold-DA-Lhx6o.mjs → migration-command-scaffold-DW2BpjZW.mjs} +4 -4
- package/dist/migration-command-scaffold-DW2BpjZW.mjs.map +1 -0
- package/dist/{migration-list-DlJJ_38Z.mjs → migration-list-BOzQzJK4.mjs} +15 -15
- package/dist/migration-list-BOzQzJK4.mjs.map +1 -0
- package/dist/{migration-log-CG0qQAFm.mjs → migration-log-q50rqMiU.mjs} +4 -4
- package/dist/migration-log-q50rqMiU.mjs.map +1 -0
- package/dist/{migration-path-target-Ce6OZImp.mjs → migration-path-target-zK6RG6JY.mjs} +2 -2
- package/dist/{migration-path-target-Ce6OZImp.mjs.map → migration-path-target-zK6RG6JY.mjs.map} +1 -1
- package/dist/{migration-plan-W_E8FQOk.mjs → migration-plan-BwJLPkwV.mjs} +24 -24
- package/dist/migration-plan-BwJLPkwV.mjs.map +1 -0
- package/dist/{migration-status-CD-LC2Ip.mjs → migration-status-RrGUf39y.mjs} +13 -13
- package/dist/migration-status-RrGUf39y.mjs.map +1 -0
- package/dist/{telemetry-BIM4beEO.mjs → telemetry-BckOSUWG.mjs} +2 -2
- package/dist/{telemetry-BIM4beEO.mjs.map → telemetry-BckOSUWG.mjs.map} +1 -1
- package/dist/{types-C_tYiJYx.d.mts → types-CKgJmH02.d.mts} +26 -20
- package/dist/types-CKgJmH02.d.mts.map +1 -0
- package/dist/{verify-DcOYZ1tH.mjs → verify-DC14_nPu.mjs} +29 -6
- package/dist/verify-DC14_nPu.mjs.map +1 -0
- package/package.json +21 -24
- package/src/cli.ts +3 -0
- package/src/commands/contract-emit.ts +1 -1
- package/src/commands/db-sign.ts +1 -1
- package/src/commands/db-verify.ts +32 -20
- package/src/commands/inspect-live-schema.ts +1 -1
- package/src/commands/lsp.ts +32 -0
- package/src/commands/migrate.ts +45 -42
- package/src/commands/migration-check.ts +6 -6
- package/src/commands/migration-graph.ts +5 -5
- package/src/commands/migration-list.ts +13 -13
- package/src/commands/migration-log.ts +1 -1
- package/src/commands/migration-new.ts +1 -1
- package/src/commands/migration-plan.ts +4 -4
- package/src/commands/migration-show.ts +1 -1
- package/src/commands/migration-status.ts +10 -10
- package/src/commands/ref.ts +1 -1
- package/src/control-api/client.ts +5 -3
- package/src/control-api/operations/contract-emit.ts +8 -7
- package/src/control-api/operations/db-init.ts +2 -2
- package/src/control-api/operations/db-run.ts +7 -7
- package/src/control-api/operations/db-verify.ts +38 -33
- package/src/control-api/operations/format.ts +1 -2
- package/src/control-api/operations/migrate.ts +66 -66
- package/src/control-api/operations/run-migration.ts +2 -2
- package/src/control-api/types.ts +7 -7
- package/src/migration-cli.ts +1 -1
- package/src/utils/combine-verify-results.ts +113 -0
- package/src/utils/extension-pack-inputs.ts +1 -1
- package/src/utils/formatters/verify.ts +44 -3
- package/src/utils/migration-command-scaffold.ts +1 -1
- package/src/utils/plan-resolution.ts +18 -18
- package/dist/client-CJzuo5wX.mjs.map +0 -1
- package/dist/config-loader-p9JMrekQ.mjs +0 -88
- package/dist/config-loader-p9JMrekQ.mjs.map +0 -1
- package/dist/config-loader.d.mts +0 -16
- package/dist/config-loader.d.mts.map +0 -1
- package/dist/config-loader.mjs +0 -2
- package/dist/contract-emit-B_qriF8B.mjs.map +0 -1
- package/dist/contract-emit-C8HmtboH.mjs.map +0 -1
- package/dist/db-verify-C24FKhb7.mjs.map +0 -1
- package/dist/format-C8yv6mXH.mjs.map +0 -1
- package/dist/inspect-live-schema-DF6IwcDl.mjs.map +0 -1
- package/dist/migration-check-VwM8xCZV.mjs.map +0 -1
- package/dist/migration-command-scaffold-DA-Lhx6o.mjs.map +0 -1
- package/dist/migration-list-DlJJ_38Z.mjs.map +0 -1
- package/dist/migration-log-CG0qQAFm.mjs.map +0 -1
- package/dist/migration-plan-W_E8FQOk.mjs.map +0 -1
- package/dist/migration-status-CD-LC2Ip.mjs.map +0 -1
- package/dist/types-C_tYiJYx.d.mts.map +0 -1
- package/dist/verify-DcOYZ1tH.mjs.map +0 -1
- package/src/config-loader.ts +0 -92
- package/src/config-path-validation.ts +0 -74
- package/src/utils/combine-schema-results.ts +0 -84
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { VerifyDatabaseSchemaResult } from '@prisma-next/framework-components/control';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The combined per-space contract-satisfaction result plus the standalone
|
|
5
|
+
* unclaimed-elements list, reported once. The CLI renders
|
|
6
|
+
* both; `unclaimed` is never folded into the combined tree or its issues.
|
|
7
|
+
*/
|
|
8
|
+
export interface CombinedVerifyResult {
|
|
9
|
+
readonly result: VerifyDatabaseSchemaResult;
|
|
10
|
+
readonly unclaimed: readonly string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Collapse the aggregate verifier's per-space contract-satisfaction results
|
|
15
|
+
* into a single {@link VerifyDatabaseSchemaResult} for the existing CLI
|
|
16
|
+
* display surface, and carry the deduplicated unclaimed-elements list
|
|
17
|
+
* alongside it. Concatenates issues across spaces; sums counts; uses the app
|
|
18
|
+
* space's result as the structural envelope (storage hash, target). Extras are
|
|
19
|
+
* already stripped from each per-space result, so nothing here duplicates an
|
|
20
|
+
* unclaimed element per space.
|
|
21
|
+
*
|
|
22
|
+
* **Unclaimed disposition.** In strict mode a non-empty `unclaimed` list fails
|
|
23
|
+
* the combined verdict (`ok: false`); in lenient mode it is carried for
|
|
24
|
+
* informational rendering only. The list itself is returned unchanged for the
|
|
25
|
+
* renderer.
|
|
26
|
+
*
|
|
27
|
+
* **Summary policy.** Preserve the per-family phrasing whenever the
|
|
28
|
+
* combined `ok` flag agrees with the app space's `ok` flag — this is
|
|
29
|
+
* the common case (single-family deployments, single-app deployments)
|
|
30
|
+
* and the family's "satisfies / does not satisfy contract" phrasing
|
|
31
|
+
* stays user-visible. When the app passes but an extension fails (or
|
|
32
|
+
* vice versa) the app's summary contradicts the envelope, so fall back
|
|
33
|
+
* to the first failing space's summary. This keeps family phrasing
|
|
34
|
+
* intact and the envelope internally consistent (`ok: false` ↔ failure
|
|
35
|
+
* summary).
|
|
36
|
+
*/
|
|
37
|
+
export function combineVerifyResults(
|
|
38
|
+
perSpace: ReadonlyMap<string, VerifyDatabaseSchemaResult>,
|
|
39
|
+
appSpaceId: string,
|
|
40
|
+
strict: boolean,
|
|
41
|
+
unclaimed: readonly string[],
|
|
42
|
+
): CombinedVerifyResult {
|
|
43
|
+
const appResult = perSpace.get(appSpaceId) ?? perSpace.values().next().value;
|
|
44
|
+
if (appResult === undefined) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
'Aggregate verifier returned no per-space verify results — this is a wiring bug.',
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let okAll = true;
|
|
51
|
+
let firstFailure: VerifyDatabaseSchemaResult | undefined;
|
|
52
|
+
let issues: VerifyDatabaseSchemaResult['schema']['issues'] = [];
|
|
53
|
+
let schemaDiffIssues: VerifyDatabaseSchemaResult['schema']['schemaDiffIssues'] = [];
|
|
54
|
+
const counts = { pass: 0, warn: 0, fail: 0, totalNodes: 0 };
|
|
55
|
+
const childRoots: Array<VerifyDatabaseSchemaResult['schema']['root']> = [];
|
|
56
|
+
for (const [, result] of perSpace) {
|
|
57
|
+
if (!result.ok) {
|
|
58
|
+
okAll = false;
|
|
59
|
+
if (firstFailure === undefined) firstFailure = result;
|
|
60
|
+
}
|
|
61
|
+
issues = [...issues, ...result.schema.issues];
|
|
62
|
+
schemaDiffIssues = [...schemaDiffIssues, ...result.schema.schemaDiffIssues];
|
|
63
|
+
counts.pass += result.schema.counts.pass;
|
|
64
|
+
counts.warn += result.schema.counts.warn;
|
|
65
|
+
counts.fail += result.schema.counts.fail;
|
|
66
|
+
counts.totalNodes += result.schema.counts.totalNodes;
|
|
67
|
+
childRoots.push(result.schema.root);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const unclaimedFails = strict && unclaimed.length > 0;
|
|
71
|
+
const ok = okAll && !unclaimedFails;
|
|
72
|
+
|
|
73
|
+
// Prefer a failing space's family phrasing; else, when only the unclaimed list
|
|
74
|
+
// fails the verdict, say so; else keep the app space's phrasing. When `okAll`
|
|
75
|
+
// is false the loop assigned `firstFailure`, so the `?? appResult.summary`
|
|
76
|
+
// fallback is unreachable — it exists only to keep the read cast-free.
|
|
77
|
+
const summary = okAll
|
|
78
|
+
? unclaimedFails
|
|
79
|
+
? `Database schema has ${unclaimed.length} unclaimed element${unclaimed.length === 1 ? '' : 's'} (not in any contract)`
|
|
80
|
+
: appResult.summary
|
|
81
|
+
: appResult.ok
|
|
82
|
+
? (firstFailure?.summary ?? appResult.summary)
|
|
83
|
+
: appResult.summary;
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
result: {
|
|
87
|
+
ok,
|
|
88
|
+
...(ok ? {} : { code: appResult.code ?? 'PN-RUN-3010' }),
|
|
89
|
+
summary,
|
|
90
|
+
contract: appResult.contract,
|
|
91
|
+
target: appResult.target,
|
|
92
|
+
schema: {
|
|
93
|
+
issues,
|
|
94
|
+
schemaDiffIssues,
|
|
95
|
+
root: {
|
|
96
|
+
status: ok ? 'pass' : 'fail',
|
|
97
|
+
kind: 'aggregate',
|
|
98
|
+
name: 'aggregate',
|
|
99
|
+
contractPath: '',
|
|
100
|
+
code: 'AGGREGATE',
|
|
101
|
+
message: ok ? 'Aggregate schema matches' : 'Aggregate schema mismatch',
|
|
102
|
+
expected: undefined,
|
|
103
|
+
actual: undefined,
|
|
104
|
+
children: childRoots,
|
|
105
|
+
},
|
|
106
|
+
counts,
|
|
107
|
+
},
|
|
108
|
+
meta: { strict },
|
|
109
|
+
timings: { total: 0 },
|
|
110
|
+
},
|
|
111
|
+
unclaimed,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -111,7 +111,7 @@ export function toExtensionInputs(
|
|
|
111
111
|
* {@link import('./contract-space-aggregate-loader').buildContractSpaceAggregate}.
|
|
112
112
|
*
|
|
113
113
|
* Codec-only extensions (no `contractSpace` declaration) are filtered
|
|
114
|
-
* out: they
|
|
114
|
+
* out: they contribute no contract space, so the aggregate loader
|
|
115
115
|
* has nothing to do with them. Filtering happens at this descriptor-
|
|
116
116
|
* import boundary so the loader stays oblivious to that distinction —
|
|
117
117
|
* every entry it sees expects an on-disk `migrations/<id>/` directory.
|
|
@@ -30,6 +30,12 @@ export interface DbVerifyCommandSuccessResult {
|
|
|
30
30
|
readonly counts: VerifyDatabaseSchemaResult['schema']['counts'];
|
|
31
31
|
readonly strict: boolean;
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Live element names no contract space declares. In full success this is
|
|
35
|
+
* only ever non-empty in lenient mode — strict mode fails on it — and is
|
|
36
|
+
* rendered informationally.
|
|
37
|
+
*/
|
|
38
|
+
readonly unclaimed?: readonly string[];
|
|
33
39
|
readonly warning?: string;
|
|
34
40
|
readonly meta?:
|
|
35
41
|
| (NonNullable<VerifyDatabaseResult['meta']> & {
|
|
@@ -76,6 +82,14 @@ export function formatVerifyOutput(
|
|
|
76
82
|
`${formatDimText(` schema: pass=${result.schema.counts.pass} warn=${result.schema.counts.warn} fail=${result.schema.counts.fail}`)}`,
|
|
77
83
|
);
|
|
78
84
|
}
|
|
85
|
+
if (result.unclaimed && result.unclaimed.length > 0) {
|
|
86
|
+
lines.push('');
|
|
87
|
+
lines.push(formatYellow('Unclaimed elements (declared by no contract):'));
|
|
88
|
+
for (const name of result.unclaimed) {
|
|
89
|
+
lines.push(` ${formatYellow('⚠')} ${name}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
79
93
|
if (result.warning) {
|
|
80
94
|
lines.push('');
|
|
81
95
|
lines.push(`${formatYellow('⚠')} ${result.warning}`);
|
|
@@ -107,6 +121,7 @@ export function formatVerifyJson(result: DbVerifyCommandSuccessResult): string {
|
|
|
107
121
|
...ifDefined('missingCodecs', result.missingCodecs),
|
|
108
122
|
...ifDefined('codecCoverageSkipped', result.codecCoverageSkipped),
|
|
109
123
|
...ifDefined('schema', result.schema),
|
|
124
|
+
unclaimed: result.unclaimed ?? [],
|
|
110
125
|
...ifDefined('warning', result.warning),
|
|
111
126
|
...ifDefined('meta', result.meta),
|
|
112
127
|
timings: result.timings,
|
|
@@ -517,6 +532,7 @@ function renderSchemaVerificationTree(
|
|
|
517
532
|
export function formatSchemaVerifyOutput(
|
|
518
533
|
result: VerifyDatabaseSchemaResult,
|
|
519
534
|
flags: GlobalFlags,
|
|
535
|
+
unclaimed: readonly string[] = [],
|
|
520
536
|
): string {
|
|
521
537
|
if (flags.quiet) {
|
|
522
538
|
return '';
|
|
@@ -527,6 +543,7 @@ export function formatSchemaVerifyOutput(
|
|
|
527
543
|
const useColor = flags.color !== false;
|
|
528
544
|
const formatGreen = createColorFormatter(useColor, green);
|
|
529
545
|
const formatRed = createColorFormatter(useColor, red);
|
|
546
|
+
const formatYellow = createColorFormatter(useColor, yellow);
|
|
530
547
|
const formatDimText = (text: string) => formatDim(useColor, text);
|
|
531
548
|
|
|
532
549
|
// Render verification tree first
|
|
@@ -539,6 +556,25 @@ export function formatSchemaVerifyOutput(
|
|
|
539
556
|
});
|
|
540
557
|
lines.push(...treeLines);
|
|
541
558
|
|
|
559
|
+
if (result.schema.schemaDiffIssues.length > 0) {
|
|
560
|
+
lines.push('');
|
|
561
|
+
lines.push(formatRed('Schema drift:'));
|
|
562
|
+
for (const issue of result.schema.schemaDiffIssues) {
|
|
563
|
+
lines.push(` ${formatRed('✖')} ${issue.message}`);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (unclaimed.length > 0) {
|
|
568
|
+
const strict = result.meta?.strict ?? false;
|
|
569
|
+
lines.push('');
|
|
570
|
+
lines.push(
|
|
571
|
+
(strict ? formatRed : formatYellow)('Unclaimed elements (declared by no contract):'),
|
|
572
|
+
);
|
|
573
|
+
for (const name of unclaimed) {
|
|
574
|
+
lines.push(` ${(strict ? formatRed : formatYellow)(strict ? '✖' : '⚠')} ${name}`);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
542
578
|
// Add counts and timings in verbose mode
|
|
543
579
|
if (isVerbose(flags, 1)) {
|
|
544
580
|
lines.push(`${formatDimText(` Total time: ${result.timings.total}ms`)}`);
|
|
@@ -562,10 +598,15 @@ export function formatSchemaVerifyOutput(
|
|
|
562
598
|
}
|
|
563
599
|
|
|
564
600
|
/**
|
|
565
|
-
* Formats JSON output for database schema verification.
|
|
601
|
+
* Formats JSON output for database schema verification. The unclaimed-elements
|
|
602
|
+
* list is a top-level field alongside the combined result, reported once for
|
|
603
|
+
* the whole database.
|
|
566
604
|
*/
|
|
567
|
-
export function formatSchemaVerifyJson(
|
|
568
|
-
|
|
605
|
+
export function formatSchemaVerifyJson(
|
|
606
|
+
result: VerifyDatabaseSchemaResult,
|
|
607
|
+
unclaimed: readonly string[] = [],
|
|
608
|
+
): string {
|
|
609
|
+
return JSON.stringify({ ...result, unclaimed }, null, 2);
|
|
569
610
|
}
|
|
570
611
|
|
|
571
612
|
// ============================================================================
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { relative, resolve } from 'node:path';
|
|
3
|
+
import { loadConfig } from '@prisma-next/config-loader';
|
|
3
4
|
import { hasMigrations } from '@prisma-next/framework-components/control';
|
|
4
5
|
import { notOk, ok, type Result } from '@prisma-next/utils/result';
|
|
5
6
|
import type { Command } from 'commander';
|
|
6
|
-
import { loadConfig } from '../config-loader';
|
|
7
7
|
import { createControlClient } from '../control-api/client';
|
|
8
8
|
import type { ControlClient } from '../control-api/types';
|
|
9
9
|
import {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Contract } from '@prisma-next/contract/types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AggregateContractSpace } from '@prisma-next/migration-tools/aggregate';
|
|
3
3
|
import { MigrationToolsError } from '@prisma-next/migration-tools/errors';
|
|
4
4
|
import type { MigrationGraph } from '@prisma-next/migration-tools/graph';
|
|
5
5
|
import {
|
|
@@ -45,11 +45,11 @@ export type FromResolution =
|
|
|
45
45
|
|
|
46
46
|
export interface ResolveFromForPlanInput {
|
|
47
47
|
readonly optionsFrom?: string | undefined;
|
|
48
|
-
readonly
|
|
48
|
+
readonly space: AggregateContractSpace;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
function graphIsEmpty(
|
|
52
|
-
return
|
|
51
|
+
function graphIsEmpty(space: AggregateContractSpace): boolean {
|
|
52
|
+
return space.packages.length === 0;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function getReachableRefs(
|
|
@@ -98,14 +98,14 @@ type RefContractResolution =
|
|
|
98
98
|
|
|
99
99
|
async function resolveContractRef(
|
|
100
100
|
parsed: ContractRef,
|
|
101
|
-
|
|
101
|
+
space: AggregateContractSpace,
|
|
102
102
|
options?: { readonly explicitLabel?: string; readonly artifactRole?: 'from' | 'to' },
|
|
103
103
|
): Promise<Result<RefContractResolution, CliStructuredError>> {
|
|
104
104
|
const { hash, provenance } = parsed;
|
|
105
105
|
const refName = provenance.kind === 'ref' ? provenance.refName : undefined;
|
|
106
106
|
|
|
107
107
|
try {
|
|
108
|
-
const at = await
|
|
108
|
+
const at = await space.contractAt(hash, refName !== undefined ? { refName } : undefined);
|
|
109
109
|
|
|
110
110
|
if (at.provenance === 'snapshot') {
|
|
111
111
|
return ok({
|
|
@@ -139,7 +139,7 @@ async function resolveFromPolicy(
|
|
|
139
139
|
refs: Refs,
|
|
140
140
|
explicitFromLabel?: string,
|
|
141
141
|
): Promise<Result<FromResolution, CliStructuredError>> {
|
|
142
|
-
const resolution = await resolveContractRef(parsed, input.
|
|
142
|
+
const resolution = await resolveContractRef(parsed, input.space, {
|
|
143
143
|
...(explicitFromLabel !== undefined ? { explicitLabel: explicitFromLabel } : {}),
|
|
144
144
|
artifactRole: 'from',
|
|
145
145
|
});
|
|
@@ -157,7 +157,7 @@ async function resolveFromPolicy(
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
const { hash, contract, contractJson, contractDts } = resolution.value;
|
|
160
|
-
if (graphIsEmpty(input.
|
|
160
|
+
if (graphIsEmpty(input.space)) {
|
|
161
161
|
return ok({
|
|
162
162
|
kind: 'auto-baseline',
|
|
163
163
|
fromHash: hash,
|
|
@@ -167,7 +167,7 @@ async function resolveFromPolicy(
|
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
const graph = input.
|
|
170
|
+
const graph = input.space.graph();
|
|
171
171
|
const graphTip = findLatestMigration(graph)?.to ?? null;
|
|
172
172
|
try {
|
|
173
173
|
assertFromIsGraphNode(hash, graph, refs, graphTip);
|
|
@@ -189,9 +189,9 @@ async function resolveFromPolicy(
|
|
|
189
189
|
export async function resolveFromForPlan(
|
|
190
190
|
input: ResolveFromForPlanInput,
|
|
191
191
|
): Promise<Result<FromResolution, CliStructuredError>> {
|
|
192
|
-
const { optionsFrom,
|
|
193
|
-
const graph =
|
|
194
|
-
const refs =
|
|
192
|
+
const { optionsFrom, space } = input;
|
|
193
|
+
const graph = space.graph();
|
|
194
|
+
const refs = space.refs;
|
|
195
195
|
|
|
196
196
|
if (optionsFrom === undefined) {
|
|
197
197
|
const dbRef = refs['db'];
|
|
@@ -208,7 +208,7 @@ export async function resolveFromForPlan(
|
|
|
208
208
|
const refResult = parseContractRef(optionsFrom, { graph, refs });
|
|
209
209
|
if (!refResult.ok) {
|
|
210
210
|
if (looksLikeFullHash(optionsFrom)) {
|
|
211
|
-
const empty = graphIsEmpty(
|
|
211
|
+
const empty = graphIsEmpty(space);
|
|
212
212
|
const graphTip = findLatestMigration(graph)?.to ?? null;
|
|
213
213
|
if (empty) {
|
|
214
214
|
return notOk(errorSnapshotMissing(optionsFrom, { viaRef: false }));
|
|
@@ -222,7 +222,7 @@ export async function resolveFromForPlan(
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
export interface ResolveToForPlanInput {
|
|
225
|
-
readonly
|
|
225
|
+
readonly space: AggregateContractSpace;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
export interface ResolvedContractRef {
|
|
@@ -236,16 +236,16 @@ export async function resolveToForPlan(
|
|
|
236
236
|
optionsTo: string,
|
|
237
237
|
input: ResolveToForPlanInput,
|
|
238
238
|
): Promise<Result<ResolvedContractRef, CliStructuredError>> {
|
|
239
|
-
const {
|
|
240
|
-
const graph =
|
|
241
|
-
const refs =
|
|
239
|
+
const { space } = input;
|
|
240
|
+
const graph = space.graph();
|
|
241
|
+
const refs = space.refs;
|
|
242
242
|
|
|
243
243
|
const refResult = parseContractRef(optionsTo, { graph, refs });
|
|
244
244
|
if (!refResult.ok) {
|
|
245
245
|
return notOk(mapRefResolutionError(refResult.failure));
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
const resolution = await resolveContractRef(refResult.value,
|
|
248
|
+
const resolution = await resolveContractRef(refResult.value, space, {
|
|
249
249
|
explicitLabel: optionsTo,
|
|
250
250
|
artifactRole: 'to',
|
|
251
251
|
});
|