pub const MAX_VALUE_BYTES: usize = 24_576;
pub const MAX_KEY_BYTES: usize = 512;
pub fn validate_key(key: &str) -> crate::error::Result<()> {
use crate::error::ErrorData;
use alien_error::AlienError;
if key.is_empty() {
return Err(AlienError::new(ErrorData::InvalidInput {
operation_context: "KV key validation".to_string(),
details: "Key cannot be empty".to_string(),
field_name: Some("key".to_string()),
}));
}
if key.len() > MAX_KEY_BYTES {
return Err(AlienError::new(ErrorData::InvalidInput {
operation_context: "KV key validation".to_string(),
details: format!("Key exceeds {} bytes", MAX_KEY_BYTES),
field_name: Some("key".to_string()),
}));
}
if !key.chars().all(|c| {
matches!(c, 'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' | ':' | '.') && !c.is_control()
}) {
return Err(AlienError::new(ErrorData::InvalidInput {
operation_context: "KV key validation".to_string(),
details: "Key contains invalid characters. Allowed: a-z A-Z 0-9 - _ : . (no spaces, slashes, or special characters)".to_string(),
field_name: Some("key".to_string()),
}));
}
Ok(())
}
pub fn validate_value(value: &[u8]) -> crate::error::Result<()> {
use crate::error::ErrorData;
use alien_error::AlienError;
if value.len() > MAX_VALUE_BYTES {
return Err(AlienError::new(ErrorData::InvalidInput {
operation_context: "KV value validation".to_string(),
details: format!("Value exceeds {} bytes", MAX_VALUE_BYTES),
field_name: Some("value".to_string()),
}));
}
Ok(())
}
#[cfg(feature = "aws")]
pub mod aws_dynamodb;
#[cfg(feature = "azure")]
pub mod azure_table_storage;
#[cfg(feature = "gcp")]
pub mod gcp_firestore;
#[cfg(feature = "grpc")]
pub mod grpc;
#[cfg(feature = "local")]
pub mod local;
#[cfg(feature = "aws")]
pub use aws_dynamodb::AwsDynamodbKv;
#[cfg(feature = "azure")]
pub use azure_table_storage::AzureTableStorageKv;
#[cfg(feature = "gcp")]
pub use gcp_firestore::GcpFirestoreKv;
#[cfg(feature = "grpc")]
pub use grpc::GrpcKv;
#[cfg(feature = "local")]
pub use local::LocalKv;