@prisma-next/core-control-plane 0.3.0-dev.46 → 0.3.0-dev.47
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 +6 -1
- package/dist/{config-types-CnWxlkH_.d.mts → config-types-Ci0VxOEC.d.mts} +31 -7
- package/dist/config-types-Ci0VxOEC.d.mts.map +1 -0
- package/dist/config-types.d.mts +3 -3
- package/dist/config-types.mjs +3 -3
- package/dist/config-types.mjs.map +1 -1
- package/dist/config-validation.d.mts +2 -2
- package/dist/config-validation.mjs +1 -0
- package/dist/config-validation.mjs.map +1 -1
- package/dist/emission.d.mts +16 -19
- package/dist/emission.d.mts.map +1 -1
- package/dist/emission.mjs +36 -19
- package/dist/emission.mjs.map +1 -1
- package/dist/{schema-view-BG_ebqoV.d.mts → schema-view-D9u47nc8.d.mts} +1 -1
- package/dist/{schema-view-BG_ebqoV.d.mts.map → schema-view-D9u47nc8.d.mts.map} +1 -1
- package/dist/schema-view.d.mts +1 -1
- package/dist/stack.d.mts +1 -1
- package/dist/{types-DE-eb6_U.d.mts → types-CuAauVCJ.d.mts} +3 -3
- package/dist/{types-DE-eb6_U.d.mts.map → types-CuAauVCJ.d.mts.map} +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +4 -4
- package/src/config-types.ts +10 -17
- package/src/config-validation.ts +7 -0
- package/src/contract-source-types.ts +28 -0
- package/src/emission/canonicalization.ts +18 -9
- package/src/emission/emit.ts +46 -16
- package/src/emission/hashing.ts +7 -25
- package/src/exports/config-types.ts +7 -0
- package/dist/config-types-CnWxlkH_.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -61,7 +61,8 @@ const config = defineConfig({
|
|
|
61
61
|
target: postgresTargetDescriptor,
|
|
62
62
|
adapter: postgresAdapterDescriptor,
|
|
63
63
|
contract: {
|
|
64
|
-
source: contractBuilder,
|
|
64
|
+
source: contractBuilder, // TS-first value/loader
|
|
65
|
+
// source: { kind: 'psl', schemaPath: './schema.prisma' }, // PSL-first
|
|
65
66
|
output: 'src/prisma/contract.json',
|
|
66
67
|
},
|
|
67
68
|
});
|
|
@@ -70,6 +71,10 @@ const config = defineConfig({
|
|
|
70
71
|
validateConfig(config);
|
|
71
72
|
```
|
|
72
73
|
|
|
74
|
+
`contract.source` supports:
|
|
75
|
+
- direct values and sync/async loader functions (TS-first)
|
|
76
|
+
- `{ kind: 'psl', schemaPath: string }` (PSL-first, requires non-empty `schemaPath`)
|
|
77
|
+
|
|
73
78
|
### ControlPlaneStack
|
|
74
79
|
|
|
75
80
|
The `ControlPlaneStack` bundles component descriptors for control plane operations (creating family instances, running CLI commands, connecting to databases):
|
|
@@ -1,16 +1,40 @@
|
|
|
1
|
-
import { a as ControlExtensionDescriptor, i as ControlDriverInstance, r as ControlDriverDescriptor, s as ControlFamilyDescriptor, t as ControlAdapterDescriptor, u as ControlTargetDescriptor } from "./types-
|
|
1
|
+
import { a as ControlExtensionDescriptor, i as ControlDriverInstance, r as ControlDriverDescriptor, s as ControlFamilyDescriptor, t as ControlAdapterDescriptor, u as ControlTargetDescriptor } from "./types-CuAauVCJ.mjs";
|
|
2
|
+
import { ContractIR } from "@prisma-next/contract/ir";
|
|
3
|
+
import { Result } from "@prisma-next/utils/result";
|
|
2
4
|
|
|
5
|
+
//#region src/contract-source-types.d.ts
|
|
6
|
+
interface ContractSourceDiagnosticPosition {
|
|
7
|
+
readonly offset: number;
|
|
8
|
+
readonly line: number;
|
|
9
|
+
readonly column: number;
|
|
10
|
+
}
|
|
11
|
+
interface ContractSourceDiagnosticSpan {
|
|
12
|
+
readonly start: ContractSourceDiagnosticPosition;
|
|
13
|
+
readonly end: ContractSourceDiagnosticPosition;
|
|
14
|
+
}
|
|
15
|
+
interface ContractSourceDiagnostic {
|
|
16
|
+
readonly code: string;
|
|
17
|
+
readonly message: string;
|
|
18
|
+
readonly sourceId?: string;
|
|
19
|
+
readonly span?: ContractSourceDiagnosticSpan;
|
|
20
|
+
}
|
|
21
|
+
interface ContractSourceDiagnostics {
|
|
22
|
+
readonly summary: string;
|
|
23
|
+
readonly diagnostics: readonly ContractSourceDiagnostic[];
|
|
24
|
+
readonly meta?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
type ContractSourceProvider = () => Promise<Result<ContractIR, ContractSourceDiagnostics>>;
|
|
27
|
+
//#endregion
|
|
3
28
|
//#region src/config-types.d.ts
|
|
4
|
-
|
|
5
29
|
/**
|
|
6
30
|
* Contract configuration specifying source and artifact locations.
|
|
7
31
|
*/
|
|
8
32
|
interface ContractConfig {
|
|
9
33
|
/**
|
|
10
|
-
* Contract source.
|
|
11
|
-
*
|
|
34
|
+
* Contract source provider. The provider is always async and must return
|
|
35
|
+
* a Result containing either ContractIR or structured diagnostics.
|
|
12
36
|
*/
|
|
13
|
-
readonly source:
|
|
37
|
+
readonly source: ContractSourceProvider;
|
|
14
38
|
/**
|
|
15
39
|
* Path to contract.json artifact. Defaults to 'src/prisma/contract.json'.
|
|
16
40
|
* The .d.ts types file will be colocated (e.g., contract.json → contract.d.ts).
|
|
@@ -68,5 +92,5 @@ interface PrismaNextConfig<TFamilyId extends string = string, TTargetId extends
|
|
|
68
92
|
*/
|
|
69
93
|
declare function defineConfig<TFamilyId extends string = string, TTargetId extends string = string>(config: PrismaNextConfig<TFamilyId, TTargetId>): PrismaNextConfig<TFamilyId, TTargetId>;
|
|
70
94
|
//#endregion
|
|
71
|
-
export { PrismaNextConfig as n, defineConfig as r, ContractConfig as t };
|
|
72
|
-
//# sourceMappingURL=config-types-
|
|
95
|
+
export { ContractSourceDiagnosticPosition as a, ContractSourceProvider as c, ContractSourceDiagnostic as i, PrismaNextConfig as n, ContractSourceDiagnosticSpan as o, defineConfig as r, ContractSourceDiagnostics as s, ContractConfig as t };
|
|
96
|
+
//# sourceMappingURL=config-types-Ci0VxOEC.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-types-Ci0VxOEC.d.mts","names":[],"sources":["../src/contract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E,EAzDS,SAyDT,CAAA,EAxDxB,WAwDwB,CAAA;EACD;;;;EACI,SAAA,EAAA,CAAA,EAAA;IAA5B;;;;;0BA9CuB;;;;;;sBAMJ;;;;;;;;;;;;;iBAsCN,2FACN,iBAAiB,WAAW,aACnC,iBAAiB,WAAW"}
|
package/dist/config-types.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./types-
|
|
2
|
-
import
|
|
3
|
-
export { type ContractConfig, type PrismaNextConfig, defineConfig };
|
|
1
|
+
import { a as ContractSourceDiagnosticPosition, c as ContractSourceProvider, i as ContractSourceDiagnostic, n as PrismaNextConfig, o as ContractSourceDiagnosticSpan, r as defineConfig, s as ContractSourceDiagnostics, t as ContractConfig } from "./config-types-Ci0VxOEC.mjs";
|
|
2
|
+
import "./types-CuAauVCJ.mjs";
|
|
3
|
+
export { type ContractConfig, type ContractSourceDiagnostic, type ContractSourceDiagnosticPosition, type ContractSourceDiagnosticSpan, type ContractSourceDiagnostics, type ContractSourceProvider, type PrismaNextConfig, defineConfig };
|
package/dist/config-types.mjs
CHANGED
|
@@ -3,7 +3,8 @@ import { type } from "arktype";
|
|
|
3
3
|
//#region src/config-types.ts
|
|
4
4
|
/**
|
|
5
5
|
* Arktype schema for ContractConfig validation.
|
|
6
|
-
* Validates
|
|
6
|
+
* Validates presence/shape only.
|
|
7
|
+
* contract.source is validated as a provider function at runtime in defineConfig().
|
|
7
8
|
*/
|
|
8
9
|
const ContractConfigSchema = type({
|
|
9
10
|
source: "unknown",
|
|
@@ -40,8 +41,7 @@ function defineConfig(config) {
|
|
|
40
41
|
throw new Error(`Config validation failed: ${messages}`);
|
|
41
42
|
}
|
|
42
43
|
if (config.contract) {
|
|
43
|
-
|
|
44
|
-
if (source !== null && typeof source !== "object" && typeof source !== "function" && typeof source !== "string" && typeof source !== "number" && typeof source !== "boolean") throw new Error("Config.contract.source must be a value (object, string, number, boolean, null) or a function");
|
|
44
|
+
if (typeof config.contract.source !== "function") throw new Error("Config.contract.source must be a provider function");
|
|
45
45
|
const output = config.contract.output ?? "src/prisma/contract.json";
|
|
46
46
|
const normalizedContract = {
|
|
47
47
|
source: config.contract.source,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-types.mjs","names":["normalizedContract: ContractConfig"],"sources":["../src/config-types.ts"],"sourcesContent":["import { type } from 'arktype';\nimport type {\n ControlAdapterDescriptor,\n ControlDriverDescriptor,\n ControlDriverInstance,\n ControlExtensionDescriptor,\n ControlFamilyDescriptor,\n ControlTargetDescriptor,\n} from './types';\n\n/**\n * Type alias for CLI driver instances.\n * Uses string for both family and target IDs for maximum flexibility.\n */\nexport type CliDriver = ControlDriverInstance<string, string>;\n\n/**\n * Contract configuration specifying source and artifact locations.\n */\nexport interface ContractConfig {\n /**\n * Contract source.
|
|
1
|
+
{"version":3,"file":"config-types.mjs","names":["normalizedContract: ContractConfig"],"sources":["../src/config-types.ts"],"sourcesContent":["import { type } from 'arktype';\nimport type { ContractSourceProvider } from './contract-source-types';\nimport type {\n ControlAdapterDescriptor,\n ControlDriverDescriptor,\n ControlDriverInstance,\n ControlExtensionDescriptor,\n ControlFamilyDescriptor,\n ControlTargetDescriptor,\n} from './types';\n\n/**\n * Type alias for CLI driver instances.\n * Uses string for both family and target IDs for maximum flexibility.\n */\nexport type CliDriver = ControlDriverInstance<string, string>;\n\n/**\n * Contract configuration specifying source and artifact locations.\n */\nexport interface ContractConfig {\n /**\n * Contract source provider. The provider is always async and must return\n * a Result containing either ContractIR or structured diagnostics.\n */\n readonly source: ContractSourceProvider;\n /**\n * Path to contract.json artifact. Defaults to 'src/prisma/contract.json'.\n * The .d.ts types file will be colocated (e.g., contract.json → contract.d.ts).\n */\n readonly output?: string;\n}\n\n/**\n * Configuration for Prisma Next CLI.\n * Uses Control*Descriptor types for type-safe wiring with compile-time compatibility checks.\n *\n * @template TFamilyId - The family ID (e.g., 'sql', 'document')\n * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')\n * @template TConnection - The driver connection input type (defaults to `unknown` for config flexibility)\n */\nexport interface PrismaNextConfig<\n TFamilyId extends string = string,\n TTargetId extends string = string,\n TConnection = unknown,\n> {\n readonly family: ControlFamilyDescriptor<TFamilyId>;\n readonly target: ControlTargetDescriptor<TFamilyId, TTargetId>;\n readonly adapter: ControlAdapterDescriptor<TFamilyId, TTargetId>;\n readonly extensionPacks?: readonly ControlExtensionDescriptor<TFamilyId, TTargetId>[];\n /**\n * Driver descriptor for DB-connected CLI commands.\n * Required for DB-connected commands (e.g., db verify).\n * Optional for commands that don't need database access (e.g., emit).\n * The driver's connection type matches the TConnection config parameter.\n */\n readonly driver?: ControlDriverDescriptor<\n TFamilyId,\n TTargetId,\n ControlDriverInstance<TFamilyId, TTargetId>,\n TConnection\n >;\n /**\n * Database connection configuration.\n * The connection type is driver-specific (e.g., URL string for Postgres).\n */\n readonly db?: {\n /**\n * Driver-specific connection input.\n * For Postgres: a connection string (URL).\n * For other drivers: may be a structured object.\n */\n readonly connection?: TConnection;\n };\n /**\n * Contract configuration. Specifies source and artifact locations.\n * Required for emit command; optional for other commands that only read artifacts.\n */\n readonly contract?: ContractConfig;\n}\n\n/**\n * Arktype schema for ContractConfig validation.\n * Validates presence/shape only.\n * contract.source is validated as a provider function at runtime in defineConfig().\n */\nconst ContractConfigSchema = type({\n source: 'unknown', // Runtime check enforces provider function shape\n 'output?': 'string',\n});\n\n/**\n * Arktype schema for PrismaNextConfig validation.\n * Note: This validates structure only. Descriptor objects (family, target, adapter) are validated separately.\n */\nconst PrismaNextConfigSchema = type({\n family: 'unknown', // ControlFamilyDescriptor - validated separately\n target: 'unknown', // ControlTargetDescriptor - validated separately\n adapter: 'unknown', // ControlAdapterDescriptor - validated separately\n 'extensionPacks?': 'unknown[]',\n 'driver?': 'unknown', // ControlDriverDescriptor - validated separately (optional)\n 'db?': 'unknown',\n 'contract?': ContractConfigSchema,\n});\n\n/**\n * Helper function to define a Prisma Next config.\n * Validates and normalizes the config using Arktype, then returns the normalized IR.\n *\n * Normalization:\n * - contract.output defaults to 'src/prisma/contract.json' if missing\n *\n * @param config - Raw config input from user\n * @returns Normalized config IR with defaults applied\n * @throws Error if config structure is invalid\n */\nexport function defineConfig<TFamilyId extends string = string, TTargetId extends string = string>(\n config: PrismaNextConfig<TFamilyId, TTargetId>,\n): PrismaNextConfig<TFamilyId, TTargetId> {\n // Validate structure using Arktype\n const validated = PrismaNextConfigSchema(config);\n if (validated instanceof type.errors) {\n const messages = validated.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Config validation failed: ${messages}`);\n }\n\n // Normalize contract config if present\n if (config.contract) {\n // Validate contract.source provider function shape at runtime.\n const source = config.contract.source;\n if (typeof source !== 'function') {\n throw new Error('Config.contract.source must be a provider function');\n }\n\n // Apply defaults\n const output = config.contract.output ?? 'src/prisma/contract.json';\n\n const normalizedContract: ContractConfig = {\n source: config.contract.source,\n output,\n };\n\n // Return normalized config\n return {\n ...config,\n contract: normalizedContract,\n };\n }\n\n // Return config as-is if no contract (preserve literal types)\n return config;\n}\n"],"mappings":";;;;;;;;AAsFA,MAAM,uBAAuB,KAAK;CAChC,QAAQ;CACR,WAAW;CACZ,CAAC;;;;;AAMF,MAAM,yBAAyB,KAAK;CAClC,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,mBAAmB;CACnB,WAAW;CACX,OAAO;CACP,aAAa;CACd,CAAC;;;;;;;;;;;;AAaF,SAAgB,aACd,QACwC;CAExC,MAAM,YAAY,uBAAuB,OAAO;AAChD,KAAI,qBAAqB,KAAK,QAAQ;EACpC,MAAM,WAAW,UAAU,KAAK,MAA2B,EAAE,QAAQ,CAAC,KAAK,KAAK;AAChF,QAAM,IAAI,MAAM,6BAA6B,WAAW;;AAI1D,KAAI,OAAO,UAAU;AAGnB,MAAI,OADW,OAAO,SAAS,WACT,WACpB,OAAM,IAAI,MAAM,qDAAqD;EAIvE,MAAM,SAAS,OAAO,SAAS,UAAU;EAEzC,MAAMA,qBAAqC;GACzC,QAAQ,OAAO,SAAS;GACxB;GACD;AAGD,SAAO;GACL,GAAG;GACH,UAAU;GACX;;AAIH,QAAO"}
|
|
@@ -69,6 +69,7 @@ function validateConfig(config) {
|
|
|
69
69
|
const contract = configObj["contract"];
|
|
70
70
|
if (!contract || typeof contract !== "object") throw errorConfigValidation("contract", { why: "Config.contract must be an object" });
|
|
71
71
|
if (!("source" in contract)) throw errorConfigValidation("contract.source", { why: "Config.contract.source is required when contract is provided" });
|
|
72
|
+
if (typeof contract["source"] !== "function") throw errorConfigValidation("contract.source", { why: "Config.contract.source must be a provider function" });
|
|
72
73
|
if (contract["output"] !== void 0 && typeof contract["output"] !== "string") throw errorConfigValidation("contract.output", { why: "Config.contract.output must be a string when provided" });
|
|
73
74
|
}
|
|
74
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-validation.mjs","names":[],"sources":["../src/config-validation.ts"],"sourcesContent":["import type { PrismaNextConfig } from './config-types';\nimport { errorConfigValidation } from './errors';\n\n/**\n * Validates that the config has the required structure.\n * This is pure validation logic with no file I/O or CLI awareness.\n *\n * @param config - Config object to validate\n * @throws CliStructuredError if config structure is invalid\n */\nexport function validateConfig(config: unknown): asserts config is PrismaNextConfig {\n if (!config || typeof config !== 'object') {\n throw errorConfigValidation('object', {\n why: 'Config must be an object',\n });\n }\n\n const configObj = config as Record<string, unknown>;\n\n if (!configObj['family']) {\n throw errorConfigValidation('family');\n }\n\n if (!configObj['target']) {\n throw errorConfigValidation('target');\n }\n\n if (!configObj['adapter']) {\n throw errorConfigValidation('adapter');\n }\n\n // Validate family descriptor\n const family = configObj['family'] as Record<string, unknown>;\n if (family['kind'] !== 'family') {\n throw errorConfigValidation('family.kind', {\n why: 'Config.family must have kind: \"family\"',\n });\n }\n if (typeof family['familyId'] !== 'string') {\n throw errorConfigValidation('family.familyId', {\n why: 'Config.family must have familyId: string',\n });\n }\n if (typeof family['version'] !== 'string') {\n throw errorConfigValidation('family.version', {\n why: 'Config.family must have version: string',\n });\n }\n if (!family['hook'] || typeof family['hook'] !== 'object') {\n throw errorConfigValidation('family.hook', {\n why: 'Config.family must have hook: TargetFamilyHook',\n });\n }\n if (typeof family['create'] !== 'function') {\n throw errorConfigValidation('family.create', {\n why: 'Config.family must have create: function',\n });\n }\n\n const familyId = family['familyId'] as string;\n\n // Validate target descriptor\n const target = configObj['target'] as Record<string, unknown>;\n if (target['kind'] !== 'target') {\n throw errorConfigValidation('target.kind', {\n why: 'Config.target must have kind: \"target\"',\n });\n }\n if (typeof target['id'] !== 'string') {\n throw errorConfigValidation('target.id', {\n why: 'Config.target must have id: string',\n });\n }\n if (typeof target['familyId'] !== 'string') {\n throw errorConfigValidation('target.familyId', {\n why: 'Config.target must have familyId: string',\n });\n }\n if (typeof target['version'] !== 'string') {\n throw errorConfigValidation('target.version', {\n why: 'Config.target must have version: string',\n });\n }\n if (target['familyId'] !== familyId) {\n throw errorConfigValidation('target.familyId', {\n why: `Config.target.familyId must match Config.family.familyId (expected: ${familyId}, got: ${target['familyId']})`,\n });\n }\n if (typeof target['targetId'] !== 'string') {\n throw errorConfigValidation('target.targetId', {\n why: 'Config.target must have targetId: string',\n });\n }\n if (typeof target['create'] !== 'function') {\n throw errorConfigValidation('target.create', {\n why: 'Config.target must have create: function',\n });\n }\n const expectedTargetId = target['targetId'] as string;\n\n // Validate adapter descriptor\n const adapter = configObj['adapter'] as Record<string, unknown>;\n if (adapter['kind'] !== 'adapter') {\n throw errorConfigValidation('adapter.kind', {\n why: 'Config.adapter must have kind: \"adapter\"',\n });\n }\n if (typeof adapter['id'] !== 'string') {\n throw errorConfigValidation('adapter.id', {\n why: 'Config.adapter must have id: string',\n });\n }\n if (typeof adapter['familyId'] !== 'string') {\n throw errorConfigValidation('adapter.familyId', {\n why: 'Config.adapter must have familyId: string',\n });\n }\n if (typeof adapter['version'] !== 'string') {\n throw errorConfigValidation('adapter.version', {\n why: 'Config.adapter must have version: string',\n });\n }\n if (adapter['familyId'] !== familyId) {\n throw errorConfigValidation('adapter.familyId', {\n why: `Config.adapter.familyId must match Config.family.familyId (expected: ${familyId}, got: ${adapter['familyId']})`,\n });\n }\n if (typeof adapter['targetId'] !== 'string') {\n throw errorConfigValidation('adapter.targetId', {\n why: 'Config.adapter must have targetId: string',\n });\n }\n if (adapter['targetId'] !== expectedTargetId) {\n throw errorConfigValidation('adapter.targetId', {\n why: `Config.adapter.targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${adapter['targetId']})`,\n });\n }\n if (typeof adapter['create'] !== 'function') {\n throw errorConfigValidation('adapter.create', {\n why: 'Config.adapter must have create: function',\n });\n }\n\n // Validate extensions array if present\n if (configObj['extensions'] !== undefined) {\n if (!Array.isArray(configObj['extensions'])) {\n throw errorConfigValidation('extensions', {\n why: 'Config.extensions must be an array',\n });\n }\n for (const ext of configObj['extensions']) {\n if (!ext || typeof ext !== 'object') {\n throw errorConfigValidation('extensions[]', {\n why: 'Config.extensions must contain ExtensionDescriptor objects',\n });\n }\n const extObj = ext as Record<string, unknown>;\n if (extObj['kind'] !== 'extension') {\n throw errorConfigValidation('extensions[].kind', {\n why: 'Config.extensions items must have kind: \"extension\"',\n });\n }\n if (typeof extObj['id'] !== 'string') {\n throw errorConfigValidation('extensions[].id', {\n why: 'Config.extensions items must have id: string',\n });\n }\n if (typeof extObj['familyId'] !== 'string') {\n throw errorConfigValidation('extensions[].familyId', {\n why: 'Config.extensions items must have familyId: string',\n });\n }\n if (typeof extObj['version'] !== 'string') {\n throw errorConfigValidation('extensions[].version', {\n why: 'Config.extensions items must have version: string',\n });\n }\n if (extObj['familyId'] !== familyId) {\n throw errorConfigValidation('extensions[].familyId', {\n why: `Config.extensions[].familyId must match Config.family.familyId (expected: ${familyId}, got: ${extObj['familyId']})`,\n });\n }\n if (typeof extObj['targetId'] !== 'string') {\n throw errorConfigValidation('extensions[].targetId', {\n why: 'Config.extensions items must have targetId: string',\n });\n }\n if (extObj['targetId'] !== expectedTargetId) {\n throw errorConfigValidation('extensions[].targetId', {\n why: `Config.extensions[].targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${extObj['targetId']})`,\n });\n }\n if (typeof extObj['create'] !== 'function') {\n throw errorConfigValidation('extensions[].create', {\n why: 'Config.extensions items must have create: function',\n });\n }\n }\n }\n\n // Validate driver descriptor if present\n if (configObj['driver'] !== undefined) {\n const driver = configObj['driver'] as Record<string, unknown>;\n if (driver['kind'] !== 'driver') {\n throw errorConfigValidation('driver.kind', {\n why: 'Config.driver must have kind: \"driver\"',\n });\n }\n if (typeof driver['id'] !== 'string') {\n throw errorConfigValidation('driver.id', {\n why: 'Config.driver must have id: string',\n });\n }\n if (typeof driver['version'] !== 'string') {\n throw errorConfigValidation('driver.version', {\n why: 'Config.driver must have version: string',\n });\n }\n if (typeof driver['familyId'] !== 'string') {\n throw errorConfigValidation('driver.familyId', {\n why: 'Config.driver must have familyId: string',\n });\n }\n if (driver['familyId'] !== familyId) {\n throw errorConfigValidation('driver.familyId', {\n why: `Config.driver.familyId must match Config.family.familyId (expected: ${familyId}, got: ${driver['familyId']})`,\n });\n }\n if (typeof driver['targetId'] !== 'string') {\n throw errorConfigValidation('driver.targetId', {\n why: 'Config.driver must have targetId: string',\n });\n }\n if (driver['targetId'] !== expectedTargetId) {\n throw errorConfigValidation('driver.targetId', {\n why: `Config.driver.targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${driver['targetId']})`,\n });\n }\n if (typeof driver['create'] !== 'function') {\n throw errorConfigValidation('driver.create', {\n why: 'Config.driver must have create: function',\n });\n }\n }\n\n // Validate contract config if present (structure validation - defineConfig() handles normalization)\n if (configObj['contract'] !== undefined) {\n const contract = configObj['contract'] as Record<string, unknown>;\n if (!contract || typeof contract !== 'object') {\n throw errorConfigValidation('contract', {\n why: 'Config.contract must be an object',\n });\n }\n if (!('source' in contract)) {\n throw errorConfigValidation('contract.source', {\n why: 'Config.contract.source is required when contract is provided',\n });\n }\n if (contract['output'] !== undefined && typeof contract['output'] !== 'string') {\n throw errorConfig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N,CAAC;AAEJ,MAAI,OAAO,gBAAgB,SACzB,OAAM,sBAAsB,mBAAmB,EAC7C,KAAK,uEAAuE,SAAS,SAAS,OAAO,YAAY,IAClH,CAAC;AAEJ,MAAI,OAAO,OAAO,gBAAgB,SAChC,OAAM,sBAAsB,mBAAmB,EAC7C,KAAK,4CACN,CAAC;AAEJ,MAAI,OAAO,gBAAgB,iBACzB,OAAM,sBAAsB,mBAAmB,EAC7C,KAAK,uEAAuE,iBAAiB,SAAS,OAAO,YAAY,IAC1H,CAAC;AAEJ,MAAI,OAAO,OAAO,cAAc,WAC9B,OAAM,sBAAsB,iBAAiB,EAC3C,KAAK,4CACN,CAAC;;AAKN,KAAI,UAAU,gBAAgB,QAAW;EACvC,MAAM,WAAW,UAAU;AAC3B,MAAI,CAAC,YAAY,OAAO,aAAa,SACnC,OAAM,sBAAsB,YAAY,EACtC,KAAK,qCACN,CAAC;AAEJ,MAAI,EAAE,YAAY,UAChB,OAAM,sBAAsB,mBAAmB,EAC7C,KAAK,gEACN,CAAC;AAEJ,MAAI,SAAS,cAAc,UAAa,OAAO,SAAS,cAAc,SACpE,OAAM,sBAAsB,mBAAmB,EAC7C,KAAK,yDACN,CAAC"}
|
|
1
|
+
{"version":3,"file":"config-validation.mjs","names":[],"sources":["../src/config-validation.ts"],"sourcesContent":["import type { PrismaNextConfig } from './config-types';\nimport { errorConfigValidation } from './errors';\n\n/**\n * Validates that the config has the required structure.\n * This is pure validation logic with no file I/O or CLI awareness.\n *\n * @param config - Config object to validate\n * @throws CliStructuredError if config structure is invalid\n */\nexport function validateConfig(config: unknown): asserts config is PrismaNextConfig {\n if (!config || typeof config !== 'object') {\n throw errorConfigValidation('object', {\n why: 'Config must be an object',\n });\n }\n\n const configObj = config as Record<string, unknown>;\n\n if (!configObj['family']) {\n throw errorConfigValidation('family');\n }\n\n if (!configObj['target']) {\n throw errorConfigValidation('target');\n }\n\n if (!configObj['adapter']) {\n throw errorConfigValidation('adapter');\n }\n\n // Validate family descriptor\n const family = configObj['family'] as Record<string, unknown>;\n if (family['kind'] !== 'family') {\n throw errorConfigValidation('family.kind', {\n why: 'Config.family must have kind: \"family\"',\n });\n }\n if (typeof family['familyId'] !== 'string') {\n throw errorConfigValidation('family.familyId', {\n why: 'Config.family must have familyId: string',\n });\n }\n if (typeof family['version'] !== 'string') {\n throw errorConfigValidation('family.version', {\n why: 'Config.family must have version: string',\n });\n }\n if (!family['hook'] || typeof family['hook'] !== 'object') {\n throw errorConfigValidation('family.hook', {\n why: 'Config.family must have hook: TargetFamilyHook',\n });\n }\n if (typeof family['create'] !== 'function') {\n throw errorConfigValidation('family.create', {\n why: 'Config.family must have create: function',\n });\n }\n\n const familyId = family['familyId'] as string;\n\n // Validate target descriptor\n const target = configObj['target'] as Record<string, unknown>;\n if (target['kind'] !== 'target') {\n throw errorConfigValidation('target.kind', {\n why: 'Config.target must have kind: \"target\"',\n });\n }\n if (typeof target['id'] !== 'string') {\n throw errorConfigValidation('target.id', {\n why: 'Config.target must have id: string',\n });\n }\n if (typeof target['familyId'] !== 'string') {\n throw errorConfigValidation('target.familyId', {\n why: 'Config.target must have familyId: string',\n });\n }\n if (typeof target['version'] !== 'string') {\n throw errorConfigValidation('target.version', {\n why: 'Config.target must have version: string',\n });\n }\n if (target['familyId'] !== familyId) {\n throw errorConfigValidation('target.familyId', {\n why: `Config.target.familyId must match Config.family.familyId (expected: ${familyId}, got: ${target['familyId']})`,\n });\n }\n if (typeof target['targetId'] !== 'string') {\n throw errorConfigValidation('target.targetId', {\n why: 'Config.target must have targetId: string',\n });\n }\n if (typeof target['create'] !== 'function') {\n throw errorConfigValidation('target.create', {\n why: 'Config.target must have create: function',\n });\n }\n const expectedTargetId = target['targetId'] as string;\n\n // Validate adapter descriptor\n const adapter = configObj['adapter'] as Record<string, unknown>;\n if (adapter['kind'] !== 'adapter') {\n throw errorConfigValidation('adapter.kind', {\n why: 'Config.adapter must have kind: \"adapter\"',\n });\n }\n if (typeof adapter['id'] !== 'string') {\n throw errorConfigValidation('adapter.id', {\n why: 'Config.adapter must have id: string',\n });\n }\n if (typeof adapter['familyId'] !== 'string') {\n throw errorConfigValidation('adapter.familyId', {\n why: 'Config.adapter must have familyId: string',\n });\n }\n if (typeof adapter['version'] !== 'string') {\n throw errorConfigValidation('adapter.version', {\n why: 'Config.adapter must have version: string',\n });\n }\n if (adapter['familyId'] !== familyId) {\n throw errorConfigValidation('adapter.familyId', {\n why: `Config.adapter.familyId must match Config.family.familyId (expected: ${familyId}, got: ${adapter['familyId']})`,\n });\n }\n if (typeof adapter['targetId'] !== 'string') {\n throw errorConfigValidation('adapter.targetId', {\n why: 'Config.adapter must have targetId: string',\n });\n }\n if (adapter['targetId'] !== expectedTargetId) {\n throw errorConfigValidation('adapter.targetId', {\n why: `Config.adapter.targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${adapter['targetId']})`,\n });\n }\n if (typeof adapter['create'] !== 'function') {\n throw errorConfigValidation('adapter.create', {\n why: 'Config.adapter must have create: function',\n });\n }\n\n // Validate extensions array if present\n if (configObj['extensions'] !== undefined) {\n if (!Array.isArray(configObj['extensions'])) {\n throw errorConfigValidation('extensions', {\n why: 'Config.extensions must be an array',\n });\n }\n for (const ext of configObj['extensions']) {\n if (!ext || typeof ext !== 'object') {\n throw errorConfigValidation('extensions[]', {\n why: 'Config.extensions must contain ExtensionDescriptor objects',\n });\n }\n const extObj = ext as Record<string, unknown>;\n if (extObj['kind'] !== 'extension') {\n throw errorConfigValidation('extensions[].kind', {\n why: 'Config.extensions items must have kind: \"extension\"',\n });\n }\n if (typeof extObj['id'] !== 'string') {\n throw errorConfigValidation('extensions[].id', {\n why: 'Config.extensions items must have id: string',\n });\n }\n if (typeof extObj['familyId'] !== 'string') {\n throw errorConfigValidation('extensions[].familyId', {\n why: 'Config.extensions items must have familyId: string',\n });\n }\n if (typeof extObj['version'] !== 'string') {\n throw errorConfigValidation('extensions[].version', {\n why: 'Config.extensions items must have version: string',\n });\n }\n if (extObj['familyId'] !== familyId) {\n throw errorConfigValidation('extensions[].familyId', {\n why: `Config.extensions[].familyId must match Config.family.familyId (expected: ${familyId}, got: ${extObj['familyId']})`,\n });\n }\n if (typeof extObj['targetId'] !== 'string') {\n throw errorConfigValidation('extensions[].targetId', {\n why: 'Config.extensions items must have targetId: string',\n });\n }\n if (extObj['targetId'] !== expectedTargetId) {\n throw errorConfigValidation('extensions[].targetId', {\n why: `Config.extensions[].targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${extObj['targetId']})`,\n });\n }\n if (typeof extObj['create'] !== 'function') {\n throw errorConfigValidation('extensions[].create', {\n why: 'Config.extensions items must have create: function',\n });\n }\n }\n }\n\n // Validate driver descriptor if present\n if (configObj['driver'] !== undefined) {\n const driver = configObj['driver'] as Record<string, unknown>;\n if (driver['kind'] !== 'driver') {\n throw errorConfigValidation('driver.kind', {\n why: 'Config.driver must have kind: \"driver\"',\n });\n }\n if (typeof driver['id'] !== 'string') {\n throw errorConfigValidation('driver.id', {\n why: 'Config.driver must have id: string',\n });\n }\n if (typeof driver['version'] !== 'string') {\n throw errorConfigValidation('driver.version', {\n why: 'Config.driver must have version: string',\n });\n }\n if (typeof driver['familyId'] !== 'string') {\n throw errorConfigValidation('driver.familyId', {\n why: 'Config.driver must have familyId: string',\n });\n }\n if (driver['familyId'] !== familyId) {\n throw errorConfigValidation('driver.familyId', {\n why: `Config.driver.familyId must match Config.family.familyId (expected: ${familyId}, got: ${driver['familyId']})`,\n });\n }\n if (typeof driver['targetId'] !== 'string') {\n throw errorConfigValidation('driver.targetId', {\n why: 'Config.driver must have targetId: string',\n });\n }\n if (driver['targetId'] !== expectedTargetId) {\n throw errorConfigValidation('driver.targetId', {\n why: `Config.driver.targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${driver['targetId']})`,\n });\n }\n if (typeof driver['create'] !== 'function') {\n throw errorConfigValidation('driver.create', {\n why: 'Config.driver must have create: function',\n });\n }\n }\n\n // Validate contract config if present (structure validation - defineConfig() handles normalization)\n if (configObj['contract'] !== undefined) {\n const contract = configObj['contract'] as Record<string, unknown>;\n if (!contract || typeof contract !== 'object') {\n throw errorConfigValidation('contract', {\n why: 'Config.contract must be an object',\n });\n }\n if (!('source' in contract)) {\n throw errorConfigValidation('contract.source', {\n why: 'Config.contract.source is required when contract is provided',\n });\n }\n\n if (typeof contract['source'] !== 'function') {\n throw errorConfigValidation('contract.source', {\n why: 'Config.contract.source must be a provider function',\n });\n }\n\n if (contract['output'] !== undefined && typeof contract['output'] !== 'string') {\n throw errorConfigValidation('contract.output', {\n why: 'Config.contract.output must be a string when provided',\n });\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,eAAe,QAAqD;AAClF,KAAI,CAAC,UAAU,OAAO,WAAW,SAC/B,OAAM,sBAAsB,UAAU,EACpC,KAAK,4BACN,CAAC;CAGJ,MAAM,YAAY;AAElB,KAAI,CAAC,UAAU,UACb,OAAM,sBAAsB,SAAS;AAGvC,KAAI,CAAC,UAAU,UACb,OAAM,sBAAsB,SAAS;AAGvC,KAAI,CAAC,UAAU,WACb,OAAM,sBAAsB,UAAU;CAIxC,MAAM,SAAS,UAAU;AACzB,KAAI,OAAO,YAAY,SACrB,OAAM,sBAAsB,eAAe,EACzC,KAAK,4CACN,CAAC;AAEJ,KAAI,OAAO,OAAO,gBAAgB,SAChC,OAAM,sBAAsB,mBAAmB,EAC7C,KAAK,4CACN,CAAC;AAEJ,KAAI,OAAO,OAAO,eAAe,SAC/B,OAAM,sBAAsB,kBAAkB,EAC5C,KAAK,2CACN,CAAC;AAEJ,KAAI,CAAC,OAAO,WAAW,OAAO,OAAO,YAAY,SAC/C,OAAM,sBAAsB,eAAe,EACzC,KAAK,kDACN,CAAC;AAEJ,KAAI,OAAO,OAAO,cAAc,WAC9B,OAAM,sBAAsB,iBAAiB,EAC3C,KAAK,4CACN,CAAC;CAGJ,MAAM,WAAW,OAAO;CAGxB,MAAM,SAAS,UAAU;AACzB,KAAI,OAAO,YAAY,SACrB,O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/ir";
|
|
|
3
3
|
import { OperationRegistry } from "@prisma-next/operations";
|
|
4
4
|
|
|
5
5
|
//#region src/emission/canonicalization.d.ts
|
|
6
|
-
|
|
6
|
+
type CanonicalContractInput = {
|
|
7
|
+
schemaVersion: string;
|
|
8
|
+
targetFamily: string;
|
|
9
|
+
target: string;
|
|
10
|
+
models: Record<string, unknown>;
|
|
11
|
+
relations: Record<string, unknown>;
|
|
12
|
+
storage: Record<string, unknown>;
|
|
13
|
+
execution?: Record<string, unknown>;
|
|
14
|
+
extensionPacks: Record<string, unknown>;
|
|
15
|
+
capabilities: Record<string, Record<string, boolean>>;
|
|
16
|
+
meta: Record<string, unknown>;
|
|
7
17
|
storageHash?: string;
|
|
8
18
|
executionHash?: string;
|
|
9
19
|
profileHash?: string;
|
|
10
|
-
}
|
|
20
|
+
};
|
|
21
|
+
declare function canonicalizeContract(ir: CanonicalContractInput): string;
|
|
11
22
|
//#endregion
|
|
12
23
|
//#region src/emission/types.d.ts
|
|
13
24
|
interface EmitOptions {
|
|
@@ -39,23 +50,9 @@ interface EmitResult {
|
|
|
39
50
|
declare function emit(ir: ContractIR, options: EmitOptions, targetFamily: TargetFamilyHook): Promise<EmitResult>;
|
|
40
51
|
//#endregion
|
|
41
52
|
//#region src/emission/hashing.d.ts
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
target: string;
|
|
46
|
-
models: Record<string, unknown>;
|
|
47
|
-
relations: Record<string, unknown>;
|
|
48
|
-
storage: Record<string, unknown>;
|
|
49
|
-
execution?: Record<string, unknown>;
|
|
50
|
-
extensionPacks: Record<string, unknown>;
|
|
51
|
-
sources: Record<string, unknown>;
|
|
52
|
-
capabilities: Record<string, Record<string, boolean>>;
|
|
53
|
-
meta: Record<string, unknown>;
|
|
54
|
-
[key: string]: unknown;
|
|
55
|
-
};
|
|
56
|
-
declare function computeStorageHash(contract: ContractInput): string;
|
|
57
|
-
declare function computeProfileHash(contract: ContractInput): string;
|
|
58
|
-
declare function computeExecutionHash(contract: ContractInput): string;
|
|
53
|
+
declare function computeStorageHash(contract: CanonicalContractInput): string;
|
|
54
|
+
declare function computeProfileHash(contract: CanonicalContractInput): string;
|
|
55
|
+
declare function computeExecutionHash(contract: CanonicalContractInput): string;
|
|
59
56
|
//#endregion
|
|
60
57
|
export { type EmitOptions, type EmitResult, canonicalizeContract, computeExecutionHash, computeProfileHash, computeStorageHash, emit };
|
|
61
58
|
//# sourceMappingURL=emission.d.mts.map
|
package/dist/emission.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emission.d.mts","names":[],"sources":["../src/emission/canonicalization.ts","../src/emission/types.ts","../src/emission/emit.ts","../src/emission/hashing.ts"],"sourcesContent":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"emission.d.mts","names":[],"sources":["../src/emission/canonicalization.ts","../src/emission/types.ts","../src/emission/emit.ts","../src/emission/hashing.ts"],"sourcesContent":[],"mappings":";;;;;KAoBY,sBAAA;;;;UAIF;EAJE,SAAA,EAKC,MALD,CAAA,MAAA,EAAsB,OAAA,CAAA;EAIxB,OAAA,EAEC,MAFD,CAAA,MAAA,EAAA,OAAA,CAAA;EACG,SAAA,CAAA,EAEC,MAFD,CAAA,MAAA,EAAA,OAAA,CAAA;EACF,cAAA,EAEO,MAFP,CAAA,MAAA,EAAA,OAAA,CAAA;EACG,YAAA,EAEE,MAFF,CAAA,MAAA,EAEiB,MAFjB,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;EACI,IAAA,EAEV,MAFU,CAAA,MAAA,EAAA,OAAA,CAAA;EACa,WAAA,CAAA,EAAA,MAAA;EAAf,aAAA,CAAA,EAAA,MAAA;EACR,WAAA,CAAA,EAAA,MAAA;CAAM;AAkPE,iBAAA,oBAAA,CAAyB,EAAA,EAAA,sBAAsB,CAAA,EAAA,MAAA;;;UC7Q9C,WAAA;;+BAEc;EDenB,SAAA,gBAAsB,CAAA,ECdJ,aDcI,CCdU,eDcV,CAAA;EAIxB,SAAA,oBAAA,CAAA,ECjBwB,aDiBxB,CCjBsC,eDiBtC,CAAA;EACG,SAAA,YAAA,CAAA,ECjBa,aDiBb,CAAA,MAAA,CAAA;EACF;;;;EAGK,SAAA,sBAAA,CAAA,EChBoB,GDgBpB,CAAA,MAAA,EChBgC,eDgBhC,CAAA;EACR;;AAkPR;;sCC9PsC,cAAc;;AAfnC,UAkBA,UAAA,CAlBW;EAEG,SAAA,YAAA,EAAA,MAAA;EACa,SAAA,WAAA,EAAA,MAAA;EAAd,SAAA,WAAA,EAAA,MAAA;EACkB,SAAA,aAAA,CAAA,EAAA,MAAA;EAAd,SAAA,WAAA,EAAA,MAAA;;;;iBCmEZ,IAAA,KAChB,qBACK,2BACK,mBACb,QAAQ;;;iBCnEK,kBAAA,WAA6B;iBAgB7B,kBAAA,WAA6B;iBAgB7B,oBAAA,WAA+B"}
|
package/dist/emission.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type } from "arktype";
|
|
1
2
|
import { bigintJsonReplacer } from "@prisma-next/contract/types";
|
|
2
3
|
import { isArrayEqual } from "@prisma-next/utils/array-equal";
|
|
3
4
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
@@ -14,12 +15,12 @@ const TOP_LEVEL_ORDER = [
|
|
|
14
15
|
"executionHash",
|
|
15
16
|
"profileHash",
|
|
16
17
|
"models",
|
|
18
|
+
"relations",
|
|
17
19
|
"storage",
|
|
18
20
|
"execution",
|
|
19
21
|
"capabilities",
|
|
20
22
|
"extensionPacks",
|
|
21
|
-
"meta"
|
|
22
|
-
"sources"
|
|
23
|
+
"meta"
|
|
23
24
|
];
|
|
24
25
|
function isDefaultValue(value) {
|
|
25
26
|
if (value === false) return true;
|
|
@@ -47,7 +48,6 @@ function omitDefaults(obj, path) {
|
|
|
47
48
|
const isRequiredExtensionPacks = isArrayEqual(currentPath, ["extensionPacks"]);
|
|
48
49
|
const isRequiredCapabilities = isArrayEqual(currentPath, ["capabilities"]);
|
|
49
50
|
const isRequiredMeta = isArrayEqual(currentPath, ["meta"]);
|
|
50
|
-
const isRequiredSources = isArrayEqual(currentPath, ["sources"]);
|
|
51
51
|
const isRequiredExecutionDefaults = isArrayEqual(currentPath, [
|
|
52
52
|
"execution",
|
|
53
53
|
"mutations",
|
|
@@ -83,7 +83,7 @@ function omitDefaults(obj, path) {
|
|
|
83
83
|
"foreignKeys"
|
|
84
84
|
]);
|
|
85
85
|
const isFkBooleanField = currentPath.length === 5 && currentPath[0] === "storage" && currentPath[1] === "tables" && currentPath[3] === "foreignKeys" && (key === "constraint" || key === "index");
|
|
86
|
-
if (!isRequiredModels && !isRequiredTables && !isRequiredRelations && !isRequiredExtensionPacks && !isRequiredCapabilities && !isRequiredMeta && !
|
|
86
|
+
if (!isRequiredModels && !isRequiredTables && !isRequiredRelations && !isRequiredExtensionPacks && !isRequiredCapabilities && !isRequiredMeta && !isRequiredExecutionDefaults && !isExtensionNamespace && !isModelRelations && !isTableUniques && !isTableIndexes && !isTableForeignKeys && !isFkBooleanField) continue;
|
|
87
87
|
}
|
|
88
88
|
result[key] = omitDefaults(value, currentPath);
|
|
89
89
|
}
|
|
@@ -149,8 +149,7 @@ function canonicalizeContract(ir) {
|
|
|
149
149
|
...ifDefined("execution", ir.execution),
|
|
150
150
|
extensionPacks: ir.extensionPacks,
|
|
151
151
|
capabilities: ir.capabilities,
|
|
152
|
-
meta: ir.meta
|
|
153
|
-
sources: ir.sources
|
|
152
|
+
meta: ir.meta
|
|
154
153
|
};
|
|
155
154
|
Object.assign(normalized, ifDefined("storageHash", ir.storageHash), ifDefined("executionHash", ir.executionHash), ifDefined("profileHash", ir.profileHash));
|
|
156
155
|
const withDefaultsOmitted = omitDefaults(normalized, []);
|
|
@@ -178,7 +177,6 @@ function computeStorageHash(contract) {
|
|
|
178
177
|
models: {},
|
|
179
178
|
relations: {},
|
|
180
179
|
extensionPacks: {},
|
|
181
|
-
sources: {},
|
|
182
180
|
capabilities: {},
|
|
183
181
|
meta: {}
|
|
184
182
|
}));
|
|
@@ -193,8 +191,7 @@ function computeProfileHash(contract) {
|
|
|
193
191
|
storage: {},
|
|
194
192
|
extensionPacks: {},
|
|
195
193
|
capabilities: contract.capabilities,
|
|
196
|
-
meta: {}
|
|
197
|
-
sources: {}
|
|
194
|
+
meta: {}
|
|
198
195
|
}));
|
|
199
196
|
}
|
|
200
197
|
function computeExecutionHash(contract) {
|
|
@@ -206,7 +203,6 @@ function computeExecutionHash(contract) {
|
|
|
206
203
|
relations: {},
|
|
207
204
|
storage: {},
|
|
208
205
|
extensionPacks: {},
|
|
209
|
-
sources: {},
|
|
210
206
|
capabilities: {},
|
|
211
207
|
meta: {},
|
|
212
208
|
...ifDefined("execution", contract.execution)
|
|
@@ -215,6 +211,29 @@ function computeExecutionHash(contract) {
|
|
|
215
211
|
|
|
216
212
|
//#endregion
|
|
217
213
|
//#region src/emission/emit.ts
|
|
214
|
+
const CanonicalMetaSchema = type({ "[string]": "unknown" });
|
|
215
|
+
const CanonicalContractSchema = type({
|
|
216
|
+
"+": "reject",
|
|
217
|
+
schemaVersion: "string",
|
|
218
|
+
targetFamily: "string",
|
|
219
|
+
target: "string",
|
|
220
|
+
models: type({ "[string]": "unknown" }),
|
|
221
|
+
relations: type({ "[string]": "unknown" }),
|
|
222
|
+
storage: type({ "[string]": "unknown" }),
|
|
223
|
+
"execution?": type({ "[string]": "unknown" }),
|
|
224
|
+
extensionPacks: type({ "[string]": "unknown" }),
|
|
225
|
+
capabilities: type({ "[string]": type({ "[string]": "boolean" }) }),
|
|
226
|
+
meta: CanonicalMetaSchema
|
|
227
|
+
});
|
|
228
|
+
function assertCanonicalArtifactShape(value) {
|
|
229
|
+
const result = CanonicalContractSchema(value);
|
|
230
|
+
if (result instanceof type.errors) {
|
|
231
|
+
const issues = result.map((error) => {
|
|
232
|
+
return `${error.path?.toString() ?? "<root>"}: ${error.message}`;
|
|
233
|
+
}).join("; ");
|
|
234
|
+
throw new Error(`ContractIR canonical artifact validation failed: ${issues}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
218
237
|
function validateCoreStructure(ir) {
|
|
219
238
|
if (!ir.targetFamily) throw new Error("ContractIR must have targetFamily");
|
|
220
239
|
if (!ir.target) throw new Error("ContractIR must have target");
|
|
@@ -225,7 +244,6 @@ function validateCoreStructure(ir) {
|
|
|
225
244
|
if (!ir.extensionPacks || typeof ir.extensionPacks !== "object") throw new Error("ContractIR must have extensionPacks");
|
|
226
245
|
if (!ir.capabilities || typeof ir.capabilities !== "object") throw new Error("ContractIR must have capabilities");
|
|
227
246
|
if (!ir.meta || typeof ir.meta !== "object") throw new Error("ContractIR must have meta");
|
|
228
|
-
if (!ir.sources || typeof ir.sources !== "object") throw new Error("ContractIR must have sources");
|
|
229
247
|
}
|
|
230
248
|
async function emit(ir, options, targetFamily) {
|
|
231
249
|
const { operationRegistry, codecTypeImports, operationTypeImports, extensionIds, parameterizedRenderers, parameterizedTypeImports } = options;
|
|
@@ -238,7 +256,7 @@ async function emit(ir, options, targetFamily) {
|
|
|
238
256
|
};
|
|
239
257
|
targetFamily.validateTypes(ir, ctx);
|
|
240
258
|
targetFamily.validateStructure(ir);
|
|
241
|
-
const
|
|
259
|
+
const canonicalContract = {
|
|
242
260
|
schemaVersion: ir.schemaVersion,
|
|
243
261
|
targetFamily: ir.targetFamily,
|
|
244
262
|
target: ir.target,
|
|
@@ -248,15 +266,14 @@ async function emit(ir, options, targetFamily) {
|
|
|
248
266
|
...ifDefined("execution", ir.execution),
|
|
249
267
|
extensionPacks: ir.extensionPacks,
|
|
250
268
|
capabilities: ir.capabilities,
|
|
251
|
-
meta: ir.meta
|
|
252
|
-
sources: ir.sources
|
|
269
|
+
meta: ir.meta
|
|
253
270
|
};
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
const
|
|
271
|
+
assertCanonicalArtifactShape(canonicalContract);
|
|
272
|
+
const storageHash = computeStorageHash(canonicalContract);
|
|
273
|
+
const executionHash = canonicalContract.execution ? computeExecutionHash(canonicalContract) : void 0;
|
|
274
|
+
const profileHash = computeProfileHash(canonicalContract);
|
|
257
275
|
const contractWithHashes = {
|
|
258
|
-
...
|
|
259
|
-
schemaVersion: contractJson.schemaVersion,
|
|
276
|
+
...canonicalContract,
|
|
260
277
|
storageHash,
|
|
261
278
|
...ifDefined("executionHash", executionHash),
|
|
262
279
|
profileHash
|
package/dist/emission.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emission.mjs","names":["result: Record<string, unknown>","sorted: Record<string, unknown>","result: StorageObject","sortedTable: TableObject","ordered: Record<string, unknown>","normalized: NormalizedContract","ctx: ValidationContext","contractWithHashes: ContractIR & {\n storageHash?: string;\n executionHash?: string;\n profileHash?: string;\n }"],"sources":["../src/emission/canonicalization.ts","../src/emission/hashing.ts","../src/emission/emit.ts"],"sourcesContent":["import type { ContractIR } from '@prisma-next/contract/ir';\nimport { bigintJsonReplacer } from '@prisma-next/contract/types';\nimport { isArrayEqual } from '@prisma-next/utils/array-equal';\nimport { ifDefined } from '@prisma-next/utils/defined';\n\ntype NormalizedContract = {\n schemaVersion: string;\n targetFamily: string;\n target: string;\n storageHash?: string;\n executionHash?: string;\n profileHash?: string;\n models: Record<string, unknown>;\n relations: Record<string, unknown>;\n storage: Record<string, unknown>;\n execution?: Record<string, unknown>;\n extensionPacks: Record<string, unknown>;\n capabilities: Record<string, Record<string, boolean>>;\n meta: Record<string, unknown>;\n sources: Record<string, unknown>;\n};\n\nconst TOP_LEVEL_ORDER = [\n 'schemaVersion',\n 'canonicalVersion',\n 'targetFamily',\n 'target',\n 'storageHash',\n 'executionHash',\n 'profileHash',\n 'models',\n 'storage',\n 'execution',\n 'capabilities',\n 'extensionPacks',\n 'meta',\n 'sources',\n] as const;\n\nfunction isDefaultValue(value: unknown): boolean {\n if (value === false) return true;\n if (value === null) return false;\n if (value instanceof Date) return false;\n if (Array.isArray(value) && value.length === 0) return true;\n if (typeof value === 'object' && value !== null) {\n const keys = Object.keys(value);\n return keys.length === 0;\n }\n return false;\n}\n\nfunction omitDefaults(obj: unknown, path: readonly string[]): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (obj instanceof Date) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => omitDefaults(item, path));\n }\n\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n const currentPath = [...path, key];\n\n // Exclude metadata fields from canonicalization\n if (key === '_generated') {\n continue;\n }\n\n if (key === 'nullable' && value === false) {\n continue;\n }\n\n if (key === 'generated' && value === false) {\n continue;\n }\n\n // Strip 'noAction' referential actions (the database default) for hash stability.\n // A contract with explicit `onDelete: 'noAction'` is semantically identical to\n // one that omits `onDelete` entirely, so they should produce the same hash.\n if ((key === 'onDelete' || key === 'onUpdate') && value === 'noAction') {\n continue;\n }\n\n if (isDefaultValue(value)) {\n const isRequiredModels = isArrayEqual(currentPath, ['models']);\n const isRequiredTables = isArrayEqual(currentPath, ['storage', 'tables']);\n const isRequiredRelations = isArrayEqual(currentPath, ['relations']);\n const isRequiredExtensionPacks = isArrayEqual(currentPath, ['extensionPacks']);\n const isRequiredCapabilities = isArrayEqual(currentPath, ['capabilities']);\n const isRequiredMeta = isArrayEqual(currentPath, ['meta']);\n const isRequiredSources = isArrayEqual(currentPath, ['sources']);\n const isRequiredExecutionDefaults = isArrayEqual(currentPath, [\n 'execution',\n 'mutations',\n 'defaults',\n ]);\n const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === 'extensionPacks';\n const isModelRelations =\n currentPath.length === 3 &&\n isArrayEqual([currentPath[0], currentPath[2]], ['models', 'relations']);\n const isTableUniques =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'uniques'],\n );\n const isTableIndexes =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'indexes'],\n );\n const isTableForeignKeys =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'foreignKeys'],\n );\n\n // Preserve per-FK `constraint` and `index` booleans (even when `false`)\n // so that hash distinguishes `false` from absent.\n // Path: ['storage', 'tables', <tableName>, 'foreignKeys', 'constraint' | 'index']\n const isFkBooleanField =\n currentPath.length === 5 &&\n currentPath[0] === 'storage' &&\n currentPath[1] === 'tables' &&\n currentPath[3] === 'foreignKeys' &&\n (key === 'constraint' || key === 'index');\n\n if (\n !isRequiredModels &&\n !isRequiredTables &&\n !isRequiredRelations &&\n !isRequiredExtensionPacks &&\n !isRequiredCapabilities &&\n !isRequiredMeta &&\n !isRequiredSources &&\n !isRequiredExecutionDefaults &&\n !isExtensionNamespace &&\n !isModelRelations &&\n !isTableUniques &&\n !isTableIndexes &&\n !isTableForeignKeys &&\n !isFkBooleanField\n ) {\n continue;\n }\n }\n\n result[key] = omitDefaults(value, currentPath);\n }\n\n return result;\n}\n\nfunction sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (obj instanceof Date) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => sortObjectKeys(item));\n }\n\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(obj).sort();\n for (const key of keys) {\n sorted[key] = sortObjectKeys((obj as Record<string, unknown>)[key]);\n }\n\n return sorted;\n}\n\ntype StorageObject = {\n tables?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\ntype TableObject = {\n indexes?: unknown[];\n uniques?: unknown[];\n [key: string]: unknown;\n};\n\nfunction sortIndexesAndUniques(storage: unknown): unknown {\n if (!storage || typeof storage !== 'object') {\n return storage;\n }\n\n const storageObj = storage as StorageObject;\n if (!storageObj.tables || typeof storageObj.tables !== 'object') {\n return storage;\n }\n\n const tables = storageObj.tables;\n const result: StorageObject = { ...storageObj };\n\n result.tables = {};\n // Sort table names to ensure deterministic ordering\n const sortedTableNames = Object.keys(tables).sort();\n for (const tableName of sortedTableNames) {\n const table = tables[tableName];\n if (!table || typeof table !== 'object') {\n result.tables[tableName] = table;\n continue;\n }\n\n const tableObj = table as TableObject;\n const sortedTable: TableObject = { ...tableObj };\n\n if (Array.isArray(tableObj.indexes)) {\n sortedTable.indexes = [...tableObj.indexes].sort((a, b) => {\n const nameA = (a as { name?: string })?.name || '';\n const nameB = (b as { name?: string })?.name || '';\n return nameA.localeCompare(nameB);\n });\n }\n\n if (Array.isArray(tableObj.uniques)) {\n sortedTable.uniques = [...tableObj.uniques].sort((a, b) => {\n const nameA = (a as { name?: string })?.name || '';\n const nameB = (b as { name?: string })?.name || '';\n return nameA.localeCompare(nameB);\n });\n }\n\n result.tables[tableName] = sortedTable;\n }\n\n return result;\n}\n\nfunction orderTopLevel(obj: Record<string, unknown>): Record<string, unknown> {\n const ordered: Record<string, unknown> = {};\n const remaining = new Set(Object.keys(obj));\n\n for (const key of TOP_LEVEL_ORDER) {\n if (remaining.has(key)) {\n ordered[key] = obj[key];\n remaining.delete(key);\n }\n }\n\n for (const key of Array.from(remaining).sort()) {\n ordered[key] = obj[key];\n }\n\n return ordered;\n}\n\nexport function canonicalizeContract(\n ir: ContractIR & { storageHash?: string; executionHash?: string; profileHash?: string },\n): string {\n const normalized: NormalizedContract = {\n schemaVersion: ir.schemaVersion,\n targetFamily: ir.targetFamily,\n target: ir.target,\n models: ir.models,\n relations: ir.relations,\n storage: ir.storage,\n ...ifDefined('execution', ir.execution),\n extensionPacks: ir.extensionPacks,\n capabilities: ir.capabilities,\n meta: ir.meta,\n sources: ir.sources,\n };\n Object.assign(\n normalized,\n ifDefined('storageHash', ir.storageHash),\n ifDefined('executionHash', ir.executionHash),\n ifDefined('profileHash', ir.profileHash),\n );\n\n const withDefaultsOmitted = omitDefaults(normalized, []) as NormalizedContract;\n const withSortedIndexes = sortIndexesAndUniques(withDefaultsOmitted.storage);\n const withSortedStorage = { ...withDefaultsOmitted, storage: withSortedIndexes };\n const withSortedKeys = sortObjectKeys(withSortedStorage) as Record<string, unknown>;\n const withOrderedTopLevel = orderTopLevel(withSortedKeys);\n\n return JSON.stringify(withOrderedTopLevel, bigintJsonReplacer, 2);\n}\n","import { createHash } from 'node:crypto';\nimport type { ContractIR } from '@prisma-next/contract/ir';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { canonicalizeContract } from './canonicalization';\n\ntype ContractInput = {\n schemaVersion: string;\n targetFamily: string;\n target: string;\n models: Record<string, unknown>;\n relations: Record<string, unknown>;\n storage: Record<string, unknown>;\n execution?: Record<string, unknown>;\n extensionPacks: Record<string, unknown>;\n sources: Record<string, unknown>;\n capabilities: Record<string, Record<string, boolean>>;\n meta: Record<string, unknown>;\n [key: string]: unknown;\n};\n\nfunction computeHash(content: string): string {\n const hash = createHash('sha256');\n hash.update(content);\n return `sha256:${hash.digest('hex')}`;\n}\n\nexport function computeStorageHash(contract: ContractInput): string {\n const storageContract: ContractIR = {\n schemaVersion: contract.schemaVersion,\n targetFamily: contract.targetFamily,\n target: contract.target,\n storage: contract.storage,\n models: {},\n relations: {},\n extensionPacks: {},\n sources: {},\n capabilities: {},\n meta: {},\n };\n const canonical = canonicalizeContract(storageContract);\n return computeHash(canonical);\n}\n\nexport function computeProfileHash(contract: ContractInput): string {\n const profileContract: ContractIR = {\n schemaVersion: contract.schemaVersion,\n targetFamily: contract.targetFamily,\n target: contract.target,\n models: {},\n relations: {},\n storage: {},\n extensionPacks: {},\n capabilities: contract.capabilities,\n meta: {},\n sources: {},\n };\n const canonical = canonicalizeContract(profileContract);\n return computeHash(canonical);\n}\n\nexport function computeExecutionHash(contract: ContractInput): string {\n const executionContract: ContractIR = {\n schemaVersion: contract.schemaVersion,\n targetFamily: contract.targetFamily,\n target: contract.target,\n models: {},\n relations: {},\n storage: {},\n extensionPacks: {},\n sources: {},\n capabilities: {},\n meta: {},\n ...ifDefined('execution', contract.execution),\n };\n const canonical = canonicalizeContract(executionContract);\n return computeHash(canonical);\n}\n","import type { ContractIR } from '@prisma-next/contract/ir';\nimport type { TargetFamilyHook, ValidationContext } from '@prisma-next/contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { format } from 'prettier';\nimport { canonicalizeContract } from './canonicalization';\nimport { computeExecutionHash, computeProfileHash, computeStorageHash } from './hashing';\nimport type { EmitOptions, EmitResult } from './types';\n\nfunction validateCoreStructure(ir: ContractIR): void {\n if (!ir.targetFamily) {\n throw new Error('ContractIR must have targetFamily');\n }\n if (!ir.target) {\n throw new Error('ContractIR must have target');\n }\n if (!ir.schemaVersion) {\n throw new Error('ContractIR must have schemaVersion');\n }\n if (!ir.models || typeof ir.models !== 'object') {\n throw new Error('ContractIR must have models');\n }\n if (!ir.storage || typeof ir.storage !== 'object') {\n throw new Error('ContractIR must have storage');\n }\n if (!ir.relations || typeof ir.relations !== 'object') {\n throw new Error('ContractIR must have relations');\n }\n if (!ir.extensionPacks || typeof ir.extensionPacks !== 'object') {\n throw new Error('ContractIR must have extensionPacks');\n }\n if (!ir.capabilities || typeof ir.capabilities !== 'object') {\n throw new Error('ContractIR must have capabilities');\n }\n if (!ir.meta || typeof ir.meta !== 'object') {\n throw new Error('ContractIR must have meta');\n }\n if (!ir.sources || typeof ir.sources !== 'object') {\n throw new Error('ContractIR must have sources');\n }\n}\n\nexport async function emit(\n ir: ContractIR,\n options: EmitOptions,\n targetFamily: TargetFamilyHook,\n): Promise<EmitResult> {\n const {\n operationRegistry,\n codecTypeImports,\n operationTypeImports,\n extensionIds,\n parameterizedRenderers,\n parameterizedTypeImports,\n } = options;\n\n validateCoreStructure(ir);\n\n const ctx: ValidationContext = {\n ...ifDefined('operationRegistry', operationRegistry),\n ...ifDefined('codecTypeImports', codecTypeImports),\n ...ifDefined('operationTypeImports', operationTypeImports),\n ...ifDefined('extensionIds', extensionIds),\n };\n targetFamily.validateTypes(ir, ctx);\n\n targetFamily.validateStructure(ir);\n\n const contractJson = {\n schemaVersion: ir.schemaVersion,\n targetFamily: ir.targetFamily,\n target: ir.target,\n models: ir.models,\n relations: ir.relations,\n storage: ir.storage,\n ...ifDefined('execution', ir.execution),\n extensionPacks: ir.extensionPacks,\n capabilities: ir.capabilities,\n meta: ir.meta,\n sources: ir.sources,\n } as const;\n\n const storageHash = computeStorageHash(contractJson);\n const executionHash = ir.execution ? computeExecutionHash(contractJson) : undefined;\n const profileHash = computeProfileHash(contractJson);\n\n const contractWithHashes: ContractIR & {\n storageHash?: string;\n executionHash?: string;\n profileHash?: string;\n } = {\n ...ir,\n schemaVersion: contractJson.schemaVersion,\n storageHash,\n ...ifDefined('executionHash', executionHash),\n profileHash,\n };\n\n // Add _generated metadata to indicate this is a generated artifact\n // This ensures consistency between CLI emit and programmatic emit\n // Always add/update _generated with standard content for consistency\n const contractJsonObj = JSON.parse(canonicalizeContract(contractWithHashes)) as Record<\n string,\n unknown\n >;\n const contractJsonWithMeta = {\n ...contractJsonObj,\n _generated: {\n warning: '⚠️ GENERATED FILE - DO NOT EDIT',\n message: 'This file is automatically generated by \"prisma-next contract emit\".',\n regenerate: 'To regenerate, run: prisma-next contract emit',\n },\n };\n const contractJsonString = JSON.stringify(contractJsonWithMeta, null, 2);\n\n const generateOptions =\n parameterizedRenderers || parameterizedTypeImports\n ? {\n ...ifDefined('parameterizedRenderers', parameterizedRenderers),\n ...ifDefined('parameterizedTypeImports', parameterizedTypeImports),\n }\n : undefined;\n\n const contractTypeHashes = {\n storageHash,\n ...ifDefined('executionHash', executionHash),\n profileHash,\n };\n const contractDtsRaw = targetFamily.generateContractTypes(\n ir,\n codecTypeImports ?? [],\n operationTypeImports ?? [],\n contractTypeHashes,\n generateOptions,\n );\n const contractDts = await format(contractDtsRaw, {\n parser: 'typescript',\n singleQuote: true,\n semi: true,\n printWidth: 100,\n });\n\n return {\n contractJson: contractJsonString,\n contractDts,\n storageHash,\n ...ifDefined('executionHash', executionHash),\n profileHash,\n };\n}\n"],"mappings":";;;;;;;AAsBA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;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cAAc;EAC5C;EACD"}
|
|
1
|
+
{"version":3,"file":"emission.mjs","names":["result: Record<string, unknown>","sorted: Record<string, unknown>","result: StorageObject","sortedTable: TableObject","ordered: Record<string, unknown>","normalized: NormalizedContract","ctx: ValidationContext"],"sources":["../src/emission/canonicalization.ts","../src/emission/hashing.ts","../src/emission/emit.ts"],"sourcesContent":["import { bigintJsonReplacer } from '@prisma-next/contract/types';\nimport { isArrayEqual } from '@prisma-next/utils/array-equal';\nimport { ifDefined } from '@prisma-next/utils/defined';\n\ntype NormalizedContract = {\n schemaVersion: string;\n targetFamily: string;\n target: string;\n storageHash?: string;\n executionHash?: string;\n profileHash?: string;\n models: Record<string, unknown>;\n relations: Record<string, unknown>;\n storage: Record<string, unknown>;\n execution?: Record<string, unknown>;\n extensionPacks: Record<string, unknown>;\n capabilities: Record<string, Record<string, boolean>>;\n meta: Record<string, unknown>;\n};\n\nexport type CanonicalContractInput = {\n schemaVersion: string;\n targetFamily: string;\n target: string;\n models: Record<string, unknown>;\n relations: Record<string, unknown>;\n storage: Record<string, unknown>;\n execution?: Record<string, unknown>;\n extensionPacks: Record<string, unknown>;\n capabilities: Record<string, Record<string, boolean>>;\n meta: Record<string, unknown>;\n storageHash?: string;\n executionHash?: string;\n profileHash?: string;\n};\n\nconst TOP_LEVEL_ORDER = [\n 'schemaVersion',\n 'canonicalVersion',\n 'targetFamily',\n 'target',\n 'storageHash',\n 'executionHash',\n 'profileHash',\n 'models',\n 'relations',\n 'storage',\n 'execution',\n 'capabilities',\n 'extensionPacks',\n 'meta',\n] as const;\n\nfunction isDefaultValue(value: unknown): boolean {\n if (value === false) return true;\n if (value === null) return false;\n if (value instanceof Date) return false;\n if (Array.isArray(value) && value.length === 0) return true;\n if (typeof value === 'object' && value !== null) {\n const keys = Object.keys(value);\n return keys.length === 0;\n }\n return false;\n}\n\nfunction omitDefaults(obj: unknown, path: readonly string[]): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (obj instanceof Date) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => omitDefaults(item, path));\n }\n\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n const currentPath = [...path, key];\n\n // Exclude metadata fields from canonicalization\n if (key === '_generated') {\n continue;\n }\n\n if (key === 'nullable' && value === false) {\n continue;\n }\n\n if (key === 'generated' && value === false) {\n continue;\n }\n\n // Strip 'noAction' referential actions (the database default) for hash stability.\n // A contract with explicit `onDelete: 'noAction'` is semantically identical to\n // one that omits `onDelete` entirely, so they should produce the same hash.\n if ((key === 'onDelete' || key === 'onUpdate') && value === 'noAction') {\n continue;\n }\n\n if (isDefaultValue(value)) {\n const isRequiredModels = isArrayEqual(currentPath, ['models']);\n const isRequiredTables = isArrayEqual(currentPath, ['storage', 'tables']);\n const isRequiredRelations = isArrayEqual(currentPath, ['relations']);\n const isRequiredExtensionPacks = isArrayEqual(currentPath, ['extensionPacks']);\n const isRequiredCapabilities = isArrayEqual(currentPath, ['capabilities']);\n const isRequiredMeta = isArrayEqual(currentPath, ['meta']);\n const isRequiredExecutionDefaults = isArrayEqual(currentPath, [\n 'execution',\n 'mutations',\n 'defaults',\n ]);\n const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === 'extensionPacks';\n const isModelRelations =\n currentPath.length === 3 &&\n isArrayEqual([currentPath[0], currentPath[2]], ['models', 'relations']);\n const isTableUniques =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'uniques'],\n );\n const isTableIndexes =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'indexes'],\n );\n const isTableForeignKeys =\n currentPath.length === 4 &&\n isArrayEqual(\n [currentPath[0], currentPath[1], currentPath[3]],\n ['storage', 'tables', 'foreignKeys'],\n );\n\n // Preserve per-FK `constraint` and `index` booleans (even when `false`)\n // so that hash distinguishes `false` from absent.\n // Path: ['storage', 'tables', <tableName>, 'foreignKeys', 'constraint' | 'index']\n const isFkBooleanField =\n currentPath.length === 5 &&\n currentPath[0] === 'storage' &&\n currentPath[1] === 'tables' &&\n currentPath[3] === 'foreignKeys' &&\n (key === 'constraint' || key === 'index');\n\n if (\n !isRequiredModels &&\n !isRequiredTables &&\n !isRequiredRelations &&\n !isRequiredExtensionPacks &&\n !isRequiredCapabilities &&\n !isRequiredMeta &&\n !isRequiredExecutionDefaults &&\n !isExtensionNamespace &&\n !isModelRelations &&\n !isTableUniques &&\n !isTableIndexes &&\n !isTableForeignKeys &&\n !isFkBooleanField\n ) {\n continue;\n }\n }\n\n result[key] = omitDefaults(value, currentPath);\n }\n\n return result;\n}\n\nfunction sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (obj instanceof Date) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => sortObjectKeys(item));\n }\n\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(obj).sort();\n for (const key of keys) {\n sorted[key] = sortObjectKeys((obj as Record<string, unknown>)[key]);\n }\n\n return sorted;\n}\n\ntype StorageObject = {\n tables?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\ntype TableObject = {\n indexes?: unknown[];\n uniques?: unknown[];\n [key: string]: unknown;\n};\n\nfunction sortIndexesAndUniques(storage: unknown): unknown {\n if (!storage || typeof storage !== 'object') {\n return storage;\n }\n\n const storageObj = storage as StorageObject;\n if (!storageObj.tables || typeof storageObj.tables !== 'object') {\n return storage;\n }\n\n const tables = storageObj.tables;\n const result: StorageObject = { ...storageObj };\n\n result.tables = {};\n // Sort table names to ensure deterministic ordering\n const sortedTableNames = Object.keys(tables).sort();\n for (const tableName of sortedTableNames) {\n const table = tables[tableName];\n if (!table || typeof table !== 'object') {\n result.tables[tableName] = table;\n continue;\n }\n\n const tableObj = table as TableObject;\n const sortedTable: TableObject = { ...tableObj };\n\n if (Array.isArray(tableObj.indexes)) {\n sortedTable.indexes = [...tableObj.indexes].sort((a, b) => {\n const nameA = (a as { name?: string })?.name || '';\n const nameB = (b as { name?: string })?.name || '';\n return nameA.localeCompare(nameB);\n });\n }\n\n if (Array.isArray(tableObj.uniques)) {\n sortedTable.uniques = [...tableObj.uniques].sort((a, b) => {\n const nameA = (a as { name?: string })?.name || '';\n const nameB = (b as { name?: string })?.name || '';\n return nameA.localeCompare(nameB);\n });\n }\n\n result.tables[tableName] = sortedTable;\n }\n\n return result;\n}\n\nfunction orderTopLevel(obj: Record<string, unknown>): Record<string, unknown> {\n const ordered: Record<string, unknown> = {};\n const remaining = new Set(Object.keys(obj));\n\n for (const key of TOP_LEVEL_ORDER) {\n if (remaining.has(key)) {\n ordered[key] = obj[key];\n remaining.delete(key);\n }\n }\n\n for (const key of Array.from(remaining).sort()) {\n ordered[key] = obj[key];\n }\n\n return ordered;\n}\n\nexport function canonicalizeContract(ir: CanonicalContractInput): string {\n const normalized: NormalizedContract = {\n schemaVersion: ir.schemaVersion,\n targetFamily: ir.targetFamily,\n target: ir.target,\n models: ir.models,\n relations: ir.relations,\n storage: ir.storage,\n ...ifDefined('execution', ir.execution),\n extensionPacks: ir.extensionPacks,\n capabilities: ir.capabilities,\n meta: ir.meta,\n };\n Object.assign(\n normalized,\n ifDefined('storageHash', ir.storageHash),\n ifDefined('executionHash', ir.executionHash),\n ifDefined('profileHash', ir.profileHash),\n );\n\n const withDefaultsOmitted = omitDefaults(normalized, []) as NormalizedContract;\n const withSortedIndexes = sortIndexesAndUniques(withDefaultsOmitted.storage);\n const withSortedStorage = { ...withDefaultsOmitted, storage: withSortedIndexes };\n const withSortedKeys = sortObjectKeys(withSortedStorage) as Record<string, unknown>;\n const withOrderedTopLevel = orderTopLevel(withSortedKeys);\n\n return JSON.stringify(withOrderedTopLevel, bigintJsonReplacer, 2);\n}\n","import { createHash } from 'node:crypto';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { CanonicalContractInput } from './canonicalization';\nimport { canonicalizeContract } from './canonicalization';\n\nfunction computeHash(content: string): string {\n const hash = createHash('sha256');\n hash.update(content);\n return `sha256:${hash.digest('hex')}`;\n}\n\nexport function computeStorageHash(contract: CanonicalContractInput): string {\n const storageContract = {\n schemaVersion: contract.schemaVersion,\n targetFamily: contract.targetFamily,\n target: contract.target,\n storage: contract.storage,\n models: {},\n relations: {},\n extensionPacks: {},\n capabilities: {},\n meta: {},\n };\n const canonical = canonicalizeContract(storageContract);\n return computeHash(canonical);\n}\n\nexport function computeProfileHash(contract: CanonicalContractInput): string {\n const profileContract = {\n schemaVersion: contract.schemaVersion,\n targetFamily: contract.targetFamily,\n target: contract.target,\n models: {},\n relations: {},\n storage: {},\n extensionPacks: {},\n capabilities: contract.capabilities,\n meta: {},\n };\n const canonical = canonicalizeContract(profileContract);\n return computeHash(canonical);\n}\n\nexport function computeExecutionHash(contract: CanonicalContractInput): string {\n const executionContract = {\n schemaVersion: contract.schemaVersion,\n targetFamily: contract.targetFamily,\n target: contract.target,\n models: {},\n relations: {},\n storage: {},\n extensionPacks: {},\n capabilities: {},\n meta: {},\n ...ifDefined('execution', contract.execution),\n };\n const canonical = canonicalizeContract(executionContract);\n return computeHash(canonical);\n}\n","import type { ContractIR } from '@prisma-next/contract/ir';\nimport type { TargetFamilyHook, ValidationContext } from '@prisma-next/contract/types';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { type } from 'arktype';\nimport { format } from 'prettier';\nimport { canonicalizeContract } from './canonicalization';\nimport { computeExecutionHash, computeProfileHash, computeStorageHash } from './hashing';\nimport type { EmitOptions, EmitResult } from './types';\n\nconst CanonicalMetaSchema = type({\n '[string]': 'unknown',\n});\n\nconst CanonicalContractSchema = type({\n '+': 'reject',\n schemaVersion: 'string',\n targetFamily: 'string',\n target: 'string',\n models: type({ '[string]': 'unknown' }),\n relations: type({ '[string]': 'unknown' }),\n storage: type({ '[string]': 'unknown' }),\n 'execution?': type({ '[string]': 'unknown' }),\n extensionPacks: type({ '[string]': 'unknown' }),\n capabilities: type({\n '[string]': type({\n '[string]': 'boolean',\n }),\n }),\n meta: CanonicalMetaSchema,\n});\n\nfunction assertCanonicalArtifactShape(value: unknown): void {\n const result = CanonicalContractSchema(value);\n if (result instanceof type.errors) {\n const issues = result\n .map((error) => {\n const path = error.path?.toString() ?? '<root>';\n return `${path}: ${error.message}`;\n })\n .join('; ');\n throw new Error(`ContractIR canonical artifact validation failed: ${issues}`);\n }\n}\n\nfunction validateCoreStructure(ir: ContractIR): void {\n if (!ir.targetFamily) {\n throw new Error('ContractIR must have targetFamily');\n }\n if (!ir.target) {\n throw new Error('ContractIR must have target');\n }\n if (!ir.schemaVersion) {\n throw new Error('ContractIR must have schemaVersion');\n }\n if (!ir.models || typeof ir.models !== 'object') {\n throw new Error('ContractIR must have models');\n }\n if (!ir.storage || typeof ir.storage !== 'object') {\n throw new Error('ContractIR must have storage');\n }\n if (!ir.relations || typeof ir.relations !== 'object') {\n throw new Error('ContractIR must have relations');\n }\n if (!ir.extensionPacks || typeof ir.extensionPacks !== 'object') {\n throw new Error('ContractIR must have extensionPacks');\n }\n if (!ir.capabilities || typeof ir.capabilities !== 'object') {\n throw new Error('ContractIR must have capabilities');\n }\n if (!ir.meta || typeof ir.meta !== 'object') {\n throw new Error('ContractIR must have meta');\n }\n}\n\nexport async function emit(\n ir: ContractIR,\n options: EmitOptions,\n targetFamily: TargetFamilyHook,\n): Promise<EmitResult> {\n const {\n operationRegistry,\n codecTypeImports,\n operationTypeImports,\n extensionIds,\n parameterizedRenderers,\n parameterizedTypeImports,\n } = options;\n\n validateCoreStructure(ir);\n\n const ctx: ValidationContext = {\n ...ifDefined('operationRegistry', operationRegistry),\n ...ifDefined('codecTypeImports', codecTypeImports),\n ...ifDefined('operationTypeImports', operationTypeImports),\n ...ifDefined('extensionIds', extensionIds),\n };\n targetFamily.validateTypes(ir, ctx);\n\n targetFamily.validateStructure(ir);\n\n const canonicalContract = {\n schemaVersion: ir.schemaVersion,\n targetFamily: ir.targetFamily,\n target: ir.target,\n models: ir.models,\n relations: ir.relations,\n storage: ir.storage,\n ...ifDefined('execution', ir.execution),\n extensionPacks: ir.extensionPacks,\n capabilities: ir.capabilities,\n meta: ir.meta,\n };\n assertCanonicalArtifactShape(canonicalContract);\n\n const storageHash = computeStorageHash(canonicalContract);\n const executionHash = canonicalContract.execution\n ? computeExecutionHash(canonicalContract)\n : undefined;\n const profileHash = computeProfileHash(canonicalContract);\n\n const contractWithHashes = {\n ...canonicalContract,\n storageHash,\n ...ifDefined('executionHash', executionHash),\n profileHash,\n };\n\n // Add _generated metadata to indicate this is a generated artifact\n // This ensures consistency between CLI emit and programmatic emit\n // Always add/update _generated with standard content for consistency\n const contractJsonObj = JSON.parse(canonicalizeContract(contractWithHashes)) as Record<\n string,\n unknown\n >;\n const contractJsonWithMeta = {\n ...contractJsonObj,\n _generated: {\n warning: '⚠️ GENERATED FILE - DO NOT EDIT',\n message: 'This file is automatically generated by \"prisma-next contract emit\".',\n regenerate: 'To regenerate, run: prisma-next contract emit',\n },\n };\n const contractJsonString = JSON.stringify(contractJsonWithMeta, null, 2);\n\n const generateOptions =\n parameterizedRenderers || parameterizedTypeImports\n ? {\n ...ifDefined('parameterizedRenderers', parameterizedRenderers),\n ...ifDefined('parameterizedTypeImports', parameterizedTypeImports),\n }\n : undefined;\n\n const contractTypeHashes = {\n storageHash,\n ...ifDefined('executionHash', executionHash),\n profileHash,\n };\n const contractDtsRaw = targetFamily.generateContractTypes(\n ir,\n codecTypeImports ?? [],\n operationTypeImports ?? [],\n contractTypeHashes,\n generateOptions,\n );\n const contractDts = await format(contractDtsRaw, {\n parser: 'typescript',\n singleQuote: true,\n semi: true,\n printWidth: 100,\n });\n\n return {\n contractJson: contractJsonString,\n contractDts,\n storageHash,\n ...ifDefined('executionHash', executionHash),\n profileHash,\n };\n}\n"],"mappings":";;;;;;;;AAoCA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD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AAqB,KAAK,UAAU,sBAAsB,MAAM,EAAE;CAExE,MAAM,kBACJ,0BAA0B,2BACtB;EACE,GAAG,UAAU,0BAA0B,uBAAuB;EAC9D,GAAG,UAAU,4BAA4B,yBAAyB;EACnE,GACD;CAEN,MAAM,qBAAqB;EACzB;EACA,GAAG,UAAU,iBAAiB,cAAc;EAC5C;EACD;AAeD,QAAO;EACL,cAAc;EACd,aATkB,MAAM,OAPH,aAAa,sBAClC,IACA,oBAAoB,EAAE,EACtB,wBAAwB,EAAE,EAC1B,oBACA,gBACD,EACgD;GAC/C,QAAQ;GACR,aAAa;GACb,MAAM;GACN,YAAY;GACb,CAAC;EAKA;EACA,GAAG,UAAU,iBAAiB,cAAc;EAC5C;EACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-view-
|
|
1
|
+
{"version":3,"file":"schema-view-D9u47nc8.d.mts","names":[],"sources":["../src/schema-view.ts"],"sourcesContent":[],"mappings":";;AAmEA;AAaA;;;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAzBY,cAAA;;;;;UAaK,cAAA;iBACA;;;kBAGC;+BACa;;;;;;UAOd,cAAA;iBACA"}
|
package/dist/schema-view.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SchemaNodeKind, r as SchemaTreeNode, t as CoreSchemaView } from "./schema-view-
|
|
1
|
+
import { n as SchemaNodeKind, r as SchemaTreeNode, t as CoreSchemaView } from "./schema-view-D9u47nc8.mjs";
|
|
2
2
|
export { type CoreSchemaView, type SchemaNodeKind, type SchemaTreeNode };
|
package/dist/stack.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as ControlExtensionDescriptor, l as ControlPlaneStack, r as ControlDriverDescriptor, t as ControlAdapterDescriptor, u as ControlTargetDescriptor } from "./types-
|
|
1
|
+
import { a as ControlExtensionDescriptor, l as ControlPlaneStack, r as ControlDriverDescriptor, t as ControlAdapterDescriptor, u as ControlTargetDescriptor } from "./types-CuAauVCJ.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/stack.d.ts
|
|
4
4
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as CoreSchemaView } from "./schema-view-
|
|
1
|
+
import { t as CoreSchemaView } from "./schema-view-D9u47nc8.mjs";
|
|
2
2
|
import { ContractMarkerRecord, TargetFamilyHook } from "@prisma-next/contract/types";
|
|
3
|
-
import { AdapterDescriptor, AdapterInstance, DriverDescriptor, DriverInstance, ExtensionDescriptor, ExtensionInstance, FamilyDescriptor, FamilyInstance, TargetBoundComponentDescriptor, TargetDescriptor, TargetInstance } from "@prisma-next/contract/framework-components";
|
|
4
3
|
import { ContractIR } from "@prisma-next/contract/ir";
|
|
5
4
|
import { Result } from "@prisma-next/utils/result";
|
|
5
|
+
import { AdapterDescriptor, AdapterInstance, DriverDescriptor, DriverInstance, ExtensionDescriptor, ExtensionInstance, FamilyDescriptor, FamilyInstance, TargetBoundComponentDescriptor, TargetDescriptor, TargetInstance } from "@prisma-next/contract/framework-components";
|
|
6
6
|
|
|
7
7
|
//#region src/migrations.d.ts
|
|
8
8
|
|
|
@@ -594,4 +594,4 @@ interface SignDatabaseResult {
|
|
|
594
594
|
}
|
|
595
595
|
//#endregion
|
|
596
596
|
export { MigrationRunnerExecutionChecks as A, MigrationPlanOperation as C, MigrationPlannerResult as D, MigrationPlannerFailureResult as E, MigrationRunnerResult as M, MigrationRunnerSuccessValue as N, MigrationPlannerSuccessResult as O, TargetMigrationsCapability as P, MigrationPlan as S, MigrationPlannerConflict as T, SignDatabaseResult as _, ControlExtensionDescriptor as a, MigrationOperationClass as b, ControlFamilyInstance as c, ControlTargetInstance as d, EmitContractResult as f, SchemaVerificationNode as g, SchemaIssue as h, ControlDriverInstance as i, MigrationRunnerFailure as j, MigrationRunner as k, ControlPlaneStack as l, OperationContext as m, ControlAdapterInstance as n, ControlExtensionInstance as o, IntrospectSchemaResult as p, ControlDriverDescriptor as r, ControlFamilyDescriptor as s, ControlAdapterDescriptor as t, ControlTargetDescriptor as u, VerifyDatabaseResult as v, MigrationPlanner as w, MigrationOperationPolicy as x, VerifyDatabaseSchemaResult as y };
|
|
597
|
-
//# sourceMappingURL=types-
|
|
597
|
+
//# sourceMappingURL=types-CuAauVCJ.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-CuAauVCJ.d.mts","names":[],"sources":["../src/migrations.ts","../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA8FA;AAQA;AASA;AAQA;AAcA;;AAAwE,KA5G5D,uBAAA,GA4G4D,UAAA,GAAA,UAAA,GAAA,aAAA;;;AAUxE;AA6BiB,UA9IA,wBAAA,CA8IgB;EAOZ,SAAA,uBAAA,EAAA,SApJwB,uBAoJxB,EAAA;;;;;;AASO,UAlJX,sBAAA,CAkJW;EAUX;EAKE,SAAA,EAAA,EAAA,MAAA;EACwB;EAAW,SAAA,KAAA,EAAA,MAAA;EAAjC;EAEA,SAAA,cAAA,EA9JM,uBA8JN;;;;;;AAgBf,UAvKW,aAAA,CAuKX;EAD4B;EAGpB,SAAA,QAAA,EAAA,MAAA;EAAR;EAAO,SAAA,WAAA,EAAA;IAeI,SAAA,WAAA,EAAA,MAA0B;IAGK,SAAA,WAAA,CAAA,EAAA,MAAA;EAAtB,CAAA;EAAyD;EAAtB,SAAA,UAAA,EAAA,SAlL7B,sBAkL6B,EAAA;;;;;AAGtC,UA3KN,wBAAA,CA2KM;EAAkC;EAAW,SAAA,IAAA,EAAA,MAAA;EAA3B;EAAe,SAAA,OAAA,EAAA,MAAA;;;;ACrMxD;;;AAqB2C,UDiB1B,6BAAA,CCjB0B;EAAtB,SAAA,IAAA,EAAA,SAAA;EAKP,SAAA,IAAA,EDcG,aCdH;;;;;AAgBkC,UDI/B,6BAAA,CCJ+B;EAAd,SAAA,IAAA,EAAA,SA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W;qBACjB,cAAc,QAAQ;;;;;;;;;UAU1B,0GAGY,yBACzB,WACA,aACE,yBAAyB,WAAW,oBAChC,oBAAoB,WAAW;YAC7B;;;;;UAMK,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA8BA,WAAA;;;;;;;;;;;;;;UAkCA,sBAAA;;;;;;;;;8BASa;;;;;UAMb,0BAAA;;;;;;;;;;;;;8BAaa;mBACX;;;;;;;;;;;;;;;;;;;;UAqBF,kBAAA;;;;;;;;;;;;;UAcA;;;;;;;mBAOE;;;;;;;;;;;;;UAcF,kBAAA"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as MigrationRunnerExecutionChecks, C as MigrationPlanOperation, D as MigrationPlannerResult, E as MigrationPlannerFailureResult, M as MigrationRunnerResult, N as MigrationRunnerSuccessValue, O as MigrationPlannerSuccessResult, P as TargetMigrationsCapability, S as MigrationPlan, T as MigrationPlannerConflict, _ as SignDatabaseResult, a as ControlExtensionDescriptor, b as MigrationOperationClass, c as ControlFamilyInstance, d as ControlTargetInstance, f as EmitContractResult, g as SchemaVerificationNode, h as SchemaIssue, i as ControlDriverInstance, j as MigrationRunnerFailure, k as MigrationRunner, l as ControlPlaneStack, m as OperationContext, n as ControlAdapterInstance, o as ControlExtensionInstance, p as IntrospectSchemaResult, r as ControlDriverDescriptor, s as ControlFamilyDescriptor, t as ControlAdapterDescriptor, u as ControlTargetDescriptor, v as VerifyDatabaseResult, w as MigrationPlanner, x as MigrationOperationPolicy, y as VerifyDatabaseSchemaResult } from "./types-
|
|
1
|
+
import { A as MigrationRunnerExecutionChecks, C as MigrationPlanOperation, D as MigrationPlannerResult, E as MigrationPlannerFailureResult, M as MigrationRunnerResult, N as MigrationRunnerSuccessValue, O as MigrationPlannerSuccessResult, P as TargetMigrationsCapability, S as MigrationPlan, T as MigrationPlannerConflict, _ as SignDatabaseResult, a as ControlExtensionDescriptor, b as MigrationOperationClass, c as ControlFamilyInstance, d as ControlTargetInstance, f as EmitContractResult, g as SchemaVerificationNode, h as SchemaIssue, i as ControlDriverInstance, j as MigrationRunnerFailure, k as MigrationRunner, l as ControlPlaneStack, m as OperationContext, n as ControlAdapterInstance, o as ControlExtensionInstance, p as IntrospectSchemaResult, r as ControlDriverDescriptor, s as ControlFamilyDescriptor, t as ControlAdapterDescriptor, u as ControlTargetDescriptor, v as VerifyDatabaseResult, w as MigrationPlanner, x as MigrationOperationPolicy, y as VerifyDatabaseSchemaResult } from "./types-CuAauVCJ.mjs";
|
|
2
2
|
export { type ControlAdapterDescriptor, type ControlAdapterInstance, type ControlDriverDescriptor, type ControlDriverInstance, type ControlExtensionDescriptor, type ControlExtensionInstance, type ControlFamilyDescriptor, type ControlFamilyInstance, type ControlPlaneStack, type ControlTargetDescriptor, type ControlTargetInstance, type EmitContractResult, type IntrospectSchemaResult, type MigrationOperationClass, type MigrationOperationPolicy, type MigrationPlan, type MigrationPlanOperation, type MigrationPlanner, type MigrationPlannerConflict, type MigrationPlannerFailureResult, type MigrationPlannerResult, type MigrationPlannerSuccessResult, type MigrationRunner, type MigrationRunnerExecutionChecks, type MigrationRunnerFailure, type MigrationRunnerResult, type MigrationRunnerSuccessValue, type OperationContext, type SchemaIssue, type SchemaVerificationNode, type SignDatabaseResult, type TargetMigrationsCapability, type VerifyDatabaseResult, type VerifyDatabaseSchemaResult };
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/core-control-plane",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.47",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Control plane domain actions, config types, validation, and error factories for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"arktype": "^2.1.26",
|
|
9
9
|
"prettier": "^3.3.3",
|
|
10
|
-
"@prisma-next/contract": "0.3.0-dev.
|
|
11
|
-
"@prisma-next/operations": "0.3.0-dev.
|
|
12
|
-
"@prisma-next/utils": "0.3.0-dev.
|
|
10
|
+
"@prisma-next/contract": "0.3.0-dev.47",
|
|
11
|
+
"@prisma-next/operations": "0.3.0-dev.47",
|
|
12
|
+
"@prisma-next/utils": "0.3.0-dev.47"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"tsdown": "0.18.4",
|
package/src/config-types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type } from 'arktype';
|
|
2
|
+
import type { ContractSourceProvider } from './contract-source-types';
|
|
2
3
|
import type {
|
|
3
4
|
ControlAdapterDescriptor,
|
|
4
5
|
ControlDriverDescriptor,
|
|
@@ -19,10 +20,10 @@ export type CliDriver = ControlDriverInstance<string, string>;
|
|
|
19
20
|
*/
|
|
20
21
|
export interface ContractConfig {
|
|
21
22
|
/**
|
|
22
|
-
* Contract source.
|
|
23
|
-
*
|
|
23
|
+
* Contract source provider. The provider is always async and must return
|
|
24
|
+
* a Result containing either ContractIR or structured diagnostics.
|
|
24
25
|
*/
|
|
25
|
-
readonly source:
|
|
26
|
+
readonly source: ContractSourceProvider;
|
|
26
27
|
/**
|
|
27
28
|
* Path to contract.json artifact. Defaults to 'src/prisma/contract.json'.
|
|
28
29
|
* The .d.ts types file will be colocated (e.g., contract.json → contract.d.ts).
|
|
@@ -80,10 +81,11 @@ export interface PrismaNextConfig<
|
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
83
|
* Arktype schema for ContractConfig validation.
|
|
83
|
-
* Validates
|
|
84
|
+
* Validates presence/shape only.
|
|
85
|
+
* contract.source is validated as a provider function at runtime in defineConfig().
|
|
84
86
|
*/
|
|
85
87
|
const ContractConfigSchema = type({
|
|
86
|
-
source: 'unknown', //
|
|
88
|
+
source: 'unknown', // Runtime check enforces provider function shape
|
|
87
89
|
'output?': 'string',
|
|
88
90
|
});
|
|
89
91
|
|
|
@@ -124,19 +126,10 @@ export function defineConfig<TFamilyId extends string = string, TTargetId extend
|
|
|
124
126
|
|
|
125
127
|
// Normalize contract config if present
|
|
126
128
|
if (config.contract) {
|
|
127
|
-
// Validate contract.source
|
|
129
|
+
// Validate contract.source provider function shape at runtime.
|
|
128
130
|
const source = config.contract.source;
|
|
129
|
-
if (
|
|
130
|
-
source
|
|
131
|
-
typeof source !== 'object' &&
|
|
132
|
-
typeof source !== 'function' &&
|
|
133
|
-
typeof source !== 'string' &&
|
|
134
|
-
typeof source !== 'number' &&
|
|
135
|
-
typeof source !== 'boolean'
|
|
136
|
-
) {
|
|
137
|
-
throw new Error(
|
|
138
|
-
'Config.contract.source must be a value (object, string, number, boolean, null) or a function',
|
|
139
|
-
);
|
|
131
|
+
if (typeof source !== 'function') {
|
|
132
|
+
throw new Error('Config.contract.source must be a provider function');
|
|
140
133
|
}
|
|
141
134
|
|
|
142
135
|
// Apply defaults
|
package/src/config-validation.ts
CHANGED
|
@@ -256,6 +256,13 @@ export function validateConfig(config: unknown): asserts config is PrismaNextCon
|
|
|
256
256
|
why: 'Config.contract.source is required when contract is provided',
|
|
257
257
|
});
|
|
258
258
|
}
|
|
259
|
+
|
|
260
|
+
if (typeof contract['source'] !== 'function') {
|
|
261
|
+
throw errorConfigValidation('contract.source', {
|
|
262
|
+
why: 'Config.contract.source must be a provider function',
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
259
266
|
if (contract['output'] !== undefined && typeof contract['output'] !== 'string') {
|
|
260
267
|
throw errorConfigValidation('contract.output', {
|
|
261
268
|
why: 'Config.contract.output must be a string when provided',
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ContractIR } from '@prisma-next/contract/ir';
|
|
2
|
+
import type { Result } from '@prisma-next/utils/result';
|
|
3
|
+
|
|
4
|
+
export interface ContractSourceDiagnosticPosition {
|
|
5
|
+
readonly offset: number;
|
|
6
|
+
readonly line: number;
|
|
7
|
+
readonly column: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ContractSourceDiagnosticSpan {
|
|
11
|
+
readonly start: ContractSourceDiagnosticPosition;
|
|
12
|
+
readonly end: ContractSourceDiagnosticPosition;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ContractSourceDiagnostic {
|
|
16
|
+
readonly code: string;
|
|
17
|
+
readonly message: string;
|
|
18
|
+
readonly sourceId?: string;
|
|
19
|
+
readonly span?: ContractSourceDiagnosticSpan;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ContractSourceDiagnostics {
|
|
23
|
+
readonly summary: string;
|
|
24
|
+
readonly diagnostics: readonly ContractSourceDiagnostic[];
|
|
25
|
+
readonly meta?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type ContractSourceProvider = () => Promise<Result<ContractIR, ContractSourceDiagnostics>>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ContractIR } from '@prisma-next/contract/ir';
|
|
2
1
|
import { bigintJsonReplacer } from '@prisma-next/contract/types';
|
|
3
2
|
import { isArrayEqual } from '@prisma-next/utils/array-equal';
|
|
4
3
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
@@ -17,7 +16,22 @@ type NormalizedContract = {
|
|
|
17
16
|
extensionPacks: Record<string, unknown>;
|
|
18
17
|
capabilities: Record<string, Record<string, boolean>>;
|
|
19
18
|
meta: Record<string, unknown>;
|
|
20
|
-
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type CanonicalContractInput = {
|
|
22
|
+
schemaVersion: string;
|
|
23
|
+
targetFamily: string;
|
|
24
|
+
target: string;
|
|
25
|
+
models: Record<string, unknown>;
|
|
26
|
+
relations: Record<string, unknown>;
|
|
27
|
+
storage: Record<string, unknown>;
|
|
28
|
+
execution?: Record<string, unknown>;
|
|
29
|
+
extensionPacks: Record<string, unknown>;
|
|
30
|
+
capabilities: Record<string, Record<string, boolean>>;
|
|
31
|
+
meta: Record<string, unknown>;
|
|
32
|
+
storageHash?: string;
|
|
33
|
+
executionHash?: string;
|
|
34
|
+
profileHash?: string;
|
|
21
35
|
};
|
|
22
36
|
|
|
23
37
|
const TOP_LEVEL_ORDER = [
|
|
@@ -29,12 +43,12 @@ const TOP_LEVEL_ORDER = [
|
|
|
29
43
|
'executionHash',
|
|
30
44
|
'profileHash',
|
|
31
45
|
'models',
|
|
46
|
+
'relations',
|
|
32
47
|
'storage',
|
|
33
48
|
'execution',
|
|
34
49
|
'capabilities',
|
|
35
50
|
'extensionPacks',
|
|
36
51
|
'meta',
|
|
37
|
-
'sources',
|
|
38
52
|
] as const;
|
|
39
53
|
|
|
40
54
|
function isDefaultValue(value: unknown): boolean {
|
|
@@ -94,7 +108,6 @@ function omitDefaults(obj: unknown, path: readonly string[]): unknown {
|
|
|
94
108
|
const isRequiredExtensionPacks = isArrayEqual(currentPath, ['extensionPacks']);
|
|
95
109
|
const isRequiredCapabilities = isArrayEqual(currentPath, ['capabilities']);
|
|
96
110
|
const isRequiredMeta = isArrayEqual(currentPath, ['meta']);
|
|
97
|
-
const isRequiredSources = isArrayEqual(currentPath, ['sources']);
|
|
98
111
|
const isRequiredExecutionDefaults = isArrayEqual(currentPath, [
|
|
99
112
|
'execution',
|
|
100
113
|
'mutations',
|
|
@@ -140,7 +153,6 @@ function omitDefaults(obj: unknown, path: readonly string[]): unknown {
|
|
|
140
153
|
!isRequiredExtensionPacks &&
|
|
141
154
|
!isRequiredCapabilities &&
|
|
142
155
|
!isRequiredMeta &&
|
|
143
|
-
!isRequiredSources &&
|
|
144
156
|
!isRequiredExecutionDefaults &&
|
|
145
157
|
!isExtensionNamespace &&
|
|
146
158
|
!isModelRelations &&
|
|
@@ -258,9 +270,7 @@ function orderTopLevel(obj: Record<string, unknown>): Record<string, unknown> {
|
|
|
258
270
|
return ordered;
|
|
259
271
|
}
|
|
260
272
|
|
|
261
|
-
export function canonicalizeContract(
|
|
262
|
-
ir: ContractIR & { storageHash?: string; executionHash?: string; profileHash?: string },
|
|
263
|
-
): string {
|
|
273
|
+
export function canonicalizeContract(ir: CanonicalContractInput): string {
|
|
264
274
|
const normalized: NormalizedContract = {
|
|
265
275
|
schemaVersion: ir.schemaVersion,
|
|
266
276
|
targetFamily: ir.targetFamily,
|
|
@@ -272,7 +282,6 @@ export function canonicalizeContract(
|
|
|
272
282
|
extensionPacks: ir.extensionPacks,
|
|
273
283
|
capabilities: ir.capabilities,
|
|
274
284
|
meta: ir.meta,
|
|
275
|
-
sources: ir.sources,
|
|
276
285
|
};
|
|
277
286
|
Object.assign(
|
|
278
287
|
normalized,
|
package/src/emission/emit.ts
CHANGED
|
@@ -1,11 +1,47 @@
|
|
|
1
1
|
import type { ContractIR } from '@prisma-next/contract/ir';
|
|
2
2
|
import type { TargetFamilyHook, ValidationContext } from '@prisma-next/contract/types';
|
|
3
3
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
4
|
+
import { type } from 'arktype';
|
|
4
5
|
import { format } from 'prettier';
|
|
5
6
|
import { canonicalizeContract } from './canonicalization';
|
|
6
7
|
import { computeExecutionHash, computeProfileHash, computeStorageHash } from './hashing';
|
|
7
8
|
import type { EmitOptions, EmitResult } from './types';
|
|
8
9
|
|
|
10
|
+
const CanonicalMetaSchema = type({
|
|
11
|
+
'[string]': 'unknown',
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const CanonicalContractSchema = type({
|
|
15
|
+
'+': 'reject',
|
|
16
|
+
schemaVersion: 'string',
|
|
17
|
+
targetFamily: 'string',
|
|
18
|
+
target: 'string',
|
|
19
|
+
models: type({ '[string]': 'unknown' }),
|
|
20
|
+
relations: type({ '[string]': 'unknown' }),
|
|
21
|
+
storage: type({ '[string]': 'unknown' }),
|
|
22
|
+
'execution?': type({ '[string]': 'unknown' }),
|
|
23
|
+
extensionPacks: type({ '[string]': 'unknown' }),
|
|
24
|
+
capabilities: type({
|
|
25
|
+
'[string]': type({
|
|
26
|
+
'[string]': 'boolean',
|
|
27
|
+
}),
|
|
28
|
+
}),
|
|
29
|
+
meta: CanonicalMetaSchema,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function assertCanonicalArtifactShape(value: unknown): void {
|
|
33
|
+
const result = CanonicalContractSchema(value);
|
|
34
|
+
if (result instanceof type.errors) {
|
|
35
|
+
const issues = result
|
|
36
|
+
.map((error) => {
|
|
37
|
+
const path = error.path?.toString() ?? '<root>';
|
|
38
|
+
return `${path}: ${error.message}`;
|
|
39
|
+
})
|
|
40
|
+
.join('; ');
|
|
41
|
+
throw new Error(`ContractIR canonical artifact validation failed: ${issues}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
9
45
|
function validateCoreStructure(ir: ContractIR): void {
|
|
10
46
|
if (!ir.targetFamily) {
|
|
11
47
|
throw new Error('ContractIR must have targetFamily');
|
|
@@ -34,9 +70,6 @@ function validateCoreStructure(ir: ContractIR): void {
|
|
|
34
70
|
if (!ir.meta || typeof ir.meta !== 'object') {
|
|
35
71
|
throw new Error('ContractIR must have meta');
|
|
36
72
|
}
|
|
37
|
-
if (!ir.sources || typeof ir.sources !== 'object') {
|
|
38
|
-
throw new Error('ContractIR must have sources');
|
|
39
|
-
}
|
|
40
73
|
}
|
|
41
74
|
|
|
42
75
|
export async function emit(
|
|
@@ -65,7 +98,7 @@ export async function emit(
|
|
|
65
98
|
|
|
66
99
|
targetFamily.validateStructure(ir);
|
|
67
100
|
|
|
68
|
-
const
|
|
101
|
+
const canonicalContract = {
|
|
69
102
|
schemaVersion: ir.schemaVersion,
|
|
70
103
|
targetFamily: ir.targetFamily,
|
|
71
104
|
target: ir.target,
|
|
@@ -76,20 +109,17 @@ export async function emit(
|
|
|
76
109
|
extensionPacks: ir.extensionPacks,
|
|
77
110
|
capabilities: ir.capabilities,
|
|
78
111
|
meta: ir.meta,
|
|
79
|
-
|
|
80
|
-
|
|
112
|
+
};
|
|
113
|
+
assertCanonicalArtifactShape(canonicalContract);
|
|
81
114
|
|
|
82
|
-
const storageHash = computeStorageHash(
|
|
83
|
-
const executionHash =
|
|
84
|
-
|
|
115
|
+
const storageHash = computeStorageHash(canonicalContract);
|
|
116
|
+
const executionHash = canonicalContract.execution
|
|
117
|
+
? computeExecutionHash(canonicalContract)
|
|
118
|
+
: undefined;
|
|
119
|
+
const profileHash = computeProfileHash(canonicalContract);
|
|
85
120
|
|
|
86
|
-
const contractWithHashes
|
|
87
|
-
|
|
88
|
-
executionHash?: string;
|
|
89
|
-
profileHash?: string;
|
|
90
|
-
} = {
|
|
91
|
-
...ir,
|
|
92
|
-
schemaVersion: contractJson.schemaVersion,
|
|
121
|
+
const contractWithHashes = {
|
|
122
|
+
...canonicalContract,
|
|
93
123
|
storageHash,
|
|
94
124
|
...ifDefined('executionHash', executionHash),
|
|
95
125
|
profileHash,
|
package/src/emission/hashing.ts
CHANGED
|
@@ -1,31 +1,16 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import type { ContractIR } from '@prisma-next/contract/ir';
|
|
3
2
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
3
|
+
import type { CanonicalContractInput } from './canonicalization';
|
|
4
4
|
import { canonicalizeContract } from './canonicalization';
|
|
5
5
|
|
|
6
|
-
type ContractInput = {
|
|
7
|
-
schemaVersion: string;
|
|
8
|
-
targetFamily: string;
|
|
9
|
-
target: string;
|
|
10
|
-
models: Record<string, unknown>;
|
|
11
|
-
relations: Record<string, unknown>;
|
|
12
|
-
storage: Record<string, unknown>;
|
|
13
|
-
execution?: Record<string, unknown>;
|
|
14
|
-
extensionPacks: Record<string, unknown>;
|
|
15
|
-
sources: Record<string, unknown>;
|
|
16
|
-
capabilities: Record<string, Record<string, boolean>>;
|
|
17
|
-
meta: Record<string, unknown>;
|
|
18
|
-
[key: string]: unknown;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
6
|
function computeHash(content: string): string {
|
|
22
7
|
const hash = createHash('sha256');
|
|
23
8
|
hash.update(content);
|
|
24
9
|
return `sha256:${hash.digest('hex')}`;
|
|
25
10
|
}
|
|
26
11
|
|
|
27
|
-
export function computeStorageHash(contract:
|
|
28
|
-
const storageContract
|
|
12
|
+
export function computeStorageHash(contract: CanonicalContractInput): string {
|
|
13
|
+
const storageContract = {
|
|
29
14
|
schemaVersion: contract.schemaVersion,
|
|
30
15
|
targetFamily: contract.targetFamily,
|
|
31
16
|
target: contract.target,
|
|
@@ -33,7 +18,6 @@ export function computeStorageHash(contract: ContractInput): string {
|
|
|
33
18
|
models: {},
|
|
34
19
|
relations: {},
|
|
35
20
|
extensionPacks: {},
|
|
36
|
-
sources: {},
|
|
37
21
|
capabilities: {},
|
|
38
22
|
meta: {},
|
|
39
23
|
};
|
|
@@ -41,8 +25,8 @@ export function computeStorageHash(contract: ContractInput): string {
|
|
|
41
25
|
return computeHash(canonical);
|
|
42
26
|
}
|
|
43
27
|
|
|
44
|
-
export function computeProfileHash(contract:
|
|
45
|
-
const profileContract
|
|
28
|
+
export function computeProfileHash(contract: CanonicalContractInput): string {
|
|
29
|
+
const profileContract = {
|
|
46
30
|
schemaVersion: contract.schemaVersion,
|
|
47
31
|
targetFamily: contract.targetFamily,
|
|
48
32
|
target: contract.target,
|
|
@@ -52,14 +36,13 @@ export function computeProfileHash(contract: ContractInput): string {
|
|
|
52
36
|
extensionPacks: {},
|
|
53
37
|
capabilities: contract.capabilities,
|
|
54
38
|
meta: {},
|
|
55
|
-
sources: {},
|
|
56
39
|
};
|
|
57
40
|
const canonical = canonicalizeContract(profileContract);
|
|
58
41
|
return computeHash(canonical);
|
|
59
42
|
}
|
|
60
43
|
|
|
61
|
-
export function computeExecutionHash(contract:
|
|
62
|
-
const executionContract
|
|
44
|
+
export function computeExecutionHash(contract: CanonicalContractInput): string {
|
|
45
|
+
const executionContract = {
|
|
63
46
|
schemaVersion: contract.schemaVersion,
|
|
64
47
|
targetFamily: contract.targetFamily,
|
|
65
48
|
target: contract.target,
|
|
@@ -67,7 +50,6 @@ export function computeExecutionHash(contract: ContractInput): string {
|
|
|
67
50
|
relations: {},
|
|
68
51
|
storage: {},
|
|
69
52
|
extensionPacks: {},
|
|
70
|
-
sources: {},
|
|
71
53
|
capabilities: {},
|
|
72
54
|
meta: {},
|
|
73
55
|
...ifDefined('execution', contract.execution),
|
|
@@ -3,3 +3,10 @@ export type {
|
|
|
3
3
|
PrismaNextConfig,
|
|
4
4
|
} from '../config-types';
|
|
5
5
|
export { defineConfig } from '../config-types';
|
|
6
|
+
export type {
|
|
7
|
+
ContractSourceDiagnostic,
|
|
8
|
+
ContractSourceDiagnosticPosition,
|
|
9
|
+
ContractSourceDiagnosticSpan,
|
|
10
|
+
ContractSourceDiagnostics,
|
|
11
|
+
ContractSourceProvider,
|
|
12
|
+
} from '../contract-source-types';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config-types-CnWxlkH_.d.mts","names":[],"sources":["../src/config-types.ts"],"sourcesContent":[],"mappings":";;;;;;;AA8CmB,UA3BF,cAAA,CA2BE;EAC0B;;;;EAC8B,SAAA,MAAA,EAAA,OAAA,GAAA,CAAA,GAAA,GAAA,OAAA,GAxB7B,OAwB6B,CAAA,OAAA,CAAA,CAAA;EAAtC;;;;EAUA,SAAA,MAAA,CAAA,EAAA,MAAA;;;;;;;AAwDrC;;;AACU,UA3EO,gBA2EP,CAAA,kBAAA,MAAA,GAAA,MAAA,EAAA,kBAAA,MAAA,GAAA,MAAA,EAAA,cAAA,OAAA,CAAA,CAAA;EACU,SAAA,MAAA,EAvED,uBAuEC,CAvEuB,SAuEvB,CAAA;EAAW,SAAA,MAAA,EAtEZ,uBAsEY,CAtEY,SAsEZ,EAtEuB,SAsEvB,CAAA;EAA5B,SAAA,OAAA,EArEiB,wBAqEjB,CArE0C,SAqE1C,EArEqD,SAqErD,CAAA;EAAgB,SAAA,cAAA,CAAA,EAAA,SApEkB,0BAoElB,CApE6C,SAoE7C,EApEwD,SAoExD,CAAA,EAAA;;;;;;;oBA7DC,wBAChB,WACA,WACA,sBAAsB,WAAW,YACjC;;;;;;;;;;;0BAYsB;;;;;;sBAMJ;;;;;;;;;;;;;iBAqCN,2FACN,iBAAiB,WAAW,aACnC,iBAAiB,WAAW"}
|