@prisma/orm-toolchain 8.0.0-rc.11-dev.5 → 8.0.0-rc.11-dev.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -1,10 +1,11 @@
1
1
  import { r as getEmittedArtifactPaths } from "./exports-CE6OD63o-4Qpqr2W7.mjs";
2
2
  import { t as MigrationToolsError } from "./errors-SoLLYLtw-DMxVbVs9.mjs";
3
+ import { t as contractSnapshotDir } from "./contract-snapshot-store-qGrwlGmt-Cf2NFzRL.mjs";
3
4
  import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
4
5
  import { r as readRef } from "./refs-BpSpzdYB-BcDelHGt.mjs";
5
6
  import { c as spaceMigrationDirectory } from "./verify-contract-spaces-CrxvgpwD-D5LLXGci.mjs";
6
7
  import { i as createScaffoldSpecifierResolver } from "./import-roots-BHOrDJbI.mjs";
7
- import { $ as loadAggregateIntegrityViolations, A as errorMigrationPackageNotFound, At as runMigrationList, C as errorDatabaseConnectionRequired, D as errorHashMismatch, Dt as runCommandAction, E as errorFileNotFound, F as errorRuntime, G as executeMigrationPlanCommand, I as errorTargetMigrationNotSupported, J as executeRefListCommand, L as errorTargetMismatch, M as errorNoMigrations, Mt as statusForMigrationHash, N as errorPathUnreachable, Nt as targetSupportsMigrations, O as errorLegendHumanOnly, P as errorRunnerFailed, Pt as toDeclaredExtensionsFromRaw, Q as listRefsByContractHash, R as errorUnexpected, S as errorContractValidationFailed, St as resolveContractRefToSnapshot, T as errorDriverRequired, Tt as resolveRefAdvancementFields, U as executeMigrateShowPlan, W as executeMigrationNewCommand, X as findPackageByDirPath, Y as executeRefSetCommand, Z as hasMigrationPath, _ as enumerateCheckSpaces, _t as refusePackageCorruptionOnAggregate, b as errorConsentPlanMismatch, bt as resolveAppTargetPath, ct as originHashForStatus, d as closeQuietly, dt as readContractIR, et as loadContractRawSafely, ft as readMigrationRefs, gt as refuseMissingInvariantPath, ht as refuseMarkerOutsideGraph, i as appliedHashesFromLedger, it as mapContractAtError, j as errorMigrationPlanningFailed, jt as sanitizeErrorMessage, k as errorMarkerMissing, kt as runMigrationCheck, l as checkSingleTarget, lt as preflightRefAdvancement, m as deriveStatusEdgeAnnotations, n as advanceRefSafely, nt as looksLikePath, o as buildMigrationSpaceGraphEntries, ot as maskConnectionUrl, p as createControlClient, pt as refuseContractSpaceIntegrity, q as executeRefDeleteCommand, rt as mapCaughtMigrationError, s as buildReadAggregate, st as migrationSpaceListEntriesFromAggregate, t as CliStructuredError$1$1, tt as loadContractSpaceAggregateForCli, u as chooseAction, ut as readContractEnvelope, v as errorAdvanceRefArgConflict, vt as refuseUnknownInvariants, w as errorDestructiveChanges, wt as resolveMigrationRef, x as errorContractArgConflict, xt as resolveContractRef$1, y as errorConfigValidation$1, yt as requireLiveDatabase, z as executeContractEmit } from "./ref-DcqFmceq-QaUjgZeM.mjs";
8
+ import { $ as listRefsByContractHash, A as errorMarkerMissing, At as sanitizeErrorMessage, B as executeContractEmit, C as errorContractValidationFailed, D as errorFileNotFound, E as errorDriverRequired, Et as runCommandAction, F as errorRunnerFailed, G as executeMigrationNewCommand, I as errorRuntime, J as executeRefDeleteCommand, K as executeMigrationPlanCommand, L as errorTargetMigrationNotSupported, M as errorMigrationPlanningFailed, Mt as targetSupportsMigrations, N as errorNoMigrations, Nt as toDeclaredExtensionsFromRaw, O as errorHashMismatch, Ot as runMigrationCheck, P as errorPathUnreachable, Q as hasMigrationPath, R as errorTargetMismatch, S as errorContractArgConflict, St as resolveContractRefToSnapshot, T as errorDestructiveChanges, W as executeMigrateShowPlan, X as executeRefSetCommand, Y as executeRefListCommand, Z as findPackageByDirPath, _t as refusePackageCorruptionOnAggregate, a as appliedHashesFromLedger, at as mapContractAtError, b as errorConfigValidation$1, bt as resolveAppTargetPath, c as buildReadAggregate, ct as migrationSpaceListEntriesFromAggregate, d as chooseAction, dt as readContractEnvelope, et as loadAggregateIntegrityViolations, f as closeQuietly, ft as readMigrationRefs, gt as refuseMissingInvariantPath, h as deriveStatusEdgeAnnotations, ht as refuseMarkerOutsideGraph, it as mapCaughtMigrationError, j as errorMigrationPackageNotFound, jt as statusForMigrationHash, k as errorLegendHumanOnly, kt as runMigrationList, l as buildRefAdvancementFields, lt as originHashForStatus, m as createControlClient, n as NO_REF_ADVANCEMENT, nt as loadContractSpaceAggregateForCli, p as computeRefAdvancementName, pt as refuseContractSpaceIntegrity, r as advanceRefSafely, rt as looksLikePath, s as buildMigrationSpaceGraphEntries, st as maskConnectionUrl, t as CliStructuredError$1$1, tt as loadContractRawSafely, u as checkSingleTarget, ut as preflightRefAdvancement, v as enumerateCheckSpaces, vt as refuseUnknownInvariants, w as errorDatabaseConnectionRequired, wt as resolveMigrationRef, x as errorConsentPlanMismatch, xt as resolveContractRef$1, y as errorAdvanceRefArgConflict, yt as requireLiveDatabase, z as errorUnexpected } from "./ref-uqvZQnnQ-DpAQaLiM.mjs";
8
9
  import { n as buildNextSteps, t as InitOutputSchema } from "./output-D83nTTpC-XlvN30yS.mjs";
