@prisma-next/cli 0.3.0-dev.34 → 0.3.0-dev.36

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 (130) hide show
  1. package/README.md +14 -13
  2. package/dist/cli.d.mts +1 -0
  3. package/dist/cli.js +1 -2910
  4. package/dist/cli.mjs +169 -0
  5. package/dist/cli.mjs.map +1 -0
  6. package/dist/client-Lm9Q6aQM.mjs +694 -0
  7. package/dist/client-Lm9Q6aQM.mjs.map +1 -0
  8. package/dist/commands/contract-emit.d.mts +7 -0
  9. package/dist/commands/contract-emit.d.mts.map +1 -0
  10. package/dist/commands/contract-emit.mjs +140 -0
  11. package/dist/commands/contract-emit.mjs.map +1 -0
  12. package/dist/commands/db-init.d.mts +7 -0
  13. package/dist/commands/db-init.d.mts.map +1 -0
  14. package/dist/commands/db-init.mjs +179 -0
  15. package/dist/commands/db-init.mjs.map +1 -0
  16. package/dist/commands/db-introspect.d.mts +7 -0
  17. package/dist/commands/db-introspect.d.mts.map +1 -0
  18. package/dist/commands/db-introspect.mjs +120 -0
  19. package/dist/commands/db-introspect.mjs.map +1 -0
  20. package/dist/commands/db-schema-verify.d.mts +7 -0
  21. package/dist/commands/db-schema-verify.d.mts.map +1 -0
  22. package/dist/commands/db-schema-verify.mjs +116 -0
  23. package/dist/commands/db-schema-verify.mjs.map +1 -0
  24. package/dist/commands/db-sign.d.mts +7 -0
  25. package/dist/commands/db-sign.d.mts.map +1 -0
  26. package/dist/commands/db-sign.mjs +138 -0
  27. package/dist/commands/db-sign.mjs.map +1 -0
  28. package/dist/commands/db-verify.d.mts +7 -0
  29. package/dist/commands/db-verify.d.mts.map +1 -0
  30. package/dist/commands/db-verify.mjs +129 -0
  31. package/dist/commands/db-verify.mjs.map +1 -0
  32. package/dist/config-loader-CnnWuluc.mjs +42 -0
  33. package/dist/config-loader-CnnWuluc.mjs.map +1 -0
  34. package/dist/{config-loader.d.ts → config-loader.d.mts} +8 -3
  35. package/dist/config-loader.d.mts.map +1 -0
  36. package/dist/config-loader.mjs +3 -0
  37. package/dist/exports/config-types.d.mts +2 -0
  38. package/dist/exports/config-types.mjs +3 -0
  39. package/dist/exports/control-api.d.mts +451 -0
  40. package/dist/exports/control-api.d.mts.map +1 -0
  41. package/dist/exports/control-api.mjs +59 -0
  42. package/dist/exports/control-api.mjs.map +1 -0
  43. package/dist/{load-ts-contract.d.ts → exports/index.d.mts} +10 -5
  44. package/dist/exports/index.d.mts.map +1 -0
  45. package/dist/exports/index.mjs +132 -0
  46. package/dist/exports/index.mjs.map +1 -0
  47. package/dist/result-handler-BZPY7HX4.mjs +1029 -0
  48. package/dist/result-handler-BZPY7HX4.mjs.map +1 -0
  49. package/package.json +41 -34
  50. package/src/commands/contract-emit.ts +13 -5
  51. package/src/commands/db-init.ts +13 -18
  52. package/src/commands/db-verify.ts +3 -2
  53. package/src/control-api/client.ts +4 -2
  54. package/src/control-api/operations/contract-emit.ts +103 -0
  55. package/src/control-api/operations/db-init.ts +6 -6
  56. package/src/control-api/types.ts +44 -12
  57. package/src/exports/control-api.ts +5 -0
  58. package/src/load-ts-contract.ts +16 -11
  59. package/src/utils/output.ts +16 -10
  60. package/dist/chunk-AGOTG4L3.js +0 -965
  61. package/dist/chunk-AGOTG4L3.js.map +0 -1
  62. package/dist/chunk-HLLI4YL7.js +0 -180
  63. package/dist/chunk-HLLI4YL7.js.map +0 -1
  64. package/dist/chunk-HWYQOCAJ.js +0 -47
  65. package/dist/chunk-HWYQOCAJ.js.map +0 -1
  66. package/dist/chunk-VG2R7DGF.js +0 -735
  67. package/dist/chunk-VG2R7DGF.js.map +0 -1
  68. package/dist/cli.d.ts +0 -2
  69. package/dist/cli.d.ts.map +0 -1
  70. package/dist/cli.js.map +0 -1
  71. package/dist/commands/contract-emit.d.ts +0 -3
  72. package/dist/commands/contract-emit.d.ts.map +0 -1
  73. package/dist/commands/contract-emit.js +0 -10
  74. package/dist/commands/contract-emit.js.map +0 -1
  75. package/dist/commands/db-init.d.ts +0 -3
  76. package/dist/commands/db-init.d.ts.map +0 -1
  77. package/dist/commands/db-init.js +0 -257
  78. package/dist/commands/db-init.js.map +0 -1
  79. package/dist/commands/db-introspect.d.ts +0 -3
  80. package/dist/commands/db-introspect.d.ts.map +0 -1
  81. package/dist/commands/db-introspect.js +0 -155
  82. package/dist/commands/db-introspect.js.map +0 -1
  83. package/dist/commands/db-schema-verify.d.ts +0 -3
  84. package/dist/commands/db-schema-verify.d.ts.map +0 -1
  85. package/dist/commands/db-schema-verify.js +0 -171
  86. package/dist/commands/db-schema-verify.js.map +0 -1
  87. package/dist/commands/db-sign.d.ts +0 -3
  88. package/dist/commands/db-sign.d.ts.map +0 -1
  89. package/dist/commands/db-sign.js +0 -195
  90. package/dist/commands/db-sign.js.map +0 -1
  91. package/dist/commands/db-verify.d.ts +0 -3
  92. package/dist/commands/db-verify.d.ts.map +0 -1
  93. package/dist/commands/db-verify.js +0 -193
  94. package/dist/commands/db-verify.js.map +0 -1
  95. package/dist/config-loader.d.ts.map +0 -1
  96. package/dist/config-loader.js +0 -7
  97. package/dist/config-loader.js.map +0 -1
  98. package/dist/control-api/client.d.ts +0 -13
  99. package/dist/control-api/client.d.ts.map +0 -1
  100. package/dist/control-api/operations/db-init.d.ts +0 -29
  101. package/dist/control-api/operations/db-init.d.ts.map +0 -1
  102. package/dist/control-api/types.d.ts +0 -387
  103. package/dist/control-api/types.d.ts.map +0 -1
  104. package/dist/exports/config-types.d.ts +0 -3
  105. package/dist/exports/config-types.d.ts.map +0 -1
  106. package/dist/exports/config-types.js +0 -6
  107. package/dist/exports/config-types.js.map +0 -1
  108. package/dist/exports/control-api.d.ts +0 -13
  109. package/dist/exports/control-api.d.ts.map +0 -1
  110. package/dist/exports/control-api.js +0 -7
  111. package/dist/exports/control-api.js.map +0 -1
  112. package/dist/exports/index.d.ts +0 -4
  113. package/dist/exports/index.d.ts.map +0 -1
  114. package/dist/exports/index.js +0 -176
  115. package/dist/exports/index.js.map +0 -1
  116. package/dist/load-ts-contract.d.ts.map +0 -1
  117. package/dist/utils/cli-errors.d.ts +0 -7
  118. package/dist/utils/cli-errors.d.ts.map +0 -1
  119. package/dist/utils/command-helpers.d.ts +0 -12
  120. package/dist/utils/command-helpers.d.ts.map +0 -1
  121. package/dist/utils/framework-components.d.ts +0 -70
  122. package/dist/utils/framework-components.d.ts.map +0 -1
  123. package/dist/utils/global-flags.d.ts +0 -25
  124. package/dist/utils/global-flags.d.ts.map +0 -1
  125. package/dist/utils/output.d.ts +0 -142
  126. package/dist/utils/output.d.ts.map +0 -1
  127. package/dist/utils/progress-adapter.d.ts +0 -26
  128. package/dist/utils/progress-adapter.d.ts.map +0 -1
  129. package/dist/utils/result-handler.d.ts +0 -15
  130. package/dist/utils/result-handler.d.ts.map +0 -1
