@prisma/orm-toolchain 8.0.0-rc.14-dev.38 → 8.0.0-rc.14-dev.40

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 (40) hide show
  1. package/dist/{aggregate-qXuJ6w_I.mjs → aggregate-C7IHVcsV.mjs} +7 -3
  2. package/dist/aggregate-C7IHVcsV.mjs.map +1 -0
  3. package/dist/{aggregate-5NMLDtcl.d.mts → aggregate-DLptsx8n.d.mts} +4 -2
  4. package/dist/aggregate-DLptsx8n.d.mts.map +1 -0
  5. package/dist/cli.mjs +170 -111
  6. package/dist/cli.mjs.map +1 -1
  7. package/dist/cli__control-api.d.mts +14 -21
  8. package/dist/cli__control-api.d.mts.map +1 -1
  9. package/dist/cli__control-api.mjs +2 -2
  10. package/dist/cli__control-api__testing.d.mts +1 -1
  11. package/dist/{db-sign-BxYV7wMQ-BB1hlVbH.d.mts → db-sign-BxYV7wMQ-CNy01Yj7.d.mts} +2 -2
  12. package/dist/{db-sign-BxYV7wMQ-BB1hlVbH.d.mts.map → db-sign-BxYV7wMQ-CNy01Yj7.d.mts.map} +1 -1
  13. package/dist/graph-membership-C_ZO26nT-B7C4CJsh.mjs +19 -0
  14. package/dist/graph-membership-C_ZO26nT-B7C4CJsh.mjs.map +1 -0
  15. package/dist/{migration-graph-De1gCcTL.d.mts → migration-graph-Dra4CcyN.d.mts} +7 -2
  16. package/dist/migration-graph-Dra4CcyN.d.mts.map +1 -0
  17. package/dist/migration-tools.d.mts +4 -4
  18. package/dist/migration-tools.mjs +4 -4
  19. package/dist/migration-tools__aggregate.d.mts +2 -2
  20. package/dist/migration-tools__aggregate.mjs +2 -2
  21. package/dist/migration-tools__migration-graph.d.mts +2 -2
  22. package/dist/migration-tools__migration-graph.mjs +2 -2
  23. package/dist/migration-tools__ref-resolution.d.mts +2 -2
  24. package/dist/migration-tools__ref-resolution.mjs +2 -2
  25. package/dist/{ref-Bcy3ShDD-S7NKefbN.mjs → ref-DQpde3VD-BW3Yc5ni.mjs} +145 -90
  26. package/dist/ref-DQpde3VD-BW3Yc5ni.mjs.map +1 -0
  27. package/dist/{ref-resolution-CaHQJXE0.d.mts → ref-resolution-BPhR-kta.d.mts} +20 -12
  28. package/dist/ref-resolution-BPhR-kta.d.mts.map +1 -0
  29. package/dist/{ref-resolution-CoHoeFT7.mjs → ref-resolution-d7rcmU6F.mjs} +22 -5
  30. package/dist/ref-resolution-d7rcmU6F.mjs.map +1 -0
  31. package/dist/vite-plugin-contract-emit.mjs +1 -1
  32. package/package.json +12 -12
  33. package/dist/aggregate-5NMLDtcl.d.mts.map +0 -1
  34. package/dist/aggregate-qXuJ6w_I.mjs.map +0 -1
  35. package/dist/graph-membership-BQ43lP4A-i4Ov419-.mjs +0 -14
  36. package/dist/graph-membership-BQ43lP4A-i4Ov419-.mjs.map +0 -1
  37. package/dist/migration-graph-De1gCcTL.d.mts.map +0 -1
  38. package/dist/ref-Bcy3ShDD-S7NKefbN.mjs.map +0 -1
  39. package/dist/ref-resolution-CaHQJXE0.d.mts.map +0 -1
  40. package/dist/ref-resolution-CoHoeFT7.mjs.map +0 -1
package/dist/cli.mjs CHANGED
@@ -5,9 +5,12 @@ import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
5
5
  import { c as spaceMigrationDirectory, l as spaceRefsDirectory } from "./verify-contract-spaces-CYjc343k-FXABEJZE.mjs";
6
6
  import { C as errorMarkerMissing, D as errorPathUnreachable, E as errorNoMigrations, F as errorSignRefsNotWritten, G as redactUrlCredentials, K as requireLiveDatabase, N as errorRunnerFailed, P as errorRuntime, R as errorTargetMigrationNotSupported, T as errorMigrationPlanningFailed, U as maskConnectionUrl, W as readContractEnvelope, X as targetSupportsMigrations, Y as runCommandAction, _ as errorFileNotFound, a as closeQuietly, d as errorContractArgConflict, f as errorContractConfigMissing, g as errorDriverRequired, h as errorDestructiveChanges, i as chooseAction, l as errorConfigValidation$1, m as errorDatabaseConnectionRequired, n as CliStructuredError$1$1, p as errorContractValidationFailed, r as ERROR_CODE_DESTRUCTIVE_CHANGES, s as errorAdvanceRefArgConflict, t as ActionableCliError, u as errorConsentPlanMismatch, v as errorFromCaught, w as errorMigrationPackageNotFound, x as errorLegendHumanOnly, y as errorHashMismatch, z as errorTargetMismatch } from "./caught-errors-DUIDd-Vm-RNMiEz4x.mjs";
7
7
  import { r as getEmittedArtifactPaths } from "./exports-B41NJHCo-BaEu3TXy.mjs";
8
+ import { r as isInSpaceHistory } from "./graph-membership-C_ZO26nT-B7C4CJsh.mjs";
8
9
  import { d as writeRef, r as readRef } from "./refs-qwvw4_dV-X8sR92eT.mjs";
