jetstream_oxide/events/
commit.rs

1use atrium_api::record::KnownRecord;
2use serde::Deserialize;
3
4use crate::{
5    events::EventInfo,
6    exports,
7};
8
9/// An event representing a repo commit, which can be a `create`, `update`, or `delete` operation.
10#[derive(Deserialize, Debug)]
11#[serde(untagged, rename_all = "snake_case")]
12pub enum CommitEvent {
13    Create {
14        #[serde(flatten)]
15        info: EventInfo,
16        commit: CommitData,
17    },
18    Update {
19        #[serde(flatten)]
20        info: EventInfo,
21        commit: CommitData,
22    },
23    Delete {
24        #[serde(flatten)]
25        info: EventInfo,
26        commit: CommitInfo,
27    },
28}
29
30/// The type of commit operation that was performed.
31#[derive(Deserialize, Debug)]
32#[serde(rename_all = "snake_case")]
33pub enum CommitType {
34    Create,
35    Update,
36    Delete,
37}
38
39/// Basic commit specific info bundled with every event, also the only data included with a `delete`
40/// operation.
41#[derive(Deserialize, Debug)]
42pub struct CommitInfo {
43    /// The type of commit operation that was performed.
44    pub operation: CommitType,
45    pub rev: String,
46    pub rkey: String,
47    /// The NSID of the record type that this commit is associated with.
48    pub collection: exports::Nsid,
49}
50
51/// Detailed data bundled with a commit event. This data is only included when the event is
52/// `create` or `update`.
53#[derive(Deserialize, Debug)]
54pub struct CommitData {
55    #[serde(flatten)]
56    pub info: CommitInfo,
57    /// The CID of the record that was operated on.
58    pub cid: exports::Cid,
59    /// The record that was operated on.
60    pub record: KnownRecord,
61}