TotalTechGeek / json-logic-engine

Construct complex rules with JSON & process them.
MIT License
43 stars 9 forks source link

Help others discover this library #12

Closed Mihailoff closed 11 months ago

Mihailoff commented 12 months ago

After evaluating a number of options I luckily found your repo.

With the .build() method execution time went down significantly thus I'm quite happy with your library so far.

For my use case, a combination of https://github.com/mithunsatheesh/node-rules and https://github.com/TotalTechGeek/json-logic-engine makes up quite a robust rules engine.

TotalTechGeek commented 12 months ago

Thank you for your contribution! I appreciate you reaching out!

I'm currently on a trip, but when I get a chance I'll try to merge and release the tag changes.

If I may ask:

What features in Node-Rules are being used most extensively in your project?

I'm curious to see if I could provide a supplementary module to complement this package to better serve some lightweight use-cases.

Mihailoff commented 12 months ago

In my case, I process an array of documents and emit them when matched

const list = [doc1, doc2, ...]
list.forEach(doc => {
  if (logicEngine.run(doc)) emit(doc)
})

list.filter() doesn't work because there is a bit of logic in emit, this is one case why node-rules is handy.

Conceptually it is made for processing lists and it breaks the flow into the condition stage and action stage. JsonLogic is perfect for the condition stage but has nothing to offer for processing a list of documents.

Maybe this is just fine to limit the scope of the library to a document level. An example would be helpful, at the beginning, it was not clear how to use JsonLint-like libraries for lists.

TotalTechGeek commented 11 months ago

Conceptually it is made for processing lists and it breaks the flow into the condition stage and action stage. JsonLogic is perfect for the condition stage but has nothing to offer for processing a list of documents.

Right, definitely not on it's own! At least... not without unreasonable amounts of nesting higher order instructions & adding new methods.

However, as JSON-Logic can be used to wrap any function, I have paired it successfully in the past with libraries like RxJS to create declarative pipelines to handle streams of documents,

{
  "map": { "var": "body" } 
},
{
  "filter": { ">": [{ "var": "age" }, 21] }
},
{
  "bufferCount": 25
},
{
 "tap": { "log": "Publishing batch of 25..." }
}

I might want to provide a recipes page to show json-logic paired with libraries like Node-Rules and RxJS.

An example would be helpful, at the beginning, it was not clear how to use JsonLint-like libraries for lists.

A fair point! I think there's a lot of improvement that could be done on the docs. I may prioritize this soon.

Mihailoff commented 11 months ago

Looks interesting. Theoretically, we could implement similar to Node-Rules flow control as custom methods. We need some examples of how to work with methods, especially parameters. logic.addMethod('+1', (item) => item + 1) is great for basic operations but not sufficient for more complex use cases.