@@ -119,7 +119,7 @@ export async function executeDbInit<TFamilyId extends string, TTargetId extends
119
119
  const existingMarker = await familyInstance.readMarker({ driver });
120
120
  if (existingMarker) {
121
121
  const markerMatchesDestination =
122
- existingMarker.coreHash === migrationPlan.destination.coreHash &&
122
+ existingMarker.storageHash === migrationPlan.destination.storageHash &&
123
123
  (!migrationPlan.destination.profileHash ||
124
124
  existingMarker.profileHash === migrationPlan.destination.profileHash);
125
125
 
@@ -138,7 +138,7 @@ export async function executeDbInit<TFamilyId extends string, TTargetId extends
138
138
  ? {
139
139
  execution: { operationsPlanned: 0, operationsExecuted: 0 },
140
140
  marker: {
141
- coreHash: existingMarker.coreHash,
141
+ storageHash: existingMarker.storageHash,
142
142
  profileHash: existingMarker.profileHash,
143
143
  },
144
144
  }
@@ -159,11 +159,11 @@ export async function executeDbInit<TFamilyId extends string, TTargetId extends
159
159
  code: 'MARKER_ORIGIN_MISMATCH' as const,
160
160
  summary: 'Existing contract marker does not match plan destination',
161
161
  marker: {
162
- coreHash: existingMarker.coreHash,
162
+ storageHash: existingMarker.storageHash,
163
163
  profileHash: existingMarker.profileHash,
164
164
  },
165
165
  destination: {
166
- coreHash: migrationPlan.destination.coreHash,
166
+ storageHash: migrationPlan.destination.storageHash,
167
167
  profileHash: migrationPlan.destination.profileHash,
168
168
  },
169
169
  why: undefined,
@@ -271,10 +271,10 @@ export async function executeDbInit<TFamilyId extends string, TTargetId extends
271
271
  },
