supabase_client_rs/
traits.rs1use crate::error::Result;
8use serde::{Serialize, de::DeserializeOwned};
9
10pub use async_trait::async_trait;
12
13#[async_trait]
18pub trait AuthProvider: Send + Sync {
19 type User: DeserializeOwned + Send;
21
22 type Session: DeserializeOwned + Send;
24
25 async fn sign_up_with_email(&self, email: &str, password: &str) -> Result<Self::Session>;
27
28 async fn sign_in_with_email(&self, email: &str, password: &str) -> Result<Self::Session>;
30
31 async fn sign_out(&self) -> Result<()>;
33
34 async fn get_session(&self) -> Result<Option<Self::Session>>;
36
37 async fn get_user(&self) -> Result<Option<Self::User>>;
39
40 async fn refresh_session(&self) -> Result<Self::Session>;
42}
43
44#[async_trait]
48pub trait StorageProvider: Send + Sync {
49 async fn upload(
51 &self,
52 bucket: &str,
53 path: &str,
54 data: Vec<u8>,
55 content_type: Option<&str>,
56 ) -> Result<String>;
57
58 async fn download(&self, bucket: &str, path: &str) -> Result<Vec<u8>>;
60
61 async fn remove(&self, bucket: &str, paths: &[&str]) -> Result<()>;
63
64 async fn list(&self, bucket: &str, path: Option<&str>) -> Result<Vec<StorageObject>>;
66
67 fn get_public_url(&self, bucket: &str, path: &str) -> String;
69
70 async fn create_signed_url(&self, bucket: &str, path: &str, expires_in: u64) -> Result<String>;
72}
73
74#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
76pub struct StorageObject {
77 pub name: String,
79 pub id: Option<String>,
81 pub updated_at: Option<String>,
83 pub created_at: Option<String>,
85 pub last_accessed_at: Option<String>,
87 pub metadata: Option<serde_json::Value>,
89}
90
91#[async_trait]
93pub trait FunctionsProvider: Send + Sync {
94 async fn invoke<T, R>(&self, function_name: &str, body: Option<T>) -> Result<R>
96 where
97 T: Serialize + Send + Sync,
98 R: DeserializeOwned;
99
100 async fn invoke_raw<T>(&self, function_name: &str, body: Option<T>) -> Result<Vec<u8>>
102 where
103 T: Serialize + Send + Sync;
104}