Skip to content

Support Facts In Events #345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 23, 2023
Merged

Conversation

chris-pardy
Copy link
Collaborator

This adds support via an engine option flag to allow event params to include reference to facts like values do.
The structure of this is that for event parameters the top-level keys may have the value: { "fact": "<fact id>" } at which point they'll be converted into the actual fact value when the rule is evaluated. You can use path and param helpers the same as any other reference to a fact.

The primary use case for this is as a way to externaize values for the events into facts so they can be shared, or so they can change without the rule needing to change. Additionally moving away from needing event / rule specific handlers allows the rules to more completely configure the system for instance:

const maxBidRule = {
   conditions: {
      all: [
         { condition: "desireable" },
         {
            fact: "remainingCash",
            operator: "greaterThanInclusive",
            value: { fact: "maxBid" }
         }
     ]
  },
  event: {
      type: "bid",
      params: {
          amount: { fact: "maxBid" }
      }
  }
}

const allInRule = {
      conditions: {
         all: [
            { condition: "desireable"  },
            {
                fact: "remainingCash",
                operator: "lessThan",
                value: { fact: "maxBid" }
            }
        ]
    },
   event: {
       type: "bid",
       params: { 
         amount: { fact: "remainingCash" }
       }
   }
 }

@CacheControl
Copy link
Owner

Will look at this today!

Copy link
Owner

@CacheControl CacheControl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of minor comments, but overall looks like a great feature!

No need for re-review before merge. 👍

Support event parameters to include facts
this allows the events to reference values that are being stored
in a persistent storage mechanism or otherwise unknown when the rules
are written.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants