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 crate::msg::status::ResourceStatus;
7use serde::{Deserialize, Serialize};
8use serde_json::Value;
9
10/// Stats of entry
11#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
12pub struct EntryInfo {
13 /// Entry name
14 pub name: String,
15 /// Size of entry in bytes
16 pub size: u64,
17 /// Number of records in entry
18 pub record_count: u64,
19 /// Number of blocks in entry
20 pub block_count: u64,
21 /// Oldest record in entry
22 pub oldest_record: u64,
23 /// Latest record in entry
24 pub latest_record: u64,
25 /// Status of the entry
26 #[serde(default)]
27 pub status: ResourceStatus,
28}
29
30/// Query Info
31#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
32pub struct QueryInfo {
33 /// Unique query name
34 pub id: u64,
35}
36
37/// Remove Query Info
38#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
39pub struct RemoveQueryInfo {
40 /// Unique query name
41 pub removed_records: u64,
42}
43
44/// Rename Entry
45#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
46pub struct RenameEntry {
47 /// New entry name
48 pub new_name: String,
49}
50
51#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
52pub enum QueryType {
53 /// Query records in entry
54 #[default]
55 #[serde(rename = "QUERY")]
56 Query = 0,
57 /// Remove records in entry
58 #[serde(rename = "REMOVE")]
59 Remove = 1,
60}
61
62/// Query records in entry
63#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq)]
64pub struct QueryEntry {
65 pub query_type: QueryType,
66
67 /// Specific entries to query (used for Batch Protocol v2)
68 pub entries: Option<Vec<String>>,
69
70 /// Start query from (Unix timestamp in microseconds)
71 pub start: Option<u64>,
72 /// Stop query at (Unix timestamp in microseconds)
73 pub stop: Option<u64>,
74
75 /// Include records with label
76 pub include: Option<HashMap<String, String>>,
77 /// Exclude records with label
78 pub exclude: Option<HashMap<String, String>>,
79 /// Return a record every S seconds
80 pub each_s: Option<f64>,
81 /// Return a record every N records
82 pub each_n: Option<u64>,
83 /// Limit the number of records returned
84 pub limit: Option<u64>,
85
86 /// TTL of query in seconds
87 pub ttl: Option<u64>,
88 /// Retrieve only metadata
89 pub only_metadata: Option<bool>,
90 /// Continuous query, it doesn't stop until the TTL is reached
91 pub continuous: Option<bool>,
92
93 /// Conditional query
94 pub when: Option<Value>,
95 /// Strict conditional query
96 /// If true, the query returns an error if any condition cannot be evaluated
97 pub strict: Option<bool>,
98 /// Extension
99 /// use nested objects to pass additional information to extensions
100 ///
101 /// Example:
102 /// ```json
103 /// {
104 /// "ext": {
105 /// "img_ext": {
106 /// "scale_width": 100,
107 /// "scale_height": 100
108 /// }
109 /// }
110 pub ext: Option<Value>,
111}