Skip to content

Zod Schema contains invalid import to logical Prisma Client, when @@validate rule references an enum #2065

Closed
@diesal11

Description

@diesal11

Description and expected behavior
Schema:

enum FooType {
    Bar
    Baz
}

// Add JSON type field so a logical prisma client is generated.
// Polymorphic models also trigger this bug 
type Meta {
    test String?
}

model Foo {
    id   String  @id @db.Uuid @default(uuid())
    type FooType
    meta Meta @json

    @@validate(type == Bar, "FooType must be Bar")
}

Screenshots
The generated Zod Schema file for Foo then contains an invalid import. .zenstack/models is a .d.ts file and contains no value exports.

Image

Environment (please complete the following information):

  • ZenStack version: 2.13.0
  • Prisma version: 6.5.0
  • Database type: Postgresql

Additional context

This bug doesn't occur when a logical client isn't generated. I believe the issue lies somewhere in this code, It doesn't really make sense to me that prismaClientPath is being mapped to a definitions file?

const { dmmf, newPrismaClientDtsPath } = await new EnhancerGenerator(model, options, project, outDir).generate();
let prismaClientPath: string | undefined;
if (dmmf) {
// a logical client is generated
if (options.output || globalOptions?.output) {
// handle custom output path
// get the absolute path of the prisma client types
const prismaClientPathAbs = path.resolve(outDir, 'models');
// resolve it relative to the schema path
prismaClientPath = normalizedRelative(path.dirname(options.schemaPath), prismaClientPathAbs);
} else {
prismaClientPath = `${RUNTIME_PACKAGE}/models`;
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions