@prisma-next/cli 0.3.0-dev.18 → 0.3.0-dev.19

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 (46) hide show
  1. package/dist/{chunk-ZG5T6OB5.js → chunk-AGOTG4L3.js} +43 -1
  2. package/dist/chunk-AGOTG4L3.js.map +1 -0
  3. package/dist/chunk-HLLI4YL7.js +180 -0
  4. package/dist/chunk-HLLI4YL7.js.map +1 -0
  5. package/dist/{chunk-RPYY5SM7.js → chunk-VG2R7DGF.js} +113 -3
  6. package/dist/chunk-VG2R7DGF.js.map +1 -0
  7. package/dist/cli.js +1662 -1580
  8. package/dist/cli.js.map +1 -1
  9. package/dist/commands/contract-emit.d.ts.map +1 -1
  10. package/dist/commands/contract-emit.js +3 -3
  11. package/dist/commands/db-init.js +4 -8
  12. package/dist/commands/db-init.js.map +1 -1
  13. package/dist/commands/db-introspect.js +4 -8
  14. package/dist/commands/db-introspect.js.map +1 -1
  15. package/dist/commands/db-schema-verify.js +4 -8
  16. package/dist/commands/db-schema-verify.js.map +1 -1
  17. package/dist/commands/db-sign.js +4 -8
  18. package/dist/commands/db-sign.js.map +1 -1
  19. package/dist/commands/db-verify.js +4 -8
  20. package/dist/commands/db-verify.js.map +1 -1
  21. package/dist/control-api/client.d.ts.map +1 -1
  22. package/dist/control-api/types.d.ts +91 -1
  23. package/dist/control-api/types.d.ts.map +1 -1
  24. package/dist/exports/control-api.d.ts +1 -1
  25. package/dist/exports/control-api.d.ts.map +1 -1
  26. package/dist/exports/control-api.js +1 -2
  27. package/dist/exports/index.js +3 -3
  28. package/package.json +10 -10
  29. package/src/commands/contract-emit.ts +179 -102
  30. package/src/control-api/client.ts +96 -0
  31. package/src/control-api/types.ts +107 -1
  32. package/src/exports/control-api.ts +9 -0
  33. package/dist/chunk-BO73VO4I.js +0 -45
  34. package/dist/chunk-BO73VO4I.js.map +0 -1
  35. package/dist/chunk-MPSJAVF6.js +0 -40
  36. package/dist/chunk-MPSJAVF6.js.map +0 -1
  37. package/dist/chunk-RIONCN4I.js +0 -172
  38. package/dist/chunk-RIONCN4I.js.map +0 -1
  39. package/dist/chunk-RPYY5SM7.js.map +0 -1
  40. package/dist/chunk-ZG5T6OB5.js.map +0 -1
  41. package/dist/utils/action.d.ts +0 -16
  42. package/dist/utils/action.d.ts.map +0 -1
  43. package/dist/utils/spinner.d.ts +0 -29
  44. package/dist/utils/spinner.d.ts.map +0 -1
  45. package/src/utils/action.ts +0 -43
  46. package/src/utils/spinner.ts +0 -67
@@ -29,7 +29,7 @@ export interface ControlClientOptions {
29
29
  /**
30
30
  * Action names for control-api operations that can emit progress events.
31
31
  */
32
- export type ControlActionName = 'dbInit' | 'verify' | 'schemaVerify' | 'sign' | 'introspect';
32
+ export type ControlActionName = 'dbInit' | 'verify' | 'schemaVerify' | 'sign' | 'introspect' | 'emit';
33
33
  /**
34
34
  * Progress event emitted during control-api operation execution.
35
35
  *
@@ -158,6 +158,56 @@ export interface IntrospectOptions {
158
158
  /** Optional progress callback for observing operation progress */
159
159
  readonly onProgress?: OnControlProgress;
160
160
  }
