@prisma/orm-toolchain 8.0.0-rc.11-dev.54 → 8.0.0-rc.11-dev.55

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 (57) hide show
  1. package/dist/{aggregate-Bp2GfWCO.mjs → aggregate-CZyUi3Gt.mjs} +8 -8
  2. package/dist/{aggregate-Bp2GfWCO.mjs.map → aggregate-CZyUi3Gt.mjs.map} +1 -1
  3. package/dist/{aggregate-Cb2CASp4.d.mts → aggregate-DwZNs0oH.d.mts} +2 -2
  4. package/dist/{aggregate-Cb2CASp4.d.mts.map → aggregate-DwZNs0oH.d.mts.map} +1 -1
  5. package/dist/cli.mjs +6 -6
  6. package/dist/cli.mjs.map +1 -1
  7. package/dist/cli__control-api.d.mts +7 -7
  8. package/dist/cli__control-api.d.mts.map +1 -1
  9. package/dist/cli__control-api.mjs +1 -1
  10. package/dist/cli__migration-cli.mjs +2 -2
  11. package/dist/{contract-snapshot-store-CM9ubenX-Bkmiki-X.mjs → contract-snapshot-store-1S_6vaGt-mzFobPtq.mjs} +3 -3
  12. package/dist/{contract-snapshot-store-CM9ubenX-Bkmiki-X.mjs.map → contract-snapshot-store-1S_6vaGt-mzFobPtq.mjs.map} +1 -1
  13. package/dist/{errors-BIroGS9E-BaecmSQ3.mjs → errors-DD6iLGXk-B4Q4tIha.mjs} +3 -31
  14. package/dist/errors-DD6iLGXk-B4Q4tIha.mjs.map +1 -0
  15. package/dist/{graph-membership-CdU6royq-DtmPCnV7.mjs → graph-membership-BQ43lP4A-B8rZC7rC.mjs} +3 -3
  16. package/dist/{graph-membership-CdU6royq-DtmPCnV7.mjs.map → graph-membership-BQ43lP4A-B8rZC7rC.mjs.map} +1 -1
  17. package/dist/{invariants-CUbFGAse-B8XFC5Y2.mjs → invariants-C0lpc60l-MH7CqDAw.mjs} +3 -3
  18. package/dist/{invariants-CUbFGAse-B8XFC5Y2.mjs.map → invariants-C0lpc60l-MH7CqDAw.mjs.map} +1 -1
  19. package/dist/{io-CyV6U3am-B8OGzhVR.mjs → io-xKnQrxIC-D_C_lwGm.mjs} +5 -5
  20. package/dist/{io-CyV6U3am-B8OGzhVR.mjs.map → io-xKnQrxIC-D_C_lwGm.mjs.map} +1 -1
  21. package/dist/{migration-CitEa8Nw.mjs → migration-CkACVhgz.mjs} +3 -3
  22. package/dist/{migration-CitEa8Nw.mjs.map → migration-CkACVhgz.mjs.map} +1 -1
  23. package/dist/{migration-graph-B4xBv7B2-BQs2PoMt.mjs → migration-graph-BoiiZAaU-DLht12k7.mjs} +3 -81
  24. package/dist/migration-graph-BoiiZAaU-DLht12k7.mjs.map +1 -0
  25. package/dist/{migration-graph-Dow0Gaw0-Dy6qj7aU.d.mts → migration-graph-D8IuOkZb-pSI7-k4_.d.mts} +4 -24
  26. package/dist/{migration-graph-Dow0Gaw0-Dy6qj7aU.d.mts.map → migration-graph-D8IuOkZb-pSI7-k4_.d.mts.map} +1 -1
  27. package/dist/{migration-graph-DhDB8qEP.d.mts → migration-graph-De1gCcTL.d.mts} +2 -2
  28. package/dist/{migration-graph-DhDB8qEP.d.mts.map → migration-graph-De1gCcTL.d.mts.map} +1 -1
  29. package/dist/migration-tools.d.mts +4 -4
  30. package/dist/migration-tools.mjs +13 -13
  31. package/dist/migration-tools__aggregate.d.mts +1 -1
  32. package/dist/migration-tools__aggregate.mjs +1 -1
  33. package/dist/migration-tools__contract-snapshot-store.mjs +1 -1
  34. package/dist/migration-tools__errors.mjs +1 -1
  35. package/dist/migration-tools__invariants.mjs +1 -1
  36. package/dist/migration-tools__io.mjs +1 -1
  37. package/dist/migration-tools__migration-graph.d.mts +3 -3
  38. package/dist/migration-tools__migration-graph.mjs +3 -3
  39. package/dist/migration-tools__migration.mjs +1 -1
  40. package/dist/migration-tools__ref-resolution.mjs +1 -1
  41. package/dist/migration-tools__refs.mjs +1 -1
  42. package/dist/migration-tools__spaces.mjs +2 -2
  43. package/dist/{ref-_x4xrDPC-RDknK2aP.mjs → ref-CTp4Kvp--3Dgd8LXq.mjs} +238 -220
  44. package/dist/ref-CTp4Kvp--3Dgd8LXq.mjs.map +1 -0
  45. package/dist/{ref-resolution--seVRSHo.mjs → ref-resolution-be3JMf5X.mjs} +2 -2
  46. package/dist/{ref-resolution--seVRSHo.mjs.map → ref-resolution-be3JMf5X.mjs.map} +1 -1
  47. package/dist/{refs-S0wu2JkI-DH94xvrM.mjs → refs-qwvw4_dV-Bk9tl756.mjs} +3 -3
  48. package/dist/{refs-S0wu2JkI-DH94xvrM.mjs.map → refs-qwvw4_dV-Bk9tl756.mjs.map} +1 -1
  49. package/dist/{spaces-CcPrrW8Z.mjs → spaces-D1-7OKid.mjs} +6 -6
  50. package/dist/{spaces-CcPrrW8Z.mjs.map → spaces-D1-7OKid.mjs.map} +1 -1
  51. package/dist/{verify-contract-spaces-BLkC9r9l-IttKTnIr.mjs → verify-contract-spaces-CYjc343k-9_2GpPRg.mjs} +4 -4
  52. package/dist/{verify-contract-spaces-BLkC9r9l-IttKTnIr.mjs.map → verify-contract-spaces-CYjc343k-9_2GpPRg.mjs.map} +1 -1
  53. package/dist/vite-plugin-contract-emit.mjs +1 -1
  54. package/package.json +12 -12
  55. package/dist/errors-BIroGS9E-BaecmSQ3.mjs.map +0 -1
  56. package/dist/migration-graph-B4xBv7B2-BQs2PoMt.mjs.map +0 -1
  57. package/dist/ref-_x4xrDPC-RDknK2aP.mjs.map +0 -1
