Skip to main content

sofie_db/
event.rs

1use serde::Serialize;
2
3use crate::Input;
4
5pub trait Event: Input + Serialize + Send + 'static {
6    /// `<crate>.<Type>`: what it is stored and delivered as.
7    const NAME: &'static str;
8}
9
10/// No field named in Rust can take it, and `Meta::raise` refuses an app event that does.
11pub(crate) const PRUNED: &str = "sofie.pruned";
12
13#[cfg(any(feature = "contracts", feature = "publishing", feature = "retention"))]
14pub(crate) fn change_payload(
15    mut fields: serde_json::Map<String, serde_json::Value>,
16    id: sofie_core::Uuid,
17    version: i64,
18) -> serde_json::Map<String, serde_json::Value> {
19    fields.insert("id".to_owned(), serde_json::Value::String(id.to_string()));
20    fields.insert("version".to_owned(), serde_json::Value::from(version));
21    fields
22}
23
24pub(crate) fn is_pruned(payload: &serde_json::Value) -> bool {
25    payload.get(PRUNED) == Some(&serde_json::Value::Bool(true))
26}