Skip to content

Commit

Permalink
chore: upgrade yrs and y-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
eliias committed Jan 26, 2024
1 parent ba25556 commit 41c8cbb
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 49 deletions.
73 changes: 53 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions ext/yrb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ homepage = "https://github.com/y-crdt/yrb"
repository = "https://github.com/y-crdt/yrb"

[dependencies]
lib0 = "0.16.10" # must match yrs version
magnus = "0.6.2"
thiserror = "1.0.56"
yrs = "=0.16.10"
y-sync = "=0.3.1"
yrs = "=0.17.4"
y-sync = "=0.4.0"
rb-sys = "0.9.87"

[dev-dependencies]
Expand Down
3 changes: 1 addition & 2 deletions ext/yrb/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::yvalue::YValue;
use lib0::any::Any;
use magnus::r_hash::ForEach::Continue;
use magnus::{exception, Error, RArray, RHash, RString, Symbol, Value};
use std::sync::Arc;
use yrs::types::{Attrs, Value as YrsValue};
use yrs::{Array, Map, TransactionMut};
use yrs::{Any, Array, Map, TransactionMut};

#[derive(Debug, Clone)]
pub(crate) struct TypeConversionError;
Expand Down
2 changes: 1 addition & 1 deletion ext/yrb/src/yany.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use lib0::any::Any;
use magnus::r_string::IntoRString;
use magnus::value::ReprValue;
use magnus::{value, IntoValue, RArray, RHash, RString, Value};
use std::borrow::Borrow;
use std::ops::{Deref, DerefMut};
use yrs::Any;

pub(crate) struct YAny(pub(crate) Any);

Expand Down
3 changes: 1 addition & 2 deletions ext/yrb/src/yarray.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::utils::convert_yvalue_to_ruby_value;
use crate::ytransaction::YTransaction;
use crate::yvalue::YValue;
use lib0::any::Any;
use magnus::block::Proc;
use magnus::value::Qnil;
use magnus::{Error, IntoValue, RArray, RHash, Symbol, Value};
use std::cell::RefCell;
use yrs::types::Change;
use yrs::{Array, ArrayRef, Observable};
use yrs::{Any, Array, ArrayRef, Observable};

#[magnus::wrap(class = "Y::Array")]
pub(crate) struct YArray(pub(crate) RefCell<ArrayRef>);
Expand Down
2 changes: 1 addition & 1 deletion ext/yrb/src/yattrs.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::yvalue::YValue;
use lib0::any::Any;
use magnus::r_hash::ForEach::Continue;
use magnus::{RHash, Value};
use std::ops::{Deref, DerefMut};
use std::sync::Arc;
use yrs::types::Attrs;
use yrs::Any;

pub(crate) struct YAttrs(pub(crate) Attrs);

