@peerbit/native-backbone 0.1.2 → 0.1.4

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.
@@ -17,6 +17,7 @@ use crate::documents::{
17
17
  document_index_plain_put_payload_append_commit, DocumentIndexAppendCommit,
18
18
  DocumentIndexValuePrefix,
19
19
  };
20
+ use crate::error::BackboneError;
20
21
  use crate::js_interop::{
21
22
  ensure_same_len, has_duplicate_strings, optional_usize_from_js, required_bytes_from_array,
22
23
  strings_from_array, strings_to_array,
@@ -43,7 +44,7 @@ impl NativePeerbitBackbone {
43
44
  self_replicating: bool,
44
45
  resolve_trimmed_entries: bool,
45
46
  ) -> Result<Array, JsValue> {
46
- self.prepare_plain_storage_append_transaction_inner(
47
+ Ok(self.prepare_plain_storage_append_transaction_inner(
47
48
  wall_time,
48
49
  logical,
49
50
  gid,
@@ -60,7 +61,7 @@ impl NativePeerbitBackbone {
60
61
  None,
61
62
  true,
62
63
  None,
63
- )
64
+ )?)
64
65
  }
65
66
 
66
67
  #[allow(clippy::too_many_arguments)]
@@ -128,7 +129,7 @@ impl NativePeerbitBackbone {
128
129
  document_projection_encoded_document: JsValue,
129
130
  document_projection_signer: JsValue,
130
131
  ) -> Result<Array, JsValue> {
131
- self.prepare_plain_storage_append_transaction_inner(
132
+ Ok(self.prepare_plain_storage_append_transaction_inner(
132
133
  wall_time,
133
134
  logical,
134
135
  gid,
@@ -154,7 +155,7 @@ impl NativePeerbitBackbone {
154
155
  document_projection_encoded_document,
155
156
  document_projection_signer,
156
157
  )?),
157
- )
158
+ )?)
158
159
  }
159
160
 
160
161
  #[allow(clippy::too_many_arguments)]
@@ -191,21 +192,23 @@ impl NativePeerbitBackbone {
191
192
  document_projection_encoded_document,
192
193
  document_projection_signer,
193
194
  )?;
194
- self.prepare_plain_committed_storage_append_document_index_latest_transaction_inner(
195
- wall_time,
196
- logical,
197
- fallback_gid,
198
- entry_type,
199
- meta_data,
200
- payload_data,
201
- replicas,
202
- role_age_ms,
203
- now,
204
- self_hash,
205
- self_replicating,
206
- resolve_trimmed_entries,
207
- trim_length_to,
208
- document_index_commit,
195
+ Ok(
196
+ self.prepare_plain_committed_storage_append_document_index_latest_transaction_inner(
197
+ wall_time,
198
+ logical,
199
+ fallback_gid,
200
+ entry_type,
201
+ meta_data,
202
+ payload_data,
203
+ replicas,
204
+ role_age_ms,
205
+ now,
206
+ self_hash,
207
+ self_replicating,
208
+ resolve_trimmed_entries,
209
+ trim_length_to,
210
+ document_index_commit,
211
+ )?,
209
212
  )
210
213
  }
211
214
 
@@ -246,21 +249,23 @@ impl NativePeerbitBackbone {
246
249
  )?;
247
250
  document_index_commit.required_previous_signer_public_key =
248
251
  Some(required_previous_signer_public_key.to_vec());
249
- self.prepare_plain_committed_storage_append_document_index_latest_transaction_inner(
250
- wall_time,
251
- logical,
252
- fallback_gid,
253
- entry_type,
254
- meta_data,
255
- payload_data,
256
- replicas,
257
- role_age_ms,
258
- now,
259
- self_hash,
260
- self_replicating,
261
- resolve_trimmed_entries,
262
- trim_length_to,
263
- document_index_commit,
252
+ Ok(
253
+ self.prepare_plain_committed_storage_append_document_index_latest_transaction_inner(
254
+ wall_time,
255
+ logical,
256
+ fallback_gid,
257
+ entry_type,
258
+ meta_data,
259
+ payload_data,
260
+ replicas,
261
+ role_age_ms,
262
+ now,
263
+ self_hash,
264
+ self_replicating,
265
+ resolve_trimmed_entries,
266
+ trim_length_to,
267
+ document_index_commit,
268
+ )?,
264
269
  )
265
270
  }
266
271
 
@@ -296,21 +301,23 @@ impl NativePeerbitBackbone {
296
301
  document_projection_encoded_document,
297
302
  document_projection_signer,
298
303
  )?;
299
- self.prepare_plain_committed_storage_append_document_index_latest_transaction_inner(
300
- wall_time,
301
- logical,
302
- fallback_gid,
303
- entry_type,
304
- meta_data,
305
- payload_data,
306
- replicas,
307
- role_age_ms,
308
- now,
309
- self_hash,
310
- self_replicating,
311
- resolve_trimmed_entries,
312
- trim_length_to,
313
- document_index_commit,
304
+ Ok(
305
+ self.prepare_plain_committed_storage_append_document_index_latest_transaction_inner(
306
+ wall_time,
307
+ logical,
308
+ fallback_gid,
309
+ entry_type,
310
+ meta_data,
311
+ payload_data,
312
+ replicas,
313
+ role_age_ms,
314
+ now,
315
+ self_hash,
316
+ self_replicating,
317
+ resolve_trimmed_entries,
318
+ trim_length_to,
319
+ document_index_commit,
320
+ )?,
314
321
  )
315
322
  }
316
323
 
@@ -348,21 +355,22 @@ impl NativePeerbitBackbone {
348
355
  document_projection_encoded_document,
349
356
  document_projection_signer,
350
357
  )?;
351
- self.prepare_plain_committed_storage_append_document_index_latest_compact_transaction_inner(
352
- wall_time,
353
- logical,
354
- fallback_gid,
355
- entry_type,
356
- meta_data,
357
- payload_data,
358
- replicas,
359
- role_age_ms,
360
- now,
361
- self_hash,
362
- self_replicating,
363
- trim_length_to,
364
- document_index_commit,
365
- )
358
+ Ok(self
359
+ .prepare_plain_committed_storage_append_document_index_latest_compact_transaction_inner(
360
+ wall_time,
361
+ logical,
362
+ fallback_gid,
363
+ entry_type,
364
+ meta_data,
365
+ payload_data,
366
+ replicas,
367
+ role_age_ms,
368
+ now,
369
+ self_hash,
370
+ self_replicating,
371
+ trim_length_to,
372
+ document_index_commit,
373
+ )?)
366
374
  }
