Coder Social home page Coder Social logo

nested-rules-engine's Introduction

nested-rules-engine

🌲Decision Tree based Rules Engine

CircleCI codecov npm version install size

code style: prettier semantic-release

Synopsis

A simple Decision tree based Rule Engine described using json files. Rules are executed according to decision tree. Create a set of rules (make them nested as you like) and based on set of inputs run the rules.

Features

  1. Rules expressed in huaman readable JSON
  2. Create new set of inputs or change existing inputs as you traverse rules tree
  3. Do multiple executions or rules set

Installation

npm install nested-rules-engine --save

Basic Example

const {executeEngine} = require('nested-rules-engine');

// Step1: Define your conditional rules
const rules = {
  "you_are_a_human": {
    "you_are_kind": "help_me_find_my_book",
    "you_are_smart": "please_do_my_homework",
  },
  "default": "please_do_my_homework"
};

// Step2: make set of inputs collection
const inputs = {
  "type" : "human",
  "kindnessLevel": 0,
  "intelligence": 10
}

// Step3: Make your custom Functions
const functions = {
  default : () => true,
  you_are_a_human: ({type}) => type === 'human',
  you_are_kind: ({kindnessLevel}) => kindnessLevel > 300,
  you_are_smart: ({intelligence}) => intelligence > 5,
  help_me_find_my_book: () => ({
    payload: 'lets help someone',
    effort: 'finding the book'
  }),
  please_do_my_homework: () => ({
    payload: 'doing homework',
    effort: 'im getting sick'
  })
};

// Step4: Execute Engine
const res = executeEngine(inputs, functions, rules);

// Output res:
/*
{
  result: { payload: 'doing homework', effort: 'im getting sick' },
  logs: []
}
*/

Documentation

Engine Execution Signature:

executeEngine(variables, functions, rules, options);

Inputs

  • variables Collection of values on which rule engine will execute You can change these collection of variables (Add/Edit/Delte them) as you traverse the decision tree of rules.

  • functions Collection of functions that decide which way the tree should be traversed.

    • In case the function indicates a final decision in tree (leaf of decision tree): Output can be anything that you want to see as result
    • In case the function is makes an intermediate decision (branch of decision tree):
      • if output is true: this means this branch should be traversed
      • else: the function will be executed
  • rules Decision Tree that will be traversed by this Rule Engine

  • options there are different options that you can provide to customize the execution nature

    • verbose (boolean): Makes Sure you get enough logs while engine goes through all decision tree
    • multiple (boolean): You can run multiple Decision Trees based on same inputs. Input sets are shared between each tree

Outputs

  • result: Result of the engine execution. format of Result will be defined by you through functions
  • logs: Detailed logs while engine got executed (by default its disabled)

Hard Examples

  1. Example with verbose output, multiple executions Find Here
  2. Example with Creating new set of inputs while engine is executing Find Here

License

MIT

nested-rules-engine's People

Contributors

ayonious avatar renovate-bot avatar renovate[bot] avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

fossabot

nested-rules-engine's Issues

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
  • circleci/node 12
npm
package.json
  • @semantic-release/changelog ^5.0.1
  • @semantic-release/git ^9.0.0
  • @types/jest ^26.0.22
  • husky ^6.0.0
  • jest ^26.6.3
  • prettier ^2.2.1
  • pretty-quick ^3.1.0
  • semantic-release ^17.4.2
  • ts-jest ^26.5.5
  • typescript ^4.2.4

  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.