y-rb 0.5.1-arm64-darwin → 0.5.2-arm64-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4803927c3c928c727924ecd0a9b6e99fb1fb2132274b4c14e2e757ae9553119b
4
- data.tar.gz: 18cca384b8eb00a0380e22f15d0a8775f6bf295a85a8cf8e8a274acd0fb8f1a2
3
+ metadata.gz: 020eb661598f9ff95a4952164e024c7367e5224a8aae495f77b53bf3a258c3c6
4
+ data.tar.gz: 8635810e426132c09b5725e7b539cadcb875baa859887a1e1971bf68ec5db3e7
5
5
  SHA512:
6
- metadata.gz: 6c643643f90ece01f39ae50a2de4e84514f7063b65061a2098e24e5d505018d9c4d69fc5a4568afbc364eac15176edfae7cf0e83be98ec40cdb743b5cdc4b58a
7
- data.tar.gz: ac138d3079333d25046c023c743406219b7d8aee4a7d4a3ee5b763eb5856209beb8375fbfb5598f52abe2bde58d355d1400163e5083d6d968c7dc91ea9625c43
6
+ metadata.gz: c31599dfac7a44966e256d6c1696e8e4a1a162014b5dcde60d27cc10c7240d8bd4d53f9f66f33fb1fe9a5e5084c36301474a494dff2d767d4161d085b54690c2
7
+ data.tar.gz: 7740d4f3a55e3c810e8606511ce2df74bcaf2721175ae4304baf04a283f0afd429e7351b9cdfc2ae6dd998e6c3404015280b71cd789e80c8149eacb795145bad
data/ext/yrb/Cargo.toml CHANGED
@@ -1,21 +1,21 @@
1
1
  [package]
2
2
  name = "yrb"
3
- version = "0.5.1"
3
+ version = "0.5.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"
7
7
  repository = "https://github.com/y-crdt/yrb"
8
8
 
9
9
  [dependencies]
10
- lib0 = "0.16.5" # must match yrs version
11
- magnus = "0.5.2"
12
- thiserror = "1.0.40"
13
- yrs = "0.16.5"
14
- y-sync = "0.3.0"
15
- rb-sys = "0.9.71"
10
+ lib0 = "0.16.9" # must match yrs version
11
+ magnus = "0.5.4"
12
+ thiserror = "1.0.41"
13
+ yrs = "=0.16.9"
14
+ y-sync = "=0.3.1"
15
+ rb-sys = "0.9.79"
16
16
 
17
17
  [dev-dependencies]
18
- magnus = { version = "0.5.2", features = ["embed"] }
18
+ magnus = { version = "0.5.4", features = ["embed"] }
19
19
 
20
20
  [lib]
21
21
  name = "yrb"
data/ext/yrb/src/lib.rs CHANGED
@@ -83,6 +83,8 @@ fn init() -> Result<(), Error> {
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),
@@ -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,6 +213,12 @@ 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
224
  .define_class("Text", Default::default())
data/ext/yrb/src/utils.rs CHANGED
@@ -2,7 +2,7 @@ use crate::yvalue::YValue;
2
2
  use lib0::any::Any;
3
3
  use magnus::r_hash::ForEach::Continue;
4
4
  use magnus::{exception, Error, RHash, RString, Symbol, Value};
5
- use std::rc::Rc;
5
+ use std::sync::Arc;
6
6
  use yrs::types::Attrs;
7
7
 
8
8
  #[derive(Debug, Clone)]
@@ -18,7 +18,7 @@ pub(crate) fn map_rhash_to_attrs(hash: RHash) -> Result<Attrs, Error> {
18
18
  let mut a: Attrs = Default::default();
19
19
 
20
20
  let result = hash.foreach(|key: Value, value: Value| {
21
- let k = Rc::from(key.to_string());
21
+ let k = Arc::from(key.to_string());
22
22
  let v = Any::from(YValue::from(value));
23
23
 
24
24
  a.insert(k, v);
@@ -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::rc::Rc;
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(Rc::from(k), avalue);
26
+ attrs.insert(Arc::from(k), avalue);
27
27
 
28
28
  Ok(Continue)
29
29
  })
@@ -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, Subscription};
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(Subscription<Event>);
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<Subscription<Event>> for YAwarenessSubscription {
148
- fn from(v: Subscription<Event>) -> Self {
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)
@@ -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/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
- # Returns or creates an array by name
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Y
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.2"
5
5
  end
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.1
4
+ version: 0.5.2
5
5
  platform: arm64-darwin
6
6
  authors:
7
7
  - Hannes Moser
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-07 00:00:00.000000000 Z
11
+ date: 2023-07-06 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: '2.7'
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.21
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