@prisma-next/core-control-plane 0.3.0-pr.99.3 → 0.3.0-pr.99.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config-types-h9ifypQ0.d.mts +79 -0
- package/dist/config-types-h9ifypQ0.d.mts.map +1 -0
- package/dist/config-types.d.mts +2 -0
- package/dist/config-types.mjs +65 -0
- package/dist/config-types.mjs.map +1 -0
- package/dist/config-validation.d.mts +15 -0
- package/dist/config-validation.d.mts.map +1 -0
- package/dist/config-validation.mjs +79 -0
- package/dist/config-validation.mjs.map +1 -0
- package/dist/emission.d.mts +57 -0
- package/dist/emission.d.mts.map +1 -0
- package/dist/emission.mjs +261 -0
- package/dist/emission.mjs.map +1 -0
- package/dist/errors-Qlh0sdcb.mjs +276 -0
- package/dist/errors-Qlh0sdcb.mjs.map +1 -0
- package/dist/errors.d.mts +191 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +3 -0
- package/dist/{schema-view.d.ts → schema-view-BG_ebqoV.d.mts} +13 -10
- package/dist/schema-view-BG_ebqoV.d.mts.map +1 -0
- package/dist/schema-view.d.mts +2 -0
- package/dist/schema-view.mjs +1 -0
- package/dist/stack.d.mts +30 -0
- package/dist/stack.d.mts.map +1 -0
- package/dist/stack.mjs +30 -0
- package/dist/stack.mjs.map +1 -0
- package/dist/types-CsaU_uQP.d.mts +595 -0
- package/dist/types-CsaU_uQP.d.mts.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +1 -0
- package/package.json +21 -37
- package/dist/chunk-YT6YGR3N.js +0 -240
- package/dist/chunk-YT6YGR3N.js.map +0 -1
- package/dist/config-types.d.ts +0 -79
- package/dist/config-types.d.ts.map +0 -1
- package/dist/config-validation.d.ts +0 -10
- package/dist/config-validation.d.ts.map +0 -1
- package/dist/emission/canonicalization.d.ts +0 -6
- package/dist/emission/canonicalization.d.ts.map +0 -1
- package/dist/emission/emit.d.ts +0 -5
- package/dist/emission/emit.d.ts.map +0 -1
- package/dist/emission/hashing.d.ts +0 -17
- package/dist/emission/hashing.d.ts.map +0 -1
- package/dist/emission/types.d.ts +0 -26
- package/dist/emission/types.d.ts.map +0 -1
- package/dist/errors.d.ts +0 -188
- package/dist/errors.d.ts.map +0 -1
- package/dist/exports/config-types.d.ts +0 -3
- package/dist/exports/config-types.d.ts.map +0 -1
- package/dist/exports/config-types.js +0 -53
- package/dist/exports/config-types.js.map +0 -1
- package/dist/exports/config-validation.d.ts +0 -2
- package/dist/exports/config-validation.d.ts.map +0 -1
- package/dist/exports/config-validation.js +0 -252
- package/dist/exports/config-validation.js.map +0 -1
- package/dist/exports/emission.d.ts +0 -5
- package/dist/exports/emission.d.ts.map +0 -1
- package/dist/exports/emission.js +0 -323
- package/dist/exports/emission.js.map +0 -1
- package/dist/exports/errors.d.ts +0 -3
- package/dist/exports/errors.d.ts.map +0 -1
- package/dist/exports/errors.js +0 -43
- package/dist/exports/errors.js.map +0 -1
- package/dist/exports/schema-view.d.ts +0 -2
- package/dist/exports/schema-view.d.ts.map +0 -1
- package/dist/exports/schema-view.js +0 -1
- package/dist/exports/schema-view.js.map +0 -1
- package/dist/exports/stack.d.ts +0 -2
- package/dist/exports/stack.d.ts.map +0 -1
- package/dist/exports/stack.js +0 -13
- package/dist/exports/stack.js.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -1
- package/dist/exports/types.js.map +0 -1
- package/dist/migrations.d.ts +0 -190
- package/dist/migrations.d.ts.map +0 -1
- package/dist/schema-view.d.ts.map +0 -1
- package/dist/stack.d.ts +0 -25
- package/dist/stack.d.ts.map +0 -1
- package/dist/types.d.ts +0 -416
- package/dist/types.d.ts.map +0 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { a as ControlExtensionDescriptor, i as ControlDriverInstance, r as ControlDriverDescriptor, s as ControlFamilyDescriptor, t as ControlAdapterDescriptor, u as ControlTargetDescriptor } from "./types-CsaU_uQP.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/config-types.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Contract configuration specifying source and artifact locations.
|
|
7
|
+
*/
|
|
8
|
+
interface ContractConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Contract source. Can be a value or a function that returns a value (sync or async).
|
|
11
|
+
* If a function, it will be called to resolve the contract.
|
|
12
|
+
*/
|
|
13
|
+
readonly source: unknown | (() => unknown | Promise<unknown>);
|
|
14
|
+
/**
|
|
15
|
+
* Path to contract.json artifact. Defaults to 'src/prisma/contract.json'.
|
|
16
|
+
* This is the canonical location where other CLI commands can find the contract JSON.
|
|
17
|
+
*/
|
|
18
|
+
readonly output?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Path to contract.d.ts artifact. Defaults to output with .d.ts extension.
|
|
21
|
+
* If output ends with .json, replaces .json with .d.ts.
|
|
22
|
+
* Otherwise, appends .d.ts to the directory containing output.
|
|
23
|
+
*/
|
|
24
|
+
readonly types?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Configuration for Prisma Next CLI.
|
|
28
|
+
* Uses Control*Descriptor types for type-safe wiring with compile-time compatibility checks.
|
|
29
|
+
*
|
|
30
|
+
* @template TFamilyId - The family ID (e.g., 'sql', 'document')
|
|
31
|
+
* @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
|
|
32
|
+
* @template TConnection - The driver connection input type (defaults to `unknown` for config flexibility)
|
|
33
|
+
*/
|
|
34
|
+
interface PrismaNextConfig<TFamilyId extends string = string, TTargetId extends string = string, TConnection = unknown> {
|
|
35
|
+
readonly family: ControlFamilyDescriptor<TFamilyId>;
|
|
36
|
+
readonly target: ControlTargetDescriptor<TFamilyId, TTargetId>;
|
|
37
|
+
readonly adapter: ControlAdapterDescriptor<TFamilyId, TTargetId>;
|
|
38
|
+
readonly extensionPacks?: readonly ControlExtensionDescriptor<TFamilyId, TTargetId>[];
|
|
39
|
+
/**
|
|
40
|
+
* Driver descriptor for DB-connected CLI commands.
|
|
41
|
+
* Required for DB-connected commands (e.g., db verify).
|
|
42
|
+
* Optional for commands that don't need database access (e.g., emit).
|
|
43
|
+
* The driver's connection type matches the TConnection config parameter.
|
|
44
|
+
*/
|
|
45
|
+
readonly driver?: ControlDriverDescriptor<TFamilyId, TTargetId, ControlDriverInstance<TFamilyId, TTargetId>, TConnection>;
|
|
46
|
+
/**
|
|
47
|
+
* Database connection configuration.
|
|
48
|
+
* The connection type is driver-specific (e.g., URL string for Postgres).
|
|
49
|
+
*/
|
|
50
|
+
readonly db?: {
|
|
51
|
+
/**
|
|
52
|
+
* Driver-specific connection input.
|
|
53
|
+
* For Postgres: a connection string (URL).
|
|
54
|
+
* For other drivers: may be a structured object.
|
|
55
|
+
*/
|
|
56
|
+
readonly connection?: TConnection;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Contract configuration. Specifies source and artifact locations.
|
|
60
|
+
* Required for emit command; optional for other commands that only read artifacts.
|
|
61
|
+
*/
|
|
62
|
+
readonly contract?: ContractConfig;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Helper function to define a Prisma Next config.
|
|
66
|
+
* Validates and normalizes the config using Arktype, then returns the normalized IR.
|
|
67
|
+
*
|
|
68
|
+
* Normalization:
|
|
69
|
+
* - contract.output defaults to 'src/prisma/contract.json' if missing
|
|
70
|
+
* - contract.types defaults to output with .d.ts extension if missing
|
|
71
|
+
*
|
|
72
|
+
* @param config - Raw config input from user
|
|
73
|
+
* @returns Normalized config IR with defaults applied
|
|
74
|
+
* @throws Error if config structure is invalid
|
|
75
|
+
*/
|
|
76
|
+
declare function defineConfig<TFamilyId extends string = string, TTargetId extends string = string>(config: PrismaNextConfig<TFamilyId, TTargetId>): PrismaNextConfig<TFamilyId, TTargetId>;
|
|
77
|
+
//#endregion
|
|
78
|
+
export { PrismaNextConfig as n, defineConfig as r, ContractConfig as t };
|
|
79
|
+
//# sourceMappingURL=config-types-h9ifypQ0.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-types-h9ifypQ0.d.mts","names":[],"sources":["../src/config-types.ts"],"sourcesContent":[],"mappings":";;;;;;;AAqDmB,UAjCF,cAAA,CAiCE;EAC0B;;;;EAC8B,SAAA,MAAA,EAAA,OAAA,GAAA,CAAA,GAAA,GAAA,OAAA,GA9B7B,OA8B6B,CAAA,OAAA,CAAA,CAAA;EAAtC;;;;EAUA,SAAA,MAAA,CAAA,EAAA,MAAA;EAAjC;;;;;EAmBgC,SAAA,KAAA,CAAA,EAAA,MAAA;AAuCpC;;;;;;;;;UA5EiB;mBAKE,wBAAwB;mBACxB,wBAAwB,WAAW;oBAClC,yBAAyB,WAAW;qCACnB,2BAA2B,WAAW;;;;;;;oBAOvD,wBAChB,WACA,WACA,sBAAsB,WAAW,YACjC;;;;;;;;;;;0BAYsB;;;;;;sBAMJ;;;;;;;;;;;;;;iBAuCN,2FACN,iBAAiB,WAAW,aACnC,iBAAiB,WAAW"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { type } from "arktype";
|
|
3
|
+
|
|
4
|
+
//#region src/config-types.ts
|
|
5
|
+
/**
|
|
6
|
+
* Arktype schema for ContractConfig validation.
|
|
7
|
+
* Validates that source is present and output/types are strings when provided.
|
|
8
|
+
*/
|
|
9
|
+
const ContractConfigSchema = type({
|
|
10
|
+
source: "unknown",
|
|
11
|
+
"output?": "string",
|
|
12
|
+
"types?": "string"
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Arktype schema for PrismaNextConfig validation.
|
|
16
|
+
* Note: This validates structure only. Descriptor objects (family, target, adapter) are validated separately.
|
|
17
|
+
*/
|
|
18
|
+
const PrismaNextConfigSchema = type({
|
|
19
|
+
family: "unknown",
|
|
20
|
+
target: "unknown",
|
|
21
|
+
adapter: "unknown",
|
|
22
|
+
"extensionPacks?": "unknown[]",
|
|
23
|
+
"driver?": "unknown",
|
|
24
|
+
"db?": "unknown",
|
|
25
|
+
"contract?": ContractConfigSchema
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Helper function to define a Prisma Next config.
|
|
29
|
+
* Validates and normalizes the config using Arktype, then returns the normalized IR.
|
|
30
|
+
*
|
|
31
|
+
* Normalization:
|
|
32
|
+
* - contract.output defaults to 'src/prisma/contract.json' if missing
|
|
33
|
+
* - contract.types defaults to output with .d.ts extension if missing
|
|
34
|
+
*
|
|
35
|
+
* @param config - Raw config input from user
|
|
36
|
+
* @returns Normalized config IR with defaults applied
|
|
37
|
+
* @throws Error if config structure is invalid
|
|
38
|
+
*/
|
|
39
|
+
function defineConfig(config) {
|
|
40
|
+
const validated = PrismaNextConfigSchema(config);
|
|
41
|
+
if (validated instanceof type.errors) {
|
|
42
|
+
const messages = validated.map((p) => p.message).join("; ");
|
|
43
|
+
throw new Error(`Config validation failed: ${messages}`);
|
|
44
|
+
}
|
|
45
|
+
if (config.contract) {
|
|
46
|
+
const source = config.contract.source;
|
|
47
|
+
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");
|
|
48
|
+
const output = config.contract.output ?? "src/prisma/contract.json";
|
|
49
|
+
const types = config.contract.types ?? (output.endsWith(".json") ? `${output.slice(0, -5)}.d.ts` : join(dirname(output), "contract.d.ts"));
|
|
50
|
+
const normalizedContract = {
|
|
51
|
+
source: config.contract.source,
|
|
52
|
+
output,
|
|
53
|
+
types
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
...config,
|
|
57
|
+
contract: normalizedContract
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return config;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { defineConfig };
|
|
65
|
+
//# sourceMappingURL=config-types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-types.mjs","names":["normalizedContract: ContractConfig"],"sources":["../src/config-types.ts"],"sourcesContent":["import { dirname, join } from 'node:path';\nimport { 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. Can be a value or a function that returns a value (sync or async).\n * If a function, it will be called to resolve the contract.\n */\n readonly source: unknown | (() => unknown | Promise<unknown>);\n /**\n * Path to contract.json artifact. Defaults to 'src/prisma/contract.json'.\n * This is the canonical location where other CLI commands can find the contract JSON.\n */\n readonly output?: string;\n /**\n * Path to contract.d.ts artifact. Defaults to output with .d.ts extension.\n * If output ends with .json, replaces .json with .d.ts.\n * Otherwise, appends .d.ts to the directory containing output.\n */\n readonly types?: 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 that source is present and output/types are strings when provided.\n */\nconst ContractConfigSchema = type({\n source: 'unknown', // Can be value or function - runtime check needed\n 'output?': 'string',\n 'types?': '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 * - contract.types defaults to output with .d.ts extension 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 is a value or function (runtime check)\n const source = config.contract.source;\n if (\n source !== null &&\n typeof source !== 'object' &&\n typeof source !== 'function' &&\n typeof source !== 'string' &&\n typeof source !== 'number' &&\n typeof source !== 'boolean'\n ) {\n throw new Error(\n 'Config.contract.source must be a value (object, string, number, boolean, null) or a function',\n );\n }\n\n // Apply defaults\n const output = config.contract.output ?? 'src/prisma/contract.json';\n const types =\n config.contract.types ??\n (output.endsWith('.json')\n ? `${output.slice(0, -5)}.d.ts`\n : join(dirname(output), 'contract.d.ts'));\n\n const normalizedContract: ContractConfig = {\n source: config.contract.source,\n output,\n types,\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":";;;;;;;;AA2FA,MAAM,uBAAuB,KAAK;CAChC,QAAQ;CACR,WAAW;CACX,UAAU;CACX,CAAC;;;;;AAMF,MAAM,yBAAyB,KAAK;CAClC,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,mBAAmB;CACnB,WAAW;CACX,OAAO;CACP,aAAa;CACd,CAAC;;;;;;;;;;;;;AAcF,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;EAEnB,MAAM,SAAS,OAAO,SAAS;AAC/B,MACE,WAAW,QACX,OAAO,WAAW,YAClB,OAAO,WAAW,cAClB,OAAO,WAAW,YAClB,OAAO,WAAW,YAClB,OAAO,WAAW,UAElB,OAAM,IAAI,MACR,+FACD;EAIH,MAAM,SAAS,OAAO,SAAS,UAAU;EACzC,MAAM,QACJ,OAAO,SAAS,UACf,OAAO,SAAS,QAAQ,GACrB,GAAG,OAAO,MAAM,GAAG,GAAG,CAAC,SACvB,KAAK,QAAQ,OAAO,EAAE,gBAAgB;EAE5C,MAAMA,qBAAqC;GACzC,QAAQ,OAAO,SAAS;GACxB;GACA;GACD;AAGD,SAAO;GACL,GAAG;GACH,UAAU;GACX;;AAIH,QAAO"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { n as PrismaNextConfig } from "./config-types-h9ifypQ0.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/config-validation.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Validates that the config has the required structure.
|
|
7
|
+
* This is pure validation logic with no file I/O or CLI awareness.
|
|
8
|
+
*
|
|
9
|
+
* @param config - Config object to validate
|
|
10
|
+
* @throws CliStructuredError if config structure is invalid
|
|
11
|
+
*/
|
|
12
|
+
declare function validateConfig(config: unknown): asserts config is PrismaNextConfig;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { validateConfig };
|
|
15
|
+
//# sourceMappingURL=config-validation.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-validation.d.mts","names":[],"sources":["../src/config-validation.ts"],"sourcesContent":[],"mappings":";;;;;;AAUA;;;;;iBAAgB,cAAA,qCAAmD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { r as errorConfigValidation } from "./errors-Qlh0sdcb.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/config-validation.ts
|
|
4
|
+
/**
|
|
5
|
+
* Validates that the config has the required structure.
|
|
6
|
+
* This is pure validation logic with no file I/O or CLI awareness.
|
|
7
|
+
*
|
|
8
|
+
* @param config - Config object to validate
|
|
9
|
+
* @throws CliStructuredError if config structure is invalid
|
|
10
|
+
*/
|
|
11
|
+
function validateConfig(config) {
|
|
12
|
+
if (!config || typeof config !== "object") throw errorConfigValidation("object", { why: "Config must be an object" });
|
|
13
|
+
const configObj = config;
|
|
14
|
+
if (!configObj["family"]) throw errorConfigValidation("family");
|
|
15
|
+
if (!configObj["target"]) throw errorConfigValidation("target");
|
|
16
|
+
if (!configObj["adapter"]) throw errorConfigValidation("adapter");
|
|
17
|
+
const family = configObj["family"];
|
|
18
|
+
if (family["kind"] !== "family") throw errorConfigValidation("family.kind", { why: "Config.family must have kind: \"family\"" });
|
|
19
|
+
if (typeof family["familyId"] !== "string") throw errorConfigValidation("family.familyId", { why: "Config.family must have familyId: string" });
|
|
20
|
+
if (typeof family["version"] !== "string") throw errorConfigValidation("family.version", { why: "Config.family must have version: string" });
|
|
21
|
+
if (!family["hook"] || typeof family["hook"] !== "object") throw errorConfigValidation("family.hook", { why: "Config.family must have hook: TargetFamilyHook" });
|
|
22
|
+
if (typeof family["create"] !== "function") throw errorConfigValidation("family.create", { why: "Config.family must have create: function" });
|
|
23
|
+
const familyId = family["familyId"];
|
|
24
|
+
const target = configObj["target"];
|
|
25
|
+
if (target["kind"] !== "target") throw errorConfigValidation("target.kind", { why: "Config.target must have kind: \"target\"" });
|
|
26
|
+
if (typeof target["id"] !== "string") throw errorConfigValidation("target.id", { why: "Config.target must have id: string" });
|
|
27
|
+
if (typeof target["familyId"] !== "string") throw errorConfigValidation("target.familyId", { why: "Config.target must have familyId: string" });
|
|
28
|
+
if (typeof target["version"] !== "string") throw errorConfigValidation("target.version", { why: "Config.target must have version: string" });
|
|
29
|
+
if (target["familyId"] !== familyId) throw errorConfigValidation("target.familyId", { why: `Config.target.familyId must match Config.family.familyId (expected: ${familyId}, got: ${target["familyId"]})` });
|
|
30
|
+
if (typeof target["targetId"] !== "string") throw errorConfigValidation("target.targetId", { why: "Config.target must have targetId: string" });
|
|
31
|
+
if (typeof target["create"] !== "function") throw errorConfigValidation("target.create", { why: "Config.target must have create: function" });
|
|
32
|
+
const expectedTargetId = target["targetId"];
|
|
33
|
+
const adapter = configObj["adapter"];
|
|
34
|
+
if (adapter["kind"] !== "adapter") throw errorConfigValidation("adapter.kind", { why: "Config.adapter must have kind: \"adapter\"" });
|
|
35
|
+
if (typeof adapter["id"] !== "string") throw errorConfigValidation("adapter.id", { why: "Config.adapter must have id: string" });
|
|
36
|
+
if (typeof adapter["familyId"] !== "string") throw errorConfigValidation("adapter.familyId", { why: "Config.adapter must have familyId: string" });
|
|
37
|
+
if (typeof adapter["version"] !== "string") throw errorConfigValidation("adapter.version", { why: "Config.adapter must have version: string" });
|
|
38
|
+
if (adapter["familyId"] !== familyId) throw errorConfigValidation("adapter.familyId", { why: `Config.adapter.familyId must match Config.family.familyId (expected: ${familyId}, got: ${adapter["familyId"]})` });
|
|
39
|
+
if (typeof adapter["targetId"] !== "string") throw errorConfigValidation("adapter.targetId", { why: "Config.adapter must have targetId: string" });
|
|
40
|
+
if (adapter["targetId"] !== expectedTargetId) throw errorConfigValidation("adapter.targetId", { why: `Config.adapter.targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${adapter["targetId"]})` });
|
|
41
|
+
if (typeof adapter["create"] !== "function") throw errorConfigValidation("adapter.create", { why: "Config.adapter must have create: function" });
|
|
42
|
+
if (configObj["extensions"] !== void 0) {
|
|
43
|
+
if (!Array.isArray(configObj["extensions"])) throw errorConfigValidation("extensions", { why: "Config.extensions must be an array" });
|
|
44
|
+
for (const ext of configObj["extensions"]) {
|
|
45
|
+
if (!ext || typeof ext !== "object") throw errorConfigValidation("extensions[]", { why: "Config.extensions must contain ExtensionDescriptor objects" });
|
|
46
|
+
const extObj = ext;
|
|
47
|
+
if (extObj["kind"] !== "extension") throw errorConfigValidation("extensions[].kind", { why: "Config.extensions items must have kind: \"extension\"" });
|
|
48
|
+
if (typeof extObj["id"] !== "string") throw errorConfigValidation("extensions[].id", { why: "Config.extensions items must have id: string" });
|
|
49
|
+
if (typeof extObj["familyId"] !== "string") throw errorConfigValidation("extensions[].familyId", { why: "Config.extensions items must have familyId: string" });
|
|
50
|
+
if (typeof extObj["version"] !== "string") throw errorConfigValidation("extensions[].version", { why: "Config.extensions items must have version: string" });
|
|
51
|
+
if (extObj["familyId"] !== familyId) throw errorConfigValidation("extensions[].familyId", { why: `Config.extensions[].familyId must match Config.family.familyId (expected: ${familyId}, got: ${extObj["familyId"]})` });
|
|
52
|
+
if (typeof extObj["targetId"] !== "string") throw errorConfigValidation("extensions[].targetId", { why: "Config.extensions items must have targetId: string" });
|
|
53
|
+
if (extObj["targetId"] !== expectedTargetId) throw errorConfigValidation("extensions[].targetId", { why: `Config.extensions[].targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${extObj["targetId"]})` });
|
|
54
|
+
if (typeof extObj["create"] !== "function") throw errorConfigValidation("extensions[].create", { why: "Config.extensions items must have create: function" });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (configObj["driver"] !== void 0) {
|
|
58
|
+
const driver = configObj["driver"];
|
|
59
|
+
if (driver["kind"] !== "driver") throw errorConfigValidation("driver.kind", { why: "Config.driver must have kind: \"driver\"" });
|
|
60
|
+
if (typeof driver["id"] !== "string") throw errorConfigValidation("driver.id", { why: "Config.driver must have id: string" });
|
|
61
|
+
if (typeof driver["version"] !== "string") throw errorConfigValidation("driver.version", { why: "Config.driver must have version: string" });
|
|
62
|
+
if (typeof driver["familyId"] !== "string") throw errorConfigValidation("driver.familyId", { why: "Config.driver must have familyId: string" });
|
|
63
|
+
if (driver["familyId"] !== familyId) throw errorConfigValidation("driver.familyId", { why: `Config.driver.familyId must match Config.family.familyId (expected: ${familyId}, got: ${driver["familyId"]})` });
|
|
64
|
+
if (typeof driver["targetId"] !== "string") throw errorConfigValidation("driver.targetId", { why: "Config.driver must have targetId: string" });
|
|
65
|
+
if (driver["targetId"] !== expectedTargetId) throw errorConfigValidation("driver.targetId", { why: `Config.driver.targetId must match Config.target.targetId (expected: ${expectedTargetId}, got: ${driver["targetId"]})` });
|
|
66
|
+
if (typeof driver["create"] !== "function") throw errorConfigValidation("driver.create", { why: "Config.driver must have create: function" });
|
|
67
|
+
}
|
|
68
|
+
if (configObj["contract"] !== void 0) {
|
|
69
|
+
const contract = configObj["contract"];
|
|
70
|
+
if (!contract || typeof contract !== "object") throw errorConfigValidation("contract", { why: "Config.contract must be an object" });
|
|
71
|
+
if (!("source" in contract)) throw errorConfigValidation("contract.source", { why: "Config.contract.source is required when contract is provided" });
|
|
72
|
+
if (contract["output"] !== void 0 && typeof contract["output"] !== "string") throw errorConfigValidation("contract.output", { why: "Config.contract.output must be a string when provided" });
|
|
73
|
+
if (contract["types"] !== void 0 && typeof contract["types"] !== "string") throw errorConfigValidation("contract.types", { why: "Config.contract.types must be a string when provided" });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
export { validateConfig };
|
|
79
|
+
//# sourceMappingURL=config-validation.mjs.map
|
|
@@ -0,0 +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 errorConfigValidation('contract.output', {\n why: 'Config.contract.output must be a string when provided',\n });\n }\n if (contract['types'] !== undefined && typeof contract['types'] !== 'string') {\n throw errorConfigValidation('contract.types', {\n why: 'Config.contract.types must be a string when provided',\n });\n }\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ContractIR } from "@prisma-next/contract/ir";
|
|
2
|
+
import { TargetFamilyHook, TypeRenderEntry, TypesImportSpec } from "@prisma-next/contract/types";
|
|
3
|
+
import { OperationRegistry } from "@prisma-next/operations";
|
|
4
|
+
|
|
5
|
+
//#region src/emission/canonicalization.d.ts
|
|
6
|
+
declare function canonicalizeContract(ir: ContractIR & {
|
|
7
|
+
coreHash?: string;
|
|
8
|
+
profileHash?: string;
|
|
9
|
+
}): string;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/emission/types.d.ts
|
|
12
|
+
interface EmitOptions {
|
|
13
|
+
readonly outputDir: string;
|
|
14
|
+
readonly operationRegistry?: OperationRegistry;
|
|
15
|
+
readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
16
|
+
readonly operationTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
17
|
+
readonly extensionIds?: ReadonlyArray<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Normalized parameterized type renderers, keyed by codecId.
|
|
20
|
+
* These are extracted from descriptors and normalized during assembly.
|
|
21
|
+
*/
|
|
22
|
+
readonly parameterizedRenderers?: Map<string, TypeRenderEntry>;
|
|
23
|
+
/**
|
|
24
|
+
* Type imports for parameterized codecs.
|
|
25
|
+
* These are added to contract.d.ts alongside codec and operation type imports.
|
|
26
|
+
*/
|
|
27
|
+
readonly parameterizedTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
28
|
+
}
|
|
29
|
+
interface EmitResult {
|
|
30
|
+
readonly contractJson: string;
|
|
31
|
+
readonly contractDts: string;
|
|
32
|
+
readonly coreHash: string;
|
|
33
|
+
readonly profileHash: string;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/emission/emit.d.ts
|
|
37
|
+
declare function emit(ir: ContractIR, options: EmitOptions, targetFamily: TargetFamilyHook): Promise<EmitResult>;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/emission/hashing.d.ts
|
|
40
|
+
type ContractInput = {
|
|
41
|
+
schemaVersion: string;
|
|
42
|
+
targetFamily: string;
|
|
43
|
+
target: string;
|
|
44
|
+
models: Record<string, unknown>;
|
|
45
|
+
relations: Record<string, unknown>;
|
|
46
|
+
storage: Record<string, unknown>;
|
|
47
|
+
extensionPacks: Record<string, unknown>;
|
|
48
|
+
sources: Record<string, unknown>;
|
|
49
|
+
capabilities: Record<string, Record<string, boolean>>;
|
|
50
|
+
meta: Record<string, unknown>;
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
};
|
|
53
|
+
declare function computeCoreHash(contract: ContractInput): string;
|
|
54
|
+
declare function computeProfileHash(contract: ContractInput): string;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { type EmitOptions, type EmitResult, canonicalizeContract, computeCoreHash, computeProfileHash, emit };
|
|
57
|
+
//# sourceMappingURL=emission.d.mts.map
|
|
@@ -0,0 +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":";;;;;iBA6NgB,oBAAA,KACV;;;;;;UC3NW,WAAA;;+BAEc;EDwNf,SAAA,gBAAoB,CAAA,ECvNN,aDwNxB,CCxNsC,eDwN5B,CAAA;kCCvNkB,cAAc;0BACtB;;AAL1B;;;EAG8B,SAAA,sBAAA,CAAA,EAOM,GAPN,CAAA,MAAA,EAOkB,eAPlB,CAAA;EACkB;;;;EAMZ,SAAA,wBAAA,CAAA,EAKE,aALF,CAKgB,eALhB,CAAA;;AAKE,UAGrB,UAAA,CAHqB;EAAa,SAAA,YAAA,EAAA,MAAA;EAGlC,SAAA,WAAU,EAAA,MAAA;;;;;;iBCoBL,IAAA,KAChB,qBACK,2BACK,mBACb,QAAQ;;;KCzCN,aAAA;;;;UAIK;EHqNM,SAAA,EGpNH,MHoNG,CAAA,MAAoB,EAAA,OAAA,CAAA;WGnNzB;kBACO;WACP;EFTM,YAAA,EEUD,MFVY,CAAA,MAAA,EEUG,MFVH,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;EAEG,IAAA,EESvB,MFTuB,CAAA,MAAA,EAAA,OAAA,CAAA;EACa,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;CAAd;AACkB,iBEiBhC,eAAA,CFjBgC,QAAA,EEiBN,aFjBM,CAAA,EAAA,MAAA;AAAd,iBEkClB,kBAAA,CFlCkB,QAAA,EEkCW,aFlCX,CAAA,EAAA,MAAA"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { isArrayEqual } from "@prisma-next/utils/array-equal";
|
|
2
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
3
|
+
import { format } from "prettier";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
//#region src/emission/canonicalization.ts
|
|
7
|
+
const TOP_LEVEL_ORDER = [
|
|
8
|
+
"schemaVersion",
|
|
9
|
+
"canonicalVersion",
|
|
10
|
+
"targetFamily",
|
|
11
|
+
"target",
|
|
12
|
+
"coreHash",
|
|
13
|
+
"profileHash",
|
|
14
|
+
"models",
|
|
15
|
+
"storage",
|
|
16
|
+
"capabilities",
|
|
17
|
+
"extensionPacks",
|
|
18
|
+
"meta",
|
|
19
|
+
"sources"
|
|
20
|
+
];
|
|
21
|
+
function isDefaultValue(value) {
|
|
22
|
+
if (value === false) return true;
|
|
23
|
+
if (value === null) return false;
|
|
24
|
+
if (Array.isArray(value) && value.length === 0) return true;
|
|
25
|
+
if (typeof value === "object" && value !== null) return Object.keys(value).length === 0;
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
function omitDefaults(obj, path) {
|
|
29
|
+
if (obj === null || typeof obj !== "object") return obj;
|
|
30
|
+
if (Array.isArray(obj)) return obj.map((item) => omitDefaults(item, path));
|
|
31
|
+
const result = {};
|
|
32
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
33
|
+
const currentPath = [...path, key];
|
|
34
|
+
if (key === "_generated") continue;
|
|
35
|
+
if (key === "nullable" && value === false) continue;
|
|
36
|
+
if (key === "generated" && value === false) continue;
|
|
37
|
+
if (isDefaultValue(value)) {
|
|
38
|
+
const isRequiredModels = isArrayEqual(currentPath, ["models"]);
|
|
39
|
+
const isRequiredTables = isArrayEqual(currentPath, ["storage", "tables"]);
|
|
40
|
+
const isRequiredRelations = isArrayEqual(currentPath, ["relations"]);
|
|
41
|
+
const isRequiredExtensionPacks = isArrayEqual(currentPath, ["extensionPacks"]);
|
|
42
|
+
const isRequiredCapabilities = isArrayEqual(currentPath, ["capabilities"]);
|
|
43
|
+
const isRequiredMeta = isArrayEqual(currentPath, ["meta"]);
|
|
44
|
+
const isRequiredSources = isArrayEqual(currentPath, ["sources"]);
|
|
45
|
+
const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === "extensionPacks";
|
|
46
|
+
const isModelRelations = currentPath.length === 3 && isArrayEqual([currentPath[0], currentPath[2]], ["models", "relations"]);
|
|
47
|
+
const isTableUniques = currentPath.length === 4 && isArrayEqual([
|
|
48
|
+
currentPath[0],
|
|
49
|
+
currentPath[1],
|
|
50
|
+
currentPath[3]
|
|
51
|
+
], [
|
|
52
|
+
"storage",
|
|
53
|
+
"tables",
|
|
54
|
+
"uniques"
|
|
55
|
+
]);
|
|
56
|
+
const isTableIndexes = currentPath.length === 4 && isArrayEqual([
|
|
57
|
+
currentPath[0],
|
|
58
|
+
currentPath[1],
|
|
59
|
+
currentPath[3]
|
|
60
|
+
], [
|
|
61
|
+
"storage",
|
|
62
|
+
"tables",
|
|
63
|
+
"indexes"
|
|
64
|
+
]);
|
|
65
|
+
const isTableForeignKeys = currentPath.length === 4 && isArrayEqual([
|
|
66
|
+
currentPath[0],
|
|
67
|
+
currentPath[1],
|
|
68
|
+
currentPath[3]
|
|
69
|
+
], [
|
|
70
|
+
"storage",
|
|
71
|
+
"tables",
|
|
72
|
+
"foreignKeys"
|
|
73
|
+
]);
|
|
74
|
+
if (!isRequiredModels && !isRequiredTables && !isRequiredRelations && !isRequiredExtensionPacks && !isRequiredCapabilities && !isRequiredMeta && !isRequiredSources && !isExtensionNamespace && !isModelRelations && !isTableUniques && !isTableIndexes && !isTableForeignKeys) continue;
|
|
75
|
+
}
|
|
76
|
+
result[key] = omitDefaults(value, currentPath);
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
function sortObjectKeys(obj) {
|
|
81
|
+
if (obj === null || typeof obj !== "object") return obj;
|
|
82
|
+
if (Array.isArray(obj)) return obj.map((item) => sortObjectKeys(item));
|
|
83
|
+
const sorted = {};
|
|
84
|
+
const keys = Object.keys(obj).sort();
|
|
85
|
+
for (const key of keys) sorted[key] = sortObjectKeys(obj[key]);
|
|
86
|
+
return sorted;
|
|
87
|
+
}
|
|
88
|
+
function sortIndexesAndUniques(storage) {
|
|
89
|
+
if (!storage || typeof storage !== "object") return storage;
|
|
90
|
+
const storageObj = storage;
|
|
91
|
+
if (!storageObj.tables || typeof storageObj.tables !== "object") return storage;
|
|
92
|
+
const tables = storageObj.tables;
|
|
93
|
+
const result = { ...storageObj };
|
|
94
|
+
result.tables = {};
|
|
95
|
+
const sortedTableNames = Object.keys(tables).sort();
|
|
96
|
+
for (const tableName of sortedTableNames) {
|
|
97
|
+
const table = tables[tableName];
|
|
98
|
+
if (!table || typeof table !== "object") {
|
|
99
|
+
result.tables[tableName] = table;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const tableObj = table;
|
|
103
|
+
const sortedTable = { ...tableObj };
|
|
104
|
+
if (Array.isArray(tableObj.indexes)) sortedTable.indexes = [...tableObj.indexes].sort((a, b) => {
|
|
105
|
+
const nameA = a?.name || "";
|
|
106
|
+
const nameB = b?.name || "";
|
|
107
|
+
return nameA.localeCompare(nameB);
|
|
108
|
+
});
|
|
109
|
+
if (Array.isArray(tableObj.uniques)) sortedTable.uniques = [...tableObj.uniques].sort((a, b) => {
|
|
110
|
+
const nameA = a?.name || "";
|
|
111
|
+
const nameB = b?.name || "";
|
|
112
|
+
return nameA.localeCompare(nameB);
|
|
113
|
+
});
|
|
114
|
+
result.tables[tableName] = sortedTable;
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
function orderTopLevel(obj) {
|
|
119
|
+
const ordered = {};
|
|
120
|
+
const remaining = new Set(Object.keys(obj));
|
|
121
|
+
for (const key of TOP_LEVEL_ORDER) if (remaining.has(key)) {
|
|
122
|
+
ordered[key] = obj[key];
|
|
123
|
+
remaining.delete(key);
|
|
124
|
+
}
|
|
125
|
+
for (const key of Array.from(remaining).sort()) ordered[key] = obj[key];
|
|
126
|
+
return ordered;
|
|
127
|
+
}
|
|
128
|
+
function canonicalizeContract(ir) {
|
|
129
|
+
const normalized = {
|
|
130
|
+
schemaVersion: ir.schemaVersion,
|
|
131
|
+
targetFamily: ir.targetFamily,
|
|
132
|
+
target: ir.target,
|
|
133
|
+
models: ir.models,
|
|
134
|
+
relations: ir.relations,
|
|
135
|
+
storage: ir.storage,
|
|
136
|
+
extensionPacks: ir.extensionPacks,
|
|
137
|
+
capabilities: ir.capabilities,
|
|
138
|
+
meta: ir.meta,
|
|
139
|
+
sources: ir.sources
|
|
140
|
+
};
|
|
141
|
+
if (ir.coreHash !== void 0) normalized.coreHash = ir.coreHash;
|
|
142
|
+
if (ir.profileHash !== void 0) normalized.profileHash = ir.profileHash;
|
|
143
|
+
const withDefaultsOmitted = omitDefaults(normalized, []);
|
|
144
|
+
const withSortedIndexes = sortIndexesAndUniques(withDefaultsOmitted.storage);
|
|
145
|
+
const withOrderedTopLevel = orderTopLevel(sortObjectKeys({
|
|
146
|
+
...withDefaultsOmitted,
|
|
147
|
+
storage: withSortedIndexes
|
|
148
|
+
}));
|
|
149
|
+
return JSON.stringify(withOrderedTopLevel, null, 2);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region src/emission/hashing.ts
|
|
154
|
+
function computeHash(content) {
|
|
155
|
+
const hash = createHash("sha256");
|
|
156
|
+
hash.update(content);
|
|
157
|
+
return `sha256:${hash.digest("hex")}`;
|
|
158
|
+
}
|
|
159
|
+
function computeCoreHash(contract) {
|
|
160
|
+
return computeHash(canonicalizeContract({
|
|
161
|
+
schemaVersion: contract.schemaVersion,
|
|
162
|
+
targetFamily: contract.targetFamily,
|
|
163
|
+
target: contract.target,
|
|
164
|
+
models: contract.models,
|
|
165
|
+
relations: contract.relations,
|
|
166
|
+
storage: contract.storage,
|
|
167
|
+
extensionPacks: contract.extensionPacks,
|
|
168
|
+
sources: contract.sources,
|
|
169
|
+
capabilities: contract.capabilities,
|
|
170
|
+
meta: contract.meta
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
function computeProfileHash(contract) {
|
|
174
|
+
return computeHash(canonicalizeContract({
|
|
175
|
+
schemaVersion: contract.schemaVersion,
|
|
176
|
+
targetFamily: contract.targetFamily,
|
|
177
|
+
target: contract.target,
|
|
178
|
+
models: {},
|
|
179
|
+
relations: {},
|
|
180
|
+
storage: {},
|
|
181
|
+
extensionPacks: {},
|
|
182
|
+
capabilities: contract.capabilities,
|
|
183
|
+
meta: {},
|
|
184
|
+
sources: {}
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/emission/emit.ts
|
|
190
|
+
function validateCoreStructure(ir) {
|
|
191
|
+
if (!ir.targetFamily) throw new Error("ContractIR must have targetFamily");
|
|
192
|
+
if (!ir.target) throw new Error("ContractIR must have target");
|
|
193
|
+
if (!ir.schemaVersion) throw new Error("ContractIR must have schemaVersion");
|
|
194
|
+
if (!ir.models || typeof ir.models !== "object") throw new Error("ContractIR must have models");
|
|
195
|
+
if (!ir.storage || typeof ir.storage !== "object") throw new Error("ContractIR must have storage");
|
|
196
|
+
if (!ir.relations || typeof ir.relations !== "object") throw new Error("ContractIR must have relations");
|
|
197
|
+
if (!ir.extensionPacks || typeof ir.extensionPacks !== "object") throw new Error("ContractIR must have extensionPacks");
|
|
198
|
+
if (!ir.capabilities || typeof ir.capabilities !== "object") throw new Error("ContractIR must have capabilities");
|
|
199
|
+
if (!ir.meta || typeof ir.meta !== "object") throw new Error("ContractIR must have meta");
|
|
200
|
+
if (!ir.sources || typeof ir.sources !== "object") throw new Error("ContractIR must have sources");
|
|
201
|
+
}
|
|
202
|
+
async function emit(ir, options, targetFamily) {
|
|
203
|
+
const { operationRegistry, codecTypeImports, operationTypeImports, extensionIds, parameterizedRenderers, parameterizedTypeImports } = options;
|
|
204
|
+
validateCoreStructure(ir);
|
|
205
|
+
const ctx = {
|
|
206
|
+
...ifDefined("operationRegistry", operationRegistry),
|
|
207
|
+
...ifDefined("codecTypeImports", codecTypeImports),
|
|
208
|
+
...ifDefined("operationTypeImports", operationTypeImports),
|
|
209
|
+
...ifDefined("extensionIds", extensionIds)
|
|
210
|
+
};
|
|
211
|
+
targetFamily.validateTypes(ir, ctx);
|
|
212
|
+
targetFamily.validateStructure(ir);
|
|
213
|
+
const contractJson = {
|
|
214
|
+
schemaVersion: ir.schemaVersion,
|
|
215
|
+
targetFamily: ir.targetFamily,
|
|
216
|
+
target: ir.target,
|
|
217
|
+
models: ir.models,
|
|
218
|
+
relations: ir.relations,
|
|
219
|
+
storage: ir.storage,
|
|
220
|
+
extensionPacks: ir.extensionPacks,
|
|
221
|
+
capabilities: ir.capabilities,
|
|
222
|
+
meta: ir.meta,
|
|
223
|
+
sources: ir.sources
|
|
224
|
+
};
|
|
225
|
+
const coreHash = computeCoreHash(contractJson);
|
|
226
|
+
const profileHash = computeProfileHash(contractJson);
|
|
227
|
+
const contractWithHashes = {
|
|
228
|
+
...ir,
|
|
229
|
+
schemaVersion: contractJson.schemaVersion,
|
|
230
|
+
coreHash,
|
|
231
|
+
profileHash
|
|
232
|
+
};
|
|
233
|
+
const contractJsonWithMeta = {
|
|
234
|
+
...JSON.parse(canonicalizeContract(contractWithHashes)),
|
|
235
|
+
_generated: {
|
|
236
|
+
warning: "⚠️ GENERATED FILE - DO NOT EDIT",
|
|
237
|
+
message: "This file is automatically generated by \"prisma-next contract emit\".",
|
|
238
|
+
regenerate: "To regenerate, run: prisma-next contract emit"
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
const contractJsonString = JSON.stringify(contractJsonWithMeta, null, 2);
|
|
242
|
+
const generateOptions = parameterizedRenderers || parameterizedTypeImports ? {
|
|
243
|
+
...ifDefined("parameterizedRenderers", parameterizedRenderers),
|
|
244
|
+
...ifDefined("parameterizedTypeImports", parameterizedTypeImports)
|
|
245
|
+
} : void 0;
|
|
246
|
+
return {
|
|
247
|
+
contractJson: contractJsonString,
|
|
248
|
+
contractDts: await format(targetFamily.generateContractTypes(ir, codecTypeImports ?? [], operationTypeImports ?? [], generateOptions), {
|
|
249
|
+
parser: "typescript",
|
|
250
|
+
singleQuote: true,
|
|
251
|
+
semi: true,
|
|
252
|
+
printWidth: 100
|
|
253
|
+
}),
|
|
254
|
+
coreHash,
|
|
255
|
+
profileHash
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
//#endregion
|
|
260
|
+
export { canonicalizeContract, computeCoreHash, computeProfileHash, emit };
|
|
261
|
+
//# sourceMappingURL=emission.mjs.map
|