367
375
 
368
376
  #[allow(clippy::too_many_arguments)]
@@ -391,21 +399,22 @@ impl NativePeerbitBackbone {
391
399
  document_byte_element_index_limit,
392
400
  document_delete_trimmed_heads,
393
401
  )?;
394
- self.prepare_plain_committed_storage_append_document_index_latest_compact_transaction_inner(
395
- wall_time,
396
- logical,
397
- fallback_gid,
398
- entry_type,
399
- meta_data,
400
- payload_data,
401
- replicas,
402
- role_age_ms,
403
- now,
404
- self_hash,
405
- self_replicating,
406
- trim_length_to,
407
- document_index_commit,
408
- )
402
+ Ok(self
403
+ .prepare_plain_committed_storage_append_document_index_latest_compact_transaction_inner(
404
+ wall_time,
405
+ logical,
406
+ fallback_gid,
407
+ entry_type,
408
+ meta_data,
409
+ payload_data,
410
+ replicas,
411
+ role_age_ms,
412
+ now,
413
+ self_hash,
414
+ self_replicating,
415
+ trim_length_to,
416
+ document_index_commit,
417
+ )?)
409
418
  }
410
419
 
411
420
  #[allow(clippy::too_many_arguments)]
@@ -445,21 +454,22 @@ impl NativePeerbitBackbone {
445
454
  )?;
446
455
  document_index_commit.required_previous_signer_public_key =
447
456
  Some(required_previous_signer_public_key.to_vec());
448
- self.prepare_plain_committed_storage_append_document_index_latest_compact_transaction_inner(
449
- wall_time,
450
- logical,
451
- fallback_gid,
452
- entry_type,
453
- meta_data,
454
- payload_data,
455
- replicas,
456
- role_age_ms,
457
- now,
458
- self_hash,
459
- self_replicating,
460
- trim_length_to,
461
- document_index_commit,
462
- )
457
+ Ok(self
458
+ .prepare_plain_committed_storage_append_document_index_latest_compact_transaction_inner(
459
+ wall_time,
460
+ logical,
461
+ fallback_gid,
462
+ entry_type,
463
+ meta_data,
464
+ payload_data,
465
+ replicas,
466
+ role_age_ms,
467
+ now,
468
+ self_hash,
469
+ self_replicating,
470
+ trim_length_to,
471
+ document_index_commit,
472
+ )?)
463
473
  }
464
474
 
465
475
  #[allow(clippy::too_many_arguments)]
@@ -494,21 +504,22 @@ impl NativePeerbitBackbone {
494
504
  document_projection_encoded_document,
495
505
  document_projection_signer,
496
506
  )?;
497
- self.prepare_plain_committed_storage_append_document_index_latest_compact_transaction_inner(
498
- wall_time,
499
- logical,
500
- fallback_gid,
501
- entry_type,
502
- meta_data,
503
- payload_data,
504
- replicas,
505
- role_age_ms,
506
- now,
507
- self_hash,
508
- self_replicating,
509
- trim_length_to,
510
- document_index_commit,
511
- )
507
+ Ok(self
508
+ .prepare_plain_committed_storage_append_document_index_latest_compact_transaction_inner(
509
+ wall_time,
510
+ logical,
511
+ fallback_gid,
512
+ entry_type,
513
+ meta_data,
514
+ payload_data,
515
+ replicas,
516
+ role_age_ms,
517
+ now,
518
+ self_hash,
519
+ self_replicating,
520
+ trim_length_to,
521
+ document_index_commit,
522
+ )?)
512
523
  }
513
524
 
514
525
  #[allow(clippy::too_many_arguments)]
@@ -542,21 +553,22 @@ impl NativePeerbitBackbone {
542
553
  document_projection_plan_id,
543
554
  document_projection_signer,
544
555
  )?;
545
- self.prepare_plain_committed_storage_append_document_index_latest_compact_transaction_inner(
546
- wall_time,
547
- logical,
548
- fallback_gid,
549
- entry_type,
550
- meta_data,
551
- payload_data,
552
- replicas,
553
- role_age_ms,
554
- now,
555
- self_hash,
556
- self_replicating,
557
- trim_length_to,
558
- document_index_commit,
559
- )
556
+ Ok(self
557
+ .prepare_plain_committed_storage_append_document_index_latest_compact_transaction_inner(
558
+ wall_time,
559
+ logical,
560
+ fallback_gid,
561
+ entry_type,
562
+ meta_data,
563
+ payload_data,
564
+ replicas,
565
+ role_age_ms,
566
+ now,
567
+ self_hash,
568
+ self_replicating,
569
+ trim_length_to,
570
+ document_index_commit,
571
+ )?)
560
572
  }
561
573
 
562
574
  #[allow(clippy::too_many_arguments)]
@@ -596,38 +608,39 @@ impl NativePeerbitBackbone {
596
608
  "batch document value prefixes",
597
609
  )?;
598
610
  let document_keys = strings_from_array(document_keys)?;
599
- self.prepare_plain_committed_storage_append_document_index_latest_batch_transaction_inner(
600
- wall_times,
601
- logicals,
602
- fallback_gids,
603
- entry_type,
604
- meta_datas,
605
- payload_datas,
606
- replicas,
607
- role_age_ms,
608
- now,
609
- self_hash,
610
- self_replicating,
611
- resolve_trimmed_entries,
612
- trim_length_to,
613
- &mut |index| {
614
- document_index_append_commit(
615
- document_keys[index as usize].clone(),
616
- required_bytes_from_array(
617
- &document_value_prefix_bytes,
618
- index,
619
- "document value prefix",
620
- )?
621
- .to_vec(),
622
- String::new(),
623
- document_byte_element_index_limit,
624
- document_delete_trimmed_heads,
625
- JsValue::UNDEFINED,
626
- JsValue::UNDEFINED,
627
- JsValue::UNDEFINED,
628
- )
629
- },
630
- )
611
+ Ok(self
612
+ .prepare_plain_committed_storage_append_document_index_latest_batch_transaction_inner(
613
+ wall_times,
614
+ logicals,
615
+ fallback_gids,
616
+ entry_type,
617
+ meta_datas,
618
+ payload_datas,
619
+ replicas,
620
+ role_age_ms,
621
+ now,
622
+ self_hash,
623
+ self_replicating,
624
+ resolve_trimmed_entries,
625
+ trim_length_to,
626
+ &mut |index| {
627
+ document_index_append_commit(
628
+ document_keys[index as usize].clone(),
629
+ required_bytes_from_array(
630
+ &document_value_prefix_bytes,
631
+ index,
632
+ "document value prefix",
633
+ )?
634
+ .to_vec(),
635
+ String::new(),
636
+ document_byte_element_index_limit,
637
+ document_delete_trimmed_heads,
638
+ JsValue::UNDEFINED,
639
+ JsValue::UNDEFINED,
640
+ JsValue::UNDEFINED,
641
+ )
642
+ },
643
+ )?)
631
644
  }
632
645
 
633
646
  #[allow(clippy::too_many_arguments)]
@@ -669,41 +682,42 @@ impl NativePeerbitBackbone {
669
682
  )?;
670
683
  let required_previous_signer_public_key = required_previous_signer_public_key.to_vec();
671
684
  let document_keys = strings_from_array(document_keys)?;
672
- self.prepare_plain_committed_storage_append_document_index_latest_batch_transaction_inner(
673
- wall_times,
674
- logicals,
675
- fallback_gids,
676
- entry_type,
677
- meta_datas,
678
- payload_datas,
679
- replicas,
680
- role_age_ms,
681
- now,
682
- self_hash,
683
- self_replicating,
684
- resolve_trimmed_entries,
685
- trim_length_to,
686
- &mut |index| {
687
- let mut document_index_commit = document_index_append_commit(
688
- document_keys[index as usize].clone(),
689
- required_bytes_from_array(
690
- &document_value_prefix_bytes,
691
- index,
692
- "document value prefix",
693
- )?
694
- .to_vec(),
695
- String::new(),
696
- document_byte_element_index_limit,
697
- document_delete_trimmed_heads,
698
- JsValue::UNDEFINED,
699
- JsValue::UNDEFINED,
700
- JsValue::UNDEFINED,
701
- )?;
702
- document_index_commit.required_previous_signer_public_key =
703
- Some(required_previous_signer_public_key.clone());
704
- Ok(document_index_commit)
705
- },
706
- )
685
+ Ok(self
686
+ .prepare_plain_committed_storage_append_document_index_latest_batch_transaction_inner(
687
+ wall_times,
688
+ logicals,
689
+ fallback_gids,
690
+ entry_type,
691
+ meta_datas,
692
+ payload_datas,
693
+ replicas,
694
+ role_age_ms,
695
+ now,
696
+ self_hash,
697
+ self_replicating,
698
+ resolve_trimmed_entries,
699
+ trim_length_to,
700
+ &mut |index| {
701
+ let mut document_index_commit = document_index_append_commit(
702
+ document_keys[index as usize].clone(),
703
+ required_bytes_from_array(
704
+ &document_value_prefix_bytes,
705
+ index,
706
+ "document value prefix",
707
+ )?
708
+ .to_vec(),
709
+ String::new(),
710
+ document_byte_element_index_limit,
711
+ document_delete_trimmed_heads,
712
+ JsValue::UNDEFINED,
713
+ JsValue::UNDEFINED,
714
+ JsValue::UNDEFINED,
715
+ )?;
716
+ document_index_commit.required_previous_signer_public_key =
717
+ Some(required_previous_signer_public_key.clone());
718
+ Ok(document_index_commit)
719
+ },
720
+ )?)
707
721
  }
708
722
 
709
723
  #[allow(clippy::too_many_arguments)]
@@ -762,7 +776,7 @@ impl NativePeerbitBackbone {
762
776
  JsValue::UNDEFINED,
763
777
  )?);
764
778
  }
765
- self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
779
+ Ok(self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
766
780
  wall_times,
767
781
  logicals,
768
782
  fallback_gids,
@@ -777,7 +791,7 @@ impl NativePeerbitBackbone {
777
791
  trim_length_to,
778
792
  &document_keys,
779
793
  document_index_commits,
780
- )
794
+ )?)
781
795
  }
782
796
 
783
797
  #[allow(clippy::too_many_arguments)]
@@ -820,7 +834,7 @@ impl NativePeerbitBackbone {
820
834
  document_delete_trimmed_heads,
821
835
  )?);
822
836
  }
823
- self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
837
+ Ok(self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
824
838
  wall_times,
825
839
  logicals,
826
840
  fallback_gids,
@@ -835,7 +849,7 @@ impl NativePeerbitBackbone {
835
849
  trim_length_to,
836
850
  &document_keys,
837
851
  document_index_commits,
838
- )
852
+ )?)
839
853
  }
840
854
 
841
855
  #[allow(clippy::too_many_arguments)]
@@ -899,7 +913,7 @@ impl NativePeerbitBackbone {
899
913
  Some(required_previous_signer_public_key.clone());
900
914
  document_index_commits.push(document_index_commit);
901
915
  }
