@prisma-next/sql-contract-emitter 0.3.0-pr.94.2 → 0.3.0-pr.95.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ import type { ContractIR } from '@prisma-next/contract/ir';
2
+ import type { GenerateContractTypesOptions, TypesImportSpec, ValidationContext } from '@prisma-next/contract/types';
3
+ import type { ModelDefinition, SqlStorage, StorageColumn } from '@prisma-next/sql-contract/types';
4
+ export declare const sqlTargetFamilyHook: {
5
+ readonly id: "sql";
6
+ readonly validateTypes: (ir: ContractIR, _ctx: ValidationContext) => void;
7
+ readonly validateStructure: (ir: ContractIR) => void;
8
+ readonly generateContractTypes: (ir: ContractIR, codecTypeImports: ReadonlyArray<TypesImportSpec>, operationTypeImports: ReadonlyArray<TypesImportSpec>, options?: GenerateContractTypesOptions) => string;
9
+ readonly generateStorageType: (storage: SqlStorage) => string;
10
+ /**
11
+ * Renders the TypeScript type for a column.
12
+ * Uses parameterized renderer if column has typeParams and renderer exists.
13
+ * Falls back to CodecTypes['codecId']['output'] for scalar codecs.
14
+ */
15
+ readonly renderColumnType: (column: StorageColumn, storage: SqlStorage, parameterizedRenderers?: GenerateContractTypesOptions["parameterizedRenderers"]) => string;
16
+ readonly generateModelsType: (models: Record<string, ModelDefinition> | undefined, storage: SqlStorage, parameterizedRenderers?: GenerateContractTypesOptions["parameterizedRenderers"]) => string;
17
+ readonly generateRelationsType: (relations: Record<string, unknown> | undefined) => string;
18
+ readonly generateMappingsType: (models: Record<string, ModelDefinition> | undefined, storage: SqlStorage, codecTypes: string, operationTypes: string) => string;
19
+ };
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EACV,4BAA4B,EAC5B,eAAe,EACf,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EACV,eAAe,EAEf,UAAU,EACV,aAAa,EAEd,MAAM,iCAAiC,CAAC;AAEzC,eAAO,MAAM,mBAAmB;;iCAGZ,UAAU,QAAQ,iBAAiB,KAAG,IAAI;qCA6BtC,UAAU,KAAG,IAAI;yCA2JjC,UAAU,oBACI,aAAa,CAAC,eAAe,CAAC,wBAC1B,aAAa,CAAC,eAAe,CAAC,YAC1C,4BAA4B,KACrC,MAAM;4CA0CoB,UAAU,KAAG,MAAM;IAuDhD;;;;OAIG;wCAEO,aAAa,WACZ,UAAU,2BACM,4BAA4B,CAAC,wBAAwB,CAAC,KAC9E,MAAM;0CA2BC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,SAAS,WAC1C,UAAU,2BACM,4BAA4B,CAAC,wBAAwB,CAAC,KAC9E,MAAM;gDA4DwB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,KAAG,MAAM;4CAkEnE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,SAAS,WAC1C,UAAU,cACP,MAAM,kBACF,MAAM,KACrB,MAAM;CAsDD,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,404 @@
1
+ // src/index.ts
2
+ var sqlTargetFamilyHook = {
3
+ id: "sql",
4
+ validateTypes(ir, _ctx) {
5
+ const storage = ir.storage;
6
+ if (!storage || !storage.tables) {
7
+ return;
8
+ }
9
+ const typeIdRegex = /^([^/]+)\/([^@]+)@(\d+)$/;
10
+ for (const [tableName, tableUnknown] of Object.entries(storage.tables)) {
11
+ const table = tableUnknown;
12
+ for (const [colName, colUnknown] of Object.entries(table.columns)) {
13
+ const col = colUnknown;
14
+ const codecId = col.codecId;
15
+ if (!codecId) {
16
+ throw new Error(`Column "${colName}" in table "${tableName}" is missing codecId`);
17
+ }
18
+ const match = codecId.match(typeIdRegex);
19
+ if (!match || !match[1]) {
20
+ throw new Error(
21
+ `Column "${colName}" in table "${tableName}" has invalid codec ID format "${codecId}". Expected format: ns/name@version`
22
+ );
23
+ }
24
+ }
25
+ }
26
+ },
27
+ validateStructure(ir) {
28
+ if (ir.targetFamily !== "sql") {
29
+ throw new Error(`Expected targetFamily "sql", got "${ir.targetFamily}"`);
30
+ }
31
+ const storage = ir.storage;
32
+ if (!storage || !storage.tables) {
33
+ throw new Error("SQL contract must have storage.tables");
34
+ }
35
+ const models = ir.models;
36
+ const tableNames = new Set(Object.keys(storage.tables));
37
+ if (models) {
38
+ for (const [modelName, modelUnknown] of Object.entries(models)) {
39
+ const model = modelUnknown;
40
+ if (!model.storage?.table) {
41
+ throw new Error(`Model "${modelName}" is missing storage.table`);
42
+ }
43
+ const tableName = model.storage.table;
44
+ if (!tableNames.has(tableName)) {
45
+ throw new Error(`Model "${modelName}" references non-existent table "${tableName}"`);
46
+ }
47
+ const table = storage.tables[tableName];
48
+ if (!table) {
49
+ throw new Error(`Model "${modelName}" references non-existent table "${tableName}"`);
50
+ }
51
+ if (!table.primaryKey) {
52
+ throw new Error(`Model "${modelName}" table "${tableName}" is missing a primary key`);
53
+ }
54
+ const columnNames = new Set(Object.keys(table.columns));
55
+ if (!model.fields || Object.keys(model.fields).length === 0) {
56
+ throw new Error(`Model "${modelName}" is missing fields`);
57
+ }
58
+ for (const [fieldName, fieldUnknown] of Object.entries(model.fields)) {
59
+ const field = fieldUnknown;
60
+ if (!field.column) {
61
+ throw new Error(`Model "${modelName}" field "${fieldName}" is missing column property`);
62
+ }
63
+ if (!columnNames.has(field.column)) {
64
+ throw new Error(
65
+ `Model "${modelName}" field "${fieldName}" references non-existent column "${field.column}" in table "${tableName}"`
66
+ );
67
+ }
68
+ }
69
+ if (!model.relations || typeof model.relations !== "object") {
70
+ throw new Error(
71
+ `Model "${modelName}" is missing required field "relations" (must be an object)`
72
+ );
73
+ }
74
+ }
75
+ }
76
+ for (const [tableName, tableUnknown] of Object.entries(storage.tables)) {
77
+ const table = tableUnknown;
78
+ const columnNames = new Set(Object.keys(table.columns));
79
+ if (!Array.isArray(table.uniques)) {
80
+ throw new Error(
81
+ `Table "${tableName}" is missing required field "uniques" (must be an array)`
82
+ );
83
+ }
84
+ if (!Array.isArray(table.indexes)) {
85
+ throw new Error(
86
+ `Table "${tableName}" is missing required field "indexes" (must be an array)`
87
+ );
88
+ }
89
+ if (!Array.isArray(table.foreignKeys)) {
90
+ throw new Error(
91
+ `Table "${tableName}" is missing required field "foreignKeys" (must be an array)`
92
+ );
93
+ }
94
+ if (table.primaryKey) {
95
+ for (const colName of table.primaryKey.columns) {
96
+ if (!columnNames.has(colName)) {
97
+ throw new Error(
98
+ `Table "${tableName}" primaryKey references non-existent column "${colName}"`
99
+ );
100
+ }
101
+ }
102
+ }
103
+ for (const unique of table.uniques) {
104
+ for (const colName of unique.columns) {
105
+ if (!columnNames.has(colName)) {
106
+ throw new Error(
107
+ `Table "${tableName}" unique constraint references non-existent column "${colName}"`
108
+ );
109
+ }
110
+ }
111
+ }
112
+ for (const index of table.indexes) {
113
+ for (const colName of index.columns) {
114
+ if (!columnNames.has(colName)) {
115
+ throw new Error(
116
+ `Table "${tableName}" index references non-existent column "${colName}"`
117
+ );
118
+ }
119
+ }
120
+ }
121
+ for (const fk of table.foreignKeys) {
122
+ for (const colName of fk.columns) {
123
+ if (!columnNames.has(colName)) {
124
+ throw new Error(
125
+ `Table "${tableName}" foreignKey references non-existent column "${colName}"`
126
+ );
127
+ }
128
+ }
129
+ if (!tableNames.has(fk.references.table)) {
130
+ throw new Error(
131
+ `Table "${tableName}" foreignKey references non-existent table "${fk.references.table}"`
132
+ );
133
+ }
134
+ const referencedTable = storage.tables[fk.references.table];
135
+ if (!referencedTable) {
136
+ throw new Error(
137
+ `Table "${tableName}" foreignKey references non-existent table "${fk.references.table}"`
138
+ );
139
+ }
140
+ const referencedColumnNames = new Set(Object.keys(referencedTable.columns));
141
+ for (const colName of fk.references.columns) {
142
+ if (!referencedColumnNames.has(colName)) {
143
+ throw new Error(
144
+ `Table "${tableName}" foreignKey references non-existent column "${colName}" in table "${fk.references.table}"`
145
+ );
146
+ }
147
+ }
148
+ if (fk.columns.length !== fk.references.columns.length) {
149
+ throw new Error(
150
+ `Table "${tableName}" foreignKey column count (${fk.columns.length}) does not match referenced column count (${fk.references.columns.length})`
151
+ );
152
+ }
153
+ }
154
+ }
155
+ },
156
+ generateContractTypes(ir, codecTypeImports, operationTypeImports, options) {
157
+ const allImports = [...codecTypeImports, ...operationTypeImports];
158
+ const importLines = allImports.map(
159
+ (imp) => `import type { ${imp.named} as ${imp.alias} } from '${imp.package}';`
160
+ );
161
+ const codecTypes = codecTypeImports.map((imp) => imp.alias).join(" & ");
162
+ const operationTypes = operationTypeImports.map((imp) => imp.alias).join(" & ");
163
+ const storage = ir.storage;
164
+ const models = ir.models;
165
+ const parameterizedRenderers = options?.parameterizedRenderers;
166
+ const storageType = this.generateStorageType(storage);
167
+ const modelsType = this.generateModelsType(models, storage, parameterizedRenderers);
168
+ const relationsType = this.generateRelationsType(ir.relations);
169
+ const mappingsType = this.generateMappingsType(models, storage, codecTypes, operationTypes);
170
+ return `// \u26A0\uFE0F GENERATED FILE - DO NOT EDIT
171
+ // This file is automatically generated by 'prisma-next contract emit'.
172
+ // To regenerate, run: prisma-next contract emit
173
+ ${importLines.join("\n")}
174
+
175
+ import type { SqlContract, SqlStorage, SqlMappings, ModelDefinition } from '@prisma-next/sql-contract/types';
176
+
177
+ export type CodecTypes = ${codecTypes || "Record<string, never>"};
178
+ export type LaneCodecTypes = CodecTypes;
179
+ export type OperationTypes = ${operationTypes || "Record<string, never>"};
180
+
181
+ export type Contract = SqlContract<
182
+ ${storageType},
183
+ ${modelsType},
184
+ ${relationsType},
185
+ ${mappingsType}
186
+ >;
187
+
188
+ export type Tables = Contract['storage']['tables'];
189
+ export type Models = Contract['models'];
190
+ export type Relations = Contract['relations'];
191
+ `;
192
+ },
193
+ generateStorageType(storage) {
194
+ const tables = [];
195
+ for (const [tableName, table] of Object.entries(storage.tables)) {
196
+ const columns = [];
197
+ for (const [colName, col] of Object.entries(table.columns)) {
198
+ const nullable = col.nullable ? "true" : "false";
199
+ const nativeType = `'${col.nativeType}'`;
200
+ const codecId = `'${col.codecId}'`;
201
+ columns.push(
202
+ `readonly ${colName}: { readonly nativeType: ${nativeType}; readonly codecId: ${codecId}; readonly nullable: ${nullable} }`
203
+ );
204
+ }
205
+ const tableParts = [`columns: { ${columns.join("; ")} }`];
206
+ if (table.primaryKey) {
207
+ const pkCols = table.primaryKey.columns.map((c) => `'${c}'`).join(", ");
208
+ const pkName = table.primaryKey.name ? `; readonly name: '${table.primaryKey.name}'` : "";
209
+ tableParts.push(`primaryKey: { readonly columns: readonly [${pkCols}]${pkName} }`);
210
+ }
211
+ const uniques = table.uniques.map((u) => {
212
+ const cols = u.columns.map((c) => `'${c}'`).join(", ");
213
+ const name = u.name ? `; readonly name: '${u.name}'` : "";
214
+ return `{ readonly columns: readonly [${cols}]${name} }`;
215
+ }).join(", ");
216
+ tableParts.push(`uniques: readonly [${uniques}]`);
217
+ const indexes = table.indexes.map((i) => {
218
+ const cols = i.columns.map((c) => `'${c}'`).join(", ");
219
+ const name = i.name ? `; readonly name: '${i.name}'` : "";
220
+ return `{ readonly columns: readonly [${cols}]${name} }`;
221
+ }).join(", ");
222
+ tableParts.push(`indexes: readonly [${indexes}]`);
223
+ const fks = table.foreignKeys.map((fk) => {
224
+ const cols = fk.columns.map((c) => `'${c}'`).join(", ");
225
+ const refCols = fk.references.columns.map((c) => `'${c}'`).join(", ");
226
+ const name = fk.name ? `; readonly name: '${fk.name}'` : "";
227
+ return `{ readonly columns: readonly [${cols}]; readonly references: { readonly table: '${fk.references.table}'; readonly columns: readonly [${refCols}] }${name} }`;
228
+ }).join(", ");
229
+ tableParts.push(`foreignKeys: readonly [${fks}]`);
230
+ tables.push(`readonly ${tableName}: { ${tableParts.join("; ")} }`);
231
+ }
232
+ return `{ readonly tables: { ${tables.join("; ")} } }`;
233
+ },
234
+ /**
235
+ * Renders the TypeScript type for a column.
236
+ * Uses parameterized renderer if column has typeParams and renderer exists.
237
+ * Falls back to CodecTypes['codecId']['output'] for scalar codecs.
238
+ */
239
+ renderColumnType(column, storage, parameterizedRenderers) {
240
+ const codecId = column.codecId;
241
+ if (column.typeRef && storage.types) {
242
+ const typeInstance = storage.types[column.typeRef];
243
+ if (typeInstance) {
244
+ const renderer = parameterizedRenderers?.get(typeInstance.codecId);
245
+ if (renderer) {
246
+ return renderer.render(typeInstance.typeParams, { codecTypesName: "CodecTypes" });
247
+ }
248
+ }
249
+ }
250
+ if (column.typeParams) {
251
+ const renderer = parameterizedRenderers?.get(codecId);
252
+ if (renderer) {
253
+ return renderer.render(column.typeParams, { codecTypesName: "CodecTypes" });
254
+ }
255
+ }
256
+ return `CodecTypes['${codecId}']['output']`;
257
+ },
258
+ generateModelsType(models, storage, parameterizedRenderers) {
259
+ if (!models) {
260
+ return "Record<string, never>";
261
+ }
262
+ const modelTypes = [];
263
+ for (const [modelName, model] of Object.entries(models)) {
264
+ const fields = [];
265
+ const tableName = model.storage.table;
266
+ const table = storage.tables[tableName];
267
+ if (table) {
268
+ for (const [fieldName, field] of Object.entries(model.fields)) {
269
+ const column = table.columns[field.column];
270
+ if (!column) {
271
+ fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
272
+ continue;
273
+ }
274
+ const baseType = this.renderColumnType(column, storage, parameterizedRenderers);
275
+ const nullable = column.nullable ?? false;
276
+ const jsType = nullable ? `${baseType} | null` : baseType;
277
+ fields.push(`readonly ${fieldName}: ${jsType}`);
278
+ }
279
+ } else {
280
+ for (const [fieldName, field] of Object.entries(model.fields)) {
281
+ fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
282
+ }
283
+ }
284
+ const relations = [];
285
+ for (const [relName, rel] of Object.entries(model.relations)) {
286
+ if (typeof rel === "object" && rel !== null && "on" in rel) {
287
+ const on = rel.on;
288
+ if (on.parentCols && on.childCols) {
289
+ const parentCols = on.parentCols.map((c) => `'${c}'`).join(", ");
290
+ const childCols = on.childCols.map((c) => `'${c}'`).join(", ");
291
+ relations.push(
292
+ `readonly ${relName}: { readonly on: { readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] } }`
293
+ );
294
+ }
295
+ }
296
+ }
297
+ const modelParts = [
298
+ `storage: { readonly table: '${tableName}' }`,
299
+ `fields: { ${fields.join("; ")} }`
300
+ ];
301
+ if (relations.length > 0) {
302
+ modelParts.push(`relations: { ${relations.join("; ")} }`);
303
+ }
304
+ modelTypes.push(`readonly ${modelName}: { ${modelParts.join("; ")} }`);
305
+ }
306
+ return `{ ${modelTypes.join("; ")} }`;
307
+ },
308
+ generateRelationsType(relations) {
309
+ if (!relations || Object.keys(relations).length === 0) {
310
+ return "Record<string, never>";
311
+ }
312
+ const tableEntries = [];
313
+ for (const [tableName, relsValue] of Object.entries(relations)) {
314
+ if (typeof relsValue !== "object" || relsValue === null) {
315
+ continue;
316
+ }
317
+ const rels = relsValue;
318
+ const relationEntries = [];
319
+ for (const [relName, relValue] of Object.entries(rels)) {
320
+ if (typeof relValue !== "object" || relValue === null) {
321
+ relationEntries.push(`readonly ${relName}: unknown`);
322
+ continue;
323
+ }
324
+ const { to, cardinality, on, through } = relValue;
325
+ const parts = [];
326
+ if (to) {
327
+ parts.push(`readonly to: '${to}'`);
328
+ }
329
+ if (cardinality) {
330
+ parts.push(`readonly cardinality: '${cardinality}'`);
331
+ }
332
+ if (on?.parentCols && on.childCols) {
333
+ const parentCols = on.parentCols.map((c) => `'${c}'`).join(", ");
334
+ const childCols = on.childCols.map((c) => `'${c}'`).join(", ");
335
+ parts.push(
336
+ `readonly on: { readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] }`
337
+ );
338
+ }
339
+ if (through) {
340
+ const parentCols = through.parentCols.map((c) => `'${c}'`).join(", ");
341
+ const childCols = through.childCols.map((c) => `'${c}'`).join(", ");
342
+ parts.push(
343
+ `readonly through: { readonly table: '${through.table}'; readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] }`
344
+ );
345
+ }
346
+ relationEntries.push(
347
+ parts.length > 0 ? `readonly ${relName}: { ${parts.join("; ")} }` : `readonly ${relName}: unknown`
348
+ );
349
+ }
350
+ tableEntries.push(`readonly ${tableName}: { ${relationEntries.join("; ")} }`);
351
+ }
352
+ return `{ ${tableEntries.join("; ")} }`;
353
+ },
354
+ generateMappingsType(models, storage, codecTypes, operationTypes) {
355
+ if (!models) {
356
+ return `SqlMappings & { readonly codecTypes: ${codecTypes || "Record<string, never>"}; readonly operationTypes: ${operationTypes || "Record<string, never>"}; }`;
357
+ }
358
+ const modelToTable = [];
359
+ const tableToModel = [];
360
+ const fieldToColumn = [];
361
+ const columnToField = [];
362
+ for (const [modelName, model] of Object.entries(models)) {
363
+ const tableName = model.storage.table;
364
+ modelToTable.push(`readonly ${modelName}: '${tableName}'`);
365
+ tableToModel.push(`readonly ${tableName}: '${modelName}'`);
366
+ const fieldMap = [];
367
+ for (const [fieldName, field] of Object.entries(model.fields)) {
368
+ fieldMap.push(`readonly ${fieldName}: '${field.column}'`);
369
+ }
370
+ if (fieldMap.length > 0) {
371
+ fieldToColumn.push(`readonly ${modelName}: { ${fieldMap.join("; ")} }`);
372
+ }
373
+ if (storage.tables[tableName]) {
374
+ const colMap = [];
375
+ for (const [fieldName, field] of Object.entries(model.fields)) {
376
+ colMap.push(`readonly ${field.column}: '${fieldName}'`);
377
+ }
378
+ if (colMap.length > 0) {
379
+ columnToField.push(`readonly ${tableName}: { ${colMap.join("; ")} }`);
380
+ }
381
+ }
382
+ }
383
+ const parts = [];
384
+ if (modelToTable.length > 0) {
385
+ parts.push(`modelToTable: { ${modelToTable.join("; ")} }`);
386
+ }
387
+ if (tableToModel.length > 0) {
388
+ parts.push(`tableToModel: { ${tableToModel.join("; ")} }`);
389
+ }
390
+ if (fieldToColumn.length > 0) {
391
+ parts.push(`fieldToColumn: { ${fieldToColumn.join("; ")} }`);
392
+ }
393
+ if (columnToField.length > 0) {
394
+ parts.push(`columnToField: { ${columnToField.join("; ")} }`);
395
+ }
396
+ parts.push(`codecTypes: ${codecTypes || "Record<string, never>"}`);
397
+ parts.push(`operationTypes: ${operationTypes || "Record<string, never>"}`);
398
+ return `{ ${parts.join("; ")} }`;
399
+ }
400
+ };
401
+ export {
402
+ sqlTargetFamilyHook
403
+ };
404
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ContractIR } from '@prisma-next/contract/ir';\nimport type {\n GenerateContractTypesOptions,\n TypesImportSpec,\n ValidationContext,\n} from '@prisma-next/contract/types';\nimport type {\n ModelDefinition,\n ModelField,\n SqlStorage,\n StorageColumn,\n StorageTable,\n} from '@prisma-next/sql-contract/types';\n\nexport const sqlTargetFamilyHook = {\n id: 'sql',\n\n validateTypes(ir: ContractIR, _ctx: ValidationContext): void {\n const storage = ir.storage as SqlStorage | undefined;\n if (!storage || !storage.tables) {\n return;\n }\n\n // Validate codec ID format (ns/name@version). Adapter-provided codecs are available regardless of contract.extensionPacks (which is for framework extensions); TypeScript prevents invalid usage and runtime validates availability.\n\n const typeIdRegex = /^([^/]+)\\/([^@]+)@(\\d+)$/;\n\n for (const [tableName, tableUnknown] of Object.entries(storage.tables)) {\n const table = tableUnknown as StorageTable;\n for (const [colName, colUnknown] of Object.entries(table.columns)) {\n const col = colUnknown as { codecId?: string };\n const codecId = col.codecId;\n if (!codecId) {\n throw new Error(`Column \"${colName}\" in table \"${tableName}\" is missing codecId`);\n }\n\n const match = codecId.match(typeIdRegex);\n if (!match || !match[1]) {\n throw new Error(\n `Column \"${colName}\" in table \"${tableName}\" has invalid codec ID format \"${codecId}\". Expected format: ns/name@version`,\n );\n }\n }\n }\n },\n\n validateStructure(ir: ContractIR): void {\n if (ir.targetFamily !== 'sql') {\n throw new Error(`Expected targetFamily \"sql\", got \"${ir.targetFamily}\"`);\n }\n\n const storage = ir.storage as SqlStorage | undefined;\n if (!storage || !storage.tables) {\n throw new Error('SQL contract must have storage.tables');\n }\n\n const models = ir.models as Record<string, ModelDefinition> | undefined;\n const tableNames = new Set(Object.keys(storage.tables));\n\n if (models) {\n for (const [modelName, modelUnknown] of Object.entries(models)) {\n const model = modelUnknown as ModelDefinition;\n if (!model.storage?.table) {\n throw new Error(`Model \"${modelName}\" is missing storage.table`);\n }\n\n const tableName = model.storage.table;\n if (!tableNames.has(tableName)) {\n throw new Error(`Model \"${modelName}\" references non-existent table \"${tableName}\"`);\n }\n\n const table = storage.tables[tableName];\n if (!table) {\n throw new Error(`Model \"${modelName}\" references non-existent table \"${tableName}\"`);\n }\n\n if (!table.primaryKey) {\n throw new Error(`Model \"${modelName}\" table \"${tableName}\" is missing a primary key`);\n }\n\n const columnNames = new Set(Object.keys(table.columns));\n if (!model.fields || Object.keys(model.fields).length === 0) {\n throw new Error(`Model \"${modelName}\" is missing fields`);\n }\n\n for (const [fieldName, fieldUnknown] of Object.entries(model.fields)) {\n const field = fieldUnknown as ModelField;\n if (!field.column) {\n throw new Error(`Model \"${modelName}\" field \"${fieldName}\" is missing column property`);\n }\n\n if (!columnNames.has(field.column)) {\n throw new Error(\n `Model \"${modelName}\" field \"${fieldName}\" references non-existent column \"${field.column}\" in table \"${tableName}\"`,\n );\n }\n }\n\n if (!model.relations || typeof model.relations !== 'object') {\n throw new Error(\n `Model \"${modelName}\" is missing required field \"relations\" (must be an object)`,\n );\n }\n }\n }\n\n for (const [tableName, tableUnknown] of Object.entries(storage.tables)) {\n const table = tableUnknown as StorageTable;\n const columnNames = new Set(Object.keys(table.columns));\n\n // Column structure (nullable, nativeType, codecId) and table arrays (uniques, indexes, foreignKeys)\n // are validated by Arktype schema validation - no need to re-check here.\n // We only validate logical consistency (foreign key references, model references, etc.)\n\n if (!Array.isArray(table.uniques)) {\n throw new Error(\n `Table \"${tableName}\" is missing required field \"uniques\" (must be an array)`,\n );\n }\n if (!Array.isArray(table.indexes)) {\n throw new Error(\n `Table \"${tableName}\" is missing required field \"indexes\" (must be an array)`,\n );\n }\n if (!Array.isArray(table.foreignKeys)) {\n throw new Error(\n `Table \"${tableName}\" is missing required field \"foreignKeys\" (must be an array)`,\n );\n }\n\n if (table.primaryKey) {\n for (const colName of table.primaryKey.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" primaryKey references non-existent column \"${colName}\"`,\n );\n }\n }\n }\n\n for (const unique of table.uniques) {\n for (const colName of unique.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" unique constraint references non-existent column \"${colName}\"`,\n );\n }\n }\n }\n\n for (const index of table.indexes) {\n for (const colName of index.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" index references non-existent column \"${colName}\"`,\n );\n }\n }\n }\n\n for (const fk of table.foreignKeys) {\n for (const colName of fk.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\"`,\n );\n }\n }\n\n if (!tableNames.has(fk.references.table)) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent table \"${fk.references.table}\"`,\n );\n }\n\n const referencedTable = storage.tables[fk.references.table];\n if (!referencedTable) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent table \"${fk.references.table}\"`,\n );\n }\n\n const referencedColumnNames = new Set(Object.keys(referencedTable.columns));\n for (const colName of fk.references.columns) {\n if (!referencedColumnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\" in table \"${fk.references.table}\"`,\n );\n }\n }\n\n if (fk.columns.length !== fk.references.columns.length) {\n throw new Error(\n `Table \"${tableName}\" foreignKey column count (${fk.columns.length}) does not match referenced column count (${fk.references.columns.length})`,\n );\n }\n }\n }\n },\n\n generateContractTypes(\n ir: ContractIR,\n codecTypeImports: ReadonlyArray<TypesImportSpec>,\n operationTypeImports: ReadonlyArray<TypesImportSpec>,\n options?: GenerateContractTypesOptions,\n ): string {\n const allImports = [...codecTypeImports, ...operationTypeImports];\n const importLines = allImports.map(\n (imp) => `import type { ${imp.named} as ${imp.alias} } from '${imp.package}';`,\n );\n\n const codecTypes = codecTypeImports.map((imp) => imp.alias).join(' & ');\n const operationTypes = operationTypeImports.map((imp) => imp.alias).join(' & ');\n\n const storage = ir.storage as SqlStorage;\n const models = ir.models as Record<string, ModelDefinition>;\n const parameterizedRenderers = options?.parameterizedRenderers;\n\n const storageType = this.generateStorageType(storage);\n const modelsType = this.generateModelsType(models, storage, parameterizedRenderers);\n const relationsType = this.generateRelationsType(ir.relations);\n const mappingsType = this.generateMappingsType(models, storage, codecTypes, operationTypes);\n\n return `// ⚠️ GENERATED FILE - DO NOT EDIT\n// This file is automatically generated by 'prisma-next contract emit'.\n// To regenerate, run: prisma-next contract emit\n${importLines.join('\\n')}\n\nimport type { SqlContract, SqlStorage, SqlMappings, ModelDefinition } from '@prisma-next/sql-contract/types';\n\nexport type CodecTypes = ${codecTypes || 'Record<string, never>'};\nexport type LaneCodecTypes = CodecTypes;\nexport type OperationTypes = ${operationTypes || 'Record<string, never>'};\n\nexport type Contract = SqlContract<\n ${storageType},\n ${modelsType},\n ${relationsType},\n ${mappingsType}\n>;\n\nexport type Tables = Contract['storage']['tables'];\nexport type Models = Contract['models'];\nexport type Relations = Contract['relations'];\n`;\n },\n\n generateStorageType(storage: SqlStorage): string {\n const tables: string[] = [];\n for (const [tableName, table] of Object.entries(storage.tables)) {\n const columns: string[] = [];\n for (const [colName, col] of Object.entries(table.columns)) {\n const nullable = col.nullable ? 'true' : 'false';\n const nativeType = `'${col.nativeType}'`;\n const codecId = `'${col.codecId}'`;\n columns.push(\n `readonly ${colName}: { readonly nativeType: ${nativeType}; readonly codecId: ${codecId}; readonly nullable: ${nullable} }`,\n );\n }\n\n const tableParts: string[] = [`columns: { ${columns.join('; ')} }`];\n\n if (table.primaryKey) {\n const pkCols = table.primaryKey.columns.map((c) => `'${c}'`).join(', ');\n const pkName = table.primaryKey.name ? `; readonly name: '${table.primaryKey.name}'` : '';\n tableParts.push(`primaryKey: { readonly columns: readonly [${pkCols}]${pkName} }`);\n }\n\n const uniques = table.uniques\n .map((u) => {\n const cols = u.columns.map((c: string) => `'${c}'`).join(', ');\n const name = u.name ? `; readonly name: '${u.name}'` : '';\n return `{ readonly columns: readonly [${cols}]${name} }`;\n })\n .join(', ');\n tableParts.push(`uniques: readonly [${uniques}]`);\n\n const indexes = table.indexes\n .map((i) => {\n const cols = i.columns.map((c: string) => `'${c}'`).join(', ');\n const name = i.name ? `; readonly name: '${i.name}'` : '';\n return `{ readonly columns: readonly [${cols}]${name} }`;\n })\n .join(', ');\n tableParts.push(`indexes: readonly [${indexes}]`);\n\n const fks = table.foreignKeys\n .map((fk) => {\n const cols = fk.columns.map((c: string) => `'${c}'`).join(', ');\n const refCols = fk.references.columns.map((c: string) => `'${c}'`).join(', ');\n const name = fk.name ? `; readonly name: '${fk.name}'` : '';\n return `{ readonly columns: readonly [${cols}]; readonly references: { readonly table: '${fk.references.table}'; readonly columns: readonly [${refCols}] }${name} }`;\n })\n .join(', ');\n tableParts.push(`foreignKeys: readonly [${fks}]`);\n\n tables.push(`readonly ${tableName}: { ${tableParts.join('; ')} }`);\n }\n\n return `{ readonly tables: { ${tables.join('; ')} } }`;\n },\n\n /**\n * Renders the TypeScript type for a column.\n * Uses parameterized renderer if column has typeParams and renderer exists.\n * Falls back to CodecTypes['codecId']['output'] for scalar codecs.\n */\n renderColumnType(\n column: StorageColumn,\n storage: SqlStorage,\n parameterizedRenderers?: GenerateContractTypesOptions['parameterizedRenderers'],\n ): string {\n const codecId = column.codecId;\n\n // Check for typeRef - use the referenced type instance's params\n if (column.typeRef && storage.types) {\n const typeInstance = storage.types[column.typeRef];\n if (typeInstance) {\n const renderer = parameterizedRenderers?.get(typeInstance.codecId);\n if (renderer) {\n return renderer.render(typeInstance.typeParams, { codecTypesName: 'CodecTypes' });\n }\n }\n }\n\n // Check for inline typeParams\n if (column.typeParams) {\n const renderer = parameterizedRenderers?.get(codecId);\n if (renderer) {\n return renderer.render(column.typeParams, { codecTypesName: 'CodecTypes' });\n }\n }\n\n // Default: scalar codec type\n return `CodecTypes['${codecId}']['output']`;\n },\n\n generateModelsType(\n models: Record<string, ModelDefinition> | undefined,\n storage: SqlStorage,\n parameterizedRenderers?: GenerateContractTypesOptions['parameterizedRenderers'],\n ): string {\n if (!models) {\n return 'Record<string, never>';\n }\n\n const modelTypes: string[] = [];\n for (const [modelName, model] of Object.entries(models)) {\n const fields: string[] = [];\n const tableName = model.storage.table;\n const table = storage.tables[tableName];\n\n if (table) {\n for (const [fieldName, field] of Object.entries(model.fields)) {\n const column = table.columns[field.column];\n if (!column) {\n fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);\n continue;\n }\n\n const baseType = this.renderColumnType(column, storage, parameterizedRenderers);\n const nullable = column.nullable ?? false;\n const jsType = nullable ? `${baseType} | null` : baseType;\n\n fields.push(`readonly ${fieldName}: ${jsType}`);\n }\n } else {\n for (const [fieldName, field] of Object.entries(model.fields)) {\n fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);\n }\n }\n\n const relations: string[] = [];\n for (const [relName, rel] of Object.entries(model.relations)) {\n if (typeof rel === 'object' && rel !== null && 'on' in rel) {\n const on = rel.on as { parentCols?: string[]; childCols?: string[] };\n if (on.parentCols && on.childCols) {\n const parentCols = on.parentCols.map((c) => `'${c}'`).join(', ');\n const childCols = on.childCols.map((c) => `'${c}'`).join(', ');\n relations.push(\n `readonly ${relName}: { readonly on: { readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] } }`,\n );\n }\n }\n }\n\n const modelParts: string[] = [\n `storage: { readonly table: '${tableName}' }`,\n `fields: { ${fields.join('; ')} }`,\n ];\n\n if (relations.length > 0) {\n modelParts.push(`relations: { ${relations.join('; ')} }`);\n }\n\n modelTypes.push(`readonly ${modelName}: { ${modelParts.join('; ')} }`);\n }\n\n return `{ ${modelTypes.join('; ')} }`;\n },\n\n generateRelationsType(relations: Record<string, unknown> | undefined): string {\n if (!relations || Object.keys(relations).length === 0) {\n return 'Record<string, never>';\n }\n\n const tableEntries: string[] = [];\n for (const [tableName, relsValue] of Object.entries(relations)) {\n if (typeof relsValue !== 'object' || relsValue === null) {\n continue;\n }\n const rels = relsValue as Record<string, unknown>;\n const relationEntries: string[] = [];\n for (const [relName, relValue] of Object.entries(rels)) {\n if (typeof relValue !== 'object' || relValue === null) {\n relationEntries.push(`readonly ${relName}: unknown`);\n continue;\n }\n const { to, cardinality, on, through } = relValue as {\n readonly to?: string;\n readonly cardinality?: string;\n readonly on?: {\n readonly parentCols?: readonly string[];\n readonly childCols?: readonly string[];\n };\n readonly through?: {\n readonly table: string;\n readonly parentCols: readonly string[];\n readonly childCols: readonly string[];\n };\n };\n\n const parts: string[] = [];\n if (to) {\n parts.push(`readonly to: '${to}'`);\n }\n if (cardinality) {\n parts.push(`readonly cardinality: '${cardinality}'`);\n }\n if (on?.parentCols && on.childCols) {\n const parentCols = on.parentCols.map((c) => `'${c}'`).join(', ');\n const childCols = on.childCols.map((c) => `'${c}'`).join(', ');\n parts.push(\n `readonly on: { readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] }`,\n );\n }\n if (through) {\n const parentCols = through.parentCols.map((c) => `'${c}'`).join(', ');\n const childCols = through.childCols.map((c) => `'${c}'`).join(', ');\n parts.push(\n `readonly through: { readonly table: '${through.table}'; readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] }`,\n );\n }\n\n relationEntries.push(\n parts.length > 0\n ? `readonly ${relName}: { ${parts.join('; ')} }`\n : `readonly ${relName}: unknown`,\n );\n }\n tableEntries.push(`readonly ${tableName}: { ${relationEntries.join('; ')} }`);\n }\n\n return `{ ${tableEntries.join('; ')} }`;\n },\n\n generateMappingsType(\n models: Record<string, ModelDefinition> | undefined,\n storage: SqlStorage,\n codecTypes: string,\n operationTypes: string,\n ): string {\n if (!models) {\n return `SqlMappings & { readonly codecTypes: ${codecTypes || 'Record<string, never>'}; readonly operationTypes: ${operationTypes || 'Record<string, never>'}; }`;\n }\n\n const modelToTable: string[] = [];\n const tableToModel: string[] = [];\n const fieldToColumn: string[] = [];\n const columnToField: string[] = [];\n\n for (const [modelName, model] of Object.entries(models)) {\n const tableName = model.storage.table;\n modelToTable.push(`readonly ${modelName}: '${tableName}'`);\n tableToModel.push(`readonly ${tableName}: '${modelName}'`);\n\n const fieldMap: string[] = [];\n for (const [fieldName, field] of Object.entries(model.fields)) {\n fieldMap.push(`readonly ${fieldName}: '${field.column}'`);\n }\n\n if (fieldMap.length > 0) {\n fieldToColumn.push(`readonly ${modelName}: { ${fieldMap.join('; ')} }`);\n }\n\n if (storage.tables[tableName]) {\n const colMap: string[] = [];\n for (const [fieldName, field] of Object.entries(model.fields)) {\n colMap.push(`readonly ${field.column}: '${fieldName}'`);\n }\n\n if (colMap.length > 0) {\n columnToField.push(`readonly ${tableName}: { ${colMap.join('; ')} }`);\n }\n }\n }\n\n const parts: string[] = [];\n if (modelToTable.length > 0) {\n parts.push(`modelToTable: { ${modelToTable.join('; ')} }`);\n }\n if (tableToModel.length > 0) {\n parts.push(`tableToModel: { ${tableToModel.join('; ')} }`);\n }\n if (fieldToColumn.length > 0) {\n parts.push(`fieldToColumn: { ${fieldToColumn.join('; ')} }`);\n }\n if (columnToField.length > 0) {\n parts.push(`columnToField: { ${columnToField.join('; ')} }`);\n }\n parts.push(`codecTypes: ${codecTypes || 'Record<string, never>'}`);\n parts.push(`operationTypes: ${operationTypes || 'Record<string, never>'}`);\n\n return `{ ${parts.join('; ')} }`;\n },\n} as const;\n"],"mappings":";AAcO,IAAM,sBAAsB;AAAA,EACjC,IAAI;AAAA,EAEJ,cAAc,IAAgB,MAA+B;AAC3D,UAAM,UAAU,GAAG;AACnB,QAAI,CAAC,WAAW,CAAC,QAAQ,QAAQ;AAC/B;AAAA,IACF;AAIA,UAAM,cAAc;AAEpB,eAAW,CAAC,WAAW,YA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AAEzE,WAAO,KAAK,MAAM,KAAK,IAAI,CAAC;AAAA,EAC9B;AACF;","names":[]}
package/package.json CHANGED
@@ -1,41 +1,36 @@
1
1
  {
2
2
  "name": "@prisma-next/sql-contract-emitter",
3
- "version": "0.3.0-pr.94.2",
3
+ "version": "0.3.0-pr.95.2",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
- "engines": {
7
- "node": ">=20"
8
- },
9
6
  "description": "SQL emitter hook for Prisma Next",
10
7
  "dependencies": {
11
- "@prisma-next/contract": "0.3.0-pr.94.2",
12
- "@prisma-next/emitter": "0.3.0-pr.94.2",
13
- "@prisma-next/sql-contract": "0.3.0-pr.94.2"
8
+ "@prisma-next/contract": "0.3.0-pr.95.2",
9
+ "@prisma-next/emitter": "0.3.0-pr.95.2",
10
+ "@prisma-next/sql-contract": "0.3.0-pr.95.2"
14
11
  },
15
12
  "devDependencies": {
16
- "tsdown": "0.18.4",
13
+ "tsup": "8.5.1",
17
14
  "typescript": "5.9.3",
18
15
  "vitest": "4.0.16",
19
16
  "@prisma-next/test-utils": "0.0.1",
20
- "@prisma-next/tsconfig": "0.0.0",
21
- "@prisma-next/tsdown": "0.0.0"
17
+ "@prisma-next/tsconfig": "0.0.0"
22
18
  },
23
19
  "files": [
24
20
  "dist",
25
21
  "src"
26
22
  ],
27
23
  "exports": {
28
- ".": "./dist/index.mjs",
29
- "./package.json": "./package.json"
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js"
27
+ }
30
28
  },
31
- "main": "./dist/index.mjs",
32
- "module": "./dist/index.mjs",
33
- "types": "./dist/index.d.mts",
34
29
  "scripts": {
35
- "build": "tsdown",
30
+ "build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
36
31
  "test": "vitest run --passWithNoTests",
37
32
  "test:coverage": "vitest run --coverage --passWithNoTests",
38
- "typecheck": "tsc --noEmit",
33
+ "typecheck": "tsc --project tsconfig.json --noEmit",
39
34
  "lint": "biome check . --error-on-warnings",
40
35
  "lint:fix": "biome check --write .",
41
36
  "lint:fix:unsafe": "biome check --write --unsafe .",
package/src/index.ts CHANGED
@@ -1,9 +1,14 @@
1
1
  import type { ContractIR } from '@prisma-next/contract/ir';
2
- import type { TypesImportSpec, ValidationContext } from '@prisma-next/contract/types';
2
+ import type {
3
+ GenerateContractTypesOptions,
4
+ TypesImportSpec,
5
+ ValidationContext,
6
+ } from '@prisma-next/contract/types';
3
7
  import type {
4
8
  ModelDefinition,
5
9
  ModelField,
6
10
  SqlStorage,
11
+ StorageColumn,
7
12
  StorageTable,
8
13
  } from '@prisma-next/sql-contract/types';
9
14
 
@@ -197,6 +202,7 @@ export const sqlTargetFamilyHook = {
197
202
  ir: ContractIR,
198
203
  codecTypeImports: ReadonlyArray<TypesImportSpec>,
199
204
  operationTypeImports: ReadonlyArray<TypesImportSpec>,
205
+ options?: GenerateContractTypesOptions,
200
206
  ): string {
201
207
  const allImports = [...codecTypeImports, ...operationTypeImports];
202
208
  const importLines = allImports.map(
@@ -208,9 +214,10 @@ export const sqlTargetFamilyHook = {
208
214
 
209
215
  const storage = ir.storage as SqlStorage;
210
216
  const models = ir.models as Record<string, ModelDefinition>;
217
+ const parameterizedRenderers = options?.parameterizedRenderers;
211
218
 
212
219
  const storageType = this.generateStorageType(storage);
213
- const modelsType = this.generateModelsType(models, storage);
220
+ const modelsType = this.generateModelsType(models, storage, parameterizedRenderers);
214
221
  const relationsType = this.generateRelationsType(ir.relations);
215
222
  const mappingsType = this.generateMappingsType(models, storage, codecTypes, operationTypes);
216
223
 
@@ -293,9 +300,45 @@ export type Relations = Contract['relations'];
293
300
  return `{ readonly tables: { ${tables.join('; ')} } }`;
294
301
  },
295
302
 
303
+ /**
304
+ * Renders the TypeScript type for a column.
305
+ * Uses parameterized renderer if column has typeParams and renderer exists.
306
+ * Falls back to CodecTypes['codecId']['output'] for scalar codecs.
307
+ */
308
+ renderColumnType(
309
+ column: StorageColumn,
310
+ storage: SqlStorage,
311
+ parameterizedRenderers?: GenerateContractTypesOptions['parameterizedRenderers'],
312
+ ): string {
313
+ const codecId = column.codecId;
314
+
315
+ // Check for typeRef - use the referenced type instance's params
316
+ if (column.typeRef && storage.types) {
317
+ const typeInstance = storage.types[column.typeRef];
318
+ if (typeInstance) {
319
+ const renderer = parameterizedRenderers?.get(typeInstance.codecId);
320
+ if (renderer) {
321
+ return renderer.render(typeInstance.typeParams, { codecTypesName: 'CodecTypes' });
322
+ }
323
+ }
324
+ }
325
+
326
+ // Check for inline typeParams
327
+ if (column.typeParams) {
328
+ const renderer = parameterizedRenderers?.get(codecId);
329
+ if (renderer) {
330
+ return renderer.render(column.typeParams, { codecTypesName: 'CodecTypes' });
331
+ }
332
+ }
333
+
334
+ // Default: scalar codec type
335
+ return `CodecTypes['${codecId}']['output']`;
336
+ },
337
+
296
338
  generateModelsType(
297
339
  models: Record<string, ModelDefinition> | undefined,
298
340
  storage: SqlStorage,
341
+ parameterizedRenderers?: GenerateContractTypesOptions['parameterizedRenderers'],
299
342
  ): string {
300
343
  if (!models) {
301
344
  return 'Record<string, never>';
@@ -315,11 +358,9 @@ export type Relations = Contract['relations'];
315
358
  continue;
316
359
  }
317
360
 
318
- const typeId = column.codecId;
361
+ const baseType = this.renderColumnType(column, storage, parameterizedRenderers);
319
362
  const nullable = column.nullable ?? false;
320
- const jsType = nullable
321
- ? `CodecTypes['${typeId}']['output'] | null`
322
- : `CodecTypes['${typeId}']['output']`;
363
+ const jsType = nullable ? `${baseType} | null` : baseType;
323
364
 
324
365
  fields.push(`readonly ${fieldName}: ${jsType}`);
325
366
  }
package/dist/index.d.mts DELETED
@@ -1,18 +0,0 @@
1
- import { ContractIR } from "@prisma-next/contract/ir";
2
- import { TypesImportSpec, ValidationContext } from "@prisma-next/contract/types";
3
- import { ModelDefinition, SqlStorage } from "@prisma-next/sql-contract/types";
4
-
5
- //#region src/index.d.ts
6
- declare const sqlTargetFamilyHook: {
7
- readonly id: "sql";
8
- readonly validateTypes: (ir: ContractIR, _ctx: ValidationContext) => void;
9
- readonly validateStructure: (ir: ContractIR) => void;
10
- readonly generateContractTypes: (ir: ContractIR, codecTypeImports: ReadonlyArray<TypesImportSpec>, operationTypeImports: ReadonlyArray<TypesImportSpec>) => string;
11
- readonly generateStorageType: (storage: SqlStorage) => string;
12
- readonly generateModelsType: (models: Record<string, ModelDefinition> | undefined, storage: SqlStorage) => string;
13
- readonly generateRelationsType: (relations: Record<string, unknown> | undefined) => string;
14
- readonly generateMappingsType: (models: Record<string, ModelDefinition> | undefined, storage: SqlStorage, codecTypes: string, operationTypes: string) => string;
15
- };
16
- //#endregion
17
- export { sqlTargetFamilyHook };
18
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;cASa;;EAAA,SAAA,aA2dH,EAAA,CAAA,EAAA,EAxdU,UAwdV,EAAA,IAAA,EAxd4B,iBAwd5B,EAAA,GAAA,IAAA;EAxdU,SAAA,iBAAA,EAAA,CAAA,EAAA,EA6BI,UA7BJ,EAAA,GAAA,IAAA;EAAkB,SAAA,qBAAA,EAAA,CAAA,EAAA,EAwL9B,UAxL8B,EAAA,gBAAA,EAyLhB,aAzLgB,CAyLF,eAzLE,CAAA,EAAA,oBAAA,EA0LZ,aA1LY,CA0LE,eA1LF,CAAA,EAAA,GAAA,MAAA;EA6Bd,SAAA,mBAAA,EAAA,CAAA,OAAA,EAuMO,UAvMP,EAAA,GAAA,MAAA;EA2JhB,SAAA,kBAAA,EAAA,CAAA,MAAA,EAoGI,MApGJ,CAAA,MAAA,EAoGmB,eApGnB,CAAA,GAAA,SAAA,EAAA,OAAA,EAqGK,UArGL,EAAA,GAAA,MAAA;EAC4B,SAAA,qBAAA,EAAA,CAAA,SAAA,EAmKD,MAnKC,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,SAAA,EAAA,GAAA,MAAA;EAAd,SAAA,oBAAA,EAAA,CAAA,MAAA,EAqOV,MArOU,CAAA,MAAA,EAqOK,eArOL,CAAA,GAAA,SAAA,EAAA,OAAA,EAsOT,UAtOS,EAAA,UAAA,EAAA,MAAA,EAAA,cAAA,EAAA,MAAA,EAAA,GAAA,MAAA;CACkB"}
package/dist/index.mjs DELETED
@@ -1,228 +0,0 @@
1
- //#region src/index.ts
2
- const sqlTargetFamilyHook = {
3
- id: "sql",
4
- validateTypes(ir, _ctx) {
5
- const storage = ir.storage;
6
- if (!storage || !storage.tables) return;
7
- const typeIdRegex = /^([^/]+)\/([^@]+)@(\d+)$/;
8
- for (const [tableName, tableUnknown] of Object.entries(storage.tables)) {
9
- const table = tableUnknown;
10
- for (const [colName, colUnknown] of Object.entries(table.columns)) {
11
- const codecId = colUnknown.codecId;
12
- if (!codecId) throw new Error(`Column "${colName}" in table "${tableName}" is missing codecId`);
13
- const match = codecId.match(typeIdRegex);
14
- if (!match || !match[1]) throw new Error(`Column "${colName}" in table "${tableName}" has invalid codec ID format "${codecId}". Expected format: ns/name@version`);
15
- }
16
- }
17
- },
18
- validateStructure(ir) {
19
- if (ir.targetFamily !== "sql") throw new Error(`Expected targetFamily "sql", got "${ir.targetFamily}"`);
20
- const storage = ir.storage;
21
- if (!storage || !storage.tables) throw new Error("SQL contract must have storage.tables");
22
- const models = ir.models;
23
- const tableNames = new Set(Object.keys(storage.tables));
24
- if (models) for (const [modelName, modelUnknown] of Object.entries(models)) {
25
- const model = modelUnknown;
26
- if (!model.storage?.table) throw new Error(`Model "${modelName}" is missing storage.table`);
27
- const tableName = model.storage.table;
28
- if (!tableNames.has(tableName)) throw new Error(`Model "${modelName}" references non-existent table "${tableName}"`);
29
- const table = storage.tables[tableName];
30
- if (!table) throw new Error(`Model "${modelName}" references non-existent table "${tableName}"`);
31
- if (!table.primaryKey) throw new Error(`Model "${modelName}" table "${tableName}" is missing a primary key`);
32
- const columnNames = new Set(Object.keys(table.columns));
33
- if (!model.fields || Object.keys(model.fields).length === 0) throw new Error(`Model "${modelName}" is missing fields`);
34
- for (const [fieldName, fieldUnknown] of Object.entries(model.fields)) {
35
- const field = fieldUnknown;
36
- if (!field.column) throw new Error(`Model "${modelName}" field "${fieldName}" is missing column property`);
37
- if (!columnNames.has(field.column)) throw new Error(`Model "${modelName}" field "${fieldName}" references non-existent column "${field.column}" in table "${tableName}"`);
38
- }
39
- if (!model.relations || typeof model.relations !== "object") throw new Error(`Model "${modelName}" is missing required field "relations" (must be an object)`);
40
- }
41
- for (const [tableName, tableUnknown] of Object.entries(storage.tables)) {
42
- const table = tableUnknown;
43
- const columnNames = new Set(Object.keys(table.columns));
44
- if (!Array.isArray(table.uniques)) throw new Error(`Table "${tableName}" is missing required field "uniques" (must be an array)`);
45
- if (!Array.isArray(table.indexes)) throw new Error(`Table "${tableName}" is missing required field "indexes" (must be an array)`);
46
- if (!Array.isArray(table.foreignKeys)) throw new Error(`Table "${tableName}" is missing required field "foreignKeys" (must be an array)`);
47
- if (table.primaryKey) {
48
- for (const colName of table.primaryKey.columns) if (!columnNames.has(colName)) throw new Error(`Table "${tableName}" primaryKey references non-existent column "${colName}"`);
49
- }
50
- for (const unique of table.uniques) for (const colName of unique.columns) if (!columnNames.has(colName)) throw new Error(`Table "${tableName}" unique constraint references non-existent column "${colName}"`);
51
- for (const index of table.indexes) for (const colName of index.columns) if (!columnNames.has(colName)) throw new Error(`Table "${tableName}" index references non-existent column "${colName}"`);
52
- for (const fk of table.foreignKeys) {
53
- for (const colName of fk.columns) if (!columnNames.has(colName)) throw new Error(`Table "${tableName}" foreignKey references non-existent column "${colName}"`);
54
- if (!tableNames.has(fk.references.table)) throw new Error(`Table "${tableName}" foreignKey references non-existent table "${fk.references.table}"`);
55
- const referencedTable = storage.tables[fk.references.table];
56
- if (!referencedTable) throw new Error(`Table "${tableName}" foreignKey references non-existent table "${fk.references.table}"`);
57
- const referencedColumnNames = new Set(Object.keys(referencedTable.columns));
58
- for (const colName of fk.references.columns) if (!referencedColumnNames.has(colName)) throw new Error(`Table "${tableName}" foreignKey references non-existent column "${colName}" in table "${fk.references.table}"`);
59
- if (fk.columns.length !== fk.references.columns.length) throw new Error(`Table "${tableName}" foreignKey column count (${fk.columns.length}) does not match referenced column count (${fk.references.columns.length})`);
60
- }
61
- }
62
- },
63
- generateContractTypes(ir, codecTypeImports, operationTypeImports) {
64
- const importLines = [...codecTypeImports, ...operationTypeImports].map((imp) => `import type { ${imp.named} as ${imp.alias} } from '${imp.package}';`);
65
- const codecTypes = codecTypeImports.map((imp) => imp.alias).join(" & ");
66
- const operationTypes = operationTypeImports.map((imp) => imp.alias).join(" & ");
67
- const storage = ir.storage;
68
- const models = ir.models;
69
- const storageType = this.generateStorageType(storage);
70
- const modelsType = this.generateModelsType(models, storage);
71
- const relationsType = this.generateRelationsType(ir.relations);
72
- const mappingsType = this.generateMappingsType(models, storage, codecTypes, operationTypes);
73
- return `// ⚠️ GENERATED FILE - DO NOT EDIT
74
- // This file is automatically generated by 'prisma-next contract emit'.
75
- // To regenerate, run: prisma-next contract emit
76
- ${importLines.join("\n")}
77
-
78
- import type { SqlContract, SqlStorage, SqlMappings, ModelDefinition } from '@prisma-next/sql-contract/types';
79
-
80
- export type CodecTypes = ${codecTypes || "Record<string, never>"};
81
- export type LaneCodecTypes = CodecTypes;
82
- export type OperationTypes = ${operationTypes || "Record<string, never>"};
83
-
84
- export type Contract = SqlContract<
85
- ${storageType},
86
- ${modelsType},
87
- ${relationsType},
88
- ${mappingsType}
89
- >;
90
-
91
- export type Tables = Contract['storage']['tables'];
92
- export type Models = Contract['models'];
93
- export type Relations = Contract['relations'];
94
- `;
95
- },
96
- generateStorageType(storage) {
97
- const tables = [];
98
- for (const [tableName, table] of Object.entries(storage.tables)) {
99
- const columns = [];
100
- for (const [colName, col] of Object.entries(table.columns)) {
101
- const nullable = col.nullable ? "true" : "false";
102
- const nativeType = `'${col.nativeType}'`;
103
- const codecId = `'${col.codecId}'`;
104
- columns.push(`readonly ${colName}: { readonly nativeType: ${nativeType}; readonly codecId: ${codecId}; readonly nullable: ${nullable} }`);
105
- }
106
- const tableParts = [`columns: { ${columns.join("; ")} }`];
107
- if (table.primaryKey) {
108
- const pkCols = table.primaryKey.columns.map((c) => `'${c}'`).join(", ");
109
- const pkName = table.primaryKey.name ? `; readonly name: '${table.primaryKey.name}'` : "";
110
- tableParts.push(`primaryKey: { readonly columns: readonly [${pkCols}]${pkName} }`);
111
- }
112
- const uniques = table.uniques.map((u) => {
113
- return `{ readonly columns: readonly [${u.columns.map((c) => `'${c}'`).join(", ")}]${u.name ? `; readonly name: '${u.name}'` : ""} }`;
114
- }).join(", ");
115
- tableParts.push(`uniques: readonly [${uniques}]`);
116
- const indexes = table.indexes.map((i) => {
117
- return `{ readonly columns: readonly [${i.columns.map((c) => `'${c}'`).join(", ")}]${i.name ? `; readonly name: '${i.name}'` : ""} }`;
118
- }).join(", ");
119
- tableParts.push(`indexes: readonly [${indexes}]`);
120
- const fks = table.foreignKeys.map((fk) => {
121
- const cols = fk.columns.map((c) => `'${c}'`).join(", ");
122
- const refCols = fk.references.columns.map((c) => `'${c}'`).join(", ");
123
- const name = fk.name ? `; readonly name: '${fk.name}'` : "";
124
- return `{ readonly columns: readonly [${cols}]; readonly references: { readonly table: '${fk.references.table}'; readonly columns: readonly [${refCols}] }${name} }`;
125
- }).join(", ");
126
- tableParts.push(`foreignKeys: readonly [${fks}]`);
127
- tables.push(`readonly ${tableName}: { ${tableParts.join("; ")} }`);
128
- }
129
- return `{ readonly tables: { ${tables.join("; ")} } }`;
130
- },
131
- generateModelsType(models, storage) {
132
- if (!models) return "Record<string, never>";
133
- const modelTypes = [];
134
- for (const [modelName, model] of Object.entries(models)) {
135
- const fields = [];
136
- const tableName = model.storage.table;
137
- const table = storage.tables[tableName];
138
- if (table) for (const [fieldName, field] of Object.entries(model.fields)) {
139
- const column = table.columns[field.column];
140
- if (!column) {
141
- fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
142
- continue;
143
- }
144
- const typeId = column.codecId;
145
- const jsType = column.nullable ?? false ? `CodecTypes['${typeId}']['output'] | null` : `CodecTypes['${typeId}']['output']`;
146
- fields.push(`readonly ${fieldName}: ${jsType}`);
147
- }
148
- else for (const [fieldName, field] of Object.entries(model.fields)) fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
149
- const relations = [];
150
- for (const [relName, rel] of Object.entries(model.relations)) if (typeof rel === "object" && rel !== null && "on" in rel) {
151
- const on = rel.on;
152
- if (on.parentCols && on.childCols) {
153
- const parentCols = on.parentCols.map((c) => `'${c}'`).join(", ");
154
- const childCols = on.childCols.map((c) => `'${c}'`).join(", ");
155
- relations.push(`readonly ${relName}: { readonly on: { readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] } }`);
156
- }
157
- }
158
- const modelParts = [`storage: { readonly table: '${tableName}' }`, `fields: { ${fields.join("; ")} }`];
159
- if (relations.length > 0) modelParts.push(`relations: { ${relations.join("; ")} }`);
160
- modelTypes.push(`readonly ${modelName}: { ${modelParts.join("; ")} }`);
161
- }
162
- return `{ ${modelTypes.join("; ")} }`;
163
- },
164
- generateRelationsType(relations) {
165
- if (!relations || Object.keys(relations).length === 0) return "Record<string, never>";
166
- const tableEntries = [];
167
- for (const [tableName, relsValue] of Object.entries(relations)) {
168
- if (typeof relsValue !== "object" || relsValue === null) continue;
169
- const rels = relsValue;
170
- const relationEntries = [];
171
- for (const [relName, relValue] of Object.entries(rels)) {
172
- if (typeof relValue !== "object" || relValue === null) {
173
- relationEntries.push(`readonly ${relName}: unknown`);
174
- continue;
175
- }
176
- const { to, cardinality, on, through } = relValue;
177
- const parts = [];
178
- if (to) parts.push(`readonly to: '${to}'`);
179
- if (cardinality) parts.push(`readonly cardinality: '${cardinality}'`);
180
- if (on?.parentCols && on.childCols) {
181
- const parentCols = on.parentCols.map((c) => `'${c}'`).join(", ");
182
- const childCols = on.childCols.map((c) => `'${c}'`).join(", ");
183
- parts.push(`readonly on: { readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] }`);
184
- }
185
- if (through) {
186
- const parentCols = through.parentCols.map((c) => `'${c}'`).join(", ");
187
- const childCols = through.childCols.map((c) => `'${c}'`).join(", ");
188
- parts.push(`readonly through: { readonly table: '${through.table}'; readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] }`);
189
- }
190
- relationEntries.push(parts.length > 0 ? `readonly ${relName}: { ${parts.join("; ")} }` : `readonly ${relName}: unknown`);
191
- }
192
- tableEntries.push(`readonly ${tableName}: { ${relationEntries.join("; ")} }`);
193
- }
194
- return `{ ${tableEntries.join("; ")} }`;
195
- },
196
- generateMappingsType(models, storage, codecTypes, operationTypes) {
197
- if (!models) return `SqlMappings & { readonly codecTypes: ${codecTypes || "Record<string, never>"}; readonly operationTypes: ${operationTypes || "Record<string, never>"}; }`;
198
- const modelToTable = [];
199
- const tableToModel = [];
200
- const fieldToColumn = [];
201
- const columnToField = [];
202
- for (const [modelName, model] of Object.entries(models)) {
203
- const tableName = model.storage.table;
204
- modelToTable.push(`readonly ${modelName}: '${tableName}'`);
205
- tableToModel.push(`readonly ${tableName}: '${modelName}'`);
206
- const fieldMap = [];
207
- for (const [fieldName, field] of Object.entries(model.fields)) fieldMap.push(`readonly ${fieldName}: '${field.column}'`);
208
- if (fieldMap.length > 0) fieldToColumn.push(`readonly ${modelName}: { ${fieldMap.join("; ")} }`);
209
- if (storage.tables[tableName]) {
210
- const colMap = [];
211
- for (const [fieldName, field] of Object.entries(model.fields)) colMap.push(`readonly ${field.column}: '${fieldName}'`);
212
- if (colMap.length > 0) columnToField.push(`readonly ${tableName}: { ${colMap.join("; ")} }`);
213
- }
214
- }
215
- const parts = [];
216
- if (modelToTable.length > 0) parts.push(`modelToTable: { ${modelToTable.join("; ")} }`);
217
- if (tableToModel.length > 0) parts.push(`tableToModel: { ${tableToModel.join("; ")} }`);
218
- if (fieldToColumn.length > 0) parts.push(`fieldToColumn: { ${fieldToColumn.join("; ")} }`);
219
- if (columnToField.length > 0) parts.push(`columnToField: { ${columnToField.join("; ")} }`);
220
- parts.push(`codecTypes: ${codecTypes || "Record<string, never>"}`);
221
- parts.push(`operationTypes: ${operationTypes || "Record<string, never>"}`);
222
- return `{ ${parts.join("; ")} }`;
223
- }
224
- };
225
-
226
- //#endregion
227
- export { sqlTargetFamilyHook };
228
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":["tables: string[]","columns: string[]","tableParts: string[]","modelTypes: string[]","fields: string[]","relations: string[]","modelParts: string[]","tableEntries: string[]","relationEntries: string[]","parts: string[]","modelToTable: string[]","tableToModel: string[]","fieldToColumn: string[]","columnToField: string[]","fieldMap: string[]","colMap: string[]"],"sources":["../src/index.ts"],"sourcesContent":["import type { ContractIR } from '@prisma-next/contract/ir';\nimport type { TypesImportSpec, ValidationContext } from '@prisma-next/contract/types';\nimport type {\n ModelDefinition,\n ModelField,\n SqlStorage,\n StorageTable,\n} from '@prisma-next/sql-contract/types';\n\nexport const sqlTargetFamilyHook = {\n id: 'sql',\n\n validateTypes(ir: ContractIR, _ctx: ValidationContext): void {\n const storage = ir.storage as SqlStorage | undefined;\n if (!storage || !storage.tables) {\n return;\n }\n\n // Validate codec ID format (ns/name@version). Adapter-provided codecs are available regardless of contract.extensionPacks (which is for framework extensions); TypeScript prevents invalid usage and runtime validates availability.\n\n const typeIdRegex = /^([^/]+)\\/([^@]+)@(\\d+)$/;\n\n for (const [tableName, tableUnknown] of Object.entries(storage.tables)) {\n const table = tableUnknown as StorageTable;\n for (const [colName, colUnknown] of Object.entries(table.columns)) {\n const col = colUnknown as { codecId?: string };\n const codecId = col.codecId;\n if (!codecId) {\n throw new Error(`Column \"${colName}\" in table \"${tableName}\" is missing codecId`);\n }\n\n const match = codecId.match(typeIdRegex);\n if (!match || !match[1]) {\n throw new Error(\n `Column \"${colName}\" in table \"${tableName}\" has invalid codec ID format \"${codecId}\". Expected format: ns/name@version`,\n );\n }\n }\n }\n },\n\n validateStructure(ir: ContractIR): void {\n if (ir.targetFamily !== 'sql') {\n throw new Error(`Expected targetFamily \"sql\", got \"${ir.targetFamily}\"`);\n }\n\n const storage = ir.storage as SqlStorage | undefined;\n if (!storage || !storage.tables) {\n throw new Error('SQL contract must have storage.tables');\n }\n\n const models = ir.models as Record<string, ModelDefinition> | undefined;\n const tableNames = new Set(Object.keys(storage.tables));\n\n if (models) {\n for (const [modelName, modelUnknown] of Object.entries(models)) {\n const model = modelUnknown as ModelDefinition;\n if (!model.storage?.table) {\n throw new Error(`Model \"${modelName}\" is missing storage.table`);\n }\n\n const tableName = model.storage.table;\n if (!tableNames.has(tableName)) {\n throw new Error(`Model \"${modelName}\" references non-existent table \"${tableName}\"`);\n }\n\n const table = storage.tables[tableName];\n if (!table) {\n throw new Error(`Model \"${modelName}\" references non-existent table \"${tableName}\"`);\n }\n\n if (!table.primaryKey) {\n throw new Error(`Model \"${modelName}\" table \"${tableName}\" is missing a primary key`);\n }\n\n const columnNames = new Set(Object.keys(table.columns));\n if (!model.fields || Object.keys(model.fields).length === 0) {\n throw new Error(`Model \"${modelName}\" is missing fields`);\n }\n\n for (const [fieldName, fieldUnknown] of Object.entries(model.fields)) {\n const field = fieldUnknown as ModelField;\n if (!field.column) {\n throw new Error(`Model \"${modelName}\" field \"${fieldName}\" is missing column property`);\n }\n\n if (!columnNames.has(field.column)) {\n throw new Error(\n `Model \"${modelName}\" field \"${fieldName}\" references non-existent column \"${field.column}\" in table \"${tableName}\"`,\n );\n }\n }\n\n if (!model.relations || typeof model.relations !== 'object') {\n throw new Error(\n `Model \"${modelName}\" is missing required field \"relations\" (must be an object)`,\n );\n }\n }\n }\n\n for (const [tableName, tableUnknown] of Object.entries(storage.tables)) {\n const table = tableUnknown as StorageTable;\n const columnNames = new Set(Object.keys(table.columns));\n\n // Column structure (nullable, nativeType, codecId) and table arrays (uniques, indexes, foreignKeys)\n // are validated by Arktype schema validation - no need to re-check here.\n // We only validate logical consistency (foreign key references, model references, etc.)\n\n if (!Array.isArray(table.uniques)) {\n throw new Error(\n `Table \"${tableName}\" is missing required field \"uniques\" (must be an array)`,\n );\n }\n if (!Array.isArray(table.indexes)) {\n throw new Error(\n `Table \"${tableName}\" is missing required field \"indexes\" (must be an array)`,\n );\n }\n if (!Array.isArray(table.foreignKeys)) {\n throw new Error(\n `Table \"${tableName}\" is missing required field \"foreignKeys\" (must be an array)`,\n );\n }\n\n if (table.primaryKey) {\n for (const colName of table.primaryKey.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" primaryKey references non-existent column \"${colName}\"`,\n );\n }\n }\n }\n\n for (const unique of table.uniques) {\n for (const colName of unique.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" unique constraint references non-existent column \"${colName}\"`,\n );\n }\n }\n }\n\n for (const index of table.indexes) {\n for (const colName of index.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" index references non-existent column \"${colName}\"`,\n );\n }\n }\n }\n\n for (const fk of table.foreignKeys) {\n for (const colName of fk.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\"`,\n );\n }\n }\n\n if (!tableNames.has(fk.references.table)) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent table \"${fk.references.table}\"`,\n );\n }\n\n const referencedTable = storage.tables[fk.references.table];\n if (!referencedTable) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent table \"${fk.references.table}\"`,\n );\n }\n\n const referencedColumnNames = new Set(Object.keys(referencedTable.columns));\n for (const colName of fk.references.columns) {\n if (!referencedColumnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\" in table \"${fk.references.table}\"`,\n );\n }\n }\n\n if (fk.columns.length !== fk.references.columns.length) {\n throw new Error(\n `Table \"${tableName}\" foreignKey column count (${fk.columns.length}) does not match referenced column count (${fk.references.columns.length})`,\n );\n }\n }\n }\n },\n\n generateContractTypes(\n ir: ContractIR,\n codecTypeImports: ReadonlyArray<TypesImportSpec>,\n operationTypeImports: ReadonlyArray<TypesImportSpec>,\n ): string {\n const allImports = [...codecTypeImports, ...operationTypeImports];\n const importLines = allImports.map(\n (imp) => `import type { ${imp.named} as ${imp.alias} } from '${imp.package}';`,\n );\n\n const codecTypes = codecTypeImports.map((imp) => imp.alias).join(' & ');\n const operationTypes = operationTypeImports.map((imp) => imp.alias).join(' & ');\n\n const storage = ir.storage as SqlStorage;\n const models = ir.models as Record<string, ModelDefinition>;\n\n const storageType = this.generateStorageType(storage);\n const modelsType = this.generateModelsType(models, storage);\n const relationsType = this.generateRelationsType(ir.relations);\n const mappingsType = this.generateMappingsType(models, storage, codecTypes, operationTypes);\n\n return `// ⚠️ GENERATED FILE - DO NOT EDIT\n// This file is automatically generated by 'prisma-next contract emit'.\n// To regenerate, run: prisma-next contract emit\n${importLines.join('\\n')}\n\nimport type { SqlContract, SqlStorage, SqlMappings, ModelDefinition } from '@prisma-next/sql-contract/types';\n\nexport type CodecTypes = ${codecTypes || 'Record<string, never>'};\nexport type LaneCodecTypes = CodecTypes;\nexport type OperationTypes = ${operationTypes || 'Record<string, never>'};\n\nexport type Contract = SqlContract<\n ${storageType},\n ${modelsType},\n ${relationsType},\n ${mappingsType}\n>;\n\nexport type Tables = Contract['storage']['tables'];\nexport type Models = Contract['models'];\nexport type Relations = Contract['relations'];\n`;\n },\n\n generateStorageType(storage: SqlStorage): string {\n const tables: string[] = [];\n for (const [tableName, table] of Object.entries(storage.tables)) {\n const columns: string[] = [];\n for (const [colName, col] of Object.entries(table.columns)) {\n const nullable = col.nullable ? 'true' : 'false';\n const nativeType = `'${col.nativeType}'`;\n const codecId = `'${col.codecId}'`;\n columns.push(\n `readonly ${colName}: { readonly nativeType: ${nativeType}; readonly codecId: ${codecId}; readonly nullable: ${nullable} }`,\n );\n }\n\n const tableParts: string[] = [`columns: { ${columns.join('; ')} }`];\n\n if (table.primaryKey) {\n const pkCols = table.primaryKey.columns.map((c) => `'${c}'`).join(', ');\n const pkName = table.primaryKey.name ? `; readonly name: '${table.primaryKey.name}'` : '';\n tableParts.push(`primaryKey: { readonly columns: readonly [${pkCols}]${pkName} }`);\n }\n\n const uniques = table.uniques\n .map((u) => {\n const cols = u.columns.map((c: string) => `'${c}'`).join(', ');\n const name = u.name ? `; readonly name: '${u.name}'` : '';\n return `{ readonly columns: readonly [${cols}]${name} }`;\n })\n .join(', ');\n tableParts.push(`uniques: readonly [${uniques}]`);\n\n const indexes = table.indexes\n .map((i) => {\n const cols = i.columns.map((c: string) => `'${c}'`).join(', ');\n const name = i.name ? `; readonly name: '${i.name}'` : '';\n return `{ readonly columns: readonly [${cols}]${name} }`;\n })\n .join(', ');\n tableParts.push(`indexes: readonly [${indexes}]`);\n\n const fks = table.foreignKeys\n .map((fk) => {\n const cols = fk.columns.map((c: string) => `'${c}'`).join(', ');\n const refCols = fk.references.columns.map((c: string) => `'${c}'`).join(', ');\n const name = fk.name ? `; readonly name: '${fk.name}'` : '';\n return `{ readonly columns: readonly [${cols}]; readonly references: { readonly table: '${fk.references.table}'; readonly columns: readonly [${refCols}] }${name} }`;\n })\n .join(', ');\n tableParts.push(`foreignKeys: readonly [${fks}]`);\n\n tables.push(`readonly ${tableName}: { ${tableParts.join('; ')} }`);\n }\n\n return `{ readonly tables: { ${tables.join('; ')} } }`;\n },\n\n generateModelsType(\n models: Record<string, ModelDefinition> | undefined,\n storage: SqlStorage,\n ): string {\n if (!models) {\n return 'Record<string, never>';\n }\n\n const modelTypes: string[] = [];\n for (const [modelName, model] of Object.entries(models)) {\n const fields: string[] = [];\n const tableName = model.storage.table;\n const table = storage.tables[tableName];\n\n if (table) {\n for (const [fieldName, field] of Object.entries(model.fields)) {\n const column = table.columns[field.column];\n if (!column) {\n fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);\n continue;\n }\n\n const typeId = column.codecId;\n const nullable = column.nullable ?? false;\n const jsType = nullable\n ? `CodecTypes['${typeId}']['output'] | null`\n : `CodecTypes['${typeId}']['output']`;\n\n fields.push(`readonly ${fieldName}: ${jsType}`);\n }\n } else {\n for (const [fieldName, field] of Object.entries(model.fields)) {\n fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);\n }\n }\n\n const relations: string[] = [];\n for (const [relName, rel] of Object.entries(model.relations)) {\n if (typeof rel === 'object' && rel !== null && 'on' in rel) {\n const on = rel.on as { parentCols?: string[]; childCols?: string[] };\n if (on.parentCols && on.childCols) {\n const parentCols = on.parentCols.map((c) => `'${c}'`).join(', ');\n const childCols = on.childCols.map((c) => `'${c}'`).join(', ');\n relations.push(\n `readonly ${relName}: { readonly on: { readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] } }`,\n );\n }\n }\n }\n\n const modelParts: string[] = [\n `storage: { readonly table: '${tableName}' }`,\n `fields: { ${fields.join('; ')} }`,\n ];\n\n if (relations.length > 0) {\n modelParts.push(`relations: { ${relations.join('; ')} }`);\n }\n\n modelTypes.push(`readonly ${modelName}: { ${modelParts.join('; ')} }`);\n }\n\n return `{ ${modelTypes.join('; ')} }`;\n },\n\n generateRelationsType(relations: Record<string, unknown> | undefined): string {\n if (!relations || Object.keys(relations).length === 0) {\n return 'Record<string, never>';\n }\n\n const tableEntries: string[] = [];\n for (const [tableName, relsValue] of Object.entries(relations)) {\n if (typeof relsValue !== 'object' || relsValue === null) {\n continue;\n }\n const rels = relsValue as Record<string, unknown>;\n const relationEntries: string[] = [];\n for (const [relName, relValue] of Object.entries(rels)) {\n if (typeof relValue !== 'object' || relValue === null) {\n relationEntries.push(`readonly ${relName}: unknown`);\n continue;\n }\n const { to, cardinality, on, through } = relValue as {\n readonly to?: string;\n readonly cardinality?: string;\n readonly on?: {\n readonly parentCols?: readonly string[];\n readonly childCols?: readonly string[];\n };\n readonly through?: {\n readonly table: string;\n readonly parentCols: readonly string[];\n readonly childCols: readonly string[];\n };\n };\n\n const parts: string[] = [];\n if (to) {\n parts.push(`readonly to: '${to}'`);\n }\n if (cardinality) {\n parts.push(`readonly cardinality: '${cardinality}'`);\n }\n if (on?.parentCols && on.childCols) {\n const parentCols = on.parentCols.map((c) => `'${c}'`).join(', ');\n const childCols = on.childCols.map((c) => `'${c}'`).join(', ');\n parts.push(\n `readonly on: { readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] }`,\n );\n }\n if (through) {\n const parentCols = through.parentCols.map((c) => `'${c}'`).join(', ');\n const childCols = through.childCols.map((c) => `'${c}'`).join(', ');\n parts.push(\n `readonly through: { readonly table: '${through.table}'; readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] }`,\n );\n }\n\n relationEntries.push(\n parts.length > 0\n ? `readonly ${relName}: { ${parts.join('; ')} }`\n : `readonly ${relName}: unknown`,\n );\n }\n tableEntries.push(`readonly ${tableName}: { ${relationEntries.join('; ')} }`);\n }\n\n return `{ ${tableEntries.join('; ')} }`;\n },\n\n generateMappingsType(\n models: Record<string, ModelDefinition> | undefined,\n storage: SqlStorage,\n codecTypes: string,\n operationTypes: string,\n ): string {\n if (!models) {\n return `SqlMappings & { readonly codecTypes: ${codecTypes || 'Record<string, never>'}; readonly operationTypes: ${operationTypes || 'Record<string, never>'}; }`;\n }\n\n const modelToTable: string[] = [];\n const tableToModel: string[] = [];\n const fieldToColumn: string[] = [];\n const columnToField: string[] = [];\n\n for (const [modelName, model] of Object.entries(models)) {\n const tableName = model.storage.table;\n modelToTable.push(`readonly ${modelName}: '${tableName}'`);\n tableToModel.push(`readonly ${tableName}: '${modelName}'`);\n\n const fieldMap: string[] = [];\n for (const [fieldName, field] of Object.entries(model.fields)) {\n fieldMap.push(`readonly ${fieldName}: '${field.column}'`);\n }\n\n if (fieldMap.length > 0) {\n fieldToColumn.push(`readonly ${modelName}: { ${fieldMap.join('; ')} }`);\n }\n\n if (storage.tables[tableName]) {\n const colMap: string[] = [];\n for (const [fieldName, field] of Object.entries(model.fields)) {\n colMap.push(`readonly ${field.column}: '${fieldName}'`);\n }\n\n if (colMap.length > 0) {\n columnToField.push(`readonly ${tableName}: { ${colMap.join('; ')} }`);\n }\n }\n }\n\n const parts: string[] = [];\n if (modelToTable.length > 0) {\n parts.push(`modelToTable: { ${modelToTable.join('; ')} }`);\n }\n if (tableToModel.length > 0) {\n parts.push(`tableToModel: { ${tableToModel.join('; ')} }`);\n }\n if (fieldToColumn.length > 0) {\n parts.push(`fieldToColumn: { ${fieldToColumn.join('; ')} }`);\n }\n if (columnToField.length > 0) {\n parts.push(`columnToField: { ${columnToField.join('; ')} }`);\n }\n parts.push(`codecTypes: ${codecTypes || 'Record<string, never>'}`);\n parts.push(`operationTypes: ${operationTypes || 'Record<string, never>'}`);\n\n return `{ ${parts.join('; ')} }`;\n },\n} as const;\n"],"mappings":";AASA,MAAa,sBAAsB;CACjC,IAAI;CAEJ,cAAc,IAAgB,MAA+B;EAC3D,MAAM,UAAU,GAAG;AACnB,MAAI,CAAC,WAAW,CAAC,QAAQ,OACvB;EAKF,MAAM,cAAc;AAEpB,OAAK,MAAM,CAAC,WAAW,iBAAiB,OAAO,QAAQ,QAAQ,OAAO,EAAE;GACtE,MAAM,QAAQ;AACd,QAAK,MAAM,CAAC,SAAS,eAAe,OAAO,QAAQ,MAAM,QAAQ,EAAE;IAEjE,MAAM,UADM,WACQ;AACpB,QAAI,CAAC,QACH,OAAM,IAAI,MAAM,WAAW,QAAQ,cAAc,UAAU,sBAAsB;IAGnF,MAAM,QAAQ,QAAQ,MAAM,YAAY;AACxC,QAAI,CAAC,SAAS,CAAC,MAAM,GACnB,OAAM,IAAI,MACR,WAAW,QAAQ,cAAc,UAAU,iCAAiC,QAAQ,qCACrF;;;;CAMT,kBAAkB,IAAsB;AACtC,MAAI,GAAG,iBAAiB,MACtB,OAAM,IAAI,MAAM,qCAAqC,GAAG,aAAa,GAAG;EAG1E,MAAM,UAAU,GAAG;AACnB,MAAI,CAAC,WAAW,CAAC,QAAQ,OACvB,OAAM,IAAI,MAAM,wCAAwC;EAG1D,MAAM,SAAS,GAAG;EACl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