1use crate::{NoopProgress, ProgressReporter};
2use serde::{Deserialize, Serialize};
3use serde_json::{Map, Value};
4use std::fmt;
5use std::sync::Arc;
6
7pub type Metadata = Map<String, Value>;
11
12#[non_exhaustive]
14#[derive(Clone, Debug, Serialize, Deserialize)]
15pub struct HealthResponse {
16 pub status: String,
18}
19
20#[non_exhaustive]
22#[derive(Clone, Debug, Serialize, Deserialize)]
23pub struct Stream {
24 pub id: i32,
26 pub name: String,
28 #[serde(rename = "type")]
30 pub stream_type: StreamType,
31 pub datapool: String,
33 #[serde(default, deserialize_with = "deserialize_default_string")]
35 pub description: String,
36 #[serde(default)]
38 pub n_datasets: Option<u64>,
39 #[serde(default)]
41 pub n_datapoints: Option<u64>,
42 #[serde(default)]
44 pub cold_bytes: Option<u64>,
45 #[serde(default)]
47 pub hot_bytes: Option<u64>,
48 #[serde(default)]
50 pub plugin: Option<String>,
51 #[serde(default)]
53 pub plugin_args: Option<String>,
54 #[serde(flatten)]
56 pub extra: Value,
57}
58
59#[non_exhaustive]
61#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
62#[serde(rename_all = "lowercase")]
63pub enum StreamType {
64 Files,
65 Realtime,
66}
67
68fn deserialize_default_string<'de, D>(deserializer: D) -> std::result::Result<String, D::Error>
69where
70 D: serde::Deserializer<'de>,
71{
72 Ok(Option::<String>::deserialize(deserializer)?.unwrap_or_default())
73}
74
75#[non_exhaustive]
79#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
80#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
81pub enum ImportStatus {
82 Uploading,
84 Waiting,
86 Importing,
88 Postprocessing,
90 PostprocessingFailed,
92 Finished,
94 Live,
96 Failed,
98}
99
100#[non_exhaustive]
102#[derive(Clone, Debug, Serialize, Deserialize)]
103pub struct Dataset {
104 pub id: i32,
106 pub datastream_id: i32,
108 pub datastream_version: Option<i32>,
110 pub created_at: f64,
112 pub created_by: Option<String>,
114 pub import_status: ImportStatus,
116 pub import_progress: Option<f64>,
118 pub import_message: Option<String>,
120 pub import_time: Option<f64>,
122 pub path: String,
124 pub metadata: Metadata,
126 pub cold_path: Option<String>,
128 pub cold_bytes: Option<u64>,
130 pub hot_bytes: Option<u64>,
132 pub backup_path: Option<String>,
134 pub backup_size: Option<u64>,
136 pub plugin: Option<String>,
138 pub plugin_args: Option<String>,
140 pub n_datapoints: Option<u64>,
142 pub n_signals: Option<u64>,
144 pub timestamp_start: Option<f64>,
146 pub timestamp_stop: Option<f64>,
148 pub import_speed: Option<f64>,
150}
151
152#[non_exhaustive]
154#[derive(Clone, Copy, Debug)]
155pub enum UploadModeOverride {
156 Auto,
158 Server,
160}
161
162#[non_exhaustive]
164pub struct PushFileOptions {
165 pub(crate) metadata: Metadata,
166 pub(crate) concurrency: usize,
167 pub(crate) upload_mode: UploadModeOverride,
168 pub(crate) progress: Arc<dyn ProgressReporter>,
169}
170
171impl fmt::Debug for PushFileOptions {
172 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
173 f.debug_struct("PushFileOptions")
174 .field("metadata", &self.metadata)
175 .field("concurrency", &self.concurrency)
176 .field("upload_mode", &self.upload_mode)
177 .finish_non_exhaustive()
178 }
179}
180
181impl PushFileOptions {
182 pub fn builder() -> PushFileOptionsBuilder {
184 PushFileOptionsBuilder::default()
185 }
186}
187
188impl Default for PushFileOptions {
189 fn default() -> Self {
190 Self {
191 metadata: Default::default(),
192 concurrency: 4,
193 upload_mode: UploadModeOverride::Auto,
194 progress: Arc::new(NoopProgress),
195 }
196 }
197}
198
199#[non_exhaustive]
201#[derive(Clone)]
202pub struct PushFileOptionsBuilder {
203 metadata: Metadata,
204 concurrency: usize,
205 upload_mode: UploadModeOverride,
206 progress: Arc<dyn ProgressReporter>,
207}
208
209impl fmt::Debug for PushFileOptionsBuilder {
210 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
211 f.debug_struct("PushFileOptionsBuilder")
212 .field("metadata", &self.metadata)
213 .field("concurrency", &self.concurrency)
214 .field("upload_mode", &self.upload_mode)
215 .finish_non_exhaustive()
216 }
217}
218
219impl Default for PushFileOptionsBuilder {
220 fn default() -> Self {
221 let options = PushFileOptions::default();
222 Self {
223 metadata: options.metadata,
224 concurrency: options.concurrency,
225 upload_mode: options.upload_mode,
226 progress: options.progress,
227 }
228 }
229}
230
231impl PushFileOptionsBuilder {
232 pub fn metadata<I, K, V>(mut self, entries: I) -> Self
246 where
247 I: IntoIterator<Item = (K, V)>,
248 K: Into<String>,
249 V: Into<Value>,
250 {
251 self.metadata = entries
252 .into_iter()
253 .map(|(key, value)| (key.into(), value.into()))
254 .collect();
255 self
256 }
257
258 pub fn concurrency(mut self, concurrency: usize) -> Self {
263 self.concurrency = concurrency;
264 self
265 }
266
267 pub fn upload_mode(mut self, upload_mode: UploadModeOverride) -> Self {
269 self.upload_mode = upload_mode;
270 self
271 }
272
273 pub fn progress(mut self, progress: Arc<dyn ProgressReporter>) -> Self {
275 self.progress = progress;
276 self
277 }
278
279 pub fn build(self) -> PushFileOptions {
281 PushFileOptions {
282 metadata: self.metadata,
283 concurrency: self.concurrency,
284 upload_mode: self.upload_mode,
285 progress: self.progress,
286 }
287 }
288}
289
290#[derive(Debug, Serialize, Deserialize)]
291pub(crate) struct StreamsResponse {
292 pub(crate) streams: Vec<Stream>,
293}
294
295#[derive(Debug, Deserialize)]
296#[serde(rename_all = "lowercase")]
297pub(crate) enum UploadMode {
298 Server,
299 Azure,
300 Single,
301 Multipart,
302}
303
304#[derive(Debug, Deserialize)]
305pub(crate) struct IngestionInit {
306 pub(crate) dataset_id: i32,
307 pub(crate) ingestion_id: i32,
308 pub(crate) mode: UploadMode,
309 pub(crate) presigned_url: Option<String>,
310 pub(crate) part_size: Option<u64>,
311 #[serde(rename = "expires_in")]
312 pub(crate) _expires_in: u64,
313}
314
315#[derive(Debug, Deserialize)]
316pub(crate) struct PartUrl {
317 pub(crate) part_number: u32,
318 pub(crate) url: String,
319}
320
321#[derive(Debug, Deserialize)]
322pub(crate) struct PartUrlsResponse {
323 pub(crate) parts: Vec<PartUrl>,
324 #[serde(rename = "expires_in")]
325 pub(crate) _expires_in: u64,
326 pub(crate) next_part: Option<u32>,
327}