@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.
package/src/validate.ts CHANGED
@@ -1,52 +1,63 @@
1
- import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';
2
- import { isTaggedBigInt, isTaggedRaw } from '@prisma-next/contract/types';
3
- import type { DomainContractShape, DomainModelShape } from '@prisma-next/contract/validate-domain';
4
- import { validateContractDomain } from '@prisma-next/contract/validate-domain';
5
- import { constructContract } from './construct';
6
- import type { SqlContract, SqlStorage, StorageColumn, StorageTable } from './types';
7
- import { applyFkDefaults } from './types';
1
+ import type {
2
+ ColumnDefaultLiteralInputValue,
3
+ Contract,
4
+ ContractField,
5
+ ContractModel,
6
+ JsonValue,
7
+ } from '@prisma-next/contract/types';
8
+ import {
9
+ ContractValidationError,
10
+ validateContract as frameworkValidateContract,
11
+ } from '@prisma-next/contract/validate-contract';
12
+ import type { CodecLookup } from '@prisma-next/framework-components/codec';
13
+ import type { SqlModelStorage, SqlStorage, StorageColumn, StorageTable } from './types';
8
14
  import { validateSqlContract, validateStorageSemantics } from './validators';
9
15
 
10
- function extractDomainShape(contract: SqlContract<SqlStorage>): DomainContractShape {
11
- return {
12
- roots: contract.roots,
13
- models: contract.models as Record<string, DomainModelShape>,
14
- };
15
- }
16
+ type SqlValidationContract = Contract<SqlStorage, Record<string, ContractModel<SqlModelStorage>>>;
16
17
 
