Declarative way for compute facts

Open
#292 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
javascript, json
Domain
backend

Research direction

No source file or test is named. Start by reviewing the documentation's discussion of computed facts and the existing addFact/function approach, then compare the proposed json-logic declaration for reusable derived facts. Done would require a maintainer decision on whether this belongs in the engine and, if accepted, a scoped design for storage and evaluation.

Written by the indexing model from the issue text.

Description

Hi! I consider this repo as a very helpful design approach! I'm looking forward and have thoughts about admin interface for editing and storing rules. But i think we have a lack of ability for storing complex computed facts. For example, i have a a big legacy system underneath my app, and some facts from there have a big value because they computes from multiple fields of big json document. I need to reuse that facts everywhere in my app. What can i do right now? I can use only functions for this objectives. Like this:

engine.addFact('account', (params, almanac) => {
    return almanac.bigDoc.path1.value + almanac.bigDoc.path2.value;
})

Ok, it's very flex and this approach cover all my needs, except storing.

My suggest:

We can use jsonLogic library (or similar operators inside this repo) for declaring facts like this:

new Fact('derivedFact', [ 'bigDoc' ], { '+' : [
        { 'var' : 'bigDoc.path1.value' },
        { 'var' : 'bigDoc.path2.value' },
    ]}
)

While i was browsing docs, i saw that you considered this as a design bad smell. Why? Can you explain? Or i can suggest PR? 🙂

Dominant language
JavaScript
Stars
3.1k
Forks
507
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from CacheControl/json-rules-engine

All issues in CacheControl/json-rules-engine

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.