@prisma-next/cli 0.11.0-dev.24 → 0.11.0-dev.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/{cli-errors-Bw2GlweY.mjs → cli-errors-DFF1LlfU.mjs} +42 -2
  2. package/dist/cli-errors-DFF1LlfU.mjs.map +1 -0
  3. package/dist/cli.mjs +8 -8
  4. package/dist/{client-DePN5ZzP.mjs → client-a5NJce0-.mjs} +4 -4
  5. package/dist/{client-DePN5ZzP.mjs.map → client-a5NJce0-.mjs.map} +1 -1
  6. package/dist/{command-helpers-137k3Zbi.mjs → command-helpers-BnqwTptC.mjs} +2 -2
  7. package/dist/{command-helpers-137k3Zbi.mjs.map → command-helpers-BnqwTptC.mjs.map} +1 -1
  8. package/dist/commands/contract-emit.mjs +1 -1
  9. package/dist/commands/contract-infer.mjs +1 -1
  10. package/dist/commands/db-init.mjs +5 -5
  11. package/dist/commands/db-schema.mjs +3 -3
  12. package/dist/commands/db-sign.mjs +4 -4
  13. package/dist/commands/db-update.mjs +5 -5
  14. package/dist/commands/db-verify.mjs +1 -1
  15. package/dist/commands/migrate.d.mts +1 -1
  16. package/dist/commands/migrate.mjs +4 -4
  17. package/dist/commands/migration-check.mjs +1 -1
  18. package/dist/commands/migration-graph.d.mts +1 -1
  19. package/dist/commands/migration-graph.mjs +2 -2
  20. package/dist/commands/migration-list.d.mts +57 -13
  21. package/dist/commands/migration-list.d.mts.map +1 -1
  22. package/dist/commands/migration-list.mjs +2 -102
  23. package/dist/commands/migration-log.mjs +3 -3
  24. package/dist/commands/migration-new.mjs +3 -3
  25. package/dist/commands/migration-plan.d.mts +1 -1
  26. package/dist/commands/migration-plan.mjs +1 -1
  27. package/dist/commands/migration-show.d.mts +1 -1
  28. package/dist/commands/migration-show.mjs +5 -5
  29. package/dist/commands/migration-status.d.mts +1 -1
  30. package/dist/commands/migration-status.mjs +5 -5
  31. package/dist/commands/ref.d.mts +1 -1
  32. package/dist/commands/ref.mjs +2 -2
  33. package/dist/{contract-emit-D3lPKeRC.mjs → contract-emit-DYBHfZqL.mjs} +3 -3
  34. package/dist/{contract-emit-D3lPKeRC.mjs.map → contract-emit-DYBHfZqL.mjs.map} +1 -1
  35. package/dist/{contract-emit-BBLRbwOP.mjs → contract-emit-aFcOi3aw.mjs} +4 -4
  36. package/dist/{contract-emit-BBLRbwOP.mjs.map → contract-emit-aFcOi3aw.mjs.map} +1 -1
  37. package/dist/{contract-infer-BLAYDLqC.mjs → contract-infer-BpJeg-Eu.mjs} +3 -3
  38. package/dist/{contract-infer-BLAYDLqC.mjs.map → contract-infer-BpJeg-Eu.mjs.map} +1 -1
  39. package/dist/{contract-space-aggregate-loader-CjVyPKxG.mjs → contract-space-aggregate-loader-EVU3n9YE.mjs} +2 -2
  40. package/dist/{contract-space-aggregate-loader-CjVyPKxG.mjs.map → contract-space-aggregate-loader-EVU3n9YE.mjs.map} +1 -1
  41. package/dist/{db-verify-6sapsnWU.mjs → db-verify-CxtdGiL3.mjs} +5 -5
  42. package/dist/{db-verify-6sapsnWU.mjs.map → db-verify-CxtdGiL3.mjs.map} +1 -1
  43. package/dist/exports/control-api.d.mts +1 -1
  44. package/dist/exports/control-api.mjs +2 -2
  45. package/dist/exports/index.mjs +1 -1
  46. package/dist/exports/init-output.mjs +1 -1
  47. package/dist/{framework-components-Bexd0f4E.mjs → framework-components-DTcjouhS.mjs} +2 -2
  48. package/dist/{framework-components-Bexd0f4E.mjs.map → framework-components-DTcjouhS.mjs.map} +1 -1
  49. package/dist/{global-flags-CLwNZnki.d.mts → global-flags-CdE7M0d9.d.mts} +1 -1
  50. package/dist/{global-flags-CLwNZnki.d.mts.map → global-flags-CdE7M0d9.d.mts.map} +1 -1
  51. package/dist/{init-Ba-AZ0zh.mjs → init-eGkSo7hi.mjs} +5 -5
  52. package/dist/{init-Ba-AZ0zh.mjs.map → init-eGkSo7hi.mjs.map} +1 -1
  53. package/dist/{inspect-live-schema-B_xGH5G6.mjs → inspect-live-schema-B1GCyjAJ.mjs} +4 -4
  54. package/dist/{inspect-live-schema-B_xGH5G6.mjs.map → inspect-live-schema-B1GCyjAJ.mjs.map} +1 -1
  55. package/dist/{migration-command-scaffold-Efyi26SZ.mjs → migration-command-scaffold-CNdZl60X.mjs} +4 -4
  56. package/dist/{migration-command-scaffold-Efyi26SZ.mjs.map → migration-command-scaffold-CNdZl60X.mjs.map} +1 -1
  57. package/dist/migration-list-CnYiHrNV.mjs +288 -0
  58. package/dist/migration-list-CnYiHrNV.mjs.map +1 -0
  59. package/dist/{migration-plan-C1blDFs-.mjs → migration-plan-BnmP_yNz.mjs} +5 -5
  60. package/dist/{migration-plan-C1blDFs-.mjs.map → migration-plan-BnmP_yNz.mjs.map} +1 -1
  61. package/dist/{migration-types-DOvz-F0g.d.mts → migration-types-BXWvz12q.d.mts} +1 -1
  62. package/dist/{migration-types-DOvz-F0g.d.mts.map → migration-types-BXWvz12q.d.mts.map} +1 -1
  63. package/dist/{migrations-B8Fjf_zG.mjs → migrations-C7YTBnLy.mjs} +2 -2
  64. package/dist/{migrations-B8Fjf_zG.mjs.map → migrations-C7YTBnLy.mjs.map} +1 -1
  65. package/dist/{output-BlsrGMEF.mjs → output-CUIdfYo5.mjs} +1 -1
  66. package/dist/{output-BlsrGMEF.mjs.map → output-CUIdfYo5.mjs.map} +1 -1
  67. package/dist/{types-CKdsR3HE.d.mts → types-UWB2-rrw.d.mts} +1 -1
  68. package/dist/{types-CKdsR3HE.d.mts.map → types-UWB2-rrw.d.mts.map} +1 -1
  69. package/dist/{verify-8e6M7ZXH.mjs → verify-DX4RQwq4.mjs} +2 -2
  70. package/dist/{verify-8e6M7ZXH.mjs.map → verify-DX4RQwq4.mjs.map} +1 -1
  71. package/package.json +18 -18
  72. package/src/commands/migration-list.ts +145 -74
  73. package/src/utils/cli-errors.ts +51 -0
  74. package/src/utils/formatters/migration-list-render.ts +171 -0
  75. package/src/utils/formatters/migration-list-styler.ts +56 -0
  76. package/dist/cli-errors-Bw2GlweY.mjs.map +0 -1
  77. package/dist/commands/migration-list.mjs.map +0 -1