10
+ import { a as contractHashAtMarker } from "./aggregate-C7IHVcsV.mjs";
9
11
  import { i as createScaffoldSpecifierResolver } from "./import-roots-BeAYfehL.mjs";
10
- import { $ as resolveContractRefToSnapshot, A as formatSourceDiagnostic, C as executeMigrationNewCommand, D as executeRefListCommand, E as executeRefDeleteCommand, F as loadContractSource, G as refuseContractSpaceIntegrity, H as originHashForStatus, I as loadContractSourceWithStack, J as refuseMissingInvariantPath, L as loadContractSpaceAggregateForCli, M as listRefsByContractHash, N as loadAggregateIntegrityViolations, O as executeRefSetCommand, P as loadContractRawSafely, Q as resolveContractRef$1, R as looksLikePath, S as executeMigrateShowPlan, U as preflightRefAdvancement, V as migrationSpaceListEntriesFromAggregate, W as readMigrationRefs, X as refuseUnknownInvariants, Y as refusePackageCorruptionOnAggregate, Z as resolveAppTargetPath, _ as executeContractEmit, a as appliedHashesFromLedger, at as runMigrationList, c as buildReadAggregate, ct as statusForMigrationHash, d as computeRefAdvancementName, f as createControlClient, g as enumerateCheckSpaces, it as runMigrationCheck, j as hasMigrationPath, k as findPackageByDirPath, l as buildRefAdvancementFields, lt as toDeclaredExtensionsFromRaw, n as NO_REF_ADVANCEMENT, ot as snapshotVerifierFor, p as deriveStatusEdgeAnnotations, q as refuseMarkerOutsideGraph, r as advanceRefSafely, s as buildMigrationSpaceGraphEntries, st as sourceWarningDiagnostic, t as DB_UPDATE_POLICY, tt as resolveMigrationRef, u as checkSingleTarget, ut as validateLoadedContract, w as executeMigrationPlanCommand, z as mapContractAtError } from "./ref-Bcy3ShDD-S7NKefbN.mjs";
12
+ import { o as isLiveMarkerRef } from "./ref-resolution-d7rcmU6F.mjs";
13
+ import { $ as refuseUnknownInvariants, A as executeRefListCommand, B as loadContractSourceWithStack, D as executeMigrationPlanCommand, E as executeMigrationNewCommand, F as listRefsByContractHash, G as migrationSpaceListEntriesFromAggregate, H as looksLikePath, I as liveMarkerUse, J as refuseContractSpaceIntegrity, K as preflightRefAdvancement, L as loadAggregateIntegrityViolations, M as findPackageByDirPath, N as formatSourceDiagnostic, P as hasMigrationPath, Q as refusePackageCorruptionOnAggregate, R as loadContractRawSafely, T as executeMigrateShowPlan, U as mapContractAtError, V as loadContractSpaceAggregateForCli, X as refuseMarkerOutsideGraph, Z as refuseMissingInvariantPath, a as RECORDED_OR_EMPTY_CONTRACT_REF_FORMS, at as resolveMigrationRef, b as executeContractEmit, c as appliedHashesFromLedger, d as buildReadAggregate, dt as snapshotVerifierFor, et as requireDatabaseForLiveMarkerUse, f as buildRefAdvancementFields, ft as sourceWarningDiagnostic, g as deriveStatusEdgeAnnotations, h as createControlClient, ht as validateLoadedContract, i as RECORDED_CONTRACT_REF_FORMS, j as executeRefSetCommand, k as executeRefDeleteCommand, lt as runMigrationCheck, m as computeRefAdvancementName, mt as toDeclaredExtensionsFromRaw, n as DB_UPDATE_POLICY, nt as resolveContractRef$1, o as advanceRefSafely, p as checkSingleTarget, pt as statusForMigrationHash, q as readMigrationRefs, r as NO_REF_ADVANCEMENT, rt as resolveContractRefToSnapshot, st as retryCommandFor, t as ALL_CONTRACT_REF_FORMS, tt as resolveAppTargetPath, u as buildMigrationSpaceGraphEntries, ut as runMigrationList, y as enumerateCheckSpaces, z as loadContractSource } from "./ref-DQpde3VD-BW3Yc5ni.mjs";
11
14
  import { a as PRISMA7_QUICK_REFERENCE_STEP, i as PRISMA7_LOOP_STEP, n as InitOutputSchema, o as buildNextSteps, r as NEXT_STEPS_BEFORE_SCAFFOLD, t as DB_SIGN_STEP } from "./output-BcC8eB0h-C5bRd-aC.mjs";
12
15
  import { createRequire } from "node:module";
13
16
  import { ifDefined } from "@prisma/orm-framework/utils/defined";
@@ -36,7 +39,7 @@ import { applyEdits, modify, parse, printParseErrorCode } from "jsonc-parser";
36
39
  import stringWidth from "string-width";
37
40
  import { bold, createColors, cyan, cyanBright, dim, green, yellow } from "colorette";
38
41
  import { build } from "esbuild";
39
- //#region ../../../1-framework/3-tooling/cli/dist/load-config-3s6FxZbn.mjs
42
+ //#region ../../../1-framework/3-tooling/cli/dist/load-config-hnzH6Cap.mjs
40
43
  /**
41
44
  * `isStructuredError` is the repo's own check, and it is the one that matters here: it holds the
42
45
  * regular expression for a dotted `NAMESPACE.SUBCODE`, so only a code the protocol accepts
@@ -1118,7 +1121,8 @@ async function prepareMigrationRun(inputs) {
1118
1121
  if (dbConnection === void 0) return notOk$1(normalizeError(errorDatabaseConnectionRequired({
1119
1122
  why: `Database connection is required for ${commandName} (set db.connection in prisma.config.ts, or pass --db <url>)`,
1120
1123
  commandName,
1121
- missingFlags: ["--db"]
1124
+ missingFlags: ["--db"],
1125
+ ...ifDefined("retryCommand", inputs.retryCommand)
1122
1126
  })));
1123
1127
  if (config.driver === void 0) return notOk$1(normalizeError(errorDriverRequired({ why: `Config.driver is required for ${commandName}` })));
1124
1128
  if (!targetSupportsMigrations(config.target)) return notOk$1(normalizeError(errorTargetMigrationNotSupported({ why: `Target "${config.target.id}" does not support migrations` })));
@@ -1644,6 +1648,7 @@ const FINDINGS_EXIT_CODE$2 = 4;
1644
1648
  * suppresses it.
1645
1649
  */
1646
1650
  const DEFAULT_ADVANCE_REF = "db";
