@peerbit/native-backbone 0.2.9 → 0.2.11

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.
@@ -1,5 +1,5 @@
1
1
  use js_sys::{Array, Uint8Array};
2
- use peerbit_log_rust::LogIndexEntry;
2
+ use peerbit_log_rust::{LogIndexEntry, NativeCommittedEntryFacts};
3
3
  use wasm_bindgen::prelude::*;
4
4
 
5
5
  use crate::append_tx::{
@@ -41,8 +41,82 @@ fn log_trim_entries_to_rows(values: Vec<LogIndexEntry>) -> Array {
41
41
  out
42
42
  }
43
43
 
44
+ /// Additive compact row carrying the gid paired with every trimmed hash.
45
+ /// The legacy hash-only compact row remains frozen in `append_tx::mod`.
46
+ fn compact_committed_entry_facts_trim_refs_to_row(
47
+ entry: &NativeCommittedEntryFacts,
48
+ trim_hashes: Vec<String>,
49
+ trim_gids: Vec<String>,
50
+ document_trimmed_heads_processed: bool,
51
+ ) -> Array {
52
+ let row = Array::new();
53
+ row.push(&JsValue::from_str(&entry.hash));
54
+ row.push(&JsValue::from_f64(entry.byte_length as f64));
55
+ row.push(&Uint8Array::from(entry.meta_bytes.as_slice()));
56
+ row.push(&Uint8Array::from(entry.hash_digest_bytes.as_slice()));
57
+ row.push(&strings_to_array(trim_hashes));
58
+ row.push(&strings_to_array(trim_gids));
59
+ row.push(&JsValue::from_bool(document_trimmed_heads_processed));
60
+ row
61
+ }
62
+
44
63
  #[wasm_bindgen]
45
64
  impl NativePeerbitBackbone {
65
+ /// Compact counterpart to `prepare_plain_entry_commit_facts`. This is an
66
+ /// additive export so older native bundles retain their frozen row shape.
67
+ #[allow(clippy::too_many_arguments)]
68
+ pub fn prepare_plain_entry_commit_facts_trim_refs(
69
+ &mut self,
70
+ wall_time: u64,
71
+ logical: u32,
72
+ gid: String,
73
+ next: Array,
74
+ entry_type: u8,
75
+ meta_data: JsValue,
76
+ payload_data: Uint8Array,
77
+ trim_length_to: usize,
78
+ ) -> Result<Array, JsValue> {
79
+ let (entry_facts, trim_refs) = if next.length() == 0 {
80
+ self.log
81
+ .prepare_entry_v0_plain_entry_commit_no_next_facts_core_profiled_and_put_with_builder_trim_refs(
82
+ &self.builder,
83
+ &mut self.blocks,
84
+ wall_time,
85
+ logical,
86
+ gid,
87
+ entry_type,
88
+ optional_bytes_from_js(meta_data, "meta data")?,
89
+ payload_data.to_vec(),
90
+ trim_length_to,
91
+ None,
92
+ )?
93
+ } else {
94
+ self.log
95
+ .prepare_entry_v0_plain_entry_commit_facts_core_profiled_and_put_with_builder_trim_refs(
96
+ &self.builder,
97
+ &mut self.blocks,
98
+ wall_time,
99
+ logical,
100
+ gid,
101
+ strings_from_array(next)?,
102
+ entry_type,
103
+ optional_bytes_from_js(meta_data, "meta data")?,
104
+ payload_data.to_vec(),
105
+ Some(trim_length_to),
106
+ None,
107
+ )?
108
+ };
109
+ let out = Array::new();
110
+ out.push(&committed_entry_facts_to_row(
111
+ &entry_facts,
112
+ !entry_facts.next.is_empty(),
113
+ ));
114
+ let (trim_hashes, trim_gids) = trim_refs.into_iter().unzip();
115
+ out.push(&strings_to_array(trim_hashes));
116
+ out.push(&strings_to_array(trim_gids));
117
+ Ok(out)
118
+ }
119
+
46
120
  #[allow(clippy::too_many_arguments)]
47
121
  pub fn prepare_plain_entry_commit_facts(
48
122
  &mut self,
@@ -472,6 +546,55 @@ impl NativePeerbitBackbone {
472
546
  )
473
547
  }
474
548
 
549
+ /// Additive trim-ref counterpart to the compact inline document-index
550
+ /// append. The hash-only export above retains its frozen row layout.
551
+ #[allow(clippy::too_many_arguments)]
552
+ pub fn prepare_plain_entry_commit_no_next_facts_document_index_compact_trim_refs(
553
+ &mut self,
554
+ wall_time: u64,
555
+ logical: u32,
556
+ gid: String,
557
+ entry_type: u8,
558
+ meta_data: JsValue,
559
+ payload_data: Uint8Array,
560
+ trim_length_to: usize,
561
+ document_key: String,
562
+ document_value_prefix_bytes: Vec<u8>,
563
+ document_existing_created: String,
564
+ document_byte_element_index_limit: usize,
565
+ document_delete_trimmed_heads: bool,
566
+ document_projection_plan: JsValue,
567
+ document_projection_encoded_document: JsValue,
568
+ document_projection_signer: JsValue,
569
+ ) -> Result<Array, JsValue> {
570
+ let document_gid = gid.clone();
571
+ let payload_size = payload_data.length();
572
+ let document_index_commit = document_index_append_commit(
573
+ document_key,
574
+ document_value_prefix_bytes,
575
+ document_existing_created,
576
+ document_byte_element_index_limit,
577
+ document_delete_trimmed_heads,
578
+ document_projection_plan,
579
+ document_projection_encoded_document,
580
+ document_projection_signer,
581
+ )?;
582
+ Ok(
583
+ self.prepare_plain_entry_commit_no_next_document_index_compact_trim_refs(
584
+ wall_time,
585
+ logical,
586
+ gid,
587
+ entry_type,
588
+ meta_data,
589
+ payload_data,
590
+ trim_length_to,
591
+ document_gid,
592
+ payload_size,
593
+ document_index_commit,
594
+ )?,
595
+ )
596
+ }
597
+
475
598
  #[allow(clippy::too_many_arguments)]
476
599
  pub fn prepare_plain_entry_commit_no_next_facts_document_index_cached_plan_trim_hashes(
477
600
  &mut self,
@@ -560,6 +683,50 @@ impl NativePeerbitBackbone {
560
683
  )
561
684
  }
562
685
 
686
+ /// Additive trim-ref counterpart to the latest-context document-index
687
+ /// append. Gids are returned parallel to the existing trimmed hashes.
688
+ #[allow(clippy::too_many_arguments)]
689
+ pub fn prepare_plain_entry_commit_latest_facts_document_index_trim_refs(
690
+ &mut self,
691
+ wall_time: u64,
692
+ logical: u32,
693
+ fallback_gid: String,
694
+ entry_type: u8,
695
+ meta_data: JsValue,
696
+ payload_data: Uint8Array,
697
+ trim_length_to: JsValue,
698
+ document_key: String,
699
+ document_value_prefix_bytes: Vec<u8>,
700
+ document_byte_element_index_limit: usize,
701
+ document_delete_trimmed_heads: bool,
702
+ document_projection_plan: JsValue,
703
+ document_projection_encoded_document: JsValue,
704
+ document_projection_signer: JsValue,
705
+ ) -> Result<Array, JsValue> {
706
+ let document_index_commit = document_index_append_commit(
707
+ document_key,
708
+ document_value_prefix_bytes,
709
+ String::new(),
710
+ document_byte_element_index_limit,
711
+ document_delete_trimmed_heads,
712
+ document_projection_plan,
713
+ document_projection_encoded_document,
714
+ document_projection_signer,
715
+ )?;
716
+ Ok(
717
+ self.prepare_plain_entry_commit_latest_document_index_trim_refs_inner(
718
+ wall_time,
719
+ logical,
720
+ fallback_gid,
721
+ entry_type,
722
+ meta_data,
723
+ payload_data,
724
+ trim_length_to,
725
+ document_index_commit,
726
+ )?,
727
+ )
728
+ }
729
+
563
730
  #[allow(clippy::too_many_arguments)]
564
731
  pub fn prepare_plain_entry_commit_latest_facts_document_index_cached_plan_trim_hashes(
565
732
  &mut self,
@@ -600,6 +767,48 @@ impl NativePeerbitBackbone {
600
767
  )
601
768
  }
602
769
 
770
+ /// Cached-plan counterpart to
771
+ /// `prepare_plain_entry_commit_latest_facts_document_index_trim_refs`.
772
+ #[allow(clippy::too_many_arguments)]
773
+ pub fn prepare_plain_entry_commit_latest_facts_document_index_cached_plan_trim_refs(
774
+ &mut self,
775
+ wall_time: u64,
776
+ logical: u32,
777
+ fallback_gid: String,
778
+ entry_type: u8,
779
+ meta_data: JsValue,
780
+ payload_data: Uint8Array,
781
+ trim_length_to: JsValue,
782
+ document_key: String,
783
+ document_byte_element_index_limit: usize,
784
+ document_delete_trimmed_heads: bool,
785
+ document_projection_plan_id: u32,
786
+ document_projection_encoded_document: JsValue,
787
+ document_projection_signer: JsValue,
788
+ ) -> Result<Array, JsValue> {
789
+ let document_index_commit = document_index_cached_projection_append_commit(
790
+ document_key,
791
+ String::new(),
792
+ document_byte_element_index_limit,
793
+ document_delete_trimmed_heads,
794
+ document_projection_plan_id,
795
+ document_projection_encoded_document,
796
+ document_projection_signer,
797
+ )?;
798
+ Ok(
799
+ self.prepare_plain_entry_commit_latest_document_index_trim_refs_inner(
800
+ wall_time,
801
+ logical,
802
+ fallback_gid,
803
+ entry_type,
804
+ meta_data,
805
+ payload_data,
806
+ trim_length_to,
807
+ document_index_commit,
808
+ )?,
809
+ )
810
+ }
811
+
603
812
  #[allow(clippy::too_many_arguments)]
604
813
  pub fn prepare_plain_entry_commit_no_next_facts_document_index_cached_plan_compact_trim_hashes(
605
814
  &mut self,
@@ -646,6 +855,52 @@ impl NativePeerbitBackbone {
646
855
  )
647
856
  }
648
857
 
858
+ /// Additive trim-ref counterpart to the cached-plan compact append.
859
+ #[allow(clippy::too_many_arguments)]
860
+ pub fn prepare_plain_entry_commit_no_next_facts_document_index_cached_plan_compact_trim_refs(
861
+ &mut self,
862
+ wall_time: u64,
863
+ logical: u32,
864
+ gid: String,
865
+ entry_type: u8,
866
+ meta_data: JsValue,
867
+ payload_data: Uint8Array,
868
+ trim_length_to: usize,
869
+ document_key: String,
870
+ document_existing_created: String,
871
+ document_byte_element_index_limit: usize,
872
+ document_delete_trimmed_heads: bool,
873
+ document_projection_plan_id: u32,
874
+ document_projection_encoded_document: JsValue,
875
+ document_projection_signer: JsValue,
876
+ ) -> Result<Array, JsValue> {
877
+ let document_gid = gid.clone();
878
+ let payload_size = payload_data.length();
879
+ let document_index_commit = document_index_cached_projection_append_commit(
880
+ document_key,
881
+ document_existing_created,
882
+ document_byte_element_index_limit,
883
+ document_delete_trimmed_heads,
884
+ document_projection_plan_id,
885
+ document_projection_encoded_document,
886
+ document_projection_signer,
887
+ )?;
888
+ Ok(
889
+ self.prepare_plain_entry_commit_no_next_document_index_compact_trim_refs(
890
+ wall_time,
891
+ logical,
892
+ gid,
893
+ entry_type,
894
+ meta_data,
895
+ payload_data,
896
+ trim_length_to,
897
+ document_gid,
898
+ payload_size,
899
+ document_index_commit,
900
+ )?,
901
+ )
902
+ }
903
+
649
904
  #[allow(clippy::too_many_arguments)]
650
905
  pub fn prepare_plain_entry_commit_no_next_facts_document_index_cached_plan_compact_trim_hashes_plain_put_payload(
651
906
  &mut self,
@@ -706,6 +961,71 @@ impl NativePeerbitBackbone {
706
961
  document_trimmed_heads_processed,
707
962
  ))
708
963
  }
964
+
965
+ /// Additive trim-ref counterpart to the cached-plan compact append that
966
+ /// reuses the plain payload bytes for the document-index put.
967
+ #[allow(clippy::too_many_arguments)]
968
+ pub fn prepare_plain_entry_commit_no_next_facts_document_index_cached_plan_compact_trim_refs_plain_put_payload(
969
+ &mut self,
970
+ wall_time: u64,
971
+ logical: u32,
972
+ gid: String,
973
+ entry_type: u8,
974
+ meta_data: JsValue,
975
+ payload_data: Uint8Array,
976
+ trim_length_to: usize,
977
+ document_key: String,
978
+ document_existing_created: String,
979
+ document_byte_element_index_limit: usize,
980
+ document_delete_trimmed_heads: bool,
981
+ document_projection_plan_id: u32,
982
+ document_projection_signer: JsValue,
983
+ ) -> Result<Array, JsValue> {
984
+ let document_gid = gid.clone();
985
+ let payload_size = payload_data.length();
986
+ let payload_data = payload_data.to_vec();
987
+ let document_index_commit =
988
+ document_index_cached_projection_plain_put_payload_append_commit(
989
+ document_key,
990
+ document_existing_created,
991
+ document_byte_element_index_limit,
992
+ document_delete_trimmed_heads,
993
+ document_projection_plan_id,
994
+ document_projection_signer,
995
+ )?;
996
+ let delete_trimmed_document_heads = document_index_commit.delete_trimmed_heads;
997
+ let (entry_facts, trim_refs) = self
998
+ .log
999
+ .prepare_entry_v0_plain_entry_commit_no_next_facts_core_profiled_and_put_with_builder_trim_refs_borrowed(
1000
+ &self.builder,
1001
+ &mut self.blocks,
1002
+ wall_time,
1003
+ logical,
1004
+ gid,
1005
+ entry_type,
1006
+ optional_bytes_from_js(meta_data, "meta data")?,
1007
+ &payload_data,
1008
+ trim_length_to,
1009
+ None,
1010
+ )?;
1011
+ self.put_document_index_for_append_with_plain_put_payload(
1012
+ Some(document_index_commit),
1013
+ wall_time,
1014
+ &entry_facts.hash,
1015
+ &document_gid,
1016
+ payload_size,
1017
+ Some(&payload_data),
1018
+ )?;
1019
+ let (trim_hashes, trim_gids): (Vec<String>, Vec<String>) = trim_refs.into_iter().unzip();
1020
+ let document_trimmed_heads_processed = delete_trimmed_document_heads
1021
+ && self.delete_documents_by_context_heads_profiled(&trim_hashes);
1022
+ Ok(compact_committed_entry_facts_trim_refs_to_row(
1023
+ &entry_facts,
1024
+ trim_hashes,
1025
+ trim_gids,
1026
+ document_trimmed_heads_processed,
1027
+ ))
1028
+ }
709
1029
  }
