'Why rulesToQuery method aggregates all query chuck with $or property when the rule is not inverted?

My understanding is when we check action on the subject of ability in a positive scenario the conditions given should be validated with and condition.

Example: AI Moderator 'can' 'update' 'Article' when 'publised==true and tags in ["AI"]'

In Code:

const moderatorPermissions = [
        { action: 'update', subject: 'Article', conditions: { publised: true, tags: ["AI"] } }
];

const moderatorAbility = createAbility(moderatorPermissions); // creatAbility function returns ability instance of casl taking user's permissions array

function ruleToSequelize(rule: any) {
    return rule.inverted ? { $not: rule.conditions } : rule.conditions;
}

const query = rulesToQuery(moderatorAbility, "update", "Article", ruleToSequelize);

console.log(query); // output: { '$or': [ { publised: true, tags: ["AI"] } ] }

My expectation is the output of the query should print like this { '$and': [ { publised: true, tags: ["AI"] } ] }

Can anyone explain why $or property getting created even the condition is not inverted.

Thanks in advance :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source