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<ReferenceView>,
143}
144
145#[derive(Debug, serde::Deserialize, serde::Serialize)]
147pub struct ReferenceView {
148 pub target: String,
150 pub index: String,
152}
153
154#[derive(Debug, serde::Deserialize, serde::Serialize)]
159pub struct IndexView {
160 pub name: String,
162 pub fields: Vec<String>,
164 pub unique: bool,
166 pub present_only: bool,
168}
169
170#[derive(Debug, serde::Deserialize, serde::Serialize)]
175pub struct TypeView {
176 pub name: String,
178 pub kind: String,
180 pub members: Vec<TypeMemberView>,
182}
183
184#[derive(Debug, serde::Deserialize, serde::Serialize)]
189pub struct TypeMemberView {
190 pub name: String,
192 #[serde(rename = "type")]
194 pub kind: String,
195 pub optional: bool,
197 pub info: String,
199}
200
201#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, Copy)]
206#[cfg_attr(feature = "console", derive(clap::ValueEnum))]
207pub enum FilterComparison {
208 Eq,
210 Ne,
212 Lt,
214 Le,
216 Gt,
218 Ge,
220 StartsWith,
222 EndsWith,
224 Contains,
226}
227
228#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
233pub struct ComparisonFilter<T> {
234 pub field: String,
236 pub op: FilterComparison,
238 pub operand: T,
240}
241
242#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
247pub struct FieldRange {
248 pub field: String,
250 pub lower: String,
252 pub upper: String,
254}
255
256#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
258pub struct RowFilters {
259 pub payload: PayloadFilters,
261 pub compare: Option<ComparisonFilter<String>>,
263 pub length: Option<ComparisonFilter<u32>>,
265 pub present: Option<String>,
267 pub absent: Option<String>,
269 pub text: Option<ComparisonFilter<String>>,
271 pub boolean: Option<(String, bool)>,
273 pub between_fields: Option<FieldRange>,
275 pub not_between_fields: Option<FieldRange>,
277}
278
279#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
281pub struct RetainedSelection {
282 pub entity: String,
284 pub select: String,
286 pub entity_filters: EntityFilters,
288 pub limit: u32,
290 pub group_bounds: (Option<String>, Option<String>),
292 pub group_order: Option<String>,
294 pub filters: RowFilters,
296 pub order: (Vec<String>, bool),
298}
299
300#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
302pub struct RetainedResume {
303 pub selection: RetainedSelection,
305 pub handle: Vec<u8>,
307 pub sequence: u64,
309 pub work: u32,
311 pub bytes: u32,
313 pub page_size: u32,
315 pub after: Option<Vec<u8>>,
317}
318
319#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
321pub struct DisplayPage {
322 pub columns: Vec<String>,
324 pub rows: Vec<Vec<String>>,
326 pub next: Option<Vec<u8>>,
328}
329
330#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
332pub struct RetainedProgress {
333 pub sequence: u64,
335 pub examined: u64,
337 pub input_bytes: u64,
339 pub output_bytes: u64,
341 pub phase: RetainedPhase,
343}
344
345#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
347pub enum RetainedPhase {
348 Running,
350 Complete(DisplayPage),
352 Invalidated,
354 Expired,
356}
357
358impl RetainedPhase {
359 #[must_use]
361 pub const fn label(&self) -> &'static str {
362 match self {
363 Self::Running => "Running",
364 Self::Complete(_) => "Complete",
365 Self::Invalidated => "Invalidated",
366 Self::Expired => "Expired",
367 }
368 }
369}
370
371#[must_use]
373pub fn lowercase_hex(bytes: &[u8], prefix: &str) -> String {
374 const DIGITS: &[u8; 16] = b"0123456789abcdef";
375 let mut output = String::with_capacity(prefix.len() + bytes.len() * 2);
376 output.push_str(prefix);
377 for &byte in bytes {
378 output.push(char::from(DIGITS[usize::from(byte >> 4)]));
379 output.push(char::from(DIGITS[usize::from(byte & 15)]));
380 }
381 output
382}