Bladeren bron

chore: remove update attributes

appflowy 2 jaren geleden
bovenliggende
commit
1fc2dceef9

+ 1 - 1
shared-lib/flowy-sync/src/client_grid/grid_revision_pad.rs

@@ -163,7 +163,7 @@ impl GridRevisionPad {
                 }
                 Some(field_rev) => {
                     let mut_field_rev = Arc::make_mut(field_rev);
-                    let old_field_type_rev = mut_field_rev.ty.clone();
+                    let old_field_type_rev = mut_field_rev.ty;
                     let old_field_type_option = mut_field_rev.get_type_option_str(mut_field_rev.ty);
                     match mut_field_rev.get_type_option_str(new_field_type) {
                         Some(new_field_type_option) => {

+ 1 - 1
shared-lib/flowy-sync/src/server_document/document_manager.rs

@@ -270,7 +270,7 @@ impl OpenDocumentHandler {
             .send(msg)
             .await
             .map_err(|e| CollaborateError::internal().context(format!("Send document command failed: {}", e)))?;
-        Ok(rx.await.map_err(internal_error)?)
+        rx.await.map_err(internal_error)
     }
 }
 

+ 1 - 1
shared-lib/flowy-sync/src/server_folder/folder_manager.rs

@@ -241,7 +241,7 @@ impl OpenFolderHandler {
             .send(msg)
             .await
             .map_err(|e| CollaborateError::internal().context(format!("Send folder command failed: {}", e)))?;
-        Ok(rx.await.map_err(internal_error)?)
+        rx.await.map_err(internal_error)
     }
 }
 

+ 6 - 10
shared-lib/lib-infra/src/code_gen/protobuf_file/mod.rs

@@ -182,9 +182,9 @@ pub fn check_pb_dart_plugin() {
                 ));
             }
 
-            msg.push_str(&"✅ You can fix that by adding:".to_string());
-            msg.push_str(&"\n\texport PATH=\"$PATH\":\"$HOME/.pub-cache/bin\"\n".to_string());
-            msg.push_str(&"to your shell's config file.(.bashrc, .bash, .profile, .zshrc etc.)".to_string());
+            msg.push_str("✅ You can fix that by adding:");
+            msg.push_str("\n\texport PATH=\"$PATH\":\"$HOME/.pub-cache/bin\"\n");
+            msg.push_str("to your shell's config file.(.bashrc, .bash, .profile, .zshrc etc.)");
             panic!("{}", msg)
         }
     }
@@ -198,13 +198,9 @@ fn gen_proto_files(crate_name: &str, crate_path: &str) -> Vec<ProtobufCrate> {
         .map(|info| info.protobuf_crate.clone())
         .collect::<Vec<_>>();
 
-    crate_context
-        .into_iter()
-        .map(|info| info.files)
-        .flatten()
-        .for_each(|file| {
-            println!("cargo:rerun-if-changed={}", file.file_path);
-        });
+    crate_context.into_iter().flat_map(|info| info.files).for_each(|file| {
+        println!("cargo:rerun-if-changed={}", file.file_path);
+    });
 
     proto_crates
 }

+ 1 - 1
shared-lib/lib-ot/src/core/delta/ops_serde.rs

@@ -1,6 +1,6 @@
 use crate::core::delta::operation::OperationAttributes;
 use crate::core::delta::DeltaOperations;