272
272
  marker: migrationPlan.destination.profileHash
273
273
  ? {
274
- coreHash: migrationPlan.destination.coreHash,
274
+ storageHash: migrationPlan.destination.storageHash,
275
275
  profileHash: migrationPlan.destination.profileHash,
276
276
  }
277
- : { coreHash: migrationPlan.destination.coreHash },
277
+ : { storageHash: migrationPlan.destination.storageHash },
278
278
  summary: `Applied ${execution.operationsExecuted} operation(s), marker written`,
279
279
  };
280
280
  return ok(result);
@@ -236,14 +236,9 @@ export interface EmitContractConfig {
236
236
  readonly source: EmitContractSource;
237
237
  /**
238
238
  * Output path for contract.json.
239
- * Should be an absolute or relative path.
239
+ * The .d.ts types file will be colocated (e.g., contract.json contract.d.ts).
240
240
  */
241
241
  readonly output: string;
242
- /**
243
- * Output path for contract.d.ts.
244
- * Should be an absolute or relative path.
245
- */
246
- readonly types: string;
247
242
  }
248
243
 
249
244
  /**
@@ -279,7 +274,7 @@ export interface DbInitSuccess {
279
274
  readonly operationsExecuted: number;
280
275
  };
281
276
  readonly marker?: {
282
- readonly coreHash: string;
277
+ readonly storageHash: string;
283
278
  readonly profileHash?: string;
284
279
  };
285
280
  readonly summary: string;
@@ -300,11 +295,11 @@ export interface DbInitFailure {
300
295
  readonly conflicts: ReadonlyArray<MigrationPlannerConflict> | undefined;
301
296
  readonly meta: Record<string, unknown> | undefined;
302
297
  readonly marker?: {
303
- readonly coreHash?: string;
298
+ readonly storageHash?: string;
304
299
  readonly profileHash?: string;
305
300
  };
306
301
  readonly destination?: {
307
- readonly coreHash: string;
302
+ readonly storageHash: string;
308
303
  readonly profileHash?: string | undefined;
309
304
  };
310
305
  }
@@ -320,8 +315,10 @@ export type DbInitResult = Result<DbInitSuccess, DbInitFailure>;
320
315
  * Contains the hashes and paths of emitted files.
321
316
  */