@@ -1,19 +1,19 @@
1
1
  import { r as getEmittedArtifactPaths, t as emit } from "./exports-DI1kMms6--e9LdT9A.mjs";
2
2
  import { r as expandContractInputs } from "./exports-8-S4PGn0.mjs";
3
- import { F as errorUnknownInvariant, i as errorContractDeserializationFailed, k as errorNoInvariantPath, t as MigrationToolsError, x as errorInvalidRefName } from "./errors-BIroGS9E-BaecmSQ3.mjs";
3
+ import { D as errorNoInvariantPath, M as errorUnknownInvariant, b as errorInvalidRefName, r as errorContractDeserializationFailed, t as MigrationToolsError } from "./errors-DD6iLGXk-B4Q4tIha.mjs";
4
4
  import { r as verifyMigrationHash, t as computeMigrationHash } from "./hash-BAZVWU4a-BdynTmar.mjs";
5
- import { a as snapshotsImportPathFrom, n as createSnapshotContentVerifier, o as writeContractSnapshot, r as readContractSnapshotJson, t as contractSnapshotDir } from "./contract-snapshot-store-CM9ubenX-Bkmiki-X.mjs";
6
- import { t as deriveProvidedInvariants } from "./invariants-CUbFGAse-B8XFC5Y2.mjs";
7
- import { i as materialiseExtensionMigrationPackageIfMissing, r as formatMigrationDirName, u as writeMigrationPackage } from "./io-CyV6U3am-B8OGzhVR.mjs";
5
+ import { a as snapshotsImportPathFrom, n as createSnapshotContentVerifier, o as writeContractSnapshot, r as readContractSnapshotJson, t as contractSnapshotDir } from "./contract-snapshot-store-1S_6vaGt-mzFobPtq.mjs";
6
+ import { t as deriveProvidedInvariants } from "./invariants-C0lpc60l-MH7CqDAw.mjs";
7
+ import { i as materialiseExtensionMigrationPackageIfMissing, r as formatMigrationDirName, u as writeMigrationPackage } from "./io-xKnQrxIC-D_C_lwGm.mjs";
8
8
  import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
9
- import { n as isGraphNode, t as assertHashIsGraphNode } from "./graph-membership-CdU6royq-DtmPCnV7.mjs";
10
- import { a as findPath, o as findPathWithDecision, r as findLatestMigration } from "./migration-graph-B4xBv7B2-BQs2PoMt.mjs";
11
- 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-S0wu2JkI-DH94xvrM.mjs";
12
- 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-BLkC9r9l-IttKTnIr.mjs";
13
- import { d as resolveRecordedPath, f as verifyMigration, l as planMigration, n as buildFabricatedMigrationEdge, r as collectAggregateNamespaces, s as loadContractSpaceAggregate, t as allStorageElementsExternal, u as requireHeadRef } from "./aggregate-Bp2GfWCO.mjs";
14
- import { i as emitContractSpaceArtifacts, o as planAllSpaces } from "./spaces-CcPrrW8Z.mjs";
9
+ import { n as isGraphNode, t as assertHashIsGraphNode } from "./graph-membership-BQ43lP4A-B8rZC7rC.mjs";
10
+ import { i as findPathWithDecision, r as findPath } from "./migration-graph-BoiiZAaU-DLht12k7.mjs";
11
+ 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-qwvw4_dV-Bk9tl756.mjs";
12
+ 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-CYjc343k-9_2GpPRg.mjs";
13
+ import { d as resolveRecordedPath, f as verifyMigration, l as planMigration, n as buildFabricatedMigrationEdge, r as collectAggregateNamespaces, s as loadContractSpaceAggregate, t as allStorageElementsExternal, u as requireHeadRef } from "./aggregate-CZyUi3Gt.mjs";
14
+ import { i as emitContractSpaceArtifacts, o as planAllSpaces } from "./spaces-D1-7OKid.mjs";
15
15
  import { c as internalImportRoot, o as importRootForDependencies, r as createImportSpecifierResolver, t as ImportRootError } from "./import-roots-CYpOz1XZ.mjs";
16
- import { n as parseContractRef, r as parseMigrationRef } from "./ref-resolution--seVRSHo.mjs";
16
+ import { n as parseContractRef, r as parseMigrationRef } from "./ref-resolution-be3JMf5X.mjs";
17
17
  import { i as writeMigrationTs } from "./migration-ts-FyF55c4M.mjs";
18
18
  import { createRequire } from "node:module";
19
19
  import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
