use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::schemas::StreamData;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct MessageMetadata {
pub graph_node: String,
pub tags: Vec<String>,
#[serde(flatten)]
pub extra: HashMap<String, Value>,
}
impl MessageMetadata {
pub fn new(node: impl Into<String>) -> Self {
Self {
graph_node: node.into(),
tags: Vec::new(),
extra: HashMap::new(),
}
}
pub fn with_tags(node: impl Into<String>, tags: Vec<String>) -> Self {
Self {
graph_node: node.into(),
tags,
extra: HashMap::new(),
}
}
pub fn with_extra(mut self, key: String, value: Value) -> Self {
self.extra.insert(key, value);
self
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct DebugInfo {
pub event_type: String,
pub node: Option<String>,
#[serde(flatten)]
pub info: HashMap<String, Value>,
}
impl DebugInfo {
pub fn new(event_type: impl Into<String>) -> Self {
Self {
event_type: event_type.into(),
node: None,
info: HashMap::new(),
}
}
pub fn with_node(event_type: impl Into<String>, node: impl Into<String>) -> Self {
Self {
event_type: event_type.into(),
node: Some(node.into()),
info: HashMap::new(),
}
}
pub fn with_info(mut self, key: String, value: Value) -> Self {
self.info.insert(key, value);
self
}
}
#[derive(Clone, Debug)]
pub struct MessageChunk {
pub chunk: StreamData,
pub metadata: MessageMetadata,
}
impl MessageChunk {
pub fn new(chunk: StreamData, metadata: MessageMetadata) -> Self {
Self { chunk, metadata }
}
}