@prisma-next/cli 0.5.0-dev.1 → 0.5.0-dev.10

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 (138) hide show
  1. package/README.md +17 -18
  2. package/dist/agent-skill-mongo.md +63 -31
  3. package/dist/agent-skill-postgres.md +1 -1
  4. package/dist/cli-errors-By1iVE3z.mjs +34 -0
  5. package/dist/cli-errors-By1iVE3z.mjs.map +1 -0
  6. package/dist/{cli-errors-C0JhVj0c.d.mts → cli-errors-D2NPMaxW.d.mts} +1 -0
  7. package/dist/cli.mjs +126 -13
  8. package/dist/cli.mjs.map +1 -1
  9. package/dist/{client-TG7rbCWT.mjs → client-faKQqcix.mjs} +19 -4
  10. package/dist/client-faKQqcix.mjs.map +1 -0
  11. package/dist/commands/contract-emit.mjs +7 -2
  12. package/dist/commands/contract-infer.mjs +8 -2
  13. package/dist/commands/db-init.mjs +8 -7
  14. package/dist/commands/db-init.mjs.map +1 -1
  15. package/dist/commands/db-schema.mjs +8 -5
  16. package/dist/commands/db-schema.mjs.map +1 -1
  17. package/dist/commands/db-sign.mjs +8 -7
  18. package/dist/commands/db-sign.mjs.map +1 -1
  19. package/dist/commands/db-update.mjs +8 -7
  20. package/dist/commands/db-update.mjs.map +1 -1
  21. package/dist/commands/db-verify.mjs +8 -7
  22. package/dist/commands/db-verify.mjs.map +1 -1
  23. package/dist/commands/migration-apply.d.mts +1 -1
  24. package/dist/commands/migration-apply.d.mts.map +1 -1
  25. package/dist/commands/migration-apply.mjs +14 -37
  26. package/dist/commands/migration-apply.mjs.map +1 -1
  27. package/dist/commands/migration-new.d.mts.map +1 -1
  28. package/dist/commands/migration-new.mjs +20 -25
  29. package/dist/commands/migration-new.mjs.map +1 -1
  30. package/dist/commands/migration-plan.d.mts +6 -3
  31. package/dist/commands/migration-plan.d.mts.map +1 -1
  32. package/dist/commands/migration-plan.mjs +30 -35
  33. package/dist/commands/migration-plan.mjs.map +1 -1
  34. package/dist/commands/migration-ref.d.mts +6 -4
  35. package/dist/commands/migration-ref.d.mts.map +1 -1
  36. package/dist/commands/migration-ref.mjs +31 -40
  37. package/dist/commands/migration-ref.mjs.map +1 -1
  38. package/dist/commands/migration-show.d.mts +4 -4
  39. package/dist/commands/migration-show.d.mts.map +1 -1
  40. package/dist/commands/migration-show.mjs +18 -25
  41. package/dist/commands/migration-show.mjs.map +1 -1
  42. package/dist/commands/migration-status.d.mts +5 -4
  43. package/dist/commands/migration-status.d.mts.map +1 -1
  44. package/dist/commands/migration-status.mjs +7 -2
  45. package/dist/{config-loader-_W4T21X1.mjs → config-loader-C25b63rJ.mjs} +1 -1
  46. package/dist/{config-loader-_W4T21X1.mjs.map → config-loader-C25b63rJ.mjs.map} +1 -1
  47. package/dist/config-loader.mjs +1 -1
  48. package/dist/{contract-emit-CNYyzJwF.mjs → contract-emit-B5wnhTuF.mjs} +8 -8
  49. package/dist/{contract-emit-CNYyzJwF.mjs.map → contract-emit-B5wnhTuF.mjs.map} +1 -1
  50. package/dist/contract-emit-B9wkchud.mjs +6 -0
  51. package/dist/{contract-emit-CQfj7xJn.mjs → contract-emit-PeB96eHy.mjs} +6 -6
  52. package/dist/{contract-emit-CQfj7xJn.mjs.map → contract-emit-PeB96eHy.mjs.map} +1 -1
  53. package/dist/{contract-enrichment-CGW6mm-E.mjs → contract-enrichment-CAOELa-H.mjs} +1 -1
  54. package/dist/{contract-enrichment-CGW6mm-E.mjs.map → contract-enrichment-CAOELa-H.mjs.map} +1 -1
  55. package/dist/{contract-infer-BP3DrGgz.mjs → contract-infer-DnY9fUw0.mjs} +4 -4
  56. package/dist/{contract-infer-BP3DrGgz.mjs.map → contract-infer-DnY9fUw0.mjs.map} +1 -1
  57. package/dist/exports/control-api.mjs +6 -4
  58. package/dist/exports/index.mjs +7 -2
  59. package/dist/exports/index.mjs.map +1 -1
  60. package/dist/exports/init-output.d.mts +39 -0
  61. package/dist/exports/init-output.d.mts.map +1 -0
  62. package/dist/exports/init-output.mjs +3 -0
  63. package/dist/{extract-operation-statements-DZUJNmL3.mjs → extract-operation-statements-DsFfxXVZ.mjs} +2 -2
  64. package/dist/{extract-operation-statements-DZUJNmL3.mjs.map → extract-operation-statements-DsFfxXVZ.mjs.map} +1 -1
  65. package/dist/{extract-sql-ddl-DDMX-9mz.mjs → extract-sql-ddl-D9UbZDyz.mjs} +1 -1
  66. package/dist/{extract-sql-ddl-DDMX-9mz.mjs.map → extract-sql-ddl-D9UbZDyz.mjs.map} +1 -1
  67. package/dist/{framework-components-DfZKQBQ2.mjs → framework-components-C6el-5x_.mjs} +2 -2
  68. package/dist/{framework-components-DfZKQBQ2.mjs.map → framework-components-C6el-5x_.mjs.map} +1 -1
  69. package/dist/init-jf33mNQ6.mjs +2062 -0
  70. package/dist/init-jf33mNQ6.mjs.map +1 -0
  71. package/dist/{inspect-live-schema-DWzf4Q_m.mjs → inspect-live-schema-CqoZhKC1.mjs} +6 -6
  72. package/dist/{inspect-live-schema-DWzf4Q_m.mjs.map → inspect-live-schema-CqoZhKC1.mjs.map} +1 -1
  73. package/dist/migration-cli.mjs +14 -7
  74. package/dist/migration-cli.mjs.map +1 -1
  75. package/dist/{migration-command-scaffold-CLMD302g.mjs → migration-command-scaffold-B40VaF-m.mjs} +6 -6
  76. package/dist/{migration-command-scaffold-CLMD302g.mjs.map → migration-command-scaffold-B40VaF-m.mjs.map} +1 -1
  77. package/dist/{migration-status-B0HLF7So.mjs → migration-status-CDgFxhAo.mjs} +18 -32
  78. package/dist/migration-status-CDgFxhAo.mjs.map +1 -0
  79. package/dist/{migrations-B0dOQlk0.mjs → migrations-CKRMAKka.mjs} +3 -3
  80. package/dist/migrations-CKRMAKka.mjs.map +1 -0
  81. package/dist/output-BpcQrnnq.mjs +103 -0
  82. package/dist/output-BpcQrnnq.mjs.map +1 -0
  83. package/dist/{progress-adapter-B-YvmcDu.mjs → progress-adapter-DvQWB1nK.mjs} +1 -1
  84. package/dist/{progress-adapter-B-YvmcDu.mjs.map → progress-adapter-DvQWB1nK.mjs.map} +1 -1
  85. package/dist/quick-reference-mongo.md +34 -13
  86. package/dist/quick-reference-postgres.md +11 -9
  87. package/dist/{result-handler-CIyu0Pdt.mjs → result-handler-DcV0QoTr.mjs} +9 -90
  88. package/dist/result-handler-DcV0QoTr.mjs.map +1 -0
  89. package/dist/{terminal-ui-C5k88MmW.mjs → terminal-ui-C3ZLwQxK.mjs} +76 -2
  90. package/dist/terminal-ui-C3ZLwQxK.mjs.map +1 -0
  91. package/dist/{validate-contract-deps-esa-VQ0h.mjs → validate-contract-deps-B_Cs29TL.mjs} +1 -1
  92. package/dist/{validate-contract-deps-esa-VQ0h.mjs.map → validate-contract-deps-B_Cs29TL.mjs.map} +1 -1
  93. package/dist/{verify-BxiVp50b.mjs → verify-Bkycc-Tf.mjs} +2 -2
  94. package/dist/{verify-BxiVp50b.mjs.map → verify-Bkycc-Tf.mjs.map} +1 -1
  95. package/package.json +19 -14
  96. package/src/commands/init/detect-pnpm-catalog.ts +141 -0
  97. package/src/commands/init/errors.ts +254 -0
  98. package/src/commands/init/exit-codes.ts +62 -0
  99. package/src/commands/init/hygiene-gitattributes.ts +97 -0
  100. package/src/commands/init/hygiene-gitignore.ts +48 -0
  101. package/src/commands/init/hygiene-package-scripts.ts +91 -0
  102. package/src/commands/init/index.ts +112 -7
  103. package/src/commands/init/init.ts +766 -144
  104. package/src/commands/init/inputs.ts +421 -0
  105. package/src/commands/init/output.ts +147 -0
  106. package/src/commands/init/probe-db.ts +308 -0
  107. package/src/commands/init/reinit-cleanup.ts +83 -0
  108. package/src/commands/init/templates/agent-skill-mongo.md +63 -31
  109. package/src/commands/init/templates/agent-skill-postgres.md +1 -1
  110. package/src/commands/init/templates/agent-skill.ts +25 -3
  111. package/src/commands/init/templates/code-templates.ts +125 -32
  112. package/src/commands/init/templates/env.ts +80 -0
  113. package/src/commands/init/templates/quick-reference-mongo.md +34 -13
  114. package/src/commands/init/templates/quick-reference-postgres.md +11 -9
  115. package/src/commands/init/templates/quick-reference.ts +42 -3
  116. package/src/commands/init/templates/tsconfig.ts +167 -5
  117. package/src/commands/migration-apply.ts +14 -49
  118. package/src/commands/migration-new.ts +19 -27
  119. package/src/commands/migration-plan.ts +52 -41
  120. package/src/commands/migration-ref.ts +40 -54
  121. package/src/commands/migration-show.ts +23 -27
  122. package/src/commands/migration-status.ts +29 -46
  123. package/src/control-api/operations/migration-apply.ts +15 -0
  124. package/src/exports/init-output.ts +10 -0
  125. package/src/migration-cli.ts +16 -9
  126. package/src/utils/cli-errors.ts +45 -1
  127. package/src/utils/command-helpers.ts +11 -24
  128. package/src/utils/formatters/graph-migration-mapper.ts +1 -1
  129. package/src/utils/formatters/migrations.ts +2 -2
  130. package/dist/cli-errors-DHq6GQGu.mjs +0 -5
  131. package/dist/client-TG7rbCWT.mjs.map +0 -1
  132. package/dist/contract-emit-fhNwwhkQ.mjs +0 -4
  133. package/dist/init-CQfo_4Ro.mjs +0 -430
  134. package/dist/init-CQfo_4Ro.mjs.map +0 -1
  135. package/dist/migration-status-B0HLF7So.mjs.map +0 -1
  136. package/dist/migrations-B0dOQlk0.mjs.map +0 -1
  137. package/dist/result-handler-CIyu0Pdt.mjs.map +0 -1
  138. package/dist/terminal-ui-C5k88MmW.mjs.map +0 -1