@@ -0,0 +1,171 @@
1
+ import type {
2
+ MigrationListEntry,
3
+ MigrationListResult,
4
+ } from '@prisma-next/migration-tools/migration-list-types';
5
+
6
+ export type {
7
+ MigrationListEntry,
8
+ MigrationListResult,
9
+ MigrationSpaceListEntry,
10
+ } from '@prisma-next/migration-tools/migration-list-types';
11
+
12
+ const HASH_WIDTH = 7;
13
+ const EMPTY_SOURCE = '∅';
14
+ const SELF_EDGE_GLYPH = '⟲';
15
+ const FORWARD_EDGE_GLYPH = '→';
16
+ const DECORATION_PREFIX = ' ';
17
+
18
+ /**
19
+ * Semantic styler for `migration list` output tokens. Token-typed so
20
+ * the renderer composes presentation-neutral fragments and the styler
21
+ * decides how each token kind is decorated (ANSI codes, plain text,
22
+ * etc.). The renderer pads with raw spaces *outside* styled tokens so
23
+ * visible column widths stay stable regardless of what the styler
24
+ * emits — adding ANSI escape sequences never disturbs alignment.
25
+ *
26
+ * `invariants` and `refs` receive the underlying string arrays rather
27
+ * than a pre-joined string so per-element styling (e.g. distinguishing
28
+ * the live-DB `db` marker from user-named refs) is possible without
29
+ * having to re-parse a joined block.
30
+ */
31
+ export interface MigrationListStyler {
32
+ dirName(text: string): string;
33
+ sourceHash(text: string): string;
34
+ destHash(text: string): string;
35
+ glyph(text: string): string;
36
+ invariants(ids: readonly string[]): string;
37
+ refs(names: readonly string[]): string;
38
+ spaceHeading(text: string): string;
39
+ summary(text: string): string;
40
+ emptyState(text: string): string;
41
+ }
42
+
43
+ export const IDENTITY_MIGRATION_LIST_STYLER: MigrationListStyler = {
44
+ dirName: (text) => text,
45
+ sourceHash: (text) => text,
46
+ destHash: (text) => text,
47
+ glyph: (text) => text,
48
+ invariants: (ids) => `{${ids.join(', ')}}`,
49
+ refs: (names) => `(${names.join(', ')})`,
50
+ spaceHeading: (text) => text,
51
+ summary: (text) => text,
52
+ emptyState: (text) => text,
53
+ };
54
+
55
+ function abbreviateContractHash(hash: string): string {
56
+ const stripped = hash.startsWith('sha256:') ? hash.slice(7) : hash;
57
+ return stripped.slice(0, HASH_WIDTH);
58
+ }
59
+
60
+ function formatSourceColumn(from: string | null, style: MigrationListStyler): string {
61
+ if (from === null) {
62
+ return style.glyph(EMPTY_SOURCE) + ' '.repeat(HASH_WIDTH - EMPTY_SOURCE.length);
63
+ }
64
+ return style.sourceHash(abbreviateContractHash(from));
65
+ }
66
+
67
+ function formatDestColumn(from: string | null, to: string, style: MigrationListStyler): string {
68
+ if (from !== null && from === to) {
69
+ return ' '.repeat(HASH_WIDTH);
70
+ }
71
+ return style.destHash(abbreviateContractHash(to));
72
+ }
73
+
74
+ function formatArrowGlyph(from: string | null, to: string, style: MigrationListStyler): string {
75
+ return style.glyph(from !== null && from === to ? SELF_EDGE_GLYPH : FORWARD_EDGE_GLYPH);
76
+ }
77
+
78
+ function formatDecorations(
79
+ providedInvariants: readonly string[],
80
+ refs: readonly string[],
81
+ style: MigrationListStyler,
82
+ ): string {
83
+ const blocks: string[] = [];
84
+ if (providedInvariants.length > 0) {
85
+ blocks.push(style.invariants(providedInvariants));
86
+ }
87
+ if (refs.length > 0) {
88
+ blocks.push(style.refs(refs));
89
+ }
90
+ if (blocks.length === 0) return '';
91
+ return `${DECORATION_PREFIX}${blocks.join(' ')}`;
92
+ }
93
+
94
+ function formatMigrationRow(
95
+ migration: MigrationListEntry,
96
+ dirNameWidth: number,
97
+ style: MigrationListStyler,
98
+ ): string {
99
+ const dirNamePadding = ' '.repeat(Math.max(0, dirNameWidth - migration.dirName.length));
100
+ const dirName = `${style.dirName(migration.dirName)}${dirNamePadding}`;
101
+ const source = formatSourceColumn(migration.from, style);
102
+ const arrow = formatArrowGlyph(migration.from, migration.to, style);
103
+ const dest = formatDestColumn(migration.from, migration.to, style);
104
+ const decorations = formatDecorations(migration.providedInvariants, migration.refs, style);
105
+ return `${dirName}${source} ${arrow} ${dest}${decorations}`;
106
+ }
107
+
108
+ function formatEmptyStateLine(spaceId: string, style: MigrationListStyler): string {
109
+ return style.emptyState(`There are no migrations in migrations/${spaceId}/ yet`);
110
+ }
111
+
112
+ function renderSpaceBlock(
113
+ spaceId: string,
114
+ migrations: readonly MigrationListEntry[],
115
+ multiSpace: boolean,
116
+ style: MigrationListStyler,
117
+ ): readonly string[] {
118
+ if (migrations.length === 0) {
119
+ const emptyLine = formatEmptyStateLine(spaceId, style);
120
+ if (!multiSpace) {
121
+ return [emptyLine];
122
+ }
123
+ return [style.spaceHeading(`${spaceId}:`), ` ${emptyLine}`];
124
+ }
125
+
126
+ const dirNameWidth = Math.max(...migrations.map((entry) => entry.dirName.length)) + 2;
127
+ const rows = migrations.map((entry) => formatMigrationRow(entry, dirNameWidth, style));
128
+ if (!multiSpace) {
129
+ return rows;
130
+ }
131
+ return [style.spaceHeading(`${spaceId}:`), ...rows.map((row) => ` ${row}`)];
132
+ }
133
+
134
+ /**
135
+ * Compose the styled `migration list` output. The renderer is
136
+ * presentation-neutral — every token passes through `style` before
137
+ * landing in the output, so the same composition serves the pure-text
138
+ * path ({@link renderMigrationList} via
139
+ * {@link IDENTITY_MIGRATION_LIST_STYLER}) and the ANSI-styled CLI path
140
+ * (via the ANSI styler the CLI shell wires up).
141
+ */
142
+ export function renderMigrationListWithStyle(
143
+ result: MigrationListResult,
144
+ style: MigrationListStyler,
145
+ ): string {
146
+ const multiSpace = result.spaces.length > 1;
147
+ const lines: string[] = [];
148
+
149
+ for (let index = 0; index < result.spaces.length; index++) {
150
+ const space = result.spaces[index]!;
151
+ if (index > 0) {
152
+ lines.push('');
153
+ }
154
+ lines.push(...renderSpaceBlock(space.spaceId, space.migrations, multiSpace, style));
155
+ }
156
+
157
+ const totalMigrations = result.spaces.reduce(
158
+ (count, space) => count + space.migrations.length,
159
+ 0,
160
+ );
161
+ if (totalMigrations > 0) {
162
+ lines.push('');
163
+ lines.push(style.summary(result.summary));
164
+ }
165
+
166
+ return lines.join('\n');
167
+ }
168
+
169
+ export function renderMigrationList(result: MigrationListResult): string {
170
+ return renderMigrationListWithStyle(result, IDENTITY_MIGRATION_LIST_STYLER);
171
+ }
@@ -0,0 +1,56 @@
1
+ import { bold, cyan, cyanBright, dim, green, greenBright, yellow } from 'colorette';
2
+ import { IDENTITY_MIGRATION_LIST_STYLER, type MigrationListStyler } from './migration-list-render';
3
+
4
+ /**
5
+ * The reserved ref name for the live-database marker. Treated as a
6
+ * structurally distinct token from user-named refs so the styler can
7
+ * make it visually pop in `(refs)` decorations.
8
+ */
9
+ const DB_REF_NAME = 'db';
10
+
11
+ function styleRefName(name: string): string {
12
+ return name === DB_REF_NAME ? bold(greenBright(name)) : green(name);
13
+ }
14
+
15
+ /**
16
+ * Build a {@link MigrationListStyler} that decorates `migration list`
17
+ * tokens with ANSI SGR codes. When `useColor` is `false` (non-TTY,
18
+ * `--no-color`, `NO_COLOR=1`, piped output) the function returns the
19
+ * shared identity styler so callers get plain text with zero ANSI
20
+ * bytes — pipe-friendly by construction.
21
+ *
22
+ * Palette:
23
+ *
24
+ * - `dirName`: bold
25
+ * - `sourceHash`: dim cyan
26
+ * - `destHash`: bright cyan
27
+ * - `glyph` (`→` / `⟲` / `∅`): dim
28
+ * - `invariants` (`{...}`): yellow
29
+ * - `refs` (`(...)`): green; the live-DB `db` marker inside is green-bold
30
+ * - `spaceHeading` (`<spaceId>:`): bold
31
+ * - `summary`: dim
32
+ * - `emptyState`: dim
33
+ */
34
+ export function createAnsiMigrationListStyler(opts: {
35
+ readonly useColor: boolean;
36
+ }): MigrationListStyler {
37
+ if (!opts.useColor) {
38
+ return IDENTITY_MIGRATION_LIST_STYLER;
39
+ }
40
+ return {
41
+ dirName: (text) => bold(text),
42
+ sourceHash: (text) => dim(cyan(text)),
43
+ destHash: (text) => cyanBright(text),
44
+ glyph: (text) => dim(text),
45
+ invariants: (ids) => yellow(`{${ids.join(', ')}}`),
46
+ refs: (names) => {
47
+ const open = green('(');
48
+ const close = green(')');
49
+ const separator = green(', ');
50
+ return open + names.map(styleRefName).join(separator) + close;
51
+ },
52
+ spaceHeading: (text) => bold(text),
53
+ summary: (text) => dim(text),
54
+ emptyState: (text) => dim(text),
55
+ };
56
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli-errors-Bw2GlweY.mjs","names":[],"sources":["../src/utils/cli-errors.ts"],"sourcesContent":["/**\n * Re-export all domain error factories from @prisma-next/errors for convenience.\n * CLI-specific errors (e.g., Commander argument validation in the main CLI, or\n * clipanion parse errors in the migration-file CLI) can be added here if needed.\n */\nexport type { CliErrorConflict, CliErrorEnvelope } from '@prisma-next/errors/control';\n\nimport {\n CliStructuredError,\n errorConfigFileNotFound,\n errorConfigValidation,\n errorContractConfigMissing,\n errorContractMissingExtensionPacks,\n errorContractValidationFailed,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorFamilyReadMarkerSqlRequired,\n errorFileNotFound,\n errorInvalidOutputFormat,\n errorMigrationCliInvalidConfigArg,\n errorMigrationCliUnknownFlag,\n errorMigrationPlanningFailed,\n errorOutputFormatMutex,\n errorQueryRunnerFactoryRequired,\n errorTargetMigrationNotSupported,\n errorUnexpected,\n} from '@prisma-next/errors/control';\nimport { errorRuntime } from '@prisma-next/errors/execution';\nimport type { MigrationToolsError } from '@prisma-next/migration-tools/errors';\nimport type { RefResolutionError } from '@prisma-next/migration-tools/ref-resolution';\nimport type { MigrationApplyFailure } from '../control-api/types';\n\nexport {\n ERROR_CODE_DESTRUCTIVE_CHANGES,\n errorDestructiveChanges,\n errorHashMismatch,\n errorMarkerMissing,\n errorMarkerRequired,\n errorRunnerFailed,\n errorRuntime,\n errorSchemaVerificationFailed,\n errorTargetMismatch,\n} from '@prisma-next/errors/execution';\nexport {\n errorMigrationFileMissing,\n errorMigrationInvalidDefaultExport,\n errorMigrationPlanNotArray,\n errorUnfilledPlaceholder,\n placeholder,\n} from '@prisma-next/errors/migration';\nexport {\n CliStructuredError,\n errorConfigFileNotFound,\n errorConfigValidation,\n errorContractConfigMissing,\n errorContractMissingExtensionPacks,\n errorContractValidationFailed,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorFamilyReadMarkerSqlRequired,\n errorFileNotFound,\n errorInvalidOutputFormat,\n errorMigrationCliInvalidConfigArg,\n errorMigrationCliUnknownFlag,\n errorMigrationPlanningFailed,\n errorOutputFormatMutex,\n errorQueryRunnerFactoryRequired,\n errorTargetMigrationNotSupported,\n errorUnexpected,\n};\n\nexport function errorRefSetHashNotInGraph(\n resolvedHash: string,\n reachableHashes: readonly string[],\n graphTipHash: string | null,\n): CliStructuredError {\n const reachableList =\n reachableHashes.length > 0 ? reachableHashes.join(', ') : '(none — migration graph is empty)';\n const fix =\n reachableHashes.length > 0\n ? graphTipHash !== null\n ? `Set the ref to a graph-node hash such as ${graphTipHash}, or run \\`prisma-next migration plan\\` to extend the graph.`\n : 'Set the ref to a hash that appears in the migration graph.'\n : 'Run `prisma-next migration plan` first.';\n return errorRuntime(`Resolved contract hash is not in the migration graph: ${resolvedHash}`, {\n why:\n reachableHashes.length > 0\n ? `The migration graph reaches ${reachableList}; resolved ${resolvedHash} isn't a graph node.`\n : 'The migration graph is empty — no hashes reachable.',\n fix,\n meta: {\n code: 'MIGRATION.HASH_NOT_IN_GRAPH',\n resolvedHash,\n reachableHashes: [...reachableHashes],\n ...(graphTipHash !== null ? { graphTipHash } : {}),\n },\n });\n}\n\nexport function errorRefSetEmptySentinel(hash: string): CliStructuredError {\n return errorRuntime(`Cannot set ref to the empty-database sentinel: ${hash}`, {\n why: 'The empty-database sentinel is a planner internal; it is not a valid ref target.',\n fix: 'Set the ref to a contract hash from the migration graph, or use another ref name.',\n meta: {\n code: 'MIGRATION.REF_SET_EMPTY_SENTINEL',\n hash,\n },\n });\n}\n\nexport function errorRefSetBundleNotFound(hash: string): CliStructuredError {\n return errorRuntime(`No migration bundle matches graph-node hash ${hash}`, {\n why: `The hash is a graph node but no on-disk bundle has metadata.to = ${hash}.`,\n fix: 'Run `pnpm fixtures:check`, or re-emit the migration that produces this hash so its bundle is restored.',\n meta: {\n code: 'MIGRATION.REF_SET_BUNDLE_NOT_FOUND',\n hash,\n },\n });\n}\n\nexport function errorPlanForgotTheFlag(\n resolvedHash: string,\n reachableRefs: ReadonlyArray<{ readonly name: string; readonly hash: string }>,\n graphTipHash: string | null,\n): CliStructuredError {\n const reachableList =\n reachableRefs.length > 0\n ? reachableRefs.map((r) => `${r.name} (${r.hash})`).join(', ')\n : '(none)';\n const refFix =\n reachableRefs.length > 0\n ? `Run migration plan with ${reachableRefs.map((r) => `--from ${r.name}`).join(' or ')}.`\n : graphTipHash !== null\n ? `Run migration plan --from ${graphTipHash}.`\n : 'Commit pending migrations first, then run migration plan.';\n return errorRuntime(`Resolved from-hash is not in the migration graph: ${resolvedHash}`, {\n why: `The migration graph reaches ${reachableList}; resolved ${resolvedHash} isn't a graph node.`,\n fix: refFix,\n meta: {\n code: 'MIGRATION.HASH_NOT_IN_GRAPH',\n resolvedHash,\n reachableRefs: reachableRefs.map((r) => r.name),\n ...(graphTipHash !== null ? { graphTipHash } : {}),\n },\n });\n}\n\nexport function errorSnapshotMissing(\n identifier: string,\n options?: { readonly viaRef?: boolean },\n): CliStructuredError {\n const viaRef = options?.viaRef !== false;\n const fix = viaRef\n ? `Run \"prisma-next db update --advance-ref ${identifier}\" to repopulate the snapshot, or \"prisma-next ref delete ${identifier}\" to clear the orphan pointer.`\n : `No contract source exists for hash \"${identifier}\" on an empty migration graph. Use --from with a ref name that has a paired snapshot, or run db update first.`;\n return errorRuntime(\n viaRef\n ? `Ref \"${identifier}\" has no paired contract snapshot`\n : `No contract source for from-hash \"${identifier}\"`,\n {\n why: viaRef\n ? `Ref \"${identifier}\" exists but its paired snapshot files are missing.`\n : `Hash \"${identifier}\" is not a graph node and no paired ref snapshot supplies a contract.`,\n fix,\n meta: {\n code: 'MIGRATION.SNAPSHOT_MISSING',\n identifier,\n viaRef,\n },\n },\n );\n}\n\nexport function errorMarkerMismatch(\n markerHash: string,\n reachableHashes: readonly string[],\n graphTip: string | null,\n): CliStructuredError {\n const reachableList =\n reachableHashes.length > 0 ? reachableHashes.join(', ') : '(none — migration graph is empty)';\n const planFromFix =\n graphTip !== null\n ? `Run \\`prisma-next migration plan --from ${graphTip}\\` if the live marker is canonical and the on-disk graph needs catching up.`\n : 'Run `prisma-next migration plan` if the live marker is canonical and the on-disk graph needs catching up.';\n return errorRuntime('Database marker is not reachable in the on-disk migration graph', {\n why: `DB marker is ${markerHash}, but the on-disk migration graph reaches: ${reachableList}.`,\n fix: [\n planFromFix,\n `Run \\`prisma-next ref set db ${markerHash}\\` if the on-disk graph is canonical and the local \\`db\\` ref drifted.`,\n 'Investigate whether the database was migrated by an out-of-band process.',\n ].join('\\n'),\n meta: {\n code: 'MIGRATION.MARKER_MISMATCH',\n markerHash,\n reachableHashes: [...reachableHashes],\n ...(graphTip !== null ? { graphTip } : {}),\n },\n });\n}\n\nexport function errorPathUnreachable(failure: MigrationApplyFailure): CliStructuredError {\n const meta = failure.meta ?? {};\n const fromHash = typeof meta['fromHash'] === 'string' ? meta['fromHash'] : null;\n const targetHash =\n typeof meta['targetHash'] === 'string'\n ? meta['targetHash']\n : typeof meta['target'] === 'string'\n ? meta['target']\n : null;\n const deadEnds = meta['deadEnds'];\n const deadEndsSuffix =\n Array.isArray(deadEnds) && deadEnds.length > 0\n ? ` Dead-ends: ${deadEnds.map(String).join(', ')}.`\n : '';\n const planFix = (() => {\n if (fromHash !== null && targetHash !== null) {\n return `Run \\`prisma-next migration plan --from ${fromHash} --to ${targetHash}\\` to introduce the missing path.`;\n }\n if (targetHash !== null) {\n return `Run \\`prisma-next migration plan --to ${targetHash}\\` to introduce the missing path.`;\n }\n if (fromHash !== null) {\n return `Run \\`prisma-next migration plan --from ${fromHash}\\` to introduce the missing path.`;\n }\n return 'Run `prisma-next migration plan` to introduce the missing path.';\n })();\n return errorRuntime(failure.summary, {\n why:\n failure.why ??\n `Cannot reach target \"${targetHash ?? '<unknown>'}\" from current marker \"${fromHash ?? '<unknown>'}\".${deadEndsSuffix}`,\n fix: [\n 'Run `prisma-next migration list` to see the on-disk graph.',\n planFix,\n 'Run `prisma-next migration show <bundle>` for any bundle in the path you expected.',\n ].join('\\n'),\n meta: {\n ...meta,\n code: 'MIGRATION.PATH_UNREACHABLE',\n },\n });\n}\n\n/**\n * Maps a `MigrationToolsError` raised by the migration-tools loader/graph\n * surface (`readMigrationPackage`, `readMigrationsDir`, `readRefs`,\n * `resolveRef`, `reconstructGraph`, ...) into a CLI `errorRuntime` envelope.\n *\n * The full `error.details` payload is forwarded into `meta` so machine\n * consumers (`--json`) see structural fields like `dir`, `storedHash`,\n * `computedHash` (for `MIGRATION.HASH_MISMATCH`) alongside the stable\n * `code`. The user-visible `summary`/`why`/`fix` text is unchanged.\n *\n * Callers are expected to gate on `MigrationToolsError.is(error)` first\n * (mirroring the original inline pattern); non-`MigrationToolsError`\n * values are caller-classified (rethrow, wrap with command-specific\n * `errorUnexpected`, etc.).\n */\nexport function mapMigrationToolsError(error: MigrationToolsError): CliStructuredError {\n return errorRuntime(error.message, {\n why: error.why,\n fix: error.fix,\n meta: { code: error.code, ...(error.details ?? {}) },\n });\n}\n\n/**\n * Maps a `RefResolutionError` from the contract/migration reference\n * resolver into a CLI structured error envelope.\n */\nexport function mapRefResolutionError(error: RefResolutionError): CliStructuredError {\n switch (error.kind) {\n case 'not-found':\n return errorRuntime(`Not a known ${error.grammar} reference: \"${error.input}\"`, {\n why: `No ${error.grammar} matching \"${error.input}\" exists in the migration graph or refs index.`,\n fix:\n error.grammar === 'contract'\n ? 'Provide a valid contract hash, ref name, or migration directory name.'\n : 'Provide a valid migration directory name or migration hash.',\n meta: { input: error.input, grammar: error.grammar },\n });\n case 'ambiguous':\n return errorRuntime(`Ambiguous ${error.grammar} reference: \"${error.input}\"`, {\n why: `\"${error.input}\" matches multiple ${error.grammar}s: ${error.candidates.join(', ')}`,\n fix: 'Provide a longer prefix or use the full hash to disambiguate.',\n meta: { input: error.input, candidates: error.candidates, grammar: error.grammar },\n });\n case 'wrong-grammar':\n return errorRuntime(error.message, {\n why: error.message,\n fix: error.fix,\n meta: { input: error.input, expectedGrammar: error.expectedGrammar },\n });\n case 'invalid-format':\n return errorRuntime(`Invalid reference format: \"${error.input}\"`, {\n why: error.reason,\n fix: 'Provide a valid contract hash, ref name, or migration directory name.',\n meta: { input: error.input },\n });\n }\n}\n"],"mappings":";;;;AAuEA,SAAgB,0BACd,cACA,iBACA,cACoB;CACpB,MAAM,gBACJ,gBAAgB,SAAS,IAAI,gBAAgB,KAAK,IAAI,IAAI;CAC5D,MAAM,MACJ,gBAAgB,SAAS,IACrB,iBAAiB,OACf,4CAA4C,aAAa,gEACzD,+DACF;CACN,OAAO,aAAa,yDAAyD,gBAAgB;EAC3F,KACE,gBAAgB,SAAS,IACrB,+BAA+B,cAAc,aAAa,aAAa,wBACvE;EACN;EACA,MAAM;GACJ,MAAM;GACN;GACA,iBAAiB,CAAC,GAAG,eAAe;GACpC,GAAI,iBAAiB,OAAO,EAAE,aAAa,IAAI,CAAC;EAClD;CACF,CAAC;AACH;AAEA,SAAgB,yBAAyB,MAAkC;CACzE,OAAO,aAAa,kDAAkD,QAAQ;EAC5E,KAAK;EACL,KAAK;EACL,MAAM;GACJ,MAAM;GACN;EACF;CACF,CAAC;AACH;AAEA,SAAgB,0BAA0B,MAAkC;CAC1E,OAAO,aAAa,+CAA+C,QAAQ;EACzE,KAAK,oEAAoE,KAAK;EAC9E,KAAK;EACL,MAAM;GACJ,MAAM;GACN;EACF;CACF,CAAC;AACH;AAEA,SAAgB,uBACd,cACA,eACA,cACoB;CACpB,MAAM,gBACJ,cAAc,SAAS,IACnB,cAAc,KAAK,MAAM,GAAG,EAAE,KAAK,IAAI,EAAE,KAAK,EAAE,EAAE,KAAK,IAAI,IAC3D;CACN,MAAM,SACJ,cAAc,SAAS,IACnB,2BAA2B,cAAc,KAAK,MAAM,UAAU,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,KACrF,iBAA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F,CAAC;EACH,KAAK,iBACH,OAAO,aAAa,MAAM,SAAS;GACjC,KAAK,MAAM;GACX,KAAK,MAAM;GACX,MAAM;IAAE,OAAO,MAAM;IAAO,iBAAiB,MAAM;GAAgB;EACrE,CAAC;EACH,KAAK,kBACH,OAAO,aAAa,8BAA8B,MAAM,MAAM,IAAI;GAChE,KAAK,MAAM;GACX,KAAK;GACL,MAAM,EAAE,OAAO,MAAM,MAAM;EAC7B,CAAC;CACL;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"migration-list.mjs","names":[],"sources":["../../src/commands/migration-list.ts"],"sourcesContent":["import type { MigrationPlanOperation } from '@prisma-next/framework-components/control';\nimport { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';\nimport { MigrationToolsError } from '@prisma-next/migration-tools/errors';\nimport { findPath } from '@prisma-next/migration-tools/migration-graph';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport {\n type CliStructuredError,\n errorUnexpected,\n mapMigrationToolsError,\n} from '../utils/cli-errors';\nimport {\n addGlobalOptions,\n loadMigrationPackages,\n resolveMigrationPaths,\n setCommandDescriptions,\n setCommandExamples,\n setCommandSeeAlso,\n} from '../utils/command-helpers';\nimport { formatStyledHeader } from '../utils/formatters/styled';\nimport type { CommonCommandOptions } from '../utils/global-flags';\nimport { type GlobalFlags, parseGlobalFlagsOrExit } from '../utils/global-flags';\nimport { handleResult } from '../utils/result-handler';\nimport { createTerminalUI, type TerminalUI } from '../utils/terminal-ui';\n\ninterface MigrationListOptions extends CommonCommandOptions {\n readonly config?: string;\n}\n\nexport interface MigrationListEntry {\n readonly dirName: string;\n readonly from: string;\n readonly to: string;\n readonly migrationHash: string;\n readonly operationCount: number;\n readonly createdAt: string;\n}\n\nexport interface MigrationListResult {\n readonly ok: true;\n readonly migrations: readonly MigrationListEntry[];\n readonly summary: string;\n}\n\nasync function executeMigrationListCommand(\n options: MigrationListOptions,\n flags: GlobalFlags,\n ui: TerminalUI,\n): Promise<Result<MigrationListResult, CliStructuredError>> {\n const config = await loadConfig(options.config);\n const { configPath, appMigrationsDir, appMigrationsRelative } = resolveMigrationPaths(\n options.config,\n config,\n );\n\n if (!flags.json && !flags.quiet) {\n const header = formatStyledHeader({\n command: 'migration list',\n description: 'List on-disk migrations in topological order',\n details: [\n { label: 'config', value: configPath },\n { label: 'migrations', value: appMigrationsRelative },\n ],\n flags,\n });\n ui.stderr(header);\n }\n\n let bundles: Awaited<ReturnType<typeof loadMigrationPackages>>['bundles'];\n let graph: Awaited<ReturnType<typeof loadMigrationPackages>>['graph'];\n try {\n ({ bundles, graph } = await loadMigrationPackages(appMigrationsDir));\n } catch (error) {\n if (MigrationToolsError.is(error)) return notOk(mapMigrationToolsError(error));\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to read migrations: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n }\n\n if (bundles.length === 0) {\n return ok({ ok: true, migrations: [], summary: 'No migrations found' });\n }\n\n const leaves = [...graph.nodes].filter(\n (n) => !graph.forwardChain.has(n) || graph.forwardChain.get(n)!.length === 0,\n );\n const targetHash =\n leaves.length === 1 ? leaves[0]! : ([...graph.nodes].values().next().value as string);\n const chain = findPath(graph, EMPTY_CONTRACT_HASH, targetHash) ?? [];\n\n const pkgByDirName = new Map(bundles.map((p) => [p.dirName, p]));\n const entries: MigrationListEntry[] = chain.map((edge) => {\n const pkg = pkgByDirName.get(edge.dirName);\n const ops = (pkg?.ops ?? []) as readonly MigrationPlanOperation[];\n return {\n dirName: edge.dirName,\n from: edge.from,\n to: edge.to,\n migrationHash: edge.migrationHash,\n operationCount: ops.length,\n createdAt: edge.createdAt,\n };\n });\n\n return ok({\n ok: true,\n migrations: entries,\n summary: `${entries.length} migration(s) on disk`,\n });\n}\n\nexport function createMigrationListCommand(): Command {\n const command = new Command('list');\n setCommandDescriptions(\n command,\n 'List on-disk migrations in topological order',\n 'Enumerates all migration packages under migrations/<space>/ in\\n' +\n 'topological order. Offline — does not consult the database.',\n );\n setCommandExamples(command, ['prisma-next migration list']);\n setCommandSeeAlso(command, [\n { verb: 'migration status', oneLiner: 'Show migration path and pending status' },\n { verb: 'migration log', oneLiner: 'Show executed migration history' },\n { verb: 'migration graph', oneLiner: 'Show the migration graph topology' },\n { verb: 'migration show', oneLiner: 'Display migration package contents' },\n ]);\n addGlobalOptions(command)\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .action(async (options: MigrationListOptions) => {\n const flags = parseGlobalFlagsOrExit(options);\n const ui = createTerminalUI(flags);\n const result = await executeMigrationListCommand(options, flags, ui);\n const exitCode = handleResult(result, flags, ui, (listResult) => {\n if (flags.json) {\n ui.output(JSON.stringify(listResult, null, 2));\n } else if (!flags.quiet) {\n if (listResult.migrations.length === 0) {\n ui.log('No migrations found');\n } else {\n for (const entry of listResult.migrations) {\n ui.log(\n `${entry.dirName} ${entry.migrationHash.slice(0, 16)}… ${entry.operationCount} op(s)`,\n );\n }\n ui.log(`\\n${listResult.summary}`);\n }\n }\n });\n process.exit(exitCode);\n });\n return command;\n}\n"],"mappings":";;;;;;;;;AA6CA,eAAe,4BACb,SACA,OACA,IAC0D;CAC1D,MAAM,SAAS,MAAM,WAAW,QAAQ,MAAM;CAC9C,MAAM,EAAE,YAAY,kBAAkB,0BAA0B,sBAC9D,QAAQ,QACR,MACF;CAEA,IAAI,CAAC,MAAM,QAAQ,CAAC,MAAM,OAAO;EAC/B,MAAM,SAAS,mBAAmB;GAChC,SAAS;GACT,aAAa;GACb,SAAS,CACP;IAAE,OAAO;IAAU,OAAO;GAAW,GACrC;IAAE,OAAO;IAAc,OAAO;GAAsB,CACtD;GACA;EACF,CAAC;EACD,GAAG,OAAO,MAAM;CAClB;CAEA,IAAI;CACJ,IAAI;CACJ,IAAI;EACF,CAAC,CAAE,SAAS,SAAU,MAAM,sBAAsB,gBAAgB;CACpE,SAAS,OAAO;EACd,IAAI,oBAAoB,GAA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