322
317
  export interface EmitSuccess {
323
- /** Core hash of the emitted contract */
324
- readonly coreHash: string;
318
+ /** Storage hash of the emitted contract */
319
+ readonly storageHash: string;
320
+ /** Execution hash of the emitted contract (if execution section exists) */
321
+ readonly executionHash?: string;
325
322
  /** Profile hash of the emitted contract (target-specific) */
326
323
  readonly profileHash: string;
327
324
  /** The emitted contract as JSON string */
@@ -351,6 +348,41 @@ export interface EmitFailure {
351
348
  */
352
349
  export type EmitResult = Result<EmitSuccess, EmitFailure>;
353
350
 
351
+ // ============================================================================
352
+ // Standalone Contract Emit Types
353
+ // ============================================================================
354
+
355
+ /**
356
+ * Options for the standalone executeContractEmit function.
357
+ * Used by tooling (e.g., Vite plugin) that needs to emit contracts
358
+ * without the full ControlClient infrastructure.
359
+ */
360
+ export interface ContractEmitOptions {
361
+ /** Path to the prisma-next.config.ts file */
362
+ readonly configPath: string;
363
+ /** Optional AbortSignal for cancellation support */
364
+ readonly signal?: AbortSignal;
365
+ }
366
+
367
+ /**
368
+ * Result from the standalone executeContractEmit function.
369
+ */
370
+ export interface ContractEmitResult {
371
+ /** Hash of the storage contract (schema-level) */
372
+ readonly storageHash: string;
373
+ /** Hash of the execution contract (if execution section exists) */
374
+ readonly executionHash?: string;
375
+ /** Hash of the profile (target+extensions) */
376
+ readonly profileHash: string;
377
+ /** Paths to the emitted files */
378
+ readonly files: {
379
+ /** Path to the emitted contract.json file */
380
+ readonly json: string;
381
+ /** Path to the emitted contract.d.ts file */
382
+ readonly dts: string;
383
+ };
384
+ }
385
+
354
386
  // ============================================================================
355
387
  // Client Interface
356
388
  // ============================================================================
@@ -397,7 +429,7 @@ export interface ControlClient {
397
429
 
398
430
  /**
399
431
  * Verifies database marker matches the contract.
400
- * Compares coreHash and profileHash.
432
+ * Compares storageHash and profileHash.
401
433
  *
402
434
  * @returns Structured result (ok: false for mismatch, not throwing)
403
435
  * @throws If not connected or infrastructure failure
@@ -18,8 +18,13 @@ export type {
18
18
  // Client factory
19
19
  export { createControlClient } from '../control-api/client';
20
20
 
21
+ // Standalone operations (for tooling that doesn't need full client)
22
+ export { executeContractEmit } from '../control-api/operations/contract-emit';
23
+
21
24
  // CLI-specific types
22
25
  export type {
26
+ ContractEmitOptions,
27
+ ContractEmitResult,
23
28
  ContractSourceLoader,
24
29
  ContractSourceValue,
25
30
  ControlActionName,
@@ -30,26 +30,31 @@ function validatePurity(value: unknown): void {
30
30
  return;
31
31
  }
32
32
 
33
- const seen = new WeakSet();
33
+ const path = new WeakSet();
34
+
34
35
  function check(value: unknown): void {
35
36
  if (value === null || typeof value !== 'object') {
36
37
  return;
37
38
  }
38
39
 
39
- if (seen.has(value)) {
40
+ if (path.has(value)) {
40
41
  throw new Error('Contract export contains circular references');
41
42
  }
42
- seen.add(value);
43
+ path.add(value);
43
44
 
44
- for (const key in value) {
45
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
46
- if (descriptor && (descriptor.get || descriptor.set)) {
47
- throw new Error(`Contract export contains getter/setter at key "${key}"`);
48
- }
49
- if (descriptor && typeof descriptor.value === 'function') {
50
- throw new Error(`Contract export contains function at key "${key}"`);
45
+ try {
46
+ for (const key in value) {
47
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
48
+ if (descriptor && (descriptor.get || descriptor.set)) {
49
+ throw new Error(`Contract export contains getter/setter at key "${key}"`);
50
+ }
51
+ if (descriptor && typeof descriptor.value === 'function') {
52
+ throw new Error(`Contract export contains function at key "${key}"`);
53
+ }
54
+ check((value as Record<string, unknown>)[key]);
51
55
  }
52
- check((value as Record<string, unknown>)[key]);
56
+ } finally {
57
+ path.delete(value);
53
58
  }
54
59
  }
55
60
 
@@ -1,4 +1,5 @@
1
1
  import { relative } from 'node:path';
2
+ import { ifDefined } from '@prisma-next/utils/defined';
2
3
  import { bgGreen, blue, bold, cyan, dim, green, magenta, red, yellow } from 'colorette';
3
4
  import type { Command } from 'commander';
4
5
  import stringWidth from 'string-width';
@@ -6,7 +7,8 @@ import stripAnsi from 'strip-ansi';
6
7
  import wrapAnsi from 'wrap-ansi';
7
8
  // EmitContractResult type for CLI output formatting (includes file paths)
8
9
  export interface EmitContractResult {
9
- readonly coreHash: string;
10
+ readonly storageHash: string;
11
+ readonly executionHash?: string;
10
12
  readonly profileHash: string;
11
13
  readonly outDir: string;
12
14
  readonly files: {
@@ -94,7 +96,10 @@ export function formatEmitOutput(result: EmitContractResult, flags: GlobalFlags)
94
96
 
95
97
  lines.push(`${prefix}✔ Emitted contract.json → ${jsonPath}`);
96
98
  lines.push(`${prefix}✔ Emitted contract.d.ts → ${dtsPath}`);
97
- lines.push(`${prefix} coreHash: ${result.coreHash}`);
99
+ lines.push(`${prefix} storageHash: ${result.storageHash}`);
100
+ if (result.executionHash) {
101
+ lines.push(`${prefix} executionHash: ${result.executionHash}`);
102
+ }
98
103
  if (result.profileHash) {
99
104
  lines.push(`${prefix} profileHash: ${result.profileHash}`);
100
105
  }
@@ -111,7 +116,8 @@ export function formatEmitOutput(result: EmitContractResult, flags: GlobalFlags)
111
116
  export function formatEmitJson(result: EmitContractResult): string {
112
117
  const output = {
113
118
  ok: true,
114
- coreHash: result.coreHash,
119
+ storageHash: result.storageHash,
120
+ ...ifDefined('executionHash', result.executionHash),
115
121
  ...(result.profileHash ? { profileHash: result.profileHash } : {}),
116
122
  outDir: result.outDir,
117
123
  files: result.files,
@@ -223,7 +229,7 @@ export function formatVerifyOutput(result: VerifyDatabaseResult, flags: GlobalFl
223
229
 
224
230
  if (result.ok) {
225
231
  lines.push(`${prefix}${formatGreen('✔')} ${result.summary}`);
226
- lines.push(`${prefix}${formatDimText(` coreHash: ${result.contract.coreHash}`)}`);
232
+ lines.push(`${prefix}${formatDimText(` storageHash: ${result.contract.storageHash}`)}`);
227
233
  if (result.contract.profileHash) {
228
234
  lines.push(`${prefix}${formatDimText(` profileHash: ${result.contract.profileHash}`)}`);
229
235
  }
@@ -772,8 +778,8 @@ export function formatSignOutput(result: SignDatabaseResult, flags: GlobalFlags)
772
778
  lines.push(`${prefix}${formatGreen('✔')} Database signed`);
773
779
 
774
780
  // Show from -> to hashes with clear labels
775
- const previousHash = result.marker.previous?.coreHash ?? 'none';
776
- const currentHash = result.contract.coreHash;
781
+ const previousHash = result.marker.previous?.storageHash ?? 'none';
782
+ const currentHash = result.contract.storageHash;
777
783
 
778
784
  lines.push(`${prefix}${formatDimText(` from: ${previousHash}`)}`);
779
785
  lines.push(`${prefix}${formatDimText(` to: ${currentHash}`)}`);
@@ -814,7 +820,7 @@ export interface DbInitResult {
814
820
  readonly plan?: {
815
821
  readonly targetId: string;
816
822
  readonly destination: {
817
- readonly coreHash: string;
823
+ readonly storageHash: string;
818
824
  readonly profileHash?: string;
819
825
  };
820
826
  readonly operations: readonly {
@@ -828,7 +834,7 @@ export interface DbInitResult {
828
834
  readonly operationsExecuted: number;
829
835
  };
830
836
  readonly marker?: {
831
- readonly coreHash: string;
837
+ readonly storageHash: string;
832
838
  readonly profileHash?: string;
833
839
  };
834
840
  readonly summary: string;
@@ -872,7 +878,7 @@ export function formatDbInitPlanOutput(result: DbInitResult, flags: GlobalFlags)
872
878
  if (result.plan?.destination) {
873
879
  lines.push(`${prefix}`);
874
880
  lines.push(
875
- `${prefix}${formatDimText(`Destination hash: ${result.plan.destination.coreHash}`)}`,
881
+ `${prefix}${formatDimText(`Destination hash: ${result.plan.destination.storageHash}`)}`,
876
882
  );
877
883
  }
878
884
 
@@ -910,7 +916,7 @@ export function formatDbInitApplyOutput(result: DbInitResult, flags: GlobalFlags
910
916
 
911
917
  // Marker info
912
918
  if (result.marker) {
913
- lines.push(`${prefix}${formatDimText(` Marker written: ${result.marker.coreHash}`)}`);
919
+ lines.push(`${prefix}${formatDimText(` Marker written: ${result.marker.storageHash}`)}`);
914
920
  if (result.marker.profileHash) {
915
921
  lines.push(`${prefix}${formatDimText(` Profile hash: ${result.marker.profileHash}`)}`);
916
922
  }