zod-prisma-types icon indicating copy to clipboard operation
zod-prisma-types copied to clipboard

Incorrect casing on aggregation types

Open jafri opened this issue 2 years ago • 5 comments

As generated by prisma 4.11.0

image

As generated by zod-prisma-types image

Temporary Regex to fix:

Prisma.([a-z])(.*)AggregateArgs

Prisma.\U$1$2AggregateArgs

jafri avatar Mar 05 '23 18:03 jafri

@jafri that's interesting. Can you check if the uppercase type that should be used also exists somewhere in your index.d.ts? We had a similar bug where the name of a relation field produced the wrong casing type #55

chrishoermann avatar Mar 06 '23 18:03 chrishoermann

@chrishoermann I am also running into a mismatching casing issue. The generated index.ts file has incorrect upper case references to lower case schemas, but also schemas that are typed with e.g. Prisma.prismatype where prismatype is incorrectly lower cased. For me it isn't just AggregateArgs, it's also GroupByArgs among other things.

jimboboliver avatar Mar 11 '23 05:03 jimboboliver

@jafri @james1050 can you provide a Schema in which this behavior occurs so I can try to reproduce the issued?

chrishoermann avatar Mar 11 '23 12:03 chrishoermann

@chrishoermann , the following schema:

generator client {
  provider = "prisma-client-js"
}

generator zod {
  provider = "zod-prisma-types"
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

model apples {
  id                Int                 @id @default(autoincrement())
  name              String?             @db.VarChar(255)
  menus             menus[]
  prices            prices[]
  oranges           oranges[]
  orange_categories orange_categories[]
}

model orange_categories {
  id       Int                            @id @default(autoincrement())
  name     String                         @db.VarChar(255)
  apples   apples                         @relation(fields: [applesId], references: [id])
  applesId Int
  oranges  oranges_to_orange_categories[]
}

model oranges {
  id                Int                            @id @default(autoincrement())
  name              String                         @db.VarChar(255)
  prices            prices[]
  apples            apples                         @relation(fields: [applesId], references: [id])
  applesId          Int
  orange_categories oranges_to_orange_categories[]
}

model oranges_to_orange_categories {
  oranges            oranges           @relation(fields: [orange_id], references: [id])
  orange_id          Int
  orange_categories  orange_categories @relation(fields: [orange_category_id], references: [id])
  orange_category_id Int

  @@id([orange_id, orange_category_id])
}

model prices {
  id                  Int     @id @default(autoincrement())
  menus               menus?  @relation(fields: [menusId], references: [id])
  menusId             Int?
  apples              apples  @relation(fields: [applesId], references: [id])
  applesId            Int
  price               Float?  @db.Float
  oranges             oranges @relation(fields: [orange_id], references: [id])
  orange_id           Int
  orange_variant_name String? @db.VarChar(255)
}

model menus {
  id       Int      @id @default(autoincrement())
  name     String   @db.VarChar(255)
  apples   apples   @relation(fields: [applesId], references: [id])
  applesId Int
  prices   prices[]
}

The schema above produces generated types that includes the section below, where ApplesCountOutputTypeArgsSchema is referenced but it should be applesCountOutputTypeArgsSchema.


/////////////////////////////////////////
// SELECT & INCLUDE
/////////////////////////////////////////

// APPLES
//------------------------------------------------------

export const applesIncludeSchema: z.ZodType<Prisma.applesInclude> = z.object({
  menus: z.union([z.boolean(),z.lazy(() => menusFindManyArgsSchema)]).optional(),
  prices: z.union([z.boolean(),z.lazy(() => pricesFindManyArgsSchema)]).optional(),
  oranges: z.union([z.boolean(),z.lazy(() => orangesFindManyArgsSchema)]).optional(),
  orange_categories: z.union([z.boolean(),z.lazy(() => orange_categoriesFindManyArgsSchema)]).optional(),
  _count: z.union([z.boolean(),z.lazy(() => ApplesCountOutputTypeArgsSchema)]).optional(),
}).strict()

export const applesArgsSchema: z.ZodType<Prisma.applesArgs> = z.object({
  select: z.lazy(() => applesSelectSchema).optional(),
  include: z.lazy(() => applesIncludeSchema).optional(),
}).strict();

export const applesCountOutputTypeArgsSchema: z.ZodType<Prisma.applesCountOutputTypeArgs> = z.object({
  select: z.lazy(() => applesCountOutputTypeSelectSchema).nullish(),
}).strict();

Edit: I'm using prisma 4.11.0, zod-prisma-types 2.5.3

jimboboliver avatar Mar 30 '23 09:03 jimboboliver

Seeing the same issue on "zod-prisma-types": "^3.1.8"

prisma                  : 5.1.1
@prisma/client          : 5.10.2
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 6a3747c37ff169c90047725a05a6ef02e32ac97e (at ../../.nvm/versions/node/v18.17.0/lib/node_modules/prisma/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli 6a3747c37ff169c90047725a05a6ef02e32ac97e (at ../../.nvm/versions/node/v18.17.0/lib/node_modules/prisma/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e
Default Engines Hash    : 6a3747c37ff169c90047725a05a6ef02e32ac97e
Studio                  : 0.492.0
769 export const user_sessionIncludeSchema: z.ZodType<Prisma.user_sessionInclude> = z.object({
                 ~~~~~~~~~~~~~~~~~~~~~~~~~

zod/index.ts:771:45 - error TS2552: Cannot find name 'User_sessionCountOutputTypeArgsSchema'. Did you mean 'user_sessionCountOutputTypeArgsSchema'?

771   _count: z.union([z.boolean(),z.lazy(() => User_sessionCountOutputTypeArgsSchema)]).optional(),
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

zod/index.ts:779:70 - error TS2724: '"/Users/kevzettler/code/event-rewrite/node_modules/.prisma/client/index".Prisma' has no exported member named 'user_sessionCountOutputTypeDefaultArgs'. Did you mean 'User_sessionCountOutputTypeDefaultArgs'?

779 export const user_sessionCountOutputTypeArgsSchema: z.ZodType<Prisma.user_sessionCountOutputTypeDefaultArgs> = z.object({
                                                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

zod/index.ts:783:72 - error TS2724: '"/Users/kevzettler/code/event-rewrite/node_modules/.prisma/client/index".Prisma' has no exported member named 'user_sessionCountOutputTypeSelect'. Did you mean 'User_sessionCountOutputTypeSelect'?

783 export const user_sessionCountOutputTypeSelectSchema: z.ZodType<Prisma.user_sessionCountOutputTypeSelect> = z.object({

kevzettler avatar Nov 05 '24 01:11 kevzettler