@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.
@@ -0,0 +1,2063 @@
1
+ use js_sys::{Array, BigUint64Array, Uint32Array, Uint8Array};
2
+ use peerbit_shared_log_rust::{
3
+ commit_local_append_for_gid_compact_core, commit_local_appends_for_gids_compact_core,
4
+ NativeLocalAppendCompactInput,
5
+ };
6
+ use wasm_bindgen::prelude::*;
7
+
8
+ use crate::append_tx::{
9
+ coordinate_plan_to_row, ensure_batch_append_lens, ensure_batch_projection_lens,
10
+ latest_compact_entry_row, required_projection_encoded_document, LatestBatchPendingAppend,
11
+ LatestCompactBatchPendingAppend,
12
+ };
13
+ use crate::documents::{
14
+ document_context_facts_to_row, document_index_append_commit,
15
+ document_index_cached_projection_append_commit,
16
+ document_index_cached_projection_plain_put_payload_append_commit,
17
+ document_index_plain_put_payload_append_commit, DocumentIndexAppendCommit,
18
+ DocumentIndexValuePrefix,
19
+ };
20
+ use crate::js_interop::{
21
+ ensure_same_len, has_duplicate_strings, optional_usize_from_js, required_bytes_from_array,
22
+ strings_from_array, strings_to_array,
23
+ };
24
+ use crate::shared_log_plan::leader_samples_to_optional_rows;
25
+ use crate::NativePeerbitBackbone;
26
+
27
+ #[wasm_bindgen]
28
+ impl NativePeerbitBackbone {
29
+ #[allow(clippy::too_many_arguments)]
30
+ pub fn prepare_plain_committed_storage_append_transaction(
31
+ &mut self,
32
+ wall_time: u64,
33
+ logical: u32,
34
+ gid: String,
35
+ next_hashes: Array,
36
+ entry_type: u8,
37
+ meta_data: JsValue,
38
+ payload_data: Uint8Array,
39
+ replicas: usize,
40
+ role_age_ms: f64,
41
+ now: String,
42
+ self_hash: String,
43
+ self_replicating: bool,
44
+ resolve_trimmed_entries: bool,
45
+ ) -> Result<Array, JsValue> {
46
+ self.prepare_plain_storage_append_transaction_inner(
47
+ wall_time,
48
+ logical,
49
+ gid,
50
+ strings_from_array(next_hashes)?,
51
+ entry_type,
52
+ meta_data,
53
+ payload_data,
54
+ replicas,
55
+ role_age_ms,
56
+ now,
57
+ self_hash,
58
+ self_replicating,
59
+ resolve_trimmed_entries,
60
+ None,
61
+ true,
62
+ None,
63
+ )
64
+ }
65
+
66
+ #[allow(clippy::too_many_arguments)]
67
+ pub fn prepare_plain_committed_storage_append_document_delete_transaction(
68
+ &mut self,
69
+ wall_time: u64,
70
+ logical: u32,
71
+ gid: String,
72
+ next_hashes: Array,
73
+ entry_type: u8,
74
+ meta_data: JsValue,
75
+ payload_data: Uint8Array,
76
+ replicas: usize,
77
+ role_age_ms: f64,
78
+ now: String,
79
+ self_hash: String,
80
+ self_replicating: bool,
81
+ resolve_trimmed_entries: bool,
82
+ document_key: String,
83
+ ) -> Result<Array, JsValue> {
84
+ let row = self.prepare_plain_storage_append_transaction_inner(
85
+ wall_time,
86
+ logical,
87
+ gid,
88
+ strings_from_array(next_hashes)?,
89
+ entry_type,
90
+ meta_data,
91
+ payload_data,
92
+ replicas,
93
+ role_age_ms,
94
+ now,
95
+ self_hash,
96
+ self_replicating,
97
+ resolve_trimmed_entries,
98
+ None,
99
+ true,
100
+ None,
101
+ )?;
102
+ self.delete_document_inner(&document_key, true);
103
+ Ok(row)
104
+ }
105
+
106
+ #[allow(clippy::too_many_arguments)]
107
+ pub fn prepare_plain_committed_storage_append_document_index_transaction(
108
+ &mut self,
109
+ wall_time: u64,
110
+ logical: u32,
111
+ gid: String,
112
+ next_hashes: Array,
113
+ entry_type: u8,
114
+ meta_data: JsValue,
115
+ payload_data: Uint8Array,
116
+ replicas: usize,
117
+ role_age_ms: f64,
118
+ now: String,
119
+ self_hash: String,
120
+ self_replicating: bool,
121
+ resolve_trimmed_entries: bool,
122
+ document_key: String,
123
+ document_value_prefix_bytes: Vec<u8>,
124
+ document_existing_created: String,
125
+ document_byte_element_index_limit: usize,
126
+ document_delete_trimmed_heads: bool,
127
+ document_projection_plan: JsValue,
128
+ document_projection_encoded_document: JsValue,
129
+ document_projection_signer: JsValue,
130
+ ) -> Result<Array, JsValue> {
131
+ self.prepare_plain_storage_append_transaction_inner(
132
+ wall_time,
133
+ logical,
134
+ gid,
135
+ strings_from_array(next_hashes)?,
136
+ entry_type,
137
+ meta_data,
138
+ payload_data,
139
+ replicas,
140
+ role_age_ms,
141
+ now,
142
+ self_hash,
143
+ self_replicating,
144
+ resolve_trimmed_entries,
145
+ None,
146
+ true,
147
+ Some(document_index_append_commit(
148
+ document_key,
149
+ document_value_prefix_bytes,
150
+ document_existing_created,
151
+ document_byte_element_index_limit,
152
+ document_delete_trimmed_heads,
153
+ document_projection_plan,
154
+ document_projection_encoded_document,
155
+ document_projection_signer,
156
+ )?),
157
+ )
158
+ }
159
+
160
+ #[allow(clippy::too_many_arguments)]
161
+ pub fn prepare_plain_committed_storage_append_document_index_latest_transaction(
162
+ &mut self,
163
+ wall_time: u64,
164
+ logical: u32,
165
+ fallback_gid: String,
166
+ entry_type: u8,
167
+ meta_data: JsValue,
168
+ payload_data: Uint8Array,
169
+ replicas: usize,
170
+ role_age_ms: f64,
171
+ now: String,
172
+ self_hash: String,
173
+ self_replicating: bool,
174
+ resolve_trimmed_entries: bool,
175
+ document_key: String,
176
+ document_value_prefix_bytes: Vec<u8>,
177
+ document_byte_element_index_limit: usize,
178
+ document_delete_trimmed_heads: bool,
179
+ document_projection_plan: JsValue,
180
+ document_projection_encoded_document: JsValue,
181
+ document_projection_signer: JsValue,
182
+ trim_length_to: JsValue,
183
+ ) -> Result<Array, JsValue> {
184
+ let document_index_commit = document_index_append_commit(
185
+ document_key,
186
+ document_value_prefix_bytes,
187
+ String::new(),
188
+ document_byte_element_index_limit,
189
+ document_delete_trimmed_heads,
190
+ document_projection_plan,
191
+ document_projection_encoded_document,
192
+ document_projection_signer,
193
+ )?;
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,
209
+ )
210
+ }
211
+
212
+ #[allow(clippy::too_many_arguments)]
213
+ pub fn prepare_plain_committed_storage_append_document_index_latest_required_previous_signer_transaction(
214
+ &mut self,
215
+ wall_time: u64,
216
+ logical: u32,
217
+ fallback_gid: String,
218
+ entry_type: u8,
219
+ meta_data: JsValue,
220
+ payload_data: Uint8Array,
221
+ replicas: usize,
222
+ role_age_ms: f64,
223
+ now: String,
224
+ self_hash: String,
225
+ self_replicating: bool,
226
+ resolve_trimmed_entries: bool,
227
+ document_key: String,
228
+ document_value_prefix_bytes: Vec<u8>,
229
+ document_byte_element_index_limit: usize,
230
+ document_delete_trimmed_heads: bool,
231
+ document_projection_plan: JsValue,
232
+ document_projection_encoded_document: JsValue,
233
+ document_projection_signer: JsValue,
234
+ required_previous_signer_public_key: Uint8Array,
235
+ trim_length_to: JsValue,
236
+ ) -> Result<Array, JsValue> {
237
+ let mut document_index_commit = document_index_append_commit(
238
+ document_key,
239
+ document_value_prefix_bytes,
240
+ String::new(),
241
+ document_byte_element_index_limit,
242
+ document_delete_trimmed_heads,
243
+ document_projection_plan,
244
+ document_projection_encoded_document,
245
+ document_projection_signer,
246
+ )?;
247
+ document_index_commit.required_previous_signer_public_key =
248
+ 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,
264
+ )
265
+ }
266
+
267
+ #[allow(clippy::too_many_arguments)]
268
+ pub fn prepare_plain_committed_storage_append_document_index_latest_cached_plan_transaction(
269
+ &mut self,
270
+ wall_time: u64,
271
+ logical: u32,
272
+ fallback_gid: String,
273
+ entry_type: u8,
274
+ meta_data: JsValue,
275
+ payload_data: Uint8Array,
276
+ replicas: usize,
277
+ role_age_ms: f64,
278
+ now: String,
279
+ self_hash: String,
280
+ self_replicating: bool,
281
+ resolve_trimmed_entries: bool,
282
+ document_key: String,
283
+ document_byte_element_index_limit: usize,
284
+ document_delete_trimmed_heads: bool,
285
+ document_projection_plan_id: u32,
286
+ document_projection_encoded_document: JsValue,
287
+ document_projection_signer: JsValue,
288
+ trim_length_to: JsValue,
289
+ ) -> Result<Array, JsValue> {
290
+ let document_index_commit = document_index_cached_projection_append_commit(
291
+ document_key,
292
+ String::new(),
293
+ document_byte_element_index_limit,
294
+ document_delete_trimmed_heads,
295
+ document_projection_plan_id,
296
+ document_projection_encoded_document,
297
+ document_projection_signer,
298
+ )?;
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,
314
+ )
315
+ }
316
+
317
+ #[allow(clippy::too_many_arguments)]
318
+ pub fn prepare_plain_committed_storage_append_document_index_latest_compact_transaction(
319
+ &mut self,
320
+ wall_time: u64,
321
+ logical: u32,
322
+ fallback_gid: String,
323
+ entry_type: u8,
324
+ meta_data: JsValue,
325
+ payload_data: Uint8Array,
326
+ replicas: usize,
327
+ role_age_ms: f64,
328
+ now: String,
329
+ self_hash: String,
330
+ self_replicating: bool,
331
+ document_key: String,
332
+ document_value_prefix_bytes: Vec<u8>,
333
+ document_byte_element_index_limit: usize,
334
+ document_delete_trimmed_heads: bool,
335
+ document_projection_plan: JsValue,
336
+ document_projection_encoded_document: JsValue,
337
+ document_projection_signer: JsValue,
338
+ trim_length_to: JsValue,
339
+ ) -> Result<Array, JsValue> {
340
+ let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
341
+ let document_index_commit = document_index_append_commit(
342
+ document_key,
343
+ document_value_prefix_bytes,
344
+ String::new(),
345
+ document_byte_element_index_limit,
346
+ document_delete_trimmed_heads,
347
+ document_projection_plan,
348
+ document_projection_encoded_document,
349
+ document_projection_signer,
350
+ )?;
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
+ )
366
+ }
367
+
368
+ #[allow(clippy::too_many_arguments)]
369
+ pub fn prepare_plain_committed_storage_append_document_index_latest_compact_plain_put_payload_transaction(
370
+ &mut self,
371
+ wall_time: u64,
372
+ logical: u32,
373
+ fallback_gid: String,
374
+ entry_type: u8,
375
+ meta_data: JsValue,
376
+ payload_data: Uint8Array,
377
+ replicas: usize,
378
+ role_age_ms: f64,
379
+ now: String,
380
+ self_hash: String,
381
+ self_replicating: bool,
382
+ document_key: String,
383
+ document_byte_element_index_limit: usize,
384
+ document_delete_trimmed_heads: bool,
385
+ trim_length_to: JsValue,
386
+ ) -> Result<Array, JsValue> {
387
+ let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
388
+ let document_index_commit = document_index_plain_put_payload_append_commit(
389
+ document_key,
390
+ String::new(),
391
+ document_byte_element_index_limit,
392
+ document_delete_trimmed_heads,
393
+ )?;
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
+ )
409
+ }
410
+
411
+ #[allow(clippy::too_many_arguments)]
412
+ pub fn prepare_plain_committed_storage_append_document_index_latest_required_previous_signer_compact_transaction(
413
+ &mut self,
414
+ wall_time: u64,
415
+ logical: u32,
416
+ fallback_gid: String,
417
+ entry_type: u8,
418
+ meta_data: JsValue,
419
+ payload_data: Uint8Array,
420
+ replicas: usize,
421
+ role_age_ms: f64,
422
+ now: String,
423
+ self_hash: String,
424
+ self_replicating: bool,
425
+ document_key: String,
426
+ document_value_prefix_bytes: Vec<u8>,
427
+ document_byte_element_index_limit: usize,
428
+ document_delete_trimmed_heads: bool,
429
+ document_projection_plan: JsValue,
430
+ document_projection_encoded_document: JsValue,
431
+ document_projection_signer: JsValue,
432
+ required_previous_signer_public_key: Uint8Array,
433
+ trim_length_to: JsValue,
434
+ ) -> Result<Array, JsValue> {
435
+ let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
436
+ let mut document_index_commit = document_index_append_commit(
437
+ document_key,
438
+ document_value_prefix_bytes,
439
+ String::new(),
440
+ document_byte_element_index_limit,
441
+ document_delete_trimmed_heads,
442
+ document_projection_plan,
443
+ document_projection_encoded_document,
444
+ document_projection_signer,
445
+ )?;
446
+ document_index_commit.required_previous_signer_public_key =
447
+ 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
+ )
463
+ }
464
+
465
+ #[allow(clippy::too_many_arguments)]
466
+ pub fn prepare_plain_committed_storage_append_document_index_latest_cached_plan_compact_transaction(
467
+ &mut self,
468
+ wall_time: u64,
469
+ logical: u32,
470
+ fallback_gid: String,
471
+ entry_type: u8,
472
+ meta_data: JsValue,
473
+ payload_data: Uint8Array,
474
+ replicas: usize,
475
+ role_age_ms: f64,
476
+ now: String,
477
+ self_hash: String,
478
+ self_replicating: bool,
479
+ document_key: String,
480
+ document_byte_element_index_limit: usize,
481
+ document_delete_trimmed_heads: bool,
482
+ document_projection_plan_id: u32,
483
+ document_projection_encoded_document: JsValue,
484
+ document_projection_signer: JsValue,
485
+ trim_length_to: JsValue,
486
+ ) -> Result<Array, JsValue> {
487
+ let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
488
+ let document_index_commit = document_index_cached_projection_append_commit(
489
+ document_key,
490
+ String::new(),
491
+ document_byte_element_index_limit,
492
+ document_delete_trimmed_heads,
493
+ document_projection_plan_id,
494
+ document_projection_encoded_document,
495
+ document_projection_signer,
496
+ )?;
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
+ )
512
+ }
513
+
514
+ #[allow(clippy::too_many_arguments)]
515
+ pub fn prepare_plain_committed_storage_append_document_index_latest_cached_plan_compact_plain_put_payload_transaction(
516
+ &mut self,
517
+ wall_time: u64,
518
+ logical: u32,
519
+ fallback_gid: String,
520
+ entry_type: u8,
521
+ meta_data: JsValue,
522
+ payload_data: Uint8Array,
523
+ replicas: usize,
524
+ role_age_ms: f64,
525
+ now: String,
526
+ self_hash: String,
527
+ self_replicating: bool,
528
+ document_key: String,
529
+ document_byte_element_index_limit: usize,
530
+ document_delete_trimmed_heads: bool,
531
+ document_projection_plan_id: u32,
532
+ document_projection_signer: JsValue,
533
+ trim_length_to: JsValue,
534
+ ) -> Result<Array, JsValue> {
535
+ let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
536
+ let document_index_commit =
537
+ document_index_cached_projection_plain_put_payload_append_commit(
538
+ document_key,
539
+ String::new(),
540
+ document_byte_element_index_limit,
541
+ document_delete_trimmed_heads,
542
+ document_projection_plan_id,
543
+ document_projection_signer,
544
+ )?;
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
+ )
560
+ }
561
+
562
+ #[allow(clippy::too_many_arguments)]
563
+ pub fn prepare_plain_committed_storage_append_document_index_latest_batch_transaction(
564
+ &mut self,
565
+ wall_times: BigUint64Array,
566
+ logicals: Uint32Array,
567
+ fallback_gids: Array,
568
+ entry_type: u8,
569
+ meta_datas: Array,
570
+ payload_datas: Array,
571
+ replicas: usize,
572
+ role_age_ms: f64,
573
+ now: String,
574
+ self_hash: String,
575
+ self_replicating: bool,
576
+ resolve_trimmed_entries: bool,
577
+ document_keys: Array,
578
+ document_value_prefix_bytes: Array,
579
+ document_byte_element_index_limit: usize,
580
+ document_delete_trimmed_heads: bool,
581
+ trim_length_to: JsValue,
582
+ ) -> Result<Array, JsValue> {
583
+ let len = payload_datas.length() as usize;
584
+ ensure_batch_append_lens(
585
+ len,
586
+ &wall_times,
587
+ &logicals,
588
+ &fallback_gids,
589
+ "batch fallback gids",
590
+ &meta_datas,
591
+ &document_keys,
592
+ )?;
593
+ ensure_same_len(
594
+ len,
595
+ document_value_prefix_bytes.length() as usize,
596
+ "batch document value prefixes",
597
+ )?;
598
+ 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
+ )
631
+ }
632
+
633
+ #[allow(clippy::too_many_arguments)]
634
+ pub fn prepare_plain_committed_storage_append_document_index_latest_required_previous_signer_batch_transaction(
635
+ &mut self,
636
+ wall_times: BigUint64Array,
637
+ logicals: Uint32Array,
638
+ fallback_gids: Array,
639
+ entry_type: u8,
640
+ meta_datas: Array,
641
+ payload_datas: Array,
642
+ replicas: usize,
643
+ role_age_ms: f64,
644
+ now: String,
645
+ self_hash: String,
646
+ self_replicating: bool,
647
+ resolve_trimmed_entries: bool,
648
+ document_keys: Array,
649
+ document_value_prefix_bytes: Array,
650
+ document_byte_element_index_limit: usize,
651
+ document_delete_trimmed_heads: bool,
652
+ required_previous_signer_public_key: Uint8Array,
653
+ trim_length_to: JsValue,
654
+ ) -> Result<Array, JsValue> {
655
+ let len = payload_datas.length() as usize;
656
+ ensure_batch_append_lens(
657
+ len,
658
+ &wall_times,
659
+ &logicals,
660
+ &fallback_gids,
661
+ "batch fallback gids",
662
+ &meta_datas,
663
+ &document_keys,
664
+ )?;
665
+ ensure_same_len(
666
+ len,
667
+ document_value_prefix_bytes.length() as usize,
668
+ "batch document value prefixes",
669
+ )?;
670
+ let required_previous_signer_public_key = required_previous_signer_public_key.to_vec();
671
+ 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
+ )
707
+ }
708
+
709
+ #[allow(clippy::too_many_arguments)]
710
+ pub fn prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction(
711
+ &mut self,
712
+ wall_times: BigUint64Array,
713
+ logicals: Uint32Array,
714
+ fallback_gids: Array,
715
+ entry_type: u8,
716
+ meta_datas: Array,
717
+ payload_datas: Array,
718
+ replicas: usize,
719
+ role_age_ms: f64,
720
+ now: String,
721
+ self_hash: String,
722
+ self_replicating: bool,
723
+ document_keys: Array,
724
+ document_value_prefix_bytes: Array,
725
+ document_byte_element_index_limit: usize,
726
+ document_delete_trimmed_heads: bool,
727
+ trim_length_to: JsValue,
728
+ ) -> Result<Array, JsValue> {
729
+ let len = payload_datas.length() as usize;
730
+ ensure_batch_append_lens(
731
+ len,
732
+ &wall_times,
733
+ &logicals,
734
+ &fallback_gids,
735
+ "batch fallback gids",
736
+ &meta_datas,
737
+ &document_keys,
738
+ )?;
739
+ ensure_same_len(
740
+ len,
741
+ document_value_prefix_bytes.length() as usize,
742
+ "batch document value prefixes",
743
+ )?;
744
+ let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
745
+ let document_keys = strings_from_array(document_keys)?;
746
+ let mut document_index_commits = Vec::with_capacity(len);
747
+ for (index, document_key) in document_keys.iter().enumerate() {
748
+ let index_u32 = index as u32;
749
+ document_index_commits.push(document_index_append_commit(
750
+ document_key.clone(),
751
+ required_bytes_from_array(
752
+ &document_value_prefix_bytes,
753
+ index_u32,
754
+ "document value prefix",
755
+ )?
756
+ .to_vec(),
757
+ String::new(),
758
+ document_byte_element_index_limit,
759
+ document_delete_trimmed_heads,
760
+ JsValue::UNDEFINED,
761
+ JsValue::UNDEFINED,
762
+ JsValue::UNDEFINED,
763
+ )?);
764
+ }
765
+ self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
766
+ wall_times,
767
+ logicals,
768
+ fallback_gids,
769
+ entry_type,
770
+ meta_datas,
771
+ payload_datas,
772
+ replicas,
773
+ role_age_ms,
774
+ now,
775
+ self_hash,
776
+ self_replicating,
777
+ trim_length_to,
778
+ &document_keys,
779
+ document_index_commits,
780
+ )
781
+ }
782
+
783
+ #[allow(clippy::too_many_arguments)]
784
+ pub fn prepare_plain_committed_storage_append_document_index_latest_compact_plain_put_payload_batch_transaction(
785
+ &mut self,
786
+ wall_times: BigUint64Array,
787
+ logicals: Uint32Array,
788
+ fallback_gids: Array,
789
+ entry_type: u8,
790
+ meta_datas: Array,
791
+ payload_datas: Array,
792
+ replicas: usize,
793
+ role_age_ms: f64,
794
+ now: String,
795
+ self_hash: String,
796
+ self_replicating: bool,
797
+ document_keys: Array,
798
+ document_byte_element_index_limit: usize,
799
+ document_delete_trimmed_heads: bool,
800
+ trim_length_to: JsValue,
801
+ ) -> Result<Array, JsValue> {
802
+ let len = payload_datas.length() as usize;
803
+ ensure_batch_append_lens(
804
+ len,
805
+ &wall_times,
806
+ &logicals,
807
+ &fallback_gids,
808
+ "batch fallback gids",
809
+ &meta_datas,
810
+ &document_keys,
811
+ )?;
812
+ let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
813
+ let document_keys = strings_from_array(document_keys)?;
814
+ let mut document_index_commits = Vec::with_capacity(len);
815
+ for document_key in &document_keys {
816
+ document_index_commits.push(document_index_plain_put_payload_append_commit(
817
+ document_key.clone(),
818
+ String::new(),
819
+ document_byte_element_index_limit,
820
+ document_delete_trimmed_heads,
821
+ )?);
822
+ }
823
+ self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
824
+ wall_times,
825
+ logicals,
826
+ fallback_gids,
827
+ entry_type,
828
+ meta_datas,
829
+ payload_datas,
830
+ replicas,
831
+ role_age_ms,
832
+ now,
833
+ self_hash,
834
+ self_replicating,
835
+ trim_length_to,
836
+ &document_keys,
837
+ document_index_commits,
838
+ )
839
+ }
840
+
841
+ #[allow(clippy::too_many_arguments)]
842
+ pub fn prepare_plain_committed_storage_append_document_index_latest_required_previous_signer_compact_batch_transaction(
843
+ &mut self,
844
+ wall_times: BigUint64Array,
845
+ logicals: Uint32Array,
846
+ fallback_gids: Array,
847
+ entry_type: u8,
848
+ meta_datas: Array,
849
+ payload_datas: Array,
850
+ replicas: usize,
851
+ role_age_ms: f64,
852
+ now: String,
853
+ self_hash: String,
854
+ self_replicating: bool,
855
+ document_keys: Array,
856
+ document_value_prefix_bytes: Array,
857
+ document_byte_element_index_limit: usize,
858
+ document_delete_trimmed_heads: bool,
859
+ required_previous_signer_public_key: Uint8Array,
860
+ trim_length_to: JsValue,
861
+ ) -> Result<Array, JsValue> {
862
+ let len = payload_datas.length() as usize;
863
+ ensure_batch_append_lens(
864
+ len,
865
+ &wall_times,
866
+ &logicals,
867
+ &fallback_gids,
868
+ "batch fallback gids",
869
+ &meta_datas,
870
+ &document_keys,
871
+ )?;
872
+ ensure_same_len(
873
+ len,
874
+ document_value_prefix_bytes.length() as usize,
875
+ "batch document value prefixes",
876
+ )?;
877
+ let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
878
+ let required_previous_signer_public_key = required_previous_signer_public_key.to_vec();
879
+ let document_keys = strings_from_array(document_keys)?;
880
+ let mut document_index_commits = Vec::with_capacity(len);
881
+ for (index, document_key) in document_keys.iter().enumerate() {
882
+ let index_u32 = index as u32;
883
+ let mut document_index_commit = document_index_append_commit(
884
+ document_key.clone(),
885
+ required_bytes_from_array(
886
+ &document_value_prefix_bytes,
887
+ index_u32,
888
+ "document value prefix",
889
+ )?
890
+ .to_vec(),
891
+ String::new(),
892
+ document_byte_element_index_limit,
893
+ document_delete_trimmed_heads,
894
+ JsValue::UNDEFINED,
895
+ JsValue::UNDEFINED,
896
+ JsValue::UNDEFINED,
897
+ )?;
898
+ document_index_commit.required_previous_signer_public_key =
899
+ Some(required_previous_signer_public_key.clone());
900
+ document_index_commits.push(document_index_commit);
901
+ }
902
+ self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
903
+ wall_times,
904
+ logicals,
905
+ fallback_gids,
906
+ entry_type,
907
+ meta_datas,
908
+ payload_datas,
909
+ replicas,
910
+ role_age_ms,
911
+ now,
912
+ self_hash,
913
+ self_replicating,
914
+ trim_length_to,
915
+ &document_keys,
916
+ document_index_commits,
917
+ )
918
+ }
919
+
920
+ #[allow(clippy::too_many_arguments)]
921
+ pub fn prepare_plain_committed_storage_append_document_index_latest_cached_plan_batch_transaction(
922
+ &mut self,
923
+ wall_times: BigUint64Array,
924
+ logicals: Uint32Array,
925
+ fallback_gids: Array,
926
+ entry_type: u8,
927
+ meta_datas: Array,
928
+ payload_datas: Array,
929
+ replicas: usize,
930
+ role_age_ms: f64,
931
+ now: String,
932
+ self_hash: String,
933
+ self_replicating: bool,
934
+ resolve_trimmed_entries: bool,
935
+ document_keys: Array,
936
+ document_byte_element_index_limit: usize,
937
+ document_delete_trimmed_heads: bool,
938
+ document_projection_plan_ids: Uint32Array,
939
+ document_projection_encoded_documents: Array,
940
+ document_projection_signers: Array,
941
+ trim_length_to: JsValue,
942
+ ) -> Result<Array, JsValue> {
943
+ let len = payload_datas.length() as usize;
944
+ ensure_batch_append_lens(
945
+ len,
946
+ &wall_times,
947
+ &logicals,
948
+ &fallback_gids,
949
+ "batch fallback gids",
950
+ &meta_datas,
951
+ &document_keys,
952
+ )?;
953
+ ensure_batch_projection_lens(
954
+ len,
955
+ &document_projection_plan_ids,
956
+ Some(&document_projection_encoded_documents),
957
+ &document_projection_signers,
958
+ )?;
959
+ 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
+ )
990
+ }
991
+
992
+ #[allow(clippy::too_many_arguments)]
993
+ pub fn prepare_plain_committed_storage_append_document_index_latest_required_previous_signer_cached_plan_batch_transaction(
994
+ &mut self,
995
+ wall_times: BigUint64Array,
996
+ logicals: Uint32Array,
997
+ fallback_gids: Array,
998
+ entry_type: u8,
999
+ meta_datas: Array,
1000
+ payload_datas: Array,
1001
+ replicas: usize,
1002
+ role_age_ms: f64,
1003
+ now: String,
1004
+ self_hash: String,
1005
+ self_replicating: bool,
1006
+ resolve_trimmed_entries: bool,
1007
+ document_keys: Array,
1008
+ document_byte_element_index_limit: usize,
1009
+ document_delete_trimmed_heads: bool,
1010
+ document_projection_plan_ids: Uint32Array,
1011
+ document_projection_encoded_documents: Array,
1012
+ document_projection_signers: Array,
1013
+ required_previous_signer_public_key: Uint8Array,
1014
+ trim_length_to: JsValue,
1015
+ ) -> Result<Array, JsValue> {
1016
+ let len = payload_datas.length() as usize;
1017
+ ensure_batch_append_lens(
1018
+ len,
1019
+ &wall_times,
1020
+ &logicals,
1021
+ &fallback_gids,
1022
+ "batch fallback gids",
1023
+ &meta_datas,
1024
+ &document_keys,
1025
+ )?;
1026
+ ensure_batch_projection_lens(
1027
+ len,
1028
+ &document_projection_plan_ids,
1029
+ Some(&document_projection_encoded_documents),
1030
+ &document_projection_signers,
1031
+ )?;
1032
+ let required_previous_signer_public_key = required_previous_signer_public_key.to_vec();
1033
+ 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
+ )
1067
+ }
1068
+
1069
+ #[allow(clippy::too_many_arguments)]
1070
+ pub fn prepare_plain_committed_storage_append_document_index_latest_cached_plan_compact_batch_transaction(
1071
+ &mut self,
1072
+ wall_times: BigUint64Array,
1073
+ logicals: Uint32Array,
1074
+ fallback_gids: Array,
1075
+ entry_type: u8,
1076
+ meta_datas: Array,
1077
+ payload_datas: Array,
1078
+ replicas: usize,
1079
+ role_age_ms: f64,
1080
+ now: String,
1081
+ self_hash: String,
1082
+ self_replicating: bool,
1083
+ document_keys: Array,
1084
+ document_byte_element_index_limit: usize,
1085
+ document_delete_trimmed_heads: bool,
1086
+ document_projection_plan_ids: Uint32Array,
1087
+ document_projection_encoded_documents: Array,
1088
+ document_projection_signers: Array,
1089
+ trim_length_to: JsValue,
1090
+ ) -> Result<Array, JsValue> {
1091
+ let len = payload_datas.length() as usize;
1092
+ ensure_batch_append_lens(
1093
+ len,
1094
+ &wall_times,
1095
+ &logicals,
1096
+ &fallback_gids,
1097
+ "batch fallback gids",
1098
+ &meta_datas,
1099
+ &document_keys,
1100
+ )?;
1101
+ ensure_batch_projection_lens(
1102
+ len,
1103
+ &document_projection_plan_ids,
1104
+ Some(&document_projection_encoded_documents),
1105
+ &document_projection_signers,
1106
+ )?;
1107
+ let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
1108
+ let document_keys = strings_from_array(document_keys)?;
1109
+ let mut document_index_commits = Vec::with_capacity(len);
1110
+ for (index, document_key) in document_keys.iter().enumerate() {
1111
+ let index_u32 = index as u32;
1112
+ let encoded_document = required_projection_encoded_document(
1113
+ &document_projection_encoded_documents,
1114
+ index_u32,
1115
+ )?;
1116
+ document_index_commits.push(document_index_cached_projection_append_commit(
1117
+ document_key.clone(),
1118
+ String::new(),
1119
+ document_byte_element_index_limit,
1120
+ document_delete_trimmed_heads,
1121
+ document_projection_plan_ids.get_index(index_u32),
1122
+ encoded_document,
1123
+ document_projection_signers.get(index_u32),
1124
+ )?);
1125
+ }
1126
+ self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
1127
+ wall_times,
1128
+ logicals,
1129
+ fallback_gids,
1130
+ entry_type,
1131
+ meta_datas,
1132
+ payload_datas,
1133
+ replicas,
1134
+ role_age_ms,
1135
+ now,
1136
+ self_hash,
1137
+ self_replicating,
1138
+ trim_length_to,
1139
+ &document_keys,
1140
+ document_index_commits,
1141
+ )
1142
+ }
1143
+
1144
+ #[allow(clippy::too_many_arguments)]
1145
+ pub fn prepare_plain_committed_storage_append_document_index_latest_required_previous_signer_cached_plan_compact_batch_transaction(
1146
+ &mut self,
1147
+ wall_times: BigUint64Array,
1148
+ logicals: Uint32Array,
1149
+ fallback_gids: Array,
1150
+ entry_type: u8,
1151
+ meta_datas: Array,
1152
+ payload_datas: Array,
1153
+ replicas: usize,
1154
+ role_age_ms: f64,
1155
+ now: String,
1156
+ self_hash: String,
1157
+ self_replicating: bool,
1158
+ document_keys: Array,
1159
+ document_byte_element_index_limit: usize,
1160
+ document_delete_trimmed_heads: bool,
1161
+ document_projection_plan_ids: Uint32Array,
1162
+ document_projection_encoded_documents: Array,
1163
+ document_projection_signers: Array,
1164
+ required_previous_signer_public_key: Uint8Array,
1165
+ trim_length_to: JsValue,
1166
+ ) -> Result<Array, JsValue> {
1167
+ let len = payload_datas.length() as usize;
1168
+ ensure_batch_append_lens(
1169
+ len,
1170
+ &wall_times,
1171
+ &logicals,
1172
+ &fallback_gids,
1173
+ "batch fallback gids",
1174
+ &meta_datas,
1175
+ &document_keys,
1176
+ )?;
1177
+ ensure_batch_projection_lens(
1178
+ len,
1179
+ &document_projection_plan_ids,
1180
+ Some(&document_projection_encoded_documents),
1181
+ &document_projection_signers,
1182
+ )?;
1183
+ let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
1184
+ let required_previous_signer_public_key = required_previous_signer_public_key.to_vec();
1185
+ let document_keys = strings_from_array(document_keys)?;
1186
+ let mut document_index_commits = Vec::with_capacity(len);
1187
+ for (index, document_key) in document_keys.iter().enumerate() {
1188
+ let index_u32 = index as u32;
1189
+ let encoded_document = required_projection_encoded_document(
1190
+ &document_projection_encoded_documents,
1191
+ index_u32,
1192
+ )?;
1193
+ let mut document_index_commit = document_index_cached_projection_append_commit(
1194
+ document_key.clone(),
1195
+ String::new(),
1196
+ document_byte_element_index_limit,
1197
+ document_delete_trimmed_heads,
1198
+ document_projection_plan_ids.get_index(index_u32),
1199
+ encoded_document,
1200
+ document_projection_signers.get(index_u32),
1201
+ )?;
1202
+ document_index_commit.required_previous_signer_public_key =
1203
+ Some(required_previous_signer_public_key.clone());
1204
+ document_index_commits.push(document_index_commit);
1205
+ }
1206
+ self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
1207
+ wall_times,
1208
+ logicals,
1209
+ fallback_gids,
1210
+ entry_type,
1211
+ meta_datas,
1212
+ payload_datas,
1213
+ replicas,
1214
+ role_age_ms,
1215
+ now,
1216
+ self_hash,
1217
+ self_replicating,
1218
+ trim_length_to,
1219
+ &document_keys,
1220
+ document_index_commits,
1221
+ )
1222
+ }
1223
+
1224
+ #[allow(clippy::too_many_arguments)]
1225
+ pub fn prepare_plain_committed_storage_append_document_index_latest_cached_plan_compact_plain_put_payload_batch_transaction(
1226
+ &mut self,
1227
+ wall_times: BigUint64Array,
1228
+ logicals: Uint32Array,
1229
+ fallback_gids: Array,
1230
+ entry_type: u8,
1231
+ meta_datas: Array,
1232
+ payload_datas: Array,
1233
+ replicas: usize,
1234
+ role_age_ms: f64,
1235
+ now: String,
1236
+ self_hash: String,
1237
+ self_replicating: bool,
1238
+ document_keys: Array,
1239
+ document_byte_element_index_limit: usize,
1240
+ document_delete_trimmed_heads: bool,
1241
+ document_projection_plan_ids: Uint32Array,
1242
+ document_projection_signers: Array,
1243
+ trim_length_to: JsValue,
1244
+ ) -> Result<Array, JsValue> {
1245
+ let len = payload_datas.length() as usize;
1246
+ ensure_batch_append_lens(
1247
+ len,
1248
+ &wall_times,
1249
+ &logicals,
1250
+ &fallback_gids,
1251
+ "batch fallback gids",
1252
+ &meta_datas,
1253
+ &document_keys,
1254
+ )?;
1255
+ ensure_batch_projection_lens(
1256
+ len,
1257
+ &document_projection_plan_ids,
1258
+ None,
1259
+ &document_projection_signers,
1260
+ )?;
1261
+ let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
1262
+ let document_keys = strings_from_array(document_keys)?;
1263
+ let mut document_index_commits = Vec::with_capacity(len);
1264
+ for (index, document_key) in document_keys.iter().enumerate() {
1265
+ let index_u32 = index as u32;
1266
+ document_index_commits.push(
1267
+ document_index_cached_projection_plain_put_payload_append_commit(
1268
+ document_key.clone(),
1269
+ String::new(),
1270
+ document_byte_element_index_limit,
1271
+ document_delete_trimmed_heads,
1272
+ document_projection_plan_ids.get_index(index_u32),
1273
+ document_projection_signers.get(index_u32),
1274
+ )?,
1275
+ );
1276
+ }
1277
+ self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
1278
+ wall_times,
1279
+ logicals,
1280
+ fallback_gids,
1281
+ entry_type,
1282
+ meta_datas,
1283
+ payload_datas,
1284
+ replicas,
1285
+ role_age_ms,
1286
+ now,
1287
+ self_hash,
1288
+ self_replicating,
1289
+ trim_length_to,
1290
+ &document_keys,
1291
+ document_index_commits,
1292
+ )
1293
+ }
1294
+
1295
+ #[allow(clippy::too_many_arguments)]
1296
+ pub fn prepare_plain_committed_storage_append_transaction_trim(
1297
+ &mut self,
1298
+ wall_time: u64,
1299
+ logical: u32,
1300
+ gid: String,
1301
+ next_hashes: Array,
1302
+ entry_type: u8,
1303
+ meta_data: JsValue,
1304
+ payload_data: Uint8Array,
1305
+ replicas: usize,
1306
+ role_age_ms: f64,
1307
+ now: String,
1308
+ self_hash: String,
1309
+ self_replicating: bool,
1310
+ resolve_trimmed_entries: bool,
1311
+ trim_length_to: usize,
1312
+ ) -> Result<Array, JsValue> {
1313
+ self.prepare_plain_storage_append_transaction_inner(
1314
+ wall_time,
1315
+ logical,
1316
+ gid,
1317
+ strings_from_array(next_hashes)?,
1318
+ entry_type,
1319
+ meta_data,
1320
+ payload_data,
1321
+ replicas,
1322
+ role_age_ms,
1323
+ now,
1324
+ self_hash,
1325
+ self_replicating,
1326
+ resolve_trimmed_entries,
1327
+ Some(trim_length_to),
1328
+ true,
1329
+ None,
1330
+ )
1331
+ }
1332
+
1333
+ #[allow(clippy::too_many_arguments)]
1334
+ pub fn prepare_plain_committed_storage_append_document_delete_transaction_trim(
1335
+ &mut self,
1336
+ wall_time: u64,
1337
+ logical: u32,
1338
+ gid: String,
1339
+ next_hashes: Array,
1340
+ entry_type: u8,
1341
+ meta_data: JsValue,
1342
+ payload_data: Uint8Array,
1343
+ replicas: usize,
1344
+ role_age_ms: f64,
1345
+ now: String,
1346
+ self_hash: String,
1347
+ self_replicating: bool,
1348
+ resolve_trimmed_entries: bool,
1349
+ document_key: String,
1350
+ trim_length_to: usize,
1351
+ ) -> Result<Array, JsValue> {
1352
+ let row = self.prepare_plain_storage_append_transaction_inner(
1353
+ wall_time,
1354
+ logical,
1355
+ gid,
1356
+ strings_from_array(next_hashes)?,
1357
+ entry_type,
1358
+ meta_data,
1359
+ payload_data,
1360
+ replicas,
1361
+ role_age_ms,
1362
+ now,
1363
+ self_hash,
1364
+ self_replicating,
1365
+ resolve_trimmed_entries,
1366
+ Some(trim_length_to),
1367
+ true,
1368
+ None,
1369
+ )?;
1370
+ self.delete_document_inner(&document_key, true);
1371
+ Ok(row)
1372
+ }
1373
+
1374
+ #[allow(clippy::too_many_arguments)]
1375
+ pub fn prepare_plain_committed_storage_append_document_index_transaction_trim(
1376
+ &mut self,
1377
+ wall_time: u64,
1378
+ logical: u32,
1379
+ gid: String,
1380
+ next_hashes: Array,
1381
+ entry_type: u8,
1382
+ meta_data: JsValue,
1383
+ payload_data: Uint8Array,
1384
+ replicas: usize,
1385
+ role_age_ms: f64,
1386
+ now: String,
1387
+ self_hash: String,
1388
+ self_replicating: bool,
1389
+ resolve_trimmed_entries: bool,
1390
+ document_key: String,
1391
+ document_value_prefix_bytes: Vec<u8>,
1392
+ document_existing_created: String,
1393
+ document_byte_element_index_limit: usize,
1394
+ document_delete_trimmed_heads: bool,
1395
+ document_projection_plan: JsValue,
1396
+ document_projection_encoded_document: JsValue,
1397
+ document_projection_signer: JsValue,
1398
+ trim_length_to: usize,
1399
+ ) -> Result<Array, JsValue> {
1400
+ self.prepare_plain_storage_append_transaction_inner(
1401
+ wall_time,
1402
+ logical,
1403
+ gid,
1404
+ strings_from_array(next_hashes)?,
1405
+ entry_type,
1406
+ meta_data,
1407
+ payload_data,
1408
+ replicas,
1409
+ role_age_ms,
1410
+ now,
1411
+ self_hash,
1412
+ self_replicating,
1413
+ resolve_trimmed_entries,
1414
+ Some(trim_length_to),
1415
+ true,
1416
+ Some(document_index_append_commit(
1417
+ document_key,
1418
+ document_value_prefix_bytes,
1419
+ document_existing_created,
1420
+ document_byte_element_index_limit,
1421
+ document_delete_trimmed_heads,
1422
+ document_projection_plan,
1423
+ document_projection_encoded_document,
1424
+ document_projection_signer,
1425
+ )?),
1426
+ )
1427
+ }
1428
+ }
1429
+
1430
+ impl NativePeerbitBackbone {
1431
+ #[allow(clippy::too_many_arguments)]
1432
+ fn prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_dispatch(
1433
+ &mut self,
1434
+ wall_times: BigUint64Array,
1435
+ logicals: Uint32Array,
1436
+ fallback_gids: Array,
1437
+ entry_type: u8,
1438
+ meta_datas: Array,
1439
+ payload_datas: Array,
1440
+ replicas: usize,
1441
+ role_age_ms: f64,
1442
+ now: String,
1443
+ self_hash: String,
1444
+ self_replicating: bool,
1445
+ trim_length_to: Option<usize>,
1446
+ document_keys: &[String],
1447
+ document_index_commits: Vec<DocumentIndexAppendCommit>,
1448
+ ) -> Result<Array, JsValue> {
1449
+ if has_duplicate_strings(document_keys) {
1450
+ let out = Array::new();
1451
+ for (index, document_index_commit) in document_index_commits.into_iter().enumerate() {
1452
+ let index_u32 = index as u32;
1453
+ let fallback_gid = fallback_gids
1454
+ .get(index_u32)
1455
+ .as_string()
1456
+ .ok_or_else(|| JsValue::from_str("Expected batch fallback gid string"))?;
1457
+ let row = self
1458
+ .prepare_plain_committed_storage_append_document_index_latest_compact_transaction_inner(
1459
+ wall_times.get_index(index_u32),
1460
+ logicals.get_index(index_u32),
1461
+ fallback_gid,
1462
+ entry_type,
1463
+ meta_datas.get(index_u32),
1464
+ required_bytes_from_array(&payload_datas, index_u32, "payload")?,
1465
+ replicas,
1466
+ role_age_ms,
1467
+ now.clone(),
1468
+ self_hash.clone(),
1469
+ self_replicating,
1470
+ trim_length_to,
1471
+ document_index_commit,
1472
+ )?;
1473
+ out.push(&row);
1474
+ }
1475
+ return Ok(out);
1476
+ }
1477
+ self.prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_inner(
1478
+ wall_times,
1479
+ logicals,
1480
+ fallback_gids,
1481
+ entry_type,
1482
+ meta_datas,
1483
+ payload_datas,
1484
+ replicas,
1485
+ role_age_ms,
1486
+ now,
1487
+ self_hash,
1488
+ self_replicating,
1489
+ trim_length_to,
1490
+ document_index_commits,
1491
+ )
1492
+ }
1493
+
1494
+ #[allow(clippy::too_many_arguments)]
1495
+ fn prepare_plain_committed_storage_append_document_index_latest_transaction_inner(
1496
+ &mut self,
1497
+ wall_time: u64,
1498
+ logical: u32,
1499
+ fallback_gid: String,
1500
+ entry_type: u8,
1501
+ meta_data: JsValue,
1502
+ payload_data: Uint8Array,
1503
+ replicas: usize,
1504
+ role_age_ms: f64,
1505
+ now: String,
1506
+ self_hash: String,
1507
+ self_replicating: bool,
1508
+ resolve_trimmed_entries: bool,
1509
+ trim_length_to: JsValue,
1510
+ mut document_index_commit: DocumentIndexAppendCommit,
1511
+ ) -> Result<Array, JsValue> {
1512
+ let trim_length_to = optional_usize_from_js(trim_length_to, "trimLengthTo")?;
1513
+ let (_, gid, next_hashes) =
1514
+ self.resolve_latest_document_append_context(&mut document_index_commit, fallback_gid)?;
1515
+ self.validate_document_index_required_previous_signer(&document_index_commit)?;
1516
+ self.prepare_plain_storage_append_transaction_inner(
1517
+ wall_time,
1518
+ logical,
1519
+ gid,
1520
+ next_hashes,
1521
+ entry_type,
1522
+ meta_data,
1523
+ payload_data,
1524
+ replicas,
1525
+ role_age_ms,
1526
+ now,
1527
+ self_hash,
1528
+ self_replicating,
1529
+ resolve_trimmed_entries,
1530
+ trim_length_to,
1531
+ true,
1532
+ Some(document_index_commit),
1533
+ )
1534
+ }
1535
+
1536
+ #[allow(clippy::too_many_arguments)]
1537
+ fn prepare_plain_committed_storage_append_document_index_latest_batch_transaction_inner(
1538
+ &mut self,
1539
+ wall_times: BigUint64Array,
1540
+ logicals: Uint32Array,
1541
+ fallback_gids: Array,
1542
+ entry_type: u8,
1543
+ meta_datas: Array,
1544
+ payload_datas: Array,
1545
+ replicas: usize,
1546
+ role_age_ms: f64,
1547
+ now: String,
1548
+ self_hash: String,
1549
+ self_replicating: bool,
1550
+ resolve_trimmed_entries: bool,
1551
+ trim_length_to: JsValue,
1552
+ make_document_index_commit: &mut dyn FnMut(
1553
+ u32,
1554
+ )
1555
+ -> Result<DocumentIndexAppendCommit, JsValue>,
1556
+ ) -> Result<Array, JsValue> {
1557
+ let batch_len = payload_datas.length() as usize;
1558
+ if batch_len == 0 {
1559
+ return Ok(Array::new());
1560
+ }
1561
+ let profile_enabled = self.append_profile_enabled;
1562
+ let storage_append_started = profile_enabled.then(js_sys::Date::now);
1563
+ self.reserve_document_batch(batch_len);
1564
+ let mut pending_appends = Vec::with_capacity(batch_len);
1565
+ let mut coordinate_inputs = Vec::with_capacity(batch_len);
1566
+
1567
+ for index in 0..batch_len {
1568
+ if let Err(error) = self.prepare_latest_batch_append_item(
1569
+ index as u32,
1570
+ &wall_times,
1571
+ &logicals,
1572
+ &fallback_gids,
1573
+ entry_type,
1574
+ &meta_datas,
1575
+ &payload_datas,
1576
+ replicas,
1577
+ role_age_ms,
1578
+ &now,
1579
+ &self_hash,
1580
+ self_replicating,
1581
+ resolve_trimmed_entries,
1582
+ &trim_length_to,
1583
+ make_document_index_commit,
1584
+ &mut pending_appends,
1585
+ &mut coordinate_inputs,
1586
+ ) {
1587
+ // The per-item path fully committed every earlier entry before
1588
+ // failing, so flush the deferred coordinate commits to match.
1589
+ self.flush_latest_batch_pending_coordinates(
1590
+ pending_appends,
1591
+ coordinate_inputs,
1592
+ replicas,
1593
+ role_age_ms,
1594
+ &now,
1595
+ &self_hash,
1596
+ self_replicating,
1597
+ )?;
1598
+ return Err(error);
1599
+ }
1600
+ }
1601
+
1602
+ let coordinate_facts = self.plan_batch_compact_coordinates_profiled(
1603
+ coordinate_inputs,
1604
+ replicas,
1605
+ role_age_ms,
1606
+ &now,
1607
+ &self_hash,
1608
+ self_replicating,
1609
+ pending_appends.len(),
1610
+ "Native latest batch returned mismatched coordinate facts",
1611
+ )?;
1612
+
1613
+ let out = Array::new();
1614
+ for (pending, coordinate_facts) in pending_appends.into_iter().zip(coordinate_facts) {
1615
+ let coordinate_core_started = profile_enabled.then(js_sys::Date::now);
1616
+ self.commit_coordinate_core_from_compact_facts(
1617
+ &coordinate_facts,
1618
+ &pending.next_hashes,
1619
+ &pending.trim_hashes,
1620
+ pending.wall_time,
1621
+ pending.meta_bytes,
1622
+ );
1623
+ if let Some(started) = coordinate_core_started {
1624
+ self.append_profile.coordinate_core_ms += js_sys::Date::now() - started;
1625
+ }
1626
+
1627
+ let result_row_started = profile_enabled.then(js_sys::Date::now);
1628
+ let row = Array::new();
1629
+ row.push(&pending.entry_row);
1630
+ row.push(&leader_samples_to_optional_rows(&coordinate_facts.leaders));
1631
+ row.push(&JsValue::from_bool(coordinate_facts.is_leader));
1632
+ row.push(&JsValue::from_bool(
1633
+ coordinate_facts.assigned_to_range_boundary,
1634
+ ));
1635
+ row.push(&coordinate_plan_to_row(&self.resolution, &coordinate_facts));
1636
+ row.push(&pending.trim_rows);
1637
+ row.push(&strings_to_array(pending.trim_hashes));
1638
+ row.push(&JsValue::from_bool(
1639
+ pending.document_trimmed_heads_processed,
1640
+ ));
1641
+ row.push(
1642
+ &pending
1643
+ .previous_document_context
1644
+ .as_ref()
1645
+ .map(|context| document_context_facts_to_row(context).into())
1646
+ .unwrap_or(JsValue::UNDEFINED),
1647
+ );
1648
+ out.push(&row);
1649
+ if let Some(started) = result_row_started {
1650
+ self.append_profile.result_row_ms += js_sys::Date::now() - started;
1651
+ }
1652
+ }
1653
+
1654
+ if let Some(started) = storage_append_started {
1655
+ self.append_profile.storage_append_inner_ms += js_sys::Date::now() - started;
1656
+ }
1657
+ Ok(out)
1658
+ }
1659
+
1660
+ #[allow(clippy::too_many_arguments)]
1661
+ fn prepare_latest_batch_append_item(
1662
+ &mut self,
1663
+ index: u32,
1664
+ wall_times: &BigUint64Array,
1665
+ logicals: &Uint32Array,
1666
+ fallback_gids: &Array,
1667
+ entry_type: u8,
1668
+ meta_datas: &Array,
1669
+ payload_datas: &Array,
1670
+ replicas: usize,
1671
+ role_age_ms: f64,
1672
+ now: &str,
1673
+ self_hash: &str,
1674
+ self_replicating: bool,
1675
+ resolve_trimmed_entries: bool,
1676
+ trim_length_to: &JsValue,
1677
+ make_document_index_commit: &mut dyn FnMut(
1678
+ u32,
1679
+ )
1680
+ -> Result<DocumentIndexAppendCommit, JsValue>,
1681
+ pending_appends: &mut Vec<LatestBatchPendingAppend>,
1682
+ coordinate_inputs: &mut Vec<NativeLocalAppendCompactInput>,
1683
+ ) -> Result<(), JsValue> {
1684
+ let profile_enabled = self.append_profile_enabled;
1685
+ let fallback_gid = fallback_gids
1686
+ .get(index)
1687
+ .as_string()
1688
+ .ok_or_else(|| JsValue::from_str("Expected batch fallback gid string"))?;
1689
+ let mut document_index_commit = make_document_index_commit(index)?;
1690
+ let payload_data = required_bytes_from_array(payload_datas, index, "payload")?;
1691
+ let trim_length_to = optional_usize_from_js(trim_length_to.clone(), "trimLengthTo")?;
1692
+ let payload_size = payload_data.length();
1693
+ let delete_trimmed_document_heads = document_index_commit.delete_trimmed_heads;
1694
+ let (previous_document_context, gid, next_hashes) =
1695
+ self.resolve_latest_document_append_context(&mut document_index_commit, fallback_gid)?;
1696
+ self.validate_document_index_required_previous_signer(&document_index_commit)?;
1697
+
1698
+ let (meta_data, payload_data) =
1699
+ self.copy_append_inputs_profiled(meta_datas.get(index), &payload_data);
1700
+
1701
+ 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(
1704
+ wall_time,
1705
+ logicals.get_index(index),
1706
+ gid.clone(),
1707
+ next_hashes.clone(),
1708
+ entry_type,
1709
+ meta_data,
1710
+ payload_data,
1711
+ trim_length_to,
1712
+ resolve_trimmed_entries,
1713
+ )?;
1714
+
1715
+ let hash_number = self.hash_number_profiled(&entry_facts.hash_digest_bytes)?;
1716
+ if index == 0 {
1717
+ // An unparseable `now` must surface exactly where the per-item
1718
+ // path raised it: after the first log append, before any other
1719
+ // entry or commit is applied.
1720
+ commit_local_appends_for_gids_compact_core(
1721
+ &mut self.shared_log,
1722
+ Vec::new(),
1723
+ replicas,
1724
+ role_age_ms,
1725
+ now,
1726
+ self_hash,
1727
+ self_replicating,
1728
+ true,
1729
+ true,
1730
+ )?;
1731
+ }
1732
+
1733
+ coordinate_inputs.push(NativeLocalAppendCompactInput {
1734
+ entry_hash: entry_facts.hash.clone(),
1735
+ gid: gid.clone(),
1736
+ entry_hash_number: hash_number,
1737
+ next_hashes: next_hashes.clone(),
1738
+ delete_hashes: trim_hashes.clone(),
1739
+ });
1740
+ let mut pending_append = LatestBatchPendingAppend {
1741
+ wall_time,
1742
+ next_hashes,
1743
+ meta_bytes: entry_facts.meta_bytes.clone(),
1744
+ trim_hashes,
1745
+ entry_row,
1746
+ trim_rows,
1747
+ document_trimmed_heads_processed: false,
1748
+ previous_document_context,
1749
+ };
1750
+
1751
+ let document_index_started = profile_enabled.then(js_sys::Date::now);
1752
+ let prepared_document_put = match self.prepare_document_index_append_put(
1753
+ document_index_commit,
1754
+ wall_time,
1755
+ &entry_facts.hash,
1756
+ &gid,
1757
+ payload_size,
1758
+ None,
1759
+ ) {
1760
+ Ok(prepared) => prepared,
1761
+ Err(error) => {
1762
+ // The per-item path commits the coordinate before the document
1763
+ // index write can fail, so leave this entry coordinate-flushable.
1764
+ pending_appends.push(pending_append);
1765
+ return Err(error);
1766
+ }
1767
+ };
1768
+ self.commit_prepared_document_index_append_put(prepared_document_put);
1769
+ let document_trimmed_heads_processed = delete_trimmed_document_heads
1770
+ && self.delete_documents_by_context_heads_profiled(&pending_append.trim_hashes);
1771
+ pending_append.document_trimmed_heads_processed = document_trimmed_heads_processed;
1772
+ if let Some(started) = document_index_started {
1773
+ self.append_profile.document_index_commit_ms += js_sys::Date::now() - started;
1774
+ }
1775
+ pending_appends.push(pending_append);
1776
+ Ok(())
1777
+ }
1778
+
1779
+ #[allow(clippy::too_many_arguments)]
1780
+ fn flush_latest_batch_pending_coordinates(
1781
+ &mut self,
1782
+ pending_appends: Vec<LatestBatchPendingAppend>,
1783
+ coordinate_inputs: Vec<NativeLocalAppendCompactInput>,
1784
+ replicas: usize,
1785
+ role_age_ms: f64,
1786
+ now: &str,
1787
+ self_hash: &str,
1788
+ self_replicating: bool,
1789
+ ) -> Result<(), JsValue> {
1790
+ if coordinate_inputs.is_empty() {
1791
+ return Ok(());
1792
+ }
1793
+ let coordinate_facts = commit_local_appends_for_gids_compact_core(
1794
+ &mut self.shared_log,
1795
+ coordinate_inputs,
1796
+ replicas,
1797
+ role_age_ms,
1798
+ now,
1799
+ self_hash,
1800
+ self_replicating,
1801
+ true,
1802
+ true,
1803
+ )?;
1804
+ for (pending, coordinate_facts) in pending_appends.into_iter().zip(coordinate_facts) {
1805
+ self.commit_coordinate_core_from_compact_facts(
1806
+ &coordinate_facts,
1807
+ &pending.next_hashes,
1808
+ &pending.trim_hashes,
1809
+ pending.wall_time,
1810
+ pending.meta_bytes,
1811
+ );
1812
+ }
1813
+ Ok(())
1814
+ }
1815
+
1816
+ #[allow(clippy::too_many_arguments)]
1817
+ fn prepare_plain_committed_storage_append_document_index_latest_compact_batch_transaction_inner(
1818
+ &mut self,
1819
+ wall_times: BigUint64Array,
1820
+ logicals: Uint32Array,
1821
+ fallback_gids: Array,
1822
+ entry_type: u8,
1823
+ meta_datas: Array,
1824
+ payload_datas: Array,
1825
+ replicas: usize,
1826
+ role_age_ms: f64,
1827
+ now: String,
1828
+ self_hash: String,
1829
+ self_replicating: bool,
1830
+ trim_length_to: Option<usize>,
1831
+ document_index_commits: Vec<DocumentIndexAppendCommit>,
1832
+ ) -> Result<Array, JsValue> {
1833
+ let profile_enabled = self.append_profile_enabled;
1834
+ let storage_append_started = profile_enabled.then(js_sys::Date::now);
1835
+ let batch_len = document_index_commits.len();
1836
+ self.reserve_document_batch(batch_len);
1837
+ let mut pending_appends = Vec::with_capacity(batch_len);
1838
+ let mut coordinate_inputs = Vec::with_capacity(batch_len);
1839
+
1840
+ for (index, mut document_index_commit) in document_index_commits.into_iter().enumerate() {
1841
+ let index_u32 = index as u32;
1842
+ let fallback_gid = fallback_gids
1843
+ .get(index_u32)
1844
+ .as_string()
1845
+ .ok_or_else(|| JsValue::from_str("Expected batch fallback gid string"))?;
1846
+ let payload_bytes = required_bytes_from_array(&payload_datas, index_u32, "payload")?;
1847
+ let payload_size = payload_bytes.length();
1848
+ let delete_trimmed_document_heads = document_index_commit.delete_trimmed_heads;
1849
+ let (previous_document_context, gid, next_hashes) = self
1850
+ .resolve_latest_document_append_context(&mut document_index_commit, fallback_gid)?;
1851
+ self.validate_document_index_required_previous_signer(&document_index_commit)?;
1852
+
1853
+ let (meta_data, payload_data) =
1854
+ self.copy_append_inputs_profiled(meta_datas.get(index_u32), &payload_bytes);
1855
+
1856
+ let (entry_facts, trim_hashes) = self.prepare_latest_log_append_profiled(
1857
+ wall_times.get_index(index_u32),
1858
+ logicals.get_index(index_u32),
1859
+ gid.clone(),
1860
+ next_hashes,
1861
+ entry_type,
1862
+ meta_data,
1863
+ &payload_data,
1864
+ trim_length_to,
1865
+ )?;
1866
+
1867
+ let hash_number = self.hash_number_profiled(&entry_facts.hash_digest_bytes)?;
1868
+ let materialization_bytes = trim_length_to
1869
+ .is_some()
1870
+ .then(|| self.blocks.get_ref(&entry_facts.hash).map(Uint8Array::from))
1871
+ .flatten();
1872
+
1873
+ coordinate_inputs.push(NativeLocalAppendCompactInput {
1874
+ entry_hash: entry_facts.hash.clone(),
1875
+ gid: gid.clone(),
1876
+ entry_hash_number: hash_number,
1877
+ next_hashes: entry_facts.next.clone(),
1878
+ delete_hashes: trim_hashes.clone(),
1879
+ });
1880
+ let plain_put_payload_data = matches!(
1881
+ &document_index_commit.value_prefix,
1882
+ DocumentIndexValuePrefix::PlainPutPayloadIdentity
1883
+ | DocumentIndexValuePrefix::PlainPutPayloadProjection { .. }
1884
+ )
1885
+ .then_some(payload_data);
1886
+ pending_appends.push(LatestCompactBatchPendingAppend {
1887
+ wall_time: wall_times.get_index(index_u32),
1888
+ payload_size,
1889
+ gid,
1890
+ entry_facts,
1891
+ trim_hashes,
1892
+ document_index_commit,
1893
+ previous_document_context,
1894
+ delete_trimmed_document_heads,
1895
+ plain_put_payload_data,
1896
+ materialization_bytes,
1897
+ });
1898
+ }
1899
+
1900
+ let coordinate_facts = self.plan_batch_compact_coordinates_profiled(
1901
+ coordinate_inputs,
1902
+ replicas,
1903
+ role_age_ms,
1904
+ &now,
1905
+ &self_hash,
1906
+ self_replicating,
1907
+ pending_appends.len(),
1908
+ "Native compact batch returned mismatched coordinate facts",
1909
+ )?;
1910
+
1911
+ let out = Array::new();
1912
+ for (pending, coordinate_facts) in pending_appends.into_iter().zip(coordinate_facts) {
1913
+ let coordinate_core_started = profile_enabled.then(js_sys::Date::now);
1914
+ self.commit_coordinate_core_from_compact_facts(
1915
+ &coordinate_facts,
1916
+ &pending.entry_facts.next,
1917
+ &pending.trim_hashes,
1918
+ pending.wall_time,
1919
+ pending.entry_facts.meta_bytes.clone(),
1920
+ );
1921
+ if let Some(started) = coordinate_core_started {
1922
+ self.append_profile.coordinate_core_ms += js_sys::Date::now() - started;
1923
+ }
1924
+
1925
+ let document_trimmed_heads_processed = self.commit_append_document_index_profiled(
1926
+ Some(pending.document_index_commit),
1927
+ pending.wall_time,
1928
+ &pending.entry_facts.hash,
1929
+ &pending.gid,
1930
+ pending.payload_size,
1931
+ pending.plain_put_payload_data.as_deref(),
1932
+ pending.delete_trimmed_document_heads,
1933
+ &pending.trim_hashes,
1934
+ )?;
1935
+
1936
+ let result_row_started = profile_enabled.then(js_sys::Date::now);
1937
+ let row = latest_compact_entry_row(
1938
+ &self.resolution,
1939
+ pending.entry_facts,
1940
+ &coordinate_facts,
1941
+ pending.trim_hashes,
1942
+ document_trimmed_heads_processed,
1943
+ pending.previous_document_context.as_ref(),
1944
+ );
1945
+ row.push(
1946
+ &pending
1947
+ .materialization_bytes
1948
+ .map(JsValue::from)
1949
+ .unwrap_or(JsValue::UNDEFINED),
1950
+ );
1951
+ out.push(&row);
1952
+ if let Some(started) = result_row_started {
1953
+ self.append_profile.result_row_ms += js_sys::Date::now() - started;
1954
+ }
1955
+ }
1956
+
1957
+ if let Some(started) = storage_append_started {
1958
+ self.append_profile.storage_append_inner_ms += js_sys::Date::now() - started;
1959
+ }
1960
+ Ok(out)
1961
+ }
1962
+
1963
+ #[allow(clippy::too_many_arguments)]
1964
+ fn prepare_plain_committed_storage_append_document_index_latest_compact_transaction_inner(
1965
+ &mut self,
1966
+ wall_time: u64,
1967
+ logical: u32,
1968
+ fallback_gid: String,
1969
+ entry_type: u8,
1970
+ meta_data: JsValue,
1971
+ payload_data: Uint8Array,
1972
+ replicas: usize,
1973
+ role_age_ms: f64,
1974
+ now: String,
1975
+ self_hash: String,
1976
+ self_replicating: bool,
1977
+ trim_length_to: Option<usize>,
1978
+ mut document_index_commit: DocumentIndexAppendCommit,
1979
+ ) -> Result<Array, JsValue> {
1980
+ let profile_enabled = self.append_profile_enabled;
1981
+ let storage_append_started = profile_enabled.then(js_sys::Date::now);
1982
+ let payload_size = payload_data.length();
1983
+ let delete_trimmed_document_heads = document_index_commit.delete_trimmed_heads;
1984
+ let (previous_document_context, gid, next_hashes) =
1985
+ self.resolve_latest_document_append_context(&mut document_index_commit, fallback_gid)?;
1986
+ self.validate_document_index_required_previous_signer(&document_index_commit)?;
1987
+
1988
+ let (meta_data, payload_data) = self.copy_append_inputs_profiled(meta_data, &payload_data);
1989
+
1990
+ let (entry_facts, trim_hashes) = self.prepare_latest_log_append_profiled(
1991
+ wall_time,
1992
+ logical,
1993
+ gid.clone(),
1994
+ next_hashes,
1995
+ entry_type,
1996
+ meta_data,
1997
+ &payload_data,
1998
+ trim_length_to,
1999
+ )?;
2000
+
2001
+ let hash_number = self.hash_number_profiled(&entry_facts.hash_digest_bytes)?;
2002
+
2003
+ let coordinate_plan_started = profile_enabled.then(js_sys::Date::now);
2004
+ let coordinate_facts = commit_local_append_for_gid_compact_core(
2005
+ &mut self.shared_log,
2006
+ entry_facts.hash.clone(),
2007
+ gid.clone(),
2008
+ hash_number,
2009
+ &entry_facts.next,
2010
+ &trim_hashes,
2011
+ replicas,
2012
+ role_age_ms,
2013
+ &now,
2014
+ &self_hash,
2015
+ self_replicating,
2016
+ true,
2017
+ true,
2018
+ )?;
2019
+ if let Some(started) = coordinate_plan_started {
2020
+ self.append_profile.coordinate_plan_ms += js_sys::Date::now() - started;
2021
+ }
2022
+
2023
+ let coordinate_core_started = profile_enabled.then(js_sys::Date::now);
2024
+ self.commit_coordinate_core_from_compact_facts(
2025
+ &coordinate_facts,
2026
+ &entry_facts.next,
2027
+ &trim_hashes,
2028
+ wall_time,
2029
+ entry_facts.meta_bytes.clone(),
2030
+ );
2031
+ if let Some(started) = coordinate_core_started {
2032
+ self.append_profile.coordinate_core_ms += js_sys::Date::now() - started;
2033
+ }
2034
+
2035
+ let document_trimmed_heads_processed = self.commit_append_document_index_profiled(
2036
+ Some(document_index_commit),
2037
+ wall_time,
2038
+ &entry_facts.hash,
2039
+ &gid,
2040
+ payload_size,
2041
+ Some(&payload_data),
2042
+ delete_trimmed_document_heads,
2043
+ &trim_hashes,
2044
+ )?;
2045
+
2046
+ let result_row_started = profile_enabled.then(js_sys::Date::now);
2047
+ let out = latest_compact_entry_row(
2048
+ &self.resolution,
2049
+ entry_facts,
2050
+ &coordinate_facts,
2051
+ trim_hashes,
2052
+ document_trimmed_heads_processed,
2053
+ previous_document_context.as_ref(),
2054
+ );
2055
+ if let Some(started) = result_row_started {
2056
+ self.append_profile.result_row_ms += js_sys::Date::now() - started;
2057
+ }
2058
+ if let Some(started) = storage_append_started {
2059
+ self.append_profile.storage_append_inner_ms += js_sys::Date::now() - started;
2060
+ }
2061
+ Ok(out)
2062
+ }
2063
+ }