Skip to content

Commit 3bc7367

Browse files
chore: release Python bindings 1.17.1 (#32)
Co-authored-by: Zixuan Chen <me@zxch3n.com>
1 parent 246b4b9 commit 3bc7367

6 files changed

Lines changed: 96 additions & 14 deletions

File tree

‎Cargo.lock‎

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "loro_py"
3-
version = "1.16.2"
3+
version = "1.17.1"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -9,7 +9,7 @@ name = "loro"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
loro = { version = "1.16.2", features = ["counter", "jsonpath"] }
12+
loro = { version = "1.17.1", features = ["counter", "jsonpath"] }
1313
rustc-hash = "2.1.1"
1414
pyo3 = { version = "0.26.0" }
1515
serde_json = "1"

‎README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,12 @@ cd loro-py
6868
pip install maturin
6969
maturin develop
7070
```
71+
72+
## 1.17.1
73+
74+
Uses Loro core 1.17.1. Adds `LoroDoc.export_pending_updates()` to persist received
75+
updates waiting for missing dependencies alongside a consistent snapshot. Restore
76+
the snapshot first, then import the pending bytes. `None` means nothing is pending;
77+
clear any previously saved pending bytes when replacing a checkpoint with `None`.
78+
JSON export keeps returning the existing JSON string and reports history decode
79+
failures as Python exceptions. The `state_vv` property retains its existing type.

‎loro.pyi‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,14 @@ class LoroDoc:
788788
"""
789789
...
790790

791+
def export_pending_updates(self) -> typing.Optional[bytes]:
792+
"""Export remote updates waiting for dependencies without committing local edits.
793+
794+
Save with a consistent snapshot. Restore the snapshot first, then import
795+
these bytes. None means no received updates are pending.
796+
"""
797+
...
798+
791799
def get_path_to_container(
792800
self, id: ContainerID
793801
) -> typing.Optional[list[tuple[ContainerID, Index]]]:

‎src/doc.rs‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,15 @@ impl LoroDoc {
515515
// TODO: return an object
516516
/// Export the current state with json-string format of the document.
517517
#[inline]
518-
pub fn export_json_updates(&self, start_vv: VersionVector, end_vv: VersionVector) -> String {
518+
pub fn export_json_updates(
519+
&self,
520+
start_vv: VersionVector,
521+
end_vv: VersionVector,
522+
) -> PyLoroResult<String> {
519523
let json = self
520524
.doc
521-
.export_json_updates(&start_vv.into(), &end_vv.into());
522-
serde_json::to_string(&json).unwrap()
525+
.export_json_updates(&start_vv.into(), &end_vv.into())?;
526+
serde_json::to_string(&json).map_err(|error| PyLoroError::Error(error.to_string()))
523527
}
524528

525529
/// Exports changes within the specified ID span to JSON schema format.
@@ -873,6 +877,15 @@ impl LoroDoc {
873877
Ok(Cow::Owned(ans))
874878
}
875879

880+
/// Export received remote updates that are waiting for missing dependencies.
881+
///
882+
/// Returns None when nothing is pending. Save these bytes together with a
883+
/// consistent snapshot, then restore the snapshot before importing these bytes.
884+
/// This does not commit local edits or consume pending updates.
885+
pub fn export_pending_updates(&self) -> PyLoroResult<Option<Cow<'_, [u8]>>> {
886+
Ok(self.doc.export_pending_updates()?.map(Cow::Owned))
887+
}
888+
876889
// /// Analyze the container info of the doc
877890
// ///
878891
// /// This is used for development and debugging. It can be slow.

‎tests/test_pending_updates.py‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import json
2+
3+
from loro import ExportMode, LoroDoc, VersionVector
4+
5+
6+
def test_pending_updates_survive_a_snapshot_checkpoint():
7+
source = LoroDoc()
8+
source.get_text("text").insert(0, "base")
9+
base = source.export(ExportMode.Snapshot())
10+
before_a = source.oplog_vv
11+
source.get_text("text").insert(4, "A")
12+
a = source.export(ExportMode.Updates(before_a))
13+
after_a = source.oplog_vv
14+
source.get_text("text").insert(5, "B")
15+
b = source.export(ExportMode.Updates(after_a))
16+
17+
receiver = LoroDoc()
18+
receiver.import_(base)
19+
receiver.import_(b)
20+
assert receiver.get_text("text").to_string() == "base"
21+
snapshot = receiver.export(ExportMode.Snapshot())
22+
pending = receiver.export_pending_updates()
23+
assert isinstance(pending, bytes)
24+
assert receiver.export_pending_updates() == pending
25+
26+
restored = LoroDoc()
27+
restored.import_(snapshot)
28+
restored.import_(pending)
29+
assert restored.get_text("text").to_string() == "base"
30+
restored.import_(a)
31+
assert restored.get_text("text").to_string() == "baseAB"
32+
assert restored.export_pending_updates() is None
33+
34+
35+
def test_pending_export_does_not_commit_local_edits():
36+
doc = LoroDoc()
37+
doc.get_text("text").insert(0, "local")
38+
pending_count = doc.get_pending_txn_len()
39+
assert pending_count > 0
40+
assert doc.export_pending_updates() is None
41+
assert doc.get_pending_txn_len() == pending_count
42+
43+
44+
def test_json_export_keeps_the_existing_schema():
45+
doc = LoroDoc()
46+
doc.get_text("text").insert(0, "hello")
47+
doc.commit()
48+
updates = doc.export_json_updates(VersionVector(), doc.oplog_vv)
49+
assert "schema_version" in json.loads(updates)
50+
restored = LoroDoc()
51+
restored.import_json_updates(updates)
52+
assert restored.get_text("text").to_string() == "hello"

0 commit comments

Comments
 (0)