jruizgit / rules

Durable Rules Engine
MIT License
1.16k stars 206 forks source link

Issue found when using nested arrays #189

Open hea-lab opened 5 years ago

hea-lab commented 5 years ago

Hi Jesus,

The following rule does not work properly

d.ruleset('test', function() {
    whenAll: m.array1.anyItem(item.array2.anyItem(item.field21 == 1) && item.field == 8)
    run: console.log("test", JSON.stringify(m))
});

The action code is fired with the following event which is not correct

curl -H "Content-type: application/json" -X POST -d '{"array1": [{"field" : 7, "array2" : [{"field21" : 1}]}]}' http://localhost:5000/test/events

If I slightly modify the above rule (changing the order of the conditions), the above event does not fire the action.

d.ruleset('test', function() {
    whenAll: m.array1.anyItem(item.field == 8 && item.array2.anyItem(item.field21 == 1))
    run: console.log("test", JSON.stringify(m))
});
jruizgit commented 5 years ago

Hi, thanks for reporting this problem. I will take a look and reply back with my findings.

jruizgit commented 5 years ago

I have pushed a fix for array evaluation. The rules above now work as expected. Please use version 2.0.7.