902
- self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
916
+ Ok(self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
903
917
  wall_times,
904
918
  logicals,
905
919
  fallback_gids,
@@ -914,7 +928,7 @@ impl NativePeerbitBackbone {
914
928
  trim_length_to,
915
929
  &document_keys,
916
930
  document_index_commits,
917
- )
931
+ )?)
918
932
  }
919
933
 
920
934
  #[allow(clippy::too_many_arguments)]
@@ -957,36 +971,37 @@ impl NativePeerbitBackbone {
957
971
  &document_projection_signers,
958
972
  )?;
959
973
  let document_keys = strings_from_array(document_keys)?;
960
- self.prepare_plain_committed_storage_append_document_index_latest_batch_transaction_inner(
961
- wall_times,
962
- logicals,
963
- fallback_gids,
964
- entry_type,
965
- meta_datas,
966
- payload_datas,
967
- replicas,
968
- role_age_ms,
969
- now,
970
- self_hash,
971
- self_replicating,
972
- resolve_trimmed_entries,
973
- trim_length_to,
974
- &mut |index| {
975
- let encoded_document = required_projection_encoded_document(
976
- &document_projection_encoded_documents,
977
- index,
978
- )?;
979
- document_index_cached_projection_append_commit(
980
- document_keys[index as usize].clone(),
981
- String::new(),
982
- document_byte_element_index_limit,
983
- document_delete_trimmed_heads,
984
- document_projection_plan_ids.get_index(index),
985
- encoded_document,
986
- document_projection_signers.get(index),
987
- )
988
- },
989
- )
974
+ Ok(self
975
+ .prepare_plain_committed_storage_append_document_index_latest_batch_transaction_inner(
976
+ wall_times,
977
+ logicals,
978
+ fallback_gids,
979
+ entry_type,
980
+ meta_datas,
981
+ payload_datas,
982
+ replicas,
983
+ role_age_ms,
984
+ now,
985
+ self_hash,
986
+ self_replicating,
987
+ resolve_trimmed_entries,
988
+ trim_length_to,
989
+ &mut |index| {
990
+ let encoded_document = required_projection_encoded_document(
991
+ &document_projection_encoded_documents,
992
+ index,
993
+ )?;
994
+ document_index_cached_projection_append_commit(
995
+ document_keys[index as usize].clone(),
996
+ String::new(),
997
+ document_byte_element_index_limit,
998
+ document_delete_trimmed_heads,
999
+ document_projection_plan_ids.get_index(index),
1000
+ encoded_document,
1001
+ document_projection_signers.get(index),
1002
+ )
1003
+ },
1004
+ )?)
990
1005
  }
991
1006
 
992
1007
  #[allow(clippy::too_many_arguments)]
@@ -1031,39 +1046,40 @@ impl NativePeerbitBackbone {
1031
1046
  )?;
1032
1047
  let required_previous_signer_public_key = required_previous_signer_public_key.to_vec();
1033
1048
  let document_keys = strings_from_array(document_keys)?;
1034
- self.prepare_plain_committed_storage_append_document_index_latest_batch_transaction_inner(
1035
- wall_times,
1036
- logicals,
1037
- fallback_gids,
1038
- entry_type,
1039
- meta_datas,
1040
- payload_datas,
1041
- replicas,
1042
- role_age_ms,
1043
- now,
1044
- self_hash,
1045
- self_replicating,
1046
- resolve_trimmed_entries,
1047
- trim_length_to,
1048
- &mut |index| {
1049
- let encoded_document = required_projection_encoded_document(
1050
- &document_projection_encoded_documents,
1051
- index,
1052
- )?;
1053
- let mut document_index_commit = document_index_cached_projection_append_commit(
1054
- document_keys[index as usize].clone(),
1055
- String::new(),
1056
- document_byte_element_index_limit,
1057
- document_delete_trimmed_heads,
1058
- document_projection_plan_ids.get_index(index),
1059
- encoded_document,
1060
- document_projection_signers.get(index),
1061
- )?;
1062
- document_index_commit.required_previous_signer_public_key =
1063
- Some(required_previous_signer_public_key.clone());
1064
- Ok(document_index_commit)
1065
- },
1066
- )
1049
+ Ok(self
1050
+ .prepare_plain_committed_storage_append_document_index_latest_batch_transaction_inner(
1051
+ wall_times,
1052
+ logicals,
1053
+ fallback_gids,
1054
+ entry_type,
1055
+ meta_datas,
1056
+ payload_datas,
1057
+ replicas,
1058
+ role_age_ms,
1059
+ now,
1060
+ self_hash,
1061
+ self_replicating,
1062
+ resolve_trimmed_entries,
1063
+ trim_length_to,
1064
+ &mut |index| {
1065
+ let encoded_document = required_projection_encoded_document(
1066
+ &document_projection_encoded_documents,
1067
+ index,
1068
+ )?;
1069
+ let mut document_index_commit = document_index_cached_projection_append_commit(
1070
+ document_keys[index as usize].clone(),
1071
+ String::new(),
1072
+ document_byte_element_index_limit,
1073
+ document_delete_trimmed_heads,
1074
+ document_projection_plan_ids.get_index(index),
1075
+ encoded_document,
1076
+ document_projection_signers.get(index),
1077
+ )?;
1078
+ document_index_commit.required_previous_signer_public_key =
1079
+ Some(required_previous_signer_public_key.clone());
1080
+ Ok(document_index_commit)
1081
+ },
1082
+ )?)
1067
1083
  }
1068
1084
 
1069
1085
  #[allow(clippy::too_many_arguments)]
@@ -1123,7 +1139,7 @@ impl NativePeerbitBackbone {
1123
1139
  document_projection_signers.get(index_u32),
1124
1140
  )?);
1125
1141
  }
1126
- self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
1142
+ Ok(self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
1127
1143
  wall_times,
1128
1144
  logicals,
1129
1145
  fallback_gids,
@@ -1138,7 +1154,7 @@ impl NativePeerbitBackbone {
1138
1154
  trim_length_to,
1139
1155
  &document_keys,
1140
1156
  document_index_commits,
1141
- )
1157
+ )?)
1142
1158
  }
