pub struct EventSchema { /* private fields */ }Expand description
The payload format of one event type: its current version and the steps that bring older payloads up to it. Events are stored as written and never changed; readers upcast them.
Made with Domain::event; its methods return it, so they chain:
shop_domain.event("ItemAdded", 2).upcast(1, |mut d| { d["qty"] = json!(1); d }); or
shop_domain.event("CustomerRegistered", 1).personal(&["email"], |_, id| id.to_owned());.
A subject function gets the payload and the aggregate’s ID, e.g.
|d, _| d["customerId"].as_str().unwrap_or_default().to_owned().
Implementations§
Source§impl EventSchema
impl EventSchema
Sourcepub fn personal(
self,
fields: &[&str],
subject: impl Fn(&Value, &str) -> String + Send + Sync + 'static,
) -> Self
pub fn personal( self, fields: &[&str], subject: impl Fn(&Value, &str) -> String + Send + Sync + 'static, ) -> Self
Keeps these top-level fields in the vault, as personal data of the subject subject
returns from the payload and the aggregate’s ID (see EventSchema for examples).
Events then hold only references; the kernel hands the values to workers and to
listeners allowed to read them, until an event erases the subject.
Sourcepub fn erases(
self,
subject: impl Fn(&Value, &str) -> String + Send + Sync + 'static,
) -> Self
pub fn erases( self, subject: impl Fn(&Value, &str) -> String + Send + Sync + 'static, ) -> Self
Makes this an erasing event: it deletes every vault value of the subject subject
returns, in every stream, and the snapshots that may hold them. Read models should drop
the subject’s data when they see it; rebuilt, they read null.
Sourcepub fn upcast(
self,
from: u32,
step: impl Fn(Value) -> Value + Send + Sync + 'static,
) -> Self
pub fn upcast( self, from: u32, step: impl Fn(Value) -> Value + Send + Sync + 'static, ) -> Self
Turns a payload of version from into one of version from + 1: step gets the old
payload and returns the new one. Declare one step per older version.
§Panics
If from is not a version below the current one.
Auto Trait Implementations§
impl Forget for EventSchema
impl Freeze for EventSchema
impl Move for EventSchema
impl RefUnwindSafe for EventSchema
impl Send for EventSchema
impl Sync for EventSchema
impl Unpin for EventSchema
impl UnsafeUnpin for EventSchema
impl UnwindSafe for EventSchema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request