json-schema-rules-engine icon indicating copy to clipboard operation
json-schema-rules-engine copied to clipboard

schema for services who get the rule selection

Open dgreene1 opened this issue 3 years ago • 1 comments

Can you share with me if there is a universally agreed upon standard for sending rules over HTTP via JSON?

Because I notice that there is a specific type for the output mentioned in the readme, but some of this (like the memorizer and resolver) are not JSON serializable since they are functions.

type Options = {
  facts?: Record<string,Fact>;
  rules?: Record<string,Rule>;
  actions?: Record<string,Action>;
  pattern?: RegExp; // for interpolation
  memoizer?: <T>(a: T, b: T) => boolean;
  resolver?: (subject: Record<string,any>, path: string) => any
};

So what I’m looking for is a JSON Schema spec that I can point to to say “this is what the API that reads the rule selections expects to receive.”

For full context, my team is building a temporary component that we will replace with your React component. So having a standardized output will allow us to make that swap easily (ie the adapter pattern). And it will let us start building the services before the UI is written. Thank you for the guidance.

dgreene1 avatar Sep 30 '22 11:09 dgreene1

if there is a universally agreed upon standard for sending rules over HTTP via JSON

Nope. It's up for you and your team to decide.

like the memorizer and resolver

The memoizer isn't related to how the rules are transmitted, only how the rules engine is run and it isn't important across HTTP. The resolver is just an agreed upon format that you decide to use to resolve nested values - in general you'll either use json path or dot notation.

So what I’m looking for is a JSON Schema spec that I can point to to say “this is what the API that reads the rule selections expects to receive.”

I'm not sure what you mean by

expects to receive

Perhaps you mean the then/otherwise that we use? As in:

{

  when: {
     // some set of facts that you can evaluate
  },
  then: {
    // some actions to perform, or nested rules to evaluate if the when block resolves to true
  },
  otherwise: {
    // some actions to perform, or nested rules to evaluate if the when block resolves to false
  }

}

If so, this isn't defined by JSON schema spec, it's just a convention that this library uses.

This library uses (or suggests that you use) standard JSON Schema - at the is key of an evaluator - only as a predicate, i.e. to evaluate whether some data returns true when validated against schemas. The output - actions - of the engine is completely up to you and your team.

I'm not sure if I've answered your questions, I'm happy to provide more concrete examples for a specific use case if you can elaborate.

akmjenkins avatar Oct 04 '22 01:10 akmjenkins