UNPKG

cancancan-ts

Version:

Lightweight and extensible authorization engine for TypeScript inspired by CanCanCan. Define flexible permissions using actions, subjects, and conditions.

16 lines (15 loc) 552 B
export type ConditionFn<T = any> = (subject: T) => boolean; export interface Rule<A extends string = string, S extends string = string, T = any> { action: A; subject: S; condition?: ConditionFn<T>; } export declare class Ability<A extends string = string, S extends string = string> { private rules; constructor(); can<T>(action: A, subject: S, object?: T): boolean; allow<T>(action: A, subject: S, condition?: ConditionFn<T>): void; deny(action: A, subject: S): void; getRules(): Rule<A, S>[]; clear(): void; }