9
10
  import { r as loadConfig, t as finalizeConfig } from "./exports-BXXeNWlj.mjs";
10
11
  import { createRequire } from "node:module";
@@ -35,7 +36,7 @@ import { applyEdits, modify, parse, printParseErrorCode } from "jsonc-parser";
35
36
  import stringWidth from "string-width";
36
37
  import { bold, createColors, cyan, cyanBright, dim, green, yellow } from "colorette";
37
38
  import { build } from "esbuild";
38
- //#region ../../../1-framework/3-tooling/cli/dist/load-config-Dg1SXbzd.mjs
39
+ //#region ../../../1-framework/3-tooling/cli/dist/load-config-Hrks_J7N.mjs
39
40
  const MISSING_CONFIG_ACTION = {
40
41
  kind: "run-command",
41
42
  label: "Create a config file",
@@ -624,6 +625,51 @@ function mapDbInitFailure(failure) {
624
625
  return assertNever(exhaustive, `Unhandled DbInitFailure code: ${String(exhaustive)}`);
625
626
  }
626
627
  /**
628
+ * Where migrations live for this project. Resolved against the invocation
629
+ * directory, which is also the config file's directory for every default
630
+ * invocation.
631
+ */
632
+ function migrationsDirFor(config, cwd) {
633
+ return resolve(cwd, config.migrations?.dir ?? "migrations");
634
+ }
635
+ /** The app subspace under {@link migrationsDirFor}. */
636
+ function appMigrationsDirFor(config, cwd) {
637
+ return spaceMigrationDirectory(migrationsDirFor(config, cwd), APP_SPACE_ID);
638
+ }
639
+ /**
640
+ * The config file an operation should anchor its project paths on. The engine
641
+ * loads the config and hands a handler the value but not the path, and
642
+ * `--config` is an engine flag the handler never sees, so a handler names the
643
+ * invocation directory's file. That equals the loaded file for every
644
+ * invocation whose config sits in the invocation directory.
645
+ */
646
+ function projectConfigPathFor(cwd) {
647
+ return resolve(cwd, "prisma.config.ts");
648
+ }
649
+ /**
650
+ * Where refs live. The framework keeps them under the app subspace rather than
651
+ * at the migrations root.
652
+ */
653
+ function appRefsDirFor(config, cwd) {
654
+ return resolve(appMigrationsDirFor(config, cwd), "refs");
655
+ }
656
+ /**
657
+ * The emitted contract. The config loader has already resolved
658
+ * `contract.output` against the config file's directory, so this only has an
659
+ * effect for a config handed in raw, as tests do.
660
+ */
661
+ function contractPathFor(config, cwd) {
662
+ const output = config.contract?.output;
663
+ return output === void 0 ? void 0 : resolve(cwd, output);
664
+ }
665
+ /**
666
+ * The header's rendering of a path: relative to where the user invoked the
667
+ * CLI, as the commander shell rendered it against the config file.
668
+ */
669
+ function displayPath(path, cwd) {
670
+ return relative(cwd, path);
671
+ }
672
+ /**
627
673
  * Render a single statement of an `OperationPreview` for the human-readable
628
674
  * preview block. SQL statements get a trailing `;` if missing so the rendered
629
675
  * preview is byte-identical to the legacy `string[]`-based renderer for SQL
@@ -849,51 +895,6 @@ function migrationResultBlocks(result) {
849
895
  function migrationResultNextActions(result, applyCommand) {
850
896
  return result.mode === "plan" ? [runCommandAction("Apply the planned operations", applyCommand)] : [runCommandAction(result.perSpace !== void 0 && result.perSpace.length === 1 ? "Confirm the space is up to date" : "Confirm every space is up to date", "{bin} migration status")];
851
897
  }
852
- /**
853
- * Where migrations live for this project. Resolved against the invocation
854
- * directory, which is also the config file's directory for every default
855
- * invocation.
856
- */
857
- function migrationsDirFor(config, cwd) {
858
- return resolve(cwd, config.migrations?.dir ?? "migrations");
859
- }
860
- /** The app subspace under {@link migrationsDirFor}. */
861
- function appMigrationsDirFor(config, cwd) {
862
- return spaceMigrationDirectory(migrationsDirFor(config, cwd), APP_SPACE_ID);
863
- }
864
- /**
865
- * The config file an operation should anchor its project paths on. The engine
866
- * loads the config and hands a handler the value but not the path, and
867
- * `--config` is an engine flag the handler never sees, so a handler names the
868
- * invocation directory's file. That equals the loaded file for every
869
- * invocation whose config sits in the invocation directory.
870
- */
871
- function projectConfigPathFor(cwd) {
872
- return resolve(cwd, "prisma.config.ts");
873
- }
874
- /**
875
- * Where refs live. The framework keeps them under the app subspace rather than
876
- * at the migrations root.
877
- */
878
- function appRefsDirFor(config, cwd) {
879
- return resolve(appMigrationsDirFor(config, cwd), "refs");
880
- }
881
- /**
882
- * The emitted contract. The config loader has already resolved
883
- * `contract.output` against the config file's directory, so this only has an
884
- * effect for a config handed in raw, as tests do.
885
- */
886
- function contractPathFor(config, cwd) {
887
- const output = config.contract?.output;
888
- return output === void 0 ? void 0 : resolve(cwd, output);
889
- }
890
- /**
891
- * The header's rendering of a path: relative to where the user invoked the
892
- * CLI, as the commander shell rendered it against the config file.
893
- */
894
- function displayPath(path, cwd) {
895
- return relative(cwd, path);
896
- }
897
898
  /** Reads the emitted contract as the raw document the control API validates. */
898
899
  async function readContractDocument(contractPath) {
899
900
  let content;
@@ -1036,6 +1037,25 @@ function createDbInitCommand(createClient) {
1036
1037
  });
1037
1038
  if (!prepared.ok) return notOk$1(prepared.failure);
1038
1039
  const { client, contractJson, contractPath, dbConnection, migrationsDir, refsDir } = prepared.value;
1040
+ const refName = computeRefAdvancementName({
1041
+ ...ifDefined("advanceRef", args.flags.advanceRef),
1042
+ ...ifDefined("db", args.flags.db)
1043
+ });
1044
+ let advancement = null;
1045
+ if (refName !== null) {
1046
+ const preflight = await preflightRefAdvancement({
1047
+ name: refName,
1048
+ contractJson,
1049
+ contractJsonPath: contractPath,
1050
+ configPath: projectConfigPathFor(ctx.cwd),
1051
+ client
1052
+ });
1053
+ if (!preflight.ok) return notOk$1(normalizeError(preflight.failure));
1054
+ advancement = {
1055
+ name: refName,
1056
+ contractIR: preflight.value
1057
+ };
1058
+ }
1039
1059
  let document;
1040
1060
  try {
1041
1061
  await client.connect(dbConnection);
@@ -1047,22 +1067,20 @@ function createDbInitCommand(createClient) {
1047
1067
  });
1048
1068
  if (!result.ok) return notOk$1(normalizeError(mapDbInitFailure(result.failure)));
1049
1069
  const advancementHash = result.value.mode === "apply" ? result.value.marker?.storageHash ?? result.value.destination.storageHash : result.value.destination.storageHash;
1050
- const advancement = await resolveRefAdvancementFields({
1051
- ...ifDefined("advanceRef", args.flags.advanceRef),
1052
- ...ifDefined("db", args.flags.db),
1070
+ const advanced = advancement === null ? ok$1(NO_REF_ADVANCEMENT) : await buildRefAdvancementFields({
1071
+ name: advancement.name,
1053
1072
  refsDir,
1054
1073
  migrationsDir,
1055
- contractJson,
1056
- contractJsonPath: contractPath,
1074
+ contractIR: advancement.contractIR,
1057
1075
  mode: result.value.mode,
1058
1076
  hash: advancementHash
1059
1077
  });
1060
- if (!advancement.ok) return notOk$1(normalizeError(advancement.failure));
1078
+ if (!advanced.ok) return notOk$1(normalizeError(advanced.failure));
1061
1079
  document = initDocument({
1062
1080
  value: result.value,
1063
1081
  targetId: ctx.config.target.targetId,
1064
- advancedRef: advancement.value.advancedRef,
1065
- plannedAdvanceRef: advancement.value.plannedAdvanceRef,
1082
+ advancedRef: advanced.value.advancedRef,
1083
+ plannedAdvanceRef: advanced.value.plannedAdvanceRef,
1066
1084
  startedAt
1067
1085
  });
1068
1086
  } catch (error) {
@@ -1662,13 +1680,22 @@ function createDbSignCommand(createClient = createControlClient) {
1662
1680
  json: emitted.value.json,
1663
1681
  jsonPath: emitted.value.path
1664
1682
  };
1683
+ const client = createClient({
1684
+ family: ctx.config.family,
1685
+ target: ctx.config.target,
1686
+ adapter: ctx.config.adapter,
1687
+ ...ifDefined("driver", ctx.config.driver),
1688
+ extensions: ctx.config.extensions ?? []
1689
+ });
1665
1690
  const refName = args.flags.noAdvanceRef ? null : args.flags.advanceRef ?? DEFAULT_ADVANCE_REF;
1666
1691
  let advancement = null;
1667
1692
  if (refName !== null) {
1668
1693
  const preflight = await preflightRefAdvancement({
1669
1694
  name: refName,
1670
1695
  contractJson: signedSource.json,
1671
- contractJsonPath: signedSource.jsonPath
1696
+ contractJsonPath: signedSource.jsonPath,
1697
+ configPath: projectConfigPathFor(ctx.cwd),
1698
+ client
1672
1699
  });
1673
1700
  if (!preflight.ok) return notOk$1(normalizeError(preflight.failure));
1674
1701
  advancement = {
@@ -1687,13 +1714,6 @@ function createDbSignCommand(createClient = createControlClient) {
1687
1714
  contract: contractRef ?? emitted.value.displayPath,
1688
1715
  database: maskConnectionUrl(dbConnection)
1689
1716
  });
1690
- const client = createClient({
1691
- family: ctx.config.family,
1692
- target: ctx.config.target,
1693
- adapter: ctx.config.adapter,
1694
- ...ifDefined("driver", ctx.config.driver),
1695
- extensions: ctx.config.extensions ?? []
1696
- });
1697
1717
  const onProgress = controlProgressReporter(ctx.report);
1698
1718
  try {
1699
1719
  const verified = await client.schemaVerify({
@@ -1962,6 +1982,25 @@ function createDbUpdateCommand(createClient) {
1962
1982
  contractJson = resolved.value.contractJson;
1963
1983
  snapshotContractPath = resolved.value.contractJsonPath;
1964
1984
  }
1985
+ const refName = computeRefAdvancementName({
1986
+ ...ifDefined("advanceRef", args.flags.advanceRef),
1987
+ ...ifDefined("db", args.flags.db)
1988
+ });
1989
+ let advancement = null;
1990
+ if (refName !== null) {
1991
+ const preflight = await preflightRefAdvancement({
1992
+ name: refName,
1993
+ contractJson,
1994
+ contractJsonPath: snapshotContractPath,
1995
+ configPath: projectConfigPathFor(ctx.cwd),
1996
+ client
1997
+ });
1998
+ if (!preflight.ok) return notOk$1(normalizeError(preflight.failure));
1999
+ advancement = {
2000
+ name: refName,
2001
+ contractIR: preflight.value
2002
+ };
2003
+ }
1965
2004
  const mode = args.flags.dryRun ? "plan" : "apply";
1966
2005
  let document;
1967
2006
  try {
@@ -1999,22 +2038,20 @@ function createDbUpdateCommand(createClient) {
1999
2038
  return notOk$1(normalizeError(mapDbUpdateFailure(result.failure)));
2000
2039
  }
2001
2040
  const advancementHash = result.value.mode === "apply" ? result.value.marker?.storageHash ?? result.value.destination.storageHash : result.value.destination.storageHash;
2002
- const advancement = await resolveRefAdvancementFields({
2003
- ...ifDefined("advanceRef", args.flags.advanceRef),
2004
- ...ifDefined("db", args.flags.db),
2041
+ const advanced = advancement === null ? ok$1(NO_REF_ADVANCEMENT) : await buildRefAdvancementFields({
2042
+ name: advancement.name,
2005
2043
  refsDir,
2006
2044
  migrationsDir,
2007
- contractJson,
2008
- contractJsonPath: snapshotContractPath,
2045
+ contractIR: advancement.contractIR,
2009
2046
  mode: result.value.mode,
2010
2047
  hash: advancementHash
2011
2048
  });
2012
- if (!advancement.ok) return notOk$1(normalizeError(advancement.failure));
2049
+ if (!advanced.ok) return notOk$1(normalizeError(advanced.failure));
2013
2050
  document = updateDocument({
2014
2051
  value: result.value,
2015
2052
  targetId: ctx.config.target.targetId,
2016
- advancedRef: advancement.value.advancedRef,
2017
- plannedAdvanceRef: advancement.value.plannedAdvanceRef,
2053
+ advancedRef: advanced.value.advancedRef,
2054
+ plannedAdvanceRef: advanced.value.plannedAdvanceRef,
2018
2055
  startedAt
2019
2056
  });
2020
2057
  } catch (error) {
@@ -7597,19 +7634,34 @@ function createMigrateCommand(createClient) {
7597
7634
  }
7598
7635
  let applyContract = appContract;
7599
7636
  let snapshotContractJson = contractJson;
7600
- let snapshotContractDts;
7637
+ let snapshotContractPath = contractPath;
7601
7638
  if (args.flags.to !== void 0 && refEntry !== void 0) {
7602
7639
  if (aggregate.app.packages.find((p) => p.metadata.to === refEntry.hash) !== void 0) try {
7603
7640
  const at = await aggregate.app.contractAt(refEntry.hash, target.value.refName === void 0 ? void 0 : { refName: target.value.refName });
7604
7641
  applyContract = at.contract;
7605
7642
  snapshotContractJson = blindCast(at.contractJson);
7606
- snapshotContractDts = at.contractDts;
7643
+ snapshotContractPath = join(contractSnapshotDir(migrationsDir, refEntry.hash), "contract.json");
7607
7644
  } catch (error) {
7608
7645
  const mapped = mapContractAtError(error, { artifactRole: "to" });
7609
7646
  if (!mapped.ok) return notOk$1(normalizeError(mapped.failure));
7610
7647
  throw error;
7611
7648
  }
7612
7649
  }
7650
+ let advancement = null;
7651
+ if (args.flags.advanceRef !== void 0) {
7652
+ const preflight = await preflightRefAdvancement({
7653
+ name: args.flags.advanceRef,
7654
+ contractJson: snapshotContractJson,
7655
+ contractJsonPath: snapshotContractPath,
7656
+ configPath: projectConfigPathFor(ctx.cwd),
7657
+ client
7658
+ });
7659
+ if (!preflight.ok) return notOk$1(normalizeError(preflight.failure));
7660
+ advancement = {
7661
+ name: args.flags.advanceRef,
7662
+ contractIR: preflight.value
7663
+ };
7664
+ }
7613
7665
  const applied = await client.migrate({
7614
7666
  contract: applyContract,
7615
7667
  migrationsDir,
@@ -7621,17 +7673,13 @@ function createMigrateCommand(createClient) {
7621
7673
  if (!applied.ok) return notOk$1(normalizeError(mapMigrateFailure(applied.failure)));
7622
7674
  const { value } = applied;
7623
7675
  let advancedRef = null;
7624
- if (args.flags.advanceRef !== void 0) {
7625
- const contractIR = snapshotContractDts === void 0 ? await readContractIR(snapshotContractJson, contractPath) : {
7626
- contract: snapshotContractJson,
7627
- contractDts: snapshotContractDts
7628
- };
7676
+ if (advancement !== null) {
7629
7677
  const advanced = await advanceRefSafely({
7630
7678
  refsDir,
7631
7679
  migrationsDir,
7632
- name: args.flags.advanceRef,
7680
+ name: advancement.name,
7633
7681
  hash: value.markerHash,
7634
- contractIR
7682
+ contractIR: advancement.contractIR
7635
7683
  });
7636
7684
  if (!advanced.ok) return notOk$1(normalizeError(advanced.failure));
7637
7685
  advancedRef = {