@prisma-next/cli 0.3.0-dev.5 → 0.3.0-dev.53
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 +145 -74
- package/dist/cli.d.mts +1 -0
- package/dist/cli.js +1 -2376
- package/dist/cli.mjs +169 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/client-BSZKpZTF.mjs +711 -0
- package/dist/client-BSZKpZTF.mjs.map +1 -0
- package/dist/commands/contract-emit.d.mts +7 -0
- package/dist/commands/contract-emit.d.mts.map +1 -0
- package/dist/commands/contract-emit.mjs +147 -0
- package/dist/commands/contract-emit.mjs.map +1 -0
- package/dist/commands/db-init.d.mts +7 -0
- package/dist/commands/db-init.d.mts.map +1 -0
- package/dist/commands/db-init.mjs +179 -0
- package/dist/commands/db-init.mjs.map +1 -0
- package/dist/commands/db-introspect.d.mts +7 -0
- package/dist/commands/db-introspect.d.mts.map +1 -0
- package/dist/commands/db-introspect.mjs +120 -0
- package/dist/commands/db-introspect.mjs.map +1 -0
- package/dist/commands/db-schema-verify.d.mts +7 -0
- package/dist/commands/db-schema-verify.d.mts.map +1 -0
- package/dist/commands/db-schema-verify.mjs +116 -0
- package/dist/commands/db-schema-verify.mjs.map +1 -0
- package/dist/commands/db-sign.d.mts +7 -0
- package/dist/commands/db-sign.d.mts.map +1 -0
- package/dist/commands/db-sign.mjs +138 -0
- package/dist/commands/db-sign.mjs.map +1 -0
- package/dist/commands/db-verify.d.mts +7 -0
- package/dist/commands/db-verify.d.mts.map +1 -0
- package/dist/commands/db-verify.mjs +129 -0
- package/dist/commands/db-verify.mjs.map +1 -0
- package/dist/config-loader-BJ8HsEdA.mjs +42 -0
- package/dist/config-loader-BJ8HsEdA.mjs.map +1 -0
- package/dist/{config-loader.d.ts → config-loader.d.mts} +8 -3
- package/dist/config-loader.d.mts.map +1 -0
- package/dist/config-loader.mjs +3 -0
- package/dist/exports/config-types.d.mts +2 -0
- package/dist/exports/config-types.mjs +3 -0
- package/dist/exports/control-api.d.mts +433 -0
- package/dist/exports/control-api.d.mts.map +1 -0
- package/dist/exports/control-api.mjs +96 -0
- package/dist/exports/control-api.mjs.map +1 -0
- package/dist/{load-ts-contract.d.ts → exports/index.d.mts} +10 -5
- package/dist/exports/index.d.mts.map +1 -0
- package/dist/exports/index.mjs +132 -0
- package/dist/exports/index.mjs.map +1 -0
- package/dist/result-handler-BZPY7HX4.mjs +1029 -0
- package/dist/result-handler-BZPY7HX4.mjs.map +1 -0
- package/package.json +48 -37
- package/src/commands/contract-emit.ts +205 -111
- package/src/commands/db-init.ts +258 -359
- package/src/commands/db-introspect.ts +151 -184
- package/src/commands/db-schema-verify.ts +151 -149
- package/src/commands/db-sign.ts +202 -200
- package/src/commands/db-verify.ts +181 -155
- package/src/control-api/client.ts +610 -0
- package/src/control-api/operations/contract-emit.ts +161 -0
- package/src/control-api/operations/db-init.ts +281 -0
- package/src/control-api/types.ts +475 -0
- package/src/exports/control-api.ts +48 -0
- package/src/load-ts-contract.ts +16 -11
- package/src/utils/cli-errors.ts +1 -1
- package/src/utils/framework-components.ts +11 -30
- package/src/utils/output.ts +16 -10
- package/src/utils/progress-adapter.ts +86 -0
- package/dist/chunk-464LNZCE.js +0 -134
- package/dist/chunk-464LNZCE.js.map +0 -1
- package/dist/chunk-BZMBKEEQ.js +0 -997
- package/dist/chunk-BZMBKEEQ.js.map +0 -1
- package/dist/chunk-HWYQOCAJ.js +0 -47
- package/dist/chunk-HWYQOCAJ.js.map +0 -1
- package/dist/chunk-ZKYEJROM.js +0 -94
- package/dist/chunk-ZKYEJROM.js.map +0 -1
- package/dist/cli.d.ts +0 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/commands/contract-emit.d.ts +0 -3
- package/dist/commands/contract-emit.d.ts.map +0 -1
- package/dist/commands/contract-emit.js +0 -9
- package/dist/commands/contract-emit.js.map +0 -1
- package/dist/commands/db-init.d.ts +0 -3
- package/dist/commands/db-init.d.ts.map +0 -1
- package/dist/commands/db-init.js +0 -341
- package/dist/commands/db-init.js.map +0 -1
- package/dist/commands/db-introspect.d.ts +0 -3
- package/dist/commands/db-introspect.d.ts.map +0 -1
- package/dist/commands/db-introspect.js +0 -190
- package/dist/commands/db-introspect.js.map +0 -1
- package/dist/commands/db-schema-verify.d.ts +0 -3
- package/dist/commands/db-schema-verify.d.ts.map +0 -1
- package/dist/commands/db-schema-verify.js +0 -164
- package/dist/commands/db-schema-verify.js.map +0 -1
- package/dist/commands/db-sign.d.ts +0 -3
- package/dist/commands/db-sign.d.ts.map +0 -1
- package/dist/commands/db-sign.js +0 -199
- package/dist/commands/db-sign.js.map +0 -1
- package/dist/commands/db-verify.d.ts +0 -3
- package/dist/commands/db-verify.d.ts.map +0 -1
- package/dist/commands/db-verify.js +0 -173
- package/dist/commands/db-verify.js.map +0 -1
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/config-loader.js +0 -7
- package/dist/config-loader.js.map +0 -1
- package/dist/exports/config-types.d.ts +0 -3
- package/dist/exports/config-types.d.ts.map +0 -1
- package/dist/exports/config-types.js +0 -6
- package/dist/exports/config-types.js.map +0 -1
- package/dist/exports/index.d.ts +0 -4
- package/dist/exports/index.d.ts.map +0 -1
- package/dist/exports/index.js +0 -175
- package/dist/exports/index.js.map +0 -1
- package/dist/load-ts-contract.d.ts.map +0 -1
- package/dist/utils/action.d.ts +0 -16
- package/dist/utils/action.d.ts.map +0 -1
- package/dist/utils/cli-errors.d.ts +0 -7
- package/dist/utils/cli-errors.d.ts.map +0 -1
- package/dist/utils/command-helpers.d.ts +0 -12
- package/dist/utils/command-helpers.d.ts.map +0 -1
- package/dist/utils/framework-components.d.ts +0 -81
- package/dist/utils/framework-components.d.ts.map +0 -1
- package/dist/utils/global-flags.d.ts +0 -25
- package/dist/utils/global-flags.d.ts.map +0 -1
- package/dist/utils/output.d.ts +0 -142
- package/dist/utils/output.d.ts.map +0 -1
- package/dist/utils/result-handler.d.ts +0 -15
- package/dist/utils/result-handler.d.ts.map +0 -1
- package/dist/utils/spinner.d.ts +0 -29
- package/dist/utils/spinner.d.ts.map +0 -1
- package/src/utils/action.ts +0 -43
- package/src/utils/spinner.ts +0 -67
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-verify.mjs","names":["details: Array<{ label: string; value: string }>","contractJsonContent: string","contractJson: Record<string, unknown>","exitCode"],"sources":["../../src/commands/db-verify.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { relative, resolve } from 'node:path';\nimport type { VerifyDatabaseResult } from '@prisma-next/core-control-plane/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { notOk, ok, type Result } from '@prisma-next/utils/result';\nimport { Command } from 'commander';\nimport { loadConfig } from '../config-loader';\nimport { createControlClient } from '../control-api/client';\nimport {\n CliStructuredError,\n errorContractValidationFailed,\n errorDatabaseConnectionRequired,\n errorDriverRequired,\n errorFileNotFound,\n errorHashMismatch,\n errorJsonFormatNotSupported,\n errorMarkerMissing,\n errorRuntime,\n errorTargetMismatch,\n errorUnexpected,\n} from '../utils/cli-errors';\nimport { setCommandDescriptions } from '../utils/command-helpers';\nimport { type GlobalFlags, parseGlobalFlags } from '../utils/global-flags';\nimport {\n formatCommandHelp,\n formatStyledHeader,\n formatVerifyJson,\n formatVerifyOutput,\n} from '../utils/output';\nimport { createProgressAdapter } from '../utils/progress-adapter';\nimport { handleResult } from '../utils/result-handler';\n\ninterface DbVerifyOptions {\n readonly db?: string;\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\n/**\n * Maps a VerifyDatabaseResult failure to a CliStructuredError.\n */\nfunction mapVerifyFailure(verifyResult: VerifyDatabaseResult): CliStructuredError {\n if (!verifyResult.ok && verifyResult.code) {\n if (verifyResult.code === 'PN-RTM-3001') {\n return errorMarkerMissing();\n }\n if (verifyResult.code === 'PN-RTM-3002') {\n return errorHashMismatch({\n expected: verifyResult.contract.storageHash,\n ...ifDefined('actual', verifyResult.marker?.storageHash),\n });\n }\n if (verifyResult.code === 'PN-RTM-3003') {\n return errorTargetMismatch(\n verifyResult.target.expected,\n verifyResult.target.actual ?? 'unknown',\n );\n }\n // Unknown code - fall through to runtime error\n }\n return errorRuntime(verifyResult.summary);\n}\n\n/**\n * Executes the db verify command and returns a structured Result.\n */\nasync function executeDbVerifyCommand(\n options: DbVerifyOptions,\n flags: GlobalFlags,\n): Promise<Result<VerifyDatabaseResult, CliStructuredError>> {\n // Load config\n const config = await loadConfig(options.config);\n const configPath = options.config\n ? relative(process.cwd(), resolve(options.config))\n : 'prisma-next.config.ts';\n const contractPathAbsolute = config.contract?.output\n ? resolve(config.contract.output)\n : resolve('src/prisma/contract.json');\n const contractPath = relative(process.cwd(), contractPathAbsolute);\n\n // Output header\n if (flags.json !== 'object' && !flags.quiet) {\n const details: Array<{ label: string; value: string }> = [\n { label: 'config', value: configPath },\n { label: 'contract', value: contractPath },\n ];\n if (options.db) {\n details.push({ label: 'database', value: options.db });\n }\n const header = formatStyledHeader({\n command: 'db verify',\n description: 'Check whether the database has been signed with your contract',\n url: 'https://pris.ly/db-verify',\n details,\n flags,\n });\n console.log(header);\n }\n\n // Load contract file\n let contractJsonContent: string;\n try {\n contractJsonContent = await readFile(contractPathAbsolute, 'utf-8');\n } catch (error) {\n if (error instanceof Error && (error as { code?: string }).code === 'ENOENT') {\n return notOk(\n errorFileNotFound(contractPathAbsolute, {\n why: `Contract file not found at ${contractPathAbsolute}`,\n fix: `Run \\`prisma-next contract emit\\` to generate ${contractPath}, or update \\`config.contract.output\\` in ${configPath}`,\n }),\n );\n }\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Failed to read contract file: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n }\n\n let contractJson: Record<string, unknown>;\n try {\n contractJson = JSON.parse(contractJsonContent) as Record<string, unknown>;\n } catch (error) {\n return notOk(\n errorContractValidationFailed(\n `Contract JSON is invalid: ${error instanceof Error ? error.message : String(error)}`,\n { where: { path: contractPathAbsolute } },\n ),\n );\n }\n\n // Resolve database connection (--db flag or config.db.connection)\n const dbConnection = options.db ?? config.db?.connection;\n if (!dbConnection) {\n return notOk(\n errorDatabaseConnectionRequired({\n why: `Database connection is required for db verify (set db.connection in ${configPath}, or pass --db <url>)`,\n }),\n );\n }\n\n // Check for driver\n if (!config.driver) {\n return notOk(errorDriverRequired({ why: 'Config.driver is required for db verify' }));\n }\n\n // Create control client\n const client = createControlClient({\n family: config.family,\n target: config.target,\n adapter: config.adapter,\n driver: config.driver,\n extensionPacks: config.extensionPacks ?? [],\n });\n\n // Create progress adapter\n const onProgress = createProgressAdapter({ flags });\n\n try {\n const verifyResult = await client.verify({\n contractIR: contractJson,\n connection: dbConnection,\n onProgress,\n });\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 // If verification failed, map to CLI structured error\n if (!verifyResult.ok) {\n return notOk(mapVerifyFailure(verifyResult));\n }\n\n return ok(verifyResult);\n } catch (error) {\n // Driver already throws CliStructuredError for connection failures\n if (error instanceof CliStructuredError) {\n return notOk(error);\n }\n\n // Wrap unexpected errors\n return notOk(\n errorUnexpected(error instanceof Error ? error.message : String(error), {\n why: `Unexpected error during db verify: ${error instanceof Error ? error.message : String(error)}`,\n }),\n );\n } finally {\n await client.close();\n }\n}\n\nexport function createDbVerifyCommand(): Command {\n const command = new Command('verify');\n setCommandDescriptions(\n command,\n 'Check whether the database has been signed with your contract',\n 'Verifies that your database schema matches the emitted contract. Checks table structures,\\n' +\n 'column types, constraints, and codec coverage. Reports any mismatches or missing codecs.',\n );\n command\n .configureHelp({\n formatHelp: (cmd) => {\n const flags = parseGlobalFlags({});\n return formatCommandHelp({ command: cmd, flags });\n },\n })\n .option('--db <url>', 'Database connection string')\n .option('--config <path>', 'Path to prisma-next.config.ts')\n .option('--json [format]', 'Output as JSON (object)', 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: DbVerifyOptions) => {\n const flags = parseGlobalFlags(options);\n\n // Validate JSON format option\n if (flags.json === 'ndjson') {\n const result = notOk(\n errorJsonFormatNotSupported({\n command: 'db verify',\n format: 'ndjson',\n supportedFormats: ['object'],\n }),\n );\n const exitCode = handleResult(result, flags);\n process.exit(exitCode);\n }\n\n const result = await executeDbVerifyCommand(options, flags);\n\n const exitCode = handleResult(result, flags, (verifyResult) => {\n if (flags.json === 'object') {\n console.log(formatVerifyJson(verifyResult));\n } else {\n const output = formatVerifyOutput(verifyResult, flags);\n if (output) {\n console.log(output);\n }\n }\n });\n process.exit(exitCode);\n });\n\n return command;\n}\n"],"mappings":";;;;;;;;;;;;;AAkDA,SAAS,iBAAiB,cAAwD;AAChF,KAAI,CAAC,aAAa,MAAM,aAAa,MAAM;AACzC,MAAI,aAAa,SAAS,cACxB,QAAO,oBAAoB;AAE7B,MAAI,aAAa,SAAS,cACxB,QAAO,kBAAkB;GACvB,UAAU,aAAa,SAAS;GAChC,GAAG,UAAU,UAAU,aAAa,QAAQ,YAAY;GACzD,CAAC;AAEJ,MAAI,aAAa,SAAS,cACxB,QAAO,oBACL,aAAa,OAAO,UACpB,aAAa,OAAO,UAAU,UAC/B;;AAIL,QAAO,aAAa,aAAa,QAAQ;;;;;AAM3C,eAAe,uBACb,SACA,OAC2D;CAE3D,MAAM,SAAS,MAAM,WAAW,QAAQ,OAAO;CAC/C,MAAM,aAAa,QAAQ,SACvB,SAAS,QAAQ,KAAK,EAAE,QAAQ,QAAQ,OAAO,CAAC,GAChD;CACJ,MA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AAQ,iBAAiB,QAAQ;AAGvC,MAAI,MAAM,SAAS,UAAU;GAQ3B,MAAMC,aAAW,aAPF,MACb,4BAA4B;IAC1B,SAAS;IACT,QAAQ;IACR,kBAAkB,CAAC,SAAS;IAC7B,CAAC,CACH,EACqC,MAAM;AAC5C,WAAQ,KAAKA,WAAS;;EAKxB,MAAM,WAAW,aAFF,MAAM,uBAAuB,SAAS,MAAM,EAErB,QAAQ,iBAAiB;AAC7D,OAAI,MAAM,SAAS,SACjB,SAAQ,IAAI,iBAAiB,aAAa,CAAC;QACtC;IACL,MAAM,SAAS,mBAAmB,cAAc,MAAM;AACtD,QAAI,OACF,SAAQ,IAAI,OAAO;;IAGvB;AACF,UAAQ,KAAK,SAAS;GACtB;AAEJ,QAAO"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { errorConfigFileNotFound, errorUnexpected } from "@prisma-next/core-control-plane/errors";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { validateConfig } from "@prisma-next/core-control-plane/config-validation";
|
|
4
|
+
import { loadConfig } from "c12";
|
|
5
|
+
|
|
6
|
+
//#region src/config-loader.ts
|
|
7
|
+
/**
|
|
8
|
+
* Loads the Prisma Next config from a TypeScript file.
|
|
9
|
+
* Supports both default export and named export.
|
|
10
|
+
* Uses c12 to automatically handle TypeScript compilation and config file discovery.
|
|
11
|
+
*
|
|
12
|
+
* @param configPath - Optional path to config file. Defaults to `./prisma-next.config.ts` in current directory.
|
|
13
|
+
* @returns The loaded config object.
|
|
14
|
+
* @throws Error if config file doesn't exist or is invalid.
|
|
15
|
+
*/
|
|
16
|
+
async function loadConfig$1(configPath) {
|
|
17
|
+
try {
|
|
18
|
+
const cwd = process.cwd();
|
|
19
|
+
const resolvedConfigPath = configPath ? resolve(cwd, configPath) : void 0;
|
|
20
|
+
const configCwd = resolvedConfigPath ? dirname(resolvedConfigPath) : cwd;
|
|
21
|
+
const result = await loadConfig({
|
|
22
|
+
name: "prisma-next",
|
|
23
|
+
...resolvedConfigPath ? { configFile: resolvedConfigPath } : {},
|
|
24
|
+
cwd: configCwd
|
|
25
|
+
});
|
|
26
|
+
if (resolvedConfigPath && result.configFile !== resolvedConfigPath) throw errorConfigFileNotFound(resolvedConfigPath);
|
|
27
|
+
if (!result.config || Object.keys(result.config).length === 0) throw errorConfigFileNotFound(result.configFile || resolvedConfigPath || configPath);
|
|
28
|
+
validateConfig(result.config);
|
|
29
|
+
return result.config;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error instanceof Error && "code" in error && typeof error.code === "string") throw error;
|
|
32
|
+
if (error instanceof Error) {
|
|
33
|
+
if (error.message.includes("not found") || error.message.includes("Cannot find") || error.message.includes("ENOENT")) throw errorConfigFileNotFound(configPath ? resolve(process.cwd(), configPath) : void 0, { why: error.message });
|
|
34
|
+
throw errorUnexpected(error.message, { why: `Failed to load config: ${error.message}` });
|
|
35
|
+
}
|
|
36
|
+
throw errorUnexpected(String(error));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { loadConfig$1 as t };
|
|
42
|
+
//# sourceMappingURL=config-loader-BJ8HsEdA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-loader-BJ8HsEdA.mjs","names":["loadConfig","loadConfigC12"],"sources":["../src/config-loader.ts"],"sourcesContent":["import { dirname, resolve } from 'node:path';\nimport type { PrismaNextConfig } from '@prisma-next/core-control-plane/config-types';\nimport { validateConfig } from '@prisma-next/core-control-plane/config-validation';\nimport { errorConfigFileNotFound, errorUnexpected } from '@prisma-next/core-control-plane/errors';\nimport { loadConfig as loadConfigC12 } from 'c12';\n\n/**\n * Loads the Prisma Next config from a TypeScript file.\n * Supports both default export and named export.\n * Uses c12 to automatically handle TypeScript compilation and config file discovery.\n *\n * @param configPath - Optional path to config file. Defaults to `./prisma-next.config.ts` in current directory.\n * @returns The loaded config object.\n * @throws Error if config file doesn't exist or is invalid.\n */\nexport async function loadConfig(configPath?: string): Promise<PrismaNextConfig> {\n try {\n const cwd = process.cwd();\n // Resolve config path to absolute path and set cwd to config directory when path is provided\n const resolvedConfigPath = configPath ? resolve(cwd, configPath) : undefined;\n const configCwd = resolvedConfigPath ? dirname(resolvedConfigPath) : cwd;\n\n const result = await loadConfigC12<PrismaNextConfig>({\n name: 'prisma-next',\n ...(resolvedConfigPath ? { configFile: resolvedConfigPath } : {}),\n cwd: configCwd,\n });\n\n // When a specific config file was requested, verify it was actually loaded\n // (c12 falls back to searching by name if the specified file doesn't exist)\n if (resolvedConfigPath && result.configFile !== resolvedConfigPath) {\n throw errorConfigFileNotFound(resolvedConfigPath);\n }\n\n // Check if config is missing or empty (c12 may return empty object when file doesn't exist)\n if (!result.config || Object.keys(result.config).length === 0) {\n // Use c12's configFile if available, otherwise use explicit configPath, otherwise omit path\n const displayPath = result.configFile || resolvedConfigPath || configPath;\n throw errorConfigFileNotFound(displayPath);\n }\n\n // Validate config structure\n validateConfig(result.config);\n\n return result.config;\n } catch (error) {\n // Re-throw structured errors as-is\n if (\n error instanceof Error &&\n 'code' in error &&\n typeof (error as { code: string }).code === 'string'\n ) {\n throw error;\n }\n\n if (error instanceof Error) {\n // Check for file not found errors\n if (\n error.message.includes('not found') ||\n error.message.includes('Cannot find') ||\n error.message.includes('ENOENT')\n ) {\n // Use resolved path if available, otherwise use original configPath\n const displayPath = configPath ? resolve(process.cwd(), configPath) : undefined;\n throw errorConfigFileNotFound(displayPath, {\n why: error.message,\n });\n }\n // For other errors, wrap in unexpected error\n throw errorUnexpected(error.message, {\n why: `Failed to load config: ${error.message}`,\n });\n }\n throw errorUnexpected(String(error));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,eAAsBA,aAAW,YAAgD;AAC/E,KAAI;EACF,MAAM,MAAM,QAAQ,KAAK;EAEzB,MAAM,qBAAqB,aAAa,QAAQ,KAAK,WAAW,GAAG;EACnE,MAAM,YAAY,qBAAqB,QAAQ,mBAAmB,GAAG;EAErE,MAAM,SAAS,MAAMC,WAAgC;GACnD,MAAM;GACN,GAAI,qBAAqB,EAAE,YAAY,oBAAoB,GAAG,EAAE;GAChE,KAAK;GACN,CAAC;AAIF,MAAI,sBAAsB,OAAO,eAAe,mBAC9C,OAAM,wBAAwB,mBAAmB;AAInD,MAAI,CAAC,OAAO,UAAU,OAAO,KAAK,OAAO,OAAO,CAAC,WAAW,EAG1D,OAAM,wBADc,OAAO,cAAc,sBAAsB,WACrB;AAI5C,iBAAe,OAAO,OAAO;AAE7B,SAAO,OAAO;UACP,OAAO;AAEd,MACE,iBAAiB,SACjB,UAAU,SACV,OAAQ,MAA2B,SAAS,SAE5C,OAAM;AAGR,MAAI,iBAAiB,OAAO;AAE1B,OACE,MAAM,QAAQ,SAAS,YAAY,IACnC,MAAM,QAAQ,SAAS,cAAc,IACrC,MAAM,QAAQ,SAAS,SAAS,CAIhC,OAAM,wBADc,aAAa,QAAQ,QAAQ,KAAK,EAAE,WAAW,GAAG,QAC3B,EACzC,KAAK,MAAM,SACZ,CAAC;AAGJ,SAAM,gBAAgB,MAAM,SAAS,EACnC,KAAK,0BAA0B,MAAM,WACtC,CAAC;;AAEJ,QAAM,gBAAgB,OAAO,MAAM,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PrismaNextConfig } from "@prisma-next/core-control-plane/config-types";
|
|
2
|
+
|
|
3
|
+
//#region src/config-loader.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Loads the Prisma Next config from a TypeScript file.
|
|
4
7
|
* Supports both default export and named export.
|
|
@@ -8,5 +11,7 @@ import type { PrismaNextConfig } from '@prisma-next/core-control-plane/config-ty
|
|
|
8
11
|
* @returns The loaded config object.
|
|
9
12
|
* @throws Error if config file doesn't exist or is invalid.
|
|
10
13
|
*/
|
|
11
|
-
|
|
12
|
-
//#
|
|
14
|
+
declare function loadConfig(configPath?: string): Promise<PrismaNextConfig>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { loadConfig };
|
|
17
|
+
//# sourceMappingURL=config-loader.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-loader.d.mts","names":[],"sources":["../src/config-loader.ts"],"sourcesContent":[],"mappings":";;;;;;AAeA;;;;;;;iBAAsB,UAAA,uBAAiC,QAAQ"}
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { Result } from "@prisma-next/utils/result";
|
|
2
|
+
import { ContractSourceDiagnostics, ContractSourceProvider } from "@prisma-next/core-control-plane/config-types";
|
|
3
|
+
import { ControlAdapterDescriptor, ControlDriverDescriptor, ControlExtensionDescriptor, ControlFamilyDescriptor, ControlPlaneStack, ControlTargetDescriptor, MigrationPlannerConflict, SignDatabaseResult, SignDatabaseResult as SignDatabaseResult$1, VerifyDatabaseResult, VerifyDatabaseResult as VerifyDatabaseResult$1, VerifyDatabaseSchemaResult, VerifyDatabaseSchemaResult as VerifyDatabaseSchemaResult$1 } from "@prisma-next/core-control-plane/types";
|
|
4
|
+
import { CoreSchemaView } from "@prisma-next/core-control-plane/schema-view";
|
|
5
|
+
|
|
6
|
+
//#region src/control-api/types.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Options for creating a control client.
|
|
10
|
+
*
|
|
11
|
+
* Note: This is NOT the same as CLI config. There's no `contract` field,
|
|
12
|
+
* no file paths. The client is config-agnostic.
|
|
13
|
+
*
|
|
14
|
+
* The descriptor types use permissive `any` because family-specific descriptors
|
|
15
|
+
* (e.g., SqlFamilyDescriptor) have more specific `create` method signatures that
|
|
16
|
+
* are not compatible with the base ControlFamilyDescriptor type due to TypeScript
|
|
17
|
+
* variance rules. The client implementation casts these internally.
|
|
18
|
+
*/
|
|
19
|
+
interface ControlClientOptions {
|
|
20
|
+
readonly family: ControlFamilyDescriptor<any, any>;
|
|
21
|
+
readonly target: ControlTargetDescriptor<any, any, any, any>;
|
|
22
|
+
readonly adapter: ControlAdapterDescriptor<any, any, any>;
|
|
23
|
+
/** Optional - control client can be created without driver for offline operations */
|
|
24
|
+
readonly driver?: ControlDriverDescriptor<any, any, any, any>;
|
|
25
|
+
readonly extensionPacks?: ReadonlyArray<ControlExtensionDescriptor<any, any, any>>;
|
|
26
|
+
/**
|
|
27
|
+
* Optional default connection for auto-connect.
|
|
28
|
+
* When provided, operations will auto-connect if not already connected.
|
|
29
|
+
* The type is driver-specific (e.g., string URL for Postgres).
|
|
30
|
+
*/
|
|
31
|
+
readonly connection?: unknown;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Action names for control-api operations that can emit progress events.
|
|
35
|
+
*/
|
|
36
|
+
type ControlActionName = 'dbInit' | 'verify' | 'schemaVerify' | 'sign' | 'introspect' | 'emit';
|
|
37
|
+
/**
|
|
38
|
+
* Progress event emitted during control-api operation execution.
|
|
39
|
+
*
|
|
40
|
+
* Events model operation progress using a span-based model:
|
|
41
|
+
* - `spanStart`: Begin a timed segment (supports nesting via parentSpanId)
|
|
42
|
+
* - `spanEnd`: Complete a timed segment
|
|
43
|
+
*
|
|
44
|
+
* All operation-specific progress (e.g., per-migration-operation) is modeled
|
|
45
|
+
* as nested spans rather than special event types.
|
|
46
|
+
*
|
|
47
|
+
* Events are delivered via an optional `onProgress` callback to avoid polluting
|
|
48
|
+
* return types. If the callback is absent, operations emit no events (zero overhead).
|
|
49
|
+
*/
|
|
50
|
+
type ControlProgressEvent = {
|
|
51
|
+
readonly action: ControlActionName;
|
|
52
|
+
readonly kind: 'spanStart';
|
|
53
|
+
readonly spanId: string;
|
|
54
|
+
readonly parentSpanId?: string;
|
|
55
|
+
readonly label: string;
|
|
56
|
+
} | {
|
|
57
|
+
readonly action: ControlActionName;
|
|
58
|
+
readonly kind: 'spanEnd';
|
|
59
|
+
readonly spanId: string;
|
|
60
|
+
readonly outcome: 'ok' | 'skipped' | 'error';
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Callback function for receiving progress events during control-api operations.
|
|
64
|
+
*
|
|
65
|
+
* @param event - The progress event emitted by the operation
|
|
66
|
+
*/
|
|
67
|
+
type OnControlProgress = (event: ControlProgressEvent) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Options for the verify operation.
|
|
70
|
+
*/
|
|
71
|
+
interface VerifyOptions {
|
|
72
|
+
/** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
|
|
73
|
+
readonly contractIR: unknown;
|
|
74
|
+
/**
|
|
75
|
+
* Database connection. If provided, verify will connect before executing.
|
|
76
|
+
* If omitted, the client must already be connected.
|
|
77
|
+
* The type is driver-specific (e.g., string URL for Postgres).
|
|
78
|
+
*/
|
|
79
|
+
readonly connection?: unknown;
|
|
80
|
+
/** Optional progress callback for observing operation progress */
|
|
81
|
+
readonly onProgress?: OnControlProgress;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Options for the schemaVerify operation.
|
|
85
|
+
*/
|
|
86
|
+
interface SchemaVerifyOptions {
|
|
87
|
+
/** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
|
|
88
|
+
readonly contractIR: unknown;
|
|
89
|
+
/**
|
|
90
|
+
* Whether to use strict mode for schema verification.
|
|
91
|
+
* In strict mode, extra tables/columns are reported as issues.
|
|
92
|
+
* Default: false (tolerant mode - allows superset)
|
|
93
|
+
*/
|
|
94
|
+
readonly strict?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Database connection. If provided, schemaVerify will connect before executing.
|
|
97
|
+
* If omitted, the client must already be connected.
|
|
98
|
+
* The type is driver-specific (e.g., string URL for Postgres).
|
|
99
|
+
*/
|
|
100
|
+
readonly connection?: unknown;
|
|
101
|
+
/** Optional progress callback for observing operation progress */
|
|
102
|
+
readonly onProgress?: OnControlProgress;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Options for the sign operation.
|
|
106
|
+
*/
|
|
107
|
+
interface SignOptions {
|
|
108
|
+
/** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
|
|
109
|
+
readonly contractIR: unknown;
|
|
110
|
+
/**
|
|
111
|
+
* Path to the contract file (for metadata in the result).
|
|
112
|
+
*/
|
|
113
|
+
readonly contractPath?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Path to the config file (for metadata in the result).
|
|
116
|
+
*/
|
|
117
|
+
readonly configPath?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Database connection. If provided, sign will connect before executing.
|
|
120
|
+
* If omitted, the client must already be connected.
|
|
121
|
+
* The type is driver-specific (e.g., string URL for Postgres).
|
|
122
|
+
*/
|
|
123
|
+
readonly connection?: unknown;
|
|
124
|
+
/** Optional progress callback for observing operation progress */
|
|
125
|
+
readonly onProgress?: OnControlProgress;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Options for the dbInit operation.
|
|
129
|
+
*/
|
|
130
|
+
interface DbInitOptions {
|
|
131
|
+
/** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
|
|
132
|
+
readonly contractIR: unknown;
|
|
133
|
+
/**
|
|
134
|
+
* Mode for the dbInit operation.
|
|
135
|
+
* - 'plan': Returns planned operations without applying
|
|
136
|
+
* - 'apply': Applies operations and writes marker
|
|
137
|
+
*/
|
|
138
|
+
readonly mode: 'plan' | 'apply';
|
|
139
|
+
/**
|
|
140
|
+
* Database connection. If provided, dbInit will connect before executing.
|
|
141
|
+
* If omitted, the client must already be connected.
|
|
142
|
+
* The type is driver-specific (e.g., string URL for Postgres).
|
|
143
|
+
*/
|
|
144
|
+
readonly connection?: unknown;
|
|
145
|
+
/** Optional progress callback for observing operation progress */
|
|
146
|
+
readonly onProgress?: OnControlProgress;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Options for the introspect operation.
|
|
150
|
+
*/
|
|
151
|
+
interface IntrospectOptions {
|
|
152
|
+
/**
|
|
153
|
+
* Optional schema name to introspect.
|
|
154
|
+
*/
|
|
155
|
+
readonly schema?: string;
|
|
156
|
+
/**
|
|
157
|
+
* Database connection. If provided, introspect will connect before executing.
|
|
158
|
+
* If omitted, the client must already be connected.
|
|
159
|
+
* The type is driver-specific (e.g., string URL for Postgres).
|
|
160
|
+
*/
|
|
161
|
+
readonly connection?: unknown;
|
|
162
|
+
/** Optional progress callback for observing operation progress */
|
|
163
|
+
readonly onProgress?: OnControlProgress;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Contract configuration for emit operation.
|
|
167
|
+
*/
|
|
168
|
+
interface EmitContractConfig {
|
|
169
|
+
/**
|
|
170
|
+
* Contract source provider.
|
|
171
|
+
*/
|
|
172
|
+
readonly sourceProvider: ContractSourceProvider;
|
|
173
|
+
/**
|
|
174
|
+
* Output path for contract.json.
|
|
175
|
+
* The .d.ts types file will be colocated (e.g., contract.json → contract.d.ts).
|
|
176
|
+
*/
|
|
177
|
+
readonly output: string;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Options for the emit operation.
|
|
181
|
+
*/
|
|
182
|
+
interface EmitOptions {
|
|
183
|
+
/**
|
|
184
|
+
* Contract configuration containing source, output, and types paths.
|
|
185
|
+
*/
|
|
186
|
+
readonly contractConfig: EmitContractConfig;
|
|
187
|
+
/** Optional progress callback for observing operation progress */
|
|
188
|
+
readonly onProgress?: OnControlProgress;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Successful dbInit result.
|
|
192
|
+
*/
|
|
193
|
+
interface DbInitSuccess {
|
|
194
|
+
readonly mode: 'plan' | 'apply';
|
|
195
|
+
readonly plan: {
|
|
196
|
+
readonly operations: ReadonlyArray<{
|
|
197
|
+
readonly id: string;
|
|
198
|
+
readonly label: string;
|
|
199
|
+
readonly operationClass: string;
|
|
200
|
+
}>;
|
|
201
|
+
};
|
|
202
|
+
readonly execution?: {
|
|
203
|
+
readonly operationsPlanned: number;
|
|
204
|
+
readonly operationsExecuted: number;
|
|
205
|
+
};
|
|
206
|
+
readonly marker?: {
|
|
207
|
+
readonly storageHash: string;
|
|
208
|
+
readonly profileHash?: string;
|
|
209
|
+
};
|
|
210
|
+
readonly summary: string;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Failure codes for dbInit operation.
|
|
214
|
+
*/
|
|
215
|
+
type DbInitFailureCode = 'PLANNING_FAILED' | 'MARKER_ORIGIN_MISMATCH' | 'RUNNER_FAILED';
|
|
216
|
+
/**
|
|
217
|
+
* Failure details for dbInit operation.
|
|
218
|
+
*/
|
|
219
|
+
interface DbInitFailure {
|
|
220
|
+
readonly code: DbInitFailureCode;
|
|
221
|
+
readonly summary: string;
|
|
222
|
+
readonly why: string | undefined;
|
|
223
|
+
readonly conflicts: ReadonlyArray<MigrationPlannerConflict> | undefined;
|
|
224
|
+
readonly meta: Record<string, unknown> | undefined;
|
|
225
|
+
readonly marker?: {
|
|
226
|
+
readonly storageHash?: string;
|
|
227
|
+
readonly profileHash?: string;
|
|
228
|
+
};
|
|
229
|
+
readonly destination?: {
|
|
230
|
+
readonly storageHash: string;
|
|
231
|
+
readonly profileHash?: string | undefined;
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Result type for dbInit operation.
|
|
236
|
+
* Uses Result pattern: success returns DbInitSuccess, failure returns DbInitFailure.
|
|
237
|
+
*/
|
|
238
|
+
type DbInitResult = Result<DbInitSuccess, DbInitFailure>;
|
|
239
|
+
/**
|
|
240
|
+
* Successful emit result.
|
|
241
|
+
* Contains the hashes and paths of emitted files.
|
|
242
|
+
*/
|
|
243
|
+
interface EmitSuccess {
|
|
244
|
+
/** Storage hash of the emitted contract */
|
|
245
|
+
readonly storageHash: string;
|
|
246
|
+
/** Execution hash of the emitted contract (if execution section exists) */
|
|
247
|
+
readonly executionHash?: string;
|
|
248
|
+
/** Profile hash of the emitted contract (target-specific) */
|
|
249
|
+
readonly profileHash: string;
|
|
250
|
+
/** The emitted contract as JSON string */
|
|
251
|
+
readonly contractJson: string;
|
|
252
|
+
/** The emitted contract TypeScript declarations */
|
|
253
|
+
readonly contractDts: string;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Failure codes for emit operation.
|
|
257
|
+
*/
|
|
258
|
+
type EmitFailureCode = 'CONTRACT_SOURCE_INVALID' | 'EMIT_FAILED';
|
|
259
|
+
/**
|
|
260
|
+
* Failure details for emit operation.
|
|
261
|
+
*/
|
|
262
|
+
interface EmitFailure {
|
|
263
|
+
readonly code: EmitFailureCode;
|
|
264
|
+
readonly summary: string;
|
|
265
|
+
readonly why: string | undefined;
|
|
266
|
+
readonly meta: Record<string, unknown> | undefined;
|
|
267
|
+
readonly diagnostics?: ContractSourceDiagnostics;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Result type for emit operation.
|
|
271
|
+
* Uses Result pattern: success returns EmitSuccess, failure returns EmitFailure.
|
|
272
|
+
*/
|
|
273
|
+
type EmitResult = Result<EmitSuccess, EmitFailure>;
|
|
274
|
+
/**
|
|
275
|
+
* Options for the standalone executeContractEmit function.
|
|
276
|
+
* Used by tooling (e.g., Vite plugin) that needs to emit contracts
|
|
277
|
+
* without the full ControlClient infrastructure.
|
|
278
|
+
*/
|
|
279
|
+
interface ContractEmitOptions {
|
|
280
|
+
/** Path to the prisma-next.config.ts file */
|
|
281
|
+
readonly configPath: string;
|
|
282
|
+
/** Optional AbortSignal for cancellation support */
|
|
283
|
+
readonly signal?: AbortSignal;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Result from the standalone executeContractEmit function.
|
|
287
|
+
*/
|
|
288
|
+
interface ContractEmitResult {
|
|
289
|
+
/** Hash of the storage contract (schema-level) */
|
|
290
|
+
readonly storageHash: string;
|
|
291
|
+
/** Hash of the execution contract (if execution section exists) */
|
|
292
|
+
readonly executionHash?: string;
|
|
293
|
+
/** Hash of the profile (target+extensions) */
|
|
294
|
+
readonly profileHash: string;
|
|
295
|
+
/** Paths to the emitted files */
|
|
296
|
+
readonly files: {
|
|
297
|
+
/** Path to the emitted contract.json file */
|
|
298
|
+
readonly json: string;
|
|
299
|
+
/** Path to the emitted contract.d.ts file */
|
|
300
|
+
readonly dts: string;
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Programmatic control client for Prisma Next operations.
|
|
305
|
+
*
|
|
306
|
+
* Lifecycle: `connect(connection)` before operations, `close()` when done.
|
|
307
|
+
* Both `init()` and `connect()` are auto-called by operations if needed,
|
|
308
|
+
* but `connect()` requires a connection so must be called explicitly first
|
|
309
|
+
* unless a default connection was provided in options.
|
|
310
|
+
*
|
|
311
|
+
* @see README.md "Programmatic Control API" section for usage examples
|
|
312
|
+
*/
|
|
313
|
+
interface ControlClient {
|
|
314
|
+
/**
|
|
315
|
+
* Initializes the client by creating the control plane stack,
|
|
316
|
+
* family instance, and validating framework components.
|
|
317
|
+
*
|
|
318
|
+
* Idempotent (safe to call multiple times).
|
|
319
|
+
* Called automatically by `connect()` if not already initialized.
|
|
320
|
+
*/
|
|
321
|
+
init(): void;
|
|
322
|
+
/**
|
|
323
|
+
* Establishes a database connection.
|
|
324
|
+
* Auto-calls `init()` if not already initialized.
|
|
325
|
+
* Must be called before any database operations unless a default connection
|
|
326
|
+
* was provided in options.
|
|
327
|
+
*
|
|
328
|
+
* @param connection - Driver-specific connection input (e.g., URL string for Postgres).
|
|
329
|
+
* If omitted, uses the default connection from options (if provided).
|
|
330
|
+
* @throws If connection fails, already connected, driver is not configured,
|
|
331
|
+
* or no connection provided and no default connection in options.
|
|
332
|
+
*/
|
|
333
|
+
connect(connection?: unknown): Promise<void>;
|
|
334
|
+
/**
|
|
335
|
+
* Closes the database connection.
|
|
336
|
+
* Idempotent (safe to call multiple times).
|
|
337
|
+
* After close(), can call `connect()` again with same or different URL.
|
|
338
|
+
*/
|
|
339
|
+
close(): Promise<void>;
|
|
340
|
+
/**
|
|
341
|
+
* Verifies database marker matches the contract.
|
|
342
|
+
* Compares storageHash and profileHash.
|
|
343
|
+
*
|
|
344
|
+
* @returns Structured result (ok: false for mismatch, not throwing)
|
|
345
|
+
* @throws If not connected or infrastructure failure
|
|
346
|
+
*/
|
|
347
|
+
verify(options: VerifyOptions): Promise<VerifyDatabaseResult$1>;
|
|
348
|
+
/**
|
|
349
|
+
* Verifies database schema satisfies the contract requirements.
|
|
350
|
+
*
|
|
351
|
+
* @param options.strict - If true, extra tables/columns are issues. Default: false
|
|
352
|
+
* @returns Structured result with schema issues
|
|
353
|
+
* @throws If not connected or infrastructure failure
|
|
354
|
+
*/
|
|
355
|
+
schemaVerify(options: SchemaVerifyOptions): Promise<VerifyDatabaseSchemaResult$1>;
|
|
356
|
+
/**
|
|
357
|
+
* Signs the database with a contract marker.
|
|
358
|
+
* Writes or updates the contract marker if schema verification passes.
|
|
359
|
+
* Idempotent (no-op if marker already matches).
|
|
360
|
+
*
|
|
361
|
+
* @returns Structured result
|
|
362
|
+
* @throws If not connected or infrastructure failure
|
|
363
|
+
*/
|
|
364
|
+
sign(options: SignOptions): Promise<SignDatabaseResult$1>;
|
|
365
|
+
/**
|
|
366
|
+
* Initializes database schema from contract.
|
|
367
|
+
* Uses additive-only policy (no destructive changes).
|
|
368
|
+
*
|
|
369
|
+
* @param options.mode - 'plan' to preview, 'apply' to execute
|
|
370
|
+
* @returns Result pattern: Ok with planned/executed operations, NotOk with failure details
|
|
371
|
+
* @throws If not connected, target doesn't support migrations, or infrastructure failure
|
|
372
|
+
*/
|
|
373
|
+
dbInit(options: DbInitOptions): Promise<DbInitResult>;
|
|
374
|
+
/**
|
|
375
|
+
* Introspects the database schema.
|
|
376
|
+
*
|
|
377
|
+
* @returns Raw schema IR
|
|
378
|
+
* @throws If not connected or infrastructure failure
|
|
379
|
+
*/
|
|
380
|
+
introspect(options?: IntrospectOptions): Promise<unknown>;
|
|
381
|
+
/**
|
|
382
|
+
* Converts a schema IR to a schema view for CLI tree rendering.
|
|
383
|
+
* Delegates to the family instance's toSchemaView method.
|
|
384
|
+
*
|
|
385
|
+
* @param schemaIR - The schema IR from introspect()
|
|
386
|
+
* @returns CoreSchemaView if the family supports it, undefined otherwise
|
|
387
|
+
*/
|
|
388
|
+
toSchemaView(schemaIR: unknown): CoreSchemaView | undefined;
|
|
389
|
+
/**
|
|
390
|
+
* Emits the contract to JSON and TypeScript declarations.
|
|
391
|
+
* This is an offline operation that does NOT require a database connection.
|
|
392
|
+
* Uses `init()` to create the stack but does NOT call `connect()`.
|
|
393
|
+
*
|
|
394
|
+
* @returns Result pattern: Ok with emit details, NotOk with failure details
|
|
395
|
+
*/
|
|
396
|
+
emit(options: EmitOptions): Promise<EmitResult>;
|
|
397
|
+
}
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region src/control-api/client.d.ts
|
|
400
|
+
/**
|
|
401
|
+
* Creates a programmatic control client for Prisma Next operations.
|
|
402
|
+
*
|
|
403
|
+
* The client accepts framework component descriptors at creation time,
|
|
404
|
+
* manages driver lifecycle via connect()/close(), and exposes domain
|
|
405
|
+
* operations that delegate to the existing family instance methods.
|
|
406
|
+
*
|
|
407
|
+
* @see {@link ControlClient} for the client interface
|
|
408
|
+
* @see README.md "Programmatic Control API" section for usage examples
|
|
409
|
+
*/
|
|
410
|
+
declare function createControlClient(options: ControlClientOptions): ControlClient;
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/control-api/operations/contract-emit.d.ts
|
|
413
|
+
/**
|
|
414
|
+
* Executes the contract emit operation.
|
|
415
|
+
*
|
|
416
|
+
* This is an offline operation that:
|
|
417
|
+
* 1. Loads the Prisma Next config from the specified path
|
|
418
|
+
* 2. Resolves the contract source from config
|
|
419
|
+
* 3. Creates a control plane stack and family instance
|
|
420
|
+
* 4. Emits contract artifacts (JSON and DTS)
|
|
421
|
+
* 5. Writes files to the paths specified in config
|
|
422
|
+
*
|
|
423
|
+
* Supports AbortSignal for cancellation, enabling "last change wins" behavior.
|
|
424
|
+
*
|
|
425
|
+
* @param options - Options including configPath and optional signal
|
|
426
|
+
* @returns File paths and hashes of emitted artifacts
|
|
427
|
+
* @throws If config loading fails, contract is invalid, or file I/O fails
|
|
428
|
+
* @throws signal.reason if cancelled via AbortSignal (typically DOMException with name 'AbortError')
|
|
429
|
+
*/
|
|
430
|
+
declare function executeContractEmit(options: ContractEmitOptions): Promise<ContractEmitResult>;
|
|
431
|
+
//#endregion
|
|
432
|
+
export { type ContractEmitOptions, type ContractEmitResult, type ControlActionName, type ControlClient, type ControlClientOptions, type ControlPlaneStack, type ControlProgressEvent, type DbInitFailure, type DbInitFailureCode, type DbInitOptions, type DbInitResult, type DbInitSuccess, type EmitContractConfig, type EmitFailure, type EmitFailureCode, type EmitOptions, type EmitResult, type EmitSuccess, type IntrospectOptions, type OnControlProgress, type SchemaVerifyOptions, type SignDatabaseResult, type SignOptions, type VerifyDatabaseResult, type VerifyDatabaseSchemaResult, type VerifyOptions, createControlClient, executeContractEmit };
|
|
433
|
+
//# sourceMappingURL=control-api.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-api.d.mts","names":[],"sources":["../../src/control-api/types.ts","../../src/control-api/client.ts","../../src/control-api/operations/contract-emit.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAiCA;;;;;;;;AA2BA;AAqBY,UAhDK,oBAAA,CAgDe;EAoBpB,SAAA,MAAA,EAlEO,uBAkEqB,CAAA,GAAA,EAAA,GAAA,CAAA;EASvB,SAAA,MAAA,EAzEE,uBAmFK,CAAA,GAAA,EAAiB,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA;EAMxB,SAAA,OAAA,EAvFG,wBAuGI,CAAA,GAAA,EAAA,GAAA,EAAiB,GAAA,CAAA;EAMxB;EAwBA,SAAA,MAAA,CAAa,EAlIV,uBAkJI,CAAA,GAAA,EAAiB,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA;EAMxB,SAAA,cAAiB,CAAA,EAtJN,aAkKJ,CAlKkB,0BAkKD,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,CAAA;EAMxB;AAejB;AAgBA;AA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A;;;;UAKK,WAAA;iBACA;;;iBAGA;yBACQ;;;;;;KAOb,UAAA,GAAa,OAAO,aAAa;;;;;;UAW5B,mBAAA;;;;oBAIG;;;;;UAMH,kBAAA;;;;;;;;;;;;;;;;;;;;;;;;;UA8BA,aAAA;;;;;;;;;;;;;;;;;;;;iCAqBgB;;;;;;WAOtB;;;;;;;;kBASO,gBAAgB,QAAQ;;;;;;;;wBASlB,sBAAsB,QAAQ;;;;;;;;;gBAUtC,cAAc,QAAQ;;;;;;;;;kBAUpB,gBAAgB,QAAQ;;;;;;;uBAQnB,oBAAoB;;;;;;;;mCASR;;;;;;;;gBASnB,cAAc,QAAQ;;;;;;;;;AAxbtC;;;;;AAW0C,iBCN1B,mBAAA,CDM0B,OAAA,ECNG,oBDMH,CAAA,ECN0B,aDM1B;;;;;;;;AAX1C;;;;;;;;AA2BA;AAqBA;AAoBA;AASA;AAgBiB,iBEhFK,mBAAA,CFgGE,OAAA,EE/Fb,mBF+F8B,CAAA,EE9FtC,OF8FsC,CE9F9B,kBF8F8B,CAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { t as loadConfig } from "../config-loader-BJ8HsEdA.mjs";
|
|
2
|
+
import { f as errorRuntime, r as errorContractConfigMissing, t as createControlClient } from "../client-BSZKpZTF.mjs";
|
|
3
|
+
import { dirname, isAbsolute, join, resolve } from "pathe";
|
|
4
|
+
import { createControlPlaneStack } from "@prisma-next/core-control-plane/stack";
|
|
5
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
6
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
7
|
+
import { abortable } from "@prisma-next/utils/abortable";
|
|
8
|
+
|
|
9
|
+
//#region src/control-api/operations/contract-emit.ts
|
|
10
|
+
function isRecord(value) {
|
|
11
|
+
return typeof value === "object" && value !== null;
|
|
12
|
+
}
|
|
13
|
+
function isAbortError(error) {
|
|
14
|
+
return isRecord(error) && typeof error["name"] === "string" && error["name"] === "AbortError";
|
|
15
|
+
}
|
|
16
|
+
function isProviderFailureLike(value) {
|
|
17
|
+
return isRecord(value) && typeof value["summary"] === "string" && Array.isArray(value["diagnostics"]);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Executes the contract emit operation.
|
|
21
|
+
*
|
|
22
|
+
* This is an offline operation that:
|
|
23
|
+
* 1. Loads the Prisma Next config from the specified path
|
|
24
|
+
* 2. Resolves the contract source from config
|
|
25
|
+
* 3. Creates a control plane stack and family instance
|
|
26
|
+
* 4. Emits contract artifacts (JSON and DTS)
|
|
27
|
+
* 5. Writes files to the paths specified in config
|
|
28
|
+
*
|
|
29
|
+
* Supports AbortSignal for cancellation, enabling "last change wins" behavior.
|
|
30
|
+
*
|
|
31
|
+
* @param options - Options including configPath and optional signal
|
|
32
|
+
* @returns File paths and hashes of emitted artifacts
|
|
33
|
+
* @throws If config loading fails, contract is invalid, or file I/O fails
|
|
34
|
+
* @throws signal.reason if cancelled via AbortSignal (typically DOMException with name 'AbortError')
|
|
35
|
+
*/
|
|
36
|
+
async function executeContractEmit(options) {
|
|
37
|
+
const { configPath, signal = new AbortController().signal } = options;
|
|
38
|
+
const unlessAborted = abortable(signal);
|
|
39
|
+
const config = await unlessAborted(loadConfig(configPath));
|
|
40
|
+
if (!config.contract) throw errorContractConfigMissing({ why: "Config.contract is required for emit. Define it in your config: contract: { source: ..., output: ... }" });
|
|
41
|
+
const contractConfig = config.contract;
|
|
42
|
+
if (!contractConfig.output) throw errorContractConfigMissing({ why: "Contract config must have output path. This should not happen if defineConfig() was used." });
|
|
43
|
+
if (!contractConfig.output.endsWith(".json")) throw errorContractConfigMissing({ why: "Contract config output path must end with .json (e.g., \"src/prisma/contract.json\")" });
|
|
44
|
+
if (typeof contractConfig.source !== "function") throw errorContractConfigMissing({ why: "Contract config must include a valid source provider function" });
|
|
45
|
+
const configDir = dirname(resolve(configPath));
|
|
46
|
+
const outputJsonPath = isAbsolute(contractConfig.output) ? contractConfig.output : join(configDir, contractConfig.output);
|
|
47
|
+
const outputDtsPath = `${outputJsonPath.slice(0, -5)}.d.ts`;
|
|
48
|
+
let providerResult;
|
|
49
|
+
try {
|
|
50
|
+
providerResult = await unlessAborted(contractConfig.source());
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (signal.aborted || isAbortError(error)) throw error;
|
|
53
|
+
throw errorRuntime("Failed to resolve contract source", {
|
|
54
|
+
why: error instanceof Error ? error.message : String(error),
|
|
55
|
+
fix: "Ensure contract.source resolves to ok(contractIR) or returns structured diagnostics."
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (!isRecord(providerResult) || typeof providerResult.ok !== "boolean") throw errorRuntime("Failed to resolve contract source", {
|
|
59
|
+
why: "Contract source provider returned malformed result shape.",
|
|
60
|
+
fix: "Ensure contract.source resolves to ok(contractIR) or notOk({ summary, diagnostics })."
|
|
61
|
+
});
|
|
62
|
+
if (providerResult.ok && !("value" in providerResult)) throw errorRuntime("Failed to resolve contract source", {
|
|
63
|
+
why: "Contract source provider returned malformed success result: missing value.",
|
|
64
|
+
fix: "Ensure contract.source success payload is ok(contractIR)."
|
|
65
|
+
});
|
|
66
|
+
if (!providerResult.ok && !isProviderFailureLike(providerResult.failure)) throw errorRuntime("Failed to resolve contract source", {
|
|
67
|
+
why: "Contract source provider returned malformed failure result: expected summary and diagnostics.",
|
|
68
|
+
fix: "Ensure contract.source failure payload is notOk({ summary, diagnostics, meta? })."
|
|
69
|
+
});
|
|
70
|
+
if (!providerResult.ok) throw errorRuntime("Failed to resolve contract source", {
|
|
71
|
+
why: providerResult.failure.summary,
|
|
72
|
+
fix: "Fix contract source diagnostics and return ok(contractIR).",
|
|
73
|
+
meta: {
|
|
74
|
+
diagnostics: providerResult.failure.diagnostics,
|
|
75
|
+
...ifDefined("providerMeta", providerResult.failure.meta)
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
const stack = createControlPlaneStack(config);
|
|
79
|
+
const emitResult = await unlessAborted(config.family.create(stack).emitContract({ contractIR: providerResult.value }));
|
|
80
|
+
await unlessAborted(mkdir(dirname(outputJsonPath), { recursive: true }));
|
|
81
|
+
await unlessAborted(writeFile(outputJsonPath, emitResult.contractJson, "utf-8"));
|
|
82
|
+
await unlessAborted(writeFile(outputDtsPath, emitResult.contractDts, "utf-8"));
|
|
83
|
+
return {
|
|
84
|
+
storageHash: emitResult.storageHash,
|
|
85
|
+
...ifDefined("executionHash", emitResult.executionHash),
|
|
86
|
+
profileHash: emitResult.profileHash,
|
|
87
|
+
files: {
|
|
88
|
+
json: outputJsonPath,
|
|
89
|
+
dts: outputDtsPath
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
export { createControlClient, executeContractEmit };
|
|
96
|
+
//# sourceMappingURL=control-api.mjs.map
|