1651
+ const CONTRACT_REF_BRIEF = `Contract reference (${RECORDED_CONTRACT_REF_FORMS})`;
1647
1652
  const NO_PREVIOUS_HASH_CODES = /* @__PURE__ */ new Set([
1648
1653
  "MIGRATION.UNKNOWN_REF",
1649
1654
  "MIGRATION.INVALID_REF_FILE",
@@ -1890,13 +1895,13 @@ function createDbSignCommand(createClient = createControlClient) {
1890
1895
  },
1891
1896
  args: {
1892
1897
  positionals: { contract: positional.optionalString({
1893
- brief: "Contract reference (hash, prefix, ref name, or migration dir name)",
1898
+ brief: CONTRACT_REF_BRIEF,
1894
1899
  placeholder: "contract"
1895
1900
  }) },
1896
1901
  flags: {
1897
1902
  db: dbFlag,
1898
1903
  contract: flag.string({
1899
- brief: "Contract reference (hash, prefix, ref name, migration dir name, <dir>^, or ./path)",
1904
+ brief: CONTRACT_REF_BRIEF,
1900
1905
  placeholder: "contract"
1901
1906
  }),
1902
1907
  advanceRef: flag.string({
@@ -1931,6 +1936,7 @@ function createDbSignCommand(createClient = createControlClient) {
1931
1936
  config: ctx.config,
1932
1937
  migrationsDir,
1933
1938
  refInput: contractRef,
1939
+ argument: "the contract argument",
1934
1940
  contractPathAbsolute: emitted.value.path,
1935
1941
  fallbackToEmitted: true
1936
1942
  });
@@ -2239,7 +2245,7 @@ function createDbUpdateCommand(createClient) {
2239
2245
  db: dbFlag,
2240
2246
  dryRun: flag.boolean({ brief: "Preview the planned operations without applying them" }),
2241
2247
  to: flag.string({
2242
- brief: "Contract to update to (hash, prefix, ref name, migration dir name, or ./path)",
2248
+ brief: `Contract to update to (${RECORDED_CONTRACT_REF_FORMS})`,
2243
2249
  placeholder: "contract"
2244
2250
  }),
2245
2251
  advanceRef: flag.string({
@@ -2250,30 +2256,35 @@ function createDbUpdateCommand(createClient) {
2250
2256
  needs: { config: ormConfigSection },
2251
2257
  handler: async (args, ctx) => {
2252
2258
  const startedAt = Date.now();
2259
+ let destination;
2260
+ if (args.flags.to !== void 0) {
2261
+ const resolved = await resolveContractRefToSnapshot({
2262
+ config: ctx.config,
2263
+ migrationsDir: migrationsDirFor(ctx.config),
2264
+ refInput: args.flags.to,
2265
+ argument: "--to",
2266
+ fallbackToEmitted: false
2267
+ });
2268
+ if (!resolved.ok) return notOk$1(normalizeError(resolved.failure));
2269
+ destination = resolved.value;
2270
+ }
2253
2271
  const prepared = await prepareMigrationRun({
2254
2272
  config: ctx.config,
2255
2273
  cwd: ctx.cwd,
2256
2274
  db: args.flags.db,
2257
2275
  commandName: "db update",
2258
- createClient
2276
+ createClient,
2277
+ retryCommand: retryCommandFor({
2278
+ commandName: args.flags.dryRun ? "db update --dry-run" : "db update",
2279
+ to: args.flags.to,
2280
+ advanceRef: args.flags.advanceRef,
2281
+ canRunOffline: false
2282
+ })
2259
2283
  });
2260
2284
  if (!prepared.ok) return notOk$1(prepared.failure);
2261
2285
  const { client, contractPath, dbConnection, migrationsDir, refsDir } = prepared.value;
2262
- let contractJson = prepared.value.contractJson;
2263
- let snapshotContractPath = contractPath;
2264
- if (args.flags.to !== void 0) {
2265
- const resolved = await resolveContractRefToSnapshot({
2266
- config: ctx.config,
2267
- migrationsDir,
2268
- refInput: args.flags.to,
2269
- contractPathAbsolute: contractPath,
2270
- fallbackToEmitted: false,
2271
- missingBundleFlag: "--to"
2272
- });
2273
- if (!resolved.ok) return notOk$1(normalizeError(resolved.failure));
2274
- contractJson = resolved.value.contractJson;
2275
- snapshotContractPath = resolved.value.contractJsonPath;
2276
- }
2286
+ const contractJson = destination?.contractJson ?? prepared.value.contractJson;
2287
+ const snapshotContractPath = destination?.contractJsonPath ?? contractPath;
2277
2288
  const refName = computeRefAdvancementName({
2278
2289
  ...ifDefined("advanceRef", args.flags.advanceRef),
2279
2290
  ...ifDefined("db", args.flags.db)
@@ -9048,13 +9059,13 @@ function renderMigrateShowGraph(plan, options) {
9048
9059
  const globalMaxDirNameWidth = multiSpace ? Math.max(Math.max(...spaceLayouts.map(({ rowModel }) => computeMaxDirNameWidth(rowModel))), widestRunListName) : void 0;
9049
9060
  const sections = [];
9050
9061
  for (const { space, isApp, rowModel, grid, edgeAnnotations } of spaceLayouts) {
9051
- const liveMarkerHash = plan.renderMarkerHashBySpace.get(space.spaceId);
9062
+ const databaseMarkerHash = plan.databaseMarkerHashBySpace?.get(space.spaceId);
9052
9063
  const tree = renderMigrationGraphCommand({
9053
9064
  grid,
9054
9065
  rowModel,
9055
9066
  contractHash,
9056
9067
  isAppSpace: isApp,
9057
- ...plan.usedLiveMarker && liveMarkerHash !== void 0 ? { dbHash: liveMarkerHash } : {},
9068
+ ...databaseMarkerHash === void 0 ? {} : { dbHash: databaseMarkerHash },
9058
9069
  refsByHash: listRefsByContractHash(space),
9059
9070
  edgeAnnotationsByHash: edgeAnnotations,
9060
9071
  colorize: options.colorize,
@@ -9195,21 +9206,22 @@ function applyPresentations(inputs) {
9195
9206
  next: () => [STATUS_ACTION]
9196
9207
  };
9197
9208
  }
9209
+ const EMITTED_CONTRACT_TARGET = {
9210
+ entry: void 0,
9211
+ refName: void 0
9212
+ };
9198
9213
  /**
9199
9214
  * `--to` as a contract the app graph knows. A ref target keeps the invariants
9200
- * the ref declares; a bare hash carries none. Omitting `--to` targets the
9201
- * emitted contract, which needs no resolution at all.
9202
- */
9203
- function resolveRequestedTarget(to, refs, graph) {
9204
- if (to === void 0) return ok$1({
9205
- entry: void 0,
9206
- refName: void 0
9207
- });
9208
- const resolved = resolveContractRef$1(to, {
9209
- graph,
9210
- refs
9211
- });
9215
+ * the ref declares; a bare hash or `@empty` carries none. An omitted `--to`
9216
+ * and `@contract` both target the emitted contract. `@db` is not resolved
9217
+ * here: it needs the live marker, which is read only once the connection is
9218
+ * open.
9219
+ */
9220
+ function resolveRequestedTarget(to, context) {
9221
+ if (to === void 0) return ok$1(EMITTED_CONTRACT_TARGET);
9222
+ const resolved = resolveContractRef$1(to, context);
9212
9223
  if (!resolved.ok) return notOk$1(normalizeError(resolved.failure));
9224
+ if (resolved.value.provenance.kind === "reserved-contract") return ok$1(EMITTED_CONTRACT_TARGET);
9213
9225
  if (resolved.value.provenance.kind !== "ref") return ok$1({
9214
9226
  entry: {
9215
9227
  hash: resolved.value.hash,
@@ -9219,15 +9231,24 @@ function resolveRequestedTarget(to, refs, graph) {
9219
9231
  });
9220
9232
  const refName = resolved.value.provenance.refName;
9221
9233
  return ok$1({
9222
- entry: refs[refName],
9234
+ entry: context.refs[refName],
9223
9235
  refName
9224
9236
  });
9225
9237
  }
9238
+ function liveMarkerTarget(appMarker) {
9239
+ return {
9240
+ entry: {
9241
+ hash: contractHashAtMarker(appMarker),
9242
+ invariants: []
9243
+ },
9244
+ refName: void 0
9245
+ };
9246
+ }
9226
9247
  function createMigrateCommand(createClient) {
9227
9248
  return defineOrmCommand({
9228
9249
  help: {
9229
9250
  summary: "Apply planned migrations to advance the database",
9230
- description: "Walks every contract space (app + extensions) and applies pending on-disk\nmigrations in canonical order (extensions alphabetically, then app). It\nreplays the on-disk migration graph and never invents an edge. Use --to to\ntarget a specific contract (hash, ref name, or migration directory) and\n--show for a read-only preview of the route it would take.",
9251
+ description: "Walks every contract space (app + extensions) and applies pending on-disk\nmigrations in canonical order (extensions alphabetically, then app). It\nreplays the on-disk migration graph and never invents an edge. Use --to to\ntarget a specific contract and --show for a read-only preview of the route\nit would take.",
9231
9252
  examples: [
9232
9253
  "db migrate",
9233
9254
  "db migrate --db $DATABASE_URL",
@@ -9239,7 +9260,7 @@ function createMigrateCommand(createClient) {
9239
9260
  args: { flags: {
9240
9261
  db: dbFlag,
9241
9262
  to: flag.string({
9242
- brief: "Target contract reference (hash, prefix, ref name, migration dir name, <dir>^, or ./path)",
9263
+ brief: `Target contract reference (${ALL_CONTRACT_REF_FORMS})`,
9243
9264
  placeholder: "contract"
9244
9265
  }),
9245
9266
  advanceRef: flag.string({
@@ -9248,7 +9269,7 @@ function createMigrateCommand(createClient) {
9248
9269
  }),
9249
9270
  show: flag.boolean({ brief: "Preview the migration route without applying (read-only)" }),
9250
9271
  from: flag.string({
9251
- brief: "From-state for the --show preview (@contract, @db, hash, ref name, or dir)",
9272
+ brief: `From-state for the --show preview (${ALL_CONTRACT_REF_FORMS})`,
9252
9273
  placeholder: "contract"
9253
9274
  })
9254
9275
  } },
@@ -9284,18 +9305,25 @@ function createMigrateCommand(createClient) {
9284
9305
  graph: rendering.graphOutput,
9285
9306
  runList: migrateShowRunListRows(plan.migrations, rendering, paint),
9286
9307
  migrationsDir: migrationsRelative,
9287
- database: args.flags.from === void 0 && typeof dbConnection === "string" ? maskConnectionUrl(dbConnection) : void 0,
9308
+ database: plan.databaseMarkerHashBySpace !== void 0 && typeof dbConnection === "string" ? maskConnectionUrl(dbConnection) : void 0,
9288
9309
  from: args.flags.from,
9289
9310
  to: args.flags.to
9290
9311
  })));
9291
9312
  }
9313
+ const liveTarget = isLiveMarkerRef(args.flags.to);
9292
9314
  const startedAt = Date.now();
9293
9315
  const prepared = await prepareMigrationRun({
9294
9316
  config: ctx.config,
9295
9317
  cwd: ctx.cwd,
9296
9318
  db: args.flags.db,
9297
9319
  commandName: "db migrate",
9298
- createClient
9320
+ createClient,
9321
+ retryCommand: retryCommandFor({
9322
+ commandName: "db migrate",
9323
+ to: args.flags.to,
9324
+ advanceRef: args.flags.advanceRef,
9325
+ canRunOffline: false
9326
+ })
9299
9327
  });
9300
9328
  if (!prepared.ok) return notOk$1(prepared.failure);
9301
9329
  const { client, contractJson, contractPath, dbConnection, migrationsDir, refsDir } = prepared.value;
@@ -9321,8 +9349,12 @@ function createMigrateCommand(createClient) {
9321
9349
  checkContracts: true
9322
9350
  }, migrationsDir);
9323
9351
  if (integrityFailure) return notOk$1(normalizeError(integrityFailure));
9324
- const target = resolveRequestedTarget(args.flags.to, aggregate.app.refs, aggregate.app.graph());
9325
- if (!target.ok) return notOk$1(target.failure);
9352
+ const offlineTarget = liveTarget ? void 0 : resolveRequestedTarget(args.flags.to, {
9353
+ graph: aggregate.app.graph(),
9354
+ refs: aggregate.app.refs,
9355
+ contractHash: aggregate.app.contract().storage.storageHash
9356
+ });
9357
+ if (offlineTarget !== void 0 && !offlineTarget.ok) return notOk$1(offlineTarget.failure);
9326
9358
  let document;
9327
9359
  try {
9328
9360
  await client.connect(dbConnection);
@@ -9335,13 +9367,14 @@ function createMigrateCommand(createClient) {
9335
9367
  });
9336
9368
  if (markerRefusal) return notOk$1(normalizeError(markerRefusal));
9337
9369
  }
9338
- const refEntry = target.value.entry;
9370
+ const target = offlineTarget === void 0 ? liveMarkerTarget(appMarker) : offlineTarget.value;
9371
+ const refEntry = target.entry;
9339
9372
  if (refEntry !== void 0 && refEntry.invariants.length > 0) {
9340
9373
  const invariantRefusal = refuseUnknownInvariants({
9341
9374
  graph: appGraph,
9342
9375
  markerInvariants: appMarker?.invariants ?? [],
9343
9376
  refInvariants: refEntry.invariants,
9344
- ...ifDefined("refName", args.flags.to)
9377
+ ...ifDefined("refName", target.refName)
9345
9378
  });
9346
9379
  if (invariantRefusal) return notOk$1(normalizeError(invariantRefusal));
9347
9380
  }
@@ -9350,7 +9383,7 @@ function createMigrateCommand(createClient) {
9350
9383
  let snapshotContractPath = contractPath;
9351
9384
  if (args.flags.to !== void 0 && refEntry !== void 0) {
9352
9385
  if (aggregate.app.packages.find((p) => p.metadata.to === refEntry.hash) !== void 0) try {
9353
- const at = await aggregate.app.contractAt(refEntry.hash, target.value.refName === void 0 ? void 0 : { refName: target.value.refName });
9386
+ const at = await aggregate.app.contractAt(refEntry.hash, target.refName === void 0 ? void 0 : { refName: target.refName });
9354
9387
  applyContract = at.contract;
9355
9388
  snapshotContractJson = blindCast(at.contractJson);
9356
9389
  snapshotContractPath = join(contractSnapshotDir(migrationsDir, refEntry.hash), "contract.json");
@@ -9381,7 +9414,7 @@ function createMigrateCommand(createClient) {
9381
9414
  onProgress: controlProgressReporter(ctx.report),
9382
9415
  ...ifDefined("refHash", refEntry?.hash),
9383
9416
  ...refEntry?.invariants === void 0 ? {} : { refInvariants: refEntry.invariants },
9384
- ...refEntry === void 0 ? {} : ifDefined("refName", args.flags.to)
9417
+ ...ifDefined("refName", target.refName)
9385
9418
  });
9386
9419
  if (!applied.ok) return notOk$1(normalizeError(mapMigrateFailure(applied.failure)));
9387
9420
  const { value } = applied;
@@ -10412,11 +10445,11 @@ function createMigrationPlanCommand(createClient) {
10412
10445
  placeholder: "slug"
10413
10446
  }),
10414
10447
  from: flag.string({
10415
- brief: "Starting contract reference (hash, prefix, ref name, migration dir name, <dir>^, @empty, or ./path)",
10448
+ brief: `Starting contract reference (${RECORDED_OR_EMPTY_CONTRACT_REF_FORMS})`,
10416
10449
  placeholder: "contract"
10417
10450
  }),
10418
10451
  to: flag.string({
10419
- brief: "Destination contract reference; defaults to the emitted contract. Same grammar as --from",
10452
+ brief: `Destination contract reference (${RECORDED_CONTRACT_REF_FORMS}); defaults to the emitted contract`,
10420
10453
  placeholder: "contract"
10421
10454
  })
10422
10455
  } },
@@ -10814,11 +10847,23 @@ async function readDatabaseState(inputs) {
10814
10847
  await closeQuietly(client);
10815
10848
  }
10816
10849
  }
10850
+ function originHashOf(origin) {
10851
+ return origin?.kind === "offline" ? origin.hash : contractHashAtMarker(origin?.marker);
10852
+ }
10853
+ function currentContractOf(origin) {
10854
+ return origin?.kind === "offline" ? origin.hash : origin?.marker?.storageHash ?? null;
10855
+ }
10856
+ function describeOrigin(origin) {
10857
+ if (origin.kind === "offline") return `the --from contract (${shortDisplayHash(origin.hash)})`;
10858
+ return origin.marker !== void 0 ? `the database state (${shortDisplayHash(origin.marker.storageHash)})` : "the database state";
10859
+ }
10817
10860
  function buildNoPathSummary(args) {
10818
- const markerPart = args.markerHash !== void 0 ? `the database state (${shortDisplayHash(args.markerHash)})` : "the database state";
10861
+ const markerPart = describeOrigin(args.origin);
10819
10862
  const targetShort = shortDisplayHash(args.targetHash);
10820
- if (!args.explicitTarget) return `No migration path from ${markerPart} to the application's contract (${targetShort}). Run \`{bin} migration plan --name <name>\` to author one.`;
10821
- return `No migration path from ${markerPart} to ${args.refName !== void 0 ? `the target (${targetShort} via \`${args.refName}\`)` : `the target (${targetShort})`}. Run \`{bin} migration plan --name <name>\` to author one, or pass \`--to <contract>\` to pick a reachable target.`;
10863
+ const { target } = args;
10864
+ if (target.kind === "extension") return `No migration path from ${markerPart} to the head of extension space \`${target.spaceId}\` (${targetShort}).`;
10865
+ if (!target.explicitTarget) return `No migration path from ${markerPart} to the application's contract (${targetShort}). Run \`{bin} migration plan --name <name>\` to author one.`;
10866
+ return `No migration path from ${markerPart} to ${target.refName !== void 0 ? `the target (${targetShort} via \`${target.refName}\`)` : `the target (${targetShort})`}. Run \`{bin} migration plan --name <name>\` to author one, or pass \`--to <contract>\` to pick a reachable target.`;
10822
10867
  }
10823
10868
  function buildStatusHeadline(args) {
10824
10869
  if (args.markerDiverged && args.markerHash !== void 0) return `Database marker ${shortDisplayHash(args.markerHash)} is not in the on-disk migration graph`;
@@ -10889,7 +10934,7 @@ function statusPresentations(inputs) {
10889
10934
  const migrationStatusCommand = defineOrmCommand({
10890
10935
  help: {
10891
10936
  summary: "Show migration path and pending status",
10892
- description: "Shows which migrations are pending between the database marker and the\ntarget contract. Requires a database connection. Pass --from for an\noffline path preview without a database. Use `migration graph` for\ntopology, `migration log` for history, and `migration list` for on-disk\nenumeration.",
10937
+ description: "Shows which migrations are pending between the database marker and the\ntarget contract. Reads the database marker by default. --from names the\norigin instead and runs offline, unless --from or --to is @db, which reads\nthe database. Use `migration graph` for topology, `migration log` for\nhistory, and `migration list` for on-disk enumeration.",
10893
10938
  examples: [
10894
10939
  "migration status",
10895
10940
  "migration status --db $DATABASE_URL",
@@ -10906,11 +10951,11 @@ const migrationStatusCommand = defineOrmCommand({
10906
10951
  placeholder: "id"
10907
10952
  }),
10908
10953
  to: flag.string({
10909
- brief: "Target contract reference (hash, prefix, ref name, migration dir name, <dir>^, or ./path)",
10954
+ brief: `Target contract reference (${ALL_CONTRACT_REF_FORMS})`,
10910
10955
  placeholder: "contract"
10911
10956
  }),
10912
10957
  from: flag.string({
10913
- brief: "Origin contract reference; same grammar as --to. Supplying it switches to offline path computation",
10958
+ brief: `Origin contract reference (${ALL_CONTRACT_REF_FORMS}). With --from the path is computed offline, unless --from or --to is @db`,
10914
10959
  placeholder: "contract"
10915
10960
  }),
10916
10961
  legend: flag.boolean({ brief: "Print a key for the tree glyphs and lane colors" }),
@@ -10921,16 +10966,19 @@ const migrationStatusCommand = defineOrmCommand({
10921
10966
  const migrationsDir = migrationsDirFor(ctx.config);
10922
10967
  const dbConnection = args.flags.db ?? ctx.config.db?.connection;
10923
10968
  const hasDriver = ctx.config.driver !== void 0;
10924
- const usingFromOverride = args.flags.from !== void 0;
10925
- if (!usingFromOverride) {
10926
- const missingDb = requireLiveDatabase({
10927
- dbConnection,
10928
- hasDriver,
10929
- why: "migration status needs a database connection to read the marker and ledger (or pass --from for an offline path preview)",
10930
- retryCommand: "{bin} migration status --from <contract>"
10931
- });
10932
- if (missingDb !== null) return notOk$1(normalizeError(missingDb));
10933
- }
10969
+ const { from, to } = args.flags;
10970
+ const { liveOrigin, liveTarget, needsDatabase } = liveMarkerUse({
10971
+ from,
10972
+ to
10973
+ });
10974
+ const missingDb = requireDatabaseForLiveMarkerUse({
10975
+ from,
10976
+ to,
10977
+ dbConnection,
10978
+ hasDriver,
10979
+ commandName: "migration status"
10980
+ });
10981
+ if (missingDb !== null) return notOk$1(normalizeError(missingDb));
10934
10982
  const refsResult = await readMigrationRefs(appRefsDirFor(ctx.config));
10935
10983
  if (!refsResult.ok) return notOk$1(normalizeError(refsResult.failure));
10936
10984
  const refs = refsResult.value;
@@ -10949,27 +10997,20 @@ const migrationStatusCommand = defineOrmCommand({
10949
10997
  if (corruption) return notOk$1(normalizeError(corruption));
10950
10998
  }
10951
10999
  const appGraph = aggregate.app.graph();
10952
- let activeRefHash;
10953
- let activeRefName;
10954
- let activeRefEntry;
10955
- if (args.flags.to !== void 0) {
10956
- const resolved = resolveContractRef$1(args.flags.to, {
10957
- graph: appGraph,
10958
- refs
10959
- });
11000
+ const refContext = {
11001
+ graph: appGraph,
11002
+ refs,
11003
+ contractHash
11004
+ };
11005
+ let toRef;
11006
+ if (to !== void 0 && !liveTarget) {
11007
+ const resolved = resolveContractRef$1(to, refContext);
10960
11008
  if (!resolved.ok) return notOk$1(normalizeError(resolved.failure));
10961
- activeRefHash = resolved.value.hash;
10962
- if (resolved.value.provenance.kind === "ref") {
10963
- activeRefName = resolved.value.provenance.refName;
10964
- activeRefEntry = refs[activeRefName];
10965
- }
11009
+ toRef = resolved.value;
10966
11010
  }
10967
11011
  let fromOverrideHash;
10968
- if (args.flags.from !== void 0) {
10969
- const resolved = resolveContractRef$1(args.flags.from, {
10970
- graph: appGraph,
10971
- refs
10972
- });
11012
+ if (from !== void 0 && !liveOrigin) {
11013
+ const resolved = resolveContractRef$1(from, refContext);
10973
11014
  if (!resolved.ok) return notOk$1(normalizeError(resolved.failure));
10974
11015
  fromOverrideHash = resolved.value.hash;
10975
11016
  }
@@ -10979,7 +11020,7 @@ const migrationStatusCommand = defineOrmCommand({
10979
11020
  });
10980
11021
  if (!listed.ok) return notOk$1(normalizeError(listed.failure));
10981
11022
  const scopedSpaces = listed.value.spaces;
10982
- const connects = dbConnection !== void 0 && hasDriver && !usingFromOverride;
11023
+ const connects = needsDatabase && dbConnection !== void 0 && hasDriver;
10983
11024
  let database = NO_DATABASE_STATE;
10984
11025
  if (connects) {
10985
11026
  const read = await readDatabaseState({
@@ -10997,7 +11038,10 @@ const migrationStatusCommand = defineOrmCommand({
10997
11038
  database = read.value;
10998
11039
  }
10999
11040
  const appMarker = database.markersBySpace.get(aggregate.app.spaceId);
11000
- if (activeRefEntry !== void 0 && activeRefEntry.invariants.length > 0 && connects) {
11041
+ const activeRefHash = liveTarget ? contractHashAtMarker(appMarker) : toRef?.hash;
11042
+ const activeRefName = toRef?.provenance.kind === "ref" ? toRef.provenance.refName : void 0;
11043
+ const activeRefEntry = activeRefName === void 0 ? void 0 : refs[activeRefName];
11044
+ if (activeRefEntry !== void 0 && activeRefEntry.invariants.length > 0 && liveOrigin) {
11001
11045
  const unknown = refuseUnknownInvariants({
11002
11046
  graph: appGraph,
11003
11047
  markerInvariants: appMarker?.invariants ?? [],
@@ -11021,29 +11065,49 @@ const migrationStatusCommand = defineOrmCommand({
11021
11065
  if (space === void 0) continue;
11022
11066
  const graph = space.graph();
11023
11067
  const spaceContractHash = space.contract().storage.storageHash;
11024
- const targetHash = activeRefHash ?? spaceContractHash;
11025
- if (entry.space === aggregate.app.spaceId) headlineTargetHash = targetHash;
11026
- const markerHash = usingFromOverride ? fromOverrideHash : database.markersBySpace.get(entry.space)?.storageHash;
11027
- const originHash = originHashForStatus(markerHash);
11028
- const markerInGraph = markerHash === void 0 || graph.nodes.has(markerHash) || markerHash === spaceContractHash;
11029
- if (connects && markerInGraph && originHash !== targetHash && noPath === void 0 && !hasMigrationPath(graph, originHash, targetHash)) noPath = {
11030
- markerHash,
11031
- targetHash
11032
- };
11033
- if (connects && markerHash !== void 0 && !markerInGraph) {
11068
+ const isAppSpace = entry.space === aggregate.app.spaceId;
11069
+ const targetHash = isAppSpace ? activeRefHash ?? spaceContractHash : spaceContractHash;
11070
+ if (isAppSpace) headlineTargetHash = targetHash;
11071
+ const origin = liveOrigin ? {
11072
+ kind: "database",
11073
+ marker: database.markersBySpace.get(entry.space)
11074
+ } : isAppSpace && fromOverrideHash !== void 0 ? {
11075
+ kind: "offline",
11076
+ hash: fromOverrideHash
11077
+ } : void 0;
11078
+ const originHash = originHashOf(origin);
11079
+ const markerRead = origin?.kind === "database" || isAppSpace && liveTarget;
11080
+ const readMarker = origin?.kind === "database" ? origin.marker : markerRead ? appMarker : void 0;
11081
+ const markerDiverged = readMarker !== void 0 && !isInSpaceHistory(readMarker.storageHash, {
11082
+ graph,
11083
+ headHash: space.headRef?.hash
11084
+ });
11085
+ if (markerDiverged) {
11034
11086
  divergedMarker ??= {
11035
11087
  space: entry.space,
11036
- markerHash
11088
+ markerHash: readMarker.storageHash
11037
11089
  };
11038
11090
  findings.push(markerNotInHistoryFinding(entry.space));
11039
11091
  }
11092
+ if (origin !== void 0 && !markerDiverged && originHash !== targetHash && noPath === void 0 && !hasMigrationPath(graph, originHash, targetHash)) noPath = {
11093
+ origin,
11094
+ targetHash,
11095
+ target: isAppSpace ? {
11096
+ kind: "app",
11097
+ explicitTarget: to !== void 0,
11098
+ refName: activeRefName
11099
+ } : {
11100
+ kind: "extension",
11101
+ spaceId: entry.space
11102
+ }
11103
+ };
11040
11104
  const ledger = database.ledgersBySpace.get(entry.space) ?? [];
11041
11105
  const annotations = deriveStatusEdgeAnnotations({
11042
11106
  graph,
11043
11107
  targetHash,
11044
11108
  originHash,
11045
- appliedMigrationHashes: connects ? appliedHashesFromLedger(ledger) : /* @__PURE__ */ new Set(),
11046
- showAppliedOverlay: connects
11109
+ appliedMigrationHashes: liveOrigin ? appliedHashesFromLedger(ledger) : /* @__PURE__ */ new Set(),
11110
+ showAppliedOverlay: liveOrigin
11047
11111
  });
11048
11112
  const migrations = entry.migrations.map((migration) => ({
11049
11113
  ...migration,
@@ -11052,7 +11116,7 @@ const migrationStatusCommand = defineOrmCommand({
11052
11116
  totalPending += migrations.filter((migration) => migration.status === "pending").length;
11053
11117
  statusSpaces.push({
11054
11118
  space: entry.space,
11055
- currentContract: markerHash ?? null,
11119
+ currentContract: currentContractOf(origin),
11056
11120
  targetContract: targetHash,
11057
11121
  migrations
11058
11122
  });
@@ -11071,12 +11135,12 @@ const migrationStatusCommand = defineOrmCommand({
11071
11135
  glyphMode,
11072
11136
  styler,
11073
11137
  palette: TONE_MIGRATION_GRAPH_PALETTE,
11074
- isAppSpace: entry.space === aggregate.app.spaceId,
11075
- ...connects && markerHash !== void 0 ? { dbHash: markerHash } : {}
11138
+ isAppSpace,
11139
+ ...markerRead ? { dbHash: contractHashAtMarker(readMarker) } : {}
11076
11140
  });
11077
11141
  }
11078
11142
  const requiredInvariants = [...activeRefEntry?.invariants ?? []].sort();
11079
- if (connects && requiredInvariants.length > 0) {
11143
+ if (liveOrigin && requiredInvariants.length > 0) {
11080
11144
  const held = new Set(appMarker?.invariants ?? []);
11081
11145
  const missing = requiredInvariants.filter((id) => !held.has(id));
11082
11146
  if (missing.length > 0) {
@@ -11087,7 +11151,7 @@ const migrationStatusCommand = defineOrmCommand({
11087
11151
  if (activeRefHash !== void 0) {
11088
11152
  const unreachable = refuseMissingInvariantPath({
11089
11153
  graph: appGraph,
11090
- originHash: originHashForStatus(appMarker?.storageHash),
11154
+ originHash: contractHashAtMarker(appMarker),
11091
11155
  targetHash: activeRefHash,
11092
11156
  missing,
11093
11157
  ...ifDefined("refName", activeRefName)
@@ -11106,12 +11170,7 @@ const migrationStatusCommand = defineOrmCommand({
11106
11170
  showHeading: showSpaceHeadings
11107
11171
  };
11108
11172
  });
11109
- const summary = scopedSpaces.every((entry) => entry.migrations.length === 0) ? "No migrations found" : noPath !== void 0 ? buildNoPathSummary({
11110
- markerHash: noPath.markerHash,
11111
- targetHash: noPath.targetHash,
11112
- explicitTarget: args.flags.to !== void 0,
11113
- refName: activeRefName
11114
- }) : buildStatusHeadline({
11173
+ const summary = scopedSpaces.every((entry) => entry.migrations.length === 0) ? "No migrations found" : noPath !== void 0 ? buildNoPathSummary(noPath) : buildStatusHeadline({
11115
11174
  pendingCount: totalPending,
11116
11175
  targetHash: headlineTargetHash,
11117
11176
  markerDiverged: divergedMarker !== void 0,
@@ -11294,7 +11353,7 @@ function createRefSetCommand(execute = executeRefSetCommand) {
11294
11353
  placeholder: "name"
11295
11354
  }),
11296
11355
  contract: positional.string({
11297
- brief: "Contract reference: hash, prefix, ref name, migration dir name, or <dir>^",
11356
+ brief: `Contract reference (${RECORDED_CONTRACT_REF_FORMS})`,
11298
11357
  placeholder: "contract"
11299
11358
  })
11300
11359
  } },