@prisma-next/cli 0.5.0-dev.3 → 0.5.0-dev.4

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 (41) hide show
  1. package/dist/cli.mjs +4 -4
  2. package/dist/commands/contract-emit.mjs +1 -1
  3. package/dist/commands/contract-infer.mjs +1 -1
  4. package/dist/commands/db-init.mjs +3 -3
  5. package/dist/commands/db-schema.mjs +3 -3
  6. package/dist/commands/db-sign.mjs +2 -2
  7. package/dist/commands/db-update.mjs +3 -3
  8. package/dist/commands/db-verify.mjs +2 -2
  9. package/dist/commands/migration-apply.mjs +4 -4
  10. package/dist/commands/migration-apply.mjs.map +1 -1
  11. package/dist/commands/migration-new.mjs +1 -1
  12. package/dist/commands/migration-plan.mjs +1 -1
  13. package/dist/commands/migration-ref.d.mts +5 -3
  14. package/dist/commands/migration-ref.d.mts.map +1 -1
  15. package/dist/commands/migration-ref.mjs +26 -31
  16. package/dist/commands/migration-ref.mjs.map +1 -1
  17. package/dist/commands/migration-show.mjs +2 -2
  18. package/dist/commands/migration-status.d.mts.map +1 -1
  19. package/dist/commands/migration-status.mjs +1 -1
  20. package/dist/{contract-emit-CNYyzJwF.mjs → contract-emit-DpPjuFy-.mjs} +2 -2
  21. package/dist/{contract-emit-CNYyzJwF.mjs.map → contract-emit-DpPjuFy-.mjs.map} +1 -1
  22. package/dist/{contract-infer-BP3DrGgz.mjs → contract-infer-BS4kIX9c.mjs} +3 -3
  23. package/dist/{contract-infer-BP3DrGgz.mjs.map → contract-infer-BS4kIX9c.mjs.map} +1 -1
  24. package/dist/exports/index.mjs +1 -1
  25. package/dist/{inspect-live-schema-DWzf4Q_m.mjs → inspect-live-schema-BsoFVoS1.mjs} +2 -2
  26. package/dist/{inspect-live-schema-DWzf4Q_m.mjs.map → inspect-live-schema-BsoFVoS1.mjs.map} +1 -1
  27. package/dist/{migration-command-scaffold-CLMD302g.mjs → migration-command-scaffold-DOXnheFa.mjs} +2 -2
  28. package/dist/{migration-command-scaffold-CLMD302g.mjs.map → migration-command-scaffold-DOXnheFa.mjs.map} +1 -1
  29. package/dist/{migration-status-B0HLF7So.mjs → migration-status-Ry3TnEya.mjs} +8 -10
  30. package/dist/{migration-status-B0HLF7So.mjs.map → migration-status-Ry3TnEya.mjs.map} +1 -1
  31. package/dist/{migrations-B0dOQlk0.mjs → migrations-fU0xoKjS.mjs} +2 -2
  32. package/dist/{migrations-B0dOQlk0.mjs.map → migrations-fU0xoKjS.mjs.map} +1 -1
  33. package/dist/{result-handler-CIyu0Pdt.mjs → result-handler-BJwA7ufw.mjs} +2 -2
  34. package/dist/{result-handler-CIyu0Pdt.mjs.map → result-handler-BJwA7ufw.mjs.map} +1 -1
  35. package/dist/{verify-BxiVp50b.mjs → verify-bl__PkXk.mjs} +2 -2
  36. package/dist/{verify-BxiVp50b.mjs.map → verify-bl__PkXk.mjs.map} +1 -1
  37. package/package.json +15 -15
  38. package/src/commands/migration-apply.ts +3 -3
  39. package/src/commands/migration-ref.ts +32 -47
  40. package/src/commands/migration-status.ts +16 -21
  41. package/src/utils/command-helpers.ts +3 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma-next/cli",
3
- "version": "0.5.0-dev.3",
3
+ "version": "0.5.0-dev.4",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -24,28 +24,28 @@
24
24
  "string-width": "^8.2.0",
25
25
  "strip-ansi": "^7.1.2",
