imicros-rules-compiler
Installation
$ npm install imicros-rules-compiler --save
Usage
Usage Compiler
const Compiler = ; let exp;// Define rule setexp = "@@ "exp += "~F user.groups.name[..string]; > result.acl[string]:= 'decline'; > result.rule[number]:= 0"exp += "@ user.groups.name :: 'admin','guests' => result.acl := 'allow'; result.rule := 1"exp += "@ user.groups.name :: 'others','members' => result.acl := 'allow'; result.rule := 2"exp += "@@" Compiler;
Rules Language
@@
starts and ends the ruleset.@
starts a new rule.=>
starts the defintion the resulting output.- All conditions are defined left of
=>
. Multiple conditions are separated by;
. Each condition has exactly one parameter on the left side of::
the required values to check on the right side. - The expression on the right side of an condition can be a single value, a list of values, a comparison like
> 5
or a range[2018-1-21..2018-2-23]
. - After the initial
@@
can follow the hit policy~F
and type defintions of the used parameters in the ruleset. Definitions of output parameter are noted with a leading>
. Parameters can be initialized with default values - e.g.result.acl[string]:= 'decline'
.
Type definitions
Valid types are
[string]
[..string]
array of strings[number]
- as decimal point, only.
is allowed. The regex for numbers is/(0[xX][ \d a-f A-F ]+|0[oO][0-7]+|0[bB][01]+|(?:\d+(?!(?:.\d|\d)))|(?:\d+.\d+)(?!(?:.\d|\d))(?: [eE][+-]?\d+ )?)/
[..number]
array of numbers[date]
[..date]
array of dates[time]
[..time]
array of times[boolean]
Examples for valid conditions
user.age :: >= 16 & <= +35
Age is between 16 and 35environment.date :: [2018-1-21..2018-2-23],>=2018-05-07
Date is between 2018-1-21 and 2018-2-23 or greater equal 2018-05-07environment.time :: [6:00..08:00:00],>=18:00
Time is between 6 and 8 am or after 6pmage :: ]12..16[,>65
Age is between 13 and 15 (the interval values 12 and 16 are excluded).