161
+ /**
162
+ * Contract source as a raw value (any JSON-serializable value).
163
+ */
164
+ export interface ContractSourceValue {
165
+ readonly kind: 'value';
166
+ readonly value: unknown;
167
+ }
168
+ /**
169
+ * Contract source as a lazy loader function.
170
+ */
171
+ export interface ContractSourceLoader {
172
+ readonly kind: 'loader';
173
+ readonly load: () => unknown | Promise<unknown>;
174
+ }
175
+ /**
176
+ * Discriminated union for contract source.
177
+ * Use `kind` to determine how to resolve the contract.
178
+ */
179
+ export type EmitContractSource = ContractSourceValue | ContractSourceLoader;
180
+ /**
181
+ * Contract configuration for emit operation.
182
+ */
183
+ export interface EmitContractConfig {
184
+ /**
185
+ * Contract source - either a raw value or a loader function.
186
+ * Switch on `source.kind` to determine how to resolve.
187
+ */
188
+ readonly source: EmitContractSource;
189
+ /**
190
+ * Output path for contract.json.
191
+ * Should be an absolute or relative path.
192
+ */
193
+ readonly output: string;
194
+ /**
195
+ * Output path for contract.d.ts.
196
+ * Should be an absolute or relative path.
197
+ */
198
+ readonly types: string;
199
+ }
200
+ /**
201
+ * Options for the emit operation.
202
+ */
203
+ export interface EmitOptions {
204
+ /**
205
+ * Contract configuration containing source, output, and types paths.
206
+ */
207
+ readonly contractConfig: EmitContractConfig;
208
+ /** Optional progress callback for observing operation progress */
209
+ readonly onProgress?: OnControlProgress;
210
+ }
161
211
  /**
162
212
  * Successful dbInit result.
163
213
  */
@@ -207,6 +257,38 @@ export interface DbInitFailure {
207
257
  * Uses Result pattern: success returns DbInitSuccess, failure returns DbInitFailure.
208
258
  */
209
259
  export type DbInitResult = Result<DbInitSuccess, DbInitFailure>;
260
+ /**
261
+ * Successful emit result.
262
+ * Contains the hashes and paths of emitted files.
263
+ */
264
+ export interface EmitSuccess {
265
+ /** Core hash of the emitted contract */
266
+ readonly coreHash: string;
267
+ /** Profile hash of the emitted contract (target-specific) */
268
+ readonly profileHash: string;
269
+ /** The emitted contract as JSON string */
270
+ readonly contractJson: string;
271
+ /** The emitted contract TypeScript declarations */
272
+ readonly contractDts: string;
273
+ }
274
+ /**
275
+ * Failure codes for emit operation.
276
+ */
277
+ export type EmitFailureCode = 'CONTRACT_SOURCE_INVALID' | 'EMIT_FAILED';
278
+ /**
279
+ * Failure details for emit operation.
280
+ */
281
+ export interface EmitFailure {
282
+ readonly code: EmitFailureCode;
283
+ readonly summary: string;
284
+ readonly why: string | undefined;
285
+ readonly meta: Record<string, unknown> | undefined;
286
+ }
287
+ /**
288
+ * Result type for emit operation.
289
+ * Uses Result pattern: success returns EmitSuccess, failure returns EmitFailure.
290
+ */
291
+ export type EmitResult = Result<EmitSuccess, EmitFailure>;
210
292
  /**
211
293
  * Programmatic control client for Prisma Next operations.
212
294
  *
@@ -293,5 +375,13 @@ export interface ControlClient {
293
375
  * @returns CoreSchemaView if the family supports it, undefined otherwise
294
376
  */
295
377
  toSchemaView(schemaIR: unknown): CoreSchemaView | undefined;
378
+ /**
379
+ * Emits the contract to JSON and TypeScript declarations.
380
+ * This is an offline operation that does NOT require a database connection.
381
+ * Uses `init()` to create the stack but does NOT call `connect()`.
382
+ *
383
+ * @returns Result pattern: Ok with emit details, NotOk with failure details
384
+ */
385
+ emit(options: EmitOptions): Promise<EmitResult>;
296
386
  }
297
387
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/control-api/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAClF,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,EAC3B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAMxD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,oBAAoB;IAEnC,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAEnD,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAE7D,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC1D,qFAAqF;IAErF,QAAQ,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAE9D,QAAQ,CAAC,cAAc,CAAC,EAAE,aAAa,CAAC,0BAA0B,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IACnF;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B;AA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,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAEtD;;;;;OAKG;IACH,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE1D;;;;;;OAMG;IACH,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CAAC;IAE5D;;;;;;OAMG;IACH,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACjD"}
@@ -9,5 +9,5 @@
9
9
  */
