hyperstack_server/view/
spec.rs1use crate::websocket::frame::Mode;
2
3#[derive(Clone, Debug)]
26pub struct ViewSpec {
27 pub id: String,
28 pub export: String,
29 pub mode: Mode,
30 pub projection: Projection,
31 pub filters: Filters,
32 pub delivery: Delivery,
33}
34
35#[derive(Clone, Debug, Default)]
36pub struct Projection {
37 pub fields: Option<Vec<String>>,
38}
39
40impl Projection {
41 pub fn all() -> Self {
42 Self { fields: None }
43 }
44
45 pub fn apply(&self, mut data: serde_json::Value) -> serde_json::Value {
46 if let Some(ref field_list) = self.fields {
47 if let Some(obj) = data.as_object_mut() {
48 obj.retain(|k, _| field_list.contains(&k.to_string()));
49 }
50 }
51 data
52 }
53}
54
55#[derive(Clone, Debug, Default)]
56pub struct Filters {
57 pub keys: Option<Vec<String>>,
58}
59
60impl Filters {
61 pub fn all() -> Self {
62 Self { keys: None }
63 }
64
65 pub fn matches(&self, key: &str) -> bool {
66 match &self.keys {
67 None => true,
68 Some(keys) => keys.iter().any(|k| k == key),
69 }
70 }
71}
72
73#[derive(Clone, Debug, Default)]
74pub struct Delivery {
75 pub coalesce_ms: Option<u64>,
76}