@prisma/orm-toolchain 8.0.0-rc.14-dev.6 → 8.0.0-rc.14-dev.8
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/{aggregate-BsI5y36e.mjs → aggregate-CzHNiMIL.mjs} +9 -9
- package/dist/{aggregate-BsI5y36e.mjs.map → aggregate-CzHNiMIL.mjs.map} +1 -1
- package/dist/caught-errors-DulynoX6-BSeStARm.mjs +663 -0
- package/dist/caught-errors-DulynoX6-BSeStARm.mjs.map +1 -0
- package/dist/cli-telemetry.mjs +3 -3
- package/dist/cli.mjs +32 -93
- package/dist/cli.mjs.map +1 -1
- package/dist/cli__control-api.d.mts +12 -6
- package/dist/cli__control-api.d.mts.map +1 -1
- package/dist/cli__control-api.mjs +3 -2
- package/dist/cli__control-api__testing.d.mts +2 -2
- package/dist/cli__migration-cli.mjs +7 -5
- package/dist/cli__migration-cli.mjs.map +1 -1
- package/dist/config-loader.mjs +1 -1
- package/dist/{contract-snapshot-store-1S_6vaGt-FrXDiBEd.mjs → contract-snapshot-store-1S_6vaGt-CQPNFWho.mjs} +4 -4
- package/dist/{contract-snapshot-store-1S_6vaGt-FrXDiBEd.mjs.map → contract-snapshot-store-1S_6vaGt-CQPNFWho.mjs.map} +1 -1
- package/dist/{db-verify-DoVihHM8-QNzdRseL.d.mts → db-verify-DoVihHM8-BrpF-Rnr.d.mts} +5 -5
- package/dist/{db-verify-DoVihHM8-QNzdRseL.d.mts.map → db-verify-DoVihHM8-BrpF-Rnr.d.mts.map} +1 -1
- package/dist/{domain-type-generation-BVFTIUm6-BRbRrGYB.mjs → domain-type-generation-DBIqOo-2-B_8sNhjJ.mjs} +17 -19
- package/dist/domain-type-generation-DBIqOo-2-B_8sNhjJ.mjs.map +1 -0
- package/dist/{domain-type-generation-X6-AaL1U-DHEoRf_y.d.mts → domain-type-generation-W1f7UBwI-CwzLK5TL.d.mts} +9 -11
- package/dist/domain-type-generation-W1f7UBwI-CwzLK5TL.d.mts.map +1 -0
- package/dist/emitter.d.mts +2 -2
- package/dist/emitter.mjs +2 -2
- package/dist/emitter__domain-type-generation.d.mts +2 -2
- package/dist/emitter__domain-type-generation.mjs +1 -1
- package/dist/{errors-D59OCpoI.d.mts → errors-KWM8yBAL.d.mts} +2 -2
- package/dist/{errors-D59OCpoI.d.mts.map → errors-KWM8yBAL.d.mts.map} +1 -1
- package/dist/{exports-p_LVQQlE.mjs → exports-CkefqB5C.mjs} +6 -6
- package/dist/{exports-p_LVQQlE.mjs.map → exports-CkefqB5C.mjs.map} +1 -1
- package/dist/{exports-CbtEF7X6.mjs → exports-Czk5PRpV.mjs} +5 -5
- package/dist/{exports-CbtEF7X6.mjs.map → exports-Czk5PRpV.mjs.map} +1 -1
- package/dist/{exports-BcO9J5Ct-BMk2j8LA.mjs → exports-DXfgwE62-BmuNqWBQ.mjs} +6 -8
- package/dist/exports-DXfgwE62-BmuNqWBQ.mjs.map +1 -0
- package/dist/{hash-BAZVWU4a-BdynTmar.mjs → hash-BAZVWU4a-BQovI7hF.mjs} +3 -3
- package/dist/{hash-BAZVWU4a-BdynTmar.mjs.map → hash-BAZVWU4a-BQovI7hF.mjs.map} +1 -1
- package/dist/{index-DG1D9rrd.d.mts → index-C1kfLErt.d.mts} +4 -4
- package/dist/{index-DG1D9rrd.d.mts.map → index-C1kfLErt.d.mts.map} +1 -1
- package/dist/{io-xKnQrxIC-BZHUkAeY.mjs → io-xKnQrxIC-BPHEfarH.mjs} +4 -4
- package/dist/{io-xKnQrxIC-BZHUkAeY.mjs.map → io-xKnQrxIC-BPHEfarH.mjs.map} +1 -1
- package/dist/{migration-CTBcGs-o.mjs → migration-DaFjTC8t.mjs} +3 -3
- package/dist/{migration-CTBcGs-o.mjs.map → migration-DaFjTC8t.mjs.map} +1 -1
- package/dist/migration-tools.d.mts +2 -2
- package/dist/migration-tools.mjs +11 -11
- package/dist/migration-tools__aggregate.mjs +1 -1
- package/dist/migration-tools__contract-snapshot-store.mjs +1 -1
- package/dist/migration-tools__errors.d.mts +1 -1
- package/dist/migration-tools__hash.mjs +1 -1
- package/dist/migration-tools__io.mjs +1 -1
- package/dist/migration-tools__migration-graph.mjs +1 -1
- package/dist/migration-tools__migration-ts.mjs +1 -1
- package/dist/migration-tools__migration.mjs +1 -1
- package/dist/migration-tools__ref-resolution.mjs +1 -1
- package/dist/migration-tools__refs.mjs +1 -1
- package/dist/migration-tools__spaces.d.mts +1 -1
- package/dist/migration-tools__spaces.mjs +2 -2
- package/dist/{migration-ts-DdVm0rws.mjs → migration-ts-BQuIba9e.mjs} +3 -3
- package/dist/{migration-ts-DdVm0rws.mjs.map → migration-ts-BQuIba9e.mjs.map} +1 -1
- package/dist/{ref-EXO_pTtx-BcH9AmJ9.mjs → ref-BLBgE_oK-CrUDNhYI.mjs} +35 -647
- package/dist/ref-BLBgE_oK-CrUDNhYI.mjs.map +1 -0
- package/dist/{ref-resolution-CyyiVwzz.mjs → ref-resolution-CoHoeFT7.mjs} +2 -2
- package/dist/{ref-resolution-CyyiVwzz.mjs.map → ref-resolution-CoHoeFT7.mjs.map} +1 -1
- package/dist/{refs-qwvw4_dV-DNg_7WTD.mjs → refs-qwvw4_dV-X8sR92eT.mjs} +2 -2
- package/dist/{refs-qwvw4_dV-DNg_7WTD.mjs.map → refs-qwvw4_dV-X8sR92eT.mjs.map} +1 -1
- package/dist/{spaces-B20bgxF9.d.mts → spaces-BWULKO54.d.mts} +2 -2
- package/dist/{spaces-B20bgxF9.d.mts.map → spaces-BWULKO54.d.mts.map} +1 -1
- package/dist/{spaces-CcU9rbeZ.mjs → spaces-CzLQQYa9.mjs} +6 -6
- package/dist/{spaces-CcU9rbeZ.mjs.map → spaces-CzLQQYa9.mjs.map} +1 -1
- package/dist/{verify-contract-spaces-CYjc343k-DHy5xtKR.mjs → verify-contract-spaces-CYjc343k-FXABEJZE.mjs} +3 -3
- package/dist/{verify-contract-spaces-CYjc343k-DHy5xtKR.mjs.map → verify-contract-spaces-CYjc343k-FXABEJZE.mjs.map} +1 -1
- package/dist/vite-plugin-contract-emit.mjs +3 -3
- package/package.json +12 -12
- package/dist/domain-type-generation-BVFTIUm6-BRbRrGYB.mjs.map +0 -1
- package/dist/domain-type-generation-X6-AaL1U-DHEoRf_y.d.mts.map +0 -1
- package/dist/exports-BcO9J5Ct-BMk2j8LA.mjs.map +0 -1
- package/dist/ref-EXO_pTtx-BcH9AmJ9.mjs.map +0 -1
|
@@ -1,410 +1,39 @@
|
|
|
1
|
-
import { i as expandContractInputs } from "./exports-
|
|
2
|
-
import { r as getEmittedArtifactPaths, t as emit } from "./exports-BcO9J5Ct-BMk2j8LA.mjs";
|
|
1
|
+
import { i as expandContractInputs } from "./exports-CkefqB5C.mjs";
|
|
3
2
|
import { D as errorNoInvariantPath, M as errorUnknownInvariant, b as errorInvalidRefName, r as errorContractDeserializationFailed, t as MigrationToolsError } from "./errors-DD6iLGXk-6I9PqjpZ.mjs";
|
|
4
|
-
import { r as verifyMigrationHash, t as computeMigrationHash } from "./hash-BAZVWU4a-
|
|
5
|
-
import { a as snapshotsImportPathFrom, n as createSnapshotContentVerifier, o as writeContractSnapshot, r as readContractSnapshotJson, t as contractSnapshotDir } from "./contract-snapshot-store-1S_6vaGt-
|
|
3
|
+
import { r as verifyMigrationHash, t as computeMigrationHash } from "./hash-BAZVWU4a-BQovI7hF.mjs";
|
|
4
|
+
import { a as snapshotsImportPathFrom, n as createSnapshotContentVerifier, o as writeContractSnapshot, r as readContractSnapshotJson, t as contractSnapshotDir } from "./contract-snapshot-store-1S_6vaGt-CQPNFWho.mjs";
|
|
6
5
|
import { t as deriveProvidedInvariants } from "./invariants-C0lpc60l-CMUCvk4O.mjs";
|
|
7
|
-
import { i as materialiseExtensionMigrationPackageIfMissing, r as formatMigrationDirName, u as writeMigrationPackage } from "./io-xKnQrxIC-
|
|
6
|
+
import { i as materialiseExtensionMigrationPackageIfMissing, r as formatMigrationDirName, u as writeMigrationPackage } from "./io-xKnQrxIC-BPHEfarH.mjs";
|
|
8
7
|
import { t as EMPTY_CONTRACT_HASH } from "./constants-CM-w38DQ-Cz_EXbOc.mjs";
|
|
9
|
-
import { n as isGraphNode, t as assertHashIsGraphNode } from "./graph-membership-BQ43lP4A-i4Ov419-.mjs";
|
|
10
8
|
import { i as findPathWithDecision, r as findPath } from "./migration-graph-BoiiZAaU-DLht12k7.mjs";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
9
|
+
import { a as isValidSpaceId, c as spaceMigrationDirectory, l as spaceRefsDirectory, o as listContractSpaceDirectories, s as readContractSpaceHeadRef, t as APP_SPACE_ID$1 } from "./verify-contract-spaces-CYjc343k-FXABEJZE.mjs";
|
|
10
|
+
import { i as emitContractSpaceArtifacts, o as planAllSpaces } from "./spaces-CzLQQYa9.mjs";
|
|
11
|
+
import { A as errorRefSetBundleNotFound, B as getTargetMigrations, D as errorPathUnreachable, F as errorSnapshotMissing, G as requireLiveDatabase, I as errorSpaceNotFound, J as runCommandAction, K as resolveContractPath, L as errorTargetMigrationNotSupported, M as errorRefSetHashNotInGraph, O as errorPlanForgotTheFlag, P as errorRuntime, S as errorMarkerMismatch, T as errorMigrationPlanningFailed, U as readContractEnvelope, V as mapRefResolutionError, X as toStructuralEdge, _ as errorFileNotFound, a as closeQuietly, b as errorInvalidSpaceId, c as errorAmbiguousMigrationRef, f as errorContractConfigMissing, h as errorDestructiveChanges, i as chooseAction, j as errorRefSetEmptySentinel, k as errorPlanOriginUnknown, l as errorConfigValidation$1, m as errorDatabaseConnectionRequired, n as CliStructuredError$1, o as collectDeclaredInvariants, p as errorContractValidationFailed, q as resolveMigrationPaths, u as errorConsentPlanMismatch, v as errorFromCaught, z as errorUnexpected } from "./caught-errors-DulynoX6-BSeStARm.mjs";
|
|
12
|
+
import { r as getEmittedArtifactPaths, t as emit } from "./exports-DXfgwE62-BmuNqWBQ.mjs";
|
|
13
|
+
import { n as isGraphNode, t as assertHashIsGraphNode } from "./graph-membership-BQ43lP4A-i4Ov419-.mjs";
|
|
14
|
+
import { d as writeRef, i as readRefs, l as validateRefName, n as deleteRef, o as refsByContractHash, t as HEAD_REF_NAME, u as validateRefValue } from "./refs-qwvw4_dV-X8sR92eT.mjs";
|
|
15
|
+
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-CzHNiMIL.mjs";
|
|
15
16
|
import { c as internalImportRoot, o as importRootForDependencies, r as createImportSpecifierResolver, t as ImportRootError } from "./import-roots-BB3GzIi-.mjs";
|
|
16
|
-
import { n as parseContractRef, r as parseMigrationRef } from "./ref-resolution-
|
|
17
|
-
import { i as writeMigrationTs } from "./migration-ts-
|
|
17
|
+
import { n as parseContractRef, r as parseMigrationRef } from "./ref-resolution-CoHoeFT7.mjs";
|
|
18
|
+
import { i as writeMigrationTs } from "./migration-ts-BQuIba9e.mjs";
|
|
18
19
|
import { createRequire } from "node:module";
|
|
19
|
-
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
20
20
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
21
|
-
import {
|
|
22
|
-
import { keepInternalSpecifiers } from "@prisma/orm-framework/components/emission";
|
|
23
|
-
import { blindCast, castAs } from "@prisma/orm-framework/utils/casts";
|
|
24
|
-
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
25
|
-
import { CliStructuredError, CliStructuredError as CliStructuredError$1, errorConfigValidation as errorConfigValidation$1, errorContractConfigMissing, errorContractValidationFailed, errorDatabaseConnectionRequired, errorDriverRequired, errorFileNotFound, errorMigrationPlanningFailed, errorTargetMigrationNotSupported, errorUnexpected } from "@prisma/orm-framework/errors/control";
|
|
21
|
+
import { CliStructuredError } from "@prisma/orm-framework/errors/control";
|
|
26
22
|
import { APP_SPACE_ID, createControlStack, hasMigrations, hasOperationPreview, hasPslContractInfer, hasSchemaSubjectClassifier, hasSchemaView } from "@prisma/orm-framework/components/control";
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import "@prisma/orm-framework/errors/migration";
|
|
23
|
+
import { InternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
24
|
+
import { isStructuredErrorCode, structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
25
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
31
26
|
import { basename, dirname, isAbsolute, join, relative, resolve } from "pathe";
|
|
32
27
|
import { createHash } from "node:crypto";
|
|
33
28
|
import { canonicalizeJson } from "@prisma/orm-framework/components/utils";
|
|
34
|
-
import {
|
|
29
|
+
import { blindCast, castAs } from "@prisma/orm-framework/utils/casts";
|
|
30
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
31
|
+
import { keepInternalSpecifiers } from "@prisma/orm-framework/components/emission";
|
|
32
|
+
import { notOk, ok } from "@prisma/orm-framework/utils/result";
|
|
33
|
+
import { mergeCapabilityMatrices } from "@prisma/orm-framework/components/components";
|
|
35
34
|
import { abortable } from "@prisma/orm-framework/utils/abortable";
|
|
36
35
|
import { resolve as resolve$1 } from "node:path";
|
|
37
|
-
//#region ../../../1-framework/3-tooling/cli/dist/ref-
|
|
38
|
-
/**
|
|
39
|
-
* The typed remediation the CLI attaches to its own errors and findings.
|
|
40
|
-
* Constructors live here rather than in any library the CLI calls: naming a
|
|
41
|
-
* runnable invocation is something only the CLI can do.
|
|
42
|
-
*/
|
|
43
|
-
function runCommandAction(label, command) {
|
|
44
|
-
return {
|
|
45
|
-
kind: "run-command",
|
|
46
|
-
label,
|
|
47
|
-
command
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
/** Advice the user acts on themselves — there is no command to run. */
|
|
51
|
-
function chooseAction(label) {
|
|
52
|
-
return {
|
|
53
|
-
kind: "user-choice",
|
|
54
|
-
label
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* A CLI-raised error that carries the typed remediation as well as the prose.
|
|
59
|
-
* Only the CLI knows which invocation fixes a failure, so only errors raised
|
|
60
|
-
* here spell one; the foundation classes every library also raises keep
|
|
61
|
-
* carrying `code`, `why` and `fix` alone.
|
|
62
|
-
*
|
|
63
|
-
* Both fields are required: the `fix` prose is what the commander shell still
|
|
64
|
-
* renders, and the handler boundary drops it in favour of `nextActions` when it
|
|
65
|
-
* settles the engine's envelope.
|
|
66
|
-
*/
|
|
67
|
-
var ActionableCliError = class extends CliStructuredError$1 {
|
|
68
|
-
nextActions;
|
|
69
|
-
constructor(code, summary, options) {
|
|
70
|
-
super(code, summary, options);
|
|
71
|
-
this.nextActions = options.nextActions;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* A command that accepts a contract reference both as a positional and as a
|
|
76
|
-
* flag was given both. Structured rather than a bare stderr line, so a script
|
|
77
|
-
* sees the same envelope every other invocation failure produces.
|
|
78
|
-
*/
|
|
79
|
-
function errorContractArgConflict(options) {
|
|
80
|
-
const fix = "Pass the contract reference once — either as the positional argument or as --contract.";
|
|
81
|
-
return new ActionableCliError("CLI.CONTRACT_ARG_CONFLICT", "Cannot specify both a positional contract argument and --contract", {
|
|
82
|
-
why: `The positional argument names "${options.positional}" and --contract names "${options.flag}"; there is no rule for which wins.`,
|
|
83
|
-
fix,
|
|
84
|
-
nextActions: [chooseAction(fix)],
|
|
85
|
-
meta: {
|
|
86
|
-
positional: options.positional,
|
|
87
|
-
flag: options.flag
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* A command was told both which ref to advance and not to advance any ref.
|
|
93
|
-
* Same envelope as the positional/flag contract conflict, so a script sees
|
|
94
|
-
* every invocation conflict in one shape.
|
|
95
|
-
*/
|
|
96
|
-
function errorAdvanceRefArgConflict(options) {
|
|
97
|
-
const fix = "Pass either --advance-ref <name> or --no-advance-ref, not both.";
|
|
98
|
-
return new ActionableCliError("CLI.ADVANCE_REF_ARG_CONFLICT", "Cannot specify both --advance-ref and --no-advance-ref", {
|
|
99
|
-
why: `--advance-ref names "${options.advanceRef}" while --no-advance-ref asks for no ref to be written; there is no rule for which wins.`,
|
|
100
|
-
fix,
|
|
101
|
-
nextActions: [chooseAction(fix)],
|
|
102
|
-
meta: { advanceRef: options.advanceRef }
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
function errorRefSetHashNotInGraph(resolvedHash, reachableHashes) {
|
|
106
|
-
const reachableList = reachableHashes.length > 0 ? reachableHashes.join(", ") : "(none — migration graph is empty)";
|
|
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
|
-
return new ActionableCliError("MIGRATION.HASH_NOT_IN_GRAPH", `Resolved contract hash is not in the migration graph: ${resolvedHash}`, {
|
|
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
|
-
fix,
|
|
112
|
-
nextActions,
|
|
113
|
-
meta: {
|
|
114
|
-
resolvedHash,
|
|
115
|
-
reachableHashes: [...reachableHashes]
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
function errorRefSetEmptySentinel(hash) {
|
|
120
|
-
return new ActionableCliError("MIGRATION.REF_SET_EMPTY_SENTINEL", `Cannot set ref to the empty-database sentinel: ${hash}`, {
|
|
121
|
-
why: "The empty-database sentinel is a planner internal; it is not a valid ref target.",
|
|
122
|
-
fix: "Set the ref to a contract hash from the migration graph, or use another ref name.",
|
|
123
|
-
nextActions: [chooseAction("Set the ref to a contract hash from the migration graph"), chooseAction("Or use another ref name")],
|
|
124
|
-
meta: { hash }
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* `--legend` was combined with a machine-readable or silent output flag.
|
|
129
|
-
* The legend is human-only decoration on stderr.
|
|
130
|
-
*/
|
|
131
|
-
function errorLegendHumanOnly(conflictingFlag) {
|
|
132
|
-
return new ActionableCliError("MIGRATION.LEGEND_HUMAN_ONLY", "`--legend` is only available for human-readable output", {
|
|
133
|
-
why: `\`--legend\` prints a glyph key to stderr and cannot be combined with ${conflictingFlag}.`,
|
|
134
|
-
fix: `Omit ${conflictingFlag} to print the legend alongside the tree, or omit --legend when using ${conflictingFlag}.`,
|
|
135
|
-
nextActions: [chooseAction(`Omit ${conflictingFlag} to print the legend alongside the tree`), chooseAction(`Or omit --legend when using ${conflictingFlag}`)],
|
|
136
|
-
meta: { conflictingFlag }
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* `--space <id>` was given a value that doesn't satisfy the contract-space
|
|
141
|
-
* naming rule (`[a-z][a-z0-9_-]{0,63}` per `isValidSpaceId`). Fires before
|
|
142
|
-
* any fs work — the input is syntactically rejected the same way an on-disk
|
|
143
|
-
* directory with that name would be skipped by the enumerator.
|
|
144
|
-
*/
|
|
145
|
-
function errorInvalidSpaceId(spaceId) {
|
|
146
|
-
return new ActionableCliError("MIGRATION.INVALID_SPACE_ID", `Invalid contract space id: ${spaceId}`, {
|
|
147
|
-
why: "Contract space ids must match [a-z][a-z0-9_-]{0,63} (lowercase, starts with a letter, max 64 characters — the rule applied to every on-disk space directory).",
|
|
148
|
-
fix: "Pass a space id that matches the directory naming rule, or omit --space to list every space.",
|
|
149
|
-
nextActions: [chooseAction("Pass a space id matching [a-z][a-z0-9_-]{0,63}"), runCommandAction("Or list every space", "{bin} migration list")],
|
|
150
|
-
meta: { spaceId }
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* `migration list --space <id>` was given a contract-space id that has no
|
|
155
|
-
* directory under `migrations/`. Distinct from "the space exists but is
|
|
156
|
-
* empty" — that path renders the empty-state line and exits 0 per the
|
|
157
|
-
* slice spec § Empty-state. This error fires only when `<projectMigrationsDir>/<spaceId>`
|
|
158
|
-
* does not exist on disk.
|
|
159
|
-
*
|
|
160
|
-
* `availableSpaces` lists the contract-space directory names actually
|
|
161
|
-
* present, sorted lex-asc, so the diagnostic can suggest a near match
|
|
162
|
-
* without making the user reach for `ls`.
|
|
163
|
-
*/
|
|
164
|
-
function errorSpaceNotFound(spaceId, availableSpaces) {
|
|
165
|
-
const availableList = availableSpaces.length > 0 ? availableSpaces.join(", ") : "(none — no contract spaces on disk yet)";
|
|
166
|
-
const fix = availableSpaces.length > 0 ? `Pick one of: ${availableList}. Run \`{bin} migration list\` (no --space) to see every space's migrations.` : "Author a migration with `{bin} migration new` to create the first contract-space directory.";
|
|
167
|
-
const nextActions = availableSpaces.length > 0 ? [chooseAction(`Pick one of: ${availableList}`), runCommandAction("See every space's migrations", "{bin} migration list")] : [runCommandAction("Author the first migration, which creates the contract-space directory", "{bin} migration new")];
|
|
168
|
-
return new ActionableCliError("MIGRATION.SPACE_NOT_FOUND", `Unknown contract space: ${spaceId}`, {
|
|
169
|
-
why: `No directory named "${spaceId}" exists under the migrations root.`,
|
|
170
|
-
fix,
|
|
171
|
-
nextActions,
|
|
172
|
-
meta: {
|
|
173
|
-
spaceId,
|
|
174
|
-
availableSpaces: [...availableSpaces]
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* A `migration show` target resolved to a directory or a graph node, but no
|
|
180
|
-
* on-disk package was loaded for it.
|
|
181
|
-
*/
|
|
182
|
-
function errorMigrationPackageNotFound(why) {
|
|
183
|
-
return new ActionableCliError("MIGRATION.PACKAGE_NOT_FOUND", "Migration package not found", {
|
|
184
|
-
why,
|
|
185
|
-
fix: "Pass a directory name, hash prefix, or path to an on-disk app-space migration package.",
|
|
186
|
-
nextActions: [chooseAction("Pass a directory name, hash prefix, or path to an on-disk app-space migration package"), runCommandAction("List what is on disk", "{bin} migration list")]
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
/** The app space has no migration packages at all, so no target can resolve. */
|
|
190
|
-
function errorNoMigrations(appMigrationsRelative) {
|
|
191
|
-
return new ActionableCliError("MIGRATION.NO_MIGRATIONS", "No migrations found", {
|
|
192
|
-
why: `No migration packages found in ${appMigrationsRelative}`,
|
|
193
|
-
fix: "Run `{bin} migration plan` to create a migration first.",
|
|
194
|
-
nextActions: [runCommandAction("Create the first migration", "{bin} migration plan")]
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
function errorRefSetBundleNotFound(hash) {
|
|
198
|
-
return new ActionableCliError("MIGRATION.REF_SET_BUNDLE_NOT_FOUND", `No migration bundle matches graph-node hash ${hash}`, {
|
|
199
|
-
why: `The hash is a graph node but no on-disk bundle has metadata.to = ${hash}.`,
|
|
200
|
-
fix: "Run `pnpm fixtures:check`, or re-emit the migration that produces this hash so its bundle is restored.",
|
|
201
|
-
nextActions: [runCommandAction("Restore the checked-in fixtures", "pnpm fixtures:check"), chooseAction("Or re-emit the migration that produces this hash")],
|
|
202
|
-
meta: { hash }
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
function errorPlanForgotTheFlag(resolvedHash, reachableRefs, options) {
|
|
206
|
-
const reachableList = reachableRefs.length > 0 ? reachableRefs.map((r) => `${r.name} (${r.hash})`).join(", ") : "(none)";
|
|
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>")];
|
|
209
|
-
return new ActionableCliError("MIGRATION.HASH_NOT_IN_GRAPH", `Resolved from-hash is not in the migration graph: ${resolvedHash}`, {
|
|
210
|
-
why: `The migration graph reaches ${reachableList}; resolved ${resolvedHash} isn't a graph node.`,
|
|
211
|
-
fix: refFix,
|
|
212
|
-
nextActions,
|
|
213
|
-
meta: {
|
|
214
|
-
resolvedHash,
|
|
215
|
-
reachableRefs: reachableRefs.map((r) => r.name)
|
|
216
|
-
},
|
|
217
|
-
...ifDefined("cause", options?.cause)
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* `viaRef: true` (the default) mirrors migration-tools' `errorRefNotResolvable`:
|
|
222
|
-
* a ref name with no pointer file, where the fallback hash isn't a graph
|
|
223
|
-
* node either — there's nothing to materialize a contract from.
|
|
224
|
-
* `viaRef: false` is a distinct, ref-independent case: an explicit `--from
|
|
225
|
-
* <hash>` that doesn't name a ref, on an empty migration graph, so there is
|
|
226
|
-
* no graph node and no ref to resolve a contract through.
|
|
227
|
-
*/
|
|
228
|
-
function errorSnapshotMissing(identifier, options) {
|
|
229
|
-
const viaRef = options?.viaRef !== false;
|
|
230
|
-
const fix = viaRef ? `Create the ref with "{bin} migration ref set ${identifier} <hash>" (or advance it via "{bin} db update --advance-ref ${identifier}"), or pass a hash that is a node in the migration graph.` : `No contract source exists for hash "${identifier}" on an empty migration graph. Use --from with a ref name (its contract resolves through the snapshot store), or run db update first.`;
|
|
231
|
-
const nextActions = viaRef ? [
|
|
232
|
-
runCommandAction(`Create the ref "${identifier}"`, `{bin} migration ref set ${identifier} <hash>`),
|
|
233
|
-
runCommandAction("Or advance it from the database", `{bin} db update --advance-ref ${identifier}`),
|
|
234
|
-
chooseAction("Or pass a hash that is a node in the migration graph")
|
|
235
|
-
] : [chooseAction("Pass --from a ref name, whose contract resolves through the snapshot store"), runCommandAction("Or populate the graph first", "{bin} db update")];
|
|
236
|
-
return new ActionableCliError("MIGRATION.SNAPSHOT_MISSING", viaRef ? `Ref "${identifier}" is not resolvable` : `No contract source for from-hash "${identifier}"`, {
|
|
237
|
-
why: viaRef ? `Ref "${identifier}" has no pointer file, and the hash being resolved is not a node in the migration graph either.` : `Hash "${identifier}" is not a node in the migration graph (the graph is empty), and it does not name a ref either.`,
|
|
238
|
-
fix,
|
|
239
|
-
nextActions,
|
|
240
|
-
meta: {
|
|
241
|
-
identifier,
|
|
242
|
-
viaRef
|
|
243
|
-
},
|
|
244
|
-
...ifDefined("cause", options?.cause)
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Default origin resolution for `migration plan` found nothing (no `--from`,
|
|
249
|
-
* no `db` ref) while migrations already exist on disk. Planning would silently
|
|
250
|
-
* produce an empty-origin migration that ignores the existing history — almost
|
|
251
|
-
* always a mistake — so the command refuses and names the three exits.
|
|
252
|
-
*/
|
|
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>";
|
|
256
|
-
return new ActionableCliError("MIGRATION.PLAN_ORIGIN_UNKNOWN", "Cannot determine the plan origin: migrations exist but no origin is named", {
|
|
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.",
|
|
258
|
-
fix: [
|
|
259
|
-
`Set the \`db\` ref to the contract your dev database is at (\`${refSetCommand}\`), or advance it via \`{bin} db update\`.`,
|
|
260
|
-
`Or pass the origin explicitly: \`{bin} migration plan ${fromSuggestion}\`.`,
|
|
261
|
-
"Or pass --from @empty to deliberately plan from an empty database."
|
|
262
|
-
].join("\n"),
|
|
263
|
-
nextActions: [
|
|
264
|
-
runCommandAction("Point the db ref at the origin contract", refSetCommand),
|
|
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}`)],
|
|
266
|
-
runCommandAction("Plan from an empty database deliberately", "{bin} migration plan --from @empty")
|
|
267
|
-
],
|
|
268
|
-
meta: { reachableRefs: reachableRefs.map((r) => r.name) }
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
function errorMarkerMismatch(markerHash, reachableHashes) {
|
|
272
|
-
return new ActionableCliError("MIGRATION.MARKER_MISMATCH", "Database marker is not reachable in the on-disk migration graph", {
|
|
273
|
-
why: `DB marker is ${markerHash}, but the on-disk migration graph reaches: ${reachableHashes.length > 0 ? reachableHashes.join(", ") : "(none — migration graph is empty)"}.`,
|
|
274
|
-
fix: [
|
|
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.",
|
|
276
|
-
`Run \`{bin} migration ref set db ${markerHash}\` if the on-disk graph is canonical and the local \`db\` ref drifted.`,
|
|
277
|
-
"Investigate whether the database was migrated by an out-of-band process."
|
|
278
|
-
].join("\n"),
|
|
279
|
-
nextActions: [
|
|
280
|
-
runCommandAction("Catch the on-disk graph up to the live marker", "{bin} migration plan --from <contract>"),
|
|
281
|
-
runCommandAction("Point the local db ref at the live marker", `{bin} migration ref set db ${markerHash}`),
|
|
282
|
-
chooseAction("Investigate whether the database was migrated by an out-of-band process")
|
|
283
|
-
],
|
|
284
|
-
meta: {
|
|
285
|
-
markerHash,
|
|
286
|
-
reachableHashes: [...reachableHashes]
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
const ROLLBACK_IS_DESTRUCTIVE = "A rollback (reverse) plan is expected to contain destructive (DROP) operations — review them before applying";
|
|
291
|
-
const NARROWER_CASES_NEED_A_HINT = "Narrower cases (rename inference, re-adding a required field without a safe default, or a type change that needs data) may additionally need a hint in the planned migration";
|
|
292
|
-
function errorPathUnreachable(failure) {
|
|
293
|
-
const meta = failure.meta ?? {};
|
|
294
|
-
const fromHashMeta = typeof meta["fromHash"] === "string" ? meta["fromHash"] : null;
|
|
295
|
-
const planFromHash = fromHashMeta === "<empty>" ? null : fromHashMeta;
|
|
296
|
-
const targetHash = typeof meta["targetHash"] === "string" ? meta["targetHash"] : typeof meta["target"] === "string" ? meta["target"] : null;
|
|
297
|
-
const deadEnds = meta["deadEnds"];
|
|
298
|
-
const deadEndsSuffix = Array.isArray(deadEnds) && deadEnds.length > 0 ? ` Dead-ends: ${deadEnds.map(String).join(", ")}.` : "";
|
|
299
|
-
const neverPlanned = meta["kind"] === "neverPlanned";
|
|
300
|
-
const planCommand = (() => {
|
|
301
|
-
if (neverPlanned) return "{bin} migration plan --name <slug>";
|
|
302
|
-
if (planFromHash !== null && targetHash !== null) return `{bin} migration plan --from ${planFromHash} --to ${targetHash} --name <slug>`;
|
|
303
|
-
if (targetHash !== null) return `{bin} migration plan --to ${targetHash} --name <slug>`;
|
|
304
|
-
if (planFromHash !== null) return `{bin} migration plan --from ${planFromHash} --name <slug>`;
|
|
305
|
-
return "{bin} migration plan";
|
|
306
|
-
})();
|
|
307
|
-
const applyCommand = targetHash !== null && !neverPlanned ? `{bin} db migrate --to ${targetHash}` : "{bin} db migrate";
|
|
308
|
-
return new ActionableCliError("MIGRATION.PATH_UNREACHABLE", failure.summary, {
|
|
309
|
-
why: failure.why ?? `Cannot reach target "${targetHash ?? "<unknown>"}" from current marker "${fromHashMeta ?? "<unknown>"}".${deadEndsSuffix}`,
|
|
310
|
-
fix: [
|
|
311
|
-
"Plan the missing edge, then apply it:",
|
|
312
|
-
` 1. ${planCommand}`,
|
|
313
|
-
` 2. ${applyCommand}`,
|
|
314
|
-
`${ROLLBACK_IS_DESTRUCTIVE}.`,
|
|
315
|
-
`${NARROWER_CASES_NEED_A_HINT}.`,
|
|
316
|
-
"Inspect the on-disk graph with `{bin} migration list`, or `{bin} migration show <bundle>` for any bundle in the path you expected."
|
|
317
|
-
].join("\n"),
|
|
318
|
-
nextActions: [
|
|
319
|
-
runCommandAction("Plan the missing edge", planCommand),
|
|
320
|
-
runCommandAction("Apply it", applyCommand),
|
|
321
|
-
chooseAction(ROLLBACK_IS_DESTRUCTIVE),
|
|
322
|
-
chooseAction(NARROWER_CASES_NEED_A_HINT),
|
|
323
|
-
runCommandAction("Inspect the on-disk graph", "{bin} migration list"),
|
|
324
|
-
runCommandAction("Inspect a bundle in the path you expected", "{bin} migration show <bundle>")
|
|
325
|
-
],
|
|
326
|
-
meta: { ...meta }
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Shared "needs a live database" precondition for read verbs that consult the
|
|
331
|
-
* marker/ledger (`migration log`, `migration status`). A command needs both a
|
|
332
|
-
* connection string and a control-plane driver; either missing yields the same
|
|
333
|
-
* `CONFIG.DB_CONNECTION_REQUIRED` envelope with `meta.missingFlags` (canonical long-form flags
|
|
334
|
-
* per CLI Style Guide §Errors) so callers can react programmatically. Returns
|
|
335
|
-
* `null` when both are present.
|
|
336
|
-
*/
|
|
337
|
-
function requireLiveDatabase(args) {
|
|
338
|
-
if (args.dbConnection && args.hasDriver) return null;
|
|
339
|
-
const missingFlags = args.dbConnection ? [] : ["--db"];
|
|
340
|
-
return errorDatabaseConnectionRequired({
|
|
341
|
-
why: args.why,
|
|
342
|
-
missingFlags,
|
|
343
|
-
...ifDefined("commandName", args.commandName),
|
|
344
|
-
...ifDefined("retryCommand", args.retryCommand)
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Maps a `RefResolutionError` from the contract/migration reference
|
|
349
|
-
* resolver into a CLI structured error envelope.
|
|
350
|
-
*/
|
|
351
|
-
/**
|
|
352
|
-
* A migration ref (dirName or hash-prefix) resolves in more than one contract
|
|
353
|
-
* space. The user must qualify with `--space <id>` to disambiguate.
|
|
354
|
-
*/
|
|
355
|
-
function errorAmbiguousMigrationRef(ref, spaceIds) {
|
|
356
|
-
const spaceList = spaceIds.join(", ");
|
|
357
|
-
return new ActionableCliError("MIGRATION.AMBIGUOUS_MIGRATION_REF", `Ambiguous migration reference: "${ref}" resolves in multiple spaces — qualify with --space <id>`, {
|
|
358
|
-
why: `"${ref}" matches migrations in spaces: ${spaceList}.`,
|
|
359
|
-
fix: `Qualify with --space <id> to select one space. Available matching spaces: ${spaceList}.`,
|
|
360
|
-
nextActions: [chooseAction(`Qualify with --space <id>, one of: ${spaceList}`)],
|
|
361
|
-
meta: {
|
|
362
|
-
ref,
|
|
363
|
-
spaceIds: [...spaceIds]
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
function mapRefResolutionError(error) {
|
|
368
|
-
switch (error.kind) {
|
|
369
|
-
case "not-found": {
|
|
370
|
-
const fix = error.grammar === "contract" ? "Provide a valid contract hash, ref name, or migration directory name." : "Provide a valid migration directory name or migration hash.";
|
|
371
|
-
return new ActionableCliError("MIGRATION.REF_NOT_FOUND", `Not a known ${error.grammar} reference: "${error.input}"`, {
|
|
372
|
-
why: `No ${error.grammar} matching "${error.input}" exists in the migration graph or refs index.`,
|
|
373
|
-
fix,
|
|
374
|
-
nextActions: [chooseAction(fix)],
|
|
375
|
-
meta: {
|
|
376
|
-
input: error.input,
|
|
377
|
-
grammar: error.grammar
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
case "ambiguous": return new ActionableCliError("MIGRATION.REF_AMBIGUOUS", `Ambiguous ${error.grammar} reference: "${error.input}"`, {
|
|
382
|
-
why: `"${error.input}" matches multiple ${error.grammar}s: ${error.candidates.join(", ")}`,
|
|
383
|
-
fix: "Provide a longer prefix or use the full hash to disambiguate.",
|
|
384
|
-
nextActions: [chooseAction("Provide a longer prefix or use the full hash to disambiguate")],
|
|
385
|
-
meta: {
|
|
386
|
-
input: error.input,
|
|
387
|
-
candidates: error.candidates,
|
|
388
|
-
grammar: error.grammar
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
case "wrong-grammar": return new ActionableCliError("MIGRATION.REF_WRONG_GRAMMAR", error.message, {
|
|
392
|
-
why: error.message,
|
|
393
|
-
fix: error.fix,
|
|
394
|
-
nextActions: [chooseAction(error.fix)],
|
|
395
|
-
meta: {
|
|
396
|
-
input: error.input,
|
|
397
|
-
expectedGrammar: error.expectedGrammar
|
|
398
|
-
}
|
|
399
|
-
});
|
|
400
|
-
case "invalid-format": return new ActionableCliError("MIGRATION.REF_INVALID_FORMAT", `Invalid reference format: "${error.input}"`, {
|
|
401
|
-
why: error.reason,
|
|
402
|
-
fix: "Provide a valid contract hash, ref name, or migration directory name.",
|
|
403
|
-
nextActions: [chooseAction("Provide a valid contract hash, ref name, or migration directory name")],
|
|
404
|
-
meta: { input: error.input }
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
}
|
|
36
|
+
//#region ../../../1-framework/3-tooling/cli/dist/ref-BLBgE_oK.mjs
|
|
408
37
|
/**
|
|
409
38
|
* Asserts that all framework components are compatible with the expected family and target.
|
|
410
39
|
*
|
|
@@ -525,208 +154,6 @@ function enrichContract(ir, components) {
|
|
|
525
154
|
extensions: sortDeepTyped(extensions)
|
|
526
155
|
};
|
|
527
156
|
}
|
|
528
|
-
const MASK = "****";
|
|
529
|
-
const URL_SCHEME = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//;
|
|
530
|
-
const LEADING_URL_USERINFO = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/([^/?#\s]+)@/;
|
|
531
|
-
const URL_USERINFO = /([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)([^/?#\s]+)@/g;
|
|
532
|
-
const PASSWORD_QUERY_PARAMETER = /([?&][^=&#\s]*password[^=&#\s]*=)([^&#\s]*)/gi;
|
|
533
|
-
function hasUrlScheme(text) {
|
|
534
|
-
return URL_SCHEME.test(text);
|
|
535
|
-
}
|
|
536
|
-
/**
|
|
537
|
-
* Reads the userinfo of a URL without parsing its hosts, so it works for URLs `new URL` rejects,
|
|
538
|
-
* such as a seed list of several `host:port` pairs. The userinfo ends at the last `@` before the
|
|
539
|
-
* first `/`, `?` or `#`.
|
|
540
|
-
*/
|
|
541
|
-
function urlUserinfo(url) {
|
|
542
|
-
return splitUserinfo(url.match(LEADING_URL_USERINFO)?.[1] ?? "");
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Reads the values of the query parameters whose key contains `password`, the same ones
|
|
546
|
-
* `redactUrlCredentials` masks, without parsing hosts.
|
|
547
|
-
*/
|
|
548
|
-
function passwordQueryValues(url) {
|
|
549
|
-
return [...url.matchAll(PASSWORD_QUERY_PARAMETER)].map((match) => match[2] ?? "");
|
|
550
|
-
}
|
|
551
|
-
/**
|
|
552
|
-
* Masks the userinfo and any password query parameter of every URL in `text`, without parsing
|
|
553
|
-
* hosts. The masked form matches what `new URL` gives when its username and password are set to
|
|
554
|
-
* `****`.
|
|
555
|
-
*/
|
|
556
|
-
function redactUrlCredentials(text) {
|
|
557
|
-
return text.replace(URL_USERINFO, (_match, scheme, userinfo) => `${scheme}${maskUserinfo(splitUserinfo(userinfo))}@`).replace(PASSWORD_QUERY_PARAMETER, `$1${MASK}`);
|
|
558
|
-
}
|
|
559
|
-
function splitUserinfo(userinfo) {
|
|
560
|
-
const colon = userinfo.indexOf(":");
|
|
561
|
-
if (colon === -1) return {
|
|
562
|
-
username: userinfo,
|
|
563
|
-
password: ""
|
|
564
|
-
};
|
|
565
|
-
return {
|
|
566
|
-
username: userinfo.slice(0, colon),
|
|
567
|
-
password: userinfo.slice(colon + 1)
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
function maskUserinfo({ username, password }) {
|
|
571
|
-
return `${username ? MASK : ""}${password ? `:${MASK}` : ""}`;
|
|
572
|
-
}
|
|
573
|
-
const PASSWORD_QUERY_KEY = /password/i;
|
|
574
|
-
/**
|
|
575
|
-
* Resolves the absolute path to contract.json from the config.
|
|
576
|
-
*/
|
|
577
|
-
function resolveContractPath(config) {
|
|
578
|
-
if (config.contract?.output === void 0) throw errorRuntime("CONFIG.VALIDATION_FAILED", "config.contract.output is required to resolve the contract path", {
|
|
579
|
-
why: "CLI commands read the emitted contract from config.contract.output; the config has no value to read.",
|
|
580
|
-
fix: "Ensure your prisma.config.ts goes through `defineConfig()`, which normalises a default output when the provider supplies an input path, or set `contract.output` explicitly."
|
|
581
|
-
});
|
|
582
|
-
return resolve(config.contract.output);
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* Resolves the migrations directory and config path from CLI options.
|
|
586
|
-
* Shared by migrate, migration-plan, and migration-status.
|
|
587
|
-
*
|
|
588
|
-
* - `migrationsDir` is the project's top-level `migrations/` directory
|
|
589
|
-
* (the root that the aggregate loader walks for every contract space).
|
|
590
|
-
* - `appMigrationsDir` is the app subspace directory under it
|
|
591
|
-
* (`<migrationsDir>/<APP_SPACE_ID>/`). Every per-app reader / writer
|
|
592
|
-
* (`migration new`, `migration plan`, `migrate`,
|
|
593
|
-
* `migration status`, `migration show`, `migration ref`) operates on
|
|
594
|
-
* this directory. Extensions own their own `migrations/<spaceId>/`.
|
|
595
|
-
* - `refsDir` is the app's refs directory (`<appMigrationsDir>/refs/`).
|
|
596
|
-
* The framework does not maintain refs at the migrations root.
|
|
597
|
-
*
|
|
598
|
-
* `cwd` is the directory the command was invoked from; every relative path in
|
|
599
|
-
* the result is computed against it.
|
|
600
|
-
*/
|
|
601
|
-
function resolveMigrationPaths(config, cwd) {
|
|
602
|
-
const configPath = "prisma.config.ts";
|
|
603
|
-
const migrationsDir = resolve(config.baseDir ?? cwd, config.migrations?.dir ?? "migrations");
|
|
604
|
-
const migrationsRelative = relative(cwd, migrationsDir);
|
|
605
|
-
const appMigrationsDir = spaceMigrationDirectory(migrationsDir, APP_SPACE_ID$1);
|
|
606
|
-
return {
|
|
607
|
-
configPath,
|
|
608
|
-
migrationsDir,
|
|
609
|
-
migrationsRelative,
|
|
610
|
-
appMigrationsDir,
|
|
611
|
-
appMigrationsRelative: relative(cwd, appMigrationsDir),
|
|
612
|
-
refsDir: resolve(appMigrationsDir, "refs")
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
function collectDeclaredInvariants(graph) {
|
|
616
|
-
const declared = /* @__PURE__ */ new Set();
|
|
617
|
-
for (const edges of graph.forwardChain.values()) for (const edge of edges) for (const inv of edge.invariants) declared.add(inv);
|
|
618
|
-
return declared;
|
|
619
|
-
}
|
|
620
|
-
/**
|
|
621
|
-
* Maps a `MigrationEdge` to the structural-edge shape used in the
|
|
622
|
-
* `MIGRATION.NO_INVARIANT_PATH` error envelope. Shared between
|
|
623
|
-
* `migrate` and `migration status` so both commands surface
|
|
624
|
-
* the same JSON wire shape when an invariant-aware route is unsatisfiable.
|
|
625
|
-
*/
|
|
626
|
-
function toStructuralEdge(edge) {
|
|
627
|
-
return {
|
|
628
|
-
dirName: edge.dirName,
|
|
629
|
-
migrationHash: edge.migrationHash,
|
|
630
|
-
from: edge.from,
|
|
631
|
-
to: edge.to,
|
|
632
|
-
invariants: edge.invariants
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
function targetSupportsMigrations(target) {
|
|
636
|
-
return hasMigrations(target);
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Hangs up without letting the hang-up decide the command's result. A rejection out of a
|
|
640
|
-
* `finally` replaces the value the `try`/`catch` already returned, so an unguarded close turns a
|
|
641
|
-
* mapped connection error into an unmapped one — and that is the case it hits most, because a
|
|
642
|
-
* `connect()` that failed leaves nothing to close.
|
|
643
|
-
*/
|
|
644
|
-
async function closeQuietly(client) {
|
|
645
|
-
try {
|
|
646
|
-
await client.close();
|
|
647
|
-
} catch {}
|
|
648
|
-
}
|
|
649
|
-
function getTargetMigrations(target) {
|
|
650
|
-
return hasMigrations(target) ? target.migrations : void 0;
|
|
651
|
-
}
|
|
652
|
-
/**
|
|
653
|
-
* Reads and parses contract.json, validating the framework-level envelope
|
|
654
|
-
* fields (storageHash, schemaVersion, target, targetFamily).
|
|
655
|
-
*
|
|
656
|
-
* Family-specific validation (storage structure, codec mappings, etc.)
|
|
657
|
-
* happens downstream in the control client via the family instance.
|
|
658
|
-
*/
|
|
659
|
-
async function readContractEnvelope(config) {
|
|
660
|
-
const contractPath = resolveContractPath(config);
|
|
661
|
-
const content = await readFile(contractPath, "utf-8");
|
|
662
|
-
const json = JSON.parse(content);
|
|
663
|
-
const { schemaVersion, target, targetFamily, profileHash } = json;
|
|
664
|
-
const storageHash = json["storage"]?.["storageHash"];
|
|
665
|
-
if (typeof storageHash !== "string") throw new CliStructuredError$1("CONTRACT.VALIDATION_FAILED", `Contract at ${relative(process.cwd(), contractPath)} is missing a valid storage.storageHash. Run \`{bin} contract emit\` to regenerate.`, { where: { path: contractPath } });
|
|
666
|
-
if (typeof schemaVersion !== "string") throw new CliStructuredError$1("CONTRACT.VALIDATION_FAILED", `Contract at ${relative(process.cwd(), contractPath)} is missing schemaVersion.`, { where: { path: contractPath } });
|
|
667
|
-
if (typeof target !== "string") throw new CliStructuredError$1("CONTRACT.VALIDATION_FAILED", `Contract at ${relative(process.cwd(), contractPath)} is missing target.`, { where: { path: contractPath } });
|
|
668
|
-
if (typeof targetFamily !== "string") throw new CliStructuredError$1("CONTRACT.VALIDATION_FAILED", `Contract at ${relative(process.cwd(), contractPath)} is missing targetFamily.`, { where: { path: contractPath } });
|
|
669
|
-
return {
|
|
670
|
-
...json,
|
|
671
|
-
storageHash,
|
|
672
|
-
schemaVersion,
|
|
673
|
-
target,
|
|
674
|
-
targetFamily,
|
|
675
|
-
...typeof profileHash === "string" ? { profileHash } : {}
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* Masks credentials in a database connection URL.
|
|
680
|
-
* Handles standard URLs (username + password + query params), URLs `new URL` rejects (such as
|
|
681
|
-
* multi-host URLs), and libpq-style key=value strings.
|
|
682
|
-
*/
|
|
683
|
-
function maskConnectionUrl(url) {
|
|
684
|
-
try {
|
|
685
|
-
const parsed = new URL(url);
|
|
686
|
-
if (parsed.username) parsed.username = "****";
|
|
687
|
-
if (parsed.password) parsed.password = "****";
|
|
688
|
-
for (const key of [...parsed.searchParams.keys()]) if (PASSWORD_QUERY_KEY.test(key)) parsed.searchParams.set(key, "****");
|
|
689
|
-
return parsed.toString();
|
|
690
|
-
} catch {
|
|
691
|
-
return hasUrlScheme(url) ? redactUrlCredentials(url) : maskKeyValueCredentials(url);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
/**
|
|
695
|
-
* Strips raw connection URL fragments from an error message to prevent credential leakage.
|
|
696
|
-
* Call this before surfacing driver errors to the user.
|
|
697
|
-
*/
|
|
698
|
-
function sanitizeErrorMessage(message, connectionUrl) {
|
|
699
|
-
if (!connectionUrl) return message;
|
|
700
|
-
const secrets = connectionUrlSecrets(connectionUrl);
|
|
701
|
-
if (secrets === void 0) return maskKeyValueCredentials(message);
|
|
702
|
-
let sanitized = message.replaceAll(connectionUrl, maskConnectionUrl(connectionUrl));
|
|
703
|
-
for (const secret of secrets.filter(Boolean).sort(longestFirst)) sanitized = sanitized.replaceAll(secret, "****");
|
|
704
|
-
return sanitized;
|
|
705
|
-
}
|
|
706
|
-
function connectionUrlSecrets(connectionUrl) {
|
|
707
|
-
try {
|
|
708
|
-
const { username, password, searchParams } = new URL(connectionUrl);
|
|
709
|
-
return [
|
|
710
|
-
username,
|
|
711
|
-
password,
|
|
712
|
-
...[...searchParams].filter(([key]) => PASSWORD_QUERY_KEY.test(key)).map(([, value]) => value)
|
|
713
|
-
];
|
|
714
|
-
} catch {
|
|
715
|
-
if (!hasUrlScheme(connectionUrl)) return;
|
|
716
|
-
const { username, password } = urlUserinfo(connectionUrl);
|
|
717
|
-
return [
|
|
718
|
-
username,
|
|
719
|
-
password,
|
|
720
|
-
...passwordQueryValues(connectionUrl)
|
|
721
|
-
];
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
function longestFirst(a, b) {
|
|
725
|
-
return b.length - a.length;
|
|
726
|
-
}
|
|
727
|
-
function maskKeyValueCredentials(text) {
|
|
728
|
-
return text.replace(/password\s*=\s*\S+/gi, "password=****").replace(/user\s*=\s*\S+/gi, "user=****");
|
|
729
|
-
}
|
|
730
157
|
/**
|
|
731
158
|
* Project the CLI's `Config.extensions` array into the canonical
|
|
732
159
|
* {@link ExtensionPackInput} shape. The single `as ExtensionPackLike`
|
|
@@ -1014,8 +441,7 @@ async function buildReadAggregate(config, options) {
|
|
|
1014
441
|
contractHash
|
|
1015
442
|
});
|
|
1016
443
|
} catch (error) {
|
|
1017
|
-
|
|
1018
|
-
return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to read migrations directory: ${error instanceof Error ? error.message : String(error)}` }));
|
|
444
|
+
return notOk(errorFromCaught(error, (message) => `Failed to read migrations directory: ${message}`));
|
|
1019
445
|
}
|
|
1020
446
|
}
|
|
1021
447
|
/**
|
|
@@ -3407,10 +2833,7 @@ async function resolveContractRefToSnapshot(options) {
|
|
|
3407
2833
|
fix: "Run `{bin} contract emit` first to generate the contract",
|
|
3408
2834
|
cause: error
|
|
3409
2835
|
}));
|
|
3410
|
-
return notOk(
|
|
3411
|
-
why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`,
|
|
3412
|
-
cause: error
|
|
3413
|
-
}));
|
|
2836
|
+
return notOk(errorFromCaught(error, (message) => `Failed to read contract file: ${message}`));
|
|
3414
2837
|
}
|
|
3415
2838
|
let parsed;
|
|
3416
2839
|
try {
|
|
@@ -3437,25 +2860,6 @@ async function resolveContractRefToSnapshot(options) {
|
|
|
3437
2860
|
throw error;
|
|
3438
2861
|
}
|
|
3439
2862
|
}
|
|
3440
|
-
/**
|
|
3441
|
-
* Classifies errors caught around migration-tools calls so commands never import the MigrationToolsError class directly.
|
|
3442
|
-
*/
|
|
3443
|
-
/** CliStructuredError (including MigrationToolsError) → identity; anything else → null (caller rethrows/wraps). */
|
|
3444
|
-
function mapCaughtMigrationError(error) {
|
|
3445
|
-
if (CliStructuredError$1.is(error)) return error;
|
|
3446
|
-
return null;
|
|
3447
|
-
}
|
|
3448
|
-
/** A structured error about the contract, such as a default a planner refuses → the same error as a CliStructuredError; anything else → null. */
|
|
3449
|
-
function mapCaughtContractError(error) {
|
|
3450
|
-
if (!isStructuredError(error) || !error.code.startsWith("CONTRACT.")) return null;
|
|
3451
|
-
return new CliStructuredError$1(error.code, error.message, {
|
|
3452
|
-
...ifDefined("why", error.why),
|
|
3453
|
-
...ifDefined("fix", error.fix),
|
|
3454
|
-
...ifDefined("where", error.where),
|
|
3455
|
-
...ifDefined("meta", error.meta),
|
|
3456
|
-
cause: error
|
|
3457
|
-
});
|
|
3458
|
-
}
|
|
3459
2863
|
function mapContractAtError(error, options) {
|
|
3460
2864
|
if (MigrationToolsError.is(error)) switch (error.code) {
|
|
3461
2865
|
case "MIGRATION.REF_NOT_RESOLVABLE": return notOk(errorSnapshotMissing(typeof error.meta?.["refName"] === "string" ? error.meta["refName"] : typeof error.meta?.["identifier"] === "string" ? error.meta["identifier"] : "unknown", { cause: error }));
|
|
@@ -3650,8 +3054,7 @@ async function executeMigrateShowPlan(options) {
|
|
|
3650
3054
|
markerBySpace.set(space.spaceId, marker ?? null);
|
|
3651
3055
|
}
|
|
3652
3056
|
} catch (error) {
|
|
3653
|
-
|
|
3654
|
-
return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to read live DB marker: ${error instanceof Error ? error.message : String(error)}` }));
|
|
3057
|
+
return notOk(errorFromCaught(error, (message) => `Failed to read live DB marker: ${message}`, { connection: typeof dbConnection === "string" ? dbConnection : void 0 }));
|
|
3655
3058
|
} finally {
|
|
3656
3059
|
await closeQuietly(client);
|
|
3657
3060
|
}
|
|
@@ -4555,8 +3958,7 @@ async function executeMigrationNewCommand(options) {
|
|
|
4555
3958
|
summary: `Scaffolded migration at ${relative(cwd, packageDir)}`
|
|
4556
3959
|
});
|
|
4557
3960
|
} catch (error) {
|
|
4558
|
-
|
|
4559
|
-
return notOk(errorUnexpected(error instanceof Error ? error.message : String(error), { why: `Failed to scaffold migration: ${error instanceof Error ? error.message : String(error)}` }));
|
|
3961
|
+
return notOk(errorFromCaught(error, (message) => `Failed to scaffold migration: ${message}`));
|
|
4560
3962
|
}
|
|
4561
3963
|
}
|
|
4562
3964
|
/**
|
|
@@ -4757,9 +4159,7 @@ async function executeMigrationPlanCommand(options, startTime, callbacks) {
|
|
|
4757
4159
|
try {
|
|
4758
4160
|
return await executeMigrationPlanCommandInner(options, startTime, callbacks);
|
|
4759
4161
|
} catch (error) {
|
|
4760
|
-
|
|
4761
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
4762
|
-
return notOk(errorUnexpected(message, { why: `Unexpected error during migration plan: ${message}` }));
|
|
4162
|
+
return notOk(errorFromCaught(error, (message) => `Unexpected error during migration plan: ${message}`));
|
|
4763
4163
|
}
|
|
4764
4164
|
}
|
|
4765
4165
|
async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
@@ -4781,7 +4181,7 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
4781
4181
|
why: `Contract file not found at ${contractPathAbsolute}`,
|
|
4782
4182
|
fix: `Run \`{bin} contract emit\` to generate ${contractPath}, or update \`config.contract.output\` in ${configPath}`
|
|
4783
4183
|
}));
|
|
4784
|
-
return notOk(
|
|
4184
|
+
return notOk(errorFromCaught(error, (message) => `Failed to read contract file: ${message}`));
|
|
4785
4185
|
}
|
|
4786
4186
|
const stack = createControlStack(config);
|
|
4787
4187
|
const familyInstance = config.family.create(stack);
|
|
@@ -5048,12 +4448,7 @@ async function executeMigrationPlanCommandInner(options, startTime, callbacks) {
|
|
|
5048
4448
|
timings: { total: Date.now() - startTime }
|
|
5049
4449
|
});
|
|
5050
4450
|
} catch (error) {
|
|
5051
|
-
|
|
5052
|
-
if (MigrationToolsError.is(error)) return notOk(error);
|
|
5053
|
-
const contractError = mapCaughtContractError(error);
|
|
5054
|
-
if (contractError !== null) return notOk(contractError);
|
|
5055
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
5056
|
-
return notOk(errorUnexpected(message, { why: `Unexpected error during migration plan: ${message}` }));
|
|
4451
|
+
return notOk(errorFromCaught(error, (message) => `Unexpected error during migration plan: ${message}`));
|
|
5057
4452
|
}
|
|
5058
4453
|
}
|
|
5059
4454
|
/**
|
|
@@ -5117,10 +4512,6 @@ async function readMigrationRefs(refsDir) {
|
|
|
5117
4512
|
throw error;
|
|
5118
4513
|
}
|
|
5119
4514
|
}
|
|
5120
|
-
function mapError(error) {
|
|
5121
|
-
if (MigrationToolsError.is(error)) return error;
|
|
5122
|
-
return errorUnexpected(error instanceof Error ? error.message : String(error));
|
|
5123
|
-
}
|
|
5124
4515
|
function cliErrorInvalidRefName(name) {
|
|
5125
4516
|
return errorRuntime("MIGRATION.INVALID_REF_NAME", `Invalid ref name "${name}"`, {
|
|
5126
4517
|
why: `Ref name "${name}" does not match the required format`,
|
|
@@ -5171,8 +4562,7 @@ async function executeRefSetCommand(name, contractInput, options) {
|
|
|
5171
4562
|
invariants: []
|
|
5172
4563
|
});
|
|
5173
4564
|
} catch (error) {
|
|
5174
|
-
|
|
5175
|
-
return notOk(mapError(error));
|
|
4565
|
+
return notOk(errorFromCaught(error, (message) => message));
|
|
5176
4566
|
}
|
|
5177
4567
|
}
|
|
5178
4568
|
async function executeRefDeleteCommand(name, options) {
|
|
@@ -5185,8 +4575,7 @@ async function executeRefDeleteCommand(name, options) {
|
|
|
5185
4575
|
deleted: true
|
|
5186
4576
|
});
|
|
5187
4577
|
} catch (error) {
|
|
5188
|
-
|
|
5189
|
-
return notOk(mapError(error));
|
|
4578
|
+
return notOk(errorFromCaught(error, (message) => message));
|
|
5190
4579
|
}
|
|
5191
4580
|
}
|
|
5192
4581
|
async function executeRefListCommand(options) {
|
|
@@ -5197,11 +4586,10 @@ async function executeRefListCommand(options) {
|
|
|
5197
4586
|
refs: await readRefs(refsDir)
|
|
5198
4587
|
});
|
|
5199
4588
|
} catch (error) {
|
|
5200
|
-
|
|
5201
|
-
return notOk(mapError(error));
|
|
4589
|
+
return notOk(errorFromCaught(error, (message) => message));
|
|
5202
4590
|
}
|
|
5203
4591
|
}
|
|
5204
4592
|
//#endregion
|
|
5205
|
-
export {
|
|
4593
|
+
export { resolveFromForPlan as $, hasMigrationPath as A, migrationSpaceListEntriesFromAggregate as B, executeMigrationPlanCommand as C, executeRefSetCommand as D, executeRefListCommand as E, loadContractSourceWithStack as F, refuseDeclaredExtensionTargetMismatch as G, preflightRefAdvancement as H, loadContractSpaceAggregateForCli as I, refusePackageCorruptionOnAggregate as J, refuseMarkerOutsideGraph as K, looksLikePath as L, loadAggregateIntegrityViolations as M, loadContractRawSafely as N, findPackageByDirPath as O, loadContractSource as P, resolveContractRefToSnapshot as Q, mapContractAtError as R, executeMigrationNewCommand as S, executeRefDeleteCommand as T, readMigrationRefs as U, originHashForStatus as V, refuseContractSpaceIntegrity as W, resolveAppTargetPath as X, refuseUnknownInvariants as Y, resolveContractRef$1 as Z, executeContractEmit as _, appliedHashesFromLedger as a, snapshotVerifierFor as at, executeDbVerify as b, buildReadAggregate as c, toDeclaredExtensionsFromRaw as ct, computeRefAdvancementName as d, resolveMigrationRef as et, createControlClient as f, enumerateCheckSpaces as g, enrichContract as h, appContractStandInFromIdentity as i, runMigrationList as it, listRefsByContractHash as j, formatSourceDiagnostic as k, buildRefAdvancementFields as l, validateLoadedContract as lt, disposeEmitQueue as m, NO_REF_ADVANCEMENT as n, runContractSpaceSeedPhase as nt, buildContractSpaceAggregate as o, sourceWarningDiagnostic as ot, deriveStatusEdgeAnnotations as p, refuseMissingInvariantPath as q, advanceRefSafely as r, runMigrationCheck as rt, buildMigrationSpaceGraphEntries as s, statusForMigrationHash as st, DB_UPDATE_POLICY as t, resolveToForPlan as tt, checkSingleTarget as u, executeDbInit as v, executeRefAdvancement as w, executeMigrateShowPlan as x, executeDbUpdate as y, mapIntegrityViolations as z };
|
|
5206
4594
|
|
|
5207
|
-
//# sourceMappingURL=ref-
|
|
4595
|
+
//# sourceMappingURL=ref-BLBgE_oK-CrUDNhYI.mjs.map
|