-
-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,381 additions
and
1,372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,79 @@ | ||
use client_api::error::ErrorCode; | ||
use serde::{Deserialize, Serialize}; | ||
use tsify::Tsify; | ||
use wasm_bindgen::JsValue; | ||
use client_api::error::{ErrorCode}; | ||
|
||
#[derive(Tsify, Serialize, Deserialize, Default, Debug)] | ||
#[tsify(into_wasm_abi, from_wasm_abi)] | ||
pub struct Configuration { | ||
pub compression_quality: u32, | ||
pub compression_buffer_size: usize, | ||
pub compression_quality: u32, | ||
pub compression_buffer_size: usize, | ||
} | ||
|
||
#[derive(Tsify, Serialize, Deserialize, Default, Debug)] | ||
#[tsify(into_wasm_abi, from_wasm_abi)] | ||
pub struct ClientAPIConfig { | ||
pub base_url: String, | ||
pub ws_addr: String, | ||
pub gotrue_url: String, | ||
pub device_id: String, | ||
pub configuration: Configuration, | ||
pub client_id: String, | ||
pub base_url: String, | ||
pub ws_addr: String, | ||
pub gotrue_url: String, | ||
pub device_id: String, | ||
pub configuration: Configuration, | ||
pub client_id: String, | ||
} | ||
|
||
#[derive(Tsify, Serialize, Deserialize, Default, Debug)] | ||
#[repr(i32)] | ||
pub enum ClientErrorCode { | ||
#[default] | ||
Ok = 0, | ||
Unhandled = -1, | ||
RecordNotFound = -2, | ||
RecordAlreadyExists = -3, | ||
InvalidEmail = 1001, | ||
InvalidPassword = 1002, | ||
OAuthError = 1003, | ||
MissingPayload = 1004, | ||
DBError = 1005, | ||
OpenError = 1006, | ||
InvalidUrl = 1007, | ||
InvalidRequest = 1008, | ||
InvalidOAuthProvider = 1009, | ||
NotLoggedIn = 1011, | ||
NotEnoughPermissions = 1012, | ||
#[default] | ||
Ok = 0, | ||
Unhandled = -1, | ||
RecordNotFound = -2, | ||
RecordAlreadyExists = -3, | ||
InvalidEmail = 1001, | ||
InvalidPassword = 1002, | ||
OAuthError = 1003, | ||
MissingPayload = 1004, | ||
DBError = 1005, | ||
OpenError = 1006, | ||
InvalidUrl = 1007, | ||
InvalidRequest = 1008, | ||
InvalidOAuthProvider = 1009, | ||
NotLoggedIn = 1011, | ||
NotEnoughPermissions = 1012, | ||
} | ||
|
||
impl From<ErrorCode> for ClientErrorCode { | ||
fn from(value: ErrorCode) -> Self { | ||
match value { | ||
ErrorCode::Ok => Self::Ok, | ||
ErrorCode::Unhandled => Self::Unhandled, | ||
ErrorCode::RecordNotFound => Self::RecordNotFound, | ||
ErrorCode::RecordAlreadyExists => Self::RecordAlreadyExists, | ||
ErrorCode::InvalidEmail => Self::InvalidEmail, | ||
ErrorCode::InvalidPassword => Self::InvalidPassword, | ||
ErrorCode::OAuthError => Self::OAuthError, | ||
ErrorCode::MissingPayload => Self::MissingPayload, | ||
ErrorCode::DBError => Self::DBError, | ||
ErrorCode::OpenError => Self::OpenError, | ||
ErrorCode::InvalidUrl => Self::InvalidUrl, | ||
ErrorCode::InvalidRequest => Self::InvalidRequest, | ||
ErrorCode::InvalidOAuthProvider => Self::InvalidOAuthProvider, | ||
ErrorCode::NotLoggedIn => Self::NotLoggedIn, | ||
ErrorCode::NotEnoughPermissions => Self::NotEnoughPermissions, | ||
_ => Self::Unhandled, | ||
} | ||
} | ||
fn from(value: ErrorCode) -> Self { | ||
match value { | ||
ErrorCode::Ok => Self::Ok, | ||
ErrorCode::Unhandled => Self::Unhandled, | ||
ErrorCode::RecordNotFound => Self::RecordNotFound, | ||
ErrorCode::RecordAlreadyExists => Self::RecordAlreadyExists, | ||
ErrorCode::InvalidEmail => Self::InvalidEmail, | ||
ErrorCode::InvalidPassword => Self::InvalidPassword, | ||
ErrorCode::OAuthError => Self::OAuthError, | ||
ErrorCode::MissingPayload => Self::MissingPayload, | ||
ErrorCode::DBError => Self::DBError, | ||
ErrorCode::OpenError => Self::OpenError, | ||
ErrorCode::InvalidUrl => Self::InvalidUrl, | ||
ErrorCode::InvalidRequest => Self::InvalidRequest, | ||
ErrorCode::InvalidOAuthProvider => Self::InvalidOAuthProvider, | ||
ErrorCode::NotLoggedIn => Self::NotLoggedIn, | ||
ErrorCode::NotEnoughPermissions => Self::NotEnoughPermissions, | ||
_ => Self::Unhandled, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Tsify, Serialize, Deserialize, Default, Debug)] | ||
#[tsify(into_wasm_abi, from_wasm_abi)] | ||
pub struct ClientResponse { | ||
pub code: ClientErrorCode, | ||
pub message: String, | ||
pub code: ClientErrorCode, | ||
pub message: String, | ||
} | ||
|
||
impl From<ClientResponse> for JsValue { | ||
fn from(value: ClientResponse) -> Self { | ||
JsValue::from_str(&serde_json::to_string(&value).unwrap()) | ||
} | ||
} | ||
fn from(value: ClientResponse) -> Self { | ||
JsValue::from_str(&serde_json::to_string(&value).unwrap()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,37 @@ | ||
use crate::wasm_trace; | ||
|
||
pub fn set_panic_hook() { | ||
#[cfg(debug_assertions)] | ||
console_error_panic_hook::set_once(); | ||
#[cfg(debug_assertions)] | ||
console_error_panic_hook::set_once(); | ||
} | ||
|
||
|
||
pub struct WASMLogger; | ||
|
||
impl log::Log for WASMLogger { | ||
fn enabled(&self, metadata: &log::Metadata) -> bool { | ||
metadata.level() <= log::Level::Debug | ||
} | ||
|
||
fn log(&self, record: &log::Record) { | ||
let level = record.level(); | ||
let target = record.target(); | ||
let args = format!("{}", record.args()); | ||
wasm_trace(&level.to_string(), target, &args); | ||
} | ||
|
||
fn flush(&self) {} | ||
fn enabled(&self, metadata: &log::Metadata) -> bool { | ||
metadata.level() <= log::Level::Debug | ||
} | ||
|
||
fn log(&self, record: &log::Record) { | ||
let level = record.level(); | ||
let target = record.target(); | ||
let args = format!("{}", record.args()); | ||
wasm_trace(&level.to_string(), target, &args); | ||
} | ||
|
||
fn flush(&self) {} | ||
} | ||
|
||
impl Default for WASMLogger { | ||
fn default() -> Self { | ||
Self | ||
} | ||
fn default() -> Self { | ||
Self | ||
} | ||
} | ||
|
||
static WASM_LOGGER: WASMLogger = WASMLogger; | ||
|
||
pub fn init_logger() { | ||
set_panic_hook(); | ||
log::set_logger(&WASM_LOGGER).unwrap(); | ||
log::set_max_level(log::LevelFilter::Debug); | ||
set_panic_hook(); | ||
log::set_logger(&WASM_LOGGER).unwrap(); | ||
log::set_max_level(log::LevelFilter::Debug); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.