Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ export class ProductDto extends IntersectionType(
- puts relational fields into different file for each model. This way the class will match the object returned by a Prisma query, default value is **false**
- _clientImportPath_
- set prisma client import path manually, default value is **@prisma/client**
- _useClassTransformerExpose_
- annotate all properties with @Expose
- _useNonNullableAssertions_
- Apply a ! after non-optional class fields to avoid strict mode warnings (Property has no initializer and is not definitely assigned in the constructor.)
- _preserveDefaultNullable_
Expand Down
13 changes: 7 additions & 6 deletions prisma/v7.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ generator client {
}

generator prismaClassGenerator {
provider = "node -r ts-node/register/transpile-only src/index.ts"
output = "../src/_gen/prisma-class"
dryRun = "false"
separateRelationFields = "false"
useClassValidator = "true"
usePrismaJsonValue = "true"
provider = "node -r ts-node/register/transpile-only src/index.ts"
output = "../src/_gen/prisma-class"
dryRun = "false"
separateRelationFields = "false"
useClassValidator = "true"
usePrismaJsonValue = "true"
useClassTransformerExpose = "true"
}

enum TestEnum {
Expand Down
16 changes: 16 additions & 0 deletions src/convertor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,17 @@ export class PrismaConvertor {
return decorators;
}

extractClassTransformerDecoratorsFromField = (dmmfField: DMMF.Field) => {
const decorators = [];

decorators.push(new DecoratorComponent({
name: 'Expose',
importFrom: 'class-transformer',
}))

return decorators;
}

convertField = (dmmfField: DMMF.Field, relationField: boolean): FieldComponent => {
const field = new FieldComponent({
name: dmmfField.name,
Expand All @@ -658,6 +669,11 @@ export class PrismaConvertor {
field.decorators.push(...decorators)
}

if (this.config.useClassTransformerExpose) {
const decorators = this.extractClassTransformerDecoratorsFromField(dmmfField);
field.decorators.push(...decorators)
}

if (this.config.useGraphQL) {
const decorator =
this.extractTypeGraphQLDecoratorFromField(dmmfField)
Expand Down
4 changes: 4 additions & 0 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export const PrismaClassGeneratorOptions = {
desc: 'use class validator',
defaultValue: false
},
useClassTransformerExpose: {
desc: 'annotate all properties with @Expose',
defaultValue: false
},
usePrismaJsonValue: {
desc: 'use Prisma JsonValue type instead of object for Json fields',
defaultValue: false,
Expand Down