diff --git a/crates/dwn-rs-core/src/interfaces/mod.rs b/crates/dwn-rs-core/src/interfaces/mod.rs index 8f05488..77e0836 100644 --- a/crates/dwn-rs-core/src/interfaces/mod.rs +++ b/crates/dwn-rs-core/src/interfaces/mod.rs @@ -1,3 +1,5 @@ pub mod messages; +pub mod replies; pub use messages::*; +pub use replies::{Reply, Response}; diff --git a/crates/dwn-rs-core/src/interfaces/replies/messages.rs b/crates/dwn-rs-core/src/interfaces/replies/messages.rs new file mode 100644 index 0000000..ef71981 --- /dev/null +++ b/crates/dwn-rs-core/src/interfaces/replies/messages.rs @@ -0,0 +1,26 @@ +use cid::Cid; +use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; + +use crate::{Cursor, Descriptor, Message}; + +#[skip_serializing_none] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct ReadEntry { + #[serde(rename = "messageCid")] + pub cid: Cid, + pub message: Option>, +} + +#[skip_serializing_none] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Read { + pub entry: Option, +} + +#[skip_serializing_none] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Query { + pub entries: Option>, + pub cursor: Option, +} diff --git a/crates/dwn-rs-core/src/interfaces/replies/mod.rs b/crates/dwn-rs-core/src/interfaces/replies/mod.rs new file mode 100644 index 0000000..32babe7 --- /dev/null +++ b/crates/dwn-rs-core/src/interfaces/replies/mod.rs @@ -0,0 +1,42 @@ +pub mod messages; +pub mod protocols; +pub mod records; + +use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; + +use crate::SubscriptionID; + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Status { + pub code: i32, + pub detail: String, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Response { + pub status: Status, + #[serde(flatten)] + pub reply: Reply, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Empty {} + +#[skip_serializing_none] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Subscribe { + pub subscription: Option, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +#[serde(untagged)] +pub enum Reply { + Empty(Empty), + RecordsRead(records::Read), + RecordsQuery(records::Query), + MessageRead(messages::Read), + MessageQuery(messages::Query), + ProtocolsQuery(protocols::Query), + Subscribe(Subscribe), +} diff --git a/crates/dwn-rs-core/src/interfaces/replies/protocols.rs b/crates/dwn-rs-core/src/interfaces/replies/protocols.rs new file mode 100644 index 0000000..bde7879 --- /dev/null +++ b/crates/dwn-rs-core/src/interfaces/replies/protocols.rs @@ -0,0 +1,10 @@ +use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; + +use crate::{descriptors::protocols, Message}; + +#[skip_serializing_none] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Query { + pub entries: Option>, +} diff --git a/crates/dwn-rs-core/src/interfaces/replies/records.rs b/crates/dwn-rs-core/src/interfaces/replies/records.rs new file mode 100644 index 0000000..e0e359d --- /dev/null +++ b/crates/dwn-rs-core/src/interfaces/replies/records.rs @@ -0,0 +1,42 @@ +use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; + +use crate::{ + descriptors::{records::WriteDescriptor, DeleteDescriptor}, + Cursor, Message, +}; + +#[skip_serializing_none] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct ReadEntry { + #[serde(rename = "recordsWrite")] + pub records_write: Option>, + #[serde(rename = "recordsDelete")] + pub records_delete: Option>, + #[serde(rename = "initialWrite")] + pub initial_write: Option>, +} + +#[skip_serializing_none] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Read { + pub entry: Option, +} + +#[skip_serializing_none] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct QueryEntry { + #[serde(rename = "initialWrite")] + pub initial_write: Option>, + #[serde(rename = "encodedData")] + pub encoded_data: Option, + #[serde(flatten)] + pub message: Message, +} + +#[skip_serializing_none] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Query { + pub entries: Option>, + pub cursor: Option, +}