@peerbit/native-backbone 0.1.2 → 0.1.3
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/dist/wasm/native_backbone.d.ts +64 -64
- package/dist/wasm/native_backbone.js +3 -0
- package/dist/wasm/native_backbone_bg.wasm +0 -0
- package/dist/wasm/native_backbone_bg.wasm.d.ts +64 -64
- package/package.json +1 -1
- package/src/append_tx/committed_latest.rs +390 -317
- package/src/append_tx/committed_no_next.rs +66 -64
- package/src/append_tx/facts.rs +213 -147
- package/src/append_tx/mod.rs +160 -58
- package/src/append_tx/storage.rs +52 -28
- package/src/coordinates.rs +135 -44
- package/src/documents.rs +340 -100
- package/src/error.rs +244 -0
- package/src/js_interop.rs +230 -90
- package/src/lib.rs +4 -0
- package/src/raw_receive.rs +182 -107
- package/src/shared_log_plan.rs +65 -23
- package/src/sync_send.rs +19 -3
- package/src/time.rs +14 -0
- package/src/wire_sync.rs +147 -36
package/src/append_tx/facts.rs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
use js_sys::{Array, Uint8Array};
|
|
2
|
+
use peerbit_log_rust::LogIndexEntry;
|
|
2
3
|
use wasm_bindgen::prelude::*;
|
|
3
4
|
|
|
4
5
|
use crate::append_tx::{
|
|
@@ -9,9 +10,37 @@ use crate::documents::{
|
|
|
9
10
|
document_index_cached_projection_append_commit,
|
|
10
11
|
document_index_cached_projection_plain_put_payload_append_commit, DocumentIndexAppendCommit,
|
|
11
12
|
};
|
|
12
|
-
use crate::
|
|
13
|
+
use crate::error::BackboneError;
|
|
14
|
+
use crate::js_interop::{
|
|
15
|
+
optional_bytes_from_js, optional_usize_from_js, strings_from_array, strings_to_array,
|
|
16
|
+
};
|
|
13
17
|
use crate::NativePeerbitBackbone;
|
|
14
18
|
|
|
19
|
+
/// Trim rows in the exact shape the log-rust
|
|
20
|
+
/// `prepare_entry_v0_plain_entry_commit_[no_next_]facts_trim_and_put_with_builder`
|
|
21
|
+
/// wrappers returned (`log_trim_entries_to_rows`), so the re-pointed typed
|
|
22
|
+
/// cores keep the frozen row layout byte-for-byte.
|
|
23
|
+
fn log_trim_entries_to_rows(values: Vec<LogIndexEntry>) -> Array {
|
|
24
|
+
let out = Array::new();
|
|
25
|
+
for entry in values {
|
|
26
|
+
let row = Array::new();
|
|
27
|
+
row.push(&JsValue::from_str(&entry.hash));
|
|
28
|
+
row.push(&JsValue::from_str(&entry.gid));
|
|
29
|
+
row.push(&JsValue::from_str(&entry.wall_time.to_string()));
|
|
30
|
+
row.push(&JsValue::from_f64(entry.logical as f64));
|
|
31
|
+
row.push(&JsValue::from_f64(entry.entry_type as f64));
|
|
32
|
+
row.push(&strings_to_array(entry.next));
|
|
33
|
+
row.push(&JsValue::from_f64(entry.payload_size as f64));
|
|
34
|
+
row.push(&JsValue::from_bool(entry.head));
|
|
35
|
+
match entry.data {
|
|
36
|
+
Some(data) => row.push(&Uint8Array::from(data.as_slice())),
|
|
37
|
+
None => row.push(&JsValue::UNDEFINED),
|
|
38
|
+
};
|
|
39
|
+
out.push(&row);
|
|
40
|
+
}
|
|
41
|
+
out
|
|
42
|
+
}
|
|
43
|
+
|
|
15
44
|
#[wasm_bindgen]
|
|
16
45
|
impl NativePeerbitBackbone {
|
|
17
46
|
#[allow(clippy::too_many_arguments)]
|
|
@@ -29,58 +58,79 @@ impl NativePeerbitBackbone {
|
|
|
29
58
|
let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
|
|
30
59
|
let has_no_next = next.length() == 0;
|
|
31
60
|
match (has_no_next, trim_length_to) {
|
|
32
|
-
(true, Some(trim_length_to)) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
)
|
|
61
|
+
(true, Some(trim_length_to)) => {
|
|
62
|
+
let (entry_facts, trimmed_entries) = self
|
|
63
|
+
.log
|
|
64
|
+
.prepare_entry_v0_plain_entry_commit_no_next_facts_core_profiled_and_put_with_builder_trim(
|
|
65
|
+
&self.builder,
|
|
66
|
+
&mut self.blocks,
|
|
67
|
+
wall_time,
|
|
68
|
+
logical,
|
|
69
|
+
gid,
|
|
70
|
+
entry_type,
|
|
71
|
+
optional_bytes_from_js(meta_data, "meta data")?,
|
|
72
|
+
payload_data.to_vec(),
|
|
73
|
+
trim_length_to,
|
|
74
|
+
None,
|
|
75
|
+
)?;
|
|
76
|
+
let out = Array::new();
|
|
77
|
+
out.push(&committed_entry_facts_to_row(&entry_facts, false));
|
|
78
|
+
out.push(&log_trim_entries_to_rows(trimmed_entries));
|
|
79
|
+
Ok(out)
|
|
80
|
+
}
|
|
81
|
+
(true, None) => {
|
|
82
|
+
let entry_facts = self
|
|
83
|
+
.log
|
|
84
|
+
.prepare_entry_v0_plain_entry_commit_no_next_facts_core_profiled_and_put_with_builder(
|
|
85
|
+
&self.builder,
|
|
86
|
+
&mut self.blocks,
|
|
87
|
+
wall_time,
|
|
88
|
+
logical,
|
|
89
|
+
gid,
|
|
90
|
+
entry_type,
|
|
91
|
+
optional_bytes_from_js(meta_data, "meta data")?,
|
|
92
|
+
payload_data.to_vec(),
|
|
93
|
+
None,
|
|
94
|
+
)?;
|
|
95
|
+
Ok(committed_entry_facts_to_row(&entry_facts, false))
|
|
96
|
+
}
|
|
97
|
+
(false, Some(trim_length_to)) => {
|
|
98
|
+
let (entry_facts, trimmed_entries) = self
|
|
99
|
+
.log
|
|
100
|
+
.prepare_entry_v0_plain_entry_commit_facts_core_and_put_with_builder(
|
|
101
|
+
&self.builder,
|
|
102
|
+
&mut self.blocks,
|
|
103
|
+
wall_time,
|
|
104
|
+
logical,
|
|
105
|
+
gid,
|
|
106
|
+
strings_from_array(next)?,
|
|
107
|
+
entry_type,
|
|
108
|
+
optional_bytes_from_js(meta_data, "meta data")?,
|
|
109
|
+
payload_data.to_vec(),
|
|
110
|
+
Some(trim_length_to),
|
|
111
|
+
)?;
|
|
112
|
+
let out = Array::new();
|
|
113
|
+
out.push(&committed_entry_facts_to_row(&entry_facts, true));
|
|
114
|
+
out.push(&log_trim_entries_to_rows(trimmed_entries));
|
|
115
|
+
Ok(out)
|
|
116
|
+
}
|
|
117
|
+
(false, None) => {
|
|
118
|
+
let (entry_facts, _trimmed_entries) = self
|
|
119
|
+
.log
|
|
120
|
+
.prepare_entry_v0_plain_entry_commit_facts_core_and_put_with_builder(
|
|
121
|
+
&self.builder,
|
|
122
|
+
&mut self.blocks,
|
|
123
|
+
wall_time,
|
|
124
|
+
logical,
|
|
125
|
+
gid,
|
|
126
|
+
strings_from_array(next)?,
|
|
127
|
+
entry_type,
|
|
128
|
+
optional_bytes_from_js(meta_data, "meta data")?,
|
|
129
|
+
payload_data.to_vec(),
|
|
130
|
+
None,
|
|
131
|
+
)?;
|
|
132
|
+
Ok(committed_entry_facts_to_row(&entry_facts, true))
|
|
133
|
+
}
|
|
84
134
|
}
|
|
85
135
|
}
|
|
86
136
|
|
|
@@ -216,16 +266,18 @@ impl NativePeerbitBackbone {
|
|
|
216
266
|
document_projection_encoded_document,
|
|
217
267
|
document_projection_signer,
|
|
218
268
|
)?;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
269
|
+
Ok(
|
|
270
|
+
self.prepare_plain_entry_commit_no_next_document_index_compact(
|
|
271
|
+
wall_time,
|
|
272
|
+
logical,
|
|
273
|
+
gid,
|
|
274
|
+
entry_type,
|
|
275
|
+
meta_data,
|
|
276
|
+
payload_data,
|
|
277
|
+
document_gid,
|
|
278
|
+
payload_size,
|
|
279
|
+
document_index_commit,
|
|
280
|
+
)?,
|
|
229
281
|
)
|
|
230
282
|
}
|
|
231
283
|
|
|
@@ -257,16 +309,18 @@ impl NativePeerbitBackbone {
|
|
|
257
309
|
document_projection_encoded_document,
|
|
258
310
|
document_projection_signer,
|
|
259
311
|
)?;
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
312
|
+
Ok(
|
|
313
|
+
self.prepare_plain_entry_commit_no_next_document_index_compact(
|
|
314
|
+
wall_time,
|
|
315
|
+
logical,
|
|
316
|
+
gid,
|
|
317
|
+
entry_type,
|
|
318
|
+
meta_data,
|
|
319
|
+
payload_data,
|
|
320
|
+
document_gid,
|
|
321
|
+
payload_size,
|
|
322
|
+
document_index_commit,
|
|
323
|
+
)?,
|
|
270
324
|
)
|
|
271
325
|
}
|
|
272
326
|
|
|
@@ -307,7 +361,7 @@ impl NativePeerbitBackbone {
|
|
|
307
361
|
logical,
|
|
308
362
|
gid,
|
|
309
363
|
entry_type,
|
|
310
|
-
optional_bytes_from_js(meta_data)
|
|
364
|
+
optional_bytes_from_js(meta_data, "meta data")?,
|
|
311
365
|
&payload_data,
|
|
312
366
|
None,
|
|
313
367
|
)?;
|
|
@@ -353,18 +407,20 @@ impl NativePeerbitBackbone {
|
|
|
353
407
|
document_projection_encoded_document,
|
|
354
408
|
document_projection_signer,
|
|
355
409
|
)?;
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
410
|
+
Ok(
|
|
411
|
+
self.prepare_plain_entry_commit_no_next_document_index_compact_trim_hashes(
|
|
412
|
+
wall_time,
|
|
413
|
+
logical,
|
|
414
|
+
gid,
|
|
415
|
+
entry_type,
|
|
416
|
+
meta_data,
|
|
417
|
+
payload_data,
|
|
418
|
+
trim_length_to,
|
|
419
|
+
document_gid,
|
|
420
|
+
payload_size,
|
|
421
|
+
document_index_commit,
|
|
422
|
+
false,
|
|
423
|
+
)?,
|
|
368
424
|
)
|
|
369
425
|
}
|
|
370
426
|
|
|
@@ -399,18 +455,20 @@ impl NativePeerbitBackbone {
|
|
|
399
455
|
document_projection_encoded_document,
|
|
400
456
|
document_projection_signer,
|
|
401
457
|
)?;
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
458
|
+
Ok(
|
|
459
|
+
self.prepare_plain_entry_commit_no_next_document_index_compact_trim_hashes(
|
|
460
|
+
wall_time,
|
|
461
|
+
logical,
|
|
462
|
+
gid,
|
|
463
|
+
entry_type,
|
|
464
|
+
meta_data,
|
|
465
|
+
payload_data,
|
|
466
|
+
trim_length_to,
|
|
467
|
+
document_gid,
|
|
468
|
+
payload_size,
|
|
469
|
+
document_index_commit,
|
|
470
|
+
true,
|
|
471
|
+
)?,
|
|
414
472
|
)
|
|
415
473
|
}
|
|
416
474
|
|
|
@@ -443,18 +501,20 @@ impl NativePeerbitBackbone {
|
|
|
443
501
|
document_projection_encoded_document,
|
|
444
502
|
document_projection_signer,
|
|
445
503
|
)?;
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
504
|
+
Ok(
|
|
505
|
+
self.prepare_plain_entry_commit_no_next_document_index_compact_trim_hashes(
|
|
506
|
+
wall_time,
|
|
507
|
+
logical,
|
|
508
|
+
gid,
|
|
509
|
+
entry_type,
|
|
510
|
+
meta_data,
|
|
511
|
+
payload_data,
|
|
512
|
+
trim_length_to,
|
|
513
|
+
document_gid,
|
|
514
|
+
payload_size,
|
|
515
|
+
document_index_commit,
|
|
516
|
+
false,
|
|
517
|
+
)?,
|
|
458
518
|
)
|
|
459
519
|
}
|
|
460
520
|
|
|
@@ -486,15 +546,17 @@ impl NativePeerbitBackbone {
|
|
|
486
546
|
document_projection_encoded_document,
|
|
487
547
|
document_projection_signer,
|
|
488
548
|
)?;
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
549
|
+
Ok(
|
|
550
|
+
self.prepare_plain_entry_commit_latest_document_index_trim_hashes_inner(
|
|
551
|
+
wall_time,
|
|
552
|
+
logical,
|
|
553
|
+
fallback_gid,
|
|
554
|
+
entry_type,
|
|
555
|
+
meta_data,
|
|
556
|
+
payload_data,
|
|
557
|
+
trim_length_to,
|
|
558
|
+
document_index_commit,
|
|
559
|
+
)?,
|
|
498
560
|
)
|
|
499
561
|
}
|
|
500
562
|
|
|
@@ -524,15 +586,17 @@ impl NativePeerbitBackbone {
|
|
|
524
586
|
document_projection_encoded_document,
|
|
525
587
|
document_projection_signer,
|
|
526
588
|
)?;
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
589
|
+
Ok(
|
|
590
|
+
self.prepare_plain_entry_commit_latest_document_index_trim_hashes_inner(
|
|
591
|
+
wall_time,
|
|
592
|
+
logical,
|
|
593
|
+
fallback_gid,
|
|
594
|
+
entry_type,
|
|
595
|
+
meta_data,
|
|
596
|
+
payload_data,
|
|
597
|
+
trim_length_to,
|
|
598
|
+
document_index_commit,
|
|
599
|
+
)?,
|
|
536
600
|
)
|
|
537
601
|
}
|
|
538
602
|
|
|
@@ -565,18 +629,20 @@ impl NativePeerbitBackbone {
|
|
|
565
629
|
document_projection_encoded_document,
|
|
566
630
|
document_projection_signer,
|
|
567
631
|
)?;
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
632
|
+
Ok(
|
|
633
|
+
self.prepare_plain_entry_commit_no_next_document_index_compact_trim_hashes(
|
|
634
|
+
wall_time,
|
|
635
|
+
logical,
|
|
636
|
+
gid,
|
|
637
|
+
entry_type,
|
|
638
|
+
meta_data,
|
|
639
|
+
payload_data,
|
|
640
|
+
trim_length_to,
|
|
641
|
+
document_gid,
|
|
642
|
+
payload_size,
|
|
643
|
+
document_index_commit,
|
|
644
|
+
true,
|
|
645
|
+
)?,
|
|
580
646
|
)
|
|
581
647
|
}
|
|
582
648
|
|
|
@@ -619,7 +685,7 @@ impl NativePeerbitBackbone {
|
|
|
619
685
|
logical,
|
|
620
686
|
gid,
|
|
621
687
|
entry_type,
|
|
622
|
-
optional_bytes_from_js(meta_data)
|
|
688
|
+
optional_bytes_from_js(meta_data, "meta data")?,
|
|
623
689
|
&payload_data,
|
|
624
690
|
trim_length_to,
|
|
625
691
|
None,
|
|
@@ -655,7 +721,7 @@ impl NativePeerbitBackbone {
|
|
|
655
721
|
document_gid: String,
|
|
656
722
|
payload_size: u32,
|
|
657
723
|
document_index_commit: DocumentIndexAppendCommit,
|
|
658
|
-
) -> Result<Array,
|
|
724
|
+
) -> Result<Array, BackboneError> {
|
|
659
725
|
let entry_facts = self
|
|
660
726
|
.log
|
|
661
727
|
.prepare_entry_v0_plain_entry_commit_no_next_facts_core_profiled_and_put_with_builder(
|
|
@@ -665,7 +731,7 @@ impl NativePeerbitBackbone {
|
|
|
665
731
|
logical,
|
|
666
732
|
gid,
|
|
667
733
|
entry_type,
|
|
668
|
-
optional_bytes_from_js(meta_data)
|
|
734
|
+
optional_bytes_from_js(meta_data, "meta data")?,
|
|
669
735
|
payload_data.to_vec(),
|
|
670
736
|
None,
|
|
671
737
|
)?;
|
|
@@ -693,7 +759,7 @@ impl NativePeerbitBackbone {
|
|
|
693
759
|
payload_size: u32,
|
|
694
760
|
document_index_commit: DocumentIndexAppendCommit,
|
|
695
761
|
compact_row: bool,
|
|
696
|
-
) -> Result<Array,
|
|
762
|
+
) -> Result<Array, BackboneError> {
|
|
697
763
|
let delete_trimmed_document_heads = document_index_commit.delete_trimmed_heads;
|
|
698
764
|
let (entry_facts, trim_hashes) = self
|
|
699
765
|
.log
|
|
@@ -704,7 +770,7 @@ impl NativePeerbitBackbone {
|
|
|
704
770
|
logical,
|
|
705
771
|
gid,
|
|
706
772
|
entry_type,
|
|
707
|
-
optional_bytes_from_js(meta_data)
|
|
773
|
+
optional_bytes_from_js(meta_data, "meta data")?,
|
|
708
774
|
payload_data.to_vec(),
|
|
709
775
|
trim_length_to,
|
|
710
776
|
None,
|
|
@@ -743,7 +809,7 @@ impl NativePeerbitBackbone {
|
|
|
743
809
|
payload_data: Uint8Array,
|
|
744
810
|
trim_length_to: JsValue,
|
|
745
811
|
mut document_index_commit: DocumentIndexAppendCommit,
|
|
746
|
-
) -> Result<Array,
|
|
812
|
+
) -> Result<Array, BackboneError> {
|
|
747
813
|
let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
|
|
748
814
|
let (previous_context, gid, next_hashes) =
|
|
749
815
|
self.resolve_latest_document_append_context(&mut document_index_commit, fallback_gid)?;
|
|
@@ -759,7 +825,7 @@ impl NativePeerbitBackbone {
|
|
|
759
825
|
gid.clone(),
|
|
760
826
|
next_hashes,
|
|
761
827
|
entry_type,
|
|
762
|
-
optional_bytes_from_js(meta_data)
|
|
828
|
+
optional_bytes_from_js(meta_data, "meta data")?,
|
|
763
829
|
payload_data.to_vec(),
|
|
764
830
|
trim_length_to,
|
|
765
831
|
None,
|