Skip to main content

outbox_core/
object.rs

1use uuid::Uuid;
2
3#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
4#[cfg_attr(feature = "sqlx", sqlx(transparent))]
5#[derive(Debug)]
6pub struct EventId(Uuid);
7impl Default for EventId {
8    fn default() -> Self {
9        Self(Uuid::new_v4())
10    }
11}
12impl EventId {
13    pub fn load(id: Uuid) -> Self {
14        Self(id)
15    }
16    pub fn as_uuid(&self) -> Uuid {
17        self.0
18    }
19}
20
21#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
22#[cfg_attr(feature = "sqlx", sqlx(transparent))]
23#[derive(Debug)]
24pub struct EventType(String);
25impl EventType {
26    pub fn new(event_type: &str) -> Self {
27        Self(event_type.to_string())
28    }
29    pub fn load(value: &String) -> Self {
30        Self(value.clone())
31    }
32    pub fn as_str(&self) -> &str {
33        &self.0
34    }
35}
36
37#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
38#[cfg_attr(feature = "sqlx", sqlx(transparent))]
39#[derive(Debug)]
40pub struct Payload(serde_json::Value);
41impl Payload {
42    pub fn new(payload: serde_json::Value) -> Self {
43        Self(payload)
44    }
45    pub fn load(value: &serde_json::Value) -> Self {
46        Self(value.clone())
47    }
48    pub fn as_json(&self) -> &serde_json::Value {
49        &self.0
50    }
51    pub fn from_static_str(s: &'static str) -> Self {
52        let val = serde_json::from_str(s).expect("Invalid JSON in static provider");
53        Self(val)
54    }
55}