Skip to main content

Crate sofie_macros

Crate sofie_macros 

Source
Expand description

Derives emit trait impls and descriptions only; behaviour lives in the libraries.

Attribute Macros§

every
Interval as 30s, 15m, 1h, 1d; each = query runs it per listed record, one job each. Or a time on a zone’s clock: daily_at = "03:00", zone = "Europe/Istanbul", and with weekly_on = "monday" on that day only.
feature
Written #[sofie::feature(FLAG)]: a bare feature is Rust’s own crate attribute.
job
Read by sofie gen, which registers the job with the worker.
on
Takes no arguments: naming the event again could only disagree with the argument’s type.

Derive Macros§

Aggregate
#[owner] marks the Id<…> field naming the owner; on the struct, a record that is its own owner, or with (through = parent) one owned by its parent’s owner. #[aggregate(behaviors(Slugged(from = name)))] adds behaviors to Versioned and Timestamps. Field constraints are those of #[derive(Input)]. A #[sensitive] field shows as *** in Debug and logs; it and one of a sensitive type stay out of JSON and search.
Enum
#[to(…)] lists a variant’s transitions.
Event
Input
#[min(n)]/#[max(n)] bound text characters or a number’s value; #[length(min, max)], #[range(min, max)], #[required] (not blank) and #[unique] (held by the database only). #[input(from = Order)] inherits Order’s field constraints, #[unconstrained] drops them; #[input(validate)] runs Validate after them.
ReadModel
#[read(from = Aggregate)]; #[read(via = Base::COLUMN, field = Other::COLUMN)] reads a column of the record the base’s id column names. A field reading a sensitive one needs #[sensitive].
Value
#[sensitive] masks it in Debug. As a handler’s input it is read from the body field named after the type: cancel(order: Order, cancel_reason: CancelReason) takes { "cancel_reason": … }, and Option<CancelReason> takes it or nothing.