Getting started
Basic Example
Write, compile, and evaluate a rule
This page walks through writing a small rule, compiling it, and
evaluating it against an input. It assumes you have the
CLI installed and on your PATH.
1. Write the ruleset
Create a file named Approve.ruleset:
signal BlockAccount(user_id)
rule Approve {
is_adult = input.age >= 18
emit BlockAccount(input.user_id) when !is_adult
out approved = is_adult
}What this says:
signal BlockAccount(user_id)declares an external event the rule may emit, with one parameter.- The rule binds a local
is_adult, conditionally queues aBlockAccountemission, and exposesapprovedas an output.
For a deeper tour of the language, see Language basics.
2. Compile
nodora compile -f Approve.rulesetThe compiler writes Approve.json next to the source. This file is the
NIR (Nodora Intermediate Representation): a portable program you can
ship and load anywhere a Nodora evaluator runs.
3. Evaluate
Pipe a JSON input into the evaluator and let the CLI run a shell command for each emitted signal:
echo '{"user_id":"u42","age":17}' | nodora eval -f Approve.json --stdin \
-e "BlockAccount=echo blocked: {1}"Output:
\(^_^)/ evaluation completed in 12 µs
---
{"outputs":{"approved":false},"emitted_signals":[{"name":"BlockAccount","args":["u42"]}]}
blocked: u42Two things happened:
- The rule's
out approvedis in theoutputsmap. - Because
is_adultwas false, theemit ... when !is_adultfired, the engine putBlockAccountinemitted_signals, and the--exechandler echoedblocked: u42.
What next
- Commands for the full CLI surface.
- Language basics for the syntax and semantics.
- Built-in functions for the standard library you can call from rules.
- Use Nodora from JavaScript if you want to embed the evaluator in a Node or browser app.