1143
1159
 
1144
1160
  #[allow(clippy::too_many_arguments)]
@@ -1203,7 +1219,7 @@ impl NativePeerbitBackbone {
1203
1219
  Some(required_previous_signer_public_key.clone());
1204
1220
  document_index_commits.push(document_index_commit);
1205
1221
  }
1206
- self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
1222
+ Ok(self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
1207
1223
  wall_times,
1208
1224
  logicals,
1209
1225
  fallback_gids,
@@ -1218,7 +1234,7 @@ impl NativePeerbitBackbone {
1218
1234
  trim_length_to,
1219
1235
  &document_keys,
1220
1236
  document_index_commits,
1221
- )
1237
+ )?)
1222
1238
  }
1223
1239
 
1224
1240
  #[allow(clippy::too_many_arguments)]
@@ -1274,7 +1290,7 @@ impl NativePeerbitBackbone {
1274
1290
  )?,
1275
1291
  );
1276
1292
  }
1277
- self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
1293
+ Ok(self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
1278
1294
  wall_times,
1279
1295
  logicals,
1280
1296
  fallback_gids,
@@ -1289,7 +1305,7 @@ impl NativePeerbitBackbone {
1289
1305
  trim_length_to,
1290
1306
  &document_keys,
1291
1307
  document_index_commits,
1292
- )
1308
+ )?)
1293
1309
  }
1294
1310
 
1295
1311
  #[allow(clippy::too_many_arguments)]
@@ -1310,7 +1326,7 @@ impl NativePeerbitBackbone {
1310
1326
  resolve_trimmed_entries: bool,
1311
1327
  trim_length_to: usize,
1312
1328
  ) -> Result<Array, JsValue> {
1313
- self.prepare_plain_storage_append_transaction_inner(
1329
+ Ok(self.prepare_plain_storage_append_transaction_inner(
1314
1330
  wall_time,
1315
1331
  logical,
1316
1332
  gid,
@@ -1327,7 +1343,7 @@ impl NativePeerbitBackbone {
1327
1343
  Some(trim_length_to),
1328
1344
  true,
1329
1345
  None,
1330
- )
1346
+ )?)
1331
1347
  }
1332
1348
 
1333
1349
  #[allow(clippy::too_many_arguments)]
@@ -1397,7 +1413,7 @@ impl NativePeerbitBackbone {
1397
1413
  document_projection_signer: JsValue,
1398
1414
  trim_length_to: usize,
1399
1415
  ) -> Result<Array, JsValue> {
1400
- self.prepare_plain_storage_append_transaction_inner(
1416
+ Ok(self.prepare_plain_storage_append_transaction_inner(
1401
1417
  wall_time,
1402
1418
  logical,
1403
1419
  gid,
@@ -1423,7 +1439,7 @@ impl NativePeerbitBackbone {
1423
1439
  document_projection_encoded_document,
1424
1440
  document_projection_signer,
1425
1441
  )?),
1426
- )
1442
+ )?)
1427
1443
  }
1428
1444
  }
1429
1445
 
