uni-common 2.0.3

Common types, identity encoding, and schema for Uni graph database
Documentation
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024-2026 Dragonscale Team

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SnapshotManifest {
    pub snapshot_id: String,
    pub name: Option<String>,
    pub created_at: DateTime<Utc>,
    pub parent_snapshot: Option<String>,
    pub schema_version: u32,
    pub version_high_water_mark: u64,
    pub wal_high_water_mark: u64,

    pub vertices: HashMap<String, LabelSnapshot>,
    pub edges: HashMap<String, EdgeSnapshot>,
}

/// Snapshot counters for one entity kind (a vertex label or an edge type).
///
/// Labels and edge types capture the identical shape, so one struct serves
/// both via the [`LabelSnapshot`] / [`EdgeSnapshot`] aliases — the map key
/// (in [`SnapshotManifest::vertices`] vs `edges`) already conveys which kind.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct EntitySnapshot {
    pub version: u32,
    pub count: u64,
    pub lance_version: u64,
}

/// Snapshot counters for a vertex label. Alias of [`EntitySnapshot`].
pub type LabelSnapshot = EntitySnapshot;

/// Snapshot counters for an edge type. Alias of [`EntitySnapshot`].
pub type EdgeSnapshot = EntitySnapshot;

impl SnapshotManifest {
    pub fn new(snapshot_id: String, schema_version: u32) -> Self {
        Self {
            snapshot_id,
            name: None,
            created_at: Utc::now(),
            parent_snapshot: None,
            schema_version,
            version_high_water_mark: 0,
            wal_high_water_mark: 0,
            vertices: HashMap::new(),
            edges: HashMap::new(),
        }
    }
}