pub struct Event {
pub event_id: Uuid,
pub aggregate_type: String,
pub aggregate_id: String,
pub sequence: i64,
pub event_type: String,
pub payload: Value,
pub audit: AuditMetadata,
pub timestamp: u64,
}Expand description
Core event type representing an immutable domain event.
§Fields
event_id: Unique identifier for this specific event occurrenceaggregate_type: Type of aggregate this event belongs to (e.g., “User”)aggregate_id: ID of the specific aggregate instancesequence: Sequential number within the aggregate stream (starts at 1)event_type: Type of event (e.g., “UserRegistered”)payload: Event data as JSON (flexible, evolvable schema)audit: HIPAA audit metadata.pending()until the bus stamps it.timestamp: When the event occurred (milliseconds since UNIX epoch)
Fields§
§event_id: UuidUnique identifier for this event
aggregate_type: StringAggregate type (e.g., “User”, “Order”)
aggregate_id: StringAggregate instance identifier
sequence: i64Sequence number within the aggregate (starts at 1)
event_type: StringEvent type (e.g., “UserCreated”, “ProfileUpdated”) Convention: Past tense, PascalCase
payload: ValueEvent payload as JSON
audit: AuditMetadataHIPAA audit metadata. AuditMetadata::pending() until the
CommandBus overwrites it before append. EventStore::append
implementations call audit.validate() and reject pending values.
timestamp: u64Wall-clock timestamp (milliseconds since UNIX epoch). For HIPAA
audit-quality time, use audit.timestamp_utc_us (microsecond precision).
Implementations§
Source§impl Event
impl Event
Sourcepub fn new(
aggregate_type: impl Into<String>,
aggregate_id: impl Into<String>,
sequence: i64,
event_type: impl Into<String>,
payload: Value,
) -> Self
pub fn new( aggregate_type: impl Into<String>, aggregate_id: impl Into<String>, sequence: i64, event_type: impl Into<String>, payload: Value, ) -> Self
Create a new event with audit = AuditMetadata::pending().
Aggregates call this from handle() and the CommandBus overwrites the
audit field with a request-scoped value before persisting. The
pending placeholder fails store-side validation, so a forgotten stamp
is impossible to commit.
§Example
use arc_core::event::Event;
use serde_json::json;
let event = Event::new(
"User",
"user-456",
1,
"UserCreated",
json!({ "name": "Bob", "email": "bob@example.com" }),
);
assert!(event.audit.is_pending());Sourcepub fn with_audit(self, audit: AuditMetadata) -> Self
pub fn with_audit(self, audit: AuditMetadata) -> Self
Replace audit with a fully-stamped value. Used by CommandBus
before calling EventStore::append.