-
Notifications
You must be signed in to change notification settings - Fork 79
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 for input data validation #167
Comments
Hi @bala-pitchuka, We have some initial plans of looking into type-safety in the future. Our foundation will rest on a dynamic language - ZEN Expressions that will be enhanced with type support at some point. For now, most common pattern is to do validation of the data before sending it to the rules engine. Depending on the language used, there are some great options: Zod (TypeScript), Validator (Go), validator (Rust crate), etc. |
This is something that will be possible with Function v2 through usage of Zod. We will provide an example in docs soon. |
Hi @stefan-gorules ! I have been exploring the ZenEngine library in Node for a in-house BRMS prototype. Firstly great work on the library! it has intuitive semantics and is very performant as well. if I'm approaching this incorrectly please suggest a way! |
@stefan-gorules docs would be great to explore the same, thnks |
hi @bala-pitchuka , with import { z } from "zod";
/* input
{
age: 20,
salary: 3000.25,
name: "John"
}
*/
export const handler = async (input) => {
const schema = z.object({
age: z.number()
.min(15, { message: "Age must be at least 15" })
.max(60, { message: "Age must be at most 60" }),
salary: z.number()
.nonnegative({ message: "Salary must be non-negative" })
.refine(value => value.toFixed(2) === value.toString(), {
message: "Salary must have up to 2 decimal places"
}),
});
const result = schema.safeParse(input);
if (result.success) {
return result.data
} else {
console.log(result.error)
return {}
}
}; |
Hi,
Just want to check if there is an existing mechanism to check that all mandatory fields are provided to zen engine without missing during evaluation.
like a sample rule if threshold > 23 then HOLD
if threshold is not provided as input to zen then them some validation error need to be thrown
Also how to check the json is a valid jdm json before execution currently facing following issue when run, just want to eliminate such issues during rule jdm json creation itself
RuntimeError: {"type":"NodeError","nodeId":"","source":"Graph did not halt. Missing output node."}
thnks
The text was updated successfully, but these errors were encountered: