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

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 (30) hide show
  1. package/dist/{aggregate-Da8PGnzg.d.mts → aggregate-BpcQdygS.d.mts} +11 -7
  2. package/dist/aggregate-BpcQdygS.d.mts.map +1 -0
  3. package/dist/{aggregate-C30LiAd-.mjs → aggregate-T_HG6gq6.mjs} +13 -8
  4. package/dist/aggregate-T_HG6gq6.mjs.map +1 -0
  5. package/dist/{caught-errors-Dijk7Hgg-DBua0IMw.mjs → caught-errors-Bmbi1dBu-DKO5X2tN.mjs} +26 -4
  6. package/dist/caught-errors-Bmbi1dBu-DKO5X2tN.mjs.map +1 -0
  7. package/dist/cli.mjs +177 -38
  8. package/dist/cli.mjs.map +1 -1
  9. package/dist/cli__control-api.d.mts +5 -5
  10. package/dist/cli__control-api.mjs +2 -2
  11. package/dist/cli__control-api__testing.d.mts +1 -1
  12. package/dist/cli__control-api__testing.mjs +1 -1
  13. package/dist/cli__control-api__testing.mjs.map +1 -1
  14. package/dist/cli__migration-cli.mjs +1 -1
  15. package/dist/cli__migration-cli.mjs.map +1 -1
  16. package/dist/{db-sign-DyugidHS-DGvMQ558.d.mts → db-sign-gvrl0kFE-D-nTGx88.d.mts} +25 -9
  17. package/dist/db-sign-gvrl0kFE-D-nTGx88.d.mts.map +1 -0
  18. package/dist/migration-tools.d.mts +1 -1
  19. package/dist/migration-tools.mjs +1 -1
  20. package/dist/migration-tools__aggregate.d.mts +1 -1
  21. package/dist/migration-tools__aggregate.mjs +1 -1
  22. package/dist/{ref-BCcYHMHw-CY5QunMw.mjs → ref-DEiY2Cbd-Bt7yXfOO.mjs} +333 -85
  23. package/dist/ref-DEiY2Cbd-Bt7yXfOO.mjs.map +1 -0
  24. package/dist/vite-plugin-contract-emit.mjs +1 -1
  25. package/package.json +12 -12
  26. package/dist/aggregate-C30LiAd-.mjs.map +0 -1
  27. package/dist/aggregate-Da8PGnzg.d.mts.map +0 -1
  28. package/dist/caught-errors-Dijk7Hgg-DBua0IMw.mjs.map +0 -1
  29. package/dist/db-sign-DyugidHS-DGvMQ558.d.mts.map +0 -1
  30. package/dist/ref-BCcYHMHw-CY5QunMw.mjs.map +0 -1
@@ -8,11 +8,11 @@ import { i as materialiseExtensionMigrationPackageIfMissing, r as formatMigratio
8
8
  import { i as findPathWithDecision, r as findPath } from "./migration-graph-BoiiZAaU-DLht12k7.mjs";
9
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
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";
11
+ import { $ as errorTargetMigrationNotSupported, B as errorRefSetBundleNotFound, D as errorFromCaught, E as errorFileNotFound, G as errorSnapshotMissing, H as errorRefSetHashNotInGraph, I as errorPathUnreachable, J as errorStatementDidNotResolveLoss, K as errorSpaceNotFound, L as errorPlanForgotTheFlag, P as errorMigrationPlanningFailed, Q as errorStatementUnresolved, R as errorPlanOriginUnknown, S as errorContractValidationFailed, U as errorRuntime, V as errorRefSetEmptySentinel, X as errorStatementNeedsMigrationFile, Y as errorStatementInvalid, Z as errorStatementOriginUnknown, _ as errorAmbiguousMigrationRef, c as cliCommand, ct as readContractEnvelope, d as closeQuietly, dt as resolveContractPath, f as collectDeclaredInvariants, ft as resolveMigrationPaths, gt as statementFlag, h as editFileAction, j as errorMarkerMismatch, k as errorInvalidSpaceId, l as cliErrorFromStructured, mt as selfEmitCommand, n as CliStructuredError$1, nt as getTargetMigrations, ot as printedPath, pt as runCommandAction, q as errorStatementAnswersNoQuestion, r as STORE_ORIGIN_SNAPSHOT_STEPS, rt as mapRefResolutionError, s as chooseAction, st as printedPlanCommand, t as ActionableCliError, tt as errorUnexpected, ut as requireLiveDatabase, v as errorConfigValidation$1, vt as toStructuralEdge, x as errorContractConfigMissing, y as errorConsentUnused, z as errorPlanProducedNoOperations } from "./caught-errors-Bmbi1dBu-DKO5X2tN.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-C30LiAd-.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-T_HG6gq6.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-BCcYHMHw.mjs
37
+ //#region ../../../1-framework/3-tooling/cli/dist/ref-DEiY2Cbd.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
  */
@@ -347,12 +347,19 @@ function migrateSchemaCheckAdvice(failedMigration, invocation) {
347
347
  const { file, run } = failedMigrationFile(failedMigration);
348
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)}`)];
349
349
  }
350
+ /** The way out when objects in the database keep an operation from running. */
351
+ function blockingObjectsAdvice(objects, rerun) {
352
+ const named = objects.map(({ kind, name }) => `${kind} ${name}`);
353
+ return [chooseAction(`Drop or change ${named.length === 1 ? named[0] : `${named.slice(0, -1).join(", ")} and ${named.at(-1)}`} in the database yourself, then re-run \`${rerun}\``)];
354
+ }
350
355
  /**
351
356
  * The way out of a failed `db migrate` apply: every path and command it prints works from where the
352
357
  * CLI ran, with the `--config` it was given.
353
358
  */
354
359
  function migrateAdvice(failure, facts, failedOnDisk, invocation) {
355
360
  const failedMigration = failedOnDisk === void 0 ? void 0 : failedMigrationText(failedOnDisk, invocation);
361
+ const { blockingObjects } = failure.meta;
362
+ if (blockingObjects !== void 0) return blockingObjectsAdvice(blockingObjects, cliCommand(invocation, "db migrate", invocation.rerunArgs ?? []));
356
363
  if (facts.failedTypeChange !== void 0) return migrateFailedTypeChangeAdvice(facts.failedTypeChange, failedMigration, invocation);
357
364
  if (facts.rowsWithoutValue !== void 0) return migrateRowsWithoutValueAdvice(facts.rowsWithoutValue, failedMigration, invocation);
358
365
  if (schemaCheckIssues(failure) !== void 0) return migrateSchemaCheckAdvice(failedMigration, invocation);
@@ -424,7 +431,8 @@ function dbInitRunnerFailureError(failure, facts, invocation) {
424
431
  function dbUpdateRunnerFailureError(failure, facts, context) {
425
432
  const { databaseStorageHash, invocation } = context;
426
433
  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}\``)]);
