Skip to content

Latest commit

 

History

History
34 lines (26 loc) · 682 Bytes

README.md

File metadata and controls

34 lines (26 loc) · 682 Bytes

ucastle

Convert CASL rules into Drizzle filters

Install

npm install ucastle

Usage

import { defineAbility } from "@casl/ability";
import { rulesToDrizzle } from "ucastle";

// Use any of your Drizzle tables
const users = pgTable("users", {
  id: integer().primaryKey(),
});

// Define your CASL ability
const ability = defineAbility((can) => {
  can("read", "User", { id: 1, age: { $lt: 18 } });
  can("read", "User", { age: { $gte: 18 } });
});

// Convert MongoDB query conditions into Drizzle filters
const where = rulesToDrizzle(ability, "read", "User", users);
// => or(
//  gte(users.age, 18),
//  and(eq(users.id, 1), lt(users.age, 18)),
// )