teo_runtime/config/
client.rs

1use serde::Serialize;
2
3#[derive(Debug, Serialize, Copy, Clone)]
4pub enum TypeScriptHTTPProvider {
5    Fetch,
6    Taro,
7    WeChat,
8}
9
10impl TypeScriptHTTPProvider {
11    pub fn is_fetch(&self) -> bool {
12        match self {
13            Self::Fetch => true,
14            _ => false,
15        }
16    }
17
18    pub fn is_taro(&self) -> bool {
19        match self {
20            Self::Taro => true,
21            _ => false,
22        }
23    }
24
25    pub fn is_wechat(&self) -> bool {
26        match self {
27            Self::WeChat => true,
28            _ => false,
29        }
30    }
31}
32
33#[derive(Debug, Serialize, Copy, Clone)]
34pub enum ClientLanguage {
35    TypeScript(TypeScriptHTTPProvider),
36    Swift,
37    Kotlin,
38    CSharp,
39    Dart,
40}
41
42impl ClientLanguage {
43
44    pub fn ts_http_provider(&self) -> Option<&TypeScriptHTTPProvider> {
45        match self {
46            ClientLanguage::TypeScript(v) => Some(v),
47            _ => None,
48        }
49    }
50}
51
52#[derive(Debug, Serialize, Clone)]
53pub enum ClientHost {
54    String(String),
55    Inject(String),
56}
57
58impl ClientHost {
59    pub fn to_host_string(&self) -> String {
60        match self {
61            Self::Inject(v) => v.clone(),
62            Self::String(s) => {
63                let appended = if s.ends_with("/") {
64                    s.clone()
65                } else {
66                    s.to_owned() + "/"
67                };
68                format!("\"{appended}\"")
69            }
70        }
71    }
72}
73
74#[derive(Debug, Serialize, Clone)]
75pub struct Client {
76    pub provider: ClientLanguage,
77    pub dest: String,
78    pub package: bool,
79    pub host: ClientHost,
80    #[serde(rename = "objectName")]
81    pub object_name: String,
82    #[serde(rename = "gitCommit")]
83    pub git_commit: bool,
84}
85
86