434
+ const { blockingObjects } = failure.meta;
435
+ return runnerFailureError(failure, blockingObjects !== void 0 ? blockingObjectsAdvice(blockingObjects, cliCommand(invocation, "db update", invocation.rerunArgs ?? [])) : 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}\``)]);
428
436
  }
429
437
  function startText(fromHash) {
430
438
  return fromHash === "empty" ? "the empty contract (the space has no marker)" : `the contract its marker names ("${fromHash}")`;
@@ -568,6 +576,7 @@ function parseRenameStatement(statement) {
568
576
  to: to.value
569
577
  });
570
578
  }
579
+ const NAMESPACE_RENAMES = "namespace";
571
580
  const MODEL_RENAMES = "model";
572
581
  const FIELD_RENAMES = "field";
573
582
  const LISTED_LIMIT = 20;
@@ -648,6 +657,9 @@ function lookupModelInNamespace(contract, namespaceId, namespace, name) {
648
657
  ...missing(`the ${contract.name} contract has no model "${name}" in namespace "${namespaceId}" (models there: ${listed(Object.keys(namespace.models))})`)
649
658
  };
650
659
  }
660
+ function modelNames(contract) {
661
+ return Object.entries(contract.contract.domain.namespaces).flatMap(([id, namespace]) => Object.keys(namespace.models).map((model) => displayName(id, model)));
662
+ }
651
663
  function lookupModel(contract, namespaceId, name) {
652
664
  const namespaces = contract.contract.domain.namespaces;
653
665
  if (namespaceId !== void 0) {
@@ -676,10 +688,9 @@ function lookupModel(contract, namespaceId, name) {
676
688
  kind: "refused",
677
689
  ...valueObjectRefusal(name)
678
690
  };
679
- const models = Object.entries(namespaces).flatMap(([id, namespace]) => Object.keys(namespace.models).map((model) => displayName(id, model)));
680
691
  return {
681
692
  kind: "missing",
682
- ...missing(`the ${contract.name} contract has no model "${name}" (models: ${listed(models)})`)
693
+ ...missing(`the ${contract.name} contract has no model "${name}" (models: ${listed(modelNames(contract))})`)
683
694
  };
684
695
  }
685
696
  function readModel(state, side, namespaceId, name) {
@@ -704,7 +715,11 @@ function readFieldOf(contract, found, field, destinationModel) {
704
715
  });
705
716
  }
