87 lines
1.6 KiB
Rust
Raw Normal View History

2021-10-06 15:23:38 +08:00
use crate::errors::DocResult;
2021-07-22 21:43:01 +08:00
use flowy_derive::ProtoBuf;
2021-10-06 15:23:38 +08:00
use flowy_ot::core::Delta;
2021-07-22 21:43:01 +08:00
2021-09-11 14:26:30 +08:00
#[derive(ProtoBuf, Default, Debug, Clone)]
pub struct CreateDocParams {
2021-07-22 21:43:01 +08:00
#[pb(index = 1)]
pub id: String,
2021-07-22 21:43:01 +08:00
#[pb(index = 2)]
2021-09-26 16:39:57 +08:00
pub data: String,
2021-07-22 21:43:01 +08:00
}
2021-09-11 14:26:30 +08:00
impl CreateDocParams {
2021-09-26 16:39:57 +08:00
pub fn new(id: &str, data: String) -> Self {
Self {
id: id.to_owned(),
data,
}
}
2021-09-11 14:26:30 +08:00
}
#[derive(ProtoBuf, Default, Debug, Clone, Eq, PartialEq)]
pub struct Doc {
#[pb(index = 1)]
2021-07-23 08:14:45 +08:00
pub id: String,
#[pb(index = 2)]
2021-09-26 16:39:57 +08:00
pub data: String,
#[pb(index = 3)]
pub rev_id: i64,
2021-10-06 15:23:38 +08:00
#[pb(index = 4)]
pub base_rev_id: i64,
}
impl Doc {
pub fn delta(&self) -> DocResult<Delta> {
let delta = Delta::from_bytes(&self.data)?;
Ok(delta)
}
2021-07-22 21:43:01 +08:00
}
2021-09-11 14:26:30 +08:00
#[derive(ProtoBuf, Default, Debug, Clone)]
pub struct UpdateDocParams {
2021-09-11 14:26:30 +08:00
#[pb(index = 1)]
2021-09-23 13:15:35 +08:00
pub doc_id: String,
2021-07-22 21:43:01 +08:00
2021-09-14 16:22:44 +08:00
#[pb(index = 2)]
2021-09-26 16:39:57 +08:00
pub data: String,
#[pb(index = 3)]
pub rev_id: i64,
2021-09-14 16:22:44 +08:00
}
#[derive(ProtoBuf, Default, Debug, Clone)]
2021-09-23 13:15:35 +08:00
pub struct DocDelta {
2021-09-14 16:22:44 +08:00
#[pb(index = 1)]
2021-09-23 13:15:35 +08:00
pub doc_id: String,
2021-09-14 16:22:44 +08:00
#[pb(index = 2)]
2021-09-26 16:39:57 +08:00
pub data: String, // Delta
2021-07-22 21:43:01 +08:00
}
2021-07-22 22:26:38 +08:00
#[derive(ProtoBuf, Default, Debug, Clone)]
pub struct NewDocUser {
#[pb(index = 1)]
pub user_id: String,
#[pb(index = 2)]
pub rev_id: i64,
#[pb(index = 3)]
pub doc_id: String,
}
#[derive(ProtoBuf, Default, Debug, Clone)]
pub struct DocIdentifier {
2021-07-22 22:26:38 +08:00
#[pb(index = 1)]
2021-09-11 14:26:30 +08:00
pub doc_id: String,
2021-07-22 22:26:38 +08:00
}
2021-10-15 13:42:52 +08:00
impl std::convert::From<String> for DocIdentifier {
fn from(doc_id: String) -> Self { DocIdentifier { doc_id } }
2021-10-15 13:42:52 +08:00
}