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§

contract
Each async fn returns a boxed future so the trait works as dyn.
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.
gateway
Calls run in <vendor>.<method> spans; see sofie::client.
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.
span
Its arguments are never recorded.
task
Read by sofie gen, which registers the task as <module>.<function>.
test_app
One database per test; the crate’s wiring must export MODULES, app and worker.

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.
Child
Needs an id: Id<Self> field; stored in its own table beside the aggregate’s.
Config
Read from its module’s <MODULE>_<FIELD> keys; a field of another struct deriving it reads <MODULE>_<FIELD>_*.
Enum
#[to(…)] lists a variant’s transitions.
Event
Fixture
Expands to nothing unless sofie’s fixtures feature is on.
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.