710
1030
 
711
1031
  impl NativePeerbitBackbone {
@@ -798,6 +1118,53 @@ impl NativePeerbitBackbone {
798
1118
  Ok(out)
799
1119
  }
800
1120
 
1121
+ #[allow(clippy::too_many_arguments)]
1122
+ fn prepare_plain_entry_commit_no_next_document_index_compact_trim_refs(
1123
+ &mut self,
1124
+ wall_time: u64,
1125
+ logical: u32,
1126
+ gid: String,
1127
+ entry_type: u8,
1128
+ meta_data: JsValue,
1129
+ payload_data: Uint8Array,
1130
+ trim_length_to: usize,
1131
+ document_gid: String,
1132
+ payload_size: u32,
1133
+ document_index_commit: DocumentIndexAppendCommit,
1134
+ ) -> Result<Array, BackboneError> {
1135
+ let delete_trimmed_document_heads = document_index_commit.delete_trimmed_heads;
1136
+ let (entry_facts, trim_refs) = self
1137
+ .log
1138
+ .prepare_entry_v0_plain_entry_commit_no_next_facts_core_profiled_and_put_with_builder_trim_refs(
1139
+ &self.builder,
1140
+ &mut self.blocks,
1141
+ wall_time,
1142
+ logical,
1143
+ gid,
1144
+ entry_type,
1145
+ optional_bytes_from_js(meta_data, "meta data")?,
1146
+ payload_data.to_vec(),
1147
+ trim_length_to,
1148
+ None,
1149
+ )?;
1150
+ self.put_document_index_for_append(
1151
+ Some(document_index_commit),
1152
+ wall_time,
1153
+ &entry_facts.hash,
1154
+ &document_gid,
1155
+ payload_size,
1156
+ )?;
1157
+ let (trim_hashes, trim_gids): (Vec<String>, Vec<String>) = trim_refs.into_iter().unzip();
1158
+ let document_trimmed_heads_processed = delete_trimmed_document_heads
1159
+ && self.delete_documents_by_context_heads_profiled(&trim_hashes);
1160
+ Ok(compact_committed_entry_facts_trim_refs_to_row(
1161
+ &entry_facts,
1162
+ trim_hashes,
1163
+ trim_gids,
1164
+ document_trimmed_heads_processed,
1165
+ ))
1166
+ }
1167
+
801
1168
  #[allow(clippy::too_many_arguments)]
802
1169
  fn prepare_plain_entry_commit_latest_document_index_trim_hashes_inner(
803
1170
  &mut self,
@@ -854,4 +1221,63 @@ impl NativePeerbitBackbone {
854
1221
  );
855
1222
  Ok(out)
856
1223
  }
1224
+
1225
+ #[allow(clippy::too_many_arguments)]
1226
+ fn prepare_plain_entry_commit_latest_document_index_trim_refs_inner(
1227
+ &mut self,
1228
+ wall_time: u64,
1229
+ logical: u32,
1230
+ fallback_gid: String,
1231
+ entry_type: u8,
1232
+ meta_data: JsValue,
1233
+ payload_data: Uint8Array,
1234
+ trim_length_to: JsValue,
1235
+ mut document_index_commit: DocumentIndexAppendCommit,
1236
+ ) -> Result<Array, BackboneError> {
1237
+ let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
1238
+ let (previous_context, gid, next_hashes) =
1239
+ self.resolve_latest_document_append_context(&mut document_index_commit, fallback_gid)?;
1240
+ let delete_trimmed_document_heads = document_index_commit.delete_trimmed_heads;
1241
+ let payload_size = payload_data.length();
1242
+ let (entry_facts, trim_refs) = self
1243
+ .log
1244
+ .prepare_entry_v0_plain_entry_commit_facts_core_profiled_and_put_with_builder_trim_refs(
1245
+ &self.builder,
1246
+ &mut self.blocks,
1247
+ wall_time,
1248
+ logical,
1249
+ gid.clone(),
1250
+ next_hashes,
1251
+ entry_type,
1252
+ optional_bytes_from_js(meta_data, "meta data")?,
1253
+ payload_data.to_vec(),
1254
+ trim_length_to,
1255
+ None,
1256
+ )?;
1257
+ self.put_document_index_for_append(
1258
+ Some(document_index_commit),
1259
+ wall_time,
1260
+ &entry_facts.hash,
1261
+ &gid,
1262
+ payload_size,
1263
+ )?;
1264
+ let (trim_hashes, trim_gids): (Vec<String>, Vec<String>) = trim_refs.into_iter().unzip();
1265
+ let document_trimmed_heads_processed = delete_trimmed_document_heads
1266
+ && self.delete_documents_by_context_heads_profiled(&trim_hashes);
1267
+ let out = Array::new();
1268
+ out.push(&committed_entry_facts_to_row(
1269
+ &entry_facts,
1270
+ !entry_facts.next.is_empty(),
1271
+ ));
1272
+ out.push(&strings_to_array(trim_hashes));
1273
+ out.push(&strings_to_array(trim_gids));
1274
+ out.push(&JsValue::from_bool(document_trimmed_heads_processed));
1275
+ out.push(
1276
+ &previous_context
1277
+ .as_ref()
1278
+ .map(|context| document_context_facts_to_row(context).into())
1279
+ .unwrap_or(JsValue::UNDEFINED),
1280
+ );
1281
+ Ok(out)
1282
+ }
857
1283
  }