10
10
  export type { ControlPlaneStack, SignDatabaseResult, VerifyDatabaseResult, VerifyDatabaseSchemaResult, } from '@prisma-next/core-control-plane/types';
11
11
  export { createControlClient } from '../control-api/client';
12
- export type { ControlActionName, ControlClient, ControlClientOptions, ControlProgressEvent, DbInitFailure, DbInitFailureCode, DbInitOptions, DbInitResult, DbInitSuccess, IntrospectOptions, OnControlProgress, SchemaVerifyOptions, SignOptions, VerifyOptions, } from '../control-api/types';
12
+ export type { ContractSourceLoader, ContractSourceValue, ControlActionName, ControlClient, ControlClientOptions, ControlProgressEvent, DbInitFailure, DbInitFailureCode, DbInitOptions, DbInitResult, DbInitSuccess, EmitContractConfig, EmitContractSource, EmitFailure, EmitFailureCode, EmitOptions, EmitResult, EmitSuccess, IntrospectOptions, OnControlProgress, SchemaVerifyOptions, SignOptions, VerifyOptions, } from '../control-api/types';
13
13
  //# sourceMappingURL=control-api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"control-api.d.ts","sourceRoot":"","sources":["../../src/exports/control-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,aAAa,GACd,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"control-api.d.ts","sourceRoot":"","sources":["../../src/exports/control-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,WAAW,EACX,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,aAAa,GACd,MAAM,sBAAsB,CAAC"}
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  createControlClient
3
- } from "../chunk-RPYY5SM7.js";
4
- import "../chunk-MPSJAVF6.js";
3
+ } from "../chunk-VG2R7DGF.js";
5
4
  export {
6
5
  createControlClient
7
6
  };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createContractEmitCommand
3
- } from "../chunk-RIONCN4I.js";
4
- import "../chunk-ZG5T6OB5.js";
3
+ } from "../chunk-HLLI4YL7.js";
4
+ import "../chunk-AGOTG4L3.js";
5
5
  import "../chunk-HWYQOCAJ.js";
6
- import "../chunk-MPSJAVF6.js";
6
+ import "../chunk-VG2R7DGF.js";
7
7
 
8
8
  // src/load-ts-contract.ts
9
9
  import { existsSync, unlinkSync, writeFileSync } from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma-next/cli",
3
- "version": "0.3.0-dev.18",
3
+ "version": "0.3.0-dev.19",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -20,10 +20,10 @@
20
20
  "string-width": "^7.2.0",
21
21
  "strip-ansi": "^7.1.2",
22
22
  "wrap-ansi": "^9.0.2",
23
- "@prisma-next/contract": "0.3.0-dev.18",
24
- "@prisma-next/core-control-plane": "0.3.0-dev.18",
25
- "@prisma-next/emitter": "0.3.0-dev.18",
26
- "@prisma-next/utils": "0.3.0-dev.18"
23
+ "@prisma-next/contract": "0.3.0-dev.19",
24
+ "@prisma-next/core-control-plane": "0.3.0-dev.19",
25
+ "@prisma-next/utils": "0.3.0-dev.19",
26
+ "@prisma-next/emitter": "0.3.0-dev.19"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/node": "24.10.4",
@@ -31,11 +31,11 @@
31
31
  "tsup": "8.5.1",
32
32
  "typescript": "5.9.3",
33
33
  "vitest": "4.0.16",
34
- "@prisma-next/sql-contract": "0.3.0-dev.18",
35
- "@prisma-next/sql-contract-emitter": "0.3.0-dev.18",
36
- "@prisma-next/sql-contract-ts": "0.3.0-dev.18",
37
- "@prisma-next/sql-operations": "0.3.0-dev.18",
38
- "@prisma-next/sql-runtime": "0.3.0-dev.18",
34
+ "@prisma-next/sql-contract": "0.3.0-dev.19",
35
+ "@prisma-next/sql-contract-ts": "0.3.0-dev.19",
36
+ "@prisma-next/sql-contract-emitter": "0.3.0-dev.19",
37
+ "@prisma-next/sql-operations": "0.3.0-dev.19",
38
+ "@prisma-next/sql-runtime": "0.3.0-dev.19",
39
39
  "@prisma-next/test-utils": "0.0.1"
