Weave documentation
Nexus

Views

Local view updates, offset pagination and separately applied persistence batches.

ViewManager::add_entries is synchronous and returns an optional persistence batch. It updates local view state; callers using a persistence sink must execute the returned batch through the intended integration. paginate returns items, next, prev and total. Cursors encode offsets into the current view, not immutable snapshot positions.

This example is checked against source signatures; it was not compiled or run during this documentation pass.

use nexus::{
    NexusCursor, TimestampOrdering, UnorderedEntry, ViewManager, ViewMetadata,
};
use std::time::{Duration, SystemTime};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // ViewManager owns the linearized output. It pairs an OrderingStrategy with
    // the live merged list and supports incremental add_entries / pagination.
    let mut manager = ViewManager::new(Box::new(TimestampOrdering::new()));

    let base = SystemTime::now();
    let batch: Vec<UnorderedEntry> = (0..5)
        .map(|i| UnorderedEntry {
            source_agent: format!("did:l1fe:writer-{}", i % 2),
            source_index: i,
            data: format!("event-{i}").into_bytes(),
            timestamp: base + Duration::from_millis(i as u64 * 10),
            metadata: None,
        })
        .collect();

    let _pending_persistence = manager.add_entries(batch)?;

    // Paginate the merged view; the returned Page yields a Vec<ViewEntry> plus
    // forward/backward cursors and the total entry count.
    let page = manager.paginate(Some(NexusCursor::from_offset(0)), 3);
    let metadata = ViewMetadata::from_data(&page.items[0].data, None);

    println!(
        "len={} page_items={} total={} first_hash={}",
        manager.len(),
        page.items.len(),
        page.total,
        hex::encode(metadata.hash),
    );
    Ok(())
}

Source declarations