reduct_base/msg/entry_api.rs
1use std::collections::HashMap;
2// Copyright 2023 ReductSoftware UG
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6use serde::{Deserialize, Serialize};
7use serde_json::Value;
8
9/// Stats of entry
10#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
11pub struct EntryInfo {
12 /// Entry name
13 pub name: String,
14 /// Size of entry in bytes
15 pub size: u64,
16 /// Number of records in entry
17 pub record_count: u64,
18 /// Number of blocks in entry
19 pub block_count: u64,
20 /// Oldest record in entry
21 pub oldest_record: u64,
22 /// Latest record in entry
23 pub latest_record: u64,
24}
25
26/// Query Info
27#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
28pub struct QueryInfo {
29 /// Unique query name
30 pub id: u64,
31}
32
33/// Remove Query Info
34#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
35pub struct RemoveQueryInfo {
36 /// Unique query name
37 pub removed_records: u64,
38}
39
40/// Rename Entry
41#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
42pub struct RenameEntry {
43 /// New entry name
44 pub new_name: String,
45}
46
47#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
48pub enum QueryType {
49 /// Query records in entry
50 #[default]
51 #[serde(rename = "QUERY")]
52 Query = 0,
53 /// Remove records in entry
54 #[serde(rename = "REMOVE")]
55 Remove = 1,
56}
57
58/// Query records in entry
59#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
60pub struct QueryEntry {
61 pub query_type: QueryType,
62
63 /// Start query from (Unix timestamp in microseconds)
64 pub start: Option<u64>,
65 /// Stop query at (Unix timestamp in microseconds)
66 pub stop: Option<u64>,
67
68 /// Include records with label
69 pub include: Option<HashMap<String, String>>,
70 /// Exclude records with label
71 pub exclude: Option<HashMap<String, String>>,
72 /// Return a record every S seconds
73 pub each_s: Option<f64>,
74 /// Return a record every N records
75 pub each_n: Option<u64>,
76 /// Limit the number of records returned
77 pub limit: Option<u64>,
78
79 /// TTL of query in seconds
80 pub ttl: Option<u64>,
81 /// Retrieve only metadata
82 pub only_metadata: Option<bool>,
83 /// Continuous query, it doesn't stop until the TTL is reached
84 pub continuous: Option<bool>,
85
86 /// Conditional query
87 pub when: Option<Value>,
88 /// Strict conditional query
89 /// If true, the query returns an error if any condition cannot be evaluated
90 pub strict: Option<bool>,
91 /// Extension
92 /// use nested objects to pass additional information to extensions
93 ///
94 /// Example:
95 /// ```json
96 /// {
97 /// "ext": {
98 /// "img_ext": {
99 /// "scale_width": 100,
100 /// "scale_height": 100
101 /// }
102 /// }
103 pub ext: Option<Value>,
104}