y-rb 0.4.0-x86_64-linux-musl → 0.4.2-x86_64-linux-musl
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 +4 -4
- data/ext/yrb/src/lib.rs +3 -0
- data/ext/yrb/src/utils.rs +5 -2
- data/ext/yrb/src/yawareness.rs +15 -9
- data/ext/yrb/src/ydoc.rs +21 -3
- data/ext/yrb/src/ymap.rs +3 -2
- data/ext/yrb/src/ytransaction.rs +7 -2
- 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 +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 747457cfb21e66da374a352cbd29d99a4d7c5741ebc971eeff82a197ada4b8ce
|
4
|
+
data.tar.gz: 542ff3efa50da67d1e9a912f5a7c1596895967b7aff83936fc7fdd39f7dbfa08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c08cd2c80ac6bd44e330f0edc8ec1ee99c678ec1ec3c5b7200cdeba26d7c06f8697728571417b764c236fdff06f60aff9b35fa730ca94c8fdd3c0df043093780
|
7
|
+
data.tar.gz: d56c3ce5b6b2d18120849a039b4c715a4b2a5b26edaf04499783b3951a804295ea8dfe2cc57a1f62e2eac7bb17bb7cb2c7a54fad2d717c75f7e0c797101edfdf
|
data/ext/yrb/Cargo.toml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
[package]
|
2
2
|
name = "yrb"
|
3
|
-
version = "0.4.
|
3
|
+
version = "0.4.2"
|
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"
|
@@ -8,12 +8,12 @@ repository = "https://github.com/y-crdt/yrb"
|
|
8
8
|
|
9
9
|
[dependencies]
|
10
10
|
lib0 = "0.14.1" # must match yrs version
|
11
|
-
magnus = {
|
12
|
-
thiserror = "1.0.
|
11
|
+
magnus = { git = "https://github.com/matsadler/magnus", rev = "a51ccaf01d82e9e1a981e4f3fbaca35100513b08" }
|
12
|
+
thiserror = "1.0.38"
|
13
13
|
yrs = "0.14.1"
|
14
14
|
|
15
15
|
[dev-dependencies]
|
16
|
-
magnus = {
|
16
|
+
magnus = { git = "https://github.com/matsadler/magnus", rev = "a51ccaf01d82e9e1a981e4f3fbaca35100513b08", 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/utils.rs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
use crate::yvalue::YValue;
|
2
2
|
use lib0::any::Any;
|
3
3
|
use magnus::r_hash::ForEach::Continue;
|
4
|
-
use magnus::{Error, RHash, RString, Symbol, Value};
|
4
|
+
use magnus::{exception, Error, RHash, RString, Symbol, Value};
|
5
5
|
use std::rc::Rc;
|
6
6
|
use yrs::types::Attrs;
|
7
7
|
|
@@ -27,7 +27,10 @@ pub(crate) fn map_rhash_to_attrs(hash: RHash) -> Result<Attrs, Error> {
|
|
27
27
|
});
|
28
28
|
|
29
29
|
if result.is_err() {
|
30
|
-
return Err(Error::
|
30
|
+
return Err(Error::new(
|
31
|
+
exception::runtime_error(),
|
32
|
+
"could not map hash to attrs",
|
33
|
+
));
|
31
34
|
}
|
32
35
|
|
33
36
|
Ok(a)
|
data/ext/yrb/src/yawareness.rs
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
use crate::awareness::{Awareness, AwarenessUpdate, Event};
|
2
|
-
use magnus::block::Proc;
|
3
|
-
use magnus::{Error, Value};
|
2
|
+
use magnus::{block::Proc, exception, Error, Value};
|
4
3
|
use std::borrow::Borrow;
|
5
4
|
use std::cell::RefCell;
|
6
5
|
use std::collections::HashMap;
|
@@ -25,12 +24,11 @@ impl YAwareness {
|
|
25
24
|
|
26
25
|
pub(crate) fn yawareness_apply_update(&self, update: Vec<u8>) -> Result<(), Error> {
|
27
26
|
AwarenessUpdate::decode_v1(update.as_slice())
|
28
|
-
.map_err(|_error| Error::runtime_error("cannot decode update"))
|
27
|
+
.map_err(|_error| Error::new(exception::runtime_error(), "cannot decode update"))
|
29
28
|
.and_then(|value| {
|
30
|
-
self.0
|
31
|
-
|
32
|
-
|
33
|
-
.map_err(|_error| Error::runtime_error("cannot apply awareness update"))
|
29
|
+
self.0.borrow_mut().apply_update(value).map_err(|_error| {
|
30
|
+
Error::new(exception::runtime_error(), "cannot apply awareness update")
|
31
|
+
})
|
34
32
|
})
|
35
33
|
}
|
36
34
|
|
@@ -83,7 +81,12 @@ impl YAwareness {
|
|
83
81
|
.borrow_mut()
|
84
82
|
.update()
|
85
83
|
.map(|update| update.encode_v1())
|
86
|
-
.map_err(|_error|
|
84
|
+
.map_err(|_error| {
|
85
|
+
Error::new(
|
86
|
+
exception::runtime_error(),
|
87
|
+
"cannot create update for current state",
|
88
|
+
)
|
89
|
+
})
|
87
90
|
}
|
88
91
|
|
89
92
|
pub(crate) fn yawareness_update_with_clients(
|
@@ -95,7 +98,10 @@ impl YAwareness {
|
|
95
98
|
.update_with_clients(clients)
|
96
99
|
.map(|update| update.encode_v1())
|
97
100
|
.map_err(|_error| {
|
98
|
-
Error::
|
101
|
+
Error::new(
|
102
|
+
exception::runtime_error(),
|
103
|
+
"cannot create update for current state and given clients",
|
104
|
+
)
|
99
105
|
})
|
100
106
|
}
|
101
107
|
}
|
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>);
|
@@ -39,7 +41,7 @@ impl YDoc {
|
|
39
41
|
|
40
42
|
StateVector::decode_v1(state_vector.borrow())
|
41
43
|
.map(|sv| tx.encode_diff_v1(&sv))
|
42
|
-
.map_err(|_e| Error::runtime_error("cannot encode diff"))
|
44
|
+
.map_err(|_e| Error::new(exception::runtime_error(), "cannot encode diff"))
|
43
45
|
}
|
44
46
|
|
45
47
|
pub(crate) fn ydoc_get_or_insert_array(&self, name: String) -> YArray {
|
@@ -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
@@ -3,7 +3,7 @@ use crate::yvalue::YValue;
|
|
3
3
|
use crate::YTransaction;
|
4
4
|
use lib0::any::Any;
|
5
5
|
use magnus::block::Proc;
|
6
|
-
use magnus::{Error, RArray, RHash, Symbol, Value};
|
6
|
+
use magnus::{exception, Error, RArray, RHash, Symbol, Value};
|
7
7
|
use std::cell::RefCell;
|
8
8
|
use yrs::types::{EntryChange, Value as YrsValue};
|
9
9
|
use yrs::{Map, MapRef, Observable};
|
@@ -60,7 +60,8 @@ impl YMap {
|
|
60
60
|
let tx = tx.as_mut().unwrap();
|
61
61
|
|
62
62
|
match indifferent_hash_key(key) {
|
63
|
-
None => Err(Error::
|
63
|
+
None => Err(Error::new(
|
64
|
+
exception::runtime_error(),
|
64
65
|
"invalid key type, make sure it is either of type Symbol or String",
|
65
66
|
)),
|
66
67
|
Some(k) => {
|
data/ext/yrb/src/ytransaction.rs
CHANGED
@@ -4,7 +4,7 @@ use crate::ytext::YText;
|
|
4
4
|
use crate::yxml_element::YXmlElement;
|
5
5
|
use crate::yxml_fragment::YXmlFragment;
|
6
6
|
use crate::yxml_text::YXmlText;
|
7
|
-
use magnus::Error;
|
7
|
+
use magnus::{exception, Error};
|
8
8
|
use std::cell::{RefCell, RefMut};
|
9
9
|
use yrs::updates::decoder::Decode;
|
10
10
|
use yrs::updates::encoder::Encode;
|
@@ -29,7 +29,12 @@ impl<'doc> From<TransactionMut<'doc>> for YTransaction {
|
|
29
29
|
impl YTransaction {
|
30
30
|
pub(crate) fn ytransaction_apply_update(&self, update: Vec<u8>) -> Result<(), Error> {
|
31
31
|
Update::decode_v1(update.as_slice())
|
32
|
-
.map_err(|error|
|
32
|
+
.map_err(|error| {
|
33
|
+
Error::new(
|
34
|
+
exception::runtime_error(),
|
35
|
+
format!("cannot decode update: {:?}", error),
|
36
|
+
)
|
37
|
+
})
|
33
38
|
.map(|u| self.transaction().as_mut().unwrap().apply_update(u))
|
34
39
|
}
|
35
40
|
|
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.2
|
5
5
|
platform: x86_64-linux-musl
|
6
6
|
authors:
|
7
7
|
- Hannes Moser
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.9.
|
33
|
+
version: 0.9.53
|
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.53
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake-compiler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|