diff --git a/crates/loro-internal/examples/encoding.rs b/crates/loro-internal/examples/encoding.rs index 532ce4e1..4ce1ee62 100644 --- a/crates/loro-internal/examples/encoding.rs +++ b/crates/loro-internal/examples/encoding.rs @@ -1,7 +1,7 @@ use std::time::Instant; use bench_utils::TextAction; -use loro_internal::LoroDoc; +use loro_internal::{loro::ExportMode, LoroDoc}; fn main() { let actions = bench_utils::get_automerge_actions(); @@ -54,6 +54,23 @@ fn main() { output.len(), ); + let start = Instant::now(); + let shallow_snapshot = loro + .export(ExportMode::shallow_snapshot(&loro.oplog_frontiers())) + .unwrap(); + println!("Shallow Snapshot time {}ms", start.elapsed().as_millis()); + let output = miniz_oxide::deflate::compress_to_vec(&shallow_snapshot, 6); + println!( + "Shallow Snapshot+compression time {}ms", + start.elapsed().as_millis() + ); + + println!( + "Shallow snapshot size {} after compression {}", + shallow_snapshot.len(), + output.len(), + ); + let updates = loro.export_from(&Default::default()); let output = miniz_oxide::deflate::compress_to_vec(&updates, 6); println!( diff --git a/crates/loro-internal/src/value.rs b/crates/loro-internal/src/value.rs index cb44bffb..c25f7de1 100644 --- a/crates/loro-internal/src/value.rs +++ b/crates/loro-internal/src/value.rs @@ -566,7 +566,7 @@ pub mod wasm { js_sys::Reflect::set(&obj, &"index".into(), &(*index).into()).unwrap(); js_sys::Reflect::set( &obj, - &"fractional_index".into(), + &"fractionalIndex".into(), &position.to_string().into(), ) .unwrap(); @@ -578,11 +578,11 @@ pub mod wasm { js_sys::Reflect::set(&obj, &"action".into(), &"delete".into()).unwrap(); js_sys::Reflect::set( &obj, - &"old_parent".into(), + &"oldParent".into(), &JsValue::from(old_parent.tree_id()), ) .unwrap(); - js_sys::Reflect::set(&obj, &"old_index".into(), &(*old_index).into()) + js_sys::Reflect::set(&obj, &"oldIndex".into(), &(*old_index).into()) .unwrap(); } TreeExternalDiff::Move { @@ -602,17 +602,17 @@ pub mod wasm { js_sys::Reflect::set(&obj, &"index".into(), &(*index).into()).unwrap(); js_sys::Reflect::set( &obj, - &"fractional_index".into(), + &"fractionalIndex".into(), &position.to_string().into(), ) .unwrap(); js_sys::Reflect::set( &obj, - &"old_parent".into(), + &"oldParent".into(), &JsValue::from(old_parent.tree_id()), ) .unwrap(); - js_sys::Reflect::set(&obj, &"old_index".into(), &(*old_index).into()) + js_sys::Reflect::set(&obj, &"oldIndex".into(), &(*old_index).into()) .unwrap(); } } diff --git a/crates/loro-wasm/src/lib.rs b/crates/loro-wasm/src/lib.rs index 61c1e018..f2dfc01f 100644 --- a/crates/loro-wasm/src/lib.rs +++ b/crates/loro-wasm/src/lib.rs @@ -3525,7 +3525,7 @@ impl LoroTree { js_sys::Reflect::set(&obj, &"index".into(), &JsValue::from(index))?; js_sys::Reflect::set( &obj, - &"fractional_index".into(), + &"fractionalIndex".into(), &JsValue::from_str(&position), )?; js_sys::Reflect::set(&obj, &"meta".into(), &map.into())?; diff --git a/loro-js/src/index.ts b/loro-js/src/index.ts index 58d27983..7804284c 100644 --- a/loro-js/src/index.ts +++ b/loro-js/src/index.ts @@ -95,17 +95,17 @@ export type TreeDiffItem = action: "create"; parent: TreeID | undefined; index: number; - fractional_index: string; + fractionalIndex: string; } - | { target: TreeID; action: "delete"; old_parent: TreeID | undefined; old_index: number } + | { target: TreeID; action: "delete"; oldParent: TreeID | undefined; oldIndex: number } | { target: TreeID; action: "move"; parent: TreeID | undefined; index: number; - fractional_index: string; - old_parent: TreeID | undefined; - old_index: number; + fractionalIndex: string; + oldParent: TreeID | undefined; + oldIndex: number; }; export type TreeDiff = { diff --git a/loro-js/tests/misc.test.ts b/loro-js/tests/misc.test.ts index c4b0f398..31c92669 100644 --- a/loro-js/tests/misc.test.ts +++ b/loro-js/tests/misc.test.ts @@ -246,6 +246,7 @@ describe("type", () => { describe("list stable position", () => { it("basic tests", () => { const loro = new LoroDoc(); + loro.oplogFrontiers const list = loro.getList("list"); list.insert(0, "a"); const pos0 = list.getCursor(0); diff --git a/loro-js/tests/tree.test.ts b/loro-js/tests/tree.test.ts index 45ae3cd6..4e3a2651 100644 --- a/loro-js/tests/tree.test.ts +++ b/loro-js/tests/tree.test.ts @@ -93,7 +93,7 @@ describe("loro tree", () => { assert(keys.includes("id")); assert(keys.includes("parent")); assert(keys.includes("index")); - assert(keys.includes("fractional_index")); + assert(keys.includes("fractionalIndex")); assert(keys.includes("meta")); assert(keys.includes("children")); }); @@ -212,8 +212,8 @@ describe("loro tree node", () => { if (e.events[0].diff.type == "tree") { const diff = e.events[0].diff as TreeDiff; if (diff.diff[0].action == "move") { - assertEquals(diff.diff[0].old_parent, root.id); - assertEquals(diff.diff[0].old_index, 1); + assertEquals(diff.diff[0].oldParent, root.id); + assertEquals(diff.diff[0].oldIndex, 1); } } });