jetstream_oxide/events/
commit.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use atrium_api::record::KnownRecord;
use serde::Deserialize;

use crate::{
    events::EventInfo,
    exports,
};

/// An event representing a repo commit, which can be a `create`, `update`, or `delete` operation.
#[derive(Deserialize, Debug)]
#[serde(untagged, rename_all = "snake_case")]
pub enum CommitEvent {
    Create {
        #[serde(flatten)]
        info: EventInfo,
        commit: CommitData,
    },
    Update {
        #[serde(flatten)]
        info: EventInfo,
        commit: CommitData,
    },
    Delete {
        #[serde(flatten)]
        info: EventInfo,
        commit: CommitInfo,
    },
}

/// The type of commit operation that was performed.
#[derive(Deserialize, Debug)]
#[serde(rename_all = "snake_case")]
pub enum CommitType {
    Create,
    Update,
    Delete,
}

/// Basic commit specific info bundled with every event, also the only data included with a `delete`
/// operation.
#[derive(Deserialize, Debug)]
pub struct CommitInfo {
    /// The type of commit operation that was performed.
    pub operation: CommitType,
    pub rev: String,
    pub rkey: String,
    /// The NSID of the record type that this commit is associated with.
    pub collection: exports::Nsid,
}

/// Detailed data bundled with a commit event. This data is only included when the event is
/// `create` or `update`.
#[derive(Deserialize, Debug)]
pub struct CommitData {
    #[serde(flatten)]
    pub info: CommitInfo,
    /// The CID of the record that was operated on.
    pub cid: exports::Cid,
    /// The record that was operated on.
    pub record: KnownRecord,
}