@prisma-next/sql-contract-emitter 0.3.0-pr.93.5 → 0.3.0-pr.94.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.
- package/dist/index.d.mts +18 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +228 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +16 -11
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -379
- package/dist/index.js.map +0 -1
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;;;;C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AM,OAAO,CAC3D,UAAS,KAAK,YAAY,UAAU,KAAK,MAAM,OAAO,GAAG;AAG3D,OAAI,SAAS,SAAS,EACpB,eAAc,KAAK,YAAY,UAAU,MAAM,SAAS,KAAK,KAAK,CAAC,IAAI;AAGzE,OAAI,QAAQ,OAAO,YAAY;IAC7B,MAAMC,SAAmB,EAAE;AAC3B,SAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,MAAM,OAAO,CAC3D,QAAO,KAAK,YAAY,MAAM,OAAO,KAAK,UAAU,GAAG;AAGzD,QAAI,OAAO,SAAS,EAClB,eAAc,KAAK,YAAY,UAAU,MAAM,OAAO,KAAK,KAAK,CAAC,IAAI;;;EAK3E,MAAMN,QAAkB,EAAE;AAC1B,MAAI,aAAa,SAAS,EACxB,OAAM,KAAK,mBAAmB,aAAa,KAAK,KAAK,CAAC,IAAI;AAE5D,MAAI,aAAa,SAAS,EACxB,OAAM,KAAK,mBAAmB,aAAa,KAAK,KAAK,CAAC,IAAI;AAE5D,MAAI,cAAc,SAAS,EACzB,OAAM,KAAK,oBAAoB,cAAc,KAAK,KAAK,CAAC,IAAI;AAE9D,MAAI,cAAc,SAAS,EACzB,OAAM,KAAK,oBAAoB,cAAc,KAAK,KAAK,CAAC,IAAI;AAE9D,QAAM,KAAK,eAAe,cAAc,0BAA0B;AAClE,QAAM,KAAK,mBAAmB,kBAAkB,0BAA0B;AAE1E,SAAO,KAAK,MAAM,KAAK,KAAK,CAAC;;CAEhC"}
|
package/package.json
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-contract-emitter",
|
|
3
|
-
"version": "0.3.0-pr.
|
|
3
|
+
"version": "0.3.0-pr.94.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=20"
|
|
8
|
+
},
|
|
6
9
|
"description": "SQL emitter hook for Prisma Next",
|
|
7
10
|
"dependencies": {
|
|
8
|
-
"@prisma-next/contract": "0.3.0-pr.
|
|
9
|
-
"@prisma-next/emitter": "0.3.0-pr.
|
|
10
|
-
"@prisma-next/sql-contract": "0.3.0-pr.
|
|
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"
|
|
11
14
|
},
|
|
12
15
|
"devDependencies": {
|
|
13
|
-
"
|
|
16
|
+
"tsdown": "0.18.4",
|
|
14
17
|
"typescript": "5.9.3",
|
|
15
18
|
"vitest": "4.0.16",
|
|
16
19
|
"@prisma-next/test-utils": "0.0.1",
|
|
17
|
-
"@prisma-next/tsconfig": "0.0.0"
|
|
20
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
21
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
18
22
|
},
|
|
19
23
|
"files": [
|
|
20
24
|
"dist",
|
|
21
25
|
"src"
|
|
22
26
|
],
|
|
23
27
|
"exports": {
|
|
24
|
-
".":
|
|
25
|
-
|
|
26
|
-
"import": "./dist/index.js"
|
|
27
|
-
}
|
|
28
|
+
".": "./dist/index.mjs",
|
|
29
|
+
"./package.json": "./package.json"
|
|
28
30
|
},
|
|
31
|
+
"main": "./dist/index.mjs",
|
|
32
|
+
"module": "./dist/index.mjs",
|
|
33
|
+
"types": "./dist/index.d.mts",
|
|
29
34
|
"scripts": {
|
|
30
|
-
"build": "
|
|
35
|
+
"build": "tsdown",
|
|
31
36
|
"test": "vitest run --passWithNoTests",
|
|
32
37
|
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
33
38
|
"typecheck": "tsc --noEmit",
|
package/dist/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ContractIR } from '@prisma-next/contract/ir';
|
|
2
|
-
import type { TypesImportSpec, ValidationContext } from '@prisma-next/contract/types';
|
|
3
|
-
import type { ModelDefinition, SqlStorage } 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>) => string;
|
|
9
|
-
readonly generateStorageType: (storage: SqlStorage) => string;
|
|
10
|
-
readonly generateModelsType: (models: Record<string, ModelDefinition> | undefined, storage: SqlStorage) => string;
|
|
11
|
-
readonly generateRelationsType: (relations: Record<string, unknown> | undefined) => string;
|
|
12
|
-
readonly generateMappingsType: (models: Record<string, ModelDefinition> | undefined, storage: SqlStorage, codecTypes: string, operationTypes: string) => string;
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,KAAK,EACV,eAAe,EAEf,UAAU,EAEX,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,KACnD,MAAM;4CAyCoB,UAAU,KAAG,MAAM;0CAwDtC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,SAAS,WAC1C,UAAU,KAClB,MAAM;gDA8DwB,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
DELETED
|
@@ -1,379 +0,0 @@
|
|
|
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) {
|
|
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 storageType = this.generateStorageType(storage);
|
|
166
|
-
const modelsType = this.generateModelsType(models, storage);
|
|
167
|
-
const relationsType = this.generateRelationsType(ir.relations);
|
|
168
|
-
const mappingsType = this.generateMappingsType(models, storage, codecTypes, operationTypes);
|
|
169
|
-
return `// \u26A0\uFE0F GENERATED FILE - DO NOT EDIT
|
|
170
|
-
// This file is automatically generated by 'prisma-next contract emit'.
|
|
171
|
-
// To regenerate, run: prisma-next contract emit
|
|
172
|
-
${importLines.join("\n")}
|
|
173
|
-
|
|
174
|
-
import type { SqlContract, SqlStorage, SqlMappings, ModelDefinition } from '@prisma-next/sql-contract/types';
|
|
175
|
-
|
|
176
|
-
export type CodecTypes = ${codecTypes || "Record<string, never>"};
|
|
177
|
-
export type LaneCodecTypes = CodecTypes;
|
|
178
|
-
export type OperationTypes = ${operationTypes || "Record<string, never>"};
|
|
179
|
-
|
|
180
|
-
export type Contract = SqlContract<
|
|
181
|
-
${storageType},
|
|
182
|
-
${modelsType},
|
|
183
|
-
${relationsType},
|
|
184
|
-
${mappingsType}
|
|
185
|
-
>;
|
|
186
|
-
|
|
187
|
-
export type Tables = Contract['storage']['tables'];
|
|
188
|
-
export type Models = Contract['models'];
|
|
189
|
-
export type Relations = Contract['relations'];
|
|
190
|
-
`;
|
|
191
|
-
},
|
|
192
|
-
generateStorageType(storage) {
|
|
193
|
-
const tables = [];
|
|
194
|
-
for (const [tableName, table] of Object.entries(storage.tables)) {
|
|
195
|
-
const columns = [];
|
|
196
|
-
for (const [colName, col] of Object.entries(table.columns)) {
|
|
197
|
-
const nullable = col.nullable ? "true" : "false";
|
|
198
|
-
const nativeType = `'${col.nativeType}'`;
|
|
199
|
-
const codecId = `'${col.codecId}'`;
|
|
200
|
-
columns.push(
|
|
201
|
-
`readonly ${colName}: { readonly nativeType: ${nativeType}; readonly codecId: ${codecId}; readonly nullable: ${nullable} }`
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
const tableParts = [`columns: { ${columns.join("; ")} }`];
|
|
205
|
-
if (table.primaryKey) {
|
|
206
|
-
const pkCols = table.primaryKey.columns.map((c) => `'${c}'`).join(", ");
|
|
207
|
-
const pkName = table.primaryKey.name ? `; readonly name: '${table.primaryKey.name}'` : "";
|
|
208
|
-
tableParts.push(`primaryKey: { readonly columns: readonly [${pkCols}]${pkName} }`);
|
|
209
|
-
}
|
|
210
|
-
const uniques = table.uniques.map((u) => {
|
|
211
|
-
const cols = u.columns.map((c) => `'${c}'`).join(", ");
|
|
212
|
-
const name = u.name ? `; readonly name: '${u.name}'` : "";
|
|
213
|
-
return `{ readonly columns: readonly [${cols}]${name} }`;
|
|
214
|
-
}).join(", ");
|
|
215
|
-
tableParts.push(`uniques: readonly [${uniques}]`);
|
|
216
|
-
const indexes = table.indexes.map((i) => {
|
|
217
|
-
const cols = i.columns.map((c) => `'${c}'`).join(", ");
|
|
218
|
-
const name = i.name ? `; readonly name: '${i.name}'` : "";
|
|
219
|
-
return `{ readonly columns: readonly [${cols}]${name} }`;
|
|
220
|
-
}).join(", ");
|
|
221
|
-
tableParts.push(`indexes: readonly [${indexes}]`);
|
|
222
|
-
const fks = table.foreignKeys.map((fk) => {
|
|
223
|
-
const cols = fk.columns.map((c) => `'${c}'`).join(", ");
|
|
224
|
-
const refCols = fk.references.columns.map((c) => `'${c}'`).join(", ");
|
|
225
|
-
const name = fk.name ? `; readonly name: '${fk.name}'` : "";
|
|
226
|
-
return `{ readonly columns: readonly [${cols}]; readonly references: { readonly table: '${fk.references.table}'; readonly columns: readonly [${refCols}] }${name} }`;
|
|
227
|
-
}).join(", ");
|
|
228
|
-
tableParts.push(`foreignKeys: readonly [${fks}]`);
|
|
229
|
-
tables.push(`readonly ${tableName}: { ${tableParts.join("; ")} }`);
|
|
230
|
-
}
|
|
231
|
-
return `{ readonly tables: { ${tables.join("; ")} } }`;
|
|
232
|
-
},
|
|
233
|
-
generateModelsType(models, storage) {
|
|
234
|
-
if (!models) {
|
|
235
|
-
return "Record<string, never>";
|
|
236
|
-
}
|
|
237
|
-
const modelTypes = [];
|
|
238
|
-
for (const [modelName, model] of Object.entries(models)) {
|
|
239
|
-
const fields = [];
|
|
240
|
-
const tableName = model.storage.table;
|
|
241
|
-
const table = storage.tables[tableName];
|
|
242
|
-
if (table) {
|
|
243
|
-
for (const [fieldName, field] of Object.entries(model.fields)) {
|
|
244
|
-
const column = table.columns[field.column];
|
|
245
|
-
if (!column) {
|
|
246
|
-
fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
const typeId = column.codecId;
|
|
250
|
-
const nullable = column.nullable ?? false;
|
|
251
|
-
const jsType = nullable ? `CodecTypes['${typeId}']['output'] | null` : `CodecTypes['${typeId}']['output']`;
|
|
252
|
-
fields.push(`readonly ${fieldName}: ${jsType}`);
|
|
253
|
-
}
|
|
254
|
-
} else {
|
|
255
|
-
for (const [fieldName, field] of Object.entries(model.fields)) {
|
|
256
|
-
fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
const relations = [];
|
|
260
|
-
for (const [relName, rel] of Object.entries(model.relations)) {
|
|
261
|
-
if (typeof rel === "object" && rel !== null && "on" in rel) {
|
|
262
|
-
const on = rel.on;
|
|
263
|
-
if (on.parentCols && on.childCols) {
|
|
264
|
-
const parentCols = on.parentCols.map((c) => `'${c}'`).join(", ");
|
|
265
|
-
const childCols = on.childCols.map((c) => `'${c}'`).join(", ");
|
|
266
|
-
relations.push(
|
|
267
|
-
`readonly ${relName}: { readonly on: { readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] } }`
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
const modelParts = [
|
|
273
|
-
`storage: { readonly table: '${tableName}' }`,
|
|
274
|
-
`fields: { ${fields.join("; ")} }`
|
|
275
|
-
];
|
|
276
|
-
if (relations.length > 0) {
|
|
277
|
-
modelParts.push(`relations: { ${relations.join("; ")} }`);
|
|
278
|
-
}
|
|
279
|
-
modelTypes.push(`readonly ${modelName}: { ${modelParts.join("; ")} }`);
|
|
280
|
-
}
|
|
281
|
-
return `{ ${modelTypes.join("; ")} }`;
|
|
282
|
-
},
|
|
283
|
-
generateRelationsType(relations) {
|
|
284
|
-
if (!relations || Object.keys(relations).length === 0) {
|
|
285
|
-
return "Record<string, never>";
|
|
286
|
-
}
|
|
287
|
-
const tableEntries = [];
|
|
288
|
-
for (const [tableName, relsValue] of Object.entries(relations)) {
|
|
289
|
-
if (typeof relsValue !== "object" || relsValue === null) {
|
|
290
|
-
continue;
|
|
291
|
-
}
|
|
292
|
-
const rels = relsValue;
|
|
293
|
-
const relationEntries = [];
|
|
294
|
-
for (const [relName, relValue] of Object.entries(rels)) {
|
|
295
|
-
if (typeof relValue !== "object" || relValue === null) {
|
|
296
|
-
relationEntries.push(`readonly ${relName}: unknown`);
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
const { to, cardinality, on, through } = relValue;
|
|
300
|
-
const parts = [];
|
|
301
|
-
if (to) {
|
|
302
|
-
parts.push(`readonly to: '${to}'`);
|
|
303
|
-
}
|
|
304
|
-
if (cardinality) {
|
|
305
|
-
parts.push(`readonly cardinality: '${cardinality}'`);
|
|
306
|
-
}
|
|
307
|
-
if (on?.parentCols && on.childCols) {
|
|
308
|
-
const parentCols = on.parentCols.map((c) => `'${c}'`).join(", ");
|
|
309
|
-
const childCols = on.childCols.map((c) => `'${c}'`).join(", ");
|
|
310
|
-
parts.push(
|
|
311
|
-
`readonly on: { readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] }`
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
if (through) {
|
|
315
|
-
const parentCols = through.parentCols.map((c) => `'${c}'`).join(", ");
|
|
316
|
-
const childCols = through.childCols.map((c) => `'${c}'`).join(", ");
|
|
317
|
-
parts.push(
|
|
318
|
-
`readonly through: { readonly table: '${through.table}'; readonly parentCols: readonly [${parentCols}]; readonly childCols: readonly [${childCols}] }`
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
relationEntries.push(
|
|
322
|
-
parts.length > 0 ? `readonly ${relName}: { ${parts.join("; ")} }` : `readonly ${relName}: unknown`
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
tableEntries.push(`readonly ${tableName}: { ${relationEntries.join("; ")} }`);
|
|
326
|
-
}
|
|
327
|
-
return `{ ${tableEntries.join("; ")} }`;
|
|
328
|
-
},
|
|
329
|
-
generateMappingsType(models, storage, codecTypes, operationTypes) {
|
|
330
|
-
if (!models) {
|
|
331
|
-
return `SqlMappings & { readonly codecTypes: ${codecTypes || "Record<string, never>"}; readonly operationTypes: ${operationTypes || "Record<string, never>"}; }`;
|
|
332
|
-
}
|
|
333
|
-
const modelToTable = [];
|
|
334
|
-
const tableToModel = [];
|
|
335
|
-
const fieldToColumn = [];
|
|
336
|
-
const columnToField = [];
|
|
337
|
-
for (const [modelName, model] of Object.entries(models)) {
|
|
338
|
-
const tableName = model.storage.table;
|
|
339
|
-
modelToTable.push(`readonly ${modelName}: '${tableName}'`);
|
|
340
|
-
tableToModel.push(`readonly ${tableName}: '${modelName}'`);
|
|
341
|
-
const fieldMap = [];
|
|
342
|
-
for (const [fieldName, field] of Object.entries(model.fields)) {
|
|
343
|
-
fieldMap.push(`readonly ${fieldName}: '${field.column}'`);
|
|
344
|
-
}
|
|
345
|
-
if (fieldMap.length > 0) {
|
|
346
|
-
fieldToColumn.push(`readonly ${modelName}: { ${fieldMap.join("; ")} }`);
|
|
347
|
-
}
|
|
348
|
-
if (storage.tables[tableName]) {
|
|
349
|
-
const colMap = [];
|
|
350
|
-
for (const [fieldName, field] of Object.entries(model.fields)) {
|
|
351
|
-
colMap.push(`readonly ${field.column}: '${fieldName}'`);
|
|
352
|
-
}
|
|
353
|
-
if (colMap.length > 0) {
|
|
354
|
-
columnToField.push(`readonly ${tableName}: { ${colMap.join("; ")} }`);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
const parts = [];
|
|
359
|
-
if (modelToTable.length > 0) {
|
|
360
|
-
parts.push(`modelToTable: { ${modelToTable.join("; ")} }`);
|
|
361
|
-
}
|
|
362
|
-
if (tableToModel.length > 0) {
|
|
363
|
-
parts.push(`tableToModel: { ${tableToModel.join("; ")} }`);
|
|
364
|
-
}
|
|
365
|
-
if (fieldToColumn.length > 0) {
|
|
366
|
-
parts.push(`fieldToColumn: { ${fieldToColumn.join("; ")} }`);
|
|
367
|
-
}
|
|
368
|
-
if (columnToField.length > 0) {
|
|
369
|
-
parts.push(`columnToField: { ${columnToField.join("; ")} }`);
|
|
370
|
-
}
|
|
371
|
-
parts.push(`codecTypes: ${codecTypes || "Record<string, never>"}`);
|
|
372
|
-
parts.push(`operationTypes: ${operationTypes || "Record<string, never>"}`);
|
|
373
|
-
return `{ ${parts.join("; ")} }`;
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
export {
|
|
377
|
-
sqlTargetFamilyHook
|
|
378
|
-
};
|
|
379
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"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":";AASO,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,YAAY,KAAK,OAAO,QAAQ,QAAQ,MAAM,GAAG;AACtE,YAAM,QAAQ;AACd,iBAAW,CAAC,SAAS,UAAU,KAAK,OAAO,QAAQ,MAAM,OAAO,GAAG;AACjE,cAAM,MAAM;AACZ,cAAM,UAAU,IAAI;AACpB,YAAI,CAAC,SAAS;AACZ,gBAAM,IAAI,MAAM,WAAW,OAAO,eAAe,SAAS,sBAAsB;AAAA,QAClF;AAEA,cAAM,QAAQ,QAAQ,MAAM,WAAW;AACvC,YAAI,CAAC,SAAS,CAAC,MAAM,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