Skip to content

Commit

Permalink
fix(ability): improves PackedRule type
Browse files Browse the repository at this point in the history
Relates to #248
  • Loading branch information
stalniy committed Feb 17, 2020
1 parent 22262fb commit a781921
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/casl-ability/src/extra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ export function permittedFieldsOf(

const joinIfArray = (value: string | string[]) => Array.isArray(value) ? value.join(',') : value;

export type PackedRule = [
string,
string,
(UnifiedRawRule['conditions'] | 0)?,
(1 | 0)?,
(string | 0)?,
(string | 0)?
];
export type PackedRule =
[string, string] |
[string, string, UnifiedRawRule['conditions']] |
[string, string, UnifiedRawRule['conditions'] | 0, 1] |
[string, string, UnifiedRawRule['conditions'] | 0, 1 | 0, string] |
[string, string, UnifiedRawRule['conditions'] | 0, 1 | 0, string | 0, string]
;

export function packRules(rules: UnifiedRawRule[]): PackedRule[] {
return rules.map(({ actions, subject, conditions, inverted, fields, reason }) => { // eslint-disable-line
Expand All @@ -111,7 +110,7 @@ export function packRules(rules: UnifiedRawRule[]): PackedRule[] {
conditions || 0,
inverted ? 1 : 0,
fields ? joinIfArray(fields) : 0,
reason || 0
reason || ''
];

while (!rule[rule.length - 1]) rule.pop();
Expand Down

0 comments on commit a781921

Please sign in to comment.