@prisma-next/cli 0.5.0-dev.9 → 0.5.1

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 (185) hide show
  1. package/README.md +61 -26
  2. package/dist/cli-errors-B9OBbled.d.mts +3 -0
  3. package/dist/cli-errors-D3_sMh2K.mjs +33 -0
  4. package/dist/cli-errors-D3_sMh2K.mjs.map +1 -0
  5. package/dist/cli.mjs +16 -78
  6. package/dist/cli.mjs.map +1 -1
  7. package/dist/client-BCnP7cHo.mjs +1485 -0
  8. package/dist/client-BCnP7cHo.mjs.map +1 -0
  9. package/dist/{result-handler-Ba3zWQsI.mjs → command-helpers-BeZHkxV8.mjs} +70 -47
  10. package/dist/command-helpers-BeZHkxV8.mjs.map +1 -0
  11. package/dist/commands/contract-emit.d.mts.map +1 -1
  12. package/dist/commands/contract-emit.mjs +2 -4
  13. package/dist/commands/contract-infer.d.mts.map +1 -1
  14. package/dist/commands/contract-infer.mjs +2 -4
  15. package/dist/commands/db-init.d.mts.map +1 -1
  16. package/dist/commands/db-init.mjs +16 -13
  17. package/dist/commands/db-init.mjs.map +1 -1
  18. package/dist/commands/db-schema.d.mts.map +1 -1
  19. package/dist/commands/db-schema.mjs +6 -7
  20. package/dist/commands/db-schema.mjs.map +1 -1
  21. package/dist/commands/db-sign.d.mts.map +1 -1
  22. package/dist/commands/db-sign.mjs +9 -9
  23. package/dist/commands/db-sign.mjs.map +1 -1
  24. package/dist/commands/db-update.d.mts.map +1 -1
  25. package/dist/commands/db-update.mjs +15 -13
  26. package/dist/commands/db-update.mjs.map +1 -1
  27. package/dist/commands/db-verify.d.mts.map +1 -1
  28. package/dist/commands/db-verify.mjs +1 -321
  29. package/dist/commands/migration-apply.d.mts +28 -13
  30. package/dist/commands/migration-apply.d.mts.map +1 -1
  31. package/dist/commands/migration-apply.mjs +55 -151
  32. package/dist/commands/migration-apply.mjs.map +1 -1
  33. package/dist/commands/migration-new.d.mts +0 -1
  34. package/dist/commands/migration-new.d.mts.map +1 -1
  35. package/dist/commands/migration-new.mjs +34 -40
  36. package/dist/commands/migration-new.mjs.map +1 -1
  37. package/dist/commands/migration-plan.d.mts +33 -6
  38. package/dist/commands/migration-plan.d.mts.map +1 -1
  39. package/dist/commands/migration-plan.mjs +2 -348
  40. package/dist/commands/migration-ref.d.mts +1 -1
  41. package/dist/commands/migration-ref.d.mts.map +1 -1
  42. package/dist/commands/migration-ref.mjs +8 -12
  43. package/dist/commands/migration-ref.mjs.map +1 -1
  44. package/dist/commands/migration-show.d.mts +64 -10
  45. package/dist/commands/migration-show.d.mts.map +1 -1
  46. package/dist/commands/migration-show.mjs +166 -60
  47. package/dist/commands/migration-show.mjs.map +1 -1
  48. package/dist/commands/migration-status.d.mts +126 -5
  49. package/dist/commands/migration-status.d.mts.map +1 -1
  50. package/dist/commands/migration-status.mjs +2 -4
  51. package/dist/{config-loader-C25b63rJ.mjs → config-loader-B6sJjXTv.mjs} +3 -5
  52. package/dist/config-loader-B6sJjXTv.mjs.map +1 -0
  53. package/dist/config-loader.d.mts +0 -1
  54. package/dist/config-loader.d.mts.map +1 -1
  55. package/dist/config-loader.mjs +2 -3
  56. package/dist/contract-emit-9DBda5Ou.mjs +150 -0
  57. package/dist/contract-emit-9DBda5Ou.mjs.map +1 -0
  58. package/dist/contract-emit-B77TsJqf.mjs +327 -0
  59. package/dist/contract-emit-B77TsJqf.mjs.map +1 -0
  60. package/dist/{contract-enrichment-CAOELa-H.mjs → contract-enrichment-Dani0mMW.mjs} +4 -6
  61. package/dist/contract-enrichment-Dani0mMW.mjs.map +1 -0
  62. package/dist/{contract-infer-D9cC3rJm.mjs → contract-infer-ByxhPjpW.mjs} +13 -22
  63. package/dist/contract-infer-ByxhPjpW.mjs.map +1 -0
  64. package/dist/contract-space-aggregate-loader-BrwKK6Q6.mjs +160 -0
  65. package/dist/contract-space-aggregate-loader-BrwKK6Q6.mjs.map +1 -0
  66. package/dist/db-verify-Czm5T-J4.mjs +404 -0
  67. package/dist/db-verify-Czm5T-J4.mjs.map +1 -0
  68. package/dist/exports/config-types.mjs +1 -2
  69. package/dist/exports/control-api.d.mts +101 -586
  70. package/dist/exports/control-api.d.mts.map +1 -1
  71. package/dist/exports/control-api.mjs +4 -6
  72. package/dist/exports/index.d.mts.map +1 -1
  73. package/dist/exports/index.mjs +28 -30
  74. package/dist/exports/index.mjs.map +1 -1
  75. package/dist/exports/init-output.d.mts +2 -4
  76. package/dist/exports/init-output.d.mts.map +1 -1
  77. package/dist/exports/init-output.mjs +2 -3
  78. package/dist/{framework-components-Cr--XBKy.mjs → framework-components-ChqVUxR-.mjs} +3 -4
  79. package/dist/{framework-components-Cr--XBKy.mjs.map → framework-components-ChqVUxR-.mjs.map} +1 -1
  80. package/dist/global-flags-Icqpxk23.d.mts +12 -0
  81. package/dist/global-flags-Icqpxk23.d.mts.map +1 -0
  82. package/dist/helpers-eqdN8tH6.mjs +25 -0
  83. package/dist/helpers-eqdN8tH6.mjs.map +1 -0
  84. package/dist/{init-C5220SY9.mjs → init-DETSgw3h.mjs} +40 -49
  85. package/dist/init-DETSgw3h.mjs.map +1 -0
  86. package/dist/{inspect-live-schema-yrHAvG71.mjs → inspect-live-schema-DxdBd4Er.mjs} +10 -11
  87. package/dist/inspect-live-schema-DxdBd4Er.mjs.map +1 -0
  88. package/dist/migration-cli.d.mts +41 -12
  89. package/dist/migration-cli.d.mts.map +1 -1
  90. package/dist/migration-cli.mjs +309 -86
  91. package/dist/migration-cli.mjs.map +1 -1
  92. package/dist/{migration-command-scaffold-B3B09et6.mjs → migration-command-scaffold-BdV8JYXV.mjs} +8 -9
  93. package/dist/migration-command-scaffold-BdV8JYXV.mjs.map +1 -0
  94. package/dist/migration-plan-mRu5K81L.mjs +494 -0
  95. package/dist/migration-plan-mRu5K81L.mjs.map +1 -0
  96. package/dist/{migration-status-DUMiH8_G.mjs → migration-status-By9G5p2H.mjs} +270 -65
  97. package/dist/migration-status-By9G5p2H.mjs.map +1 -0
  98. package/dist/migrations-CTsyBXCA.mjs +229 -0
  99. package/dist/migrations-CTsyBXCA.mjs.map +1 -0
  100. package/dist/{output-BpcQrnnq.mjs → output-B16Kefzx.mjs} +9 -3
  101. package/dist/output-B16Kefzx.mjs.map +1 -0
  102. package/dist/{progress-adapter-DvQWB1nK.mjs → progress-adapter-DFfvZcYL.mjs} +2 -2
  103. package/dist/{progress-adapter-DvQWB1nK.mjs.map → progress-adapter-DFfvZcYL.mjs.map} +1 -1
  104. package/dist/result-handler-rmPVKIP2.mjs +25 -0
  105. package/dist/result-handler-rmPVKIP2.mjs.map +1 -0
  106. package/dist/rolldown-runtime-twds-ZHy.mjs +14 -0
  107. package/dist/{terminal-ui-C3ZLwQxK.mjs → terminal-ui-C_hFNbAn.mjs} +4 -28
  108. package/dist/terminal-ui-C_hFNbAn.mjs.map +1 -0
  109. package/dist/types-LItU7E4l.d.mts +856 -0
  110. package/dist/types-LItU7E4l.d.mts.map +1 -0
  111. package/dist/{verify-Bkycc-Tf.mjs → verify-CiwNWM9N.mjs} +3 -4
  112. package/dist/verify-CiwNWM9N.mjs.map +1 -0
  113. package/package.json +28 -26
  114. package/src/cli.ts +32 -6
  115. package/src/commands/contract-emit.ts +67 -163
  116. package/src/commands/contract-infer.ts +7 -20
  117. package/src/commands/db-init.ts +15 -3
  118. package/src/commands/db-update.ts +9 -4
  119. package/src/commands/db-verify.ts +47 -15
  120. package/src/commands/init/index.ts +1 -1
  121. package/src/commands/init/init.ts +2 -2
  122. package/src/commands/init/templates/code-templates.ts +26 -18
  123. package/src/commands/inspect-live-schema.ts +10 -5
  124. package/src/commands/migration-apply.ts +114 -212
  125. package/src/commands/migration-new.ts +42 -45
  126. package/src/commands/migration-plan.ts +213 -75
  127. package/src/commands/migration-ref.ts +8 -7
  128. package/src/commands/migration-show.ts +274 -70
  129. package/src/commands/migration-status.ts +491 -64
  130. package/src/config-path-validation.ts +0 -1
  131. package/src/control-api/client.ts +85 -5
  132. package/src/control-api/contract-enrichment.ts +6 -4
  133. package/src/control-api/operations/apply-aggregate.ts +290 -0
  134. package/src/control-api/operations/contract-emit.ts +198 -115
  135. package/src/control-api/operations/db-apply-aggregate.ts +399 -0
  136. package/src/control-api/operations/db-init.ts +51 -253
  137. package/src/control-api/operations/db-update.ts +66 -183
  138. package/src/control-api/operations/db-verify.ts +342 -0
  139. package/src/control-api/operations/migration-apply.ts +430 -131
  140. package/src/control-api/types.ts +278 -29
  141. package/src/exports/control-api.ts +15 -3
  142. package/src/load-ts-contract.ts +28 -26
  143. package/src/migration-cli.ts +445 -122
  144. package/src/utils/cli-errors.ts +49 -2
  145. package/src/utils/combine-schema-results.ts +84 -0
  146. package/src/utils/command-helpers.ts +69 -25
  147. package/src/utils/contract-space-aggregate-loader.ts +177 -0
  148. package/src/utils/contract-space-seed-phase.ts +201 -0
  149. package/src/utils/emit-queue.ts +26 -0
  150. package/src/utils/extension-pack-inputs.ts +162 -0
  151. package/src/utils/formatters/graph-migration-mapper.ts +7 -3
  152. package/src/utils/formatters/migrations.ts +255 -77
  153. package/src/utils/publish-contract-artifact-pair.ts +134 -0
  154. package/dist/cli-errors-BFYgBH3L.d.mts +0 -4
  155. package/dist/cli-errors-Cd79vmTH.mjs +0 -5
  156. package/dist/client-CrsnY58k.mjs +0 -997
  157. package/dist/client-CrsnY58k.mjs.map +0 -1
  158. package/dist/commands/db-verify.mjs.map +0 -1
  159. package/dist/commands/migration-plan.mjs.map +0 -1
  160. package/dist/config-loader-C25b63rJ.mjs.map +0 -1
  161. package/dist/contract-emit--feXyNd7.mjs +0 -4
  162. package/dist/contract-emit-NJ01hiiv.mjs +0 -195
  163. package/dist/contract-emit-NJ01hiiv.mjs.map +0 -1
  164. package/dist/contract-emit-V5SSitUT.mjs +0 -122
  165. package/dist/contract-emit-V5SSitUT.mjs.map +0 -1
  166. package/dist/contract-enrichment-CAOELa-H.mjs.map +0 -1
  167. package/dist/contract-infer-D9cC3rJm.mjs.map +0 -1
  168. package/dist/extract-operation-statements-DsFfxXVZ.mjs +0 -13
  169. package/dist/extract-operation-statements-DsFfxXVZ.mjs.map +0 -1
  170. package/dist/extract-sql-ddl-D9UbZDyz.mjs +0 -26
  171. package/dist/extract-sql-ddl-D9UbZDyz.mjs.map +0 -1
  172. package/dist/init-C5220SY9.mjs.map +0 -1
  173. package/dist/inspect-live-schema-yrHAvG71.mjs.map +0 -1
  174. package/dist/migration-command-scaffold-B3B09et6.mjs.map +0 -1
  175. package/dist/migration-status-DUMiH8_G.mjs.map +0 -1
  176. package/dist/migrations-Bo5WtTla.mjs +0 -153
  177. package/dist/migrations-Bo5WtTla.mjs.map +0 -1
  178. package/dist/output-BpcQrnnq.mjs.map +0 -1
  179. package/dist/result-handler-Ba3zWQsI.mjs.map +0 -1
  180. package/dist/terminal-ui-C3ZLwQxK.mjs.map +0 -1
  181. package/dist/validate-contract-deps-B_Cs29TL.mjs +0 -37
  182. package/dist/validate-contract-deps-B_Cs29TL.mjs.map +0 -1
  183. package/dist/verify-Bkycc-Tf.mjs.map +0 -1
  184. package/src/control-api/operations/extract-operation-statements.ts +0 -14
  185. package/src/control-api/operations/extract-sql-ddl.ts +0 -47
