@prisma/orm-toolchain 8.0.0-rc.19-dev.2 → 8.0.0-rc.19-dev.4

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.
Files changed (32) hide show
  1. package/dist/{aggregate-B9HIfbq6.mjs → aggregate-C30LiAd-.mjs} +3 -3
  2. package/dist/{aggregate-B9HIfbq6.mjs.map → aggregate-C30LiAd-.mjs.map} +1 -1
  3. package/dist/{caught-errors-VVhfmaAC-B-4FGHb0.mjs → caught-errors-Dijk7Hgg-DBua0IMw.mjs} +12 -5
  4. package/dist/caught-errors-Dijk7Hgg-DBua0IMw.mjs.map +1 -0
  5. package/dist/cli.mjs +9 -9
  6. package/dist/cli.mjs.map +1 -1
  7. package/dist/cli__control-api.mjs +2 -2
  8. package/dist/cli__migration-cli.mjs +2 -2
  9. package/dist/cli__migration-cli.mjs.map +1 -1
  10. package/dist/{io-BJ-LXfIc-BDm7pWEw.mjs → io-BNxFm3eg-DYD82QeZ.mjs} +3 -3
  11. package/dist/{io-BJ-LXfIc-BDm7pWEw.mjs.map → io-BNxFm3eg-DYD82QeZ.mjs.map} +1 -1
  12. package/dist/{migration-wBxEFdXP.mjs → migration-CWyjX9vz.mjs} +2 -2
  13. package/dist/{migration-wBxEFdXP.mjs.map → migration-CWyjX9vz.mjs.map} +1 -1
  14. package/dist/migration-tools.mjs +5 -5
  15. package/dist/migration-tools__aggregate.mjs +1 -1
  16. package/dist/migration-tools__io.mjs +1 -1
  17. package/dist/migration-tools__migration.mjs +1 -1
  18. package/dist/migration-tools__spaces.mjs +2 -2
  19. package/dist/op-schema-3tXg0LTS-DqpOKDEa.mjs +23 -0
  20. package/dist/op-schema-3tXg0LTS-DqpOKDEa.mjs.map +1 -0
  21. package/dist/{ref-DLqjHXyn-CsLViutC.mjs → ref-BCcYHMHw-CY5QunMw.mjs} +100 -70
  22. package/dist/ref-BCcYHMHw-CY5QunMw.mjs.map +1 -0
  23. package/dist/{spaces-COXaiv-z.mjs → spaces-c9xdiXW8.mjs} +3 -3
  24. package/dist/{spaces-COXaiv-z.mjs.map → spaces-c9xdiXW8.mjs.map} +1 -1
  25. package/dist/{verify-contract-spaces-DkXWDLa0-R1nU6Hq1.mjs → verify-contract-spaces-YzEHF9zj-DGZgox_3.mjs} +3 -3
  26. package/dist/{verify-contract-spaces-DkXWDLa0-R1nU6Hq1.mjs.map → verify-contract-spaces-YzEHF9zj-DGZgox_3.mjs.map} +1 -1
  27. package/dist/vite-plugin-contract-emit.mjs +1 -1
  28. package/package.json +12 -12
  29. package/dist/caught-errors-VVhfmaAC-B-4FGHb0.mjs.map +0 -1
  30. package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs +0 -13
  31. package/dist/op-schema-BSVHzEQN-DIWt28D8.mjs.map +0 -1
  32. package/dist/ref-DLqjHXyn-CsLViutC.mjs.map +0 -1
