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