pub struct CommandContext {
pub actor_id: String,
pub session_id: Option<String>,
pub source_ip: Option<String>,
pub user_agent: Option<String>,
pub correlation_id: Uuid,
pub causation_id: Option<Uuid>,
}Expand description
Request-scoped context for command dispatch.
Constructed once per HTTP request (or by CommandContext::system for
internal jobs). Carries the data needed to build AuditMetadata for every
event the command produces.
Fields§
§actor_id: StringRequired. Aggregate UUID, "system", "anonymous", or
"legacy-pre-hipaa". Must be non-empty.
session_id: Option<String>Optional session id (paired with HIPAA-4 server-side session store).
source_ip: Option<String>Source IP. None for system jobs.
user_agent: Option<String>User-Agent header.
correlation_id: UuidRequired. Groups every event from one logical request together.
causation_id: Option<Uuid>Optional event id that triggered this command (saga / projection follow-up).
Implementations§
Source§impl CommandContext
impl CommandContext
Sourcepub fn for_actor(actor_id: impl Into<String>) -> Self
pub fn for_actor(actor_id: impl Into<String>) -> Self
Convenience for an authenticated HTTP request. Synthesizes
correlation_id if not supplied by the caller.
Sourcepub fn caused_by(actor_id: impl Into<String>, triggering: &Event) -> Self
pub fn caused_by(actor_id: impl Into<String>, triggering: &Event) -> Self
Build a context whose causation chains from a triggering event. Inherit
the upstream correlation_id so the saga is traceable end-to-end.
Sourcepub fn to_audit(&self) -> Result<AuditMetadata, AuditError>
pub fn to_audit(&self) -> Result<AuditMetadata, AuditError>
Convert into the AuditMetadata that will stamp produced events.
Sets timestamp_utc_us = now. Validates before returning.
Trait Implementations§
Source§impl Clone for CommandContext
impl Clone for CommandContext
Source§fn clone(&self) -> CommandContext
fn clone(&self) -> CommandContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more