Files
zesdex/crates/zesdex-cms/src/domain/edit_log.rs
T

58 lines
1.5 KiB
Rust
Raw Normal View History

//! Pure EditLog entities — append-only log of file mutations for audit / undo.
//!
//! # Architecture
//! This is a pure data structure with **no I/O logic**. Load/save
//! responsibilities live in [`EditLogRepository`](super::repository::EditLogRepository).
use serde::{Deserialize, Serialize};
/// A single recorded file edit: which tool made it, to which path, why,
/// and a content hash/size delta for verification.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EditLogEntry {
pub ts: i64,
pub tool: String,
pub path: String,
pub reason: String,
pub content_sha256: String,
pub bytes_delta: i64,
pub origin: String,
pub session_id: String,
}
/// Maximum number of edit entries held in memory at once.
/// Beyond this limit, old entries are dropped from the in-memory cache
/// to prevent unbounded memory growth in long sessions.
pub const MAX_MEMORY_ENTRIES: usize = 10_000;
/// In-memory view of a session's edit log.
#[derive(Debug, Clone)]
pub struct EditLog {
pub entries: Vec<EditLogEntry>,
}
impl EditLog {
/// Create an empty edit log.
pub fn new() -> Self {
Self {
entries: Vec::new(),
}
}
/// Return the number of in-memory entries.
pub fn len(&self) -> usize {
self.entries.len()
}
/// Return `true` if the log is empty.
pub fn is_empty(&self) -> bool {
self.entries.is_empty()
}
}
impl Default for EditLog {
fn default() -> Self {
Self::new()
}
}