Skip to content

Commit 3436488

Browse files
committed
refactor: always add $Types
1 parent 5773049 commit 3436488

1 file changed

Lines changed: 8 additions & 31 deletions

File tree

  • packages/schema/src/plugins/enhancer/enhance

packages/schema/src/plugins/enhancer/enhance/index.ts

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,12 @@ export class EnhancerGenerator {
122122

123123
// reexport PrismaClient types (original or fixed)
124124
const modelsTsContent = `export * from '${resultPrismaTypeImport}';${
125-
this.isNewPrismaClientGenerator ? '\nexport * from \'./json-fields\';' : ''
125+
this.isNewPrismaClientGenerator ? "\nexport * from './json-fields';" : ''
126126
}`;
127-
128-
const modelsTs = this.project.createSourceFile(
129-
path.join(this.outDir, 'models.ts'),
130-
modelsTsContent,
131-
{ overwrite: true }
132-
);
127+
128+
const modelsTs = this.project.createSourceFile(path.join(this.outDir, 'models.ts'), modelsTsContent, {
129+
overwrite: true,
130+
});
133131
this.saveSourceFile(modelsTs);
134132

135133
const authDecl = getAuthDecl(getDataModelAndTypeDefs(this.model));
@@ -520,28 +518,7 @@ export type Enhanced<Client> =
520518
throw new PluginError(name, `Unexpected syntax list structure in ${fileName}`);
521519
}
522520

523-
// Check if $Types is used in any type aliases (before and after transformation)
524-
let needsTypesImport = false;
525-
syntaxList.getChildren().forEach((node) => {
526-
if (Node.isTypeAliasDeclaration(node)) {
527-
// Check original type
528-
const typeText = node.getType().getText();
529-
if (typeText.includes('$Types')) {
530-
needsTypesImport = true;
531-
}
532-
533-
// Check if transformation would add $Types
534-
const structure = this.transformTypeAlias(node, delegateInfo);
535-
if (structure.type && typeof structure.type === 'string' && structure.type.includes('$Types')) {
536-
needsTypesImport = true;
537-
}
538-
}
539-
});
540-
541-
// Add $Types import if needed
542-
if (needsTypesImport) {
543-
sfNew.addStatements('import $Types = runtime.Types;');
544-
}
521+
sfNew.addStatements('import $Types = runtime.Types;');
545522

546523
// Add import for json-fields if this model has JSON type fields
547524
const modelWithJsonFields = this.modelsWithJsonTypeFields.find((m) => m.name === d.name);
@@ -551,8 +528,8 @@ export type Enhanced<Client> =
551528
return model.fields.filter((f) => isTypeDef(f.type.reference?.ref));
552529
};
553530
const jsonFieldTypes = getTypedJsonFields(modelWithJsonFields);
554-
const typeNames = jsonFieldTypes.map(field => field.type.reference!.$refText);
555-
531+
const typeNames = jsonFieldTypes.map((field) => field.type.reference!.$refText);
532+
556533
if (typeNames.length > 0) {
557534
sfNew.addStatements(`import type { ${typeNames.join(', ')} } from "../../json-fields";`);
558535
}

0 commit comments

Comments
 (0)