Skip to main content

nominal_api/conjure/objects/scout/internal/search/api/
search_query.rs

1use conjure_object::serde::{ser, de};
2use conjure_object::serde::ser::SerializeMap as SerializeMap_;
3use conjure_object::private::{UnionField_, UnionTypeField_};
4use std::fmt;
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub enum SearchQuery {
7    DateTimeField(super::DateTimeField),
8    StringField(super::StringField),
9    TimestampField(super::TimestampField),
10    LongField(super::LongField),
11    BooleanField(super::BooleanField),
12    /// Performs case insensitive exact match search on the title.
13    ExactMatch(String),
14    /// Requires the string values in the query to exactly match the set of string values in the resource.
15    /// To do a partial match, use an "and" on StringField queries.
16    StringArrayExactMatch(super::StringArrayField),
17    StringArrayLength(super::super::super::super::metadata::StringArrayLengthQuery),
18    SearchText(String),
19    Label(super::super::super::super::super::api::Label),
20    Property(super::super::super::super::super::api::Property),
21    /// Matches documents that have a property with this key, regardless of value.
22    PropertyKey(super::super::super::super::super::api::PropertyName),
23    And(Vec<super::SearchQuery>),
24    Or(Vec<super::SearchQuery>),
25    Not(Box<super::SearchQuery>),
26    Workspace(super::super::super::super::super::api::rids::WorkspaceRid),
27    CreatedAt(super::super::super::super::metadata::CreatedAtQuery),
28    /// Prefer to use archivedStatus field in IndexableDb#search
29    ArchivedStatus(super::super::super::super::super::api::ArchivedStatus),
30    IsPublished(bool),
31    /// An unknown variant.
32    Unknown(Unknown),
33}
34impl ser::Serialize for SearchQuery {
35    fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
36    where
37        S: ser::Serializer,
38    {
39        let mut map = s.serialize_map(Some(2))?;
40        match self {
41            SearchQuery::DateTimeField(value) => {
42                map.serialize_entry(&"type", &"dateTimeField")?;
43                map.serialize_entry(&"dateTimeField", value)?;
44            }
45            SearchQuery::StringField(value) => {
46                map.serialize_entry(&"type", &"stringField")?;
47                map.serialize_entry(&"stringField", value)?;
48            }
49            SearchQuery::TimestampField(value) => {
50                map.serialize_entry(&"type", &"timestampField")?;
51                map.serialize_entry(&"timestampField", value)?;
52            }
53            SearchQuery::LongField(value) => {
54                map.serialize_entry(&"type", &"longField")?;
55                map.serialize_entry(&"longField", value)?;
56            }
57            SearchQuery::BooleanField(value) => {
58                map.serialize_entry(&"type", &"booleanField")?;
59                map.serialize_entry(&"booleanField", value)?;
60            }
61            SearchQuery::ExactMatch(value) => {
62                map.serialize_entry(&"type", &"exactMatch")?;
63                map.serialize_entry(&"exactMatch", value)?;
64            }
65            SearchQuery::StringArrayExactMatch(value) => {
66                map.serialize_entry(&"type", &"stringArrayExactMatch")?;
67                map.serialize_entry(&"stringArrayExactMatch", value)?;
68            }
69            SearchQuery::StringArrayLength(value) => {
70                map.serialize_entry(&"type", &"stringArrayLength")?;
71                map.serialize_entry(&"stringArrayLength", value)?;
72            }
73            SearchQuery::SearchText(value) => {
74                map.serialize_entry(&"type", &"searchText")?;
75                map.serialize_entry(&"searchText", value)?;
76            }
77            SearchQuery::Label(value) => {
78                map.serialize_entry(&"type", &"label")?;
79                map.serialize_entry(&"label", value)?;
80            }
81            SearchQuery::Property(value) => {
82                map.serialize_entry(&"type", &"property")?;
83                map.serialize_entry(&"property", value)?;
84            }
85            SearchQuery::PropertyKey(value) => {
86                map.serialize_entry(&"type", &"propertyKey")?;
87                map.serialize_entry(&"propertyKey", value)?;
88            }
89            SearchQuery::And(value) => {
90                map.serialize_entry(&"type", &"and")?;
91                map.serialize_entry(&"and", value)?;
92            }
93            SearchQuery::Or(value) => {
94                map.serialize_entry(&"type", &"or")?;
95                map.serialize_entry(&"or", value)?;
96            }
97            SearchQuery::Not(value) => {
98                map.serialize_entry(&"type", &"not")?;
99                map.serialize_entry(&"not", value)?;
100            }
101            SearchQuery::Workspace(value) => {
102                map.serialize_entry(&"type", &"workspace")?;
103                map.serialize_entry(&"workspace", value)?;
104            }
105            SearchQuery::CreatedAt(value) => {
106                map.serialize_entry(&"type", &"createdAt")?;
107                map.serialize_entry(&"createdAt", value)?;
108            }
109            SearchQuery::ArchivedStatus(value) => {
110                map.serialize_entry(&"type", &"archivedStatus")?;
111                map.serialize_entry(&"archivedStatus", value)?;
112            }
113            SearchQuery::IsPublished(value) => {
114                map.serialize_entry(&"type", &"isPublished")?;
115                map.serialize_entry(&"isPublished", value)?;
116            }
117            SearchQuery::Unknown(value) => {
118                map.serialize_entry(&"type", &value.type_)?;
119                map.serialize_entry(&value.type_, &value.value)?;
120            }
121        }
122        map.end()
123    }
124}
125impl<'de> de::Deserialize<'de> for SearchQuery {
126    fn deserialize<D>(d: D) -> Result<SearchQuery, D::Error>
127    where
128        D: de::Deserializer<'de>,
129    {
130        d.deserialize_map(Visitor_)
131    }
132}
133struct Visitor_;
134impl<'de> de::Visitor<'de> for Visitor_ {
135    type Value = SearchQuery;
136    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
137        fmt.write_str("union SearchQuery")
138    }
139    fn visit_map<A>(self, mut map: A) -> Result<SearchQuery, A::Error>
140    where
141        A: de::MapAccess<'de>,
142    {
143        let v = match map.next_key::<UnionField_<Variant_>>()? {
144            Some(UnionField_::Type) => {
145                let variant = map.next_value()?;
146                let key = map.next_key()?;
147                match (variant, key) {
148                    (Variant_::DateTimeField, Some(Variant_::DateTimeField)) => {
149                        let value = map.next_value()?;
150                        SearchQuery::DateTimeField(value)
151                    }
152                    (Variant_::StringField, Some(Variant_::StringField)) => {
153                        let value = map.next_value()?;
154                        SearchQuery::StringField(value)
155                    }
156                    (Variant_::TimestampField, Some(Variant_::TimestampField)) => {
157                        let value = map.next_value()?;
158                        SearchQuery::TimestampField(value)
159                    }
160                    (Variant_::LongField, Some(Variant_::LongField)) => {
161                        let value = map.next_value()?;
162                        SearchQuery::LongField(value)
163                    }
164                    (Variant_::BooleanField, Some(Variant_::BooleanField)) => {
165                        let value = map.next_value()?;
166                        SearchQuery::BooleanField(value)
167                    }
168                    (Variant_::ExactMatch, Some(Variant_::ExactMatch)) => {
169                        let value = map.next_value()?;
170                        SearchQuery::ExactMatch(value)
171                    }
172                    (
173                        Variant_::StringArrayExactMatch,
174                        Some(Variant_::StringArrayExactMatch),
175                    ) => {
176                        let value = map.next_value()?;
177                        SearchQuery::StringArrayExactMatch(value)
178                    }
179                    (Variant_::StringArrayLength, Some(Variant_::StringArrayLength)) => {
180                        let value = map.next_value()?;
181                        SearchQuery::StringArrayLength(value)
182                    }
183                    (Variant_::SearchText, Some(Variant_::SearchText)) => {
184                        let value = map.next_value()?;
185                        SearchQuery::SearchText(value)
186                    }
187                    (Variant_::Label, Some(Variant_::Label)) => {
188                        let value = map.next_value()?;
189                        SearchQuery::Label(value)
190                    }
191                    (Variant_::Property, Some(Variant_::Property)) => {
192                        let value = map.next_value()?;
193                        SearchQuery::Property(value)
194                    }
195                    (Variant_::PropertyKey, Some(Variant_::PropertyKey)) => {
196                        let value = map.next_value()?;
197                        SearchQuery::PropertyKey(value)
198                    }
199                    (Variant_::And, Some(Variant_::And)) => {
200                        let value = map.next_value()?;
201                        SearchQuery::And(value)
202                    }
203                    (Variant_::Or, Some(Variant_::Or)) => {
204                        let value = map.next_value()?;
205                        SearchQuery::Or(value)
206                    }
207                    (Variant_::Not, Some(Variant_::Not)) => {
208                        let value = map.next_value()?;
209                        SearchQuery::Not(value)
210                    }
211                    (Variant_::Workspace, Some(Variant_::Workspace)) => {
212                        let value = map.next_value()?;
213                        SearchQuery::Workspace(value)
214                    }
215                    (Variant_::CreatedAt, Some(Variant_::CreatedAt)) => {
216                        let value = map.next_value()?;
217                        SearchQuery::CreatedAt(value)
218                    }
219                    (Variant_::ArchivedStatus, Some(Variant_::ArchivedStatus)) => {
220                        let value = map.next_value()?;
221                        SearchQuery::ArchivedStatus(value)
222                    }
223                    (Variant_::IsPublished, Some(Variant_::IsPublished)) => {
224                        let value = map.next_value()?;
225                        SearchQuery::IsPublished(value)
226                    }
227                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
228                        if type_ == b {
229                            let value = map.next_value()?;
230                            SearchQuery::Unknown(Unknown { type_, value })
231                        } else {
232                            return Err(
233                                de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
234                            )
235                        }
236                    }
237                    (variant, Some(key)) => {
238                        return Err(
239                            de::Error::invalid_value(
240                                de::Unexpected::Str(key.as_str()),
241                                &variant.as_str(),
242                            ),
243                        );
244                    }
245                    (variant, None) => {
246                        return Err(de::Error::missing_field(variant.as_str()));
247                    }
248                }
249            }
250            Some(UnionField_::Value(variant)) => {
251                let value = match &variant {
252                    Variant_::DateTimeField => {
253                        let value = map.next_value()?;
254                        SearchQuery::DateTimeField(value)
255                    }
256                    Variant_::StringField => {
257                        let value = map.next_value()?;
258                        SearchQuery::StringField(value)
259                    }
260                    Variant_::TimestampField => {
261                        let value = map.next_value()?;
262                        SearchQuery::TimestampField(value)
263                    }
264                    Variant_::LongField => {
265                        let value = map.next_value()?;
266                        SearchQuery::LongField(value)
267                    }
268                    Variant_::BooleanField => {
269                        let value = map.next_value()?;
270                        SearchQuery::BooleanField(value)
271                    }
272                    Variant_::ExactMatch => {
273                        let value = map.next_value()?;
274                        SearchQuery::ExactMatch(value)
275                    }
276                    Variant_::StringArrayExactMatch => {
277                        let value = map.next_value()?;
278                        SearchQuery::StringArrayExactMatch(value)
279                    }
280                    Variant_::StringArrayLength => {
281                        let value = map.next_value()?;
282                        SearchQuery::StringArrayLength(value)
283                    }
284                    Variant_::SearchText => {
285                        let value = map.next_value()?;
286                        SearchQuery::SearchText(value)
287                    }
288                    Variant_::Label => {
289                        let value = map.next_value()?;
290                        SearchQuery::Label(value)
291                    }
292                    Variant_::Property => {
293                        let value = map.next_value()?;
294                        SearchQuery::Property(value)
295                    }
296                    Variant_::PropertyKey => {
297                        let value = map.next_value()?;
298                        SearchQuery::PropertyKey(value)
299                    }
300                    Variant_::And => {
301                        let value = map.next_value()?;
302                        SearchQuery::And(value)
303                    }
304                    Variant_::Or => {
305                        let value = map.next_value()?;
306                        SearchQuery::Or(value)
307                    }
308                    Variant_::Not => {
309                        let value = map.next_value()?;
310                        SearchQuery::Not(value)
311                    }
312                    Variant_::Workspace => {
313                        let value = map.next_value()?;
314                        SearchQuery::Workspace(value)
315                    }
316                    Variant_::CreatedAt => {
317                        let value = map.next_value()?;
318                        SearchQuery::CreatedAt(value)
319                    }
320                    Variant_::ArchivedStatus => {
321                        let value = map.next_value()?;
322                        SearchQuery::ArchivedStatus(value)
323                    }
324                    Variant_::IsPublished => {
325                        let value = map.next_value()?;
326                        SearchQuery::IsPublished(value)
327                    }
328                    Variant_::Unknown(type_) => {
329                        let value = map.next_value()?;
330                        SearchQuery::Unknown(Unknown {
331                            type_: type_.clone(),
332                            value,
333                        })
334                    }
335                };
336                if map.next_key::<UnionTypeField_>()?.is_none() {
337                    return Err(de::Error::missing_field("type"));
338                }
339                let type_variant = map.next_value::<Variant_>()?;
340                if variant != type_variant {
341                    return Err(
342                        de::Error::invalid_value(
343                            de::Unexpected::Str(type_variant.as_str()),
344                            &variant.as_str(),
345                        ),
346                    );
347                }
348                value
349            }
350            None => return Err(de::Error::missing_field("type")),
351        };
352        if map.next_key::<UnionField_<Variant_>>()?.is_some() {
353            return Err(de::Error::invalid_length(3, &"type and value fields"));
354        }
355        Ok(v)
356    }
357}
358#[derive(PartialEq)]
359enum Variant_ {
360    DateTimeField,
361    StringField,
362    TimestampField,
363    LongField,
364    BooleanField,
365    ExactMatch,
366    StringArrayExactMatch,
367    StringArrayLength,
368    SearchText,
369    Label,
370    Property,
371    PropertyKey,
372    And,
373    Or,
374    Not,
375    Workspace,
376    CreatedAt,
377    ArchivedStatus,
378    IsPublished,
379    Unknown(Box<str>),
380}
381impl Variant_ {
382    fn as_str(&self) -> &'static str {
383        match *self {
384            Variant_::DateTimeField => "dateTimeField",
385            Variant_::StringField => "stringField",
386            Variant_::TimestampField => "timestampField",
387            Variant_::LongField => "longField",
388            Variant_::BooleanField => "booleanField",
389            Variant_::ExactMatch => "exactMatch",
390            Variant_::StringArrayExactMatch => "stringArrayExactMatch",
391            Variant_::StringArrayLength => "stringArrayLength",
392            Variant_::SearchText => "searchText",
393            Variant_::Label => "label",
394            Variant_::Property => "property",
395            Variant_::PropertyKey => "propertyKey",
396            Variant_::And => "and",
397            Variant_::Or => "or",
398            Variant_::Not => "not",
399            Variant_::Workspace => "workspace",
400            Variant_::CreatedAt => "createdAt",
401            Variant_::ArchivedStatus => "archivedStatus",
402            Variant_::IsPublished => "isPublished",
403            Variant_::Unknown(_) => "unknown variant",
404        }
405    }
406}
407impl<'de> de::Deserialize<'de> for Variant_ {
408    fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
409    where
410        D: de::Deserializer<'de>,
411    {
412        d.deserialize_str(VariantVisitor_)
413    }
414}
415struct VariantVisitor_;
416impl<'de> de::Visitor<'de> for VariantVisitor_ {
417    type Value = Variant_;
418    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
419        fmt.write_str("string")
420    }
421    fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
422    where
423        E: de::Error,
424    {
425        let v = match value {
426            "dateTimeField" => Variant_::DateTimeField,
427            "stringField" => Variant_::StringField,
428            "timestampField" => Variant_::TimestampField,
429            "longField" => Variant_::LongField,
430            "booleanField" => Variant_::BooleanField,
431            "exactMatch" => Variant_::ExactMatch,
432            "stringArrayExactMatch" => Variant_::StringArrayExactMatch,
433            "stringArrayLength" => Variant_::StringArrayLength,
434            "searchText" => Variant_::SearchText,
435            "label" => Variant_::Label,
436            "property" => Variant_::Property,
437            "propertyKey" => Variant_::PropertyKey,
438            "and" => Variant_::And,
439            "or" => Variant_::Or,
440            "not" => Variant_::Not,
441            "workspace" => Variant_::Workspace,
442            "createdAt" => Variant_::CreatedAt,
443            "archivedStatus" => Variant_::ArchivedStatus,
444            "isPublished" => Variant_::IsPublished,
445            value => Variant_::Unknown(value.to_string().into_boxed_str()),
446        };
447        Ok(v)
448    }
449}
450///An unknown variant of the SearchQuery union.
451#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
452pub struct Unknown {
453    type_: Box<str>,
454    value: conjure_object::Any,
455}
456impl Unknown {
457    /// Returns the unknown variant's type name.
458    #[inline]
459    pub fn type_(&self) -> &str {
460        &self.type_
461    }
462}