@prisma/orm-toolchain 8.0.0-rc.13-dev.10 → 8.0.0-rc.13-dev.12

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 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 findPackageByDirPath, A as errorHashMismatch, At as resolveMigrationRef, B as errorTargetMismatch, Bt as toDeclaredExtensionsFromRaw, C as errorContractArgConflict, Ct as refusePackageCorruptionOnAggregate, D as errorDestructiveChanges, Dt as resolveContractRef$1, E as errorDatabaseConnectionRequired, Et as resolveAppTargetPath, F as errorNoMigrations, Ft as runMigrationList, H as executeContractEmit, I as errorPathUnreachable, It as sanitizeErrorMessage, J as executeMigrationPlanCommand, K as executeMigrateShowPlan, L as errorRunnerFailed, Lt as snapshotVerifierFor, M as errorMarkerMissing, Mt as runCommandAction, N as errorMigrationPackageNotFound, O as errorDriverRequired, Ot as resolveContractRefToSnapshot, P as errorMigrationPlanningFailed, Pt as runMigrationCheck, Q as executeRefSetCommand, R as errorRuntime, Rt as statusForMigrationHash, S as errorConsentPlanMismatch, St as refuseMissingInvariantPath, T as errorContractValidationFailed, Tt as requireLiveDatabase, V as errorUnexpected, Vt as validateLoadedContract, X as executeRefDeleteCommand, Z as executeRefListCommand, _t as readMigrationRefs, at as loadContractSource, b as errorAdvanceRefArgConflict, c as buildMigrationSpaceGraphEntries, ct as looksLikePath, d as checkSingleTarget, et as formatSourceDiagnostic, f as chooseAction, ft as maskConnectionUrl, g as deriveStatusEdgeAnnotations, gt as readContractEnvelope, h as createControlClient, ht as preflightRefAdvancement, i as advanceRefSafely, it as loadContractRawSafely, j as errorLegendHumanOnly, k as errorFileNotFound, l as buildReadAggregate, lt as mapCaughtMigrationError, m as computeRefAdvancementName, mt as originHashForStatus, n as ERROR_CODE_DESTRUCTIVE_CHANGES, nt as listRefsByContractHash, o as appliedHashesFromLedger, ot as loadContractSourceWithStack, p as closeQuietly, pt as migrationSpaceListEntriesFromAggregate, q as executeMigrationNewCommand, r as NO_REF_ADVANCEMENT, rt as loadAggregateIntegrityViolations, st as loadContractSpaceAggregateForCli, t as CliStructuredError$1$1, tt as hasMigrationPath, u as buildRefAdvancementFields, ut as mapContractAtError, vt as redactUrlCredentials, w as errorContractConfigMissing, wt as refuseUnknownInvariants, x as errorConfigValidation$1, xt as refuseMarkerOutsideGraph, y as enumerateCheckSpaces, yt as refuseContractSpaceIntegrity, z as errorTargetMigrationNotSupported, zt as targetSupportsMigrations } from "./ref-DZuzAvuD-RQwSwQwC.mjs";
9
+ import { $ as findPackageByDirPath, A as errorHashMismatch, At as resolveMigrationRef, B as errorTargetMismatch, Bt as toDeclaredExtensionsFromRaw, C as errorContractArgConflict, Ct as refusePackageCorruptionOnAggregate, D as errorDestructiveChanges, Dt as resolveContractRef$1, E as errorDatabaseConnectionRequired, Et as resolveAppTargetPath, F as errorNoMigrations, Ft as runMigrationList, H as executeContractEmit, I as errorPathUnreachable, It as sanitizeErrorMessage, J as executeMigrationPlanCommand, K as executeMigrateShowPlan, L as errorRunnerFailed, Lt as snapshotVerifierFor, M as errorMarkerMissing, Mt as runCommandAction, N as errorMigrationPackageNotFound, O as errorDriverRequired, Ot as resolveContractRefToSnapshot, P as errorMigrationPlanningFailed, Pt as runMigrationCheck, Q as executeRefSetCommand, R as errorRuntime, Rt as statusForMigrationHash, S as errorConsentPlanMismatch, St as refuseMissingInvariantPath, T as errorContractValidationFailed, Tt as requireLiveDatabase, V as errorUnexpected, Vt as validateLoadedContract, X as executeRefDeleteCommand, Z as executeRefListCommand, _t as readMigrationRefs, at as loadContractSource, b as errorAdvanceRefArgConflict, c as buildMigrationSpaceGraphEntries, ct as looksLikePath, d as checkSingleTarget, et as formatSourceDiagnostic, f as chooseAction, ft as maskConnectionUrl, g as deriveStatusEdgeAnnotations, gt as readContractEnvelope, h as createControlClient, ht as preflightRefAdvancement, i as advanceRefSafely, it as loadContractRawSafely, j as errorLegendHumanOnly, k as errorFileNotFound, l as buildReadAggregate, lt as mapCaughtMigrationError, m as computeRefAdvancementName, mt as originHashForStatus, n as ERROR_CODE_DESTRUCTIVE_CHANGES, nt as listRefsByContractHash, o as appliedHashesFromLedger, ot as loadContractSourceWithStack, p as closeQuietly, pt as migrationSpaceListEntriesFromAggregate, q as executeMigrationNewCommand, r as NO_REF_ADVANCEMENT, rt as loadAggregateIntegrityViolations, st as loadContractSpaceAggregateForCli, t as CliStructuredError$1$1, tt as hasMigrationPath, u as buildRefAdvancementFields, ut as mapContractAtError, vt as redactUrlCredentials, w as errorContractConfigMissing, wt as refuseUnknownInvariants, x as errorConfigValidation$1, xt as refuseMarkerOutsideGraph, y as enumerateCheckSpaces, yt as refuseContractSpaceIntegrity, z as errorTargetMigrationNotSupported, zt as targetSupportsMigrations } from "./ref-Qev9k5zj-BMvIT-te.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-OBtYidHx.mjs
38
+ //#region ../../../1-framework/3-tooling/cli/dist/load-config-CoKo1dRY.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
@@ -1251,6 +1258,7 @@ function createDbInitCommand(createClient) {
1251
1258
  } catch (error) {
1252
1259
  if (CliStructuredError$1$1.is(error)) return notOk$1(normalizeError(error));
1253
1260
  if (isStructuredError(error) && error.code === "CONTRACT.VALIDATION_FAILED") return notOk$1(normalizeError(errorContractValidationFailed(`Contract validation failed: ${error.message}`, { where: { path: contractPath } })));
1261
+ if (isContractError(error)) return notOk$1(normalizeError(error));
1254
1262
  const safeMessage = sanitizeErrorMessage(error instanceof Error ? error.message : String(error), typeof dbConnection === "string" ? dbConnection : void 0);
1255
1263
  return notOk$1(normalizeError(errorUnexpected(safeMessage, { why: `Unexpected error during db init: ${safeMessage}` })));
1256
1264
  } finally {
@@ -1569,7 +1577,8 @@ const OUTCOME_LABEL = {
1569
1577
  };
1570
1578
  /** What a diff issue says, in the words the commander shell used. */
1571
1579
  function issueLabel(issue) {
1572
- return `${OUTCOME_LABEL[issueOutcome(issue)]}: ${issue.path.join("/")}`;
1580
+ const label = `${OUTCOME_LABEL[issueOutcome(issue)]}: ${issue.path.join("/")}`;
1581
+ return issue.explanation === void 0 ? label : `${label}. ${issue.explanation}`;
1573
1582
  }
1574
1583
  function issueNodes(issues, status) {
1575
1584
  return issues.map((issue) => ({
@@ -1626,7 +1635,7 @@ function schemaVerdictDiagnostic(inputs) {
1626
1635
  code: dotted ? code : "CONTRACT.VERIFY_FAILED",
1627
1636
  severity: "error",
1628
1637
  summary: inputs.result.summary,
1629
- ...issues.length === 0 ? {} : { why: `The live schema differs: ${issues.join("; ")}.` },
1638
+ ...issues.length === 0 ? {} : { why: sentence(`The live schema differs: ${issues.join("; ")}`) },
1630
1639
  nextActions: inputs.nextActions,
1631
1640
  meta: {
1632
1641
  ...inputs.space === void 0 ? {} : { space: inputs.space },
@@ -1635,10 +1644,19 @@ function schemaVerdictDiagnostic(inputs) {
1635
1644
  }
1636
1645
  };
1637
1646
  }
1647
+ function sentence(text) {
1648
+ return text.endsWith(".") ? text : `${text}.`;
1649
+ }
1650
+ /**
1651
+ * What to do about schema drift. An issue with an explanation means the emitted contract holds a
1652
+ * value its type refuses. Only re-emitting fixes that, and the re-emitted contract has a new hash,
1653
+ * so that is the one action offered.
1654
+ */
1638
1655
  function schemaDriftNextActions(inputs) {
1639
1656
  const { verb, contractRef } = inputs;
1640
1657
  const retryAfterEmit = contractRef === void 0 ? `${verb} again` : `${verb} the emitted contract instead of "${contractRef}"`;
1641
- return [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}`)];
1658
+ 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}`)];
1659
+ 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
1660
  }
1643
1661
  /**
1644
1662
  * Verification ran and refused the signature. The command completed — it
@@ -1902,7 +1920,8 @@ function createDbSignCommand(createClient = createControlClient) {
1902
1920
  space: void 0,
1903
1921
  nextActions: schemaDriftNextActions({
1904
1922
  verb: "sign",
1905
- contractRef
1923
+ contractRef,
1924
+ issues: verified.schema.issues
1906
1925
  })
1907
1926
  })]
1908
1927
  }, refusedPresentations({
@@ -2234,6 +2253,7 @@ function createDbUpdateCommand(createClient) {
2234
2253
  if (error instanceof CliStructuredError$1) throw error;
2235
2254
  if (CliStructuredError$1$1.is(error)) return notOk$1(normalizeError(error));
2236
2255
  if (isStructuredError(error) && error.code === "CONTRACT.VALIDATION_FAILED") return notOk$1(normalizeError(errorContractValidationFailed(`Contract validation failed: ${error.message}`, { where: { path: contractPath } })));
2256
+ if (isContractError(error)) return notOk$1(normalizeError(error));
2237
2257
  const safeMessage = sanitizeErrorMessage(error instanceof Error ? error.message : String(error), typeof dbConnection === "string" ? dbConnection : void 0);
2238
2258
  return notOk$1(normalizeError(errorUnexpected(safeMessage, { why: `Unexpected error during db update: ${safeMessage}` })));
2239
2259
  } finally {
@@ -2517,7 +2537,8 @@ function driftDiagnostics(inputs) {
2517
2537
  space,
2518
2538
  nextActions: schemaDriftNextActions({
2519
2539
  verb: "verify",
2520
- contractRef: void 0
2540
+ contractRef: void 0,
2541
+ issues: result.schema.issues
2521
2542
  })
2522
2543
  }));
2523
2544
  if (perSpace.length > 0) return perSpace;