@@ -4,15 +4,15 @@ import { D as errorNoInvariantPath, M as errorUnknownInvariant, b as errorInvali
4
4
  import { r as verifyMigrationHash, t as computeMigrationHash } from "./hash-BAZVWU4a-BQovI7hF.mjs";
5
5
  import { a as snapshotsImportPathFrom, n as createSnapshotContentVerifier, o as writeContractSnapshot, r as readContractSnapshotJson, t as contractSnapshotDir } from "./contract-snapshot-store-6gIBcUeb-DJK3OM0j.mjs";
6
6
  import { t as deriveProvidedInvariants } from "./invariants-DrF9p5Gd-BF70vGl1.mjs";
7
- import { i as materialiseExtensionMigrationPackageIfMissing, r as formatMigrationDirName, u as writeMigrationPackage } from "./io-BJ-LXfIc-BDm7pWEw.mjs";
7
+ import { i as materialiseExtensionMigrationPackageIfMissing, r as formatMigrationDirName, u as writeMigrationPackage } from "./io-BNxFm3eg-DYD82QeZ.mjs";
8
8
  import { i as findPathWithDecision, r as findPath } from "./migration-graph-BoiiZAaU-DLht12k7.mjs";
9
- import { a as isValidSpaceId, c as spaceMigrationDirectory, l as spaceRefsDirectory, o as listContractSpaceDirectories, s as readContractSpaceHeadRef, t as APP_SPACE_ID$1 } from "./verify-contract-spaces-DkXWDLa0-R1nU6Hq1.mjs";
10
- import { i as emitContractSpaceArtifacts, o as planAllSpaces } from "./spaces-COXaiv-z.mjs";
11
- import { $ as errorUnexpected, B as errorRefSetHashNotInGraph, D as errorInvalidSpaceId, F as errorPlanForgotTheFlag, G as errorStatementAnswersNoQuestion, I as errorPlanOriginUnknown, J as errorStatementNeedsMigrationFile, K as errorStatementDidNotResolveLoss, L as errorPlanProducedNoOperations, M as errorMigrationPlanningFailed, P as errorPathUnreachable, R as errorRefSetBundleNotFound, T as errorFromCaught, U as errorSnapshotMissing, V as errorRuntime, W as errorSpaceNotFound, X as errorStatementUnresolved, Y as errorStatementOriginUnknown, Z as errorTargetMigrationNotSupported, _ as errorConfigValidation$1, at as printedPlanCommand, b as errorContractValidationFailed, c as cliCommand, ct as requireLiveDatabase, d as closeQuietly, dt as runCommandAction, et as getTargetMigrations, f as collectDeclaredInvariants, ft as selfEmitCommand, g as errorAmbiguousMigrationRef, gt as toStructuralEdge, it as printedPath, k as errorMarkerMismatch, l as cliErrorFromStructured, lt as resolveContractPath, mt as statementFlag, n as CliStructuredError$1, ot as readContractEnvelope, q as errorStatementInvalid, r as STORE_ORIGIN_SNAPSHOT_STEPS, s as chooseAction, t as ActionableCliError, tt as mapRefResolutionError, ut as resolveMigrationPaths, w as errorFileNotFound, y as errorContractConfigMissing, z as errorRefSetEmptySentinel } from "./caught-errors-VVhfmaAC-B-4FGHb0.mjs";
9
+ import { a as isValidSpaceId, c as spaceMigrationDirectory, l as spaceRefsDirectory, o as listContractSpaceDirectories, s as readContractSpaceHeadRef, t as APP_SPACE_ID$1 } from "./verify-contract-spaces-YzEHF9zj-DGZgox_3.mjs";
10
+ import { i as emitContractSpaceArtifacts, o as planAllSpaces } from "./spaces-c9xdiXW8.mjs";
11
+ import { A as errorMarkerMismatch, B as errorRefSetEmptySentinel, E as errorFromCaught, F as errorPathUnreachable, G as errorSpaceNotFound, H as errorRuntime, I as errorPlanForgotTheFlag, J as errorStatementInvalid, K as errorStatementAnswersNoQuestion, L as errorPlanOriginUnknown, N as errorMigrationPlanningFailed, O as errorInvalidSpaceId, Q as errorTargetMigrationNotSupported, R as errorPlanProducedNoOperations, T as errorFileNotFound, V as errorRefSetHashNotInGraph, W as errorSnapshotMissing, X as errorStatementOriginUnknown, Y as errorStatementNeedsMigrationFile, Z as errorStatementUnresolved, _ as errorAmbiguousMigrationRef, _t as toStructuralEdge, at as printedPath, b as errorContractConfigMissing, c as cliCommand, d as closeQuietly, dt as resolveMigrationPaths, et as errorUnexpected, f as collectDeclaredInvariants, ft as runCommandAction, h as editFileAction, ht as statementFlag, l as cliErrorFromStructured, lt as requireLiveDatabase, n as CliStructuredError$1, nt as mapRefResolutionError, ot as printedPlanCommand, pt as selfEmitCommand, q as errorStatementDidNotResolveLoss, r as STORE_ORIGIN_SNAPSHOT_STEPS, s as chooseAction, st as readContractEnvelope, t as ActionableCliError, tt as getTargetMigrations, ut as resolveContractPath, v as errorConfigValidation$1, x as errorContractValidationFailed, z as errorRefSetBundleNotFound } from "./caught-errors-Dijk7Hgg-DBua0IMw.mjs";
12
12
  import { r as getEmittedArtifactPaths, t as emit } from "./exports-BCIlMjIW-DkUBVDzl.mjs";
13
13
  import { n as isGraphNode, t as assertHashIsGraphNode } from "./graph-membership-DxpNgxfZ-BfqA-H7V.mjs";
14
14
  import { d as writeRef, i as readRefs, l as validateRefName, n as deleteRef, o as refsByContractHash, t as HEAD_REF_NAME, u as validateRefValue } from "./refs-DM3q3IZC-BC6H6P0X.mjs";
15
- import { a as contractHashAtMarker, c as loadContractSpaceAggregate, d as requireHeadRef, f as resolveRecordedPath, m as verifyMigration, n as buildFabricatedMigrationEdge, p as spacesInApplyOrder, r as collectAggregateNamespaces, t as allStorageElementsExternal, u as planMigration } from "./aggregate-B9HIfbq6.mjs";
15
+ import { a as contractHashAtMarker, c as loadContractSpaceAggregate, d as requireHeadRef, f as resolveRecordedPath, m as verifyMigration, n as buildFabricatedMigrationEdge, p as spacesInApplyOrder, r as collectAggregateNamespaces, t as allStorageElementsExternal, u as planMigration } from "./aggregate-C30LiAd-.mjs";
16
16
  import { c as internalImportRoot, o as importRootForDependencies, r as createImportSpecifierResolver, t as ImportRootError } from "./import-roots-DXD7fung.mjs";
17
17
  import { c as parseContractRef, l as parseMigrationRef, o as isLiveMarkerRef, r as RESERVED_CONTRACT_REFS, s as isReservedContractRef, t as EMPTY_CONTRACT_REF } from "./ref-resolution-Eo0QHp4f.mjs";
18
18
  import { a as writeMigrationTs } from "./migration-ts-DDgjsR1O.mjs";
@@ -34,7 +34,7 @@ import { asNamespaceId } from "@prisma/orm-framework/contract/types";
34
34
  import { isDeepStrictEqual } from "node:util";
35
35
  import { abortable } from "@prisma/orm-framework/utils/abortable";
36
36
  import { resolve as resolve$1 } from "node:path";
37
- //#region ../../../1-framework/3-tooling/cli/dist/ref-DLqjHXyn.mjs
37
+ //#region ../../../1-framework/3-tooling/cli/dist/ref-BCcYHMHw.mjs
38
38
  /**
39
39
  * The meta of a contract that failed to load because the family refused it, such as the columns whose defaults it refused, for the command to report: the refusal's own meta, or the `refusedDefaults` a migration-tools error kept from it.
40
40
  */
@@ -183,13 +183,14 @@ const DB_UPDATE_POLICY = { allowedOperationClasses: [
183
183
  "destructive"
184
184
  ] };
185
185
  /** The way out of a failed check before an operation of `db migrate`. */
186
- function migrateFailedPrecheckFix(report, invocation) {
186
+ function migrateFailedPrecheckAdvice(report, invocation) {
187
187
  const migrate = `\`${cliCommand(invocation, "db migrate")}\``;
188
- return report.planStartsFromMarker ? `The database has drifted from its migration history: it is not in the state the migrations before this one leave. See how it differs from the contract with \`${cliCommand(invocation, "db verify")}\`, change the database or the migration so they agree, and run ${migrate} again.` : `The database has no migration marker, so ${migrate} applies every migration from the first, and the database may already be ahead of this one. If its schema already matches the contract, adopt it with \`${cliCommand(invocation, "db sign")}\` instead.`;
188
+ if (report.planStartsFromMarker) return [chooseAction(`The database has drifted from its migration history: it is not in the state the migrations before this one leave. See how it differs from the contract with \`${cliCommand(invocation, "db verify")}\`, change the database or the migration so they agree, and run ${migrate} again`)];
189
+ return [runCommandAction(`The database has no migration marker, so ${migrate} applies every migration from the first, and the database may already be ahead of this one. If its schema already matches the contract, adopt it instead`, cliCommand(invocation, "db sign"))];
189
190
  }
190
191
  /** The way out of a failed check before an operation of `db init`, which runs only on a database with no marker. */
191
- function dbInitFailedPrecheckFix(invocation) {
192
- return `The database already holds part of the schema \`${cliCommand(invocation, "db init")}\` would create. If its schema already matches the contract, adopt it with \`${cliCommand(invocation, "db sign")}\` instead.`;
192
+ function dbInitFailedPrecheckAdvice(invocation) {
193
+ return [runCommandAction(`The database already holds part of the schema \`${cliCommand(invocation, "db init")}\` would create. If its schema already matches the contract, adopt it instead`, cliCommand(invocation, "db sign"))];
193
194
  }
194
195
  /** The issues a failed schema check after apply reported; a check that reported none counts as none. */
195
196
  function schemaCheckIssues(failure) {
@@ -205,15 +206,17 @@ function failedTypeChangeText(change) {
205
206
  case "expressionError": return `The conversion of field "${change.field}" failed with an error in its expression.`;
206
207
  }
207
208
  }
208
- function migrationPlanCommand(invocation, flags, from) {
209
- return `\`${printedPlanCommand(invocation, from, flags)}\``;
209
+ function quoted(command) {
210
+ return `\`${command}\``;
210
211
  }
211
212
  /** A `db migrate` command as advice prints it. */
212
213
  function dbMigrateCommand(invocation) {
213
- return `\`${cliCommand(invocation, "db migrate")}\``;
214
+ return quoted(cliCommand(invocation, "db migrate"));
214
215
  }
215
216
  /** The step between filling a planned migration.ts and applying it, which writes its operations. */
216
217
  const RUN_PLANNED_FILE = "run that migration.ts with the `node` command `migration plan` prints";
218
+ /** What advice that plans a migration again says of the statements it was planned with, which the CLI does not store. */
219
+ const OTHER_STATEMENTS = "adding any other statements you planned it with";
217
220
  function backfillFlags(reports) {
218
221
  return [...new Set(reports.flatMap(({ field }) => field === void 0 ? [] : [statementFlag({
219
222
  verb: "backfill",
@@ -221,31 +224,32 @@ function backfillFlags(reports) {
221
224
  })]))];
222
225
  }
223
226
  /** The way out of a failed cast for `db update`, which plans and applies in one step. */
224
- function dbUpdateFailedTypeChangeFix(change, databaseStorageHash, invocation) {
225
- const plan = migrationPlanCommand(invocation, [statementFlag({
227
+ function dbUpdateFailedTypeChangeAdvice(change, databaseStorageHash, invocation) {
228
+ const plan = printedPlanCommand(invocation, databaseStorageHash, [statementFlag({
226
229
  verb: "convert",
227
230
  text: change.field
228
- })], databaseStorageHash);
229
- return `${failedTypeChangeText(change)} Plan the change with ${plan}, write the conversion in the migration.ts it writes, ${RUN_PLANNED_FILE}, and apply it with ${dbMigrateCommand(invocation)}.`;
231
+ })]);
232
+ return [chooseAction(`${failedTypeChangeText(change)} Plan the change with ${quoted(plan)}, write the conversion in the migration.ts it writes, ${RUN_PLANNED_FILE}, and apply it with ${dbMigrateCommand(invocation)}`)];
230
233
  }
231
234
  /** The way out of rows without a value for `db update`, which plans and applies in one step. */
232
- function dbUpdateRowsWithoutValueFix(reports, databaseStorageHash, invocation) {
235
+ function dbUpdateRowsWithoutValueAdvice(reports, databaseStorageHash, invocation) {
233
236
  const flags = backfillFlags(reports);
234
- const plan = flags.length === 0 ? void 0 : `${migrationPlanCommand(invocation, flags, databaseStorageHash)}, fill the backfill steps in the migration.ts it writes, ${RUN_PLANNED_FILE}, and apply it with ${dbMigrateCommand(invocation)}`;
235
- if (reports[0]?.reason === "nullValues") {
236
- const keep = "Set a value in those rows, or keep the field optional.";
237
- return plan === void 0 ? keep : `${keep} Or plan it with ${plan}.`;
238
- }
239
- return plan === void 0 ? "Make the field optional." : `Plan it with ${plan}. Or make the field optional.`;
237
+ const planned = flags.length === 0 ? [] : [chooseAction(`Plan it with ${quoted(printedPlanCommand(invocation, databaseStorageHash, flags))}, fill the backfill steps in the migration.ts it writes, ${RUN_PLANNED_FILE}, and apply it with ${dbMigrateCommand(invocation)}`)];
238
+ const [first] = reports;
239
+ if (first?.reason === "nullValues") return [
240
+ chooseAction(`Set a value in ${theRows(first.rows)}`),
241
+ editFileAction("Keep the field optional in the contract source"),
242
+ ...planned
243
+ ];
244
+ return [...planned, editFileAction("Make the field optional in the contract source")];
240
245
  }
241
246
  /**
242
247
  * The way out of rows without a value for `db init`: a migration plan needs an origin contract,
243
248
  * which a database that `db init` never initialized does not have.
244
249
  */
245
- function dbInitRowsWithoutValueFix(reports, invocation) {
250
+ function dbInitRowsWithoutValueAdvice(reports, invocation) {
246
251
  const field = reports[0]?.field;
247
- const subject = field === void 0 ? "it" : `field "${field}"`;
248
- return `Run \`${cliCommand(invocation, "db init")}\` with ${subject} optional. Then make it required with \`${cliCommand(invocation, "db update")}\`, which says how to give the rows a value.`;
252
+ return [editFileAction(`Make ${field === void 0 ? "it" : `field "${field}"`} optional in the contract source, run ${quoted(cliCommand(invocation, "db init"))}, then make it required with ${quoted(cliCommand(invocation, "db update"))}, which says how to give the rows a value`)];
249
253
  }
250
254
  function failedMigrationText(failed, invocation) {
251
255
  const dirName = basename(failed.directory);
@@ -257,14 +261,18 @@ function failedMigrationText(failed, invocation) {
257
261
  invocation
258
262
  };
259
263
  }
260
- function replan(flags, failed, except = void 0) {
261
- const others = except === void 0 ? "its other statements" : `its other statements except any ${except}`;
262
- const plan = migrationPlanCommand(failed.invocation, [
264
+ /**
265
+ * Planning the failed migration again with `flags`. `opening` is the words before the directory,
266
+ * so the sentence can start the advice or follow why it is needed.
267
+ */
268
+ function replan(opening, flags, failed, except = void 0) {
269
+ const others = except === void 0 ? OTHER_STATEMENTS : `${OTHER_STATEMENTS} except any ${except}`;
270
+ const plan = printedPlanCommand(failed.invocation, failed.from, [
263
271
  "--name",
264
272
  failed.name,
265
273
  ...flags
266
- ], failed.from);
267
- return `delete \`${failed.directory}\` (copy any code you wrote in its migration.ts first), plan it again with ${plan} and ${others}, fill in the migration.ts it writes, ${RUN_PLANNED_FILE}, and run ${dbMigrateCommand(failed.invocation)}`;
274
+ ]);
275
+ return chooseAction(`${opening} \`${failed.directory}\` (copy any code you wrote in its migration.ts first), plan it again with ${quoted(plan)}, ${others}, fill in the migration.ts it writes, ${RUN_PLANNED_FILE}, and run ${dbMigrateCommand(failed.invocation)}`);
268
276
  }
269
277
  /**
270
278
  * Where to fix code written in the failed migration's `migration.ts`, and the command that runs the
@@ -280,72 +288,91 @@ function failedMigrationFile(failedMigration) {
280
288
  run: `run \`${failedMigration.nodeCommand}\``
281
289
  };
282
290
  }
283
- function migrateFailedTypeChangeFix(change, failedMigration, invocation) {
284
- if (change.by === "conversion") {
285
- const { file, run } = failedMigrationFile(failedMigration);
286
- return `${failedTypeChangeText(change)} The failed apply changed nothing. Fix the conversion in ${file}, ${run}, and re-run ${dbMigrateCommand(invocation)}.`;
287
- }
291
+ function migrateFailedTypeChangeAdvice(change, failedMigration, invocation) {
292
+ const changeText = failedTypeChangeText(change);
293
+ const { file, run } = failedMigrationFile(failedMigration);
294
+ if (change.by === "conversion") return [editFileAction(`${changeText} Fix the conversion in ${file}, ${run}, and re-run ${dbMigrateCommand(invocation)}`)];
288
295
  const convert = statementFlag({
289
296
  verb: "convert",
290
297
  text: change.field
291
298
  });
292
- if (failedMigration === void 0) return `${failedTypeChangeText(change)} Plan the type change again with ${migrationPlanCommand(invocation, [convert], void 0)}, write the conversion in the migration.ts it writes, ${RUN_PLANNED_FILE}, and apply it with ${dbMigrateCommand(invocation)}.`;
299
+ if (failedMigration === void 0) return [chooseAction(`${changeText} Plan the type change again with ${quoted(printedPlanCommand(invocation, void 0, [convert]))}, write the conversion in the migration.ts it writes, ${RUN_PLANNED_FILE}, and apply it with ${dbMigrateCommand(invocation)}`)];
293
300
  const deleted = `\`${statementFlag({
294
301
  verb: "delete",
295
302
  text: change.field
296
303
  })}\``;
297
- const { file, run } = failedMigrationFile(failedMigration);
298
- return `${failedTypeChangeText(change)} The failed apply changed nothing. ${file} has no conversion for field "${change.field}": write one there, ${run}, and re-run ${dbMigrateCommand(invocation)}. Or ${replan([convert], failedMigration, deleted)}.`;
304
+ return [editFileAction(`${changeText} ${file} has no conversion for field "${change.field}": write one there, ${run}, and re-run ${dbMigrateCommand(invocation)}`), replan("Delete", [convert], failedMigration, deleted)];
299
305
  }
300
- function migrateRowsWithoutValueFix(reports, failedMigration, invocation) {
306
+ function migrateRowsWithoutValueAdvice(reports, failedMigration, invocation) {
301
307
  const [first] = reports;
302
308
  if (first?.reason === "backfillMissedRows") {
303
309
  const { file, run } = failedMigrationFile(failedMigration);
304
- return `${first.field === void 0 ? "The backfill step" : `The backfill step of field "${first.field}"`} left those rows without a value, and the failed apply changed nothing. Make its run fill every row in ${file}, ${run}, and re-run ${dbMigrateCommand(invocation)}.`;
310
+ return [editFileAction(`${first.field === void 0 ? "The backfill step" : `The backfill step of field "${first.field}"`} left those rows without a value. Make its run fill every row in ${file}, ${run}, and re-run ${dbMigrateCommand(invocation)}`)];
305
311
  }
306
312
  const flags = backfillFlags(reports);
307
- const again = flags.length === 0 || failedMigration === void 0 ? void 0 : replan(flags, failedMigration);
313
+ const again = (opening) => flags.length === 0 || failedMigration === void 0 ? void 0 : replan(opening, flags, failedMigration);
314
+ const one = reports.length === 1;
308
315
  if (reports.every(({ reason }) => reason === "nullValues")) {
309
- const rerun = reports.length === 1 ? `Set a value in those rows and re-run ${dbMigrateCommand(invocation)}.` : `Set a value in the rows that hold NULL in each of ${fieldList(reports)} and re-run ${dbMigrateCommand(invocation)}.`;
310
- const keep = failedMigration === void 0 ? `Or keep ${reports.length === 1 ? "the field" : "those fields"} optional, and plan the migration again.` : `Or keep ${reports.length === 1 ? "the field" : "those fields"} optional: make ${reports.length === 1 ? "it" : "them"} optional in the contract again, delete \`${failedMigration.directory}\` (copy any code you wrote in its migration.ts first), and plan it again with ${migrationPlanCommand(invocation, ["--name", failedMigration.name], failedMigration.from)} and its other statements, put back any code you copied, ${RUN_PLANNED_FILE}, and apply it with ${dbMigrateCommand(invocation)}.`;
316
+ const rerun = chooseAction(one ? `Set a value in ${theRows(first?.rows ?? 0)} and re-run ${dbMigrateCommand(invocation)}` : `Set a value in the rows that hold NULL in each of ${fieldList(reports)} and re-run ${dbMigrateCommand(invocation)}`);
317
+ const backfill = again("Delete");
318
+ const fields = one ? "the field" : "those fields";
319
+ const keep = failedMigration === void 0 ? editFileAction(`Keep ${fields} optional in the contract source, and plan the migration again`) : keepOptional(fields, one ? "it" : "them", failedMigration, invocation);
311
320
  return [
312
321
  rerun,
313
- ...again === void 0 ? [] : [`Or ${again}.`],
322
+ ...backfill === void 0 ? [] : [backfill],
314
323
  keep
315
- ].join(" ");
324
+ ];
325
+ }
326
+ if (first?.reason === "nullValues") {
327
+ const notEnough = "The migration also adds a required field the existing rows have no value for, so setting values is not enough.";
328
+ return [again(`${notEnough} Delete`) ?? editFileAction(`${notEnough} Make the new fields optional in the contract source, and plan the migration again`)];
316
329
  }
317
- if (reports[0]?.reason === "nullValues") return again === void 0 ? "The migration also adds a required field the existing rows have no value for, so setting values is not enough: make the new fields optional, and plan the migration again." : `The migration also adds a required field the existing rows have no value for, so setting values is not enough. The failed apply changed nothing: ${again}.`;
318
- return again === void 0 ? "Make the field optional, and plan the migration again." : `The failed apply changed nothing. To keep the field required, ${again}. Or make the field optional, and plan it again.`;
330
+ const required = again("To keep the field required, delete");
331
+ return required === void 0 ? [editFileAction("Make the field optional in the contract source, and plan the migration again")] : [required, editFileAction("Make the field optional in the contract source, and plan it again")];
332
+ }
333
+ function keepOptional(fields, pronoun, failedMigration, invocation) {
334
+ const plan = printedPlanCommand(invocation, failedMigration.from, ["--name", failedMigration.name]);
335
+ return editFileAction(`Keep ${fields} optional: make ${pronoun} optional in the contract source again, delete \`${failedMigration.directory}\` (copy any code you wrote in its migration.ts first), and plan it again with ${quoted(plan)}, ${OTHER_STATEMENTS}, put back any code you copied, ${RUN_PLANNED_FILE}, and apply it with ${dbMigrateCommand(invocation)}`);
336
+ }
337
+ function theRows(rows) {
338
+ return rows === 1 ? "that row" : `those ${rows} rows`;
319
339
  }
320
340
  function fieldList(reports) {
321
341
  return reports.map(({ field }) => field === void 0 ? void 0 : `"${field}"`).filter((field) => field !== void 0).join(", ");
322
342
  }
323
- function migrateSchemaCheckFix(failedMigration, invocation) {
324
- const emit = `\`${cliCommand(invocation, "contract emit")}\``;
325
- if (failedMigration === void 0) return `The failed apply changed nothing. Change the contract source to resolve the issues listed, re-run ${emit}, delete the failed migration's directory (copy any code you wrote in its migration.ts first), plan it again with ${migrationPlanCommand(invocation, [], void 0)}, put any code you copied into the migration.ts it writes, ${RUN_PLANNED_FILE}, and run ${dbMigrateCommand(invocation)}.`;
326
- const plan = migrationPlanCommand(invocation, ["--name", failedMigration.name], failedMigration.from);
327
- return `The failed apply changed nothing. Change the contract source to resolve the issues listed, re-run ${emit}, delete \`${failedMigration.directory}\` (copy any code you wrote in its migration.ts first), plan it again with ${plan}, put any code you copied into the migration.ts it writes, ${RUN_PLANNED_FILE}, and run ${dbMigrateCommand(invocation)}.`;
343
+ function migrateSchemaCheckAdvice(failedMigration, invocation) {
344
+ const emit = quoted(cliCommand(invocation, "contract emit"));
345
+ const plan = printedPlanCommand(invocation, failedMigration?.from, failedMigration === void 0 ? [] : ["--name", failedMigration.name]);
346
+ const directory = failedMigration === void 0 ? "the failed migration's directory" : `\`${failedMigration.directory}\``;
347
+ const { file, run } = failedMigrationFile(failedMigration);
348
+ return [editFileAction(`If the contract source does not describe the schema you want, change it to resolve the issues listed, re-run ${emit}, delete ${directory} (copy any code you wrote in its migration.ts first), plan it again with ${quoted(plan)}, put any code you copied into the migration.ts it writes, ${RUN_PLANNED_FILE}, and run ${dbMigrateCommand(invocation)}`), editFileAction(`If ${file} does not reach its destination contract, for example after a hand edit, change its operations to resolve the issues listed, ${run}, and run ${dbMigrateCommand(invocation)}`)];
328
349
  }
329
350
  /**
330
351
  * The way out of a failed `db migrate` apply: every path and command it prints works from where the
331
352
  * CLI ran, with the `--config` it was given.
332
353
  */
333
- function migrateFix(failure, facts, failedOnDisk, invocation) {
354
+ function migrateAdvice(failure, facts, failedOnDisk, invocation) {
334
355
  const failedMigration = failedOnDisk === void 0 ? void 0 : failedMigrationText(failedOnDisk, invocation);
335
- if (facts.failedTypeChange !== void 0) return migrateFailedTypeChangeFix(facts.failedTypeChange, failedMigration, invocation);
336
- if (facts.rowsWithoutValue !== void 0) return migrateRowsWithoutValueFix(facts.rowsWithoutValue, failedMigration, invocation);
337
- if (schemaCheckIssues(failure) !== void 0) return migrateSchemaCheckFix(failedMigration, invocation);
338
- if (facts.failedPrecheck !== void 0) return migrateFailedPrecheckFix(facts.failedPrecheck, invocation);
339
- return `Fix the issue and re-run \`${cliCommand(invocation, "db migrate", ["--to", "<contract>"])}\` — previously applied migrations are preserved.`;
356
+ if (facts.failedTypeChange !== void 0) return migrateFailedTypeChangeAdvice(facts.failedTypeChange, failedMigration, invocation);
357
+ if (facts.rowsWithoutValue !== void 0) return migrateRowsWithoutValueAdvice(facts.rowsWithoutValue, failedMigration, invocation);
358
+ if (schemaCheckIssues(failure) !== void 0) return migrateSchemaCheckAdvice(failedMigration, invocation);
359
+ if (facts.failedPrecheck !== void 0) return migrateFailedPrecheckAdvice(facts.failedPrecheck, invocation);
360
+ return [chooseAction(`Fix the issue and re-run \`${cliCommand(invocation, "db migrate", ["--to", "<contract>"])}\``)];
361
+ }
362
+ /** The ways out as prose: each label as a sentence, every one after the first after "Or:". */
363
+ function adviceText(advice) {
364
+ return advice.map(({ label }, index) => index === 0 ? `${label}.` : `Or: ${label}.`).join(" ");
340
365
  }
341
366
  /**
342
- * A runner failure as the CLI reports it: the runner's code, message, why and meta, and the failure
343
- * itself as `cause`, with the CLI's `fix`.
367
+ * A runner failure as the CLI reports it: the runner's code, message, why and meta, unchanged, and
368
+ * the failure itself as `cause`, with the CLI's advice: each way out as a next action, and all of
369
+ * them as `fix` prose.
344
370
  */
345
371
  function runnerFailureError(failure, advice) {
346
- return new CliStructuredError$1(failure.code, failure.message, {
372
+ return new ActionableCliError(failure.code, failure.message, {
347
373
  ...ifDefined("why", failure.why),
348
- fix: advice.fix,
374
+ fix: adviceText(advice),
375
+ nextActions: advice,
349
376
  meta: failure.meta,
350
377
  docsUrl: docsUrlFor(failure.code),
351
378
  cause: failure
@@ -386,7 +413,8 @@ function dbInitPlanningFailedError(conflicts) {
386
413
  }
387
414
  /** A failed `db init` apply as the CLI reports it. */
388
415
  function dbInitRunnerFailureError(failure, facts, invocation) {
389
- return runnerFailureError(failure, { fix: facts.rowsWithoutValue !== void 0 ? dbInitRowsWithoutValueFix(facts.rowsWithoutValue, invocation) : schemaCheckIssues(failure) !== void 0 ? `Change the contract source to resolve the issues listed, re-run \`${cliCommand(invocation, "contract emit")}\`, then re-run \`${cliCommand(invocation, "db init")}\`.` : facts.failedPrecheck !== void 0 ? dbInitFailedPrecheckFix(invocation) : `Fix the schema mismatch (db init is additive-only), or drop/reset the database and re-run \`${cliCommand(invocation, "db init")}\`` });
416
+ const init = cliCommand(invocation, "db init");
417
+ return runnerFailureError(failure, facts.rowsWithoutValue !== void 0 ? dbInitRowsWithoutValueAdvice(facts.rowsWithoutValue, invocation) : schemaCheckIssues(failure) !== void 0 ? [editFileAction(`Change the contract source to resolve the issues listed, re-run \`${cliCommand(invocation, "contract emit")}\`, then re-run \`${init}\``)] : facts.failedPrecheck !== void 0 ? dbInitFailedPrecheckAdvice(invocation) : [chooseAction(`Fix the schema mismatch (db init is additive-only), or drop/reset the database and re-run \`${init}\``)]);
390
418
  }
391
419
  /**
392
420
  * A failed `db update` apply as the CLI reports it. `databaseStorageHash` is the contract the
@@ -395,7 +423,8 @@ function dbInitRunnerFailureError(failure, facts, invocation) {
395
423
  */
396
424
  function dbUpdateRunnerFailureError(failure, facts, context) {
397
425
  const { databaseStorageHash, invocation } = context;
398
- return runnerFailureError(failure, { fix: facts.failedTypeChange !== void 0 ? dbUpdateFailedTypeChangeFix(facts.failedTypeChange, databaseStorageHash, invocation) : facts.rowsWithoutValue !== void 0 ? dbUpdateRowsWithoutValueFix(facts.rowsWithoutValue, databaseStorageHash, invocation) : schemaCheckIssues(failure) !== void 0 ? `Change the contract source to resolve the issues listed, re-run \`${cliCommand(invocation, "contract emit")}\`, then re-run \`${cliCommand(invocation, "db update")}\`.` : `Inspect the reported conflict, reconcile schema drift if needed, then re-run \`${cliCommand(invocation, "db update")}\`` });
426
+ const update = cliCommand(invocation, "db update");
427
+ return runnerFailureError(failure, facts.failedTypeChange !== void 0 ? dbUpdateFailedTypeChangeAdvice(facts.failedTypeChange, databaseStorageHash, invocation) : facts.rowsWithoutValue !== void 0 ? dbUpdateRowsWithoutValueAdvice(facts.rowsWithoutValue, databaseStorageHash, invocation) : schemaCheckIssues(failure) !== void 0 ? [editFileAction(`Change the contract source to resolve the issues listed, re-run \`${cliCommand(invocation, "contract emit")}\`, then re-run \`${update}\``)] : [chooseAction(`Inspect the reported conflict, reconcile schema drift if needed, then re-run \`${update}\``)]);
399
428
  }
400
429
  function startText(fromHash) {
401
430
  return fromHash === "empty" ? "the empty contract (the space has no marker)" : `the contract its marker names ("${fromHash}")`;
@@ -1777,9 +1806,10 @@ function failureReports(failure, resolutions) {
1777
1806
  const edge = operationIndex !== void 0 ? edgeOfOperation(resolution.entry.migrationEdges, operationIndex) : schemaCheckIssues(failure) !== void 0 ? resolution.entry.migrationEdges.at(-1) : void 0;
1778
1807
  return {
1779
1808
  ...ifDefined("failedTypeChange", failedTypeChange === void 0 ? void 0 : failedTypeChangeReport(failedTypeChange, fieldText(failedTypeChange.field))),
1780
- ...ifDefined("rowsWithoutValue", rowsWithoutValue?.map(({ field, reason }) => ({
1809
+ ...ifDefined("rowsWithoutValue", rowsWithoutValue?.map(({ field, reason, rows }) => ({
1781
1810
  field: field === void 0 ? void 0 : fieldText(field),
1782
- reason
1811
+ reason,
1812
+ rows
1783
1813
  }))),
1784
1814
  ...ifDefined("failedMigration", edge === void 0 ? void 0 : {
1785
1815
  spaceId: resolution.spaceId,
@@ -2964,7 +2994,7 @@ async function loadContractSource(config, options = {}) {
2964
2994
  * from where the CLI ran, with the `--config` it was given.
2965
2995
  */
2966
2996
  function migrateRunnerFailureError(failure, facts, failedMigration, invocation) {
2967
- return runnerFailureError(failure, { fix: migrateFix(failure, facts, failedMigration, invocation) });
2997
+ return runnerFailureError(failure, migrateAdvice(failure, facts, failedMigration, invocation));
2968
2998
  }
2969
2999
  /**
2970
3000
  * Apply pending migrations across every contract space (app +
@@ -6382,4 +6412,4 @@ async function executeRefListCommand(options) {
6382
6412
  //#endregion
6383
6413
  export { refuseMissingInvariantPath as $, executeRefDeleteCommand as A, loadContractRawSafely as B, executeDbSign as C, executeMigrationNewCommand as D, executeMigrateShowPlan as E, hasMigrationPath as F, mapContractAtError as G, loadContractSourceWithStack as H, isStatementVerb as I, preflightRefAdvancement as J, mapIntegrityViolations as K, listRefsByContractHash as L, executeRefSetCommand as M, findPackageByDirPath as N, executeMigrationPlanCommand as O, formatSourceDiagnostic as P, refuseMarkerOutsideGraph as Q, liveMarkerUse as R, executeDbInit as S, executeDbVerify as T, loadContractSpaceAggregateForCli as U, loadContractSource as V, looksLikePath as W, refuseContractSpaceIntegrity as X, readMigrationRefs as Y, refuseDeclaredExtensionTargetMismatch as Z, deriveStatusEdgeAnnotations as _, toDeclaredExtensionsFromRaw as _t, advanceRefSafely as a, resolveContractRefToSnapshot as at, enumerateCheckSpaces as b, buildContractSpaceAggregate as c, resolveStatements as ct, buildRefAdvancementFields as d, runContractSpaceSeedPhase as dt, refusePackageCorruptionOnAggregate as et, checkSingleTarget as f, runMigrationCheck as ft, createControlClient as g, statusForMigrationHash as gt, convertAndDelete as h, sourceWarningDiagnostic as ht, RECORDED_OR_EMPTY_CONTRACT_REF_FORMS as i, resolveContractRef$1 as it, executeRefListCommand as j, executeRefAdvancement as k, buildMigrationSpaceGraphEntries as l, resolveToForPlan as lt, contractValidationMeta as m, snapshotVerifierFor as mt, NO_REF_ADVANCEMENT as n, requireDatabaseForLiveMarkerUse as nt, appContractStandInFromIdentity as o, resolveFromForPlan as ot, computeRefAdvancementName as p, runMigrationList as pt, migrationSpaceListEntriesFromAggregate as q, RECORDED_CONTRACT_REF_FORMS as r, resolveAppTargetPath as rt, appliedHashesFromLedger as s, resolveMigrationRef as st, ALL_CONTRACT_REF_FORMS as t, refuseUnknownInvariants as tt, buildReadAggregate as u, retryCommandFor as ut, disposeEmitQueue as v, validateLoadedContract as vt, executeDbUpdate as w, executeContractEmit as x, enrichContract as y, loadAggregateIntegrityViolations as z };
6384
6414
 
6385
- //# sourceMappingURL=ref-DLqjHXyn-CsLViutC.mjs.map
6415
+ //# sourceMappingURL=ref-BCcYHMHw-CY5QunMw.mjs.map