Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some schemas are not available at compile time somehow and are registered as undefined #12

Open
Morriz opened this issue Aug 8, 2022 · 2 comments

Comments

@Morriz
Copy link

Morriz commented Aug 8, 2022

Bug description

the culprit is in the oneOfSchemas helper. The test breaks because it was given an array of schemas that were undefined. You can reproduce it with:

Yup.addMethod(Yup.MixedSchema, 'oneOfSchemas', function (schemas: Yup.AnySchema[]) {
  if (schemas.length && schemas[0] === undefined) debugger
  return this.test('one-of-schemas', 'Not all items in ${path} match one of the allowed schemas', (item) =>
    schemas.some((schema) =>
      // uncommenting the next line will make the test run correctly
      // if (schema === undefined) return true
      schema.isValidSync(item, { strict: true }),
    ),
  )
})

How to reproduce

Expected behavior

No response

Prisma information

Environment & setup

  • OS:
  • Database:
  • Node.js version:

Prisma Version


@omar-dulaimi
Copy link
Owner

Could you provide the code snippet you used?
Like which schema, what payload, etc.

@Morriz
Copy link
Author

Morriz commented Aug 16, 2022

I only have this schema:

// prisma/schema.prisma

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

generator yup {
  provider = "prisma-yup-generator"
  output   = "../src/yup/gen"
}

enum Role {
  USER
  ADMIN
  MEMBER
  OWNER
}

enum Tier {
  FREE
  PRO
  ENTERPRISE
}

enum PaymentStatus {
  PENDING
  PAID
}

model License {
  tier        Tier
  price       Int
  description String

  @@unique([tier])
}

enum InvoicePeriod {
  MONTHLY
  YEARLY
}

model Account {
  id                String   @id @default(cuid())
  createdAt         DateTime @default(now())
  updatedAt         DateTime @updatedAt
  userId            String
  type              String
  provider          String
  providerAccountId String
  refresh_token     String?  @map("refreshToken") @db.Text
  access_token      String?  @map("accessToken") @db.Text
  expires_at        Int?     @map("expiresAt")
  token_type        String?  @map("tokenType")
  scope             String?
  id_token          String?  @map("idToken") @db.Text
  session_state     String?  @map("sessionState")
  // relations:
  user              User     @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
}

model Session {
  id           String        @id @default(cuid())
  createdAt    DateTime      @default(now())
  updatedAt    DateTime      @updatedAt
  userId       String
  oboOrgId     String?
  expires      DateTime
  role         Role          @default(USER)
  sessionToken String        @unique
  // relations:
  oboOrg       Organisation? @relation(fields: [oboOrgId], references: [id], onDelete: Cascade)
  user         User          @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
  id            String    @id @default(cuid())
  createdAt     DateTime  @default(now())
  updatedAt     DateTime  @updatedAt
  address       String? /// @encrypted
  avatarUrl     String? /// @encrypted
  city          String? /// @encrypted
  company       String?
  country       String?
  email         String?   @unique
  emailVerified DateTime?
  image         String?
  name          String?
  phoneNumber   String? /// @encrypted
  role          Role      @default(USER)
  state         String?
  tier          Tier      @default(FREE)
  zipCode       String? /// @encrypted
  // relations:
  things        Thing[]
  accounts      Account[]
  sessions      Session[]
  userOrgs      UserOrg[]
}

model VerificationToken {
  identifier String
  token      String   @unique
  expires    DateTime

  @@unique([identifier, token])
}

model UserOrg {
  createdAt      DateTime     @default(now())
  updatedAt      DateTime     @updatedAt
  userId         String
  organisationId String
  role           Role
  // relations:
  user           User         @relation(fields: [userId], references: [id], onDelete: Cascade)
  organisation   Organisation @relation(fields: [organisationId], references: [id])

  @@id([userId, organisationId])
}

model Invoice {
  id             String        @id @default(uuid())
  createdAt      DateTime      @default(now())
  updatedAt      DateTime      @updatedAt
  accountId      String
  endDate        DateTime
  organisationId String
  period         InvoicePeriod
  price          Int
  startDate      DateTime
  status         PaymentStatus
  // relations:
  organisation   Organisation  @relation(fields: [organisationId], references: [id])
}

model Organisation {
  id        String    @id @default(uuid())
  createdAt DateTime  @default(now())
  updatedAt DateTime  @updatedAt
  accountId String    @unique
  name      String    @unique
  image     String?
  // relations:
  orgUsers  UserOrg[]
  Invoice   Invoice[]
  Thing     Thing[]
  Session   Session[]
}

model Thing {
  id             String        @id @default(uuid())
  createdAt      DateTime      @default(now())
  updatedAt      DateTime      @updatedAt
  accountId      String
  description    String
  key            String        @default(cuid())
  name           String
  organisationId String?
  userId         String?
  // relations:
  user           User?         @relation(fields: [userId], references: [id])
  organisation   Organisation? @relation(fields: [organisationId], references: [id])
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants