Skip to main content

oxigdal_offline/
lib.rs

1//! OxiGDAL Offline - Offline-First Data Management
2//!
3//! This crate provides comprehensive offline-first data management capabilities for OxiGDAL,
4//! including local storage, sync queue management, conflict resolution, and optimistic updates.
5//!
6//! # Features
7//!
8//! - **Offline-first architecture**: Local-first data layer with background sync
9//! - **Multi-platform storage**: IndexedDB for WASM, SQLite for native platforms
10//! - **Sync queue management**: Persistent queue with automatic retry
11//! - **Conflict detection**: Automatic detection of concurrent modifications
12//! - **Merge strategies**: Configurable strategies (Last-Write-Wins, Three-Way-Merge, Custom)
13//! - **Background sync**: Automatic sync when connectivity is restored
14//! - **Optimistic updates**: Immediate UI updates with eventual consistency
15//! - **Retry mechanisms**: Exponential backoff with jitter
16//!
17//! # Architecture
18//!
19//! The offline system consists of several key components:
20//!
21//! 1. **Storage Layer**: Abstraction over IndexedDB (WASM) and SQLite (native)
22//! 2. **Sync Queue**: Persistent queue of pending operations
23//! 3. **Conflict Detector**: Detects concurrent modifications
24//! 4. **Merge Engine**: Resolves conflicts using configurable strategies
25//! 5. **Retry Manager**: Handles failed sync attempts with exponential backoff
26//! 6. **Optimistic Update Tracker**: Tracks optimistic changes for rollback
27//!
28//! # Example
29//!
30//! ```rust,no_run
31//! use oxigdal_offline::{OfflineManager, Config, MergeStrategy};
32//! use oxigdal_offline::storage::StorageBackend;
33//!
34//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
35//! // Configure offline manager
36//! let config = Config::builder()
37//!     .max_queue_size(1000)
38//!     .merge_strategy(MergeStrategy::LastWriteWins)
39//!     .retry_max_attempts(5)
40//!     .build()?;
41//!
42//! // Create offline manager
43//! let manager = OfflineManager::new(config).await?;
44//!
45//! // Write data (automatically queued for sync)
46//! manager.write("key1", b"value1").await?;
47//!
48//! // Read data (from local cache)
49//! let value = manager.read("key1").await?;
50//!
51//! // Sync when online
52//! manager.sync().await?;
53//! # Ok(())
54//! # }
55//! ```
56//!
57//! # WASM Support
58//!
59//! The crate is fully WASM-compatible, using IndexedDB for storage in browsers:
60//!
61//! ```rust,ignore
62//! // Enable WASM feature in Cargo.toml
63//! // oxigdal-offline = { version = "0.1", features = ["wasm"] }
64//!
65//! use oxigdal_offline::OfflineManager;
66//! use oxigdal_offline::error::Result;
67//!
68//! async fn wasm_example() -> Result<()> {
69//!     let manager = OfflineManager::new_wasm("my-database").await?;
70//!     manager.write("key", b"value").await?;
71//!     Ok(())
72//! }
73//! ```
74
75#![warn(missing_docs)]
76#![deny(clippy::unwrap_used)]
77#![deny(clippy::panic)]
78#![allow(clippy::module_name_repetitions)]
79
80pub mod config;
81pub mod conflict;
82pub mod error;
83pub mod manager;
84pub mod merge;
85pub mod optimistic;
86pub mod queue;
87pub mod retry;
88pub mod storage;
89pub mod sync;
90pub mod types;
91
92// Re-export commonly used items
93pub use config::{Config, ConfigBuilder};
94pub use error::{Error, Result};
95pub use manager::OfflineManager;
96pub use merge::MergeStrategy;
97pub use types::{Operation, OperationId, Record, RecordId, Version};
98
99/// Crate version
100pub const VERSION: &str = env!("CARGO_PKG_VERSION");
101
102/// Crate name
103pub const NAME: &str = env!("CARGO_PKG_NAME");
104
105#[cfg(test)]
106mod tests {
107    use super::*;
108
109    #[test]
110    fn test_version() {
111        assert!(!VERSION.is_empty());
112        assert_eq!(NAME, "oxigdal-offline");
113    }
114}