1#![forbid(unsafe_code)]
3
4#[cfg(feature = "fixture-codec")]
5pub mod fixture_codec;
6
7#[cfg(feature = "host")]
8pub mod host;
9
10#[derive(Debug, PartialEq, Eq, 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(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
80#[cfg_attr(feature = "console", derive(clap::Args))]
81pub struct GroupBounds {
82 #[cfg_attr(feature = "console", arg(long, allow_hyphen_values = true))]
88 pub group_min: Option<String>,
89 #[cfg_attr(feature = "console", arg(long, allow_hyphen_values = true))]
92 pub group_max: Option<String>,
93}
94
95#[derive(Debug, serde::Deserialize, serde::Serialize)]
97pub struct QueryOptions {
98 pub distinct: bool,
100 pub group_bounds: GroupBounds,
102 pub group_order: Option<String>,
104 pub filters: RowFilters,
106}
107
108#[derive(Debug, serde::Deserialize, serde::Serialize)]
110pub struct Status {
111 pub schema: [u8; 32],
113 pub incarnation: [u8; 16],
115 pub revision: u64,
117 pub pages: u64,
119}
120
121#[derive(Debug, serde::Deserialize, serde::Serialize)]
123pub struct SchemaResponse {
124 pub status: Status,
126 pub entities: Vec<EntityView>,
128 pub types: Vec<TypeView>,
130}
131
132#[derive(Debug, serde::Deserialize, serde::Serialize)]
134pub struct EntityView {
135 pub name: String,
137 #[serde(rename = "primary_key")]
139 pub primary: String,
140 pub fields: Vec<FieldView>,
142 pub indexes: Vec<IndexView>,
144}
145
146#[derive(Debug, serde::Deserialize, serde::Serialize)]
148pub struct FieldView {
149 pub name: String,
151 #[serde(rename = "type")]
153 pub kind: String,
154 pub optional: bool,
156 pub info: String,
158 pub reference: Option<ReferenceView>,
160}
161
162#[derive(Debug, serde::Deserialize, serde::Serialize)]
164pub struct ReferenceView {
165 pub target: String,
167 pub index: String,
169}
170
171#[derive(Debug, serde::Deserialize, serde::Serialize)]
176pub struct IndexView {
177 pub name: String,
179 pub fields: Vec<String>,
181 pub unique: bool,
183 pub present_only: bool,
185}
186
187#[derive(Debug, serde::Deserialize, serde::Serialize)]
192pub struct TypeView {
193 pub name: String,
195 pub kind: String,
197 pub members: Vec<TypeMemberView>,
199}
200
201#[derive(Debug, serde::Deserialize, serde::Serialize)]
206pub struct TypeMemberView {
207 pub name: String,
209 #[serde(rename = "type")]
211 pub kind: String,
212 pub optional: bool,
214 pub info: String,
216}
217
218#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, Copy)]
223#[cfg_attr(feature = "console", derive(clap::ValueEnum))]
224pub enum FilterComparison {
225 Eq,
227 Ne,
229 Lt,
231 Le,
233 Gt,
235 Ge,
237 StartsWith,
239 EndsWith,
241 Contains,
243}
244
245#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
250pub struct ComparisonFilter<T> {
251 pub field: String,
253 pub op: FilterComparison,
255 pub operand: T,
257}
258
259#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
264pub struct FieldRange {
265 pub field: String,
267 pub lower: String,
269 pub upper: String,
271}
272
273#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
275pub struct RowFilters {
276 pub payload: PayloadFilters,
278 pub compare: Option<ComparisonFilter<String>>,
280 pub length: Option<ComparisonFilter<u32>>,
282 pub present: Option<String>,
284 pub absent: Option<String>,
286 pub text: Option<ComparisonFilter<String>>,
288 pub boolean: Option<(String, bool)>,
290 pub between_fields: Option<FieldRange>,
292 pub not_between_fields: Option<FieldRange>,
294}
295
296#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
298pub struct RetainedSelection {
299 pub entity: String,
301 pub select: String,
303 pub entity_filters: EntityFilters,
305 pub limit: u32,
307 pub group_bounds: GroupBounds,
309 pub group_order: Option<String>,
311 pub filters: RowFilters,
313 pub order: (Vec<String>, bool),
315}
316
317#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
319pub struct RetainedResume {
320 pub selection: RetainedSelection,
322 pub handle: Vec<u8>,
324 pub sequence: u64,
326 pub work: u32,
328 pub bytes: u32,
330 pub page_size: u32,
332 pub after: Option<Vec<u8>>,
334}
335
336#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
338pub struct DisplayPage {
339 pub columns: Vec<String>,
341 pub rows: Vec<Vec<String>>,
343 pub next: Option<Vec<u8>>,
345}
346
347#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
349pub struct RetainedProgress {
350 pub sequence: u64,
352 pub examined: u64,
354 pub input_bytes: u64,
356 pub output_bytes: u64,
358 pub phase: RetainedPhase,
360}
361
362#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
364pub enum RetainedPhase {
365 Running,
367 Complete(DisplayPage),
369 Invalidated,
371 Expired,
373}
374
375impl RetainedPhase {
376 #[must_use]
378 pub const fn label(&self) -> &'static str {
379 match self {
380 Self::Running => "Running",
381 Self::Complete(_) => "Complete",
382 Self::Invalidated => "Invalidated",
383 Self::Expired => "Expired",
384 }
385 }
386}
387
388#[must_use]
390pub fn lowercase_hex(bytes: &[u8], prefix: &str) -> String {
391 const DIGITS: &[u8; 16] = b"0123456789abcdef";
392 let mut output = String::with_capacity(prefix.len() + bytes.len() * 2);
393 output.push_str(prefix);
394 for &byte in bytes {
395 output.push(char::from(DIGITS[usize::from(byte >> 4)]));
396 output.push(char::from(DIGITS[usize::from(byte & 15)]));
397 }
398 output
399}