@prisma-next/sql-contract 0.3.0-dev.135 → 0.3.0-dev.146

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.
@@ -1,3 +1,4 @@
1
+ import { ContractValidationError } from "@prisma-next/contract/validate-contract";
1
2
  import { type } from "arktype";
2
3
 
3
4
  //#region src/validators.ts
@@ -34,6 +35,7 @@ const ExecutionMutationDefaultSchema = type({
34
35
  });
35
36
  const ExecutionSchema = type({
36
37
  "+": "reject",
38
+ executionHash: "string",
37
39
  mutations: {
38
40
  "+": "reject",
39
41
  defaults: ExecutionMutationDefaultSchema.array().readonly()
@@ -94,12 +96,37 @@ const StorageTableSchema = type({
94
96
  });
95
97
  const StorageSchema = type({
96
98
  "+": "reject",
99
+ storageHash: "string",
97
100
  tables: type({ "[string]": StorageTableSchema }),
98
101
  "types?": type({ "[string]": StorageTypeInstanceSchema })
99
102
  });
103
+ function isPlainRecord(value) {
104
+ return typeof value === "object" && value !== null && !Array.isArray(value);
105
+ }
106
+ function isContractFieldType(value) {
107
+ if (!isPlainRecord(value)) return false;
108
+ const kind = value["kind"];
109
+ if (kind === "scalar") {
110
+ if (typeof value["codecId"] !== "string") return false;
111
+ const typeParams = value["typeParams"];
112
+ if (typeParams !== void 0 && !isPlainRecord(typeParams)) return false;
113
+ return true;
114
+ }
115
+ if (kind === "valueObject") return typeof value["name"] === "string";
116
+ if (kind === "union") {
117
+ const members = value["members"];
118
+ if (!Array.isArray(members)) return false;
119
+ return members.every((m) => isContractFieldType(m));
120
+ }
121
+ return false;
122
+ }
123
+ const ContractFieldTypeSchema = type("unknown").narrow((value, ctx) => isContractFieldType(value) ? true : ctx.mustBe("scalar, valueObject, or union field type"));
100
124
  const ModelFieldSchema = type({
101
- "nullable?": "boolean",
102
- "codecId?": "string"
125
+ "+": "reject",
126
+ nullable: "boolean",
127
+ type: ContractFieldTypeSchema,
128
+ "many?": "true",
129
+ "dict?": "true"
103
130
  });
104
131
  const ModelStorageFieldSchema = type({
105
132
  column: "string",
@@ -121,20 +148,16 @@ const ModelSchema = type({
121
148
  const ContractMetaSchema = type({ "[string]": "unknown" });
122
149
  const SqlContractSchema = type({
123
150
  "+": "reject",
124
- "schemaVersion?": "'1'",
125
151
  target: "string",
126
152
  targetFamily: "'sql'",
127
153
  "coreHash?": "string",
128
- storageHash: "string",
129
- "executionHash?": "string",
130
- "profileHash?": "string",
131
- "_generated?": "Record<string, unknown>",
154
+ profileHash: "string",
132
155
  "capabilities?": "Record<string, Record<string, boolean>>",
133
156
  "extensionPacks?": "Record<string, unknown>",
134
157
  "meta?": ContractMetaSchema,
135
- "sources?": "Record<string, unknown>",
136
158
  "roots?": "Record<string, string>",
137
159
  models: type({ "[string]": ModelSchema }),
160
+ "valueObjects?": "Record<string, unknown>",
138
161
  storage: StorageSchema,
139
162
  "execution?": ExecutionSchema
140
163
  });
@@ -162,30 +185,21 @@ function validateModel(value) {
162
185
  return result;
163
186
  }
164
187
  /**
165
- * Validates the structural shape of a SqlContract using Arktype.
166
- *
167
- * **Responsibility: Validation Only**
168
- * This function validates that the contract has the correct structure and types.
169
- * It does NOT normalize the contract - normalization must happen in the contract builder.
188
+ * Validates the structural shape of an SQL contract using Arktype.
170
189
  *
171
- * The contract passed to this function must already be normalized (all required fields present).
172
- * If normalization is needed, it should be done by the contract builder before calling this function.
173
- *
174
- * This ensures all required fields are present and have the correct types.
190
+ * Ensures all required fields are present and have the correct types,
191
+ * including SQL-specific storage structure (tables, columns, constraints).
175
192
  *
176
193
  * @param value - The contract value to validate (typically from a JSON import)
177
194
  * @returns The validated contract if structure is valid
178
- * @throws Error if the contract structure is invalid
195
+ * @throws ContractValidationError if the contract structure is invalid
179
196
  */
180
197
  function validateSqlContract(value) {
181
- if (typeof value !== "object" || value === null) throw new Error("Contract structural validation failed: value must be an object");
198
+ if (typeof value !== "object" || value === null) throw new ContractValidationError("Contract structural validation failed: value must be an object", "structural");
182
199
  const rawValue = value;
183
- if (rawValue.targetFamily !== void 0 && rawValue.targetFamily !== "sql") throw new Error(`Unsupported target family: ${rawValue.targetFamily}`);
200
+ if (rawValue.targetFamily !== void 0 && rawValue.targetFamily !== "sql") throw new ContractValidationError(`Unsupported target family: ${rawValue.targetFamily}`, "structural");
184
201
  const contractResult = SqlContractSchema(value);
185
- if (contractResult instanceof type.errors) {
186
- const messages = contractResult.map((p) => p.message).join("; ");
187
- throw new Error(`Contract structural validation failed: ${messages}`);
188
- }
202
+ if (contractResult instanceof type.errors) throw new ContractValidationError(`Contract structural validation failed: ${contractResult.map((p) => p.message).join("; ")}`, "structural");
189
203
  return contractResult;
190
204
  }
191
205
  /**
@@ -264,4 +278,4 @@ function validateStorageSemantics(storage) {
264
278
 
265
279
  //#endregion
266
280
  export { ForeignKeySchema as a, validateModel as c, validateStorageSemantics as d, ForeignKeyReferencesSchema as i, validateSqlContract as l, ColumnDefaultLiteralSchema as n, IndexSchema as o, ColumnDefaultSchema as r, ReferentialActionSchema as s, ColumnDefaultFunctionSchema as t, validateStorage as u };
267
- //# sourceMappingURL=validators-i9MX9Dti.mjs.map
281
+ //# sourceMappingURL=validators-BjZ6lOS1.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators-BjZ6lOS1.mjs","names":["errors: string[]"],"sources":["../src/validators.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport { ContractValidationError } from '@prisma-next/contract/validate-contract';\nimport { type } from 'arktype';\nimport type {\n ForeignKey,\n ForeignKeyReferences,\n PrimaryKey,\n ReferentialAction,\n SqlStorage,\n StorageTypeInstance,\n UniqueConstraint,\n} from './types';\n\ntype ColumnDefaultLiteral = {\n readonly kind: 'literal';\n readonly value: string | number | boolean | Record<string, unknown> | unknown[] | null;\n};\ntype ColumnDefaultFunction = { readonly kind: 'function'; readonly expression: string };\nconst literalKindSchema = type(\"'literal'\");\nconst functionKindSchema = type(\"'function'\");\nconst generatorKindSchema = type(\"'generator'\");\nconst generatorIdSchema = type('string').narrow((value, ctx) => {\n return /^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(value) ? true : ctx.mustBe('a flat generator id');\n});\n\nexport const ColumnDefaultLiteralSchema = type.declare<ColumnDefaultLiteral>().type({\n kind: literalKindSchema,\n value: 'string | number | boolean | null | unknown[] | Record<string, unknown>',\n});\n\nexport const ColumnDefaultFunctionSchema = type.declare<ColumnDefaultFunction>().type({\n kind: functionKindSchema,\n expression: 'string',\n});\n\nexport const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);\n\nconst ExecutionMutationDefaultValueSchema = type({\n '+': 'reject',\n kind: generatorKindSchema,\n id: generatorIdSchema,\n 'params?': 'Record<string, unknown>',\n});\n\nconst ExecutionMutationDefaultSchema = type({\n '+': 'reject',\n ref: {\n '+': 'reject',\n table: 'string',\n column: 'string',\n },\n 'onCreate?': ExecutionMutationDefaultValueSchema,\n 'onUpdate?': ExecutionMutationDefaultValueSchema,\n});\n\nconst ExecutionSchema = type({\n '+': 'reject',\n executionHash: 'string',\n mutations: {\n '+': 'reject',\n defaults: ExecutionMutationDefaultSchema.array().readonly(),\n },\n});\n\nconst StorageColumnSchema = type({\n '+': 'reject',\n nativeType: 'string',\n codecId: 'string',\n nullable: 'boolean',\n 'typeParams?': 'Record<string, unknown>',\n 'typeRef?': 'string',\n 'default?': ColumnDefaultSchema,\n}).narrow((col, ctx) => {\n if (col.typeParams !== undefined && col.typeRef !== undefined) {\n return ctx.mustBe('a column with either typeParams or typeRef, not both');\n }\n return true;\n});\n\nconst StorageTypeInstanceSchema = type.declare<StorageTypeInstance>().type({\n codecId: 'string',\n nativeType: 'string',\n typeParams: 'Record<string, unknown>',\n});\n\nconst PrimaryKeySchema = type.declare<PrimaryKey>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nconst UniqueConstraintSchema = type.declare<UniqueConstraint>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nexport const IndexSchema = type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n 'using?': 'string',\n 'config?': 'Record<string, unknown>',\n});\n\nexport const ForeignKeyReferencesSchema = type.declare<ForeignKeyReferences>().type({\n table: 'string',\n columns: type.string.array().readonly(),\n});\n\nexport const ReferentialActionSchema = type\n .declare<ReferentialAction>()\n .type(\"'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'\");\n\nexport const ForeignKeySchema = type.declare<ForeignKey>().type({\n columns: type.string.array().readonly(),\n references: ForeignKeyReferencesSchema,\n 'name?': 'string',\n 'onDelete?': ReferentialActionSchema,\n 'onUpdate?': ReferentialActionSchema,\n constraint: 'boolean',\n index: 'boolean',\n});\n\nconst StorageTableSchema = type({\n '+': 'reject',\n columns: type({ '[string]': StorageColumnSchema }),\n 'primaryKey?': PrimaryKeySchema,\n uniques: UniqueConstraintSchema.array().readonly(),\n indexes: IndexSchema.array().readonly(),\n foreignKeys: ForeignKeySchema.array().readonly(),\n});\n\nconst StorageSchema = type({\n '+': 'reject',\n storageHash: 'string',\n tables: type({ '[string]': StorageTableSchema }),\n 'types?': type({ '[string]': StorageTypeInstanceSchema }),\n});\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isContractFieldType(value: unknown): boolean {\n if (!isPlainRecord(value)) return false;\n const kind = value['kind'];\n if (kind === 'scalar') {\n if (typeof value['codecId'] !== 'string') return false;\n const typeParams = value['typeParams'];\n if (typeParams !== undefined && !isPlainRecord(typeParams)) return false;\n return true;\n }\n if (kind === 'valueObject') {\n return typeof value['name'] === 'string';\n }\n if (kind === 'union') {\n const members = value['members'];\n if (!Array.isArray(members)) return false;\n return members.every((m) => isContractFieldType(m));\n }\n return false;\n}\n\nconst ContractFieldTypeSchema = type('unknown').narrow((value, ctx) =>\n isContractFieldType(value) ? true : ctx.mustBe('scalar, valueObject, or union field type'),\n);\n\nconst ModelFieldSchema = type({\n '+': 'reject',\n nullable: 'boolean',\n type: ContractFieldTypeSchema,\n 'many?': 'true',\n 'dict?': 'true',\n});\n\nconst ModelStorageFieldSchema = type({\n column: 'string',\n 'codecId?': 'string',\n 'nullable?': 'boolean',\n});\n\nconst ModelStorageSchema = type({\n table: 'string',\n fields: type({ '[string]': ModelStorageFieldSchema }),\n});\n\nconst ModelSchema = type({\n storage: ModelStorageSchema,\n 'fields?': type({ '[string]': ModelFieldSchema }),\n 'relations?': type({ '[string]': 'unknown' }),\n 'discriminator?': 'unknown',\n 'variants?': 'unknown',\n 'base?': 'string',\n 'owner?': 'string',\n});\n\nconst ContractMetaSchema = type({\n '[string]': 'unknown',\n});\n\nconst SqlContractSchema = type({\n '+': 'reject',\n target: 'string',\n targetFamily: \"'sql'\",\n 'coreHash?': 'string',\n profileHash: 'string',\n 'capabilities?': 'Record<string, Record<string, boolean>>',\n 'extensionPacks?': 'Record<string, unknown>',\n 'meta?': ContractMetaSchema,\n 'roots?': 'Record<string, string>',\n models: type({ '[string]': ModelSchema }),\n 'valueObjects?': 'Record<string, unknown>',\n storage: StorageSchema,\n 'execution?': ExecutionSchema,\n});\n\n// NOTE: StorageColumnSchema, StorageTableSchema, and StorageSchema use bare type()\n// instead of type.declare<T>().type() because the ColumnDefault union's value field\n// includes bigint | Date (runtime-only types after decoding) which cannot be expressed\n// in Arktype's JSON validation DSL. The `as SqlStorage` cast in validateStorage() bridges\n// the gap between the JSON-safe Arktype output and the runtime TypeScript type.\n// See decodeContractDefaults() in validate.ts for the decoding step.\n\n/**\n * Validates the structural shape of SqlStorage using Arktype.\n *\n * @param value - The storage value to validate\n * @returns The validated storage if structure is valid\n * @throws Error if the storage structure is invalid\n */\nexport function validateStorage(value: unknown): SqlStorage {\n const result = StorageSchema(value);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Storage validation failed: ${messages}`);\n }\n return result as SqlStorage;\n}\n\nexport function validateModel(value: unknown): unknown {\n const result = ModelSchema(value);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Model validation failed: ${messages}`);\n }\n return result;\n}\n\n/**\n * Validates the structural shape of an SQL contract using Arktype.\n *\n * Ensures all required fields are present and have the correct types,\n * including SQL-specific storage structure (tables, columns, constraints).\n *\n * @param value - The contract value to validate (typically from a JSON import)\n * @returns The validated contract if structure is valid\n * @throws ContractValidationError if the contract structure is invalid\n */\nexport function validateSqlContract<T extends Contract<SqlStorage>>(value: unknown): T {\n if (typeof value !== 'object' || value === null) {\n throw new ContractValidationError(\n 'Contract structural validation failed: value must be an object',\n 'structural',\n );\n }\n\n const rawValue = value as { targetFamily?: string };\n if (rawValue.targetFamily !== undefined && rawValue.targetFamily !== 'sql') {\n throw new ContractValidationError(\n `Unsupported target family: ${rawValue.targetFamily}`,\n 'structural',\n );\n }\n\n const contractResult = SqlContractSchema(value);\n\n if (contractResult instanceof type.errors) {\n const messages = contractResult.map((p: { message: string }) => p.message).join('; ');\n throw new ContractValidationError(\n `Contract structural validation failed: ${messages}`,\n 'structural',\n );\n }\n\n // Arktype's inferred output type differs from T due to exactOptionalPropertyTypes\n // and branded hash types — the runtime value is structurally compatible after validation\n return contractResult as unknown as T;\n}\n\n/**\n * Validates semantic constraints on SqlStorage that cannot be expressed in Arktype schemas.\n *\n * Returns an array of human-readable error strings. Empty array = valid.\n *\n * Currently checks:\n * - duplicate named primary key / unique / index / foreign key objects within a table\n * - duplicate unique, index, or foreign key declarations within a table\n * - `setNull` referential action on a non-nullable FK column (would fail at runtime)\n * - `setDefault` referential action on a non-nullable FK column without a DEFAULT (would fail at runtime)\n */\nexport function validateStorageSemantics(storage: SqlStorage): string[] {\n const errors: string[] = [];\n\n for (const [tableName, table] of Object.entries(storage.tables)) {\n const namedObjects = new Map<string, string[]>();\n const registerNamedObject = (kind: string, name: string | undefined) => {\n if (!name) return;\n namedObjects.set(name, [...(namedObjects.get(name) ?? []), kind]);\n };\n\n registerNamedObject('primary key', table.primaryKey?.name);\n for (const unique of table.uniques) {\n registerNamedObject('unique constraint', unique.name);\n }\n for (const index of table.indexes) {\n registerNamedObject('index', index.name);\n }\n for (const fk of table.foreignKeys) {\n registerNamedObject('foreign key', fk.name);\n }\n\n for (const [name, kinds] of namedObjects) {\n if (kinds.length > 1) {\n errors.push(\n `Table \"${tableName}\": named object \"${name}\" is declared multiple times (${kinds.join(', ')})`,\n );\n }\n }\n\n const seenUniqueDefinitions = new Set<string>();\n for (const unique of table.uniques) {\n const signature = JSON.stringify({ columns: unique.columns });\n if (seenUniqueDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate unique constraint definition on columns [${unique.columns.join(', ')}]`,\n );\n continue;\n }\n seenUniqueDefinitions.add(signature);\n }\n\n const seenIndexDefinitions = new Set<string>();\n for (const index of table.indexes) {\n const signature = JSON.stringify({\n columns: index.columns,\n using: index.using ?? null,\n config: index.config ?? null,\n });\n if (seenIndexDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate index definition on columns [${index.columns.join(', ')}]`,\n );\n continue;\n }\n seenIndexDefinitions.add(signature);\n }\n\n const seenForeignKeyDefinitions = new Set<string>();\n for (const fk of table.foreignKeys) {\n const signature = JSON.stringify({\n columns: fk.columns,\n references: fk.references,\n onDelete: fk.onDelete ?? null,\n onUpdate: fk.onUpdate ?? null,\n constraint: fk.constraint,\n index: fk.index,\n });\n if (seenForeignKeyDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate foreign key definition on columns [${fk.columns.join(', ')}]`,\n );\n continue;\n }\n seenForeignKeyDefinitions.add(signature);\n }\n\n for (const fk of table.foreignKeys) {\n for (const colName of fk.columns) {\n const column = table.columns[colName];\n if (!column) continue;\n\n if (fk.onDelete === 'setNull' && !column.nullable) {\n errors.push(\n `Table \"${tableName}\": onDelete setNull on foreign key column \"${colName}\" which is NOT NULL`,\n );\n }\n if (fk.onUpdate === 'setNull' && !column.nullable) {\n errors.push(\n `Table \"${tableName}\": onUpdate setNull on foreign key column \"${colName}\" which is NOT NULL`,\n );\n }\n if (fk.onDelete === 'setDefault' && !column.nullable && column.default === undefined) {\n errors.push(\n `Table \"${tableName}\": onDelete setDefault on foreign key column \"${colName}\" which is NOT NULL and has no DEFAULT`,\n );\n }\n if (fk.onUpdate === 'setDefault' && !column.nullable && column.default === undefined) {\n errors.push(\n `Table \"${tableName}\": onUpdate setDefault on foreign key column \"${colName}\" which is NOT NULL and has no DEFAULT`,\n );\n }\n }\n }\n }\n\n return errors;\n}\n"],"mappings":";;;;AAkBA,MAAM,oBAAoB,KAAK,YAAY;AAC3C,MAAM,qBAAqB,KAAK,aAAa;AAC7C,MAAM,sBAAsB,KAAK,cAAc;AAC/C,MAAM,oBAAoB,KAAK,SAAS,CAAC,QAAQ,OAAO,QAAQ;AAC9D,QAAO,8BAA8B,KAAK,MAAM,GAAG,OAAO,IAAI,OAAO,sBAAsB;EAC3F;AAEF,MAAa,6BAA6B,KAAK,SAA+B,CAAC,KAAK;CAClF,MAAM;CACN,OAAO;CACR,CAAC;AAEF,MAAa,8BAA8B,KAAK,SAAgC,CAAC,KAAK;CACpF,MAAM;CACN,YAAY;CACb,CAAC;AAEF,MAAa,sBAAsB,2BAA2B,GAAG,4BAA4B;AAE7F,MAAM,sCAAsC,KAAK;CAC/C,KAAK;CACL,MAAM;CACN,IAAI;CACJ,WAAW;CACZ,CAAC;AAEF,MAAM,iCAAiC,KAAK;CAC1C,KAAK;CACL,KAAK;EACH,KAAK;EACL,OAAO;EACP,QAAQ;EACT;CACD,aAAa;CACb,aAAa;CACd,CAAC;AAEF,MAAM,kBAAkB,KAAK;CAC3B,KAAK;CACL,eAAe;CACf,WAAW;EACT,KAAK;EACL,UAAU,+BAA+B,OAAO,CAAC,UAAU;EAC5D;CACF,CAAC;AAEF,MAAM,sBAAsB,KAAK;CAC/B,KAAK;CACL,YAAY;CACZ,SAAS;CACT,UAAU;CACV,eAAe;CACf,YAAY;CACZ,YAAY;CACb,CAAC,CAAC,QAAQ,KAAK,QAAQ;AACtB,K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G;IACf,OAAO,GAAG;IACX,CAAC;AACF,OAAI,0BAA0B,IAAI,UAAU,EAAE;AAC5C,WAAO,KACL,UAAU,UAAU,kDAAkD,GAAG,QAAQ,KAAK,KAAK,CAAC,GAC7F;AACD;;AAEF,6BAA0B,IAAI,UAAU;;AAG1C,OAAK,MAAM,MAAM,MAAM,YACrB,MAAK,MAAM,WAAW,GAAG,SAAS;GAChC,MAAM,SAAS,MAAM,QAAQ;AAC7B,OAAI,CAAC,OAAQ;AAEb,OAAI,GAAG,aAAa,aAAa,CAAC,OAAO,SACvC,QAAO,KACL,UAAU,UAAU,6CAA6C,QAAQ,qBAC1E;AAEH,OAAI,GAAG,aAAa,aAAa,CAAC,OAAO,SACvC,QAAO,KACL,UAAU,UAAU,6CAA6C,QAAQ,qBAC1E;AAEH,OAAI,GAAG,aAAa,gBAAgB,CAAC,OAAO,YAAY,OAAO,YAAY,OACzE,QAAO,KACL,UAAU,UAAU,gDAAgD,QAAQ,wCAC7E;AAEH,OAAI,GAAG,aAAa,gBAAgB,CAAC,OAAO,YAAY,OAAO,YAAY,OACzE,QAAO,KACL,UAAU,UAAU,gDAAgD,QAAQ,wCAC7E;;;AAMT,QAAO"}
@@ -1,4 +1,5 @@
1
- import { E as SqlStorage, d as ForeignKeyReferences, l as ForeignKey, v as ReferentialAction, x as SqlContract } from "./types-D6K16_9R.mjs";
1
+ import { T as SqlStorage, f as ForeignKeyReferences, u as ForeignKey, y as ReferentialAction } from "./types-D6o_FjCJ.mjs";
2
+ import { Contract } from "@prisma-next/contract/types";
2
3
  import * as arktype_internal_variants_object_ts0 from "arktype/internal/variants/object.ts";
3
4
  import * as arktype_internal_variants_string_ts0 from "arktype/internal/variants/string.ts";
4
5
 
@@ -33,22 +34,16 @@ declare const ForeignKeySchema: arktype_internal_variants_object_ts0.ObjectType<
33
34
  declare function validateStorage(value: unknown): SqlStorage;
34
35
  declare function validateModel(value: unknown): unknown;
35
36
  /**
36
- * Validates the structural shape of a SqlContract using Arktype.
37
+ * Validates the structural shape of an SQL contract using Arktype.
37
38
  *
38
- * **Responsibility: Validation Only**
39
- * This function validates that the contract has the correct structure and types.
40
- * It does NOT normalize the contract - normalization must happen in the contract builder.
41
- *
42
- * The contract passed to this function must already be normalized (all required fields present).
43
- * If normalization is needed, it should be done by the contract builder before calling this function.
44
- *
45
- * This ensures all required fields are present and have the correct types.
39
+ * Ensures all required fields are present and have the correct types,
40
+ * including SQL-specific storage structure (tables, columns, constraints).
46
41
  *
47
42
  * @param value - The contract value to validate (typically from a JSON import)
48
43
  * @returns The validated contract if structure is valid
49
- * @throws Error if the contract structure is invalid
44
+ * @throws ContractValidationError if the contract structure is invalid
50
45
  */
51
- declare function validateSqlContract<T extends SqlContract<SqlStorage>>(value: unknown): T;
46
+ declare function validateSqlContract<T extends Contract<SqlStorage>>(value: unknown): T;
52
47
  /**
53
48
  * Validates semantic constraints on SqlStorage that cannot be expressed in Arktype schemas.
54
49
  *
@@ -1 +1 @@
1
- {"version":3,"file":"validators.d.mts","names":[],"sources":["../src/validators.ts"],"sourcesContent":[],"mappings":";;;;;KAYK,oBAAA;;8CAEyC;;AAJ7B,KAMZ,qBAAA,GAJoB;EAIpB,SAAA,IAAA,EAAA,UAAqB;EAQb,SAAA,UAAA,EAAA,MAAA;AAKb,CAAA;AAKa,cAVA,0BAUgF,EAVtD,oCAAA,CAAA,UAUsD,CAVtD,oBAUsD,EAAA,CAAA,CAAA,CAAA;AAA7D,cALnB,2BAKmB,EALQ,oCAAA,CAAA,UAKR,CALQ,qBAKR,EAAA,CAAA,CAAA,CAAA;AAAA,cAAnB,mBAAmB,EAAA,oCAAA,CAAA,UAAA,CAAA,oBAAA,GAAA,qBAAA,EAAA,CAAA,CAAA,CAAA;AAAA,cA2DnB,WA3DmB,EAgE9B,oCAAA,CALsB,UA3DQ,CAAA;EAAA,OAAA,EAAA,SAAA,MAAA,EAAA;EA2DnB,IAAA,CAAA,EAAA,MAAA;EAOA,KAAA,CAAA,EAAA,MAAA;EAK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CAAA,CAAA;AAqHG,cA9HH,0BA8H8C,EA9HpB,oCAAA,CAAA,UA8HoB,CA9HpB,oBA8HoB,EAAA,CAAA,CAAA,CAAA;AAS3C,cAlIH,uBAkIgB,EAlIO,oCAAA,CAAA,UAkIP,CAlIO,iBAkIP,EAAA,CAAA,CAAA,CAAA;AAmBb,cAjJH,gBAiJsB,EAjJN,oCAAA,CAAA,UAiJM,CAjJN,UAiJM,EAAA,CAAA,CAAA,CAAA;;;;;AA0CnC;;;iBAtEgB,eAAA,kBAAiC;iBASjC,aAAA;;;;;;;;;;;iBAmBA,8BAA8B,SAAS,8BAA8B;;;;;;;;;;;;iBA0CrE,wBAAA,UAAkC"}
@@ -1,3 +1,3 @@
1
- import { a as ForeignKeySchema, c as validateModel, d as validateStorageSemantics, i as ForeignKeyReferencesSchema, l as validateSqlContract, n as ColumnDefaultLiteralSchema, o as IndexSchema, r as ColumnDefaultSchema, s as ReferentialActionSchema, t as ColumnDefaultFunctionSchema, u as validateStorage } from "./validators-i9MX9Dti.mjs";
1
+ import { a as ForeignKeySchema, c as validateModel, d as validateStorageSemantics, i as ForeignKeyReferencesSchema, l as validateSqlContract, n as ColumnDefaultLiteralSchema, o as IndexSchema, r as ColumnDefaultSchema, s as ReferentialActionSchema, t as ColumnDefaultFunctionSchema, u as validateStorage } from "./validators-BjZ6lOS1.mjs";
2
2
 
3
3
  export { ColumnDefaultFunctionSchema, ColumnDefaultLiteralSchema, ColumnDefaultSchema, ForeignKeyReferencesSchema, ForeignKeySchema, IndexSchema, ReferentialActionSchema, validateModel, validateSqlContract, validateStorage, validateStorageSemantics };
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "@prisma-next/sql-contract",
3
- "version": "0.3.0-dev.135",
3
+ "version": "0.3.0-dev.146",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "SQL contract types, validators, and IR factories for Prisma Next",
7
7
  "dependencies": {
8
8
  "arktype": "^2.1.25",
9
- "@prisma-next/contract": "0.3.0-dev.135"
9
+ "@prisma-next/contract": "0.3.0-dev.146",
10
+ "@prisma-next/framework-components": "0.3.0-dev.146"
10
11
  },
11
12
  "devDependencies": {
12
13
  "tsdown": "0.18.4",
13
14
  "typescript": "5.9.3",
14
15
  "vitest": "4.0.17",
15
- "@prisma-next/test-utils": "0.0.1",
16
16
  "@prisma-next/tsdown": "0.0.0",
17
- "@prisma-next/tsconfig": "0.0.0"
17
+ "@prisma-next/tsconfig": "0.0.0",
18
+ "@prisma-next/test-utils": "0.0.1"
18
19
  },
19
20
  "files": [
20
21
  "dist",
@@ -1,11 +1 @@
1
- export {
2
- col,
3
- contract,
4
- fk,
5
- index,
6
- model,
7
- pk,
8
- storage,
9
- table,
10
- unique,
11
- } from '../factories';
1
+ export { col, fk, index, model, pk, table, unique } from '../factories';
@@ -2,9 +2,10 @@ export type {
2
2
  CodecTypesOf,
3
3
  ContractWithTypeMaps,
4
4
  ExtractCodecTypes,
5
- ExtractOperationTypes,
5
+ ExtractFieldOutputTypes,
6
6
  ExtractQueryOperationTypes,
7
7
  ExtractTypeMapsFromContract,
8
+ FieldOutputTypesOf,
8
9
  ForeignKey,
9
10
  ForeignKeyOptions,
10
11
  ForeignKeyReferences,
@@ -17,11 +18,9 @@ export type {
17
18
  ReferentialAction,
18
19
  ResolveCodecTypes,
19
20
  ResolveOperationTypes,
20
- SqlContract,
21
21
  SqlModelFieldStorage,
22
22
  SqlModelStorage,
23
23
  SqlQueryOperationTypes,
24
- SqlRelation,
25
24
  SqlStorage,
26
25
  StorageColumn,
27
26
  StorageTable,
@@ -1,6 +1 @@
1
- export {
2
- decodeContractDefaults,
3
- isBigIntColumn,
4
- normalizeContract,
5
- validateContract,
6
- } from '../validate';
1
+ export { validateContract } from '../validate';
package/src/factories.ts CHANGED
@@ -1,18 +1,12 @@
1
- import type {
2
- ExecutionHashBase,
3
- ProfileHashBase,
4
- StorageHashBase,
5
- } from '@prisma-next/contract/types';
1
+ import type { ScalarFieldType } from '@prisma-next/contract/types';
6
2
  import type {
7
3
  ForeignKey,
8
4
  ForeignKeyOptions,
9
5
  ForeignKeyReferences,
10
6
  Index,
11
7
  PrimaryKey,
12
- SqlContract,
13
8
  SqlModelFieldStorage,
14
9
  SqlModelStorage,
15
- SqlStorage,
16
10
  StorageColumn,
17
11
  StorageTable,
18
12
  UniqueConstraint,
@@ -90,7 +84,7 @@ export function model(
90
84
  relations: Record<string, unknown> = {},
91
85
  ): {
92
86
  storage: SqlModelStorage;
93
- fields: Record<string, { nullable: boolean; codecId?: string }>;
87
+ fields: Record<string, { readonly nullable: boolean; readonly type: ScalarFieldType }>;
94
88
  relations: Record<string, unknown>;
95
89
  } {
96
90
  const storage: SqlModelStorage = { table: tableName, fields };
@@ -99,52 +93,13 @@ export function model(
99
93
  name,
100
94
  {
101
95
  nullable: field.nullable ?? false,
102
- ...(field.codecId !== undefined ? { codecId: field.codecId } : {}),
96
+ type: { kind: 'scalar' as const, codecId: field.codecId ?? 'core/unknown@1' },
103
97
  },
104
98
  ]),
105
- ) as Record<string, { nullable: boolean; codecId?: string }>;
99
+ ) as Record<string, { nullable: boolean; type: ScalarFieldType }>;
106
100
  return {
107
101
  storage,
108
102
  fields: domainFields,
109
103
  relations,
110
104
  };
111
105
  }
112
-
113
- export function storage(tables: Record<string, StorageTable>): SqlStorage {
114
- return { tables };
115
- }
116
-
117
- export function contract<
118
- TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,
119
- TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,
120
- TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,
121
- >(opts: {
122
- target: string;
123
- storageHash: TStorageHash;
124
- executionHash?: TExecutionHash;
125
- storage: SqlStorage;
126
- models?: Record<string, unknown>;
127
- schemaVersion?: '1';
128
- targetFamily?: 'sql';
129
- profileHash?: TProfileHash;
130
- capabilities?: Record<string, Record<string, boolean>>;
131
- extensionPacks?: Record<string, unknown>;
132
- meta?: Record<string, unknown>;
133
- sources?: Record<string, unknown>;
134
- }): SqlContract<SqlStorage, Record<string, unknown>, TStorageHash, TExecutionHash, TProfileHash> {
135
- return {
136
- schemaVersion: opts.schemaVersion ?? '1',
137
- target: opts.target,
138
- targetFamily: opts.targetFamily ?? 'sql',
139
- storageHash: opts.storageHash,
140
- ...(opts.executionHash !== undefined && { executionHash: opts.executionHash }),
141
- storage: opts.storage,
142
- models: opts.models ?? {},
143
- roots: {},
144
- ...(opts.profileHash !== undefined && { profileHash: opts.profileHash }),
145
- ...(opts.capabilities !== undefined && { capabilities: opts.capabilities }),
146
- ...(opts.extensionPacks !== undefined && { extensionPacks: opts.extensionPacks }),
147
- ...(opts.meta !== undefined && { meta: opts.meta }),
148
- ...(opts.sources !== undefined && { sources: opts.sources as Record<string, unknown> }),
149
- } as SqlContract<SqlStorage, Record<string, unknown>, TStorageHash, TExecutionHash, TProfileHash>;
150
- }
package/src/types.ts CHANGED
@@ -1,12 +1,4 @@
1
- import type {
2
- ColumnDefault,
3
- ContractBase,
4
- DomainRelationOn,
5
- ExecutionHashBase,
6
- ExecutionSection,
7
- ProfileHashBase,
8
- StorageHashBase,
9
- } from '@prisma-next/contract/types';
1
+ import type { ColumnDefault, StorageBase } from '@prisma-next/contract/types';
10
2
 
11
3
  /**
12
4
  * A column definition in storage.
@@ -111,7 +103,7 @@ export type StorageTypeInstance = {
111
103
  readonly typeParams: Record<string, unknown>;
112
104
  };
113
105
 
114
- export type SqlStorage = {
106
+ export type SqlStorage<THash extends string = string> = StorageBase<THash> & {
115
107
  readonly tables: Record<string, StorageTable>;
116
108
  /**
117
109
  * Named type instances for parameterized/custom types.
@@ -131,12 +123,6 @@ export type SqlModelStorage = {
131
123
  readonly fields: Record<string, SqlModelFieldStorage>;
132
124
  };
133
125
 
134
- export type SqlRelation = {
135
- readonly to: string;
136
- readonly cardinality: '1:1' | '1:N' | 'N:1';
137
- readonly on: DomainRelationOn;
138
- };
139
-
140
126
  export const DEFAULT_FK_CONSTRAINT = true;
141
127
  export const DEFAULT_FK_INDEX = true;
142
128
 
@@ -154,10 +140,12 @@ export type TypeMaps<
154
140
  TCodecTypes extends Record<string, { output: unknown }> = Record<string, never>,
155
141
  TOperationTypes extends Record<string, unknown> = Record<string, never>,
156
142
  TQueryOperationTypes extends Record<string, unknown> = Record<string, never>,
143
+ TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>,
157
144
  > = {
158
145
  readonly codecTypes: TCodecTypes;
159
146
  readonly operationTypes: TOperationTypes;
160
147
  readonly queryOperationTypes: TQueryOperationTypes;
148
+ readonly fieldOutputTypes: TFieldOutputTypes;
161
149
  };
162
150
 
163
151
  export type CodecTypesOf<T> = [T] extends [never]
@@ -199,31 +187,24 @@ export type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & {
199
187
  readonly [K in TypeMapsPhantomKey]?: TTypeMaps;
200
188
  };
201
189
 
202
- export type SqlContract<
203
- S extends SqlStorage = SqlStorage,
204
- TModels extends Record<string, unknown> = Record<string, unknown>,
205
- TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,
206
- TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,
207
- TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,
208
- > = Omit<ContractBase<TStorageHash, TExecutionHash, TProfileHash>, 'models'> & {
209
- readonly targetFamily: string;
210
- readonly storage: S;
211
- readonly models: TModels;
212
- readonly execution?: ExecutionSection;
213
- };
214
-
215
190
  export type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T
216
191
  ? NonNullable<T[TypeMapsPhantomKey & keyof T]>
217
192
  : never;
218
193
 
194
+ export type FieldOutputTypesOf<T> = [T] extends [never]
195
+ ? Record<string, never>
196
+ : T extends { readonly fieldOutputTypes: infer F }
197
+ ? F extends Record<string, Record<string, unknown>>
198
+ ? F
199
+ : Record<string, never>
200
+ : Record<string, never>;
201
+
219
202
  export type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;
220
- export type ExtractOperationTypes<T> = OperationTypesOf<ExtractTypeMapsFromContract<T>>;
221
203
  export type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;
204
+ export type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;
222
205
 
223
206
  export type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]
224
207
  ? ExtractCodecTypes<TContract>
225
208
  : CodecTypesOf<TTypeMaps>;
226
209
 
227
- export type ResolveOperationTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]
228
- ? ExtractOperationTypes<TContract>
229
- : OperationTypesOf<TTypeMaps>;
210
+ export type ResolveOperationTypes<_TContract, TTypeMaps> = OperationTypesOf<TTypeMaps>;