supabase-client-storage 0.2.2

Storage HTTP client for supabase-client
Documentation
//! Supabase Storage HTTP client.
//!
//! This crate provides an HTTP client for the Supabase Storage API.
//! It communicates with Storage REST endpoints at `/storage/v1/...`.
//!
//! # Usage
//!
//! ```ignore
//! use supabase_client_sdk::prelude::*;
//!
//! let client = SupabaseClient::new(config).await?;
//! let storage = client.storage()?;
//!
//! // Bucket operations
//! let buckets = storage.list_buckets().await?;
//! storage.create_bucket("photos", BucketOptions::new().public(true)).await?;
//!
//! // File operations
//! let file_api = storage.from("photos");
//! file_api.upload("photo.png", data, FileOptions::new().content_type("image/png")).await?;
//! let bytes = file_api.download("photo.png").await?;
//! ```

pub mod bucket_api;
pub mod client;
pub mod error;
pub mod types;

// Re-exports for convenient access
pub use bucket_api::StorageBucketApi;
pub use client::StorageClient;
pub use error::{StorageApiErrorResponse, StorageError};
pub use types::*;

use supabase_client_core::SupabaseClient;

/// Extension trait to create a [`StorageClient`] from a [`SupabaseClient`].
///
/// # Example
/// ```ignore
/// use supabase_client_sdk::prelude::*;
/// use supabase_client_storage::SupabaseClientStorageExt;
///
/// let client = SupabaseClient::new(config).await?;
/// let storage = client.storage()?;
/// let buckets = storage.list_buckets().await?;
/// ```
pub trait SupabaseClientStorageExt {
    /// Create a [`StorageClient`] from the client's configuration.
    ///
    /// Requires `supabase_url` and `supabase_key` to be set in the config.
    fn storage(&self) -> Result<StorageClient, StorageError>;
}

impl SupabaseClientStorageExt for SupabaseClient {
    fn storage(&self) -> Result<StorageClient, StorageError> {
        StorageClient::new(self.supabase_url(), self.api_key())
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use supabase_client_core::config::SupabaseConfig;

    #[test]
    fn test_storage_extension_trait() {
        let config = SupabaseConfig::new("http://localhost:54321", "test-key");
        let client = SupabaseClient::new(config).unwrap();
        let storage = client.storage();
        assert!(storage.is_ok());
        let storage = storage.unwrap();
        assert_eq!(storage.base_url().path(), "/storage/v1");
    }
}