40
40
  },
41
41
  "exports": {
@@ -1,21 +1,24 @@
1
1
  import { mkdirSync, writeFileSync } from 'node:fs';
2
2
  import { dirname, relative, resolve } from 'node:path';
3
3
  import { errorContractConfigMissing } from '@prisma-next/core-control-plane/errors';
4
- import { createControlPlaneStack } from '@prisma-next/core-control-plane/stack';
4
+ import { notOk, ok, type Result } from '@prisma-next/utils/result';
5
5
  import { Command } from 'commander';
6
6
  import { loadConfig } from '../config-loader';
7
- import { performAction } from '../utils/action';
7
+ import { createControlClient } from '../control-api/client';
8
+ import type { EmitContractSource, EmitFailure } from '../control-api/types';
9
+ import { CliStructuredError, errorRuntime, errorUnexpected } from '../utils/cli-errors';
8
10
  import { setCommandDescriptions } from '../utils/command-helpers';
9
- import { parseGlobalFlags } from '../utils/global-flags';
11
+ import { type GlobalFlags, parseGlobalFlags } from '../utils/global-flags';
10
12
  import {
13
+ type EmitContractResult,
11
14
  formatCommandHelp,
12
15
  formatEmitJson,
13
16
  formatEmitOutput,
14
17
  formatStyledHeader,
15
18
  formatSuccessMessage,
16
19
  } from '../utils/output';
20
+ import { createProgressAdapter } from '../utils/progress-adapter';
17
21
  import { handleResult } from '../utils/result-handler';
18
- import { withSpinner } from '../utils/spinner';
19
22
 
20
23
  interface ContractEmitOptions {
21
24
  readonly config?: string;
@@ -31,6 +34,176 @@ interface ContractEmitOptions {
31
34
  readonly 'no-color'?: boolean;
32
35
  }
33
36
 
37
+ /**
38
+ * Maps an EmitFailure to a CliStructuredError for consistent error handling.
39
+ */
40
+ function mapEmitFailure(failure: EmitFailure): CliStructuredError {
41
+ if (failure.code === 'CONTRACT_SOURCE_INVALID') {
42
+ return errorRuntime(failure.summary, {
43
+ why: failure.why ?? 'Contract source is invalid',
44
+ fix: 'Check your contract source configuration in prisma-next.config.ts',
45
+ });
46
+ }
47
+
48
+ if (failure.code === 'EMIT_FAILED') {
49
+ return errorRuntime(failure.summary, {
50
+ why: failure.why ?? 'Failed to emit contract',
51
+ fix: 'Check your contract configuration and ensure the source is valid',
52
+ });
53
+ }
54
+
55
+ // Exhaustive check - TypeScript will error if a new code is added but not handled
56
+ const exhaustive: never = failure.code;
57
+ throw new Error(`Unhandled EmitFailure code: ${exhaustive}`);
58
+ }
59
+
60
+ /**
61
+ * Executes the contract emit command and returns a structured Result.
62
+ */
63
+ async function executeContractEmitCommand(
64
+ options: ContractEmitOptions,
65
+ flags: GlobalFlags,
66
+ startTime: number,
67
+ ): Promise<Result<EmitContractResult, CliStructuredError>> {
68
+ // Load config
69
+ let config: Awaited<ReturnType<typeof loadConfig>>;
70
+ try {
71
+ config = await loadConfig(options.config);
72
+ } catch (error) {
73
+ // Convert thrown CliStructuredError to Result
74
+ if (error instanceof CliStructuredError) {
75
+ return notOk(error);
76
+ }
77
+ return notOk(
78
+ errorUnexpected(error instanceof Error ? error.message : String(error), {
79
+ why: 'Failed to load config',
80
+ }),
81
+ );
82
+ }
83
+
84
+ // Resolve contract from config
85
+ if (!config.contract) {
86
+ return notOk(
87
+ errorContractConfigMissing({
88
+ why: 'Config.contract is required for emit. Define it in your config: contract: { source: ..., output: ..., types: ... }',
89
+ }),
90
+ );
91
+ }
92
+
93
+ // Contract config is already normalized by defineConfig() with defaults applied
94
+ const contractConfig = config.contract;
95
+
96
+ // Resolve artifact paths from config (already normalized by defineConfig() with defaults)
97
+ if (!contractConfig.output || !contractConfig.types) {
98
+ return notOk(
99
+ errorContractConfigMissing({
100
+ why: 'Contract config must have output and types paths. This should not happen if defineConfig() was used.',
101
+ }),
102
+ );
103
+ }
104
+ const outputJsonPath = resolve(contractConfig.output);
105
+ const outputDtsPath = resolve(contractConfig.types);
106
+
107
+ // Output header (only for human-readable output)
108
+ if (flags.json !== 'object' && !flags.quiet) {
109
+ // Normalize config path for display (match contract path format - no ./ prefix)
110
+ const configPath = options.config
111
+ ? relative(process.cwd(), resolve(options.config))
112
+ : 'prisma-next.config.ts';
113
+ // Convert absolute paths to relative paths for display
114
+ const contractPath = relative(process.cwd(), outputJsonPath);
115
+ const typesPath = relative(process.cwd(), outputDtsPath);
116
+ const header = formatStyledHeader({
117
+ command: 'contract emit',
118
+ description: 'Write your contract to JSON and sign it',
119
+ url: 'https://pris.ly/contract-emit',
120
+ details: [
121
+ { label: 'config', value: configPath },
122
+ { label: 'contract', value: contractPath },
123
+ { label: 'types', value: typesPath },
124
+ ],
125
+ flags,
126
+ });
127
+ console.log(header);
128
+ }
129
+
130
+ // Create control client (no driver needed for emit)
131
+ const client = createControlClient({
132
+ family: config.family,
133
+ target: config.target,
134
+ adapter: config.adapter,
135
+ extensionPacks: config.extensionPacks ?? [],
136
+ });
137
+
138
+ // Create progress adapter
139
+ const onProgress = createProgressAdapter({ flags });
140
+
141
+ try {
142
+ // Convert user config source to discriminated union
143
+ // Type assertion is safe: we check typeof to determine if it's a function
144
+ const source: EmitContractSource =
145
+ typeof contractConfig.source === 'function'
146
+ ? { kind: 'loader', load: contractConfig.source as () => unknown | Promise<unknown> }
147
+ : { kind: 'value', value: contractConfig.source };
148
+
149
+ // Call emit with progress callback
150
+ const result = await client.emit({
151
+ contractConfig: {
152
+ source,
153
+ output: outputJsonPath,
154
+ types: outputDtsPath,
155
+ },
156
+ onProgress,
157
+ });
158
+
159
+ // Handle failures by mapping to CLI structured error
160
+ if (!result.ok) {
161
+ return notOk(mapEmitFailure(result.failure));
162
+ }
163
+
164
+ // Create directories if needed
165
+ mkdirSync(dirname(outputJsonPath), { recursive: true });
166
+ mkdirSync(dirname(outputDtsPath), { recursive: true });
167
+
168
+ // Write the results to files
169
+ writeFileSync(outputJsonPath, result.value.contractJson, 'utf-8');
170
+ writeFileSync(outputDtsPath, result.value.contractDts, 'utf-8');
171
+
172
+ // Add blank line after all async operations if spinners were shown
173
+ if (!flags.quiet && flags.json !== 'object' && process.stdout.isTTY) {
174
+ console.log('');
175
+ }
176
+
177
+ // Convert success result to CLI output format
178
+ const emitResult: EmitContractResult = {
179
+ coreHash: result.value.coreHash,
180
+ profileHash: result.value.profileHash,
181
+ outDir: dirname(outputJsonPath),
182
+ files: {
183
+ json: outputJsonPath,
184
+ dts: outputDtsPath,
185
+ },
186
+ timings: { total: Date.now() - startTime },
187
+ };
188
+
189
+ return ok(emitResult);
190
+ } catch (error) {
191
+ // Use static type guard to work across module boundaries
192
+ if (CliStructuredError.is(error)) {
193
+ return notOk(error);
194
+ }
195
+
196
+ // Wrap unexpected errors
197
+ return notOk(
198
+ errorUnexpected('Unexpected error during contract emit', {
199
+ why: error instanceof Error ? error.message : String(error),
200
+ }),
201
+ );
202
+ } finally {
203
+ await client.close();
204
+ }
205
+ }
206
+
34
207
  export function createContractEmitCommand(): Command {
35
208
  const command = new Command('emit');
36
209
  setCommandDescriptions(
@@ -57,105 +230,9 @@ export function createContractEmitCommand(): Command {
57
230
  .option('--no-color', 'Disable color output')
58
231
  .action(async (options: ContractEmitOptions) => {
59
232
  const flags = parseGlobalFlags(options);
233
+ const startTime = Date.now();
60
234
 
61
- const result = await performAction(async () => {
62
- // Load config
63
- const config = await loadConfig(options.config);
64
-
65
- // Resolve contract from config
66
- if (!config.contract) {
67
- throw errorContractConfigMissing({
68
- why: 'Config.contract is required for emit. Define it in your config: contract: { source: ..., output: ..., types: ... }',
69
- });
70
- }
71
-
72
- // Contract config is already normalized by defineConfig() with defaults applied
73
- const contractConfig = config.contract;
74
-
75
- // Resolve artifact paths from config (already normalized by defineConfig() with defaults)
76
- if (!contractConfig.output || !contractConfig.types) {
77
- throw errorContractConfigMissing({
78
- why: 'Contract config must have output and types paths. This should not happen if defineConfig() was used.',
79
- });
80
- }
81
- const outputJsonPath = resolve(contractConfig.output);
82
- const outputDtsPath = resolve(contractConfig.types);
83
-
84
- // Output header (only for human-readable output)
85
- if (flags.json !== 'object' && !flags.quiet) {
86
- // Normalize config path for display (match contract path format - no ./ prefix)
87
- const configPath = options.config
88
- ? relative(process.cwd(), resolve(options.config))
89
- : 'prisma-next.config.ts';
90
- // Convert absolute paths to relative paths for display
91
- const contractPath = relative(process.cwd(), outputJsonPath);
92
- const typesPath = relative(process.cwd(), outputDtsPath);
93
- const header = formatStyledHeader({
94
- command: 'contract emit',
95
- description: 'Write your contract to JSON and sign it',
96
- url: 'https://pris.ly/contract-emit',
97
- details: [
98
- { label: 'config', value: configPath },
99
- { label: 'contract', value: contractPath },
100
- { label: 'types', value: typesPath },
101
- ],
102
- flags,
103
- });
104
- console.log(header);
105
- }
106
-
107
- const stack = createControlPlaneStack({
108
- target: config.target,
109
- adapter: config.adapter,
110
- driver: config.driver,
111
- extensionPacks: config.extensionPacks,
112
- });
113
- const familyInstance = config.family.create(stack);
114
-
115
- // Resolve contract source from config (user's config handles loading)
116
- let contractRaw: unknown;
117
- if (typeof contractConfig.source === 'function') {
118
- contractRaw = await contractConfig.source();
119
- } else {
120
- contractRaw = contractConfig.source;
121
- }
122
-
123
- // Call emitContract on family instance (handles stripping mappings and validation internally)
124
- const emitResult = await withSpinner(
125
- () => familyInstance.emitContract({ contractIR: contractRaw }),
126
- {
127
- message: 'Emitting contract...',
128
- flags,
129
- },
130
- );
131
-
132
- // Create directories if needed
133
- mkdirSync(dirname(outputJsonPath), { recursive: true });
134
- mkdirSync(dirname(outputDtsPath), { recursive: true });
135
-
136
- // Write the results to files
137
- writeFileSync(outputJsonPath, emitResult.contractJson, 'utf-8');
138
- writeFileSync(outputDtsPath, emitResult.contractDts, 'utf-8');
139
-
140
- // Add blank line after all async operations if spinners were shown
141
- if (!flags.quiet && flags.json !== 'object' && process.stdout.isTTY) {
142
- console.log('');
143
- }
144
-
145
- // Return result with file paths for output formatting
146
- return {
147
- coreHash: emitResult.coreHash,
148
- profileHash: emitResult.profileHash,
149
- outDir: dirname(outputJsonPath),
150
- files: {
151
- json: outputJsonPath,
152
- dts: outputDtsPath,
153
- },
154
- timings: {
155
- total: 0, // Timing is handled by emitContract internally if needed
156
- },
157
- };
158
- });
235
+ const result = await executeContractEmitCommand(options, flags, startTime);
159
236
 
160
237
  // Handle result - formats output and returns exit code
161
238
  const exitCode = handleResult(result, flags, (emitResult) => {
@@ -9,6 +9,7 @@ import type {
9
9
  VerifyDatabaseResult,
10
10
  VerifyDatabaseSchemaResult,
11
11
  } from '@prisma-next/core-control-plane/types';
12
+ import { notOk, ok } from '@prisma-next/utils/result';
12
13
  import { assertFrameworkComponentsCompatible } from '../utils/framework-components';
13
14
  import { executeDbInit } from './operations/db-init';
14
15
  import type {
@@ -16,6 +17,8 @@ import type {
16
17
  ControlClientOptions,
17
18
  DbInitOptions,
18
19
  DbInitResult,
20
+ EmitOptions,
21
+ EmitResult,
19
22
  IntrospectOptions,
20
23
  SchemaVerifyOptions,
21
24
  SignOptions,
@@ -490,4 +493,97 @@ class ControlClientImpl implements ControlClient {
490
493
  }
491
494
  return undefined;
492
495
  }
496
+
497
+ async emit(options: EmitOptions): Promise<EmitResult> {
498
+ const { onProgress, contractConfig } = options;
499
+
500
+ // Ensure initialized (creates stack and family instance)
501
+ // emit() does NOT require a database connection
502
+ this.init();
503
+
504
+ if (!this.familyInstance) {
505
+ throw new Error('Family instance was not initialized. This is a bug.');
506
+ }
507
+
508
+ // Resolve contract source
509
+ let contractRaw: unknown;
510
+ onProgress?.({
511
+ action: 'emit',
512
+ kind: 'spanStart',
513
+ spanId: 'resolveSource',
514
+ label: 'Resolving contract source...',
515
+ });
516
+
517
+ try {
518
+ switch (contractConfig.source.kind) {
519
+ case 'loader':
520
+ contractRaw = await contractConfig.source.load();
521
+ break;
522
+ case 'value':
523
+ contractRaw = contractConfig.source.value;
524
+ break;
525
+ }
526
+
527
+ onProgress?.({
528
+ action: 'emit',
529
+ kind: 'spanEnd',
530
+ spanId: 'resolveSource',
531
+ outcome: 'ok',
532
+ });
533
+ } catch (error) {
534
+ onProgress?.({
535
+ action: 'emit',
536
+ kind: 'spanEnd',
537
+ spanId: 'resolveSource',
538
+ outcome: 'error',
539
+ });
540
+
541
+ return notOk({
542
+ code: 'CONTRACT_SOURCE_INVALID',
543
+ summary: 'Failed to resolve contract source',
544
+ why: error instanceof Error ? error.message : String(error),
545
+ meta: undefined,
546
+ });
547
+ }
548
+
549
+ // Emit contract
550
+ onProgress?.({
551
+ action: 'emit',
552
+ kind: 'spanStart',
553
+ spanId: 'emit',
554
+ label: 'Emitting contract...',
555
+ });
556
+
557
+ try {
558
+ const emitResult = await this.familyInstance.emitContract({ contractIR: contractRaw });
559
+
560
+ onProgress?.({
561
+ action: 'emit',
562
+ kind: 'spanEnd',
563
+ spanId: 'emit',
564
+ outcome: 'ok',
565
+ });
566
+
567
+ return ok({
568
+ coreHash: emitResult.coreHash,
569
+ profileHash: emitResult.profileHash,
570
+ contractJson: emitResult.contractJson,
571
+ contractDts: emitResult.contractDts,
572
+ });
573
+ } catch (error) {
574
+ onProgress?.({
575
+ action: 'emit',
576
+ kind: 'spanEnd',
577
+ spanId: 'emit',
578
+ outcome: 'error',
579
+ });
580
+
581
+ return notOk({
582
+ code: 'EMIT_FAILED',
583
+ summary: 'Failed to emit contract',
584
+ why: error instanceof Error ? error.message : String(error),
585
+ meta: undefined,
586
+ });
587
+ }
588
+ }
493
589
  }