Skip to main content

kuska_ssb/api/dto/
stream.rs

1// https://github.com/ssbc/ssb-db/blob/master/api.md
2#[derive(Debug, Serialize)]
3pub struct CreateStreamIn<K> {
4    /// live (boolean, default: false): Keep the stream open and emit new messages as they are received
5    #[serde(skip_serializing_if = "Option::is_none")]
6    pub live: Option<bool>,
7
8    /// gt (greater than), gte (greater than or equal) define the lower bound of the range to be streamed
9    #[serde(skip_serializing_if = "Option::is_none")]
10    pub gt: Option<K>,
11
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub gte: Option<K>,
14
15    /// lt (less than), lte (less than or equal) define the higher bound of the range to be streamed. Only key/value pairs where the key is less than (or equal to) this option will be included in the range. When reverse=true the order will be reversed, but the records streamed will be the same.
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub lt: Option<K>,
18
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub lte: Option<K>,
21
22    /// reverse (boolean, default: false): a boolean, set true and the stream output will be reversed. Beware that due to the way LevelDB works, a reverse seek will be slower than a forward seek.
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub reverse: Option<bool>,
25
26    /// keys (boolean, default: true): whether the data event should contain keys. If set to true and values set to false then data events will simply be keys, rather than objects with a key property.
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub keys: Option<bool>,
29
30    /// values (boolean, default: true): whether the data event should contain values. If set to true and keys set to false then data events will simply be values, rather than objects with a value property.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub values: Option<bool>,
33
34    /// limit (number, default: -1): limit the number of results collected by this stream. This number represents a maximum number of results and may not be reached if you get to the end of the data first. A value of -1 means there is no limit. When reverse=true the highest keys will be returned instead of the lowest keys.
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub limit: Option<i64>,
37
38    /// fillCache (boolean, default: false): wheather LevelDB's LRU-cache should be filled with data read.
39    #[serde(rename = "fillCache")]
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub fill_cache: Option<bool>,
42    /// keyEncoding / valueEncoding (string): the encoding applied to each read piece of data.
43    #[serde(rename = "keyEncoding")]
44    pub key_encoding: Option<String>,
45
46    #[serde(rename = "valueEncoding")]
47    pub value_encoding: Option<String>,
48}
49
50impl<K> Default for CreateStreamIn<K> {
51    fn default() -> Self {
52        Self {
53            live: None,
54            gt: None,
55            gte: None,
56            lt: None,
57            lte: None,
58            reverse: None,
59            keys: None,
60            values: None,
61            limit: None,
62            fill_cache: None,
63            key_encoding: None,
64            value_encoding: None,
65        }
66    }
67}
68
69impl<K> CreateStreamIn<K> {
70    pub fn live(self, live: bool) -> Self {
71        Self {
72            live: Some(live),
73            ..self
74        }
75    }
76    pub fn gt(self, v: K) -> Self {
77        Self {
78            gt: Some(v),
79            ..self
80        }
81    }
82    pub fn gte(self, v: K) -> Self {
83        Self {
84            gte: Some(v),
85            ..self
86        }
87    }
88    pub fn lt(self, v: K) -> Self {
89        Self {
90            lt: Some(v),
91            ..self
92        }
93    }
94    pub fn lte(self, v: K) -> Self {
95        Self {
96            lte: Some(v),
97            ..self
98        }
99    }
100    pub fn reverse(self, reversed: bool) -> Self {
101        Self {
102            reverse: Some(reversed),
103            ..self
104        }
105    }
106    pub fn keys_values(self, keys: bool, values: bool) -> Self {
107        Self {
108            keys: Some(keys),
109            values: Some(values),
110            ..self
111        }
112    }
113    pub fn encoding(self, keys: String, values: String) -> Self {
114        Self {
115            key_encoding: Some(keys),
116            value_encoding: Some(values),
117            ..self
118        }
119    }
120    pub fn limit(self, limit: i64) -> Self {
121        Self {
122            limit: Some(limit),
123            ..self
124        }
125    }
126}