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 trailbase_sqlvalue::SqlValue;
7use ts_rs::TS;
8
9#[derive(Clone, Debug, Deserialize, Serialize, TS)]
10#[ts(export)]
11pub struct SqliteRequest {
12  pub query: String,
13  pub params: Vec<SqlValue>,
14}
15
16#[derive(Clone, Debug, Deserialize, Serialize, TS)]
17#[ts(export)]
18pub enum SqliteResponse {
19  Query { rows: Vec<Vec<SqlValue>> },
20  Execute { rows_affected: usize },
21  Error(String),
22  TxBegin,
23  TxCommit,
24  TxRollback,
25}
26
27/// Used to pass extra information from host to guest via an HTTP request header "__context".
28#[derive(Clone, Debug, Deserialize, Serialize, TS)]
29#[ts(export)]
30pub struct HttpContext {
31  pub kind: HttpContextKind,
32  pub registered_path: String,
33  pub path_params: Vec<(String, String)>,
34  pub user: Option<HttpContextUser>,
35}
36
37#[derive(Clone, Debug, Deserialize, Serialize, TS)]
38pub enum HttpContextKind {
39  /// An incoming http request.
40  Http,
41  /// An incoming job request.
42  Job,
43}
44
45#[derive(Clone, Debug, Deserialize, Serialize, TS)]
46pub struct HttpContextUser {
47  /// Url-safe Base64 encoded id of the current user.
48  pub id: String,
49  /// E-mail of the current user.
50  pub email: String,
51  /// The "expected" CSRF token as included in the auth token claims [User] was constructed from.
52  pub csrf_token: String,
53}