@prisma/orm-toolchain 8.0.0-rc.14-dev.5 → 8.0.0-rc.14-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/{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
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
import { c as spaceMigrationDirectory, t as APP_SPACE_ID$1 } from "./verify-contract-spaces-CYjc343k-FXABEJZE.mjs";
|
|
2
|
+
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
3
|
+
import { CliStructuredError as CliStructuredError$1, errorConfigValidation as errorConfigValidation$1, errorContractConfigMissing, errorContractValidationFailed, errorDatabaseConnectionRequired, errorDriverRequired, errorFileNotFound, errorMigrationPlanningFailed, errorTargetMigrationNotSupported, errorUnexpected } from "@prisma/orm-framework/errors/control";
|
|
4
|
+
import { hasMigrations } from "@prisma/orm-framework/components/control";
|
|
5
|
+
import { isInternalError } from "@prisma/orm-framework/utils/internal-error";
|
|
6
|
+
import { isStructuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
7
|
+
import { ERROR_CODE_DESTRUCTIVE_CHANGES, errorConsentPlanMismatch, errorDestructiveChanges, errorHashMismatch, errorMarkerMissing, errorRunnerFailed, errorRuntime, errorTargetMismatch } from "@prisma/orm-framework/errors/execution";
|
|
8
|
+
import "@prisma/orm-framework/errors/migration";
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { relative, resolve } from "pathe";
|
|
11
|
+
//#region ../../../1-framework/3-tooling/cli/dist/caught-errors-DulynoX6.mjs
|
|
12
|
+
/**
|
|
13
|
+
* The typed remediation the CLI attaches to its own errors and findings.
|
|
14
|
+
* Constructors live here rather than in any library the CLI calls: naming a
|
|
15
|
+
* runnable invocation is something only the CLI can do.
|
|
16
|
+
*/
|
|
17
|
+
function runCommandAction(label, command) {
|
|
18
|
+
return {
|
|
19
|
+
kind: "run-command",
|
|
20
|
+
label,
|
|
21
|
+
command
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Advice the user acts on themselves — there is no command to run. */
|
|
25
|
+
function chooseAction(label) {
|
|
26
|
+
return {
|
|
27
|
+
kind: "user-choice",
|
|
28
|
+
label
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A CLI-raised error that carries the typed remediation as well as the prose.
|
|
33
|
+
* Only the CLI knows which invocation fixes a failure, so only errors raised
|
|
34
|
+
* here spell one; the foundation classes every library also raises keep
|
|
35
|
+
* carrying `code`, `why` and `fix` alone.
|
|
36
|
+
*
|
|
37
|
+
* Both fields are required: the `fix` prose is what the commander shell still
|
|
38
|
+
* renders, and the handler boundary drops it in favour of `nextActions` when it
|
|
39
|
+
* settles the engine's envelope.
|
|
40
|
+
*/
|
|
41
|
+
var ActionableCliError = class extends CliStructuredError$1 {
|
|
42
|
+
nextActions;
|
|
43
|
+
constructor(code, summary, options) {
|
|
44
|
+
super(code, summary, options);
|
|
45
|
+
this.nextActions = options.nextActions;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* A command that accepts a contract reference both as a positional and as a
|
|
50
|
+
* flag was given both. Structured rather than a bare stderr line, so a script
|
|
51
|
+
* sees the same envelope every other invocation failure produces.
|
|
52
|
+
*/
|
|
53
|
+
function errorContractArgConflict(options) {
|
|
54
|
+
const fix = "Pass the contract reference once — either as the positional argument or as --contract.";
|
|
55
|
+
return new ActionableCliError("CLI.CONTRACT_ARG_CONFLICT", "Cannot specify both a positional contract argument and --contract", {
|
|
56
|
+
why: `The positional argument names "${options.positional}" and --contract names "${options.flag}"; there is no rule for which wins.`,
|
|
57
|
+
fix,
|
|
58
|
+
nextActions: [chooseAction(fix)],
|
|
59
|
+
meta: {
|
|
60
|
+
positional: options.positional,
|
|
61
|
+
flag: options.flag
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A command was told both which ref to advance and not to advance any ref.
|
|
67
|
+
* Same envelope as the positional/flag contract conflict, so a script sees
|
|
68
|
+
* every invocation conflict in one shape.
|
|
69
|
+
*/
|
|
70
|
+
function errorAdvanceRefArgConflict(options) {
|
|
71
|
+
const fix = "Pass either --advance-ref <name> or --no-advance-ref, not both.";
|
|
72
|
+
return new ActionableCliError("CLI.ADVANCE_REF_ARG_CONFLICT", "Cannot specify both --advance-ref and --no-advance-ref", {
|
|
73
|
+
why: `--advance-ref names "${options.advanceRef}" while --no-advance-ref asks for no ref to be written; there is no rule for which wins.`,
|
|
74
|
+
fix,
|
|
75
|
+
nextActions: [chooseAction(fix)],
|
|
76
|
+
meta: { advanceRef: options.advanceRef }
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function errorRefSetHashNotInGraph(resolvedHash, reachableHashes) {
|
|
80
|
+
const reachableList = reachableHashes.length > 0 ? reachableHashes.join(", ") : "(none — migration graph is empty)";
|
|
81
|
+
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.";
|
|
82
|
+
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")];
|
|
83
|
+
return new ActionableCliError("MIGRATION.HASH_NOT_IN_GRAPH", `Resolved contract hash is not in the migration graph: ${resolvedHash}`, {
|
|
84
|
+
why: reachableHashes.length > 0 ? `The migration graph reaches ${reachableList}; resolved ${resolvedHash} isn't a graph node.` : "The migration graph is empty — no hashes reachable.",
|
|
85
|
+
fix,
|
|
86
|
+
nextActions,
|
|
87
|
+
meta: {
|
|
88
|
+
resolvedHash,
|
|
89
|
+
reachableHashes: [...reachableHashes]
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function errorRefSetEmptySentinel(hash) {
|
|
94
|
+
return new ActionableCliError("MIGRATION.REF_SET_EMPTY_SENTINEL", `Cannot set ref to the empty-database sentinel: ${hash}`, {
|
|
95
|
+
why: "The empty-database sentinel is a planner internal; it is not a valid ref target.",
|
|
96
|
+
fix: "Set the ref to a contract hash from the migration graph, or use another ref name.",
|
|
97
|
+
nextActions: [chooseAction("Set the ref to a contract hash from the migration graph"), chooseAction("Or use another ref name")],
|
|
98
|
+
meta: { hash }
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* `--legend` was combined with a machine-readable or silent output flag.
|
|
103
|
+
* The legend is human-only decoration on stderr.
|
|
104
|
+
*/
|
|
105
|
+
function errorLegendHumanOnly(conflictingFlag) {
|
|
106
|
+
return new ActionableCliError("MIGRATION.LEGEND_HUMAN_ONLY", "`--legend` is only available for human-readable output", {
|
|
107
|
+
why: `\`--legend\` prints a glyph key to stderr and cannot be combined with ${conflictingFlag}.`,
|
|
108
|
+
fix: `Omit ${conflictingFlag} to print the legend alongside the tree, or omit --legend when using ${conflictingFlag}.`,
|
|
109
|
+
nextActions: [chooseAction(`Omit ${conflictingFlag} to print the legend alongside the tree`), chooseAction(`Or omit --legend when using ${conflictingFlag}`)],
|
|
110
|
+
meta: { conflictingFlag }
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* `--space <id>` was given a value that doesn't satisfy the contract-space
|
|
115
|
+
* naming rule (`[a-z][a-z0-9_-]{0,63}` per `isValidSpaceId`). Fires before
|
|
116
|
+
* any fs work — the input is syntactically rejected the same way an on-disk
|
|
117
|
+
* directory with that name would be skipped by the enumerator.
|
|
118
|
+
*/
|
|
119
|
+
function errorInvalidSpaceId(spaceId) {
|
|
120
|
+
return new ActionableCliError("MIGRATION.INVALID_SPACE_ID", `Invalid contract space id: ${spaceId}`, {
|
|
121
|
+
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).",
|
|
122
|
+
fix: "Pass a space id that matches the directory naming rule, or omit --space to list every space.",
|
|
123
|
+
nextActions: [chooseAction("Pass a space id matching [a-z][a-z0-9_-]{0,63}"), runCommandAction("Or list every space", "{bin} migration list")],
|
|
124
|
+
meta: { spaceId }
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* `migration list --space <id>` was given a contract-space id that has no
|
|
129
|
+
* directory under `migrations/`. Distinct from "the space exists but is
|
|
130
|
+
* empty" — that path renders the empty-state line and exits 0 per the
|
|
131
|
+
* slice spec § Empty-state. This error fires only when `<projectMigrationsDir>/<spaceId>`
|
|
132
|
+
* does not exist on disk.
|
|
133
|
+
*
|
|
134
|
+
* `availableSpaces` lists the contract-space directory names actually
|
|
135
|
+
* present, sorted lex-asc, so the diagnostic can suggest a near match
|
|
136
|
+
* without making the user reach for `ls`.
|
|
137
|
+
*/
|
|
138
|
+
function errorSpaceNotFound(spaceId, availableSpaces) {
|
|
139
|
+
const availableList = availableSpaces.length > 0 ? availableSpaces.join(", ") : "(none — no contract spaces on disk yet)";
|
|
140
|
+
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.";
|
|
141
|
+
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")];
|
|
142
|
+
return new ActionableCliError("MIGRATION.SPACE_NOT_FOUND", `Unknown contract space: ${spaceId}`, {
|
|
143
|
+
why: `No directory named "${spaceId}" exists under the migrations root.`,
|
|
144
|
+
fix,
|
|
145
|
+
nextActions,
|
|
146
|
+
meta: {
|
|
147
|
+
spaceId,
|
|
148
|
+
availableSpaces: [...availableSpaces]
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* A `migration show` target resolved to a directory or a graph node, but no
|
|
154
|
+
* on-disk package was loaded for it.
|
|
155
|
+
*/
|
|
156
|
+
function errorMigrationPackageNotFound(why) {
|
|
157
|
+
return new ActionableCliError("MIGRATION.PACKAGE_NOT_FOUND", "Migration package not found", {
|
|
158
|
+
why,
|
|
159
|
+
fix: "Pass a directory name, hash prefix, or path to an on-disk app-space migration package.",
|
|
160
|
+
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")]
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/** The app space has no migration packages at all, so no target can resolve. */
|
|
164
|
+
function errorNoMigrations(appMigrationsRelative) {
|
|
165
|
+
return new ActionableCliError("MIGRATION.NO_MIGRATIONS", "No migrations found", {
|
|
166
|
+
why: `No migration packages found in ${appMigrationsRelative}`,
|
|
167
|
+
fix: "Run `{bin} migration plan` to create a migration first.",
|
|
168
|
+
nextActions: [runCommandAction("Create the first migration", "{bin} migration plan")]
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function errorRefSetBundleNotFound(hash) {
|
|
172
|
+
return new ActionableCliError("MIGRATION.REF_SET_BUNDLE_NOT_FOUND", `No migration bundle matches graph-node hash ${hash}`, {
|
|
173
|
+
why: `The hash is a graph node but no on-disk bundle has metadata.to = ${hash}.`,
|
|
174
|
+
fix: "Run `pnpm fixtures:check`, or re-emit the migration that produces this hash so its bundle is restored.",
|
|
175
|
+
nextActions: [runCommandAction("Restore the checked-in fixtures", "pnpm fixtures:check"), chooseAction("Or re-emit the migration that produces this hash")],
|
|
176
|
+
meta: { hash }
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function errorPlanForgotTheFlag(resolvedHash, reachableRefs, options) {
|
|
180
|
+
const reachableList = reachableRefs.length > 0 ? reachableRefs.map((r) => `${r.name} (${r.hash})`).join(", ") : "(none)";
|
|
181
|
+
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>`.";
|
|
182
|
+
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>")];
|
|
183
|
+
return new ActionableCliError("MIGRATION.HASH_NOT_IN_GRAPH", `Resolved from-hash is not in the migration graph: ${resolvedHash}`, {
|
|
184
|
+
why: `The migration graph reaches ${reachableList}; resolved ${resolvedHash} isn't a graph node.`,
|
|
185
|
+
fix: refFix,
|
|
186
|
+
nextActions,
|
|
187
|
+
meta: {
|
|
188
|
+
resolvedHash,
|
|
189
|
+
reachableRefs: reachableRefs.map((r) => r.name)
|
|
190
|
+
},
|
|
191
|
+
...ifDefined("cause", options?.cause)
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* `viaRef: true` (the default) mirrors migration-tools' `errorRefNotResolvable`:
|
|
196
|
+
* a ref name with no pointer file, where the fallback hash isn't a graph
|
|
197
|
+
* node either — there's nothing to materialize a contract from.
|
|
198
|
+
* `viaRef: false` is a distinct, ref-independent case: an explicit `--from
|
|
199
|
+
* <hash>` that doesn't name a ref, on an empty migration graph, so there is
|
|
200
|
+
* no graph node and no ref to resolve a contract through.
|
|
201
|
+
*/
|
|
202
|
+
function errorSnapshotMissing(identifier, options) {
|
|
203
|
+
const viaRef = options?.viaRef !== false;
|
|
204
|
+
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.`;
|
|
205
|
+
const nextActions = viaRef ? [
|
|
206
|
+
runCommandAction(`Create the ref "${identifier}"`, `{bin} migration ref set ${identifier} <hash>`),
|
|
207
|
+
runCommandAction("Or advance it from the database", `{bin} db update --advance-ref ${identifier}`),
|
|
208
|
+
chooseAction("Or pass a hash that is a node in the migration graph")
|
|
209
|
+
] : [chooseAction("Pass --from a ref name, whose contract resolves through the snapshot store"), runCommandAction("Or populate the graph first", "{bin} db update")];
|
|
210
|
+
return new ActionableCliError("MIGRATION.SNAPSHOT_MISSING", viaRef ? `Ref "${identifier}" is not resolvable` : `No contract source for from-hash "${identifier}"`, {
|
|
211
|
+
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.`,
|
|
212
|
+
fix,
|
|
213
|
+
nextActions,
|
|
214
|
+
meta: {
|
|
215
|
+
identifier,
|
|
216
|
+
viaRef
|
|
217
|
+
},
|
|
218
|
+
...ifDefined("cause", options?.cause)
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Default origin resolution for `migration plan` found nothing (no `--from`,
|
|
223
|
+
* no `db` ref) while migrations already exist on disk. Planning would silently
|
|
224
|
+
* produce an empty-origin migration that ignores the existing history — almost
|
|
225
|
+
* always a mistake — so the command refuses and names the three exits.
|
|
226
|
+
*/
|
|
227
|
+
function errorPlanOriginUnknown(reachableRefs) {
|
|
228
|
+
const fromSuggestion = reachableRefs.length > 0 ? reachableRefs.map((r) => `--from ${r.name}`).join(" or ") : "--from <contract>";
|
|
229
|
+
const refSetCommand = "{bin} migration ref set db <contract>";
|
|
230
|
+
return new ActionableCliError("MIGRATION.PLAN_ORIGIN_UNKNOWN", "Cannot determine the plan origin: migrations exist but no origin is named", {
|
|
231
|
+
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.",
|
|
232
|
+
fix: [
|
|
233
|
+
`Set the \`db\` ref to the contract your dev database is at (\`${refSetCommand}\`), or advance it via \`{bin} db update\`.`,
|
|
234
|
+
`Or pass the origin explicitly: \`{bin} migration plan ${fromSuggestion}\`.`,
|
|
235
|
+
"Or pass --from @empty to deliberately plan from an empty database."
|
|
236
|
+
].join("\n"),
|
|
237
|
+
nextActions: [
|
|
238
|
+
runCommandAction("Point the db ref at the origin contract", refSetCommand),
|
|
239
|
+
...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}`)],
|
|
240
|
+
runCommandAction("Plan from an empty database deliberately", "{bin} migration plan --from @empty")
|
|
241
|
+
],
|
|
242
|
+
meta: { reachableRefs: reachableRefs.map((r) => r.name) }
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function errorMarkerMismatch(markerHash, reachableHashes) {
|
|
246
|
+
return new ActionableCliError("MIGRATION.MARKER_MISMATCH", "Database marker is not reachable in the on-disk migration graph", {
|
|
247
|
+
why: `DB marker is ${markerHash}, but the on-disk migration graph reaches: ${reachableHashes.length > 0 ? reachableHashes.join(", ") : "(none — migration graph is empty)"}.`,
|
|
248
|
+
fix: [
|
|
249
|
+
"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.",
|
|
250
|
+
`Run \`{bin} migration ref set db ${markerHash}\` if the on-disk graph is canonical and the local \`db\` ref drifted.`,
|
|
251
|
+
"Investigate whether the database was migrated by an out-of-band process."
|
|
252
|
+
].join("\n"),
|
|
253
|
+
nextActions: [
|
|
254
|
+
runCommandAction("Catch the on-disk graph up to the live marker", "{bin} migration plan --from <contract>"),
|
|
255
|
+
runCommandAction("Point the local db ref at the live marker", `{bin} migration ref set db ${markerHash}`),
|
|
256
|
+
chooseAction("Investigate whether the database was migrated by an out-of-band process")
|
|
257
|
+
],
|
|
258
|
+
meta: {
|
|
259
|
+
markerHash,
|
|
260
|
+
reachableHashes: [...reachableHashes]
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
const ROLLBACK_IS_DESTRUCTIVE = "A rollback (reverse) plan is expected to contain destructive (DROP) operations — review them before applying";
|
|
265
|
+
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";
|
|
266
|
+
function errorPathUnreachable(failure) {
|
|
267
|
+
const meta = failure.meta ?? {};
|
|
268
|
+
const fromHashMeta = typeof meta["fromHash"] === "string" ? meta["fromHash"] : null;
|
|
269
|
+
const planFromHash = fromHashMeta === "<empty>" ? null : fromHashMeta;
|
|
270
|
+
const targetHash = typeof meta["targetHash"] === "string" ? meta["targetHash"] : typeof meta["target"] === "string" ? meta["target"] : null;
|
|
271
|
+
const deadEnds = meta["deadEnds"];
|
|
272
|
+
const deadEndsSuffix = Array.isArray(deadEnds) && deadEnds.length > 0 ? ` Dead-ends: ${deadEnds.map(String).join(", ")}.` : "";
|
|
273
|
+
const neverPlanned = meta["kind"] === "neverPlanned";
|
|
274
|
+
const planCommand = (() => {
|
|
275
|
+
if (neverPlanned) return "{bin} migration plan --name <slug>";
|
|
276
|
+
if (planFromHash !== null && targetHash !== null) return `{bin} migration plan --from ${planFromHash} --to ${targetHash} --name <slug>`;
|
|
277
|
+
if (targetHash !== null) return `{bin} migration plan --to ${targetHash} --name <slug>`;
|
|
278
|
+
if (planFromHash !== null) return `{bin} migration plan --from ${planFromHash} --name <slug>`;
|
|
279
|
+
return "{bin} migration plan";
|
|
280
|
+
})();
|
|
281
|
+
const applyCommand = targetHash !== null && !neverPlanned ? `{bin} db migrate --to ${targetHash}` : "{bin} db migrate";
|
|
282
|
+
return new ActionableCliError("MIGRATION.PATH_UNREACHABLE", failure.summary, {
|
|
283
|
+
why: failure.why ?? `Cannot reach target "${targetHash ?? "<unknown>"}" from current marker "${fromHashMeta ?? "<unknown>"}".${deadEndsSuffix}`,
|
|
284
|
+
fix: [
|
|
285
|
+
"Plan the missing edge, then apply it:",
|
|
286
|
+
` 1. ${planCommand}`,
|
|
287
|
+
` 2. ${applyCommand}`,
|
|
288
|
+
`${ROLLBACK_IS_DESTRUCTIVE}.`,
|
|
289
|
+
`${NARROWER_CASES_NEED_A_HINT}.`,
|
|
290
|
+
"Inspect the on-disk graph with `{bin} migration list`, or `{bin} migration show <bundle>` for any bundle in the path you expected."
|
|
291
|
+
].join("\n"),
|
|
292
|
+
nextActions: [
|
|
293
|
+
runCommandAction("Plan the missing edge", planCommand),
|
|
294
|
+
runCommandAction("Apply it", applyCommand),
|
|
295
|
+
chooseAction(ROLLBACK_IS_DESTRUCTIVE),
|
|
296
|
+
chooseAction(NARROWER_CASES_NEED_A_HINT),
|
|
297
|
+
runCommandAction("Inspect the on-disk graph", "{bin} migration list"),
|
|
298
|
+
runCommandAction("Inspect a bundle in the path you expected", "{bin} migration show <bundle>")
|
|
299
|
+
],
|
|
300
|
+
meta: { ...meta }
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Shared "needs a live database" precondition for read verbs that consult the
|
|
305
|
+
* marker/ledger (`migration log`, `migration status`). A command needs both a
|
|
306
|
+
* connection string and a control-plane driver; either missing yields the same
|
|
307
|
+
* `CONFIG.DB_CONNECTION_REQUIRED` envelope with `meta.missingFlags` (canonical long-form flags
|
|
308
|
+
* per CLI Style Guide §Errors) so callers can react programmatically. Returns
|
|
309
|
+
* `null` when both are present.
|
|
310
|
+
*/
|
|
311
|
+
function requireLiveDatabase(args) {
|
|
312
|
+
if (args.dbConnection && args.hasDriver) return null;
|
|
313
|
+
const missingFlags = args.dbConnection ? [] : ["--db"];
|
|
314
|
+
return errorDatabaseConnectionRequired({
|
|
315
|
+
why: args.why,
|
|
316
|
+
missingFlags,
|
|
317
|
+
...ifDefined("commandName", args.commandName),
|
|
318
|
+
...ifDefined("retryCommand", args.retryCommand)
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Maps a `RefResolutionError` from the contract/migration reference
|
|
323
|
+
* resolver into a CLI structured error envelope.
|
|
324
|
+
*/
|
|
325
|
+
/**
|
|
326
|
+
* A migration ref (dirName or hash-prefix) resolves in more than one contract
|
|
327
|
+
* space. The user must qualify with `--space <id>` to disambiguate.
|
|
328
|
+
*/
|
|
329
|
+
function errorAmbiguousMigrationRef(ref, spaceIds) {
|
|
330
|
+
const spaceList = spaceIds.join(", ");
|
|
331
|
+
return new ActionableCliError("MIGRATION.AMBIGUOUS_MIGRATION_REF", `Ambiguous migration reference: "${ref}" resolves in multiple spaces — qualify with --space <id>`, {
|
|
332
|
+
why: `"${ref}" matches migrations in spaces: ${spaceList}.`,
|
|
333
|
+
fix: `Qualify with --space <id> to select one space. Available matching spaces: ${spaceList}.`,
|
|
334
|
+
nextActions: [chooseAction(`Qualify with --space <id>, one of: ${spaceList}`)],
|
|
335
|
+
meta: {
|
|
336
|
+
ref,
|
|
337
|
+
spaceIds: [...spaceIds]
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
function mapRefResolutionError(error) {
|
|
342
|
+
switch (error.kind) {
|
|
343
|
+
case "not-found": {
|
|
344
|
+
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.";
|
|
345
|
+
return new ActionableCliError("MIGRATION.REF_NOT_FOUND", `Not a known ${error.grammar} reference: "${error.input}"`, {
|
|
346
|
+
why: `No ${error.grammar} matching "${error.input}" exists in the migration graph or refs index.`,
|
|
347
|
+
fix,
|
|
348
|
+
nextActions: [chooseAction(fix)],
|
|
349
|
+
meta: {
|
|
350
|
+
input: error.input,
|
|
351
|
+
grammar: error.grammar
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
case "ambiguous": return new ActionableCliError("MIGRATION.REF_AMBIGUOUS", `Ambiguous ${error.grammar} reference: "${error.input}"`, {
|
|
356
|
+
why: `"${error.input}" matches multiple ${error.grammar}s: ${error.candidates.join(", ")}`,
|
|
357
|
+
fix: "Provide a longer prefix or use the full hash to disambiguate.",
|
|
358
|
+
nextActions: [chooseAction("Provide a longer prefix or use the full hash to disambiguate")],
|
|
359
|
+
meta: {
|
|
360
|
+
input: error.input,
|
|
361
|
+
candidates: error.candidates,
|
|
362
|
+
grammar: error.grammar
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
case "wrong-grammar": return new ActionableCliError("MIGRATION.REF_WRONG_GRAMMAR", error.message, {
|
|
366
|
+
why: error.message,
|
|
367
|
+
fix: error.fix,
|
|
368
|
+
nextActions: [chooseAction(error.fix)],
|
|
369
|
+
meta: {
|
|
370
|
+
input: error.input,
|
|
371
|
+
expectedGrammar: error.expectedGrammar
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
case "invalid-format": return new ActionableCliError("MIGRATION.REF_INVALID_FORMAT", `Invalid reference format: "${error.input}"`, {
|
|
375
|
+
why: error.reason,
|
|
376
|
+
fix: "Provide a valid contract hash, ref name, or migration directory name.",
|
|
377
|
+
nextActions: [chooseAction("Provide a valid contract hash, ref name, or migration directory name")],
|
|
378
|
+
meta: { input: error.input }
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
const MASK = "****";
|
|
383
|
+
const URL_SCHEME = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//;
|
|
384
|
+
const LEADING_URL_USERINFO = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/([^/?#\s]+)@/;
|
|
385
|
+
const URL_USERINFO = /([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)([^/?#\s]+)@/g;
|
|
386
|
+
const PASSWORD_QUERY_PARAMETER = /([?&][^=&#\s]*password[^=&#\s]*=)([^&#\s]*)/gi;
|
|
387
|
+
function hasUrlScheme(text) {
|
|
388
|
+
return URL_SCHEME.test(text);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Reads the userinfo of a URL without parsing its hosts, so it works for URLs `new URL` rejects,
|
|
392
|
+
* such as a seed list of several `host:port` pairs. The userinfo ends at the last `@` before the
|
|
393
|
+
* first `/`, `?` or `#`.
|
|
394
|
+
*/
|
|
395
|
+
function urlUserinfo(url) {
|
|
396
|
+
return splitUserinfo(url.match(LEADING_URL_USERINFO)?.[1] ?? "");
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Reads the values of the query parameters whose key contains `password`, the same ones
|
|
400
|
+
* `redactUrlCredentials` masks, without parsing hosts.
|
|
401
|
+
*/
|
|
402
|
+
function passwordQueryValues(url) {
|
|
403
|
+
return [...url.matchAll(PASSWORD_QUERY_PARAMETER)].map((match) => match[2] ?? "");
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Masks the userinfo and any password query parameter of every URL in `text`, without parsing
|
|
407
|
+
* hosts. The masked form matches what `new URL` gives when its username and password are set to
|
|
408
|
+
* `****`.
|
|
409
|
+
*/
|
|
410
|
+
function redactUrlCredentials(text) {
|
|
411
|
+
return text.replace(URL_USERINFO, (_match, scheme, userinfo) => `${scheme}${maskUserinfo(splitUserinfo(userinfo))}@`).replace(PASSWORD_QUERY_PARAMETER, `$1${MASK}`);
|
|
412
|
+
}
|
|
413
|
+
function splitUserinfo(userinfo) {
|
|
414
|
+
const colon = userinfo.indexOf(":");
|
|
415
|
+
if (colon === -1) return {
|
|
416
|
+
username: userinfo,
|
|
417
|
+
password: ""
|
|
418
|
+
};
|
|
419
|
+
return {
|
|
420
|
+
username: userinfo.slice(0, colon),
|
|
421
|
+
password: userinfo.slice(colon + 1)
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
function maskUserinfo({ username, password }) {
|
|
425
|
+
return `${username ? MASK : ""}${password ? `:${MASK}` : ""}`;
|
|
426
|
+
}
|
|
427
|
+
const PASSWORD_QUERY_KEY = /password/i;
|
|
428
|
+
/**
|
|
429
|
+
* Resolves the absolute path to contract.json from the config.
|
|
430
|
+
*/
|
|
431
|
+
function resolveContractPath(config) {
|
|
432
|
+
if (config.contract?.output === void 0) throw errorRuntime("CONFIG.VALIDATION_FAILED", "config.contract.output is required to resolve the contract path", {
|
|
433
|
+
why: "CLI commands read the emitted contract from config.contract.output; the config has no value to read.",
|
|
434
|
+
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."
|
|
435
|
+
});
|
|
436
|
+
return resolve(config.contract.output);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Resolves the migrations directory and config path from CLI options.
|
|
440
|
+
* Shared by migrate, migration-plan, and migration-status.
|
|
441
|
+
*
|
|
442
|
+
* - `migrationsDir` is the project's top-level `migrations/` directory
|
|
443
|
+
* (the root that the aggregate loader walks for every contract space).
|
|
444
|
+
* - `appMigrationsDir` is the app subspace directory under it
|
|
445
|
+
* (`<migrationsDir>/<APP_SPACE_ID>/`). Every per-app reader / writer
|
|
446
|
+
* (`migration new`, `migration plan`, `migrate`,
|
|
447
|
+
* `migration status`, `migration show`, `migration ref`) operates on
|
|
448
|
+
* this directory. Extensions own their own `migrations/<spaceId>/`.
|
|
449
|
+
* - `refsDir` is the app's refs directory (`<appMigrationsDir>/refs/`).
|
|
450
|
+
* The framework does not maintain refs at the migrations root.
|
|
451
|
+
*
|
|
452
|
+
* `cwd` is the directory the command was invoked from; every relative path in
|
|
453
|
+
* the result is computed against it.
|
|
454
|
+
*/
|
|
455
|
+
function resolveMigrationPaths(config, cwd) {
|
|
456
|
+
const configPath = "prisma.config.ts";
|
|
457
|
+
const migrationsDir = resolve(config.baseDir ?? cwd, config.migrations?.dir ?? "migrations");
|
|
458
|
+
const migrationsRelative = relative(cwd, migrationsDir);
|
|
459
|
+
const appMigrationsDir = spaceMigrationDirectory(migrationsDir, APP_SPACE_ID$1);
|
|
460
|
+
return {
|
|
461
|
+
configPath,
|
|
462
|
+
migrationsDir,
|
|
463
|
+
migrationsRelative,
|
|
464
|
+
appMigrationsDir,
|
|
465
|
+
appMigrationsRelative: relative(cwd, appMigrationsDir),
|
|
466
|
+
refsDir: resolve(appMigrationsDir, "refs")
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function collectDeclaredInvariants(graph) {
|
|
470
|
+
const declared = /* @__PURE__ */ new Set();
|
|
471
|
+
for (const edges of graph.forwardChain.values()) for (const edge of edges) for (const inv of edge.invariants) declared.add(inv);
|
|
472
|
+
return declared;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Maps a `MigrationEdge` to the structural-edge shape used in the
|
|
476
|
+
* `MIGRATION.NO_INVARIANT_PATH` error envelope. Shared between
|
|
477
|
+
* `migrate` and `migration status` so both commands surface
|
|
478
|
+
* the same JSON wire shape when an invariant-aware route is unsatisfiable.
|
|
479
|
+
*/
|
|
480
|
+
function toStructuralEdge(edge) {
|
|
481
|
+
return {
|
|
482
|
+
dirName: edge.dirName,
|
|
483
|
+
migrationHash: edge.migrationHash,
|
|
484
|
+
from: edge.from,
|
|
485
|
+
to: edge.to,
|
|
486
|
+
invariants: edge.invariants
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
function targetSupportsMigrations(target) {
|
|
490
|
+
return hasMigrations(target);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Hangs up without letting the hang-up decide the command's result. A rejection out of a
|
|
494
|
+
* `finally` replaces the value the `try`/`catch` already returned, so an unguarded close turns a
|
|
495
|
+
* mapped connection error into an unmapped one — and that is the case it hits most, because a
|
|
496
|
+
* `connect()` that failed leaves nothing to close.
|
|
497
|
+
*/
|
|
498
|
+
async function closeQuietly(client) {
|
|
499
|
+
try {
|
|
500
|
+
await client.close();
|
|
501
|
+
} catch {}
|
|
502
|
+
}
|
|
503
|
+
function getTargetMigrations(target) {
|
|
504
|
+
return hasMigrations(target) ? target.migrations : void 0;
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Reads and parses contract.json, validating the framework-level envelope
|
|
508
|
+
* fields (storageHash, schemaVersion, target, targetFamily).
|
|
509
|
+
*
|
|
510
|
+
* Family-specific validation (storage structure, codec mappings, etc.)
|
|
511
|
+
* happens downstream in the control client via the family instance.
|
|
512
|
+
*/
|
|
513
|
+
async function readContractEnvelope(config) {
|
|
514
|
+
const contractPath = resolveContractPath(config);
|
|
515
|
+
const content = await readFile(contractPath, "utf-8");
|
|
516
|
+
const json = JSON.parse(content);
|
|
517
|
+
const { schemaVersion, target, targetFamily, profileHash } = json;
|
|
518
|
+
const storageHash = json["storage"]?.["storageHash"];
|
|
519
|
+
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 } });
|
|
520
|
+
if (typeof schemaVersion !== "string") throw new CliStructuredError$1("CONTRACT.VALIDATION_FAILED", `Contract at ${relative(process.cwd(), contractPath)} is missing schemaVersion.`, { where: { path: contractPath } });
|
|
521
|
+
if (typeof target !== "string") throw new CliStructuredError$1("CONTRACT.VALIDATION_FAILED", `Contract at ${relative(process.cwd(), contractPath)} is missing target.`, { where: { path: contractPath } });
|
|
522
|
+
if (typeof targetFamily !== "string") throw new CliStructuredError$1("CONTRACT.VALIDATION_FAILED", `Contract at ${relative(process.cwd(), contractPath)} is missing targetFamily.`, { where: { path: contractPath } });
|
|
523
|
+
return {
|
|
524
|
+
...json,
|
|
525
|
+
storageHash,
|
|
526
|
+
schemaVersion,
|
|
527
|
+
target,
|
|
528
|
+
targetFamily,
|
|
529
|
+
...typeof profileHash === "string" ? { profileHash } : {}
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Masks credentials in a database connection URL.
|
|
534
|
+
* Handles standard URLs (username + password + query params), URLs `new URL` rejects (such as
|
|
535
|
+
* multi-host URLs), and libpq-style key=value strings.
|
|
536
|
+
*/
|
|
537
|
+
function maskConnectionUrl(url) {
|
|
538
|
+
try {
|
|
539
|
+
const parsed = new URL(url);
|
|
540
|
+
if (parsed.username) parsed.username = "****";
|
|
541
|
+
if (parsed.password) parsed.password = "****";
|
|
542
|
+
for (const key of [...parsed.searchParams.keys()]) if (PASSWORD_QUERY_KEY.test(key)) parsed.searchParams.set(key, "****");
|
|
543
|
+
return parsed.toString();
|
|
544
|
+
} catch {
|
|
545
|
+
return hasUrlScheme(url) ? redactUrlCredentials(url) : maskKeyValueCredentials(url);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Strips raw connection URL fragments from an error message to prevent credential leakage.
|
|
550
|
+
* Call this before surfacing driver errors to the user.
|
|
551
|
+
*/
|
|
552
|
+
function sanitizeErrorMessage(message, connectionUrl) {
|
|
553
|
+
if (!connectionUrl) return message;
|
|
554
|
+
const secrets = connectionUrlSecrets(connectionUrl);
|
|
555
|
+
if (secrets === void 0) return maskKeyValueCredentials(message);
|
|
556
|
+
let sanitized = message.replaceAll(connectionUrl, maskConnectionUrl(connectionUrl));
|
|
557
|
+
for (const secret of secrets.filter(Boolean).sort(longestFirst)) sanitized = sanitized.replaceAll(secret, "****");
|
|
558
|
+
return sanitized;
|
|
559
|
+
}
|
|
560
|
+
/** A next action with the connection string removed from each of its strings. */
|
|
561
|
+
function nextActionWithoutConnectionString(action, connectionUrl) {
|
|
562
|
+
const clean = (text) => sanitizeErrorMessage(text, connectionUrl);
|
|
563
|
+
return {
|
|
564
|
+
kind: action.kind,
|
|
565
|
+
label: clean(action.label),
|
|
566
|
+
...ifDefined("command", action.command === void 0 ? void 0 : clean(action.command)),
|
|
567
|
+
...ifDefined("commands", action.commands?.map(clean)),
|
|
568
|
+
...ifDefined("url", action.url === void 0 ? void 0 : clean(action.url)),
|
|
569
|
+
...ifDefined("reason", action.reason === void 0 ? void 0 : clean(action.reason))
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
/** `meta` with the connection string removed from every string it holds, however deeply nested. */
|
|
573
|
+
function metaWithoutConnectionString(meta, connectionUrl) {
|
|
574
|
+
const clean = (value) => {
|
|
575
|
+
if (typeof value === "string") return sanitizeErrorMessage(value, connectionUrl);
|
|
576
|
+
if (Array.isArray(value)) return value.map(clean);
|
|
577
|
+
if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, clean(entry)]));
|
|
578
|
+
return value;
|
|
579
|
+
};
|
|
580
|
+
return Object.fromEntries(Object.entries(meta).map(([key, value]) => [key, clean(value)]));
|
|
581
|
+
}
|
|
582
|
+
function connectionUrlSecrets(connectionUrl) {
|
|
583
|
+
try {
|
|
584
|
+
const { username, password, searchParams } = new URL(connectionUrl);
|
|
585
|
+
return [
|
|
586
|
+
username,
|
|
587
|
+
password,
|
|
588
|
+
...[...searchParams].filter(([key]) => PASSWORD_QUERY_KEY.test(key)).map(([, value]) => value)
|
|
589
|
+
];
|
|
590
|
+
} catch {
|
|
591
|
+
if (!hasUrlScheme(connectionUrl)) return;
|
|
592
|
+
const { username, password } = urlUserinfo(connectionUrl);
|
|
593
|
+
return [
|
|
594
|
+
username,
|
|
595
|
+
password,
|
|
596
|
+
...passwordQueryValues(connectionUrl)
|
|
597
|
+
];
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function longestFirst(a, b) {
|
|
601
|
+
return b.length - a.length;
|
|
602
|
+
}
|
|
603
|
+
function maskKeyValueCredentials(text) {
|
|
604
|
+
return text.replace(/password\s*=\s*\S+/gi, "password=****").replace(/user\s*=\s*\S+/gi, "user=****");
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* The error a command reports for one it caught. A CLI error is reported as it is, and so is any other error a library raised with a structured code, such as `CONTRACT.DEFAULT_INVALID` for a stale contract's default or `RUNTIME.TYPE_PARAMS_INVALID` for its type parameters: the code says what went wrong better than the command can. An `InternalError` is thrown again, so the command boundary, `defineOrmCommand`, lets the engine report it as a bug. Anything else is reported as `CLI.UNEXPECTED` with the `why` the command gives for the error's message, and a `code` it carries that is not a structured one, such as a driver's `ECONNREFUSED` or a SQLSTATE, in `meta.code`.
|
|
608
|
+
*
|
|
609
|
+
* A command that holds a database connection passes its connection string, which is then removed from every string the reported error carries, whichever of those it is.
|
|
610
|
+
*/
|
|
611
|
+
function errorFromCaught(error, why, options = {}) {
|
|
612
|
+
const reported = reportedError(error, why);
|
|
613
|
+
return options.connection === void 0 ? reported : withoutConnectionString(reported, options.connection);
|
|
614
|
+
}
|
|
615
|
+
function reportedError(error, why) {
|
|
616
|
+
if (isInternalError(error)) throw error;
|
|
617
|
+
if (CliStructuredError$1.is(error)) return error;
|
|
618
|
+
if (isStructuredError(error)) return new CliStructuredError$1(error.code, error.message, {
|
|
619
|
+
...ifDefined("severity", error.severity),
|
|
620
|
+
...ifDefined("why", error.why),
|
|
621
|
+
...ifDefined("fix", error.fix),
|
|
622
|
+
...ifDefined("nextActions", error.nextActions),
|
|
623
|
+
...ifDefined("where", error.where),
|
|
624
|
+
...ifDefined("meta", error.meta),
|
|
625
|
+
...ifDefined("docsUrl", error.docsUrl),
|
|
626
|
+
cause: error
|
|
627
|
+
});
|
|
628
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
629
|
+
const driverCode = error instanceof Error ? Reflect.get(error, "code") : void 0;
|
|
630
|
+
return errorUnexpected(message, {
|
|
631
|
+
why: why(message),
|
|
632
|
+
...ifDefined("meta", typeof driverCode === "string" ? { code: driverCode } : void 0),
|
|
633
|
+
cause: error
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
function withoutConnectionString(error, connection) {
|
|
637
|
+
const clean = (text) => sanitizeErrorMessage(text, connection);
|
|
638
|
+
return new CliStructuredError$1(error.code, clean(error.message), {
|
|
639
|
+
severity: error.severity,
|
|
640
|
+
...ifDefined("why", error.why === void 0 ? void 0 : clean(error.why)),
|
|
641
|
+
...ifDefined("fix", error.fix === void 0 ? void 0 : clean(error.fix)),
|
|
642
|
+
...ifDefined("nextActions", error.nextActions?.map((action) => nextActionWithoutConnectionString(action, connection))),
|
|
643
|
+
...ifDefined("diagnostics", error.diagnostics?.map((diagnostic) => diagnosticWithoutConnectionString(diagnostic, connection))),
|
|
644
|
+
...ifDefined("where", error.where),
|
|
645
|
+
...ifDefined("meta", error.meta === void 0 ? void 0 : metaWithoutConnectionString(error.meta, connection)),
|
|
646
|
+
...ifDefined("docsUrl", error.docsUrl),
|
|
647
|
+
cause: error.cause
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
function diagnosticWithoutConnectionString(diagnostic, connection) {
|
|
651
|
+
const clean = (text) => sanitizeErrorMessage(text, connection);
|
|
652
|
+
return {
|
|
653
|
+
...diagnostic,
|
|
654
|
+
summary: clean(diagnostic.summary),
|
|
655
|
+
...ifDefined("why", diagnostic.why === void 0 ? void 0 : clean(diagnostic.why)),
|
|
656
|
+
nextActions: diagnostic.nextActions.map((action) => nextActionWithoutConnectionString(action, connection)),
|
|
657
|
+
...ifDefined("meta", diagnostic.meta === void 0 ? void 0 : metaWithoutConnectionString(diagnostic.meta, connection))
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
//#endregion
|
|
661
|
+
export { errorRefSetBundleNotFound as A, getTargetMigrations as B, errorMarkerMissing as C, errorPathUnreachable as D, errorNoMigrations as E, errorSnapshotMissing as F, requireLiveDatabase as G, maskConnectionUrl as H, errorSpaceNotFound as I, runCommandAction as J, resolveContractPath as K, errorTargetMigrationNotSupported as L, errorRefSetHashNotInGraph as M, errorRunnerFailed as N, errorPlanForgotTheFlag as O, errorRuntime as P, errorTargetMismatch as R, errorMarkerMismatch as S, errorMigrationPlanningFailed as T, readContractEnvelope as U, mapRefResolutionError as V, redactUrlCredentials as W, toStructuralEdge as X, targetSupportsMigrations as Y, errorFileNotFound as _, closeQuietly as a, errorInvalidSpaceId as b, errorAmbiguousMigrationRef as c, errorContractArgConflict as d, errorContractConfigMissing as f, errorDriverRequired as g, errorDestructiveChanges as h, chooseAction as i, errorRefSetEmptySentinel as j, errorPlanOriginUnknown as k, errorConfigValidation$1 as l, errorDatabaseConnectionRequired as m, CliStructuredError$1 as n, collectDeclaredInvariants as o, errorContractValidationFailed as p, resolveMigrationPaths as q, ERROR_CODE_DESTRUCTIVE_CHANGES as r, errorAdvanceRefArgConflict as s, ActionableCliError as t, errorConsentPlanMismatch as u, errorFromCaught as v, errorMigrationPackageNotFound as w, errorLegendHumanOnly as x, errorHashMismatch as y, errorUnexpected as z };
|
|
662
|
+
|
|
663
|
+
//# sourceMappingURL=caught-errors-DulynoX6-BSeStARm.mjs.map
|