|
| 1 | +//! This module contains supporting options for the client requests. |
| 2 | +
|
| 3 | +use serde::Serialize; |
| 4 | + |
| 5 | +/// Options for reading events from the database |
| 6 | +#[derive(Debug, Default, Clone, Serialize)] |
| 7 | +#[serde(rename_all = "camelCase")] |
| 8 | +pub struct ReadEventsRequestOptions<'a> { |
| 9 | + /// Start reading events from this start event |
| 10 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 11 | + pub from_latest_event: Option<FromLatestEventOptions<'a>>, |
| 12 | + /// Lower bound of events to read |
| 13 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 14 | + pub lower_bound: Option<Bound<'a>>, |
| 15 | + /// Ordering of the returned events |
| 16 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 17 | + pub order: Option<Ordering>, |
| 18 | + /// Include recursive subject's events |
| 19 | + pub recursive: bool, |
| 20 | + /// Upper bound of events to read |
| 21 | + #[serde(skip_serializing_if = "Option::is_none")] |
| 22 | + pub upper_bound: Option<Bound<'a>>, |
| 23 | +} |
| 24 | + |
| 25 | +/// Ordering of the responses of requests |
| 26 | +#[derive(Debug, Clone, Serialize)] |
| 27 | +#[serde(rename_all = "kebab-case")] |
| 28 | +pub enum Ordering { |
| 29 | + /// Order the responses in chronological order |
| 30 | + Chronological, |
| 31 | + /// Order the responses in reverse chronological order |
| 32 | + Antichronological, |
| 33 | +} |
| 34 | + |
| 35 | +/// The type of the request bound |
| 36 | +#[derive(Debug, Clone, Serialize)] |
| 37 | +#[serde(rename_all = "kebab-case")] |
| 38 | +pub enum BoundType { |
| 39 | + /// The bound is included in the response |
| 40 | + Inclusive, |
| 41 | + /// The bound is excluded from the response |
| 42 | + Exclusive, |
| 43 | +} |
| 44 | + |
| 45 | +/// A single bound for the request |
| 46 | +#[derive(Debug, Clone, Serialize)] |
| 47 | +#[serde(rename_all = "camelCase")] |
| 48 | +pub struct Bound<'a> { |
| 49 | + /// The type of the bound |
| 50 | + pub bound_type: BoundType, |
| 51 | + /// The value of the bound |
| 52 | + pub id: &'a str, |
| 53 | +} |
| 54 | + |
| 55 | +/// The strategy for handling missing events |
| 56 | +#[derive(Debug, Clone, Serialize)] |
| 57 | +#[serde(rename_all = "kebab-case")] |
| 58 | +pub enum EventMissingStrategy { |
| 59 | + /// Read all events if the required one is missing |
| 60 | + ReadEverything, |
| 61 | + /// Read no events if the required one is missing |
| 62 | + ReadNothing, |
| 63 | +} |
| 64 | + |
| 65 | +/// Options for reading events from the start reading at |
| 66 | +#[derive(Debug, Clone, Serialize)] |
| 67 | +#[serde(rename_all = "camelCase")] |
| 68 | +pub struct FromLatestEventOptions<'a> { |
| 69 | + /// The strategy for handling missing events |
| 70 | + pub if_event_is_missing: EventMissingStrategy, |
| 71 | + /// The subject the event should be on |
| 72 | + pub subject: &'a str, |
| 73 | + /// The type of the event to read from |
| 74 | + #[serde(rename = "type")] |
| 75 | + pub ty: &'a str, |
| 76 | +} |
0 commit comments