1#![forbid(unsafe_code)]
3
4#[cfg(feature = "host")]
5pub mod host;
6
7#[derive(Debug, serde::Deserialize, serde::Serialize)]
9pub struct ConsolePage {
10 pub page: DisplayPage,
12 pub examined: u32,
14 pub fetched: u32,
16 pub output_bytes: u32,
18}
19
20#[derive(Clone, Default, Debug, serde::Deserialize, serde::Serialize)]
22pub struct PayloadFilters {
23 pub minimum: Option<Vec<u8>>,
25 pub maximum: Option<Vec<u8>>,
27 pub prefix: Option<Vec<u8>>,
29 pub suffix: Option<Vec<u8>>,
31 pub contains: Option<Vec<u8>>,
33}
34
35#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
37#[cfg_attr(feature = "console", derive(clap::Args))]
38pub struct EntityFilters {
39 #[cfg_attr(feature = "console", arg(long = "min"))]
41 pub minimum: Option<u64>,
42 #[cfg_attr(feature = "console", arg(long))]
44 pub category: Option<u64>,
45 #[cfg_attr(feature = "console", arg(long))]
47 pub entry_id: Option<u64>,
48}
49
50#[derive(Debug, serde::Deserialize, serde::Serialize)]
52pub struct QueryRequest {
53 pub entity: String,
55 pub cursor: Option<Vec<u8>>,
57 pub limit: u32,
59 pub entity_filters: EntityFilters,
61 pub order: Vec<String>,
63 pub descending: bool,
65 pub work: u32,
67 pub bytes: u32,
69 pub select: String,
71 pub options: QueryOptions,
73}
74
75#[derive(Debug, serde::Deserialize, serde::Serialize)]
77pub struct QueryOptions {
78 pub distinct: bool,
80 pub group_bounds: (Option<String>, Option<String>),
82 pub group_order: Option<String>,
84 pub filters: RowFilters,
86}
87
88#[derive(Debug, serde::Deserialize, serde::Serialize)]
90pub struct Status {
91 pub schema: [u8; 32],
93 pub incarnation: [u8; 16],
95 pub revision: u64,
97 pub pages: u64,
99}
100
101#[derive(Debug, serde::Deserialize, serde::Serialize)]
103pub struct SchemaResponse {
104 pub status: Status,
106 pub entities: Vec<EntityView>,
108 pub types: Vec<TypeView>,
110}
111
112#[derive(Debug, serde::Deserialize, serde::Serialize)]
114pub struct EntityView {
115 pub name: String,
117 pub id: u32,
119 pub primary: String,
121 pub fields: Vec<FieldView>,
123 pub indexes: Vec<IndexView>,
125}
126
127#[derive(Debug, serde::Deserialize, serde::Serialize)]
129pub struct FieldView {
130 pub name: String,
132 pub kind: String,
134 pub optional: bool,
136 pub info: String,
138 pub reference: Option<(String, String)>,
140}
141
142#[derive(Debug, serde::Deserialize, serde::Serialize)]
147pub struct IndexView {
148 pub name: String,
150 pub fields: Vec<String>,
152 pub unique: bool,
154 pub present_only: bool,
156}
157
158#[derive(Debug, serde::Deserialize, serde::Serialize)]
163pub struct TypeView {
164 pub name: String,
166 pub kind: String,
168 pub members: Vec<TypeMemberView>,
170}
171
172#[derive(Debug, serde::Deserialize, serde::Serialize)]
177pub struct TypeMemberView {
178 pub name: String,
180 #[serde(rename = "type")]
182 pub kind: String,
183 pub optional: bool,
185 pub info: String,
187}
188
189#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
191pub struct RowFilters {
192 pub payload: PayloadFilters,
194 pub compare: Option<[String; 3]>,
196 pub length: Option<(String, String, u32)>,
198 pub present: Option<String>,
200 pub absent: Option<String>,
202 pub text: Option<[String; 3]>,
204 pub boolean: Option<(String, bool)>,
206 pub between_fields: Option<[String; 3]>,
208 pub not_between_fields: Option<[String; 3]>,
210}
211
212#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
214pub struct RetainedSelection {
215 pub entity: String,
217 pub select: String,
219 pub entity_filters: EntityFilters,
221 pub limit: u32,
223 pub group_bounds: (Option<String>, Option<String>),
225 pub group_order: Option<String>,
227 pub filters: RowFilters,
229 pub order: (Vec<String>, bool),
231}
232
233#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
235pub struct RetainedResume {
236 pub selection: RetainedSelection,
238 pub handle: Vec<u8>,
240 pub sequence: u64,
242 pub work: u32,
244 pub bytes: u32,
246 pub page_size: u32,
248 pub after: Option<Vec<u8>>,
250}
251
252#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
254pub struct DisplayPage {
255 pub columns: Vec<String>,
257 pub rows: Vec<Vec<String>>,
259 pub next: Option<Vec<u8>>,
261}
262
263#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
265pub struct RetainedProgress {
266 pub sequence: u64,
268 pub examined: u64,
270 pub input_bytes: u64,
272 pub output_bytes: u64,
274 pub phase: RetainedPhase,
276}
277
278#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
280pub enum RetainedPhase {
281 Running,
283 Complete(DisplayPage),
285 Invalidated,
287 Expired,
289}
290
291impl RetainedPhase {
292 #[must_use]
294 pub const fn label(&self) -> &'static str {
295 match self {
296 Self::Running => "Running",
297 Self::Complete(_) => "Complete",
298 Self::Invalidated => "Invalidated",
299 Self::Expired => "Expired",
300 }
301 }
302}
303
304#[must_use]
306pub fn lowercase_hex(bytes: &[u8], prefix: &str) -> String {
307 const DIGITS: &[u8; 16] = b"0123456789abcdef";
308 let mut output = String::with_capacity(prefix.len() + bytes.len() * 2);
309 output.push_str(prefix);
310 for &byte in bytes {
311 output.push(char::from(DIGITS[usize::from(byte >> 4)]));
312 output.push(char::from(DIGITS[usize::from(byte & 15)]));
313 }
314 output
315}