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, serde::Deserialize, serde::Serialize, Copy)]
194#[cfg_attr(feature = "console", derive(clap::ValueEnum))]
195pub enum FilterComparison {
196 Eq,
198 Ne,
200 Lt,
202 Le,
204 Gt,
206 Ge,
208 StartsWith,
210 EndsWith,
212 Contains,
214}
215
216#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
221pub struct ComparisonFilter<T> {
222 pub field: String,
224 pub op: FilterComparison,
226 pub operand: T,
228}
229
230#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
235pub struct FieldRange {
236 pub field: String,
238 pub lower: String,
240 pub upper: String,
242}
243
244#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
246pub struct RowFilters {
247 pub payload: PayloadFilters,
249 pub compare: Option<ComparisonFilter<String>>,
251 pub length: Option<ComparisonFilter<u32>>,
253 pub present: Option<String>,
255 pub absent: Option<String>,
257 pub text: Option<ComparisonFilter<String>>,
259 pub boolean: Option<(String, bool)>,
261 pub between_fields: Option<FieldRange>,
263 pub not_between_fields: Option<FieldRange>,
265}
266
267#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
269pub struct RetainedSelection {
270 pub entity: String,
272 pub select: String,
274 pub entity_filters: EntityFilters,
276 pub limit: u32,
278 pub group_bounds: (Option<String>, Option<String>),
280 pub group_order: Option<String>,
282 pub filters: RowFilters,
284 pub order: (Vec<String>, bool),
286}
287
288#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
290pub struct RetainedResume {
291 pub selection: RetainedSelection,
293 pub handle: Vec<u8>,
295 pub sequence: u64,
297 pub work: u32,
299 pub bytes: u32,
301 pub page_size: u32,
303 pub after: Option<Vec<u8>>,
305}
306
307#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
309pub struct DisplayPage {
310 pub columns: Vec<String>,
312 pub rows: Vec<Vec<String>>,
314 pub next: Option<Vec<u8>>,
316}
317
318#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
320pub struct RetainedProgress {
321 pub sequence: u64,
323 pub examined: u64,
325 pub input_bytes: u64,
327 pub output_bytes: u64,
329 pub phase: RetainedPhase,
331}
332
333#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
335pub enum RetainedPhase {
336 Running,
338 Complete(DisplayPage),
340 Invalidated,
342 Expired,
344}
345
346impl RetainedPhase {
347 #[must_use]
349 pub const fn label(&self) -> &'static str {
350 match self {
351 Self::Running => "Running",
352 Self::Complete(_) => "Complete",
353 Self::Invalidated => "Invalidated",
354 Self::Expired => "Expired",
355 }
356 }
357}
358
359#[must_use]
361pub fn lowercase_hex(bytes: &[u8], prefix: &str) -> String {
362 const DIGITS: &[u8; 16] = b"0123456789abcdef";
363 let mut output = String::with_capacity(prefix.len() + bytes.len() * 2);
364 output.push_str(prefix);
365 for &byte in bytes {
366 output.push(char::from(DIGITS[usize::from(byte >> 4)]));
367 output.push(char::from(DIGITS[usize::from(byte & 15)]));
368 }
369 output
370}