Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/fix-virtual-fields-never-select.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@opensaas/stack-cli': patch
---

Fix virtual fields typed as `never` when mixed with relation fields in `select` or when using `include`
10 changes: 5 additions & 5 deletions examples/auth-demo/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ model Post {
authorId String? @map("author")
author User? @relation(fields: [authorId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt

@@index([authorId])
}
Expand All @@ -33,7 +33,7 @@ model User {
accounts Account[]
posts Post[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}

model Session {
Expand All @@ -45,7 +45,7 @@ model Session {
userId String? @map("user")
user User? @relation(fields: [userId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt

@@index([userId])
}
Expand All @@ -64,7 +64,7 @@ model Account {
userId String? @map("user")
user User? @relation(fields: [userId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt

@@index([userId])
}
Expand All @@ -75,5 +75,5 @@ model Verification {
value String
expiresAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}
6 changes: 3 additions & 3 deletions examples/blog/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ model Settings {
maintenanceMode Boolean @default(false)
maxUploadSize Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}

model User {
Expand All @@ -23,7 +23,7 @@ model User {
password String
posts Post[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}

model Post {
Expand All @@ -38,7 +38,7 @@ model Post {
authorId String? @map("author")
author User? @relation(fields: [authorId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt

@@index([authorId])
}
4 changes: 2 additions & 2 deletions examples/composable-dashboard/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ model User {
password String
posts Post[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}

model Post {
Expand All @@ -28,7 +28,7 @@ model Post {
authorId String? @map("author")
author User? @relation(fields: [authorId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt

@@index([authorId])
}
4 changes: 2 additions & 2 deletions examples/custom-field/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ model User {
favoriteColor String?
posts Post[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}

model Post {
Expand All @@ -29,7 +29,7 @@ model Post {
authorId String? @map("author")
author User? @relation(fields: [authorId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt

@@index([authorId])
}
6 changes: 4 additions & 2 deletions examples/file-upload-demo/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ model User {
avatar Json?
posts Post[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}

model Post {
Expand All @@ -26,5 +26,7 @@ model Post {
authorId String? @map("author")
author User? @relation(fields: [authorId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt

@@index([authorId])
}
4 changes: 2 additions & 2 deletions examples/json-demo/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ model Product {
settings Json?
configuration Json
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}

model Article {
Expand All @@ -23,5 +23,5 @@ model Article {
content Json?
taxonomy Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}
2 changes: 1 addition & 1 deletion examples/rag-openai-chatbot/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ model KnowledgeBase {
published Boolean @default(true)
contentEmbedding Json?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}
10 changes: 5 additions & 5 deletions examples/starter-auth/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ model Post {
authorId String? @map("author")
author User? @relation(fields: [authorId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt

@@index([authorId])
}
Expand All @@ -33,7 +33,7 @@ model User {
accounts Account[]
posts Post[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}

model Session {
Expand All @@ -45,7 +45,7 @@ model Session {
userId String? @map("user")
user User? @relation(fields: [userId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt

@@index([userId])
}
Expand All @@ -64,7 +64,7 @@ model Account {
userId String? @map("user")
user User? @relation(fields: [userId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt

@@index([userId])
}
Expand All @@ -75,5 +75,5 @@ model Verification {
value String
expiresAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}
4 changes: 2 additions & 2 deletions examples/starter/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ model User {
password String
posts Post[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}

model Post {
Expand All @@ -28,7 +28,7 @@ model Post {
authorId String? @map("author")
author User? @relation(fields: [authorId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt

@@index([authorId])
}
6 changes: 4 additions & 2 deletions examples/tiptap-demo/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ model User {
email String @unique
articles Article[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt
}

model Article {
Expand All @@ -26,5 +26,7 @@ model Article {
authorId String? @map("author")
author User? @relation(fields: [authorId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updatedAt DateTime @default(now()) @updatedAt

@@index([authorId])
}
16 changes: 16 additions & 0 deletions packages/cli/src/commands/__snapshots__/generate.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ import type { Session as OpensaasSession, StorageUtils, ServerActionProps, Acces
import type { PrismaClient, Prisma } from './prisma-client/client'
import type { PluginServices } from './plugin-types'

// Utility: strips virtual field keys from select/include so Prisma GetPayload never sees them
type StripVirtualFromArgs<T, VirtualKeys extends string> =
T extends { select: infer S extends object }
? Omit<T, 'select'> & { select: Omit<S, VirtualKeys> }
: T extends { include: infer I extends object }
? Omit<T, 'include'> & { include: Omit<I, VirtualKeys> }
: T

/**
* Virtual fields for User - computed fields not in database
* These are added to query results via resolveOutput hooks
Expand Down Expand Up @@ -443,6 +451,14 @@ import type { Session as OpensaasSession, StorageUtils, ServerActionProps, Acces
import type { PrismaClient, Prisma } from './prisma-client/client'
import type { PluginServices } from './plugin-types'

// Utility: strips virtual field keys from select/include so Prisma GetPayload never sees them
type StripVirtualFromArgs<T, VirtualKeys extends string> =
T extends { select: infer S extends object }
? Omit<T, 'select'> & { select: Omit<S, VirtualKeys> }
: T extends { include: infer I extends object }
? Omit<T, 'include'> & { include: Omit<I, VirtualKeys> }
: T

/**
* Custom DB type that uses Prisma's conditional types with virtual and transformed field support
* Types change based on select/include - relationships only present when explicitly included
Expand Down
Loading
Loading