@prisma-next/cli 0.4.1 → 0.4.3

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 (170) hide show
  1. package/README.md +56 -26
  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-DDeVsP2Y.d.mts +5 -0
  7. package/dist/cli.mjs +131 -15
  8. package/dist/cli.mjs.map +1 -1
  9. package/dist/{client-DGKrciLM.mjs → client-1JqqkiC7.mjs} +45 -20
  10. package/dist/client-1JqqkiC7.mjs.map +1 -0
  11. package/dist/commands/contract-emit.d.mts.map +1 -1
  12. package/dist/commands/contract-emit.mjs +7 -2
  13. package/dist/commands/contract-infer.d.mts.map +1 -1
  14. package/dist/commands/contract-infer.mjs +8 -2
  15. package/dist/commands/db-init.d.mts.map +1 -1
  16. package/dist/commands/db-init.mjs +11 -9
  17. package/dist/commands/db-init.mjs.map +1 -1
  18. package/dist/commands/db-schema.mjs +8 -5
  19. package/dist/commands/db-schema.mjs.map +1 -1
  20. package/dist/commands/db-sign.mjs +8 -7
  21. package/dist/commands/db-sign.mjs.map +1 -1
  22. package/dist/commands/db-update.mjs +10 -9
  23. package/dist/commands/db-update.mjs.map +1 -1
  24. package/dist/commands/db-verify.mjs +10 -9
  25. package/dist/commands/db-verify.mjs.map +1 -1
  26. package/dist/commands/migration-apply.d.mts +5 -2
  27. package/dist/commands/migration-apply.d.mts.map +1 -1
  28. package/dist/commands/migration-apply.mjs +57 -57
  29. package/dist/commands/migration-apply.mjs.map +1 -1
  30. package/dist/commands/migration-new.d.mts.map +1 -1
  31. package/dist/commands/migration-new.mjs +26 -32
  32. package/dist/commands/migration-new.mjs.map +1 -1
  33. package/dist/commands/migration-plan.d.mts +14 -5
  34. package/dist/commands/migration-plan.d.mts.map +1 -1
  35. package/dist/commands/migration-plan.mjs +45 -48
  36. package/dist/commands/migration-plan.mjs.map +1 -1
  37. package/dist/commands/migration-ref.d.mts +6 -4
  38. package/dist/commands/migration-ref.d.mts.map +1 -1
  39. package/dist/commands/migration-ref.mjs +31 -40
  40. package/dist/commands/migration-ref.mjs.map +1 -1
  41. package/dist/commands/migration-show.d.mts +13 -7
  42. package/dist/commands/migration-show.d.mts.map +1 -1
  43. package/dist/commands/migration-show.mjs +28 -29
  44. package/dist/commands/migration-show.mjs.map +1 -1
  45. package/dist/commands/migration-status.d.mts +23 -5
  46. package/dist/commands/migration-status.d.mts.map +1 -1
  47. package/dist/commands/migration-status.mjs +8 -3
  48. package/dist/{config-loader-_xQZsw0i.mjs → config-loader-ih8ViDb_.mjs} +2 -2
  49. package/dist/config-loader-ih8ViDb_.mjs.map +1 -0
  50. package/dist/config-loader.mjs +1 -1
  51. package/dist/contract-emit-DS5NzZh2.mjs +6 -0
  52. package/dist/contract-emit-RZBWzkop.mjs +329 -0
  53. package/dist/contract-emit-RZBWzkop.mjs.map +1 -0
  54. package/dist/contract-emit-rt_Nmdwq.mjs +150 -0
  55. package/dist/contract-emit-rt_Nmdwq.mjs.map +1 -0
  56. package/dist/{contract-enrichment-BV4KpbNW.mjs → contract-enrichment-4Ptgw3Pe.mjs} +1 -1
  57. package/dist/{contract-enrichment-BV4KpbNW.mjs.map → contract-enrichment-4Ptgw3Pe.mjs.map} +1 -1
  58. package/dist/{contract-infer-CUbiWGX0.mjs → contract-infer-Cf5J2wVg.mjs} +11 -19
  59. package/dist/contract-infer-Cf5J2wVg.mjs.map +1 -0
  60. package/dist/exports/control-api.d.mts +86 -21
  61. package/dist/exports/control-api.d.mts.map +1 -1
  62. package/dist/exports/control-api.mjs +7 -5
  63. package/dist/exports/index.mjs +8 -3
  64. package/dist/exports/index.mjs.map +1 -1
  65. package/dist/exports/init-output.d.mts +39 -0
  66. package/dist/exports/init-output.d.mts.map +1 -0
  67. package/dist/exports/init-output.mjs +3 -0
  68. package/dist/{framework-components-B__p--vT.mjs → framework-components-Bgcre3Z6.mjs} +2 -2
  69. package/dist/{framework-components-B__p--vT.mjs.map → framework-components-Bgcre3Z6.mjs.map} +1 -1
  70. package/dist/init-DAbQMxIR.mjs +2062 -0
  71. package/dist/init-DAbQMxIR.mjs.map +1 -0
  72. package/dist/{inspect-live-schema-wIYBTdL3.mjs → inspect-live-schema-LWtXfxm_.mjs} +9 -9
  73. package/dist/inspect-live-schema-LWtXfxm_.mjs.map +1 -0
  74. package/dist/migration-cli.d.mts +80 -0
  75. package/dist/migration-cli.d.mts.map +1 -0
  76. package/dist/migration-cli.mjs +408 -0
  77. package/dist/migration-cli.mjs.map +1 -0
  78. package/dist/{migration-command-scaffold-BC73xQSo.mjs → migration-command-scaffold-CU452v9h.mjs} +7 -7
  79. package/dist/{migration-command-scaffold-BC73xQSo.mjs.map → migration-command-scaffold-CU452v9h.mjs.map} +1 -1
  80. package/dist/{migration-status-CXBbScH5.mjs → migration-status-DoPrFIOQ.mjs} +119 -64
  81. package/dist/migration-status-DoPrFIOQ.mjs.map +1 -0
  82. package/dist/{migrations-DYRAjiVh.mjs → migrations-MEoKMiV5.mjs} +42 -21
  83. package/dist/migrations-MEoKMiV5.mjs.map +1 -0
  84. package/dist/output-BpcQrnnq.mjs +103 -0
  85. package/dist/output-BpcQrnnq.mjs.map +1 -0
  86. package/dist/{progress-adapter-Bwouy73-.mjs → progress-adapter-DgRGldpT.mjs} +1 -1
  87. package/dist/{progress-adapter-Bwouy73-.mjs.map → progress-adapter-DgRGldpT.mjs.map} +1 -1
  88. package/dist/quick-reference-mongo.md +34 -13
  89. package/dist/quick-reference-postgres.md +11 -9
  90. package/dist/{result-handler-CGohaH1o.mjs → result-handler-Ch6hVnOo.mjs} +36 -94
  91. package/dist/result-handler-Ch6hVnOo.mjs.map +1 -0
  92. package/dist/{terminal-ui-BuPXVRFY.mjs → terminal-ui-u2YgKghu.mjs} +76 -2
  93. package/dist/terminal-ui-u2YgKghu.mjs.map +1 -0
  94. package/dist/{verify-Cm2UFuZA.mjs → verify-BT9tgCOH.mjs} +2 -2
  95. package/dist/{verify-Cm2UFuZA.mjs.map → verify-BT9tgCOH.mjs.map} +1 -1
  96. package/package.json +27 -17
  97. package/src/cli.ts +32 -6
  98. package/src/commands/contract-emit.ts +67 -163
  99. package/src/commands/contract-infer.ts +7 -20
  100. package/src/commands/db-init.ts +1 -0
  101. package/src/commands/db-update.ts +1 -1
  102. package/src/commands/init/detect-pnpm-catalog.ts +141 -0
  103. package/src/commands/init/errors.ts +254 -0
  104. package/src/commands/init/exit-codes.ts +62 -0
  105. package/src/commands/init/hygiene-gitattributes.ts +97 -0
  106. package/src/commands/init/hygiene-gitignore.ts +48 -0
  107. package/src/commands/init/hygiene-package-scripts.ts +91 -0
  108. package/src/commands/init/index.ts +112 -7
  109. package/src/commands/init/init.ts +766 -144
  110. package/src/commands/init/inputs.ts +421 -0
  111. package/src/commands/init/output.ts +147 -0
  112. package/src/commands/init/probe-db.ts +308 -0
  113. package/src/commands/init/reinit-cleanup.ts +83 -0
  114. package/src/commands/init/templates/agent-skill-mongo.md +63 -31
  115. package/src/commands/init/templates/agent-skill-postgres.md +1 -1
  116. package/src/commands/init/templates/agent-skill.ts +25 -3
  117. package/src/commands/init/templates/code-templates.ts +125 -32
  118. package/src/commands/init/templates/env.ts +80 -0
  119. package/src/commands/init/templates/quick-reference-mongo.md +34 -13
  120. package/src/commands/init/templates/quick-reference-postgres.md +11 -9
  121. package/src/commands/init/templates/quick-reference.ts +42 -3
  122. package/src/commands/init/templates/tsconfig.ts +167 -5
  123. package/src/commands/inspect-live-schema.ts +10 -5
  124. package/src/commands/migration-apply.ts +86 -65
  125. package/src/commands/migration-new.ts +28 -34
  126. package/src/commands/migration-plan.ts +80 -56
  127. package/src/commands/migration-ref.ts +40 -54
  128. package/src/commands/migration-show.ts +53 -36
  129. package/src/commands/migration-status.ts +202 -71
  130. package/src/config-path-validation.ts +0 -1
  131. package/src/control-api/client.ts +21 -0
  132. package/src/control-api/operations/contract-emit.ts +198 -115
  133. package/src/control-api/operations/db-init.ts +10 -6
  134. package/src/control-api/operations/db-update.ts +10 -6
  135. package/src/control-api/operations/migration-apply.ts +30 -9
  136. package/src/control-api/types.ts +69 -7
  137. package/src/exports/control-api.ts +2 -1
  138. package/src/exports/init-output.ts +10 -0
  139. package/src/migration-cli.ts +577 -0
  140. package/src/utils/cli-errors.ts +50 -2
  141. package/src/utils/command-helpers.ts +48 -26
  142. package/src/utils/emit-queue.ts +26 -0
  143. package/src/utils/formatters/graph-migration-mapper.ts +7 -3
  144. package/src/utils/formatters/migrations.ts +62 -26
  145. package/src/utils/publish-contract-artifact-pair.ts +134 -0
  146. package/dist/cli-errors-CznZA5-d.mjs +0 -5
  147. package/dist/cli-errors-z37sV3eR.d.mts +0 -4
  148. package/dist/client-DGKrciLM.mjs.map +0 -1
  149. package/dist/config-loader-_xQZsw0i.mjs.map +0 -1
  150. package/dist/contract-emit-304WZtZJ.mjs +0 -4
  151. package/dist/contract-emit-DgeWdonT.mjs +0 -122
  152. package/dist/contract-emit-DgeWdonT.mjs.map +0 -1
  153. package/dist/contract-emit-mU1_B_m9.mjs +0 -195
  154. package/dist/contract-emit-mU1_B_m9.mjs.map +0 -1
  155. package/dist/contract-infer-CUbiWGX0.mjs.map +0 -1
  156. package/dist/extract-operation-statements-DWWFz1PK.mjs +0 -13
  157. package/dist/extract-operation-statements-DWWFz1PK.mjs.map +0 -1
  158. package/dist/extract-sql-ddl-7zn_AFS8.mjs +0 -26
  159. package/dist/extract-sql-ddl-7zn_AFS8.mjs.map +0 -1
  160. package/dist/init-DRquYpPa.mjs +0 -430
  161. package/dist/init-DRquYpPa.mjs.map +0 -1
  162. package/dist/inspect-live-schema-wIYBTdL3.mjs.map +0 -1
  163. package/dist/migration-status-CXBbScH5.mjs.map +0 -1
  164. package/dist/migrations-DYRAjiVh.mjs.map +0 -1
  165. package/dist/result-handler-CGohaH1o.mjs.map +0 -1
  166. package/dist/terminal-ui-BuPXVRFY.mjs.map +0 -1
  167. package/dist/validate-contract-deps-DZqv9m7H.mjs +0 -37
  168. package/dist/validate-contract-deps-DZqv9m7H.mjs.map +0 -1
  169. package/src/control-api/operations/extract-operation-statements.ts +0 -14
  170. package/src/control-api/operations/extract-sql-ddl.ts +0 -47
