@prisma-next/cli 0.1.0-dev.16 → 0.1.0-dev.18

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/README.md CHANGED
@@ -221,20 +221,21 @@ Failure:
221
221
 
222
222
  **Family Requirements:**
223
223
 
224
- The family must provide a `create()` method in the family descriptor that returns a `FamilyInstance` with a `verify()` method:
224
+ The family must provide a `create()` method in the family descriptor that returns a `ControlFamilyInstance` with a `verify()` method:
225
225
 
226
226
  ```typescript
227
- interface FamilyDescriptor {
227
+ interface ControlFamilyDescriptor {
228
228
  create(options: {
229
- target: TargetDescriptor;
230
- adapter: AdapterDescriptor;
231
- extensions: ExtensionDescriptor[];
232
- }): FamilyInstance;
229
+ target: ControlTargetDescriptor;
230
+ adapter: ControlAdapterDescriptor;
231
+ driver: ControlDriverDescriptor;
232
+ extensions: ControlExtensionDescriptor[];
233
+ }): ControlFamilyInstance;
233
234
  }
234
235
 
235
- interface FamilyInstance {
236
+ interface ControlFamilyInstance {
236
237
  verify(options: {
237
- driver: ControlPlaneDriver;
238
+ driver: ControlDriverInstance;
238
239
  contractIR: ContractIR;
239
240
  expectedTargetId: string;
240
241
  contractPath: string;
@@ -377,11 +378,11 @@ sql schema (tables: 2)
377
378
  **Family Requirements:**
378
379
 
379
380
  The family must provide:
380
- 1. A `create()` method in the family descriptor that returns a `FamilyInstance` with an `introspect()` method
381
- 2. An optional `toSchemaView()` method on the `FamilyInstance` to project family-specific schema IR into `CoreSchemaView`
381
+ 1. A `create()` method in the family descriptor that returns a `ControlFamilyInstance` with an `introspect()` method
382
+ 2. An optional `toSchemaView()` method on the `ControlFamilyInstance` to project family-specific schema IR into `CoreSchemaView`
382
383
 
383
384
  ```typescript
