y-rb 0.5.1-x86_64-darwin → 0.5.3-x86_64-darwin
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/yrb/Cargo.toml +9 -9
- data/ext/yrb/src/lib.rs +25 -11
- data/ext/yrb/src/utils.rs +32 -4
- data/ext/yrb/src/yany.rs +11 -10
- data/ext/yrb/src/yarray.rs +8 -6
- data/ext/yrb/src/yattrs.rs +2 -2
- data/ext/yrb/src/yawareness.rs +4 -4
- data/ext/yrb/src/ydoc.rs +16 -0
- data/ext/yrb/src/ymap.rs +5 -4
- data/ext/yrb/src/ytransaction.rs +19 -0
- data/ext/yrb/src/yvalue.rs +25 -22
- data/ext/yrb/src/yxml_element.rs +16 -16
- data/ext/yrb/src/yxml_fragment.rs +13 -13
- data/ext/yrb/src/yxml_text.rs +10 -10
- data/lib/3.0/yrb.bundle +0 -0
- data/lib/3.1/yrb.bundle +0 -0
- data/lib/3.2/yrb.bundle +0 -0
- data/lib/y/doc.rb +40 -0
- data/lib/y/transaction.rb +30 -2
- data/lib/y/version.rb +1 -1
- metadata +4 -5
- data/lib/2.7/yrb.bundle +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91ac411669334b234f375bd050bded350b6fda596d65cb7fa152cb91b23fcbd5
|
4
|
+
data.tar.gz: 3dfbc0a85871c26fcc7fe049bc465b686499af3287c26a8f632ffc1cbdba987c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09f93c246cb186a0703af5e44c87796854c17b68dd6731f8e914a6add09c148f0affb6e6f9dd146d0913ebf2982a3bf718683b026ec8462940674723b72d9788'
|
7
|
+
data.tar.gz: e89a596a2decffcf7858dfba3b38ff2ba78fadcaf2a5b2b7d163fb6715734004c36f12e998261a713fc9524302edde673c276a85956d290493f8410a5f960aab
|
data/ext/yrb/Cargo.toml
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
[package]
|
2
2
|
name = "yrb"
|
3
|
-
version = "0.5.
|
4
|
-
authors = ["Hannes Moser <box@hannesmoser.at>"
|
3
|
+
version = "0.5.3"
|
4
|
+
authors = ["Hannes Moser <box@hannesmoser.at>"]
|
5
5
|
edition = "2021"
|
6
6
|
homepage = "https://github.com/y-crdt/yrb"
|
7
7
|
repository = "https://github.com/y-crdt/yrb"
|
8
8
|
|
9
9
|
[dependencies]
|
10
|
-
lib0 = "0.16.
|
11
|
-
magnus = "0.
|
12
|
-
thiserror = "1.0.
|
13
|
-
yrs = "0.16.
|
14
|
-
y-sync = "0.3.
|
15
|
-
rb-sys = "0.9.
|
10
|
+
lib0 = "0.16.10" # must match yrs version
|
11
|
+
magnus = "0.6.2"
|
12
|
+
thiserror = "1.0.50"
|
13
|
+
yrs = "=0.16.10"
|
14
|
+
y-sync = "=0.3.1"
|
15
|
+
rb-sys = "0.9.82"
|
16
16
|
|
17
17
|
[dev-dependencies]
|
18
|
-
magnus = { version = "0.
|
18
|
+
magnus = { version = "0.6.2", features = ["embed"] }
|
19
19
|
|
20
20
|
[lib]
|
21
21
|
name = "yrb"
|
data/ext/yrb/src/lib.rs
CHANGED
@@ -9,7 +9,7 @@ use crate::ytransaction::YTransaction;
|
|
9
9
|
use crate::yxml_element::YXmlElement;
|
10
10
|
use crate::yxml_fragment::YXmlFragment;
|
11
11
|
use crate::yxml_text::YXmlText;
|
12
|
-
use magnus::{define_module, function, method, Error, Module, Object};
|
12
|
+
use magnus::{class, define_module, function, method, Error, Module, Object};
|
13
13
|
|
14
14
|
mod utils;
|
15
15
|
mod yany;
|
@@ -30,7 +30,7 @@ fn init() -> Result<(), Error> {
|
|
30
30
|
let module = define_module("Y").expect("cannot define ::Y module");
|
31
31
|
|
32
32
|
let yarray = module
|
33
|
-
.define_class("Array",
|
33
|
+
.define_class("Array", class::object())
|
34
34
|
.expect("cannot find class Y::Array");
|
35
35
|
|
36
36
|
yarray
|
@@ -77,12 +77,14 @@ fn init() -> Result<(), Error> {
|
|
77
77
|
.expect("cannot define private method: yarray_unobserve");
|
78
78
|
|
79
79
|
let ydoc = module
|
80
|
-
.define_class("Doc",
|
80
|
+
.define_class("Doc", class::object())
|
81
81
|
.expect("cannot define class Y::Doc");
|
82
82
|
ydoc.define_singleton_method("new", function!(YDoc::ydoc_new, -1))
|
83
83
|
.expect("cannot define singleton method: ydoc_new");
|
84
84
|
ydoc.define_private_method("ydoc_encode_diff_v1", method!(YDoc::ydoc_encode_diff_v1, 2))
|
85
85
|
.expect("cannot define private method: ydoc_encode_diff_v1");
|
86
|
+
ydoc.define_private_method("ydoc_encode_diff_v2", method!(YDoc::ydoc_encode_diff_v2, 2))
|
87
|
+
.expect("cannot define private method: ydoc_encode_diff_v2");
|
86
88
|
ydoc.define_private_method(
|
87
89
|
"ydoc_get_or_insert_array",
|
88
90
|
method!(YDoc::ydoc_get_or_insert_array, 1),
|
@@ -120,7 +122,7 @@ fn init() -> Result<(), Error> {
|
|
120
122
|
.expect("cannot define private method: ydoc_observe_update");
|
121
123
|
|
122
124
|
let ymap = module
|
123
|
-
.define_class("Map",
|
125
|
+
.define_class("Map", class::object())
|
124
126
|
.expect("cannot define class Y::Map");
|
125
127
|
|
126
128
|
ymap.define_private_method("ymap_clear", method!(YMap::ymap_clear, 1))
|
@@ -145,7 +147,7 @@ fn init() -> Result<(), Error> {
|
|
145
147
|
.expect("cannot define private method: ymap_unobserve");
|
146
148
|
|
147
149
|
let ytransaction = module
|
148
|
-
.define_class("Transaction",
|
150
|
+
.define_class("Transaction", class::object())
|
149
151
|
.expect("cannot define class Y::Transaction");
|
150
152
|
|
151
153
|
ytransaction
|
@@ -154,6 +156,12 @@ fn init() -> Result<(), Error> {
|
|
154
156
|
method!(YTransaction::ytransaction_apply_update, 1),
|
155
157
|
)
|
156
158
|
.expect("cannot define private method: ytransaction_apply_update");
|
159
|
+
ytransaction
|
160
|
+
.define_private_method(
|
161
|
+
"ytransaction_apply_update_v2",
|
162
|
+
method!(YTransaction::ytransaction_apply_update_v2, 1),
|
163
|
+
)
|
164
|
+
.expect("cannot define private method: ytransaction_apply_update_v2");
|
157
165
|
ytransaction
|
158
166
|
.define_private_method(
|
159
167
|
"ytransaction_commit",
|
@@ -205,9 +213,15 @@ fn init() -> Result<(), Error> {
|
|
205
213
|
method!(YTransaction::ytransaction_state_vector, 0),
|
206
214
|
)
|
207
215
|
.expect("cannot define private method: ytransaction_state_vector");
|
216
|
+
ytransaction
|
217
|
+
.define_private_method(
|
218
|
+
"ytransaction_state_vector_v2",
|
219
|
+
method!(YTransaction::ytransaction_state_vector_v2, 0),
|
220
|
+
)
|
221
|
+
.expect("cannot define private method: ytransaction_state_vector_v2");
|
208
222
|
|
209
223
|
let ytext = module
|
210
|
-
.define_class("Text",
|
224
|
+
.define_class("Text", class::object())
|
211
225
|
.expect("cannot define class Y::Text");
|
212
226
|
|
213
227
|
ytext
|
@@ -251,7 +265,7 @@ fn init() -> Result<(), Error> {
|
|
251
265
|
.expect("cannot define private method: ytext_unobserve");
|
252
266
|
|
253
267
|
let yxml_element = module
|
254
|
-
.define_class("XMLElement",
|
268
|
+
.define_class("XMLElement", class::object())
|
255
269
|
.expect("cannot define class Y::XMLElement");
|
256
270
|
|
257
271
|
yxml_element
|
@@ -394,7 +408,7 @@ fn init() -> Result<(), Error> {
|
|
394
408
|
.expect("cannot define private method: yxml_element_unobserve");
|
395
409
|
|
396
410
|
let yxml_fragment = module
|
397
|
-
.define_class("XMLFragment",
|
411
|
+
.define_class("XMLFragment", class::object())
|
398
412
|
.expect("cannot define class: Y::XMLFragment");
|
399
413
|
|
400
414
|
yxml_fragment
|
@@ -459,7 +473,7 @@ fn init() -> Result<(), Error> {
|
|
459
473
|
.expect("cannot define private method: yxml_fragment_to_s");
|
460
474
|
|
461
475
|
let yxml_text = module
|
462
|
-
.define_class("XMLText",
|
476
|
+
.define_class("XMLText", class::object())
|
463
477
|
.expect("cannot define class Y::XMLText");
|
464
478
|
|
465
479
|
yxml_text
|
@@ -536,7 +550,7 @@ fn init() -> Result<(), Error> {
|
|
536
550
|
.expect("cannot define private method: yxml_text_to_s");
|
537
551
|
|
538
552
|
let yawareness = module
|
539
|
-
.define_class("Awareness",
|
553
|
+
.define_class("Awareness", class::object())
|
540
554
|
.expect("cannot define class Y::Awareness");
|
541
555
|
yawareness
|
542
556
|
.define_singleton_method("new", function!(YAwareness::yawareness_new, 0))
|
@@ -603,7 +617,7 @@ fn init() -> Result<(), Error> {
|
|
603
617
|
.expect("cannot define private method: yawareness_update_with_clients");
|
604
618
|
|
605
619
|
let yawareness_event = module
|
606
|
-
.define_class("AwarenessEvent",
|
620
|
+
.define_class("AwarenessEvent", class::object())
|
607
621
|
.expect("cannot define class Y:AwarenessEvent");
|
608
622
|
yawareness_event
|
609
623
|
.define_method("added", method!(YAwarenessEvent::added, 0))
|
data/ext/yrb/src/utils.rs
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
use crate::yvalue::YValue;
|
2
2
|
use lib0::any::Any;
|
3
3
|
use magnus::r_hash::ForEach::Continue;
|
4
|
-
use magnus::{exception, Error, RHash, RString, Symbol, Value};
|
5
|
-
use std::
|
6
|
-
use yrs::types::Attrs;
|
4
|
+
use magnus::{exception, Error, RArray, RHash, RString, Symbol, Value};
|
5
|
+
use std::sync::Arc;
|
6
|
+
use yrs::types::{Attrs, Value as YrsValue};
|
7
|
+
use yrs::{Array, Map, TransactionMut};
|
7
8
|
|
8
9
|
#[derive(Debug, Clone)]
|
9
10
|
pub(crate) struct TypeConversionError;
|
@@ -18,7 +19,7 @@ pub(crate) fn map_rhash_to_attrs(hash: RHash) -> Result<Attrs, Error> {
|
|
18
19
|
let mut a: Attrs = Default::default();
|
19
20
|
|
20
21
|
let result = hash.foreach(|key: Value, value: Value| {
|
21
|
-
let k =
|
22
|
+
let k = Arc::from(key.to_string());
|
22
23
|
let v = Any::from(YValue::from(value));
|
23
24
|
|
24
25
|
a.insert(k, v);
|
@@ -35,3 +36,30 @@ pub(crate) fn map_rhash_to_attrs(hash: RHash) -> Result<Attrs, Error> {
|
|
35
36
|
|
36
37
|
Ok(a)
|
37
38
|
}
|
39
|
+
|
40
|
+
pub(crate) fn convert_yvalue_to_ruby_value(value: YrsValue, tx: &TransactionMut) -> YValue {
|
41
|
+
match value {
|
42
|
+
YrsValue::Any(val) => YValue::from(val),
|
43
|
+
YrsValue::YText(text) => YValue::from(text),
|
44
|
+
YrsValue::YXmlElement(el) => YValue::from(el),
|
45
|
+
YrsValue::YXmlText(text) => YValue::from(text),
|
46
|
+
YrsValue::YArray(val) => {
|
47
|
+
let arr = RArray::new();
|
48
|
+
for item in val.iter(tx) {
|
49
|
+
let val = convert_yvalue_to_ruby_value(item.clone(), tx);
|
50
|
+
let val = *val.0.borrow();
|
51
|
+
arr.push(val).expect("cannot push item event to array");
|
52
|
+
}
|
53
|
+
YValue::from(arr)
|
54
|
+
}
|
55
|
+
YrsValue::YMap(val) => {
|
56
|
+
let iter = val.iter(tx).map(|(key, val)| {
|
57
|
+
let val = convert_yvalue_to_ruby_value(val.clone(), tx);
|
58
|
+
let val = val.0.into_inner();
|
59
|
+
(key, val)
|
60
|
+
});
|
61
|
+
YValue::from(RHash::from_iter(iter))
|
62
|
+
}
|
63
|
+
v => panic!("cannot map given yrs values to yvalue: {:?}", v),
|
64
|
+
}
|
65
|
+
}
|
data/ext/yrb/src/yany.rs
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
use lib0::any::Any;
|
2
2
|
use magnus::r_string::IntoRString;
|
3
|
-
use magnus::
|
3
|
+
use magnus::value::ReprValue;
|
4
|
+
use magnus::{value, IntoValue, RArray, RHash, RString, Value};
|
4
5
|
use std::borrow::Borrow;
|
5
6
|
use std::ops::{Deref, DerefMut};
|
6
7
|
|
@@ -27,19 +28,19 @@ impl TryInto<Value> for YAny {
|
|
27
28
|
return match self.0 {
|
28
29
|
Any::Array(_v) => {
|
29
30
|
let arr = RArray::new();
|
30
|
-
Ok(
|
31
|
+
Ok(arr.as_value())
|
31
32
|
}
|
32
33
|
Any::Map(_v) => {
|
33
34
|
let hash = RHash::new();
|
34
|
-
Ok(
|
35
|
+
Ok(hash.as_value())
|
35
36
|
}
|
36
|
-
Any::Null => Ok(
|
37
|
-
Any::Undefined => Ok(Value::from(
|
38
|
-
Any::Bool(v) => Ok(
|
39
|
-
Any::Number(v) => Ok(Value::from(v)),
|
40
|
-
Any::BigInt(v) => Ok(Value::from(v)),
|
41
|
-
Any::String(v) => Ok(
|
42
|
-
Any::Buffer(v) => Ok(
|
37
|
+
Any::Null => Ok(value::qnil().as_value()),
|
38
|
+
Any::Undefined => Ok(Value::from(value::qnil().as_value())),
|
39
|
+
Any::Bool(v) => Ok(v.into_value()),
|
40
|
+
Any::Number(v) => Ok(Value::from(v.into_value())),
|
41
|
+
Any::BigInt(v) => Ok(Value::from(v.into_value())),
|
42
|
+
Any::String(v) => Ok(RString::from(v.into_r_string()).as_value()),
|
43
|
+
Any::Buffer(v) => Ok(RString::from_slice(v.borrow()).as_value()),
|
43
44
|
};
|
44
45
|
}
|
45
46
|
}
|
data/ext/yrb/src/yarray.rs
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
use crate::utils::convert_yvalue_to_ruby_value;
|
1
2
|
use crate::ytransaction::YTransaction;
|
2
3
|
use crate::yvalue::YValue;
|
3
4
|
use lib0::any::Any;
|
4
5
|
use magnus::block::Proc;
|
5
6
|
use magnus::value::Qnil;
|
6
|
-
use magnus::{Error, RArray, RHash, Symbol, Value};
|
7
|
+
use magnus::{Error, IntoValue, RArray, RHash, Symbol, Value};
|
7
8
|
use std::borrow::Borrow;
|
8
9
|
use std::cell::RefCell;
|
9
10
|
use yrs::types::Change;
|
@@ -22,20 +23,21 @@ impl YArray {
|
|
22
23
|
|
23
24
|
let arr = self.0.borrow();
|
24
25
|
arr.iter(tx).for_each(|val| {
|
25
|
-
let yvalue =
|
26
|
-
let args = (yvalue
|
26
|
+
let yvalue = *convert_yvalue_to_ruby_value(val, tx).0.borrow();
|
27
|
+
let args = (yvalue,);
|
27
28
|
let _ = block.call::<(Value,), Qnil>(args);
|
28
29
|
});
|
29
30
|
|
30
31
|
Ok(())
|
31
32
|
}
|
33
|
+
|
32
34
|
pub(crate) fn yarray_get(&self, transaction: &YTransaction, index: u32) -> Value {
|
33
35
|
let tx = transaction.transaction();
|
34
36
|
let tx = tx.as_ref().unwrap();
|
35
37
|
|
36
38
|
let arr = self.0.borrow();
|
37
39
|
let v = arr.get(tx, index).unwrap();
|
38
|
-
|
40
|
+
*convert_yvalue_to_ruby_value(v, tx).0.borrow()
|
39
41
|
}
|
40
42
|
pub(crate) fn yarray_insert(&self, transaction: &YTransaction, index: u32, value: Value) {
|
41
43
|
let yvalue = YValue::from(value);
|
@@ -98,10 +100,10 @@ impl YArray {
|
|
98
100
|
payload.aset(change_added, values)
|
99
101
|
}
|
100
102
|
Change::Retain(position) => {
|
101
|
-
payload.aset(change_retain,
|
103
|
+
payload.aset(change_retain, (*position).into_value())
|
102
104
|
}
|
103
105
|
Change::Removed(position) => {
|
104
|
-
payload.aset(change_removed,
|
106
|
+
payload.aset(change_removed, (*position).into_value())
|
105
107
|
}
|
106
108
|
};
|
107
109
|
|
data/ext/yrb/src/yattrs.rs
CHANGED
@@ -3,7 +3,7 @@ use lib0::any::Any;
|
|
3
3
|
use magnus::r_hash::ForEach::Continue;
|
4
4
|
use magnus::{RHash, Value};
|
5
5
|
use std::ops::{Deref, DerefMut};
|
6
|
-
use std::
|
6
|
+
use std::sync::Arc;
|
7
7
|
use yrs::types::Attrs;
|
8
8
|
|
9
9
|
pub(crate) struct YAttrs(pub(crate) Attrs);
|
@@ -23,7 +23,7 @@ impl From<RHash> for YAttrs {
|
|
23
23
|
let k = key.to_string();
|
24
24
|
let yvalue = YValue::from(value);
|
25
25
|
let avalue = Any::from(yvalue);
|
26
|
-
attrs.insert(
|
26
|
+
attrs.insert(Arc::from(k), avalue);
|
27
27
|
|
28
28
|
Ok(Continue)
|
29
29
|
})
|
data/ext/yrb/src/yawareness.rs
CHANGED
@@ -2,7 +2,7 @@ use magnus::{block::Proc, exception, Error, Value};
|
|
2
2
|
use std::borrow::Borrow;
|
3
3
|
use std::cell::RefCell;
|
4
4
|
use std::collections::HashMap;
|
5
|
-
use y_sync::awareness::{Awareness, AwarenessUpdate, Event,
|
5
|
+
use y_sync::awareness::{Awareness, AwarenessUpdate, Event, UpdateSubscription};
|
6
6
|
use yrs::block::ClientID;
|
7
7
|
use yrs::updates::decoder::Decode;
|
8
8
|
use yrs::updates::encoder::Encode;
|
@@ -138,14 +138,14 @@ impl From<&Event> for YAwarenessEvent {
|
|
138
138
|
}
|
139
139
|
|
140
140
|
#[magnus::wrap(class = "Y::AwarenessEvent")]
|
141
|
-
pub(crate) struct YAwarenessSubscription(
|
141
|
+
pub(crate) struct YAwarenessSubscription(UpdateSubscription);
|
142
142
|
|
143
143
|
unsafe impl Send for YAwarenessSubscription {}
|
144
144
|
|
145
145
|
impl YAwarenessSubscription {}
|
146
146
|
|
147
|
-
impl From<
|
148
|
-
fn from(v:
|
147
|
+
impl From<UpdateSubscription> for YAwarenessSubscription {
|
148
|
+
fn from(v: UpdateSubscription) -> Self {
|
149
149
|
YAwarenessSubscription(v)
|
150
150
|
}
|
151
151
|
}
|
data/ext/yrb/src/ydoc.rs
CHANGED
@@ -10,6 +10,7 @@ use magnus::{exception::runtime_error, Error, Integer, RArray, Value};
|
|
10
10
|
use std::borrow::Borrow;
|
11
11
|
use std::cell::RefCell;
|
12
12
|
use yrs::updates::decoder::Decode;
|
13
|
+
use yrs::updates::encoder::{Encoder, EncoderV2};
|
13
14
|
use yrs::{Doc, OffsetKind, Options, ReadTxn, StateVector, SubscriptionId, Transact};
|
14
15
|
|
15
16
|
#[magnus::wrap(class = "Y::Doc")]
|
@@ -43,6 +44,21 @@ impl YDoc {
|
|
43
44
|
.map_err(|_e| Error::new(runtime_error(), "cannot encode diff"))
|
44
45
|
}
|
45
46
|
|
47
|
+
pub(crate) fn ydoc_encode_diff_v2(
|
48
|
+
&self,
|
49
|
+
transaction: &YTransaction,
|
50
|
+
state_vector: Vec<u8>,
|
51
|
+
) -> Result<Vec<u8>, Error> {
|
52
|
+
let mut tx = transaction.transaction();
|
53
|
+
let tx = tx.as_mut().unwrap();
|
54
|
+
let mut encoder = EncoderV2::new();
|
55
|
+
|
56
|
+
StateVector::decode_v2(state_vector.borrow())
|
57
|
+
.map(|sv| tx.encode_diff(&sv, &mut encoder))
|
58
|
+
.map(|_| encoder.to_vec())
|
59
|
+
.map_err(|_e| Error::new(runtime_error(), "cannot encode diff"))
|
60
|
+
}
|
61
|
+
|
46
62
|
pub(crate) fn ydoc_get_or_insert_array(&self, name: String) -> YArray {
|
47
63
|
let array_ref = self.0.borrow().get_or_insert_array(name.as_str());
|
48
64
|
YArray::from(array_ref)
|
data/ext/yrb/src/ymap.rs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
use crate::utils::indifferent_hash_key;
|
1
|
+
use crate::utils::{convert_yvalue_to_ruby_value, indifferent_hash_key};
|
2
2
|
use crate::yvalue::YValue;
|
3
3
|
use crate::YTransaction;
|
4
4
|
use lib0::any::Any;
|
@@ -30,17 +30,18 @@ impl YMap {
|
|
30
30
|
Some(k) => self.0.borrow().contains_key(tx, k.as_str()),
|
31
31
|
}
|
32
32
|
}
|
33
|
+
|
33
34
|
pub(crate) fn ymap_each(&self, transaction: &YTransaction, proc: Proc) {
|
34
35
|
let tx = transaction.transaction();
|
35
36
|
let tx = tx.as_ref().unwrap();
|
36
|
-
|
37
37
|
self.0.borrow().iter(tx).for_each(|(key, val)| {
|
38
38
|
let k = key.to_string();
|
39
|
-
let v = *
|
39
|
+
let v = *convert_yvalue_to_ruby_value(val, tx).0.borrow();
|
40
40
|
proc.call::<(String, Value), Value>((k, v))
|
41
41
|
.expect("cannot iterate map");
|
42
42
|
})
|
43
43
|
}
|
44
|
+
|
44
45
|
pub(crate) fn ymap_get(&self, transaction: &YTransaction, key: Value) -> Option<Value> {
|
45
46
|
let tx = transaction.transaction();
|
46
47
|
let tx = tx.as_ref().unwrap();
|
@@ -48,7 +49,7 @@ impl YMap {
|
|
48
49
|
indifferent_hash_key(key)
|
49
50
|
.map(|k| self.0.borrow().get(tx, k.as_str()))
|
50
51
|
.map(|v| v.unwrap_or(YrsValue::Any(Any::Undefined)))
|
51
|
-
.map(|v| *
|
52
|
+
.map(|v| *convert_yvalue_to_ruby_value(v, tx).0.borrow())
|
52
53
|
}
|
53
54
|
pub(crate) fn ymap_insert(
|
54
55
|
&self,
|
data/ext/yrb/src/ytransaction.rs
CHANGED
@@ -38,6 +38,17 @@ impl YTransaction {
|
|
38
38
|
.map(|u| self.transaction().as_mut().unwrap().apply_update(u))
|
39
39
|
}
|
40
40
|
|
41
|
+
pub(crate) fn ytransaction_apply_update_v2(&self, update: Vec<u8>) -> Result<(), Error> {
|
42
|
+
Update::decode_v2(update.as_slice())
|
43
|
+
.map_err(|error| {
|
44
|
+
Error::new(
|
45
|
+
exception::runtime_error(),
|
46
|
+
format!("cannot decode update: {:?}", error),
|
47
|
+
)
|
48
|
+
})
|
49
|
+
.map(|u| self.transaction().as_mut().unwrap().apply_update(u))
|
50
|
+
}
|
51
|
+
|
41
52
|
pub(crate) fn ytransaction_commit(&self) {
|
42
53
|
self.transaction().as_mut().unwrap().commit();
|
43
54
|
}
|
@@ -98,6 +109,14 @@ impl YTransaction {
|
|
98
109
|
.encode_v1()
|
99
110
|
}
|
100
111
|
|
112
|
+
pub(crate) fn ytransaction_state_vector_v2(&self) -> Vec<u8> {
|
113
|
+
self.transaction()
|
114
|
+
.as_ref()
|
115
|
+
.unwrap()
|
116
|
+
.state_vector()
|
117
|
+
.encode_v2()
|
118
|
+
}
|
119
|
+
|
101
120
|
pub(crate) fn ytransaction_free(&self) {
|
102
121
|
self.0.replace(None);
|
103
122
|
}
|
data/ext/yrb/src/yvalue.rs
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
use crate::{YText, YXmlElement, YXmlText};
|
2
2
|
use lib0::any::Any;
|
3
3
|
use magnus::r_hash::ForEach::Continue;
|
4
|
-
use magnus::value::Qnil;
|
5
|
-
use magnus::{class, Float, Integer, RArray, RHash, RString, Symbol, Value
|
4
|
+
use magnus::value::{Qnil, ReprValue};
|
5
|
+
use magnus::{class, value, Float, Integer, IntoValue, RArray, RHash, RString, Symbol, Value};
|
6
6
|
use std::cell::RefCell;
|
7
7
|
use std::collections::HashMap;
|
8
8
|
use yrs::types::Value as YrsValue;
|
@@ -21,100 +21,100 @@ impl From<Value> for YValue {
|
|
21
21
|
|
22
22
|
impl From<Qnil> for YValue {
|
23
23
|
fn from(value: Qnil) -> Self {
|
24
|
-
YValue(RefCell::from(
|
24
|
+
YValue(RefCell::from(value.into_value()))
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
28
28
|
impl From<bool> for YValue {
|
29
29
|
fn from(value: bool) -> Self {
|
30
|
-
YValue(RefCell::from(
|
30
|
+
YValue(RefCell::from(value.into_value()))
|
31
31
|
}
|
32
32
|
}
|
33
33
|
|
34
34
|
impl From<f64> for YValue {
|
35
35
|
fn from(value: f64) -> Self {
|
36
|
-
YValue(RefCell::from(
|
36
|
+
YValue(RefCell::from(value.into_value()))
|
37
37
|
}
|
38
38
|
}
|
39
39
|
|
40
40
|
impl From<i64> for YValue {
|
41
41
|
fn from(value: i64) -> Self {
|
42
|
-
YValue(RefCell::from(
|
42
|
+
YValue(RefCell::from(value.into_value()))
|
43
43
|
}
|
44
44
|
}
|
45
45
|
|
46
46
|
impl From<u32> for YValue {
|
47
47
|
fn from(value: u32) -> Self {
|
48
|
-
YValue(RefCell::from(
|
48
|
+
YValue(RefCell::from(value.into_value()))
|
49
49
|
}
|
50
50
|
}
|
51
51
|
|
52
52
|
impl From<String> for YValue {
|
53
53
|
fn from(value: String) -> Self {
|
54
|
-
YValue(RefCell::from(
|
54
|
+
YValue(RefCell::from(value.into_value()))
|
55
55
|
}
|
56
56
|
}
|
57
57
|
|
58
58
|
impl From<RArray> for YValue {
|
59
59
|
fn from(value: RArray) -> Self {
|
60
|
-
YValue(RefCell::from(
|
60
|
+
YValue(RefCell::from(value.into_value()))
|
61
61
|
}
|
62
62
|
}
|
63
63
|
|
64
64
|
impl From<RHash> for YValue {
|
65
65
|
fn from(value: RHash) -> Self {
|
66
|
-
YValue(RefCell::from(
|
66
|
+
YValue(RefCell::from(value.into_value()))
|
67
67
|
}
|
68
68
|
}
|
69
69
|
|
70
70
|
impl From<YrsText> for YValue {
|
71
71
|
fn from(value: YrsText) -> Self {
|
72
|
-
YValue(RefCell::from(
|
72
|
+
YValue(RefCell::from(YText(RefCell::from(value)).into_value()))
|
73
73
|
}
|
74
74
|
}
|
75
75
|
|
76
76
|
impl From<YrsXmlElement> for YValue {
|
77
77
|
fn from(value: YrsXmlElement) -> Self {
|
78
|
-
YValue(RefCell::from(
|
79
|
-
value,
|
80
|
-
))
|
78
|
+
YValue(RefCell::from(
|
79
|
+
YXmlElement(RefCell::from(value)).into_value(),
|
80
|
+
))
|
81
81
|
}
|
82
82
|
}
|
83
83
|
|
84
84
|
impl From<YrsXmlText> for YValue {
|
85
85
|
fn from(value: YrsXmlText) -> Self {
|
86
|
-
YValue(RefCell::from(
|
86
|
+
YValue(RefCell::from(YXmlText(RefCell::from(value)).into_value()))
|
87
87
|
}
|
88
88
|
}
|
89
89
|
|
90
90
|
impl From<YText> for YValue {
|
91
91
|
fn from(value: YText) -> Self {
|
92
|
-
YValue(RefCell::from(
|
92
|
+
YValue(RefCell::from(value.into_value()))
|
93
93
|
}
|
94
94
|
}
|
95
95
|
|
96
96
|
impl From<YXmlElement> for YValue {
|
97
97
|
fn from(value: YXmlElement) -> Self {
|
98
|
-
YValue(RefCell::from(
|
98
|
+
YValue(RefCell::from(value.into_value()))
|
99
99
|
}
|
100
100
|
}
|
101
101
|
|
102
102
|
impl From<YXmlText> for YValue {
|
103
103
|
fn from(value: YXmlText) -> Self {
|
104
|
-
YValue(RefCell::from(
|
104
|
+
YValue(RefCell::from(value.into_value()))
|
105
105
|
}
|
106
106
|
}
|
107
107
|
|
108
108
|
impl From<Any> for YValue {
|
109
109
|
fn from(value: Any) -> Self {
|
110
110
|
match value {
|
111
|
-
Any::Null => YValue::from(
|
112
|
-
Any::Undefined => YValue::from(
|
111
|
+
Any::Null => YValue::from(value::qnil()),
|
112
|
+
Any::Undefined => YValue::from(value::qnil()),
|
113
113
|
Any::Bool(v) => YValue::from(v),
|
114
114
|
Any::Number(v) => YValue::from(v),
|
115
115
|
Any::BigInt(v) => YValue::from(v),
|
116
116
|
Any::String(v) => YValue::from(v.into_string()),
|
117
|
-
Any::Buffer(v) => YValue::from(
|
117
|
+
Any::Buffer(v) => YValue::from(v.into_vec().into_value()),
|
118
118
|
Any::Array(v) => {
|
119
119
|
let arr = RArray::new();
|
120
120
|
for item in v.iter() {
|
@@ -146,16 +146,18 @@ impl From<YrsValue> for YValue {
|
|
146
146
|
YrsValue::YXmlElement(el) => YValue::from(el),
|
147
147
|
YrsValue::YXmlText(text) => YValue::from(text),
|
148
148
|
YrsValue::YArray(val) => {
|
149
|
+
print!("try to acquire transaction");
|
149
150
|
let tx = val.transact();
|
150
151
|
let arr = RArray::new();
|
151
152
|
for item in val.iter(&tx) {
|
152
153
|
let val = YValue::from(item.clone());
|
153
|
-
let val = val.0.borrow()
|
154
|
+
let val = *val.0.borrow();
|
154
155
|
arr.push(val).expect("cannot push item event to array");
|
155
156
|
}
|
156
157
|
YValue::from(arr)
|
157
158
|
}
|
158
159
|
YrsValue::YMap(val) => {
|
160
|
+
print!("try to acquire transaction");
|
159
161
|
let tx = val.transact();
|
160
162
|
let iter = val.iter(&tx).map(|(key, val)| {
|
161
163
|
let val = YValue::from(val);
|
@@ -237,6 +239,7 @@ impl Into<Value> for YValue {
|
|
237
239
|
mod tests {
|
238
240
|
use crate::yvalue::YValue;
|
239
241
|
use lib0::any::Any;
|
242
|
+
use magnus::value::ReprValue;
|
240
243
|
|
241
244
|
#[test]
|
242
245
|
fn convert_any_to_yvalue() {
|
data/ext/yrb/src/yxml_element.rs
CHANGED
@@ -3,7 +3,7 @@ use crate::yxml_fragment::YXmlFragment;
|
|
3
3
|
use crate::yxml_text::YXmlText;
|
4
4
|
use crate::YTransaction;
|
5
5
|
use magnus::block::Proc;
|
6
|
-
use magnus::{Error, RArray, RHash, Symbol, Value};
|
6
|
+
use magnus::{Error, IntoValue, RArray, RHash, Symbol, Value};
|
7
7
|
use std::cell::RefCell;
|
8
8
|
use yrs::types::Change;
|
9
9
|
use yrs::{
|
@@ -32,9 +32,9 @@ impl YXmlElement {
|
|
32
32
|
let tx = tx.as_ref().unwrap();
|
33
33
|
|
34
34
|
self.0.borrow().get(tx, index).map(|node| match node {
|
35
|
-
XmlNode::Element(element) =>
|
36
|
-
XmlNode::Fragment(fragment) =>
|
37
|
-
XmlNode::Text(text) =>
|
35
|
+
XmlNode::Element(element) => YXmlElement::from(element).into_value(),
|
36
|
+
XmlNode::Fragment(fragment) => YXmlFragment::from(fragment).into_value(),
|
37
|
+
XmlNode::Text(text) => YXmlText::from(text).into_value(),
|
38
38
|
})
|
39
39
|
}
|
40
40
|
pub(crate) fn yxml_element_get_attribute(
|
@@ -93,9 +93,9 @@ impl YXmlElement {
|
|
93
93
|
let tx = tx.as_ref().unwrap();
|
94
94
|
|
95
95
|
self.0.borrow().siblings(tx).next().map(|item| match item {
|
96
|
-
XmlNode::Element(el) =>
|
97
|
-
XmlNode::Fragment(fragment) =>
|
98
|
-
XmlNode::Text(text) =>
|
96
|
+
XmlNode::Element(el) => YXmlElement::from(el).into_value(),
|
97
|
+
XmlNode::Fragment(fragment) => YXmlFragment::from(fragment).into_value(),
|
98
|
+
XmlNode::Text(text) => YXmlText::from(text).into_value(),
|
99
99
|
})
|
100
100
|
}
|
101
101
|
pub(crate) fn yxml_element_observe(&self, block: Proc) -> Result<u32, Error> {
|
@@ -161,9 +161,9 @@ impl YXmlElement {
|
|
161
161
|
}
|
162
162
|
pub(crate) fn yxml_element_parent(&self) -> Option<Value> {
|
163
163
|
self.0.borrow().parent().map(|item| match item {
|
164
|
-
XmlNode::Element(el) =>
|
165
|
-
XmlNode::Fragment(fragment) =>
|
166
|
-
XmlNode::Text(text) =>
|
164
|
+
XmlNode::Element(el) => YXmlElement::from(el).into_value(),
|
165
|
+
XmlNode::Fragment(fragment) => YXmlFragment::from(fragment).into_value(),
|
166
|
+
XmlNode::Text(text) => YXmlText::from(text).into_value(),
|
167
167
|
})
|
168
168
|
}
|
169
169
|
pub(crate) fn yxml_element_prev_sibling(&self, transaction: &YTransaction) -> Option<Value> {
|
@@ -175,9 +175,9 @@ impl YXmlElement {
|
|
175
175
|
.siblings(tx)
|
176
176
|
.next_back()
|
177
177
|
.map(|item| match item {
|
178
|
-
XmlNode::Element(el) =>
|
179
|
-
XmlNode::Fragment(fragment) =>
|
180
|
-
XmlNode::Text(text) =>
|
178
|
+
XmlNode::Element(el) => YXmlElement::from(el).into_value(),
|
179
|
+
XmlNode::Fragment(fragment) => YXmlFragment::from(fragment).into_value(),
|
180
|
+
XmlNode::Text(text) => YXmlText::from(text).into_value(),
|
181
181
|
})
|
182
182
|
}
|
183
183
|
pub(crate) fn yxml_element_push_element_back(
|
@@ -246,9 +246,9 @@ impl YXmlElement {
|
|
246
246
|
let tx = tx.as_ref().unwrap();
|
247
247
|
|
248
248
|
let siblings = self.0.borrow().siblings(tx).map(|item| match item {
|
249
|
-
XmlNode::Element(el) =>
|
250
|
-
XmlNode::Fragment(fragment) =>
|
251
|
-
XmlNode::Text(text) =>
|
249
|
+
XmlNode::Element(el) => YXmlElement::from(el).into_value(),
|
250
|
+
XmlNode::Fragment(fragment) => YXmlFragment::from(fragment).into_value(),
|
251
|
+
XmlNode::Text(text) => YXmlText::from(text).into_value(),
|
252
252
|
});
|
253
253
|
|
254
254
|
RArray::from_iter(siblings)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
use crate::ytransaction::YTransaction;
|
2
2
|
use crate::yxml_element::YXmlElement;
|
3
3
|
use crate::yxml_text::YXmlText;
|
4
|
-
use magnus::{RArray, Value};
|
4
|
+
use magnus::{IntoValue, RArray, Value};
|
5
5
|
use std::cell::RefCell;
|
6
6
|
use yrs::{GetString, XmlElementPrelim, XmlFragment, XmlFragmentRef, XmlNode};
|
7
7
|
|
@@ -14,9 +14,9 @@ unsafe impl Send for YXmlFragment {}
|
|
14
14
|
impl YXmlFragment {
|
15
15
|
pub(crate) fn yxml_fragment_first_child(&self) -> Option<Value> {
|
16
16
|
self.0.borrow().first_child().map(|node| match node {
|
17
|
-
XmlNode::Element(element) =>
|
18
|
-
XmlNode::Fragment(fragment) =>
|
19
|
-
XmlNode::Text(text) =>
|
17
|
+
XmlNode::Element(element) => YXmlElement::from(element).into_value(),
|
18
|
+
XmlNode::Fragment(fragment) => YXmlFragment::from(fragment).into_value(),
|
19
|
+
XmlNode::Text(text) => YXmlText::from(text).into_value(),
|
20
20
|
})
|
21
21
|
}
|
22
22
|
|
@@ -29,9 +29,9 @@ impl YXmlFragment {
|
|
29
29
|
let tx = tx.as_ref().unwrap();
|
30
30
|
|
31
31
|
self.0.borrow().get(tx, index).map(|node| match node {
|
32
|
-
XmlNode::Element(element) =>
|
33
|
-
XmlNode::Fragment(fragment) =>
|
34
|
-
XmlNode::Text(text) =>
|
32
|
+
XmlNode::Element(element) => YXmlElement::from(element).into_value(),
|
33
|
+
XmlNode::Fragment(fragment) => YXmlFragment::from(fragment).into_value(),
|
34
|
+
XmlNode::Text(text) => YXmlText::from(text).into_value(),
|
35
35
|
})
|
36
36
|
}
|
37
37
|
|
@@ -57,9 +57,9 @@ impl YXmlFragment {
|
|
57
57
|
|
58
58
|
pub(crate) fn yxml_fragment_parent(&self) -> Option<Value> {
|
59
59
|
self.0.borrow().parent().map(|item| match item {
|
60
|
-
XmlNode::Element(el) =>
|
61
|
-
XmlNode::Fragment(fragment) =>
|
62
|
-
XmlNode::Text(text) =>
|
60
|
+
XmlNode::Element(el) => YXmlElement::from(el).into_value(),
|
61
|
+
XmlNode::Fragment(fragment) => YXmlFragment::from(fragment).into_value(),
|
62
|
+
XmlNode::Text(text) => YXmlText::from(text).into_value(),
|
63
63
|
})
|
64
64
|
}
|
65
65
|
|
@@ -106,9 +106,9 @@ impl YXmlFragment {
|
|
106
106
|
let fragment = self.0.borrow();
|
107
107
|
|
108
108
|
let result = fragment.successors(tx).map(|item| match item {
|
109
|
-
XmlNode::Element(el) =>
|
110
|
-
XmlNode::Fragment(fragment) =>
|
111
|
-
XmlNode::Text(text) =>
|
109
|
+
XmlNode::Element(el) => YXmlElement::from(el).into_value(),
|
110
|
+
XmlNode::Fragment(fragment) => YXmlFragment::from(fragment).into_value(),
|
111
|
+
XmlNode::Text(text) => YXmlText::from(text).into_value(),
|
112
112
|
});
|
113
113
|
|
114
114
|
RArray::from_iter(result)
|
data/ext/yrb/src/yxml_text.rs
CHANGED
@@ -3,7 +3,7 @@ use crate::yvalue::YValue;
|
|
3
3
|
use crate::yxml_fragment::YXmlFragment;
|
4
4
|
use crate::{YTransaction, YXmlElement};
|
5
5
|
use lib0::any::Any;
|
6
|
-
use magnus::{Error, RHash, Value};
|
6
|
+
use magnus::{Error, IntoValue, RHash, Value};
|
7
7
|
use std::cell::RefCell;
|
8
8
|
use yrs::{GetString, Text, Xml, XmlNode, XmlTextRef};
|
9
9
|
|
@@ -120,16 +120,16 @@ impl YXmlText {
|
|
120
120
|
let tx = tx.as_ref().unwrap();
|
121
121
|
|
122
122
|
self.0.borrow().siblings(tx).next().map(|item| match item {
|
123
|
-
XmlNode::Element(el) =>
|
124
|
-
XmlNode::Fragment(fragment) =>
|
125
|
-
XmlNode::Text(text) =>
|
123
|
+
XmlNode::Element(el) => YXmlElement(RefCell::from(el)).into_value(),
|
124
|
+
XmlNode::Fragment(fragment) => YXmlFragment(RefCell::from(fragment)).into_value(),
|
125
|
+
XmlNode::Text(text) => YXmlText(RefCell::from(text)).into_value(),
|
126
126
|
})
|
127
127
|
}
|
128
128
|
pub(crate) fn yxml_text_parent(&self) -> Option<Value> {
|
129
129
|
self.0.borrow().parent().map(|item| match item {
|
130
|
-
XmlNode::Element(el) =>
|
131
|
-
XmlNode::Fragment(fragment) =>
|
132
|
-
XmlNode::Text(text) =>
|
130
|
+
XmlNode::Element(el) => YXmlElement(RefCell::from(el)).into_value(),
|
131
|
+
XmlNode::Fragment(fragment) => YXmlFragment(RefCell::from(fragment)).into_value(),
|
132
|
+
XmlNode::Text(text) => YXmlText(RefCell::from(text)).into_value(),
|
133
133
|
})
|
134
134
|
}
|
135
135
|
pub(crate) fn yxml_text_prev_sibling(&self, transaction: &YTransaction) -> Option<Value> {
|
@@ -141,9 +141,9 @@ impl YXmlText {
|
|
141
141
|
.siblings(tx)
|
142
142
|
.next_back()
|
143
143
|
.map(|item| match item {
|
144
|
-
XmlNode::Element(el) =>
|
145
|
-
XmlNode::Fragment(fragment) =>
|
146
|
-
XmlNode::Text(text) =>
|
144
|
+
XmlNode::Element(el) => YXmlElement(RefCell::from(el)).into_value(),
|
145
|
+
XmlNode::Fragment(fragment) => YXmlFragment(RefCell::from(fragment)).into_value(),
|
146
|
+
XmlNode::Text(text) => YXmlText(RefCell::from(text)).into_value(),
|
147
147
|
})
|
148
148
|
}
|
149
149
|
pub(crate) fn yxml_text_push(&self, transaction: &YTransaction, content: String) {
|
data/lib/3.0/yrb.bundle
CHANGED
Binary file
|
data/lib/3.1/yrb.bundle
CHANGED
Binary file
|
data/lib/3.2/yrb.bundle
CHANGED
Binary file
|
data/lib/y/doc.rb
CHANGED
@@ -19,6 +19,9 @@ module Y
|
|
19
19
|
ZERO_STATE = [0].freeze
|
20
20
|
private_constant :ZERO_STATE
|
21
21
|
|
22
|
+
ZERO_STATE_V2 = [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0].freeze
|
23
|
+
private_constant :ZERO_STATE_V2
|
24
|
+
|
22
25
|
# Attach a listener to document changes. If one of the data structures is
|
23
26
|
# changes, the block is called with the update as its only argument.
|
24
27
|
#
|
@@ -55,6 +58,16 @@ module Y
|
|
55
58
|
current_transaction { |tx| ydoc_encode_diff_v1(tx, state) }
|
56
59
|
end
|
57
60
|
|
61
|
+
# Create a v2 diff between this document and another document. The diff is
|
62
|
+
# created based on a state vector provided by the other document. It only
|
63
|
+
# returns the missing blocks, as binary encoded sequence.
|
64
|
+
#
|
65
|
+
# @param state [::Array<Integer>] The state to create the diff against
|
66
|
+
# @return [::Array<Integer>] Binary encoded diff
|
67
|
+
def diff_v2(state = ZERO_STATE_V2)
|
68
|
+
current_transaction { |tx| ydoc_encode_diff_v2(tx, state) }
|
69
|
+
end
|
70
|
+
|
58
71
|
# Creates a full diff for the current document. It is similar to {#diff},
|
59
72
|
# but does not take a state. Instead it creates an empty state and passes it
|
60
73
|
# to the encode_diff function.
|
@@ -152,6 +165,14 @@ module Y
|
|
152
165
|
current_transaction(&:state)
|
153
166
|
end
|
154
167
|
|
168
|
+
# Creates a v2 state vector of this document. This can be used to compare
|
169
|
+
# the state of two documents with each other and to later on sync them.
|
170
|
+
#
|
171
|
+
# @return [::Array<Integer>] Binary encoded state vector
|
172
|
+
def state_v2
|
173
|
+
current_transaction(&:state_v2)
|
174
|
+
end
|
175
|
+
|
155
176
|
# Synchronizes this document with the diff from another document
|
156
177
|
#
|
157
178
|
# @param diff [::Array<Integer>] Binary encoded update
|
@@ -160,6 +181,14 @@ module Y
|
|
160
181
|
current_transaction { |tx| tx.apply(diff) }
|
161
182
|
end
|
162
183
|
|
184
|
+
# Synchronizes this document with the v2 diff from another document
|
185
|
+
#
|
186
|
+
# @param diff [::Array<Integer>] Binary encoded update
|
187
|
+
# @return [void]
|
188
|
+
def sync_v2(diff)
|
189
|
+
current_transaction { |tx| tx.apply_v2(diff) }
|
190
|
+
end
|
191
|
+
|
163
192
|
# Restores a specific document from an update that contains full state
|
164
193
|
#
|
165
194
|
# This is doing the same as {#sync}, but it exists to be explicit about
|
@@ -211,6 +240,17 @@ module Y
|
|
211
240
|
# @return [Array<Integer>] Binary encoded update
|
212
241
|
# @!visibility private
|
213
242
|
|
243
|
+
# @!method ydoc_encode_diff_v2(tx, state_vector)
|
244
|
+
# Encodes the diff of current document state vs provided state in the v2
|
245
|
+
# format
|
246
|
+
#
|
247
|
+
# @example Create transaction on doc
|
248
|
+
# doc = Y::Doc.new
|
249
|
+
# tx = doc.ydoc_encode_diff_v2(other_state)
|
250
|
+
#
|
251
|
+
# @return [Array<Integer>] Binary encoded update
|
252
|
+
# @!visibility private
|
253
|
+
|
214
254
|
# @!method ydoc_transact
|
215
255
|
# Creates a new transaction for the document
|
216
256
|
#
|
data/lib/y/transaction.rb
CHANGED
@@ -22,6 +22,15 @@ module Y
|
|
22
22
|
ytransaction_apply_update(update)
|
23
23
|
end
|
24
24
|
|
25
|
+
# Applies the v2 encoded update on this document. This will bring the
|
26
|
+
# the document to the same state as the one the update is from.
|
27
|
+
#
|
28
|
+
# @param update [::Array<Integer>]
|
29
|
+
# @return [void]
|
30
|
+
def apply_v2(update)
|
31
|
+
ytransaction_apply_update_v2(update)
|
32
|
+
end
|
33
|
+
|
25
34
|
# Commits transaction
|
26
35
|
#
|
27
36
|
# @return [void]
|
@@ -89,15 +98,29 @@ module Y
|
|
89
98
|
xml_text
|
90
99
|
end
|
91
100
|
|
92
|
-
# Return state vector for transaction
|
101
|
+
# Return a state vector for this transaction
|
93
102
|
#
|
94
103
|
# @return [::Array<Integer>]
|
95
104
|
def state
|
96
105
|
ytransaction_state_vector
|
97
106
|
end
|
98
107
|
|
108
|
+
# Returns a v2 state vector for this transaction
|
109
|
+
#
|
110
|
+
# @return [::Array<Integer>]
|
111
|
+
def state_v2
|
112
|
+
ytransaction_state_vector_v2
|
113
|
+
end
|
114
|
+
|
99
115
|
# @!method ytransaction_apply_update(update)
|
100
|
-
#
|
116
|
+
# Apply the encoded update within current transaction
|
117
|
+
#
|
118
|
+
# @param update [::Array<Integer>]
|
119
|
+
# @return [void]
|
120
|
+
# @!visibility private
|
121
|
+
|
122
|
+
# @!method ytransaction_apply_update_v2(update)
|
123
|
+
# Apply the v2 encoded update within current transaction
|
101
124
|
#
|
102
125
|
# @param update [::Array<Integer>]
|
103
126
|
# @return [void]
|
@@ -157,5 +180,10 @@ module Y
|
|
157
180
|
#
|
158
181
|
# @return [Array<Integer>]
|
159
182
|
# @!visibility private
|
183
|
+
|
184
|
+
# @!method ytransaction_state_vector_v2
|
185
|
+
#
|
186
|
+
# @return [Array<Integer>]
|
187
|
+
# @!visibility private
|
160
188
|
end
|
161
189
|
end
|
data/lib/y/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: y-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: x86_64-darwin
|
6
6
|
authors:
|
7
7
|
- Hannes Moser
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -92,7 +92,6 @@ files:
|
|
92
92
|
- ext/yrb/src/yxml_element.rs
|
93
93
|
- ext/yrb/src/yxml_fragment.rs
|
94
94
|
- ext/yrb/src/yxml_text.rs
|
95
|
-
- lib/2.7/yrb.bundle
|
96
95
|
- lib/3.0/yrb.bundle
|
97
96
|
- lib/3.1/yrb.bundle
|
98
97
|
- lib/3.2/yrb.bundle
|
@@ -123,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
122
|
requirements:
|
124
123
|
- - ">="
|
125
124
|
- !ruby/object:Gem::Version
|
126
|
-
version: '
|
125
|
+
version: '3.0'
|
127
126
|
- - "<"
|
128
127
|
- !ruby/object:Gem::Version
|
129
128
|
version: 3.3.dev
|
@@ -131,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
130
|
requirements:
|
132
131
|
- - ">="
|
133
132
|
- !ruby/object:Gem::Version
|
134
|
-
version: 3.3.
|
133
|
+
version: 3.3.22
|
135
134
|
requirements: []
|
136
135
|
rubygems_version: 3.4.4
|
137
136
|
signing_key:
|
data/lib/2.7/yrb.bundle
DELETED
Binary file
|