northwesternmutual/regent

Support JSON defined rules import

Closed this issue · 5 comments

Basically this feature is to allow the importing of a JSON defined rules structure (similar to regent < 3.x.x

{
  isHot: { greaterThan: ['@temperature', 55]  },
  isRaining: { equals: ['@precipitation', 'raining'] },
  windyAndCold: {
    or: [
      { greaterThan: ['@windSpeed', 10] },
      { lessThan: ['@temp', 65] }
    ]
  }
}

We could call regent.import on this rules object and the method would return an object of rules, with the value of each being a regent function. I propose that the first iteration of this not try to handle custom predicates. I can't think of a sane way to do that.

Here is a PR with code the handle JSON imports.

#40

No docs written yet, but if anyone has any feedback on the API let me know.

What about just regent.import(json, predicates)

Also, is this useful without a way to export as well?

@jesselee34 I think it's super useful without export. You could define a rules server that served rules to multiple applications.

I don't like regent import because import is a reserved keyword, so you couldn't do

import { import } from 'regent'

And I don't want to have to do this every time

import { import as importFn} from 'regent'

Plus, the parse function doesn't really import anything, it returns an object of regent functions