@prisma/orm-toolchain 8.0.0-rc.13-dev.11 → 8.0.0-rc.14
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/cli.mjs +71 -21
- package/dist/cli.mjs.map +1 -1
- package/dist/cli__control-api.d.mts +1 -0
- package/dist/cli__control-api.d.mts.map +1 -1
- package/dist/cli__control-api.mjs +1 -1
- package/dist/{ref-DZuzAvuD-RQwSwQwC.mjs → ref-EXO_pTtx-DOX1lJKh.mjs} +51 -13
- package/dist/ref-EXO_pTtx-DOX1lJKh.mjs.map +1 -0
- package/dist/vite-plugin-contract-emit.mjs +1 -1
- package/package.json +12 -12
- package/dist/ref-DZuzAvuD-RQwSwQwC.mjs.map +0 -1
package/dist/cli.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
|
|
|
6
6
|
import { r as readRef } from "./refs-qwvw4_dV-DNg_7WTD.mjs";
|
|
7
7
|
import { c as spaceMigrationDirectory } from "./verify-contract-spaces-CYjc343k-DHy5xtKR.mjs";
|
|
8
8
|
import { i as createScaffoldSpecifierResolver } from "./import-roots-BB3GzIi-.mjs";
|
|
9
|
-
import { $ as
|
|
9
|
+
import { $ as executeRefListCommand, A as errorDriverRequired, At as resolveContractRefToSnapshot, B as errorRuntime, Bt as sourceWarningDiagnostic, C as errorConfigValidation$1, Ct as refuseMarkerOutsideGraph, D as errorContractValidationFailed, Dt as requireLiveDatabase, E as errorContractConfigMissing, Et as refuseUnknownInvariants, F as errorMigrationPackageNotFound, H as errorTargetMismatch, Ht as targetSupportsMigrations, I as errorMigrationPlanningFailed, It as runMigrationCheck, J as executeMigrateShowPlan, L as errorNoMigrations, Lt as runMigrationList, M as errorHashMismatch, Mt as resolveMigrationRef, N as errorLegendHumanOnly, O as errorDatabaseConnectionRequired, Ot as resolveAppTargetPath, P as errorMarkerMissing, Pt as runCommandAction, Q as executeRefDeleteCommand, R as errorPathUnreachable, Rt as sanitizeErrorMessage, S as errorAdvanceRefArgConflict, T as errorContractArgConflict, Tt as refusePackageCorruptionOnAggregate, U as errorUnexpected, Ut as toDeclaredExtensionsFromRaw, V as errorTargetMigrationNotSupported, Vt as statusForMigrationHash, W as executeContractEmit, Wt as validateLoadedContract, X as executeMigrationPlanCommand, Y as executeMigrationNewCommand, _ as createControlClient, _t as preflightRefAdvancement, a as NO_REF_ADVANCEMENT, at as loadAggregateIntegrityViolations, bt as redactUrlCredentials, c as appliedHashesFromLedger, ct as loadContractSourceWithStack, d as buildReadAggregate, dt as mapCaughtMigrationError, et as executeRefSetCommand, f as buildRefAdvancementFields, ft as mapContractAtError, g as computeRefAdvancementName, gt as originHashForStatus, h as closeQuietly, ht as migrationSpaceListEntriesFromAggregate, i as ERROR_CODE_DESTRUCTIVE_CHANGES, it as listRefsByContractHash, j as errorFileNotFound, k as errorDestructiveChanges, kt as resolveContractRef$1, lt as loadContractSpaceAggregateForCli, m as chooseAction, mt as maskConnectionUrl, n as CliStructuredError$1$1, nt as formatSourceDiagnostic, o as advanceRefSafely, ot as loadContractRawSafely, p as checkSingleTarget, r as DB_UPDATE_POLICY, rt as hasMigrationPath, st as loadContractSource, t as ActionableCliError, tt as findPackageByDirPath, u as buildMigrationSpaceGraphEntries, ut as looksLikePath, v as deriveStatusEdgeAnnotations, vt as readContractEnvelope, w as errorConsentPlanMismatch, wt as refuseMissingInvariantPath, x as enumerateCheckSpaces, xt as refuseContractSpaceIntegrity, yt as readMigrationRefs, z as errorRunnerFailed, zt as snapshotVerifierFor } from "./ref-EXO_pTtx-DOX1lJKh.mjs";
|
|
10
10
|
import { a as PRISMA7_QUICK_REFERENCE_STEP, i as PRISMA7_LOOP_STEP, n as InitOutputSchema, o as buildNextSteps, r as NEXT_STEPS_BEFORE_SCAFFOLD, t as DB_SIGN_STEP } from "./output-BcC8eB0h-C5bRd-aC.mjs";
|
|
11
11
|
import { createRequire } from "node:module";
|
|
12
12
|
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
@@ -35,7 +35,7 @@ import { applyEdits, modify, parse, printParseErrorCode } from "jsonc-parser";
|
|
|
35
35
|
import stringWidth from "string-width";
|
|
36
36
|
import { bold, createColors, cyan, cyanBright, dim, green, yellow } from "colorette";
|
|
37
37
|
import { build } from "esbuild";
|
|
38
|
-
//#region ../../../1-framework/3-tooling/cli/dist/load-config-
|
|
38
|
+
//#region ../../../1-framework/3-tooling/cli/dist/load-config-dx-AKQyD.mjs
|
|
39
39
|
/**
|
|
40
40
|
* `isStructuredError` is the repo's own check, and it is the one that matters here: it holds the
|
|
41
41
|
* regular expression for a dotted `NAMESPACE.SUBCODE`, so only a code the protocol accepts
|
|
@@ -95,6 +95,13 @@ function toEngineDiagnostic(error) {
|
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
|
+
* An error about the contract, such as a default a planner refuses, which the user fixes in the
|
|
99
|
+
* contract. A command reports it as it is, not as an unexpected failure of the tool.
|
|
100
|
+
*/
|
|
101
|
+
function isContractError(error) {
|
|
102
|
+
return isRaisedError(error) && error.code.startsWith("CONTRACT.");
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
98
105
|
* The handler boundary's single conversion. Handlers pass every error they
|
|
99
106
|
* return through `notOk` — and every error a top-of-handler catch sees —
|
|
100
107
|
* through this, so a settled envelope always carries `nextActions` and never
|
|
@@ -255,11 +262,7 @@ function createContractEmitCommand({ executeContractEmit }) {
|
|
|
255
262
|
signal: ctx.signal,
|
|
256
263
|
...ifDefined("outputPath", outputPath)
|
|
257
264
|
});
|
|
258
|
-
|
|
259
|
-
kind: "message",
|
|
260
|
-
severity: "warn",
|
|
261
|
-
text: `warning ${formatSourceDiagnostic(warning)}`
|
|
262
|
-
});
|
|
265
|
+
const diagnostics = (result.sourceWarnings ?? []).flatMap((warning) => sourceWarningDiagnostic(warning, ctx.cwd) ?? []);
|
|
263
266
|
if (result.validationWarning !== void 0) ctx.report({
|
|
264
267
|
kind: "message",
|
|
265
268
|
severity: "warn",
|
|
@@ -279,7 +282,10 @@ function createContractEmitCommand({ executeContractEmit }) {
|
|
|
279
282
|
severity: "verbose",
|
|
280
283
|
text: `Total time: ${document.timings.total}ms`
|
|
281
284
|
});
|
|
282
|
-
return ok$1(ctx.present({
|
|
285
|
+
return ok$1(ctx.present({
|
|
286
|
+
data: document,
|
|
287
|
+
diagnostics
|
|
288
|
+
}, emitPresentations({
|
|
283
289
|
document,
|
|
284
290
|
cwd: ctx.cwd
|
|
285
291
|
})));
|
|
@@ -508,12 +514,13 @@ const defaultContractPrintDependencies = { printPsl };
|
|
|
508
514
|
* @throws {DOMException} `AbortError` if cancelled via `signal`
|
|
509
515
|
*/
|
|
510
516
|
async function executeContractPrint(options, dependencies = defaultContractPrintDependencies) {
|
|
511
|
-
const { config, contractConfig, description, signal } = options;
|
|
517
|
+
const { config, contractConfig, description, cwd, signal } = options;
|
|
512
518
|
const stack = createControlStack(config);
|
|
513
519
|
const sourceWarnings = [];
|
|
514
520
|
const loaded = await loadContractSourceWithStack({
|
|
515
521
|
stack,
|
|
516
522
|
source: contractConfig.source,
|
|
523
|
+
cwd,
|
|
517
524
|
...ifDefined("signal", signal),
|
|
518
525
|
reportWarning: (diagnostic) => {
|
|
519
526
|
sourceWarnings.push(diagnostic);
|
|
@@ -745,17 +752,14 @@ function createContractPrintCommand({ printPsl }) {
|
|
|
745
752
|
config: ctx.config,
|
|
746
753
|
contractConfig,
|
|
747
754
|
description: printDescription(sourcePaths),
|
|
755
|
+
cwd: ctx.cwd,
|
|
748
756
|
signal: ctx.signal
|
|
749
757
|
}, { printPsl });
|
|
750
758
|
} catch (error) {
|
|
751
759
|
return notOk$1(normalizeError(error));
|
|
752
760
|
}
|
|
753
761
|
ctx.signal.throwIfAborted();
|
|
754
|
-
|
|
755
|
-
kind: "message",
|
|
756
|
-
severity: "warn",
|
|
757
|
-
text: `warning ${formatSourceDiagnostic(warning)}`
|
|
758
|
-
});
|
|
762
|
+
const diagnostics = printed.sourceWarnings.flatMap((warning) => sourceWarningDiagnostic(warning, ctx.cwd) ?? []);
|
|
759
763
|
if (outputPath !== void 0) {
|
|
760
764
|
if (existsSync(outputPath)) ctx.report({
|
|
761
765
|
kind: "message",
|
|
@@ -786,7 +790,10 @@ function createContractPrintCommand({ printPsl }) {
|
|
|
786
790
|
sourceSettings: printed.sourceSettings,
|
|
787
791
|
timings: { total: Date.now() - startedAt }
|
|
788
792
|
};
|
|
789
|
-
return ok$1(ctx.present({
|
|
793
|
+
return ok$1(ctx.present({
|
|
794
|
+
data: document,
|
|
795
|
+
diagnostics
|
|
796
|
+
}, printPresentations(document, outputPath === void 0 ? void 0 : {
|
|
790
797
|
contractPath: relative(configDir, outputPath),
|
|
791
798
|
emittedFilesMove: emittedFilesMoveFor({
|
|
792
799
|
configDir,
|
|
@@ -798,6 +805,22 @@ function createContractPrintCommand({ printPsl }) {
|
|
|
798
805
|
});
|
|
799
806
|
}
|
|
800
807
|
const contractPrintCommand = createContractPrintCommand({ printPsl });
|
|
808
|
+
const DB_INIT_ADDITIVE_ONLY_FIX = "`db init` applies only additive changes. Run `{bin} db update`, which also applies widening and destructive ones after you confirm them by typing the database name, or pass `--no-interactive --confirm <database>` where there is nobody to ask.";
|
|
809
|
+
const DB_INIT_NEEDS_MIGRATION_FIX = "`db init` applies only additive changes, and `db update` does not apply data operations. Plan a migration with `{bin} migration plan`, which can include them, and apply it with `{bin} db migrate`.";
|
|
810
|
+
/**
|
|
811
|
+
* What to do instead of `db init` when its additive-only policy refused operations of the given classes: `db update` when its policy allows all of them, otherwise a planned migration.
|
|
812
|
+
*/
|
|
813
|
+
function adviceForRefusedClasses(refused) {
|
|
814
|
+
const allowedByDbUpdate = new Set(DB_UPDATE_POLICY.allowedOperationClasses);
|
|
815
|
+
if (![...refused].every((operationClass) => allowedByDbUpdate.has(operationClass))) return {
|
|
816
|
+
fix: DB_INIT_NEEDS_MIGRATION_FIX,
|
|
817
|
+
nextAction: runCommandAction("Plan a migration, since db update does not apply data operations", "{bin} migration plan")
|
|
818
|
+
};
|
|
819
|
+
return {
|
|
820
|
+
fix: DB_INIT_ADDITIVE_ONLY_FIX,
|
|
821
|
+
nextAction: runCommandAction(refused.has("destructive") ? "Apply the change with db update, which lists the destructive operations and asks you to confirm them" : "Apply the change with db update", "{bin} db update")
|
|
822
|
+
};
|
|
823
|
+
}
|
|
801
824
|
function markerMismatchDetail(failure) {
|
|
802
825
|
const parts = [];
|
|
803
826
|
if (failure.marker?.storageHash !== failure.destination?.storageHash && failure.marker?.storageHash && failure.destination?.storageHash) parts.push(`storageHash (marker: ${failure.marker.storageHash}, destination: ${failure.destination.storageHash})`);
|
|
@@ -811,7 +834,20 @@ function markerMismatchDetail(failure) {
|
|
|
811
834
|
* handle must stop the command rather than degrade into a generic message.
|
|
812
835
|
*/
|
|
813
836
|
function mapDbInitFailure(failure) {
|
|
814
|
-
if (failure.code === "PLANNING_FAILED")
|
|
837
|
+
if (failure.code === "PLANNING_FAILED") {
|
|
838
|
+
const conflicts = failure.conflicts ?? [];
|
|
839
|
+
const planningFailed = errorMigrationPlanningFailed({ conflicts });
|
|
840
|
+
const refused = new Set(conflicts.flatMap((conflict) => conflict.refusedOperationClass === void 0 ? [] : [conflict.refusedOperationClass]));
|
|
841
|
+
if (refused.size === 0) return planningFailed;
|
|
842
|
+
const { fix, nextAction } = adviceForRefusedClasses(refused);
|
|
843
|
+
return new ActionableCliError(planningFailed.code, planningFailed.message, {
|
|
844
|
+
why: planningFailed.why ?? "",
|
|
845
|
+
fix,
|
|
846
|
+
nextActions: [nextAction],
|
|
847
|
+
...ifDefined("meta", planningFailed.meta),
|
|
848
|
+
...ifDefined("docsUrl", planningFailed.docsUrl)
|
|
849
|
+
});
|
|
850
|
+
}
|
|
815
851
|
if (failure.code === "MIGRATION.MARKER_ORIGIN_MISMATCH") return errorRuntime("MIGRATION.MARKER_ORIGIN_MISMATCH", `Existing database signature does not match plan destination.${markerMismatchDetail(failure)}`, {
|
|
816
852
|
why: "Database has an existing signature (marker) that does not match the target contract",
|
|
817
853
|
fix: "If bootstrapping, drop/reset the database then re-run `{bin} db init`; otherwise reconcile schema/marker using your migration workflow",
|
|
@@ -1251,6 +1287,7 @@ function createDbInitCommand(createClient) {
|
|
|
1251
1287
|
} catch (error) {
|
|
1252
1288
|
if (CliStructuredError$1$1.is(error)) return notOk$1(normalizeError(error));
|
|
1253
1289
|
if (isStructuredError(error) && error.code === "CONTRACT.VALIDATION_FAILED") return notOk$1(normalizeError(errorContractValidationFailed(`Contract validation failed: ${error.message}`, { where: { path: contractPath } })));
|
|
1290
|
+
if (isContractError(error)) return notOk$1(normalizeError(error));
|
|
1254
1291
|
const safeMessage = sanitizeErrorMessage(error instanceof Error ? error.message : String(error), typeof dbConnection === "string" ? dbConnection : void 0);
|
|
1255
1292
|
return notOk$1(normalizeError(errorUnexpected(safeMessage, { why: `Unexpected error during db init: ${safeMessage}` })));
|
|
1256
1293
|
} finally {
|
|
@@ -1569,7 +1606,8 @@ const OUTCOME_LABEL = {
|
|
|
1569
1606
|
};
|
|
1570
1607
|
/** What a diff issue says, in the words the commander shell used. */
|
|
1571
1608
|
function issueLabel(issue) {
|
|
1572
|
-
|
|
1609
|
+
const label = `${OUTCOME_LABEL[issueOutcome(issue)]}: ${issue.path.join("/")}`;
|
|
1610
|
+
return issue.explanation === void 0 ? label : `${label}. ${issue.explanation}`;
|
|
1573
1611
|
}
|
|
1574
1612
|
function issueNodes(issues, status) {
|
|
1575
1613
|
return issues.map((issue) => ({
|
|
@@ -1626,7 +1664,7 @@ function schemaVerdictDiagnostic(inputs) {
|
|
|
1626
1664
|
code: dotted ? code : "CONTRACT.VERIFY_FAILED",
|
|
1627
1665
|
severity: "error",
|
|
1628
1666
|
summary: inputs.result.summary,
|
|
1629
|
-
...issues.length === 0 ? {} : { why: `The live schema differs: ${issues.join("; ")}
|
|
1667
|
+
...issues.length === 0 ? {} : { why: sentence(`The live schema differs: ${issues.join("; ")}`) },
|
|
1630
1668
|
nextActions: inputs.nextActions,
|
|
1631
1669
|
meta: {
|
|
1632
1670
|
...inputs.space === void 0 ? {} : { space: inputs.space },
|
|
@@ -1635,10 +1673,19 @@ function schemaVerdictDiagnostic(inputs) {
|
|
|
1635
1673
|
}
|
|
1636
1674
|
};
|
|
1637
1675
|
}
|
|
1676
|
+
function sentence(text) {
|
|
1677
|
+
return text.endsWith(".") ? text : `${text}.`;
|
|
1678
|
+
}
|
|
1679
|
+
/**
|
|
1680
|
+
* What to do about schema drift. An issue with an explanation means the emitted contract holds a
|
|
1681
|
+
* value its type refuses. Only re-emitting fixes that, and the re-emitted contract has a new hash,
|
|
1682
|
+
* so that is the one action offered.
|
|
1683
|
+
*/
|
|
1638
1684
|
function schemaDriftNextActions(inputs) {
|
|
1639
1685
|
const { verb, contractRef } = inputs;
|
|
1640
1686
|
const retryAfterEmit = contractRef === void 0 ? `${verb} again` : `${verb} the emitted contract instead of "${contractRef}"`;
|
|
1641
|
-
|
|
1687
|
+
const drift = [runCommandAction(`Change the database to match the contract, then ${verb} again`, contractRef === void 0 ? "{bin} db update" : `{bin} db update --to "${contractRef}"`), chooseAction(`Or change the contract source to describe the database as it is, re-run contract emit, then ${retryAfterEmit}`)];
|
|
1688
|
+
return inputs.issues.some((issue) => issue.explanation !== void 0) ? [runCommandAction("Re-emit the contract, which stores the refused default as its type holds it", "{bin} contract emit")] : drift;
|
|
1642
1689
|
}
|
|
1643
1690
|
/**
|
|
1644
1691
|
* Verification ran and refused the signature. The command completed — it
|
|
@@ -1902,7 +1949,8 @@ function createDbSignCommand(createClient = createControlClient) {
|
|
|
1902
1949
|
space: void 0,
|
|
1903
1950
|
nextActions: schemaDriftNextActions({
|
|
1904
1951
|
verb: "sign",
|
|
1905
|
-
contractRef
|
|
1952
|
+
contractRef,
|
|
1953
|
+
issues: verified.schema.issues
|
|
1906
1954
|
})
|
|
1907
1955
|
})]
|
|
1908
1956
|
}, refusedPresentations({
|
|
@@ -2234,6 +2282,7 @@ function createDbUpdateCommand(createClient) {
|
|
|
2234
2282
|
if (error instanceof CliStructuredError$1) throw error;
|
|
2235
2283
|
if (CliStructuredError$1$1.is(error)) return notOk$1(normalizeError(error));
|
|
2236
2284
|
if (isStructuredError(error) && error.code === "CONTRACT.VALIDATION_FAILED") return notOk$1(normalizeError(errorContractValidationFailed(`Contract validation failed: ${error.message}`, { where: { path: contractPath } })));
|
|
2285
|
+
if (isContractError(error)) return notOk$1(normalizeError(error));
|
|
2237
2286
|
const safeMessage = sanitizeErrorMessage(error instanceof Error ? error.message : String(error), typeof dbConnection === "string" ? dbConnection : void 0);
|
|
2238
2287
|
return notOk$1(normalizeError(errorUnexpected(safeMessage, { why: `Unexpected error during db update: ${safeMessage}` })));
|
|
2239
2288
|
} finally {
|
|
@@ -2517,7 +2566,8 @@ function driftDiagnostics(inputs) {
|
|
|
2517
2566
|
space,
|
|
2518
2567
|
nextActions: schemaDriftNextActions({
|
|
2519
2568
|
verb: "verify",
|
|
2520
|
-
contractRef: void 0
|
|
2569
|
+
contractRef: void 0,
|
|
2570
|
+
issues: result.schema.issues
|
|
2521
2571
|
})
|
|
2522
2572
|
}));
|
|
2523
2573
|
if (perSpace.length > 0) return perSpace;
|