bones-core 0.24.6

Core data structures, CRDT event model, and projection engine for bones
Documentation
#![deny(unsafe_code)]
//! bones-core library.

pub mod cache;
pub mod capabilities;
pub mod clock;
pub mod compact;
pub mod config;
pub mod crdt;
pub mod dag;
pub mod db;
pub mod error;
pub mod event;
pub mod graph;
pub mod lock;
pub mod model;
pub mod recovery;
pub mod shard;
pub mod sync;
pub mod timing;
pub mod undo;
pub mod verify;

use tracing::{info, instrument};

/// # Conventions
///
/// - **Errors**: Use `anyhow::Result` for return types where appropriate.
/// - **Logging**: Use `tracing` macros (`info!`, `warn!`, `error!`, `debug!`, `trace!`).

#[instrument]
pub fn init() {
    info!("bones-core initialized");
    // Ensure .bones/.gitattributes exists and has the union merge hint for events.
    let bones_dir = std::path::Path::new(".bones");
    if !bones_dir.is_dir() {
        return;
    }

    let gitattributes_path = bones_dir.join(".gitattributes");
    let attr_line = "events/** merge=union\n";
    let legacy_attr = "events merge=union";

    let mut content = if gitattributes_path.exists() {
        std::fs::read_to_string(&gitattributes_path).unwrap_or_default()
    } else {
        String::new()
    };

    // Migrate old buggy pattern that only matched a file named `events`.
    if content.contains(legacy_attr) && !content.contains("events/**") {
        content = content.replace(legacy_attr, "events/** merge=union");
        let _ = std::fs::write(&gitattributes_path, &content);
    } else if !content.contains("events/** merge=union") {
        if !content.is_empty() && !content.ends_with('\n') {
            content.push('\n');
        }
        content.push_str(attr_line);
        let _ = std::fs::write(gitattributes_path, content);
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert!(true);
    }
}