#![forbid(unsafe_code, clippy::unwrap_used)]
#![allow(clippy::needless_return)]
#![warn(clippy::await_holding_lock, clippy::inefficient_to_string)]
use serde::{Deserialize, Serialize};
use trailbase_sqlvalue::SqlValue;
use ts_rs::TS;
pub mod manifest;
#[derive(Clone, Debug, Deserialize, Serialize, TS)]
#[ts(export)]
pub struct SqliteRequest {
pub query: String,
pub params: Vec<SqlValue>,
}
#[derive(Clone, Debug, Deserialize, Serialize, TS)]
#[ts(export)]
pub enum SqliteResponse {
Query { rows: Vec<Vec<SqlValue>> },
Execute { rows_affected: usize },
Error(String),
TxBegin,
TxCommit,
TxRollback,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum PrefsRequest {
Get { key: String },
Set { key: String, value: Option<String> },
}
#[derive(Clone, Debug, Deserialize, Serialize, TS)]
pub enum PrefsResponse {
Ok,
Value(Option<String>),
Error(String),
}
#[derive(Clone, Debug, Deserialize, Serialize, TS)]
#[ts(export)]
pub struct HttpContext {
pub kind: HttpContextKind,
pub registered_path: String,
pub path_params: Vec<(String, String)>,
pub user: Option<HttpContextUser>,
}
#[derive(Clone, Debug, Deserialize, Serialize, TS)]
pub enum HttpContextKind {
Http,
Job,
#[serde(other)]
Unknown,
}
#[derive(Clone, Debug, Deserialize, Serialize, TS)]
pub struct HttpContextUser {
pub id: String,
pub email: Option<String>,
pub username: Option<String>,
pub csrf_token: String,
}
#[inline]
pub fn component_path_to_name(path: &std::path::Path) -> Result<String, String> {
return Ok(
path
.file_stem()
.and_then(|s| s.to_str())
.ok_or_else(|| format!("failed to get component name from '{path:?}'"))?
.to_string(),
);
}