@@ -34,7 +34,7 @@ import { createHash } from "node:crypto";
34
34
  import { canonicalizeJson } from "@prisma/orm-framework/components/utils";
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-_x4xrDPC.mjs
37
+ //#region ../../../1-framework/3-tooling/cli/dist/ref-CTp4Kvp-.mjs
38
38
  /**
39
39
  * The typed remediation the CLI attaches to its own errors and findings.
40
40
  * Constructors live here rather than in any library the CLI calls: naming a
@@ -102,18 +102,17 @@ function errorAdvanceRefArgConflict(options) {
102
102
  meta: { advanceRef: options.advanceRef }
103
103
  });
104
104
  }
105
- function errorRefSetHashNotInGraph(resolvedHash, reachableHashes, graphTipHash) {
105
+ function errorRefSetHashNotInGraph(resolvedHash, reachableHashes) {
106
106
  const reachableList = reachableHashes.length > 0 ? reachableHashes.join(", ") : "(none — migration graph is empty)";
107
- const fix = reachableHashes.length > 0 ? graphTipHash !== null ? `Set the ref to a graph-node hash such as ${graphTipHash}, or run \`{bin} migration plan\` to extend the graph.` : "Set the ref to a hash that appears in the migration graph." : "Run `{bin} migration plan` first.";
108
- const nextActions = reachableHashes.length > 0 ? graphTipHash !== null ? [chooseAction(`Set the ref to a graph-node hash such as ${graphTipHash}`), runCommandAction("Extend the migration graph", "{bin} migration plan")] : [chooseAction("Set the ref to a hash that appears in the migration graph")] : [runCommandAction("Plan the first migration", "{bin} migration plan")];
107
+ const fix = reachableHashes.length > 0 ? "Set the ref to the `to` hash of an on-disk migration; `{bin} migration list` shows them." : "Run `{bin} migration plan` first.";
108
+ const nextActions = reachableHashes.length > 0 ? [runCommandAction("List the migrations and their destination hashes", "{bin} migration list"), chooseAction("Set the ref to the `to` hash of one of them")] : [runCommandAction("Plan the first migration", "{bin} migration plan")];
109
109
  return new ActionableCliError("MIGRATION.HASH_NOT_IN_GRAPH", `Resolved contract hash is not in the migration graph: ${resolvedHash}`, {
110
110
  why: reachableHashes.length > 0 ? `The migration graph reaches ${reachableList}; resolved ${resolvedHash} isn't a graph node.` : "The migration graph is empty — no hashes reachable.",
111
111
  fix,
112
112
  nextActions,
113
113
  meta: {
114
114
  resolvedHash,
115
- reachableHashes: [...reachableHashes],
116
- ...graphTipHash !== null ? { graphTipHash } : {}
115
+ reachableHashes: [...reachableHashes]
117
116
  }
118
117
  });
119
118
  }
@@ -203,18 +202,17 @@ function errorRefSetBundleNotFound(hash) {
203
202
  meta: { hash }
204
203
  });
205
204
  }
206
- function errorPlanForgotTheFlag(resolvedHash, reachableRefs, graphTipHash, options) {
205
+ function errorPlanForgotTheFlag(resolvedHash, reachableRefs, options) {
207
206
  const reachableList = reachableRefs.length > 0 ? reachableRefs.map((r) => `${r.name} (${r.hash})`).join(", ") : "(none)";
208
- const refFix = reachableRefs.length > 0 ? `Run migration plan with ${reachableRefs.map((r) => `--from ${r.name}`).join(" or ")}.` : graphTipHash !== null ? `Run migration plan --from ${graphTipHash}.` : "Commit pending migrations first, then run migration plan.";
209
- const nextActions = reachableRefs.length > 0 ? reachableRefs.map((ref) => runCommandAction(`Plan from ${ref.name}`, `{bin} migration plan --from ${ref.name}`)) : graphTipHash !== null ? [runCommandAction("Plan from the graph tip", `{bin} migration plan --from ${graphTipHash}`)] : [chooseAction("Commit pending migrations first, then run migration plan")];
207
+ const refFix = reachableRefs.length > 0 ? `Run migration plan with ${reachableRefs.map((r) => `--from ${r.name}`).join(" or ")}.` : "Pass --from <contract> naming the `to` hash of an on-disk migration (`{bin} migration list` shows them), or point the db ref at one with `{bin} migration ref set db <contract>`.";
208
+ const nextActions = reachableRefs.length > 0 ? reachableRefs.map((ref) => runCommandAction(`Plan from ${ref.name}`, `{bin} migration plan --from ${ref.name}`)) : [runCommandAction("Plan from an explicit origin", "{bin} migration plan --from <contract>"), runCommandAction("Point the db ref at a graph node", "{bin} migration ref set db <contract>")];
210
209
  return new ActionableCliError("MIGRATION.HASH_NOT_IN_GRAPH", `Resolved from-hash is not in the migration graph: ${resolvedHash}`, {
211
210
  why: `The migration graph reaches ${reachableList}; resolved ${resolvedHash} isn't a graph node.`,
212
211
  fix: refFix,
213
212
  nextActions,
214
213
  meta: {
215
214
  resolvedHash,
216
- reachableRefs: reachableRefs.map((r) => r.name),
217
- ...graphTipHash !== null ? { graphTipHash } : {}
215
+ reachableRefs: reachableRefs.map((r) => r.name)
218
216
  },
219
217
  ...ifDefined("cause", options?.cause)
220
218
  });
@@ -252,9 +250,9 @@ function errorSnapshotMissing(identifier, options) {
252
250
  * produce an empty-origin migration that ignores the existing history — almost
253
251
  * always a mistake — so the command refuses and names the three exits.
254
252
  */
