Skip to main content

Module validate

Module validate 

Source
Expand description

Event format validation and hardening.

Three validation levels:

  1. Line syntax — TSJSON shape (8 tab-separated fields), valid UTF-8, event_hash matches recomputed BLAKE3 hash of fields 1–7.
  2. Schema validation — Typed payload deserialization per event type. Unknown fields are preserved (forward compatible). Unknown event types produce warnings, not errors.
  3. Semantic validation — Enum constraint checks (kind, urgency, size, state values), item ID format, link target format.

§Shard-level checks

  • Verifies Merkle hash chains against shard manifests.
  • Detects truncated event files (incomplete trailing lines).
  • Preserves valid events before a corrupt line in the report.

§Usage

use std::path::Path;
use bones_core::event::validate::{validate_shard, validate_all};

// Validate a single shard file
let report = validate_shard(Path::new(".bones/events/2026-01.events"), None);
println!("passed: {}, failed: {}", report.passed, report.failed);
for err in &report.errors {
    println!("  line {}: {:?} — {}", err.line_num, err.kind, err.message);
}

// Validate all shards in a directory
let reports = validate_all(Path::new(".bones/events"));

Structs§

ValidationError
Details about a single validation failure.
ValidationReport
Summary report from validating an entire shard.

Enums§

ValidationErrorKind
Category of validation failure.

Constants§

MAX_PAYLOAD_BYTES
Maximum allowed size (in bytes) for the JSON data field of a single event.

Functions§

validate_all
Validate all shard files (*.events) in an events directory.
validate_event
Validate a single TSJSON event line.
validate_shard
Validate an entire shard file.