Skip to content

Commit

Permalink
feat: adds return type to 'rulesToQuery' based on return type from 'c…
Browse files Browse the repository at this point in the history
…onvert' param (#876)

Co-authored-by: Sergii Stotskyi <sergiy.stotskiy@gmail.com>
  • Loading branch information
jarpoole and stalniy authored Feb 14, 2024
1 parent fa43c2b commit 379e130
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/casl-ability/src/extra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import { Rule } from './Rule';
import { setByPath, wrapArray } from './utils';
import { AnyObject, SubjectType, ExtractSubjectType } from './types';

export type RuleToQueryConverter<T extends AnyAbility> = (rule: RuleOf<T>) => object;
export type RuleToQueryConverter<T extends AnyAbility, R = object> = (rule: RuleOf<T>) => R;
export interface AbilityQuery<T = object> {
$or?: T[]
$and?: T[]
}

export function rulesToQuery<T extends AnyAbility>(
export function rulesToQuery<T extends AnyAbility, R = object>(
ability: T,
action: Parameters<T['rulesFor']>[0],
subjectType: ExtractSubjectType<Parameters<T['rulesFor']>[1]>,
convert: RuleToQueryConverter<T>
): AbilityQuery | null {
const query: AbilityQuery = {};
convert: RuleToQueryConverter<T, R>
): AbilityQuery<R> | null {
const query: AbilityQuery<R> = {};
const rules = ability.rulesFor(action, subjectType);

for (let i = 0; i < rules.length; i++) {
Expand Down

0 comments on commit 379e130

Please sign in to comment.