pub struct SyncEvent {
pub id: Uuid,
pub sequence: u64,
pub event_type: String,
pub entity_type: String,
pub entity_id: String,
pub payload: Value,
pub hash: String,
pub signature: Option<String>,
pub timestamp: DateTime<Utc>,
}Expand description
A sync event representing a state change in the system.
This is the Rust equivalent of the JS OutboxEvent and the VES v1.0
event envelope. Events are immutable once created.
§Examples
use stateset_sync::SyncEvent;
use serde_json::json;
let event = SyncEvent::new(
"order.created",
"order",
"ORD-123",
json!({"total": 99.99}),
);
assert_eq!(event.event_type, "order.created");
assert_eq!(event.entity_type, "order");
assert!(!event.hash.is_empty());Fields§
§id: UuidUnique event identifier.
sequence: u64Monotonically increasing sequence number (0 = unassigned).
event_type: StringThe type of event (e.g. order.created, inventory.adjusted).
entity_type: StringThe entity type this event applies to (e.g. order, customer).
entity_id: StringThe identifier of the entity.
payload: ValueThe event payload as a JSON value.
hash: StringSHA-256 hash of the canonicalized payload (hex-encoded).
signature: Option<String>Optional cryptographic signature (hex-encoded Ed25519).
timestamp: DateTime<Utc>Timestamp when the event was created.
Implementations§
Source§impl SyncEvent
impl SyncEvent
Sourcepub fn new(
event_type: impl Into<String>,
entity_type: impl Into<String>,
entity_id: impl Into<String>,
payload: Value,
) -> Self
pub fn new( event_type: impl Into<String>, entity_type: impl Into<String>, entity_id: impl Into<String>, payload: Value, ) -> Self
Create a new SyncEvent with an auto-generated id, hash, and timestamp.
Sourcepub fn with_id(
id: Uuid,
sequence: u64,
event_type: impl Into<String>,
entity_type: impl Into<String>,
entity_id: impl Into<String>,
payload: Value,
timestamp: DateTime<Utc>,
) -> Self
pub fn with_id( id: Uuid, sequence: u64, event_type: impl Into<String>, entity_type: impl Into<String>, entity_id: impl Into<String>, payload: Value, timestamp: DateTime<Utc>, ) -> Self
Create a SyncEvent with an explicit id and sequence.
Sourcepub fn compute_hash(payload: &Value) -> String
pub fn compute_hash(payload: &Value) -> String
Compute the SHA-256 hash of a JSON payload, hex-encoded.
Sourcepub const fn with_sequence(self, sequence: u64) -> Self
pub const fn with_sequence(self, sequence: u64) -> Self
Assign a sequence number to this event, returning a new event.
Sourcepub fn with_signature(self, signature: impl Into<String>) -> Self
pub fn with_signature(self, signature: impl Into<String>) -> Self
Set the signature on this event.