@prisma-next/cli 0.1.0-dev.17 → 0.1.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.
- package/README.md +14 -13
- package/dist/{chunk-4W62XWA4.js → chunk-XS2KZ6CJ.js} +1 -1
- package/dist/chunk-XS2KZ6CJ.js.map +1 -0
- package/dist/cli.js +25 -35
- package/dist/cli.js.map +1 -1
- package/dist/commands/contract-emit.js +1 -1
- package/dist/commands/db-init.js +2 -3
- package/dist/commands/db-init.js.map +1 -1
- package/dist/commands/db-introspect.js +5 -7
- package/dist/commands/db-introspect.js.map +1 -1
- package/dist/commands/db-schema-verify.js +2 -3
- package/dist/commands/db-schema-verify.js.map +1 -1
- package/dist/commands/db-sign.js +14 -19
- package/dist/commands/db-sign.js.map +1 -1
- package/dist/commands/db-verify.js +2 -3
- package/dist/commands/db-verify.js.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +12 -12
- package/dist/chunk-4W62XWA4.js.map +0 -1
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 `
|
|
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
|
|
227
|
+
interface ControlFamilyDescriptor {
|
|
228
228
|
create(options: {
|
|
229
|
-
target:
|
|
230
|
-
adapter:
|
|
231
|
-
|
|
232
|
-
|
|
229
|
+
target: ControlTargetDescriptor;
|
|
230
|
+
adapter: ControlAdapterDescriptor;
|
|
231
|
+
driver: ControlDriverDescriptor;
|
|
232
|
+
extensions: ControlExtensionDescriptor[];
|
|
233
|
+
}): ControlFamilyInstance;
|
|
233
234
|
}
|
|
234
235
|
|
|
235
|
-
interface
|
|
236
|
+
interface ControlFamilyInstance {
|
|
236
237
|
verify(options: {
|
|
237
|
-
driver:
|
|
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 `
|
|
381
|
-
2. An optional `toSchemaView()` method on the `
|
|
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
|
|
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 `
|
|
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
|
|
590
|
+
interface ControlFamilyInstance {
|
|
590
591
|
schemaVerify(options: {
|
|
591
592
|
driver: ControlDriverInstance;
|
|
592
593
|
contractIR: ContractIR;
|
|
@@ -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"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,WAAW,qBAAqB;AACzC,SAAS,SAAS,UAAU,eAAe;AAC3C,SAAS,kCAAkC;AAC3C,SAAS,eAAe;AA6BjB,SAAS,4BAAqC;AACnD,QAAM,UAAU,IAAI,QAAQ,MAAM;AAClC;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,EAGF;AACA,UACG,cAAc;AAAA,IACb,YAAY,CAAC,QAAQ;AACnB,YAAM,QAAQ,iBAAiB,CAAC,CAAC;AACjC,aAAO,kBAAkB,EAAE,SAAS,KAAK,MAAM,CAAC;AAAA,IAClD;AAAA,EACF,CAAC,EACA,OAAO,mBAAmB,+BAA+B,EACzD,OAAO,mBAAmB,qCAAqC,KAAK,EACpE,OAAO,eAAe,yBAAyB,EAC/C,OAAO,iBAAiB,qCAAqC,EAC7D,OAAO,gBAAgB,4CAA4C,EACnE,OAAO,gBAAgB,0BAA0B,EACjD,OAAO,WAAW,oBAAoB,EACtC,OAAO,cAAc,sBAAsB,EAC3C,OAAO,OAAO,YAAiC;AAC9C,UAAM,QAAQ,iBAAiB,OAAO;AAEtC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DbInitCommand() {
|
|
|
1262
1262
|
driver: driverDescriptor,
|
|
1263
1263
|
extensions: config.extensions ?? []
|
|
1264
1264
|
});
|
|
1265
|
-
const
|
|
1266
|
-
const contractIR = typedFamilyInstance.validateContractIR(contractJson);
|
|
1265
|
+
const contractIR = familyInstance.validateContractIR(contractJson);
|
|
1267
1266
|
const planner = migrations.createPlanner(familyInstance);
|
|
1268
1267
|
const runner = migrations.createRunner(familyInstance);
|
|
1269
|
-
const schemaIR = await withSpinner(() =>
|
|
1268
|
+
const schemaIR = await withSpinner(() => familyInstance.introspect({ driver }), {
|
|
1270
1269
|
message: "Introspecting database schema...",
|
|
1271
1270
|
flags
|
|
1272
1271
|
});
|
|
@@ -1409,8 +1408,7 @@ function createDbIntrospectCommand() {
|
|
|
1409
1408
|
const contractPath = resolve4(config.contract.output);
|
|
1410
1409
|
try {
|
|
1411
1410
|
const contractJsonContent = await readFile2(contractPath, "utf-8");
|
|
1412
|
-
|
|
1413
|
-
contractIR = contractJson;
|
|
1411
|
+
contractIR = JSON.parse(contractJsonContent);
|
|
1414
1412
|
} catch (error) {
|
|
1415
1413
|
if (error instanceof Error && error.code !== "ENOENT") {
|
|
1416
1414
|
throw errorUnexpected3(error.message, {
|
|
@@ -1458,14 +1456,13 @@ function createDbIntrospectCommand() {
|
|
|
1458
1456
|
driver: driverDescriptor,
|
|
1459
1457
|
extensions: config.extensions ?? []
|
|
1460
1458
|
});
|
|
1461
|
-
const typedFamilyInstance = familyInstance;
|
|
1462
1459
|
if (contractIR) {
|
|
1463
|
-
contractIR =
|
|
1460
|
+
contractIR = familyInstance.validateContractIR(contractIR);
|
|
1464
1461
|
}
|
|
1465
1462
|
let schemaIR;
|
|
1466
1463
|
try {
|
|
1467
1464
|
schemaIR = await withSpinner(
|
|
1468
|
-
() =>
|
|
1465
|
+
() => familyInstance.introspect({
|
|
1469
1466
|
driver,
|
|
1470
1467
|
contractIR
|
|
1471
1468
|
}),
|
|
@@ -1480,9 +1477,9 @@ function createDbIntrospectCommand() {
|
|
|
1480
1477
|
});
|
|
1481
1478
|
}
|
|
1482
1479
|
let schemaView;
|
|
1483
|
-
if (
|
|
1480
|
+
if (familyInstance.toSchemaView) {
|
|
1484
1481
|
try {
|
|
1485
|
-
schemaView =
|
|
1482
|
+
schemaView = familyInstance.toSchemaView(schemaIR);
|
|
1486
1483
|
} catch (error) {
|
|
1487
1484
|
if (flags.verbose) {
|
|
1488
1485
|
console.error(
|
|
@@ -1619,12 +1616,11 @@ function createDbSchemaVerifyCommand() {
|
|
|
1619
1616
|
driver: driverDescriptor,
|
|
1620
1617
|
extensions: config.extensions ?? []
|
|
1621
1618
|
});
|
|
1622
|
-
const
|
|
1623
|
-
const contractIR = typedFamilyInstance.validateContractIR(contractJson);
|
|
1619
|
+
const contractIR = familyInstance.validateContractIR(contractJson);
|
|
1624
1620
|
let schemaVerifyResult;
|
|
1625
1621
|
try {
|
|
1626
1622
|
schemaVerifyResult = await withSpinner(
|
|
1627
|
-
() =>
|
|
1623
|
+
() => familyInstance.schemaVerify({
|
|
1628
1624
|
driver,
|
|
1629
1625
|
contractIR,
|
|
1630
1626
|
strict: options.strict ?? false,
|
|
@@ -1745,20 +1741,17 @@ function createDbSignCommand() {
|
|
|
1745
1741
|
driver: driverDescriptor,
|
|
1746
1742
|
extensions: config.extensions ?? []
|
|
1747
1743
|
});
|
|
1748
|
-
const
|
|
1749
|
-
const contractIR = typedFamilyInstance.validateContractIR(contractJson);
|
|
1744
|
+
const contractIR = familyInstance.validateContractIR(contractJson);
|
|
1750
1745
|
let schemaVerifyResult;
|
|
1751
1746
|
try {
|
|
1752
1747
|
schemaVerifyResult = await withSpinner(
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
});
|
|
1761
|
-
},
|
|
1748
|
+
() => familyInstance.schemaVerify({
|
|
1749
|
+
driver,
|
|
1750
|
+
contractIR,
|
|
1751
|
+
strict: false,
|
|
1752
|
+
contractPath: contractPathAbsolute,
|
|
1753
|
+
configPath
|
|
1754
|
+
}),
|
|
1762
1755
|
{
|
|
1763
1756
|
message: "Verifying database satisfies contract",
|
|
1764
1757
|
flags
|
|
@@ -1775,14 +1768,12 @@ function createDbSignCommand() {
|
|
|
1775
1768
|
let signResult;
|
|
1776
1769
|
try {
|
|
1777
1770
|
signResult = await withSpinner(
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
});
|
|
1785
|
-
},
|
|
1771
|
+
() => familyInstance.sign({
|
|
1772
|
+
driver,
|
|
1773
|
+
contractIR,
|
|
1774
|
+
contractPath: contractPathAbsolute,
|
|
1775
|
+
configPath
|
|
1776
|
+
}),
|
|
1786
1777
|
{
|
|
1787
1778
|
message: "Signing database...",
|
|
1788
1779
|
flags
|
|
@@ -1917,12 +1908,11 @@ function createDbVerifyCommand() {
|
|
|
1917
1908
|
driver: driverDescriptor,
|
|
1918
1909
|
extensions: config.extensions ?? []
|
|
1919
1910
|
});
|
|
1920
|
-
const
|
|
1921
|
-
const contractIR = typedFamilyInstance.validateContractIR(contractJson);
|
|
1911
|
+
const contractIR = familyInstance.validateContractIR(contractJson);
|
|
1922
1912
|
let verifyResult;
|
|
1923
1913
|
try {
|
|
1924
1914
|
verifyResult = await withSpinner(
|
|
1925
|
-
() =>
|
|
1915
|
+
() => familyInstance.verify({
|
|
1926
1916
|
driver,
|
|
1927
1917
|
contractIR,
|
|
1928
1918
|
expectedTargetId: config.target.targetId,
|