Skip to content

Feature/add value pipes support #314

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

Closed

Conversation

migzzi
Copy link

@migzzi migzzi commented Sep 19, 2022

Add support for pipes to manipulate fact values.

Here is an example of using a pipe to transform the balance currency from euros to USD and another one for applying a discount to the product.

const discount = 0.5;
const rule = {
    conditions: {
      all: [{
        fact: 'account',
        path: '$.balance',
        params: {
          accountType: 'eurosAccount'
        },
        pipes: [ { name: 'euroToUSD' } ],
        operator: 'greaterThanInclusive', 
        value: {
          fact: 'product',
          path: '$.price',
          pipes: [ { name: 'scale', args: [discount]}],
          params: {
            productId: 'giftCard'
          }
        }
      }]
    },
    event: { type: 'customer-can-partially-afford-gift-card' }
  }
 
 engine.addPipe('euroToUSD', (val) => val * 1.1)

@migzzi
Copy link
Author

migzzi commented Sep 20, 2022

@CacheControl I need your review on this if you got some time.

@yoni333
Copy link

yoni333 commented Feb 19, 2023

i think this feature is out of the scope of rule engine. it is nice to have.... but it will break the pure rule engine concept. pipes will move as to the STATE MACHINE zone

@CacheControl
Copy link
Owner

re-opening for visibility and to hear more opinions on this feature; I can see it being valuable for certain situations.

@chris-pardy
Copy link
Collaborator

@CacheControl my thought on this is that we could make the Condition constructor pluggable, so that it's easy to drop in custom condition classes. Additionally a way to plug in custom Almanacs could fill this role.

Over all what I think we should focus on for improvements is less new features and more ways to plug in new features by providing points at which other code can step in.

@chris-pardy
Copy link
Collaborator

@CacheControl see #356 for part of the work to support something like this. The ability to plug in custom condition classes in order to add arbitrary logic. In this case the support for pipes would need to live in the condition.

@yoni333
Copy link

yoni333 commented Oct 18, 2023

in my work place we was need to add some changes in the source code in order to get data on array conditions - to know the index inside the array that fail the condition check. so we pass and expose the "this" of the inner rule object ..
so it is needed for better data type "Array" results.

@chris-pardy chris-pardy mentioned this pull request Nov 5, 2023
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.

4 participants