17
- function validateModelStorageReferences(contract: SqlContract<SqlStorage>): void {
18
- const models = contract.models as Record<
19
- string,
20
- { storage?: { table?: string; fields?: Record<string, { column?: string }> } }
21
- >;
22
-
23
- for (const [modelName, model] of Object.entries(models)) {
24
- const storageTable = model.storage?.table;
25
- if (!storageTable) continue;
18
+ function validateModelStorageReferences(contract: SqlValidationContract): void {
19
+ for (const [modelName, model] of Object.entries(contract.models)) {
20
+ const storageTable = model.storage.table;
26
21
 
27
22
  const table = contract.storage.tables[storageTable] as
28
23
  | (typeof contract.storage.tables)[string]
29
24
  | undefined;
30
25
  if (!table) {
31
- throw new Error(`Model "${modelName}" references non-existent table "${storageTable}"`);
26
+ throw new ContractValidationError(
27
+ `Model "${modelName}" references non-existent table "${storageTable}"`,
28
+ 'storage',
29
+ );
32
30
  }
33
31
 
34
- const storageFields = model.storage?.fields;
35
- if (!storageFields) continue;
36
-
37
32
  const columnNames = new Set(Object.keys(table.columns));
38
- for (const [fieldName, field] of Object.entries(storageFields)) {
39
- const column = field.column;
40
- if (column && !columnNames.has(column)) {
41
- throw new Error(
42
- `Model "${modelName}" field "${fieldName}" references non-existent column "${column}" in table "${storageTable}"`,
33
+ for (const [fieldName, field] of Object.entries(model.storage.fields)) {
34
+ if (!columnNames.has(field.column)) {
35
+ throw new ContractValidationError(
36
+ `Model "${modelName}" field "${fieldName}" references non-existent column "${field.column}" in table "${storageTable}"`,
37
+ 'storage',
38
+ );
39
+ }
40
+ }
41
+
42
+ const JSON_NATIVE_TYPES = new Set(['json', 'jsonb']);
43
+ for (const [fieldName, domainField] of Object.entries(model.fields)) {
44
+ const f = domainField as ContractField;
45
+ if (f.type?.kind !== 'valueObject') continue;
46
+ const storageField = model.storage.fields[fieldName];
47
+ if (!storageField) continue;
48
+ const column = table.columns[storageField.column];
49
+ if (!column) continue;
50
+ if (!JSON_NATIVE_TYPES.has(column.nativeType)) {
51
+ throw new ContractValidationError(
52
+ `Model "${modelName}" field "${fieldName}" is a value object but storage column "${storageField.column}" has nativeType "${column.nativeType}" (expected json or jsonb)`,
53
+ 'storage',
43
54
  );
44
55
  }
45
56
  }
46
57
  }
47
58
  }
48
59
 
49
- function validateContractLogic(contract: SqlContract<SqlStorage>): void {
60
+ function validateContractLogic(contract: Contract<SqlStorage>): void {
50
61
  const tableNames = new Set(Object.keys(contract.storage.tables));
51
62
 
52
63
  for (const [tableName, table] of Object.entries(contract.storage.tables)) {
@@ -55,8 +66,9 @@ function validateContractLogic(contract: SqlContract<SqlStorage>): void {
55
66
  if (table.primaryKey) {
56
67
  for (const colName of table.primaryKey.columns) {
57
68
  if (!columnNames.has(colName)) {
58
- throw new Error(
69
+ throw new ContractValidationError(
59
70
  `Table "${tableName}" primaryKey references non-existent column "${colName}"`,
71
+ 'storage',
60
72
  );
61
73
  }
62
74
  }
@@ -65,8 +77,9 @@ function validateContractLogic(contract: SqlContract<SqlStorage>): void {
65
77
  for (const unique of table.uniques) {
66
78
  for (const colName of unique.columns) {
67
79
  if (!columnNames.has(colName)) {
68
- throw new Error(
80
+ throw new ContractValidationError(
69
81
  `Table "${tableName}" unique constraint references non-existent column "${colName}"`,
82
+ 'storage',
70
83
  );
71
84
  }
72
85
  }
@@ -75,15 +88,19 @@ function validateContractLogic(contract: SqlContract<SqlStorage>): void {
75
88
  for (const index of table.indexes) {
76
89
  for (const colName of index.columns) {
77
90
  if (!columnNames.has(colName)) {
78
- throw new Error(`Table "${tableName}" index references non-existent column "${colName}"`);
91
+ throw new ContractValidationError(
92
+ `Table "${tableName}" index references non-existent column "${colName}"`,
93
+ 'storage',
94
+ );
79
95
  }
80
96
  }
81
97
  }
82
98
 
83
99
  for (const [colName, column] of Object.entries(table.columns)) {
84
100
  if (!column.nullable && column.default?.kind === 'literal' && column.default.value === null) {
85
- throw new Error(
101
+ throw new ContractValidationError(
86
102
  `Table "${tableName}" column "${colName}" is NOT NULL but has a literal null default`,
103
+ 'storage',
87
104
  );
88
105
  }
89
106
  }
@@ -91,76 +108,59 @@ function validateContractLogic(contract: SqlContract<SqlStorage>): void {
91
108
  for (const fk of table.foreignKeys) {
92
109
  for (const colName of fk.columns) {
93
110
  if (!columnNames.has(colName)) {
94
- throw new Error(
111
+ throw new ContractValidationError(
95
112
  `Table "${tableName}" foreignKey references non-existent column "${colName}"`,
113
+ 'storage',
96
114
  );
97
115
  }
98
116
  }
99
117
 
100
118
  if (!tableNames.has(fk.references.table)) {
101
- throw new Error(
119
+ throw new ContractValidationError(
102
120
  `Table "${tableName}" foreignKey references non-existent table "${fk.references.table}"`,
121
+ 'storage',
103
122
  );
104
123
  }
105
124
 
106
- const referencedTable = contract.storage.tables[
107
- fk.references.table
108
- ] as (typeof contract.storage.tables)[string];
125
+ const referencedTable = contract.storage.tables[fk.references.table];
126
+ if (!referencedTable) continue;
109
127
  const referencedColumnNames = new Set(Object.keys(referencedTable.columns));
110
128
  for (const colName of fk.references.columns) {
111
129
  if (!referencedColumnNames.has(colName)) {
112
- throw new Error(
130
+ throw new ContractValidationError(
113
131
  `Table "${tableName}" foreignKey references non-existent column "${colName}" in table "${fk.references.table}"`,
132
+ 'storage',
114
133
  );
115
134
  }
116
135
  }
117
136
 
118
137
  if (fk.columns.length !== fk.references.columns.length) {
119
- throw new Error(
138
+ throw new ContractValidationError(
120
139
  `Table "${tableName}" foreignKey column count (${fk.columns.length}) does not match referenced column count (${fk.references.columns.length})`,
140
+ 'storage',
121
141
  );
122
142
  }
123
143
  }
124
144
  }
125
145
  }
126
146
 
127
- const BIGINT_NATIVE_TYPES = new Set(['bigint', 'int8']);
128
-
129
- export function isBigIntColumn(column: StorageColumn): boolean {
130
- const nativeType = column.nativeType?.toLowerCase() ?? '';
131
- if (BIGINT_NATIVE_TYPES.has(nativeType)) return true;
132
- const codecId = column.codecId?.toLowerCase() ?? '';
133
- return codecId.includes('int8') || codecId.includes('bigint');
134
- }
135
-
136
- export function decodeDefaultLiteralValue(
137
- value: ColumnDefaultLiteralInputValue,
138
- column: StorageColumn,
139
- tableName: string,
140
- columnName: string,
141
- ): ColumnDefaultLiteralInputValue {
142
- if (value instanceof Date) {
143
- return value;
144
- }
145
- if (isTaggedRaw(value)) {
146
- return value.value;
147
- }
148
- if (isTaggedBigInt(value)) {
149
- if (!isBigIntColumn(column)) {
150
- return value;
151
- }
152
- try {
153
- return BigInt(value.value);
154
- } catch {
155
- throw new Error(
156
- `Invalid tagged bigint for default value on "${tableName}.${columnName}": "${value.value}" is not a valid integer`,
157
- );
158
- }
147
+ function validateSqlStorage(contract: Contract): void {
148
+ const sqlContract = validateSqlContract<SqlValidationContract>(contract);
149
+ validateContractLogic(sqlContract);
150
+ validateModelStorageReferences(sqlContract);
151
+ const semanticErrors = validateStorageSemantics(sqlContract.storage);
152
+ if (semanticErrors.length > 0) {
153
+ throw new ContractValidationError(
154
+ `Contract semantic validation failed: ${semanticErrors.join('; ')}`,
155
+ 'storage',
156
+ );
159
157
  }
160
- return value;
161
158
  }
162
159
 
163
- export function decodeContractDefaults<T extends SqlContract<SqlStorage>>(contract: T): T {
160
+ function decodeContractDefaults<T extends Contract<SqlStorage>>(
161
+ contract: T,
162
+ codecLookup: CodecLookup,
163
+ ): T {
164
164
  const tables = contract.storage.tables;
165
165
  let tablesChanged = false;
166
166
  const decodedTables: Record<string, StorageTable> = {};
@@ -171,19 +171,19 @@ export function decodeContractDefaults<T extends SqlContract<SqlStorage>>(contra
171
171
 
172
172
  for (const [columnName, column] of Object.entries(table.columns)) {
173
173
  if (column.default?.kind === 'literal') {
174
- const decodedValue = decodeDefaultLiteralValue(
175
- column.default.value,
176
- column,
177
- tableName,
178
- columnName,
179
- );
180
- if (decodedValue !== column.default.value) {
181
- columnsChanged = true;
182
- decodedColumns[columnName] = {
183
- ...column,
184
- default: { kind: 'literal', value: decodedValue },
185
- };
186
- continue;
174
+ const codec = codecLookup.get(column.codecId);
175
+ if (codec) {
176
+ const decodedValue = codec.decodeJson(
177
+ column.default.value as JsonValue,
178
+ ) as ColumnDefaultLiteralInputValue;
179
+ if (decodedValue !== column.default.value) {
180
+ columnsChanged = true;
181
+ decodedColumns[columnName] = {
182
+ ...column,
183
+ default: { kind: 'literal', value: decodedValue },
184
+ };
185
+ continue;
186
+ }
187
187
  }
188
188
  }
189
189
  decodedColumns[columnName] = column;
@@ -210,122 +210,18 @@ export function decodeContractDefaults<T extends SqlContract<SqlStorage>>(contra
210
210
  } as T;
211
211
  }
212
212
 
213
- function normalizeStorage(contractObj: Record<string, unknown>): Record<string, unknown> {
214
- const normalizedStorage = contractObj['storage'];
215
- if (!normalizedStorage || typeof normalizedStorage !== 'object')
216
- return normalizedStorage as Record<string, unknown>;
217
-
218
- const storage = normalizedStorage as Record<string, unknown>;
219
- const tables = storage['tables'] as Record<string, unknown> | undefined;
220
- if (!tables) return storage;
221
-
222
- const normalizedTables: Record<string, unknown> = {};
223
- for (const [tableName, table] of Object.entries(tables)) {
224
- const tableObj = table as Record<string, unknown>;
225
- const columns = tableObj['columns'] as Record<string, unknown> | undefined;
226
-
227
- if (columns) {
228
- const normalizedColumns: Record<string, unknown> = {};
229
- for (const [columnName, column] of Object.entries(columns)) {
230
- const columnObj = column as Record<string, unknown>;
231
- normalizedColumns[columnName] = {
232
- ...columnObj,
233
- nullable: columnObj['nullable'] ?? false,
234
- };
235
- }
236
-
237
- const rawForeignKeys = (tableObj['foreignKeys'] ?? []) as Array<Record<string, unknown>>;
238
- const normalizedForeignKeys = rawForeignKeys.map((fk) => ({
239
- ...fk,
240
- ...applyFkDefaults({
241
- constraint: typeof fk['constraint'] === 'boolean' ? fk['constraint'] : undefined,
242
- index: typeof fk['index'] === 'boolean' ? fk['index'] : undefined,
243
- }),
244
- }));
245
-
246
- normalizedTables[tableName] = {
247
- ...tableObj,
248
- columns: normalizedColumns,
249
- uniques: tableObj['uniques'] ?? [],
250
- indexes: tableObj['indexes'] ?? [],
251
- foreignKeys: normalizedForeignKeys,
252
- };
253
- } else {
254
- normalizedTables[tableName] = tableObj;
255
- }
256
- }
257
-
258
- return { ...storage, tables: normalizedTables };
259
- }
260
-
261
- function normalizeModels(
262
- models: Record<string, Record<string, unknown>>,
263
- ): Record<string, Record<string, unknown>> {
264
- const normalized: Record<string, Record<string, unknown>> = {};
265
- for (const [modelName, model] of Object.entries(models)) {
266
- normalized[modelName] = {
267
- ...model,
268
- relations: model['relations'] ?? {},
269
- };
270
- }
271
- return normalized;
272
- }
273
-
274
- export function normalizeContract(contract: unknown): SqlContract<SqlStorage> {
275
- if (typeof contract !== 'object' || contract === null) {
276
- return contract as SqlContract<SqlStorage>;
277
- }
278
-
279
- const contractObj = contract as Record<string, unknown>;
280
- const normalizedStorage = normalizeStorage(contractObj);
281
-
282
- const rawModels = contractObj['models'];
283
- const models =
284
- rawModels && typeof rawModels === 'object' && rawModels !== null
285
- ? normalizeModels(rawModels as Record<string, Record<string, unknown>>)
286
- : (rawModels ?? {});
287
-
288
- const pick = (key: string) =>
289
- key in contractObj && contractObj[key] !== undefined ? { [key]: contractObj[key] } : {};
290
-
291
- return {
292
- ...pick('schemaVersion'),
293
- target: contractObj['target'],
294
- targetFamily: contractObj['targetFamily'],
295
- ...pick('coreHash'),
296
- storageHash: contractObj['storageHash'],
297
- ...pick('executionHash'),
298
- ...pick('profileHash'),
299
- ...pick('_generated'),
300
- roots: contractObj['roots'] ?? {},
301
- models,
302
- storage: normalizedStorage,
303
- extensionPacks: contractObj['extensionPacks'] ?? {},
304
- capabilities: contractObj['capabilities'] ?? {},
305
- meta: contractObj['meta'] ?? {},
306
- sources: contractObj['sources'] ?? {},
307
- ...pick('execution'),
308
- } as SqlContract<SqlStorage>;
309
- }
310
-
311
- export function validateContract<TContract extends SqlContract<SqlStorage>>(
213
+ export function validateContract<TContract extends Contract<SqlStorage>>(
312
214
  value: unknown,
215
+ codecLookup: CodecLookup,
313
216
  ): TContract {
314
- const normalized = normalizeContract(value);
315
-
316
- const structurallyValid = validateSqlContract<SqlContract<SqlStorage>>(normalized);
317
-
318
- validateContractDomain(extractDomainShape(structurallyValid));
319
-
320
- validateContractLogic(structurallyValid);
321
-
322
- validateModelStorageReferences(structurallyValid);
323
-
324
- const semanticErrors = validateStorageSemantics(structurallyValid.storage);
325
- if (semanticErrors.length > 0) {
326
- throw new Error(`Contract semantic validation failed: ${semanticErrors.join('; ')}`);
217
+ const validated = frameworkValidateContract<TContract>(value, validateSqlStorage);
218
+ try {
219
+ return decodeContractDefaults(validated, codecLookup);
220
+ } catch (error) {
221
+ if (error instanceof ContractValidationError) throw error;
222
+ throw new ContractValidationError(
223
+ error instanceof Error ? error.message : String(error),
224
+ 'storage',
225
+ );
327
226
  }
328
-
329
- const constructed = constructContract<TContract>(structurallyValid);
330
- return decodeContractDefaults(constructed) as TContract;
331
227
  }
package/src/validators.ts CHANGED
@@ -1,10 +1,11 @@
1
+ import type { Contract } from '@prisma-next/contract/types';
2
+ import { ContractValidationError } from '@prisma-next/contract/validate-contract';
1
3
  import { type } from 'arktype';
2
4
  import type {
3
5
  ForeignKey,
4
6
  ForeignKeyReferences,
5
7
  PrimaryKey,
6
8
  ReferentialAction,
7
- SqlContract,
8
9
  SqlStorage,
9
10
  StorageTypeInstance,
10
11
  UniqueConstraint,
@@ -54,6 +55,7 @@ const ExecutionMutationDefaultSchema = type({
54
55
 
55
56
  const ExecutionSchema = type({
56
57
  '+': 'reject',
58
+ executionHash: 'string',
57
59
  mutations: {
58
60
  '+': 'reject',
59
61
  defaults: ExecutionMutationDefaultSchema.array().readonly(),
@@ -128,13 +130,45 @@ const StorageTableSchema = type({
128
130
 
129
131
  const StorageSchema = type({
130
132
  '+': 'reject',
133
+ storageHash: 'string',
131
134
  tables: type({ '[string]': StorageTableSchema }),
132
135
  'types?': type({ '[string]': StorageTypeInstanceSchema }),
133
136
  });
134
137
 
138
+ function isPlainRecord(value: unknown): value is Record<string, unknown> {
139
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
140
+ }
141
+
142
+ function isContractFieldType(value: unknown): boolean {
143
+ if (!isPlainRecord(value)) return false;
144
+ const kind = value['kind'];
145
+ if (kind === 'scalar') {
146
+ if (typeof value['codecId'] !== 'string') return false;
147
+ const typeParams = value['typeParams'];
148
+ if (typeParams !== undefined && !isPlainRecord(typeParams)) return false;
149
+ return true;
150
+ }
151
+ if (kind === 'valueObject') {
152
+ return typeof value['name'] === 'string';
153
+ }
154
+ if (kind === 'union') {
155
+ const members = value['members'];
156
+ if (!Array.isArray(members)) return false;
157
+ return members.every((m) => isContractFieldType(m));
158
+ }
159
+ return false;
160
+ }
161
+
162
+ const ContractFieldTypeSchema = type('unknown').narrow((value, ctx) =>
163
+ isContractFieldType(value) ? true : ctx.mustBe('scalar, valueObject, or union field type'),
164
+ );
165
+
135
166
  const ModelFieldSchema = type({
136
- 'nullable?': 'boolean',
137
- 'codecId?': 'string',
167
+ '+': 'reject',
168
+ nullable: 'boolean',
169
+ type: ContractFieldTypeSchema,
170
+ 'many?': 'true',
171
+ 'dict?': 'true',
138
172
  });
139
173
 
140
174
  const ModelStorageFieldSchema = type({
@@ -164,20 +198,16 @@ const ContractMetaSchema = type({
164
198
 
165
199
  const SqlContractSchema = type({
166
200
  '+': 'reject',
167
- 'schemaVersion?': "'1'",
168
201
  target: 'string',
169
202
  targetFamily: "'sql'",
170
203
  'coreHash?': 'string',
171
- storageHash: 'string',
172
- 'executionHash?': 'string',
173
- 'profileHash?': 'string',
174
- '_generated?': 'Record<string, unknown>',
204
+ profileHash: 'string',
175
205
  'capabilities?': 'Record<string, Record<string, boolean>>',
176
206
  'extensionPacks?': 'Record<string, unknown>',
177
207
  'meta?': ContractMetaSchema,
178
- 'sources?': 'Record<string, unknown>',
179
208
  'roots?': 'Record<string, string>',
180
209
  models: type({ '[string]': ModelSchema }),
210
+ 'valueObjects?': 'Record<string, unknown>',
181
211
  storage: StorageSchema,
182
212
  'execution?': ExecutionSchema,
183
213
  });
@@ -215,43 +245,44 @@ export function validateModel(value: unknown): unknown {
215
245
  }
216
246
 
217
247
  /**
218
- * Validates the structural shape of a SqlContract using Arktype.
219
- *
220
- * **Responsibility: Validation Only**
221
- * This function validates that the contract has the correct structure and types.
222
- * It does NOT normalize the contract - normalization must happen in the contract builder.
223
- *
224
- * The contract passed to this function must already be normalized (all required fields present).
225
- * If normalization is needed, it should be done by the contract builder before calling this function.
248
+ * Validates the structural shape of an SQL contract using Arktype.
226
249
  *
227
- * This ensures all required fields are present and have the correct types.
250
+ * Ensures all required fields are present and have the correct types,
251
+ * including SQL-specific storage structure (tables, columns, constraints).
228
252
  *
229
253
  * @param value - The contract value to validate (typically from a JSON import)
230
254
  * @returns The validated contract if structure is valid
231
- * @throws Error if the contract structure is invalid
255
+ * @throws ContractValidationError if the contract structure is invalid
232
256
  */
233
- export function validateSqlContract<T extends SqlContract<SqlStorage>>(value: unknown): T {
257
+ export function validateSqlContract<T extends Contract<SqlStorage>>(value: unknown): T {
234
258
  if (typeof value !== 'object' || value === null) {
235
- throw new Error('Contract structural validation failed: value must be an object');
259
+ throw new ContractValidationError(
260
+ 'Contract structural validation failed: value must be an object',
261
+ 'structural',
262
+ );
236
263
  }
237
264
 
238
- // Check targetFamily first to provide a clear error message for unsupported target families
239
265
  const rawValue = value as { targetFamily?: string };
240
266
  if (rawValue.targetFamily !== undefined && rawValue.targetFamily !== 'sql') {
241
- throw new Error(`Unsupported target family: ${rawValue.targetFamily}`);
267
+ throw new ContractValidationError(
268
+ `Unsupported target family: ${rawValue.targetFamily}`,
269
+ 'structural',
270
+ );
242
271
  }
243
272
 
244
273
  const contractResult = SqlContractSchema(value);
245
274
 
246
275
  if (contractResult instanceof type.errors) {
247
276
  const messages = contractResult.map((p: { message: string }) => p.message).join('; ');
248
- throw new Error(`Contract structural validation failed: ${messages}`);
277
+ throw new ContractValidationError(
278
+ `Contract structural validation failed: ${messages}`,
279
+ 'structural',
280
+ );
249
281
  }
250
282
 
251
- // After validation, contractResult matches the schema and preserves the input structure
252
- // TypeScript needs an assertion here due to exactOptionalPropertyTypes differences
253
- // between Arktype's inferred type and the generic T, but runtime-wise they're compatible
254
- return contractResult as T;
283
+ // Arktype's inferred output type differs from T due to exactOptionalPropertyTypes
284
+ // and branded hash types the runtime value is structurally compatible after validation
285
+ return contractResult as unknown as T;
255
286
  }
256
287
 
257
288
  /**
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-D6K16_9R.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAiBA;AAsBA;AAKA;AAKA;AAeA;AAKY,KApDA,aAAA,GAoDiB;EAEjB,SAAA,UAAA,EAAiB,MAAA;EAMjB,SAAA,OA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AA,GA3DpB,MA2DoB,CAAA,MAAA,EAAA,KAAA,CAAA;AAAtB,KAzDQ,gBAyDR,CAAA,CAAA,CAAA,GAAA,CAzD+B,CAyD/B,CAAA,SAAA,CAAA,KAAA,CAAA,GAxDA,MAwDA,CAAA,MAAA,EAAA,KAAA,CAAA,GAvDA,CAuDA,SAAA;EACiB,SAAA,cAAA,EAAA,KAAA,EAAA;CAAjB,GAAA,CAAA,SAvDY,MAuDZ,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,CAAA,GArDI,MAqDJ,CAAA,MAAA,EAAA,KAAA,CAAA,GApDE,MAoDF,CAAA,MAAA,EAAA,KAAA,CAAA;AAAgB,KAlDR,uBAAA,GAkDQ;;;;;;;;;;KA7CR,iCAAiC,eAAe,4BAA4B;KAE5E,uBAAA,GAA0B,eAAe;KAEzC,4BAA4B,qBACpC,wBACA;;cACY,8BAER,wBACF;KAEM,kBAAA;KAEA,6CAA6C,6BACxC,sBAAsB;KAG3B,sBACA,aAAa,4BACP,0BAA0B,8CACrB,0BAA0B,gDACxB,4BAA4B,gDAC9B,0BAA0B,2BAC7C,KAAK,aAAa,cAAc,gBAAgB;;oBAEhC;mBACD;uBACI;;KAGX,iCAAiC,iCAAiC,IAC1E,YAAY,EAAE,2BAA2B;KAGjC,uBAAuB,aAAa,4BAA4B;KAChE,2BAA2B,iBAAiB,4BAA4B;KACxE,gCAAgC,sBAAsB,4BAA4B;KAElF,2CAA2C,6BACnD,kBAAkB,aAClB,aAAa;KAEL,+CAA+C,6BACvD,sBAAsB,aACtB,iBAAiB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"validators-i9MX9Dti.mjs","names":["errors: string[]"],"sources":["../src/validators.ts"],"sourcesContent":["import { type } from 'arktype';\nimport type {\n ForeignKey,\n ForeignKeyReferences,\n PrimaryKey,\n ReferentialAction,\n SqlContract,\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 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 tables: type({ '[string]': StorageTableSchema }),\n 'types?': type({ '[string]': StorageTypeInstanceSchema }),\n});\n\nconst ModelFieldSchema = type({\n 'nullable?': 'boolean',\n 'codecId?': 'string',\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 'schemaVersion?': \"'1'\",\n target: 'string',\n targetFamily: \"'sql'\",\n 'coreHash?': 'string',\n storageHash: 'string',\n 'executionHash?': 'string',\n 'profileHash?': 'string',\n '_generated?': 'Record<string, unknown>',\n 'capabilities?': 'Record<string, Record<string, boolean>>',\n 'extensionPacks?': 'Record<string, unknown>',\n 'meta?': ContractMetaSchema,\n 'sources?': 'Record<string, unknown>',\n 'roots?': 'Record<string, string>',\n models: type({ '[string]': ModelSchema }),\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 a SqlContract using Arktype.\n *\n * **Responsibility: Validation Only**\n * This function validates that the contract has the correct structure and types.\n * It does NOT normalize the contract - normalization must happen in the contract builder.\n *\n * The contract passed to this function must already be normalized (all required fields present).\n * If normalization is needed, it should be done by the contract builder before calling this function.\n *\n * This ensures all required fields are present and have the correct types.\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 Error if the contract structure is invalid\n */\nexport function validateSqlContract<T extends SqlContract<SqlStorage>>(value: unknown): T {\n if (typeof value !== 'object' || value === null) {\n throw new Error('Contract structural validation failed: value must be an object');\n }\n\n // Check targetFamily first to provide a clear error message for unsupported target families\n const rawValue = value as { targetFamily?: string };\n if (rawValue.targetFamily !== undefined && rawValue.targetFamily !== 'sql') {\n throw new Error(`Unsupported target family: ${rawValue.targetFamily}`);\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 Error(`Contract structural validation failed: ${messages}`);\n }\n\n // After validation, contractResult matches the schema and preserves the input structure\n // TypeScript needs an assertion here due to exactOptionalPropertyTypes differences\n // between Arktype's inferred type and the generic T, but runtime-wise they're compatible\n return contractResult 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":";;;AAiBA,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,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,KAAI,IAAI,eAAe,UAAa,IAAI,YAAY,OAClD,QAAO,IAAI,OAAO,uDAAuD;AAE3E,QAAO;EACP;AAEF,MAAM,4BAA4B,KAAK,SAA8B,CAAC,KAAK;CACzE,SAAS;CACT,YAAY;CACZ,YAAY;CACb,CAA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- type ValidatedContractInput = SqlContract<SqlStorage> & { _generated?: unknown };
4
-
5
- function stripGenerated(obj: ValidatedContractInput): Omit<ValidatedContractInput, '_generated'> {
6
- const input = obj as unknown as Record<string, unknown>;
7
- const { _generated: _, ...rest } = input;
8
- return rest as Omit<ValidatedContractInput, '_generated'>;
9
- }
10
-
11
- export function constructContract<TContract extends SqlContract<SqlStorage>>(
12
- input: ValidatedContractInput,
13
- ): TContract {
14
- const stripped = stripGenerated(input);
15
- return stripped as TContract;
16
- }