#[non_exhaustive]pub struct NewEvent {
pub correlation_id: CorrelationId,
pub causation_id: Option<CausationId>,
pub conversation_id: ConversationId,
pub process_id: ProcessId,
pub tenant_id: TenantId,
pub workflow_id: WorkflowId,
pub event_type: Box<str>,
pub schema_version: u32,
pub payload: Value,
}Expand description
A pending event ready to be appended to a stream.
The caller constructs a NewEvent for each domain event produced by a
workflow command. Fields that the store assigns (event_id,
sequence_number, timestamp, stream_id) are absent.
§Idiomatic construction
Prefer CommandContext::new_event
inside workflow handlers and transport adapters — it propagates all
correlation IDs from the command context automatically:
// Inside a MessageAdapter or test:
let new_event = ctx.new_event(&SupplierChangeEvent::Initiated { .. })?;
store.append(&stream_id, ExpectedVersion::Any, &[new_event]).await?;Use EventEnvelope::new_caused_event when building a follow-up event
causally linked to a prior persisted event.
For test scaffolding that needs a NewEvent without a typed payload or
context, use NewEvent::new. The #[non_exhaustive] attribute
future-proofs callers against new optional fields being added without
requiring a semver-breaking change.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.correlation_id: CorrelationIdGroups all events that originate from the same root command.
causation_id: Option<CausationId>The event or command that directly caused this event, if any.
conversation_id: ConversationIdLinks events belonging to the same business conversation.
process_id: ProcessIdStable identifier for the MaKo process instance.
tenant_id: TenantIdTenant that owns this event.
workflow_id: WorkflowIdWorkflow definition that produced this event.
event_type: Box<str>Stable, human-readable type discriminant (e.g. "SupplierChangeInitiated").
schema_version: u32Schema version of the serialized payload.
payload: ValueThe domain event payload, serialized as JSON.
Implementations§
Source§impl NewEvent
impl NewEvent
Sourcepub fn new(
correlation_id: CorrelationId,
causation_id: Option<CausationId>,
conversation_id: ConversationId,
process_id: ProcessId,
tenant_id: TenantId,
workflow_id: WorkflowId,
event_type: impl Into<Box<str>>,
schema_version: u32,
payload: Value,
) -> Self
pub fn new( correlation_id: CorrelationId, causation_id: Option<CausationId>, conversation_id: ConversationId, process_id: ProcessId, tenant_id: TenantId, workflow_id: WorkflowId, event_type: impl Into<Box<str>>, schema_version: u32, payload: Value, ) -> Self
Construct a NewEvent from its constituent parts.
This is the escape hatch for callers that need full control over all
fields (e.g. test scaffolding, migration tooling, storage-layer tests).
In application code, prefer
CommandContext::new_event
which propagates correlation metadata automatically.