pixeluvw_supabase 0.1.0

A production-ready, high-performance Supabase SDK for Rust with middleware, retry logic, and Arc<Inner> architecture
Documentation
//! # pixeluvw_supabase
//!
//! **A production-ready, high-performance Rust SDK for [Supabase](https://supabase.com).**
//!
//! Designed for reliability and improved developer experience, this crate provides a strongly-typed, fluent interface for interacting with the entire Supabase stack (Database, Auth, Realtime, Storage, and Edge Functions).
//!
//! > **Note:** This SDK is currently in Beta. APIs are stable but may evolve.
//!
//! ## ✨ Features
//!
//! - **🚀 Database**: Full PostgREST support with a fluent query builder, 25+ filters, and strong typing.
//! - **🔮 Schema Introspection**: Unique capability to fetch remote schema metadata at runtime and generate Rust structs.
//! - **🔐 Auth**: Complete authentication suite including Email/Password, OAuth, OTP, MFA, and Admin API.
//! - **⚡ Realtime**: Robust WebSocket client for listening to database changes (INSERT, UPDATE, DELETE), presence, and broadcast.
//! - **📦 Storage**: Simple API for file uploads, downloads, and signed URL generation.
//! - **serverless Functions**: Invoke Edge Functions seamlessly.
//! - **🛡️ Enterprise Ready**: Built-in middleware support, automatic retries with exponential backoff, and robust error handling.
//!
//! ## 🚀 Quick Start
//!
//! ### A. Setup Environment
//!
//! Create a `.env` file (ensure it's in your `.gitignore`):
//!
//! ```env
//! SUPABASE_URL=https://your-project.supabase.co
//! SUPABASE_KEY=your-anon-key
//! ```
//!
//! ### B. Basic Usage
//!
//! ```rust,no_run
//! use pixeluvw_supabase::{supabase, SupabaseClient};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     dotenv::dotenv().ok();
//!
//!     // Initialize the client (automatically loads from env)
//!     let client = supabase!()?;
//!
//!     // Perform a query
//!     let users: Vec<serde_json::Value> = client
//!         .from("users")
//!         .select("*")
//!         .eq("status", "active")
//!         .limit(5)
//!         .execute()
//!         .await?;
//!
//!     println!("Users: {:?}", users);
//!
//!     Ok(())
//! }
//! ```
//!
//! ## Security
//!
//! **Never hardcode credentials!** Use environment variables:
//!
//! - `SUPABASE_URL` — Your project URL
//! - `SUPABASE_KEY` — Your anon or service key
//! - Add `.env` to `.gitignore`
//!

#[cfg(feature = "auth")]
mod auth;
#[cfg(feature = "auth")]
mod auth_store;
mod builder;
mod client_builder;
mod config;
mod core;
mod error;
#[cfg(feature = "functions")]
mod functions;
#[cfg(feature = "realtime")]
mod realtime;
mod schema;
#[cfg(feature = "storage")]
mod storage;

// Core types
pub use builder::QueryBuilder;
pub use client_builder::SupabaseClientBuilder;
pub use config::ClientConfig;
pub use core::{Middleware, RequestContext, SupabaseClient};
pub use schema::{ColumnSchema, Schema, TableSchema};

// Auth types
#[cfg(feature = "auth")]
pub use auth::{AuthService, OtpType, Provider, SignUpResult};
#[cfg(feature = "auth")]
pub use auth_store::{FileSessionStore, MemorySessionStore, SessionStore};
#[cfg(feature = "auth")]
pub use core::{Session, User};

// Storage types
#[cfg(feature = "storage")]
pub use storage::{Bucket, StorageBucket, StorageClient, UploadedFile};

// Functions types
#[cfg(feature = "functions")]
pub use functions::FunctionsClient;

// Realtime types
#[cfg(feature = "realtime")]
pub use realtime::{
    ConnectionState, PostgresEvent, RealtimeChannel, RealtimeChannelBuilder, RealtimeClient,
    RealtimeMessage,
};

// Errors
pub use error::{Result, SupaError};

// Re-export specific modules if users need deep access (optional, kept private by default for cleaner API)
// If users need to import traits or specific internals, we can expose them here.
pub mod prelude {
    pub use super::{
        ClientConfig, Middleware, QueryBuilder, RequestContext, SupaError, SupabaseClient,
    };

    #[cfg(feature = "auth")]
    pub use super::{AuthService, OtpType, Provider, Session, User};

    #[cfg(feature = "storage")]
    pub use super::{Bucket, StorageBucket, StorageClient, UploadedFile};

    #[cfg(feature = "functions")]
    pub use super::FunctionsClient;

    #[cfg(feature = "realtime")]
    pub use super::{PostgresEvent, RealtimeChannelBuilder, RealtimeClient, RealtimeMessage};
}
/// Initialize a SupabaseClient with less boilerplate.
///
/// # Examples
///
/// ```rust,no_run
/// use pixeluvw_supabase::supabase;
///
/// // 1. Load from SUPABASE_URL and SUPABASE_KEY env vars
/// let client = supabase!();
///
/// // 2. Load from custom env vars
/// let client = supabase!("MY_URL_ENV", "MY_KEY_ENV");
///
/// // 3. Use direct values
/// let client = supabase!(url: "https://xyz.supabase.co", key: "public-anon-key");
/// ```
#[macro_export]
macro_rules! supabase {
    // Default: use standard environment variable names
    () => {{
        use $crate::SupabaseClient;

        let url = std::env::var("SUPABASE_URL")
            .map_err(|_| "SUPABASE_URL environment variable not set".to_string());
        let key = std::env::var("SUPABASE_KEY")
            .map_err(|_| "SUPABASE_KEY environment variable not set".to_string());

        match (url, key) {
            (Ok(u), Ok(k)) => SupabaseClient::new(u, k),
            (Err(e), _) => Err($crate::SupaError::ClientError { message: e }),
            (_, Err(e)) => Err($crate::SupaError::ClientError { message: e }),
        }
    }};

    // Custom environment variable names
    ($url_env:expr, $key_env:expr) => {{
        use $crate::SupabaseClient;

        let url = std::env::var($url_env)
            .map_err(|e| format!("{} environment variable not set: {}", $url_env, e));
        let key = std::env::var($key_env)
            .map_err(|e| format!("{} environment variable not set: {}", $key_env, e));

        match (url, key) {
            (Ok(u), Ok(k)) => SupabaseClient::new(u, k),
            (Err(e), _) => Err($crate::SupaError::ClientError { message: e }),
            (_, Err(e)) => Err($crate::SupaError::ClientError { message: e }),
        }
    }};

    // Direct URL and key values
    (url: $url:expr, key: $key:expr) => {{
        use $crate::SupabaseClient;
        SupabaseClient::new($url.to_string(), $key.to_string())
    }};
}