trailbase_wasm_common/
lib.rs

1#![forbid(unsafe_code, clippy::unwrap_used)]
2#![allow(clippy::needless_return)]
3#![warn(clippy::await_holding_lock, clippy::inefficient_to_string)]
4
5use serde::{Deserialize, Serialize};
6use ts_rs::TS;
7
8#[derive(Clone, Debug, Deserialize, Serialize, TS)]
9#[ts(export)]
10pub struct SqliteRequest {
11  pub query: String,
12  pub params: Vec<serde_json::Value>,
13}
14
15#[derive(Clone, Debug, Deserialize, Serialize, TS)]
16#[ts(export)]
17pub enum SqliteResponse {
18  Query { rows: Vec<Vec<serde_json::Value>> },
19  Execute { rows_affected: usize },
20  Error(String),
21  TxBegin,
22  TxCommit,
23  TxRollback,
24}
25
26#[derive(Clone, Debug, Deserialize, Serialize, TS)]
27pub enum HttpContextKind {
28  /// An incoming http request.
29  Http,
30  /// An incoming job request.
31  Job,
32}
33
34#[derive(Clone, Debug, Deserialize, Serialize, TS)]
35pub struct HttpContextUser {
36  /// Url-safe Base64 encoded id of the current user.
37  pub id: String,
38  /// E-mail of the current user.
39  pub email: String,
40  /// The "expected" CSRF token as included in the auth token claims [User] was constructed from.
41  pub csrf_token: String,
42}
43
44#[derive(Clone, Debug, Deserialize, Serialize, TS)]
45#[ts(export)]
46pub struct HttpContext {
47  pub kind: HttpContextKind,
48  pub registered_path: String,
49  pub path_params: Vec<(String, String)>,
50  pub user: Option<HttpContextUser>,
51}