1use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6use uuid::Uuid;
7
8#[derive(Debug, Clone)]
10pub struct SupabaseConfig {
11 pub url: String,
13 pub key: String,
15 pub http_config: HttpConfig,
17 pub auth_config: AuthConfig,
19 pub database_config: DatabaseConfig,
21 pub storage_config: StorageConfig,
23}
24
25#[derive(Debug, Clone)]
27pub struct HttpConfig {
28 pub timeout: u64,
30 pub connect_timeout: u64,
32 pub max_redirects: usize,
34 pub default_headers: HashMap<String, String>,
36}
37
38impl Default for HttpConfig {
39 fn default() -> Self {
40 Self {
41 timeout: 60,
42 connect_timeout: 10,
43 max_redirects: 10,
44 default_headers: HashMap::new(),
45 }
46 }
47}
48
49#[derive(Debug, Clone)]
51pub struct AuthConfig {
52 pub auto_refresh_token: bool,
54 pub refresh_threshold: u64,
56 pub persist_session: bool,
58 pub storage_key: String,
60}
61
62impl Default for AuthConfig {
63 fn default() -> Self {
64 Self {
65 auto_refresh_token: true,
66 refresh_threshold: 300, persist_session: true,
68 storage_key: "supabase.auth.token".to_string(),
69 }
70 }
71}
72
73#[derive(Debug, Clone)]
75pub struct DatabaseConfig {
76 pub schema: String,
78 pub max_retries: u32,
80 pub retry_delay: u64,
82}
83
84impl Default for DatabaseConfig {
85 fn default() -> Self {
86 Self {
87 schema: "public".to_string(),
88 max_retries: 3,
89 retry_delay: 1000,
90 }
91 }
92}
93
94#[derive(Debug, Clone)]
96pub struct StorageConfig {
97 pub default_bucket: Option<String>,
99 pub upload_timeout: u64,
101 pub max_file_size: u64,
103}
104
105impl Default for StorageConfig {
106 fn default() -> Self {
107 Self {
108 default_bucket: None,
109 upload_timeout: 300, max_file_size: 50 * 1024 * 1024, }
112 }
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize)]
117pub struct SupabaseResponse<T> {
118 pub data: Option<T>,
119 pub error: Option<SupabaseError>,
120}
121
122#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct SupabaseError {
125 pub message: String,
126 pub details: Option<String>,
127 pub hint: Option<String>,
128 pub code: Option<String>,
129}
130
131#[derive(Debug, Clone, Serialize, Deserialize)]
133pub struct Pagination {
134 pub page: u32,
136 pub per_page: u32,
138 pub total: Option<u64>,
140 pub has_more: Option<bool>,
142}
143
144#[derive(Debug, Clone, Serialize, Deserialize)]
146pub enum FilterOperator {
147 #[serde(rename = "eq")]
148 Equal,
149 #[serde(rename = "neq")]
150 NotEqual,
151 #[serde(rename = "gt")]
152 GreaterThan,
153 #[serde(rename = "gte")]
154 GreaterThanOrEqual,
155 #[serde(rename = "lt")]
156 LessThan,
157 #[serde(rename = "lte")]
158 LessThanOrEqual,
159 #[serde(rename = "like")]
160 Like,
161 #[serde(rename = "ilike")]
162 ILike,
163 #[serde(rename = "is")]
164 Is,
165 #[serde(rename = "in")]
166 In,
167 #[serde(rename = "cs")]
168 Contains,
169 #[serde(rename = "cd")]
170 ContainedBy,
171 #[serde(rename = "sl")]
172 StrictlyLeft,
173 #[serde(rename = "sr")]
174 StrictlyRight,
175 #[serde(rename = "nxr")]
176 NotExtendToRight,
177 #[serde(rename = "nxl")]
178 NotExtendToLeft,
179 #[serde(rename = "adj")]
180 Adjacent,
181}
182
183#[derive(Debug, Clone, Serialize, Deserialize)]
185pub enum OrderDirection {
186 #[serde(rename = "asc")]
187 Ascending,
188 #[serde(rename = "desc")]
189 Descending,
190}
191
192#[derive(Debug, Clone, Copy)]
194pub enum HttpMethod {
195 Get,
196 Post,
197 Put,
198 Patch,
199 Delete,
200 Head,
201 Options,
202}
203
204impl HttpMethod {
205 pub fn as_str(&self) -> &'static str {
206 match self {
207 HttpMethod::Get => "GET",
208 HttpMethod::Post => "POST",
209 HttpMethod::Put => "PUT",
210 HttpMethod::Patch => "PATCH",
211 HttpMethod::Delete => "DELETE",
212 HttpMethod::Head => "HEAD",
213 HttpMethod::Options => "OPTIONS",
214 }
215 }
216}
217
218pub type Timestamp = DateTime<Utc>;
220
221pub type Id = Uuid;
223
224pub type JsonValue = serde_json::Value;
226
227pub type Headers = HashMap<String, String>;
229
230pub type QueryParams = HashMap<String, String>;