teo_runtime/config/
client.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use serde::Serialize;

#[derive(Debug, Serialize, Copy, Clone)]
pub enum TypeScriptHTTPProvider {
    Fetch,
    Taro,
    WeChat,
}

impl TypeScriptHTTPProvider {
    pub fn is_fetch(&self) -> bool {
        match self {
            Self::Fetch => true,
            _ => false,
        }
    }

    pub fn is_taro(&self) -> bool {
        match self {
            Self::Taro => true,
            _ => false,
        }
    }

    pub fn is_wechat(&self) -> bool {
        match self {
            Self::WeChat => true,
            _ => false,
        }
    }
}

#[derive(Debug, Serialize, Copy, Clone)]
pub enum ClientLanguage {
    TypeScript(TypeScriptHTTPProvider),
    Swift,
    Kotlin,
    CSharp,
    Dart,
}

impl ClientLanguage {

    pub fn ts_http_provider(&self) -> Option<&TypeScriptHTTPProvider> {
        match self {
            ClientLanguage::TypeScript(v) => Some(v),
            _ => None,
        }
    }
}

#[derive(Debug, Serialize, Clone)]
pub enum ClientHost {
    String(String),
    Inject(String),
}

impl ClientHost {
    pub fn to_host_string(&self) -> String {
        match self {
            Self::Inject(v) => v.clone(),
            Self::String(s) => {
                let appended = if s.ends_with("/") {
                    s.clone()
                } else {
                    s.to_owned() + "/"
                };
                format!("\"{appended}\"")
            }
        }
    }
}

#[derive(Debug, Serialize, Clone)]
pub struct Client {
    pub provider: ClientLanguage,
    pub dest: String,
    pub package: bool,
    pub host: ClientHost,
    #[serde(rename = "objectName")]
    pub object_name: String,
    #[serde(rename = "gitCommit")]
    pub git_commit: bool,
}