1#![forbid(unsafe_code)]
3
4#[cfg(feature = "fixture-wire")]
5pub mod fixture_wire;
6
7#[cfg(feature = "host")]
8pub mod host;
9
10#[derive(Debug, serde::Deserialize, serde::Serialize)]
12pub struct ConsolePage {
13 pub page: DisplayPage,
15 pub examined: u32,
17 pub fetched: u32,
19 pub output_bytes: u32,
21}
22
23#[derive(Clone, Default, Debug, serde::Deserialize, serde::Serialize)]
25pub struct PayloadFilters {
26 pub minimum: Option<Vec<u8>>,
28 pub maximum: Option<Vec<u8>>,
30 pub prefix: Option<Vec<u8>>,
32 pub suffix: Option<Vec<u8>>,
34 pub contains: Option<Vec<u8>>,
36}
37
38#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
40#[cfg_attr(feature = "console", derive(clap::Args))]
41pub struct EntityFilters {
42 #[cfg_attr(feature = "console", arg(long = "min"))]
44 pub minimum: Option<u64>,
45 #[cfg_attr(feature = "console", arg(long))]
47 pub category: Option<u64>,
48 #[cfg_attr(feature = "console", arg(long))]
50 pub entry_id: Option<u64>,
51}
52
53#[derive(Debug, serde::Deserialize, serde::Serialize)]
55pub struct QueryRequest {
56 pub entity: String,
58 pub cursor: Option<Vec<u8>>,
60 pub limit: u32,
62 pub entity_filters: EntityFilters,
64 pub order: Vec<String>,
66 pub descending: bool,
68 pub work: u32,
70 pub bytes: u32,
72 pub select: String,
74 pub options: QueryOptions,
76}
77
78#[derive(Debug, serde::Deserialize, serde::Serialize)]
80pub struct QueryOptions {
81 pub distinct: bool,
83 pub group_bounds: (Option<String>, Option<String>),
85 pub group_order: Option<String>,
87 pub filters: RowFilters,
89}
90
91#[derive(Debug, serde::Deserialize, serde::Serialize)]
93pub struct Status {
94 pub schema: [u8; 32],
96 pub incarnation: [u8; 16],
98 pub revision: u64,
100 pub pages: u64,
102}
103
104#[derive(Debug, serde::Deserialize, serde::Serialize)]
106pub struct SchemaResponse {
107 pub status: Status,
109 pub entities: Vec<EntityView>,
111 pub types: Vec<TypeView>,
113}
114
115#[derive(Debug, serde::Deserialize, serde::Serialize)]
117pub struct EntityView {
118 pub name: String,
120 pub id: u32,
122 pub primary: String,
124 pub fields: Vec<FieldView>,
126 pub indexes: Vec<IndexView>,
128}
129
130#[derive(Debug, serde::Deserialize, serde::Serialize)]
132pub struct FieldView {
133 pub name: String,
135 pub kind: String,
137 pub optional: bool,
139 pub info: String,
141 pub reference: Option<(String, String)>,
143}
144
145#[derive(Debug, serde::Deserialize, serde::Serialize)]
150pub struct IndexView {
151 pub name: String,
153 pub fields: Vec<String>,
155 pub unique: bool,
157 pub present_only: bool,
159}
160
161#[derive(Debug, serde::Deserialize, serde::Serialize)]
166pub struct TypeView {
167 pub name: String,
169 pub kind: String,
171 pub members: Vec<TypeMemberView>,
173}
174
175#[derive(Debug, serde::Deserialize, serde::Serialize)]
180pub struct TypeMemberView {
181 pub name: String,
183 #[serde(rename = "type")]
185 pub kind: String,
186 pub optional: bool,
188 pub info: String,
190}
191
192#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, Copy)]
197#[cfg_attr(feature = "console", derive(clap::ValueEnum))]
198pub enum FilterComparison {
199 Eq,
201 Ne,
203 Lt,
205 Le,
207 Gt,
209 Ge,
211 StartsWith,
213 EndsWith,
215 Contains,
217}
218
219#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
224pub struct ComparisonFilter<T> {
225 pub field: String,
227 pub op: FilterComparison,
229 pub operand: T,
231}
232
233#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
238pub struct FieldRange {
239 pub field: String,
241 pub lower: String,
243 pub upper: String,
245}
246
247#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
249pub struct RowFilters {
250 pub payload: PayloadFilters,
252 pub compare: Option<ComparisonFilter<String>>,
254 pub length: Option<ComparisonFilter<u32>>,
256 pub present: Option<String>,
258 pub absent: Option<String>,
260 pub text: Option<ComparisonFilter<String>>,
262 pub boolean: Option<(String, bool)>,
264 pub between_fields: Option<FieldRange>,
266 pub not_between_fields: Option<FieldRange>,
268}
269
270#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
272pub struct RetainedSelection {
273 pub entity: String,
275 pub select: String,
277 pub entity_filters: EntityFilters,
279 pub limit: u32,
281 pub group_bounds: (Option<String>, Option<String>),
283 pub group_order: Option<String>,
285 pub filters: RowFilters,
287 pub order: (Vec<String>, bool),
289}
290
291#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
293pub struct RetainedResume {
294 pub selection: RetainedSelection,
296 pub handle: Vec<u8>,
298 pub sequence: u64,
300 pub work: u32,
302 pub bytes: u32,
304 pub page_size: u32,
306 pub after: Option<Vec<u8>>,
308}
309
310#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
312pub struct DisplayPage {
313 pub columns: Vec<String>,
315 pub rows: Vec<Vec<String>>,
317 pub next: Option<Vec<u8>>,
319}
320
321#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
323pub struct RetainedProgress {
324 pub sequence: u64,
326 pub examined: u64,
328 pub input_bytes: u64,
330 pub output_bytes: u64,
332 pub phase: RetainedPhase,
334}
335
336#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
338pub enum RetainedPhase {
339 Running,
341 Complete(DisplayPage),
343 Invalidated,
345 Expired,
347}
348
349impl RetainedPhase {
350 #[must_use]
352 pub const fn label(&self) -> &'static str {
353 match self {
354 Self::Running => "Running",
355 Self::Complete(_) => "Complete",
356 Self::Invalidated => "Invalidated",
357 Self::Expired => "Expired",
358 }
359 }
360}
361
362#[must_use]
364pub fn lowercase_hex(bytes: &[u8], prefix: &str) -> String {
365 const DIGITS: &[u8; 16] = b"0123456789abcdef";
366 let mut output = String::with_capacity(prefix.len() + bytes.len() * 2);
367 output.push_str(prefix);
368 for &byte in bytes {
369 output.push(char::from(DIGITS[usize::from(byte >> 4)]));
370 output.push(char::from(DIGITS[usize::from(byte & 15)]));
371 }
372 output
373}