-
Notifications
You must be signed in to change notification settings - Fork 503
Fact paths #9
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
Fact paths #9
Conversation
@CacheControl Thanks for doing this! I'll try it out :-) |
@CacheControl , I tested a couple of paths. The second doesn't seem to be triggering either - properties with depth for example, "address.prop.test[0].zipcode". I was attempting to trigger on empty values. Might I be setting up the Condition incorrectly for the object? // test object // rule |
@slmmm Thanks for taking a crack at this! Your sample looks correct, perhaps you're testing against version 1.1, which I released earlier this week? These changes haven't been pushed to npm. If that was the case, I've just published If something else is going on, maybe double check against this test, which demonstrates a similar situation. |
Yes, you're correct. I should have pulled rather than install from npm. A Question - how might it be possible for us to also reference this path functionality from within a custom fact where we're getting facts from a call to almanac.factValue()? |
Cool, glad it works. Regarding accessing this functionality within a custom fact - I'd like to know more about your motivations. For example:: // why would this:
engine.addFact('account-information', function (params, almanac) {
return almanac.factValue('address', {}, '.prop.test[0].zipcode') // path as the third arg, for example
})
// be preferable to this:
engine.addFact('account-information', function (params, almanac) {
return almanac.factValue('address', {}).then(address => address.prop.test[0].zipcode)
}) |
The preference is for dynamic rule building of its conditions. // In this case, the fact value reference is hard-coded, and only changed programmatically. This fact can only be used in one scenario in which address object has the specific path. But in our case, we are attempting to utilize generalized custom facts that allow for reuse across more than a specific object. In order to do this, we've been using "params" to carry the various "paths" we're interested in. As you point out though, it would be outside the scope of a "fact" to comprehend the multitude of "rules" and their varying properties like 'path'. Thinking on this a bit more, for our current cases, we may actually be able to use the combination of the new "path" functionality and the new "custom operator" functionality to accomplish what we're doing in our generalized custom facts. |
Hi My Fact JSON is this : and My Rules is : I am getting an error while running it. Engine is throwing error that it could not convert ObjectType to String. Since JSON object item is in the fact it trying to compare it as a string to my condition. Please help where I am doing it wrong. |
Adds support for traversing an object returned from a fact.
@ctaity @slmmm - will this work for solving your use cases?