26
26
  "wrap-ansi": "^10.0.0",
27
- "@prisma-next/config": "0.5.0-dev.3",
28
- "@prisma-next/contract": "0.5.0-dev.3",
29
- "@prisma-next/emitter": "0.5.0-dev.3",
30
- "@prisma-next/framework-components": "0.5.0-dev.3",
31
- "@prisma-next/psl-printer": "0.5.0-dev.3",
32
- "@prisma-next/migration-tools": "0.5.0-dev.3",
33
- "@prisma-next/errors": "0.5.0-dev.3",
34
- "@prisma-next/utils": "0.5.0-dev.3"
27
+ "@prisma-next/config": "0.5.0-dev.4",
28
+ "@prisma-next/contract": "0.5.0-dev.4",
29
+ "@prisma-next/emitter": "0.5.0-dev.4",
30
+ "@prisma-next/errors": "0.5.0-dev.4",
31
+ "@prisma-next/psl-printer": "0.5.0-dev.4",
32
+ "@prisma-next/migration-tools": "0.5.0-dev.4",
33
+ "@prisma-next/framework-components": "0.5.0-dev.4",
34
+ "@prisma-next/utils": "0.5.0-dev.4"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "24.10.4",
38
38
  "tsdown": "0.18.4",
39
39
  "typescript": "5.9.3",
40
40
  "vitest": "4.0.17",
41
- "@prisma-next/sql-contract": "0.5.0-dev.3",
42
- "@prisma-next/sql-contract-emitter": "0.5.0-dev.3",
43
- "@prisma-next/sql-runtime": "0.5.0-dev.3",
41
+ "@prisma-next/sql-contract": "0.5.0-dev.4",
42
+ "@prisma-next/sql-contract-emitter": "0.5.0-dev.4",
43
+ "@prisma-next/sql-contract-ts": "0.5.0-dev.4",
44
+ "@prisma-next/sql-operations": "0.5.0-dev.4",
44
45
  "@prisma-next/test-utils": "0.0.1",
46
+ "@prisma-next/sql-runtime": "0.5.0-dev.4",
45
47
  "@prisma-next/tsconfig": "0.0.0",
46
- "@prisma-next/sql-contract-ts": "0.5.0-dev.3",
47
- "@prisma-next/tsdown": "0.0.0",
48
- "@prisma-next/sql-operations": "0.5.0-dev.3"
48
+ "@prisma-next/tsdown": "0.0.0"
49
49
  },
