y-rb 0.4.1-x86_64-linux → 0.4.3-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/yrb/Cargo.toml +5 -5
- data/ext/yrb/src/lib.rs +3 -0
- data/ext/yrb/src/yany.rs +2 -1
- data/ext/yrb/src/yarray.rs +18 -10
- data/ext/yrb/src/ydoc.rs +20 -2
- data/ext/yrb/src/ymap.rs +1 -1
- data/ext/yrb/src/ytext.rs +2 -2
- data/ext/yrb/src/yvalue.rs +13 -14
- data/ext/yrb/src/yxml_element.rs +7 -6
- data/ext/yrb/src/yxml_text.rs +8 -6
- data/lib/2.7/yrb.so +0 -0
- data/lib/3.0/yrb.so +0 -0
- data/lib/3.1/yrb.so +0 -0
- data/lib/y/doc.rb +22 -0
- data/lib/y/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61073f9f43e7b8167ae899a61d7876f76f6dd88962a5f3e8bbb9352317575d06
|
4
|
+
data.tar.gz: 8648119b4b33348546741ed2d3c19ea059bdfc91798cbe099bab6f79a92bf371
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a1e70f12a62302d34d7f05912fdd636a66bdc6f03d3046702d06fb63c28a041591939d27723b3b42c8daa382f6f86045a11906b87ae99dc7cd961842ad4097c
|
7
|
+
data.tar.gz: a7102aa1360f57d8012492c53e8f0564ee4db08492ec725e81ede03d2447cbd540a3d3020ddbd29a0921dcebfbf842cef482dc07291e9660b6a6dee1457ee14b
|
data/ext/yrb/Cargo.toml
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
[package]
|
2
2
|
name = "yrb"
|
3
|
-
version = "0.4.
|
3
|
+
version = "0.4.3"
|
4
4
|
authors = ["Hannes Moser <box@hannesmoser.at>", "Hannes Moser <hmoser@gitlab.com>"]
|
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.
|
11
|
-
magnus = { git = "https://github.com/matsadler/magnus", rev = "
|
10
|
+
lib0 = "0.15.0" # must match yrs version
|
11
|
+
magnus = { git = "https://github.com/matsadler/magnus", rev = "ab982c3643421b38f3293f1fe014aa373abfd6dc" }
|
12
12
|
thiserror = "1.0.38"
|
13
|
-
yrs = "0.
|
13
|
+
yrs = "0.15.0"
|
14
14
|
|
15
15
|
[dev-dependencies]
|
16
|
-
magnus = { git = "https://github.com/matsadler/magnus", rev = "
|
16
|
+
magnus = { git = "https://github.com/matsadler/magnus", rev = "ab982c3643421b38f3293f1fe014aa373abfd6dc", features = ["embed"] }
|
17
17
|
|
18
18
|
[lib]
|
19
19
|
name = "yrb"
|
data/ext/yrb/src/lib.rs
CHANGED
@@ -116,6 +116,9 @@ fn init() -> Result<(), Error> {
|
|
116
116
|
ydoc.define_private_method("ydoc_transact", method!(YDoc::ydoc_transact, 0))
|
117
117
|
.expect("cannot define private method: ydoc_transact");
|
118
118
|
|
119
|
+
ydoc.define_private_method("ydoc_observe_update", method!(YDoc::ydoc_observe_update, 1))
|
120
|
+
.expect("cannot define private method: ydoc_observe_update");
|
121
|
+
|
119
122
|
let ymap = module
|
120
123
|
.define_class("Map", Default::default())
|
121
124
|
.expect("cannot define class Y::Map");
|
data/ext/yrb/src/yany.rs
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
use lib0::any::Any;
|
2
|
+
use magnus::r_string::IntoRString;
|
2
3
|
use magnus::{RArray, RHash, RString, Value, QNIL};
|
3
4
|
use std::borrow::Borrow;
|
4
5
|
use std::ops::{Deref, DerefMut};
|
@@ -37,7 +38,7 @@ impl TryInto<Value> for YAny {
|
|
37
38
|
Any::Bool(v) => Ok(Value::from(v)),
|
38
39
|
Any::Number(v) => Ok(Value::from(v)),
|
39
40
|
Any::BigInt(v) => Ok(Value::from(v)),
|
40
|
-
Any::String(v) => Ok(Value::from(RString::from(v.
|
41
|
+
Any::String(v) => Ok(Value::from(RString::from(v.into_r_string()))),
|
41
42
|
Any::Buffer(v) => Ok(Value::from(RString::from_slice(v.borrow()))),
|
42
43
|
};
|
43
44
|
}
|
data/ext/yrb/src/yarray.rs
CHANGED
@@ -4,6 +4,7 @@ use lib0::any::Any;
|
|
4
4
|
use magnus::block::Proc;
|
5
5
|
use magnus::value::Qnil;
|
6
6
|
use magnus::{Error, RArray, RHash, Symbol, Value};
|
7
|
+
use std::borrow::Borrow;
|
7
8
|
use std::cell::RefCell;
|
8
9
|
use yrs::types::Change;
|
9
10
|
use yrs::{Array, ArrayRef, Observable};
|
@@ -112,9 +113,15 @@ impl YArray {
|
|
112
113
|
.partition(Result::is_ok);
|
113
114
|
|
114
115
|
if errors.is_empty() {
|
115
|
-
let
|
116
|
-
|
117
|
-
|
116
|
+
let args_changes = RArray::new();
|
117
|
+
for change in changes.iter() {
|
118
|
+
let c = *change.borrow().as_ref().unwrap();
|
119
|
+
args_changes
|
120
|
+
.push(c)
|
121
|
+
.expect("cannot push change event to args");
|
122
|
+
}
|
123
|
+
|
124
|
+
let args = (args_changes,);
|
118
125
|
let _ = block.call::<(RArray,), Qnil>(args);
|
119
126
|
// todo: make sure we respect the result and bubble up the
|
120
127
|
// error so that we can return as part of the Result
|
@@ -143,7 +150,7 @@ impl YArray {
|
|
143
150
|
let tx = tx.as_mut().unwrap();
|
144
151
|
|
145
152
|
let arr = self.0.borrow_mut();
|
146
|
-
arr.push_front(tx, avalue)
|
153
|
+
arr.push_front(tx, avalue);
|
147
154
|
}
|
148
155
|
pub(crate) fn yarray_remove(&self, transaction: &YTransaction, index: u32) {
|
149
156
|
let mut tx = transaction.transaction();
|
@@ -164,12 +171,13 @@ impl YArray {
|
|
164
171
|
let tx = transaction.transaction();
|
165
172
|
let tx = tx.as_ref().unwrap();
|
166
173
|
|
167
|
-
let
|
168
|
-
|
169
|
-
|
170
|
-
.
|
171
|
-
|
172
|
-
|
174
|
+
let r_arr = RArray::new();
|
175
|
+
for item in arr.iter(tx) {
|
176
|
+
let r_val = YValue::from(item);
|
177
|
+
let r_val = r_val.0.borrow().clone();
|
178
|
+
r_arr.push(r_val).expect("cannot push item event to array");
|
179
|
+
}
|
180
|
+
r_arr
|
173
181
|
}
|
174
182
|
pub(crate) fn yarray_unobserve(&self, subscription_id: u32) {
|
175
183
|
self.0.borrow_mut().unobserve(subscription_id);
|
data/ext/yrb/src/ydoc.rs
CHANGED
@@ -5,11 +5,13 @@ use crate::yxml_element::YXmlElement;
|
|
5
5
|
use crate::yxml_fragment::YXmlFragment;
|
6
6
|
use crate::yxml_text::YXmlText;
|
7
7
|
use crate::YTransaction;
|
8
|
-
use magnus::
|
8
|
+
use magnus::block::Proc;
|
9
|
+
use magnus::exception::runtime_error;
|
10
|
+
use magnus::{exception, Error, Integer, RArray, Value};
|
9
11
|
use std::borrow::Borrow;
|
10
12
|
use std::cell::RefCell;
|
11
13
|
use yrs::updates::decoder::Decode;
|
12
|
-
use yrs::{Doc, OffsetKind, Options, ReadTxn, StateVector, Transact};
|
14
|
+
use yrs::{Doc, OffsetKind, Options, ReadTxn, StateVector, SubscriptionId, Transact};
|
13
15
|
|
14
16
|
#[magnus::wrap(class = "Y::Doc")]
|
15
17
|
pub(crate) struct YDoc(pub(crate) RefCell<Doc>);
|
@@ -75,4 +77,20 @@ impl YDoc {
|
|
75
77
|
let transaction = doc.transact_mut();
|
76
78
|
YTransaction::from(transaction)
|
77
79
|
}
|
80
|
+
|
81
|
+
pub(crate) fn ydoc_observe_update(&self, block: Proc) -> Result<SubscriptionId, Error> {
|
82
|
+
self.0
|
83
|
+
.borrow()
|
84
|
+
.observe_update_v1(move |_tx, update_event| {
|
85
|
+
let update = update_event.update.to_vec();
|
86
|
+
let update = RArray::from_vec(update);
|
87
|
+
|
88
|
+
let args: (RArray,) = (update,);
|
89
|
+
block
|
90
|
+
.call::<(RArray,), Value>(args)
|
91
|
+
.expect("cannot call update block");
|
92
|
+
})
|
93
|
+
.map(|v| v.into())
|
94
|
+
.map_err(|err| Error::new(runtime_error(), err.to_string()))
|
95
|
+
}
|
78
96
|
}
|
data/ext/yrb/src/ymap.rs
CHANGED
@@ -27,7 +27,7 @@ impl YMap {
|
|
27
27
|
|
28
28
|
match indifferent_hash_key(key) {
|
29
29
|
None => false,
|
30
|
-
Some(k) => self.0.borrow().
|
30
|
+
Some(k) => self.0.borrow().contains_key(tx, k.as_str()),
|
31
31
|
}
|
32
32
|
}
|
33
33
|
pub(crate) fn ymap_each(&self, transaction: &YTransaction, proc: Proc) {
|
data/ext/yrb/src/ytext.rs
CHANGED
@@ -48,7 +48,7 @@ impl YText {
|
|
48
48
|
let yvalue = YValue::from(content);
|
49
49
|
let avalue = Any::from(yvalue);
|
50
50
|
|
51
|
-
self.0.borrow_mut().insert_embed(tx, index, avalue)
|
51
|
+
self.0.borrow_mut().insert_embed(tx, index, avalue);
|
52
52
|
}
|
53
53
|
pub(crate) fn ytext_insert_embed_with_attributes(
|
54
54
|
&self,
|
@@ -67,7 +67,7 @@ impl YText {
|
|
67
67
|
|
68
68
|
self.0
|
69
69
|
.borrow_mut()
|
70
|
-
.insert_embed_with_attributes(tx, index, avalue, a.0)
|
70
|
+
.insert_embed_with_attributes(tx, index, avalue, a.0);
|
71
71
|
}
|
72
72
|
pub(crate) fn ytext_insert_with_attributes(
|
73
73
|
&self,
|
data/ext/yrb/src/yvalue.rs
CHANGED
@@ -116,12 +116,13 @@ impl From<Any> for YValue {
|
|
116
116
|
Any::String(v) => YValue::from(v.into_string()),
|
117
117
|
Any::Buffer(v) => YValue::from(Value::from(v.into_vec())),
|
118
118
|
Any::Array(v) => {
|
119
|
-
let arr =
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
.
|
124
|
-
|
119
|
+
let arr = RArray::new();
|
120
|
+
for item in v.iter() {
|
121
|
+
let val = YValue::from(item.clone());
|
122
|
+
let val = val.0.borrow().clone();
|
123
|
+
arr.push(val).expect("cannot push item event to array");
|
124
|
+
}
|
125
|
+
YValue::from(arr)
|
125
126
|
}
|
126
127
|
Any::Map(v) => {
|
127
128
|
let map = v
|
@@ -146,14 +147,12 @@ impl From<YrsValue> for YValue {
|
|
146
147
|
YrsValue::YXmlText(text) => YValue::from(text),
|
147
148
|
YrsValue::YArray(val) => {
|
148
149
|
let tx = val.transact();
|
149
|
-
let arr = RArray::
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
.collect(),
|
156
|
-
);
|
150
|
+
let arr = RArray::new();
|
151
|
+
for item in val.iter(&tx) {
|
152
|
+
let val = YValue::from(item.clone());
|
153
|
+
let val = val.0.borrow().clone();
|
154
|
+
arr.push(val).expect("cannot push item event to array");
|
155
|
+
}
|
157
156
|
YValue::from(arr)
|
158
157
|
}
|
159
158
|
YrsValue::YMap(val) => {
|
data/ext/yrb/src/yxml_element.rs
CHANGED
@@ -107,15 +107,16 @@ impl YXmlElement {
|
|
107
107
|
for change in delta {
|
108
108
|
match change {
|
109
109
|
Change::Added(v) => {
|
110
|
-
let values =
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
.
|
110
|
+
let values = RArray::new();
|
111
|
+
for value in v.iter() {
|
112
|
+
let value = YValue::from(value.clone());
|
113
|
+
let value = value.0.borrow().clone();
|
114
|
+
values.push(value).expect("cannot push value to array");
|
115
|
+
}
|
115
116
|
|
116
117
|
let payload = RHash::new();
|
117
118
|
payload
|
118
|
-
.aset(change_added,
|
119
|
+
.aset(change_added, values)
|
119
120
|
.expect("cannot create change::added payload");
|
120
121
|
|
121
122
|
changes
|
data/ext/yrb/src/yxml_text.rs
CHANGED
@@ -72,11 +72,13 @@ impl YXmlText {
|
|
72
72
|
let yvalue = YValue::from(content);
|
73
73
|
let avalue = Any::from(yvalue);
|
74
74
|
|
75
|
-
map_rhash_to_attrs(attrs)
|
76
|
-
|
77
|
-
.
|
78
|
-
|
79
|
-
|
75
|
+
map_rhash_to_attrs(attrs)
|
76
|
+
.map(|a| {
|
77
|
+
self.0
|
78
|
+
.borrow_mut()
|
79
|
+
.insert_embed_with_attributes(tx, index, avalue, a)
|
80
|
+
})
|
81
|
+
.map(|_| ())
|
80
82
|
}
|
81
83
|
pub(crate) fn yxml_text_insert_embed(
|
82
84
|
&self,
|
@@ -89,7 +91,7 @@ impl YXmlText {
|
|
89
91
|
|
90
92
|
self.0
|
91
93
|
.borrow_mut()
|
92
|
-
.insert_embed(tx, index, Any::from(YValue::from(embed)))
|
94
|
+
.insert_embed(tx, index, Any::from(YValue::from(embed)));
|
93
95
|
}
|
94
96
|
pub(crate) fn yxml_text_insert_with_attributes(
|
95
97
|
&self,
|
data/lib/2.7/yrb.so
CHANGED
Binary file
|
data/lib/3.0/yrb.so
CHANGED
Binary file
|
data/lib/3.1/yrb.so
CHANGED
Binary file
|
data/lib/y/doc.rb
CHANGED
@@ -19,6 +19,22 @@ module Y
|
|
19
19
|
ZERO_STATE = [0].freeze
|
20
20
|
private_constant :ZERO_STATE
|
21
21
|
|
22
|
+
# Attach a listener to document changes. If one of the data structures is
|
23
|
+
# changes, the block is called with the update as its only argument.
|
24
|
+
#
|
25
|
+
# @yield [update] Called when document is updated
|
26
|
+
# @yieldparam [Array<Integer>] update The encoded document updates
|
27
|
+
|
28
|
+
# Example: Attach listener to document changes
|
29
|
+
# doc = described_class.new
|
30
|
+
# doc.attach { |update| pp update }
|
31
|
+
#
|
32
|
+
# text = doc.get_text("my text")
|
33
|
+
# text << "1"
|
34
|
+
def attach(&block)
|
35
|
+
ydoc_observe_update(block)
|
36
|
+
end
|
37
|
+
|
22
38
|
# Commit current transaction
|
23
39
|
#
|
24
40
|
# This is a convenience method that invokes {Y::Transaction#commit} on the
|
@@ -222,5 +238,11 @@ module Y
|
|
222
238
|
#
|
223
239
|
# @return [Y::XMLText]
|
224
240
|
# @!visibility private
|
241
|
+
|
242
|
+
# @!method ydoc_observe_update(block)
|
243
|
+
# Creates a subscription to observe changes to the document
|
244
|
+
# @param [Proc] block
|
245
|
+
# @return [Integer]
|
246
|
+
# @!visibility private
|
225
247
|
end
|
226
248
|
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.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: x86_64-linux
|
6
6
|
authors:
|
7
7
|
- Hannes Moser
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -30,42 +30,42 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.9.
|
33
|
+
version: 0.9.56
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.9.
|
40
|
+
version: 0.9.56
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake-compiler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.2.
|
47
|
+
version: 1.2.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.2.
|
54
|
+
version: 1.2.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake-compiler-dock
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.3.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: 1.3.0
|
69
69
|
description: Ruby bindings for yrs. Yrs "wires" is a Rust port of the Yjs framework.
|
70
70
|
email:
|
71
71
|
- hmoser@gitlab.com
|