Skip to main content

kuska_ssb/api/dto/
history_stream.rs

1#[derive(Debug, Serialize, Deserialize)]
2pub struct CreateHistoryStreamIn {
3    // id (FeedID, required): The id of the feed to fetch.
4    pub id: String,
5
6    /// (number, default: 0): If seq > 0, then only stream messages with sequence numbers greater than seq.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub seq: Option<u64>,
9
10    /// live (boolean, default: false): Keep the stream open and emit new messages as they are received
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub live: Option<bool>,
13    /// 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.
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub keys: Option<bool>,
16
17    /// 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.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub values: Option<bool>,
20
21    /// 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.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub limit: Option<i64>,
24}
25
26impl CreateHistoryStreamIn {
27    pub fn new(id: String) -> Self {
28        Self {
29            id,
30            seq: None,
31            live: None,
32            keys: None,
33            values: None,
34            limit: None,
35        }
36    }
37    pub fn after_seq(self, seq: u64) -> Self {
38        Self {
39            seq: Some(seq),
40            ..self
41        }
42    }
43    pub fn live(self, live: bool) -> Self {
44        Self {
45            live: Some(live),
46            ..self
47        }
48    }
49    pub fn keys_values(self, keys: bool, values: bool) -> Self {
50        Self {
51            keys: Some(keys),
52            values: Some(values),
53            ..self
54        }
55    }
56    pub fn limit(self, limit: i64) -> Self {
57        Self {
58            limit: Some(limit),
59            ..self
60        }
61    }
62}