50
50
  "exports": {
51
51
  ".": {
@@ -112,7 +112,7 @@ async function executeMigrationApplyCommand(
112
112
  startTime: number,
113
113
  ): Promise<Result<MigrationApplyResult, CliStructuredErrorType>> {
114
114
  const config = await loadConfig(options.config);
115
- const { configPath, migrationsDir, migrationsRelative, refsPath } = resolveMigrationPaths(
115
+ const { configPath, migrationsDir, migrationsRelative, refsDir } = resolveMigrationPaths(
116
116
  options.config,
117
117
  config,
118
118
  );
@@ -149,8 +149,8 @@ async function executeMigrationApplyCommand(
149
149
  if (options.ref) {
150
150
  refName = options.ref;
151
151
  try {
152
- const refs = await readRefs(refsPath);
153
- destinationHash = resolveRef(refs, refName);
152
+ const refs = await readRefs(refsDir);
153
+ destinationHash = resolveRef(refs, refName).hash;
154
154
  } catch (error) {
155
155
  if (MigrationToolsError.is(error)) {
156
156
  return notOk(mapMigrationToolsError(error));
@@ -1,17 +1,22 @@
1
+ import type { RefEntry } from '@prisma-next/migration-tools/refs';
1
2
  import {
3
+ deleteRef,
4
+ readRef,
2
5
  readRefs,
3
- resolveRef,
4
6
  validateRefName,
5
7
  validateRefValue,
6
- writeRefs,
8
+ writeRef,
7
9
  } from '@prisma-next/migration-tools/refs';
8
10
  import { MigrationToolsError } from '@prisma-next/migration-tools/types';
9
11
  import { notOk, ok, type Result } from '@prisma-next/utils/result';
10
12
  import { Command } from 'commander';
11
- import { resolve } from 'pathe';
12
13
  import { loadConfig } from '../config-loader';
13
14
  import { CliStructuredError, errorRuntime, errorUnexpected } from '../utils/cli-errors';
14
- import { addGlobalOptions, setCommandDescriptions } from '../utils/command-helpers';
15
+ import {
16
+ addGlobalOptions,
17
+ resolveMigrationPaths,
18
+ setCommandDescriptions,
19
+ } from '../utils/command-helpers';
15
20
  import { formatCommandHelp } from '../utils/formatters/help';
16
21
  import { parseGlobalFlags } from '../utils/global-flags';
17
22
  import { handleResult } from '../utils/result-handler';
@@ -21,12 +26,14 @@ interface RefSetResult {
21
26
  readonly ok: true;
22
27
  readonly ref: string;
23
28
  readonly hash: string;
29
+ readonly invariants: readonly string[];
24
30
  }
25
31
 
26
32
  interface RefGetResult {
27
33
  readonly ok: true;
28
34
  readonly ref: string;
29
35
  readonly hash: string;
36
+ readonly invariants: readonly string[];
30
37
  }
31
38
 
32
39
  interface RefDeleteResult {
@@ -37,12 +44,7 @@ interface RefDeleteResult {
37
44
 
38
45
  interface RefListResult {
39
46
  readonly ok: true;
40
- readonly refs: Record<string, string>;
41
- }
42
-
43
- function resolveRefsPath(configPath?: string, config?: { migrations?: { dir?: string } }): string {
44
- const base = configPath ? resolve(configPath, '..') : process.cwd();
45
- return resolve(base, config?.migrations?.dir ?? 'migrations', 'refs.json');
47
+ readonly refs: Record<string, RefEntry>;
46
48
  }
47
49
 
48
50
  function mapError(error: unknown): CliStructuredError {
@@ -70,13 +72,6 @@ function cliErrorInvalidRefValue(hash: string): CliStructuredError {
70
72
  });
71
73
  }
72
74
 
73
- function errorRefNotFound(name: string): CliStructuredError {
74
- return errorRuntime(`Ref "${name}" does not exist`, {
75
- why: `No ref named "${name}" found in refs.json`,
76
- fix: `Run \`prisma-next migration ref list\` to see available refs, or \`prisma-next migration ref set ${name} <hash>\` to create it`,
77
- });
78
- }
79
-
80
75
  async function executeRefSetCommand(
81
76
  name: string,
82
77
  hash: string,
@@ -91,11 +86,10 @@ async function executeRefSetCommand(
91
86
 
92
87
  try {
93
88
  const config = await loadConfig(options.config);
94
- const refsPath = resolveRefsPath(options.config, config);
95
- const refs = await readRefs(refsPath);
96
- const updated = { ...refs, [name]: hash };
97
- await writeRefs(refsPath, updated);
98
- return ok({ ok: true as const, ref: name, hash });
89
+ const { refsDir } = resolveMigrationPaths(options.config, config);
90
+ const entry: RefEntry = { hash, invariants: [] };
91
+ await writeRef(refsDir, name, entry);
92
+ return ok({ ok: true as const, ref: name, hash, invariants: [] });
99
93
  } catch (error) {
100
94
  if (error instanceof CliStructuredError) return notOk(error);
101
95
  return notOk(mapError(error));
@@ -108,10 +102,9 @@ async function executeRefGetCommand(
108
102
  ): Promise<Result<RefGetResult, CliStructuredError>> {
109
103
  try {
110
104
  const config = await loadConfig(options.config);
111
- const refsPath = resolveRefsPath(options.config, config);
112
- const refs = await readRefs(refsPath);
113
- const hash = resolveRef(refs, name);
114
- return ok({ ok: true as const, ref: name, hash });
105
+ const { refsDir } = resolveMigrationPaths(options.config, config);
106
+ const entry = await readRef(refsDir, name);
107
+ return ok({ ok: true as const, ref: name, hash: entry.hash, invariants: entry.invariants });
115
108
  } catch (error) {
116
109
  if (error instanceof CliStructuredError) return notOk(error);
117
110
  return notOk(mapError(error));
@@ -124,13 +117,8 @@ async function executeRefDeleteCommand(
124
117
  ): Promise<Result<RefDeleteResult, CliStructuredError>> {
125
118
  try {
126
119
  const config = await loadConfig(options.config);
127
- const refsPath = resolveRefsPath(options.config, config);
128
- const refs = await readRefs(refsPath);
129
- if (!Object.hasOwn(refs, name)) {
130
- return notOk(errorRefNotFound(name));
131
- }
132
- const { [name]: _, ...remaining } = refs;
133
- await writeRefs(refsPath, remaining);
120
+ const { refsDir } = resolveMigrationPaths(options.config, config);
121
+ await deleteRef(refsDir, name);
134
122
  return ok({ ok: true as const, ref: name, deleted: true as const });
135
123
  } catch (error) {
136
124
  if (error instanceof CliStructuredError) return notOk(error);
@@ -143,8 +131,8 @@ async function executeRefListCommand(options: {
143
131
  }): Promise<Result<RefListResult, CliStructuredError>> {
144
132
  try {
145
133
  const config = await loadConfig(options.config);
146
- const refsPath = resolveRefsPath(options.config, config);
147
- const refs = await readRefs(refsPath);
134
+ const { refsDir } = resolveMigrationPaths(options.config, config);
135
+ const refs = await readRefs(refsDir);
148
136
  return ok({ ok: true as const, refs });
149
137
  } catch (error) {
150
138
  if (error instanceof CliStructuredError) return notOk(error);
@@ -157,7 +145,7 @@ function createRefSetCommand(): Command {
157
145
  setCommandDescriptions(
158
146
  command,
159
147
  'Set a ref to a contract hash',
160
- 'Sets a named ref to point to a contract hash in migrations/refs.json.',
148
+ 'Sets a named ref to point to a contract hash in migrations/refs/.',
161
149
  );
162
150
  addGlobalOptions(command)
163
151
  .argument('<name>', 'Ref name (e.g., staging, production)')
@@ -190,7 +178,7 @@ function createRefGetCommand(): Command {
190
178
  setCommandDescriptions(
191
179
  command,
192
180
  'Get the hash for a ref',
193
- 'Reads a named ref from migrations/refs.json and prints its contract hash.',
181
+ 'Reads a named ref from migrations/refs/ and prints its contract hash.',
194
182
  );
195
183
  addGlobalOptions(command)
196
184
  .argument('<name>', 'Ref name to look up')
@@ -218,7 +206,7 @@ function createRefGetCommand(): Command {
218
206
 
219
207
  function createRefDeleteCommand(): Command {
220
208
  const command = new Command('delete');
221
- setCommandDescriptions(command, 'Delete a ref', 'Removes a named ref from migrations/refs.json.');
209
+ setCommandDescriptions(command, 'Delete a ref', 'Removes a named ref from migrations/refs/.');
222
210
  addGlobalOptions(command)
223
211
  .argument('<name>', 'Ref name to delete')
224
212
  .option('--config <path>', 'Path to prisma-next.config.ts')
@@ -245,11 +233,7 @@ function createRefDeleteCommand(): Command {
245
233
 
246
234
  function createRefListCommand(): Command {
247
235
  const command = new Command('list');
248
- setCommandDescriptions(
249
- command,
250
- 'List all refs',
251
- 'Lists all named refs from migrations/refs.json.',
252
- );
236
+ setCommandDescriptions(command, 'List all refs', 'Lists all named refs from migrations/refs/.');
253
237
  addGlobalOptions(command)
254
238
  .option('--config <path>', 'Path to prisma-next.config.ts')
255
239
  .action(async (options: { config?: string; json?: string | boolean; quiet?: boolean }) => {
@@ -264,8 +248,10 @@ function createRefListCommand(): Command {
264
248
  if (entries.length === 0) {
265
249
  ui.output('No refs defined');
266
250
  } else {
267
- for (const [refName, hash] of entries) {
268
- ui.output(`${refName} ${hash}`);
251
+ for (const [refName, entry] of entries) {
252
+ const invariantsSuffix =
253
+ entry.invariants.length > 0 ? ` [invariants: ${entry.invariants.join(', ')}]` : '';
254
+ ui.output(`${refName} → ${entry.hash}${invariantsSuffix}`);
269
255
  }
270
256
  }
271
257
  }
@@ -282,7 +268,6 @@ export {
282
268
  executeRefListCommand,
283
269
  cliErrorInvalidRefName,
284
270
  cliErrorInvalidRefValue,
285
- errorRefNotFound,
286
271
  };
287
272
 
288
273
  export function createMigrationRefCommand(): Command {
@@ -290,7 +275,7 @@ export function createMigrationRefCommand(): Command {
290
275
  setCommandDescriptions(
291
276
  command,
292
277
  'Manage migration refs',
293
- 'Manage named refs in migrations/refs.json. Refs map logical environment\n' +
278
+ 'Manage named refs in migrations/refs/. Refs map logical environment\n' +
294
279
  'names (e.g., staging, production) to contract hashes.',
295
280
  );
296
281
  addGlobalOptions(command).configureHelp({
@@ -345,7 +345,7 @@ async function executeMigrationStatusCommand(
345
345
  ui: TerminalUI,
346
346
  ): Promise<Result<MigrationStatusResult, CliStructuredError>> {
347
347
  const config = await loadConfig(options.config);
348
- const { configPath, migrationsDir, migrationsRelative, refsPath } = resolveMigrationPaths(
348
+ const { configPath, migrationsDir, migrationsRelative, refsDir } = resolveMigrationPaths(
349
349
  options.config,
350
350
  config,
351
351
  );
@@ -357,7 +357,7 @@ async function executeMigrationStatusCommand(
357
357
  let activeRefHash: string | undefined;
358
358
  let allRefs: Refs = {};
359
359
  try {
360
- allRefs = await readRefs(refsPath);
360
+ allRefs = await readRefs(refsDir);
361
361
  } catch (error) {
362
362
  if (MigrationToolsError.is(error)) {
363
363
  return notOk(
@@ -373,30 +373,25 @@ async function executeMigrationStatusCommand(
373
373
 
374
374
  if (options.ref) {
375
375
  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;
376
+ try {
377
+ activeRefHash = resolveRef(allRefs, activeRefName).hash;
378
+ } catch (error) {
379
+ if (MigrationToolsError.is(error)) {
380
+ return notOk(
381
+ errorRuntime(error.message, {
382
+ why: error.why,
383
+ fix: error.fix,
384
+ meta: { code: error.code },
385
+ }),
386
+ );
393
387
  }
388
+ throw error;
394
389
  }
395
390
  }
396
391
 
397
- const statusRefs: StatusRef[] = Object.entries(allRefs).map(([name, hash]) => ({
392
+ const statusRefs: StatusRef[] = Object.entries(allRefs).map(([name, entry]) => ({
398
393
  name,
399
- hash,
394
+ hash: entry.hash,
400
395
  active: name === activeRefName,
401
396
  }));
402
397
 
@@ -85,7 +85,7 @@ export function resolveMigrationPaths(
85
85
  configPath: string;
86
86
  migrationsDir: string;
87
87
  migrationsRelative: string;
88
- refsPath: string;
88
+ refsDir: string;
89
89
  } {
90
90
  const configPath = configOption
91
91
  ? relative(process.cwd(), resolve(configOption))
@@ -95,8 +95,8 @@ export function resolveMigrationPaths(
95
95
  config.migrations?.dir ?? 'migrations',
96
96
  );
97
97
  const migrationsRelative = relative(process.cwd(), migrationsDir);
98
- const refsPath = resolve(migrationsDir, 'refs.json');
99
- return { configPath, migrationsDir, migrationsRelative, refsPath };
98
+ const refsDir = resolve(migrationsDir, 'refs');
99
+ return { configPath, migrationsDir, migrationsRelative, refsDir };
100
100
  }
101
101
 
102
102
  /**