y-rb 0.3.2-aarch64-linux → 0.4.0-aarch64-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/awareness.rs +5 -5
- data/ext/yrb/src/lib.rs +81 -35
- data/ext/yrb/src/yarray.rs +68 -33
- data/ext/yrb/src/ydoc.rs +53 -10
- data/ext/yrb/src/ymap.rs +47 -24
- data/ext/yrb/src/ytext.rs +55 -60
- data/ext/yrb/src/ytransaction.rs +71 -23
- data/ext/yrb/src/yvalue.rs +26 -7
- data/ext/yrb/src/yxml_element.rs +133 -72
- data/ext/yrb/src/yxml_fragment.rs +16 -0
- data/ext/yrb/src/yxml_text.rs +96 -56
- 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/array.rb +114 -100
- data/lib/y/awareness.rb +40 -14
- data/lib/y/doc.rb +77 -71
- data/lib/y/map.rb +39 -42
- data/lib/y/text.rb +92 -96
- data/lib/y/transaction.rb +31 -13
- data/lib/y/version.rb +1 -1
- data/lib/y/xml.rb +259 -227
- data/lib/y-rb.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6676f1ce2df0d862b3d52f031fcf46dae59241d54cac970ea6a45af280351b05
|
4
|
+
data.tar.gz: 8e33aba267f00c3bce89d3c8bdd29fe71f5d25e35c64b628e56653f8debea55f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5b5b471797a1dde9b6de96a2eaa99ceeb16b78ddecca9de723c782f734a8faae5cd9fcbca40e78c0307fadd5c129bd65d6722cf2e089c35ab80775e25abc9c1
|
7
|
+
data.tar.gz: d20bc09bb6d4fedc1e683f1db8ec683fcc4d8fc5d8ba236553c33549dd8ded852da8acec7408cad5c271aafb2693dec9a6b3a1efd9d2eb2bece29ee935bff851
|
data/ext/yrb/Cargo.toml
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
[package]
|
2
2
|
name = "yrb"
|
3
|
-
version = "0.
|
3
|
+
version = "0.4.0"
|
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 = {
|
10
|
+
lib0 = "0.14.1" # must match yrs version
|
11
|
+
magnus = { version = "0.4.3" }
|
12
12
|
thiserror = "1.0.37"
|
13
|
-
yrs = "0.
|
13
|
+
yrs = "0.14.1"
|
14
14
|
|
15
15
|
[dev-dependencies]
|
16
|
-
magnus = {
|
16
|
+
magnus = { version = "0.4.3", features = ["embed"] }
|
17
17
|
|
18
18
|
[lib]
|
19
19
|
name = "yrb"
|
data/ext/yrb/src/awareness.rs
CHANGED
@@ -64,7 +64,7 @@ impl Awareness {
|
|
64
64
|
|
65
65
|
/// Returns a globally unique client ID of an underlying [Doc].
|
66
66
|
pub fn client_id(&self) -> ClientID {
|
67
|
-
self.doc.client_id
|
67
|
+
self.doc.client_id()
|
68
68
|
}
|
69
69
|
|
70
70
|
/// Returns a state map of all of the clients tracked by current [Awareness] instance. Those
|
@@ -76,7 +76,7 @@ impl Awareness {
|
|
76
76
|
|
77
77
|
/// Returns a JSON string state representation of a current [Awareness] instance.
|
78
78
|
pub fn local_state(&self) -> Option<&str> {
|
79
|
-
Some(self.states.get(&self.doc.client_id)?.as_str())
|
79
|
+
Some(self.states.get(&self.doc.client_id())?.as_str())
|
80
80
|
}
|
81
81
|
|
82
82
|
/// Sets a current [Awareness] instance state to a corresponding JSON string. This state will
|
@@ -84,7 +84,7 @@ impl Awareness {
|
|
84
84
|
/// to be emitted if current instance was created using [Awareness::with_observer] method.
|
85
85
|
///
|
86
86
|
pub fn set_local_state<S: Into<String>>(&mut self, json: S) {
|
87
|
-
let client_id = self.doc.client_id;
|
87
|
+
let client_id = self.doc.client_id();
|
88
88
|
self.update_meta(client_id);
|
89
89
|
let new: String = json.into();
|
90
90
|
match self.states.entry(client_id) {
|
@@ -120,7 +120,7 @@ impl Awareness {
|
|
120
120
|
/// Clears out a state of a current client (see: [Awareness::client_id]),
|
121
121
|
/// effectively marking it as disconnected.
|
122
122
|
pub fn clean_local_state(&mut self) {
|
123
|
-
let client_id = self.doc.client_id;
|
123
|
+
let client_id = self.doc.client_id();
|
124
124
|
self.remove_state(client_id);
|
125
125
|
}
|
126
126
|
|
@@ -192,7 +192,7 @@ impl Awareness {
|
|
192
192
|
if is_new || is_removed {
|
193
193
|
if is_null {
|
194
194
|
// never let a remote client remove this local state
|
195
|
-
if client_id == self.doc.client_id
|
195
|
+
if client_id == self.doc.client_id()
|
196
196
|
&& self.states.get(&client_id).is_some()
|
197
197
|
{
|
198
198
|
// remote client removed the local state. Do not remote state. Broadcast a message indicating
|
data/ext/yrb/src/lib.rs
CHANGED
@@ -22,6 +22,7 @@ mod ytext;
|
|
22
22
|
mod ytransaction;
|
23
23
|
mod yvalue;
|
24
24
|
mod yxml_element;
|
25
|
+
mod yxml_fragment;
|
25
26
|
mod yxml_text;
|
26
27
|
|
27
28
|
#[magnus::init]
|
@@ -33,10 +34,10 @@ fn init() -> Result<(), Error> {
|
|
33
34
|
.expect("cannot find class Y::Array");
|
34
35
|
|
35
36
|
yarray
|
36
|
-
.define_private_method("yarray_each", method!(YArray::yarray_each,
|
37
|
+
.define_private_method("yarray_each", method!(YArray::yarray_each, 2))
|
37
38
|
.expect("cannot define private method: yarray_each");
|
38
39
|
yarray
|
39
|
-
.define_private_method("yarray_get", method!(YArray::yarray_get,
|
40
|
+
.define_private_method("yarray_get", method!(YArray::yarray_get, 2))
|
40
41
|
.expect("cannot define private method: yarray_get");
|
41
42
|
yarray
|
42
43
|
.define_private_method("yarray_insert", method!(YArray::yarray_insert, 3))
|
@@ -48,7 +49,7 @@ fn init() -> Result<(), Error> {
|
|
48
49
|
)
|
49
50
|
.expect("cannot define private method: yarray_insert_range");
|
50
51
|
yarray
|
51
|
-
.define_private_method("yarray_length", method!(YArray::yarray_length,
|
52
|
+
.define_private_method("yarray_length", method!(YArray::yarray_length, 1))
|
52
53
|
.expect("cannot define private method: yarray_length");
|
53
54
|
yarray
|
54
55
|
.define_private_method("yarray_observe", method!(YArray::yarray_observe, 1))
|
@@ -69,7 +70,7 @@ fn init() -> Result<(), Error> {
|
|
69
70
|
)
|
70
71
|
.expect("cannot define private method: yarray_remove_range");
|
71
72
|
yarray
|
72
|
-
.define_private_method("yarray_to_a", method!(YArray::yarray_to_a,
|
73
|
+
.define_private_method("yarray_to_a", method!(YArray::yarray_to_a, 1))
|
73
74
|
.expect("cannot define private method: yarray_to_a");
|
74
75
|
yarray
|
75
76
|
.define_private_method("yarray_unobserve", method!(YArray::yarray_unobserve, 1))
|
@@ -80,10 +81,40 @@ fn init() -> Result<(), Error> {
|
|
80
81
|
.expect("cannot define class Y::Doc");
|
81
82
|
ydoc.define_singleton_method("new", function!(YDoc::ydoc_new, -1))
|
82
83
|
.expect("cannot define singleton method: ydoc_new");
|
84
|
+
ydoc.define_private_method("ydoc_encode_diff_v1", method!(YDoc::ydoc_encode_diff_v1, 2))
|
85
|
+
.expect("cannot define private method: ydoc_encode_diff_v1");
|
86
|
+
ydoc.define_private_method(
|
87
|
+
"ydoc_get_or_insert_array",
|
88
|
+
method!(YDoc::ydoc_get_or_insert_array, 1),
|
89
|
+
)
|
90
|
+
.expect("cannot define private method: ydoc_get_or_insert_array");
|
91
|
+
ydoc.define_private_method(
|
92
|
+
"ydoc_get_or_insert_map",
|
93
|
+
method!(YDoc::ydoc_get_or_insert_map, 1),
|
94
|
+
)
|
95
|
+
.expect("cannot define private method: ydoc_get_or_insert_map");
|
96
|
+
ydoc.define_private_method(
|
97
|
+
"ydoc_get_or_insert_text",
|
98
|
+
method!(YDoc::ydoc_get_or_insert_text, 1),
|
99
|
+
)
|
100
|
+
.expect("cannot define private method: ydoc_get_or_insert_text");
|
101
|
+
ydoc.define_private_method(
|
102
|
+
"ydoc_get_or_insert_xml_element",
|
103
|
+
method!(YDoc::ydoc_get_or_insert_xml_element, 1),
|
104
|
+
)
|
105
|
+
.expect("cannot define private method: ydoc_get_or_insert_xml_element");
|
106
|
+
ydoc.define_private_method(
|
107
|
+
"ydoc_get_or_insert_xml_fragment",
|
108
|
+
method!(YDoc::ydoc_get_or_insert_xml_fragment, 1),
|
109
|
+
)
|
110
|
+
.expect("cannot define private method: ydoc_get_or_insert_xml_fragment");
|
111
|
+
ydoc.define_private_method(
|
112
|
+
"ydoc_get_or_insert_xml_text",
|
113
|
+
method!(YDoc::ydoc_get_or_insert_xml_text, 1),
|
114
|
+
)
|
115
|
+
.expect("cannot define private method: ydoc_get_or_insert_xml_text");
|
83
116
|
ydoc.define_private_method("ydoc_transact", method!(YDoc::ydoc_transact, 0))
|
84
117
|
.expect("cannot define private method: ydoc_transact");
|
85
|
-
ydoc.define_private_method("ydoc_encode_diff_v1", method!(YDoc::ydoc_encode_diff_v1, 1))
|
86
|
-
.expect("cannot define private method: ydoc_encode_diff_v1");
|
87
118
|
|
88
119
|
let ymap = module
|
89
120
|
.define_class("Map", Default::default())
|
@@ -91,11 +122,11 @@ fn init() -> Result<(), Error> {
|
|
91
122
|
|
92
123
|
ymap.define_private_method("ymap_clear", method!(YMap::ymap_clear, 1))
|
93
124
|
.expect("cannot define private method: ymap_clear");
|
94
|
-
ymap.define_private_method("ymap_contains", method!(YMap::ymap_contains,
|
125
|
+
ymap.define_private_method("ymap_contains", method!(YMap::ymap_contains, 2))
|
95
126
|
.expect("cannot define private method: ymap_contains");
|
96
|
-
ymap.define_private_method("ymap_each", method!(YMap::ymap_each,
|
127
|
+
ymap.define_private_method("ymap_each", method!(YMap::ymap_each, 2))
|
97
128
|
.expect("cannot define private method: ymap_each");
|
98
|
-
ymap.define_private_method("ymap_get", method!(YMap::ymap_get,
|
129
|
+
ymap.define_private_method("ymap_get", method!(YMap::ymap_get, 2))
|
99
130
|
.expect("cannot define private method: ymap_get");
|
100
131
|
ymap.define_private_method("ymap_insert", method!(YMap::ymap_insert, 3))
|
101
132
|
.expect("cannot define private method: ymap_insert");
|
@@ -103,9 +134,9 @@ fn init() -> Result<(), Error> {
|
|
103
134
|
.expect("cannot define private method: ymap_observe");
|
104
135
|
ymap.define_private_method("ymap_remove", method!(YMap::ymap_remove, 2))
|
105
136
|
.expect("cannot define private method: ymap_remove");
|
106
|
-
ymap.define_private_method("ymap_size", method!(YMap::ymap_size,
|
137
|
+
ymap.define_private_method("ymap_size", method!(YMap::ymap_size, 1))
|
107
138
|
.expect("cannot define private method: ymap_size");
|
108
|
-
ymap.define_private_method("ymap_to_h", method!(YMap::ymap_to_h,
|
139
|
+
ymap.define_private_method("ymap_to_h", method!(YMap::ymap_to_h, 1))
|
109
140
|
.expect("cannot define private method: ymap_to_h");
|
110
141
|
ymap.define_private_method("ymap_unobserve", method!(YMap::ymap_unobserve, 1))
|
111
142
|
.expect("cannot define private method: ymap_unobserve");
|
@@ -126,6 +157,9 @@ fn init() -> Result<(), Error> {
|
|
126
157
|
method!(YTransaction::ytransaction_commit, 0),
|
127
158
|
)
|
128
159
|
.expect("cannot define private method: ytransaction_commit");
|
160
|
+
ytransaction
|
161
|
+
.define_method("free", method!(YTransaction::ytransaction_free, 0))
|
162
|
+
.expect("");
|
129
163
|
ytransaction
|
130
164
|
.define_private_method(
|
131
165
|
"ytransaction_get_array",
|
@@ -137,7 +171,7 @@ fn init() -> Result<(), Error> {
|
|
137
171
|
"ytransaction_get_map",
|
138
172
|
method!(YTransaction::ytransaction_get_map, 1),
|
139
173
|
)
|
140
|
-
.expect("cannot define private method:
|
174
|
+
.expect("cannot define private method: ytransaction_get_map");
|
141
175
|
ytransaction
|
142
176
|
.define_private_method(
|
143
177
|
"ytransaction_get_text",
|
@@ -150,6 +184,12 @@ fn init() -> Result<(), Error> {
|
|
150
184
|
method!(YTransaction::ytransaction_get_xml_element, 1),
|
151
185
|
)
|
152
186
|
.expect("cannot define private method: ytransaction_get_xml_element");
|
187
|
+
ytransaction
|
188
|
+
.define_private_method(
|
189
|
+
"ytransaction_get_xml_fragment",
|
190
|
+
method!(YTransaction::ytransaction_get_xml_fragment, 1),
|
191
|
+
)
|
192
|
+
.expect("cannot define private method: ytransaction_get_xml_fragment");
|
153
193
|
ytransaction
|
154
194
|
.define_private_method(
|
155
195
|
"ytransaction_get_xml_text",
|
@@ -189,7 +229,7 @@ fn init() -> Result<(), Error> {
|
|
189
229
|
)
|
190
230
|
.expect("cannot define private method: ytext_insert_with_attributes");
|
191
231
|
ytext
|
192
|
-
.define_private_method("ytext_length", method!(YText::ytext_length,
|
232
|
+
.define_private_method("ytext_length", method!(YText::ytext_length, 1))
|
193
233
|
.expect("cannot define private method: ytext_length");
|
194
234
|
ytext
|
195
235
|
.define_private_method("ytext_observe", method!(YText::ytext_observe, 1))
|
@@ -201,7 +241,7 @@ fn init() -> Result<(), Error> {
|
|
201
241
|
.define_private_method("ytext_remove_range", method!(YText::ytext_remove_range, 3))
|
202
242
|
.expect("cannot define private method: ytext_remove_range");
|
203
243
|
ytext
|
204
|
-
.define_private_method("ytext_to_s", method!(YText::ytext_to_s,
|
244
|
+
.define_private_method("ytext_to_s", method!(YText::ytext_to_s, 1))
|
205
245
|
.expect("cannot define private method: ytext_to_s");
|
206
246
|
ytext
|
207
247
|
.define_private_method("ytext_unobserve", method!(YText::ytext_unobserve, 1))
|
@@ -214,25 +254,25 @@ fn init() -> Result<(), Error> {
|
|
214
254
|
yxml_element
|
215
255
|
.define_private_method(
|
216
256
|
"yxml_element_attributes",
|
217
|
-
method!(YXmlElement::yxml_element_attributes,
|
257
|
+
method!(YXmlElement::yxml_element_attributes, 1),
|
218
258
|
)
|
219
259
|
.expect("cannot define private method: yxml_element_attributes");
|
220
260
|
yxml_element
|
221
261
|
.define_private_method(
|
222
262
|
"yxml_element_first_child",
|
223
|
-
method!(YXmlElement::yxml_element_first_child,
|
263
|
+
method!(YXmlElement::yxml_element_first_child, 1),
|
224
264
|
)
|
225
265
|
.expect("cannot define private method: yxml_element_first_child");
|
226
266
|
yxml_element
|
227
267
|
.define_private_method(
|
228
268
|
"yxml_element_get",
|
229
|
-
method!(YXmlElement::yxml_element_get,
|
269
|
+
method!(YXmlElement::yxml_element_get, 2),
|
230
270
|
)
|
231
271
|
.expect("cannot define private method: yxml_element_get");
|
232
272
|
yxml_element
|
233
273
|
.define_private_method(
|
234
274
|
"yxml_element_get_attribute",
|
235
|
-
method!(YXmlElement::yxml_element_get_attribute,
|
275
|
+
method!(YXmlElement::yxml_element_get_attribute, 2),
|
236
276
|
)
|
237
277
|
.expect("cannot define private method: yxml_element_get_attribute");
|
238
278
|
yxml_element
|
@@ -250,13 +290,13 @@ fn init() -> Result<(), Error> {
|
|
250
290
|
yxml_element
|
251
291
|
.define_private_method(
|
252
292
|
"yxml_element_insert_text",
|
253
|
-
method!(YXmlElement::yxml_element_insert_text,
|
293
|
+
method!(YXmlElement::yxml_element_insert_text, 3),
|
254
294
|
)
|
255
295
|
.expect("cannot define private method: yxml_element_insert_text");
|
256
296
|
yxml_element
|
257
297
|
.define_private_method(
|
258
298
|
"yxml_element_next_sibling",
|
259
|
-
method!(YXmlElement::yxml_element_next_sibling,
|
299
|
+
method!(YXmlElement::yxml_element_next_sibling, 1),
|
260
300
|
)
|
261
301
|
.expect("cannot define private method: yxml_element_next_sibling");
|
262
302
|
yxml_element
|
@@ -274,31 +314,31 @@ fn init() -> Result<(), Error> {
|
|
274
314
|
yxml_element
|
275
315
|
.define_private_method(
|
276
316
|
"yxml_element_prev_sibling",
|
277
|
-
method!(YXmlElement::yxml_element_prev_sibling,
|
317
|
+
method!(YXmlElement::yxml_element_prev_sibling, 1),
|
278
318
|
)
|
279
319
|
.expect("cannot define private method: yxml_element_prev_sibling");
|
280
320
|
yxml_element
|
281
321
|
.define_private_method(
|
282
|
-
"
|
322
|
+
"yxml_element_push_element_back",
|
283
323
|
method!(YXmlElement::yxml_element_push_element_back, 2),
|
284
324
|
)
|
285
|
-
.expect("cannot define private method:
|
325
|
+
.expect("cannot define private method: yxml_element_push_element_back");
|
286
326
|
yxml_element
|
287
327
|
.define_private_method(
|
288
|
-
"
|
328
|
+
"yxml_element_push_element_front",
|
289
329
|
method!(YXmlElement::yxml_element_push_element_front, 2),
|
290
330
|
)
|
291
|
-
.expect("cannot define private method:
|
331
|
+
.expect("cannot define private method: yxml_element_push_element_front");
|
292
332
|
yxml_element
|
293
333
|
.define_private_method(
|
294
334
|
"yxml_element_push_text_back",
|
295
|
-
method!(YXmlElement::yxml_element_push_text_back,
|
335
|
+
method!(YXmlElement::yxml_element_push_text_back, 2),
|
296
336
|
)
|
297
337
|
.expect("cannot define private method: yxml_element_push_text_back");
|
298
338
|
yxml_element
|
299
339
|
.define_private_method(
|
300
340
|
"yxml_element_push_text_front",
|
301
|
-
method!(YXmlElement::yxml_element_push_text_front,
|
341
|
+
method!(YXmlElement::yxml_element_push_text_front, 2),
|
302
342
|
)
|
303
343
|
.expect("cannot define private method: yxml_element_push_text_front");
|
304
344
|
yxml_element
|
@@ -313,10 +353,16 @@ fn init() -> Result<(), Error> {
|
|
313
353
|
method!(YXmlElement::yxml_element_remove_range, 3),
|
314
354
|
)
|
315
355
|
.expect("cannot define private method: yxml_element_remove_range");
|
356
|
+
yxml_element
|
357
|
+
.define_private_method(
|
358
|
+
"yxml_element_siblings",
|
359
|
+
method!(YXmlElement::yxml_element_siblings, 1),
|
360
|
+
)
|
361
|
+
.expect("cannot define private method: yxml_element_siblings");
|
316
362
|
yxml_element
|
317
363
|
.define_private_method(
|
318
364
|
"yxml_element_size",
|
319
|
-
method!(YXmlElement::yxml_element_size,
|
365
|
+
method!(YXmlElement::yxml_element_size, 1),
|
320
366
|
)
|
321
367
|
.expect("cannot define private method: yxml_element_size");
|
322
368
|
yxml_element
|
@@ -328,7 +374,7 @@ fn init() -> Result<(), Error> {
|
|
328
374
|
yxml_element
|
329
375
|
.define_private_method(
|
330
376
|
"yxml_element_to_s",
|
331
|
-
method!(YXmlElement::yxml_element_to_s,
|
377
|
+
method!(YXmlElement::yxml_element_to_s, 1),
|
332
378
|
)
|
333
379
|
.expect("cannot define private method: yxml_element_to_s");
|
334
380
|
yxml_element
|
@@ -345,7 +391,7 @@ fn init() -> Result<(), Error> {
|
|
345
391
|
yxml_text
|
346
392
|
.define_private_method(
|
347
393
|
"yxml_text_attributes",
|
348
|
-
method!(YXmlText::yxml_text_attributes,
|
394
|
+
method!(YXmlText::yxml_text_attributes, 1),
|
349
395
|
)
|
350
396
|
.expect("cannot define private method: yxml_text_attributes");
|
351
397
|
yxml_text
|
@@ -354,7 +400,7 @@ fn init() -> Result<(), Error> {
|
|
354
400
|
yxml_text
|
355
401
|
.define_private_method(
|
356
402
|
"yxml_text_get_attribute",
|
357
|
-
method!(YXmlText::yxml_text_get_attribute,
|
403
|
+
method!(YXmlText::yxml_text_get_attribute, 2),
|
358
404
|
)
|
359
405
|
.expect("cannot define private method: yxml_text_get_attribute");
|
360
406
|
yxml_text
|
@@ -385,12 +431,12 @@ fn init() -> Result<(), Error> {
|
|
385
431
|
)
|
386
432
|
.expect("cannot define private method: yxml_text_insert_embed");
|
387
433
|
yxml_text
|
388
|
-
.define_private_method("yxml_text_length", method!(YXmlText::yxml_text_length,
|
434
|
+
.define_private_method("yxml_text_length", method!(YXmlText::yxml_text_length, 1))
|
389
435
|
.expect("cannot define private method: yxml_text_length");
|
390
436
|
yxml_text
|
391
437
|
.define_private_method(
|
392
438
|
"yxml_text_next_sibling",
|
393
|
-
method!(YXmlText::yxml_text_next_sibling,
|
439
|
+
method!(YXmlText::yxml_text_next_sibling, 1),
|
394
440
|
)
|
395
441
|
.expect("cannot define private method: yxml_text_next_sibling");
|
396
442
|
yxml_text
|
@@ -399,7 +445,7 @@ fn init() -> Result<(), Error> {
|
|
399
445
|
yxml_text
|
400
446
|
.define_private_method(
|
401
447
|
"yxml_text_prev_sibling",
|
402
|
-
method!(YXmlText::yxml_text_prev_sibling,
|
448
|
+
method!(YXmlText::yxml_text_prev_sibling, 1),
|
403
449
|
)
|
404
450
|
.expect("cannot define private method: yxml_text_prev_sibling");
|
405
451
|
yxml_text
|
@@ -412,7 +458,7 @@ fn init() -> Result<(), Error> {
|
|
412
458
|
)
|
413
459
|
.expect("cannot define private method: yxml_text_remove_range");
|
414
460
|
yxml_text
|
415
|
-
.define_private_method("yxml_text_to_s", method!(YXmlText::yxml_text_to_s,
|
461
|
+
.define_private_method("yxml_text_to_s", method!(YXmlText::yxml_text_to_s, 1))
|
416
462
|
.expect("cannot define private method: yxml_text_to_s");
|
417
463
|
|
418
464
|
let yawareness = module
|
data/ext/yrb/src/yarray.rs
CHANGED
@@ -1,37 +1,50 @@
|
|
1
|
+
use crate::ytransaction::YTransaction;
|
1
2
|
use crate::yvalue::YValue;
|
2
|
-
use crate::YTransaction;
|
3
3
|
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
7
|
use std::cell::RefCell;
|
8
8
|
use yrs::types::Change;
|
9
|
-
use yrs::Array;
|
9
|
+
use yrs::{Array, ArrayRef, Observable};
|
10
10
|
|
11
11
|
#[magnus::wrap(class = "Y::Array")]
|
12
|
-
pub(crate) struct YArray(pub(crate) RefCell<
|
12
|
+
pub(crate) struct YArray(pub(crate) RefCell<ArrayRef>);
|
13
13
|
|
14
14
|
/// SAFETY: This is safe because we only access this data when the GVL is held.
|
15
15
|
unsafe impl Send for YArray {}
|
16
16
|
|
17
17
|
impl YArray {
|
18
|
-
pub(crate) fn yarray_each(&self, block: Proc) {
|
19
|
-
|
18
|
+
pub(crate) fn yarray_each(&self, transaction: &YTransaction, block: Proc) -> Result<(), Error> {
|
19
|
+
let tx = transaction.transaction();
|
20
|
+
let tx = tx.as_ref().unwrap();
|
21
|
+
|
22
|
+
let arr = self.0.borrow();
|
23
|
+
arr.iter(tx).for_each(|val| {
|
20
24
|
let yvalue = YValue::from(val);
|
21
25
|
let args = (yvalue.into(),);
|
22
26
|
let _ = block.call::<(Value,), Qnil>(args);
|
23
27
|
});
|
28
|
+
|
29
|
+
Ok(())
|
24
30
|
}
|
25
|
-
pub(crate) fn yarray_get(&self, index: u32) -> Value {
|
26
|
-
let
|
31
|
+
pub(crate) fn yarray_get(&self, transaction: &YTransaction, index: u32) -> Value {
|
32
|
+
let tx = transaction.transaction();
|
33
|
+
let tx = tx.as_ref().unwrap();
|
34
|
+
|
35
|
+
let arr = self.0.borrow();
|
36
|
+
let v = arr.get(tx, index).unwrap();
|
27
37
|
YValue::from(v).into()
|
28
38
|
}
|
29
39
|
pub(crate) fn yarray_insert(&self, transaction: &YTransaction, index: u32, value: Value) {
|
30
40
|
let yvalue = YValue::from(value);
|
31
41
|
let avalue = Any::from(yvalue);
|
32
|
-
|
33
|
-
|
34
|
-
|
42
|
+
|
43
|
+
let mut tx = transaction.transaction();
|
44
|
+
let tx = tx.as_mut().unwrap();
|
45
|
+
|
46
|
+
let arr = self.0.borrow_mut();
|
47
|
+
arr.insert(tx, index, avalue);
|
35
48
|
}
|
36
49
|
pub(crate) fn yarray_insert_range(
|
37
50
|
&self,
|
@@ -39,18 +52,24 @@ impl YArray {
|
|
39
52
|
index: u32,
|
40
53
|
values: RArray,
|
41
54
|
) {
|
42
|
-
let arr
|
55
|
+
let arr = self.0.borrow_mut();
|
56
|
+
let mut tx = transaction.transaction();
|
57
|
+
let tx = tx.as_mut().unwrap();
|
58
|
+
|
59
|
+
let add_values: Vec<Any> = values
|
43
60
|
.each()
|
44
61
|
.into_iter()
|
45
62
|
.map(|value| YValue::from(value.unwrap()).into())
|
46
63
|
.collect();
|
47
64
|
|
48
|
-
|
49
|
-
.borrow_mut()
|
50
|
-
.insert_range(&mut *transaction.0.borrow_mut(), index, arr);
|
65
|
+
arr.insert_range(tx, index, add_values)
|
51
66
|
}
|
52
|
-
pub(crate) fn yarray_length(&self) -> u32 {
|
53
|
-
|
67
|
+
pub(crate) fn yarray_length(&self, transaction: &YTransaction) -> u32 {
|
68
|
+
let arr = self.0.borrow();
|
69
|
+
let tx = transaction.transaction();
|
70
|
+
let tx = tx.as_ref().unwrap();
|
71
|
+
|
72
|
+
arr.len(tx)
|
54
73
|
}
|
55
74
|
pub(crate) fn yarray_observe(&self, block: Proc) -> Result<u32, Error> {
|
56
75
|
let change_added = Symbol::new("added").to_static();
|
@@ -111,32 +130,42 @@ impl YArray {
|
|
111
130
|
pub(crate) fn yarray_push_back(&self, transaction: &YTransaction, value: Value) {
|
112
131
|
let yvalue = YValue::from(value);
|
113
132
|
let avalue = Any::from(yvalue);
|
114
|
-
|
115
|
-
|
116
|
-
|
133
|
+
let mut tx = transaction.transaction();
|
134
|
+
let tx = tx.as_mut().unwrap();
|
135
|
+
|
136
|
+
self.0.borrow_mut().push_back(tx, avalue);
|
117
137
|
}
|
118
138
|
pub(crate) fn yarray_push_front(&self, transaction: &YTransaction, value: Value) {
|
119
139
|
let yvalue = YValue::from(value);
|
120
140
|
let avalue = Any::from(yvalue);
|
121
|
-
|
122
|
-
|
123
|
-
|
141
|
+
|
142
|
+
let mut tx = transaction.transaction();
|
143
|
+
let tx = tx.as_mut().unwrap();
|
144
|
+
|
145
|
+
let arr = self.0.borrow_mut();
|
146
|
+
arr.push_front(tx, avalue)
|
124
147
|
}
|
125
148
|
pub(crate) fn yarray_remove(&self, transaction: &YTransaction, index: u32) {
|
126
|
-
|
127
|
-
|
128
|
-
|
149
|
+
let mut tx = transaction.transaction();
|
150
|
+
let tx = tx.as_mut().unwrap();
|
151
|
+
|
152
|
+
let arr = self.0.borrow_mut();
|
153
|
+
arr.remove(tx, index)
|
129
154
|
}
|
130
155
|
pub(crate) fn yarray_remove_range(&self, transaction: &YTransaction, index: u32, len: u32) {
|
131
|
-
|
132
|
-
|
133
|
-
|
156
|
+
let mut tx = transaction.transaction();
|
157
|
+
let tx = tx.as_mut().unwrap();
|
158
|
+
|
159
|
+
let arr = self.0.borrow_mut();
|
160
|
+
arr.remove_range(tx, index, len)
|
134
161
|
}
|
135
|
-
pub(crate) fn yarray_to_a(&self) -> RArray {
|
136
|
-
let arr = self
|
137
|
-
|
138
|
-
|
139
|
-
|
162
|
+
pub(crate) fn yarray_to_a(&self, transaction: &YTransaction) -> RArray {
|
163
|
+
let arr = self.0.borrow();
|
164
|
+
let tx = transaction.transaction();
|
165
|
+
let tx = tx.as_ref().unwrap();
|
166
|
+
|
167
|
+
let arr = arr
|
168
|
+
.iter(tx)
|
140
169
|
.map(|v| YValue::from(v).into())
|
141
170
|
.collect::<Vec<Value>>();
|
142
171
|
|
@@ -146,3 +175,9 @@ impl YArray {
|
|
146
175
|
self.0.borrow_mut().unobserve(subscription_id);
|
147
176
|
}
|
148
177
|
}
|
178
|
+
|
179
|
+
impl From<ArrayRef> for YArray {
|
180
|
+
fn from(v: ArrayRef) -> Self {
|
181
|
+
YArray(RefCell::from(v))
|
182
|
+
}
|
183
|
+
}
|
data/ext/yrb/src/ydoc.rs
CHANGED
@@ -1,35 +1,78 @@
|
|
1
|
+
use crate::yarray::YArray;
|
2
|
+
use crate::ymap::YMap;
|
3
|
+
use crate::ytext::YText;
|
4
|
+
use crate::yxml_element::YXmlElement;
|
5
|
+
use crate::yxml_fragment::YXmlFragment;
|
6
|
+
use crate::yxml_text::YXmlText;
|
1
7
|
use crate::YTransaction;
|
2
8
|
use magnus::{Error, Integer, Value};
|
9
|
+
use std::borrow::Borrow;
|
3
10
|
use std::cell::RefCell;
|
4
11
|
use yrs::updates::decoder::Decode;
|
5
|
-
use yrs::{Doc, OffsetKind, Options, StateVector};
|
12
|
+
use yrs::{Doc, OffsetKind, Options, ReadTxn, StateVector, Transact};
|
6
13
|
|
7
14
|
#[magnus::wrap(class = "Y::Doc")]
|
8
15
|
pub(crate) struct YDoc(pub(crate) RefCell<Doc>);
|
9
16
|
|
17
|
+
unsafe impl Send for YDoc {}
|
18
|
+
|
10
19
|
impl YDoc {
|
11
20
|
pub(crate) fn ydoc_new(client_id: &[Value]) -> Self {
|
12
21
|
let mut options = Options::default();
|
13
|
-
|
14
22
|
if client_id.len() == 1 {
|
15
23
|
let value = client_id.first().unwrap();
|
16
24
|
options.client_id = Integer::from_value(*value).unwrap().to_u64().unwrap();
|
17
25
|
}
|
18
|
-
|
19
26
|
options.offset_kind = OffsetKind::Utf32;
|
20
27
|
|
21
28
|
let doc = Doc::with_options(options);
|
22
29
|
Self(RefCell::new(doc))
|
23
30
|
}
|
24
31
|
|
25
|
-
pub(crate) fn
|
26
|
-
|
32
|
+
pub(crate) fn ydoc_encode_diff_v1(
|
33
|
+
&self,
|
34
|
+
transaction: &YTransaction,
|
35
|
+
state_vector: Vec<u8>,
|
36
|
+
) -> Result<Vec<u8>, Error> {
|
37
|
+
let mut tx = transaction.transaction();
|
38
|
+
let tx = tx.as_mut().unwrap();
|
27
39
|
|
28
|
-
|
29
|
-
|
30
|
-
pub(crate) fn ydoc_encode_diff_v1(&self, state_vector: Vec<u8>) -> Result<Vec<u8>, Error> {
|
31
|
-
StateVector::decode_v1(&*state_vector)
|
32
|
-
.map(|sv| self.0.borrow().encode_state_as_update_v1(&sv))
|
40
|
+
StateVector::decode_v1(state_vector.borrow())
|
41
|
+
.map(|sv| tx.encode_diff_v1(&sv))
|
33
42
|
.map_err(|_e| Error::runtime_error("cannot encode diff"))
|
34
43
|
}
|
44
|
+
|
45
|
+
pub(crate) fn ydoc_get_or_insert_array(&self, name: String) -> YArray {
|
46
|
+
self.0.borrow().get_or_insert_array(name.as_str()).into()
|
47
|
+
}
|
48
|
+
|
49
|
+
pub(crate) fn ydoc_get_or_insert_map(&self, name: String) -> YMap {
|
50
|
+
self.0.borrow().get_or_insert_map(name.as_str()).into()
|
51
|
+
}
|
52
|
+
|
53
|
+
pub(crate) fn ydoc_get_or_insert_text(&self, name: String) -> YText {
|
54
|
+
self.0.borrow().get_or_insert_text(name.as_str()).into()
|
55
|
+
}
|
56
|
+
|
57
|
+
pub(crate) fn ydoc_get_or_insert_xml_element(&self, name: String) -> YXmlElement {
|
58
|
+
let xml_element_ref = self.0.borrow_mut().get_or_insert_xml_element(name.as_str());
|
59
|
+
YXmlElement::from(xml_element_ref) // ::into() maps to YXmlFragment instead of YXmlElement :-(
|
60
|
+
}
|
61
|
+
|
62
|
+
pub(crate) fn ydoc_get_or_insert_xml_fragment(&self, name: String) -> YXmlFragment {
|
63
|
+
self.0
|
64
|
+
.borrow()
|
65
|
+
.get_or_insert_xml_fragment(name.as_str())
|
66
|
+
.into()
|
67
|
+
}
|
68
|
+
|
69
|
+
pub(crate) fn ydoc_get_or_insert_xml_text(&self, name: String) -> YXmlText {
|
70
|
+
self.0.borrow().get_or_insert_xml_text(name.as_str()).into()
|
71
|
+
}
|
72
|
+
|
73
|
+
pub(crate) fn ydoc_transact<'doc>(&self) -> YTransaction {
|
74
|
+
let doc = self.0.borrow();
|
75
|
+
let transaction = doc.transact_mut();
|
76
|
+
YTransaction::from(transaction)
|
77
|
+
}
|
35
78
|
}
|