Expand Down
4 changes: 2 additions & 2 deletions ext/yrb/src/yawareness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ unsafe impl Send for YAwareness {}
impl YAwareness {
pub(crate) fn yawareness_new() -> Self {
let mut options = Options {
offset_kind: OffsetKind::Utf32,
offset_kind: OffsetKind::Utf16,
..Default::default()
};
options.offset_kind = OffsetKind::Utf32;
options.offset_kind = OffsetKind::Utf16;

let doc = Doc::with_options(options);

Expand Down
2 changes: 1 addition & 1 deletion ext/yrb/src/ydoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl YDoc {
let value = client_id.first().unwrap();
options.client_id = Integer::from_value(*value).unwrap().to_u64().unwrap();
}
options.offset_kind = OffsetKind::Utf32;
options.offset_kind = OffsetKind::Utf16;

let doc = Doc::with_options(options);
Self(RefCell::new(doc))
Expand Down
3 changes: 1 addition & 2 deletions ext/yrb/src/ymap.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::utils::{convert_yvalue_to_ruby_value, indifferent_hash_key};
use crate::yvalue::YValue;
use crate::YTransaction;
use lib0::any::Any;
use magnus::block::Proc;
use magnus::{exception, Error, RArray, RHash, Symbol, Value};
use std::cell::RefCell;
use yrs::types::{EntryChange, Value as YrsValue};
use yrs::{Map, MapRef, Observable};
use yrs::{Any, Map, MapRef, Observable};

#[magnus::wrap(class = "Y::Map")]
pub(crate) struct YMap(pub(crate) RefCell<MapRef>);
Expand Down
3 changes: 1 addition & 2 deletions ext/yrb/src/ytext.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::yattrs::YAttrs;
use crate::yvalue::YValue;
use crate::YTransaction;
use lib0::any::Any;
use magnus::block::Proc;
use magnus::value::Qnil;
use magnus::{Error, RHash, Symbol, Value};
use std::cell::RefCell;
use yrs::types::Delta;
use yrs::{GetString, Observable, Text, TextRef};
use yrs::{Any, GetString, Observable, Text, TextRef};

#[magnus::wrap(class = "Y::Text")]
pub(crate) struct YText(pub(crate) RefCell<TextRef>);
Expand Down
26 changes: 15 additions & 11 deletions ext/yrb/src/yvalue.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::{YText, YXmlElement, YXmlText};
use lib0::any::Any;
use magnus::r_hash::ForEach::Continue;
use magnus::value::{Qnil, ReprValue};
use magnus::{class, value, Float, Integer, IntoValue, RArray, RHash, RString, Symbol, Value};
use std::cell::RefCell;
use std::collections::HashMap;
use std::sync::Arc;
use yrs::types::Value as YrsValue;
use yrs::{
Array, Map, TextRef as YrsText, Transact, XmlElementRef as YrsXmlElement,
Any, Array, Map, TextRef as YrsText, Transact, XmlElementRef as YrsXmlElement,
XmlTextRef as YrsXmlText,
};

Expand Down Expand Up @@ -67,6 +67,12 @@ impl From<RHash> for YValue {
}
}

impl From<Vec<u8>> for YValue {
fn from(value: Vec<u8>) -> Self {
YValue(RefCell::from(value.into_value()))
}
}

impl From<YrsText> for YValue {
fn from(value: YrsText) -> Self {
YValue(RefCell::from(YText(RefCell::from(value)).into_value()))
Expand Down Expand Up @@ -113,8 +119,8 @@ impl From<Any> for YValue {
Any::Bool(v) => YValue::from(v),
Any::Number(v) => YValue::from(v),
Any::BigInt(v) => YValue::from(v),
Any::String(v) => YValue::from(v.into_string()),
Any::Buffer(v) => YValue::from(v.into_vec().into_value()),
Any::String(v) => YValue::from(v.to_string()),
Any::Buffer(v) => YValue::from(v.to_vec()),
Any::Array(v) => {
let arr = RArray::new();
for item in v.iter() {
Expand Down Expand Up @@ -146,7 +152,6 @@ impl From<YrsValue> for YValue {
YrsValue::YXmlElement(el) => YValue::from(el),
YrsValue::YXmlText(text) => YValue::from(text),
YrsValue::YArray(val) => {
print!("try to acquire transaction");
let tx = val.transact();
let arr = RArray::new();
for item in val.iter(&tx) {
Expand All @@ -157,7 +162,6 @@ impl From<YrsValue> for YValue {
YValue::from(arr)
}
YrsValue::YMap(val) => {
print!("try to acquire transaction");
let tx = val.transact();
let iter = val.iter(&tx).map(|(key, val)| {
let val = YValue::from(val);
Expand All @@ -184,14 +188,14 @@ impl From<YValue> for Any {
Any::BigInt(i.to_i64().unwrap())
} else if value.is_kind_of(class::symbol()) {
let s = Symbol::from_value(value).unwrap();
Any::String(Box::from(s.name().unwrap()))
Any::String(Arc::from(s.name().unwrap()))
} else if value.is_kind_of(class::true_class()) {
Any::Bool(true)
} else if value.is_kind_of(class::false_class()) {
Any::Bool(false)
} else if value.is_kind_of(class::string()) {
let s = RString::from_value(value).unwrap();
unsafe { Any::String(Box::from(s.as_str().unwrap().to_string())) }
unsafe { Any::String(Arc::from(s.as_str().unwrap().to_string())) }
} else if value.is_kind_of(class::array()) {
let arr = RArray::from_value(value).unwrap();
let items = arr
Expand All @@ -201,7 +205,7 @@ impl From<YValue> for Any {
Any::from(yvalue)
})
.collect::<Vec<Any>>();
Any::Array(Box::from(items))
Any::Array(Arc::from(items))
} else if value.is_kind_of(class::hash()) {
let map = RHash::from_value(value).unwrap();
let mut m: HashMap<String, Any> = HashMap::new();
Expand All @@ -221,7 +225,7 @@ impl From<YValue> for Any {
})
.expect("cannot map key/value pair");

Any::Map(Box::from(m))
Any::Map(Arc::from(m))
} else {
Any::Undefined
}
Expand All @@ -238,8 +242,8 @@ impl Into<Value> for YValue {
#[cfg(test)]
mod tests {
use crate::yvalue::YValue;
use lib0::any::Any;
use magnus::value::ReprValue;
use yrs::Any;

#[test]
fn convert_any_to_yvalue() {
Expand Down
3 changes: 1 addition & 2 deletions ext/yrb/src/yxml_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use crate::utils::map_rhash_to_attrs;
use crate::yvalue::YValue;
use crate::yxml_fragment::YXmlFragment;
use crate::{YTransaction, YXmlElement};
use lib0::any::Any;
use magnus::{Error, IntoValue, RHash, Value};
use std::cell::RefCell;
use yrs::{GetString, Text, Xml, XmlNode, XmlTextRef};
use yrs::{Any, GetString, Text, Xml, XmlNode, XmlTextRef};

#[magnus::wrap(class = "Y::XMLText")]
pub(crate) struct YXmlText(pub(crate) RefCell<XmlTextRef>);
Expand Down

0 comments on commit 41c8cbb

Please sign in to comment.