amaters_sdk_rust/lib.rs
1//! # AmateRS SDK for Rust
2//!
3//! This is the official Rust SDK for AmateRS, a Fully Homomorphic Encrypted Database.
4//!
5//! ## Features
6//!
7//! - **Client-side encryption**: All encryption/decryption happens on the client
8//! - **Connection pooling**: Efficient connection management with automatic reconnection
9//! - **Retry logic**: Automatic retries with exponential backoff
10//! - **Type-safe queries**: Fluent API for building queries
11//! - **Async-first**: Built on Tokio for high performance
12//!
13//! ## Quick Start
14//!
15//! ```no_run
16//! use amaters_sdk_rust::{AmateRSClient, ClientConfig};
17//! use amaters_core::{Key, CipherBlob};
18//!
19//! #[tokio::main]
20//! async fn main() -> anyhow::Result<()> {
21//! // Connect to server
22//! let client = AmateRSClient::connect("http://localhost:50051").await?;
23//!
24//! // Set a value
25//! let key = Key::from_str("user:123");
26//! let value = CipherBlob::new(vec![1, 2, 3, 4]);
27//! client.set("users", &key, &value).await?;
28//!
29//! // Get a value
30//! if let Some(retrieved) = client.get("users", &key).await? {
31//! println!("Retrieved {} bytes", retrieved.len());
32//! }
33//!
34//! // Delete a key
35//! client.delete("users", &key).await?;
36//!
37//! Ok(())
38//! }
39//! ```
40//!
41//! ## Connection Configuration
42//!
43//! ```no_run
44//! use amaters_sdk_rust::{AmateRSClient, ClientConfig, RetryConfig};
45//! use std::time::Duration;
46//!
47//! # async fn example() -> anyhow::Result<()> {
48//! let config = ClientConfig::new("http://localhost:50051")
49//! .with_connect_timeout(Duration::from_secs(5))
50//! .with_request_timeout(Duration::from_secs(30))
51//! .with_max_connections(20)
52//! .with_retry_config(
53//! RetryConfig::new()
54//! .with_max_retries(5)
55//! .with_initial_backoff(Duration::from_millis(100))
56//! );
57//!
58//! let client = AmateRSClient::connect_with_config(config).await?;
59//! # Ok(())
60//! # }
61//! ```
62//!
63//! ## Query Builder
64//!
65//! ```no_run
66//! use amaters_sdk_rust::query;
67//! use amaters_core::{Key, CipherBlob, col, Predicate};
68//!
69//! # async fn example() {
70//! // Simple query
71//! let q = query("users").get(Key::from_str("user:123"));
72//!
73//! // Filter with predicates
74//! let q = query("users")
75//! .where_clause()
76//! .eq(col("status"), CipherBlob::new(vec![1]))
77//! .and(Predicate::Gt(col("age"), CipherBlob::new(vec![18])))
78//! .build();
79//!
80//! // Range query
81//! let q = query("data").range(
82//! Key::from_str("start"),
83//! Key::from_str("end")
84//! );
85//! # }
86//! ```
87//!
88//! ## FHE Integration
89//!
90//! The SDK supports client-side encryption with FHE (feature-gated):
91//!
92//! ```no_run
93//! use amaters_sdk_rust::{AmateRSClient, FheEncryptor};
94//!
95//! # async fn example() -> anyhow::Result<()> {
96//! // Create encryptor (stub implementation for now)
97//! let encryptor = FheEncryptor::new()?;
98//!
99//! // Connect with encryptor
100//! let client = AmateRSClient::connect("http://localhost:50051")
101//! .await?
102//! .with_encryptor(encryptor);
103//! # Ok(())
104//! # }
105//! ```
106//!
107//! ## Feature Flags
108//!
109//! - `fhe` - Enable full FHE support with TFHE
110//! - `serialization` - Enable key serialization with oxicode
111
112#![allow(dead_code)]
113#![allow(clippy::type_complexity)]
114
115pub mod cache;
116pub mod client;
117pub mod config;
118pub mod connection;
119pub mod connection_manager;
120pub mod error;
121pub mod fhe;
122pub mod query;
123pub mod streaming;
124
125// Re-export main types
126pub use cache::{CacheStats, InvalidationPolicy, QueryCache, QueryCacheConfig};
127pub use client::{
128 AmateRSClient, PaginatedQueryBuilder, PaginatedResult, PaginationConfig, QueryResult,
129 ServerInfo, SortConfig, SortField, SortOrder,
130};
131pub use config::{ClientConfig, RetryConfig, TlsConfig};
132pub use connection_manager::{
133 AtomicConnectionState, ConnectionHealth, ConnectionManager, ConnectionState, EndpointList,
134 ReconnectConfig as ConnectionReconnectConfig,
135};
136pub use error::{Result, SdkError};
137pub use fhe::{FheEncryptor, FheKeys};
138pub use query::{FilterBuilder, FluentQueryBuilder, PredicateBuilder, query};
139pub use streaming::{QueryStream, Row, RowSender, StreamConfig, spawn_stub_producer};
140
141// Re-export core types for convenience
142pub use amaters_core::{CipherBlob, ColumnRef, Key, Predicate, Query, Update, col};
143
144/// Library version
145pub const VERSION: &str = env!("CARGO_PKG_VERSION");
146
147#[cfg(test)]
148mod tests {
149 use super::*;
150
151 #[test]
152 #[allow(clippy::len_zero)]
153 fn test_version() {
154 // Just verify it's defined - no need to check is_empty since it's a const
155 assert!(VERSION.len() > 0);
156 }
157
158 #[test]
159 fn test_exports() {
160 // Test that main types are accessible
161 let _config = ClientConfig::default();
162 let _retry = RetryConfig::default();
163 }
164}