Nodora
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 a BlockAccount emission, and exposes approved as an output.

For a deeper tour of the language, see Language basics.

2. Compile

nodora compile -f Approve.ruleset

The 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: u42

Two things happened:

  • The rule's out approved is in the outputs map.
  • Because is_adult was false, the emit ... when !is_adult fired, the engine put BlockAccount in emitted_signals, and the --exec handler echoed blocked: u42.

What next

On this page