@prisma-next/sql-contract-emitter 0.3.0-dev.123 → 0.3.0-dev.125
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 +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +34 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +45 -13
package/dist/index.d.mts
CHANGED
|
@@ -12,6 +12,7 @@ declare const sqlTargetFamilyHook: {
|
|
|
12
12
|
readonly executionHash?: string;
|
|
13
13
|
readonly profileHash: string;
|
|
14
14
|
}, options?: GenerateContractTypesOptions) => string;
|
|
15
|
+
readonly generateRootsType: (roots: Record<string, string> | undefined) => string;
|
|
15
16
|
readonly generateStorageType: (storage: SqlStorage) => string;
|
|
16
17
|
/**
|
|
17
18
|
* Generates the TypeScript type for storage.types with literal types.
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;cAwCa;;EAAA,SAAA,
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;cAwCa;;EAAA,SAAA,aA2sBH,EAAA,CAAA,EAAA,EAxsBU,UAwsBV,EAAA,IAAA,EAxsB4B,iBAwsB5B,EAAA,GAAA,IAAA;EAxsBU,SAAA,iBAAA,EAAA,CAAA,EAAA,EA6BI,UA7BJ,EAAA,GAAA,IAAA;EAAkB,SAAA,qBAAA,EAAA,CAAA,EAAA,EAsL9B,UAtL8B,EAAA,gBAAA,EAuLhB,aAvLgB,CAuLF,eAvLE,CAAA,EAAA,oBAAA,EAwLZ,aAxLY,CAwLE,eAxLF,CAAA,EAAA,MAAA,EAAA;IA6Bd,SAAA,WAAA,EAAA,MAAA;IAyJhB,SAAA,aAAA,CAAA,EAAA,MAAA;IAC4B,SAAA,WAAA,EAAA,MAAA;EAAd,CAAA,EAAA,OAAA,CAAA,EAOR,4BAPQ,EAAA,GAAA,MAAA;EACkB,SAAA,iBAAA,EAAA,CAAA,KAAA,EA0Ib,MA1Ia,CAAA,MAAA,EAAA,MAAA,CAAA,GAAA,SAAA,EAAA,GAAA,MAAA;EAAd,SAAA,mBAAA,EAAA,CAAA,OAAA,EAsJK,UAtJL,EAAA,GAAA,MAAA;EAMZ;;;;EAgPuB,SAAA,wBAAA,EAAA,CAAA,KAAA,EAtBH,UAsBG,CAAA,OAAA,CAAA,EAAA,GAAA,MAAA;EAyDV;;;;EAEE,SAAA,0BAAA,EAAA,CAAA,MAAA,EA3DQ,MA2DR,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,GAAA,MAAA;EAyFjB;;;EAEgB,SAAA,cAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,MAAA;EACb,SAAA,kBAAA,EAAA,CAAA,GAAA,EAAA,MAAA,EAAA,GAAA,MAAA;EAWoB,SAAA,kBAAA,EAAA,CAAA,MAAA,EAzGvB,MAyGuB,CAAA,MAAA,EAzGR,eAyGQ,CAAA,GAAA,SAAA,EAAA,OAAA,EAxGtB,UAwGsB,EAAA,sBAAA,CAAA,EAvGN,GAuGM,CAAA,MAAA,EAvGM,eAuGN,CAAA,EAAA,GAAA,MAAA;EAkER;;;;;wCAhFf,wBACC,oCACe,YAAY,yCACzB;8CAWoB;0CAkEvB,eAAe,uCACd"}
|
package/dist/index.mjs
CHANGED
|
@@ -101,6 +101,7 @@ const sqlTargetFamilyHook = {
|
|
|
101
101
|
const modelsType = this.generateModelsType(models, storage, parameterizedRenderers);
|
|
102
102
|
const relationsType = this.generateRelationsType(ir.relations);
|
|
103
103
|
const mappingsType = this.generateMappingsType(models, storage);
|
|
104
|
+
const rootsType = this.generateRootsType(ir.roots);
|
|
104
105
|
const executionHashType = hashes.executionHash ? `ExecutionHashBase<'${hashes.executionHash}'>` : "ExecutionHashBase<string>";
|
|
105
106
|
return `// ⚠️ GENERATED FILE - DO NOT EDIT
|
|
106
107
|
// This file is automatically generated by 'prisma-next contract emit'.
|
|
@@ -148,6 +149,7 @@ const sqlTargetFamilyHook = {
|
|
|
148
149
|
ProfileHash
|
|
149
150
|
> & {
|
|
150
151
|
readonly target: ${this.serializeValue(ir.target)};
|
|
152
|
+
readonly roots: ${rootsType};
|
|
151
153
|
readonly capabilities: ${this.serializeValue(ir.capabilities)};
|
|
152
154
|
readonly extensionPacks: ${this.serializeValue(ir.extensionPacks)};
|
|
153
155
|
readonly execution: ${this.serializeValue(ir.execution)};
|
|
@@ -160,6 +162,10 @@ const sqlTargetFamilyHook = {
|
|
|
160
162
|
export type Relations = Contract['relations'];
|
|
161
163
|
`;
|
|
162
164
|
},
|
|
165
|
+
generateRootsType(roots) {
|
|
166
|
+
if (!roots || Object.keys(roots).length === 0) return "Record<string, string>";
|
|
167
|
+
return `{ ${Object.entries(roots).map(([key, value]) => `readonly ${this.serializeObjectKey(key)}: ${this.serializeValue(value)}`).join("; ")} }`;
|
|
168
|
+
},
|
|
163
169
|
generateStorageType(storage) {
|
|
164
170
|
const tables = [];
|
|
165
171
|
for (const [tableName, table] of Object.entries(storage.tables)) {
|
|
@@ -241,29 +247,48 @@ const sqlTargetFamilyHook = {
|
|
|
241
247
|
const modelTypes = [];
|
|
242
248
|
for (const [modelName, model] of Object.entries(models)) {
|
|
243
249
|
const fields = [];
|
|
250
|
+
const storageFieldParts = [];
|
|
244
251
|
const tableName = model.storage.table;
|
|
245
252
|
const table = storage.tables[tableName];
|
|
246
253
|
if (table) for (const [fieldName, field] of Object.entries(model.fields)) {
|
|
247
254
|
const column = table.columns[field.column];
|
|
248
255
|
if (!column) {
|
|
249
256
|
fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
|
|
257
|
+
storageFieldParts.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
|
|
250
258
|
continue;
|
|
251
259
|
}
|
|
252
260
|
const jsType = this.generateColumnType(column, storage, parameterizedRenderers, renderCtx);
|
|
253
261
|
fields.push(`readonly ${fieldName}: ${jsType}`);
|
|
262
|
+
storageFieldParts.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
|
|
263
|
+
}
|
|
264
|
+
else for (const [fieldName, field] of Object.entries(model.fields)) {
|
|
265
|
+
fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
|
|
266
|
+
storageFieldParts.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
|
|
254
267
|
}
|
|
255
|
-
else for (const [fieldName, field] of Object.entries(model.fields)) fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
|
|
256
268
|
const relations = [];
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
269
|
+
const modelRels = model.relations;
|
|
270
|
+
for (const [relName, rel] of Object.entries(modelRels)) {
|
|
271
|
+
if (typeof rel !== "object" || rel === null) continue;
|
|
272
|
+
const relObj = rel;
|
|
273
|
+
const relParts = [];
|
|
274
|
+
if (relObj["to"]) relParts.push(`readonly to: '${relObj["to"]}'`);
|
|
275
|
+
if (relObj["cardinality"]) relParts.push(`readonly cardinality: '${relObj["cardinality"]}'`);
|
|
276
|
+
const on = relObj["on"];
|
|
277
|
+
if (on?.localFields && on.targetFields) {
|
|
278
|
+
const localFields = on.localFields.map((f) => `'${f}'`).join(", ");
|
|
279
|
+
const targetFields = on.targetFields.map((f) => `'${f}'`).join(", ");
|
|
280
|
+
relParts.push(`readonly on: { readonly localFields: readonly [${localFields}]; readonly targetFields: readonly [${targetFields}] }`);
|
|
263
281
|
}
|
|
282
|
+
if (relParts.length > 0) relations.push(`readonly ${relName}: { ${relParts.join("; ")} }`);
|
|
264
283
|
}
|
|
265
|
-
const
|
|
266
|
-
if (
|
|
284
|
+
const storageParts = [`readonly table: '${tableName}'`];
|
|
285
|
+
if (storageFieldParts.length > 0) storageParts.push(`readonly fields: { ${storageFieldParts.join("; ")} }`);
|
|
286
|
+
const modelParts = [
|
|
287
|
+
`storage: { ${storageParts.join("; ")} }`,
|
|
288
|
+
`fields: { ${fields.join("; ")} }`,
|
|
289
|
+
`relations: { ${relations.join("; ")} }`
|
|
290
|
+
];
|
|
291
|
+
if (model.owner) modelParts.push(`owner: ${this.serializeValue(model.owner)}`);
|
|
267
292
|
modelTypes.push(`readonly ${modelName}: { ${modelParts.join("; ")} }`);
|
|
268
293
|
}
|
|
269
294
|
return `{ ${modelTypes.join("; ")} }`;
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["table: StorageTable | undefined","referencedTable: StorageTable | undefined","allImports: TypesImportSpec[]","uniqueImports: TypesImportSpec[]","tables: string[]","columns: string[]","tableParts: string[]","typeEntries: string[]","entries: string[]","renderCtx: TypeRenderContext","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 {\n GenerateContractTypesOptions,\n TypeRenderContext,\n TypeRenderEntry,\n TypesImportSpec,\n ValidationContext,\n} from '@prisma-next/contract/types';\nimport type {\n ModelDefinition,\n ModelField,\n SqlStorage,\n StorageColumn,\n StorageTable,\n StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { assertDefined } from '@prisma-next/utils/assertions';\n\n/**\n * Resolves the typeParams for a column, either from inline typeParams or from typeRef.\n * Returns undefined if no typeParams are available.\n */\nfunction resolveColumnTypeParams(\n column: StorageColumn,\n storage: SqlStorage,\n): Record<string, unknown> | undefined {\n // Inline typeParams take precedence\n if (column.typeParams && Object.keys(column.typeParams).length > 0) {\n return column.typeParams;\n }\n // Check typeRef\n if (column.typeRef && storage.types) {\n const typeInstance = storage.types[column.typeRef] as StorageTypeInstance | undefined;\n if (typeInstance?.typeParams) {\n return typeInstance.typeParams;\n }\n }\n return undefined;\n}\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: StorageTable | undefined = storage.tables[tableName];\n assertDefined(table, `Model \"${modelName}\" references non-existent table \"${tableName}\"`);\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 // Table existence guaranteed by Set.has() check above\n const referencedTable: StorageTable | undefined = storage.tables[fk.references.table];\n assertDefined(\n referencedTable,\n `Table \"${tableName}\" foreignKey references non-existent table \"${fk.references.table}\"`,\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 hashes: {\n readonly storageHash: string;\n readonly executionHash?: string;\n readonly profileHash: string;\n },\n options?: GenerateContractTypesOptions,\n ): string {\n const parameterizedRenderers = options?.parameterizedRenderers;\n const parameterizedTypeImports = options?.parameterizedTypeImports;\n const storage = ir.storage as SqlStorage;\n const models = ir.models as Record<string, ModelDefinition>;\n\n // Collect all type imports from three sources:\n // 1. Codec type imports (from adapters, targets, and extensions)\n // 2. Operation type imports (from adapters, targets, and extensions)\n // 3. Parameterized type imports (for parameterized codec renderers, may contain duplicates)\n const allImports: TypesImportSpec[] = [...codecTypeImports, ...operationTypeImports];\n\n if (parameterizedTypeImports) {\n allImports.push(...parameterizedTypeImports);\n }\n\n const queryOperationTypeImports = options?.queryOperationTypeImports ?? [];\n if (queryOperationTypeImports.length > 0) {\n allImports.push(...queryOperationTypeImports);\n }\n\n // Deduplicate imports by package+named to avoid duplicate import statements.\n // Strategy: When the same package::named appears multiple times, keep the first\n // occurrence (and its alias); later duplicates with different aliases are silently ignored.\n //\n // Note: uniqueImports must be an array (not a Set) because:\n // - We need to preserve the full TypesImportSpec objects (package, named, alias)\n // - We need to preserve insertion order (first occurrence wins)\n // - seenImportKeys is a Set used only for O(1) duplicate detection\n const seenImportKeys = new Set<string>();\n const uniqueImports: TypesImportSpec[] = [];\n for (const imp of allImports) {\n const key = `${imp.package}::${imp.named}`;\n if (!seenImportKeys.has(key)) {\n seenImportKeys.add(key);\n uniqueImports.push(imp);\n }\n }\n\n // Generate import statements, omitting redundant \"as Alias\" when named === alias\n const importLines = uniqueImports.map((imp) => {\n // Simplify import when named === alias (e.g., `import type { Vector }` instead of `{ Vector as Vector }`)\n const importClause = imp.named === imp.alias ? imp.named : `${imp.named} as ${imp.alias}`;\n return `import type { ${importClause} } from '${imp.package}';`;\n });\n\n // Only intersect actual codec/operation type maps. Extra type-only imports (e.g. Vector<N>) are\n // included in importLines via codecTypeImports but must not be intersected into CodecTypes.\n const codecTypes = codecTypeImports\n .filter((imp) => imp.named === 'CodecTypes')\n .map((imp) => imp.alias)\n .join(' & ');\n const operationTypes = operationTypeImports\n .filter((imp) => imp.named === 'OperationTypes')\n .map((imp) => imp.alias)\n .join(' & ');\n const queryOperationTypes = queryOperationTypeImports\n .filter((imp) => imp.named === 'QueryOperationTypes')\n .map((imp) => imp.alias)\n .join(' & ');\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);\n\n const executionHashType = hashes.executionHash\n ? `ExecutionHashBase<'${hashes.executionHash}'>`\n : 'ExecutionHashBase<string>';\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\n import type {\n ExecutionHashBase,\n ProfileHashBase,\n StorageHashBase,\n } from '@prisma-next/contract/types';\n import type {\n SqlContract,\n SqlStorage,\n SqlMappings,\n ModelDefinition,\n ContractWithTypeMaps,\n TypeMaps as TypeMapsType,\n } from '@prisma-next/sql-contract/types';\n\n export type StorageHash = StorageHashBase<'${hashes.storageHash}'>;\n export type ExecutionHash = ${executionHashType};\n export type ProfileHash = ProfileHashBase<'${hashes.profileHash}'>;\n\n export type CodecTypes = ${codecTypes || 'Record<string, never>'};\n export type LaneCodecTypes = CodecTypes;\n export type OperationTypes = ${operationTypes || 'Record<string, never>'};\n export type QueryOperationTypes = ${queryOperationTypes || 'Record<string, never>'};\n type DefaultLiteralValue<CodecId extends string, Encoded> =\n CodecId extends keyof CodecTypes\n ? CodecTypes[CodecId] extends { readonly output: infer O }\n ? O extends Date | bigint ? O : Encoded\n : Encoded\n : Encoded;\n\n export type TypeMaps = TypeMapsType<CodecTypes, OperationTypes, QueryOperationTypes>;\n\n type ContractBase = SqlContract<\n ${storageType},\n ${modelsType},\n ${relationsType},\n ${mappingsType},\n StorageHash,\n ExecutionHash,\n ProfileHash\n > & {\n readonly target: ${this.serializeValue(ir.target)};\n readonly capabilities: ${this.serializeValue(ir.capabilities)};\n readonly extensionPacks: ${this.serializeValue(ir.extensionPacks)};\n readonly execution: ${this.serializeValue(ir.execution)};\n };\n\n export type Contract = ContractWithTypeMaps<ContractBase, TypeMaps>;\n\n export type Tables = Contract['storage']['tables'];\n export type Models = Contract['models'];\n export 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 const defaultSpec = col.default\n ? col.default.kind === 'literal'\n ? `; readonly default: { readonly kind: 'literal'; readonly value: DefaultLiteralValue<${codecId}, ${this.serializeValue(\n col.default.value,\n )}> }`\n : `; readonly default: { readonly kind: 'function'; readonly expression: ${this.serializeValue(\n col.default.expression,\n )} }`\n : '';\n columns.push(\n `readonly ${colName}: { readonly nativeType: ${nativeType}; readonly codecId: ${codecId}; readonly nullable: ${nullable}${defaultSpec} }`,\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 const using =\n i.using !== undefined ? `; readonly using: ${this.serializeValue(i.using)}` : '';\n const config =\n i.config !== undefined ? `; readonly config: ${this.serializeValue(i.config)}` : '';\n return `{ readonly columns: readonly [${cols}]${name}${using}${config} }`;\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}; readonly constraint: ${fk.constraint}; readonly index: ${fk.index} }`;\n })\n .join(', ');\n tableParts.push(`foreignKeys: readonly [${fks}]`);\n\n tables.push(`readonly ${tableName}: { ${tableParts.join('; ')} }`);\n }\n\n const typesType = this.generateStorageTypesType(storage.types);\n\n return `{ readonly tables: { ${tables.join('; ')} }; readonly types: ${typesType} }`;\n },\n\n /**\n * Generates the TypeScript type for storage.types with literal types.\n * This preserves type params as literal values for precise typing.\n */\n generateStorageTypesType(types: SqlStorage['types']): string {\n if (!types || Object.keys(types).length === 0) {\n return 'Record<string, never>';\n }\n\n const typeEntries: string[] = [];\n for (const [typeName, typeInstance] of Object.entries(types)) {\n const codecId = `'${typeInstance.codecId}'`;\n const nativeType = `'${typeInstance.nativeType}'`;\n const typeParamsStr = this.serializeTypeParamsLiteral(typeInstance.typeParams);\n typeEntries.push(\n `readonly ${typeName}: { readonly codecId: ${codecId}; readonly nativeType: ${nativeType}; readonly typeParams: ${typeParamsStr} }`,\n );\n }\n\n return `{ ${typeEntries.join('; ')} }`;\n },\n\n /**\n * Serializes a typeParams object to a TypeScript literal type.\n * Converts { length: 1536 } to \"{ readonly length: 1536 }\".\n */\n serializeTypeParamsLiteral(params: Record<string, unknown>): string {\n if (!params || Object.keys(params).length === 0) {\n return 'Record<string, never>';\n }\n\n const entries: string[] = [];\n for (const [key, value] of Object.entries(params)) {\n const serialized = this.serializeValue(value);\n entries.push(`readonly ${this.serializeObjectKey(key)}: ${serialized}`);\n }\n\n return `{ ${entries.join('; ')} }`;\n },\n\n /**\n * Serializes a value to a TypeScript literal type expression.\n */\n serializeValue(value: unknown): string {\n if (value === null) {\n return 'null';\n }\n if (value === undefined) {\n return 'undefined';\n }\n if (typeof value === 'string') {\n // Escape backslashes first, then single quotes\n const escaped = value.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\");\n return `'${escaped}'`;\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n if (typeof value === 'bigint') {\n return `${value}n`;\n }\n if (Array.isArray(value)) {\n const items = value.map((v) => this.serializeValue(v)).join(', ');\n return `readonly [${items}]`;\n }\n if (typeof value === 'object') {\n const entries: string[] = [];\n for (const [k, v] of Object.entries(value)) {\n entries.push(`readonly ${this.serializeObjectKey(k)}: ${this.serializeValue(v)}`);\n }\n return `{ ${entries.join('; ')} }`;\n }\n return 'unknown';\n },\n\n serializeObjectKey(key: string): string {\n if (/^[$A-Z_a-z][$\\w]*$/.test(key)) {\n return key;\n }\n return this.serializeValue(key);\n },\n\n generateModelsType(\n models: Record<string, ModelDefinition> | undefined,\n storage: SqlStorage,\n parameterizedRenderers?: Map<string, TypeRenderEntry>,\n ): string {\n if (!models) {\n return 'Record<string, never>';\n }\n\n const renderCtx: TypeRenderContext = { codecTypesName: 'CodecTypes' };\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 jsType = this.generateColumnType(\n column,\n storage,\n parameterizedRenderers,\n renderCtx,\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 /**\n * Generates the TypeScript type expression for a column.\n * Uses parameterized renderer if the column has typeParams and a matching renderer exists,\n * otherwise falls back to CodecTypes[codecId]['output'].\n */\n generateColumnType(\n column: StorageColumn,\n storage: SqlStorage,\n parameterizedRenderers: Map<string, TypeRenderEntry> | undefined,\n renderCtx: TypeRenderContext,\n ): string {\n const typeParams = resolveColumnTypeParams(column, storage);\n const nullable = column.nullable ?? false;\n const fallbackType = `CodecTypes['${column.codecId}']['output']`;\n const renderer = typeParams && parameterizedRenderers?.get(column.codecId);\n const baseType = renderer ? renderer.render(typeParams, renderCtx) : fallbackType;\n\n return nullable ? `${baseType} | null` : baseType;\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 ): string {\n if (!models) {\n return 'SqlMappings';\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\n return parts.length > 0 ? `{ ${parts.join('; ')} }` : 'SqlMappings';\n },\n} as const;\n"],"mappings":";;;;;;;AAsBA,SAAS,wBACP,QACA,SACqC;AAErC,KAAI,OAAO,cAAc,OAAO,KAAK,OAAO,WAAW,CAAC,SAAS,EAC/D,QAAO,OAAO;AAGhB,KAAI,OAAO,WAAW,QAAQ,OAAO;EACnC,MAAM,eAAe,QAAQ,MAAM,OAAO;AAC1C,MAAI,cAAc,WAChB,QAAO,aAAa;;;AAM1B,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;EAClB,MAAM,aAAa,IAAI,IAAI,OAAO,KA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AAM,SAAS,IAAI,KAAK,MAAM,KAAK,KAAK,CAAC,MAAM;;CAEzD"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["table: StorageTable | undefined","referencedTable: StorageTable | undefined","allImports: TypesImportSpec[]","uniqueImports: TypesImportSpec[]","tables: string[]","columns: string[]","tableParts: string[]","typeEntries: string[]","entries: string[]","renderCtx: TypeRenderContext","modelTypes: string[]","fields: string[]","storageFieldParts: string[]","relations: string[]","relParts: 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 {\n GenerateContractTypesOptions,\n TypeRenderContext,\n TypeRenderEntry,\n TypesImportSpec,\n ValidationContext,\n} from '@prisma-next/contract/types';\nimport type {\n ModelDefinition,\n ModelField,\n SqlStorage,\n StorageColumn,\n StorageTable,\n StorageTypeInstance,\n} from '@prisma-next/sql-contract/types';\nimport { assertDefined } from '@prisma-next/utils/assertions';\n\n/**\n * Resolves the typeParams for a column, either from inline typeParams or from typeRef.\n * Returns undefined if no typeParams are available.\n */\nfunction resolveColumnTypeParams(\n column: StorageColumn,\n storage: SqlStorage,\n): Record<string, unknown> | undefined {\n // Inline typeParams take precedence\n if (column.typeParams && Object.keys(column.typeParams).length > 0) {\n return column.typeParams;\n }\n // Check typeRef\n if (column.typeRef && storage.types) {\n const typeInstance = storage.types[column.typeRef] as StorageTypeInstance | undefined;\n if (typeInstance?.typeParams) {\n return typeInstance.typeParams;\n }\n }\n return undefined;\n}\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: StorageTable | undefined = storage.tables[tableName];\n assertDefined(table, `Model \"${modelName}\" references non-existent table \"${tableName}\"`);\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 // Table existence guaranteed by Set.has() check above\n const referencedTable: StorageTable | undefined = storage.tables[fk.references.table];\n assertDefined(\n referencedTable,\n `Table \"${tableName}\" foreignKey references non-existent table \"${fk.references.table}\"`,\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 hashes: {\n readonly storageHash: string;\n readonly executionHash?: string;\n readonly profileHash: string;\n },\n options?: GenerateContractTypesOptions,\n ): string {\n const parameterizedRenderers = options?.parameterizedRenderers;\n const parameterizedTypeImports = options?.parameterizedTypeImports;\n const storage = ir.storage as SqlStorage;\n const models = ir.models as Record<string, ModelDefinition>;\n\n // Collect all type imports from three sources:\n // 1. Codec type imports (from adapters, targets, and extensions)\n // 2. Operation type imports (from adapters, targets, and extensions)\n // 3. Parameterized type imports (for parameterized codec renderers, may contain duplicates)\n const allImports: TypesImportSpec[] = [...codecTypeImports, ...operationTypeImports];\n\n if (parameterizedTypeImports) {\n allImports.push(...parameterizedTypeImports);\n }\n\n const queryOperationTypeImports = options?.queryOperationTypeImports ?? [];\n if (queryOperationTypeImports.length > 0) {\n allImports.push(...queryOperationTypeImports);\n }\n\n // Deduplicate imports by package+named to avoid duplicate import statements.\n // Strategy: When the same package::named appears multiple times, keep the first\n // occurrence (and its alias); later duplicates with different aliases are silently ignored.\n //\n // Note: uniqueImports must be an array (not a Set) because:\n // - We need to preserve the full TypesImportSpec objects (package, named, alias)\n // - We need to preserve insertion order (first occurrence wins)\n // - seenImportKeys is a Set used only for O(1) duplicate detection\n const seenImportKeys = new Set<string>();\n const uniqueImports: TypesImportSpec[] = [];\n for (const imp of allImports) {\n const key = `${imp.package}::${imp.named}`;\n if (!seenImportKeys.has(key)) {\n seenImportKeys.add(key);\n uniqueImports.push(imp);\n }\n }\n\n // Generate import statements, omitting redundant \"as Alias\" when named === alias\n const importLines = uniqueImports.map((imp) => {\n // Simplify import when named === alias (e.g., `import type { Vector }` instead of `{ Vector as Vector }`)\n const importClause = imp.named === imp.alias ? imp.named : `${imp.named} as ${imp.alias}`;\n return `import type { ${importClause} } from '${imp.package}';`;\n });\n\n // Only intersect actual codec/operation type maps. Extra type-only imports (e.g. Vector<N>) are\n // included in importLines via codecTypeImports but must not be intersected into CodecTypes.\n const codecTypes = codecTypeImports\n .filter((imp) => imp.named === 'CodecTypes')\n .map((imp) => imp.alias)\n .join(' & ');\n const operationTypes = operationTypeImports\n .filter((imp) => imp.named === 'OperationTypes')\n .map((imp) => imp.alias)\n .join(' & ');\n const queryOperationTypes = queryOperationTypeImports\n .filter((imp) => imp.named === 'QueryOperationTypes')\n .map((imp) => imp.alias)\n .join(' & ');\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);\n const rootsType = this.generateRootsType(ir.roots);\n\n const executionHashType = hashes.executionHash\n ? `ExecutionHashBase<'${hashes.executionHash}'>`\n : 'ExecutionHashBase<string>';\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\n import type {\n ExecutionHashBase,\n ProfileHashBase,\n StorageHashBase,\n } from '@prisma-next/contract/types';\n import type {\n SqlContract,\n SqlStorage,\n SqlMappings,\n ModelDefinition,\n ContractWithTypeMaps,\n TypeMaps as TypeMapsType,\n } from '@prisma-next/sql-contract/types';\n\n export type StorageHash = StorageHashBase<'${hashes.storageHash}'>;\n export type ExecutionHash = ${executionHashType};\n export type ProfileHash = ProfileHashBase<'${hashes.profileHash}'>;\n\n export type CodecTypes = ${codecTypes || 'Record<string, never>'};\n export type LaneCodecTypes = CodecTypes;\n export type OperationTypes = ${operationTypes || 'Record<string, never>'};\n export type QueryOperationTypes = ${queryOperationTypes || 'Record<string, never>'};\n type DefaultLiteralValue<CodecId extends string, Encoded> =\n CodecId extends keyof CodecTypes\n ? CodecTypes[CodecId] extends { readonly output: infer O }\n ? O extends Date | bigint ? O : Encoded\n : Encoded\n : Encoded;\n\n export type TypeMaps = TypeMapsType<CodecTypes, OperationTypes, QueryOperationTypes>;\n\n type ContractBase = SqlContract<\n ${storageType},\n ${modelsType},\n ${relationsType},\n ${mappingsType},\n StorageHash,\n ExecutionHash,\n ProfileHash\n > & {\n readonly target: ${this.serializeValue(ir.target)};\n readonly roots: ${rootsType};\n readonly capabilities: ${this.serializeValue(ir.capabilities)};\n readonly extensionPacks: ${this.serializeValue(ir.extensionPacks)};\n readonly execution: ${this.serializeValue(ir.execution)};\n };\n\n export type Contract = ContractWithTypeMaps<ContractBase, TypeMaps>;\n\n export type Tables = Contract['storage']['tables'];\n export type Models = Contract['models'];\n export type Relations = Contract['relations'];\n `;\n },\n\n generateRootsType(roots: Record<string, string> | undefined): string {\n if (!roots || Object.keys(roots).length === 0) {\n return 'Record<string, string>';\n }\n const entries = Object.entries(roots)\n .map(\n ([key, value]) => `readonly ${this.serializeObjectKey(key)}: ${this.serializeValue(value)}`,\n )\n .join('; ');\n return `{ ${entries} }`;\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 const defaultSpec = col.default\n ? col.default.kind === 'literal'\n ? `; readonly default: { readonly kind: 'literal'; readonly value: DefaultLiteralValue<${codecId}, ${this.serializeValue(\n col.default.value,\n )}> }`\n : `; readonly default: { readonly kind: 'function'; readonly expression: ${this.serializeValue(\n col.default.expression,\n )} }`\n : '';\n columns.push(\n `readonly ${colName}: { readonly nativeType: ${nativeType}; readonly codecId: ${codecId}; readonly nullable: ${nullable}${defaultSpec} }`,\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 const using =\n i.using !== undefined ? `; readonly using: ${this.serializeValue(i.using)}` : '';\n const config =\n i.config !== undefined ? `; readonly config: ${this.serializeValue(i.config)}` : '';\n return `{ readonly columns: readonly [${cols}]${name}${using}${config} }`;\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}; readonly constraint: ${fk.constraint}; readonly index: ${fk.index} }`;\n })\n .join(', ');\n tableParts.push(`foreignKeys: readonly [${fks}]`);\n\n tables.push(`readonly ${tableName}: { ${tableParts.join('; ')} }`);\n }\n\n const typesType = this.generateStorageTypesType(storage.types);\n\n return `{ readonly tables: { ${tables.join('; ')} }; readonly types: ${typesType} }`;\n },\n\n /**\n * Generates the TypeScript type for storage.types with literal types.\n * This preserves type params as literal values for precise typing.\n */\n generateStorageTypesType(types: SqlStorage['types']): string {\n if (!types || Object.keys(types).length === 0) {\n return 'Record<string, never>';\n }\n\n const typeEntries: string[] = [];\n for (const [typeName, typeInstance] of Object.entries(types)) {\n const codecId = `'${typeInstance.codecId}'`;\n const nativeType = `'${typeInstance.nativeType}'`;\n const typeParamsStr = this.serializeTypeParamsLiteral(typeInstance.typeParams);\n typeEntries.push(\n `readonly ${typeName}: { readonly codecId: ${codecId}; readonly nativeType: ${nativeType}; readonly typeParams: ${typeParamsStr} }`,\n );\n }\n\n return `{ ${typeEntries.join('; ')} }`;\n },\n\n /**\n * Serializes a typeParams object to a TypeScript literal type.\n * Converts { length: 1536 } to \"{ readonly length: 1536 }\".\n */\n serializeTypeParamsLiteral(params: Record<string, unknown>): string {\n if (!params || Object.keys(params).length === 0) {\n return 'Record<string, never>';\n }\n\n const entries: string[] = [];\n for (const [key, value] of Object.entries(params)) {\n const serialized = this.serializeValue(value);\n entries.push(`readonly ${this.serializeObjectKey(key)}: ${serialized}`);\n }\n\n return `{ ${entries.join('; ')} }`;\n },\n\n /**\n * Serializes a value to a TypeScript literal type expression.\n */\n serializeValue(value: unknown): string {\n if (value === null) {\n return 'null';\n }\n if (value === undefined) {\n return 'undefined';\n }\n if (typeof value === 'string') {\n // Escape backslashes first, then single quotes\n const escaped = value.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\");\n return `'${escaped}'`;\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n if (typeof value === 'bigint') {\n return `${value}n`;\n }\n if (Array.isArray(value)) {\n const items = value.map((v) => this.serializeValue(v)).join(', ');\n return `readonly [${items}]`;\n }\n if (typeof value === 'object') {\n const entries: string[] = [];\n for (const [k, v] of Object.entries(value)) {\n entries.push(`readonly ${this.serializeObjectKey(k)}: ${this.serializeValue(v)}`);\n }\n return `{ ${entries.join('; ')} }`;\n }\n return 'unknown';\n },\n\n serializeObjectKey(key: string): string {\n if (/^[$A-Z_a-z][$\\w]*$/.test(key)) {\n return key;\n }\n return this.serializeValue(key);\n },\n\n generateModelsType(\n models: Record<string, ModelDefinition> | undefined,\n storage: SqlStorage,\n parameterizedRenderers?: Map<string, TypeRenderEntry>,\n ): string {\n if (!models) {\n return 'Record<string, never>';\n }\n\n const renderCtx: TypeRenderContext = { codecTypesName: 'CodecTypes' };\n\n const modelTypes: string[] = [];\n for (const [modelName, model] of Object.entries(models)) {\n const fields: string[] = [];\n const storageFieldParts: 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 storageFieldParts.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);\n continue;\n }\n\n const jsType = this.generateColumnType(\n column,\n storage,\n parameterizedRenderers,\n renderCtx,\n );\n fields.push(`readonly ${fieldName}: ${jsType}`);\n storageFieldParts.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);\n }\n } else {\n for (const [fieldName, field] of Object.entries(model.fields)) {\n fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);\n storageFieldParts.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);\n }\n }\n\n const relations: string[] = [];\n const modelRels = model.relations as Record<string, unknown>;\n for (const [relName, rel] of Object.entries(modelRels)) {\n if (typeof rel !== 'object' || rel === null) continue;\n const relObj = rel as Record<string, unknown>;\n const relParts: string[] = [];\n if (relObj['to']) relParts.push(`readonly to: '${relObj['to']}'`);\n if (relObj['cardinality'])\n relParts.push(`readonly cardinality: '${relObj['cardinality']}'`);\n const on = relObj['on'] as { localFields?: string[]; targetFields?: string[] } | undefined;\n if (on?.localFields && on.targetFields) {\n const localFields = on.localFields.map((f) => `'${f}'`).join(', ');\n const targetFields = on.targetFields.map((f) => `'${f}'`).join(', ');\n relParts.push(\n `readonly on: { readonly localFields: readonly [${localFields}]; readonly targetFields: readonly [${targetFields}] }`,\n );\n }\n if (relParts.length > 0) {\n relations.push(`readonly ${relName}: { ${relParts.join('; ')} }`);\n }\n }\n\n const storageParts = [`readonly table: '${tableName}'`];\n if (storageFieldParts.length > 0) {\n storageParts.push(`readonly fields: { ${storageFieldParts.join('; ')} }`);\n }\n\n const modelParts: string[] = [\n `storage: { ${storageParts.join('; ')} }`,\n `fields: { ${fields.join('; ')} }`,\n `relations: { ${relations.join('; ')} }`,\n ];\n\n if (model.owner) {\n modelParts.push(`owner: ${this.serializeValue(model.owner)}`);\n }\n\n modelTypes.push(`readonly ${modelName}: { ${modelParts.join('; ')} }`);\n }\n\n return `{ ${modelTypes.join('; ')} }`;\n },\n\n /**\n * Generates the TypeScript type expression for a column.\n * Uses parameterized renderer if the column has typeParams and a matching renderer exists,\n * otherwise falls back to CodecTypes[codecId]['output'].\n */\n generateColumnType(\n column: StorageColumn,\n storage: SqlStorage,\n parameterizedRenderers: Map<string, TypeRenderEntry> | undefined,\n renderCtx: TypeRenderContext,\n ): string {\n const typeParams = resolveColumnTypeParams(column, storage);\n const nullable = column.nullable ?? false;\n const fallbackType = `CodecTypes['${column.codecId}']['output']`;\n const renderer = typeParams && parameterizedRenderers?.get(column.codecId);\n const baseType = renderer ? renderer.render(typeParams, renderCtx) : fallbackType;\n\n return nullable ? `${baseType} | null` : baseType;\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 ): string {\n if (!models) {\n return 'SqlMappings';\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\n return parts.length > 0 ? `{ ${parts.join('; ')} }` : 'SqlMappings';\n },\n} as const;\n"],"mappings":";;;;;;;AAsBA,SAAS,wBACP,QACA,SACqC;AAErC,KAAI,OAAO,cAAc,OAAO,KAAK,OAAO,WAAW,CAAC,SAAS,EAC/D,QAAO,OAAO;AAGhB,KAAI,OAAO,WAAW,QAAQ,OAAO;EACnC,MAAM,eAAe,QAAQ,MAAM,OAAO;AAC1C,MAAI,cAAc,WAChB,QAAO,aAAa;;;AAM1B,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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K,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;AAG9D,SAAO,MAAM,SAAS,IAAI,KAAK,MAAM,KAAK,KAAK,CAAC,MAAM;;CAEzD"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-contract-emitter",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.125",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "SQL emitter hook for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@prisma-next/
|
|
9
|
-
"@prisma-next/
|
|
10
|
-
"@prisma-next/
|
|
11
|
-
"@prisma-next/
|
|
8
|
+
"@prisma-next/contract": "0.3.0-dev.125",
|
|
9
|
+
"@prisma-next/emitter": "0.3.0-dev.125",
|
|
10
|
+
"@prisma-next/sql-contract": "0.3.0-dev.125",
|
|
11
|
+
"@prisma-next/utils": "0.3.0-dev.125"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"tsdown": "0.18.4",
|
|
15
15
|
"typescript": "5.9.3",
|
|
16
16
|
"vitest": "4.0.17",
|
|
17
|
-
"@prisma-next/core-control-plane": "0.3.0-dev.
|
|
17
|
+
"@prisma-next/core-control-plane": "0.3.0-dev.125",
|
|
18
18
|
"@prisma-next/test-utils": "0.0.1",
|
|
19
19
|
"@prisma-next/tsconfig": "0.0.0",
|
|
20
20
|
"@prisma-next/tsdown": "0.0.0"
|
package/src/index.ts
CHANGED
|
@@ -297,6 +297,7 @@ export const sqlTargetFamilyHook = {
|
|
|
297
297
|
const modelsType = this.generateModelsType(models, storage, parameterizedRenderers);
|
|
298
298
|
const relationsType = this.generateRelationsType(ir.relations);
|
|
299
299
|
const mappingsType = this.generateMappingsType(models, storage);
|
|
300
|
+
const rootsType = this.generateRootsType(ir.roots);
|
|
300
301
|
|
|
301
302
|
const executionHashType = hashes.executionHash
|
|
302
303
|
? `ExecutionHashBase<'${hashes.executionHash}'>`
|
|
@@ -348,6 +349,7 @@ export const sqlTargetFamilyHook = {
|
|
|
348
349
|
ProfileHash
|
|
349
350
|
> & {
|
|
350
351
|
readonly target: ${this.serializeValue(ir.target)};
|
|
352
|
+
readonly roots: ${rootsType};
|
|
351
353
|
readonly capabilities: ${this.serializeValue(ir.capabilities)};
|
|
352
354
|
readonly extensionPacks: ${this.serializeValue(ir.extensionPacks)};
|
|
353
355
|
readonly execution: ${this.serializeValue(ir.execution)};
|
|
@@ -361,6 +363,18 @@ export const sqlTargetFamilyHook = {
|
|
|
361
363
|
`;
|
|
362
364
|
},
|
|
363
365
|
|
|
366
|
+
generateRootsType(roots: Record<string, string> | undefined): string {
|
|
367
|
+
if (!roots || Object.keys(roots).length === 0) {
|
|
368
|
+
return 'Record<string, string>';
|
|
369
|
+
}
|
|
370
|
+
const entries = Object.entries(roots)
|
|
371
|
+
.map(
|
|
372
|
+
([key, value]) => `readonly ${this.serializeObjectKey(key)}: ${this.serializeValue(value)}`,
|
|
373
|
+
)
|
|
374
|
+
.join('; ');
|
|
375
|
+
return `{ ${entries} }`;
|
|
376
|
+
},
|
|
377
|
+
|
|
364
378
|
generateStorageType(storage: SqlStorage): string {
|
|
365
379
|
const tables: string[] = [];
|
|
366
380
|
for (const [tableName, table] of Object.entries(storage.tables)) {
|
|
@@ -527,6 +541,7 @@ export const sqlTargetFamilyHook = {
|
|
|
527
541
|
const modelTypes: string[] = [];
|
|
528
542
|
for (const [modelName, model] of Object.entries(models)) {
|
|
529
543
|
const fields: string[] = [];
|
|
544
|
+
const storageFieldParts: string[] = [];
|
|
530
545
|
const tableName = model.storage.table;
|
|
531
546
|
const table = storage.tables[tableName];
|
|
532
547
|
|
|
@@ -535,6 +550,7 @@ export const sqlTargetFamilyHook = {
|
|
|
535
550
|
const column = table.columns[field.column];
|
|
536
551
|
if (!column) {
|
|
537
552
|
fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
|
|
553
|
+
storageFieldParts.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
|
|
538
554
|
continue;
|
|
539
555
|
}
|
|
540
556
|
|
|
@@ -545,34 +561,50 @@ export const sqlTargetFamilyHook = {
|
|
|
545
561
|
renderCtx,
|
|
546
562
|
);
|
|
547
563
|
fields.push(`readonly ${fieldName}: ${jsType}`);
|
|
564
|
+
storageFieldParts.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
|
|
548
565
|
}
|
|
549
566
|
} else {
|
|
550
567
|
for (const [fieldName, field] of Object.entries(model.fields)) {
|
|
551
568
|
fields.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
|
|
569
|
+
storageFieldParts.push(`readonly ${fieldName}: { readonly column: '${field.column}' }`);
|
|
552
570
|
}
|
|
553
571
|
}
|
|
554
572
|
|
|
555
573
|
const relations: string[] = [];
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
574
|
+
const modelRels = model.relations as Record<string, unknown>;
|
|
575
|
+
for (const [relName, rel] of Object.entries(modelRels)) {
|
|
576
|
+
if (typeof rel !== 'object' || rel === null) continue;
|
|
577
|
+
const relObj = rel as Record<string, unknown>;
|
|
578
|
+
const relParts: string[] = [];
|
|
579
|
+
if (relObj['to']) relParts.push(`readonly to: '${relObj['to']}'`);
|
|
580
|
+
if (relObj['cardinality'])
|
|
581
|
+
relParts.push(`readonly cardinality: '${relObj['cardinality']}'`);
|
|
582
|
+
const on = relObj['on'] as { localFields?: string[]; targetFields?: string[] } | undefined;
|
|
583
|
+
if (on?.localFields && on.targetFields) {
|
|
584
|
+
const localFields = on.localFields.map((f) => `'${f}'`).join(', ');
|
|
585
|
+
const targetFields = on.targetFields.map((f) => `'${f}'`).join(', ');
|
|
586
|
+
relParts.push(
|
|
587
|
+
`readonly on: { readonly localFields: readonly [${localFields}]; readonly targetFields: readonly [${targetFields}] }`,
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
if (relParts.length > 0) {
|
|
591
|
+
relations.push(`readonly ${relName}: { ${relParts.join('; ')} }`);
|
|
566
592
|
}
|
|
567
593
|
}
|
|
568
594
|
|
|
595
|
+
const storageParts = [`readonly table: '${tableName}'`];
|
|
596
|
+
if (storageFieldParts.length > 0) {
|
|
597
|
+
storageParts.push(`readonly fields: { ${storageFieldParts.join('; ')} }`);
|
|
598
|
+
}
|
|
599
|
+
|
|
569
600
|
const modelParts: string[] = [
|
|
570
|
-
`storage: {
|
|
601
|
+
`storage: { ${storageParts.join('; ')} }`,
|
|
571
602
|
`fields: { ${fields.join('; ')} }`,
|
|
603
|
+
`relations: { ${relations.join('; ')} }`,
|
|
572
604
|
];
|
|
573
605
|
|
|
574
|
-
if (
|
|
575
|
-
modelParts.push(`
|
|
606
|
+
if (model.owner) {
|
|
607
|
+
modelParts.push(`owner: ${this.serializeValue(model.owner)}`);
|
|
576
608
|
}
|
|
577
609
|
|
|
578
610
|
modelTypes.push(`readonly ${modelName}: { ${modelParts.join('; ')} }`);
|