Closed p0thi closed 1 month ago
isSet is currently not support
I see, thanks for the heads up. The isSet filter is only available for prisma with mongodb. I would go ahead anyways and implement it and create a PR. Does that sound good @stalniy ?
Yes, would be cool!
Describe the bug Using the prisma
isSet
filter in my casl conditions leads to an error.To Reproduce
For reference, behind this expandable spoiler is the ability builder code. Click to show.
```typescript import { AbilityBuilder, AbilityOptionsOf, PureAbility, fieldPatternMatcher, type AbilityTuple, } from "@casl/ability"; import { PrismaQuery, Subjects, prismaQuery } from "@casl/prisma"; import { User } from "@prisma/client"; // PrismaModels is a helper, that contains all Prisma Models. // ExtendedPrismaClient is my prisma client with extensions import type { ExtendedPrismaClient, PrismaModels } from "../prismaClient"; export type MFActions = "manage" | "read" | "update" | "create" | "delete"; export type MFSubjects = | "all" | Subjects<{ Foo: PrismaModels["Foo"]; }>; export type MFAbility = PureAbility< AbilityTupleI am using casl v6 prisma for my prisma objects. I have a prisma model like this:
So if the active flag is not defined in the database, prisma includes it as true in the query result. Now, if i want to allow read access only on Foos, that have the active flag set to false or don't have it at all (as it is optional), I would need to configure the ability like the following:
but the use of the
isSet
filter for optional fields leads to an error, when I check if the ability can read an object of typeFoo
.To be precise, it is an
Error: "equals" does not supports comparison of arrays and objects
error, even though it works, when I only use{ active: { equals: true } }
as the condition without theisSet
filter.Expected behavior The use of the
isSet
filter for optional fields should not throw an exception.CASL Version
@casl/ability
- v 6.7.1@casl/prisma
- v 1.4.1Environment: Node version 20.12.1