Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions packages/sdk/src/ts-schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,17 +618,18 @@ export class TsSchemaGenerator {
ts.factory.createPropertyAssignment(
field.name,
ts.factory.createObjectLiteralExpression([
ts.factory.createPropertyAssignment(
'type',
ts.factory.createStringLiteral(field.type.type!),
),
ts.factory.createPropertyAssignment('type', this.generateFieldTypeLiteral(field)),
]),
),
);
}
}

// model-level id and unique

// it's possible to have the same set of fields in both `@@id` and `@@unique`
// so we need to deduplicate them
const seenKeys = new Set<string>();
for (const attr of dm.attributes) {
if (attr.decl.$refText === '@@id' || attr.decl.$refText === '@@unique') {
const fieldNames = this.getReferenceNames(attr.args[0]!.value);
Expand All @@ -643,15 +644,17 @@ export class TsSchemaGenerator {
ts.factory.createPropertyAssignment(
fieldNames[0]!,
ts.factory.createObjectLiteralExpression([
ts.factory.createPropertyAssignment(
'type',
ts.factory.createStringLiteral(fieldDef.type.type!),
),
ts.factory.createPropertyAssignment('type', this.generateFieldTypeLiteral(fieldDef)),
]),
),
);
} else {
// multi-field unique
const key = fieldNames.join('_');
if (seenKeys.has(key)) {
continue;
}
seenKeys.add(key);
properties.push(
ts.factory.createPropertyAssignment(
fieldNames.join('_'),
Comment thread
ymc9 marked this conversation as resolved.
Expand All @@ -663,7 +666,7 @@ export class TsSchemaGenerator {
ts.factory.createObjectLiteralExpression([
ts.factory.createPropertyAssignment(
'type',
ts.factory.createStringLiteral(fieldDef.type.type!),
this.generateFieldTypeLiteral(fieldDef),
),
]),
);
Expand All @@ -678,6 +681,10 @@ export class TsSchemaGenerator {
return ts.factory.createObjectLiteralExpression(properties, true);
}

private generateFieldTypeLiteral(field: DataModelField): ts.Expression {
Comment thread
ymc9 marked this conversation as resolved.
return ts.factory.createStringLiteral(field.type.type ?? field.type.reference!.$refText);
}

private createEnumObject(e: Enum) {
return ts.factory.createObjectLiteralExpression(
e.fields.map((field) =>
Expand Down