@@ -1,14 +1,25 @@
1
- import type { MigrationPlanOperation } from '@prisma-next/framework-components/control';
2
- import { findLatestMigration, reconstructGraph } from '@prisma-next/migration-tools/dag';
1
+ import type {
2
+ MigrationPlanOperation,
3
+ OperationPreview,
4
+ } from '@prisma-next/framework-components/control';
5
+ import { MigrationToolsError } from '@prisma-next/migration-tools/errors';
3
6
  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';
7
+ import {
8
+ findLatestMigration,
9
+ reconstructGraph,
10
+ } from '@prisma-next/migration-tools/migration-graph';
11
+ import type { MigrationPackage } from '@prisma-next/migration-tools/package';
6
12
  import { notOk, ok, type Result } from '@prisma-next/utils/result';
7
13
  import { Command } from 'commander';
8
14
  import { relative, resolve } from 'pathe';
9
15
  import { loadConfig } from '../config-loader';
10
- import { extractOperationStatements } from '../control-api/operations/extract-operation-statements';
11
- import { type CliStructuredError, errorRuntime, errorUnexpected } from '../utils/cli-errors';
16
+ import { createControlClient } from '../control-api/client';
17
+ import {
18
+ type CliStructuredError,
19
+ errorRuntime,
20
+ errorUnexpected,
21
+ mapMigrationToolsError,
22
+ } from '../utils/cli-errors';
12
23
  import {
13
24
  addGlobalOptions,
14
25
  setCommandDescriptions,
@@ -29,17 +40,22 @@ export interface MigrationShowResult {
29
40
  readonly ok: true;
30
41
  readonly dirName: string;
31
42
  readonly dirPath: string;
32
- readonly from: string;
43
+ readonly from: string | null;
33
44
  readonly to: string;
34
- readonly migrationId: string;
35
- readonly kind: string;
45
+ readonly migrationHash: string;
36
46
  readonly createdAt: string;
37
47
  readonly operations: readonly {
38
48
  readonly id: string;
39
49
  readonly label: string;
40
50
  readonly operationClass: string;
41
51
  }[];
42
- readonly sql: readonly string[];
52
+ /**
53
+ * Family-agnostic textual preview of the migration's operations. Replaces
54
+ * the previous string-array DDL field. Always defined; statements is empty
55
+ * for a no-op migration or a family that does not implement the
56
+ * `OperationPreviewCapable` capability.
57
+ */
58
+ readonly preview: OperationPreview;
43
59
  readonly summary: string;
44
60
  }
45
61
 
@@ -48,11 +64,11 @@ function looksLikePath(target: string): boolean {
48
64
  }
49
65
 
50
66
  export function resolveByHashPrefix(
51
- packages: readonly MigrationBundle[],
67
+ packages: readonly MigrationPackage[],
52
68
  prefix: string,
53
- ): Result<MigrationBundle, CliStructuredError> {
69
+ ): Result<MigrationPackage, CliStructuredError> {
54
70
  const normalizedPrefix = prefix.startsWith('sha256:') ? prefix : `sha256:${prefix}`;
55
- const matches = packages.filter((p) => p.manifest.migrationId.startsWith(normalizedPrefix));
71
+ const matches = packages.filter((p) => p.metadata.migrationHash.startsWith(normalizedPrefix));
56
72
 
57
73
  if (matches.length === 1) {
58
74
  return ok(matches[0]!);
@@ -61,13 +77,13 @@ export function resolveByHashPrefix(
61
77
  if (matches.length === 0) {
62
78
  return notOk(
63
79
  errorRuntime('No migration found matching prefix', {
64
- why: `No migration has a migrationId starting with "${normalizedPrefix}"`,
80
+ why: `No migration has a migrationHash starting with "${normalizedPrefix}"`,
65
81
  fix: 'Run `prisma-next migration show` (no argument) to see the latest migration, or check the migrations directory for available packages.',
66
82
  }),
67
83
  );
68
84
  }
69
85
 
70
- const candidates = matches.map((p) => ` ${p.dirName} ${p.manifest.migrationId}`).join('\n');
86
+ const candidates = matches.map((p) => ` ${p.dirName} ${p.metadata.migrationHash}`).join('\n');
71
87
  return notOk(
72
88
  errorRuntime('Ambiguous hash prefix', {
73
89
  why: `Multiple migrations match prefix "${normalizedPrefix}":\n${candidates}`,
@@ -110,7 +126,7 @@ async function executeMigrationShowCommand(
110
126
  ui.stderr(header);
111
127
  }
112
128
 
113
- let pkg: MigrationBundle;
129
+ let pkg: MigrationPackage;
114
130
 
115
131
  try {
116
132
  if (target && looksLikePath(target)) {
@@ -142,7 +158,7 @@ async function executeMigrationShowCommand(
142
158
  );
143
159
  }
144
160
  const leafPkg = allPackages.find(
145
- (p) => p.manifest.migrationId === latestMigration.migrationId,
161
+ (p) => p.metadata.migrationHash === latestMigration.migrationHash,
146
162
  );
147
163
  if (!leafPkg) {
148
164
  return notOk(
@@ -157,13 +173,7 @@ async function executeMigrationShowCommand(
157
173
  }
158
174
  } catch (error) {
159
175
  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
- );
176
+ return notOk(mapMigrationToolsError(error));
167
177
  }
168
178
  return notOk(
169
179
  errorUnexpected(error instanceof Error ? error.message : String(error), {
@@ -173,23 +183,33 @@ async function executeMigrationShowCommand(
173
183
  }
174
184
 
175
185
  const ops = pkg.ops as readonly MigrationPlanOperation[];
176
- const sql = extractOperationStatements(config.family.familyId, ops) ?? [];
186
+
187
+ // `migration show` is an offline command; the control client is constructed
188
+ // purely to dispatch the family-specific `toOperationPreview` capability and
189
+ // is not connected to a database.
190
+ const client = createControlClient({
191
+ family: config.family,
192
+ target: config.target,
193
+ adapter: config.adapter,
194
+ ...(config.driver ? { driver: config.driver } : {}),
195
+ extensionPacks: config.extensionPacks ?? [],
196
+ });
197
+ const preview: OperationPreview = client.toOperationPreview(ops) ?? { statements: [] };
177
198
 
178
199
  const result: MigrationShowResult = {
179
200
  ok: true,
180
201
  dirName: pkg.dirName,
181
202
  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,
203
+ from: pkg.metadata.from,
204
+ to: pkg.metadata.to,
205
+ migrationHash: pkg.metadata.migrationHash,
206
+ createdAt: pkg.metadata.createdAt,
187
207
  operations: ops.map((op) => ({
188
208
  id: op.id,
189
209
  label: op.label,
190
210
  operationClass: op.operationClass,
191
211
  })),
192
- sql,
212
+ preview,
193
213
  summary: `${ops.length} operation(s)`,
194
214
  };
195
215
  return ok(result);
@@ -200,7 +220,7 @@ export function createMigrationShowCommand(): Command {
200
220
  setCommandDescriptions(
201
221
  command,
202
222
  'Display migration package contents',
203
- 'Shows the operations, DDL preview, and metadata for a migration package.\n' +
223
+ 'Shows the operations, statement preview, and metadata for a migration package.\n' +
204
224
  'Accepts a directory path, a hash prefix (git-style), or defaults to the\n' +
205
225
  'latest migration.',
206
226
  );
@@ -209,10 +229,7 @@ export function createMigrationShowCommand(): Command {
209
229
  'prisma-next migration show sha256:a1b2c3',
210
230
  ]);
211
231
  addGlobalOptions(command)
212
- .argument(
213
- '[target]',
214
- 'Migration directory path or migrationId hash prefix (defaults to latest)',
215
- )
232
+ .argument('[target]', 'Migration directory path or migrationHash prefix (defaults to latest)')
216
233
  .option('--config <path>', 'Path to prisma-next.config.ts')
217
234
  .action(async (target: string | undefined, options: MigrationShowOptions) => {
218
235
  const flags = parseGlobalFlags(options);