@peerbit/native-backbone 0.2.9 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -20
- package/dist/src/index.d.ts +59 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +942 -74
- package/dist/src/index.js.map +1 -1
- package/dist/wasm/README.md +55 -20
- package/dist/wasm/native_backbone.d.ts +118 -79
- package/dist/wasm/native_backbone.js +227 -0
- package/dist/wasm/native_backbone_bg.wasm +0 -0
- package/dist/wasm/native_backbone_bg.wasm.d.ts +87 -79
- package/package.json +1 -1
- package/src/append_tx/committed_latest.rs +10 -5
- package/src/append_tx/committed_no_next.rs +6 -3
- package/src/append_tx/facts.rs +427 -1
- package/src/append_tx/mod.rs +51 -18
- package/src/append_tx/storage.rs +12 -2
- package/src/index.ts +1388 -223
package/src/append_tx/mod.rs
CHANGED
|
@@ -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
|
|
293
|
+
let (entry, refs) = if let Some(trim_length_to) = trim_length_to {
|
|
284
294
|
self.log
|
|
285
|
-
.
|
|
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(
|
|
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
|
|
347
|
+
let (entry, refs) = self
|
|
337
348
|
.log
|
|
338
|
-
.
|
|
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
|
-
|
|
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<
|
|
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
|
-
|
|
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,
|
|
425
|
+
let (entry_facts, trim_refs) = self
|
|
403
426
|
.log
|
|
404
|
-
.
|
|
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
|
-
(
|
|
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<
|
|
475
|
-
|
|
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)]
|
package/src/append_tx/storage.rs
CHANGED
|
@@ -2,7 +2,7 @@ use js_sys::{Array, Uint8Array};
|
|
|
2
2
|
use peerbit_shared_log_rust::commit_local_append_for_gid_compact_core;
|
|
3
3
|
use wasm_bindgen::prelude::*;
|
|
4
4
|
|
|
5
|
-
use crate::append_tx::coordinate_plan_to_row;
|
|
5
|
+
use crate::append_tx::{coordinate_plan_to_row, push_trim_gid_extension};
|
|
6
6
|
use crate::documents::{
|
|
7
7
|
document_context_facts_to_row, document_index_append_commit, DocumentIndexAppendCommit,
|
|
8
8
|
};
|
|
@@ -473,10 +473,11 @@ impl NativePeerbitBackbone {
|
|
|
473
473
|
let previous_document_context = document_index_commit
|
|
474
474
|
.as_ref()
|
|
475
475
|
.and_then(|commit| commit.previous_context.clone());
|
|
476
|
+
let mut committed_trim_gids = None;
|
|
476
477
|
let (entry_row, trim_rows, trim_hashes, hash, digest, meta_bytes) = if commit_blocks {
|
|
477
478
|
let (meta_data, payload_data) =
|
|
478
479
|
self.copy_append_inputs_profiled(meta_data, &payload_data)?;
|
|
479
|
-
let (entry_facts, trim_hashes, entry_row, trim_rows) = self
|
|
480
|
+
let (entry_facts, trim_hashes, trim_gids, entry_row, trim_rows) = self
|
|
480
481
|
.prepare_committed_log_append_rows_profiled(
|
|
481
482
|
wall_time,
|
|
482
483
|
logical,
|
|
@@ -488,6 +489,7 @@ impl NativePeerbitBackbone {
|
|
|
488
489
|
trim_length_to,
|
|
489
490
|
resolve_trimmed_entries,
|
|
490
491
|
)?;
|
|
492
|
+
committed_trim_gids = Some(trim_gids);
|
|
491
493
|
(
|
|
492
494
|
entry_row,
|
|
493
495
|
trim_rows,
|
|
@@ -549,6 +551,13 @@ impl NativePeerbitBackbone {
|
|
|
549
551
|
let meta_bytes = bytes_field(&row, 4, "storage entry meta bytes")?;
|
|
550
552
|
(row, Array::new(), Vec::new(), hash, digest, meta_bytes)
|
|
551
553
|
};
|
|
554
|
+
let trim_gids = match committed_trim_gids {
|
|
555
|
+
Some(trim_gids) => trim_gids,
|
|
556
|
+
None => trim_rows
|
|
557
|
+
.iter()
|
|
558
|
+
.map(|row| string_field(&array_from_value(row, "trim row")?, 1, "trim gid"))
|
|
559
|
+
.collect::<Result<Vec<_>, _>>()?,
|
|
560
|
+
};
|
|
552
561
|
|
|
553
562
|
let hash_number = self.hash_number_profiled(&digest)?;
|
|
554
563
|
let document_hash = hash.clone();
|
|
@@ -612,6 +621,7 @@ impl NativePeerbitBackbone {
|
|
|
612
621
|
.map(|context| document_context_facts_to_row(context).into())
|
|
613
622
|
.unwrap_or(JsValue::UNDEFINED),
|
|
614
623
|
);
|
|
624
|
+
push_trim_gid_extension(&out, trim_gids);
|
|
615
625
|
if let Some(started) = result_row_started {
|
|
616
626
|
self.append_profile.result_row_ms += crate::time::now_ms() - started;
|
|
617
627
|
}
|