chrishoermann / zod-prisma-types

Generator creates zod types for your prisma models with advanced validation
Other
661 stars 50 forks source link

[BUG] Prisma' has no exported member 'CreateMany<MODEL>AndReturnOutputTypeDefaultArgs'. #252

Closed type9 closed 6 months ago

type9 commented 6 months ago

Describe the bug Hi Chris. Thanks for the work on the package so far. I'm having types issues being created by zod-prisma-types trying to extract types that don't exist in generated prisma client. Notably it was working for me at one point and started breaking when I ran an unrelated pnpm install as part of my monorepo setup. I want to say at one point there were a few type issues also related to my User model but they have since gone away. I was wondering if you could point to what could be causing this mismatch of expected output from prisma and zod-prisma-types

Prisma' has no exported member 'CreateManySavedCompanionAndReturnOutputTypeDefaultArgs'
import { z } from 'zod';
import type { Prisma } from '../../client';
import { CreateManySavedCompanionAndReturnOutputTypeSelectSchema } from '../inputTypeSchemas/CreateManySavedCompanionAndReturnOutputTypeSelectSchema';
import { CreateManySavedCompanionAndReturnOutputTypeIncludeSchema } from '../inputTypeSchemas/CreateManySavedCompanionAndReturnOutputTypeIncludeSchema';

export const CreateManySavedCompanionAndReturnOutputTypeArgsSchema: z.ZodType<Prisma.CreateManySavedCompanionAndReturnOutputTypeDefaultArgs> = z.object({
  select: z.lazy(() => CreateManySavedCompanionAndReturnOutputTypeSelectSchema).optional(),
  include: z.lazy(() => CreateManySavedCompanionAndReturnOutputTypeIncludeSchema).optional(),
}).strict();

export default CreateManySavedCompanionAndReturnOutputTypeArgsSchema;
//prisma schema
generator client {
  provider = "prisma-client-js"
  output = "../lib/generated/client"
}

generator zod {
  provider       = "zod-prisma-types"
  output = "../lib/generated/zod"
  useTypeAssertions = true
  createRelationValuesTypes = true
  useMultipleFiles          = true
}

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

enum AccessControl {
  PUBLIC
  PRIVATE
}

model SavedCompanion {
  id                 String   @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  createdAt          DateTime @default(now()) @db.Timestamp(6)
  owner              String?  @db.Uuid
  savedInputs        Json?
  accessControl      AccessControl   @default(PUBLIC)
  savedConfiguration Json?
  name               String?  @db.Text
  description        String?  @db.Text
  updatedAt          DateTime @default(now()) @db.Timestamp(6)
  shortId            String   @unique @db.Text
  user              User?    @relation(fields: [owner], references: [id], onUpdate: Cascade, onDelete: Cascade)

  @@unique([id, shortId])
}

model User {
  id               String           @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  createdAt        DateTime?        @db.Timestamp(6)
  clerkId          String?          @unique @db.Text
  lastUpdated      DateTime         @default(now()) @db.Timestamp(6)
  emailAddresses   Json?
  lastSignInAt     DateTime?        @db.Timestamp(6)
  username         String           @unique @db.Text
  firstName        String?          @db.Text
  lastName         String?          @db.Text
  externalAccounts Json?
  SavedCompanion   SavedCompanion[]
}
//package.json build scripts
"scripts": {
        "withenv": "npx dotenv-cli -e ../../.env --",
        "db:generate": "pnpm withenv prisma generate",
        "db:push": "pnpm withenv prisma db push --skip-generate",
        "db:makemigration": "pnpm withenv prisma migrate dev --name",
        "db:studio": "pnpm withenv prisma studio",
        "lint": "eslint ./src/**/*.ts --fix",
        "type-check": "tsc --noEmit"
    },

Package versions (please complete the following information):

Additional context Add any other context about the problem here.

type9 commented 6 months ago

Actually the problem fixed itself when I reverted back to prisma 5.13. It was caused by an auto upgrade to 5.14. This might or might not be worth looking into further.

"dependencies": {
        "@prisma/client": "5.13.0",
        "prisma": "5.13.0"
}
goern commented 6 months ago

Heya, this issue is a good source of information, it solved my problems... ;)

a. can we keep it open or label it as a known issue? b. will this be further triaged, so that we know where the root cause is?

thanks!

and thanks for all the work on this project!!

bingneef commented 6 months ago

Hi all! In the 5.14.0 release, prisma added createManyAndReturn. Perhaps this is not implemented yet in zod-prisma-types?

Thanks for the great work! 🎉

TomJuzanx commented 6 months ago

Hi! I had the exact same problem with prisma 5.14.0, downgrade to 5.13.0 as mentioned by type9, this also fixed the issue.

I agree with bingneef on this one!

Hi all! In the 5.14.0 release, prisma added createManyAndReturn. Perhaps this is not implemented yet in zod-prisma-types?

Thanks for the great work! 🎉

capitlux commented 6 months ago

Hello, I confirm prisma downgrade from 5.14.0 to 5.13.0 fixed this issue. Hopping @chrishoermann will help us to support this breaking change. Thx.

chrishoermann commented 6 months ago

Thanks for reporting this issue. I'm currently short on time since I have to finish a milestone in a project in the next weeks but I'll try to look into it the next days.

chrishoermann commented 6 months ago

@capitlux, @type9, @goern , @bingneef, @TomJuzanx I implemented a fix in the latest version 3.1.7. It indeed was the newly added createManyAndReturn function that created the problems. The generator created some schemas that had no corresponding type in the Prisma namespace which caused the error. Please let me know if this fixes the issue on your side

bingneef commented 6 months ago

@chrishoermann Works perfectly!

chrishoermann commented 6 months ago

Closing since this should be resolved!