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 columns: Vec<String>,
12 pub rows: Vec<Vec<String>>,
14 pub next: Option<Vec<u8>>,
16 pub examined: u32,
18 pub fetched: u32,
20 pub output_bytes: u32,
22}
23
24#[derive(Clone, Default, Debug, serde::Deserialize, serde::Serialize)]
26pub struct PayloadFilters {
27 pub minimum: Option<Vec<u8>>,
29 pub maximum: Option<Vec<u8>>,
31 pub prefix: Option<Vec<u8>>,
33 pub suffix: Option<Vec<u8>>,
35 pub contains: Option<Vec<u8>>,
37}
38
39#[derive(Debug, serde::Deserialize, serde::Serialize)]
41pub struct QueryRequest {
42 pub entity: String,
44 pub cursor: Option<Vec<u8>>,
46 pub limit: u32,
48 pub minimum: Option<u64>,
50 pub category: Option<u64>,
52 pub entry_id: Option<u64>,
54 pub order: Vec<String>,
56 pub descending: bool,
58 pub work: u32,
60 pub bytes: u32,
62 pub select: String,
64 pub options: QueryOptions,
66}
67
68#[derive(Debug, serde::Deserialize, serde::Serialize)]
70pub struct QueryOptions {
71 pub distinct: bool,
73 pub group_bounds: (Option<String>, Option<String>),
75 pub group_order: Option<String>,
77 pub filters: RowFilters,
79}
80
81#[derive(Debug, serde::Deserialize, serde::Serialize)]
83pub struct Status {
84 pub schema: [u8; 32],
86 pub incarnation: [u8; 16],
88 pub revision: u64,
90 pub pages: u64,
92}
93
94#[derive(Debug, serde::Deserialize, serde::Serialize)]
96pub struct SchemaResponse {
97 pub status: Status,
99 pub entities: Vec<EntityView>,
101 pub types: Vec<TypeView>,
103}
104
105#[derive(Debug, serde::Deserialize, serde::Serialize)]
107pub struct EntityView {
108 pub name: String,
110 pub id: u32,
112 pub primary: String,
114 pub fields: Vec<FieldView>,
116 pub indexes: Vec<IndexView>,
118}
119
120#[derive(Debug, serde::Deserialize, serde::Serialize)]
122pub struct FieldView {
123 pub name: String,
125 pub kind: String,
127 pub optional: bool,
129 pub info: String,
131 pub reference: Option<(String, String)>,
133}
134
135pub type IndexView = (String, Vec<String>, bool, bool);
137
138pub type TypeView = (String, String, Vec<(String, String, bool, String)>);
140
141#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
143pub struct RowFilters {
144 pub payload: PayloadFilters,
146 pub compare: Option<[String; 3]>,
148 pub length: Option<(String, String, u32)>,
150 pub present: Option<String>,
152 pub absent: Option<String>,
154 pub text: Option<[String; 3]>,
156 pub boolean: Option<(String, bool)>,
158 pub between_fields: Option<[String; 3]>,
160 pub not_between_fields: Option<[String; 3]>,
162}
163
164#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
166pub struct RetainedSelection {
167 pub entity: String,
169 pub select: String,
171 pub entity_filters: (Option<u64>, Option<u64>, Option<u64>),
173 pub limit: u32,
175 pub group_bounds: (Option<String>, Option<String>),
177 pub group_order: Option<String>,
179 pub filters: RowFilters,
181 pub order: (Vec<String>, bool),
183}
184
185#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
187pub struct RetainedResume {
188 pub selection: RetainedSelection,
190 pub handle: Vec<u8>,
192 pub sequence: u64,
194 pub work: u32,
196 pub bytes: u32,
198 pub page_size: u32,
200 pub after: Option<Vec<u8>>,
202}
203
204pub type RetainedOutput = (Vec<String>, Vec<Vec<String>>, Option<Vec<u8>>);
206
207#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
209pub struct RetainedProgress {
210 pub sequence: u64,
212 pub examined: u64,
214 pub input_bytes: u64,
216 pub output_bytes: u64,
218 pub phase: RetainedPhase,
220}
221
222#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
224pub enum RetainedPhase {
225 Running,
227 Complete(RetainedOutput),
229 Invalidated,
231 Expired,
233}
234
235impl RetainedPhase {
236 #[must_use]
238 pub const fn label(&self) -> &'static str {
239 match self {
240 Self::Running => "Running",
241 Self::Complete(_) => "Complete",
242 Self::Invalidated => "Invalidated",
243 Self::Expired => "Expired",
244 }
245 }
246}
247
248#[must_use]
250pub fn lowercase_hex(bytes: &[u8], prefix: &str) -> String {
251 const DIGITS: &[u8; 16] = b"0123456789abcdef";
252 let mut output = String::with_capacity(prefix.len() + bytes.len() * 2);
253 output.push_str(prefix);
254 for &byte in bytes {
255 output.push(char::from(DIGITS[usize::from(byte >> 4)]));
256 output.push(char::from(DIGITS[usize::from(byte & 15)]));
257 }
258 output
259}