706
717
  function originCounterpart(state, destinationModel) {
707
- const coordinate = state.originOfRenamedModel.get(qualifiedModel(destinationModel)) ?? destinationModel;
718
+ const namespaceOrigin = state.originOfRenamedNamespace.get(destinationModel.namespaceId);
719
+ const coordinate = state.originOfRenamedModel.get(qualifiedModel(destinationModel)) ?? (namespaceOrigin === void 0 ? destinationModel : {
720
+ namespaceId: asNamespaceId(namespaceOrigin),
721
+ model: destinationModel.model
722
+ });
708
723
  const model = modelAt(state.origin.contract, coordinate);
709
724
  return model === void 0 ? void 0 : {
710
725
  coordinate,
@@ -880,7 +895,81 @@ function oldSideRefusal(state, statement, later, refusal) {
880
895
  if (renamesModel !== void 0) return errorStatementUnresolved(statement, `${sentence(refusal.reason)} A later statement, --${renamesModel.verb} ${renamesModel.text}, renames it, and statements apply in the order given.`, `Put --${renamesModel.verb} ${renamesModel.text} before --${statement.verb} ${statement.text}.`);
881
896
  return unresolved(statement, refusal);
882
897
  }
898
+ function namespacesOf(contract) {
899
+ return Object.keys(contract.contract.domain.namespaces).filter((id) => id !== UNBOUND_NAMESPACE_ID);
900
+ }
901
+ /**
902
+ * The namespace reading of a statement with one name on each side: `undefined` when the old name
903
+ * is no namespace of the origin contract, so the statement is not about a namespace.
904
+ */
905
+ function readNamespaceRename(state, from, to) {
906
+ if (!namespacesOf(state.origin).includes(from)) return void 0;
907
+ if (namespacesOf(state.destination).includes(from)) return notOk(missing(`namespace "${from}" still exists in the destination contract, so it was not renamed`));
908
+ const destinationNamespaces = namespacesOf(state.destination);
909
+ if (!destinationNamespaces.includes(to)) return notOk(missing(`the destination contract has no namespace "${to}" (namespaces: ${listed(destinationNamespaces)})`));
910
+ if (namespacesOf(state.origin).includes(to)) return notOk(missing(`namespace "${to}" already exists in the origin contract, so it cannot be the new name of a namespace`));
911
+ return ok({
912
+ from,
913
+ to
914
+ });
915
+ }
916
+ function resolveNamespaceRename(state, statement, rename) {
917
+ const fromKey = `${NAMESPACE_RENAMES}:${rename.from}`;
918
+ const toKey = `${NAMESPACE_RENAMES}:${rename.to}`;
919
+ if (state.renamedFrom.has(fromKey)) return notOk(errorStatementInvalid(statement, `An earlier statement already renames namespace "${rename.from}".`, REPEATED_NAME_FIX));
920
+ if (state.renamedTo.has(toKey)) return notOk(errorStatementInvalid(statement, `An earlier statement already renames a namespace to "${rename.to}".`, REPEATED_NAME_FIX));
921
+ state.renamedFrom.add(fromKey);
922
+ state.renamedTo.add(toKey);
923
+ state.originOfRenamedNamespace.set(rename.to, rename.from);
924
+ return ok({
925
+ kind: "rename",
926
+ entity: "namespace",
927
+ from: asNamespaceId(rename.from),
928
+ to: asNamespaceId(rename.to)
929
+ });
930
+ }
931
+ /** Whether an earlier or a later statement of the run renames the model with its namespace. */
932
+ function renamedElsewhere(state, later, model) {
933
+ if (state.renamedFrom.has(`${MODEL_RENAMES}:${qualifiedModel(model)}`)) return true;
934
+ return later.some((candidate) => {
935
+ if (candidate.from.length !== 2) return false;
936
+ const reading = readSide(state, "old", candidate.from);
937
+ return reading.ok && reading.value.entity === "model" && qualifiedModel(reading.value.coordinate) === qualifiedModel(model);
938
+ });
939
+ }
940
+ /**
941
+ * A statement with one name on each side reads as a namespace rename or a model rename. Exactly
942
+ * one reading must resolve; `undefined` leaves the statement to the model reading.
943
+ */
944
+ /**
945
+ * A one-name statement whose new name is a namespace of the destination, and whose old name is no
946
+ * namespace or model of the origin, as when a namespace rename is given again.
947
+ */
948
+ function neitherNamespaceNorModel(state, statement, from, to) {
949
+ if (!namespacesOf(state.destination).includes(to)) return void 0;
950
+ if (lookupModel(state.origin, void 0, from).kind !== "missing") return void 0;
951
+ return notOk(unresolved(statement, missing(`the origin contract has no namespace or model "${from}" (namespaces: ${listed(namespacesOf(state.origin))}; models: ${listed(modelNames(state.origin))})`)));
952
+ }
953
+ function resolveOneNameStatement(state, statement, later, from, to) {
954
+ const asNamespace = readNamespaceRename(state, from, to);
955
+ if (asNamespace === void 0) return neitherNamespaceNorModel(state, statement, from, to);
956
+ const fromModel = readModel(state, "old", void 0, from);
957
+ const toModel = readModel(state, "new", void 0, to);
958
+ if (asNamespace.ok && fromModel.ok && renamedElsewhere(state, later, fromModel.value.coordinate)) return resolveNamespaceRename(state, statement, asNamespace.value);
959
+ if (asNamespace.ok && fromModel.ok && toModel.ok) {
960
+ const oldModel = qualifiedModel(fromModel.value.coordinate);
961
+ const newModel = qualifiedModel(toModel.value.coordinate);
962
+ return notOk(errorStatementUnresolved(statement, `"${statement.text}" reads both as a rename of namespace "${from}" to "${to}" and as a rename of model "${oldModel}" to "${newModel}".`, `To rename the model, name it with its namespace: --${statement.verb} ${oldModel}:${newModel}. To rename both the namespace and the model, give both statements: --${statement.verb} ${oldModel}:${newModel} --${statement.verb} ${statement.text}.`));
963
+ }
964
+ if (asNamespace.ok) return resolveNamespaceRename(state, statement, asNamespace.value);
965
+ if (fromModel.ok) return void 0;
966
+ return notOk(unresolved(statement, asNamespace.failure));
967
+ }
883
968
  function resolveStatement(state, statement, later) {
969
+ if (statement.from.length === 1 && statement.to.length === 1) {
970
+ const oneName = resolveOneNameStatement(state, statement, later, statement.from[0], statement.to[0]);
971
+ if (oneName !== void 0) return oneName;
972
+ }
884
973
  const from = readSide(state, "old", statement.from);
885
974
  if (!from.ok) return notOk(oldSideRefusal(state, statement, later, from.failure));
886
975
  const to = readSide(state, "new", statement.to);
@@ -960,6 +1049,14 @@ function resolveFieldStatement(state, statement) {
960
1049
  field: coordinate
961
1050
  });
962
1051
  }
1052
+ /** A delete that names what a rename of the same run renames: both cannot happen. */
1053
+ function deleteOfRenamed(deletes, renames) {
1054
+ for (const deleted of deletes) {
1055
+ const renamed = renames.find((rename) => rename.from.join(".") === deleted.text);
1056
+ if (renamed === void 0) continue;
1057
+ return errorStatementInvalid(deleted, `--delete ${deleted.text} names what --rename ${renamed.text} renames in the same run, so it cannot also be deleted.`, `Leave out --delete ${deleted.text} to keep the data under its new name, or leave out --rename ${renamed.text} to delete it.`);
1058
+ }
1059
+ }
963
1060
  /**
964
1061
  * Resolves the statements a user gave against the origin and destination contracts. Renames
965
1062
  * resolve first, in the order given, so a convert or backfill statement can name a renamed field
@@ -969,6 +1066,7 @@ function resolveFieldStatement(state, statement) {
969
1066
  */
970
1067
  function resolveStatements(input) {
971
1068
  const renames = [];
1069
+ const deletes = [];
972
1070
  const fieldStatements = [];
973
1071
  for (const [index, entry] of input.statements.entries()) {
974
1072
  if (entry.verb === "delete" || entry.verb === "allow") {
@@ -977,6 +1075,7 @@ function resolveStatements(input) {
977
1075
  verb: entry.verb
978
1076
  });
979
1077
  if (!statement.ok) return statement;
1078
+ if (entry.verb === "delete") deletes.push(entry);
980
1079
  continue;
981
1080
  }
982
1081
  if (input.origin.kind === "missing") return notOk(errorStatementOriginUnknown(input.origin));
@@ -1014,12 +1113,15 @@ function resolveStatements(input) {
1014
1113
  },
1015
1114
  originOfRenamedModel: /* @__PURE__ */ new Map(),
1016
1115
  originOfRenamedField: /* @__PURE__ */ new Map(),
1116
+ originOfRenamedNamespace: /* @__PURE__ */ new Map(),
1017
1117
  renamedFrom: /* @__PURE__ */ new Set(),
1018
1118
  renamedTo: /* @__PURE__ */ new Set(),
1019
1119
  fieldStatements: /* @__PURE__ */ new Set()
1020
1120
  };
1021
1121
  const resolved = [];
1022
1122
  const parsedRenames = renames.map(({ statement }) => statement);
1123
+ const contradicted = deleteOfRenamed(deletes, parsedRenames);
1124
+ if (contradicted !== void 0) return notOk(contradicted);
1023
1125
  for (const [position, { index, statement }] of renames.entries()) {
1024
1126
  const result = resolveStatement(state, statement, parsedRenames.slice(position + 1));
1025
1127
  if (!result.ok) return result;
@@ -1038,24 +1140,6 @@ function resolveStatements(input) {
1038
1140
  }
1039
1141
  return ok([...resolved].sort((left, right) => left.index - right.index).map(({ statement }) => statement));
1040
1142
  }
1041
- const STATEMENT_VERBS = [
1042
- "rename",
1043
- "delete",
1044
- "allow",
1045
- "convert",
1046
- "backfill"
1047
- ];
1048
- function isStatementVerb(verb) {
1049
- return STATEMENT_VERBS.includes(verb);
1050
- }
1051
- function isPlannedStatement(statement) {
1052
- return statement.verb === "rename" || statement.verb === "convert" || statement.verb === "backfill";
1053
- }
1054
- /** The field a `convert` and a `delete` of the same run both name, which conflict; `undefined` when none does. */
1055
- function convertAndDelete(statements) {
1056
- const deleted = new Set(statements.filter(({ verb }) => verb === "delete").map(({ text }) => text));
1057
- return statements.find(({ verb, text }) => verb === "convert" && deleted.has(text))?.text;
1058
- }
1059
1143
  /** The plan's renames, resolved; empty when there are none or they do not resolve. */
1060
1144
  function resolvedRenames(contracts) {
1061
1145
  const renames = contracts.statements.filter((statement) => statement.verb === "rename");
@@ -1073,9 +1157,21 @@ function resolvedRenames(contracts) {
1073
1157
  function sameModel(left, right) {
1074
1158
  return left.namespaceId === right.namespaceId && left.model === right.model;
1075
1159
  }
1076
- /** The model a rename statement of `contracts` gives `coordinate` in the destination, if any. */
1160
+ /**
1161
+ * The model a rename statement of `contracts` gives `coordinate` in the destination, if any: a
1162
+ * rename of the model, or else a rename of its namespace, under which the model keeps its name when
1163
+ * the destination has it there.
1164
+ */
1077
1165
  function renamedModel(coordinate, contracts) {
1078
- for (const statement of resolvedRenames(contracts)) if (statement.kind === "rename" && statement.entity === "model" && sameModel(statement.from, coordinate)) return statement.to;
1166
+ const renames = resolvedRenames(contracts);
1167
+ for (const statement of renames) if (statement.kind === "rename" && statement.entity === "model" && sameModel(statement.from, coordinate)) return statement.to;
1168
+ for (const statement of renames) if (statement.kind === "rename" && statement.entity === "namespace" && statement.from === coordinate.namespaceId) {
1169
+ const moved = {
1170
+ namespaceId: statement.to,
1171
+ model: coordinate.model
1172
+ };
1173
+ return contracts.destination?.domain.namespaces[moved.namespaceId]?.models[moved.model] !== void 0 ? moved : void 0;
1174
+ }
1079
1175
  }
1080
1176
  /** The field of the origin contract at `coordinate`, as the destination names it after the plan's renames. */
1081
1177
  function destinationField(coordinate, contracts) {
@@ -1088,12 +1184,15 @@ function destinationField(coordinate, contracts) {
1088
1184
  /**
1089
1185
  * The subject as a statement names it: `Model` or `Model.field`, with the namespace when its
1090
1186
  * contract has several, or the storage name when no model stores what the operation is about. A
1091
- * field of a model the plan renames is named through the model's new name, as a rename of the
1092
- * field is written.
1187
+ * model the plan renames or moves, and a field of it, are named through the model's new name, as a
1188
+ * rename of the field is written.
1093
1189
  */
1094
1190
  function subjectText(subject, contracts) {
1095
1191
  switch (subject.kind) {
1096
- case "model": return modelStatementText(contracts.origin, subject);
1192
+ case "model": {
1193
+ const renamed = renamedModel(subject, contracts);
1194
+ return renamed === void 0 || contracts.destination === void 0 ? modelStatementText(contracts.origin, subject) : modelStatementText(contracts.destination, renamed);
1195
+ }
1097
1196
  case "field": {
1098
1197
  const renamed = renamedModel(subject, contracts);
1099
1198
  return `${renamed === void 0 || contracts.destination === void 0 ? modelStatementText(contracts.origin, subject) : modelStatementText(contracts.destination, renamed)}.${subject.field}`;
@@ -1124,7 +1223,7 @@ function lossText(subject, text, originKnown, loss) {
1124
1223
  */
1125
1224
  const ORIGIN_SNAPSHOT_RECOVERY = ["If it was renamed, keep its data instead: store the snapshot of the contract the database is at, then run this command again and answer with --rename.", ...STORE_ORIGIN_SNAPSHOT_STEPS.map((step) => step.replaceAll("{bin}", "prisma"))].join("\n");
1126
1225
  function sameCoordinate(statement, subject) {
1127
- if (statement.kind !== "rename" || subject.kind === "storage") return false;
1226
+ if (statement.kind !== "rename" || statement.entity === "namespace" || subject.kind === "storage") return false;
1128
1227
  const { from } = statement;
1129
1228
  if (from.namespaceId !== subject.namespaceId || from.model !== subject.model) return false;
1130
1229
  return subject.kind === "field" ? statement.entity === "field" && statement.from.field === subject.field : statement.entity === "model";
@@ -1242,14 +1341,14 @@ function dataLossQuestion(loss, contracts) {
1242
1341
  };
1243
1342
  }
1244
1343
  /**
1245
- * The question for one operation that changes who can read or write its subject's rows: it widens
1246
- * access, as disabling row-level security does, or changes it either way, as dropping a policy
1247
- * does. Each such operation is its own question, answered by its own `allow`.
1344
+ * The question for one operation that changes who can read or write its subject's data: it widens
1345
+ * access, or changes it in a way that can go either way. Each such operation is its own question,
1346
+ * answered by its own `allow`.
1248
1347
  */
1249
- function accessWideningQuestion(widening, contracts) {
1250
- const subject = subjectText(widening.subject, contracts);
1348
+ function accessChangeQuestion(change, contracts) {
1349
+ const subject = subjectText(change.subject, contracts);
1251
1350
  return {
1252
- question: `${widening.label} would ${widening.widens ? "widen" : "change"} who can read and write its rows.`,
1351
+ question: `${change.label} would ${change.widens ? "widen" : "change"} who can read and write its data.`,
1253
1352
  subject,
1254
1353
  verbs: ["allow"],
1255
1354
  forms: {},
@@ -1258,14 +1357,12 @@ function accessWideningQuestion(widening, contracts) {
1258
1357
  }
1259
1358
  const keyOf = (planned) => migrationSubjectKey(planned.subject);
1260
1359
  /**
1261
- * The pre-answers that answer a question about `text`: every `delete` of the subject, or the
1262
- * first `allow` of it no earlier question took, since an `allow` answers one operation.
1360
+ * The namespace of the model or field a subject names, when the planner removes that namespace: a
1361
+ * `delete` of the namespace answers the question too.
1263
1362
  */
1264
- function givenFor(verb, text, preAnswers, taken) {
1265
- const matching = preAnswers.filter((statement) => statement.verb === verb && statement.text === text);
1266
- if (verb === "delete") return matching;
1267
- const first = matching.find((statement) => !taken.has(statement));
1268
- return first === void 0 ? [] : [first];
1363
+ function removedNamespaceOf(subject, namespaces) {
1364
+ if (subject.kind === "storage") return void 0;
1365
+ return namespaces?.removed.includes(subject.namespaceId) === true ? subject.namespaceId : void 0;
1269
1366
  }
1270
1367
  /**
1271
1368
  * A `delete` answers for its subject; an `allow` for its one operation, known by its label and
@@ -1275,6 +1372,12 @@ function questionKey(verb, entry) {
1275
1372
  return verb === "allow" ? `allow:${entry.label}:${keyOf(entry)}` : `delete:${keyOf(entry)}`;
1276
1373
  }
1277
1374
  function checkAnswers(questions, answers) {
1375
+ const plansAgain = answers.some((answer) => answer?.verb === "rename" || answer?.verb === "convert");
1376
+ const open = answers.findIndex((answer) => answer === void 0);
1377
+ if (open !== -1 && !plansAgain) throw new InternalError(`answerQuestions left "${questions[open]?.question}" open, which it may do only beside a rename or convert answer that plans again.`, { cause: {
1378
+ questions: questions.map(({ subject }) => subject),
1379
+ answers
1380
+ } });
1278
1381
  if (answers.length !== questions.length) {
1279
1382
  const noun = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
1280
1383
  throw new InternalError(`answerQuestions gave ${noun(answers.length, "answer")} for ${noun(questions.length, "question")}; answer each question in order, or throw to refuse.`, { cause: {
@@ -1295,6 +1398,57 @@ function checkAnswers(questions, answers) {
1295
1398
  if (rejected !== void 0) throw new InternalError(`answerQuestions answered "${question.question}" wrongly: ${rejected}`, cause);
1296
1399
  });
1297
1400
  }
1401
+ function namespaceRenameAdvice(removed, added) {
1402
+ const [only] = added;
1403
+ if (only === void 0) return void 0;
1404
+ const lead = `If namespace "${removed}" was renamed, --rename ${removed}:`;
1405
+ if (added.length === 1) return `${lead}${only} renames it instead.`;
1406
+ return `${lead}<new namespace> renames it instead, where <new namespace> is ${`${added.slice(0, -1).join(", ")} or ${added.at(-1)}`}.`;
1407
+ }
1408
+ /**
1409
+ * The first question about a model or field of a namespace the destination contract no longer has
1410
+ * says that a `delete` of the namespace answers every question about it, and, when the destination
1411
+ * adds a namespace, how to rename the namespace instead.
1412
+ */
1413
+ function withNamespaceDeleteOnFirstQuestion(questions, added) {
1414
+ const told = /* @__PURE__ */ new Set();
1415
+ return questions.map((question) => {
1416
+ const { removedNamespace } = question;
1417
+ if (removedNamespace === void 0 || told.has(removedNamespace)) return question;
1418
+ told.add(removedNamespace);
1419
+ const lines = [
1420
+ question.question,
1421
+ `--delete ${removedNamespace} answers this question and every other about a model or field of namespace "${removedNamespace}", which the destination contract no longer has.`,
1422
+ namespaceRenameAdvice(removedNamespace, added)
1423
+ ];
1424
+ return {
1425
+ ...question,
1426
+ question: lines.filter((line) => line !== void 0).join("\n")
1427
+ };
1428
+ });
1429
+ }
1430
+ /**
1431
+ * A question about a model or field of a namespace the destination removed, which also accepts the
1432
+ * namespace's own answers: a `delete` of the namespace, or a `rename` of it to another one.
1433
+ */
1434
+ function acceptingNamespaceAnswers(question, removedNamespace, contracts) {
1435
+ if (removedNamespace === void 0) return question;
1436
+ const namespaceAnswer = (verb, text) => {
1437
+ if (verb === "delete") return text === removedNamespace ? "delete" : void 0;
1438
+ if (verb !== "rename") return void 0;
1439
+ const resolved = resolvesWith({
1440
+ verb,
1441
+ text
1442
+ }, contracts);
1443
+ return resolved.ok && resolved.value?.kind === "rename" && resolved.value.entity === "namespace" && resolved.value.from === removedNamespace ? "rename" : void 0;
1444
+ };
1445
+ return {
1446
+ ...question,
1447
+ removedNamespace,
1448
+ namespaceAnswer,
1449
+ validate: (verb, text) => namespaceAnswer(verb, text) !== void 0 ? void 0 : question.validate(verb, text)
1450
+ };
1451
+ }
1298
1452
  function withRecoveryOnFirstStorageQuestion(asked, recoveryApplies) {
1299
1453
  const first = recoveryApplies ? asked.findIndex(({ loss }) => loss.subject.kind === "storage") : -1;
1300
1454
  return asked.map(({ question }, index) => index === first ? {
@@ -1304,7 +1458,7 @@ function withRecoveryOnFirstStorageQuestion(asked, recoveryApplies) {
1304
1458
  }
1305
1459
  /**
1306
1460
  * Asks about every operation of a plan that would lose data and, when `askAccess`, every one that
1307
- * would widen access, until each is answered. A `delete` or `allow` text in `preAnswers`, or
1461
+ * would change access, until each is answered. A `delete` or `allow` text in `preAnswers`, or
1308
1462
  * `consentAll` for its verb, answers its question without asking. A rename or convert typed at the
1309
1463
  * prompt is a statement the plan did not have, so the plan is made again with every statement, and
1310
1464
  * the operation it answered must be gone; a loss the new plan has on the same subject, such as a
@@ -1332,44 +1486,60 @@ async function askPlanQuestions(input) {
1332
1486
  operationIndex: entry.operationIndex,
1333
1487
  loss: verb === "delete" && "loss" in entry ? entry.loss : void 0
1334
1488
  });
1335
- for (const [verb, entries] of [["delete", pending("delete", plan.dataLoss)], ["allow", input.askAccess ? pending("allow", plan.accessWidening) : []]]) for (const entry of entries) {
1336
- const text = subjectText(entry.subject, contracts);
1337
- const given = givenFor(verb, text, input.preAnswers, usedPreAnswers);
1338
- for (const statement of given) usedPreAnswers.add(statement);
1339
- if (input.consentAll[verb] || given.length > 0) consent(verb, entry, text);
1489
+ for (const [verb, entries] of [["delete", pending("delete", plan.dataLoss)], ["allow", input.askAccess ? pending("allow", plan.accessChanges) : []]]) {
1490
+ const texts = entries.map((entry) => subjectText(entry.subject, contracts));
1491
+ const given = input.preAnswers.filter((statement) => statement.verb === verb && (verb === "delete" || !usedPreAnswers.has(statement)));
1492
+ const matched = matchConsents(verb, entries.map((entry, index) => ({
1493
+ text: texts[index] ?? "",
1494
+ removedNamespace: removedNamespaceOf(entry.subject, plan.namespaces)
1495
+ })), given.map(({ text }) => text));
1496
+ for (const position of matched.used) {
1497
+ const statement = given[position];
1498
+ if (statement !== void 0) usedPreAnswers.add(statement);
1499
+ }
1500
+ entries.forEach((entry, index) => {
1501
+ if (input.consentAll[verb] || matched.answered.has(index)) consent(verb, entry, texts[index] ?? "");
1502
+ });
1340
1503
  }
1341
1504
  const losses = pending("delete", plan.dataLoss);
1342
- const widenings = input.askAccess ? pending("allow", plan.accessWidening) : [];
1343
- if (losses.length + widenings.length === 0 && round > 0) break;
1344
- const questions = [...withRecoveryOnFirstStorageQuestion(losses.map((loss) => ({
1505
+ const accessChanges = input.askAccess ? pending("allow", plan.accessChanges) : [];
1506
+ if (losses.length + accessChanges.length === 0 && round > 0) break;
1507
+ const questions = [...withNamespaceDeleteOnFirstQuestion(withRecoveryOnFirstStorageQuestion(losses.map((loss) => ({
1345
1508
  loss,
1346
- question: dataLossQuestion(loss, contracts)
1347
- })), !input.originKnown), ...widenings.map((widening) => accessWideningQuestion(widening, contracts))];
1509
+ question: acceptingNamespaceAnswers(dataLossQuestion(loss, contracts), removedNamespaceOf(loss.subject, plan.namespaces), contracts)
1510
+ })), !input.originKnown), plan.namespaces?.added ?? []), ...accessChanges.map((change) => accessChangeQuestion(change, contracts))];
1348
1511
  const answers = await input.answer(questions);
1349
1512
  checkAnswers(questions, answers);
1350
1513
  const typed = [];
1351
1514
  answers.forEach((answer, index) => {
1352
- const entry = [...losses, ...widenings][index];
1515
+ const entry = [...losses, ...accessChanges][index];
1353
1516
  const question = questions[index];
1354
- if (entry === void 0 || question === void 0) return;
1517
+ if (answer === void 0 || entry === void 0 || question === void 0) return;
1355
1518
  if (answer.verb === "rename" || answer.verb === "convert") typed.push({
1356
1519
  statement: {
1357
1520
  verb: answer.verb,
1358
1521
  text: answer.text
1359
1522
  },
1360
- loss: entry
1523
+ loss: entry,
1524
+ ofNamespace: question.namespaceAnswer?.(answer.verb, answer.text) === "rename"
1361
1525
  });
1362
1526
  else consent(answer.verb, entry, question.subject);
1363
1527
  });
1364
1528
  if (typed.length === 0) {
1365
- if (losses.length + widenings.length === 0) break;
1529
+ if (losses.length + accessChanges.length === 0) break;
1366
1530
  continue;
1367
1531
  }
1368
- statements = [...statements, ...typed.map(({ statement }) => statement)];
1532
+ const given = new Set(statements.map(({ verb, text }) => `${verb} ${text}`));
1533
+ for (const { statement } of typed) {
1534
+ const key = `${statement.verb} ${statement.text}`;
1535
+ if (given.has(key)) continue;
1536
+ given.add(key);
1537
+ statements = [...statements, statement];
1538
+ }
1369
1539
  const replanned = await input.replan(statements);
1370
1540
  if (!replanned.ok) return replanned;
1371
1541
  plan = replanned.value;
1372
- for (const entry of plan.accessWidening) {
1542
+ for (const entry of plan.accessChanges) {
1373
1543
  const allowed = consented.get(questionKey("allow", entry));
1374
1544
  if (allowed !== void 0) consented.set(questionKey("allow", entry), {
1375
1545
  ...allowed,
@@ -1378,7 +1548,7 @@ async function askPlanQuestions(input) {
1378
1548
  }
1379
1549
  const operationOf = (entry) => `${entry.label}:${keyOf(entry)}`;
1380
1550
  const stillPlanned = new Set(plan.dataLoss.map(operationOf));
1381
- const unresolved = typed.find(({ loss }) => stillPlanned.has(operationOf(loss)));
1551
+ const unresolved = typed.find(({ loss, ofNamespace }) => !ofNamespace && stillPlanned.has(operationOf(loss)));
1382
1552
  if (unresolved !== void 0) return notOk(errorStatementDidNotResolveLoss(unresolved.statement, subjectText(unresolved.loss.subject, contracts)));
1383
1553
  }
1384
1554
  const unused = input.preAnswers.filter((statement) => !usedPreAnswers.has(statement));
@@ -1393,7 +1563,7 @@ async function askPlanQuestions(input) {
1393
1563
  });
1394
1564
  }
1395
1565
  function questionSubjects(plan, askAccess, contracts) {
1396
- const subjects = [...plan.dataLoss, ...askAccess ? plan.accessWidening : []].map((entry) => subjectText(entry.subject, contracts));
1566
+ const subjects = [...plan.dataLoss, ...askAccess ? plan.accessChanges : []].map((entry) => subjectText(entry.subject, contracts));
1397
1567
  return [...new Set(subjects)];
1398
1568
  }
1399
1569
  /**
@@ -1403,13 +1573,67 @@ function questionSubjects(plan, askAccess, contracts) {
1403
1573
  */
1404
1574
  function refuseUnusedConsents(input) {
1405
1575
  const subjects = questionSubjects(input.plan, true, input.contracts);
1406
- const used = /* @__PURE__ */ new Set();
1407
- for (const [verb, entries] of [["delete", input.plan.dataLoss], ["allow", input.plan.accessWidening]]) for (const entry of entries) {
1408
- const text = subjectText(entry.subject, input.contracts);
1409
- for (const statement of givenFor(verb, text, input.statements, used)) used.add(statement);
1576
+ const unused = [];
1577
+ for (const [verb, entries] of [["delete", input.plan.dataLoss], ["allow", input.plan.accessChanges]]) {
1578
+ const questions = entries.map((entry) => ({
1579
+ text: subjectText(entry.subject, input.contracts),
1580
+ removedNamespace: verb === "delete" ? removedNamespaceOf(entry.subject, input.plan.namespaces) : void 0
1581
+ }));
1582
+ const given = input.statements.filter((statement) => statement.verb === verb);
1583
+ unused.push(...matchConsents(verb, verb === "delete" ? [...new Map(questions.map((q) => [q.text, q])).values()] : questions, given.map(({ text }) => text)).unused);
1410
1584
  }
1411
- const unused = input.statements.filter((statement) => !isPlannedStatement(statement) && !used.has(statement));
1412
- return unused.length === 0 ? ok(void 0) : notOk(errorStatementAnswersNoQuestion(unused, subjects));
1585
+ const answersNothing = unused.filter(({ alreadyAnsweredBy }) => alreadyAnsweredBy === void 0);
1586
+ if (answersNothing.length > 0) return notOk(errorStatementAnswersNoQuestion(answersNothing, subjects));
1587
+ return unused.length === 0 ? ok(void 0) : notOk(errorConsentUnused(unused, subjects));
1588
+ }
1589
+ /**
1590
+ * Matches `--delete` or `--allow` flags to questions as an apply does, whatever their order. A
1591
+ * `delete` naming a subject answers every question about it; then a `delete` naming a removed
1592
+ * namespace answers the questions of the namespace still open. An `allow` answers one operation,
1593
+ * so each question takes a flag of its own. A flag no question took is unused, and says what had
1594
+ * already answered its question, if anything had. Every path that matches consent flags asks this,
1595
+ * so a dry run and an apply refuse the same flags.
1596
+ */
1597
+ function matchConsents(verb, questions, texts) {
1598
+ const answered = /* @__PURE__ */ new Map();
1599
+ const used = /* @__PURE__ */ new Set();
1600
+ const take = (index, position) => {
1601
+ const text = texts[position];
1602
+ if (text === void 0) return;
1603
+ answered.set(index, text);
1604
+ used.add(position);
1605
+ };
1606
+ questions.forEach((question, index) => {
1607
+ const position = texts.findIndex((text, at) => text === question.text && (verb === "delete" || !used.has(at)));
1608
+ if (position !== -1) take(index, position);
1609
+ });
1610
+ if (verb === "delete") questions.forEach((question, index) => {
1611
+ if (answered.has(index) || question.removedNamespace === void 0) return;
1612
+ const position = texts.indexOf(question.removedNamespace);
1613
+ if (position !== -1) take(index, position);
1614
+ });
1615
+ return {
1616
+ answered,
1617
+ used,
1618
+ unused: texts.flatMap((text, position) => {
1619
+ if (used.has(position)) return [];
1620
+ return [{
1621
+ verb,
1622
+ text,
1623
+ alreadyAnsweredBy: questions.find((question) => question.text === text) !== void 0 ? {
1624
+ kind: "subject",
1625
+ subject: text,
1626
+ flag: {
1627
+ verb,
1628
+ text
1629
+ }
1630
+ } : questions.some(({ removedNamespace }) => removedNamespace === text) ? {
1631
+ kind: "namespace",
1632
+ namespace: text
1633
+ } : void 0
1634
+ }];
1635
+ })
1636
+ };
1413
1637
  }
1414
1638
  /**
1415
1639
  * `operationOffset` is the number of operations the result lists before the plan that applied the
@@ -1435,6 +1659,24 @@ function reportConsentStatement(consented, operationIndexes) {
1435
1659
  description: consentDescription(consented.verb, consented.subject, consented.text, consented.loss)
1436
1660
  };
1437
1661
  }
1662
+ const STATEMENT_VERBS = [
1663
+ "rename",
1664
+ "delete",
1665
+ "allow",
1666
+ "convert",
1667
+ "backfill"
1668
+ ];
1669
+ function isStatementVerb(verb) {
1670
+ return STATEMENT_VERBS.includes(verb);
1671
+ }
1672
+ function isPlannedStatement(statement) {
1673
+ return statement.verb === "rename" || statement.verb === "convert" || statement.verb === "backfill";
1674
+ }
1675
+ /** The field a `convert` and a `delete` of the same run both name, which conflict; `undefined` when none does. */
1676
+ function convertAndDelete(statements) {
1677
+ const deleted = new Set(statements.filter(({ verb }) => verb === "delete").map(({ text }) => text));
1678
+ return statements.find(({ verb, text }) => verb === "convert" && deleted.has(text))?.text;
1679
+ }
1438
1680
  /** The fields of `values` named as `destination` names them; a column no field stores is left out. */
1439
1681
  function reportTemporaryValues(values, destination) {
1440
1682
  return values.flatMap(({ subject, value }) => subject.kind === "field" ? [{
@@ -2033,7 +2275,7 @@ async function executeRun(options) {
2033
2275
  });
2034
2276
  const schemaIR = await familyInstance.introspect({
2035
2277
  driver,
2036
- contract: collectAggregateNamespaces(aggregate)
2278
+ contract: collectAggregateNamespaces(aggregate, fromContract)
2037
2279
  });
2038
2280
  onProgress?.({
2039
2281
  action,
@@ -2088,7 +2330,7 @@ async function executeRun(options) {
2088
2330
  const orderedResolutions = collectOrdered(planned.value.applyOrder, planned.value.perSpace);
2089
2331
  const subjects = action === "dbUpdate" ? subjectsAcrossSpaces(orderedResolutions) : {
2090
2332
  dataLoss: [],
2091
- accessWidening: [],
2333
+ accessChanges: [],
2092
2334
  temporaryValues: []
2093
2335
  };
2094
2336
  const operations = orderedResolutions.flatMap((r) => r.entry.displayOps);
@@ -2104,7 +2346,8 @@ async function executeRun(options) {
2104
2346
  ...entry,
2105
2347
  loss: entry.loss
2106
2348
  })),
2107
- accessWidening: labelled(subjects.accessWidening)
2349
+ accessChanges: labelled(subjects.accessChanges),
2350
+ ...ifDefined("namespaces", orderedResolutions.find(({ spaceId }) => spaceId === aggregate.app.spaceId)?.entry.namespaces)
2108
2351
  });
2109
2352
  };
2110
2353
  const first = await plan(statements);
@@ -2121,7 +2364,7 @@ async function executeRun(options) {
2121
2364
  preAnswers: statementTexts.filter((statement) => !isPlannedStatement(statement)),
2122
2365
  consentAll: {
2123
2366
  delete: options.acceptDataLoss,
2124
- allow: options.acceptAccessWidening
2367
+ allow: options.acceptAccessChanges
2125
2368
  },
2126
2369
  origin: fromContract ?? EMPTY_ORIGIN$1,
2127
2370
  originKnown: fromContract !== null,
@@ -2161,15 +2404,18 @@ async function executeRun(options) {
2161
2404
  destination: contract,
2162
2405
  statements: plannedTexts
2163
2406
  };
2407
+ const namespaceAnswersOf = (subject) => ifDefined("removedNamespace", removedNamespaceOf(subject, run.namespaces));
2164
2408
  const asked = (entries) => entries.map((entry) => ({
2165
2409
  ...entry,
2166
- text: subjectText(entry.subject, contractsAsked)
2410
+ text: subjectText(entry.subject, contractsAsked),
2411
+ ...namespaceAnswersOf(entry.subject)
2167
2412
  }));
2168
2413
  const databaseStorageHash = action === "dbUpdate" ? recordedDatabaseContract(aggregate, markerRows) : void 0;
2169
2414
  const subjects = action === "dbUpdate" ? {
2170
2415
  dataLoss: asked(run.subjects.dataLoss),
2171
- accessWidening: asked(run.subjects.accessWidening),
2172
- temporaryValues: reportTemporaryValues(run.subjects.temporaryValues, contract)
2416
+ accessChanges: asked(run.subjects.accessChanges),
2417
+ temporaryValues: reportTemporaryValues(run.subjects.temporaryValues, contract),
2418
+ ...ifDefined("namespaces", run.namespaces)
2173
2419
  } : void 0;
2174
2420
  if (mode === "plan") {
2175
2421
  const aggregateOps = orderedResolutions.flatMap((r) => r.entry.displayOps);
@@ -2290,7 +2536,7 @@ function operationsBefore(orderedResolutions, spaceId) {
2290
2536
  return orderedResolutions.slice(0, position).reduce((count, resolution) => count + resolution.entry.displayOps.length, 0);
2291
2537
  }
2292
2538
  /**
2293
- * What the planned operations lose and whose access they widen, across every space, each at its
2539
+ * What the planned operations lose and whose access they change, across every space, each at its
2294
2540
  * position in the operations the result reports.
2295
2541
  */
2296
2542
  function subjectsAcrossSpaces(orderedResolutions) {
@@ -2300,7 +2546,7 @@ function subjectsAcrossSpaces(orderedResolutions) {
2300
2546
  }));
2301
2547
  return {
2302
2548
  dataLoss: orderedResolutions.flatMap((resolution) => offset(resolution, resolution.entry.dataLoss)),
2303
- accessWidening: orderedResolutions.flatMap((resolution) => offset(resolution, resolution.entry.accessWidening)),
2549
+ accessChanges: orderedResolutions.flatMap((resolution) => offset(resolution, resolution.entry.accessChanges)),
2304
2550
  temporaryValues: orderedResolutions.flatMap((resolution) => offset(resolution, resolution.entry.temporaryValues))
2305
2551
  };
2306
2552
  }
@@ -2766,7 +3012,7 @@ async function executeDbUpdate(options) {
2766
3012
  statements: options.statements ?? [],
2767
3013
  answerQuestions: options.answerQuestions,
2768
3014
  acceptDataLoss: options.acceptDataLoss ?? false,
2769
- acceptAccessWidening: options.acceptAccessWidening ?? false,
3015
+ acceptAccessChanges: options.acceptAccessChanges ?? false,
2770
3016
  ...ifDefined("verifySnapshotContent", options.verifySnapshotContent),
2771
3017
  ...ifDefined("onPlannerWarnings", options.onPlannerWarnings),
2772
3018
  ...ifDefined("onProgress", options.onProgress)
@@ -3254,7 +3500,7 @@ function buildAtHeadResolution(args) {
3254
3500
  strategy: "declared-state",
3255
3501
  appliedStatements: [],
3256
3502
  dataLoss: [],
3257
- accessWidening: [],
3503
+ accessChanges: [],
3258
3504
  temporaryValues: [],
3259
3505
  migrationEdges: [buildFabricatedMigrationEdge({
3260
3506
  currentMarkerStorageHash: liveMarker?.storageHash,
@@ -3629,7 +3875,7 @@ var ControlClientImpl = class {
3629
3875
  targetId: this.options.target.targetId,
3630
3876
  extensions: this.options.extensions ?? [],
3631
3877
  ...ifDefined("acceptDataLoss", options.acceptDataLoss),
3632
- ...ifDefined("acceptAccessWidening", options.acceptAccessWidening),
3878
+ ...ifDefined("acceptAccessChanges", options.acceptAccessChanges),
3633
3879
  ...ifDefined("statements", options.statements),
3634
3880
  answerQuestions: options.answerQuestions,
3635
3881
  ...ifDefined("verifySnapshotContent", this.snapshotVerifier),
@@ -5795,7 +6041,8 @@ async function runPlannerLeg(planner, migrations, frameworkComponents, contract,
5795
6041
  return at === void 0 ? [] : [at];
5796
6042
  })
5797
6043
  })), fromContract, contract, 0),
5798
- temporaryValues: reportTemporaryValues(plannerResult.temporaryValues, contract)
6044
+ temporaryValues: reportTemporaryValues(plannerResult.temporaryValues, contract),
6045
+ ...ifDefined("namespaces", plannerResult.namespaces)
5799
6046
  });
5800
6047
  }
5801
6048
  /**
@@ -5846,7 +6093,8 @@ async function answerPlannedDataLoss(input) {
5846
6093
  const legs = (delta) => ({
5847
6094
  delta,
5848
6095
  dataLoss: [...input.baseline?.dataLoss ?? [], ...delta?.dataLoss ?? []],
5849
- accessWidening: []
6096
+ accessChanges: [],
6097
+ ...ifDefined("namespaces", delta?.namespaces)
5850
6098
  });
5851
6099
  const answered = await askPlanQuestions({
5852
6100
  plan: legs(input.delta),
@@ -6410,6 +6658,6 @@ async function executeRefListCommand(options) {
6410
6658
  }
6411
6659
  }
6412
6660
  //#endregion
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 };
6661
+ export { refuseMarkerOutsideGraph 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, migrationSpaceListEntriesFromAggregate as J, mapIntegrityViolations as K, listRefsByContractHash as L, executeRefSetCommand as M, findPackageByDirPath as N, executeMigrationPlanCommand as O, formatSourceDiagnostic as P, refuseDeclaredExtensionTargetMismatch as Q, liveMarkerUse as R, executeDbInit as S, executeDbVerify as T, loadContractSpaceAggregateForCli as U, loadContractSource as V, looksLikePath as W, readMigrationRefs as X, preflightRefAdvancement as Y, refuseContractSpaceIntegrity as Z, deriveStatusEdgeAnnotations as _, statusForMigrationHash as _t, advanceRefSafely as a, resolveContractRef$1 as at, enumerateCheckSpaces as b, buildContractSpaceAggregate as c, resolveMigrationRef as ct, buildRefAdvancementFields as d, retryCommandFor as dt, refuseMissingInvariantPath as et, checkSingleTarget as f, runContractSpaceSeedPhase as ft, createControlClient as g, sourceWarningDiagnostic as gt, convertAndDelete as h, snapshotVerifierFor as ht, RECORDED_OR_EMPTY_CONTRACT_REF_FORMS as i, resolveAppTargetPath as it, executeRefListCommand as j, executeRefAdvancement as k, buildMigrationSpaceGraphEntries as l, resolveStatements as lt, contractValidationMeta as m, runMigrationList as mt, NO_REF_ADVANCEMENT as n, refuseUnknownInvariants as nt, appContractStandInFromIdentity as o, resolveContractRefToSnapshot as ot, computeRefAdvancementName as p, runMigrationCheck as pt, matchConsents as q, RECORDED_CONTRACT_REF_FORMS as r, requireDatabaseForLiveMarkerUse as rt, appliedHashesFromLedger as s, resolveFromForPlan as st, ALL_CONTRACT_REF_FORMS as t, refusePackageCorruptionOnAggregate as tt, buildReadAggregate as u, resolveToForPlan as ut, disposeEmitQueue as v, toDeclaredExtensionsFromRaw as vt, executeDbUpdate as w, executeContractEmit as x, enrichContract as y, validateLoadedContract as yt, loadAggregateIntegrityViolations as z };
6414
6662
 
6415
- //# sourceMappingURL=ref-BCcYHMHw-CY5QunMw.mjs.map
6663
+ //# sourceMappingURL=ref-DEiY2Cbd-Bt7yXfOO.mjs.map