-
-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added additionalData field to Rule class #752
Conversation
Codecov Report
@@ Coverage Diff @@
## master #752 +/- ##
==========================================
+ Coverage 94.81% 95.16% +0.34%
==========================================
Files 34 34
Lines 733 724 -9
Branches 174 170 -4
==========================================
- Hits 695 689 -6
Misses 18 18
+ Partials 20 17 -3
... and 8 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
sorry but I do not understand the usage, also you can store additionalData outside of rule using |
Separate object with extra info is not comfortable. (And i can't understand how we can match rule with source rule without any id) For example if we will add this free prop we can create rule like this:
this is optional prop, it don't break existing behavior. It just give freedom and ability to investigate issues. We can't use WeakMap because RuleClass creating inside PureAbility. We give RawRules to constructor, and get ability with rules(RuleClass). It's different instances. |
I see. Thanks for the explanation, I plan some day to add ability to trace decision. Something like this const tracer = new DecisionTracer()
const ability = new Ability([], { tracer })
const isAllowed = ability.can(....);
console.log(tracer.explainLatestCall())
/*
[
{
testedRule: rule,
conditionsMatched: true | false,
conditions: [
{
conditionOperator: 'and',
matched: true | false,
condition: /* raw condition */
children: [
{
conditionOperator: 'eq',
matched: true | false,
condition: /* raw condition */
}
]
}
],
matchedField: null | string
},
//...
]
*/ |
I don't like the idea of storing unstructured data inside Rule, later anybody will want to put there anything and I will need to support many other cases later or keep that unstructured data forever :) what I can do is to add public reference to origin rawRule (e.g., |
It's acceptable solution. I will change this PR. |
Tracer will be useful for me. If you create it i will use it also. |
This PR will add prop 'origin' to RuleClass. This prop will point to original RawRule.
It will give great abilities for debug and other.
Conversation saved at this PR. Description was changed.