feat(native): sync yocto codes (#14243)

#### PR Dependency Tree


* **PR #14243** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Batch management API for coordinated document mutations and change
tracking.
* New document accessors (IDs, state snapshots, change/delete set
queries) and subscriber count.

* **Chores**
  * Upgraded Rust edition across packages to 2024.
  * Repository-wide formatting, stylistic cleanups and test adjustments.

* **Breaking Changes**
* Removed the Node native bindings package and its JS/TS declarations
and tests (no longer published/available).

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2026-01-11 06:08:33 +08:00
committed by GitHub
parent d515d295ce
commit ca2462f987
143 changed files with 1396 additions and 4841 deletions
@@ -69,10 +69,7 @@ pub fn yrs_create_array_from_nest_type(
let str = text.get_string(&trx);
let len = str.chars().fold(0, |acc, _| acc + 1);
let index = random_pick_num(len, insert_pos) as usize;
let byte_start_offset = str
.chars()
.take(index)
.fold(0, |acc, ch| acc + ch.len_utf8());
let byte_start_offset = str.chars().take(index).fold(0, |acc, ch| acc + ch.len_utf8());
Some(text.insert_embed(&mut trx, byte_start_offset as u32, array_prelim))
}
@@ -80,10 +77,7 @@ pub fn yrs_create_array_from_nest_type(
let str = xml_text.get_string(&trx);
let len = str.chars().fold(0, |acc, _| acc + 1);
let index = random_pick_num(len, insert_pos) as usize;
let byte_start_offset = str
.chars()
.take(index)
.fold(0, |acc, ch| acc + ch.len_utf8());
let byte_start_offset = str.chars().take(index).fold(0, |acc, ch| acc + ch.len_utf8());
Some(xml_text.insert_embed(&mut trx, byte_start_offset as u32, array_prelim))
}
@@ -114,26 +108,14 @@ mod tests {
nest_data_op_type: NestDataOpType::Insert,
};
ops_registry.operate_yrs_nest_type(
&doc,
YrsNestType::ArrayType(array_ref.clone()),
params.clone(),
);
ops_registry.operate_yrs_nest_type(&doc, YrsNestType::ArrayType(array_ref.clone()), params.clone());
assert_eq!(array_ref.len(&doc.transact()), 1);
params.nest_data_op_type = NestDataOpType::Delete;
ops_registry.operate_yrs_nest_type(
&doc,
YrsNestType::ArrayType(array_ref.clone()),
params.clone(),
);
ops_registry.operate_yrs_nest_type(&doc, YrsNestType::ArrayType(array_ref.clone()), params.clone());
assert_eq!(array_ref.len(&doc.transact()), 0);
params.nest_data_op_type = NestDataOpType::Clear;
ops_registry.operate_yrs_nest_type(
&doc,
YrsNestType::ArrayType(array_ref.clone()),
params.clone(),
);
ops_registry.operate_yrs_nest_type(&doc, YrsNestType::ArrayType(array_ref.clone()), params.clone());
assert_eq!(array_ref.len(&doc.transact()), 0);
}
@@ -26,9 +26,7 @@ fn remove_op(doc: &yrs::Doc, nest_input: &YrsNestType, params: CRDTParam) {
random_pick_num((len - 1) as u32, &params.insert_pos)
};
iter
.nth(skip_step as usize)
.map(|(key, _value)| key.to_string())
iter.nth(skip_step as usize).map(|(key, _value)| key.to_string())
};
if let Some(key) = rand_key {
@@ -77,10 +75,7 @@ pub fn yrs_create_map_from_nest_type(
let str = text.get_string(&trx);
let len = str.chars().fold(0, |acc, _| acc + 1);
let index = random_pick_num(len, insert_pos) as usize;
let byte_start_offset = str
.chars()
.take(index)
.fold(0, |acc, ch| acc + ch.len_utf8());
let byte_start_offset = str.chars().take(index).fold(0, |acc, ch| acc + ch.len_utf8());
Some(text.insert_embed(&mut trx, byte_start_offset as u32, map_prelim))
}
@@ -88,10 +83,7 @@ pub fn yrs_create_map_from_nest_type(
let str = xml_text.get_string(&trx);
let len = str.chars().fold(0, |acc, _| acc + 1);
let index = random_pick_num(len, insert_pos) as usize;
let byte_start_offset = str
.chars()
.take(index)
.fold(0, |acc, ch| acc + ch.len_utf8());
let byte_start_offset = str.chars().take(index).fold(0, |acc, ch| acc + ch.len_utf8());
Some(xml_text.insert_embed(&mut trx, byte_start_offset as u32, map_prelim))
}
@@ -14,8 +14,8 @@ use xml_element::*;
use xml_fragment::*;
use xml_text::*;
use yrs::{
Array, ArrayPrelim, ArrayRef, Doc, GetString, Map, MapPrelim, MapRef, Text, TextPrelim, TextRef,
Transact, XmlFragment, XmlTextPrelim, XmlTextRef,
Array, ArrayPrelim, ArrayRef, Doc, GetString, Map, MapPrelim, MapRef, Text, TextPrelim, TextRef, Transact,
XmlFragment, XmlTextPrelim, XmlTextRef,
};
use super::*;
@@ -66,12 +66,7 @@ impl OpsRegistry<'_> {
}
}
pub fn operate_yrs_nest_type(
&self,
doc: &yrs::Doc,
cur_crdt_nest_type: YrsNestType,
crdt_param: CRDTParam,
) {
pub fn operate_yrs_nest_type(&self, doc: &yrs::Doc, cur_crdt_nest_type: YrsNestType, crdt_param: CRDTParam) {
let ops = self.get_ops_from_yrs_nest_type(&cur_crdt_nest_type);
ops
.get(match &crdt_param.nest_data_op_type {
@@ -83,11 +78,7 @@ impl OpsRegistry<'_> {
}
}
pub fn yrs_create_nest_type_from_root(
doc: &yrs::Doc,
target_type: CRDTNestType,
key: &str,
) -> YrsNestType {
pub fn yrs_create_nest_type_from_root(doc: &yrs::Doc, target_type: CRDTNestType, key: &str) -> YrsNestType {
match target_type {
CRDTNestType::Array => YrsNestType::ArrayType(doc.get_or_insert_array(key)),
CRDTNestType::Map => YrsNestType::MapType(doc.get_or_insert_map(key)),
@@ -141,17 +132,13 @@ pub fn gen_nest_type_from_nest_type(
nest_type: &mut YrsNestType,
) -> Option<YrsNestType> {
match crdt_param.new_nest_type {
CRDTNestType::Array => {
yrs_create_array_from_nest_type(doc, nest_type, &crdt_param.insert_pos, crdt_param.key)
.map(YrsNestType::ArrayType)
}
CRDTNestType::Array => yrs_create_array_from_nest_type(doc, nest_type, &crdt_param.insert_pos, crdt_param.key)
.map(YrsNestType::ArrayType),
CRDTNestType::Map => {
yrs_create_map_from_nest_type(doc, nest_type, &crdt_param.insert_pos, crdt_param.key)
.map(YrsNestType::MapType)
yrs_create_map_from_nest_type(doc, nest_type, &crdt_param.insert_pos, crdt_param.key).map(YrsNestType::MapType)
}
CRDTNestType::Text => {
yrs_create_text_from_nest_type(doc, nest_type, &crdt_param.insert_pos, crdt_param.key)
.map(YrsNestType::TextType)
yrs_create_text_from_nest_type(doc, nest_type, &crdt_param.insert_pos, crdt_param.key).map(YrsNestType::TextType)
}
_ => None,
}
@@ -12,10 +12,7 @@ fn insert_op(doc: &yrs::Doc, nest_input: &YrsNestType, params: CRDTParam) {
let str = text.get_string(&trx);
let len = str.chars().fold(0, |acc, _| acc + 1);
let index = random_pick_num(len, &params.insert_pos) as usize;
let byte_start_offset = str
.chars()
.take(index)
.fold(0, |acc, ch| acc + ch.len_utf8());
let byte_start_offset = str.chars().take(index).fold(0, |acc, ch| acc + ch.len_utf8());
text.insert(&mut trx, byte_start_offset as u32, &params.value);
}
@@ -33,10 +30,7 @@ fn remove_op(doc: &yrs::Doc, nest_input: &YrsNestType, params: CRDTParam) {
return;
}
let index = random_pick_num(len - 1, &params.insert_pos) as usize;
let byte_start_offset = str
.chars()
.take(index)
.fold(0, |acc, ch| acc + ch.len_utf8());
let byte_start_offset = str.chars().take(index).fold(0, |acc, ch| acc + ch.len_utf8());
let char_byte_len = str.chars().nth(index).unwrap().len_utf8();
text.remove_range(&mut trx, byte_start_offset as u32, char_byte_len as u32);
@@ -80,10 +74,7 @@ pub fn yrs_create_text_from_nest_type(
let str = text.get_string(&trx);
let len = str.chars().fold(0, |acc, _| acc + 1);
let index = random_pick_num(len, insert_pos) as usize;
let byte_start_offset = str
.chars()
.take(index)
.fold(0, |acc, ch| acc + ch.len_utf8());
let byte_start_offset = str.chars().take(index).fold(0, |acc, ch| acc + ch.len_utf8());
Some(text.insert_embed(&mut trx, byte_start_offset as u32, text_prelim))
}
@@ -91,10 +82,7 @@ pub fn yrs_create_text_from_nest_type(
let str = xml_text.get_string(&trx);
let len = str.chars().fold(0, |acc, _| acc + 1);
let index = random_pick_num(len, insert_pos) as usize;
let byte_start_offset = str
.chars()
.take(index)
.fold(0, |acc, ch| acc + ch.len_utf8());
let byte_start_offset = str.chars().take(index).fold(0, |acc, ch| acc + ch.len_utf8());
Some(xml_text.insert_embed(&mut trx, byte_start_offset as u32, text_prelim))
}
@@ -122,26 +110,14 @@ mod tests {
nest_data_op_type: NestDataOpType::Insert,
};
ops_registry.operate_yrs_nest_type(
&doc,
YrsNestType::TextType(text_ref.clone()),
params.clone(),
);
ops_registry.operate_yrs_nest_type(&doc, YrsNestType::TextType(text_ref.clone()), params.clone());
assert_eq!(text_ref.len(&doc.transact()), 10);
params.nest_data_op_type = NestDataOpType::Delete;
ops_registry.operate_yrs_nest_type(
&doc,
YrsNestType::TextType(text_ref.clone()),
params.clone(),
);
ops_registry.operate_yrs_nest_type(&doc, YrsNestType::TextType(text_ref.clone()), params.clone());
assert_eq!(text_ref.len(&doc.transact()), 9);
params.nest_data_op_type = NestDataOpType::Clear;
ops_registry.operate_yrs_nest_type(
&doc,
YrsNestType::TextType(text_ref.clone()),
params.clone(),
);
ops_registry.operate_yrs_nest_type(&doc, YrsNestType::TextType(text_ref.clone()), params.clone());
assert_eq!(text_ref.len(&doc.transact()), 0);
}
@@ -12,10 +12,7 @@ fn insert_op(doc: &yrs::Doc, nest_input: &YrsNestType, params: CRDTParam) {
let str = xml_text.get_string(&trx);
let len = str.chars().fold(0, |acc, _| acc + 1);
let index = random_pick_num(len, &params.insert_pos) as usize;
let byte_start_offset = str
.chars()
.take(index)
.fold(0, |acc, ch| acc + ch.len_utf8());
let byte_start_offset = str.chars().take(index).fold(0, |acc, ch| acc + ch.len_utf8());
xml_text.insert(&mut trx, byte_start_offset as u32, &params.value);
}
@@ -33,10 +30,7 @@ fn remove_op(doc: &yrs::Doc, nest_input: &YrsNestType, params: CRDTParam) {
return;
}
let index = random_pick_num(len - 1, &params.insert_pos) as usize;
let byte_start_offset = str
.chars()
.take(index)
.fold(0, |acc, ch| acc + ch.len_utf8());
let byte_start_offset = str.chars().take(index).fold(0, |acc, ch| acc + ch.len_utf8());
let char_byte_len = str.chars().nth(index).unwrap().len_utf8();
xml_text.remove_range(&mut trx, byte_start_offset as u32, char_byte_len as u32);