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
use serde::{Deserialize, Serialize};
/// Filters for file search.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum Filter {
/// A filter used to compare a specified attribute key to a given value using a defined
/// comparison operation.
Comparison(ComparisonFilter),
/// Combine multiple filters using `and` or `or`.
Compound(CompoundFilter),
}
/// Single comparison filter.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ComparisonFilter {
/// Specifies the comparison operator: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`, `in`, `nin`.
/// - `eq`: equals
/// - `ne`: not equal
/// - `gt`: greater than
/// - `gte`: greater than or equal
/// - `lt`: less than
/// - `lte`: less than or equal
/// - `in`: in
/// - `nin`: not in
pub kind: ComparisonType,
/// The key to compare against the value.
pub key: String,
/// The value to compare against the attribute key; supports string, number, or boolean types.
pub value: serde_json::Value,
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
pub enum ComparisonType {
#[serde(rename = "eq")]
Equals,
#[serde(rename = "ne")]
NotEquals,
#[serde(rename = "gt")]
GreaterThan,
#[serde(rename = "gte")]
GreaterThanOrEqual,
#[serde(rename = "lt")]
LessThan,
#[serde(rename = "lte")]
LessThanOrEqual,
#[serde(rename = "in")]
In,
#[serde(rename = "nin")]
NotIn,
}
/// Combine multiple filters using `and` or `or`.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct CompoundFilter {
/// 'Type of operation: `and` or `or`.'
pub kind: CompoundType,
/// Array of filters to combine. Items can be ComparisonFilter or CompoundFilter.
pub filters: Vec<Filter>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum CompoundType {
And,
Or,
}