-
Notifications
You must be signed in to change notification settings - Fork 4
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
Support functions in input context #33
Comments
This is still failing with both of the following: import { ruleFactory } from '@elite-libs/rules-machine';
const things = [
{
name: "ABC"
},
{
name: "DEF"
},
{
name: "123"
}
];
const thingRules = ([
{
if: 'isConditional(thing.name) == false', then: 'keep = false'
},
{
return: "keep"
}
]);
const filterWithRules = ruleFactory(thingRules)
function isFiltered(thing: Record<string, string>): boolean {
const result = filterWithRules({
thing,
isConditional: (value:string) => value.endsWith('C'),
keep: true
});
return result;
}
console.dir(things.filter(isFiltered)); import { ruleFactory } from '@elite-libs/rules-machine';
const things = [
{
name: "ABC"
},
{
name: "DEF"
},
{
name: "123"
}
];
const thingRules = ([
{
if: 'isConditional(thing.name)', then: 'keep = false'
},
{
return: "keep"
}
]);
const filterWithRules = ruleFactory(thingRules)
function isFiltered(thing: Record<string, string>): boolean {
const result = filterWithRules({
thing,
isConditional: (value:string) => value.endsWith('C'),
keep: true
});
return result;
}
console.dir(things.filter(isFiltered)); |
Found what may be the source of the problem: import { ruleFactory } from '@elite-libs/rules-machine';
const things = [
{
rateCode: "Z2H",
provider: "Marriott",
shouldKeep: false
},
{
rateCode: "C13",
provider: "This is a Marriott Hotel",
shouldKeep: false
},
];
const thingRules = ([
{
if: 'stringContains(LOWER(thing.provider), "marriott")',
then: "keep = false"
},
{
return: "keep"
}
]);
const filterWithRules = ruleFactory(thingRules, { trace: true })
function isFiltered(thing: Record<string, string>): boolean {
const result = filterWithRules({
thing,
stringContains: (value: string, search: string): boolean => value.includes(search),
keep: true
});
console.dir(result.trace)
return result;
}
console.dir(things.filter(isFiltered)); According to the trace, it appears that {
operation: 'expression',
rule: 'stringContains(LOWER(thing.provider), "marriott")',
result: [ 'this is a marriott hotel', 'marriott' ],
stepRow: 0,
stepCount: 1
},
{
operation: 'if',
rule: 'stringContains(LOWER(thing.provider), "marriott")',
result: true,
currentState: '{"thing":{"rateCode":"C13","provider":"This is a Marriott Hotel","shouldKeep":false},"keep":true}',
stepRow: 0,
stepCount: 1
}, I base this presumption on how it is evaluated if I strip the function name out manually: {
operation: 'expression',
rule: '(LOWER(thing.provider), "marriott")',
result: [ 'this is a marriott hotel', 'marriott' ],
stepRow: 0,
stepCount: 1
},
{
operation: 'if',
rule: '(LOWER(thing.provider), "marriott")',
result: true,
currentState: '{"thing":{"rateCode":"C13","provider":"This is a Marriott Hotel","shouldKeep":false},"keep":true}',
stepRow: 0,
stepCount: 1
}, |
@chhatch @justsml Replit for the above example: https://replit.com/@dara-rockwell/Rules-Machine-Custom-Functions#index.ts |
Good spotting @dara-rockwell. It looks like there is a function safe list thing going on. |
No description provided.
The text was updated successfully, but these errors were encountered: