Give name to a rule (and may be an id??)
See original GitHub issue@CacheControl Is there a way we can give names to our rules? So for example:
let volumeRule = new Rule({
**name: myVolumeRule //----- Note the name here**
conditions: {
all: [{
fact: 'volume',
operator: 'greaterThanInclusive',
value: 100
}]
},
event: { // define the event to fire when the conditions evaluate truthy
type: 'fouledOut',
params: {
message: 'Player has fouled out!'
}
}
,
priority: 100
});
So the reason for this is that when you are writing 100s of rules, you may want to give them name to identify which rule you are talking about. Also, if we are saving them into a database, we can save them in rows and identified by their names. Its helpful when you are managing a large number of rules.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (5 by maintainers)
Top Results From Across the Web
What If The Name On An ID Doesn't Match The Name On The ...
As a general rule, if the name on the ID provides enough detail to support that the signer is the same person as...
Read more >What are valid values for the id attribute in HTML?
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"),...
Read more >Name Variations in Proof Documents Create Major ...
That's because, under the rules for REAL ID–compliant licenses, the name on the documents required to prove the DL applicant's identity, ...
Read more >23.3.127 : FULL LEGAL NAME, NAME COMBINATION AND ...
(2) For driver licensing and identification card purposes, an applicant's full legal name is deemed to be the individual's name as shown on...
Read more >US Naming Laws by State - US Birth Certificates
Learn everything you need to know about naming laws by state —including which names are illegal for birth certificates where you live.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
thanks @CacheControl appreciate the heads up and suburb work on rule results! The example looks to be a perfect fit. Will implement beta2 to test in the next few days and let you know.
@slmmm You’re 100% correct! This project is coming up on a year old, and I think I’m starting to forget why certain design decisions were made. Thanks for keeping me honest! Also, I’d like to take this opportunity to thank you for your input on this project - it is very much appreciated.
@arsalans I’ve persisted rules in a database with this project before, so perhaps I can provide some guidance. Assuming you’re using a relational database, I think it’s best to think about each rule as being a column, rather than a row. So after calling
rule.toJSON()
, you might take that value and store it in adefinition
column. Our table schema looked something like the following:This allows you to add things like foreign keys to other resources (is the rule “owned” by something?), and provide columns for other metadata you find useful.
If you’re going the NoSQL approach, you’d probably want to follow the same conceptual pattern; simply nest the
rule.toJSON()
results into a dedicated property of whatever resource you’re persisting.Finally, I see the responsibility of enforcing things like rule uniqueness as being outside the scope of this library - as modeled above, this is something most database technologies (or if working on the front end, libraries like lodash) do very well already, and I’d prefer to keep
json-rules-engine
lightweight and un-opinionated in this regard; a thing that runs rules and spits out results.Does this help and/or address your concerns?