384
- interface FamilyInstance {
385
+ interface ControlFamilyInstance {
385
386
  introspect(options: {
386
387
  driver: ControlDriverInstance;
387
388
  contractIR?: ContractIR;
@@ -583,10 +584,10 @@ The `db sign` command is idempotent and safe to run multiple times:
583
584
  - Safe to run in CI/deployment pipelines
584
585
 
585
586
  **Family Requirements:**
586
- The family must provide a `create()` method in the family descriptor that returns a `FamilyInstance` with `schemaVerify()` and `sign()` methods:
587
+ The family must provide a `create()` method in the family descriptor that returns a `ControlFamilyInstance` with `schemaVerify()` and `sign()` methods:
587
588
 
588
589
  ```typescript
589
- interface FamilyInstance {
590
+ interface ControlFamilyInstance {
590
591
  schemaVerify(options: {
591
592
  driver: ControlDriverInstance;
592
593
  contractIR: ContractIR;
@@ -131,4 +131,4 @@ function createContractEmitCommand() {
131
131
  export {
132
132
  createContractEmitCommand
133
133
  };
134
- //# sourceMappingURL=chunk-4W62XWA4.js.map
134
+ //# sourceMappingURL=chunk-XS2KZ6CJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/contract-emit.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, relative, resolve } from 'node:path';\nimport { errorContractConfigMissing } from '@prisma-next/core-control-plane/errors';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport { setCommandDescriptions } from '../utils/command-helpers';\nimport { parseGlobalFlags } from '../utils/global-flags';\nimport {\n formatCommandHelp,\n formatEmitJson,\n formatEmitOutput,\n formatStyledHeader,\n formatSuccessMessage,\n} from '../utils/output';\nimport { performAction } from '../utils/result';\nimport { handleResult } from '../utils/result-handler';\nimport { withSpinner } from '../utils/spinner';\n\ninterface ContractEmitOptions {\n readonly config?: string;\n readonly json?: string | boolean;\n readonly quiet?: boolean;\n readonly q?: boolean;\n readonly verbose?: boolean;\n readonly v?: boolean;\n readonly vv?: boolean;\n readonly trace?: boolean;\n readonly timestamps?: boolean;\n readonly color?: boolean;\n readonly 'no-color'?: boolean;\n}\n\nexport function createContractEmitCommand(): Command {\n const command = new Command('emit');\n setCommandDescriptions(\n command,\n 'Write your contract to JSON and sign it',\n 'Reads your contract source (TypeScript or Prisma schema) and emits contract.json and\\n' +\n 'contract.d.ts. The contract.json contains the canonical contract structure, and\\n' +\n 'contract.d.ts provides TypeScript types for type-safe query building.',\n );\n command\n .configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n })\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option('--json [format]', 'Output as JSON (object or ndjson)', false)\n .option('-q, --quiet', 'Quiet mode: errors only')\n .option('-v, --verbose', 'Verbose output: debug info, timings')\n .option('-vv, --trace', 'Trace output: deep internals, stack traces')\n .option('--timestamps', 'Add timestamps to output')\n .option('--color', 'Force color output')\n .option('--no-color', 'Disable color output')\n .action(async (options: ContractEmitOptions) => {\n const flags = parseGlobalFlags(options);\n\n const result = await performAction(async () => {\n // Load config\n const config = await loadConfig(options.config);\n\n // Resolve contract from config\n if (!config.contract) {\n throw errorContractConfigMissing({\n why: 'Config.contract is required for emit. Define it in your config: contract: { source: ..., output: ..., types: ... }',\n });\n }\n\n // Contract config is already normalized by defineConfig() with defaults applied\n const contractConfig = config.contract;\n\n // Resolve artifact paths from config (already normalized by defineConfig() with defaults)\n if (!contractConfig.output || !contractConfig.types) {\n throw errorContractConfigMissing({\n why: 'Contract config must have output and types paths. This should not happen if defineConfig() was used.',\n });\n }\n const outputJsonPath = resolve(contractConfig.output);\n const outputDtsPath = resolve(contractConfig.types);\n\n // Output header (only for human-readable output)\n if (flags.json !== 'object' && !flags.quiet) {\n // Normalize config path for display (match contract path format - no ./ prefix)\n const configPath = options.config\n ? relative(process.cwd(), resolve(options.config))\n : 'prisma-next.config.ts';\n // Convert absolute paths to relative paths for display\n const contractPath = relative(process.cwd(), outputJsonPath);\n const typesPath = relative(process.cwd(), outputDtsPath);\n const header = formatStyledHeader({\n command: 'contract emit',\n description: 'Write your contract to JSON and sign it',\n url: 'https://pris.ly/contract-emit',\n details: [\n { label: 'config', value: configPath },\n { label: 'contract', value: contractPath },\n { label: 'types', value: typesPath },\n ],\n flags,\n });\n console.log(header);\n }\n\n // Create family instance (assembles operation registry, type imports, extension IDs)\n // Note: emit command doesn't need driver, but ControlFamilyDescriptor.create() requires it\n // We'll need to provide a minimal driver descriptor or make driver optional for emit\n // For now, we'll require driver to be present in config even for emit\n if (!config.driver) {\n throw errorContractConfigMissing({\n why: 'Config.driver is required. Even though emit does not use the driver, it is required by ControlFamilyDescriptor.create()',\n });\n }\n const familyInstance = config.family.create({\n target: config.target,\n adapter: config.adapter,\n driver: config.driver,\n extensions: config.extensions ?? [],\n });\n\n // Resolve contract source from config (user's config handles loading)\n let contractRaw: unknown;\n if (typeof contractConfig.source === 'function') {\n contractRaw = await contractConfig.source();\n } else {\n contractRaw = contractConfig.source;\n }\n\n // Call emitContract on family instance (handles stripping mappings and validation internally)\n const emitResult = await withSpinner(\n () => familyInstance.emitContract({ contractIR: contractRaw }),\n {\n message: 'Emitting contract...',\n flags,\n },\n );\n\n // Create directories if needed\n mkdirSync(dirname(outputJsonPath), { recursive: true });\n mkdirSync(dirname(outputDtsPath), { recursive: true });\n\n // Write the results to files\n writeFileSync(outputJsonPath, emitResult.contractJson, 'utf-8');\n writeFileSync(outputDtsPath, emitResult.contractDts, 'utf-8');\n\n // Add blank line after all async operations if spinners were shown\n if (!flags.quiet && flags.json !== 'object' && process.stdout.isTTY) {\n console.log('');\n }\n\n // Return result with file paths for output formatting\n return {\n coreHash: emitResult.coreHash,\n profileHash: emitResult.profileHash,\n outDir: dirname(outputJsonPath),\n files: {\n json: outputJsonPath,\n dts: outputDtsPath,\n },\n timings: {\n total: 0, // Timing is handled by emitContract internally if needed\n },\n };\n });\n\n // Handle result - formats output and returns exit code\n const exitCode = handleResult(result, flags, (emitResult) => {\n // Output based on flags\n if (flags.json === 'object') {\n // JSON output to stdout\n console.log(formatEmitJson(emitResult));\n } else {\n // Human-readable output to stdout\n const output = formatEmitOutput(emitResult, flags);\n if (output) {\n console.log(output);\n }\n // Output success message\n if (!flags.quiet) {\n console.log(formatSuccessMessage(flags));\n }\n }\n });\n process.exit(exitCode);\n });\n\n return command;\n}\n"],"m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;AAGA,aAAO;AAAA,QACL,UAAU,WAAW;AAAA,QACrB,aAAa,WAAW;AAAA,QACxB,QAAQ,QAAQ,cAAc;AAAA,QAC9B,OAAO;AAAA,UACL,MAAM;AAAA,UACN,KAAK;AAAA,QACP;AAAA,QACA,SAAS;AAAA,UACP,OAAO;AAAA;AAAA,QACT;AAAA,MACF;AAAA,IACF,CAAC;AAGD,UAAM,WAAW,aAAa,QAAQ,OAAO,CAAC,eAAe;AAE3D,UAAI,MAAM,SAAS,UAAU;AAE3B,gBAAQ,IAAI,eAAe,UAAU,CAAC;AAAA,MACxC,OAAO;AAEL,cAAM,SAAS,iBAAiB,YAAY,KAAK;AACjD,YAAI,QAAQ;AACV,kBAAQ,IAAI,MAAM;AAAA,QACpB;AAEA,YAAI,CAAC,MAAM,OAAO;AAChB,kBAAQ,IAAI,qBAAqB,KAAK,CAAC;AAAA,QACzC;AAAA,MACF;AAAA,IACF,CAAC;AACD,YAAQ,KAAK,QAAQ;AAAA,EACvB,CAAC;AAEH,SAAO;AACT;","names":[]}
package/dist/cli.js CHANGED
@@ -1176,9 +1176,6 @@ function createContractEmitCommand() {
1176
1176
  import { readFile } from "fs/promises";
1177
1177
  import { relative as relative3, resolve as resolve3 } from "path";
1178
1178
  import { Command as Command2 } from "commander";
1179
- function hasMigrationSupport(target) {
1180
- return typeof target === "object" && target !== null && Object.hasOwn(target, "createPlanner") && typeof target["createPlanner"] === "function" && Object.hasOwn(target, "createRunner") && typeof target["createRunner"] === "function";
1181
- }
1182
1179
  function createDbInitCommand() {
1183
1180
  const command = new Command2("init");
1184
1181
  setCommandDescriptions(
@@ -1248,11 +1245,12 @@ function createDbInitCommand() {
1248
1245
  throw errorDriverRequired({ why: "Config.driver is required for db init" });
1249
1246
  }
1250
1247
  const driverDescriptor = config.driver;
1251
- if (!hasMigrationSupport(config.target)) {
1248
+ if (!config.target.migrations) {
1252
1249
  throw errorTargetMigrationNotSupported({
1253
- why: `Target "${config.target.id}" does not support migrations (missing createPlanner/createRunner)`
1250
+ why: `Target "${config.target.id}" does not support migrations`
1254
1251
  });
1255
1252
  }
1253
+ const migrations = config.target.migrations;
1256
1254
  const driver = await withSpinner(() => driverDescriptor.create(dbUrl), {
1257
1255
  message: "Connecting to database...",
1258
1256
  flags
@@ -1264,11 +1262,10 @@ function createDbInitCommand() {
1264
1262
  driver: driverDescriptor,
1265
1263
  extensions: config.extensions ?? []
1266
1264
  });
1267
- const typedFamilyInstance = familyInstance;
1268
- const contractIR = typedFamilyInstance.validateContractIR(contractJson);
1269
- const planner = config.target.createPlanner(familyInstance);
1270
- const runner = config.target.createRunner(familyInstance);
1271
- const schemaIR = await withSpinner(() => typedFamilyInstance.introspect({ driver }), {
1265
+ const contractIR = familyInstance.validateContractIR(contractJson);
1266
+ const planner = migrations.createPlanner(familyInstance);
1267
+ const runner = migrations.createRunner(familyInstance);
1268
+ const schemaIR = await withSpinner(() => familyInstance.introspect({ driver }), {
1272
1269
  message: "Introspecting database schema...",
1273
1270
  flags
1274
1271
  });
@@ -1411,8 +1408,7 @@ function createDbIntrospectCommand() {
1411
1408
  const contractPath = resolve4(config.contract.output);
1412
1409
  try {
1413
1410
  const contractJsonContent = await readFile2(contractPath, "utf-8");
1414
- const contractJson = JSON.parse(contractJsonContent);
1415
- contractIR = contractJson;
1411
+ contractIR = JSON.parse(contractJsonContent);
1416
1412
  } catch (error) {
1417
1413
  if (error instanceof Error && error.code !== "ENOENT") {
1418
1414
  throw errorUnexpected3(error.message, {
@@ -1460,14 +1456,13 @@ function createDbIntrospectCommand() {
1460
1456
  driver: driverDescriptor,
1461
1457
  extensions: config.extensions ?? []
1462
1458
  });
1463
- const typedFamilyInstance = familyInstance;
1464
1459
  if (contractIR) {
1465
- contractIR = typedFamilyInstance.validateContractIR(contractIR);
1460
+ contractIR = familyInstance.validateContractIR(contractIR);
1466
1461
  }
1467
1462
  let schemaIR;
1468
1463
  try {
1469
1464
  schemaIR = await withSpinner(
1470
- () => typedFamilyInstance.introspect({
1465
+ () => familyInstance.introspect({
1471
1466
  driver,
1472
1467
  contractIR
1473
1468
  }),
@@ -1482,9 +1477,9 @@ function createDbIntrospectCommand() {
1482
1477
  });
1483
1478
  }
1484
1479
  let schemaView;
1485
- if (typedFamilyInstance.toSchemaView) {
1480
+ if (familyInstance.toSchemaView) {
1486
1481
  try {
1487
- schemaView = typedFamilyInstance.toSchemaView(schemaIR);
1482
+ schemaView = familyInstance.toSchemaView(schemaIR);
1488
1483
  } catch (error) {
1489
1484
  if (flags.verbose) {
1490
1485
  console.error(
@@ -1621,12 +1616,11 @@ function createDbSchemaVerifyCommand() {
1621
1616
  driver: driverDescriptor,
1622
1617
  extensions: config.extensions ?? []
1623
1618
  });
1624
- const typedFamilyInstance = familyInstance;
1625
- const contractIR = typedFamilyInstance.validateContractIR(contractJson);
1619
+ const contractIR = familyInstance.validateContractIR(contractJson);
1626
1620
  let schemaVerifyResult;
1627
1621
  try {
1628
1622
  schemaVerifyResult = await withSpinner(
1629
- () => typedFamilyInstance.schemaVerify({
1623
+ () => familyInstance.schemaVerify({
1630
1624
  driver,
1631
1625
  contractIR,
1632
1626
  strict: options.strict ?? false,
@@ -1747,20 +1741,17 @@ function createDbSignCommand() {
1747
1741
  driver: driverDescriptor,
1748
1742
  extensions: config.extensions ?? []
1749
1743
  });
1750
- const typedFamilyInstance = familyInstance;
1751
- const contractIR = typedFamilyInstance.validateContractIR(contractJson);
1744
+ const contractIR = familyInstance.validateContractIR(contractJson);
1752
1745
  let schemaVerifyResult;
1753
1746
  try {
1754
1747
  schemaVerifyResult = await withSpinner(
1755
- async () => {
1756
- return await typedFamilyInstance.schemaVerify({
1757
- driver,
1758
- contractIR,
1759
- strict: false,
1760
- contractPath: contractPathAbsolute,
1761
- configPath
1762
- });
1763
- },
1748
+ () => familyInstance.schemaVerify({
1749
+ driver,
1750
+ contractIR,
1751
+ strict: false,
1752
+ contractPath: contractPathAbsolute,
1753
+ configPath
1754
+ }),
1764
1755
  {
1765
1756
  message: "Verifying database satisfies contract",
1766
1757
  flags
@@ -1777,14 +1768,12 @@ function createDbSignCommand() {
1777
1768
  let signResult;
1778
1769
  try {
1779
1770
  signResult = await withSpinner(
1780
- async () => {
1781
- return await typedFamilyInstance.sign({
1782
- driver,
1783
- contractIR,
1784
- contractPath: contractPathAbsolute,
1785
- configPath
1786
- });
1787
- },
1771
+ () => familyInstance.sign({
1772
+ driver,
1773
+ contractIR,
1774
+ contractPath: contractPathAbsolute,
1775
+ configPath
1776
+ }),
1788
1777
  {
1789
1778
  message: "Signing database...",
1790
1779
  flags
@@ -1919,12 +1908,11 @@ function createDbVerifyCommand() {
1919
1908
  driver: driverDescriptor,
1920
1909
  extensions: config.extensions ?? []
1921
1910
  });
1922
- const typedFamilyInstance = familyInstance;
1923
- const contractIR = typedFamilyInstance.validateContractIR(contractJson);
1911
+ const contractIR = familyInstance.validateContractIR(contractJson);
1924
1912
  let verifyResult;
1925
1913
  try {
1926
1914
  verifyResult = await withSpinner(
1927
- () => typedFamilyInstance.verify({
1915
+ () => familyInstance.verify({
1928
1916
  driver,
1929
1917
  contractIR,
1930
1918
  expectedTargetId: config.target.targetId,