doc.rs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. use crate::errors::DocResult;
  2. use flowy_derive::ProtoBuf;
  3. use flowy_ot::core::Delta;
  4. #[derive(ProtoBuf, Default, Debug, Clone)]
  5. pub struct CreateDocParams {
  6. #[pb(index = 1)]
  7. pub id: String,
  8. #[pb(index = 2)]
  9. pub data: String,
  10. }
  11. impl CreateDocParams {
  12. pub fn new(id: &str, data: String) -> Self {
  13. Self {
  14. id: id.to_owned(),
  15. data,
  16. }
  17. }
  18. }
  19. #[derive(ProtoBuf, Default, Debug, Clone, Eq, PartialEq)]
  20. pub struct Doc {
  21. #[pb(index = 1)]
  22. pub id: String,
  23. #[pb(index = 2)]
  24. pub data: String,
  25. #[pb(index = 3)]
  26. pub rev_id: i64,
  27. #[pb(index = 4)]
  28. pub base_rev_id: i64,
  29. }
  30. impl Doc {
  31. pub fn delta(&self) -> DocResult<Delta> {
  32. let delta = Delta::from_bytes(&self.data)?;
  33. Ok(delta)
  34. }
  35. }
  36. #[derive(ProtoBuf, Default, Debug, Clone)]
  37. pub struct UpdateDocParams {
  38. #[pb(index = 1)]
  39. pub doc_id: String,
  40. #[pb(index = 2)]
  41. pub data: String,
  42. #[pb(index = 3)]
  43. pub rev_id: i64,
  44. }
  45. #[derive(ProtoBuf, Default, Debug, Clone)]
  46. pub struct DocDelta {
  47. #[pb(index = 1)]
  48. pub doc_id: String,
  49. #[pb(index = 2)]
  50. pub data: String, // Delta
  51. }
  52. #[derive(ProtoBuf, Default, Debug, Clone)]
  53. pub struct NewDocUser {
  54. #[pb(index = 1)]
  55. pub user_id: String,
  56. #[pb(index = 2)]
  57. pub rev_id: i64,
  58. #[pb(index = 3)]
  59. pub doc_id: String,
  60. }
  61. #[derive(ProtoBuf, Default, Debug, Clone)]
  62. pub struct QueryDocParams {
  63. #[pb(index = 1)]
  64. pub doc_id: String,
  65. }
  66. impl std::convert::From<String> for QueryDocParams {
  67. fn from(doc_id: String) -> Self { QueryDocParams { doc_id } }
  68. }