ontoref-code/examples/catalog-extension/01-rust/README.md

59 lines
2.2 KiB
Markdown
Raw Permalink Normal View History

# Path A — `kind = 'Rust`
Default path. The op is compiled into the daemon binary via
`inventory::collect!` at link time. Full Rust type safety; replay-
deterministic by construction; zero runtime overhead.
## Files
| File | Purpose |
| --- | --- |
| [`greet_actor.ncl`](greet_actor.ncl) | Catalog declaration — typechecks against `schema-future.ncl` |
| [`greet_actor.rs`](greet_actor.rs) | Handler — copies to `crates/ontoref-ops/src/ops/greet_actor.rs` |
## How to integrate into ontoref-el-proyecto
1. Copy the catalog declaration:
cp examples/catalog-extension/01-rust/greet_actor.ncl \
.ontoref/catalog/operations/greet_actor.ncl
(Remove the `kind = 'Rust` line if migration 0025 is not yet applied —
the current schema doesn't accept the field but defaults the
behaviour to Rust.)
2. Copy the Rust handler:
cp examples/catalog-extension/01-rust/greet_actor.rs \
crates/ontoref-ops/src/ops/greet_actor.rs
echo 'pub mod greet_actor;' >> crates/ontoref-ops/src/ops/mod.rs
3. Author the matching validators (out of scope of this example):
`actor_exists`, `tone_in_allowed_set`, `greeting_recorded` — each as
a `#[onto_validator]` function. See
`crates/ontoref-ops/src/precondition/` for the pattern.
4. Build and test:
cargo build -p ontoref-daemon
cargo test -p ontoref-ops greet_actor
5. Dispatch:
curl -X POST http://127.0.0.1:7891/ops/greet_actor \
-H "Authorization: Bearer $ONTOREF_TOKEN" \
-d '{"actor_id":"jpl","tone":"dao"}'
## Key properties
- **Witness coverage**: the daemon signs the canonical serialisation of
the state delta (the new `current_state` value in the `actor-greeting`
FSM dimension). The signature attests the in-process computation.
- **No `evaluate_ondaod` required in pre-validators**: Rust ops can
invoke `dispatch::call("evaluate_ondaod", …)` inline when needed.
The schema-level Hard constraint
[`non-rust-kinds-require-ondaod-pre`](../../../.ontoref/adrs/adr-034-catalog-extensibility-beyond-rust.ncl)
only applies to `kind != 'Rust`.
- **Backward-compatible**: omitting `kind` in the declaration is
equivalent to declaring `'Rust` (default).