255
- function errorPlanOriginUnknown(reachableRefs, graphTipHash) {
256
- const fromSuggestion = reachableRefs.length > 0 ? reachableRefs.map((r) => `--from ${r.name}`).join(" or ") : graphTipHash !== null ? `--from ${graphTipHash}` : "--from <contract>";
257
- const refSetCommand = graphTipHash !== null ? `{bin} migration ref set db ${graphTipHash}` : "{bin} migration ref set db <contract>";
253
+ function errorPlanOriginUnknown(reachableRefs) {
254
+ const fromSuggestion = reachableRefs.length > 0 ? reachableRefs.map((r) => `--from ${r.name}`).join(" or ") : "--from <contract>";
255
+ const refSetCommand = "{bin} migration ref set db <contract>";
258
256
  return new ActionableCliError("MIGRATION.PLAN_ORIGIN_UNKNOWN", "Cannot determine the plan origin: migrations exist but no origin is named", {
259
257
  why: "Migrations exist on disk, but there is no `db` ref and no --from was given, so the plan origin would silently fall back to an empty database and the resulting migration would recreate everything the existing migrations already create.",
260
258
  fix: [
@@ -267,32 +265,25 @@ function errorPlanOriginUnknown(reachableRefs, graphTipHash) {
267
265
  ...reachableRefs.length > 0 ? reachableRefs.map((ref) => runCommandAction(`Plan from ${ref.name}`, `{bin} migration plan --from ${ref.name}`)) : [runCommandAction("Plan from an explicit origin", `{bin} migration plan ${fromSuggestion}`)],
268
266
  runCommandAction("Plan from an empty database deliberately", "{bin} migration plan --from @empty")
269
267
  ],
270
- meta: {
271
- reachableRefs: reachableRefs.map((r) => r.name),
272
- ...graphTipHash !== null ? { graphTipHash } : {}
273
- }
268
+ meta: { reachableRefs: reachableRefs.map((r) => r.name) }
274
269
  });
275
270
  }
276
- function errorMarkerMismatch(markerHash, reachableHashes, graphTip) {
277
- const reachableList = reachableHashes.length > 0 ? reachableHashes.join(", ") : "(none — migration graph is empty)";
278
- const planFromFix = graphTip !== null ? `Run \`{bin} migration plan --from ${graphTip}\` if the live marker is canonical and the on-disk graph needs catching up.` : "Run `{bin} migration plan` if the live marker is canonical and the on-disk graph needs catching up.";
279
- const planCommand = graphTip !== null ? `{bin} migration plan --from ${graphTip}` : "{bin} migration plan";
271
+ function errorMarkerMismatch(markerHash, reachableHashes) {
280
272
  return new ActionableCliError("MIGRATION.MARKER_MISMATCH", "Database marker is not reachable in the on-disk migration graph", {
281
- why: `DB marker is ${markerHash}, but the on-disk migration graph reaches: ${reachableList}.`,
273
+ why: `DB marker is ${markerHash}, but the on-disk migration graph reaches: ${reachableHashes.length > 0 ? reachableHashes.join(", ") : "(none — migration graph is empty)"}.`,
282
274
  fix: [
283
- planFromFix,
275
+ "Run `{bin} migration plan --from <contract>`, naming the graph node the database was migrated from, if the live marker is canonical and the on-disk graph needs catching up.",
284
276
  `Run \`{bin} migration ref set db ${markerHash}\` if the on-disk graph is canonical and the local \`db\` ref drifted.`,
285
277
  "Investigate whether the database was migrated by an out-of-band process."
286
278
  ].join("\n"),
287
279
  nextActions: [
288
- runCommandAction("Catch the on-disk graph up to the live marker", planCommand),
280
+ runCommandAction("Catch the on-disk graph up to the live marker", "{bin} migration plan --from <contract>"),
289
281
  runCommandAction("Point the local db ref at the live marker", `{bin} migration ref set db ${markerHash}`),
290
282
  chooseAction("Investigate whether the database was migrated by an out-of-band process")
291
283
  ],
292
284
  meta: {
293
285
  markerHash,
294
- reachableHashes: [...reachableHashes],
295
- ...graphTip !== null ? { graphTip } : {}
286
+ reachableHashes: [...reachableHashes]
296
287
  }
297
288
  });
298
289
  }
@@ -3401,7 +3392,7 @@ function hasMigrationPath(graph, fromHash, toHash) {
3401
3392
  */
3402
3393
  function refuseMarkerOutsideGraph(args) {
3403
3394
  if (isGraphNode(args.markerHash, args.graph)) return null;
3404
- return errorMarkerMismatch(args.markerHash, [...args.graph.nodes].sort(), findLatestMigration(args.graph)?.to ?? null);
3395
+ return errorMarkerMismatch(args.markerHash, [...args.graph.nodes].sort());
3405
3396
  }
3406
3397
  /**
3407
3398
  * Invariant refusals shared by migrate and migration status: unknown ref invariants and unsatisfiable invariant paths.
@@ -4131,6 +4122,196 @@ function buildMigrationSpaceGraphEntries(args) {
4131
4122
  }
4132
4123
  return spaces;
4133
4124
  }
4125
+ const FULL_HASH_PATTERN = /^([0-9a-f]{64}|empty)$/;
4126
+ function looksLikeFullHash(input) {
4127
+ return FULL_HASH_PATTERN.test(input);
4128
+ }
4129
+ function graphIsEmpty(space) {
4130
+ return space.packages.length === 0;
4131
+ }
4132
+ function outgoingDestinations(graph, hash) {
4133
+ return [...new Set((graph.forwardChain.get(hash) ?? []).map((edge) => edge.to))].sort();
4134
+ }
4135
+ function getReachableRefs(refs, graph) {
4136
+ return Object.entries(refs).flatMap(([name, entry]) => entry && isGraphNode(entry.hash, graph) ? [{
4137
+ name,
4138
+ hash: entry.hash
4139
+ }] : []).sort((a, b) => a.name.localeCompare(b.name));
4140
+ }
4141
+ function assertFromIsGraphNode(fromHash, graph, refs) {
4142
+ try {
4143
+ assertHashIsGraphNode(fromHash, graph);
4144
+ } catch (error) {
4145
+ if (MigrationToolsError.is(error) && error.code === "MIGRATION.HASH_NOT_IN_GRAPH") throw errorPlanForgotTheFlag(fromHash, getReachableRefs(refs, graph), { cause: error });
4146
+ throw error;
4147
+ }
4148
+ }
4149
+ /**
4150
+ * The origin a command uses when `--from` is omitted, as a hash only. An empty
4151
+ * graph with no `db` ref plans from the empty database. An empty graph with a
4152
+ * `db` ref is `ref-needs-baseline`: the ref names a real contract that is not
4153
+ * a graph node yet (`migration plan` handles this by writing a baseline first).
4154
+ * Otherwise the `db` ref must exist and point at a graph node. `migration
4155
+ * plan` materialises the contract on top of this; `migration new` needs only
4156
+ * the hash.
4157
+ */
4158
+ function resolveDefaultOriginHash(space) {
4159
+ const refs = space.refs;
4160
+ const dbRef = refs["db"];
4161
+ if (graphIsEmpty(space)) return ok(dbRef ? {
4162
+ kind: "ref-needs-baseline",
4163
+ refName: "db",
4164
+ fromHash: dbRef.hash
4165
+ } : {
4166
+ kind: "greenfield",
4167
+ fromHash: null
4168
+ });
4169
+ const graph = space.graph();
4170
+ if (!dbRef) return notOk(errorPlanOriginUnknown(getReachableRefs(refs, graph)));
4171
+ try {
4172
+ assertFromIsGraphNode(dbRef.hash, graph, refs);
4173
+ } catch (error) {
4174
+ if (CliStructuredError$1.is(error)) return notOk(error);
4175
+ throw error;
4176
+ }
4177
+ return ok({
4178
+ kind: "ref",
4179
+ refName: "db",
4180
+ fromHash: dbRef.hash
4181
+ });
4182
+ }
4183
+ async function resolveContractRef(parsed, space, options) {
4184
+ const { hash, provenance } = parsed;
4185
+ const refName = provenance.kind === "ref" ? provenance.refName : void 0;
4186
+ try {
4187
+ const at = await space.contractAt(hash, refName !== void 0 ? { refName } : void 0);
4188
+ if (at.provenance === "ref") return ok({
4189
+ kind: "ref",
4190
+ hash: at.hash,
4191
+ contract: at.contract
4192
+ });
4193
+ return ok({
4194
+ kind: "graph-node",
4195
+ hash: at.hash,
4196
+ contract: at.contract
4197
+ });
4198
+ } catch (error) {
4199
+ return mapContractAtError(error, options?.artifactRole !== void 0 ? { artifactRole: options.artifactRole } : void 0);
4200
+ }
4201
+ }
4202
+ async function resolveFromPolicy(parsed, input, refs, explicitFromLabel) {
4203
+ const resolution = await resolveContractRef(parsed, input.space, {
4204
+ ...explicitFromLabel !== void 0 ? { explicitLabel: explicitFromLabel } : {},
4205
+ artifactRole: "from"
4206
+ });
4207
+ if (!resolution.ok) return resolution;
4208
+ if (resolution.value.kind === "graph-node") return ok({
4209
+ kind: "graph-node",
4210
+ fromHash: resolution.value.hash,
4211
+ fromContract: resolution.value.contract
4212
+ });
4213
+ const { hash, contract } = resolution.value;
4214
+ if (graphIsEmpty(input.space)) return ok({
4215
+ kind: "auto-baseline",
4216
+ fromHash: hash,
4217
+ fromContract: contract
4218
+ });
4219
+ const graph = input.space.graph();
4220
+ try {
4221
+ assertFromIsGraphNode(hash, graph, refs);
4222
+ } catch (error) {
4223
+ if (CliStructuredError$1.is(error)) return notOk(error);
4224
+ throw error;
4225
+ }
4226
+ return ok({
4227
+ kind: "ref",
4228
+ fromHash: hash,
4229
+ fromContract: contract
4230
+ });
4231
+ }
4232
+ async function resolveFromForPlan(input) {
4233
+ const { optionsFrom, space } = input;
4234
+ const graph = space.graph();
4235
+ const refs = space.refs;
4236
+ if (optionsFrom === void 0) {
4237
+ const dbRef = refs["db"];
4238
+ if (!dbRef) {
4239
+ if (graphIsEmpty(space)) return ok({
4240
+ kind: "greenfield",
4241
+ fromHash: null,
4242
+ fromContract: null,
4243
+ defaulted: true
4244
+ });
4245
+ return notOk(errorPlanOriginUnknown(getReachableRefs(refs, graph)));
4246
+ }
4247
+ const resolved = await resolveFromPolicy({
4248
+ hash: dbRef.hash,
4249
+ provenance: {
4250
+ kind: "ref",
4251
+ refName: "db"
4252
+ }
4253
+ }, input, refs);
4254
+ if (!resolved.ok) return resolved;
4255
+ const value = resolved.value;
4256
+ if (value.kind === "ref" || value.kind === "graph-node") {
4257
+ const outgoingTo = outgoingDestinations(graph, value.fromHash);
4258
+ if (outgoingTo.length > 0) return ok({
4259
+ ...value,
4260
+ defaultOriginForks: {
4261
+ refName: "db",
4262
+ refHash: value.fromHash,
4263
+ outgoingTo
4264
+ }
4265
+ });
4266
+ }
4267
+ return resolved;
4268
+ }
4269
+ const refResult = parseContractRef(optionsFrom, {
4270
+ graph,
4271
+ refs
4272
+ });
4273
+ if (!refResult.ok) {
4274
+ if (looksLikeFullHash(optionsFrom)) {
4275
+ if (graphIsEmpty(space)) return notOk(errorSnapshotMissing(optionsFrom, { viaRef: false }));
4276
+ return notOk(errorPlanForgotTheFlag(optionsFrom, getReachableRefs(refs, graph)));
4277
+ }
4278
+ return notOk(mapRefResolutionError(refResult.failure));
4279
+ }
4280
+ if (refResult.value.provenance.kind === "reserved-empty") return ok({
4281
+ kind: "greenfield",
4282
+ fromHash: null,
4283
+ fromContract: null,
4284
+ defaulted: false
4285
+ });
4286
+ return resolveFromPolicy(refResult.value, input, refs, optionsFrom);
4287
+ }
4288
+ async function resolveToForPlan(optionsTo, input) {
4289
+ const { space } = input;
4290
+ const graph = space.graph();
4291
+ const refs = space.refs;
4292
+ const refResult = parseContractRef(optionsTo, {
4293
+ graph,
4294
+ refs
4295
+ });
4296
+ if (!refResult.ok) return notOk(mapRefResolutionError(refResult.failure));
4297
+ if (refResult.value.provenance.kind === "reserved-empty") return notOk(mapRefResolutionError({
4298
+ kind: "wrong-grammar",
4299
+ input: optionsTo,
4300
+ expectedGrammar: "contract",
4301
+ message: "`@empty` is only valid as an origin (`--from`); planning a migration to the empty contract is not supported through this shortcut",
4302
+ fix: "Pass `--to` a contract hash, ref name, or migration directory name. To plan starting from an empty database, use `--from @empty`."
4303
+ }));
4304
+ const resolution = await resolveContractRef(refResult.value, space, {
4305
+ explicitLabel: optionsTo,
4306
+ artifactRole: "to"
4307
+ });
4308
+ if (!resolution.ok) return resolution;
4309
+ const { hash, contract } = resolution.value;
4310
+ return ok({
4311
+ hash,
4312
+ contract
4313
+ });
4314
+ }
4134
4315
  /**
4135
4316
  * Policy core of `migration new`: scaffolds a migration package with a `migration.ts` stub for manual authoring.
4136
4317
  */
@@ -4179,7 +4360,6 @@ async function executeMigrationNewCommand(options) {
4179
4360
  const packageCorruptionFailure = refusePackageCorruptionOnAggregate(aggregate, migrationsDir);
4180
4361
  if (packageCorruptionFailure) return notOk(packageCorruptionFailure);
4181
4362
  const packages = aggregate.app.packages;
4182
- const graph = aggregate.app.graph();
4183
4363
  let fromHash = null;
4184
4364
  if (options.from !== void 0) {
4185
4365
  if (packages.length === 0) return notOk(errorRuntime("MIGRATION.HASH_NOT_IN_GRAPH", "--from has no meaning on an empty graph", {
@@ -4200,9 +4380,18 @@ async function executeMigrationNewCommand(options) {
4200
4380
  }
4201
4381
  }));
4202
4382
  fromHash = matchedHashes[0] ?? null;
4203
- } else if (packages.length > 0) {
4204
- const latestMigration = findLatestMigration(graph);
4205
- if (latestMigration) fromHash = latestMigration.to;
4383
+ } else {
4384
+ const origin = resolveDefaultOriginHash(aggregate.app);
4385
+ if (!origin.ok) return notOk(origin.failure);
4386
+ if (origin.value.kind === "ref-needs-baseline") return notOk(errorRuntime("MIGRATION.HASH_NOT_IN_GRAPH", "The db ref is not a graph node yet", {
4387
+ why: `The db ref points at ${origin.value.fromHash}, but ${appMigrationsRelative} contains no migrations, so that contract is not a graph node and nothing can chain from it.`,
4388
+ fix: "Run `{bin} migration plan` first: on an empty graph it writes the baseline migration for the db ref alongside the delta, after which `migration new` can chain from it.",
4389
+ meta: {
4390
+ refName: origin.value.refName,
4391
+ resolvedHash: origin.value.fromHash
4392
+ }
4393
+ }));
4394
+ fromHash = origin.value.fromHash;
4206
4395
  }
4207
4396
  if (fromHash === toStorageHash && !options.from) return notOk(errorRuntime("MIGRATION.NO_CHANGES", "No changes detected", {
4208
4397
  why: "The from and to contract hashes are identical — there is nothing to migrate.",
@@ -4350,174 +4539,6 @@ function buildPlaceholderContractDts(spaceId) {
4350
4539
  ""
4351
4540
  ].join("\n");
4352
4541
  }
4353
- const FULL_HASH_PATTERN = /^([0-9a-f]{64}|empty)$/;
4354
- function looksLikeFullHash(input) {
4355
- return FULL_HASH_PATTERN.test(input);
4356
- }
4357
- function graphIsEmpty(space) {
4358
- return space.packages.length === 0;
4359
- }
4360
- /**
4361
- * The graph tip, or `null` when the graph is empty or already forked —
4362
- * a forked graph has no single tip to compare the default ref against.
4363
- */
4364
- function findUnambiguousTip(graph) {
4365
- try {
4366
- return findLatestMigration(graph)?.to ?? null;
4367
- } catch (error) {
4368
- if (MigrationToolsError.is(error)) return null;
4369
- throw error;
4370
- }
4371
- }
4372
- function getReachableRefs(refs, graph) {
4373
- return Object.entries(refs).flatMap(([name, entry]) => entry && isGraphNode(entry.hash, graph) ? [{
4374
- name,
4375
- hash: entry.hash
4376
- }] : []).sort((a, b) => a.name.localeCompare(b.name));
4377
- }
4378
- function assertFromIsGraphNode(fromHash, graph, refs, graphTipHash) {
4379
- try {
4380
- assertHashIsGraphNode(fromHash, graph);
4381
- } catch (error) {
4382
- if (MigrationToolsError.is(error) && error.code === "MIGRATION.HASH_NOT_IN_GRAPH") throw errorPlanForgotTheFlag(fromHash, getReachableRefs(refs, graph), graphTipHash, { cause: error });
4383
- throw error;
4384
- }
4385
- }
4386
- async function resolveContractRef(parsed, space, options) {
4387
- const { hash, provenance } = parsed;
4388
- const refName = provenance.kind === "ref" ? provenance.refName : void 0;
4389
- try {
4390
- const at = await space.contractAt(hash, refName !== void 0 ? { refName } : void 0);
4391
- if (at.provenance === "ref") return ok({
4392
- kind: "ref",
4393
- hash: at.hash,
4394
- contract: at.contract
4395
- });
4396
- return ok({
4397
- kind: "graph-node",
4398
- hash: at.hash,
4399
- contract: at.contract
4400
- });
4401
- } catch (error) {
4402
- return mapContractAtError(error, options?.artifactRole !== void 0 ? { artifactRole: options.artifactRole } : void 0);
4403
- }
4404
- }
4405
- async function resolveFromPolicy(parsed, input, refs, explicitFromLabel) {
4406
- const resolution = await resolveContractRef(parsed, input.space, {
4407
- ...explicitFromLabel !== void 0 ? { explicitLabel: explicitFromLabel } : {},
4408
- artifactRole: "from"
4409
- });
4410
- if (!resolution.ok) return resolution;
4411
- if (resolution.value.kind === "graph-node") return ok({
4412
- kind: "graph-node",
4413
- fromHash: resolution.value.hash,
4414
- fromContract: resolution.value.contract
4415
- });
4416
- const { hash, contract } = resolution.value;
4417
- if (graphIsEmpty(input.space)) return ok({
4418
- kind: "auto-baseline",
4419
- fromHash: hash,
4420
- fromContract: contract
4421
- });
4422
- const graph = input.space.graph();
4423
- const graphTip = findLatestMigration(graph)?.to ?? null;
4424
- try {
4425
- assertFromIsGraphNode(hash, graph, refs, graphTip);
4426
- } catch (error) {
4427
- if (CliStructuredError$1.is(error)) return notOk(error);
4428
- throw error;
4429
- }
4430
- return ok({
4431
- kind: "ref",
4432
- fromHash: hash,
4433
- fromContract: contract
4434
- });
4435
- }
4436
- async function resolveFromForPlan(input) {
4437
- const { optionsFrom, space } = input;
4438
- const graph = space.graph();
4439
- const refs = space.refs;
4440
- if (optionsFrom === void 0) {
4441
- const dbRef = refs["db"];
4442
- if (!dbRef) {
4443
- if (graphIsEmpty(space)) return ok({
4444
- kind: "greenfield",
4445
- fromHash: null,
4446
- fromContract: null,
4447
- defaulted: true
4448
- });
4449
- return notOk(errorPlanOriginUnknown(getReachableRefs(refs, graph), findLatestMigration(graph)?.to ?? null));
4450
- }
4451
- const resolved = await resolveFromPolicy({
4452
- hash: dbRef.hash,
4453
- provenance: {
4454
- kind: "ref",
4455
- refName: "db"
4456
- }
4457
- }, input, refs);
4458
- if (!resolved.ok) return resolved;
4459
- const value = resolved.value;
4460
- if (value.kind === "ref" || value.kind === "graph-node") {
4461
- const tipHash = findUnambiguousTip(graph);
4462
- if (tipHash !== null && tipHash !== value.fromHash) return ok({
4463
- ...value,
4464
- defaultOriginBehindTip: {
4465
- refName: "db",
4466
- refHash: value.fromHash,
4467
- tipHash
4468
- }
4469
- });
4470
- }
4471
- return resolved;
4472
- }
4473
- const refResult = parseContractRef(optionsFrom, {
4474
- graph,
4475
- refs
4476
- });
4477
- if (!refResult.ok) {
4478
- if (looksLikeFullHash(optionsFrom)) {
4479
- const empty = graphIsEmpty(space);
4480
- const graphTip = findLatestMigration(graph)?.to ?? null;
4481
- if (empty) return notOk(errorSnapshotMissing(optionsFrom, { viaRef: false }));
4482
- return notOk(errorPlanForgotTheFlag(optionsFrom, getReachableRefs(refs, graph), graphTip));
4483
- }
4484
- return notOk(mapRefResolutionError(refResult.failure));
4485
- }
4486
- if (refResult.value.provenance.kind === "reserved-empty") return ok({
4487
- kind: "greenfield",
4488
- fromHash: null,
4489
- fromContract: null,
4490
- defaulted: false
4491
- });
4492
- return resolveFromPolicy(refResult.value, input, refs, optionsFrom);
4493
- }
4494
- async function resolveToForPlan(optionsTo, input) {
4495
- const { space } = input;
4496
- const graph = space.graph();
4497
- const refs = space.refs;
4498
- const refResult = parseContractRef(optionsTo, {
4499
- graph,
4500
- refs
4501
- });
4502
- if (!refResult.ok) return notOk(mapRefResolutionError(refResult.failure));
4503
- if (refResult.value.provenance.kind === "reserved-empty") return notOk(mapRefResolutionError({
4504
- kind: "wrong-grammar",
4505
- input: optionsTo,
4506
- expectedGrammar: "contract",
4507
- message: "`@empty` is only valid as an origin (`--from`); planning a migration to the empty contract is not supported through this shortcut",
4508
- fix: "Pass `--to` a contract hash, ref name, or migration directory name. To plan starting from an empty database, use `--from @empty`."
4509
- }));
4510
- const resolution = await resolveContractRef(refResult.value, space, {
4511
- explicitLabel: optionsTo,
4512
- artifactRole: "to"
4513
- });
4514
- if (!resolution.ok) return resolution;
4515
- const { hash, contract } = resolution.value;
4516
- return ok({
4517
- hash,
4518
- contract
4519
- });
4520
- }
4521
4542
  /**
4522
4543
  * Policy core of `migration plan`: resolves from/to contracts, runs the planner legs, and writes the planned migration packages.
4523
4544
  */
@@ -4689,8 +4710,8 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
4689
4710
  });
4690
4711
  if (!resolutionResult.ok) return notOk(resolutionResult.failure);
4691
4712
  const warnings = [];
4692
- const warnBehindTip = (behind) => {
4693
- warnings.push(`The default origin ref '${behind.refName}' points at ${behind.refHash}, which is not the latest migration (${behind.tipHash}). Planning from it forks the migration graph; pass --from to choose the origin explicitly.`);
4713
+ const warnForks = (forks) => {
4714
+ warnings.push(`The default origin ref '${forks.refName}' points at ${forks.refHash}, which already has a migration leading to ${forks.outgoingTo.join(", ")}. Planning from it forks the migration graph; pass --from to choose the origin explicitly.`);
4694
4715
  };
4695
4716
  switch (resolutionResult.value.kind) {
4696
4717
  case "greenfield":
@@ -4699,13 +4720,13 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
4699
4720
  case "graph-node":
4700
4721
  fromHash = resolutionResult.value.fromHash;
4701
4722
  fromContract = resolutionResult.value.fromContract;
4702
- if (resolutionResult.value.defaultOriginBehindTip !== void 0) warnBehindTip(resolutionResult.value.defaultOriginBehindTip);
4723
+ if (resolutionResult.value.defaultOriginForks !== void 0) warnForks(resolutionResult.value.defaultOriginForks);
4703
4724
  break;
4704
4725
  case "ref":
4705
4726
  fromHash = resolutionResult.value.fromHash;
4706
4727
  fromContract = resolutionResult.value.fromContract;
4707
4728
  fromContractInStore = true;
4708
- if (resolutionResult.value.defaultOriginBehindTip !== void 0) warnBehindTip(resolutionResult.value.defaultOriginBehindTip);
4729
+ if (resolutionResult.value.defaultOriginForks !== void 0) warnForks(resolutionResult.value.defaultOriginForks);
4709
4730
  break;
4710
4731
  case "auto-baseline":
4711
4732
  fromHash = resolutionResult.value.fromHash;
@@ -5015,10 +5036,7 @@ async function executeRefSetCommand(name, contractInput, options) {
5015
5036
  resolvedHash = refResult.value.hash;
5016
5037
  }
5017
5038
  if (resolvedHash === "empty") return notOk(errorRefSetEmptySentinel(resolvedHash));
5018
- if (!isGraphNode(resolvedHash, graph)) {
5019
- const graphTip = findLatestMigration(graph)?.to ?? null;
5020
- return notOk(errorRefSetHashNotInGraph(resolvedHash, [...graph.nodes].sort(), graphTip));
5021
- }
5039
+ if (!isGraphNode(resolvedHash, graph)) return notOk(errorRefSetHashNotInGraph(resolvedHash, [...graph.nodes].sort()));
5022
5040
  if (!bundles.find((bundle) => bundle.metadata.to === resolvedHash)) return notOk(errorRefSetBundleNotFound(resolvedHash));
5023
5041
  const contractJsonPath = join(contractSnapshotDir(migrationsDir, resolvedHash), "contract.json");
5024
5042
  try {
@@ -5074,4 +5092,4 @@ async function executeRefListCommand(options) {
5074
5092
  //#endregion
5075
5093
  export { formatSourceDiagnostic as $, errorLegendHumanOnly as A, runContractSpaceSeedPhase as At, errorUnexpected as B, errorContractArgConflict as C, resolveAppTargetPath as Ct, errorDriverRequired as D, resolveMigrationRef as Dt, errorDestructiveChanges as E, resolveFromForPlan as Et, errorPathUnreachable as F, statusForMigrationHash as Ft, executeMigrateShowPlan as G, executeDbInit as H, errorRunnerFailed as I, targetSupportsMigrations as It, executeRefAdvancement as J, executeMigrationNewCommand as K, errorRuntime as L, toDeclaredExtensionsFromRaw as Lt, errorMigrationPackageNotFound as M, runMigrationList as Mt, errorMigrationPlanningFailed as N, sanitizeErrorMessage as Nt, errorFileNotFound as O, resolveToForPlan as Ot, errorNoMigrations as P, snapshotVerifierFor as Pt, findPackageByDirPath as Q, errorTargetMigrationNotSupported as R, errorConsentPlanMismatch as S, requireLiveDatabase as St, errorDatabaseConnectionRequired as T, resolveContractRefToSnapshot as Tt, executeDbUpdate as U, executeContractEmit as V, executeDbVerify as W, executeRefListCommand as X, executeRefDeleteCommand as Y, executeRefSetCommand as Z, disposeEmitQueue as _, refuseDeclaredExtensionTargetMismatch as _t, appContractStandInFromIdentity as a, loadContractSpaceAggregateForCli as at, errorAdvanceRefArgConflict as b, refusePackageCorruptionOnAggregate as bt, buildMigrationSpaceGraphEntries as c, mapContractAtError as ct, checkSingleTarget as d, migrationSpaceListEntriesFromAggregate as dt, hasMigrationPath as et, chooseAction as f, originHashForStatus as ft, deriveStatusEdgeAnnotations as g, refuseContractSpaceIntegrity as gt, createControlClient as h, readMigrationRefs as ht, advanceRefSafely as i, loadContractSource as it, errorMarkerMissing as j, runMigrationCheck as jt, errorHashMismatch as k, runCommandAction as kt, buildReadAggregate as l, mapIntegrityViolations as lt, computeRefAdvancementName as m, readContractEnvelope as mt, ERROR_CODE_DESTRUCTIVE_CHANGES as n, loadAggregateIntegrityViolations as nt, appliedHashesFromLedger as o, looksLikePath as ot, closeQuietly as p, preflightRefAdvancement as pt, executeMigrationPlanCommand as q, NO_REF_ADVANCEMENT as r, loadContractRawSafely as rt, buildContractSpaceAggregate as s, mapCaughtMigrationError as st, CliStructuredError$1 as t, listRefsByContractHash as tt, buildRefAdvancementFields as u, maskConnectionUrl as ut, enrichContract as v, refuseMarkerOutsideGraph as vt, errorContractValidationFailed as w, resolveContractRef$1 as wt, errorConfigValidation$1 as x, refuseUnknownInvariants as xt, enumerateCheckSpaces as y, refuseMissingInvariantPath as yt, errorTargetMismatch as z };
5076
5094
 
5077
- //# sourceMappingURL=ref-_x4xrDPC-RDknK2aP.mjs.map
5095
+ //# sourceMappingURL=ref-CTp4Kvp--3Dgd8LXq.mjs.map