WeaveDocs
Nexus

Views

Views in Nexus — declarative multi-strand projections with custom ordering, governance, and materialised state.

Purpose

Multi-strand ordered views with governance, custom ordering, strand input stats, and materialized projections.

This page follows the real source shape for Nexus and explains the workflow a developer is likely to use first.

Developer workflow

Start from the smallest constructor or builder, perform one meaningful operation, inspect the returned state, then add the relevant policy, storage, or network integration. The examples below should be expanded whenever the crate API changes.

Primary types to know

  • AllowAllPolicy — models/nexus/src/governance.rs
  • ApprovalRecord — models/nexus/src/governance.rs
  • CustomOrdering — models/nexus/src/ordering.rs
  • GovernancePolicy — models/nexus/src/governance.rs
  • GovernanceRules — models/nexus/src/governance.rs
  • IndexOrdering — models/nexus/src/ordering.rs
  • InputStrand — models/nexus/src/strand_input.rs
  • MemoryView — models/nexus/src/view.rs
  • Nexus — models/nexus/src/nexus.rs
  • NexusConfig — models/nexus/src/config.rs
  • NexusCursor — models/nexus/src/view.rs
  • Page — models/nexus/src/view.rs

Example shape

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();

    manager.add_entries(batch).await?;

    // 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(())
}