@@ -11,32 +11,36 @@
11
11
  import { readFileSync } from 'node:fs';
12
12
  import type { Contract } from '@prisma-next/contract/types';
13
13
  import { getEmittedArtifactPaths } from '@prisma-next/emitter';
14
- import { createControlStack } from '@prisma-next/framework-components/control';
15
- import { computeMigrationId } from '@prisma-next/migration-tools/attestation';
16
- import { EMPTY_CONTRACT_HASH } from '@prisma-next/migration-tools/constants';
17
- import { findLatestMigration, reconstructGraph } from '@prisma-next/migration-tools/dag';
14
+ import { APP_SPACE_ID, createControlStack } from '@prisma-next/framework-components/control';
15
+ import { MigrationToolsError } from '@prisma-next/migration-tools/errors';
16
+ import { computeMigrationHash } from '@prisma-next/migration-tools/hash';
18
17
  import {
19
18
  copyFilesWithRename,
20
19
  formatMigrationDirName,
21
20
  readMigrationsDir,
22
21
  writeMigrationPackage,
23
22
  } from '@prisma-next/migration-tools/io';
23
+ import type { MigrationMetadata } from '@prisma-next/migration-tools/metadata';
24
+ import {
25
+ findLatestMigration,
26
+ reconstructGraph,
27
+ } from '@prisma-next/migration-tools/migration-graph';
24
28
  import { writeMigrationTs } from '@prisma-next/migration-tools/migration-ts';
