@prisma-next/cli 0.0.1 → 0.1.0-pr.25.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.
package/dist/index.js CHANGED
@@ -2,636 +2,14 @@ import {
2
2
  loadExtensionPackManifest,
3
3
  loadExtensionPacks
4
4
  } from "./chunk-W5YXBFPY.js";
5
-
6
- // src/commands/contract-emit.ts
7
- import { mkdirSync, writeFileSync } from "fs";
8
- import { dirname as dirname2, relative as relative2, resolve as resolve2 } from "path";
9
- import { errorContractConfigMissing as errorContractConfigMissing2 } from "@prisma-next/core-control-plane/errors";
10
- import { Command } from "commander";
11
-
12
- // src/config-loader.ts
13
- import { dirname, resolve } from "path";
14
- import { validateConfig } from "@prisma-next/core-control-plane/config-validation";
15
- import { errorConfigFileNotFound, errorUnexpected } from "@prisma-next/core-control-plane/errors";
16
- import { loadConfig as loadConfigC12 } from "c12";
17
- async function loadConfig(configPath) {
18
- try {
19
- const cwd = process.cwd();
20
- const resolvedConfigPath = configPath ? resolve(cwd, configPath) : void 0;
21
- const configCwd = resolvedConfigPath ? dirname(resolvedConfigPath) : cwd;
22
- const result = await loadConfigC12({
23
- name: "prisma-next",
24
- ...resolvedConfigPath ? { configFile: resolvedConfigPath } : {},
25
- cwd: configCwd
26
- });
27
- if (!result.config || Object.keys(result.config).length === 0) {
28
- const displayPath = result.configFile || resolvedConfigPath || configPath;
29
- throw errorConfigFileNotFound(displayPath);
30
- }
31
- validateConfig(result.config);
32
- return result.config;
33
- } catch (error) {
34
- if (error instanceof Error && "code" in error && typeof error.code === "string") {
35
- throw error;
36
- }
37
- if (error instanceof Error) {
38
- if (error.message.includes("not found") || error.message.includes("Cannot find") || error.message.includes("ENOENT")) {
39
- const displayPath = configPath ? resolve(process.cwd(), configPath) : void 0;
40
- throw errorConfigFileNotFound(displayPath, {
41
- why: error.message
42
- });
43
- }
44
- throw errorUnexpected(error.message, {
45
- why: `Failed to load config: ${error.message}`
46
- });
47
- }
48
- throw errorUnexpected(String(error));
49
- }
50
- }
51
-
52
- // src/utils/command-helpers.ts
53
- function setCommandDescriptions(command, shortDescription, longDescription) {
54
- command.description(shortDescription);
55
- if (longDescription) {
56
- command._longDescription = longDescription;
57
- }
58
- return command;
59
- }
60
- function getLongDescription(command) {
61
- return command._longDescription;
62
- }
63
-
64
- // src/utils/global-flags.ts
65
- function parseGlobalFlags(options) {
66
- const flags = {};
67
- if (options.json === true || options.json === "object") {
68
- flags.json = "object";
69
- } else if (options.json === "ndjson") {
70
- flags.json = "ndjson";
71
- }
72
- if (options.quiet || options.q) {
73
- flags.quiet = true;
74
- }
75
- if (options.vv || options.trace) {
76
- flags.verbose = 2;
77
- } else if (options.verbose || options.v) {
78
- flags.verbose = 1;
79
- } else {
80
- flags.verbose = 0;
81
- }
82
- if (options.timestamps) {
83
- flags.timestamps = true;
84
- }
85
- if (process.env["NO_COLOR"]) {
86
- flags.color = false;
87
- } else if (options["no-color"]) {
88
- flags.color = false;
89
- } else if (options.color !== void 0) {
90
- flags.color = options.color;
91
- } else {
92
- flags.color = process.stdout.isTTY && !process.env["CI"];
93
- }
94
- return flags;
95
- }
96
-
97
- // src/utils/output.ts
98
- import { relative } from "path";
99
- import { bgGreen, blue, bold, cyan, dim, green, magenta, red, yellow } from "colorette";
100
- import stringWidth from "string-width";
101
- import stripAnsi from "strip-ansi";
102
- import wrapAnsi from "wrap-ansi";
103
- function formatTimestamp() {
104
- return (/* @__PURE__ */ new Date()).toISOString();
105
- }
106
- function createPrefix(flags) {
107
- return flags.timestamps ? `[${formatTimestamp()}] ` : "";
108
- }
109
- function isVerbose(flags, level) {
110
- return (flags.verbose ?? 0) >= level;
111
- }
112
- function createColorFormatter(useColor, colorFn) {
113
- return useColor ? colorFn : (text) => text;
114
- }
115
- function formatDim(useColor, text) {
116
- return useColor ? dim(text) : text;
117
- }
118
- function formatEmitOutput(result, flags) {
119
- if (flags.quiet) {
120
- return "";
121
- }
122
- const lines = [];
123
- const prefix = createPrefix(flags);
124
- const jsonPath = relative(process.cwd(), result.files.json);
125
- const dtsPath = relative(process.cwd(), result.files.dts);
126
- lines.push(`${prefix}\u2714 Emitted contract.json \u2192 ${jsonPath}`);
127
- lines.push(`${prefix}\u2714 Emitted contract.d.ts \u2192 ${dtsPath}`);
128
- lines.push(`${prefix} coreHash: ${result.coreHash}`);
129
- if (result.profileHash) {
130
- lines.push(`${prefix} profileHash: ${result.profileHash}`);
131
- }
132
- if (isVerbose(flags, 1)) {
133
- lines.push(`${prefix} Total time: ${result.timings.total}ms`);
134
- }
135
- return lines.join("\n");
136
- }
137
- function formatEmitJson(result) {
138
- const output = {
139
- ok: true,
140
- coreHash: result.coreHash,
141
- ...result.profileHash ? { profileHash: result.profileHash } : {},
142
- outDir: result.outDir,
143
- files: result.files,
144
- timings: result.timings
145
- };
146
- return JSON.stringify(output, null, 2);
147
- }
148
- function formatErrorOutput(error, flags) {
149
- const lines = [];
150
- const prefix = createPrefix(flags);
151
- const useColor = flags.color !== false;
152
- const formatRed = createColorFormatter(useColor, red);
153
- const formatDimText = (text) => formatDim(useColor, text);
154
- lines.push(`${prefix}${formatRed("\u2716")} ${error.summary} (${error.code})`);
155
- if (error.why) {
156
- lines.push(`${prefix}${formatDimText(` Why: ${error.why}`)}`);
157
- }
158
- if (error.fix) {
159
- lines.push(`${prefix}${formatDimText(` Fix: ${error.fix}`)}`);
160
- }
161
- if (error.where?.path) {
162
- const whereLine = error.where.line ? `${error.where.path}:${error.where.line}` : error.where.path;
163
- lines.push(`${prefix}${formatDimText(` Where: ${whereLine}`)}`);
164
- }
165
- if (error.docsUrl && isVerbose(flags, 1)) {
166
- lines.push(formatDimText(error.docsUrl));
167
- }
168
- if (isVerbose(flags, 2) && error.meta) {
169
- lines.push(`${prefix}${formatDimText(` Meta: ${JSON.stringify(error.meta, null, 2)}`)}`);
170
- }
171
- return lines.join("\n");
172
- }
173
- function formatErrorJson(error) {
174
- return JSON.stringify(error, null, 2);
175
- }
176
- var LEFT_COLUMN_WIDTH = 20;
177
- var RIGHT_COLUMN_MIN_WIDTH = 40;
178
- var RIGHT_COLUMN_MAX_WIDTH = 90;
179
- function getTerminalWidth() {
180
- const terminalWidth = process.stdout.columns;
181
- const defaultWidth = Number.parseInt(process.env["CLI_WIDTH"] || "80", 10);
182
- return terminalWidth || defaultWidth;
183
- }
184
- function calculateRightColumnWidth() {
185
- const terminalWidth = getTerminalWidth();
186
- const availableWidth = terminalWidth - 2 - LEFT_COLUMN_WIDTH - 2;
187
- return Math.max(RIGHT_COLUMN_MIN_WIDTH, Math.min(availableWidth, RIGHT_COLUMN_MAX_WIDTH));
188
- }
189
- function createPrismaNextBadge(useColor) {
190
- if (!useColor) {
191
- return "prisma-next";
192
- }
193
- const text = " prisma-next ";
194
- const body = bgGreen(bold(text));
195
- const separator = "\uE0B0";
196
- const tip = green(separator);
197
- return `${body}${tip}`;
198
- }
199
- function createPadFunction() {
200
- return (s, w) => s + " ".repeat(Math.max(0, w - s.length));
201
- }
202
- function formatHeaderLine(options) {
203
- if (options.operation) {
204
- return `${options.brand} ${options.operation} \u2192 ${options.intent}`;
205
- }
206
- return `${options.brand} ${options.intent}`;
207
- }
208
- function formatReadMoreLine(options) {
209
- const pad = createPadFunction();
210
- const labelPadded = pad("Read more", options.maxLabelWidth);
211
- const valueColored = options.useColor ? blue(options.url) : options.url;
212
- return `${options.formatDimText("\u2502")} ${labelPadded} ${valueColored}`;
213
- }
214
- function padToFixedWidth(text, width) {
215
- const actualWidth = stringWidth(text);
216
- const padding = Math.max(0, width - actualWidth);
217
- return text + " ".repeat(padding);
218
- }
219
- function wrapTextAnsi(text, width) {
220
- const wrapped = wrapAnsi(text, width, { hard: false, trim: true });
221
- return wrapped.split("\n");
222
- }
223
- function formatDefaultValue(value, useColor) {
224
- const valueStr = String(value);
225
- const defaultText = `default: ${valueStr}`;
226
- return useColor ? dim(defaultText) : defaultText;
227
- }
228
- function renderCommandTree(options) {
229
- const { commands, useColor, formatDimText, hasItemsAfter, continuationPrefix } = options;
230
- const lines = [];
231
- if (commands.length === 0) {
232
- return lines;
233
- }
234
- for (let i = 0; i < commands.length; i++) {
235
- const cmd = commands[i];
236
- if (!cmd) continue;
237
- const subcommands = cmd.commands.filter((subcmd) => !subcmd.name().startsWith("_"));
238
- const isLastCommand = i === commands.length - 1;
239
- if (subcommands.length > 0) {
240
- const prefix = isLastCommand && !hasItemsAfter ? formatDimText("\u2514") : formatDimText("\u251C");
241
- const treePrefix = `${prefix}\u2500 `;
242
- const treePrefixWidth = stringWidth(stripAnsi(treePrefix));
243
- const remainingWidth = LEFT_COLUMN_WIDTH - treePrefixWidth;
244
- const commandNamePadded = padToFixedWidth(cmd.name(), remainingWidth);
245
- const commandNameColored = useColor ? cyan(commandNamePadded) : commandNamePadded;
246
- lines.push(`${formatDimText("\u2502")} ${treePrefix}${commandNameColored}`);
247
- for (let j = 0; j < subcommands.length; j++) {
248
- const subcmd = subcommands[j];
249
- if (!subcmd) continue;
250
- const isLastSubcommand = j === subcommands.length - 1;
251
- const shortDescription = subcmd.description() || "";
252
- const treeChar = isLastSubcommand ? "\u2514" : "\u251C";
253
- const continuation = continuationPrefix ?? (isLastCommand && isLastSubcommand && !hasItemsAfter ? " " : formatDimText("\u2502"));
254
- const continuationStr = continuation === " " ? " " : continuation;
255
- const subTreePrefix = `${continuationStr} ${formatDimText(treeChar)}\u2500 `;
256
- const subTreePrefixWidth = stringWidth(stripAnsi(subTreePrefix));
257
- const subRemainingWidth = LEFT_COLUMN_WIDTH - subTreePrefixWidth;
258
- const subcommandNamePadded = padToFixedWidth(subcmd.name(), subRemainingWidth);
259
- const subcommandNameColored = useColor ? cyan(subcommandNamePadded) : subcommandNamePadded;
260
- lines.push(
261
- `${formatDimText("\u2502")} ${subTreePrefix}${subcommandNameColored} ${shortDescription}`
262
- );
263
- }
264
- } else {
265
- const prefix = isLastCommand && !hasItemsAfter ? formatDimText("\u2514") : formatDimText("\u251C");
266
- const treePrefix = `${prefix}\u2500 `;
267
- const treePrefixWidth = stringWidth(stripAnsi(treePrefix));
268
- const remainingWidth = LEFT_COLUMN_WIDTH - treePrefixWidth;
269
- const commandNamePadded = padToFixedWidth(cmd.name(), remainingWidth);
270
- const commandNameColored = useColor ? cyan(commandNamePadded) : commandNamePadded;
271
- const shortDescription = cmd.description() || "";
272
- lines.push(`${formatDimText("\u2502")} ${treePrefix}${commandNameColored} ${shortDescription}`);
273
- }
274
- }
275
- return lines;
276
- }
277
- function formatMultilineDescription(options) {
278
- const lines = [];
279
- const formatGreen = (text) => options.useColor ? green(text) : text;
280
- const rightColumnWidth = calculateRightColumnWidth();
281
- const totalWidth = 2 + LEFT_COLUMN_WIDTH + 2 + rightColumnWidth;
282
- const wrapWidth = totalWidth - 2;
283
- for (const descLine of options.descriptionLines) {
284
- const formattedLine = descLine.replace(/Prisma Next/g, (match) => formatGreen(match));
285
- const wrappedLines = wrapTextAnsi(formattedLine, wrapWidth);
286
- for (const wrappedLine of wrappedLines) {
287
- lines.push(`${options.formatDimText("\u2502")} ${wrappedLine}`);
288
- }
289
- }
290
- return lines;
291
- }
292
- function formatStyledHeader(options) {
293
- const lines = [];
294
- const useColor = options.flags.color !== false;
295
- const formatDimText = (text) => formatDim(useColor, text);
296
- const brand = createPrismaNextBadge(useColor);
297
- const operation = useColor ? bold(options.command) : options.command;
298
- const intent = formatDimText(options.description);
299
- lines.push(formatHeaderLine({ brand, operation, intent }));
300
- lines.push(formatDimText("\u2502"));
301
- for (const detail of options.details) {
302
- const labelWithColon = `${detail.label}:`;
303
- const labelPadded = padToFixedWidth(labelWithColon, LEFT_COLUMN_WIDTH);
304
- const labelColored = useColor ? cyan(labelPadded) : labelPadded;
305
- lines.push(`${formatDimText("\u2502")} ${labelColored} ${detail.value}`);
306
- }
307
- if (options.url) {
308
- lines.push(formatDimText("\u2502"));
309
- lines.push(
310
- formatReadMoreLine({
311
- url: options.url,
312
- maxLabelWidth: LEFT_COLUMN_WIDTH,
313
- useColor,
314
- formatDimText
315
- })
316
- );
317
- }
318
- lines.push(formatDimText("\u2514"));
319
- return `${lines.join("\n")}
320
- `;
321
- }
322
- function formatSuccessMessage(flags) {
323
- const useColor = flags.color !== false;
324
- const formatGreen = createColorFormatter(useColor, green);
325
- return `${formatGreen("\u2714")} Success`;
326
- }
327
- function getCommandDocsUrl(commandPath) {
328
- const docsMap = {
329
- "contract emit": "https://pris.ly/contract-emit",
330
- "db verify": "https://pris.ly/db-verify"
331
- };
332
- return docsMap[commandPath];
333
- }
334
- function buildCommandPath(command) {
335
- const parts = [];
336
- let current = command;
337
- while (current && current.name() !== "prisma-next") {
338
- parts.unshift(current.name());
339
- current = current.parent ?? void 0;
340
- }
341
- return parts.join(" ");
342
- }
343
- function formatCommandHelp(options) {
344
- const { command, flags } = options;
345
- const lines = [];
346
- const useColor = flags.color !== false;
347
- const formatDimText = (text) => formatDim(useColor, text);
348
- const commandPath = buildCommandPath(command);
349
- const shortDescription = command.description() || "";
350
- const longDescription = getLongDescription(command);
351
- const brand = createPrismaNextBadge(useColor);
352
- const operation = useColor ? bold(commandPath) : commandPath;
353
- const intent = formatDimText(shortDescription);
354
- lines.push(formatHeaderLine({ brand, operation, intent }));
355
- lines.push(formatDimText("\u2502"));
356
- const optionsList = command.options.map((opt) => {
357
- const flags2 = opt.flags;
358
- const description = opt.description || "";
359
- const defaultValue = opt.defaultValue;
360
- return { flags: flags2, description, defaultValue };
361
- });
362
- const subcommands = command.commands.filter((cmd) => !cmd.name().startsWith("_"));
363
- if (subcommands.length > 0) {
364
- const hasItemsAfter = optionsList.length > 0;
365
- const treeLines = renderCommandTree({
366
- commands: subcommands,
367
- useColor,
368
- formatDimText,
369
- hasItemsAfter
370
- });
371
- lines.push(...treeLines);
372
- }
373
- if (subcommands.length > 0 && optionsList.length > 0) {
374
- lines.push(formatDimText("\u2502"));
375
- }
376
- if (optionsList.length > 0) {
377
- for (const opt of optionsList) {
378
- const flagsPadded = padToFixedWidth(opt.flags, LEFT_COLUMN_WIDTH);
379
- let flagsColored = flagsPadded;
380
- if (useColor) {
381
- flagsColored = flagsPadded.replace(/(<[^>]+>)/g, (match) => magenta(match));
382
- flagsColored = cyan(flagsColored);
383
- }
384
- const rightColumnWidth = calculateRightColumnWidth();
385
- const wrappedDescription = wrapTextAnsi(opt.description, rightColumnWidth);
386
- lines.push(`${formatDimText("\u2502")} ${flagsColored} ${wrappedDescription[0] || ""}`);
387
- for (let i = 1; i < wrappedDescription.length; i++) {
388
- const emptyLabel = " ".repeat(LEFT_COLUMN_WIDTH);
389
- lines.push(`${formatDimText("\u2502")} ${emptyLabel} ${wrappedDescription[i] || ""}`);
390
- }
391
- if (opt.defaultValue !== void 0) {
392
- const emptyLabel = " ".repeat(LEFT_COLUMN_WIDTH);
393
- const defaultText = formatDefaultValue(opt.defaultValue, useColor);
394
- lines.push(`${formatDimText("\u2502")} ${emptyLabel} ${defaultText}`);
395
- }
396
- }
397
- }
398
- const docsUrl = getCommandDocsUrl(commandPath);
399
- if (docsUrl) {
400
- lines.push(formatDimText("\u2502"));
401
- lines.push(
402
- formatReadMoreLine({
403
- url: docsUrl,
404
- maxLabelWidth: LEFT_COLUMN_WIDTH,
405
- useColor,
406
- formatDimText
407
- })
408
- );
409
- }
410
- if (longDescription) {
411
- lines.push(formatDimText("\u2502"));
412
- const descriptionLines = longDescription.split("\n").filter((line) => line.trim().length > 0);
413
- lines.push(...formatMultilineDescription({ descriptionLines, useColor, formatDimText }));
414
- }
415
- lines.push(formatDimText("\u2514"));
416
- return `${lines.join("\n")}
417
- `;
418
- }
419
-
420
- // src/utils/cli-errors.ts
421
5
  import {
422
- CliStructuredError,
423
- errorConfigFileNotFound as errorConfigFileNotFound2,
424
- errorConfigValidation,
425
- errorContractConfigMissing,
426
- errorContractValidationFailed,
427
- errorDatabaseUrlRequired,
428
- errorDriverRequired,
429
- errorFamilyReadMarkerSqlRequired,
430
- errorFileNotFound,
431
- errorHashMismatch,
432
- errorMarkerMissing,
433
- errorQueryRunnerFactoryRequired,
434
- errorRuntime,
435
- errorTargetMismatch,
436
- errorUnexpected as errorUnexpected2
437
- } from "@prisma-next/core-control-plane/errors";
438
-
439
- // src/utils/result.ts
440
- function ok(value) {
441
- return { ok: true, value };
442
- }
443
- function err(error) {
444
- return { ok: false, error };
445
- }
446
- async function performAction(fn) {
447
- try {
448
- const value = await fn();
449
- return ok(value);
450
- } catch (error) {
451
- if (error instanceof CliStructuredError) {
452
- return err(error);
453
- }
454
- throw error;
455
- }
456
- }
457
-
458
- // src/utils/result-handler.ts
459
- function handleResult(result, flags, onSuccess) {
460
- if (result.ok) {
461
- if (onSuccess) {
462
- onSuccess(result.value);
463
- }
464
- return 0;
465
- }
466
- const envelope = result.error.toEnvelope();
467
- if (flags.json === "object") {
468
- console.error(formatErrorJson(envelope));
469
- } else {
470
- console.error(formatErrorOutput(envelope, flags));
471
- }
472
- const exitCode = result.error.domain === "CLI" ? 2 : 1;
473
- return exitCode;
474
- }
475
-
476
- // src/utils/spinner.ts
477
- import ora from "ora";
478
- async function withSpinner(operation, options) {
479
- const { message, flags, delayThreshold = 100 } = options;
480
- const shouldShowSpinner = !flags.quiet && flags.json !== "object" && process.stdout.isTTY;
481
- if (!shouldShowSpinner) {
482
- return operation();
483
- }
484
- const startTime = Date.now();
485
- let spinner = null;
486
- let timeoutId = null;
487
- let operationCompleted = false;
488
- timeoutId = setTimeout(() => {
489
- if (!operationCompleted) {
490
- spinner = ora({
491
- text: message,
492
- color: flags.color !== false ? "cyan" : false
493
- }).start();
494
- }
495
- }, delayThreshold);
496
- try {
497
- const result = await operation();
498
- operationCompleted = true;
499
- if (timeoutId) {
500
- clearTimeout(timeoutId);
501
- timeoutId = null;
502
- }
503
- if (spinner !== null) {
504
- const elapsed = Date.now() - startTime;
505
- spinner.succeed(`${message} (${elapsed}ms)`);
506
- }
507
- return result;
508
- } catch (error) {
509
- operationCompleted = true;
510
- if (timeoutId) {
511
- clearTimeout(timeoutId);
512
- timeoutId = null;
513
- }
514
- if (spinner !== null) {
515
- spinner.fail(
516
- `${message} failed: ${error instanceof Error ? error.message : String(error)}`
517
- );
518
- }
519
- throw error;
520
- }
521
- }
522
-
523
- // src/commands/contract-emit.ts
524
- function createContractEmitCommand() {
525
- const command = new Command("emit");
526
- setCommandDescriptions(
527
- command,
528
- "Write your contract to JSON and sign it",
529
- "Reads your contract source (TypeScript or Prisma schema) and emits contract.json and\ncontract.d.ts. The contract.json contains the canonical contract structure, and\ncontract.d.ts provides TypeScript types for type-safe query building."
530
- );
531
- command.configureHelp({
532
- formatHelp: (cmd) => {
533
- const flags = parseGlobalFlags({});
534
- return formatCommandHelp({ command: cmd, flags });
535
- }
536
- }).option("--config <path>", "Path to prisma-next.config.ts").option("--json [format]", "Output as JSON (object or ndjson)", false).option("-q, --quiet", "Quiet mode: errors only").option("-v, --verbose", "Verbose output: debug info, timings").option("-vv, --trace", "Trace output: deep internals, stack traces").option("--timestamps", "Add timestamps to output").option("--color", "Force color output").option("--no-color", "Disable color output").action(async (options) => {
537
- const flags = parseGlobalFlags(options);
538
- const result = await performAction(async () => {
539
- const config = await loadConfig(options.config);
540
- if (!config.contract) {
541
- throw errorContractConfigMissing2({
542
- why: "Config.contract is required for emit. Define it in your config: contract: { source: ..., output: ..., types: ... }"
543
- });
544
- }
545
- const contractConfig = config.contract;
546
- if (!contractConfig.output || !contractConfig.types) {
547
- throw errorContractConfigMissing2({
548
- why: "Contract config must have output and types paths. This should not happen if defineConfig() was used."
549
- });
550
- }
551
- const outputJsonPath = resolve2(contractConfig.output);
552
- const outputDtsPath = resolve2(contractConfig.types);
553
- if (flags.json !== "object" && !flags.quiet) {
554
- const configPath = options.config ? relative2(process.cwd(), resolve2(options.config)) : "prisma-next.config.ts";
555
- const contractPath = relative2(process.cwd(), outputJsonPath);
556
- const typesPath = relative2(process.cwd(), outputDtsPath);
557
- const header = formatStyledHeader({
558
- command: "contract emit",
559
- description: "Write your contract to JSON and sign it",
560
- url: "https://pris.ly/contract-emit",
561
- details: [
562
- { label: "config", value: configPath },
563
- { label: "contract", value: contractPath },
564
- { label: "types", value: typesPath }
565
- ],
566
- flags
567
- });
568
- console.log(header);
569
- }
570
- if (!config.driver) {
571
- throw errorContractConfigMissing2({
572
- why: "Config.driver is required. Even though emit does not use the driver, it is required by ControlFamilyDescriptor.create()"
573
- });
574
- }
575
- const familyInstance = config.family.create({
576
- target: config.target,
577
- adapter: config.adapter,
578
- driver: config.driver,
579
- extensions: config.extensions ?? []
580
- });
581
- let contractRaw;
582
- if (typeof contractConfig.source === "function") {
583
- contractRaw = await contractConfig.source();
584
- } else {
585
- contractRaw = contractConfig.source;
586
- }
587
- const emitResult = await withSpinner(
588
- () => familyInstance.emitContract({ contractIR: contractRaw }),
589
- {
590
- message: "Emitting contract...",
591
- flags
592
- }
593
- );
594
- mkdirSync(dirname2(outputJsonPath), { recursive: true });
595
- mkdirSync(dirname2(outputDtsPath), { recursive: true });
596
- writeFileSync(outputJsonPath, emitResult.contractJson, "utf-8");
597
- writeFileSync(outputDtsPath, emitResult.contractDts, "utf-8");
598
- if (!flags.quiet && flags.json !== "object" && process.stdout.isTTY) {
599
- console.log("");
600
- }
601
- return {
602
- coreHash: emitResult.coreHash,
603
- profileHash: emitResult.profileHash,
604
- outDir: dirname2(outputJsonPath),
605
- files: {
606
- json: outputJsonPath,
607
- dts: outputDtsPath
608
- },
609
- timings: {
610
- total: 0
611
- // Timing is handled by emitContract internally if needed
612
- }
613
- };
614
- });
615
- const exitCode = handleResult(result, flags, (emitResult) => {
616
- if (flags.json === "object") {
617
- console.log(formatEmitJson(emitResult));
618
- } else {
619
- const output = formatEmitOutput(emitResult, flags);
620
- if (output) {
621
- console.log(output);
622
- }
623
- if (!flags.quiet) {
624
- console.log(formatSuccessMessage(flags));
625
- }
626
- }
627
- });
628
- process.exit(exitCode);
629
- });
630
- return command;
631
- }
6
+ createContractEmitCommand
7
+ } from "./chunk-4Q3MO4TK.js";
8
+ import "./chunk-3EODSNGS.js";
9
+ import "./chunk-HWYQOCAJ.js";
632
10
 
633
11
  // src/load-ts-contract.ts
634
- import { existsSync, unlinkSync, writeFileSync as writeFileSync2 } from "fs";
12
+ import { existsSync, unlinkSync, writeFileSync } from "fs";
635
13
  import { tmpdir } from "os";
636
14
  import { join } from "path";
637
15
  import { build } from "esbuild";
@@ -763,7 +141,7 @@ Only @prisma-next/* packages are allowed in contract files.`
763
141
  if (bundleContent === void 0) {
764
142
  throw new Error("Bundle content is undefined");
765
143
  }
766
- writeFileSync2(tempFile, bundleContent, "utf-8");
144
+ writeFileSync(tempFile, bundleContent, "utf-8");
767
145
  const module = await import(`file://${tempFile}`);
768
146
  unlinkSync(tempFile);
769
147
  let contract;