@@ -32,6 +32,7 @@ struct LatestCompactBatchPendingAppend {
32
32
  gid: String,
33
33
  entry_facts: NativeCommittedEntryFacts,
34
34
  trim_hashes: Vec<String>,
35
+ trim_gids: Vec<String>,
35
36
  document_index_commit: DocumentIndexAppendCommit,
36
37
  previous_document_context: Option<DocumentContextFacts>,
37
38
  delete_trimmed_document_heads: bool,
@@ -44,6 +45,7 @@ struct LatestBatchPendingAppend {
44
45
  next_hashes: Vec<String>,
45
46
  meta_bytes: Vec<u8>,
46
47
  trim_hashes: Vec<String>,
48
+ trim_gids: Vec<String>,
47
49
  // Owned committed-append facts and resolved trimmed entries; the frozen JS
48
50
  // `entry_row`/`trim_rows` layouts are rebuilt at the consume boundary so
49
51
  // this pending state stays JS-free (no `js_sys::Array` captured in core
@@ -186,6 +188,14 @@ fn push_optional_trim_result(row: &Array, trim_hashes: Vec<String>, document_tri
186
188
  }
187
189
  }
188
190
 
191
+ fn push_trim_gid_extension(row: &Array, trim_gids: Vec<String>) {
192
+ if trim_gids.is_empty() {
193
+ return;
194
+ }
195
+ row.push(&JsValue::UNDEFINED);
196
+ row.push(&strings_to_array(trim_gids));
197
+ }
198
+
189
199
  fn ensure_batch_append_lens(
190
200
  len: usize,
191
201
  wall_times: &BigUint64Array,
@@ -276,13 +286,13 @@ impl NativePeerbitBackbone {
276
286
  meta_data: Option<Vec<u8>>,
277
287
  payload_data: &[u8],
278
288
  trim_length_to: Option<usize>,
279
- ) -> Result<(NativeCommittedEntryFacts, Vec<String>), BackboneError> {
289
+ ) -> Result<(NativeCommittedEntryFacts, Vec<String>, Vec<String>), BackboneError> {
280
290
  let profile_enabled = self.append_profile_enabled;
281
291
  let log_started = profile_enabled.then(crate::time::now_ms);
282
292
  let mut log_profile = NativeLogAppendProfile::default();
283
- let result = if let Some(trim_length_to) = trim_length_to {
293
+ let (entry, refs) = if let Some(trim_length_to) = trim_length_to {
284
294
  self.log
285
- .prepare_entry_v0_plain_entry_commit_no_next_facts_core_profiled_and_put_with_builder_trim_hashes_borrowed(
295
+ .prepare_entry_v0_plain_entry_commit_no_next_facts_core_profiled_and_put_with_builder_trim_refs_borrowed(
286
296
  &self.builder,
287
297
  &mut self.blocks,
288
298
  wall_time,
@@ -311,11 +321,12 @@ impl NativePeerbitBackbone {
311
321
  Vec::new(),
312
322
  )
313
323
  };
324
+ let (hashes, gids) = refs.into_iter().unzip();
314
325
  if let Some(started) = log_started {
315
326
  self.append_profile.log_total_ms += crate::time::now_ms() - started;
316
327
  self.append_profile.add_log_profile(&log_profile);
317
328
  }
318
- Ok(result)
329
+ Ok((entry, hashes, gids))
319
330
  }
320
331
 
321
332
  #[allow(clippy::too_many_arguments)]
@@ -329,13 +340,13 @@ impl NativePeerbitBackbone {
329
340
  meta_data: Option<Vec<u8>>,
330
341
  payload_data: &[u8],
331
342
  trim_length_to: Option<usize>,
332
- ) -> Result<(NativeCommittedEntryFacts, Vec<String>), BackboneError> {
343
+ ) -> Result<(NativeCommittedEntryFacts, Vec<String>, Vec<String>), BackboneError> {
333
344
  let profile_enabled = self.append_profile_enabled;
334
345
  let log_started = profile_enabled.then(crate::time::now_ms);
335
346
  let mut log_profile = NativeLogAppendProfile::default();
336
- let result = self
347
+ let (entry, refs) = self
337
348
  .log
338
- .prepare_entry_v0_plain_entry_commit_facts_core_profiled_and_put_with_builder_trim_hashes_borrowed(
349
+ .prepare_entry_v0_plain_entry_commit_facts_core_profiled_and_put_with_builder_trim_refs_borrowed(
339
350
  &self.builder,
340
351
  &mut self.blocks,
341
352
  wall_time,
@@ -352,7 +363,8 @@ impl NativePeerbitBackbone {
352
363
  self.append_profile.log_total_ms += crate::time::now_ms() - started;
353
364
  self.append_profile.add_log_profile(&log_profile);
354
365
  }
355
- Ok(result)
366
+ let (hashes, gids) = refs.into_iter().unzip();
367
+ Ok((entry, hashes, gids))
356
368
  }
357
369
 
358
370
  /// JS-free committed-log append: performs the log append and (optionally)
@@ -373,11 +385,19 @@ impl NativePeerbitBackbone {
373
385
  payload_data: Vec<u8>,
374
386
  trim_length_to: Option<usize>,
375
387
  resolve_trimmed_entries: bool,
376
- ) -> Result<(NativeCommittedEntryFacts, Vec<LogIndexEntry>, Vec<String>), BackboneError> {
388
+ ) -> Result<
389
+ (
390
+ NativeCommittedEntryFacts,
391
+ Vec<LogIndexEntry>,
392
+ Vec<String>,
393
+ Vec<String>,
394
+ ),
395
+ BackboneError,
396
+ > {
377
397
  let profile_enabled = self.append_profile_enabled;
378
398
  let log_started = profile_enabled.then(crate::time::now_ms);
379
399
  let mut log_profile = NativeLogAppendProfile::default();
380
- let (entry_facts, trimmed_entries, trim_hashes) = if resolve_trimmed_entries {
400
+ let (entry_facts, trimmed_entries, trim_hashes, trim_gids) = if resolve_trimmed_entries {
381
401
  let (entry_facts, trimmed_entries) = self
382
402
  .log
383
403
  .prepare_entry_v0_plain_entry_commit_facts_core_profiled_and_put_with_builder(
@@ -397,11 +417,14 @@ impl NativePeerbitBackbone {
397
417
  .iter()
398
418
  .map(|entry| entry.hash.clone())
399
419
  .collect::<Vec<_>>();
400
- (entry_facts, trimmed_entries, trim_hashes)
420
+ // Resolved trim rows already carry their gids. Keep the additive
421
+ // gid suffix for hashes-only mode, where the rows cannot provide
422
+ // them, and avoid cloning the strings on materialized paths.
423
+ (entry_facts, trimmed_entries, trim_hashes, Vec::new())
401
424
  } else {
402
- let (entry_facts, trim_hashes) = self
425
+ let (entry_facts, trim_refs) = self
403
426
  .log
404
- .prepare_entry_v0_plain_entry_commit_facts_core_profiled_and_put_with_builder_trim_hashes(
427
+ .prepare_entry_v0_plain_entry_commit_facts_core_profiled_and_put_with_builder_trim_refs(
405
428
  &self.builder,
406
429
  &mut self.blocks,
407
430
  wall_time,
@@ -414,13 +437,14 @@ impl NativePeerbitBackbone {
414
437
  trim_length_to,
415
438
  profile_enabled.then_some(&mut log_profile),
416
439
  )?;
417
- (entry_facts, Vec::new(), trim_hashes)
440
+ let (trim_hashes, trim_gids) = trim_refs.into_iter().unzip();
441
+ (entry_facts, Vec::new(), trim_hashes, trim_gids)
418
442
  };
419
443
  if let Some(started) = log_started {
420
444
  self.append_profile.log_total_ms += crate::time::now_ms() - started;
421
445
  self.append_profile.add_log_profile(&log_profile);
422
446
  }
423
- Ok((entry_facts, trimmed_entries, trim_hashes))
447
+ Ok((entry_facts, trimmed_entries, trim_hashes, trim_gids))
424
448
  }
425
449
 
426
450
  /// Build the frozen committed-append entry row from owned facts, timing the
@@ -471,8 +495,17 @@ impl NativePeerbitBackbone {
471
495
  payload_data: Vec<u8>,
472
496
  trim_length_to: Option<usize>,
473
497
  resolve_trimmed_entries: bool,
474
- ) -> Result<(NativeCommittedEntryFacts, Vec<String>, Array, Array), BackboneError> {
475
- let (entry_facts, trimmed_entries, trim_hashes) = self
498
+ ) -> Result<
499
+ (
500
+ NativeCommittedEntryFacts,
501
+ Vec<String>,
502
+ Vec<String>,
503
+ Array,
504
+ Array,
505
+ ),
506
+ BackboneError,
507
+ > {
508
+ let (entry_facts, trimmed_entries, trim_hashes, trim_gids) = self
476
509
  .prepare_committed_log_append_owned_profiled(
477
510
  wall_time,
478
511
  logical,
@@ -489,7 +522,7 @@ impl NativePeerbitBackbone {
489
522
  trimmed_entries,
490
523
  resolve_trimmed_entries,
491
524
  );
492
- Ok((entry_facts, trim_hashes, entry_row, trim_rows))
525
+ Ok((entry_facts, trim_hashes, trim_gids, entry_row, trim_rows))
493
526
  }
494
527
 
495
528
  #[allow(clippy::too_many_arguments)]