25
- import type { MigrationManifest } from '@prisma-next/migration-tools/types';
26
- import { MigrationToolsError } from '@prisma-next/migration-tools/types';
27
29
  import { notOk, ok, type Result } from '@prisma-next/utils/result';
28
30
  import { Command } from 'commander';
29
- import { join, relative, resolve } from 'pathe';
31
+ import { join, relative } from 'pathe';
30
32
  import { loadConfig } from '../config-loader';
31
33
  import {
32
34
  CliStructuredError,
33
35
  errorRuntime,
34
36
  errorTargetMigrationNotSupported,
35
37
  errorUnexpected,
38
+ mapMigrationToolsError,
36
39
  } from '../utils/cli-errors';
37
40
  import {
38
41
  addGlobalOptions,
39
42
  getTargetMigrations,
43
+ resolveContractPath,
40
44
  resolveMigrationPaths,
41
45
  setCommandDescriptions,
42
46
  setCommandExamples,
@@ -57,7 +61,7 @@ interface MigrationNewOptions extends CommonCommandOptions {
57
61
  interface MigrationNewResult {
58
62
  readonly ok: true;
59
63
  readonly dir: string;
60
- readonly from: string;
64
+ readonly from: string | null;
61
65
  readonly to: string;
62
66
  readonly summary: string;
63
67
  }
@@ -66,13 +70,9 @@ async function executeMigrationNewCommand(
66
70
  options: MigrationNewOptions,
67
71
  ): Promise<Result<MigrationNewResult, CliStructuredError>> {
68
72
  const config = await loadConfig(options.config);
69
- const { migrationsDir, migrationsRelative } = resolveMigrationPaths(options.config, config);
73
+ const { appMigrationsDir, appMigrationsRelative } = resolveMigrationPaths(options.config, config);
70
74
 
71
- const contractPath = config.contract?.output ?? 'contract.json';
72
- const contractPathAbsolute = resolve(
73
- options.config ? resolve(options.config, '..') : process.cwd(),
74
- contractPath,
75
- );
75
+ const contractPathAbsolute = resolveContractPath(config);
76
76
 
77
77
  let contractJsonContent: string;
78
78
  try {
@@ -116,37 +116,37 @@ async function executeMigrationNewCommand(
116
116
  }
117
117
 
118
118
  let fromContract: Contract | null = null;
119
- let fromHash: string = EMPTY_CONTRACT_HASH;
119
+ let fromHash: string | null = null;
120
120
  let fromContractSourceDir: string | null = null;
121
121
 
122
122
  try {
123
- const packages = await readMigrationsDir(migrationsDir);
123
+ const packages = await readMigrationsDir(appMigrationsDir);
124
124
 
125
125
  if (packages.length > 0) {
126
126
  const graph = reconstructGraph(packages);
127
127
 
128
128
  if (options.from) {
129
- const match = packages.find((p) => p.manifest.to.startsWith(options.from!));
129
+ const match = packages.find((p) => p.metadata.to.startsWith(options.from!));
130
130
  if (!match) {
131
131
  return notOk(
132
132
  errorRuntime('Starting contract not found', {
133
- why: `No migration with to hash matching "${options.from}" exists in ${migrationsRelative}`,
133
+ why: `No migration with to hash matching "${options.from}" exists in ${appMigrationsRelative}`,
134
134
  fix: 'Check that the --from hash matches a known migration target hash.',
135
135
  }),
136
136
  );
137
137
  }
138
- fromHash = match.manifest.to;
139
- fromContract = match.manifest.toContract;
138
+ fromHash = match.metadata.to;
139
+ fromContract = match.metadata.toContract;
140
140
  fromContractSourceDir = match.dirPath;
141
141
  } else {
142
142
  const latestMigration = findLatestMigration(graph);
143
143
  if (latestMigration) {
144
144
  fromHash = latestMigration.to;
145
145
  const leafPkg = packages.find(
146
- (p) => p.manifest.migrationId === latestMigration.migrationId,
146
+ (p) => p.metadata.migrationHash === latestMigration.migrationHash,
147
147
  );
148
148
  if (leafPkg) {
149
- fromContract = leafPkg.manifest.toContract;
149
+ fromContract = leafPkg.metadata.toContract;
150
150
  fromContractSourceDir = leafPkg.dirPath;
151
151
  }
152
152
  }
@@ -154,22 +154,16 @@ async function executeMigrationNewCommand(
154
154
  }
155
155
  } catch (error) {
156
156
  if (MigrationToolsError.is(error)) {
157
- return notOk(
158
- errorRuntime(error.message, {
159
- why: error.why,
160
- fix: error.fix,
161
- meta: { code: error.code },
162
- }),
163
- );
157
+ return notOk(mapMigrationToolsError(error));
164
158
  }
165
159
  throw error;
166
160
  }
167
161
 
168
- if (fromHash === toStorageHash) {
162
+ if (fromHash === toStorageHash && !options.from) {
169
163
  return notOk(
170
164
  errorRuntime('No changes detected', {
171
165
  why: 'The from and to contract hashes are identical — there is nothing to migrate.',
172
- fix: 'Change the contract and run `prisma-next contract emit` before creating a new migration.',
166
+ fix: 'Change the contract and run `prisma-next contract emit` before creating a new migration. To author a data-only migration on the current contract hash, pass `--from <hash>` explicitly.',
173
167
  }),
174
168
  );
175
169
  }
@@ -177,16 +171,15 @@ async function executeMigrationNewCommand(
177
171
  const timestamp = new Date();
178
172
  const slug = options.name ?? 'migration';
179
173
  const dirName = formatMigrationDirName(timestamp, slug);
180
- const packageDir = join(migrationsDir, dirName);
174
+ const packageDir = join(appMigrationsDir, dirName);
181
175
 
182
176
  // `migration new` scaffolds an empty `migration.ts` for the user to
183
177
  // fill, so we attest over `ops: []`. Re-running self-emit after the
184
- // user adds operations will produce a different `migrationId` (over
178
+ // user adds operations will produce a different `migrationHash` (over
185
179
  // the real ops). This is intentional — there is no on-disk draft.
186
- const baseManifest: Omit<MigrationManifest, 'migrationId'> = {
180
+ const baseMetadata: Omit<MigrationMetadata, 'migrationHash'> = {
187
181
  from: fromHash,
188
182
  to: toStorageHash,
189
- kind: 'regular',
190
183
  fromContract,
191
184
  toContract: toContractJson,
192
185
  hints: {
@@ -195,11 +188,12 @@ async function executeMigrationNewCommand(
195
188
  plannerVersion: '1.0.0',
196
189
  },
197
190
  labels: [],
191
+ providedInvariants: [],
198
192
  createdAt: timestamp.toISOString(),
199
193
  };
200
- const manifest: MigrationManifest = {
201
- ...baseManifest,
202
- migrationId: computeMigrationId(baseManifest, []),
194
+ const metadata: MigrationMetadata = {
195
+ ...baseMetadata,
196
+ migrationHash: computeMigrationHash(baseMetadata, []),
203
197
  };
204
198
 
205
199
  const migrations = getTargetMigrations(config.target);
@@ -218,7 +212,7 @@ async function executeMigrationNewCommand(
218
212
  ...(config.extensionPacks ?? []),
219
213
  ]);
220
214
 
221
- await writeMigrationPackage(packageDir, manifest, []);
215
+ await writeMigrationPackage(packageDir, metadata, []);
222
216
  const destinationArtifacts = getEmittedArtifactPaths(contractPathAbsolute);
223
217
  await copyFilesWithRename(packageDir, [
224
218
  { sourcePath: destinationArtifacts.jsonPath, destName: 'end-contract.json' },
@@ -237,12 +231,15 @@ async function executeMigrationNewCommand(
237
231
  const stack = createControlStack(config);
238
232
  const familyInstance = config.family.create(stack);
239
233
  const planner = migrations.createPlanner(familyInstance);
240
- const emptyPlan = planner.emptyMigration({
241
- packageDir,
242
- contractJsonPath: join(packageDir, 'end-contract.json'),
243
- fromHash,
244
- toHash: toStorageHash,
245
- });
234
+ const emptyPlan = planner.emptyMigration(
235
+ {
236
+ packageDir,
237
+ contractJsonPath: join(packageDir, 'end-contract.json'),
238
+ fromHash,
239
+ toHash: toStorageHash,
240
+ },
241
+ APP_SPACE_ID,
242
+ );
246
243
  await writeMigrationTs(packageDir, emptyPlan.renderTypeScript());
247
244
 
248
245
  return ok({