@peerbit/native-backbone 0.1.0
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.
- package/LICENSE +202 -0
- package/README.md +27 -0
- package/dist/src/benchmark.d.ts +19 -0
- package/dist/src/benchmark.d.ts.map +1 -0
- package/dist/src/benchmark.js +12 -0
- package/dist/src/benchmark.js.map +1 -0
- package/dist/src/index.d.ts +1561 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +3406 -0
- package/dist/src/index.js.map +1 -0
- package/dist/wasm/README.md +27 -0
- package/dist/wasm/native_backbone.d.ts +1609 -0
- package/dist/wasm/native_backbone.js +10221 -0
- package/dist/wasm/native_backbone_bg.wasm +0 -0
- package/dist/wasm/native_backbone_bg.wasm.d.ts +625 -0
- package/package.json +64 -0
- package/src/append_tx/committed_latest.rs +2063 -0
- package/src/append_tx/committed_no_next.rs +1165 -0
- package/src/append_tx/facts.rs +791 -0
- package/src/append_tx/mod.rs +751 -0
- package/src/append_tx/storage.rs +599 -0
- package/src/benchmark.ts +58 -0
- package/src/coordinates.rs +422 -0
- package/src/documents.rs +1698 -0
- package/src/graph_blocks.rs +362 -0
- package/src/index.ts +9134 -0
- package/src/js_interop.rs +448 -0
- package/src/lib.rs +144 -0
- package/src/profile.rs +164 -0
- package/src/raw_receive.rs +1724 -0
- package/src/shared_log_plan.rs +1464 -0
- package/src/sync_send.rs +180 -0
- package/src/wire_sync.rs +727 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
use js_sys::{Array, BigUint64Array, Uint32Array, Uint8Array};
|
|
2
|
+
use peerbit_log_rust::entry_v0_signature_public_key_from_storage_bytes;
|
|
3
|
+
use wasm_bindgen::prelude::*;
|
|
4
|
+
|
|
5
|
+
use crate::js_interop::strings_from_array;
|
|
6
|
+
use crate::NativePeerbitBackbone;
|
|
7
|
+
|
|
8
|
+
#[wasm_bindgen]
|
|
9
|
+
impl NativePeerbitBackbone {
|
|
10
|
+
pub fn graph_has_many(&self, hashes: Array) -> Result<Array, JsValue> {
|
|
11
|
+
self.log.has_many(hashes)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#[allow(clippy::too_many_arguments)]
|
|
15
|
+
pub fn graph_put(
|
|
16
|
+
&mut self,
|
|
17
|
+
hash: String,
|
|
18
|
+
gid: String,
|
|
19
|
+
next: Array,
|
|
20
|
+
entry_type: u8,
|
|
21
|
+
wall_time: u64,
|
|
22
|
+
logical: u32,
|
|
23
|
+
payload_size: u32,
|
|
24
|
+
head: bool,
|
|
25
|
+
data: JsValue,
|
|
26
|
+
) -> Result<(), JsValue> {
|
|
27
|
+
self.log.put(
|
|
28
|
+
hash,
|
|
29
|
+
gid,
|
|
30
|
+
next,
|
|
31
|
+
entry_type,
|
|
32
|
+
wall_time,
|
|
33
|
+
logical,
|
|
34
|
+
payload_size,
|
|
35
|
+
head,
|
|
36
|
+
data,
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
pub fn graph_put_batch(
|
|
41
|
+
&mut self,
|
|
42
|
+
hashes: Array,
|
|
43
|
+
gids: Array,
|
|
44
|
+
nexts: Array,
|
|
45
|
+
entry_types: Uint8Array,
|
|
46
|
+
wall_times: BigUint64Array,
|
|
47
|
+
logicals: Uint32Array,
|
|
48
|
+
payload_sizes: Uint32Array,
|
|
49
|
+
heads: Uint8Array,
|
|
50
|
+
datas: Array,
|
|
51
|
+
) -> Result<(), JsValue> {
|
|
52
|
+
self.log.put_many(
|
|
53
|
+
hashes,
|
|
54
|
+
gids,
|
|
55
|
+
nexts,
|
|
56
|
+
entry_types,
|
|
57
|
+
wall_times,
|
|
58
|
+
logicals,
|
|
59
|
+
payload_sizes,
|
|
60
|
+
heads,
|
|
61
|
+
datas,
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
pub fn graph_put_append_chain(
|
|
66
|
+
&mut self,
|
|
67
|
+
hashes: Array,
|
|
68
|
+
gid: String,
|
|
69
|
+
initial_next: Array,
|
|
70
|
+
entry_type: u8,
|
|
71
|
+
wall_times: BigUint64Array,
|
|
72
|
+
logicals: Uint32Array,
|
|
73
|
+
payload_sizes: Uint32Array,
|
|
74
|
+
datas: Array,
|
|
75
|
+
) -> Result<(), JsValue> {
|
|
76
|
+
self.log.put_append_chain(
|
|
77
|
+
hashes,
|
|
78
|
+
gid,
|
|
79
|
+
initial_next,
|
|
80
|
+
entry_type,
|
|
81
|
+
wall_times,
|
|
82
|
+
logicals,
|
|
83
|
+
payload_sizes,
|
|
84
|
+
datas,
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
pub fn commit_log_blocks_and_graph_batch(
|
|
89
|
+
&mut self,
|
|
90
|
+
hashes: Array,
|
|
91
|
+
block_bytes: Array,
|
|
92
|
+
gids: Array,
|
|
93
|
+
nexts: Array,
|
|
94
|
+
entry_types: Uint8Array,
|
|
95
|
+
wall_times: BigUint64Array,
|
|
96
|
+
logicals: Uint32Array,
|
|
97
|
+
payload_sizes: Uint32Array,
|
|
98
|
+
heads: Uint8Array,
|
|
99
|
+
datas: Array,
|
|
100
|
+
) -> Result<(), JsValue> {
|
|
101
|
+
self.blocks.put_many(hashes.clone(), block_bytes)?;
|
|
102
|
+
self.log.put_many(
|
|
103
|
+
hashes,
|
|
104
|
+
gids,
|
|
105
|
+
nexts,
|
|
106
|
+
entry_types,
|
|
107
|
+
wall_times,
|
|
108
|
+
logicals,
|
|
109
|
+
payload_sizes,
|
|
110
|
+
heads,
|
|
111
|
+
datas,
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#[allow(clippy::too_many_arguments)]
|
|
116
|
+
pub fn commit_log_blocks_graph_and_coordinates_batch(
|
|
117
|
+
&mut self,
|
|
118
|
+
hashes: Array,
|
|
119
|
+
block_bytes: Array,
|
|
120
|
+
gids: Array,
|
|
121
|
+
nexts: Array,
|
|
122
|
+
entry_types: Uint8Array,
|
|
123
|
+
wall_times: BigUint64Array,
|
|
124
|
+
logicals: Uint32Array,
|
|
125
|
+
payload_sizes: Uint32Array,
|
|
126
|
+
heads: Uint8Array,
|
|
127
|
+
datas: Array,
|
|
128
|
+
coordinate_hashes: Array,
|
|
129
|
+
coordinate_gids: Array,
|
|
130
|
+
coordinate_hash_numbers: Array,
|
|
131
|
+
coordinate_batches: Array,
|
|
132
|
+
coordinate_next_hash_batches: Array,
|
|
133
|
+
coordinate_assigned_to_range_boundaries: Uint8Array,
|
|
134
|
+
coordinate_requested_replicas: Array,
|
|
135
|
+
) -> Result<(), JsValue> {
|
|
136
|
+
self.blocks.put_many(hashes.clone(), block_bytes)?;
|
|
137
|
+
self.log.put_many(
|
|
138
|
+
hashes,
|
|
139
|
+
gids,
|
|
140
|
+
nexts,
|
|
141
|
+
entry_types,
|
|
142
|
+
wall_times,
|
|
143
|
+
logicals,
|
|
144
|
+
payload_sizes,
|
|
145
|
+
heads,
|
|
146
|
+
datas,
|
|
147
|
+
)?;
|
|
148
|
+
if coordinate_hashes.length() > 0 {
|
|
149
|
+
self.commit_entry_coordinates_batch(
|
|
150
|
+
coordinate_hashes,
|
|
151
|
+
coordinate_gids,
|
|
152
|
+
coordinate_hash_numbers,
|
|
153
|
+
coordinate_batches,
|
|
154
|
+
coordinate_next_hash_batches,
|
|
155
|
+
coordinate_assigned_to_range_boundaries,
|
|
156
|
+
coordinate_requested_replicas,
|
|
157
|
+
)?;
|
|
158
|
+
}
|
|
159
|
+
Ok(())
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
pub fn graph_delete(&mut self, hash: &str) -> bool {
|
|
163
|
+
self.log.delete(hash)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
pub fn graph_clear(&mut self) {
|
|
167
|
+
self.log.clear();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
pub fn graph_delete_many(&mut self, hashes: Array) -> Result<usize, JsValue> {
|
|
171
|
+
self.log.delete_many(hashes)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
pub fn graph_oldest_entries(&self, limit: usize) -> Array {
|
|
175
|
+
self.log.oldest_entries(limit)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
pub fn graph_heads(&self, gid: Option<String>) -> Array {
|
|
179
|
+
self.log.heads(gid)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
pub fn graph_has_head(&self, gid: Option<String>) -> bool {
|
|
183
|
+
self.log.has_head(gid)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
pub fn graph_has_any_head(&self, gids: Array) -> Result<bool, JsValue> {
|
|
187
|
+
self.log.has_any_head(gids)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
pub fn graph_has_any_head_batch(&self, gid_sets: Array) -> Result<Array, JsValue> {
|
|
191
|
+
self.log.has_any_head_batch(gid_sets)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
pub fn graph_head_entries(&self, gid: Option<String>) -> Array {
|
|
195
|
+
self.log.head_entries(gid)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
pub fn graph_head_data_entries(&self, gid: Option<String>) -> Array {
|
|
199
|
+
self.log.head_data_entries(gid)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
pub fn graph_max_head_data_u32(&self, gid: Option<String>) -> JsValue {
|
|
203
|
+
self.log.max_head_data_u32(gid)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
pub fn graph_max_head_data_u32_batch(&self, gids: Array) -> Result<Array, JsValue> {
|
|
207
|
+
self.log.max_head_data_u32_batch(gids)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
pub fn graph_join_head_entries(&self, gid: Option<String>) -> Array {
|
|
211
|
+
self.log.head_join_entries(gid)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
pub fn graph_child_join_entries(&self, hash: &str) -> Array {
|
|
215
|
+
self.log.child_join_entries(hash)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
pub fn graph_entry_metadata_batch(&self, hashes: Array) -> Result<Array, JsValue> {
|
|
219
|
+
self.log.entry_metadata_batch(hashes)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
pub fn graph_entry_metadata_hints_batch(&self, hashes: Array) -> Result<Array, JsValue> {
|
|
223
|
+
self.log.entry_metadata_hints_batch(hashes)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
pub fn graph_entry_signature_public_key_batch(&self, hashes: Array) -> Result<Array, JsValue> {
|
|
227
|
+
let hashes = strings_from_array(hashes)?;
|
|
228
|
+
let out = Array::new();
|
|
229
|
+
for hash in hashes {
|
|
230
|
+
match self
|
|
231
|
+
.blocks
|
|
232
|
+
.get(&hash)
|
|
233
|
+
.and_then(|bytes| entry_v0_signature_public_key_from_storage_bytes(&bytes).ok())
|
|
234
|
+
{
|
|
235
|
+
Some(public_key) => out.push(&Uint8Array::from(public_key.as_slice())),
|
|
236
|
+
None => out.push(&JsValue::UNDEFINED),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
Ok(out)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
pub fn graph_unique_reference_gids(&self, hash: &str) -> JsValue {
|
|
243
|
+
self.log.unique_reference_gids(hash)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
pub fn graph_unique_reference_gid_rows_batch(&self, hashes: Array) -> Result<Array, JsValue> {
|
|
247
|
+
self.log.unique_reference_gid_rows_batch(hashes)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
pub fn graph_unique_reference_gid_rows_flat_batch(
|
|
251
|
+
&self,
|
|
252
|
+
hashes: Array,
|
|
253
|
+
) -> Result<JsValue, JsValue> {
|
|
254
|
+
self.log.unique_reference_gid_rows_flat_batch(hashes)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
pub fn graph_plan_delete_recursively(
|
|
258
|
+
&self,
|
|
259
|
+
hashes: Array,
|
|
260
|
+
skip_first: bool,
|
|
261
|
+
) -> Result<Array, JsValue> {
|
|
262
|
+
self.log.plan_delete_recursively(hashes, skip_first)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
pub fn graph_payload_size_sum(&self) -> f64 {
|
|
266
|
+
self.log.payload_size_sum()
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
pub fn graph_oldest_hash(&self) -> JsValue {
|
|
270
|
+
self.log.oldest_hash()
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
pub fn graph_newest_hash(&self) -> JsValue {
|
|
274
|
+
self.log.newest_hash()
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
pub fn graph_count_has_next(&self, next: &str, exclude_hash: Option<String>) -> usize {
|
|
278
|
+
self.log.count_has_next(next, exclude_hash)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
pub fn graph_shadowed_gids(
|
|
282
|
+
&self,
|
|
283
|
+
gid: String,
|
|
284
|
+
next: Array,
|
|
285
|
+
exclude_hash: Option<String>,
|
|
286
|
+
) -> Result<Array, JsValue> {
|
|
287
|
+
self.log.shadowed_gids(&gid, next, exclude_hash)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
pub fn graph_plan_join(
|
|
291
|
+
&self,
|
|
292
|
+
hash: String,
|
|
293
|
+
next: Array,
|
|
294
|
+
entry_type: u8,
|
|
295
|
+
reset: bool,
|
|
296
|
+
gid: Option<String>,
|
|
297
|
+
wall_time: Option<u64>,
|
|
298
|
+
logical: Option<u32>,
|
|
299
|
+
) -> Result<Array, JsValue> {
|
|
300
|
+
self.log
|
|
301
|
+
.plan_join(&hash, next, entry_type, reset, gid, wall_time, logical)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
pub fn graph_plan_join_batch(
|
|
305
|
+
&self,
|
|
306
|
+
hashes: Array,
|
|
307
|
+
nexts: Array,
|
|
308
|
+
entry_types: Uint8Array,
|
|
309
|
+
reset: bool,
|
|
310
|
+
gids: Array,
|
|
311
|
+
wall_times: BigUint64Array,
|
|
312
|
+
logicals: Uint32Array,
|
|
313
|
+
cut_check: bool,
|
|
314
|
+
) -> Result<Array, JsValue> {
|
|
315
|
+
self.log.plan_join_batch(
|
|
316
|
+
hashes,
|
|
317
|
+
nexts,
|
|
318
|
+
entry_types,
|
|
319
|
+
reset,
|
|
320
|
+
gids,
|
|
321
|
+
wall_times,
|
|
322
|
+
logicals,
|
|
323
|
+
cut_check,
|
|
324
|
+
)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
pub fn block_get(&self, key: &str) -> Option<Vec<u8>> {
|
|
328
|
+
self.blocks.get(key)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
pub fn block_get_many(&self, keys: Array) -> Result<Array, JsValue> {
|
|
332
|
+
self.blocks.get_many(keys)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
pub fn block_has_many(&self, keys: Array) -> Result<Array, JsValue> {
|
|
336
|
+
self.blocks.has_many(keys)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
pub fn block_put(&mut self, key: String, value: Vec<u8>) {
|
|
340
|
+
self.blocks.put(key, value);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
pub fn block_put_many(&mut self, keys: Array, values: Array) -> Result<(), JsValue> {
|
|
344
|
+
self.blocks.put_many(keys, values)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
pub fn block_delete(&mut self, key: &str) -> bool {
|
|
348
|
+
self.blocks.delete(key)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
pub fn block_delete_many(&mut self, keys: Array) -> Result<usize, JsValue> {
|
|
352
|
+
self.blocks.delete_many(keys)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
pub fn block_entries(&self) -> Array {
|
|
356
|
+
self.blocks.entries()
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
pub fn block_size(&self) -> f64 {
|
|
360
|
+
self.blocks.size()
|
|
361
|
+
}
|
|
362
|
+
}
|