forked from stalniy/casl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
51 lines (33 loc) · 1.24 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
export interface Rule {
subject: string | string[],
actions: string | string[],
conditions?: Object,
inverted?: boolean
}
export interface AbilityOptions {
subjectName: (subject: any) => string
}
export class Ability {
rules: Rule[]
static addAlias(alias: string, fields: string | string[]): void
constructor(rules?: Rule[], options?: AbilityOptions)
update(rules: Rule[]): Ability
can(action: string, subject: any): boolean
cannot(action: string, subject: any): boolean
rulesFor(action: string, subject: any): Rule[]
throwUnlessCan(action: string, subject: any): void
}
export abstract class AbilityBuilderParts {
rules: Rule[]
can(action: string | string[], subject: string | string[]): Rule
cannot(action: string | string[], subject: string | string[]): Rule
}
export class AbilityBuilder extends AbilityBuilderParts {
static define(params: AbilityOptions, dsl: Function): Ability
static define(dsl: Function): Ability
static extract(): AbilityBuilderParts
}
export class ForbiddenError extends Error {}
export function rulesToQuery(rules: Rule[], convert: (rule: Rule) => Object): Object[] | null
export function toMongoQuery(rules: Rule[]): Object[] | null
export function mongoosePlugin(schema: any): any