@prisma-next/cli 0.3.0-pr.94.3 → 0.3.0-pr.95.2
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/chunk-AGOTG4L3.js +965 -0
- package/dist/chunk-AGOTG4L3.js.map +1 -0
- package/dist/chunk-HLLI4YL7.js +180 -0
- package/dist/chunk-HLLI4YL7.js.map +1 -0
- package/dist/chunk-HWYQOCAJ.js +47 -0
- package/dist/chunk-HWYQOCAJ.js.map +1 -0
- package/dist/chunk-VG2R7DGF.js +735 -0
- package/dist/chunk-VG2R7DGF.js.map +1 -0
- package/dist/cli.d.ts +2 -2
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +2764 -2522
- package/dist/cli.js.map +1 -1
- package/dist/commands/contract-emit.d.ts +3 -0
- package/dist/commands/contract-emit.d.ts.map +1 -0
- package/dist/commands/contract-emit.js +10 -0
- package/dist/commands/contract-emit.js.map +1 -0
- package/dist/commands/db-init.d.ts +3 -0
- package/dist/commands/db-init.d.ts.map +1 -0
- package/dist/commands/db-init.js +257 -0
- package/dist/commands/db-init.js.map +1 -0
- package/dist/commands/db-introspect.d.ts +3 -0
- package/dist/commands/db-introspect.d.ts.map +1 -0
- package/dist/commands/db-introspect.js +155 -0
- package/dist/commands/db-introspect.js.map +1 -0
- package/dist/commands/db-schema-verify.d.ts +3 -0
- package/dist/commands/db-schema-verify.d.ts.map +1 -0
- package/dist/commands/db-schema-verify.js +171 -0
- package/dist/commands/db-schema-verify.js.map +1 -0
- package/dist/commands/db-sign.d.ts +3 -0
- package/dist/commands/db-sign.d.ts.map +1 -0
- package/dist/commands/db-sign.js +195 -0
- package/dist/commands/db-sign.js.map +1 -0
- package/dist/commands/db-verify.d.ts +3 -0
- package/dist/commands/db-verify.d.ts.map +1 -0
- package/dist/commands/db-verify.js +193 -0
- package/dist/commands/db-verify.js.map +1 -0
- package/dist/{config-loader.d.mts → config-loader.d.ts} +3 -8
- package/dist/config-loader.d.ts.map +1 -0
- package/dist/config-loader.js +7 -0
- package/dist/config-loader.js.map +1 -0
- package/dist/control-api/client.d.ts +13 -0
- package/dist/control-api/client.d.ts.map +1 -0
- package/dist/control-api/operations/db-init.d.ts +29 -0
- package/dist/control-api/operations/db-init.d.ts.map +1 -0
- package/dist/control-api/types.d.ts +387 -0
- package/dist/control-api/types.d.ts.map +1 -0
- package/dist/exports/config-types.d.ts +3 -0
- package/dist/exports/config-types.d.ts.map +1 -0
- package/dist/exports/config-types.js +6 -0
- package/dist/exports/config-types.js.map +1 -0
- package/dist/exports/control-api.d.ts +13 -0
- package/dist/exports/control-api.d.ts.map +1 -0
- package/dist/exports/control-api.js +7 -0
- package/dist/exports/control-api.js.map +1 -0
- package/dist/exports/index.d.ts +4 -0
- package/dist/exports/index.d.ts.map +1 -0
- package/dist/exports/index.js +176 -0
- package/dist/exports/index.js.map +1 -0
- package/dist/{exports/index.d.mts → load-ts-contract.d.ts} +5 -10
- package/dist/load-ts-contract.d.ts.map +1 -0
- package/dist/utils/cli-errors.d.ts +7 -0
- package/dist/utils/cli-errors.d.ts.map +1 -0
- package/dist/utils/command-helpers.d.ts +12 -0
- package/dist/utils/command-helpers.d.ts.map +1 -0
- package/dist/utils/framework-components.d.ts +70 -0
- package/dist/utils/framework-components.d.ts.map +1 -0
- package/dist/utils/global-flags.d.ts +25 -0
- package/dist/utils/global-flags.d.ts.map +1 -0
- package/dist/utils/output.d.ts +142 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/progress-adapter.d.ts +26 -0
- package/dist/utils/progress-adapter.d.ts.map +1 -0
- package/dist/utils/result-handler.d.ts +15 -0
- package/dist/utils/result-handler.d.ts.map +1 -0
- package/package.json +54 -29
- package/dist/client-CoxxGz_7.mjs +0 -692
- package/dist/client-CoxxGz_7.mjs.map +0 -1
- package/dist/commands/contract-emit.d.mts +0 -7
- package/dist/commands/contract-emit.d.mts.map +0 -1
- package/dist/commands/contract-emit.mjs +0 -139
- package/dist/commands/contract-emit.mjs.map +0 -1
- package/dist/commands/db-init.d.mts +0 -7
- package/dist/commands/db-init.d.mts.map +0 -1
- package/dist/commands/db-init.mjs +0 -178
- package/dist/commands/db-init.mjs.map +0 -1
- package/dist/commands/db-introspect.d.mts +0 -7
- package/dist/commands/db-introspect.d.mts.map +0 -1
- package/dist/commands/db-introspect.mjs +0 -120
- package/dist/commands/db-introspect.mjs.map +0 -1
- package/dist/commands/db-schema-verify.d.mts +0 -7
- package/dist/commands/db-schema-verify.d.mts.map +0 -1
- package/dist/commands/db-schema-verify.mjs +0 -116
- package/dist/commands/db-schema-verify.mjs.map +0 -1
- package/dist/commands/db-sign.d.mts +0 -7
- package/dist/commands/db-sign.d.mts.map +0 -1
- package/dist/commands/db-sign.mjs +0 -138
- package/dist/commands/db-sign.mjs.map +0 -1
- package/dist/commands/db-verify.d.mts +0 -7
- package/dist/commands/db-verify.d.mts.map +0 -1
- package/dist/commands/db-verify.mjs +0 -128
- package/dist/commands/db-verify.mjs.map +0 -1
- package/dist/config-loader-B-pobG0R.mjs +0 -42
- package/dist/config-loader-B-pobG0R.mjs.map +0 -1
- package/dist/config-loader.d.mts.map +0 -1
- package/dist/config-loader.mjs +0 -3
- package/dist/exports/config-types.d.mts +0 -2
- package/dist/exports/config-types.mjs +0 -3
- package/dist/exports/control-api.d.mts +0 -405
- package/dist/exports/control-api.d.mts.map +0 -1
- package/dist/exports/control-api.mjs +0 -3
- package/dist/exports/index.d.mts.map +0 -1
- package/dist/exports/index.mjs +0 -128
- package/dist/exports/index.mjs.map +0 -1
- package/dist/result-handler-Do_4Fi4U.mjs +0 -959
- package/dist/result-handler-Do_4Fi4U.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
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 { 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.coreHash,\n ...(verifyResult.marker?.coreHash ? { actual: verifyResult.marker.coreHash } : {}),\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":";;;;;;;;;;;;AAiDA,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,GAAI,aAAa,QAAQ,WAAW,EAAE,QAAQ,aAAa,OAAO,UAAU,GAAG,EAAE;GAClF,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,MAAM,uBAAuB,OAAO,UAAU,SAC1C,QAAQ,OAAO,SAAS,OAAO,GAC/B,QAAQ,2BAA2B;CACvC,MAAM,eAAe,SAAS,QAAQ,KAAK,EAAE,qBAAqB;AAGlE,KAAI,MAAM,SAAS,YAAY,CAAC,MAAM,OAAO;EAC3C,MAAMA,UAAmD,CACvD;GAAE,OAAO;GAAU,OAAO;GAAY,EACtC;GAAE,OAAO;GAAY,OAAO;GAAc,CAC3C;AACD,MAAI,QAAQ,GACV,SAA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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"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { dirname, resolve } from "node:path";
|
|
2
|
-
import { errorConfigFileNotFound, errorUnexpected } from "@prisma-next/core-control-plane/errors";
|
|
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-B-pobG0R.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config-loader-B-pobG0R.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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config-loader.d.mts","names":[],"sources":["../src/config-loader.ts"],"sourcesContent":[],"mappings":";;;;;;AAeA;;;;;;;iBAAsB,UAAA,uBAAiC,QAAQ"}
|
package/dist/config-loader.mjs
DELETED
|
@@ -1,405 +0,0 @@
|
|
|
1
|
-
import { Result } from "@prisma-next/utils/result";
|
|
2
|
-
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";
|
|
3
|
-
import { CoreSchemaView } from "@prisma-next/core-control-plane/schema-view";
|
|
4
|
-
|
|
5
|
-
//#region src/control-api/types.d.ts
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Options for creating a control client.
|
|
9
|
-
*
|
|
10
|
-
* Note: This is NOT the same as CLI config. There's no `contract` field,
|
|
11
|
-
* no file paths. The client is config-agnostic.
|
|
12
|
-
*
|
|
13
|
-
* The descriptor types use permissive `any` because family-specific descriptors
|
|
14
|
-
* (e.g., SqlFamilyDescriptor) have more specific `create` method signatures that
|
|
15
|
-
* are not compatible with the base ControlFamilyDescriptor type due to TypeScript
|
|
16
|
-
* variance rules. The client implementation casts these internally.
|
|
17
|
-
*/
|
|
18
|
-
interface ControlClientOptions {
|
|
19
|
-
readonly family: ControlFamilyDescriptor<any, any>;
|
|
20
|
-
readonly target: ControlTargetDescriptor<any, any, any, any>;
|
|
21
|
-
readonly adapter: ControlAdapterDescriptor<any, any, any>;
|
|
22
|
-
/** Optional - control client can be created without driver for offline operations */
|
|
23
|
-
readonly driver?: ControlDriverDescriptor<any, any, any, any>;
|
|
24
|
-
readonly extensionPacks?: ReadonlyArray<ControlExtensionDescriptor<any, any, any>>;
|
|
25
|
-
/**
|
|
26
|
-
* Optional default connection for auto-connect.
|
|
27
|
-
* When provided, operations will auto-connect if not already connected.
|
|
28
|
-
* The type is driver-specific (e.g., string URL for Postgres).
|
|
29
|
-
*/
|
|
30
|
-
readonly connection?: unknown;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Action names for control-api operations that can emit progress events.
|
|
34
|
-
*/
|
|
35
|
-
type ControlActionName = 'dbInit' | 'verify' | 'schemaVerify' | 'sign' | 'introspect' | 'emit';
|
|
36
|
-
/**
|
|
37
|
-
* Progress event emitted during control-api operation execution.
|
|
38
|
-
*
|
|
39
|
-
* Events model operation progress using a span-based model:
|
|
40
|
-
* - `spanStart`: Begin a timed segment (supports nesting via parentSpanId)
|
|
41
|
-
* - `spanEnd`: Complete a timed segment
|
|
42
|
-
*
|
|
43
|
-
* All operation-specific progress (e.g., per-migration-operation) is modeled
|
|
44
|
-
* as nested spans rather than special event types.
|
|
45
|
-
*
|
|
46
|
-
* Events are delivered via an optional `onProgress` callback to avoid polluting
|
|
47
|
-
* return types. If the callback is absent, operations emit no events (zero overhead).
|
|
48
|
-
*/
|
|
49
|
-
type ControlProgressEvent = {
|
|
50
|
-
readonly action: ControlActionName;
|
|
51
|
-
readonly kind: 'spanStart';
|
|
52
|
-
readonly spanId: string;
|
|
53
|
-
readonly parentSpanId?: string;
|
|
54
|
-
readonly label: string;
|
|
55
|
-
} | {
|
|
56
|
-
readonly action: ControlActionName;
|
|
57
|
-
readonly kind: 'spanEnd';
|
|
58
|
-
readonly spanId: string;
|
|
59
|
-
readonly outcome: 'ok' | 'skipped' | 'error';
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Callback function for receiving progress events during control-api operations.
|
|
63
|
-
*
|
|
64
|
-
* @param event - The progress event emitted by the operation
|
|
65
|
-
*/
|
|
66
|
-
type OnControlProgress = (event: ControlProgressEvent) => void;
|
|
67
|
-
/**
|
|
68
|
-
* Options for the verify operation.
|
|
69
|
-
*/
|
|
70
|
-
interface VerifyOptions {
|
|
71
|
-
/** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
|
|
72
|
-
readonly contractIR: unknown;
|
|
73
|
-
/**
|
|
74
|
-
* Database connection. If provided, verify will connect before executing.
|
|
75
|
-
* If omitted, the client must already be connected.
|
|
76
|
-
* The type is driver-specific (e.g., string URL for Postgres).
|
|
77
|
-
*/
|
|
78
|
-
readonly connection?: unknown;
|
|
79
|
-
/** Optional progress callback for observing operation progress */
|
|
80
|
-
readonly onProgress?: OnControlProgress;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Options for the schemaVerify operation.
|
|
84
|
-
*/
|
|
85
|
-
interface SchemaVerifyOptions {
|
|
86
|
-
/** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
|
|
87
|
-
readonly contractIR: unknown;
|
|
88
|
-
/**
|
|
89
|
-
* Whether to use strict mode for schema verification.
|
|
90
|
-
* In strict mode, extra tables/columns are reported as issues.
|
|
91
|
-
* Default: false (tolerant mode - allows superset)
|
|
92
|
-
*/
|
|
93
|
-
readonly strict?: boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Database connection. If provided, schemaVerify will connect before executing.
|
|
96
|
-
* If omitted, the client must already be connected.
|
|
97
|
-
* The type is driver-specific (e.g., string URL for Postgres).
|
|
98
|
-
*/
|
|
99
|
-
readonly connection?: unknown;
|
|
100
|
-
/** Optional progress callback for observing operation progress */
|
|
101
|
-
readonly onProgress?: OnControlProgress;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Options for the sign operation.
|
|
105
|
-
*/
|
|
106
|
-
interface SignOptions {
|
|
107
|
-
/** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
|
|
108
|
-
readonly contractIR: unknown;
|
|
109
|
-
/**
|
|
110
|
-
* Path to the contract file (for metadata in the result).
|
|
111
|
-
*/
|
|
112
|
-
readonly contractPath?: string;
|
|
113
|
-
/**
|
|
114
|
-
* Path to the config file (for metadata in the result).
|
|
115
|
-
*/
|
|
116
|
-
readonly configPath?: string;
|
|
117
|
-
/**
|
|
118
|
-
* Database connection. If provided, sign will connect before executing.
|
|
119
|
-
* If omitted, the client must already be connected.
|
|
120
|
-
* The type is driver-specific (e.g., string URL for Postgres).
|
|
121
|
-
*/
|
|
122
|
-
readonly connection?: unknown;
|
|
123
|
-
/** Optional progress callback for observing operation progress */
|
|
124
|
-
readonly onProgress?: OnControlProgress;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Options for the dbInit operation.
|
|
128
|
-
*/
|
|
129
|
-
interface DbInitOptions {
|
|
130
|
-
/** Contract IR or unvalidated JSON - validated at runtime via familyInstance.validateContractIR() */
|
|
131
|
-
readonly contractIR: unknown;
|
|
132
|
-
/**
|
|
133
|
-
* Mode for the dbInit operation.
|
|
134
|
-
* - 'plan': Returns planned operations without applying
|
|
135
|
-
* - 'apply': Applies operations and writes marker
|
|
136
|
-
*/
|
|
137
|
-
readonly mode: 'plan' | 'apply';
|
|
138
|
-
/**
|
|
139
|
-
* Database connection. If provided, dbInit will connect before executing.
|
|
140
|
-
* If omitted, the client must already be connected.
|
|
141
|
-
* The type is driver-specific (e.g., string URL for Postgres).
|
|
142
|
-
*/
|
|
143
|
-
readonly connection?: unknown;
|
|
144
|
-
/** Optional progress callback for observing operation progress */
|
|
145
|
-
readonly onProgress?: OnControlProgress;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Options for the introspect operation.
|
|
149
|
-
*/
|
|
150
|
-
interface IntrospectOptions {
|
|
151
|
-
/**
|
|
152
|
-
* Optional schema name to introspect.
|
|
153
|
-
*/
|
|
154
|
-
readonly schema?: string;
|
|
155
|
-
/**
|
|
156
|
-
* Database connection. If provided, introspect will connect before executing.
|
|
157
|
-
* If omitted, the client must already be connected.
|
|
158
|
-
* The type is driver-specific (e.g., string URL for Postgres).
|
|
159
|
-
*/
|
|
160
|
-
readonly connection?: unknown;
|
|
161
|
-
/** Optional progress callback for observing operation progress */
|
|
162
|
-
readonly onProgress?: OnControlProgress;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Contract source as a raw value (any JSON-serializable value).
|
|
166
|
-
*/
|
|
167
|
-
interface ContractSourceValue {
|
|
168
|
-
readonly kind: 'value';
|
|
169
|
-
readonly value: unknown;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Contract source as a lazy loader function.
|
|
173
|
-
*/
|
|
174
|
-
interface ContractSourceLoader {
|
|
175
|
-
readonly kind: 'loader';
|
|
176
|
-
readonly load: () => unknown | Promise<unknown>;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Discriminated union for contract source.
|
|
180
|
-
* Use `kind` to determine how to resolve the contract.
|
|
181
|
-
*/
|
|
182
|
-
type EmitContractSource = ContractSourceValue | ContractSourceLoader;
|
|
183
|
-
/**
|
|
184
|
-
* Contract configuration for emit operation.
|
|
185
|
-
*/
|
|
186
|
-
interface EmitContractConfig {
|
|
187
|
-
/**
|
|
188
|
-
* Contract source - either a raw value or a loader function.
|
|
189
|
-
* Switch on `source.kind` to determine how to resolve.
|
|
190
|
-
*/
|
|
191
|
-
readonly source: EmitContractSource;
|
|
192
|
-
/**
|
|
193
|
-
* Output path for contract.json.
|
|
194
|
-
* Should be an absolute or relative path.
|
|
195
|
-
*/
|
|
196
|
-
readonly output: string;
|
|
197
|
-
/**
|
|
198
|
-
* Output path for contract.d.ts.
|
|
199
|
-
* Should be an absolute or relative path.
|
|
200
|
-
*/
|
|
201
|
-
readonly types: string;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Options for the emit operation.
|
|
205
|
-
*/
|
|
206
|
-
interface EmitOptions {
|
|
207
|
-
/**
|
|
208
|
-
* Contract configuration containing source, output, and types paths.
|
|
209
|
-
*/
|
|
210
|
-
readonly contractConfig: EmitContractConfig;
|
|
211
|
-
/** Optional progress callback for observing operation progress */
|
|
212
|
-
readonly onProgress?: OnControlProgress;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Successful dbInit result.
|
|
216
|
-
*/
|
|
217
|
-
interface DbInitSuccess {
|
|
218
|
-
readonly mode: 'plan' | 'apply';
|
|
219
|
-
readonly plan: {
|
|
220
|
-
readonly operations: ReadonlyArray<{
|
|
221
|
-
readonly id: string;
|
|
222
|
-
readonly label: string;
|
|
223
|
-
readonly operationClass: string;
|
|
224
|
-
}>;
|
|
225
|
-
};
|
|
226
|
-
readonly execution?: {
|
|
227
|
-
readonly operationsPlanned: number;
|
|
228
|
-
readonly operationsExecuted: number;
|
|
229
|
-
};
|
|
230
|
-
readonly marker?: {
|
|
231
|
-
readonly coreHash: string;
|
|
232
|
-
readonly profileHash?: string;
|
|
233
|
-
};
|
|
234
|
-
readonly summary: string;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Failure codes for dbInit operation.
|
|
238
|
-
*/
|
|
239
|
-
type DbInitFailureCode = 'PLANNING_FAILED' | 'MARKER_ORIGIN_MISMATCH' | 'RUNNER_FAILED';
|
|
240
|
-
/**
|
|
241
|
-
* Failure details for dbInit operation.
|
|
242
|
-
*/
|
|
243
|
-
interface DbInitFailure {
|
|
244
|
-
readonly code: DbInitFailureCode;
|
|
245
|
-
readonly summary: string;
|
|
246
|
-
readonly why: string | undefined;
|
|
247
|
-
readonly conflicts: ReadonlyArray<MigrationPlannerConflict> | undefined;
|
|
248
|
-
readonly meta: Record<string, unknown> | undefined;
|
|
249
|
-
readonly marker?: {
|
|
250
|
-
readonly coreHash?: string;
|
|
251
|
-
readonly profileHash?: string;
|
|
252
|
-
};
|
|
253
|
-
readonly destination?: {
|
|
254
|
-
readonly coreHash: string;
|
|
255
|
-
readonly profileHash?: string | undefined;
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Result type for dbInit operation.
|
|
260
|
-
* Uses Result pattern: success returns DbInitSuccess, failure returns DbInitFailure.
|
|
261
|
-
*/
|
|
262
|
-
type DbInitResult = Result<DbInitSuccess, DbInitFailure>;
|
|
263
|
-
/**
|
|
264
|
-
* Successful emit result.
|
|
265
|
-
* Contains the hashes and paths of emitted files.
|
|
266
|
-
*/
|
|
267
|
-
interface EmitSuccess {
|
|
268
|
-
/** Core hash of the emitted contract */
|
|
269
|
-
readonly coreHash: string;
|
|
270
|
-
/** Profile hash of the emitted contract (target-specific) */
|
|
271
|
-
readonly profileHash: string;
|
|
272
|
-
/** The emitted contract as JSON string */
|
|
273
|
-
readonly contractJson: string;
|
|
274
|
-
/** The emitted contract TypeScript declarations */
|
|
275
|
-
readonly contractDts: string;
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Failure codes for emit operation.
|
|
279
|
-
*/
|
|
280
|
-
type EmitFailureCode = 'CONTRACT_SOURCE_INVALID' | 'EMIT_FAILED';
|
|
281
|
-
/**
|
|
282
|
-
* Failure details for emit operation.
|
|
283
|
-
*/
|
|
284
|
-
interface EmitFailure {
|
|
285
|
-
readonly code: EmitFailureCode;
|
|
286
|
-
readonly summary: string;
|
|
287
|
-
readonly why: string | undefined;
|
|
288
|
-
readonly meta: Record<string, unknown> | undefined;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Result type for emit operation.
|
|
292
|
-
* Uses Result pattern: success returns EmitSuccess, failure returns EmitFailure.
|
|
293
|
-
*/
|
|
294
|
-
type EmitResult = Result<EmitSuccess, EmitFailure>;
|
|
295
|
-
/**
|
|
296
|
-
* Programmatic control client for Prisma Next operations.
|
|
297
|
-
*
|
|
298
|
-
* Lifecycle: `connect(connection)` before operations, `close()` when done.
|
|
299
|
-
* Both `init()` and `connect()` are auto-called by operations if needed,
|
|
300
|
-
* but `connect()` requires a connection so must be called explicitly first
|
|
301
|
-
* unless a default connection was provided in options.
|
|
302
|
-
*
|
|
303
|
-
* @see README.md "Programmatic Control API" section for usage examples
|
|
304
|
-
*/
|
|
305
|
-
interface ControlClient {
|
|
306
|
-
/**
|
|
307
|
-
* Initializes the client by creating the control plane stack,
|
|
308
|
-
* family instance, and validating framework components.
|
|
309
|
-
*
|
|
310
|
-
* Idempotent (safe to call multiple times).
|
|
311
|
-
* Called automatically by `connect()` if not already initialized.
|
|
312
|
-
*/
|
|
313
|
-
init(): void;
|
|
314
|
-
/**
|
|
315
|
-
* Establishes a database connection.
|
|
316
|
-
* Auto-calls `init()` if not already initialized.
|
|
317
|
-
* Must be called before any database operations unless a default connection
|
|
318
|
-
* was provided in options.
|
|
319
|
-
*
|
|
320
|
-
* @param connection - Driver-specific connection input (e.g., URL string for Postgres).
|
|
321
|
-
* If omitted, uses the default connection from options (if provided).
|
|
322
|
-
* @throws If connection fails, already connected, driver is not configured,
|
|
323
|
-
* or no connection provided and no default connection in options.
|
|
324
|
-
*/
|
|
325
|
-
connect(connection?: unknown): Promise<void>;
|
|
326
|
-
/**
|
|
327
|
-
* Closes the database connection.
|
|
328
|
-
* Idempotent (safe to call multiple times).
|
|
329
|
-
* After close(), can call `connect()` again with same or different URL.
|
|
330
|
-
*/
|
|
331
|
-
close(): Promise<void>;
|
|
332
|
-
/**
|
|
333
|
-
* Verifies database marker matches the contract.
|
|
334
|
-
* Compares coreHash and profileHash.
|
|
335
|
-
*
|
|
336
|
-
* @returns Structured result (ok: false for mismatch, not throwing)
|
|
337
|
-
* @throws If not connected or infrastructure failure
|
|
338
|
-
*/
|
|
339
|
-
verify(options: VerifyOptions): Promise<VerifyDatabaseResult$1>;
|
|
340
|
-
/**
|
|
341
|
-
* Verifies database schema satisfies the contract requirements.
|
|
342
|
-
*
|
|
343
|
-
* @param options.strict - If true, extra tables/columns are issues. Default: false
|
|
344
|
-
* @returns Structured result with schema issues
|
|
345
|
-
* @throws If not connected or infrastructure failure
|
|
346
|
-
*/
|
|
347
|
-
schemaVerify(options: SchemaVerifyOptions): Promise<VerifyDatabaseSchemaResult$1>;
|
|
348
|
-
/**
|
|
349
|
-
* Signs the database with a contract marker.
|
|
350
|
-
* Writes or updates the contract marker if schema verification passes.
|
|
351
|
-
* Idempotent (no-op if marker already matches).
|
|
352
|
-
*
|
|
353
|
-
* @returns Structured result
|
|
354
|
-
* @throws If not connected or infrastructure failure
|
|
355
|
-
*/
|
|
356
|
-
sign(options: SignOptions): Promise<SignDatabaseResult$1>;
|
|
357
|
-
/**
|
|
358
|
-
* Initializes database schema from contract.
|
|
359
|
-
* Uses additive-only policy (no destructive changes).
|
|
360
|
-
*
|
|
361
|
-
* @param options.mode - 'plan' to preview, 'apply' to execute
|
|
362
|
-
* @returns Result pattern: Ok with planned/executed operations, NotOk with failure details
|
|
363
|
-
* @throws If not connected, target doesn't support migrations, or infrastructure failure
|
|
364
|
-
*/
|
|
365
|
-
dbInit(options: DbInitOptions): Promise<DbInitResult>;
|
|
366
|
-
/**
|
|
367
|
-
* Introspects the database schema.
|
|
368
|
-
*
|
|
369
|
-
* @returns Raw schema IR
|
|
370
|
-
* @throws If not connected or infrastructure failure
|
|
371
|
-
*/
|
|
372
|
-
introspect(options?: IntrospectOptions): Promise<unknown>;
|
|
373
|
-
/**
|
|
374
|
-
* Converts a schema IR to a schema view for CLI tree rendering.
|
|
375
|
-
* Delegates to the family instance's toSchemaView method.
|
|
376
|
-
*
|
|
377
|
-
* @param schemaIR - The schema IR from introspect()
|
|
378
|
-
* @returns CoreSchemaView if the family supports it, undefined otherwise
|
|
379
|
-
*/
|
|
380
|
-
toSchemaView(schemaIR: unknown): CoreSchemaView | undefined;
|
|
381
|
-
/**
|
|
382
|
-
* Emits the contract to JSON and TypeScript declarations.
|
|
383
|
-
* This is an offline operation that does NOT require a database connection.
|
|
384
|
-
* Uses `init()` to create the stack but does NOT call `connect()`.
|
|
385
|
-
*
|
|
386
|
-
* @returns Result pattern: Ok with emit details, NotOk with failure details
|
|
387
|
-
*/
|
|
388
|
-
emit(options: EmitOptions): Promise<EmitResult>;
|
|
389
|
-
}
|
|
390
|
-
//#endregion
|
|
391
|
-
//#region src/control-api/client.d.ts
|
|
392
|
-
/**
|
|
393
|
-
* Creates a programmatic control client for Prisma Next operations.
|
|
394
|
-
*
|
|
395
|
-
* The client accepts framework component descriptors at creation time,
|
|
396
|
-
* manages driver lifecycle via connect()/close(), and exposes domain
|
|
397
|
-
* operations that delegate to the existing family instance methods.
|
|
398
|
-
*
|
|
399
|
-
* @see {@link ControlClient} for the client interface
|
|
400
|
-
* @see README.md "Programmatic Control API" section for usage examples
|
|
401
|
-
*/
|
|
402
|
-
declare function createControlClient(options: ControlClientOptions): ControlClient;
|
|
403
|
-
//#endregion
|
|
404
|
-
export { type ContractSourceLoader, type ContractSourceValue, type ControlActionName, type ControlClient, type ControlClientOptions, type ControlPlaneStack, type ControlProgressEvent, type DbInitFailure, type DbInitFailureCode, type DbInitOptions, type DbInitResult, type DbInitSuccess, type EmitContractConfig, type EmitContractSource, 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 };
|
|
405
|
-
//# sourceMappingURL=control-api.d.mts.map
|
|
@@ -1 +0,0 @@
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B;AAqGA;;;;;;;;;;;;;;iBAAsB,kBAAA,8BAEV,wBACT,QAAQ"}
|
package/dist/exports/index.mjs
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import "../config-loader-B-pobG0R.mjs";
|
|
2
|
-
import "../client-CoxxGz_7.mjs";
|
|
3
|
-
import "../result-handler-Do_4Fi4U.mjs";
|
|
4
|
-
import { createContractEmitCommand } from "../commands/contract-emit.mjs";
|
|
5
|
-
import { existsSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import { tmpdir } from "node:os";
|
|
8
|
-
import { build } from "esbuild";
|
|
9
|
-
|
|
10
|
-
//#region src/load-ts-contract.ts
|
|
11
|
-
const DEFAULT_ALLOWLIST = ["@prisma-next/*"];
|
|
12
|
-
function isAllowedImport(importPath, allowlist) {
|
|
13
|
-
for (const pattern of allowlist) if (pattern.endsWith("/*")) {
|
|
14
|
-
const prefix = pattern.slice(0, -2);
|
|
15
|
-
if (importPath === prefix || importPath.startsWith(`${prefix}/`)) return true;
|
|
16
|
-
} else if (importPath === pattern) return true;
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
function validatePurity(value) {
|
|
20
|
-
if (typeof value !== "object" || value === null) return;
|
|
21
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
22
|
-
function check(value$1) {
|
|
23
|
-
if (value$1 === null || typeof value$1 !== "object") return;
|
|
24
|
-
if (seen.has(value$1)) throw new Error("Contract export contains circular references");
|
|
25
|
-
seen.add(value$1);
|
|
26
|
-
for (const key in value$1) {
|
|
27
|
-
const descriptor = Object.getOwnPropertyDescriptor(value$1, key);
|
|
28
|
-
if (descriptor && (descriptor.get || descriptor.set)) throw new Error(`Contract export contains getter/setter at key "${key}"`);
|
|
29
|
-
if (descriptor && typeof descriptor.value === "function") throw new Error(`Contract export contains function at key "${key}"`);
|
|
30
|
-
check(value$1[key]);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
check(value);
|
|
35
|
-
JSON.stringify(value);
|
|
36
|
-
} catch (error) {
|
|
37
|
-
if (error instanceof Error) {
|
|
38
|
-
if (error.message.includes("getter") || error.message.includes("circular")) throw error;
|
|
39
|
-
throw new Error(`Contract export is not JSON-serializable: ${error.message}`);
|
|
40
|
-
}
|
|
41
|
-
throw new Error("Contract export is not JSON-serializable");
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function createImportAllowlistPlugin(allowlist, entryPath) {
|
|
45
|
-
return {
|
|
46
|
-
name: "import-allowlist",
|
|
47
|
-
setup(build$1) {
|
|
48
|
-
build$1.onResolve({ filter: /.*/ }, (args) => {
|
|
49
|
-
if (args.kind === "entry-point") return;
|
|
50
|
-
if (args.path.startsWith(".") || args.path.startsWith("/")) return;
|
|
51
|
-
if ((args.importer === entryPath || args.importer === "<stdin>") && !isAllowedImport(args.path, allowlist)) return {
|
|
52
|
-
path: args.path,
|
|
53
|
-
external: true
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Loads a contract from a TypeScript file and returns it as ContractIR.
|
|
61
|
-
*
|
|
62
|
-
* **Responsibility: Parsing Only**
|
|
63
|
-
* This function loads and parses a TypeScript contract file. It does NOT normalize the contract.
|
|
64
|
-
* The contract should already be normalized if it was built using the contract builder.
|
|
65
|
-
*
|
|
66
|
-
* Normalization must happen in the contract builder when the contract is created.
|
|
67
|
-
* This function only validates that the contract is JSON-serializable and returns it as-is.
|
|
68
|
-
*
|
|
69
|
-
* @param entryPath - Path to the TypeScript contract file
|
|
70
|
-
* @param options - Optional configuration (import allowlist)
|
|
71
|
-
* @returns The contract as ContractIR (should already be normalized)
|
|
72
|
-
* @throws Error if the contract cannot be loaded or is not JSON-serializable
|
|
73
|
-
*/
|
|
74
|
-
async function loadContractFromTs(entryPath, options) {
|
|
75
|
-
const allowlist = options?.allowlist ?? DEFAULT_ALLOWLIST;
|
|
76
|
-
if (!existsSync(entryPath)) throw new Error(`Contract file not found: ${entryPath}`);
|
|
77
|
-
const tempFile = join(tmpdir(), `prisma-next-contract-${Date.now()}-${Math.random().toString(36).slice(2)}.mjs`);
|
|
78
|
-
try {
|
|
79
|
-
const result = await build({
|
|
80
|
-
entryPoints: [entryPath],
|
|
81
|
-
bundle: true,
|
|
82
|
-
format: "esm",
|
|
83
|
-
platform: "node",
|
|
84
|
-
target: "es2022",
|
|
85
|
-
outfile: tempFile,
|
|
86
|
-
write: false,
|
|
87
|
-
metafile: true,
|
|
88
|
-
plugins: [createImportAllowlistPlugin(allowlist, entryPath)],
|
|
89
|
-
logLevel: "error"
|
|
90
|
-
});
|
|
91
|
-
if (result.errors.length > 0) {
|
|
92
|
-
const errorMessages = result.errors.map((e) => e.text).join("\n");
|
|
93
|
-
throw new Error(`Failed to bundle contract file: ${errorMessages}`);
|
|
94
|
-
}
|
|
95
|
-
if (!result.outputFiles || result.outputFiles.length === 0) throw new Error("No output files generated from bundling");
|
|
96
|
-
const disallowedImports = [];
|
|
97
|
-
if (result.metafile) {
|
|
98
|
-
const inputs = result.metafile.inputs;
|
|
99
|
-
for (const [, inputData] of Object.entries(inputs)) {
|
|
100
|
-
const imports = inputData.imports || [];
|
|
101
|
-
for (const imp of imports) if (imp.external && !imp.path.startsWith(".") && !imp.path.startsWith("/") && !isAllowedImport(imp.path, allowlist)) disallowedImports.push(imp.path);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (disallowedImports.length > 0) throw new Error(`Disallowed imports detected. Only imports matching the allowlist are permitted:\n Allowlist: ${allowlist.join(", ")}\n Disallowed imports: ${disallowedImports.join(", ")}\n\nOnly @prisma-next/* packages are allowed in contract files.`);
|
|
105
|
-
const bundleContent = result.outputFiles[0]?.text;
|
|
106
|
-
if (bundleContent === void 0) throw new Error("Bundle content is undefined");
|
|
107
|
-
writeFileSync(tempFile, bundleContent, "utf-8");
|
|
108
|
-
const module = await import(`file://${tempFile}`);
|
|
109
|
-
unlinkSync(tempFile);
|
|
110
|
-
let contract;
|
|
111
|
-
if (module.default !== void 0) contract = module.default;
|
|
112
|
-
else if (module.contract !== void 0) contract = module.contract;
|
|
113
|
-
else throw new Error(`Contract file must export a contract as default export or named export 'contract'. Found exports: ${Object.keys(module).join(", ") || "none"}`);
|
|
114
|
-
if (typeof contract !== "object" || contract === null) throw new Error(`Contract export must be an object, got ${typeof contract}`);
|
|
115
|
-
validatePurity(contract);
|
|
116
|
-
return contract;
|
|
117
|
-
} catch (error) {
|
|
118
|
-
try {
|
|
119
|
-
if (tempFile) unlinkSync(tempFile);
|
|
120
|
-
} catch {}
|
|
121
|
-
if (error instanceof Error) throw error;
|
|
122
|
-
throw new Error(`Failed to load contract from ${entryPath}: ${String(error)}`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
//#endregion
|
|
127
|
-
export { createContractEmitCommand, loadContractFromTs };
|
|
128
|
-
//# sourceMappingURL=index.mjs.map
|