@@ -1445,7 +1461,7 @@ impl NativePeerbitBackbone {
1445
1461
  trim_length_to: Option<usize>,
1446
1462
  document_keys: &[String],
1447
1463
  document_index_commits: Vec<DocumentIndexAppendCommit>,
1448
- ) -> Result<Array, JsValue> {
1464
+ ) -> Result<Array, BackboneError> {
1449
1465
  if has_duplicate_strings(document_keys) {
1450
1466
  let out = Array::new();
1451
1467
  for (index, document_index_commit) in document_index_commits.into_iter().enumerate() {
@@ -1453,7 +1469,7 @@ impl NativePeerbitBackbone {
1453
1469
  let fallback_gid = fallback_gids
1454
1470
  .get(index_u32)
1455
1471
  .as_string()
1456
- .ok_or_else(|| JsValue::from_str("Expected batch fallback gid string"))?;
1472
+ .ok_or(BackboneError::ExpectedString("batch fallback gid"))?;
1457
1473
  let row = self
1458
1474
  .prepare_plain_committed_storage_append_document_index_latest_compact_transaction_inner(
1459
1475
  wall_times.get_index(index_u32),
@@ -1508,7 +1524,7 @@ impl NativePeerbitBackbone {
1508
1524
  resolve_trimmed_entries: bool,
1509
1525
  trim_length_to: JsValue,
1510
1526
  mut document_index_commit: DocumentIndexAppendCommit,
1511
- ) -> Result<Array, JsValue> {
1527
+ ) -> Result<Array, BackboneError> {
1512
1528
  let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
1513
1529
  let (_, gid, next_hashes) =
1514
1530
  self.resolve_latest_document_append_context(&mut document_index_commit, fallback_gid)?;
@@ -1551,15 +1567,17 @@ impl NativePeerbitBackbone {
1551
1567
  trim_length_to: JsValue,
1552
1568
  make_document_index_commit: &mut dyn FnMut(
1553
1569
  u32,
1554
- )
1555
- -> Result<DocumentIndexAppendCommit, JsValue>,
1556
- ) -> Result<Array, JsValue> {
1570
+ ) -> Result<
1571
+ DocumentIndexAppendCommit,
1572
+ BackboneError,
1573
+ >,
1574
+ ) -> Result<Array, BackboneError> {
1557
1575
  let batch_len = payload_datas.length() as usize;
1558
1576
  if batch_len == 0 {
1559
1577
  return Ok(Array::new());
1560
1578
  }
1561
1579
  let profile_enabled = self.append_profile_enabled;
1562
- let storage_append_started = profile_enabled.then(js_sys::Date::now);
1580
+ let storage_append_started = profile_enabled.then(crate::time::now_ms);
1563
1581
  self.reserve_document_batch(batch_len);
1564
1582
  let mut pending_appends = Vec::with_capacity(batch_len);
1565
1583
  let mut coordinate_inputs = Vec::with_capacity(batch_len);
@@ -1612,7 +1630,7 @@ impl NativePeerbitBackbone {
1612
1630
 
1613
1631
  let out = Array::new();
1614
1632
  for (pending, coordinate_facts) in pending_appends.into_iter().zip(coordinate_facts) {
1615
- let coordinate_core_started = profile_enabled.then(js_sys::Date::now);
1633
+ let coordinate_core_started = profile_enabled.then(crate::time::now_ms);
1616
1634
  self.commit_coordinate_core_from_compact_facts(
1617
1635
  &coordinate_facts,
1618
1636
  &pending.next_hashes,
@@ -1621,19 +1639,28 @@ impl NativePeerbitBackbone {
1621
1639
  pending.meta_bytes,
1622
1640
  );
1623
1641
  if let Some(started) = coordinate_core_started {
1624
- self.append_profile.coordinate_core_ms += js_sys::Date::now() - started;
1642
+ self.append_profile.coordinate_core_ms += crate::time::now_ms() - started;
1625
1643
  }
1626
1644
 
1627
- let result_row_started = profile_enabled.then(js_sys::Date::now);
1645
+ // Rebuild the frozen JS entry/trim rows from the owned pending state
1646
+ // at the emit boundary, timed against the same entry_row/trim_rows
1647
+ // profile counters the pre-lift inline build used.
1648
+ let entry_row = self.committed_entry_facts_to_row_profiled(&pending.entry_facts);
1649
+ let trim_rows = self.native_backbone_trim_entries_to_rows_profiled(
1650
+ pending.trimmed_entries,
1651
+ pending.resolve_trimmed_entries,
1652
+ );
1653
+
1654
+ let result_row_started = profile_enabled.then(crate::time::now_ms);
1628
1655
  let row = Array::new();
1629
- row.push(&pending.entry_row);
1656
+ row.push(&entry_row);
1630
1657
  row.push(&leader_samples_to_optional_rows(&coordinate_facts.leaders));
1631
1658
  row.push(&JsValue::from_bool(coordinate_facts.is_leader));
1632
1659
  row.push(&JsValue::from_bool(
1633
1660
  coordinate_facts.assigned_to_range_boundary,
1634
1661
  ));
1635
1662
  row.push(&coordinate_plan_to_row(&self.resolution, &coordinate_facts));
1636
- row.push(&pending.trim_rows);
1663
+ row.push(&trim_rows);
1637
1664
  row.push(&strings_to_array(pending.trim_hashes));
1638
1665
  row.push(&JsValue::from_bool(
1639
1666
  pending.document_trimmed_heads_processed,
@@ -1647,12 +1674,12 @@ impl NativePeerbitBackbone {
1647
1674
  );
1648
1675
  out.push(&row);
1649
1676
  if let Some(started) = result_row_started {
1650
- self.append_profile.result_row_ms += js_sys::Date::now() - started;
1677
+ self.append_profile.result_row_ms += crate::time::now_ms() - started;
1651
1678
  }
1652
1679
  }
1653
1680
 
1654
1681
  if let Some(started) = storage_append_started {
1655
- self.append_profile.storage_append_inner_ms += js_sys::Date::now() - started;
1682
+ self.append_profile.storage_append_inner_ms += crate::time::now_ms() - started;
1656
1683
  }
1657
1684
  Ok(out)
1658
1685
  }
@@ -1676,16 +1703,18 @@ impl NativePeerbitBackbone {
1676
1703
  trim_length_to: &JsValue,
1677
1704
  make_document_index_commit: &mut dyn FnMut(
1678
1705
  u32,
1679
- )
1680
- -> Result<DocumentIndexAppendCommit, JsValue>,
1706
+ ) -> Result<
1707
+ DocumentIndexAppendCommit,
1708
+ BackboneError,
1709
+ >,
1681
1710
  pending_appends: &mut Vec<LatestBatchPendingAppend>,
1682
1711
  coordinate_inputs: &mut Vec<NativeLocalAppendCompactInput>,
1683
- ) -> Result<(), JsValue> {
1712
+ ) -> Result<(), BackboneError> {
1684
1713
  let profile_enabled = self.append_profile_enabled;
1685
1714
  let fallback_gid = fallback_gids
1686
1715
  .get(index)
1687
1716
  .as_string()
1688
- .ok_or_else(|| JsValue::from_str("Expected batch fallback gid string"))?;
1717
+ .ok_or(BackboneError::ExpectedString("batch fallback gid"))?;
1689
1718
  let mut document_index_commit = make_document_index_commit(index)?;
1690
1719
  let payload_data = required_bytes_from_array(payload_datas, index, "payload")?;
1691
1720
  let trim_length_to = optional_usize_from_js(trim_length_to.clone(), "trimLengthTo")?;
@@ -1696,11 +1725,11 @@ impl NativePeerbitBackbone {
1696
1725
  self.validate_document_index_required_previous_signer(&document_index_commit)?;
1697
1726
 
1698
1727
  let (meta_data, payload_data) =
1699
- self.copy_append_inputs_profiled(meta_datas.get(index), &payload_data);
1728
+ self.copy_append_inputs_profiled(meta_datas.get(index), &payload_data)?;
1700
1729
 
1701
1730
  let wall_time = wall_times.get_index(index);
1702
- let (entry_facts, trim_hashes, entry_row, trim_rows) = self
1703
- .prepare_committed_log_append_rows_profiled(
1731
+ let (entry_facts, trimmed_entries, trim_hashes) = self
1732
+ .prepare_committed_log_append_owned_profiled(
1704
1733
  wall_time,
1705
1734
  logicals.get_index(index),
1706
1735
  gid.clone(),
@@ -1737,22 +1766,27 @@ impl NativePeerbitBackbone {
1737
1766
  next_hashes: next_hashes.clone(),
1738
1767
  delete_hashes: trim_hashes.clone(),
1739
1768
  });
1769
+ // Keep the entry hash for the document-index put; `entry_facts` itself
1770
+ // moves into the pending state so the JS entry row is rebuilt only when
1771
+ // the batch is emitted.
1772
+ let entry_hash = entry_facts.hash.clone();
1740
1773
  let mut pending_append = LatestBatchPendingAppend {
1741
1774
  wall_time,
1742
1775
  next_hashes,
1743
1776
  meta_bytes: entry_facts.meta_bytes.clone(),
1744
1777
  trim_hashes,
1745
- entry_row,
1746
- trim_rows,
1778
+ entry_facts,
1779
+ trimmed_entries,
1780
+ resolve_trimmed_entries,
1747
1781
  document_trimmed_heads_processed: false,
1748
1782
  previous_document_context,
1749
1783
  };
1750
1784
 
1751
- let document_index_started = profile_enabled.then(js_sys::Date::now);
1785
+ let document_index_started = profile_enabled.then(crate::time::now_ms);
1752
1786
  let prepared_document_put = match self.prepare_document_index_append_put(
1753
1787
  document_index_commit,
1754
1788
  wall_time,
1755
- &entry_facts.hash,
1789
+ &entry_hash,
1756
1790
  &gid,
1757
1791
  payload_size,
1758
1792
  None,
@@ -1770,7 +1804,7 @@ impl NativePeerbitBackbone {
1770
1804
  && self.delete_documents_by_context_heads_profiled(&pending_append.trim_hashes);
1771
1805
  pending_append.document_trimmed_heads_processed = document_trimmed_heads_processed;
1772
1806
  if let Some(started) = document_index_started {
1773
- self.append_profile.document_index_commit_ms += js_sys::Date::now() - started;
1807
+ self.append_profile.document_index_commit_ms += crate::time::now_ms() - started;
1774
1808
  }
1775
1809
  pending_appends.push(pending_append);
1776
1810
  Ok(())
@@ -1786,7 +1820,7 @@ impl NativePeerbitBackbone {
1786
1820
  now: &str,
1787
1821
  self_hash: &str,
1788
1822
  self_replicating: bool,
1789
- ) -> Result<(), JsValue> {
1823
+ ) -> Result<(), BackboneError> {
1790
1824
  if coordinate_inputs.is_empty() {
1791
1825
  return Ok(());
1792
1826
  }
@@ -1829,9 +1863,9 @@ impl NativePeerbitBackbone {
1829
1863
  self_replicating: bool,
1830
1864
  trim_length_to: Option<usize>,
1831
1865
  document_index_commits: Vec<DocumentIndexAppendCommit>,
1832
- ) -> Result<Array, JsValue> {
1866
+ ) -> Result<Array, BackboneError> {
1833
1867
  let profile_enabled = self.append_profile_enabled;
1834
- let storage_append_started = profile_enabled.then(js_sys::Date::now);
1868
+ let storage_append_started = profile_enabled.then(crate::time::now_ms);
1835
1869
  let batch_len = document_index_commits.len();
1836
1870
  self.reserve_document_batch(batch_len);
1837
1871
  let mut pending_appends = Vec::with_capacity(batch_len);
@@ -1842,7 +1876,7 @@ impl NativePeerbitBackbone {
1842
1876
  let fallback_gid = fallback_gids
1843
1877
  .get(index_u32)
1844
1878
  .as_string()
1845
- .ok_or_else(|| JsValue::from_str("Expected batch fallback gid string"))?;
1879
+ .ok_or(BackboneError::ExpectedString("batch fallback gid"))?;
1846
1880
  let payload_bytes = required_bytes_from_array(&payload_datas, index_u32, "payload")?;
1847
1881
  let payload_size = payload_bytes.length();
1848
1882
  let delete_trimmed_document_heads = document_index_commit.delete_trimmed_heads;
@@ -1851,7 +1885,7 @@ impl NativePeerbitBackbone {
1851
1885
  self.validate_document_index_required_previous_signer(&document_index_commit)?;
1852
1886
 
1853
1887
  let (meta_data, payload_data) =
1854
- self.copy_append_inputs_profiled(meta_datas.get(index_u32), &payload_bytes);
1888
+ self.copy_append_inputs_profiled(meta_datas.get(index_u32), &payload_bytes)?;
1855
1889
 
1856
1890
  let (entry_facts, trim_hashes) = self.prepare_latest_log_append_profiled(
1857
1891
  wall_times.get_index(index_u32),
@@ -1910,7 +1944,7 @@ impl NativePeerbitBackbone {
1910
1944
 
1911
1945
  let out = Array::new();
1912
1946
  for (pending, coordinate_facts) in pending_appends.into_iter().zip(coordinate_facts) {
1913
- let coordinate_core_started = profile_enabled.then(js_sys::Date::now);
1947
+ let coordinate_core_started = profile_enabled.then(crate::time::now_ms);
1914
1948
  self.commit_coordinate_core_from_compact_facts(
1915
1949
  &coordinate_facts,
1916
1950
  &pending.entry_facts.next,
@@ -1919,7 +1953,7 @@ impl NativePeerbitBackbone {
1919
1953
  pending.entry_facts.meta_bytes.clone(),
1920
1954
  );
1921
1955
  if let Some(started) = coordinate_core_started {
1922
- self.append_profile.coordinate_core_ms += js_sys::Date::now() - started;
1956
+ self.append_profile.coordinate_core_ms += crate::time::now_ms() - started;
1923
1957
  }
1924
1958
 
1925
1959
  let document_trimmed_heads_processed = self.commit_append_document_index_profiled(
@@ -1933,7 +1967,7 @@ impl NativePeerbitBackbone {
1933
1967
  &pending.trim_hashes,
1934
1968
  )?;
1935
1969
 
1936
- let result_row_started = profile_enabled.then(js_sys::Date::now);
1970
+ let result_row_started = profile_enabled.then(crate::time::now_ms);
1937
1971
  let row = latest_compact_entry_row(
1938
1972
  &self.resolution,
1939
1973
  pending.entry_facts,
@@ -1950,12 +1984,12 @@ impl NativePeerbitBackbone {
1950
1984
  );
1951
1985
  out.push(&row);
1952
1986
  if let Some(started) = result_row_started {
1953
- self.append_profile.result_row_ms += js_sys::Date::now() - started;
1987
+ self.append_profile.result_row_ms += crate::time::now_ms() - started;
1954
1988
  }
1955
1989
  }
1956
1990
 
1957
1991
  if let Some(started) = storage_append_started {
1958
- self.append_profile.storage_append_inner_ms += js_sys::Date::now() - started;
1992
+ self.append_profile.storage_append_inner_ms += crate::time::now_ms() - started;
1959
1993
  }
1960
1994
  Ok(out)
1961
1995
  }
@@ -1976,16 +2010,17 @@ impl NativePeerbitBackbone {
1976
2010
  self_replicating: bool,
1977
2011
  trim_length_to: Option<usize>,
1978
2012
  mut document_index_commit: DocumentIndexAppendCommit,
1979
- ) -> Result<Array, JsValue> {
2013
+ ) -> Result<Array, BackboneError> {
1980
2014
  let profile_enabled = self.append_profile_enabled;
1981
- let storage_append_started = profile_enabled.then(js_sys::Date::now);
2015
+ let storage_append_started = profile_enabled.then(crate::time::now_ms);
1982
2016
  let payload_size = payload_data.length();
1983
2017
  let delete_trimmed_document_heads = document_index_commit.delete_trimmed_heads;
1984
2018
  let (previous_document_context, gid, next_hashes) =
1985
2019
  self.resolve_latest_document_append_context(&mut document_index_commit, fallback_gid)?;
1986
2020
  self.validate_document_index_required_previous_signer(&document_index_commit)?;
1987
2021
 
1988
- let (meta_data, payload_data) = self.copy_append_inputs_profiled(meta_data, &payload_data);
2022
+ let (meta_data, payload_data) =
2023
+ self.copy_append_inputs_profiled(meta_data, &payload_data)?;
1989
2024
 
1990
2025
  let (entry_facts, trim_hashes) = self.prepare_latest_log_append_profiled(
1991
2026
  wall_time,
@@ -2000,7 +2035,7 @@ impl NativePeerbitBackbone {
2000
2035
 
2001
2036
  let hash_number = self.hash_number_profiled(&entry_facts.hash_digest_bytes)?;
2002
2037
 
2003
- let coordinate_plan_started = profile_enabled.then(js_sys::Date::now);
2038
+ let coordinate_plan_started = profile_enabled.then(crate::time::now_ms);
2004
2039
  let coordinate_facts = commit_local_append_for_gid_compact_core(
2005
2040
  &mut self.shared_log,
2006
2041
  entry_facts.hash.clone(),
@@ -2017,10 +2052,10 @@ impl NativePeerbitBackbone {
2017
2052
  true,
2018
2053
  )?;
2019
2054
  if let Some(started) = coordinate_plan_started {
2020
- self.append_profile.coordinate_plan_ms += js_sys::Date::now() - started;
2055
+ self.append_profile.coordinate_plan_ms += crate::time::now_ms() - started;
2021
2056
  }
2022
2057
 
2023
- let coordinate_core_started = profile_enabled.then(js_sys::Date::now);
2058
+ let coordinate_core_started = profile_enabled.then(crate::time::now_ms);
2024
2059
  self.commit_coordinate_core_from_compact_facts(
2025
2060
  &coordinate_facts,
2026
2061
  &entry_facts.next,
@@ -2029,7 +2064,7 @@ impl NativePeerbitBackbone {
2029
2064
  entry_facts.meta_bytes.clone(),
2030
2065
  );
2031
2066
  if let Some(started) = coordinate_core_started {
2032
- self.append_profile.coordinate_core_ms += js_sys::Date::now() - started;
2067
+ self.append_profile.coordinate_core_ms += crate::time::now_ms() - started;
2033
2068
  }
2034
2069
 
2035
2070
  let document_trimmed_heads_processed = self.commit_append_document_index_profiled(
@@ -2043,7 +2078,7 @@ impl NativePeerbitBackbone {
2043
2078
  &trim_hashes,
2044
2079
  )?;
2045
2080
 
2046
- let result_row_started = profile_enabled.then(js_sys::Date::now);
2081
+ let result_row_started = profile_enabled.then(crate::time::now_ms);
2047
2082
  let out = latest_compact_entry_row(
2048
2083
  &self.resolution,
2049
2084
  entry_facts,
@@ -2053,11 +2088,30 @@ impl NativePeerbitBackbone {
2053
2088
  previous_document_context.as_ref(),
2054
2089
  );
2055
2090
  if let Some(started) = result_row_started {
2056
- self.append_profile.result_row_ms += js_sys::Date::now() - started;
2091
+ self.append_profile.result_row_ms += crate::time::now_ms() - started;
2057
2092
  }
2058
2093
  if let Some(started) = storage_append_started {
2059
- self.append_profile.storage_append_inner_ms += js_sys::Date::now() - started;
2094
+ self.append_profile.storage_append_inner_ms += crate::time::now_ms() - started;
2060
2095
  }
2061
2096
  Ok(out)
2062
2097
  }
2063
2098
  }
2099
+
2100
+ #[cfg(test)]
2101
+ mod tests {
2102
+ use crate::error::BackboneError;
2103
+
2104
+ // The required-previous-signer validator now reports typed variants. Pin
2105
+ // their Display so the thrown strings stay byte-for-byte with master.
2106
+ #[test]
2107
+ fn document_signer_variants_render_verbatim() {
2108
+ assert_eq!(
2109
+ BackboneError::PreviousDocumentSignerPublicKeyUnavailable.to_string(),
2110
+ "Previous document signer public key unavailable"
2111
+ );
2112
+ assert_eq!(
2113
+ BackboneError::PreviousDocumentSignerPublicKeyPolicyMismatch.to_string(),
2114
+ "Previous document signer public key did not match native policy"
2115
+ );
2116
+ }
2117
+ }