Chuyển tới nội dung chính

riverbase_proc

riverbase_procCore · v0.2.0

Procedural macros: #[domain_action] and riverbase_namespace!.

cargo add riverbase_proc --git https://github.com/riverbase-io/riverbase

Two procedural macros. Everything else in Riverbase is a declarative macro_rules! macro exported from riverbase_core.

#[domain_action]​

Marks an aggregate method as an action: the only place state may change.

use riverbase_proc::domain_action;

impl<S: DataStore + 'static> TodoAggregate<S> {
#[domain_action(event = "todo.created", resources = ["todo"])]
pub async fn create(&mut self, title: &str) -> RiverbaseResult<Value> {
// upsert / update / create / remove are allowed here
// emit_message and emit_activity stay explicit
Ok(json!({ "title": title }))
}
}
AttributeRequiredMeaning
eventyesThe event key recorded on Ok, such as "todo.created". It names the action, not the command.
resourcesnoAllow-list of resources this action may write. A mismatch is CMD-003.

Requirements:

  • The method is async, takes &mut self, and returns RiverbaseResult<_>.
  • The aggregate has a field named core: AggregateCore<S>.
  • The event key appears in registered_event_keys().

On Ok(result), the action queues one event_log row with {input, result}; it is persisted when the command session finishes, inside the same transaction. On Err, nothing is queued and the transaction rolls back. State writes outside any action fail with DOM-016.

riverbase_namespace!​

Builds a Namespace from a string literal. It is shorthand for riverbase_core::base::Namespace::new("…") and only accepts a literal:

use riverbase_proc::riverbase_namespace;

let ns = riverbase_namespace!("riverbase.todo");