mesc/types/
queries.rs

1use crate::{ChainId, MescError, TryIntoChainId};
2
3/// Multi Endpoint Query
4#[derive(Debug, Default, Clone)]
5pub struct MultiEndpointQuery {
6    /// chain_id
7    pub chain_id: Option<ChainId>,
8    /// name_contains
9    pub name_contains: Option<String>,
10    /// url_contains
11    pub url_contains: Option<String>,
12}
13
14/// builder for MultiEndpointQuery
15impl MultiEndpointQuery {
16    /// new MultiEndpointQuery
17    pub fn new() -> Self {
18        Self::default()
19    }
20
21    /// set chain_id
22    pub fn chain_id<T: TryIntoChainId>(mut self, chain_id: T) -> Result<Self, MescError> {
23        self.chain_id = Some(chain_id.try_into_chain_id()?);
24        Ok(self)
25    }
26
27    /// set name
28    pub fn name<T: AsRef<str>>(mut self, query: T) -> Result<Self, MescError> {
29        self.name_contains = Some(query.as_ref().to_string());
30        Ok(self)
31    }
32
33    /// set url
34    pub fn url<T: AsRef<str>>(mut self, query: T) -> Result<Self, MescError> {
35        self.url_contains = Some(query.as_ref().to_string());
36        Ok(self)
37    }
38}
39
40//
41// // individual queries
42//
43
44/// EndpointQuery
45#[derive(Debug, Clone)]
46pub struct EndpointQuery {
47    /// query_type
48    pub query_type: EndpointQueryType,
49    /// fields
50    pub fields: EndpointQueryFields,
51}
52
53/// EndpointQueryType
54#[derive(Debug, Clone)]
55pub enum EndpointQueryType {
56    /// DefeaultEndpoint
57    DefaultEndpoint,
58    /// EndpointByName
59    EndpointByName,
60    /// EndpointByNetwork
61    EndpointByNetwork,
62    /// UserInput
63    UserInput,
64}
65
66/// EndpointQueryFields
67#[derive(Debug, Clone)]
68pub enum EndpointQueryFields {
69    /// DefaultEndpoint
70    DefaultEndpoint(DefaultEndpointQuery),
71    /// EndpointName
72    EndpointName(EndpointNameQuery),
73    /// EndpointNetwork
74    EndpointNetwork(EndpointNetworkQuery),
75    /// UserInput
76    UserInput(UserInputQuery),
77}
78
79/// DefaultEndpointQuery
80#[derive(Debug, Clone)]
81pub struct DefaultEndpointQuery {
82    /// profile
83    pub profile: Option<String>,
84}
85
86/// EndpointNameQuery
87#[derive(Debug, Clone)]
88pub struct EndpointNameQuery {
89    /// name
90    pub name: String,
91}
92
93/// EndpointNetworkQuery
94#[derive(Debug, Clone)]
95pub struct EndpointNetworkQuery {
96    /// profile
97    pub profile: Option<String>,
98    /// chain_id
99    pub chain_id: String,
100}
101
102/// UserInputQuery
103#[derive(Debug, Clone)]
104pub struct UserInputQuery {
105    /// profile
106    pub profile: Option<String>,
107    /// user_input
108    pub user_input: String,
109}
110
111//
112// // global metadata
113//
114
115/// GlobalMetadataQuery
116#[derive(Debug, Clone)]
117pub struct GlobalMetadataQuery {
118    /// profile
119    pub profile: Option<String>,
120    /// path
121    pub path: Option<Vec<String>>,
122}
123
124//
125// // general MESC queries
126//
127
128/// MescQuery
129#[derive(Debug, Clone)]
130pub struct MescQuery {
131    /// query_type
132    pub query_type: MescQueryType,
133    /// field
134    pub fields: MescQueryFields,
135}
136
137/// MescQueryType
138#[derive(Debug, Clone)]
139pub enum MescQueryType {
140    /// DefaultEndpoint
141    DefaultEndpoint,
142    /// EndpointByName
143    EndpointByName,
144    /// EndpointByNetwork
145    EndpointByNetwork,
146    /// UserInput
147    UserInput,
148    /// MultiEndpoint
149    MultiEndpoint,
150    /// GlobalMetadata
151    GlobalMetadata,
152}
153
154/// MescQueryFields
155#[derive(Debug, Clone)]
156pub enum MescQueryFields {
157    /// DefaultEndpoint
158    DefaultEndpoint(DefaultEndpointQuery),
159    /// EndpointName
160    EndpointName(EndpointNameQuery),
161    /// EndpointNetwork
162    EndpointNetwork(EndpointNetworkQuery),
163    /// UserInput
164    UserInput(UserInputQuery),
165    /// MultiEndpoint
166    MultiEndpoint(MultiEndpointQuery),
167    /// GlobalMetadata
168    GlobalMetadata(GlobalMetadataQuery),
169}