@@ -1,14 +1,19 @@
1
1
  import type { MigrationPlanOperation } from '@prisma-next/framework-components/control';
2
2
  import { findLatestMigration, reconstructGraph } from '@prisma-next/migration-tools/dag';
3
+ import { MigrationToolsError } from '@prisma-next/migration-tools/errors';
3
4
  import { readMigrationPackage, readMigrationsDir } from '@prisma-next/migration-tools/io';
4
- import type { MigrationBundle } from '@prisma-next/migration-tools/types';
5
- import { MigrationToolsError } from '@prisma-next/migration-tools/types';
5
+ import type { MigrationPackage } from '@prisma-next/migration-tools/package';
6
6
  import { notOk, ok, type Result } from '@prisma-next/utils/result';
7
7
  import { Command } from 'commander';
8
8
  import { relative, resolve } from 'pathe';
9
9
  import { loadConfig } from '../config-loader';
10
10
  import { extractOperationStatements } from '../control-api/operations/extract-operation-statements';
11
- import { type CliStructuredError, errorRuntime, errorUnexpected } from '../utils/cli-errors';
11
+ import {
12
+ type CliStructuredError,
13
+ errorRuntime,
14
+ errorUnexpected,
15
+ mapMigrationToolsError,
16
+ } from '../utils/cli-errors';
12
17
  import {
13
18
  addGlobalOptions,
14
19
  setCommandDescriptions,
@@ -31,7 +36,7 @@ export interface MigrationShowResult {
31
36
  readonly dirPath: string;
32
37
  readonly from: string;
33
38
  readonly to: string;
34
- readonly migrationId: string;
39
+ readonly migrationHash: string;
35
40
  readonly kind: string;
36
41
  readonly createdAt: string;
37
42
  readonly operations: readonly {
@@ -48,11 +53,11 @@ function looksLikePath(target: string): boolean {
48
53
  }
49
54
 
50
55
  export function resolveByHashPrefix(
51
- packages: readonly MigrationBundle[],
56
+ packages: readonly MigrationPackage[],
52
57
  prefix: string,
53
- ): Result<MigrationBundle, CliStructuredError> {
58
+ ): Result<MigrationPackage, CliStructuredError> {
54
59
  const normalizedPrefix = prefix.startsWith('sha256:') ? prefix : `sha256:${prefix}`;
55
- const matches = packages.filter((p) => p.manifest.migrationId.startsWith(normalizedPrefix));
60
+ const matches = packages.filter((p) => p.metadata.migrationHash.startsWith(normalizedPrefix));
56
61
 
57
62
  if (matches.length === 1) {
58
63
  return ok(matches[0]!);
@@ -61,13 +66,13 @@ export function resolveByHashPrefix(
61
66
  if (matches.length === 0) {
62
67
  return notOk(
63
68
  errorRuntime('No migration found matching prefix', {
64
- why: `No migration has a migrationId starting with "${normalizedPrefix}"`,
69
+ why: `No migration has a migrationHash starting with "${normalizedPrefix}"`,
65
70
  fix: 'Run `prisma-next migration show` (no argument) to see the latest migration, or check the migrations directory for available packages.',
66
71
  }),
67
72
  );
68
73
  }
69
74
 
70
- const candidates = matches.map((p) => ` ${p.dirName} ${p.manifest.migrationId}`).join('\n');
75
+ const candidates = matches.map((p) => ` ${p.dirName} ${p.metadata.migrationHash}`).join('\n');
71
76
  return notOk(
72
77
  errorRuntime('Ambiguous hash prefix', {
73
78
  why: `Multiple migrations match prefix "${normalizedPrefix}":\n${candidates}`,
@@ -110,7 +115,7 @@ async function executeMigrationShowCommand(
110
115
  ui.stderr(header);
111
116
  }
112
117
 
113
- let pkg: MigrationBundle;
118
+ let pkg: MigrationPackage;
114
119
 
115
120
  try {
116
121
  if (target && looksLikePath(target)) {
@@ -142,7 +147,7 @@ async function executeMigrationShowCommand(
142
147
  );
143
148
  }
144
149
  const leafPkg = allPackages.find(
145
- (p) => p.manifest.migrationId === latestMigration.migrationId,
150
+ (p) => p.metadata.migrationHash === latestMigration.migrationHash,
146
151
  );
147
152
  if (!leafPkg) {
148
153
  return notOk(
@@ -157,13 +162,7 @@ async function executeMigrationShowCommand(
157
162
  }
158
163
  } catch (error) {
159
164
  if (MigrationToolsError.is(error)) {
160
- return notOk(
161
- errorRuntime(error.message, {
162
- why: error.why,
163
- fix: error.fix,
164
- meta: { code: error.code, ...(error.details ?? {}) },
165
- }),
166
- );
165
+ return notOk(mapMigrationToolsError(error));
167
166
  }
168
167
  return notOk(
169
168
  errorUnexpected(error instanceof Error ? error.message : String(error), {
@@ -179,11 +178,11 @@ async function executeMigrationShowCommand(
179
178
  ok: true,
180
179
  dirName: pkg.dirName,
181
180
  dirPath: relative(process.cwd(), pkg.dirPath),
182
- from: pkg.manifest.from,
183
- to: pkg.manifest.to,
184
- migrationId: pkg.manifest.migrationId,
185
- kind: pkg.manifest.kind,
186
- createdAt: pkg.manifest.createdAt,
181
+ from: pkg.metadata.from,
182
+ to: pkg.metadata.to,
183
+ migrationHash: pkg.metadata.migrationHash,
184
+ kind: pkg.metadata.kind,
185
+ createdAt: pkg.metadata.createdAt,
187
186
  operations: ops.map((op) => ({
188
187
  id: op.id,
189
188
  label: op.label,
@@ -209,10 +208,7 @@ export function createMigrationShowCommand(): Command {
209
208
  'prisma-next migration show sha256:a1b2c3',
210
209
  ]);
211
210
  addGlobalOptions(command)
212
- .argument(
213
- '[target]',
214
- 'Migration directory path or migrationId hash prefix (defaults to latest)',
215
- )
211
+ .argument('[target]', 'Migration directory path or migrationHash prefix (defaults to latest)')
216
212
  .option('--config <path>', 'Path to prisma-next.config.ts')
217
213
  .action(async (target: string | undefined, options: MigrationShowOptions) => {
218
214
  const flags = parseGlobalFlags(options);
@@ -5,14 +5,11 @@ import {
5
5
  findPathWithDecision,
6
6
  findReachableLeaves,
7
7
  } from '@prisma-next/migration-tools/dag';
8
+ import { MigrationToolsError } from '@prisma-next/migration-tools/errors';
9
+ import type { MigrationChainEntry, MigrationGraph } from '@prisma-next/migration-tools/graph';
10
+ import type { MigrationPackage } from '@prisma-next/migration-tools/package';
8
11
  import type { Refs } from '@prisma-next/migration-tools/refs';
9
12
  import { readRefs, resolveRef } from '@prisma-next/migration-tools/refs';
10
- import type {
11
- MigrationBundle,
12
- MigrationChainEntry,
13
- MigrationGraph,
14
- } from '@prisma-next/migration-tools/types';
15
- import { MigrationToolsError } from '@prisma-next/migration-tools/types';
16
13
  import { ifDefined } from '@prisma-next/utils/defined';
17
14
  import { notOk, ok, type Result } from '@prisma-next/utils/result';
18
15
  import { cyan, dim, magenta, yellow } from 'colorette';
@@ -20,10 +17,15 @@ import { Command } from 'commander';
20
17
 
21
18
  import { loadConfig } from '../config-loader';
22
19
  import { createControlClient } from '../control-api/client';
23
- import { type CliStructuredError, errorRuntime, errorUnexpected } from '../utils/cli-errors';
20
+ import {
21
+ type CliStructuredError,
22
+ errorRuntime,
23
+ errorUnexpected,
24
+ mapMigrationToolsError,
25
+ } from '../utils/cli-errors';
24
26
  import {
25
27
  addGlobalOptions,
26
- loadAllBundles,
28
+ loadMigrationPackages,
27
29
  maskConnectionUrl,
28
30
  readContractEnvelope,
29
31
  resolveMigrationPaths,
@@ -61,7 +63,7 @@ export interface MigrationStatusEntry {
61
63
  readonly dirName: string;
62
64
  readonly from: string;
63
65
  readonly to: string;
64
- readonly migrationId: string;
66
+ readonly migrationHash: string;
65
67
  readonly operationCount: number;
66
68
  readonly operationSummary: string;
67
69
  readonly hasDestructive: boolean;
@@ -86,7 +88,7 @@ export interface MigrationStatusResult {
86
88
  readonly refName?: string;
87
89
  readonly selectedPath: readonly {
88
90
  readonly dirName: string;
89
- readonly migrationId: string;
91
+ readonly migrationHash: string;
90
92
  readonly from: string;
91
93
  readonly to: string;
92
94
  }[];
@@ -94,7 +96,7 @@ export interface MigrationStatusResult {
94
96
  readonly summary: string;
95
97
  readonly diagnostics: readonly StatusDiagnostic[];
96
98
  readonly graph?: MigrationGraph;
97
- readonly bundles?: readonly MigrationBundle[];
99
+ readonly bundles?: readonly MigrationPackage[];
98
100
  readonly edgeStatuses?: readonly EdgeStatus[];
99
101
  readonly activeRefHash?: string;
100
102
  readonly activeRefName?: string;
@@ -225,7 +227,7 @@ export function deriveEdgeStatuses(
225
227
  */
226
228
  function buildMigrationEntries(
227
229
  chain: readonly MigrationChainEntry[],
228
- packages: readonly MigrationBundle[],
230
+ packages: readonly MigrationPackage[],
229
231
  mode: 'online' | 'offline',
230
232
  markerHash: string | undefined,
231
233
  edgeStatuses?: readonly EdgeStatus[],
@@ -261,7 +263,7 @@ function buildMigrationEntries(
261
263
  dirName: migration.dirName,
262
264
  from: migration.from,
263
265
  to: migration.to,
264
- migrationId: migration.migrationId,
266
+ migrationHash: migration.migrationHash,
265
267
  operationCount: ops.length,
266
268
  operationSummary: summary,
267
269
  hasDestructive,
@@ -345,7 +347,7 @@ async function executeMigrationStatusCommand(
345
347
  ui: TerminalUI,
346
348
  ): Promise<Result<MigrationStatusResult, CliStructuredError>> {
347
349
  const config = await loadConfig(options.config);
348
- const { configPath, migrationsDir, migrationsRelative, refsPath } = resolveMigrationPaths(
350
+ const { configPath, migrationsDir, migrationsRelative, refsDir } = resolveMigrationPaths(
349
351
  options.config,
350
352
  config,
351
353
  );
@@ -357,46 +359,29 @@ async function executeMigrationStatusCommand(
357
359
  let activeRefHash: string | undefined;
358
360
  let allRefs: Refs = {};
359
361
  try {
360
- allRefs = await readRefs(refsPath);
362
+ allRefs = await readRefs(refsDir);
361
363
  } catch (error) {
362
364
  if (MigrationToolsError.is(error)) {
363
- return notOk(
364
- errorRuntime(error.message, {
365
- why: error.why,
366
- fix: error.fix,
367
- meta: { code: error.code },
368
- }),
369
- );
365
+ return notOk(mapMigrationToolsError(error));
370
366
  }
371
367
  throw error;
372
368
  }
373
369
 
374
370
  if (options.ref) {
375
371
  activeRefName = options.ref;
376
- const refHash = allRefs[activeRefName];
377
- if (refHash) {
378
- activeRefHash = refHash;
379
- } else {
380
- try {
381
- activeRefHash = resolveRef(allRefs, activeRefName);
382
- } catch (error) {
383
- if (MigrationToolsError.is(error)) {
384
- return notOk(
385
- errorRuntime(error.message, {
386
- why: error.why,
387
- fix: error.fix,
388
- meta: { code: error.code },
389
- }),
390
- );
391
- }
392
- throw error;
372
+ try {
373
+ activeRefHash = resolveRef(allRefs, activeRefName).hash;
374
+ } catch (error) {
375
+ if (MigrationToolsError.is(error)) {
376
+ return notOk(mapMigrationToolsError(error));
393
377
  }
378
+ throw error;
394
379
  }
395
380
  }
396
381
 
397
- const statusRefs: StatusRef[] = Object.entries(allRefs).map(([name, hash]) => ({
382
+ const statusRefs: StatusRef[] = Object.entries(allRefs).map(([name, entry]) => ({
398
383
  name,
399
- hash,
384
+ hash: entry.hash,
400
385
  active: name === activeRefName,
401
386
  }));
402
387
 
@@ -434,15 +419,13 @@ async function executeMigrationStatusCommand(
434
419
  });
435
420
  }
436
421
 
437
- let bundles: readonly MigrationBundle[];
422
+ let bundles: readonly MigrationPackage[];
438
423
  let graph: MigrationGraph;
439
424
  try {
440
- ({ bundles, graph } = await loadAllBundles(migrationsDir));
425
+ ({ bundles, graph } = await loadMigrationPackages(migrationsDir));
441
426
  } catch (error) {
442
427
  if (MigrationToolsError.is(error)) {
443
- return notOk(
444
- errorRuntime(error.message, { why: error.why, fix: error.fix, meta: { code: error.code } }),
445
- );
428
+ return notOk(mapMigrationToolsError(error));
446
429
  }
447
430
  return notOk(
448
431
  errorUnexpected(error instanceof Error ? error.message : String(error), {
@@ -30,6 +30,21 @@ export interface ExecuteMigrationApplyOptions<TFamilyId extends string, TTargetI
30
30
  readonly onProgress?: OnControlProgress;
31
31
  }
32
32
 
33
+ /**
34
+ * Apply a sequence of migration packages against the configured driver.
35
+ *
36
+ * Validates the path's continuity (origin → ... → destination, no gaps),
37
+ * then drives the family/target's migration runner over each package's
38
+ * operations in order, surfacing per-migration progress through `onProgress`.
39
+ *
40
+ * The `pendingMigrations` parameter is trusted input. Callers are responsible
41
+ * for upstream verification of the originating migration packages — typically
42
+ * by loading them via `readMigrationPackage` from
43
+ * `@prisma-next/migration-tools/io`, which performs hash-integrity checks at
44
+ * the load boundary. This operation does not re-verify the packages and
45
+ * assumes the `(metadata, ops)` pairs on disk have not been tampered with
46
+ * since emit.
47
+ */
33
48
  export async function executeMigrationApply<TFamilyId extends string, TTargetId extends string>(
34
49
  options: ExecuteMigrationApplyOptions<TFamilyId, TTargetId>,
35
50
  ): Promise<MigrationApplyResult> {
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Public re-export of the `init --json` success-document schema (FR1.5).
3
+ *
4
+ * Imported as `@prisma-next/cli/init-output`. The shared error envelope is
5
+ * exported separately from `@prisma-next/errors`; consumers should branch
6
+ * on the `ok` discriminator (success documents carry `ok: true`, error
7
+ * envelopes carry `ok: false`) per the
8
+ * [Style Guide § JSON Semantics](../../../../../../../docs/CLI%20Style%20Guide.md#json-semantics).
9
+ */
10
+ export { type InitOutput, InitOutputSchema } from '../commands/init/output';
@@ -41,13 +41,13 @@ import { fileURLToPath } from 'node:url';
41
41
  import { CliStructuredError, errorMigrationCliInvalidConfigArg } from '@prisma-next/errors/control';
42
42
  import { errorMigrationTargetMismatch } from '@prisma-next/errors/migration';
43
43
  import { createControlStack } from '@prisma-next/framework-components/control';
44
+ import type { MigrationMetadata } from '@prisma-next/migration-tools/metadata';
44
45
  import {
45
46
  buildMigrationArtifacts,
46
47
  isDirectEntrypoint,
47
48
  type Migration,
48
49
  printMigrationHelp,
49
50
  } from '@prisma-next/migration-tools/migration';
50
- import type { MigrationManifest } from '@prisma-next/migration-tools/types';
51
51
  import { dirname, join } from 'pathe';
52
52
  import { loadConfig } from './config-loader';
53
53
 
@@ -202,16 +202,23 @@ export class MigrationCLI {
202
202
  * `buildMigrationArtifacts` so the pure builder can preserve fields owned
203
203
  * by `migration plan` (contract bookends, hints, labels, `createdAt`)
204
204
  * across re-emits.
205
+ *
206
+ * Author-time path: this loader is non-verifying by design. Hash mismatch
207
+ * is the *expected* outcome of a re-author (the developer's source
208
+ * changes invalidate the prior hash by construction), and verification
209
+ * here would block legitimate regenerations. Apply-time consumers always
210
+ * route through the verifying `readMigrationPackage` in
211
+ * `@prisma-next/migration-tools/io` instead.
205
212
  */
206
- function readExistingManifest(manifestPath: string): Partial<MigrationManifest> | null {
213
+ function readExistingMetadata(metadataPath: string): Partial<MigrationMetadata> | null {
207
214
  let raw: string;
208
215
  try {
209
- raw = readFileSync(manifestPath, 'utf-8');
216
+ raw = readFileSync(metadataPath, 'utf-8');
210
217
  } catch {
211
218
  return null;
212
219
  }
213
220
  try {
214
- return JSON.parse(raw) as Partial<MigrationManifest>;
221
+ return JSON.parse(raw) as Partial<MigrationMetadata>;
215
222
  } catch {
216
223
  return null;
217
224
  }
@@ -236,19 +243,19 @@ function serializeMigrationToDisk(
236
243
  migrationDir: string,
237
244
  dryRun: boolean,
238
245
  ): void {
239
- const manifestPath = join(migrationDir, 'migration.json');
240
- const existing = readExistingManifest(manifestPath);
241
- const { opsJson, manifestJson } = buildMigrationArtifacts(instance, existing);
246
+ const metadataPath = join(migrationDir, 'migration.json');
247
+ const existing = readExistingMetadata(metadataPath);
248
+ const { opsJson, metadataJson } = buildMigrationArtifacts(instance, existing);
242
249
 
243
250
  if (dryRun) {
244
- process.stdout.write(`--- migration.json ---\n${manifestJson}\n`);
251
+ process.stdout.write(`--- migration.json ---\n${metadataJson}\n`);
245
252
  process.stdout.write('--- ops.json ---\n');
246
253
  process.stdout.write(`${opsJson}\n`);
247
254
  return;
248
255
  }
249
256
 
250
257
  writeFileSync(join(migrationDir, 'ops.json'), opsJson);
251
- writeFileSync(manifestPath, manifestJson);
258
+ writeFileSync(metadataPath, metadataJson);
252
259
 
253
260
  process.stdout.write(`Wrote ops.json + migration.json to ${migrationDir}\n`);
254
261
  }
@@ -3,7 +3,8 @@
3
3
  * CLI-specific errors (e.g., Commander.js argument validation) can be added here if needed.
4
4
  */
5
5
  export type { CliErrorConflict, CliErrorEnvelope } from '@prisma-next/errors/control';
6
- export {
6
+
7
+ import {
7
8
  CliStructuredError,
8
9
  errorConfigFileNotFound,
9
10
  errorConfigValidation,
@@ -20,6 +21,26 @@ export {
20
21
  errorTargetMigrationNotSupported,
21
22
  errorUnexpected,
22
23
  } from '@prisma-next/errors/control';
24
+ import { errorRuntime } from '@prisma-next/errors/execution';
25
+ import type { MigrationToolsError } from '@prisma-next/migration-tools/errors';
26
+
27
+ export {
28
+ CliStructuredError,
29
+ errorConfigFileNotFound,
30
+ errorConfigValidation,
31
+ errorContractConfigMissing,
32
+ errorContractMissingExtensionPacks,
33
+ errorContractValidationFailed,
34
+ errorDatabaseConnectionRequired,
35
+ errorDriverRequired,
36
+ errorFamilyReadMarkerSqlRequired,
37
+ errorFileNotFound,
38
+ errorMigrationCliInvalidConfigArg,
39
+ errorMigrationPlanningFailed,
40
+ errorQueryRunnerFactoryRequired,
41
+ errorTargetMigrationNotSupported,
42
+ errorUnexpected,
43
+ };
23
44
  export {
24
45
  ERROR_CODE_DESTRUCTIVE_CHANGES,
25
46
  errorDestructiveChanges,
@@ -38,3 +59,26 @@ export {
38
59
  errorUnfilledPlaceholder,
39
60
  placeholder,
40
61
  } from '@prisma-next/errors/migration';
62
+
63
+ /**
64
+ * Maps a `MigrationToolsError` raised by the migration-tools loader/graph
65
+ * surface (`readMigrationPackage`, `readMigrationsDir`, `readRefs`,
66
+ * `resolveRef`, `reconstructGraph`, ...) into a CLI `errorRuntime` envelope.
67
+ *
68
+ * The full `error.details` payload is forwarded into `meta` so machine
69
+ * consumers (`--json`) see structural fields like `dir`, `storedHash`,
70
+ * `computedHash` (for `MIGRATION.HASH_MISMATCH`) alongside the stable
71
+ * `code`. The user-visible `summary`/`why`/`fix` text is unchanged.
72
+ *
73
+ * Callers are expected to gate on `MigrationToolsError.is(error)` first
74
+ * (mirroring the original inline pattern); non-`MigrationToolsError`
75
+ * values are caller-classified (rethrow, wrap with command-specific
76
+ * `errorUnexpected`, etc.).
77
+ */
78
+ export function mapMigrationToolsError(error: MigrationToolsError): CliStructuredError {
79
+ return errorRuntime(error.message, {
80
+ why: error.why,
81
+ fix: error.fix,
82
+ meta: { code: error.code, ...(error.details ?? {}) },
83
+ });
84
+ }
@@ -3,8 +3,9 @@ import type { ControlTargetDescriptor } from '@prisma-next/framework-components/
3
3
  import { hasMigrations } from '@prisma-next/framework-components/control';
4
4
  import type { PathDecision } from '@prisma-next/migration-tools/dag';
5
5
  import { reconstructGraph } from '@prisma-next/migration-tools/dag';
6
+ import type { MigrationGraph } from '@prisma-next/migration-tools/graph';
6
7
  import { readMigrationsDir } from '@prisma-next/migration-tools/io';
7
- import type { MigrationBundle, MigrationGraph } from '@prisma-next/migration-tools/types';
8
+ import type { MigrationPackage } from '@prisma-next/migration-tools/package';
8
9
  import { ifDefined } from '@prisma-next/utils/defined';
9
10
  import type { Command } from 'commander';
10
11
  import { relative, resolve } from 'pathe';
@@ -85,7 +86,7 @@ export function resolveMigrationPaths(
85
86
  configPath: string;
86
87
  migrationsDir: string;
87
88
  migrationsRelative: string;
88
- refsPath: string;
89
+ refsDir: string;
89
90
  } {
90
91
  const configPath = configOption
91
92
  ? relative(process.cwd(), resolve(configOption))
@@ -95,8 +96,8 @@ export function resolveMigrationPaths(
95
96
  config.migrations?.dir ?? 'migrations',
96
97
  );
97
98
  const migrationsRelative = relative(process.cwd(), migrationsDir);
98
- const refsPath = resolve(migrationsDir, 'refs.json');
99
- return { configPath, migrationsDir, migrationsRelative, refsPath };
99
+ const refsDir = resolve(migrationsDir, 'refs');
100
+ return { configPath, migrationsDir, migrationsRelative, refsDir };
100
101
  }
101
102
 
102
103
  /**
@@ -111,7 +112,7 @@ export interface PathDecisionResult {
111
112
  readonly refName?: string;
112
113
  readonly selectedPath: readonly {
113
114
  readonly dirName: string;
114
- readonly migrationId: string;
115
+ readonly migrationHash: string;
115
116
  readonly from: string;
116
117
  readonly to: string;
117
118
  }[];
@@ -129,7 +130,7 @@ export function toPathDecisionResult(decision: PathDecision): PathDecisionResult
129
130
  ...ifDefined('refName', decision.refName),
130
131
  selectedPath: decision.selectedPath.map((entry) => ({
131
132
  dirName: entry.dirName,
132
- migrationId: entry.migrationId,
133
+ migrationHash: entry.migrationHash,
133
134
  from: entry.from,
134
135
  to: entry.to,
135
136
  })),
@@ -146,13 +147,13 @@ export function getTargetMigrations(target: ControlTargetDescriptor<string, stri
146
147
 
147
148
  /**
148
149
  * Reads the migrations directory and builds the migration graph from all
149
- * bundles. Throws on I/O or graph errors — callers handle error mapping.
150
+ * packages. Throws on I/O or graph errors — callers handle error mapping.
150
151
  *
151
- * Every on-disk bundle is content-addressed (`migrationId` is always a
152
+ * Every on-disk package is content-addressed (`migrationHash` is always a
152
153
  * string); there is no draft state to filter out.
153
154
  */
154
- export async function loadMigrationBundles(migrationsDir: string): Promise<{
155
- bundles: readonly MigrationBundle[];
155
+ export async function loadMigrationPackages(migrationsDir: string): Promise<{
156
+ bundles: readonly MigrationPackage[];
156
157
  graph: MigrationGraph;
157
158
  }> {
158
159
  const bundles = await readMigrationsDir(migrationsDir);
@@ -160,20 +161,6 @@ export async function loadMigrationBundles(migrationsDir: string): Promise<{
160
161
  return { bundles, graph };
161
162
  }
162
163
 
163
- export interface MigrationBundleSet {
164
- readonly bundles: readonly MigrationBundle[];
165
- readonly graph: MigrationGraph;
166
- }
167
-
168
- /**
169
- * Alias of `loadMigrationBundles` retained for naming-clarity in commands
170
- * that previously needed both attested and draft splits. With the
171
- * collapse of the draft state, both helpers do the same thing.
172
- */
173
- export async function loadAllBundles(migrationsDir: string): Promise<MigrationBundleSet> {
174
- return loadMigrationBundles(migrationsDir);
175
- }
176
-
177
164
  /**
178
165
  * The subset of the emitted contract.json that the framework layer can
179
166
  * safely type. The emitter adds these fields on top of the family-specific
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';
5
5
  import { findPath } from '@prisma-next/migration-tools/dag';
6
- import type { MigrationGraph } from '@prisma-next/migration-tools/types';
6
+ import type { MigrationGraph } from '@prisma-next/migration-tools/graph';
7
7
  import { ifDefined } from '@prisma-next/utils/defined';
8
8
 
9
9
  import type { StatusRef } from '../migration-types';
@@ -183,7 +183,7 @@ interface MigrationShowResult {
183
183
  readonly dirPath: string;
184
184
  readonly from: string;
185
185
  readonly to: string;
186
- readonly migrationId: string;
186
+ readonly migrationHash: string;
187
187
  readonly kind: string;
188
188
  readonly createdAt: string;
189
189
  readonly operations: readonly {
@@ -211,7 +211,7 @@ export function formatMigrationShowOutput(result: MigrationShowResult, flags: Gl
211
211
  lines.push(`${formatDimText(` kind: ${result.kind}`)}`);
212
212
  lines.push(`${formatDimText(` from: ${result.from}`)}`);
213
213
  lines.push(`${formatDimText(` to: ${result.to}`)}`);
214
- lines.push(`${formatDimText(` migrationId: ${result.migrationId}`)}`);
214
+ lines.push(`${formatDimText(` migrationHash: ${result.migrationHash}`)}`);
215
215
  lines.push(`${formatDimText(` created: ${result.createdAt}`)}`);
216
216
 
217
217
  lines.push('');
@@ -1,5 +0,0 @@
1
- import { CliStructuredError as CliStructuredError$1, errorConfigValidation as errorConfigValidation$1, errorContractConfigMissing as errorContractConfigMissing$1, errorContractValidationFailed, errorDatabaseConnectionRequired, errorDriverRequired, errorFileNotFound, errorMigrationPlanningFailed, errorTargetMigrationNotSupported, errorUnexpected as errorUnexpected$1 } from "@prisma-next/errors/control";
2
- import { ERROR_CODE_DESTRUCTIVE_CHANGES, errorDestructiveChanges, errorHashMismatch, errorMarkerMissing, errorRunnerFailed, errorRuntime as errorRuntime$1, errorTargetMismatch } from "@prisma-next/errors/execution";
3
- import "@prisma-next/errors/migration";
4
-
5
- export { errorUnexpected$1 as _, errorContractValidationFailed as a, errorDriverRequired as c, errorMarkerMissing as d, errorMigrationPlanningFailed as f, errorTargetMismatch as g, errorTargetMigrationNotSupported as h, errorContractConfigMissing$1 as i, errorFileNotFound as l, errorRuntime$1 as m, ERROR_CODE_DESTRUCTIVE_CHANGES as n, errorDatabaseConnectionRequired as o, errorRunnerFailed as p, errorConfigValidation$1 as r, errorDestructiveChanges as s, CliStructuredError$1 as t, errorHashMismatch as u };