entities.rs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. use std::collections::HashMap;
  2. use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
  3. #[derive(Default, ProtoBuf)]
  4. pub struct OpenDocumentPayloadPB {
  5. #[pb(index = 1)]
  6. pub document_id: String,
  7. }
  8. #[derive(Default, ProtoBuf)]
  9. pub struct CreateDocumentPayloadPB {
  10. #[pb(index = 1)]
  11. pub document_id: String,
  12. #[pb(index = 2, one_of)]
  13. pub initial_data: Option<DocumentDataPB>,
  14. }
  15. #[derive(Default, ProtoBuf)]
  16. pub struct CloseDocumentPayloadPB {
  17. #[pb(index = 1)]
  18. pub document_id: String,
  19. }
  20. #[derive(Default, ProtoBuf, Debug)]
  21. pub struct ApplyActionPayloadPB {
  22. #[pb(index = 1)]
  23. pub document_id: String,
  24. #[pb(index = 2)]
  25. pub actions: Vec<BlockActionPB>,
  26. }
  27. #[derive(Default, ProtoBuf)]
  28. pub struct GetDocumentDataPayloadPB {
  29. #[pb(index = 1)]
  30. pub document_id: String,
  31. // Support customize initial data
  32. }
  33. #[derive(Default, ProtoBuf)]
  34. pub struct DocumentDataPB {
  35. #[pb(index = 1)]
  36. pub page_id: String,
  37. #[pb(index = 2)]
  38. pub blocks: HashMap<String, BlockPB>,
  39. #[pb(index = 3)]
  40. pub meta: MetaPB,
  41. }
  42. #[derive(Default, ProtoBuf, Debug)]
  43. pub struct BlockPB {
  44. #[pb(index = 1)]
  45. pub id: String,
  46. #[pb(index = 2)]
  47. pub ty: String,
  48. #[pb(index = 3)]
  49. pub data: String,
  50. #[pb(index = 4)]
  51. pub parent_id: String,
  52. #[pb(index = 5)]
  53. pub children_id: String,
  54. }
  55. #[derive(Default, ProtoBuf)]
  56. pub struct MetaPB {
  57. #[pb(index = 1)]
  58. pub children_map: HashMap<String, ChildrenPB>,
  59. }
  60. #[derive(Default, ProtoBuf)]
  61. pub struct ChildrenPB {
  62. #[pb(index = 1)]
  63. pub children: Vec<String>,
  64. }
  65. // Actions
  66. #[derive(Default, ProtoBuf, Debug)]
  67. pub struct BlockActionPB {
  68. #[pb(index = 1)]
  69. pub action: BlockActionTypePB,
  70. #[pb(index = 2)]
  71. pub payload: BlockActionPayloadPB,
  72. }
  73. #[derive(Default, ProtoBuf, Debug)]
  74. pub struct BlockActionPayloadPB {
  75. #[pb(index = 1)]
  76. pub block: BlockPB,
  77. #[pb(index = 2, one_of)]
  78. pub prev_id: Option<String>,
  79. #[pb(index = 3, one_of)]
  80. pub parent_id: Option<String>,
  81. }
  82. #[derive(ProtoBuf_Enum, Debug)]
  83. pub enum BlockActionTypePB {
  84. Insert = 0,
  85. Update = 1,
  86. Delete = 2,
  87. Move = 3,
  88. }
  89. impl Default for BlockActionTypePB {
  90. fn default() -> Self {
  91. Self::Insert
  92. }
  93. }
  94. #[derive(ProtoBuf_Enum)]
  95. pub enum DeltaTypePB {
  96. Inserted = 0,
  97. Updated = 1,
  98. Removed = 2,
  99. }
  100. impl Default for DeltaTypePB {
  101. fn default() -> Self {
  102. Self::Inserted
  103. }
  104. }
  105. #[derive(Default, ProtoBuf)]
  106. pub struct DocEventPB {
  107. #[pb(index = 1)]
  108. pub events: Vec<BlockEventPB>,
  109. #[pb(index = 2)]
  110. pub is_remote: bool,
  111. }
  112. #[derive(Default, ProtoBuf)]
  113. pub struct BlockEventPB {
  114. #[pb(index = 1)]
  115. pub event: Vec<BlockEventPayloadPB>,
  116. }
  117. #[derive(Default, ProtoBuf)]
  118. pub struct BlockEventPayloadPB {
  119. #[pb(index = 1)]
  120. pub command: DeltaTypePB,
  121. #[pb(index = 2)]
  122. pub path: Vec<String>,
  123. #[pb(index = 3)]
  124. pub id: String,
  125. #[pb(index = 4)]
  126. pub value: String,
  127. }
  128. #[derive(PartialEq, Eq, Debug, ProtoBuf_Enum, Clone)]
  129. pub enum ExportType {
  130. Text = 0,
  131. Markdown = 1,
  132. Link = 2,
  133. }
  134. impl Default for ExportType {
  135. fn default() -> Self {
  136. ExportType::Text
  137. }
  138. }
  139. impl From<i32> for ExportType {
  140. fn from(val: i32) -> Self {
  141. match val {
  142. 0 => ExportType::Text,
  143. 1 => ExportType::Markdown,
  144. 2 => ExportType::Link,
  145. _ => {
  146. tracing::error!("Invalid export type: {}", val);
  147. ExportType::Text
  148. },
  149. }
  150. }
  151. }
  152. #[derive(Default, ProtoBuf)]
  153. pub struct EditPayloadPB {
  154. #[pb(index = 1)]
  155. pub doc_id: String,
  156. // Encode in JSON format
  157. #[pb(index = 2)]
  158. pub operations: String,
  159. }
  160. #[derive(Default, ProtoBuf)]
  161. pub struct ExportDataPB {
  162. #[pb(index = 1)]
  163. pub data: String,
  164. #[pb(index = 2)]
  165. pub export_type: ExportType,
  166. }