-use serde::de::DeserializeOwned;
+
 use serde::{
     de::{SeqAccess, Visitor},
     ser::SerializeSeq,

+ 38 - 24
shared-lib/lib-ot/src/core/node_tree/node.rs

@@ -1,6 +1,6 @@
 use super::node_serde::*;
 use crate::core::attributes::{AttributeHashMap, AttributeKey, AttributeValue};
-use crate::core::NodeBody::Delta;
+use crate::core::Body::Delta;
 use crate::core::OperationTransform;
 use crate::errors::OTError;
 use crate::text_delta::TextOperations;
@@ -17,9 +17,9 @@ pub struct NodeData {
 
     #[serde(serialize_with = "serialize_body")]
     #[serde(deserialize_with = "deserialize_body")]
-    #[serde(skip_serializing_if = "NodeBody::is_empty")]
+    #[serde(skip_serializing_if = "Body::is_empty")]
     #[serde(default)]
-    pub body: NodeBody,
+    pub body: Body,
 
     #[serde(skip_serializing_if = "Vec::is_empty")]
     #[serde(default)]
@@ -72,7 +72,7 @@ impl NodeDataBuilder {
     }
 
     /// Inserts a body to the builder's node
-    pub fn insert_body(mut self, body: NodeBody) -> Self {
+    pub fn insert_body(mut self, body: Body) -> Self {
         self.node.body = body;
         self
     }
@@ -92,24 +92,24 @@ impl NodeDataBuilder {
 /// compose, transform and invert.
 ///
 #[derive(Debug, Clone, PartialEq, Eq)]
-pub enum NodeBody {
+pub enum Body {
     Empty,
     Delta(TextOperations),
 }
 
-impl std::default::Default for NodeBody {
+impl std::default::Default for Body {
     fn default() -> Self {
-        NodeBody::Empty
+        Body::Empty
     }
 }
 
-impl NodeBody {
+impl Body {
     fn is_empty(&self) -> bool {
-        matches!(self, NodeBody::Empty)
+        matches!(self, Body::Empty)
     }
 }
 
-impl OperationTransform for NodeBody {
+impl OperationTransform for Body {
     /// Only the same enum variant can perform the compose operation.
     fn compose(&self, other: &Self) -> Result<Self, OTError>
     where
@@ -117,7 +117,7 @@ impl OperationTransform for NodeBody {
     {
         match (self, other) {
             (Delta(a), Delta(b)) => a.compose(b).map(Delta),
-            (NodeBody::Empty, NodeBody::Empty) => Ok(NodeBody::Empty),
+            (Body::Empty, Body::Empty) => Ok(Body::Empty),
             (l, r) => {
                 let msg = format!("{:?} can not compose {:?}", l, r);
                 Err(OTError::internal().context(msg))
@@ -132,7 +132,7 @@ impl OperationTransform for NodeBody {
     {
         match (self, other) {
             (Delta(l), Delta(r)) => l.transform(r).map(|(ta, tb)| (Delta(ta), Delta(tb))),
-            (NodeBody::Empty, NodeBody::Empty) => Ok((NodeBody::Empty, NodeBody::Empty)),
+            (Body::Empty, Body::Empty) => Ok((Body::Empty, Body::Empty)),
             (l, r) => {
                 let msg = format!("{:?} can not compose {:?}", l, r);
                 Err(OTError::internal().context(msg))
@@ -144,7 +144,7 @@ impl OperationTransform for NodeBody {
     fn invert(&self, other: &Self) -> Self {
         match (self, other) {
             (Delta(l), Delta(r)) => Delta(l.invert(r)),
-            (NodeBody::Empty, NodeBody::Empty) => NodeBody::Empty,
+            (Body::Empty, Body::Empty) => Body::Empty,
             (l, r) => {
                 tracing::error!("{:?} can not compose {:?}", l, r);
                 l.clone()
@@ -158,20 +158,28 @@ impl OperationTransform for NodeBody {
 /// Each NodeBody except the Empty should have its corresponding changeset variant.
 #[derive(Debug, Clone, Serialize, Deserialize)]
 #[serde(rename_all = "snake_case")]
-pub enum NodeBodyChangeset {
+pub enum Changeset {
     Delta {
         delta: TextOperations,
         inverted: TextOperations,
     },
+    Attributes {
+        new: AttributeHashMap,
+        old: AttributeHashMap,
+    },
 }
 
-impl NodeBodyChangeset {
-    pub fn inverted(&self) -> NodeBodyChangeset {
+impl Changeset {
+    pub fn inverted(&self) -> Changeset {
         match self {
-            NodeBodyChangeset::Delta { delta, inverted } => NodeBodyChangeset::Delta {
+            Changeset::Delta { delta, inverted } => Changeset::Delta {
                 delta: inverted.clone(),
                 inverted: delta.clone(),
             },
+            Changeset::Attributes { new, old } => Changeset::Attributes {
+                new: old.clone(),
+                old: new.clone(),
+            },
         }
     }
 }
@@ -181,7 +189,7 @@ impl NodeBodyChangeset {
 #[derive(Clone, Eq, PartialEq, Debug)]
 pub struct Node {
     pub node_type: String,
-    pub body: NodeBody,
+    pub body: Body,
     pub attributes: AttributeHashMap,
 }
 
@@ -190,16 +198,22 @@ impl Node {
         Node {
             node_type: node_type.into(),
             attributes: AttributeHashMap::new(),
-            body: NodeBody::Empty,
+            body: Body::Empty,
         }
     }
 
-    pub fn apply_body_changeset(&mut self, changeset: NodeBodyChangeset) {
+    pub fn apply_changeset(&mut self, changeset: Changeset) -> Result<(), OTError> {
         match changeset {
-            NodeBodyChangeset::Delta { delta, inverted: _ } => match self.body.compose(&Delta(delta)) {
-                Ok(new_body) => self.body = new_body,
-                Err(e) => tracing::error!("{:?}", e),
-            },
+            Changeset::Delta { delta, inverted: _ } => {
+                let new_body = self.body.compose(&Delta(delta))?;
+                self.body = new_body;
+                Ok(())
+            }
+            Changeset::Attributes { new, old: _ } => {
+                let new_attributes = AttributeHashMap::compose(&self.attributes, &new)?;
+                self.attributes = new_attributes;
+                Ok(())
+            }
         }
     }
 }

+ 8 - 8
shared-lib/lib-ot/src/core/node_tree/node_serde.rs

@@ -1,18 +1,18 @@
-use super::NodeBody;
+use super::Body;
 use crate::text_delta::TextOperations;
 use serde::de::{self, MapAccess, Visitor};
 use serde::ser::SerializeMap;
 use serde::{Deserializer, Serializer};
 use std::fmt;
 
-pub fn serialize_body<S>(body: &NodeBody, serializer: S) -> Result<S::Ok, S::Error>
+pub fn serialize_body<S>(body: &Body, serializer: S) -> Result<S::Ok, S::Error>
 where
     S: Serializer,
 {
     let mut map = serializer.serialize_map(Some(3))?;
     match body {
-        NodeBody::Empty => {}
-        NodeBody::Delta(delta) => {
+        Body::Empty => {}
+        Body::Delta(delta) => {
             map.serialize_key("delta")?;
             map.serialize_value(delta)?;
         }
@@ -20,14 +20,14 @@ where
     map.end()
 }
 
-pub fn deserialize_body<'de, D>(deserializer: D) -> Result<NodeBody, D::Error>
+pub fn deserialize_body<'de, D>(deserializer: D) -> Result<Body, D::Error>
 where
     D: Deserializer<'de>,
 {
     struct NodeBodyVisitor();
 
     impl<'de> Visitor<'de> for NodeBodyVisitor {
-        type Value = NodeBody;
+        type Value = Body;
 
         fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
             formatter.write_str("Expect NodeBody")
@@ -41,7 +41,7 @@ where
             while let Some(op) = seq.next_element()? {
                 delta.add(op);
             }
-            Ok(NodeBody::Delta(delta))
+            Ok(Body::Delta(delta))
         }
 
         #[inline]
@@ -65,7 +65,7 @@ where
             }
 
             if let Some(delta) = delta {
-                return Ok(NodeBody::Delta(delta));
+                return Ok(Body::Delta(delta));
             }
 
             Err(de::Error::missing_field("delta"))

+ 6 - 25
shared-lib/lib-ot/src/core/node_tree/operation.rs

@@ -1,5 +1,4 @@
-use crate::core::attributes::AttributeHashMap;
-use crate::core::{NodeBodyChangeset, NodeData, Path};
+use crate::core::{Changeset, NodeData, Path};
 use crate::errors::OTError;
 use serde::{Deserialize, Serialize};
 use std::rc::Rc;
@@ -10,17 +9,10 @@ pub enum NodeOperation {
     #[serde(rename = "insert")]
     Insert { path: Path, nodes: Vec<NodeData> },
 
-    #[serde(rename = "update-attribute")]
-    UpdateAttributes {
-        path: Path,
-        new: AttributeHashMap,
-        old: AttributeHashMap,
-    },
-
-    #[serde(rename = "update-body")]
+    #[serde(rename = "update")]
     // #[serde(serialize_with = "serialize_edit_body")]
     // #[serde(deserialize_with = "deserialize_edit_body")]
-    UpdateBody { path: Path, changeset: NodeBodyChangeset },
+    Update { path: Path, changeset: Changeset },
 
     #[serde(rename = "delete")]
     Delete { path: Path, nodes: Vec<NodeData> },
@@ -30,18 +22,16 @@ impl NodeOperation {
     pub fn get_path(&self) -> &Path {
         match self {
             NodeOperation::Insert { path, .. } => path,
-            NodeOperation::UpdateAttributes { path, .. } => path,
             NodeOperation::Delete { path, .. } => path,
-            NodeOperation::UpdateBody { path, .. } => path,
+            NodeOperation::Update { path, .. } => path,
         }
     }
 
     pub fn get_mut_path(&mut self) -> &mut Path {
         match self {
             NodeOperation::Insert { path, .. } => path,
-            NodeOperation::UpdateAttributes { path, .. } => path,
             NodeOperation::Delete { path, .. } => path,
-            NodeOperation::UpdateBody { path, .. } => path,
+            NodeOperation::Update { path, .. } => path,
         }
     }
 
@@ -51,20 +41,11 @@ impl NodeOperation {
                 path: path.clone(),
                 nodes: nodes.clone(),
             },
-            NodeOperation::UpdateAttributes {
-                path,
-                new: attributes,
-                old: old_attributes,
-            } => NodeOperation::UpdateAttributes {
-                path: path.clone(),
-                new: old_attributes.clone(),
-                old: attributes.clone(),
-            },
             NodeOperation::Delete { path, nodes } => NodeOperation::Insert {
                 path: path.clone(),
                 nodes: nodes.clone(),
             },
-            NodeOperation::UpdateBody { path, changeset: body } => NodeOperation::UpdateBody {
+            NodeOperation::Update { path, changeset: body } => NodeOperation::Update {
                 path: path.clone(),
                 changeset: body.inverted(),
             },

+ 22 - 15
shared-lib/lib-ot/src/core/node_tree/operation_serde.rs

@@ -1,4 +1,4 @@
-use crate::core::{NodeBodyChangeset, Path};
+use crate::core::{Changeset, Path};
 use crate::text_delta::TextOperations;
 use serde::de::{self, MapAccess, Visitor};
 use serde::ser::SerializeMap;
@@ -8,7 +8,7 @@ use std::fmt;
 use std::marker::PhantomData;
 
 #[allow(dead_code)]
-pub fn serialize_edit_body<S>(path: &Path, changeset: &NodeBodyChangeset, serializer: S) -> Result<S::Ok, S::Error>
+pub fn serialize_edit_body<S>(path: &Path, changeset: &Changeset, serializer: S) -> Result<S::Ok, S::Error>
 where
     S: Serializer,
 {
@@ -17,28 +17,35 @@ where
     map.serialize_value(path)?;
 
     match changeset {
-        NodeBodyChangeset::Delta { delta, inverted } => {
+        Changeset::Delta { delta, inverted } => {
             map.serialize_key("delta")?;
             map.serialize_value(delta)?;
             map.serialize_key("inverted")?;
             map.serialize_value(inverted)?;
             map.end()
         }
+        Changeset::Attributes { new, old } => {
+            map.serialize_key("new")?;
+            map.serialize_value(new)?;
+            map.serialize_key("old")?;
+            map.serialize_value(old)?;
+            map.end()
+        }
     }
 }
 
 #[allow(dead_code)]
-pub fn deserialize_edit_body<'de, D>(deserializer: D) -> Result<(Path, NodeBodyChangeset), D::Error>
+pub fn deserialize_edit_body<'de, D>(deserializer: D) -> Result<(Path, Changeset), D::Error>
 where
     D: Deserializer<'de>,
 {
-    struct NodeBodyChangesetVisitor();
+    struct ChangesetVisitor();
 
-    impl<'de> Visitor<'de> for NodeBodyChangesetVisitor {
-        type Value = (Path, NodeBodyChangeset);
+    impl<'de> Visitor<'de> for ChangesetVisitor {
+        type Value = (Path, Changeset);
 
         fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
-            formatter.write_str("Expect Path and NodeBodyChangeset")
+            formatter.write_str("Expect Path and Changeset")
         }
 
         #[inline]
@@ -47,7 +54,7 @@ where
             V: MapAccess<'de>,
         {
             let mut path: Option<Path> = None;
-            let mut delta_changeset = DeltaBodyChangeset::<V::Error>::new();
+            let mut delta_changeset = DeltaChangeset::<V::Error>::new();
             while let Some(key) = map.next_key()? {
                 match key {
                     "delta" => {
@@ -83,17 +90,17 @@ where
             Ok((path.unwrap(), changeset))
         }
     }
-    deserializer.deserialize_any(NodeBodyChangesetVisitor())
+    deserializer.deserialize_any(ChangesetVisitor())
 }
 
 #[allow(dead_code)]
-struct DeltaBodyChangeset<E> {
+struct DeltaChangeset<E> {
     delta: Option<TextOperations>,
     inverted: Option<TextOperations>,
     error: PhantomData<E>,
 }
 
-impl<E> DeltaBodyChangeset<E> {
+impl<E> DeltaChangeset<E> {
     fn new() -> Self {
         Self {
             delta: None,
@@ -103,13 +110,13 @@ impl<E> DeltaBodyChangeset<E> {
     }
 }
 
-impl<E> std::convert::TryInto<NodeBodyChangeset> for DeltaBodyChangeset<E>
+impl<E> std::convert::TryInto<Changeset> for DeltaChangeset<E>
 where
     E: de::Error,
 {
     type Error = E;
 
-    fn try_into(self) -> Result<NodeBodyChangeset, Self::Error> {
+    fn try_into(self) -> Result<Changeset, Self::Error> {
         if self.delta.is_none() {
             return Err(de::Error::missing_field("delta"));
         }
@@ -117,7 +124,7 @@ where
         if self.inverted.is_none() {
             return Err(de::Error::missing_field("inverted"));
         }
-        let changeset = NodeBodyChangeset::Delta {
+        let changeset = Changeset::Delta {
             delta: self.delta.unwrap(),
             inverted: self.inverted.unwrap(),
         };

+ 8 - 6
shared-lib/lib-ot/src/core/node_tree/transaction.rs

@@ -4,7 +4,7 @@ use crate::errors::OTError;
 use indextree::NodeId;
 use std::rc::Rc;
 
-use super::{NodeBodyChangeset, NodeOperations};
+use super::{Changeset, NodeOperations};
 
 #[derive(Debug, Clone, Default)]
 pub struct Transaction {
@@ -143,10 +143,12 @@ impl<'a> TransactionBuilder<'a> {
                     }
                 }
 
-                self.operations.add_op(NodeOperation::UpdateAttributes {
+                self.operations.add_op(NodeOperation::Update {
                     path: path.clone(),
-                    new: attributes,
-                    old: old_attributes,
+                    changeset: Changeset::Attributes {
+                        new: attributes,
+                        old: old_attributes,
+                    },
                 });
             }
             None => tracing::warn!("Update attributes at path: {:?} failed. Node is not exist", path),
@@ -154,10 +156,10 @@ impl<'a> TransactionBuilder<'a> {
         self
     }
 
-    pub fn update_body_at_path(mut self, path: &Path, changeset: NodeBodyChangeset) -> Self {
+    pub fn update_body_at_path(mut self, path: &Path, changeset: Changeset) -> Self {
         match self.node_tree.node_id_at_path(path) {
             Some(_) => {
-                self.operations.add_op(NodeOperation::UpdateBody {
+                self.operations.add_op(NodeOperation::Update {
                     path: path.clone(),
                     changeset,
                 });

+ 4 - 14
shared-lib/lib-ot/src/core/node_tree/tree.rs

@@ -1,5 +1,4 @@
-use crate::core::attributes::AttributeHashMap;
-use crate::core::{Node, NodeBodyChangeset, NodeData, NodeOperation, OperationTransform, Path, Transaction};
+use crate::core::{Changeset, Node, NodeData, NodeOperation, Path, Transaction};
 use crate::errors::{ErrorBuilder, OTError, OTErrorCode};
 use indextree::{Arena, Children, FollowingSiblings, NodeId};
 use std::rc::Rc;
@@ -181,8 +180,7 @@ impl NodeTree {
 
         match op {
             NodeOperation::Insert { path, nodes } => self.insert_nodes(&path, nodes),
-            NodeOperation::UpdateAttributes { path, new, .. } => self.update_attributes(&path, new),
-            NodeOperation::UpdateBody { path, changeset } => self.update_body(&path, changeset),
+            NodeOperation::Update { path, changeset } => self.update(&path, changeset),
             NodeOperation::Delete { path, nodes } => self.delete_node(&path, nodes),
         }
     }
@@ -252,14 +250,6 @@ impl NodeTree {
         }
     }
 
-    fn update_attributes(&mut self, path: &Path, attributes: AttributeHashMap) -> Result<(), OTError> {
-        self.mut_node_at_path(path, |node| {
-            let new_attributes = AttributeHashMap::compose(&node.attributes, &attributes)?;
-            node.attributes = new_attributes;
-            Ok(())
-        })
-    }
-
     fn delete_node(&mut self, path: &Path, nodes: Vec<NodeData>) -> Result<(), OTError> {
         let mut update_node = self
             .node_id_at_path(path)
@@ -277,9 +267,9 @@ impl NodeTree {
         Ok(())
     }
 
-    fn update_body(&mut self, path: &Path, changeset: NodeBodyChangeset) -> Result<(), OTError> {
+    fn update(&mut self, path: &Path, changeset: Changeset) -> Result<(), OTError> {
         self.mut_node_at_path(path, |node| {
-            node.apply_body_changeset(changeset);
+            let _ = node.apply_changeset(changeset)?;
             Ok(())
         })
     }

+ 11 - 9
shared-lib/lib-ot/tests/node/operation_test.rs

@@ -2,7 +2,7 @@ use crate::node::script::NodeScript::*;
 use crate::node::script::NodeTest;
 use lib_ot::core::{AttributeBuilder, Node};
 use lib_ot::{
-    core::{NodeBodyChangeset, NodeData, NodeDataBuilder, NodeOperation, Path},
+    core::{Changeset, NodeData, NodeDataBuilder, NodeOperation, Path},
     text_delta::TextOperationBuilder,
 };
 
@@ -33,16 +33,18 @@ fn operation_insert_node_with_children_serde_test() {
 }
 #[test]
 fn operation_update_node_attributes_serde_test() {
-    let operation = NodeOperation::UpdateAttributes {
+    let operation = NodeOperation::Update {
         path: Path(vec![0, 1]),
-        new: AttributeBuilder::new().insert("bold", true).build(),
-        old: AttributeBuilder::new().insert("bold", false).build(),
+        changeset: Changeset::Attributes {
+            new: AttributeBuilder::new().insert("bold", true).build(),
+            old: AttributeBuilder::new().insert("bold", false).build(),
+        },
     };
 
     let result = serde_json::to_string(&operation).unwrap();
     assert_eq!(
         result,
-        r#"{"op":"update-attribute","path":[0,1],"new":{"bold":true},"old":{"bold":null}}"#
+        r#"{"op":"update","path":[0,1],"changeset":{"attributes":{"new":{"bold":true},"old":{"bold":null}}}}"#
     );
 }
 
@@ -50,22 +52,22 @@ fn operation_update_node_attributes_serde_test() {
 fn operation_update_node_body_serialize_test() {
     let delta = TextOperationBuilder::new().insert("AppFlowy...").build();
     let inverted = delta.invert_str("");
-    let changeset = NodeBodyChangeset::Delta { delta, inverted };
-    let insert = NodeOperation::UpdateBody {
+    let changeset = Changeset::Delta { delta, inverted };
+    let insert = NodeOperation::Update {
         path: Path(vec![0, 1]),
         changeset,
     };
     let result = serde_json::to_string(&insert).unwrap();
     assert_eq!(
         result,
-        r#"{"op":"update-body","path":[0,1],"changeset":{"delta":{"delta":[{"insert":"AppFlowy..."}],"inverted":[{"delete":11}]}}}"#
+        r#"{"op":"update","path":[0,1],"changeset":{"delta":{"delta":[{"insert":"AppFlowy..."}],"inverted":[{"delete":11}]}}}"#
     );
     //
 }
 
 #[test]
 fn operation_update_node_body_deserialize_test() {
-    let json_1 = r#"{"op":"update-body","path":[0,1],"changeset":{"delta":{"delta":[{"insert":"AppFlowy..."}],"inverted":[{"delete":11}]}}}"#;
+    let json_1 = r#"{"op":"update","path":[0,1],"changeset":{"delta":{"delta":[{"insert":"AppFlowy..."}],"inverted":[{"delete":11}]}}}"#;
     let operation: NodeOperation = serde_json::from_str(json_1).unwrap();
     let json_2 = serde_json::to_string(&operation).unwrap();
     assert_eq!(json_1, json_2);

+ 3 - 3
shared-lib/lib-ot/tests/node/script.rs

@@ -1,7 +1,7 @@
 use lib_ot::core::{Node, Transaction};
 use lib_ot::{
     core::attributes::AttributeHashMap,
-    core::{NodeBody, NodeBodyChangeset, NodeData, NodeTree, Path, TransactionBuilder},
+    core::{Body, Changeset, NodeData, NodeTree, Path, TransactionBuilder},
     text_delta::TextOperations,
 };
 use std::collections::HashMap;
@@ -18,7 +18,7 @@ pub enum NodeScript {
     },
     UpdateBody {
         path: Path,
-        changeset: NodeBodyChangeset,
+        changeset: Changeset,
     },
     DeleteNode {
         path: Path,
@@ -132,7 +132,7 @@ impl NodeTest {
             },
             NodeScript::AssertNodeDelta { path, expected } => {
                 let node = self.node_tree.get_node_at_path(&path).unwrap();
-                if let NodeBody::Delta(delta) = node.body.clone() {
+                if let Body::Delta(delta) = node.body.clone() {
                     debug_assert_eq!(delta, expected);
                 } else {
                     panic!("Node body type not match, expect Delta");

+ 4 - 4
shared-lib/lib-ot/tests/node/tree_test.rs

@@ -1,7 +1,7 @@
 use crate::node::script::NodeScript::*;
 use crate::node::script::NodeTest;
-use lib_ot::core::NodeBody;
-use lib_ot::core::NodeBodyChangeset;
+use lib_ot::core::Body;
+use lib_ot::core::Changeset;
 use lib_ot::core::OperationTransform;
 use lib_ot::core::{NodeData, NodeDataBuilder, Path};
 use lib_ot::text_delta::TextOperationBuilder;
@@ -299,7 +299,7 @@ fn node_update_body_test() {
     let expected = init_delta.compose(&delta).unwrap();
 
     let node = NodeDataBuilder::new("text")
-        .insert_body(NodeBody::Delta(init_delta))
+        .insert_body(Body::Delta(init_delta))
         .build();
 
     let scripts = vec![
@@ -310,7 +310,7 @@ fn node_update_body_test() {
         },
         UpdateBody {
             path: path.clone(),
-            changeset: NodeBodyChangeset::Delta { delta, inverted },
+            changeset: Changeset::Delta { delta, inverted },
         },
         AssertNodeDelta { path, expected },
     ];