decthings_api/client/rpc/dataset/
request.rs

1use crate::{
2    client::rpc::TagProvider,
3    tensor::{DecthingsParameterDefinition, DecthingsTensor},
4};
5use serde::Serialize;
6
7#[derive(Debug, Clone, Serialize)]
8#[serde(rename_all = "camelCase")]
9pub struct CreateDatasetParams<'a> {
10    /// The dataset's name.
11    pub name: &'a str,
12    /// A description of the dataset.
13    pub description: &'a str,
14    /// If true, all Decthings users can find and use this dataset. Defaults to false.
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub public_access: Option<bool>,
17    /// Tags are used to specify things like dataset type (image classification, etc.) and other metadata.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub tags: Option<&'a [TagProvider<'a>]>,
20    /// Each key contains separate data, allowing you to mix multiple types. For example, for an image dataset you
21    /// could have an "image" of type image, and "label" of type string.
22    pub keys: &'a [&'a DecthingsParameterDefinition],
23}
24
25#[derive(Debug, Clone, Serialize)]
26#[serde(rename_all = "camelCase")]
27pub struct UpdateDatasetProperties<'a> {
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub name: Option<&'a str>,
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub description: Option<&'a str>,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub public_access: Option<bool>,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub tags: Option<&'a [TagProvider<'a>]>,
36}
37
38#[derive(Debug, Clone, Serialize)]
39#[serde(rename_all = "camelCase")]
40pub struct UpdateDatasetParams<'a> {
41    /// The dataset's id.
42    pub dataset_id: &'a str,
43    /// Properties and values to change. Empty fields will not be changed.
44    pub properties: UpdateDatasetProperties<'a>,
45}
46
47#[derive(Debug, Clone, Serialize)]
48#[serde(rename_all = "camelCase")]
49pub struct DeleteDatasetParams<'a> {
50    /// The dataset's id.
51    pub dataset_id: &'a str,
52}
53
54#[derive(Debug, Clone, Serialize)]
55#[serde(rename_all = "camelCase")]
56pub struct GetDatasetsFilter<'a, S: AsRef<str>> {
57    #[serde(serialize_with = "super::super::serialize_option_asref_str_seq")]
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub owners: Option<&'a [S]>,
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub tags: Option<&'a [TagProvider<'a>]>,
62    #[serde(serialize_with = "super::super::serialize_option_asref_str_seq")]
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub ids: Option<&'a [S]>,
65    #[serde(serialize_with = "super::super::serialize_option_asref_str_seq")]
66    #[serde(skip_serializing_if = "Option::is_none")]
67    pub names: Option<&'a [S]>,
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub search_name: Option<&'a str>,
70}
71
72#[derive(Debug, Clone, Serialize)]
73#[serde(rename_all = "camelCase")]
74pub enum SortDirection {
75    Asc,
76    Desc,
77}
78
79#[derive(Debug, Clone, Serialize)]
80#[serde(rename_all = "camelCase")]
81#[serde(bound(serialize = ""))]
82pub struct GetDatasetsParams<'a, S: AsRef<str>> {
83    /// Number of items from the results to skip. Defaults to 0.
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub offset: Option<u32>,
86    /// Max number of items to return. Defaults to 20.
87    #[serde(skip_serializing_if = "Option::is_none")]
88    pub limit: Option<u32>,
89    /// If specified, determines which items to retrieve.
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub filter: Option<GetDatasetsFilter<'a, S>>,
92    /// Specifies a field in the returned items to sort by. Defaults to "createdAt".
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub sort: Option<&'a str>,
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub sort_direction: Option<SortDirection>,
97}
98
99#[derive(Debug, Clone)]
100pub struct DataToAddForKey<'a> {
101    pub key: &'a str,
102    pub data: Vec<DecthingsTensor<'a>>,
103}
104
105impl Serialize for DataToAddForKey<'_> {
106    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
107    where
108        S: serde::Serializer,
109    {
110        serializer.serialize_str(self.key)
111    }
112}
113
114#[derive(Debug, Clone, Serialize)]
115#[serde(rename_all = "camelCase")]
116pub struct AddEntriesParams<'a> {
117    /// The dataset's id.
118    pub dataset_id: &'a str,
119    /// New data to add to the dataset. There should be one entry for each key in the dataset, and the length of the
120    /// data to add to all keys must be the same.
121    pub keys: Vec<DataToAddForKey<'a>>,
122    /// If specified, the operation will only be performed if the current dataset versionId is equal to the specified
123    /// string.
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub dataset_version_id: Option<&'a str>,
126}
127
128#[derive(Debug, Clone, Serialize)]
129#[serde(rename_all = "camelCase")]
130pub struct AddEntriesToNeedsReviewParams<'a> {
131    /// The dataset's id.
132    pub dataset_id: &'a str,
133    /// New data to add to the dataset. There should be one entry for each key in the dataset, and the length of the
134    /// data to add to all keys must be the same.
135    pub keys: Vec<DataToAddForKey<'a>>,
136    /// If specified, the operation will only be performed if the current dataset versionId is equal to the specified
137    /// string.
138    #[serde(skip_serializing_if = "Option::is_none")]
139    pub dataset_version_id: Option<&'a str>,
140}
141
142#[derive(Debug, Clone, Serialize)]
143#[serde(rename_all = "camelCase")]
144pub struct FinalizeNeedsReviewEntriesParams<'a> {
145    /// The dataset's id.
146    pub dataset_id: &'a str,
147    /// An array containing the index to remove from 'needs review'.
148    pub indexes: &'a [u32],
149    /// New data to add to the dataset, in place of the entries removed from 'needs review'. There should be one entry
150    /// for each key in the dataset, and the length of the data in each key must equal the length of *indexes*.
151    #[serde(skip_serializing)]
152    pub keys: Vec<DataToAddForKey<'a>>,
153    /// If specified, the operation will only be performed if the current dataset versionId is equal to the specified
154    /// string.
155    #[serde(skip_serializing_if = "Option::is_none")]
156    pub dataset_version_id: Option<&'a str>,
157}
158
159#[derive(Debug, Clone, Serialize)]
160#[serde(rename_all = "camelCase")]
161pub struct EntriesToGetRange {
162    pub start: u32,
163    pub end: u32,
164}
165
166#[derive(Debug, Clone, Serialize)]
167#[serde(untagged)]
168pub enum EntriesToGet<'a> {
169    Indexes(&'a [u32]),
170    Range(EntriesToGetRange),
171}
172
173#[derive(Debug, Clone, Serialize)]
174#[serde(rename_all = "camelCase")]
175pub struct GetEntriesParams<'a> {
176    /// The dataset's id.
177    pub dataset_id: &'a str,
178    /// Which entries to fetch. Either an array of indexes or a start/end range.
179    pub entries: EntriesToGet<'a>,
180    /// If specified, the operation will only be performed if the current dataset versionId is equal to the specified
181    /// string.
182    #[serde(skip_serializing_if = "Option::is_none")]
183    pub dataset_version_id: Option<&'a str>,
184}
185
186#[derive(Debug, Clone, Serialize)]
187#[serde(rename_all = "camelCase")]
188pub struct GetNeedsReviewEntriesParams<'a> {
189    /// The dataset's id.
190    pub dataset_id: &'a str,
191    /// Which entries to fetch. Either an array of indexes or a start/end range.
192    pub entries: EntriesToGet<'a>,
193    /// If specified, the operation will only be performed if the current dataset versionId is equal to the specified
194    /// string.
195    #[serde(skip_serializing_if = "Option::is_none")]
196    pub dataset_version_id: Option<&'a str>,
197}
198
199#[derive(Debug, Clone, Serialize)]
200#[serde(rename_all = "camelCase")]
201pub struct RemoveEntriesParams<'a> {
202    /// The dataset's id.
203    pub dataset_id: &'a str,
204    /// An array of indexes of the elements to remove.
205    pub entries: &'a [u32],
206    /// If specified, the operation will only be performed if the current dataset versionId is equal to the specified
207    /// string.
208    #[serde(skip_serializing_if = "Option::is_none")]
209    pub dataset_version_id: Option<&'a str>,
210}
211
212#[derive(Debug, Clone, Serialize)]
213#[serde(rename_all = "camelCase")]
214pub struct RemoveNeedsReviewEntriesParams<'a> {
215    /// The dataset's id.
216    pub dataset_id: &'a str,
217    /// An array of indexes of the elements to remove.
218    pub entries: &'a [u32],
219    /// If specified, the operation will only be performed if the current dataset versionId is equal to the specified
220    /// string.
221    #[serde(skip_serializing_if = "Option::is_none")]
222    pub dataset_version_id: Option<&'a str>,
223}